Annotation of researchv10dc/man/man5/a.out.5, revision 1.1.1.1

1.1       root        1: .TH A.OUT 5
                      2: .CT 1 lib_obj
                      3: .SH NAME
                      4: a.out \- object file format
                      5: .SH SYNOPSIS
                      6: .B #include <a.out.h>
                      7: .SH DESCRIPTION
                      8: .I A.out
                      9: is the default name of the output file of the assembler
                     10: .IR as (1)
                     11: or the link editor
                     12: .IR ld (1).
                     13: Both programs make
                     14: .I a.out
                     15: executable if there were no
                     16: errors and no unresolved external references.
                     17: An object file has five sections:
                     18: a header, the program text and data,
                     19: relocation information, a symbol table and a string table (in that order).
                     20: The last three may be absent; see
                     21: .IR strip (1)
                     22: and option
                     23: .B -s
                     24: of
                     25: .IR ld (1).
                     26: The header format, given in 
                     27: .BR <a.out.h> ,
                     28: is
                     29: .PP
                     30: .EX
                     31: .ta \w'#define  'u +\w'unsigned  'u +\w'a_dirsize  'u +4n
                     32: struct exec {
                     33:        long    a_magic;        /* magic number */
                     34:        unsigned        a_text; /* size of text segment */
                     35:        unsigned        a_data; /* size of initialized data */
                     36:        unsigned        a_bss;  /* size of uninitialized data */
                     37:        unsigned        a_syms; /* size of symbol table */
                     38:        unsigned        a_entry;        /* entry point */
                     39:        unsigned        a_trsize;       /* size of text relocation */
                     40:        unsigned        a_drsize;       /* size of data relocation */
                     41: };
                     42: #define        OMAGIC  0407    /* old impure format */
                     43: #define        NMAGIC  0410    /* read-only text */
                     44: #define        ZMAGIC  0413    /* demand load format */
                     45: .EE
                     46: .PP
                     47: Macros which take
                     48: .L exec
                     49: structures as arguments and tell whether
                     50: the file has a reasonable magic number or return offsets:
                     51: .EX
                     52: #define        N_BADMAG(x) (((x).a_magic)!=OMAGIC && \e
                     53:        ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
                     54: #define        N_TXTOFF(x) \e
                     55:        ((x).a_magic==ZMAGIC ? 1024 : sizeof (struct exec))
                     56: #define N_SYMOFF(x) (N_TXTOFF(x) + (x).a_text+(x).a_data + \e
                     57:        (x).a_trsize+(x).a_drsize)
                     58: #define        N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
                     59: .EE
                     60: .DT
                     61: .PP
                     62: Sizes are expressed in bytes.
                     63: The size of the header is not included in any of the other sizes.
                     64: .PP
                     65: When an
                     66: .F a.out
                     67: file is executed, a memory image of three segments is
                     68: set up: the text segment, the data segment,
                     69: and a stack.
                     70: The text segment begins at virtual address 0.
                     71: Following the text segment is the data segment, in which
                     72: explicitly initialized data come first, then
                     73: other data, initialized to 0.
                     74: The stack occupies the highest possible locations
                     75: in the core image, automatically growing downwards from
                     76: .lg 0
                     77: .BR 0x7ffff400 
                     78: .lg 1
                     79: as needed.
                     80: The data segment may be extended by
                     81: .IR brk (2).
                     82: .PP
                     83: If the magic number in the header is
                     84: .BR OMAGIC ,
                     85: the text
                     86: segment is neither write-protected nor shared and
                     87: the data segment is immediately contiguous
                     88: with the text segment.
                     89: This kind of executable program is rarely used.
                     90: If the magic number is
                     91: .BR NMAGIC 
                     92: or
                     93: .BR ZMAGIC ,
                     94: the data segment is loaded at the first 0 mod 1024 address
                     95: following the text segment,
                     96: and the text segment is write-protected and shared among
                     97: all processes that are executing the same file.
                     98: .BR ZMAGIC
                     99: format, which
                    100: .IR ld (1)
                    101: produces by default, supports demand paging: the
                    102: text and data segments are multiples of
                    103: 1024 bytes long and begin at byte offsets of 0 mod 1024
                    104: in the
                    105: .F a.out
                    106: file.
                    107: .PP
                    108: Macros are provided to compute the absolute offset of various
                    109: parts of the file:
                    110: .TF N_TXTOFF
                    111: .TP 
                    112: .B N_TXTOFF
                    113: Text segment.
                    114: .TP
                    115: .B N_SYMOFF
                    116: Symbol table.
                    117: .TP
                    118: .B N_STROFF
                    119: String table.
                    120: .PD
                    121: .PP
                    122: The offsets of the data segment, text relocation information,
                    123: and data relocation information are obtained by successively
                    124: adding to 
                    125: .B N_TXTOFF
                    126: the size fields
                    127: .BR a_text ,
                    128: .BR a_data ,
                    129: and
                    130: .BR a_trsize .
                    131: The first 4 bytes of the string table contain it size, including
                    132: the 4 bytes.
                    133: .PP
                    134: The layout of a symbol table entry, as given in
                    135: .BR <a.out.h> ,
                    136: is
                    137: .PP
                    138: .EX
                    139: .ta \w'#define  'u +\w'char'u-1u +\w'unsigned  'u+1u +\w'*n_name 'u
                    140: struct nlist {
                    141:        union {
                    142:                char    *n_name;        /* for use when in-core */
                    143:                long    n_strx; /* index into file string table */
                    144:        } n_un;
                    145:        unsigned char   n_type; /* type flag; see below */
                    146:        char    n_other;
                    147:        short   n_desc; /* see \fIstab\fR(5)\f5 */
                    148:        unsigned        n_value;        /* value of this symbol (or struct offset) */
                    149: };
                    150: .EE
                    151: .PP
                    152: Basic values for
                    153: .BR n_type :
                    154: .PP
                    155: .EX
                    156: #define        N_UNDF  0x0     /* undefined */
                    157: #define        N_ABS   0x2     /* absolute */
                    158: #define        N_TEXT  0x4     /* text */
                    159: #define        N_DATA  0x6     /* data */
                    160: #define        N_BSS   0x8     /* bss */
                    161: #define        N_COMM  0x12    /* common (internal to ld) */
                    162: #define        N_FN    0x1f    /* file name symbol */
                    163: #define        N_EXT   01      /* external bit, or'ed in */
                    164: #define        N_TYPE  0x1e    /* mask for all the type bits */
                    165: .EE
                    166: .PP
                    167: Other permanent symbol table entries have some
                    168: .B N_STAB
                    169: bits set.
                    170: These are given in
                    171: .LR <stab.h> :
                    172: .EX
                    173: #define        N_STAB  0xe0    /* if any of these bits set, keep */
                    174: .EE
                    175: .DT
                    176: .PP
                    177: The field
                    178: .B n_un.n_strx
                    179: gives an index into the
                    180: string table; 0
                    181: indicates that no name is associated
                    182: with the entry.
                    183: The field
                    184: .B n_un.n_name
                    185: can be used
                    186: to refer to the symbol name only if the program sets this up using
                    187: .B n_strx
                    188: and appropriate data from the string table.
                    189: .PP
                    190: A symbol of type undefined external with nonzero value field
                    191: names a common region; the value specifies its size.
                    192: .PP
                    193: Relocation
                    194: information occupies eight bytes per
                    195: relocatable datum:
                    196: .PP
                    197: .EX
                    198: .ta \w'#define  'u +\w'unsigned  'u +\w'r_symbolnum:24,  'u +4n
                    199: struct relocation_info {
                    200:        int     r_address;      /* address of datum to be relocated */
                    201:        unsigned        r_symbolnum:24, /* local symbol ordinal */
                    202:                r_pcrel:1,      /* is referenced relative to pc */
                    203:                r_length:2,     /* 0=byte, 1=word, 2=long */
                    204:                r_extern:1,     /* symbol value unknown */
                    205:                :4;     /* nothing, yet */
                    206: };
                    207: .EE
                    208: .DT
                    209: .PP
                    210: If
                    211: .B r_extern 
                    212: is 1, the datum designated by
                    213: .B r_address 
                    214: and
                    215: .B r_length
                    216: will be relocated by adding to it the value of the associated
                    217: external symbol.
                    218: If
                    219: .B r_extern
                    220: is 0, 
                    221: .BR r_symbolnum
                    222: is encoded in the style of
                    223: .B n_type
                    224: and the value will be relocated by adding the relocated base of
                    225: the designated area (text, initialized data, or common data).
                    226: .SH "SEE ALSO"
                    227: .IR adb (1), 
                    228: .IR as (1), 
                    229: .IR ld (1), 
                    230: .IR nm (1), 
                    231: .IR stab (5), 
                    232: .IR strip (1)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.