Skip to content

Commit d77c6b8

Browse files
committed
Rework the definitions of the extern ABIs
This updates the definitions of the extern ABIs to try to make them a little clearer as to what they mean. This also adds new statements about the equivalence of some ABIs to the "C" ABI.
1 parent 02bf556 commit d77c6b8

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

src/items/external-blocks.md

Lines changed: 37 additions & 9 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 the function's ABI is not specified. 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 attempts to match 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 otherwise use a different 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,33 +136,57 @@ 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.
138141
142+
> [!NOTE]
143+
> See <https://learn.microsoft.com/en-us/cpp/cpp/cdecl> and <https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl> for more information.
144+
139145
r[items.extern.abi.stdcall]
140-
* `unsafe extern "stdcall"` --- The default for the Win32 API on x86_32.
146+
* `unsafe extern "stdcall"` --- The calling convention typically used by the [Win32 API] on x86_32.
141147
* Only available on x86_32 targets.
142148
149+
> [!NOTE]
150+
> See <https://learn.microsoft.com/en-us/cpp/cpp/stdcall> and <https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall> for more information.
151+
143152
r[items.extern.abi.win64]
144-
* `unsafe extern "win64"` --- The default for C code on x86_64 Windows.
153+
* `unsafe extern "win64"` --- The Windows x64 ABI.
145154
* Only available on x86_64 targets.
155+
* "win64" is the same as the "C" ABI on Windows x86_64 targets.
156+
157+
> [!NOTE]
158+
> See <https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions> and <https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_x64_calling_convention> for more information.
146159
147160
r[items.extern.abi.sysv64]
148-
* `unsafe extern "sysv64"` --- The default for C code on non-Windows x86_64.
161+
* `unsafe extern "sysv64"` --- The System V ABI.
149162
* Only available on x86_64 targets.
163+
* "sysv64" is the same as the "C" ABI on non-Windows x86_64 targets.
164+
165+
> [!NOTE]
166+
> See <https://wiki.osdev.org/System_V_ABI> or <https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI> for more information.
150167
151168
r[items.extern.abi.aapcs]
152-
* `unsafe extern "aapcs"` --- The default for ARM.
169+
* `unsafe extern "aapcs"` --- The soft-float ABI for ARM.
153170
* Only available on ARM32 targets.
171+
* "aapcs" is the same as the "C" ABI on soft-float ARM32.
172+
173+
> [!NOTE]
174+
> See [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-) for more information.
154175
155176
r[items.extern.abi.fastcall]
156177
* `unsafe extern "fastcall"` --- The `fastcall` ABI --- corresponds to MSVC's `__fastcall` and GCC and clang's `__attribute__((fastcall))`.
157178
* Only available on x86_32 targets.
158179
180+
> [!NOTE]
181+
> See <https://learn.microsoft.com/en-us/cpp/cpp/fastcall> and <https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_fastcall> for more information.
182+
159183
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))`.
184+
* `unsafe extern "thiscall"` --- The calling convention typically used on C++ class member functions on x86_32 MSVC --- corresponds to MSVC's `__thiscall` and GCC and clang's `__attribute__((thiscall))`.
161185
* Only available on x86_32 targets.
162186
187+
> [!NOTE]
188+
> See <https://en.wikipedia.org/wiki/X86_calling_conventions#thiscall> and <https://learn.microsoft.com/en-us/cpp/cpp/thiscall> for more information.
189+
163190
r[items.extern.abi.efiapi]
164191
* `unsafe extern "efiapi"` --- The ABI used for [UEFI] functions.
165192
* Only available on x86 and ARM targets (32bit and 64bit).
@@ -494,4 +521,5 @@ restrictions as [regular function parameters].
494521
[statics]: static-items.md
495522
[unwind-behavior]: functions.md#unwinding
496523
[value namespace]: ../names/namespaces.md
524+
[win32 api]: https://learn.microsoft.com/en-us/windows/win32/api/
497525
[`link_ordinal`]: items.extern.attributes.link_ordinal

0 commit comments

Comments
 (0)