1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
32 #include "libiberty.h"
34 #include "opcode/i386.h"
35 #include "elf/x86-64.h"
42 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
43 #define MINUS_ONE (~ (bfd_vma) 0)
45 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
46 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
47 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
48 since they are the same. */
50 #define ABI_64_P(abfd) \
51 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
53 /* The relocation "howto" table. Order of fields:
54 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
55 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
56 static reloc_howto_type x86_64_elf_howto_table[] =
58 HOWTO(R_X86_64_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
59 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
61 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
62 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
64 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
65 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
67 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
68 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
71 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
74 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
77 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
79 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
80 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
82 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
83 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
85 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
86 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
88 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
89 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
91 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
92 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
94 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
95 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
96 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
97 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
98 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
99 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
100 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
101 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
102 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
103 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
105 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
106 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
108 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
109 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
111 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
112 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
114 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
115 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
117 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
118 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
120 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
121 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
123 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
124 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
126 HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
127 bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
129 HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
130 bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
131 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
132 HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
133 bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
134 FALSE, 0xffffffff, 0xffffffff, TRUE),
135 HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
136 bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
138 HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
139 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
141 HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
142 bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
143 FALSE, MINUS_ONE, MINUS_ONE, TRUE),
144 HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
145 bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
147 HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
148 bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
150 HOWTO(R_X86_64_SIZE32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
151 bfd_elf_generic_reloc, "R_X86_64_SIZE32", FALSE, 0xffffffff, 0xffffffff,
153 HOWTO(R_X86_64_SIZE64, 0, 4, 64, FALSE, 0, complain_overflow_unsigned,
154 bfd_elf_generic_reloc, "R_X86_64_SIZE64", FALSE, MINUS_ONE, MINUS_ONE,
156 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
157 complain_overflow_bitfield, bfd_elf_generic_reloc,
158 "R_X86_64_GOTPC32_TLSDESC",
159 FALSE, 0xffffffff, 0xffffffff, TRUE),
160 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
161 complain_overflow_dont, bfd_elf_generic_reloc,
162 "R_X86_64_TLSDESC_CALL",
164 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
165 complain_overflow_bitfield, bfd_elf_generic_reloc,
167 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
168 HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
169 bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
171 HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
172 bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", FALSE, MINUS_ONE,
174 HOWTO(R_X86_64_PC32_BND, 0, 2, 32, TRUE, 0, complain_overflow_signed,
175 bfd_elf_generic_reloc, "R_X86_64_PC32_BND", FALSE, 0xffffffff, 0xffffffff,
177 HOWTO(R_X86_64_PLT32_BND, 0, 2, 32, TRUE, 0, complain_overflow_signed,
178 bfd_elf_generic_reloc, "R_X86_64_PLT32_BND", FALSE, 0xffffffff, 0xffffffff,
180 HOWTO(R_X86_64_GOTPCRELX, 0, 2, 32, TRUE, 0, complain_overflow_signed,
181 bfd_elf_generic_reloc, "R_X86_64_GOTPCRELX", FALSE, 0xffffffff,
183 HOWTO(R_X86_64_REX_GOTPCRELX, 0, 2, 32, TRUE, 0, complain_overflow_signed,
184 bfd_elf_generic_reloc, "R_X86_64_REX_GOTPCRELX", FALSE, 0xffffffff,
187 /* We have a gap in the reloc numbers here.
188 R_X86_64_standard counts the number up to this point, and
189 R_X86_64_vt_offset is the value to subtract from a reloc type of
190 R_X86_64_GNU_VT* to form an index into this table. */
191 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
192 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
194 /* GNU extension to record C++ vtable hierarchy. */
195 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
196 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
198 /* GNU extension to record C++ vtable member usage. */
199 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
200 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
203 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
204 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
205 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
209 #define IS_X86_64_PCREL_TYPE(TYPE) \
210 ( ((TYPE) == R_X86_64_PC8) \
211 || ((TYPE) == R_X86_64_PC16) \
212 || ((TYPE) == R_X86_64_PC32) \
213 || ((TYPE) == R_X86_64_PC32_BND) \
214 || ((TYPE) == R_X86_64_PC64))
216 /* Map BFD relocs to the x86_64 elf relocs. */
219 bfd_reloc_code_real_type bfd_reloc_val;
220 unsigned char elf_reloc_val;
223 static const struct elf_reloc_map x86_64_reloc_map[] =
225 { BFD_RELOC_NONE, R_X86_64_NONE, },
226 { BFD_RELOC_64, R_X86_64_64, },
227 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
228 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
229 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
230 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
231 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
232 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
233 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
234 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
235 { BFD_RELOC_32, R_X86_64_32, },
236 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
237 { BFD_RELOC_16, R_X86_64_16, },
238 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
239 { BFD_RELOC_8, R_X86_64_8, },
240 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
241 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
242 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
243 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
244 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
245 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
246 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
247 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
248 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
249 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
250 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
251 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
252 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
253 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
254 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
255 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
256 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
257 { BFD_RELOC_SIZE32, R_X86_64_SIZE32, },
258 { BFD_RELOC_SIZE64, R_X86_64_SIZE64, },
259 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
260 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
261 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
262 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
263 { BFD_RELOC_X86_64_PC32_BND, R_X86_64_PC32_BND, },
264 { BFD_RELOC_X86_64_PLT32_BND, R_X86_64_PLT32_BND, },
265 { BFD_RELOC_X86_64_GOTPCRELX, R_X86_64_GOTPCRELX, },
266 { BFD_RELOC_X86_64_REX_GOTPCRELX, R_X86_64_REX_GOTPCRELX, },
267 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
268 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
271 static reloc_howto_type *
272 elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
276 if (r_type == (unsigned int) R_X86_64_32)
281 i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
283 else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
284 || r_type >= (unsigned int) R_X86_64_max)
286 if (r_type >= (unsigned int) R_X86_64_standard)
288 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
290 r_type = R_X86_64_NONE;
295 i = r_type - (unsigned int) R_X86_64_vt_offset;
296 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
297 return &x86_64_elf_howto_table[i];
300 /* Given a BFD reloc type, return a HOWTO structure. */
301 static reloc_howto_type *
302 elf_x86_64_reloc_type_lookup (bfd *abfd,
303 bfd_reloc_code_real_type code)
307 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
310 if (x86_64_reloc_map[i].bfd_reloc_val == code)
311 return elf_x86_64_rtype_to_howto (abfd,
312 x86_64_reloc_map[i].elf_reloc_val);
317 static reloc_howto_type *
318 elf_x86_64_reloc_name_lookup (bfd *abfd,
323 if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
325 /* Get x32 R_X86_64_32. */
326 reloc_howto_type *reloc
327 = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
328 BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
332 for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
333 if (x86_64_elf_howto_table[i].name != NULL
334 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
335 return &x86_64_elf_howto_table[i];
340 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
343 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
344 Elf_Internal_Rela *dst)
348 r_type = ELF32_R_TYPE (dst->r_info);
349 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
350 BFD_ASSERT (r_type == cache_ptr->howto->type);
353 /* Support for core dump NOTE sections. */
355 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
360 switch (note->descsz)
365 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
367 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
370 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
378 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
380 elf_tdata (abfd)->core->signal
381 = bfd_get_16 (abfd, note->descdata + 12);
384 elf_tdata (abfd)->core->lwpid
385 = bfd_get_32 (abfd, note->descdata + 32);
394 /* Make a ".reg/999" section. */
395 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
396 size, note->descpos + offset);
400 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
402 switch (note->descsz)
407 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
408 elf_tdata (abfd)->core->pid
409 = bfd_get_32 (abfd, note->descdata + 12);
410 elf_tdata (abfd)->core->program
411 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
412 elf_tdata (abfd)->core->command
413 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
416 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
417 elf_tdata (abfd)->core->pid
418 = bfd_get_32 (abfd, note->descdata + 24);
419 elf_tdata (abfd)->core->program
420 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
421 elf_tdata (abfd)->core->command
422 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
425 /* Note that for some reason, a spurious space is tacked
426 onto the end of the args in some (at least one anyway)
427 implementations, so strip it off if it exists. */
430 char *command = elf_tdata (abfd)->core->command;
431 int n = strlen (command);
433 if (0 < n && command[n - 1] == ' ')
434 command[n - 1] = '\0';
442 elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz,
445 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
447 const char *fname, *psargs;
458 va_start (ap, note_type);
459 fname = va_arg (ap, const char *);
460 psargs = va_arg (ap, const char *);
463 if (bed->s->elfclass == ELFCLASS32)
466 memset (&data, 0, sizeof (data));
467 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
468 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
469 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
470 &data, sizeof (data));
475 memset (&data, 0, sizeof (data));
476 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
477 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
478 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
479 &data, sizeof (data));
484 va_start (ap, note_type);
485 pid = va_arg (ap, long);
486 cursig = va_arg (ap, int);
487 gregs = va_arg (ap, const void *);
490 if (bed->s->elfclass == ELFCLASS32)
492 if (bed->elf_machine_code == EM_X86_64)
494 prstatusx32_t prstat;
495 memset (&prstat, 0, sizeof (prstat));
497 prstat.pr_cursig = cursig;
498 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
499 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
500 &prstat, sizeof (prstat));
505 memset (&prstat, 0, sizeof (prstat));
507 prstat.pr_cursig = cursig;
508 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
509 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
510 &prstat, sizeof (prstat));
516 memset (&prstat, 0, sizeof (prstat));
518 prstat.pr_cursig = cursig;
519 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
520 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
521 &prstat, sizeof (prstat));
528 /* Functions for the x86-64 ELF linker. */
530 /* The name of the dynamic interpreter. This is put in the .interp
533 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
534 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
536 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
537 copying dynamic variables from a shared lib into an app's dynbss
538 section, and instead use a dynamic relocation to point into the
540 #define ELIMINATE_COPY_RELOCS 1
542 /* The size in bytes of an entry in the global offset table. */
544 #define GOT_ENTRY_SIZE 8
546 /* The size in bytes of an entry in the procedure linkage table. */
548 #define PLT_ENTRY_SIZE 16
550 /* The first entry in a procedure linkage table looks like this. See the
551 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
553 static const bfd_byte elf_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
555 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
556 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
557 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
560 /* Subsequent entries in a procedure linkage table look like this. */
562 static const bfd_byte elf_x86_64_plt_entry[PLT_ENTRY_SIZE] =
564 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
565 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
566 0x68, /* pushq immediate */
567 0, 0, 0, 0, /* replaced with index into relocation table. */
568 0xe9, /* jmp relative */
569 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
572 /* The first entry in a procedure linkage table with BND relocations
575 static const bfd_byte elf_x86_64_bnd_plt0_entry[PLT_ENTRY_SIZE] =
577 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
578 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
579 0x0f, 0x1f, 0 /* nopl (%rax) */
582 /* Subsequent entries for legacy branches in a procedure linkage table
583 with BND relocations look like this. */
585 static const bfd_byte elf_x86_64_legacy_plt_entry[PLT_ENTRY_SIZE] =
587 0x68, 0, 0, 0, 0, /* pushq immediate */
588 0xe9, 0, 0, 0, 0, /* jmpq relative */
589 0x66, 0x0f, 0x1f, 0x44, 0, 0 /* nopw (%rax,%rax,1) */
592 /* Subsequent entries for branches with BND prefx in a procedure linkage
593 table with BND relocations look like this. */
595 static const bfd_byte elf_x86_64_bnd_plt_entry[PLT_ENTRY_SIZE] =
597 0x68, 0, 0, 0, 0, /* pushq immediate */
598 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
599 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
602 /* Entries for legacy branches in the second procedure linkage table
605 static const bfd_byte elf_x86_64_legacy_plt2_entry[8] =
607 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
608 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
609 0x66, 0x90 /* xchg %ax,%ax */
612 /* Entries for branches with BND prefix in the second procedure linkage
613 table look like this. */
615 static const bfd_byte elf_x86_64_bnd_plt2_entry[8] =
617 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
618 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
622 /* .eh_frame covering the .plt section. */
624 static const bfd_byte elf_x86_64_eh_frame_plt[] =
626 #define PLT_CIE_LENGTH 20
627 #define PLT_FDE_LENGTH 36
628 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
629 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
630 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
631 0, 0, 0, 0, /* CIE ID */
633 'z', 'R', 0, /* Augmentation string */
634 1, /* Code alignment factor */
635 0x78, /* Data alignment factor */
636 16, /* Return address column */
637 1, /* Augmentation size */
638 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
639 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
640 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
641 DW_CFA_nop, DW_CFA_nop,
643 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
644 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
645 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
646 0, 0, 0, 0, /* .plt size goes here */
647 0, /* Augmentation size */
648 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
649 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
650 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
651 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
652 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
653 11, /* Block length */
654 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
655 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
656 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
657 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
658 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
661 /* .eh_frame covering the .plt.got section. */
663 static const bfd_byte elf_x86_64_eh_frame_plt_got[] =
665 #define PLT_GOT_FDE_LENGTH 20
666 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
667 0, 0, 0, 0, /* CIE ID */
669 'z', 'R', 0, /* Augmentation string */
670 1, /* Code alignment factor */
671 0x78, /* Data alignment factor */
672 16, /* Return address column */
673 1, /* Augmentation size */
674 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
675 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
676 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
677 DW_CFA_nop, DW_CFA_nop,
679 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
680 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
681 0, 0, 0, 0, /* the start of .plt.got goes here */
682 0, 0, 0, 0, /* .plt.got size goes here */
683 0, /* Augmentation size */
684 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop,
685 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
688 /* Architecture-specific backend data for x86-64. */
690 struct elf_x86_64_backend_data
692 /* Templates for the initial PLT entry and for subsequent entries. */
693 const bfd_byte *plt0_entry;
694 const bfd_byte *plt_entry;
695 unsigned int plt_entry_size; /* Size of each PLT entry. */
697 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
698 unsigned int plt0_got1_offset;
699 unsigned int plt0_got2_offset;
701 /* Offset of the end of the PC-relative instruction containing
703 unsigned int plt0_got2_insn_end;
705 /* Offsets into plt_entry that are to be replaced with... */
706 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
707 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
708 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
710 /* Length of the PC-relative instruction containing plt_got_offset. */
711 unsigned int plt_got_insn_size;
713 /* Offset of the end of the PC-relative jump to plt0_entry. */
714 unsigned int plt_plt_insn_end;
716 /* Offset into plt_entry where the initial value of the GOT entry points. */
717 unsigned int plt_lazy_offset;
719 /* .eh_frame covering the .plt section. */
720 const bfd_byte *eh_frame_plt;
721 unsigned int eh_frame_plt_size;
723 /* .eh_frame covering the .plt.got section. */
724 const bfd_byte *eh_frame_plt_got;
725 unsigned int eh_frame_plt_got_size;
728 #define get_elf_x86_64_arch_data(bed) \
729 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
731 #define get_elf_x86_64_backend_data(abfd) \
732 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
734 #define GET_PLT_ENTRY_SIZE(abfd) \
735 get_elf_x86_64_backend_data (abfd)->plt_entry_size
737 /* These are the standard parameters. */
738 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
740 elf_x86_64_plt0_entry, /* plt0_entry */
741 elf_x86_64_plt_entry, /* plt_entry */
742 sizeof (elf_x86_64_plt_entry), /* plt_entry_size */
743 2, /* plt0_got1_offset */
744 8, /* plt0_got2_offset */
745 12, /* plt0_got2_insn_end */
746 2, /* plt_got_offset */
747 7, /* plt_reloc_offset */
748 12, /* plt_plt_offset */
749 6, /* plt_got_insn_size */
750 PLT_ENTRY_SIZE, /* plt_plt_insn_end */
751 6, /* plt_lazy_offset */
752 elf_x86_64_eh_frame_plt, /* eh_frame_plt */
753 sizeof (elf_x86_64_eh_frame_plt), /* eh_frame_plt_size */
754 elf_x86_64_eh_frame_plt_got, /* eh_frame_plt_got */
755 sizeof (elf_x86_64_eh_frame_plt_got), /* eh_frame_plt_got_size */
758 static const struct elf_x86_64_backend_data elf_x86_64_bnd_arch_bed =
760 elf_x86_64_bnd_plt0_entry, /* plt0_entry */
761 elf_x86_64_bnd_plt_entry, /* plt_entry */
762 sizeof (elf_x86_64_bnd_plt_entry), /* plt_entry_size */
763 2, /* plt0_got1_offset */
764 1+8, /* plt0_got2_offset */
765 1+12, /* plt0_got2_insn_end */
766 1+2, /* plt_got_offset */
767 1, /* plt_reloc_offset */
768 7, /* plt_plt_offset */
769 1+6, /* plt_got_insn_size */
770 11, /* plt_plt_insn_end */
771 0, /* plt_lazy_offset */
772 elf_x86_64_eh_frame_plt, /* eh_frame_plt */
773 sizeof (elf_x86_64_eh_frame_plt), /* eh_frame_plt_size */
774 /* FIXME: Needs .eh_frame coverage. */
775 NULL, /* eh_frame_plt_got */
776 0, /* eh_frame_plt_got_size */
779 #define elf_backend_arch_data &elf_x86_64_arch_bed
781 /* Is a undefined weak symbol which is resolved to 0. Reference to an
782 undefined weak symbol is resolved to 0 when building executable if
784 1. Has non-GOT/non-PLT relocations in text section. Or
785 2. Has no GOT/PLT relocation.
787 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
788 ((EH)->elf.root.type == bfd_link_hash_undefweak \
789 && bfd_link_executable (INFO) \
790 && (elf_x86_64_hash_table (INFO)->interp == NULL \
792 || (EH)->has_non_got_reloc \
793 || !(INFO)->dynamic_undefined_weak))
795 /* x86-64 ELF linker hash entry. */
797 struct elf_x86_64_link_hash_entry
799 struct elf_link_hash_entry elf;
801 /* Track dynamic relocs copied for this symbol. */
802 struct elf_dyn_relocs *dyn_relocs;
804 #define GOT_UNKNOWN 0
808 #define GOT_TLS_GDESC 4
809 #define GOT_TLS_GD_BOTH_P(type) \
810 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
811 #define GOT_TLS_GD_P(type) \
812 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
813 #define GOT_TLS_GDESC_P(type) \
814 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
815 #define GOT_TLS_GD_ANY_P(type) \
816 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
817 unsigned char tls_type;
819 /* TRUE if a weak symbol with a real definition needs a copy reloc.
820 When there is a weak symbol with a real definition, the processor
821 independent code will have arranged for us to see the real
822 definition first. We need to copy the needs_copy bit from the
823 real definition and check it when allowing copy reloc in PIE. */
824 unsigned int needs_copy : 1;
826 /* TRUE if symbol has at least one BND relocation. */
827 unsigned int has_bnd_reloc : 1;
829 /* TRUE if symbol has GOT or PLT relocations. */
830 unsigned int has_got_reloc : 1;
832 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
833 unsigned int has_non_got_reloc : 1;
835 /* 0: symbol isn't __tls_get_addr.
836 1: symbol is __tls_get_addr.
837 2: symbol is unknown. */
838 unsigned int tls_get_addr : 2;
840 /* Reference count of C/C++ function pointer relocations in read-write
841 section which can be resolved at run-time. */
842 bfd_signed_vma func_pointer_refcount;
844 /* Information about the GOT PLT entry. Filled when there are both
845 GOT and PLT relocations against the same function. */
846 union gotplt_union plt_got;
848 /* Information about the second PLT entry. Filled when has_bnd_reloc is
850 union gotplt_union plt_bnd;
852 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
853 starting at the end of the jump table. */
857 #define elf_x86_64_hash_entry(ent) \
858 ((struct elf_x86_64_link_hash_entry *)(ent))
860 struct elf_x86_64_obj_tdata
862 struct elf_obj_tdata root;
864 /* tls_type for each local got entry. */
865 char *local_got_tls_type;
867 /* GOTPLT entries for TLS descriptors. */
868 bfd_vma *local_tlsdesc_gotent;
871 #define elf_x86_64_tdata(abfd) \
872 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
874 #define elf_x86_64_local_got_tls_type(abfd) \
875 (elf_x86_64_tdata (abfd)->local_got_tls_type)
877 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
878 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
880 #define is_x86_64_elf(bfd) \
881 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
882 && elf_tdata (bfd) != NULL \
883 && elf_object_id (bfd) == X86_64_ELF_DATA)
886 elf_x86_64_mkobject (bfd *abfd)
888 return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_64_obj_tdata),
892 /* x86-64 ELF linker hash table. */
894 struct elf_x86_64_link_hash_table
896 struct elf_link_hash_table elf;
898 /* Short-cuts to get to dynamic linker sections. */
902 asection *plt_eh_frame;
905 asection *plt_got_eh_frame;
909 bfd_signed_vma refcount;
913 /* The amount of space used by the jump slots in the GOT. */
914 bfd_vma sgotplt_jump_table_size;
916 /* Small local sym cache. */
917 struct sym_cache sym_cache;
919 bfd_vma (*r_info) (bfd_vma, bfd_vma);
920 bfd_vma (*r_sym) (bfd_vma);
921 unsigned int pointer_r_type;
922 const char *dynamic_interpreter;
923 int dynamic_interpreter_size;
925 /* _TLS_MODULE_BASE_ symbol. */
926 struct bfd_link_hash_entry *tls_module_base;
928 /* Used by local STT_GNU_IFUNC symbols. */
929 htab_t loc_hash_table;
930 void * loc_hash_memory;
932 /* The offset into splt of the PLT entry for the TLS descriptor
933 resolver. Special values are 0, if not necessary (or not found
934 to be necessary yet), and -1 if needed but not determined
937 /* The offset into sgot of the GOT entry used by the PLT entry
941 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
942 bfd_vma next_jump_slot_index;
943 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
944 bfd_vma next_irelative_index;
946 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
947 to read-only sections. */
948 bfd_boolean readonly_dynrelocs_against_ifunc;
951 /* Get the x86-64 ELF linker hash table from a link_info structure. */
953 #define elf_x86_64_hash_table(p) \
954 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
955 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
957 #define elf_x86_64_compute_jump_table_size(htab) \
958 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
960 /* Create an entry in an x86-64 ELF linker hash table. */
962 static struct bfd_hash_entry *
963 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
964 struct bfd_hash_table *table,
967 /* Allocate the structure if it has not already been allocated by a
971 entry = (struct bfd_hash_entry *)
972 bfd_hash_allocate (table,
973 sizeof (struct elf_x86_64_link_hash_entry));
978 /* Call the allocation method of the superclass. */
979 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
982 struct elf_x86_64_link_hash_entry *eh;
984 eh = (struct elf_x86_64_link_hash_entry *) entry;
985 eh->dyn_relocs = NULL;
986 eh->tls_type = GOT_UNKNOWN;
988 eh->has_bnd_reloc = 0;
989 eh->has_got_reloc = 0;
990 eh->has_non_got_reloc = 0;
991 eh->tls_get_addr = 2;
992 eh->func_pointer_refcount = 0;
993 eh->plt_bnd.offset = (bfd_vma) -1;
994 eh->plt_got.offset = (bfd_vma) -1;
995 eh->tlsdesc_got = (bfd_vma) -1;
1001 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1002 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1003 as global symbol. We reuse indx and dynstr_index for local symbol
1004 hash since they aren't used by global symbols in this backend. */
1007 elf_x86_64_local_htab_hash (const void *ptr)
1009 struct elf_link_hash_entry *h
1010 = (struct elf_link_hash_entry *) ptr;
1011 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
1014 /* Compare local hash entries. */
1017 elf_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
1019 struct elf_link_hash_entry *h1
1020 = (struct elf_link_hash_entry *) ptr1;
1021 struct elf_link_hash_entry *h2
1022 = (struct elf_link_hash_entry *) ptr2;
1024 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
1027 /* Find and/or create a hash entry for local symbol. */
1029 static struct elf_link_hash_entry *
1030 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table *htab,
1031 bfd *abfd, const Elf_Internal_Rela *rel,
1034 struct elf_x86_64_link_hash_entry e, *ret;
1035 asection *sec = abfd->sections;
1036 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
1037 htab->r_sym (rel->r_info));
1040 e.elf.indx = sec->id;
1041 e.elf.dynstr_index = htab->r_sym (rel->r_info);
1042 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
1043 create ? INSERT : NO_INSERT);
1050 ret = (struct elf_x86_64_link_hash_entry *) *slot;
1054 ret = (struct elf_x86_64_link_hash_entry *)
1055 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
1056 sizeof (struct elf_x86_64_link_hash_entry));
1059 memset (ret, 0, sizeof (*ret));
1060 ret->elf.indx = sec->id;
1061 ret->elf.dynstr_index = htab->r_sym (rel->r_info);
1062 ret->elf.dynindx = -1;
1063 ret->func_pointer_refcount = 0;
1064 ret->plt_got.offset = (bfd_vma) -1;
1070 /* Destroy an X86-64 ELF linker hash table. */
1073 elf_x86_64_link_hash_table_free (bfd *obfd)
1075 struct elf_x86_64_link_hash_table *htab
1076 = (struct elf_x86_64_link_hash_table *) obfd->link.hash;
1078 if (htab->loc_hash_table)
1079 htab_delete (htab->loc_hash_table);
1080 if (htab->loc_hash_memory)
1081 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
1082 _bfd_elf_link_hash_table_free (obfd);
1085 /* Create an X86-64 ELF linker hash table. */
1087 static struct bfd_link_hash_table *
1088 elf_x86_64_link_hash_table_create (bfd *abfd)
1090 struct elf_x86_64_link_hash_table *ret;
1091 bfd_size_type amt = sizeof (struct elf_x86_64_link_hash_table);
1093 ret = (struct elf_x86_64_link_hash_table *) bfd_zmalloc (amt);
1097 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1098 elf_x86_64_link_hash_newfunc,
1099 sizeof (struct elf_x86_64_link_hash_entry),
1106 if (ABI_64_P (abfd))
1108 ret->r_info = elf64_r_info;
1109 ret->r_sym = elf64_r_sym;
1110 ret->pointer_r_type = R_X86_64_64;
1111 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
1112 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
1116 ret->r_info = elf32_r_info;
1117 ret->r_sym = elf32_r_sym;
1118 ret->pointer_r_type = R_X86_64_32;
1119 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
1120 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
1123 ret->loc_hash_table = htab_try_create (1024,
1124 elf_x86_64_local_htab_hash,
1125 elf_x86_64_local_htab_eq,
1127 ret->loc_hash_memory = objalloc_create ();
1128 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1130 elf_x86_64_link_hash_table_free (abfd);
1133 ret->elf.root.hash_table_free = elf_x86_64_link_hash_table_free;
1135 return &ret->elf.root;
1138 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1139 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1143 elf_x86_64_create_dynamic_sections (bfd *dynobj,
1144 struct bfd_link_info *info)
1146 struct elf_x86_64_link_hash_table *htab;
1148 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1151 htab = elf_x86_64_hash_table (info);
1155 /* Set the contents of the .interp section to the interpreter. */
1156 if (bfd_link_executable (info) && !info->nointerp)
1158 asection *s = bfd_get_linker_section (dynobj, ".interp");
1161 s->size = htab->dynamic_interpreter_size;
1162 s->contents = (unsigned char *) htab->dynamic_interpreter;
1166 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
1170 if (bfd_link_executable (info))
1172 /* Always allow copy relocs for building executables. */
1173 asection *s = bfd_get_linker_section (dynobj, ".rela.bss");
1176 const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
1177 s = bfd_make_section_anyway_with_flags (dynobj,
1179 (bed->dynamic_sec_flags
1182 || ! bfd_set_section_alignment (dynobj, s,
1183 bed->s->log_file_align))
1189 if (!info->no_ld_generated_unwind_info
1190 && htab->plt_eh_frame == NULL
1191 && htab->elf.splt != NULL)
1193 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
1194 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1195 | SEC_LINKER_CREATED);
1197 = bfd_make_section_anyway_with_flags (dynobj, ".eh_frame", flags);
1198 if (htab->plt_eh_frame == NULL
1199 || !bfd_set_section_alignment (dynobj, htab->plt_eh_frame, 3))
1205 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1208 elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
1209 struct elf_link_hash_entry *dir,
1210 struct elf_link_hash_entry *ind)
1212 struct elf_x86_64_link_hash_entry *edir, *eind;
1214 edir = (struct elf_x86_64_link_hash_entry *) dir;
1215 eind = (struct elf_x86_64_link_hash_entry *) ind;
1217 if (!edir->has_bnd_reloc)
1218 edir->has_bnd_reloc = eind->has_bnd_reloc;
1220 if (!edir->has_got_reloc)
1221 edir->has_got_reloc = eind->has_got_reloc;
1223 if (!edir->has_non_got_reloc)
1224 edir->has_non_got_reloc = eind->has_non_got_reloc;
1226 if (eind->dyn_relocs != NULL)
1228 if (edir->dyn_relocs != NULL)
1230 struct elf_dyn_relocs **pp;
1231 struct elf_dyn_relocs *p;
1233 /* Add reloc counts against the indirect sym to the direct sym
1234 list. Merge any entries against the same section. */
1235 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1237 struct elf_dyn_relocs *q;
1239 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1240 if (q->sec == p->sec)
1242 q->pc_count += p->pc_count;
1243 q->count += p->count;
1250 *pp = edir->dyn_relocs;
1253 edir->dyn_relocs = eind->dyn_relocs;
1254 eind->dyn_relocs = NULL;
1257 if (ind->root.type == bfd_link_hash_indirect
1258 && dir->got.refcount <= 0)
1260 edir->tls_type = eind->tls_type;
1261 eind->tls_type = GOT_UNKNOWN;
1264 if (ELIMINATE_COPY_RELOCS
1265 && ind->root.type != bfd_link_hash_indirect
1266 && dir->dynamic_adjusted)
1268 /* If called to transfer flags for a weakdef during processing
1269 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1270 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1271 dir->ref_dynamic |= ind->ref_dynamic;
1272 dir->ref_regular |= ind->ref_regular;
1273 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1274 dir->needs_plt |= ind->needs_plt;
1275 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1279 if (eind->func_pointer_refcount > 0)
1281 edir->func_pointer_refcount += eind->func_pointer_refcount;
1282 eind->func_pointer_refcount = 0;
1285 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1290 elf64_x86_64_elf_object_p (bfd *abfd)
1292 /* Set the right machine number for an x86-64 elf64 file. */
1293 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
1298 elf32_x86_64_elf_object_p (bfd *abfd)
1300 /* Set the right machine number for an x86-64 elf32 file. */
1301 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
1305 /* Return TRUE if the TLS access code sequence support transition
1309 elf_x86_64_check_tls_transition (bfd *abfd,
1310 struct bfd_link_info *info,
1313 Elf_Internal_Shdr *symtab_hdr,
1314 struct elf_link_hash_entry **sym_hashes,
1315 unsigned int r_type,
1316 const Elf_Internal_Rela *rel,
1317 const Elf_Internal_Rela *relend)
1320 unsigned long r_symndx;
1321 bfd_boolean largepic = FALSE;
1322 struct elf_link_hash_entry *h;
1324 struct elf_x86_64_link_hash_table *htab;
1326 bfd_boolean indirect_call, tls_get_addr;
1328 htab = elf_x86_64_hash_table (info);
1329 offset = rel->r_offset;
1332 case R_X86_64_TLSGD:
1333 case R_X86_64_TLSLD:
1334 if ((rel + 1) >= relend)
1337 if (r_type == R_X86_64_TLSGD)
1339 /* Check transition from GD access model. For 64bit, only
1340 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1341 .word 0x6666; rex64; call __tls_get_addr@PLT
1343 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1345 call *__tls_get_addr@GOTPCREL(%rip)
1346 which may be converted to
1347 addr32 call __tls_get_addr
1348 can transit to different access model. For 32bit, only
1349 leaq foo@tlsgd(%rip), %rdi
1350 .word 0x6666; rex64; call __tls_get_addr@PLT
1352 leaq foo@tlsgd(%rip), %rdi
1354 call *__tls_get_addr@GOTPCREL(%rip)
1355 which may be converted to
1356 addr32 call __tls_get_addr
1357 can transit to different access model. For largepic,
1359 leaq foo@tlsgd(%rip), %rdi
1360 movabsq $__tls_get_addr@pltoff, %rax
1364 leaq foo@tlsgd(%rip), %rdi
1365 movabsq $__tls_get_addr@pltoff, %rax
1369 static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
1371 if ((offset + 12) > sec->size)
1374 call = contents + offset + 4;
1376 || !((call[1] == 0x48
1384 && call[3] == 0xe8)))
1386 if (!ABI_64_P (abfd)
1387 || (offset + 19) > sec->size
1389 || memcmp (call - 7, leaq + 1, 3) != 0
1390 || memcmp (call, "\x48\xb8", 2) != 0
1394 || !((call[10] == 0x48 && call[12] == 0xd8)
1395 || (call[10] == 0x4c && call[12] == 0xf8)))
1399 else if (ABI_64_P (abfd))
1402 || memcmp (contents + offset - 4, leaq, 4) != 0)
1408 || memcmp (contents + offset - 3, leaq + 1, 3) != 0)
1411 indirect_call = call[2] == 0xff;
1415 /* Check transition from LD access model. Only
1416 leaq foo@tlsld(%rip), %rdi;
1417 call __tls_get_addr@PLT
1419 leaq foo@tlsld(%rip), %rdi;
1420 call *__tls_get_addr@GOTPCREL(%rip)
1421 which may be converted to
1422 addr32 call __tls_get_addr
1423 can transit to different access model. For largepic
1425 leaq foo@tlsld(%rip), %rdi
1426 movabsq $__tls_get_addr@pltoff, %rax
1430 leaq foo@tlsld(%rip), %rdi
1431 movabsq $__tls_get_addr@pltoff, %rax
1435 static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
1437 if (offset < 3 || (offset + 9) > sec->size)
1440 if (memcmp (contents + offset - 3, lea, 3) != 0)
1443 call = contents + offset + 4;
1444 if (!(call[0] == 0xe8
1445 || (call[0] == 0xff && call[1] == 0x15)
1446 || (call[0] == 0x67 && call[1] == 0xe8)))
1448 if (!ABI_64_P (abfd)
1449 || (offset + 19) > sec->size
1450 || memcmp (call, "\x48\xb8", 2) != 0
1454 || !((call[10] == 0x48 && call[12] == 0xd8)
1455 || (call[10] == 0x4c && call[12] == 0xf8)))
1459 indirect_call = call[0] == 0xff;
1462 r_symndx = htab->r_sym (rel[1].r_info);
1463 if (r_symndx < symtab_hdr->sh_info)
1466 tls_get_addr = FALSE;
1467 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1468 if (h != NULL && h->root.root.string != NULL)
1470 struct elf_x86_64_link_hash_entry *eh
1471 = (struct elf_x86_64_link_hash_entry *) h;
1472 tls_get_addr = eh->tls_get_addr == 1;
1473 if (eh->tls_get_addr > 1)
1475 /* Use strncmp to check __tls_get_addr since
1476 __tls_get_addr may be versioned. */
1477 if (strncmp (h->root.root.string, "__tls_get_addr", 14)
1480 eh->tls_get_addr = 1;
1481 tls_get_addr = TRUE;
1484 eh->tls_get_addr = 0;
1491 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLTOFF64;
1492 else if (indirect_call)
1493 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_GOTPCRELX;
1495 return (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
1496 || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
1498 case R_X86_64_GOTTPOFF:
1499 /* Check transition from IE access model:
1500 mov foo@gottpoff(%rip), %reg
1501 add foo@gottpoff(%rip), %reg
1504 /* Check REX prefix first. */
1505 if (offset >= 3 && (offset + 4) <= sec->size)
1507 val = bfd_get_8 (abfd, contents + offset - 3);
1508 if (val != 0x48 && val != 0x4c)
1510 /* X32 may have 0x44 REX prefix or no REX prefix. */
1511 if (ABI_64_P (abfd))
1517 /* X32 may not have any REX prefix. */
1518 if (ABI_64_P (abfd))
1520 if (offset < 2 || (offset + 3) > sec->size)
1524 val = bfd_get_8 (abfd, contents + offset - 2);
1525 if (val != 0x8b && val != 0x03)
1528 val = bfd_get_8 (abfd, contents + offset - 1);
1529 return (val & 0xc7) == 5;
1531 case R_X86_64_GOTPC32_TLSDESC:
1532 /* Check transition from GDesc access model:
1533 leaq x@tlsdesc(%rip), %rax
1535 Make sure it's a leaq adding rip to a 32-bit offset
1536 into any register, although it's probably almost always
1539 if (offset < 3 || (offset + 4) > sec->size)
1542 val = bfd_get_8 (abfd, contents + offset - 3);
1543 if ((val & 0xfb) != 0x48)
1546 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1549 val = bfd_get_8 (abfd, contents + offset - 1);
1550 return (val & 0xc7) == 0x05;
1552 case R_X86_64_TLSDESC_CALL:
1553 /* Check transition from GDesc access model:
1554 call *x@tlsdesc(%rax)
1556 if (offset + 2 <= sec->size)
1558 /* Make sure that it's a call *x@tlsdesc(%rax). */
1559 call = contents + offset;
1560 return call[0] == 0xff && call[1] == 0x10;
1570 /* Return TRUE if the TLS access transition is OK or no transition
1571 will be performed. Update R_TYPE if there is a transition. */
1574 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1575 asection *sec, bfd_byte *contents,
1576 Elf_Internal_Shdr *symtab_hdr,
1577 struct elf_link_hash_entry **sym_hashes,
1578 unsigned int *r_type, int tls_type,
1579 const Elf_Internal_Rela *rel,
1580 const Elf_Internal_Rela *relend,
1581 struct elf_link_hash_entry *h,
1582 unsigned long r_symndx,
1583 bfd_boolean from_relocate_section)
1585 unsigned int from_type = *r_type;
1586 unsigned int to_type = from_type;
1587 bfd_boolean check = TRUE;
1589 /* Skip TLS transition for functions. */
1591 && (h->type == STT_FUNC
1592 || h->type == STT_GNU_IFUNC))
1597 case R_X86_64_TLSGD:
1598 case R_X86_64_GOTPC32_TLSDESC:
1599 case R_X86_64_TLSDESC_CALL:
1600 case R_X86_64_GOTTPOFF:
1601 if (bfd_link_executable (info))
1604 to_type = R_X86_64_TPOFF32;
1606 to_type = R_X86_64_GOTTPOFF;
1609 /* When we are called from elf_x86_64_relocate_section, there may
1610 be additional transitions based on TLS_TYPE. */
1611 if (from_relocate_section)
1613 unsigned int new_to_type = to_type;
1615 if (bfd_link_executable (info)
1618 && tls_type == GOT_TLS_IE)
1619 new_to_type = R_X86_64_TPOFF32;
1621 if (to_type == R_X86_64_TLSGD
1622 || to_type == R_X86_64_GOTPC32_TLSDESC
1623 || to_type == R_X86_64_TLSDESC_CALL)
1625 if (tls_type == GOT_TLS_IE)
1626 new_to_type = R_X86_64_GOTTPOFF;
1629 /* We checked the transition before when we were called from
1630 elf_x86_64_check_relocs. We only want to check the new
1631 transition which hasn't been checked before. */
1632 check = new_to_type != to_type && from_type == to_type;
1633 to_type = new_to_type;
1638 case R_X86_64_TLSLD:
1639 if (bfd_link_executable (info))
1640 to_type = R_X86_64_TPOFF32;
1647 /* Return TRUE if there is no transition. */
1648 if (from_type == to_type)
1651 /* Check if the transition can be performed. */
1653 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1654 symtab_hdr, sym_hashes,
1655 from_type, rel, relend))
1657 reloc_howto_type *from, *to;
1660 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1661 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1664 name = h->root.root.string;
1667 struct elf_x86_64_link_hash_table *htab;
1669 htab = elf_x86_64_hash_table (info);
1674 Elf_Internal_Sym *isym;
1676 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1678 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1682 (*_bfd_error_handler)
1683 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1684 "in section `%A' failed"),
1685 abfd, sec, from->name, to->name, name,
1686 (unsigned long) rel->r_offset);
1687 bfd_set_error (bfd_error_bad_value);
1695 /* Rename some of the generic section flags to better document how they
1697 #define need_convert_load sec_flg0
1698 #define check_relocs_failed sec_flg1
1701 elf_x86_64_need_pic (bfd *input_bfd, asection *sec,
1702 struct elf_link_hash_entry *h,
1703 Elf_Internal_Shdr *symtab_hdr,
1704 Elf_Internal_Sym *isym,
1705 reloc_howto_type *howto)
1708 const char *und = "";
1709 const char *pic = "";
1714 name = h->root.root.string;
1715 switch (ELF_ST_VISIBILITY (h->other))
1718 v = _("hidden symbol ");
1721 v = _("internal symbol ");
1724 v = _("protected symbol ");
1728 pic = _("; recompile with -fPIC");
1732 if (!h->def_regular && !h->def_dynamic)
1733 und = _("undefined ");
1737 name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
1738 pic = _("; recompile with -fPIC");
1741 (*_bfd_error_handler) (_("%B: relocation %s against %s%s`%s' can "
1742 "not be used when making a shared object%s"),
1743 input_bfd, howto->name, und, v, name, pic);
1744 bfd_set_error (bfd_error_bad_value);
1745 sec->check_relocs_failed = 1;
1749 /* With the local symbol, foo, we convert
1750 mov foo@GOTPCREL(%rip), %reg
1754 call/jmp *foo@GOTPCREL(%rip)
1756 nop call foo/jmp foo nop
1757 When PIC is false, convert
1758 test %reg, foo@GOTPCREL(%rip)
1762 binop foo@GOTPCREL(%rip), %reg
1765 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1769 elf_x86_64_convert_load_reloc (bfd *abfd, asection *sec,
1771 Elf_Internal_Rela *irel,
1772 struct elf_link_hash_entry *h,
1773 bfd_boolean *converted,
1774 struct bfd_link_info *link_info)
1776 struct elf_x86_64_link_hash_table *htab;
1778 bfd_boolean require_reloc_pc32;
1780 bfd_boolean to_reloc_pc32;
1783 bfd_signed_vma raddend;
1784 unsigned int opcode;
1786 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
1787 unsigned int r_symndx;
1789 bfd_vma roff = irel->r_offset;
1791 if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2))
1794 raddend = irel->r_addend;
1795 /* Addend for 32-bit PC-relative relocation must be -4. */
1799 htab = elf_x86_64_hash_table (link_info);
1800 is_pic = bfd_link_pic (link_info);
1802 relocx = (r_type == R_X86_64_GOTPCRELX
1803 || r_type == R_X86_64_REX_GOTPCRELX);
1805 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1808 = link_info->disable_target_specific_optimizations > 1;
1810 r_symndx = htab->r_sym (irel->r_info);
1812 opcode = bfd_get_8 (abfd, contents + roff - 2);
1814 /* Convert mov to lea since it has been done for a while. */
1817 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1818 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1819 test, xor instructions. */
1824 /* We convert only to R_X86_64_PC32:
1826 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1827 3. require_reloc_pc32 is true.
1830 to_reloc_pc32 = (opcode == 0xff
1832 || require_reloc_pc32
1835 /* Get the symbol referred to by the reloc. */
1838 Elf_Internal_Sym *isym
1839 = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
1841 /* Skip relocation against undefined symbols. */
1842 if (isym->st_shndx == SHN_UNDEF)
1845 symtype = ELF_ST_TYPE (isym->st_info);
1847 if (isym->st_shndx == SHN_ABS)
1848 tsec = bfd_abs_section_ptr;
1849 else if (isym->st_shndx == SHN_COMMON)
1850 tsec = bfd_com_section_ptr;
1851 else if (isym->st_shndx == SHN_X86_64_LCOMMON)
1852 tsec = &_bfd_elf_large_com_section;
1854 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1856 toff = isym->st_value;
1860 /* Undefined weak symbol is only bound locally in executable
1861 and its reference is resolved as 0 without relocation
1862 overflow. We can only perform this optimization for
1863 GOTPCRELX relocations since we need to modify REX byte.
1864 It is OK convert mov with R_X86_64_GOTPCREL to
1866 if ((relocx || opcode == 0x8b)
1867 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info,
1869 elf_x86_64_hash_entry (h)))
1873 /* Skip for branch instructions since R_X86_64_PC32
1875 if (require_reloc_pc32)
1880 /* For non-branch instructions, we can convert to
1881 R_X86_64_32/R_X86_64_32S since we know if there
1883 to_reloc_pc32 = FALSE;
1886 /* Since we don't know the current PC when PIC is true,
1887 we can't convert to R_X86_64_PC32. */
1888 if (to_reloc_pc32 && is_pic)
1893 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1894 ld.so may use its link-time address. */
1895 else if ((h->def_regular
1896 || h->root.type == bfd_link_hash_defined
1897 || h->root.type == bfd_link_hash_defweak)
1898 && h != htab->elf.hdynamic
1899 && SYMBOL_REFERENCES_LOCAL (link_info, h))
1901 /* bfd_link_hash_new or bfd_link_hash_undefined is
1902 set by an assignment in a linker script in
1903 bfd_elf_record_link_assignment. */
1905 && (h->root.type == bfd_link_hash_new
1906 || h->root.type == bfd_link_hash_undefined))
1908 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1909 if (require_reloc_pc32)
1913 tsec = h->root.u.def.section;
1914 toff = h->root.u.def.value;
1921 /* Don't convert GOTPCREL relocation against large section. */
1922 if (elf_section_data (tsec) != NULL
1923 && (elf_section_flags (tsec) & SHF_X86_64_LARGE) != 0)
1926 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1930 if (tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
1932 /* At this stage in linking, no SEC_MERGE symbol has been
1933 adjusted, so all references to such symbols need to be
1934 passed through _bfd_merged_section_offset. (Later, in
1935 relocate_section, all SEC_MERGE symbols *except* for
1936 section symbols have been adjusted.)
1938 gas may reduce relocations against symbols in SEC_MERGE
1939 sections to a relocation against the section symbol when
1940 the original addend was zero. When the reloc is against
1941 a section symbol we should include the addend in the
1942 offset passed to _bfd_merged_section_offset, since the
1943 location of interest is the original symbol. On the
1944 other hand, an access to "sym+addend" where "sym" is not
1945 a section symbol should not include the addend; Such an
1946 access is presumed to be an offset from "sym"; The
1947 location of interest is just "sym". */
1948 if (symtype == STT_SECTION)
1951 toff = _bfd_merged_section_offset (abfd, &tsec,
1952 elf_section_data (tsec)->sec_info,
1955 if (symtype != STT_SECTION)
1961 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1962 if (tsec->output_section == sec->output_section)
1964 if ((toff - roff + 0x80000000) > 0xffffffff)
1969 bfd_signed_vma distance;
1971 /* At this point, we don't know the load addresses of TSEC
1972 section nor SEC section. We estimate the distrance between
1973 SEC and TSEC. We store the estimated distances in the
1974 compressed_size field of the output section, which is only
1975 used to decompress the compressed input section. */
1976 if (sec->output_section->compressed_size == 0)
1979 bfd_size_type size = 0;
1980 for (asect = link_info->output_bfd->sections;
1982 asect = asect->next)
1983 /* Skip debug sections since compressed_size is used to
1984 compress debug sections. */
1985 if ((asect->flags & SEC_DEBUGGING) == 0)
1988 for (i = asect->map_head.s;
1992 size = align_power (size, i->alignment_power);
1995 asect->compressed_size = size;
1999 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2001 distance = (tsec->output_section->compressed_size
2002 - sec->output_section->compressed_size);
2006 /* Take PT_GNU_RELRO segment into account by adding
2008 if ((toff + distance + get_elf_backend_data (abfd)->maxpagesize
2009 - roff + 0x80000000) > 0xffffffff)
2016 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2021 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2023 modrm = bfd_get_8 (abfd, contents + roff - 1);
2026 /* Convert to "jmp foo nop". */
2029 nop_offset = irel->r_offset + 3;
2030 disp = bfd_get_32 (abfd, contents + irel->r_offset);
2031 irel->r_offset -= 1;
2032 bfd_put_32 (abfd, disp, contents + irel->r_offset);
2036 struct elf_x86_64_link_hash_entry *eh
2037 = (struct elf_x86_64_link_hash_entry *) h;
2039 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2042 /* To support TLS optimization, always use addr32 prefix for
2043 "call *__tls_get_addr@GOTPCREL(%rip)". */
2044 if (eh && eh->tls_get_addr == 1)
2047 nop_offset = irel->r_offset - 2;
2051 nop = link_info->call_nop_byte;
2052 if (link_info->call_nop_as_suffix)
2054 nop_offset = irel->r_offset + 3;
2055 disp = bfd_get_32 (abfd, contents + irel->r_offset);
2056 irel->r_offset -= 1;
2057 bfd_put_32 (abfd, disp, contents + irel->r_offset);
2060 nop_offset = irel->r_offset - 2;
2063 bfd_put_8 (abfd, nop, contents + nop_offset);
2064 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
2065 r_type = R_X86_64_PC32;
2070 unsigned int rex_mask = REX_R;
2072 if (r_type == R_X86_64_REX_GOTPCRELX)
2073 rex = bfd_get_8 (abfd, contents + roff - 3);
2081 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2082 "lea foo(%rip), %reg". */
2084 r_type = R_X86_64_PC32;
2088 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2089 "mov $foo, %reg". */
2091 modrm = bfd_get_8 (abfd, contents + roff - 1);
2092 modrm = 0xc0 | (modrm & 0x38) >> 3;
2093 if ((rex & REX_W) != 0
2094 && ABI_64_P (link_info->output_bfd))
2096 /* Keep the REX_W bit in REX byte for LP64. */
2097 r_type = R_X86_64_32S;
2098 goto rewrite_modrm_rex;
2102 /* If the REX_W bit in REX byte isn't needed,
2103 use R_X86_64_32 and clear the W bit to avoid
2104 sign-extend imm32 to imm64. */
2105 r_type = R_X86_64_32;
2106 /* Clear the W bit in REX byte. */
2108 goto rewrite_modrm_rex;
2114 /* R_X86_64_PC32 isn't supported. */
2118 modrm = bfd_get_8 (abfd, contents + roff - 1);
2121 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2122 "test $foo, %reg". */
2123 modrm = 0xc0 | (modrm & 0x38) >> 3;
2128 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2129 "binop $foo, %reg". */
2130 modrm = 0xc0 | (modrm & 0x38) >> 3 | (opcode & 0x3c);
2134 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2135 overflow when sign-extending imm32 to imm64. */
2136 r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32;
2139 bfd_put_8 (abfd, modrm, contents + roff - 1);
2143 /* Move the R bit to the B bit in REX byte. */
2144 rex = (rex & ~rex_mask) | (rex & REX_R) >> 2;
2145 bfd_put_8 (abfd, rex, contents + roff - 3);
2148 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2152 bfd_put_8 (abfd, opcode, contents + roff - 2);
2155 irel->r_info = htab->r_info (r_symndx, r_type);
2162 /* Look through the relocs for a section during the first phase, and
2163 calculate needed space in the global offset table, procedure
2164 linkage table, and dynamic reloc sections. */
2167 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2169 const Elf_Internal_Rela *relocs)
2171 struct elf_x86_64_link_hash_table *htab;
2172 Elf_Internal_Shdr *symtab_hdr;
2173 struct elf_link_hash_entry **sym_hashes;
2174 const Elf_Internal_Rela *rel;
2175 const Elf_Internal_Rela *rel_end;
2178 bfd_boolean use_plt_got;
2180 if (bfd_link_relocatable (info))
2183 /* Don't do anything special with non-loaded, non-alloced sections.
2184 In particular, any relocs in such sections should not affect GOT
2185 and PLT reference counting (ie. we don't allow them to create GOT
2186 or PLT entries), there's no possibility or desire to optimize TLS
2187 relocs, and there's not much point in propagating relocs to shared
2188 libs that the dynamic linker won't relocate. */
2189 if ((sec->flags & SEC_ALLOC) == 0)
2192 BFD_ASSERT (is_x86_64_elf (abfd));
2194 htab = elf_x86_64_hash_table (info);
2197 sec->check_relocs_failed = 1;
2201 /* Get the section contents. */
2202 if (elf_section_data (sec)->this_hdr.contents != NULL)
2203 contents = elf_section_data (sec)->this_hdr.contents;
2204 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2206 sec->check_relocs_failed = 1;
2210 use_plt_got = get_elf_x86_64_backend_data (abfd) == &elf_x86_64_arch_bed;
2212 symtab_hdr = &elf_symtab_hdr (abfd);
2213 sym_hashes = elf_sym_hashes (abfd);
2217 rel_end = relocs + sec->reloc_count;
2218 for (rel = relocs; rel < rel_end; rel++)
2220 unsigned int r_type;
2221 unsigned long r_symndx;
2222 struct elf_link_hash_entry *h;
2223 struct elf_x86_64_link_hash_entry *eh;
2224 Elf_Internal_Sym *isym;
2226 bfd_boolean size_reloc;
2228 r_symndx = htab->r_sym (rel->r_info);
2229 r_type = ELF32_R_TYPE (rel->r_info);
2231 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
2233 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
2238 if (r_symndx < symtab_hdr->sh_info)
2240 /* A local symbol. */
2241 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2246 /* Check relocation against local STT_GNU_IFUNC symbol. */
2247 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
2249 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel,
2254 /* Fake a STT_GNU_IFUNC symbol. */
2255 h->type = STT_GNU_IFUNC;
2258 h->forced_local = 1;
2259 h->root.type = bfd_link_hash_defined;
2267 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2268 while (h->root.type == bfd_link_hash_indirect
2269 || h->root.type == bfd_link_hash_warning)
2270 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2273 /* Check invalid x32 relocations. */
2274 if (!ABI_64_P (abfd))
2280 case R_X86_64_DTPOFF64:
2281 case R_X86_64_TPOFF64:
2283 case R_X86_64_GOTOFF64:
2284 case R_X86_64_GOT64:
2285 case R_X86_64_GOTPCREL64:
2286 case R_X86_64_GOTPC64:
2287 case R_X86_64_GOTPLT64:
2288 case R_X86_64_PLTOFF64:
2291 name = h->root.root.string;
2293 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
2295 (*_bfd_error_handler)
2296 (_("%B: relocation %s against symbol `%s' isn't "
2297 "supported in x32 mode"), abfd,
2298 x86_64_elf_howto_table[r_type].name, name);
2299 bfd_set_error (bfd_error_bad_value);
2312 case R_X86_64_PC32_BND:
2313 case R_X86_64_PLT32_BND:
2315 case R_X86_64_PLT32:
2318 /* MPX PLT is supported only if elf_x86_64_arch_bed
2319 is used in 64-bit mode. */
2322 && (get_elf_x86_64_backend_data (abfd)
2323 == &elf_x86_64_arch_bed))
2325 elf_x86_64_hash_entry (h)->has_bnd_reloc = 1;
2327 /* Create the second PLT for Intel MPX support. */
2328 if (htab->plt_bnd == NULL)
2330 unsigned int plt_bnd_align;
2331 const struct elf_backend_data *bed;
2333 bed = get_elf_backend_data (info->output_bfd);
2334 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry) == 8
2335 && (sizeof (elf_x86_64_bnd_plt2_entry)
2336 == sizeof (elf_x86_64_legacy_plt2_entry)));
2339 if (htab->elf.dynobj == NULL)
2340 htab->elf.dynobj = abfd;
2342 = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2344 (bed->dynamic_sec_flags
2349 if (htab->plt_bnd == NULL
2350 || !bfd_set_section_alignment (htab->elf.dynobj,
2359 case R_X86_64_GOTPCREL:
2360 case R_X86_64_GOTPCRELX:
2361 case R_X86_64_REX_GOTPCRELX:
2362 case R_X86_64_GOTPCREL64:
2363 if (htab->elf.dynobj == NULL)
2364 htab->elf.dynobj = abfd;
2365 /* Create the ifunc sections for static executables. */
2366 if (h->type == STT_GNU_IFUNC
2367 && !_bfd_elf_create_ifunc_sections (htab->elf.dynobj,
2373 /* It is referenced by a non-shared object. */
2375 h->root.non_ir_ref = 1;
2377 if (h->type == STT_GNU_IFUNC)
2378 elf_tdata (info->output_bfd)->has_gnu_symbols
2379 |= elf_gnu_symbol_ifunc;
2382 if (! elf_x86_64_tls_transition (info, abfd, sec, contents,
2383 symtab_hdr, sym_hashes,
2384 &r_type, GOT_UNKNOWN,
2385 rel, rel_end, h, r_symndx, FALSE))
2388 eh = (struct elf_x86_64_link_hash_entry *) h;
2391 case R_X86_64_TLSLD:
2392 htab->tls_ld_got.refcount += 1;
2395 case R_X86_64_TPOFF32:
2396 if (!bfd_link_executable (info) && ABI_64_P (abfd))
2397 return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
2398 &x86_64_elf_howto_table[r_type]);
2400 eh->has_got_reloc = 1;
2403 case R_X86_64_GOTTPOFF:
2404 if (!bfd_link_executable (info))
2405 info->flags |= DF_STATIC_TLS;
2408 case R_X86_64_GOT32:
2409 case R_X86_64_GOTPCREL:
2410 case R_X86_64_GOTPCRELX:
2411 case R_X86_64_REX_GOTPCRELX:
2412 case R_X86_64_TLSGD:
2413 case R_X86_64_GOT64:
2414 case R_X86_64_GOTPCREL64:
2415 case R_X86_64_GOTPLT64:
2416 case R_X86_64_GOTPC32_TLSDESC:
2417 case R_X86_64_TLSDESC_CALL:
2418 /* This symbol requires a global offset table entry. */
2420 int tls_type, old_tls_type;
2424 default: tls_type = GOT_NORMAL; break;
2425 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
2426 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
2427 case R_X86_64_GOTPC32_TLSDESC:
2428 case R_X86_64_TLSDESC_CALL:
2429 tls_type = GOT_TLS_GDESC; break;
2434 h->got.refcount += 1;
2435 old_tls_type = eh->tls_type;
2439 bfd_signed_vma *local_got_refcounts;
2441 /* This is a global offset table entry for a local symbol. */
2442 local_got_refcounts = elf_local_got_refcounts (abfd);
2443 if (local_got_refcounts == NULL)
2447 size = symtab_hdr->sh_info;
2448 size *= sizeof (bfd_signed_vma)
2449 + sizeof (bfd_vma) + sizeof (char);
2450 local_got_refcounts = ((bfd_signed_vma *)
2451 bfd_zalloc (abfd, size));
2452 if (local_got_refcounts == NULL)
2454 elf_local_got_refcounts (abfd) = local_got_refcounts;
2455 elf_x86_64_local_tlsdesc_gotent (abfd)
2456 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
2457 elf_x86_64_local_got_tls_type (abfd)
2458 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
2460 local_got_refcounts[r_symndx] += 1;
2462 = elf_x86_64_local_got_tls_type (abfd) [r_symndx];
2465 /* If a TLS symbol is accessed using IE at least once,
2466 there is no point to use dynamic model for it. */
2467 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
2468 && (! GOT_TLS_GD_ANY_P (old_tls_type)
2469 || tls_type != GOT_TLS_IE))
2471 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
2472 tls_type = old_tls_type;
2473 else if (GOT_TLS_GD_ANY_P (old_tls_type)
2474 && GOT_TLS_GD_ANY_P (tls_type))
2475 tls_type |= old_tls_type;
2479 name = h->root.root.string;
2481 name = bfd_elf_sym_name (abfd, symtab_hdr,
2483 (*_bfd_error_handler)
2484 (_("%B: '%s' accessed both as normal and thread local symbol"),
2486 bfd_set_error (bfd_error_bad_value);
2491 if (old_tls_type != tls_type)
2494 eh->tls_type = tls_type;
2496 elf_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
2501 case R_X86_64_GOTOFF64:
2502 case R_X86_64_GOTPC32:
2503 case R_X86_64_GOTPC64:
2506 eh->has_got_reloc = 1;
2507 if (htab->elf.sgot == NULL)
2509 if (htab->elf.dynobj == NULL)
2510 htab->elf.dynobj = abfd;
2511 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
2517 case R_X86_64_PLT32:
2518 case R_X86_64_PLT32_BND:
2519 /* This symbol requires a procedure linkage table entry. We
2520 actually build the entry in adjust_dynamic_symbol,
2521 because this might be a case of linking PIC code which is
2522 never referenced by a dynamic object, in which case we
2523 don't need to generate a procedure linkage table entry
2526 /* If this is a local symbol, we resolve it directly without
2527 creating a procedure linkage table entry. */
2531 eh->has_got_reloc = 1;
2533 h->plt.refcount += 1;
2536 case R_X86_64_PLTOFF64:
2537 /* This tries to form the 'address' of a function relative
2538 to GOT. For global symbols we need a PLT entry. */
2542 h->plt.refcount += 1;
2546 case R_X86_64_SIZE32:
2547 case R_X86_64_SIZE64:
2552 if (!ABI_64_P (abfd))
2557 /* Check relocation overflow as these relocs may lead to
2558 run-time relocation overflow. Don't error out for
2559 sections we don't care about, such as debug sections or
2560 when relocation overflow check is disabled. */
2561 if (!info->no_reloc_overflow_check
2562 && (bfd_link_pic (info)
2563 || (bfd_link_executable (info)
2567 && (sec->flags & SEC_READONLY) == 0)))
2568 return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
2569 &x86_64_elf_howto_table[r_type]);
2575 case R_X86_64_PC32_BND:
2579 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
2580 eh->has_non_got_reloc = 1;
2581 /* We are called after all symbols have been resolved. Only
2582 relocation against STT_GNU_IFUNC symbol must go through
2585 && (bfd_link_executable (info)
2586 || h->type == STT_GNU_IFUNC))
2588 /* If this reloc is in a read-only section, we might
2589 need a copy reloc. We can't check reliably at this
2590 stage whether the section is read-only, as input
2591 sections have not yet been mapped to output sections.
2592 Tentatively set the flag for now, and correct in
2593 adjust_dynamic_symbol. */
2596 /* We may need a .plt entry if the symbol is a function
2597 defined in a shared lib or is a STT_GNU_IFUNC function
2598 referenced from the code or read-only section. */
2600 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
2601 h->plt.refcount += 1;
2603 if (r_type == R_X86_64_PC32)
2605 /* Since something like ".long foo - ." may be used
2606 as pointer, make sure that PLT is used if foo is
2607 a function defined in a shared library. */
2608 if ((sec->flags & SEC_CODE) == 0)
2609 h->pointer_equality_needed = 1;
2611 else if (r_type != R_X86_64_PC32_BND
2612 && r_type != R_X86_64_PC64)
2614 h->pointer_equality_needed = 1;
2615 /* At run-time, R_X86_64_64 can be resolved for both
2616 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2617 can only be resolved for x32. */
2618 if ((sec->flags & SEC_READONLY) == 0
2619 && (r_type == R_X86_64_64
2620 || (!ABI_64_P (abfd)
2621 && (r_type == R_X86_64_32
2622 || r_type == R_X86_64_32S))))
2623 eh->func_pointer_refcount += 1;
2629 /* If we are creating a shared library, and this is a reloc
2630 against a global symbol, or a non PC relative reloc
2631 against a local symbol, then we need to copy the reloc
2632 into the shared library. However, if we are linking with
2633 -Bsymbolic, we do not need to copy a reloc against a
2634 global symbol which is defined in an object we are
2635 including in the link (i.e., DEF_REGULAR is set). At
2636 this point we have not seen all the input files, so it is
2637 possible that DEF_REGULAR is not set now but will be set
2638 later (it is never cleared). In case of a weak definition,
2639 DEF_REGULAR may be cleared later by a strong definition in
2640 a shared library. We account for that possibility below by
2641 storing information in the relocs_copied field of the hash
2642 table entry. A similar situation occurs when creating
2643 shared libraries and symbol visibility changes render the
2646 If on the other hand, we are creating an executable, we
2647 may need to keep relocations for symbols satisfied by a
2648 dynamic library if we manage to avoid copy relocs for the
2651 Generate dynamic pointer relocation against STT_GNU_IFUNC
2652 symbol in the non-code section. */
2653 if ((bfd_link_pic (info)
2654 && (! IS_X86_64_PCREL_TYPE (r_type)
2656 && (! (bfd_link_pie (info)
2657 || SYMBOLIC_BIND (info, h))
2658 || h->root.type == bfd_link_hash_defweak
2659 || !h->def_regular))))
2661 && h->type == STT_GNU_IFUNC
2662 && r_type == htab->pointer_r_type
2663 && (sec->flags & SEC_CODE) == 0)
2664 || (ELIMINATE_COPY_RELOCS
2665 && !bfd_link_pic (info)
2667 && (h->root.type == bfd_link_hash_defweak
2668 || !h->def_regular)))
2670 struct elf_dyn_relocs *p;
2671 struct elf_dyn_relocs **head;
2673 /* We must copy these reloc types into the output file.
2674 Create a reloc section in dynobj and make room for
2678 if (htab->elf.dynobj == NULL)
2679 htab->elf.dynobj = abfd;
2681 sreloc = _bfd_elf_make_dynamic_reloc_section
2682 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
2683 abfd, /*rela?*/ TRUE);
2689 /* If this is a global symbol, we count the number of
2690 relocations we need for this symbol. */
2692 head = &eh->dyn_relocs;
2695 /* Track dynamic relocs needed for local syms too.
2696 We really need local syms available to do this
2701 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2706 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2710 /* Beware of type punned pointers vs strict aliasing
2712 vpp = &(elf_section_data (s)->local_dynrel);
2713 head = (struct elf_dyn_relocs **)vpp;
2717 if (p == NULL || p->sec != sec)
2719 bfd_size_type amt = sizeof *p;
2721 p = ((struct elf_dyn_relocs *)
2722 bfd_alloc (htab->elf.dynobj, amt));
2733 /* Count size relocation as PC-relative relocation. */
2734 if (IS_X86_64_PCREL_TYPE (r_type) || size_reloc)
2739 /* This relocation describes the C++ object vtable hierarchy.
2740 Reconstruct it for later use during GC. */
2741 case R_X86_64_GNU_VTINHERIT:
2742 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2746 /* This relocation describes which C++ vtable entries are actually
2747 used. Record for later use during GC. */
2748 case R_X86_64_GNU_VTENTRY:
2749 BFD_ASSERT (h != NULL);
2751 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2761 && h->plt.refcount > 0
2762 && (((info->flags & DF_BIND_NOW) && !h->pointer_equality_needed)
2763 || h->got.refcount > 0)
2764 && htab->plt_got == NULL)
2766 /* Create the GOT procedure linkage table. */
2767 unsigned int plt_got_align;
2768 const struct elf_backend_data *bed;
2770 bed = get_elf_backend_data (info->output_bfd);
2771 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry) == 8
2772 && (sizeof (elf_x86_64_bnd_plt2_entry)
2773 == sizeof (elf_x86_64_legacy_plt2_entry)));
2776 if (htab->elf.dynobj == NULL)
2777 htab->elf.dynobj = abfd;
2779 = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2781 (bed->dynamic_sec_flags
2786 if (htab->plt_got == NULL
2787 || !bfd_set_section_alignment (htab->elf.dynobj,
2792 if (!info->no_ld_generated_unwind_info
2793 && htab->plt_got_eh_frame == NULL
2794 && get_elf_x86_64_backend_data (abfd)->eh_frame_plt_got != NULL)
2796 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2797 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2798 | SEC_LINKER_CREATED);
2799 htab->plt_got_eh_frame
2800 = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2803 if (htab->plt_got_eh_frame == NULL
2804 || !bfd_set_section_alignment (htab->elf.dynobj,
2805 htab->plt_got_eh_frame,
2811 if ((r_type == R_X86_64_GOTPCREL
2812 || r_type == R_X86_64_GOTPCRELX
2813 || r_type == R_X86_64_REX_GOTPCRELX)
2814 && (h == NULL || h->type != STT_GNU_IFUNC))
2815 sec->need_convert_load = 1;
2818 if (elf_section_data (sec)->this_hdr.contents != contents)
2820 if (!info->keep_memory)
2824 /* Cache the section contents for elf_link_input_bfd. */
2825 elf_section_data (sec)->this_hdr.contents = contents;
2832 if (elf_section_data (sec)->this_hdr.contents != contents)
2834 sec->check_relocs_failed = 1;
2838 /* Return the section that should be marked against GC for a given
2842 elf_x86_64_gc_mark_hook (asection *sec,
2843 struct bfd_link_info *info,
2844 Elf_Internal_Rela *rel,
2845 struct elf_link_hash_entry *h,
2846 Elf_Internal_Sym *sym)
2849 switch (ELF32_R_TYPE (rel->r_info))
2851 case R_X86_64_GNU_VTINHERIT:
2852 case R_X86_64_GNU_VTENTRY:
2856 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2859 /* Remove undefined weak symbol from the dynamic symbol table if it
2860 is resolved to 0. */
2863 elf_x86_64_fixup_symbol (struct bfd_link_info *info,
2864 struct elf_link_hash_entry *h)
2866 if (h->dynindx != -1
2867 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2868 elf_x86_64_hash_entry (h)->has_got_reloc,
2869 elf_x86_64_hash_entry (h)))
2872 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
2878 /* Adjust a symbol defined by a dynamic object and referenced by a
2879 regular object. The current definition is in some section of the
2880 dynamic object, but we're not including those sections. We have to
2881 change the definition to something the rest of the link can
2885 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
2886 struct elf_link_hash_entry *h)
2888 struct elf_x86_64_link_hash_table *htab;
2890 struct elf_x86_64_link_hash_entry *eh;
2891 struct elf_dyn_relocs *p;
2893 /* STT_GNU_IFUNC symbol must go through PLT. */
2894 if (h->type == STT_GNU_IFUNC)
2896 /* All local STT_GNU_IFUNC references must be treate as local
2897 calls via local PLT. */
2899 && SYMBOL_CALLS_LOCAL (info, h))
2901 bfd_size_type pc_count = 0, count = 0;
2902 struct elf_dyn_relocs **pp;
2904 eh = (struct elf_x86_64_link_hash_entry *) h;
2905 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2907 pc_count += p->pc_count;
2908 p->count -= p->pc_count;
2917 if (pc_count || count)
2922 /* Increment PLT reference count only for PC-relative
2925 if (h->plt.refcount <= 0)
2926 h->plt.refcount = 1;
2928 h->plt.refcount += 1;
2933 if (h->plt.refcount <= 0)
2935 h->plt.offset = (bfd_vma) -1;
2941 /* If this is a function, put it in the procedure linkage table. We
2942 will fill in the contents of the procedure linkage table later,
2943 when we know the address of the .got section. */
2944 if (h->type == STT_FUNC
2947 if (h->plt.refcount <= 0
2948 || SYMBOL_CALLS_LOCAL (info, h)
2949 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2950 && h->root.type == bfd_link_hash_undefweak))
2952 /* This case can occur if we saw a PLT32 reloc in an input
2953 file, but the symbol was never referred to by a dynamic
2954 object, or if all references were garbage collected. In
2955 such a case, we don't actually need to build a procedure
2956 linkage table, and we can just do a PC32 reloc instead. */
2957 h->plt.offset = (bfd_vma) -1;
2964 /* It's possible that we incorrectly decided a .plt reloc was
2965 needed for an R_X86_64_PC32 reloc to a non-function sym in
2966 check_relocs. We can't decide accurately between function and
2967 non-function syms in check-relocs; Objects loaded later in
2968 the link may change h->type. So fix it now. */
2969 h->plt.offset = (bfd_vma) -1;
2971 /* If this is a weak symbol, and there is a real definition, the
2972 processor independent code will have arranged for us to see the
2973 real definition first, and we can just use the same value. */
2974 if (h->u.weakdef != NULL)
2976 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2977 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2978 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2979 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2980 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
2982 eh = (struct elf_x86_64_link_hash_entry *) h;
2983 h->non_got_ref = h->u.weakdef->non_got_ref;
2984 eh->needs_copy = h->u.weakdef->needs_copy;
2989 /* This is a reference to a symbol defined by a dynamic object which
2990 is not a function. */
2992 /* If we are creating a shared library, we must presume that the
2993 only references to the symbol are via the global offset table.
2994 For such cases we need not do anything here; the relocations will
2995 be handled correctly by relocate_section. */
2996 if (!bfd_link_executable (info))
2999 /* If there are no references to this symbol that do not use the
3000 GOT, we don't need to generate a copy reloc. */
3001 if (!h->non_got_ref)
3004 /* If -z nocopyreloc was given, we won't generate them either. */
3005 if (info->nocopyreloc)
3011 if (ELIMINATE_COPY_RELOCS)
3013 eh = (struct elf_x86_64_link_hash_entry *) h;
3014 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3016 s = p->sec->output_section;
3017 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3021 /* If we didn't find any dynamic relocs in read-only sections, then
3022 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3030 /* We must allocate the symbol in our .dynbss section, which will
3031 become part of the .bss section of the executable. There will be
3032 an entry for this symbol in the .dynsym section. The dynamic
3033 object will contain position independent code, so all references
3034 from the dynamic object to this symbol will go through the global
3035 offset table. The dynamic linker will use the .dynsym entry to
3036 determine the address it must put in the global offset table, so
3037 both the dynamic object and the regular object will refer to the
3038 same memory location for the variable. */
3040 htab = elf_x86_64_hash_table (info);
3044 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3045 to copy the initial value out of the dynamic object and into the
3046 runtime process image. */
3047 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3049 const struct elf_backend_data *bed;
3050 bed = get_elf_backend_data (info->output_bfd);
3051 htab->srelbss->size += bed->s->sizeof_rela;
3057 return _bfd_elf_adjust_dynamic_copy (info, h, s);
3060 /* Allocate space in .plt, .got and associated reloc sections for
3064 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
3066 struct bfd_link_info *info;
3067 struct elf_x86_64_link_hash_table *htab;
3068 struct elf_x86_64_link_hash_entry *eh;
3069 struct elf_dyn_relocs *p;
3070 const struct elf_backend_data *bed;
3071 unsigned int plt_entry_size;
3072 bfd_boolean resolved_to_zero;
3074 if (h->root.type == bfd_link_hash_indirect)
3077 eh = (struct elf_x86_64_link_hash_entry *) h;
3079 info = (struct bfd_link_info *) inf;
3080 htab = elf_x86_64_hash_table (info);
3083 bed = get_elf_backend_data (info->output_bfd);
3084 plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
3086 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
3090 /* We can't use the GOT PLT if pointer equality is needed since
3091 finish_dynamic_symbol won't clear symbol value and the dynamic
3092 linker won't update the GOT slot. We will get into an infinite
3093 loop at run-time. */
3094 if (htab->plt_got != NULL
3095 && h->type != STT_GNU_IFUNC
3096 && !h->pointer_equality_needed
3097 && h->plt.refcount > 0
3098 && h->got.refcount > 0)
3100 /* Don't use the regular PLT if there are both GOT and GOTPLT
3102 h->plt.offset = (bfd_vma) -1;
3104 /* Use the GOT PLT. */
3105 eh->plt_got.refcount = 1;
3108 /* Clear the reference count of function pointer relocations if
3109 symbol isn't a normal function. */
3110 if (h->type != STT_FUNC)
3111 eh->func_pointer_refcount = 0;
3113 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3114 here if it is defined and referenced in a non-shared object. */
3115 if (h->type == STT_GNU_IFUNC
3118 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h,
3120 &htab->readonly_dynrelocs_against_ifunc,
3123 GOT_ENTRY_SIZE, TRUE))
3125 asection *s = htab->plt_bnd;
3126 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
3128 /* Use the .plt.bnd section if it is created. */
3129 eh->plt_bnd.offset = s->size;
3131 /* Make room for this entry in the .plt.bnd section. */
3132 s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3140 /* Don't create the PLT entry if there are only function pointer
3141 relocations which can be resolved at run-time. */
3142 else if (htab->elf.dynamic_sections_created
3143 && (h->plt.refcount > eh->func_pointer_refcount
3144 || eh->plt_got.refcount > 0))
3146 bfd_boolean use_plt_got;
3148 /* Clear the reference count of function pointer relocations
3150 eh->func_pointer_refcount = 0;
3152 if ((info->flags & DF_BIND_NOW) && !h->pointer_equality_needed)
3154 /* Don't use the regular PLT for DF_BIND_NOW. */
3155 h->plt.offset = (bfd_vma) -1;
3157 /* Use the GOT PLT. */
3158 h->got.refcount = 1;
3159 eh->plt_got.refcount = 1;
3162 use_plt_got = eh->plt_got.refcount > 0;
3164 /* Make sure this symbol is output as a dynamic symbol.
3165 Undefined weak syms won't yet be marked as dynamic. */
3166 if (h->dynindx == -1
3168 && !resolved_to_zero)
3170 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3174 if (bfd_link_pic (info)
3175 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3177 asection *s = htab->elf.splt;
3178 asection *bnd_s = htab->plt_bnd;
3179 asection *got_s = htab->plt_got;
3181 /* If this is the first .plt entry, make room for the special
3182 first entry. The .plt section is used by prelink to undo
3183 prelinking for dynamic relocations. */
3185 s->size = plt_entry_size;
3188 eh->plt_got.offset = got_s->size;
3191 h->plt.offset = s->size;
3193 eh->plt_bnd.offset = bnd_s->size;
3196 /* If this symbol is not defined in a regular file, and we are
3197 not generating a shared library, then set the symbol to this
3198 location in the .plt. This is required to make function
3199 pointers compare as equal between the normal executable and
3200 the shared library. */
3201 if (! bfd_link_pic (info)
3206 /* We need to make a call to the entry of the GOT PLT
3207 instead of regular PLT entry. */
3208 h->root.u.def.section = got_s;
3209 h->root.u.def.value = eh->plt_got.offset;
3215 /* We need to make a call to the entry of the second
3216 PLT instead of regular PLT entry. */
3217 h->root.u.def.section = bnd_s;
3218 h->root.u.def.value = eh->plt_bnd.offset;
3222 h->root.u.def.section = s;
3223 h->root.u.def.value = h->plt.offset;
3228 /* Make room for this entry. */
3230 got_s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3233 s->size += plt_entry_size;
3235 bnd_s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3237 /* We also need to make an entry in the .got.plt section,
3238 which will be placed in the .got section by the linker
3240 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
3242 /* There should be no PLT relocation against resolved
3243 undefined weak symbol in executable. */
3244 if (!resolved_to_zero)
3246 /* We also need to make an entry in the .rela.plt
3248 htab->elf.srelplt->size += bed->s->sizeof_rela;
3249 htab->elf.srelplt->reloc_count++;
3255 eh->plt_got.offset = (bfd_vma) -1;
3256 h->plt.offset = (bfd_vma) -1;
3262 eh->plt_got.offset = (bfd_vma) -1;
3263 h->plt.offset = (bfd_vma) -1;
3267 eh->tlsdesc_got = (bfd_vma) -1;
3269 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3270 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3271 if (h->got.refcount > 0
3272 && bfd_link_executable (info)
3274 && elf_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
3276 h->got.offset = (bfd_vma) -1;
3278 else if (h->got.refcount > 0)
3282 int tls_type = elf_x86_64_hash_entry (h)->tls_type;
3284 /* Make sure this symbol is output as a dynamic symbol.
3285 Undefined weak syms won't yet be marked as dynamic. */
3286 if (h->dynindx == -1
3288 && !resolved_to_zero)
3290 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3294 if (GOT_TLS_GDESC_P (tls_type))
3296 eh->tlsdesc_got = htab->elf.sgotplt->size
3297 - elf_x86_64_compute_jump_table_size (htab);
3298 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
3299 h->got.offset = (bfd_vma) -2;
3301 if (! GOT_TLS_GDESC_P (tls_type)
3302 || GOT_TLS_GD_P (tls_type))
3305 h->got.offset = s->size;
3306 s->size += GOT_ENTRY_SIZE;
3307 if (GOT_TLS_GD_P (tls_type))
3308 s->size += GOT_ENTRY_SIZE;
3310 dyn = htab->elf.dynamic_sections_created;
3311 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3312 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3313 relocation. No dynamic relocation against resolved undefined
3314 weak symbol in executable. */
3315 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
3316 || tls_type == GOT_TLS_IE)
3317 htab->elf.srelgot->size += bed->s->sizeof_rela;
3318 else if (GOT_TLS_GD_P (tls_type))
3319 htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
3320 else if (! GOT_TLS_GDESC_P (tls_type)
3321 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3322 && !resolved_to_zero)
3323 || h->root.type != bfd_link_hash_undefweak)
3324 && (bfd_link_pic (info)
3325 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
3326 htab->elf.srelgot->size += bed->s->sizeof_rela;
3327 if (GOT_TLS_GDESC_P (tls_type))
3329 htab->elf.srelplt->size += bed->s->sizeof_rela;
3330 htab->tlsdesc_plt = (bfd_vma) -1;
3334 h->got.offset = (bfd_vma) -1;
3336 if (eh->dyn_relocs == NULL)
3339 /* In the shared -Bsymbolic case, discard space allocated for
3340 dynamic pc-relative relocs against symbols which turn out to be
3341 defined in regular objects. For the normal shared case, discard
3342 space for pc-relative relocs that have become local due to symbol
3343 visibility changes. */
3345 if (bfd_link_pic (info))
3347 /* Relocs that use pc_count are those that appear on a call
3348 insn, or certain REL relocs that can generated via assembly.
3349 We want calls to protected symbols to resolve directly to the
3350 function rather than going via the plt. If people want
3351 function pointer comparisons to work as expected then they
3352 should avoid writing weird assembly. */
3353 if (SYMBOL_CALLS_LOCAL (info, h))
3355 struct elf_dyn_relocs **pp;
3357 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3359 p->count -= p->pc_count;
3368 /* Also discard relocs on undefined weak syms with non-default
3369 visibility or in PIE. */
3370 if (eh->dyn_relocs != NULL)
3372 if (h->root.type == bfd_link_hash_undefweak)
3374 /* Undefined weak symbol is never bound locally in shared
3376 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3377 || resolved_to_zero)
3378 eh->dyn_relocs = NULL;
3379 else if (h->dynindx == -1
3380 && ! h->forced_local
3381 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3384 /* For PIE, discard space for pc-relative relocs against
3385 symbols which turn out to need copy relocs. */
3386 else if (bfd_link_executable (info)
3387 && (h->needs_copy || eh->needs_copy)
3391 struct elf_dyn_relocs **pp;
3393 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3395 if (p->pc_count != 0)
3403 else if (ELIMINATE_COPY_RELOCS)
3405 /* For the non-shared case, discard space for relocs against
3406 symbols which turn out to need copy relocs or are not
3407 dynamic. Keep dynamic relocations for run-time function
3408 pointer initialization. */
3410 if ((!h->non_got_ref
3411 || eh->func_pointer_refcount > 0
3412 || (h->root.type == bfd_link_hash_undefweak
3413 && !resolved_to_zero))
3416 || (htab->elf.dynamic_sections_created
3417 && (h->root.type == bfd_link_hash_undefweak
3418 || h->root.type == bfd_link_hash_undefined))))
3420 /* Make sure this symbol is output as a dynamic symbol.
3421 Undefined weak syms won't yet be marked as dynamic. */
3422 if (h->dynindx == -1
3423 && ! h->forced_local
3424 && ! resolved_to_zero
3425 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3428 /* If that succeeded, we know we'll be keeping all the
3430 if (h->dynindx != -1)
3434 eh->dyn_relocs = NULL;
3435 eh->func_pointer_refcount = 0;
3440 /* Finally, allocate space. */
3441 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3445 sreloc = elf_section_data (p->sec)->sreloc;
3447 BFD_ASSERT (sreloc != NULL);
3449 sreloc->size += p->count * bed->s->sizeof_rela;
3455 /* Allocate space in .plt, .got and associated reloc sections for
3456 local dynamic relocs. */
3459 elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
3461 struct elf_link_hash_entry *h
3462 = (struct elf_link_hash_entry *) *slot;
3464 if (h->type != STT_GNU_IFUNC
3468 || h->root.type != bfd_link_hash_defined)
3471 return elf_x86_64_allocate_dynrelocs (h, inf);
3474 /* Find any dynamic relocs that apply to read-only sections. */
3477 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
3480 struct elf_x86_64_link_hash_entry *eh;
3481 struct elf_dyn_relocs *p;
3483 /* Skip local IFUNC symbols. */
3484 if (h->forced_local && h->type == STT_GNU_IFUNC)
3487 eh = (struct elf_x86_64_link_hash_entry *) h;
3488 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3490 asection *s = p->sec->output_section;
3492 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3494 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3496 info->flags |= DF_TEXTREL;
3498 if ((info->warn_shared_textrel && bfd_link_pic (info))
3499 || info->error_textrel)
3500 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3501 p->sec->owner, h->root.root.string,
3504 /* Not an error, just cut short the traversal. */
3511 /* Convert load via the GOT slot to load immediate. */
3514 elf_x86_64_convert_load (bfd *abfd, asection *sec,
3515 struct bfd_link_info *link_info)
3517 Elf_Internal_Shdr *symtab_hdr;
3518 Elf_Internal_Rela *internal_relocs;
3519 Elf_Internal_Rela *irel, *irelend;
3521 struct elf_x86_64_link_hash_table *htab;
3522 bfd_boolean changed;
3523 bfd_signed_vma *local_got_refcounts;
3525 /* Don't even try to convert non-ELF outputs. */
3526 if (!is_elf_hash_table (link_info->hash))
3529 /* Nothing to do if there is no need or no output. */
3530 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
3531 || sec->need_convert_load == 0
3532 || bfd_is_abs_section (sec->output_section))
3535 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3537 /* Load the relocations for this section. */
3538 internal_relocs = (_bfd_elf_link_read_relocs
3539 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
3540 link_info->keep_memory));
3541 if (internal_relocs == NULL)
3545 htab = elf_x86_64_hash_table (link_info);
3546 local_got_refcounts = elf_local_got_refcounts (abfd);
3548 /* Get the section contents. */
3549 if (elf_section_data (sec)->this_hdr.contents != NULL)
3550 contents = elf_section_data (sec)->this_hdr.contents;
3553 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
3557 irelend = internal_relocs + sec->reloc_count;
3558 for (irel = internal_relocs; irel < irelend; irel++)
3560 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
3561 unsigned int r_symndx;
3562 struct elf_link_hash_entry *h;
3563 bfd_boolean converted;
3565 if (r_type != R_X86_64_GOTPCRELX
3566 && r_type != R_X86_64_REX_GOTPCRELX
3567 && r_type != R_X86_64_GOTPCREL)
3570 r_symndx = htab->r_sym (irel->r_info);
3571 if (r_symndx < symtab_hdr->sh_info)
3572 h = elf_x86_64_get_local_sym_hash (htab, sec->owner,
3573 (const Elf_Internal_Rela *) irel,
3577 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
3578 while (h->root.type == bfd_link_hash_indirect
3579 || h->root.type == bfd_link_hash_warning)
3580 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3583 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3584 if (h != NULL && h->type == STT_GNU_IFUNC)
3588 if (!elf_x86_64_convert_load_reloc (abfd, sec, contents, irel, h,
3589 &converted, link_info))
3594 changed = converted;
3597 if (h->got.refcount > 0)
3598 h->got.refcount -= 1;
3602 if (local_got_refcounts != NULL
3603 && local_got_refcounts[r_symndx] > 0)
3604 local_got_refcounts[r_symndx] -= 1;
3609 if (contents != NULL
3610 && elf_section_data (sec)->this_hdr.contents != contents)
3612 if (!changed && !link_info->keep_memory)
3616 /* Cache the section contents for elf_link_input_bfd. */
3617 elf_section_data (sec)->this_hdr.contents = contents;
3621 if (elf_section_data (sec)->relocs != internal_relocs)
3624 free (internal_relocs);
3626 elf_section_data (sec)->relocs = internal_relocs;
3632 if (contents != NULL
3633 && elf_section_data (sec)->this_hdr.contents != contents)
3635 if (internal_relocs != NULL
3636 && elf_section_data (sec)->relocs != internal_relocs)
3637 free (internal_relocs);
3641 /* Set the sizes of the dynamic sections. */
3644 elf_x86_64_size_dynamic_sections (bfd *output_bfd,
3645 struct bfd_link_info *info)
3647 struct elf_x86_64_link_hash_table *htab;
3652 const struct elf_backend_data *bed;
3654 htab = elf_x86_64_hash_table (info);
3657 bed = get_elf_backend_data (output_bfd);
3659 dynobj = htab->elf.dynobj;
3663 /* Set up .got offsets for local syms, and space for local dynamic
3665 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3667 bfd_signed_vma *local_got;
3668 bfd_signed_vma *end_local_got;
3669 char *local_tls_type;
3670 bfd_vma *local_tlsdesc_gotent;
3671 bfd_size_type locsymcount;
3672 Elf_Internal_Shdr *symtab_hdr;
3675 if (! is_x86_64_elf (ibfd))
3678 for (s = ibfd->sections; s != NULL; s = s->next)
3680 struct elf_dyn_relocs *p;
3682 if (!elf_x86_64_convert_load (ibfd, s, info))
3685 for (p = (struct elf_dyn_relocs *)
3686 (elf_section_data (s)->local_dynrel);
3690 if (!bfd_is_abs_section (p->sec)
3691 && bfd_is_abs_section (p->sec->output_section))
3693 /* Input section has been discarded, either because
3694 it is a copy of a linkonce section or due to
3695 linker script /DISCARD/, so we'll be discarding
3698 else if (p->count != 0)
3700 srel = elf_section_data (p->sec)->sreloc;
3701 srel->size += p->count * bed->s->sizeof_rela;
3702 if ((p->sec->output_section->flags & SEC_READONLY) != 0
3703 && (info->flags & DF_TEXTREL) == 0)
3705 info->flags |= DF_TEXTREL;
3706 if ((info->warn_shared_textrel && bfd_link_pic (info))
3707 || info->error_textrel)
3708 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3709 p->sec->owner, p->sec);
3715 local_got = elf_local_got_refcounts (ibfd);
3719 symtab_hdr = &elf_symtab_hdr (ibfd);
3720 locsymcount = symtab_hdr->sh_info;
3721 end_local_got = local_got + locsymcount;
3722 local_tls_type = elf_x86_64_local_got_tls_type (ibfd);
3723 local_tlsdesc_gotent = elf_x86_64_local_tlsdesc_gotent (ibfd);
3725 srel = htab->elf.srelgot;
3726 for (; local_got < end_local_got;
3727 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
3729 *local_tlsdesc_gotent = (bfd_vma) -1;
3732 if (GOT_TLS_GDESC_P (*local_tls_type))
3734 *local_tlsdesc_gotent = htab->elf.sgotplt->size
3735 - elf_x86_64_compute_jump_table_size (htab);
3736 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
3737 *local_got = (bfd_vma) -2;
3739 if (! GOT_TLS_GDESC_P (*local_tls_type)
3740 || GOT_TLS_GD_P (*local_tls_type))
3742 *local_got = s->size;
3743 s->size += GOT_ENTRY_SIZE;
3744 if (GOT_TLS_GD_P (*local_tls_type))
3745 s->size += GOT_ENTRY_SIZE;
3747 if (bfd_link_pic (info)
3748 || GOT_TLS_GD_ANY_P (*local_tls_type)
3749 || *local_tls_type == GOT_TLS_IE)
3751 if (GOT_TLS_GDESC_P (*local_tls_type))
3753 htab->elf.srelplt->size
3754 += bed->s->sizeof_rela;
3755 htab->tlsdesc_plt = (bfd_vma) -1;
3757 if (! GOT_TLS_GDESC_P (*local_tls_type)
3758 || GOT_TLS_GD_P (*local_tls_type))
3759 srel->size += bed->s->sizeof_rela;
3763 *local_got = (bfd_vma) -1;
3767 if (htab->tls_ld_got.refcount > 0)
3769 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3771 htab->tls_ld_got.offset = htab->elf.sgot->size;
3772 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
3773 htab->elf.srelgot->size += bed->s->sizeof_rela;
3776 htab->tls_ld_got.offset = -1;
3778 /* Allocate global sym .plt and .got entries, and space for global
3779 sym dynamic relocs. */
3780 elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
3783 /* Allocate .plt and .got entries, and space for local symbols. */
3784 htab_traverse (htab->loc_hash_table,
3785 elf_x86_64_allocate_local_dynrelocs,
3788 /* For every jump slot reserved in the sgotplt, reloc_count is
3789 incremented. However, when we reserve space for TLS descriptors,
3790 it's not incremented, so in order to compute the space reserved
3791 for them, it suffices to multiply the reloc count by the jump
3794 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3795 so that R_X86_64_IRELATIVE entries come last. */
3796 if (htab->elf.srelplt)
3798 htab->sgotplt_jump_table_size
3799 = elf_x86_64_compute_jump_table_size (htab);
3800 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
3802 else if (htab->elf.irelplt)
3803 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
3805 if (htab->tlsdesc_plt)
3807 /* If we're not using lazy TLS relocations, don't generate the
3808 PLT and GOT entries they require. */
3809 if ((info->flags & DF_BIND_NOW))
3810 htab->tlsdesc_plt = 0;
3813 htab->tlsdesc_got = htab->elf.sgot->size;
3814 htab->elf.sgot->size += GOT_ENTRY_SIZE;
3815 /* Reserve room for the initial entry.
3816 FIXME: we could probably do away with it in this case. */
3817 if (htab->elf.splt->size == 0)
3818 htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);
3819 htab->tlsdesc_plt = htab->elf.splt->size;
3820 htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);
3824 if (htab->elf.sgotplt)
3826 /* Don't allocate .got.plt section if there are no GOT nor PLT
3827 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3828 if ((htab->elf.hgot == NULL
3829 || !htab->elf.hgot->ref_regular_nonweak)
3830 && (htab->elf.sgotplt->size
3831 == get_elf_backend_data (output_bfd)->got_header_size)
3832 && (htab->elf.splt == NULL
3833 || htab->elf.splt->size == 0)
3834 && (htab->elf.sgot == NULL
3835 || htab->elf.sgot->size == 0)
3836 && (htab->elf.iplt == NULL
3837 || htab->elf.iplt->size == 0)
3838 && (htab->elf.igotplt == NULL
3839 || htab->elf.igotplt->size == 0))
3840 htab->elf.sgotplt->size = 0;
3843 if (_bfd_elf_eh_frame_present (info))
3845 if (htab->plt_eh_frame != NULL
3846 && htab->elf.splt != NULL
3847 && htab->elf.splt->size != 0
3848 && !bfd_is_abs_section (htab->elf.splt->output_section))
3850 const struct elf_x86_64_backend_data *arch_data
3851 = get_elf_x86_64_arch_data (bed);
3852 htab->plt_eh_frame->size = arch_data->eh_frame_plt_size;
3855 if (htab->plt_got_eh_frame != NULL
3856 && htab->plt_got != NULL
3857 && htab->plt_got->size != 0
3858 && !bfd_is_abs_section (htab->plt_got->output_section))
3860 const struct elf_x86_64_backend_data *arch_data
3861 = get_elf_x86_64_arch_data (bed);
3862 htab->plt_got_eh_frame->size
3863 = arch_data->eh_frame_plt_got_size;
3867 /* We now have determined the sizes of the various dynamic sections.
3868 Allocate memory for them. */
3870 for (s = dynobj->sections; s != NULL; s = s->next)
3872 if ((s->flags & SEC_LINKER_CREATED) == 0)
3875 if (s == htab->elf.splt
3876 || s == htab->elf.sgot
3877 || s == htab->elf.sgotplt
3878 || s == htab->elf.iplt
3879 || s == htab->elf.igotplt
3880 || s == htab->plt_bnd
3881 || s == htab->plt_got
3882 || s == htab->plt_eh_frame
3883 || s == htab->plt_got_eh_frame
3884 || s == htab->sdynbss)
3886 /* Strip this section if we don't need it; see the
3889 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3891 if (s->size != 0 && s != htab->elf.srelplt)
3894 /* We use the reloc_count field as a counter if we need
3895 to copy relocs into the output file. */
3896 if (s != htab->elf.srelplt)
3901 /* It's not one of our sections, so don't allocate space. */
3907 /* If we don't need this section, strip it from the
3908 output file. This is mostly to handle .rela.bss and
3909 .rela.plt. We must create both sections in
3910 create_dynamic_sections, because they must be created
3911 before the linker maps input sections to output
3912 sections. The linker does that before
3913 adjust_dynamic_symbol is called, and it is that
3914 function which decides whether anything needs to go
3915 into these sections. */
3917 s->flags |= SEC_EXCLUDE;
3921 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3924 /* Allocate memory for the section contents. We use bfd_zalloc
3925 here in case unused entries are not reclaimed before the
3926 section's contents are written out. This should not happen,
3927 but this way if it does, we get a R_X86_64_NONE reloc instead
3929 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3930 if (s->contents == NULL)
3934 if (htab->plt_eh_frame != NULL
3935 && htab->plt_eh_frame->contents != NULL)
3937 const struct elf_x86_64_backend_data *arch_data
3938 = get_elf_x86_64_arch_data (bed);
3940 memcpy (htab->plt_eh_frame->contents,
3941 arch_data->eh_frame_plt, htab->plt_eh_frame->size);
3942 bfd_put_32 (dynobj, htab->elf.splt->size,
3943 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
3946 if (htab->plt_got_eh_frame != NULL
3947 && htab->plt_got_eh_frame->contents != NULL)
3949 const struct elf_x86_64_backend_data *arch_data
3950 = get_elf_x86_64_arch_data (bed);
3952 memcpy (htab->plt_got_eh_frame->contents,
3953 arch_data->eh_frame_plt_got,
3954 htab->plt_got_eh_frame->size);
3955 bfd_put_32 (dynobj, htab->plt_got->size,
3956 (htab->plt_got_eh_frame->contents
3957 + PLT_FDE_LEN_OFFSET));
3960 if (htab->elf.dynamic_sections_created)
3962 /* Add some entries to the .dynamic section. We fill in the
3963 values later, in elf_x86_64_finish_dynamic_sections, but we
3964 must add the entries now so that we get the correct size for
3965 the .dynamic section. The DT_DEBUG entry is filled in by the
3966 dynamic linker and used by the debugger. */
3967 #define add_dynamic_entry(TAG, VAL) \
3968 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3970 if (bfd_link_executable (info))
3972 if (!add_dynamic_entry (DT_DEBUG, 0))
3976 if (htab->elf.splt->size != 0)
3978 /* DT_PLTGOT is used by prelink even if there is no PLT
3980 if (!add_dynamic_entry (DT_PLTGOT, 0))
3983 if (htab->elf.srelplt->size != 0)
3985 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
3986 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3987 || !add_dynamic_entry (DT_JMPREL, 0))
3991 if (htab->tlsdesc_plt
3992 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
3993 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
3999 if (!add_dynamic_entry (DT_RELA, 0)
4000 || !add_dynamic_entry (DT_RELASZ, 0)
4001 || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
4004 /* If any dynamic relocs apply to a read-only section,
4005 then we need a DT_TEXTREL entry. */
4006 if ((info->flags & DF_TEXTREL) == 0)
4007 elf_link_hash_traverse (&htab->elf,
4008 elf_x86_64_readonly_dynrelocs,
4011 if ((info->flags & DF_TEXTREL) != 0)
4013 if (htab->readonly_dynrelocs_against_ifunc)
4015 info->callbacks->einfo
4016 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4017 bfd_set_error (bfd_error_bad_value);
4021 if (!add_dynamic_entry (DT_TEXTREL, 0))
4026 #undef add_dynamic_entry
4032 elf_x86_64_always_size_sections (bfd *output_bfd,
4033 struct bfd_link_info *info)
4035 asection *tls_sec = elf_hash_table (info)->tls_sec;
4039 struct elf_link_hash_entry *tlsbase;
4041 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
4042 "_TLS_MODULE_BASE_",
4043 FALSE, FALSE, FALSE);
4045 if (tlsbase && tlsbase->type == STT_TLS)
4047 struct elf_x86_64_link_hash_table *htab;
4048 struct bfd_link_hash_entry *bh = NULL;
4049 const struct elf_backend_data *bed
4050 = get_elf_backend_data (output_bfd);
4052 htab = elf_x86_64_hash_table (info);
4056 if (!(_bfd_generic_link_add_one_symbol
4057 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
4058 tls_sec, 0, NULL, FALSE,
4059 bed->collect, &bh)))
4062 htab->tls_module_base = bh;
4064 tlsbase = (struct elf_link_hash_entry *)bh;
4065 tlsbase->def_regular = 1;
4066 tlsbase->other = STV_HIDDEN;
4067 tlsbase->root.linker_def = 1;
4068 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
4075 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4076 executables. Rather than setting it to the beginning of the TLS
4077 section, we have to set it to the end. This function may be called
4078 multiple times, it is idempotent. */
4081 elf_x86_64_set_tls_module_base (struct bfd_link_info *info)
4083 struct elf_x86_64_link_hash_table *htab;
4084 struct bfd_link_hash_entry *base;
4086 if (!bfd_link_executable (info))
4089 htab = elf_x86_64_hash_table (info);
4093 base = htab->tls_module_base;
4097 base->u.def.value = htab->elf.tls_size;
4100 /* Return the base VMA address which should be subtracted from real addresses
4101 when resolving @dtpoff relocation.
4102 This is PT_TLS segment p_vaddr. */
4105 elf_x86_64_dtpoff_base (struct bfd_link_info *info)
4107 /* If tls_sec is NULL, we should have signalled an error already. */
4108 if (elf_hash_table (info)->tls_sec == NULL)
4110 return elf_hash_table (info)->tls_sec->vma;
4113 /* Return the relocation value for @tpoff relocation
4114 if STT_TLS virtual address is ADDRESS. */
4117 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
4119 struct elf_link_hash_table *htab = elf_hash_table (info);
4120 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
4121 bfd_vma static_tls_size;
4123 /* If tls_segment is NULL, we should have signalled an error already. */
4124 if (htab->tls_sec == NULL)
4127 /* Consider special static TLS alignment requirements. */
4128 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
4129 return address - static_tls_size - htab->tls_sec->vma;
4132 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4136 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
4138 /* Opcode Instruction
4141 0x0f 0x8x conditional jump */
4143 && (contents [offset - 1] == 0xe8
4144 || contents [offset - 1] == 0xe9))
4146 && contents [offset - 2] == 0x0f
4147 && (contents [offset - 1] & 0xf0) == 0x80));
4150 /* Relocate an x86_64 ELF section. */
4153 elf_x86_64_relocate_section (bfd *output_bfd,
4154 struct bfd_link_info *info,
4156 asection *input_section,
4158 Elf_Internal_Rela *relocs,
4159 Elf_Internal_Sym *local_syms,
4160 asection **local_sections)
4162 struct elf_x86_64_link_hash_table *htab;
4163 Elf_Internal_Shdr *symtab_hdr;
4164 struct elf_link_hash_entry **sym_hashes;
4165 bfd_vma *local_got_offsets;
4166 bfd_vma *local_tlsdesc_gotents;
4167 Elf_Internal_Rela *rel;
4168 Elf_Internal_Rela *wrel;
4169 Elf_Internal_Rela *relend;
4170 const unsigned int plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
4172 BFD_ASSERT (is_x86_64_elf (input_bfd));
4174 /* Skip if check_relocs failed. */
4175 if (input_section->check_relocs_failed)
4178 htab = elf_x86_64_hash_table (info);
4181 symtab_hdr = &elf_symtab_hdr (input_bfd);
4182 sym_hashes = elf_sym_hashes (input_bfd);
4183 local_got_offsets = elf_local_got_offsets (input_bfd);
4184 local_tlsdesc_gotents = elf_x86_64_local_tlsdesc_gotent (input_bfd);
4186 elf_x86_64_set_tls_module_base (info);
4188 rel = wrel = relocs;
4189 relend = relocs + input_section->reloc_count;
4190 for (; rel < relend; wrel++, rel++)
4192 unsigned int r_type;
4193 reloc_howto_type *howto;
4194 unsigned long r_symndx;
4195 struct elf_link_hash_entry *h;
4196 struct elf_x86_64_link_hash_entry *eh;
4197 Elf_Internal_Sym *sym;
4199 bfd_vma off, offplt, plt_offset;
4201 bfd_boolean unresolved_reloc;
4202 bfd_reloc_status_type r;
4204 asection *base_got, *resolved_plt;
4206 bfd_boolean resolved_to_zero;
4208 r_type = ELF32_R_TYPE (rel->r_info);
4209 if (r_type == (int) R_X86_64_GNU_VTINHERIT
4210 || r_type == (int) R_X86_64_GNU_VTENTRY)
4217 if (r_type >= (int) R_X86_64_standard)
4219 (*_bfd_error_handler)
4220 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4221 input_bfd, input_section, r_type);
4222 bfd_set_error (bfd_error_bad_value);
4226 if (r_type != (int) R_X86_64_32
4227 || ABI_64_P (output_bfd))
4228 howto = x86_64_elf_howto_table + r_type;
4230 howto = (x86_64_elf_howto_table
4231 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
4232 r_symndx = htab->r_sym (rel->r_info);
4236 unresolved_reloc = FALSE;
4237 if (r_symndx < symtab_hdr->sh_info)
4239 sym = local_syms + r_symndx;
4240 sec = local_sections[r_symndx];
4242 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
4244 st_size = sym->st_size;
4246 /* Relocate against local STT_GNU_IFUNC symbol. */
4247 if (!bfd_link_relocatable (info)
4248 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
4250 h = elf_x86_64_get_local_sym_hash (htab, input_bfd,
4255 /* Set STT_GNU_IFUNC symbol value. */
4256 h->root.u.def.value = sym->st_value;
4257 h->root.u.def.section = sec;
4262 bfd_boolean warned ATTRIBUTE_UNUSED;
4263 bfd_boolean ignored ATTRIBUTE_UNUSED;
4265 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4266 r_symndx, symtab_hdr, sym_hashes,
4268 unresolved_reloc, warned, ignored);
4272 if (sec != NULL && discarded_section (sec))
4274 _bfd_clear_contents (howto, input_bfd, input_section,
4275 contents + rel->r_offset);
4276 wrel->r_offset = rel->r_offset;
4280 /* For ld -r, remove relocations in debug sections against
4281 sections defined in discarded sections. Not done for
4282 eh_frame editing code expects to be present. */
4283 if (bfd_link_relocatable (info)
4284 && (input_section->flags & SEC_DEBUGGING))
4290 if (bfd_link_relocatable (info))
4297 if (rel->r_addend == 0 && !ABI_64_P (output_bfd))
4299 if (r_type == R_X86_64_64)
4301 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4302 zero-extend it to 64bit if addend is zero. */
4303 r_type = R_X86_64_32;
4304 memset (contents + rel->r_offset + 4, 0, 4);
4306 else if (r_type == R_X86_64_SIZE64)
4308 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4309 zero-extend it to 64bit if addend is zero. */
4310 r_type = R_X86_64_SIZE32;
4311 memset (contents + rel->r_offset + 4, 0, 4);
4315 eh = (struct elf_x86_64_link_hash_entry *) h;
4317 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4318 it here if it is defined in a non-shared object. */
4320 && h->type == STT_GNU_IFUNC
4326 if ((input_section->flags & SEC_ALLOC) == 0)
4328 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4329 sections because such sections are not SEC_ALLOC and
4330 thus ld.so will not process them. */
4331 if ((input_section->flags & SEC_DEBUGGING) != 0)
4341 case R_X86_64_GOTPCREL:
4342 case R_X86_64_GOTPCRELX:
4343 case R_X86_64_REX_GOTPCRELX:
4344 case R_X86_64_GOTPCREL64:
4345 base_got = htab->elf.sgot;
4346 off = h->got.offset;
4348 if (base_got == NULL)
4351 if (off == (bfd_vma) -1)
4353 /* We can't use h->got.offset here to save state, or
4354 even just remember the offset, as finish_dynamic_symbol
4355 would use that as offset into .got. */
4357 if (h->plt.offset == (bfd_vma) -1)
4360 if (htab->elf.splt != NULL)
4362 plt_index = h->plt.offset / plt_entry_size - 1;
4363 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4364 base_got = htab->elf.sgotplt;
4368 plt_index = h->plt.offset / plt_entry_size;
4369 off = plt_index * GOT_ENTRY_SIZE;
4370 base_got = htab->elf.igotplt;
4373 if (h->dynindx == -1
4377 /* This references the local defitionion. We must
4378 initialize this entry in the global offset table.
4379 Since the offset must always be a multiple of 8,
4380 we use the least significant bit to record
4381 whether we have initialized it already.
4383 When doing a dynamic link, we create a .rela.got
4384 relocation entry to initialize the value. This
4385 is done in the finish_dynamic_symbol routine. */
4390 bfd_put_64 (output_bfd, relocation,
4391 base_got->contents + off);
4392 /* Note that this is harmless for the GOTPLT64
4393 case, as -1 | 1 still is -1. */
4399 relocation = (base_got->output_section->vma
4400 + base_got->output_offset + off);
4405 if (h->plt.offset == (bfd_vma) -1)
4407 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4408 if (r_type == htab->pointer_r_type
4409 && (input_section->flags & SEC_CODE) == 0)
4410 goto do_ifunc_pointer;
4411 goto bad_ifunc_reloc;
4414 /* STT_GNU_IFUNC symbol must go through PLT. */
4415 if (htab->elf.splt != NULL)
4417 if (htab->plt_bnd != NULL)
4419 resolved_plt = htab->plt_bnd;
4420 plt_offset = eh->plt_bnd.offset;
4424 resolved_plt = htab->elf.splt;
4425 plt_offset = h->plt.offset;
4430 resolved_plt = htab->elf.iplt;
4431 plt_offset = h->plt.offset;
4434 relocation = (resolved_plt->output_section->vma
4435 + resolved_plt->output_offset + plt_offset);
4441 if (h->root.root.string)
4442 name = h->root.root.string;
4444 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4446 (*_bfd_error_handler)
4447 (_("%B: relocation %s against STT_GNU_IFUNC "
4448 "symbol `%s' isn't supported"), input_bfd,
4450 bfd_set_error (bfd_error_bad_value);
4454 if (bfd_link_pic (info))
4459 if (ABI_64_P (output_bfd))
4464 if (rel->r_addend != 0)
4466 if (h->root.root.string)
4467 name = h->root.root.string;
4469 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4471 (*_bfd_error_handler)
4472 (_("%B: relocation %s against STT_GNU_IFUNC "
4473 "symbol `%s' has non-zero addend: %d"),
4474 input_bfd, howto->name, name, rel->r_addend);
4475 bfd_set_error (bfd_error_bad_value);
4479 /* Generate dynamic relcoation only when there is a
4480 non-GOT reference in a shared object or there is no
4482 if ((bfd_link_pic (info) && h->non_got_ref)
4483 || h->plt.offset == (bfd_vma) -1)
4485 Elf_Internal_Rela outrel;
4488 /* Need a dynamic relocation to get the real function
4490 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4494 if (outrel.r_offset == (bfd_vma) -1
4495 || outrel.r_offset == (bfd_vma) -2)
4498 outrel.r_offset += (input_section->output_section->vma
4499 + input_section->output_offset);
4501 if (h->dynindx == -1
4503 || bfd_link_executable (info))
4505 /* This symbol is resolved locally. */
4506 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
4507 outrel.r_addend = (h->root.u.def.value
4508 + h->root.u.def.section->output_section->vma
4509 + h->root.u.def.section->output_offset);
4513 outrel.r_info = htab->r_info (h->dynindx, r_type);
4514 outrel.r_addend = 0;
4517 /* Dynamic relocations are stored in
4518 1. .rela.ifunc section in PIC object.
4519 2. .rela.got section in dynamic executable.
4520 3. .rela.iplt section in static executable. */
4521 if (bfd_link_pic (info))
4522 sreloc = htab->elf.irelifunc;
4523 else if (htab->elf.splt != NULL)
4524 sreloc = htab->elf.srelgot;
4526 sreloc = htab->elf.irelplt;
4527 elf_append_rela (output_bfd, sreloc, &outrel);
4529 /* If this reloc is against an external symbol, we
4530 do not want to fiddle with the addend. Otherwise,
4531 we need to include the symbol value so that it
4532 becomes an addend for the dynamic reloc. For an
4533 internal symbol, we have updated addend. */
4538 case R_X86_64_PC32_BND:
4540 case R_X86_64_PLT32:
4541 case R_X86_64_PLT32_BND:
4546 resolved_to_zero = (eh != NULL
4547 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
4551 /* When generating a shared object, the relocations handled here are
4552 copied into the output file to be resolved at run time. */
4555 case R_X86_64_GOT32:
4556 case R_X86_64_GOT64:
4557 /* Relocation is to the entry for this symbol in the global
4559 case R_X86_64_GOTPCREL:
4560 case R_X86_64_GOTPCRELX:
4561 case R_X86_64_REX_GOTPCRELX:
4562 case R_X86_64_GOTPCREL64:
4563 /* Use global offset table entry as symbol value. */
4564 case R_X86_64_GOTPLT64:
4565 /* This is obsolete and treated the the same as GOT64. */
4566 base_got = htab->elf.sgot;
4568 if (htab->elf.sgot == NULL)
4575 off = h->got.offset;
4577 && h->plt.offset != (bfd_vma)-1
4578 && off == (bfd_vma)-1)
4580 /* We can't use h->got.offset here to save
4581 state, or even just remember the offset, as
4582 finish_dynamic_symbol would use that as offset into
4584 bfd_vma plt_index = h->plt.offset / plt_entry_size - 1;
4585 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4586 base_got = htab->elf.sgotplt;
4589 dyn = htab->elf.dynamic_sections_created;
4591 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4592 || (bfd_link_pic (info)
4593 && SYMBOL_REFERENCES_LOCAL (info, h))
4594 || (ELF_ST_VISIBILITY (h->other)
4595 && h->root.type == bfd_link_hash_undefweak))
4597 /* This is actually a static link, or it is a -Bsymbolic
4598 link and the symbol is defined locally, or the symbol
4599 was forced to be local because of a version file. We
4600 must initialize this entry in the global offset table.
4601 Since the offset must always be a multiple of 8, we
4602 use the least significant bit to record whether we
4603 have initialized it already.
4605 When doing a dynamic link, we create a .rela.got
4606 relocation entry to initialize the value. This is
4607 done in the finish_dynamic_symbol routine. */
4612 bfd_put_64 (output_bfd, relocation,
4613 base_got->contents + off);
4614 /* Note that this is harmless for the GOTPLT64 case,
4615 as -1 | 1 still is -1. */
4620 unresolved_reloc = FALSE;
4624 if (local_got_offsets == NULL)
4627 off = local_got_offsets[r_symndx];
4629 /* The offset must always be a multiple of 8. We use
4630 the least significant bit to record whether we have
4631 already generated the necessary reloc. */
4636 bfd_put_64 (output_bfd, relocation,
4637 base_got->contents + off);
4639 if (bfd_link_pic (info))
4642 Elf_Internal_Rela outrel;
4644 /* We need to generate a R_X86_64_RELATIVE reloc
4645 for the dynamic linker. */
4646 s = htab->elf.srelgot;
4650 outrel.r_offset = (base_got->output_section->vma
4651 + base_got->output_offset
4653 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4654 outrel.r_addend = relocation;
4655 elf_append_rela (output_bfd, s, &outrel);
4658 local_got_offsets[r_symndx] |= 1;
4662 if (off >= (bfd_vma) -2)
4665 relocation = base_got->output_section->vma
4666 + base_got->output_offset + off;
4667 if (r_type != R_X86_64_GOTPCREL
4668 && r_type != R_X86_64_GOTPCRELX
4669 && r_type != R_X86_64_REX_GOTPCRELX
4670 && r_type != R_X86_64_GOTPCREL64)
4671 relocation -= htab->elf.sgotplt->output_section->vma
4672 - htab->elf.sgotplt->output_offset;
4676 case R_X86_64_GOTOFF64:
4677 /* Relocation is relative to the start of the global offset
4680 /* Check to make sure it isn't a protected function or data
4681 symbol for shared library since it may not be local when
4682 used as function address or with copy relocation. We also
4683 need to make sure that a symbol is referenced locally. */
4684 if (bfd_link_pic (info) && h)
4686 if (!h->def_regular)
4690 switch (ELF_ST_VISIBILITY (h->other))
4693 v = _("hidden symbol");
4696 v = _("internal symbol");
4699 v = _("protected symbol");
4706 (*_bfd_error_handler)
4707 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s `%s' can not be used when making a shared object"),
4708 input_bfd, v, h->root.root.string);
4709 bfd_set_error (bfd_error_bad_value);
4712 else if (!bfd_link_executable (info)
4713 && !SYMBOL_REFERENCES_LOCAL (info, h)
4714 && (h->type == STT_FUNC
4715 || h->type == STT_OBJECT)
4716 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
4718 (*_bfd_error_handler)
4719 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"),
4721 h->type == STT_FUNC ? "function" : "data",
4722 h->root.root.string);
4723 bfd_set_error (bfd_error_bad_value);
4728 /* Note that sgot is not involved in this
4729 calculation. We always want the start of .got.plt. If we
4730 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4731 permitted by the ABI, we might have to change this
4733 relocation -= htab->elf.sgotplt->output_section->vma
4734 + htab->elf.sgotplt->output_offset;
4737 case R_X86_64_GOTPC32:
4738 case R_X86_64_GOTPC64:
4739 /* Use global offset table as symbol value. */
4740 relocation = htab->elf.sgotplt->output_section->vma
4741 + htab->elf.sgotplt->output_offset;
4742 unresolved_reloc = FALSE;
4745 case R_X86_64_PLTOFF64:
4746 /* Relocation is PLT entry relative to GOT. For local
4747 symbols it's the symbol itself relative to GOT. */
4749 /* See PLT32 handling. */
4750 && h->plt.offset != (bfd_vma) -1
4751 && htab->elf.splt != NULL)
4753 if (htab->plt_bnd != NULL)
4755 resolved_plt = htab->plt_bnd;
4756 plt_offset = eh->plt_bnd.offset;
4760 resolved_plt = htab->elf.splt;
4761 plt_offset = h->plt.offset;
4764 relocation = (resolved_plt->output_section->vma
4765 + resolved_plt->output_offset
4767 unresolved_reloc = FALSE;
4770 relocation -= htab->elf.sgotplt->output_section->vma
4771 + htab->elf.sgotplt->output_offset;
4774 case R_X86_64_PLT32:
4775 case R_X86_64_PLT32_BND:
4776 /* Relocation is to the entry for this symbol in the
4777 procedure linkage table. */
4779 /* Resolve a PLT32 reloc against a local symbol directly,
4780 without using the procedure linkage table. */
4784 if ((h->plt.offset == (bfd_vma) -1
4785 && eh->plt_got.offset == (bfd_vma) -1)
4786 || htab->elf.splt == NULL)
4788 /* We didn't make a PLT entry for this symbol. This
4789 happens when statically linking PIC code, or when
4790 using -Bsymbolic. */
4794 if (h->plt.offset != (bfd_vma) -1)
4796 if (htab->plt_bnd != NULL)
4798 resolved_plt = htab->plt_bnd;
4799 plt_offset = eh->plt_bnd.offset;
4803 resolved_plt = htab->elf.splt;
4804 plt_offset = h->plt.offset;
4809 /* Use the GOT PLT. */
4810 resolved_plt = htab->plt_got;
4811 plt_offset = eh->plt_got.offset;
4814 relocation = (resolved_plt->output_section->vma
4815 + resolved_plt->output_offset
4817 unresolved_reloc = FALSE;
4820 case R_X86_64_SIZE32:
4821 case R_X86_64_SIZE64:
4822 /* Set to symbol size. */
4823 relocation = st_size;
4829 case R_X86_64_PC32_BND:
4830 /* Don't complain about -fPIC if the symbol is undefined when
4831 building executable unless it is unresolved weak symbol. */
4832 if ((input_section->flags & SEC_ALLOC) != 0
4833 && (input_section->flags & SEC_READONLY) != 0
4835 && ((bfd_link_executable (info)
4836 && h->root.type == bfd_link_hash_undefweak
4837 && !resolved_to_zero)
4838 || (bfd_link_pic (info)
4839 && !(bfd_link_pie (info)
4840 && h->root.type == bfd_link_hash_undefined))))
4842 bfd_boolean fail = FALSE;
4844 = ((r_type == R_X86_64_PC32
4845 || r_type == R_X86_64_PC32_BND)
4846 && is_32bit_relative_branch (contents, rel->r_offset));
4848 if (SYMBOL_REFERENCES_LOCAL (info, h))
4850 /* Symbol is referenced locally. Make sure it is
4851 defined locally or for a branch. */
4852 fail = !h->def_regular && !branch;
4854 else if (!(bfd_link_pie (info)
4855 && (h->needs_copy || eh->needs_copy)))
4857 /* Symbol doesn't need copy reloc and isn't referenced
4858 locally. We only allow branch to symbol with
4859 non-default visibility. */
4861 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
4865 return elf_x86_64_need_pic (input_bfd, input_section,
4866 h, NULL, NULL, howto);
4875 /* FIXME: The ABI says the linker should make sure the value is
4876 the same when it's zeroextended to 64 bit. */
4879 if ((input_section->flags & SEC_ALLOC) == 0)
4882 /* Don't copy a pc-relative relocation into the output file
4883 if the symbol needs copy reloc or the symbol is undefined
4884 when building executable. Copy dynamic function pointer
4885 relocations. Don't generate dynamic relocations against
4886 resolved undefined weak symbols in PIE. */
4887 if ((bfd_link_pic (info)
4888 && !(bfd_link_pie (info)
4892 || h->root.type == bfd_link_hash_undefined)
4893 && IS_X86_64_PCREL_TYPE (r_type))
4895 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4896 && !resolved_to_zero)
4897 || h->root.type != bfd_link_hash_undefweak))
4898 && ((! IS_X86_64_PCREL_TYPE (r_type)
4899 && r_type != R_X86_64_SIZE32
4900 && r_type != R_X86_64_SIZE64)
4901 || ! SYMBOL_CALLS_LOCAL (info, h)))
4902 || (ELIMINATE_COPY_RELOCS
4903 && !bfd_link_pic (info)
4907 || eh->func_pointer_refcount > 0
4908 || (h->root.type == bfd_link_hash_undefweak
4909 && !resolved_to_zero))
4910 && ((h->def_dynamic && !h->def_regular)
4911 /* Undefined weak symbol is bound locally when
4913 || h->root.type == bfd_link_hash_undefined)))
4915 Elf_Internal_Rela outrel;
4916 bfd_boolean skip, relocate;
4919 /* When generating a shared object, these relocations
4920 are copied into the output file to be resolved at run
4926 _bfd_elf_section_offset (output_bfd, info, input_section,
4928 if (outrel.r_offset == (bfd_vma) -1)
4930 else if (outrel.r_offset == (bfd_vma) -2)
4931 skip = TRUE, relocate = TRUE;
4933 outrel.r_offset += (input_section->output_section->vma
4934 + input_section->output_offset);
4937 memset (&outrel, 0, sizeof outrel);
4939 /* h->dynindx may be -1 if this symbol was marked to
4943 && (IS_X86_64_PCREL_TYPE (r_type)
4944 || !(bfd_link_executable (info)
4945 || SYMBOLIC_BIND (info, h))
4946 || ! h->def_regular))
4948 outrel.r_info = htab->r_info (h->dynindx, r_type);
4949 outrel.r_addend = rel->r_addend;
4953 /* This symbol is local, or marked to become local.
4954 When relocation overflow check is disabled, we
4955 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4956 if (r_type == htab->pointer_r_type
4957 || (r_type == R_X86_64_32
4958 && info->no_reloc_overflow_check))
4961 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4962 outrel.r_addend = relocation + rel->r_addend;
4964 else if (r_type == R_X86_64_64
4965 && !ABI_64_P (output_bfd))
4968 outrel.r_info = htab->r_info (0,
4969 R_X86_64_RELATIVE64);
4970 outrel.r_addend = relocation + rel->r_addend;
4971 /* Check addend overflow. */
4972 if ((outrel.r_addend & 0x80000000)
4973 != (rel->r_addend & 0x80000000))
4976 int addend = rel->r_addend;
4977 if (h && h->root.root.string)
4978 name = h->root.root.string;
4980 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4983 (*_bfd_error_handler)
4984 (_("%B: addend -0x%x in relocation %s against "
4985 "symbol `%s' at 0x%lx in section `%A' is "
4987 input_bfd, input_section, addend,
4989 (unsigned long) rel->r_offset);
4991 (*_bfd_error_handler)
4992 (_("%B: addend 0x%x in relocation %s against "
4993 "symbol `%s' at 0x%lx in section `%A' is "
4995 input_bfd, input_section, addend,
4997 (unsigned long) rel->r_offset);
4998 bfd_set_error (bfd_error_bad_value);
5006 if (bfd_is_abs_section (sec))
5008 else if (sec == NULL || sec->owner == NULL)
5010 bfd_set_error (bfd_error_bad_value);
5017 /* We are turning this relocation into one
5018 against a section symbol. It would be
5019 proper to subtract the symbol's value,
5020 osec->vma, from the emitted reloc addend,
5021 but ld.so expects buggy relocs. */
5022 osec = sec->output_section;
5023 sindx = elf_section_data (osec)->dynindx;
5026 asection *oi = htab->elf.text_index_section;
5027 sindx = elf_section_data (oi)->dynindx;
5029 BFD_ASSERT (sindx != 0);
5032 outrel.r_info = htab->r_info (sindx, r_type);
5033 outrel.r_addend = relocation + rel->r_addend;
5037 sreloc = elf_section_data (input_section)->sreloc;
5039 if (sreloc == NULL || sreloc->contents == NULL)
5041 r = bfd_reloc_notsupported;
5042 goto check_relocation_error;
5045 elf_append_rela (output_bfd, sreloc, &outrel);
5047 /* If this reloc is against an external symbol, we do
5048 not want to fiddle with the addend. Otherwise, we
5049 need to include the symbol value so that it becomes
5050 an addend for the dynamic reloc. */
5057 case R_X86_64_TLSGD:
5058 case R_X86_64_GOTPC32_TLSDESC:
5059 case R_X86_64_TLSDESC_CALL:
5060 case R_X86_64_GOTTPOFF:
5061 tls_type = GOT_UNKNOWN;
5062 if (h == NULL && local_got_offsets)
5063 tls_type = elf_x86_64_local_got_tls_type (input_bfd) [r_symndx];
5065 tls_type = elf_x86_64_hash_entry (h)->tls_type;
5067 if (! elf_x86_64_tls_transition (info, input_bfd,
5068 input_section, contents,
5069 symtab_hdr, sym_hashes,
5070 &r_type, tls_type, rel,
5071 relend, h, r_symndx, TRUE))
5074 if (r_type == R_X86_64_TPOFF32)
5076 bfd_vma roff = rel->r_offset;
5078 BFD_ASSERT (! unresolved_reloc);
5080 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
5082 /* GD->LE transition. For 64bit, change
5083 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5084 .word 0x6666; rex64; call __tls_get_addr@PLT
5086 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5088 call *__tls_get_addr@GOTPCREL(%rip)
5089 which may be converted to
5090 addr32 call __tls_get_addr
5093 leaq foo@tpoff(%rax), %rax
5095 leaq foo@tlsgd(%rip), %rdi
5096 .word 0x6666; rex64; call __tls_get_addr@PLT
5098 leaq foo@tlsgd(%rip), %rdi
5100 call *__tls_get_addr@GOTPCREL(%rip)
5101 which may be converted to
5102 addr32 call __tls_get_addr
5105 leaq foo@tpoff(%rax), %rax
5106 For largepic, change:
5107 leaq foo@tlsgd(%rip), %rdi
5108 movabsq $__tls_get_addr@pltoff, %rax
5113 leaq foo@tpoff(%rax), %rax
5114 nopw 0x0(%rax,%rax,1) */
5116 if (ABI_64_P (output_bfd))
5118 if (contents[roff + 5] == 0xb8)
5120 memcpy (contents + roff - 3,
5121 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5122 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5126 memcpy (contents + roff - 4,
5127 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5131 memcpy (contents + roff - 3,
5132 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5134 bfd_put_32 (output_bfd,
5135 elf_x86_64_tpoff (info, relocation),
5136 contents + roff + 8 + largepic);
5137 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5138 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5143 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
5145 /* GDesc -> LE transition.
5146 It's originally something like:
5147 leaq x@tlsdesc(%rip), %rax
5150 movl $x@tpoff, %rax. */
5152 unsigned int val, type;
5154 type = bfd_get_8 (input_bfd, contents + roff - 3);
5155 val = bfd_get_8 (input_bfd, contents + roff - 1);
5156 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
5157 contents + roff - 3);
5158 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
5159 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
5160 contents + roff - 1);
5161 bfd_put_32 (output_bfd,
5162 elf_x86_64_tpoff (info, relocation),
5166 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
5168 /* GDesc -> LE transition.
5173 bfd_put_8 (output_bfd, 0x66, contents + roff);
5174 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
5177 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
5179 /* IE->LE transition:
5180 For 64bit, originally it can be one of:
5181 movq foo@gottpoff(%rip), %reg
5182 addq foo@gottpoff(%rip), %reg
5185 leaq foo(%reg), %reg
5187 For 32bit, originally it can be one of:
5188 movq foo@gottpoff(%rip), %reg
5189 addl foo@gottpoff(%rip), %reg
5192 leal foo(%reg), %reg
5195 unsigned int val, type, reg;
5198 val = bfd_get_8 (input_bfd, contents + roff - 3);
5201 type = bfd_get_8 (input_bfd, contents + roff - 2);
5202 reg = bfd_get_8 (input_bfd, contents + roff - 1);
5208 bfd_put_8 (output_bfd, 0x49,
5209 contents + roff - 3);
5210 else if (!ABI_64_P (output_bfd) && val == 0x44)
5211 bfd_put_8 (output_bfd, 0x41,
5212 contents + roff - 3);
5213 bfd_put_8 (output_bfd, 0xc7,
5214 contents + roff - 2);
5215 bfd_put_8 (output_bfd, 0xc0 | reg,
5216 contents + roff - 1);
5220 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5223 bfd_put_8 (output_bfd, 0x49,
5224 contents + roff - 3);
5225 else if (!ABI_64_P (output_bfd) && val == 0x44)
5226 bfd_put_8 (output_bfd, 0x41,
5227 contents + roff - 3);
5228 bfd_put_8 (output_bfd, 0x81,
5229 contents + roff - 2);
5230 bfd_put_8 (output_bfd, 0xc0 | reg,
5231 contents + roff - 1);
5235 /* addq/addl -> leaq/leal */
5237 bfd_put_8 (output_bfd, 0x4d,
5238 contents + roff - 3);
5239 else if (!ABI_64_P (output_bfd) && val == 0x44)
5240 bfd_put_8 (output_bfd, 0x45,
5241 contents + roff - 3);
5242 bfd_put_8 (output_bfd, 0x8d,
5243 contents + roff - 2);
5244 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
5245 contents + roff - 1);
5247 bfd_put_32 (output_bfd,
5248 elf_x86_64_tpoff (info, relocation),
5256 if (htab->elf.sgot == NULL)
5261 off = h->got.offset;
5262 offplt = elf_x86_64_hash_entry (h)->tlsdesc_got;
5266 if (local_got_offsets == NULL)
5269 off = local_got_offsets[r_symndx];
5270 offplt = local_tlsdesc_gotents[r_symndx];
5277 Elf_Internal_Rela outrel;
5281 if (htab->elf.srelgot == NULL)
5284 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5286 if (GOT_TLS_GDESC_P (tls_type))
5288 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
5289 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
5290 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
5291 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
5292 + htab->elf.sgotplt->output_offset
5294 + htab->sgotplt_jump_table_size);
5295 sreloc = htab->elf.srelplt;
5297 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
5299 outrel.r_addend = 0;
5300 elf_append_rela (output_bfd, sreloc, &outrel);
5303 sreloc = htab->elf.srelgot;
5305 outrel.r_offset = (htab->elf.sgot->output_section->vma
5306 + htab->elf.sgot->output_offset + off);
5308 if (GOT_TLS_GD_P (tls_type))
5309 dr_type = R_X86_64_DTPMOD64;
5310 else if (GOT_TLS_GDESC_P (tls_type))
5313 dr_type = R_X86_64_TPOFF64;
5315 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
5316 outrel.r_addend = 0;
5317 if ((dr_type == R_X86_64_TPOFF64
5318 || dr_type == R_X86_64_TLSDESC) && indx == 0)
5319 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
5320 outrel.r_info = htab->r_info (indx, dr_type);
5322 elf_append_rela (output_bfd, sreloc, &outrel);
5324 if (GOT_TLS_GD_P (tls_type))
5328 BFD_ASSERT (! unresolved_reloc);
5329 bfd_put_64 (output_bfd,
5330 relocation - elf_x86_64_dtpoff_base (info),
5331 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5335 bfd_put_64 (output_bfd, 0,
5336 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5337 outrel.r_info = htab->r_info (indx,
5339 outrel.r_offset += GOT_ENTRY_SIZE;
5340 elf_append_rela (output_bfd, sreloc,
5349 local_got_offsets[r_symndx] |= 1;
5352 if (off >= (bfd_vma) -2
5353 && ! GOT_TLS_GDESC_P (tls_type))
5355 if (r_type == ELF32_R_TYPE (rel->r_info))
5357 if (r_type == R_X86_64_GOTPC32_TLSDESC
5358 || r_type == R_X86_64_TLSDESC_CALL)
5359 relocation = htab->elf.sgotplt->output_section->vma
5360 + htab->elf.sgotplt->output_offset
5361 + offplt + htab->sgotplt_jump_table_size;
5363 relocation = htab->elf.sgot->output_section->vma
5364 + htab->elf.sgot->output_offset + off;
5365 unresolved_reloc = FALSE;
5369 bfd_vma roff = rel->r_offset;
5371 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
5373 /* GD->IE transition. For 64bit, change
5374 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5375 .word 0x6666; rex64; call __tls_get_addr@PLT
5377 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5379 call *__tls_get_addr@GOTPCREL(%rip
5380 which may be converted to
5381 addr32 call __tls_get_addr
5384 addq foo@gottpoff(%rip), %rax
5386 leaq foo@tlsgd(%rip), %rdi
5387 .word 0x6666; rex64; call __tls_get_addr@PLT
5389 leaq foo@tlsgd(%rip), %rdi
5391 call *__tls_get_addr@GOTPCREL(%rip)
5392 which may be converted to
5393 addr32 call __tls_get_addr
5396 addq foo@gottpoff(%rip), %rax
5397 For largepic, change:
5398 leaq foo@tlsgd(%rip), %rdi
5399 movabsq $__tls_get_addr@pltoff, %rax
5404 addq foo@gottpoff(%rax), %rax
5405 nopw 0x0(%rax,%rax,1) */
5407 if (ABI_64_P (output_bfd))
5409 if (contents[roff + 5] == 0xb8)
5411 memcpy (contents + roff - 3,
5412 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5413 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5417 memcpy (contents + roff - 4,
5418 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5422 memcpy (contents + roff - 3,
5423 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5426 relocation = (htab->elf.sgot->output_section->vma
5427 + htab->elf.sgot->output_offset + off
5430 - input_section->output_section->vma
5431 - input_section->output_offset
5433 bfd_put_32 (output_bfd, relocation,
5434 contents + roff + 8 + largepic);
5435 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5440 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
5442 /* GDesc -> IE transition.
5443 It's originally something like:
5444 leaq x@tlsdesc(%rip), %rax
5447 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5449 /* Now modify the instruction as appropriate. To
5450 turn a leaq into a movq in the form we use it, it
5451 suffices to change the second byte from 0x8d to
5453 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
5455 bfd_put_32 (output_bfd,
5456 htab->elf.sgot->output_section->vma
5457 + htab->elf.sgot->output_offset + off
5459 - input_section->output_section->vma
5460 - input_section->output_offset
5465 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
5467 /* GDesc -> IE transition.
5474 bfd_put_8 (output_bfd, 0x66, contents + roff);
5475 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
5483 case R_X86_64_TLSLD:
5484 if (! elf_x86_64_tls_transition (info, input_bfd,
5485 input_section, contents,
5486 symtab_hdr, sym_hashes,
5487 &r_type, GOT_UNKNOWN, rel,
5488 relend, h, r_symndx, TRUE))
5491 if (r_type != R_X86_64_TLSLD)
5493 /* LD->LE transition:
5494 leaq foo@tlsld(%rip), %rdi
5495 call __tls_get_addr@PLT
5496 For 64bit, we change it into:
5497 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5498 For 32bit, we change it into:
5499 nopl 0x0(%rax); movl %fs:0, %eax
5501 leaq foo@tlsld(%rip), %rdi;
5502 call *__tls_get_addr@GOTPCREL(%rip)
5503 which may be converted to
5504 addr32 call __tls_get_addr
5505 For 64bit, we change it into:
5506 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5507 For 32bit, we change it into:
5508 nopw 0x0(%rax); movl %fs:0, %eax
5509 For largepic, change:
5510 leaq foo@tlsgd(%rip), %rdi
5511 movabsq $__tls_get_addr@pltoff, %rax
5515 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5518 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
5519 if (ABI_64_P (output_bfd))
5521 if (contents[rel->r_offset + 5] == 0xb8)
5522 memcpy (contents + rel->r_offset - 3,
5523 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5524 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5525 else if (contents[rel->r_offset + 4] == 0xff
5526 || contents[rel->r_offset + 4] == 0x67)
5527 memcpy (contents + rel->r_offset - 3,
5528 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5531 memcpy (contents + rel->r_offset - 3,
5532 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5536 if (contents[rel->r_offset + 4] == 0xff)
5537 memcpy (contents + rel->r_offset - 3,
5538 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5541 memcpy (contents + rel->r_offset - 3,
5542 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5544 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5545 and R_X86_64_PLTOFF64. */
5551 if (htab->elf.sgot == NULL)
5554 off = htab->tls_ld_got.offset;
5559 Elf_Internal_Rela outrel;
5561 if (htab->elf.srelgot == NULL)
5564 outrel.r_offset = (htab->elf.sgot->output_section->vma
5565 + htab->elf.sgot->output_offset + off);
5567 bfd_put_64 (output_bfd, 0,
5568 htab->elf.sgot->contents + off);
5569 bfd_put_64 (output_bfd, 0,
5570 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5571 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
5572 outrel.r_addend = 0;
5573 elf_append_rela (output_bfd, htab->elf.srelgot,
5575 htab->tls_ld_got.offset |= 1;
5577 relocation = htab->elf.sgot->output_section->vma
5578 + htab->elf.sgot->output_offset + off;
5579 unresolved_reloc = FALSE;
5582 case R_X86_64_DTPOFF32:
5583 if (!bfd_link_executable (info)
5584 || (input_section->flags & SEC_CODE) == 0)
5585 relocation -= elf_x86_64_dtpoff_base (info);
5587 relocation = elf_x86_64_tpoff (info, relocation);
5590 case R_X86_64_TPOFF32:
5591 case R_X86_64_TPOFF64:
5592 BFD_ASSERT (bfd_link_executable (info));
5593 relocation = elf_x86_64_tpoff (info, relocation);
5596 case R_X86_64_DTPOFF64:
5597 BFD_ASSERT ((input_section->flags & SEC_CODE) == 0);
5598 relocation -= elf_x86_64_dtpoff_base (info);
5605 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5606 because such sections are not SEC_ALLOC and thus ld.so will
5607 not process them. */
5608 if (unresolved_reloc
5609 && !((input_section->flags & SEC_DEBUGGING) != 0
5611 && _bfd_elf_section_offset (output_bfd, info, input_section,
5612 rel->r_offset) != (bfd_vma) -1)
5614 (*_bfd_error_handler)
5615 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5618 (long) rel->r_offset,
5620 h->root.root.string);
5625 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5626 contents, rel->r_offset,
5627 relocation, rel->r_addend);
5629 check_relocation_error:
5630 if (r != bfd_reloc_ok)
5635 name = h->root.root.string;
5638 name = bfd_elf_string_from_elf_section (input_bfd,
5639 symtab_hdr->sh_link,
5644 name = bfd_section_name (input_bfd, sec);
5647 if (r == bfd_reloc_overflow)
5648 (*info->callbacks->reloc_overflow)
5649 (info, (h ? &h->root : NULL), name, howto->name,
5650 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5653 (*_bfd_error_handler)
5654 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5655 input_bfd, input_section,
5656 (long) rel->r_offset, name, (int) r);
5667 Elf_Internal_Shdr *rel_hdr;
5668 size_t deleted = rel - wrel;
5670 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
5671 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5672 if (rel_hdr->sh_size == 0)
5674 /* It is too late to remove an empty reloc section. Leave
5676 ??? What is wrong with an empty section??? */
5677 rel_hdr->sh_size = rel_hdr->sh_entsize;
5680 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
5681 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5682 input_section->reloc_count -= deleted;
5688 /* Finish up dynamic symbol handling. We set the contents of various
5689 dynamic sections here. */
5692 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
5693 struct bfd_link_info *info,
5694 struct elf_link_hash_entry *h,
5695 Elf_Internal_Sym *sym)
5697 struct elf_x86_64_link_hash_table *htab;
5698 const struct elf_x86_64_backend_data *abed;
5699 bfd_boolean use_plt_bnd;
5700 struct elf_x86_64_link_hash_entry *eh;
5701 bfd_boolean local_undefweak;
5703 htab = elf_x86_64_hash_table (info);
5707 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5708 section only if there is .plt section. */
5709 use_plt_bnd = htab->elf.splt != NULL && htab->plt_bnd != NULL;
5711 ? &elf_x86_64_bnd_arch_bed
5712 : get_elf_x86_64_backend_data (output_bfd));
5714 eh = (struct elf_x86_64_link_hash_entry *) h;
5716 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5717 resolved undefined weak symbols in executable so that their
5718 references have value 0 at run-time. */
5719 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
5723 if (h->plt.offset != (bfd_vma) -1)
5726 bfd_vma got_offset, plt_offset, plt_plt_offset, plt_got_offset;
5727 bfd_vma plt_plt_insn_end, plt_got_insn_size;
5728 Elf_Internal_Rela rela;
5730 asection *plt, *gotplt, *relplt, *resolved_plt;
5731 const struct elf_backend_data *bed;
5732 bfd_vma plt_got_pcrel_offset;
5734 /* When building a static executable, use .iplt, .igot.plt and
5735 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5736 if (htab->elf.splt != NULL)
5738 plt = htab->elf.splt;
5739 gotplt = htab->elf.sgotplt;
5740 relplt = htab->elf.srelplt;
5744 plt = htab->elf.iplt;
5745 gotplt = htab->elf.igotplt;
5746 relplt = htab->elf.irelplt;
5749 /* This symbol has an entry in the procedure linkage table. Set
5751 if ((h->dynindx == -1
5753 && !((h->forced_local || bfd_link_executable (info))
5755 && h->type == STT_GNU_IFUNC))
5761 /* Get the index in the procedure linkage table which
5762 corresponds to this symbol. This is the index of this symbol
5763 in all the symbols for which we are making plt entries. The
5764 first entry in the procedure linkage table is reserved.
5766 Get the offset into the .got table of the entry that
5767 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5768 bytes. The first three are reserved for the dynamic linker.
5770 For static executables, we don't reserve anything. */
5772 if (plt == htab->elf.splt)
5774 got_offset = h->plt.offset / abed->plt_entry_size - 1;
5775 got_offset = (got_offset + 3) * GOT_ENTRY_SIZE;
5779 got_offset = h->plt.offset / abed->plt_entry_size;
5780 got_offset = got_offset * GOT_ENTRY_SIZE;
5783 plt_plt_insn_end = abed->plt_plt_insn_end;
5784 plt_plt_offset = abed->plt_plt_offset;
5785 plt_got_insn_size = abed->plt_got_insn_size;
5786 plt_got_offset = abed->plt_got_offset;
5789 /* Use the second PLT with BND relocations. */
5790 const bfd_byte *plt_entry, *plt2_entry;
5792 if (eh->has_bnd_reloc)
5794 plt_entry = elf_x86_64_bnd_plt_entry;
5795 plt2_entry = elf_x86_64_bnd_plt2_entry;
5799 plt_entry = elf_x86_64_legacy_plt_entry;
5800 plt2_entry = elf_x86_64_legacy_plt2_entry;
5802 /* Subtract 1 since there is no BND prefix. */
5803 plt_plt_insn_end -= 1;
5804 plt_plt_offset -= 1;
5805 plt_got_insn_size -= 1;
5806 plt_got_offset -= 1;
5809 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry)
5810 == sizeof (elf_x86_64_legacy_plt_entry));
5812 /* Fill in the entry in the procedure linkage table. */
5813 memcpy (plt->contents + h->plt.offset,
5814 plt_entry, sizeof (elf_x86_64_legacy_plt_entry));
5815 /* Fill in the entry in the second PLT. */
5816 memcpy (htab->plt_bnd->contents + eh->plt_bnd.offset,
5817 plt2_entry, sizeof (elf_x86_64_legacy_plt2_entry));
5819 resolved_plt = htab->plt_bnd;
5820 plt_offset = eh->plt_bnd.offset;
5824 /* Fill in the entry in the procedure linkage table. */
5825 memcpy (plt->contents + h->plt.offset, abed->plt_entry,
5826 abed->plt_entry_size);
5829 plt_offset = h->plt.offset;
5832 /* Insert the relocation positions of the plt section. */
5834 /* Put offset the PC-relative instruction referring to the GOT entry,
5835 subtracting the size of that instruction. */
5836 plt_got_pcrel_offset = (gotplt->output_section->vma
5837 + gotplt->output_offset
5839 - resolved_plt->output_section->vma
5840 - resolved_plt->output_offset
5842 - plt_got_insn_size);
5844 /* Check PC-relative offset overflow in PLT entry. */
5845 if ((plt_got_pcrel_offset + 0x80000000) > 0xffffffff)
5846 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5847 output_bfd, h->root.root.string);
5849 bfd_put_32 (output_bfd, plt_got_pcrel_offset,
5850 resolved_plt->contents + plt_offset + plt_got_offset);
5852 /* Fill in the entry in the global offset table, initially this
5853 points to the second part of the PLT entry. Leave the entry
5854 as zero for undefined weak symbol in PIE. No PLT relocation
5855 against undefined weak symbol in PIE. */
5856 if (!local_undefweak)
5858 bfd_put_64 (output_bfd, (plt->output_section->vma
5859 + plt->output_offset
5861 + abed->plt_lazy_offset),
5862 gotplt->contents + got_offset);
5864 /* Fill in the entry in the .rela.plt section. */
5865 rela.r_offset = (gotplt->output_section->vma
5866 + gotplt->output_offset
5868 if (h->dynindx == -1
5869 || ((bfd_link_executable (info)
5870 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5872 && h->type == STT_GNU_IFUNC))
5874 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5875 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5876 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
5877 rela.r_addend = (h->root.u.def.value
5878 + h->root.u.def.section->output_section->vma
5879 + h->root.u.def.section->output_offset);
5880 /* R_X86_64_IRELATIVE comes last. */
5881 plt_index = htab->next_irelative_index--;
5885 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
5887 plt_index = htab->next_jump_slot_index++;
5890 /* Don't fill PLT entry for static executables. */
5891 if (plt == htab->elf.splt)
5893 bfd_vma plt0_offset = h->plt.offset + plt_plt_insn_end;
5895 /* Put relocation index. */
5896 bfd_put_32 (output_bfd, plt_index,
5897 (plt->contents + h->plt.offset
5898 + abed->plt_reloc_offset));
5900 /* Put offset for jmp .PLT0 and check for overflow. We don't
5901 check relocation index for overflow since branch displacement
5902 will overflow first. */
5903 if (plt0_offset > 0x80000000)
5904 info->callbacks->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5905 output_bfd, h->root.root.string);
5906 bfd_put_32 (output_bfd, - plt0_offset,
5907 plt->contents + h->plt.offset + plt_plt_offset);
5910 bed = get_elf_backend_data (output_bfd);
5911 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
5912 bed->s->swap_reloca_out (output_bfd, &rela, loc);
5915 else if (eh->plt_got.offset != (bfd_vma) -1)
5917 bfd_vma got_offset, plt_offset, plt_got_offset, plt_got_insn_size;
5918 asection *plt, *got;
5919 bfd_boolean got_after_plt;
5920 int32_t got_pcrel_offset;
5921 const bfd_byte *got_plt_entry;
5923 /* Set the entry in the GOT procedure linkage table. */
5924 plt = htab->plt_got;
5925 got = htab->elf.sgot;
5926 got_offset = h->got.offset;
5928 if (got_offset == (bfd_vma) -1
5929 || h->type == STT_GNU_IFUNC
5934 /* Use the second PLT entry template for the GOT PLT since they
5935 are the identical. */
5936 plt_got_insn_size = elf_x86_64_bnd_arch_bed.plt_got_insn_size;
5937 plt_got_offset = elf_x86_64_bnd_arch_bed.plt_got_offset;
5938 if (eh->has_bnd_reloc)
5939 got_plt_entry = elf_x86_64_bnd_plt2_entry;
5942 got_plt_entry = elf_x86_64_legacy_plt2_entry;
5944 /* Subtract 1 since there is no BND prefix. */
5945 plt_got_insn_size -= 1;
5946 plt_got_offset -= 1;
5949 /* Fill in the entry in the GOT procedure linkage table. */
5950 plt_offset = eh->plt_got.offset;
5951 memcpy (plt->contents + plt_offset,
5952 got_plt_entry, sizeof (elf_x86_64_legacy_plt2_entry));
5954 /* Put offset the PC-relative instruction referring to the GOT
5955 entry, subtracting the size of that instruction. */
5956 got_pcrel_offset = (got->output_section->vma
5957 + got->output_offset
5959 - plt->output_section->vma
5960 - plt->output_offset
5962 - plt_got_insn_size);
5964 /* Check PC-relative offset overflow in GOT PLT entry. */
5965 got_after_plt = got->output_section->vma > plt->output_section->vma;
5966 if ((got_after_plt && got_pcrel_offset < 0)
5967 || (!got_after_plt && got_pcrel_offset > 0))
5968 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5969 output_bfd, h->root.root.string);
5971 bfd_put_32 (output_bfd, got_pcrel_offset,
5972 plt->contents + plt_offset + plt_got_offset);
5975 if (!local_undefweak
5977 && (h->plt.offset != (bfd_vma) -1
5978 || eh->plt_got.offset != (bfd_vma) -1))
5980 /* Mark the symbol as undefined, rather than as defined in
5981 the .plt section. Leave the value if there were any
5982 relocations where pointer equality matters (this is a clue
5983 for the dynamic linker, to make function pointer
5984 comparisons work between an application and shared
5985 library), otherwise set it to zero. If a function is only
5986 called from a binary, there is no need to slow down
5987 shared libraries because of that. */
5988 sym->st_shndx = SHN_UNDEF;
5989 if (!h->pointer_equality_needed)
5993 /* Don't generate dynamic GOT relocation against undefined weak
5994 symbol in executable. */
5995 if (h->got.offset != (bfd_vma) -1
5996 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h)->tls_type)
5997 && elf_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE
5998 && !local_undefweak)
6000 Elf_Internal_Rela rela;
6001 asection *relgot = htab->elf.srelgot;
6003 /* This symbol has an entry in the global offset table. Set it
6005 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
6008 rela.r_offset = (htab->elf.sgot->output_section->vma
6009 + htab->elf.sgot->output_offset
6010 + (h->got.offset &~ (bfd_vma) 1));
6012 /* If this is a static link, or it is a -Bsymbolic link and the
6013 symbol is defined locally or was forced to be local because
6014 of a version file, we just want to emit a RELATIVE reloc.
6015 The entry in the global offset table will already have been
6016 initialized in the relocate_section function. */
6018 && h->type == STT_GNU_IFUNC)
6020 if (h->plt.offset == (bfd_vma) -1)
6022 /* STT_GNU_IFUNC is referenced without PLT. */
6023 if (htab->elf.splt == NULL)
6025 /* use .rel[a].iplt section to store .got relocations
6026 in static executable. */
6027 relgot = htab->elf.irelplt;
6029 if (SYMBOL_REFERENCES_LOCAL (info, h))
6031 rela.r_info = htab->r_info (0,
6032 R_X86_64_IRELATIVE);
6033 rela.r_addend = (h->root.u.def.value
6034 + h->root.u.def.section->output_section->vma
6035 + h->root.u.def.section->output_offset);
6040 else if (bfd_link_pic (info))
6042 /* Generate R_X86_64_GLOB_DAT. */
6049 if (!h->pointer_equality_needed)
6052 /* For non-shared object, we can't use .got.plt, which
6053 contains the real function addres if we need pointer
6054 equality. We load the GOT entry with the PLT entry. */
6055 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
6056 bfd_put_64 (output_bfd, (plt->output_section->vma
6057 + plt->output_offset
6059 htab->elf.sgot->contents + h->got.offset);
6063 else if (bfd_link_pic (info)
6064 && SYMBOL_REFERENCES_LOCAL (info, h))
6066 if (!h->def_regular)
6068 BFD_ASSERT((h->got.offset & 1) != 0);
6069 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
6070 rela.r_addend = (h->root.u.def.value
6071 + h->root.u.def.section->output_section->vma
6072 + h->root.u.def.section->output_offset);
6076 BFD_ASSERT((h->got.offset & 1) == 0);
6078 bfd_put_64 (output_bfd, (bfd_vma) 0,
6079 htab->elf.sgot->contents + h->got.offset);
6080 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
6084 elf_append_rela (output_bfd, relgot, &rela);
6089 Elf_Internal_Rela rela;
6091 /* This symbol needs a copy reloc. Set it up. */
6093 if (h->dynindx == -1
6094 || (h->root.type != bfd_link_hash_defined
6095 && h->root.type != bfd_link_hash_defweak)
6096 || htab->srelbss == NULL)
6099 rela.r_offset = (h->root.u.def.value
6100 + h->root.u.def.section->output_section->vma
6101 + h->root.u.def.section->output_offset);
6102 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
6104 elf_append_rela (output_bfd, htab->srelbss, &rela);
6110 /* Finish up local dynamic symbol handling. We set the contents of
6111 various dynamic sections here. */
6114 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
6116 struct elf_link_hash_entry *h
6117 = (struct elf_link_hash_entry *) *slot;
6118 struct bfd_link_info *info
6119 = (struct bfd_link_info *) inf;
6121 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
6125 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6126 here since undefined weak symbol may not be dynamic and may not be
6127 called for elf_x86_64_finish_dynamic_symbol. */
6130 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
6133 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
6134 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6136 if (h->root.type != bfd_link_hash_undefweak
6137 || h->dynindx != -1)
6140 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
6144 /* Used to decide how to sort relocs in an optimal manner for the
6145 dynamic linker, before writing them out. */
6147 static enum elf_reloc_type_class
6148 elf_x86_64_reloc_type_class (const struct bfd_link_info *info,
6149 const asection *rel_sec ATTRIBUTE_UNUSED,
6150 const Elf_Internal_Rela *rela)
6152 bfd *abfd = info->output_bfd;
6153 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6154 struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
6156 if (htab->elf.dynsym != NULL
6157 && htab->elf.dynsym->contents != NULL)
6159 /* Check relocation against STT_GNU_IFUNC symbol if there are
6161 unsigned long r_symndx = htab->r_sym (rela->r_info);
6162 if (r_symndx != STN_UNDEF)
6164 Elf_Internal_Sym sym;
6165 if (!bed->s->swap_symbol_in (abfd,
6166 (htab->elf.dynsym->contents
6167 + r_symndx * bed->s->sizeof_sym),
6171 if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
6172 return reloc_class_ifunc;
6176 switch ((int) ELF32_R_TYPE (rela->r_info))
6178 case R_X86_64_IRELATIVE:
6179 return reloc_class_ifunc;
6180 case R_X86_64_RELATIVE:
6181 case R_X86_64_RELATIVE64:
6182 return reloc_class_relative;
6183 case R_X86_64_JUMP_SLOT:
6184 return reloc_class_plt;
6186 return reloc_class_copy;
6188 return reloc_class_normal;
6192 /* Finish up the dynamic sections. */
6195 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
6196 struct bfd_link_info *info)
6198 struct elf_x86_64_link_hash_table *htab;
6201 const struct elf_x86_64_backend_data *abed;
6203 htab = elf_x86_64_hash_table (info);
6207 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6208 section only if there is .plt section. */
6209 abed = (htab->elf.splt != NULL && htab->plt_bnd != NULL
6210 ? &elf_x86_64_bnd_arch_bed
6211 : get_elf_x86_64_backend_data (output_bfd));
6213 dynobj = htab->elf.dynobj;
6214 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
6216 if (htab->elf.dynamic_sections_created)
6218 bfd_byte *dyncon, *dynconend;
6219 const struct elf_backend_data *bed;
6220 bfd_size_type sizeof_dyn;
6222 if (sdyn == NULL || htab->elf.sgot == NULL)
6225 bed = get_elf_backend_data (dynobj);
6226 sizeof_dyn = bed->s->sizeof_dyn;
6227 dyncon = sdyn->contents;
6228 dynconend = sdyn->contents + sdyn->size;
6229 for (; dyncon < dynconend; dyncon += sizeof_dyn)
6231 Elf_Internal_Dyn dyn;
6234 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
6242 s = htab->elf.sgotplt;
6243 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6247 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
6251 s = htab->elf.srelplt->output_section;
6252 dyn.d_un.d_val = s->size;
6256 /* The procedure linkage table relocs (DT_JMPREL) should
6257 not be included in the overall relocs (DT_RELA).
6258 Therefore, we override the DT_RELASZ entry here to
6259 make it not include the JMPREL relocs. Since the
6260 linker script arranges for .rela.plt to follow all
6261 other relocation sections, we don't have to worry
6262 about changing the DT_RELA entry. */
6263 if (htab->elf.srelplt != NULL)
6265 s = htab->elf.srelplt->output_section;
6266 dyn.d_un.d_val -= s->size;
6270 case DT_TLSDESC_PLT:
6272 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
6273 + htab->tlsdesc_plt;
6276 case DT_TLSDESC_GOT:
6278 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
6279 + htab->tlsdesc_got;
6283 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
6286 /* Fill in the special first entry in the procedure linkage table. */
6287 if (htab->elf.splt && htab->elf.splt->size > 0)
6289 /* Fill in the first entry in the procedure linkage table. */
6290 memcpy (htab->elf.splt->contents,
6291 abed->plt0_entry, abed->plt_entry_size);
6292 /* Add offset for pushq GOT+8(%rip), since the instruction
6293 uses 6 bytes subtract this value. */
6294 bfd_put_32 (output_bfd,
6295 (htab->elf.sgotplt->output_section->vma
6296 + htab->elf.sgotplt->output_offset
6298 - htab->elf.splt->output_section->vma
6299 - htab->elf.splt->output_offset
6301 htab->elf.splt->contents + abed->plt0_got1_offset);
6302 /* Add offset for the PC-relative instruction accessing GOT+16,
6303 subtracting the offset to the end of that instruction. */
6304 bfd_put_32 (output_bfd,
6305 (htab->elf.sgotplt->output_section->vma
6306 + htab->elf.sgotplt->output_offset
6308 - htab->elf.splt->output_section->vma
6309 - htab->elf.splt->output_offset
6310 - abed->plt0_got2_insn_end),
6311 htab->elf.splt->contents + abed->plt0_got2_offset);
6313 elf_section_data (htab->elf.splt->output_section)
6314 ->this_hdr.sh_entsize = abed->plt_entry_size;
6316 if (htab->tlsdesc_plt)
6318 bfd_put_64 (output_bfd, (bfd_vma) 0,
6319 htab->elf.sgot->contents + htab->tlsdesc_got);
6321 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
6322 abed->plt0_entry, abed->plt_entry_size);
6324 /* Add offset for pushq GOT+8(%rip), since the
6325 instruction uses 6 bytes subtract this value. */
6326 bfd_put_32 (output_bfd,
6327 (htab->elf.sgotplt->output_section->vma
6328 + htab->elf.sgotplt->output_offset
6330 - htab->elf.splt->output_section->vma
6331 - htab->elf.splt->output_offset
6334 htab->elf.splt->contents
6335 + htab->tlsdesc_plt + abed->plt0_got1_offset);
6336 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6337 where TGD stands for htab->tlsdesc_got, subtracting the offset
6338 to the end of that instruction. */
6339 bfd_put_32 (output_bfd,
6340 (htab->elf.sgot->output_section->vma
6341 + htab->elf.sgot->output_offset
6343 - htab->elf.splt->output_section->vma
6344 - htab->elf.splt->output_offset
6346 - abed->plt0_got2_insn_end),
6347 htab->elf.splt->contents
6348 + htab->tlsdesc_plt + abed->plt0_got2_offset);
6353 if (htab->plt_bnd != NULL)
6354 elf_section_data (htab->plt_bnd->output_section)
6355 ->this_hdr.sh_entsize = sizeof (elf_x86_64_bnd_plt2_entry);
6357 if (htab->elf.sgotplt)
6359 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
6361 (*_bfd_error_handler)
6362 (_("discarded output section: `%A'"), htab->elf.sgotplt);
6366 /* Fill in the first three entries in the global offset table. */
6367 if (htab->elf.sgotplt->size > 0)
6369 /* Set the first entry in the global offset table to the address of
6370 the dynamic section. */
6372 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
6374 bfd_put_64 (output_bfd,
6375 sdyn->output_section->vma + sdyn->output_offset,
6376 htab->elf.sgotplt->contents);
6377 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6378 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
6379 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
6382 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
6386 /* Adjust .eh_frame for .plt section. */
6387 if (htab->plt_eh_frame != NULL
6388 && htab->plt_eh_frame->contents != NULL)
6390 if (htab->elf.splt != NULL
6391 && htab->elf.splt->size != 0
6392 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
6393 && htab->elf.splt->output_section != NULL
6394 && htab->plt_eh_frame->output_section != NULL)
6396 bfd_vma plt_start = htab->elf.splt->output_section->vma;
6397 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
6398 + htab->plt_eh_frame->output_offset
6399 + PLT_FDE_START_OFFSET;
6400 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6401 htab->plt_eh_frame->contents
6402 + PLT_FDE_START_OFFSET);
6404 if (htab->plt_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6406 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6408 htab->plt_eh_frame->contents))
6413 /* Adjust .eh_frame for .plt.got section. */
6414 if (htab->plt_got_eh_frame != NULL
6415 && htab->plt_got_eh_frame->contents != NULL)
6417 if (htab->plt_got != NULL
6418 && htab->plt_got->size != 0
6419 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
6420 && htab->plt_got->output_section != NULL
6421 && htab->plt_got_eh_frame->output_section != NULL)
6423 bfd_vma plt_start = htab->plt_got->output_section->vma;
6424 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
6425 + htab->plt_got_eh_frame->output_offset
6426 + PLT_FDE_START_OFFSET;
6427 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6428 htab->plt_got_eh_frame->contents
6429 + PLT_FDE_START_OFFSET);
6431 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6433 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6434 htab->plt_got_eh_frame,
6435 htab->plt_got_eh_frame->contents))
6440 if (htab->elf.sgot && htab->elf.sgot->size > 0)
6441 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
6444 /* Fill PLT entries for undefined weak symbols in PIE. */
6445 if (bfd_link_pie (info))
6446 bfd_hash_traverse (&info->hash->table,
6447 elf_x86_64_pie_finish_undefweak_symbol,
6453 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6454 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6455 It has to be done before elf_link_sort_relocs is called so that
6456 dynamic relocations are properly sorted. */
6459 elf_x86_64_output_arch_local_syms
6460 (bfd *output_bfd ATTRIBUTE_UNUSED,
6461 struct bfd_link_info *info,
6462 void *flaginfo ATTRIBUTE_UNUSED,
6463 int (*func) (void *, const char *,
6466 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
6468 struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
6472 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6473 htab_traverse (htab->loc_hash_table,
6474 elf_x86_64_finish_local_dynamic_symbol,
6480 /* Return an array of PLT entry symbol values. */
6483 elf_x86_64_get_plt_sym_val (bfd *abfd, asymbol **dynsyms, asection *plt,
6486 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
6489 bfd_vma *plt_sym_val;
6491 bfd_byte *plt_contents;
6492 const struct elf_x86_64_backend_data *bed;
6493 Elf_Internal_Shdr *hdr;
6496 /* Get the .plt section contents. PLT passed down may point to the
6497 .plt.bnd section. Make sure that PLT always points to the .plt
6499 plt_bnd = bfd_get_section_by_name (abfd, ".plt.bnd");
6504 plt = bfd_get_section_by_name (abfd, ".plt");
6507 bed = &elf_x86_64_bnd_arch_bed;
6510 bed = get_elf_x86_64_backend_data (abfd);
6512 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
6513 if (plt_contents == NULL)
6515 if (!bfd_get_section_contents (abfd, (asection *) plt,
6516 plt_contents, 0, plt->size))
6519 free (plt_contents);
6523 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
6524 if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
6527 hdr = &elf_section_data (relplt)->this_hdr;
6528 count = relplt->size / hdr->sh_entsize;
6530 plt_sym_val = (bfd_vma *) bfd_malloc (sizeof (bfd_vma) * count);
6531 if (plt_sym_val == NULL)
6534 for (i = 0; i < count; i++)
6535 plt_sym_val[i] = -1;
6537 plt_offset = bed->plt_entry_size;
6538 p = relplt->relocation;
6539 for (i = 0; i < count; i++, p++)
6543 /* Skip unknown relocation. */
6544 if (p->howto == NULL)
6547 if (p->howto->type != R_X86_64_JUMP_SLOT
6548 && p->howto->type != R_X86_64_IRELATIVE)
6551 reloc_index = H_GET_32 (abfd, (plt_contents + plt_offset
6552 + bed->plt_reloc_offset));
6553 if (reloc_index < count)
6557 /* This is the index in .plt section. */
6558 long plt_index = plt_offset / bed->plt_entry_size;
6559 /* Store VMA + the offset in .plt.bnd section. */
6560 plt_sym_val[reloc_index] =
6562 + (plt_index - 1) * sizeof (elf_x86_64_legacy_plt2_entry));
6565 plt_sym_val[reloc_index] = plt->vma + plt_offset;
6567 plt_offset += bed->plt_entry_size;
6569 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6571 if (plt_offset >= plt->size)
6575 free (plt_contents);
6580 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6584 elf_x86_64_get_synthetic_symtab (bfd *abfd,
6591 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6592 as PLT if it exists. */
6593 asection *plt = bfd_get_section_by_name (abfd, ".plt.bnd");
6595 plt = bfd_get_section_by_name (abfd, ".plt");
6596 return _bfd_elf_ifunc_get_synthetic_symtab (abfd, symcount, syms,
6597 dynsymcount, dynsyms, ret,
6599 elf_x86_64_get_plt_sym_val);
6602 /* Handle an x86-64 specific section when reading an object file. This
6603 is called when elfcode.h finds a section with an unknown type. */
6606 elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr,
6607 const char *name, int shindex)
6609 if (hdr->sh_type != SHT_X86_64_UNWIND)
6612 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6618 /* Hook called by the linker routine which adds symbols from an object
6619 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6623 elf_x86_64_add_symbol_hook (bfd *abfd,
6624 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6625 Elf_Internal_Sym *sym,
6626 const char **namep ATTRIBUTE_UNUSED,
6627 flagword *flagsp ATTRIBUTE_UNUSED,
6633 switch (sym->st_shndx)
6635 case SHN_X86_64_LCOMMON:
6636 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
6639 lcomm = bfd_make_section_with_flags (abfd,
6643 | SEC_LINKER_CREATED));
6646 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
6649 *valp = sym->st_size;
6657 /* Given a BFD section, try to locate the corresponding ELF section
6661 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
6662 asection *sec, int *index_return)
6664 if (sec == &_bfd_elf_large_com_section)
6666 *index_return = SHN_X86_64_LCOMMON;
6672 /* Process a symbol. */
6675 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
6678 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
6680 switch (elfsym->internal_elf_sym.st_shndx)
6682 case SHN_X86_64_LCOMMON:
6683 asym->section = &_bfd_elf_large_com_section;
6684 asym->value = elfsym->internal_elf_sym.st_size;
6685 /* Common symbol doesn't set BSF_GLOBAL. */
6686 asym->flags &= ~BSF_GLOBAL;
6692 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
6694 return (sym->st_shndx == SHN_COMMON
6695 || sym->st_shndx == SHN_X86_64_LCOMMON);
6699 elf_x86_64_common_section_index (asection *sec)
6701 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6704 return SHN_X86_64_LCOMMON;
6708 elf_x86_64_common_section (asection *sec)
6710 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6711 return bfd_com_section_ptr;
6713 return &_bfd_elf_large_com_section;
6717 elf_x86_64_merge_symbol (struct elf_link_hash_entry *h,
6718 const Elf_Internal_Sym *sym,
6723 const asection *oldsec)
6725 /* A normal common symbol and a large common symbol result in a
6726 normal common symbol. We turn the large common symbol into a
6729 && h->root.type == bfd_link_hash_common
6731 && bfd_is_com_section (*psec)
6734 if (sym->st_shndx == SHN_COMMON
6735 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) != 0)
6737 h->root.u.c.p->section
6738 = bfd_make_section_old_way (oldbfd, "COMMON");
6739 h->root.u.c.p->section->flags = SEC_ALLOC;
6741 else if (sym->st_shndx == SHN_X86_64_LCOMMON
6742 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) == 0)
6743 *psec = bfd_com_section_ptr;
6750 elf_x86_64_additional_program_headers (bfd *abfd,
6751 struct bfd_link_info *info ATTRIBUTE_UNUSED)
6756 /* Check to see if we need a large readonly segment. */
6757 s = bfd_get_section_by_name (abfd, ".lrodata");
6758 if (s && (s->flags & SEC_LOAD))
6761 /* Check to see if we need a large data segment. Since .lbss sections
6762 is placed right after the .bss section, there should be no need for
6763 a large data segment just because of .lbss. */
6764 s = bfd_get_section_by_name (abfd, ".ldata");
6765 if (s && (s->flags & SEC_LOAD))
6771 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6774 elf_x86_64_hash_symbol (struct elf_link_hash_entry *h)
6776 if (h->plt.offset != (bfd_vma) -1
6778 && !h->pointer_equality_needed)
6781 return _bfd_elf_hash_symbol (h);
6784 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6787 elf_x86_64_relocs_compatible (const bfd_target *input,
6788 const bfd_target *output)
6790 return ((xvec_get_elf_backend_data (input)->s->elfclass
6791 == xvec_get_elf_backend_data (output)->s->elfclass)
6792 && _bfd_elf_relocs_compatible (input, output));
6795 /* Parse x86-64 GNU properties. */
6797 static enum elf_property_kind
6798 elf_x86_64_parse_gnu_properties (bfd *abfd, unsigned int type,
6799 bfd_byte *ptr, unsigned int datasz)
6805 case GNU_PROPERTY_X86_ISA_1_USED:
6806 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6810 ((type == GNU_PROPERTY_X86_ISA_1_USED
6811 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>\n")
6812 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>\n")),
6814 return property_corrupt;
6816 prop = _bfd_elf_get_property (abfd, type, datasz);
6817 prop->u.number = bfd_h_get_32 (abfd, ptr);
6818 prop->pr_kind = property_number;
6822 return property_ignored;
6825 return property_number;
6828 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
6829 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6830 should be merged with ABFD. */
6833 elf_x86_64_merge_gnu_properties (bfd *abfd ATTRIBUTE_UNUSED,
6834 elf_property *aprop,
6835 elf_property *bprop)
6837 unsigned int number;
6838 bfd_boolean updated = FALSE;
6839 unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
6843 case GNU_PROPERTY_X86_ISA_1_USED:
6844 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6845 if (aprop != NULL && bprop != NULL)
6847 number = aprop->u.number;
6848 aprop->u.number = number | bprop->u.number;
6849 updated = number != (unsigned int) aprop->u.number;
6853 /* Return TRUE if APROP is NULL to indicate that BPROP should
6854 be added to ABFD. */
6855 updated = aprop == NULL;
6860 /* Never should happen. */
6867 static const struct bfd_elf_special_section
6868 elf_x86_64_special_sections[]=
6870 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6871 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6872 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
6873 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6874 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6875 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6876 { NULL, 0, 0, 0, 0 }
6879 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6880 #define TARGET_LITTLE_NAME "elf64-x86-64"
6881 #define ELF_ARCH bfd_arch_i386
6882 #define ELF_TARGET_ID X86_64_ELF_DATA
6883 #define ELF_MACHINE_CODE EM_X86_64
6884 #define ELF_MAXPAGESIZE 0x200000
6885 #define ELF_MINPAGESIZE 0x1000
6886 #define ELF_COMMONPAGESIZE 0x1000
6888 #define elf_backend_can_gc_sections 1
6889 #define elf_backend_can_refcount 1
6890 #define elf_backend_want_got_plt 1
6891 #define elf_backend_plt_readonly 1
6892 #define elf_backend_want_plt_sym 0
6893 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6894 #define elf_backend_rela_normal 1
6895 #define elf_backend_plt_alignment 4
6896 #define elf_backend_extern_protected_data 1
6897 #define elf_backend_caches_rawsize 1
6899 #define elf_info_to_howto elf_x86_64_info_to_howto
6901 #define bfd_elf64_bfd_link_hash_table_create \
6902 elf_x86_64_link_hash_table_create
6903 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
6904 #define bfd_elf64_bfd_reloc_name_lookup \
6905 elf_x86_64_reloc_name_lookup
6907 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
6908 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
6909 #define elf_backend_check_relocs elf_x86_64_check_relocs
6910 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
6911 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
6912 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
6913 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
6914 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
6915 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
6916 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
6917 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
6919 #define elf_backend_write_core_note elf_x86_64_write_core_note
6921 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
6922 #define elf_backend_relocate_section elf_x86_64_relocate_section
6923 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
6924 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
6925 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
6926 #define elf_backend_object_p elf64_x86_64_elf_object_p
6927 #define bfd_elf64_mkobject elf_x86_64_mkobject
6928 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
6930 #define elf_backend_section_from_shdr \
6931 elf_x86_64_section_from_shdr
6933 #define elf_backend_section_from_bfd_section \
6934 elf_x86_64_elf_section_from_bfd_section
6935 #define elf_backend_add_symbol_hook \
6936 elf_x86_64_add_symbol_hook
6937 #define elf_backend_symbol_processing \
6938 elf_x86_64_symbol_processing
6939 #define elf_backend_common_section_index \
6940 elf_x86_64_common_section_index
6941 #define elf_backend_common_section \
6942 elf_x86_64_common_section
6943 #define elf_backend_common_definition \
6944 elf_x86_64_common_definition
6945 #define elf_backend_merge_symbol \
6946 elf_x86_64_merge_symbol
6947 #define elf_backend_special_sections \
6948 elf_x86_64_special_sections
6949 #define elf_backend_additional_program_headers \
6950 elf_x86_64_additional_program_headers
6951 #define elf_backend_hash_symbol \
6952 elf_x86_64_hash_symbol
6953 #define elf_backend_omit_section_dynsym \
6954 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
6955 #define elf_backend_fixup_symbol \
6956 elf_x86_64_fixup_symbol
6957 #define elf_backend_parse_gnu_properties \
6958 elf_x86_64_parse_gnu_properties
6959 #define elf_backend_merge_gnu_properties \
6960 elf_x86_64_merge_gnu_properties
6962 #include "elf64-target.h"
6964 /* CloudABI support. */
6966 #undef TARGET_LITTLE_SYM
6967 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
6968 #undef TARGET_LITTLE_NAME
6969 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
6972 #define ELF_OSABI ELFOSABI_CLOUDABI
6975 #define elf64_bed elf64_x86_64_cloudabi_bed
6977 #include "elf64-target.h"
6979 /* FreeBSD support. */
6981 #undef TARGET_LITTLE_SYM
6982 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
6983 #undef TARGET_LITTLE_NAME
6984 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
6987 #define ELF_OSABI ELFOSABI_FREEBSD
6990 #define elf64_bed elf64_x86_64_fbsd_bed
6992 #include "elf64-target.h"
6994 /* Solaris 2 support. */
6996 #undef TARGET_LITTLE_SYM
6997 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
6998 #undef TARGET_LITTLE_NAME
6999 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7001 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7002 objects won't be recognized. */
7006 #define elf64_bed elf64_x86_64_sol2_bed
7008 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7010 #undef elf_backend_static_tls_alignment
7011 #define elf_backend_static_tls_alignment 16
7013 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7015 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7017 #undef elf_backend_want_plt_sym
7018 #define elf_backend_want_plt_sym 1
7020 #undef elf_backend_strtab_flags
7021 #define elf_backend_strtab_flags SHF_STRINGS
7024 elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
7025 bfd *obfd ATTRIBUTE_UNUSED,
7026 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
7027 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
7029 /* PR 19938: FIXME: Need to add code for setting the sh_info
7030 and sh_link fields of Solaris specific section types. */
7034 #undef elf_backend_copy_special_section_fields
7035 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7037 #include "elf64-target.h"
7039 /* Native Client support. */
7042 elf64_x86_64_nacl_elf_object_p (bfd *abfd)
7044 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7045 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64_nacl);
7049 #undef TARGET_LITTLE_SYM
7050 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7051 #undef TARGET_LITTLE_NAME
7052 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7054 #define elf64_bed elf64_x86_64_nacl_bed
7056 #undef ELF_MAXPAGESIZE
7057 #undef ELF_MINPAGESIZE
7058 #undef ELF_COMMONPAGESIZE
7059 #define ELF_MAXPAGESIZE 0x10000
7060 #define ELF_MINPAGESIZE 0x10000
7061 #define ELF_COMMONPAGESIZE 0x10000
7063 /* Restore defaults. */
7065 #undef elf_backend_static_tls_alignment
7066 #undef elf_backend_want_plt_sym
7067 #define elf_backend_want_plt_sym 0
7068 #undef elf_backend_strtab_flags
7069 #undef elf_backend_copy_special_section_fields
7071 /* NaCl uses substantially different PLT entries for the same effects. */
7073 #undef elf_backend_plt_alignment
7074 #define elf_backend_plt_alignment 5
7075 #define NACL_PLT_ENTRY_SIZE 64
7076 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7078 static const bfd_byte elf_x86_64_nacl_plt0_entry[NACL_PLT_ENTRY_SIZE] =
7080 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7081 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7082 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7083 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7084 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7086 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7087 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7089 /* 32 bytes of nop to pad out to the standard size. */
7090 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7091 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7092 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7093 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7094 0x66, /* excess data16 prefix */
7098 static const bfd_byte elf_x86_64_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
7100 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7101 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7102 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7103 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7105 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7106 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7107 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7109 /* Lazy GOT entries point here (32-byte aligned). */
7110 0x68, /* pushq immediate */
7111 0, 0, 0, 0, /* replaced with index into relocation table. */
7112 0xe9, /* jmp relative */
7113 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7115 /* 22 bytes of nop to pad out to the standard size. */
7116 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7117 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7118 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7121 /* .eh_frame covering the .plt section. */
7123 static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] =
7125 #if (PLT_CIE_LENGTH != 20 \
7126 || PLT_FDE_LENGTH != 36 \
7127 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7128 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7129 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7131 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
7132 0, 0, 0, 0, /* CIE ID */
7133 1, /* CIE version */
7134 'z', 'R', 0, /* Augmentation string */
7135 1, /* Code alignment factor */
7136 0x78, /* Data alignment factor */
7137 16, /* Return address column */
7138 1, /* Augmentation size */
7139 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
7140 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7141 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7142 DW_CFA_nop, DW_CFA_nop,
7144 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
7145 PLT_CIE_LENGTH + 8, 0, 0, 0,/* CIE pointer */
7146 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7147 0, 0, 0, 0, /* .plt size goes here */
7148 0, /* Augmentation size */
7149 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
7150 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7151 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
7152 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7153 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
7154 13, /* Block length */
7155 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
7156 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
7157 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
7158 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
7159 DW_CFA_nop, DW_CFA_nop
7162 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed =
7164 elf_x86_64_nacl_plt0_entry, /* plt0_entry */
7165 elf_x86_64_nacl_plt_entry, /* plt_entry */
7166 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
7167 2, /* plt0_got1_offset */
7168 9, /* plt0_got2_offset */
7169 13, /* plt0_got2_insn_end */
7170 3, /* plt_got_offset */
7171 33, /* plt_reloc_offset */
7172 38, /* plt_plt_offset */
7173 7, /* plt_got_insn_size */
7174 42, /* plt_plt_insn_end */
7175 32, /* plt_lazy_offset */
7176 elf_x86_64_nacl_eh_frame_plt, /* eh_frame_plt */
7177 sizeof (elf_x86_64_nacl_eh_frame_plt), /* eh_frame_plt_size */
7178 NULL, /* eh_frame_plt_got */
7179 0, /* eh_frame_plt_got_size */
7182 #undef elf_backend_arch_data
7183 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7185 #undef elf_backend_object_p
7186 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7187 #undef elf_backend_modify_segment_map
7188 #define elf_backend_modify_segment_map nacl_modify_segment_map
7189 #undef elf_backend_modify_program_headers
7190 #define elf_backend_modify_program_headers nacl_modify_program_headers
7191 #undef elf_backend_final_write_processing
7192 #define elf_backend_final_write_processing nacl_final_write_processing
7194 #include "elf64-target.h"
7196 /* Native Client x32 support. */
7199 elf32_x86_64_nacl_elf_object_p (bfd *abfd)
7201 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7202 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32_nacl);
7206 #undef TARGET_LITTLE_SYM
7207 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7208 #undef TARGET_LITTLE_NAME
7209 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7211 #define elf32_bed elf32_x86_64_nacl_bed
7213 #define bfd_elf32_bfd_link_hash_table_create \
7214 elf_x86_64_link_hash_table_create
7215 #define bfd_elf32_bfd_reloc_type_lookup \
7216 elf_x86_64_reloc_type_lookup
7217 #define bfd_elf32_bfd_reloc_name_lookup \
7218 elf_x86_64_reloc_name_lookup
7219 #define bfd_elf32_mkobject \
7221 #define bfd_elf32_get_synthetic_symtab \
7222 elf_x86_64_get_synthetic_symtab
7224 #undef elf_backend_object_p
7225 #define elf_backend_object_p \
7226 elf32_x86_64_nacl_elf_object_p
7228 #undef elf_backend_bfd_from_remote_memory
7229 #define elf_backend_bfd_from_remote_memory \
7230 _bfd_elf32_bfd_from_remote_memory
7232 #undef elf_backend_size_info
7233 #define elf_backend_size_info \
7234 _bfd_elf32_size_info
7236 #include "elf32-target.h"
7238 /* Restore defaults. */
7239 #undef elf_backend_object_p
7240 #define elf_backend_object_p elf64_x86_64_elf_object_p
7241 #undef elf_backend_bfd_from_remote_memory
7242 #undef elf_backend_size_info
7243 #undef elf_backend_modify_segment_map
7244 #undef elf_backend_modify_program_headers
7245 #undef elf_backend_final_write_processing
7247 /* Intel L1OM support. */
7250 elf64_l1om_elf_object_p (bfd *abfd)
7252 /* Set the right machine number for an L1OM elf64 file. */
7253 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
7257 #undef TARGET_LITTLE_SYM
7258 #define TARGET_LITTLE_SYM l1om_elf64_vec
7259 #undef TARGET_LITTLE_NAME
7260 #define TARGET_LITTLE_NAME "elf64-l1om"
7262 #define ELF_ARCH bfd_arch_l1om
7264 #undef ELF_MACHINE_CODE
7265 #define ELF_MACHINE_CODE EM_L1OM
7270 #define elf64_bed elf64_l1om_bed
7272 #undef elf_backend_object_p
7273 #define elf_backend_object_p elf64_l1om_elf_object_p
7275 /* Restore defaults. */
7276 #undef ELF_MAXPAGESIZE
7277 #undef ELF_MINPAGESIZE
7278 #undef ELF_COMMONPAGESIZE
7279 #define ELF_MAXPAGESIZE 0x200000
7280 #define ELF_MINPAGESIZE 0x1000
7281 #define ELF_COMMONPAGESIZE 0x1000
7282 #undef elf_backend_plt_alignment
7283 #define elf_backend_plt_alignment 4
7284 #undef elf_backend_arch_data
7285 #define elf_backend_arch_data &elf_x86_64_arch_bed
7287 #include "elf64-target.h"
7289 /* FreeBSD L1OM support. */
7291 #undef TARGET_LITTLE_SYM
7292 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7293 #undef TARGET_LITTLE_NAME
7294 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7297 #define ELF_OSABI ELFOSABI_FREEBSD
7300 #define elf64_bed elf64_l1om_fbsd_bed
7302 #include "elf64-target.h"
7304 /* Intel K1OM support. */
7307 elf64_k1om_elf_object_p (bfd *abfd)
7309 /* Set the right machine number for an K1OM elf64 file. */
7310 bfd_default_set_arch_mach (abfd, bfd_arch_k1om, bfd_mach_k1om);
7314 #undef TARGET_LITTLE_SYM
7315 #define TARGET_LITTLE_SYM k1om_elf64_vec
7316 #undef TARGET_LITTLE_NAME
7317 #define TARGET_LITTLE_NAME "elf64-k1om"
7319 #define ELF_ARCH bfd_arch_k1om
7321 #undef ELF_MACHINE_CODE
7322 #define ELF_MACHINE_CODE EM_K1OM
7327 #define elf64_bed elf64_k1om_bed
7329 #undef elf_backend_object_p
7330 #define elf_backend_object_p elf64_k1om_elf_object_p
7332 #undef elf_backend_static_tls_alignment
7334 #undef elf_backend_want_plt_sym
7335 #define elf_backend_want_plt_sym 0
7337 #include "elf64-target.h"
7339 /* FreeBSD K1OM support. */
7341 #undef TARGET_LITTLE_SYM
7342 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7343 #undef TARGET_LITTLE_NAME
7344 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7347 #define ELF_OSABI ELFOSABI_FREEBSD
7350 #define elf64_bed elf64_k1om_fbsd_bed
7352 #include "elf64-target.h"
7354 /* 32bit x86-64 support. */
7356 #undef TARGET_LITTLE_SYM
7357 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7358 #undef TARGET_LITTLE_NAME
7359 #define TARGET_LITTLE_NAME "elf32-x86-64"
7363 #define ELF_ARCH bfd_arch_i386
7365 #undef ELF_MACHINE_CODE
7366 #define ELF_MACHINE_CODE EM_X86_64
7370 #undef elf_backend_object_p
7371 #define elf_backend_object_p \
7372 elf32_x86_64_elf_object_p
7374 #undef elf_backend_bfd_from_remote_memory
7375 #define elf_backend_bfd_from_remote_memory \
7376 _bfd_elf32_bfd_from_remote_memory
7378 #undef elf_backend_size_info
7379 #define elf_backend_size_info \
7380 _bfd_elf32_size_info
7382 #include "elf32-target.h"