bfdlink.h 38 KB

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