a.out(FP) 6 January 1993 a.out(FP) Name a.out - UNIX common assembler and link editor output Syntax #include <a.out.h> Description The file name a.out is the default output file name from the link editor ld(CP). The link editor will make a.out executable if there were no errors in linking. The output file of the UNIX assembler as(CP) 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 (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 as shown: 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(CP) or if they were removed by strip(CP). Also note that the relo- cation information will be absent after linking unless the -r option of ld(CP) was used. The string table exists only if the symbol table con- tains symbols with names longer than eight characters. The sizes of each section (contained in the header, as discussed later) 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, with the latter actually being initialized to all 0's), and a stack. The text segment starts at location virtual address 0. The a.out file produced by ld(CP) may have one of two magic numbers in the first field of the UNIX system header. A magic number of 0410 indi- cates that the executable must be swapped through the private swapping store of the UNIX system, while the magic number 0413 causes the system to attempt to page the text directly from the a.out file. In a 0410 executable, the text section is loaded at virtual location 0x00000000. The data section is loaded after the text section. For a 0413 executable, the headers (file header, UNIX system header, and section headers) are loaded at the beginning of the text segment, and the text follows the headers in the user address space. The first text address will equal the sum of the sizes of the headers, and will vary, depending on the number of sections in the a.out file. In an a.out file with three sections (.text, .data, and .bss), the first text address is at 0x000000D0. The data section starts in the next page table directory after the last one used by the text section, in the first page of that directory, with an offset into that page equal to the first unused memory offset in the last page of text. Thus, given that etext is the address of the last byte of the text section, the 1st byte of the data section will be at 0x00400000 + (etext & 0xFFC00000) + ((etext+1) & 0xFFC00FFF). On the 80386 computer the stack begins at location 7FFFFFFC and grows toward lower addresses. The stack is automatically extended as required. The data segment is extended only as requested by the brk(S) 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 the value that will appear in memory when the file is executed. If a word in the text 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 */ }; UNIX system header The format of the UNIX system 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[SYMNMLEN]; /* 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 short s_nreloc; /* # reloc entries */ unsigned short 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 */ ushort r_type; /* relocation type */ }; The start of the relocation information is srelptr from the section header. If there is no relocation information, srelptr is 0. 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 */ }; #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 fol- lowed by auxiliary entries that are the same size as a symbol entry. The format follows: union auxent { struct { long x_tagndx; union { struct { unsigned short x_lnno; unsigned short x_size; } x_lnsz; long x_fsize; } x_misc; union { struct { long x_lnnoptr; long x_endndx; } x_fcn; struct { unsigned short x_dimen[DIMNUM]; } x_ary; } x_fcnary; unsigned short x_tvndx; } x_sym; union { char x_fname[FILNMLEN]; struct { long x_zero; long x_offset; } x_longname; } 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 fsymptr (from the file header) bytes from the beginning of the file. If the symbol table is stripped, fsymptr is 0. The string table (if one exists) begins at fsymptr + (fnsyms * SYMESZ) bytes from the beginning of the file. See also as(CP), cc(CP), ld(CP), brk(S), filehdr(FP), ldfcn(FP), linenum(FP), reloc(FP), scnhdr(FP), syms(FP)