Skip to content

Commit 4e460e3

Browse files
authored
Merge pull request #1793 from ehuss/abi-rules
Add rule identifiers for the ABI chapter
2 parents 53561c9 + b961598 commit 4e460e3

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/abi.md

+30-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
r[abi]
12
# Application Binary Interface (ABI)
23

4+
r[abi.intro]
35
This section documents features that affect the ABI of the compiled output of
46
a crate.
57

68
See *[extern functions]* for information on specifying the ABI for exporting
79
functions. See *[external blocks]* for information on specifying the ABI for
810
linking external libraries.
911

12+
r[abi.used]
1013
## The `used` attribute
1114

15+
r[abi.used.intro]
1216
The *`used` attribute* can only be applied to [`static` items]. This [attribute] forces the
1317
compiler to keep the variable in the output object file (.o, .rlib, etc. excluding final binaries)
1418
even if the variable is not used, or referenced, by any other item in the crate.
@@ -57,15 +61,19 @@ $ nm -C foo.o
5761
0000000000000000 T foo::quux
5862
```
5963

64+
r[abi.no_mangle]
6065
## The `no_mangle` attribute
6166

67+
r[abi.no_mangle.intro]
6268
The *`no_mangle` attribute* may be used on any [item] to disable standard
6369
symbol name mangling. The symbol for the item will be the identifier of the
6470
item's name.
6571

72+
r[abi.no_mangle.publicly-exported]
6673
Additionally, the item will be publicly exported from the produced library or
6774
object file, similar to the [`used` attribute](#the-used-attribute).
6875

76+
r[abi.no_mangle.unsafe]
6977
This attribute is unsafe as an unmangled symbol may collide with another symbol
7078
with 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.
7482
extern "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]
8293
The *`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.
93103
pub 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]
101118
The *`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")]
111126
pub 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

Comments
 (0)