1 /* X86-64 specific support for ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Jan Hubicka <jh@suse.cz>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "bfd_stdint.h"
33 #include "libiberty.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, 0, 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,
152 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
153 complain_overflow_bitfield, bfd_elf_generic_reloc,
154 "R_X86_64_GOTPC32_TLSDESC",
155 FALSE, 0xffffffff, 0xffffffff, TRUE),
156 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
157 complain_overflow_dont, bfd_elf_generic_reloc,
158 "R_X86_64_TLSDESC_CALL",
160 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
161 complain_overflow_bitfield, bfd_elf_generic_reloc,
163 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
164 HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
165 bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
167 HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
168 bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", FALSE, MINUS_ONE,
171 /* We have a gap in the reloc numbers here.
172 R_X86_64_standard counts the number up to this point, and
173 R_X86_64_vt_offset is the value to subtract from a reloc type of
174 R_X86_64_GNU_VT* to form an index into this table. */
175 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
176 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
178 /* GNU extension to record C++ vtable hierarchy. */
179 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
180 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
182 /* GNU extension to record C++ vtable member usage. */
183 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
184 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
187 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
188 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
189 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
193 #define IS_X86_64_PCREL_TYPE(TYPE) \
194 ( ((TYPE) == R_X86_64_PC8) \
195 || ((TYPE) == R_X86_64_PC16) \
196 || ((TYPE) == R_X86_64_PC32) \
197 || ((TYPE) == R_X86_64_PC64))
199 /* Map BFD relocs to the x86_64 elf relocs. */
202 bfd_reloc_code_real_type bfd_reloc_val;
203 unsigned char elf_reloc_val;
206 static const struct elf_reloc_map x86_64_reloc_map[] =
208 { BFD_RELOC_NONE, R_X86_64_NONE, },
209 { BFD_RELOC_64, R_X86_64_64, },
210 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
211 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
212 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
213 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
214 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
215 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
216 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
217 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
218 { BFD_RELOC_32, R_X86_64_32, },
219 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
220 { BFD_RELOC_16, R_X86_64_16, },
221 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
222 { BFD_RELOC_8, R_X86_64_8, },
223 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
224 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
225 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
226 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
227 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
228 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
229 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
230 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
231 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
232 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
233 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
234 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
235 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
236 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
237 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
238 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
239 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
240 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
241 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
242 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
243 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
244 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
245 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
248 static reloc_howto_type *
249 elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
253 if (r_type == (unsigned int) R_X86_64_32)
258 i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
260 else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
261 || r_type >= (unsigned int) R_X86_64_max)
263 if (r_type >= (unsigned int) R_X86_64_standard)
265 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
267 r_type = R_X86_64_NONE;
272 i = r_type - (unsigned int) R_X86_64_vt_offset;
273 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
274 return &x86_64_elf_howto_table[i];
277 /* Given a BFD reloc type, return a HOWTO structure. */
278 static reloc_howto_type *
279 elf_x86_64_reloc_type_lookup (bfd *abfd,
280 bfd_reloc_code_real_type code)
284 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
287 if (x86_64_reloc_map[i].bfd_reloc_val == code)
288 return elf_x86_64_rtype_to_howto (abfd,
289 x86_64_reloc_map[i].elf_reloc_val);
294 static reloc_howto_type *
295 elf_x86_64_reloc_name_lookup (bfd *abfd,
300 if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
302 /* Get x32 R_X86_64_32. */
303 reloc_howto_type *reloc
304 = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
305 BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
309 for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
310 if (x86_64_elf_howto_table[i].name != NULL
311 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
312 return &x86_64_elf_howto_table[i];
317 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
320 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
321 Elf_Internal_Rela *dst)
325 r_type = ELF32_R_TYPE (dst->r_info);
326 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
327 BFD_ASSERT (r_type == cache_ptr->howto->type);
330 /* Support for core dump NOTE sections. */
332 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
337 switch (note->descsz)
342 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
344 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
347 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
355 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
357 elf_tdata (abfd)->core_signal
358 = bfd_get_16 (abfd, note->descdata + 12);
361 elf_tdata (abfd)->core_lwpid
362 = bfd_get_32 (abfd, note->descdata + 32);
371 /* Make a ".reg/999" section. */
372 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
373 size, note->descpos + offset);
377 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
379 switch (note->descsz)
384 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
385 elf_tdata (abfd)->core_pid
386 = bfd_get_32 (abfd, note->descdata + 12);
387 elf_tdata (abfd)->core_program
388 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
389 elf_tdata (abfd)->core_command
390 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
393 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
394 elf_tdata (abfd)->core_pid
395 = bfd_get_32 (abfd, note->descdata + 24);
396 elf_tdata (abfd)->core_program
397 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
398 elf_tdata (abfd)->core_command
399 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
402 /* Note that for some reason, a spurious space is tacked
403 onto the end of the args in some (at least one anyway)
404 implementations, so strip it off if it exists. */
407 char *command = elf_tdata (abfd)->core_command;
408 int n = strlen (command);
410 if (0 < n && command[n - 1] == ' ')
411 command[n - 1] = '\0';
419 elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz,
422 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
424 const char *fname, *psargs;
435 va_start (ap, note_type);
436 fname = va_arg (ap, const char *);
437 psargs = va_arg (ap, const char *);
440 if (bed->s->elfclass == ELFCLASS32)
443 memset (&data, 0, sizeof (data));
444 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
445 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
446 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
447 &data, sizeof (data));
452 memset (&data, 0, sizeof (data));
453 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
454 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
455 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
456 &data, sizeof (data));
461 va_start (ap, note_type);
462 pid = va_arg (ap, long);
463 cursig = va_arg (ap, int);
464 gregs = va_arg (ap, const void *);
467 if (bed->s->elfclass == ELFCLASS32)
469 if (bed->elf_machine_code == EM_X86_64)
471 prstatusx32_t prstat;
472 memset (&prstat, 0, sizeof (prstat));
474 prstat.pr_cursig = cursig;
475 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
476 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
477 &prstat, sizeof (prstat));
482 memset (&prstat, 0, sizeof (prstat));
484 prstat.pr_cursig = cursig;
485 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
486 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
487 &prstat, sizeof (prstat));
493 memset (&prstat, 0, sizeof (prstat));
495 prstat.pr_cursig = cursig;
496 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
497 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
498 &prstat, sizeof (prstat));
505 /* Functions for the x86-64 ELF linker. */
507 /* The name of the dynamic interpreter. This is put in the .interp
510 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
511 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
513 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
514 copying dynamic variables from a shared lib into an app's dynbss
515 section, and instead use a dynamic relocation to point into the
517 #define ELIMINATE_COPY_RELOCS 1
519 /* The size in bytes of an entry in the global offset table. */
521 #define GOT_ENTRY_SIZE 8
523 /* The size in bytes of an entry in the procedure linkage table. */
525 #define PLT_ENTRY_SIZE 16
527 /* The first entry in a procedure linkage table looks like this. See the
528 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
530 static const bfd_byte elf_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
532 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
533 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
534 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
537 /* Subsequent entries in a procedure linkage table look like this. */
539 static const bfd_byte elf_x86_64_plt_entry[PLT_ENTRY_SIZE] =
541 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
542 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
543 0x68, /* pushq immediate */
544 0, 0, 0, 0, /* replaced with index into relocation table. */
545 0xe9, /* jmp relative */
546 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
549 /* .eh_frame covering the .plt section. */
551 static const bfd_byte elf_x86_64_eh_frame_plt[] =
553 #define PLT_CIE_LENGTH 20
554 #define PLT_FDE_LENGTH 36
555 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
556 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
557 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
558 0, 0, 0, 0, /* CIE ID */
560 'z', 'R', 0, /* Augmentation string */
561 1, /* Code alignment factor */
562 0x78, /* Data alignment factor */
563 16, /* Return address column */
564 1, /* Augmentation size */
565 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
566 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
567 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
568 DW_CFA_nop, DW_CFA_nop,
570 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
571 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
572 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
573 0, 0, 0, 0, /* .plt size goes here */
574 0, /* Augmentation size */
575 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
576 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
577 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
578 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
579 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
580 11, /* Block length */
581 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
582 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
583 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
584 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
585 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
588 /* Architecture-specific backend data for x86-64. */
590 struct elf_x86_64_backend_data
592 /* Templates for the initial PLT entry and for subsequent entries. */
593 const bfd_byte *plt0_entry;
594 const bfd_byte *plt_entry;
595 unsigned int plt_entry_size; /* Size of each PLT entry. */
597 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
598 unsigned int plt0_got1_offset;
599 unsigned int plt0_got2_offset;
601 /* Offset of the end of the PC-relative instruction containing
603 unsigned int plt0_got2_insn_end;
605 /* Offsets into plt_entry that are to be replaced with... */
606 unsigned int plt_got_offset; /* ... address of this symbol in .got. */
607 unsigned int plt_reloc_offset; /* ... offset into relocation table. */
608 unsigned int plt_plt_offset; /* ... offset to start of .plt. */
610 /* Length of the PC-relative instruction containing plt_got_offset. */
611 unsigned int plt_got_insn_size;
613 /* Offset of the end of the PC-relative jump to plt0_entry. */
614 unsigned int plt_plt_insn_end;
616 /* Offset into plt_entry where the initial value of the GOT entry points. */
617 unsigned int plt_lazy_offset;
619 /* .eh_frame covering the .plt section. */
620 const bfd_byte *eh_frame_plt;
621 unsigned int eh_frame_plt_size;
624 #define get_elf_x86_64_backend_data(abfd) \
625 ((const struct elf_x86_64_backend_data *) \
626 get_elf_backend_data (abfd)->arch_data)
628 #define GET_PLT_ENTRY_SIZE(abfd) \
629 get_elf_x86_64_backend_data (abfd)->plt_entry_size
631 /* These are the standard parameters. */
632 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
634 elf_x86_64_plt0_entry, /* plt0_entry */
635 elf_x86_64_plt_entry, /* plt_entry */
636 sizeof (elf_x86_64_plt_entry), /* plt_entry_size */
637 2, /* plt0_got1_offset */
638 8, /* plt0_got2_offset */
639 12, /* plt0_got2_insn_end */
640 2, /* plt_got_offset */
641 7, /* plt_reloc_offset */
642 12, /* plt_plt_offset */
643 6, /* plt_got_insn_size */
644 PLT_ENTRY_SIZE, /* plt_plt_insn_end */
645 6, /* plt_lazy_offset */
646 elf_x86_64_eh_frame_plt, /* eh_frame_plt */
647 sizeof (elf_x86_64_eh_frame_plt), /* eh_frame_plt_size */
650 #define elf_backend_arch_data &elf_x86_64_arch_bed
652 /* x86-64 ELF linker hash entry. */
654 struct elf_x86_64_link_hash_entry
656 struct elf_link_hash_entry elf;
658 /* Track dynamic relocs copied for this symbol. */
659 struct elf_dyn_relocs *dyn_relocs;
661 #define GOT_UNKNOWN 0
665 #define GOT_TLS_GDESC 4
666 #define GOT_TLS_GD_BOTH_P(type) \
667 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
668 #define GOT_TLS_GD_P(type) \
669 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
670 #define GOT_TLS_GDESC_P(type) \
671 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
672 #define GOT_TLS_GD_ANY_P(type) \
673 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
674 unsigned char tls_type;
676 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
677 starting at the end of the jump table. */
681 #define elf_x86_64_hash_entry(ent) \
682 ((struct elf_x86_64_link_hash_entry *)(ent))
684 struct elf_x86_64_obj_tdata
686 struct elf_obj_tdata root;
688 /* tls_type for each local got entry. */
689 char *local_got_tls_type;
691 /* GOTPLT entries for TLS descriptors. */
692 bfd_vma *local_tlsdesc_gotent;
695 #define elf_x86_64_tdata(abfd) \
696 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
698 #define elf_x86_64_local_got_tls_type(abfd) \
699 (elf_x86_64_tdata (abfd)->local_got_tls_type)
701 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
702 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
704 #define is_x86_64_elf(bfd) \
705 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
706 && elf_tdata (bfd) != NULL \
707 && elf_object_id (bfd) == X86_64_ELF_DATA)
710 elf_x86_64_mkobject (bfd *abfd)
712 return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_64_obj_tdata),
716 /* x86-64 ELF linker hash table. */
718 struct elf_x86_64_link_hash_table
720 struct elf_link_hash_table elf;
722 /* Short-cuts to get to dynamic linker sections. */
725 asection *plt_eh_frame;
729 bfd_signed_vma refcount;
733 /* The amount of space used by the jump slots in the GOT. */
734 bfd_vma sgotplt_jump_table_size;
736 /* Small local sym cache. */
737 struct sym_cache sym_cache;
739 bfd_vma (*r_info) (bfd_vma, bfd_vma);
740 bfd_vma (*r_sym) (bfd_vma);
741 unsigned int pointer_r_type;
742 const char *dynamic_interpreter;
743 int dynamic_interpreter_size;
745 /* _TLS_MODULE_BASE_ symbol. */
746 struct bfd_link_hash_entry *tls_module_base;
748 /* Used by local STT_GNU_IFUNC symbols. */
749 htab_t loc_hash_table;
750 void * loc_hash_memory;
752 /* The offset into splt of the PLT entry for the TLS descriptor
753 resolver. Special values are 0, if not necessary (or not found
754 to be necessary yet), and -1 if needed but not determined
757 /* The offset into sgot of the GOT entry used by the PLT entry
761 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
762 bfd_vma next_jump_slot_index;
763 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
764 bfd_vma next_irelative_index;
767 /* Get the x86-64 ELF linker hash table from a link_info structure. */
769 #define elf_x86_64_hash_table(p) \
770 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
771 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
773 #define elf_x86_64_compute_jump_table_size(htab) \
774 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
776 /* Create an entry in an x86-64 ELF linker hash table. */
778 static struct bfd_hash_entry *
779 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
780 struct bfd_hash_table *table,
783 /* Allocate the structure if it has not already been allocated by a
787 entry = (struct bfd_hash_entry *)
788 bfd_hash_allocate (table,
789 sizeof (struct elf_x86_64_link_hash_entry));
794 /* Call the allocation method of the superclass. */
795 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
798 struct elf_x86_64_link_hash_entry *eh;
800 eh = (struct elf_x86_64_link_hash_entry *) entry;
801 eh->dyn_relocs = NULL;
802 eh->tls_type = GOT_UNKNOWN;
803 eh->tlsdesc_got = (bfd_vma) -1;
809 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
810 for local symbol so that we can handle local STT_GNU_IFUNC symbols
811 as global symbol. We reuse indx and dynstr_index for local symbol
812 hash since they aren't used by global symbols in this backend. */
815 elf_x86_64_local_htab_hash (const void *ptr)
817 struct elf_link_hash_entry *h
818 = (struct elf_link_hash_entry *) ptr;
819 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
822 /* Compare local hash entries. */
825 elf_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
827 struct elf_link_hash_entry *h1
828 = (struct elf_link_hash_entry *) ptr1;
829 struct elf_link_hash_entry *h2
830 = (struct elf_link_hash_entry *) ptr2;
832 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
835 /* Find and/or create a hash entry for local symbol. */
837 static struct elf_link_hash_entry *
838 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table *htab,
839 bfd *abfd, const Elf_Internal_Rela *rel,
842 struct elf_x86_64_link_hash_entry e, *ret;
843 asection *sec = abfd->sections;
844 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
845 htab->r_sym (rel->r_info));
848 e.elf.indx = sec->id;
849 e.elf.dynstr_index = htab->r_sym (rel->r_info);
850 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
851 create ? INSERT : NO_INSERT);
858 ret = (struct elf_x86_64_link_hash_entry *) *slot;
862 ret = (struct elf_x86_64_link_hash_entry *)
863 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
864 sizeof (struct elf_x86_64_link_hash_entry));
867 memset (ret, 0, sizeof (*ret));
868 ret->elf.indx = sec->id;
869 ret->elf.dynstr_index = htab->r_sym (rel->r_info);
870 ret->elf.dynindx = -1;
876 /* Create an X86-64 ELF linker hash table. */
878 static struct bfd_link_hash_table *
879 elf_x86_64_link_hash_table_create (bfd *abfd)
881 struct elf_x86_64_link_hash_table *ret;
882 bfd_size_type amt = sizeof (struct elf_x86_64_link_hash_table);
884 ret = (struct elf_x86_64_link_hash_table *) bfd_malloc (amt);
888 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
889 elf_x86_64_link_hash_newfunc,
890 sizeof (struct elf_x86_64_link_hash_entry),
899 ret->plt_eh_frame = NULL;
900 ret->sym_cache.abfd = NULL;
901 ret->tlsdesc_plt = 0;
902 ret->tlsdesc_got = 0;
903 ret->tls_ld_got.refcount = 0;
904 ret->sgotplt_jump_table_size = 0;
905 ret->tls_module_base = NULL;
906 ret->next_jump_slot_index = 0;
907 ret->next_irelative_index = 0;
911 ret->r_info = elf64_r_info;
912 ret->r_sym = elf64_r_sym;
913 ret->pointer_r_type = R_X86_64_64;
914 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
915 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
919 ret->r_info = elf32_r_info;
920 ret->r_sym = elf32_r_sym;
921 ret->pointer_r_type = R_X86_64_32;
922 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
923 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
926 ret->loc_hash_table = htab_try_create (1024,
927 elf_x86_64_local_htab_hash,
928 elf_x86_64_local_htab_eq,
930 ret->loc_hash_memory = objalloc_create ();
931 if (!ret->loc_hash_table || !ret->loc_hash_memory)
937 return &ret->elf.root;
940 /* Destroy an X86-64 ELF linker hash table. */
943 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
945 struct elf_x86_64_link_hash_table *htab
946 = (struct elf_x86_64_link_hash_table *) hash;
948 if (htab->loc_hash_table)
949 htab_delete (htab->loc_hash_table);
950 if (htab->loc_hash_memory)
951 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
952 _bfd_generic_link_hash_table_free (hash);
955 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
956 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
960 elf_x86_64_create_dynamic_sections (bfd *dynobj,
961 struct bfd_link_info *info)
963 struct elf_x86_64_link_hash_table *htab;
965 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
968 htab = elf_x86_64_hash_table (info);
972 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
974 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
977 || (!info->shared && !htab->srelbss))
980 if (!info->no_ld_generated_unwind_info
981 && bfd_get_section_by_name (dynobj, ".eh_frame") == NULL
982 && htab->elf.splt != NULL)
984 const struct elf_x86_64_backend_data *const abed
985 = get_elf_x86_64_backend_data (dynobj);
986 flagword flags = get_elf_backend_data (dynobj)->dynamic_sec_flags;
988 = bfd_make_section_with_flags (dynobj, ".eh_frame",
989 flags | SEC_READONLY);
990 if (htab->plt_eh_frame == NULL
991 || !bfd_set_section_alignment (dynobj, htab->plt_eh_frame, 3))
994 htab->plt_eh_frame->size = abed->eh_frame_plt_size;
995 htab->plt_eh_frame->contents
996 = bfd_alloc (dynobj, htab->plt_eh_frame->size);
997 memcpy (htab->plt_eh_frame->contents,
998 abed->eh_frame_plt, abed->eh_frame_plt_size);
1003 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1006 elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
1007 struct elf_link_hash_entry *dir,
1008 struct elf_link_hash_entry *ind)
1010 struct elf_x86_64_link_hash_entry *edir, *eind;
1012 edir = (struct elf_x86_64_link_hash_entry *) dir;
1013 eind = (struct elf_x86_64_link_hash_entry *) ind;
1015 if (eind->dyn_relocs != NULL)
1017 if (edir->dyn_relocs != NULL)
1019 struct elf_dyn_relocs **pp;
1020 struct elf_dyn_relocs *p;
1022 /* Add reloc counts against the indirect sym to the direct sym
1023 list. Merge any entries against the same section. */
1024 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1026 struct elf_dyn_relocs *q;
1028 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1029 if (q->sec == p->sec)
1031 q->pc_count += p->pc_count;
1032 q->count += p->count;
1039 *pp = edir->dyn_relocs;
1042 edir->dyn_relocs = eind->dyn_relocs;
1043 eind->dyn_relocs = NULL;
1046 if (ind->root.type == bfd_link_hash_indirect
1047 && dir->got.refcount <= 0)
1049 edir->tls_type = eind->tls_type;
1050 eind->tls_type = GOT_UNKNOWN;
1053 if (ELIMINATE_COPY_RELOCS
1054 && ind->root.type != bfd_link_hash_indirect
1055 && dir->dynamic_adjusted)
1057 /* If called to transfer flags for a weakdef during processing
1058 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1059 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1060 dir->ref_dynamic |= ind->ref_dynamic;
1061 dir->ref_regular |= ind->ref_regular;
1062 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1063 dir->needs_plt |= ind->needs_plt;
1064 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1067 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1071 elf64_x86_64_elf_object_p (bfd *abfd)
1073 /* Set the right machine number for an x86-64 elf64 file. */
1074 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
1079 elf32_x86_64_elf_object_p (bfd *abfd)
1081 /* Set the right machine number for an x86-64 elf32 file. */
1082 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
1086 /* Return TRUE if the TLS access code sequence support transition
1090 elf_x86_64_check_tls_transition (bfd *abfd,
1091 struct bfd_link_info *info,
1094 Elf_Internal_Shdr *symtab_hdr,
1095 struct elf_link_hash_entry **sym_hashes,
1096 unsigned int r_type,
1097 const Elf_Internal_Rela *rel,
1098 const Elf_Internal_Rela *relend)
1101 unsigned long r_symndx;
1102 struct elf_link_hash_entry *h;
1104 struct elf_x86_64_link_hash_table *htab;
1106 /* Get the section contents. */
1107 if (contents == NULL)
1109 if (elf_section_data (sec)->this_hdr.contents != NULL)
1110 contents = elf_section_data (sec)->this_hdr.contents;
1113 /* FIXME: How to better handle error condition? */
1114 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1117 /* Cache the section contents for elf_link_input_bfd. */
1118 elf_section_data (sec)->this_hdr.contents = contents;
1122 htab = elf_x86_64_hash_table (info);
1123 offset = rel->r_offset;
1126 case R_X86_64_TLSGD:
1127 case R_X86_64_TLSLD:
1128 if ((rel + 1) >= relend)
1131 if (r_type == R_X86_64_TLSGD)
1133 /* Check transition from GD access model. For 64bit, only
1134 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1135 .word 0x6666; rex64; call __tls_get_addr
1136 can transit to different access model. For 32bit, only
1137 leaq foo@tlsgd(%rip), %rdi
1138 .word 0x6666; rex64; call __tls_get_addr
1139 can transit to different access model. */
1141 static const unsigned char call[] = { 0x66, 0x66, 0x48, 0xe8 };
1142 static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
1144 if ((offset + 12) > sec->size
1145 || memcmp (contents + offset + 4, call, 4) != 0)
1148 if (ABI_64_P (abfd))
1151 || memcmp (contents + offset - 4, leaq, 4) != 0)
1157 || memcmp (contents + offset - 3, leaq + 1, 3) != 0)
1163 /* Check transition from LD access model. Only
1164 leaq foo@tlsld(%rip), %rdi;
1166 can transit to different access model. */
1168 static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
1170 if (offset < 3 || (offset + 9) > sec->size)
1173 if (memcmp (contents + offset - 3, lea, 3) != 0
1174 || 0xe8 != *(contents + offset + 4))
1178 r_symndx = htab->r_sym (rel[1].r_info);
1179 if (r_symndx < symtab_hdr->sh_info)
1182 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1183 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1184 may be versioned. */
1186 && h->root.root.string != NULL
1187 && (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
1188 || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
1189 && (strncmp (h->root.root.string,
1190 "__tls_get_addr", 14) == 0));
1192 case R_X86_64_GOTTPOFF:
1193 /* Check transition from IE access model:
1194 mov foo@gottpoff(%rip), %reg
1195 add foo@gottpoff(%rip), %reg
1198 /* Check REX prefix first. */
1199 if (offset >= 3 && (offset + 4) <= sec->size)
1201 val = bfd_get_8 (abfd, contents + offset - 3);
1202 if (val != 0x48 && val != 0x4c)
1204 /* X32 may have 0x44 REX prefix or no REX prefix. */
1205 if (ABI_64_P (abfd))
1211 /* X32 may not have any REX prefix. */
1212 if (ABI_64_P (abfd))
1214 if (offset < 2 || (offset + 3) > sec->size)
1218 val = bfd_get_8 (abfd, contents + offset - 2);
1219 if (val != 0x8b && val != 0x03)
1222 val = bfd_get_8 (abfd, contents + offset - 1);
1223 return (val & 0xc7) == 5;
1225 case R_X86_64_GOTPC32_TLSDESC:
1226 /* Check transition from GDesc access model:
1227 leaq x@tlsdesc(%rip), %rax
1229 Make sure it's a leaq adding rip to a 32-bit offset
1230 into any register, although it's probably almost always
1233 if (offset < 3 || (offset + 4) > sec->size)
1236 val = bfd_get_8 (abfd, contents + offset - 3);
1237 if ((val & 0xfb) != 0x48)
1240 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1243 val = bfd_get_8 (abfd, contents + offset - 1);
1244 return (val & 0xc7) == 0x05;
1246 case R_X86_64_TLSDESC_CALL:
1247 /* Check transition from GDesc access model:
1248 call *x@tlsdesc(%rax)
1250 if (offset + 2 <= sec->size)
1252 /* Make sure that it's a call *x@tlsdesc(%rax). */
1253 static const unsigned char call[] = { 0xff, 0x10 };
1254 return memcmp (contents + offset, call, 2) == 0;
1264 /* Return TRUE if the TLS access transition is OK or no transition
1265 will be performed. Update R_TYPE if there is a transition. */
1268 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1269 asection *sec, bfd_byte *contents,
1270 Elf_Internal_Shdr *symtab_hdr,
1271 struct elf_link_hash_entry **sym_hashes,
1272 unsigned int *r_type, int tls_type,
1273 const Elf_Internal_Rela *rel,
1274 const Elf_Internal_Rela *relend,
1275 struct elf_link_hash_entry *h,
1276 unsigned long r_symndx)
1278 unsigned int from_type = *r_type;
1279 unsigned int to_type = from_type;
1280 bfd_boolean check = TRUE;
1282 /* Skip TLS transition for functions. */
1284 && (h->type == STT_FUNC
1285 || h->type == STT_GNU_IFUNC))
1290 case R_X86_64_TLSGD:
1291 case R_X86_64_GOTPC32_TLSDESC:
1292 case R_X86_64_TLSDESC_CALL:
1293 case R_X86_64_GOTTPOFF:
1294 if (info->executable)
1297 to_type = R_X86_64_TPOFF32;
1299 to_type = R_X86_64_GOTTPOFF;
1302 /* When we are called from elf_x86_64_relocate_section,
1303 CONTENTS isn't NULL and there may be additional transitions
1304 based on TLS_TYPE. */
1305 if (contents != NULL)
1307 unsigned int new_to_type = to_type;
1309 if (info->executable
1312 && tls_type == GOT_TLS_IE)
1313 new_to_type = R_X86_64_TPOFF32;
1315 if (to_type == R_X86_64_TLSGD
1316 || to_type == R_X86_64_GOTPC32_TLSDESC
1317 || to_type == R_X86_64_TLSDESC_CALL)
1319 if (tls_type == GOT_TLS_IE)
1320 new_to_type = R_X86_64_GOTTPOFF;
1323 /* We checked the transition before when we were called from
1324 elf_x86_64_check_relocs. We only want to check the new
1325 transition which hasn't been checked before. */
1326 check = new_to_type != to_type && from_type == to_type;
1327 to_type = new_to_type;
1332 case R_X86_64_TLSLD:
1333 if (info->executable)
1334 to_type = R_X86_64_TPOFF32;
1341 /* Return TRUE if there is no transition. */
1342 if (from_type == to_type)
1345 /* Check if the transition can be performed. */
1347 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1348 symtab_hdr, sym_hashes,
1349 from_type, rel, relend))
1351 reloc_howto_type *from, *to;
1354 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1355 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1358 name = h->root.root.string;
1361 struct elf_x86_64_link_hash_table *htab;
1363 htab = elf_x86_64_hash_table (info);
1368 Elf_Internal_Sym *isym;
1370 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1372 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1376 (*_bfd_error_handler)
1377 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1378 "in section `%A' failed"),
1379 abfd, sec, from->name, to->name, name,
1380 (unsigned long) rel->r_offset);
1381 bfd_set_error (bfd_error_bad_value);
1389 /* Look through the relocs for a section during the first phase, and
1390 calculate needed space in the global offset table, procedure
1391 linkage table, and dynamic reloc sections. */
1394 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1396 const Elf_Internal_Rela *relocs)
1398 struct elf_x86_64_link_hash_table *htab;
1399 Elf_Internal_Shdr *symtab_hdr;
1400 struct elf_link_hash_entry **sym_hashes;
1401 const Elf_Internal_Rela *rel;
1402 const Elf_Internal_Rela *rel_end;
1405 if (info->relocatable)
1408 BFD_ASSERT (is_x86_64_elf (abfd));
1410 htab = elf_x86_64_hash_table (info);
1414 symtab_hdr = &elf_symtab_hdr (abfd);
1415 sym_hashes = elf_sym_hashes (abfd);
1419 rel_end = relocs + sec->reloc_count;
1420 for (rel = relocs; rel < rel_end; rel++)
1422 unsigned int r_type;
1423 unsigned long r_symndx;
1424 struct elf_link_hash_entry *h;
1425 Elf_Internal_Sym *isym;
1428 r_symndx = htab->r_sym (rel->r_info);
1429 r_type = ELF32_R_TYPE (rel->r_info);
1431 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1433 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1438 if (r_symndx < symtab_hdr->sh_info)
1440 /* A local symbol. */
1441 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1446 /* Check relocation against local STT_GNU_IFUNC symbol. */
1447 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1449 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel,
1454 /* Fake a STT_GNU_IFUNC symbol. */
1455 h->type = STT_GNU_IFUNC;
1458 h->forced_local = 1;
1459 h->root.type = bfd_link_hash_defined;
1467 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1468 while (h->root.type == bfd_link_hash_indirect
1469 || h->root.type == bfd_link_hash_warning)
1470 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1473 /* Check invalid x32 relocations. */
1474 if (!ABI_64_P (abfd))
1480 case R_X86_64_DTPOFF64:
1481 case R_X86_64_TPOFF64:
1483 case R_X86_64_GOTOFF64:
1484 case R_X86_64_GOT64:
1485 case R_X86_64_GOTPCREL64:
1486 case R_X86_64_GOTPC64:
1487 case R_X86_64_GOTPLT64:
1488 case R_X86_64_PLTOFF64:
1491 name = h->root.root.string;
1493 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1495 (*_bfd_error_handler)
1496 (_("%B: relocation %s against symbol `%s' isn't "
1497 "supported in x32 mode"), abfd,
1498 x86_64_elf_howto_table[r_type].name, name);
1499 bfd_set_error (bfd_error_bad_value);
1507 /* Create the ifunc sections for static executables. If we
1508 never see an indirect function symbol nor we are building
1509 a static executable, those sections will be empty and
1510 won't appear in output. */
1521 case R_X86_64_PLT32:
1522 case R_X86_64_GOTPCREL:
1523 case R_X86_64_GOTPCREL64:
1524 if (htab->elf.dynobj == NULL)
1525 htab->elf.dynobj = abfd;
1526 if (!_bfd_elf_create_ifunc_sections (htab->elf.dynobj, info))
1531 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1532 it here if it is defined in a non-shared object. */
1533 if (h->type == STT_GNU_IFUNC
1536 /* It is referenced by a non-shared object. */
1540 /* STT_GNU_IFUNC symbol must go through PLT. */
1541 h->plt.refcount += 1;
1543 /* STT_GNU_IFUNC needs dynamic sections. */
1544 if (htab->elf.dynobj == NULL)
1545 htab->elf.dynobj = abfd;
1550 if (h->root.root.string)
1551 name = h->root.root.string;
1553 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1555 (*_bfd_error_handler)
1556 (_("%B: relocation %s against STT_GNU_IFUNC "
1557 "symbol `%s' isn't handled by %s"), abfd,
1558 x86_64_elf_howto_table[r_type].name,
1559 name, __FUNCTION__);
1560 bfd_set_error (bfd_error_bad_value);
1564 if (ABI_64_P (abfd))
1568 h->pointer_equality_needed = 1;
1571 /* We must copy these reloc types into the output
1572 file. Create a reloc section in dynobj and
1573 make room for this reloc. */
1574 sreloc = _bfd_elf_create_ifunc_dyn_reloc
1575 (abfd, info, sec, sreloc,
1576 &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs);
1587 if (r_type != R_X86_64_PC32
1588 && r_type != R_X86_64_PC64)
1589 h->pointer_equality_needed = 1;
1592 case R_X86_64_PLT32:
1595 case R_X86_64_GOTPCREL:
1596 case R_X86_64_GOTPCREL64:
1597 h->got.refcount += 1;
1598 if (htab->elf.sgot == NULL
1599 && !_bfd_elf_create_got_section (htab->elf.dynobj,
1609 if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
1610 symtab_hdr, sym_hashes,
1611 &r_type, GOT_UNKNOWN,
1612 rel, rel_end, h, r_symndx))
1617 case R_X86_64_TLSLD:
1618 htab->tls_ld_got.refcount += 1;
1621 case R_X86_64_TPOFF32:
1622 if (!info->executable && ABI_64_P (abfd))
1625 name = h->root.root.string;
1627 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1629 (*_bfd_error_handler)
1630 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1632 x86_64_elf_howto_table[r_type].name, name);
1633 bfd_set_error (bfd_error_bad_value);
1638 case R_X86_64_GOTTPOFF:
1639 if (!info->executable)
1640 info->flags |= DF_STATIC_TLS;
1643 case R_X86_64_GOT32:
1644 case R_X86_64_GOTPCREL:
1645 case R_X86_64_TLSGD:
1646 case R_X86_64_GOT64:
1647 case R_X86_64_GOTPCREL64:
1648 case R_X86_64_GOTPLT64:
1649 case R_X86_64_GOTPC32_TLSDESC:
1650 case R_X86_64_TLSDESC_CALL:
1651 /* This symbol requires a global offset table entry. */
1653 int tls_type, old_tls_type;
1657 default: tls_type = GOT_NORMAL; break;
1658 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1659 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1660 case R_X86_64_GOTPC32_TLSDESC:
1661 case R_X86_64_TLSDESC_CALL:
1662 tls_type = GOT_TLS_GDESC; break;
1667 if (r_type == R_X86_64_GOTPLT64)
1669 /* This relocation indicates that we also need
1670 a PLT entry, as this is a function. We don't need
1671 a PLT entry for local symbols. */
1673 h->plt.refcount += 1;
1675 h->got.refcount += 1;
1676 old_tls_type = elf_x86_64_hash_entry (h)->tls_type;
1680 bfd_signed_vma *local_got_refcounts;
1682 /* This is a global offset table entry for a local symbol. */
1683 local_got_refcounts = elf_local_got_refcounts (abfd);
1684 if (local_got_refcounts == NULL)
1688 size = symtab_hdr->sh_info;
1689 size *= sizeof (bfd_signed_vma)
1690 + sizeof (bfd_vma) + sizeof (char);
1691 local_got_refcounts = ((bfd_signed_vma *)
1692 bfd_zalloc (abfd, size));
1693 if (local_got_refcounts == NULL)
1695 elf_local_got_refcounts (abfd) = local_got_refcounts;
1696 elf_x86_64_local_tlsdesc_gotent (abfd)
1697 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1698 elf_x86_64_local_got_tls_type (abfd)
1699 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1701 local_got_refcounts[r_symndx] += 1;
1703 = elf_x86_64_local_got_tls_type (abfd) [r_symndx];
1706 /* If a TLS symbol is accessed using IE at least once,
1707 there is no point to use dynamic model for it. */
1708 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1709 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1710 || tls_type != GOT_TLS_IE))
1712 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1713 tls_type = old_tls_type;
1714 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1715 && GOT_TLS_GD_ANY_P (tls_type))
1716 tls_type |= old_tls_type;
1720 name = h->root.root.string;
1722 name = bfd_elf_sym_name (abfd, symtab_hdr,
1724 (*_bfd_error_handler)
1725 (_("%B: '%s' accessed both as normal and thread local symbol"),
1731 if (old_tls_type != tls_type)
1734 elf_x86_64_hash_entry (h)->tls_type = tls_type;
1736 elf_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1741 case R_X86_64_GOTOFF64:
1742 case R_X86_64_GOTPC32:
1743 case R_X86_64_GOTPC64:
1745 if (htab->elf.sgot == NULL)
1747 if (htab->elf.dynobj == NULL)
1748 htab->elf.dynobj = abfd;
1749 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
1755 case R_X86_64_PLT32:
1756 /* This symbol requires a procedure linkage table entry. We
1757 actually build the entry in adjust_dynamic_symbol,
1758 because this might be a case of linking PIC code which is
1759 never referenced by a dynamic object, in which case we
1760 don't need to generate a procedure linkage table entry
1763 /* If this is a local symbol, we resolve it directly without
1764 creating a procedure linkage table entry. */
1769 h->plt.refcount += 1;
1772 case R_X86_64_PLTOFF64:
1773 /* This tries to form the 'address' of a function relative
1774 to GOT. For global symbols we need a PLT entry. */
1778 h->plt.refcount += 1;
1783 if (!ABI_64_P (abfd))
1788 /* Let's help debug shared library creation. These relocs
1789 cannot be used in shared libs. Don't error out for
1790 sections we don't care about, such as debug sections or
1791 non-constant sections. */
1793 && (sec->flags & SEC_ALLOC) != 0
1794 && (sec->flags & SEC_READONLY) != 0)
1797 name = h->root.root.string;
1799 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1800 (*_bfd_error_handler)
1801 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1802 abfd, x86_64_elf_howto_table[r_type].name, name);
1803 bfd_set_error (bfd_error_bad_value);
1814 if (h != NULL && info->executable)
1816 /* If this reloc is in a read-only section, we might
1817 need a copy reloc. We can't check reliably at this
1818 stage whether the section is read-only, as input
1819 sections have not yet been mapped to output sections.
1820 Tentatively set the flag for now, and correct in
1821 adjust_dynamic_symbol. */
1824 /* We may need a .plt entry if the function this reloc
1825 refers to is in a shared lib. */
1826 h->plt.refcount += 1;
1827 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1828 h->pointer_equality_needed = 1;
1831 /* If we are creating a shared library, and this is a reloc
1832 against a global symbol, or a non PC relative reloc
1833 against a local symbol, then we need to copy the reloc
1834 into the shared library. However, if we are linking with
1835 -Bsymbolic, we do not need to copy a reloc against a
1836 global symbol which is defined in an object we are
1837 including in the link (i.e., DEF_REGULAR is set). At
1838 this point we have not seen all the input files, so it is
1839 possible that DEF_REGULAR is not set now but will be set
1840 later (it is never cleared). In case of a weak definition,
1841 DEF_REGULAR may be cleared later by a strong definition in
1842 a shared library. We account for that possibility below by
1843 storing information in the relocs_copied field of the hash
1844 table entry. A similar situation occurs when creating
1845 shared libraries and symbol visibility changes render the
1848 If on the other hand, we are creating an executable, we
1849 may need to keep relocations for symbols satisfied by a
1850 dynamic library if we manage to avoid copy relocs for the
1853 && (sec->flags & SEC_ALLOC) != 0
1854 && (! IS_X86_64_PCREL_TYPE (r_type)
1856 && (! SYMBOLIC_BIND (info, h)
1857 || h->root.type == bfd_link_hash_defweak
1858 || !h->def_regular))))
1859 || (ELIMINATE_COPY_RELOCS
1861 && (sec->flags & SEC_ALLOC) != 0
1863 && (h->root.type == bfd_link_hash_defweak
1864 || !h->def_regular)))
1866 struct elf_dyn_relocs *p;
1867 struct elf_dyn_relocs **head;
1869 /* We must copy these reloc types into the output file.
1870 Create a reloc section in dynobj and make room for
1874 if (htab->elf.dynobj == NULL)
1875 htab->elf.dynobj = abfd;
1877 sreloc = _bfd_elf_make_dynamic_reloc_section
1878 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
1879 abfd, /*rela?*/ TRUE);
1885 /* If this is a global symbol, we count the number of
1886 relocations we need for this symbol. */
1889 head = &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs;
1893 /* Track dynamic relocs needed for local syms too.
1894 We really need local syms available to do this
1899 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1904 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1908 /* Beware of type punned pointers vs strict aliasing
1910 vpp = &(elf_section_data (s)->local_dynrel);
1911 head = (struct elf_dyn_relocs **)vpp;
1915 if (p == NULL || p->sec != sec)
1917 bfd_size_type amt = sizeof *p;
1919 p = ((struct elf_dyn_relocs *)
1920 bfd_alloc (htab->elf.dynobj, amt));
1931 if (IS_X86_64_PCREL_TYPE (r_type))
1936 /* This relocation describes the C++ object vtable hierarchy.
1937 Reconstruct it for later use during GC. */
1938 case R_X86_64_GNU_VTINHERIT:
1939 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1943 /* This relocation describes which C++ vtable entries are actually
1944 used. Record for later use during GC. */
1945 case R_X86_64_GNU_VTENTRY:
1946 BFD_ASSERT (h != NULL);
1948 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1960 /* Return the section that should be marked against GC for a given
1964 elf_x86_64_gc_mark_hook (asection *sec,
1965 struct bfd_link_info *info,
1966 Elf_Internal_Rela *rel,
1967 struct elf_link_hash_entry *h,
1968 Elf_Internal_Sym *sym)
1971 switch (ELF32_R_TYPE (rel->r_info))
1973 case R_X86_64_GNU_VTINHERIT:
1974 case R_X86_64_GNU_VTENTRY:
1978 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1981 /* Update the got entry reference counts for the section being removed. */
1984 elf_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1986 const Elf_Internal_Rela *relocs)
1988 struct elf_x86_64_link_hash_table *htab;
1989 Elf_Internal_Shdr *symtab_hdr;
1990 struct elf_link_hash_entry **sym_hashes;
1991 bfd_signed_vma *local_got_refcounts;
1992 const Elf_Internal_Rela *rel, *relend;
1994 if (info->relocatable)
1997 htab = elf_x86_64_hash_table (info);
2001 elf_section_data (sec)->local_dynrel = NULL;
2003 symtab_hdr = &elf_symtab_hdr (abfd);
2004 sym_hashes = elf_sym_hashes (abfd);
2005 local_got_refcounts = elf_local_got_refcounts (abfd);
2007 htab = elf_x86_64_hash_table (info);
2008 relend = relocs + sec->reloc_count;
2009 for (rel = relocs; rel < relend; rel++)
2011 unsigned long r_symndx;
2012 unsigned int r_type;
2013 struct elf_link_hash_entry *h = NULL;
2015 r_symndx = htab->r_sym (rel->r_info);
2016 if (r_symndx >= symtab_hdr->sh_info)
2018 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2019 while (h->root.type == bfd_link_hash_indirect
2020 || h->root.type == bfd_link_hash_warning)
2021 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2025 /* A local symbol. */
2026 Elf_Internal_Sym *isym;
2028 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2031 /* Check relocation against local STT_GNU_IFUNC symbol. */
2033 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
2035 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel, FALSE);
2043 struct elf_x86_64_link_hash_entry *eh;
2044 struct elf_dyn_relocs **pp;
2045 struct elf_dyn_relocs *p;
2047 eh = (struct elf_x86_64_link_hash_entry *) h;
2049 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
2052 /* Everything must go for SEC. */
2058 r_type = ELF32_R_TYPE (rel->r_info);
2059 if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
2060 symtab_hdr, sym_hashes,
2061 &r_type, GOT_UNKNOWN,
2062 rel, relend, h, r_symndx))
2067 case R_X86_64_TLSLD:
2068 if (htab->tls_ld_got.refcount > 0)
2069 htab->tls_ld_got.refcount -= 1;
2072 case R_X86_64_TLSGD:
2073 case R_X86_64_GOTPC32_TLSDESC:
2074 case R_X86_64_TLSDESC_CALL:
2075 case R_X86_64_GOTTPOFF:
2076 case R_X86_64_GOT32:
2077 case R_X86_64_GOTPCREL:
2078 case R_X86_64_GOT64:
2079 case R_X86_64_GOTPCREL64:
2080 case R_X86_64_GOTPLT64:
2083 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
2084 h->plt.refcount -= 1;
2085 if (h->got.refcount > 0)
2086 h->got.refcount -= 1;
2087 if (h->type == STT_GNU_IFUNC)
2089 if (h->plt.refcount > 0)
2090 h->plt.refcount -= 1;
2093 else if (local_got_refcounts != NULL)
2095 if (local_got_refcounts[r_symndx] > 0)
2096 local_got_refcounts[r_symndx] -= 1;
2110 && (h == NULL || h->type != STT_GNU_IFUNC))
2114 case R_X86_64_PLT32:
2115 case R_X86_64_PLTOFF64:
2118 if (h->plt.refcount > 0)
2119 h->plt.refcount -= 1;
2131 /* Adjust a symbol defined by a dynamic object and referenced by a
2132 regular object. The current definition is in some section of the
2133 dynamic object, but we're not including those sections. We have to
2134 change the definition to something the rest of the link can
2138 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
2139 struct elf_link_hash_entry *h)
2141 struct elf_x86_64_link_hash_table *htab;
2144 /* STT_GNU_IFUNC symbol must go through PLT. */
2145 if (h->type == STT_GNU_IFUNC)
2147 if (h->plt.refcount <= 0)
2149 h->plt.offset = (bfd_vma) -1;
2155 /* If this is a function, put it in the procedure linkage table. We
2156 will fill in the contents of the procedure linkage table later,
2157 when we know the address of the .got section. */
2158 if (h->type == STT_FUNC
2161 if (h->plt.refcount <= 0
2162 || SYMBOL_CALLS_LOCAL (info, h)
2163 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2164 && h->root.type == bfd_link_hash_undefweak))
2166 /* This case can occur if we saw a PLT32 reloc in an input
2167 file, but the symbol was never referred to by a dynamic
2168 object, or if all references were garbage collected. In
2169 such a case, we don't actually need to build a procedure
2170 linkage table, and we can just do a PC32 reloc instead. */
2171 h->plt.offset = (bfd_vma) -1;
2178 /* It's possible that we incorrectly decided a .plt reloc was
2179 needed for an R_X86_64_PC32 reloc to a non-function sym in
2180 check_relocs. We can't decide accurately between function and
2181 non-function syms in check-relocs; Objects loaded later in
2182 the link may change h->type. So fix it now. */
2183 h->plt.offset = (bfd_vma) -1;
2185 /* If this is a weak symbol, and there is a real definition, the
2186 processor independent code will have arranged for us to see the
2187 real definition first, and we can just use the same value. */
2188 if (h->u.weakdef != NULL)
2190 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2191 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2192 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2193 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2194 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
2195 h->non_got_ref = h->u.weakdef->non_got_ref;
2199 /* This is a reference to a symbol defined by a dynamic object which
2200 is not a function. */
2202 /* If we are creating a shared library, we must presume that the
2203 only references to the symbol are via the global offset table.
2204 For such cases we need not do anything here; the relocations will
2205 be handled correctly by relocate_section. */
2209 /* If there are no references to this symbol that do not use the
2210 GOT, we don't need to generate a copy reloc. */
2211 if (!h->non_got_ref)
2214 /* If -z nocopyreloc was given, we won't generate them either. */
2215 if (info->nocopyreloc)
2221 if (ELIMINATE_COPY_RELOCS)
2223 struct elf_x86_64_link_hash_entry * eh;
2224 struct elf_dyn_relocs *p;
2226 eh = (struct elf_x86_64_link_hash_entry *) h;
2227 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2229 s = p->sec->output_section;
2230 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2234 /* If we didn't find any dynamic relocs in read-only sections, then
2235 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2243 /* We must allocate the symbol in our .dynbss section, which will
2244 become part of the .bss section of the executable. There will be
2245 an entry for this symbol in the .dynsym section. The dynamic
2246 object will contain position independent code, so all references
2247 from the dynamic object to this symbol will go through the global
2248 offset table. The dynamic linker will use the .dynsym entry to
2249 determine the address it must put in the global offset table, so
2250 both the dynamic object and the regular object will refer to the
2251 same memory location for the variable. */
2253 htab = elf_x86_64_hash_table (info);
2257 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2258 to copy the initial value out of the dynamic object and into the
2259 runtime process image. */
2260 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2262 const struct elf_backend_data *bed;
2263 bed = get_elf_backend_data (info->output_bfd);
2264 htab->srelbss->size += bed->s->sizeof_rela;
2270 return _bfd_elf_adjust_dynamic_copy (h, s);
2273 /* Allocate space in .plt, .got and associated reloc sections for
2277 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2279 struct bfd_link_info *info;
2280 struct elf_x86_64_link_hash_table *htab;
2281 struct elf_x86_64_link_hash_entry *eh;
2282 struct elf_dyn_relocs *p;
2283 const struct elf_backend_data *bed;
2284 unsigned int plt_entry_size;
2286 if (h->root.type == bfd_link_hash_indirect)
2289 eh = (struct elf_x86_64_link_hash_entry *) h;
2291 info = (struct bfd_link_info *) inf;
2292 htab = elf_x86_64_hash_table (info);
2295 bed = get_elf_backend_data (info->output_bfd);
2296 plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
2298 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2299 here if it is defined and referenced in a non-shared object. */
2300 if (h->type == STT_GNU_IFUNC
2302 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
2306 else if (htab->elf.dynamic_sections_created
2307 && h->plt.refcount > 0)
2309 /* Make sure this symbol is output as a dynamic symbol.
2310 Undefined weak syms won't yet be marked as dynamic. */
2311 if (h->dynindx == -1
2312 && !h->forced_local)
2314 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2319 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2321 asection *s = htab->elf.splt;
2323 /* If this is the first .plt entry, make room for the special
2326 s->size += plt_entry_size;
2328 h->plt.offset = s->size;
2330 /* If this symbol is not defined in a regular file, and we are
2331 not generating a shared library, then set the symbol to this
2332 location in the .plt. This is required to make function
2333 pointers compare as equal between the normal executable and
2334 the shared library. */
2338 h->root.u.def.section = s;
2339 h->root.u.def.value = h->plt.offset;
2342 /* Make room for this entry. */
2343 s->size += plt_entry_size;
2345 /* We also need to make an entry in the .got.plt section, which
2346 will be placed in the .got section by the linker script. */
2347 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
2349 /* We also need to make an entry in the .rela.plt section. */
2350 htab->elf.srelplt->size += bed->s->sizeof_rela;
2351 htab->elf.srelplt->reloc_count++;
2355 h->plt.offset = (bfd_vma) -1;
2361 h->plt.offset = (bfd_vma) -1;
2365 eh->tlsdesc_got = (bfd_vma) -1;
2367 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2368 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2369 if (h->got.refcount > 0
2372 && elf_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
2374 h->got.offset = (bfd_vma) -1;
2376 else if (h->got.refcount > 0)
2380 int tls_type = elf_x86_64_hash_entry (h)->tls_type;
2382 /* Make sure this symbol is output as a dynamic symbol.
2383 Undefined weak syms won't yet be marked as dynamic. */
2384 if (h->dynindx == -1
2385 && !h->forced_local)
2387 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2391 if (GOT_TLS_GDESC_P (tls_type))
2393 eh->tlsdesc_got = htab->elf.sgotplt->size
2394 - elf_x86_64_compute_jump_table_size (htab);
2395 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2396 h->got.offset = (bfd_vma) -2;
2398 if (! GOT_TLS_GDESC_P (tls_type)
2399 || GOT_TLS_GD_P (tls_type))
2402 h->got.offset = s->size;
2403 s->size += GOT_ENTRY_SIZE;
2404 if (GOT_TLS_GD_P (tls_type))
2405 s->size += GOT_ENTRY_SIZE;
2407 dyn = htab->elf.dynamic_sections_created;
2408 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2410 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2411 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2412 || tls_type == GOT_TLS_IE)
2413 htab->elf.srelgot->size += bed->s->sizeof_rela;
2414 else if (GOT_TLS_GD_P (tls_type))
2415 htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
2416 else if (! GOT_TLS_GDESC_P (tls_type)
2417 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2418 || h->root.type != bfd_link_hash_undefweak)
2420 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2421 htab->elf.srelgot->size += bed->s->sizeof_rela;
2422 if (GOT_TLS_GDESC_P (tls_type))
2424 htab->elf.srelplt->size += bed->s->sizeof_rela;
2425 htab->tlsdesc_plt = (bfd_vma) -1;
2429 h->got.offset = (bfd_vma) -1;
2431 if (eh->dyn_relocs == NULL)
2434 /* In the shared -Bsymbolic case, discard space allocated for
2435 dynamic pc-relative relocs against symbols which turn out to be
2436 defined in regular objects. For the normal shared case, discard
2437 space for pc-relative relocs that have become local due to symbol
2438 visibility changes. */
2442 /* Relocs that use pc_count are those that appear on a call
2443 insn, or certain REL relocs that can generated via assembly.
2444 We want calls to protected symbols to resolve directly to the
2445 function rather than going via the plt. If people want
2446 function pointer comparisons to work as expected then they
2447 should avoid writing weird assembly. */
2448 if (SYMBOL_CALLS_LOCAL (info, h))
2450 struct elf_dyn_relocs **pp;
2452 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2454 p->count -= p->pc_count;
2463 /* Also discard relocs on undefined weak syms with non-default
2465 if (eh->dyn_relocs != NULL
2466 && h->root.type == bfd_link_hash_undefweak)
2468 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2469 eh->dyn_relocs = NULL;
2471 /* Make sure undefined weak symbols are output as a dynamic
2473 else if (h->dynindx == -1
2474 && ! h->forced_local
2475 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2480 else if (ELIMINATE_COPY_RELOCS)
2482 /* For the non-shared case, discard space for relocs against
2483 symbols which turn out to need copy relocs or are not
2489 || (htab->elf.dynamic_sections_created
2490 && (h->root.type == bfd_link_hash_undefweak
2491 || h->root.type == bfd_link_hash_undefined))))
2493 /* Make sure this symbol is output as a dynamic symbol.
2494 Undefined weak syms won't yet be marked as dynamic. */
2495 if (h->dynindx == -1
2496 && ! h->forced_local
2497 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2500 /* If that succeeded, we know we'll be keeping all the
2502 if (h->dynindx != -1)
2506 eh->dyn_relocs = NULL;
2511 /* Finally, allocate space. */
2512 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2516 sreloc = elf_section_data (p->sec)->sreloc;
2518 BFD_ASSERT (sreloc != NULL);
2520 sreloc->size += p->count * bed->s->sizeof_rela;
2526 /* Allocate space in .plt, .got and associated reloc sections for
2527 local dynamic relocs. */
2530 elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
2532 struct elf_link_hash_entry *h
2533 = (struct elf_link_hash_entry *) *slot;
2535 if (h->type != STT_GNU_IFUNC
2539 || h->root.type != bfd_link_hash_defined)
2542 return elf_x86_64_allocate_dynrelocs (h, inf);
2545 /* Find any dynamic relocs that apply to read-only sections. */
2548 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
2551 struct elf_x86_64_link_hash_entry *eh;
2552 struct elf_dyn_relocs *p;
2554 /* Skip local IFUNC symbols. */
2555 if (h->forced_local && h->type == STT_GNU_IFUNC)
2558 eh = (struct elf_x86_64_link_hash_entry *) h;
2559 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2561 asection *s = p->sec->output_section;
2563 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2565 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2567 info->flags |= DF_TEXTREL;
2569 if (info->warn_shared_textrel && info->shared)
2570 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2571 p->sec->owner, h->root.root.string,
2574 /* Not an error, just cut short the traversal. */
2581 /* Set the sizes of the dynamic sections. */
2584 elf_x86_64_size_dynamic_sections (bfd *output_bfd,
2585 struct bfd_link_info *info)
2587 struct elf_x86_64_link_hash_table *htab;
2592 const struct elf_backend_data *bed;
2594 htab = elf_x86_64_hash_table (info);
2597 bed = get_elf_backend_data (output_bfd);
2599 dynobj = htab->elf.dynobj;
2603 if (htab->elf.dynamic_sections_created)
2605 /* Set the contents of the .interp section to the interpreter. */
2606 if (info->executable)
2608 s = bfd_get_section_by_name (dynobj, ".interp");
2611 s->size = htab->dynamic_interpreter_size;
2612 s->contents = (unsigned char *) htab->dynamic_interpreter;
2616 /* Set up .got offsets for local syms, and space for local dynamic
2618 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2620 bfd_signed_vma *local_got;
2621 bfd_signed_vma *end_local_got;
2622 char *local_tls_type;
2623 bfd_vma *local_tlsdesc_gotent;
2624 bfd_size_type locsymcount;
2625 Elf_Internal_Shdr *symtab_hdr;
2628 if (! is_x86_64_elf (ibfd))
2631 for (s = ibfd->sections; s != NULL; s = s->next)
2633 struct elf_dyn_relocs *p;
2635 for (p = (struct elf_dyn_relocs *)
2636 (elf_section_data (s)->local_dynrel);
2640 if (!bfd_is_abs_section (p->sec)
2641 && bfd_is_abs_section (p->sec->output_section))
2643 /* Input section has been discarded, either because
2644 it is a copy of a linkonce section or due to
2645 linker script /DISCARD/, so we'll be discarding
2648 else if (p->count != 0)
2650 srel = elf_section_data (p->sec)->sreloc;
2651 srel->size += p->count * bed->s->sizeof_rela;
2652 if ((p->sec->output_section->flags & SEC_READONLY) != 0
2653 && (info->flags & DF_TEXTREL) == 0)
2655 info->flags |= DF_TEXTREL;
2656 if (info->warn_shared_textrel && info->shared)
2657 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2658 p->sec->owner, p->sec);
2664 local_got = elf_local_got_refcounts (ibfd);
2668 symtab_hdr = &elf_symtab_hdr (ibfd);
2669 locsymcount = symtab_hdr->sh_info;
2670 end_local_got = local_got + locsymcount;
2671 local_tls_type = elf_x86_64_local_got_tls_type (ibfd);
2672 local_tlsdesc_gotent = elf_x86_64_local_tlsdesc_gotent (ibfd);
2674 srel = htab->elf.srelgot;
2675 for (; local_got < end_local_got;
2676 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2678 *local_tlsdesc_gotent = (bfd_vma) -1;
2681 if (GOT_TLS_GDESC_P (*local_tls_type))
2683 *local_tlsdesc_gotent = htab->elf.sgotplt->size
2684 - elf_x86_64_compute_jump_table_size (htab);
2685 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2686 *local_got = (bfd_vma) -2;
2688 if (! GOT_TLS_GDESC_P (*local_tls_type)
2689 || GOT_TLS_GD_P (*local_tls_type))
2691 *local_got = s->size;
2692 s->size += GOT_ENTRY_SIZE;
2693 if (GOT_TLS_GD_P (*local_tls_type))
2694 s->size += GOT_ENTRY_SIZE;
2697 || GOT_TLS_GD_ANY_P (*local_tls_type)
2698 || *local_tls_type == GOT_TLS_IE)
2700 if (GOT_TLS_GDESC_P (*local_tls_type))
2702 htab->elf.srelplt->size
2703 += bed->s->sizeof_rela;
2704 htab->tlsdesc_plt = (bfd_vma) -1;
2706 if (! GOT_TLS_GDESC_P (*local_tls_type)
2707 || GOT_TLS_GD_P (*local_tls_type))
2708 srel->size += bed->s->sizeof_rela;
2712 *local_got = (bfd_vma) -1;
2716 if (htab->tls_ld_got.refcount > 0)
2718 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2720 htab->tls_ld_got.offset = htab->elf.sgot->size;
2721 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
2722 htab->elf.srelgot->size += bed->s->sizeof_rela;
2725 htab->tls_ld_got.offset = -1;
2727 /* Allocate global sym .plt and .got entries, and space for global
2728 sym dynamic relocs. */
2729 elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
2732 /* Allocate .plt and .got entries, and space for local symbols. */
2733 htab_traverse (htab->loc_hash_table,
2734 elf_x86_64_allocate_local_dynrelocs,
2737 /* For every jump slot reserved in the sgotplt, reloc_count is
2738 incremented. However, when we reserve space for TLS descriptors,
2739 it's not incremented, so in order to compute the space reserved
2740 for them, it suffices to multiply the reloc count by the jump
2743 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2744 so that R_X86_64_IRELATIVE entries come last. */
2745 if (htab->elf.srelplt)
2747 htab->sgotplt_jump_table_size
2748 = elf_x86_64_compute_jump_table_size (htab);
2749 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
2751 else if (htab->elf.irelplt)
2752 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
2754 if (htab->tlsdesc_plt)
2756 /* If we're not using lazy TLS relocations, don't generate the
2757 PLT and GOT entries they require. */
2758 if ((info->flags & DF_BIND_NOW))
2759 htab->tlsdesc_plt = 0;
2762 htab->tlsdesc_got = htab->elf.sgot->size;
2763 htab->elf.sgot->size += GOT_ENTRY_SIZE;
2764 /* Reserve room for the initial entry.
2765 FIXME: we could probably do away with it in this case. */
2766 if (htab->elf.splt->size == 0)
2767 htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);
2768 htab->tlsdesc_plt = htab->elf.splt->size;
2769 htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);
2773 if (htab->elf.sgotplt)
2775 struct elf_link_hash_entry *got;
2776 got = elf_link_hash_lookup (elf_hash_table (info),
2777 "_GLOBAL_OFFSET_TABLE_",
2778 FALSE, FALSE, FALSE);
2780 /* Don't allocate .got.plt section if there are no GOT nor PLT
2781 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2783 || !got->ref_regular_nonweak)
2784 && (htab->elf.sgotplt->size
2785 == get_elf_backend_data (output_bfd)->got_header_size)
2786 && (htab->elf.splt == NULL
2787 || htab->elf.splt->size == 0)
2788 && (htab->elf.sgot == NULL
2789 || htab->elf.sgot->size == 0)
2790 && (htab->elf.iplt == NULL
2791 || htab->elf.iplt->size == 0)
2792 && (htab->elf.igotplt == NULL
2793 || htab->elf.igotplt->size == 0))
2794 htab->elf.sgotplt->size = 0;
2797 /* We now have determined the sizes of the various dynamic sections.
2798 Allocate memory for them. */
2800 for (s = dynobj->sections; s != NULL; s = s->next)
2802 if ((s->flags & SEC_LINKER_CREATED) == 0)
2805 if (s == htab->elf.splt
2806 || s == htab->elf.sgot
2807 || s == htab->elf.sgotplt
2808 || s == htab->elf.iplt
2809 || s == htab->elf.igotplt
2810 || s == htab->sdynbss)
2812 /* Strip this section if we don't need it; see the
2815 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2817 if (s->size != 0 && s != htab->elf.srelplt)
2820 /* We use the reloc_count field as a counter if we need
2821 to copy relocs into the output file. */
2822 if (s != htab->elf.srelplt)
2827 /* It's not one of our sections, so don't allocate space. */
2833 /* If we don't need this section, strip it from the
2834 output file. This is mostly to handle .rela.bss and
2835 .rela.plt. We must create both sections in
2836 create_dynamic_sections, because they must be created
2837 before the linker maps input sections to output
2838 sections. The linker does that before
2839 adjust_dynamic_symbol is called, and it is that
2840 function which decides whether anything needs to go
2841 into these sections. */
2843 s->flags |= SEC_EXCLUDE;
2847 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2850 /* Allocate memory for the section contents. We use bfd_zalloc
2851 here in case unused entries are not reclaimed before the
2852 section's contents are written out. This should not happen,
2853 but this way if it does, we get a R_X86_64_NONE reloc instead
2855 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2856 if (s->contents == NULL)
2860 if (htab->plt_eh_frame != NULL
2861 && htab->elf.splt != NULL
2862 && htab->elf.splt->size != 0
2863 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0)
2864 bfd_put_32 (dynobj, htab->elf.splt->size,
2865 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
2867 if (htab->elf.dynamic_sections_created)
2869 /* Add some entries to the .dynamic section. We fill in the
2870 values later, in elf_x86_64_finish_dynamic_sections, but we
2871 must add the entries now so that we get the correct size for
2872 the .dynamic section. The DT_DEBUG entry is filled in by the
2873 dynamic linker and used by the debugger. */
2874 #define add_dynamic_entry(TAG, VAL) \
2875 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2877 if (info->executable)
2879 if (!add_dynamic_entry (DT_DEBUG, 0))
2883 if (htab->elf.splt->size != 0)
2885 if (!add_dynamic_entry (DT_PLTGOT, 0)
2886 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2887 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2888 || !add_dynamic_entry (DT_JMPREL, 0))
2891 if (htab->tlsdesc_plt
2892 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2893 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2899 if (!add_dynamic_entry (DT_RELA, 0)
2900 || !add_dynamic_entry (DT_RELASZ, 0)
2901 || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
2904 /* If any dynamic relocs apply to a read-only section,
2905 then we need a DT_TEXTREL entry. */
2906 if ((info->flags & DF_TEXTREL) == 0)
2907 elf_link_hash_traverse (&htab->elf,
2908 elf_x86_64_readonly_dynrelocs,
2911 if ((info->flags & DF_TEXTREL) != 0)
2913 if (!add_dynamic_entry (DT_TEXTREL, 0))
2918 #undef add_dynamic_entry
2924 elf_x86_64_always_size_sections (bfd *output_bfd,
2925 struct bfd_link_info *info)
2927 asection *tls_sec = elf_hash_table (info)->tls_sec;
2931 struct elf_link_hash_entry *tlsbase;
2933 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2934 "_TLS_MODULE_BASE_",
2935 FALSE, FALSE, FALSE);
2937 if (tlsbase && tlsbase->type == STT_TLS)
2939 struct elf_x86_64_link_hash_table *htab;
2940 struct bfd_link_hash_entry *bh = NULL;
2941 const struct elf_backend_data *bed
2942 = get_elf_backend_data (output_bfd);
2944 htab = elf_x86_64_hash_table (info);
2948 if (!(_bfd_generic_link_add_one_symbol
2949 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2950 tls_sec, 0, NULL, FALSE,
2951 bed->collect, &bh)))
2954 htab->tls_module_base = bh;
2956 tlsbase = (struct elf_link_hash_entry *)bh;
2957 tlsbase->def_regular = 1;
2958 tlsbase->other = STV_HIDDEN;
2959 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2966 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2967 executables. Rather than setting it to the beginning of the TLS
2968 section, we have to set it to the end. This function may be called
2969 multiple times, it is idempotent. */
2972 elf_x86_64_set_tls_module_base (struct bfd_link_info *info)
2974 struct elf_x86_64_link_hash_table *htab;
2975 struct bfd_link_hash_entry *base;
2977 if (!info->executable)
2980 htab = elf_x86_64_hash_table (info);
2984 base = htab->tls_module_base;
2988 base->u.def.value = htab->elf.tls_size;
2991 /* Return the base VMA address which should be subtracted from real addresses
2992 when resolving @dtpoff relocation.
2993 This is PT_TLS segment p_vaddr. */
2996 elf_x86_64_dtpoff_base (struct bfd_link_info *info)
2998 /* If tls_sec is NULL, we should have signalled an error already. */
2999 if (elf_hash_table (info)->tls_sec == NULL)
3001 return elf_hash_table (info)->tls_sec->vma;
3004 /* Return the relocation value for @tpoff relocation
3005 if STT_TLS virtual address is ADDRESS. */
3008 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
3010 struct elf_link_hash_table *htab = elf_hash_table (info);
3011 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
3012 bfd_vma static_tls_size;
3014 /* If tls_segment is NULL, we should have signalled an error already. */
3015 if (htab->tls_sec == NULL)
3018 /* Consider special static TLS alignment requirements. */
3019 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
3020 return address - static_tls_size - htab->tls_sec->vma;
3023 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3027 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
3029 /* Opcode Instruction
3032 0x0f 0x8x conditional jump */
3034 && (contents [offset - 1] == 0xe8
3035 || contents [offset - 1] == 0xe9))
3037 && contents [offset - 2] == 0x0f
3038 && (contents [offset - 1] & 0xf0) == 0x80));
3041 /* Relocate an x86_64 ELF section. */
3044 elf_x86_64_relocate_section (bfd *output_bfd,
3045 struct bfd_link_info *info,
3047 asection *input_section,
3049 Elf_Internal_Rela *relocs,
3050 Elf_Internal_Sym *local_syms,
3051 asection **local_sections)
3053 struct elf_x86_64_link_hash_table *htab;
3054 Elf_Internal_Shdr *symtab_hdr;
3055 struct elf_link_hash_entry **sym_hashes;
3056 bfd_vma *local_got_offsets;
3057 bfd_vma *local_tlsdesc_gotents;
3058 Elf_Internal_Rela *rel;
3059 Elf_Internal_Rela *relend;
3060 const unsigned int plt_entry_size = GET_PLT_ENTRY_SIZE (info->output_bfd);
3062 BFD_ASSERT (is_x86_64_elf (input_bfd));
3064 htab = elf_x86_64_hash_table (info);
3067 symtab_hdr = &elf_symtab_hdr (input_bfd);
3068 sym_hashes = elf_sym_hashes (input_bfd);
3069 local_got_offsets = elf_local_got_offsets (input_bfd);
3070 local_tlsdesc_gotents = elf_x86_64_local_tlsdesc_gotent (input_bfd);
3072 elf_x86_64_set_tls_module_base (info);
3075 relend = relocs + input_section->reloc_count;
3076 for (; rel < relend; rel++)
3078 unsigned int r_type;
3079 reloc_howto_type *howto;
3080 unsigned long r_symndx;
3081 struct elf_link_hash_entry *h;
3082 Elf_Internal_Sym *sym;
3084 bfd_vma off, offplt;
3086 bfd_boolean unresolved_reloc;
3087 bfd_reloc_status_type r;
3091 r_type = ELF32_R_TYPE (rel->r_info);
3092 if (r_type == (int) R_X86_64_GNU_VTINHERIT
3093 || r_type == (int) R_X86_64_GNU_VTENTRY)
3096 if (r_type >= R_X86_64_max)
3098 bfd_set_error (bfd_error_bad_value);
3102 if (r_type != (int) R_X86_64_32
3103 || ABI_64_P (output_bfd))
3104 howto = x86_64_elf_howto_table + r_type;
3106 howto = (x86_64_elf_howto_table
3107 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
3108 r_symndx = htab->r_sym (rel->r_info);
3112 unresolved_reloc = FALSE;
3113 if (r_symndx < symtab_hdr->sh_info)
3115 sym = local_syms + r_symndx;
3116 sec = local_sections[r_symndx];
3118 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
3121 /* Relocate against local STT_GNU_IFUNC symbol. */
3122 if (!info->relocatable
3123 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
3125 h = elf_x86_64_get_local_sym_hash (htab, input_bfd,
3130 /* Set STT_GNU_IFUNC symbol value. */
3131 h->root.u.def.value = sym->st_value;
3132 h->root.u.def.section = sec;
3137 bfd_boolean warned ATTRIBUTE_UNUSED;
3139 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3140 r_symndx, symtab_hdr, sym_hashes,
3142 unresolved_reloc, warned);
3145 if (sec != NULL && elf_discarded_section (sec))
3146 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3147 rel, relend, howto, contents);
3149 if (info->relocatable)
3152 if (rel->r_addend == 0
3153 && r_type == R_X86_64_64
3154 && !ABI_64_P (output_bfd))
3156 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3157 it to 64bit if addend is zero. */
3158 r_type = R_X86_64_32;
3159 memset (contents + rel->r_offset + 4, 0, 4);
3162 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3163 it here if it is defined in a non-shared object. */
3165 && h->type == STT_GNU_IFUNC
3172 if ((input_section->flags & SEC_ALLOC) == 0
3173 || h->plt.offset == (bfd_vma) -1)
3176 /* STT_GNU_IFUNC symbol must go through PLT. */
3177 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
3178 relocation = (plt->output_section->vma
3179 + plt->output_offset + h->plt.offset);
3184 if (h->root.root.string)
3185 name = h->root.root.string;
3187 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3189 (*_bfd_error_handler)
3190 (_("%B: relocation %s against STT_GNU_IFUNC "
3191 "symbol `%s' isn't handled by %s"), input_bfd,
3192 x86_64_elf_howto_table[r_type].name,
3193 name, __FUNCTION__);
3194 bfd_set_error (bfd_error_bad_value);
3203 if (ABI_64_P (output_bfd))
3207 if (rel->r_addend != 0)
3209 if (h->root.root.string)
3210 name = h->root.root.string;
3212 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
3214 (*_bfd_error_handler)
3215 (_("%B: relocation %s against STT_GNU_IFUNC "
3216 "symbol `%s' has non-zero addend: %d"),
3217 input_bfd, x86_64_elf_howto_table[r_type].name,
3218 name, rel->r_addend);
3219 bfd_set_error (bfd_error_bad_value);
3223 /* Generate dynamic relcoation only when there is a
3224 non-GOT reference in a shared object. */
3225 if (info->shared && h->non_got_ref)
3227 Elf_Internal_Rela outrel;
3230 /* Need a dynamic relocation to get the real function
3232 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
3236 if (outrel.r_offset == (bfd_vma) -1
3237 || outrel.r_offset == (bfd_vma) -2)
3240 outrel.r_offset += (input_section->output_section->vma
3241 + input_section->output_offset);
3243 if (h->dynindx == -1
3245 || info->executable)
3247 /* This symbol is resolved locally. */
3248 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
3249 outrel.r_addend = (h->root.u.def.value
3250 + h->root.u.def.section->output_section->vma
3251 + h->root.u.def.section->output_offset);
3255 outrel.r_info = htab->r_info (h->dynindx, r_type);
3256 outrel.r_addend = 0;
3259 sreloc = htab->elf.irelifunc;
3260 elf_append_rela (output_bfd, sreloc, &outrel);
3262 /* If this reloc is against an external symbol, we
3263 do not want to fiddle with the addend. Otherwise,
3264 we need to include the symbol value so that it
3265 becomes an addend for the dynamic reloc. For an
3266 internal symbol, we have updated addend. */
3272 case R_X86_64_PLT32:
3275 case R_X86_64_GOTPCREL:
3276 case R_X86_64_GOTPCREL64:
3277 base_got = htab->elf.sgot;
3278 off = h->got.offset;
3280 if (base_got == NULL)
3283 if (off == (bfd_vma) -1)
3285 /* We can't use h->got.offset here to save state, or
3286 even just remember the offset, as finish_dynamic_symbol
3287 would use that as offset into .got. */
3289 if (htab->elf.splt != NULL)
3291 plt_index = h->plt.offset / plt_entry_size - 1;
3292 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3293 base_got = htab->elf.sgotplt;
3297 plt_index = h->plt.offset / plt_entry_size;
3298 off = plt_index * GOT_ENTRY_SIZE;
3299 base_got = htab->elf.igotplt;
3302 if (h->dynindx == -1
3306 /* This references the local defitionion. We must
3307 initialize this entry in the global offset table.
3308 Since the offset must always be a multiple of 8,
3309 we use the least significant bit to record
3310 whether we have initialized it already.
3312 When doing a dynamic link, we create a .rela.got
3313 relocation entry to initialize the value. This
3314 is done in the finish_dynamic_symbol routine. */
3319 bfd_put_64 (output_bfd, relocation,
3320 base_got->contents + off);
3321 /* Note that this is harmless for the GOTPLT64
3322 case, as -1 | 1 still is -1. */
3328 relocation = (base_got->output_section->vma
3329 + base_got->output_offset + off);
3335 /* When generating a shared object, the relocations handled here are
3336 copied into the output file to be resolved at run time. */
3339 case R_X86_64_GOT32:
3340 case R_X86_64_GOT64:
3341 /* Relocation is to the entry for this symbol in the global
3343 case R_X86_64_GOTPCREL:
3344 case R_X86_64_GOTPCREL64:
3345 /* Use global offset table entry as symbol value. */
3346 case R_X86_64_GOTPLT64:
3347 /* This is the same as GOT64 for relocation purposes, but
3348 indicates the existence of a PLT entry. The difficulty is,
3349 that we must calculate the GOT slot offset from the PLT
3350 offset, if this symbol got a PLT entry (it was global).
3351 Additionally if it's computed from the PLT entry, then that
3352 GOT offset is relative to .got.plt, not to .got. */
3353 base_got = htab->elf.sgot;
3355 if (htab->elf.sgot == NULL)
3362 off = h->got.offset;
3364 && h->plt.offset != (bfd_vma)-1
3365 && off == (bfd_vma)-1)
3367 /* We can't use h->got.offset here to save
3368 state, or even just remember the offset, as
3369 finish_dynamic_symbol would use that as offset into
3371 bfd_vma plt_index = h->plt.offset / plt_entry_size - 1;
3372 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3373 base_got = htab->elf.sgotplt;
3376 dyn = htab->elf.dynamic_sections_created;
3378 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3380 && SYMBOL_REFERENCES_LOCAL (info, h))
3381 || (ELF_ST_VISIBILITY (h->other)
3382 && h->root.type == bfd_link_hash_undefweak))
3384 /* This is actually a static link, or it is a -Bsymbolic
3385 link and the symbol is defined locally, or the symbol
3386 was forced to be local because of a version file. We
3387 must initialize this entry in the global offset table.
3388 Since the offset must always be a multiple of 8, we
3389 use the least significant bit to record whether we
3390 have initialized it already.
3392 When doing a dynamic link, we create a .rela.got
3393 relocation entry to initialize the value. This is
3394 done in the finish_dynamic_symbol routine. */
3399 bfd_put_64 (output_bfd, relocation,
3400 base_got->contents + off);
3401 /* Note that this is harmless for the GOTPLT64 case,
3402 as -1 | 1 still is -1. */
3407 unresolved_reloc = FALSE;
3411 if (local_got_offsets == NULL)
3414 off = local_got_offsets[r_symndx];
3416 /* The offset must always be a multiple of 8. We use
3417 the least significant bit to record whether we have
3418 already generated the necessary reloc. */
3423 bfd_put_64 (output_bfd, relocation,
3424 base_got->contents + off);
3429 Elf_Internal_Rela outrel;
3431 /* We need to generate a R_X86_64_RELATIVE reloc
3432 for the dynamic linker. */
3433 s = htab->elf.srelgot;
3437 outrel.r_offset = (base_got->output_section->vma
3438 + base_got->output_offset
3440 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3441 outrel.r_addend = relocation;
3442 elf_append_rela (output_bfd, s, &outrel);
3445 local_got_offsets[r_symndx] |= 1;
3449 if (off >= (bfd_vma) -2)
3452 relocation = base_got->output_section->vma
3453 + base_got->output_offset + off;
3454 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
3455 relocation -= htab->elf.sgotplt->output_section->vma
3456 - htab->elf.sgotplt->output_offset;
3460 case R_X86_64_GOTOFF64:
3461 /* Relocation is relative to the start of the global offset
3464 /* Check to make sure it isn't a protected function symbol
3465 for shared library since it may not be local when used
3466 as function address. */
3470 && h->type == STT_FUNC
3471 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3473 (*_bfd_error_handler)
3474 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3475 input_bfd, h->root.root.string);
3476 bfd_set_error (bfd_error_bad_value);
3480 /* Note that sgot is not involved in this
3481 calculation. We always want the start of .got.plt. If we
3482 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3483 permitted by the ABI, we might have to change this
3485 relocation -= htab->elf.sgotplt->output_section->vma
3486 + htab->elf.sgotplt->output_offset;
3489 case R_X86_64_GOTPC32:
3490 case R_X86_64_GOTPC64:
3491 /* Use global offset table as symbol value. */
3492 relocation = htab->elf.sgotplt->output_section->vma
3493 + htab->elf.sgotplt->output_offset;
3494 unresolved_reloc = FALSE;
3497 case R_X86_64_PLTOFF64:
3498 /* Relocation is PLT entry relative to GOT. For local
3499 symbols it's the symbol itself relative to GOT. */
3501 /* See PLT32 handling. */
3502 && h->plt.offset != (bfd_vma) -1
3503 && htab->elf.splt != NULL)
3505 relocation = (htab->elf.splt->output_section->vma
3506 + htab->elf.splt->output_offset
3508 unresolved_reloc = FALSE;
3511 relocation -= htab->elf.sgotplt->output_section->vma
3512 + htab->elf.sgotplt->output_offset;
3515 case R_X86_64_PLT32:
3516 /* Relocation is to the entry for this symbol in the
3517 procedure linkage table. */
3519 /* Resolve a PLT32 reloc against a local symbol directly,
3520 without using the procedure linkage table. */
3524 if (h->plt.offset == (bfd_vma) -1
3525 || htab->elf.splt == NULL)
3527 /* We didn't make a PLT entry for this symbol. This
3528 happens when statically linking PIC code, or when
3529 using -Bsymbolic. */
3533 relocation = (htab->elf.splt->output_section->vma
3534 + htab->elf.splt->output_offset
3536 unresolved_reloc = FALSE;
3543 && (input_section->flags & SEC_ALLOC) != 0
3544 && (input_section->flags & SEC_READONLY) != 0
3547 bfd_boolean fail = FALSE;
3549 = (r_type == R_X86_64_PC32
3550 && is_32bit_relative_branch (contents, rel->r_offset));
3552 if (SYMBOL_REFERENCES_LOCAL (info, h))
3554 /* Symbol is referenced locally. Make sure it is
3555 defined locally or for a branch. */
3556 fail = !h->def_regular && !branch;
3560 /* Symbol isn't referenced locally. We only allow
3561 branch to symbol with non-default visibility. */
3563 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
3570 const char *pic = "";
3572 switch (ELF_ST_VISIBILITY (h->other))
3575 v = _("hidden symbol");
3578 v = _("internal symbol");
3581 v = _("protected symbol");
3585 pic = _("; recompile with -fPIC");
3590 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3592 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3594 (*_bfd_error_handler) (fmt, input_bfd,
3595 x86_64_elf_howto_table[r_type].name,
3596 v, h->root.root.string, pic);
3597 bfd_set_error (bfd_error_bad_value);
3608 /* FIXME: The ABI says the linker should make sure the value is
3609 the same when it's zeroextended to 64 bit. */
3611 if ((input_section->flags & SEC_ALLOC) == 0)
3616 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3617 || h->root.type != bfd_link_hash_undefweak)
3618 && (! IS_X86_64_PCREL_TYPE (r_type)
3619 || ! SYMBOL_CALLS_LOCAL (info, h)))
3620 || (ELIMINATE_COPY_RELOCS
3627 || h->root.type == bfd_link_hash_undefweak
3628 || h->root.type == bfd_link_hash_undefined)))
3630 Elf_Internal_Rela outrel;
3631 bfd_boolean skip, relocate;
3634 /* When generating a shared object, these relocations
3635 are copied into the output file to be resolved at run
3641 _bfd_elf_section_offset (output_bfd, info, input_section,
3643 if (outrel.r_offset == (bfd_vma) -1)
3645 else if (outrel.r_offset == (bfd_vma) -2)
3646 skip = TRUE, relocate = TRUE;
3648 outrel.r_offset += (input_section->output_section->vma
3649 + input_section->output_offset);
3652 memset (&outrel, 0, sizeof outrel);
3654 /* h->dynindx may be -1 if this symbol was marked to
3658 && (IS_X86_64_PCREL_TYPE (r_type)
3660 || ! SYMBOLIC_BIND (info, h)
3661 || ! h->def_regular))
3663 outrel.r_info = htab->r_info (h->dynindx, r_type);
3664 outrel.r_addend = rel->r_addend;
3668 /* This symbol is local, or marked to become local. */
3669 if (r_type == htab->pointer_r_type)
3672 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3673 outrel.r_addend = relocation + rel->r_addend;
3675 else if (r_type == R_X86_64_64
3676 && !ABI_64_P (output_bfd))
3679 outrel.r_info = htab->r_info (0,
3680 R_X86_64_RELATIVE64);
3681 outrel.r_addend = relocation + rel->r_addend;
3687 if (bfd_is_abs_section (sec))
3689 else if (sec == NULL || sec->owner == NULL)
3691 bfd_set_error (bfd_error_bad_value);
3698 /* We are turning this relocation into one
3699 against a section symbol. It would be
3700 proper to subtract the symbol's value,
3701 osec->vma, from the emitted reloc addend,
3702 but ld.so expects buggy relocs. */
3703 osec = sec->output_section;
3704 sindx = elf_section_data (osec)->dynindx;
3707 asection *oi = htab->elf.text_index_section;
3708 sindx = elf_section_data (oi)->dynindx;
3710 BFD_ASSERT (sindx != 0);
3713 outrel.r_info = htab->r_info (sindx, r_type);
3714 outrel.r_addend = relocation + rel->r_addend;
3718 sreloc = elf_section_data (input_section)->sreloc;
3720 if (sreloc == NULL || sreloc->contents == NULL)
3722 r = bfd_reloc_notsupported;
3723 goto check_relocation_error;
3726 elf_append_rela (output_bfd, sreloc, &outrel);
3728 /* If this reloc is against an external symbol, we do
3729 not want to fiddle with the addend. Otherwise, we
3730 need to include the symbol value so that it becomes
3731 an addend for the dynamic reloc. */
3738 case R_X86_64_TLSGD:
3739 case R_X86_64_GOTPC32_TLSDESC:
3740 case R_X86_64_TLSDESC_CALL:
3741 case R_X86_64_GOTTPOFF:
3742 tls_type = GOT_UNKNOWN;
3743 if (h == NULL && local_got_offsets)
3744 tls_type = elf_x86_64_local_got_tls_type (input_bfd) [r_symndx];
3746 tls_type = elf_x86_64_hash_entry (h)->tls_type;
3748 if (! elf_x86_64_tls_transition (info, input_bfd,
3749 input_section, contents,
3750 symtab_hdr, sym_hashes,
3751 &r_type, tls_type, rel,
3752 relend, h, r_symndx))
3755 if (r_type == R_X86_64_TPOFF32)
3757 bfd_vma roff = rel->r_offset;
3759 BFD_ASSERT (! unresolved_reloc);
3761 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3763 /* GD->LE transition. For 64bit, change
3764 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3765 .word 0x6666; rex64; call __tls_get_addr
3768 leaq foo@tpoff(%rax), %rax
3770 leaq foo@tlsgd(%rip), %rdi
3771 .word 0x6666; rex64; call __tls_get_addr
3774 leaq foo@tpoff(%rax), %rax */
3775 if (ABI_64_P (output_bfd))
3776 memcpy (contents + roff - 4,
3777 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3780 memcpy (contents + roff - 3,
3781 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3783 bfd_put_32 (output_bfd,
3784 elf_x86_64_tpoff (info, relocation),
3785 contents + roff + 8);
3786 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3790 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3792 /* GDesc -> LE transition.
3793 It's originally something like:
3794 leaq x@tlsdesc(%rip), %rax
3797 movl $x@tpoff, %rax. */
3799 unsigned int val, type;
3801 type = bfd_get_8 (input_bfd, contents + roff - 3);
3802 val = bfd_get_8 (input_bfd, contents + roff - 1);
3803 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
3804 contents + roff - 3);
3805 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
3806 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3807 contents + roff - 1);
3808 bfd_put_32 (output_bfd,
3809 elf_x86_64_tpoff (info, relocation),
3813 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3815 /* GDesc -> LE transition.
3820 bfd_put_8 (output_bfd, 0x66, contents + roff);
3821 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3824 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
3826 /* IE->LE transition:
3827 Originally it can be one of:
3828 movq foo@gottpoff(%rip), %reg
3829 addq foo@gottpoff(%rip), %reg
3832 leaq foo(%reg), %reg
3835 unsigned int val, type, reg;
3837 val = bfd_get_8 (input_bfd, contents + roff - 3);
3838 type = bfd_get_8 (input_bfd, contents + roff - 2);
3839 reg = bfd_get_8 (input_bfd, contents + roff - 1);
3845 bfd_put_8 (output_bfd, 0x49,
3846 contents + roff - 3);
3847 else if (!ABI_64_P (output_bfd) && val == 0x44)
3848 bfd_put_8 (output_bfd, 0x41,
3849 contents + roff - 3);
3850 bfd_put_8 (output_bfd, 0xc7,
3851 contents + roff - 2);
3852 bfd_put_8 (output_bfd, 0xc0 | reg,
3853 contents + roff - 1);
3857 /* addq -> addq - addressing with %rsp/%r12 is
3860 bfd_put_8 (output_bfd, 0x49,
3861 contents + roff - 3);
3862 else if (!ABI_64_P (output_bfd) && val == 0x44)
3863 bfd_put_8 (output_bfd, 0x41,
3864 contents + roff - 3);
3865 bfd_put_8 (output_bfd, 0x81,
3866 contents + roff - 2);
3867 bfd_put_8 (output_bfd, 0xc0 | reg,
3868 contents + roff - 1);
3874 bfd_put_8 (output_bfd, 0x4d,
3875 contents + roff - 3);
3876 else if (!ABI_64_P (output_bfd) && val == 0x44)
3877 bfd_put_8 (output_bfd, 0x45,
3878 contents + roff - 3);
3879 bfd_put_8 (output_bfd, 0x8d,
3880 contents + roff - 2);
3881 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
3882 contents + roff - 1);
3884 bfd_put_32 (output_bfd,
3885 elf_x86_64_tpoff (info, relocation),
3893 if (htab->elf.sgot == NULL)
3898 off = h->got.offset;
3899 offplt = elf_x86_64_hash_entry (h)->tlsdesc_got;
3903 if (local_got_offsets == NULL)
3906 off = local_got_offsets[r_symndx];
3907 offplt = local_tlsdesc_gotents[r_symndx];
3914 Elf_Internal_Rela outrel;
3918 if (htab->elf.srelgot == NULL)
3921 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3923 if (GOT_TLS_GDESC_P (tls_type))
3925 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
3926 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3927 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
3928 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3929 + htab->elf.sgotplt->output_offset
3931 + htab->sgotplt_jump_table_size);
3932 sreloc = htab->elf.srelplt;
3934 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
3936 outrel.r_addend = 0;
3937 elf_append_rela (output_bfd, sreloc, &outrel);
3940 sreloc = htab->elf.srelgot;
3942 outrel.r_offset = (htab->elf.sgot->output_section->vma
3943 + htab->elf.sgot->output_offset + off);
3945 if (GOT_TLS_GD_P (tls_type))
3946 dr_type = R_X86_64_DTPMOD64;
3947 else if (GOT_TLS_GDESC_P (tls_type))
3950 dr_type = R_X86_64_TPOFF64;
3952 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
3953 outrel.r_addend = 0;
3954 if ((dr_type == R_X86_64_TPOFF64
3955 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3956 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
3957 outrel.r_info = htab->r_info (indx, dr_type);
3959 elf_append_rela (output_bfd, sreloc, &outrel);
3961 if (GOT_TLS_GD_P (tls_type))
3965 BFD_ASSERT (! unresolved_reloc);
3966 bfd_put_64 (output_bfd,
3967 relocation - elf_x86_64_dtpoff_base (info),
3968 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3972 bfd_put_64 (output_bfd, 0,
3973 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3974 outrel.r_info = htab->r_info (indx,
3976 outrel.r_offset += GOT_ENTRY_SIZE;
3977 elf_append_rela (output_bfd, sreloc,
3986 local_got_offsets[r_symndx] |= 1;
3989 if (off >= (bfd_vma) -2
3990 && ! GOT_TLS_GDESC_P (tls_type))
3992 if (r_type == ELF32_R_TYPE (rel->r_info))
3994 if (r_type == R_X86_64_GOTPC32_TLSDESC
3995 || r_type == R_X86_64_TLSDESC_CALL)
3996 relocation = htab->elf.sgotplt->output_section->vma
3997 + htab->elf.sgotplt->output_offset
3998 + offplt + htab->sgotplt_jump_table_size;
4000 relocation = htab->elf.sgot->output_section->vma
4001 + htab->elf.sgot->output_offset + off;
4002 unresolved_reloc = FALSE;
4006 bfd_vma roff = rel->r_offset;
4008 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
4010 /* GD->IE transition. For 64bit, change
4011 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4012 .word 0x6666; rex64; call __tls_get_addr@plt
4015 addq foo@gottpoff(%rip), %rax
4017 leaq foo@tlsgd(%rip), %rdi
4018 .word 0x6666; rex64; call __tls_get_addr@plt
4021 addq foo@gottpoff(%rip), %rax */
4022 if (ABI_64_P (output_bfd))
4023 memcpy (contents + roff - 4,
4024 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4027 memcpy (contents + roff - 3,
4028 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4031 relocation = (htab->elf.sgot->output_section->vma
4032 + htab->elf.sgot->output_offset + off
4034 - input_section->output_section->vma
4035 - input_section->output_offset
4037 bfd_put_32 (output_bfd, relocation,
4038 contents + roff + 8);
4039 /* Skip R_X86_64_PLT32. */
4043 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
4045 /* GDesc -> IE transition.
4046 It's originally something like:
4047 leaq x@tlsdesc(%rip), %rax
4050 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4052 /* Now modify the instruction as appropriate. To
4053 turn a leaq into a movq in the form we use it, it
4054 suffices to change the second byte from 0x8d to
4056 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
4058 bfd_put_32 (output_bfd,
4059 htab->elf.sgot->output_section->vma
4060 + htab->elf.sgot->output_offset + off
4062 - input_section->output_section->vma
4063 - input_section->output_offset
4068 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
4070 /* GDesc -> IE transition.
4077 bfd_put_8 (output_bfd, 0x66, contents + roff);
4078 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4086 case R_X86_64_TLSLD:
4087 if (! elf_x86_64_tls_transition (info, input_bfd,
4088 input_section, contents,
4089 symtab_hdr, sym_hashes,
4090 &r_type, GOT_UNKNOWN,
4091 rel, relend, h, r_symndx))
4094 if (r_type != R_X86_64_TLSLD)
4096 /* LD->LE transition:
4097 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4098 For 64bit, we change it into:
4099 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4100 For 32bit, we change it into:
4101 nopl 0x0(%rax); movl %fs:0, %eax. */
4103 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
4104 if (ABI_64_P (output_bfd))
4105 memcpy (contents + rel->r_offset - 3,
4106 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4108 memcpy (contents + rel->r_offset - 3,
4109 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4110 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4115 if (htab->elf.sgot == NULL)
4118 off = htab->tls_ld_got.offset;
4123 Elf_Internal_Rela outrel;
4125 if (htab->elf.srelgot == NULL)
4128 outrel.r_offset = (htab->elf.sgot->output_section->vma
4129 + htab->elf.sgot->output_offset + off);
4131 bfd_put_64 (output_bfd, 0,
4132 htab->elf.sgot->contents + off);
4133 bfd_put_64 (output_bfd, 0,
4134 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
4135 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
4136 outrel.r_addend = 0;
4137 elf_append_rela (output_bfd, htab->elf.srelgot,
4139 htab->tls_ld_got.offset |= 1;
4141 relocation = htab->elf.sgot->output_section->vma
4142 + htab->elf.sgot->output_offset + off;
4143 unresolved_reloc = FALSE;
4146 case R_X86_64_DTPOFF32:
4147 if (!info->executable|| (input_section->flags & SEC_CODE) == 0)
4148 relocation -= elf_x86_64_dtpoff_base (info);
4150 relocation = elf_x86_64_tpoff (info, relocation);
4153 case R_X86_64_TPOFF32:
4154 case R_X86_64_TPOFF64:
4155 BFD_ASSERT (info->executable);
4156 relocation = elf_x86_64_tpoff (info, relocation);
4163 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4164 because such sections are not SEC_ALLOC and thus ld.so will
4165 not process them. */
4166 if (unresolved_reloc
4167 && !((input_section->flags & SEC_DEBUGGING) != 0
4169 && _bfd_elf_section_offset (output_bfd, info, input_section,
4170 rel->r_offset) != (bfd_vma) -1)
4171 (*_bfd_error_handler)
4172 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4175 (long) rel->r_offset,
4177 h->root.root.string);
4180 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4181 contents, rel->r_offset,
4182 relocation, rel->r_addend);
4184 check_relocation_error:
4185 if (r != bfd_reloc_ok)
4190 name = h->root.root.string;
4193 name = bfd_elf_string_from_elf_section (input_bfd,
4194 symtab_hdr->sh_link,
4199 name = bfd_section_name (input_bfd, sec);
4202 if (r == bfd_reloc_overflow)
4204 if (! ((*info->callbacks->reloc_overflow)
4205 (info, (h ? &h->root : NULL), name, howto->name,
4206 (bfd_vma) 0, input_bfd, input_section,
4212 (*_bfd_error_handler)
4213 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4214 input_bfd, input_section,
4215 (long) rel->r_offset, name, (int) r);
4224 /* Finish up dynamic symbol handling. We set the contents of various
4225 dynamic sections here. */
4228 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
4229 struct bfd_link_info *info,
4230 struct elf_link_hash_entry *h,
4231 Elf_Internal_Sym *sym)
4233 struct elf_x86_64_link_hash_table *htab;
4234 const struct elf_x86_64_backend_data *const abed
4235 = get_elf_x86_64_backend_data (output_bfd);
4237 htab = elf_x86_64_hash_table (info);
4241 if (h->plt.offset != (bfd_vma) -1)
4245 Elf_Internal_Rela rela;
4247 asection *plt, *gotplt, *relplt;
4248 const struct elf_backend_data *bed;
4250 /* When building a static executable, use .iplt, .igot.plt and
4251 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4252 if (htab->elf.splt != NULL)
4254 plt = htab->elf.splt;
4255 gotplt = htab->elf.sgotplt;
4256 relplt = htab->elf.srelplt;
4260 plt = htab->elf.iplt;
4261 gotplt = htab->elf.igotplt;
4262 relplt = htab->elf.irelplt;
4265 /* This symbol has an entry in the procedure linkage table. Set
4267 if ((h->dynindx == -1
4268 && !((h->forced_local || info->executable)
4270 && h->type == STT_GNU_IFUNC))
4276 /* Get the index in the procedure linkage table which
4277 corresponds to this symbol. This is the index of this symbol
4278 in all the symbols for which we are making plt entries. The
4279 first entry in the procedure linkage table is reserved.
4281 Get the offset into the .got table of the entry that
4282 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4283 bytes. The first three are reserved for the dynamic linker.
4285 For static executables, we don't reserve anything. */
4287 if (plt == htab->elf.splt)
4289 got_offset = h->plt.offset / abed->plt_entry_size - 1;
4290 got_offset = (got_offset + 3) * GOT_ENTRY_SIZE;
4294 got_offset = h->plt.offset / abed->plt_entry_size;
4295 got_offset = got_offset * GOT_ENTRY_SIZE;
4298 /* Fill in the entry in the procedure linkage table. */
4299 memcpy (plt->contents + h->plt.offset, abed->plt_entry,
4300 abed->plt_entry_size);
4302 /* Insert the relocation positions of the plt section. */
4304 /* Put offset the PC-relative instruction referring to the GOT entry,
4305 subtracting the size of that instruction. */
4306 bfd_put_32 (output_bfd,
4307 (gotplt->output_section->vma
4308 + gotplt->output_offset
4310 - plt->output_section->vma
4311 - plt->output_offset
4313 - abed->plt_got_insn_size),
4314 plt->contents + h->plt.offset + abed->plt_got_offset);
4316 /* Fill in the entry in the global offset table, initially this
4317 points to the second part of the PLT entry. */
4318 bfd_put_64 (output_bfd, (plt->output_section->vma
4319 + plt->output_offset
4320 + h->plt.offset + abed->plt_lazy_offset),
4321 gotplt->contents + got_offset);
4323 /* Fill in the entry in the .rela.plt section. */
4324 rela.r_offset = (gotplt->output_section->vma
4325 + gotplt->output_offset
4327 if (h->dynindx == -1
4328 || ((info->executable
4329 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4331 && h->type == STT_GNU_IFUNC))
4333 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4334 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4335 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
4336 rela.r_addend = (h->root.u.def.value
4337 + h->root.u.def.section->output_section->vma
4338 + h->root.u.def.section->output_offset);
4339 /* R_X86_64_IRELATIVE comes last. */
4340 plt_index = htab->next_irelative_index--;
4344 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
4346 plt_index = htab->next_jump_slot_index++;
4349 /* Don't fill PLT entry for static executables. */
4350 if (plt == htab->elf.splt)
4352 /* Put relocation index. */
4353 bfd_put_32 (output_bfd, plt_index,
4354 plt->contents + h->plt.offset + abed->plt_reloc_offset);
4355 /* Put offset for jmp .PLT0. */
4356 bfd_put_32 (output_bfd, - (h->plt.offset + abed->plt_plt_insn_end),
4357 plt->contents + h->plt.offset + abed->plt_plt_offset);
4360 bed = get_elf_backend_data (output_bfd);
4361 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
4362 bed->s->swap_reloca_out (output_bfd, &rela, loc);
4364 if (!h->def_regular)
4366 /* Mark the symbol as undefined, rather than as defined in
4367 the .plt section. Leave the value if there were any
4368 relocations where pointer equality matters (this is a clue
4369 for the dynamic linker, to make function pointer
4370 comparisons work between an application and shared
4371 library), otherwise set it to zero. If a function is only
4372 called from a binary, there is no need to slow down
4373 shared libraries because of that. */
4374 sym->st_shndx = SHN_UNDEF;
4375 if (!h->pointer_equality_needed)
4380 if (h->got.offset != (bfd_vma) -1
4381 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h)->tls_type)
4382 && elf_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
4384 Elf_Internal_Rela rela;
4386 /* This symbol has an entry in the global offset table. Set it
4388 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
4391 rela.r_offset = (htab->elf.sgot->output_section->vma
4392 + htab->elf.sgot->output_offset
4393 + (h->got.offset &~ (bfd_vma) 1));
4395 /* If this is a static link, or it is a -Bsymbolic link and the
4396 symbol is defined locally or was forced to be local because
4397 of a version file, we just want to emit a RELATIVE reloc.
4398 The entry in the global offset table will already have been
4399 initialized in the relocate_section function. */
4401 && h->type == STT_GNU_IFUNC)
4405 /* Generate R_X86_64_GLOB_DAT. */
4412 if (!h->pointer_equality_needed)
4415 /* For non-shared object, we can't use .got.plt, which
4416 contains the real function addres if we need pointer
4417 equality. We load the GOT entry with the PLT entry. */
4418 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4419 bfd_put_64 (output_bfd, (plt->output_section->vma
4420 + plt->output_offset
4422 htab->elf.sgot->contents + h->got.offset);
4426 else if (info->shared
4427 && SYMBOL_REFERENCES_LOCAL (info, h))
4429 if (!h->def_regular)
4431 BFD_ASSERT((h->got.offset & 1) != 0);
4432 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4433 rela.r_addend = (h->root.u.def.value
4434 + h->root.u.def.section->output_section->vma
4435 + h->root.u.def.section->output_offset);
4439 BFD_ASSERT((h->got.offset & 1) == 0);
4441 bfd_put_64 (output_bfd, (bfd_vma) 0,
4442 htab->elf.sgot->contents + h->got.offset);
4443 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
4447 elf_append_rela (output_bfd, htab->elf.srelgot, &rela);
4452 Elf_Internal_Rela rela;
4454 /* This symbol needs a copy reloc. Set it up. */
4456 if (h->dynindx == -1
4457 || (h->root.type != bfd_link_hash_defined
4458 && h->root.type != bfd_link_hash_defweak)
4459 || htab->srelbss == NULL)
4462 rela.r_offset = (h->root.u.def.value
4463 + h->root.u.def.section->output_section->vma
4464 + h->root.u.def.section->output_offset);
4465 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
4467 elf_append_rela (output_bfd, htab->srelbss, &rela);
4470 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4471 be NULL for local symbols. */
4473 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
4474 || h == htab->elf.hgot))
4475 sym->st_shndx = SHN_ABS;
4480 /* Finish up local dynamic symbol handling. We set the contents of
4481 various dynamic sections here. */
4484 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
4486 struct elf_link_hash_entry *h
4487 = (struct elf_link_hash_entry *) *slot;
4488 struct bfd_link_info *info
4489 = (struct bfd_link_info *) inf;
4491 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
4495 /* Used to decide how to sort relocs in an optimal manner for the
4496 dynamic linker, before writing them out. */
4498 static enum elf_reloc_type_class
4499 elf_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
4501 switch ((int) ELF32_R_TYPE (rela->r_info))
4503 case R_X86_64_RELATIVE:
4504 return reloc_class_relative;
4505 case R_X86_64_JUMP_SLOT:
4506 return reloc_class_plt;
4508 return reloc_class_copy;
4510 return reloc_class_normal;
4514 /* Finish up the dynamic sections. */
4517 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
4518 struct bfd_link_info *info)
4520 struct elf_x86_64_link_hash_table *htab;
4523 const struct elf_x86_64_backend_data *const abed
4524 = get_elf_x86_64_backend_data (output_bfd);
4526 htab = elf_x86_64_hash_table (info);
4530 dynobj = htab->elf.dynobj;
4531 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4533 if (htab->elf.dynamic_sections_created)
4535 bfd_byte *dyncon, *dynconend;
4536 const struct elf_backend_data *bed;
4537 bfd_size_type sizeof_dyn;
4539 if (sdyn == NULL || htab->elf.sgot == NULL)
4542 bed = get_elf_backend_data (dynobj);
4543 sizeof_dyn = bed->s->sizeof_dyn;
4544 dyncon = sdyn->contents;
4545 dynconend = sdyn->contents + sdyn->size;
4546 for (; dyncon < dynconend; dyncon += sizeof_dyn)
4548 Elf_Internal_Dyn dyn;
4551 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
4559 s = htab->elf.sgotplt;
4560 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4564 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
4568 s = htab->elf.srelplt->output_section;
4569 dyn.d_un.d_val = s->size;
4573 /* The procedure linkage table relocs (DT_JMPREL) should
4574 not be included in the overall relocs (DT_RELA).
4575 Therefore, we override the DT_RELASZ entry here to
4576 make it not include the JMPREL relocs. Since the
4577 linker script arranges for .rela.plt to follow all
4578 other relocation sections, we don't have to worry
4579 about changing the DT_RELA entry. */
4580 if (htab->elf.srelplt != NULL)
4582 s = htab->elf.srelplt->output_section;
4583 dyn.d_un.d_val -= s->size;
4587 case DT_TLSDESC_PLT:
4589 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4590 + htab->tlsdesc_plt;
4593 case DT_TLSDESC_GOT:
4595 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4596 + htab->tlsdesc_got;
4600 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
4603 /* Fill in the special first entry in the procedure linkage table. */
4604 if (htab->elf.splt && htab->elf.splt->size > 0)
4606 /* Fill in the first entry in the procedure linkage table. */
4607 memcpy (htab->elf.splt->contents,
4608 abed->plt0_entry, abed->plt_entry_size);
4609 /* Add offset for pushq GOT+8(%rip), since the instruction
4610 uses 6 bytes subtract this value. */
4611 bfd_put_32 (output_bfd,
4612 (htab->elf.sgotplt->output_section->vma
4613 + htab->elf.sgotplt->output_offset
4615 - htab->elf.splt->output_section->vma
4616 - htab->elf.splt->output_offset
4618 htab->elf.splt->contents + abed->plt0_got1_offset);
4619 /* Add offset for the PC-relative instruction accessing GOT+16,
4620 subtracting the offset to the end of that instruction. */
4621 bfd_put_32 (output_bfd,
4622 (htab->elf.sgotplt->output_section->vma
4623 + htab->elf.sgotplt->output_offset
4625 - htab->elf.splt->output_section->vma
4626 - htab->elf.splt->output_offset
4627 - abed->plt0_got2_insn_end),
4628 htab->elf.splt->contents + abed->plt0_got2_offset);
4630 elf_section_data (htab->elf.splt->output_section)
4631 ->this_hdr.sh_entsize = abed->plt_entry_size;
4633 if (htab->tlsdesc_plt)
4635 bfd_put_64 (output_bfd, (bfd_vma) 0,
4636 htab->elf.sgot->contents + htab->tlsdesc_got);
4638 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
4639 abed->plt0_entry, abed->plt_entry_size);
4641 /* Add offset for pushq GOT+8(%rip), since the
4642 instruction uses 6 bytes subtract this value. */
4643 bfd_put_32 (output_bfd,
4644 (htab->elf.sgotplt->output_section->vma
4645 + htab->elf.sgotplt->output_offset
4647 - htab->elf.splt->output_section->vma
4648 - htab->elf.splt->output_offset
4651 htab->elf.splt->contents
4652 + htab->tlsdesc_plt + abed->plt0_got1_offset);
4653 /* Add offset for the PC-relative instruction accessing GOT+TDG,
4654 where TGD stands for htab->tlsdesc_got, subtracting the offset
4655 to the end of that instruction. */
4656 bfd_put_32 (output_bfd,
4657 (htab->elf.sgot->output_section->vma
4658 + htab->elf.sgot->output_offset
4660 - htab->elf.splt->output_section->vma
4661 - htab->elf.splt->output_offset
4663 - abed->plt0_got2_insn_end),
4664 htab->elf.splt->contents
4665 + htab->tlsdesc_plt + abed->plt0_got2_offset);
4670 if (htab->elf.sgotplt)
4672 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
4674 (*_bfd_error_handler)
4675 (_("discarded output section: `%A'"), htab->elf.sgotplt);
4679 /* Fill in the first three entries in the global offset table. */
4680 if (htab->elf.sgotplt->size > 0)
4682 /* Set the first entry in the global offset table to the address of
4683 the dynamic section. */
4685 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
4687 bfd_put_64 (output_bfd,
4688 sdyn->output_section->vma + sdyn->output_offset,
4689 htab->elf.sgotplt->contents);
4690 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4691 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
4692 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
4695 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
4699 /* Adjust .eh_frame for .plt section. */
4700 if (htab->plt_eh_frame != NULL)
4702 if (htab->elf.splt != NULL
4703 && htab->elf.splt->size != 0
4704 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
4705 && htab->elf.splt->output_section != NULL
4706 && htab->plt_eh_frame->output_section != NULL)
4708 bfd_vma plt_start = htab->elf.splt->output_section->vma;
4709 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
4710 + htab->plt_eh_frame->output_offset
4711 + PLT_FDE_START_OFFSET;
4712 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
4713 htab->plt_eh_frame->contents
4714 + PLT_FDE_START_OFFSET);
4716 if (htab->plt_eh_frame->sec_info_type
4717 == ELF_INFO_TYPE_EH_FRAME)
4719 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
4721 htab->plt_eh_frame->contents))
4726 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4727 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
4730 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4731 htab_traverse (htab->loc_hash_table,
4732 elf_x86_64_finish_local_dynamic_symbol,
4738 /* Return address for Ith PLT stub in section PLT, for relocation REL
4739 or (bfd_vma) -1 if it should not be included. */
4742 elf_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
4743 const arelent *rel ATTRIBUTE_UNUSED)
4745 return plt->vma + (i + 1) * GET_PLT_ENTRY_SIZE (plt->owner);
4748 /* Handle an x86-64 specific section when reading an object file. This
4749 is called when elfcode.h finds a section with an unknown type. */
4752 elf_x86_64_section_from_shdr (bfd *abfd,
4753 Elf_Internal_Shdr *hdr,
4757 if (hdr->sh_type != SHT_X86_64_UNWIND)
4760 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
4766 /* Hook called by the linker routine which adds symbols from an object
4767 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4771 elf_x86_64_add_symbol_hook (bfd *abfd,
4772 struct bfd_link_info *info,
4773 Elf_Internal_Sym *sym,
4774 const char **namep ATTRIBUTE_UNUSED,
4775 flagword *flagsp ATTRIBUTE_UNUSED,
4781 switch (sym->st_shndx)
4783 case SHN_X86_64_LCOMMON:
4784 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
4787 lcomm = bfd_make_section_with_flags (abfd,
4791 | SEC_LINKER_CREATED));
4794 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
4797 *valp = sym->st_size;
4801 if ((abfd->flags & DYNAMIC) == 0
4802 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
4803 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
4804 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4810 /* Given a BFD section, try to locate the corresponding ELF section
4814 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4815 asection *sec, int *index_return)
4817 if (sec == &_bfd_elf_large_com_section)
4819 *index_return = SHN_X86_64_LCOMMON;
4825 /* Process a symbol. */
4828 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
4831 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
4833 switch (elfsym->internal_elf_sym.st_shndx)
4835 case SHN_X86_64_LCOMMON:
4836 asym->section = &_bfd_elf_large_com_section;
4837 asym->value = elfsym->internal_elf_sym.st_size;
4838 /* Common symbol doesn't set BSF_GLOBAL. */
4839 asym->flags &= ~BSF_GLOBAL;
4845 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
4847 return (sym->st_shndx == SHN_COMMON
4848 || sym->st_shndx == SHN_X86_64_LCOMMON);
4852 elf_x86_64_common_section_index (asection *sec)
4854 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4857 return SHN_X86_64_LCOMMON;
4861 elf_x86_64_common_section (asection *sec)
4863 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4864 return bfd_com_section_ptr;
4866 return &_bfd_elf_large_com_section;
4870 elf_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4871 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
4872 struct elf_link_hash_entry *h,
4873 Elf_Internal_Sym *sym,
4875 bfd_vma *pvalue ATTRIBUTE_UNUSED,
4876 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
4877 bfd_boolean *skip ATTRIBUTE_UNUSED,
4878 bfd_boolean *override ATTRIBUTE_UNUSED,
4879 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
4880 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
4881 bfd_boolean *newdyn ATTRIBUTE_UNUSED,
4882 bfd_boolean *newdef,
4883 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
4884 bfd_boolean *newweak ATTRIBUTE_UNUSED,
4885 bfd *abfd ATTRIBUTE_UNUSED,
4887 bfd_boolean *olddyn ATTRIBUTE_UNUSED,
4888 bfd_boolean *olddef,
4889 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
4890 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
4894 /* A normal common symbol and a large common symbol result in a
4895 normal common symbol. We turn the large common symbol into a
4898 && h->root.type == bfd_link_hash_common
4900 && bfd_is_com_section (*sec)
4903 if (sym->st_shndx == SHN_COMMON
4904 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
4906 h->root.u.c.p->section
4907 = bfd_make_section_old_way (oldbfd, "COMMON");
4908 h->root.u.c.p->section->flags = SEC_ALLOC;
4910 else if (sym->st_shndx == SHN_X86_64_LCOMMON
4911 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
4912 *psec = *sec = bfd_com_section_ptr;
4919 elf_x86_64_additional_program_headers (bfd *abfd,
4920 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4925 /* Check to see if we need a large readonly segment. */
4926 s = bfd_get_section_by_name (abfd, ".lrodata");
4927 if (s && (s->flags & SEC_LOAD))
4930 /* Check to see if we need a large data segment. Since .lbss sections
4931 is placed right after the .bss section, there should be no need for
4932 a large data segment just because of .lbss. */
4933 s = bfd_get_section_by_name (abfd, ".ldata");
4934 if (s && (s->flags & SEC_LOAD))
4940 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4943 elf_x86_64_hash_symbol (struct elf_link_hash_entry *h)
4945 if (h->plt.offset != (bfd_vma) -1
4947 && !h->pointer_equality_needed)
4950 return _bfd_elf_hash_symbol (h);
4953 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4956 elf_x86_64_relocs_compatible (const bfd_target *input,
4957 const bfd_target *output)
4959 return ((xvec_get_elf_backend_data (input)->s->elfclass
4960 == xvec_get_elf_backend_data (output)->s->elfclass)
4961 && _bfd_elf_relocs_compatible (input, output));
4964 static const struct bfd_elf_special_section
4965 elf_x86_64_special_sections[]=
4967 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4968 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4969 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
4970 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4971 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4972 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4973 { NULL, 0, 0, 0, 0 }
4976 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4977 #define TARGET_LITTLE_NAME "elf64-x86-64"
4978 #define ELF_ARCH bfd_arch_i386
4979 #define ELF_TARGET_ID X86_64_ELF_DATA
4980 #define ELF_MACHINE_CODE EM_X86_64
4981 #define ELF_MAXPAGESIZE 0x200000
4982 #define ELF_MINPAGESIZE 0x1000
4983 #define ELF_COMMONPAGESIZE 0x1000
4985 #define elf_backend_can_gc_sections 1
4986 #define elf_backend_can_refcount 1
4987 #define elf_backend_want_got_plt 1
4988 #define elf_backend_plt_readonly 1
4989 #define elf_backend_want_plt_sym 0
4990 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4991 #define elf_backend_rela_normal 1
4992 #define elf_backend_plt_alignment 4
4994 #define elf_info_to_howto elf_x86_64_info_to_howto
4996 #define bfd_elf64_bfd_link_hash_table_create \
4997 elf_x86_64_link_hash_table_create
4998 #define bfd_elf64_bfd_link_hash_table_free \
4999 elf_x86_64_link_hash_table_free
5000 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5001 #define bfd_elf64_bfd_reloc_name_lookup \
5002 elf_x86_64_reloc_name_lookup
5004 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
5005 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5006 #define elf_backend_check_relocs elf_x86_64_check_relocs
5007 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
5008 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
5009 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5010 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5011 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
5012 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
5013 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5014 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5016 #define elf_backend_write_core_note elf_x86_64_write_core_note
5018 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5019 #define elf_backend_relocate_section elf_x86_64_relocate_section
5020 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
5021 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5022 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5023 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
5024 #define elf_backend_object_p elf64_x86_64_elf_object_p
5025 #define bfd_elf64_mkobject elf_x86_64_mkobject
5027 #define elf_backend_section_from_shdr \
5028 elf_x86_64_section_from_shdr
5030 #define elf_backend_section_from_bfd_section \
5031 elf_x86_64_elf_section_from_bfd_section
5032 #define elf_backend_add_symbol_hook \
5033 elf_x86_64_add_symbol_hook
5034 #define elf_backend_symbol_processing \
5035 elf_x86_64_symbol_processing
5036 #define elf_backend_common_section_index \
5037 elf_x86_64_common_section_index
5038 #define elf_backend_common_section \
5039 elf_x86_64_common_section
5040 #define elf_backend_common_definition \
5041 elf_x86_64_common_definition
5042 #define elf_backend_merge_symbol \
5043 elf_x86_64_merge_symbol
5044 #define elf_backend_special_sections \
5045 elf_x86_64_special_sections
5046 #define elf_backend_additional_program_headers \
5047 elf_x86_64_additional_program_headers
5048 #define elf_backend_hash_symbol \
5049 elf_x86_64_hash_symbol
5051 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5053 #include "elf64-target.h"
5055 /* FreeBSD support. */
5057 #undef TARGET_LITTLE_SYM
5058 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
5059 #undef TARGET_LITTLE_NAME
5060 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5063 #define ELF_OSABI ELFOSABI_FREEBSD
5066 #define elf64_bed elf64_x86_64_fbsd_bed
5068 #include "elf64-target.h"
5070 /* Solaris 2 support. */
5072 #undef TARGET_LITTLE_SYM
5073 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
5074 #undef TARGET_LITTLE_NAME
5075 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5077 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5078 objects won't be recognized. */
5082 #define elf64_bed elf64_x86_64_sol2_bed
5084 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5086 #undef elf_backend_static_tls_alignment
5087 #define elf_backend_static_tls_alignment 16
5089 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5091 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5093 #undef elf_backend_want_plt_sym
5094 #define elf_backend_want_plt_sym 1
5096 #include "elf64-target.h"
5098 /* Native Client support. */
5100 #undef TARGET_LITTLE_SYM
5101 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_nacl_vec
5102 #undef TARGET_LITTLE_NAME
5103 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5105 #define elf64_bed elf64_x86_64_nacl_bed
5107 #undef ELF_MAXPAGESIZE
5108 #undef ELF_MINPAGESIZE
5109 #undef ELF_COMMONPAGESIZE
5110 #define ELF_MAXPAGESIZE 0x10000
5111 #define ELF_MINPAGESIZE 0x10000
5112 #define ELF_COMMONPAGESIZE 0x10000
5114 /* Restore defaults. */
5116 #undef elf_backend_static_tls_alignment
5117 #undef elf_backend_want_plt_sym
5118 #define elf_backend_want_plt_sym 0
5120 /* NaCl uses substantially different PLT entries for the same effects. */
5122 #undef elf_backend_plt_alignment
5123 #define elf_backend_plt_alignment 5
5124 #define NACL_PLT_ENTRY_SIZE 64
5125 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5127 static const bfd_byte elf_x86_64_nacl_plt0_entry[NACL_PLT_ENTRY_SIZE] =
5129 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5130 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5131 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
5132 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5133 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5135 /* 41 bytes of nop to pad out to the standard size. */
5136 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5137 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5138 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5139 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5140 0x66, 0x66, /* excess data32 prefixes */
5141 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5144 static const bfd_byte elf_x86_64_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
5146 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5147 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
5148 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5149 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5151 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5152 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5153 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5155 /* Lazy GOT entries point here (32-byte aligned). */
5156 0x68, /* pushq immediate */
5157 0, 0, 0, 0, /* replaced with index into relocation table. */
5158 0xe9, /* jmp relative */
5159 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5161 /* 22 bytes of nop to pad out to the standard size. */
5162 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5163 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5164 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5167 /* .eh_frame covering the .plt section. */
5169 static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] =
5171 #if (PLT_CIE_LENGTH != 20 \
5172 || PLT_FDE_LENGTH != 36 \
5173 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5174 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5175 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5177 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
5178 0, 0, 0, 0, /* CIE ID */
5179 1, /* CIE version */
5180 'z', 'R', 0, /* Augmentation string */
5181 1, /* Code alignment factor */
5182 0x78, /* Data alignment factor */
5183 16, /* Return address column */
5184 1, /* Augmentation size */
5185 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
5186 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5187 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5188 DW_CFA_nop, DW_CFA_nop,
5190 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
5191 PLT_CIE_LENGTH + 8, 0, 0, 0,/* CIE pointer */
5192 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5193 0, 0, 0, 0, /* .plt size goes here */
5194 0, /* Augmentation size */
5195 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
5196 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5197 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
5198 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5199 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
5200 13, /* Block length */
5201 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
5202 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
5203 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
5204 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
5205 DW_CFA_nop, DW_CFA_nop
5208 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed =
5210 elf_x86_64_nacl_plt0_entry, /* plt0_entry */
5211 elf_x86_64_nacl_plt_entry, /* plt_entry */
5212 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
5213 2, /* plt0_got1_offset */
5214 9, /* plt0_got2_offset */
5215 13, /* plt0_got2_insn_end */
5216 3, /* plt_got_offset */
5217 33, /* plt_reloc_offset */
5218 38, /* plt_plt_offset */
5219 7, /* plt_got_insn_size */
5220 42, /* plt_plt_insn_end */
5221 32, /* plt_lazy_offset */
5222 elf_x86_64_nacl_eh_frame_plt, /* eh_frame_plt */
5223 sizeof (elf_x86_64_nacl_eh_frame_plt), /* eh_frame_plt_size */
5226 #undef elf_backend_arch_data
5227 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5229 #include "elf64-target.h"
5231 /* Native Client x32 support. */
5233 #undef TARGET_LITTLE_SYM
5234 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_nacl_vec
5235 #undef TARGET_LITTLE_NAME
5236 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5238 #define elf32_bed elf32_x86_64_nacl_bed
5240 #define bfd_elf32_bfd_link_hash_table_create \
5241 elf_x86_64_link_hash_table_create
5242 #define bfd_elf32_bfd_link_hash_table_free \
5243 elf_x86_64_link_hash_table_free
5244 #define bfd_elf32_bfd_reloc_type_lookup \
5245 elf_x86_64_reloc_type_lookup
5246 #define bfd_elf32_bfd_reloc_name_lookup \
5247 elf_x86_64_reloc_name_lookup
5248 #define bfd_elf32_mkobject \
5251 #undef elf_backend_object_p
5252 #define elf_backend_object_p \
5253 elf32_x86_64_elf_object_p
5255 #undef elf_backend_bfd_from_remote_memory
5256 #define elf_backend_bfd_from_remote_memory \
5257 _bfd_elf32_bfd_from_remote_memory
5259 #undef elf_backend_size_info
5260 #define elf_backend_size_info \
5261 _bfd_elf32_size_info
5263 #include "elf32-target.h"
5265 /* Restore defaults. */
5266 #undef elf_backend_object_p
5267 #define elf_backend_object_p elf64_x86_64_elf_object_p
5268 #undef elf_backend_bfd_from_remote_memory
5269 #undef elf_backend_size_info
5271 /* Intel L1OM support. */
5274 elf64_l1om_elf_object_p (bfd *abfd)
5276 /* Set the right machine number for an L1OM elf64 file. */
5277 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
5281 #undef TARGET_LITTLE_SYM
5282 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5283 #undef TARGET_LITTLE_NAME
5284 #define TARGET_LITTLE_NAME "elf64-l1om"
5286 #define ELF_ARCH bfd_arch_l1om
5288 #undef ELF_MACHINE_CODE
5289 #define ELF_MACHINE_CODE EM_L1OM
5294 #define elf64_bed elf64_l1om_bed
5296 #undef elf_backend_object_p
5297 #define elf_backend_object_p elf64_l1om_elf_object_p
5299 /* Restore defaults. */
5300 #undef ELF_MAXPAGESIZE
5301 #undef ELF_MINPAGESIZE
5302 #undef ELF_COMMONPAGESIZE
5303 #define ELF_MAXPAGESIZE 0x200000
5304 #define ELF_MINPAGESIZE 0x1000
5305 #define ELF_COMMONPAGESIZE 0x1000
5306 #undef elf_backend_plt_alignment
5307 #define elf_backend_plt_alignment 4
5308 #undef elf_backend_arch_data
5309 #define elf_backend_arch_data &elf_x86_64_arch_bed
5311 #include "elf64-target.h"
5313 /* FreeBSD L1OM support. */
5315 #undef TARGET_LITTLE_SYM
5316 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5317 #undef TARGET_LITTLE_NAME
5318 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5321 #define ELF_OSABI ELFOSABI_FREEBSD
5324 #define elf64_bed elf64_l1om_fbsd_bed
5326 #include "elf64-target.h"
5328 /* Intel K1OM support. */
5331 elf64_k1om_elf_object_p (bfd *abfd)
5333 /* Set the right machine number for an K1OM elf64 file. */
5334 bfd_default_set_arch_mach (abfd, bfd_arch_k1om, bfd_mach_k1om);
5338 #undef TARGET_LITTLE_SYM
5339 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5340 #undef TARGET_LITTLE_NAME
5341 #define TARGET_LITTLE_NAME "elf64-k1om"
5343 #define ELF_ARCH bfd_arch_k1om
5345 #undef ELF_MACHINE_CODE
5346 #define ELF_MACHINE_CODE EM_K1OM
5351 #define elf64_bed elf64_k1om_bed
5353 #undef elf_backend_object_p
5354 #define elf_backend_object_p elf64_k1om_elf_object_p
5356 #undef elf_backend_static_tls_alignment
5358 #undef elf_backend_want_plt_sym
5359 #define elf_backend_want_plt_sym 0
5361 #include "elf64-target.h"
5363 /* FreeBSD K1OM support. */
5365 #undef TARGET_LITTLE_SYM
5366 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5367 #undef TARGET_LITTLE_NAME
5368 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5371 #define ELF_OSABI ELFOSABI_FREEBSD
5374 #define elf64_bed elf64_k1om_fbsd_bed
5376 #include "elf64-target.h"
5378 /* 32bit x86-64 support. */
5380 #undef TARGET_LITTLE_SYM
5381 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5382 #undef TARGET_LITTLE_NAME
5383 #define TARGET_LITTLE_NAME "elf32-x86-64"
5387 #define ELF_ARCH bfd_arch_i386
5389 #undef ELF_MACHINE_CODE
5390 #define ELF_MACHINE_CODE EM_X86_64
5394 #undef elf_backend_object_p
5395 #define elf_backend_object_p \
5396 elf32_x86_64_elf_object_p
5398 #undef elf_backend_bfd_from_remote_memory
5399 #define elf_backend_bfd_from_remote_memory \
5400 _bfd_elf32_bfd_from_remote_memory
5402 #undef elf_backend_size_info
5403 #define elf_backend_size_info \
5404 _bfd_elf32_size_info
5406 #include "elf32-target.h"