133965Sjdp/* BFD ECOFF object file private structure. 2218822Sdim Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003, 2004, 3218822Sdim 2005, 2006 Free Software Foundation, Inc. 433965Sjdp Written by Ian Lance Taylor, Cygnus Support. 533965Sjdp 6218822Sdim This file is part of BFD, the Binary File Descriptor library. 733965Sjdp 8218822Sdim This program is free software; you can redistribute it and/or modify 9218822Sdim it under the terms of the GNU General Public License as published by 10218822Sdim the Free Software Foundation; either version 2 of the License, or 11218822Sdim (at your option) any later version. 1233965Sjdp 13218822Sdim This program is distributed in the hope that it will be useful, 14218822Sdim but WITHOUT ANY WARRANTY; without even the implied warranty of 15218822Sdim MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16218822Sdim GNU General Public License for more details. 1733965Sjdp 18218822Sdim You should have received a copy of the GNU General Public License 19218822Sdim along with this program; if not, write to the Free Software 20218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2133965Sjdp 2233965Sjdp#include "bfdlink.h" 2333965Sjdp 2433965Sjdp#ifndef ECOFF_H 2533965Sjdp#include "coff/ecoff.h" 2633965Sjdp#endif 2733965Sjdp 2833965Sjdp/* This is the backend information kept for ECOFF files. This 2933965Sjdp structure is constant for a particular backend. The first element 3033965Sjdp is the COFF backend data structure, so that ECOFF targets can use 3133965Sjdp the generic COFF code. */ 3233965Sjdp 3333965Sjdp#define ecoff_backend(abfd) \ 3433965Sjdp ((struct ecoff_backend_data *) (abfd)->xvec->backend_data) 3533965Sjdp 3633965Sjdpstruct ecoff_backend_data 3733965Sjdp{ 3833965Sjdp /* COFF backend information. This must be the first field. */ 3933965Sjdp bfd_coff_backend_data coff; 4033965Sjdp /* Supported architecture. */ 4133965Sjdp enum bfd_architecture arch; 4233965Sjdp /* Initial portion of armap string. */ 4333965Sjdp const char *armap_start; 4433965Sjdp /* The page boundary used to align sections in a demand-paged 4533965Sjdp executable file. E.g., 0x1000. */ 4633965Sjdp bfd_vma round; 47130561Sobrien /* TRUE if the .rdata section is part of the text segment, as on the 48130561Sobrien Alpha. FALSE if .rdata is part of the data segment, as on the 4933965Sjdp MIPS. */ 50130561Sobrien bfd_boolean rdata_in_text; 5133965Sjdp /* Bitsize of constructor entries. */ 5233965Sjdp unsigned int constructor_bitsize; 5333965Sjdp /* Reloc to use for constructor entries. */ 5433965Sjdp reloc_howto_type *constructor_reloc; 5533965Sjdp /* How to swap debugging information. */ 5633965Sjdp struct ecoff_debug_swap debug_swap; 5733965Sjdp /* External reloc size. */ 5833965Sjdp bfd_size_type external_reloc_size; 5933965Sjdp /* Reloc swapping functions. */ 60218822Sdim void (*swap_reloc_in) (bfd *, void *, struct internal_reloc *); 61218822Sdim void (*swap_reloc_out) (bfd *, const struct internal_reloc *, void *); 6233965Sjdp /* Backend reloc tweaking. */ 63130561Sobrien void (*adjust_reloc_in) 64218822Sdim (bfd *, const struct internal_reloc *, arelent *); 65130561Sobrien void (*adjust_reloc_out) 66218822Sdim (bfd *, const arelent *, struct internal_reloc *); 6733965Sjdp /* Relocate section contents while linking. */ 68130561Sobrien bfd_boolean (*relocate_section) 69218822Sdim (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, void *); 7033965Sjdp /* Do final adjustments to filehdr and aouthdr. */ 71130561Sobrien bfd_boolean (*adjust_headers) 72218822Sdim (bfd *, struct internal_filehdr *, struct internal_aouthdr *); 7333965Sjdp /* Read an element from an archive at a given file position. This 7433965Sjdp is needed because OSF/1 3.2 uses a weird archive format. */ 75218822Sdim bfd *(*get_elt_at_filepos) (bfd *, file_ptr); 7633965Sjdp}; 7733965Sjdp 7833965Sjdp/* This is the target specific information kept for ECOFF files. */ 7933965Sjdp 8033965Sjdp#define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) 8133965Sjdp 8233965Sjdptypedef struct ecoff_tdata 8333965Sjdp{ 8433965Sjdp /* The reloc file position, set by 8533965Sjdp ecoff_compute_section_file_positions. */ 8633965Sjdp file_ptr reloc_filepos; 8733965Sjdp 8833965Sjdp /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */ 8933965Sjdp file_ptr sym_filepos; 9033965Sjdp 9133965Sjdp /* The start and end of the text segment. Only valid for an 9233965Sjdp existing file, not for one we are creating. */ 9333965Sjdp unsigned long text_start; 9433965Sjdp unsigned long text_end; 9533965Sjdp 9633965Sjdp /* The cached gp value. This is used when relocating. */ 9733965Sjdp bfd_vma gp; 9833965Sjdp 9933965Sjdp /* The maximum size of objects to optimize using gp. This is 10033965Sjdp typically set by the -G option to the compiler, assembler or 10133965Sjdp linker. */ 10233965Sjdp unsigned int gp_size; 10333965Sjdp 10433965Sjdp /* The register masks. When linking, all the masks found in the 10533965Sjdp input files are combined into the masks of the output file. 10633965Sjdp These are not all used for all targets, but that's OK, because 10733965Sjdp the relevant ones are the only ones swapped in and out. */ 10833965Sjdp unsigned long gprmask; 10933965Sjdp unsigned long fprmask; 11033965Sjdp unsigned long cprmask[4]; 11133965Sjdp 11233965Sjdp /* The ECOFF symbolic debugging information. */ 11333965Sjdp struct ecoff_debug_info debug_info; 11433965Sjdp 11533965Sjdp /* The unswapped ECOFF symbolic information. */ 116218822Sdim void * raw_syments; 11733965Sjdp 11833965Sjdp /* The canonical BFD symbols. */ 11933965Sjdp struct ecoff_symbol_struct *canonical_symbols; 12033965Sjdp 12133965Sjdp /* A mapping from external symbol numbers to entries in the linker 12233965Sjdp hash table, used when linking. */ 12333965Sjdp struct ecoff_link_hash_entry **sym_hashes; 12433965Sjdp 12533965Sjdp /* A mapping from reloc symbol indices to sections, used when 12633965Sjdp linking. */ 12733965Sjdp asection **symndx_to_section; 12833965Sjdp 129130561Sobrien /* TRUE if this BFD was written by the backend linker. */ 130130561Sobrien bfd_boolean linker; 13133965Sjdp 132130561Sobrien /* TRUE if a warning that multiple global pointer values are 13333965Sjdp needed in the output binary was issued already. */ 134130561Sobrien bfd_boolean issued_multiple_gp_warning; 13533965Sjdp 13633965Sjdp /* Used by find_nearest_line entry point. The structure could be 13733965Sjdp included directly in this one, but there's no point to wasting 13833965Sjdp the memory just for the infrequently called find_nearest_line. */ 13933965Sjdp struct ecoff_find_line *find_line_info; 14033965Sjdp 14133965Sjdp /* Whether the .rdata section is in the text segment for this 14233965Sjdp particular ECOFF file. This is not valid until 14333965Sjdp ecoff_compute_section_file_positions is called. */ 144130561Sobrien bfd_boolean rdata_in_text; 14533965Sjdp 14633965Sjdp} ecoff_data_type; 14733965Sjdp 14833965Sjdp/* Each canonical asymbol really looks like this. */ 14933965Sjdp 15033965Sjdptypedef struct ecoff_symbol_struct 15133965Sjdp{ 15233965Sjdp /* The actual symbol which the rest of BFD works with */ 15333965Sjdp asymbol symbol; 15433965Sjdp 15533965Sjdp /* The fdr for this symbol. */ 15633965Sjdp FDR *fdr; 15733965Sjdp 158130561Sobrien /* TRUE if this is a local symbol rather than an external one. */ 159130561Sobrien bfd_boolean local; 16033965Sjdp 16133965Sjdp /* A pointer to the unswapped hidden information for this symbol. 16233965Sjdp This is either a struct sym_ext or a struct ext_ext, depending on 16333965Sjdp the value of the local field above. */ 164218822Sdim void * native; 16533965Sjdp} ecoff_symbol_type; 16633965Sjdp 16789857Sobrien/* We take the address of the first element of an asymbol to ensure that the 16833965Sjdp macro is only ever applied to an asymbol. */ 16933965Sjdp#define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) 17033965Sjdp 17133965Sjdp/* We need to save the index of an external symbol when we write it 17233965Sjdp out so that can set the symbol index correctly when we write out 17333965Sjdp the relocs. */ 17433965Sjdp#define ecoff_get_sym_index(symbol) ((symbol)->udata.i) 17533965Sjdp#define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx)) 17633965Sjdp 177218822Sdim/* A pointer to this structure is put in the used_by_bfd pointer of 178218822Sdim a section to keep track of any per-section data. 179218822Sdim The user_by_bfd pointer will be NULL if the information was not 180218822Sdim needed. */ 18133965Sjdp 18233965Sjdpstruct ecoff_section_tdata 18333965Sjdp{ 18433965Sjdp /* When producing an executable (i.e., final, non-relocatable link) 18533965Sjdp on the Alpha, we may need to use multiple global pointer values 18633965Sjdp to span the entire .lita section. In essence, we allow each 18733965Sjdp input .lita section to have its own gp value. To support this, 18833965Sjdp we need to keep track of the gp values that we picked for each 18933965Sjdp input .lita section . */ 19033965Sjdp bfd_vma gp; 19133965Sjdp}; 19233965Sjdp 19333965Sjdp/* An accessor macro for the ecoff_section_tdata structure. */ 19433965Sjdp#define ecoff_section_data(abfd, sec) \ 19533965Sjdp ((struct ecoff_section_tdata *) (sec)->used_by_bfd) 19633965Sjdp 19733965Sjdp/* ECOFF linker hash table entries. */ 19833965Sjdp 19933965Sjdpstruct ecoff_link_hash_entry 20033965Sjdp{ 20133965Sjdp struct bfd_link_hash_entry root; 20233965Sjdp /* Symbol index in output file. */ 20333965Sjdp long indx; 20433965Sjdp /* BFD that ext field value came from. */ 20533965Sjdp bfd *abfd; 20633965Sjdp /* ECOFF external symbol information. */ 20733965Sjdp EXTR esym; 20833965Sjdp /* Nonzero if this symbol has been written out. */ 20933965Sjdp char written; 21033965Sjdp /* Nonzero if this symbol was referred to as small undefined. */ 21133965Sjdp char small; 21233965Sjdp}; 21333965Sjdp 21433965Sjdp/* ECOFF linker hash table. */ 21533965Sjdp 21633965Sjdpstruct ecoff_link_hash_table 21733965Sjdp{ 21833965Sjdp struct bfd_link_hash_table root; 21933965Sjdp}; 22033965Sjdp 22133965Sjdp/* Make an ECOFF object. */ 222218822Sdimextern bfd_boolean _bfd_ecoff_mkobject (bfd *); 22333965Sjdp 22433965Sjdp/* Read in the ECOFF symbolic debugging information. */ 225130561Sobrienextern bfd_boolean _bfd_ecoff_slurp_symbolic_info 226218822Sdim (bfd *, asection *, struct ecoff_debug_info *); 22733965Sjdp 22833965Sjdp/* Generic ECOFF BFD backend vectors. */ 22933965Sjdp 230218822Sdimextern bfd_boolean _bfd_ecoff_write_object_contents (bfd *); 231218822Sdimextern const bfd_target *_bfd_ecoff_archive_p (bfd *); 23233965Sjdp 23333965Sjdp#define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup 23433965Sjdp#define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info 235130561Sobrienextern bfd_boolean _bfd_ecoff_new_section_hook 236218822Sdim (bfd *, asection *); 237130561Sobrienextern bfd_boolean _bfd_ecoff_get_section_contents 238218822Sdim (bfd *, asection *, void * location, file_ptr, bfd_size_type); 23933965Sjdp 24033965Sjdp#define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section 24133965Sjdp 242130561Sobrienextern bfd_boolean _bfd_ecoff_bfd_copy_private_bfd_data 243218822Sdim (bfd *, bfd *); 24433965Sjdp#define _bfd_ecoff_bfd_copy_private_section_data \ 24533965Sjdp _bfd_generic_bfd_copy_private_section_data 24633965Sjdp 24733965Sjdp#define _bfd_ecoff_bfd_copy_private_symbol_data \ 24833965Sjdp _bfd_generic_bfd_copy_private_symbol_data 24933965Sjdp 250218822Sdim#define _bfd_ecoff_bfd_copy_private_header_data \ 251218822Sdim _bfd_generic_bfd_copy_private_header_data 252218822Sdim 25333965Sjdp#define _bfd_ecoff_bfd_print_private_bfd_data \ 25433965Sjdp _bfd_generic_bfd_print_private_bfd_data 25533965Sjdp 25633965Sjdp#define _bfd_ecoff_bfd_merge_private_bfd_data \ 25733965Sjdp _bfd_generic_bfd_merge_private_bfd_data 25833965Sjdp 25933965Sjdp#define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags 260218822Sdimextern bfd_boolean _bfd_ecoff_slurp_armap (bfd *); 26133965Sjdp#define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table 26233965Sjdp#define _bfd_ecoff_construct_extended_name_table \ 26333965Sjdp _bfd_archive_bsd_construct_extended_name_table 26433965Sjdp#define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname 265130561Sobrienextern bfd_boolean _bfd_ecoff_write_armap 266218822Sdim (bfd *, unsigned int, struct orl *, unsigned int, int); 26733965Sjdp#define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr 26833965Sjdp#define _bfd_ecoff_openr_next_archived_file \ 26933965Sjdp bfd_generic_openr_next_archived_file 27033965Sjdp#define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index 27133965Sjdp#define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt 27233965Sjdp#define _bfd_ecoff_update_armap_timestamp bfd_true 273218822Sdim#define _bfd_ecoff_bfd_is_target_special_symbol \ 274218822Sdim ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) 27533965Sjdp 276218822Sdimextern long _bfd_ecoff_get_symtab_upper_bound (bfd *); 277218822Sdimextern long _bfd_ecoff_canonicalize_symtab (bfd *, asymbol **); 278218822Sdimextern asymbol *_bfd_ecoff_make_empty_symbol (bfd *); 27933965Sjdpextern void _bfd_ecoff_print_symbol 280218822Sdim (bfd *, void *, asymbol *, bfd_print_symbol_type); 28133965Sjdpextern void _bfd_ecoff_get_symbol_info 282218822Sdim (bfd *, asymbol *, symbol_info *); 283130561Sobrienextern bfd_boolean _bfd_ecoff_bfd_is_local_label_name 284218822Sdim (bfd *, const char *); 28533965Sjdp#define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno 286130561Sobrienextern bfd_boolean _bfd_ecoff_find_nearest_line 287218822Sdim (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **, 288218822Sdim unsigned int *); 28933965Sjdp#define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol 29033965Sjdp#define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols 29133965Sjdp#define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol 292218822Sdim#define _bfd_ecoff_find_inliner_info _bfd_nosymbols_find_inliner_info 29333965Sjdp 29433965Sjdp#define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound 29533965Sjdpextern long _bfd_ecoff_canonicalize_reloc 296218822Sdim (bfd *, asection *, arelent **, asymbol **symbols); 29733965Sjdp/* ecoff_bfd_reloc_type_lookup defined by backend. */ 29833965Sjdp 299130561Sobrienextern bfd_boolean _bfd_ecoff_set_arch_mach 300218822Sdim (bfd *, enum bfd_architecture, unsigned long); 301130561Sobrienextern bfd_boolean _bfd_ecoff_set_section_contents 302218822Sdim (bfd *, asection *, const void * location, file_ptr, bfd_size_type); 30333965Sjdp 304218822Sdimextern int _bfd_ecoff_sizeof_headers (bfd *, struct bfd_link_info *); 30533965Sjdp/* ecoff_bfd_get_relocated_section_contents defined by backend. */ 30633965Sjdp/* ecoff_bfd_relax_section defined by backend. */ 30733965Sjdpextern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create 308218822Sdim (bfd *); 309104834Sobrien#define _bfd_ecoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free 310130561Sobrienextern bfd_boolean _bfd_ecoff_bfd_link_add_symbols 311218822Sdim (bfd *, struct bfd_link_info *); 312104834Sobrien#define _bfd_ecoff_bfd_link_just_syms _bfd_generic_link_just_syms 313130561Sobrienextern bfd_boolean _bfd_ecoff_bfd_final_link 314218822Sdim (bfd *, struct bfd_link_info *); 31533965Sjdp 31633965Sjdp/* Hook functions for the generic COFF section reading code. */ 31733965Sjdp 318218822Sdimextern void * _bfd_ecoff_mkobject_hook (bfd *, void *, void *); 31933965Sjdp#define _bfd_ecoff_set_alignment_hook \ 320218822Sdim ((void (*) (bfd *, asection *, void *)) bfd_void) 321130561Sobrienextern bfd_boolean _bfd_ecoff_set_arch_mach_hook 322218822Sdim (bfd *, void *); 323130561Sobrienextern bfd_boolean _bfd_ecoff_styp_to_sec_flags 324218822Sdim (bfd *, void *, const char *, asection *, flagword *); 325218822Sdimextern bfd_boolean _bfd_ecoff_slurp_symbol_table (bfd *); 32633965Sjdp 32733965Sjdp/* ECOFF auxiliary information swapping routines. These are the same 32833965Sjdp for all ECOFF targets, so they are defined in ecofflink.c. */ 32933965Sjdp 33033965Sjdpextern void _bfd_ecoff_swap_tir_in 331218822Sdim (int, const struct tir_ext *, TIR *); 33233965Sjdpextern void _bfd_ecoff_swap_tir_out 333218822Sdim (int, const TIR *, struct tir_ext *); 33433965Sjdpextern void _bfd_ecoff_swap_rndx_in 335218822Sdim (int, const struct rndx_ext *, RNDXR *); 33633965Sjdpextern void _bfd_ecoff_swap_rndx_out 337218822Sdim (int, const RNDXR *, struct rndx_ext *); 338