Commit | Line | Data |
---|---|---|
0afcef53 L |
1 | /* x86 specific support for ELF |
2 | Copyright (C) 2017 Free Software Foundation, Inc. | |
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" | |
26 | #include "bfd_stdint.h" | |
0afcef53 L |
27 | #include "hashtab.h" |
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 | ||
0afcef53 L |
52 | /* Is a undefined weak symbol which is resolved to 0. Reference to an |
53 | undefined weak symbol is resolved to 0 when building executable if | |
54 | it isn't dynamic and | |
55 | 1. Has non-GOT/non-PLT relocations in text section. Or | |
56 | 2. Has no GOT/PLT relocation. | |
57 | Local undefined weak symbol is always resolved to 0. | |
58 | */ | |
c5bce5c6 | 59 | #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \ |
0afcef53 | 60 | ((EH)->elf.root.type == bfd_link_hash_undefweak \ |
6999821f | 61 | && (SYMBOL_REFERENCES_LOCAL_P ((INFO), &(EH)->elf) \ |
0afcef53 | 62 | || (bfd_link_executable (INFO) \ |
98b273dc | 63 | && (EH)->zero_undefweak > 0))) |
0afcef53 L |
64 | |
65 | /* Should copy relocation be generated for a symbol. Don't generate | |
66 | copy relocation against a protected symbol defined in a shared | |
67 | object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. */ | |
68 | #define SYMBOL_NO_COPYRELOC(INFO, EH) \ | |
69 | ((EH)->def_protected \ | |
70 | && ((EH)->elf.root.type == bfd_link_hash_defined \ | |
71 | || (EH)->elf.root.type == bfd_link_hash_defweak) \ | |
72 | && elf_has_no_copy_on_protected ((EH)->elf.root.u.def.section->owner) \ | |
73 | && ((EH)->elf.root.u.def.section->owner->flags & DYNAMIC) != 0 \ | |
74 | && ((EH)->elf.root.u.def.section->flags & SEC_CODE) == 0) | |
75 | ||
daf1c414 L |
76 | /* TRUE if dynamic relocation is needed. If we are creating a shared |
77 | library, and this is a reloc against a global symbol, or a non PC | |
78 | relative reloc against a local symbol, then we need to copy the reloc | |
79 | into the shared library. However, if we are linking with -Bsymbolic, | |
80 | we do not need to copy a reloc against a global symbol which is | |
81 | defined in an object we are including in the link (i.e., DEF_REGULAR | |
82 | is set). At this point we have not seen all the input files, so it | |
83 | is possible that DEF_REGULAR is not set now but will be set later (it | |
84 | is never cleared). In case of a weak definition, DEF_REGULAR may be | |
85 | cleared later by a strong definition in a shared library. We account | |
86 | for that possibility below by storing information in the relocs_copied | |
87 | field of the hash table entry. A similar situation occurs when | |
88 | creating shared libraries and symbol visibility changes render the | |
89 | symbol local. | |
90 | ||
91 | If on the other hand, we are creating an executable, we may need to | |
92 | keep relocations for symbols satisfied by a dynamic library if we | |
93 | manage to avoid copy relocs for the symbol. | |
94 | ||
95 | We also need to generate dynamic pointer relocation against | |
96 | STT_GNU_IFUNC symbol in the non-code section. */ | |
97 | #define NEED_DYNAMIC_RELOCATION_P(INFO, H, SEC, R_TYPE, POINTER_TYPE) \ | |
98 | ((bfd_link_pic (INFO) \ | |
99 | && (! X86_PCREL_TYPE_P (R_TYPE) \ | |
100 | || ((H) != NULL \ | |
101 | && (! (bfd_link_pie (INFO) \ | |
102 | || SYMBOLIC_BIND ((INFO), (H))) \ | |
103 | || (H)->root.type == bfd_link_hash_defweak \ | |
104 | || !(H)->def_regular)))) \ | |
105 | || ((H) != NULL \ | |
106 | && (H)->type == STT_GNU_IFUNC \ | |
107 | && (R_TYPE) == POINTER_TYPE \ | |
108 | && ((SEC)->flags & SEC_CODE) == 0) \ | |
109 | || (ELIMINATE_COPY_RELOCS \ | |
110 | && !bfd_link_pic (INFO) \ | |
111 | && (H) != NULL \ | |
112 | && ((H)->root.type == bfd_link_hash_defweak \ | |
113 | || !(H)->def_regular))) | |
114 | ||
aebcc8ff L |
115 | /* TRUE if dynamic relocation should be generated. Don't copy a |
116 | pc-relative relocation into the output file if the symbol needs | |
117 | copy reloc or the symbol is undefined when building executable. | |
118 | Copy dynamic function pointer relocations. Don't generate dynamic | |
119 | relocations against resolved undefined weak symbols in PIE, except | |
120 | when PC32_RELOC is TRUE. Undefined weak symbol is bound locally | |
121 | when PIC is false. */ | |
122 | #define GENERATE_DYNAMIC_RELOCATION_P(INFO, EH, R_TYPE, \ | |
123 | NEED_COPY_RELOC_IN_PIE, \ | |
124 | RESOLVED_TO_ZERO, PC32_RELOC) \ | |
125 | ((bfd_link_pic (INFO) \ | |
126 | && !(NEED_COPY_RELOC_IN_PIE) \ | |
127 | && ((EH) == NULL \ | |
128 | || ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \ | |
129 | && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \ | |
130 | || (EH)->elf.root.type != bfd_link_hash_undefweak)) \ | |
131 | && ((!X86_PCREL_TYPE_P (R_TYPE) \ | |
132 | && !X86_SIZE_TYPE_P (R_TYPE)) \ | |
133 | || ! SYMBOL_CALLS_LOCAL ((INFO), &(EH)->elf))) \ | |
134 | || (ELIMINATE_COPY_RELOCS \ | |
135 | && !bfd_link_pic (INFO) \ | |
136 | && (EH) != NULL \ | |
137 | && (EH)->elf.dynindx != -1 \ | |
138 | && (!(EH)->elf.non_got_ref \ | |
139 | || (EH)->func_pointer_refcount > 0 \ | |
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 | ||
f70656b2 L |
165 | /* TRUE if relative relocation should be generated. GOT reference to |
166 | global symbol in PIC will lead to dynamic symbol. It becomes a | |
167 | problem when "time" or "times" is defined as a variable in an | |
168 | executable, clashing with functions of the same name in libc. If a | |
169 | symbol isn't undefined weak symbol, don't make it dynamic in PIC and | |
170 | generate relative relocation. */ | |
171 | #define GENERATE_RELATIVE_RELOC_P(INFO, H) \ | |
172 | ((H)->dynindx == -1 \ | |
173 | && !(H)->forced_local \ | |
174 | && (H)->root.type != bfd_link_hash_undefweak \ | |
175 | && bfd_link_pic (INFO)) | |
176 | ||
cf1070f1 L |
177 | /* TRUE if this is a pointer reference to a local IFUNC. */ |
178 | #define POINTER_LOCAL_IFUNC_P(INFO, H) \ | |
179 | ((H)->dynindx == -1 \ | |
180 | || (H)->forced_local \ | |
181 | || bfd_link_executable (INFO)) | |
182 | ||
183 | /* TRUE if this is a PLT reference to a local IFUNC. */ | |
184 | #define PLT_LOCAL_IFUNC_P(INFO, H) \ | |
185 | ((H)->dynindx == -1 \ | |
186 | || ((bfd_link_executable (INFO) \ | |
187 | || ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT) \ | |
188 | && (H)->def_regular \ | |
189 | && (H)->type == STT_GNU_IFUNC)) | |
190 | ||
51537393 L |
191 | /* TRUE if TLS IE->LE transition is OK. */ |
192 | #define TLS_TRANSITION_IE_TO_LE_P(INFO, H, TLS_TYPE) \ | |
193 | (bfd_link_executable (INFO) \ | |
194 | && (H) != NULL \ | |
195 | && (H)->dynindx == -1 \ | |
196 | && (TLS_TYPE & GOT_TLS_IE)) | |
197 | ||
f3180fa9 L |
198 | /* Verify that the symbol has an entry in the procedure linkage table. */ |
199 | #define VERIFY_PLT_ENTRY(INFO, H, PLT, GOTPLT, RELPLT, LOCAL_UNDEFWEAK) \ | |
e0d8f431 L |
200 | do \ |
201 | { \ | |
202 | if (((H)->dynindx == -1 \ | |
203 | && !LOCAL_UNDEFWEAK \ | |
204 | && !(((H)->forced_local || bfd_link_executable (INFO)) \ | |
205 | && (H)->def_regular \ | |
206 | && (H)->type == STT_GNU_IFUNC)) \ | |
207 | || (PLT) == NULL \ | |
208 | || (GOTPLT) == NULL \ | |
209 | || (RELPLT) == NULL) \ | |
210 | abort (); \ | |
211 | } \ | |
212 | while (0); | |
f3180fa9 | 213 | |
ff38b4cc L |
214 | /* Verify that the symbol supports copy relocation. */ |
215 | #define VERIFY_COPY_RELOC(H, HTAB) \ | |
e0d8f431 L |
216 | do \ |
217 | { \ | |
218 | if ((H)->dynindx == -1 \ | |
219 | || ((H)->root.type != bfd_link_hash_defined \ | |
220 | && (H)->root.type != bfd_link_hash_defweak) \ | |
221 | || (HTAB)->elf.srelbss == NULL \ | |
222 | || (HTAB)->elf.sreldynrelro == NULL) \ | |
223 | abort (); \ | |
224 | } \ | |
225 | while (0); | |
ff38b4cc | 226 | |
0afcef53 L |
227 | /* x86 ELF linker hash entry. */ |
228 | ||
229 | struct elf_x86_link_hash_entry | |
230 | { | |
231 | struct elf_link_hash_entry elf; | |
232 | ||
233 | /* Track dynamic relocs copied for this symbol. */ | |
234 | struct elf_dyn_relocs *dyn_relocs; | |
235 | ||
236 | unsigned char tls_type; | |
237 | ||
98b273dc L |
238 | /* Bit 0: Symbol has no GOT nor PLT relocations. |
239 | Bit 1: Symbol has non-GOT/non-PLT relocations in text sections. | |
240 | zero_undefweak is initialized to 1 and undefined weak symbol | |
241 | should be resolved to 0 if zero_undefweak > 0. */ | |
242 | unsigned int zero_undefweak : 2; | |
0afcef53 L |
243 | |
244 | /* Don't call finish_dynamic_symbol on this symbol. */ | |
245 | unsigned int no_finish_dynamic_symbol : 1; | |
246 | ||
247 | /* TRUE if symbol is __tls_get_addr. */ | |
248 | unsigned int tls_get_addr : 1; | |
249 | ||
250 | /* TRUE if symbol is defined as a protected symbol. */ | |
251 | unsigned int def_protected : 1; | |
252 | ||
6999821f L |
253 | /* 0: Symbol references are unknown. |
254 | 1: Symbol references aren't local. | |
255 | 2: Symbol references are local. | |
256 | */ | |
257 | unsigned int local_ref : 2; | |
258 | ||
0a27fed7 L |
259 | /* TRUE if symbol is defined by linker. */ |
260 | unsigned int linker_def : 1; | |
261 | ||
f47432d4 | 262 | /* TRUE if symbol is referenced by R_386_GOTOFF relocation. This is |
c7df954f | 263 | only used by i386. */ |
0afcef53 L |
264 | unsigned int gotoff_ref : 1; |
265 | ||
266 | /* TRUE if a weak symbol with a real definition needs a copy reloc. | |
267 | When there is a weak symbol with a real definition, the processor | |
268 | independent code will have arranged for us to see the real | |
269 | definition first. We need to copy the needs_copy bit from the | |
270 | real definition and check it when allowing copy reloc in PIE. This | |
271 | is only used by x86-64. */ | |
272 | unsigned int needs_copy : 1; | |
273 | ||
274 | /* Reference count of C/C++ function pointer relocations in read-write | |
275 | section which can be resolved at run-time. */ | |
276 | bfd_signed_vma func_pointer_refcount; | |
277 | ||
278 | /* Information about the GOT PLT entry. Filled when there are both | |
279 | GOT and PLT relocations against the same function. */ | |
280 | union gotplt_union plt_got; | |
281 | ||
282 | /* Information about the second PLT entry. */ | |
283 | union gotplt_union plt_second; | |
284 | ||
285 | /* Offset of the GOTPLT entry reserved for the TLS descriptor, | |
286 | starting at the end of the jump table. */ | |
287 | bfd_vma tlsdesc_got; | |
288 | }; | |
289 | ||
765e526c L |
290 | struct elf_x86_lazy_plt_layout |
291 | { | |
292 | /* The first entry in an absolute lazy procedure linkage table looks | |
293 | like this. */ | |
294 | const bfd_byte *plt0_entry; | |
295 | unsigned int plt0_entry_size; /* Size of PLT0 entry. */ | |
296 | ||
297 | /* Later entries in an absolute lazy procedure linkage table look | |
298 | like this. */ | |
299 | const bfd_byte *plt_entry; | |
300 | unsigned int plt_entry_size; /* Size of each PLT entry. */ | |
301 | ||
302 | /* Offsets into plt0_entry that are to be replaced with GOT[1] and | |
303 | GOT[2]. */ | |
304 | unsigned int plt0_got1_offset; | |
305 | unsigned int plt0_got2_offset; | |
306 | ||
307 | /* Offset of the end of the PC-relative instruction containing | |
308 | plt0_got2_offset. This is for x86-64 only. */ | |
309 | unsigned int plt0_got2_insn_end; | |
310 | ||
311 | /* Offsets into plt_entry that are to be replaced with... */ | |
312 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ | |
313 | unsigned int plt_reloc_offset; /* ... offset into relocation table. */ | |
314 | unsigned int plt_plt_offset; /* ... offset to start of .plt. */ | |
315 | ||
316 | /* Length of the PC-relative instruction containing plt_got_offset. | |
317 | This is used for x86-64 only. */ | |
318 | unsigned int plt_got_insn_size; | |
319 | ||
320 | /* Offset of the end of the PC-relative jump to plt0_entry. This is | |
321 | used for x86-64 only. */ | |
322 | unsigned int plt_plt_insn_end; | |
323 | ||
324 | /* Offset into plt_entry where the initial value of the GOT entry | |
325 | points. */ | |
326 | unsigned int plt_lazy_offset; | |
327 | ||
328 | /* The first entry in a PIC lazy procedure linkage table looks like | |
a6798bab | 329 | this. */ |
765e526c L |
330 | const bfd_byte *pic_plt0_entry; |
331 | ||
332 | /* Subsequent entries in a PIC lazy procedure linkage table look | |
a6798bab | 333 | like this. */ |
765e526c L |
334 | const bfd_byte *pic_plt_entry; |
335 | ||
336 | /* .eh_frame covering the lazy .plt section. */ | |
337 | const bfd_byte *eh_frame_plt; | |
338 | unsigned int eh_frame_plt_size; | |
339 | }; | |
340 | ||
341 | struct elf_x86_non_lazy_plt_layout | |
342 | { | |
343 | /* Entries in an absolute non-lazy procedure linkage table look like | |
344 | this. */ | |
345 | const bfd_byte *plt_entry; | |
a6798bab | 346 | /* Entries in a PIC non-lazy procedure linkage table look like this. */ |
765e526c L |
347 | const bfd_byte *pic_plt_entry; |
348 | ||
349 | unsigned int plt_entry_size; /* Size of each PLT entry. */ | |
350 | ||
351 | /* Offsets into plt_entry that are to be replaced with... */ | |
352 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ | |
353 | ||
354 | /* Length of the PC-relative instruction containing plt_got_offset. | |
355 | This is used for x86-64 only. */ | |
356 | unsigned int plt_got_insn_size; | |
357 | ||
358 | /* .eh_frame covering the non-lazy .plt section. */ | |
359 | const bfd_byte *eh_frame_plt; | |
360 | unsigned int eh_frame_plt_size; | |
361 | }; | |
362 | ||
363 | struct elf_x86_plt_layout | |
364 | { | |
365 | /* The first entry in a lazy procedure linkage table looks like this. | |
366 | This is only used for i386 where absolute PLT0 and PIC PLT0 are | |
367 | different. */ | |
368 | const bfd_byte *plt0_entry; | |
369 | /* Entries in a procedure linkage table look like this. */ | |
370 | const bfd_byte *plt_entry; | |
371 | unsigned int plt_entry_size; /* Size of each PLT entry. */ | |
372 | ||
373 | /* 1 has PLT0. */ | |
374 | unsigned int has_plt0; | |
375 | ||
376 | /* Offsets into plt_entry that are to be replaced with... */ | |
377 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ | |
378 | ||
379 | /* Length of the PC-relative instruction containing plt_got_offset. | |
380 | This is only used for x86-64. */ | |
381 | unsigned int plt_got_insn_size; | |
382 | ||
383 | /* .eh_frame covering the .plt section. */ | |
384 | const bfd_byte *eh_frame_plt; | |
385 | unsigned int eh_frame_plt_size; | |
386 | }; | |
387 | ||
6b9553e2 | 388 | /* Values in tls_type of x86 ELF linker hash entry. */ |
0afcef53 L |
389 | #define GOT_UNKNOWN 0 |
390 | #define GOT_NORMAL 1 | |
391 | #define GOT_TLS_GD 2 | |
6b9553e2 L |
392 | #define GOT_TLS_IE 4 |
393 | #define GOT_TLS_IE_POS 5 | |
394 | #define GOT_TLS_IE_NEG 6 | |
395 | #define GOT_TLS_IE_BOTH 7 | |
396 | #define GOT_TLS_GDESC 8 | |
397 | #define GOT_TLS_GD_BOTH_P(type) \ | |
398 | ((type) == (GOT_TLS_GD | GOT_TLS_GDESC)) | |
399 | #define GOT_TLS_GD_P(type) \ | |
400 | ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type)) | |
401 | #define GOT_TLS_GDESC_P(type) \ | |
402 | ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type)) | |
403 | #define GOT_TLS_GD_ANY_P(type) \ | |
404 | (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type)) | |
0afcef53 L |
405 | |
406 | #define elf_x86_hash_entry(ent) \ | |
407 | ((struct elf_x86_link_hash_entry *)(ent)) | |
408 | ||
409 | /* x86 ELF linker hash table. */ | |
410 | ||
411 | struct elf_x86_link_hash_table | |
412 | { | |
413 | struct elf_link_hash_table elf; | |
414 | ||
415 | /* Short-cuts to get to dynamic linker sections. */ | |
416 | asection *interp; | |
417 | asection *plt_eh_frame; | |
418 | asection *plt_second; | |
419 | asection *plt_second_eh_frame; | |
420 | asection *plt_got; | |
421 | asection *plt_got_eh_frame; | |
422 | ||
765e526c L |
423 | /* Parameters describing PLT generation, lazy or non-lazy. */ |
424 | struct elf_x86_plt_layout plt; | |
425 | ||
426 | /* Parameters describing lazy PLT generation. */ | |
427 | const struct elf_x86_lazy_plt_layout *lazy_plt; | |
428 | ||
429 | /* Parameters describing non-lazy PLT generation. */ | |
430 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; | |
431 | ||
0afcef53 L |
432 | union |
433 | { | |
434 | bfd_signed_vma refcount; | |
435 | bfd_vma offset; | |
436 | } tls_ld_or_ldm_got; | |
437 | ||
438 | /* The amount of space used by the jump slots in the GOT. */ | |
439 | bfd_vma sgotplt_jump_table_size; | |
440 | ||
441 | /* Small local sym cache. */ | |
442 | struct sym_cache sym_cache; | |
443 | ||
444 | /* _TLS_MODULE_BASE_ symbol. */ | |
445 | struct bfd_link_hash_entry *tls_module_base; | |
446 | ||
447 | /* Used by local STT_GNU_IFUNC symbols. */ | |
448 | htab_t loc_hash_table; | |
449 | void * loc_hash_memory; | |
450 | ||
0afcef53 L |
451 | /* The offset into sgot of the GOT entry used by the PLT entry |
452 | above. */ | |
453 | bfd_vma tlsdesc_got; | |
454 | ||
455 | /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */ | |
456 | bfd_vma next_jump_slot_index; | |
457 | /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */ | |
458 | bfd_vma next_irelative_index; | |
459 | ||
460 | /* TRUE if there are dynamic relocs against IFUNC symbols that apply | |
461 | to read-only sections. */ | |
462 | bfd_boolean readonly_dynrelocs_against_ifunc; | |
463 | ||
2926eb2c L |
464 | /* TRUE if this is a VxWorks x86 target. This is only used for |
465 | i386. */ | |
eeb2f20a L |
466 | bfd_boolean is_vxworks; |
467 | ||
765e526c L |
468 | /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. |
469 | This is used for i386 only. */ | |
470 | asection *srelplt2; | |
471 | ||
472 | /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. This | |
2926eb2c | 473 | is only used for i386. */ |
765e526c L |
474 | bfd_vma next_tls_desc_index; |
475 | ||
2926eb2c L |
476 | /* The offset into splt of the PLT entry for the TLS descriptor |
477 | resolver. Special values are 0, if not necessary (or not found | |
478 | to be necessary yet), and -1 if needed but not determined | |
479 | yet. This is only used for x86-64. */ | |
480 | bfd_vma tlsdesc_plt; | |
481 | ||
0afcef53 L |
482 | bfd_vma (*r_info) (bfd_vma, bfd_vma); |
483 | bfd_vma (*r_sym) (bfd_vma); | |
5e2ac45d | 484 | bfd_boolean (*is_reloc_section) (const char *); |
fe53b4a4 | 485 | enum elf_target_id target_id; |
503294e7 | 486 | unsigned int sizeof_reloc; |
5e2ac45d L |
487 | unsigned int dt_reloc; |
488 | unsigned int dt_reloc_sz; | |
489 | unsigned int dt_reloc_ent; | |
9ff114ca | 490 | unsigned int got_entry_size; |
0afcef53 L |
491 | unsigned int pointer_r_type; |
492 | int dynamic_interpreter_size; | |
493 | const char *dynamic_interpreter; | |
494 | const char *tls_get_addr; | |
495 | }; | |
496 | ||
1de031c8 | 497 | struct elf_x86_init_table |
a6798bab L |
498 | { |
499 | /* The lazy PLT layout. */ | |
500 | const struct elf_x86_lazy_plt_layout *lazy_plt; | |
501 | ||
502 | /* The non-lazy PLT layout. */ | |
503 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; | |
504 | ||
505 | /* The lazy PLT layout for IBT. */ | |
506 | const struct elf_x86_lazy_plt_layout *lazy_ibt_plt; | |
507 | ||
508 | /* The non-lazy PLT layout for IBT. */ | |
509 | const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt; | |
510 | ||
c6295c22 | 511 | /* TRUE if this is a normal x86 target. */ |
a6798bab L |
512 | bfd_boolean normal_target; |
513 | ||
514 | /* TRUE if this is a VxWorks x86 target. */ | |
515 | bfd_boolean is_vxworks; | |
7a382c1c L |
516 | |
517 | bfd_vma (*r_info) (bfd_vma, bfd_vma); | |
518 | bfd_vma (*r_sym) (bfd_vma); | |
a6798bab L |
519 | }; |
520 | ||
0afcef53 L |
521 | struct elf_x86_obj_tdata |
522 | { | |
523 | struct elf_obj_tdata root; | |
524 | ||
525 | /* tls_type for each local got entry. */ | |
526 | char *local_got_tls_type; | |
527 | ||
528 | /* GOTPLT entries for TLS descriptors. */ | |
529 | bfd_vma *local_tlsdesc_gotent; | |
530 | }; | |
531 | ||
f493882d L |
532 | enum elf_x86_plt_type |
533 | { | |
534 | plt_non_lazy = 0, | |
535 | plt_lazy = 1 << 0, | |
536 | plt_pic = 1 << 1, | |
537 | plt_second = 1 << 2, | |
538 | plt_unknown = -1 | |
539 | }; | |
540 | ||
541 | struct elf_x86_plt | |
542 | { | |
543 | const char *name; | |
544 | asection *sec; | |
545 | bfd_byte *contents; | |
546 | enum elf_x86_plt_type type; | |
547 | unsigned int plt_got_offset; | |
548 | unsigned int plt_entry_size; | |
549 | unsigned int plt_got_insn_size; /* Only used for x86-64. */ | |
550 | long count; | |
551 | }; | |
552 | ||
0afcef53 L |
553 | #define elf_x86_tdata(abfd) \ |
554 | ((struct elf_x86_obj_tdata *) (abfd)->tdata.any) | |
555 | ||
556 | #define elf_x86_local_got_tls_type(abfd) \ | |
557 | (elf_x86_tdata (abfd)->local_got_tls_type) | |
558 | ||
559 | #define elf_x86_local_tlsdesc_gotent(abfd) \ | |
560 | (elf_x86_tdata (abfd)->local_tlsdesc_gotent) | |
561 | ||
9ff114ca L |
562 | #define elf_x86_compute_jump_table_size(htab) \ |
563 | ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size) | |
564 | ||
fe53b4a4 L |
565 | #define is_x86_elf(bfd, htab) \ |
566 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
567 | && elf_tdata (bfd) != NULL \ | |
568 | && elf_object_id (bfd) == (htab)->target_id) | |
569 | ||
39946cc2 L |
570 | extern bfd_boolean _bfd_x86_elf_mkobject |
571 | (bfd *); | |
572 | ||
0afcef53 L |
573 | extern void _bfd_x86_elf_set_tls_module_base |
574 | (struct bfd_link_info *); | |
575 | ||
576 | extern bfd_vma _bfd_x86_elf_dtpoff_base | |
577 | (struct bfd_link_info *); | |
578 | ||
579 | extern bfd_boolean _bfd_x86_elf_readonly_dynrelocs | |
580 | (struct elf_link_hash_entry *, void *); | |
581 | ||
582 | extern struct elf_link_hash_entry * _bfd_elf_x86_get_local_sym_hash | |
583 | (struct elf_x86_link_hash_table *, bfd *, const Elf_Internal_Rela *, | |
584 | bfd_boolean); | |
585 | ||
586 | extern hashval_t _bfd_x86_elf_local_htab_hash | |
587 | (const void *); | |
588 | ||
589 | extern int _bfd_x86_elf_local_htab_eq | |
590 | (const void *, const void *); | |
591 | ||
592 | extern struct bfd_hash_entry * _bfd_x86_elf_link_hash_newfunc | |
593 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); | |
594 | ||
765e526c | 595 | extern struct bfd_link_hash_table * _bfd_x86_elf_link_hash_table_create |
0afcef53 L |
596 | (bfd *); |
597 | ||
598 | extern int _bfd_x86_elf_compare_relocs | |
599 | (const void *, const void *); | |
600 | ||
601 | extern bfd_boolean _bfd_x86_elf_link_check_relocs | |
602 | (bfd *, struct bfd_link_info *); | |
603 | ||
5e2ac45d L |
604 | extern bfd_boolean _bfd_x86_elf_size_dynamic_sections |
605 | (bfd *, struct bfd_link_info *); | |
606 | ||
0afcef53 L |
607 | extern bfd_boolean _bfd_x86_elf_always_size_sections |
608 | (bfd *, struct bfd_link_info *); | |
609 | ||
610 | extern void _bfd_x86_elf_merge_symbol_attribute | |
611 | (struct elf_link_hash_entry *, const Elf_Internal_Sym *, | |
612 | bfd_boolean, bfd_boolean); | |
613 | ||
614 | extern void _bfd_x86_elf_copy_indirect_symbol | |
615 | (struct bfd_link_info *, struct elf_link_hash_entry *, | |
616 | struct elf_link_hash_entry *); | |
617 | ||
618 | extern bfd_boolean _bfd_x86_elf_fixup_symbol | |
619 | (struct bfd_link_info *, struct elf_link_hash_entry *); | |
620 | ||
621 | extern bfd_boolean _bfd_x86_elf_hash_symbol | |
622 | (struct elf_link_hash_entry *); | |
623 | ||
eeb2f20a L |
624 | extern bfd_boolean _bfd_x86_elf_adjust_dynamic_symbol |
625 | (struct bfd_link_info *, struct elf_link_hash_entry *); | |
626 | ||
6999821f L |
627 | extern bfd_boolean _bfd_x86_elf_link_symbol_references_local |
628 | (struct bfd_link_info *, struct elf_link_hash_entry *); | |
629 | ||
4f501a24 L |
630 | extern asection * _bfd_x86_elf_gc_mark_hook |
631 | (asection *, struct bfd_link_info *, Elf_Internal_Rela *, | |
632 | struct elf_link_hash_entry *, Elf_Internal_Sym *); | |
633 | ||
f493882d L |
634 | extern long _bfd_x86_elf_get_synthetic_symtab |
635 | (bfd *, long, long, bfd_vma, struct elf_x86_plt [], asymbol **, | |
636 | asymbol **); | |
637 | ||
0afcef53 L |
638 | extern enum elf_property_kind _bfd_x86_elf_parse_gnu_properties |
639 | (bfd *, unsigned int, bfd_byte *, unsigned int); | |
640 | ||
641 | extern bfd_boolean _bfd_x86_elf_merge_gnu_properties | |
642 | (struct bfd_link_info *, bfd *, elf_property *, elf_property *); | |
643 | ||
a6798bab | 644 | extern bfd * _bfd_x86_elf_link_setup_gnu_properties |
1de031c8 | 645 | (struct bfd_link_info *, struct elf_x86_init_table *); |
a6798bab | 646 | |
39946cc2 L |
647 | #define bfd_elf64_mkobject \ |
648 | _bfd_x86_elf_mkobject | |
649 | #define bfd_elf32_mkobject \ | |
650 | _bfd_x86_elf_mkobject | |
765e526c L |
651 | #define bfd_elf64_bfd_link_hash_table_create \ |
652 | _bfd_x86_elf_link_hash_table_create | |
653 | #define bfd_elf32_bfd_link_hash_table_create \ | |
654 | _bfd_x86_elf_link_hash_table_create | |
0afcef53 L |
655 | #define bfd_elf64_bfd_link_check_relocs \ |
656 | _bfd_x86_elf_link_check_relocs | |
657 | #define bfd_elf32_bfd_link_check_relocs \ | |
658 | _bfd_x86_elf_link_check_relocs | |
659 | ||
5e2ac45d L |
660 | #define elf_backend_size_dynamic_sections \ |
661 | _bfd_x86_elf_size_dynamic_sections | |
0afcef53 L |
662 | #define elf_backend_always_size_sections \ |
663 | _bfd_x86_elf_always_size_sections | |
664 | #define elf_backend_merge_symbol_attribute \ | |
665 | _bfd_x86_elf_merge_symbol_attribute | |
666 | #define elf_backend_copy_indirect_symbol \ | |
667 | _bfd_x86_elf_copy_indirect_symbol | |
668 | #define elf_backend_fixup_symbol \ | |
669 | _bfd_x86_elf_fixup_symbol | |
670 | #define elf_backend_hash_symbol \ | |
671 | _bfd_x86_elf_hash_symbol | |
eeb2f20a L |
672 | #define elf_backend_adjust_dynamic_symbol \ |
673 | _bfd_x86_elf_adjust_dynamic_symbol | |
4f501a24 L |
674 | #define elf_backend_gc_mark_hook \ |
675 | _bfd_x86_elf_gc_mark_hook | |
0afcef53 L |
676 | #define elf_backend_omit_section_dynsym \ |
677 | ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) | |
678 | #define elf_backend_parse_gnu_properties \ | |
679 | _bfd_x86_elf_parse_gnu_properties | |
680 | #define elf_backend_merge_gnu_properties \ | |
681 | _bfd_x86_elf_merge_gnu_properties |