a.out(4) DG/UX 4.30 a.out(4)
NAME
a.out - common assembler and link editor output
SYNOPSIS
#include <a.out.h>
DESCRIPTION
The filename a.out is the default output filename from the
link editor ld(1). The link editor will make a.out
executable if there were no errors in linking. The output
file of the assembler, as(1), also follows the common object
file format of the a.out file although the default filename
is different.
A common object file consists of a file header, a UNIX
system header (if the file is link editor output), a table
of section headers, relocation information, (optional) line
numbers, a symbol table, and a string table. The order is
given below.
File header.
UNIX system header.
Section 1 header.
...
Section n header.
Section 1 data.
...
Section n data.
Section 1 relocation.
...
Section n relocation.
Section 1 line numbers.
...
Section n line numbers.
Symbol table.
String table.
The last three parts of an object file (line numbers, symbol
table and string table) may be missing if the program was
linked with the -s option of ld(1) or if they were removed
by strip(1). Also note that the relocation information will
be absent after linking unless the -r option of ld(1) was
used. The string table exists only if the symbol table
contains symbols with names longer than eight characters.
The sizes of each section (contained in the header,
discussed below) are in bytes.
When an a.out file is loaded into memory for execution,
three logical segments are set up: the text segment, the
data segment (initialized data followed by uninitialized,
the latter actually being initialized to all 0's), and a
Licensed material--property of copyright holder(s) Page 1
a.out(4) DG/UX 4.30 a.out(4)
stack. On the M88K computer the text segment typically
starts at location 0x00010000 plus the byte offset in the
a.out file of the text section data.
The first 16 bits of a.out files is the magic number. For
non-executable a.out files and executables linked in the
m88kbcs SDE, the magic number is 0555. For executables
linked in the dgux SDE, the magic number is 0541. See
sde(1). The optional header of an a.out file produced by
ld(1) also has a magic number whose value is 0413. The
headers (file header, optional header, and section headers)
appear at the beginning of a.out files and determine the
address of the text segment when it is loaded into memory.
The first text address will equal 0x00010000 plus the size
of the headers, and will vary depending upon the number of
section headers in the a.out file. In an a.out file with
three sections (.text, .data, and .bss), the first text
address is at 0x000100B8 on the M88K computer. The text
segment is not writable by the program; if other processes
are executing the same a.out file, the processes will share
a single text segment.
On the M88K computer the stack begins at location 0xF000000
and grows toward lower addresses. The stack is
automatically extended as required. The data segment is
extended only as requested by the brk(2) system call.
For relocatable files the value of a word in the text or
data portions that is not a reference to an undefined
external symbol is exactly the value that will appear in
memory when the file is executed. If a word in text or data
involves a reference to an undefined external symbol, there
will be a relocation entry for the word, the storage class
of the symbol-table entry for the symbol will be marked as
an ``external symbol'', and the value and section number of
the symbol-table entry will be undefined. When the file is
processed by the link editor and the external symbol becomes
defined, the value of the symbol will be added to the word
in the file.
File Header
The format of the filehdr header is
struct filehdr
{
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
long f_timdat; /* time and date stamp */
long f_symptr; /* file ptr to symtab */
long f_nsyms; /* # symtab entries */
unsigned short f_opthdr; /* sizeof(opt hdr) */
unsigned short f_flags; /* flags */
Licensed material--property of copyright holder(s) Page 2
a.out(4) DG/UX 4.30 a.out(4)
};
Optional Header
The format of the optional header is
typedef struct aouthdr
{
short magic; /* magic number */
short vstamp; /* version stamp */
long tsize; /* text size in bytes, padded */
long dsize; /* initialized data (.data) */
long bsize; /* uninitialized data (.bss) */
long entry; /* entry point */
long text_start; /* base of text used for this file */
long data_start; /* base of data used for this file */
} AOUTHDR;
Section Header
The format of the section header is
struct scnhdr
{
char s_name[8]; /* section name */
long s_paddr; /* physical address */
long s_vaddr; /* virtual address */
long s_size; /* section size */
long s_scnptr; /* file ptr to raw data */
long s_relptr; /* file ptr to relocation */
long s_lnnoptr; /* file ptr to line numbers */
unsigned long s_nreloc; /* # reloc entries */
unsigned long s_nlnno; /* # line number entries */
long s_flags; /* flags */
};
Relocation
Object files have one relocation entry for each relocatable
reference in the text or data. If relocation information is
present, it will be in the following format:
struct reloc
{
long r_vaddr;/* (virtual) address of reference */
long r_symndx;/* index into symbol table */
unsigned short r_type;/* relocation type */
unsigned short r_offset;/* high 16 bits of expression */
};
The start of the relocation information is s_relptr from the
section header. If there is no relocation information,
s_relptr is 0.
Licensed material--property of copyright holder(s) Page 3
a.out(4) DG/UX 4.30 a.out(4)
Symbol Table
The format of each symbol in the symbol table is
#define SYMNMLEN 8
#define FILNMLEN 14
#define DIMNUM 4
struct syment
{
union /* all ways to get a symbol name */
{
char _n_name[SYMNMLEN]; /* name of symbol */
struct
{
long _n_zeroes; /* == 0L if in string table */
long _n_offset; /* location in string table */
} _n_n;
char *_n_nptr[2]; /* allows overlaying */
} _n;
long n_value; /* value of symbol */
short n_scnum; /* section number */
unsigned short n_type; /* type and derived type */
char n_sclass; /* storage class */
char n_numaux; /* number of aux entries */
char n_pad1; /* pad to 4 byte multiple */
char n_pad2; /* pad to 4 byte multiple */
};
#define n_name _n._n_name
#define n_zeroes _n._n_n._n_zeroes
#define n_offset _n._n_n._n_offset
#define n_nptr _n._n_nptr[1]
Some symbols require more information than a single entry;
they are followed by auxiliary entries that are the same
size as a symbol entry. The format follows.
union auxent {
struct {
long x_tagndx;
union {
struct {
unsigned long x_lnno;
unsigned long x_size;
} x_lnsz;
long x_fsize;
} x_misc;
union {
struct {
long x_lnnoptr;
long x_endndx;
} x_fcn;
Licensed material--property of copyright holder(s) Page 4
a.out(4) DG/UX 4.30 a.out(4)
struct {
unsigned short x_dimen[4];
} x_ary;
struct {
unsigned long x_dimen1[2];
} x_ary1;
} x_fcnary;
unsigned short x_tvndx;
char x_pad1;
char x_pad2;
} x_sym;
struct {
unsigned long x_dimen2[5];
} x_ary2;
union {
char x_fname[FILNMLEN];
struct {
long _x_zeroes; /* 0 if name is in string table*/
long _x_offset; /* offset into string table */
} _x_x;
char *_x_xptr[2]; /* allows for overlaying */
} x_file;
} x_file;
struct {
long x_scnlen;
unsigned short x_nreloc;
unsigned short x_nlinno;
} x_scn;
struct {
long x_tvfill;
unsigned short x_tvlen;
unsigned short x_tvran[2];
} x_tv;
};
Indexes of symbol table entries begin at zero. The start of
the symbol table is f_symptr (from the file header) bytes
from the beginning of the file. If the symbol table is
stripped, f_symptr is 0. The string table (if one exists)
begins at f_symptr + (f_nsyms * SYMESZ) bytes from the
beginning of the file.
SEE ALSO
as(1), att_dump(1), cc(1), ld(1), brk(2), filehdr(4),
ldfcn(4), linenum(4), reloc(4), syms(4).
Licensed material--property of copyright holder(s) Page 5