1 .\" $OpenBSD: a.out.5,v 1.15 2007/05/31 19:19:58 jmc Exp $
2 .\" $NetBSD: a.out.5,v 1.8 1994/11/30 19:31:09 jtc Exp $
4 .\" Copyright (c) 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" This man page is derived from documentation contributed to Berkeley by
8 .\" Donn Seeley at UUNET Technologies, Inc.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)a.out.5 8.1 (Berkeley) 6/5/93
36 .Dd $Mdocdate: May 31 2007 $
41 .Nd format of executable binary files
43 .Fd #include <sys/types.h>
44 .Fd #include <a.out.h>
48 declares three structures and several macros.
49 The structures describe the format of executable machine code files
53 A binary file consists of up to 7 sections.
54 In order, these sections are:
55 .Bl -tag -width "text relocations"
57 Contains parameters used by the kernel to load a binary file into memory
58 and execute it, and by the link editor
60 to combine a binary file with other binary files.
61 This section is the only mandatory one.
63 Contains machine code and related data
64 that are loaded into memory when a program executes.
65 May be loaded read-only.
67 Contains initialized data; always loaded into writable memory.
69 Contains records used by the link editor
70 to update pointers in the text segment when combining binary files.
72 Like the text relocation section, but for data segment pointers.
74 Contains records used by the link editor
75 to cross reference the addresses of named variables and functions
79 Contains the character strings corresponding to the symbol names.
82 Every binary file begins with an
85 .Bd -literal -offset indent
98 The fields have the following functions:
99 .Bl -tag -width a_trsize
101 This field is stored in network byte-order so that binaries for
102 machines with alternate byte orders can be distinguished.
103 It has a number of sub-components accessed by the macros
114 .Bl -tag -width EX_DYNAMIC
116 Indicates that the executable requires the services of the run-time link editor.
118 Indicates that the object contains position independent code.
123 flag and is preserved by
132 are set, the object file is a position independent
133 executable image (e.g., a shared library), which is to be loaded into the
134 process address space by the run-time link editor.
138 returns the machine ID.
139 This indicates which machine(s) the binary is intended to run on.
142 specifies the magic number, which uniquely identifies binary files
143 and distinguishes different loading conventions.
144 The field must contain one of the following values:
145 .Bl -tag -width ZMAGIC
147 The text and data segments immediately follow the header and are contiguous.
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 and loads the data
154 into writable memory at the next page boundary after the text.
156 The kernel loads individual pages on demand from the binary.
157 The header, text segment and data segment are all
158 padded by the link editor to a multiple of the page size.
159 Pages that the kernel loads from the text segment are read-only,
160 while pages from the data segment are writable.
163 Contains the size of the text segment in bytes.
165 Contains the size of the data segment in bytes.
167 Contains the number of bytes in the
169 and is used by the kernel to set the initial break
171 after the data segment.
172 The kernel loads the program so that this amount of writable memory
173 appears to follow the data segment and initially reads as zeroes.
175 Contains the size in bytes of the symbol table section.
177 Contains the address in memory of the entry point
178 of the program after the kernel has loaded it;
179 the kernel starts the execution of the program
180 from the machine instruction at this address.
182 Contains the size in bytes of the text relocation table.
184 Contains the size in bytes of the data relocation table.
189 include file defines several macros which use an
191 structure to test consistency or to locate section offsets in the binary file.
192 .Bl -tag -width N_TRELOFF(exec)
196 field does not contain a recognized value.
198 The byte offset of the beginning of the text segment.
200 The byte offset of the beginning of the data segment.
201 .It Fn N_DRELOFF exec
202 The byte offset of the beginning of the data relocation table.
203 .It Fn N_TRELOFF exec
204 The byte offset of the beginning of the text relocation table.
206 The byte offset of the beginning of the symbol table.
208 The byte offset of the beginning of the string table.
211 Relocation records have a standard format which is described by the
214 .Bd -literal -offset indent
215 struct relocation_info {
217 unsigned int r_symbolnum : 24,
230 fields are used as follows:
231 .Bl -tag -width r_symbolnum
233 Contains the byte offset of a pointer that needs to be link-edited.
234 Text relocation offsets are reckoned from the start of the text segment,
235 and data relocation offsets from the start of the data segment.
236 The link editor adds the value that is already stored at this offset
237 into the new value that it computes using this relocation record.
239 Contains the ordinal number of a symbol structure in the symbol table (it is
242 After the link editor resolves the absolute address for this symbol,
243 it adds that address to the pointer that is undergoing relocation.
246 bit is clear, the situation is different; see below.)
248 If this is set, 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 only occurs in shared objects.
290 If set, this relocation record identifies a symbol whose contents should
291 be copied to the location given in
293 The copying is done by the run-time link editor from a suitable data
294 item in a shared object.
297 Symbols map names to addresses (or more generally, strings to values).
298 Since the link editor adjusts addresses,
299 a symbol's name must be used to stand for its address
300 until an absolute value has been assigned.
301 Symbols consist of a fixed-length record in the symbol table
302 and a variable-length name in the string table.
303 The symbol table is an array of
306 .Bd -literal -offset indent
312 unsigned char n_type;
315 unsigned long n_value;
319 The fields are used as follows:
320 .Bl -tag -width n_un.n_strx
322 Contains a byte offset into the string table for the name of this symbol.
323 When a program accesses a symbol table with the
325 function, this field is replaced with the
327 field, which is a pointer to the string in memory.
329 Used by the link editor to determine how to update the symbol's value.
332 field is broken down into three sub-fields using bitmasks.
333 The link editor treats symbols with the
337 symbols and permits references to them from other binary files.
340 mask selects bits of interest to the link editor:
341 .Bl -tag -width N_TEXT
344 The link editor must locate an external symbol with the same name
345 in another binary file to determine the absolute value of this symbol.
346 As a special case, if the
348 field is non-zero and no binary file in the link-edit defines this symbol,
349 the link editor will resolve this symbol to an address
350 in the BSS segment, reserving an amount of bytes equal to
352 If this symbol is undefined in more than one binary file
353 and the binary files do not agree on the size,
354 the link editor chooses the greatest size found across all binaries.
357 The link editor does not update an absolute symbol.
360 This symbol's value is a text address and
361 the link editor will update it when it merges binary files.
363 A data symbol; similar to
365 but for data addresses.
366 The values for text and data symbols are not file offsets but
367 addresses; to recover the file offsets, it is necessary
368 to identify the loaded address of the beginning of the corresponding
369 section and subtract it, then add the offset of the section.
371 A BSS symbol; like text or data symbols but
372 has no corresponding offset in the binary file.
375 The link editor inserts this symbol before
376 the other symbols from a binary file when
377 merging binary files.
378 The name of the symbol is the filename given to the link editor,
379 and its value is the first text address from that binary file.
380 Filename symbols are not needed for link editing or loading,
381 but are useful for debuggers.
386 mask selects bits of interest to symbolic debuggers
389 the values are described in
392 This field provides information on the nature of the symbol independent of
393 the symbol's location in terms of segments as determined by the
396 Currently, the lower 4 bits of the
398 field hold one of two values:
405 for their definitions
408 associates the symbol with a callable function, while
410 associates the symbol with data, irrespective of their locations in
411 either the text or the data segment.
412 This field is intended to be used by
414 for the construction of dynamic executables.
416 Reserved for use by debuggers; passed untouched by the link editor.
417 Different debuggers use this field for different purposes.
419 Contains the value of the symbol.
420 For text, data and BSS symbols, this is an address;
421 for other symbols (such as debugger symbols),
422 the value may be arbitrary.
425 The string table consists of an
427 length followed by null-terminated symbol strings.
428 The length represents the size of the entire table in bytes,
429 so its minimum value (or the offset of the first string)
430 is always 4 on 32-bit machines.
444 include file appeared in
447 Nobody seems to agree on what
451 New binary file formats may be supported in the future,
452 and they probably will not be compatible at any level
453 with this ancient format.