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