This appendix contains the following sections:
Introduction
File Header
Section Headers
Section Fillers
Relocation Records
Name Records
Extension Records
The layout of the assembler/linker output file is machine independent (through being fully byte oriented), compact and accepts variable-length symbols. All chars are 1 byte, shorts are 2 bytes and longs are 4 bytes.
The elements of an a.out file describe the sections in the file and the symbol debug information. These elements include:
- Segment Range recordsAllocation records
The linker produces absolute object files. These files do not contain relocation records. The following figure illustrates the layout of an a.out file:
Linking large applications the maximum number of sections in an a.out file (62) is easily reached. There is a new version of a.out, version 2, that supports a larger maximum section count. This is 256. Due to this change the layout of the header for version 1 and version 2 is slightly different. The two figures at the end of this section show the difference.
The file header occupies the first 20 bytes (version 1) or 22 bytes (version 2) of the file and comprises:
oh_magic An unsigned short containing the 'magic' number specifying the type of file (assembler/linker output file).
oh_stamp An unsigned short containing the version stamp (the assembler/linker release version). The upper 8 bits of the stamp field contain a code specifying the target processor.
oh_flags An unsigned short specifying the following format flags:
HF_BREV If bit 0 of oh_flags is '1' then the high order byte of an adjacent pair of bytes is contained in the lower address; otherwise it is in the higher address.
HF_WREV If bit 1 of oh_flags is '1' then the high order word of an adjacent pair of words is contained in the lower address; otherwise it is in the higher address.
HF_LINK If bit 2 of oh_flags is '1' then one or more references remain unresolved; otherwise all references have been resolved.
HF_8086 If bit 3 of oh_flags is '1' then os_base has been specially encoded for an 8086 machine.
oh_nsect Version 1:
A char containing the number of output section fillers.
oh_nsegm Version 1:
A char containing the number of segments used.
oh_nrelo An unsigned short containing the number of relocation records.
oh_nname An unsigned short containing the number of name records (also called 'symbol records').
oh_nemit A long containing the sum of the sizes of all sections in the file.
oh_nchar A long containing the size of the symbol string area
file header layout (Version 1):
byte type description number 0-1 unsigned short oh_magic: magic number 2-3 unsigned short oh_stamp: version stamp 4-5 unsigned short oh_flags: flag field 6 char oh_nsect: number of sections 7 char oh_nsegm: number of segments 8-9 unsigned short oh_nrelo: number of relocation records 10-11 unsigned short oh_nname: number of name records 12-15 long oh_nemit: number of bytes initialized data in the file 16-19 long oh_nchar: size of string area
file header layout (Version 2):
byte type description number 0-1 unsigned short oh_magic: magic number 2-3 unsigned short oh_stamp: version stamp 4-5 unsigned short oh_flags: flag field 6-7 unsigned short oh_nsect: number of sections 8-9 unsigned short oh_nrelo: number of relocation records 10-11 unsigned short oh_nname: number of name records 12-15 long oh_nemit: number of bytes initialized data in the file 16-19 long oh_nchar: size of string area 20-21 unsigned short oh_nsegm: number of segments
The section header records comprise a separate header for each output section; each section header record occupies 20 bytes and comprises the following:
os_base A long containing the start address of the section in the machine.
os_size A long containing the size of the section in the machine.
os_foff A long containing the start address of the section in the file.
os_flen A long containing the size of the section in the file.
os_lign A long containing the alignment of the section.
The section contents follow the section headers and comprise the contents of each output section, in the same order as the section headers. The contents start at the address specified by os_base and are of the length specified by os_size. The initialized portion of the section is of the length specified by os_flen. An uninitialized portion of the contents comprising os_size - os_flen bytes is left at the end of the contents. There are no restrictions on section boundaries so sections may overlap.
Relocation records comprise an 8-byte entry for each occurrence of a relocatable value; the entries have the following structure:
or_type A char containing the type of reference.
or_sect A char containing the number of the referencing section. If or_sect is zero, the relocation record is a symbol table relocation record rather than a code relocation record.
or_nami An unsigned short containing the referenced symbol index (the offset from the start of the symbol table).
or_addr A long containing the address where relocation is to take place. If the current relocation record is a symbol table relocation record, or_addr contains the index of the symbol to be relocated.
The name records comprise a variable length entry for each symbol. Each entry consists of a record and an associated identifier; the record and the identifier are held separately to allow variable length identifiers. The records comprise the following:
on_u A union which can contain (at different times) either a char pointer (on_ptr) or a long (on_off). on_ptr is the symbol name when the file is loaded into memory for execution and on_off is the offset in the file to the first character of the identifier.
on_type An unsigned short which describes the symbol as follows:
S_TYP This comprises the least significant 7 bits of on_type which have the following significance:
If all bits are '0' the symbol is undefined (S_UND).
If bit 0 is '1' and bits 1 to 6 are all '0' the symbol is absolute (S_ABS).
Otherwise it is relative. In version 1 of the a.out file format these bits specify the section number. In version 2 of the a.out file format a separate field is used (S_SEC). The number of bits are not enough to hold all possible section numbers.
S_PUB If bit 6 of on_type is '1' the symbol is associated with a .comm pseudo.
S_EXT If bit 7 of on_type is '1' the symbol is external; otherwise it is local.
S_ETC Bits 8-15 are the type specification for the symbol table information. The include file sd_class.h contains a list of possible numbers and their meaning.
on_desc An unsigned short containing the debug information.
on_valu A long containing the symbol value.
on_sect An unsigned short containing the number of the relocatable section the symbol belongs to (format version 2 only).
In order to permit several symbolic debug features, all symbol entries are in the order of their definition. The section symbols occupy the last entries in the symbol table for the purpose of quick reference.
The way the link information is passed from the assembler to the linker is through extension records at the end of the file. Within the framework of these extension records we can describe all the extra information required.
The extension records only occur in object files. Extension records consist of:
- an extension header
- allocation specification records.
The extension header consists of 8 bytes and consist of:
eh_magic An unsigned short containing the 'magic' number specifying the type of file (assembler/linker output file).
N_MAGIC (0x202) specifies an object file
eh_stamp An unsigned short containing the version stamp (the assembler/linker release version)
eh_nsegm An unsigned short containing the number of range specification records.
eh_allo An unsigned short containing the number of allocation records.
The segment range allocation records specify the lower bound and upper bound of a particular memory range.
es_type An unsigned short containing segment type information.
S_TYP In version 1 of the file format these bits contain the segment number. In version 2 these bits are meaningless.
S_ETC Bits 8-15 are the type specification bits. Currently used values are:
S_RNG with a value of 0x7100: range record.
es_desc An unsigned short, currently not used, but it can be used for future debugging extensions.
es_lval A long containing the lower bound value of the memory range.
es_uval A long containing the upper bound value of the memory range.
es_sect An unsigned short containing the segment type information. (format version 2 only)
ea_type An unsigned short containing segment type information. Types are:
S_TYP In version 1 of the file format these bits contain the segment number. In version 2 these bits are meaningless.
S_ETC Bits 8-15 are the type specification bits. Currently used values are:
S_BAS specifies the base value (0x7200)
S_PAG specifies the page value (0x7300)
S_INP specifies the inpage value (0x7400).
S_SBAS specifies the SBASE value (0x7500). (8086, 80186)
S_USE specifies the final "using" value (0x7600). (8051)
ea_desc An unsigned short, currently not used, but it can be used for future debugging extensions.
ea_valu A long containing the page size or the base address.
ea_sect An unsigned short containing the segment type information. (format version 2 only)