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