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
+20-26
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,23 @@
2
2
3
3
r[abi]
4
4
5
+
This section documents features that affect the ABI of the compiled output of
6
+
a crate.
7
+
8
+
See *[extern functions]* for information on specifying the ABI for exporting
9
+
functions. See *[`extern` block]s* for information on specifying the ABI for
10
+
linking external libraries.
11
+
5
12
## ABI compatibility
6
13
7
14
r[abi.compatibility]
8
15
9
16
r[abi.compatibility.type]
10
17
Two types, `T` and `U`, can be *abi compatible*.
11
18
19
+
> [!NOTE]
20
+
> *abi compatible* types can be used in place of each other in signatures when calling via [function pointer] at runtime (via pointer, or [`extern` block]).
21
+
12
22
r[abi.compatibility.equivalence]
13
23
Two types `T` and `U` are *abi compatible* if:
14
24
* They are the same type,
@@ -116,7 +126,7 @@ If `T` is a type listed in [layout.enum.option](https://doc.rust-lang.org/stable
116
126
117
127
118
128
r[abi.compatibility.fn-ptr]
119
-
An [`fn`-ptr type]`T` is *abi compatible* with an [`fn`-ptr type]`U` if `T` and `U` have *abi compatible* tags.
129
+
An [function pointer] type `T` is *abi compatible* with an [function pointer] type`U` if `T` and `U` have *abi compatible* tags.
120
130
121
131
r[abi.compatibility.extern-tag]
122
132
Two [abi tags][abi tag] are *abi compatible* if:
@@ -139,7 +149,13 @@ Two function signatures are compatible if:
139
149
r[abi.compatibility.simd-abi]
140
150
A type has *simd abi requirements* if:
141
151
* It is a type declared with the standard-library repr-attribute `simd`, or
142
-
* It is a aggregate type[^1], which has a type with *simd abi requirements* as a field.
152
+
* It is a aggregate type[^aggregate], which has a type with *simd abi requirements* as a field.
153
+
154
+
> [!NOTE]
155
+
> Types with *simd abi requirements* may be passed using special registers that aren't always available to code.
156
+
157
+
> [!NOTE]
158
+
> Notably References and pointers to types with *simd abi requirements* do not have *simd abi requirements*.
143
159
144
160
> [!NOTE]
145
161
> The `repr(simd)` attribute cannot be used by Rust code, only by the standard library.
@@ -166,7 +182,7 @@ The behavior of a call that is not valid is undefined.
166
182
> [!NOTE]
167
183
> The ABI tag `extern "Rust"` is the default when the `extern` keyword is not used (either to declare the function within an [`extern` block], or as a [function qualifier][extern functions]). Thus it is safe to call most functions that use simd types.
168
184
169
-
[^1]: The aggregate types, for the purposes of this clause, are [`struct`] types, [`enum`] types, [`union`] types, and [array] types.
185
+
[^aggregate]: The aggregate types, for the purposes of this clause, are [`struct`] types, [`enum`] types, [`union`] types, and [array] types.
@@ -349,16 +365,6 @@ The *`link_section` attribute* may be specified as a built-in attribute, using t
349
365
r[abi.link_section.application]
350
366
The *`link_section` attribute* shall be applied to a `static` or `fn` item.
351
367
352
-
353
-
r[abi.link_section.def]
354
-
An item with the *`link_section` attribute* is placed in the specified section when linking. The section specified shall not violate the constraints on section names on the target, and shall not be invalid for the item type, no diagnostic is required.
355
-
356
-
> [!NOTE]
357
-
> A section name may be invalid if it violates the requirements for the item type, for example, an `fn` item must be placed in an executable section, and a mutable static item (`static mut` or one containing an `UnsafeCell`) must be placed in a writable section.
358
-
> The required format and any restrictions on section names are target-specific.
359
-
>
360
-
> The result of using an invalid section name may be that the section is placed into the section but cannot be used as applicable, or that the section is given additional attributes that may be incompatible when linking.
361
-
362
368
r[abi.link_section.safety]
363
369
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.
364
370
@@ -369,18 +375,6 @@ This attribute is unsafe as it allows users to place data and code into sections
369
375
pub static VAR1: u32 = 1;
370
376
```
371
377
372
-
> [!TARGET-SPECIFIC]
373
-
> On ELF Platforms, the standard section names, and their attributes are:
374
-
> *`.text`: Readable and Executable,
375
-
> *`.rodata`: Readable,
376
-
> *`.data`: Readable and Writable,
377
-
> *`.bss`: Readable and Writable - Uninitialized data,
378
-
> *`.tdata`: Readable and Writable - Thread-local,
379
-
> *`.tbss`: Readable and Writable - Uninitialized and Thread-local.
380
-
>
381
-
> This is not an exhaustive list, and generally extended versions of these section names such as `.text.foo`, are also defined with the same properties as the base section.
0 commit comments