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 */
27 #define _MAGIC(b) ((((4*b)+0)*b)+7)
28 #define A_MAGIC _MAGIC(8) /* 68020 */
29 #define I_MAGIC _MAGIC(11) /* intel 386 */
30 #define J_MAGIC _MAGIC(12) /* intel 960 */
31 #define K_MAGIC _MAGIC(13) /* sparc */
32 #define V_MAGIC _MAGIC(16) /* mips 3000 */
33 #define X_MAGIC _MAGIC(17) /* att dsp 3210 */
34 #define M_MAGIC _MAGIC(18) /* mips 4000 */
35 #define D_MAGIC _MAGIC(19) /* amd 29000 */
36 #define E_MAGIC _MAGIC(20) /* arm 7-something */
37 #define Q_MAGIC _MAGIC(21) /* powerpc */
38 #define N_MAGIC _MAGIC(22) /* mips 4000 LE */
39 #define L_MAGIC _MAGIC(23) /* dec alpha */
43 Sizes are expressed in bytes.
44 The size of the header is not included in any of the other sizes.
46 When a Plan 9 binary file is executed,
47 a memory image of three segments is
48 set up: the text segment, the data segment, and the stack.
49 The text segment begins at a virtual address which is
50 a multiple of the machine-dependent page size.
51 The text segment consists of the header and the first
53 bytes of the binary file.
56 field gives the virtual address of the entry point of the program.
57 The data segment starts at the first page-rounded virtual address
58 after the text segment.
59 It consists of the next
61 bytes of the binary file, followed by
63 bytes initialized to zero.
64 The stack occupies the highest possible locations
65 in the core image, automatically growing downwards.
66 The bss segment may be extended by
72 bytes of the file contain symbol table
73 entries, each laid out as:
78 char name[\f2n\fP]; /* NUL-terminated */
83 is in big-endian order and
86 field is not pre-defined: it is a zero-terminated array of
91 field is one of the following characters with the high bit set:
99 static text segment symbol
102 leaf function text segment symbol
105 static leaf function text segment symbol
111 static data segment symbol
117 static bss segment symbol
120 automatic (local) variable symbol
123 function parameter symbol
127 A few others are described below.
128 The symbols in the symbol table appear in the same order
129 as the program components they describe.
131 The Plan 9 compilers implement a virtual stack frame pointer rather
132 than dedicating a register;
133 moreover, on the MC680X0 architectures
134 there is a variable offset between the stack pointer and the
136 Following the symbol table,
137 MC680X0 executable files contain a
139 table encoding the offset
140 of the stack frame pointer as a function of program location;
141 this section is not present for other architectures.
142 The PC/SP table is encoded as a byte stream.
143 By setting the PC to the base of the text segment
144 and the offset to zero and interpreting the stream,
145 the offset can be computed for any PC.
146 A byte value of 0 is followed by four bytes that hold, in big-endian order,
147 a constant to be added to the offset.
148 A byte value of 1 to 64 is multiplied by four and added, without sign
149 extension, to the offset.
150 A byte value of 65 to 128 is reduced by 64, multiplied by four, and
151 subtracted from the offset.
152 A byte value of 129 to 255 is reduced by 129, multiplied by the quantum
154 (e.g. two on the MC680X0),
155 and added to the current PC without changing the offset.
156 After any of these operations, the instruction quantum is added to the PC.
158 A similar table, occupying
160 is the next section in an executable; it is present for all architectures.
161 The same algorithm may be run using this table to
162 recover the absolute source line number from a given program location.
163 The absolute line number (starting from zero) counts the newlines
164 in the C-preprocessed source seen by the compiler.
165 Three symbol types in the main symbol table facilitate conversion of the absolute
166 number to source file and line number:
170 source file name components
176 source file line offset
181 symbol associates an integer (the
183 field of the `symbol') with
184 a unique file path name component (the
187 These path components are used by the
189 symbol to represent a file name: the
190 first byte of the name field is always 0; the remaining
191 bytes hold a zero-terminated array of 16-bit values (in big-endian order)
192 that represent file name components from
195 These components, when separated by slashes, form a file name.
196 The initial slash of a file name is recorded in the symbol table by an
198 symbol; when forming file names from
200 symbols an initial slash is not to be assumed.
203 symbols are clustered, one set for each object file in the program,
204 before any text symbols from that object file.
207 symbols for an object file form a
209 of the included source files from which the object file was compiled.
210 The value associated with each
212 symbol is the absolute line number at which that file was included in the source;
213 if the name associated with the
215 symbol is null, the symbol represents the end of an included file, that is,
216 a pop of the history stack.
220 it represents the start of a new history stack.
221 To recover the source file and line number for a program location,
222 find the text symbol containing the location
223 and then the first history stack preceding the text symbol in the symbol table.
224 Next, interpret the PC/line offset table to discover the absolute line number
225 for the program location.
226 Using the line number, scan the history stack to find the set of source
227 files open at that location.
228 The line number within the file can be found using the line numbers
229 in the history stack.
232 symbols correspond to
234 directives in the source; they specify an adjustment to the line number
235 to be printed by the above algorithm. The offset is associated with the
238 symbol in the symbol table.
249 There is no type information in the symbol table; however, the
251 flags on the compilers will produce symbols for