]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elfxx-x86.h
i386: Update I386_NEED_DYNAMIC_RELOC_TYPE_P for DT_TEXTREL
[thirdparty/binutils-gdb.git] / bfd / elfxx-x86.h
CommitLineData
0afcef53 1/* x86 specific support for ELF
a2c58332 2 Copyright (C) 2017-2022 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
d1bcae83 21/* Don't generate unused section symbols. */
0a1b45a2 22#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS false
d1bcae83 23
0afcef53
L
24#include "sysdep.h"
25#include "bfd.h"
26#include "bfdlink.h"
27#include "libbfd.h"
28#include "elf-bfd.h"
0afcef53 29#include "hashtab.h"
5b9c07b2 30#include "elf-linker-x86.h"
831083d3
L
31#include "elf/i386.h"
32#include "elf/x86-64.h"
33
34#define X86_64_PCREL_TYPE_P(TYPE) \
35 ((TYPE) == R_X86_64_PC8 \
36 || (TYPE) == R_X86_64_PC16 \
37 || (TYPE) == R_X86_64_PC32 \
38 || (TYPE) == R_X86_64_PC32_BND \
39 || (TYPE) == R_X86_64_PC64)
40#define I386_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
41#define X86_PCREL_TYPE_P(IS_X86_64, TYPE) \
42 ((IS_X86_64) ? X86_64_PCREL_TYPE_P (TYPE) : I386_PCREL_TYPE_P (TYPE))
43
44#define X86_64_SIZE_TYPE_P(TYPE) \
45 ((TYPE) == R_X86_64_SIZE32 || (TYPE) == R_X86_64_SIZE64)
46#define I386_SIZE_TYPE_P(TYPE) ((TYPE) == R_386_SIZE32)
47#define X86_SIZE_TYPE_P(IS_X86_64, TYPE) \
48 ((IS_X86_64) ? X86_64_SIZE_TYPE_P(TYPE) : I386_SIZE_TYPE_P (TYPE))
0afcef53 49
5af6f000
L
50#define X86_64_GOT_TYPE_P(TYPE) \
51 ((TYPE) == R_X86_64_GOTPCREL \
52 || (TYPE) == R_X86_64_GOTPCRELX \
8d26ee1c
L
53 || (TYPE) == R_X86_64_REX_GOTPCRELX \
54 || (TYPE) == R_X86_64_GOT32 \
55 || (TYPE) == R_X86_64_GOT64 \
56 || (TYPE) == R_X86_64_GOTPCREL64 \
57 || (TYPE) == R_X86_64_GOTPLT64)
5af6f000
L
58#define I386_GOT_TYPE_P(TYPE) \
59 ((TYPE) == R_386_GOT32 || (TYPE) == R_386_GOT32X)
60#define X86_GOT_TYPE_P(IS_X86_64, TYPE) \
61 ((IS_X86_64) ? X86_64_GOT_TYPE_P (TYPE) : I386_GOT_TYPE_P (TYPE))
62
63#define X86_64_RELATIVE_RELOC_TYPE_P(TYPE) \
64 (X86_64_PCREL_TYPE_P (TYPE) \
3747999c
L
65 || (TYPE) == R_X86_64_8 \
66 || (TYPE) == R_X86_64_16 \
67 || (TYPE) == R_X86_64_32 \
68 || (TYPE) == R_X86_64_32S \
69 || (TYPE) == R_X86_64_64)
5af6f000
L
70#define I386_RELATIVE_RELOC_TYPE_P(TYPE) \
71 ((TYPE) == R_386_32 || (TYPE) == R_386_PC32)
72#define X86_RELATIVE_RELOC_TYPE_P(IS_X86_64, TYPE) \
73 ((IS_X86_64) \
74 ? X86_64_RELATIVE_RELOC_TYPE_P (TYPE) \
75 : I386_RELATIVE_RELOC_TYPE_P(TYPE))
76
77#define X86_64_NEED_DYNAMIC_RELOC_TYPE_P(TYPE) \
78 (X86_64_SIZE_TYPE_P (TYPE) \
79 || X86_64_RELATIVE_RELOC_TYPE_P (TYPE))
3747999c
L
80#define I386_NEED_DYNAMIC_RELOC_TYPE_P(TYPE) \
81 (I386_SIZE_TYPE_P (TYPE) \
5af6f000 82 || I386_RELATIVE_RELOC_TYPE_P (TYPE) \
3319ba7a 83 || (TYPE) == R_386_TLS_IE \
3747999c
L
84 || (TYPE) == R_386_TLS_LE \
85 || (TYPE) == R_386_TLS_LE_32)
86#define X86_NEED_DYNAMIC_RELOC_TYPE_P(IS_X86_64, TYPE) \
87 ((IS_X86_64) \
88 ? X86_64_NEED_DYNAMIC_RELOC_TYPE_P (TYPE) \
89 : I386_NEED_DYNAMIC_RELOC_TYPE_P (TYPE))
90
5af6f000
L
91#define X86_LOCAL_GOT_RELATIVE_RELOC_P(IS_X86_64, INFO, SYM) \
92 (bfd_link_pic (INFO) \
93 && (!(IS_X86_64) || ((SYM) != NULL && (SYM)->st_shndx != SHN_ABS)))
94
aa595247
L
95#define PLT_CIE_LENGTH 20
96#define PLT_FDE_LENGTH 36
97#define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
98#define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
99
5af6f000
L
100#define I386_PCREL_TYPE_P(TYPE) ((TYPE) == R_386_PC32)
101#define X86_64_PCREL_TYPE_P(TYPE) \
102 ((TYPE) == R_X86_64_PC8 \
103 || (TYPE) == R_X86_64_PC16 \
104 || (TYPE) == R_X86_64_PC32 \
105 || (TYPE) == R_X86_64_PC32_BND \
106 || (TYPE) == R_X86_64_PC64)
107
765e526c
L
108#define ABI_64_P(abfd) \
109 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
110
0afcef53
L
111/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
112 copying dynamic variables from a shared lib into an app's dynbss
113 section, and instead use a dynamic relocation to point into the
114 shared lib. */
115#define ELIMINATE_COPY_RELOCS 1
116
117#define elf_x86_hash_table(p, id) \
1cf58434
AM
118 (is_elf_hash_table ((p)->hash) \
119 && elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) == (id) \
0afcef53
L
120 ? ((struct elf_x86_link_hash_table *) ((p)->hash)) : NULL)
121
6999821f
L
122/* Will references to this symbol always be local in this object? */
123#define SYMBOL_REFERENCES_LOCAL_P(INFO, H) \
124 _bfd_x86_elf_link_symbol_references_local ((INFO), (H))
125
99180bcc
L
126/* TRUE if an undefined weak symbol should be resolved to 0. Local
127 undefined weak symbol is always resolved to 0. Reference to an
128 undefined weak symbol is resolved to 0 in executable if undefined
129 weak symbol should be resolved to 0 (zero_undefweak > 0). */
c5bce5c6 130#define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \
0afcef53 131 ((EH)->elf.root.type == bfd_link_hash_undefweak \
6999821f 132 && (SYMBOL_REFERENCES_LOCAL_P ((INFO), &(EH)->elf) \
0afcef53 133 || (bfd_link_executable (INFO) \
98b273dc 134 && (EH)->zero_undefweak > 0)))
0afcef53
L
135
136/* Should copy relocation be generated for a symbol. Don't generate
137 copy relocation against a protected symbol defined in a shared
138 object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. */
139#define SYMBOL_NO_COPYRELOC(INFO, EH) \
140 ((EH)->def_protected \
141 && ((EH)->elf.root.type == bfd_link_hash_defined \
142 || (EH)->elf.root.type == bfd_link_hash_defweak) \
143 && elf_has_no_copy_on_protected ((EH)->elf.root.u.def.section->owner) \
144 && ((EH)->elf.root.u.def.section->owner->flags & DYNAMIC) != 0 \
145 && ((EH)->elf.root.u.def.section->flags & SEC_CODE) == 0)
146
daf1c414
L
147/* TRUE if dynamic relocation is needed. If we are creating a shared
148 library, and this is a reloc against a global symbol, or a non PC
149 relative reloc against a local symbol, then we need to copy the reloc
150 into the shared library. However, if we are linking with -Bsymbolic,
151 we do not need to copy a reloc against a global symbol which is
152 defined in an object we are including in the link (i.e., DEF_REGULAR
451875b4
L
153 is set).
154
155 If PCREL_PLT is true, don't generate dynamic relocation in PIE for
156 PC-relative relocation against a dynamic function definition in data
157 section when PLT address can be used.
daf1c414
L
158
159 If on the other hand, we are creating an executable, we may need to
160 keep relocations for symbols satisfied by a dynamic library if we
161 manage to avoid copy relocs for the symbol.
162
163 We also need to generate dynamic pointer relocation against
164 STT_GNU_IFUNC symbol in the non-code section. */
831083d3
L
165#define NEED_DYNAMIC_RELOCATION_P(IS_X86_64, INFO, PCREL_PLT, H, SEC, \
166 R_TYPE, POINTER_TYPE) \
daf1c414 167 ((bfd_link_pic (INFO) \
831083d3 168 && (! X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
daf1c414
L
169 || ((H) != NULL \
170 && (! (bfd_link_pie (INFO) \
171 || SYMBOLIC_BIND ((INFO), (H))) \
172 || (H)->root.type == bfd_link_hash_defweak \
451875b4
L
173 || (!(bfd_link_pie (INFO) \
174 && (PCREL_PLT) \
175 && (H)->plt.refcount > 0 \
176 && ((SEC)->flags & SEC_CODE) == 0 \
177 && (H)->type == STT_FUNC \
178 && (H)->def_dynamic) \
179 && !(H)->def_regular))))) \
180 || ((H) != NULL \
181 && (H)->type == STT_GNU_IFUNC \
182 && (R_TYPE) == POINTER_TYPE \
183 && ((SEC)->flags & SEC_CODE) == 0) \
184 || (ELIMINATE_COPY_RELOCS \
185 && !bfd_link_pic (INFO) \
186 && (H) != NULL \
187 && ((H)->root.type == bfd_link_hash_defweak \
188 || !(H)->def_regular)))
daf1c414 189
aebcc8ff
L
190/* TRUE if dynamic relocation should be generated. Don't copy a
191 pc-relative relocation into the output file if the symbol needs
192 copy reloc or the symbol is undefined when building executable.
193 Copy dynamic function pointer relocations. Don't generate dynamic
194 relocations against resolved undefined weak symbols in PIE, except
195 when PC32_RELOC is TRUE. Undefined weak symbol is bound locally
382aae06 196 when PIC is false. Don't generate dynamic relocations against
5af6f000
L
197 non-preemptible absolute symbol. NB: rel_from_abs is set on symbols
198 defined by linker scripts from "dot" (also SEGMENT_START or ORIGIN)
199 outside of an output section statement, which will be converted from
200 absolute to section-relative in set_sym_sections called from
201 ldexp_finalize_syms after ldemul_finish. */
831083d3
L
202#define GENERATE_DYNAMIC_RELOCATION_P(IS_X86_64, INFO, EH, R_TYPE, \
203 SEC, NEED_COPY_RELOC_IN_PIE, \
aebcc8ff
L
204 RESOLVED_TO_ZERO, PC32_RELOC) \
205 ((bfd_link_pic (INFO) \
382aae06 206 && !(bfd_is_abs_section (SEC) \
5af6f000
L
207 && ((EH) == NULL \
208 || (EH)->elf.root.rel_from_abs == 0) \
382aae06
L
209 && ((EH) == NULL \
210 || SYMBOL_REFERENCES_LOCAL (INFO, &(EH)->elf))) \
aebcc8ff
L
211 && !(NEED_COPY_RELOC_IN_PIE) \
212 && ((EH) == NULL \
213 || ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \
214 && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \
215 || (EH)->elf.root.type != bfd_link_hash_undefweak)) \
831083d3
L
216 && ((!X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
217 && !X86_SIZE_TYPE_P (IS_X86_64, R_TYPE)) \
433953ff
L
218 || ! SYMBOL_CALLS_LOCAL ((INFO), \
219 (struct elf_link_hash_entry *) (EH)))) \
aebcc8ff
L
220 || (ELIMINATE_COPY_RELOCS \
221 && !bfd_link_pic (INFO) \
222 && (EH) != NULL \
223 && (EH)->elf.dynindx != -1 \
224 && (!(EH)->elf.non_got_ref \
aebcc8ff
L
225 || ((EH)->elf.root.type == bfd_link_hash_undefweak \
226 && !(RESOLVED_TO_ZERO))) \
227 && (((EH)->elf.def_dynamic && !(EH)->elf.def_regular) \
228 || (EH)->elf.root.type == bfd_link_hash_undefined)))
229
e74399c4
L
230/* TRUE if this input relocation should be copied to output. H->dynindx
231 may be -1 if this symbol was marked to become local. */
831083d3 232#define COPY_INPUT_RELOC_P(IS_X86_64, INFO, H, R_TYPE) \
e74399c4
L
233 ((H) != NULL \
234 && (H)->dynindx != -1 \
831083d3 235 && (X86_PCREL_TYPE_P (IS_X86_64, R_TYPE) \
e74399c4
L
236 || !(bfd_link_executable (INFO) || SYMBOLIC_BIND ((INFO), (H))) \
237 || !(H)->def_regular))
238
2eba97c2
L
239/* TRUE if this is actually a static link, or it is a -Bsymbolic link
240 and the symbol is defined locally, or the symbol was forced to be
241 local because of a version file. */
242#define RESOLVED_LOCALLY_P(INFO, H, HTAB) \
243 (!WILL_CALL_FINISH_DYNAMIC_SYMBOL ((HTAB)->elf.dynamic_sections_created, \
244 bfd_link_pic (INFO), (H)) \
245 || (bfd_link_pic (INFO) \
246 && SYMBOL_REFERENCES_LOCAL_P ((INFO), (H))) \
247 || (ELF_ST_VISIBILITY ((H)->other) \
248 && (H)->root.type == bfd_link_hash_undefweak))
249
83924b38
L
250/* TRUE if this symbol isn't defined by a shared object. */
251#define SYMBOL_DEFINED_NON_SHARED_P(H) \
252 ((H)->def_regular \
253 || (H)->root.linker_def \
254 || (H)->root.ldscript_def \
4e84a8f8 255 || ((struct elf_x86_link_hash_entry *) (H))->linker_def \
83924b38
L
256 || ELF_COMMON_DEF_P (H))
257
382aae06
L
258/* Return TRUE if the symbol described by a linker hash entry H is
259 going to be absolute. Similar to bfd_is_abs_symbol, but excluding
260 all linker-script defined symbols. */
261#define ABS_SYMBOL_P(H) \
262 (bfd_is_abs_symbol (&(H)->root) && !(H)->root.ldscript_def)
263
f70656b2
L
264/* TRUE if relative relocation should be generated. GOT reference to
265 global symbol in PIC will lead to dynamic symbol. It becomes a
266 problem when "time" or "times" is defined as a variable in an
267 executable, clashing with functions of the same name in libc. If a
268 symbol isn't undefined weak symbol, don't make it dynamic in PIC and
382aae06
L
269 generate relative relocation. Don't generate relative relocation
270 against non-preemptible absolute symbol. */
f70656b2
L
271#define GENERATE_RELATIVE_RELOC_P(INFO, H) \
272 ((H)->dynindx == -1 \
273 && !(H)->forced_local \
274 && (H)->root.type != bfd_link_hash_undefweak \
382aae06
L
275 && bfd_link_pic (INFO) \
276 && !ABS_SYMBOL_P (H))
f70656b2 277
cf1070f1
L
278/* TRUE if this is a pointer reference to a local IFUNC. */
279#define POINTER_LOCAL_IFUNC_P(INFO, H) \
280 ((H)->dynindx == -1 \
281 || (H)->forced_local \
282 || bfd_link_executable (INFO))
283
284/* TRUE if this is a PLT reference to a local IFUNC. */
285#define PLT_LOCAL_IFUNC_P(INFO, H) \
286 ((H)->dynindx == -1 \
287 || ((bfd_link_executable (INFO) \
288 || ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT) \
289 && (H)->def_regular \
290 && (H)->type == STT_GNU_IFUNC))
291
51537393
L
292/* TRUE if TLS IE->LE transition is OK. */
293#define TLS_TRANSITION_IE_TO_LE_P(INFO, H, TLS_TYPE) \
294 (bfd_link_executable (INFO) \
295 && (H) != NULL \
296 && (H)->dynindx == -1 \
297 && (TLS_TYPE & GOT_TLS_IE))
298
f3180fa9
L
299/* Verify that the symbol has an entry in the procedure linkage table. */
300#define VERIFY_PLT_ENTRY(INFO, H, PLT, GOTPLT, RELPLT, LOCAL_UNDEFWEAK) \
e0d8f431
L
301 do \
302 { \
303 if (((H)->dynindx == -1 \
304 && !LOCAL_UNDEFWEAK \
305 && !(((H)->forced_local || bfd_link_executable (INFO)) \
306 && (H)->def_regular \
307 && (H)->type == STT_GNU_IFUNC)) \
308 || (PLT) == NULL \
309 || (GOTPLT) == NULL \
310 || (RELPLT) == NULL) \
311 abort (); \
312 } \
313 while (0);
f3180fa9 314
ff38b4cc
L
315/* Verify that the symbol supports copy relocation. */
316#define VERIFY_COPY_RELOC(H, HTAB) \
e0d8f431
L
317 do \
318 { \
319 if ((H)->dynindx == -1 \
320 || ((H)->root.type != bfd_link_hash_defined \
321 && (H)->root.type != bfd_link_hash_defweak) \
322 || (HTAB)->elf.srelbss == NULL \
323 || (HTAB)->elf.sreldynrelro == NULL) \
324 abort (); \
325 } \
326 while (0);
ff38b4cc 327
0afcef53
L
328/* x86 ELF linker hash entry. */
329
330struct elf_x86_link_hash_entry
331{
332 struct elf_link_hash_entry elf;
333
0afcef53
L
334 unsigned char tls_type;
335
98b273dc
L
336 /* Bit 0: Symbol has no GOT nor PLT relocations.
337 Bit 1: Symbol has non-GOT/non-PLT relocations in text sections.
338 zero_undefweak is initialized to 1 and undefined weak symbol
339 should be resolved to 0 if zero_undefweak > 0. */
340 unsigned int zero_undefweak : 2;
0afcef53
L
341
342 /* Don't call finish_dynamic_symbol on this symbol. */
343 unsigned int no_finish_dynamic_symbol : 1;
344
5af6f000
L
345 /* R_*_RELATIVE relocation in GOT for this symbol has been
346 processed. */
347 unsigned int got_relative_reloc_done : 1;
348
0afcef53
L
349 /* TRUE if symbol is __tls_get_addr. */
350 unsigned int tls_get_addr : 1;
351
352 /* TRUE if symbol is defined as a protected symbol. */
353 unsigned int def_protected : 1;
354
6999821f
L
355 /* 0: Symbol references are unknown.
356 1: Symbol references aren't local.
357 2: Symbol references are local.
358 */
359 unsigned int local_ref : 2;
360
0a27fed7
L
361 /* TRUE if symbol is defined by linker. */
362 unsigned int linker_def : 1;
363
6f365fda
L
364 /* TRUE if symbol is referenced by a non-GOT/non-PLT relocation in a
365 relocatable object file without indirect external access marker. */
366 unsigned int non_got_ref_without_indirect_extern_access : 1;
367
f47432d4 368 /* TRUE if symbol is referenced by R_386_GOTOFF relocation. This is
c7df954f 369 only used by i386. */
0afcef53
L
370 unsigned int gotoff_ref : 1;
371
372 /* TRUE if a weak symbol with a real definition needs a copy reloc.
373 When there is a weak symbol with a real definition, the processor
374 independent code will have arranged for us to see the real
375 definition first. We need to copy the needs_copy bit from the
376 real definition and check it when allowing copy reloc in PIE. This
377 is only used by x86-64. */
378 unsigned int needs_copy : 1;
379
0afcef53
L
380 /* Information about the GOT PLT entry. Filled when there are both
381 GOT and PLT relocations against the same function. */
382 union gotplt_union plt_got;
383
384 /* Information about the second PLT entry. */
385 union gotplt_union plt_second;
386
387 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
388 starting at the end of the jump table. */
389 bfd_vma tlsdesc_got;
390};
391
765e526c
L
392struct elf_x86_lazy_plt_layout
393{
92e68c1d 394 /* The first entry in a lazy procedure linkage table looks like this. */
765e526c 395 const bfd_byte *plt0_entry;
07d6d2b8 396 unsigned int plt0_entry_size; /* Size of PLT0 entry. */
765e526c 397
92e68c1d 398 /* Later entries in a lazy procedure linkage table look like this. */
765e526c 399 const bfd_byte *plt_entry;
07d6d2b8 400 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c 401
92e68c1d
L
402 /* The TLSDESC entry in a lazy procedure linkage table looks like
403 this. This is for x86-64 only. */
404 const bfd_byte *plt_tlsdesc_entry;
405 unsigned int plt_tlsdesc_entry_size; /* Size of TLSDESC entry. */
406
407 /* Offsets into the TLSDESC entry that are to be replaced with
408 GOT+8 and GOT+TDG. These are for x86-64 only. */
409 unsigned int plt_tlsdesc_got1_offset;
410 unsigned int plt_tlsdesc_got2_offset;
411
412 /* Offset of the end of the PC-relative instructions containing
413 plt_tlsdesc_got1_offset and plt_tlsdesc_got2_offset. These
414 are for x86-64 only. */
415 unsigned int plt_tlsdesc_got1_insn_end;
416 unsigned int plt_tlsdesc_got2_insn_end;
417
765e526c
L
418 /* Offsets into plt0_entry that are to be replaced with GOT[1] and
419 GOT[2]. */
420 unsigned int plt0_got1_offset;
421 unsigned int plt0_got2_offset;
422
423 /* Offset of the end of the PC-relative instruction containing
424 plt0_got2_offset. This is for x86-64 only. */
425 unsigned int plt0_got2_insn_end;
426
427 /* Offsets into plt_entry that are to be replaced with... */
428 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
429 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
430 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
431
432 /* Length of the PC-relative instruction containing plt_got_offset.
433 This is used for x86-64 only. */
434 unsigned int plt_got_insn_size;
435
436 /* Offset of the end of the PC-relative jump to plt0_entry. This is
437 used for x86-64 only. */
438 unsigned int plt_plt_insn_end;
439
440 /* Offset into plt_entry where the initial value of the GOT entry
441 points. */
442 unsigned int plt_lazy_offset;
443
444 /* The first entry in a PIC lazy procedure linkage table looks like
a6798bab 445 this. */
765e526c
L
446 const bfd_byte *pic_plt0_entry;
447
448 /* Subsequent entries in a PIC lazy procedure linkage table look
a6798bab 449 like this. */
765e526c
L
450 const bfd_byte *pic_plt_entry;
451
452 /* .eh_frame covering the lazy .plt section. */
453 const bfd_byte *eh_frame_plt;
454 unsigned int eh_frame_plt_size;
455};
456
457struct elf_x86_non_lazy_plt_layout
458{
92e68c1d 459 /* Entries in a non-lazy procedure linkage table look like this. */
765e526c 460 const bfd_byte *plt_entry;
92e68c1d
L
461 /* Entries in a PIC non-lazy procedure linkage table look like this.
462 This is only used for i386 where absolute PLT and PIC PLT are
463 different. */
765e526c
L
464 const bfd_byte *pic_plt_entry;
465
07d6d2b8 466 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c
L
467
468 /* Offsets into plt_entry that are to be replaced with... */
469 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
470
471 /* Length of the PC-relative instruction containing plt_got_offset.
472 This is used for x86-64 only. */
473 unsigned int plt_got_insn_size;
474
475 /* .eh_frame covering the non-lazy .plt section. */
476 const bfd_byte *eh_frame_plt;
477 unsigned int eh_frame_plt_size;
478};
479
480struct elf_x86_plt_layout
481{
92e68c1d 482 /* The first entry in a lazy procedure linkage table looks like this. */
765e526c
L
483 const bfd_byte *plt0_entry;
484 /* Entries in a procedure linkage table look like this. */
485 const bfd_byte *plt_entry;
07d6d2b8 486 unsigned int plt_entry_size; /* Size of each PLT entry. */
765e526c
L
487
488 /* 1 has PLT0. */
489 unsigned int has_plt0;
490
491 /* Offsets into plt_entry that are to be replaced with... */
492 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
493
494 /* Length of the PC-relative instruction containing plt_got_offset.
495 This is only used for x86-64. */
496 unsigned int plt_got_insn_size;
497
b44ee3a8
L
498 /* Alignment of the .iplt section. */
499 unsigned int iplt_alignment;
500
765e526c
L
501 /* .eh_frame covering the .plt section. */
502 const bfd_byte *eh_frame_plt;
503 unsigned int eh_frame_plt_size;
504};
505
6b9553e2 506/* Values in tls_type of x86 ELF linker hash entry. */
0afcef53
L
507#define GOT_UNKNOWN 0
508#define GOT_NORMAL 1
509#define GOT_TLS_GD 2
6b9553e2
L
510#define GOT_TLS_IE 4
511#define GOT_TLS_IE_POS 5
512#define GOT_TLS_IE_NEG 6
513#define GOT_TLS_IE_BOTH 7
514#define GOT_TLS_GDESC 8
382aae06 515#define GOT_ABS 9
6b9553e2
L
516#define GOT_TLS_GD_BOTH_P(type) \
517 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
518#define GOT_TLS_GD_P(type) \
519 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
520#define GOT_TLS_GDESC_P(type) \
521 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
522#define GOT_TLS_GD_ANY_P(type) \
523 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
0afcef53
L
524
525#define elf_x86_hash_entry(ent) \
526 ((struct elf_x86_link_hash_entry *)(ent))
527
5af6f000
L
528/* Information of an input relocation used to compute its contribution
529 to the DT_RELR section size. */
530
531struct elf_x86_relative_reloc_record
532{
533 /* The original relocation info. */
534 Elf_Internal_Rela rel;
535 /* The input or the GOT section where the relocation is applied. */
536 asection *sec;
537 /* Local symbol info. NULL for global symbol. */
538 Elf_Internal_Sym *sym;
539 union
540 {
541 /* Section where the local symbol is defined. */
542 asection *sym_sec;
543 /* Global symbol hash. */
544 struct elf_link_hash_entry *h;
545 } u;
546 /* The offset into the output section where the relative relocation
547 will be applied at run-time. */
548 bfd_vma offset;
549 /* The run-time address. */
550 bfd_vma address;
551};
552
553struct elf_x86_relative_reloc_data
554{
555 bfd_size_type count;
556 bfd_size_type size;
557 struct elf_x86_relative_reloc_record *data;
558};
559
560/* DT_RELR bitmap. */
561struct elf_dt_relr_bitmap
562{
563 bfd_size_type count;
564 bfd_size_type size;
565 union
566 {
567 /* 32-bit bitmap. */
568 uint32_t *elf32;
569 /* 64-bit bitmap. */
570 uint64_t *elf64;
571 } u;
572};
573
0afcef53
L
574/* x86 ELF linker hash table. */
575
576struct elf_x86_link_hash_table
577{
578 struct elf_link_hash_table elf;
579
580 /* Short-cuts to get to dynamic linker sections. */
581 asection *interp;
582 asection *plt_eh_frame;
583 asection *plt_second;
584 asection *plt_second_eh_frame;
585 asection *plt_got;
586 asection *plt_got_eh_frame;
587
765e526c
L
588 /* Parameters describing PLT generation, lazy or non-lazy. */
589 struct elf_x86_plt_layout plt;
590
591 /* Parameters describing lazy PLT generation. */
592 const struct elf_x86_lazy_plt_layout *lazy_plt;
593
594 /* Parameters describing non-lazy PLT generation. */
595 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
596
0afcef53
L
597 union
598 {
599 bfd_signed_vma refcount;
600 bfd_vma offset;
601 } tls_ld_or_ldm_got;
602
603 /* The amount of space used by the jump slots in the GOT. */
604 bfd_vma sgotplt_jump_table_size;
605
0afcef53
L
606 /* _TLS_MODULE_BASE_ symbol. */
607 struct bfd_link_hash_entry *tls_module_base;
608
609 /* Used by local STT_GNU_IFUNC symbols. */
610 htab_t loc_hash_table;
611 void * loc_hash_memory;
612
0afcef53
L
613 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
614 bfd_vma next_jump_slot_index;
615 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
616 bfd_vma next_irelative_index;
617
765e526c
L
618 /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.
619 This is used for i386 only. */
620 asection *srelplt2;
621
622 /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. This
2926eb2c 623 is only used for i386. */
765e526c
L
624 bfd_vma next_tls_desc_index;
625
5af6f000
L
626 /* DT_RELR bitmap. */
627 struct elf_dt_relr_bitmap dt_relr_bitmap;
628
629 /* Relative relocation data. */
630 struct elf_x86_relative_reloc_data relative_reloc;
631
632 /* Unaligned relative relocation data. */
633 struct elf_x86_relative_reloc_data unaligned_relative_reloc;
634
635 /* Number of relative reloc generation pass. */
636 unsigned int generate_relative_reloc_pass;
637
851b6fa1
L
638 /* Value used to fill the unused bytes of the first PLT entry. This
639 is only used for i386. */
640 bfd_byte plt0_pad_byte;
641
cd048363
L
642 /* TRUE if GOT is referenced. */
643 unsigned int got_referenced : 1;
644
451875b4
L
645 /* TRUE if PLT is PC-relative. PLT in PDE and PC-relative PLT in PIE
646 can be used as function address.
647
648 NB: i386 has non-PIC PLT and PIC PLT. Only non-PIC PLT in PDE can
649 be used as function address. PIC PLT in PIE can't be used as
650 function address. */
651 unsigned int pcrel_plt : 1;
652
0afcef53
L
653 bfd_vma (*r_info) (bfd_vma, bfd_vma);
654 bfd_vma (*r_sym) (bfd_vma);
0a1b45a2 655 bool (*is_reloc_section) (const char *);
503294e7 656 unsigned int sizeof_reloc;
9ff114ca 657 unsigned int got_entry_size;
0afcef53 658 unsigned int pointer_r_type;
5af6f000 659 unsigned int relative_r_type;
0afcef53
L
660 int dynamic_interpreter_size;
661 const char *dynamic_interpreter;
662 const char *tls_get_addr;
5af6f000
L
663 const char *relative_r_name;
664 void (*elf_append_reloc) (bfd *, asection *, Elf_Internal_Rela *);
665 void (*elf_write_addend) (bfd *, uint64_t, void *);
666 void (*elf_write_addend_in_got) (bfd *, uint64_t, void *);
5b9c07b2
L
667
668 /* Options passed from the linker. */
669 struct elf_linker_x86_params *params;
0afcef53
L
670};
671
1de031c8 672struct elf_x86_init_table
a6798bab
L
673{
674 /* The lazy PLT layout. */
675 const struct elf_x86_lazy_plt_layout *lazy_plt;
676
677 /* The non-lazy PLT layout. */
678 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
679
680 /* The lazy PLT layout for IBT. */
681 const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
682
683 /* The non-lazy PLT layout for IBT. */
684 const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
685
851b6fa1 686 bfd_byte plt0_pad_byte;
7a382c1c
L
687
688 bfd_vma (*r_info) (bfd_vma, bfd_vma);
689 bfd_vma (*r_sym) (bfd_vma);
a6798bab
L
690};
691
0afcef53
L
692struct elf_x86_obj_tdata
693{
694 struct elf_obj_tdata root;
695
696 /* tls_type for each local got entry. */
697 char *local_got_tls_type;
698
699 /* GOTPLT entries for TLS descriptors. */
700 bfd_vma *local_tlsdesc_gotent;
5af6f000
L
701
702 /* R_*_RELATIVE relocation in GOT for this local symbol has been
703 processed. */
704 char *relative_reloc_done;
0afcef53
L
705};
706
f493882d
L
707enum elf_x86_plt_type
708{
709 plt_non_lazy = 0,
710 plt_lazy = 1 << 0,
711 plt_pic = 1 << 1,
712 plt_second = 1 << 2,
713 plt_unknown = -1
714};
715
716struct elf_x86_plt
717{
718 const char *name;
719 asection *sec;
720 bfd_byte *contents;
721 enum elf_x86_plt_type type;
722 unsigned int plt_got_offset;
723 unsigned int plt_entry_size;
724 unsigned int plt_got_insn_size; /* Only used for x86-64. */
725 long count;
726};
727
382aae06
L
728/* Set if a relocation is converted from a GOTPCREL relocation. */
729#define R_X86_64_converted_reloc_bit (1 << 7)
730
0afcef53
L
731#define elf_x86_tdata(abfd) \
732 ((struct elf_x86_obj_tdata *) (abfd)->tdata.any)
733
734#define elf_x86_local_got_tls_type(abfd) \
735 (elf_x86_tdata (abfd)->local_got_tls_type)
736
737#define elf_x86_local_tlsdesc_gotent(abfd) \
738 (elf_x86_tdata (abfd)->local_tlsdesc_gotent)
739
5af6f000
L
740#define elf_x86_relative_reloc_done(abfd) \
741 (elf_x86_tdata (abfd)->relative_reloc_done)
742
9ff114ca
L
743#define elf_x86_compute_jump_table_size(htab) \
744 ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size)
745
fe53b4a4
L
746#define is_x86_elf(bfd, htab) \
747 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
748 && elf_tdata (bfd) != NULL \
add5f777 749 && elf_object_id (bfd) == (htab)->elf.hash_table_id)
fe53b4a4 750
a321de3f
L
751/* Rename some of the generic section flags to better document how they
752 are used here. */
753#define check_relocs_failed sec_flg0
5af6f000 754#define relative_reloc_packed sec_flg1
a321de3f 755
0a1b45a2 756extern bool _bfd_x86_elf_mkobject
39946cc2
L
757 (bfd *);
758
0afcef53
L
759extern void _bfd_x86_elf_set_tls_module_base
760 (struct bfd_link_info *);
761
762extern bfd_vma _bfd_x86_elf_dtpoff_base
763 (struct bfd_link_info *);
764
0a1b45a2 765extern bool _bfd_x86_elf_readonly_dynrelocs
0afcef53
L
766 (struct elf_link_hash_entry *, void *);
767
768extern struct elf_link_hash_entry * _bfd_elf_x86_get_local_sym_hash
769 (struct elf_x86_link_hash_table *, bfd *, const Elf_Internal_Rela *,
0a1b45a2 770 bool);
0afcef53
L
771
772extern hashval_t _bfd_x86_elf_local_htab_hash
773 (const void *);
774
775extern int _bfd_x86_elf_local_htab_eq
776 (const void *, const void *);
777
778extern struct bfd_hash_entry * _bfd_x86_elf_link_hash_newfunc
779 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
780
765e526c 781extern struct bfd_link_hash_table * _bfd_x86_elf_link_hash_table_create
0afcef53
L
782 (bfd *);
783
784extern int _bfd_x86_elf_compare_relocs
785 (const void *, const void *);
786
0a1b45a2 787extern bool _bfd_x86_elf_link_check_relocs
0afcef53
L
788 (bfd *, struct bfd_link_info *);
789
3747999c
L
790extern bool _bfd_x86_elf_check_relocs
791 (bfd *, struct bfd_link_info *, asection *,
792 const Elf_Internal_Rela *);
793
5af6f000
L
794extern bool _bfd_x86_elf_link_relax_section
795 (bfd *, asection *, struct bfd_link_info *, bool *);
796
797extern bool _bfd_elf_x86_size_relative_relocs
798 (struct bfd_link_info *, bool *);
799
800extern bool _bfd_elf_x86_finish_relative_relocs
801 (struct bfd_link_info *);
802
803extern void _bfd_elf32_write_addend (bfd *, uint64_t, void *);
804extern void _bfd_elf64_write_addend (bfd *, uint64_t, void *);
805
0a1b45a2 806extern bool _bfd_elf_x86_valid_reloc_p
382aae06
L
807 (asection *, struct bfd_link_info *, struct elf_x86_link_hash_table *,
808 const Elf_Internal_Rela *, struct elf_link_hash_entry *,
0a1b45a2 809 Elf_Internal_Sym *, Elf_Internal_Shdr *, bool *);
382aae06 810
0a1b45a2 811extern bool _bfd_x86_elf_size_dynamic_sections
5e2ac45d
L
812 (bfd *, struct bfd_link_info *);
813
9577f60b
L
814extern struct elf_x86_link_hash_table *_bfd_x86_elf_finish_dynamic_sections
815 (bfd *, struct bfd_link_info *);
816
0a1b45a2 817extern bool _bfd_x86_elf_always_size_sections
0afcef53
L
818 (bfd *, struct bfd_link_info *);
819
820extern void _bfd_x86_elf_merge_symbol_attribute
0a1b45a2 821 (struct elf_link_hash_entry *, unsigned int, bool, bool);
0afcef53
L
822
823extern void _bfd_x86_elf_copy_indirect_symbol
824 (struct bfd_link_info *, struct elf_link_hash_entry *,
825 struct elf_link_hash_entry *);
826
0a1b45a2 827extern bool _bfd_x86_elf_fixup_symbol
0afcef53
L
828 (struct bfd_link_info *, struct elf_link_hash_entry *);
829
0a1b45a2 830extern bool _bfd_x86_elf_hash_symbol
0afcef53
L
831 (struct elf_link_hash_entry *);
832
0a1b45a2 833extern bool _bfd_x86_elf_adjust_dynamic_symbol
eeb2f20a
L
834 (struct bfd_link_info *, struct elf_link_hash_entry *);
835
9f857535 836extern void _bfd_x86_elf_hide_symbol
0a1b45a2 837 (struct bfd_link_info *, struct elf_link_hash_entry *, bool);
9f857535 838
0a1b45a2 839extern bool _bfd_x86_elf_link_symbol_references_local
6999821f
L
840 (struct bfd_link_info *, struct elf_link_hash_entry *);
841
4f501a24
L
842extern asection * _bfd_x86_elf_gc_mark_hook
843 (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
844 struct elf_link_hash_entry *, Elf_Internal_Sym *);
845
f493882d
L
846extern long _bfd_x86_elf_get_synthetic_symtab
847 (bfd *, long, long, bfd_vma, struct elf_x86_plt [], asymbol **,
848 asymbol **);
849
0afcef53
L
850extern enum elf_property_kind _bfd_x86_elf_parse_gnu_properties
851 (bfd *, unsigned int, bfd_byte *, unsigned int);
852
0a1b45a2 853extern bool _bfd_x86_elf_merge_gnu_properties
4e539114 854 (struct bfd_link_info *, bfd *, bfd *, elf_property *, elf_property *);
0afcef53 855
bfb1e8c1
L
856extern void _bfd_x86_elf_link_fixup_gnu_properties
857 (struct bfd_link_info *, elf_property_list **);
858
a6798bab 859extern bfd * _bfd_x86_elf_link_setup_gnu_properties
1de031c8 860 (struct bfd_link_info *, struct elf_x86_init_table *);
a6798bab 861
4ec09950
L
862extern void _bfd_x86_elf_link_fixup_ifunc_symbol
863 (struct bfd_link_info *, struct elf_x86_link_hash_table *,
864 struct elf_link_hash_entry *, Elf_Internal_Sym *sym);
865
68b00778
L
866extern void _bfd_x86_elf_link_report_relative_reloc
867 (struct bfd_link_info *, asection *, struct elf_link_hash_entry *,
868 Elf_Internal_Sym *, const char *, const void *);
869
39946cc2
L
870#define bfd_elf64_mkobject \
871 _bfd_x86_elf_mkobject
872#define bfd_elf32_mkobject \
873 _bfd_x86_elf_mkobject
765e526c
L
874#define bfd_elf64_bfd_link_hash_table_create \
875 _bfd_x86_elf_link_hash_table_create
876#define bfd_elf32_bfd_link_hash_table_create \
877 _bfd_x86_elf_link_hash_table_create
0afcef53
L
878#define bfd_elf64_bfd_link_check_relocs \
879 _bfd_x86_elf_link_check_relocs
880#define bfd_elf32_bfd_link_check_relocs \
881 _bfd_x86_elf_link_check_relocs
5af6f000
L
882#define bfd_elf32_bfd_relax_section \
883 _bfd_x86_elf_link_relax_section
884#define bfd_elf64_bfd_relax_section \
885 _bfd_x86_elf_link_relax_section
0afcef53 886
3747999c
L
887#define elf_backend_check_relocs \
888 _bfd_x86_elf_check_relocs
5e2ac45d
L
889#define elf_backend_size_dynamic_sections \
890 _bfd_x86_elf_size_dynamic_sections
0afcef53
L
891#define elf_backend_merge_symbol_attribute \
892 _bfd_x86_elf_merge_symbol_attribute
893#define elf_backend_copy_indirect_symbol \
894 _bfd_x86_elf_copy_indirect_symbol
895#define elf_backend_fixup_symbol \
896 _bfd_x86_elf_fixup_symbol
897#define elf_backend_hash_symbol \
898 _bfd_x86_elf_hash_symbol
eeb2f20a
L
899#define elf_backend_adjust_dynamic_symbol \
900 _bfd_x86_elf_adjust_dynamic_symbol
4f501a24
L
901#define elf_backend_gc_mark_hook \
902 _bfd_x86_elf_gc_mark_hook
0afcef53 903#define elf_backend_omit_section_dynsym \
d00dd7dc 904 _bfd_elf_omit_section_dynsym_all
0afcef53
L
905#define elf_backend_parse_gnu_properties \
906 _bfd_x86_elf_parse_gnu_properties
907#define elf_backend_merge_gnu_properties \
908 _bfd_x86_elf_merge_gnu_properties
bfb1e8c1
L
909#define elf_backend_fixup_gnu_properties \
910 _bfd_x86_elf_link_fixup_gnu_properties
5af6f000
L
911#define elf_backend_size_relative_relocs \
912 _bfd_elf_x86_size_relative_relocs
913#define elf_backend_finish_relative_relocs \
914 _bfd_elf_x86_finish_relative_relocs
794f2bba 915
74e315db
L
916#define ELF_P_ALIGN ELF_MINPAGESIZE
917
bbdeb108
L
918/* Allocate x86 GOT info for local symbols. */
919
920static inline bool
921elf_x86_allocate_local_got_info (bfd *abfd, bfd_size_type count)
922{
923 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
924 if (local_got_refcounts == NULL)
925 {
926 bfd_size_type size = count * (sizeof (bfd_signed_vma)
5af6f000
L
927 + sizeof (bfd_vma)
928 + 2 * sizeof(char));
bbdeb108
L
929 local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size);
930 if (local_got_refcounts == NULL)
931 return false;
932 elf_local_got_refcounts (abfd) = local_got_refcounts;
933 elf_x86_local_tlsdesc_gotent (abfd) =
934 (bfd_vma *) (local_got_refcounts + count);
935 elf_x86_local_got_tls_type (abfd) =
936 (char *) (local_got_refcounts + 2 * count);
5af6f000
L
937 elf_x86_relative_reloc_done (abfd) =
938 ((char *) (local_got_refcounts + 2 * count)) + count;
bbdeb108
L
939 }
940 return true;
941}