1*a9fa9459Szrj /* BFD ECOFF object file private structure. 2*a9fa9459Szrj Copyright (C) 1993-2016 Free Software Foundation, Inc. 3*a9fa9459Szrj Written by Ian Lance Taylor, 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 #include "bfdlink.h" 23*a9fa9459Szrj 24*a9fa9459Szrj #ifndef ECOFF_H 25*a9fa9459Szrj #include "coff/ecoff.h" 26*a9fa9459Szrj #endif 27*a9fa9459Szrj 28*a9fa9459Szrj /* This is the backend information kept for ECOFF files. This 29*a9fa9459Szrj structure is constant for a particular backend. The first element 30*a9fa9459Szrj is the COFF backend data structure, so that ECOFF targets can use 31*a9fa9459Szrj the generic COFF code. */ 32*a9fa9459Szrj 33*a9fa9459Szrj #define ecoff_backend(abfd) \ 34*a9fa9459Szrj ((struct ecoff_backend_data *) (abfd)->xvec->backend_data) 35*a9fa9459Szrj 36*a9fa9459Szrj struct ecoff_backend_data 37*a9fa9459Szrj { 38*a9fa9459Szrj /* COFF backend information. This must be the first field. */ 39*a9fa9459Szrj bfd_coff_backend_data coff; 40*a9fa9459Szrj /* Supported architecture. */ 41*a9fa9459Szrj enum bfd_architecture arch; 42*a9fa9459Szrj /* Initial portion of armap string. */ 43*a9fa9459Szrj const char *armap_start; 44*a9fa9459Szrj /* The page boundary used to align sections in a demand-paged 45*a9fa9459Szrj executable file. E.g., 0x1000. */ 46*a9fa9459Szrj bfd_vma round; 47*a9fa9459Szrj /* TRUE if the .rdata section is part of the text segment, as on the 48*a9fa9459Szrj Alpha. FALSE if .rdata is part of the data segment, as on the 49*a9fa9459Szrj MIPS. */ 50*a9fa9459Szrj bfd_boolean rdata_in_text; 51*a9fa9459Szrj /* Bitsize of constructor entries. */ 52*a9fa9459Szrj unsigned int constructor_bitsize; 53*a9fa9459Szrj /* Reloc to use for constructor entries. */ 54*a9fa9459Szrj reloc_howto_type *constructor_reloc; 55*a9fa9459Szrj /* How to swap debugging information. */ 56*a9fa9459Szrj struct ecoff_debug_swap debug_swap; 57*a9fa9459Szrj /* External reloc size. */ 58*a9fa9459Szrj bfd_size_type external_reloc_size; 59*a9fa9459Szrj /* Reloc swapping functions. */ 60*a9fa9459Szrj void (*swap_reloc_in) (bfd *, void *, struct internal_reloc *); 61*a9fa9459Szrj void (*swap_reloc_out) (bfd *, const struct internal_reloc *, void *); 62*a9fa9459Szrj /* Backend reloc tweaking. */ 63*a9fa9459Szrj void (*adjust_reloc_in) 64*a9fa9459Szrj (bfd *, const struct internal_reloc *, arelent *); 65*a9fa9459Szrj void (*adjust_reloc_out) 66*a9fa9459Szrj (bfd *, const arelent *, struct internal_reloc *); 67*a9fa9459Szrj /* Relocate section contents while linking. */ 68*a9fa9459Szrj bfd_boolean (*relocate_section) 69*a9fa9459Szrj (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, void *); 70*a9fa9459Szrj /* Do final adjustments to filehdr and aouthdr. */ 71*a9fa9459Szrj bfd_boolean (*adjust_headers) 72*a9fa9459Szrj (bfd *, struct internal_filehdr *, struct internal_aouthdr *); 73*a9fa9459Szrj /* Read an element from an archive at a given file position. This 74*a9fa9459Szrj is needed because OSF/1 3.2 uses a weird archive format. */ 75*a9fa9459Szrj bfd *(*get_elt_at_filepos) (bfd *, file_ptr); 76*a9fa9459Szrj }; 77*a9fa9459Szrj 78*a9fa9459Szrj /* ECOFF targets don't support COFF long section names, so this 79*a9fa9459Szrj macro is provided to use as an initialiser for the related 80*a9fa9459Szrj members of the embedded bfd_coff_backend_data struct. */ 81*a9fa9459Szrj #define ECOFF_NO_LONG_SECTION_NAMES (FALSE), _bfd_ecoff_no_long_sections 82*a9fa9459Szrj 83*a9fa9459Szrj /* This is the target specific information kept for ECOFF files. */ 84*a9fa9459Szrj 85*a9fa9459Szrj #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) 86*a9fa9459Szrj 87*a9fa9459Szrj typedef struct ecoff_tdata 88*a9fa9459Szrj { 89*a9fa9459Szrj /* The reloc file position, set by 90*a9fa9459Szrj ecoff_compute_section_file_positions. */ 91*a9fa9459Szrj file_ptr reloc_filepos; 92*a9fa9459Szrj 93*a9fa9459Szrj /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */ 94*a9fa9459Szrj file_ptr sym_filepos; 95*a9fa9459Szrj 96*a9fa9459Szrj /* The start and end of the text segment. Only valid for an 97*a9fa9459Szrj existing file, not for one we are creating. */ 98*a9fa9459Szrj unsigned long text_start; 99*a9fa9459Szrj unsigned long text_end; 100*a9fa9459Szrj 101*a9fa9459Szrj /* The cached gp value. This is used when relocating. */ 102*a9fa9459Szrj bfd_vma gp; 103*a9fa9459Szrj 104*a9fa9459Szrj /* The maximum size of objects to optimize using gp. This is 105*a9fa9459Szrj typically set by the -G option to the compiler, assembler or 106*a9fa9459Szrj linker. */ 107*a9fa9459Szrj unsigned int gp_size; 108*a9fa9459Szrj 109*a9fa9459Szrj /* The register masks. When linking, all the masks found in the 110*a9fa9459Szrj input files are combined into the masks of the output file. 111*a9fa9459Szrj These are not all used for all targets, but that's OK, because 112*a9fa9459Szrj the relevant ones are the only ones swapped in and out. */ 113*a9fa9459Szrj unsigned long gprmask; 114*a9fa9459Szrj unsigned long fprmask; 115*a9fa9459Szrj unsigned long cprmask[4]; 116*a9fa9459Szrj 117*a9fa9459Szrj /* The ECOFF symbolic debugging information. */ 118*a9fa9459Szrj struct ecoff_debug_info debug_info; 119*a9fa9459Szrj 120*a9fa9459Szrj /* The unswapped ECOFF symbolic information. */ 121*a9fa9459Szrj void * raw_syments; 122*a9fa9459Szrj 123*a9fa9459Szrj /* The canonical BFD symbols. */ 124*a9fa9459Szrj struct ecoff_symbol_struct *canonical_symbols; 125*a9fa9459Szrj 126*a9fa9459Szrj /* A mapping from external symbol numbers to entries in the linker 127*a9fa9459Szrj hash table, used when linking. */ 128*a9fa9459Szrj struct ecoff_link_hash_entry **sym_hashes; 129*a9fa9459Szrj 130*a9fa9459Szrj /* A mapping from reloc symbol indices to sections, used when 131*a9fa9459Szrj linking. */ 132*a9fa9459Szrj asection **symndx_to_section; 133*a9fa9459Szrj 134*a9fa9459Szrj /* TRUE if this BFD was written by the backend linker. */ 135*a9fa9459Szrj bfd_boolean linker; 136*a9fa9459Szrj 137*a9fa9459Szrj /* TRUE if a warning that multiple global pointer values are 138*a9fa9459Szrj needed in the output binary was issued already. */ 139*a9fa9459Szrj bfd_boolean issued_multiple_gp_warning; 140*a9fa9459Szrj 141*a9fa9459Szrj /* Used by find_nearest_line entry point. The structure could be 142*a9fa9459Szrj included directly in this one, but there's no point to wasting 143*a9fa9459Szrj the memory just for the infrequently called find_nearest_line. */ 144*a9fa9459Szrj struct ecoff_find_line *find_line_info; 145*a9fa9459Szrj 146*a9fa9459Szrj /* Whether the .rdata section is in the text segment for this 147*a9fa9459Szrj particular ECOFF file. This is not valid until 148*a9fa9459Szrj ecoff_compute_section_file_positions is called. */ 149*a9fa9459Szrj bfd_boolean rdata_in_text; 150*a9fa9459Szrj 151*a9fa9459Szrj } ecoff_data_type; 152*a9fa9459Szrj 153*a9fa9459Szrj /* Each canonical asymbol really looks like this. */ 154*a9fa9459Szrj 155*a9fa9459Szrj typedef struct ecoff_symbol_struct 156*a9fa9459Szrj { 157*a9fa9459Szrj /* The actual symbol which the rest of BFD works with */ 158*a9fa9459Szrj asymbol symbol; 159*a9fa9459Szrj 160*a9fa9459Szrj /* The fdr for this symbol. */ 161*a9fa9459Szrj FDR *fdr; 162*a9fa9459Szrj 163*a9fa9459Szrj /* TRUE if this is a local symbol rather than an external one. */ 164*a9fa9459Szrj bfd_boolean local; 165*a9fa9459Szrj 166*a9fa9459Szrj /* A pointer to the unswapped hidden information for this symbol. 167*a9fa9459Szrj This is either a struct sym_ext or a struct ext_ext, depending on 168*a9fa9459Szrj the value of the local field above. */ 169*a9fa9459Szrj void * native; 170*a9fa9459Szrj } ecoff_symbol_type; 171*a9fa9459Szrj 172*a9fa9459Szrj /* We take the address of the first element of an asymbol to ensure that the 173*a9fa9459Szrj macro is only ever applied to an asymbol. */ 174*a9fa9459Szrj #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) 175*a9fa9459Szrj 176*a9fa9459Szrj /* We need to save the index of an external symbol when we write it 177*a9fa9459Szrj out so that can set the symbol index correctly when we write out 178*a9fa9459Szrj the relocs. */ 179*a9fa9459Szrj #define ecoff_get_sym_index(symbol) ((symbol)->udata.i) 180*a9fa9459Szrj #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx)) 181*a9fa9459Szrj 182*a9fa9459Szrj /* A pointer to this structure is put in the used_by_bfd pointer of 183*a9fa9459Szrj a section to keep track of any per-section data. 184*a9fa9459Szrj The user_by_bfd pointer will be NULL if the information was not 185*a9fa9459Szrj needed. */ 186*a9fa9459Szrj 187*a9fa9459Szrj struct ecoff_section_tdata 188*a9fa9459Szrj { 189*a9fa9459Szrj /* When producing an executable (i.e., final, non-relocatable link) 190*a9fa9459Szrj on the Alpha, we may need to use multiple global pointer values 191*a9fa9459Szrj to span the entire .lita section. In essence, we allow each 192*a9fa9459Szrj input .lita section to have its own gp value. To support this, 193*a9fa9459Szrj we need to keep track of the gp values that we picked for each 194*a9fa9459Szrj input .lita section . */ 195*a9fa9459Szrj bfd_vma gp; 196*a9fa9459Szrj }; 197*a9fa9459Szrj 198*a9fa9459Szrj /* An accessor macro for the ecoff_section_tdata structure. */ 199*a9fa9459Szrj #define ecoff_section_data(abfd, sec) \ 200*a9fa9459Szrj ((struct ecoff_section_tdata *) (sec)->used_by_bfd) 201*a9fa9459Szrj 202*a9fa9459Szrj /* ECOFF linker hash table entries. */ 203*a9fa9459Szrj 204*a9fa9459Szrj struct ecoff_link_hash_entry 205*a9fa9459Szrj { 206*a9fa9459Szrj struct bfd_link_hash_entry root; 207*a9fa9459Szrj /* Symbol index in output file. */ 208*a9fa9459Szrj long indx; 209*a9fa9459Szrj /* BFD that ext field value came from. */ 210*a9fa9459Szrj bfd *abfd; 211*a9fa9459Szrj /* ECOFF external symbol information. */ 212*a9fa9459Szrj EXTR esym; 213*a9fa9459Szrj /* Nonzero if this symbol has been written out. */ 214*a9fa9459Szrj char written; 215*a9fa9459Szrj /* Nonzero if this symbol was referred to as small undefined. */ 216*a9fa9459Szrj char small; 217*a9fa9459Szrj }; 218*a9fa9459Szrj 219*a9fa9459Szrj /* ECOFF linker hash table. */ 220*a9fa9459Szrj 221*a9fa9459Szrj struct ecoff_link_hash_table 222*a9fa9459Szrj { 223*a9fa9459Szrj struct bfd_link_hash_table root; 224*a9fa9459Szrj }; 225*a9fa9459Szrj 226*a9fa9459Szrj /* Make an ECOFF object. */ 227*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_mkobject (bfd *); 228*a9fa9459Szrj 229*a9fa9459Szrj /* Read in the ECOFF symbolic debugging information. */ 230*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_slurp_symbolic_info 231*a9fa9459Szrj (bfd *, asection *, struct ecoff_debug_info *); 232*a9fa9459Szrj 233*a9fa9459Szrj /* Generic ECOFF BFD backend vectors. */ 234*a9fa9459Szrj 235*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_write_object_contents (bfd *); 236*a9fa9459Szrj 237*a9fa9459Szrj #define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup 238*a9fa9459Szrj #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info 239*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_new_section_hook 240*a9fa9459Szrj (bfd *, asection *); 241*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_get_section_contents 242*a9fa9459Szrj (bfd *, asection *, void * location, file_ptr, bfd_size_type); 243*a9fa9459Szrj 244*a9fa9459Szrj #define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section 245*a9fa9459Szrj #define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs 246*a9fa9459Szrj 247*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_bfd_copy_private_bfd_data 248*a9fa9459Szrj (bfd *, bfd *); 249*a9fa9459Szrj #define _bfd_ecoff_bfd_copy_private_section_data \ 250*a9fa9459Szrj _bfd_generic_bfd_copy_private_section_data 251*a9fa9459Szrj 252*a9fa9459Szrj #define _bfd_ecoff_bfd_copy_private_symbol_data \ 253*a9fa9459Szrj _bfd_generic_bfd_copy_private_symbol_data 254*a9fa9459Szrj 255*a9fa9459Szrj #define _bfd_ecoff_bfd_copy_private_header_data \ 256*a9fa9459Szrj _bfd_generic_bfd_copy_private_header_data 257*a9fa9459Szrj 258*a9fa9459Szrj #define _bfd_ecoff_bfd_print_private_bfd_data \ 259*a9fa9459Szrj _bfd_generic_bfd_print_private_bfd_data 260*a9fa9459Szrj 261*a9fa9459Szrj #define _bfd_ecoff_bfd_merge_private_bfd_data \ 262*a9fa9459Szrj _bfd_generic_bfd_merge_private_bfd_data 263*a9fa9459Szrj 264*a9fa9459Szrj #define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags 265*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_slurp_armap (bfd *); 266*a9fa9459Szrj #define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table 267*a9fa9459Szrj #define _bfd_ecoff_construct_extended_name_table \ 268*a9fa9459Szrj _bfd_archive_bsd_construct_extended_name_table 269*a9fa9459Szrj #define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname 270*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_write_armap 271*a9fa9459Szrj (bfd *, unsigned int, struct orl *, unsigned int, int); 272*a9fa9459Szrj #define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr 273*a9fa9459Szrj #define _bfd_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr 274*a9fa9459Szrj #define _bfd_ecoff_openr_next_archived_file \ 275*a9fa9459Szrj bfd_generic_openr_next_archived_file 276*a9fa9459Szrj #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index 277*a9fa9459Szrj #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt 278*a9fa9459Szrj #define _bfd_ecoff_update_armap_timestamp bfd_true 279*a9fa9459Szrj #define _bfd_ecoff_bfd_is_target_special_symbol \ 280*a9fa9459Szrj ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) 281*a9fa9459Szrj 282*a9fa9459Szrj extern long _bfd_ecoff_get_symtab_upper_bound (bfd *); 283*a9fa9459Szrj extern long _bfd_ecoff_canonicalize_symtab (bfd *, asymbol **); 284*a9fa9459Szrj extern asymbol *_bfd_ecoff_make_empty_symbol (bfd *); 285*a9fa9459Szrj extern void _bfd_ecoff_print_symbol 286*a9fa9459Szrj (bfd *, void *, asymbol *, bfd_print_symbol_type); 287*a9fa9459Szrj extern void _bfd_ecoff_get_symbol_info 288*a9fa9459Szrj (bfd *, asymbol *, symbol_info *); 289*a9fa9459Szrj #define _bfd_ecoff_get_symbol_version_string \ 290*a9fa9459Szrj _bfd_nosymbols_get_symbol_version_string 291*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_bfd_is_local_label_name 292*a9fa9459Szrj (bfd *, const char *); 293*a9fa9459Szrj #define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno 294*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_find_nearest_line 295*a9fa9459Szrj (bfd *, asymbol **, asection *, bfd_vma, 296*a9fa9459Szrj const char **, const char **, unsigned int *, unsigned int *); 297*a9fa9459Szrj #define _bfd_ecoff_find_line _bfd_nosymbols_find_line 298*a9fa9459Szrj #define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol 299*a9fa9459Szrj #define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols 300*a9fa9459Szrj #define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol 301*a9fa9459Szrj #define _bfd_ecoff_find_inliner_info _bfd_nosymbols_find_inliner_info 302*a9fa9459Szrj 303*a9fa9459Szrj #define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound 304*a9fa9459Szrj extern long _bfd_ecoff_canonicalize_reloc 305*a9fa9459Szrj (bfd *, asection *, arelent **, asymbol **symbols); 306*a9fa9459Szrj /* ecoff_bfd_reloc_type_lookup defined by backend. */ 307*a9fa9459Szrj 308*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_set_arch_mach 309*a9fa9459Szrj (bfd *, enum bfd_architecture, unsigned long); 310*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_set_section_contents 311*a9fa9459Szrj (bfd *, asection *, const void * location, file_ptr, bfd_size_type); 312*a9fa9459Szrj 313*a9fa9459Szrj extern int _bfd_ecoff_sizeof_headers (bfd *, struct bfd_link_info *); 314*a9fa9459Szrj /* ecoff_bfd_get_relocated_section_contents defined by backend. */ 315*a9fa9459Szrj /* ecoff_bfd_relax_section defined by backend. */ 316*a9fa9459Szrj extern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create 317*a9fa9459Szrj (bfd *); 318*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_bfd_link_add_symbols 319*a9fa9459Szrj (bfd *, struct bfd_link_info *); 320*a9fa9459Szrj #define _bfd_ecoff_bfd_link_just_syms _bfd_generic_link_just_syms 321*a9fa9459Szrj #define _bfd_ecoff_bfd_copy_link_hash_symbol_type \ 322*a9fa9459Szrj _bfd_generic_copy_link_hash_symbol_type 323*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_bfd_final_link 324*a9fa9459Szrj (bfd *, struct bfd_link_info *); 325*a9fa9459Szrj 326*a9fa9459Szrj /* Hook functions for the generic COFF section reading code. */ 327*a9fa9459Szrj 328*a9fa9459Szrj extern void * _bfd_ecoff_mkobject_hook (bfd *, void *, void *); 329*a9fa9459Szrj #define _bfd_ecoff_set_alignment_hook \ 330*a9fa9459Szrj ((void (*) (bfd *, asection *, void *)) bfd_void) 331*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_set_arch_mach_hook 332*a9fa9459Szrj (bfd *, void *); 333*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_no_long_sections 334*a9fa9459Szrj (bfd *abfd, int enable); 335*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_styp_to_sec_flags 336*a9fa9459Szrj (bfd *, void *, const char *, asection *, flagword *); 337*a9fa9459Szrj extern bfd_boolean _bfd_ecoff_slurp_symbol_table (bfd *); 338*a9fa9459Szrj 339*a9fa9459Szrj /* ECOFF auxiliary information swapping routines. These are the same 340*a9fa9459Szrj for all ECOFF targets, so they are defined in ecofflink.c. */ 341*a9fa9459Szrj 342*a9fa9459Szrj extern void _bfd_ecoff_swap_tir_in 343*a9fa9459Szrj (int, const struct tir_ext *, TIR *); 344*a9fa9459Szrj extern void _bfd_ecoff_swap_tir_out 345*a9fa9459Szrj (int, const TIR *, struct tir_ext *); 346*a9fa9459Szrj extern void _bfd_ecoff_swap_rndx_in 347*a9fa9459Szrj (int, const struct rndx_ext *, RNDXR *); 348*a9fa9459Szrj extern void _bfd_ecoff_swap_rndx_out 349*a9fa9459Szrj (int, const RNDXR *, struct rndx_ext *); 350