1
+ r[ abi]
1
2
# Application Binary Interface (ABI)
2
3
4
+ r[ abi.intro]
3
5
This section documents features that affect the ABI of the compiled output of
4
6
a crate.
5
7
6
8
See * [ extern functions] * for information on specifying the ABI for exporting
7
9
functions. See * [ external blocks] * for information on specifying the ABI for
8
10
linking external libraries.
9
11
12
+ r[ abi.used]
10
13
## The ` used ` attribute
11
14
15
+ r[ abi.used.intro]
12
16
The * ` used ` attribute* can only be applied to [ ` static ` items] . This [ attribute] forces the
13
17
compiler to keep the variable in the output object file (.o, .rlib, etc. excluding final binaries)
14
18
even if the variable is not used, or referenced, by any other item in the crate.
@@ -57,15 +61,19 @@ $ nm -C foo.o
57
61
0000000000000000 T foo::quux
58
62
```
59
63
64
+ r[ abi.no_mangle]
60
65
## The ` no_mangle ` attribute
61
66
67
+ r[ abi.no_mangle.intro]
62
68
The * ` no_mangle ` attribute* may be used on any [ item] to disable standard
63
69
symbol name mangling. The symbol for the item will be the identifier of the
64
70
item's name.
65
71
72
+ r[ abi.no_mangle.publicly-exported]
66
73
Additionally, the item will be publicly exported from the produced library or
67
74
object file, similar to the [ ` used ` attribute] ( #the-used-attribute ) .
68
75
76
+ r[ abi.no_mangle.unsafe]
69
77
This attribute is unsafe as an unmangled symbol may collide with another symbol
70
78
with the same name (or with a well-known symbol), leading to undefined behavior.
71
79
@@ -74,17 +82,19 @@ with the same name (or with a well-known symbol), leading to undefined behavior.
74
82
extern " C" fn foo () {}
75
83
```
76
84
85
+ r[ abi.no_mangle.edition2024]
77
86
> [ !EDITION-2024]
78
87
> Before the 2024 edition it is allowed to use the ` no_mangle ` attribute without the ` unsafe ` qualification.
79
88
89
+ r[ abi.link_section]
80
90
## The ` link_section ` attribute
81
91
92
+ r[ abi.link_section.intro]
82
93
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.
85
95
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 .
88
98
89
99
<!-- no_run: don't link. The format of the section name is platform-specific. -->
90
100
``` rust,no_run
@@ -93,24 +103,35 @@ of memory not expecting them, such as mutable data into read-only areas.
93
103
pub static VAR1: u32 = 1;
94
104
```
95
105
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]
96
111
> [ !EDITION-2024]
97
112
> Before the 2024 edition it is allowed to use the ` link_section ` attribute without the ` unsafe ` qualification.
98
113
114
+ r[ abi.export_name]
99
115
## The ` export_name ` attribute
100
116
117
+ r[ abi.export_name.intro]
101
118
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] .
104
120
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.
108
123
109
124
``` rust
110
125
#[unsafe (export_name = " exported_symbol_name" )]
111
126
pub fn name_in_rust () { }
112
127
```
113
128
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]
114
135
> [ !EDITION-2024]
115
136
> Before the 2024 edition it is allowed to use the ` export_name ` attribute without the ` unsafe ` qualification.
116
137
0 commit comments