1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2017 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 /* xgettext:c-format */
289 _bfd_error_handler (_("%B: invalid relocation type %d"),
291 r_type = R_X86_64_NONE;
296 i = r_type - (unsigned int) R_X86_64_vt_offset;
297 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
298 return &x86_64_elf_howto_table[i];
301 /* Given a BFD reloc type, return a HOWTO structure. */
302 static reloc_howto_type *
303 elf_x86_64_reloc_type_lookup (bfd *abfd,
304 bfd_reloc_code_real_type code)
308 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
311 if (x86_64_reloc_map[i].bfd_reloc_val == code)
312 return elf_x86_64_rtype_to_howto (abfd,
313 x86_64_reloc_map[i].elf_reloc_val);
318 static reloc_howto_type *
319 elf_x86_64_reloc_name_lookup (bfd *abfd,
324 if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
326 /* Get x32 R_X86_64_32. */
327 reloc_howto_type *reloc
328 = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
329 BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
333 for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
334 if (x86_64_elf_howto_table[i].name != NULL
335 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
336 return &x86_64_elf_howto_table[i];
341 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
344 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
345 Elf_Internal_Rela *dst)
349 r_type = ELF32_R_TYPE (dst->r_info);
350 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
351 BFD_ASSERT (r_type == cache_ptr->howto->type);
354 /* Support for core dump NOTE sections. */
356 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
361 switch (note->descsz)
366 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
368 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
371 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
379 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
381 elf_tdata (abfd)->core->signal
382 = bfd_get_16 (abfd, note->descdata + 12);
385 elf_tdata (abfd)->core->lwpid
386 = bfd_get_32 (abfd, note->descdata + 32);
395 /* Make a ".reg/999" section. */
396 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
397 size, note->descpos + offset);
401 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
403 switch (note->descsz)
408 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
409 elf_tdata (abfd)->core->pid
410 = bfd_get_32 (abfd, note->descdata + 12);
411 elf_tdata (abfd)->core->program
412 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
413 elf_tdata (abfd)->core->command
414 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
417 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
418 elf_tdata (abfd)->core->pid
419 = bfd_get_32 (abfd, note->descdata + 24);
420 elf_tdata (abfd)->core->program
421 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
422 elf_tdata (abfd)->core->command
423 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
426 /* Note that for some reason, a spurious space is tacked
427 onto the end of the args in some (at least one anyway)
428 implementations, so strip it off if it exists. */
431 char *command = elf_tdata (abfd)->core->command;
432 int n = strlen (command);
434 if (0 < n && command[n - 1] == ' ')
435 command[n - 1] = '\0';
443 elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz,
446 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
448 const char *fname, *psargs;
459 va_start (ap, note_type);
460 fname = va_arg (ap, const char *);
461 psargs = va_arg (ap, const char *);
464 if (bed->s->elfclass == ELFCLASS32)
467 memset (&data, 0, sizeof (data));
468 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
469 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
470 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
471 &data, sizeof (data));
476 memset (&data, 0, sizeof (data));
477 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
478 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
479 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
480 &data, sizeof (data));
485 va_start (ap, note_type);
486 pid = va_arg (ap, long);
487 cursig = va_arg (ap, int);
488 gregs = va_arg (ap, const void *);
491 if (bed->s->elfclass == ELFCLASS32)
493 if (bed->elf_machine_code == EM_X86_64)
495 prstatusx32_t prstat;
496 memset (&prstat, 0, sizeof (prstat));
498 prstat.pr_cursig = cursig;
499 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
500 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
501 &prstat, sizeof (prstat));
506 memset (&prstat, 0, sizeof (prstat));
508 prstat.pr_cursig = cursig;
509 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
510 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
511 &prstat, sizeof (prstat));
517 memset (&prstat, 0, sizeof (prstat));
519 prstat.pr_cursig = cursig;
520 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
521 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
522 &prstat, sizeof (prstat));
529 /* Functions for the x86-64 ELF linker. */
531 /* The name of the dynamic interpreter. This is put in the .interp
534 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
535 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
537 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
538 copying dynamic variables from a shared lib into an app's dynbss
539 section, and instead use a dynamic relocation to point into the
541 #define ELIMINATE_COPY_RELOCS 1
543 /* The size in bytes of an entry in the global offset table. */
545 #define GOT_ENTRY_SIZE 8
547 /* The size in bytes of an entry in the procedure linkage table. */
549 #define PLT_ENTRY_SIZE 16
551 /* The first entry in a procedure linkage table looks like this. See the
552 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
554 static const bfd_byte elf_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
556 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
557 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
558 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
561 /* Subsequent entries in a procedure linkage table look like this. */
563 static const bfd_byte elf_x86_64_plt_entry[PLT_ENTRY_SIZE] =
565 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
566 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
567 0x68, /* pushq immediate */
568 0, 0, 0, 0, /* replaced with index into relocation table. */
569 0xe9, /* jmp relative */
570 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
573 /* The first entry in a procedure linkage table with BND relocations
576 static const bfd_byte elf_x86_64_bnd_plt0_entry[PLT_ENTRY_SIZE] =
578 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
579 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
580 0x0f, 0x1f, 0 /* nopl (%rax) */
583 /* Subsequent entries for legacy branches in a procedure linkage table
584 with BND relocations look like this. */
586 static const bfd_byte elf_x86_64_legacy_plt_entry[PLT_ENTRY_SIZE] =
588 0x68, 0, 0, 0, 0, /* pushq immediate */
589 0xe9, 0, 0, 0, 0, /* jmpq relative */
590 0x66, 0x0f, 0x1f, 0x44, 0, 0 /* nopw (%rax,%rax,1) */
593 /* Subsequent entries for branches with BND prefx in a procedure linkage
594 table with BND relocations look like this. */
596 static const bfd_byte elf_x86_64_bnd_plt_entry[PLT_ENTRY_SIZE] =
598 0x68, 0, 0, 0, 0, /* pushq immediate */
599 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
600 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
603 /* Entries for legacy branches in the second procedure linkage table
606 static const bfd_byte elf_x86_64_legacy_plt2_entry[8] =
608 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
609 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
610 0x66, 0x90 /* xchg %ax,%ax */
613 /* Entries for branches with BND prefix in the second procedure linkage
614 table look like this. */
616 static const bfd_byte elf_x86_64_bnd_plt2_entry[8] =
618 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
619 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
623 /* .eh_frame covering the .plt section. */
625 static const bfd_byte elf_x86_64_eh_frame_plt[] =
627 #define PLT_CIE_LENGTH 20
628 #define PLT_FDE_LENGTH 36
629 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
630 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
631 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
632 0, 0, 0, 0, /* CIE ID */
634 'z', 'R', 0, /* Augmentation string */
635 1, /* Code alignment factor */
636 0x78, /* Data alignment factor */
637 16, /* Return address column */
638 1, /* Augmentation size */
639 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
640 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
641 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
642 DW_CFA_nop, DW_CFA_nop,
644 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
645 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
646 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
647 0, 0, 0, 0, /* .plt size goes here */
648 0, /* Augmentation size */
649 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
650 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
651 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
652 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
653 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
654 11, /* Block length */
655 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
656 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
657 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
658 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
659 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
662 /* .eh_frame covering the BND .plt section. */
664 static const bfd_byte elf_x86_64_eh_frame_bnd_plt[] =
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_FDE_LENGTH, 0, 0, 0, /* FDE length */
680 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
681 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
682 0, 0, 0, 0, /* .plt size goes here */
683 0, /* Augmentation size */
684 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
685 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
686 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
687 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
688 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
689 11, /* Block length */
690 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
691 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
692 DW_OP_lit15, DW_OP_and, DW_OP_lit5, DW_OP_ge,
693 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
694 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
697 /* .eh_frame covering the .plt.got section. */
699 static const bfd_byte elf_x86_64_eh_frame_plt_got[] =
701 #define PLT_GOT_FDE_LENGTH 20
702 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
703 0, 0, 0, 0, /* CIE ID */
705 'z', 'R', 0, /* Augmentation string */
706 1, /* Code alignment factor */
707 0x78, /* Data alignment factor */
708 16, /* Return address column */
709 1, /* Augmentation size */
710 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
711 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
712 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
713 DW_CFA_nop, DW_CFA_nop,
715 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
716 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
717 0, 0, 0, 0, /* the start of .plt.got goes here */
718 0, 0, 0, 0, /* .plt.got size goes here */
719 0, /* Augmentation size */
720 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop,
721 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
724 /* Architecture-specific backend data for x86-64. */
726 struct elf_x86_64_backend_data
728 /* Templates for the initial PLT entry and for subsequent entries. */
729 const bfd_byte *plt0_entry;
730 const bfd_byte *plt_entry;
731 unsigned int plt_entry_size; /* Size of each PLT entry. */
733 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
734 unsigned int plt0_got1_offset;
735 unsigned int plt0_got2_offset;
737 /* Offset of the end of the PC-relative instruction containing
739 unsigned int plt0_got2_insn_end;
741 /* Offsets into plt_entry that are to be replaced with... */
742 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
743 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
744 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
746 /* Length of the PC-relative instruction containing plt_got_offset. */
747 unsigned int plt_got_insn_size;
749 /* Offset of the end of the PC-relative jump to plt0_entry. */
750 unsigned int plt_plt_insn_end;
752 /* Offset into plt_entry where the initial value of the GOT entry points. */
753 unsigned int plt_lazy_offset;
755 /* .eh_frame covering the .plt section. */
756 const bfd_byte *eh_frame_plt;
757 unsigned int eh_frame_plt_size;
759 /* .eh_frame covering the .plt.got section. */
760 const bfd_byte *eh_frame_plt_got;
761 unsigned int eh_frame_plt_got_size;
764 #define get_elf_x86_64_arch_data(bed) \
765 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
767 #define get_elf_x86_64_backend_data(abfd) \
768 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
770 #define GET_PLT_ENTRY_SIZE(abfd) \
771 get_elf_x86_64_backend_data (abfd)->plt_entry_size
773 /* These are the standard parameters. */
774 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
776 elf_x86_64_plt0_entry, /* plt0_entry */
777 elf_x86_64_plt_entry, /* plt_entry */
778 sizeof (elf_x86_64_plt_entry), /* plt_entry_size */
779 2, /* plt0_got1_offset */
780 8, /* plt0_got2_offset */
781 12, /* plt0_got2_insn_end */
782 2, /* plt_got_offset */
783 7, /* plt_reloc_offset */
784 12, /* plt_plt_offset */
785 6, /* plt_got_insn_size */
786 PLT_ENTRY_SIZE, /* plt_plt_insn_end */
787 6, /* plt_lazy_offset */
788 elf_x86_64_eh_frame_plt, /* eh_frame_plt */
789 sizeof (elf_x86_64_eh_frame_plt), /* eh_frame_plt_size */
790 elf_x86_64_eh_frame_plt_got, /* eh_frame_plt_got */
791 sizeof (elf_x86_64_eh_frame_plt_got), /* eh_frame_plt_got_size */
794 static const struct elf_x86_64_backend_data elf_x86_64_bnd_arch_bed =
796 elf_x86_64_bnd_plt0_entry, /* plt0_entry */
797 elf_x86_64_bnd_plt_entry, /* plt_entry */
798 sizeof (elf_x86_64_bnd_plt_entry), /* plt_entry_size */
799 2, /* plt0_got1_offset */
800 1+8, /* plt0_got2_offset */
801 1+12, /* plt0_got2_insn_end */
802 1+2, /* plt_got_offset */
803 1, /* plt_reloc_offset */
804 7, /* plt_plt_offset */
805 1+6, /* plt_got_insn_size */
806 11, /* plt_plt_insn_end */
807 0, /* plt_lazy_offset */
808 elf_x86_64_eh_frame_bnd_plt, /* eh_frame_plt */
809 sizeof (elf_x86_64_eh_frame_bnd_plt), /* eh_frame_plt_size */
810 elf_x86_64_eh_frame_plt_got, /* eh_frame_plt_got */
811 sizeof (elf_x86_64_eh_frame_plt_got), /* eh_frame_plt_got_size */
814 #define elf_backend_arch_data &elf_x86_64_arch_bed
816 /* Is a undefined weak symbol which is resolved to 0. Reference to an
817 undefined weak symbol is resolved to 0 when building executable if
819 1. Has non-GOT/non-PLT relocations in text section. Or
820 2. Has no GOT/PLT relocation.
822 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
823 ((EH)->elf.root.type == bfd_link_hash_undefweak \
824 && bfd_link_executable (INFO) \
825 && (elf_x86_64_hash_table (INFO)->interp == NULL \
827 || (EH)->has_non_got_reloc \
828 || !(INFO)->dynamic_undefined_weak))
830 /* x86-64 ELF linker hash entry. */
832 struct elf_x86_64_link_hash_entry
834 struct elf_link_hash_entry elf;
836 /* Track dynamic relocs copied for this symbol. */
837 struct elf_dyn_relocs *dyn_relocs;
839 #define GOT_UNKNOWN 0
843 #define GOT_TLS_GDESC 4
844 #define GOT_TLS_GD_BOTH_P(type) \
845 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
846 #define GOT_TLS_GD_P(type) \
847 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
848 #define GOT_TLS_GDESC_P(type) \
849 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
850 #define GOT_TLS_GD_ANY_P(type) \
851 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
852 unsigned char tls_type;
854 /* TRUE if a weak symbol with a real definition needs a copy reloc.
855 When there is a weak symbol with a real definition, the processor
856 independent code will have arranged for us to see the real
857 definition first. We need to copy the needs_copy bit from the
858 real definition and check it when allowing copy reloc in PIE. */
859 unsigned int needs_copy : 1;
861 /* TRUE if symbol has GOT or PLT relocations. */
862 unsigned int has_got_reloc : 1;
864 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
865 unsigned int has_non_got_reloc : 1;
867 /* Don't call finish_dynamic_symbol on this symbol. */
868 unsigned int no_finish_dynamic_symbol : 1;
870 /* 0: symbol isn't __tls_get_addr.
871 1: symbol is __tls_get_addr.
872 2: symbol is unknown. */
873 unsigned int tls_get_addr : 2;
875 /* Reference count of C/C++ function pointer relocations in read-write
876 section which can be resolved at run-time. */
877 bfd_signed_vma func_pointer_refcount;
879 /* Information about the GOT PLT entry. Filled when there are both
880 GOT and PLT relocations against the same function. */
881 union gotplt_union plt_got;
883 /* Information about the second PLT entry. Filled when info>bndplt is
885 union gotplt_union plt_bnd;
887 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
888 starting at the end of the jump table. */
892 #define elf_x86_64_hash_entry(ent) \
893 ((struct elf_x86_64_link_hash_entry *)(ent))
895 struct elf_x86_64_obj_tdata
897 struct elf_obj_tdata root;
899 /* tls_type for each local got entry. */
900 char *local_got_tls_type;
902 /* GOTPLT entries for TLS descriptors. */
903 bfd_vma *local_tlsdesc_gotent;
906 #define elf_x86_64_tdata(abfd) \
907 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
909 #define elf_x86_64_local_got_tls_type(abfd) \
910 (elf_x86_64_tdata (abfd)->local_got_tls_type)
912 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
913 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
915 #define is_x86_64_elf(bfd) \
916 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
917 && elf_tdata (bfd) != NULL \
918 && elf_object_id (bfd) == X86_64_ELF_DATA)
921 elf_x86_64_mkobject (bfd *abfd)
923 return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_64_obj_tdata),
927 /* x86-64 ELF linker hash table. */
929 struct elf_x86_64_link_hash_table
931 struct elf_link_hash_table elf;
933 /* Short-cuts to get to dynamic linker sections. */
935 asection *plt_eh_frame;
937 asection *plt_bnd_eh_frame;
939 asection *plt_got_eh_frame;
943 bfd_signed_vma refcount;
947 /* The amount of space used by the jump slots in the GOT. */
948 bfd_vma sgotplt_jump_table_size;
950 /* Small local sym cache. */
951 struct sym_cache sym_cache;
953 bfd_vma (*r_info) (bfd_vma, bfd_vma);
954 bfd_vma (*r_sym) (bfd_vma);
955 unsigned int pointer_r_type;
956 const char *dynamic_interpreter;
957 int dynamic_interpreter_size;
959 /* _TLS_MODULE_BASE_ symbol. */
960 struct bfd_link_hash_entry *tls_module_base;
962 /* Used by local STT_GNU_IFUNC symbols. */
963 htab_t loc_hash_table;
964 void * loc_hash_memory;
966 /* The offset into splt of the PLT entry for the TLS descriptor
967 resolver. Special values are 0, if not necessary (or not found
968 to be necessary yet), and -1 if needed but not determined
971 /* The offset into sgot of the GOT entry used by the PLT entry
975 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
976 bfd_vma next_jump_slot_index;
977 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
978 bfd_vma next_irelative_index;
980 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
981 to read-only sections. */
982 bfd_boolean readonly_dynrelocs_against_ifunc;
985 /* Get the x86-64 ELF linker hash table from a link_info structure. */
987 #define elf_x86_64_hash_table(p) \
988 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
989 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
991 #define elf_x86_64_compute_jump_table_size(htab) \
992 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
994 /* Create an entry in an x86-64 ELF linker hash table. */
996 static struct bfd_hash_entry *
997 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
998 struct bfd_hash_table *table,
1001 /* Allocate the structure if it has not already been allocated by a
1005 entry = (struct bfd_hash_entry *)
1006 bfd_hash_allocate (table,
1007 sizeof (struct elf_x86_64_link_hash_entry));
1012 /* Call the allocation method of the superclass. */
1013 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
1016 struct elf_x86_64_link_hash_entry *eh;
1018 eh = (struct elf_x86_64_link_hash_entry *) entry;
1019 eh->dyn_relocs = NULL;
1020 eh->tls_type = GOT_UNKNOWN;
1022 eh->has_got_reloc = 0;
1023 eh->has_non_got_reloc = 0;
1024 eh->no_finish_dynamic_symbol = 0;
1025 eh->tls_get_addr = 2;
1026 eh->func_pointer_refcount = 0;
1027 eh->plt_bnd.offset = (bfd_vma) -1;
1028 eh->plt_got.offset = (bfd_vma) -1;
1029 eh->tlsdesc_got = (bfd_vma) -1;
1035 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1036 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1037 as global symbol. We reuse indx and dynstr_index for local symbol
1038 hash since they aren't used by global symbols in this backend. */
1041 elf_x86_64_local_htab_hash (const void *ptr)
1043 struct elf_link_hash_entry *h
1044 = (struct elf_link_hash_entry *) ptr;
1045 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
1048 /* Compare local hash entries. */
1051 elf_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
1053 struct elf_link_hash_entry *h1
1054 = (struct elf_link_hash_entry *) ptr1;
1055 struct elf_link_hash_entry *h2
1056 = (struct elf_link_hash_entry *) ptr2;
1058 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
1061 /* Find and/or create a hash entry for local symbol. */
1063 static struct elf_link_hash_entry *
1064 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table *htab,
1065 bfd *abfd, const Elf_Internal_Rela *rel,
1068 struct elf_x86_64_link_hash_entry e, *ret;
1069 asection *sec = abfd->sections;
1070 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
1071 htab->r_sym (rel->r_info));
1074 e.elf.indx = sec->id;
1075 e.elf.dynstr_index = htab->r_sym (rel->r_info);
1076 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
1077 create ? INSERT : NO_INSERT);
1084 ret = (struct elf_x86_64_link_hash_entry *) *slot;
1088 ret = (struct elf_x86_64_link_hash_entry *)
1089 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
1090 sizeof (struct elf_x86_64_link_hash_entry));
1093 memset (ret, 0, sizeof (*ret));
1094 ret->elf.indx = sec->id;
1095 ret->elf.dynstr_index = htab->r_sym (rel->r_info);
1096 ret->elf.dynindx = -1;
1097 ret->func_pointer_refcount = 0;
1098 ret->plt_got.offset = (bfd_vma) -1;
1104 /* Destroy an X86-64 ELF linker hash table. */
1107 elf_x86_64_link_hash_table_free (bfd *obfd)
1109 struct elf_x86_64_link_hash_table *htab
1110 = (struct elf_x86_64_link_hash_table *) obfd->link.hash;
1112 if (htab->loc_hash_table)
1113 htab_delete (htab->loc_hash_table);
1114 if (htab->loc_hash_memory)
1115 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
1116 _bfd_elf_link_hash_table_free (obfd);
1119 /* Create an X86-64 ELF linker hash table. */
1121 static struct bfd_link_hash_table *
1122 elf_x86_64_link_hash_table_create (bfd *abfd)
1124 struct elf_x86_64_link_hash_table *ret;
1125 bfd_size_type amt = sizeof (struct elf_x86_64_link_hash_table);
1127 ret = (struct elf_x86_64_link_hash_table *) bfd_zmalloc (amt);
1131 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1132 elf_x86_64_link_hash_newfunc,
1133 sizeof (struct elf_x86_64_link_hash_entry),
1140 if (ABI_64_P (abfd))
1142 ret->r_info = elf64_r_info;
1143 ret->r_sym = elf64_r_sym;
1144 ret->pointer_r_type = R_X86_64_64;
1145 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
1146 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
1150 ret->r_info = elf32_r_info;
1151 ret->r_sym = elf32_r_sym;
1152 ret->pointer_r_type = R_X86_64_32;
1153 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
1154 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
1157 ret->loc_hash_table = htab_try_create (1024,
1158 elf_x86_64_local_htab_hash,
1159 elf_x86_64_local_htab_eq,
1161 ret->loc_hash_memory = objalloc_create ();
1162 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1164 elf_x86_64_link_hash_table_free (abfd);
1167 ret->elf.root.hash_table_free = elf_x86_64_link_hash_table_free;
1169 return &ret->elf.root;
1172 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1173 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1177 elf_x86_64_create_dynamic_sections (bfd *dynobj,
1178 struct bfd_link_info *info)
1180 struct elf_x86_64_link_hash_table *htab;
1182 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1185 htab = elf_x86_64_hash_table (info);
1189 /* Set the contents of the .interp section to the interpreter. */
1190 if (bfd_link_executable (info) && !info->nointerp)
1192 asection *s = bfd_get_linker_section (dynobj, ".interp");
1195 s->size = htab->dynamic_interpreter_size;
1196 s->contents = (unsigned char *) htab->dynamic_interpreter;
1200 if (htab->elf.splt != NULL)
1202 const struct elf_backend_data *bed
1203 = get_elf_backend_data (dynobj);
1204 flagword pltflags = (bed->dynamic_sec_flags
1210 if (htab->plt_got == NULL
1211 && get_elf_x86_64_backend_data (dynobj) == &elf_x86_64_arch_bed)
1213 /* Create the GOT procedure linkage table. */
1214 unsigned int plt_got_align;
1216 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry) == 8
1217 && (sizeof (elf_x86_64_bnd_plt2_entry)
1218 == sizeof (elf_x86_64_legacy_plt2_entry)));
1222 = bfd_make_section_anyway_with_flags (dynobj,
1225 if (htab->plt_got == NULL
1226 || !bfd_set_section_alignment (dynobj,
1232 /* MPX PLT is supported only if elf_x86_64_arch_bed is used in
1234 if (ABI_64_P (dynobj)
1236 && get_elf_x86_64_backend_data (dynobj) == &elf_x86_64_arch_bed
1237 && htab->plt_bnd == NULL)
1239 /* Create the second PLT for Intel MPX support. */
1240 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry) == 8
1241 && (sizeof (elf_x86_64_bnd_plt2_entry)
1242 == sizeof (elf_x86_64_legacy_plt2_entry)));
1245 = bfd_make_section_anyway_with_flags (dynobj,
1248 if (htab->plt_bnd == NULL
1249 || !bfd_set_section_alignment (dynobj, htab->plt_bnd, 3))
1253 if (!info->no_ld_generated_unwind_info)
1255 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
1256 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1257 | SEC_LINKER_CREATED);
1259 if (htab->plt_eh_frame == NULL)
1262 = bfd_make_section_anyway_with_flags (dynobj,
1265 if (htab->plt_eh_frame == NULL
1266 || !bfd_set_section_alignment (dynobj,
1268 ABI_64_P (dynobj) ? 3 : 2))
1272 if (htab->plt_got_eh_frame == NULL
1273 && htab->plt_got != NULL)
1275 htab->plt_got_eh_frame
1276 = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
1279 if (htab->plt_got_eh_frame == NULL
1280 || !bfd_set_section_alignment (dynobj,
1281 htab->plt_got_eh_frame,
1282 ABI_64_P (dynobj) ? 3 : 2))
1286 if (htab->plt_bnd_eh_frame == NULL
1287 && htab->plt_bnd != NULL)
1289 htab->plt_bnd_eh_frame
1290 = bfd_make_section_anyway_with_flags (dynobj,
1293 if (htab->plt_bnd_eh_frame == NULL
1294 || !bfd_set_section_alignment (dynobj,
1295 htab->plt_bnd_eh_frame,
1302 /* Align .got section to its entry size. */
1303 if (htab->elf.sgot != NULL
1304 && !bfd_set_section_alignment (dynobj, htab->elf.sgot, 3))
1307 /* Align .got.plt section to its entry size. */
1308 if (htab->elf.sgotplt != NULL
1309 && !bfd_set_section_alignment (dynobj, htab->elf.sgotplt, 3))
1315 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1318 elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
1319 struct elf_link_hash_entry *dir,
1320 struct elf_link_hash_entry *ind)
1322 struct elf_x86_64_link_hash_entry *edir, *eind;
1324 edir = (struct elf_x86_64_link_hash_entry *) dir;
1325 eind = (struct elf_x86_64_link_hash_entry *) ind;
1327 edir->has_got_reloc |= eind->has_got_reloc;
1328 edir->has_non_got_reloc |= eind->has_non_got_reloc;
1330 if (eind->dyn_relocs != NULL)
1332 if (edir->dyn_relocs != NULL)
1334 struct elf_dyn_relocs **pp;
1335 struct elf_dyn_relocs *p;
1337 /* Add reloc counts against the indirect sym to the direct sym
1338 list. Merge any entries against the same section. */
1339 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1341 struct elf_dyn_relocs *q;
1343 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1344 if (q->sec == p->sec)
1346 q->pc_count += p->pc_count;
1347 q->count += p->count;
1354 *pp = edir->dyn_relocs;
1357 edir->dyn_relocs = eind->dyn_relocs;
1358 eind->dyn_relocs = NULL;
1361 if (ind->root.type == bfd_link_hash_indirect
1362 && dir->got.refcount <= 0)
1364 edir->tls_type = eind->tls_type;
1365 eind->tls_type = GOT_UNKNOWN;
1368 if (ELIMINATE_COPY_RELOCS
1369 && ind->root.type != bfd_link_hash_indirect
1370 && dir->dynamic_adjusted)
1372 /* If called to transfer flags for a weakdef during processing
1373 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1374 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1375 if (dir->versioned != versioned_hidden)
1376 dir->ref_dynamic |= ind->ref_dynamic;
1377 dir->ref_regular |= ind->ref_regular;
1378 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1379 dir->needs_plt |= ind->needs_plt;
1380 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1384 if (eind->func_pointer_refcount > 0)
1386 edir->func_pointer_refcount += eind->func_pointer_refcount;
1387 eind->func_pointer_refcount = 0;
1390 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1395 elf64_x86_64_elf_object_p (bfd *abfd)
1397 /* Set the right machine number for an x86-64 elf64 file. */
1398 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
1403 elf32_x86_64_elf_object_p (bfd *abfd)
1405 /* Set the right machine number for an x86-64 elf32 file. */
1406 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
1410 /* Return TRUE if the TLS access code sequence support transition
1414 elf_x86_64_check_tls_transition (bfd *abfd,
1415 struct bfd_link_info *info,
1418 Elf_Internal_Shdr *symtab_hdr,
1419 struct elf_link_hash_entry **sym_hashes,
1420 unsigned int r_type,
1421 const Elf_Internal_Rela *rel,
1422 const Elf_Internal_Rela *relend)
1425 unsigned long r_symndx;
1426 bfd_boolean largepic = FALSE;
1427 struct elf_link_hash_entry *h;
1429 struct elf_x86_64_link_hash_table *htab;
1431 bfd_boolean indirect_call, tls_get_addr;
1433 htab = elf_x86_64_hash_table (info);
1434 offset = rel->r_offset;
1437 case R_X86_64_TLSGD:
1438 case R_X86_64_TLSLD:
1439 if ((rel + 1) >= relend)
1442 if (r_type == R_X86_64_TLSGD)
1444 /* Check transition from GD access model. For 64bit, only
1445 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1446 .word 0x6666; rex64; call __tls_get_addr@PLT
1448 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1450 call *__tls_get_addr@GOTPCREL(%rip)
1451 which may be converted to
1452 addr32 call __tls_get_addr
1453 can transit to different access model. For 32bit, only
1454 leaq foo@tlsgd(%rip), %rdi
1455 .word 0x6666; rex64; call __tls_get_addr@PLT
1457 leaq foo@tlsgd(%rip), %rdi
1459 call *__tls_get_addr@GOTPCREL(%rip)
1460 which may be converted to
1461 addr32 call __tls_get_addr
1462 can transit to different access model. For largepic,
1464 leaq foo@tlsgd(%rip), %rdi
1465 movabsq $__tls_get_addr@pltoff, %rax
1469 leaq foo@tlsgd(%rip), %rdi
1470 movabsq $__tls_get_addr@pltoff, %rax
1474 static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
1476 if ((offset + 12) > sec->size)
1479 call = contents + offset + 4;
1481 || !((call[1] == 0x48
1489 && call[3] == 0xe8)))
1491 if (!ABI_64_P (abfd)
1492 || (offset + 19) > sec->size
1494 || memcmp (call - 7, leaq + 1, 3) != 0
1495 || memcmp (call, "\x48\xb8", 2) != 0
1499 || !((call[10] == 0x48 && call[12] == 0xd8)
1500 || (call[10] == 0x4c && call[12] == 0xf8)))
1504 else if (ABI_64_P (abfd))
1507 || memcmp (contents + offset - 4, leaq, 4) != 0)
1513 || memcmp (contents + offset - 3, leaq + 1, 3) != 0)
1516 indirect_call = call[2] == 0xff;
1520 /* Check transition from LD access model. Only
1521 leaq foo@tlsld(%rip), %rdi;
1522 call __tls_get_addr@PLT
1524 leaq foo@tlsld(%rip), %rdi;
1525 call *__tls_get_addr@GOTPCREL(%rip)
1526 which may be converted to
1527 addr32 call __tls_get_addr
1528 can transit to different access model. For largepic
1530 leaq foo@tlsld(%rip), %rdi
1531 movabsq $__tls_get_addr@pltoff, %rax
1535 leaq foo@tlsld(%rip), %rdi
1536 movabsq $__tls_get_addr@pltoff, %rax
1540 static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
1542 if (offset < 3 || (offset + 9) > sec->size)
1545 if (memcmp (contents + offset - 3, lea, 3) != 0)
1548 call = contents + offset + 4;
1549 if (!(call[0] == 0xe8
1550 || (call[0] == 0xff && call[1] == 0x15)
1551 || (call[0] == 0x67 && call[1] == 0xe8)))
1553 if (!ABI_64_P (abfd)
1554 || (offset + 19) > sec->size
1555 || memcmp (call, "\x48\xb8", 2) != 0
1559 || !((call[10] == 0x48 && call[12] == 0xd8)
1560 || (call[10] == 0x4c && call[12] == 0xf8)))
1564 indirect_call = call[0] == 0xff;
1567 r_symndx = htab->r_sym (rel[1].r_info);
1568 if (r_symndx < symtab_hdr->sh_info)
1571 tls_get_addr = FALSE;
1572 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1573 if (h != NULL && h->root.root.string != NULL)
1575 struct elf_x86_64_link_hash_entry *eh
1576 = (struct elf_x86_64_link_hash_entry *) h;
1577 tls_get_addr = eh->tls_get_addr == 1;
1578 if (eh->tls_get_addr > 1)
1580 /* Use strncmp to check __tls_get_addr since
1581 __tls_get_addr may be versioned. */
1582 if (strncmp (h->root.root.string, "__tls_get_addr", 14)
1585 eh->tls_get_addr = 1;
1586 tls_get_addr = TRUE;
1589 eh->tls_get_addr = 0;
1596 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLTOFF64;
1597 else if (indirect_call)
1598 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_GOTPCRELX;
1600 return (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
1601 || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
1603 case R_X86_64_GOTTPOFF:
1604 /* Check transition from IE access model:
1605 mov foo@gottpoff(%rip), %reg
1606 add foo@gottpoff(%rip), %reg
1609 /* Check REX prefix first. */
1610 if (offset >= 3 && (offset + 4) <= sec->size)
1612 val = bfd_get_8 (abfd, contents + offset - 3);
1613 if (val != 0x48 && val != 0x4c)
1615 /* X32 may have 0x44 REX prefix or no REX prefix. */
1616 if (ABI_64_P (abfd))
1622 /* X32 may not have any REX prefix. */
1623 if (ABI_64_P (abfd))
1625 if (offset < 2 || (offset + 3) > sec->size)
1629 val = bfd_get_8 (abfd, contents + offset - 2);
1630 if (val != 0x8b && val != 0x03)
1633 val = bfd_get_8 (abfd, contents + offset - 1);
1634 return (val & 0xc7) == 5;
1636 case R_X86_64_GOTPC32_TLSDESC:
1637 /* Check transition from GDesc access model:
1638 leaq x@tlsdesc(%rip), %rax
1640 Make sure it's a leaq adding rip to a 32-bit offset
1641 into any register, although it's probably almost always
1644 if (offset < 3 || (offset + 4) > sec->size)
1647 val = bfd_get_8 (abfd, contents + offset - 3);
1648 if ((val & 0xfb) != 0x48)
1651 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1654 val = bfd_get_8 (abfd, contents + offset - 1);
1655 return (val & 0xc7) == 0x05;
1657 case R_X86_64_TLSDESC_CALL:
1658 /* Check transition from GDesc access model:
1659 call *x@tlsdesc(%rax)
1661 if (offset + 2 <= sec->size)
1663 /* Make sure that it's a call *x@tlsdesc(%rax). */
1664 call = contents + offset;
1665 return call[0] == 0xff && call[1] == 0x10;
1675 /* Return TRUE if the TLS access transition is OK or no transition
1676 will be performed. Update R_TYPE if there is a transition. */
1679 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1680 asection *sec, bfd_byte *contents,
1681 Elf_Internal_Shdr *symtab_hdr,
1682 struct elf_link_hash_entry **sym_hashes,
1683 unsigned int *r_type, int tls_type,
1684 const Elf_Internal_Rela *rel,
1685 const Elf_Internal_Rela *relend,
1686 struct elf_link_hash_entry *h,
1687 unsigned long r_symndx,
1688 bfd_boolean from_relocate_section)
1690 unsigned int from_type = *r_type;
1691 unsigned int to_type = from_type;
1692 bfd_boolean check = TRUE;
1694 /* Skip TLS transition for functions. */
1696 && (h->type == STT_FUNC
1697 || h->type == STT_GNU_IFUNC))
1702 case R_X86_64_TLSGD:
1703 case R_X86_64_GOTPC32_TLSDESC:
1704 case R_X86_64_TLSDESC_CALL:
1705 case R_X86_64_GOTTPOFF:
1706 if (bfd_link_executable (info))
1709 to_type = R_X86_64_TPOFF32;
1711 to_type = R_X86_64_GOTTPOFF;
1714 /* When we are called from elf_x86_64_relocate_section, there may
1715 be additional transitions based on TLS_TYPE. */
1716 if (from_relocate_section)
1718 unsigned int new_to_type = to_type;
1720 if (bfd_link_executable (info)
1723 && tls_type == GOT_TLS_IE)
1724 new_to_type = R_X86_64_TPOFF32;
1726 if (to_type == R_X86_64_TLSGD
1727 || to_type == R_X86_64_GOTPC32_TLSDESC
1728 || to_type == R_X86_64_TLSDESC_CALL)
1730 if (tls_type == GOT_TLS_IE)
1731 new_to_type = R_X86_64_GOTTPOFF;
1734 /* We checked the transition before when we were called from
1735 elf_x86_64_check_relocs. We only want to check the new
1736 transition which hasn't been checked before. */
1737 check = new_to_type != to_type && from_type == to_type;
1738 to_type = new_to_type;
1743 case R_X86_64_TLSLD:
1744 if (bfd_link_executable (info))
1745 to_type = R_X86_64_TPOFF32;
1752 /* Return TRUE if there is no transition. */
1753 if (from_type == to_type)
1756 /* Check if the transition can be performed. */
1758 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1759 symtab_hdr, sym_hashes,
1760 from_type, rel, relend))
1762 reloc_howto_type *from, *to;
1765 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1766 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1769 name = h->root.root.string;
1772 struct elf_x86_64_link_hash_table *htab;
1774 htab = elf_x86_64_hash_table (info);
1779 Elf_Internal_Sym *isym;
1781 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1783 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1788 /* xgettext:c-format */
1789 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1790 "in section `%A' failed"),
1791 abfd, from->name, to->name, name,
1792 (unsigned long) rel->r_offset, sec);
1793 bfd_set_error (bfd_error_bad_value);
1801 /* Rename some of the generic section flags to better document how they
1803 #define need_convert_load sec_flg0
1804 #define check_relocs_failed sec_flg1
1807 elf_x86_64_need_pic (bfd *input_bfd, asection *sec,
1808 struct elf_link_hash_entry *h,
1809 Elf_Internal_Shdr *symtab_hdr,
1810 Elf_Internal_Sym *isym,
1811 reloc_howto_type *howto)
1814 const char *und = "";
1815 const char *pic = "";
1820 name = h->root.root.string;
1821 switch (ELF_ST_VISIBILITY (h->other))
1824 v = _("hidden symbol ");
1827 v = _("internal symbol ");
1830 v = _("protected symbol ");
1834 pic = _("; recompile with -fPIC");
1838 if (!h->def_regular && !h->def_dynamic)
1839 und = _("undefined ");
1843 name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
1844 pic = _("; recompile with -fPIC");
1847 /* xgettext:c-format */
1848 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1849 "not be used when making a shared object%s"),
1850 input_bfd, howto->name, und, v, name, pic);
1851 bfd_set_error (bfd_error_bad_value);
1852 sec->check_relocs_failed = 1;
1856 /* With the local symbol, foo, we convert
1857 mov foo@GOTPCREL(%rip), %reg
1861 call/jmp *foo@GOTPCREL(%rip)
1863 nop call foo/jmp foo nop
1864 When PIC is false, convert
1865 test %reg, foo@GOTPCREL(%rip)
1869 binop foo@GOTPCREL(%rip), %reg
1872 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1876 elf_x86_64_convert_load_reloc (bfd *abfd, asection *sec,
1878 Elf_Internal_Rela *irel,
1879 struct elf_link_hash_entry *h,
1880 bfd_boolean *converted,
1881 struct bfd_link_info *link_info)
1883 struct elf_x86_64_link_hash_table *htab;
1885 bfd_boolean require_reloc_pc32;
1887 bfd_boolean to_reloc_pc32;
1890 bfd_signed_vma raddend;
1891 unsigned int opcode;
1893 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
1894 unsigned int r_symndx;
1896 bfd_vma roff = irel->r_offset;
1898 if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2))
1901 raddend = irel->r_addend;
1902 /* Addend for 32-bit PC-relative relocation must be -4. */
1906 htab = elf_x86_64_hash_table (link_info);
1907 is_pic = bfd_link_pic (link_info);
1909 relocx = (r_type == R_X86_64_GOTPCRELX
1910 || r_type == R_X86_64_REX_GOTPCRELX);
1912 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1915 = link_info->disable_target_specific_optimizations > 1;
1917 r_symndx = htab->r_sym (irel->r_info);
1919 opcode = bfd_get_8 (abfd, contents + roff - 2);
1921 /* Convert mov to lea since it has been done for a while. */
1924 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1925 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1926 test, xor instructions. */
1931 /* We convert only to R_X86_64_PC32:
1933 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1934 3. require_reloc_pc32 is true.
1937 to_reloc_pc32 = (opcode == 0xff
1939 || require_reloc_pc32
1942 /* Get the symbol referred to by the reloc. */
1945 Elf_Internal_Sym *isym
1946 = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
1948 /* Skip relocation against undefined symbols. */
1949 if (isym->st_shndx == SHN_UNDEF)
1952 symtype = ELF_ST_TYPE (isym->st_info);
1954 if (isym->st_shndx == SHN_ABS)
1955 tsec = bfd_abs_section_ptr;
1956 else if (isym->st_shndx == SHN_COMMON)
1957 tsec = bfd_com_section_ptr;
1958 else if (isym->st_shndx == SHN_X86_64_LCOMMON)
1959 tsec = &_bfd_elf_large_com_section;
1961 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1963 toff = isym->st_value;
1967 /* Undefined weak symbol is only bound locally in executable
1968 and its reference is resolved as 0 without relocation
1969 overflow. We can only perform this optimization for
1970 GOTPCRELX relocations since we need to modify REX byte.
1971 It is OK convert mov with R_X86_64_GOTPCREL to
1973 if ((relocx || opcode == 0x8b)
1974 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info,
1976 elf_x86_64_hash_entry (h)))
1980 /* Skip for branch instructions since R_X86_64_PC32
1982 if (require_reloc_pc32)
1987 /* For non-branch instructions, we can convert to
1988 R_X86_64_32/R_X86_64_32S since we know if there
1990 to_reloc_pc32 = FALSE;
1993 /* Since we don't know the current PC when PIC is true,
1994 we can't convert to R_X86_64_PC32. */
1995 if (to_reloc_pc32 && is_pic)
2000 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
2001 ld.so may use its link-time address. */
2002 else if ((h->def_regular
2003 || h->root.type == bfd_link_hash_defined
2004 || h->root.type == bfd_link_hash_defweak)
2005 && h != htab->elf.hdynamic
2006 && SYMBOL_REFERENCES_LOCAL (link_info, h))
2008 /* bfd_link_hash_new or bfd_link_hash_undefined is
2009 set by an assignment in a linker script in
2010 bfd_elf_record_link_assignment. */
2012 && (h->root.type == bfd_link_hash_new
2013 || h->root.type == bfd_link_hash_undefined
2014 || ((h->root.type == bfd_link_hash_defined
2015 || h->root.type == bfd_link_hash_defweak)
2016 && h->root.u.def.section == bfd_und_section_ptr)))
2018 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
2019 if (require_reloc_pc32)
2023 tsec = h->root.u.def.section;
2024 toff = h->root.u.def.value;
2031 /* Don't convert GOTPCREL relocation against large section. */
2032 if (elf_section_data (tsec) != NULL
2033 && (elf_section_flags (tsec) & SHF_X86_64_LARGE) != 0)
2036 /* We can only estimate relocation overflow for R_X86_64_PC32. */
2040 if (tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
2042 /* At this stage in linking, no SEC_MERGE symbol has been
2043 adjusted, so all references to such symbols need to be
2044 passed through _bfd_merged_section_offset. (Later, in
2045 relocate_section, all SEC_MERGE symbols *except* for
2046 section symbols have been adjusted.)
2048 gas may reduce relocations against symbols in SEC_MERGE
2049 sections to a relocation against the section symbol when
2050 the original addend was zero. When the reloc is against
2051 a section symbol we should include the addend in the
2052 offset passed to _bfd_merged_section_offset, since the
2053 location of interest is the original symbol. On the
2054 other hand, an access to "sym+addend" where "sym" is not
2055 a section symbol should not include the addend; Such an
2056 access is presumed to be an offset from "sym"; The
2057 location of interest is just "sym". */
2058 if (symtype == STT_SECTION)
2061 toff = _bfd_merged_section_offset (abfd, &tsec,
2062 elf_section_data (tsec)->sec_info,
2065 if (symtype != STT_SECTION)
2071 /* Don't convert if R_X86_64_PC32 relocation overflows. */
2072 if (tsec->output_section == sec->output_section)
2074 if ((toff - roff + 0x80000000) > 0xffffffff)
2079 bfd_signed_vma distance;
2081 /* At this point, we don't know the load addresses of TSEC
2082 section nor SEC section. We estimate the distrance between
2083 SEC and TSEC. We store the estimated distances in the
2084 compressed_size field of the output section, which is only
2085 used to decompress the compressed input section. */
2086 if (sec->output_section->compressed_size == 0)
2089 bfd_size_type size = 0;
2090 for (asect = link_info->output_bfd->sections;
2092 asect = asect->next)
2093 /* Skip debug sections since compressed_size is used to
2094 compress debug sections. */
2095 if ((asect->flags & SEC_DEBUGGING) == 0)
2098 for (i = asect->map_head.s;
2102 size = align_power (size, i->alignment_power);
2105 asect->compressed_size = size;
2109 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2111 distance = (tsec->output_section->compressed_size
2112 - sec->output_section->compressed_size);
2116 /* Take PT_GNU_RELRO segment into account by adding
2118 if ((toff + distance + get_elf_backend_data (abfd)->maxpagesize
2119 - roff + 0x80000000) > 0xffffffff)
2126 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2131 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2133 modrm = bfd_get_8 (abfd, contents + roff - 1);
2136 /* Convert to "jmp foo nop". */
2139 nop_offset = irel->r_offset + 3;
2140 disp = bfd_get_32 (abfd, contents + irel->r_offset);
2141 irel->r_offset -= 1;
2142 bfd_put_32 (abfd, disp, contents + irel->r_offset);
2146 struct elf_x86_64_link_hash_entry *eh
2147 = (struct elf_x86_64_link_hash_entry *) h;
2149 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2152 /* To support TLS optimization, always use addr32 prefix for
2153 "call *__tls_get_addr@GOTPCREL(%rip)". */
2154 if (eh && eh->tls_get_addr == 1)
2157 nop_offset = irel->r_offset - 2;
2161 nop = link_info->call_nop_byte;
2162 if (link_info->call_nop_as_suffix)
2164 nop_offset = irel->r_offset + 3;
2165 disp = bfd_get_32 (abfd, contents + irel->r_offset);
2166 irel->r_offset -= 1;
2167 bfd_put_32 (abfd, disp, contents + irel->r_offset);
2170 nop_offset = irel->r_offset - 2;
2173 bfd_put_8 (abfd, nop, contents + nop_offset);
2174 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
2175 r_type = R_X86_64_PC32;
2180 unsigned int rex_mask = REX_R;
2182 if (r_type == R_X86_64_REX_GOTPCRELX)
2183 rex = bfd_get_8 (abfd, contents + roff - 3);
2191 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2192 "lea foo(%rip), %reg". */
2194 r_type = R_X86_64_PC32;
2198 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2199 "mov $foo, %reg". */
2201 modrm = bfd_get_8 (abfd, contents + roff - 1);
2202 modrm = 0xc0 | (modrm & 0x38) >> 3;
2203 if ((rex & REX_W) != 0
2204 && ABI_64_P (link_info->output_bfd))
2206 /* Keep the REX_W bit in REX byte for LP64. */
2207 r_type = R_X86_64_32S;
2208 goto rewrite_modrm_rex;
2212 /* If the REX_W bit in REX byte isn't needed,
2213 use R_X86_64_32 and clear the W bit to avoid
2214 sign-extend imm32 to imm64. */
2215 r_type = R_X86_64_32;
2216 /* Clear the W bit in REX byte. */
2218 goto rewrite_modrm_rex;
2224 /* R_X86_64_PC32 isn't supported. */
2228 modrm = bfd_get_8 (abfd, contents + roff - 1);
2231 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2232 "test $foo, %reg". */
2233 modrm = 0xc0 | (modrm & 0x38) >> 3;
2238 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2239 "binop $foo, %reg". */
2240 modrm = 0xc0 | (modrm & 0x38) >> 3 | (opcode & 0x3c);
2244 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2245 overflow when sign-extending imm32 to imm64. */
2246 r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32;
2249 bfd_put_8 (abfd, modrm, contents + roff - 1);
2253 /* Move the R bit to the B bit in REX byte. */
2254 rex = (rex & ~rex_mask) | (rex & REX_R) >> 2;
2255 bfd_put_8 (abfd, rex, contents + roff - 3);
2258 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2262 bfd_put_8 (abfd, opcode, contents + roff - 2);
2265 irel->r_info = htab->r_info (r_symndx, r_type);
2272 /* Look through the relocs for a section during the first phase, and
2273 calculate needed space in the global offset table, procedure
2274 linkage table, and dynamic reloc sections. */
2277 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2279 const Elf_Internal_Rela *relocs)
2281 struct elf_x86_64_link_hash_table *htab;
2282 Elf_Internal_Shdr *symtab_hdr;
2283 struct elf_link_hash_entry **sym_hashes;
2284 const Elf_Internal_Rela *rel;
2285 const Elf_Internal_Rela *rel_end;
2289 if (bfd_link_relocatable (info))
2292 /* Don't do anything special with non-loaded, non-alloced sections.
2293 In particular, any relocs in such sections should not affect GOT
2294 and PLT reference counting (ie. we don't allow them to create GOT
2295 or PLT entries), there's no possibility or desire to optimize TLS
2296 relocs, and there's not much point in propagating relocs to shared
2297 libs that the dynamic linker won't relocate. */
2298 if ((sec->flags & SEC_ALLOC) == 0)
2301 BFD_ASSERT (is_x86_64_elf (abfd));
2303 htab = elf_x86_64_hash_table (info);
2306 sec->check_relocs_failed = 1;
2310 /* Get the section contents. */
2311 if (elf_section_data (sec)->this_hdr.contents != NULL)
2312 contents = elf_section_data (sec)->this_hdr.contents;
2313 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2315 sec->check_relocs_failed = 1;
2319 symtab_hdr = &elf_symtab_hdr (abfd);
2320 sym_hashes = elf_sym_hashes (abfd);
2324 rel_end = relocs + sec->reloc_count;
2325 for (rel = relocs; rel < rel_end; rel++)
2327 unsigned int r_type;
2328 unsigned long r_symndx;
2329 struct elf_link_hash_entry *h;
2330 struct elf_x86_64_link_hash_entry *eh;
2331 Elf_Internal_Sym *isym;
2333 bfd_boolean size_reloc;
2335 r_symndx = htab->r_sym (rel->r_info);
2336 r_type = ELF32_R_TYPE (rel->r_info);
2338 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
2340 /* xgettext:c-format */
2341 _bfd_error_handler (_("%B: bad symbol index: %d"),
2346 if (r_symndx < symtab_hdr->sh_info)
2348 /* A local symbol. */
2349 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2354 /* Check relocation against local STT_GNU_IFUNC symbol. */
2355 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
2357 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel,
2362 /* Fake a STT_GNU_IFUNC symbol. */
2363 h->type = STT_GNU_IFUNC;
2366 h->forced_local = 1;
2367 h->root.type = bfd_link_hash_defined;
2375 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2376 while (h->root.type == bfd_link_hash_indirect
2377 || h->root.type == bfd_link_hash_warning)
2378 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2381 /* Check invalid x32 relocations. */
2382 if (!ABI_64_P (abfd))
2388 case R_X86_64_DTPOFF64:
2389 case R_X86_64_TPOFF64:
2391 case R_X86_64_GOTOFF64:
2392 case R_X86_64_GOT64:
2393 case R_X86_64_GOTPCREL64:
2394 case R_X86_64_GOTPC64:
2395 case R_X86_64_GOTPLT64:
2396 case R_X86_64_PLTOFF64:
2399 name = h->root.root.string;
2401 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
2404 /* xgettext:c-format */
2405 (_("%B: relocation %s against symbol `%s' isn't "
2406 "supported in x32 mode"), abfd,
2407 x86_64_elf_howto_table[r_type].name, name);
2408 bfd_set_error (bfd_error_bad_value);
2421 case R_X86_64_PC32_BND:
2422 case R_X86_64_PLT32_BND:
2424 case R_X86_64_PLT32:
2429 case R_X86_64_GOTPCREL:
2430 case R_X86_64_GOTPCRELX:
2431 case R_X86_64_REX_GOTPCRELX:
2432 case R_X86_64_GOTPCREL64:
2433 if (htab->elf.dynobj == NULL)
2434 htab->elf.dynobj = abfd;
2435 /* Create the ifunc sections for static executables. */
2436 if (h->type == STT_GNU_IFUNC
2437 && !_bfd_elf_create_ifunc_sections (htab->elf.dynobj,
2443 /* It is referenced by a non-shared object. */
2445 h->root.non_ir_ref = 1;
2447 if (h->type == STT_GNU_IFUNC)
2448 elf_tdata (info->output_bfd)->has_gnu_symbols
2449 |= elf_gnu_symbol_ifunc;
2452 if (! elf_x86_64_tls_transition (info, abfd, sec, contents,
2453 symtab_hdr, sym_hashes,
2454 &r_type, GOT_UNKNOWN,
2455 rel, rel_end, h, r_symndx, FALSE))
2458 eh = (struct elf_x86_64_link_hash_entry *) h;
2461 case R_X86_64_TLSLD:
2462 htab->tls_ld_got.refcount += 1;
2465 case R_X86_64_TPOFF32:
2466 if (!bfd_link_executable (info) && ABI_64_P (abfd))
2467 return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
2468 &x86_64_elf_howto_table[r_type]);
2470 eh->has_got_reloc = 1;
2473 case R_X86_64_GOTTPOFF:
2474 if (!bfd_link_executable (info))
2475 info->flags |= DF_STATIC_TLS;
2478 case R_X86_64_GOT32:
2479 case R_X86_64_GOTPCREL:
2480 case R_X86_64_GOTPCRELX:
2481 case R_X86_64_REX_GOTPCRELX:
2482 case R_X86_64_TLSGD:
2483 case R_X86_64_GOT64:
2484 case R_X86_64_GOTPCREL64:
2485 case R_X86_64_GOTPLT64:
2486 case R_X86_64_GOTPC32_TLSDESC:
2487 case R_X86_64_TLSDESC_CALL:
2488 /* This symbol requires a global offset table entry. */
2490 int tls_type, old_tls_type;
2494 default: tls_type = GOT_NORMAL; break;
2495 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
2496 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
2497 case R_X86_64_GOTPC32_TLSDESC:
2498 case R_X86_64_TLSDESC_CALL:
2499 tls_type = GOT_TLS_GDESC; break;
2504 h->got.refcount += 1;
2505 old_tls_type = eh->tls_type;
2509 bfd_signed_vma *local_got_refcounts;
2511 /* This is a global offset table entry for a local symbol. */
2512 local_got_refcounts = elf_local_got_refcounts (abfd);
2513 if (local_got_refcounts == NULL)
2517 size = symtab_hdr->sh_info;
2518 size *= sizeof (bfd_signed_vma)
2519 + sizeof (bfd_vma) + sizeof (char);
2520 local_got_refcounts = ((bfd_signed_vma *)
2521 bfd_zalloc (abfd, size));
2522 if (local_got_refcounts == NULL)
2524 elf_local_got_refcounts (abfd) = local_got_refcounts;
2525 elf_x86_64_local_tlsdesc_gotent (abfd)
2526 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
2527 elf_x86_64_local_got_tls_type (abfd)
2528 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
2530 local_got_refcounts[r_symndx] += 1;
2532 = elf_x86_64_local_got_tls_type (abfd) [r_symndx];
2535 /* If a TLS symbol is accessed using IE at least once,
2536 there is no point to use dynamic model for it. */
2537 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
2538 && (! GOT_TLS_GD_ANY_P (old_tls_type)
2539 || tls_type != GOT_TLS_IE))
2541 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
2542 tls_type = old_tls_type;
2543 else if (GOT_TLS_GD_ANY_P (old_tls_type)
2544 && GOT_TLS_GD_ANY_P (tls_type))
2545 tls_type |= old_tls_type;
2549 name = h->root.root.string;
2551 name = bfd_elf_sym_name (abfd, symtab_hdr,
2554 /* xgettext:c-format */
2555 (_("%B: '%s' accessed both as normal and"
2556 " thread local symbol"),
2558 bfd_set_error (bfd_error_bad_value);
2563 if (old_tls_type != tls_type)
2566 eh->tls_type = tls_type;
2568 elf_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
2573 case R_X86_64_GOTOFF64:
2574 case R_X86_64_GOTPC32:
2575 case R_X86_64_GOTPC64:
2578 eh->has_got_reloc = 1;
2579 if (htab->elf.sgot == NULL)
2581 if (htab->elf.dynobj == NULL)
2582 htab->elf.dynobj = abfd;
2583 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
2589 case R_X86_64_PLT32:
2590 case R_X86_64_PLT32_BND:
2591 /* This symbol requires a procedure linkage table entry. We
2592 actually build the entry in adjust_dynamic_symbol,
2593 because this might be a case of linking PIC code which is
2594 never referenced by a dynamic object, in which case we
2595 don't need to generate a procedure linkage table entry
2598 /* If this is a local symbol, we resolve it directly without
2599 creating a procedure linkage table entry. */
2603 eh->has_got_reloc = 1;
2605 h->plt.refcount += 1;
2608 case R_X86_64_PLTOFF64:
2609 /* This tries to form the 'address' of a function relative
2610 to GOT. For global symbols we need a PLT entry. */
2614 h->plt.refcount += 1;
2618 case R_X86_64_SIZE32:
2619 case R_X86_64_SIZE64:
2624 if (!ABI_64_P (abfd))
2630 /* Check relocation overflow as these relocs may lead to
2631 run-time relocation overflow. Don't error out for
2632 sections we don't care about, such as debug sections or
2633 when relocation overflow check is disabled. */
2634 if (!info->no_reloc_overflow_check
2635 && (bfd_link_pic (info)
2636 || (bfd_link_executable (info)
2640 && (sec->flags & SEC_READONLY) == 0)))
2641 return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
2642 &x86_64_elf_howto_table[r_type]);
2648 case R_X86_64_PC32_BND:
2652 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
2653 eh->has_non_got_reloc = 1;
2654 /* We are called after all symbols have been resolved. Only
2655 relocation against STT_GNU_IFUNC symbol must go through
2658 && (bfd_link_executable (info)
2659 || h->type == STT_GNU_IFUNC))
2661 /* If this reloc is in a read-only section, we might
2662 need a copy reloc. We can't check reliably at this
2663 stage whether the section is read-only, as input
2664 sections have not yet been mapped to output sections.
2665 Tentatively set the flag for now, and correct in
2666 adjust_dynamic_symbol. */
2669 /* We may need a .plt entry if the symbol is a function
2670 defined in a shared lib or is a STT_GNU_IFUNC function
2671 referenced from the code or read-only section. */
2673 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
2674 h->plt.refcount += 1;
2676 if (r_type == R_X86_64_PC32)
2678 /* Since something like ".long foo - ." may be used
2679 as pointer, make sure that PLT is used if foo is
2680 a function defined in a shared library. */
2681 if ((sec->flags & SEC_CODE) == 0)
2682 h->pointer_equality_needed = 1;
2684 else if (r_type != R_X86_64_PC32_BND
2685 && r_type != R_X86_64_PC64)
2687 h->pointer_equality_needed = 1;
2688 /* At run-time, R_X86_64_64 can be resolved for both
2689 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2690 can only be resolved for x32. */
2691 if ((sec->flags & SEC_READONLY) == 0
2692 && (r_type == R_X86_64_64
2693 || (!ABI_64_P (abfd)
2694 && (r_type == R_X86_64_32
2695 || r_type == R_X86_64_32S))))
2696 eh->func_pointer_refcount += 1;
2702 /* If we are creating a shared library, and this is a reloc
2703 against a global symbol, or a non PC relative reloc
2704 against a local symbol, then we need to copy the reloc
2705 into the shared library. However, if we are linking with
2706 -Bsymbolic, we do not need to copy a reloc against a
2707 global symbol which is defined in an object we are
2708 including in the link (i.e., DEF_REGULAR is set). At
2709 this point we have not seen all the input files, so it is
2710 possible that DEF_REGULAR is not set now but will be set
2711 later (it is never cleared). In case of a weak definition,
2712 DEF_REGULAR may be cleared later by a strong definition in
2713 a shared library. We account for that possibility below by
2714 storing information in the relocs_copied field of the hash
2715 table entry. A similar situation occurs when creating
2716 shared libraries and symbol visibility changes render the
2719 If on the other hand, we are creating an executable, we
2720 may need to keep relocations for symbols satisfied by a
2721 dynamic library if we manage to avoid copy relocs for the
2724 Generate dynamic pointer relocation against STT_GNU_IFUNC
2725 symbol in the non-code section. */
2726 if ((bfd_link_pic (info)
2727 && (! IS_X86_64_PCREL_TYPE (r_type)
2729 && (! (bfd_link_pie (info)
2730 || SYMBOLIC_BIND (info, h))
2731 || h->root.type == bfd_link_hash_defweak
2732 || !h->def_regular))))
2734 && h->type == STT_GNU_IFUNC
2735 && r_type == htab->pointer_r_type
2736 && (sec->flags & SEC_CODE) == 0)
2737 || (ELIMINATE_COPY_RELOCS
2738 && !bfd_link_pic (info)
2740 && (h->root.type == bfd_link_hash_defweak
2741 || !h->def_regular)))
2743 struct elf_dyn_relocs *p;
2744 struct elf_dyn_relocs **head;
2746 /* We must copy these reloc types into the output file.
2747 Create a reloc section in dynobj and make room for
2751 if (htab->elf.dynobj == NULL)
2752 htab->elf.dynobj = abfd;
2754 sreloc = _bfd_elf_make_dynamic_reloc_section
2755 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
2756 abfd, /*rela?*/ TRUE);
2762 /* If this is a global symbol, we count the number of
2763 relocations we need for this symbol. */
2765 head = &eh->dyn_relocs;
2768 /* Track dynamic relocs needed for local syms too.
2769 We really need local syms available to do this
2774 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2779 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2783 /* Beware of type punned pointers vs strict aliasing
2785 vpp = &(elf_section_data (s)->local_dynrel);
2786 head = (struct elf_dyn_relocs **)vpp;
2790 if (p == NULL || p->sec != sec)
2792 bfd_size_type amt = sizeof *p;
2794 p = ((struct elf_dyn_relocs *)
2795 bfd_alloc (htab->elf.dynobj, amt));
2806 /* Count size relocation as PC-relative relocation. */
2807 if (IS_X86_64_PCREL_TYPE (r_type) || size_reloc)
2812 /* This relocation describes the C++ object vtable hierarchy.
2813 Reconstruct it for later use during GC. */
2814 case R_X86_64_GNU_VTINHERIT:
2815 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2819 /* This relocation describes which C++ vtable entries are actually
2820 used. Record for later use during GC. */
2821 case R_X86_64_GNU_VTENTRY:
2822 BFD_ASSERT (h != NULL);
2824 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2832 if ((r_type == R_X86_64_GOTPCREL
2833 || r_type == R_X86_64_GOTPCRELX
2834 || r_type == R_X86_64_REX_GOTPCRELX)
2835 && (h == NULL || h->type != STT_GNU_IFUNC))
2836 sec->need_convert_load = 1;
2839 if (elf_section_data (sec)->this_hdr.contents != contents)
2841 if (!info->keep_memory)
2845 /* Cache the section contents for elf_link_input_bfd. */
2846 elf_section_data (sec)->this_hdr.contents = contents;
2853 if (elf_section_data (sec)->this_hdr.contents != contents)
2855 sec->check_relocs_failed = 1;
2859 /* Return the section that should be marked against GC for a given
2863 elf_x86_64_gc_mark_hook (asection *sec,
2864 struct bfd_link_info *info,
2865 Elf_Internal_Rela *rel,
2866 struct elf_link_hash_entry *h,
2867 Elf_Internal_Sym *sym)
2870 switch (ELF32_R_TYPE (rel->r_info))
2872 case R_X86_64_GNU_VTINHERIT:
2873 case R_X86_64_GNU_VTENTRY:
2877 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2880 /* Remove undefined weak symbol from the dynamic symbol table if it
2881 is resolved to 0. */
2884 elf_x86_64_fixup_symbol (struct bfd_link_info *info,
2885 struct elf_link_hash_entry *h)
2887 if (h->dynindx != -1
2888 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2889 elf_x86_64_hash_entry (h)->has_got_reloc,
2890 elf_x86_64_hash_entry (h)))
2893 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
2899 /* Adjust a symbol defined by a dynamic object and referenced by a
2900 regular object. The current definition is in some section of the
2901 dynamic object, but we're not including those sections. We have to
2902 change the definition to something the rest of the link can
2906 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
2907 struct elf_link_hash_entry *h)
2909 struct elf_x86_64_link_hash_table *htab;
2911 struct elf_x86_64_link_hash_entry *eh;
2912 struct elf_dyn_relocs *p;
2914 /* STT_GNU_IFUNC symbol must go through PLT. */
2915 if (h->type == STT_GNU_IFUNC)
2917 /* All local STT_GNU_IFUNC references must be treate as local
2918 calls via local PLT. */
2920 && SYMBOL_CALLS_LOCAL (info, h))
2922 bfd_size_type pc_count = 0, count = 0;
2923 struct elf_dyn_relocs **pp;
2925 eh = (struct elf_x86_64_link_hash_entry *) h;
2926 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2928 pc_count += p->pc_count;
2929 p->count -= p->pc_count;
2938 if (pc_count || count)
2943 /* Increment PLT reference count only for PC-relative
2946 if (h->plt.refcount <= 0)
2947 h->plt.refcount = 1;
2949 h->plt.refcount += 1;
2954 if (h->plt.refcount <= 0)
2956 h->plt.offset = (bfd_vma) -1;
2962 /* If this is a function, put it in the procedure linkage table. We
2963 will fill in the contents of the procedure linkage table later,
2964 when we know the address of the .got section. */
2965 if (h->type == STT_FUNC
2968 if (h->plt.refcount <= 0
2969 || SYMBOL_CALLS_LOCAL (info, h)
2970 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2971 && h->root.type == bfd_link_hash_undefweak))
2973 /* This case can occur if we saw a PLT32 reloc in an input
2974 file, but the symbol was never referred to by a dynamic
2975 object, or if all references were garbage collected. In
2976 such a case, we don't actually need to build a procedure
2977 linkage table, and we can just do a PC32 reloc instead. */
2978 h->plt.offset = (bfd_vma) -1;
2985 /* It's possible that we incorrectly decided a .plt reloc was
2986 needed for an R_X86_64_PC32 reloc to a non-function sym in
2987 check_relocs. We can't decide accurately between function and
2988 non-function syms in check-relocs; Objects loaded later in
2989 the link may change h->type. So fix it now. */
2990 h->plt.offset = (bfd_vma) -1;
2992 /* If this is a weak symbol, and there is a real definition, the
2993 processor independent code will have arranged for us to see the
2994 real definition first, and we can just use the same value. */
2995 if (h->u.weakdef != NULL)
2997 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2998 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2999 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3000 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3001 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
3003 eh = (struct elf_x86_64_link_hash_entry *) h;
3004 h->non_got_ref = h->u.weakdef->non_got_ref;
3005 eh->needs_copy = h->u.weakdef->needs_copy;
3010 /* This is a reference to a symbol defined by a dynamic object which
3011 is not a function. */
3013 /* If we are creating a shared library, we must presume that the
3014 only references to the symbol are via the global offset table.
3015 For such cases we need not do anything here; the relocations will
3016 be handled correctly by relocate_section. */
3017 if (!bfd_link_executable (info))
3020 /* If there are no references to this symbol that do not use the
3021 GOT, we don't need to generate a copy reloc. */
3022 if (!h->non_got_ref)
3025 /* If -z nocopyreloc was given, we won't generate them either. */
3026 if (info->nocopyreloc)
3032 if (ELIMINATE_COPY_RELOCS)
3034 eh = (struct elf_x86_64_link_hash_entry *) h;
3035 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3037 s = p->sec->output_section;
3038 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3042 /* If we didn't find any dynamic relocs in read-only sections, then
3043 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3051 /* We must allocate the symbol in our .dynbss section, which will
3052 become part of the .bss section of the executable. There will be
3053 an entry for this symbol in the .dynsym section. The dynamic
3054 object will contain position independent code, so all references
3055 from the dynamic object to this symbol will go through the global
3056 offset table. The dynamic linker will use the .dynsym entry to
3057 determine the address it must put in the global offset table, so
3058 both the dynamic object and the regular object will refer to the
3059 same memory location for the variable. */
3061 htab = elf_x86_64_hash_table (info);
3065 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3066 to copy the initial value out of the dynamic object and into the
3067 runtime process image. */
3068 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
3070 s = htab->elf.sdynrelro;
3071 srel = htab->elf.sreldynrelro;
3075 s = htab->elf.sdynbss;
3076 srel = htab->elf.srelbss;
3078 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3080 const struct elf_backend_data *bed;
3081 bed = get_elf_backend_data (info->output_bfd);
3082 srel->size += bed->s->sizeof_rela;
3086 return _bfd_elf_adjust_dynamic_copy (info, h, s);
3089 /* Allocate space in .plt, .got and associated reloc sections for
3093 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
3095 struct bfd_link_info *info;
3096 struct elf_x86_64_link_hash_table *htab;
3097 struct elf_x86_64_link_hash_entry *eh;
3098 struct elf_dyn_relocs *p;
3099 const struct elf_backend_data *bed;
3100 unsigned int plt_entry_size;
3101 bfd_boolean resolved_to_zero;
3103 if (h->root.type == bfd_link_hash_indirect)
3106 eh = (struct elf_x86_64_link_hash_entry *) h;
3108 info = (struct bfd_link_info *) inf;
3109 htab = elf_x86_64_hash_table (info);
3112 bed = get_elf_backend_data (info->output_bfd);
3113 plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
3115 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
3119 /* We can't use the GOT PLT if pointer equality is needed since
3120 finish_dynamic_symbol won't clear symbol value and the dynamic
3121 linker won't update the GOT slot. We will get into an infinite
3122 loop at run-time. */
3123 if (htab->plt_got != NULL
3124 && h->type != STT_GNU_IFUNC
3125 && !h->pointer_equality_needed
3126 && h->plt.refcount > 0
3127 && h->got.refcount > 0)
3129 /* Don't use the regular PLT if there are both GOT and GOTPLT
3131 h->plt.offset = (bfd_vma) -1;
3133 /* Use the GOT PLT. */
3134 eh->plt_got.refcount = 1;
3137 /* Clear the reference count of function pointer relocations if
3138 symbol isn't a normal function. */
3139 if (h->type != STT_FUNC)
3140 eh->func_pointer_refcount = 0;
3142 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3143 here if it is defined and referenced in a non-shared object. */
3144 if (h->type == STT_GNU_IFUNC
3147 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h,
3149 &htab->readonly_dynrelocs_against_ifunc,
3152 GOT_ENTRY_SIZE, TRUE))
3154 asection *s = htab->plt_bnd;
3155 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
3157 /* Use the .plt.bnd section if it is created. */
3158 eh->plt_bnd.offset = s->size;
3160 /* Make room for this entry in the .plt.bnd section. */
3161 s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3169 /* Don't create the PLT entry if there are only function pointer
3170 relocations which can be resolved at run-time. */
3171 else if (htab->elf.dynamic_sections_created
3172 && (h->plt.refcount > eh->func_pointer_refcount
3173 || eh->plt_got.refcount > 0))
3175 bfd_boolean use_plt_got;
3177 /* Clear the reference count of function pointer relocations
3179 eh->func_pointer_refcount = 0;
3181 if ((info->flags & DF_BIND_NOW) && !h->pointer_equality_needed)
3183 /* Don't use the regular PLT for DF_BIND_NOW. */
3184 h->plt.offset = (bfd_vma) -1;
3186 /* Use the GOT PLT. */
3187 h->got.refcount = 1;
3188 eh->plt_got.refcount = 1;
3191 use_plt_got = eh->plt_got.refcount > 0;
3193 /* Make sure this symbol is output as a dynamic symbol.
3194 Undefined weak syms won't yet be marked as dynamic. */
3195 if (h->dynindx == -1
3197 && !resolved_to_zero
3198 && h->root.type == bfd_link_hash_undefweak)
3200 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3204 if (bfd_link_pic (info)
3205 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3207 asection *s = htab->elf.splt;
3208 asection *bnd_s = htab->plt_bnd;
3209 asection *got_s = htab->plt_got;
3211 /* If this is the first .plt entry, make room for the special
3212 first entry. The .plt section is used by prelink to undo
3213 prelinking for dynamic relocations. */
3215 s->size = plt_entry_size;
3218 eh->plt_got.offset = got_s->size;
3221 h->plt.offset = s->size;
3223 eh->plt_bnd.offset = bnd_s->size;
3226 /* If this symbol is not defined in a regular file, and we are
3227 not generating a shared library, then set the symbol to this
3228 location in the .plt. This is required to make function
3229 pointers compare as equal between the normal executable and
3230 the shared library. */
3231 if (! bfd_link_pic (info)
3236 /* We need to make a call to the entry of the GOT PLT
3237 instead of regular PLT entry. */
3238 h->root.u.def.section = got_s;
3239 h->root.u.def.value = eh->plt_got.offset;
3245 /* We need to make a call to the entry of the second
3246 PLT instead of regular PLT entry. */
3247 h->root.u.def.section = bnd_s;
3248 h->root.u.def.value = eh->plt_bnd.offset;
3252 h->root.u.def.section = s;
3253 h->root.u.def.value = h->plt.offset;
3258 /* Make room for this entry. */
3260 got_s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3263 s->size += plt_entry_size;
3265 bnd_s->size += sizeof (elf_x86_64_legacy_plt2_entry);
3267 /* We also need to make an entry in the .got.plt section,
3268 which will be placed in the .got section by the linker
3270 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
3272 /* There should be no PLT relocation against resolved
3273 undefined weak symbol in executable. */
3274 if (!resolved_to_zero)
3276 /* We also need to make an entry in the .rela.plt
3278 htab->elf.srelplt->size += bed->s->sizeof_rela;
3279 htab->elf.srelplt->reloc_count++;
3285 eh->plt_got.offset = (bfd_vma) -1;
3286 h->plt.offset = (bfd_vma) -1;
3292 eh->plt_got.offset = (bfd_vma) -1;
3293 h->plt.offset = (bfd_vma) -1;
3297 eh->tlsdesc_got = (bfd_vma) -1;
3299 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3300 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3301 if (h->got.refcount > 0
3302 && bfd_link_executable (info)
3304 && elf_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
3306 h->got.offset = (bfd_vma) -1;
3308 else if (h->got.refcount > 0)
3312 int tls_type = elf_x86_64_hash_entry (h)->tls_type;
3314 /* Make sure this symbol is output as a dynamic symbol.
3315 Undefined weak syms won't yet be marked as dynamic. */
3316 if (h->dynindx == -1
3318 && !resolved_to_zero
3319 && h->root.type == bfd_link_hash_undefweak)
3321 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3325 if (GOT_TLS_GDESC_P (tls_type))
3327 eh->tlsdesc_got = htab->elf.sgotplt->size
3328 - elf_x86_64_compute_jump_table_size (htab);
3329 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
3330 h->got.offset = (bfd_vma) -2;
3332 if (! GOT_TLS_GDESC_P (tls_type)
3333 || GOT_TLS_GD_P (tls_type))
3336 h->got.offset = s->size;
3337 s->size += GOT_ENTRY_SIZE;
3338 if (GOT_TLS_GD_P (tls_type))
3339 s->size += GOT_ENTRY_SIZE;
3341 dyn = htab->elf.dynamic_sections_created;
3342 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3343 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3344 relocation. No dynamic relocation against resolved undefined
3345 weak symbol in executable. */
3346 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
3347 || tls_type == GOT_TLS_IE)
3348 htab->elf.srelgot->size += bed->s->sizeof_rela;
3349 else if (GOT_TLS_GD_P (tls_type))
3350 htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
3351 else if (! GOT_TLS_GDESC_P (tls_type)
3352 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3353 && !resolved_to_zero)
3354 || h->root.type != bfd_link_hash_undefweak)
3355 && (bfd_link_pic (info)
3356 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
3357 htab->elf.srelgot->size += bed->s->sizeof_rela;
3358 if (GOT_TLS_GDESC_P (tls_type))
3360 htab->elf.srelplt->size += bed->s->sizeof_rela;
3361 htab->tlsdesc_plt = (bfd_vma) -1;
3365 h->got.offset = (bfd_vma) -1;
3367 if (eh->dyn_relocs == NULL)
3370 /* In the shared -Bsymbolic case, discard space allocated for
3371 dynamic pc-relative relocs against symbols which turn out to be
3372 defined in regular objects. For the normal shared case, discard
3373 space for pc-relative relocs that have become local due to symbol
3374 visibility changes. */
3376 if (bfd_link_pic (info))
3378 /* Relocs that use pc_count are those that appear on a call
3379 insn, or certain REL relocs that can generated via assembly.
3380 We want calls to protected symbols to resolve directly to the
3381 function rather than going via the plt. If people want
3382 function pointer comparisons to work as expected then they
3383 should avoid writing weird assembly. */
3384 if (SYMBOL_CALLS_LOCAL (info, h))
3386 struct elf_dyn_relocs **pp;
3388 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3390 p->count -= p->pc_count;
3399 /* Also discard relocs on undefined weak syms with non-default
3400 visibility or in PIE. */
3401 if (eh->dyn_relocs != NULL)
3403 if (h->root.type == bfd_link_hash_undefweak)
3405 /* Undefined weak symbol is never bound locally in shared
3407 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3408 || resolved_to_zero)
3409 eh->dyn_relocs = NULL;
3410 else if (h->dynindx == -1
3411 && ! h->forced_local
3412 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3415 /* For PIE, discard space for pc-relative relocs against
3416 symbols which turn out to need copy relocs. */
3417 else if (bfd_link_executable (info)
3418 && (h->needs_copy || eh->needs_copy)
3422 struct elf_dyn_relocs **pp;
3424 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3426 if (p->pc_count != 0)
3434 else if (ELIMINATE_COPY_RELOCS)
3436 /* For the non-shared case, discard space for relocs against
3437 symbols which turn out to need copy relocs or are not
3438 dynamic. Keep dynamic relocations for run-time function
3439 pointer initialization. */
3441 if ((!h->non_got_ref
3442 || eh->func_pointer_refcount > 0
3443 || (h->root.type == bfd_link_hash_undefweak
3444 && !resolved_to_zero))
3447 || (htab->elf.dynamic_sections_created
3448 && (h->root.type == bfd_link_hash_undefweak
3449 || h->root.type == bfd_link_hash_undefined))))
3451 /* Make sure this symbol is output as a dynamic symbol.
3452 Undefined weak syms won't yet be marked as dynamic. */
3453 if (h->dynindx == -1
3454 && ! h->forced_local
3455 && ! resolved_to_zero
3456 && h->root.type == bfd_link_hash_undefweak
3457 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3460 /* If that succeeded, we know we'll be keeping all the
3462 if (h->dynindx != -1)
3466 eh->dyn_relocs = NULL;
3467 eh->func_pointer_refcount = 0;
3472 /* Finally, allocate space. */
3473 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3477 sreloc = elf_section_data (p->sec)->sreloc;
3479 BFD_ASSERT (sreloc != NULL);
3481 sreloc->size += p->count * bed->s->sizeof_rela;
3487 /* Allocate space in .plt, .got and associated reloc sections for
3488 local dynamic relocs. */
3491 elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
3493 struct elf_link_hash_entry *h
3494 = (struct elf_link_hash_entry *) *slot;
3496 if (h->type != STT_GNU_IFUNC
3500 || h->root.type != bfd_link_hash_defined)
3503 return elf_x86_64_allocate_dynrelocs (h, inf);
3506 /* Find any dynamic relocs that apply to read-only sections. */
3509 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
3512 struct elf_x86_64_link_hash_entry *eh;
3513 struct elf_dyn_relocs *p;
3515 /* Skip local IFUNC symbols. */
3516 if (h->forced_local && h->type == STT_GNU_IFUNC)
3519 eh = (struct elf_x86_64_link_hash_entry *) h;
3520 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3522 asection *s = p->sec->output_section;
3524 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3526 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3528 info->flags |= DF_TEXTREL;
3530 if ((info->warn_shared_textrel && bfd_link_pic (info))
3531 || info->error_textrel)
3532 /* xgettext:c-format */
3533 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3534 p->sec->owner, h->root.root.string,
3537 /* Not an error, just cut short the traversal. */
3544 /* Convert load via the GOT slot to load immediate. */
3547 elf_x86_64_convert_load (bfd *abfd, asection *sec,
3548 struct bfd_link_info *link_info)
3550 Elf_Internal_Shdr *symtab_hdr;
3551 Elf_Internal_Rela *internal_relocs;
3552 Elf_Internal_Rela *irel, *irelend;
3554 struct elf_x86_64_link_hash_table *htab;
3555 bfd_boolean changed;
3556 bfd_signed_vma *local_got_refcounts;
3558 /* Don't even try to convert non-ELF outputs. */
3559 if (!is_elf_hash_table (link_info->hash))
3562 /* Nothing to do if there is no need or no output. */
3563 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
3564 || sec->need_convert_load == 0
3565 || bfd_is_abs_section (sec->output_section))
3568 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3570 /* Load the relocations for this section. */
3571 internal_relocs = (_bfd_elf_link_read_relocs
3572 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
3573 link_info->keep_memory));
3574 if (internal_relocs == NULL)
3578 htab = elf_x86_64_hash_table (link_info);
3579 local_got_refcounts = elf_local_got_refcounts (abfd);
3581 /* Get the section contents. */
3582 if (elf_section_data (sec)->this_hdr.contents != NULL)
3583 contents = elf_section_data (sec)->this_hdr.contents;
3586 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
3590 irelend = internal_relocs + sec->reloc_count;
3591 for (irel = internal_relocs; irel < irelend; irel++)
3593 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
3594 unsigned int r_symndx;
3595 struct elf_link_hash_entry *h;
3596 bfd_boolean converted;
3598 if (r_type != R_X86_64_GOTPCRELX
3599 && r_type != R_X86_64_REX_GOTPCRELX
3600 && r_type != R_X86_64_GOTPCREL)
3603 r_symndx = htab->r_sym (irel->r_info);
3604 if (r_symndx < symtab_hdr->sh_info)
3605 h = elf_x86_64_get_local_sym_hash (htab, sec->owner,
3606 (const Elf_Internal_Rela *) irel,
3610 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
3611 while (h->root.type == bfd_link_hash_indirect
3612 || h->root.type == bfd_link_hash_warning)
3613 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3616 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3617 if (h != NULL && h->type == STT_GNU_IFUNC)
3621 if (!elf_x86_64_convert_load_reloc (abfd, sec, contents, irel, h,
3622 &converted, link_info))
3627 changed = converted;
3630 if (h->got.refcount > 0)
3631 h->got.refcount -= 1;
3635 if (local_got_refcounts != NULL
3636 && local_got_refcounts[r_symndx] > 0)
3637 local_got_refcounts[r_symndx] -= 1;
3642 if (contents != NULL
3643 && elf_section_data (sec)->this_hdr.contents != contents)
3645 if (!changed && !link_info->keep_memory)
3649 /* Cache the section contents for elf_link_input_bfd. */
3650 elf_section_data (sec)->this_hdr.contents = contents;
3654 if (elf_section_data (sec)->relocs != internal_relocs)
3657 free (internal_relocs);
3659 elf_section_data (sec)->relocs = internal_relocs;
3665 if (contents != NULL
3666 && elf_section_data (sec)->this_hdr.contents != contents)
3668 if (internal_relocs != NULL
3669 && elf_section_data (sec)->relocs != internal_relocs)
3670 free (internal_relocs);
3674 /* Set the sizes of the dynamic sections. */
3677 elf_x86_64_size_dynamic_sections (bfd *output_bfd,
3678 struct bfd_link_info *info)
3680 struct elf_x86_64_link_hash_table *htab;
3685 const struct elf_backend_data *bed;
3686 const struct elf_x86_64_backend_data *arch_data;
3688 htab = elf_x86_64_hash_table (info);
3691 bed = get_elf_backend_data (output_bfd);
3693 dynobj = htab->elf.dynobj;
3697 /* Set up .got offsets for local syms, and space for local dynamic
3699 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3701 bfd_signed_vma *local_got;
3702 bfd_signed_vma *end_local_got;
3703 char *local_tls_type;
3704 bfd_vma *local_tlsdesc_gotent;
3705 bfd_size_type locsymcount;
3706 Elf_Internal_Shdr *symtab_hdr;
3709 if (! is_x86_64_elf (ibfd))
3712 for (s = ibfd->sections; s != NULL; s = s->next)
3714 struct elf_dyn_relocs *p;
3716 if (!elf_x86_64_convert_load (ibfd, s, info))
3719 for (p = (struct elf_dyn_relocs *)
3720 (elf_section_data (s)->local_dynrel);
3724 if (!bfd_is_abs_section (p->sec)
3725 && bfd_is_abs_section (p->sec->output_section))
3727 /* Input section has been discarded, either because
3728 it is a copy of a linkonce section or due to
3729 linker script /DISCARD/, so we'll be discarding
3732 else if (p->count != 0)
3734 srel = elf_section_data (p->sec)->sreloc;
3735 srel->size += p->count * bed->s->sizeof_rela;
3736 if ((p->sec->output_section->flags & SEC_READONLY) != 0
3737 && (info->flags & DF_TEXTREL) == 0)
3739 info->flags |= DF_TEXTREL;
3740 if ((info->warn_shared_textrel && bfd_link_pic (info))
3741 || info->error_textrel)
3742 /* xgettext:c-format */
3743 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3744 p->sec->owner, p->sec);
3750 local_got = elf_local_got_refcounts (ibfd);
3754 symtab_hdr = &elf_symtab_hdr (ibfd);
3755 locsymcount = symtab_hdr->sh_info;
3756 end_local_got = local_got + locsymcount;
3757 local_tls_type = elf_x86_64_local_got_tls_type (ibfd);
3758 local_tlsdesc_gotent = elf_x86_64_local_tlsdesc_gotent (ibfd);
3760 srel = htab->elf.srelgot;
3761 for (; local_got < end_local_got;
3762 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
3764 *local_tlsdesc_gotent = (bfd_vma) -1;
3767 if (GOT_TLS_GDESC_P (*local_tls_type))
3769 *local_tlsdesc_gotent = htab->elf.sgotplt->size
3770 - elf_x86_64_compute_jump_table_size (htab);
3771 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
3772 *local_got = (bfd_vma) -2;
3774 if (! GOT_TLS_GDESC_P (*local_tls_type)
3775 || GOT_TLS_GD_P (*local_tls_type))
3777 *local_got = s->size;
3778 s->size += GOT_ENTRY_SIZE;
3779 if (GOT_TLS_GD_P (*local_tls_type))
3780 s->size += GOT_ENTRY_SIZE;
3782 if (bfd_link_pic (info)
3783 || GOT_TLS_GD_ANY_P (*local_tls_type)
3784 || *local_tls_type == GOT_TLS_IE)
3786 if (GOT_TLS_GDESC_P (*local_tls_type))
3788 htab->elf.srelplt->size
3789 += bed->s->sizeof_rela;
3790 htab->tlsdesc_plt = (bfd_vma) -1;
3792 if (! GOT_TLS_GDESC_P (*local_tls_type)
3793 || GOT_TLS_GD_P (*local_tls_type))
3794 srel->size += bed->s->sizeof_rela;
3798 *local_got = (bfd_vma) -1;
3802 if (htab->tls_ld_got.refcount > 0)
3804 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3806 htab->tls_ld_got.offset = htab->elf.sgot->size;
3807 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
3808 htab->elf.srelgot->size += bed->s->sizeof_rela;
3811 htab->tls_ld_got.offset = -1;
3813 /* Allocate global sym .plt and .got entries, and space for global
3814 sym dynamic relocs. */
3815 elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
3818 /* Allocate .plt and .got entries, and space for local symbols. */
3819 htab_traverse (htab->loc_hash_table,
3820 elf_x86_64_allocate_local_dynrelocs,
3823 /* For every jump slot reserved in the sgotplt, reloc_count is
3824 incremented. However, when we reserve space for TLS descriptors,
3825 it's not incremented, so in order to compute the space reserved
3826 for them, it suffices to multiply the reloc count by the jump
3829 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3830 so that R_X86_64_IRELATIVE entries come last. */
3831 if (htab->elf.srelplt)
3833 htab->sgotplt_jump_table_size
3834 = elf_x86_64_compute_jump_table_size (htab);
3835 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
3837 else if (htab->elf.irelplt)
3838 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
3840 if (htab->tlsdesc_plt)
3842 /* If we're not using lazy TLS relocations, don't generate the
3843 PLT and GOT entries they require. */
3844 if ((info->flags & DF_BIND_NOW))
3845 htab->tlsdesc_plt = 0;
3848 htab->tlsdesc_got = htab->elf.sgot->size;
3849 htab->elf.sgot->size += GOT_ENTRY_SIZE;
3850 /* Reserve room for the initial entry.
3851 FIXME: we could probably do away with it in this case. */
3852 if (htab->elf.splt->size == 0)
3853 htab->elf.splt->size = GET_PLT_ENTRY_SIZE (output_bfd);
3854 htab->tlsdesc_plt = htab->elf.splt->size;
3855 htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);
3859 if (htab->elf.sgotplt)
3861 /* Don't allocate .got.plt section if there are no GOT nor PLT
3862 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3863 if ((htab->elf.hgot == NULL
3864 || !htab->elf.hgot->ref_regular_nonweak)
3865 && (htab->elf.sgotplt->size
3866 == get_elf_backend_data (output_bfd)->got_header_size)
3867 && (htab->elf.splt == NULL
3868 || htab->elf.splt->size == 0)
3869 && (htab->elf.sgot == NULL
3870 || htab->elf.sgot->size == 0)
3871 && (htab->elf.iplt == NULL
3872 || htab->elf.iplt->size == 0)
3873 && (htab->elf.igotplt == NULL
3874 || htab->elf.igotplt->size == 0))
3875 htab->elf.sgotplt->size = 0;
3878 arch_data = (htab->plt_bnd != NULL
3879 ? &elf_x86_64_bnd_arch_bed
3880 : get_elf_x86_64_arch_data (bed));
3882 if (_bfd_elf_eh_frame_present (info))
3884 if (htab->plt_eh_frame != NULL
3885 && htab->elf.splt != NULL
3886 && htab->elf.splt->size != 0
3887 && !bfd_is_abs_section (htab->elf.splt->output_section))
3888 htab->plt_eh_frame->size = arch_data->eh_frame_plt_size;
3890 if (htab->plt_got_eh_frame != NULL
3891 && htab->plt_got != NULL
3892 && htab->plt_got->size != 0
3893 && !bfd_is_abs_section (htab->plt_got->output_section))
3894 htab->plt_got_eh_frame->size = arch_data->eh_frame_plt_got_size;
3896 /* Unwind info for .plt.bnd and .plt.got sections are
3898 if (htab->plt_bnd_eh_frame != NULL
3899 && htab->plt_bnd != NULL
3900 && htab->plt_bnd->size != 0
3901 && !bfd_is_abs_section (htab->plt_bnd->output_section))
3902 htab->plt_bnd_eh_frame->size = arch_data->eh_frame_plt_got_size;
3905 /* We now have determined the sizes of the various dynamic sections.
3906 Allocate memory for them. */
3908 for (s = dynobj->sections; s != NULL; s = s->next)
3910 if ((s->flags & SEC_LINKER_CREATED) == 0)
3913 if (s == htab->elf.splt
3914 || s == htab->elf.sgot
3915 || s == htab->elf.sgotplt
3916 || s == htab->elf.iplt
3917 || s == htab->elf.igotplt
3918 || s == htab->plt_bnd
3919 || s == htab->plt_got
3920 || s == htab->plt_eh_frame
3921 || s == htab->plt_got_eh_frame
3922 || s == htab->plt_bnd_eh_frame
3923 || s == htab->elf.sdynbss
3924 || s == htab->elf.sdynrelro)
3926 /* Strip this section if we don't need it; see the
3929 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3931 if (s->size != 0 && s != htab->elf.srelplt)
3934 /* We use the reloc_count field as a counter if we need
3935 to copy relocs into the output file. */
3936 if (s != htab->elf.srelplt)
3941 /* It's not one of our sections, so don't allocate space. */
3947 /* If we don't need this section, strip it from the
3948 output file. This is mostly to handle .rela.bss and
3949 .rela.plt. We must create both sections in
3950 create_dynamic_sections, because they must be created
3951 before the linker maps input sections to output
3952 sections. The linker does that before
3953 adjust_dynamic_symbol is called, and it is that
3954 function which decides whether anything needs to go
3955 into these sections. */
3957 s->flags |= SEC_EXCLUDE;
3961 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3964 /* Allocate memory for the section contents. We use bfd_zalloc
3965 here in case unused entries are not reclaimed before the
3966 section's contents are written out. This should not happen,
3967 but this way if it does, we get a R_X86_64_NONE reloc instead
3969 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3970 if (s->contents == NULL)
3974 if (htab->plt_eh_frame != NULL
3975 && htab->plt_eh_frame->contents != NULL)
3977 memcpy (htab->plt_eh_frame->contents,
3978 arch_data->eh_frame_plt, htab->plt_eh_frame->size);
3979 bfd_put_32 (dynobj, htab->elf.splt->size,
3980 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
3983 if (htab->plt_got_eh_frame != NULL
3984 && htab->plt_got_eh_frame->contents != NULL)
3986 memcpy (htab->plt_got_eh_frame->contents,
3987 arch_data->eh_frame_plt_got,
3988 htab->plt_got_eh_frame->size);
3989 bfd_put_32 (dynobj, htab->plt_got->size,
3990 (htab->plt_got_eh_frame->contents
3991 + PLT_FDE_LEN_OFFSET));
3994 if (htab->plt_bnd_eh_frame != NULL
3995 && htab->plt_bnd_eh_frame->contents != NULL)
3997 memcpy (htab->plt_bnd_eh_frame->contents,
3998 arch_data->eh_frame_plt_got,
3999 htab->plt_bnd_eh_frame->size);
4000 bfd_put_32 (dynobj, htab->plt_bnd->size,
4001 (htab->plt_bnd_eh_frame->contents
4002 + PLT_FDE_LEN_OFFSET));
4005 if (htab->elf.dynamic_sections_created)
4007 /* Add some entries to the .dynamic section. We fill in the
4008 values later, in elf_x86_64_finish_dynamic_sections, but we
4009 must add the entries now so that we get the correct size for
4010 the .dynamic section. The DT_DEBUG entry is filled in by the
4011 dynamic linker and used by the debugger. */
4012 #define add_dynamic_entry(TAG, VAL) \
4013 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4015 if (bfd_link_executable (info))
4017 if (!add_dynamic_entry (DT_DEBUG, 0))
4021 if (htab->elf.splt->size != 0)
4023 /* DT_PLTGOT is used by prelink even if there is no PLT
4025 if (!add_dynamic_entry (DT_PLTGOT, 0))
4029 if (htab->elf.srelplt->size != 0)
4031 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
4032 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4033 || !add_dynamic_entry (DT_JMPREL, 0))
4037 if (htab->tlsdesc_plt
4038 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
4039 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
4044 if (!add_dynamic_entry (DT_RELA, 0)
4045 || !add_dynamic_entry (DT_RELASZ, 0)
4046 || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
4049 /* If any dynamic relocs apply to a read-only section,
4050 then we need a DT_TEXTREL entry. */
4051 if ((info->flags & DF_TEXTREL) == 0)
4052 elf_link_hash_traverse (&htab->elf,
4053 elf_x86_64_readonly_dynrelocs,
4056 if ((info->flags & DF_TEXTREL) != 0)
4058 if (htab->readonly_dynrelocs_against_ifunc)
4060 info->callbacks->einfo
4061 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4062 bfd_set_error (bfd_error_bad_value);
4066 if (!add_dynamic_entry (DT_TEXTREL, 0))
4071 #undef add_dynamic_entry
4077 elf_x86_64_always_size_sections (bfd *output_bfd,
4078 struct bfd_link_info *info)
4080 asection *tls_sec = elf_hash_table (info)->tls_sec;
4084 struct elf_link_hash_entry *tlsbase;
4086 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
4087 "_TLS_MODULE_BASE_",
4088 FALSE, FALSE, FALSE);
4090 if (tlsbase && tlsbase->type == STT_TLS)
4092 struct elf_x86_64_link_hash_table *htab;
4093 struct bfd_link_hash_entry *bh = NULL;
4094 const struct elf_backend_data *bed
4095 = get_elf_backend_data (output_bfd);
4097 htab = elf_x86_64_hash_table (info);
4101 if (!(_bfd_generic_link_add_one_symbol
4102 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
4103 tls_sec, 0, NULL, FALSE,
4104 bed->collect, &bh)))
4107 htab->tls_module_base = bh;
4109 tlsbase = (struct elf_link_hash_entry *)bh;
4110 tlsbase->def_regular = 1;
4111 tlsbase->other = STV_HIDDEN;
4112 tlsbase->root.linker_def = 1;
4113 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
4120 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4121 executables. Rather than setting it to the beginning of the TLS
4122 section, we have to set it to the end. This function may be called
4123 multiple times, it is idempotent. */
4126 elf_x86_64_set_tls_module_base (struct bfd_link_info *info)
4128 struct elf_x86_64_link_hash_table *htab;
4129 struct bfd_link_hash_entry *base;
4131 if (!bfd_link_executable (info))
4134 htab = elf_x86_64_hash_table (info);
4138 base = htab->tls_module_base;
4142 base->u.def.value = htab->elf.tls_size;
4145 /* Return the base VMA address which should be subtracted from real addresses
4146 when resolving @dtpoff relocation.
4147 This is PT_TLS segment p_vaddr. */
4150 elf_x86_64_dtpoff_base (struct bfd_link_info *info)
4152 /* If tls_sec is NULL, we should have signalled an error already. */
4153 if (elf_hash_table (info)->tls_sec == NULL)
4155 return elf_hash_table (info)->tls_sec->vma;
4158 /* Return the relocation value for @tpoff relocation
4159 if STT_TLS virtual address is ADDRESS. */
4162 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
4164 struct elf_link_hash_table *htab = elf_hash_table (info);
4165 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
4166 bfd_vma static_tls_size;
4168 /* If tls_segment is NULL, we should have signalled an error already. */
4169 if (htab->tls_sec == NULL)
4172 /* Consider special static TLS alignment requirements. */
4173 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
4174 return address - static_tls_size - htab->tls_sec->vma;
4177 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4181 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
4183 /* Opcode Instruction
4186 0x0f 0x8x conditional jump */
4188 && (contents [offset - 1] == 0xe8
4189 || contents [offset - 1] == 0xe9))
4191 && contents [offset - 2] == 0x0f
4192 && (contents [offset - 1] & 0xf0) == 0x80));
4195 /* Relocate an x86_64 ELF section. */
4198 elf_x86_64_relocate_section (bfd *output_bfd,
4199 struct bfd_link_info *info,
4201 asection *input_section,
4203 Elf_Internal_Rela *relocs,
4204 Elf_Internal_Sym *local_syms,
4205 asection **local_sections)
4207 struct elf_x86_64_link_hash_table *htab;
4208 Elf_Internal_Shdr *symtab_hdr;
4209 struct elf_link_hash_entry **sym_hashes;
4210 bfd_vma *local_got_offsets;
4211 bfd_vma *local_tlsdesc_gotents;
4212 Elf_Internal_Rela *rel;
4213 Elf_Internal_Rela *wrel;
4214 Elf_Internal_Rela *relend;
4215 const unsigned int plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
4217 BFD_ASSERT (is_x86_64_elf (input_bfd));
4219 /* Skip if check_relocs failed. */
4220 if (input_section->check_relocs_failed)
4223 htab = elf_x86_64_hash_table (info);
4226 symtab_hdr = &elf_symtab_hdr (input_bfd);
4227 sym_hashes = elf_sym_hashes (input_bfd);
4228 local_got_offsets = elf_local_got_offsets (input_bfd);
4229 local_tlsdesc_gotents = elf_x86_64_local_tlsdesc_gotent (input_bfd);
4231 elf_x86_64_set_tls_module_base (info);
4233 rel = wrel = relocs;
4234 relend = relocs + input_section->reloc_count;
4235 for (; rel < relend; wrel++, rel++)
4237 unsigned int r_type;
4238 reloc_howto_type *howto;
4239 unsigned long r_symndx;
4240 struct elf_link_hash_entry *h;
4241 struct elf_x86_64_link_hash_entry *eh;
4242 Elf_Internal_Sym *sym;
4244 bfd_vma off, offplt, plt_offset;
4246 bfd_boolean unresolved_reloc;
4247 bfd_reloc_status_type r;
4249 asection *base_got, *resolved_plt;
4251 bfd_boolean resolved_to_zero;
4252 bfd_boolean relative_reloc;
4254 r_type = ELF32_R_TYPE (rel->r_info);
4255 if (r_type == (int) R_X86_64_GNU_VTINHERIT
4256 || r_type == (int) R_X86_64_GNU_VTENTRY)
4263 if (r_type >= (int) R_X86_64_standard)
4266 /* xgettext:c-format */
4267 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4268 input_bfd, r_type, input_section);
4269 bfd_set_error (bfd_error_bad_value);
4273 if (r_type != (int) R_X86_64_32
4274 || ABI_64_P (output_bfd))
4275 howto = x86_64_elf_howto_table + r_type;
4277 howto = (x86_64_elf_howto_table
4278 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
4279 r_symndx = htab->r_sym (rel->r_info);
4283 unresolved_reloc = FALSE;
4284 if (r_symndx < symtab_hdr->sh_info)
4286 sym = local_syms + r_symndx;
4287 sec = local_sections[r_symndx];
4289 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
4291 st_size = sym->st_size;
4293 /* Relocate against local STT_GNU_IFUNC symbol. */
4294 if (!bfd_link_relocatable (info)
4295 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
4297 h = elf_x86_64_get_local_sym_hash (htab, input_bfd,
4302 /* Set STT_GNU_IFUNC symbol value. */
4303 h->root.u.def.value = sym->st_value;
4304 h->root.u.def.section = sec;
4309 bfd_boolean warned ATTRIBUTE_UNUSED;
4310 bfd_boolean ignored ATTRIBUTE_UNUSED;
4312 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4313 r_symndx, symtab_hdr, sym_hashes,
4315 unresolved_reloc, warned, ignored);
4319 if (sec != NULL && discarded_section (sec))
4321 _bfd_clear_contents (howto, input_bfd, input_section,
4322 contents + rel->r_offset);
4323 wrel->r_offset = rel->r_offset;
4327 /* For ld -r, remove relocations in debug sections against
4328 sections defined in discarded sections. Not done for
4329 eh_frame editing code expects to be present. */
4330 if (bfd_link_relocatable (info)
4331 && (input_section->flags & SEC_DEBUGGING))
4337 if (bfd_link_relocatable (info))
4344 if (rel->r_addend == 0 && !ABI_64_P (output_bfd))
4346 if (r_type == R_X86_64_64)
4348 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4349 zero-extend it to 64bit if addend is zero. */
4350 r_type = R_X86_64_32;
4351 memset (contents + rel->r_offset + 4, 0, 4);
4353 else if (r_type == R_X86_64_SIZE64)
4355 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4356 zero-extend it to 64bit if addend is zero. */
4357 r_type = R_X86_64_SIZE32;
4358 memset (contents + rel->r_offset + 4, 0, 4);
4362 eh = (struct elf_x86_64_link_hash_entry *) h;
4364 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4365 it here if it is defined in a non-shared object. */
4367 && h->type == STT_GNU_IFUNC
4373 if ((input_section->flags & SEC_ALLOC) == 0)
4375 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4376 sections because such sections are not SEC_ALLOC and
4377 thus ld.so will not process them. */
4378 if ((input_section->flags & SEC_DEBUGGING) != 0)
4388 case R_X86_64_GOTPCREL:
4389 case R_X86_64_GOTPCRELX:
4390 case R_X86_64_REX_GOTPCRELX:
4391 case R_X86_64_GOTPCREL64:
4392 base_got = htab->elf.sgot;
4393 off = h->got.offset;
4395 if (base_got == NULL)
4398 if (off == (bfd_vma) -1)
4400 /* We can't use h->got.offset here to save state, or
4401 even just remember the offset, as finish_dynamic_symbol
4402 would use that as offset into .got. */
4404 if (h->plt.offset == (bfd_vma) -1)
4407 if (htab->elf.splt != NULL)
4409 plt_index = h->plt.offset / plt_entry_size - 1;
4410 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4411 base_got = htab->elf.sgotplt;
4415 plt_index = h->plt.offset / plt_entry_size;
4416 off = plt_index * GOT_ENTRY_SIZE;
4417 base_got = htab->elf.igotplt;
4420 if (h->dynindx == -1
4424 /* This references the local defitionion. We must
4425 initialize this entry in the global offset table.
4426 Since the offset must always be a multiple of 8,
4427 we use the least significant bit to record
4428 whether we have initialized it already.
4430 When doing a dynamic link, we create a .rela.got
4431 relocation entry to initialize the value. This
4432 is done in the finish_dynamic_symbol routine. */
4437 bfd_put_64 (output_bfd, relocation,
4438 base_got->contents + off);
4439 /* Note that this is harmless for the GOTPLT64
4440 case, as -1 | 1 still is -1. */
4446 relocation = (base_got->output_section->vma
4447 + base_got->output_offset + off);
4452 if (h->plt.offset == (bfd_vma) -1)
4454 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4455 if (r_type == htab->pointer_r_type
4456 && (input_section->flags & SEC_CODE) == 0)
4457 goto do_ifunc_pointer;
4458 goto bad_ifunc_reloc;
4461 /* STT_GNU_IFUNC symbol must go through PLT. */
4462 if (htab->elf.splt != NULL)
4464 if (htab->plt_bnd != NULL)
4466 resolved_plt = htab->plt_bnd;
4467 plt_offset = eh->plt_bnd.offset;
4471 resolved_plt = htab->elf.splt;
4472 plt_offset = h->plt.offset;
4477 resolved_plt = htab->elf.iplt;
4478 plt_offset = h->plt.offset;
4481 relocation = (resolved_plt->output_section->vma
4482 + resolved_plt->output_offset + plt_offset);
4488 if (h->root.root.string)
4489 name = h->root.root.string;
4491 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4494 /* xgettext:c-format */
4495 (_("%B: relocation %s against STT_GNU_IFUNC "
4496 "symbol `%s' isn't supported"), input_bfd,
4498 bfd_set_error (bfd_error_bad_value);
4502 if (bfd_link_pic (info))
4507 if (ABI_64_P (output_bfd))
4512 if (rel->r_addend != 0)
4514 if (h->root.root.string)
4515 name = h->root.root.string;
4517 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4520 /* xgettext:c-format */
4521 (_("%B: relocation %s against STT_GNU_IFUNC "
4522 "symbol `%s' has non-zero addend: %d"),
4523 input_bfd, howto->name, name, rel->r_addend);
4524 bfd_set_error (bfd_error_bad_value);
4528 /* Generate dynamic relcoation only when there is a
4529 non-GOT reference in a shared object or there is no
4531 if ((bfd_link_pic (info) && h->non_got_ref)
4532 || h->plt.offset == (bfd_vma) -1)
4534 Elf_Internal_Rela outrel;
4537 /* Need a dynamic relocation to get the real function
4539 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4543 if (outrel.r_offset == (bfd_vma) -1
4544 || outrel.r_offset == (bfd_vma) -2)
4547 outrel.r_offset += (input_section->output_section->vma
4548 + input_section->output_offset);
4550 if (h->dynindx == -1
4552 || bfd_link_executable (info))
4554 /* This symbol is resolved locally. */
4555 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
4556 outrel.r_addend = (h->root.u.def.value
4557 + h->root.u.def.section->output_section->vma
4558 + h->root.u.def.section->output_offset);
4562 outrel.r_info = htab->r_info (h->dynindx, r_type);
4563 outrel.r_addend = 0;
4566 /* Dynamic relocations are stored in
4567 1. .rela.ifunc section in PIC object.
4568 2. .rela.got section in dynamic executable.
4569 3. .rela.iplt section in static executable. */
4570 if (bfd_link_pic (info))
4571 sreloc = htab->elf.irelifunc;
4572 else if (htab->elf.splt != NULL)
4573 sreloc = htab->elf.srelgot;
4575 sreloc = htab->elf.irelplt;
4576 elf_append_rela (output_bfd, sreloc, &outrel);
4578 /* If this reloc is against an external symbol, we
4579 do not want to fiddle with the addend. Otherwise,
4580 we need to include the symbol value so that it
4581 becomes an addend for the dynamic reloc. For an
4582 internal symbol, we have updated addend. */
4587 case R_X86_64_PC32_BND:
4589 case R_X86_64_PLT32:
4590 case R_X86_64_PLT32_BND:
4595 resolved_to_zero = (eh != NULL
4596 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
4600 /* When generating a shared object, the relocations handled here are
4601 copied into the output file to be resolved at run time. */
4604 case R_X86_64_GOT32:
4605 case R_X86_64_GOT64:
4606 /* Relocation is to the entry for this symbol in the global
4608 case R_X86_64_GOTPCREL:
4609 case R_X86_64_GOTPCRELX:
4610 case R_X86_64_REX_GOTPCRELX:
4611 case R_X86_64_GOTPCREL64:
4612 /* Use global offset table entry as symbol value. */
4613 case R_X86_64_GOTPLT64:
4614 /* This is obsolete and treated the the same as GOT64. */
4615 base_got = htab->elf.sgot;
4617 if (htab->elf.sgot == NULL)
4620 relative_reloc = FALSE;
4625 off = h->got.offset;
4627 && h->plt.offset != (bfd_vma)-1
4628 && off == (bfd_vma)-1)
4630 /* We can't use h->got.offset here to save
4631 state, or even just remember the offset, as
4632 finish_dynamic_symbol would use that as offset into
4634 bfd_vma plt_index = h->plt.offset / plt_entry_size - 1;
4635 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4636 base_got = htab->elf.sgotplt;
4639 dyn = htab->elf.dynamic_sections_created;
4641 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4642 || (bfd_link_pic (info)
4643 && SYMBOL_REFERENCES_LOCAL (info, h))
4644 || (ELF_ST_VISIBILITY (h->other)
4645 && h->root.type == bfd_link_hash_undefweak))
4647 /* This is actually a static link, or it is a -Bsymbolic
4648 link and the symbol is defined locally, or the symbol
4649 was forced to be local because of a version file. We
4650 must initialize this entry in the global offset table.
4651 Since the offset must always be a multiple of 8, we
4652 use the least significant bit to record whether we
4653 have initialized it already.
4655 When doing a dynamic link, we create a .rela.got
4656 relocation entry to initialize the value. This is
4657 done in the finish_dynamic_symbol routine. */
4662 bfd_put_64 (output_bfd, relocation,
4663 base_got->contents + off);
4664 /* Note that this is harmless for the GOTPLT64 case,
4665 as -1 | 1 still is -1. */
4668 if (h->dynindx == -1
4670 && h->root.type != bfd_link_hash_undefweak
4671 && bfd_link_pic (info))
4673 /* If this symbol isn't dynamic in PIC,
4674 generate R_X86_64_RELATIVE here. */
4675 eh->no_finish_dynamic_symbol = 1;
4676 relative_reloc = TRUE;
4681 unresolved_reloc = FALSE;
4685 if (local_got_offsets == NULL)
4688 off = local_got_offsets[r_symndx];
4690 /* The offset must always be a multiple of 8. We use
4691 the least significant bit to record whether we have
4692 already generated the necessary reloc. */
4697 bfd_put_64 (output_bfd, relocation,
4698 base_got->contents + off);
4699 local_got_offsets[r_symndx] |= 1;
4701 if (bfd_link_pic (info))
4702 relative_reloc = TRUE;
4709 Elf_Internal_Rela outrel;
4711 /* We need to generate a R_X86_64_RELATIVE reloc
4712 for the dynamic linker. */
4713 s = htab->elf.srelgot;
4717 outrel.r_offset = (base_got->output_section->vma
4718 + base_got->output_offset
4720 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4721 outrel.r_addend = relocation;
4722 elf_append_rela (output_bfd, s, &outrel);
4725 if (off >= (bfd_vma) -2)
4728 relocation = base_got->output_section->vma
4729 + base_got->output_offset + off;
4730 if (r_type != R_X86_64_GOTPCREL
4731 && r_type != R_X86_64_GOTPCRELX
4732 && r_type != R_X86_64_REX_GOTPCRELX
4733 && r_type != R_X86_64_GOTPCREL64)
4734 relocation -= htab->elf.sgotplt->output_section->vma
4735 - htab->elf.sgotplt->output_offset;
4739 case R_X86_64_GOTOFF64:
4740 /* Relocation is relative to the start of the global offset
4743 /* Check to make sure it isn't a protected function or data
4744 symbol for shared library since it may not be local when
4745 used as function address or with copy relocation. We also
4746 need to make sure that a symbol is referenced locally. */
4747 if (bfd_link_pic (info) && h)
4749 if (!h->def_regular)
4753 switch (ELF_ST_VISIBILITY (h->other))
4756 v = _("hidden symbol");
4759 v = _("internal symbol");
4762 v = _("protected symbol");
4770 /* xgettext:c-format */
4771 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4772 " `%s' can not be used when making a shared object"),
4773 input_bfd, v, h->root.root.string);
4774 bfd_set_error (bfd_error_bad_value);
4777 else if (!bfd_link_executable (info)
4778 && !SYMBOL_REFERENCES_LOCAL (info, h)
4779 && (h->type == STT_FUNC
4780 || h->type == STT_OBJECT)
4781 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
4784 /* xgettext:c-format */
4785 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4786 " `%s' can not be used when making a shared object"),
4788 h->type == STT_FUNC ? "function" : "data",
4789 h->root.root.string);
4790 bfd_set_error (bfd_error_bad_value);
4795 /* Note that sgot is not involved in this
4796 calculation. We always want the start of .got.plt. If we
4797 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4798 permitted by the ABI, we might have to change this
4800 relocation -= htab->elf.sgotplt->output_section->vma
4801 + htab->elf.sgotplt->output_offset;
4804 case R_X86_64_GOTPC32:
4805 case R_X86_64_GOTPC64:
4806 /* Use global offset table as symbol value. */
4807 relocation = htab->elf.sgotplt->output_section->vma
4808 + htab->elf.sgotplt->output_offset;
4809 unresolved_reloc = FALSE;
4812 case R_X86_64_PLTOFF64:
4813 /* Relocation is PLT entry relative to GOT. For local
4814 symbols it's the symbol itself relative to GOT. */
4816 /* See PLT32 handling. */
4817 && (h->plt.offset != (bfd_vma) -1
4818 || eh->plt_got.offset != (bfd_vma) -1)
4819 && htab->elf.splt != NULL)
4821 if (eh->plt_got.offset != (bfd_vma) -1)
4823 /* Use the GOT PLT. */
4824 resolved_plt = htab->plt_got;
4825 plt_offset = eh->plt_got.offset;
4827 else if (htab->plt_bnd != NULL)
4829 resolved_plt = htab->plt_bnd;
4830 plt_offset = eh->plt_bnd.offset;
4834 resolved_plt = htab->elf.splt;
4835 plt_offset = h->plt.offset;
4838 relocation = (resolved_plt->output_section->vma
4839 + resolved_plt->output_offset
4841 unresolved_reloc = FALSE;
4844 relocation -= htab->elf.sgotplt->output_section->vma
4845 + htab->elf.sgotplt->output_offset;
4848 case R_X86_64_PLT32:
4849 case R_X86_64_PLT32_BND:
4850 /* Relocation is to the entry for this symbol in the
4851 procedure linkage table. */
4853 /* Resolve a PLT32 reloc against a local symbol directly,
4854 without using the procedure linkage table. */
4858 if ((h->plt.offset == (bfd_vma) -1
4859 && eh->plt_got.offset == (bfd_vma) -1)
4860 || htab->elf.splt == NULL)
4862 /* We didn't make a PLT entry for this symbol. This
4863 happens when statically linking PIC code, or when
4864 using -Bsymbolic. */
4868 if (h->plt.offset != (bfd_vma) -1)
4870 if (htab->plt_bnd != NULL)
4872 resolved_plt = htab->plt_bnd;
4873 plt_offset = eh->plt_bnd.offset;
4877 resolved_plt = htab->elf.splt;
4878 plt_offset = h->plt.offset;
4883 /* Use the GOT PLT. */
4884 resolved_plt = htab->plt_got;
4885 plt_offset = eh->plt_got.offset;
4888 relocation = (resolved_plt->output_section->vma
4889 + resolved_plt->output_offset
4891 unresolved_reloc = FALSE;
4894 case R_X86_64_SIZE32:
4895 case R_X86_64_SIZE64:
4896 /* Set to symbol size. */
4897 relocation = st_size;
4903 case R_X86_64_PC32_BND:
4904 /* Don't complain about -fPIC if the symbol is undefined when
4905 building executable unless it is unresolved weak symbol. */
4906 if ((input_section->flags & SEC_ALLOC) != 0
4907 && (input_section->flags & SEC_READONLY) != 0
4909 && ((bfd_link_executable (info)
4910 && h->root.type == bfd_link_hash_undefweak
4911 && !resolved_to_zero)
4912 || (bfd_link_pic (info)
4913 && !(bfd_link_pie (info)
4914 && h->root.type == bfd_link_hash_undefined))))
4916 bfd_boolean fail = FALSE;
4918 = ((r_type == R_X86_64_PC32
4919 || r_type == R_X86_64_PC32_BND)
4920 && is_32bit_relative_branch (contents, rel->r_offset));
4922 if (SYMBOL_REFERENCES_LOCAL (info, h))
4924 /* Symbol is referenced locally. Make sure it is
4925 defined locally or for a branch. */
4926 fail = (!(h->def_regular || ELF_COMMON_DEF_P (h))
4929 else if (!(bfd_link_pie (info)
4930 && (h->needs_copy || eh->needs_copy)))
4932 /* Symbol doesn't need copy reloc and isn't referenced
4933 locally. We only allow branch to symbol with
4934 non-default visibility. */
4936 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
4940 return elf_x86_64_need_pic (input_bfd, input_section,
4941 h, NULL, NULL, howto);
4950 /* FIXME: The ABI says the linker should make sure the value is
4951 the same when it's zeroextended to 64 bit. */
4954 if ((input_section->flags & SEC_ALLOC) == 0)
4957 /* Don't copy a pc-relative relocation into the output file
4958 if the symbol needs copy reloc or the symbol is undefined
4959 when building executable. Copy dynamic function pointer
4960 relocations. Don't generate dynamic relocations against
4961 resolved undefined weak symbols in PIE. */
4962 if ((bfd_link_pic (info)
4963 && !(bfd_link_pie (info)
4967 || h->root.type == bfd_link_hash_undefined)
4968 && (IS_X86_64_PCREL_TYPE (r_type)
4969 || r_type == R_X86_64_SIZE32
4970 || r_type == R_X86_64_SIZE64))
4972 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4973 && !resolved_to_zero)
4974 || h->root.type != bfd_link_hash_undefweak))
4975 && ((! IS_X86_64_PCREL_TYPE (r_type)
4976 && r_type != R_X86_64_SIZE32
4977 && r_type != R_X86_64_SIZE64)
4978 || ! SYMBOL_CALLS_LOCAL (info, h)))
4979 || (ELIMINATE_COPY_RELOCS
4980 && !bfd_link_pic (info)
4984 || eh->func_pointer_refcount > 0
4985 || (h->root.type == bfd_link_hash_undefweak
4986 && !resolved_to_zero))
4987 && ((h->def_dynamic && !h->def_regular)
4988 /* Undefined weak symbol is bound locally when
4990 || h->root.type == bfd_link_hash_undefined)))
4992 Elf_Internal_Rela outrel;
4993 bfd_boolean skip, relocate;
4996 /* When generating a shared object, these relocations
4997 are copied into the output file to be resolved at run
5003 _bfd_elf_section_offset (output_bfd, info, input_section,
5005 if (outrel.r_offset == (bfd_vma) -1)
5007 else if (outrel.r_offset == (bfd_vma) -2)
5008 skip = TRUE, relocate = TRUE;
5010 outrel.r_offset += (input_section->output_section->vma
5011 + input_section->output_offset);
5014 memset (&outrel, 0, sizeof outrel);
5016 /* h->dynindx may be -1 if this symbol was marked to
5020 && (IS_X86_64_PCREL_TYPE (r_type)
5021 || !(bfd_link_executable (info)
5022 || SYMBOLIC_BIND (info, h))
5023 || ! h->def_regular))
5025 outrel.r_info = htab->r_info (h->dynindx, r_type);
5026 outrel.r_addend = rel->r_addend;
5030 /* This symbol is local, or marked to become local.
5031 When relocation overflow check is disabled, we
5032 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
5033 if (r_type == htab->pointer_r_type
5034 || (r_type == R_X86_64_32
5035 && info->no_reloc_overflow_check))
5038 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
5039 outrel.r_addend = relocation + rel->r_addend;
5041 else if (r_type == R_X86_64_64
5042 && !ABI_64_P (output_bfd))
5045 outrel.r_info = htab->r_info (0,
5046 R_X86_64_RELATIVE64);
5047 outrel.r_addend = relocation + rel->r_addend;
5048 /* Check addend overflow. */
5049 if ((outrel.r_addend & 0x80000000)
5050 != (rel->r_addend & 0x80000000))
5053 int addend = rel->r_addend;
5054 if (h && h->root.root.string)
5055 name = h->root.root.string;
5057 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
5061 /* xgettext:c-format */
5062 (_("%B: addend -0x%x in relocation %s against "
5063 "symbol `%s' at 0x%lx in section `%A' is "
5065 input_bfd, addend, howto->name, name,
5066 (unsigned long) rel->r_offset, input_section);
5069 /* xgettext:c-format */
5070 (_("%B: addend 0x%x in relocation %s against "
5071 "symbol `%s' at 0x%lx in section `%A' is "
5073 input_bfd, addend, howto->name, name,
5074 (unsigned long) rel->r_offset, input_section);
5075 bfd_set_error (bfd_error_bad_value);
5083 if (bfd_is_abs_section (sec))
5085 else if (sec == NULL || sec->owner == NULL)
5087 bfd_set_error (bfd_error_bad_value);
5094 /* We are turning this relocation into one
5095 against a section symbol. It would be
5096 proper to subtract the symbol's value,
5097 osec->vma, from the emitted reloc addend,
5098 but ld.so expects buggy relocs. */
5099 osec = sec->output_section;
5100 sindx = elf_section_data (osec)->dynindx;
5103 asection *oi = htab->elf.text_index_section;
5104 sindx = elf_section_data (oi)->dynindx;
5106 BFD_ASSERT (sindx != 0);
5109 outrel.r_info = htab->r_info (sindx, r_type);
5110 outrel.r_addend = relocation + rel->r_addend;
5114 sreloc = elf_section_data (input_section)->sreloc;
5116 if (sreloc == NULL || sreloc->contents == NULL)
5118 r = bfd_reloc_notsupported;
5119 goto check_relocation_error;
5122 elf_append_rela (output_bfd, sreloc, &outrel);
5124 /* If this reloc is against an external symbol, we do
5125 not want to fiddle with the addend. Otherwise, we
5126 need to include the symbol value so that it becomes
5127 an addend for the dynamic reloc. */
5134 case R_X86_64_TLSGD:
5135 case R_X86_64_GOTPC32_TLSDESC:
5136 case R_X86_64_TLSDESC_CALL:
5137 case R_X86_64_GOTTPOFF:
5138 tls_type = GOT_UNKNOWN;
5139 if (h == NULL && local_got_offsets)
5140 tls_type = elf_x86_64_local_got_tls_type (input_bfd) [r_symndx];
5142 tls_type = elf_x86_64_hash_entry (h)->tls_type;
5144 if (! elf_x86_64_tls_transition (info, input_bfd,
5145 input_section, contents,
5146 symtab_hdr, sym_hashes,
5147 &r_type, tls_type, rel,
5148 relend, h, r_symndx, TRUE))
5151 if (r_type == R_X86_64_TPOFF32)
5153 bfd_vma roff = rel->r_offset;
5155 BFD_ASSERT (! unresolved_reloc);
5157 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
5159 /* GD->LE transition. For 64bit, change
5160 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5161 .word 0x6666; rex64; call __tls_get_addr@PLT
5163 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5165 call *__tls_get_addr@GOTPCREL(%rip)
5166 which may be converted to
5167 addr32 call __tls_get_addr
5170 leaq foo@tpoff(%rax), %rax
5172 leaq foo@tlsgd(%rip), %rdi
5173 .word 0x6666; rex64; call __tls_get_addr@PLT
5175 leaq foo@tlsgd(%rip), %rdi
5177 call *__tls_get_addr@GOTPCREL(%rip)
5178 which may be converted to
5179 addr32 call __tls_get_addr
5182 leaq foo@tpoff(%rax), %rax
5183 For largepic, change:
5184 leaq foo@tlsgd(%rip), %rdi
5185 movabsq $__tls_get_addr@pltoff, %rax
5190 leaq foo@tpoff(%rax), %rax
5191 nopw 0x0(%rax,%rax,1) */
5193 if (ABI_64_P (output_bfd))
5195 if (contents[roff + 5] == 0xb8)
5197 memcpy (contents + roff - 3,
5198 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5199 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5203 memcpy (contents + roff - 4,
5204 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5208 memcpy (contents + roff - 3,
5209 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5211 bfd_put_32 (output_bfd,
5212 elf_x86_64_tpoff (info, relocation),
5213 contents + roff + 8 + largepic);
5214 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5215 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5220 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
5222 /* GDesc -> LE transition.
5223 It's originally something like:
5224 leaq x@tlsdesc(%rip), %rax
5227 movl $x@tpoff, %rax. */
5229 unsigned int val, type;
5231 type = bfd_get_8 (input_bfd, contents + roff - 3);
5232 val = bfd_get_8 (input_bfd, contents + roff - 1);
5233 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
5234 contents + roff - 3);
5235 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
5236 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
5237 contents + roff - 1);
5238 bfd_put_32 (output_bfd,
5239 elf_x86_64_tpoff (info, relocation),
5243 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
5245 /* GDesc -> LE transition.
5250 bfd_put_8 (output_bfd, 0x66, contents + roff);
5251 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
5254 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
5256 /* IE->LE transition:
5257 For 64bit, originally it can be one of:
5258 movq foo@gottpoff(%rip), %reg
5259 addq foo@gottpoff(%rip), %reg
5262 leaq foo(%reg), %reg
5264 For 32bit, originally it can be one of:
5265 movq foo@gottpoff(%rip), %reg
5266 addl foo@gottpoff(%rip), %reg
5269 leal foo(%reg), %reg
5272 unsigned int val, type, reg;
5275 val = bfd_get_8 (input_bfd, contents + roff - 3);
5278 type = bfd_get_8 (input_bfd, contents + roff - 2);
5279 reg = bfd_get_8 (input_bfd, contents + roff - 1);
5285 bfd_put_8 (output_bfd, 0x49,
5286 contents + roff - 3);
5287 else if (!ABI_64_P (output_bfd) && val == 0x44)
5288 bfd_put_8 (output_bfd, 0x41,
5289 contents + roff - 3);
5290 bfd_put_8 (output_bfd, 0xc7,
5291 contents + roff - 2);
5292 bfd_put_8 (output_bfd, 0xc0 | reg,
5293 contents + roff - 1);
5297 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5300 bfd_put_8 (output_bfd, 0x49,
5301 contents + roff - 3);
5302 else if (!ABI_64_P (output_bfd) && val == 0x44)
5303 bfd_put_8 (output_bfd, 0x41,
5304 contents + roff - 3);
5305 bfd_put_8 (output_bfd, 0x81,
5306 contents + roff - 2);
5307 bfd_put_8 (output_bfd, 0xc0 | reg,
5308 contents + roff - 1);
5312 /* addq/addl -> leaq/leal */
5314 bfd_put_8 (output_bfd, 0x4d,
5315 contents + roff - 3);
5316 else if (!ABI_64_P (output_bfd) && val == 0x44)
5317 bfd_put_8 (output_bfd, 0x45,
5318 contents + roff - 3);
5319 bfd_put_8 (output_bfd, 0x8d,
5320 contents + roff - 2);
5321 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
5322 contents + roff - 1);
5324 bfd_put_32 (output_bfd,
5325 elf_x86_64_tpoff (info, relocation),
5333 if (htab->elf.sgot == NULL)
5338 off = h->got.offset;
5339 offplt = elf_x86_64_hash_entry (h)->tlsdesc_got;
5343 if (local_got_offsets == NULL)
5346 off = local_got_offsets[r_symndx];
5347 offplt = local_tlsdesc_gotents[r_symndx];
5354 Elf_Internal_Rela outrel;
5358 if (htab->elf.srelgot == NULL)
5361 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5363 if (GOT_TLS_GDESC_P (tls_type))
5365 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
5366 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
5367 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
5368 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
5369 + htab->elf.sgotplt->output_offset
5371 + htab->sgotplt_jump_table_size);
5372 sreloc = htab->elf.srelplt;
5374 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
5376 outrel.r_addend = 0;
5377 elf_append_rela (output_bfd, sreloc, &outrel);
5380 sreloc = htab->elf.srelgot;
5382 outrel.r_offset = (htab->elf.sgot->output_section->vma
5383 + htab->elf.sgot->output_offset + off);
5385 if (GOT_TLS_GD_P (tls_type))
5386 dr_type = R_X86_64_DTPMOD64;
5387 else if (GOT_TLS_GDESC_P (tls_type))
5390 dr_type = R_X86_64_TPOFF64;
5392 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
5393 outrel.r_addend = 0;
5394 if ((dr_type == R_X86_64_TPOFF64
5395 || dr_type == R_X86_64_TLSDESC) && indx == 0)
5396 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
5397 outrel.r_info = htab->r_info (indx, dr_type);
5399 elf_append_rela (output_bfd, sreloc, &outrel);
5401 if (GOT_TLS_GD_P (tls_type))
5405 BFD_ASSERT (! unresolved_reloc);
5406 bfd_put_64 (output_bfd,
5407 relocation - elf_x86_64_dtpoff_base (info),
5408 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5412 bfd_put_64 (output_bfd, 0,
5413 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5414 outrel.r_info = htab->r_info (indx,
5416 outrel.r_offset += GOT_ENTRY_SIZE;
5417 elf_append_rela (output_bfd, sreloc,
5426 local_got_offsets[r_symndx] |= 1;
5429 if (off >= (bfd_vma) -2
5430 && ! GOT_TLS_GDESC_P (tls_type))
5432 if (r_type == ELF32_R_TYPE (rel->r_info))
5434 if (r_type == R_X86_64_GOTPC32_TLSDESC
5435 || r_type == R_X86_64_TLSDESC_CALL)
5436 relocation = htab->elf.sgotplt->output_section->vma
5437 + htab->elf.sgotplt->output_offset
5438 + offplt + htab->sgotplt_jump_table_size;
5440 relocation = htab->elf.sgot->output_section->vma
5441 + htab->elf.sgot->output_offset + off;
5442 unresolved_reloc = FALSE;
5446 bfd_vma roff = rel->r_offset;
5448 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
5450 /* GD->IE transition. For 64bit, change
5451 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5452 .word 0x6666; rex64; call __tls_get_addr@PLT
5454 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5456 call *__tls_get_addr@GOTPCREL(%rip
5457 which may be converted to
5458 addr32 call __tls_get_addr
5461 addq foo@gottpoff(%rip), %rax
5463 leaq foo@tlsgd(%rip), %rdi
5464 .word 0x6666; rex64; call __tls_get_addr@PLT
5466 leaq foo@tlsgd(%rip), %rdi
5468 call *__tls_get_addr@GOTPCREL(%rip)
5469 which may be converted to
5470 addr32 call __tls_get_addr
5473 addq foo@gottpoff(%rip), %rax
5474 For largepic, change:
5475 leaq foo@tlsgd(%rip), %rdi
5476 movabsq $__tls_get_addr@pltoff, %rax
5481 addq foo@gottpoff(%rax), %rax
5482 nopw 0x0(%rax,%rax,1) */
5484 if (ABI_64_P (output_bfd))
5486 if (contents[roff + 5] == 0xb8)
5488 memcpy (contents + roff - 3,
5489 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5490 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5494 memcpy (contents + roff - 4,
5495 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5499 memcpy (contents + roff - 3,
5500 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5503 relocation = (htab->elf.sgot->output_section->vma
5504 + htab->elf.sgot->output_offset + off
5507 - input_section->output_section->vma
5508 - input_section->output_offset
5510 bfd_put_32 (output_bfd, relocation,
5511 contents + roff + 8 + largepic);
5512 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5517 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
5519 /* GDesc -> IE transition.
5520 It's originally something like:
5521 leaq x@tlsdesc(%rip), %rax
5524 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5526 /* Now modify the instruction as appropriate. To
5527 turn a leaq into a movq in the form we use it, it
5528 suffices to change the second byte from 0x8d to
5530 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
5532 bfd_put_32 (output_bfd,
5533 htab->elf.sgot->output_section->vma
5534 + htab->elf.sgot->output_offset + off
5536 - input_section->output_section->vma
5537 - input_section->output_offset
5542 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
5544 /* GDesc -> IE transition.
5551 bfd_put_8 (output_bfd, 0x66, contents + roff);
5552 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
5560 case R_X86_64_TLSLD:
5561 if (! elf_x86_64_tls_transition (info, input_bfd,
5562 input_section, contents,
5563 symtab_hdr, sym_hashes,
5564 &r_type, GOT_UNKNOWN, rel,
5565 relend, h, r_symndx, TRUE))
5568 if (r_type != R_X86_64_TLSLD)
5570 /* LD->LE transition:
5571 leaq foo@tlsld(%rip), %rdi
5572 call __tls_get_addr@PLT
5573 For 64bit, we change it into:
5574 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5575 For 32bit, we change it into:
5576 nopl 0x0(%rax); movl %fs:0, %eax
5578 leaq foo@tlsld(%rip), %rdi;
5579 call *__tls_get_addr@GOTPCREL(%rip)
5580 which may be converted to
5581 addr32 call __tls_get_addr
5582 For 64bit, we change it into:
5583 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5584 For 32bit, we change it into:
5585 nopw 0x0(%rax); movl %fs:0, %eax
5586 For largepic, change:
5587 leaq foo@tlsgd(%rip), %rdi
5588 movabsq $__tls_get_addr@pltoff, %rax
5592 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5595 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
5596 if (ABI_64_P (output_bfd))
5598 if (contents[rel->r_offset + 5] == 0xb8)
5599 memcpy (contents + rel->r_offset - 3,
5600 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5601 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5602 else if (contents[rel->r_offset + 4] == 0xff
5603 || contents[rel->r_offset + 4] == 0x67)
5604 memcpy (contents + rel->r_offset - 3,
5605 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5608 memcpy (contents + rel->r_offset - 3,
5609 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5613 if (contents[rel->r_offset + 4] == 0xff)
5614 memcpy (contents + rel->r_offset - 3,
5615 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5618 memcpy (contents + rel->r_offset - 3,
5619 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5621 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5622 and R_X86_64_PLTOFF64. */
5628 if (htab->elf.sgot == NULL)
5631 off = htab->tls_ld_got.offset;
5636 Elf_Internal_Rela outrel;
5638 if (htab->elf.srelgot == NULL)
5641 outrel.r_offset = (htab->elf.sgot->output_section->vma
5642 + htab->elf.sgot->output_offset + off);
5644 bfd_put_64 (output_bfd, 0,
5645 htab->elf.sgot->contents + off);
5646 bfd_put_64 (output_bfd, 0,
5647 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5648 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
5649 outrel.r_addend = 0;
5650 elf_append_rela (output_bfd, htab->elf.srelgot,
5652 htab->tls_ld_got.offset |= 1;
5654 relocation = htab->elf.sgot->output_section->vma
5655 + htab->elf.sgot->output_offset + off;
5656 unresolved_reloc = FALSE;
5659 case R_X86_64_DTPOFF32:
5660 if (!bfd_link_executable (info)
5661 || (input_section->flags & SEC_CODE) == 0)
5662 relocation -= elf_x86_64_dtpoff_base (info);
5664 relocation = elf_x86_64_tpoff (info, relocation);
5667 case R_X86_64_TPOFF32:
5668 case R_X86_64_TPOFF64:
5669 BFD_ASSERT (bfd_link_executable (info));
5670 relocation = elf_x86_64_tpoff (info, relocation);
5673 case R_X86_64_DTPOFF64:
5674 BFD_ASSERT ((input_section->flags & SEC_CODE) == 0);
5675 relocation -= elf_x86_64_dtpoff_base (info);
5682 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5683 because such sections are not SEC_ALLOC and thus ld.so will
5684 not process them. */
5685 if (unresolved_reloc
5686 && !((input_section->flags & SEC_DEBUGGING) != 0
5688 && _bfd_elf_section_offset (output_bfd, info, input_section,
5689 rel->r_offset) != (bfd_vma) -1)
5692 /* xgettext:c-format */
5693 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5696 (long) rel->r_offset,
5698 h->root.root.string);
5703 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5704 contents, rel->r_offset,
5705 relocation, rel->r_addend);
5707 check_relocation_error:
5708 if (r != bfd_reloc_ok)
5713 name = h->root.root.string;
5716 name = bfd_elf_string_from_elf_section (input_bfd,
5717 symtab_hdr->sh_link,
5722 name = bfd_section_name (input_bfd, sec);
5725 if (r == bfd_reloc_overflow)
5726 (*info->callbacks->reloc_overflow)
5727 (info, (h ? &h->root : NULL), name, howto->name,
5728 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5732 /* xgettext:c-format */
5733 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5734 input_bfd, input_section,
5735 (long) rel->r_offset, name, (int) r);
5746 Elf_Internal_Shdr *rel_hdr;
5747 size_t deleted = rel - wrel;
5749 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
5750 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5751 if (rel_hdr->sh_size == 0)
5753 /* It is too late to remove an empty reloc section. Leave
5755 ??? What is wrong with an empty section??? */
5756 rel_hdr->sh_size = rel_hdr->sh_entsize;
5759 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
5760 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5761 input_section->reloc_count -= deleted;
5767 /* Finish up dynamic symbol handling. We set the contents of various
5768 dynamic sections here. */
5771 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
5772 struct bfd_link_info *info,
5773 struct elf_link_hash_entry *h,
5774 Elf_Internal_Sym *sym)
5776 struct elf_x86_64_link_hash_table *htab;
5777 const struct elf_x86_64_backend_data *abed;
5778 bfd_boolean use_plt_bnd;
5779 struct elf_x86_64_link_hash_entry *eh;
5780 bfd_boolean local_undefweak;
5782 htab = elf_x86_64_hash_table (info);
5786 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5787 section only if there is .plt section. */
5788 use_plt_bnd = htab->elf.splt != NULL && htab->plt_bnd != NULL;
5790 ? &elf_x86_64_bnd_arch_bed
5791 : get_elf_x86_64_backend_data (output_bfd));
5793 eh = (struct elf_x86_64_link_hash_entry *) h;
5794 if (eh->no_finish_dynamic_symbol)
5797 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5798 resolved undefined weak symbols in executable so that their
5799 references have value 0 at run-time. */
5800 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
5804 if (h->plt.offset != (bfd_vma) -1)
5807 bfd_vma got_offset, plt_offset, plt_plt_offset, plt_got_offset;
5808 bfd_vma plt_plt_insn_end, plt_got_insn_size;
5809 Elf_Internal_Rela rela;
5811 asection *plt, *gotplt, *relplt, *resolved_plt;
5812 const struct elf_backend_data *bed;
5813 bfd_vma plt_got_pcrel_offset;
5815 /* When building a static executable, use .iplt, .igot.plt and
5816 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5817 if (htab->elf.splt != NULL)
5819 plt = htab->elf.splt;
5820 gotplt = htab->elf.sgotplt;
5821 relplt = htab->elf.srelplt;
5825 plt = htab->elf.iplt;
5826 gotplt = htab->elf.igotplt;
5827 relplt = htab->elf.irelplt;
5830 /* This symbol has an entry in the procedure linkage table. Set
5832 if ((h->dynindx == -1
5834 && !((h->forced_local || bfd_link_executable (info))
5836 && h->type == STT_GNU_IFUNC))
5842 /* Get the index in the procedure linkage table which
5843 corresponds to this symbol. This is the index of this symbol
5844 in all the symbols for which we are making plt entries. The
5845 first entry in the procedure linkage table is reserved.
5847 Get the offset into the .got table of the entry that
5848 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5849 bytes. The first three are reserved for the dynamic linker.
5851 For static executables, we don't reserve anything. */
5853 if (plt == htab->elf.splt)
5855 got_offset = h->plt.offset / abed->plt_entry_size - 1;
5856 got_offset = (got_offset + 3) * GOT_ENTRY_SIZE;
5860 got_offset = h->plt.offset / abed->plt_entry_size;
5861 got_offset = got_offset * GOT_ENTRY_SIZE;
5864 plt_plt_insn_end = abed->plt_plt_insn_end;
5865 plt_plt_offset = abed->plt_plt_offset;
5866 plt_got_insn_size = abed->plt_got_insn_size;
5867 plt_got_offset = abed->plt_got_offset;
5870 /* Use the second PLT with BND relocations. */
5871 const bfd_byte *plt_entry, *plt2_entry;
5875 plt_entry = elf_x86_64_bnd_plt_entry;
5876 plt2_entry = elf_x86_64_bnd_plt2_entry;
5880 plt_entry = elf_x86_64_legacy_plt_entry;
5881 plt2_entry = elf_x86_64_legacy_plt2_entry;
5883 /* Subtract 1 since there is no BND prefix. */
5884 plt_plt_insn_end -= 1;
5885 plt_plt_offset -= 1;
5886 plt_got_insn_size -= 1;
5887 plt_got_offset -= 1;
5890 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry)
5891 == sizeof (elf_x86_64_legacy_plt_entry));
5893 /* Fill in the entry in the procedure linkage table. */
5894 memcpy (plt->contents + h->plt.offset,
5895 plt_entry, sizeof (elf_x86_64_legacy_plt_entry));
5896 /* Fill in the entry in the second PLT. */
5897 memcpy (htab->plt_bnd->contents + eh->plt_bnd.offset,
5898 plt2_entry, sizeof (elf_x86_64_legacy_plt2_entry));
5900 resolved_plt = htab->plt_bnd;
5901 plt_offset = eh->plt_bnd.offset;
5905 /* Fill in the entry in the procedure linkage table. */
5906 memcpy (plt->contents + h->plt.offset, abed->plt_entry,
5907 abed->plt_entry_size);
5910 plt_offset = h->plt.offset;
5913 /* Insert the relocation positions of the plt section. */
5915 /* Put offset the PC-relative instruction referring to the GOT entry,
5916 subtracting the size of that instruction. */
5917 plt_got_pcrel_offset = (gotplt->output_section->vma
5918 + gotplt->output_offset
5920 - resolved_plt->output_section->vma
5921 - resolved_plt->output_offset
5923 - plt_got_insn_size);
5925 /* Check PC-relative offset overflow in PLT entry. */
5926 if ((plt_got_pcrel_offset + 0x80000000) > 0xffffffff)
5927 /* xgettext:c-format */
5928 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5929 output_bfd, h->root.root.string);
5931 bfd_put_32 (output_bfd, plt_got_pcrel_offset,
5932 resolved_plt->contents + plt_offset + plt_got_offset);
5934 /* Fill in the entry in the global offset table, initially this
5935 points to the second part of the PLT entry. Leave the entry
5936 as zero for undefined weak symbol in PIE. No PLT relocation
5937 against undefined weak symbol in PIE. */
5938 if (!local_undefweak)
5940 bfd_put_64 (output_bfd, (plt->output_section->vma
5941 + plt->output_offset
5943 + abed->plt_lazy_offset),
5944 gotplt->contents + got_offset);
5946 /* Fill in the entry in the .rela.plt section. */
5947 rela.r_offset = (gotplt->output_section->vma
5948 + gotplt->output_offset
5950 if (h->dynindx == -1
5951 || ((bfd_link_executable (info)
5952 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5954 && h->type == STT_GNU_IFUNC))
5956 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5957 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5958 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
5959 rela.r_addend = (h->root.u.def.value
5960 + h->root.u.def.section->output_section->vma
5961 + h->root.u.def.section->output_offset);
5962 /* R_X86_64_IRELATIVE comes last. */
5963 plt_index = htab->next_irelative_index--;
5967 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
5969 plt_index = htab->next_jump_slot_index++;
5972 /* Don't fill PLT entry for static executables. */
5973 if (plt == htab->elf.splt)
5975 bfd_vma plt0_offset = h->plt.offset + plt_plt_insn_end;
5977 /* Put relocation index. */
5978 bfd_put_32 (output_bfd, plt_index,
5979 (plt->contents + h->plt.offset
5980 + abed->plt_reloc_offset));
5982 /* Put offset for jmp .PLT0 and check for overflow. We don't
5983 check relocation index for overflow since branch displacement
5984 will overflow first. */
5985 if (plt0_offset > 0x80000000)
5986 /* xgettext:c-format */
5987 info->callbacks->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5988 output_bfd, h->root.root.string);
5989 bfd_put_32 (output_bfd, - plt0_offset,
5990 plt->contents + h->plt.offset + plt_plt_offset);
5993 bed = get_elf_backend_data (output_bfd);
5994 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
5995 bed->s->swap_reloca_out (output_bfd, &rela, loc);
5998 else if (eh->plt_got.offset != (bfd_vma) -1)
6000 bfd_vma got_offset, plt_offset, plt_got_offset, plt_got_insn_size;
6001 asection *plt, *got;
6002 bfd_boolean got_after_plt;
6003 int32_t got_pcrel_offset;
6004 const bfd_byte *got_plt_entry;
6006 /* Set the entry in the GOT procedure linkage table. */
6007 plt = htab->plt_got;
6008 got = htab->elf.sgot;
6009 got_offset = h->got.offset;
6011 if (got_offset == (bfd_vma) -1
6012 || (h->type == STT_GNU_IFUNC && h->def_regular)
6017 /* Use the second PLT entry template for the GOT PLT since they
6018 are the identical. */
6019 plt_got_insn_size = elf_x86_64_bnd_arch_bed.plt_got_insn_size;
6020 plt_got_offset = elf_x86_64_bnd_arch_bed.plt_got_offset;
6022 got_plt_entry = elf_x86_64_bnd_plt2_entry;
6025 got_plt_entry = elf_x86_64_legacy_plt2_entry;
6027 /* Subtract 1 since there is no BND prefix. */
6028 plt_got_insn_size -= 1;
6029 plt_got_offset -= 1;
6032 /* Fill in the entry in the GOT procedure linkage table. */
6033 plt_offset = eh->plt_got.offset;
6034 memcpy (plt->contents + plt_offset,
6035 got_plt_entry, sizeof (elf_x86_64_legacy_plt2_entry));
6037 /* Put offset the PC-relative instruction referring to the GOT
6038 entry, subtracting the size of that instruction. */
6039 got_pcrel_offset = (got->output_section->vma
6040 + got->output_offset
6042 - plt->output_section->vma
6043 - plt->output_offset
6045 - plt_got_insn_size);
6047 /* Check PC-relative offset overflow in GOT PLT entry. */
6048 got_after_plt = got->output_section->vma > plt->output_section->vma;
6049 if ((got_after_plt && got_pcrel_offset < 0)
6050 || (!got_after_plt && got_pcrel_offset > 0))
6051 /* xgettext:c-format */
6052 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
6053 output_bfd, h->root.root.string);
6055 bfd_put_32 (output_bfd, got_pcrel_offset,
6056 plt->contents + plt_offset + plt_got_offset);
6059 if (!local_undefweak
6061 && (h->plt.offset != (bfd_vma) -1
6062 || eh->plt_got.offset != (bfd_vma) -1))
6064 /* Mark the symbol as undefined, rather than as defined in
6065 the .plt section. Leave the value if there were any
6066 relocations where pointer equality matters (this is a clue
6067 for the dynamic linker, to make function pointer
6068 comparisons work between an application and shared
6069 library), otherwise set it to zero. If a function is only
6070 called from a binary, there is no need to slow down
6071 shared libraries because of that. */
6072 sym->st_shndx = SHN_UNDEF;
6073 if (!h->pointer_equality_needed)
6077 /* Don't generate dynamic GOT relocation against undefined weak
6078 symbol in executable. */
6079 if (h->got.offset != (bfd_vma) -1
6080 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h)->tls_type)
6081 && elf_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE
6082 && !local_undefweak)
6084 Elf_Internal_Rela rela;
6085 asection *relgot = htab->elf.srelgot;
6087 /* This symbol has an entry in the global offset table. Set it
6089 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
6092 rela.r_offset = (htab->elf.sgot->output_section->vma
6093 + htab->elf.sgot->output_offset
6094 + (h->got.offset &~ (bfd_vma) 1));
6096 /* If this is a static link, or it is a -Bsymbolic link and the
6097 symbol is defined locally or was forced to be local because
6098 of a version file, we just want to emit a RELATIVE reloc.
6099 The entry in the global offset table will already have been
6100 initialized in the relocate_section function. */
6102 && h->type == STT_GNU_IFUNC)
6104 if (h->plt.offset == (bfd_vma) -1)
6106 /* STT_GNU_IFUNC is referenced without PLT. */
6107 if (htab->elf.splt == NULL)
6109 /* use .rel[a].iplt section to store .got relocations
6110 in static executable. */
6111 relgot = htab->elf.irelplt;
6113 if (SYMBOL_REFERENCES_LOCAL (info, h))
6115 rela.r_info = htab->r_info (0,
6116 R_X86_64_IRELATIVE);
6117 rela.r_addend = (h->root.u.def.value
6118 + h->root.u.def.section->output_section->vma
6119 + h->root.u.def.section->output_offset);
6124 else if (bfd_link_pic (info))
6126 /* Generate R_X86_64_GLOB_DAT. */
6133 if (!h->pointer_equality_needed)
6136 /* For non-shared object, we can't use .got.plt, which
6137 contains the real function addres if we need pointer
6138 equality. We load the GOT entry with the PLT entry. */
6139 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
6140 bfd_put_64 (output_bfd, (plt->output_section->vma
6141 + plt->output_offset
6143 htab->elf.sgot->contents + h->got.offset);
6147 else if (bfd_link_pic (info)
6148 && SYMBOL_REFERENCES_LOCAL (info, h))
6150 if (!h->def_regular)
6152 BFD_ASSERT((h->got.offset & 1) != 0);
6153 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
6154 rela.r_addend = (h->root.u.def.value
6155 + h->root.u.def.section->output_section->vma
6156 + h->root.u.def.section->output_offset);
6160 BFD_ASSERT((h->got.offset & 1) == 0);
6162 bfd_put_64 (output_bfd, (bfd_vma) 0,
6163 htab->elf.sgot->contents + h->got.offset);
6164 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
6168 elf_append_rela (output_bfd, relgot, &rela);
6173 Elf_Internal_Rela rela;
6176 /* This symbol needs a copy reloc. Set it up. */
6178 if (h->dynindx == -1
6179 || (h->root.type != bfd_link_hash_defined
6180 && h->root.type != bfd_link_hash_defweak)
6181 || htab->elf.srelbss == NULL
6182 || htab->elf.sreldynrelro == NULL)
6185 rela.r_offset = (h->root.u.def.value
6186 + h->root.u.def.section->output_section->vma
6187 + h->root.u.def.section->output_offset);
6188 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
6190 if (h->root.u.def.section == htab->elf.sdynrelro)
6191 s = htab->elf.sreldynrelro;
6193 s = htab->elf.srelbss;
6194 elf_append_rela (output_bfd, s, &rela);
6200 /* Finish up local dynamic symbol handling. We set the contents of
6201 various dynamic sections here. */
6204 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
6206 struct elf_link_hash_entry *h
6207 = (struct elf_link_hash_entry *) *slot;
6208 struct bfd_link_info *info
6209 = (struct bfd_link_info *) inf;
6211 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
6215 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6216 here since undefined weak symbol may not be dynamic and may not be
6217 called for elf_x86_64_finish_dynamic_symbol. */
6220 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
6223 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
6224 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6226 if (h->root.type != bfd_link_hash_undefweak
6227 || h->dynindx != -1)
6230 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
6234 /* Used to decide how to sort relocs in an optimal manner for the
6235 dynamic linker, before writing them out. */
6237 static enum elf_reloc_type_class
6238 elf_x86_64_reloc_type_class (const struct bfd_link_info *info,
6239 const asection *rel_sec ATTRIBUTE_UNUSED,
6240 const Elf_Internal_Rela *rela)
6242 bfd *abfd = info->output_bfd;
6243 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6244 struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
6246 if (htab->elf.dynsym != NULL
6247 && htab->elf.dynsym->contents != NULL)
6249 /* Check relocation against STT_GNU_IFUNC symbol if there are
6251 unsigned long r_symndx = htab->r_sym (rela->r_info);
6252 if (r_symndx != STN_UNDEF)
6254 Elf_Internal_Sym sym;
6255 if (!bed->s->swap_symbol_in (abfd,
6256 (htab->elf.dynsym->contents
6257 + r_symndx * bed->s->sizeof_sym),
6261 if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
6262 return reloc_class_ifunc;
6266 switch ((int) ELF32_R_TYPE (rela->r_info))
6268 case R_X86_64_IRELATIVE:
6269 return reloc_class_ifunc;
6270 case R_X86_64_RELATIVE:
6271 case R_X86_64_RELATIVE64:
6272 return reloc_class_relative;
6273 case R_X86_64_JUMP_SLOT:
6274 return reloc_class_plt;
6276 return reloc_class_copy;
6278 return reloc_class_normal;
6282 /* Finish up the dynamic sections. */
6285 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
6286 struct bfd_link_info *info)
6288 struct elf_x86_64_link_hash_table *htab;
6291 const struct elf_x86_64_backend_data *abed;
6293 htab = elf_x86_64_hash_table (info);
6297 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6298 section only if there is .plt section. */
6299 abed = (htab->elf.splt != NULL && htab->plt_bnd != NULL
6300 ? &elf_x86_64_bnd_arch_bed
6301 : get_elf_x86_64_backend_data (output_bfd));
6303 dynobj = htab->elf.dynobj;
6304 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
6306 if (htab->elf.dynamic_sections_created)
6308 bfd_byte *dyncon, *dynconend;
6309 const struct elf_backend_data *bed;
6310 bfd_size_type sizeof_dyn;
6312 if (sdyn == NULL || htab->elf.sgot == NULL)
6315 bed = get_elf_backend_data (dynobj);
6316 sizeof_dyn = bed->s->sizeof_dyn;
6317 dyncon = sdyn->contents;
6318 dynconend = sdyn->contents + sdyn->size;
6319 for (; dyncon < dynconend; dyncon += sizeof_dyn)
6321 Elf_Internal_Dyn dyn;
6324 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
6332 s = htab->elf.sgotplt;
6333 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6337 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
6341 s = htab->elf.srelplt->output_section;
6342 dyn.d_un.d_val = s->size;
6345 case DT_TLSDESC_PLT:
6347 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
6348 + htab->tlsdesc_plt;
6351 case DT_TLSDESC_GOT:
6353 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
6354 + htab->tlsdesc_got;
6358 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
6361 /* Fill in the special first entry in the procedure linkage table. */
6362 if (htab->elf.splt && htab->elf.splt->size > 0)
6364 /* Fill in the first entry in the procedure linkage table. */
6365 memcpy (htab->elf.splt->contents,
6366 abed->plt0_entry, abed->plt_entry_size);
6367 /* Add offset for pushq GOT+8(%rip), since the instruction
6368 uses 6 bytes subtract this value. */
6369 bfd_put_32 (output_bfd,
6370 (htab->elf.sgotplt->output_section->vma
6371 + htab->elf.sgotplt->output_offset
6373 - htab->elf.splt->output_section->vma
6374 - htab->elf.splt->output_offset
6376 htab->elf.splt->contents + abed->plt0_got1_offset);
6377 /* Add offset for the PC-relative instruction accessing GOT+16,
6378 subtracting the offset to the end of that instruction. */
6379 bfd_put_32 (output_bfd,
6380 (htab->elf.sgotplt->output_section->vma
6381 + htab->elf.sgotplt->output_offset
6383 - htab->elf.splt->output_section->vma
6384 - htab->elf.splt->output_offset
6385 - abed->plt0_got2_insn_end),
6386 htab->elf.splt->contents + abed->plt0_got2_offset);
6388 elf_section_data (htab->elf.splt->output_section)
6389 ->this_hdr.sh_entsize = abed->plt_entry_size;
6391 if (htab->tlsdesc_plt)
6393 bfd_put_64 (output_bfd, (bfd_vma) 0,
6394 htab->elf.sgot->contents + htab->tlsdesc_got);
6396 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
6397 abed->plt0_entry, abed->plt_entry_size);
6399 /* Add offset for pushq GOT+8(%rip), since the
6400 instruction uses 6 bytes subtract this value. */
6401 bfd_put_32 (output_bfd,
6402 (htab->elf.sgotplt->output_section->vma
6403 + htab->elf.sgotplt->output_offset
6405 - htab->elf.splt->output_section->vma
6406 - htab->elf.splt->output_offset
6409 htab->elf.splt->contents
6410 + htab->tlsdesc_plt + abed->plt0_got1_offset);
6411 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6412 where TGD stands for htab->tlsdesc_got, subtracting the offset
6413 to the end of that instruction. */
6414 bfd_put_32 (output_bfd,
6415 (htab->elf.sgot->output_section->vma
6416 + htab->elf.sgot->output_offset
6418 - htab->elf.splt->output_section->vma
6419 - htab->elf.splt->output_offset
6421 - abed->plt0_got2_insn_end),
6422 htab->elf.splt->contents
6423 + htab->tlsdesc_plt + abed->plt0_got2_offset);
6428 if (htab->plt_bnd != NULL)
6429 elf_section_data (htab->plt_bnd->output_section)
6430 ->this_hdr.sh_entsize = sizeof (elf_x86_64_bnd_plt2_entry);
6432 if (htab->elf.sgotplt)
6434 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
6437 (_("discarded output section: `%A'"), htab->elf.sgotplt);
6441 /* Fill in the first three entries in the global offset table. */
6442 if (htab->elf.sgotplt->size > 0)
6444 /* Set the first entry in the global offset table to the address of
6445 the dynamic section. */
6447 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
6449 bfd_put_64 (output_bfd,
6450 sdyn->output_section->vma + sdyn->output_offset,
6451 htab->elf.sgotplt->contents);
6452 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6453 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
6454 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
6457 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
6461 /* Adjust .eh_frame for .plt section. */
6462 if (htab->plt_eh_frame != NULL
6463 && htab->plt_eh_frame->contents != NULL)
6465 if (htab->elf.splt != NULL
6466 && htab->elf.splt->size != 0
6467 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
6468 && htab->elf.splt->output_section != NULL
6469 && htab->plt_eh_frame->output_section != NULL)
6471 bfd_vma plt_start = htab->elf.splt->output_section->vma;
6472 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
6473 + htab->plt_eh_frame->output_offset
6474 + PLT_FDE_START_OFFSET;
6475 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6476 htab->plt_eh_frame->contents
6477 + PLT_FDE_START_OFFSET);
6479 if (htab->plt_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6481 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6483 htab->plt_eh_frame->contents))
6488 /* Adjust .eh_frame for .plt.got section. */
6489 if (htab->plt_got_eh_frame != NULL
6490 && htab->plt_got_eh_frame->contents != NULL)
6492 if (htab->plt_got != NULL
6493 && htab->plt_got->size != 0
6494 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
6495 && htab->plt_got->output_section != NULL
6496 && htab->plt_got_eh_frame->output_section != NULL)
6498 bfd_vma plt_start = htab->plt_got->output_section->vma;
6499 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
6500 + htab->plt_got_eh_frame->output_offset
6501 + PLT_FDE_START_OFFSET;
6502 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6503 htab->plt_got_eh_frame->contents
6504 + PLT_FDE_START_OFFSET);
6506 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6508 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6509 htab->plt_got_eh_frame,
6510 htab->plt_got_eh_frame->contents))
6515 /* Adjust .eh_frame for .plt.bnd section. */
6516 if (htab->plt_bnd_eh_frame != NULL
6517 && htab->plt_bnd_eh_frame->contents != NULL)
6519 if (htab->plt_bnd != NULL
6520 && htab->plt_bnd->size != 0
6521 && (htab->plt_bnd->flags & SEC_EXCLUDE) == 0
6522 && htab->plt_bnd->output_section != NULL
6523 && htab->plt_bnd_eh_frame->output_section != NULL)
6525 bfd_vma plt_start = htab->plt_bnd->output_section->vma;
6526 bfd_vma eh_frame_start = htab->plt_bnd_eh_frame->output_section->vma
6527 + htab->plt_bnd_eh_frame->output_offset
6528 + PLT_FDE_START_OFFSET;
6529 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
6530 htab->plt_bnd_eh_frame->contents
6531 + PLT_FDE_START_OFFSET);
6533 if (htab->plt_bnd_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
6535 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
6536 htab->plt_bnd_eh_frame,
6537 htab->plt_bnd_eh_frame->contents))
6542 if (htab->elf.sgot && htab->elf.sgot->size > 0)
6543 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
6546 /* Fill PLT entries for undefined weak symbols in PIE. */
6547 if (bfd_link_pie (info))
6548 bfd_hash_traverse (&info->hash->table,
6549 elf_x86_64_pie_finish_undefweak_symbol,
6555 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6556 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6557 It has to be done before elf_link_sort_relocs is called so that
6558 dynamic relocations are properly sorted. */
6561 elf_x86_64_output_arch_local_syms
6562 (bfd *output_bfd ATTRIBUTE_UNUSED,
6563 struct bfd_link_info *info,
6564 void *flaginfo ATTRIBUTE_UNUSED,
6565 int (*func) (void *, const char *,
6568 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
6570 struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
6574 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6575 htab_traverse (htab->loc_hash_table,
6576 elf_x86_64_finish_local_dynamic_symbol,
6582 /* Return an array of PLT entry symbol values. */
6585 elf_x86_64_get_plt_sym_val (bfd *abfd, asymbol **dynsyms, asection *plt,
6588 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
6591 bfd_vma *plt_sym_val;
6593 bfd_byte *plt_contents;
6594 const struct elf_x86_64_backend_data *bed;
6595 Elf_Internal_Shdr *hdr;
6598 /* Get the .plt section contents. PLT passed down may point to the
6599 .plt.bnd section. Make sure that PLT always points to the .plt
6601 plt_bnd = bfd_get_section_by_name (abfd, ".plt.bnd");
6606 plt = bfd_get_section_by_name (abfd, ".plt");
6609 bed = &elf_x86_64_bnd_arch_bed;
6612 bed = get_elf_x86_64_backend_data (abfd);
6614 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
6615 if (plt_contents == NULL)
6617 if (!bfd_get_section_contents (abfd, (asection *) plt,
6618 plt_contents, 0, plt->size))
6621 free (plt_contents);
6625 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
6626 if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
6629 hdr = &elf_section_data (relplt)->this_hdr;
6630 count = relplt->size / hdr->sh_entsize;
6632 plt_sym_val = (bfd_vma *) bfd_malloc (sizeof (bfd_vma) * count);
6633 if (plt_sym_val == NULL)
6636 for (i = 0; i < count; i++)
6637 plt_sym_val[i] = -1;
6639 plt_offset = bed->plt_entry_size;
6640 p = relplt->relocation;
6641 for (i = 0; i < count; i++, p++)
6645 /* Skip unknown relocation. */
6646 if (p->howto == NULL)
6649 if (p->howto->type != R_X86_64_JUMP_SLOT
6650 && p->howto->type != R_X86_64_IRELATIVE)
6653 reloc_index = H_GET_32 (abfd, (plt_contents + plt_offset
6654 + bed->plt_reloc_offset));
6655 if (reloc_index < count)
6659 /* This is the index in .plt section. */
6660 long plt_index = plt_offset / bed->plt_entry_size;
6661 /* Store VMA + the offset in .plt.bnd section. */
6662 plt_sym_val[reloc_index] =
6664 + (plt_index - 1) * sizeof (elf_x86_64_legacy_plt2_entry));
6667 plt_sym_val[reloc_index] = plt->vma + plt_offset;
6669 plt_offset += bed->plt_entry_size;
6671 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6673 if (plt_offset >= plt->size)
6677 free (plt_contents);
6682 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6686 elf_x86_64_get_synthetic_symtab (bfd *abfd,
6693 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6694 as PLT if it exists. */
6695 asection *plt = bfd_get_section_by_name (abfd, ".plt.bnd");
6697 plt = bfd_get_section_by_name (abfd, ".plt");
6698 return _bfd_elf_ifunc_get_synthetic_symtab (abfd, symcount, syms,
6699 dynsymcount, dynsyms, ret,
6701 elf_x86_64_get_plt_sym_val);
6704 /* Handle an x86-64 specific section when reading an object file. This
6705 is called when elfcode.h finds a section with an unknown type. */
6708 elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr,
6709 const char *name, int shindex)
6711 if (hdr->sh_type != SHT_X86_64_UNWIND)
6714 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6720 /* Hook called by the linker routine which adds symbols from an object
6721 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6725 elf_x86_64_add_symbol_hook (bfd *abfd,
6726 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6727 Elf_Internal_Sym *sym,
6728 const char **namep ATTRIBUTE_UNUSED,
6729 flagword *flagsp ATTRIBUTE_UNUSED,
6735 switch (sym->st_shndx)
6737 case SHN_X86_64_LCOMMON:
6738 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
6741 lcomm = bfd_make_section_with_flags (abfd,
6745 | SEC_LINKER_CREATED));
6748 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
6751 *valp = sym->st_size;
6759 /* Given a BFD section, try to locate the corresponding ELF section
6763 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
6764 asection *sec, int *index_return)
6766 if (sec == &_bfd_elf_large_com_section)
6768 *index_return = SHN_X86_64_LCOMMON;
6774 /* Process a symbol. */
6777 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
6780 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
6782 switch (elfsym->internal_elf_sym.st_shndx)
6784 case SHN_X86_64_LCOMMON:
6785 asym->section = &_bfd_elf_large_com_section;
6786 asym->value = elfsym->internal_elf_sym.st_size;
6787 /* Common symbol doesn't set BSF_GLOBAL. */
6788 asym->flags &= ~BSF_GLOBAL;
6794 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
6796 return (sym->st_shndx == SHN_COMMON
6797 || sym->st_shndx == SHN_X86_64_LCOMMON);
6801 elf_x86_64_common_section_index (asection *sec)
6803 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6806 return SHN_X86_64_LCOMMON;
6810 elf_x86_64_common_section (asection *sec)
6812 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6813 return bfd_com_section_ptr;
6815 return &_bfd_elf_large_com_section;
6819 elf_x86_64_merge_symbol (struct elf_link_hash_entry *h,
6820 const Elf_Internal_Sym *sym,
6825 const asection *oldsec)
6827 /* A normal common symbol and a large common symbol result in a
6828 normal common symbol. We turn the large common symbol into a
6831 && h->root.type == bfd_link_hash_common
6833 && bfd_is_com_section (*psec)
6836 if (sym->st_shndx == SHN_COMMON
6837 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) != 0)
6839 h->root.u.c.p->section
6840 = bfd_make_section_old_way (oldbfd, "COMMON");
6841 h->root.u.c.p->section->flags = SEC_ALLOC;
6843 else if (sym->st_shndx == SHN_X86_64_LCOMMON
6844 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) == 0)
6845 *psec = bfd_com_section_ptr;
6852 elf_x86_64_additional_program_headers (bfd *abfd,
6853 struct bfd_link_info *info ATTRIBUTE_UNUSED)
6858 /* Check to see if we need a large readonly segment. */
6859 s = bfd_get_section_by_name (abfd, ".lrodata");
6860 if (s && (s->flags & SEC_LOAD))
6863 /* Check to see if we need a large data segment. Since .lbss sections
6864 is placed right after the .bss section, there should be no need for
6865 a large data segment just because of .lbss. */
6866 s = bfd_get_section_by_name (abfd, ".ldata");
6867 if (s && (s->flags & SEC_LOAD))
6873 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6876 elf_x86_64_hash_symbol (struct elf_link_hash_entry *h)
6878 if (h->plt.offset != (bfd_vma) -1
6880 && !h->pointer_equality_needed)
6883 return _bfd_elf_hash_symbol (h);
6886 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6889 elf_x86_64_relocs_compatible (const bfd_target *input,
6890 const bfd_target *output)
6892 return ((xvec_get_elf_backend_data (input)->s->elfclass
6893 == xvec_get_elf_backend_data (output)->s->elfclass)
6894 && _bfd_elf_relocs_compatible (input, output));
6897 /* Parse x86-64 GNU properties. */
6899 static enum elf_property_kind
6900 elf_x86_64_parse_gnu_properties (bfd *abfd, unsigned int type,
6901 bfd_byte *ptr, unsigned int datasz)
6907 case GNU_PROPERTY_X86_ISA_1_USED:
6908 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6912 ((type == GNU_PROPERTY_X86_ISA_1_USED
6913 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6914 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>")),
6916 return property_corrupt;
6918 prop = _bfd_elf_get_property (abfd, type, datasz);
6919 prop->u.number = bfd_h_get_32 (abfd, ptr);
6920 prop->pr_kind = property_number;
6924 return property_ignored;
6927 return property_number;
6930 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
6931 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6932 should be merged with ABFD. */
6935 elf_x86_64_merge_gnu_properties (bfd *abfd ATTRIBUTE_UNUSED,
6936 elf_property *aprop,
6937 elf_property *bprop)
6939 unsigned int number;
6940 bfd_boolean updated = FALSE;
6941 unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
6945 case GNU_PROPERTY_X86_ISA_1_USED:
6946 case GNU_PROPERTY_X86_ISA_1_NEEDED:
6947 if (aprop != NULL && bprop != NULL)
6949 number = aprop->u.number;
6950 aprop->u.number = number | bprop->u.number;
6951 updated = number != (unsigned int) aprop->u.number;
6955 /* Return TRUE if APROP is NULL to indicate that BPROP should
6956 be added to ABFD. */
6957 updated = aprop == NULL;
6962 /* Never should happen. */
6969 static const struct bfd_elf_special_section
6970 elf_x86_64_special_sections[]=
6972 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6973 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6974 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
6975 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6976 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6977 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6978 { NULL, 0, 0, 0, 0 }
6981 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6982 #define TARGET_LITTLE_NAME "elf64-x86-64"
6983 #define ELF_ARCH bfd_arch_i386
6984 #define ELF_TARGET_ID X86_64_ELF_DATA
6985 #define ELF_MACHINE_CODE EM_X86_64
6986 #define ELF_MAXPAGESIZE 0x200000
6987 #define ELF_MINPAGESIZE 0x1000
6988 #define ELF_COMMONPAGESIZE 0x1000
6990 #define elf_backend_can_gc_sections 1
6991 #define elf_backend_can_refcount 1
6992 #define elf_backend_want_got_plt 1
6993 #define elf_backend_plt_readonly 1
6994 #define elf_backend_want_plt_sym 0
6995 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6996 #define elf_backend_rela_normal 1
6997 #define elf_backend_plt_alignment 4
6998 #define elf_backend_extern_protected_data 1
6999 #define elf_backend_caches_rawsize 1
7000 #define elf_backend_dtrel_excludes_plt 1
7001 #define elf_backend_want_dynrelro 1
7003 #define elf_info_to_howto elf_x86_64_info_to_howto
7005 #define bfd_elf64_bfd_link_hash_table_create \
7006 elf_x86_64_link_hash_table_create
7007 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7008 #define bfd_elf64_bfd_reloc_name_lookup \
7009 elf_x86_64_reloc_name_lookup
7011 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7012 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7013 #define elf_backend_check_relocs elf_x86_64_check_relocs
7014 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7015 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
7016 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7017 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7018 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7019 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7020 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7021 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7023 #define elf_backend_write_core_note elf_x86_64_write_core_note
7025 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7026 #define elf_backend_relocate_section elf_x86_64_relocate_section
7027 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7028 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7029 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7030 #define elf_backend_object_p elf64_x86_64_elf_object_p
7031 #define bfd_elf64_mkobject elf_x86_64_mkobject
7032 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7034 #define elf_backend_section_from_shdr \
7035 elf_x86_64_section_from_shdr
7037 #define elf_backend_section_from_bfd_section \
7038 elf_x86_64_elf_section_from_bfd_section
7039 #define elf_backend_add_symbol_hook \
7040 elf_x86_64_add_symbol_hook
7041 #define elf_backend_symbol_processing \
7042 elf_x86_64_symbol_processing
7043 #define elf_backend_common_section_index \
7044 elf_x86_64_common_section_index
7045 #define elf_backend_common_section \
7046 elf_x86_64_common_section
7047 #define elf_backend_common_definition \
7048 elf_x86_64_common_definition
7049 #define elf_backend_merge_symbol \
7050 elf_x86_64_merge_symbol
7051 #define elf_backend_special_sections \
7052 elf_x86_64_special_sections
7053 #define elf_backend_additional_program_headers \
7054 elf_x86_64_additional_program_headers
7055 #define elf_backend_hash_symbol \
7056 elf_x86_64_hash_symbol
7057 #define elf_backend_omit_section_dynsym \
7058 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7059 #define elf_backend_fixup_symbol \
7060 elf_x86_64_fixup_symbol
7061 #define elf_backend_parse_gnu_properties \
7062 elf_x86_64_parse_gnu_properties
7063 #define elf_backend_merge_gnu_properties \
7064 elf_x86_64_merge_gnu_properties
7066 #include "elf64-target.h"
7068 /* CloudABI support. */
7070 #undef TARGET_LITTLE_SYM
7071 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7072 #undef TARGET_LITTLE_NAME
7073 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7076 #define ELF_OSABI ELFOSABI_CLOUDABI
7079 #define elf64_bed elf64_x86_64_cloudabi_bed
7081 #include "elf64-target.h"
7083 /* FreeBSD support. */
7085 #undef TARGET_LITTLE_SYM
7086 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7087 #undef TARGET_LITTLE_NAME
7088 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7091 #define ELF_OSABI ELFOSABI_FREEBSD
7094 #define elf64_bed elf64_x86_64_fbsd_bed
7096 #include "elf64-target.h"
7098 /* Solaris 2 support. */
7100 #undef TARGET_LITTLE_SYM
7101 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7102 #undef TARGET_LITTLE_NAME
7103 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7105 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7106 objects won't be recognized. */
7110 #define elf64_bed elf64_x86_64_sol2_bed
7112 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7114 #undef elf_backend_static_tls_alignment
7115 #define elf_backend_static_tls_alignment 16
7117 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7119 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7121 #undef elf_backend_want_plt_sym
7122 #define elf_backend_want_plt_sym 1
7124 #undef elf_backend_strtab_flags
7125 #define elf_backend_strtab_flags SHF_STRINGS
7128 elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
7129 bfd *obfd ATTRIBUTE_UNUSED,
7130 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
7131 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
7133 /* PR 19938: FIXME: Need to add code for setting the sh_info
7134 and sh_link fields of Solaris specific section types. */
7138 #undef elf_backend_copy_special_section_fields
7139 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7141 #include "elf64-target.h"
7143 /* Native Client support. */
7146 elf64_x86_64_nacl_elf_object_p (bfd *abfd)
7148 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7149 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64_nacl);
7153 #undef TARGET_LITTLE_SYM
7154 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7155 #undef TARGET_LITTLE_NAME
7156 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7158 #define elf64_bed elf64_x86_64_nacl_bed
7160 #undef ELF_MAXPAGESIZE
7161 #undef ELF_MINPAGESIZE
7162 #undef ELF_COMMONPAGESIZE
7163 #define ELF_MAXPAGESIZE 0x10000
7164 #define ELF_MINPAGESIZE 0x10000
7165 #define ELF_COMMONPAGESIZE 0x10000
7167 /* Restore defaults. */
7169 #undef elf_backend_static_tls_alignment
7170 #undef elf_backend_want_plt_sym
7171 #define elf_backend_want_plt_sym 0
7172 #undef elf_backend_strtab_flags
7173 #undef elf_backend_copy_special_section_fields
7175 /* NaCl uses substantially different PLT entries for the same effects. */
7177 #undef elf_backend_plt_alignment
7178 #define elf_backend_plt_alignment 5
7179 #define NACL_PLT_ENTRY_SIZE 64
7180 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7182 static const bfd_byte elf_x86_64_nacl_plt0_entry[NACL_PLT_ENTRY_SIZE] =
7184 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7185 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7186 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7187 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7188 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7190 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7191 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7193 /* 32 bytes of nop to pad out to the standard size. */
7194 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7195 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7196 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7197 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7198 0x66, /* excess data16 prefix */
7202 static const bfd_byte elf_x86_64_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
7204 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7205 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7206 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7207 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7209 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7210 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7211 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7213 /* Lazy GOT entries point here (32-byte aligned). */
7214 0x68, /* pushq immediate */
7215 0, 0, 0, 0, /* replaced with index into relocation table. */
7216 0xe9, /* jmp relative */
7217 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7219 /* 22 bytes of nop to pad out to the standard size. */
7220 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7221 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7222 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7225 /* .eh_frame covering the .plt section. */
7227 static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] =
7229 #if (PLT_CIE_LENGTH != 20 \
7230 || PLT_FDE_LENGTH != 36 \
7231 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7232 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7233 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7235 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
7236 0, 0, 0, 0, /* CIE ID */
7237 1, /* CIE version */
7238 'z', 'R', 0, /* Augmentation string */
7239 1, /* Code alignment factor */
7240 0x78, /* Data alignment factor */
7241 16, /* Return address column */
7242 1, /* Augmentation size */
7243 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
7244 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7245 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7246 DW_CFA_nop, DW_CFA_nop,
7248 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
7249 PLT_CIE_LENGTH + 8, 0, 0, 0,/* CIE pointer */
7250 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7251 0, 0, 0, 0, /* .plt size goes here */
7252 0, /* Augmentation size */
7253 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
7254 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7255 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
7256 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7257 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
7258 13, /* Block length */
7259 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
7260 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
7261 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
7262 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
7263 DW_CFA_nop, DW_CFA_nop
7266 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed =
7268 elf_x86_64_nacl_plt0_entry, /* plt0_entry */
7269 elf_x86_64_nacl_plt_entry, /* plt_entry */
7270 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
7271 2, /* plt0_got1_offset */
7272 9, /* plt0_got2_offset */
7273 13, /* plt0_got2_insn_end */
7274 3, /* plt_got_offset */
7275 33, /* plt_reloc_offset */
7276 38, /* plt_plt_offset */
7277 7, /* plt_got_insn_size */
7278 42, /* plt_plt_insn_end */
7279 32, /* plt_lazy_offset */
7280 elf_x86_64_nacl_eh_frame_plt, /* eh_frame_plt */
7281 sizeof (elf_x86_64_nacl_eh_frame_plt), /* eh_frame_plt_size */
7282 NULL, /* eh_frame_plt_got */
7283 0, /* eh_frame_plt_got_size */
7286 #undef elf_backend_arch_data
7287 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7289 #undef elf_backend_object_p
7290 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7291 #undef elf_backend_modify_segment_map
7292 #define elf_backend_modify_segment_map nacl_modify_segment_map
7293 #undef elf_backend_modify_program_headers
7294 #define elf_backend_modify_program_headers nacl_modify_program_headers
7295 #undef elf_backend_final_write_processing
7296 #define elf_backend_final_write_processing nacl_final_write_processing
7298 #include "elf64-target.h"
7300 /* Native Client x32 support. */
7303 elf32_x86_64_nacl_elf_object_p (bfd *abfd)
7305 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7306 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32_nacl);
7310 #undef TARGET_LITTLE_SYM
7311 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7312 #undef TARGET_LITTLE_NAME
7313 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7315 #define elf32_bed elf32_x86_64_nacl_bed
7317 #define bfd_elf32_bfd_link_hash_table_create \
7318 elf_x86_64_link_hash_table_create
7319 #define bfd_elf32_bfd_reloc_type_lookup \
7320 elf_x86_64_reloc_type_lookup
7321 #define bfd_elf32_bfd_reloc_name_lookup \
7322 elf_x86_64_reloc_name_lookup
7323 #define bfd_elf32_mkobject \
7325 #define bfd_elf32_get_synthetic_symtab \
7326 elf_x86_64_get_synthetic_symtab
7328 #undef elf_backend_object_p
7329 #define elf_backend_object_p \
7330 elf32_x86_64_nacl_elf_object_p
7332 #undef elf_backend_bfd_from_remote_memory
7333 #define elf_backend_bfd_from_remote_memory \
7334 _bfd_elf32_bfd_from_remote_memory
7336 #undef elf_backend_size_info
7337 #define elf_backend_size_info \
7338 _bfd_elf32_size_info
7340 #include "elf32-target.h"
7342 /* Restore defaults. */
7343 #undef elf_backend_object_p
7344 #define elf_backend_object_p elf64_x86_64_elf_object_p
7345 #undef elf_backend_bfd_from_remote_memory
7346 #undef elf_backend_size_info
7347 #undef elf_backend_modify_segment_map
7348 #undef elf_backend_modify_program_headers
7349 #undef elf_backend_final_write_processing
7351 /* Intel L1OM support. */
7354 elf64_l1om_elf_object_p (bfd *abfd)
7356 /* Set the right machine number for an L1OM elf64 file. */
7357 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
7361 #undef TARGET_LITTLE_SYM
7362 #define TARGET_LITTLE_SYM l1om_elf64_vec
7363 #undef TARGET_LITTLE_NAME
7364 #define TARGET_LITTLE_NAME "elf64-l1om"
7366 #define ELF_ARCH bfd_arch_l1om
7368 #undef ELF_MACHINE_CODE
7369 #define ELF_MACHINE_CODE EM_L1OM
7374 #define elf64_bed elf64_l1om_bed
7376 #undef elf_backend_object_p
7377 #define elf_backend_object_p elf64_l1om_elf_object_p
7379 /* Restore defaults. */
7380 #undef ELF_MAXPAGESIZE
7381 #undef ELF_MINPAGESIZE
7382 #undef ELF_COMMONPAGESIZE
7383 #define ELF_MAXPAGESIZE 0x200000
7384 #define ELF_MINPAGESIZE 0x1000
7385 #define ELF_COMMONPAGESIZE 0x1000
7386 #undef elf_backend_plt_alignment
7387 #define elf_backend_plt_alignment 4
7388 #undef elf_backend_arch_data
7389 #define elf_backend_arch_data &elf_x86_64_arch_bed
7391 #include "elf64-target.h"
7393 /* FreeBSD L1OM support. */
7395 #undef TARGET_LITTLE_SYM
7396 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7397 #undef TARGET_LITTLE_NAME
7398 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7401 #define ELF_OSABI ELFOSABI_FREEBSD
7404 #define elf64_bed elf64_l1om_fbsd_bed
7406 #include "elf64-target.h"
7408 /* Intel K1OM support. */
7411 elf64_k1om_elf_object_p (bfd *abfd)
7413 /* Set the right machine number for an K1OM elf64 file. */
7414 bfd_default_set_arch_mach (abfd, bfd_arch_k1om, bfd_mach_k1om);
7418 #undef TARGET_LITTLE_SYM
7419 #define TARGET_LITTLE_SYM k1om_elf64_vec
7420 #undef TARGET_LITTLE_NAME
7421 #define TARGET_LITTLE_NAME "elf64-k1om"
7423 #define ELF_ARCH bfd_arch_k1om
7425 #undef ELF_MACHINE_CODE
7426 #define ELF_MACHINE_CODE EM_K1OM
7431 #define elf64_bed elf64_k1om_bed
7433 #undef elf_backend_object_p
7434 #define elf_backend_object_p elf64_k1om_elf_object_p
7436 #undef elf_backend_static_tls_alignment
7438 #undef elf_backend_want_plt_sym
7439 #define elf_backend_want_plt_sym 0
7441 #include "elf64-target.h"
7443 /* FreeBSD K1OM support. */
7445 #undef TARGET_LITTLE_SYM
7446 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7447 #undef TARGET_LITTLE_NAME
7448 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7451 #define ELF_OSABI ELFOSABI_FREEBSD
7454 #define elf64_bed elf64_k1om_fbsd_bed
7456 #include "elf64-target.h"
7458 /* 32bit x86-64 support. */
7460 #undef TARGET_LITTLE_SYM
7461 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7462 #undef TARGET_LITTLE_NAME
7463 #define TARGET_LITTLE_NAME "elf32-x86-64"
7467 #define ELF_ARCH bfd_arch_i386
7469 #undef ELF_MACHINE_CODE
7470 #define ELF_MACHINE_CODE EM_X86_64
7474 #undef elf_backend_object_p
7475 #define elf_backend_object_p \
7476 elf32_x86_64_elf_object_p
7478 #undef elf_backend_bfd_from_remote_memory
7479 #define elf_backend_bfd_from_remote_memory \
7480 _bfd_elf32_bfd_from_remote_memory
7482 #undef elf_backend_size_info
7483 #define elf_backend_size_info \
7484 _bfd_elf32_size_info
7486 #include "elf32-target.h"