3 a.out \- object file format
7 An executable Plan 9 binary file has up to six sections:
8 a header, the program text, the data,
9 a symbol table, a PC/SP offset table (MC68020 only),
10 and finally a PC/line number table.
11 The header, given by a structure in
13 contains 4-byte integers in big-endian order:
16 .ta \w'#define 'u +\w'_MAGIC(b) 'u +\w'_MAGIC(10) 'u +4n +4n +4n +4n
18 long magic; /* magic number */
19 long text; /* size of text segment */
20 long data; /* size of initialized data */
21 long bss; /* size of uninitialized data */
22 long syms; /* size of symbol table */
23 long entry; /* entry point */
24 long spsz; /* size of pc/sp offset table */
25 long pcsz; /* size of pc/line number table */
28 #define HDR_MAGIC 0x00008000
30 #define _MAGIC(f, b) ((f)|((((4*(b))+0)*(b))+7))
31 #define A_MAGIC _MAGIC(0, 8) /* 68020 */
32 #define I_MAGIC _MAGIC(0, 11) /* intel 386 */
33 #define J_MAGIC _MAGIC(0, 12) /* intel 960 (retired) */
34 #define K_MAGIC _MAGIC(0, 13) /* sparc */
35 #define V_MAGIC _MAGIC(0, 16) /* mips 3000 BE */
36 #define X_MAGIC _MAGIC(0, 17) /* att dsp 3210 (retired) */
37 #define M_MAGIC _MAGIC(0, 18) /* mips 4000 BE */
38 #define D_MAGIC _MAGIC(0, 19) /* amd 29000 (retired) */
39 #define E_MAGIC _MAGIC(0, 20) /* arm */
40 #define Q_MAGIC _MAGIC(0, 21) /* powerpc */
41 #define N_MAGIC _MAGIC(0, 22) /* mips 4000 LE */
42 #define L_MAGIC _MAGIC(0, 23) /* dec alpha (retired) */
43 #define P_MAGIC _MAGIC(0, 24) /* mips 3000 LE */
44 #define U_MAGIC _MAGIC(0, 25) /* sparc64 */
45 #define S_MAGIC _MAGIC(HDR_MAGIC, 26) /* amd64 */
46 #define T_MAGIC _MAGIC(HDR_MAGIC, 27) /* powerpc64 */
47 #define R_MAGIC _MAGIC(HDR_MAGIC, 28) /* arm64 */
52 Sizes are expressed in bytes.
53 The size of the header is not included in any of the other sizes.
55 When a Plan 9 binary file is executed,
56 a memory image of three segments is
57 set up: the text segment, the data segment, and the stack.
58 The text segment begins at a virtual address which is
59 a multiple of the machine-dependent page size.
60 The text segment consists of the header and the first
62 bytes of the binary file.
65 field gives the virtual address of the entry point of the program.
66 The data segment starts at the first page-rounded virtual address
67 after the text segment.
68 It consists of the next
70 bytes of the binary file, followed by
72 bytes initialized to zero.
73 The stack occupies the highest possible locations
74 in the core image, automatically growing downwards.
75 The bss segment may be extended by
81 bytes of the file contain symbol table
82 entries, each laid out as:
87 char name[\f2n\fP]; /* NUL-terminated */
92 is in big-endian order and
95 field is not pre-defined: it is a zero-terminated array of
100 field is one of the following characters with the high bit set:
108 static text segment symbol
111 leaf function text segment symbol
114 static leaf function text segment symbol
120 static data segment symbol
126 static bss segment symbol
129 automatic (local) variable symbol
132 function parameter symbol
136 A few others are described below.
137 The symbols in the symbol table appear in the same order
138 as the program components they describe.
140 The Plan 9 compilers implement a virtual stack frame pointer rather
141 than dedicating a register;
142 moreover, on the MC680X0 architectures
143 there is a variable offset between the stack pointer and the
145 Following the symbol table,
146 MC680X0 executable files contain a
148 table encoding the offset
149 of the stack frame pointer as a function of program location;
150 this section is not present for other architectures.
151 The PC/SP table is encoded as a byte stream.
152 By setting the PC to the base of the text segment
153 and the offset to zero and interpreting the stream,
154 the offset can be computed for any PC.
155 A byte value of 0 is followed by four bytes that hold, in big-endian order,
156 a constant to be added to the offset.
157 A byte value of 1 to 64 is multiplied by four and added, without sign
158 extension, to the offset.
159 A byte value of 65 to 128 is reduced by 64, multiplied by four, and
160 subtracted from the offset.
161 A byte value of 129 to 255 is reduced by 129, multiplied by the quantum
163 (e.g. two on the MC680X0),
164 and added to the current PC without changing the offset.
165 After any of these operations, the instruction quantum is added to the PC.
167 A similar table, occupying
169 is the next section in an executable; it is present for all architectures.
170 The same algorithm may be run using this table to
171 recover the absolute source line number from a given program location.
172 The absolute line number (starting from zero) counts the newlines
173 in the C-preprocessed source seen by the compiler.
174 Three symbol types in the main symbol table facilitate conversion of the absolute
175 number to source file and line number:
179 source file name components
185 source file line offset
190 symbol associates an integer (the
192 field of the `symbol') with
193 a unique file path name component (the
196 These path components are used by the
198 symbol to represent a file name: the
199 first byte of the name field is always 0; the remaining
200 bytes hold a zero-terminated array of 16-bit values (in big-endian order)
201 that represent file name components from
204 These components, when separated by slashes, form a file name.
205 The initial slash of a file name is recorded in the symbol table by an
207 symbol; when forming file names from
209 symbols an initial slash is not to be assumed.
212 symbols are clustered, one set for each object file in the program,
213 before any text symbols from that object file.
216 symbols for an object file form a
218 of the included source files from which the object file was compiled.
219 The value associated with each
221 symbol is the absolute line number at which that file was included in the source;
222 if the name associated with the
224 symbol is null, the symbol represents the end of an included file, that is,
225 a pop of the history stack.
229 it represents the start of a new history stack.
230 To recover the source file and line number for a program location,
231 find the text symbol containing the location
232 and then the first history stack preceding the text symbol in the symbol table.
233 Next, interpret the PC/line offset table to discover the absolute line number
234 for the program location.
235 Using the line number, scan the history stack to find the set of source
236 files open at that location.
237 The line number within the file can be found using the line numbers
238 in the history stack.
241 symbols correspond to
243 directives in the source; they specify an adjustment to the line number
244 to be printed by the above algorithm. The offset is associated with the
247 symbol in the symbol table.
258 There is no type information in the symbol table; however, the
260 flags on the compilers will produce symbols for