Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end data structures for a.out (and similar) files. |
b3adc24a | 2 | Copyright (C) 1990-2020 Free Software Foundation, Inc. |
252b5132 RH |
3 | Written by Cygnus Support. |
4 | ||
e6af3a53 | 5 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 6 | |
e6af3a53 NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 9 | the Free Software Foundation; either version 3 of the License, or |
e6af3a53 | 10 | (at your option) any later version. |
252b5132 | 11 | |
e6af3a53 NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
252b5132 | 16 | |
e6af3a53 NC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
252b5132 RH |
21 | |
22 | #ifndef LIBAOUT_H | |
23 | #define LIBAOUT_H | |
24 | ||
25 | /* We try to encapsulate the differences in the various a.out file | |
26 | variants in a few routines, and otherwise share large masses of code. | |
27 | This means we only have to fix bugs in one place, most of the time. */ | |
28 | ||
29 | #include "bfdlink.h" | |
30 | ||
edeb6e24 | 31 | /* Macros for accessing components in an aout header. */ |
dc810e39 | 32 | |
7920ce38 NC |
33 | #define H_PUT_64 bfd_h_put_64 |
34 | #define H_PUT_32 bfd_h_put_32 | |
35 | #define H_PUT_16 bfd_h_put_16 | |
36 | #define H_PUT_8 bfd_h_put_8 | |
edeb6e24 AM |
37 | #define H_PUT_S64 bfd_h_put_signed_64 |
38 | #define H_PUT_S32 bfd_h_put_signed_32 | |
39 | #define H_PUT_S16 bfd_h_put_signed_16 | |
7920ce38 NC |
40 | #define H_PUT_S8 bfd_h_put_signed_8 |
41 | #define H_GET_64 bfd_h_get_64 | |
42 | #define H_GET_32 bfd_h_get_32 | |
43 | #define H_GET_16 bfd_h_get_16 | |
44 | #define H_GET_8 bfd_h_get_8 | |
edeb6e24 AM |
45 | #define H_GET_S64 bfd_h_get_signed_64 |
46 | #define H_GET_S32 bfd_h_get_signed_32 | |
47 | #define H_GET_S16 bfd_h_get_signed_16 | |
7920ce38 | 48 | #define H_GET_S8 bfd_h_get_signed_8 |
dc810e39 | 49 | |
252b5132 RH |
50 | /* Parameterize the a.out code based on whether it is being built |
51 | for a 32-bit architecture or a 64-bit architecture. */ | |
e43d48cc AM |
52 | /* Do not "beautify" the CONCAT* macro args. Traditional C will not |
53 | remove whitespace added here, and thus will fail to concatenate | |
54 | the tokens. */ | |
252b5132 | 55 | #if ARCH_SIZE==64 |
7920ce38 | 56 | #define GET_WORD H_GET_64 |
dc810e39 AM |
57 | #define GET_SWORD H_GET_S64 |
58 | #define GET_MAGIC H_GET_32 | |
7920ce38 | 59 | #define PUT_WORD H_PUT_64 |
dc810e39 | 60 | #define PUT_MAGIC H_PUT_32 |
252b5132 | 61 | #ifndef NAME |
e43d48cc | 62 | #define NAME(x,y) CONCAT3 (x,_64_,y) |
252b5132 | 63 | #endif |
e43d48cc | 64 | #define JNAME(x) CONCAT2 (x,_64) |
252b5132 | 65 | #define BYTES_IN_WORD 8 |
e135f41b NC |
66 | #else |
67 | #if ARCH_SIZE==16 | |
7920ce38 | 68 | #define GET_WORD H_GET_16 |
dc810e39 AM |
69 | #define GET_SWORD H_GET_S16 |
70 | #define GET_MAGIC H_GET_16 | |
7920ce38 | 71 | #define PUT_WORD H_PUT_16 |
dc810e39 | 72 | #define PUT_MAGIC H_PUT_16 |
e135f41b | 73 | #ifndef NAME |
e43d48cc | 74 | #define NAME(x,y) CONCAT3 (x,_16_,y) |
e135f41b | 75 | #endif |
e43d48cc | 76 | #define JNAME(x) CONCAT2 (x,_16) |
e135f41b | 77 | #define BYTES_IN_WORD 2 |
252b5132 | 78 | #else /* ARCH_SIZE == 32 */ |
7920ce38 | 79 | #define GET_WORD H_GET_32 |
dc810e39 AM |
80 | #define GET_SWORD H_GET_S32 |
81 | #define GET_MAGIC H_GET_32 | |
7920ce38 | 82 | #define PUT_WORD H_PUT_32 |
dc810e39 | 83 | #define PUT_MAGIC H_PUT_32 |
252b5132 | 84 | #ifndef NAME |
e43d48cc | 85 | #define NAME(x,y) CONCAT3 (x,_32_,y) |
252b5132 | 86 | #endif |
e43d48cc | 87 | #define JNAME(x) CONCAT2 (x,_32) |
252b5132 RH |
88 | #define BYTES_IN_WORD 4 |
89 | #endif /* ARCH_SIZE==32 */ | |
e135f41b | 90 | #endif /* ARCH_SIZE==64 */ |
252b5132 RH |
91 | |
92 | /* Declare at file level, since used in parameter lists, which have | |
93 | weird scope. */ | |
94 | struct external_exec; | |
95 | struct external_nlist; | |
96 | struct reloc_ext_external; | |
97 | struct reloc_std_external; | |
98 | \f | |
99 | /* a.out backend linker hash table entries. */ | |
100 | ||
101 | struct aout_link_hash_entry | |
102 | { | |
103 | struct bfd_link_hash_entry root; | |
104 | /* Whether this symbol has been written out. */ | |
b34976b6 | 105 | bfd_boolean written; |
252b5132 RH |
106 | /* Symbol index in output file. */ |
107 | int indx; | |
108 | }; | |
109 | ||
110 | /* a.out backend linker hash table. */ | |
111 | ||
112 | struct aout_link_hash_table | |
113 | { | |
114 | struct bfd_link_hash_table root; | |
115 | }; | |
116 | ||
117 | /* Look up an entry in an a.out link hash table. */ | |
118 | ||
119 | #define aout_link_hash_lookup(table, string, create, copy, follow) \ | |
120 | ((struct aout_link_hash_entry *) \ | |
121 | bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow))) | |
122 | ||
123 | /* Traverse an a.out link hash table. */ | |
124 | ||
125 | #define aout_link_hash_traverse(table, func, info) \ | |
126 | (bfd_link_hash_traverse \ | |
127 | (&(table)->root, \ | |
7920ce38 | 128 | (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
129 | (info))) |
130 | ||
131 | /* Get the a.out link hash table from the info structure. This is | |
132 | just a cast. */ | |
133 | ||
134 | #define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash)) | |
135 | \f | |
136 | /* Back-end information for various a.out targets. */ | |
137 | struct aout_backend_data | |
138 | { | |
139 | /* Are ZMAGIC files mapped contiguously? If so, the text section may | |
140 | need more padding, if the segment size (granularity for memory access | |
141 | control) is larger than the page size. */ | |
142 | unsigned char zmagic_mapped_contiguous; | |
143 | /* If this flag is set, ZMAGIC/NMAGIC file headers get mapped in with the | |
144 | text section, which starts immediately after the file header. | |
145 | If not, the text section starts on the next page. */ | |
146 | unsigned char text_includes_header; | |
147 | ||
148 | /* If this flag is set, then if the entry address is not in the | |
149 | first SEGMENT_SIZE bytes of the text section, it is taken to be | |
150 | the address of the start of the text section. This can be useful | |
151 | for kernels. */ | |
152 | unsigned char entry_is_text_address; | |
153 | ||
154 | /* The value to pass to N_SET_FLAGS. */ | |
155 | unsigned char exec_hdr_flags; | |
156 | ||
157 | /* If the text section VMA isn't specified, and we need an absolute | |
158 | address, use this as the default. If we're producing a relocatable | |
159 | file, zero is always used. */ | |
160 | /* ?? Perhaps a callback would be a better choice? Will this do anything | |
161 | reasonable for a format that handles multiple CPUs with different | |
162 | load addresses for each? */ | |
163 | bfd_vma default_text_vma; | |
164 | ||
165 | /* Callback for setting the page and segment sizes, if they can't be | |
166 | trivially determined from the architecture. */ | |
7920ce38 | 167 | bfd_boolean (*set_sizes) (bfd *); |
252b5132 RH |
168 | |
169 | /* zmagic files only. For go32, the length of the exec header contributes | |
170 | to the size of the text section in the file for alignment purposes but | |
171 | does *not* get counted in the length of the text section. */ | |
172 | unsigned char exec_header_not_counted; | |
173 | ||
174 | /* Callback from the add symbols phase of the linker code to handle | |
175 | a dynamic object. */ | |
b34976b6 | 176 | bfd_boolean (*add_dynamic_symbols) |
7920ce38 NC |
177 | (bfd *, struct bfd_link_info *, struct external_nlist **, |
178 | bfd_size_type *, char **); | |
252b5132 RH |
179 | |
180 | /* Callback from the add symbols phase of the linker code to handle | |
181 | adding a single symbol to the global linker hash table. */ | |
b34976b6 | 182 | bfd_boolean (*add_one_symbol) |
7920ce38 NC |
183 | (struct bfd_link_info *, bfd *, const char *, flagword, |
184 | asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, | |
185 | struct bfd_link_hash_entry **); | |
252b5132 RH |
186 | |
187 | /* Called to handle linking a dynamic object. */ | |
b34976b6 | 188 | bfd_boolean (*link_dynamic_object) |
7920ce38 | 189 | (struct bfd_link_info *, bfd *); |
252b5132 RH |
190 | |
191 | /* Called for each global symbol being written out by the linker. | |
192 | This should write out the dynamic symbol information. */ | |
b34976b6 | 193 | bfd_boolean (*write_dynamic_symbol) |
7920ce38 | 194 | (bfd *, struct bfd_link_info *, struct aout_link_hash_entry *); |
252b5132 RH |
195 | |
196 | /* If this callback is not NULL, the linker calls it for each reloc. | |
197 | RELOC is a pointer to the unswapped reloc. If *SKIP is set to | |
b34976b6 | 198 | TRUE, the reloc will be skipped. *RELOCATION may be changed to |
252b5132 | 199 | change the effects of the relocation. */ |
b34976b6 | 200 | bfd_boolean (*check_dynamic_reloc) |
7920ce38 NC |
201 | (struct bfd_link_info *info, bfd *input_bfd, |
202 | asection *input_section, struct aout_link_hash_entry *h, | |
203 | void * reloc, bfd_byte *contents, bfd_boolean *skip, | |
204 | bfd_vma *relocation); | |
252b5132 RH |
205 | |
206 | /* Called at the end of a link to finish up any dynamic linking | |
207 | information. */ | |
7920ce38 | 208 | bfd_boolean (*finish_dynamic_link) (bfd *, struct bfd_link_info *); |
252b5132 RH |
209 | }; |
210 | #define aout_backend_info(abfd) \ | |
dc810e39 | 211 | ((const struct aout_backend_data *)((abfd)->xvec->backend_data)) |
252b5132 RH |
212 | |
213 | /* This is the layout in memory of a "struct exec" while we process it. | |
214 | All 'lengths' are given as a number of bytes. | |
215 | All 'alignments' are for relinkable files only; an alignment of | |
216 | 'n' indicates the corresponding segment must begin at an | |
217 | address that is a multiple of (2**n). */ | |
218 | ||
219 | struct internal_exec | |
220 | { | |
aca305d9 NC |
221 | long a_info; /* Magic number and flags, packed. */ |
222 | bfd_vma a_text; /* Length of text, in bytes. */ | |
223 | bfd_vma a_data; /* Length of data, in bytes. */ | |
224 | bfd_vma a_bss; /* Length of uninitialized data area in mem. */ | |
225 | bfd_vma a_syms; /* Length of symbol table data in file. */ | |
226 | bfd_vma a_entry; /* Start address. */ | |
227 | bfd_vma a_trsize; /* Length of text's relocation info, in bytes. */ | |
228 | bfd_vma a_drsize; /* Length of data's relocation info, in bytes. */ | |
229 | /* Added for i960 */ | |
230 | bfd_vma a_tload; /* Text runtime load address. */ | |
231 | bfd_vma a_dload; /* Data runtime load address. */ | |
232 | unsigned char a_talign; /* Alignment of text segment. */ | |
233 | unsigned char a_dalign; /* Alignment of data segment. */ | |
234 | unsigned char a_balign; /* Alignment of bss segment. */ | |
07d6d2b8 | 235 | char a_relaxable; /* Enough info for linker relax. */ |
252b5132 RH |
236 | }; |
237 | ||
dc810e39 | 238 | /* Magic number is written |
07d6d2b8 | 239 | < MSB > |
aca305d9 | 240 | 3130292827262524232221201918171615141312111009080706050403020100 |
07d6d2b8 | 241 | < FLAGS >< MACHINE TYPE >< MAGIC NUMBER > */ |
aca305d9 | 242 | |
252b5132 | 243 | /* Magic number for NetBSD is |
07d6d2b8 | 244 | <MSB > |
aca305d9 | 245 | 3130292827262524232221201918171615141312111009080706050403020100 |
07d6d2b8 | 246 | < FLAGS >< MACHINE TYPE >< MAGIC NUMBER > */ |
252b5132 | 247 | |
aca305d9 NC |
248 | enum machine_type |
249 | { | |
252b5132 RH |
250 | M_UNKNOWN = 0, |
251 | M_68010 = 1, | |
252 | M_68020 = 2, | |
253 | M_SPARC = 3, | |
e6af3a53 NC |
254 | /* Skip a bunch so we don't run into any of SUN's numbers. */ |
255 | /* Make these up for the ns32k. */ | |
aca305d9 NC |
256 | M_NS32032 = (64), /* NS32032 running ? */ |
257 | M_NS32532 = (64 + 5), /* NS32532 running mach. */ | |
252b5132 | 258 | M_386 = 100, |
07d6d2b8 | 259 | M_29K = 101, /* AMD 29000. */ |
aca305d9 NC |
260 | M_386_DYNIX = 102, /* Sequent running dynix. */ |
261 | M_ARM = 103, /* Advanced Risc Machines ARM. */ | |
262 | M_SPARCLET = 131, /* SPARClet = M_SPARC + 128. */ | |
263 | M_386_NETBSD = 134, /* NetBSD/i386 binary. */ | |
264 | M_68K_NETBSD = 135, /* NetBSD/m68k binary. */ | |
265 | M_68K4K_NETBSD = 136, /* NetBSD/m68k4k binary. */ | |
266 | M_532_NETBSD = 137, /* NetBSD/ns32k binary. */ | |
267 | M_SPARC_NETBSD = 138, /* NetBSD/sparc binary. */ | |
268 | M_PMAX_NETBSD = 139, /* NetBSD/pmax (MIPS little-endian) binary. */ | |
269 | M_VAX_NETBSD = 140, /* NetBSD/vax binary. */ | |
270 | M_ALPHA_NETBSD = 141, /* NetBSD/alpha binary. */ | |
271 | M_ARM6_NETBSD = 143, /* NetBSD/arm32 binary. */ | |
272 | M_SPARCLET_1 = 147, /* 0x93, reserved. */ | |
7f919c84 | 273 | M_POWERPC_NETBSD = 149, /* NetBSD/powerpc (big-endian) binary. */ |
aca305d9 | 274 | M_VAX4K_NETBSD = 150, /* NetBSD/vax 4K pages binary. */ |
07d6d2b8 AM |
275 | M_MIPS1 = 151, /* MIPS R2000/R3000 binary. */ |
276 | M_MIPS2 = 152, /* MIPS R4000/R6000 binary. */ | |
8377c19c MK |
277 | M_88K_OPENBSD = 153, /* OpenBSD/m88k binary. */ |
278 | M_HPPA_OPENBSD = 154, /* OpenBSD/hppa binary. */ | |
aca305d9 NC |
279 | M_SPARC64_NETBSD = 156, /* NetBSD/sparc64 binary. */ |
280 | M_X86_64_NETBSD = 157, /* NetBSD/amd64 binary. */ | |
281 | M_SPARCLET_2 = 163, /* 0xa3, reserved. */ | |
282 | M_SPARCLET_3 = 179, /* 0xb3, reserved. */ | |
283 | M_SPARCLET_4 = 195, /* 0xc3, reserved. */ | |
284 | M_HP200 = 200, /* HP 200 (68010) BSD binary. */ | |
285 | M_HP300 = (300 % 256), /* HP 300 (68020+68881) BSD binary. */ | |
286 | M_HPUX = (0x20c % 256), /* HP 200/300 HPUX binary. */ | |
287 | M_SPARCLET_5 = 211, /* 0xd3, reserved. */ | |
288 | M_SPARCLET_6 = 227, /* 0xe3, reserved. */ | |
289 | /*M_SPARCLET_7 = 243 / * 0xf3, reserved. */ | |
06c15ad7 | 290 | M_SPARCLITE_LE = 243, |
aca305d9 | 291 | M_CRIS = 255 /* Axis CRIS binary. */ |
252b5132 RH |
292 | }; |
293 | ||
bbb1afc8 | 294 | #define N_DYNAMIC(execp) ((execp)->a_info & 0x80000000) |
252b5132 RH |
295 | |
296 | #ifndef N_MAGIC | |
bbb1afc8 | 297 | # define N_MAGIC(execp) ((execp)->a_info & 0xffff) |
252b5132 RH |
298 | #endif |
299 | ||
300 | #ifndef N_MACHTYPE | |
bbb1afc8 | 301 | # define N_MACHTYPE(execp) ((enum machine_type)(((execp)->a_info >> 16) & 0xff)) |
252b5132 RH |
302 | #endif |
303 | ||
304 | #ifndef N_FLAGS | |
bbb1afc8 | 305 | # define N_FLAGS(execp) (((execp)->a_info >> 24) & 0xff) |
252b5132 RH |
306 | #endif |
307 | ||
308 | #ifndef N_SET_INFO | |
bbb1afc8 AM |
309 | # define N_SET_INFO(execp, magic, type, flags) \ |
310 | ((execp)->a_info = ((magic) & 0xffff) \ | |
252b5132 | 311 | | (((int)(type) & 0xff) << 16) \ |
13c9c485 | 312 | | (((flags) & 0xffu) << 24)) |
252b5132 RH |
313 | #endif |
314 | ||
315 | #ifndef N_SET_DYNAMIC | |
bbb1afc8 AM |
316 | # define N_SET_DYNAMIC(execp, dynamic) \ |
317 | ((execp)->a_info = (dynamic) ? (long) ((execp)->a_info | 0x80000000) : \ | |
318 | ((execp)->a_info & 0x7fffffff)) | |
252b5132 RH |
319 | #endif |
320 | ||
321 | #ifndef N_SET_MAGIC | |
bbb1afc8 AM |
322 | # define N_SET_MAGIC(execp, magic) \ |
323 | ((execp)->a_info = (((execp)->a_info & 0xffff0000) | ((magic) & 0xffff))) | |
252b5132 RH |
324 | #endif |
325 | ||
326 | #ifndef N_SET_MACHTYPE | |
bbb1afc8 AM |
327 | # define N_SET_MACHTYPE(execp, machtype) \ |
328 | ((execp)->a_info = \ | |
329 | ((execp)->a_info & 0xff00ffff) | ((((int) (machtype)) &0xff) << 16)) | |
252b5132 RH |
330 | #endif |
331 | ||
332 | #ifndef N_SET_FLAGS | |
bbb1afc8 AM |
333 | # define N_SET_FLAGS(execp, flags) \ |
334 | ((execp)->a_info = \ | |
13c9c485 | 335 | ((execp)->a_info & 0x00ffffff) | (((flags) & 0xffu) << 24)) |
252b5132 RH |
336 | #endif |
337 | ||
aca305d9 NC |
338 | typedef struct aout_symbol |
339 | { | |
252b5132 RH |
340 | asymbol symbol; |
341 | short desc; | |
342 | char other; | |
343 | unsigned char type; | |
344 | } aout_symbol_type; | |
345 | ||
346 | /* The `tdata' struct for all a.out-like object file formats. | |
347 | Various things depend on this struct being around any time an a.out | |
348 | file is being handled. An example is dbxread.c in GDB. */ | |
349 | ||
a50b1753 NC |
350 | enum aout_subformat { |
351 | default_format = 0, | |
dc12032b | 352 | /* Used on HP 9000/300 running HP/UX. */ |
a50b1753 NC |
353 | gnu_encap_format, |
354 | /* Used on Linux, 386BSD, etc. See include/aout/aout64.h. */ | |
355 | q_magic_format | |
356 | }; | |
357 | ||
358 | enum aout_magic { | |
359 | undecided_magic = 0, | |
360 | z_magic, | |
361 | o_magic, | |
fa1477dc SC |
362 | n_magic, |
363 | i_magic | |
a50b1753 NC |
364 | }; |
365 | ||
aca305d9 NC |
366 | struct aoutdata |
367 | { | |
368 | struct internal_exec *hdr; /* Exec file header. */ | |
369 | aout_symbol_type *symbols; /* Symtab for input bfd. */ | |
dc810e39 | 370 | |
e6af3a53 | 371 | /* For ease, we do this. */ |
252b5132 RH |
372 | asection *textsec; |
373 | asection *datasec; | |
374 | asection *bsssec; | |
375 | ||
376 | /* We remember these offsets so that after check_file_format, we have | |
377 | no dependencies on the particular format of the exec_hdr. */ | |
378 | file_ptr sym_filepos; | |
379 | file_ptr str_filepos; | |
380 | ||
e6af3a53 | 381 | /* Size of a relocation entry in external form. */ |
252b5132 RH |
382 | unsigned reloc_entry_size; |
383 | ||
e6af3a53 | 384 | /* Size of a symbol table entry in external form. */ |
252b5132 RH |
385 | unsigned symbol_entry_size; |
386 | ||
e6af3a53 | 387 | /* Page size - needed for alignment of demand paged files. */ |
252b5132 RH |
388 | unsigned long page_size; |
389 | ||
e6af3a53 | 390 | /* Segment size - needed for alignment of demand paged files. */ |
252b5132 RH |
391 | unsigned long segment_size; |
392 | ||
393 | /* Zmagic disk block size - need to align the start of the text | |
394 | section in ZMAGIC binaries. Normally the same as page_size. */ | |
395 | unsigned long zmagic_disk_block_size; | |
396 | ||
397 | unsigned exec_bytes_size; | |
398 | unsigned vma_adjusted : 1; | |
399 | ||
e6af3a53 | 400 | /* Used when a bfd supports several highly similar formats. */ |
a50b1753 NC |
401 | enum aout_subformat subformat; |
402 | ||
403 | enum aout_magic magic; | |
252b5132 RH |
404 | |
405 | /* A buffer for find_nearest_line. */ | |
406 | char *line_buf; | |
407 | ||
408 | /* The external symbol information. */ | |
409 | struct external_nlist *external_syms; | |
410 | bfd_size_type external_sym_count; | |
411 | bfd_window sym_window; | |
412 | char *external_strings; | |
413 | bfd_size_type external_string_size; | |
414 | bfd_window string_window; | |
415 | struct aout_link_hash_entry **sym_hashes; | |
416 | ||
417 | /* A pointer for shared library information. */ | |
7920ce38 | 418 | void * dynamic_info; |
252b5132 RH |
419 | |
420 | /* A mapping from local symbols to offsets into the global offset | |
421 | table, used when linking on SunOS. This is indexed by the symbol | |
422 | index. */ | |
423 | bfd_vma *local_got_offsets; | |
424 | }; | |
425 | ||
aca305d9 NC |
426 | struct aout_data_struct |
427 | { | |
428 | struct aoutdata a; | |
429 | struct internal_exec e; | |
252b5132 RH |
430 | }; |
431 | ||
07d6d2b8 AM |
432 | #define adata(bfd) ((bfd)->tdata.aout_data->a) |
433 | #define exec_hdr(bfd) (adata (bfd).hdr) | |
434 | #define obj_aout_symbols(bfd) (adata (bfd).symbols) | |
435 | #define obj_textsec(bfd) (adata (bfd).textsec) | |
436 | #define obj_datasec(bfd) (adata (bfd).datasec) | |
437 | #define obj_bsssec(bfd) (adata (bfd).bsssec) | |
438 | #define obj_sym_filepos(bfd) (adata (bfd).sym_filepos) | |
439 | #define obj_str_filepos(bfd) (adata (bfd).str_filepos) | |
440 | #define obj_reloc_entry_size(bfd) (adata (bfd).reloc_entry_size) | |
441 | #define obj_symbol_entry_size(bfd) (adata (bfd).symbol_entry_size) | |
442 | #define obj_aout_subformat(bfd) (adata (bfd).subformat) | |
443 | #define obj_aout_external_syms(bfd) (adata (bfd).external_syms) | |
aca305d9 | 444 | #define obj_aout_external_sym_count(bfd) (adata (bfd).external_sym_count) |
07d6d2b8 AM |
445 | #define obj_aout_sym_window(bfd) (adata (bfd).sym_window) |
446 | #define obj_aout_external_strings(bfd) (adata (bfd).external_strings) | |
aca305d9 | 447 | #define obj_aout_external_string_size(bfd) (adata (bfd).external_string_size) |
07d6d2b8 AM |
448 | #define obj_aout_string_window(bfd) (adata (bfd).string_window) |
449 | #define obj_aout_sym_hashes(bfd) (adata (bfd).sym_hashes) | |
450 | #define obj_aout_dynamic_info(bfd) (adata (bfd).dynamic_info) | |
252b5132 RH |
451 | |
452 | /* We take the address of the first element of an asymbol to ensure that the | |
e6af3a53 | 453 | macro is only ever applied to an asymbol. */ |
252b5132 RH |
454 | #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd)) |
455 | ||
456 | /* Information we keep for each a.out section. This is currently only | |
457 | used by the a.out backend linker. */ | |
458 | ||
459 | struct aout_section_data_struct | |
460 | { | |
461 | /* The unswapped relocation entries for this section. */ | |
7920ce38 | 462 | void * relocs; |
252b5132 RH |
463 | }; |
464 | ||
465 | #define aout_section_data(s) \ | |
466 | ((struct aout_section_data_struct *) (s)->used_by_bfd) | |
467 | ||
468 | #define set_aout_section_data(s,v) \ | |
7920ce38 | 469 | ((s)->used_by_bfd = (void *)&(v)->relocs) |
252b5132 | 470 | |
e6af3a53 | 471 | /* Prototype declarations for functions defined in aoutx.h. */ |
252b5132 | 472 | |
7920ce38 NC |
473 | extern bfd_boolean NAME (aout, squirt_out_relocs) |
474 | (bfd *, asection *); | |
252b5132 | 475 | |
7920ce38 NC |
476 | extern bfd_boolean NAME (aout, make_sections) |
477 | (bfd *); | |
252b5132 | 478 | |
cb001c0d AM |
479 | extern bfd_cleanup NAME (aout, some_aout_object_p) |
480 | (bfd *, struct internal_exec *, bfd_cleanup (*) (bfd *)); | |
252b5132 | 481 | |
7920ce38 NC |
482 | extern bfd_boolean NAME (aout, mkobject) |
483 | (bfd *); | |
252b5132 | 484 | |
7920ce38 NC |
485 | extern enum machine_type NAME (aout, machine_type) |
486 | (enum bfd_architecture, unsigned long, bfd_boolean *); | |
252b5132 | 487 | |
7920ce38 NC |
488 | extern bfd_boolean NAME (aout, set_arch_mach) |
489 | (bfd *, enum bfd_architecture, unsigned long); | |
252b5132 | 490 | |
7920ce38 NC |
491 | extern bfd_boolean NAME (aout, new_section_hook) |
492 | (bfd *, asection *); | |
252b5132 | 493 | |
7920ce38 NC |
494 | extern bfd_boolean NAME (aout, set_section_contents) |
495 | (bfd *, sec_ptr, const void *, file_ptr, bfd_size_type); | |
252b5132 | 496 | |
7920ce38 NC |
497 | extern asymbol * NAME (aout, make_empty_symbol) |
498 | (bfd *); | |
252b5132 | 499 | |
7920ce38 NC |
500 | extern bfd_boolean NAME (aout, translate_symbol_table) |
501 | (bfd *, aout_symbol_type *, struct external_nlist *, bfd_size_type, | |
502 | char *, bfd_size_type, bfd_boolean); | |
252b5132 | 503 | |
7920ce38 NC |
504 | extern bfd_boolean NAME (aout, slurp_symbol_table) |
505 | (bfd *); | |
252b5132 | 506 | |
7920ce38 NC |
507 | extern bfd_boolean NAME (aout, write_syms) |
508 | (bfd *); | |
252b5132 | 509 | |
7920ce38 NC |
510 | extern void NAME (aout, reclaim_symbol_table) |
511 | (bfd *); | |
252b5132 | 512 | |
7920ce38 NC |
513 | extern long NAME (aout, get_symtab_upper_bound) |
514 | (bfd *); | |
252b5132 | 515 | |
7920ce38 NC |
516 | extern long NAME (aout, canonicalize_symtab) |
517 | (bfd *, asymbol **); | |
252b5132 | 518 | |
7920ce38 NC |
519 | extern void NAME (aout, swap_ext_reloc_in) |
520 | (bfd *, struct reloc_ext_external *, arelent *, asymbol **, | |
521 | bfd_size_type); | |
252b5132 | 522 | |
7920ce38 NC |
523 | extern void NAME (aout, swap_std_reloc_in) |
524 | (bfd *, struct reloc_std_external *, arelent *, asymbol **, | |
525 | bfd_size_type); | |
252b5132 | 526 | |
7920ce38 NC |
527 | extern reloc_howto_type * NAME (aout, reloc_type_lookup) |
528 | (bfd *, bfd_reloc_code_real_type); | |
252b5132 | 529 | |
157090f7 AM |
530 | extern reloc_howto_type * NAME (aout, reloc_name_lookup) |
531 | (bfd *, const char *); | |
532 | ||
7920ce38 NC |
533 | extern bfd_boolean NAME (aout, slurp_reloc_table) |
534 | (bfd *, sec_ptr, asymbol **); | |
252b5132 | 535 | |
7920ce38 NC |
536 | extern long NAME (aout, canonicalize_reloc) |
537 | (bfd *, sec_ptr, arelent **, asymbol **); | |
252b5132 | 538 | |
7920ce38 NC |
539 | extern long NAME (aout, get_reloc_upper_bound) |
540 | (bfd *, sec_ptr); | |
252b5132 | 541 | |
7920ce38 NC |
542 | extern void NAME (aout, reclaim_reloc) |
543 | (bfd *, sec_ptr); | |
252b5132 | 544 | |
7920ce38 NC |
545 | extern alent * NAME (aout, get_lineno) |
546 | (bfd *, asymbol *); | |
252b5132 | 547 | |
7920ce38 NC |
548 | extern void NAME (aout, print_symbol) |
549 | (bfd *, void *, asymbol *, bfd_print_symbol_type); | |
252b5132 | 550 | |
7920ce38 NC |
551 | extern void NAME (aout, get_symbol_info) |
552 | (bfd *, asymbol *, symbol_info *); | |
252b5132 | 553 | |
7920ce38 | 554 | extern bfd_boolean NAME (aout, find_nearest_line) |
fb167eb2 AM |
555 | (bfd *, asymbol **, asection *, bfd_vma, |
556 | const char **, const char **, unsigned int *, unsigned int *); | |
252b5132 | 557 | |
7920ce38 NC |
558 | extern long NAME (aout, read_minisymbols) |
559 | (bfd *, bfd_boolean, void * *, unsigned int *); | |
252b5132 | 560 | |
7920ce38 NC |
561 | extern asymbol * NAME (aout, minisymbol_to_symbol) |
562 | (bfd *, bfd_boolean, const void *, asymbol *); | |
252b5132 | 563 | |
7920ce38 | 564 | extern int NAME (aout, sizeof_headers) |
a6b96beb | 565 | (bfd *, struct bfd_link_info *); |
252b5132 | 566 | |
7920ce38 | 567 | extern bfd_boolean NAME (aout, adjust_sizes_and_vmas) |
3a8c4a5b | 568 | (bfd *); |
252b5132 | 569 | |
7920ce38 NC |
570 | extern void NAME (aout, swap_exec_header_in) |
571 | (bfd *, struct external_exec *, struct internal_exec *); | |
252b5132 | 572 | |
7920ce38 NC |
573 | extern void NAME (aout, swap_exec_header_out) |
574 | (bfd *, struct internal_exec *, struct external_exec *); | |
252b5132 | 575 | |
7920ce38 NC |
576 | extern struct bfd_hash_entry * NAME (aout, link_hash_newfunc) |
577 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); | |
252b5132 | 578 | |
7920ce38 NC |
579 | extern bfd_boolean NAME (aout, link_hash_table_init) |
580 | (struct aout_link_hash_table *, bfd *, | |
581 | struct bfd_hash_entry *(*) (struct bfd_hash_entry *, | |
582 | struct bfd_hash_table *, | |
66eb6687 AM |
583 | const char *), |
584 | unsigned int); | |
252b5132 | 585 | |
7920ce38 NC |
586 | extern struct bfd_link_hash_table * NAME (aout, link_hash_table_create) |
587 | (bfd *); | |
252b5132 | 588 | |
7920ce38 NC |
589 | extern bfd_boolean NAME (aout, link_add_symbols) |
590 | (bfd *, struct bfd_link_info *); | |
252b5132 | 591 | |
7920ce38 NC |
592 | extern bfd_boolean NAME (aout, final_link) |
593 | (bfd *, struct bfd_link_info *, | |
594 | void (*) (bfd *, file_ptr *, file_ptr *, file_ptr *)); | |
595 | ||
596 | extern bfd_boolean NAME (aout, bfd_free_cached_info) | |
597 | (bfd *); | |
252b5132 | 598 | |
4ab527b0 FF |
599 | #define aout_32_find_inliner_info _bfd_nosymbols_find_inliner_info |
600 | #if 0 /* Are these needed? */ | |
601 | #define aout_16_find_inliner_info _bfd_nosymbols_find_inliner_info | |
602 | #define aout_64_find_inliner_info _bfd_nosymbols_find_inliner_info | |
603 | #endif | |
604 | ||
e6af3a53 | 605 | /* A.out uses the generic versions of these routines... */ |
252b5132 | 606 | |
e135f41b NC |
607 | #define aout_16_get_section_contents _bfd_generic_get_section_contents |
608 | ||
252b5132 RH |
609 | #define aout_32_get_section_contents _bfd_generic_get_section_contents |
610 | ||
611 | #define aout_64_get_section_contents _bfd_generic_get_section_contents | |
252b5132 RH |
612 | |
613 | #ifndef aout_32_bfd_is_local_label_name | |
614 | #define aout_32_bfd_is_local_label_name bfd_generic_is_local_label_name | |
615 | #endif | |
616 | ||
3c9458e9 | 617 | #ifndef aout_32_bfd_is_target_special_symbol |
d00dd7dc | 618 | #define aout_32_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
3c9458e9 NC |
619 | #endif |
620 | ||
252b5132 RH |
621 | #ifndef WRITE_HEADERS |
622 | #define WRITE_HEADERS(abfd, execp) \ | |
623 | { \ | |
252b5132 | 624 | if (adata(abfd).magic == undecided_magic) \ |
3a8c4a5b | 625 | NAME (aout, adjust_sizes_and_vmas) (abfd); \ |
07d6d2b8 | 626 | \ |
252b5132 RH |
627 | execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \ |
628 | execp->a_entry = bfd_get_start_address (abfd); \ | |
07d6d2b8 | 629 | \ |
252b5132 RH |
630 | execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \ |
631 | obj_reloc_entry_size (abfd)); \ | |
632 | execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \ | |
633 | obj_reloc_entry_size (abfd)); \ | |
7920ce38 | 634 | NAME (aout, swap_exec_header_out) (abfd, execp, & exec_bytes); \ |
252b5132 | 635 | \ |
dc810e39 | 636 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 \ |
7920ce38 | 637 | || bfd_bwrite (& exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \ |
dc810e39 | 638 | abfd) != EXEC_BYTES_SIZE) \ |
b34976b6 | 639 | return FALSE; \ |
e6af3a53 | 640 | /* Now write out reloc info, followed by syms and strings. */ \ |
07d6d2b8 | 641 | \ |
7920ce38 | 642 | if (bfd_get_outsymbols (abfd) != NULL \ |
07d6d2b8 | 643 | && bfd_get_symcount (abfd) != 0) \ |
252b5132 | 644 | { \ |
bbb1afc8 | 645 | if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (execp)), SEEK_SET) != 0)\ |
b34976b6 | 646 | return FALSE; \ |
252b5132 | 647 | \ |
7920ce38 | 648 | if (! NAME (aout, write_syms) (abfd)) \ |
b34976b6 | 649 | return FALSE; \ |
252b5132 RH |
650 | } \ |
651 | \ | |
bbb1afc8 | 652 | if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (execp)), SEEK_SET) != 0) \ |
07d6d2b8 AM |
653 | return FALSE; \ |
654 | if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd))) \ | |
655 | return FALSE; \ | |
252b5132 | 656 | \ |
bbb1afc8 | 657 | if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (execp)), SEEK_SET) != 0) \ |
07d6d2b8 AM |
658 | return FALSE; \ |
659 | if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd))) \ | |
660 | return FALSE; \ | |
dc810e39 | 661 | } |
252b5132 RH |
662 | #endif |
663 | ||
e6af3a53 NC |
664 | /* Test if a read-only section can be merged with .text. This is |
665 | possible if: | |
666 | ||
667 | 1. Section has file contents and is read-only. | |
668 | 2. The VMA of the section is after the end of .text and before | |
669 | the start of .data. | |
670 | 3. The image is demand-pageable (otherwise, a_text in the header | |
671 | will not reflect the gap between .text and .data). */ | |
672 | ||
673 | #define aout_section_merge_with_text_p(abfd, sec) \ | |
674 | (((sec)->flags & (SEC_HAS_CONTENTS | SEC_READONLY)) == \ | |
675 | (SEC_HAS_CONTENTS | SEC_READONLY) \ | |
676 | && obj_textsec (abfd) != NULL \ | |
677 | && obj_datasec (abfd) != NULL \ | |
678 | && (sec)->vma >= (obj_textsec (abfd)->vma + \ | |
eea6121a AM |
679 | obj_textsec (abfd)->size) \ |
680 | && ((sec)->vma + (sec)->size) <= obj_datasec (abfd)->vma \ | |
e6af3a53 NC |
681 | && ((abfd)->flags & D_PAGED) != 0) |
682 | ||
252b5132 | 683 | #endif /* ! defined (LIBAOUT_H) */ |