Commit | Line | Data |
---|---|---|
ad787160 C |
1 | .\" This source code is a product of Sun Microsystems, Inc. and is provided |
2 | .\" for unrestricted use provided that this legend is included on all tape | |
3 | .\" media and as a part of the software program in whole or part. Users | |
4 | .\" may copy or modify this source code without charge, but are not authorized | |
5 | .\" to license or distribute it to anyone else except as part of a product or | |
6 | .\" program developed by the user. | |
7 | .\" | |
8 | .\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC. | |
9 | .\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY | |
10 | .\" OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT | |
11 | .\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS | |
12 | .\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED | |
13 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN | |
14 | .\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT, | |
15 | .\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING | |
16 | .\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY. | |
17 | .\" | |
18 | .\" This source code is provided with no support and without any obligation on | |
19 | .\" the part of Sun Microsystems, Inc. to assist in its use, correction, | |
20 | .\" modification or enhancement. | |
21 | .\" | |
22 | .\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
23 | .\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS | |
24 | .\" SOURCE CODE OR ANY PART THEREOF. | |
25 | .\" | |
26 | .\" Sun Microsystems, Inc. | |
27 | .\" 2550 Garcia Avenue | |
28 | .\" Mountain View, California 94043 | |
29 | .\" | |
30 | .\" Copyright (c) 1991 Sun Microsystems, Inc. | |
31 | .\" | |
32 | .\" @(#)a.out.5 1.32 90/01/30 SMI; from UCB 4.2 | |
33 | .TH A.OUT 5 "18 February 1988" | |
34 | .SH NAME | |
35 | a.out \- assembler and link editor output format | |
36 | .SH SYNOPSIS | |
37 | .nf | |
38 | .ft B | |
39 | #include <a.out.h> | |
40 | #include <stab.h> | |
41 | #include <nlist.h> | |
42 | .ft R | |
43 | .fi | |
44 | .SH AVAILABILITY | |
45 | .LP | |
46 | Sun-2, Sun-3, and Sun-4 systems only. | |
47 | For Sun386i systems refer to | |
48 | .BR coff (5). | |
49 | .SH DESCRIPTION | |
50 | .IX "a.out file" "" "\fLa.out\fP \(em assembler and link editor output" | |
51 | .IX "assembler output" "" "assembler output \(em \fLa.out\fP" | |
52 | .IX "link editor output" "" "link editor output \(em \fLa.out\fP" | |
53 | .LP | |
54 | .B a.out | |
55 | is the output format of the assembler | |
56 | .BR as (1) | |
57 | and the link editor | |
58 | .BR ld (1). | |
59 | The link editor makes | |
60 | .B a.out | |
61 | executable files. | |
62 | .LP | |
63 | A file in | |
64 | .B a.out | |
65 | format consists of: a header, the program text, program data, text | |
66 | and data relocation information, a symbol table, | |
67 | and a string table (in that order). | |
68 | In the header, the sizes of each section are given in bytes. The | |
69 | last three sections may be absent if the program was loaded with | |
70 | the | |
71 | .B \-s | |
72 | option of | |
73 | .B ld | |
74 | or if the symbols and relocation have been removed by | |
75 | .BR strip (1). | |
76 | .LP | |
77 | The machine type in the header indicates the type of hardware on | |
78 | which the object code can be executed. Sun-2 code runs on | |
79 | Sun-3 systems, but not vice versa. Program files predating release | |
80 | 3.0 are recognized by a machine type of | |
81 | .RB ` 0 '. | |
82 | Sun-4 code may not be run on Sun-2 or Sun-3, nor vice versa. | |
83 | .SS Header | |
84 | .LP | |
85 | The header consists of a | |
86 | .B exec | |
87 | structure. The | |
88 | .B exec | |
89 | structure has the form: | |
90 | .LP | |
91 | .RS | |
92 | .nf | |
93 | .ta 1i 2.0i 3.0i | |
94 | .ft B | |
95 | struct exec { | |
96 | unsigned char a_dynamic:1; /* has a __DYNAMIC */ | |
97 | unsigned char a_toolversion:7; /* version of toolset used to create this file */ | |
98 | unsigned char a_machtype; /* machine type */ | |
99 | unsigned short a_magic; /* magic number */ | |
100 | unsigned long a_text; /* size of text segment */ | |
101 | unsigned long a_data; /* size of initialized data */ | |
102 | unsigned long a_bss; /* size of uninitialized data */ | |
103 | unsigned long a_syms; /* size of symbol table */ | |
104 | unsigned long a_entry; /* entry point */ | |
105 | unsigned long a_trsize; /* size of text relocation */ | |
106 | unsigned long a_drsize; /* size of data relocation */ | |
107 | }; | |
108 | .ft R | |
109 | .fi | |
110 | .DT | |
111 | .RE | |
112 | .LP | |
113 | The members of the structure are: | |
114 | .TP 15 | |
115 | .B a_dynamic | |
116 | .B 1 | |
117 | if the | |
118 | .B a.out | |
119 | file is dynamically linked or is a shared object, | |
120 | .B 0 | |
121 | otherwise. | |
122 | .TP | |
123 | .B a_toolversion | |
124 | The version number of the toolset | |
125 | .RB ( as , | |
126 | .BR ld , | |
127 | etc.) used to create the file. | |
128 | .TP | |
129 | .B a_machtype | |
130 | One of the following: | |
131 | .RS | |
132 | .TP 12 | |
133 | .B 0 | |
134 | pre-3.0 executable image | |
135 | .TP | |
136 | .SB M_68010 | |
137 | executable image using only \s-1MC\s068010 instructions that can run | |
138 | on Sun-2 or Sun-3 | |
139 | systems. | |
140 | .TP | |
141 | .SB M_68020 | |
142 | executable image using \s-1MC\s068020 instructions that can run only | |
143 | on Sun-3 | |
144 | systems. | |
145 | .TP | |
146 | .SB M_SPARC | |
147 | executable image using \s-1SPARC\s0 instructions that can run only | |
148 | on Sun-4 | |
149 | systems. | |
150 | .RE | |
151 | .TP 15 | |
152 | .B a_magic | |
153 | One of the following: | |
154 | .RS | |
155 | .TP 12 | |
156 | .SB OMAGIC | |
157 | An text executable image which is not to be | |
158 | write-protected, so the data segment is immediately contiguous with the | |
159 | text segment. | |
160 | .TP | |
161 | .SB NMAGIC | |
162 | A write-protected text executable image. | |
163 | The data segment begins at the first segment boundary following | |
164 | the text segment, and the text segment is not writable by the program. | |
165 | When the image is started with | |
166 | .BR execve (2V), | |
167 | the entire text and data segments will be read into memory. | |
168 | .TP | |
169 | .SB ZMAGIC | |
170 | A page-aligned text executable image. | |
171 | the data segment begins at the first segment boundary following | |
172 | the text segment, and the text segment is not writable by the program. | |
173 | The text and data sizes are both multiples of the page size, | |
174 | and the pages of the file will be brought into the running image as needed, | |
175 | and not pre-loaded as with the other formats. | |
176 | This is the default format produced by | |
177 | .BR ld (1). | |
178 | .RE | |
179 | .IP | |
180 | The macro | |
181 | .SB N_BADMAG | |
182 | takes an | |
183 | .B exec | |
184 | structure as an argument; it evaluates to 1 if the | |
185 | .B a_magic | |
186 | field of that structure is invalid, and evaluates to 0 if it is valid. | |
187 | .TP 15 | |
188 | .B a_text | |
189 | The size of the text segment, in bytes. | |
190 | .TP | |
191 | .B a_data | |
192 | The size of the initialized portion of the data segment, in bytes. | |
193 | .TP | |
194 | .B a_bss | |
195 | The size of the \*(lquninitialized\*(rq portion of the data segment, in bytes. | |
196 | This portion is actually initialized to zero. The zeroes are not stored in the | |
197 | .B a.out | |
198 | file; the data in this portion of the data segment is zeroed out when it is | |
199 | loaded. | |
200 | .TP | |
201 | .B a_syms | |
202 | The size of the symbol table, in bytes. | |
203 | .TP | |
204 | .B a_entry | |
205 | The virtual address of the entry point of the program; when the image is | |
206 | started with | |
207 | .BR execve , | |
208 | the first instruction executed in the image is at this address. | |
209 | .TP | |
210 | .B a_trsize | |
211 | The size of the relocation information for the text segment. | |
212 | .TP | |
213 | .B a_drsize | |
214 | The size of the relocation information for the data segment. | |
215 | .LP | |
216 | The macros | |
217 | .SM | |
218 | .BR N_TXTADDR , | |
219 | .SM | |
220 | .BR N_DATADDR , | |
221 | and | |
222 | .SB N_BSSADDR | |
223 | give the memory addresses at which the text, data, and bss segments, | |
224 | respectively, will be loaded. | |
225 | .LP | |
226 | In the | |
227 | .SB ZMAGIC | |
228 | format, the size of the header is included in the size of the text | |
229 | section; in other formats, it is not. | |
230 | .LP | |
231 | When an | |
232 | .B a.out | |
233 | file is executed, three logical segments are set up: the text segment, | |
234 | the data segment (with uninitialized data, which starts off as all 0, | |
235 | following initialized data), and a stack. For the | |
236 | .SB ZMAGIC | |
237 | format, the header is loaded with the text segment; for other | |
238 | formats it is not. | |
239 | .LP | |
240 | Program execution begins at the address given by the value of | |
241 | the | |
242 | .B a_entry | |
243 | field. | |
244 | .LP | |
245 | The stack starts at the highest possible location in the memory image, | |
246 | and grows downwards. The stack is automatically extended as required. | |
247 | The data segment is extended as requested by | |
248 | .BR brk (2) | |
249 | or | |
250 | .BR sbrk . | |
251 | .SS "Text and Data Segments" | |
252 | .LP | |
253 | The text segment begins at the start | |
254 | of the file for | |
255 | .SB ZMAGIC | |
256 | format, or just after the header for the other formats. The | |
257 | .SB N_TXTOFF | |
258 | macro returns this absolute file position when given an | |
259 | .B exec | |
260 | structure as argument. The data segment is contiguous with the | |
261 | text and immediately followed by the text relocation and then the data | |
262 | relocation information. The | |
263 | .SB N_DATOFF | |
264 | macro returns the absolute file position of the beginning of the data segment | |
265 | when given an | |
266 | .B exec | |
267 | structure as argument. | |
268 | .SS Relocation | |
269 | .LP | |
270 | The relocation information appears after the text and data segments. | |
271 | The | |
272 | .SB N_TRELOFF | |
273 | macro returns the absolute file position of the relocation information | |
274 | for the text segment, when given an | |
275 | .B exec | |
276 | structure as argument. | |
277 | The | |
278 | .SB N_DRELOFF | |
279 | macro returns the absolute file position of the relocation information | |
280 | for the data segment, when given an | |
281 | .B exec | |
282 | structure as argument. | |
283 | There is no relocation information if | |
284 | .BR a_trsize + a_drsize ==0. | |
285 | .SS "Relocation (Sun-2 and Sun-3 Systems)" | |
286 | If a byte in the text | |
287 | or data involves a reference to an undefined external symbol, as | |
288 | indicated by the relocation information, then the value stored in the | |
289 | file is an offset from the associated external symbol. When the file | |
290 | is processed by the link editor and the external symbol becomes | |
291 | defined, the value of the symbol is added to the bytes in the file. | |
292 | If a byte involves a reference to a relative location, or | |
293 | relocatable segment, then the value stored in the file is an | |
294 | offset from the associated segment. | |
295 | .br | |
296 | .ne 12 | |
297 | .LP | |
298 | If relocation information is present, it amounts to eight bytes per | |
299 | relocatable datum as in the following structure: | |
300 | .LP | |
301 | .RS | |
302 | .nf | |
303 | .ft B | |
304 | .ta +4n; +8n; +8n; +10n | |
305 | struct reloc_info_68k { | |
306 | long r_address; /* address which is relocated */ | |
307 | unsigned int r_symbolnum:24, /* local symbol ordinal */ | |
308 | r_pcrel:1, /* was relocated pc relative already */ | |
309 | r_length:2, /* 0=byte, 1=word, 2=long */ | |
310 | r_extern:1, /* does not include value of sym referenced */ | |
311 | r_baserel:1, /* linkage table relative */ | |
312 | r_jmptable:1, /* pc-relative to jump table */ | |
313 | r_relative:1, /* relative relocation */ | |
314 | :1; | |
315 | }; | |
316 | ||
317 | .fi | |
318 | .RE | |
319 | .LP | |
320 | If | |
321 | .B r_extern | |
322 | is 0, then | |
323 | .B r_symbolnum | |
324 | is actually an | |
325 | .B n_type | |
326 | for the relocation (for instance, | |
327 | .SB N_TEXT | |
328 | meaning relative to segment text origin.) | |
329 | .SS "Relocation (Sun-4 System)" | |
330 | .LP | |
331 | If a byte in the text | |
332 | or data involves a reference to an undefined external symbol, as | |
333 | indicated by the relocation information, then the value stored in the | |
334 | file is ignored. Unlike the Sun-2 and Sun-3 system, the offset from the | |
335 | associated symbol is kept with the relocation record. When the file | |
336 | is processed by the link editor and the external symbol becomes | |
337 | defined, the value of the symbol is added to this offset, and the | |
338 | sum is inserted into the bytes in the text or data segment. | |
339 | .LP | |
340 | If relocation information is present, it amounts to twelve bytes per | |
341 | relocatable datum as in the following structure: | |
342 | .LP | |
343 | .nf | |
344 | .ft B | |
345 | .ta 4n; +22n; +22n; +22n; +8n; +8n | |
346 | enum reloc_type | |
347 | { | |
348 | \s-1RELOC_8\s0, \s-1RELOC_16\s0, \s-1RELOC_32\s0, /* simplest relocs */ | |
349 | \s-1RELOC_DISP8\s0, \s-1RELOC_DISP16\s0, \s-1RELOC_DISP32\s0, /* Disp's (pc-rel) */ | |
350 | \s-1RELOC_WDISP30\s0, \s-1RELOC_WDISP22\s0, /* \s-1SR\s0 word disp's */ | |
351 | \s-1RELOC_HI22\s0, \s-1RELOC_22\s0, /* \s-1SR\s0 22-bit relocs */ | |
352 | \s-1RELOC_13\s0, \s-1RELOC_LO10\s0, /* \s-1SR\s0 13&10-bit relocs */ | |
353 | \s-1RELOC_SFA_BASE\s0, \s-1RELOC_SFA_OFF13\s0, /* \s-1SR S.F.A.\s0 relocs */ | |
354 | \s-1RELOC_BASE10\s0, \s-1RELOC_BASE13\s0, \s-1RELOC_BASE22\s0, /* base_relative pic */ | |
355 | \s-1RELOC_PC10\s0, \s-1RELOC_PC22\s0, /* special pc-rel pic*/ | |
356 | \s-1RELOC_JMP_TBL\s0, /* jmp_tbl_rel in pic */ | |
357 | \s-1RELOC_SEGOFF16\s0, /* ShLib offset-in-seg */ | |
358 | \s-1RELOC_GLOB_DAT\s0, \s-1RELOC_JMP_SLOT\s0, \s-1RELOC_RELATIVE\s0, /* rtld relocs */ | |
359 | }; | |
360 | .sp .5 | |
361 | .ne 9 | |
362 | .ta 4n; +18n; +10n; +10n | |
363 | struct reloc_info_sparc /* used when header.a_machtype == M_SPARC */ | |
364 | { | |
365 | unsigned long int r_address; /* relocation addr (offset in segment) */ | |
366 | unsigned int r_index :24; /* segment index or symbol index */ | |
367 | unsigned int r_extern :\01; /* if F, r_index==SEG#; if T, SYM idx */ | |
368 | int :\02; /* <unused> */ | |
369 | enum reloc_type r_type :\05; /* type of relocation to perform */ | |
370 | long int r_addend; /* addend for relocation value */ | |
371 | }; | |
372 | .fi | |
373 | .ft | |
374 | .LP | |
375 | If | |
376 | .B r_extern | |
377 | is 0, then | |
378 | .B r_index | |
379 | is actually a | |
380 | .B n_type | |
381 | for the relocation (for instance, | |
382 | .SB N_TEXT | |
383 | meaning relative to segment text origin.) | |
384 | .SS Symbol Table | |
385 | .LP | |
386 | The | |
387 | .SB N_SYMOFF | |
388 | macro returns the absolute file position of the symbol table when given an | |
389 | .B exec | |
390 | structure as argument. | |
391 | Within this symbol table, distinct symbols point to disjoint | |
392 | areas in the string table (even when two symbols have the same name). | |
393 | The string table immediately follows the symbol table; the | |
394 | .SB N_STROFF | |
395 | macro returns the absolute file position of the string table when given an | |
396 | .B exec | |
397 | structure as argument. | |
398 | The first 4 bytes of the string table are not used for string storage, | |
399 | but rather contain the size of the string table. This size | |
400 | .I includes | |
401 | the 4 bytes; thus, the minimum string table size is 4. | |
402 | Layout information as given in the include file for the Sun system is | |
403 | shown below. | |
404 | .LP | |
405 | The layout of a symbol table entry and the principal flag values | |
406 | that distinguish symbol types are given in the include file as follows: | |
407 | .LP | |
408 | .nf | |
409 | .ft B | |
410 | .ta 6; +6; +4; +10 | |
411 | struct nlist { | |
412 | union { | |
413 | char *n_name; /* for use when in-memory */ | |
414 | long n_strx; /* index into file string table */ | |
415 | } n_un; | |
416 | unsigned char n_type; /* type flag, that is, \s-1N_TEXT\s0 etc; see below */ | |
417 | char n_other; | |
418 | short n_desc; /* see <stab.h> */ | |
419 | unsigned n_value; /* value of this symbol (or adb offset) */ | |
420 | }; | |
421 | #define n_hash n_desc /* used internally by ld */ | |
422 | /* | |
423 | * Simple values for n_type. | |
424 | */ | |
425 | #define \s-1N_UNDF\s0 0x0 /* undefined */ | |
426 | #define \s-1N_ABS\s0 0x2 /* absolute */ | |
427 | #define \s-1N_TEXT\s0 0x4 /* text */ | |
428 | #define \s-1N_DATA\s0 0x6 /* data */ | |
429 | #define \s-1N_BSS\s0 0x8 /* bss */ | |
430 | #define \s-1N_COMM\s0 0x12 /* common (internal to ld) */ | |
431 | #define \s-1N_FN\s0 0x1f /* file name symbol */ | |
432 | #define \s-1N_EXT\s0 01 /* external bit, or'ed in */ | |
433 | #define \s-1N_TYPE\s0 0x1e /* mask for all the type bits */ | |
434 | .sp .5v | |
435 | /* | |
436 | * Other permanent symbol table entries have some of the \s-1N_STAB\s0 bits set. | |
437 | * These are given in <stab.h> | |
438 | */ | |
439 | #define \s-1N_STAB\s0 0xe0 /* if any of these bits set, don't discard */ | |
440 | .ft | |
441 | .fi | |
442 | .LP | |
443 | In the | |
444 | .B a.out | |
445 | file a symbol's | |
446 | .B n_un.n_strx | |
447 | field gives an index into the string | |
448 | table. A | |
449 | .B n_strx | |
450 | value of 0 indicates that no name is associated with a | |
451 | particular symbol table entry. The field | |
452 | .B n_un.n_name | |
453 | can be used to | |
454 | refer to the symbol name only if the program sets this up using | |
455 | .B n_strx | |
456 | and appropriate data from the string table. Because of the union in | |
457 | the | |
458 | .B nlist | |
459 | declaration, it is impossible in C to statically initialize | |
460 | such a structure. If this must be done (as when using | |
461 | .BR nlist (3V)) | |
462 | include the file | |
463 | .BR <nlist.h> , | |
464 | rather than | |
465 | .BR <a.out.h> . | |
466 | This contains the declaration without the union. | |
467 | .LP | |
468 | If a symbol's type is undefined external, and the value field is | |
469 | non-zero, the symbol is interpreted by the loader | |
470 | .B ld | |
471 | as the name of a common region whose size | |
472 | is indicated by the value of the symbol. | |
473 | .SH "SEE ALSO" | |
474 | .BR adb (1), | |
475 | .BR as (1), | |
476 | .BR cc (1V), | |
477 | .BR dbx (1), | |
478 | .BR ld (1), | |
479 | .BR nm (1), | |
480 | .BR strip (1), | |
481 | .BR brk (2), | |
482 | .BR nlist (3V), | |
483 | .BR coff (5) |