Application binary interface

A high-level comparison of in-kernel and kernel-to-userspace APIs and ABIs
The Linux kernel and GNU C Library define the Linux API. After compilation, the binaries offer an ABI. Keeping this ABI stable over a long time is important for ISVs.

An application binary interface (ABI) is an interface exposed by software that is defined for in-process machine code access. Often, the exposing software is a library, and the consumer is a program.

An ABI is at a relatively low level of abstraction. Interface compatibility depends on the target hardware and the software build toolchain. In contrast, an application programming interface (API) defines access in source code, which is a relatively high-level, hardware-independent, and human-readable format. An API defines an interface at the source code level, before compilation, whereas an ABI defines an interface to compiled code.

API compatibility is generally the concern for system design and of the toolchain. However, a programmer may have to deal with an ABI directly when writing a program in multiple languages or when using multiple compilers for the same language.

A complete ABI enables a program that supports an ABI to run without modification on multiple operating systems that provide the ABI. The target system must provide any required libraries (that implement the ABI), and there may be other prerequisites.

Description

Interface aspects covered by an ABI include:

  • Processor instruction set, with details like register file structure, memory access types, etc.
  • Size, layout, and alignment of basic data types that the processor can directly access
  • Calling convention, which controls how the arguments of functions are passed, and return values retrieved; for example, it controls the following:
    • How the call stack is organized
    • Whether all parameters are passed on the call stack, or some are passed in registers
    • Which registers are used for which function parameters
    • Which registers should be preserved by the callee (restore its value if changed)
    • Whether the first function parameter passed on the call stack is pushed first or last
    • Whether the caller or callee is responsible for cleaning up the call stack after the function call
  • Stack unwinding (setjmp/longjmp)
  • Name mangling, or how an API entity is named in the resulting object file (not in C)[1]
  • Exception propagation (not in C)[2]
  • How an application should make system calls to the operating system, and if the ABI specifies direct system calls rather than procedure calls to system call stubs, the system call numbers
  • In the case of a complete operating system ABI, the binary format of object files, program libraries, etc.

Example ABIs include the obsolete Intel Binary Compatibility Standard (iBCS),[3], the System V Release 4 ABIs for various instruction set architectures (ISAs) used by many Unix-like systems, and the Microsoft Windows ABIs for various ISAs.[4]

Embedded ABI

An embedded ABI (EABI), used on an embedded operating system, specifies aspects such as file formats, data types, register usage, stack frame organization, and function parameter passing of an embedded software program.

Each compiler and assembler that supports an EABI creates object code that is compatible with code generated by other such compilers and assemblers. This allows developers to link libraries generated by one compiler with object code generated by another.

Typically, an EABI is optimized for performance for the limited resources of the target embedded system. Therefore, an EABI may omit abstractions between kernel and user space typically found in desktop operating systems. For example, dynamic linking may be avoided to allow smaller executables and faster loading, fixed register usage allows more compact stacks and kernel calls, and running the application in privileged mode allows direct access to custom hardware operation without the indirection of calling a device driver.[5] The choice of EABI can affect performance.[6][7]

Widely used EABIs include the PowerPC,[5] Arm,[8] and MIPS EABIs.[9] Specific software implementations like the C library may impose additional limitations to form more concrete ABIs; one example is the GNU OABI and EABI for ARM, both of which are subsets of the ARM EABI.[10] Another point of distinction is whether optional features such as hardware floating-point is present. For example, in GCC and LLVM, armv7-unknown-linux-musleabi, armv7-unknown-linux-musleabihf both refer to GNU EABI with the musl C library, except the latter uses hardware floating-point and therefore has a slightly different call convention.[11]

Language ABIs

Each programming language may use a different set of features and data types. If there is no existing ABI for a feature, the language often needs to define its own ABI as an extension of the existing ABI.

C

The official website of the C programming language describes C as a lingua franca in foreign function interfaces (FFIs: function calls between different programming languages).[12] Many languages define their FFIs around the C ABI, for example the extern "C" of Rust and C++.[13] This is because almost every current operating system, both Unix-like and Windows, provides an agreed-upon C ABI. These systems themselves mainly provide a C API, which depends upon a C ABI for functioning, hence the ubiquity of a C ABI.[14] (Furthermore, C is relatively limited in what it requires of the ABI rules compared to other languages, only requiring definition of data structure layout and calling convention.)[15]

Nevertheless, C was not originally designed to serve in this role, and the ABI has been criticized for many of its perceived deficiencies as an FFI:

  • C ABIs are defined by C APIs, which are defined in C header files. However, C header files are very hard to parse and most FFI implementations resort to calling the compiler.[11]
  • C ABIs define interpretations for C-specific types such as long long, time_t, intmax_t. These choices of types are set in stone by the ABI, but there exist valid reasons to change them, which ends up breaking the ABI.[16]
  • C ABIs do not have parts required to support features in other languages, e.g. type safety and memory safety.[13]

