1 /* `a.out' object-file definitions, including extensions to 64-bit fields */
6 /* This is the layout on disk of the 32-bit or 64-bit exec header. */
10 bfd_byte e_info
[4]; /* magic number and stuff */
11 bfd_byte e_text
[BYTES_IN_WORD
]; /* length of text section in bytes */
12 bfd_byte e_data
[BYTES_IN_WORD
]; /* length of data section in bytes */
13 bfd_byte e_bss
[BYTES_IN_WORD
]; /* length of bss area in bytes */
14 bfd_byte e_syms
[BYTES_IN_WORD
]; /* length of symbol table in bytes */
15 bfd_byte e_entry
[BYTES_IN_WORD
]; /* start address */
16 bfd_byte e_trsize
[BYTES_IN_WORD
]; /* length of text relocation info */
17 bfd_byte e_drsize
[BYTES_IN_WORD
]; /* length of data relocation info */
20 #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7)
22 /* Magic numbers for a.out files */
25 #define OMAGIC 0x1001 /* Code indicating object file */
26 #define ZMAGIC 0x1002 /* Code indicating demand-paged executable. */
27 #define NMAGIC 0x1003 /* Code indicating pure executable. */
29 #define OMAGIC 0407 /* ...object file or impure executable. */
30 #define NMAGIC 0410 /* Code indicating pure executable. */
31 #define ZMAGIC 0413 /* Code indicating demand-paged executable. */
34 #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \
35 && N_MAGIC(x) != NMAGIC \
36 && N_MAGIC(x) != ZMAGIC)
38 /* By default, segment size is constant. But some machines override this
39 to be a function of the a.out header (e.g. machine type). */
41 #define N_SEGSIZE(x) SEGMENT_SIZE
44 /* Virtual memory address of the text section.
45 This is getting very complicated. A good reason to discard a.out format
46 for something that specifies these fields explicitly. But til then...
48 * OMAGIC and NMAGIC files:
49 (object files: text for "relocatable addr 0" right after the header)
50 start at 0, offset is EXEC_BYTES_SIZE, size as stated.
51 * The text address, offset, and size of ZMAGIC files depend
52 on the entry point of the file:
53 * entry point below TEXT_START_ADDR:
54 (hack for SunOS shared libraries)
55 start at 0, offset is 0, size as stated.
56 * If N_HEADER_IN_TEXT(x) is true (which defaults to being the
57 case when the entry point is EXEC_BYTES_SIZE or further into a page):
58 no padding is needed; text can start after exec header. Sun
59 considers the text segment of such files to include the exec header;
60 for BFD's purposes, we don't, which makes more work for us.
61 start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE,
62 size as stated minus EXEC_BYTES_SIZE.
63 * If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when
64 the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page
65 aligned)): (padding is needed so that text can start at a page boundary)
66 start at TEXT_START_ADDR, offset PAGE_SIZE, size as stated.
68 Specific configurations may want to hardwire N_HEADER_IN_TEXT,
69 for efficiency or to allow people to play games with the entry point.
70 In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos,
71 and as 0 for most other hosts (Sony News, Vax Ultrix, etc).
72 (Do this in the appropriate bfd target file.)
73 (The default is a heuristic that will break if people try changing
74 the entry point, perhaps with the ld -e flag.)
77 #ifndef N_HEADER_IN_TEXT
78 #define N_HEADER_IN_TEXT(x) (((x).a_entry & (PAGE_SIZE-1)) >= EXEC_BYTES_SIZE)
82 #define N_TXTADDR(x) \
83 ( (N_MAGIC(x) != ZMAGIC)? \
84 0: /* object file or NMAGIC */\
85 ((x).a_entry < TEXT_START_ADDR)? \
87 (N_HEADER_IN_TEXT(x) ? \
88 TEXT_START_ADDR + EXEC_BYTES_SIZE: /* no padding */\
89 TEXT_START_ADDR /* a page of padding */\
94 /* Offset in an a.out of the start of the text section. */
97 ( (N_MAGIC(x) != ZMAGIC)? \
98 EXEC_BYTES_SIZE: /* object file or NMAGIC */\
99 ((x).a_entry < TEXT_START_ADDR)? \
101 (N_HEADER_IN_TEXT(x) ? \
102 EXEC_BYTES_SIZE: /* no padding */\
103 PAGE_SIZE /* a page of padding */\
107 /* Size of the text section. It's always as stated, except that we
108 offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF
109 for NMAGIC/ZMAGIC files that nominally include the exec header
110 as part of the first page of text. (BFD doesn't consider the
111 exec header to be part of the text segment.) */
113 #define N_TXTSIZE(x) \
114 ( (N_MAGIC(x) != ZMAGIC)? \
115 (x).a_text: /* object file or NMAGIC */\
116 ((x).a_entry < TEXT_START_ADDR)? \
117 (x).a_text: /* shared lib */\
118 (N_HEADER_IN_TEXT(x) ? \
119 (x).a_text - EXEC_BYTES_SIZE: /* no padding */\
120 (x).a_text /* a page of padding */\
124 /* The address of the data segment in virtual memory.
125 It is the text segment address, plus text segment size, rounded
126 up to a N_SEGSIZE boundary for pure or pageable files. */
128 #define N_DATADDR(x) \
129 (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+N_TXTSIZE(x)) \
130 : (N_SEGSIZE(x) + ((N_TXTADDR(x)+N_TXTSIZE(x)-1) & ~(N_SEGSIZE(x)-1))))
132 /* The address of the BSS segment -- immediately after the data segment. */
134 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
136 /* Offsets of the various portions of the file after the text segment. */
138 #define N_DATOFF(x) ( N_TXTOFF(x) + N_TXTSIZE(x) )
139 #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data )
140 #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize )
141 #define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize )
142 #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms )
145 struct external_nlist
{
146 bfd_byte e_strx
[BYTES_IN_WORD
]; /* index into string table of name */
147 bfd_byte e_type
[1]; /* type of symbol */
148 bfd_byte e_other
[1]; /* misc info (usually empty) */
149 bfd_byte e_desc
[2]; /* description field */
150 bfd_byte e_value
[BYTES_IN_WORD
]; /* value of symbol */
153 #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
155 struct internal_nlist
{
156 unsigned long n_strx
; /* index into string table of name */
157 unsigned char n_type
; /* type of symbol */
158 unsigned char n_other
; /* misc info (usually empty) */
159 unsigned short n_desc
; /* description field */
160 bfd_vma n_value
; /* value of symbol */
163 /* The n_type field is the symbol type, containing: */
165 #define N_UNDF 0 /* Undefined symbol */
166 #define N_ABS 2 /* Absolute symbol -- defined at particular addr */
167 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
168 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
169 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
170 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
171 #define N_FN 0x1f /* File name of .o file */
172 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
173 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
174 N_DATA, or N_BSS. When the low-order bit of other types is set,
175 (e.g. N_WARNING versus N_FN), they are two different types. */
176 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
178 #define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol */
182 /* The following symbols refer to set elements.
183 All the N_SET[ATDB] symbols with the same name form one set.
184 Space is allocated for the set in the text section, and each set
185 elements value is stored into one word of the space.
186 The first word of the space is the length of the set (number of elements).
188 The address of the set is made into an N_SETV symbol
189 whose name is the same as the name of the set.
190 This symbol acts like a N_DATA global symbol
191 in that it can satisfy undefined external references. */
193 /* These appear as input to LD, in a .o file. */
194 #define N_SETA 0x14 /* Absolute set element symbol */
195 #define N_SETT 0x16 /* Text set element symbol */
196 #define N_SETD 0x18 /* Data set element symbol */
197 #define N_SETB 0x1A /* Bss set element symbol */
199 /* This is output from LD. */
200 #define N_SETV 0x1C /* Pointer to set vector in data area. */
202 /* Warning symbol. The text gives a warning message, the next symbol
203 in the table will be undefined. When the symbol is referenced, the
204 message is printed. */
206 #define N_WARNING 0x1e
210 There are two types of relocation flavours for a.out systems,
211 standard and extended. The standard form is used on systems where the
212 instruction has room for all the bits of an offset to the operand, whilst
213 the extended form is used when an address operand has to be split over n
214 instructions. Eg, on the 68k, each move instruction can reference
215 the target with a displacement of 16 or 32 bits. On the sparc, move
216 instructions use an offset of 14 bits, so the offset is stored in
217 the reloc field, and the data in the section is ignored.
220 /* This structure describes a single relocation to be performed.
221 The text-relocation section of the file is a vector of these structures,
222 all of which apply to the text section.
223 Likewise, the data-relocation section applies to the data section. */
225 struct reloc_std_external
{
226 bfd_byte r_address
[BYTES_IN_WORD
]; /* offset of of data to relocate */
227 bfd_byte r_index
[3]; /* symbol table index of symbol */
228 bfd_byte r_type
[1]; /* relocation type */
231 #define RELOC_STD_BITS_PCREL_BIG 0x80
232 #define RELOC_STD_BITS_PCREL_LITTLE 0x01
234 #define RELOC_STD_BITS_LENGTH_BIG 0x60
235 #define RELOC_STD_BITS_LENGTH_SH_BIG 5 /* To shift to units place */
236 #define RELOC_STD_BITS_LENGTH_LITTLE 0x06
237 #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1
239 #define RELOC_STD_BITS_EXTERN_BIG 0x10
240 #define RELOC_STD_BITS_EXTERN_LITTLE 0x08
242 #define RELOC_STD_BITS_BASEREL_BIG 0x08
243 #define RELOC_STD_BITS_BASEREL_LITTLE 0x08
245 #define RELOC_STD_BITS_JMPTABLE_BIG 0x04
246 #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04
248 #define RELOC_STD_BITS_RELATIVE_BIG 0x02
249 #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02
251 #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */
253 struct reloc_std_internal
255 bfd_vma r_address
; /* Address (within segment) to be relocated. */
256 /* The meaning of r_symbolnum depends on r_extern. */
257 unsigned int r_symbolnum
:24;
258 /* Nonzero means value is a pc-relative offset
259 and it should be relocated for changes in its own address
260 as well as for changes in the symbol or section specified. */
261 unsigned int r_pcrel
:1;
262 /* Length (as exponent of 2) of the field to be relocated.
263 Thus, a value of 2 indicates 1<<2 bytes. */
264 unsigned int r_length
:2;
265 /* 1 => relocate with value of symbol.
266 r_symbolnum is the index of the symbol
267 in files the symbol table.
268 0 => relocate with the address of a segment.
269 r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
270 (the N_EXT bit may be set also, but signifies nothing). */
271 unsigned int r_extern
:1;
272 /* The next three bits are for SunOS shared libraries, and seem to
274 unsigned int r_baserel
:1; /* Linkage table relative */
275 unsigned int r_jmptable
:1; /* pc-relative to jump table */
276 unsigned int r_relative
:1; /* "relative relocation" */
278 unsigned int r_pad
:1; /* Padding -- set to zero */
282 /* EXTENDED RELOCS */
284 struct reloc_ext_external
{
285 bfd_byte r_address
[BYTES_IN_WORD
]; /* offset of of data to relocate */
286 bfd_byte r_index
[3]; /* symbol table index of symbol */
287 bfd_byte r_type
[1]; /* relocation type */
288 bfd_byte r_addend
[BYTES_IN_WORD
]; /* datum addend */
291 #define RELOC_EXT_BITS_EXTERN_BIG 0x80
292 #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01
294 #define RELOC_EXT_BITS_TYPE_BIG 0x1F
295 #define RELOC_EXT_BITS_TYPE_SH_BIG 0
296 #define RELOC_EXT_BITS_TYPE_LITTLE 0xF8
297 #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3
299 /* Bytes per relocation entry */
300 #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
304 /* simple relocations */
305 RELOC_8
, /* data[0:7] = addend + sv */
306 RELOC_16
, /* data[0:15] = addend + sv */
307 RELOC_32
, /* data[0:31] = addend + sv */
308 /* pc-rel displacement */
309 RELOC_DISP8
, /* data[0:7] = addend - pc + sv */
310 RELOC_DISP16
, /* data[0:15] = addend - pc + sv */
311 RELOC_DISP32
, /* data[0:31] = addend - pc + sv */
313 RELOC_WDISP30
, /* data[0:29] = (addend + sv - pc)>>2 */
314 RELOC_WDISP22
, /* data[0:21] = (addend + sv - pc)>>2 */
315 RELOC_HI22
, /* data[0:21] = (addend + sv)>>10 */
316 RELOC_22
, /* data[0:21] = (addend + sv) */
317 RELOC_13
, /* data[0:12] = (addend + sv) */
318 RELOC_LO10
, /* data[0:9] = (addend + sv) */
321 /* P.I.C. (base-relative) */
322 RELOC_BASE10
, /* Not sure - maybe we can do this the */
323 RELOC_BASE13
, /* right way now */
325 /* for some sort of pc-rel P.I.C. (?) */
328 /* P.I.C. jump table */
330 /* reputedly for shared libraries somehow */
339 RELOC_HHI22
, /* data[0:21] = (addend + sv) >> 42 */
340 RELOC_HLO10
, /* data[0:9] = (addend + sv) >> 32 */
342 /* 29K relocation types */
347 /* All the new ones I can think of *//*v9*/
349 RELOC_64
, /* data[0:63] = addend + sv *//*v9*/
350 RELOC_DISP64
, /* data[0:63] = addend - pc + sv *//*v9*/
351 RELOC_WDISP21
, /* data[0:20] = (addend + sv - pc)>>2 *//*v9*/
352 RELOC_DISP21
, /* data[0:20] = addend - pc + sv *//*v9*/
353 RELOC_DISP14
, /* data[0:13] = addend - pc + sv *//*v9*/
355 What are the other ones,
356 Since this is a clean slate, can we throw away the ones we dont
357 understand ? Should we sort the values ? What about using a
358 microcode format like the 68k ?
364 struct reloc_internal
{
365 bfd_vma r_address
; /* offset of of data to relocate */
366 long r_index
; /* symbol table index of symbol */
367 enum reloc_type r_type
; /* relocation type */
368 bfd_vma r_addend
; /* datum addend */
372 Should the length of the string table be 4 bytes or 8 bytes ?
375 What about archive indexes ?
379 #endif /* __A_OUT_64_H__ */
This page took 0.038274 seconds and 4 git commands to generate.