1 .\" $NetBSD: a.out.5,v 1.18 2003/08/07 10:31:16 agc Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This man page is derived from documentation contributed to Berkeley by
7 .\" Donn Seeley at UUNET Technologies, Inc.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" @(#)a.out.5 8.1 (Berkeley) 6/5/93
40 .Nd format of executable binary files
47 declares three structures and several macros.
48 The structures describe the format of
49 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
58 to load a binary file into memory and execute it,
59 and by the link editor
61 to combine a binary file with other binary files.
62 This section is the only mandatory one.
64 Contains machine code and related data
65 that are loaded into memory when a program executes.
66 May be loaded read-only.
68 Contains initialized data; always loaded into writable memory.
70 Contains records used by the link editor
71 to update pointers in the text segment when combining binary files.
73 Like the text relocation section, but for data segment pointers.
75 Contains records used by the link editor
76 to cross reference the addresses of named variables and functions
80 Contains the character strings corresponding to the symbol names.
83 Every binary file begins with an
86 .Bd -literal -offset indent
88 unsigned long a_midmag;
93 unsigned long a_entry;
94 unsigned long a_trsize;
95 unsigned long a_drsize;
99 The fields have the following functions:
100 .Bl -tag -width a_trsize
102 This field is stored in network byte-order so that binaries for
103 machines with alternative byte orders can be distinguished.
104 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. This flag is
123 flag and is preserved by
128 If both EX_DYNAMIC and EX_PIC are set, the object file is a position independent
129 executable image (e.g. a shared library), which is to be loaded into the
130 process address space by the run-time link editor.
134 returns the machine-id.
135 This indicates which machine(s) the binary is intended to run on.
138 specifies the magic number, which uniquely identifies binary files
139 and distinguishes different loading conventions.
140 The field must contain one of the following values:
141 .Bl -tag -width ZMAGIC
143 The text and data segments immediately follow the header
145 The kernel loads both text and data segments into writable memory.
149 text and data segments immediately follow the header and are contiguous.
150 However, the kernel loads the text into read-only memory
151 and loads the data into writable memory at the next
152 page boundary after the text.
154 The kernel loads individual pages on demand from the binary.
155 The header, text segment and data segment are all
156 padded by the link editor to a multiple of the page size.
157 Pages that the kernel loads from the text segment are read-only,
158 while pages from the data segment are writable.
161 Contains the size of the text segment in bytes.
163 Contains the size of the data segment in bytes.
165 Contains the number of bytes in the
167 and is used by the kernel to set the initial break
169 after the data segment.
170 The kernel loads the program so that this amount of writable memory
171 appears to follow the data segment and initially reads as zeroes.
173 Contains the size in bytes of the symbol table section.
175 Contains the address in memory of the entry point
176 of the program after the kernel has loaded it;
177 the kernel starts the execution of the program
178 from the machine instruction at this address.
180 Contains the size in bytes of the text relocation table.
182 Contains the size in bytes of the data relocation table.
187 include file defines several macros which use an
189 structure to test consistency or to locate section offsets in the binary file.
190 .Bl -tag -width N_BADMAG(exec)
194 field does not contain a recognized value.
196 The byte offset in the binary file of the beginning of the text segment.
198 The byte offset of the beginning of the symbol table.
200 The byte offset of the beginning of the string table.
203 Relocation records have a standard format which
207 .Bd -literal -offset indent
208 struct relocation_info {
210 unsigned int r_symbolnum : 24,
223 fields are used as follows:
224 .Bl -tag -width r_symbolnum
226 Contains the byte offset of a pointer that needs to be link-edited.
227 Text relocation offsets are reckoned from the start of the text segment,
228 and data relocation offsets from the start of the data segment.
229 The link editor adds the value that is already stored at this offset
230 into the new value that it computes using this relocation record.
232 Contains the ordinal number of a symbol structure
233 in the symbol table (it is
236 After the link editor resolves the absolute address for this symbol,
237 it adds that address to the pointer that is undergoing relocation.
240 bit is clear, the situation is different; see below.)
243 the link editor assumes that it is updating a pointer
244 that is part of a machine code instruction using pc-relative addressing.
245 The address of the relocated pointer is implicitly added
246 to its value when the running program uses it.
248 Contains the log base 2 of the length of the pointer in bytes;
249 0 for 1-byte displacements, 1 for 2-byte displacements,
250 2 for 4-byte displacements.
252 Set if this relocation requires an external reference;
253 the link editor must use a symbol address to update the pointer.
256 bit is clear, the relocation is
258 the link editor updates the pointer to reflect
259 changes in the load addresses of the various segments,
260 rather than changes in the value of a symbol (except when
262 is also set, see below).
263 In this case, the content of the
268 this type field tells the link editor
269 what segment the relocated pointer points into.
271 If set, the symbol, as identified by the
273 field, is to be relocated to an offset into the Global Offset Table.
274 At run-time, the entry in the Global Offset Table at this offset is set to
275 be the address of the symbol.
277 If set, the symbol, as identified by the
279 field, is to be relocated to an offset into the Procedure Linkage Table.
281 If set, this relocation is relative to the (run-time) load address of the
282 image this object file is going to be a part of. This type of relocation
283 only occurs in shared objects.
285 If set, this relocation record identifies a symbol whose contents should
286 be copied to the location given in
288 The copying is done by the run-time link-editor from a suitable data
289 item in a shared object.
292 Symbols map names to addresses (or more generally, strings to values).
293 Since the link-editor adjusts addresses,
294 a symbol's name must be used to stand for its address
295 until an absolute value has been assigned.
296 Symbols consist of a fixed-length record in the symbol table
297 and a variable-length name in the string table.
298 The symbol table is an array of
301 .Bd -literal -offset indent
307 unsigned char n_type;
310 unsigned long n_value;
314 The fields are used as follows:
315 .Bl -tag -width n_un.n_strx
317 Contains a byte offset into the string table
318 for the name of this symbol.
319 When a program accesses a symbol table with the
322 this field is replaced with the
324 field, which is a pointer to the string in memory.
326 Used by the link editor to determine
327 how to update the symbol's value.
330 field is broken down into three sub-fields using bitmasks.
331 The link editor treats symbols with the
335 symbols and permits references to them from other binary files.
338 mask selects bits of interest to the link editor:
339 .Bl -tag -width N_TEXT
342 The link editor must locate an external symbol with the same name
343 in another binary file to determine the absolute value of this symbol.
344 As a special case, if the
346 field is nonzero and no binary file in the link-edit defines this symbol,
347 the link-editor will resolve this symbol to an address
349 reserving an amount of bytes equal to
351 If this symbol is undefined in more than one binary file
352 and the binary files do not agree on the size,
353 the link editor chooses the greatest size found across all binaries.
356 The link editor does not update an absolute symbol.
359 This symbol's value is a text address and
360 the link editor will update it when it merges binary files.
362 A data symbol; similar to
364 but for data addresses.
365 The values for text and data symbols are not file offsets but
366 addresses; to recover the file offsets, it is necessary
367 to identify the loaded address of the beginning of the corresponding
368 section and subtract it, then add the offset of the section.
370 A bss symbol; like text or data symbols but
371 has no corresponding offset in the binary file.
374 The link editor inserts this symbol before
375 the other symbols from a binary file when
376 merging binary files.
377 The name of the symbol is the filename given to the link editor,
378 and its value is the first text address from that binary file.
379 Filename symbols are not needed for link-editing or loading,
380 but are useful for debuggers.
385 mask selects bits of interest to symbolic debuggers
388 the values are described in
391 This field provides information on the nature of the symbol independent of
392 the symbol's location in terms of segments as determined by the
394 field. Currently, the lower 4 bits of the
396 field hold one of two values:
403 for their definitions
406 associates the symbol with a callable function, while
408 associates the symbol with data, irrespective of their locations in
409 either the text or the data segment.
410 This field is intended to be used by
412 for the construction of dynamic executables.
414 Reserved for use by debuggers; passed untouched by the link editor.
415 Different debuggers use this field for different purposes.
417 Contains the value of the symbol.
418 For text, data and bss symbols, this is an address;
419 for other symbols (such as debugger symbols),
420 the value may be arbitrary.
423 The string table consists of an
425 length followed by null-terminated symbol strings.
426 The length represents the size of the entire table in bytes,
427 so its minimum value (or the offset of the first string)
428 is always 4 on 32-bit machines.
443 include file appeared in
446 Nobody seems to agree on what
450 New binary file formats may be supported in the future,
451 and they probably will not be compatible at any level
452 with this ancient format.