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