libcoff-in.h revision 33965
1/* BFD COFF object file private structure. 2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997 3 Free Software Foundation, Inc. 4 Written by Cygnus Support. 5 6** NOTE: libcoff.h is a GENERATED file. Don't change it; instead, 7** change libcoff-in.h or coffcode.h. 8 9This file is part of BFD, the Binary File Descriptor library. 10 11This program is free software; you can redistribute it and/or modify 12it under the terms of the GNU General Public License as published by 13the Free Software Foundation; either version 2 of the License, or 14(at your option) any later version. 15 16This program is distributed in the hope that it will be useful, 17but WITHOUT ANY WARRANTY; without even the implied warranty of 18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19GNU General Public License for more details. 20 21You should have received a copy of the GNU General Public License 22along with this program; if not, write to the Free Software 23Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 24 25#include "bfdlink.h" 26 27/* Object file tdata; access macros */ 28 29#define coff_data(bfd) ((bfd)->tdata.coff_obj_data) 30#define exec_hdr(bfd) (coff_data(bfd)->hdr) 31#define obj_pe(bfd) (coff_data(bfd)->pe) 32#define obj_symbols(bfd) (coff_data(bfd)->symbols) 33#define obj_sym_filepos(bfd) (coff_data(bfd)->sym_filepos) 34 35#define obj_relocbase(bfd) (coff_data(bfd)->relocbase) 36#define obj_raw_syments(bfd) (coff_data(bfd)->raw_syments) 37#define obj_raw_syment_count(bfd) (coff_data(bfd)->raw_syment_count) 38#define obj_convert(bfd) (coff_data(bfd)->conversion_table) 39#define obj_conv_table_size(bfd) (coff_data(bfd)->conv_table_size) 40 41#define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms) 42#define obj_coff_keep_syms(bfd) (coff_data (bfd)->keep_syms) 43#define obj_coff_strings(bfd) (coff_data (bfd)->strings) 44#define obj_coff_keep_strings(bfd) (coff_data (bfd)->keep_strings) 45#define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes) 46 47#define obj_coff_local_toc_table(bfd) (coff_data(bfd)->local_toc_sym_map) 48 49/* `Tdata' information kept for COFF files. */ 50 51typedef struct coff_tdata 52{ 53 struct coff_symbol_struct *symbols; /* symtab for input bfd */ 54 unsigned int *conversion_table; 55 int conv_table_size; 56 file_ptr sym_filepos; 57 58 struct coff_ptr_struct *raw_syments; 59 unsigned int raw_syment_count; 60 61 /* These are only valid once writing has begun */ 62 long int relocbase; 63 64 /* These members communicate important constants about the symbol table 65 to GDB's symbol-reading code. These `constants' unfortunately vary 66 from coff implementation to implementation... */ 67 unsigned local_n_btmask; 68 unsigned local_n_btshft; 69 unsigned local_n_tmask; 70 unsigned local_n_tshift; 71 unsigned local_symesz; 72 unsigned local_auxesz; 73 unsigned local_linesz; 74 75 /* The unswapped external symbols. May be NULL. Read by 76 _bfd_coff_get_external_symbols. */ 77 PTR external_syms; 78 /* If this is true, the external_syms may not be freed. */ 79 boolean keep_syms; 80 81 /* The string table. May be NULL. Read by 82 _bfd_coff_read_string_table. */ 83 char *strings; 84 /* If this is true, the strings may not be freed. */ 85 boolean keep_strings; 86 87 /* is this a PE format coff file */ 88 int pe; 89 /* Used by the COFF backend linker. */ 90 struct coff_link_hash_entry **sym_hashes; 91 92 /* used by the pe linker for PowerPC */ 93 int *local_toc_sym_map; 94 95 struct bfd_link_info *link_info; 96 97 /* Used by coff_find_nearest_line. */ 98 PTR line_info; 99} coff_data_type; 100 101/* Tdata for pe image files. */ 102typedef struct pe_tdata 103{ 104 coff_data_type coff; 105 struct internal_extra_pe_aouthdr pe_opthdr; 106 int dll; 107 int has_reloc_section; 108 boolean (*in_reloc_p) PARAMS((bfd *, reloc_howto_type *)); 109 flagword real_flags; 110} pe_data_type; 111 112#define pe_data(bfd) ((bfd)->tdata.pe_obj_data) 113 114/* Tdata for XCOFF files. */ 115 116struct xcoff_tdata 117{ 118 /* Basic COFF information. */ 119 coff_data_type coff; 120 121 /* True if a large a.out header should be generated. */ 122 boolean full_aouthdr; 123 124 /* TOC value. */ 125 bfd_vma toc; 126 127 /* Index of section holding TOC. */ 128 int sntoc; 129 130 /* Index of section holding entry point. */ 131 int snentry; 132 133 /* .text alignment from optional header. */ 134 int text_align_power; 135 136 /* .data alignment from optional header. */ 137 int data_align_power; 138 139 /* modtype from optional header. */ 140 short modtype; 141 142 /* cputype from optional header. */ 143 short cputype; 144 145 /* maxdata from optional header. */ 146 bfd_size_type maxdata; 147 148 /* maxstack from optional header. */ 149 bfd_size_type maxstack; 150 151 /* Used by the XCOFF backend linker. */ 152 asection **csects; 153 unsigned long *debug_indices; 154 unsigned int import_file_id; 155}; 156 157#define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data) 158 159/* We take the address of the first element of a asymbol to ensure that the 160 * macro is only ever applied to an asymbol. */ 161#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd))) 162 163/* The used_by_bfd field of a section may be set to a pointer to this 164 structure. */ 165 166struct coff_section_tdata 167{ 168 /* The relocs, swapped into COFF internal form. This may be NULL. */ 169 struct internal_reloc *relocs; 170 /* If this is true, the relocs entry may not be freed. */ 171 boolean keep_relocs; 172 /* The section contents. This may be NULL. */ 173 bfd_byte *contents; 174 /* If this is true, the contents entry may not be freed. */ 175 boolean keep_contents; 176 /* Information cached by coff_find_nearest_line. */ 177 bfd_vma offset; 178 unsigned int i; 179 const char *function; 180 int line_base; 181 /* A pointer used for .stab linking optimizations. */ 182 PTR stab_info; 183 /* Available for individual backends. */ 184 PTR tdata; 185}; 186 187/* An accessor macro for the coff_section_tdata structure. */ 188#define coff_section_data(abfd, sec) \ 189 ((struct coff_section_tdata *) (sec)->used_by_bfd) 190 191/* Tdata for sections in XCOFF files. This is used by the linker. */ 192 193struct xcoff_section_tdata 194{ 195 /* Used for XCOFF csects created by the linker; points to the real 196 XCOFF section which contains this csect. */ 197 asection *enclosing; 198 /* The lineno_count field for the enclosing section, because we are 199 going to clobber it there. */ 200 unsigned int lineno_count; 201 /* The first and one past the last symbol indices for symbols used 202 by this csect. */ 203 unsigned long first_symndx; 204 unsigned long last_symndx; 205}; 206 207/* An accessor macro the xcoff_section_tdata structure. */ 208#define xcoff_section_data(abfd, sec) \ 209 ((struct xcoff_section_tdata *) coff_section_data ((abfd), (sec))->tdata) 210 211/* Tdata for sections in PEI image files. */ 212 213struct pei_section_tdata 214{ 215 /* The virtual size of the section. */ 216 bfd_size_type virt_size; 217}; 218 219/* An accessor macro for the pei_section_tdata structure. */ 220#define pei_section_data(abfd, sec) \ 221 ((struct pei_section_tdata *) coff_section_data ((abfd), (sec))->tdata) 222 223/* COFF linker hash table entries. */ 224 225struct coff_link_hash_entry 226{ 227 struct bfd_link_hash_entry root; 228 229 /* Symbol index in output file. Set to -1 initially. Set to -2 if 230 there is a reloc against this symbol. */ 231 long indx; 232 233 /* Symbol type. */ 234 unsigned short type; 235 236 /* Symbol class. */ 237 unsigned char class; 238 239 /* Number of auxiliary entries. */ 240 char numaux; 241 242 /* BFD to take auxiliary entries from. */ 243 bfd *auxbfd; 244 245 /* Pointer to array of auxiliary entries, if any. */ 246 union internal_auxent *aux; 247}; 248 249/* COFF linker hash table. */ 250 251struct coff_link_hash_table 252{ 253 struct bfd_link_hash_table root; 254 /* A pointer to information used to link stabs in sections. */ 255 PTR stab_info; 256}; 257 258/* Look up an entry in a COFF linker hash table. */ 259 260#define coff_link_hash_lookup(table, string, create, copy, follow) \ 261 ((struct coff_link_hash_entry *) \ 262 bfd_link_hash_lookup (&(table)->root, (string), (create), \ 263 (copy), (follow))) 264 265/* Traverse a COFF linker hash table. */ 266 267#define coff_link_hash_traverse(table, func, info) \ 268 (bfd_link_hash_traverse \ 269 (&(table)->root, \ 270 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \ 271 (info))) 272 273/* Get the COFF linker hash table from a link_info structure. */ 274 275#define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash)) 276 277/* Functions in coffgen.c. */ 278extern const bfd_target *coff_object_p PARAMS ((bfd *)); 279extern struct sec *coff_section_from_bfd_index PARAMS ((bfd *, int)); 280extern long coff_get_symtab_upper_bound PARAMS ((bfd *)); 281extern long coff_get_symtab PARAMS ((bfd *, asymbol **)); 282extern int coff_count_linenumbers PARAMS ((bfd *)); 283extern struct coff_symbol_struct *coff_symbol_from PARAMS ((bfd *, asymbol *)); 284extern boolean coff_renumber_symbols PARAMS ((bfd *, int *)); 285extern void coff_mangle_symbols PARAMS ((bfd *)); 286extern boolean coff_write_symbols PARAMS ((bfd *)); 287extern boolean coff_write_linenumbers PARAMS ((bfd *)); 288extern alent *coff_get_lineno PARAMS ((bfd *, asymbol *)); 289extern asymbol *coff_section_symbol PARAMS ((bfd *, char *)); 290extern boolean _bfd_coff_get_external_symbols PARAMS ((bfd *)); 291extern const char *_bfd_coff_read_string_table PARAMS ((bfd *)); 292extern boolean _bfd_coff_free_symbols PARAMS ((bfd *)); 293extern struct coff_ptr_struct *coff_get_normalized_symtab PARAMS ((bfd *)); 294extern long coff_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); 295extern asymbol *coff_make_empty_symbol PARAMS ((bfd *)); 296extern void coff_print_symbol PARAMS ((bfd *, PTR filep, asymbol *, 297 bfd_print_symbol_type how)); 298extern void coff_get_symbol_info PARAMS ((bfd *, asymbol *, 299 symbol_info *ret)); 300extern boolean _bfd_coff_is_local_label_name PARAMS ((bfd *, const char *)); 301extern asymbol *coff_bfd_make_debug_symbol PARAMS ((bfd *, PTR, 302 unsigned long)); 303extern boolean coff_find_nearest_line PARAMS ((bfd *, 304 asection *, 305 asymbol **, 306 bfd_vma offset, 307 CONST char **filename_ptr, 308 CONST char **functionname_ptr, 309 unsigned int *line_ptr)); 310extern int coff_sizeof_headers PARAMS ((bfd *, boolean reloc)); 311extern boolean bfd_coff_reloc16_relax_section 312 PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *)); 313extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents 314 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, 315 bfd_byte *, boolean relocateable, asymbol **)); 316extern bfd_vma bfd_coff_reloc16_get_value PARAMS ((arelent *, 317 struct bfd_link_info *, 318 asection *)); 319extern void bfd_perform_slip PARAMS ((bfd *abfd, unsigned int slip, 320 asection *input_section, 321 bfd_vma val)); 322 323/* Functions and types in cofflink.c. */ 324 325#define STRING_SIZE_SIZE (4) 326 327/* We use a hash table to merge identical enum, struct, and union 328 definitions in the linker. */ 329 330/* Information we keep for a single element (an enum value, a 331 structure or union field) in the debug merge hash table. */ 332 333struct coff_debug_merge_element 334{ 335 /* Next element. */ 336 struct coff_debug_merge_element *next; 337 338 /* Name. */ 339 const char *name; 340 341 /* Type. */ 342 unsigned int type; 343 344 /* Symbol index for complex type. */ 345 long tagndx; 346}; 347 348/* A linked list of debug merge entries for a given name. */ 349 350struct coff_debug_merge_type 351{ 352 /* Next type with the same name. */ 353 struct coff_debug_merge_type *next; 354 355 /* Class of type. */ 356 int class; 357 358 /* Symbol index where this type is defined. */ 359 long indx; 360 361 /* List of elements. */ 362 struct coff_debug_merge_element *elements; 363}; 364 365/* Information we store in the debug merge hash table. */ 366 367struct coff_debug_merge_hash_entry 368{ 369 struct bfd_hash_entry root; 370 371 /* A list of types with this name. */ 372 struct coff_debug_merge_type *types; 373}; 374 375/* The debug merge hash table. */ 376 377struct coff_debug_merge_hash_table 378{ 379 struct bfd_hash_table root; 380}; 381 382/* Initialize a COFF debug merge hash table. */ 383 384#define coff_debug_merge_hash_table_init(table) \ 385 (bfd_hash_table_init (&(table)->root, _bfd_coff_debug_merge_hash_newfunc)) 386 387/* Free a COFF debug merge hash table. */ 388 389#define coff_debug_merge_hash_table_free(table) \ 390 (bfd_hash_table_free (&(table)->root)) 391 392/* Look up an entry in a COFF debug merge hash table. */ 393 394#define coff_debug_merge_hash_lookup(table, string, create, copy) \ 395 ((struct coff_debug_merge_hash_entry *) \ 396 bfd_hash_lookup (&(table)->root, (string), (create), (copy))) 397 398/* Information we keep for each section in the output file when doing 399 a relocateable link. */ 400 401struct coff_link_section_info 402{ 403 /* The relocs to be output. */ 404 struct internal_reloc *relocs; 405 /* For each reloc against a global symbol whose index was not known 406 when the reloc was handled, the global hash table entry. */ 407 struct coff_link_hash_entry **rel_hashes; 408}; 409 410/* Information that we pass around while doing the final link step. */ 411 412struct coff_final_link_info 413{ 414 /* General link information. */ 415 struct bfd_link_info *info; 416 /* Output BFD. */ 417 bfd *output_bfd; 418 /* Used to indicate failure in traversal routine. */ 419 boolean failed; 420 /* Hash table for long symbol names. */ 421 struct bfd_strtab_hash *strtab; 422 /* When doing a relocateable link, an array of information kept for 423 each output section, indexed by the target_index field. */ 424 struct coff_link_section_info *section_info; 425 /* Symbol index of last C_FILE symbol (-1 if none). */ 426 long last_file_index; 427 /* Contents of last C_FILE symbol. */ 428 struct internal_syment last_file; 429 /* Symbol index of first aux entry of last .bf symbol with an empty 430 endndx field (-1 if none). */ 431 long last_bf_index; 432 /* Contents of last_bf_index aux entry. */ 433 union internal_auxent last_bf; 434 /* Hash table used to merge debug information. */ 435 struct coff_debug_merge_hash_table debug_merge; 436 /* Buffer large enough to hold swapped symbols of any input file. */ 437 struct internal_syment *internal_syms; 438 /* Buffer large enough to hold sections of symbols of any input file. */ 439 asection **sec_ptrs; 440 /* Buffer large enough to hold output indices of symbols of any 441 input file. */ 442 long *sym_indices; 443 /* Buffer large enough to hold output symbols for any input file. */ 444 bfd_byte *outsyms; 445 /* Buffer large enough to hold external line numbers for any input 446 section. */ 447 bfd_byte *linenos; 448 /* Buffer large enough to hold any input section. */ 449 bfd_byte *contents; 450 /* Buffer large enough to hold external relocs of any input section. */ 451 bfd_byte *external_relocs; 452 /* Buffer large enough to hold swapped relocs of any input section. */ 453 struct internal_reloc *internal_relocs; 454}; 455 456extern struct bfd_hash_entry *_bfd_coff_link_hash_newfunc 457 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 458extern boolean _bfd_coff_link_hash_table_init 459 PARAMS ((struct coff_link_hash_table *, bfd *, 460 struct bfd_hash_entry *(*) (struct bfd_hash_entry *, 461 struct bfd_hash_table *, 462 const char *))); 463extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create 464 PARAMS ((bfd *)); 465extern const char *_bfd_coff_internal_syment_name 466 PARAMS ((bfd *, const struct internal_syment *, char *)); 467extern boolean _bfd_coff_link_add_symbols 468 PARAMS ((bfd *, struct bfd_link_info *)); 469extern boolean _bfd_coff_final_link 470 PARAMS ((bfd *, struct bfd_link_info *)); 471extern struct internal_reloc *_bfd_coff_read_internal_relocs 472 PARAMS ((bfd *, asection *, boolean, bfd_byte *, boolean, 473 struct internal_reloc *)); 474extern boolean _bfd_coff_generic_relocate_section 475 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 476 struct internal_reloc *, struct internal_syment *, asection **)); 477 478extern struct bfd_hash_entry *_bfd_coff_debug_merge_hash_newfunc 479 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 480extern boolean _bfd_coff_write_global_sym 481 PARAMS ((struct coff_link_hash_entry *, PTR)); 482extern boolean _bfd_coff_link_input_bfd 483 PARAMS ((struct coff_final_link_info *, bfd *)); 484extern boolean _bfd_coff_reloc_link_order 485 PARAMS ((bfd *, struct coff_final_link_info *, asection *, 486 struct bfd_link_order *)); 487 488 489#define coff_get_section_contents_in_window \ 490 _bfd_generic_get_section_contents_in_window 491 492/* Functions in xcofflink.c. */ 493 494extern long _bfd_xcoff_get_dynamic_symtab_upper_bound PARAMS ((bfd *)); 495extern long _bfd_xcoff_canonicalize_dynamic_symtab 496 PARAMS ((bfd *, asymbol **)); 497extern long _bfd_xcoff_get_dynamic_reloc_upper_bound PARAMS ((bfd *)); 498extern long _bfd_xcoff_canonicalize_dynamic_reloc 499 PARAMS ((bfd *, arelent **, asymbol **)); 500extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create 501 PARAMS ((bfd *)); 502extern boolean _bfd_xcoff_bfd_link_add_symbols 503 PARAMS ((bfd *, struct bfd_link_info *)); 504extern boolean _bfd_xcoff_bfd_final_link 505 PARAMS ((bfd *, struct bfd_link_info *)); 506extern boolean _bfd_ppc_xcoff_relocate_section 507 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 508 struct internal_reloc *, struct internal_syment *, asection **)); 509 510/* Functions in coff-ppc.c. FIXME: These are called be pe.em in the 511 linker, and so should start with bfd and be declared in bfd.h. */ 512 513extern boolean ppc_allocate_toc_section PARAMS ((struct bfd_link_info *)); 514extern boolean ppc_process_before_allocation 515 PARAMS ((bfd *, struct bfd_link_info *)); 516 517/* And more taken from the source .. */ 518 519