forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf-bfd.h
3328 lines (2818 loc) · 119 KB
/
elf-bfd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* BFD back-end data structures for ELF files.
Copyright (C) 1992-2025 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef _LIBELF_H_
#define _LIBELF_H_ 1
#include <stdlib.h>
#include "elf/common.h"
#include "elf/external.h"
#include "elf/internal.h"
#include "bfdlink.h"
#ifndef ENABLE_CHECKING
#define ENABLE_CHECKING 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* The number of entries in a section is its size divided by the size
of a single entry. This is normally only applicable to reloc and
symbol table sections.
PR 9934: It is possible to have relocations that do not refer to
symbols, thus it is also possible to have a relocation section in
an object file, but no symbol table. */
#define NUM_SHDR_ENTRIES(shdr) ((shdr)->sh_entsize > 0 ? (shdr)->sh_size / (shdr)->sh_entsize : 0)
/* If size isn't specified as 64 or 32, NAME macro should fail. */
#ifndef NAME
#if ARCH_SIZE == 64
#define NAME(x, y) x ## 64 ## _ ## y
#endif
#if ARCH_SIZE == 32
#define NAME(x, y) x ## 32 ## _ ## y
#endif
#endif
#ifndef NAME
#define NAME(x, y) x ## NOSIZE ## _ ## y
#endif
#define ElfNAME(X) NAME(Elf,X)
#define elfNAME(X) NAME(elf,X)
/* Information held for an ELF symbol. The first field is the
corresponding asymbol. Every symbol is an ELF file is actually a
pointer to this structure, although it is often handled as a
pointer to an asymbol. */
typedef struct
{
/* The BFD symbol. */
asymbol symbol;
/* ELF symbol information. */
Elf_Internal_Sym internal_elf_sym;
/* Backend specific information. */
union
{
unsigned int hppa_arg_reloc;
void *mips_extr;
void *any;
}
tc_data;
/* Version information. This is from an Elf_Internal_Versym
structure in a SHT_GNU_versym section. It is zero if there is no
version information. */
unsigned short version;
} elf_symbol_type;
struct elf_strtab_hash;
struct got_entry;
struct plt_entry;
union gotplt_union
{
bfd_signed_vma refcount;
bfd_vma offset;
struct got_entry *glist;
struct plt_entry *plist;
};
struct elf_link_virtual_table_entry
{
/* Virtual table entry use information. This array is nominally of size
size/sizeof(target_void_pointer), though we have to be able to assume
and track a size while the symbol is still undefined. It is indexed
via offset/sizeof(target_void_pointer). */
size_t size;
bool *used;
/* Virtual table derivation info. */
struct elf_link_hash_entry *parent;
};
/* ELF symbol version. */
enum elf_symbol_version
{
unknown = 0,
unversioned,
versioned,
versioned_hidden
};
/* ELF linker hash table entries. */
struct elf_link_hash_entry
{
struct bfd_link_hash_entry root;
/* Symbol index in output file. This is initialized to -1. It is
set to -2 if the symbol is used by a reloc. It is set to -3 if
this symbol is defined in a discarded section. */
long indx;
/* Symbol index as a dynamic symbol. Initialized to -1, and remains
-1 if this is not a dynamic symbol. */
/* ??? Note that this is consistently used as a synonym for tests
against whether we can perform various simplifying transformations
to the code. (E.g. changing a pc-relative jump to a PLT entry
into a pc-relative jump to the target function.) That test, which
is often relatively complex, and someplaces wrong or incomplete,
should really be replaced by a predicate in elflink.c.
End result: this field -1 does not indicate that the symbol is
not in the dynamic symbol table, but rather that the symbol is
not visible outside this DSO. */
long dynindx;
/* If this symbol requires an entry in the global offset table, the
processor specific backend uses this field to track usage and
final offset. Two schemes are supported: The first assumes that
a symbol may only have one GOT entry, and uses REFCOUNT until
size_dynamic_sections, at which point the contents of the .got is
fixed. Afterward, if OFFSET is -1, then the symbol does not
require a global offset table entry. The second scheme allows
multiple GOT entries per symbol, managed via a linked list
pointed to by GLIST. */
union gotplt_union got;
/* Same, but tracks a procedure linkage table entry. */
union gotplt_union plt;
/* Symbol size. NB: All fields starting from here are cleared by
_bfd_elf_link_hash_newfunc. */
bfd_size_type size;
/* Track dynamic relocs copied for this symbol. */
struct elf_dyn_relocs *dyn_relocs;
/* Symbol type (STT_NOTYPE, STT_OBJECT, etc.). */
unsigned int type : 8;
/* Symbol st_other value, symbol visibility. */
unsigned int other : 8;
/* The symbol's st_target_internal value (see Elf_Internal_Sym). */
unsigned int target_internal : 8;
/* Symbol is referenced by a non-shared object (other than the object
in which it is defined). */
unsigned int ref_regular : 1;
/* Symbol is defined by a non-shared object. */
unsigned int def_regular : 1;
/* Symbol is referenced by a shared object. */
unsigned int ref_dynamic : 1;
/* Symbol is defined by a shared object. */
unsigned int def_dynamic : 1;
/* Symbol has a non-weak reference from a non-shared object (other than
the object in which it is defined). */
unsigned int ref_regular_nonweak : 1;
/* Symbol has a non-weak reference from a LTO IR object file. */
unsigned int ref_ir_nonweak : 1;
/* Dynamic symbol has been adjustd. */
unsigned int dynamic_adjusted : 1;
/* Symbol needs a copy reloc. */
unsigned int needs_copy : 1;
/* Symbol needs a procedure linkage table entry. */
unsigned int needs_plt : 1;
/* Symbol appears in a non-ELF input file. */
unsigned int non_elf : 1;
/* Symbol version information. */
ENUM_BITFIELD (elf_symbol_version) versioned : 2;
/* Symbol was forced to local scope due to a version script file. */
unsigned int forced_local : 1;
/* Symbol was forced to be dynamic due to a version script file. */
unsigned int dynamic : 1;
/* Symbol was marked during garbage collection. */
unsigned int mark : 1;
/* Symbol is referenced by a non-GOT/non-PLT relocation. This is
not currently set by all the backends. */
unsigned int non_got_ref : 1;
/* Symbol has a definition in a shared object.
FIXME: There is no real need for this field if def_dynamic is never
cleared and all places that test def_dynamic also test def_regular. */
unsigned int dynamic_def : 1;
/* Symbol has a non-weak reference from a shared object. */
unsigned int ref_dynamic_nonweak : 1;
/* Symbol is referenced with a relocation where C/C++ pointer equality
matters. */
unsigned int pointer_equality_needed : 1;
/* Symbol is a unique global symbol. */
unsigned int unique_global : 1;
/* Symbol is defined by a shared library with non-default visibility
in a read/write section. */
unsigned int protected_def : 1;
/* Symbol is __start_SECNAME or __stop_SECNAME to mark section
SECNAME. */
unsigned int start_stop : 1;
/* Symbol is or was a weak defined symbol from a dynamic object with
a strong defined symbol alias. U.ALIAS points to a list of aliases,
the definition having is_weakalias clear. */
unsigned int is_weakalias : 1;
/* Symbol has a relocation. */
unsigned int has_reloc : 1;
/* String table index in .dynstr if this is a dynamic symbol. */
unsigned long dynstr_index;
union
{
/* Points to a circular list of non-function symbol aliases. */
struct elf_link_hash_entry *alias;
/* Hash value of the name computed using the ELF hash function.
Used part way through size_dynamic_sections, after we've finished
with aliases. */
unsigned long elf_hash_value;
} u;
/* Version information. */
union
{
/* This field is used for a symbol which is not defined in a
regular object. It points to the version information read in
from the dynamic object. */
Elf_Internal_Verdef *verdef;
/* This field is used for a symbol which is defined in a regular
object. It is set up in size_dynamic_sections. It points to
the version information we should write out for this symbol. */
struct bfd_elf_version_tree *vertree;
} verinfo;
union
{
/* For __start_SECNAME and __stop_SECNAME symbols, record the first
input section whose section name is SECNAME. */
asection *start_stop_section;
/* Vtable information. */
struct elf_link_virtual_table_entry *vtable;
} u2;
};
/* Return the strong definition for a weak symbol with aliases. */
static inline struct elf_link_hash_entry *
weakdef (struct elf_link_hash_entry *h)
{
while (h->is_weakalias)
h = h->u.alias;
return h;
}
/* Will references to this symbol always reference the symbol
in this object? */
#define SYMBOL_REFERENCES_LOCAL(INFO, H) \
_bfd_elf_symbol_refs_local_p (H, INFO, 0)
/* Will _calls_ to this symbol always call the version in this object? */
#define SYMBOL_CALLS_LOCAL(INFO, H) \
_bfd_elf_symbol_refs_local_p (H, INFO, 1)
/* Whether an undefined weak symbol should resolve to its link-time
value, even in PIC or PIE objects. The linker_def test is to
handle symbols like __ehdr_start that may be undefweak in early
stages of linking but are guaranteed to be defined later. */
#define UNDEFWEAK_NO_DYNAMIC_RELOC(INFO, H) \
((H)->root.type == bfd_link_hash_undefweak \
&& !(H)->root.linker_def \
&& (ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT \
|| (INFO)->dynamic_undefined_weak == 0))
/* Common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, so they might appear to be undefined.
Symbols defined in linker scripts also don't have DEF_REGULAR set. */
#define ELF_COMMON_DEF_P(H) \
(!(H)->def_regular \
&& !(H)->def_dynamic \
&& (H)->root.type == bfd_link_hash_defined)
/* Records local symbols to be emitted in the dynamic symbol table. */
struct elf_link_local_dynamic_entry
{
struct elf_link_local_dynamic_entry *next;
/* The input bfd this symbol came from. */
bfd *input_bfd;
/* The index of the local symbol being copied. */
long input_indx;
/* The index in the outgoing dynamic symbol table. */
long dynindx;
/* A copy of the input symbol. */
Elf_Internal_Sym isym;
};
struct elf_link_loaded_list
{
struct elf_link_loaded_list *next;
bfd *abfd;
};
/* Structures used by the eh_frame optimization code. */
struct eh_cie_fde
{
union {
struct {
/* If REMOVED == 1, this is the CIE that the FDE originally used.
The CIE belongs to the same .eh_frame input section as the FDE.
If REMOVED == 0, this is the CIE that we have chosen to use for
the output FDE. The CIE's REMOVED field is also 0, but the CIE
might belong to a different .eh_frame input section from the FDE.
May be NULL to signify that the FDE should be discarded. */
struct eh_cie_fde *cie_inf;
struct eh_cie_fde *next_for_section;
} fde;
struct {
/* CIEs have three states:
- REMOVED && !MERGED: Slated for removal because we haven't yet
proven that an FDE needs it. FULL_CIE, if nonnull, points to
more detailed information about the CIE.
- REMOVED && MERGED: We have merged this CIE with MERGED_WITH,
which may not belong to the same input section.
- !REMOVED: We have decided to keep this CIE. SEC is the
.eh_frame input section that contains the CIE. */
union {
struct cie *full_cie;
struct eh_cie_fde *merged_with;
asection *sec;
} u;
/* The offset of the personality data from the start of the CIE,
or 0 if the CIE doesn't have any. */
unsigned int personality_offset : 8;
/* Length of augmentation. aug_str_len is the length of the
string including null terminator. aug_data_len is the length
of the rest up to the initial insns. */
unsigned int aug_str_len : 3;
unsigned int aug_data_len : 5;
/* True if we have marked relocations associated with this CIE. */
unsigned int gc_mark : 1;
/* True if we have decided to turn an absolute LSDA encoding into
a PC-relative one. */
unsigned int make_lsda_relative : 1;
/* True if we have decided to turn an absolute personality
encoding into a PC-relative one. */
unsigned int make_per_encoding_relative : 1;
/* True if the CIE contains personality data and if that
data uses a PC-relative encoding. Always true when
make_per_encoding_relative is. */
unsigned int per_encoding_relative : 1;
/* True if the CIE contains personality data aligned to a
multiple of eight bytes. */
unsigned int per_encoding_aligned8 : 1;
/* True if we need to add an 'R' (FDE encoding) entry to the
CIE's augmentation data. */
unsigned int add_fde_encoding : 1;
/* True if we have merged this CIE with another. */
unsigned int merged : 1;
/* Unused bits. */
unsigned int pad1 : 9;
} cie;
} u;
unsigned int reloc_index;
unsigned int size;
unsigned int offset;
unsigned int new_offset;
unsigned int fde_encoding : 8;
unsigned int lsda_encoding : 8;
unsigned int lsda_offset : 8;
/* True if this entry represents a CIE, false if it represents an FDE. */
unsigned int cie : 1;
/* True if this entry is currently marked for removal. */
unsigned int removed : 1;
/* True if we need to add a 'z' (augmentation size) entry to the CIE's
augmentation data, and an associated byte to each of the CIE's FDEs. */
unsigned int add_augmentation_size : 1;
/* True if we have decided to convert absolute FDE relocations into
relative ones. This applies to the first relocation in the FDE,
which is against the code that the FDE describes. */
unsigned int make_relative : 1;
/* Unused bits. */
unsigned int pad1 : 4;
unsigned int *set_loc;
};
struct eh_frame_sec_info
{
unsigned int count;
struct cie *cies;
struct eh_cie_fde entry[1];
};
struct eh_frame_array_ent
{
bfd_vma initial_loc;
bfd_size_type range;
bfd_vma fde;
};
struct htab;
#define DWARF2_EH_HDR 1
#define COMPACT_EH_HDR 2
/* Endian-neutral code indicating that a function cannot be unwound. */
#define COMPACT_EH_CANT_UNWIND_OPCODE 0x015d5d01
struct dwarf_eh_frame_hdr_info
{
struct htab *cies;
unsigned int fde_count;
/* TRUE if .eh_frame_hdr should contain the sorted search table.
We build it if we successfully read all .eh_frame input sections
and recognize them. */
bool table;
struct eh_frame_array_ent *array;
};
struct compact_eh_frame_hdr_info
{
unsigned int allocated_entries;
/* eh_frame_entry fragments. */
asection **entries;
};
struct eh_frame_hdr_info
{
asection *hdr_sec;
unsigned int array_count;
bool frame_hdr_is_compact;
union
{
struct dwarf_eh_frame_hdr_info dwarf;
struct compact_eh_frame_hdr_info compact;
}
u;
};
/* Additional information for each function (used at link time). */
struct sframe_func_bfdinfo
{
/* Whether the function has been discarded from the final output. */
bool func_deleted_p;
/* Relocation offset. */
unsigned int func_r_offset;
/* Relocation index. */
unsigned int func_reloc_index;
};
/* SFrame decoder info.
Contains all information for a decoded .sframe section. */
struct sframe_dec_info
{
/* Decoder context. */
struct sframe_decoder_ctx *sfd_ctx;
/* Number of function descriptor entries in this .sframe. */
unsigned int sfd_fde_count;
/* Additional information for linking. */
struct sframe_func_bfdinfo *sfd_func_bfdinfo;
};
/* SFrame encoder info.
Contains all information for an encoded .sframe section to be
written out. */
struct sframe_enc_info
{
/* Encoder context. */
struct sframe_encoder_ctx *sfe_ctx;
/* Output section. */
asection *sframe_section;
};
/* Enum used to identify target specific extensions to the elf_obj_tdata
and elf_link_hash_table structures. Note the enums deliberately start
from 1 so that we can detect an uninitialized field. The generic value
is last so that additions to this enum do not need to modify more than
one line. */
enum elf_target_id
{
AARCH64_ELF_DATA = 1,
ALPHA_ELF_DATA,
AMDGCN_ELF_DATA,
ARC_ELF_DATA,
ARM_ELF_DATA,
AVR_ELF_DATA,
BFIN_ELF_DATA,
CR16_ELF_DATA,
CRIS_ELF_DATA,
CSKY_ELF_DATA,
FRV_ELF_DATA,
HPPA32_ELF_DATA,
HPPA64_ELF_DATA,
I386_ELF_DATA,
IA64_ELF_DATA,
KVX_ELF_DATA,
LARCH_ELF_DATA,
LM32_ELF_DATA,
M32R_ELF_DATA,
M68HC11_ELF_DATA,
M68K_ELF_DATA,
METAG_ELF_DATA,
MICROBLAZE_ELF_DATA,
MIPS_ELF_DATA,
MMIX_ELF_DATA,
MN10300_ELF_DATA,
NDS32_ELF_DATA,
OR1K_ELF_DATA,
PPC32_ELF_DATA,
PPC64_ELF_DATA,
PRU_ELF_DATA,
RISCV_ELF_DATA,
S390_ELF_DATA,
SCORE_ELF_DATA,
SH_ELF_DATA,
SPARC_ELF_DATA,
SPU_ELF_DATA,
TIC6X_ELF_DATA,
TILEGX_ELF_DATA,
TILEPRO_ELF_DATA,
X86_64_ELF_DATA,
XTENSA_ELF_DATA,
VAX_ELF_DATA,
GENERIC_ELF_DATA
};
struct elf_sym_strtab
{
Elf_Internal_Sym sym;
unsigned long dest_index;
};
struct bfd_link_needed_list
{
struct bfd_link_needed_list *next;
bfd *by;
const char *name;
};
enum elf_target_os
{
is_normal,
is_solaris, /* Solaris. */
is_vxworks, /* VxWorks. */
is_nacl /* Native Client. */
};
/* Used by bfd_sym_from_r_symndx to cache a small number of local
symbols. */
#define LOCAL_SYM_CACHE_SIZE 32
struct sym_cache
{
bfd *abfd;
unsigned long indx[LOCAL_SYM_CACHE_SIZE];
Elf_Internal_Sym sym[LOCAL_SYM_CACHE_SIZE];
};
/* ELF linker hash table. */
struct elf_link_hash_table
{
struct bfd_link_hash_table root;
/* An identifier used to distinguish different target
specific extensions to this structure. */
enum elf_target_id hash_table_id;
/* Whether we have created the special dynamic sections required
when linking against or generating a shared object. */
bool dynamic_sections_created;
/* Whether dynamic relocations are present. */
bool dynamic_relocs;
/* True if this target has relocatable executables, so needs dynamic
section symbols. */
bool is_relocatable_executable;
/* TRUE if there are IFUNC resolvers. */
bool ifunc_resolvers;
/* TRUE if DT_PLTGOT is a required dynamic tag. */
bool dt_pltgot_required;
/* TRUE if DT_JMPREL is a required dynamic tag. */
bool dt_jmprel_required;
/* TRUE when we are handling DT_NEEDED entries. */
bool handling_dt_needed;
/* The BFD used to hold special sections created by the linker.
This will be the first BFD found which requires these sections to
be created. */
bfd *dynobj;
/* The value to use when initialising got.refcount/offset and
plt.refcount/offset in an elf_link_hash_entry. Set to zero when
the values are refcounts. Set to init_got_offset/init_plt_offset
in size_dynamic_sections when the values may be offsets. */
union gotplt_union init_got_refcount;
union gotplt_union init_plt_refcount;
/* The value to use for got.refcount/offset and plt.refcount/offset
when the values may be offsets. Normally (bfd_vma) -1. */
union gotplt_union init_got_offset;
union gotplt_union init_plt_offset;
/* The number of symbols found in the link which is intended for the
mandatory DT_SYMTAB tag (.dynsym section) in .dynamic section. */
bfd_size_type dynsymcount;
bfd_size_type local_dynsymcount;
/* The string table of dynamic symbols, which becomes the .dynstr
section. */
struct elf_strtab_hash *dynstr;
/* The array size of the symbol string table, which becomes the
.strtab section. */
bfd_size_type strtabsize;
/* The array of strings, which becomes the .strtab section. */
struct elf_sym_strtab *strtab;
/* The number of buckets in the hash table in the .hash section.
This is based on the number of dynamic symbols. */
bfd_size_type bucketcount;
/* A linked list of DT_NEEDED names found in dynamic objects
included in the link. */
struct bfd_link_needed_list *needed;
/* Sections in the output bfd that provides a section symbol
to be used by relocations emitted against local symbols.
Most targets will not use data_index_section. */
asection *text_index_section;
asection *data_index_section;
/* The _GLOBAL_OFFSET_TABLE_ symbol. */
struct elf_link_hash_entry *hgot;
/* The _PROCEDURE_LINKAGE_TABLE_ symbol. */
struct elf_link_hash_entry *hplt;
/* The _DYNAMIC symbol. */
struct elf_link_hash_entry *hdynamic;
/* The __ehdr_start symbol. */
struct elf_link_hash_entry *hehdr_start;
/* A pointer to information used to merge SEC_MERGE sections. */
void *merge_info;
/* Used to link stabs in sections. */
struct stab_info stab_info;
/* Used by eh_frame code when editing .eh_frame. */
struct eh_frame_hdr_info eh_info;
/* Used to link stack trace info in .sframe sections. */
struct sframe_enc_info sfe_info;
/* A linked list of local symbols to be added to .dynsym. */
struct elf_link_local_dynamic_entry *dynlocal;
/* A linked list of DT_RPATH/DT_RUNPATH names found in dynamic
objects included in the link. */
struct bfd_link_needed_list *runpath;
/* Cached first output tls section and size of PT_TLS segment. */
asection *tls_sec;
bfd_size_type tls_size; /* Bytes. */
/* The offset into splt of the PLT entry for the TLS descriptor
resolver. Special values are 0, if not necessary (or not found
to be necessary yet), and -1 if needed but not determined
yet. */
bfd_vma tlsdesc_plt;
/* The GOT offset for the lazy trampoline. Communicated to the
loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
indicates an offset is not allocated. */
bfd_vma tlsdesc_got;
/* Target OS for linker output. */
enum elf_target_os target_os;
/* A linked list of dynamic BFD's loaded in the link. */
struct elf_link_loaded_list *dyn_loaded;
/* Small local sym cache. */
struct sym_cache sym_cache;
/* Hash table of symbols which are first defined in archives or shared
objects when there are any IR inputs. */
struct bfd_hash_table *first_hash;
/* Short-cuts to get to dynamic linker sections. */
asection *sgot;
asection *sgotplt;
asection *srelgot;
asection *splt;
asection *srelplt;
asection *sdynbss;
asection *srelbss;
asection *sdynrelro;
asection *sreldynrelro;
asection *igotplt;
asection *iplt;
asection *irelplt;
asection *irelifunc;
asection *dynsym;
asection *srelrdyn;
asection *dynamic;
};
/* Returns TRUE if the hash table is a struct elf_link_hash_table. */
static inline bool
is_elf_hash_table (const struct bfd_link_hash_table *htab)
{
return htab->type == bfd_link_elf_hash_table;
}
/* Look up an entry in an ELF linker hash table. */
static inline struct elf_link_hash_entry *
elf_link_hash_lookup (struct elf_link_hash_table *table, const char *string,
bool create, bool copy, bool follow)
{
if (ENABLE_CHECKING && !is_elf_hash_table (&table->root))
abort ();
return (struct elf_link_hash_entry *)
bfd_link_hash_lookup (&table->root, string, create, copy, follow);
}
/* Traverse an ELF linker hash table. */
static inline void
elf_link_hash_traverse (struct elf_link_hash_table *table,
bool (*f) (struct elf_link_hash_entry *, void *),
void *info)
{
if (ENABLE_CHECKING && !is_elf_hash_table (&table->root))
abort ();
bfd_link_hash_traverse (&table->root,
(bool (*) (struct bfd_link_hash_entry *, void *)) f,
info);
}
/* Get the ELF linker hash table from a link_info structure. */
static inline struct elf_link_hash_table *
elf_hash_table (const struct bfd_link_info *info)
{
return (struct elf_link_hash_table *) info->hash;
}
static inline enum elf_target_id
elf_hash_table_id (const struct elf_link_hash_table *table)
{
return table->hash_table_id;
}
/* Constant information held for an ELF backend. */
struct elf_size_info {
unsigned char sizeof_ehdr, sizeof_phdr, sizeof_shdr;
unsigned char sizeof_rel, sizeof_rela, sizeof_sym, sizeof_dyn, sizeof_note;
/* The size of entries in the .hash section. */
unsigned char sizeof_hash_entry;
/* The number of internal relocations to allocate per external
relocation entry. */
unsigned char int_rels_per_ext_rel;
/* We use some fixed size arrays. This should be large enough to
handle all back-ends. */
#define MAX_INT_RELS_PER_EXT_REL 3
unsigned char arch_size, log_file_align;
unsigned char elfclass, ev_current;
int (*write_out_phdrs)
(bfd *, const Elf_Internal_Phdr *, unsigned int);
bool (*write_shdrs_and_ehdr) (bfd *);
bool (*checksum_contents)
(bfd * , void (*) (const void *, size_t, void *), void *);
void (*write_relocs)
(bfd *, asection *, void *);
bool (*swap_symbol_in)
(bfd *, const void *, const void *, Elf_Internal_Sym *);
void (*swap_symbol_out)
(bfd *, const Elf_Internal_Sym *, void *, void *);
bool (*slurp_reloc_table)
(bfd *, asection *, asymbol **, bool);
long (*slurp_symbol_table)
(bfd *, asymbol **, bool);
void (*swap_dyn_in)
(bfd *, const void *, Elf_Internal_Dyn *);
void (*swap_dyn_out)
(bfd *, const Elf_Internal_Dyn *, void *);
/* This function is called to swap in a REL relocation. If an
external relocation corresponds to more than one internal
relocation, then all relocations are swapped in at once. */
void (*swap_reloc_in)
(bfd *, const bfd_byte *, Elf_Internal_Rela *);
/* This function is called to swap out a REL relocation. */
void (*swap_reloc_out)
(bfd *, const Elf_Internal_Rela *, bfd_byte *);
/* This function is called to swap in a RELA relocation. If an
external relocation corresponds to more than one internal
relocation, then all relocations are swapped in at once. */
void (*swap_reloca_in)
(bfd *, const bfd_byte *, Elf_Internal_Rela *);
/* This function is called to swap out a RELA relocation. */
void (*swap_reloca_out)
(bfd *, const Elf_Internal_Rela *, bfd_byte *);
};
#define elf_symbol_from(S) \
((((S)->flags & BSF_SYNTHETIC) == 0 \
&& (S)->the_bfd != NULL \
&& (S)->the_bfd->xvec->flavour == bfd_target_elf_flavour \
&& (S)->the_bfd->tdata.elf_obj_data != 0) \
? (elf_symbol_type *) (S) \
: 0)
enum elf_reloc_type_class {
reloc_class_normal,
reloc_class_relative,
reloc_class_copy,
reloc_class_ifunc,
reloc_class_plt
};
struct elf_reloc_cookie
{
Elf_Internal_Rela *rels, *rel, *relend;
Elf_Internal_Sym *locsyms;
bfd *abfd;
size_t locsymcount;
size_t extsymoff;
struct elf_link_hash_entry **sym_hashes;
int r_sym_shift;
bool bad_symtab;
};
/* The level of IRIX compatibility we're striving for. */
typedef enum {
ict_none,
ict_irix5,
ict_irix6
} irix_compat_t;
/* Mapping of ELF section names and types. */
struct bfd_elf_special_section
{
const char *prefix;
unsigned int prefix_length;
/* 0 means name must match PREFIX exactly.
-1 means name must start with PREFIX followed by an arbitrary string.
-2 means name must match PREFIX exactly or consist of PREFIX followed
by a dot then anything.
> 0 means name must start with the first PREFIX_LENGTH chars of
PREFIX and finish with the last SUFFIX_LENGTH chars of PREFIX. */
signed int suffix_length;
unsigned int type;
bfd_vma attr;
};
enum action_discarded
{
COMPLAIN = 1,
PRETEND = 2
};
typedef asection * (*elf_gc_mark_hook_fn)
(asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *, Elf_Internal_Sym *);
enum elf_property_kind
{
/* A new property. */
property_unknown = 0,
/* A property ignored by backend. */
property_ignored,
/* A corrupt property reported by backend. */
property_corrupt,
/* A property should be removed due to property merge. */
property_remove,
/* A property which is a number. */
property_number
};
typedef struct elf_property
{
unsigned int pr_type;
unsigned int pr_datasz;
union
{
/* For property_number, this is a number. */
bfd_vma number;
/* Add a new one if elf_property_kind is updated. */
} u;
enum elf_property_kind pr_kind;
} elf_property;
typedef struct elf_property_list
{
struct elf_property_list *next;
struct elf_property property;
} elf_property_list;
/* This structure is used to pass information to
elf_backend_add_glibc_version_dependency. */
struct elf_find_verdep_info
{
/* General link information. */
struct bfd_link_info *info;
/* The number of dependencies. */
unsigned int vers;
/* Whether we had a failure. */
bool failed;
};
struct bfd_elf_section_reloc_data;
struct elf_backend_data
{
/* The architecture for this backend. */
enum bfd_architecture arch;
/* An identifier used to distinguish different target specific
extensions to elf_obj_tdata and elf_link_hash_table structures. */
enum elf_target_id target_id;
/* Target OS. */
enum elf_target_os target_os;
/* The ELF machine code (EM_xxxx) for this backend. */