1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This manual page is derived from documentation contributed to Berkeley by
5 .\" Donn Seeley at UUNET Technologies, Inc.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)a.out.5 8.1 (Berkeley) 6/5/93
43 .Nd format of executable binary files
49 declares three structures and several macros.
50 The structures describe the format of
51 executable machine code files
55 A binary file consists of up to 7 sections.
56 In order, these sections are:
57 .Bl -tag -width "text relocations"
59 Contains parameters used by the kernel
60 to load a binary file into memory and execute it,
61 and by the link editor
63 to combine a binary file with other binary files.
64 This section is the only mandatory one.
66 Contains machine code and related data
67 that are loaded into memory when a program executes.
68 May be loaded read-only.
70 Contains initialized data; always loaded into writable memory.
72 Contains records used by the link editor
73 to update pointers in the text segment when combining binary files.
75 Like the text relocation section, but for data segment pointers.
77 Contains records used by the link editor
78 to cross reference the addresses of named variables and functions
82 Contains the character strings corresponding to the symbol names.
85 Every binary file begins with an
88 .Bd -literal -offset indent
90 unsigned long a_midmag;
95 unsigned long a_entry;
96 unsigned long a_trsize;
97 unsigned long a_drsize;
101 The fields have the following functions:
102 .Bl -tag -width a_trsize
104 This field is stored in host byte-order.
105 It has a number of sub-components accessed by the macros
116 .Bl -tag -width EX_DYNAMIC
118 indicates that the executable requires the services of the run-time link editor.
120 indicates that the object contains position independent code.
126 flag and is preserved by
131 If both EX_DYNAMIC and EX_PIC are set, the object file is a position independent
132 executable image (e.g.\& a shared library), which is to be loaded into the
133 process address space by the run-time link editor.
137 returns the machine-id.
138 This indicates which machine(s) the binary is intended to run on.
141 specifies the magic number, which uniquely identifies binary files
142 and distinguishes different loading conventions.
143 The field must contain one of the following values:
144 .Bl -tag -width ZMAGIC
146 The text and data segments immediately follow the header
148 The kernel loads both text and data segments into writable memory.
152 text and data segments immediately follow the header and are contiguous.
153 However, the kernel loads the text into read-only memory
154 and loads the data into writable memory at the next
155 page boundary after the text.
157 The kernel loads individual pages on demand from the binary.
158 The header, text segment and data segment are all
159 padded by the link editor to a multiple of the page size.
160 Pages that the kernel loads from the text segment are read-only,
161 while pages from the data segment are writable.
164 Contains the size of the text segment in bytes.
166 Contains the size of the data segment in bytes.
168 Contains the number of bytes in the
170 and is used by the kernel to set the initial break
172 after the data segment.
173 The kernel loads the program so that this amount of writable memory
174 appears to follow the data segment and initially reads as zeroes.
176 = block started by symbol)
178 Contains the size in bytes of the symbol table section.
180 Contains the address in memory of the entry point
181 of the program after the kernel has loaded it;
182 the kernel starts the execution of the program
183 from the machine instruction at this address.
185 Contains the size in bytes of the text relocation table.
187 Contains the size in bytes of the data relocation table.
192 include file defines several macros which use an
194 structure to test consistency or to locate section offsets in the binary file.
195 .Bl -tag -width N_BADMAG(exec)
199 field does not contain a recognized value.
201 The byte offset in the binary file of the beginning of the text segment.
203 The byte offset of the beginning of the symbol table.
205 The byte offset of the beginning of the string table.
208 Relocation records have a standard format which
212 .Bd -literal -offset indent
213 struct relocation_info {
215 unsigned int r_symbolnum : 24,
228 fields are used as follows:
229 .Bl -tag -width r_symbolnum
231 Contains the byte offset of a pointer that needs to be link-edited.
232 Text relocation offsets are reckoned from the start of the text segment,
233 and data relocation offsets from the start of the data segment.
234 The link editor adds the value that is already stored at this offset
235 into the new value that it computes using this relocation record.
237 Contains the ordinal number of a symbol structure
238 in the symbol table (it is
241 After the link editor resolves the absolute address for this symbol,
242 it adds that address to the pointer that is undergoing relocation.
245 bit is clear, the situation is different; see below.)
248 the link editor assumes that it is updating a pointer
249 that is part of a machine code instruction using pc-relative addressing.
250 The address of the relocated pointer is implicitly added
251 to its value when the running program uses it.
253 Contains the log base 2 of the length of the pointer in bytes;
254 0 for 1-byte displacements, 1 for 2-byte displacements,
255 2 for 4-byte displacements.
257 Set if this relocation requires an external reference;
258 the link editor must use a symbol address to update the pointer.
261 bit is clear, the relocation is
263 the link editor updates the pointer to reflect
264 changes in the load addresses of the various segments,
265 rather than changes in the value of a symbol (except when
267 is also set (see below).
268 In this case, the content of the
273 this type field tells the link editor
274 what segment the relocated pointer points into.
276 If set, the symbol, as identified by the
278 field, is to be relocated to an offset into the Global Offset Table.
279 At run-time, the entry in the Global Offset Table at this offset is set to
280 be the address of the symbol.
282 If set, the symbol, as identified by the
284 field, is to be relocated to an offset into the Procedure Linkage Table.
286 If set, this relocation is relative to the (run-time) load address of the
287 image this object file is going to be a part of.
288 This type of relocation
289 only occurs in shared objects.
291 If set, this relocation record identifies a symbol whose contents should
292 be copied to the location given in
294 The copying is done by the run-time link-editor from a suitable data
295 item in a shared object.
298 Symbols map names to addresses (or more generally, strings to values).
299 Since the link-editor adjusts addresses,
300 a symbol's name must be used to stand for its address
301 until an absolute value has been assigned.
302 Symbols consist of a fixed-length record in the symbol table
303 and a variable-length name in the string table.
304 The symbol table is an array of
307 .Bd -literal -offset indent
313 unsigned char n_type;
316 unsigned long n_value;
320 The fields are used as follows:
321 .Bl -tag -width n_un.n_strx
323 Contains a byte offset into the string table
324 for the name of this symbol.
325 When a program accesses a symbol table with the
328 this field is replaced with the
330 field, which is a pointer to the string in memory.
332 Used by the link editor to determine
333 how to update the symbol's value.
336 field is broken down into three sub-fields using bitmasks.
337 The link editor treats symbols with the
341 symbols and permits references to them from other binary files.
344 mask selects bits of interest to the link editor:
345 .Bl -tag -width N_TEXT
348 The link editor must locate an external symbol with the same name
349 in another binary file to determine the absolute value of this symbol.
350 As a special case, if the
352 field is nonzero and no binary file in the link-edit defines this symbol,
353 the link-editor will resolve this symbol to an address
355 reserving an amount of bytes equal to
357 If this symbol is undefined in more than one binary file
358 and the binary files do not agree on the size,
359 the link editor chooses the greatest size found across all binaries.
362 The link editor does not update an absolute symbol.
365 This symbol's value is a text address and
366 the link editor will update it when it merges binary files.
368 A data symbol; similar to
370 but for data addresses.
371 The values for text and data symbols are not file offsets but
372 addresses; to recover the file offsets, it is necessary
373 to identify the loaded address of the beginning of the corresponding
374 section and subtract it, then add the offset of the section.
376 A bss symbol; like text or data symbols but
377 has no corresponding offset in the binary file.
380 The link editor inserts this symbol before
381 the other symbols from a binary file when
382 merging binary files.
383 The name of the symbol is the filename given to the link editor,
384 and its value is the first text address from that binary file.
385 Filename symbols are not needed for link-editing or loading,
386 but are useful for debuggers.
391 mask selects bits of interest to symbolic debuggers
394 the values are described in
397 This field provides information on the nature of the symbol independent of
398 the symbol's location in terms of segments as determined by the
401 Currently, the lower 4 bits of the
403 field hold one of two values:
409 for their definitions).
411 associates the symbol with a callable function, while
413 associates the symbol with data, irrespective of their locations in
414 either the text or the data segment.
415 This field is intended to be used by
417 for the construction of dynamic executables.
419 Reserved for use by debuggers; passed untouched by the link editor.
420 Different debuggers use this field for different purposes.
422 Contains the value of the symbol.
423 For text, data and bss symbols, this is an address;
424 for other symbols (such as debugger symbols),
425 the value may be arbitrary.
428 The string table consists of an
430 length followed by null-terminated symbol strings.
431 The length represents the size of the entire table in bytes,
432 so its minimum value (or the offset of the first string)
433 is always 4 on 32-bit machines.
448 include file appeared in
451 Since not all of the supported architectures use the
454 it can be difficult to determine what
455 architecture a binary will execute on
456 without examining its actual machine code.
457 Even with a machine identifier,
458 the byte order of the
460 header is machine-dependent.