Generated by GPT-5-mini| C ABI | |
|---|---|
![]() ScotXW · CC BY-SA 3.0 · source | |
| Name | C ABI |
| Developers | Dennis Ritchie, Ken Thompson, Bell Labs |
| Introduced | 1972 |
| Influenced by | ALGOL, B language |
| Influenced | System V ABI, Microsoft x64 calling convention, ARM Procedure Call Standard |
C ABI The C ABI is the application binary interface convention associated with the C programming language family and its runtime environment. It governs interoperability between compilers, linkers, loaders, and libraries such as glibc, musl, libc++, and defines how functions, data, and exceptions interoperate across binaries produced by toolchains like GCC, Clang, MSVC, and Intel C++ Compiler. The ABI affects executables and shared objects used by operating systems and platforms such as Unix, Linux kernel, Windows NT, macOS, FreeBSD, Android, and iOS.
The ABI specifies low-level conventions for interaction between compiled modules: symbol representation used by linkers like GNU ld and Gold, object file layouts from ELF and Mach-O formats, calling and return mechanics used by processors such as x86-64, ARM architecture, RISC-V, PowerPC, and MIPS. It complements higher-level language standards from organizations like ISO/IEC JTC 1 and runtime ecosystems such as POSIX and System V. Implementations must reconcile compiler frontends from projects like LLVM and GCC with toolchain components including assemblers like GNU Assembler and debuggers like GDB.
The ABI prescribes the size, alignment, and layout of primitive types and aggregates to ensure binary compatibility between modules produced by different compilers. It defines widths for types comparable to specifications in ISO C99 and ISO C11 and for platform-specific types used on x86-64 LP64 vs ILP32 models, Windows x64 LLP64 model, and embedded targets like ARM EABI. Structure packing, endianness on architectures such as Big-endian PowerPC and Little-endian x86, and alignment rules determine offsets used by linkers and loaders. Standard calling conventions reference primitive sizes for types like pointers, integers, and floating-point types implemented via hardware units such as SSE, AVX, and NEON vector extensions; aggregate passing rules mirror behaviors required by libc implementations and language runtimes including C++ ABI variants.
Calling conventions in the C ABI dictate register usage, stack frame layout, parameter passing (in-register vs on-stack), return value locations, and callee/caller-saved registers. For x86-64 System V ABI, integer arguments are passed in registers like RDI, RSI, RDX, RCX, R8, R9 and floating-point arguments in XMM0–XMM7; for Windows x64 a distinct register set is prescribed. On ARM64 (AArch64) the ABI assigns X0–X7 for arguments and V0–V7 for floating-point. Stack alignment constraints are enforced for compatibility with runtimes such as glibc, and unwind metadata must cooperate with linkers and loaders of executables produced by toolchains like GNU Make and CMake.
The ABI defines symbol naming, visibility, and linkage semantics used by linkers and dynamic linkers such as ld.so and dyld. C linkage often employs unmangled symbols to support interoperability with assemblers and other languages; extern "C" in C++ enforces this to allow linking with Fortran or Ada runtimes. Symbol versioning, weak/strong symbol rules, and export tables are used by shared object mechanisms in ELF and PE/COFF formats. Toolchains like Binutils and build systems such as Autotools and Meson must honor these conventions to produce compatible binaries across distributions like Debian, Fedora, OpenBSD, and NetBSD.
While the C language itself lacks built-in exceptions, the ABI must interact with exception and unwinding mechanisms used by languages compiled with compatible ABIs, notably C++ and Rust. Unwind tables and personality routines described by standards such as the DWARF unwind info and used by unwinders like libunwind enable stack unwinding across mixed-language stacks. The ABI defines how stack frames and registers are saved so that runtime services in environments like LLVM's libc++abi or libgcc can perform stack walks, stack traces, and cleanup. Language runtimes and operating systems such as Linux kernel and Windows NT provide facilities for structured exception handling that compilers must bridge according to ABI conventions.
Maintaining ABI compatibility is crucial for binary distributions, shared libraries, and OS upgrades provided by vendors like Red Hat, Canonical, Apple Inc., and Microsoft. Changes to type sizes, alignment rules, calling conventions, or symbol formats can break compatibility across versions of glibc or cause subtle bugs in mixed-toolchain deployments involving GCC and Clang/LLVM. Porting to new architectures like RISC-V or ARM requires defining platform-specific ABI documents such as the System V AMD64 ABI or the ARM EABI and coordinating with compiler communities and standards bodies including ISO and IEEE. Versioning strategies, symbol compatibility techniques, and thorough conformance testing with suites used by projects like LLVM Project, GNU Project, and Free Software Foundation help preserve interoperability across diverse ecosystems.
Category:Application binary interfaces