A.OUT(5) UNIX Programmer's Manual A.OUT(5) NAME a.out - assembler and loader output SYNOPSIS #include DESCRIPTION _A._o_u_t is the output file of the assembler _a_s(1) and the loader _l_d(1). Both programs make _a._o_u_t executable if there were no errors and no unresolved external references. Lay- out information as given in the include file for the PDP11 is: #define NOVL 7 #define A_MAGIC1 0407 /* normal */ #define A_MAGIC2 0410 /* read-only text */ #define A_MAGIC3 0411 /* separated I&D */ #define A_MAGIC4 0405 /* overlay */ #define A_MAGIC5 0430 /* auto-overlay (nonseparate) */ #define A_MAGIC6 0431 /* auto-overlay (separate) */ struct exec { int a_magic; /* magic number */ unsigned a_text; /* size of text segment */ unsigned a_data; /* size of initialized data */ unsigned a_bss; /* size of uninitialized data */ unsigned a_syms; /* size of symbol table */ unsigned a_entry; /* entry point */ unsigned a_unused; /* not used */ unsigned a_flag; /* relocation info stripped */ }; struct ovlhdr { int max_ovl;/* maximum ovl size */ unsigned ov_siz[NOVL];/* size of i'th overlay */ }; struct nlist { char n_name[8]; /* symbol name */ int n_type; /* type flag */ unsigned n_value; /* value */ }; /* * Macros which take exec structures as arguments and tell whether * the file has a reasonable magic number or offset to text. */ #define N_BADMAG(x) \ (((x).a_magic)!=A_MAGIC1 && ((x).a_magic)!=A_MAGIC2 && \ ((x).a_magic)!=A_MAGIC3 && ((x).a_magic)!=A_MAGIC4 && \ ((x).a_magic)!=A_MAGIC5 && ((x).a_magic)!=A_MAGIC6) Printed 5/17/83 1 A.OUT(5) UNIX Programmer's Manual A.OUT(5) #define N_TXTOFF(x) \ ((x).a_magic==A_MAGIC5 || (x).a_magic==A_MAGIC6 ? \ sizeof (struct ovlhdr) + sizeof (struct exec) : sizeof (struct exec)) /* values for type flag */ #define N_UNDF 0 /* undefined */ #define N_ABS 01 /* absolute */ #define N_TEXT 02 /* text symbol */ #define N_DATA 03 /* data symbol */ #define N_BSS 04 /* bss symbol */ #define N_TYPE 037 /* mask for type flag */ #define N_REG 024 /* register name */ #define N_FN 037 /* file name symbol */ #define N_EXT 040 /* external bit, or'ed in */ #define FORMAT "%06o" /* to print a value */ The file has four sections: a header, the program and data text, relocation information, and a symbol table (in that order). The last two may be empty if the program was loaded with the `-s' option of _l_d or if the symbols and relocation have been removed by _s_t_r_i_p(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._o_u_t file is loaded into core for execution, three or four logical segments are set up: the text segment, a possible text overlay segment, the data segment (with unini- tialized data, which starts off as all 0, following initial- ized), and a stack. The text segment begins at 0 in the core image; the header is not loaded. If the magic number in the header is 0407(8), 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 0410, the data segment begins at the first 0 mod 8K byte boundary following the text segment, and the text segment is not writable by the program; if other processes are executing the same file, they will share the text segment. If the magic number is 0411, the text segment is again pure, write-protected, and shared, and moreover instruction and data space are separated; the text and data segment both begin at location 0. If the magic number is 0405, the text segment is overlaid on an existing (0411 or 0405) text segment and the existing data segment is preserved. If the magic number is 0430, the base text segment is write-protected and shared and is followed by a text overlay segment. There are a maximum of 7 overlays, all pure and shared. The base segment runs from 0 to txtsiz. At the next 0 mod 8k boundary is the overlay region, which is as Printed 5/17/83 2 A.OUT(5) UNIX Programmer's Manual A.OUT(5) large as the largest overlay. When running, any one of the 7 overlays can be mapped into this region. At the following 0 mod 8k byte boundary the data segment begins. If the magic number is 0431, the situation is the same as for type 0430 except that instruction and data spaces are separated and both begin at location 0. Both 0430 and 0431 executable files have a second header between the normal a.out header and the start of the text image; it contains the maximum overlay size and the sizes of each of the seven overlays. The text images of the overlays follow the text in the object file, and are followed by the initialized data. The stack segment will occupy the highest possible locations in the core image: from 0177776(8) and growing downwards. The stack segment is automatically extended as required. The data segment is only extended as requested by _b_r_k(2). The layout of a symbol table entry and the principal flag values that distinguish symbol types are given in the include file. Other flag values may occur if an assembly language program defines machine instructions. If a symbol's type is undefined external, and the value field is non-zero, the symbol is interpreted by the loader _l_d 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 exe- cuted. 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 associ- ated 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 amounts to one word per word of program text or initialized data. There is no relocation information if the `relocation info stripped' flag in the header is on. Automatic-overlay (0430 and 0431) files do not contain relocation information. Bits 3-1 of a relocation word indicate the segment referred to by the text or data word associated with the relocation word: 000 absolute number 002 reference to text segment 004 reference to initialized data 006 reference to uninitialized data (bss) Printed 5/17/83 3 A.OUT(5) UNIX Programmer's Manual A.OUT(5) 010 reference to undefined external symbol Bit 0 of the relocation word indicates, if 1, that the reference is relative to the pc (e.g. `clr x'); if 0, that the reference is to the actual symbol (e.g., `clr *$x'). The remainder of the relocation word (bits 15-4) contains a symbol number in the case of external references, and is unused otherwise. The first symbol is numbered 0, the second 1, etc. SEE ALSO as(1), ld(1), nm(1) Printed 5/17/83 4