Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ a.out(5) — Unisoft V7

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

as(1)

ld(1)

nm(1)

A.OUT(5)  —  UNIX Programmer’s Manual

NAME

a.out − assembler and link editor output

SYNOPSIS

#include <a.out.h>

DESCRIPTION

A.out is the output file of the assembler as(1) and the link loader ld(1). Ld(1) makes a.out executable if there were no errors and no unresolved external references.  Layout information as given in the include file for the 68000 is:

/*
 *Layout of a.out file :
 *
 *header of 8 longsmagic number 405, 407, 410, 411
 *text size)
 *data size) in bytes
 *bss size)
 *symbol table size)
 *text relocation size)
 *data relocation size)
 *entry point
 *
 *header:0
 *text:32
 *data:32+textsize
 *symbol table:32+textsize+datasize
 *text relocation:32+textsize+datasize+symsize
 *data relocation:32+textsize+datasize+symsize+rtextsize
 *
 */
/* various parameters */
#define SYMLENGTH  50/* maximum length of a symbol */
 /* types of files */
#defineARCMAGIC 0177545/* ar files */
#defineFMAGIC0407/* standard executable */
#defineNMAGIC0410/* shared text executable */
 /* symbol types */
#defineEXTERN040/* external */
#defineUNDEF00/* undefined */
#defineABS01/* absolute */
#defineTEXT02/* text */
#defineDATA03/* data */
#defineBSS04/* bss */
#defineCOMM05/* internal use only */
#define REG06/* register name */
/* relocation regions */
#defineRTEXT00
#defineRDATA01
#defineRBSS02
#defineREXT03
 /* relocation sizes */
#define RBYTE00
#define RWORD01
#define RLONG02
 /* macros which define various positions in file based on a bhdr, filhdr */
#define TEXTPOS ((long) sizeof(filhdr))
#define DATAPOS (TEXTPOS + filhdr.tsize)
#define SYMPOS(DATAPOS + filhdr.dsize)
#define RTEXTPOS(SYMPOS + filhdr.ssize)
#define RDATAPOS(RTEXTPOS + filhdr.rtsize)
#define ENDPOS(RDATAPOS + filhdr.rdsize)
 /* header of a.out files */
struct bhdr {
longfmagic;
longtsize;
longdsize;
longbsize;
longssize;
longrtsize;
longrdsize;
longentry;
};
 /* symbol management */
struct sym {
charstype;/* symbol type */
charsympad;/* pad to short align */
longsvalue;/* value */
};
 /* relocation commands */
struct reloc {
unsigned rsegment:2;    /* RTEXT, RDATA, RBSS, or REXTERN */
unsigned rsize:2;       /* RBYTE, RWORD, or RLONG */
unsigned rdisp:1;       /* 1 => a displacement */
unsigned relpad1:3;     /* pad 1 */
char relpad2;       /* pad 2 */
short rsymbol;          /* id of the symbol of external relocations */
long rpos;              /* position of relocation in segment */
};
 
struct nlist {/* symbol table entry */
char    n_name[8];    /* symbol name */
int     n_type;       /* type flag */
unsignedn_value;      /* value */
};
 /* values for type flag */
#defineN_UNDF0      /* undefined */
#defineN_ABS01     /* absolute */
#defineN_TEXT02     /* text symbol */
#defineN_DATA03     /* data symbol */
#defineN_BSS04     /* bss symbol */
#defineN_TYPE037
#defineN_REG024    /* register name */
#defineN_FN037    /* file name symbol */
#defineN_EXT040    /* external bit, or’ed in */
#defineFORMAT"%06o" /* to print a value */

The file has four sections: a header, the program and data text, a symbol table, and relocation information.  The last two may be empty if the program was loaded with the ’−s’ option of ld or if the symbols and relocation have been removed by strip(1).

In the header the sizes of each section are given in bytes, but are even.  The size of the header is not included in any of the other sizes. 

When an a.out file is loaded into core for execution, three logical segments are set up: the text segment, the data segment (with uninitialized data, which starts off as all 0, following initialized), and a stack.  The text segment begins at the user program start address in the core image; the header is not loaded.  If the magic number in the header is FMAGIC, it indicates that the text segment is not to be write-protected and shared, so the data segment is immediately contiguous with the text segment.  If the magic number is NMAGIC, the data segment begins at the next segment boundary following the text segment, and the text segment is not writeable by the program; if other processes are executing the same file, they will share the text segment. 

The stack will occupy the highest possible user program locations in the core image and will grow downwards.  The stack is automatically extended as required.  The data segment is only extended as requested by brk(2).

The start of the text segment in the file is 32(10); the start of the data segment is 32+St (the size of the text) the start of the relocation information is 32+St+Sd; the start of the symbol table is 32+2(St+Sd) if the relocation information is present, 32+St+Sd if not. 

The layout of a symbol table entry and the principal flag values that distinguish symbol types are given in the include file. 

If a symbol’s type is undefined external, and the value field is non-zero, the symbol is interpreted by the loader ld as the name of a common region whose size is indicated by the value of the symbol. 

The value of a word in the text or data portions which is not a reference to an undefined external symbol is exactly that value which will appear in core when the file is executed.  If a word in the text or data portion involves a reference to an undefined external symbol, as indicated by the relocation information for that word, then the value of the word as stored in the file is an offset from the associated external symbol.  When the file is processed by the link editor and the external symbol becomes defined, the value of the symbol will be added into the word in the file. 

If relocation information is present, it will appear in the form of the structure shown above. 

SEE ALSO

as(1), ld(1), nm(1)

7th Edition

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