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