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