]>
Commit | Line | Data |
---|---|---|
2d8ffde4 JG |
1 | /* `a.out' object-file definitions, including extensions to 64-bit fields */ |
2 | ||
a3bb31a0 SC |
3 | #ifndef __A_OUT_64_H__ |
4 | #define __A_OUT_64_H__ | |
5 | ||
2d8ffde4 | 6 | /* This is the layout on disk of the 32-bit or 64-bit exec header. */ |
a3bb31a0 SC |
7 | |
8 | struct external_exec | |
9 | { | |
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 */ | |
18 | }; | |
19 | ||
a3bb31a0 SC |
20 | #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7) |
21 | ||
c6fec0bf | 22 | /* Magic numbers for a.out files */ |
22ef104a | 23 | |
a3bb31a0 | 24 | #if ARCH_SIZE==64 |
a3bb31a0 SC |
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. */ | |
28 | #else | |
c6fec0bf | 29 | #define OMAGIC 0407 /* ...object file or impure executable. */ |
a3bb31a0 SC |
30 | #define NMAGIC 0410 /* Code indicating pure executable. */ |
31 | #define ZMAGIC 0413 /* Code indicating demand-paged executable. */ | |
32 | #endif | |
33 | ||
34 | #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ | |
35 | && N_MAGIC(x) != NMAGIC \ | |
36 | && N_MAGIC(x) != ZMAGIC) | |
37 | ||
c6fec0bf JG |
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). */ | |
40 | #ifndef N_SEGSIZE | |
41 | #define N_SEGSIZE(x) SEGMENT_SIZE | |
42 | #endif | |
43 | \f | |
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... | |
47 | ||
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. | |
27612c29 PB |
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 | |
c6fec0bf | 59 | considers the text segment of such files to include the exec header; |
27612c29 | 60 | for BFD's purposes, we don't, which makes more work for us. |
c6fec0bf JG |
61 | start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE, |
62 | size as stated minus EXEC_BYTES_SIZE. | |
27612c29 PB |
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. | |
67 | ||
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.) | |
75 | */ | |
76 | ||
77 | #ifndef N_HEADER_IN_TEXT | |
78 | #define N_HEADER_IN_TEXT(x) (((x).a_entry & (PAGE_SIZE-1)) >= EXEC_BYTES_SIZE) | |
79 | #endif | |
a3bb31a0 | 80 | |
c6fec0bf JG |
81 | #ifndef N_TXTADDR |
82 | #define N_TXTADDR(x) \ | |
83 | ( (N_MAGIC(x) != ZMAGIC)? \ | |
84 | 0: /* object file or NMAGIC */\ | |
85 | ((x).a_entry < TEXT_START_ADDR)? \ | |
86 | 0: /* shared lib */\ | |
27612c29 | 87 | (N_HEADER_IN_TEXT(x) ? \ |
c6fec0bf JG |
88 | TEXT_START_ADDR + EXEC_BYTES_SIZE: /* no padding */\ |
89 | TEXT_START_ADDR /* a page of padding */\ | |
90 | ) \ | |
91 | ) | |
92 | #endif | |
93 | ||
94 | /* Offset in an a.out of the start of the text section. */ | |
95 | ||
96 | #define N_TXTOFF(x) \ | |
97 | ( (N_MAGIC(x) != ZMAGIC)? \ | |
98 | EXEC_BYTES_SIZE: /* object file or NMAGIC */\ | |
99 | ((x).a_entry < TEXT_START_ADDR)? \ | |
100 | 0: /* shared lib */\ | |
27612c29 | 101 | (N_HEADER_IN_TEXT(x) ? \ |
c6fec0bf JG |
102 | EXEC_BYTES_SIZE: /* no padding */\ |
103 | PAGE_SIZE /* a page of padding */\ | |
104 | ) \ | |
105 | ) | |
106 | ||
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.) */ | |
112 | ||
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 */\ | |
27612c29 | 118 | (N_HEADER_IN_TEXT(x) ? \ |
c6fec0bf JG |
119 | (x).a_text - EXEC_BYTES_SIZE: /* no padding */\ |
120 | (x).a_text /* a page of padding */\ | |
121 | ) \ | |
122 | ) | |
123 | ||
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. */ | |
a3bb31a0 SC |
127 | |
128 | #define N_DATADDR(x) \ | |
c6fec0bf JG |
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)))) | |
a3bb31a0 | 131 | |
c6fec0bf | 132 | /* The address of the BSS segment -- immediately after the data segment. */ |
a3bb31a0 | 133 | |
c6fec0bf | 134 | #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data) |
a3bb31a0 | 135 | |
c6fec0bf JG |
136 | /* Offsets of the various portions of the file after the text segment. */ |
137 | ||
138 | #define N_DATOFF(x) ( N_TXTOFF(x) + N_TXTSIZE(x) ) | |
a3bb31a0 SC |
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 ) | |
c6fec0bf | 143 | \f |
a3bb31a0 SC |
144 | /* Symbols */ |
145 | struct external_nlist { | |
2d8ffde4 JG |
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 */ | |
a3bb31a0 SC |
151 | }; |
152 | ||
2d8ffde4 JG |
153 | #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD) |
154 | ||
a3bb31a0 | 155 | struct internal_nlist { |
2d8ffde4 JG |
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 */ | |
a3bb31a0 SC |
161 | }; |
162 | ||
2d8ffde4 | 163 | /* The n_type field is the symbol type, containing: */ |
a3bb31a0 | 164 | |
2d8ffde4 JG |
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 */ | |
e557edcf | 170 | #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */ |
30c52cdf | 171 | #define N_FN 0x1f /* File name of .o file */ |
1c067821 | 172 | #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */ |
2d8ffde4 | 173 | /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT, |
30c52cdf JG |
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. */ | |
2d8ffde4 | 176 | #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */ |
a3bb31a0 | 177 | #define N_TYPE 0x1e |
2d8ffde4 | 178 | #define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol */ |
a3bb31a0 | 179 | |
9bbfd057 SC |
180 | #define N_INDR 0x0a |
181 | ||
a3bb31a0 SC |
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). | |
187 | ||
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. */ | |
192 | ||
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 */ | |
198 | ||
199 | /* This is output from LD. */ | |
200 | #define N_SETV 0x1C /* Pointer to set vector in data area. */ | |
201 | ||
e557edcf JG |
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. */ | |
205 | ||
206 | #define N_WARNING 0x1e | |
a3bb31a0 SC |
207 | |
208 | /* Relocations | |
209 | ||
210 | There are two types of relocation flavours for a.out systems, | |
2d8ffde4 JG |
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 | |
a3bb31a0 SC |
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. | |
218 | */ | |
219 | ||
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. */ | |
224 | ||
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 */ | |
229 | }; | |
230 | ||
231 | #define RELOC_STD_BITS_PCREL_BIG 0x80 | |
232 | #define RELOC_STD_BITS_PCREL_LITTLE 0x01 | |
233 | ||
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 | |
238 | ||
239 | #define RELOC_STD_BITS_EXTERN_BIG 0x10 | |
240 | #define RELOC_STD_BITS_EXTERN_LITTLE 0x08 | |
241 | ||
242 | #define RELOC_STD_BITS_BASEREL_BIG 0x08 | |
243 | #define RELOC_STD_BITS_BASEREL_LITTLE 0x08 | |
244 | ||
245 | #define RELOC_STD_BITS_JMPTABLE_BIG 0x04 | |
246 | #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04 | |
247 | ||
248 | #define RELOC_STD_BITS_RELATIVE_BIG 0x02 | |
249 | #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02 | |
250 | ||
251 | #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */ | |
252 | ||
253 | struct reloc_std_internal | |
254 | { | |
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 | |
273 | be undocumented. */ | |
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" */ | |
277 | /* unused */ | |
278 | unsigned int r_pad:1; /* Padding -- set to zero */ | |
279 | }; | |
280 | ||
281 | ||
282 | /* EXTENDED RELOCS */ | |
283 | ||
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 */ | |
289 | }; | |
290 | ||
291 | #define RELOC_EXT_BITS_EXTERN_BIG 0x80 | |
292 | #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01 | |
293 | ||
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 | |
298 | ||
2d8ffde4 JG |
299 | /* Bytes per relocation entry */ |
300 | #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD) | |
a3bb31a0 SC |
301 | |
302 | enum reloc_type | |
303 | { | |
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 */ | |
312 | /* Special */ | |
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) */ | |
319 | RELOC_SFA_BASE, | |
320 | RELOC_SFA_OFF13, | |
321 | /* P.I.C. (base-relative) */ | |
322 | RELOC_BASE10, /* Not sure - maybe we can do this the */ | |
323 | RELOC_BASE13, /* right way now */ | |
324 | RELOC_BASE22, | |
325 | /* for some sort of pc-rel P.I.C. (?) */ | |
326 | RELOC_PC10, | |
327 | RELOC_PC22, | |
328 | /* P.I.C. jump table */ | |
329 | RELOC_JMP_TBL, | |
330 | /* reputedly for shared libraries somehow */ | |
331 | RELOC_SEGOFF16, | |
332 | RELOC_GLOB_DAT, | |
333 | RELOC_JMP_SLOT, | |
334 | RELOC_RELATIVE, | |
fcc654cb SC |
335 | |
336 | RELOC_11, | |
337 | RELOC_WDISP2_14, | |
338 | RELOC_WDISP19, | |
339 | RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */ | |
340 | RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */ | |
341 | ||
a3bb31a0 SC |
342 | /* 29K relocation types */ |
343 | RELOC_JUMPTARG, | |
344 | RELOC_CONST, | |
345 | RELOC_CONSTH, | |
346 | ||
bdedf53f | 347 | /* All the new ones I can think of *//*v9*/ |
a3bb31a0 | 348 | |
bdedf53f SC |
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*/ | |
a3bb31a0 SC |
354 | /* Q . |
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 ? | |
359 | */ | |
360 | NO_RELOC | |
361 | }; | |
362 | ||
363 | ||
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 */ | |
369 | }; | |
370 | ||
371 | /* Q. | |
372 | Should the length of the string table be 4 bytes or 8 bytes ? | |
373 | ||
374 | Q. | |
375 | What about archive indexes ? | |
376 | ||
377 | */ | |
378 | ||
2d8ffde4 | 379 | #endif /* __A_OUT_64_H__ */ |