From 6de8dd2f6d18b93a3138fef4ee775cb13a8f1e11 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 0ddd93b88f..e3eaecc73f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -126,8 +126,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. @@ -138,9 +137,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.duplicates] Only the first use of `export_name` on an item has effect. From d20ed596269eb583557836ab58787fe07dd7a842 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 e3eaecc73f..fc3c39937b 100644 --- a/src/abi.md +++ b/src/abi.md @@ -128,14 +128,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 c7a232a6f3684baaa8f021054562b5f12e87f850 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 fc3c39937b..0c48d70e8f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -126,7 +126,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 1d6a0b9fe390c9682f99e9a4548d1edcd44c0b75 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 0c48d70e8f..91240bcddd 100644 --- a/src/abi.md +++ b/src/abi.md @@ -135,7 +135,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 11f5e32b9ee3e4ac0b77297303a62cd3f680e490 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/abi.md b/src/abi.md index 91240bcddd..d4269f289d 100644 --- a/src/abi.md +++ b/src/abi.md @@ -137,8 +137,16 @@ 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.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. +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. @@ -146,6 +154,9 @@ 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. + r[abi.export_name.edition2024] > [!EDITION-2024] > Before the 2024 edition it is allowed to use the `export_name` attribute without the `unsafe` qualification. From 6d65d00d2f148d7af05fdaf6be788fb6b025c14f 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 d4269f289d..eaef8a23bd 100644 --- a/src/abi.md +++ b/src/abi.md @@ -155,7 +155,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 a57641484fb4e0ff710128c31bf979bad4142212 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 eaef8a23bd..2522c1a9b8 100644 --- a/src/abi.md +++ b/src/abi.md @@ -161,6 +161,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. + [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md From d1e8bf41ae00db89b490af880993e0f5c592e666 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 2522c1a9b8..8f17ec1177 100644 --- a/src/abi.md +++ b/src/abi.md @@ -164,6 +164,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). + [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md From 85a048f86622ba7374bd615609e7fba75660710c 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 8f17ec1177..4b57363896 100644 --- a/src/abi.md +++ b/src/abi.md @@ -167,6 +167,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. + [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md From 0dffb5d8bd7173f560f1bab5545767a9afcb4dcb 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 4b57363896..b70be816f9 100644 --- a/src/abi.md +++ b/src/abi.md @@ -170,6 +170,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. + [attribute]: attributes.md [extern functions]: items/functions.md#extern-function-qualifier [external blocks]: items/external-blocks.md From 20a6d0074debea58e7b0fbf35299710a2f7a2883 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 b70be816f9..55252fe675 100644 --- a/src/abi.md +++ b/src/abi.md @@ -122,6 +122,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