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