1+ r[ abi]
12# Application Binary Interface (ABI)
23
4+ r[ abi.intro]
35This section documents features that affect the ABI of the compiled output of
46a crate.
57
68See * [ extern functions] * for information on specifying the ABI for exporting
79functions. See * [ external blocks] * for information on specifying the ABI for
810linking external libraries.
911
12+ r[ abi.used]
1013## The ` used ` attribute
1114
15+ r[ abi.used.intro]
1216The * ` used ` attribute* can only be applied to [ ` static ` items] . This [ attribute] forces the
1317compiler to keep the variable in the output object file (.o, .rlib, etc. excluding final binaries)
1418even if the variable is not used, or referenced, by any other item in the crate.
@@ -57,15 +61,19 @@ $ nm -C foo.o
57610000000000000000 T foo::quux
5862```
5963
64+ r[ abi.no_mangle]
6065## The ` no_mangle ` attribute
6166
67+ r[ abi.no_mangle.intro]
6268The * ` no_mangle ` attribute* may be used on any [ item] to disable standard
6369symbol name mangling. The symbol for the item will be the identifier of the
6470item's name.
6571
72+ r[ abi.no_mangle.publicly-exported]
6673Additionally, the item will be publicly exported from the produced library or
6774object file, similar to the [ ` used ` attribute] ( #the-used-attribute ) .
6875
76+ r[ abi.no_mangle.unsafe]
6977This attribute is unsafe as an unmangled symbol may collide with another symbol
7078with the same name (or with a well-known symbol), leading to undefined behavior.
7179
@@ -74,17 +82,19 @@ with the same name (or with a well-known symbol), leading to undefined behavior.
7482extern " C" fn foo () {}
7583```
7684
85+ r[ abi.no_mangle.edition2024]
7786> [ !EDITION-2024]
7887> Before the 2024 edition it is allowed to use the ` no_mangle ` attribute without the ` unsafe ` qualification.
7988
89+ r[ abi.link_section]
8090## The ` link_section ` attribute
8191
92+ r[ abi.link_section.intro]
8293The * ` link_section ` attribute* specifies the section of the object file that a
83- [ function] or [ static] 's content will be placed into. It uses the
84- [ MetaNameValueStr] syntax to specify the section name.
94+ [ function] or [ static] 's content will be placed into.
8595
86- This attribute is unsafe as it allows users to place data and code into sections
87- of memory not expecting them, such as mutable data into read-only areas .
96+ r [ abi.link_section.syntax ]
97+ The ` link_section ` attribute uses the [ MetaNameValueStr ] syntax to specify the section name .
8898
8999<!-- no_run: don't link. The format of the section name is platform-specific. -->
90100``` rust,no_run
@@ -93,24 +103,35 @@ of memory not expecting them, such as mutable data into read-only areas.
93103pub static VAR1: u32 = 1;
94104```
95105
106+ r[ abi.link_section.unsafe]
107+ This attribute is unsafe as it allows users to place data and code into sections
108+ of memory not expecting them, such as mutable data into read-only areas.
109+
110+ r[ abi.link_section.edition2024]
96111> [ !EDITION-2024]
97112> Before the 2024 edition it is allowed to use the ` link_section ` attribute without the ` unsafe ` qualification.
98113
114+ r[ abi.export_name]
99115## The ` export_name ` attribute
100116
117+ r[ abi.export_name.intro]
101118The * ` export_name ` attribute* specifies the name of the symbol that will be
102- exported on a [ function] or [ static] . It uses the [ MetaNameValueStr] syntax
103- to specify the symbol name.
119+ exported on a [ function] or [ static] .
104120
105- This attribute is unsafe as a symbol with a custom name may collide with another
106- symbol with the same name (or with a well-known symbol), leading to undefined
107- behavior.
121+ r[ abi.export_name.syntax]
122+ The ` export_name ` attribute uses the [ MetaNameValueStr] syntax to specify the symbol name.
108123
109124``` rust
110125#[unsafe (export_name = " exported_symbol_name" )]
111126pub fn name_in_rust () { }
112127```
113128
129+ r[ abi.export_name.unsafe]
130+ This attribute is unsafe as a symbol with a custom name may collide with another
131+ symbol with the same name (or with a well-known symbol), leading to undefined
132+ behavior.
133+
134+ r[ abi.export_name.edition2024]
114135> [ !EDITION-2024]
115136> Before the 2024 edition it is allowed to use the ` export_name ` attribute without the ` unsafe ` qualification.
116137
0 commit comments