Introduction
a.out, short for “assembler output”, is the executable and object file format of early Unix. It takes its name from the file the assembler and the C compiler write when no output name is given. The BSDs and early Linux used it for programs, libraries and object files until the late 1990s or early 2000s, when it gave way to ELF, which can describe shared libraries and many sections far more easily. Modern Linux no longer runs a.out programs.
Compilers still name their output a.out by default, but on today’s
systems that file is an ELF or Mach-O program; only
the name is left.
Structure
An a.out file starts with a short header: on 32-bit systems, eight 32-bit words. The
first is the magic number, which also says how the program is loaded: octal
0407 (OMAGIC) for a program whose code may be written to,
0410 (NMAGIC) for read-only code that can be shared, and
0413 (ZMAGIC) for a program paged in from the file on demand. On the
PDP-11, 0407 was also the instruction to jump over the header. The other
words give the sizes of the text (code), the data, the zero-filled BSS area, the
symbol table and the two relocation tables, and the entry point. On the BSDs the
first word also holds a machine ID and flags, and a fourth magic number, QMAGIC
(0314), puts the header inside the first page of text.
The header fields, magic numbers, machine IDs, flags and file offsets are on the header and layout page; relocation entries, symbols, every symbol type and the string table on relocations and symbols; and the 16-bit PDP-11 form, with its magic numbers 0405 to 0411, on Seventh Edition.
0x00a_magic: 0407, 0410 or 0413 (octal)4 bytes0x04a_text, a_data, a_bss sizes12 bytes0x10a_syms symbol table size, a_entry entry point8 bytes0x18a_trsize, a_drsize: text and data relocation sizes8 bytes0x20text, then datavaries…text relocations, data relocationsvaries…symbol table, then the string tablevaries
Not described
Known, not yet covered
- Reference: the bit positions of
relocation_info(they depend on the compiler’s bit-field order),__LDPGSZ, the machine IDs of BSDs other than FreeBSD, and the stabn_descandn_valuemeanings; see header and symbols. - Reference: the First to Fourth Edition headers, the magic numbers
0430and0431, and the Sixth Edition system call table (see Seventh Edition). - Viewer: only the 16-bit PDP-11 form is read (the Fifth to Seventh Edition header): the explorer shows its header, segments, relocation words, symbols and disassembly. The 32-bit BSD a.out is not read.
Links
Software
- GNU Binutils – GNU’s binary tools, whose
objdumpandnmread a.out files when built with support for them (Linux, macOS, Windows) - IDA Pro – commercial disassembler and decompiler (Windows, macOS, Linux)
Reference
- a.out(5) – the FreeBSD manual page for the format