From fdd15749a454a3be79538f4f4c3e96ae7fd3d876 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 c0f7ed78a6..d1b72c3b36 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 6679bb3b63cff8e7afe9ad606ecc9bed9a9ed1ef 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 d1b72c3b36..7d9555d050 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 319ed11783c7fb63b545539745dc14179648b84d 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 7d9555d050..566a343ccb 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 b67ab43e3e8826a72088b2261d41809e5adb9531 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 566a343ccb..b8531bec86 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 1dd0f17af52168002f255a0765a0b063d3e2bc51 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 b8531bec86..f4236f924b 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 9bfeb948fa328bfb6c9aaa25c4cc403a7290f927 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 f4236f924b..a7290fe70c 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 d01b974866a80516bbf88450f98638b28649c7d7 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 a7290fe70c..aa415f2334 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 8cd70e1bb6584ca9cc7be98854dd6dc3802b175d 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 aa415f2334..0d54da5aa9 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 dfc87a9b2099436dacad4a5b908d634fdad9b671 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 0d54da5aa9..75879744f0 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 f083ae7654f23a83fe4ab0b5098b1e4c784d040b 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 75879744f0..d6609c53c0 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 ff643631c1b63ab084823e3ff85f9cd4c52e1c2c 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/abi.md b/src/abi.md index d6609c53c0..c2807d6c14 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 @@ -138,7 +139,7 @@ The `export_name` attribute may only be applied to: > `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. +Only the last use of `export_name` on an item has effect. > [!NOTE] > `rustc` currently warns on preceding duplicate `export_name` attributes. This may become an error in the future.