You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/abi.md
+9-21Lines changed: 9 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,9 @@ r[abi]
2
2
# Application binary interface (ABI)
3
3
4
4
r[abi.intro]
5
-
This section documents features that affect the ABI of the compiled output of
6
-
a crate.
5
+
This section documents features that affect the ABI of the compiled output of a crate.
7
6
8
-
See *[extern functions]* for information on specifying the ABI for exporting
9
-
functions. See *[external blocks]* for information on specifying the ABI for
10
-
linking external libraries.
7
+
See *[extern functions]* for information on specifying the ABI for exporting functions. See *[external blocks]* for information on specifying the ABI for linking external libraries.
11
8
12
9
<!-- template:attributes -->
13
10
r[abi.used]
@@ -68,17 +65,13 @@ r[abi.no_mangle]
68
65
## The `no_mangle` attribute
69
66
70
67
r[abi.no_mangle.intro]
71
-
The*`no_mangle` attribute* may be used on any [item] to disable standard
72
-
symbol name mangling.The symbol for the item will be the identifier of the
73
-
item's name.
68
+
The*`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling.The symbol for the item will be the identifier of the item's name.
74
69
75
70
r[abi.no_mangle.publicly-exported]
76
-
Additionally, the item will be publicly exported from the produced library or
77
-
object file, similar to the [`used` attribute](#the-used-attribute).
71
+
Additionally, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute).
78
72
79
73
r[abi.no_mangle.unsafe]
80
-
This attribute is unsafeas an unmangled symbol may collide with another symbol
81
-
with the same name (or with a well-known symbol), leading to undefined behavior.
74
+
This attribute is unsafeas an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior.
82
75
83
76
```rust
84
77
#[unsafe(no_mangle)]
@@ -93,8 +86,7 @@ r[abi.link_section]
93
86
## The `link_section` attribute
94
87
95
88
r[abi.link_section.intro]
96
-
The*`link_section` attribute* specifies the section of the object file that a
97
-
[function] or [static]'s content will be placed into.
89
+
The*`link_section` attribute* specifies the section of the object file that a [function] or [static]'s content will be placed into.
98
90
99
91
r[abi.link_section.syntax]
100
92
The `link_section` attribute uses the [MetaNameValueStr] syntax to specify the section name.
@@ -109,8 +101,7 @@ pub static VAR1: u32 = 1;
109
101
```
110
102
111
103
r[abi.link_section.unsafe]
112
-
This attribute is unsafe as it allows users to place data and code into sections
113
-
of memory not expecting them, such as mutable data into read-only areas.
104
+
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.
114
105
115
106
r[abi.link_section.duplicates]
116
107
Only the first use of `link_section` on an item has effect.
@@ -126,8 +117,7 @@ r[abi.export_name]
126
117
## The `export_name` attribute
127
118
128
119
r[abi.export_name.intro]
129
-
The *`export_name` attribute* specifies the name of the symbol that will be
130
-
exported on a [function] or [static].
120
+
The *`export_name` attribute* specifies the name of the symbol that will be exported on a [function] or [static].
131
121
132
122
r[abi.export_name.syntax]
133
123
The `export_name `attribute uses the [MetaNameValueStr] syntax to specify the symbol name.
@@ -138,9 +128,7 @@ pub fn name_in_rust() { }
138
128
```
139
129
140
130
r[abi.export_name.unsafe]
141
-
This attribute is unsafe as a symbol with a custom name may collide with another
142
-
symbol with the same name (or with a well-known symbol), leading to undefined
143
-
behavior.
131
+
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.
144
132
145
133
r[abi.export_name.duplicates]
146
134
Only the first use of `export_name` on an item has effect.
The Rust compiler does not consider the following behaviors _unsafe_,
4
-
though a programmer may (should) find them undesirable, unexpected,
5
-
or erroneous.
3
+
The Rust compiler does not consider the following behaviors _unsafe_, though a programmer may (should) find them undesirable, unexpected, or erroneous.
6
4
7
5
- Deadlocks
8
6
- Leaks of memory and other resources
@@ -11,47 +9,22 @@ or erroneous.
11
9
12
10
## Integer overflow
13
11
14
-
If a program contains arithmetic overflow, the programmer has made an
15
-
error. In the following discussion, we maintain a distinction between
16
-
arithmetic overflow and wrapping arithmetic. The first is erroneous,
17
-
while the second is intentional.
12
+
If a program contains arithmetic overflow, the programmer has made an error. In the following discussion, we maintain a distinction between arithmetic overflow and wrapping arithmetic. The first is erroneous, while the second is intentional.
18
13
19
-
When the programmer has enabled `debug_assert!` assertions (for
20
-
example, by enabling a non-optimized build), implementations must
21
-
insert dynamic checks that `panic` on overflow. Other kinds of builds
22
-
may result in `panics` or silently wrapped values on overflow, at the
23
-
implementation's discretion.
14
+
When the programmer has enabled `debug_assert!` assertions (for example, by enabling a non-optimized build), implementations must insert dynamic checks that `panic` on overflow. Other kinds of builds may result in `panics` or silently wrapped values on overflow, at the implementation's discretion.
24
15
25
-
In the case of implicitly-wrapped overflow, implementations must
26
-
provide well-defined (even if still considered erroneous) results by
27
-
using two's complement overflow conventions.
16
+
In the case of implicitly-wrapped overflow, implementations must provide well-defined (even if still considered erroneous) results by using two's complement overflow conventions.
28
17
29
-
The integral types provide inherent methods to allow programmers
30
-
explicitly to perform wrapping arithmetic. For example,
The integral types provide inherent methods to allow programmers explicitly to perform wrapping arithmetic. For example, `i32::wrapping_add` provides two's complement, wrapping addition.
32
19
33
-
The standard library also provides a `Wrapping<T>` newtype which
34
-
ensures all standard arithmetic operations for `T` have wrapping
35
-
semantics.
20
+
The standard library also provides a `Wrapping<T>` newtype which ensures all standard arithmetic operations for `T` have wrapping semantics.
36
21
37
-
See [RFC 560] for error conditions, rationale, and more details about
38
-
integer overflow.
22
+
See [RFC 560] for error conditions, rationale, and more details about integer overflow.
39
23
40
24
## Logic errors
41
25
42
-
Safe code may impose extra logical constraints that can be checked
43
-
at neither compile-time nor runtime. If a program breaks such
44
-
a constraint, the behavior may be unspecified but will not result in
45
-
undefined behavior. This could include panics, incorrect results,
46
-
aborts, and non-termination. The behavior may also differ between
47
-
runs, builds, or kinds of build.
48
-
49
-
For example, implementing both `Hash` and `Eq` requires that values
50
-
considered equal have equal hashes. Another example are data structures
51
-
like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet`
52
-
which describe constraints on the modification of their keys while
53
-
they are in the data structure. Violating such constraints is not
54
-
considered unsafe, yet the program is considered erroneous and
55
-
its behavior unpredictable.
26
+
Safe code may impose extra logical constraints that can be checked at neither compile-time nor runtime. If a program breaks such a constraint, the behavior may be unspecified but will not result in undefined behavior. This could include panics, incorrect results, aborts, and non-termination. The behavior may also differ between runs, builds, or kinds of build.
27
+
28
+
For example, implementing both `Hash` and `Eq` requires that values considered equal have equal hashes. Another example are data structures like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet` which describe constraints on the modification of their keys while they are in the data structure. Violating such constraints is not considered unsafe, yet the program is considered erroneous and its behavior unpredictable.
0 commit comments