From 1bce65120de506cde4155f6b106ba4c49648f3bf Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:16:52 -0700 Subject: [PATCH 01/11] 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 48cc067884..107979e8c6 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 d57b8c6d7947f827ac02087c2063a98fbf24460e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:17:28 -0700 Subject: [PATCH 02/11] 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 107979e8c6..3de6e0c8d2 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 545f15494753995271a14ba6b8b4f2da2383f1e6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:23 -0700 Subject: [PATCH 03/11] Linkify attribute --- src/abi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index 3de6e0c8d2..05e3128b05 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 179b3c3a85898a152738ab06416d65668557097b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:31 -0700 Subject: [PATCH 04/11] 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 05e3128b05..f02174578c 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 3a695b497e81f37972c7304cc0fd49f089b2e849 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:44 -0700 Subject: [PATCH 05/11] 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 f02174578c..e164aa1469 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 first use of `export_name` on an item has effect. + +> [!NOTE] +> `rustc` lints against any use following the first with a future-compatibility warning. 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 90b25836e389dd700da1ab48a835a4ef16b3e0cc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:04 -0700 Subject: [PATCH 06/11] 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 e164aa1469..e4c3e4d009 100644 --- a/src/abi.md +++ b/src/abi.md @@ -144,7 +144,7 @@ Only the first use of `export_name` on an item has effect. > `rustc` lints against any use following the first with a future-compatibility warning. 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 410104103a1c7c7e9d76f8fefc4a71916a92aa82 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:36 -0700 Subject: [PATCH 07/11] 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 e4c3e4d009..9b7336ee94 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 915e849a0f5fbf360a95e778704b5fccb7b64cba Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:38:43 -0700 Subject: [PATCH 08/11] 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 9b7336ee94..7841397c67 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 45fc26bb71a0310dc3fc2a57c4d45e67703a3c86 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:40:06 -0700 Subject: [PATCH 09/11] 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 7841397c67..a1a3f37d6a 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 f7441976515cd482fac5a84c7758daaf3b724f28 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 30 Jun 2025 14:50:23 -0700 Subject: [PATCH 10/11] 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 a1a3f37d6a..53f33c13a4 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 From 7c29bc885f2797146ce602b024f9169502ceb77b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:11:51 -0700 Subject: [PATCH 11/11] Minor update of `export_name` More closely align with the template, and some minor word tweaks. --- src/abi.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/abi.md b/src/abi.md index 53f33c13a4..19764639be 100644 --- a/src/abi.md +++ b/src/abi.md @@ -111,6 +111,7 @@ r[abi.link_section.edition2024] > [!EDITION-2024] > Before the 2024 edition it is allowed to use the `link_section` attribute without the `unsafe` qualification. + r[abi.export_name] ## The `export_name` attribute