libcoff.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically
  2. generated from "libcoff-in.h" and "coffcode.h".
  3. Run "make headers" in your build bfd/ to regenerate. */
  4. /* BFD COFF object file private structure.
  5. Copyright (C) 1990-2015 Free Software Foundation, Inc.
  6. Written by Cygnus Support.
  7. This file is part of BFD, the Binary File Descriptor library.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or
  11. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. MA 02110-1301, USA. */
  20. #include "bfdlink.h"
  21. #include "coff-bfd.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Object file tdata; access macros. */
  26. #define coff_data(bfd) ((bfd)->tdata.coff_obj_data)
  27. #define obj_pe(bfd) (coff_data (bfd)->pe)
  28. #define obj_symbols(bfd) (coff_data (bfd)->symbols)
  29. #define obj_sym_filepos(bfd) (coff_data (bfd)->sym_filepos)
  30. #define obj_relocbase(bfd) (coff_data (bfd)->relocbase)
  31. #define obj_raw_syments(bfd) (coff_data (bfd)->raw_syments)
  32. #define obj_raw_syment_count(bfd) (coff_data (bfd)->raw_syment_count)
  33. #define obj_convert(bfd) (coff_data (bfd)->conversion_table)
  34. #define obj_conv_table_size(bfd) (coff_data (bfd)->conv_table_size)
  35. #define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms)
  36. #define obj_coff_keep_syms(bfd) (coff_data (bfd)->keep_syms)
  37. #define obj_coff_strings(bfd) (coff_data (bfd)->strings)
  38. #define obj_coff_strings_len(bfd) (coff_data (bfd)->strings_len)
  39. #define obj_coff_keep_strings(bfd) (coff_data (bfd)->keep_strings)
  40. #define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes)
  41. #define obj_coff_strings_written(bfd) (coff_data (bfd)->strings_written)
  42. #define obj_coff_local_toc_table(bfd) (coff_data (bfd)->local_toc_sym_map)
  43. /* `Tdata' information kept for COFF files. */
  44. typedef struct coff_tdata
  45. {
  46. struct coff_symbol_struct *symbols; /* Symtab for input bfd. */
  47. unsigned int *conversion_table;
  48. int conv_table_size;
  49. file_ptr sym_filepos;
  50. struct coff_ptr_struct *raw_syments;
  51. unsigned long raw_syment_count;
  52. /* These are only valid once writing has begun. */
  53. unsigned long int relocbase;
  54. /* These members communicate important constants about the symbol table
  55. to GDB's symbol-reading code. These `constants' unfortunately vary
  56. from coff implementation to implementation... */
  57. unsigned local_n_btmask;
  58. unsigned local_n_btshft;
  59. unsigned local_n_tmask;
  60. unsigned local_n_tshift;
  61. unsigned local_symesz;
  62. unsigned local_auxesz;
  63. unsigned local_linesz;
  64. /* The unswapped external symbols. May be NULL. Read by
  65. _bfd_coff_get_external_symbols. */
  66. void * external_syms;
  67. /* If this is TRUE, the external_syms may not be freed. */
  68. bfd_boolean keep_syms;
  69. /* The string table. May be NULL. Read by
  70. _bfd_coff_read_string_table. */
  71. char *strings;
  72. /* The length of the strings table. For error checking. */
  73. bfd_size_type strings_len;
  74. /* If this is TRUE, the strings may not be freed. */
  75. bfd_boolean keep_strings;
  76. /* If this is TRUE, the strings have been written out already. */
  77. bfd_boolean strings_written;
  78. /* Is this a PE format coff file? */
  79. int pe;
  80. /* Used by the COFF backend linker. */
  81. struct coff_link_hash_entry **sym_hashes;
  82. /* Used by the pe linker for PowerPC. */
  83. int *local_toc_sym_map;
  84. struct bfd_link_info *link_info;
  85. /* Used by coff_find_nearest_line. */
  86. void * line_info;
  87. /* A place to stash dwarf2 info for this bfd. */
  88. void * dwarf2_find_line_info;
  89. /* The timestamp from the COFF file header. */
  90. long timestamp;
  91. /* Copy of some of the f_flags bits in the COFF filehdr structure,
  92. used by ARM code. */
  93. flagword flags;
  94. /* coff-stgo32 EXE stub header after BFD tdata has been allocated. Its data
  95. is kept in internal_filehdr.go32stub beforehand. */
  96. char *go32stub;
  97. } coff_data_type;
  98. /* Tdata for pe image files. */
  99. typedef struct pe_tdata
  100. {
  101. coff_data_type coff;
  102. struct internal_extra_pe_aouthdr pe_opthdr;
  103. int dll;
  104. int has_reloc_section;
  105. int dont_strip_reloc;
  106. bfd_boolean insert_timestamp;
  107. bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *);
  108. flagword real_flags;
  109. /* Build-id info. */
  110. struct
  111. {
  112. bfd_boolean (*after_write_object_contents) (bfd *);
  113. const char *style;
  114. asection *sec;
  115. } build_id;
  116. } pe_data_type;
  117. #define pe_data(bfd) ((bfd)->tdata.pe_obj_data)
  118. /* Tdata for XCOFF files. */
  119. struct xcoff_tdata
  120. {
  121. /* Basic COFF information. */
  122. coff_data_type coff;
  123. /* TRUE if this is an XCOFF64 file. */
  124. bfd_boolean xcoff64;
  125. /* TRUE if a large a.out header should be generated. */
  126. bfd_boolean full_aouthdr;
  127. /* TOC value. */
  128. bfd_vma toc;
  129. /* Index of section holding TOC. */
  130. int sntoc;
  131. /* Index of section holding entry point. */
  132. int snentry;
  133. /* .text alignment from optional header. */
  134. int text_align_power;
  135. /* .data alignment from optional header. */
  136. int data_align_power;
  137. /* modtype from optional header. */
  138. short modtype;
  139. /* cputype from optional header. */
  140. short cputype;
  141. /* maxdata from optional header. */
  142. bfd_vma maxdata;
  143. /* maxstack from optional header. */
  144. bfd_vma maxstack;
  145. /* Used by the XCOFF backend linker. */
  146. asection **csects;
  147. long *debug_indices;
  148. unsigned int *lineno_counts;
  149. unsigned int import_file_id;
  150. };
  151. #define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
  152. /* We take the address of the first element of an asymbol to ensure that the
  153. macro is only ever applied to an asymbol. */
  154. #define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
  155. /* Tdata for sections in XCOFF files. This is used by the linker. */
  156. struct xcoff_section_tdata
  157. {
  158. /* Used for XCOFF csects created by the linker; points to the real
  159. XCOFF section which contains this csect. */
  160. asection *enclosing;
  161. /* The lineno_count field for the enclosing section, because we are
  162. going to clobber it there. */
  163. unsigned int lineno_count;
  164. /* The first and last symbol indices for symbols used by this csect. */
  165. unsigned long first_symndx;
  166. unsigned long last_symndx;
  167. };
  168. /* An accessor macro the xcoff_section_tdata structure. */
  169. #define xcoff_section_data(abfd, sec) \
  170. ((struct xcoff_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
  171. /* Tdata for sections in PE files. */
  172. struct pei_section_tdata
  173. {
  174. /* The virtual size of the section. */
  175. bfd_size_type virt_size;
  176. /* The PE section flags. */
  177. long pe_flags;
  178. };
  179. /* An accessor macro for the pei_section_tdata structure. */
  180. #define pei_section_data(abfd, sec) \
  181. ((struct pei_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
  182. /* COFF linker hash table entries. */
  183. struct coff_link_hash_entry
  184. {
  185. struct bfd_link_hash_entry root;
  186. /* Symbol index in output file. Set to -1 initially. Set to -2 if
  187. there is a reloc against this symbol. */
  188. long indx;
  189. /* Symbol type. */
  190. unsigned short type;
  191. /* Symbol class. */
  192. unsigned char symbol_class;
  193. /* Number of auxiliary entries. */
  194. char numaux;
  195. /* BFD to take auxiliary entries from. */
  196. bfd *auxbfd;
  197. /* Pointer to array of auxiliary entries, if any. */
  198. union internal_auxent *aux;
  199. /* Flag word; legal values follow. */
  200. unsigned short coff_link_hash_flags;
  201. /* Symbol is a PE section symbol. */
  202. #define COFF_LINK_HASH_PE_SECTION_SYMBOL (01)
  203. };
  204. /* COFF linker hash table. */
  205. struct coff_link_hash_table
  206. {
  207. struct bfd_link_hash_table root;
  208. /* A pointer to information used to link stabs in sections. */
  209. struct stab_info stab_info;
  210. };
  211. struct coff_reloc_cookie
  212. {
  213. struct internal_reloc * rels;
  214. struct internal_reloc * rel;
  215. struct internal_reloc * relend;
  216. struct coff_symbol_struct * symbols; /* Symtab for input bfd. */
  217. bfd * abfd;
  218. struct coff_link_hash_entry ** sym_hashes;
  219. };
  220. /* Look up an entry in a COFF linker hash table. */
  221. #define coff_link_hash_lookup(table, string, create, copy, follow) \
  222. ((struct coff_link_hash_entry *) \
  223. bfd_link_hash_lookup (&(table)->root, (string), (create), \
  224. (copy), (follow)))
  225. /* Traverse a COFF linker hash table. */
  226. #define coff_link_hash_traverse(table, func, info) \
  227. (bfd_link_hash_traverse \
  228. (&(table)->root, \
  229. (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func), \
  230. (info)))
  231. /* Get the COFF linker hash table from a link_info structure. */
  232. #define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
  233. /* Functions in coffgen.c. */
  234. extern const bfd_target *coff_object_p
  235. (bfd *);
  236. extern struct bfd_section *coff_section_from_bfd_index
  237. (bfd *, int);
  238. extern long coff_get_symtab_upper_bound
  239. (bfd *);
  240. extern long coff_canonicalize_symtab
  241. (bfd *, asymbol **);
  242. extern int coff_count_linenumbers
  243. (bfd *);
  244. extern bfd_boolean coff_renumber_symbols
  245. (bfd *, int *);
  246. extern void coff_mangle_symbols
  247. (bfd *);
  248. extern bfd_boolean coff_write_symbols
  249. (bfd *);
  250. extern bfd_boolean coff_write_alien_symbol
  251. (bfd *, asymbol *, struct internal_syment *, bfd_vma *,
  252. bfd_size_type *, asection **, bfd_size_type *);
  253. extern bfd_boolean coff_write_linenumbers
  254. (bfd *);
  255. extern alent *coff_get_lineno
  256. (bfd *, asymbol *);
  257. extern asymbol *coff_section_symbol
  258. (bfd *, char *);
  259. extern bfd_boolean _bfd_coff_get_external_symbols
  260. (bfd *);
  261. extern const char *_bfd_coff_read_string_table
  262. (bfd *);
  263. extern bfd_boolean _bfd_coff_free_symbols
  264. (bfd *);
  265. extern struct coff_ptr_struct *coff_get_normalized_symtab
  266. (bfd *);
  267. extern long coff_get_reloc_upper_bound
  268. (bfd *, sec_ptr);
  269. extern asymbol *coff_make_empty_symbol
  270. (bfd *);
  271. extern void coff_print_symbol
  272. (bfd *, void * filep, asymbol *, bfd_print_symbol_type);
  273. extern void coff_get_symbol_info
  274. (bfd *, asymbol *, symbol_info *ret);
  275. #define coff_get_symbol_version_string \
  276. _bfd_nosymbols_get_symbol_version_string
  277. extern bfd_boolean _bfd_coff_is_local_label_name
  278. (bfd *, const char *);
  279. extern asymbol *coff_bfd_make_debug_symbol
  280. (bfd *, void *, unsigned long);
  281. extern bfd_boolean coff_find_nearest_line
  282. (bfd *, asymbol **, asection *, bfd_vma,
  283. const char **, const char **, unsigned int *, unsigned int *);
  284. #define coff_find_line _bfd_nosymbols_find_line
  285. struct dwarf_debug_section;
  286. extern bfd_boolean coff_find_nearest_line_with_names
  287. (bfd *, asymbol **, asection *, bfd_vma, const char **, const char **,
  288. unsigned int *, const struct dwarf_debug_section *);
  289. extern bfd_boolean coff_find_inliner_info
  290. (bfd *, const char **, const char **, unsigned int *);
  291. extern int coff_sizeof_headers
  292. (bfd *, struct bfd_link_info *);
  293. extern bfd_boolean bfd_coff_reloc16_relax_section
  294. (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
  295. extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents
  296. (bfd *, struct bfd_link_info *, struct bfd_link_order *,
  297. bfd_byte *, bfd_boolean, asymbol **);
  298. extern bfd_vma bfd_coff_reloc16_get_value
  299. (arelent *, struct bfd_link_info *, asection *);
  300. extern void bfd_perform_slip
  301. (bfd *, unsigned int, asection *, bfd_vma);
  302. /* Functions and types in cofflink.c. */
  303. #define STRING_SIZE_SIZE 4
  304. /* We use a hash table to merge identical enum, struct, and union
  305. definitions in the linker. */
  306. /* Information we keep for a single element (an enum value, a
  307. structure or union field) in the debug merge hash table. */
  308. struct coff_debug_merge_element
  309. {
  310. /* Next element. */
  311. struct coff_debug_merge_element *next;
  312. /* Name. */
  313. const char *name;
  314. /* Type. */
  315. unsigned int type;
  316. /* Symbol index for complex type. */
  317. long tagndx;
  318. };
  319. /* A linked list of debug merge entries for a given name. */
  320. struct coff_debug_merge_type
  321. {
  322. /* Next type with the same name. */
  323. struct coff_debug_merge_type *next;
  324. /* Class of type. */
  325. int type_class;
  326. /* Symbol index where this type is defined. */
  327. long indx;
  328. /* List of elements. */
  329. struct coff_debug_merge_element *elements;
  330. };
  331. /* Information we store in the debug merge hash table. */
  332. struct coff_debug_merge_hash_entry
  333. {
  334. struct bfd_hash_entry root;
  335. /* A list of types with this name. */
  336. struct coff_debug_merge_type *types;
  337. };
  338. /* The debug merge hash table. */
  339. struct coff_debug_merge_hash_table
  340. {
  341. struct bfd_hash_table root;
  342. };
  343. /* Initialize a COFF debug merge hash table. */
  344. #define coff_debug_merge_hash_table_init(table) \
  345. (bfd_hash_table_init (&(table)->root, _bfd_coff_debug_merge_hash_newfunc, \
  346. sizeof (struct coff_debug_merge_hash_entry)))
  347. /* Free a COFF debug merge hash table. */
  348. #define coff_debug_merge_hash_table_free(table) \
  349. (bfd_hash_table_free (&(table)->root))
  350. /* Look up an entry in a COFF debug merge hash table. */
  351. #define coff_debug_merge_hash_lookup(table, string, create, copy) \
  352. ((struct coff_debug_merge_hash_entry *) \
  353. bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
  354. /* Information we keep for each section in the output file when doing
  355. a relocatable link. */
  356. struct coff_link_section_info
  357. {
  358. /* The relocs to be output. */
  359. struct internal_reloc *relocs;
  360. /* For each reloc against a global symbol whose index was not known
  361. when the reloc was handled, the global hash table entry. */
  362. struct coff_link_hash_entry **rel_hashes;
  363. };
  364. /* Information that we pass around while doing the final link step. */
  365. struct coff_final_link_info
  366. {
  367. /* General link information. */
  368. struct bfd_link_info *info;
  369. /* Output BFD. */
  370. bfd *output_bfd;
  371. /* Used to indicate failure in traversal routine. */
  372. bfd_boolean failed;
  373. /* If doing "task linking" set only during the time when we want the
  374. global symbol writer to convert the storage class of defined global
  375. symbols from global to static. */
  376. bfd_boolean global_to_static;
  377. /* Hash table for long symbol names. */
  378. struct bfd_strtab_hash *strtab;
  379. /* When doing a relocatable link, an array of information kept for
  380. each output section, indexed by the target_index field. */
  381. struct coff_link_section_info *section_info;
  382. /* Symbol index of last C_FILE symbol (-1 if none). */
  383. long last_file_index;
  384. /* Contents of last C_FILE symbol. */
  385. struct internal_syment last_file;
  386. /* Symbol index of first aux entry of last .bf symbol with an empty
  387. endndx field (-1 if none). */
  388. long last_bf_index;
  389. /* Contents of last_bf_index aux entry. */
  390. union internal_auxent last_bf;
  391. /* Hash table used to merge debug information. */
  392. struct coff_debug_merge_hash_table debug_merge;
  393. /* Buffer large enough to hold swapped symbols of any input file. */
  394. struct internal_syment *internal_syms;
  395. /* Buffer large enough to hold sections of symbols of any input file. */
  396. asection **sec_ptrs;
  397. /* Buffer large enough to hold output indices of symbols of any
  398. input file. */
  399. long *sym_indices;
  400. /* Buffer large enough to hold output symbols for any input file. */
  401. bfd_byte *outsyms;
  402. /* Buffer large enough to hold external line numbers for any input
  403. section. */
  404. bfd_byte *linenos;
  405. /* Buffer large enough to hold any input section. */
  406. bfd_byte *contents;
  407. /* Buffer large enough to hold external relocs of any input section. */
  408. bfd_byte *external_relocs;
  409. /* Buffer large enough to hold swapped relocs of any input section. */
  410. struct internal_reloc *internal_relocs;
  411. };
  412. /* Most COFF variants have no way to record the alignment of a
  413. section. This struct is used to set a specific alignment based on
  414. the name of the section. */
  415. struct coff_section_alignment_entry
  416. {
  417. /* The section name. */
  418. const char *name;
  419. /* This is either (unsigned int) -1, indicating that the section
  420. name must match exactly, or it is the number of letters which
  421. must match at the start of the name. */
  422. unsigned int comparison_length;
  423. /* These macros may be used to fill in the first two fields in a
  424. structure initialization. */
  425. #define COFF_SECTION_NAME_EXACT_MATCH(name) (name), ((unsigned int) -1)
  426. #define COFF_SECTION_NAME_PARTIAL_MATCH(name) (name), (sizeof (name) - 1)
  427. /* Only use this entry if the default section alignment for this
  428. target is at least that much (as a power of two). If this field
  429. is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
  430. unsigned int default_alignment_min;
  431. /* Only use this entry if the default section alignment for this
  432. target is no greater than this (as a power of two). If this
  433. field is COFF_ALIGNMENT_FIELD_EMPTY, it should be ignored. */
  434. unsigned int default_alignment_max;
  435. #define COFF_ALIGNMENT_FIELD_EMPTY ((unsigned int) -1)
  436. /* The desired alignment for this section (as a power of two). */
  437. unsigned int alignment_power;
  438. };
  439. extern struct bfd_hash_entry *_bfd_coff_link_hash_newfunc
  440. (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
  441. extern bfd_boolean _bfd_coff_link_hash_table_init
  442. (struct coff_link_hash_table *, bfd *,
  443. struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
  444. struct bfd_hash_table *,
  445. const char *),
  446. unsigned int);
  447. extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create
  448. (bfd *);
  449. extern const char *_bfd_coff_internal_syment_name
  450. (bfd *, const struct internal_syment *, char *);
  451. extern bfd_boolean _bfd_coff_section_already_linked
  452. (bfd *, asection *, struct bfd_link_info *);
  453. extern bfd_boolean _bfd_coff_link_add_symbols
  454. (bfd *, struct bfd_link_info *);
  455. extern bfd_boolean _bfd_coff_final_link
  456. (bfd *, struct bfd_link_info *);
  457. extern struct internal_reloc *_bfd_coff_read_internal_relocs
  458. (bfd *, asection *, bfd_boolean, bfd_byte *, bfd_boolean,
  459. struct internal_reloc *);
  460. extern bfd_boolean _bfd_coff_generic_relocate_section
  461. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  462. struct internal_reloc *, struct internal_syment *, asection **);
  463. extern struct bfd_hash_entry *_bfd_coff_debug_merge_hash_newfunc
  464. (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
  465. extern bfd_boolean _bfd_coff_write_global_sym
  466. (struct bfd_hash_entry *, void *);
  467. extern bfd_boolean _bfd_coff_write_task_globals
  468. (struct coff_link_hash_entry *, void *);
  469. extern bfd_boolean _bfd_coff_link_input_bfd
  470. (struct coff_final_link_info *, bfd *);
  471. extern bfd_boolean _bfd_coff_reloc_link_order
  472. (bfd *, struct coff_final_link_info *, asection *,
  473. struct bfd_link_order *);
  474. extern bfd_boolean bfd_coff_gc_sections
  475. (bfd *, struct bfd_link_info *);
  476. #define coff_get_section_contents_in_window \
  477. _bfd_generic_get_section_contents_in_window
  478. /* Functions in xcofflink.c. */
  479. extern long _bfd_xcoff_get_dynamic_symtab_upper_bound
  480. (bfd *);
  481. extern long _bfd_xcoff_canonicalize_dynamic_symtab
  482. (bfd *, asymbol **);
  483. extern long _bfd_xcoff_get_dynamic_reloc_upper_bound
  484. (bfd *);
  485. extern long _bfd_xcoff_canonicalize_dynamic_reloc
  486. (bfd *, arelent **, asymbol **);
  487. extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
  488. (bfd *);
  489. extern bfd_boolean _bfd_xcoff_bfd_link_add_symbols
  490. (bfd *, struct bfd_link_info *);
  491. extern bfd_boolean _bfd_xcoff_bfd_final_link
  492. (bfd *, struct bfd_link_info *);
  493. extern bfd_boolean _bfd_xcoff_define_common_symbol
  494. (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
  495. extern bfd_boolean _bfd_ppc_xcoff_relocate_section
  496. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  497. struct internal_reloc *, struct internal_syment *, asection **);
  498. /* Functions in coff-ppc.c. FIXME: These are called by pe.em in the
  499. linker, and so should start with bfd and be declared in bfd.h. */
  500. extern bfd_boolean ppc_allocate_toc_section
  501. (struct bfd_link_info *);
  502. extern bfd_boolean ppc_process_before_allocation
  503. (bfd *, struct bfd_link_info *);
  504. /* Extracted from coffcode.h. */
  505. typedef struct coff_ptr_struct
  506. {
  507. /* Remembers the offset from the first symbol in the file for
  508. this symbol. Generated by coff_renumber_symbols. */
  509. unsigned int offset;
  510. /* Should the value of this symbol be renumbered. Used for
  511. XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
  512. unsigned int fix_value : 1;
  513. /* Should the tag field of this symbol be renumbered.
  514. Created by coff_pointerize_aux. */
  515. unsigned int fix_tag : 1;
  516. /* Should the endidx field of this symbol be renumbered.
  517. Created by coff_pointerize_aux. */
  518. unsigned int fix_end : 1;
  519. /* Should the x_csect.x_scnlen field be renumbered.
  520. Created by coff_pointerize_aux. */
  521. unsigned int fix_scnlen : 1;
  522. /* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
  523. index into the line number entries. Set by coff_slurp_symbol_table. */
  524. unsigned int fix_line : 1;
  525. /* The container for the symbol structure as read and translated
  526. from the file. */
  527. union
  528. {
  529. union internal_auxent auxent;
  530. struct internal_syment syment;
  531. } u;
  532. /* Selector for the union above. */
  533. bfd_boolean is_sym;
  534. } combined_entry_type;
  535. /* Each canonical asymbol really looks like this: */
  536. typedef struct coff_symbol_struct
  537. {
  538. /* The actual symbol which the rest of BFD works with */
  539. asymbol symbol;
  540. /* A pointer to the hidden information for this symbol */
  541. combined_entry_type *native;
  542. /* A pointer to the linenumber information for this symbol */
  543. struct lineno_cache_entry *lineno;
  544. /* Have the line numbers been relocated yet ? */
  545. bfd_boolean done_lineno;
  546. } coff_symbol_type;
  547. /* COFF symbol classifications. */
  548. enum coff_symbol_classification
  549. {
  550. /* Global symbol. */
  551. COFF_SYMBOL_GLOBAL,
  552. /* Common symbol. */
  553. COFF_SYMBOL_COMMON,
  554. /* Undefined symbol. */
  555. COFF_SYMBOL_UNDEFINED,
  556. /* Local symbol. */
  557. COFF_SYMBOL_LOCAL,
  558. /* PE section symbol. */
  559. COFF_SYMBOL_PE_SECTION
  560. };
  561. typedef asection * (*coff_gc_mark_hook_fn)
  562. (asection *, struct bfd_link_info *, struct internal_reloc *,
  563. struct coff_link_hash_entry *, struct internal_syment *);
  564. typedef struct
  565. {
  566. void (*_bfd_coff_swap_aux_in)
  567. (bfd *, void *, int, int, int, int, void *);
  568. void (*_bfd_coff_swap_sym_in)
  569. (bfd *, void *, void *);
  570. void (*_bfd_coff_swap_lineno_in)
  571. (bfd *, void *, void *);
  572. unsigned int (*_bfd_coff_swap_aux_out)
  573. (bfd *, void *, int, int, int, int, void *);
  574. unsigned int (*_bfd_coff_swap_sym_out)
  575. (bfd *, void *, void *);
  576. unsigned int (*_bfd_coff_swap_lineno_out)
  577. (bfd *, void *, void *);
  578. unsigned int (*_bfd_coff_swap_reloc_out)
  579. (bfd *, void *, void *);
  580. unsigned int (*_bfd_coff_swap_filehdr_out)
  581. (bfd *, void *, void *);
  582. unsigned int (*_bfd_coff_swap_aouthdr_out)
  583. (bfd *, void *, void *);
  584. unsigned int (*_bfd_coff_swap_scnhdr_out)
  585. (bfd *, void *, void *);
  586. unsigned int _bfd_filhsz;
  587. unsigned int _bfd_aoutsz;
  588. unsigned int _bfd_scnhsz;
  589. unsigned int _bfd_symesz;
  590. unsigned int _bfd_auxesz;
  591. unsigned int _bfd_relsz;
  592. unsigned int _bfd_linesz;
  593. unsigned int _bfd_filnmlen;
  594. bfd_boolean _bfd_coff_long_filenames;
  595. bfd_boolean _bfd_coff_long_section_names;
  596. bfd_boolean (*_bfd_coff_set_long_section_names)
  597. (bfd *, int);
  598. unsigned int _bfd_coff_default_section_alignment_power;
  599. bfd_boolean _bfd_coff_force_symnames_in_strings;
  600. unsigned int _bfd_coff_debug_string_prefix_length;
  601. unsigned int _bfd_coff_max_nscns;
  602. void (*_bfd_coff_swap_filehdr_in)
  603. (bfd *, void *, void *);
  604. void (*_bfd_coff_swap_aouthdr_in)
  605. (bfd *, void *, void *);
  606. void (*_bfd_coff_swap_scnhdr_in)
  607. (bfd *, void *, void *);
  608. void (*_bfd_coff_swap_reloc_in)
  609. (bfd *abfd, void *, void *);
  610. bfd_boolean (*_bfd_coff_bad_format_hook)
  611. (bfd *, void *);
  612. bfd_boolean (*_bfd_coff_set_arch_mach_hook)
  613. (bfd *, void *);
  614. void * (*_bfd_coff_mkobject_hook)
  615. (bfd *, void *, void *);
  616. bfd_boolean (*_bfd_styp_to_sec_flags_hook)
  617. (bfd *, void *, const char *, asection *, flagword *);
  618. void (*_bfd_set_alignment_hook)
  619. (bfd *, asection *, void *);
  620. bfd_boolean (*_bfd_coff_slurp_symbol_table)
  621. (bfd *);
  622. bfd_boolean (*_bfd_coff_symname_in_debug)
  623. (bfd *, struct internal_syment *);
  624. bfd_boolean (*_bfd_coff_pointerize_aux_hook)
  625. (bfd *, combined_entry_type *, combined_entry_type *,
  626. unsigned int, combined_entry_type *);
  627. bfd_boolean (*_bfd_coff_print_aux)
  628. (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
  629. combined_entry_type *, unsigned int);
  630. void (*_bfd_coff_reloc16_extra_cases)
  631. (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
  632. bfd_byte *, unsigned int *, unsigned int *);
  633. int (*_bfd_coff_reloc16_estimate)
  634. (bfd *, asection *, arelent *, unsigned int,
  635. struct bfd_link_info *);
  636. enum coff_symbol_classification (*_bfd_coff_classify_symbol)
  637. (bfd *, struct internal_syment *);
  638. bfd_boolean (*_bfd_coff_compute_section_file_positions)
  639. (bfd *);
  640. bfd_boolean (*_bfd_coff_start_final_link)
  641. (bfd *, struct bfd_link_info *);
  642. bfd_boolean (*_bfd_coff_relocate_section)
  643. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  644. struct internal_reloc *, struct internal_syment *, asection **);
  645. reloc_howto_type *(*_bfd_coff_rtype_to_howto)
  646. (bfd *, asection *, struct internal_reloc *,
  647. struct coff_link_hash_entry *, struct internal_syment *,
  648. bfd_vma *);
  649. bfd_boolean (*_bfd_coff_adjust_symndx)
  650. (bfd *, struct bfd_link_info *, bfd *, asection *,
  651. struct internal_reloc *, bfd_boolean *);
  652. bfd_boolean (*_bfd_coff_link_add_one_symbol)
  653. (struct bfd_link_info *, bfd *, const char *, flagword,
  654. asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
  655. struct bfd_link_hash_entry **);
  656. bfd_boolean (*_bfd_coff_link_output_has_begun)
  657. (bfd *, struct coff_final_link_info *);
  658. bfd_boolean (*_bfd_coff_final_link_postscript)
  659. (bfd *, struct coff_final_link_info *);
  660. bfd_boolean (*_bfd_coff_print_pdata)
  661. (bfd *, void *);
  662. } bfd_coff_backend_data;
  663. #define coff_backend_info(abfd) \
  664. ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
  665. #define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
  666. ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
  667. #define bfd_coff_swap_sym_in(a,e,i) \
  668. ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
  669. #define bfd_coff_swap_lineno_in(a,e,i) \
  670. ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
  671. #define bfd_coff_swap_reloc_out(abfd, i, o) \
  672. ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
  673. #define bfd_coff_swap_lineno_out(abfd, i, o) \
  674. ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
  675. #define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
  676. ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
  677. #define bfd_coff_swap_sym_out(abfd, i,o) \
  678. ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
  679. #define bfd_coff_swap_scnhdr_out(abfd, i,o) \
  680. ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
  681. #define bfd_coff_swap_filehdr_out(abfd, i,o) \
  682. ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
  683. #define bfd_coff_swap_aouthdr_out(abfd, i,o) \
  684. ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
  685. #define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
  686. #define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
  687. #define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
  688. #define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
  689. #define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
  690. #define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
  691. #define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
  692. #define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
  693. #define bfd_coff_long_filenames(abfd) \
  694. (coff_backend_info (abfd)->_bfd_coff_long_filenames)
  695. #define bfd_coff_long_section_names(abfd) \
  696. (coff_backend_info (abfd)->_bfd_coff_long_section_names)
  697. #define bfd_coff_set_long_section_names(abfd, enable) \
  698. ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
  699. #define bfd_coff_default_section_alignment_power(abfd) \
  700. (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
  701. #define bfd_coff_max_nscns(abfd) \
  702. (coff_backend_info (abfd)->_bfd_coff_max_nscns)
  703. #define bfd_coff_swap_filehdr_in(abfd, i,o) \
  704. ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
  705. #define bfd_coff_swap_aouthdr_in(abfd, i,o) \
  706. ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
  707. #define bfd_coff_swap_scnhdr_in(abfd, i,o) \
  708. ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
  709. #define bfd_coff_swap_reloc_in(abfd, i, o) \
  710. ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
  711. #define bfd_coff_bad_format_hook(abfd, filehdr) \
  712. ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
  713. #define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
  714. ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
  715. #define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
  716. ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
  717. (abfd, filehdr, aouthdr))
  718. #define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
  719. ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
  720. (abfd, scnhdr, name, section, flags_ptr))
  721. #define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
  722. ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
  723. #define bfd_coff_slurp_symbol_table(abfd)\
  724. ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
  725. #define bfd_coff_symname_in_debug(abfd, sym)\
  726. ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
  727. #define bfd_coff_force_symnames_in_strings(abfd)\
  728. (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
  729. #define bfd_coff_debug_string_prefix_length(abfd)\
  730. (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
  731. #define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
  732. ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
  733. (abfd, file, base, symbol, aux, indaux))
  734. #define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
  735. reloc, data, src_ptr, dst_ptr)\
  736. ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
  737. (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
  738. #define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
  739. ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
  740. (abfd, section, reloc, shrink, link_info))
  741. #define bfd_coff_classify_symbol(abfd, sym)\
  742. ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
  743. (abfd, sym))
  744. #define bfd_coff_compute_section_file_positions(abfd)\
  745. ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
  746. (abfd))
  747. #define bfd_coff_start_final_link(obfd, info)\
  748. ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
  749. (obfd, info))
  750. #define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
  751. ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
  752. (obfd, info, ibfd, o, con, rel, isyms, secs))
  753. #define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
  754. ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
  755. (abfd, sec, rel, h, sym, addendp))
  756. #define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
  757. ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
  758. (obfd, info, ibfd, sec, rel, adjustedp))
  759. #define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
  760. value, string, cp, coll, hashp)\
  761. ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
  762. (info, abfd, name, flags, section, value, string, cp, coll, hashp))
  763. #define bfd_coff_link_output_has_begun(a,p) \
  764. ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
  765. #define bfd_coff_final_link_postscript(a,p) \
  766. ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
  767. #define bfd_coff_have_print_pdata(a) \
  768. (coff_backend_info (a)->_bfd_coff_print_pdata)
  769. #define bfd_coff_print_pdata(a,p) \
  770. ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
  771. /* Macro: Returns true if the bfd is a PE executable as opposed to a
  772. PE object file. */
  773. #define bfd_pei_p(abfd) \
  774. (CONST_STRNEQ ((abfd)->xvec->name, "pei-"))
  775. #ifdef __cplusplus
  776. }
  777. #endif