133965Sjdp/* BFD back-end data structures for a.out (and similar) files. 278828Sobrien Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3218822Sdim 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 438889Sjdp Free Software Foundation, Inc. 533965Sjdp Written by Cygnus Support. 633965Sjdp 7130561Sobrien This file is part of BFD, the Binary File Descriptor library. 833965Sjdp 9130561Sobrien This program is free software; you can redistribute it and/or modify 10130561Sobrien it under the terms of the GNU General Public License as published by 11130561Sobrien the Free Software Foundation; either version 2 of the License, or 12130561Sobrien (at your option) any later version. 1333965Sjdp 14130561Sobrien This program is distributed in the hope that it will be useful, 15130561Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 16130561Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17130561Sobrien GNU General Public License for more details. 1833965Sjdp 19130561Sobrien You should have received a copy of the GNU General Public License 20130561Sobrien along with this program; if not, write to the Free Software 21218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2233965Sjdp 2333965Sjdp#ifndef LIBAOUT_H 2433965Sjdp#define LIBAOUT_H 2533965Sjdp 2633965Sjdp/* We try to encapsulate the differences in the various a.out file 2733965Sjdp variants in a few routines, and otherwise share large masses of code. 2833965Sjdp This means we only have to fix bugs in one place, most of the time. */ 2933965Sjdp 3033965Sjdp#include "bfdlink.h" 3133965Sjdp 32130561Sobrien/* Macros for accessing components in an aout header. */ 3389857Sobrien 34218822Sdim#define H_PUT_64 bfd_h_put_64 35218822Sdim#define H_PUT_32 bfd_h_put_32 36218822Sdim#define H_PUT_16 bfd_h_put_16 37218822Sdim#define H_PUT_8 bfd_h_put_8 38130561Sobrien#define H_PUT_S64 bfd_h_put_signed_64 39130561Sobrien#define H_PUT_S32 bfd_h_put_signed_32 40130561Sobrien#define H_PUT_S16 bfd_h_put_signed_16 41218822Sdim#define H_PUT_S8 bfd_h_put_signed_8 42218822Sdim#define H_GET_64 bfd_h_get_64 43218822Sdim#define H_GET_32 bfd_h_get_32 44218822Sdim#define H_GET_16 bfd_h_get_16 45218822Sdim#define H_GET_8 bfd_h_get_8 46130561Sobrien#define H_GET_S64 bfd_h_get_signed_64 47130561Sobrien#define H_GET_S32 bfd_h_get_signed_32 48130561Sobrien#define H_GET_S16 bfd_h_get_signed_16 49218822Sdim#define H_GET_S8 bfd_h_get_signed_8 5089857Sobrien 5133965Sjdp/* Parameterize the a.out code based on whether it is being built 5233965Sjdp for a 32-bit architecture or a 64-bit architecture. */ 5389857Sobrien/* Do not "beautify" the CONCAT* macro args. Traditional C will not 5489857Sobrien remove whitespace added here, and thus will fail to concatenate 5589857Sobrien the tokens. */ 5633965Sjdp#if ARCH_SIZE==64 57218822Sdim#define GET_WORD H_GET_64 5889857Sobrien#define GET_SWORD H_GET_S64 5989857Sobrien#define GET_MAGIC H_GET_32 60218822Sdim#define PUT_WORD H_PUT_64 6189857Sobrien#define PUT_MAGIC H_PUT_32 6233965Sjdp#ifndef NAME 6389857Sobrien#define NAME(x,y) CONCAT3 (x,_64_,y) 6433965Sjdp#endif 6589857Sobrien#define JNAME(x) CONCAT2 (x,_64) 6633965Sjdp#define BYTES_IN_WORD 8 6789857Sobrien#else 6889857Sobrien#if ARCH_SIZE==16 69218822Sdim#define GET_WORD H_GET_16 7089857Sobrien#define GET_SWORD H_GET_S16 7189857Sobrien#define GET_MAGIC H_GET_16 72218822Sdim#define PUT_WORD H_PUT_16 7389857Sobrien#define PUT_MAGIC H_PUT_16 7489857Sobrien#ifndef NAME 7589857Sobrien#define NAME(x,y) CONCAT3 (x,_16_,y) 7689857Sobrien#endif 7789857Sobrien#define JNAME(x) CONCAT2 (x,_16) 7889857Sobrien#define BYTES_IN_WORD 2 7933965Sjdp#else /* ARCH_SIZE == 32 */ 80218822Sdim#define GET_WORD H_GET_32 8189857Sobrien#define GET_SWORD H_GET_S32 8289857Sobrien#define GET_MAGIC H_GET_32 83218822Sdim#define PUT_WORD H_PUT_32 8489857Sobrien#define PUT_MAGIC H_PUT_32 8533965Sjdp#ifndef NAME 8689857Sobrien#define NAME(x,y) CONCAT3 (x,_32_,y) 8733965Sjdp#endif 8889857Sobrien#define JNAME(x) CONCAT2 (x,_32) 8933965Sjdp#define BYTES_IN_WORD 4 9033965Sjdp#endif /* ARCH_SIZE==32 */ 9189857Sobrien#endif /* ARCH_SIZE==64 */ 9233965Sjdp 9333965Sjdp/* Declare at file level, since used in parameter lists, which have 9433965Sjdp weird scope. */ 9533965Sjdpstruct external_exec; 9633965Sjdpstruct external_nlist; 9733965Sjdpstruct reloc_ext_external; 9833965Sjdpstruct reloc_std_external; 9933965Sjdp 10033965Sjdp/* a.out backend linker hash table entries. */ 10133965Sjdp 10233965Sjdpstruct aout_link_hash_entry 10333965Sjdp{ 10433965Sjdp struct bfd_link_hash_entry root; 10533965Sjdp /* Whether this symbol has been written out. */ 106130561Sobrien bfd_boolean written; 10733965Sjdp /* Symbol index in output file. */ 10833965Sjdp int indx; 10933965Sjdp}; 11033965Sjdp 11133965Sjdp/* a.out backend linker hash table. */ 11233965Sjdp 11333965Sjdpstruct aout_link_hash_table 11433965Sjdp{ 11533965Sjdp struct bfd_link_hash_table root; 11633965Sjdp}; 11733965Sjdp 11833965Sjdp/* Look up an entry in an a.out link hash table. */ 11933965Sjdp 12033965Sjdp#define aout_link_hash_lookup(table, string, create, copy, follow) \ 12133965Sjdp ((struct aout_link_hash_entry *) \ 12233965Sjdp bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow))) 12333965Sjdp 12433965Sjdp/* Traverse an a.out link hash table. */ 12533965Sjdp 12633965Sjdp#define aout_link_hash_traverse(table, func, info) \ 12733965Sjdp (bfd_link_hash_traverse \ 12833965Sjdp (&(table)->root, \ 129218822Sdim (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func), \ 13033965Sjdp (info))) 13133965Sjdp 13233965Sjdp/* Get the a.out link hash table from the info structure. This is 13333965Sjdp just a cast. */ 13433965Sjdp 13533965Sjdp#define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash)) 13633965Sjdp 13733965Sjdp/* Back-end information for various a.out targets. */ 13833965Sjdpstruct aout_backend_data 13933965Sjdp{ 14033965Sjdp /* Are ZMAGIC files mapped contiguously? If so, the text section may 14133965Sjdp need more padding, if the segment size (granularity for memory access 14233965Sjdp control) is larger than the page size. */ 14333965Sjdp unsigned char zmagic_mapped_contiguous; 14433965Sjdp /* If this flag is set, ZMAGIC/NMAGIC file headers get mapped in with the 14533965Sjdp text section, which starts immediately after the file header. 14633965Sjdp If not, the text section starts on the next page. */ 14733965Sjdp unsigned char text_includes_header; 14833965Sjdp 14933965Sjdp /* If this flag is set, then if the entry address is not in the 15033965Sjdp first SEGMENT_SIZE bytes of the text section, it is taken to be 15133965Sjdp the address of the start of the text section. This can be useful 15233965Sjdp for kernels. */ 15333965Sjdp unsigned char entry_is_text_address; 15433965Sjdp 15533965Sjdp /* The value to pass to N_SET_FLAGS. */ 15633965Sjdp unsigned char exec_hdr_flags; 15733965Sjdp 15833965Sjdp /* If the text section VMA isn't specified, and we need an absolute 15933965Sjdp address, use this as the default. If we're producing a relocatable 16033965Sjdp file, zero is always used. */ 16133965Sjdp /* ?? Perhaps a callback would be a better choice? Will this do anything 16233965Sjdp reasonable for a format that handles multiple CPUs with different 16333965Sjdp load addresses for each? */ 16433965Sjdp bfd_vma default_text_vma; 16533965Sjdp 16633965Sjdp /* Callback for setting the page and segment sizes, if they can't be 16733965Sjdp trivially determined from the architecture. */ 168218822Sdim bfd_boolean (*set_sizes) (bfd *); 16933965Sjdp 17033965Sjdp /* zmagic files only. For go32, the length of the exec header contributes 17133965Sjdp to the size of the text section in the file for alignment purposes but 17233965Sjdp does *not* get counted in the length of the text section. */ 17333965Sjdp unsigned char exec_header_not_counted; 17433965Sjdp 17533965Sjdp /* Callback from the add symbols phase of the linker code to handle 17633965Sjdp a dynamic object. */ 177130561Sobrien bfd_boolean (*add_dynamic_symbols) 178218822Sdim (bfd *, struct bfd_link_info *, struct external_nlist **, 179218822Sdim bfd_size_type *, char **); 18033965Sjdp 18133965Sjdp /* Callback from the add symbols phase of the linker code to handle 18233965Sjdp adding a single symbol to the global linker hash table. */ 183130561Sobrien bfd_boolean (*add_one_symbol) 184218822Sdim (struct bfd_link_info *, bfd *, const char *, flagword, 185218822Sdim asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, 186218822Sdim struct bfd_link_hash_entry **); 18733965Sjdp 18833965Sjdp /* Called to handle linking a dynamic object. */ 189130561Sobrien bfd_boolean (*link_dynamic_object) 190218822Sdim (struct bfd_link_info *, bfd *); 19133965Sjdp 19233965Sjdp /* Called for each global symbol being written out by the linker. 19333965Sjdp This should write out the dynamic symbol information. */ 194130561Sobrien bfd_boolean (*write_dynamic_symbol) 195218822Sdim (bfd *, struct bfd_link_info *, struct aout_link_hash_entry *); 19633965Sjdp 19733965Sjdp /* If this callback is not NULL, the linker calls it for each reloc. 19833965Sjdp RELOC is a pointer to the unswapped reloc. If *SKIP is set to 199130561Sobrien TRUE, the reloc will be skipped. *RELOCATION may be changed to 20033965Sjdp change the effects of the relocation. */ 201130561Sobrien bfd_boolean (*check_dynamic_reloc) 202218822Sdim (struct bfd_link_info *info, bfd *input_bfd, 203218822Sdim asection *input_section, struct aout_link_hash_entry *h, 204218822Sdim void * reloc, bfd_byte *contents, bfd_boolean *skip, 205218822Sdim bfd_vma *relocation); 20633965Sjdp 20733965Sjdp /* Called at the end of a link to finish up any dynamic linking 20833965Sjdp information. */ 209218822Sdim bfd_boolean (*finish_dynamic_link) (bfd *, struct bfd_link_info *); 21033965Sjdp}; 21133965Sjdp#define aout_backend_info(abfd) \ 21289857Sobrien ((const struct aout_backend_data *)((abfd)->xvec->backend_data)) 21333965Sjdp 21433965Sjdp/* This is the layout in memory of a "struct exec" while we process it. 21533965Sjdp All 'lengths' are given as a number of bytes. 21633965Sjdp All 'alignments' are for relinkable files only; an alignment of 21733965Sjdp 'n' indicates the corresponding segment must begin at an 21833965Sjdp address that is a multiple of (2**n). */ 21933965Sjdp 22033965Sjdpstruct internal_exec 22133965Sjdp{ 222218822Sdim long a_info; /* Magic number and flags, packed. */ 223218822Sdim bfd_vma a_text; /* Length of text, in bytes. */ 224218822Sdim bfd_vma a_data; /* Length of data, in bytes. */ 225218822Sdim bfd_vma a_bss; /* Length of uninitialized data area in mem. */ 226218822Sdim bfd_vma a_syms; /* Length of symbol table data in file. */ 227218822Sdim bfd_vma a_entry; /* Start address. */ 228218822Sdim bfd_vma a_trsize; /* Length of text's relocation info, in bytes. */ 229218822Sdim bfd_vma a_drsize; /* Length of data's relocation info, in bytes. */ 230218822Sdim /* Added for i960 */ 231218822Sdim bfd_vma a_tload; /* Text runtime load address. */ 232218822Sdim bfd_vma a_dload; /* Data runtime load address. */ 233218822Sdim unsigned char a_talign; /* Alignment of text segment. */ 234218822Sdim unsigned char a_dalign; /* Alignment of data segment. */ 235218822Sdim unsigned char a_balign; /* Alignment of bss segment. */ 236218822Sdim char a_relaxable; /* Enough info for linker relax. */ 23733965Sjdp}; 23833965Sjdp 23989857Sobrien/* Magic number is written 240218822Sdim < MSB > 241218822Sdim 3130292827262524232221201918171615141312111009080706050403020100 242218822Sdim < FLAGS >< MACHINE TYPE >< MAGIC NUMBER > */ 243218822Sdim 24433965Sjdp/* Magic number for NetBSD is 245218822Sdim <MSB > 246218822Sdim 3130292827262524232221201918171615141312111009080706050403020100 247218822Sdim < FLAGS >< MACHINE TYPE >< MAGIC NUMBER > */ 24833965Sjdp 249218822Sdimenum machine_type 250218822Sdim{ 25133965Sjdp M_UNKNOWN = 0, 25233965Sjdp M_68010 = 1, 25333965Sjdp M_68020 = 2, 25433965Sjdp M_SPARC = 3, 255130561Sobrien /* Skip a bunch so we don't run into any of SUN's numbers. */ 256130561Sobrien /* Make these up for the ns32k. */ 257218822Sdim M_NS32032 = (64), /* NS32032 running ? */ 258218822Sdim M_NS32532 = (64 + 5), /* NS32532 running mach. */ 25933965Sjdp M_386 = 100, 260218822Sdim M_29K = 101, /* AMD 29000. */ 261218822Sdim M_386_DYNIX = 102, /* Sequent running dynix. */ 262218822Sdim M_ARM = 103, /* Advanced Risc Machines ARM. */ 263218822Sdim M_SPARCLET = 131, /* SPARClet = M_SPARC + 128. */ 264218822Sdim M_386_NETBSD = 134, /* NetBSD/i386 binary. */ 265218822Sdim M_68K_NETBSD = 135, /* NetBSD/m68k binary. */ 266218822Sdim M_68K4K_NETBSD = 136, /* NetBSD/m68k4k binary. */ 267218822Sdim M_532_NETBSD = 137, /* NetBSD/ns32k binary. */ 268218822Sdim M_SPARC_NETBSD = 138, /* NetBSD/sparc binary. */ 269218822Sdim M_PMAX_NETBSD = 139, /* NetBSD/pmax (MIPS little-endian) binary. */ 270218822Sdim M_VAX_NETBSD = 140, /* NetBSD/vax binary. */ 271218822Sdim M_ALPHA_NETBSD = 141, /* NetBSD/alpha binary. */ 272218822Sdim M_ARM6_NETBSD = 143, /* NetBSD/arm32 binary. */ 273218822Sdim M_SPARCLET_1 = 147, /* 0x93, reserved. */ 274218822Sdim M_POWERPC_NETBSD = 149, /* NetBSD/powerpc (big-endian) binary. */ 275218822Sdim M_VAX4K_NETBSD = 150, /* NetBSD/vax 4K pages binary. */ 276218822Sdim M_MIPS1 = 151, /* MIPS R2000/R3000 binary. */ 277218822Sdim M_MIPS2 = 152, /* MIPS R4000/R6000 binary. */ 278218822Sdim M_88K_OPENBSD = 153, /* OpenBSD/m88k binary. */ 279218822Sdim M_HPPA_OPENBSD = 154, /* OpenBSD/hppa binary. */ 280218822Sdim M_SPARC64_NETBSD = 156, /* NetBSD/sparc64 binary. */ 281218822Sdim M_X86_64_NETBSD = 157, /* NetBSD/amd64 binary. */ 282218822Sdim M_SPARCLET_2 = 163, /* 0xa3, reserved. */ 283218822Sdim M_SPARCLET_3 = 179, /* 0xb3, reserved. */ 284218822Sdim M_SPARCLET_4 = 195, /* 0xc3, reserved. */ 285218822Sdim M_HP200 = 200, /* HP 200 (68010) BSD binary. */ 286218822Sdim M_HP300 = (300 % 256), /* HP 300 (68020+68881) BSD binary. */ 287218822Sdim M_HPUX = (0x20c % 256), /* HP 200/300 HPUX binary. */ 288218822Sdim M_SPARCLET_5 = 211, /* 0xd3, reserved. */ 289218822Sdim M_SPARCLET_6 = 227, /* 0xe3, reserved. */ 290218822Sdim/*M_SPARCLET_7 = 243 / * 0xf3, reserved. */ 29177298Sobrien M_SPARCLITE_LE = 243, 292218822Sdim M_CRIS = 255 /* Axis CRIS binary. */ 29333965Sjdp}; 29433965Sjdp 29533965Sjdp#define N_DYNAMIC(exec) ((exec).a_info & 0x80000000) 29633965Sjdp 29733965Sjdp#ifndef N_MAGIC 29833965Sjdp# define N_MAGIC(exec) ((exec).a_info & 0xffff) 29933965Sjdp#endif 30033965Sjdp 30133965Sjdp#ifndef N_MACHTYPE 30233965Sjdp# define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff)) 30333965Sjdp#endif 30433965Sjdp 30533965Sjdp#ifndef N_FLAGS 30633965Sjdp# define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff) 30733965Sjdp#endif 30833965Sjdp 30933965Sjdp#ifndef N_SET_INFO 31033965Sjdp# define N_SET_INFO(exec, magic, type, flags) \ 31133965Sjdp((exec).a_info = ((magic) & 0xffff) \ 31233965Sjdp | (((int)(type) & 0xff) << 16) \ 31333965Sjdp | (((flags) & 0xff) << 24)) 31433965Sjdp#endif 31533965Sjdp 31633965Sjdp#ifndef N_SET_DYNAMIC 31733965Sjdp# define N_SET_DYNAMIC(exec, dynamic) \ 31889857Sobrien((exec).a_info = (dynamic) ? (long) ((exec).a_info | 0x80000000) : \ 31933965Sjdp((exec).a_info & 0x7fffffff)) 32033965Sjdp#endif 32133965Sjdp 32233965Sjdp#ifndef N_SET_MAGIC 32333965Sjdp# define N_SET_MAGIC(exec, magic) \ 32433965Sjdp((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff))) 32533965Sjdp#endif 32633965Sjdp 32733965Sjdp#ifndef N_SET_MACHTYPE 32833965Sjdp# define N_SET_MACHTYPE(exec, machtype) \ 32933965Sjdp((exec).a_info = \ 33033965Sjdp ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16)) 33133965Sjdp#endif 33233965Sjdp 33333965Sjdp#ifndef N_SET_FLAGS 33433965Sjdp# define N_SET_FLAGS(exec, flags) \ 33533965Sjdp((exec).a_info = \ 33633965Sjdp ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24)) 33733965Sjdp#endif 33833965Sjdp 339218822Sdimtypedef struct aout_symbol 340218822Sdim{ 34133965Sjdp asymbol symbol; 34233965Sjdp short desc; 34333965Sjdp char other; 34433965Sjdp unsigned char type; 34533965Sjdp} aout_symbol_type; 34633965Sjdp 34733965Sjdp/* The `tdata' struct for all a.out-like object file formats. 34833965Sjdp Various things depend on this struct being around any time an a.out 34933965Sjdp file is being handled. An example is dbxread.c in GDB. */ 35033965Sjdp 351218822Sdimstruct aoutdata 352218822Sdim{ 353218822Sdim struct internal_exec *hdr; /* Exec file header. */ 354218822Sdim aout_symbol_type *symbols; /* Symtab for input bfd. */ 35589857Sobrien 356130561Sobrien /* For ease, we do this. */ 35733965Sjdp asection *textsec; 35833965Sjdp asection *datasec; 35933965Sjdp asection *bsssec; 36033965Sjdp 36133965Sjdp /* We remember these offsets so that after check_file_format, we have 36233965Sjdp no dependencies on the particular format of the exec_hdr. */ 36333965Sjdp file_ptr sym_filepos; 36433965Sjdp file_ptr str_filepos; 36533965Sjdp 366130561Sobrien /* Size of a relocation entry in external form. */ 36733965Sjdp unsigned reloc_entry_size; 36833965Sjdp 369130561Sobrien /* Size of a symbol table entry in external form. */ 37033965Sjdp unsigned symbol_entry_size; 37133965Sjdp 372130561Sobrien /* Page size - needed for alignment of demand paged files. */ 37333965Sjdp unsigned long page_size; 37433965Sjdp 375130561Sobrien /* Segment size - needed for alignment of demand paged files. */ 37633965Sjdp unsigned long segment_size; 37733965Sjdp 37833965Sjdp /* Zmagic disk block size - need to align the start of the text 37933965Sjdp section in ZMAGIC binaries. Normally the same as page_size. */ 38033965Sjdp unsigned long zmagic_disk_block_size; 38133965Sjdp 38233965Sjdp unsigned exec_bytes_size; 38333965Sjdp unsigned vma_adjusted : 1; 38433965Sjdp 385130561Sobrien /* Used when a bfd supports several highly similar formats. */ 38633965Sjdp enum 38733965Sjdp { 38833965Sjdp default_format = 0, 38933965Sjdp /* Used on HP 9000/300 running HP/UX. See hp300hpux.c. */ 39033965Sjdp gnu_encap_format, 39133965Sjdp /* Used on Linux, 386BSD, etc. See include/aout/aout64.h. */ 39233965Sjdp q_magic_format 39333965Sjdp } subformat; 39433965Sjdp 39533965Sjdp enum 39633965Sjdp { 39733965Sjdp undecided_magic = 0, 39833965Sjdp z_magic, 39933965Sjdp o_magic, 40033965Sjdp n_magic 40133965Sjdp } magic; 40233965Sjdp 40333965Sjdp /* A buffer for find_nearest_line. */ 40433965Sjdp char *line_buf; 40533965Sjdp 40633965Sjdp /* The external symbol information. */ 40733965Sjdp struct external_nlist *external_syms; 40833965Sjdp bfd_size_type external_sym_count; 40933965Sjdp bfd_window sym_window; 41033965Sjdp char *external_strings; 41133965Sjdp bfd_size_type external_string_size; 41233965Sjdp bfd_window string_window; 41333965Sjdp struct aout_link_hash_entry **sym_hashes; 41433965Sjdp 41533965Sjdp /* A pointer for shared library information. */ 416218822Sdim void * dynamic_info; 41733965Sjdp 41833965Sjdp /* A mapping from local symbols to offsets into the global offset 41933965Sjdp table, used when linking on SunOS. This is indexed by the symbol 42033965Sjdp index. */ 42133965Sjdp bfd_vma *local_got_offsets; 42233965Sjdp}; 42333965Sjdp 424218822Sdimstruct aout_data_struct 425218822Sdim{ 426218822Sdim struct aoutdata a; 427218822Sdim struct internal_exec e; 42833965Sjdp}; 42933965Sjdp 430218822Sdim#define adata(bfd) ((bfd)->tdata.aout_data->a) 431218822Sdim#define exec_hdr(bfd) (adata (bfd).hdr) 432218822Sdim#define obj_aout_symbols(bfd) (adata (bfd).symbols) 433218822Sdim#define obj_textsec(bfd) (adata (bfd).textsec) 434218822Sdim#define obj_datasec(bfd) (adata (bfd).datasec) 435218822Sdim#define obj_bsssec(bfd) (adata (bfd).bsssec) 436218822Sdim#define obj_sym_filepos(bfd) (adata (bfd).sym_filepos) 437218822Sdim#define obj_str_filepos(bfd) (adata (bfd).str_filepos) 438218822Sdim#define obj_reloc_entry_size(bfd) (adata (bfd).reloc_entry_size) 439218822Sdim#define obj_symbol_entry_size(bfd) (adata (bfd).symbol_entry_size) 440218822Sdim#define obj_aout_subformat(bfd) (adata (bfd).subformat) 441218822Sdim#define obj_aout_external_syms(bfd) (adata (bfd).external_syms) 442218822Sdim#define obj_aout_external_sym_count(bfd) (adata (bfd).external_sym_count) 443218822Sdim#define obj_aout_sym_window(bfd) (adata (bfd).sym_window) 444218822Sdim#define obj_aout_external_strings(bfd) (adata (bfd).external_strings) 445218822Sdim#define obj_aout_external_string_size(bfd) (adata (bfd).external_string_size) 446218822Sdim#define obj_aout_string_window(bfd) (adata (bfd).string_window) 447218822Sdim#define obj_aout_sym_hashes(bfd) (adata (bfd).sym_hashes) 448218822Sdim#define obj_aout_dynamic_info(bfd) (adata (bfd).dynamic_info) 44933965Sjdp 45033965Sjdp/* We take the address of the first element of an asymbol to ensure that the 451130561Sobrien macro is only ever applied to an asymbol. */ 45233965Sjdp#define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd)) 45333965Sjdp 45433965Sjdp/* Information we keep for each a.out section. This is currently only 45533965Sjdp used by the a.out backend linker. */ 45633965Sjdp 45733965Sjdpstruct aout_section_data_struct 45833965Sjdp{ 45933965Sjdp /* The unswapped relocation entries for this section. */ 460218822Sdim void * relocs; 46133965Sjdp}; 46233965Sjdp 46333965Sjdp#define aout_section_data(s) \ 46433965Sjdp ((struct aout_section_data_struct *) (s)->used_by_bfd) 46533965Sjdp 46633965Sjdp#define set_aout_section_data(s,v) \ 467218822Sdim ((s)->used_by_bfd = (void *)&(v)->relocs) 46833965Sjdp 469130561Sobrien/* Prototype declarations for functions defined in aoutx.h. */ 47033965Sjdp 471218822Sdimextern bfd_boolean NAME (aout, squirt_out_relocs) 472218822Sdim (bfd *, asection *); 47333965Sjdp 474218822Sdimextern bfd_boolean NAME (aout, make_sections) 475218822Sdim (bfd *); 47633965Sjdp 477218822Sdimextern const bfd_target * NAME (aout, some_aout_object_p) 478218822Sdim (bfd *, struct internal_exec *, const bfd_target *(*) (bfd *)); 47933965Sjdp 480218822Sdimextern bfd_boolean NAME (aout, mkobject) 481218822Sdim (bfd *); 48233965Sjdp 483218822Sdimextern enum machine_type NAME (aout, machine_type) 484218822Sdim (enum bfd_architecture, unsigned long, bfd_boolean *); 48533965Sjdp 486218822Sdimextern bfd_boolean NAME (aout, set_arch_mach) 487218822Sdim (bfd *, enum bfd_architecture, unsigned long); 48833965Sjdp 489218822Sdimextern bfd_boolean NAME (aout, new_section_hook) 490218822Sdim (bfd *, asection *); 49133965Sjdp 492218822Sdimextern bfd_boolean NAME (aout, set_section_contents) 493218822Sdim (bfd *, sec_ptr, const void *, file_ptr, bfd_size_type); 49433965Sjdp 495218822Sdimextern asymbol * NAME (aout, make_empty_symbol) 496218822Sdim (bfd *); 49733965Sjdp 498218822Sdimextern bfd_boolean NAME (aout, translate_symbol_table) 499218822Sdim (bfd *, aout_symbol_type *, struct external_nlist *, bfd_size_type, 500218822Sdim char *, bfd_size_type, bfd_boolean); 50133965Sjdp 502218822Sdimextern bfd_boolean NAME (aout, slurp_symbol_table) 503218822Sdim (bfd *); 50433965Sjdp 505218822Sdimextern bfd_boolean NAME (aout, write_syms) 506218822Sdim (bfd *); 50733965Sjdp 508218822Sdimextern void NAME (aout, reclaim_symbol_table) 509218822Sdim (bfd *); 51033965Sjdp 511218822Sdimextern long NAME (aout, get_symtab_upper_bound) 512218822Sdim (bfd *); 51333965Sjdp 514218822Sdimextern long NAME (aout, canonicalize_symtab) 515218822Sdim (bfd *, asymbol **); 51633965Sjdp 517218822Sdimextern void NAME (aout, swap_ext_reloc_in) 518218822Sdim (bfd *, struct reloc_ext_external *, arelent *, asymbol **, 519218822Sdim bfd_size_type); 52033965Sjdp 521218822Sdimextern void NAME (aout, swap_std_reloc_in) 522218822Sdim (bfd *, struct reloc_std_external *, arelent *, asymbol **, 523218822Sdim bfd_size_type); 52433965Sjdp 525218822Sdimextern reloc_howto_type * NAME (aout, reloc_type_lookup) 526218822Sdim (bfd *, bfd_reloc_code_real_type); 52733965Sjdp 528218822Sdimextern reloc_howto_type * NAME (aout, reloc_name_lookup) 529218822Sdim (bfd *, const char *); 53033965Sjdp 531218822Sdimextern bfd_boolean NAME (aout, slurp_reloc_table) 532218822Sdim (bfd *, sec_ptr, asymbol **); 53333965Sjdp 534218822Sdimextern long NAME (aout, canonicalize_reloc) 535218822Sdim (bfd *, sec_ptr, arelent **, asymbol **); 53633965Sjdp 537218822Sdimextern long NAME (aout, get_reloc_upper_bound) 538218822Sdim (bfd *, sec_ptr); 53933965Sjdp 540218822Sdimextern void NAME (aout, reclaim_reloc) 541218822Sdim (bfd *, sec_ptr); 54233965Sjdp 543218822Sdimextern alent * NAME (aout, get_lineno) 544218822Sdim (bfd *, asymbol *); 54533965Sjdp 546218822Sdimextern void NAME (aout, print_symbol) 547218822Sdim (bfd *, void *, asymbol *, bfd_print_symbol_type); 54833965Sjdp 549218822Sdimextern void NAME (aout, get_symbol_info) 550218822Sdim (bfd *, asymbol *, symbol_info *); 55133965Sjdp 552218822Sdimextern bfd_boolean NAME (aout, find_nearest_line) 553218822Sdim (bfd *, asection *, asymbol **, bfd_vma, const char **, 554218822Sdim const char **, unsigned int *); 55533965Sjdp 556218822Sdimextern long NAME (aout, read_minisymbols) 557218822Sdim (bfd *, bfd_boolean, void * *, unsigned int *); 55833965Sjdp 559218822Sdimextern asymbol * NAME (aout, minisymbol_to_symbol) 560218822Sdim (bfd *, bfd_boolean, const void *, asymbol *); 56133965Sjdp 562218822Sdimextern int NAME (aout, sizeof_headers) 563218822Sdim (bfd *, struct bfd_link_info *); 56433965Sjdp 565218822Sdimextern bfd_boolean NAME (aout, adjust_sizes_and_vmas) 566218822Sdim (bfd *, bfd_size_type *, file_ptr *); 56733965Sjdp 568218822Sdimextern void NAME (aout, swap_exec_header_in) 569218822Sdim (bfd *, struct external_exec *, struct internal_exec *); 57033965Sjdp 571218822Sdimextern void NAME (aout, swap_exec_header_out) 572218822Sdim (bfd *, struct internal_exec *, struct external_exec *); 57333965Sjdp 574218822Sdimextern struct bfd_hash_entry * NAME (aout, link_hash_newfunc) 575218822Sdim (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); 57633965Sjdp 577218822Sdimextern bfd_boolean NAME (aout, link_hash_table_init) 578218822Sdim (struct aout_link_hash_table *, bfd *, 579218822Sdim struct bfd_hash_entry *(*) (struct bfd_hash_entry *, 580218822Sdim struct bfd_hash_table *, 581218822Sdim const char *), 582218822Sdim unsigned int); 58333965Sjdp 584218822Sdimextern struct bfd_link_hash_table * NAME (aout, link_hash_table_create) 585218822Sdim (bfd *); 58633965Sjdp 587218822Sdimextern bfd_boolean NAME (aout, link_add_symbols) 588218822Sdim (bfd *, struct bfd_link_info *); 58933965Sjdp 590218822Sdimextern bfd_boolean NAME (aout, final_link) 591218822Sdim (bfd *, struct bfd_link_info *, 592218822Sdim void (*) (bfd *, file_ptr *, file_ptr *, file_ptr *)); 593218822Sdim 594218822Sdimextern bfd_boolean NAME (aout, bfd_free_cached_info) 595218822Sdim (bfd *); 596218822Sdim 597218822Sdim#define aout_32_find_inliner_info _bfd_nosymbols_find_inliner_info 598218822Sdim#if 0 /* Are these needed? */ 599218822Sdim#define aout_16_find_inliner_info _bfd_nosymbols_find_inliner_info 600218822Sdim#define aout_64_find_inliner_info _bfd_nosymbols_find_inliner_info 601218822Sdim#endif 602218822Sdim 603130561Sobrien/* A.out uses the generic versions of these routines... */ 60433965Sjdp 60589857Sobrien#define aout_16_get_section_contents _bfd_generic_get_section_contents 60689857Sobrien 60733965Sjdp#define aout_32_get_section_contents _bfd_generic_get_section_contents 60833965Sjdp 60933965Sjdp#define aout_64_get_section_contents _bfd_generic_get_section_contents 61033965Sjdp#ifndef NO_WRITE_HEADER_KLUDGE 61133965Sjdp#define NO_WRITE_HEADER_KLUDGE 0 61233965Sjdp#endif 61333965Sjdp 61433965Sjdp#ifndef aout_32_bfd_is_local_label_name 61533965Sjdp#define aout_32_bfd_is_local_label_name bfd_generic_is_local_label_name 61633965Sjdp#endif 61733965Sjdp 618218822Sdim#ifndef aout_32_bfd_is_target_special_symbol 619218822Sdim#define aout_32_bfd_is_target_special_symbol \ 620218822Sdim ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) 621218822Sdim#endif 622218822Sdim 62333965Sjdp#ifndef WRITE_HEADERS 62433965Sjdp#define WRITE_HEADERS(abfd, execp) \ 62533965Sjdp { \ 626218822Sdim bfd_size_type text_size; /* Dummy vars. */ \ 62733965Sjdp file_ptr text_end; \ 628218822Sdim \ 62933965Sjdp if (adata(abfd).magic == undecided_magic) \ 630218822Sdim NAME (aout, adjust_sizes_and_vmas) (abfd, & text_size, & text_end); \ 63133965Sjdp \ 63233965Sjdp execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \ 63333965Sjdp execp->a_entry = bfd_get_start_address (abfd); \ 63433965Sjdp \ 63533965Sjdp execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \ 63633965Sjdp obj_reloc_entry_size (abfd)); \ 63733965Sjdp execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \ 63833965Sjdp obj_reloc_entry_size (abfd)); \ 639218822Sdim NAME (aout, swap_exec_header_out) (abfd, execp, & exec_bytes); \ 64033965Sjdp \ 64189857Sobrien if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 \ 642218822Sdim || bfd_bwrite (& exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \ 64389857Sobrien abfd) != EXEC_BYTES_SIZE) \ 644130561Sobrien return FALSE; \ 645130561Sobrien /* Now write out reloc info, followed by syms and strings. */ \ 64633965Sjdp \ 647218822Sdim if (bfd_get_outsymbols (abfd) != NULL \ 64833965Sjdp && bfd_get_symcount (abfd) != 0) \ 64933965Sjdp { \ 65089857Sobrien if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0)\ 651130561Sobrien return FALSE; \ 65233965Sjdp \ 653218822Sdim if (! NAME (aout, write_syms) (abfd)) \ 654130561Sobrien return FALSE; \ 65533965Sjdp } \ 65633965Sjdp \ 657218822Sdim if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0) \ 658130561Sobrien return FALSE; \ 659218822Sdim if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd))) \ 660130561Sobrien return FALSE; \ 66133965Sjdp \ 662218822Sdim if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0) \ 663130561Sobrien return FALSE; \ 664218822Sdim if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd))) \ 665130561Sobrien return FALSE; \ 66689857Sobrien } 66733965Sjdp#endif 66833965Sjdp 669130561Sobrien/* Test if a read-only section can be merged with .text. This is 670130561Sobrien possible if: 671130561Sobrien 672130561Sobrien 1. Section has file contents and is read-only. 673130561Sobrien 2. The VMA of the section is after the end of .text and before 674130561Sobrien the start of .data. 675130561Sobrien 3. The image is demand-pageable (otherwise, a_text in the header 676130561Sobrien will not reflect the gap between .text and .data). */ 677130561Sobrien 678130561Sobrien#define aout_section_merge_with_text_p(abfd, sec) \ 679130561Sobrien (((sec)->flags & (SEC_HAS_CONTENTS | SEC_READONLY)) == \ 680130561Sobrien (SEC_HAS_CONTENTS | SEC_READONLY) \ 681130561Sobrien && obj_textsec (abfd) != NULL \ 682130561Sobrien && obj_datasec (abfd) != NULL \ 683130561Sobrien && (sec)->vma >= (obj_textsec (abfd)->vma + \ 684218822Sdim obj_textsec (abfd)->size) \ 685218822Sdim && ((sec)->vma + (sec)->size) <= obj_datasec (abfd)->vma \ 686130561Sobrien && ((abfd)->flags & D_PAGED) != 0) 687130561Sobrien 68833965Sjdp#endif /* ! defined (LIBAOUT_H) */ 689