From 8a6d66e04839210ebe2702c6b7b71c58faeb7429 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:17:28 -0700 Subject: [PATCH 01/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 cf6f32c90e..125c4a0184 100644 --- a/src/abi.md +++ b/src/abi.md @@ -119,14 +119,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 247d1fb0e3046ad23557905aeec5e75c8e403bc7 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:23 -0700 Subject: [PATCH 02/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 125c4a0184..f217610189 100644 --- a/src/abi.md +++ b/src/abi.md @@ -117,7 +117,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 7d259863c703f076ab6cb4a629481ca72542af46 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:31 -0700 Subject: [PATCH 03/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 f217610189..23f57ce5ec 100644 --- a/src/abi.md +++ b/src/abi.md @@ -126,7 +126,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 c664afb1c356f7cb2b03ce9bc0760002c675428f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:36:44 -0700 Subject: [PATCH 04/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 23f57ce5ec..366885920a 100644 --- a/src/abi.md +++ b/src/abi.md @@ -128,8 +128,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. @@ -137,6 +145,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 06f71d4237c94e3ecec3bf74853578784d972ce9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:04 -0700 Subject: [PATCH 05/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 366885920a..a9bdbea6c6 100644 --- a/src/abi.md +++ b/src/abi.md @@ -146,7 +146,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 aa5d9909d0c1928f577fd9de30b420ef4413f60d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:37:36 -0700 Subject: [PATCH 06/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 a9bdbea6c6..bde9e89e67 100644 --- a/src/abi.md +++ b/src/abi.md @@ -152,6 +152,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 7af0b30a0f7db9a7993965ca0872c7ccc4d6540d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:38:43 -0700 Subject: [PATCH 07/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 bde9e89e67..e00481a5bf 100644 --- a/src/abi.md +++ b/src/abi.md @@ -155,6 +155,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 2eeea4b7b10f24ec7e91fc13b8dcbc1dbe940143 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Jun 2025 16:40:06 -0700 Subject: [PATCH 08/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 e00481a5bf..93e763152d 100644 --- a/src/abi.md +++ b/src/abi.md @@ -158,6 +158,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 a4789d4d12ad538e4d609a8c3bf4a07a0bfc9858 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 30 Jun 2025 14:50:23 -0700 Subject: [PATCH 09/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 93e763152d..eb5a5e5731 100644 --- a/src/abi.md +++ b/src/abi.md @@ -161,6 +161,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 2161f1e2343832e0e460133d474430222c9e3f9d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:11:51 -0700 Subject: [PATCH 10/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 eb5a5e5731..62dfbfb14f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -113,6 +113,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 From 135123e0e72c3f24c5d81b2fc9cdc076f945d058 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 11 May 2026 14:25:13 -0700 Subject: [PATCH 11/11] Update export_name for updated restrictions https://github.com/rust-lang/rust/pull/155515 added a restriction that the symbol name cannot be empty in the `export_name` attribute. This now matches the behavior of link_name (see https://github.com/rust-lang/reference/pull/2268). --- src/abi.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/abi.md b/src/abi.md index 62dfbfb14f..428a122c42 100644 --- a/src/abi.md +++ b/src/abi.md @@ -159,8 +159,8 @@ 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. +r[abi.export_name.invalid-names] +The exported name must not be the empty string, and must not contain any `U+0000` (NUL) bytes. r[abi.export_name.generic] `export_name` has no effect on generic items.