Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

as(1)

brk(2)

cc(1)

ld(1)

A.OUT(4)  —  Stardent Computer Inc.

NAME

a.out − common assembler and link editor output

SYNOPSIS

#include <a.out.h>

DESCRIPTION

The file name a.out is the default output file name from the link editor ld(1). The link editor makes 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 file name is different. 

A common object file consists of a file header, a UNIX system header, a table of section headers, section data, relocation information, a symbol table header, a string table, symbol table entries, and postload information.  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.
Symbol table header.
String table.
Symbol table entries.
Postload information.

The file header and UNIX system header are always present.  Other sections may be absent under different circumstances.  Also note that relocation information is absent after linking unless the −r option of ld(1) was used.

When an a.out file is loaded into memory for execution, four 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), thread local data (in the case that the process will use more than one processor), and a stack. 

The a.out file produced by ld(1) is identified by the magic number 0413 in the first field of the UNIX system header.  The headers (file header, UNIX system header, and section headers) are loaded at the beginning of the text segment and the text immediately follows the headers in the user address space.  The first text address equals 0x400000 plus the size of the headers, and varies depending upon the number of section headers in the a.out file.  The text segment is not writable by the program, and, to preserve the ability to postload, should contain only instructions.  If other processes are executing the same a.out file, the processes share a single text segment. 

The data segment starts by default at virtual address 0x10000000.  The first three pages of this data region are mapped to contain registers for controlling the floating point unit, so the actual data begins in 0x10003000.  By convention, the page at this address is dedicated to holding common floating-point constants, so the page at 0x10004000 begins the true data region.  The data region can be grown by the brk(2) system call.

Threadlocal storage begins at virtual address 0x7fe00000.  The threadlocal region cannot be initialized or grown. 

The stack starts at 0x7fe00000 and grows toward smaller addresses.  It can be grown simply by accessing off of the low end of it. 

For relocatable files, the value of a word that is not relocated is exactly its value in the file.  If a word is relocated by the base of a region (such as the text or data region), the base of the region is added to the word in the file.  If a word is relocated by the address of a variable, the address of the variable is again added to the data in the file; in the case of an instruction, the target address is reflected in the instruction depending on the type of relocation and the kind of instruction being relocated. 

File Header

The format of the filehdr header is

struct filehdr
{
unsigned shortf_magic;/∗ magic number ∗/
unsigned shortf_nscns;/∗ number of sections ∗/
longf_timdat;/∗ time & date stamp ∗/
longf_symptr;/∗ file pointer to symbolic header ∗/
longf_nsyms;/∗ sizeof(symbolic hdr) ∗/
unsigned shortf_opthdr;/∗ sizeof(optional hdr) ∗/
unsigned shortf_flags;/∗ flags ∗/
};

UNIX System Header

The format of the UNIX system header is

typedefstruct aouthdr
{
shortmagic;/∗ magic number ∗/
shortvstamp;/∗ version stamp ∗/
longtsize;/∗ text size in bytes, padded to FW bdry ∗/
longdsize;/∗ initialized data ∗/
longbsize;/∗ uninitialized data ∗/
longentry;/∗ entry pt. ∗/
longtext_start;/∗ starting address of text ∗/
longdata_start;/∗ starting address of data ∗/
longbss_start;/∗ starting address of bss ∗/
longFIX_flags;/∗ bits describing h’ware fixes applied ∗/
longtlsize;/∗ thread-local data area size ∗/
longtl_start;/∗ starting address of thread-local ∗/
longstack_start;/∗ starting address of stack ∗/
longstamp;/∗ 2 words of version/testing stamp ∗/
longgp_value;/∗ the gp value used for this object ∗/
} AOUTHDR;

Section Header

The format of the section header is

struct scnhdr
{
chars_name[8];/∗ section name ∗/
longs_paddr;/∗ physical address ∗/
longs_vaddr;/∗ virtual address ∗/
longs_size;/∗ section size ∗/
longs_scnptr;/∗ file ptr to raw data for section ∗/
longs_relptr;/∗ file ptr to relocation ∗/
unsigneds_nreloc;/∗ the number of relocation entries ∗/
unsigned shorto_nreloc;/∗ field for backwards compatibility ∗/
unsigned shortfiller2;/∗ number of line numbers (not used) ∗/
longs_flags;/∗ flags ∗/
};

Relocation

Object files contain one relocation entry for each relocatable reference in the text or data.  If relocation information is present, it appears in the following format:

typedef struct
{
    longr_vaddr;/∗ (virtual) address of reference ∗/
    unsignedr_symndx:24;/∗ index into symbol table ∗/
r_reserved:3;
    r_type:4;/∗ relocation type ∗/
r_extern:1;/∗ extern flag ∗/
} RELOC;

The field r_extern distinguishes between relocation by the base of a section (r_extern is zero, r_symndx has the section number) and relocation by a symbol (r_extern is one, and r_symndx has the symbol table index for the symbol).  If there is no relocation information, s_relptr is 0. 

Symbol Table Header

The format of the symbol table header is

typedef struct
{
shortmagic;/∗ to verify validity of the table ∗/
shortvstamp;/∗ version stamp ∗/
longfiller1[15];/∗ for backwards compatibility ∗/
longstrings_ct;/∗ number of bytes of strings ∗/
longstrings_off;/∗ offset of strings ∗/
longcomini_ct;/∗ initialized common data ∗/
longcomini_off;/∗ offset of initialized common data ∗/
longaddress_ct;/∗ number of text-relocated addresses ∗/
longaddress_off;/∗ offset of text-relocated addresses ∗/
longsymbols_ct;/∗ number of external symbols ∗/
longsymbols_off;/∗ offset of external symbols ∗/
} SYMBOLS;

The symbol table header is followed by three additional blocks of data; the symbol table entries, the string table, and the list of text-relocated addresses that is used to support postloading. 

DISCUSSION

Note that, in constrast to other UNIX implementations, there is no explicit bss section; all the information is taken from the UNIX system header.  The threadlocal information is treated similarly. 

In addition to the text and data sections, other sections may be present that do not directly affect the execution of the program.  A section of #ident information may be present, giving information on how to rebuild the executable progra.  A section may be present that supports FORTRAN common initialization (in object files only).  Two different forms of debugging sections may be present with auxiliary information that may be used to improve the debugging. 

Details about the values of specific fields can be found in the full a.out.h file. 

SEE ALSO

as(1), brk(2), cc(1), ld(1)

September 29, 2021

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026