Skip to content

Commit 053c511

Browse files
authored
Merge pull request #2003 from ehuss/rewrite-abi-defs
Rework the definitions of the extern ABIs
2 parents a3ee4b9 + cc463db commit 053c511

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

src/items/external-blocks.md

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,16 @@ r[items.extern.abi.standard]
118118
The following ABI strings are supported on all platforms:
119119
120120
r[items.extern.abi.rust]
121-
* `unsafe extern "Rust"` --- The default ABI when you write a normal `fn foo()` in any Rust code.
121+
* `unsafe extern "Rust"` --- The native calling convention for Rust functions and closures. This is the default when a function is declared without using [`extern fn`]. The Rust ABI offers no stability guarantees.
122122
123123
r[items.extern.abi.c]
124-
* `unsafe extern "C"` --- This is the same as `extern fn foo()`; whatever the default your C compiler supports.
124+
* `unsafe extern "C"` --- The "C" ABI matches the default ABI chosen by the dominant C compiler for the target.
125125
126126
r[items.extern.abi.system]
127-
* `unsafe extern "system"` --- Usually the same as `extern "C"`, except on Win32, in which case it's `"stdcall"`, or what you should use to link to the Windows API itself.
127+
* `unsafe extern "system"` --- This is equivalent to `extern "C"` except on Windows x86_32 where it is equivalent to `"stdcall"`.
128+
129+
> [!NOTE]
130+
> As the correct underlying ABI on Windows is target-specific, it's best to use `extern "system"` when attempting to link Windows API functions that don't use an explicitly defined ABI.
128131
129132
r[items.extern.abi.unwind]
130133
* `extern "C-unwind"` and `extern "system-unwind"` --- Identical to `"C"` and `"system"`, respectively, but with [different behavior][unwind-behavior] when the callee unwinds (by panicking or throwing a C++ style exception).
@@ -133,32 +136,83 @@ r[items.extern.abi.platform]
133136
There are also some platform-specific ABI strings:
134137
135138
r[items.extern.abi.cdecl]
136-
* `unsafe extern "cdecl"` --- The default for x86_32 C code.
139+
* `unsafe extern "cdecl"` --- The calling convention typically used with x86_32 C code.
137140
* Only available on x86_32 targets.
141+
* Corresponds to MSVC's `__cdecl` and GCC and clang's `__attribute__((cdecl))`.
142+
143+
> [!NOTE]
144+
> For details, see:
145+
>
146+
> - <https://learn.microsoft.com/en-us/cpp/cpp/cdecl>
147+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl>
138148
139149
r[items.extern.abi.stdcall]
140-
* `unsafe extern "stdcall"` --- The default for the Win32 API on x86_32.
150+
* `unsafe extern "stdcall"` --- The calling convention typically used by the [Win32 API] on x86_32.
141151
* Only available on x86_32 targets.
152+
* Corresponds to MSVC's `__stdcall` and GCC and clang's `__attribute__((stdcall))`.
153+
154+
> [!NOTE]
155+
> For details, see:
156+
>
157+
> - <https://learn.microsoft.com/en-us/cpp/cpp/stdcall>
158+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall>
142159
143160
r[items.extern.abi.win64]
144-
* `unsafe extern "win64"` --- The default for C code on x86_64 Windows.
161+
* `unsafe extern "win64"` --- The Windows x64 ABI.
145162
* Only available on x86_64 targets.
163+
* "win64" is the same as the "C" ABI on Windows x86_64 targets.
164+
* Corresponds to GCC and clang's `__attribute__((ms_abi))`.
165+
166+
> [!NOTE]
167+
> For details, see:
168+
>
169+
> - <https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions>
170+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_x64_calling_convention>
146171
147172
r[items.extern.abi.sysv64]
148-
* `unsafe extern "sysv64"` --- The default for C code on non-Windows x86_64.
173+
* `unsafe extern "sysv64"` --- The System V ABI.
149174
* Only available on x86_64 targets.
175+
* "sysv64" is the same as the "C" ABI on non-Windows x86_64 targets.
176+
* Corresponds to GCC and clang's `__attribute__((sysv_abi))`.
177+
178+
> [!NOTE]
179+
> For details, see:
180+
>
181+
> - <https://wiki.osdev.org/System_V_ABI>
182+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI>
150183
151184
r[items.extern.abi.aapcs]
152-
* `unsafe extern "aapcs"` --- The default for ARM.
185+
* `unsafe extern "aapcs"` --- The soft-float ABI for ARM.
153186
* Only available on ARM32 targets.
187+
* "aapcs" is the same as the "C" ABI on soft-float ARM32.
188+
* Corresponds to clang's `__attribute__((pcs("aapcs")))`.
189+
190+
> [!NOTE]
191+
> For details, see:
192+
>
193+
> - [Arm Procedure Call Standard](https://developer.arm.com/documentation/107656/0101/Getting-started-with-Armv8-M-based-systems/Procedure-Call-Standard-for-Arm-Architecture--AAPCS-)
154194
155195
r[items.extern.abi.fastcall]
156-
* `unsafe extern "fastcall"` --- The `fastcall` ABI --- corresponds to MSVC's `__fastcall` and GCC and clang's `__attribute__((fastcall))`.
196+
* `unsafe extern "fastcall"` --- A "fast" variant of stdcall that passes some arguments in registers.
157197
* Only available on x86_32 targets.
198+
* Corresponds to MSVC's `__fastcall` and GCC and clang's `__attribute__((fastcall))`.
199+
200+
> [!NOTE]
201+
> For details, see:
202+
>
203+
> - <https://learn.microsoft.com/en-us/cpp/cpp/fastcall>
204+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_fastcall>
158205
159206
r[items.extern.abi.thiscall]
160-
* `unsafe extern "thiscall"` --- The default for C++ member functions on x86_32 MSVC --- corresponds to MSVC's `__thiscall` and GCC and clang's `__attribute__((thiscall))`.
207+
* `unsafe extern "thiscall"` --- The calling convention typically used on C++ class member functions on x86_32 MSVC.
161208
* Only available on x86_32 targets.
209+
* Corresponds to MSVC's `__thiscall` and GCC and clang's `__attribute__((thiscall))`.
210+
211+
> [!NOTE]
212+
> For details, see:
213+
>
214+
> - <https://en.wikipedia.org/wiki/X86_calling_conventions#thiscall>
215+
> - <https://learn.microsoft.com/en-us/cpp/cpp/thiscall>
162216
163217
r[items.extern.abi.efiapi]
164218
* `unsafe extern "efiapi"` --- The ABI used for [UEFI] functions.
@@ -485,6 +539,7 @@ restrictions as [regular function parameters].
485539
[WebAssembly module]: https://webassembly.github.io/spec/core/syntax/modules.html
486540
[`bundle` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-bundle
487541
[`dylib` versus `raw-dylib`]: #dylib-versus-raw-dylib
542+
[`extern fn`]: items.fn.extern
488543
[`unsafe` context]: ../unsafe-keyword.md
489544
[`verbatim` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-verbatim
490545
[`whole-archive` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive
@@ -494,4 +549,5 @@ restrictions as [regular function parameters].
494549
[statics]: static-items.md
495550
[unwind-behavior]: functions.md#unwinding
496551
[value namespace]: ../names/namespaces.md
552+
[win32 api]: https://learn.microsoft.com/en-us/windows/win32/api/
497553
[`link_ordinal`]: items.extern.attributes.link_ordinal

0 commit comments

Comments
 (0)