From 4d160e006d281c22c3be23dcd99d41f1715c339a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:16:52 -0700 Subject: [PATCH 01/10] Unwrap export_name --- src/abi.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/abi.md b/src/abi.md index c0f7ed78a..d1b72c3b3 100644 --- a/src/abi.md +++ b/src/abi.md @@ -115,8 +115,7 @@ r[abi.export_name] ## The `export_name` attribute r[abi.export_name.intro] -The *`export_name` attribute* specifies the name of the symbol that will be -exported on a [function] or [static]. +The *`export_name` attribute* specifies the name of the symbol that will be exported on a [function] or [static]. r[abi.export_name.syntax] The `export_name `attribute uses the [MetaNameValueStr] syntax to specify the symbol name. @@ -127,9 +126,7 @@ pub fn name_in_rust() { } ``` r[abi.export_name.unsafe] -This attribute is unsafe as a symbol with a custom name may collide with another -symbol with the same name (or with a well-known symbol), leading to undefined -behavior. +This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. r[abi.export_name.edition2024] > [!EDITION-2024] From 6361ca48a8107396fa0cf9814ae4967b69387efb Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:17:28 -0700 Subject: [PATCH 02/10] Move export_name example to the intro --- src/abi.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/abi.md b/src/abi.md index d1b72c3b3..7d9555d05 100644 --- a/src/abi.md +++ b/src/abi.md @@ -117,14 +117,15 @@ r[abi.export_name] r[abi.export_name.intro] The *`export_name` attribute* specifies the name of the symbol that will be exported on a [function] or [static]. +> [!EXAMPLE] +> ```rust +> #[unsafe(export_name = "exported_symbol_name")] +> pub fn name_in_rust() { } +> ``` + r[abi.export_name.syntax] The `export_name `attribute uses the [MetaNameValueStr] syntax to specify the symbol name. -```rust -#[unsafe(export_name = "exported_symbol_name")] -pub fn name_in_rust() { } -``` - r[abi.export_name.unsafe] This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. From 10dc0331e382a516047bf39d306c7d094b8c564d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:23 -0700 Subject: [PATCH 03/10] Linkify attribute --- src/abi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index 7d9555d05..566a343cc 100644 --- a/src/abi.md +++ b/src/abi.md @@ -115,7 +115,7 @@ r[abi.export_name] ## The `export_name` attribute r[abi.export_name.intro] -The *`export_name` attribute* specifies the name of the symbol that will be exported on a [function] or [static]. +The *`export_name` [attribute]* specifies the name of the symbol that will be exported on a [function] or [static]. > [!EXAMPLE] > ```rust From 677d600ec6ed5c82fdb2e102fb5de44453e64fa0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:31 -0700 Subject: [PATCH 04/10] Fix misplaced space --- src/abi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index 566a343cc..b8531bec8 100644 --- a/src/abi.md +++ b/src/abi.md @@ -124,7 +124,7 @@ The *`export_name` [attribute]* specifies the name of the symbol that will be ex > ``` r[abi.export_name.syntax] -The `export_name `attribute uses the [MetaNameValueStr] syntax to specify the symbol name. +The `export_name` attribute uses the [MetaNameValueStr] syntax to specify the symbol name. r[abi.export_name.unsafe] This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. From a33d999835e87da4d9481125300a7074c06b5358 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:44 -0700 Subject: [PATCH 05/10] Add template rules for export_name --- src/abi.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/abi.md b/src/abi.md index b8531bec8..f4236f924 100644 --- a/src/abi.md +++ b/src/abi.md @@ -126,6 +126,23 @@ The *`export_name` [attribute]* specifies the name of the symbol that will be ex r[abi.export_name.syntax] The `export_name` attribute uses the [MetaNameValueStr] syntax to specify the symbol name. +r[abi.export_name.allowed-positions] +The `export_name` attribute may only be applied to: + +- [Static items][items.static] +- [Free functions][items.fn] +- [Inherent associated functions][items.associated.fn] +- [Trait impl functions][items.impl.trait] + +> [!NOTE] +> `rustc` currently ignores `export_name` in some positions, but this may be rejected in the future. + +r[abi.export_name.duplicates] +Only the last instance of `export_name` on an item is honored. Previous `export_name` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on preceding duplicate `export_name` attributes. This may become an error in the future. + r[abi.export_name.unsafe] This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. From 643d60b78e5e05722ae177cff841745097534894 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:04 -0700 Subject: [PATCH 06/10] Reword abi.export_name.unsafe to follow template --- src/abi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index f4236f924..a7290fe70 100644 --- a/src/abi.md +++ b/src/abi.md @@ -144,7 +144,7 @@ Only the last instance of `export_name` on an item is honored. Previous `export_ > `rustc` currently warns on preceding duplicate `export_name` attributes. This may become an error in the future. r[abi.export_name.unsafe] -This attribute is unsafe as a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. +The `export_name` attribute must be marked with [`unsafe`][attributes.safety] because a symbol with a custom name may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior. r[abi.export_name.edition2024] > [!EDITION-2024] From d36ea17607f385ee333b5b7cba1ebe1a0314edac Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:36 -0700 Subject: [PATCH 07/10] Add abi.export_name.no_mangle Specifies the interaction with export_name and no_mangle. This is essentially a duplicate of abi.no_mangle.export_name, but I think it is worthwile to say it in both places. --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index a7290fe70..aa415f233 100644 --- a/src/abi.md +++ b/src/abi.md @@ -150,6 +150,9 @@ r[abi.export_name.edition2024] > [!EDITION-2024] > Before the 2024 edition it is allowed to use the `export_name` attribute without the `unsafe` qualification. +r[abi.export_name.no_mangle] +If `export_name` is used with [`no_mangle`][abi.no_mangle], then the `export_name` is used instead. + [`static` items]: items/static-items.md [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier From 66d074c27ce8143593dd54810f73ea90362e1713 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:38:43 -0700 Subject: [PATCH 08/10] Add abi.export_name.publicly-exported I'm not sure why this wasn't added before with no_mangle. I believe this is done here: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_passes/src/dead.rs#L690-L700 --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index aa415f233..0d54da5aa 100644 --- a/src/abi.md +++ b/src/abi.md @@ -153,6 +153,9 @@ r[abi.export_name.edition2024] r[abi.export_name.no_mangle] If `export_name` is used with [`no_mangle`][abi.no_mangle], then the `export_name` is used instead. +r[abi.export_name.publicly-exported] +The `export_name` attribute causes the symbol to be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute). + [`static` items]: items/static-items.md [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier From 204dfa2616a0949e80ed1aeac1f9bb511ad672dc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:40:06 -0700 Subject: [PATCH 09/10] Add abi.export_name.null I'm guessing this is a reasonable rule to have for all targets. At least rustc treats it that way. https://github.com/rust-lang/rust/blob/5d707b07e42766c080c5012869c9988a18dcbb83/compiler/rustc_codegen_ssa/src/codegen_attrs.rs#L254-L264 --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index 0d54da5aa..75879744f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -156,6 +156,9 @@ If `export_name` is used with [`no_mangle`][abi.no_mangle], then the `export_nam r[abi.export_name.publicly-exported] The `export_name` attribute causes the symbol to be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute). +r[abi.export_name.null] +The exported name must not contain a [NUL] character. + [`static` items]: items/static-items.md [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier From ded3d4e88235a889c22123b5f9e65c3f92ba9acc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 30 Jun 2025 14:50:23 -0700 Subject: [PATCH 10/10] Add abi.export_name.generic --- src/abi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi.md b/src/abi.md index 75879744f..d6609c53c 100644 --- a/src/abi.md +++ b/src/abi.md @@ -159,6 +159,9 @@ The `export_name` attribute causes the symbol to be publicly exported from the p r[abi.export_name.null] The exported name must not contain a [NUL] character. +r[abi.export_name.generic] +`export_name` has no effect on generic items. + [`static` items]: items/static-items.md [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier