]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elfxx-x86.h
MSP430 Linker: Define __crt0_init_bss/__crt0_movedata symbols when .lower or .either...
[thirdparty/binutils-gdb.git] / bfd / elfxx-x86.h
CommitLineData
0afcef53 1/* x86 specific support for ELF
82704155 2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
0afcef53
L
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21#include "sysdep.h"
22#include "bfd.h"
23#include "bfdlink.h"
24#include "libbfd.h"
25#include "elf-bfd.h"
0afcef53 26#include "hashtab.h"
5b9c07b2 27#include "elf-linker-x86.h"
0afcef53 28
aa595247
L
29#define PLT_CIE_LENGTH 20
30#define PLT_FDE_LENGTH 36
31#define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
32#define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
33
765e526c
L
34#define ABI_64_P(abfd) \
35 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
36
0afcef53
L
37/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
38 copying dynamic variables from a shared lib into an app's dynbss
39 section, and instead use a dynamic relocation to point into the
40 shared lib. */
41#define ELIMINATE_COPY_RELOCS 1
42
43#define elf_x86_hash_table(p, id) \
1cf58434
AM
44 (is_elf_hash_table ((p)->hash) \
45 && elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) == (id) \
0afcef53
L
46 ? ((struct elf_x86_link_hash_table *) ((p)->hash)) : NULL)
47
6999821f
L
48/* Will references to this symbol always be local in this object? */
49#define SYMBOL_REFERENCES_LOCAL_P(INFO, H) \
50 _bfd_x86_elf_link_symbol_references_local ((INFO), (H))
51
99180bcc
L
52/* TRUE if an undefined weak symbol should be resolved to 0. Local
53 undefined weak symbol is always resolved to 0. Reference to an
54 undefined weak symbol is resolved to 0 in executable if undefined
55 weak symbol should be resolved to 0 (zero_undefweak > 0). */
c5bce5c6 56#define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \
0afcef53 57 ((EH)->elf.root.type == bfd_link_hash_undefweak \
6999821f 58 && (SYMBOL_REFERENCES_LOCAL_P ((INFO), &(EH)->elf) \
0afcef53 59 || (bfd_link_executable (INFO) \
98b273dc 60 && (EH)->zero_undefweak > 0)))
0afcef53
L
61
62/* Should copy relocation be generated for a symbol. Don't generate
63 copy relocation against a protected symbol defined in a shared
64 object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. */
65#define SYMBOL_NO_COPYRELOC(INFO, EH) \
66 ((EH)->def_protected \
67 && ((EH)->elf.root.type == bfd_link_hash_defined \
68 || (EH)->elf.root.type == bfd_link_hash_defweak) \
69 && elf_has_no_copy_on_protected ((EH)->elf.root.u.def.section->owner) \
70 && ((EH)->elf.root.u.def.section->owner->flags & DYNAMIC) != 0 \
71 && ((EH)->elf.root.u.def.section->flags & SEC_CODE) == 0)
72
daf1c414
L
73/* TRUE if dynamic relocation is needed. If we are creating a shared
74 library, and this is a reloc against a global symbol, or a non PC
75 relative reloc against a local symbol, then we need to copy the reloc
76 into the shared library. However, if we are linking with -Bsymbolic,
77 we do not need to copy a reloc against a global symbol which is
78 defined in an object we are including in the link (i.e., DEF_REGULAR
451875b4
L
79 is set).
80
81 If PCREL_PLT is true, don't generate dynamic relocation in PIE for
82 PC-relative relocation against a dynamic function definition in data
83 section when PLT address can be used.
daf1c414
L
84
85 If on the other hand, we are creating an executable, we may need to
86 keep relocations for symbols satisfied by a dynamic library if we
87 manage to avoid copy relocs for the symbol.
88
89 We also need to generate dynamic pointer relocation against
90 STT_GNU_IFUNC symbol in the non-code section. */
451875b4
L
91#define NEED_DYNAMIC_RELOCATION_P(INFO, PCREL_PLT, H, SEC, R_TYPE, \
92 POINTER_TYPE) \
daf1c414
L
93 ((bfd_link_pic (INFO) \
94 && (! X86_PCREL_TYPE_P (R_TYPE) \
95 || ((H) != NULL \
96 && (! (bfd_link_pie (INFO) \
97 || SYMBOLIC_BIND ((INFO), (H))) \
98 || (H)->root.type == bfd_link_hash_defweak \
451875b4
L
99 || (!(bfd_link_pie (INFO) \
100 && (PCREL_PLT) \
101 && (H)->plt.refcount > 0 \
102 && ((SEC)->flags & SEC_CODE) == 0 \
103 && (H)->type == STT_FUNC \
104 && (H)->def_dynamic) \
105 && !(H)->def_regular))))) \
106 || ((H) != NULL \
107 && (H)->type == STT_GNU_IFUNC \
108 && (R_TYPE) == POINTER_TYPE \
109 && ((SEC)->flags & SEC_CODE) == 0) \
110 || (ELIMINATE_COPY_RELOCS \
111 && !bfd_link_pic (INFO) \
112 && (H) != NULL \
113 && ((H)->root.type == bfd_link_hash_defweak \
114 || !(H)->def_regular)))
daf1c414 115
aebcc8ff
L
116/* TRUE if dynamic relocation should be generated. Don't copy a
117 pc-relative relocation into the output file if the symbol needs
118 copy reloc or the symbol is undefined when building executable.
119 Copy dynamic function pointer relocations. Don't generate dynamic
120 relocations against resolved undefined weak symbols in PIE, except
121 when PC32_RELOC is TRUE. Undefined weak symbol is bound locally
122 when PIC is false. */
123#define GENERATE_DYNAMIC_RELOCATION_P(INFO, EH, R_TYPE, \
124 NEED_COPY_RELOC_IN_PIE, \
125 RESOLVED_TO_ZERO, PC32_RELOC) \
126 ((bfd_link_pic (INFO) \
127 && !(NEED_COPY_RELOC_IN_PIE) \
128 && ((EH) == NULL \
129 || ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \
130 && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \
131 || (EH)->elf.root.type != bfd_link_hash_undefweak)) \
132 && ((!X86_PCREL_TYPE_P (R_TYPE) \
133 && !X86_SIZE_TYPE_P (R_TYPE)) \
134 || ! SYMBOL_CALLS_LOCAL ((INFO), &(EH)->elf))) \
135 || (ELIMINATE_COPY_RELOCS \
136 && !bfd_link_pic (INFO) \
137 && (EH) != NULL \
138 && (EH)->elf.dynindx != -1 \
139 && (!(EH)->elf.non_got_ref \
aebcc8ff
L
140 || ((EH)->elf.root.type == bfd_link_hash_undefweak \
141 && !(RESOLVED_TO_ZERO))) \
142 && (((EH)->elf.def_dynamic && !(EH)->elf.def_regular) \
143 || (EH)->elf.root.type == bfd_link_hash_undefined)))
144
e74399c4
L
145/* TRUE if this input relocation should be copied to output. H->dynindx
146 may be -1 if this symbol was marked to become local. */
147#define COPY_INPUT_RELOC_P(INFO, H, R_TYPE) \
148 ((H) != NULL \
149 && (H)->dynindx != -1 \
150 && (X86_PCREL_TYPE_P (R_TYPE) \
151 || !(bfd_link_executable (INFO) || SYMBOLIC_BIND ((INFO), (H))) \
152 || !(H)->def_regular))
153
2eba97c2
L
154/* TRUE if this is actually a static link, or it is a -Bsymbolic link
155 and the symbol is defined locally, or the symbol was forced to be
156 local because of a version file. */
157#define RESOLVED_LOCALLY_P(INFO, H, HTAB) \
158 (!WILL_CALL_FINISH_DYNAMIC_SYMBOL ((HTAB)->elf.dynamic_sections_created, \
159 bfd_link_pic (INFO), (H)) \
160 || (bfd_link_pic (INFO) \
161 && SYMBOL_REFERENCES_LOCAL_P ((INFO), (H))) \
162 || (ELF_ST_VISIBILITY ((H)->other) \
163 && (H)->root.type == bfd_link_hash_undefweak))
164
83924b38
L
165/* TRUE if this symbol isn't defined by a shared object. */
166#define SYMBOL_DEFINED_NON_SHARED_P(H) \
167 ((H)->def_regular \
168 || (H)->root.linker_def \
169 || (H)->root.ldscript_def \
170 || ELF_COMMON_DEF_P (H))
171
f70656b2
L
172/* TRUE if relative relocation should be generated. GOT reference to
173 global symbol in PIC will lead to dynamic symbol. It becomes a
174 problem when "time" or "times" is defined as a variable in an
175 executable, clashing with functions of the same name in libc. If a
176 symbol isn't undefined weak symbol, don't make it dynamic in PIC and
177 generate relative relocation. */
178#define GENERATE_RELATIVE_RELOC_P(INFO, H) \
179 ((H)->dynindx == -1 \
180 && !(H)->forced_local \
181 && (H)->root.type != bfd_link_hash_undefweak \
182 && bfd_link_pic (INFO))
183
cf1070f1
L
184/* TRUE if this is a pointer reference to a local IFUNC. */
185#define POINTER_LOCAL_IFUNC_P(INFO, H) \
186 ((H)->dynindx == -1 \
187 || (H)->forced_local \
188 || bfd_link_executable (INFO))
189
190/* TRUE if this is a PLT reference to a local IFUNC. */
191#define PLT_LOCAL_IFUNC_P(INFO, H) \
192 ((H)->dynindx == -1 \
193 || ((bfd_link_executable (INFO) \
194 || ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT) \
195 && (H)->def_regular \
196 && (H)->type == STT_GNU_IFUNC))
197
51537393
L
198/* TRUE if TLS IE->LE transition is OK. */
199#define TLS_TRANSITION_IE_TO_LE_P(INFO, H, TLS_TYPE) \
200 (bfd_link_executable (INFO) \
201 && (H) != NULL \
202 && (H)->dynindx == -1 \
203 && (TLS_TYPE & GOT_TLS_IE))
204
f3180fa9
L
205/* Verify that the symbol has an entry in the procedure linkage table. */
206#define VERIFY_PLT_ENTRY(INFO, H, PLT, GOTPLT, RELPLT, LOCAL_UNDEFWEAK) \
e0d8f431
L
207 do \
208 { \
209 if (((H)->dynindx == -1 \
210 && !LOCAL_UNDEFWEAK \
211 && !(((H)->forced_local || bfd_link_executable (INFO)) \
212 && (H)->def_regular \
213 && (H)->type == STT_GNU_IFUNC)) \
214 || (PLT) == NULL \
215 || (GOTPLT) == NULL \
216 || (RELPLT) == NULL) \
217 abort (); \
218 } \
219 while (0);
f3180fa9 220
ff38b4cc
L
221/* Verify that the symbol supports copy relocation. */
222#define VERIFY_COPY_RELOC(H, HTAB) \
e0d8f431
L
223 do \
224 { \
225 if ((H)->dynindx == -1 \
226 || ((H)->root.type != bfd_link_hash_defined \
227 && (H)->root.type != bfd_link_hash_defweak) \
228 || (HTAB)->elf.srelbss == NULL \
229 || (HTAB)->elf.sreldynrelro == NULL) \
230 abort (); \
231 } \
232 while (0);
ff38b4cc 233
0afcef53
L
234/* x86 ELF linker hash entry. */
235
236struct elf_x86_link_hash_entry
237{
238 struct elf_link_hash_entry elf;
239
240 /* Track dynamic relocs copied for this symbol. */
241 struct elf_dyn_relocs *dyn_relocs;
242
243 unsigned char tls_type;
244
98b273dc
L
245 /* Bit 0: Symbol has no GOT nor PLT relocations.
246 Bit 1: Symbol has non-GOT/non-PLT relocations in text sections.
247 zero_undefweak is initialized to 1 and undefined weak symbol
248 should be resolved to 0 if zero_undefweak > 0. */
249 unsigned int zero_undefweak : 2;
0afcef53
L
250
251 /* Don't call finish_dynamic_symbol on this symbol. */
252 unsigned int no_finish_dynamic_symbol : 1;
253
254 /* TRUE if symbol is __tls_get_addr. */
255 unsigned int tls_get_addr : 1;
256
257 /* TRUE if symbol is defined as a protected symbol. */
258 unsigned int def_protected : 1;
259
6999821f
L
260 /* 0: Symbol references are unknown.
261 1: Symbol references aren't local.
262 2: Symbol references are local.
263 */
264 unsigned int local_ref : 2;
265
0a27fed7
L
266 /* TRUE if symbol is defined by linker. */
267 unsigned int linker_def : 1;
268
f47432d4 269 /* TRUE if symbol is referenced by R_386_GOTOFF relocation. This is
c7df954f 270 only used by i386. */
0afcef53
L
271 unsigned int gotoff_ref : 1;
272
273 /* TRUE if a weak symbol with a real definition needs a copy reloc.
274 When there is a weak symbol with a real definition, the processor
275 independent code will have arranged for us to see the real
276 definition first. We need to copy the needs_copy bit from the
277 real definition and check it when allowing copy reloc in PIE. This
278 is only used by x86-64. */
279 unsigned int needs_copy : 1;
280
0afcef53
L
281 /* Information about the GOT PLT entry. Filled when there are both
282 GOT and PLT relocations against the same function. */
283 union gotplt_union plt_got;
284
285 /* Information about the second PLT entry. */
286 union gotplt_union plt_second;
287
288 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
289 starting at the end of the jump table. */
290 bfd_vma tlsdesc_got;
291};
292
765e526c
L
293struct elf_x86_lazy_plt_layout
294{
92e68c1d 295 /* The first entry in a lazy procedure linkage table looks like this. */
765e526c 296 const bfd_byte *plt0_entry;
07d6d2b8 297 unsigned int plt0_entry_size; /* Size of PLT0 entry. */
765e526c 298
92e68c1d 299 /* Later entries in a lazy procedure linkage table look like this. */
765e526c 300 const bfd_byte *plt_entry;
07d6d2b8 301 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c 302
92e68c1d
L
303 /* The TLSDESC entry in a lazy procedure linkage table looks like
304 this. This is for x86-64 only. */
305 const bfd_byte *plt_tlsdesc_entry;
306 unsigned int plt_tlsdesc_entry_size; /* Size of TLSDESC entry. */
307
308 /* Offsets into the TLSDESC entry that are to be replaced with
309 GOT+8 and GOT+TDG. These are for x86-64 only. */
310 unsigned int plt_tlsdesc_got1_offset;
311 unsigned int plt_tlsdesc_got2_offset;
312
313 /* Offset of the end of the PC-relative instructions containing
314 plt_tlsdesc_got1_offset and plt_tlsdesc_got2_offset. These
315 are for x86-64 only. */
316 unsigned int plt_tlsdesc_got1_insn_end;
317 unsigned int plt_tlsdesc_got2_insn_end;
318
765e526c
L
319 /* Offsets into plt0_entry that are to be replaced with GOT[1] and
320 GOT[2]. */
321 unsigned int plt0_got1_offset;
322 unsigned int plt0_got2_offset;
323
324 /* Offset of the end of the PC-relative instruction containing
325 plt0_got2_offset. This is for x86-64 only. */
326 unsigned int plt0_got2_insn_end;
327
328 /* Offsets into plt_entry that are to be replaced with... */
329 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
330 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
331 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
332
333 /* Length of the PC-relative instruction containing plt_got_offset.
334 This is used for x86-64 only. */
335 unsigned int plt_got_insn_size;
336
337 /* Offset of the end of the PC-relative jump to plt0_entry. This is
338 used for x86-64 only. */
339 unsigned int plt_plt_insn_end;
340
341 /* Offset into plt_entry where the initial value of the GOT entry
342 points. */
343 unsigned int plt_lazy_offset;
344
345 /* The first entry in a PIC lazy procedure linkage table looks like
a6798bab 346 this. */
765e526c
L
347 const bfd_byte *pic_plt0_entry;
348
349 /* Subsequent entries in a PIC lazy procedure linkage table look
a6798bab 350 like this. */
765e526c
L
351 const bfd_byte *pic_plt_entry;
352
353 /* .eh_frame covering the lazy .plt section. */
354 const bfd_byte *eh_frame_plt;
355 unsigned int eh_frame_plt_size;
356};
357
358struct elf_x86_non_lazy_plt_layout
359{
92e68c1d 360 /* Entries in a non-lazy procedure linkage table look like this. */
765e526c 361 const bfd_byte *plt_entry;
92e68c1d
L
362 /* Entries in a PIC non-lazy procedure linkage table look like this.
363 This is only used for i386 where absolute PLT and PIC PLT are
364 different. */
765e526c
L
365 const bfd_byte *pic_plt_entry;
366
07d6d2b8 367 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c
L
368
369 /* Offsets into plt_entry that are to be replaced with... */
370 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
371
372 /* Length of the PC-relative instruction containing plt_got_offset.
373 This is used for x86-64 only. */
374 unsigned int plt_got_insn_size;
375
376 /* .eh_frame covering the non-lazy .plt section. */
377 const bfd_byte *eh_frame_plt;
378 unsigned int eh_frame_plt_size;
379};
380
381struct elf_x86_plt_layout
382{
92e68c1d 383 /* The first entry in a lazy procedure linkage table looks like this. */
765e526c
L
384 const bfd_byte *plt0_entry;
385 /* Entries in a procedure linkage table look like this. */
386 const bfd_byte *plt_entry;
07d6d2b8 387 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c
L
388
389 /* 1 has PLT0. */
390 unsigned int has_plt0;
391
392 /* Offsets into plt_entry that are to be replaced with... */
393 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
394
395 /* Length of the PC-relative instruction containing plt_got_offset.
396 This is only used for x86-64. */
397 unsigned int plt_got_insn_size;
398
b44ee3a8
L
399 /* Alignment of the .iplt section. */
400 unsigned int iplt_alignment;
401
765e526c
L
402 /* .eh_frame covering the .plt section. */
403 const bfd_byte *eh_frame_plt;
404 unsigned int eh_frame_plt_size;
405};
406
6b9553e2 407/* Values in tls_type of x86 ELF linker hash entry. */
0afcef53
L
408#define GOT_UNKNOWN 0
409#define GOT_NORMAL 1
410#define GOT_TLS_GD 2
6b9553e2
L
411#define GOT_TLS_IE 4
412#define GOT_TLS_IE_POS 5
413#define GOT_TLS_IE_NEG 6
414#define GOT_TLS_IE_BOTH 7
415#define GOT_TLS_GDESC 8
416#define GOT_TLS_GD_BOTH_P(type) \
417 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
418#define GOT_TLS_GD_P(type) \
419 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
420#define GOT_TLS_GDESC_P(type) \
421 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
422#define GOT_TLS_GD_ANY_P(type) \
423 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
0afcef53
L
424
425#define elf_x86_hash_entry(ent) \
426 ((struct elf_x86_link_hash_entry *)(ent))
427
851b6fa1
L
428enum elf_x86_target_os
429{
430 is_normal,
3b4c3844 431 is_solaris,
851b6fa1
L
432 is_vxworks,
433 is_nacl
434};
435
0afcef53
L
436/* x86 ELF linker hash table. */
437
438struct elf_x86_link_hash_table
439{
440 struct elf_link_hash_table elf;
441
442 /* Short-cuts to get to dynamic linker sections. */
443 asection *interp;
444 asection *plt_eh_frame;
445 asection *plt_second;
446 asection *plt_second_eh_frame;
447 asection *plt_got;
448 asection *plt_got_eh_frame;
449
765e526c
L
450 /* Parameters describing PLT generation, lazy or non-lazy. */
451 struct elf_x86_plt_layout plt;
452
453 /* Parameters describing lazy PLT generation. */
454 const struct elf_x86_lazy_plt_layout *lazy_plt;
455
456 /* Parameters describing non-lazy PLT generation. */
457 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
458
0afcef53
L
459 union
460 {
461 bfd_signed_vma refcount;
462 bfd_vma offset;
463 } tls_ld_or_ldm_got;
464
465 /* The amount of space used by the jump slots in the GOT. */
466 bfd_vma sgotplt_jump_table_size;
467
468 /* Small local sym cache. */
469 struct sym_cache sym_cache;
470
471 /* _TLS_MODULE_BASE_ symbol. */
472 struct bfd_link_hash_entry *tls_module_base;
473
474 /* Used by local STT_GNU_IFUNC symbols. */
475 htab_t loc_hash_table;
476 void * loc_hash_memory;
477
0afcef53
L
478 /* The offset into sgot of the GOT entry used by the PLT entry
479 above. */
480 bfd_vma tlsdesc_got;
481
482 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
483 bfd_vma next_jump_slot_index;
484 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
485 bfd_vma next_irelative_index;
486
487 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
488 to read-only sections. */
489 bfd_boolean readonly_dynrelocs_against_ifunc;
490
765e526c
L
491 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.
492 This is used for i386 only. */
493 asection *srelplt2;
494
495 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. This
2926eb2c 496 is only used for i386. */
765e526c
L
497 bfd_vma next_tls_desc_index;
498
2926eb2c
L
499 /* The offset into splt of the PLT entry for the TLS descriptor
500 resolver. Special values are 0, if not necessary (or not found
501 to be necessary yet), and -1 if needed but not determined
502 yet. This is only used for x86-64. */
503 bfd_vma tlsdesc_plt;
504
851b6fa1
L
505 /* Value used to fill the unused bytes of the first PLT entry. This
506 is only used for i386. */
507 bfd_byte plt0_pad_byte;
508
cd048363
L
509 /* TRUE if GOT is referenced. */
510 unsigned int got_referenced : 1;
511
451875b4
L
512 /* TRUE if PLT is PC-relative. PLT in PDE and PC-relative PLT in PIE
513 can be used as function address.
514
515 NB: i386 has non-PIC PLT and PIC PLT. Only non-PIC PLT in PDE can
516 be used as function address. PIC PLT in PIE can't be used as
517 function address. */
518 unsigned int pcrel_plt : 1;
519
0afcef53
L
520 bfd_vma (*r_info) (bfd_vma, bfd_vma);
521 bfd_vma (*r_sym) (bfd_vma);
5e2ac45d 522 bfd_boolean (*is_reloc_section) (const char *);
fe53b4a4 523 enum elf_target_id target_id;
851b6fa1 524 enum elf_x86_target_os target_os;
503294e7 525 unsigned int sizeof_reloc;
5e2ac45d
L
526 unsigned int dt_reloc;
527 unsigned int dt_reloc_sz;
528 unsigned int dt_reloc_ent;
9ff114ca 529 unsigned int got_entry_size;
0afcef53
L
530 unsigned int pointer_r_type;
531 int dynamic_interpreter_size;
532 const char *dynamic_interpreter;
533 const char *tls_get_addr;
5b9c07b2
L
534
535 /* Options passed from the linker. */
536 struct elf_linker_x86_params *params;
0afcef53
L
537};
538
851b6fa1
L
539/* Architecture-specific backend data for x86. */
540
541struct elf_x86_backend_data
542{
543 /* Target system. */
544 enum elf_x86_target_os target_os;
545};
546
547#define get_elf_x86_backend_data(abfd) \
548 ((const struct elf_x86_backend_data *) \
549 get_elf_backend_data (abfd)->arch_data)
550
1de031c8 551struct elf_x86_init_table
a6798bab
L
552{
553 /* The lazy PLT layout. */
554 const struct elf_x86_lazy_plt_layout *lazy_plt;
555
556 /* The non-lazy PLT layout. */
557 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
558
559 /* The lazy PLT layout for IBT. */
560 const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
561
562 /* The non-lazy PLT layout for IBT. */
563 const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
564
851b6fa1 565 bfd_byte plt0_pad_byte;
7a382c1c
L
566
567 bfd_vma (*r_info) (bfd_vma, bfd_vma);
568 bfd_vma (*r_sym) (bfd_vma);
a6798bab
L
569};
570
0afcef53
L
571struct elf_x86_obj_tdata
572{
573 struct elf_obj_tdata root;
574
575 /* tls_type for each local got entry. */
576 char *local_got_tls_type;
577
578 /* GOTPLT entries for TLS descriptors. */
579 bfd_vma *local_tlsdesc_gotent;
580};
581
f493882d
L
582enum elf_x86_plt_type
583{
584 plt_non_lazy = 0,
585 plt_lazy = 1 << 0,
586 plt_pic = 1 << 1,
587 plt_second = 1 << 2,
588 plt_unknown = -1
589};
590
591struct elf_x86_plt
592{
593 const char *name;
594 asection *sec;
595 bfd_byte *contents;
596 enum elf_x86_plt_type type;
597 unsigned int plt_got_offset;
598 unsigned int plt_entry_size;
599 unsigned int plt_got_insn_size; /* Only used for x86-64. */
600 long count;
601};
602
0afcef53
L
603#define elf_x86_tdata(abfd) \
604 ((struct elf_x86_obj_tdata *) (abfd)->tdata.any)
605
606#define elf_x86_local_got_tls_type(abfd) \
607 (elf_x86_tdata (abfd)->local_got_tls_type)
608
609#define elf_x86_local_tlsdesc_gotent(abfd) \
610 (elf_x86_tdata (abfd)->local_tlsdesc_gotent)
611
9ff114ca
L
612#define elf_x86_compute_jump_table_size(htab) \
613 ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size)
614
fe53b4a4
L
615#define is_x86_elf(bfd, htab) \
616 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
617 && elf_tdata (bfd) != NULL \
618 && elf_object_id (bfd) == (htab)->target_id)
619
39946cc2
L
620extern bfd_boolean _bfd_x86_elf_mkobject
621 (bfd *);
622
0afcef53
L
623extern void _bfd_x86_elf_set_tls_module_base
624 (struct bfd_link_info *);
625
626extern bfd_vma _bfd_x86_elf_dtpoff_base
627 (struct bfd_link_info *);
628
629extern bfd_boolean _bfd_x86_elf_readonly_dynrelocs
630 (struct elf_link_hash_entry *, void *);
631
632extern struct elf_link_hash_entry * _bfd_elf_x86_get_local_sym_hash
633 (struct elf_x86_link_hash_table *, bfd *, const Elf_Internal_Rela *,
634 bfd_boolean);
635
636extern hashval_t _bfd_x86_elf_local_htab_hash
637 (const void *);
638
639extern int _bfd_x86_elf_local_htab_eq
640 (const void *, const void *);
641
642extern struct bfd_hash_entry * _bfd_x86_elf_link_hash_newfunc
643 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
644
765e526c 645extern struct bfd_link_hash_table * _bfd_x86_elf_link_hash_table_create
0afcef53
L
646 (bfd *);
647
648extern int _bfd_x86_elf_compare_relocs
649 (const void *, const void *);
650
651extern bfd_boolean _bfd_x86_elf_link_check_relocs
652 (bfd *, struct bfd_link_info *);
653
5e2ac45d
L
654extern bfd_boolean _bfd_x86_elf_size_dynamic_sections
655 (bfd *, struct bfd_link_info *);
656
9577f60b
L
657extern struct elf_x86_link_hash_table *_bfd_x86_elf_finish_dynamic_sections
658 (bfd *, struct bfd_link_info *);
659
0afcef53
L
660extern bfd_boolean _bfd_x86_elf_always_size_sections
661 (bfd *, struct bfd_link_info *);
662
663extern void _bfd_x86_elf_merge_symbol_attribute
664 (struct elf_link_hash_entry *, const Elf_Internal_Sym *,
665 bfd_boolean, bfd_boolean);
666
667extern void _bfd_x86_elf_copy_indirect_symbol
668 (struct bfd_link_info *, struct elf_link_hash_entry *,
669 struct elf_link_hash_entry *);
670
671extern bfd_boolean _bfd_x86_elf_fixup_symbol
672 (struct bfd_link_info *, struct elf_link_hash_entry *);
673
674extern bfd_boolean _bfd_x86_elf_hash_symbol
675 (struct elf_link_hash_entry *);
676
eeb2f20a
L
677extern bfd_boolean _bfd_x86_elf_adjust_dynamic_symbol
678 (struct bfd_link_info *, struct elf_link_hash_entry *);
679
9f857535
L
680extern void _bfd_x86_elf_hide_symbol
681 (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
682
6999821f
L
683extern bfd_boolean _bfd_x86_elf_link_symbol_references_local
684 (struct bfd_link_info *, struct elf_link_hash_entry *);
685
4f501a24
L
686extern asection * _bfd_x86_elf_gc_mark_hook
687 (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
688 struct elf_link_hash_entry *, Elf_Internal_Sym *);
689
f493882d
L
690extern long _bfd_x86_elf_get_synthetic_symtab
691 (bfd *, long, long, bfd_vma, struct elf_x86_plt [], asymbol **,
692 asymbol **);
693
0afcef53
L
694extern enum elf_property_kind _bfd_x86_elf_parse_gnu_properties
695 (bfd *, unsigned int, bfd_byte *, unsigned int);
696
697extern bfd_boolean _bfd_x86_elf_merge_gnu_properties
4e539114 698 (struct bfd_link_info *, bfd *, bfd *, elf_property *, elf_property *);
0afcef53 699
bfb1e8c1
L
700extern void _bfd_x86_elf_link_fixup_gnu_properties
701 (struct bfd_link_info *, elf_property_list **);
702
a6798bab 703extern bfd * _bfd_x86_elf_link_setup_gnu_properties
1de031c8 704 (struct bfd_link_info *, struct elf_x86_init_table *);
a6798bab 705
4ec09950
L
706extern void _bfd_x86_elf_link_fixup_ifunc_symbol
707 (struct bfd_link_info *, struct elf_x86_link_hash_table *,
708 struct elf_link_hash_entry *, Elf_Internal_Sym *sym);
709
39946cc2
L
710#define bfd_elf64_mkobject \
711 _bfd_x86_elf_mkobject
712#define bfd_elf32_mkobject \
713 _bfd_x86_elf_mkobject
765e526c
L
714#define bfd_elf64_bfd_link_hash_table_create \
715 _bfd_x86_elf_link_hash_table_create
716#define bfd_elf32_bfd_link_hash_table_create \
717 _bfd_x86_elf_link_hash_table_create
0afcef53
L
718#define bfd_elf64_bfd_link_check_relocs \
719 _bfd_x86_elf_link_check_relocs
720#define bfd_elf32_bfd_link_check_relocs \
721 _bfd_x86_elf_link_check_relocs
722
5e2ac45d
L
723#define elf_backend_size_dynamic_sections \
724 _bfd_x86_elf_size_dynamic_sections
0afcef53
L
725#define elf_backend_always_size_sections \
726 _bfd_x86_elf_always_size_sections
727#define elf_backend_merge_symbol_attribute \
728 _bfd_x86_elf_merge_symbol_attribute
729#define elf_backend_copy_indirect_symbol \
730 _bfd_x86_elf_copy_indirect_symbol
731#define elf_backend_fixup_symbol \
732 _bfd_x86_elf_fixup_symbol
733#define elf_backend_hash_symbol \
734 _bfd_x86_elf_hash_symbol
eeb2f20a
L
735#define elf_backend_adjust_dynamic_symbol \
736 _bfd_x86_elf_adjust_dynamic_symbol
4f501a24
L
737#define elf_backend_gc_mark_hook \
738 _bfd_x86_elf_gc_mark_hook
0afcef53 739#define elf_backend_omit_section_dynsym \
d00dd7dc 740 _bfd_elf_omit_section_dynsym_all
0afcef53
L
741#define elf_backend_parse_gnu_properties \
742 _bfd_x86_elf_parse_gnu_properties
743#define elf_backend_merge_gnu_properties \
744 _bfd_x86_elf_merge_gnu_properties
bfb1e8c1
L
745#define elf_backend_fixup_gnu_properties \
746 _bfd_x86_elf_link_fixup_gnu_properties