System V Application Binary Interface
AMD64 Architecture Processor Supplement
Draft Version 0.99.4
Edited by
Michael Matz, Jan Hubicka, Andreas Jaeger, Mark Mitchell
January 13, 2010
Contents
1 Introduction 8
2 Software Installation 9
3 Low Level System Information 10
3.1 Machine Interface . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.1 Processor Architecture . . . . . . . . . . . . . . . . . . 10
3.1.2 Data Representation . . . . . . . . . . . . . . . . . . . 10
3.2 Function Calling Sequence . . . . . . . . . . . . . . . . . . . . 14
3.2.1 Registers and the Stack Frame . . . . . . . . . . . . . . 14
3.2.2 The Stack Frame . . . . . . . . . . . . . . . . . . . . . 15
3.2.3 Parameter Passing . . . . . . . . . . . . . . . . . . . . 16
3.3 Operating System Interface . . . . . . . . . . . . . . . . . . . 23
3.3.1 Exception Interface . . . . . . . . . . . . . . . . . . . 23
3.3.2 Virtual Address Space . . . . . . . . . . . . . . . . . . 23
3.3.3 Page Size . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3.4 Virtual Address Assignments . . . . . . . . . . . . . . . 23
3.4 Process Initialization . . . . . . . . . . . . . . . . . . . . . 26
3.4.1 Initial Stack and Register State . . . . . . . . . . . . . 26
3.4.2 Thread State . . . . . . . . . . . . . . . . . . . . . . . 29
3.4.3 Auxiliary Vector . . . . . . . . . . . . . . . . . . . . . 29
3.5 Coding Examples . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.5.1 Architectural Constraints . . . . . . . . . . . . . . . . 32
3.5.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . 34
3.5.3 Position-Independent Function Prologue . . . . . . . . . . 35
3.5.4 Data Objects . . . . . . . . . . . . . . . . . . . . . . 36
3.5.5 Function Calls . . . . . . . . . . . . . . . . . . . . . 44
3.5.6 Branching . . . . . . . . . . . . . . . . . . . . . . . . 46
3.5.7 Variable Argument Lists . . . . . . . . . . . . . . . . . 49
3.6 DWARF Definition . . . . . . . . . . . . . . . . . . . . . . . . 54
3.6.1 DWARF Release Number . . . . . . . . . . . . . . . . . . . 55
3.6.2 DWARF Register Number Mapping . . . . . . . . . . . . . . 55
3.7 Stack Unwind Algorithm . . . . . . . . . . . . . . . . . . . . . 55
4 Object Files 59
4.1 ELF Header . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.1.1 Machine Information . . . . . . . . . . . . . . . . . . . 59
4.1.2 Number of Program Headers . . . . . . . . . . . . . . . . 59
4.2 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.2.1 Section Flags . . . . . . . . . . . . . . . . . . . . . . 60
4.2.2 Section types . . . . . . . . . . . . . . . . . . . . . . 61
4.2.3 Special Sections . . . . . . . . . . . . . . . . . . . . 61
4.2.4 EH_FRAME sections . . . . . . . . . . . . . . . . . . . . 62
4.3 Symbol Table . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.4 Relocation . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.4.1 Relocation Types . . . . . . . . . . . . . . . . . . . . . 67
4.4.2 Large Models . . . . . . . . . . . . . . . . . . . . . . . 72
5 Program Loading and Dynamic Linking 74
5.1 Program Loading . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.1.1 Program header . . . . . . . . . . . . . . . . . . . . . . 75
5.2 Dynamic Linking . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.2.1 Program Interpreter . . . . . . . . . . . . . . . . . . . 82
5.2.2 Initialization and Termination Functions . . . . . . . . . 82
6 Libraries 83
6.1 C Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6.1.1 Global Data Symbols . . . . . . . . . . . . . . . . . . . 83
6.1.2 Floating Point Environment Functions . . . . . . . . . . . 83
6.2 Unwind Library Interface . . . . . . . . . . . . . . . . . . . . 84
6.2.1 Exception Handler Framework . . . . . . . . . . . . . . . 85
6.2.2 Data Structures . . . . . . . . . . . . . . . . . . . . . 87
6.2.3 Throwing an Exception . . . . . . . . . . . . . . . . . . 89
6.2.4 Exception Object Management . . . . . . . . . . . . . . . 92
6.2.5 Context Management . . . . . . . . . . . . . . . . . . . . 92
6.2.6 Personality Routine . . . . . . . . . . . . . . . . . . . 95
6.3 Unwinding Through Assembler Code . . . . . . . . . . . . . . . . 99
7 Development Environment 102
8 Execution Environment 103
9 Conventions 104
9.1 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
9.2 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.2.1 Names . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.2.2 Representation of Fortran Types . . . . . . . . . . . . . 107
9.2.3 Argument Passing . . . . . . . . . . . . . . . . . . . . . 108
9.2.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . 109
9.2.5 COMMON blocks . . . . . . . . . . . . . . . . . . . . . . 110
9.2.6 Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . 111
A Linux Conventions 122
A.1 Execution of 32-bit Programs . . . . . . . . . . . . . . . . . . 122
A.2 AMD64 Linux Kernel Conventions . . . . . . . . . . . . . . . . . 122
A.2.1 Calling Conventions . . . . . . . . . . . . . . . . . . . 122
A.2.2 Stack Layout . . . . . . . . . . . . . . . . . . . . . . . 123
A.2.3 Required Processor Features . . . . . . . . . . . . . . . 123
A.2.4 Miscellaneous Remarks . . . . . . . . . . . . . . . . . . 123
Introduction
The AMD architecture is an extension of the x86 architecture. Any processor
implementing the AMD64 architecture specification will also provide compatibil-
ity modes for previous descendants of the Intel 8086 architecture, including
32-bit processors such as the Intel 386, Intel Pentium, and AMD K6-2 processor.
Operating systems conforming to the AMD64 ABI may provide support for executing
programs that are designed to execute in these compatibility modes. The AMD64
ABI does not apply to such programs; this document applies only programs run-
ning in the long mode provided by the AMD64 architecture.
Except where otherwise noted, the AMD64 architecture ABI follows the con-
ventions described in the Intel386 ABI. Rather than replicate the entire
contents of the Intel386 ABI, the AMD64 ABI indicates only those places where
changes have been made to the Intel386 ABI.
No attempt has been made to specify an ABI for languages other than C. How-
ever, it is assumed that many programming languages will wish to link with code
written in C, so that the ABI specifications documented here apply there too.
(*** download for full text ***)