BSD 4_4 release
[unix-history] / usr / src / contrib / sun.sharedlib / man / man5 / a.out.5
CommitLineData
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
35a.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
46Sun-2, Sun-3, and Sun-4 systems only.
47For 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
55is the output format of the assembler
56.BR as (1)
57and the link editor
58.BR ld (1).
59The link editor makes
60.B a.out
61executable files.
62.LP
63A file in
64.B a.out
65format consists of: a header, the program text, program data, text
66and data relocation information, a symbol table,
67and a string table (in that order).
68In the header, the sizes of each section are given in bytes. The
69last three sections may be absent if the program was loaded with
70the
71.B \-s
72option of
73.B ld
74or if the symbols and relocation have been removed by
75.BR strip (1).
76.LP
77The machine type in the header indicates the type of hardware on
78which the object code can be executed. Sun-2 code runs on
79Sun-3 systems, but not vice versa. Program files predating release
803.0 are recognized by a machine type of
81.RB ` 0 '.
82Sun-4 code may not be run on Sun-2 or Sun-3, nor vice versa.
83.SS Header
84.LP
85The header consists of a
86.B exec
87structure. The
88.B exec
89structure has the form:
90.LP
91.RS
92.nf
93.ta 1i 2.0i 3.0i
94.ft B
95struct 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
113The members of the structure are:
114.TP 15
115.B a_dynamic
116.B 1
117if the
118.B a.out
119file is dynamically linked or is a shared object,
120.B 0
121otherwise.
122.TP
123.B a_toolversion
124The version number of the toolset
125.RB ( as ,
126.BR ld ,
127etc.) used to create the file.
128.TP
129.B a_machtype
130One of the following:
131.RS
132.TP 12
133.B 0
134pre-3.0 executable image
135.TP
136.SB M_68010
137executable image using only \s-1MC\s068010 instructions that can run
138on Sun-2 or Sun-3
139systems.
140.TP
141.SB M_68020
142executable image using \s-1MC\s068020 instructions that can run only
143on Sun-3
144systems.
145.TP
146.SB M_SPARC
147executable image using \s-1SPARC\s0 instructions that can run only
148on Sun-4
149systems.
150.RE
151.TP 15
152.B a_magic
153One of the following:
154.RS
155.TP 12
156.SB OMAGIC
157An text executable image which is not to be
158write-protected, so the data segment is immediately contiguous with the
159text segment.
160.TP
161.SB NMAGIC
162A write-protected text executable image.
163The data segment begins at the first segment boundary following
164the text segment, and the text segment is not writable by the program.
165When the image is started with
166.BR execve (2V),
167the entire text and data segments will be read into memory.
168.TP
169.SB ZMAGIC
170A page-aligned text executable image.
171the data segment begins at the first segment boundary following
172the text segment, and the text segment is not writable by the program.
173The text and data sizes are both multiples of the page size,
174and the pages of the file will be brought into the running image as needed,
175and not pre-loaded as with the other formats.
176This is the default format produced by
177.BR ld (1).
178.RE
179.IP
180The macro
181.SB N_BADMAG
182takes an
183.B exec
184structure as an argument; it evaluates to 1 if the
185.B a_magic
186field of that structure is invalid, and evaluates to 0 if it is valid.
187.TP 15
188.B a_text
189The size of the text segment, in bytes.
190.TP
191.B a_data
192The size of the initialized portion of the data segment, in bytes.
193.TP
194.B a_bss
195The size of the \*(lquninitialized\*(rq portion of the data segment, in bytes.
196This portion is actually initialized to zero. The zeroes are not stored in the
197.B a.out
198file; the data in this portion of the data segment is zeroed out when it is
199loaded.
200.TP
201.B a_syms
202The size of the symbol table, in bytes.
203.TP
204.B a_entry
205The virtual address of the entry point of the program; when the image is
206started with
207.BR execve ,
208the first instruction executed in the image is at this address.
209.TP
210.B a_trsize
211The size of the relocation information for the text segment.
212.TP
213.B a_drsize
214The size of the relocation information for the data segment.
215.LP
216The macros
217.SM
218.BR N_TXTADDR ,
219.SM
220.BR N_DATADDR ,
221and
222.SB N_BSSADDR
223give the memory addresses at which the text, data, and bss segments,
224respectively, will be loaded.
225.LP
226In the
227.SB ZMAGIC
228format, the size of the header is included in the size of the text
229section; in other formats, it is not.
230.LP
231When an
232.B a.out
233file is executed, three logical segments are set up: the text segment,
234the data segment (with uninitialized data, which starts off as all 0,
235following initialized data), and a stack. For the
236.SB ZMAGIC
237format, the header is loaded with the text segment; for other
238formats it is not.
239.LP
240Program execution begins at the address given by the value of
241the
242.B a_entry
243field.
244.LP
245The stack starts at the highest possible location in the memory image,
246and grows downwards. The stack is automatically extended as required.
247The data segment is extended as requested by
248.BR brk (2)
249or
250.BR sbrk .
251.SS "Text and Data Segments"
252.LP
253The text segment begins at the start
254of the file for
255.SB ZMAGIC
256format, or just after the header for the other formats. The
257.SB N_TXTOFF
258macro returns this absolute file position when given an
259.B exec
260structure as argument. The data segment is contiguous with the
261text and immediately followed by the text relocation and then the data
262relocation information. The
263.SB N_DATOFF
264macro returns the absolute file position of the beginning of the data segment
265when given an
266.B exec
267structure as argument.
268.SS Relocation
269.LP
270The relocation information appears after the text and data segments.
271The
272.SB N_TRELOFF
273macro returns the absolute file position of the relocation information
274for the text segment, when given an
275.B exec
276structure as argument.
277The
278.SB N_DRELOFF
279macro returns the absolute file position of the relocation information
280for the data segment, when given an
281.B exec
282structure as argument.
283There is no relocation information if
284.BR a_trsize + a_drsize ==0.
285.SS "Relocation (Sun-2 and Sun-3 Systems)"
286If a byte in the text
287or data involves a reference to an undefined external symbol, as
288indicated by the relocation information, then the value stored in the
289file is an offset from the associated external symbol. When the file
290is processed by the link editor and the external symbol becomes
291defined, the value of the symbol is added to the bytes in the file.
292If a byte involves a reference to a relative location, or
293relocatable segment, then the value stored in the file is an
294offset from the associated segment.
295.br
296.ne 12
297.LP
298If relocation information is present, it amounts to eight bytes per
299relocatable datum as in the following structure:
300.LP
301.RS
302.nf
303.ft B
304.ta +4n; +8n; +8n; +10n
305struct reloc_info_68k {
306 long r_address; /* address which is relocated */
307unsigned 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
320If
321.B r_extern
322is 0, then
323.B r_symbolnum
324is actually an
325.B n_type
326for the relocation (for instance,
327.SB N_TEXT
328meaning relative to segment text origin.)
329.SS "Relocation (Sun-4 System)"
330.LP
331If a byte in the text
332or data involves a reference to an undefined external symbol, as
333indicated by the relocation information, then the value stored in the
334file is ignored. Unlike the Sun-2 and Sun-3 system, the offset from the
335associated symbol is kept with the relocation record. When the file
336is processed by the link editor and the external symbol becomes
337defined, the value of the symbol is added to this offset, and the
338sum is inserted into the bytes in the text or data segment.
339.LP
340If relocation information is present, it amounts to twelve bytes per
341relocatable datum as in the following structure:
342.LP
343.nf
344.ft B
345.ta 4n; +22n; +22n; +22n; +8n; +8n
346enum 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
363struct 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
375If
376.B r_extern
377is 0, then
378.B r_index
379is actually a
380.B n_type
381for the relocation (for instance,
382.SB N_TEXT
383meaning relative to segment text origin.)
384.SS Symbol Table
385.LP
386The
387.SB N_SYMOFF
388macro returns the absolute file position of the symbol table when given an
389.B exec
390structure as argument.
391Within this symbol table, distinct symbols point to disjoint
392areas in the string table (even when two symbols have the same name).
393The string table immediately follows the symbol table; the
394.SB N_STROFF
395macro returns the absolute file position of the string table when given an
396.B exec
397structure as argument.
398The first 4 bytes of the string table are not used for string storage,
399but rather contain the size of the string table. This size
400.I includes
401the 4 bytes; thus, the minimum string table size is 4.
402Layout information as given in the include file for the Sun system is
403shown below.
404.LP
405The layout of a symbol table entry and the principal flag values
406that distinguish symbol types are given in the include file as follows:
407.LP
408.nf
409.ft B
410.ta 6; +6; +4; +10
411struct 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
443In the
444.B a.out
445file a symbol's
446.B n_un.n_strx
447field gives an index into the string
448table. A
449.B n_strx
450value of 0 indicates that no name is associated with a
451particular symbol table entry. The field
452.B n_un.n_name
453can be used to
454refer to the symbol name only if the program sets this up using
455.B n_strx
456and appropriate data from the string table. Because of the union in
457the
458.B nlist
459declaration, it is impossible in C to statically initialize
460such a structure. If this must be done (as when using
461.BR nlist (3V))
462include the file
463.BR <nlist.h> ,
464rather than
465.BR <a.out.h> .
466This contains the declaration without the union.
467.LP
468If a symbol's type is undefined external, and the value field is
469non-zero, the symbol is interpreted by the loader
470.B ld
471as the name of a common region whose size
472is 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)