1A.OUT(5)                      File Formats Manual                     A.OUT(5)
2
3
4

NAME

6       a.out - assembler and link editor output
7

SYNOPSIS

9       #include <a.out.h>
10

DESCRIPTION

12       A.out  is  the  output  file of the assembler as(1) and the link editor
13       ld(1).  Both programs make a.out executable if there were no errors and
14       no  unresolved external references.  Layout information as given in the
15       include file for the PDP11 is:
16
17       #ifndef __A_OUT_GNU_H__
18       #define __A_OUT_GNU_H__
19
20       #include <bits/a.out.h>
21
22       #define __GNU_EXEC_MACROS__
23
24       struct exec
25       {
26         unsigned long a_info;     /* Use macros N_MAGIC, etc for access.  */
27         unsigned int a_text;      /* Length of text, in bytes.  */
28         unsigned int a_data;      /* Length of data, in bytes.  */
29         unsigned int a_bss;       /* Length of uninitialized data area for file, in bytes.  */
30         unsigned int a_syms;      /* Length of symbol table data in file, in bytes.  */
31         unsigned int a_entry;     /* Start address.  */
32         unsigned int a_trsize;/* Length of relocation info for text, in bytes.  */
33         unsigned int a_drsize;/* Length of relocation info for data, in bytes.  */
34       };
35
36       enum machine_type
37       {
38         M_OLDSUN2 = 0,
39         M_68010 = 1,
40         M_68020 = 2,
41         M_SPARC = 3,
42         M_386 = 100,
43         M_MIPS1 = 151,
44         M_MIPS2 = 152
45       };
46
47       #define N_MAGIC(exec)       ((exec).a_info & 0xffff)
48       #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
49       #define N_FLAGS(exec)       (((exec).a_info >> 24) & 0xff)
50       #define N_SET_INFO(exec, magic, type, flags)   ((exec).a_info = ((magic) & 0xffff)   | (((int)(type) & 0xff) << 16)   | (((flags) & 0xff) << 24))
51       #define N_SET_MAGIC(exec, magic)   ((exec).a_info = ((exec).a_info & 0xffff0000) | ((magic) & 0xffff))
52       #define N_SET_MACHTYPE(exec, machtype)   ((exec).a_info =   ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
53       #define N_SET_FLAGS(exec, flags)   ((exec).a_info =   ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
54
55       /* Code indicating object file or impure executable.  */
56       #define OMAGIC 0407
57       /* Code indicating pure executable.  */
58       #define NMAGIC 0410
59       /* Code indicating demand-paged executable.  */
60       #define ZMAGIC 0413
61       /* This indicates a demand-paged executable with the header in the text.
62          The first page is unmapped to help trap NULL pointer references.  */
63       #define QMAGIC 0314
64       /* Code indicating core file.  */
65       #define CMAGIC 0421
66
67       #define N_TRSIZE(a)         ((a).a_trsize)
68       #define N_DRSIZE(a)         ((a).a_drsize)
69       #define N_SYMSIZE(a)        ((a).a_syms)
70       #define N_BADMAG(x)   (N_MAGIC(x) != OMAGIC&& N_MAGIC(x) != NMAGIC   && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
71       #define _N_HDROFF(x)        (1024 - sizeof (struct exec))
72       #define N_TXTOFF(x)   (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) :   (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
73       #define N_DATOFF(x)         (N_TXTOFF(x) + (x).a_text)
74       #define N_TRELOFF(x)        (N_DATOFF(x) + (x).a_data)
75       #define N_DRELOFF(x)        (N_TRELOFF(x) + N_TRSIZE(x))
76       #define N_SYMOFF(x)         (N_DRELOFF(x) + N_DRSIZE(x))
77       #define N_STROFF(x)         (N_SYMOFF(x) + N_SYMSIZE(x))
78
79       /* Address of text segment in memory after it is loaded.  */
80       #define N_TXTADDR(x)        (N_MAGIC(x) == QMAGIC ? 4096 : 0)
81
82       /* Address of data segment in memory after it is loaded.  */
83       #define SEGMENT_SIZE        1024
84
85       #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
86       #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
87
88       #define N_DATADDR(x)   (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x))   : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
89       #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
90
91       #if !defined (N_NLIST_DECLARED)
92       struct nlist
93       {
94         union
95           {
96             char *n_name;
97             struct nlist *n_next;
98             long n_strx;
99           } n_un;
100         unsigned char n_type;
101         char n_other;
102         short n_desc;
103         unsigned long n_value;
104       };
105       #endif /* no N_NLIST_DECLARED.  */
106
107       #define N_UNDF   0
108       #define N_ABS    2
109       #define N_TEXT   4
110       #define N_DATA   6
111       #define N_BSS    8
112       #define N_FN     15
113       #define N_EXT    1
114       #define N_TYPE   036
115       #define N_STAB   0340
116       #define N_INDR   0xa
117       #define N_SETA   0x14       /* Absolute set element symbol.  */
118       #define N_SETT   0x16       /* Text set element symbol.  */
119       #define N_SETD   0x18       /* Data set element symbol.  */
120       #define N_SETB   0x1A       /* Bss set element symbol.  */
121       #define N_SETV   0x1C       /* Pointer to set vector in data area.  */
122
123       #if !defined (N_RELOCATION_INFO_DECLARED)
124       /* This structure describes a single relocation to be performed.
125          The text-relocation section of the file is a vector of these structures,
126          all of which apply to the text section.
127          Likewise, the data-relocation section applies to the data section.  */
128
129       struct relocation_info
130       {
131         int r_address;
132         unsigned int r_symbolnum:24;
133         unsigned int r_pcrel:1;
134         unsigned int r_length:2;
135         unsigned int r_extern:1;
136         unsigned int r_pad:4;
137       };
138       #endif /* no N_RELOCATION_INFO_DECLARED.  */
139
140       #endif /* __A_OUT_GNU_H__ */
141
142       The file has four sections: a header, the program and data text,  relo‐
143       cation  information,  and a symbol table (in that order).  The last two
144       may be empty if the program was loaded with the `-s' option of ld or if
145       the symbols and relocation have been removed by strip(1).
146
147       In  the  header  the  sizes of each section are given in bytes, but are
148       even.  The size of the header is not  included  in  any  of  the  other
149       sizes.
150
151       When  an  a.out  file  is loaded into core for execution, three logical
152       segments are set up: the text segment, the data  segment  (with  unini‐
153       tialized data, which starts off as all 0, following initialized), and a
154       stack.  The text segment begins at 0 in the core image; the  header  is
155       not loaded.  If the magic number in the header is 0407(8), it indicates
156       that the text segment is not to be write-protected and shared,  so  the
157       data  segment  is immediately contiguous with the text segment.  If the
158       magic number is 0410, the data segment begins at the  first  0  mod  8K
159       byte  boundary  following the text segment, and the text segment is not
160       writable by the program; if other  processes  are  executing  the  same
161       file,  they  will  share the text segment.  If the magic number is 411,
162       the text segment is again pure, write-protected, and shared, and  more‐
163       over  instruction  and data space are separated; the text and data seg‐
164       ment both begin at location 0.  If the magic number is 0405,  the  text
165       segment  is overlaid on an existing (0411 or 0405) text segment and the
166       existing data segment is preserved.
167
168       The stack will occupy the highest possible locations in the core image:
169       from  0177776(8)  and  growing  downwards.   The stack is automatically
170       extended as required.  The data segment is only extended  as  requested
171       by brk(2).
172
173       The  start  of the text segment in the file is 020(8); the start of the
174       data segment is 020+St (the size of the text) the start of the  reloca‐
175       tion  information  is  020+St+Sd;  the  start  of  the  symbol table is
176       020+2(St+Sd) if the relocation information  is  present,  020+St+Sd  if
177       not.
178
179       The  layout  of a symbol table entry and the principal flag values that
180       distinguish symbol types are given in the  include  file.   Other  flag
181       values  may  occur  if  an  assembly  language  program defines machine
182       instructions.
183
184       If a symbol's type is undefined external, and the value field  is  non-
185       zero,  the symbol is interpreted by the loader ld as the name of a com‐
186       mon region whose size is indicated by the value of the symbol.
187
188       The value of a word in the text or data portions which is not a  refer‐
189       ence  to  an undefined external symbol is exactly that value which will
190       appear in core when the file is executed.  If a word  in  the  text  or
191       data  portion  involves a reference to an undefined external symbol, as
192       indicated by the relocation information for that word, then  the  value
193       of  the  word  as  stored  in the file is an offset from the associated
194       external symbol.  When the file is processed by the link editor and the
195       external  symbol becomes defined, the value of the symbol will be added
196       into the word in the file.
197
198       If relocation information is present, it amounts to one word  per  word
199       of  program  text or initialized data.  There is no relocation informa‐
200       tion if the `relocation info stripped' flag in the header is on.
201
202       Bits 3-1 of a relocation word indicate the segment referred to  by  the
203       text or data word associated with the relocation word:
204
205       000    absolute number
206       002    reference to text segment
207       004    reference to initialized data
208       006    reference to uninitialized data (bss)
209       010    reference to undefined external symbol
210
211       Bit  0  of  the  relocation word indicates, if 1, that the reference is
212       relative to the pc (e.g. `clr x'); if 0, that the reference is  to  the
213       actual symbol (e.g., `clr *$x').
214
215       The remainder of the relocation word (bits 15-4) contains a symbol num‐
216       ber in the case of external references, and is unused  otherwise.   The
217       first symbol is numbered 0, the second 1, etc.
218

SEE ALSO

220       as(1), ld(1), nm(1)
221
222
223
224                                                                      A.OUT(5)
Impressum