source: Daodan/MSYS2/mingw32/include/binutils/bfdlink.h@ 1179

Last change on this file since 1179 was 1166, checked in by rossy, 3 years ago

Daodan: Replace MinGW build env with an up-to-date MSYS2 env

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