Charles.Forsyth20060303-partialeea662d19 years agoHistory
242 lines · 6.9 KB · Text
RawDownload
.TH A.OUT 10.6.SH NAMEa.out \- native kernel object file format.SH SYNOPSIS.B #include <a.out.h>.SH DESCRIPTIONAn executable native binary file has up to six sections:a header, the program text, the data,a symbol table, a PC/SP offset table (MC680x0 only),and finally a PC/line number table.The header, given by a structure in.BR <a.out.h> ,contains 4-byte integers in big-endian order:.PP.EXtypedef struct Exec {    long    magic;  /* magic number */    long    text;   /* size of text segment */    long    data;   /* size of initialized data */    long    bss;    /* size of uninitialized data */    long    syms;   /* size of symbol table */    long    entry;  /* entry point */    long    spsz;   /* size of pc/sp offset table */    long    pcsz;   /* size of pc/line number table */} Exec;#define _MAGIC(b)   ((((4*b)+0)*b)+7)#define A_MAGIC     _MAGIC(8)   /* 68020 */#define I_MAGIC     _MAGIC(11)  /* intel 386 */#define J_MAGIC     _MAGIC(12)  /* intel 960 */#define K_MAGIC     _MAGIC(13)  /* sparc */#define V_MAGIC     _MAGIC(16)  /* mips 3000 */#define X_MAGIC     _MAGIC(17)  /* att dsp 3210 */#define M_MAGIC     _MAGIC(18)  /* mips 4000 */#define D_MAGIC     _MAGIC(19)  /* amd 29000 */#define E_MAGIC     _MAGIC(20)  /* arm 7-something */#define Q_MAGIC     _MAGIC(21)  /* powerpc */#define N_MAGIC     _MAGIC(22)  /* mips 4000-le */#define L_MAGIC     _MAGIC(23)  /* dec alpha */.EE.DT.PPSizes are expressed in bytes.The size of the header is not included in any of the other sizes..PPWhen a Plan 9 binary file is executed,a memory image of three segments isset up: the text segment, the data segment, and the stack.The text segment begins at a virtual address which isa multiple of the machine-dependent page size.The text segment consists of the header and the first.B textbytes of the binary file.The.B entryfield gives the virtual address of the entry point of the program.The data segment starts at the first page-rounded virtual addressafter the text segment.It consists of the next.B databytes of the binary file, followed by.B bssbytes initialized to zero.The stack occupies the highest possible locationsin the core image, automatically growing downwards..PPThe next.B syms(possibly zero)bytes of the file contain symbol tableentries, each laid out as:.IP.EXuchar value[4];char  type;char  name[\f2n\fP];   /* NUL-terminated */.EE.PPThe.B valueis in big-endian order andthe size of the.B namefield is not pre-defined: it is a zero-terminated array ofvariable length..PPThe.B typefield is one of the following characters:.RS.TP.B Ttext segment symbol.PD0.TP.B tstatic text segment symbol.TP.B Lleaf function text segment symbol.TP.B lstatic leaf function text segment symbol.TP.B Ddata segment symbol.TP.B dstatic data segment symbol.TP.B Bbss segment symbol.TP.B bstatic bss segment symbol.TP.B aautomatic (local) variable symbol.TP.B pfunction parameter symbol.RE.PD.PPA few others are described below.The symbols in the symbol table appear in the same orderas the program components they describe..PPThe Plan 9 compilers implement a virtual stack frame pointer ratherthan dedicating a register;moreover, on the MC680x0there is a variable offset between the stack pointer and theframe pointer.Following the symbol table,MC680x0 executable files contain a.BR spsz -bytetable encoding the offsetof the stack frame pointer as a function of program location;this section is not present for other architectures.The PC/SP table is encoded as a byte stream.By setting the PC to the base of the text segmentand the offset to zero and interpreting the stream,the offset can be computed for any PC.A byte value of 0 is followed by four bytes that hold, in big-endian order,a constant to be added to the offset.A byte value of 1 to 64 is multiplied by four and added, without signextension, to the offset.A byte value of 65 to 128 is reduced by 64, multiplied by four, andsubtracted from the offset.A byte value of 129 to 255 is reduced by 129, multiplied by the quantumof instruction size(e.g. two on the MC680x0),and added to the current PC without changing the offset.After any of these operations, the instruction quantum is added to the PC..PPA similar table, occupying.BR pcsz -bytes,is the next section in an executable; it is present for all architectures.The same algorithm may be run using this table torecover the absolute source line number from a given program location.The absolute line number (starting from zero) counts the newlinesin the C-preprocessed source seen by the compiler.Three symbol types in the main symbol table facilitate conversion of the absolutenumber to source file and line number:.RS.TP.B fsource file name components.TP.B zsource file name.TP.B Zsource file line offset.RE.PPThe.B fsymbol associates an integer (the.B valuefield of the `symbol') witha unique file path name component (the.B nameof the `symbol').These path components are used by the.B zsymbol to represent a file name: thefirst byte of the name field is always 0; the remainingbytes hold a zero-terminated array of 16-bit values (in big-endian order)that represent file name components from.B fsymbols.These components, when separated by slashes, form a file name.The initial slash of a file name is recorded in the symbol table by an.B fsymbol; when forming file names from.B zsymbols an initial slash is not to be assumed.The.B zsymbols are clustered, one set for each object file in the program,before any text symbols from that object file.The set of.B zsymbols for an object file form a.I history stackof the included source files from which the object file was compiled.The value associated with each.B zsymbol is the absolute line number at which that file was included in the source;if the name associated with the.B zsymbol is null, the symbol represents the end of an included file, that is,a pop of the history stack.If the value of the.B zsymbol is 1 (one),it represents the start of a new history stack.To recover the source file and line number for a program location,find the text symbol containing the locationand then the first history stack preceding the text symbol in the symbol table.Next, interpret the PC/line offset table to discover the absolute line numberfor the program location.Using the line number, scan the history stack to find the set of sourcefiles open at that location.The line number within the file can be found using the line numbersin the history stack.The.B Zsymbols correspond to.B #linedirectives in the source; they specify an adjustment to the line numberto be printed by the above algorithm.  The offset is associated with thefirst previous.B zsymbol in the symbol table..SH "SEE ALSO".IR acid (10.1), .IR 2a (10.1), .IR 2l (10.1), .IR inm (10.1).SH BUGSThere is no type information in the symbol table.