12159047fSniklas /* BFD ECOFF object file private structure. 2*007c2a45Smiod Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003 3c074d1c9Sdrahn Free Software Foundation, Inc. 42159047fSniklas Written by Ian Lance Taylor, Cygnus Support. 52159047fSniklas 62159047fSniklas This file is part of BFD, the Binary File Descriptor library. 72159047fSniklas 82159047fSniklas This program is free software; you can redistribute it and/or modify 92159047fSniklas it under the terms of the GNU General Public License as published by 102159047fSniklas the Free Software Foundation; either version 2 of the License, or 112159047fSniklas (at your option) any later version. 122159047fSniklas 132159047fSniklas This program is distributed in the hope that it will be useful, 142159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of 152159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162159047fSniklas GNU General Public License for more details. 172159047fSniklas 182159047fSniklas You should have received a copy of the GNU General Public License 192159047fSniklas along with this program; if not, write to the Free Software 202159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 212159047fSniklas 222159047fSniklas #include "bfdlink.h" 232159047fSniklas 242159047fSniklas #ifndef ECOFF_H 252159047fSniklas #include "coff/ecoff.h" 262159047fSniklas #endif 272159047fSniklas 282159047fSniklas /* This is the backend information kept for ECOFF files. This 292159047fSniklas structure is constant for a particular backend. The first element 302159047fSniklas is the COFF backend data structure, so that ECOFF targets can use 312159047fSniklas the generic COFF code. */ 322159047fSniklas 332159047fSniklas #define ecoff_backend(abfd) \ 342159047fSniklas ((struct ecoff_backend_data *) (abfd)->xvec->backend_data) 352159047fSniklas 362159047fSniklas struct ecoff_backend_data 372159047fSniklas { 382159047fSniklas /* COFF backend information. This must be the first field. */ 392159047fSniklas bfd_coff_backend_data coff; 402159047fSniklas /* Supported architecture. */ 412159047fSniklas enum bfd_architecture arch; 422159047fSniklas /* Initial portion of armap string. */ 432159047fSniklas const char *armap_start; 442159047fSniklas /* The page boundary used to align sections in a demand-paged 452159047fSniklas executable file. E.g., 0x1000. */ 462159047fSniklas bfd_vma round; 47c074d1c9Sdrahn /* TRUE if the .rdata section is part of the text segment, as on the 48c074d1c9Sdrahn Alpha. FALSE if .rdata is part of the data segment, as on the 492159047fSniklas MIPS. */ 50c074d1c9Sdrahn bfd_boolean rdata_in_text; 512159047fSniklas /* Bitsize of constructor entries. */ 522159047fSniklas unsigned int constructor_bitsize; 532159047fSniklas /* Reloc to use for constructor entries. */ 542159047fSniklas reloc_howto_type *constructor_reloc; 552159047fSniklas /* How to swap debugging information. */ 562159047fSniklas struct ecoff_debug_swap debug_swap; 572159047fSniklas /* External reloc size. */ 582159047fSniklas bfd_size_type external_reloc_size; 592159047fSniklas /* Reloc swapping functions. */ 602159047fSniklas void (*swap_reloc_in) PARAMS ((bfd *, PTR, struct internal_reloc *)); 612159047fSniklas void (*swap_reloc_out) PARAMS ((bfd *, const struct internal_reloc *, PTR)); 622159047fSniklas /* Backend reloc tweaking. */ 63c074d1c9Sdrahn void (*adjust_reloc_in) 64c074d1c9Sdrahn PARAMS ((bfd *, const struct internal_reloc *, arelent *)); 65c074d1c9Sdrahn void (*adjust_reloc_out) 66c074d1c9Sdrahn PARAMS ((bfd *, const arelent *, struct internal_reloc *)); 672159047fSniklas /* Relocate section contents while linking. */ 68c074d1c9Sdrahn bfd_boolean (*relocate_section) 69c074d1c9Sdrahn PARAMS ((bfd *output_bfd, struct bfd_link_info *, bfd *input_bfd, 70c074d1c9Sdrahn asection *input_section, bfd_byte *contents, 712159047fSniklas PTR external_relocs)); 722159047fSniklas /* Do final adjustments to filehdr and aouthdr. */ 73c074d1c9Sdrahn bfd_boolean (*adjust_headers) 74c074d1c9Sdrahn PARAMS ((bfd *, struct internal_filehdr *, struct internal_aouthdr *)); 75c88b1d6cSniklas /* Read an element from an archive at a given file position. This 76c88b1d6cSniklas is needed because OSF/1 3.2 uses a weird archive format. */ 77c88b1d6cSniklas bfd *(*get_elt_at_filepos) PARAMS ((bfd *, file_ptr)); 782159047fSniklas }; 792159047fSniklas 802159047fSniklas /* This is the target specific information kept for ECOFF files. */ 812159047fSniklas 822159047fSniklas #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) 832159047fSniklas 842159047fSniklas typedef struct ecoff_tdata 852159047fSniklas { 862159047fSniklas /* The reloc file position, set by 872159047fSniklas ecoff_compute_section_file_positions. */ 882159047fSniklas file_ptr reloc_filepos; 892159047fSniklas 902159047fSniklas /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */ 912159047fSniklas file_ptr sym_filepos; 922159047fSniklas 932159047fSniklas /* The start and end of the text segment. Only valid for an 942159047fSniklas existing file, not for one we are creating. */ 952159047fSniklas unsigned long text_start; 962159047fSniklas unsigned long text_end; 972159047fSniklas 982159047fSniklas /* The cached gp value. This is used when relocating. */ 992159047fSniklas bfd_vma gp; 1002159047fSniklas 1012159047fSniklas /* The maximum size of objects to optimize using gp. This is 1022159047fSniklas typically set by the -G option to the compiler, assembler or 1032159047fSniklas linker. */ 1042159047fSniklas unsigned int gp_size; 1052159047fSniklas 1062159047fSniklas /* The register masks. When linking, all the masks found in the 1072159047fSniklas input files are combined into the masks of the output file. 1082159047fSniklas These are not all used for all targets, but that's OK, because 1092159047fSniklas the relevant ones are the only ones swapped in and out. */ 1102159047fSniklas unsigned long gprmask; 1112159047fSniklas unsigned long fprmask; 1122159047fSniklas unsigned long cprmask[4]; 1132159047fSniklas 1142159047fSniklas /* The ECOFF symbolic debugging information. */ 1152159047fSniklas struct ecoff_debug_info debug_info; 1162159047fSniklas 1172159047fSniklas /* The unswapped ECOFF symbolic information. */ 1182159047fSniklas PTR raw_syments; 1192159047fSniklas 1202159047fSniklas /* The canonical BFD symbols. */ 1212159047fSniklas struct ecoff_symbol_struct *canonical_symbols; 1222159047fSniklas 1232159047fSniklas /* A mapping from external symbol numbers to entries in the linker 1242159047fSniklas hash table, used when linking. */ 1252159047fSniklas struct ecoff_link_hash_entry **sym_hashes; 1262159047fSniklas 1272159047fSniklas /* A mapping from reloc symbol indices to sections, used when 1282159047fSniklas linking. */ 1292159047fSniklas asection **symndx_to_section; 1302159047fSniklas 131c074d1c9Sdrahn /* TRUE if this BFD was written by the backend linker. */ 132c074d1c9Sdrahn bfd_boolean linker; 1332159047fSniklas 134c074d1c9Sdrahn /* TRUE if a warning that multiple global pointer values are 135c88b1d6cSniklas needed in the output binary was issued already. */ 136c074d1c9Sdrahn bfd_boolean issued_multiple_gp_warning; 137c88b1d6cSniklas 1382159047fSniklas /* Used by find_nearest_line entry point. The structure could be 1392159047fSniklas included directly in this one, but there's no point to wasting 1402159047fSniklas the memory just for the infrequently called find_nearest_line. */ 1412159047fSniklas struct ecoff_find_line *find_line_info; 1422159047fSniklas 1430c6d0228Sniklas /* Whether the .rdata section is in the text segment for this 1440c6d0228Sniklas particular ECOFF file. This is not valid until 1450c6d0228Sniklas ecoff_compute_section_file_positions is called. */ 146c074d1c9Sdrahn bfd_boolean rdata_in_text; 1470c6d0228Sniklas 1482159047fSniklas } ecoff_data_type; 1492159047fSniklas 1502159047fSniklas /* Each canonical asymbol really looks like this. */ 1512159047fSniklas 1522159047fSniklas typedef struct ecoff_symbol_struct 1532159047fSniklas { 1542159047fSniklas /* The actual symbol which the rest of BFD works with */ 1552159047fSniklas asymbol symbol; 1562159047fSniklas 1572159047fSniklas /* The fdr for this symbol. */ 1582159047fSniklas FDR *fdr; 1592159047fSniklas 160c074d1c9Sdrahn /* TRUE if this is a local symbol rather than an external one. */ 161c074d1c9Sdrahn bfd_boolean local; 1622159047fSniklas 1632159047fSniklas /* A pointer to the unswapped hidden information for this symbol. 1642159047fSniklas This is either a struct sym_ext or a struct ext_ext, depending on 1652159047fSniklas the value of the local field above. */ 1662159047fSniklas PTR native; 1672159047fSniklas } ecoff_symbol_type; 1682159047fSniklas 169c074d1c9Sdrahn /* We take the address of the first element of an asymbol to ensure that the 1702159047fSniklas macro is only ever applied to an asymbol. */ 1712159047fSniklas #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) 1722159047fSniklas 1732159047fSniklas /* We need to save the index of an external symbol when we write it 1742159047fSniklas out so that can set the symbol index correctly when we write out 1752159047fSniklas the relocs. */ 1762159047fSniklas #define ecoff_get_sym_index(symbol) ((symbol)->udata.i) 1772159047fSniklas #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx)) 1782159047fSniklas 1792159047fSniklas /* When generating MIPS embedded PIC code, the linker relaxes the code 1802159047fSniklas to turn PC relative branches into longer code sequences when the PC 1812159047fSniklas relative branch is out of range. This involves reading the relocs 1822159047fSniklas in bfd_relax_section as well as in bfd_final_link, and requires the 1832159047fSniklas code to keep track of which relocs have been expanded. A pointer 1842159047fSniklas to this structure is put in the used_by_bfd pointer of a section to 1852159047fSniklas keep track of this information. The user_by_bfd pointer will be 1862159047fSniklas NULL if the information was not needed. */ 1872159047fSniklas 1882159047fSniklas struct ecoff_section_tdata 1892159047fSniklas { 1902159047fSniklas /* The unswapped relocs for this section. These are stored in 1912159047fSniklas memory so the input file does not have to be read twice. */ 1922159047fSniklas PTR external_relocs; 1932159047fSniklas 1942159047fSniklas /* The contents of the section. These bytes may or may not be saved 1952159047fSniklas in memory, but if it is this is a pointer to them. */ 1962159047fSniklas bfd_byte *contents; 1972159047fSniklas 1982159047fSniklas /* Offset adjustments for PC relative branches. A number other than 1992159047fSniklas 1 is an addend for a PC relative branch, or a switch table entry 2002159047fSniklas which is the difference of two .text locations; this addend 2012159047fSniklas arises because the branch or difference crosses one or more 2022159047fSniklas branches which were expanded into a larger code sequence. A 1 2032159047fSniklas means that this branch was itself expanded into a larger code 2042159047fSniklas sequence. 1 is not a possible offset, since all offsets must be 2052159047fSniklas multiples of the instruction size, which is 4; also, the only 2062159047fSniklas relocs with non-zero offsets will be PC relative branches or 2072159047fSniklas switch table entries within the same object file. If this field 2082159047fSniklas is NULL, no branches were expanded and no offsets are required. 2092159047fSniklas Otherwise there are as many entries as there are relocs in the 2102159047fSniklas section, and the entry for any reloc that is not PC relative is 2112159047fSniklas zero. */ 2122159047fSniklas long *offsets; 213c88b1d6cSniklas 214c88b1d6cSniklas /* When producing an executable (i.e., final, non-relocatable link) 215c88b1d6cSniklas on the Alpha, we may need to use multiple global pointer values 216c88b1d6cSniklas to span the entire .lita section. In essence, we allow each 217c88b1d6cSniklas input .lita section to have its own gp value. To support this, 218c88b1d6cSniklas we need to keep track of the gp values that we picked for each 219c88b1d6cSniklas input .lita section . */ 220c88b1d6cSniklas bfd_vma gp; 2212159047fSniklas }; 2222159047fSniklas 2232159047fSniklas /* An accessor macro for the ecoff_section_tdata structure. */ 2242159047fSniklas #define ecoff_section_data(abfd, sec) \ 2252159047fSniklas ((struct ecoff_section_tdata *) (sec)->used_by_bfd) 2262159047fSniklas 2272159047fSniklas /* ECOFF linker hash table entries. */ 2282159047fSniklas 2292159047fSniklas struct ecoff_link_hash_entry 2302159047fSniklas { 2312159047fSniklas struct bfd_link_hash_entry root; 2322159047fSniklas /* Symbol index in output file. */ 2332159047fSniklas long indx; 2342159047fSniklas /* BFD that ext field value came from. */ 2352159047fSniklas bfd *abfd; 2362159047fSniklas /* ECOFF external symbol information. */ 2372159047fSniklas EXTR esym; 2382159047fSniklas /* Nonzero if this symbol has been written out. */ 2392159047fSniklas char written; 2402159047fSniklas /* Nonzero if this symbol was referred to as small undefined. */ 2412159047fSniklas char small; 2422159047fSniklas }; 2432159047fSniklas 2442159047fSniklas /* ECOFF linker hash table. */ 2452159047fSniklas 2462159047fSniklas struct ecoff_link_hash_table 2472159047fSniklas { 2482159047fSniklas struct bfd_link_hash_table root; 2492159047fSniklas }; 2502159047fSniklas 2512159047fSniklas /* Make an ECOFF object. */ 252c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_mkobject PARAMS ((bfd *)); 2532159047fSniklas 2542159047fSniklas /* Read in the ECOFF symbolic debugging information. */ 255c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_slurp_symbolic_info 2562159047fSniklas PARAMS ((bfd *, asection *, struct ecoff_debug_info *)); 2572159047fSniklas 2582159047fSniklas /* Generic ECOFF BFD backend vectors. */ 2592159047fSniklas 260c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_write_object_contents PARAMS ((bfd *abfd)); 2612159047fSniklas extern const bfd_target *_bfd_ecoff_archive_p PARAMS ((bfd *abfd)); 2622159047fSniklas 2632159047fSniklas #define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup 2642159047fSniklas #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info 265c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_new_section_hook 2662159047fSniklas PARAMS ((bfd *, asection *)); 267c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_get_section_contents 2682159047fSniklas PARAMS ((bfd *, asection *, PTR location, file_ptr, bfd_size_type)); 2692159047fSniklas 2702159047fSniklas #define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section 2712159047fSniklas 272c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_bfd_copy_private_bfd_data 273c074d1c9Sdrahn PARAMS ((bfd *, bfd *)); 2742159047fSniklas #define _bfd_ecoff_bfd_copy_private_section_data \ 2752159047fSniklas _bfd_generic_bfd_copy_private_section_data 2762159047fSniklas 2772159047fSniklas #define _bfd_ecoff_bfd_copy_private_symbol_data \ 2782159047fSniklas _bfd_generic_bfd_copy_private_symbol_data 2792159047fSniklas 2802159047fSniklas #define _bfd_ecoff_bfd_print_private_bfd_data \ 2812159047fSniklas _bfd_generic_bfd_print_private_bfd_data 2822159047fSniklas 2832159047fSniklas #define _bfd_ecoff_bfd_merge_private_bfd_data \ 2842159047fSniklas _bfd_generic_bfd_merge_private_bfd_data 2852159047fSniklas 2862159047fSniklas #define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags 287c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_slurp_armap PARAMS ((bfd *abfd)); 2882159047fSniklas #define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table 2892159047fSniklas #define _bfd_ecoff_construct_extended_name_table \ 2902159047fSniklas _bfd_archive_bsd_construct_extended_name_table 2912159047fSniklas #define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname 292c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_write_armap 2932159047fSniklas PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); 2942159047fSniklas #define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr 2952159047fSniklas #define _bfd_ecoff_openr_next_archived_file \ 2962159047fSniklas bfd_generic_openr_next_archived_file 297c88b1d6cSniklas #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index 2982159047fSniklas #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt 2992159047fSniklas #define _bfd_ecoff_update_armap_timestamp bfd_true 3002159047fSniklas 3012159047fSniklas extern long _bfd_ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd)); 302*007c2a45Smiod extern long _bfd_ecoff_canonicalize_symtab PARAMS ((bfd *abfd, asymbol **alocation)); 3032159047fSniklas extern asymbol *_bfd_ecoff_make_empty_symbol PARAMS ((bfd *abfd)); 3042159047fSniklas extern void _bfd_ecoff_print_symbol 3052159047fSniklas PARAMS ((bfd *, PTR filep, asymbol *, bfd_print_symbol_type)); 3062159047fSniklas extern void _bfd_ecoff_get_symbol_info 3072159047fSniklas PARAMS ((bfd *, asymbol *, symbol_info *)); 308c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_bfd_is_local_label_name 309b305b0f1Sespie PARAMS ((bfd *, const char *)); 3102159047fSniklas #define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno 311c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_find_nearest_line 3122159047fSniklas PARAMS ((bfd *, asection *, asymbol **, bfd_vma offset, 3132159047fSniklas const char **filename_ptr, const char **fnname_ptr, 3142159047fSniklas unsigned int *retline_ptr)); 3152159047fSniklas #define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol 3162159047fSniklas #define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols 3172159047fSniklas #define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol 3182159047fSniklas 3192159047fSniklas #define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound 3202159047fSniklas extern long _bfd_ecoff_canonicalize_reloc 3212159047fSniklas PARAMS ((bfd *, asection *, arelent **, asymbol **symbols)); 3222159047fSniklas /* ecoff_bfd_reloc_type_lookup defined by backend. */ 3232159047fSniklas 324c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_set_arch_mach 325c074d1c9Sdrahn PARAMS ((bfd *, enum bfd_architecture, unsigned long)); 326c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_set_section_contents 327*007c2a45Smiod PARAMS ((bfd *, asection *, const PTR location, file_ptr, bfd_size_type)); 3282159047fSniklas 329c074d1c9Sdrahn extern int _bfd_ecoff_sizeof_headers PARAMS ((bfd *abfd, bfd_boolean reloc)); 3302159047fSniklas /* ecoff_bfd_get_relocated_section_contents defined by backend. */ 3312159047fSniklas /* ecoff_bfd_relax_section defined by backend. */ 3322159047fSniklas extern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create 3332159047fSniklas PARAMS ((bfd *)); 334c074d1c9Sdrahn #define _bfd_ecoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free 335c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_bfd_link_add_symbols 3362159047fSniklas PARAMS ((bfd *, struct bfd_link_info *)); 337c074d1c9Sdrahn #define _bfd_ecoff_bfd_link_just_syms _bfd_generic_link_just_syms 338c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_bfd_final_link 3392159047fSniklas PARAMS ((bfd *, struct bfd_link_info *)); 3402159047fSniklas 3412159047fSniklas /* Hook functions for the generic COFF section reading code. */ 3422159047fSniklas 3432159047fSniklas extern PTR _bfd_ecoff_mkobject_hook PARAMS ((bfd *, PTR filehdr, PTR aouthdr)); 3442159047fSniklas #define _bfd_ecoff_set_alignment_hook \ 3452159047fSniklas ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void) 346c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_set_arch_mach_hook 347c074d1c9Sdrahn PARAMS ((bfd *abfd, PTR filehdr)); 348c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_styp_to_sec_flags 349c074d1c9Sdrahn PARAMS ((bfd *, PTR, const char *, asection *, flagword *)); 350c074d1c9Sdrahn extern bfd_boolean _bfd_ecoff_slurp_symbol_table PARAMS ((bfd *abfd)); 3512159047fSniklas 3522159047fSniklas /* ECOFF auxiliary information swapping routines. These are the same 3532159047fSniklas for all ECOFF targets, so they are defined in ecofflink.c. */ 3542159047fSniklas 3552159047fSniklas extern void _bfd_ecoff_swap_tir_in 3562159047fSniklas PARAMS ((int, const struct tir_ext *, TIR *)); 3572159047fSniklas extern void _bfd_ecoff_swap_tir_out 3582159047fSniklas PARAMS ((int, const TIR *, struct tir_ext *)); 3592159047fSniklas extern void _bfd_ecoff_swap_rndx_in 3602159047fSniklas PARAMS ((int, const struct rndx_ext *, RNDXR *)); 3612159047fSniklas extern void _bfd_ecoff_swap_rndx_out 3622159047fSniklas PARAMS ((int, const RNDXR *, struct rndx_ext *)); 363