a.out.h
>
declares three structures and several macros.
The structures describe the format of
executable machine code files
(`binaries')
on the system.
A binary file consists of up to 7 sections. In order, these sections are:
Every binary file begins with an
exec
structure:
struct exec {
unsigned long a_midmag;
unsigned long a_text;
unsigned long a_data;
unsigned long a_bss;
unsigned long a_syms;
unsigned long a_entry;
unsigned long a_trsize;
unsigned long a_drsize;
};
The fields have the following functions:
a_midmag
N_GETFLAG()
,
N_GETMID()
, and
N_GETMAGIC()
,
and set by the macro
N_SETMAGIC()
.
The macro
N_GETFLAG()
returns a few flags:
EX_DYNAMIC
EX_PIC
If both EX_DYNAMIC and EX_PIC are set, the object file is a position independent executable image (e.g. a shared library), which is to be loaded into the process address space by the run-time link editor.
The macro
N_GETMID()
returns the machine-id.
This indicates which machine(s) the binary is intended to run on.
N_GETMAGIC()
specifies the magic number, which uniquely identifies binary files
and distinguishes different loading conventions.
The field must contain one of the following values:
OMAGIC
NMAGIC
OMAGIC
,
text and data segments immediately follow the header and are contiguous.
However, the kernel loads the text into read-only memory
and loads the data into writable memory at the next
page boundary after the text.
ZMAGIC
a_text
a_data
a_bss
a_syms
a_entry
a_trsize
a_drsize
The
a.out.h
include file defines several macros which use an
exec
structure to test consistency or to locate section offsets in the binary file.
exec
)
a_magic
field does not contain a recognized value.
exec
)
exec
)
exec
)
Relocation records have a standard format which
is described by the
relocation_info
structure:
struct relocation_info {
int r_address;
unsigned int r_symbolnum : 24,
r_pcrel : 1,
r_length : 2,
r_extern : 1,
r_baserel : 1,
r_jmptable : 1,
r_relative : 1,
r_copy : 1;
};
The
relocation_info
fields are used as follows:
r_address
r_symbolnum
r_extern
bit is clear, the situation is different; see below.)
r_pcrel
r_length
r_extern
r_extern
bit is clear, the relocation is
`local';
the link editor updates the pointer to reflect
changes in the load addresses of the various segments,
rather than changes in the value of a symbol (except when
r_baserel
is also set, see below).
In this case, the content of the
r_symbolnum
field is an
n_type
value (see below);
this type field tells the link editor
what segment the relocated pointer points into.
r_baserel
r_symbolnum
field, is to be relocated to an offset into the Global Offset Table.
At run-time, the entry in the Global Offset Table at this offset is set to
be the address of the symbol.
r_jmptable
r_symbolnum
field, is to be relocated to an offset into the Procedure Linkage Table.
r_relative
r_copy
r_address
.
The copying is done by the run-time link-editor from a suitable data
item in a shared object.
Symbols map names to addresses (or more generally, strings to values).
Since the link-editor adjusts addresses,
a symbol's name must be used to stand for its address
until an absolute value has been assigned.
Symbols consist of a fixed-length record in the symbol table
and a variable-length name in the string table.
The symbol table is an array of
nlist
structures:
struct nlist {
union {
char *n_name;
long n_strx;
} n_un;
unsigned char n_type;
char n_other;
short n_desc;
unsigned long n_value;
};
The fields are used as follows:
n_un.n_strx
n_un.n_name
field, which is a pointer to the string in memory.
n_type
n_type
field is broken down into three sub-fields using bitmasks.
The link editor treats symbols with the
N_EXT
type bit set as
`external'
symbols and permits references to them from other binary files.
The
N_TYPE
mask selects bits of interest to the link editor:
N_UNDF
n_value
field is nonzero and no binary file in the link-edit defines this symbol,
the link-editor will resolve this symbol to an address
in the bss segment,
reserving an amount of bytes equal to
n_value
.
If this symbol is undefined in more than one binary file
and the binary files do not agree on the size,
the link editor chooses the greatest size found across all binaries.
N_ABS
N_TEXT
N_DATA
N_TEXT
but for data addresses.
The values for text and data symbols are not file offsets but
addresses; to recover the file offsets, it is necessary
to identify the loaded address of the beginning of the corresponding
section and subtract it, then add the offset of the section.
N_BSS
N_FN
The
N_STAB
mask selects bits of interest to symbolic debuggers
such as
gdb(1);
the values are described in
stab(5).
n_other
n_type
field. Currently, the lower 4 bits of the
n_other
field hold one of two values:
AUX_FUNC
and
AUX_OBJECT
tions
(see <
link.h
> for their defini-.)
AUX_FUNC
associates the symbol with a callable function, while
AUX_OBJECT
associates the symbol with data, irrespective of their locations in
either the text or the data segment.
This field is intended to be used by
ld(1)
for the construction of dynamic executables.
n_desc
n_value
The string table consists of an unsigned long length followed by null-terminated symbol strings. The length represents the size of the entire table in bytes, so its minimum value (or the offset of the first string) is always 4 on 32-bit machines.
a.out.h
include file appeared in
Version 7 AT&T UNIX
.
New binary file formats may be supported in the future, and they probably will not be compatible at any level with this ancient format.