diff --git a/src/abi.md b/src/abi.md index c0f7ed78a..06010c13f 100644 --- a/src/abi.md +++ b/src/abi.md @@ -90,27 +90,47 @@ r[abi.link_section] ## The `link_section` attribute r[abi.link_section.intro] -The *`link_section` attribute* specifies the section of the object file that a -[function] or [static]'s content will be placed into. +The *`link_section` [attribute]* specifies the section of the object file that a [function] or [static]'s content will be placed into. + +> [!EXAMPLE] +> +> ```rust,no_run +> #[unsafe(no_mangle)] +> #[unsafe(link_section = ".example_section")] +> pub static VAR1: u32 = 1; +> ``` r[abi.link_section.syntax] The `link_section` attribute uses the [MetaNameValueStr] syntax to specify the section name. - -```rust,no_run -#[unsafe(no_mangle)] -#[unsafe(link_section = ".example_section")] -pub static VAR1: u32 = 1; -``` +r[abi.link_section.allowed-positions] +The `link_section` 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] +- [Trait definition functions][items.traits] with a body + +> [!NOTE] +> `rustc` currently warns in other positions, but this may be rejected in the future. + +r[abi.link_section.duplicates] +Only the last instance of `link_section` on an item is honored. Previous `link_section` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on preceding duplicate `link_section` attributes. This may become an error in the future. r[abi.link_section.unsafe] -This attribute is unsafe as it allows users to place data and code into sections -of memory not expecting them, such as mutable data into read-only areas. +The `link_section` attribute must be marked with [`unsafe`][attributes.safety] because it allows users to place data and code into sections of memory not expecting them, such as mutable data into read-only areas. 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.link_section.null] +The section name must not contain a [NUL] character. + r[abi.export_name] ## The `export_name` attribute