1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "elfxx-x86.h"
25 #include "libiberty.h"
27 #include "opcode/i386.h"
28 #include "elf/x86-64.h"
35 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
36 #define MINUS_ONE (~ (bfd_vma) 0)
38 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
39 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
40 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
41 since they are the same. */
43 /* The relocation "howto" table. Order of fields:
44 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
45 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
46 static reloc_howto_type x86_64_elf_howto_table[] =
48 HOWTO(R_X86_64_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
49 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
51 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
52 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
54 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
55 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
58 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
61 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
63 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
64 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
66 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
67 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
69 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
70 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
72 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
73 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
75 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
76 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
78 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
79 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
81 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
82 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
84 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
85 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
86 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
87 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
88 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
89 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
90 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
91 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
92 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
93 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
95 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
96 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
98 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
99 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
101 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
102 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
104 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
105 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
107 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
108 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
110 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
111 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
113 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
114 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
116 HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
117 bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
119 HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
120 bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
121 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
122 HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
123 bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
124 FALSE, 0xffffffff, 0xffffffff, TRUE),
125 HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
126 bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
128 HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
129 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
131 HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
132 bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
133 FALSE, MINUS_ONE, MINUS_ONE, TRUE),
134 HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
135 bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
137 HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
138 bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
140 HOWTO(R_X86_64_SIZE32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
141 bfd_elf_generic_reloc, "R_X86_64_SIZE32", FALSE, 0xffffffff, 0xffffffff,
143 HOWTO(R_X86_64_SIZE64, 0, 4, 64, FALSE, 0, complain_overflow_unsigned,
144 bfd_elf_generic_reloc, "R_X86_64_SIZE64", FALSE, MINUS_ONE, MINUS_ONE,
146 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
147 complain_overflow_bitfield, bfd_elf_generic_reloc,
148 "R_X86_64_GOTPC32_TLSDESC",
149 FALSE, 0xffffffff, 0xffffffff, TRUE),
150 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
151 complain_overflow_dont, bfd_elf_generic_reloc,
152 "R_X86_64_TLSDESC_CALL",
154 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
155 complain_overflow_bitfield, bfd_elf_generic_reloc,
157 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
158 HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
159 bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
161 HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
162 bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", FALSE, MINUS_ONE,
164 HOWTO(R_X86_64_PC32_BND, 0, 2, 32, TRUE, 0, complain_overflow_signed,
165 bfd_elf_generic_reloc, "R_X86_64_PC32_BND", FALSE, 0xffffffff, 0xffffffff,
167 HOWTO(R_X86_64_PLT32_BND, 0, 2, 32, TRUE, 0, complain_overflow_signed,
168 bfd_elf_generic_reloc, "R_X86_64_PLT32_BND", FALSE, 0xffffffff, 0xffffffff,
170 HOWTO(R_X86_64_GOTPCRELX, 0, 2, 32, TRUE, 0, complain_overflow_signed,
171 bfd_elf_generic_reloc, "R_X86_64_GOTPCRELX", FALSE, 0xffffffff,
173 HOWTO(R_X86_64_REX_GOTPCRELX, 0, 2, 32, TRUE, 0, complain_overflow_signed,
174 bfd_elf_generic_reloc, "R_X86_64_REX_GOTPCRELX", FALSE, 0xffffffff,
177 /* We have a gap in the reloc numbers here.
178 R_X86_64_standard counts the number up to this point, and
179 R_X86_64_vt_offset is the value to subtract from a reloc type of
180 R_X86_64_GNU_VT* to form an index into this table. */
181 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
182 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
184 /* GNU extension to record C++ vtable hierarchy. */
185 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
186 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
188 /* GNU extension to record C++ vtable member usage. */
189 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
190 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
193 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
194 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
195 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
199 #define IS_X86_64_PCREL_TYPE(TYPE) \
200 ( ((TYPE) == R_X86_64_PC8) \
201 || ((TYPE) == R_X86_64_PC16) \
202 || ((TYPE) == R_X86_64_PC32) \
203 || ((TYPE) == R_X86_64_PC32_BND) \
204 || ((TYPE) == R_X86_64_PC64))
206 /* Map BFD relocs to the x86_64 elf relocs. */
209 bfd_reloc_code_real_type bfd_reloc_val;
210 unsigned char elf_reloc_val;
213 static const struct elf_reloc_map x86_64_reloc_map[] =
215 { BFD_RELOC_NONE, R_X86_64_NONE, },
216 { BFD_RELOC_64, R_X86_64_64, },
217 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
218 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
219 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
220 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
221 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
222 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
223 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
224 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
225 { BFD_RELOC_32, R_X86_64_32, },
226 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
227 { BFD_RELOC_16, R_X86_64_16, },
228 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
229 { BFD_RELOC_8, R_X86_64_8, },
230 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
231 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
232 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
233 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
234 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
235 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
236 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
237 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
238 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
239 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
240 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
241 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
242 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
243 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
244 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
245 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
246 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
247 { BFD_RELOC_SIZE32, R_X86_64_SIZE32, },
248 { BFD_RELOC_SIZE64, R_X86_64_SIZE64, },
249 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
250 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
251 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
252 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
253 { BFD_RELOC_X86_64_PC32_BND, R_X86_64_PC32_BND, },
254 { BFD_RELOC_X86_64_PLT32_BND, R_X86_64_PLT32_BND, },
255 { BFD_RELOC_X86_64_GOTPCRELX, R_X86_64_GOTPCRELX, },
256 { BFD_RELOC_X86_64_REX_GOTPCRELX, R_X86_64_REX_GOTPCRELX, },
257 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
258 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
261 static reloc_howto_type *
262 elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
266 if (r_type == (unsigned int) R_X86_64_32)
271 i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
273 else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
274 || r_type >= (unsigned int) R_X86_64_max)
276 if (r_type >= (unsigned int) R_X86_64_standard)
278 /* xgettext:c-format */
279 _bfd_error_handler (_("%B: invalid relocation type %d"),
281 r_type = R_X86_64_NONE;
286 i = r_type - (unsigned int) R_X86_64_vt_offset;
287 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
288 return &x86_64_elf_howto_table[i];
291 /* Given a BFD reloc type, return a HOWTO structure. */
292 static reloc_howto_type *
293 elf_x86_64_reloc_type_lookup (bfd *abfd,
294 bfd_reloc_code_real_type code)
298 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
301 if (x86_64_reloc_map[i].bfd_reloc_val == code)
302 return elf_x86_64_rtype_to_howto (abfd,
303 x86_64_reloc_map[i].elf_reloc_val);
308 static reloc_howto_type *
309 elf_x86_64_reloc_name_lookup (bfd *abfd,
314 if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
316 /* Get x32 R_X86_64_32. */
317 reloc_howto_type *reloc
318 = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
319 BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
323 for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
324 if (x86_64_elf_howto_table[i].name != NULL
325 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
326 return &x86_64_elf_howto_table[i];
331 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
334 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
335 Elf_Internal_Rela *dst)
339 r_type = ELF32_R_TYPE (dst->r_info);
340 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
341 BFD_ASSERT (r_type == cache_ptr->howto->type);
344 /* Support for core dump NOTE sections. */
346 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
351 switch (note->descsz)
356 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
358 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
361 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
369 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
371 elf_tdata (abfd)->core->signal
372 = bfd_get_16 (abfd, note->descdata + 12);
375 elf_tdata (abfd)->core->lwpid
376 = bfd_get_32 (abfd, note->descdata + 32);
385 /* Make a ".reg/999" section. */
386 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
387 size, note->descpos + offset);
391 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
393 switch (note->descsz)
398 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
399 elf_tdata (abfd)->core->pid
400 = bfd_get_32 (abfd, note->descdata + 12);
401 elf_tdata (abfd)->core->program
402 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
403 elf_tdata (abfd)->core->command
404 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
407 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
408 elf_tdata (abfd)->core->pid
409 = bfd_get_32 (abfd, note->descdata + 24);
410 elf_tdata (abfd)->core->program
411 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
412 elf_tdata (abfd)->core->command
413 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
416 /* Note that for some reason, a spurious space is tacked
417 onto the end of the args in some (at least one anyway)
418 implementations, so strip it off if it exists. */
421 char *command = elf_tdata (abfd)->core->command;
422 int n = strlen (command);
424 if (0 < n && command[n - 1] == ' ')
425 command[n - 1] = '\0';
433 elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz,
436 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
438 const char *fname, *psargs;
449 va_start (ap, note_type);
450 fname = va_arg (ap, const char *);
451 psargs = va_arg (ap, const char *);
454 if (bed->s->elfclass == ELFCLASS32)
457 memset (&data, 0, sizeof (data));
458 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
459 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
460 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
461 &data, sizeof (data));
466 memset (&data, 0, sizeof (data));
467 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
468 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
469 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
470 &data, sizeof (data));
475 va_start (ap, note_type);
476 pid = va_arg (ap, long);
477 cursig = va_arg (ap, int);
478 gregs = va_arg (ap, const void *);
481 if (bed->s->elfclass == ELFCLASS32)
483 if (bed->elf_machine_code == EM_X86_64)
485 prstatusx32_t prstat;
486 memset (&prstat, 0, sizeof (prstat));
488 prstat.pr_cursig = cursig;
489 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
490 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
491 &prstat, sizeof (prstat));
496 memset (&prstat, 0, sizeof (prstat));
498 prstat.pr_cursig = cursig;
499 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
500 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
501 &prstat, sizeof (prstat));
507 memset (&prstat, 0, sizeof (prstat));
509 prstat.pr_cursig = cursig;
510 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
511 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
512 &prstat, sizeof (prstat));
519 /* Functions for the x86-64 ELF linker. */
521 /* The size in bytes of an entry in the global offset table. */
523 #define GOT_ENTRY_SIZE 8
525 /* The size in bytes of an entry in the lazy procedure linkage table. */
527 #define LAZY_PLT_ENTRY_SIZE 16
529 /* The size in bytes of an entry in the non-lazy procedure linkage
532 #define NON_LAZY_PLT_ENTRY_SIZE 8
534 /* The first entry in a lazy procedure linkage table looks like this.
535 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
538 static const bfd_byte elf_x86_64_lazy_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
540 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
541 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
542 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
545 /* Subsequent entries in a lazy procedure linkage table look like this. */
547 static const bfd_byte elf_x86_64_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
549 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
550 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
551 0x68, /* pushq immediate */
552 0, 0, 0, 0, /* replaced with index into relocation table. */
553 0xe9, /* jmp relative */
554 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
557 /* The first entry in a lazy procedure linkage table with BND prefix
560 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
562 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
563 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
564 0x0f, 0x1f, 0 /* nopl (%rax) */
567 /* Subsequent entries for branches with BND prefx in a lazy procedure
568 linkage table look like this. */
570 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry[LAZY_PLT_ENTRY_SIZE] =
572 0x68, 0, 0, 0, 0, /* pushq immediate */
573 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
574 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
577 /* The first entry in the IBT-enabled lazy procedure linkage table is the
578 the same as the lazy PLT with BND prefix so that bound registers are
579 preserved when control is passed to dynamic linker. Subsequent
580 entries for a IBT-enabled lazy procedure linkage table look like
583 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
585 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
586 0x68, 0, 0, 0, 0, /* pushq immediate */
587 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
591 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
592 is the same as the normal lazy PLT. Subsequent entries for an
593 x32 IBT-enabled lazy procedure linkage table look like this. */
595 static const bfd_byte elf_x32_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
597 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
598 0x68, 0, 0, 0, 0, /* pushq immediate */
599 0xe9, 0, 0, 0, 0, /* jmpq relative */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* Entries in the non-lazey procedure linkage table look like this. */
605 static const bfd_byte elf_x86_64_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
607 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
608 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
609 0x66, 0x90 /* xchg %ax,%ax */
612 /* Entries for branches with BND prefix in the non-lazey procedure
613 linkage table look like this. */
615 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
617 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
618 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
622 /* Entries for branches with IBT-enabled in the non-lazey procedure
623 linkage table look like this. They have the same size as the lazy
626 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
628 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
629 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
630 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
631 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
634 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
635 linkage table look like this. They have the same size as the lazy
638 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
640 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
641 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
642 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
643 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
646 /* .eh_frame covering the lazy .plt section. */
648 static const bfd_byte elf_x86_64_eh_frame_lazy_plt[] =
650 #define PLT_CIE_LENGTH 20
651 #define PLT_FDE_LENGTH 36
652 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
653 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
654 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
655 0, 0, 0, 0, /* CIE ID */
657 'z', 'R', 0, /* Augmentation string */
658 1, /* Code alignment factor */
659 0x78, /* Data alignment factor */
660 16, /* Return address column */
661 1, /* Augmentation size */
662 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
663 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
664 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
665 DW_CFA_nop, DW_CFA_nop,
667 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
668 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
669 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
670 0, 0, 0, 0, /* .plt size goes here */
671 0, /* Augmentation size */
672 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
673 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
674 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
675 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
676 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
677 11, /* Block length */
678 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
679 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
680 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
681 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
682 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
685 /* .eh_frame covering the lazy BND .plt section. */
687 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt[] =
689 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
690 0, 0, 0, 0, /* CIE ID */
692 'z', 'R', 0, /* Augmentation string */
693 1, /* Code alignment factor */
694 0x78, /* Data alignment factor */
695 16, /* Return address column */
696 1, /* Augmentation size */
697 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
698 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
699 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
700 DW_CFA_nop, DW_CFA_nop,
702 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
703 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
704 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
705 0, 0, 0, 0, /* .plt size goes here */
706 0, /* Augmentation size */
707 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
708 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
709 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
710 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
711 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
712 11, /* Block length */
713 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
714 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
715 DW_OP_lit15, DW_OP_and, DW_OP_lit5, DW_OP_ge,
716 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
717 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
720 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
722 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt[] =
724 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
725 0, 0, 0, 0, /* CIE ID */
727 'z', 'R', 0, /* Augmentation string */
728 1, /* Code alignment factor */
729 0x78, /* Data alignment factor */
730 16, /* Return address column */
731 1, /* Augmentation size */
732 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
733 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
734 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
735 DW_CFA_nop, DW_CFA_nop,
737 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
738 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
739 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
740 0, 0, 0, 0, /* .plt size goes here */
741 0, /* Augmentation size */
742 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
743 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
744 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
745 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
746 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
747 11, /* Block length */
748 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
749 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
750 DW_OP_lit15, DW_OP_and, DW_OP_lit10, DW_OP_ge,
751 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
752 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
755 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
757 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt[] =
759 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
760 0, 0, 0, 0, /* CIE ID */
762 'z', 'R', 0, /* Augmentation string */
763 1, /* Code alignment factor */
764 0x78, /* Data alignment factor */
765 16, /* Return address column */
766 1, /* Augmentation size */
767 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
768 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
769 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
770 DW_CFA_nop, DW_CFA_nop,
772 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
773 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
774 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
775 0, 0, 0, 0, /* .plt size goes here */
776 0, /* Augmentation size */
777 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
778 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
779 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
780 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
781 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
782 11, /* Block length */
783 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
784 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
785 DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge,
786 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
787 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
790 /* .eh_frame covering the non-lazy .plt section. */
792 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt[] =
794 #define PLT_GOT_FDE_LENGTH 20
795 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
796 0, 0, 0, 0, /* CIE ID */
798 'z', 'R', 0, /* Augmentation string */
799 1, /* Code alignment factor */
800 0x78, /* Data alignment factor */
801 16, /* Return address column */
802 1, /* Augmentation size */
803 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
804 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
805 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
806 DW_CFA_nop, DW_CFA_nop,
808 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
809 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
810 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
811 0, 0, 0, 0, /* non-lazy .plt size goes here */
812 0, /* Augmentation size */
813 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop,
814 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
817 /* Architecture-specific backend data for x86-64. */
819 struct elf_x86_64_backend_data
829 #define get_elf_x86_64_arch_data(bed) \
830 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
832 #define get_elf_x86_64_backend_data(abfd) \
833 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
835 /* These are the standard parameters. */
836 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt =
838 elf_x86_64_lazy_plt0_entry, /* plt0_entry */
839 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
840 elf_x86_64_lazy_plt_entry, /* plt_entry */
841 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
842 2, /* plt0_got1_offset */
843 8, /* plt0_got2_offset */
844 12, /* plt0_got2_insn_end */
845 2, /* plt_got_offset */
846 7, /* plt_reloc_offset */
847 12, /* plt_plt_offset */
848 6, /* plt_got_insn_size */
849 LAZY_PLT_ENTRY_SIZE, /* plt_plt_insn_end */
850 6, /* plt_lazy_offset */
851 NULL, /* pic_plt0_entry */
852 NULL, /* pic_plt_entry */
853 elf_x86_64_eh_frame_lazy_plt, /* eh_frame_plt */
854 sizeof (elf_x86_64_eh_frame_lazy_plt) /* eh_frame_plt_size */
857 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt =
859 elf_x86_64_non_lazy_plt_entry, /* plt_entry */
860 NULL, /* pic_plt_entry */
861 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
862 2, /* plt_got_offset */
863 6, /* plt_got_insn_size */
864 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
865 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
868 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt =
870 elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */
871 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
872 elf_x86_64_lazy_bnd_plt_entry, /* plt_entry */
873 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
874 2, /* plt0_got1_offset */
875 1+8, /* plt0_got2_offset */
876 1+12, /* plt0_got2_insn_end */
877 1+2, /* plt_got_offset */
878 1, /* plt_reloc_offset */
879 7, /* plt_plt_offset */
880 1+6, /* plt_got_insn_size */
881 11, /* plt_plt_insn_end */
882 0, /* plt_lazy_offset */
883 NULL, /* pic_plt0_entry */
884 NULL, /* pic_plt_entry */
885 elf_x86_64_eh_frame_lazy_bnd_plt, /* eh_frame_plt */
886 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt) /* eh_frame_plt_size */
889 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt =
891 elf_x86_64_non_lazy_bnd_plt_entry, /* plt_entry */
892 NULL, /* pic_plt_entry */
893 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
894 1+2, /* plt_got_offset */
895 1+6, /* plt_got_insn_size */
896 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
897 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
900 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt =
902 elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */
903 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
904 elf_x86_64_lazy_ibt_plt_entry, /* plt_entry */
905 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
906 2, /* plt0_got1_offset */
907 1+8, /* plt0_got2_offset */
908 1+12, /* plt0_got2_insn_end */
909 4+1+2, /* plt_got_offset */
910 4+1, /* plt_reloc_offset */
911 4+1+6, /* plt_plt_offset */
912 4+1+6, /* plt_got_insn_size */
913 4+1+5+5, /* plt_plt_insn_end */
914 0, /* plt_lazy_offset */
915 NULL, /* pic_plt0_entry */
916 NULL, /* pic_plt_entry */
917 elf_x86_64_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
918 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
921 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt =
923 elf_x86_64_lazy_plt0_entry, /* plt0_entry */
924 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
925 elf_x32_lazy_ibt_plt_entry, /* plt_entry */
926 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
927 2, /* plt0_got1_offset */
928 8, /* plt0_got2_offset */
929 12, /* plt0_got2_insn_end */
930 4+2, /* plt_got_offset */
931 4+1, /* plt_reloc_offset */
932 4+6, /* plt_plt_offset */
933 4+6, /* plt_got_insn_size */
934 4+5+5, /* plt_plt_insn_end */
935 0, /* plt_lazy_offset */
936 NULL, /* pic_plt0_entry */
937 NULL, /* pic_plt_entry */
938 elf_x32_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
939 sizeof (elf_x32_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
942 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt =
944 elf_x86_64_non_lazy_ibt_plt_entry, /* plt_entry */
945 NULL, /* pic_plt_entry */
946 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
947 4+1+2, /* plt_got_offset */
948 4+1+6, /* plt_got_insn_size */
949 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
950 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
953 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt =
955 elf_x32_non_lazy_ibt_plt_entry, /* plt_entry */
956 NULL, /* pic_plt_entry */
957 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
958 4+2, /* plt_got_offset */
959 4+6, /* plt_got_insn_size */
960 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
961 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
964 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
969 #define elf_backend_arch_data &elf_x86_64_arch_bed
971 /* Values in tls_type of x86 ELF linker hash entry. */
973 #define GOT_TLS_GDESC 4
974 #define GOT_TLS_GD_BOTH_P(type) \
975 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
976 #define GOT_TLS_GD_P(type) \
977 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
978 #define GOT_TLS_GDESC_P(type) \
979 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
980 #define GOT_TLS_GD_ANY_P(type) \
981 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
983 #define is_x86_64_elf(bfd) \
984 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
985 && elf_tdata (bfd) != NULL \
986 && elf_object_id (bfd) == X86_64_ELF_DATA)
989 elf_x86_64_mkobject (bfd *abfd)
991 return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_obj_tdata),
995 #define elf_x86_64_compute_jump_table_size(htab) \
996 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
999 elf64_x86_64_elf_object_p (bfd *abfd)
1001 /* Set the right machine number for an x86-64 elf64 file. */
1002 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
1007 elf32_x86_64_elf_object_p (bfd *abfd)
1009 /* Set the right machine number for an x86-64 elf32 file. */
1010 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
1014 /* Return TRUE if the TLS access code sequence support transition
1018 elf_x86_64_check_tls_transition (bfd *abfd,
1019 struct bfd_link_info *info,
1022 Elf_Internal_Shdr *symtab_hdr,
1023 struct elf_link_hash_entry **sym_hashes,
1024 unsigned int r_type,
1025 const Elf_Internal_Rela *rel,
1026 const Elf_Internal_Rela *relend)
1029 unsigned long r_symndx;
1030 bfd_boolean largepic = FALSE;
1031 struct elf_link_hash_entry *h;
1033 struct elf_x86_link_hash_table *htab;
1035 bfd_boolean indirect_call;
1037 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1038 offset = rel->r_offset;
1041 case R_X86_64_TLSGD:
1042 case R_X86_64_TLSLD:
1043 if ((rel + 1) >= relend)
1046 if (r_type == R_X86_64_TLSGD)
1048 /* Check transition from GD access model. For 64bit, only
1049 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1050 .word 0x6666; rex64; call __tls_get_addr@PLT
1052 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1054 call *__tls_get_addr@GOTPCREL(%rip)
1055 which may be converted to
1056 addr32 call __tls_get_addr
1057 can transit to different access model. For 32bit, only
1058 leaq foo@tlsgd(%rip), %rdi
1059 .word 0x6666; rex64; call __tls_get_addr@PLT
1061 leaq foo@tlsgd(%rip), %rdi
1063 call *__tls_get_addr@GOTPCREL(%rip)
1064 which may be converted to
1065 addr32 call __tls_get_addr
1066 can transit to different access model. For largepic,
1068 leaq foo@tlsgd(%rip), %rdi
1069 movabsq $__tls_get_addr@pltoff, %rax
1073 leaq foo@tlsgd(%rip), %rdi
1074 movabsq $__tls_get_addr@pltoff, %rax
1078 static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
1080 if ((offset + 12) > sec->size)
1083 call = contents + offset + 4;
1085 || !((call[1] == 0x48
1093 && call[3] == 0xe8)))
1095 if (!ABI_64_P (abfd)
1096 || (offset + 19) > sec->size
1098 || memcmp (call - 7, leaq + 1, 3) != 0
1099 || memcmp (call, "\x48\xb8", 2) != 0
1103 || !((call[10] == 0x48 && call[12] == 0xd8)
1104 || (call[10] == 0x4c && call[12] == 0xf8)))
1108 else if (ABI_64_P (abfd))
1111 || memcmp (contents + offset - 4, leaq, 4) != 0)
1117 || memcmp (contents + offset - 3, leaq + 1, 3) != 0)
1120 indirect_call = call[2] == 0xff;
1124 /* Check transition from LD access model. Only
1125 leaq foo@tlsld(%rip), %rdi;
1126 call __tls_get_addr@PLT
1128 leaq foo@tlsld(%rip), %rdi;
1129 call *__tls_get_addr@GOTPCREL(%rip)
1130 which may be converted to
1131 addr32 call __tls_get_addr
1132 can transit to different access model. For largepic
1134 leaq foo@tlsld(%rip), %rdi
1135 movabsq $__tls_get_addr@pltoff, %rax
1139 leaq foo@tlsld(%rip), %rdi
1140 movabsq $__tls_get_addr@pltoff, %rax
1144 static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
1146 if (offset < 3 || (offset + 9) > sec->size)
1149 if (memcmp (contents + offset - 3, lea, 3) != 0)
1152 call = contents + offset + 4;
1153 if (!(call[0] == 0xe8
1154 || (call[0] == 0xff && call[1] == 0x15)
1155 || (call[0] == 0x67 && call[1] == 0xe8)))
1157 if (!ABI_64_P (abfd)
1158 || (offset + 19) > sec->size
1159 || memcmp (call, "\x48\xb8", 2) != 0
1163 || !((call[10] == 0x48 && call[12] == 0xd8)
1164 || (call[10] == 0x4c && call[12] == 0xf8)))
1168 indirect_call = call[0] == 0xff;
1171 r_symndx = htab->r_sym (rel[1].r_info);
1172 if (r_symndx < symtab_hdr->sh_info)
1175 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1177 || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr)
1180 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLTOFF64;
1181 else if (indirect_call)
1182 return ELF32_R_TYPE (rel[1].r_info) == R_X86_64_GOTPCRELX;
1184 return (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
1185 || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32);
1187 case R_X86_64_GOTTPOFF:
1188 /* Check transition from IE access model:
1189 mov foo@gottpoff(%rip), %reg
1190 add foo@gottpoff(%rip), %reg
1193 /* Check REX prefix first. */
1194 if (offset >= 3 && (offset + 4) <= sec->size)
1196 val = bfd_get_8 (abfd, contents + offset - 3);
1197 if (val != 0x48 && val != 0x4c)
1199 /* X32 may have 0x44 REX prefix or no REX prefix. */
1200 if (ABI_64_P (abfd))
1206 /* X32 may not have any REX prefix. */
1207 if (ABI_64_P (abfd))
1209 if (offset < 2 || (offset + 3) > sec->size)
1213 val = bfd_get_8 (abfd, contents + offset - 2);
1214 if (val != 0x8b && val != 0x03)
1217 val = bfd_get_8 (abfd, contents + offset - 1);
1218 return (val & 0xc7) == 5;
1220 case R_X86_64_GOTPC32_TLSDESC:
1221 /* Check transition from GDesc access model:
1222 leaq x@tlsdesc(%rip), %rax
1224 Make sure it's a leaq adding rip to a 32-bit offset
1225 into any register, although it's probably almost always
1228 if (offset < 3 || (offset + 4) > sec->size)
1231 val = bfd_get_8 (abfd, contents + offset - 3);
1232 if ((val & 0xfb) != 0x48)
1235 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1238 val = bfd_get_8 (abfd, contents + offset - 1);
1239 return (val & 0xc7) == 0x05;
1241 case R_X86_64_TLSDESC_CALL:
1242 /* Check transition from GDesc access model:
1243 call *x@tlsdesc(%rax)
1245 if (offset + 2 <= sec->size)
1247 /* Make sure that it's a call *x@tlsdesc(%rax). */
1248 call = contents + offset;
1249 return call[0] == 0xff && call[1] == 0x10;
1259 /* Return TRUE if the TLS access transition is OK or no transition
1260 will be performed. Update R_TYPE if there is a transition. */
1263 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1264 asection *sec, bfd_byte *contents,
1265 Elf_Internal_Shdr *symtab_hdr,
1266 struct elf_link_hash_entry **sym_hashes,
1267 unsigned int *r_type, int tls_type,
1268 const Elf_Internal_Rela *rel,
1269 const Elf_Internal_Rela *relend,
1270 struct elf_link_hash_entry *h,
1271 unsigned long r_symndx,
1272 bfd_boolean from_relocate_section)
1274 unsigned int from_type = *r_type;
1275 unsigned int to_type = from_type;
1276 bfd_boolean check = TRUE;
1278 /* Skip TLS transition for functions. */
1280 && (h->type == STT_FUNC
1281 || h->type == STT_GNU_IFUNC))
1286 case R_X86_64_TLSGD:
1287 case R_X86_64_GOTPC32_TLSDESC:
1288 case R_X86_64_TLSDESC_CALL:
1289 case R_X86_64_GOTTPOFF:
1290 if (bfd_link_executable (info))
1293 to_type = R_X86_64_TPOFF32;
1295 to_type = R_X86_64_GOTTPOFF;
1298 /* When we are called from elf_x86_64_relocate_section, there may
1299 be additional transitions based on TLS_TYPE. */
1300 if (from_relocate_section)
1302 unsigned int new_to_type = to_type;
1304 if (bfd_link_executable (info)
1307 && tls_type == GOT_TLS_IE)
1308 new_to_type = R_X86_64_TPOFF32;
1310 if (to_type == R_X86_64_TLSGD
1311 || to_type == R_X86_64_GOTPC32_TLSDESC
1312 || to_type == R_X86_64_TLSDESC_CALL)
1314 if (tls_type == GOT_TLS_IE)
1315 new_to_type = R_X86_64_GOTTPOFF;
1318 /* We checked the transition before when we were called from
1319 elf_x86_64_check_relocs. We only want to check the new
1320 transition which hasn't been checked before. */
1321 check = new_to_type != to_type && from_type == to_type;
1322 to_type = new_to_type;
1327 case R_X86_64_TLSLD:
1328 if (bfd_link_executable (info))
1329 to_type = R_X86_64_TPOFF32;
1336 /* Return TRUE if there is no transition. */
1337 if (from_type == to_type)
1340 /* Check if the transition can be performed. */
1342 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1343 symtab_hdr, sym_hashes,
1344 from_type, rel, relend))
1346 reloc_howto_type *from, *to;
1349 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1350 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1353 name = h->root.root.string;
1356 struct elf_x86_link_hash_table *htab;
1358 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1363 Elf_Internal_Sym *isym;
1365 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1367 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1372 /* xgettext:c-format */
1373 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1374 "in section `%A' failed"),
1375 abfd, from->name, to->name, name, rel->r_offset, sec);
1376 bfd_set_error (bfd_error_bad_value);
1384 /* Rename some of the generic section flags to better document how they
1386 #define need_convert_load sec_flg0
1387 #define check_relocs_failed sec_flg1
1390 elf_x86_64_need_pic (struct bfd_link_info *info,
1391 bfd *input_bfd, asection *sec,
1392 struct elf_link_hash_entry *h,
1393 Elf_Internal_Shdr *symtab_hdr,
1394 Elf_Internal_Sym *isym,
1395 reloc_howto_type *howto)
1398 const char *und = "";
1399 const char *pic = "";
1405 name = h->root.root.string;
1406 switch (ELF_ST_VISIBILITY (h->other))
1409 v = _("hidden symbol ");
1412 v = _("internal symbol ");
1415 v = _("protected symbol ");
1418 if (((struct elf_x86_link_hash_entry *) h)->def_protected)
1419 v = _("protected symbol ");
1422 pic = _("; recompile with -fPIC");
1426 if (!h->def_regular && !h->def_dynamic)
1427 und = _("undefined ");
1431 name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
1432 pic = _("; recompile with -fPIC");
1435 if (bfd_link_dll (info))
1436 object = _("a shared object");
1437 else if (bfd_link_pie (info))
1438 object = _("a PIE object");
1440 object = _("a PDE object");
1442 /* xgettext:c-format */
1443 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1444 "not be used when making %s%s"),
1445 input_bfd, howto->name, und, v, name,
1447 bfd_set_error (bfd_error_bad_value);
1448 sec->check_relocs_failed = 1;
1452 /* With the local symbol, foo, we convert
1453 mov foo@GOTPCREL(%rip), %reg
1457 call/jmp *foo@GOTPCREL(%rip)
1459 nop call foo/jmp foo nop
1460 When PIC is false, convert
1461 test %reg, foo@GOTPCREL(%rip)
1465 binop foo@GOTPCREL(%rip), %reg
1468 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1472 elf_x86_64_convert_load_reloc (bfd *abfd, asection *sec,
1474 Elf_Internal_Rela *irel,
1475 struct elf_link_hash_entry *h,
1476 bfd_boolean *converted,
1477 struct bfd_link_info *link_info)
1479 struct elf_x86_link_hash_table *htab;
1481 bfd_boolean require_reloc_pc32;
1483 bfd_boolean to_reloc_pc32;
1486 bfd_signed_vma raddend;
1487 unsigned int opcode;
1489 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
1490 unsigned int r_symndx;
1492 bfd_vma roff = irel->r_offset;
1494 if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2))
1497 raddend = irel->r_addend;
1498 /* Addend for 32-bit PC-relative relocation must be -4. */
1502 htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA);
1503 is_pic = bfd_link_pic (link_info);
1505 relocx = (r_type == R_X86_64_GOTPCRELX
1506 || r_type == R_X86_64_REX_GOTPCRELX);
1508 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1511 = link_info->disable_target_specific_optimizations > 1;
1513 r_symndx = htab->r_sym (irel->r_info);
1515 opcode = bfd_get_8 (abfd, contents + roff - 2);
1517 /* Convert mov to lea since it has been done for a while. */
1520 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1521 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1522 test, xor instructions. */
1527 /* We convert only to R_X86_64_PC32:
1529 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1530 3. require_reloc_pc32 is true.
1533 to_reloc_pc32 = (opcode == 0xff
1535 || require_reloc_pc32
1538 /* Get the symbol referred to by the reloc. */
1541 Elf_Internal_Sym *isym
1542 = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
1544 /* Skip relocation against undefined symbols. */
1545 if (isym->st_shndx == SHN_UNDEF)
1548 symtype = ELF_ST_TYPE (isym->st_info);
1550 if (isym->st_shndx == SHN_ABS)
1551 tsec = bfd_abs_section_ptr;
1552 else if (isym->st_shndx == SHN_COMMON)
1553 tsec = bfd_com_section_ptr;
1554 else if (isym->st_shndx == SHN_X86_64_LCOMMON)
1555 tsec = &_bfd_elf_large_com_section;
1557 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1559 toff = isym->st_value;
1563 /* Undefined weak symbol is only bound locally in executable
1564 and its reference is resolved as 0 without relocation
1565 overflow. We can only perform this optimization for
1566 GOTPCRELX relocations since we need to modify REX byte.
1567 It is OK convert mov with R_X86_64_GOTPCREL to
1569 if ((relocx || opcode == 0x8b)
1570 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info,
1573 elf_x86_hash_entry (h)))
1577 /* Skip for branch instructions since R_X86_64_PC32
1579 if (require_reloc_pc32)
1584 /* For non-branch instructions, we can convert to
1585 R_X86_64_32/R_X86_64_32S since we know if there
1587 to_reloc_pc32 = FALSE;
1590 /* Since we don't know the current PC when PIC is true,
1591 we can't convert to R_X86_64_PC32. */
1592 if (to_reloc_pc32 && is_pic)
1597 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1598 ld.so may use its link-time address. */
1599 else if (h->start_stop
1601 || h->root.type == bfd_link_hash_defined
1602 || h->root.type == bfd_link_hash_defweak)
1603 && h != htab->elf.hdynamic
1604 && SYMBOL_REFERENCES_LOCAL (link_info, h)))
1606 /* bfd_link_hash_new or bfd_link_hash_undefined is
1607 set by an assignment in a linker script in
1608 bfd_elf_record_link_assignment. start_stop is set
1609 on __start_SECNAME/__stop_SECNAME which mark section
1613 && (h->root.type == bfd_link_hash_new
1614 || h->root.type == bfd_link_hash_undefined
1615 || ((h->root.type == bfd_link_hash_defined
1616 || h->root.type == bfd_link_hash_defweak)
1617 && h->root.u.def.section == bfd_und_section_ptr))))
1619 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1620 if (require_reloc_pc32)
1624 tsec = h->root.u.def.section;
1625 toff = h->root.u.def.value;
1632 /* Don't convert GOTPCREL relocation against large section. */
1633 if (elf_section_data (tsec) != NULL
1634 && (elf_section_flags (tsec) & SHF_X86_64_LARGE) != 0)
1637 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1641 if (tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
1643 /* At this stage in linking, no SEC_MERGE symbol has been
1644 adjusted, so all references to such symbols need to be
1645 passed through _bfd_merged_section_offset. (Later, in
1646 relocate_section, all SEC_MERGE symbols *except* for
1647 section symbols have been adjusted.)
1649 gas may reduce relocations against symbols in SEC_MERGE
1650 sections to a relocation against the section symbol when
1651 the original addend was zero. When the reloc is against
1652 a section symbol we should include the addend in the
1653 offset passed to _bfd_merged_section_offset, since the
1654 location of interest is the original symbol. On the
1655 other hand, an access to "sym+addend" where "sym" is not
1656 a section symbol should not include the addend; Such an
1657 access is presumed to be an offset from "sym"; The
1658 location of interest is just "sym". */
1659 if (symtype == STT_SECTION)
1662 toff = _bfd_merged_section_offset (abfd, &tsec,
1663 elf_section_data (tsec)->sec_info,
1666 if (symtype != STT_SECTION)
1672 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1673 if (tsec->output_section == sec->output_section)
1675 if ((toff - roff + 0x80000000) > 0xffffffff)
1680 bfd_signed_vma distance;
1682 /* At this point, we don't know the load addresses of TSEC
1683 section nor SEC section. We estimate the distrance between
1684 SEC and TSEC. We store the estimated distances in the
1685 compressed_size field of the output section, which is only
1686 used to decompress the compressed input section. */
1687 if (sec->output_section->compressed_size == 0)
1690 bfd_size_type size = 0;
1691 for (asect = link_info->output_bfd->sections;
1693 asect = asect->next)
1694 /* Skip debug sections since compressed_size is used to
1695 compress debug sections. */
1696 if ((asect->flags & SEC_DEBUGGING) == 0)
1699 for (i = asect->map_head.s;
1703 size = align_power (size, i->alignment_power);
1706 asect->compressed_size = size;
1710 /* Don't convert GOTPCREL relocations if TSEC isn't placed
1712 distance = (tsec->output_section->compressed_size
1713 - sec->output_section->compressed_size);
1717 /* Take PT_GNU_RELRO segment into account by adding
1719 if ((toff + distance + get_elf_backend_data (abfd)->maxpagesize
1720 - roff + 0x80000000) > 0xffffffff)
1727 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1732 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1734 modrm = bfd_get_8 (abfd, contents + roff - 1);
1737 /* Convert to "jmp foo nop". */
1740 nop_offset = irel->r_offset + 3;
1741 disp = bfd_get_32 (abfd, contents + irel->r_offset);
1742 irel->r_offset -= 1;
1743 bfd_put_32 (abfd, disp, contents + irel->r_offset);
1747 struct elf_x86_link_hash_entry *eh
1748 = (struct elf_x86_link_hash_entry *) h;
1750 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1753 /* To support TLS optimization, always use addr32 prefix for
1754 "call *__tls_get_addr@GOTPCREL(%rip)". */
1755 if (eh && eh->tls_get_addr)
1758 nop_offset = irel->r_offset - 2;
1762 nop = link_info->call_nop_byte;
1763 if (link_info->call_nop_as_suffix)
1765 nop_offset = irel->r_offset + 3;
1766 disp = bfd_get_32 (abfd, contents + irel->r_offset);
1767 irel->r_offset -= 1;
1768 bfd_put_32 (abfd, disp, contents + irel->r_offset);
1771 nop_offset = irel->r_offset - 2;
1774 bfd_put_8 (abfd, nop, contents + nop_offset);
1775 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
1776 r_type = R_X86_64_PC32;
1781 unsigned int rex_mask = REX_R;
1783 if (r_type == R_X86_64_REX_GOTPCRELX)
1784 rex = bfd_get_8 (abfd, contents + roff - 3);
1792 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1793 "lea foo(%rip), %reg". */
1795 r_type = R_X86_64_PC32;
1799 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1800 "mov $foo, %reg". */
1802 modrm = bfd_get_8 (abfd, contents + roff - 1);
1803 modrm = 0xc0 | (modrm & 0x38) >> 3;
1804 if ((rex & REX_W) != 0
1805 && ABI_64_P (link_info->output_bfd))
1807 /* Keep the REX_W bit in REX byte for LP64. */
1808 r_type = R_X86_64_32S;
1809 goto rewrite_modrm_rex;
1813 /* If the REX_W bit in REX byte isn't needed,
1814 use R_X86_64_32 and clear the W bit to avoid
1815 sign-extend imm32 to imm64. */
1816 r_type = R_X86_64_32;
1817 /* Clear the W bit in REX byte. */
1819 goto rewrite_modrm_rex;
1825 /* R_X86_64_PC32 isn't supported. */
1829 modrm = bfd_get_8 (abfd, contents + roff - 1);
1832 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1833 "test $foo, %reg". */
1834 modrm = 0xc0 | (modrm & 0x38) >> 3;
1839 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1840 "binop $foo, %reg". */
1841 modrm = 0xc0 | (modrm & 0x38) >> 3 | (opcode & 0x3c);
1845 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1846 overflow when sign-extending imm32 to imm64. */
1847 r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32;
1850 bfd_put_8 (abfd, modrm, contents + roff - 1);
1854 /* Move the R bit to the B bit in REX byte. */
1855 rex = (rex & ~rex_mask) | (rex & REX_R) >> 2;
1856 bfd_put_8 (abfd, rex, contents + roff - 3);
1859 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1863 bfd_put_8 (abfd, opcode, contents + roff - 2);
1866 irel->r_info = htab->r_info (r_symndx, r_type);
1873 /* Look through the relocs for a section during the first phase, and
1874 calculate needed space in the global offset table, procedure
1875 linkage table, and dynamic reloc sections. */
1878 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1880 const Elf_Internal_Rela *relocs)
1882 struct elf_x86_link_hash_table *htab;
1883 Elf_Internal_Shdr *symtab_hdr;
1884 struct elf_link_hash_entry **sym_hashes;
1885 const Elf_Internal_Rela *rel;
1886 const Elf_Internal_Rela *rel_end;
1890 if (bfd_link_relocatable (info))
1893 /* Don't do anything special with non-loaded, non-alloced sections.
1894 In particular, any relocs in such sections should not affect GOT
1895 and PLT reference counting (ie. we don't allow them to create GOT
1896 or PLT entries), there's no possibility or desire to optimize TLS
1897 relocs, and there's not much point in propagating relocs to shared
1898 libs that the dynamic linker won't relocate. */
1899 if ((sec->flags & SEC_ALLOC) == 0)
1902 BFD_ASSERT (is_x86_64_elf (abfd));
1904 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1907 sec->check_relocs_failed = 1;
1911 /* Get the section contents. */
1912 if (elf_section_data (sec)->this_hdr.contents != NULL)
1913 contents = elf_section_data (sec)->this_hdr.contents;
1914 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1916 sec->check_relocs_failed = 1;
1920 symtab_hdr = &elf_symtab_hdr (abfd);
1921 sym_hashes = elf_sym_hashes (abfd);
1925 rel_end = relocs + sec->reloc_count;
1926 for (rel = relocs; rel < rel_end; rel++)
1928 unsigned int r_type;
1929 unsigned int r_symndx;
1930 struct elf_link_hash_entry *h;
1931 struct elf_x86_link_hash_entry *eh;
1932 Elf_Internal_Sym *isym;
1934 bfd_boolean size_reloc;
1936 r_symndx = htab->r_sym (rel->r_info);
1937 r_type = ELF32_R_TYPE (rel->r_info);
1939 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1941 /* xgettext:c-format */
1942 _bfd_error_handler (_("%B: bad symbol index: %d"),
1947 if (r_symndx < symtab_hdr->sh_info)
1949 /* A local symbol. */
1950 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1955 /* Check relocation against local STT_GNU_IFUNC symbol. */
1956 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1958 h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel,
1963 /* Fake a STT_GNU_IFUNC symbol. */
1964 h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
1966 h->type = STT_GNU_IFUNC;
1969 h->forced_local = 1;
1970 h->root.type = bfd_link_hash_defined;
1978 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1979 while (h->root.type == bfd_link_hash_indirect
1980 || h->root.type == bfd_link_hash_warning)
1981 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1984 /* Check invalid x32 relocations. */
1985 if (!ABI_64_P (abfd))
1991 case R_X86_64_DTPOFF64:
1992 case R_X86_64_TPOFF64:
1994 case R_X86_64_GOTOFF64:
1995 case R_X86_64_GOT64:
1996 case R_X86_64_GOTPCREL64:
1997 case R_X86_64_GOTPC64:
1998 case R_X86_64_GOTPLT64:
1999 case R_X86_64_PLTOFF64:
2002 name = h->root.root.string;
2004 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
2007 /* xgettext:c-format */
2008 (_("%B: relocation %s against symbol `%s' isn't "
2009 "supported in x32 mode"), abfd,
2010 x86_64_elf_howto_table[r_type].name, name);
2011 bfd_set_error (bfd_error_bad_value);
2019 /* It is referenced by a non-shared object. */
2021 h->root.non_ir_ref_regular = 1;
2023 if (h->type == STT_GNU_IFUNC)
2024 elf_tdata (info->output_bfd)->has_gnu_symbols
2025 |= elf_gnu_symbol_ifunc;
2028 if (! elf_x86_64_tls_transition (info, abfd, sec, contents,
2029 symtab_hdr, sym_hashes,
2030 &r_type, GOT_UNKNOWN,
2031 rel, rel_end, h, r_symndx, FALSE))
2034 eh = (struct elf_x86_link_hash_entry *) h;
2037 case R_X86_64_TLSLD:
2038 htab->tls_ld_or_ldm_got.refcount += 1;
2041 case R_X86_64_TPOFF32:
2042 if (!bfd_link_executable (info) && ABI_64_P (abfd))
2043 return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
2044 &x86_64_elf_howto_table[r_type]);
2046 eh->has_got_reloc = 1;
2049 case R_X86_64_GOTTPOFF:
2050 if (!bfd_link_executable (info))
2051 info->flags |= DF_STATIC_TLS;
2054 case R_X86_64_GOT32:
2055 case R_X86_64_GOTPCREL:
2056 case R_X86_64_GOTPCRELX:
2057 case R_X86_64_REX_GOTPCRELX:
2058 case R_X86_64_TLSGD:
2059 case R_X86_64_GOT64:
2060 case R_X86_64_GOTPCREL64:
2061 case R_X86_64_GOTPLT64:
2062 case R_X86_64_GOTPC32_TLSDESC:
2063 case R_X86_64_TLSDESC_CALL:
2064 /* This symbol requires a global offset table entry. */
2066 int tls_type, old_tls_type;
2070 default: tls_type = GOT_NORMAL; break;
2071 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
2072 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
2073 case R_X86_64_GOTPC32_TLSDESC:
2074 case R_X86_64_TLSDESC_CALL:
2075 tls_type = GOT_TLS_GDESC; break;
2080 h->got.refcount += 1;
2081 old_tls_type = eh->tls_type;
2085 bfd_signed_vma *local_got_refcounts;
2087 /* This is a global offset table entry for a local symbol. */
2088 local_got_refcounts = elf_local_got_refcounts (abfd);
2089 if (local_got_refcounts == NULL)
2093 size = symtab_hdr->sh_info;
2094 size *= sizeof (bfd_signed_vma)
2095 + sizeof (bfd_vma) + sizeof (char);
2096 local_got_refcounts = ((bfd_signed_vma *)
2097 bfd_zalloc (abfd, size));
2098 if (local_got_refcounts == NULL)
2100 elf_local_got_refcounts (abfd) = local_got_refcounts;
2101 elf_x86_local_tlsdesc_gotent (abfd)
2102 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
2103 elf_x86_local_got_tls_type (abfd)
2104 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
2106 local_got_refcounts[r_symndx] += 1;
2108 = elf_x86_local_got_tls_type (abfd) [r_symndx];
2111 /* If a TLS symbol is accessed using IE at least once,
2112 there is no point to use dynamic model for it. */
2113 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
2114 && (! GOT_TLS_GD_ANY_P (old_tls_type)
2115 || tls_type != GOT_TLS_IE))
2117 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
2118 tls_type = old_tls_type;
2119 else if (GOT_TLS_GD_ANY_P (old_tls_type)
2120 && GOT_TLS_GD_ANY_P (tls_type))
2121 tls_type |= old_tls_type;
2125 name = h->root.root.string;
2127 name = bfd_elf_sym_name (abfd, symtab_hdr,
2130 /* xgettext:c-format */
2131 (_("%B: '%s' accessed both as normal and"
2132 " thread local symbol"),
2134 bfd_set_error (bfd_error_bad_value);
2139 if (old_tls_type != tls_type)
2142 eh->tls_type = tls_type;
2144 elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type;
2149 case R_X86_64_GOTOFF64:
2150 case R_X86_64_GOTPC32:
2151 case R_X86_64_GOTPC64:
2154 eh->has_got_reloc = 1;
2157 case R_X86_64_PLT32:
2158 case R_X86_64_PLT32_BND:
2159 /* This symbol requires a procedure linkage table entry. We
2160 actually build the entry in adjust_dynamic_symbol,
2161 because this might be a case of linking PIC code which is
2162 never referenced by a dynamic object, in which case we
2163 don't need to generate a procedure linkage table entry
2166 /* If this is a local symbol, we resolve it directly without
2167 creating a procedure linkage table entry. */
2171 eh->has_got_reloc = 1;
2173 h->plt.refcount += 1;
2176 case R_X86_64_PLTOFF64:
2177 /* This tries to form the 'address' of a function relative
2178 to GOT. For global symbols we need a PLT entry. */
2182 h->plt.refcount += 1;
2186 case R_X86_64_SIZE32:
2187 case R_X86_64_SIZE64:
2192 if (!ABI_64_P (abfd))
2198 /* Check relocation overflow as these relocs may lead to
2199 run-time relocation overflow. Don't error out for
2200 sections we don't care about, such as debug sections or
2201 when relocation overflow check is disabled. */
2202 if (!info->no_reloc_overflow_check
2203 && (bfd_link_pic (info)
2204 || (bfd_link_executable (info)
2208 && (sec->flags & SEC_READONLY) == 0)))
2209 return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
2210 &x86_64_elf_howto_table[r_type]);
2216 case R_X86_64_PC32_BND:
2220 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
2221 eh->has_non_got_reloc = 1;
2222 /* We are called after all symbols have been resolved. Only
2223 relocation against STT_GNU_IFUNC symbol must go through
2226 && (bfd_link_executable (info)
2227 || h->type == STT_GNU_IFUNC))
2229 /* If this reloc is in a read-only section, we might
2230 need a copy reloc. We can't check reliably at this
2231 stage whether the section is read-only, as input
2232 sections have not yet been mapped to output sections.
2233 Tentatively set the flag for now, and correct in
2234 adjust_dynamic_symbol. */
2237 /* We may need a .plt entry if the symbol is a function
2238 defined in a shared lib or is a STT_GNU_IFUNC function
2239 referenced from the code or read-only section. */
2241 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
2242 h->plt.refcount += 1;
2244 if (r_type == R_X86_64_PC32)
2246 /* Since something like ".long foo - ." may be used
2247 as pointer, make sure that PLT is used if foo is
2248 a function defined in a shared library. */
2249 if ((sec->flags & SEC_CODE) == 0)
2250 h->pointer_equality_needed = 1;
2252 else if (r_type != R_X86_64_PC32_BND
2253 && r_type != R_X86_64_PC64)
2255 h->pointer_equality_needed = 1;
2256 /* At run-time, R_X86_64_64 can be resolved for both
2257 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2258 can only be resolved for x32. */
2259 if ((sec->flags & SEC_READONLY) == 0
2260 && (r_type == R_X86_64_64
2261 || (!ABI_64_P (abfd)
2262 && (r_type == R_X86_64_32
2263 || r_type == R_X86_64_32S))))
2264 eh->func_pointer_refcount += 1;
2270 /* If we are creating a shared library, and this is a reloc
2271 against a global symbol, or a non PC relative reloc
2272 against a local symbol, then we need to copy the reloc
2273 into the shared library. However, if we are linking with
2274 -Bsymbolic, we do not need to copy a reloc against a
2275 global symbol which is defined in an object we are
2276 including in the link (i.e., DEF_REGULAR is set). At
2277 this point we have not seen all the input files, so it is
2278 possible that DEF_REGULAR is not set now but will be set
2279 later (it is never cleared). In case of a weak definition,
2280 DEF_REGULAR may be cleared later by a strong definition in
2281 a shared library. We account for that possibility below by
2282 storing information in the relocs_copied field of the hash
2283 table entry. A similar situation occurs when creating
2284 shared libraries and symbol visibility changes render the
2287 If on the other hand, we are creating an executable, we
2288 may need to keep relocations for symbols satisfied by a
2289 dynamic library if we manage to avoid copy relocs for the
2292 Generate dynamic pointer relocation against STT_GNU_IFUNC
2293 symbol in the non-code section. */
2294 if ((bfd_link_pic (info)
2295 && (! IS_X86_64_PCREL_TYPE (r_type)
2297 && (! (bfd_link_pie (info)
2298 || SYMBOLIC_BIND (info, h))
2299 || h->root.type == bfd_link_hash_defweak
2300 || !h->def_regular))))
2302 && h->type == STT_GNU_IFUNC
2303 && r_type == htab->pointer_r_type
2304 && (sec->flags & SEC_CODE) == 0)
2305 || (ELIMINATE_COPY_RELOCS
2306 && !bfd_link_pic (info)
2308 && (h->root.type == bfd_link_hash_defweak
2309 || !h->def_regular)))
2311 struct elf_dyn_relocs *p;
2312 struct elf_dyn_relocs **head;
2314 /* We must copy these reloc types into the output file.
2315 Create a reloc section in dynobj and make room for
2319 sreloc = _bfd_elf_make_dynamic_reloc_section
2320 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
2321 abfd, /*rela?*/ TRUE);
2327 /* If this is a global symbol, we count the number of
2328 relocations we need for this symbol. */
2330 head = &eh->dyn_relocs;
2333 /* Track dynamic relocs needed for local syms too.
2334 We really need local syms available to do this
2339 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2344 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2348 /* Beware of type punned pointers vs strict aliasing
2350 vpp = &(elf_section_data (s)->local_dynrel);
2351 head = (struct elf_dyn_relocs **)vpp;
2355 if (p == NULL || p->sec != sec)
2357 bfd_size_type amt = sizeof *p;
2359 p = ((struct elf_dyn_relocs *)
2360 bfd_alloc (htab->elf.dynobj, amt));
2371 /* Count size relocation as PC-relative relocation. */
2372 if (IS_X86_64_PCREL_TYPE (r_type) || size_reloc)
2377 /* This relocation describes the C++ object vtable hierarchy.
2378 Reconstruct it for later use during GC. */
2379 case R_X86_64_GNU_VTINHERIT:
2380 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2384 /* This relocation describes which C++ vtable entries are actually
2385 used. Record for later use during GC. */
2386 case R_X86_64_GNU_VTENTRY:
2387 BFD_ASSERT (h != NULL);
2389 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2397 if ((r_type == R_X86_64_GOTPCREL
2398 || r_type == R_X86_64_GOTPCRELX
2399 || r_type == R_X86_64_REX_GOTPCRELX)
2400 && (h == NULL || h->type != STT_GNU_IFUNC))
2401 sec->need_convert_load = 1;
2404 if (elf_section_data (sec)->this_hdr.contents != contents)
2406 if (!info->keep_memory)
2410 /* Cache the section contents for elf_link_input_bfd. */
2411 elf_section_data (sec)->this_hdr.contents = contents;
2418 if (elf_section_data (sec)->this_hdr.contents != contents)
2420 sec->check_relocs_failed = 1;
2424 /* Return the section that should be marked against GC for a given
2428 elf_x86_64_gc_mark_hook (asection *sec,
2429 struct bfd_link_info *info,
2430 Elf_Internal_Rela *rel,
2431 struct elf_link_hash_entry *h,
2432 Elf_Internal_Sym *sym)
2435 switch (ELF32_R_TYPE (rel->r_info))
2437 case R_X86_64_GNU_VTINHERIT:
2438 case R_X86_64_GNU_VTENTRY:
2442 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2445 /* Adjust a symbol defined by a dynamic object and referenced by a
2446 regular object. The current definition is in some section of the
2447 dynamic object, but we're not including those sections. We have to
2448 change the definition to something the rest of the link can
2452 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
2453 struct elf_link_hash_entry *h)
2455 struct elf_x86_link_hash_table *htab;
2457 struct elf_x86_link_hash_entry *eh;
2458 struct elf_dyn_relocs *p;
2460 /* STT_GNU_IFUNC symbol must go through PLT. */
2461 if (h->type == STT_GNU_IFUNC)
2463 /* All local STT_GNU_IFUNC references must be treate as local
2464 calls via local PLT. */
2466 && SYMBOL_CALLS_LOCAL (info, h))
2468 bfd_size_type pc_count = 0, count = 0;
2469 struct elf_dyn_relocs **pp;
2471 eh = (struct elf_x86_link_hash_entry *) h;
2472 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2474 pc_count += p->pc_count;
2475 p->count -= p->pc_count;
2484 if (pc_count || count)
2489 /* Increment PLT reference count only for PC-relative
2492 if (h->plt.refcount <= 0)
2493 h->plt.refcount = 1;
2495 h->plt.refcount += 1;
2500 if (h->plt.refcount <= 0)
2502 h->plt.offset = (bfd_vma) -1;
2508 /* If this is a function, put it in the procedure linkage table. We
2509 will fill in the contents of the procedure linkage table later,
2510 when we know the address of the .got section. */
2511 if (h->type == STT_FUNC
2514 if (h->plt.refcount <= 0
2515 || SYMBOL_CALLS_LOCAL (info, h)
2516 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2517 && h->root.type == bfd_link_hash_undefweak))
2519 /* This case can occur if we saw a PLT32 reloc in an input
2520 file, but the symbol was never referred to by a dynamic
2521 object, or if all references were garbage collected. In
2522 such a case, we don't actually need to build a procedure
2523 linkage table, and we can just do a PC32 reloc instead. */
2524 h->plt.offset = (bfd_vma) -1;
2531 /* It's possible that we incorrectly decided a .plt reloc was
2532 needed for an R_X86_64_PC32 reloc to a non-function sym in
2533 check_relocs. We can't decide accurately between function and
2534 non-function syms in check-relocs; Objects loaded later in
2535 the link may change h->type. So fix it now. */
2536 h->plt.offset = (bfd_vma) -1;
2538 eh = (struct elf_x86_link_hash_entry *) h;
2540 /* If this is a weak symbol, and there is a real definition, the
2541 processor independent code will have arranged for us to see the
2542 real definition first, and we can just use the same value. */
2543 if (h->u.weakdef != NULL)
2545 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2546 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2547 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2548 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2549 if (ELIMINATE_COPY_RELOCS
2550 || info->nocopyreloc
2551 || SYMBOL_NO_COPYRELOC (info, eh))
2553 h->non_got_ref = h->u.weakdef->non_got_ref;
2554 eh->needs_copy = h->u.weakdef->needs_copy;
2559 /* This is a reference to a symbol defined by a dynamic object which
2560 is not a function. */
2562 /* If we are creating a shared library, we must presume that the
2563 only references to the symbol are via the global offset table.
2564 For such cases we need not do anything here; the relocations will
2565 be handled correctly by relocate_section. */
2566 if (!bfd_link_executable (info))
2569 /* If there are no references to this symbol that do not use the
2570 GOT, we don't need to generate a copy reloc. */
2571 if (!h->non_got_ref)
2574 /* If -z nocopyreloc was given, we won't generate them either. */
2575 if (info->nocopyreloc || SYMBOL_NO_COPYRELOC (info, eh))
2581 if (ELIMINATE_COPY_RELOCS)
2583 eh = (struct elf_x86_link_hash_entry *) h;
2584 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2586 s = p->sec->output_section;
2587 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2591 /* If we didn't find any dynamic relocs in read-only sections, then
2592 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2600 /* We must allocate the symbol in our .dynbss section, which will
2601 become part of the .bss section of the executable. There will be
2602 an entry for this symbol in the .dynsym section. The dynamic
2603 object will contain position independent code, so all references
2604 from the dynamic object to this symbol will go through the global
2605 offset table. The dynamic linker will use the .dynsym entry to
2606 determine the address it must put in the global offset table, so
2607 both the dynamic object and the regular object will refer to the
2608 same memory location for the variable. */
2610 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
2614 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2615 to copy the initial value out of the dynamic object and into the
2616 runtime process image. */
2617 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2619 s = htab->elf.sdynrelro;
2620 srel = htab->elf.sreldynrelro;
2624 s = htab->elf.sdynbss;
2625 srel = htab->elf.srelbss;
2627 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2629 const struct elf_backend_data *bed;
2630 bed = get_elf_backend_data (info->output_bfd);
2631 srel->size += bed->s->sizeof_rela;
2635 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2638 /* Allocate space in .plt, .got and associated reloc sections for
2642 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2644 struct bfd_link_info *info;
2645 struct elf_x86_link_hash_table *htab;
2646 struct elf_x86_link_hash_entry *eh;
2647 struct elf_dyn_relocs *p;
2648 const struct elf_backend_data *bed;
2649 unsigned int plt_entry_size;
2650 bfd_boolean resolved_to_zero;
2652 if (h->root.type == bfd_link_hash_indirect)
2655 eh = (struct elf_x86_link_hash_entry *) h;
2657 info = (struct bfd_link_info *) inf;
2658 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
2661 bed = get_elf_backend_data (info->output_bfd);
2663 plt_entry_size = htab->plt.plt_entry_size;
2665 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2670 /* We can't use the GOT PLT if pointer equality is needed since
2671 finish_dynamic_symbol won't clear symbol value and the dynamic
2672 linker won't update the GOT slot. We will get into an infinite
2673 loop at run-time. */
2674 if (htab->plt_got != NULL
2675 && h->type != STT_GNU_IFUNC
2676 && !h->pointer_equality_needed
2677 && h->plt.refcount > 0
2678 && h->got.refcount > 0)
2680 /* Don't use the regular PLT if there are both GOT and GOTPLT
2682 h->plt.offset = (bfd_vma) -1;
2684 /* Use the GOT PLT. */
2685 eh->plt_got.refcount = 1;
2688 /* Clear the reference count of function pointer relocations if
2689 symbol isn't a normal function. */
2690 if (h->type != STT_FUNC)
2691 eh->func_pointer_refcount = 0;
2693 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2694 here if it is defined and referenced in a non-shared object. */
2695 if (h->type == STT_GNU_IFUNC
2698 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h,
2700 &htab->readonly_dynrelocs_against_ifunc,
2704 GOT_ENTRY_SIZE, TRUE))
2706 asection *s = htab->plt_second;
2707 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
2709 /* Use the second PLT section if it is created. */
2710 eh->plt_second.offset = s->size;
2712 /* Make room for this entry in the second PLT section. */
2713 s->size += htab->non_lazy_plt->plt_entry_size;
2721 /* Don't create the PLT entry if there are only function pointer
2722 relocations which can be resolved at run-time. */
2723 else if (htab->elf.dynamic_sections_created
2724 && (h->plt.refcount > eh->func_pointer_refcount
2725 || eh->plt_got.refcount > 0))
2727 bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
2729 /* Clear the reference count of function pointer relocations
2731 eh->func_pointer_refcount = 0;
2733 /* Make sure this symbol is output as a dynamic symbol.
2734 Undefined weak syms won't yet be marked as dynamic. */
2735 if (h->dynindx == -1
2737 && !resolved_to_zero
2738 && h->root.type == bfd_link_hash_undefweak)
2740 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2744 if (bfd_link_pic (info)
2745 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2747 asection *s = htab->elf.splt;
2748 asection *second_s = htab->plt_second;
2749 asection *got_s = htab->plt_got;
2751 /* If this is the first .plt entry, make room for the special
2752 first entry. The .plt section is used by prelink to undo
2753 prelinking for dynamic relocations. */
2755 s->size = htab->plt.has_plt0 * plt_entry_size;
2758 eh->plt_got.offset = got_s->size;
2761 h->plt.offset = s->size;
2763 eh->plt_second.offset = second_s->size;
2766 /* If this symbol is not defined in a regular file, and we are
2767 not generating a shared library, then set the symbol to this
2768 location in the .plt. This is required to make function
2769 pointers compare as equal between the normal executable and
2770 the shared library. */
2771 if (! bfd_link_pic (info)
2776 /* We need to make a call to the entry of the GOT PLT
2777 instead of regular PLT entry. */
2778 h->root.u.def.section = got_s;
2779 h->root.u.def.value = eh->plt_got.offset;
2785 /* We need to make a call to the entry of the
2786 second PLT instead of regular PLT entry. */
2787 h->root.u.def.section = second_s;
2788 h->root.u.def.value = eh->plt_second.offset;
2792 h->root.u.def.section = s;
2793 h->root.u.def.value = h->plt.offset;
2798 /* Make room for this entry. */
2800 got_s->size += htab->non_lazy_plt->plt_entry_size;
2803 s->size += plt_entry_size;
2805 second_s->size += htab->non_lazy_plt->plt_entry_size;
2807 /* We also need to make an entry in the .got.plt section,
2808 which will be placed in the .got section by the linker
2810 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
2812 /* There should be no PLT relocation against resolved
2813 undefined weak symbol in executable. */
2814 if (!resolved_to_zero)
2816 /* We also need to make an entry in the .rela.plt
2818 htab->elf.srelplt->size += bed->s->sizeof_rela;
2819 htab->elf.srelplt->reloc_count++;
2825 eh->plt_got.offset = (bfd_vma) -1;
2826 h->plt.offset = (bfd_vma) -1;
2832 eh->plt_got.offset = (bfd_vma) -1;
2833 h->plt.offset = (bfd_vma) -1;
2837 eh->tlsdesc_got = (bfd_vma) -1;
2839 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2840 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2841 if (h->got.refcount > 0
2842 && bfd_link_executable (info)
2844 && elf_x86_hash_entry (h)->tls_type == GOT_TLS_IE)
2846 h->got.offset = (bfd_vma) -1;
2848 else if (h->got.refcount > 0)
2852 int tls_type = elf_x86_hash_entry (h)->tls_type;
2854 /* Make sure this symbol is output as a dynamic symbol.
2855 Undefined weak syms won't yet be marked as dynamic. */
2856 if (h->dynindx == -1
2858 && !resolved_to_zero
2859 && h->root.type == bfd_link_hash_undefweak)
2861 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2865 if (GOT_TLS_GDESC_P (tls_type))
2867 eh->tlsdesc_got = htab->elf.sgotplt->size
2868 - elf_x86_64_compute_jump_table_size (htab);
2869 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2870 h->got.offset = (bfd_vma) -2;
2872 if (! GOT_TLS_GDESC_P (tls_type)
2873 || GOT_TLS_GD_P (tls_type))
2876 h->got.offset = s->size;
2877 s->size += GOT_ENTRY_SIZE;
2878 if (GOT_TLS_GD_P (tls_type))
2879 s->size += GOT_ENTRY_SIZE;
2881 dyn = htab->elf.dynamic_sections_created;
2882 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2883 and two if global. R_X86_64_GOTTPOFF needs one dynamic
2884 relocation. No dynamic relocation against resolved undefined
2885 weak symbol in executable. */
2886 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2887 || tls_type == GOT_TLS_IE)
2888 htab->elf.srelgot->size += bed->s->sizeof_rela;
2889 else if (GOT_TLS_GD_P (tls_type))
2890 htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
2891 else if (! GOT_TLS_GDESC_P (tls_type)
2892 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2893 && !resolved_to_zero)
2894 || h->root.type != bfd_link_hash_undefweak)
2895 && (bfd_link_pic (info)
2896 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2897 htab->elf.srelgot->size += bed->s->sizeof_rela;
2898 if (GOT_TLS_GDESC_P (tls_type))
2900 htab->elf.srelplt->size += bed->s->sizeof_rela;
2901 htab->tlsdesc_plt = (bfd_vma) -1;
2905 h->got.offset = (bfd_vma) -1;
2907 if (eh->dyn_relocs == NULL)
2910 /* In the shared -Bsymbolic case, discard space allocated for
2911 dynamic pc-relative relocs against symbols which turn out to be
2912 defined in regular objects. For the normal shared case, discard
2913 space for pc-relative relocs that have become local due to symbol
2914 visibility changes. */
2916 if (bfd_link_pic (info))
2918 /* Relocs that use pc_count are those that appear on a call
2919 insn, or certain REL relocs that can generated via assembly.
2920 We want calls to protected symbols to resolve directly to the
2921 function rather than going via the plt. If people want
2922 function pointer comparisons to work as expected then they
2923 should avoid writing weird assembly. */
2924 if (SYMBOL_CALLS_LOCAL (info, h))
2926 struct elf_dyn_relocs **pp;
2928 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2930 p->count -= p->pc_count;
2939 /* Also discard relocs on undefined weak syms with non-default
2940 visibility or in PIE. */
2941 if (eh->dyn_relocs != NULL)
2943 if (h->root.type == bfd_link_hash_undefweak)
2945 /* Undefined weak symbol is never bound locally in shared
2947 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2948 || resolved_to_zero)
2949 eh->dyn_relocs = NULL;
2950 else if (h->dynindx == -1
2951 && ! h->forced_local
2952 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2955 /* For PIE, discard space for pc-relative relocs against
2956 symbols which turn out to need copy relocs. */
2957 else if (bfd_link_executable (info)
2958 && (h->needs_copy || eh->needs_copy)
2962 struct elf_dyn_relocs **pp;
2964 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2966 if (p->pc_count != 0)
2974 else if (ELIMINATE_COPY_RELOCS)
2976 /* For the non-shared case, discard space for relocs against
2977 symbols which turn out to need copy relocs or are not
2978 dynamic. Keep dynamic relocations for run-time function
2979 pointer initialization. */
2981 if ((!h->non_got_ref
2982 || eh->func_pointer_refcount > 0
2983 || (h->root.type == bfd_link_hash_undefweak
2984 && !resolved_to_zero))
2987 || (htab->elf.dynamic_sections_created
2988 && (h->root.type == bfd_link_hash_undefweak
2989 || h->root.type == bfd_link_hash_undefined))))
2991 /* Make sure this symbol is output as a dynamic symbol.
2992 Undefined weak syms won't yet be marked as dynamic. */
2993 if (h->dynindx == -1
2994 && ! h->forced_local
2995 && ! resolved_to_zero
2996 && h->root.type == bfd_link_hash_undefweak
2997 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3000 /* If that succeeded, we know we'll be keeping all the
3002 if (h->dynindx != -1)
3006 eh->dyn_relocs = NULL;
3007 eh->func_pointer_refcount = 0;
3012 /* Finally, allocate space. */
3013 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3017 sreloc = elf_section_data (p->sec)->sreloc;
3019 BFD_ASSERT (sreloc != NULL);
3021 sreloc->size += p->count * bed->s->sizeof_rela;
3027 /* Allocate space in .plt, .got and associated reloc sections for
3028 local dynamic relocs. */
3031 elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
3033 struct elf_link_hash_entry *h
3034 = (struct elf_link_hash_entry *) *slot;
3036 if (h->type != STT_GNU_IFUNC
3040 || h->root.type != bfd_link_hash_defined)
3043 return elf_x86_64_allocate_dynrelocs (h, inf);
3046 /* Convert load via the GOT slot to load immediate. */
3049 elf_x86_64_convert_load (bfd *abfd, asection *sec,
3050 struct bfd_link_info *link_info)
3052 Elf_Internal_Shdr *symtab_hdr;
3053 Elf_Internal_Rela *internal_relocs;
3054 Elf_Internal_Rela *irel, *irelend;
3056 struct elf_x86_link_hash_table *htab;
3057 bfd_boolean changed;
3058 bfd_signed_vma *local_got_refcounts;
3060 /* Don't even try to convert non-ELF outputs. */
3061 if (!is_elf_hash_table (link_info->hash))
3064 /* Nothing to do if there is no need or no output. */
3065 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
3066 || sec->need_convert_load == 0
3067 || bfd_is_abs_section (sec->output_section))
3070 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3072 /* Load the relocations for this section. */
3073 internal_relocs = (_bfd_elf_link_read_relocs
3074 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
3075 link_info->keep_memory));
3076 if (internal_relocs == NULL)
3080 htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA);
3081 local_got_refcounts = elf_local_got_refcounts (abfd);
3083 /* Get the section contents. */
3084 if (elf_section_data (sec)->this_hdr.contents != NULL)
3085 contents = elf_section_data (sec)->this_hdr.contents;
3088 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
3092 irelend = internal_relocs + sec->reloc_count;
3093 for (irel = internal_relocs; irel < irelend; irel++)
3095 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
3096 unsigned int r_symndx;
3097 struct elf_link_hash_entry *h;
3098 bfd_boolean converted;
3100 if (r_type != R_X86_64_GOTPCRELX
3101 && r_type != R_X86_64_REX_GOTPCRELX
3102 && r_type != R_X86_64_GOTPCREL)
3105 r_symndx = htab->r_sym (irel->r_info);
3106 if (r_symndx < symtab_hdr->sh_info)
3107 h = _bfd_elf_x86_get_local_sym_hash (htab, sec->owner,
3108 (const Elf_Internal_Rela *) irel,
3112 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
3113 while (h->root.type == bfd_link_hash_indirect
3114 || h->root.type == bfd_link_hash_warning)
3115 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3118 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3119 if (h != NULL && h->type == STT_GNU_IFUNC)
3123 if (!elf_x86_64_convert_load_reloc (abfd, sec, contents, irel, h,
3124 &converted, link_info))
3129 changed = converted;
3132 if (h->got.refcount > 0)
3133 h->got.refcount -= 1;
3137 if (local_got_refcounts != NULL
3138 && local_got_refcounts[r_symndx] > 0)
3139 local_got_refcounts[r_symndx] -= 1;
3144 if (contents != NULL
3145 && elf_section_data (sec)->this_hdr.contents != contents)
3147 if (!changed && !link_info->keep_memory)
3151 /* Cache the section contents for elf_link_input_bfd. */
3152 elf_section_data (sec)->this_hdr.contents = contents;
3156 if (elf_section_data (sec)->relocs != internal_relocs)
3159 free (internal_relocs);
3161 elf_section_data (sec)->relocs = internal_relocs;
3167 if (contents != NULL
3168 && elf_section_data (sec)->this_hdr.contents != contents)
3170 if (internal_relocs != NULL
3171 && elf_section_data (sec)->relocs != internal_relocs)
3172 free (internal_relocs);
3176 /* Set the sizes of the dynamic sections. */
3179 elf_x86_64_size_dynamic_sections (bfd *output_bfd,
3180 struct bfd_link_info *info)
3182 struct elf_x86_link_hash_table *htab;
3187 const struct elf_backend_data *bed;
3189 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
3192 bed = get_elf_backend_data (output_bfd);
3194 dynobj = htab->elf.dynobj;
3198 /* Set up .got offsets for local syms, and space for local dynamic
3200 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3202 bfd_signed_vma *local_got;
3203 bfd_signed_vma *end_local_got;
3204 char *local_tls_type;
3205 bfd_vma *local_tlsdesc_gotent;
3206 bfd_size_type locsymcount;
3207 Elf_Internal_Shdr *symtab_hdr;
3210 if (! is_x86_64_elf (ibfd))
3213 for (s = ibfd->sections; s != NULL; s = s->next)
3215 struct elf_dyn_relocs *p;
3217 if (!elf_x86_64_convert_load (ibfd, s, info))
3220 for (p = (struct elf_dyn_relocs *)
3221 (elf_section_data (s)->local_dynrel);
3225 if (!bfd_is_abs_section (p->sec)
3226 && bfd_is_abs_section (p->sec->output_section))
3228 /* Input section has been discarded, either because
3229 it is a copy of a linkonce section or due to
3230 linker script /DISCARD/, so we'll be discarding
3233 else if (p->count != 0)
3235 srel = elf_section_data (p->sec)->sreloc;
3236 srel->size += p->count * bed->s->sizeof_rela;
3237 if ((p->sec->output_section->flags & SEC_READONLY) != 0
3238 && (info->flags & DF_TEXTREL) == 0)
3240 info->flags |= DF_TEXTREL;
3241 if ((info->warn_shared_textrel && bfd_link_pic (info))
3242 || info->error_textrel)
3243 /* xgettext:c-format */
3244 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3245 p->sec->owner, p->sec);
3251 local_got = elf_local_got_refcounts (ibfd);
3255 symtab_hdr = &elf_symtab_hdr (ibfd);
3256 locsymcount = symtab_hdr->sh_info;
3257 end_local_got = local_got + locsymcount;
3258 local_tls_type = elf_x86_local_got_tls_type (ibfd);
3259 local_tlsdesc_gotent = elf_x86_local_tlsdesc_gotent (ibfd);
3261 srel = htab->elf.srelgot;
3262 for (; local_got < end_local_got;
3263 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
3265 *local_tlsdesc_gotent = (bfd_vma) -1;
3268 if (GOT_TLS_GDESC_P (*local_tls_type))
3270 *local_tlsdesc_gotent = htab->elf.sgotplt->size
3271 - elf_x86_64_compute_jump_table_size (htab);
3272 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
3273 *local_got = (bfd_vma) -2;
3275 if (! GOT_TLS_GDESC_P (*local_tls_type)
3276 || GOT_TLS_GD_P (*local_tls_type))
3278 *local_got = s->size;
3279 s->size += GOT_ENTRY_SIZE;
3280 if (GOT_TLS_GD_P (*local_tls_type))
3281 s->size += GOT_ENTRY_SIZE;
3283 if (bfd_link_pic (info)
3284 || GOT_TLS_GD_ANY_P (*local_tls_type)
3285 || *local_tls_type == GOT_TLS_IE)
3287 if (GOT_TLS_GDESC_P (*local_tls_type))
3289 htab->elf.srelplt->size
3290 += bed->s->sizeof_rela;
3291 htab->tlsdesc_plt = (bfd_vma) -1;
3293 if (! GOT_TLS_GDESC_P (*local_tls_type)
3294 || GOT_TLS_GD_P (*local_tls_type))
3295 srel->size += bed->s->sizeof_rela;
3299 *local_got = (bfd_vma) -1;
3303 if (htab->tls_ld_or_ldm_got.refcount > 0)
3305 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3307 htab->tls_ld_or_ldm_got.offset = htab->elf.sgot->size;
3308 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
3309 htab->elf.srelgot->size += bed->s->sizeof_rela;
3312 htab->tls_ld_or_ldm_got.offset = -1;
3314 /* Allocate global sym .plt and .got entries, and space for global
3315 sym dynamic relocs. */
3316 elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
3319 /* Allocate .plt and .got entries, and space for local symbols. */
3320 htab_traverse (htab->loc_hash_table,
3321 elf_x86_64_allocate_local_dynrelocs,
3324 /* For every jump slot reserved in the sgotplt, reloc_count is
3325 incremented. However, when we reserve space for TLS descriptors,
3326 it's not incremented, so in order to compute the space reserved
3327 for them, it suffices to multiply the reloc count by the jump
3330 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3331 so that R_X86_64_IRELATIVE entries come last. */
3332 if (htab->elf.srelplt)
3334 htab->sgotplt_jump_table_size
3335 = elf_x86_64_compute_jump_table_size (htab);
3336 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
3338 else if (htab->elf.irelplt)
3339 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
3341 if (htab->tlsdesc_plt)
3343 /* If we're not using lazy TLS relocations, don't generate the
3344 PLT and GOT entries they require. */
3345 if ((info->flags & DF_BIND_NOW))
3346 htab->tlsdesc_plt = 0;
3349 htab->tlsdesc_got = htab->elf.sgot->size;
3350 htab->elf.sgot->size += GOT_ENTRY_SIZE;
3351 /* Reserve room for the initial entry.
3352 FIXME: we could probably do away with it in this case. */
3353 if (htab->elf.splt->size == 0)
3354 htab->elf.splt->size = htab->plt.plt_entry_size;
3355 htab->tlsdesc_plt = htab->elf.splt->size;
3356 htab->elf.splt->size += htab->plt.plt_entry_size;
3360 if (htab->elf.sgotplt)
3362 /* Don't allocate .got.plt section if there are no GOT nor PLT
3363 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3364 if ((htab->elf.hgot == NULL
3365 || !htab->elf.hgot->ref_regular_nonweak)
3366 && (htab->elf.sgotplt->size
3367 == get_elf_backend_data (output_bfd)->got_header_size)
3368 && (htab->elf.splt == NULL
3369 || htab->elf.splt->size == 0)
3370 && (htab->elf.sgot == NULL
3371 || htab->elf.sgot->size == 0)
3372 && (htab->elf.iplt == NULL
3373 || htab->elf.iplt->size == 0)
3374 && (htab->elf.igotplt == NULL
3375 || htab->elf.igotplt->size == 0))
3376 htab->elf.sgotplt->size = 0;
3379 if (_bfd_elf_eh_frame_present (info))
3381 if (htab->plt_eh_frame != NULL
3382 && htab->elf.splt != NULL
3383 && htab->elf.splt->size != 0
3384 && !bfd_is_abs_section (htab->elf.splt->output_section))
3385 htab->plt_eh_frame->size = htab->plt.eh_frame_plt_size;
3387 if (htab->plt_got_eh_frame != NULL
3388 && htab->plt_got != NULL
3389 && htab->plt_got->size != 0
3390 && !bfd_is_abs_section (htab->plt_got->output_section))
3391 htab->plt_got_eh_frame->size
3392 = htab->non_lazy_plt->eh_frame_plt_size;
3394 /* Unwind info for the second PLT and .plt.got sections are
3396 if (htab->plt_second_eh_frame != NULL
3397 && htab->plt_second != NULL
3398 && htab->plt_second->size != 0
3399 && !bfd_is_abs_section (htab->plt_second->output_section))
3400 htab->plt_second_eh_frame->size
3401 = htab->non_lazy_plt->eh_frame_plt_size;
3404 /* We now have determined the sizes of the various dynamic sections.
3405 Allocate memory for them. */
3407 for (s = dynobj->sections; s != NULL; s = s->next)
3409 if ((s->flags & SEC_LINKER_CREATED) == 0)
3412 if (s == htab->elf.splt
3413 || s == htab->elf.sgot
3414 || s == htab->elf.sgotplt
3415 || s == htab->elf.iplt
3416 || s == htab->elf.igotplt
3417 || s == htab->plt_second
3418 || s == htab->plt_got
3419 || s == htab->plt_eh_frame
3420 || s == htab->plt_got_eh_frame
3421 || s == htab->plt_second_eh_frame
3422 || s == htab->elf.sdynbss
3423 || s == htab->elf.sdynrelro)
3425 /* Strip this section if we don't need it; see the
3428 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
3430 if (s->size != 0 && s != htab->elf.srelplt)
3433 /* We use the reloc_count field as a counter if we need
3434 to copy relocs into the output file. */
3435 if (s != htab->elf.srelplt)
3440 /* It's not one of our sections, so don't allocate space. */
3446 /* If we don't need this section, strip it from the
3447 output file. This is mostly to handle .rela.bss and
3448 .rela.plt. We must create both sections in
3449 create_dynamic_sections, because they must be created
3450 before the linker maps input sections to output
3451 sections. The linker does that before
3452 adjust_dynamic_symbol is called, and it is that
3453 function which decides whether anything needs to go
3454 into these sections. */
3456 s->flags |= SEC_EXCLUDE;
3460 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3463 /* Allocate memory for the section contents. We use bfd_zalloc
3464 here in case unused entries are not reclaimed before the
3465 section's contents are written out. This should not happen,
3466 but this way if it does, we get a R_X86_64_NONE reloc instead
3468 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3469 if (s->contents == NULL)
3473 if (htab->plt_eh_frame != NULL
3474 && htab->plt_eh_frame->contents != NULL)
3476 memcpy (htab->plt_eh_frame->contents,
3477 htab->plt.eh_frame_plt, htab->plt_eh_frame->size);
3478 bfd_put_32 (dynobj, htab->elf.splt->size,
3479 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
3482 if (htab->plt_got_eh_frame != NULL
3483 && htab->plt_got_eh_frame->contents != NULL)
3485 memcpy (htab->plt_got_eh_frame->contents,
3486 htab->non_lazy_plt->eh_frame_plt,
3487 htab->plt_got_eh_frame->size);
3488 bfd_put_32 (dynobj, htab->plt_got->size,
3489 (htab->plt_got_eh_frame->contents
3490 + PLT_FDE_LEN_OFFSET));
3493 if (htab->plt_second_eh_frame != NULL
3494 && htab->plt_second_eh_frame->contents != NULL)
3496 memcpy (htab->plt_second_eh_frame->contents,
3497 htab->non_lazy_plt->eh_frame_plt,
3498 htab->plt_second_eh_frame->size);
3499 bfd_put_32 (dynobj, htab->plt_second->size,
3500 (htab->plt_second_eh_frame->contents
3501 + PLT_FDE_LEN_OFFSET));
3504 if (htab->elf.dynamic_sections_created)
3506 /* Add some entries to the .dynamic section. We fill in the
3507 values later, in elf_x86_64_finish_dynamic_sections, but we
3508 must add the entries now so that we get the correct size for
3509 the .dynamic section. The DT_DEBUG entry is filled in by the
3510 dynamic linker and used by the debugger. */
3511 #define add_dynamic_entry(TAG, VAL) \
3512 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3514 if (bfd_link_executable (info))
3516 if (!add_dynamic_entry (DT_DEBUG, 0))
3520 if (htab->elf.splt->size != 0)
3522 /* DT_PLTGOT is used by prelink even if there is no PLT
3524 if (!add_dynamic_entry (DT_PLTGOT, 0))
3528 if (htab->elf.srelplt->size != 0)
3530 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
3531 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3532 || !add_dynamic_entry (DT_JMPREL, 0))
3536 if (htab->tlsdesc_plt
3537 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
3538 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
3543 if (!add_dynamic_entry (DT_RELA, 0)
3544 || !add_dynamic_entry (DT_RELASZ, 0)
3545 || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
3548 /* If any dynamic relocs apply to a read-only section,
3549 then we need a DT_TEXTREL entry. */
3550 if ((info->flags & DF_TEXTREL) == 0)
3551 elf_link_hash_traverse (&htab->elf,
3552 _bfd_x86_elf_readonly_dynrelocs,
3555 if ((info->flags & DF_TEXTREL) != 0)
3557 if (htab->readonly_dynrelocs_against_ifunc)
3559 info->callbacks->einfo
3560 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3561 bfd_set_error (bfd_error_bad_value);
3565 if (!add_dynamic_entry (DT_TEXTREL, 0))
3570 #undef add_dynamic_entry
3575 /* Return the relocation value for @tpoff relocation
3576 if STT_TLS virtual address is ADDRESS. */
3579 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
3581 struct elf_link_hash_table *htab = elf_hash_table (info);
3582 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
3583 bfd_vma static_tls_size;
3585 /* If tls_segment is NULL, we should have signalled an error already. */
3586 if (htab->tls_sec == NULL)
3589 /* Consider special static TLS alignment requirements. */
3590 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
3591 return address - static_tls_size - htab->tls_sec->vma;
3594 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3598 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
3600 /* Opcode Instruction
3603 0x0f 0x8x conditional jump */
3605 && (contents [offset - 1] == 0xe8
3606 || contents [offset - 1] == 0xe9))
3608 && contents [offset - 2] == 0x0f
3609 && (contents [offset - 1] & 0xf0) == 0x80));
3612 /* Relocate an x86_64 ELF section. */
3615 elf_x86_64_relocate_section (bfd *output_bfd,
3616 struct bfd_link_info *info,
3618 asection *input_section,
3620 Elf_Internal_Rela *relocs,
3621 Elf_Internal_Sym *local_syms,
3622 asection **local_sections)
3624 struct elf_x86_link_hash_table *htab;
3625 Elf_Internal_Shdr *symtab_hdr;
3626 struct elf_link_hash_entry **sym_hashes;
3627 bfd_vma *local_got_offsets;
3628 bfd_vma *local_tlsdesc_gotents;
3629 Elf_Internal_Rela *rel;
3630 Elf_Internal_Rela *wrel;
3631 Elf_Internal_Rela *relend;
3632 unsigned int plt_entry_size;
3634 BFD_ASSERT (is_x86_64_elf (input_bfd));
3636 /* Skip if check_relocs failed. */
3637 if (input_section->check_relocs_failed)
3640 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
3643 plt_entry_size = htab->plt.plt_entry_size;
3644 symtab_hdr = &elf_symtab_hdr (input_bfd);
3645 sym_hashes = elf_sym_hashes (input_bfd);
3646 local_got_offsets = elf_local_got_offsets (input_bfd);
3647 local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd);
3649 _bfd_x86_elf_set_tls_module_base (info);
3651 rel = wrel = relocs;
3652 relend = relocs + input_section->reloc_count;
3653 for (; rel < relend; wrel++, rel++)
3655 unsigned int r_type;
3656 reloc_howto_type *howto;
3657 unsigned long r_symndx;
3658 struct elf_link_hash_entry *h;
3659 struct elf_x86_link_hash_entry *eh;
3660 Elf_Internal_Sym *sym;
3662 bfd_vma off, offplt, plt_offset;
3664 bfd_boolean unresolved_reloc;
3665 bfd_reloc_status_type r;
3667 asection *base_got, *resolved_plt;
3669 bfd_boolean resolved_to_zero;
3670 bfd_boolean relative_reloc;
3672 r_type = ELF32_R_TYPE (rel->r_info);
3673 if (r_type == (int) R_X86_64_GNU_VTINHERIT
3674 || r_type == (int) R_X86_64_GNU_VTENTRY)
3681 if (r_type >= (int) R_X86_64_standard)
3682 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
3684 if (r_type != (int) R_X86_64_32
3685 || ABI_64_P (output_bfd))
3686 howto = x86_64_elf_howto_table + r_type;
3688 howto = (x86_64_elf_howto_table
3689 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
3690 r_symndx = htab->r_sym (rel->r_info);
3694 unresolved_reloc = FALSE;
3695 if (r_symndx < symtab_hdr->sh_info)
3697 sym = local_syms + r_symndx;
3698 sec = local_sections[r_symndx];
3700 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
3702 st_size = sym->st_size;
3704 /* Relocate against local STT_GNU_IFUNC symbol. */
3705 if (!bfd_link_relocatable (info)
3706 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
3708 h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd,
3713 /* Set STT_GNU_IFUNC symbol value. */
3714 h->root.u.def.value = sym->st_value;
3715 h->root.u.def.section = sec;
3720 bfd_boolean warned ATTRIBUTE_UNUSED;
3721 bfd_boolean ignored ATTRIBUTE_UNUSED;
3723 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3724 r_symndx, symtab_hdr, sym_hashes,
3726 unresolved_reloc, warned, ignored);
3730 if (sec != NULL && discarded_section (sec))
3732 _bfd_clear_contents (howto, input_bfd, input_section,
3733 contents + rel->r_offset);
3734 wrel->r_offset = rel->r_offset;
3738 /* For ld -r, remove relocations in debug sections against
3739 sections defined in discarded sections. Not done for
3740 eh_frame editing code expects to be present. */
3741 if (bfd_link_relocatable (info)
3742 && (input_section->flags & SEC_DEBUGGING))
3748 if (bfd_link_relocatable (info))
3755 if (rel->r_addend == 0 && !ABI_64_P (output_bfd))
3757 if (r_type == R_X86_64_64)
3759 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
3760 zero-extend it to 64bit if addend is zero. */
3761 r_type = R_X86_64_32;
3762 memset (contents + rel->r_offset + 4, 0, 4);
3764 else if (r_type == R_X86_64_SIZE64)
3766 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
3767 zero-extend it to 64bit if addend is zero. */
3768 r_type = R_X86_64_SIZE32;
3769 memset (contents + rel->r_offset + 4, 0, 4);
3773 eh = (struct elf_x86_link_hash_entry *) h;
3775 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3776 it here if it is defined in a non-shared object. */
3778 && h->type == STT_GNU_IFUNC
3784 if ((input_section->flags & SEC_ALLOC) == 0)
3786 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3787 sections because such sections are not SEC_ALLOC and
3788 thus ld.so will not process them. */
3789 if ((input_section->flags & SEC_DEBUGGING) != 0)
3799 case R_X86_64_GOTPCREL:
3800 case R_X86_64_GOTPCRELX:
3801 case R_X86_64_REX_GOTPCRELX:
3802 case R_X86_64_GOTPCREL64:
3803 base_got = htab->elf.sgot;
3804 off = h->got.offset;
3806 if (base_got == NULL)
3809 if (off == (bfd_vma) -1)
3811 /* We can't use h->got.offset here to save state, or
3812 even just remember the offset, as finish_dynamic_symbol
3813 would use that as offset into .got. */
3815 if (h->plt.offset == (bfd_vma) -1)
3818 if (htab->elf.splt != NULL)
3820 plt_index = (h->plt.offset / plt_entry_size
3821 - htab->plt.has_plt0);
3822 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3823 base_got = htab->elf.sgotplt;
3827 plt_index = h->plt.offset / plt_entry_size;
3828 off = plt_index * GOT_ENTRY_SIZE;
3829 base_got = htab->elf.igotplt;
3832 if (h->dynindx == -1
3836 /* This references the local defitionion. We must
3837 initialize this entry in the global offset table.
3838 Since the offset must always be a multiple of 8,
3839 we use the least significant bit to record
3840 whether we have initialized it already.
3842 When doing a dynamic link, we create a .rela.got
3843 relocation entry to initialize the value. This
3844 is done in the finish_dynamic_symbol routine. */
3849 bfd_put_64 (output_bfd, relocation,
3850 base_got->contents + off);
3851 /* Note that this is harmless for the GOTPLT64
3852 case, as -1 | 1 still is -1. */
3858 relocation = (base_got->output_section->vma
3859 + base_got->output_offset + off);
3864 if (h->plt.offset == (bfd_vma) -1)
3866 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3867 if (r_type == htab->pointer_r_type
3868 && (input_section->flags & SEC_CODE) == 0)
3869 goto do_ifunc_pointer;
3870 goto bad_ifunc_reloc;
3873 /* STT_GNU_IFUNC symbol must go through PLT. */
3874 if (htab->elf.splt != NULL)
3876 if (htab->plt_second != NULL)
3878 resolved_plt = htab->plt_second;
3879 plt_offset = eh->plt_second.offset;
3883 resolved_plt = htab->elf.splt;
3884 plt_offset = h->plt.offset;
3889 resolved_plt = htab->elf.iplt;
3890 plt_offset = h->plt.offset;
3893 relocation = (resolved_plt->output_section->vma
3894 + resolved_plt->output_offset + plt_offset);
3900 if (h->root.root.string)
3901 name = h->root.root.string;
3903 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3906 /* xgettext:c-format */
3907 (_("%B: relocation %s against STT_GNU_IFUNC "
3908 "symbol `%s' isn't supported"), input_bfd,
3910 bfd_set_error (bfd_error_bad_value);
3914 if (bfd_link_pic (info))
3919 if (ABI_64_P (output_bfd))
3924 if (rel->r_addend != 0)
3926 if (h->root.root.string)
3927 name = h->root.root.string;
3929 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
3932 /* xgettext:c-format */
3933 (_("%B: relocation %s against STT_GNU_IFUNC "
3934 "symbol `%s' has non-zero addend: %Ld"),
3935 input_bfd, howto->name, name, rel->r_addend);
3936 bfd_set_error (bfd_error_bad_value);
3940 /* Generate dynamic relcoation only when there is a
3941 non-GOT reference in a shared object or there is no
3943 if ((bfd_link_pic (info) && h->non_got_ref)
3944 || h->plt.offset == (bfd_vma) -1)
3946 Elf_Internal_Rela outrel;
3949 /* Need a dynamic relocation to get the real function
3951 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
3955 if (outrel.r_offset == (bfd_vma) -1
3956 || outrel.r_offset == (bfd_vma) -2)
3959 outrel.r_offset += (input_section->output_section->vma
3960 + input_section->output_offset);
3962 if (h->dynindx == -1
3964 || bfd_link_executable (info))
3966 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
3967 h->root.root.string,
3968 h->root.u.def.section->owner);
3970 /* This symbol is resolved locally. */
3971 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
3972 outrel.r_addend = (h->root.u.def.value
3973 + h->root.u.def.section->output_section->vma
3974 + h->root.u.def.section->output_offset);
3978 outrel.r_info = htab->r_info (h->dynindx, r_type);
3979 outrel.r_addend = 0;
3982 /* Dynamic relocations are stored in
3983 1. .rela.ifunc section in PIC object.
3984 2. .rela.got section in dynamic executable.
3985 3. .rela.iplt section in static executable. */
3986 if (bfd_link_pic (info))
3987 sreloc = htab->elf.irelifunc;
3988 else if (htab->elf.splt != NULL)
3989 sreloc = htab->elf.srelgot;
3991 sreloc = htab->elf.irelplt;
3992 elf_append_rela (output_bfd, sreloc, &outrel);
3994 /* If this reloc is against an external symbol, we
3995 do not want to fiddle with the addend. Otherwise,
3996 we need to include the symbol value so that it
3997 becomes an addend for the dynamic reloc. For an
3998 internal symbol, we have updated addend. */
4003 case R_X86_64_PC32_BND:
4005 case R_X86_64_PLT32:
4006 case R_X86_64_PLT32_BND:
4011 resolved_to_zero = (eh != NULL
4012 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
4017 /* When generating a shared object, the relocations handled here are
4018 copied into the output file to be resolved at run time. */
4021 case R_X86_64_GOT32:
4022 case R_X86_64_GOT64:
4023 /* Relocation is to the entry for this symbol in the global
4025 case R_X86_64_GOTPCREL:
4026 case R_X86_64_GOTPCRELX:
4027 case R_X86_64_REX_GOTPCRELX:
4028 case R_X86_64_GOTPCREL64:
4029 /* Use global offset table entry as symbol value. */
4030 case R_X86_64_GOTPLT64:
4031 /* This is obsolete and treated the same as GOT64. */
4032 base_got = htab->elf.sgot;
4034 if (htab->elf.sgot == NULL)
4037 relative_reloc = FALSE;
4042 off = h->got.offset;
4044 && h->plt.offset != (bfd_vma)-1
4045 && off == (bfd_vma)-1)
4047 /* We can't use h->got.offset here to save
4048 state, or even just remember the offset, as
4049 finish_dynamic_symbol would use that as offset into
4051 bfd_vma plt_index = (h->plt.offset / plt_entry_size
4052 - htab->plt.has_plt0);
4053 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4054 base_got = htab->elf.sgotplt;
4057 dyn = htab->elf.dynamic_sections_created;
4059 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4060 || (bfd_link_pic (info)
4061 && SYMBOL_REFERENCES_LOCAL (info, h))
4062 || (ELF_ST_VISIBILITY (h->other)
4063 && h->root.type == bfd_link_hash_undefweak))
4065 /* This is actually a static link, or it is a -Bsymbolic
4066 link and the symbol is defined locally, or the symbol
4067 was forced to be local because of a version file. We
4068 must initialize this entry in the global offset table.
4069 Since the offset must always be a multiple of 8, we
4070 use the least significant bit to record whether we
4071 have initialized it already.
4073 When doing a dynamic link, we create a .rela.got
4074 relocation entry to initialize the value. This is
4075 done in the finish_dynamic_symbol routine. */
4080 bfd_put_64 (output_bfd, relocation,
4081 base_got->contents + off);
4082 /* Note that this is harmless for the GOTPLT64 case,
4083 as -1 | 1 still is -1. */
4086 if (h->dynindx == -1
4088 && h->root.type != bfd_link_hash_undefweak
4089 && bfd_link_pic (info))
4091 /* If this symbol isn't dynamic in PIC,
4092 generate R_X86_64_RELATIVE here. */
4093 eh->no_finish_dynamic_symbol = 1;
4094 relative_reloc = TRUE;
4099 unresolved_reloc = FALSE;
4103 if (local_got_offsets == NULL)
4106 off = local_got_offsets[r_symndx];
4108 /* The offset must always be a multiple of 8. We use
4109 the least significant bit to record whether we have
4110 already generated the necessary reloc. */
4115 bfd_put_64 (output_bfd, relocation,
4116 base_got->contents + off);
4117 local_got_offsets[r_symndx] |= 1;
4119 if (bfd_link_pic (info))
4120 relative_reloc = TRUE;
4127 Elf_Internal_Rela outrel;
4129 /* We need to generate a R_X86_64_RELATIVE reloc
4130 for the dynamic linker. */
4131 s = htab->elf.srelgot;
4135 outrel.r_offset = (base_got->output_section->vma
4136 + base_got->output_offset
4138 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4139 outrel.r_addend = relocation;
4140 elf_append_rela (output_bfd, s, &outrel);
4143 if (off >= (bfd_vma) -2)
4146 relocation = base_got->output_section->vma
4147 + base_got->output_offset + off;
4148 if (r_type != R_X86_64_GOTPCREL
4149 && r_type != R_X86_64_GOTPCRELX
4150 && r_type != R_X86_64_REX_GOTPCRELX
4151 && r_type != R_X86_64_GOTPCREL64)
4152 relocation -= htab->elf.sgotplt->output_section->vma
4153 - htab->elf.sgotplt->output_offset;
4157 case R_X86_64_GOTOFF64:
4158 /* Relocation is relative to the start of the global offset
4161 /* Check to make sure it isn't a protected function or data
4162 symbol for shared library since it may not be local when
4163 used as function address or with copy relocation. We also
4164 need to make sure that a symbol is referenced locally. */
4165 if (bfd_link_pic (info) && h)
4167 if (!h->def_regular)
4171 switch (ELF_ST_VISIBILITY (h->other))
4174 v = _("hidden symbol");
4177 v = _("internal symbol");
4180 v = _("protected symbol");
4188 /* xgettext:c-format */
4189 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4190 " `%s' can not be used when making a shared object"),
4191 input_bfd, v, h->root.root.string);
4192 bfd_set_error (bfd_error_bad_value);
4195 else if (!bfd_link_executable (info)
4196 && !SYMBOL_REFERENCES_LOCAL (info, h)
4197 && (h->type == STT_FUNC
4198 || h->type == STT_OBJECT)
4199 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
4202 /* xgettext:c-format */
4203 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4204 " `%s' can not be used when making a shared object"),
4206 h->type == STT_FUNC ? "function" : "data",
4207 h->root.root.string);
4208 bfd_set_error (bfd_error_bad_value);
4213 /* Note that sgot is not involved in this
4214 calculation. We always want the start of .got.plt. If we
4215 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4216 permitted by the ABI, we might have to change this
4218 relocation -= htab->elf.sgotplt->output_section->vma
4219 + htab->elf.sgotplt->output_offset;
4222 case R_X86_64_GOTPC32:
4223 case R_X86_64_GOTPC64:
4224 /* Use global offset table as symbol value. */
4225 relocation = htab->elf.sgotplt->output_section->vma
4226 + htab->elf.sgotplt->output_offset;
4227 unresolved_reloc = FALSE;
4230 case R_X86_64_PLTOFF64:
4231 /* Relocation is PLT entry relative to GOT. For local
4232 symbols it's the symbol itself relative to GOT. */
4234 /* See PLT32 handling. */
4235 && (h->plt.offset != (bfd_vma) -1
4236 || eh->plt_got.offset != (bfd_vma) -1)
4237 && htab->elf.splt != NULL)
4239 if (eh->plt_got.offset != (bfd_vma) -1)
4241 /* Use the GOT PLT. */
4242 resolved_plt = htab->plt_got;
4243 plt_offset = eh->plt_got.offset;
4245 else if (htab->plt_second != NULL)
4247 resolved_plt = htab->plt_second;
4248 plt_offset = eh->plt_second.offset;
4252 resolved_plt = htab->elf.splt;
4253 plt_offset = h->plt.offset;
4256 relocation = (resolved_plt->output_section->vma
4257 + resolved_plt->output_offset
4259 unresolved_reloc = FALSE;
4262 relocation -= htab->elf.sgotplt->output_section->vma
4263 + htab->elf.sgotplt->output_offset;
4266 case R_X86_64_PLT32:
4267 case R_X86_64_PLT32_BND:
4268 /* Relocation is to the entry for this symbol in the
4269 procedure linkage table. */
4271 /* Resolve a PLT32 reloc against a local symbol directly,
4272 without using the procedure linkage table. */
4276 if ((h->plt.offset == (bfd_vma) -1
4277 && eh->plt_got.offset == (bfd_vma) -1)
4278 || htab->elf.splt == NULL)
4280 /* We didn't make a PLT entry for this symbol. This
4281 happens when statically linking PIC code, or when
4282 using -Bsymbolic. */
4286 if (h->plt.offset != (bfd_vma) -1)
4288 if (htab->plt_second != NULL)
4290 resolved_plt = htab->plt_second;
4291 plt_offset = eh->plt_second.offset;
4295 resolved_plt = htab->elf.splt;
4296 plt_offset = h->plt.offset;
4301 /* Use the GOT PLT. */
4302 resolved_plt = htab->plt_got;
4303 plt_offset = eh->plt_got.offset;
4306 relocation = (resolved_plt->output_section->vma
4307 + resolved_plt->output_offset
4309 unresolved_reloc = FALSE;
4312 case R_X86_64_SIZE32:
4313 case R_X86_64_SIZE64:
4314 /* Set to symbol size. */
4315 relocation = st_size;
4321 case R_X86_64_PC32_BND:
4322 /* Don't complain about -fPIC if the symbol is undefined when
4323 building executable unless it is unresolved weak symbol or
4324 -z nocopyreloc is used. */
4325 if ((input_section->flags & SEC_ALLOC) != 0
4326 && (input_section->flags & SEC_READONLY) != 0
4328 && ((bfd_link_executable (info)
4329 && ((h->root.type == bfd_link_hash_undefweak
4330 && !resolved_to_zero)
4331 || ((info->nocopyreloc
4332 || (eh->def_protected
4333 && elf_has_no_copy_on_protected (h->root.u.def.section->owner)))
4335 && !(h->root.u.def.section->flags & SEC_CODE))))
4336 || bfd_link_dll (info)))
4338 bfd_boolean fail = FALSE;
4340 = ((r_type == R_X86_64_PC32
4341 || r_type == R_X86_64_PC32_BND)
4342 && is_32bit_relative_branch (contents, rel->r_offset));
4344 if (SYMBOL_REFERENCES_LOCAL (info, h))
4346 /* Symbol is referenced locally. Make sure it is
4347 defined locally or for a branch. */
4348 fail = (!(h->def_regular || ELF_COMMON_DEF_P (h))
4351 else if (!(bfd_link_pie (info)
4352 && (h->needs_copy || eh->needs_copy)))
4354 /* Symbol doesn't need copy reloc and isn't referenced
4355 locally. We only allow branch to symbol with
4356 non-default visibility. */
4358 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
4362 return elf_x86_64_need_pic (info, input_bfd, input_section,
4363 h, NULL, NULL, howto);
4372 /* FIXME: The ABI says the linker should make sure the value is
4373 the same when it's zeroextended to 64 bit. */
4376 if ((input_section->flags & SEC_ALLOC) == 0)
4379 /* Don't copy a pc-relative relocation into the output file
4380 if the symbol needs copy reloc or the symbol is undefined
4381 when building executable. Copy dynamic function pointer
4382 relocations. Don't generate dynamic relocations against
4383 resolved undefined weak symbols in PIE. */
4384 if ((bfd_link_pic (info)
4385 && !(bfd_link_pie (info)
4389 || h->root.type == bfd_link_hash_undefined)
4390 && (IS_X86_64_PCREL_TYPE (r_type)
4391 || r_type == R_X86_64_SIZE32
4392 || r_type == R_X86_64_SIZE64))
4394 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4395 && !resolved_to_zero)
4396 || h->root.type != bfd_link_hash_undefweak))
4397 && ((! IS_X86_64_PCREL_TYPE (r_type)
4398 && r_type != R_X86_64_SIZE32
4399 && r_type != R_X86_64_SIZE64)
4400 || ! SYMBOL_CALLS_LOCAL (info, h)))
4401 || (ELIMINATE_COPY_RELOCS
4402 && !bfd_link_pic (info)
4406 || eh->func_pointer_refcount > 0
4407 || (h->root.type == bfd_link_hash_undefweak
4408 && !resolved_to_zero))
4409 && ((h->def_dynamic && !h->def_regular)
4410 /* Undefined weak symbol is bound locally when
4412 || h->root.type == bfd_link_hash_undefined)))
4414 Elf_Internal_Rela outrel;
4415 bfd_boolean skip, relocate;
4418 /* When generating a shared object, these relocations
4419 are copied into the output file to be resolved at run
4425 _bfd_elf_section_offset (output_bfd, info, input_section,
4427 if (outrel.r_offset == (bfd_vma) -1)
4429 else if (outrel.r_offset == (bfd_vma) -2)
4430 skip = TRUE, relocate = TRUE;
4432 outrel.r_offset += (input_section->output_section->vma
4433 + input_section->output_offset);
4436 memset (&outrel, 0, sizeof outrel);
4438 /* h->dynindx may be -1 if this symbol was marked to
4442 && (IS_X86_64_PCREL_TYPE (r_type)
4443 || !(bfd_link_executable (info)
4444 || SYMBOLIC_BIND (info, h))
4445 || ! h->def_regular))
4447 outrel.r_info = htab->r_info (h->dynindx, r_type);
4448 outrel.r_addend = rel->r_addend;
4452 /* This symbol is local, or marked to become local.
4453 When relocation overflow check is disabled, we
4454 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4455 if (r_type == htab->pointer_r_type
4456 || (r_type == R_X86_64_32
4457 && info->no_reloc_overflow_check))
4460 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4461 outrel.r_addend = relocation + rel->r_addend;
4463 else if (r_type == R_X86_64_64
4464 && !ABI_64_P (output_bfd))
4467 outrel.r_info = htab->r_info (0,
4468 R_X86_64_RELATIVE64);
4469 outrel.r_addend = relocation + rel->r_addend;
4470 /* Check addend overflow. */
4471 if ((outrel.r_addend & 0x80000000)
4472 != (rel->r_addend & 0x80000000))
4475 int addend = rel->r_addend;
4476 if (h && h->root.root.string)
4477 name = h->root.root.string;
4479 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4482 /* xgettext:c-format */
4483 (_("%B: addend %s%#x in relocation %s against "
4484 "symbol `%s' at %#Lx in section `%A' is "
4486 input_bfd, addend < 0 ? "-" : "", addend,
4487 howto->name, name, rel->r_offset, input_section);
4488 bfd_set_error (bfd_error_bad_value);
4496 if (bfd_is_abs_section (sec))
4498 else if (sec == NULL || sec->owner == NULL)
4500 bfd_set_error (bfd_error_bad_value);
4507 /* We are turning this relocation into one
4508 against a section symbol. It would be
4509 proper to subtract the symbol's value,
4510 osec->vma, from the emitted reloc addend,
4511 but ld.so expects buggy relocs. */
4512 osec = sec->output_section;
4513 sindx = elf_section_data (osec)->dynindx;
4516 asection *oi = htab->elf.text_index_section;
4517 sindx = elf_section_data (oi)->dynindx;
4519 BFD_ASSERT (sindx != 0);
4522 outrel.r_info = htab->r_info (sindx, r_type);
4523 outrel.r_addend = relocation + rel->r_addend;
4527 sreloc = elf_section_data (input_section)->sreloc;
4529 if (sreloc == NULL || sreloc->contents == NULL)
4531 r = bfd_reloc_notsupported;
4532 goto check_relocation_error;
4535 elf_append_rela (output_bfd, sreloc, &outrel);
4537 /* If this reloc is against an external symbol, we do
4538 not want to fiddle with the addend. Otherwise, we
4539 need to include the symbol value so that it becomes
4540 an addend for the dynamic reloc. */
4547 case R_X86_64_TLSGD:
4548 case R_X86_64_GOTPC32_TLSDESC:
4549 case R_X86_64_TLSDESC_CALL:
4550 case R_X86_64_GOTTPOFF:
4551 tls_type = GOT_UNKNOWN;
4552 if (h == NULL && local_got_offsets)
4553 tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx];
4555 tls_type = elf_x86_hash_entry (h)->tls_type;
4557 if (! elf_x86_64_tls_transition (info, input_bfd,
4558 input_section, contents,
4559 symtab_hdr, sym_hashes,
4560 &r_type, tls_type, rel,
4561 relend, h, r_symndx, TRUE))
4564 if (r_type == R_X86_64_TPOFF32)
4566 bfd_vma roff = rel->r_offset;
4568 BFD_ASSERT (! unresolved_reloc);
4570 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
4572 /* GD->LE transition. For 64bit, change
4573 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4574 .word 0x6666; rex64; call __tls_get_addr@PLT
4576 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4578 call *__tls_get_addr@GOTPCREL(%rip)
4579 which may be converted to
4580 addr32 call __tls_get_addr
4583 leaq foo@tpoff(%rax), %rax
4585 leaq foo@tlsgd(%rip), %rdi
4586 .word 0x6666; rex64; call __tls_get_addr@PLT
4588 leaq foo@tlsgd(%rip), %rdi
4590 call *__tls_get_addr@GOTPCREL(%rip)
4591 which may be converted to
4592 addr32 call __tls_get_addr
4595 leaq foo@tpoff(%rax), %rax
4596 For largepic, change:
4597 leaq foo@tlsgd(%rip), %rdi
4598 movabsq $__tls_get_addr@pltoff, %rax
4603 leaq foo@tpoff(%rax), %rax
4604 nopw 0x0(%rax,%rax,1) */
4606 if (ABI_64_P (output_bfd))
4608 if (contents[roff + 5] == 0xb8)
4610 memcpy (contents + roff - 3,
4611 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
4612 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4616 memcpy (contents + roff - 4,
4617 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4621 memcpy (contents + roff - 3,
4622 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4624 bfd_put_32 (output_bfd,
4625 elf_x86_64_tpoff (info, relocation),
4626 contents + roff + 8 + largepic);
4627 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
4628 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
4633 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
4635 /* GDesc -> LE transition.
4636 It's originally something like:
4637 leaq x@tlsdesc(%rip), %rax
4640 movl $x@tpoff, %rax. */
4642 unsigned int val, type;
4644 type = bfd_get_8 (input_bfd, contents + roff - 3);
4645 val = bfd_get_8 (input_bfd, contents + roff - 1);
4646 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
4647 contents + roff - 3);
4648 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
4649 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
4650 contents + roff - 1);
4651 bfd_put_32 (output_bfd,
4652 elf_x86_64_tpoff (info, relocation),
4656 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
4658 /* GDesc -> LE transition.
4663 bfd_put_8 (output_bfd, 0x66, contents + roff);
4664 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4667 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
4669 /* IE->LE transition:
4670 For 64bit, originally it can be one of:
4671 movq foo@gottpoff(%rip), %reg
4672 addq foo@gottpoff(%rip), %reg
4675 leaq foo(%reg), %reg
4677 For 32bit, originally it can be one of:
4678 movq foo@gottpoff(%rip), %reg
4679 addl foo@gottpoff(%rip), %reg
4682 leal foo(%reg), %reg
4685 unsigned int val, type, reg;
4688 val = bfd_get_8 (input_bfd, contents + roff - 3);
4691 type = bfd_get_8 (input_bfd, contents + roff - 2);
4692 reg = bfd_get_8 (input_bfd, contents + roff - 1);
4698 bfd_put_8 (output_bfd, 0x49,
4699 contents + roff - 3);
4700 else if (!ABI_64_P (output_bfd) && val == 0x44)
4701 bfd_put_8 (output_bfd, 0x41,
4702 contents + roff - 3);
4703 bfd_put_8 (output_bfd, 0xc7,
4704 contents + roff - 2);
4705 bfd_put_8 (output_bfd, 0xc0 | reg,
4706 contents + roff - 1);
4710 /* addq/addl -> addq/addl - addressing with %rsp/%r12
4713 bfd_put_8 (output_bfd, 0x49,
4714 contents + roff - 3);
4715 else if (!ABI_64_P (output_bfd) && val == 0x44)
4716 bfd_put_8 (output_bfd, 0x41,
4717 contents + roff - 3);
4718 bfd_put_8 (output_bfd, 0x81,
4719 contents + roff - 2);
4720 bfd_put_8 (output_bfd, 0xc0 | reg,
4721 contents + roff - 1);
4725 /* addq/addl -> leaq/leal */
4727 bfd_put_8 (output_bfd, 0x4d,
4728 contents + roff - 3);
4729 else if (!ABI_64_P (output_bfd) && val == 0x44)
4730 bfd_put_8 (output_bfd, 0x45,
4731 contents + roff - 3);
4732 bfd_put_8 (output_bfd, 0x8d,
4733 contents + roff - 2);
4734 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
4735 contents + roff - 1);
4737 bfd_put_32 (output_bfd,
4738 elf_x86_64_tpoff (info, relocation),
4746 if (htab->elf.sgot == NULL)
4751 off = h->got.offset;
4752 offplt = elf_x86_hash_entry (h)->tlsdesc_got;
4756 if (local_got_offsets == NULL)
4759 off = local_got_offsets[r_symndx];
4760 offplt = local_tlsdesc_gotents[r_symndx];
4767 Elf_Internal_Rela outrel;
4771 if (htab->elf.srelgot == NULL)
4774 indx = h && h->dynindx != -1 ? h->dynindx : 0;
4776 if (GOT_TLS_GDESC_P (tls_type))
4778 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
4779 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
4780 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
4781 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
4782 + htab->elf.sgotplt->output_offset
4784 + htab->sgotplt_jump_table_size);
4785 sreloc = htab->elf.srelplt;
4787 outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
4789 outrel.r_addend = 0;
4790 elf_append_rela (output_bfd, sreloc, &outrel);
4793 sreloc = htab->elf.srelgot;
4795 outrel.r_offset = (htab->elf.sgot->output_section->vma
4796 + htab->elf.sgot->output_offset + off);
4798 if (GOT_TLS_GD_P (tls_type))
4799 dr_type = R_X86_64_DTPMOD64;
4800 else if (GOT_TLS_GDESC_P (tls_type))
4803 dr_type = R_X86_64_TPOFF64;
4805 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
4806 outrel.r_addend = 0;
4807 if ((dr_type == R_X86_64_TPOFF64
4808 || dr_type == R_X86_64_TLSDESC) && indx == 0)
4809 outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
4810 outrel.r_info = htab->r_info (indx, dr_type);
4812 elf_append_rela (output_bfd, sreloc, &outrel);
4814 if (GOT_TLS_GD_P (tls_type))
4818 BFD_ASSERT (! unresolved_reloc);
4819 bfd_put_64 (output_bfd,
4820 relocation - _bfd_x86_elf_dtpoff_base (info),
4821 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
4825 bfd_put_64 (output_bfd, 0,
4826 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
4827 outrel.r_info = htab->r_info (indx,
4829 outrel.r_offset += GOT_ENTRY_SIZE;
4830 elf_append_rela (output_bfd, sreloc,
4839 local_got_offsets[r_symndx] |= 1;
4842 if (off >= (bfd_vma) -2
4843 && ! GOT_TLS_GDESC_P (tls_type))
4845 if (r_type == ELF32_R_TYPE (rel->r_info))
4847 if (r_type == R_X86_64_GOTPC32_TLSDESC
4848 || r_type == R_X86_64_TLSDESC_CALL)
4849 relocation = htab->elf.sgotplt->output_section->vma
4850 + htab->elf.sgotplt->output_offset
4851 + offplt + htab->sgotplt_jump_table_size;
4853 relocation = htab->elf.sgot->output_section->vma
4854 + htab->elf.sgot->output_offset + off;
4855 unresolved_reloc = FALSE;
4859 bfd_vma roff = rel->r_offset;
4861 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
4863 /* GD->IE transition. For 64bit, change
4864 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4865 .word 0x6666; rex64; call __tls_get_addr@PLT
4867 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4869 call *__tls_get_addr@GOTPCREL(%rip
4870 which may be converted to
4871 addr32 call __tls_get_addr
4874 addq foo@gottpoff(%rip), %rax
4876 leaq foo@tlsgd(%rip), %rdi
4877 .word 0x6666; rex64; call __tls_get_addr@PLT
4879 leaq foo@tlsgd(%rip), %rdi
4881 call *__tls_get_addr@GOTPCREL(%rip)
4882 which may be converted to
4883 addr32 call __tls_get_addr
4886 addq foo@gottpoff(%rip), %rax
4887 For largepic, change:
4888 leaq foo@tlsgd(%rip), %rdi
4889 movabsq $__tls_get_addr@pltoff, %rax
4894 addq foo@gottpoff(%rax), %rax
4895 nopw 0x0(%rax,%rax,1) */
4897 if (ABI_64_P (output_bfd))
4899 if (contents[roff + 5] == 0xb8)
4901 memcpy (contents + roff - 3,
4902 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
4903 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4907 memcpy (contents + roff - 4,
4908 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4912 memcpy (contents + roff - 3,
4913 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4916 relocation = (htab->elf.sgot->output_section->vma
4917 + htab->elf.sgot->output_offset + off
4920 - input_section->output_section->vma
4921 - input_section->output_offset
4923 bfd_put_32 (output_bfd, relocation,
4924 contents + roff + 8 + largepic);
4925 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
4930 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
4932 /* GDesc -> IE transition.
4933 It's originally something like:
4934 leaq x@tlsdesc(%rip), %rax
4937 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4939 /* Now modify the instruction as appropriate. To
4940 turn a leaq into a movq in the form we use it, it
4941 suffices to change the second byte from 0x8d to
4943 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
4945 bfd_put_32 (output_bfd,
4946 htab->elf.sgot->output_section->vma
4947 + htab->elf.sgot->output_offset + off
4949 - input_section->output_section->vma
4950 - input_section->output_offset
4955 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
4957 /* GDesc -> IE transition.
4964 bfd_put_8 (output_bfd, 0x66, contents + roff);
4965 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
4973 case R_X86_64_TLSLD:
4974 if (! elf_x86_64_tls_transition (info, input_bfd,
4975 input_section, contents,
4976 symtab_hdr, sym_hashes,
4977 &r_type, GOT_UNKNOWN, rel,
4978 relend, h, r_symndx, TRUE))
4981 if (r_type != R_X86_64_TLSLD)
4983 /* LD->LE transition:
4984 leaq foo@tlsld(%rip), %rdi
4985 call __tls_get_addr@PLT
4986 For 64bit, we change it into:
4987 .word 0x6666; .byte 0x66; movq %fs:0, %rax
4988 For 32bit, we change it into:
4989 nopl 0x0(%rax); movl %fs:0, %eax
4991 leaq foo@tlsld(%rip), %rdi;
4992 call *__tls_get_addr@GOTPCREL(%rip)
4993 which may be converted to
4994 addr32 call __tls_get_addr
4995 For 64bit, we change it into:
4996 .word 0x6666; .word 0x6666; movq %fs:0, %rax
4997 For 32bit, we change it into:
4998 nopw 0x0(%rax); movl %fs:0, %eax
4999 For largepic, change:
5000 leaq foo@tlsgd(%rip), %rdi
5001 movabsq $__tls_get_addr@pltoff, %rax
5005 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5008 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
5009 if (ABI_64_P (output_bfd))
5011 if (contents[rel->r_offset + 5] == 0xb8)
5012 memcpy (contents + rel->r_offset - 3,
5013 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5014 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5015 else if (contents[rel->r_offset + 4] == 0xff
5016 || contents[rel->r_offset + 4] == 0x67)
5017 memcpy (contents + rel->r_offset - 3,
5018 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5021 memcpy (contents + rel->r_offset - 3,
5022 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5026 if (contents[rel->r_offset + 4] == 0xff)
5027 memcpy (contents + rel->r_offset - 3,
5028 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5031 memcpy (contents + rel->r_offset - 3,
5032 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5034 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5035 and R_X86_64_PLTOFF64. */
5041 if (htab->elf.sgot == NULL)
5044 off = htab->tls_ld_or_ldm_got.offset;
5049 Elf_Internal_Rela outrel;
5051 if (htab->elf.srelgot == NULL)
5054 outrel.r_offset = (htab->elf.sgot->output_section->vma
5055 + htab->elf.sgot->output_offset + off);
5057 bfd_put_64 (output_bfd, 0,
5058 htab->elf.sgot->contents + off);
5059 bfd_put_64 (output_bfd, 0,
5060 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
5061 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
5062 outrel.r_addend = 0;
5063 elf_append_rela (output_bfd, htab->elf.srelgot,
5065 htab->tls_ld_or_ldm_got.offset |= 1;
5067 relocation = htab->elf.sgot->output_section->vma
5068 + htab->elf.sgot->output_offset + off;
5069 unresolved_reloc = FALSE;
5072 case R_X86_64_DTPOFF32:
5073 if (!bfd_link_executable (info)
5074 || (input_section->flags & SEC_CODE) == 0)
5075 relocation -= _bfd_x86_elf_dtpoff_base (info);
5077 relocation = elf_x86_64_tpoff (info, relocation);
5080 case R_X86_64_TPOFF32:
5081 case R_X86_64_TPOFF64:
5082 BFD_ASSERT (bfd_link_executable (info));
5083 relocation = elf_x86_64_tpoff (info, relocation);
5086 case R_X86_64_DTPOFF64:
5087 BFD_ASSERT ((input_section->flags & SEC_CODE) == 0);
5088 relocation -= _bfd_x86_elf_dtpoff_base (info);
5095 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5096 because such sections are not SEC_ALLOC and thus ld.so will
5097 not process them. */
5098 if (unresolved_reloc
5099 && !((input_section->flags & SEC_DEBUGGING) != 0
5101 && _bfd_elf_section_offset (output_bfd, info, input_section,
5102 rel->r_offset) != (bfd_vma) -1)
5107 sec = h->root.u.def.section;
5108 if ((info->nocopyreloc
5109 || (eh->def_protected
5110 && elf_has_no_copy_on_protected (h->root.u.def.section->owner)))
5111 && !(h->root.u.def.section->flags & SEC_CODE))
5112 return elf_x86_64_need_pic (info, input_bfd, input_section,
5113 h, NULL, NULL, howto);
5118 /* xgettext:c-format */
5119 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
5124 h->root.root.string);
5130 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5131 contents, rel->r_offset,
5132 relocation, rel->r_addend);
5134 check_relocation_error:
5135 if (r != bfd_reloc_ok)
5140 name = h->root.root.string;
5143 name = bfd_elf_string_from_elf_section (input_bfd,
5144 symtab_hdr->sh_link,
5149 name = bfd_section_name (input_bfd, sec);
5152 if (r == bfd_reloc_overflow)
5153 (*info->callbacks->reloc_overflow)
5154 (info, (h ? &h->root : NULL), name, howto->name,
5155 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
5159 /* xgettext:c-format */
5160 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
5161 input_bfd, input_section,
5162 rel->r_offset, name, (int) r);
5173 Elf_Internal_Shdr *rel_hdr;
5174 size_t deleted = rel - wrel;
5176 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
5177 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5178 if (rel_hdr->sh_size == 0)
5180 /* It is too late to remove an empty reloc section. Leave
5182 ??? What is wrong with an empty section??? */
5183 rel_hdr->sh_size = rel_hdr->sh_entsize;
5186 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
5187 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
5188 input_section->reloc_count -= deleted;
5194 /* Finish up dynamic symbol handling. We set the contents of various
5195 dynamic sections here. */
5198 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
5199 struct bfd_link_info *info,
5200 struct elf_link_hash_entry *h,
5201 Elf_Internal_Sym *sym)
5203 struct elf_x86_link_hash_table *htab;
5204 bfd_boolean use_plt_second;
5205 struct elf_x86_link_hash_entry *eh;
5206 bfd_boolean local_undefweak;
5208 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
5212 /* Use the second PLT section only if there is .plt section. */
5213 use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
5215 eh = (struct elf_x86_link_hash_entry *) h;
5216 if (eh->no_finish_dynamic_symbol)
5219 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5220 resolved undefined weak symbols in executable so that their
5221 references have value 0 at run-time. */
5222 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
5227 if (h->plt.offset != (bfd_vma) -1)
5230 bfd_vma got_offset, plt_offset;
5231 Elf_Internal_Rela rela;
5233 asection *plt, *gotplt, *relplt, *resolved_plt;
5234 const struct elf_backend_data *bed;
5235 bfd_vma plt_got_pcrel_offset;
5237 /* When building a static executable, use .iplt, .igot.plt and
5238 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5239 if (htab->elf.splt != NULL)
5241 plt = htab->elf.splt;
5242 gotplt = htab->elf.sgotplt;
5243 relplt = htab->elf.srelplt;
5247 plt = htab->elf.iplt;
5248 gotplt = htab->elf.igotplt;
5249 relplt = htab->elf.irelplt;
5252 /* This symbol has an entry in the procedure linkage table. Set
5254 if ((h->dynindx == -1
5256 && !((h->forced_local || bfd_link_executable (info))
5258 && h->type == STT_GNU_IFUNC))
5264 /* Get the index in the procedure linkage table which
5265 corresponds to this symbol. This is the index of this symbol
5266 in all the symbols for which we are making plt entries. The
5267 first entry in the procedure linkage table is reserved.
5269 Get the offset into the .got table of the entry that
5270 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5271 bytes. The first three are reserved for the dynamic linker.
5273 For static executables, we don't reserve anything. */
5275 if (plt == htab->elf.splt)
5277 got_offset = (h->plt.offset / htab->plt.plt_entry_size
5278 - htab->plt.has_plt0);
5279 got_offset = (got_offset + 3) * GOT_ENTRY_SIZE;
5283 got_offset = h->plt.offset / htab->plt.plt_entry_size;
5284 got_offset = got_offset * GOT_ENTRY_SIZE;
5287 /* Fill in the entry in the procedure linkage table. */
5288 memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry,
5289 htab->plt.plt_entry_size);
5292 memcpy (htab->plt_second->contents + eh->plt_second.offset,
5293 htab->non_lazy_plt->plt_entry,
5294 htab->non_lazy_plt->plt_entry_size);
5296 resolved_plt = htab->plt_second;
5297 plt_offset = eh->plt_second.offset;
5302 plt_offset = h->plt.offset;
5305 /* Insert the relocation positions of the plt section. */
5307 /* Put offset the PC-relative instruction referring to the GOT entry,
5308 subtracting the size of that instruction. */
5309 plt_got_pcrel_offset = (gotplt->output_section->vma
5310 + gotplt->output_offset
5312 - resolved_plt->output_section->vma
5313 - resolved_plt->output_offset
5315 - htab->plt.plt_got_insn_size);
5317 /* Check PC-relative offset overflow in PLT entry. */
5318 if ((plt_got_pcrel_offset + 0x80000000) > 0xffffffff)
5319 /* xgettext:c-format */
5320 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5321 output_bfd, h->root.root.string);
5323 bfd_put_32 (output_bfd, plt_got_pcrel_offset,
5324 (resolved_plt->contents + plt_offset
5325 + htab->plt.plt_got_offset));
5327 /* Fill in the entry in the global offset table, initially this
5328 points to the second part of the PLT entry. Leave the entry
5329 as zero for undefined weak symbol in PIE. No PLT relocation
5330 against undefined weak symbol in PIE. */
5331 if (!local_undefweak)
5333 if (htab->plt.has_plt0)
5334 bfd_put_64 (output_bfd, (plt->output_section->vma
5335 + plt->output_offset
5337 + htab->lazy_plt->plt_lazy_offset),
5338 gotplt->contents + got_offset);
5340 /* Fill in the entry in the .rela.plt section. */
5341 rela.r_offset = (gotplt->output_section->vma
5342 + gotplt->output_offset
5344 if (h->dynindx == -1
5345 || ((bfd_link_executable (info)
5346 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5348 && h->type == STT_GNU_IFUNC))
5350 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
5351 h->root.root.string,
5352 h->root.u.def.section->owner);
5354 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5355 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5356 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
5357 rela.r_addend = (h->root.u.def.value
5358 + h->root.u.def.section->output_section->vma
5359 + h->root.u.def.section->output_offset);
5360 /* R_X86_64_IRELATIVE comes last. */
5361 plt_index = htab->next_irelative_index--;
5365 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
5367 plt_index = htab->next_jump_slot_index++;
5370 /* Don't fill the second and third slots in PLT entry for
5371 static executables nor without PLT0. */
5372 if (plt == htab->elf.splt && htab->plt.has_plt0)
5375 = h->plt.offset + htab->lazy_plt->plt_plt_insn_end;
5377 /* Put relocation index. */
5378 bfd_put_32 (output_bfd, plt_index,
5379 (plt->contents + h->plt.offset
5380 + htab->lazy_plt->plt_reloc_offset));
5382 /* Put offset for jmp .PLT0 and check for overflow. We don't
5383 check relocation index for overflow since branch displacement
5384 will overflow first. */
5385 if (plt0_offset > 0x80000000)
5386 /* xgettext:c-format */
5387 info->callbacks->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5388 output_bfd, h->root.root.string);
5389 bfd_put_32 (output_bfd, - plt0_offset,
5390 (plt->contents + h->plt.offset
5391 + htab->lazy_plt->plt_plt_offset));
5394 bed = get_elf_backend_data (output_bfd);
5395 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
5396 bed->s->swap_reloca_out (output_bfd, &rela, loc);
5399 else if (eh->plt_got.offset != (bfd_vma) -1)
5401 bfd_vma got_offset, plt_offset;
5402 asection *plt, *got;
5403 bfd_boolean got_after_plt;
5404 int32_t got_pcrel_offset;
5406 /* Set the entry in the GOT procedure linkage table. */
5407 plt = htab->plt_got;
5408 got = htab->elf.sgot;
5409 got_offset = h->got.offset;
5411 if (got_offset == (bfd_vma) -1
5412 || (h->type == STT_GNU_IFUNC && h->def_regular)
5417 /* Use the non-lazy PLT entry template for the GOT PLT since they
5418 are the identical. */
5419 /* Fill in the entry in the GOT procedure linkage table. */
5420 plt_offset = eh->plt_got.offset;
5421 memcpy (plt->contents + plt_offset,
5422 htab->non_lazy_plt->plt_entry,
5423 htab->non_lazy_plt->plt_entry_size);
5425 /* Put offset the PC-relative instruction referring to the GOT
5426 entry, subtracting the size of that instruction. */
5427 got_pcrel_offset = (got->output_section->vma
5428 + got->output_offset
5430 - plt->output_section->vma
5431 - plt->output_offset
5433 - htab->non_lazy_plt->plt_got_insn_size);
5435 /* Check PC-relative offset overflow in GOT PLT entry. */
5436 got_after_plt = got->output_section->vma > plt->output_section->vma;
5437 if ((got_after_plt && got_pcrel_offset < 0)
5438 || (!got_after_plt && got_pcrel_offset > 0))
5439 /* xgettext:c-format */
5440 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5441 output_bfd, h->root.root.string);
5443 bfd_put_32 (output_bfd, got_pcrel_offset,
5444 (plt->contents + plt_offset
5445 + htab->non_lazy_plt->plt_got_offset));
5448 if (!local_undefweak
5450 && (h->plt.offset != (bfd_vma) -1
5451 || eh->plt_got.offset != (bfd_vma) -1))
5453 /* Mark the symbol as undefined, rather than as defined in
5454 the .plt section. Leave the value if there were any
5455 relocations where pointer equality matters (this is a clue
5456 for the dynamic linker, to make function pointer
5457 comparisons work between an application and shared
5458 library), otherwise set it to zero. If a function is only
5459 called from a binary, there is no need to slow down
5460 shared libraries because of that. */
5461 sym->st_shndx = SHN_UNDEF;
5462 if (!h->pointer_equality_needed)
5466 /* Don't generate dynamic GOT relocation against undefined weak
5467 symbol in executable. */
5468 if (h->got.offset != (bfd_vma) -1
5469 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h)->tls_type)
5470 && elf_x86_hash_entry (h)->tls_type != GOT_TLS_IE
5471 && !local_undefweak)
5473 Elf_Internal_Rela rela;
5474 asection *relgot = htab->elf.srelgot;
5476 /* This symbol has an entry in the global offset table. Set it
5478 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
5481 rela.r_offset = (htab->elf.sgot->output_section->vma
5482 + htab->elf.sgot->output_offset
5483 + (h->got.offset &~ (bfd_vma) 1));
5485 /* If this is a static link, or it is a -Bsymbolic link and the
5486 symbol is defined locally or was forced to be local because
5487 of a version file, we just want to emit a RELATIVE reloc.
5488 The entry in the global offset table will already have been
5489 initialized in the relocate_section function. */
5491 && h->type == STT_GNU_IFUNC)
5493 if (h->plt.offset == (bfd_vma) -1)
5495 /* STT_GNU_IFUNC is referenced without PLT. */
5496 if (htab->elf.splt == NULL)
5498 /* use .rel[a].iplt section to store .got relocations
5499 in static executable. */
5500 relgot = htab->elf.irelplt;
5502 if (SYMBOL_REFERENCES_LOCAL (info, h))
5504 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
5506 h->root.root.string,
5507 h->root.u.def.section->owner);
5509 rela.r_info = htab->r_info (0,
5510 R_X86_64_IRELATIVE);
5511 rela.r_addend = (h->root.u.def.value
5512 + h->root.u.def.section->output_section->vma
5513 + h->root.u.def.section->output_offset);
5518 else if (bfd_link_pic (info))
5520 /* Generate R_X86_64_GLOB_DAT. */
5528 if (!h->pointer_equality_needed)
5531 /* For non-shared object, we can't use .got.plt, which
5532 contains the real function addres if we need pointer
5533 equality. We load the GOT entry with the PLT entry. */
5534 if (htab->plt_second != NULL)
5536 plt = htab->plt_second;
5537 plt_offset = eh->plt_second.offset;
5541 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
5542 plt_offset = h->plt.offset;
5544 bfd_put_64 (output_bfd, (plt->output_section->vma
5545 + plt->output_offset
5547 htab->elf.sgot->contents + h->got.offset);
5551 else if (bfd_link_pic (info)
5552 && SYMBOL_REFERENCES_LOCAL (info, h))
5554 if (!h->def_regular)
5556 BFD_ASSERT((h->got.offset & 1) != 0);
5557 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
5558 rela.r_addend = (h->root.u.def.value
5559 + h->root.u.def.section->output_section->vma
5560 + h->root.u.def.section->output_offset);
5564 BFD_ASSERT((h->got.offset & 1) == 0);
5566 bfd_put_64 (output_bfd, (bfd_vma) 0,
5567 htab->elf.sgot->contents + h->got.offset);
5568 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
5572 elf_append_rela (output_bfd, relgot, &rela);
5577 Elf_Internal_Rela rela;
5580 /* This symbol needs a copy reloc. Set it up. */
5582 if (h->dynindx == -1
5583 || (h->root.type != bfd_link_hash_defined
5584 && h->root.type != bfd_link_hash_defweak)
5585 || htab->elf.srelbss == NULL
5586 || htab->elf.sreldynrelro == NULL)
5589 rela.r_offset = (h->root.u.def.value
5590 + h->root.u.def.section->output_section->vma
5591 + h->root.u.def.section->output_offset);
5592 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
5594 if (h->root.u.def.section == htab->elf.sdynrelro)
5595 s = htab->elf.sreldynrelro;
5597 s = htab->elf.srelbss;
5598 elf_append_rela (output_bfd, s, &rela);
5604 /* Finish up local dynamic symbol handling. We set the contents of
5605 various dynamic sections here. */
5608 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
5610 struct elf_link_hash_entry *h
5611 = (struct elf_link_hash_entry *) *slot;
5612 struct bfd_link_info *info
5613 = (struct bfd_link_info *) inf;
5615 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
5619 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5620 here since undefined weak symbol may not be dynamic and may not be
5621 called for elf_x86_64_finish_dynamic_symbol. */
5624 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
5627 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
5628 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5630 if (h->root.type != bfd_link_hash_undefweak
5631 || h->dynindx != -1)
5634 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
5638 /* Used to decide how to sort relocs in an optimal manner for the
5639 dynamic linker, before writing them out. */
5641 static enum elf_reloc_type_class
5642 elf_x86_64_reloc_type_class (const struct bfd_link_info *info,
5643 const asection *rel_sec ATTRIBUTE_UNUSED,
5644 const Elf_Internal_Rela *rela)
5646 bfd *abfd = info->output_bfd;
5647 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5648 struct elf_x86_link_hash_table *htab
5649 = elf_x86_hash_table (info, X86_64_ELF_DATA);
5651 if (htab->elf.dynsym != NULL
5652 && htab->elf.dynsym->contents != NULL)
5654 /* Check relocation against STT_GNU_IFUNC symbol if there are
5656 unsigned long r_symndx = htab->r_sym (rela->r_info);
5657 if (r_symndx != STN_UNDEF)
5659 Elf_Internal_Sym sym;
5660 if (!bed->s->swap_symbol_in (abfd,
5661 (htab->elf.dynsym->contents
5662 + r_symndx * bed->s->sizeof_sym),
5666 if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
5667 return reloc_class_ifunc;
5671 switch ((int) ELF32_R_TYPE (rela->r_info))
5673 case R_X86_64_IRELATIVE:
5674 return reloc_class_ifunc;
5675 case R_X86_64_RELATIVE:
5676 case R_X86_64_RELATIVE64:
5677 return reloc_class_relative;
5678 case R_X86_64_JUMP_SLOT:
5679 return reloc_class_plt;
5681 return reloc_class_copy;
5683 return reloc_class_normal;
5687 /* Finish up the dynamic sections. */
5690 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
5691 struct bfd_link_info *info)
5693 struct elf_x86_link_hash_table *htab;
5697 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
5701 dynobj = htab->elf.dynobj;
5702 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
5704 if (htab->elf.dynamic_sections_created)
5706 bfd_byte *dyncon, *dynconend;
5707 const struct elf_backend_data *bed;
5708 bfd_size_type sizeof_dyn;
5710 if (sdyn == NULL || htab->elf.sgot == NULL)
5713 bed = get_elf_backend_data (dynobj);
5714 sizeof_dyn = bed->s->sizeof_dyn;
5715 dyncon = sdyn->contents;
5716 dynconend = sdyn->contents + sdyn->size;
5717 for (; dyncon < dynconend; dyncon += sizeof_dyn)
5719 Elf_Internal_Dyn dyn;
5722 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
5730 s = htab->elf.sgotplt;
5731 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
5735 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
5739 s = htab->elf.srelplt->output_section;
5740 dyn.d_un.d_val = s->size;
5743 case DT_TLSDESC_PLT:
5745 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
5746 + htab->tlsdesc_plt;
5749 case DT_TLSDESC_GOT:
5751 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
5752 + htab->tlsdesc_got;
5756 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
5759 if (htab->elf.splt && htab->elf.splt->size > 0)
5761 elf_section_data (htab->elf.splt->output_section)
5762 ->this_hdr.sh_entsize = htab->plt.plt_entry_size;
5764 if (htab->plt.has_plt0)
5766 /* Fill in the special first entry in the procedure linkage
5768 memcpy (htab->elf.splt->contents,
5769 htab->lazy_plt->plt0_entry,
5770 htab->lazy_plt->plt0_entry_size);
5771 /* Add offset for pushq GOT+8(%rip), since the instruction
5772 uses 6 bytes subtract this value. */
5773 bfd_put_32 (output_bfd,
5774 (htab->elf.sgotplt->output_section->vma
5775 + htab->elf.sgotplt->output_offset
5777 - htab->elf.splt->output_section->vma
5778 - htab->elf.splt->output_offset
5780 (htab->elf.splt->contents
5781 + htab->lazy_plt->plt0_got1_offset));
5782 /* Add offset for the PC-relative instruction accessing
5783 GOT+16, subtracting the offset to the end of that
5785 bfd_put_32 (output_bfd,
5786 (htab->elf.sgotplt->output_section->vma
5787 + htab->elf.sgotplt->output_offset
5789 - htab->elf.splt->output_section->vma
5790 - htab->elf.splt->output_offset
5791 - htab->lazy_plt->plt0_got2_insn_end),
5792 (htab->elf.splt->contents
5793 + htab->lazy_plt->plt0_got2_offset));
5795 if (htab->tlsdesc_plt)
5797 bfd_put_64 (output_bfd, (bfd_vma) 0,
5798 htab->elf.sgot->contents + htab->tlsdesc_got);
5800 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
5801 htab->lazy_plt->plt0_entry,
5802 htab->lazy_plt->plt0_entry_size);
5804 /* Add offset for pushq GOT+8(%rip), since the
5805 instruction uses 6 bytes subtract this value. */
5806 bfd_put_32 (output_bfd,
5807 (htab->elf.sgotplt->output_section->vma
5808 + htab->elf.sgotplt->output_offset
5810 - htab->elf.splt->output_section->vma
5811 - htab->elf.splt->output_offset
5814 (htab->elf.splt->contents
5816 + htab->lazy_plt->plt0_got1_offset));
5817 /* Add offset for the PC-relative instruction accessing
5818 GOT+TDG, where TDG stands for htab->tlsdesc_got,
5819 subtracting the offset to the end of that
5821 bfd_put_32 (output_bfd,
5822 (htab->elf.sgot->output_section->vma
5823 + htab->elf.sgot->output_offset
5825 - htab->elf.splt->output_section->vma
5826 - htab->elf.splt->output_offset
5828 - htab->lazy_plt->plt0_got2_insn_end),
5829 (htab->elf.splt->contents
5831 + htab->lazy_plt->plt0_got2_offset));
5836 if (htab->plt_got != NULL && htab->plt_got->size > 0)
5837 elf_section_data (htab->plt_got->output_section)
5838 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
5840 if (htab->plt_second != NULL && htab->plt_second->size > 0)
5841 elf_section_data (htab->plt_second->output_section)
5842 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
5845 /* GOT is always created in setup_gnu_properties. But it may not be
5847 if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0)
5849 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
5852 (_("discarded output section: `%A'"), htab->elf.sgotplt);
5856 /* Set the first entry in the global offset table to the address of
5857 the dynamic section. */
5859 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
5861 bfd_put_64 (output_bfd,
5862 sdyn->output_section->vma + sdyn->output_offset,
5863 htab->elf.sgotplt->contents);
5864 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
5865 bfd_put_64 (output_bfd, (bfd_vma) 0,
5866 htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
5867 bfd_put_64 (output_bfd, (bfd_vma) 0,
5868 htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
5870 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize
5874 /* Adjust .eh_frame for .plt section. */
5875 if (htab->plt_eh_frame != NULL
5876 && htab->plt_eh_frame->contents != NULL)
5878 if (htab->elf.splt != NULL
5879 && htab->elf.splt->size != 0
5880 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
5881 && htab->elf.splt->output_section != NULL
5882 && htab->plt_eh_frame->output_section != NULL)
5884 bfd_vma plt_start = htab->elf.splt->output_section->vma;
5885 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
5886 + htab->plt_eh_frame->output_offset
5887 + PLT_FDE_START_OFFSET;
5888 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5889 htab->plt_eh_frame->contents
5890 + PLT_FDE_START_OFFSET);
5892 if (htab->plt_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
5894 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5896 htab->plt_eh_frame->contents))
5901 /* Adjust .eh_frame for .plt.got section. */
5902 if (htab->plt_got_eh_frame != NULL
5903 && htab->plt_got_eh_frame->contents != NULL)
5905 if (htab->plt_got != NULL
5906 && htab->plt_got->size != 0
5907 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
5908 && htab->plt_got->output_section != NULL
5909 && htab->plt_got_eh_frame->output_section != NULL)
5911 bfd_vma plt_start = htab->plt_got->output_section->vma;
5912 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
5913 + htab->plt_got_eh_frame->output_offset
5914 + PLT_FDE_START_OFFSET;
5915 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5916 htab->plt_got_eh_frame->contents
5917 + PLT_FDE_START_OFFSET);
5919 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
5921 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5922 htab->plt_got_eh_frame,
5923 htab->plt_got_eh_frame->contents))
5928 /* Adjust .eh_frame for the second PLT section. */
5929 if (htab->plt_second_eh_frame != NULL
5930 && htab->plt_second_eh_frame->contents != NULL)
5932 if (htab->plt_second != NULL
5933 && htab->plt_second->size != 0
5934 && (htab->plt_second->flags & SEC_EXCLUDE) == 0
5935 && htab->plt_second->output_section != NULL
5936 && htab->plt_second_eh_frame->output_section != NULL)
5938 bfd_vma plt_start = htab->plt_second->output_section->vma;
5939 bfd_vma eh_frame_start
5940 = (htab->plt_second_eh_frame->output_section->vma
5941 + htab->plt_second_eh_frame->output_offset
5942 + PLT_FDE_START_OFFSET);
5943 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
5944 htab->plt_second_eh_frame->contents
5945 + PLT_FDE_START_OFFSET);
5947 if (htab->plt_second_eh_frame->sec_info_type
5948 == SEC_INFO_TYPE_EH_FRAME)
5950 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
5951 htab->plt_second_eh_frame,
5952 htab->plt_second_eh_frame->contents))
5957 if (htab->elf.sgot && htab->elf.sgot->size > 0)
5958 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
5961 /* Fill PLT entries for undefined weak symbols in PIE. */
5962 if (bfd_link_pie (info))
5963 bfd_hash_traverse (&info->hash->table,
5964 elf_x86_64_pie_finish_undefweak_symbol,
5970 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5971 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5972 It has to be done before elf_link_sort_relocs is called so that
5973 dynamic relocations are properly sorted. */
5976 elf_x86_64_output_arch_local_syms
5977 (bfd *output_bfd ATTRIBUTE_UNUSED,
5978 struct bfd_link_info *info,
5979 void *flaginfo ATTRIBUTE_UNUSED,
5980 int (*func) (void *, const char *,
5983 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
5985 struct elf_x86_link_hash_table *htab
5986 = elf_x86_hash_table (info, X86_64_ELF_DATA);
5990 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5991 htab_traverse (htab->loc_hash_table,
5992 elf_x86_64_finish_local_dynamic_symbol,
5998 enum elf_x86_64_plt_type
6002 plt_second = 1 << 1,
6006 struct elf_x86_64_plt
6011 enum elf_x86_64_plt_type type;
6012 unsigned int plt_got_offset;
6013 unsigned int plt_got_insn_size;
6014 unsigned int plt_entry_size;
6018 /* Forward declaration. */
6019 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt;
6021 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6022 dynamic relocations. */
6025 elf_x86_64_get_synthetic_symtab (bfd *abfd,
6026 long symcount ATTRIBUTE_UNUSED,
6027 asymbol **syms ATTRIBUTE_UNUSED,
6032 long size, count, i, n, len;
6034 unsigned int plt_got_offset, plt_entry_size, plt_got_insn_size;
6036 bfd_byte *plt_contents;
6037 long dynrelcount, relsize;
6038 arelent **dynrelbuf, *p;
6039 const struct elf_x86_lazy_plt_layout *lazy_plt;
6040 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
6041 const struct elf_x86_lazy_plt_layout *lazy_bnd_plt;
6042 const struct elf_x86_non_lazy_plt_layout *non_lazy_bnd_plt;
6043 const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
6044 const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
6047 enum elf_x86_64_plt_type plt_type;
6048 struct elf_x86_64_plt plts[] =
6050 { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 },
6051 { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 },
6052 { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 },
6053 { ".plt.bnd", NULL, NULL, plt_second, 0, 0, 0, 0 },
6054 { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }
6059 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
6062 if (dynsymcount <= 0)
6065 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
6069 if (get_elf_x86_64_backend_data (abfd)->os == is_normal)
6071 lazy_plt = &elf_x86_64_lazy_plt;
6072 non_lazy_plt = &elf_x86_64_non_lazy_plt;
6073 lazy_bnd_plt = &elf_x86_64_lazy_bnd_plt;
6074 non_lazy_bnd_plt = &elf_x86_64_non_lazy_bnd_plt;
6075 if (ABI_64_P (abfd))
6077 lazy_ibt_plt = &elf_x86_64_lazy_ibt_plt;
6078 non_lazy_ibt_plt = &elf_x86_64_non_lazy_ibt_plt;
6082 lazy_ibt_plt = &elf_x32_lazy_ibt_plt;
6083 non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt;
6088 lazy_plt = &elf_x86_64_nacl_plt;
6089 non_lazy_plt = NULL;
6090 lazy_bnd_plt = NULL;
6091 non_lazy_bnd_plt = NULL;
6092 lazy_ibt_plt = NULL;
6093 non_lazy_ibt_plt = NULL;
6097 for (j = 0; plts[j].name != NULL; j++)
6099 plt = bfd_get_section_by_name (abfd, plts[j].name);
6100 if (plt == NULL || plt->size == 0)
6103 /* Get the PLT section contents. */
6104 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
6105 if (plt_contents == NULL)
6107 if (!bfd_get_section_contents (abfd, (asection *) plt,
6108 plt_contents, 0, plt->size))
6110 free (plt_contents);
6114 /* Check what kind of PLT it is. */
6115 plt_type = plt_unknown;
6116 if (plts[j].type == plt_unknown
6117 && (plt->size >= (lazy_plt->plt_entry_size
6118 + lazy_plt->plt_entry_size)))
6120 /* Match lazy PLT first. Need to check the first two
6122 if ((memcmp (plt_contents, lazy_plt->plt0_entry,
6123 lazy_plt->plt0_got1_offset) == 0)
6124 && (memcmp (plt_contents + 6, lazy_plt->plt0_entry + 6,
6126 plt_type = plt_lazy;
6127 else if (lazy_bnd_plt != NULL
6128 && (memcmp (plt_contents, lazy_bnd_plt->plt0_entry,
6129 lazy_bnd_plt->plt0_got1_offset) == 0)
6130 && (memcmp (plt_contents + 6,
6131 lazy_bnd_plt->plt0_entry + 6, 3) == 0))
6133 plt_type = plt_lazy | plt_second;
6134 /* The fist entry in the lazy IBT PLT is the same as the
6136 if ((memcmp (plt_contents + lazy_ibt_plt->plt_entry_size,
6137 lazy_ibt_plt->plt_entry,
6138 lazy_ibt_plt->plt_got_offset) == 0))
6139 lazy_plt = lazy_ibt_plt;
6141 lazy_plt = lazy_bnd_plt;
6145 if (non_lazy_plt != NULL
6146 && (plt_type == plt_unknown || plt_type == plt_non_lazy)
6147 && plt->size >= non_lazy_plt->plt_entry_size)
6149 /* Match non-lazy PLT. */
6150 if (memcmp (plt_contents, non_lazy_plt->plt_entry,
6151 non_lazy_plt->plt_got_offset) == 0)
6152 plt_type = plt_non_lazy;
6155 if (plt_type == plt_unknown || plt_type == plt_second)
6157 if (non_lazy_bnd_plt != NULL
6158 && plt->size >= non_lazy_bnd_plt->plt_entry_size
6159 && (memcmp (plt_contents, non_lazy_bnd_plt->plt_entry,
6160 non_lazy_bnd_plt->plt_got_offset) == 0))
6162 /* Match BND PLT. */
6163 plt_type = plt_second;
6164 non_lazy_plt = non_lazy_bnd_plt;
6166 else if (non_lazy_ibt_plt != NULL
6167 && plt->size >= non_lazy_ibt_plt->plt_entry_size
6168 && (memcmp (plt_contents,
6169 non_lazy_ibt_plt->plt_entry,
6170 non_lazy_ibt_plt->plt_got_offset) == 0))
6172 /* Match IBT PLT. */
6173 plt_type = plt_second;
6174 non_lazy_plt = non_lazy_ibt_plt;
6178 if (plt_type == plt_unknown)
6180 free (plt_contents);
6185 plts[j].type = plt_type;
6187 if ((plt_type & plt_lazy))
6189 plts[j].plt_got_offset = lazy_plt->plt_got_offset;
6190 plts[j].plt_got_insn_size = lazy_plt->plt_got_insn_size;
6191 plts[j].plt_entry_size = lazy_plt->plt_entry_size;
6192 /* Skip PLT0 in lazy PLT. */
6197 plts[j].plt_got_offset = non_lazy_plt->plt_got_offset;
6198 plts[j].plt_got_insn_size = non_lazy_plt->plt_got_insn_size;
6199 plts[j].plt_entry_size = non_lazy_plt->plt_entry_size;
6203 /* Skip lazy PLT when the second PLT is used. */
6204 if (plt_type == (plt_lazy | plt_second))
6208 n = plt->size / plts[j].plt_entry_size;
6213 plts[j].contents = plt_contents;
6219 dynrelbuf = (arelent **) bfd_malloc (relsize);
6220 if (dynrelbuf == NULL)
6223 dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf,
6226 /* Sort the relocs by address. */
6227 qsort (dynrelbuf, dynrelcount, sizeof (arelent *),
6228 _bfd_x86_elf_compare_relocs);
6230 size = count * sizeof (asymbol);
6232 /* Allocate space for @plt suffixes. */
6234 for (i = 0; i < dynrelcount; i++)
6237 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
6239 size += sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd);
6242 s = *ret = (asymbol *) bfd_zmalloc (size);
6246 /* Check for each PLT section. */
6247 names = (char *) (s + count);
6250 for (j = 0; plts[j].name != NULL; j++)
6251 if ((plt_contents = plts[j].contents) != NULL)
6256 plt_got_offset = plts[j].plt_got_offset;
6257 plt_got_insn_size = plts[j].plt_got_insn_size;
6258 plt_entry_size = plts[j].plt_entry_size;
6262 if ((plts[j].type & plt_lazy))
6264 /* Skip PLT0 in lazy PLT. */
6266 offset = plt_entry_size;
6274 /* Check each PLT entry against dynamic relocations. */
6275 for (; k < plts[j].count; k++)
6281 /* Get the PC-relative offset, a signed 32-bit integer. */
6282 off = H_GET_32 (abfd, (plt_contents + offset
6284 got_vma = plt->vma + offset + off + plt_got_insn_size;
6286 /* Binary search. */
6290 while ((min + 1) < max)
6294 mid = (min + max) / 2;
6296 if (got_vma > r->address)
6298 else if (got_vma < r->address)
6307 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6308 if (got_vma == p->address
6310 && (p->howto->type == R_X86_64_JUMP_SLOT
6311 || p->howto->type == R_X86_64_GLOB_DAT
6312 || p->howto->type == R_X86_64_IRELATIVE))
6314 *s = **p->sym_ptr_ptr;
6315 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6316 set. Since we are defining a symbol, ensure one
6318 if ((s->flags & BSF_LOCAL) == 0)
6319 s->flags |= BSF_GLOBAL;
6320 s->flags |= BSF_SYNTHETIC;
6321 /* This is no longer a section symbol. */
6322 s->flags &= ~BSF_SECTION_SYM;
6324 s->the_bfd = plt->owner;
6328 len = strlen ((*p->sym_ptr_ptr)->name);
6329 memcpy (names, (*p->sym_ptr_ptr)->name, len);
6335 memcpy (names, "+0x", sizeof ("+0x") - 1);
6336 names += sizeof ("+0x") - 1;
6337 bfd_sprintf_vma (abfd, buf, p->addend);
6338 for (a = buf; *a == '0'; ++a)
6341 memcpy (names, a, size);
6344 memcpy (names, "@plt", sizeof ("@plt"));
6345 names += sizeof ("@plt");
6349 offset += plt_entry_size;
6353 /* PLT entries with R_X86_64_TLSDESC relocations are skipped. */
6362 for (j = 0; plts[j].name != NULL; j++)
6363 if (plts[j].contents != NULL)
6364 free (plts[j].contents);
6371 /* Handle an x86-64 specific section when reading an object file. This
6372 is called when elfcode.h finds a section with an unknown type. */
6375 elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr,
6376 const char *name, int shindex)
6378 if (hdr->sh_type != SHT_X86_64_UNWIND)
6381 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6387 /* Hook called by the linker routine which adds symbols from an object
6388 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6392 elf_x86_64_add_symbol_hook (bfd *abfd,
6393 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6394 Elf_Internal_Sym *sym,
6395 const char **namep ATTRIBUTE_UNUSED,
6396 flagword *flagsp ATTRIBUTE_UNUSED,
6402 switch (sym->st_shndx)
6404 case SHN_X86_64_LCOMMON:
6405 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
6408 lcomm = bfd_make_section_with_flags (abfd,
6412 | SEC_LINKER_CREATED));
6415 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
6418 *valp = sym->st_size;
6426 /* Given a BFD section, try to locate the corresponding ELF section
6430 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
6431 asection *sec, int *index_return)
6433 if (sec == &_bfd_elf_large_com_section)
6435 *index_return = SHN_X86_64_LCOMMON;
6441 /* Process a symbol. */
6444 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
6447 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
6449 switch (elfsym->internal_elf_sym.st_shndx)
6451 case SHN_X86_64_LCOMMON:
6452 asym->section = &_bfd_elf_large_com_section;
6453 asym->value = elfsym->internal_elf_sym.st_size;
6454 /* Common symbol doesn't set BSF_GLOBAL. */
6455 asym->flags &= ~BSF_GLOBAL;
6461 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
6463 return (sym->st_shndx == SHN_COMMON
6464 || sym->st_shndx == SHN_X86_64_LCOMMON);
6468 elf_x86_64_common_section_index (asection *sec)
6470 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6473 return SHN_X86_64_LCOMMON;
6477 elf_x86_64_common_section (asection *sec)
6479 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
6480 return bfd_com_section_ptr;
6482 return &_bfd_elf_large_com_section;
6486 elf_x86_64_merge_symbol (struct elf_link_hash_entry *h,
6487 const Elf_Internal_Sym *sym,
6492 const asection *oldsec)
6494 /* A normal common symbol and a large common symbol result in a
6495 normal common symbol. We turn the large common symbol into a
6498 && h->root.type == bfd_link_hash_common
6500 && bfd_is_com_section (*psec)
6503 if (sym->st_shndx == SHN_COMMON
6504 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) != 0)
6506 h->root.u.c.p->section
6507 = bfd_make_section_old_way (oldbfd, "COMMON");
6508 h->root.u.c.p->section->flags = SEC_ALLOC;
6510 else if (sym->st_shndx == SHN_X86_64_LCOMMON
6511 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) == 0)
6512 *psec = bfd_com_section_ptr;
6519 elf_x86_64_additional_program_headers (bfd *abfd,
6520 struct bfd_link_info *info ATTRIBUTE_UNUSED)
6525 /* Check to see if we need a large readonly segment. */
6526 s = bfd_get_section_by_name (abfd, ".lrodata");
6527 if (s && (s->flags & SEC_LOAD))
6530 /* Check to see if we need a large data segment. Since .lbss sections
6531 is placed right after the .bss section, there should be no need for
6532 a large data segment just because of .lbss. */
6533 s = bfd_get_section_by_name (abfd, ".ldata");
6534 if (s && (s->flags & SEC_LOAD))
6540 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6543 elf_x86_64_relocs_compatible (const bfd_target *input,
6544 const bfd_target *output)
6546 return ((xvec_get_elf_backend_data (input)->s->elfclass
6547 == xvec_get_elf_backend_data (output)->s->elfclass)
6548 && _bfd_elf_relocs_compatible (input, output));
6551 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
6552 with GNU properties if found. Otherwise, return NULL. */
6555 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
6557 bfd_boolean normal_target;
6558 bfd_boolean lazy_plt;
6559 asection *sec, *pltsec;
6561 bfd_boolean use_ibt_plt;
6562 unsigned int plt_alignment, features;
6563 struct elf_x86_link_hash_table *htab;
6570 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
6572 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
6574 /* Find a normal input file with GNU property note. */
6575 for (pbfd = info->input_bfds;
6577 pbfd = pbfd->link.next)
6578 if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
6579 && bfd_count_sections (pbfd) != 0)
6583 if (elf_properties (pbfd) != NULL)
6587 if (ebfd != NULL && features)
6589 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
6590 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
6591 prop = _bfd_elf_get_property (ebfd,
6592 GNU_PROPERTY_X86_FEATURE_1_AND,
6594 prop->u.number |= features;
6595 prop->pr_kind = property_number;
6597 /* Create the GNU property note section if needed. */
6600 sec = bfd_make_section_with_flags (ebfd,
6601 NOTE_GNU_PROPERTY_SECTION_NAME,
6609 info->callbacks->einfo (_("%F: failed to create GNU property section\n"));
6611 if (!bfd_set_section_alignment (ebfd, sec,
6612 ABI_64_P (ebfd) ? 3 : 2))
6615 info->callbacks->einfo (_("%F%A: failed to align section\n"),
6619 elf_section_type (sec) = SHT_NOTE;
6623 pbfd = _bfd_elf_link_setup_gnu_properties (info);
6625 if (bfd_link_relocatable (info))
6628 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
6632 use_ibt_plt = info->ibtplt || info->ibt;
6633 if (!use_ibt_plt && pbfd != NULL)
6635 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
6636 elf_property_list *p;
6638 /* The property list is sorted in order of type. */
6639 for (p = elf_properties (pbfd); p; p = p->next)
6641 if (GNU_PROPERTY_X86_FEATURE_1_AND == p->property.pr_type)
6643 use_ibt_plt = !!(p->property.u.number
6644 & GNU_PROPERTY_X86_FEATURE_1_IBT);
6647 else if (GNU_PROPERTY_X86_FEATURE_1_AND < p->property.pr_type)
6652 dynobj = htab->elf.dynobj;
6654 /* Set htab->elf.dynobj here so that there is no need to check and
6655 set it in check_relocs. */
6660 htab->elf.dynobj = pbfd;
6667 /* Find a normal input file to hold linker created
6669 for (abfd = info->input_bfds;
6671 abfd = abfd->link.next)
6672 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
6674 & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0)
6676 htab->elf.dynobj = abfd;
6683 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
6684 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
6685 canonical function address. */
6686 htab->plt.has_plt0 = 1;
6688 if (get_elf_x86_64_backend_data (info->output_bfd)->os
6693 if (ABI_64_P (dynobj))
6696 = &elf_x86_64_lazy_ibt_plt;
6698 = &elf_x86_64_non_lazy_ibt_plt;
6703 = &elf_x32_lazy_ibt_plt;
6705 = &elf_x32_non_lazy_ibt_plt;
6708 else if (info->bndplt)
6710 htab->lazy_plt = &elf_x86_64_lazy_bnd_plt;
6711 htab->non_lazy_plt = &elf_x86_64_non_lazy_bnd_plt;
6715 htab->lazy_plt = &elf_x86_64_lazy_plt;
6716 htab->non_lazy_plt = &elf_x86_64_non_lazy_plt;
6718 normal_target = TRUE;
6722 htab->lazy_plt = &elf_x86_64_nacl_plt;
6723 htab->non_lazy_plt = NULL;
6724 normal_target = FALSE;
6727 pltsec = htab->elf.splt;
6729 /* If the non-lazy PLT is available, use it for all PLT entries if
6730 there are no PLT0 or no .plt section. */
6731 if (htab->non_lazy_plt != NULL
6732 && (!htab->plt.has_plt0 || pltsec == NULL))
6735 htab->plt.plt_entry = htab->non_lazy_plt->plt_entry;
6736 htab->plt.plt_entry_size = htab->non_lazy_plt->plt_entry_size;
6737 htab->plt.plt_got_offset = htab->non_lazy_plt->plt_got_offset;
6738 htab->plt.plt_got_insn_size
6739 = htab->non_lazy_plt->plt_got_insn_size;
6740 htab->plt.eh_frame_plt_size
6741 = htab->non_lazy_plt->eh_frame_plt_size;
6742 htab->plt.eh_frame_plt = htab->non_lazy_plt->eh_frame_plt;
6747 htab->plt.plt_entry = htab->lazy_plt->plt_entry;
6748 htab->plt.plt_entry_size = htab->lazy_plt->plt_entry_size;
6749 htab->plt.plt_got_offset = htab->lazy_plt->plt_got_offset;
6750 htab->plt.plt_got_insn_size
6751 = htab->lazy_plt->plt_got_insn_size;
6752 htab->plt.eh_frame_plt_size
6753 = htab->lazy_plt->eh_frame_plt_size;
6754 htab->plt.eh_frame_plt = htab->lazy_plt->eh_frame_plt;
6757 /* This is unused for x86-64. */
6758 htab->plt.plt0_entry = NULL;
6760 /* Return if there are no normal input files. */
6764 /* Since create_dynamic_sections isn't always called, but GOT
6765 relocations need GOT relocations, create them here so that we
6766 don't need to do it in check_relocs. */
6767 if (htab->elf.sgot == NULL
6768 && !_bfd_elf_create_got_section (dynobj, info))
6769 info->callbacks->einfo (_("%F: failed to create GOT sections\n"));
6771 /* Align .got and .got.plt sections to their entry size. Do it here
6772 instead of in create_dynamic_sections so that they are always
6773 properly aligned even if create_dynamic_sections isn't called. */
6774 sec = htab->elf.sgot;
6775 if (!bfd_set_section_alignment (dynobj, sec, 3))
6776 goto error_alignment;
6778 sec = htab->elf.sgotplt;
6779 if (!bfd_set_section_alignment (dynobj, sec, 3))
6780 goto error_alignment;
6782 /* Create the ifunc sections here so that check_relocs can be
6784 if (!_bfd_elf_create_ifunc_sections (dynobj, info))
6785 info->callbacks->einfo (_("%F: failed to create ifunc sections\n"));
6787 plt_alignment = bfd_log2 (htab->plt.plt_entry_size);
6791 /* Whe creating executable, set the contents of the .interp
6792 section to the interpreter. */
6793 if (bfd_link_executable (info) && !info->nointerp)
6795 asection *s = bfd_get_linker_section (dynobj, ".interp");
6798 s->size = htab->dynamic_interpreter_size;
6799 s->contents = (unsigned char *) htab->dynamic_interpreter;
6803 /* Don't change PLT section alignment for NaCl since it uses
6804 64-byte PLT entry and sets PLT section alignment to 32
6805 bytes. Don't create additional PLT sections for NaCl. */
6808 const struct elf_backend_data *bed
6809 = get_elf_backend_data (dynobj);
6810 flagword pltflags = (bed->dynamic_sec_flags
6815 unsigned int non_lazy_plt_alignment
6816 = bfd_log2 (htab->non_lazy_plt->plt_entry_size);
6819 if (!bfd_set_section_alignment (sec->owner, sec,
6821 goto error_alignment;
6823 /* Create the GOT procedure linkage table. */
6824 sec = bfd_make_section_anyway_with_flags (dynobj,
6828 info->callbacks->einfo (_("%F: failed to create GOT PLT section\n"));
6830 if (!bfd_set_section_alignment (dynobj, sec,
6831 non_lazy_plt_alignment))
6832 goto error_alignment;
6834 htab->plt_got = sec;
6842 /* Create the second PLT for Intel IBT support. IBT
6843 PLT is supported only for non-NaCl target and is
6844 is needed only for lazy binding. */
6845 sec = bfd_make_section_anyway_with_flags (dynobj,
6849 info->callbacks->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
6851 if (!bfd_set_section_alignment (dynobj, sec,
6853 goto error_alignment;
6855 else if (info->bndplt && ABI_64_P (dynobj))
6857 /* Create the second PLT for Intel MPX support. MPX
6858 PLT is supported only for non-NaCl target in 64-bit
6859 mode and is needed only for lazy binding. */
6860 sec = bfd_make_section_anyway_with_flags (dynobj,
6864 info->callbacks->einfo (_("%F: failed to create BND PLT section\n"));
6866 if (!bfd_set_section_alignment (dynobj, sec,
6867 non_lazy_plt_alignment))
6868 goto error_alignment;
6871 htab->plt_second = sec;
6875 if (!info->no_ld_generated_unwind_info)
6877 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
6878 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
6879 | SEC_LINKER_CREATED);
6881 sec = bfd_make_section_anyway_with_flags (dynobj,
6885 info->callbacks->einfo (_("%F: failed to create PLT .eh_frame section\n"));
6887 if (!bfd_set_section_alignment (dynobj, sec,
6888 ABI_64_P (dynobj) ? 3 : 2))
6889 goto error_alignment;
6891 htab->plt_eh_frame = sec;
6893 if (htab->plt_got != NULL)
6895 sec = bfd_make_section_anyway_with_flags (dynobj,
6899 info->callbacks->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
6901 if (!bfd_set_section_alignment (dynobj, sec,
6902 ABI_64_P (dynobj) ? 3 : 2))
6903 goto error_alignment;
6905 htab->plt_got_eh_frame = sec;
6908 if (htab->plt_second != NULL)
6910 sec = bfd_make_section_anyway_with_flags (dynobj,
6914 info->callbacks->einfo (_("%F: failed to create BND PLT .eh_frame section\n"));
6916 if (!bfd_set_section_alignment (dynobj, sec, 3))
6917 goto error_alignment;
6919 htab->plt_second_eh_frame = sec;
6926 /* The .iplt section is used for IFUNC symbols in static
6928 sec = htab->elf.iplt;
6930 && !bfd_set_section_alignment (sec->owner, sec,
6932 goto error_alignment;
6938 static const struct bfd_elf_special_section
6939 elf_x86_64_special_sections[]=
6941 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6942 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6943 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
6944 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6945 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
6946 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
6947 { NULL, 0, 0, 0, 0 }
6950 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6951 #define TARGET_LITTLE_NAME "elf64-x86-64"
6952 #define ELF_ARCH bfd_arch_i386
6953 #define ELF_TARGET_ID X86_64_ELF_DATA
6954 #define ELF_MACHINE_CODE EM_X86_64
6955 #define ELF_MAXPAGESIZE 0x200000
6956 #define ELF_MINPAGESIZE 0x1000
6957 #define ELF_COMMONPAGESIZE 0x1000
6959 #define elf_backend_can_gc_sections 1
6960 #define elf_backend_can_refcount 1
6961 #define elf_backend_want_got_plt 1
6962 #define elf_backend_plt_readonly 1
6963 #define elf_backend_want_plt_sym 0
6964 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6965 #define elf_backend_rela_normal 1
6966 #define elf_backend_plt_alignment 4
6967 #define elf_backend_extern_protected_data 1
6968 #define elf_backend_caches_rawsize 1
6969 #define elf_backend_dtrel_excludes_plt 1
6970 #define elf_backend_want_dynrelro 1
6972 #define elf_info_to_howto elf_x86_64_info_to_howto
6974 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
6975 #define bfd_elf64_bfd_reloc_name_lookup \
6976 elf_x86_64_reloc_name_lookup
6978 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
6979 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
6980 #define elf_backend_check_relocs elf_x86_64_check_relocs
6981 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
6982 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
6983 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
6984 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
6985 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
6986 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
6987 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
6989 #define elf_backend_write_core_note elf_x86_64_write_core_note
6991 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
6992 #define elf_backend_relocate_section elf_x86_64_relocate_section
6993 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
6994 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
6995 #define elf_backend_object_p elf64_x86_64_elf_object_p
6996 #define bfd_elf64_mkobject elf_x86_64_mkobject
6997 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
6999 #define elf_backend_section_from_shdr \
7000 elf_x86_64_section_from_shdr
7002 #define elf_backend_section_from_bfd_section \
7003 elf_x86_64_elf_section_from_bfd_section
7004 #define elf_backend_add_symbol_hook \
7005 elf_x86_64_add_symbol_hook
7006 #define elf_backend_symbol_processing \
7007 elf_x86_64_symbol_processing
7008 #define elf_backend_common_section_index \
7009 elf_x86_64_common_section_index
7010 #define elf_backend_common_section \
7011 elf_x86_64_common_section
7012 #define elf_backend_common_definition \
7013 elf_x86_64_common_definition
7014 #define elf_backend_merge_symbol \
7015 elf_x86_64_merge_symbol
7016 #define elf_backend_special_sections \
7017 elf_x86_64_special_sections
7018 #define elf_backend_additional_program_headers \
7019 elf_x86_64_additional_program_headers
7020 #define elf_backend_setup_gnu_properties \
7021 elf_x86_64_link_setup_gnu_properties
7023 #include "elf64-target.h"
7025 /* CloudABI support. */
7027 #undef TARGET_LITTLE_SYM
7028 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7029 #undef TARGET_LITTLE_NAME
7030 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7033 #define ELF_OSABI ELFOSABI_CLOUDABI
7036 #define elf64_bed elf64_x86_64_cloudabi_bed
7038 #include "elf64-target.h"
7040 /* FreeBSD support. */
7042 #undef TARGET_LITTLE_SYM
7043 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7044 #undef TARGET_LITTLE_NAME
7045 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7048 #define ELF_OSABI ELFOSABI_FREEBSD
7051 #define elf64_bed elf64_x86_64_fbsd_bed
7053 #include "elf64-target.h"
7055 /* Solaris 2 support. */
7057 #undef TARGET_LITTLE_SYM
7058 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7059 #undef TARGET_LITTLE_NAME
7060 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7062 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7063 objects won't be recognized. */
7067 #define elf64_bed elf64_x86_64_sol2_bed
7069 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7071 #undef elf_backend_static_tls_alignment
7072 #define elf_backend_static_tls_alignment 16
7074 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7076 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7078 #undef elf_backend_want_plt_sym
7079 #define elf_backend_want_plt_sym 1
7081 #undef elf_backend_strtab_flags
7082 #define elf_backend_strtab_flags SHF_STRINGS
7085 elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
7086 bfd *obfd ATTRIBUTE_UNUSED,
7087 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
7088 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
7090 /* PR 19938: FIXME: Need to add code for setting the sh_info
7091 and sh_link fields of Solaris specific section types. */
7095 #undef elf_backend_copy_special_section_fields
7096 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7098 #include "elf64-target.h"
7100 /* Native Client support. */
7103 elf64_x86_64_nacl_elf_object_p (bfd *abfd)
7105 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7106 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64_nacl);
7110 #undef TARGET_LITTLE_SYM
7111 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7112 #undef TARGET_LITTLE_NAME
7113 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7115 #define elf64_bed elf64_x86_64_nacl_bed
7117 #undef ELF_MAXPAGESIZE
7118 #undef ELF_MINPAGESIZE
7119 #undef ELF_COMMONPAGESIZE
7120 #define ELF_MAXPAGESIZE 0x10000
7121 #define ELF_MINPAGESIZE 0x10000
7122 #define ELF_COMMONPAGESIZE 0x10000
7124 /* Restore defaults. */
7126 #undef elf_backend_static_tls_alignment
7127 #undef elf_backend_want_plt_sym
7128 #define elf_backend_want_plt_sym 0
7129 #undef elf_backend_strtab_flags
7130 #undef elf_backend_copy_special_section_fields
7132 /* NaCl uses substantially different PLT entries for the same effects. */
7134 #undef elf_backend_plt_alignment
7135 #define elf_backend_plt_alignment 5
7136 #define NACL_PLT_ENTRY_SIZE 64
7137 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7139 static const bfd_byte elf_x86_64_nacl_plt0_entry[NACL_PLT_ENTRY_SIZE] =
7141 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7142 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7143 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7144 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7145 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7147 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7148 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7150 /* 32 bytes of nop to pad out to the standard size. */
7151 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7152 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7153 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7154 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7155 0x66, /* excess data16 prefix */
7159 static const bfd_byte elf_x86_64_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
7161 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7162 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
7163 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7164 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7166 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7167 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7168 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7170 /* Lazy GOT entries point here (32-byte aligned). */
7171 0x68, /* pushq immediate */
7172 0, 0, 0, 0, /* replaced with index into relocation table. */
7173 0xe9, /* jmp relative */
7174 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7176 /* 22 bytes of nop to pad out to the standard size. */
7177 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7178 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7179 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7182 /* .eh_frame covering the .plt section. */
7184 static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] =
7186 #if (PLT_CIE_LENGTH != 20 \
7187 || PLT_FDE_LENGTH != 36 \
7188 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7189 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7190 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7192 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
7193 0, 0, 0, 0, /* CIE ID */
7194 1, /* CIE version */
7195 'z', 'R', 0, /* Augmentation string */
7196 1, /* Code alignment factor */
7197 0x78, /* Data alignment factor */
7198 16, /* Return address column */
7199 1, /* Augmentation size */
7200 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
7201 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7202 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7203 DW_CFA_nop, DW_CFA_nop,
7205 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
7206 PLT_CIE_LENGTH + 8, 0, 0, 0,/* CIE pointer */
7207 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7208 0, 0, 0, 0, /* .plt size goes here */
7209 0, /* Augmentation size */
7210 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
7211 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7212 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
7213 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7214 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
7215 13, /* Block length */
7216 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
7217 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
7218 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
7219 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
7220 DW_CFA_nop, DW_CFA_nop
7223 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt =
7225 elf_x86_64_nacl_plt0_entry, /* plt0_entry */
7226 NACL_PLT_ENTRY_SIZE, /* plt0_entry_size */
7227 elf_x86_64_nacl_plt_entry, /* plt_entry */
7228 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
7229 2, /* plt0_got1_offset */
7230 9, /* plt0_got2_offset */
7231 13, /* plt0_got2_insn_end */
7232 3, /* plt_got_offset */
7233 33, /* plt_reloc_offset */
7234 38, /* plt_plt_offset */
7235 7, /* plt_got_insn_size */
7236 42, /* plt_plt_insn_end */
7237 32, /* plt_lazy_offset */
7238 NULL, /* pic_plt0_entry */
7239 NULL, /* pic_plt_entry */
7240 elf_x86_64_nacl_eh_frame_plt, /* eh_frame_plt */
7241 sizeof (elf_x86_64_nacl_eh_frame_plt) /* eh_frame_plt_size */
7244 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed =
7249 #undef elf_backend_arch_data
7250 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7252 #undef elf_backend_object_p
7253 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7254 #undef elf_backend_modify_segment_map
7255 #define elf_backend_modify_segment_map nacl_modify_segment_map
7256 #undef elf_backend_modify_program_headers
7257 #define elf_backend_modify_program_headers nacl_modify_program_headers
7258 #undef elf_backend_final_write_processing
7259 #define elf_backend_final_write_processing nacl_final_write_processing
7261 #include "elf64-target.h"
7263 /* Native Client x32 support. */
7266 elf32_x86_64_nacl_elf_object_p (bfd *abfd)
7268 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7269 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32_nacl);
7273 #undef TARGET_LITTLE_SYM
7274 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7275 #undef TARGET_LITTLE_NAME
7276 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7278 #define elf32_bed elf32_x86_64_nacl_bed
7280 #define bfd_elf32_bfd_reloc_type_lookup \
7281 elf_x86_64_reloc_type_lookup
7282 #define bfd_elf32_bfd_reloc_name_lookup \
7283 elf_x86_64_reloc_name_lookup
7284 #define bfd_elf32_mkobject \
7286 #define bfd_elf32_get_synthetic_symtab \
7287 elf_x86_64_get_synthetic_symtab
7289 #undef elf_backend_object_p
7290 #define elf_backend_object_p \
7291 elf32_x86_64_nacl_elf_object_p
7293 #undef elf_backend_bfd_from_remote_memory
7294 #define elf_backend_bfd_from_remote_memory \
7295 _bfd_elf32_bfd_from_remote_memory
7297 #undef elf_backend_size_info
7298 #define elf_backend_size_info \
7299 _bfd_elf32_size_info
7301 #include "elf32-target.h"
7303 /* Restore defaults. */
7304 #undef elf_backend_object_p
7305 #define elf_backend_object_p elf64_x86_64_elf_object_p
7306 #undef elf_backend_bfd_from_remote_memory
7307 #undef elf_backend_size_info
7308 #undef elf_backend_modify_segment_map
7309 #undef elf_backend_modify_program_headers
7310 #undef elf_backend_final_write_processing
7312 /* Intel L1OM support. */
7315 elf64_l1om_elf_object_p (bfd *abfd)
7317 /* Set the right machine number for an L1OM elf64 file. */
7318 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
7322 #undef TARGET_LITTLE_SYM
7323 #define TARGET_LITTLE_SYM l1om_elf64_vec
7324 #undef TARGET_LITTLE_NAME
7325 #define TARGET_LITTLE_NAME "elf64-l1om"
7327 #define ELF_ARCH bfd_arch_l1om
7329 #undef ELF_MACHINE_CODE
7330 #define ELF_MACHINE_CODE EM_L1OM
7335 #define elf64_bed elf64_l1om_bed
7337 #undef elf_backend_object_p
7338 #define elf_backend_object_p elf64_l1om_elf_object_p
7340 /* Restore defaults. */
7341 #undef ELF_MAXPAGESIZE
7342 #undef ELF_MINPAGESIZE
7343 #undef ELF_COMMONPAGESIZE
7344 #define ELF_MAXPAGESIZE 0x200000
7345 #define ELF_MINPAGESIZE 0x1000
7346 #define ELF_COMMONPAGESIZE 0x1000
7347 #undef elf_backend_plt_alignment
7348 #define elf_backend_plt_alignment 4
7349 #undef elf_backend_arch_data
7350 #define elf_backend_arch_data &elf_x86_64_arch_bed
7352 #include "elf64-target.h"
7354 /* FreeBSD L1OM support. */
7356 #undef TARGET_LITTLE_SYM
7357 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7358 #undef TARGET_LITTLE_NAME
7359 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7362 #define ELF_OSABI ELFOSABI_FREEBSD
7365 #define elf64_bed elf64_l1om_fbsd_bed
7367 #include "elf64-target.h"
7369 /* Intel K1OM support. */
7372 elf64_k1om_elf_object_p (bfd *abfd)
7374 /* Set the right machine number for an K1OM elf64 file. */
7375 bfd_default_set_arch_mach (abfd, bfd_arch_k1om, bfd_mach_k1om);
7379 #undef TARGET_LITTLE_SYM
7380 #define TARGET_LITTLE_SYM k1om_elf64_vec
7381 #undef TARGET_LITTLE_NAME
7382 #define TARGET_LITTLE_NAME "elf64-k1om"
7384 #define ELF_ARCH bfd_arch_k1om
7386 #undef ELF_MACHINE_CODE
7387 #define ELF_MACHINE_CODE EM_K1OM
7392 #define elf64_bed elf64_k1om_bed
7394 #undef elf_backend_object_p
7395 #define elf_backend_object_p elf64_k1om_elf_object_p
7397 #undef elf_backend_static_tls_alignment
7399 #undef elf_backend_want_plt_sym
7400 #define elf_backend_want_plt_sym 0
7402 #include "elf64-target.h"
7404 /* FreeBSD K1OM support. */
7406 #undef TARGET_LITTLE_SYM
7407 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7408 #undef TARGET_LITTLE_NAME
7409 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7412 #define ELF_OSABI ELFOSABI_FREEBSD
7415 #define elf64_bed elf64_k1om_fbsd_bed
7417 #include "elf64-target.h"
7419 /* 32bit x86-64 support. */
7421 #undef TARGET_LITTLE_SYM
7422 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7423 #undef TARGET_LITTLE_NAME
7424 #define TARGET_LITTLE_NAME "elf32-x86-64"
7428 #define ELF_ARCH bfd_arch_i386
7430 #undef ELF_MACHINE_CODE
7431 #define ELF_MACHINE_CODE EM_X86_64
7435 #undef elf_backend_object_p
7436 #define elf_backend_object_p \
7437 elf32_x86_64_elf_object_p
7439 #undef elf_backend_bfd_from_remote_memory
7440 #define elf_backend_bfd_from_remote_memory \
7441 _bfd_elf32_bfd_from_remote_memory
7443 #undef elf_backend_size_info
7444 #define elf_backend_size_info \
7445 _bfd_elf32_size_info
7447 #include "elf32-target.h"