C++

There is no portable C++ ABI: even on the same operating system, different compilers (or combination of compiler and standard library implementations) may use different ABIs.[13] Most C++ ABIs are extensions on top of the C ABI, filling in the missing name mangling (required for function overloading) and exception handling details. In modern systems two main schemes are encountered: Microsoft's Visual C++ scheme and the Itanium scheme.[1]

Although the ABI documents define the rules for transforming identifiers into names, they do not define the whole ABI surface of the standard library, leaving it to the specific standard library implementation (see section "Library ABI" below). As a result, each implementation has its own ABI; even on the same architecture and operating system, two object files end up having different ABIs if linked to standard libraries with incompatible ABIs.[13] In 2015, GCC/libstdc++ revised its implementation of std::string, leading to an ABI change. Even though the new library supports both ABIs, users still had to make a choice between the old ABI and the new ABI, as this determines what precompiled libraries their programs can be linked to.[17] Similarly, Visual C++ does not guarantee compatibility when code produced by different versions of the compiler (intended for different versions of the runtime library) are linked together.[18]

Library ABI

As defined above the "ABI" documents describe how an API is transformed into a concrete form at the assembly language level. In the case of libraries, the term "ABI" instead refers to the concrete interface resulting from the transformation of ABI.[19] For example, changing the type signature of a function, either directly or indirectly (e.g. by changing the definition of a struct used by the function), often changes the ABI to the point of incompatibility, an "ABI break".[20][21]

Because operating systems include a number of libraries for use by the programmer, their ABIs also include the library ABIs. The Linux Standard Base specifications, for example, includes details about what the symbol tables of certain libraries should contain, what API they correspond to, and that SysV ABI should be used.[22] This kind of distinctions matter for compilers and other kinds of code generators; in the case of GCC and LLVM, each option is given a name called a target triple. (The choice of a standard library implementation also affects the ABI: for example, musl and uClibc for ARMv7 GNU EABI as well as libstdc++ and Microsoft Visual C++ for x64 Windows each have different triples.)[11]

See also

References

  1. ^ a b "Itanium C++ ABI". (compatible with multiple architectures)
  2. ^ "Itanium C++ ABI: Exception Handling". (compatible with multiple architectures)
  3. ^ "Intel Binary Compatibility Standard (iBCS)".
  4. ^ "x64 Calling Convention". learn.microsoft.com.
  5. ^ a b "EABI Summary". PowerPC Embedded Application Binary Interface: 32-Bit Implementation (PDF) (Version 1.0 ed.). Freescale Semiconductor, Inc. 1 October 1995. pp. 28–30.
  6. ^ "Debian ARM accelerates via EABI port". Linuxdevices.com. 16 October 2016. Archived from the original on 21 January 2007. Retrieved 11 October 2007.
  7. ^ Andrés Calderón and Nelson Castillo (14 March 2007). "Why ARM's EABI matters". Linuxdevices.com. Archived from the original on 31 March 2007. Retrieved 11 October 2007.
  8. ^ "ABI for the Arm Architecture". Developer.arm.com. Retrieved 4 February 2020.
  9. ^ Eric Christopher (11 June 2003). "mips eabi documentation". [email protected] (Mailing list). Retrieved 19 June 2020.
  10. ^ "ArmEabiPort". Debian Wiki. Strictly speaking, both the old and new ARM ABIs are subsets of the ARM EABI specification, but in everyday usage the term "EABI" is used to mean the new one described here and "OABI" or "old-ABI" to mean the old one.
  11. ^ a b c Desires, Aria (16 March 2022). "C Isn't A Programming Language Anymore - Faultlore".
  12. ^ "C language: FAQ". www.c-language.org.
  13. ^ a b c d Sutter, Herb (2014). "Defining a Portable C++ ABI" (PDF).
  14. ^ "Why C is still the most important programming language". DEV Community. 7 January 2026.
  15. ^ "tool-conventions/BasicCABI.md at main · WebAssembly/tool-conventions". GitHub.
  16. ^ "To Save C, We Must Save ABI". The Pasture. 13 March 2022.
  17. ^ "Dual ABI". gcc.gnu.org.
  18. ^ "C++ binary compatibility 2015-2026". learn.microsoft.com.
  19. ^ "libcurl - ABI". curl.se.
  20. ^ "Application Binary Interface (ABI) - pypackaging-native". pypackaging-native.github.io.
  21. ^ Winters, T (2020). "What is ABI, and What Should WG21 Do About It?" (PDF).
  22. ^ "Interfaces for libc (LSB 5.0 PPC64)". refspecs.linuxfoundation.org.

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.