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 /* Set if a relocation is converted from a GOTPCREL relocation. */
200 #define R_X86_64_converted_reloc_bit (1 << 7)
202 #define IS_X86_64_PCREL_TYPE(TYPE) \
203 ( ((TYPE) == R_X86_64_PC8) \
204 || ((TYPE) == R_X86_64_PC16) \
205 || ((TYPE) == R_X86_64_PC32) \
206 || ((TYPE) == R_X86_64_PC32_BND) \
207 || ((TYPE) == R_X86_64_PC64))
209 /* Map BFD relocs to the x86_64 elf relocs. */
212 bfd_reloc_code_real_type bfd_reloc_val;
213 unsigned char elf_reloc_val;
216 static const struct elf_reloc_map x86_64_reloc_map[] =
218 { BFD_RELOC_NONE, R_X86_64_NONE, },
219 { BFD_RELOC_64, R_X86_64_64, },
220 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
221 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
222 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
223 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
224 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
225 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
226 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
227 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
228 { BFD_RELOC_32, R_X86_64_32, },
229 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
230 { BFD_RELOC_16, R_X86_64_16, },
231 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
232 { BFD_RELOC_8, R_X86_64_8, },
233 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
234 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
235 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
236 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
237 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
238 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
239 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
240 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
241 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
242 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
243 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
244 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
245 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
246 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
247 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
248 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
249 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
250 { BFD_RELOC_SIZE32, R_X86_64_SIZE32, },
251 { BFD_RELOC_SIZE64, R_X86_64_SIZE64, },
252 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
253 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
254 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
255 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
256 { BFD_RELOC_X86_64_PC32_BND, R_X86_64_PC32_BND, },
257 { BFD_RELOC_X86_64_PLT32_BND, R_X86_64_PLT32_BND, },
258 { BFD_RELOC_X86_64_GOTPCRELX, R_X86_64_GOTPCRELX, },
259 { BFD_RELOC_X86_64_REX_GOTPCRELX, R_X86_64_REX_GOTPCRELX, },
260 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
261 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
264 static reloc_howto_type *
265 elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
269 if (r_type == (unsigned int) R_X86_64_32)
274 i = ARRAY_SIZE (x86_64_elf_howto_table) - 1;
276 else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
277 || r_type >= (unsigned int) R_X86_64_max)
279 if (r_type >= (unsigned int) R_X86_64_standard)
281 /* xgettext:c-format */
282 _bfd_error_handler (_("%B: invalid relocation type %d"),
284 r_type = R_X86_64_NONE;
289 i = r_type - (unsigned int) R_X86_64_vt_offset;
290 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
291 return &x86_64_elf_howto_table[i];
294 /* Given a BFD reloc type, return a HOWTO structure. */
295 static reloc_howto_type *
296 elf_x86_64_reloc_type_lookup (bfd *abfd,
297 bfd_reloc_code_real_type code)
301 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
304 if (x86_64_reloc_map[i].bfd_reloc_val == code)
305 return elf_x86_64_rtype_to_howto (abfd,
306 x86_64_reloc_map[i].elf_reloc_val);
311 static reloc_howto_type *
312 elf_x86_64_reloc_name_lookup (bfd *abfd,
317 if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0)
319 /* Get x32 R_X86_64_32. */
320 reloc_howto_type *reloc
321 = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1];
322 BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32);
326 for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++)
327 if (x86_64_elf_howto_table[i].name != NULL
328 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
329 return &x86_64_elf_howto_table[i];
334 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
337 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
338 Elf_Internal_Rela *dst)
342 r_type = ELF32_R_TYPE (dst->r_info);
343 if (r_type != (unsigned int) R_X86_64_GNU_VTINHERIT
344 && r_type != (unsigned int) R_X86_64_GNU_VTENTRY)
345 r_type &= ~R_X86_64_converted_reloc_bit;
346 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
347 BFD_ASSERT (r_type == cache_ptr->howto->type);
350 /* Support for core dump NOTE sections. */
352 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
357 switch (note->descsz)
362 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
364 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
367 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
375 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
377 elf_tdata (abfd)->core->signal
378 = bfd_get_16 (abfd, note->descdata + 12);
381 elf_tdata (abfd)->core->lwpid
382 = bfd_get_32 (abfd, note->descdata + 32);
391 /* Make a ".reg/999" section. */
392 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
393 size, note->descpos + offset);
397 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
399 switch (note->descsz)
404 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
405 elf_tdata (abfd)->core->pid
406 = bfd_get_32 (abfd, note->descdata + 12);
407 elf_tdata (abfd)->core->program
408 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
409 elf_tdata (abfd)->core->command
410 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
413 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
414 elf_tdata (abfd)->core->pid
415 = bfd_get_32 (abfd, note->descdata + 24);
416 elf_tdata (abfd)->core->program
417 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
418 elf_tdata (abfd)->core->command
419 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
422 /* Note that for some reason, a spurious space is tacked
423 onto the end of the args in some (at least one anyway)
424 implementations, so strip it off if it exists. */
427 char *command = elf_tdata (abfd)->core->command;
428 int n = strlen (command);
430 if (0 < n && command[n - 1] == ' ')
431 command[n - 1] = '\0';
439 elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz,
442 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
444 const char *fname, *psargs;
455 va_start (ap, note_type);
456 fname = va_arg (ap, const char *);
457 psargs = va_arg (ap, const char *);
460 if (bed->s->elfclass == ELFCLASS32)
463 memset (&data, 0, sizeof (data));
464 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
465 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
466 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
467 &data, sizeof (data));
472 memset (&data, 0, sizeof (data));
473 strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
474 strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
475 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
476 &data, sizeof (data));
481 va_start (ap, note_type);
482 pid = va_arg (ap, long);
483 cursig = va_arg (ap, int);
484 gregs = va_arg (ap, const void *);
487 if (bed->s->elfclass == ELFCLASS32)
489 if (bed->elf_machine_code == EM_X86_64)
491 prstatusx32_t prstat;
492 memset (&prstat, 0, sizeof (prstat));
494 prstat.pr_cursig = cursig;
495 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
496 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
497 &prstat, sizeof (prstat));
502 memset (&prstat, 0, sizeof (prstat));
504 prstat.pr_cursig = cursig;
505 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
506 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
507 &prstat, sizeof (prstat));
513 memset (&prstat, 0, sizeof (prstat));
515 prstat.pr_cursig = cursig;
516 memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
517 return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
518 &prstat, sizeof (prstat));
525 /* Functions for the x86-64 ELF linker. */
527 /* The size in bytes of an entry in the global offset table. */
529 #define GOT_ENTRY_SIZE 8
531 /* The size in bytes of an entry in the lazy procedure linkage table. */
533 #define LAZY_PLT_ENTRY_SIZE 16
535 /* The size in bytes of an entry in the non-lazy procedure linkage
538 #define NON_LAZY_PLT_ENTRY_SIZE 8
540 /* The first entry in a lazy procedure linkage table looks like this.
541 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
544 static const bfd_byte elf_x86_64_lazy_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
546 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
547 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
548 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
551 /* Subsequent entries in a lazy procedure linkage table look like this. */
553 static const bfd_byte elf_x86_64_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
555 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
556 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
557 0x68, /* pushq immediate */
558 0, 0, 0, 0, /* replaced with index into relocation table. */
559 0xe9, /* jmp relative */
560 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
563 /* The first entry in a lazy procedure linkage table with BND prefix
566 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
568 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
569 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
570 0x0f, 0x1f, 0 /* nopl (%rax) */
573 /* Subsequent entries for branches with BND prefx in a lazy procedure
574 linkage table look like this. */
576 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry[LAZY_PLT_ENTRY_SIZE] =
578 0x68, 0, 0, 0, 0, /* pushq immediate */
579 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
580 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
583 /* The first entry in the IBT-enabled lazy procedure linkage table is the
584 the same as the lazy PLT with BND prefix so that bound registers are
585 preserved when control is passed to dynamic linker. Subsequent
586 entries for a IBT-enabled lazy procedure linkage table look like
589 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
591 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
592 0x68, 0, 0, 0, 0, /* pushq immediate */
593 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
597 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
598 is the same as the normal lazy PLT. Subsequent entries for an
599 x32 IBT-enabled lazy procedure linkage table look like this. */
601 static const bfd_byte elf_x32_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
603 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
604 0x68, 0, 0, 0, 0, /* pushq immediate */
605 0xe9, 0, 0, 0, 0, /* jmpq relative */
606 0x66, 0x90 /* xchg %ax,%ax */
609 /* Entries in the non-lazey procedure linkage table look like this. */
611 static const bfd_byte elf_x86_64_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
613 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
614 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
615 0x66, 0x90 /* xchg %ax,%ax */
618 /* Entries for branches with BND prefix in the non-lazey procedure
619 linkage table look like this. */
621 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
623 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
624 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
628 /* Entries for branches with IBT-enabled in the non-lazey procedure
629 linkage table look like this. They have the same size as the lazy
632 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
634 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
635 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
636 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
637 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
640 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
641 linkage table look like this. They have the same size as the lazy
644 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
646 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
647 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
648 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
649 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
652 /* .eh_frame covering the lazy .plt section. */
654 static const bfd_byte elf_x86_64_eh_frame_lazy_plt[] =
656 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
657 0, 0, 0, 0, /* CIE ID */
659 'z', 'R', 0, /* Augmentation string */
660 1, /* Code alignment factor */
661 0x78, /* Data alignment factor */
662 16, /* Return address column */
663 1, /* Augmentation size */
664 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
665 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
666 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
667 DW_CFA_nop, DW_CFA_nop,
669 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
670 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
671 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
672 0, 0, 0, 0, /* .plt size goes here */
673 0, /* Augmentation size */
674 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
675 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
676 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
677 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
678 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
679 11, /* Block length */
680 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
681 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
682 DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
683 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
684 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
687 /* .eh_frame covering the lazy BND .plt section. */
689 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt[] =
691 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
692 0, 0, 0, 0, /* CIE ID */
694 'z', 'R', 0, /* Augmentation string */
695 1, /* Code alignment factor */
696 0x78, /* Data alignment factor */
697 16, /* Return address column */
698 1, /* Augmentation size */
699 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
700 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
701 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
702 DW_CFA_nop, DW_CFA_nop,
704 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
705 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
706 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
707 0, 0, 0, 0, /* .plt size goes here */
708 0, /* Augmentation size */
709 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
710 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
711 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
712 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
713 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
714 11, /* Block length */
715 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
716 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
717 DW_OP_lit15, DW_OP_and, DW_OP_lit5, DW_OP_ge,
718 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
719 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
722 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
724 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt[] =
726 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
727 0, 0, 0, 0, /* CIE ID */
729 'z', 'R', 0, /* Augmentation string */
730 1, /* Code alignment factor */
731 0x78, /* Data alignment factor */
732 16, /* Return address column */
733 1, /* Augmentation size */
734 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
735 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
736 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
737 DW_CFA_nop, DW_CFA_nop,
739 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
740 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
741 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
742 0, 0, 0, 0, /* .plt size goes here */
743 0, /* Augmentation size */
744 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
745 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
746 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
747 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
748 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
749 11, /* Block length */
750 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
751 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
752 DW_OP_lit15, DW_OP_and, DW_OP_lit10, DW_OP_ge,
753 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
754 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
757 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
759 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt[] =
761 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
762 0, 0, 0, 0, /* CIE ID */
764 'z', 'R', 0, /* Augmentation string */
765 1, /* Code alignment factor */
766 0x78, /* Data alignment factor */
767 16, /* Return address column */
768 1, /* Augmentation size */
769 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
770 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
771 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
772 DW_CFA_nop, DW_CFA_nop,
774 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
775 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
776 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
777 0, 0, 0, 0, /* .plt size goes here */
778 0, /* Augmentation size */
779 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
780 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
781 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
782 DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
783 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
784 11, /* Block length */
785 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
786 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
787 DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge,
788 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
789 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
792 /* .eh_frame covering the non-lazy .plt section. */
794 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt[] =
796 #define PLT_GOT_FDE_LENGTH 20
797 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
798 0, 0, 0, 0, /* CIE ID */
800 'z', 'R', 0, /* Augmentation string */
801 1, /* Code alignment factor */
802 0x78, /* Data alignment factor */
803 16, /* Return address column */
804 1, /* Augmentation size */
805 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
806 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
807 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
808 DW_CFA_nop, DW_CFA_nop,
810 PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
811 PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
812 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
813 0, 0, 0, 0, /* non-lazy .plt size goes here */
814 0, /* Augmentation size */
815 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop,
816 DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
819 /* Architecture-specific backend data for x86-64. */
821 struct elf_x86_64_backend_data
831 #define get_elf_x86_64_arch_data(bed) \
832 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
834 #define get_elf_x86_64_backend_data(abfd) \
835 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
837 /* These are the standard parameters. */
838 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt =
840 elf_x86_64_lazy_plt0_entry, /* plt0_entry */
841 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
842 elf_x86_64_lazy_plt_entry, /* plt_entry */
843 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
844 2, /* plt0_got1_offset */
845 8, /* plt0_got2_offset */
846 12, /* plt0_got2_insn_end */
847 2, /* plt_got_offset */
848 7, /* plt_reloc_offset */
849 12, /* plt_plt_offset */
850 6, /* plt_got_insn_size */
851 LAZY_PLT_ENTRY_SIZE, /* plt_plt_insn_end */
852 6, /* plt_lazy_offset */
853 elf_x86_64_lazy_plt0_entry, /* pic_plt0_entry */
854 elf_x86_64_lazy_plt_entry, /* pic_plt_entry */
855 elf_x86_64_eh_frame_lazy_plt, /* eh_frame_plt */
856 sizeof (elf_x86_64_eh_frame_lazy_plt) /* eh_frame_plt_size */
859 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt =
861 elf_x86_64_non_lazy_plt_entry, /* plt_entry */
862 elf_x86_64_non_lazy_plt_entry, /* pic_plt_entry */
863 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
864 2, /* plt_got_offset */
865 6, /* plt_got_insn_size */
866 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
867 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
870 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt =
872 elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */
873 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
874 elf_x86_64_lazy_bnd_plt_entry, /* plt_entry */
875 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
876 2, /* plt0_got1_offset */
877 1+8, /* plt0_got2_offset */
878 1+12, /* plt0_got2_insn_end */
879 1+2, /* plt_got_offset */
880 1, /* plt_reloc_offset */
881 7, /* plt_plt_offset */
882 1+6, /* plt_got_insn_size */
883 11, /* plt_plt_insn_end */
884 0, /* plt_lazy_offset */
885 elf_x86_64_lazy_bnd_plt0_entry, /* pic_plt0_entry */
886 elf_x86_64_lazy_bnd_plt_entry, /* pic_plt_entry */
887 elf_x86_64_eh_frame_lazy_bnd_plt, /* eh_frame_plt */
888 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt) /* eh_frame_plt_size */
891 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt =
893 elf_x86_64_non_lazy_bnd_plt_entry, /* plt_entry */
894 elf_x86_64_non_lazy_bnd_plt_entry, /* pic_plt_entry */
895 NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
896 1+2, /* plt_got_offset */
897 1+6, /* plt_got_insn_size */
898 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
899 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
902 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt =
904 elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */
905 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
906 elf_x86_64_lazy_ibt_plt_entry, /* plt_entry */
907 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
908 2, /* plt0_got1_offset */
909 1+8, /* plt0_got2_offset */
910 1+12, /* plt0_got2_insn_end */
911 4+1+2, /* plt_got_offset */
912 4+1, /* plt_reloc_offset */
913 4+1+6, /* plt_plt_offset */
914 4+1+6, /* plt_got_insn_size */
915 4+1+5+5, /* plt_plt_insn_end */
916 0, /* plt_lazy_offset */
917 elf_x86_64_lazy_bnd_plt0_entry, /* pic_plt0_entry */
918 elf_x86_64_lazy_ibt_plt_entry, /* pic_plt_entry */
919 elf_x86_64_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
920 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
923 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt =
925 elf_x86_64_lazy_plt0_entry, /* plt0_entry */
926 LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */
927 elf_x32_lazy_ibt_plt_entry, /* plt_entry */
928 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
929 2, /* plt0_got1_offset */
930 8, /* plt0_got2_offset */
931 12, /* plt0_got2_insn_end */
932 4+2, /* plt_got_offset */
933 4+1, /* plt_reloc_offset */
934 4+6, /* plt_plt_offset */
935 4+6, /* plt_got_insn_size */
936 4+5+5, /* plt_plt_insn_end */
937 0, /* plt_lazy_offset */
938 elf_x86_64_lazy_plt0_entry, /* pic_plt0_entry */
939 elf_x32_lazy_ibt_plt_entry, /* pic_plt_entry */
940 elf_x32_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
941 sizeof (elf_x32_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
944 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt =
946 elf_x86_64_non_lazy_ibt_plt_entry, /* plt_entry */
947 elf_x86_64_non_lazy_ibt_plt_entry, /* pic_plt_entry */
948 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
949 4+1+2, /* plt_got_offset */
950 4+1+6, /* plt_got_insn_size */
951 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
952 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
955 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt =
957 elf_x32_non_lazy_ibt_plt_entry, /* plt_entry */
958 elf_x32_non_lazy_ibt_plt_entry, /* pic_plt_entry */
959 LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
960 4+2, /* plt_got_offset */
961 4+6, /* plt_got_insn_size */
962 elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */
963 sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
966 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
971 #define elf_backend_arch_data &elf_x86_64_arch_bed
974 elf64_x86_64_elf_object_p (bfd *abfd)
976 /* Set the right machine number for an x86-64 elf64 file. */
977 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
982 elf32_x86_64_elf_object_p (bfd *abfd)
984 /* Set the right machine number for an x86-64 elf32 file. */
985 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
989 /* Return TRUE if the TLS access code sequence support transition
993 elf_x86_64_check_tls_transition (bfd *abfd,
994 struct bfd_link_info *info,
997 Elf_Internal_Shdr *symtab_hdr,
998 struct elf_link_hash_entry **sym_hashes,
1000 const Elf_Internal_Rela *rel,
1001 const Elf_Internal_Rela *relend)
1004 unsigned long r_symndx;
1005 bfd_boolean largepic = FALSE;
1006 struct elf_link_hash_entry *h;
1008 struct elf_x86_link_hash_table *htab;
1010 bfd_boolean indirect_call;
1012 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1013 offset = rel->r_offset;
1016 case R_X86_64_TLSGD:
1017 case R_X86_64_TLSLD:
1018 if ((rel + 1) >= relend)
1021 if (r_type == R_X86_64_TLSGD)
1023 /* Check transition from GD access model. For 64bit, only
1024 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1025 .word 0x6666; rex64; call __tls_get_addr@PLT
1027 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1029 call *__tls_get_addr@GOTPCREL(%rip)
1030 which may be converted to
1031 addr32 call __tls_get_addr
1032 can transit to different access model. For 32bit, only
1033 leaq foo@tlsgd(%rip), %rdi
1034 .word 0x6666; rex64; call __tls_get_addr@PLT
1036 leaq foo@tlsgd(%rip), %rdi
1038 call *__tls_get_addr@GOTPCREL(%rip)
1039 which may be converted to
1040 addr32 call __tls_get_addr
1041 can transit to different access model. For largepic,
1043 leaq foo@tlsgd(%rip), %rdi
1044 movabsq $__tls_get_addr@pltoff, %rax
1048 leaq foo@tlsgd(%rip), %rdi
1049 movabsq $__tls_get_addr@pltoff, %rax
1053 static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d };
1055 if ((offset + 12) > sec->size)
1058 call = contents + offset + 4;
1060 || !((call[1] == 0x48
1068 && call[3] == 0xe8)))
1070 if (!ABI_64_P (abfd)
1071 || (offset + 19) > sec->size
1073 || memcmp (call - 7, leaq + 1, 3) != 0
1074 || memcmp (call, "\x48\xb8", 2) != 0
1078 || !((call[10] == 0x48 && call[12] == 0xd8)
1079 || (call[10] == 0x4c && call[12] == 0xf8)))
1083 else if (ABI_64_P (abfd))
1086 || memcmp (contents + offset - 4, leaq, 4) != 0)
1092 || memcmp (contents + offset - 3, leaq + 1, 3) != 0)
1095 indirect_call = call[2] == 0xff;
1099 /* Check transition from LD access model. Only
1100 leaq foo@tlsld(%rip), %rdi;
1101 call __tls_get_addr@PLT
1103 leaq foo@tlsld(%rip), %rdi;
1104 call *__tls_get_addr@GOTPCREL(%rip)
1105 which may be converted to
1106 addr32 call __tls_get_addr
1107 can transit to different access model. For largepic
1109 leaq foo@tlsld(%rip), %rdi
1110 movabsq $__tls_get_addr@pltoff, %rax
1114 leaq foo@tlsld(%rip), %rdi
1115 movabsq $__tls_get_addr@pltoff, %rax
1119 static const unsigned char lea[] = { 0x48, 0x8d, 0x3d };
1121 if (offset < 3 || (offset + 9) > sec->size)
1124 if (memcmp (contents + offset - 3, lea, 3) != 0)
1127 call = contents + offset + 4;
1128 if (!(call[0] == 0xe8
1129 || (call[0] == 0xff && call[1] == 0x15)
1130 || (call[0] == 0x67 && call[1] == 0xe8)))
1132 if (!ABI_64_P (abfd)
1133 || (offset + 19) > sec->size
1134 || memcmp (call, "\x48\xb8", 2) != 0
1138 || !((call[10] == 0x48 && call[12] == 0xd8)
1139 || (call[10] == 0x4c && call[12] == 0xf8)))
1143 indirect_call = call[0] == 0xff;
1146 r_symndx = htab->r_sym (rel[1].r_info);
1147 if (r_symndx < symtab_hdr->sh_info)
1150 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1152 || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr)
1156 r_type = (ELF32_R_TYPE (rel[1].r_info)
1157 & ~R_X86_64_converted_reloc_bit);
1159 return r_type == R_X86_64_PLTOFF64;
1160 else if (indirect_call)
1161 return r_type == R_X86_64_GOTPCRELX;
1163 return (r_type == R_X86_64_PC32 || r_type == R_X86_64_PLT32);
1166 case R_X86_64_GOTTPOFF:
1167 /* Check transition from IE access model:
1168 mov foo@gottpoff(%rip), %reg
1169 add foo@gottpoff(%rip), %reg
1172 /* Check REX prefix first. */
1173 if (offset >= 3 && (offset + 4) <= sec->size)
1175 val = bfd_get_8 (abfd, contents + offset - 3);
1176 if (val != 0x48 && val != 0x4c)
1178 /* X32 may have 0x44 REX prefix or no REX prefix. */
1179 if (ABI_64_P (abfd))
1185 /* X32 may not have any REX prefix. */
1186 if (ABI_64_P (abfd))
1188 if (offset < 2 || (offset + 3) > sec->size)
1192 val = bfd_get_8 (abfd, contents + offset - 2);
1193 if (val != 0x8b && val != 0x03)
1196 val = bfd_get_8 (abfd, contents + offset - 1);
1197 return (val & 0xc7) == 5;
1199 case R_X86_64_GOTPC32_TLSDESC:
1200 /* Check transition from GDesc access model:
1201 leaq x@tlsdesc(%rip), %rax
1203 Make sure it's a leaq adding rip to a 32-bit offset
1204 into any register, although it's probably almost always
1207 if (offset < 3 || (offset + 4) > sec->size)
1210 val = bfd_get_8 (abfd, contents + offset - 3);
1211 if ((val & 0xfb) != 0x48)
1214 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1217 val = bfd_get_8 (abfd, contents + offset - 1);
1218 return (val & 0xc7) == 0x05;
1220 case R_X86_64_TLSDESC_CALL:
1221 /* Check transition from GDesc access model:
1222 call *x@tlsdesc(%rax)
1224 if (offset + 2 <= sec->size)
1226 /* Make sure that it's a call *x@tlsdesc(%rax). */
1227 call = contents + offset;
1228 return call[0] == 0xff && call[1] == 0x10;
1238 /* Return TRUE if the TLS access transition is OK or no transition
1239 will be performed. Update R_TYPE if there is a transition. */
1242 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1243 asection *sec, bfd_byte *contents,
1244 Elf_Internal_Shdr *symtab_hdr,
1245 struct elf_link_hash_entry **sym_hashes,
1246 unsigned int *r_type, int tls_type,
1247 const Elf_Internal_Rela *rel,
1248 const Elf_Internal_Rela *relend,
1249 struct elf_link_hash_entry *h,
1250 unsigned long r_symndx,
1251 bfd_boolean from_relocate_section)
1253 unsigned int from_type = *r_type;
1254 unsigned int to_type = from_type;
1255 bfd_boolean check = TRUE;
1257 /* Skip TLS transition for functions. */
1259 && (h->type == STT_FUNC
1260 || h->type == STT_GNU_IFUNC))
1265 case R_X86_64_TLSGD:
1266 case R_X86_64_GOTPC32_TLSDESC:
1267 case R_X86_64_TLSDESC_CALL:
1268 case R_X86_64_GOTTPOFF:
1269 if (bfd_link_executable (info))
1272 to_type = R_X86_64_TPOFF32;
1274 to_type = R_X86_64_GOTTPOFF;
1277 /* When we are called from elf_x86_64_relocate_section, there may
1278 be additional transitions based on TLS_TYPE. */
1279 if (from_relocate_section)
1281 unsigned int new_to_type = to_type;
1283 if (bfd_link_executable (info)
1286 && tls_type == GOT_TLS_IE)
1287 new_to_type = R_X86_64_TPOFF32;
1289 if (to_type == R_X86_64_TLSGD
1290 || to_type == R_X86_64_GOTPC32_TLSDESC
1291 || to_type == R_X86_64_TLSDESC_CALL)
1293 if (tls_type == GOT_TLS_IE)
1294 new_to_type = R_X86_64_GOTTPOFF;
1297 /* We checked the transition before when we were called from
1298 elf_x86_64_check_relocs. We only want to check the new
1299 transition which hasn't been checked before. */
1300 check = new_to_type != to_type && from_type == to_type;
1301 to_type = new_to_type;
1306 case R_X86_64_TLSLD:
1307 if (bfd_link_executable (info))
1308 to_type = R_X86_64_TPOFF32;
1315 /* Return TRUE if there is no transition. */
1316 if (from_type == to_type)
1319 /* Check if the transition can be performed. */
1321 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1322 symtab_hdr, sym_hashes,
1323 from_type, rel, relend))
1325 reloc_howto_type *from, *to;
1328 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1329 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1332 name = h->root.root.string;
1335 struct elf_x86_link_hash_table *htab;
1337 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1342 Elf_Internal_Sym *isym;
1344 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1346 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1351 /* xgettext:c-format */
1352 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1353 "in section `%A' failed"),
1354 abfd, from->name, to->name, name, rel->r_offset, sec);
1355 bfd_set_error (bfd_error_bad_value);
1363 /* Rename some of the generic section flags to better document how they
1365 #define need_convert_load sec_flg0
1366 #define check_relocs_failed sec_flg1
1369 elf_x86_64_need_pic (struct bfd_link_info *info,
1370 bfd *input_bfd, asection *sec,
1371 struct elf_link_hash_entry *h,
1372 Elf_Internal_Shdr *symtab_hdr,
1373 Elf_Internal_Sym *isym,
1374 reloc_howto_type *howto)
1377 const char *und = "";
1378 const char *pic = "";
1384 name = h->root.root.string;
1385 switch (ELF_ST_VISIBILITY (h->other))
1388 v = _("hidden symbol ");
1391 v = _("internal symbol ");
1394 v = _("protected symbol ");
1397 if (((struct elf_x86_link_hash_entry *) h)->def_protected)
1398 v = _("protected symbol ");
1401 pic = _("; recompile with -fPIC");
1405 if (!h->def_regular && !h->def_dynamic)
1406 und = _("undefined ");
1410 name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL);
1411 pic = _("; recompile with -fPIC");
1414 if (bfd_link_dll (info))
1415 object = _("a shared object");
1416 else if (bfd_link_pie (info))
1417 object = _("a PIE object");
1419 object = _("a PDE object");
1421 /* xgettext:c-format */
1422 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1423 "not be used when making %s%s"),
1424 input_bfd, howto->name, und, v, name,
1426 bfd_set_error (bfd_error_bad_value);
1427 sec->check_relocs_failed = 1;
1431 /* With the local symbol, foo, we convert
1432 mov foo@GOTPCREL(%rip), %reg
1436 call/jmp *foo@GOTPCREL(%rip)
1438 nop call foo/jmp foo nop
1439 When PIC is false, convert
1440 test %reg, foo@GOTPCREL(%rip)
1444 binop foo@GOTPCREL(%rip), %reg
1447 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1451 elf_x86_64_convert_load_reloc (bfd *abfd,
1453 Elf_Internal_Rela *irel,
1454 struct elf_link_hash_entry *h,
1455 bfd_boolean *converted,
1456 struct bfd_link_info *link_info)
1458 struct elf_x86_link_hash_table *htab;
1460 bfd_boolean no_overflow;
1462 bfd_boolean to_reloc_pc32;
1464 bfd_signed_vma raddend;
1465 unsigned int opcode;
1467 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
1468 unsigned int r_symndx;
1469 bfd_vma roff = irel->r_offset;
1471 if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2))
1474 raddend = irel->r_addend;
1475 /* Addend for 32-bit PC-relative relocation must be -4. */
1479 htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA);
1480 is_pic = bfd_link_pic (link_info);
1482 relocx = (r_type == R_X86_64_GOTPCRELX
1483 || r_type == R_X86_64_REX_GOTPCRELX);
1485 /* TRUE if --no-relax is used. */
1486 no_overflow = link_info->disable_target_specific_optimizations > 1;
1488 r_symndx = htab->r_sym (irel->r_info);
1490 opcode = bfd_get_8 (abfd, contents + roff - 2);
1492 /* Convert mov to lea since it has been done for a while. */
1495 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1496 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1497 test, xor instructions. */
1502 /* We convert only to R_X86_64_PC32:
1504 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1505 3. no_overflow is true.
1508 to_reloc_pc32 = (opcode == 0xff
1513 /* Get the symbol referred to by the reloc. */
1516 Elf_Internal_Sym *isym
1517 = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
1519 /* Skip relocation against undefined symbols. */
1520 if (isym->st_shndx == SHN_UNDEF)
1523 if (isym->st_shndx == SHN_ABS)
1524 tsec = bfd_abs_section_ptr;
1525 else if (isym->st_shndx == SHN_COMMON)
1526 tsec = bfd_com_section_ptr;
1527 else if (isym->st_shndx == SHN_X86_64_LCOMMON)
1528 tsec = &_bfd_elf_large_com_section;
1530 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1534 /* Undefined weak symbol is only bound locally in executable
1535 and its reference is resolved as 0 without relocation
1536 overflow. We can only perform this optimization for
1537 GOTPCRELX relocations since we need to modify REX byte.
1538 It is OK convert mov with R_X86_64_GOTPCREL to
1540 if ((relocx || opcode == 0x8b)
1541 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info,
1544 elf_x86_hash_entry (h)))
1548 /* Skip for branch instructions since R_X86_64_PC32
1555 /* For non-branch instructions, we can convert to
1556 R_X86_64_32/R_X86_64_32S since we know if there
1558 to_reloc_pc32 = FALSE;
1561 /* Since we don't know the current PC when PIC is true,
1562 we can't convert to R_X86_64_PC32. */
1563 if (to_reloc_pc32 && is_pic)
1568 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1569 ld.so may use its link-time address. */
1570 else if (h->start_stop
1572 || h->root.type == bfd_link_hash_defined
1573 || h->root.type == bfd_link_hash_defweak)
1574 && h != htab->elf.hdynamic
1575 && SYMBOL_REFERENCES_LOCAL (link_info, h)))
1577 /* bfd_link_hash_new or bfd_link_hash_undefined is
1578 set by an assignment in a linker script in
1579 bfd_elf_record_link_assignment. start_stop is set
1580 on __start_SECNAME/__stop_SECNAME which mark section
1584 && (h->root.type == bfd_link_hash_new
1585 || h->root.type == bfd_link_hash_undefined
1586 || ((h->root.type == bfd_link_hash_defined
1587 || h->root.type == bfd_link_hash_defweak)
1588 && h->root.u.def.section == bfd_und_section_ptr))))
1590 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1595 tsec = h->root.u.def.section;
1601 /* Don't convert GOTPCREL relocation against large section. */
1602 if (elf_section_data (tsec) != NULL
1603 && (elf_section_flags (tsec) & SHF_X86_64_LARGE) != 0)
1606 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1613 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1618 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1620 modrm = bfd_get_8 (abfd, contents + roff - 1);
1623 /* Convert to "jmp foo nop". */
1626 nop_offset = irel->r_offset + 3;
1627 disp = bfd_get_32 (abfd, contents + irel->r_offset);
1628 irel->r_offset -= 1;
1629 bfd_put_32 (abfd, disp, contents + irel->r_offset);
1633 struct elf_x86_link_hash_entry *eh
1634 = (struct elf_x86_link_hash_entry *) h;
1636 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1639 /* To support TLS optimization, always use addr32 prefix for
1640 "call *__tls_get_addr@GOTPCREL(%rip)". */
1641 if (eh && eh->tls_get_addr)
1644 nop_offset = irel->r_offset - 2;
1648 nop = link_info->call_nop_byte;
1649 if (link_info->call_nop_as_suffix)
1651 nop_offset = irel->r_offset + 3;
1652 disp = bfd_get_32 (abfd, contents + irel->r_offset);
1653 irel->r_offset -= 1;
1654 bfd_put_32 (abfd, disp, contents + irel->r_offset);
1657 nop_offset = irel->r_offset - 2;
1660 bfd_put_8 (abfd, nop, contents + nop_offset);
1661 bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
1662 r_type = R_X86_64_PC32;
1667 unsigned int rex_mask = REX_R;
1669 if (r_type == R_X86_64_REX_GOTPCRELX)
1670 rex = bfd_get_8 (abfd, contents + roff - 3);
1678 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1679 "lea foo(%rip), %reg". */
1681 r_type = R_X86_64_PC32;
1685 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1686 "mov $foo, %reg". */
1688 modrm = bfd_get_8 (abfd, contents + roff - 1);
1689 modrm = 0xc0 | (modrm & 0x38) >> 3;
1690 if ((rex & REX_W) != 0
1691 && ABI_64_P (link_info->output_bfd))
1693 /* Keep the REX_W bit in REX byte for LP64. */
1694 r_type = R_X86_64_32S;
1695 goto rewrite_modrm_rex;
1699 /* If the REX_W bit in REX byte isn't needed,
1700 use R_X86_64_32 and clear the W bit to avoid
1701 sign-extend imm32 to imm64. */
1702 r_type = R_X86_64_32;
1703 /* Clear the W bit in REX byte. */
1705 goto rewrite_modrm_rex;
1711 /* R_X86_64_PC32 isn't supported. */
1715 modrm = bfd_get_8 (abfd, contents + roff - 1);
1718 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1719 "test $foo, %reg". */
1720 modrm = 0xc0 | (modrm & 0x38) >> 3;
1725 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1726 "binop $foo, %reg". */
1727 modrm = 0xc0 | (modrm & 0x38) >> 3 | (opcode & 0x3c);
1731 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1732 overflow when sign-extending imm32 to imm64. */
1733 r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32;
1736 bfd_put_8 (abfd, modrm, contents + roff - 1);
1740 /* Move the R bit to the B bit in REX byte. */
1741 rex = (rex & ~rex_mask) | (rex & REX_R) >> 2;
1742 bfd_put_8 (abfd, rex, contents + roff - 3);
1745 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1749 bfd_put_8 (abfd, opcode, contents + roff - 2);
1752 irel->r_info = htab->r_info (r_symndx,
1753 r_type | R_X86_64_converted_reloc_bit);
1760 /* Look through the relocs for a section during the first phase, and
1761 calculate needed space in the global offset table, procedure
1762 linkage table, and dynamic reloc sections. */
1765 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1767 const Elf_Internal_Rela *relocs)
1769 struct elf_x86_link_hash_table *htab;
1770 Elf_Internal_Shdr *symtab_hdr;
1771 struct elf_link_hash_entry **sym_hashes;
1772 const Elf_Internal_Rela *rel;
1773 const Elf_Internal_Rela *rel_end;
1777 if (bfd_link_relocatable (info))
1780 /* Don't do anything special with non-loaded, non-alloced sections.
1781 In particular, any relocs in such sections should not affect GOT
1782 and PLT reference counting (ie. we don't allow them to create GOT
1783 or PLT entries), there's no possibility or desire to optimize TLS
1784 relocs, and there's not much point in propagating relocs to shared
1785 libs that the dynamic linker won't relocate. */
1786 if ((sec->flags & SEC_ALLOC) == 0)
1789 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
1792 sec->check_relocs_failed = 1;
1796 BFD_ASSERT (is_x86_elf (abfd, htab));
1798 /* Get the section contents. */
1799 if (elf_section_data (sec)->this_hdr.contents != NULL)
1800 contents = elf_section_data (sec)->this_hdr.contents;
1801 else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1803 sec->check_relocs_failed = 1;
1807 symtab_hdr = &elf_symtab_hdr (abfd);
1808 sym_hashes = elf_sym_hashes (abfd);
1812 rel_end = relocs + sec->reloc_count;
1813 for (rel = relocs; rel < rel_end; rel++)
1815 unsigned int r_type;
1816 unsigned int r_symndx;
1817 struct elf_link_hash_entry *h;
1818 struct elf_x86_link_hash_entry *eh;
1819 Elf_Internal_Sym *isym;
1821 bfd_boolean size_reloc;
1823 r_symndx = htab->r_sym (rel->r_info);
1824 r_type = ELF32_R_TYPE (rel->r_info);
1826 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1828 /* xgettext:c-format */
1829 _bfd_error_handler (_("%B: bad symbol index: %d"),
1834 if (r_symndx < symtab_hdr->sh_info)
1836 /* A local symbol. */
1837 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1842 /* Check relocation against local STT_GNU_IFUNC symbol. */
1843 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1845 h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel,
1850 /* Fake a STT_GNU_IFUNC symbol. */
1851 h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
1853 h->type = STT_GNU_IFUNC;
1856 h->forced_local = 1;
1857 h->root.type = bfd_link_hash_defined;
1865 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1866 while (h->root.type == bfd_link_hash_indirect
1867 || h->root.type == bfd_link_hash_warning)
1868 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1871 /* Check invalid x32 relocations. */
1872 if (!ABI_64_P (abfd))
1878 case R_X86_64_DTPOFF64:
1879 case R_X86_64_TPOFF64:
1881 case R_X86_64_GOTOFF64:
1882 case R_X86_64_GOT64:
1883 case R_X86_64_GOTPCREL64:
1884 case R_X86_64_GOTPC64:
1885 case R_X86_64_GOTPLT64:
1886 case R_X86_64_PLTOFF64:
1889 name = h->root.root.string;
1891 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1894 /* xgettext:c-format */
1895 (_("%B: relocation %s against symbol `%s' isn't "
1896 "supported in x32 mode"), abfd,
1897 x86_64_elf_howto_table[r_type].name, name);
1898 bfd_set_error (bfd_error_bad_value);
1906 /* It is referenced by a non-shared object. */
1908 h->root.non_ir_ref_regular = 1;
1910 if (h->type == STT_GNU_IFUNC)
1911 elf_tdata (info->output_bfd)->has_gnu_symbols
1912 |= elf_gnu_symbol_ifunc;
1915 if (! elf_x86_64_tls_transition (info, abfd, sec, contents,
1916 symtab_hdr, sym_hashes,
1917 &r_type, GOT_UNKNOWN,
1918 rel, rel_end, h, r_symndx, FALSE))
1921 eh = (struct elf_x86_link_hash_entry *) h;
1924 case R_X86_64_TLSLD:
1925 htab->tls_ld_or_ldm_got.refcount += 1;
1928 case R_X86_64_TPOFF32:
1929 if (!bfd_link_executable (info) && ABI_64_P (abfd))
1930 return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
1931 &x86_64_elf_howto_table[r_type]);
1933 eh->has_got_reloc = 1;
1936 case R_X86_64_GOTTPOFF:
1937 if (!bfd_link_executable (info))
1938 info->flags |= DF_STATIC_TLS;
1941 case R_X86_64_GOT32:
1942 case R_X86_64_GOTPCREL:
1943 case R_X86_64_GOTPCRELX:
1944 case R_X86_64_REX_GOTPCRELX:
1945 case R_X86_64_TLSGD:
1946 case R_X86_64_GOT64:
1947 case R_X86_64_GOTPCREL64:
1948 case R_X86_64_GOTPLT64:
1949 case R_X86_64_GOTPC32_TLSDESC:
1950 case R_X86_64_TLSDESC_CALL:
1951 /* This symbol requires a global offset table entry. */
1953 int tls_type, old_tls_type;
1957 default: tls_type = GOT_NORMAL; break;
1958 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1959 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1960 case R_X86_64_GOTPC32_TLSDESC:
1961 case R_X86_64_TLSDESC_CALL:
1962 tls_type = GOT_TLS_GDESC; break;
1967 h->got.refcount += 1;
1968 old_tls_type = eh->tls_type;
1972 bfd_signed_vma *local_got_refcounts;
1974 /* This is a global offset table entry for a local symbol. */
1975 local_got_refcounts = elf_local_got_refcounts (abfd);
1976 if (local_got_refcounts == NULL)
1980 size = symtab_hdr->sh_info;
1981 size *= sizeof (bfd_signed_vma)
1982 + sizeof (bfd_vma) + sizeof (char);
1983 local_got_refcounts = ((bfd_signed_vma *)
1984 bfd_zalloc (abfd, size));
1985 if (local_got_refcounts == NULL)
1987 elf_local_got_refcounts (abfd) = local_got_refcounts;
1988 elf_x86_local_tlsdesc_gotent (abfd)
1989 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1990 elf_x86_local_got_tls_type (abfd)
1991 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1993 local_got_refcounts[r_symndx] += 1;
1995 = elf_x86_local_got_tls_type (abfd) [r_symndx];
1998 /* If a TLS symbol is accessed using IE at least once,
1999 there is no point to use dynamic model for it. */
2000 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
2001 && (! GOT_TLS_GD_ANY_P (old_tls_type)
2002 || tls_type != GOT_TLS_IE))
2004 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
2005 tls_type = old_tls_type;
2006 else if (GOT_TLS_GD_ANY_P (old_tls_type)
2007 && GOT_TLS_GD_ANY_P (tls_type))
2008 tls_type |= old_tls_type;
2012 name = h->root.root.string;
2014 name = bfd_elf_sym_name (abfd, symtab_hdr,
2017 /* xgettext:c-format */
2018 (_("%B: '%s' accessed both as normal and"
2019 " thread local symbol"),
2021 bfd_set_error (bfd_error_bad_value);
2026 if (old_tls_type != tls_type)
2029 eh->tls_type = tls_type;
2031 elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type;
2036 case R_X86_64_GOTOFF64:
2037 case R_X86_64_GOTPC32:
2038 case R_X86_64_GOTPC64:
2041 eh->has_got_reloc = 1;
2044 case R_X86_64_PLT32:
2045 case R_X86_64_PLT32_BND:
2046 /* This symbol requires a procedure linkage table entry. We
2047 actually build the entry in adjust_dynamic_symbol,
2048 because this might be a case of linking PIC code which is
2049 never referenced by a dynamic object, in which case we
2050 don't need to generate a procedure linkage table entry
2053 /* If this is a local symbol, we resolve it directly without
2054 creating a procedure linkage table entry. */
2058 eh->has_got_reloc = 1;
2060 h->plt.refcount += 1;
2063 case R_X86_64_PLTOFF64:
2064 /* This tries to form the 'address' of a function relative
2065 to GOT. For global symbols we need a PLT entry. */
2069 h->plt.refcount += 1;
2073 case R_X86_64_SIZE32:
2074 case R_X86_64_SIZE64:
2079 if (!ABI_64_P (abfd))
2085 /* Check relocation overflow as these relocs may lead to
2086 run-time relocation overflow. Don't error out for
2087 sections we don't care about, such as debug sections or
2088 when relocation overflow check is disabled. */
2089 if (!info->no_reloc_overflow_check
2090 && (bfd_link_pic (info)
2091 || (bfd_link_executable (info)
2095 && (sec->flags & SEC_READONLY) == 0)))
2096 return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym,
2097 &x86_64_elf_howto_table[r_type]);
2103 case R_X86_64_PC32_BND:
2107 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
2108 eh->has_non_got_reloc = 1;
2109 /* We are called after all symbols have been resolved. Only
2110 relocation against STT_GNU_IFUNC symbol must go through
2113 && (bfd_link_executable (info)
2114 || h->type == STT_GNU_IFUNC))
2116 /* If this reloc is in a read-only section, we might
2117 need a copy reloc. We can't check reliably at this
2118 stage whether the section is read-only, as input
2119 sections have not yet been mapped to output sections.
2120 Tentatively set the flag for now, and correct in
2121 adjust_dynamic_symbol. */
2124 /* We may need a .plt entry if the symbol is a function
2125 defined in a shared lib or is a STT_GNU_IFUNC function
2126 referenced from the code or read-only section. */
2128 || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
2129 h->plt.refcount += 1;
2131 if (r_type == R_X86_64_PC32)
2133 /* Since something like ".long foo - ." may be used
2134 as pointer, make sure that PLT is used if foo is
2135 a function defined in a shared library. */
2136 if ((sec->flags & SEC_CODE) == 0)
2137 h->pointer_equality_needed = 1;
2139 else if (r_type != R_X86_64_PC32_BND
2140 && r_type != R_X86_64_PC64)
2142 h->pointer_equality_needed = 1;
2143 /* At run-time, R_X86_64_64 can be resolved for both
2144 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2145 can only be resolved for x32. */
2146 if ((sec->flags & SEC_READONLY) == 0
2147 && (r_type == R_X86_64_64
2148 || (!ABI_64_P (abfd)
2149 && (r_type == R_X86_64_32
2150 || r_type == R_X86_64_32S))))
2151 eh->func_pointer_refcount += 1;
2157 /* If we are creating a shared library, and this is a reloc
2158 against a global symbol, or a non PC relative reloc
2159 against a local symbol, then we need to copy the reloc
2160 into the shared library. However, if we are linking with
2161 -Bsymbolic, we do not need to copy a reloc against a
2162 global symbol which is defined in an object we are
2163 including in the link (i.e., DEF_REGULAR is set). At
2164 this point we have not seen all the input files, so it is
2165 possible that DEF_REGULAR is not set now but will be set
2166 later (it is never cleared). In case of a weak definition,
2167 DEF_REGULAR may be cleared later by a strong definition in
2168 a shared library. We account for that possibility below by
2169 storing information in the relocs_copied field of the hash
2170 table entry. A similar situation occurs when creating
2171 shared libraries and symbol visibility changes render the
2174 If on the other hand, we are creating an executable, we
2175 may need to keep relocations for symbols satisfied by a
2176 dynamic library if we manage to avoid copy relocs for the
2179 Generate dynamic pointer relocation against STT_GNU_IFUNC
2180 symbol in the non-code section. */
2181 if ((bfd_link_pic (info)
2182 && (! IS_X86_64_PCREL_TYPE (r_type)
2184 && (! (bfd_link_pie (info)
2185 || SYMBOLIC_BIND (info, h))
2186 || h->root.type == bfd_link_hash_defweak
2187 || !h->def_regular))))
2189 && h->type == STT_GNU_IFUNC
2190 && r_type == htab->pointer_r_type
2191 && (sec->flags & SEC_CODE) == 0)
2192 || (ELIMINATE_COPY_RELOCS
2193 && !bfd_link_pic (info)
2195 && (h->root.type == bfd_link_hash_defweak
2196 || !h->def_regular)))
2198 struct elf_dyn_relocs *p;
2199 struct elf_dyn_relocs **head;
2201 /* We must copy these reloc types into the output file.
2202 Create a reloc section in dynobj and make room for
2206 sreloc = _bfd_elf_make_dynamic_reloc_section
2207 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
2208 abfd, /*rela?*/ TRUE);
2214 /* If this is a global symbol, we count the number of
2215 relocations we need for this symbol. */
2217 head = &eh->dyn_relocs;
2220 /* Track dynamic relocs needed for local syms too.
2221 We really need local syms available to do this
2226 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
2231 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2235 /* Beware of type punned pointers vs strict aliasing
2237 vpp = &(elf_section_data (s)->local_dynrel);
2238 head = (struct elf_dyn_relocs **)vpp;
2242 if (p == NULL || p->sec != sec)
2244 bfd_size_type amt = sizeof *p;
2246 p = ((struct elf_dyn_relocs *)
2247 bfd_alloc (htab->elf.dynobj, amt));
2258 /* Count size relocation as PC-relative relocation. */
2259 if (IS_X86_64_PCREL_TYPE (r_type) || size_reloc)
2264 /* This relocation describes the C++ object vtable hierarchy.
2265 Reconstruct it for later use during GC. */
2266 case R_X86_64_GNU_VTINHERIT:
2267 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2271 /* This relocation describes which C++ vtable entries are actually
2272 used. Record for later use during GC. */
2273 case R_X86_64_GNU_VTENTRY:
2274 BFD_ASSERT (h != NULL);
2276 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2284 if ((r_type == R_X86_64_GOTPCREL
2285 || r_type == R_X86_64_GOTPCRELX
2286 || r_type == R_X86_64_REX_GOTPCRELX)
2287 && (h == NULL || h->type != STT_GNU_IFUNC))
2288 sec->need_convert_load = 1;
2291 if (elf_section_data (sec)->this_hdr.contents != contents)
2293 if (!info->keep_memory)
2297 /* Cache the section contents for elf_link_input_bfd. */
2298 elf_section_data (sec)->this_hdr.contents = contents;
2305 if (elf_section_data (sec)->this_hdr.contents != contents)
2307 sec->check_relocs_failed = 1;
2311 /* Convert load via the GOT slot to load immediate. */
2314 _bfd_x86_64_elf_convert_load (bfd *abfd, asection *sec,
2315 struct bfd_link_info *link_info)
2317 Elf_Internal_Shdr *symtab_hdr;
2318 Elf_Internal_Rela *internal_relocs;
2319 Elf_Internal_Rela *irel, *irelend;
2321 struct elf_x86_link_hash_table *htab;
2322 bfd_boolean changed;
2323 bfd_signed_vma *local_got_refcounts;
2325 /* Don't even try to convert non-ELF outputs. */
2326 if (!is_elf_hash_table (link_info->hash))
2329 /* Nothing to do if there is no need or no output. */
2330 if ((sec->flags & (SEC_CODE | SEC_RELOC)) != (SEC_CODE | SEC_RELOC)
2331 || sec->need_convert_load == 0
2332 || bfd_is_abs_section (sec->output_section))
2335 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2337 /* Load the relocations for this section. */
2338 internal_relocs = (_bfd_elf_link_read_relocs
2339 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
2340 link_info->keep_memory));
2341 if (internal_relocs == NULL)
2345 htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA);
2346 local_got_refcounts = elf_local_got_refcounts (abfd);
2348 /* Get the section contents. */
2349 if (elf_section_data (sec)->this_hdr.contents != NULL)
2350 contents = elf_section_data (sec)->this_hdr.contents;
2353 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2357 irelend = internal_relocs + sec->reloc_count;
2358 for (irel = internal_relocs; irel < irelend; irel++)
2360 unsigned int r_type = ELF32_R_TYPE (irel->r_info);
2361 unsigned int r_symndx;
2362 struct elf_link_hash_entry *h;
2363 bfd_boolean converted;
2365 if (r_type != R_X86_64_GOTPCRELX
2366 && r_type != R_X86_64_REX_GOTPCRELX
2367 && r_type != R_X86_64_GOTPCREL)
2370 r_symndx = htab->r_sym (irel->r_info);
2371 if (r_symndx < symtab_hdr->sh_info)
2372 h = _bfd_elf_x86_get_local_sym_hash (htab, sec->owner,
2373 (const Elf_Internal_Rela *) irel,
2377 h = elf_sym_hashes (abfd)[r_symndx - symtab_hdr->sh_info];
2378 while (h->root.type == bfd_link_hash_indirect
2379 || h->root.type == bfd_link_hash_warning)
2380 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2383 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
2384 if (h != NULL && h->type == STT_GNU_IFUNC)
2388 if (!elf_x86_64_convert_load_reloc (abfd, contents, irel, h,
2389 &converted, link_info))
2394 changed = converted;
2397 if (h->got.refcount > 0)
2398 h->got.refcount -= 1;
2402 if (local_got_refcounts != NULL
2403 && local_got_refcounts[r_symndx] > 0)
2404 local_got_refcounts[r_symndx] -= 1;
2409 if (contents != NULL
2410 && elf_section_data (sec)->this_hdr.contents != contents)
2412 if (!changed && !link_info->keep_memory)
2416 /* Cache the section contents for elf_link_input_bfd. */
2417 elf_section_data (sec)->this_hdr.contents = contents;
2421 if (elf_section_data (sec)->relocs != internal_relocs)
2424 free (internal_relocs);
2426 elf_section_data (sec)->relocs = internal_relocs;
2432 if (contents != NULL
2433 && elf_section_data (sec)->this_hdr.contents != contents)
2435 if (internal_relocs != NULL
2436 && elf_section_data (sec)->relocs != internal_relocs)
2437 free (internal_relocs);
2441 /* Return the relocation value for @tpoff relocation
2442 if STT_TLS virtual address is ADDRESS. */
2445 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
2447 struct elf_link_hash_table *htab = elf_hash_table (info);
2448 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
2449 bfd_vma static_tls_size;
2451 /* If tls_segment is NULL, we should have signalled an error already. */
2452 if (htab->tls_sec == NULL)
2455 /* Consider special static TLS alignment requirements. */
2456 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
2457 return address - static_tls_size - htab->tls_sec->vma;
2460 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2464 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2466 /* Opcode Instruction
2469 0x0f 0x8x conditional jump */
2471 && (contents [offset - 1] == 0xe8
2472 || contents [offset - 1] == 0xe9))
2474 && contents [offset - 2] == 0x0f
2475 && (contents [offset - 1] & 0xf0) == 0x80));
2478 /* Relocate an x86_64 ELF section. */
2481 elf_x86_64_relocate_section (bfd *output_bfd,
2482 struct bfd_link_info *info,
2484 asection *input_section,
2486 Elf_Internal_Rela *relocs,
2487 Elf_Internal_Sym *local_syms,
2488 asection **local_sections)
2490 struct elf_x86_link_hash_table *htab;
2491 Elf_Internal_Shdr *symtab_hdr;
2492 struct elf_link_hash_entry **sym_hashes;
2493 bfd_vma *local_got_offsets;
2494 bfd_vma *local_tlsdesc_gotents;
2495 Elf_Internal_Rela *rel;
2496 Elf_Internal_Rela *wrel;
2497 Elf_Internal_Rela *relend;
2498 unsigned int plt_entry_size;
2500 /* Skip if check_relocs failed. */
2501 if (input_section->check_relocs_failed)
2504 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
2508 BFD_ASSERT (is_x86_elf (input_bfd, htab));
2510 plt_entry_size = htab->plt.plt_entry_size;
2511 symtab_hdr = &elf_symtab_hdr (input_bfd);
2512 sym_hashes = elf_sym_hashes (input_bfd);
2513 local_got_offsets = elf_local_got_offsets (input_bfd);
2514 local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd);
2516 _bfd_x86_elf_set_tls_module_base (info);
2518 rel = wrel = relocs;
2519 relend = relocs + input_section->reloc_count;
2520 for (; rel < relend; wrel++, rel++)
2522 unsigned int r_type, r_type_tls;
2523 reloc_howto_type *howto;
2524 unsigned long r_symndx;
2525 struct elf_link_hash_entry *h;
2526 struct elf_x86_link_hash_entry *eh;
2527 Elf_Internal_Sym *sym;
2529 bfd_vma off, offplt, plt_offset;
2531 bfd_boolean unresolved_reloc;
2532 bfd_reloc_status_type r;
2534 asection *base_got, *resolved_plt;
2536 bfd_boolean resolved_to_zero;
2537 bfd_boolean relative_reloc;
2538 bfd_boolean converted_reloc;
2540 r_type = ELF32_R_TYPE (rel->r_info);
2541 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2542 || r_type == (int) R_X86_64_GNU_VTENTRY)
2549 converted_reloc = (r_type & R_X86_64_converted_reloc_bit) != 0;
2550 r_type &= ~R_X86_64_converted_reloc_bit;
2552 if (r_type >= (int) R_X86_64_standard)
2553 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
2555 if (r_type != (int) R_X86_64_32
2556 || ABI_64_P (output_bfd))
2557 howto = x86_64_elf_howto_table + r_type;
2559 howto = (x86_64_elf_howto_table
2560 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
2561 r_symndx = htab->r_sym (rel->r_info);
2565 unresolved_reloc = FALSE;
2566 if (r_symndx < symtab_hdr->sh_info)
2568 sym = local_syms + r_symndx;
2569 sec = local_sections[r_symndx];
2571 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
2573 st_size = sym->st_size;
2575 /* Relocate against local STT_GNU_IFUNC symbol. */
2576 if (!bfd_link_relocatable (info)
2577 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2579 h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd,
2584 /* Set STT_GNU_IFUNC symbol value. */
2585 h->root.u.def.value = sym->st_value;
2586 h->root.u.def.section = sec;
2591 bfd_boolean warned ATTRIBUTE_UNUSED;
2592 bfd_boolean ignored ATTRIBUTE_UNUSED;
2594 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2595 r_symndx, symtab_hdr, sym_hashes,
2597 unresolved_reloc, warned, ignored);
2601 if (sec != NULL && discarded_section (sec))
2603 _bfd_clear_contents (howto, input_bfd, input_section,
2604 contents + rel->r_offset);
2605 wrel->r_offset = rel->r_offset;
2609 /* For ld -r, remove relocations in debug sections against
2610 sections defined in discarded sections. Not done for
2611 eh_frame editing code expects to be present. */
2612 if (bfd_link_relocatable (info)
2613 && (input_section->flags & SEC_DEBUGGING))
2619 if (bfd_link_relocatable (info))
2626 if (rel->r_addend == 0 && !ABI_64_P (output_bfd))
2628 if (r_type == R_X86_64_64)
2630 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2631 zero-extend it to 64bit if addend is zero. */
2632 r_type = R_X86_64_32;
2633 memset (contents + rel->r_offset + 4, 0, 4);
2635 else if (r_type == R_X86_64_SIZE64)
2637 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2638 zero-extend it to 64bit if addend is zero. */
2639 r_type = R_X86_64_SIZE32;
2640 memset (contents + rel->r_offset + 4, 0, 4);
2644 eh = (struct elf_x86_link_hash_entry *) h;
2646 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2647 it here if it is defined in a non-shared object. */
2649 && h->type == STT_GNU_IFUNC
2655 if ((input_section->flags & SEC_ALLOC) == 0)
2657 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2658 sections because such sections are not SEC_ALLOC and
2659 thus ld.so will not process them. */
2660 if ((input_section->flags & SEC_DEBUGGING) != 0)
2670 case R_X86_64_GOTPCREL:
2671 case R_X86_64_GOTPCRELX:
2672 case R_X86_64_REX_GOTPCRELX:
2673 case R_X86_64_GOTPCREL64:
2674 base_got = htab->elf.sgot;
2675 off = h->got.offset;
2677 if (base_got == NULL)
2680 if (off == (bfd_vma) -1)
2682 /* We can't use h->got.offset here to save state, or
2683 even just remember the offset, as finish_dynamic_symbol
2684 would use that as offset into .got. */
2686 if (h->plt.offset == (bfd_vma) -1)
2689 if (htab->elf.splt != NULL)
2691 plt_index = (h->plt.offset / plt_entry_size
2692 - htab->plt.has_plt0);
2693 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2694 base_got = htab->elf.sgotplt;
2698 plt_index = h->plt.offset / plt_entry_size;
2699 off = plt_index * GOT_ENTRY_SIZE;
2700 base_got = htab->elf.igotplt;
2703 if (h->dynindx == -1
2707 /* This references the local defitionion. We must
2708 initialize this entry in the global offset table.
2709 Since the offset must always be a multiple of 8,
2710 we use the least significant bit to record
2711 whether we have initialized it already.
2713 When doing a dynamic link, we create a .rela.got
2714 relocation entry to initialize the value. This
2715 is done in the finish_dynamic_symbol routine. */
2720 bfd_put_64 (output_bfd, relocation,
2721 base_got->contents + off);
2722 /* Note that this is harmless for the GOTPLT64
2723 case, as -1 | 1 still is -1. */
2729 relocation = (base_got->output_section->vma
2730 + base_got->output_offset + off);
2735 if (h->plt.offset == (bfd_vma) -1)
2737 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2738 if (r_type == htab->pointer_r_type
2739 && (input_section->flags & SEC_CODE) == 0)
2740 goto do_ifunc_pointer;
2741 goto bad_ifunc_reloc;
2744 /* STT_GNU_IFUNC symbol must go through PLT. */
2745 if (htab->elf.splt != NULL)
2747 if (htab->plt_second != NULL)
2749 resolved_plt = htab->plt_second;
2750 plt_offset = eh->plt_second.offset;
2754 resolved_plt = htab->elf.splt;
2755 plt_offset = h->plt.offset;
2760 resolved_plt = htab->elf.iplt;
2761 plt_offset = h->plt.offset;
2764 relocation = (resolved_plt->output_section->vma
2765 + resolved_plt->output_offset + plt_offset);
2771 if (h->root.root.string)
2772 name = h->root.root.string;
2774 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
2777 /* xgettext:c-format */
2778 (_("%B: relocation %s against STT_GNU_IFUNC "
2779 "symbol `%s' isn't supported"), input_bfd,
2781 bfd_set_error (bfd_error_bad_value);
2785 if (bfd_link_pic (info))
2790 if (ABI_64_P (output_bfd))
2795 if (rel->r_addend != 0)
2797 if (h->root.root.string)
2798 name = h->root.root.string;
2800 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
2803 /* xgettext:c-format */
2804 (_("%B: relocation %s against STT_GNU_IFUNC "
2805 "symbol `%s' has non-zero addend: %Ld"),
2806 input_bfd, howto->name, name, rel->r_addend);
2807 bfd_set_error (bfd_error_bad_value);
2811 /* Generate dynamic relcoation only when there is a
2812 non-GOT reference in a shared object or there is no
2814 if ((bfd_link_pic (info) && h->non_got_ref)
2815 || h->plt.offset == (bfd_vma) -1)
2817 Elf_Internal_Rela outrel;
2820 /* Need a dynamic relocation to get the real function
2822 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2826 if (outrel.r_offset == (bfd_vma) -1
2827 || outrel.r_offset == (bfd_vma) -2)
2830 outrel.r_offset += (input_section->output_section->vma
2831 + input_section->output_offset);
2833 if (h->dynindx == -1
2835 || bfd_link_executable (info))
2837 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
2838 h->root.root.string,
2839 h->root.u.def.section->owner);
2841 /* This symbol is resolved locally. */
2842 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
2843 outrel.r_addend = (h->root.u.def.value
2844 + h->root.u.def.section->output_section->vma
2845 + h->root.u.def.section->output_offset);
2849 outrel.r_info = htab->r_info (h->dynindx, r_type);
2850 outrel.r_addend = 0;
2853 /* Dynamic relocations are stored in
2854 1. .rela.ifunc section in PIC object.
2855 2. .rela.got section in dynamic executable.
2856 3. .rela.iplt section in static executable. */
2857 if (bfd_link_pic (info))
2858 sreloc = htab->elf.irelifunc;
2859 else if (htab->elf.splt != NULL)
2860 sreloc = htab->elf.srelgot;
2862 sreloc = htab->elf.irelplt;
2863 elf_append_rela (output_bfd, sreloc, &outrel);
2865 /* If this reloc is against an external symbol, we
2866 do not want to fiddle with the addend. Otherwise,
2867 we need to include the symbol value so that it
2868 becomes an addend for the dynamic reloc. For an
2869 internal symbol, we have updated addend. */
2874 case R_X86_64_PC32_BND:
2876 case R_X86_64_PLT32:
2877 case R_X86_64_PLT32_BND:
2882 resolved_to_zero = (eh != NULL
2883 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
2888 /* When generating a shared object, the relocations handled here are
2889 copied into the output file to be resolved at run time. */
2892 case R_X86_64_GOT32:
2893 case R_X86_64_GOT64:
2894 /* Relocation is to the entry for this symbol in the global
2896 case R_X86_64_GOTPCREL:
2897 case R_X86_64_GOTPCRELX:
2898 case R_X86_64_REX_GOTPCRELX:
2899 case R_X86_64_GOTPCREL64:
2900 /* Use global offset table entry as symbol value. */
2901 case R_X86_64_GOTPLT64:
2902 /* This is obsolete and treated the same as GOT64. */
2903 base_got = htab->elf.sgot;
2905 if (htab->elf.sgot == NULL)
2908 relative_reloc = FALSE;
2913 off = h->got.offset;
2915 && h->plt.offset != (bfd_vma)-1
2916 && off == (bfd_vma)-1)
2918 /* We can't use h->got.offset here to save
2919 state, or even just remember the offset, as
2920 finish_dynamic_symbol would use that as offset into
2922 bfd_vma plt_index = (h->plt.offset / plt_entry_size
2923 - htab->plt.has_plt0);
2924 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2925 base_got = htab->elf.sgotplt;
2928 dyn = htab->elf.dynamic_sections_created;
2930 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
2931 || (bfd_link_pic (info)
2932 && SYMBOL_REFERENCES_LOCAL (info, h))
2933 || (ELF_ST_VISIBILITY (h->other)
2934 && h->root.type == bfd_link_hash_undefweak))
2936 /* This is actually a static link, or it is a -Bsymbolic
2937 link and the symbol is defined locally, or the symbol
2938 was forced to be local because of a version file. We
2939 must initialize this entry in the global offset table.
2940 Since the offset must always be a multiple of 8, we
2941 use the least significant bit to record whether we
2942 have initialized it already.
2944 When doing a dynamic link, we create a .rela.got
2945 relocation entry to initialize the value. This is
2946 done in the finish_dynamic_symbol routine. */
2951 bfd_put_64 (output_bfd, relocation,
2952 base_got->contents + off);
2953 /* Note that this is harmless for the GOTPLT64 case,
2954 as -1 | 1 still is -1. */
2957 if (h->dynindx == -1
2959 && h->root.type != bfd_link_hash_undefweak
2960 && bfd_link_pic (info))
2962 /* If this symbol isn't dynamic in PIC,
2963 generate R_X86_64_RELATIVE here. */
2964 eh->no_finish_dynamic_symbol = 1;
2965 relative_reloc = TRUE;
2970 unresolved_reloc = FALSE;
2974 if (local_got_offsets == NULL)
2977 off = local_got_offsets[r_symndx];
2979 /* The offset must always be a multiple of 8. We use
2980 the least significant bit to record whether we have
2981 already generated the necessary reloc. */
2986 bfd_put_64 (output_bfd, relocation,
2987 base_got->contents + off);
2988 local_got_offsets[r_symndx] |= 1;
2990 if (bfd_link_pic (info))
2991 relative_reloc = TRUE;
2998 Elf_Internal_Rela outrel;
3000 /* We need to generate a R_X86_64_RELATIVE reloc
3001 for the dynamic linker. */
3002 s = htab->elf.srelgot;
3006 outrel.r_offset = (base_got->output_section->vma
3007 + base_got->output_offset
3009 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3010 outrel.r_addend = relocation;
3011 elf_append_rela (output_bfd, s, &outrel);
3014 if (off >= (bfd_vma) -2)
3017 relocation = base_got->output_section->vma
3018 + base_got->output_offset + off;
3019 if (r_type != R_X86_64_GOTPCREL
3020 && r_type != R_X86_64_GOTPCRELX
3021 && r_type != R_X86_64_REX_GOTPCRELX
3022 && r_type != R_X86_64_GOTPCREL64)
3023 relocation -= htab->elf.sgotplt->output_section->vma
3024 - htab->elf.sgotplt->output_offset;
3028 case R_X86_64_GOTOFF64:
3029 /* Relocation is relative to the start of the global offset
3032 /* Check to make sure it isn't a protected function or data
3033 symbol for shared library since it may not be local when
3034 used as function address or with copy relocation. We also
3035 need to make sure that a symbol is referenced locally. */
3036 if (bfd_link_pic (info) && h)
3038 if (!h->def_regular)
3042 switch (ELF_ST_VISIBILITY (h->other))
3045 v = _("hidden symbol");
3048 v = _("internal symbol");
3051 v = _("protected symbol");
3059 /* xgettext:c-format */
3060 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
3061 " `%s' can not be used when making a shared object"),
3062 input_bfd, v, h->root.root.string);
3063 bfd_set_error (bfd_error_bad_value);
3066 else if (!bfd_link_executable (info)
3067 && !SYMBOL_REFERENCES_LOCAL (info, h)
3068 && (h->type == STT_FUNC
3069 || h->type == STT_OBJECT)
3070 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3073 /* xgettext:c-format */
3074 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
3075 " `%s' can not be used when making a shared object"),
3077 h->type == STT_FUNC ? "function" : "data",
3078 h->root.root.string);
3079 bfd_set_error (bfd_error_bad_value);
3084 /* Note that sgot is not involved in this
3085 calculation. We always want the start of .got.plt. If we
3086 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3087 permitted by the ABI, we might have to change this
3089 relocation -= htab->elf.sgotplt->output_section->vma
3090 + htab->elf.sgotplt->output_offset;
3093 case R_X86_64_GOTPC32:
3094 case R_X86_64_GOTPC64:
3095 /* Use global offset table as symbol value. */
3096 relocation = htab->elf.sgotplt->output_section->vma
3097 + htab->elf.sgotplt->output_offset;
3098 unresolved_reloc = FALSE;
3101 case R_X86_64_PLTOFF64:
3102 /* Relocation is PLT entry relative to GOT. For local
3103 symbols it's the symbol itself relative to GOT. */
3105 /* See PLT32 handling. */
3106 && (h->plt.offset != (bfd_vma) -1
3107 || eh->plt_got.offset != (bfd_vma) -1)
3108 && htab->elf.splt != NULL)
3110 if (eh->plt_got.offset != (bfd_vma) -1)
3112 /* Use the GOT PLT. */
3113 resolved_plt = htab->plt_got;
3114 plt_offset = eh->plt_got.offset;
3116 else if (htab->plt_second != NULL)
3118 resolved_plt = htab->plt_second;
3119 plt_offset = eh->plt_second.offset;
3123 resolved_plt = htab->elf.splt;
3124 plt_offset = h->plt.offset;
3127 relocation = (resolved_plt->output_section->vma
3128 + resolved_plt->output_offset
3130 unresolved_reloc = FALSE;
3133 relocation -= htab->elf.sgotplt->output_section->vma
3134 + htab->elf.sgotplt->output_offset;
3137 case R_X86_64_PLT32:
3138 case R_X86_64_PLT32_BND:
3139 /* Relocation is to the entry for this symbol in the
3140 procedure linkage table. */
3142 /* Resolve a PLT32 reloc against a local symbol directly,
3143 without using the procedure linkage table. */
3147 if ((h->plt.offset == (bfd_vma) -1
3148 && eh->plt_got.offset == (bfd_vma) -1)
3149 || htab->elf.splt == NULL)
3151 /* We didn't make a PLT entry for this symbol. This
3152 happens when statically linking PIC code, or when
3153 using -Bsymbolic. */
3157 if (h->plt.offset != (bfd_vma) -1)
3159 if (htab->plt_second != NULL)
3161 resolved_plt = htab->plt_second;
3162 plt_offset = eh->plt_second.offset;
3166 resolved_plt = htab->elf.splt;
3167 plt_offset = h->plt.offset;
3172 /* Use the GOT PLT. */
3173 resolved_plt = htab->plt_got;
3174 plt_offset = eh->plt_got.offset;
3177 relocation = (resolved_plt->output_section->vma
3178 + resolved_plt->output_offset
3180 unresolved_reloc = FALSE;
3183 case R_X86_64_SIZE32:
3184 case R_X86_64_SIZE64:
3185 /* Set to symbol size. */
3186 relocation = st_size;
3192 case R_X86_64_PC32_BND:
3193 /* Don't complain about -fPIC if the symbol is undefined when
3194 building executable unless it is unresolved weak symbol or
3195 -z nocopyreloc is used. */
3196 if ((input_section->flags & SEC_ALLOC) != 0
3197 && (input_section->flags & SEC_READONLY) != 0
3199 && ((bfd_link_executable (info)
3200 && ((h->root.type == bfd_link_hash_undefweak
3201 && !resolved_to_zero)
3202 || ((info->nocopyreloc
3203 || (eh->def_protected
3204 && elf_has_no_copy_on_protected (h->root.u.def.section->owner)))
3206 && !(h->root.u.def.section->flags & SEC_CODE))))
3207 || bfd_link_dll (info)))
3209 bfd_boolean fail = FALSE;
3211 = ((r_type == R_X86_64_PC32
3212 || r_type == R_X86_64_PC32_BND)
3213 && is_32bit_relative_branch (contents, rel->r_offset));
3215 if (SYMBOL_REFERENCES_LOCAL (info, h))
3217 /* Symbol is referenced locally. Make sure it is
3218 defined locally or for a branch. */
3219 fail = (!(h->def_regular || ELF_COMMON_DEF_P (h))
3222 else if (!(bfd_link_pie (info)
3223 && (h->needs_copy || eh->needs_copy)))
3225 /* Symbol doesn't need copy reloc and isn't referenced
3226 locally. We only allow branch to symbol with
3227 non-default visibility. */
3229 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
3233 return elf_x86_64_need_pic (info, input_bfd, input_section,
3234 h, NULL, NULL, howto);
3243 /* FIXME: The ABI says the linker should make sure the value is
3244 the same when it's zeroextended to 64 bit. */
3247 if ((input_section->flags & SEC_ALLOC) == 0)
3250 /* Don't copy a pc-relative relocation into the output file
3251 if the symbol needs copy reloc or the symbol is undefined
3252 when building executable. Copy dynamic function pointer
3253 relocations. Don't generate dynamic relocations against
3254 resolved undefined weak symbols in PIE. */
3255 if ((bfd_link_pic (info)
3256 && !(bfd_link_pie (info)
3260 || h->root.type == bfd_link_hash_undefined)
3261 && (IS_X86_64_PCREL_TYPE (r_type)
3262 || r_type == R_X86_64_SIZE32
3263 || r_type == R_X86_64_SIZE64))
3265 || ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3266 && !resolved_to_zero)
3267 || h->root.type != bfd_link_hash_undefweak))
3268 && ((! IS_X86_64_PCREL_TYPE (r_type)
3269 && r_type != R_X86_64_SIZE32
3270 && r_type != R_X86_64_SIZE64)
3271 || ! SYMBOL_CALLS_LOCAL (info, h)))
3272 || (ELIMINATE_COPY_RELOCS
3273 && !bfd_link_pic (info)
3277 || eh->func_pointer_refcount > 0
3278 || (h->root.type == bfd_link_hash_undefweak
3279 && !resolved_to_zero))
3280 && ((h->def_dynamic && !h->def_regular)
3281 /* Undefined weak symbol is bound locally when
3283 || h->root.type == bfd_link_hash_undefined)))
3285 Elf_Internal_Rela outrel;
3286 bfd_boolean skip, relocate;
3289 /* When generating a shared object, these relocations
3290 are copied into the output file to be resolved at run
3296 _bfd_elf_section_offset (output_bfd, info, input_section,
3298 if (outrel.r_offset == (bfd_vma) -1)
3300 else if (outrel.r_offset == (bfd_vma) -2)
3301 skip = TRUE, relocate = TRUE;
3303 outrel.r_offset += (input_section->output_section->vma
3304 + input_section->output_offset);
3307 memset (&outrel, 0, sizeof outrel);
3309 /* h->dynindx may be -1 if this symbol was marked to
3313 && (IS_X86_64_PCREL_TYPE (r_type)
3314 || !(bfd_link_executable (info)
3315 || SYMBOLIC_BIND (info, h))
3316 || ! h->def_regular))
3318 outrel.r_info = htab->r_info (h->dynindx, r_type);
3319 outrel.r_addend = rel->r_addend;
3323 /* This symbol is local, or marked to become local.
3324 When relocation overflow check is disabled, we
3325 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3326 if (r_type == htab->pointer_r_type
3327 || (r_type == R_X86_64_32
3328 && info->no_reloc_overflow_check))
3331 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3332 outrel.r_addend = relocation + rel->r_addend;
3334 else if (r_type == R_X86_64_64
3335 && !ABI_64_P (output_bfd))
3338 outrel.r_info = htab->r_info (0,
3339 R_X86_64_RELATIVE64);
3340 outrel.r_addend = relocation + rel->r_addend;
3341 /* Check addend overflow. */
3342 if ((outrel.r_addend & 0x80000000)
3343 != (rel->r_addend & 0x80000000))
3346 int addend = rel->r_addend;
3347 if (h && h->root.root.string)
3348 name = h->root.root.string;
3350 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
3353 /* xgettext:c-format */
3354 (_("%B: addend %s%#x in relocation %s against "
3355 "symbol `%s' at %#Lx in section `%A' is "
3357 input_bfd, addend < 0 ? "-" : "", addend,
3358 howto->name, name, rel->r_offset, input_section);
3359 bfd_set_error (bfd_error_bad_value);
3367 if (bfd_is_abs_section (sec))
3369 else if (sec == NULL || sec->owner == NULL)
3371 bfd_set_error (bfd_error_bad_value);
3378 /* We are turning this relocation into one
3379 against a section symbol. It would be
3380 proper to subtract the symbol's value,
3381 osec->vma, from the emitted reloc addend,
3382 but ld.so expects buggy relocs. */
3383 osec = sec->output_section;
3384 sindx = elf_section_data (osec)->dynindx;
3387 asection *oi = htab->elf.text_index_section;
3388 sindx = elf_section_data (oi)->dynindx;
3390 BFD_ASSERT (sindx != 0);
3393 outrel.r_info = htab->r_info (sindx, r_type);
3394 outrel.r_addend = relocation + rel->r_addend;
3398 sreloc = elf_section_data (input_section)->sreloc;
3400 if (sreloc == NULL || sreloc->contents == NULL)
3402 r = bfd_reloc_notsupported;
3403 goto check_relocation_error;
3406 elf_append_rela (output_bfd, sreloc, &outrel);
3408 /* If this reloc is against an external symbol, we do
3409 not want to fiddle with the addend. Otherwise, we
3410 need to include the symbol value so that it becomes
3411 an addend for the dynamic reloc. */
3418 case R_X86_64_TLSGD:
3419 case R_X86_64_GOTPC32_TLSDESC:
3420 case R_X86_64_TLSDESC_CALL:
3421 case R_X86_64_GOTTPOFF:
3422 tls_type = GOT_UNKNOWN;
3423 if (h == NULL && local_got_offsets)
3424 tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx];
3426 tls_type = elf_x86_hash_entry (h)->tls_type;
3428 r_type_tls = r_type;
3429 if (! elf_x86_64_tls_transition (info, input_bfd,
3430 input_section, contents,
3431 symtab_hdr, sym_hashes,
3432 &r_type_tls, tls_type, rel,
3433 relend, h, r_symndx, TRUE))
3436 if (r_type_tls == R_X86_64_TPOFF32)
3438 bfd_vma roff = rel->r_offset;
3440 BFD_ASSERT (! unresolved_reloc);
3442 if (r_type == R_X86_64_TLSGD)
3444 /* GD->LE transition. For 64bit, change
3445 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3446 .word 0x6666; rex64; call __tls_get_addr@PLT
3448 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3450 call *__tls_get_addr@GOTPCREL(%rip)
3451 which may be converted to
3452 addr32 call __tls_get_addr
3455 leaq foo@tpoff(%rax), %rax
3457 leaq foo@tlsgd(%rip), %rdi
3458 .word 0x6666; rex64; call __tls_get_addr@PLT
3460 leaq foo@tlsgd(%rip), %rdi
3462 call *__tls_get_addr@GOTPCREL(%rip)
3463 which may be converted to
3464 addr32 call __tls_get_addr
3467 leaq foo@tpoff(%rax), %rax
3468 For largepic, change:
3469 leaq foo@tlsgd(%rip), %rdi
3470 movabsq $__tls_get_addr@pltoff, %rax
3475 leaq foo@tpoff(%rax), %rax
3476 nopw 0x0(%rax,%rax,1) */
3478 if (ABI_64_P (output_bfd))
3480 if (contents[roff + 5] == 0xb8)
3482 memcpy (contents + roff - 3,
3483 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3484 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3488 memcpy (contents + roff - 4,
3489 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3493 memcpy (contents + roff - 3,
3494 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3496 bfd_put_32 (output_bfd,
3497 elf_x86_64_tpoff (info, relocation),
3498 contents + roff + 8 + largepic);
3499 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3500 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3505 else if (r_type == R_X86_64_GOTPC32_TLSDESC)
3507 /* GDesc -> LE transition.
3508 It's originally something like:
3509 leaq x@tlsdesc(%rip), %rax
3512 movl $x@tpoff, %rax. */
3514 unsigned int val, type;
3516 type = bfd_get_8 (input_bfd, contents + roff - 3);
3517 val = bfd_get_8 (input_bfd, contents + roff - 1);
3518 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
3519 contents + roff - 3);
3520 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
3521 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3522 contents + roff - 1);
3523 bfd_put_32 (output_bfd,
3524 elf_x86_64_tpoff (info, relocation),
3528 else if (r_type == R_X86_64_TLSDESC_CALL)
3530 /* GDesc -> LE transition.
3535 bfd_put_8 (output_bfd, 0x66, contents + roff);
3536 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3539 else if (r_type == R_X86_64_GOTTPOFF)
3541 /* IE->LE transition:
3542 For 64bit, originally it can be one of:
3543 movq foo@gottpoff(%rip), %reg
3544 addq foo@gottpoff(%rip), %reg
3547 leaq foo(%reg), %reg
3549 For 32bit, originally it can be one of:
3550 movq foo@gottpoff(%rip), %reg
3551 addl foo@gottpoff(%rip), %reg
3554 leal foo(%reg), %reg
3557 unsigned int val, type, reg;
3560 val = bfd_get_8 (input_bfd, contents + roff - 3);
3563 type = bfd_get_8 (input_bfd, contents + roff - 2);
3564 reg = bfd_get_8 (input_bfd, contents + roff - 1);
3570 bfd_put_8 (output_bfd, 0x49,
3571 contents + roff - 3);
3572 else if (!ABI_64_P (output_bfd) && val == 0x44)
3573 bfd_put_8 (output_bfd, 0x41,
3574 contents + roff - 3);
3575 bfd_put_8 (output_bfd, 0xc7,
3576 contents + roff - 2);
3577 bfd_put_8 (output_bfd, 0xc0 | reg,
3578 contents + roff - 1);
3582 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3585 bfd_put_8 (output_bfd, 0x49,
3586 contents + roff - 3);
3587 else if (!ABI_64_P (output_bfd) && val == 0x44)
3588 bfd_put_8 (output_bfd, 0x41,
3589 contents + roff - 3);
3590 bfd_put_8 (output_bfd, 0x81,
3591 contents + roff - 2);
3592 bfd_put_8 (output_bfd, 0xc0 | reg,
3593 contents + roff - 1);
3597 /* addq/addl -> leaq/leal */
3599 bfd_put_8 (output_bfd, 0x4d,
3600 contents + roff - 3);
3601 else if (!ABI_64_P (output_bfd) && val == 0x44)
3602 bfd_put_8 (output_bfd, 0x45,
3603 contents + roff - 3);
3604 bfd_put_8 (output_bfd, 0x8d,
3605 contents + roff - 2);
3606 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
3607 contents + roff - 1);
3609 bfd_put_32 (output_bfd,
3610 elf_x86_64_tpoff (info, relocation),
3618 if (htab->elf.sgot == NULL)
3623 off = h->got.offset;
3624 offplt = elf_x86_hash_entry (h)->tlsdesc_got;
3628 if (local_got_offsets == NULL)
3631 off = local_got_offsets[r_symndx];
3632 offplt = local_tlsdesc_gotents[r_symndx];
3639 Elf_Internal_Rela outrel;
3643 if (htab->elf.srelgot == NULL)
3646 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3648 if (GOT_TLS_GDESC_P (tls_type))
3650 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
3651 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3652 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
3653 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3654 + htab->elf.sgotplt->output_offset
3656 + htab->sgotplt_jump_table_size);
3657 sreloc = htab->elf.srelplt;
3659 outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
3661 outrel.r_addend = 0;
3662 elf_append_rela (output_bfd, sreloc, &outrel);
3665 sreloc = htab->elf.srelgot;
3667 outrel.r_offset = (htab->elf.sgot->output_section->vma
3668 + htab->elf.sgot->output_offset + off);
3670 if (GOT_TLS_GD_P (tls_type))
3671 dr_type = R_X86_64_DTPMOD64;
3672 else if (GOT_TLS_GDESC_P (tls_type))
3675 dr_type = R_X86_64_TPOFF64;
3677 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
3678 outrel.r_addend = 0;
3679 if ((dr_type == R_X86_64_TPOFF64
3680 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3681 outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
3682 outrel.r_info = htab->r_info (indx, dr_type);
3684 elf_append_rela (output_bfd, sreloc, &outrel);
3686 if (GOT_TLS_GD_P (tls_type))
3690 BFD_ASSERT (! unresolved_reloc);
3691 bfd_put_64 (output_bfd,
3692 relocation - _bfd_x86_elf_dtpoff_base (info),
3693 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3697 bfd_put_64 (output_bfd, 0,
3698 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3699 outrel.r_info = htab->r_info (indx,
3701 outrel.r_offset += GOT_ENTRY_SIZE;
3702 elf_append_rela (output_bfd, sreloc,
3711 local_got_offsets[r_symndx] |= 1;
3714 if (off >= (bfd_vma) -2
3715 && ! GOT_TLS_GDESC_P (tls_type))
3717 if (r_type_tls == r_type)
3719 if (r_type == R_X86_64_GOTPC32_TLSDESC
3720 || r_type == R_X86_64_TLSDESC_CALL)
3721 relocation = htab->elf.sgotplt->output_section->vma
3722 + htab->elf.sgotplt->output_offset
3723 + offplt + htab->sgotplt_jump_table_size;
3725 relocation = htab->elf.sgot->output_section->vma
3726 + htab->elf.sgot->output_offset + off;
3727 unresolved_reloc = FALSE;
3731 bfd_vma roff = rel->r_offset;
3733 if (r_type == R_X86_64_TLSGD)
3735 /* GD->IE transition. For 64bit, change
3736 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3737 .word 0x6666; rex64; call __tls_get_addr@PLT
3739 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3741 call *__tls_get_addr@GOTPCREL(%rip
3742 which may be converted to
3743 addr32 call __tls_get_addr
3746 addq foo@gottpoff(%rip), %rax
3748 leaq foo@tlsgd(%rip), %rdi
3749 .word 0x6666; rex64; call __tls_get_addr@PLT
3751 leaq foo@tlsgd(%rip), %rdi
3753 call *__tls_get_addr@GOTPCREL(%rip)
3754 which may be converted to
3755 addr32 call __tls_get_addr
3758 addq foo@gottpoff(%rip), %rax
3759 For largepic, change:
3760 leaq foo@tlsgd(%rip), %rdi
3761 movabsq $__tls_get_addr@pltoff, %rax
3766 addq foo@gottpoff(%rax), %rax
3767 nopw 0x0(%rax,%rax,1) */
3769 if (ABI_64_P (output_bfd))
3771 if (contents[roff + 5] == 0xb8)
3773 memcpy (contents + roff - 3,
3774 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3775 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3779 memcpy (contents + roff - 4,
3780 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3784 memcpy (contents + roff - 3,
3785 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3788 relocation = (htab->elf.sgot->output_section->vma
3789 + htab->elf.sgot->output_offset + off
3792 - input_section->output_section->vma
3793 - input_section->output_offset
3795 bfd_put_32 (output_bfd, relocation,
3796 contents + roff + 8 + largepic);
3797 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3802 else if (r_type == R_X86_64_GOTPC32_TLSDESC)
3804 /* GDesc -> IE transition.
3805 It's originally something like:
3806 leaq x@tlsdesc(%rip), %rax
3809 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3811 /* Now modify the instruction as appropriate. To
3812 turn a leaq into a movq in the form we use it, it
3813 suffices to change the second byte from 0x8d to
3815 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3817 bfd_put_32 (output_bfd,
3818 htab->elf.sgot->output_section->vma
3819 + htab->elf.sgot->output_offset + off
3821 - input_section->output_section->vma
3822 - input_section->output_offset
3827 else if (r_type == R_X86_64_TLSDESC_CALL)
3829 /* GDesc -> IE transition.
3836 bfd_put_8 (output_bfd, 0x66, contents + roff);
3837 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3845 case R_X86_64_TLSLD:
3846 if (! elf_x86_64_tls_transition (info, input_bfd,
3847 input_section, contents,
3848 symtab_hdr, sym_hashes,
3849 &r_type, GOT_UNKNOWN, rel,
3850 relend, h, r_symndx, TRUE))
3853 if (r_type != R_X86_64_TLSLD)
3855 /* LD->LE transition:
3856 leaq foo@tlsld(%rip), %rdi
3857 call __tls_get_addr@PLT
3858 For 64bit, we change it into:
3859 .word 0x6666; .byte 0x66; movq %fs:0, %rax
3860 For 32bit, we change it into:
3861 nopl 0x0(%rax); movl %fs:0, %eax
3863 leaq foo@tlsld(%rip), %rdi;
3864 call *__tls_get_addr@GOTPCREL(%rip)
3865 which may be converted to
3866 addr32 call __tls_get_addr
3867 For 64bit, we change it into:
3868 .word 0x6666; .word 0x6666; movq %fs:0, %rax
3869 For 32bit, we change it into:
3870 nopw 0x0(%rax); movl %fs:0, %eax
3871 For largepic, change:
3872 leaq foo@tlsgd(%rip), %rdi
3873 movabsq $__tls_get_addr@pltoff, %rax
3877 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
3880 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3881 if (ABI_64_P (output_bfd))
3883 if (contents[rel->r_offset + 5] == 0xb8)
3884 memcpy (contents + rel->r_offset - 3,
3885 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
3886 "\x64\x48\x8b\x04\x25\0\0\0", 22);
3887 else if (contents[rel->r_offset + 4] == 0xff
3888 || contents[rel->r_offset + 4] == 0x67)
3889 memcpy (contents + rel->r_offset - 3,
3890 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
3893 memcpy (contents + rel->r_offset - 3,
3894 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3898 if (contents[rel->r_offset + 4] == 0xff)
3899 memcpy (contents + rel->r_offset - 3,
3900 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
3903 memcpy (contents + rel->r_offset - 3,
3904 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3906 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
3907 and R_X86_64_PLTOFF64. */
3913 if (htab->elf.sgot == NULL)
3916 off = htab->tls_ld_or_ldm_got.offset;
3921 Elf_Internal_Rela outrel;
3923 if (htab->elf.srelgot == NULL)
3926 outrel.r_offset = (htab->elf.sgot->output_section->vma
3927 + htab->elf.sgot->output_offset + off);
3929 bfd_put_64 (output_bfd, 0,
3930 htab->elf.sgot->contents + off);
3931 bfd_put_64 (output_bfd, 0,
3932 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3933 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
3934 outrel.r_addend = 0;
3935 elf_append_rela (output_bfd, htab->elf.srelgot,
3937 htab->tls_ld_or_ldm_got.offset |= 1;
3939 relocation = htab->elf.sgot->output_section->vma
3940 + htab->elf.sgot->output_offset + off;
3941 unresolved_reloc = FALSE;
3944 case R_X86_64_DTPOFF32:
3945 if (!bfd_link_executable (info)
3946 || (input_section->flags & SEC_CODE) == 0)
3947 relocation -= _bfd_x86_elf_dtpoff_base (info);
3949 relocation = elf_x86_64_tpoff (info, relocation);
3952 case R_X86_64_TPOFF32:
3953 case R_X86_64_TPOFF64:
3954 BFD_ASSERT (bfd_link_executable (info));
3955 relocation = elf_x86_64_tpoff (info, relocation);
3958 case R_X86_64_DTPOFF64:
3959 BFD_ASSERT ((input_section->flags & SEC_CODE) == 0);
3960 relocation -= _bfd_x86_elf_dtpoff_base (info);
3967 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3968 because such sections are not SEC_ALLOC and thus ld.so will
3969 not process them. */
3970 if (unresolved_reloc
3971 && !((input_section->flags & SEC_DEBUGGING) != 0
3973 && _bfd_elf_section_offset (output_bfd, info, input_section,
3974 rel->r_offset) != (bfd_vma) -1)
3979 sec = h->root.u.def.section;
3980 if ((info->nocopyreloc
3981 || (eh->def_protected
3982 && elf_has_no_copy_on_protected (h->root.u.def.section->owner)))
3983 && !(h->root.u.def.section->flags & SEC_CODE))
3984 return elf_x86_64_need_pic (info, input_bfd, input_section,
3985 h, NULL, NULL, howto);
3990 /* xgettext:c-format */
3991 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3996 h->root.root.string);
4002 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4003 contents, rel->r_offset,
4004 relocation, rel->r_addend);
4006 check_relocation_error:
4007 if (r != bfd_reloc_ok)
4012 name = h->root.root.string;
4015 name = bfd_elf_string_from_elf_section (input_bfd,
4016 symtab_hdr->sh_link,
4021 name = bfd_section_name (input_bfd, sec);
4024 if (r == bfd_reloc_overflow)
4026 if (converted_reloc)
4028 info->callbacks->einfo
4029 (_("%F%P: failed to convert GOTPCREL relocation; relink with --no-relax\n"));
4032 (*info->callbacks->reloc_overflow)
4033 (info, (h ? &h->root : NULL), name, howto->name,
4034 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4039 /* xgettext:c-format */
4040 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4041 input_bfd, input_section,
4042 rel->r_offset, name, (int) r);
4053 Elf_Internal_Shdr *rel_hdr;
4054 size_t deleted = rel - wrel;
4056 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
4057 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
4058 if (rel_hdr->sh_size == 0)
4060 /* It is too late to remove an empty reloc section. Leave
4062 ??? What is wrong with an empty section??? */
4063 rel_hdr->sh_size = rel_hdr->sh_entsize;
4066 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
4067 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
4068 input_section->reloc_count -= deleted;
4074 /* Finish up dynamic symbol handling. We set the contents of various
4075 dynamic sections here. */
4078 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
4079 struct bfd_link_info *info,
4080 struct elf_link_hash_entry *h,
4081 Elf_Internal_Sym *sym)
4083 struct elf_x86_link_hash_table *htab;
4084 bfd_boolean use_plt_second;
4085 struct elf_x86_link_hash_entry *eh;
4086 bfd_boolean local_undefweak;
4088 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
4092 /* Use the second PLT section only if there is .plt section. */
4093 use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
4095 eh = (struct elf_x86_link_hash_entry *) h;
4096 if (eh->no_finish_dynamic_symbol)
4099 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4100 resolved undefined weak symbols in executable so that their
4101 references have value 0 at run-time. */
4102 local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
4107 if (h->plt.offset != (bfd_vma) -1)
4110 bfd_vma got_offset, plt_offset;
4111 Elf_Internal_Rela rela;
4113 asection *plt, *gotplt, *relplt, *resolved_plt;
4114 const struct elf_backend_data *bed;
4115 bfd_vma plt_got_pcrel_offset;
4117 /* When building a static executable, use .iplt, .igot.plt and
4118 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4119 if (htab->elf.splt != NULL)
4121 plt = htab->elf.splt;
4122 gotplt = htab->elf.sgotplt;
4123 relplt = htab->elf.srelplt;
4127 plt = htab->elf.iplt;
4128 gotplt = htab->elf.igotplt;
4129 relplt = htab->elf.irelplt;
4132 /* This symbol has an entry in the procedure linkage table. Set
4134 if ((h->dynindx == -1
4136 && !((h->forced_local || bfd_link_executable (info))
4138 && h->type == STT_GNU_IFUNC))
4144 /* Get the index in the procedure linkage table which
4145 corresponds to this symbol. This is the index of this symbol
4146 in all the symbols for which we are making plt entries. The
4147 first entry in the procedure linkage table is reserved.
4149 Get the offset into the .got table of the entry that
4150 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4151 bytes. The first three are reserved for the dynamic linker.
4153 For static executables, we don't reserve anything. */
4155 if (plt == htab->elf.splt)
4157 got_offset = (h->plt.offset / htab->plt.plt_entry_size
4158 - htab->plt.has_plt0);
4159 got_offset = (got_offset + 3) * GOT_ENTRY_SIZE;
4163 got_offset = h->plt.offset / htab->plt.plt_entry_size;
4164 got_offset = got_offset * GOT_ENTRY_SIZE;
4167 /* Fill in the entry in the procedure linkage table. */
4168 memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry,
4169 htab->plt.plt_entry_size);
4172 memcpy (htab->plt_second->contents + eh->plt_second.offset,
4173 htab->non_lazy_plt->plt_entry,
4174 htab->non_lazy_plt->plt_entry_size);
4176 resolved_plt = htab->plt_second;
4177 plt_offset = eh->plt_second.offset;
4182 plt_offset = h->plt.offset;
4185 /* Insert the relocation positions of the plt section. */
4187 /* Put offset the PC-relative instruction referring to the GOT entry,
4188 subtracting the size of that instruction. */
4189 plt_got_pcrel_offset = (gotplt->output_section->vma
4190 + gotplt->output_offset
4192 - resolved_plt->output_section->vma
4193 - resolved_plt->output_offset
4195 - htab->plt.plt_got_insn_size);
4197 /* Check PC-relative offset overflow in PLT entry. */
4198 if ((plt_got_pcrel_offset + 0x80000000) > 0xffffffff)
4199 /* xgettext:c-format */
4200 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
4201 output_bfd, h->root.root.string);
4203 bfd_put_32 (output_bfd, plt_got_pcrel_offset,
4204 (resolved_plt->contents + plt_offset
4205 + htab->plt.plt_got_offset));
4207 /* Fill in the entry in the global offset table, initially this
4208 points to the second part of the PLT entry. Leave the entry
4209 as zero for undefined weak symbol in PIE. No PLT relocation
4210 against undefined weak symbol in PIE. */
4211 if (!local_undefweak)
4213 if (htab->plt.has_plt0)
4214 bfd_put_64 (output_bfd, (plt->output_section->vma
4215 + plt->output_offset
4217 + htab->lazy_plt->plt_lazy_offset),
4218 gotplt->contents + got_offset);
4220 /* Fill in the entry in the .rela.plt section. */
4221 rela.r_offset = (gotplt->output_section->vma
4222 + gotplt->output_offset
4224 if (h->dynindx == -1
4225 || ((bfd_link_executable (info)
4226 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4228 && h->type == STT_GNU_IFUNC))
4230 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
4231 h->root.root.string,
4232 h->root.u.def.section->owner);
4234 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4235 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4236 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
4237 rela.r_addend = (h->root.u.def.value
4238 + h->root.u.def.section->output_section->vma
4239 + h->root.u.def.section->output_offset);
4240 /* R_X86_64_IRELATIVE comes last. */
4241 plt_index = htab->next_irelative_index--;
4245 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
4247 plt_index = htab->next_jump_slot_index++;
4250 /* Don't fill the second and third slots in PLT entry for
4251 static executables nor without PLT0. */
4252 if (plt == htab->elf.splt && htab->plt.has_plt0)
4255 = h->plt.offset + htab->lazy_plt->plt_plt_insn_end;
4257 /* Put relocation index. */
4258 bfd_put_32 (output_bfd, plt_index,
4259 (plt->contents + h->plt.offset
4260 + htab->lazy_plt->plt_reloc_offset));
4262 /* Put offset for jmp .PLT0 and check for overflow. We don't
4263 check relocation index for overflow since branch displacement
4264 will overflow first. */
4265 if (plt0_offset > 0x80000000)
4266 /* xgettext:c-format */
4267 info->callbacks->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
4268 output_bfd, h->root.root.string);
4269 bfd_put_32 (output_bfd, - plt0_offset,
4270 (plt->contents + h->plt.offset
4271 + htab->lazy_plt->plt_plt_offset));
4274 bed = get_elf_backend_data (output_bfd);
4275 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
4276 bed->s->swap_reloca_out (output_bfd, &rela, loc);
4279 else if (eh->plt_got.offset != (bfd_vma) -1)
4281 bfd_vma got_offset, plt_offset;
4282 asection *plt, *got;
4283 bfd_boolean got_after_plt;
4284 int32_t got_pcrel_offset;
4286 /* Set the entry in the GOT procedure linkage table. */
4287 plt = htab->plt_got;
4288 got = htab->elf.sgot;
4289 got_offset = h->got.offset;
4291 if (got_offset == (bfd_vma) -1
4292 || (h->type == STT_GNU_IFUNC && h->def_regular)
4297 /* Use the non-lazy PLT entry template for the GOT PLT since they
4298 are the identical. */
4299 /* Fill in the entry in the GOT procedure linkage table. */
4300 plt_offset = eh->plt_got.offset;
4301 memcpy (plt->contents + plt_offset,
4302 htab->non_lazy_plt->plt_entry,
4303 htab->non_lazy_plt->plt_entry_size);
4305 /* Put offset the PC-relative instruction referring to the GOT
4306 entry, subtracting the size of that instruction. */
4307 got_pcrel_offset = (got->output_section->vma
4308 + got->output_offset
4310 - plt->output_section->vma
4311 - plt->output_offset
4313 - htab->non_lazy_plt->plt_got_insn_size);
4315 /* Check PC-relative offset overflow in GOT PLT entry. */
4316 got_after_plt = got->output_section->vma > plt->output_section->vma;
4317 if ((got_after_plt && got_pcrel_offset < 0)
4318 || (!got_after_plt && got_pcrel_offset > 0))
4319 /* xgettext:c-format */
4320 info->callbacks->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4321 output_bfd, h->root.root.string);
4323 bfd_put_32 (output_bfd, got_pcrel_offset,
4324 (plt->contents + plt_offset
4325 + htab->non_lazy_plt->plt_got_offset));
4328 if (!local_undefweak
4330 && (h->plt.offset != (bfd_vma) -1
4331 || eh->plt_got.offset != (bfd_vma) -1))
4333 /* Mark the symbol as undefined, rather than as defined in
4334 the .plt section. Leave the value if there were any
4335 relocations where pointer equality matters (this is a clue
4336 for the dynamic linker, to make function pointer
4337 comparisons work between an application and shared
4338 library), otherwise set it to zero. If a function is only
4339 called from a binary, there is no need to slow down
4340 shared libraries because of that. */
4341 sym->st_shndx = SHN_UNDEF;
4342 if (!h->pointer_equality_needed)
4346 /* Don't generate dynamic GOT relocation against undefined weak
4347 symbol in executable. */
4348 if (h->got.offset != (bfd_vma) -1
4349 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h)->tls_type)
4350 && elf_x86_hash_entry (h)->tls_type != GOT_TLS_IE
4351 && !local_undefweak)
4353 Elf_Internal_Rela rela;
4354 asection *relgot = htab->elf.srelgot;
4356 /* This symbol has an entry in the global offset table. Set it
4358 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
4361 rela.r_offset = (htab->elf.sgot->output_section->vma
4362 + htab->elf.sgot->output_offset
4363 + (h->got.offset &~ (bfd_vma) 1));
4365 /* If this is a static link, or it is a -Bsymbolic link and the
4366 symbol is defined locally or was forced to be local because
4367 of a version file, we just want to emit a RELATIVE reloc.
4368 The entry in the global offset table will already have been
4369 initialized in the relocate_section function. */
4371 && h->type == STT_GNU_IFUNC)
4373 if (h->plt.offset == (bfd_vma) -1)
4375 /* STT_GNU_IFUNC is referenced without PLT. */
4376 if (htab->elf.splt == NULL)
4378 /* use .rel[a].iplt section to store .got relocations
4379 in static executable. */
4380 relgot = htab->elf.irelplt;
4382 if (SYMBOL_REFERENCES_LOCAL (info, h))
4384 info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
4386 h->root.root.string,
4387 h->root.u.def.section->owner);
4389 rela.r_info = htab->r_info (0,
4390 R_X86_64_IRELATIVE);
4391 rela.r_addend = (h->root.u.def.value
4392 + h->root.u.def.section->output_section->vma
4393 + h->root.u.def.section->output_offset);
4398 else if (bfd_link_pic (info))
4400 /* Generate R_X86_64_GLOB_DAT. */
4408 if (!h->pointer_equality_needed)
4411 /* For non-shared object, we can't use .got.plt, which
4412 contains the real function addres if we need pointer
4413 equality. We load the GOT entry with the PLT entry. */
4414 if (htab->plt_second != NULL)
4416 plt = htab->plt_second;
4417 plt_offset = eh->plt_second.offset;
4421 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4422 plt_offset = h->plt.offset;
4424 bfd_put_64 (output_bfd, (plt->output_section->vma
4425 + plt->output_offset
4427 htab->elf.sgot->contents + h->got.offset);
4431 else if (bfd_link_pic (info)
4432 && SYMBOL_REFERENCES_LOCAL (info, h))
4434 if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
4436 BFD_ASSERT((h->got.offset & 1) != 0);
4437 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4438 rela.r_addend = (h->root.u.def.value
4439 + h->root.u.def.section->output_section->vma
4440 + h->root.u.def.section->output_offset);
4444 BFD_ASSERT((h->got.offset & 1) == 0);
4446 bfd_put_64 (output_bfd, (bfd_vma) 0,
4447 htab->elf.sgot->contents + h->got.offset);
4448 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
4452 elf_append_rela (output_bfd, relgot, &rela);
4457 Elf_Internal_Rela rela;
4460 /* This symbol needs a copy reloc. Set it up. */
4462 if (h->dynindx == -1
4463 || (h->root.type != bfd_link_hash_defined
4464 && h->root.type != bfd_link_hash_defweak)
4465 || htab->elf.srelbss == NULL
4466 || htab->elf.sreldynrelro == NULL)
4469 rela.r_offset = (h->root.u.def.value
4470 + h->root.u.def.section->output_section->vma
4471 + h->root.u.def.section->output_offset);
4472 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
4474 if (h->root.u.def.section == htab->elf.sdynrelro)
4475 s = htab->elf.sreldynrelro;
4477 s = htab->elf.srelbss;
4478 elf_append_rela (output_bfd, s, &rela);
4484 /* Finish up local dynamic symbol handling. We set the contents of
4485 various dynamic sections here. */
4488 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
4490 struct elf_link_hash_entry *h
4491 = (struct elf_link_hash_entry *) *slot;
4492 struct bfd_link_info *info
4493 = (struct bfd_link_info *) inf;
4495 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
4499 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4500 here since undefined weak symbol may not be dynamic and may not be
4501 called for elf_x86_64_finish_dynamic_symbol. */
4504 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
4507 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
4508 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4510 if (h->root.type != bfd_link_hash_undefweak
4511 || h->dynindx != -1)
4514 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
4518 /* Used to decide how to sort relocs in an optimal manner for the
4519 dynamic linker, before writing them out. */
4521 static enum elf_reloc_type_class
4522 elf_x86_64_reloc_type_class (const struct bfd_link_info *info,
4523 const asection *rel_sec ATTRIBUTE_UNUSED,
4524 const Elf_Internal_Rela *rela)
4526 bfd *abfd = info->output_bfd;
4527 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4528 struct elf_x86_link_hash_table *htab
4529 = elf_x86_hash_table (info, X86_64_ELF_DATA);
4531 if (htab->elf.dynsym != NULL
4532 && htab->elf.dynsym->contents != NULL)
4534 /* Check relocation against STT_GNU_IFUNC symbol if there are
4536 unsigned long r_symndx = htab->r_sym (rela->r_info);
4537 if (r_symndx != STN_UNDEF)
4539 Elf_Internal_Sym sym;
4540 if (!bed->s->swap_symbol_in (abfd,
4541 (htab->elf.dynsym->contents
4542 + r_symndx * bed->s->sizeof_sym),
4546 if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
4547 return reloc_class_ifunc;
4551 switch ((int) ELF32_R_TYPE (rela->r_info))
4553 case R_X86_64_IRELATIVE:
4554 return reloc_class_ifunc;
4555 case R_X86_64_RELATIVE:
4556 case R_X86_64_RELATIVE64:
4557 return reloc_class_relative;
4558 case R_X86_64_JUMP_SLOT:
4559 return reloc_class_plt;
4561 return reloc_class_copy;
4563 return reloc_class_normal;
4567 /* Finish up the dynamic sections. */
4570 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
4571 struct bfd_link_info *info)
4573 struct elf_x86_link_hash_table *htab;
4577 htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
4581 dynobj = htab->elf.dynobj;
4582 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4584 if (htab->elf.dynamic_sections_created)
4586 bfd_byte *dyncon, *dynconend;
4587 const struct elf_backend_data *bed;
4588 bfd_size_type sizeof_dyn;
4590 if (sdyn == NULL || htab->elf.sgot == NULL)
4593 bed = get_elf_backend_data (dynobj);
4594 sizeof_dyn = bed->s->sizeof_dyn;
4595 dyncon = sdyn->contents;
4596 dynconend = sdyn->contents + sdyn->size;
4597 for (; dyncon < dynconend; dyncon += sizeof_dyn)
4599 Elf_Internal_Dyn dyn;
4602 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
4610 s = htab->elf.sgotplt;
4611 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4615 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
4619 s = htab->elf.srelplt->output_section;
4620 dyn.d_un.d_val = s->size;
4623 case DT_TLSDESC_PLT:
4625 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4626 + htab->tlsdesc_plt;
4629 case DT_TLSDESC_GOT:
4631 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4632 + htab->tlsdesc_got;
4636 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
4639 if (htab->elf.splt && htab->elf.splt->size > 0)
4641 elf_section_data (htab->elf.splt->output_section)
4642 ->this_hdr.sh_entsize = htab->plt.plt_entry_size;
4644 if (htab->plt.has_plt0)
4646 /* Fill in the special first entry in the procedure linkage
4648 memcpy (htab->elf.splt->contents,
4649 htab->lazy_plt->plt0_entry,
4650 htab->lazy_plt->plt0_entry_size);
4651 /* Add offset for pushq GOT+8(%rip), since the instruction
4652 uses 6 bytes subtract this value. */
4653 bfd_put_32 (output_bfd,
4654 (htab->elf.sgotplt->output_section->vma
4655 + htab->elf.sgotplt->output_offset
4657 - htab->elf.splt->output_section->vma
4658 - htab->elf.splt->output_offset
4660 (htab->elf.splt->contents
4661 + htab->lazy_plt->plt0_got1_offset));
4662 /* Add offset for the PC-relative instruction accessing
4663 GOT+16, subtracting the offset to the end of that
4665 bfd_put_32 (output_bfd,
4666 (htab->elf.sgotplt->output_section->vma
4667 + htab->elf.sgotplt->output_offset
4669 - htab->elf.splt->output_section->vma
4670 - htab->elf.splt->output_offset
4671 - htab->lazy_plt->plt0_got2_insn_end),
4672 (htab->elf.splt->contents
4673 + htab->lazy_plt->plt0_got2_offset));
4675 if (htab->tlsdesc_plt)
4677 bfd_put_64 (output_bfd, (bfd_vma) 0,
4678 htab->elf.sgot->contents + htab->tlsdesc_got);
4680 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
4681 htab->lazy_plt->plt0_entry,
4682 htab->lazy_plt->plt0_entry_size);
4684 /* Add offset for pushq GOT+8(%rip), since the
4685 instruction uses 6 bytes subtract this value. */
4686 bfd_put_32 (output_bfd,
4687 (htab->elf.sgotplt->output_section->vma
4688 + htab->elf.sgotplt->output_offset
4690 - htab->elf.splt->output_section->vma
4691 - htab->elf.splt->output_offset
4694 (htab->elf.splt->contents
4696 + htab->lazy_plt->plt0_got1_offset));
4697 /* Add offset for the PC-relative instruction accessing
4698 GOT+TDG, where TDG stands for htab->tlsdesc_got,
4699 subtracting the offset to the end of that
4701 bfd_put_32 (output_bfd,
4702 (htab->elf.sgot->output_section->vma
4703 + htab->elf.sgot->output_offset
4705 - htab->elf.splt->output_section->vma
4706 - htab->elf.splt->output_offset
4708 - htab->lazy_plt->plt0_got2_insn_end),
4709 (htab->elf.splt->contents
4711 + htab->lazy_plt->plt0_got2_offset));
4716 if (htab->plt_got != NULL && htab->plt_got->size > 0)
4717 elf_section_data (htab->plt_got->output_section)
4718 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
4720 if (htab->plt_second != NULL && htab->plt_second->size > 0)
4721 elf_section_data (htab->plt_second->output_section)
4722 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
4725 /* GOT is always created in setup_gnu_properties. But it may not be
4727 if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0)
4729 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
4732 (_("discarded output section: `%A'"), htab->elf.sgotplt);
4736 /* Set the first entry in the global offset table to the address of
4737 the dynamic section. */
4739 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
4741 bfd_put_64 (output_bfd,
4742 sdyn->output_section->vma + sdyn->output_offset,
4743 htab->elf.sgotplt->contents);
4744 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4745 bfd_put_64 (output_bfd, (bfd_vma) 0,
4746 htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
4747 bfd_put_64 (output_bfd, (bfd_vma) 0,
4748 htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
4750 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize
4754 /* Adjust .eh_frame for .plt section. */
4755 if (htab->plt_eh_frame != NULL
4756 && htab->plt_eh_frame->contents != NULL)
4758 if (htab->elf.splt != NULL
4759 && htab->elf.splt->size != 0
4760 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
4761 && htab->elf.splt->output_section != NULL
4762 && htab->plt_eh_frame->output_section != NULL)
4764 bfd_vma plt_start = htab->elf.splt->output_section->vma;
4765 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
4766 + htab->plt_eh_frame->output_offset
4767 + PLT_FDE_START_OFFSET;
4768 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
4769 htab->plt_eh_frame->contents
4770 + PLT_FDE_START_OFFSET);
4772 if (htab->plt_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
4774 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
4776 htab->plt_eh_frame->contents))
4781 /* Adjust .eh_frame for .plt.got section. */
4782 if (htab->plt_got_eh_frame != NULL
4783 && htab->plt_got_eh_frame->contents != NULL)
4785 if (htab->plt_got != NULL
4786 && htab->plt_got->size != 0
4787 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
4788 && htab->plt_got->output_section != NULL
4789 && htab->plt_got_eh_frame->output_section != NULL)
4791 bfd_vma plt_start = htab->plt_got->output_section->vma;
4792 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
4793 + htab->plt_got_eh_frame->output_offset
4794 + PLT_FDE_START_OFFSET;
4795 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
4796 htab->plt_got_eh_frame->contents
4797 + PLT_FDE_START_OFFSET);
4799 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
4801 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
4802 htab->plt_got_eh_frame,
4803 htab->plt_got_eh_frame->contents))
4808 /* Adjust .eh_frame for the second PLT section. */
4809 if (htab->plt_second_eh_frame != NULL
4810 && htab->plt_second_eh_frame->contents != NULL)
4812 if (htab->plt_second != NULL
4813 && htab->plt_second->size != 0
4814 && (htab->plt_second->flags & SEC_EXCLUDE) == 0
4815 && htab->plt_second->output_section != NULL
4816 && htab->plt_second_eh_frame->output_section != NULL)
4818 bfd_vma plt_start = htab->plt_second->output_section->vma;
4819 bfd_vma eh_frame_start
4820 = (htab->plt_second_eh_frame->output_section->vma
4821 + htab->plt_second_eh_frame->output_offset
4822 + PLT_FDE_START_OFFSET);
4823 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
4824 htab->plt_second_eh_frame->contents
4825 + PLT_FDE_START_OFFSET);
4827 if (htab->plt_second_eh_frame->sec_info_type
4828 == SEC_INFO_TYPE_EH_FRAME)
4830 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
4831 htab->plt_second_eh_frame,
4832 htab->plt_second_eh_frame->contents))
4837 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4838 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
4841 /* Fill PLT entries for undefined weak symbols in PIE. */
4842 if (bfd_link_pie (info))
4843 bfd_hash_traverse (&info->hash->table,
4844 elf_x86_64_pie_finish_undefweak_symbol,
4850 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4851 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4852 It has to be done before elf_link_sort_relocs is called so that
4853 dynamic relocations are properly sorted. */
4856 elf_x86_64_output_arch_local_syms
4857 (bfd *output_bfd ATTRIBUTE_UNUSED,
4858 struct bfd_link_info *info,
4859 void *flaginfo ATTRIBUTE_UNUSED,
4860 int (*func) (void *, const char *,
4863 struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
4865 struct elf_x86_link_hash_table *htab
4866 = elf_x86_hash_table (info, X86_64_ELF_DATA);
4870 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4871 htab_traverse (htab->loc_hash_table,
4872 elf_x86_64_finish_local_dynamic_symbol,
4878 /* Forward declaration. */
4879 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt;
4881 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4882 dynamic relocations. */
4885 elf_x86_64_get_synthetic_symtab (bfd *abfd,
4886 long symcount ATTRIBUTE_UNUSED,
4887 asymbol **syms ATTRIBUTE_UNUSED,
4894 bfd_byte *plt_contents;
4896 const struct elf_x86_lazy_plt_layout *lazy_plt;
4897 const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
4898 const struct elf_x86_lazy_plt_layout *lazy_bnd_plt;
4899 const struct elf_x86_non_lazy_plt_layout *non_lazy_bnd_plt;
4900 const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
4901 const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
4903 enum elf_x86_plt_type plt_type;
4904 struct elf_x86_plt plts[] =
4906 { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 },
4907 { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 },
4908 { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 },
4909 { ".plt.bnd", NULL, NULL, plt_second, 0, 0, 0, 0 },
4910 { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }
4915 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
4918 if (dynsymcount <= 0)
4921 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
4925 if (get_elf_x86_64_backend_data (abfd)->os == is_normal)
4927 lazy_plt = &elf_x86_64_lazy_plt;
4928 non_lazy_plt = &elf_x86_64_non_lazy_plt;
4929 lazy_bnd_plt = &elf_x86_64_lazy_bnd_plt;
4930 non_lazy_bnd_plt = &elf_x86_64_non_lazy_bnd_plt;
4931 if (ABI_64_P (abfd))
4933 lazy_ibt_plt = &elf_x86_64_lazy_ibt_plt;
4934 non_lazy_ibt_plt = &elf_x86_64_non_lazy_ibt_plt;
4938 lazy_ibt_plt = &elf_x32_lazy_ibt_plt;
4939 non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt;
4944 lazy_plt = &elf_x86_64_nacl_plt;
4945 non_lazy_plt = NULL;
4946 lazy_bnd_plt = NULL;
4947 non_lazy_bnd_plt = NULL;
4948 lazy_ibt_plt = NULL;
4949 non_lazy_ibt_plt = NULL;
4953 for (j = 0; plts[j].name != NULL; j++)
4955 plt = bfd_get_section_by_name (abfd, plts[j].name);
4956 if (plt == NULL || plt->size == 0)
4959 /* Get the PLT section contents. */
4960 plt_contents = (bfd_byte *) bfd_malloc (plt->size);
4961 if (plt_contents == NULL)
4963 if (!bfd_get_section_contents (abfd, (asection *) plt,
4964 plt_contents, 0, plt->size))
4966 free (plt_contents);
4970 /* Check what kind of PLT it is. */
4971 plt_type = plt_unknown;
4972 if (plts[j].type == plt_unknown
4973 && (plt->size >= (lazy_plt->plt_entry_size
4974 + lazy_plt->plt_entry_size)))
4976 /* Match lazy PLT first. Need to check the first two
4978 if ((memcmp (plt_contents, lazy_plt->plt0_entry,
4979 lazy_plt->plt0_got1_offset) == 0)
4980 && (memcmp (plt_contents + 6, lazy_plt->plt0_entry + 6,
4982 plt_type = plt_lazy;
4983 else if (lazy_bnd_plt != NULL
4984 && (memcmp (plt_contents, lazy_bnd_plt->plt0_entry,
4985 lazy_bnd_plt->plt0_got1_offset) == 0)
4986 && (memcmp (plt_contents + 6,
4987 lazy_bnd_plt->plt0_entry + 6, 3) == 0))
4989 plt_type = plt_lazy | plt_second;
4990 /* The fist entry in the lazy IBT PLT is the same as the
4992 if ((memcmp (plt_contents + lazy_ibt_plt->plt_entry_size,
4993 lazy_ibt_plt->plt_entry,
4994 lazy_ibt_plt->plt_got_offset) == 0))
4995 lazy_plt = lazy_ibt_plt;
4997 lazy_plt = lazy_bnd_plt;
5001 if (non_lazy_plt != NULL
5002 && (plt_type == plt_unknown || plt_type == plt_non_lazy)
5003 && plt->size >= non_lazy_plt->plt_entry_size)
5005 /* Match non-lazy PLT. */
5006 if (memcmp (plt_contents, non_lazy_plt->plt_entry,
5007 non_lazy_plt->plt_got_offset) == 0)
5008 plt_type = plt_non_lazy;
5011 if (plt_type == plt_unknown || plt_type == plt_second)
5013 if (non_lazy_bnd_plt != NULL
5014 && plt->size >= non_lazy_bnd_plt->plt_entry_size
5015 && (memcmp (plt_contents, non_lazy_bnd_plt->plt_entry,
5016 non_lazy_bnd_plt->plt_got_offset) == 0))
5018 /* Match BND PLT. */
5019 plt_type = plt_second;
5020 non_lazy_plt = non_lazy_bnd_plt;
5022 else if (non_lazy_ibt_plt != NULL
5023 && plt->size >= non_lazy_ibt_plt->plt_entry_size
5024 && (memcmp (plt_contents,
5025 non_lazy_ibt_plt->plt_entry,
5026 non_lazy_ibt_plt->plt_got_offset) == 0))
5028 /* Match IBT PLT. */
5029 plt_type = plt_second;
5030 non_lazy_plt = non_lazy_ibt_plt;
5034 if (plt_type == plt_unknown)
5036 free (plt_contents);
5041 plts[j].type = plt_type;
5043 if ((plt_type & plt_lazy))
5045 plts[j].plt_got_offset = lazy_plt->plt_got_offset;
5046 plts[j].plt_got_insn_size = lazy_plt->plt_got_insn_size;
5047 plts[j].plt_entry_size = lazy_plt->plt_entry_size;
5048 /* Skip PLT0 in lazy PLT. */
5053 plts[j].plt_got_offset = non_lazy_plt->plt_got_offset;
5054 plts[j].plt_got_insn_size = non_lazy_plt->plt_got_insn_size;
5055 plts[j].plt_entry_size = non_lazy_plt->plt_entry_size;
5059 /* Skip lazy PLT when the second PLT is used. */
5060 if (plt_type == (plt_lazy | plt_second))
5064 n = plt->size / plts[j].plt_entry_size;
5069 plts[j].contents = plt_contents;
5072 return _bfd_x86_elf_get_synthetic_symtab (abfd, count, relsize,
5073 (bfd_vma) 0, plts, dynsyms,
5077 /* Handle an x86-64 specific section when reading an object file. This
5078 is called when elfcode.h finds a section with an unknown type. */
5081 elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr,
5082 const char *name, int shindex)
5084 if (hdr->sh_type != SHT_X86_64_UNWIND)
5087 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
5093 /* Hook called by the linker routine which adds symbols from an object
5094 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
5098 elf_x86_64_add_symbol_hook (bfd *abfd,
5099 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5100 Elf_Internal_Sym *sym,
5101 const char **namep ATTRIBUTE_UNUSED,
5102 flagword *flagsp ATTRIBUTE_UNUSED,
5108 switch (sym->st_shndx)
5110 case SHN_X86_64_LCOMMON:
5111 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
5114 lcomm = bfd_make_section_with_flags (abfd,
5118 | SEC_LINKER_CREATED));
5121 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
5124 *valp = sym->st_size;
5132 /* Given a BFD section, try to locate the corresponding ELF section
5136 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
5137 asection *sec, int *index_return)
5139 if (sec == &_bfd_elf_large_com_section)
5141 *index_return = SHN_X86_64_LCOMMON;
5147 /* Process a symbol. */
5150 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
5153 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
5155 switch (elfsym->internal_elf_sym.st_shndx)
5157 case SHN_X86_64_LCOMMON:
5158 asym->section = &_bfd_elf_large_com_section;
5159 asym->value = elfsym->internal_elf_sym.st_size;
5160 /* Common symbol doesn't set BSF_GLOBAL. */
5161 asym->flags &= ~BSF_GLOBAL;
5167 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
5169 return (sym->st_shndx == SHN_COMMON
5170 || sym->st_shndx == SHN_X86_64_LCOMMON);
5174 elf_x86_64_common_section_index (asection *sec)
5176 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
5179 return SHN_X86_64_LCOMMON;
5183 elf_x86_64_common_section (asection *sec)
5185 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
5186 return bfd_com_section_ptr;
5188 return &_bfd_elf_large_com_section;
5192 elf_x86_64_merge_symbol (struct elf_link_hash_entry *h,
5193 const Elf_Internal_Sym *sym,
5198 const asection *oldsec)
5200 /* A normal common symbol and a large common symbol result in a
5201 normal common symbol. We turn the large common symbol into a
5204 && h->root.type == bfd_link_hash_common
5206 && bfd_is_com_section (*psec)
5209 if (sym->st_shndx == SHN_COMMON
5210 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) != 0)
5212 h->root.u.c.p->section
5213 = bfd_make_section_old_way (oldbfd, "COMMON");
5214 h->root.u.c.p->section->flags = SEC_ALLOC;
5216 else if (sym->st_shndx == SHN_X86_64_LCOMMON
5217 && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) == 0)
5218 *psec = bfd_com_section_ptr;
5225 elf_x86_64_additional_program_headers (bfd *abfd,
5226 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5231 /* Check to see if we need a large readonly segment. */
5232 s = bfd_get_section_by_name (abfd, ".lrodata");
5233 if (s && (s->flags & SEC_LOAD))
5236 /* Check to see if we need a large data segment. Since .lbss sections
5237 is placed right after the .bss section, there should be no need for
5238 a large data segment just because of .lbss. */
5239 s = bfd_get_section_by_name (abfd, ".ldata");
5240 if (s && (s->flags & SEC_LOAD))
5246 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5249 elf_x86_64_relocs_compatible (const bfd_target *input,
5250 const bfd_target *output)
5252 return ((xvec_get_elf_backend_data (input)->s->elfclass
5253 == xvec_get_elf_backend_data (output)->s->elfclass)
5254 && _bfd_elf_relocs_compatible (input, output));
5257 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5258 with GNU properties if found. Otherwise, return NULL. */
5261 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
5263 struct elf_x86_plt_layout_table plt_layout;
5265 if ((int) R_X86_64_standard >= (int) R_X86_64_converted_reloc_bit
5266 || (int) R_X86_64_max <= (int) R_X86_64_converted_reloc_bit
5267 || ((int) (R_X86_64_GNU_VTINHERIT | R_X86_64_converted_reloc_bit)
5268 != (int) R_X86_64_GNU_VTINHERIT)
5269 || ((int) (R_X86_64_GNU_VTENTRY | R_X86_64_converted_reloc_bit)
5270 != (int) R_X86_64_GNU_VTENTRY))
5273 plt_layout.is_vxworks = FALSE;
5274 if (get_elf_x86_64_backend_data (info->output_bfd)->os == is_normal)
5278 plt_layout.lazy_plt = &elf_x86_64_lazy_bnd_plt;
5279 plt_layout.non_lazy_plt = &elf_x86_64_non_lazy_bnd_plt;
5283 plt_layout.lazy_plt = &elf_x86_64_lazy_plt;
5284 plt_layout.non_lazy_plt = &elf_x86_64_non_lazy_plt;
5287 if (ABI_64_P (info->output_bfd))
5289 plt_layout.lazy_ibt_plt = &elf_x86_64_lazy_ibt_plt;
5290 plt_layout.non_lazy_ibt_plt = &elf_x86_64_non_lazy_ibt_plt;
5294 plt_layout.lazy_ibt_plt = &elf_x32_lazy_ibt_plt;
5295 plt_layout.non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt;
5297 plt_layout.normal_target = TRUE;
5301 plt_layout.lazy_plt = &elf_x86_64_nacl_plt;
5302 plt_layout.non_lazy_plt = NULL;
5303 plt_layout.lazy_ibt_plt = NULL;
5304 plt_layout.non_lazy_ibt_plt = NULL;
5305 plt_layout.normal_target = FALSE;
5308 return _bfd_x86_elf_link_setup_gnu_properties (info, &plt_layout);
5311 static const struct bfd_elf_special_section
5312 elf_x86_64_special_sections[]=
5314 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
5315 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
5316 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
5317 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
5318 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
5319 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
5320 { NULL, 0, 0, 0, 0 }
5323 #define TARGET_LITTLE_SYM x86_64_elf64_vec
5324 #define TARGET_LITTLE_NAME "elf64-x86-64"
5325 #define ELF_ARCH bfd_arch_i386
5326 #define ELF_TARGET_ID X86_64_ELF_DATA
5327 #define ELF_MACHINE_CODE EM_X86_64
5328 #define ELF_MAXPAGESIZE 0x200000
5329 #define ELF_MINPAGESIZE 0x1000
5330 #define ELF_COMMONPAGESIZE 0x1000
5332 #define elf_backend_can_gc_sections 1
5333 #define elf_backend_can_refcount 1
5334 #define elf_backend_want_got_plt 1
5335 #define elf_backend_plt_readonly 1
5336 #define elf_backend_want_plt_sym 0
5337 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5338 #define elf_backend_rela_normal 1
5339 #define elf_backend_plt_alignment 4
5340 #define elf_backend_extern_protected_data 1
5341 #define elf_backend_caches_rawsize 1
5342 #define elf_backend_dtrel_excludes_plt 1
5343 #define elf_backend_want_dynrelro 1
5345 #define elf_info_to_howto elf_x86_64_info_to_howto
5347 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5348 #define bfd_elf64_bfd_reloc_name_lookup \
5349 elf_x86_64_reloc_name_lookup
5351 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5352 #define elf_backend_check_relocs elf_x86_64_check_relocs
5353 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5354 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5355 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5356 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
5357 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5358 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5360 #define elf_backend_write_core_note elf_x86_64_write_core_note
5362 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5363 #define elf_backend_relocate_section elf_x86_64_relocate_section
5364 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5365 #define elf_backend_object_p elf64_x86_64_elf_object_p
5366 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5368 #define elf_backend_section_from_shdr \
5369 elf_x86_64_section_from_shdr
5371 #define elf_backend_section_from_bfd_section \
5372 elf_x86_64_elf_section_from_bfd_section
5373 #define elf_backend_add_symbol_hook \
5374 elf_x86_64_add_symbol_hook
5375 #define elf_backend_symbol_processing \
5376 elf_x86_64_symbol_processing
5377 #define elf_backend_common_section_index \
5378 elf_x86_64_common_section_index
5379 #define elf_backend_common_section \
5380 elf_x86_64_common_section
5381 #define elf_backend_common_definition \
5382 elf_x86_64_common_definition
5383 #define elf_backend_merge_symbol \
5384 elf_x86_64_merge_symbol
5385 #define elf_backend_special_sections \
5386 elf_x86_64_special_sections
5387 #define elf_backend_additional_program_headers \
5388 elf_x86_64_additional_program_headers
5389 #define elf_backend_setup_gnu_properties \
5390 elf_x86_64_link_setup_gnu_properties
5392 #include "elf64-target.h"
5394 /* CloudABI support. */
5396 #undef TARGET_LITTLE_SYM
5397 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
5398 #undef TARGET_LITTLE_NAME
5399 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
5402 #define ELF_OSABI ELFOSABI_CLOUDABI
5405 #define elf64_bed elf64_x86_64_cloudabi_bed
5407 #include "elf64-target.h"
5409 /* FreeBSD support. */
5411 #undef TARGET_LITTLE_SYM
5412 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
5413 #undef TARGET_LITTLE_NAME
5414 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5417 #define ELF_OSABI ELFOSABI_FREEBSD
5420 #define elf64_bed elf64_x86_64_fbsd_bed
5422 #include "elf64-target.h"
5424 /* Solaris 2 support. */
5426 #undef TARGET_LITTLE_SYM
5427 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
5428 #undef TARGET_LITTLE_NAME
5429 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5431 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5432 objects won't be recognized. */
5436 #define elf64_bed elf64_x86_64_sol2_bed
5438 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5440 #undef elf_backend_static_tls_alignment
5441 #define elf_backend_static_tls_alignment 16
5443 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5445 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5447 #undef elf_backend_want_plt_sym
5448 #define elf_backend_want_plt_sym 1
5450 #undef elf_backend_strtab_flags
5451 #define elf_backend_strtab_flags SHF_STRINGS
5454 elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
5455 bfd *obfd ATTRIBUTE_UNUSED,
5456 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
5457 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
5459 /* PR 19938: FIXME: Need to add code for setting the sh_info
5460 and sh_link fields of Solaris specific section types. */
5464 #undef elf_backend_copy_special_section_fields
5465 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
5467 #include "elf64-target.h"
5469 /* Native Client support. */
5472 elf64_x86_64_nacl_elf_object_p (bfd *abfd)
5474 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
5475 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64_nacl);
5479 #undef TARGET_LITTLE_SYM
5480 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
5481 #undef TARGET_LITTLE_NAME
5482 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5484 #define elf64_bed elf64_x86_64_nacl_bed
5486 #undef ELF_MAXPAGESIZE
5487 #undef ELF_MINPAGESIZE
5488 #undef ELF_COMMONPAGESIZE
5489 #define ELF_MAXPAGESIZE 0x10000
5490 #define ELF_MINPAGESIZE 0x10000
5491 #define ELF_COMMONPAGESIZE 0x10000
5493 /* Restore defaults. */
5495 #undef elf_backend_static_tls_alignment
5496 #undef elf_backend_want_plt_sym
5497 #define elf_backend_want_plt_sym 0
5498 #undef elf_backend_strtab_flags
5499 #undef elf_backend_copy_special_section_fields
5501 /* NaCl uses substantially different PLT entries for the same effects. */
5503 #undef elf_backend_plt_alignment
5504 #define elf_backend_plt_alignment 5
5505 #define NACL_PLT_ENTRY_SIZE 64
5506 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5508 static const bfd_byte elf_x86_64_nacl_plt0_entry[NACL_PLT_ENTRY_SIZE] =
5510 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5511 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5512 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
5513 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5514 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5516 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
5517 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
5519 /* 32 bytes of nop to pad out to the standard size. */
5520 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5521 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5522 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5523 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5524 0x66, /* excess data16 prefix */
5528 static const bfd_byte elf_x86_64_nacl_plt_entry[NACL_PLT_ENTRY_SIZE] =
5530 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5531 0x41, 0x83, 0xe3, NACLMASK, /* and $-32, %r11d */
5532 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5533 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5535 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5536 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5537 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5539 /* Lazy GOT entries point here (32-byte aligned). */
5540 0x68, /* pushq immediate */
5541 0, 0, 0, 0, /* replaced with index into relocation table. */
5542 0xe9, /* jmp relative */
5543 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5545 /* 22 bytes of nop to pad out to the standard size. */
5546 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5547 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5548 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5551 /* .eh_frame covering the .plt section. */
5553 static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] =
5555 #if (PLT_CIE_LENGTH != 20 \
5556 || PLT_FDE_LENGTH != 36 \
5557 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5558 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5559 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5561 PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
5562 0, 0, 0, 0, /* CIE ID */
5563 1, /* CIE version */
5564 'z', 'R', 0, /* Augmentation string */
5565 1, /* Code alignment factor */
5566 0x78, /* Data alignment factor */
5567 16, /* Return address column */
5568 1, /* Augmentation size */
5569 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
5570 DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5571 DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5572 DW_CFA_nop, DW_CFA_nop,
5574 PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
5575 PLT_CIE_LENGTH + 8, 0, 0, 0,/* CIE pointer */
5576 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5577 0, 0, 0, 0, /* .plt size goes here */
5578 0, /* Augmentation size */
5579 DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */
5580 DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5581 DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */
5582 DW_CFA_advance_loc + 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5583 DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
5584 13, /* Block length */
5585 DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */
5586 DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */
5587 DW_OP_const1u, 63, DW_OP_and, DW_OP_const1u, 37, DW_OP_ge,
5588 DW_OP_lit3, DW_OP_shl, DW_OP_plus,
5589 DW_CFA_nop, DW_CFA_nop
5592 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt =
5594 elf_x86_64_nacl_plt0_entry, /* plt0_entry */
5595 NACL_PLT_ENTRY_SIZE, /* plt0_entry_size */
5596 elf_x86_64_nacl_plt_entry, /* plt_entry */
5597 NACL_PLT_ENTRY_SIZE, /* plt_entry_size */
5598 2, /* plt0_got1_offset */
5599 9, /* plt0_got2_offset */
5600 13, /* plt0_got2_insn_end */
5601 3, /* plt_got_offset */
5602 33, /* plt_reloc_offset */
5603 38, /* plt_plt_offset */
5604 7, /* plt_got_insn_size */
5605 42, /* plt_plt_insn_end */
5606 32, /* plt_lazy_offset */
5607 elf_x86_64_nacl_plt0_entry, /* pic_plt0_entry */
5608 elf_x86_64_nacl_plt_entry, /* pic_plt_entry */
5609 elf_x86_64_nacl_eh_frame_plt, /* eh_frame_plt */
5610 sizeof (elf_x86_64_nacl_eh_frame_plt) /* eh_frame_plt_size */
5613 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed =
5618 #undef elf_backend_arch_data
5619 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5621 #undef elf_backend_object_p
5622 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
5623 #undef elf_backend_modify_segment_map
5624 #define elf_backend_modify_segment_map nacl_modify_segment_map
5625 #undef elf_backend_modify_program_headers
5626 #define elf_backend_modify_program_headers nacl_modify_program_headers
5627 #undef elf_backend_final_write_processing
5628 #define elf_backend_final_write_processing nacl_final_write_processing
5630 #include "elf64-target.h"
5632 /* Native Client x32 support. */
5635 elf32_x86_64_nacl_elf_object_p (bfd *abfd)
5637 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
5638 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32_nacl);
5642 #undef TARGET_LITTLE_SYM
5643 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
5644 #undef TARGET_LITTLE_NAME
5645 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5647 #define elf32_bed elf32_x86_64_nacl_bed
5649 #define bfd_elf32_bfd_reloc_type_lookup \
5650 elf_x86_64_reloc_type_lookup
5651 #define bfd_elf32_bfd_reloc_name_lookup \
5652 elf_x86_64_reloc_name_lookup
5653 #define bfd_elf32_get_synthetic_symtab \
5654 elf_x86_64_get_synthetic_symtab
5656 #undef elf_backend_object_p
5657 #define elf_backend_object_p \
5658 elf32_x86_64_nacl_elf_object_p
5660 #undef elf_backend_bfd_from_remote_memory
5661 #define elf_backend_bfd_from_remote_memory \
5662 _bfd_elf32_bfd_from_remote_memory
5664 #undef elf_backend_size_info
5665 #define elf_backend_size_info \
5666 _bfd_elf32_size_info
5668 #include "elf32-target.h"
5670 /* Restore defaults. */
5671 #undef elf_backend_object_p
5672 #define elf_backend_object_p elf64_x86_64_elf_object_p
5673 #undef elf_backend_bfd_from_remote_memory
5674 #undef elf_backend_size_info
5675 #undef elf_backend_modify_segment_map
5676 #undef elf_backend_modify_program_headers
5677 #undef elf_backend_final_write_processing
5679 /* Intel L1OM support. */
5682 elf64_l1om_elf_object_p (bfd *abfd)
5684 /* Set the right machine number for an L1OM elf64 file. */
5685 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
5689 #undef TARGET_LITTLE_SYM
5690 #define TARGET_LITTLE_SYM l1om_elf64_vec
5691 #undef TARGET_LITTLE_NAME
5692 #define TARGET_LITTLE_NAME "elf64-l1om"
5694 #define ELF_ARCH bfd_arch_l1om
5696 #undef ELF_MACHINE_CODE
5697 #define ELF_MACHINE_CODE EM_L1OM
5702 #define elf64_bed elf64_l1om_bed
5704 #undef elf_backend_object_p
5705 #define elf_backend_object_p elf64_l1om_elf_object_p
5707 /* Restore defaults. */
5708 #undef ELF_MAXPAGESIZE
5709 #undef ELF_MINPAGESIZE
5710 #undef ELF_COMMONPAGESIZE
5711 #define ELF_MAXPAGESIZE 0x200000
5712 #define ELF_MINPAGESIZE 0x1000
5713 #define ELF_COMMONPAGESIZE 0x1000
5714 #undef elf_backend_plt_alignment
5715 #define elf_backend_plt_alignment 4
5716 #undef elf_backend_arch_data
5717 #define elf_backend_arch_data &elf_x86_64_arch_bed
5719 #include "elf64-target.h"
5721 /* FreeBSD L1OM support. */
5723 #undef TARGET_LITTLE_SYM
5724 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
5725 #undef TARGET_LITTLE_NAME
5726 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5729 #define ELF_OSABI ELFOSABI_FREEBSD
5732 #define elf64_bed elf64_l1om_fbsd_bed
5734 #include "elf64-target.h"
5736 /* Intel K1OM support. */
5739 elf64_k1om_elf_object_p (bfd *abfd)
5741 /* Set the right machine number for an K1OM elf64 file. */
5742 bfd_default_set_arch_mach (abfd, bfd_arch_k1om, bfd_mach_k1om);
5746 #undef TARGET_LITTLE_SYM
5747 #define TARGET_LITTLE_SYM k1om_elf64_vec
5748 #undef TARGET_LITTLE_NAME
5749 #define TARGET_LITTLE_NAME "elf64-k1om"
5751 #define ELF_ARCH bfd_arch_k1om
5753 #undef ELF_MACHINE_CODE
5754 #define ELF_MACHINE_CODE EM_K1OM
5759 #define elf64_bed elf64_k1om_bed
5761 #undef elf_backend_object_p
5762 #define elf_backend_object_p elf64_k1om_elf_object_p
5764 #undef elf_backend_static_tls_alignment
5766 #undef elf_backend_want_plt_sym
5767 #define elf_backend_want_plt_sym 0
5769 #include "elf64-target.h"
5771 /* FreeBSD K1OM support. */
5773 #undef TARGET_LITTLE_SYM
5774 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
5775 #undef TARGET_LITTLE_NAME
5776 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5779 #define ELF_OSABI ELFOSABI_FREEBSD
5782 #define elf64_bed elf64_k1om_fbsd_bed
5784 #include "elf64-target.h"
5786 /* 32bit x86-64 support. */
5788 #undef TARGET_LITTLE_SYM
5789 #define TARGET_LITTLE_SYM x86_64_elf32_vec
5790 #undef TARGET_LITTLE_NAME
5791 #define TARGET_LITTLE_NAME "elf32-x86-64"
5795 #define ELF_ARCH bfd_arch_i386
5797 #undef ELF_MACHINE_CODE
5798 #define ELF_MACHINE_CODE EM_X86_64
5802 #undef elf_backend_object_p
5803 #define elf_backend_object_p \
5804 elf32_x86_64_elf_object_p
5806 #undef elf_backend_bfd_from_remote_memory
5807 #define elf_backend_bfd_from_remote_memory \
5808 _bfd_elf32_bfd_from_remote_memory
5810 #undef elf_backend_size_info
5811 #define elf_backend_size_info \
5812 _bfd_elf32_size_info
5814 #include "elf32-target.h"