a.out
Purpose
Provides common assembler and link editor output.
Synopsis
#include <a.out.h>
Description
The as (assembler) and ld (link editor) programs produce
an output file (the a.out file by default) in the fol-
lowing format. The a.out file is executable if the
assembler and the link editor do not find any unresolved
external references or errors in the source.
This file can have the following sections: a header, the
text segment, data segment, relocation information, a
symbol table, a line number section, a string table, and
a shared library identifer (in that order). The last
five sections may be missing if the program was linked
with the -s flag of the ld command or if they were
removed by the strip command. The shared library identi-
fier exists only for object modules related to a shared
library image. Note the relocation information is not
present if there are not external references to be
resolved after linking.
Loading an a.out file into memory for execution causes
the creation of three logical segments: the text
segment, the data segment (initialized data followed by
data that is not initialized, the latter actually being
initialized to all zeros) and a stack.
Segment 1 occupies a low memory address in the process
image and its size is static. Segment 2 follows segment
1 in memory. The size of this segment can be extended
using the brk system call. The stack segment begins near
the highest locations in segment 3 and grows toward
segment 2 as required.
Header
The format of the a.out header is:
struct exec {
unsigned char a_magic[2]; /* magic number */
unsigned char a_flags; /* flags */
unsigned char a_cpu; /* CPU-ID */
unsigned char a_hdrlen; /* length of header */
unsigned char a_unused; /* reserved for future use */
unsigned short a_version; /* version stamp */
long a_text; /* size of text segment */
long a_data; /* size of data segment */
long a_bss; /* size of bss segment */
long a_entry; /* entry point */
long a_misc; /* misc., e.g. initial stack pointer */
long a_syms; /* symbol table size */
/* SHORT FORM ENDS HERE */
long a_trsize; /* text relocation size */
long a_drsize; /* data relocation size */
long a_tbase; /* text relocation base */
long a_dbase; /* data relocation base */
long a_lnums; /* size of line number section */
long a_toffs; /* offset of text from start of file */
};
The fields in the header are as follows:
a_magic A 2-byte number that has a value of 0x0103.
a_flags A byte with various options that apply to the
a.out file. Bits that are not used are set
to 0. Options supported are:
A_TOFF Text offset is specified by
a_toffs
A_STRS String table is present
A_HDREXT Extended header is present
A_EXEC File is executable
A_SEP Instruction and data spaces are
separate
A_PURE Pure text
A_SHLIB Shared library identifier is
present
a_cpu A coded entry describing the system unit and
the byte order it expects. The coded entry
for RT PC is 0x13.
a_hdrlen The length of the header. The size of the
header is variable, but it must be at least
32 bytes to include all of the fields in the
structure through a_syms. If the size of the
header is such that a field is not included,
the default value is assumed.
a_misc The maximum size in bytes the user stack is
allowed to grow.
Extended Header
The presence of an extended header is indicated by the
A_HDREXT bit being set in a_flags. The format of the
extended header is:
struct exthdr {
unsigned short ax_size; /* total size of extension */
unsigned short ax_type; /* type of extension */
unsigned short ax_flags; /* e.g., execution model */
unsigned short ax_nsegs; /* number of segment entries */
};
The size of the extension (in bytes) is ax_size, which
includes the length of exthdr plus any auxiliary entries
which comprise this extended header type, indicated by
ax_type. The value of ax_flags is also dependent on
ax_type. In the event that the following auxiliary
entries contain per-segment information, ax_nsegs is the
number of segments (and thus the number of auxiliary
entries) present.
Legal values for ax_type are:
AXT_INTEL 1
AXT_SHLIB 2
The legal values for ax_flags when ax_type is AX_INTEL
are:
AXF_SSS Separate stack segment
AXF_MCS Multiple code segments
AXF_MDS Multiple data segments
AXF_HDS Huge data present
AXF_OVLY Code overlay
AXF_FPH Floating-point hardware required
AXF_ABS Absolute addresses present
When ax_type is AXT_INTEL, exthdr is followed by ax_nsegs
entries of the form:
struct segent {
unsigned short as_type; /* segment type */
unsigned short as_flags; /* segment attributes */
unsigned short as_num; /* segment number */
unsigned short as_nlnno; /* # lineno entries */
long as_filep; /* position (offset) in file */
long as_psize; /* size of segment in file */
long as_vsize; /* virtual size */
long as_rsvd1; /* reserved */
long as_rsvd2; /* reserved */
long as_lnptr; /* position of lineno entries */
};
Each segent describes a segment of the a.out file. Legal
values for the type of segment, as_type, are:
AST_NULL
AST_TEXT Code segment
AST_DATA Data segment
Various characteristics of the segment are described by
as_flags. Possible values are:
ASF_HUGE Segment contains huge model data
ASF_BSS Segment contains implicit bss
ASF_SHARE Segment is sharable
ASF_EXPDOWN Segment expands downward
ASF_SEG Always on for segments
When ax_type is AXT_SHLIB, exthdr is followed by a table
describing the ax_nsegs shared libraries required by this
program. Each element of the table has the format:
struct slent {
long sl_off; /* offset from table start of lib key */
long as_addr; /* address where library to be mapped */
};
The table is terminated by an element with an sl_off
member of zero. Following the table are the shared
library keys associated with the libraries mentioned.
Each shared library key is preceded by a string recogni-
zable to the what command, and is terminated with an
ASCII NUL character. (Each sl_off entry points past the
what string to the real start of the key.)
Text and Data Sections
The text and data sections are indicated in the fields as
follows:
a_text The size of the text segment in bytes. This
segment begins immediately after the header or
at the offset specified in the a_toffs field if
the A_TOFF flag is set. The A_TEXTPOS macro
defined in the a.out.h header file gives the
offset of this segment in either case.
a_data The size of the data segment in bytes. This
segment begins immediately following the text
segment. The A_DATAPOS macro gives the offset
of this segment.
a_bss The size of the bss segment in bytes. This
segment represents data that is not initial-
ized. It does not appear in the file.
The text, data, and bss segments must each be a multiple
of full words in size.
a_entry The text address where the program should start
to run. The default is the a_tbase value.
a_tbase The virtual address of the first byte of the
text segment. The default value for this field
is 0.
a_dbase The virtual address of the first byte of the
data segment. The default value for this field
is a_tbase + a_text, rounded to the next
segment boundary.
Relocation
The fields in the relocation information are as follows:
a_drsize The size of the data relocation information
in bytes. The A_DRELPOS macro defines where
the data relocation information entries
begin.
a_trsize The size of the text relocation information
in bytes. The A_TRELPOS macro defines where
the text relocation entries begin.
A word in the text or data segment of memory contains
either an actual value or the value of an offset. If a
word in the text or data segment references an undefined
external symbol, its value is an offset from the associ-
ated external symbol. During processing, the link editor
defines the external symbol and adds the value of the
symbol to the word in the file.
When relocation information is present, each item that
can be relocated is 8 bytes long. The format of the
relocation information is:
struct reloc {
long r_vaddr; /* virtual address of reference */
unsigned short r_symndx; /* internal segnum or extern
symbol number */
unsigned short r_type; /* relocation type */
};
The r_vaddr field gives the location of the relocatable
reference relative to the beginning of the segment in
which it is defined.
The r_symndx field contains a symbol number in the case
of an external. Otherwise, it contains a segment number
code:
S_ABS 0xFFFF /* absolute */
S_TEXT 0xFFFE /* text segment */
S_DATA 0xFFFD /* data segment */
S_BSS 0xFFFC /* bss segment */
The r_type field indicates the type of relocation. The relocation types are:
R_ABS 0 /* absolute */
R_RELBYTE 2 /* byte */
R_PCRBYTE 3 /* byte (pc relative) */
R_RELWORD 4 /* word */
R_PCRWORD 5 /* word (pc relative) */
R_RELLONG 6 /* long */
R_PCRLONG 7 /* long (pc relative) */
R_REL3BYTE 8 /* 3 bytes */
R_KBRANCH 9 /* 20-bit 1-shifted */
R_SEG86 10 /* segmented PC-XT */
R_SEG286 11 /* segmented PC-AT */
R_KCALL 12 /* 20-bit 1-shifted or fix up */
Symbol Table
The a_syms field in the header indicates the size of the symbol table in
bytes. The A_SYMPOS macro defines the offset where the symbol table begins.
The symbol table consists of the following entries:
struct syment {
union {
char _n_name [8]; /* non-flex version */
struct {
long _n_zeroes; /* flexname == 0 */
long _n_offset; /* offset into string table */
}_n_n;
char *_n_n_ptr[2]; /* allows for overlaying */
}_n;
long n_value; /* symbol value */
unsigned char n_sclass; /* storage class */
unsigned char n_numaux; /* number of auxiliary entries */
unsigned short n_type; /* language base and derived type */
};
#define SYMENT struct syment
#define SYMESZ sizeof(struct syment)
#define n_name _n._n_name
#define n_nptr _n._n_nptr[1]
#define n_zeroes _n._n_n._n_zeroes
#define n_offset _n_n._n_n._n_offset
The low-order 3 bits of n_sclass indicate the section information:
N_UNDF 00 /* undefined */
N_ABS 01 /* absolute */
N_TEXT 02 /* text */
N_DATA 03 /* data */
N_BSS 04 /* bss */
N_COMM 05 /* common */
N_SECT 07 /* section mask */
The high-order bits indicate the storage class. The following storage
classes are implemented:
C_NULL 0000 /* undefined symbol */
C_AUTO 0010 /* (0x08) automatic variable */
C_EXT 0020 /* (0x010) external symbol */
C_STAT 0030 /* (0x18) static */
C_REG 0040 /* (0x20) register variable */
C_EXTDEF 0050 /* (0x28) external definition */
C_LABEL 0060 /* (0x30) label */
C_ULABEL 0070 /* (0x38) undefined label */
C_MOS 0100 /* (0x40) member of structure */
C_ARG 0110 /* (0x48) function argument */
C_STRTAG 0120 /* (0x50) structure tag */
C_MOU 0130 /* (0x58) member of union */
C_UNTAG 0140 /* (0x60) union tag */
C_TPDEF 0150 /* (0x68) type definition */
C_USTATIC 0160 /* (0x70) undefined static */
C_ENTAG 0170 /* (0x78) enumeration tag */
C_MOE 0200 /* (0x80) member of enumeration */
C_REGPARM 0210 /* (0x88) register parameter */
C_FIELD 0220 /* (0x90) bit field */
C_BLOCK 0300 /* (0xc0) .bb or .eb */
C_FCN 0310 /* (0xc8) .bf or .ef */
C_EOS 0320 /* (0xd0) end of structure */
C_FILE 0330 /* (0xd8) file name */
N_CLASS 0370 /* (0xff) storage class mask */
If a symbol section and class is undefined external and the value field is a
value other than 0, the link editor interprets the symbol as the name of a
common region in which the size is indicated by the value of the symbol.
The n_type field is primarily for use by a symbol debugger. The low-order 4
bits form the base type with values defined as follows:
T_NULL 0 /* undefined symbol */
T_ARG 1 /* used internally by compiler */
T_CHAR 2 /* character */
T_SHORT 3 /* short integer */
T_INT 4 /* integer */
T_LONG 5 /* long integer */
T_FLOAT 6 /* floating point */
T_DOUBLE 7 /* double */
T_STRUCT 8 /* structure */
T_UNION 9 /* union */
T_ENUM 10 /* enumeration */
T_MOE 11 /* member of enumeration */
T_UCHAR 12 /* unsigned character */
T_USHORT 13 /* unsigned short */
T_UINT 14 /* unsigned integer */
T_ULONG 15 /* unsigned long */
The high-order bits form the derived type. The following values are repeated
up to six times to form the derived type:
DT_NON 0 /* no derived type */
DT_PTR 1 /* pointer */
DT_FCN 2 /* function */
DT_ARY 3 /* array */
The n_numaux field contains the number of auxiliary entries associated with
this symbol table entry. Currently, a symbol table entry can have at most
one auxiliary entry. The auxiliary entry provides additional information,
and has this form:
union auxent {
struct {
long x_tagndx; /* str, union, or enum tag index */
union {
struct {
ushort x_lnno; /* declaration line number */
ushort x_size; /* str, union, array size */
}x_lnsz;
long x_fsize; /* size of function */
} x_misc;
union {
struct { /* if ISFCN, tag, or .bb */
long x_lnnoptr; /* ptr to fcn line # */
long x_endndx; /* entry index past block end */
} x_fcn;
struct { /* if ISARY, up to 4 dimen. */
ushort x_dimen[DIMNUM];
} x_ary;
}x_fcnary;
}x_sym;
struct {
char x_fname[FILNMLEN];
}x_file;
};
#define FILNMLEN 14
#define DIMNUM 4
The information in an auxiliary entry cannot be correctly interpreted without
the symbol table entry to which it belongs. The order of entries within the
symbol table is significant.
Line Number Section
The a_lnums field contains the size in bytes of the line number section. The
line number section starts at the location in the file defined by the
A_LINEPOS macro.
Line number entries are used by the symbolic debugger to debug code at the
source level. Entries within the line number section are grouped by func-
tion. The format of a line number entry is:
struct lineno {
union {
long l_symndx; /* symbol table index of function name
if and only if l_lnno == 0 */
long l_paddr; /* physical address of line number */
} l_addr;
unsigned short l_lnno; /* line number */
};
String Table
The string table contains the names of symbols that are longer than 8 charac-
ters. It is present only if the A_STRS flag is set. If present, the first 4
bytes contain the length, in bytes, of the string table, including the count.
The remainder of the table is a sequence of null-terminated strings. If the
n_zeroes field in a symbol entry is 0, the n_offset field gives the offset
into the string table of the name for the symbol.
Shared Library Identifier
The shared library identifier names the shared library image to which this
object module is related. It is present only if the A_SHLIB flag is set. If
present, the first byte contains the length of the identifier section
including the count byte. The identifier itself is a string terminated with
an ASCII NUL.
Related Information
The as, cc, dump, ld, nm, sdb, size, and strip commands in AIX Operating
System Commands Reference.
The config program and the what command in AIX Operating System Commands Ref-
erence.
&c2ins.