Commit | Line | Data |
---|---|---|
3922de1d C |
1 | |
2 | ||
3 | ||
4 | A.OUT(5) 1986 A.OUT(5) | |
5 | ||
6 | ||
7 | ||
8 | N\bNA\bAM\bME\bE | |
9 | a.out - assembler and link editor output | |
10 | ||
11 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS | |
12 | #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<a\ba.\b.o\bou\but\bt.\b.h\bh>\b> | |
13 | ||
14 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN | |
15 | _\bA._\bo_\bu_\bt is the output file of the assembler _\ba_\bs(1) and the link | |
16 | editor _\bl_\bd(1). Both programs make _\ba._\bo_\bu_\bt executable if there | |
17 | were no errors and no unresolved external references. Lay- | |
18 | out information as given in the include file for the VAX-11 | |
19 | is: | |
20 | ||
21 | /* | |
22 | * Header prepended to each a.out file. | |
23 | */ | |
24 | struct exec { | |
25 | long a_magic; /* magic number */ | |
26 | unsigned a_text; /* size of text segment */ | |
27 | unsigned a_data; /* size of initialized data */ | |
28 | unsigned a_bss; /* size of uninitialized data */ | |
29 | unsigned a_syms; /* size of symbol table */ | |
30 | unsigned a_entry; /* entry point */ | |
31 | unsigned a_trsize; /* size of text relocation */ | |
32 | unsigned a_drsize; /* size of data relocation */ | |
33 | }; | |
34 | ||
35 | #define OMAGIC 0407 /* old impure format */ | |
36 | #define NMAGIC 0410 /* read-only text */ | |
37 | #define ZMAGIC 0413 /* demand load format */ | |
38 | ||
39 | /* | |
40 | * Macros which take exec structures as arguments and tell whether | |
41 | * the file has a reasonable magic number or offsets to text|symbols|strings. | |
42 | */ | |
43 | #define N_BADMAG(x) \ | |
44 | (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC) | |
45 | ||
46 | #define N_TXTOFF(x) \ | |
47 | ((x).a_magic==ZMAGIC ? 1024 : sizeof (struct exec)) | |
48 | #define N_SYMOFF(x) \ | |
49 | (N_TXTOFF(x) + (x).a_text+(x).a_data + (x).a_trsize+(x).a_drsize) | |
50 | #define N_STROFF(x) \ | |
51 | (N_SYMOFF(x) + (x).a_syms) | |
52 | ||
53 | The file has five sections: a header, the program text and | |
54 | data, relocation information, a symbol table and a string | |
55 | table (in that order). The last three may be omitted if the | |
56 | program was loaded with the `-s' option of _\bl_\bd or if the sym- | |
57 | bols and relocation have been removed by _\bs_\bt_\br_\bi_\bp(1). | |
58 | ||
59 | ||
60 | ||
61 | ||
62 | ||
63 | Printed 7/27/90 May 1 | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | ||
70 | A.OUT(5) 1986 A.OUT(5) | |
71 | ||
72 | ||
73 | ||
74 | In the header the sizes of each section are given in bytes. | |
75 | The size of the header is not included in any of the other | |
76 | sizes. | |
77 | ||
78 | When an _\ba._\bo_\bu_\bt file is executed, three logical segments are | |
79 | set up: the text segment, the data segment (with uninitial- | |
80 | ized data, which starts off as all 0, following initial- | |
81 | ized), and a stack. The text segment begins at 0 in the | |
82 | core image; the header is not loaded. If the magic number | |
83 | in the header is OMAGIC (0407), it indicates that the text | |
84 | segment is not to be write-protected and shared, so the data | |
85 | segment is immediately contiguous with the text segment. | |
86 | This is the oldest kind of executable program and is rarely | |
87 | used. If the magic number is NMAGIC (0410) or ZMAGIC | |
88 | (0413), the data segment begins at the first 0 mod 1024 byte | |
89 | boundary following the text segment, and the text segment is | |
90 | not writable by the program; if other processes are execut- | |
91 | ing the same file, they will share the text segment. For | |
92 | ZMAGIC format, the text segment begins at a 0 mod 1024 byte | |
93 | boundary in the _\ba._\bo_\bu_\bt file, the remaining bytes after the | |
94 | header in the first block are reserved and should be zero. | |
95 | In this case the text and data sizes must both be multiples | |
96 | of 1024 bytes, and the pages of the file will be brought | |
97 | into the running image as needed, and not pre-loaded as with | |
98 | the other formats. This is especially suitable for very | |
99 | large programs and is the default format produced by _\bl_\bd(1). | |
100 | ||
101 | The stack will occupy the highest possible locations in the | |
102 | core image, growing downwards from USRSTACK (from | |
103 | <_\bm_\ba_\bc_\bh_\bi_\bn_\be/_\bv_\bm_\bp_\ba_\br_\ba_\bm._\bh>). The stack is automatically extended | |
104 | as required. The data segment is only extended as requested | |
105 | by _\bb_\br_\bk(2). | |
106 | ||
107 | After the header in the file follow the text, data, text | |
108 | relocation data relocation, symbol table and string table in | |
109 | that order. The text begins at the byte 1024 in the file | |
110 | for ZMAGIC format or just after the header for the other | |
111 | formats. The N_TXTOFF macro returns this absolute file | |
112 | position when given the name of an exec structure as argu- | |
113 | ment. The data segment is contiguous with the text and | |
114 | immediately followed by the text relocation and then the | |
115 | data relocation information. The symbol table follows all | |
116 | this; its position is computed by the N_SYMOFF macro. | |
117 | Finally, the string table immediately follows the symbol | |
118 | table at a position which can be gotten easily using | |
119 | N_STROFF. The first 4 bytes of the string table are not | |
120 | used for string storage, but rather contain the size of the | |
121 | string table; this size INCLUDES the 4 bytes, the minimum | |
122 | string table size is thus 4. | |
123 | ||
124 | The layout of a symbol table entry and the principal flag | |
125 | values that distinguish symbol types are given in the | |
126 | ||
127 | ||
128 | ||
129 | Printed 7/27/90 May 2 | |
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | A.OUT(5) 1986 A.OUT(5) | |
137 | ||
138 | ||
139 | ||
140 | include file as follows: | |
141 | ||
142 | /* | |
143 | * Format of a symbol table entry. | |
144 | */ | |
145 | struct nlist { | |
146 | union { | |
147 | char *n_name; /* for use when in-core */ | |
148 | long n_strx; /* index into file string table */ | |
149 | } n_un; | |
150 | unsigned char n_type; /* type flag, i.e. N_TEXT etc; see below */ | |
151 | char n_other; | |
152 | short n_desc; /* see <stab.h> */ | |
153 | unsigned n_value; /* value of this symbol (or offset) */ | |
154 | }; | |
155 | #define n_hash n_desc /* used internally by ld */ | |
156 | ||
157 | /* | |
158 | * Simple values for n_type. | |
159 | */ | |
160 | #define N_UNDF 0x0 /* undefined */ | |
161 | #define N_ABS 0x2 /* absolute */ | |
162 | #define N_TEXT 0x4 /* text */ | |
163 | #define N_DATA 0x6 /* data */ | |
164 | #define N_BSS 0x8 /* bss */ | |
165 | #define N_COMM 0x12 /* common (internal to ld) */ | |
166 | #define N_FN 0x1f /* file name symbol */ | |
167 | ||
168 | #define N_EXT 01 /* external bit, or'ed in */ | |
169 | #define N_TYPE 0x1e /* mask for all the type bits */ | |
170 | ||
171 | /* | |
172 | * Other permanent symbol table entries have some of the N_STAB bits set. | |
173 | * These are given in <stab.h> | |
174 | */ | |
175 | #define N_STAB 0xe0 /* if any of these bits set, don't discard */ | |
176 | ||
177 | /* | |
178 | * Format for namelist values. | |
179 | */ | |
180 | #define N_FORMAT "%08x" | |
181 | ||
182 | In the _\ba._\bo_\bu_\bt file a symbol's n_un.n_strx field gives an | |
183 | index into the string table. A n_strx value of 0 indicates | |
184 | that no name is associated with a particular symbol table | |
185 | entry. The field n_un.n_name can be used to refer to the | |
186 | symbol name only if the program sets this up using n_strx | |
187 | and appropriate data from the string table. | |
188 | ||
189 | If a symbol's type is undefined external, and the value | |
190 | field is non-zero, the symbol is interpreted by the loader | |
191 | _\bl_\bd as the name of a common region whose size is indicated by | |
192 | ||
193 | ||
194 | ||
195 | Printed 7/27/90 May 3 | |
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
201 | ||
202 | A.OUT(5) 1986 A.OUT(5) | |
203 | ||
204 | ||
205 | ||
206 | the value of the symbol. | |
207 | ||
208 | The value of a byte in the text or data which is not a por- | |
209 | tion of a reference to an undefined external symbol is | |
210 | exactly that value which will appear in memory when the file | |
211 | is executed. If a byte in the text or data involves a | |
212 | reference to an undefined external symbol, as indicated by | |
213 | the relocation information, then the value stored in the | |
214 | file is an offset from the associated external symbol. When | |
215 | the file is processed by the link editor and the external | |
216 | symbol becomes defined, the value of the symbol will be | |
217 | added to the bytes in the file. | |
218 | ||
219 | If relocation information is present, it amounts to eight | |
220 | bytes per relocatable datum as in the following structure: | |
221 | ||
222 | /* | |
223 | * Format of a relocation datum. | |
224 | */ | |
225 | struct relocation_info { | |
226 | int r_address; /* address which is relocated */ | |
227 | unsigned r_symbolnum:24, /* local symbol ordinal */ | |
228 | r_pcrel:1, /* was relocated pc relative already */ | |
229 | r_length:2, /* 0=byte, 1=word, 2=long */ | |
230 | r_extern:1, /* does not include value of sym referenced */ | |
231 | :4; /* nothing, yet */ | |
232 | }; | |
233 | ||
234 | There is no relocation information if a_trsize+a_drsize==0. | |
235 | If r_extern is 0, then r_symbolnum is actually a n_type for | |
236 | the relocation (i.e. N_TEXT meaning relative to segment text | |
237 | origin.) | |
238 | ||
239 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO | |
240 | adb(1), as(1), ld(1), nm(1), dbx(1), stab(5), strip(1) | |
241 | ||
242 | B\bBU\bUG\bGS\bS | |
243 | Not having the size of the string table in the header is a | |
244 | loss, but expanding the header size would have meant | |
245 | stripped executable file incompatibility, and we couldn't | |
246 | hack this just now. | |
247 | ||
248 | ||
249 | ||
250 | ||
251 | ||
252 | ||
253 | ||
254 | ||
255 | ||
256 | ||
257 | ||
258 | ||
259 | ||
260 | ||
261 | Printed 7/27/90 May 4 | |
262 | ||
263 | ||
264 |