bfdlink.h 37 KB

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