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