Skip to content

Commit 2477068

Browse files
committed
Elaborate more on *abi compatible* and *simd abi requirements*. Remove new claims about link_section.
1 parent 51fc74a commit 2477068

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/abi.md

+20-26
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
r[abi]
44

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+
512
## ABI compatibility
613

714
r[abi.compatibility]
815

916
r[abi.compatibility.type]
1017
Two types, `T` and `U`, can be *abi compatible*.
1118

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+
1222
r[abi.compatibility.equivalence]
1323
Two types `T` and `U` are *abi compatible* if:
1424
* 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
116126

117127

118128
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.
120130

121131
r[abi.compatibility.extern-tag]
122132
Two [abi tags][abi tag] are *abi compatible* if:
@@ -139,7 +149,13 @@ Two function signatures are compatible if:
139149
r[abi.compatibility.simd-abi]
140150
A type has *simd abi requirements* if:
141151
* 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*.
143159
144160
> [!NOTE]
145161
> 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.
166182
> [!NOTE]
167183
> 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.
168184
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.
170186

171187
[`__m128`]: https://doc.rust-lang.org/stable/core/arch/x86_64/struct.__m128.html
172188
[`__m128i`]: https://doc.rust-lang.org/stable/core/arch/x86_64/struct.__m128i.html
@@ -349,16 +365,6 @@ The *`link_section` attribute* may be specified as a built-in attribute, using t
349365
r[abi.link_section.application]
350366
The *`link_section` attribute* shall be applied to a `static` or `fn` item.
351367

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-
362368
r[abi.link_section.safety]
363369
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.
364370

@@ -369,18 +375,6 @@ This attribute is unsafe as it allows users to place data and code into sections
369375
pub static VAR1: u32 = 1;
370376
```
371377

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.
382-
383-
384378
[_MetaWord_]: attributes.md#meta-item-attribute-syntax
385379
[_MetaNameValueStr_]: attributes.md#meta-item-attribute-syntax
386380
[`static` items]: items/static-items.md
@@ -389,7 +383,7 @@ pub static VAR1: u32 = 1;
389383
[`extern` block]: items/external-blocks.md
390384
[abi tag]: items/external-blocks.md#abi
391385
[function]: items/functions.md
392-
[`fn`-ptr type]: types/function-pointer.md
386+
[function pointer]: types/function-pointer.md
393387
[integer types]: types/numeric.md#integer-types
394388
[`char`]: types/textual.md
395389
[pointer types]: types/pointer.md#raw-pointers-const-and-mut

0 commit comments

Comments
 (0)