bfdlink.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. /* bfdlink.h -- header file for BFD link routines
  2. Copyright (C) 1993-2020 Free Software Foundation, Inc.
  3. Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #ifndef BFDLINK_H
  18. #define BFDLINK_H
  19. /* Which symbols to strip during a link. */
  20. enum bfd_link_strip
  21. {
  22. strip_none, /* Don't strip any symbols. */
  23. strip_debugger, /* Strip debugging symbols. */
  24. strip_some, /* keep_hash is the list of symbols to keep. */
  25. strip_all /* Strip all symbols. */
  26. };
  27. /* Which local symbols to discard during a link. This is irrelevant
  28. if strip_all is used. */
  29. enum bfd_link_discard
  30. {
  31. discard_sec_merge, /* Discard local temporary symbols in SEC_MERGE
  32. sections. */
  33. discard_none, /* Don't discard any locals. */
  34. discard_l, /* Discard local temporary symbols. */
  35. discard_all /* Discard all locals. */
  36. };
  37. enum notice_asneeded_action {
  38. notice_as_needed,
  39. notice_not_needed,
  40. notice_needed
  41. };
  42. /* Whether to generate ELF common symbols with the STT_COMMON type
  43. during a relocatable link. */
  44. enum bfd_link_elf_stt_common
  45. {
  46. unchanged,
  47. elf_stt_common,
  48. no_elf_stt_common
  49. };
  50. /* Describes the type of hash table entry structure being used.
  51. Different hash table structure have different fields and so
  52. support different linking features. */
  53. enum bfd_link_hash_table_type
  54. {
  55. bfd_link_generic_hash_table,
  56. bfd_link_elf_hash_table
  57. };
  58. /* These are the possible types of an entry in the BFD link hash
  59. table. */
  60. enum bfd_link_hash_type
  61. {
  62. bfd_link_hash_new, /* Symbol is new. */
  63. bfd_link_hash_undefined, /* Symbol seen before, but undefined. */
  64. bfd_link_hash_undefweak, /* Symbol is weak and undefined. */
  65. bfd_link_hash_defined, /* Symbol is defined. */
  66. bfd_link_hash_defweak, /* Symbol is weak and defined. */
  67. bfd_link_hash_common, /* Symbol is common. */
  68. bfd_link_hash_indirect, /* Symbol is an indirect link. */
  69. bfd_link_hash_warning /* Like indirect, but warn if referenced. */
  70. };
  71. enum bfd_link_common_skip_ar_symbols
  72. {
  73. bfd_link_common_skip_none,
  74. bfd_link_common_skip_text,
  75. bfd_link_common_skip_data,
  76. bfd_link_common_skip_all
  77. };
  78. struct bfd_link_hash_common_entry
  79. {
  80. unsigned int alignment_power; /* Alignment. */
  81. asection *section; /* Symbol section. */
  82. };
  83. /* The linking routines use a hash table which uses this structure for
  84. its elements. */
  85. struct bfd_link_hash_entry
  86. {
  87. /* Base hash table entry structure. */
  88. struct bfd_hash_entry root;
  89. /* Type of this entry. */
  90. ENUM_BITFIELD (bfd_link_hash_type) type : 8;
  91. /* Symbol is referenced in a normal regular object file,
  92. as distinct from a LTO IR object file. */
  93. unsigned int non_ir_ref_regular : 1;
  94. /* Symbol is referenced in a normal dynamic object file,
  95. as distinct from a LTO IR object file. */
  96. unsigned int non_ir_ref_dynamic : 1;
  97. /* Symbol is a built-in define. These will be overridden by PROVIDE
  98. in a linker script. */
  99. unsigned int linker_def : 1;
  100. /* Symbol defined in a linker script. */
  101. unsigned int ldscript_def : 1;
  102. /* Symbol will be converted from absolute to section-relative. Set for
  103. symbols defined by a script from "dot" (also SEGMENT_START or ORIGIN)
  104. outside of an output section statement. */
  105. unsigned int rel_from_abs : 1;
  106. /* A union of information depending upon the type. */
  107. union
  108. {
  109. /* Nothing is kept for bfd_hash_new. */
  110. /* bfd_link_hash_undefined, bfd_link_hash_undefweak. */
  111. struct
  112. {
  113. /* Undefined and common symbols are kept in a linked list through
  114. this field. This field is present in all of the union element
  115. so that we don't need to remove entries from the list when we
  116. change their type. Removing entries would either require the
  117. list to be doubly linked, which would waste more memory, or
  118. require a traversal. When an undefined or common symbol is
  119. created, it should be added to this list, the head of which is in
  120. the link hash table itself. As symbols are defined, they need
  121. not be removed from the list; anything which reads the list must
  122. doublecheck the symbol type.
  123. Weak symbols are not kept on this list.
  124. Defined and defweak symbols use this field as a reference marker.
  125. If the field is not NULL, or this structure is the tail of the
  126. undefined symbol list, the symbol has been referenced. If the
  127. symbol is undefined and becomes defined, this field will
  128. automatically be non-NULL since the symbol will have been on the
  129. undefined symbol list. */
  130. struct bfd_link_hash_entry *next;
  131. /* BFD symbol was found in. */
  132. bfd *abfd;
  133. } undef;
  134. /* bfd_link_hash_defined, bfd_link_hash_defweak. */
  135. struct
  136. {
  137. struct bfd_link_hash_entry *next;
  138. /* Symbol section. */
  139. asection *section;
  140. /* Symbol value. */
  141. bfd_vma value;
  142. } def;
  143. /* bfd_link_hash_indirect, bfd_link_hash_warning. */
  144. struct
  145. {
  146. struct bfd_link_hash_entry *next;
  147. /* Real symbol. */
  148. struct bfd_link_hash_entry *link;
  149. /* Warning message (bfd_link_hash_warning only). */
  150. const char *warning;
  151. } i;
  152. /* bfd_link_hash_common. */
  153. struct
  154. {
  155. struct bfd_link_hash_entry *next;
  156. /* The linker needs to know three things about common
  157. symbols: the size, the alignment, and the section in
  158. which the symbol should be placed. We store the size
  159. here, and we allocate a small structure to hold the
  160. section and the alignment. The alignment is stored as a
  161. power of two. We don't store all the information
  162. directly because we don't want to increase the size of
  163. the union; this structure is a major space user in the
  164. linker. */
  165. struct bfd_link_hash_common_entry *p;
  166. /* Common symbol size. */
  167. bfd_size_type size;
  168. } c;
  169. } u;
  170. };
  171. /* This is the link hash table. It is a derived class of
  172. bfd_hash_table. */
  173. struct bfd_link_hash_table
  174. {
  175. /* The hash table itself. */
  176. struct bfd_hash_table table;
  177. /* A linked list of undefined and common symbols, linked through the
  178. next field in the bfd_link_hash_entry structure. */
  179. struct bfd_link_hash_entry *undefs;
  180. /* Entries are added to the tail of the undefs list. */
  181. struct bfd_link_hash_entry *undefs_tail;
  182. /* Function to free the hash table on closing BFD. */
  183. void (*hash_table_free) (bfd *);
  184. /* The type of the link hash table. */
  185. enum bfd_link_hash_table_type type;
  186. };
  187. /* Look up an entry in a link hash table. If FOLLOW is TRUE, this
  188. follows bfd_link_hash_indirect and bfd_link_hash_warning links to
  189. the real symbol. */
  190. extern struct bfd_link_hash_entry *bfd_link_hash_lookup
  191. (struct bfd_link_hash_table *, const char *, bfd_boolean create,
  192. bfd_boolean copy, bfd_boolean follow);
  193. /* Look up an entry in the main linker hash table if the symbol might
  194. be wrapped. This should only be used for references to an
  195. undefined symbol, not for definitions of a symbol. */
  196. extern struct bfd_link_hash_entry *bfd_wrapped_link_hash_lookup
  197. (bfd *, struct bfd_link_info *, const char *, bfd_boolean,
  198. bfd_boolean, bfd_boolean);
  199. /* If H is a wrapped symbol, ie. the symbol name starts with "__wrap_"
  200. and the remainder is found in wrap_hash, return the real symbol. */
  201. extern struct bfd_link_hash_entry *unwrap_hash_lookup
  202. (struct bfd_link_info *, bfd *, struct bfd_link_hash_entry *);
  203. /* Traverse a link hash table. */
  204. extern void bfd_link_hash_traverse
  205. (struct bfd_link_hash_table *,
  206. bfd_boolean (*) (struct bfd_link_hash_entry *, void *),
  207. void *);
  208. /* Add an entry to the undefs list. */
  209. extern void bfd_link_add_undef
  210. (struct bfd_link_hash_table *, struct bfd_link_hash_entry *);
  211. /* Remove symbols from the undefs list that don't belong there. */
  212. extern void bfd_link_repair_undef_list
  213. (struct bfd_link_hash_table *table);
  214. /* Read symbols and cache symbol pointer array in outsymbols. */
  215. extern bfd_boolean bfd_generic_link_read_symbols (bfd *);
  216. /* Check the relocs in the BFD. Called after all the input
  217. files have been loaded, and garbage collection has tagged
  218. any unneeded sections. */
  219. extern bfd_boolean bfd_link_check_relocs (bfd *,struct bfd_link_info *);
  220. struct bfd_sym_chain
  221. {
  222. struct bfd_sym_chain *next;
  223. const char *name;
  224. };
  225. /* How to handle unresolved symbols.
  226. There are four possibilities which are enumerated below: */
  227. enum report_method
  228. {
  229. /* This is the initial value when then link_info structure is created.
  230. It allows the various stages of the linker to determine whether they
  231. allowed to set the value. */
  232. RM_NOT_YET_SET = 0,
  233. RM_IGNORE,
  234. RM_GENERATE_WARNING,
  235. RM_GENERATE_ERROR
  236. };
  237. typedef enum {with_flags, without_flags} flag_type;
  238. /* A section flag list. */
  239. struct flag_info_list
  240. {
  241. flag_type with;
  242. const char *name;
  243. bfd_boolean valid;
  244. struct flag_info_list *next;
  245. };
  246. /* Section flag info. */
  247. struct flag_info
  248. {
  249. flagword only_with_flags;
  250. flagword not_with_flags;
  251. struct flag_info_list *flag_list;
  252. bfd_boolean flags_initialized;
  253. };
  254. struct bfd_elf_dynamic_list;
  255. struct bfd_elf_version_tree;
  256. /* Types of output. */
  257. enum output_type
  258. {
  259. type_pde,
  260. type_pie,
  261. type_relocatable,
  262. type_dll,
  263. };
  264. #define bfd_link_pde(info) ((info)->type == type_pde)
  265. #define bfd_link_dll(info) ((info)->type == type_dll)
  266. #define bfd_link_relocatable(info) ((info)->type == type_relocatable)
  267. #define bfd_link_pie(info) ((info)->type == type_pie)
  268. #define bfd_link_executable(info) (bfd_link_pde (info) || bfd_link_pie (info))
  269. #define bfd_link_pic(info) (bfd_link_dll (info) || bfd_link_pie (info))
  270. /* This structure holds all the information needed to communicate
  271. between BFD and the linker when doing a link. */
  272. struct bfd_link_info
  273. {
  274. /* Output type. */
  275. ENUM_BITFIELD (output_type) type : 2;
  276. /* TRUE if BFD should pre-bind symbols in a shared object. */
  277. unsigned int symbolic: 1;
  278. /* TRUE if executable should not contain copy relocs.
  279. Setting this true may result in a non-sharable text segment. */
  280. unsigned int nocopyreloc: 1;
  281. /* TRUE if BFD should export all symbols in the dynamic symbol table
  282. of an executable, rather than only those used. */
  283. unsigned int export_dynamic: 1;
  284. /* TRUE if a default symbol version should be created and used for
  285. exported symbols. */
  286. unsigned int create_default_symver: 1;
  287. /* TRUE if unreferenced sections should be removed. */
  288. unsigned int gc_sections: 1;
  289. /* TRUE if exported symbols should be kept during section gc. */
  290. unsigned int gc_keep_exported: 1;
  291. /* TRUE if every symbol should be reported back via the notice
  292. callback. */
  293. unsigned int notice_all: 1;
  294. /* TRUE if the LTO plugin is active. */
  295. unsigned int lto_plugin_active: 1;
  296. /* TRUE if global symbols in discarded sections should be stripped. */
  297. unsigned int strip_discarded: 1;
  298. /* TRUE if all data symbols should be dynamic. */
  299. unsigned int dynamic_data: 1;
  300. /* TRUE if section groups should be resolved. */
  301. unsigned int resolve_section_groups: 1;
  302. /* Set if output file is big-endian, or if that is unknown, from
  303. the command line or first input file endianness. */
  304. unsigned int big_endian : 1;
  305. /* Which symbols to strip. */
  306. ENUM_BITFIELD (bfd_link_strip) strip : 2;
  307. /* Which local symbols to discard. */
  308. ENUM_BITFIELD (bfd_link_discard) discard : 2;
  309. /* Whether to generate ELF common symbols with the STT_COMMON type. */
  310. ENUM_BITFIELD (bfd_link_elf_stt_common) elf_stt_common : 2;
  311. /* Criteria for skipping symbols when determining
  312. whether to include an object from an archive. */
  313. ENUM_BITFIELD (bfd_link_common_skip_ar_symbols) common_skip_ar_symbols : 2;
  314. /* What to do with unresolved symbols in an object file.
  315. When producing executables the default is GENERATE_ERROR.
  316. When producing shared libraries the default is IGNORE. The
  317. assumption with shared libraries is that the reference will be
  318. resolved at load/execution time. */
  319. ENUM_BITFIELD (report_method) unresolved_syms_in_objects : 2;
  320. /* What to do with unresolved symbols in a shared library.
  321. The same defaults apply. */
  322. ENUM_BITFIELD (report_method) unresolved_syms_in_shared_libs : 2;
  323. /* TRUE if shared objects should be linked directly, not shared. */
  324. unsigned int static_link: 1;
  325. /* TRUE if symbols should be retained in memory, FALSE if they
  326. should be freed and reread. */
  327. unsigned int keep_memory: 1;
  328. /* TRUE if BFD should generate relocation information in the final
  329. executable. */
  330. unsigned int emitrelocations: 1;
  331. /* TRUE if PT_GNU_RELRO segment should be created. */
  332. unsigned int relro: 1;
  333. /* TRUE if separate code segment should be created. */
  334. unsigned int separate_code: 1;
  335. /* Nonzero if .eh_frame_hdr section and PT_GNU_EH_FRAME ELF segment
  336. should be created. 1 for DWARF2 tables, 2 for compact tables. */
  337. unsigned int eh_frame_hdr_type: 2;
  338. /* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */
  339. unsigned int warn_shared_textrel: 1;
  340. /* TRUE if we should error when adding a DT_TEXTREL. */
  341. unsigned int error_textrel: 1;
  342. /* TRUE if .hash section should be created. */
  343. unsigned int emit_hash: 1;
  344. /* TRUE if .gnu.hash section should be created. */
  345. unsigned int emit_gnu_hash: 1;
  346. /* If TRUE reduce memory overheads, at the expense of speed. This will
  347. cause map file generation to use an O(N^2) algorithm and disable
  348. caching ELF symbol buffer. */
  349. unsigned int reduce_memory_overheads: 1;
  350. /* TRUE if the output file should be in a traditional format. This
  351. is equivalent to the setting of the BFD_TRADITIONAL_FORMAT flag
  352. on the output file, but may be checked when reading the input
  353. files. */
  354. unsigned int traditional_format: 1;
  355. /* TRUE if non-PLT relocs should be merged into one reloc section
  356. and sorted so that relocs against the same symbol come together. */
  357. unsigned int combreloc: 1;
  358. /* TRUE if a default symbol version should be created and used for
  359. imported symbols. */
  360. unsigned int default_imported_symver: 1;
  361. /* TRUE if the new ELF dynamic tags are enabled. */
  362. unsigned int new_dtags: 1;
  363. /* FALSE if .eh_frame unwind info should be generated for PLT and other
  364. linker created sections, TRUE if it should be omitted. */
  365. unsigned int no_ld_generated_unwind_info: 1;
  366. /* TRUE if BFD should generate a "task linked" object file,
  367. similar to relocatable but also with globals converted to
  368. statics. */
  369. unsigned int task_link: 1;
  370. /* TRUE if ok to have multiple definition. */
  371. unsigned int allow_multiple_definition: 1;
  372. /* TRUE if ok to have prohibit multiple definition of absolute symbols. */
  373. unsigned int prohibit_multiple_definition_absolute: 1;
  374. /* TRUE if ok to have version with no definition. */
  375. unsigned int allow_undefined_version: 1;
  376. /* TRUE if some symbols have to be dynamic, controlled by
  377. --dynamic-list command line options. */
  378. unsigned int dynamic: 1;
  379. /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W|PF_X
  380. flags. */
  381. unsigned int execstack: 1;
  382. /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W
  383. flags. */
  384. unsigned int noexecstack: 1;
  385. /* TRUE if we want to produced optimized output files. This might
  386. need much more time and therefore must be explicitly selected. */
  387. unsigned int optimize: 1;
  388. /* TRUE if user should be informed of removed unreferenced sections. */
  389. unsigned int print_gc_sections: 1;
  390. /* TRUE if we should warn alternate ELF machine code. */
  391. unsigned int warn_alternate_em: 1;
  392. /* TRUE if the linker script contained an explicit PHDRS command. */
  393. unsigned int user_phdrs: 1;
  394. /* TRUE if program headers ought to be loaded. */
  395. unsigned int load_phdrs: 1;
  396. /* TRUE if we should check relocations after all input files have
  397. been opened. */
  398. unsigned int check_relocs_after_open_input: 1;
  399. /* TRUE if generation of .interp/PT_INTERP should be suppressed. */
  400. unsigned int nointerp: 1;
  401. /* TRUE if common symbols should be treated as undefined. */
  402. unsigned int inhibit_common_definition : 1;
  403. /* TRUE if "-Map map" is passed to linker. */
  404. unsigned int has_map_file : 1;
  405. /* Char that may appear as the first char of a symbol, but should be
  406. skipped (like symbol_leading_char) when looking up symbols in
  407. wrap_hash. Used by PowerPC Linux for 'dot' symbols. */
  408. char wrap_char;
  409. /* Separator between archive and filename in linker script filespecs. */
  410. char path_separator;
  411. /* Compress DWARF debug sections. */
  412. enum compressed_debug_section_type compress_debug;
  413. /* Default stack size. Zero means default (often zero itself), -1
  414. means explicitly zero-sized. */
  415. bfd_signed_vma stacksize;
  416. /* Enable or disable target specific optimizations.
  417. Not all targets have optimizations to enable.
  418. Normally these optimizations are disabled by default but some targets
  419. prefer to enable them by default. So this field is a tri-state variable.
  420. The values are:
  421. zero: Enable the optimizations (either from --relax being specified on
  422. the command line or the backend's before_allocation emulation function.
  423. positive: The user has requested that these optimizations be disabled.
  424. (Via the --no-relax command line option).
  425. negative: The optimizations are disabled. (Set when initializing the
  426. args_type structure in ldmain.c:main. */
  427. signed int disable_target_specific_optimizations;
  428. /* Function callbacks. */
  429. const struct bfd_link_callbacks *callbacks;
  430. /* Hash table handled by BFD. */
  431. struct bfd_link_hash_table *hash;
  432. /* Hash table of symbols to keep. This is NULL unless strip is
  433. strip_some. */
  434. struct bfd_hash_table *keep_hash;
  435. /* Hash table of symbols to report back via the notice callback. If
  436. this is NULL, and notice_all is FALSE, then no symbols are
  437. reported back. */
  438. struct bfd_hash_table *notice_hash;
  439. /* Hash table of symbols which are being wrapped (the --wrap linker
  440. option). If this is NULL, no symbols are being wrapped. */
  441. struct bfd_hash_table *wrap_hash;
  442. /* Hash table of symbols which may be left unresolved during
  443. a link. If this is NULL, no symbols can be left unresolved. */
  444. struct bfd_hash_table *ignore_hash;
  445. /* The output BFD. */
  446. bfd *output_bfd;
  447. /* The import library generated. */
  448. bfd *out_implib_bfd;
  449. /* The list of input BFD's involved in the link. These are chained
  450. together via the link.next field. */
  451. bfd *input_bfds;
  452. bfd **input_bfds_tail;
  453. /* If a symbol should be created for each input BFD, this is section
  454. where those symbols should be placed. It must be a section in
  455. the output BFD. It may be NULL, in which case no such symbols
  456. will be created. This is to support CREATE_OBJECT_SYMBOLS in the
  457. linker command language. */
  458. asection *create_object_symbols_section;
  459. /* List of global symbol names that are starting points for marking
  460. sections against garbage collection. */
  461. struct bfd_sym_chain *gc_sym_list;
  462. /* If a base output file is wanted, then this points to it */
  463. void *base_file;
  464. /* The function to call when the executable or shared object is
  465. loaded. */
  466. const char *init_function;
  467. /* The function to call when the executable or shared object is
  468. unloaded. */
  469. const char *fini_function;
  470. /* Number of relaxation passes. Usually only one relaxation pass
  471. is needed. But a backend can have as many relaxation passes as
  472. necessary. During bfd_relax_section call, it is set to the
  473. current pass, starting from 0. */
  474. int relax_pass;
  475. /* Number of relaxation trips. This number is incremented every
  476. time the relaxation pass is restarted due to a previous
  477. relaxation returning true in *AGAIN. */
  478. int relax_trip;
  479. /* > 0 to treat protected data defined in the shared library as
  480. reference external. 0 to treat it as internal. -1 to let
  481. backend to decide. */
  482. int extern_protected_data;
  483. /* 1 to make undefined weak symbols dynamic when building a dynamic
  484. object. 0 to resolve undefined weak symbols to zero. -1 to let
  485. the backend decide. */
  486. int dynamic_undefined_weak;
  487. /* Non-zero if auto-import thunks for DATA items in pei386 DLLs
  488. should be generated/linked against. Set to 1 if this feature
  489. is explicitly requested by the user, -1 if enabled by default. */
  490. int pei386_auto_import;
  491. /* Non-zero if runtime relocs for DATA items with non-zero addends
  492. in pei386 DLLs should be generated. Set to 1 if this feature
  493. is explicitly requested by the user, -1 if enabled by default. */
  494. int pei386_runtime_pseudo_reloc;
  495. /* How many spare .dynamic DT_NULL entries should be added? */
  496. unsigned int spare_dynamic_tags;
  497. /* May be used to set DT_FLAGS for ELF. */
  498. bfd_vma flags;
  499. /* May be used to set DT_FLAGS_1 for ELF. */
  500. bfd_vma flags_1;
  501. /* Start and end of RELRO region. */
  502. bfd_vma relro_start, relro_end;
  503. /* List of symbols should be dynamic. */
  504. struct bfd_elf_dynamic_list *dynamic_list;
  505. /* The version information. */
  506. struct bfd_elf_version_tree *version_info;
  507. };
  508. /* Some forward-definitions used by some callbacks. */
  509. struct elf_strtab_hash;
  510. struct elf_sym_strtab;
  511. /* This structures holds a set of callback functions. These are called
  512. by the BFD linker routines. */
  513. struct bfd_link_callbacks
  514. {
  515. /* A function which is called when an object is added from an
  516. archive. ABFD is the archive element being added. NAME is the
  517. name of the symbol which caused the archive element to be pulled
  518. in. This function may set *SUBSBFD to point to an alternative
  519. BFD from which symbols should in fact be added in place of the
  520. original BFD's symbols. Returns TRUE if the object should be
  521. added, FALSE if it should be skipped. */
  522. bfd_boolean (*add_archive_element)
  523. (struct bfd_link_info *, bfd *abfd, const char *name, bfd **subsbfd);
  524. /* A function which is called when a symbol is found with multiple
  525. definitions. H is the symbol which is defined multiple times.
  526. NBFD is the new BFD, NSEC is the new section, and NVAL is the new
  527. value. NSEC may be bfd_com_section or bfd_ind_section. */
  528. void (*multiple_definition)
  529. (struct bfd_link_info *, struct bfd_link_hash_entry *h,
  530. bfd *nbfd, asection *nsec, bfd_vma nval);
  531. /* A function which is called when a common symbol is defined
  532. multiple times. H is the symbol appearing multiple times.
  533. NBFD is the BFD of the new symbol. NTYPE is the type of the new
  534. symbol, one of bfd_link_hash_defined, bfd_link_hash_common, or
  535. bfd_link_hash_indirect. If NTYPE is bfd_link_hash_common, NSIZE
  536. is the size of the new symbol. */
  537. void (*multiple_common)
  538. (struct bfd_link_info *, struct bfd_link_hash_entry *h,
  539. bfd *nbfd, enum bfd_link_hash_type ntype, bfd_vma nsize);
  540. /* A function which is called to add a symbol to a set. ENTRY is
  541. the link hash table entry for the set itself (e.g.,
  542. __CTOR_LIST__). RELOC is the relocation to use for an entry in
  543. the set when generating a relocatable file, and is also used to
  544. get the size of the entry when generating an executable file.
  545. ABFD, SEC and VALUE identify the value to add to the set. */
  546. void (*add_to_set)
  547. (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
  548. bfd_reloc_code_real_type reloc, bfd *abfd, asection *sec, bfd_vma value);
  549. /* A function which is called when the name of a g++ constructor or
  550. destructor is found. This is only called by some object file
  551. formats. CONSTRUCTOR is TRUE for a constructor, FALSE for a
  552. destructor. This will use BFD_RELOC_CTOR when generating a
  553. relocatable file. NAME is the name of the symbol found. ABFD,
  554. SECTION and VALUE are the value of the symbol. */
  555. void (*constructor)
  556. (struct bfd_link_info *, bfd_boolean constructor, const char *name,
  557. bfd *abfd, asection *sec, bfd_vma value);
  558. /* A function which is called to issue a linker warning. For
  559. example, this is called when there is a reference to a warning
  560. symbol. WARNING is the warning to be issued. SYMBOL is the name
  561. of the symbol which triggered the warning; it may be NULL if
  562. there is none. ABFD, SECTION and ADDRESS identify the location
  563. which trigerred the warning; either ABFD or SECTION or both may
  564. be NULL if the location is not known. */
  565. void (*warning)
  566. (struct bfd_link_info *, const char *warning, const char *symbol,
  567. bfd *abfd, asection *section, bfd_vma address);
  568. /* A function which is called when a relocation is attempted against
  569. an undefined symbol. NAME is the symbol which is undefined.
  570. ABFD, SECTION and ADDRESS identify the location from which the
  571. reference is made. IS_FATAL indicates whether an undefined symbol is
  572. a fatal error or not. In some cases SECTION may be NULL. */
  573. void (*undefined_symbol)
  574. (struct bfd_link_info *, const char *name, bfd *abfd,
  575. asection *section, bfd_vma address, bfd_boolean is_fatal);
  576. /* A function which is called when a reloc overflow occurs. ENTRY is
  577. the link hash table entry for the symbol the reloc is against.
  578. NAME is the name of the local symbol or section the reloc is
  579. against, RELOC_NAME is the name of the relocation, and ADDEND is
  580. any addend that is used. ABFD, SECTION and ADDRESS identify the
  581. location at which the overflow occurs; if this is the result of a
  582. bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  583. ABFD will be NULL. */
  584. void (*reloc_overflow)
  585. (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
  586. const char *name, const char *reloc_name, bfd_vma addend,
  587. bfd *abfd, asection *section, bfd_vma address);
  588. /* A function which is called when a dangerous reloc is performed.
  589. MESSAGE is an appropriate message.
  590. ABFD, SECTION and ADDRESS identify the location at which the
  591. problem occurred; if this is the result of a
  592. bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  593. ABFD will be NULL. */
  594. void (*reloc_dangerous)
  595. (struct bfd_link_info *, const char *message,
  596. bfd *abfd, asection *section, bfd_vma address);
  597. /* A function which is called when a reloc is found to be attached
  598. to a symbol which is not being written out. NAME is the name of
  599. the symbol. ABFD, SECTION and ADDRESS identify the location of
  600. the reloc; if this is the result of a
  601. bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
  602. ABFD will be NULL. */
  603. void (*unattached_reloc)
  604. (struct bfd_link_info *, const char *name,
  605. bfd *abfd, asection *section, bfd_vma address);
  606. /* A function which is called when a symbol in notice_hash is
  607. defined or referenced. H is the symbol, INH the indirect symbol
  608. if applicable. ABFD, SECTION and ADDRESS are the (new) value of
  609. the symbol. If SECTION is bfd_und_section, this is a reference.
  610. FLAGS are the symbol BSF_* flags. */
  611. bfd_boolean (*notice)
  612. (struct bfd_link_info *, struct bfd_link_hash_entry *h,
  613. struct bfd_link_hash_entry *inh,
  614. bfd *abfd, asection *section, bfd_vma address, flagword flags);
  615. /* Error or warning link info message. */
  616. void (*einfo)
  617. (const char *fmt, ...);
  618. /* General link info message. */
  619. void (*info)
  620. (const char *fmt, ...);
  621. /* Message to be printed in linker map file. */
  622. void (*minfo)
  623. (const char *fmt, ...);
  624. /* This callback provides a chance for users of the BFD library to
  625. override its decision about whether to place two adjacent sections
  626. into the same segment. */
  627. bfd_boolean (*override_segment_assignment)
  628. (struct bfd_link_info *, bfd * abfd,
  629. asection * current_section, asection * previous_section,
  630. bfd_boolean new_segment);
  631. /* This callback provides a chance for callers of the BFD to examine the
  632. ELF string table and symbol table once they are complete and indexes and
  633. offsets assigned. */
  634. void (*examine_strtab)
  635. (struct elf_sym_strtab *syms, bfd_size_type symcount,
  636. struct elf_strtab_hash *symstrtab);
  637. /* This callback should emit the CTF section into a non-loadable section in
  638. the output BFD named .ctf or a name beginning with ".ctf.". */
  639. void (*emit_ctf)
  640. (void);
  641. };
  642. /* The linker builds link_order structures which tell the code how to
  643. include input data in the output file. */
  644. /* These are the types of link_order structures. */
  645. enum bfd_link_order_type
  646. {
  647. bfd_undefined_link_order, /* Undefined. */
  648. bfd_indirect_link_order, /* Built from a section. */
  649. bfd_data_link_order, /* Set to explicit data. */
  650. bfd_section_reloc_link_order, /* Relocate against a section. */
  651. bfd_symbol_reloc_link_order /* Relocate against a symbol. */
  652. };
  653. /* This is the link_order structure itself. These form a chain
  654. attached to the output section whose contents they are describing. */
  655. struct bfd_link_order
  656. {
  657. /* Next link_order in chain. */
  658. struct bfd_link_order *next;
  659. /* Type of link_order. */
  660. enum bfd_link_order_type type;
  661. /* Offset within output section. */
  662. bfd_vma offset;
  663. /* Size within output section. */
  664. bfd_size_type size;
  665. /* Type specific information. */
  666. union
  667. {
  668. struct
  669. {
  670. /* Section to include. If this is used, then
  671. section->output_section must be the section the
  672. link_order is attached to, section->output_offset must
  673. equal the link_order offset field, and section->size
  674. must equal the link_order size field. Maybe these
  675. restrictions should be relaxed someday. */
  676. asection *section;
  677. } indirect;
  678. struct
  679. {
  680. /* Size of contents, or zero when contents should be filled by
  681. the architecture-dependent fill function.
  682. A non-zero value allows filling of the output section
  683. with an arbitrary repeated pattern. */
  684. unsigned int size;
  685. /* Data to put into file. */
  686. bfd_byte *contents;
  687. } data;
  688. struct
  689. {
  690. /* Description of reloc to generate. Used for
  691. bfd_section_reloc_link_order and
  692. bfd_symbol_reloc_link_order. */
  693. struct bfd_link_order_reloc *p;
  694. } reloc;
  695. } u;
  696. };
  697. /* A linker order of type bfd_section_reloc_link_order or
  698. bfd_symbol_reloc_link_order means to create a reloc against a
  699. section or symbol, respectively. This is used to implement -Ur to
  700. generate relocs for the constructor tables. The
  701. bfd_link_order_reloc structure describes the reloc that BFD should
  702. create. It is similar to a arelent, but I didn't use arelent
  703. because the linker does not know anything about most symbols, and
  704. any asymbol structure it creates will be partially meaningless.
  705. This information could logically be in the bfd_link_order struct,
  706. but I didn't want to waste the space since these types of relocs
  707. are relatively rare. */
  708. struct bfd_link_order_reloc
  709. {
  710. /* Reloc type. */
  711. bfd_reloc_code_real_type reloc;
  712. union
  713. {
  714. /* For type bfd_section_reloc_link_order, this is the section
  715. the reloc should be against. This must be a section in the
  716. output BFD, not any of the input BFDs. */
  717. asection *section;
  718. /* For type bfd_symbol_reloc_link_order, this is the name of the
  719. symbol the reloc should be against. */
  720. const char *name;
  721. } u;
  722. /* Addend to use. The object file should contain zero. The BFD
  723. backend is responsible for filling in the contents of the object
  724. file correctly. For some object file formats (e.g., COFF) the
  725. addend must be stored into in the object file, and for some
  726. (e.g., SPARC a.out) it is kept in the reloc. */
  727. bfd_vma addend;
  728. };
  729. /* Allocate a new link_order for a section. */
  730. extern struct bfd_link_order *bfd_new_link_order (bfd *, asection *);
  731. struct bfd_section_already_linked;
  732. extern bfd_boolean bfd_section_already_linked_table_init (void);
  733. extern void bfd_section_already_linked_table_free (void);
  734. extern bfd_boolean _bfd_handle_already_linked
  735. (struct bfd_section *, struct bfd_section_already_linked *,
  736. struct bfd_link_info *);
  737. extern struct bfd_section *_bfd_nearby_section
  738. (bfd *, struct bfd_section *, bfd_vma);
  739. extern void _bfd_fix_excluded_sec_syms
  740. (bfd *, struct bfd_link_info *);
  741. /* These structures are used to describe version information for the
  742. ELF linker. These structures could be manipulated entirely inside
  743. BFD, but it would be a pain. Instead, the regular linker sets up
  744. these structures, and then passes them into BFD. */
  745. /* Glob pattern for a version. */
  746. struct bfd_elf_version_expr
  747. {
  748. /* Next glob pattern for this version. */
  749. struct bfd_elf_version_expr *next;
  750. /* Glob pattern. */
  751. const char *pattern;
  752. /* Set if pattern is not a glob. */
  753. unsigned int literal : 1;
  754. /* Defined by ".symver". */
  755. unsigned int symver : 1;
  756. /* Defined by version script. */
  757. unsigned int script : 1;
  758. /* Pattern type. */
  759. #define BFD_ELF_VERSION_C_TYPE 1
  760. #define BFD_ELF_VERSION_CXX_TYPE 2
  761. #define BFD_ELF_VERSION_JAVA_TYPE 4
  762. unsigned int mask : 3;
  763. };
  764. struct bfd_elf_version_expr_head
  765. {
  766. /* List of all patterns, both wildcards and non-wildcards. */
  767. struct bfd_elf_version_expr *list;
  768. /* Hash table for non-wildcards. */
  769. void *htab;
  770. /* Remaining patterns. */
  771. struct bfd_elf_version_expr *remaining;
  772. /* What kind of pattern types are present in list (bitmask). */
  773. unsigned int mask;
  774. };
  775. /* Version dependencies. */
  776. struct bfd_elf_version_deps
  777. {
  778. /* Next dependency for this version. */
  779. struct bfd_elf_version_deps *next;
  780. /* The version which this version depends upon. */
  781. struct bfd_elf_version_tree *version_needed;
  782. };
  783. /* A node in the version tree. */
  784. struct bfd_elf_version_tree
  785. {
  786. /* Next version. */
  787. struct bfd_elf_version_tree *next;
  788. /* Name of this version. */
  789. const char *name;
  790. /* Version number. */
  791. unsigned int vernum;
  792. /* Regular expressions for global symbols in this version. */
  793. struct bfd_elf_version_expr_head globals;
  794. /* Regular expressions for local symbols in this version. */
  795. struct bfd_elf_version_expr_head locals;
  796. /* List of versions which this version depends upon. */
  797. struct bfd_elf_version_deps *deps;
  798. /* Index of the version name. This is used within BFD. */
  799. unsigned int name_indx;
  800. /* Whether this version tree was used. This is used within BFD. */
  801. int used;
  802. /* Matching hook. */
  803. struct bfd_elf_version_expr *(*match)
  804. (struct bfd_elf_version_expr_head *head,
  805. struct bfd_elf_version_expr *prev, const char *sym);
  806. };
  807. struct bfd_elf_dynamic_list
  808. {
  809. struct bfd_elf_version_expr_head head;
  810. struct bfd_elf_version_expr *(*match)
  811. (struct bfd_elf_version_expr_head *head,
  812. struct bfd_elf_version_expr *prev, const char *sym);
  813. };
  814. #endif