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