System V ABI: Difference between revisions

m
Updated document link
[unchecked revision][unchecked revision]
(Add information about -fomit-frame-pointer)
m (Updated document link)
 
(11 intermediate revisions by 4 users not shown)
Line 1:
The '''System V Application Binary Interface''' is a set of specifications that detail [[Calling Conventions|calling conventions]], [[Object Files|object file formats]], [[Executable Formats|executable file formats]], dynamic linking semantics, and much more for systems that complies with the ''X/Open Common Application Environment Specification'' and the ''System V Interface Definition''. It is today the standard ABI used by the major Unix operating systems such as Linux, the BSD systems, and many others. The [[Executable and Linkable Format]] ((ELF) is part of the System V ABI.
 
The ABI is organized as a portable base document and platform-specific supplements that fill in the blank gaps. Unofficial new architecture processor supplements have been published as the format has been adapted to new platforms such as [[X86-64]]. The standard is extensible and the format continues to evolve as Unix vendors add new features. Due to the many unofficial supplement specifications and the chaotic history of the Unix operating systems, the current situation is that the System V ABI has become a family of unofficial draft specifications with no real central governing body.
 
Many of the advanced feature such as dynamic linking are optional and loading a simple statically linked [[ELF]] program is straightforward. Earlier versions of the standard were more ambitious and attempted to standardize software package installation formats and X11 details, while these obsolete details are disregarded today. The ABI is well-understood by common operating system's development tools like [[binutilsBinutils]] and [[GCC]]. Toolchains such as <tt>i686-elf-gcc</tt> generate code and executable files according to this ABI.
 
== Executable and Linkable Format ==
Line 16:
=== i386 ===
 
This is a 32-bit platform. The stack grows downwards. Parameters to functions are passed on the stack in reverse order such that the first parameter is the last value pushed to the stack, which will then be the lowest value on the stack. Parameters passed on the stack may be modified by the called function. Functions are called using the <tt>call</tt> instruction that pushes the address of the next instruction to the stack and jumps to the operand. Functions return to the caller using the <tt>ret</tt> instruction that pops a value from the stack and jump to it. The stack is 4-byte aligned all the time, on older systems and those honouring the SYSV psABI. On some newer systems, the stack is additionally 16-byte aligned just before the call instruction is called (usually those that want to support SSE instructions); consult your manual (GNU/Linux on i386 has recently become such a system, but code mixing with 4-byte stack alignment-assuming code is possible).
 
Functions preserve the registers <tt>ebx</tt>, <tt>esi</tt>, <tt>edi</tt>, <tt>ebp</tt>, and <tt>esp</tt>; while <tt>eax</tt>, <tt>ecx</tt>, <tt>edx</tt> are scratch registers. The return value is stored in the <tt>eax</tt> register, or if it is a 64-bit value, then the higher 32-bits go in <tt>edx</tt>. Functions push <tt>ebp</tt> such that the <tt>caller-return-eip</tt> is 4 bytes above it, and set <tt>ebp</tt> to the address of the saved ebp. This allows iterating through the existing stack frames. This can be eliminated by specifying the <tt>-fomit-frame-pointer</tt> GCC option.
 
Additionally, if you compile with [[GCC]], it assumes the stack is 16-byte aligned (not just 4-byte aligned) when the <tt>call</tt> instruction in the caller was executed. This is required to properly store SSE values on the stack, as they require 16-byte alignment, or other values (such as 64-bit values) with higher-than-4-byte alignment. As a special exception, GCC assumes the stack is not properly aligned and realigns it when entering <tt>main</tt> or if the <tt>attribute ((force_align_arg_pointer))</tt> is set on the function.
 
=== x86-64 ===
Line 33:
 
=== Documents ===
'''TODO:''' ''Ensure whether these are the latest official links. These documents are simply what I foundcould find through a quick online search.''
* base document and addons
* [http://www.sco.com/developers/gabi/latest/contents.html System V ABI - Latest Base Document]
** [http://www.sco.com/developers/devspecsgabi/gabi41latest/contents.pdfhtml System V ABI - OlderLatest Base Document]
** [http://www.sco.com/developers/devspecs/abi386-4gabi41.pdf System V ABI - Intel386 ArchitectureOlder ProcessorBase SupplementDocument]
** [http://www.x86-64akkadia.org/documentationdrepper/abitls.pdf SystemELF VHandling ABIFor Thread-Local AMD64 Architecture Processor SupplementStorage]
* x86 (i8086, i386, amd64, x32, k1om)
* [http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf System V ABI - MIPS RISC Processor Supplement]
** [httphttps://math-atlas.sourceforgegitlab.netcom/develx86-psABIs/assembly/mipsabi64.pdfx86-64-ABI System V ABI - MIPSpro™AMD64 64-BitArchitecture Processor Supplement]
** [http://math-atlaswww.sourceforgesco.netcom/develdevelopers/assemblydevspecs/007abi386-2816-0054.pdf System V ABI - MIPSpro™Intel386 N32Architecture ABIProcessor HandbookSupplement]
** [http://math-atlassoftware.sourceforgeintel.netcom/develsites/assemblydefault/elfspec_ppcfiles/forum/278102/k1om-psabi-1.0.pdf System V ABI - PowerPCK1OM Architecture Processor Supplement]
* MIPS
* [http://math-atlas.sourceforge.net/devel/assembly/PPC-elf64abi-1.7.pdf System V ABI - 64-bit PowerPC]
** [http://math-atlas.sourceforge.net/devel/assembly/abi_sysV_sparcmipsabi32.pdf System V ABI - SPARC®MIPS RISC Processor Supplement]
** [http://math-atlas.sourceforge.net/devel/assembly/64.psabi.1.33.psmipsabi64.Zpdf System V ABI - SPARC®MIPSpro™ Version 9 Processor Supplement64-Bit]
** [http://softwaremath-atlas.intelsourceforge.comnet/sitesdevel/defaultassembly/files/forum/278102/k1om007-psabi2816-1.0005.pdf System V ABI - K1OMMIPSpro™ ArchitectureN32 ProcessorABI SupplementHandbook]
* PowerPC
* [http://www.csee.umbc.edu/portal/help/architecture/24537001.pdf System V ABI - IA-64 Architecture Processor Supplement]
** [http://math-atlas.sourceforge.net/devel/assembly/mipsabi32elfspec_ppc.pdf System V ABI - MIPS RISCPowerPC Processor Supplement]
* [http://www.akkadia.org/drepper/tls.pdf ELF Handling For Thread-Local Storage]
** [http://math-atlas.sourceforge.net/devel/assembly/PPC-elf64abi-1.7.pdf System V ABI - 64-bit PowerPC]
* SPARC
** [http://math-atlas.sourceforge.net/devel/assembly/abi_sysV_sparc.pdf System V ABI - SPARC® Processor Supplement]
** [http://math-atlas.sourceforge.net/devel/assembly/64.psabi.1.33.ps.Z System V ABI - SPARC® Version 9 Processor Supplement]
* Itanium
** [http://www.csee.umbc.edu/portal/help/architecture/24537001.pdf System V ABI - IA-64 Architecture Processor Supplement]
* ⚠ not SYSV ABI, but at least the architecture-official calling standards:
** [http://bitsavers.trailing-edge.com/pdf/dec/alpha/Alpha_Calling_Standard_Rev_2.0_19900427.pdf DEC Alpha calling standard]
 
===External Links===
* [http://www.sco.com/developers/gabi/ System V ABI Website]
* [https://refspecs.linuxfoundation.org/ Linux Foundation — Referenced Specifications]
* [https://course.ece.cmu.edu/~ece447/s15/doku.php?id=techdocs Introduction to Computer Architecture — Technical Documents]
 
[[Category:ABI]]
Anonymous user