Where is the x86-64 System V ABI documented?
Asked Answered
A

3

91

The x86-64 System V ABI (used on everything except Windows) used to live at http://x86-64.org/documentation/abi.pdf, but that site has now fallen off the internet.

Is there a new authoritative home for the document?

Alexina answered 8/8, 2013 at 18:50 Comment(4)
The 0.99.6 draft is the latest version I'm aware of. To get around the broken link on the referring page, try here.Hoxsie
The www.x86-64.org site has now fallen back on the planet, after a brief one year hiatus. I don't think we'll ever know, but I would love to know the backstory there. :) AMD slashes budget by $100 worth of hosting fees?Ocker
agner.org/optimize/calling_conventions.pdfVulnerary
Would also love to know the backstory. web.archive.org/web/20160609221003/http://www.x86-64.org/… is still a useful what's-new-in-x86-64 guide for beginners who followed a 32-bit tutorial and are now confused by x86-64. Really glad the Wayback machine exists.General
G
99

The System V AMD64 psABI document is maintained as LaTeX sources on GitLab. Similarly the i386 psABI is a separate GitLab repo. (Formerly on github). Those pages have info on where revisions are discussed.
The x32 ABI (32-bit pointers in long mode) is part of the x86-64 aka AMD64 ABI doc. See Chapter 10: ILP32 Programming Model.

The GitLab repo auto-builds a PDF of the current x86-64 version, but not i386.

See also the tag wiki for other guides / references / links.


The last version on Github was x86-64 version 1.0 draft (January 2018). As of July 2022, the current version is still 1.0, with the word Draft being removed by late 2018.

Github also hosts a PDF of i386 ABI version 1.1.
(Note that most non-Linux OSes use an older version of the i386 ABI which doesn't require 16-byte stack alignment, only 4. GCC ended up depending on -mpreferred-stack-boundary=4 16-byte alignment for its SSE code-gen (perhaps unintentionally), and eventually the ABI got updated for Linux to enshrine that as an official requirement. I attempted a summary in a comment on GCC bug #40838. This breaks backwards compat with some hand-written asm that calls other functions.)

Unofficially, sign-extending narrow args to 32-bit is required (for both i386 and amd64), because clang depends on it. Hopefully a future ABI revision will document that. GCC and/or clang now have some options to control that (TODO dig up what they were called), but the default is still the same as of 2022.


Naming: psABI

The Processor Supplement (psABI) docs are designed as a supplement to the less-frequently-updated System V gABI (generic), hosted on SCO's website.


Other links

Also https://refspecs.linuxfoundation.org/ hosts a copy of the gABI from 1997.

https://uclibc.org/specs.html has psABI links for various non-x86 ISAs. (Although for example the ARM one only seems to document the ELF file layout, not the calling convention or process startup state.) https://uclibc.org/docs/psABI-x86_64.pdf is an outdated copy of the x86-64 psABI (0.99.7 from 2014). The version on GitHub has clearer wording of a few things and bugfixes in some examples.


Related: What are the calling conventions for UNIX & Linux system calls (and user-space functions) on i386 and x86-64 describes the system-call calling convention for x86-64 SysV (as well as i386 Linux vs. FreeBSD).

It also summarizes the function calling conventions for integer args. System calls don't take FP or SSE/AVX vector args, or structs by value, so the function-calling convention is more complicated.


Agner Fog has a calling conventions guide (covering Windows vs. Sys V, and the various conventions for 32-bit, and tips/tricks for writing functions you can use on either platform). This is a separate PDF from his optimization and microarchitecture guides and instruction tables (which are essential reading if you care about performance.)

Wikipedia has an x86 calling conventions article which describes various conventions, but mostly not in enough detail to use them for anything other than simple integer args. (e.g. no description of struct-packing rules).


Related: C++ ABI

GCC and Clang (on all architectures) use the C++ ABI originally developed for Itanium. https://itanium-cxx-abi.github.io/cxx-abi/. This is relevant for example for what requirements a C++ struct/class need to be passed in registers (e.g. being an aggregate according to some definition), vs. when a struct/class always needs to have an address and get passed by reference, even when it's small enough to pack into 2 registers. These rules depend on stuff having a non-trivial constructor or destructor.

General answered 31/10, 2016 at 18:11 Comment(7)
The X32 ABI is located at X32 System V Application Binary Interface. Its a Google site, not a GitHub; but it appears to be maintained by H.J. Lu. I wonder why X32 is not in the same place.Elastin
@jww: x32 is documented in Chapter 10 of the main x86-64 psABI PDF, at least in the current draft 0.99.8 version. Maybe it used to be a separate PDF.General
Here's the Intel versionFiume
The github page now points people to gitlab.com/x86-psABIs/x86-64-ABI instead. Unfortunately it doesn't look like there is a prebuilt PDF anymore.Bahadur
Using the prebuilts there's the link for the latest x86-64 PDF gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/… but not for i386Fail
what about sco.com/developers/gabi is this also the official source ?Biskra
@AkashR: Yes, for the generic part of the SysV ABI, to which the AMD64 psABI is a "processor supplement". That's why my answer already links sco.com/developers/gabiGeneral
G
6

Linux standard base

The Linux Standard Base, which can be considered by some the authoritative spec for this matter, has section called 7.2. "Function Calling Sequence" points to the 2.1. "Normative References section" which contains the following links:

I would therefore recommend using those versions of the specifications as the canonical ones unless you have good reason to do otherwise.

Germicide answered 17/3, 2019 at 12:18 Comment(0)
V
4

The current version of the System V ABI from GitLab can be easily turned into a nice PDF with these steps, assuming an Ubuntu system.

sudo apt-get install texlive-full
git clone https://gitlab.com/x86-psABIs/x86-64-ABI
cd x86-64-ABI
make pdf

This will produce a file called abi.pdf which is the very one that is needed, as below.

Note that the date in the title appears to be the PDF's build date rather than the document's actual last modification date.

enter image description here

Vivian answered 10/9, 2020 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.