1 /* X86-64 specific support for ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Jan Hubicka <jh@suse.cz>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "bfd_stdint.h"
33 #include "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 #define ABI_64_P(abfd) \
44 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
46 /* The relocation "howto" table. Order of fields:
47 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
48 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
49 static reloc_howto_type x86_64_elf_howto_table[] =
51 HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
52 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
54 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
55 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
57 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
58 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
61 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
63 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
64 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
66 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
67 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
69 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
70 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
72 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
73 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
75 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
76 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
78 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
79 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
81 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
82 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
84 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
85 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
87 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
88 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
89 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
90 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
91 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
92 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
93 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
94 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
95 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
96 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
98 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
99 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
101 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
102 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
104 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
105 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
107 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
108 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
110 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
111 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
113 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
114 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
116 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
117 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
119 HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
120 bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
122 HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
123 bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
124 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
125 HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
126 bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
127 FALSE, 0xffffffff, 0xffffffff, TRUE),
128 HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
129 bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
131 HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
132 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
134 HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
135 bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
136 FALSE, MINUS_ONE, MINUS_ONE, TRUE),
137 HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
138 bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
140 HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
141 bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
145 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
146 complain_overflow_bitfield, bfd_elf_generic_reloc,
147 "R_X86_64_GOTPC32_TLSDESC",
148 FALSE, 0xffffffff, 0xffffffff, TRUE),
149 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
150 complain_overflow_dont, bfd_elf_generic_reloc,
151 "R_X86_64_TLSDESC_CALL",
153 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
154 complain_overflow_bitfield, bfd_elf_generic_reloc,
156 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
157 HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
158 bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
161 /* We have a gap in the reloc numbers here.
162 R_X86_64_standard counts the number up to this point, and
163 R_X86_64_vt_offset is the value to subtract from a reloc type of
164 R_X86_64_GNU_VT* to form an index into this table. */
165 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
166 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
168 /* GNU extension to record C++ vtable hierarchy. */
169 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
170 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
172 /* GNU extension to record C++ vtable member usage. */
173 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
174 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
178 #define IS_X86_64_PCREL_TYPE(TYPE) \
179 ( ((TYPE) == R_X86_64_PC8) \
180 || ((TYPE) == R_X86_64_PC16) \
181 || ((TYPE) == R_X86_64_PC32) \
182 || ((TYPE) == R_X86_64_PC64))
184 /* Map BFD relocs to the x86_64 elf relocs. */
187 bfd_reloc_code_real_type bfd_reloc_val;
188 unsigned char elf_reloc_val;
191 static const struct elf_reloc_map x86_64_reloc_map[] =
193 { BFD_RELOC_NONE, R_X86_64_NONE, },
194 { BFD_RELOC_64, R_X86_64_64, },
195 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
196 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
197 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
198 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
199 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
200 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
201 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
202 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
203 { BFD_RELOC_32, R_X86_64_32, },
204 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
205 { BFD_RELOC_16, R_X86_64_16, },
206 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
207 { BFD_RELOC_8, R_X86_64_8, },
208 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
209 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
210 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
211 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
212 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
213 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
214 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
215 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
216 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
217 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
218 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
219 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
220 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
221 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
222 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
223 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
224 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
225 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
226 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
227 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
228 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
229 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
230 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
233 static reloc_howto_type *
234 elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
238 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
239 || r_type >= (unsigned int) R_X86_64_max)
241 if (r_type >= (unsigned int) R_X86_64_standard)
243 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
245 r_type = R_X86_64_NONE;
250 i = r_type - (unsigned int) R_X86_64_vt_offset;
251 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
252 return &x86_64_elf_howto_table[i];
255 /* Given a BFD reloc type, return a HOWTO structure. */
256 static reloc_howto_type *
257 elf_x86_64_reloc_type_lookup (bfd *abfd,
258 bfd_reloc_code_real_type code)
262 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
265 if (x86_64_reloc_map[i].bfd_reloc_val == code)
266 return elf_x86_64_rtype_to_howto (abfd,
267 x86_64_reloc_map[i].elf_reloc_val);
272 static reloc_howto_type *
273 elf_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
279 i < (sizeof (x86_64_elf_howto_table)
280 / sizeof (x86_64_elf_howto_table[0]));
282 if (x86_64_elf_howto_table[i].name != NULL
283 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
284 return &x86_64_elf_howto_table[i];
289 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
292 elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
293 Elf_Internal_Rela *dst)
297 r_type = ELF32_R_TYPE (dst->r_info);
298 cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
299 BFD_ASSERT (r_type == cache_ptr->howto->type);
302 /* Support for core dump NOTE sections. */
304 elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
309 switch (note->descsz)
314 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
316 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
319 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
327 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
329 elf_tdata (abfd)->core_signal
330 = bfd_get_16 (abfd, note->descdata + 12);
333 elf_tdata (abfd)->core_lwpid
334 = bfd_get_32 (abfd, note->descdata + 32);
343 /* Make a ".reg/999" section. */
344 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
345 size, note->descpos + offset);
349 elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
351 switch (note->descsz)
356 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
357 elf_tdata (abfd)->core_pid
358 = bfd_get_32 (abfd, note->descdata + 12);
359 elf_tdata (abfd)->core_program
360 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
361 elf_tdata (abfd)->core_command
362 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
365 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
366 elf_tdata (abfd)->core_pid
367 = bfd_get_32 (abfd, note->descdata + 24);
368 elf_tdata (abfd)->core_program
369 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
370 elf_tdata (abfd)->core_command
371 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
374 /* Note that for some reason, a spurious space is tacked
375 onto the end of the args in some (at least one anyway)
376 implementations, so strip it off if it exists. */
379 char *command = elf_tdata (abfd)->core_command;
380 int n = strlen (command);
382 if (0 < n && command[n - 1] == ' ')
383 command[n - 1] = '\0';
389 /* Functions for the x86-64 ELF linker. */
391 /* The name of the dynamic interpreter. This is put in the .interp
394 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
395 #define ELF32_DYNAMIC_INTERPRETER "/lib/ld32.so.1"
397 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
398 copying dynamic variables from a shared lib into an app's dynbss
399 section, and instead use a dynamic relocation to point into the
401 #define ELIMINATE_COPY_RELOCS 1
403 /* The size in bytes of an entry in the global offset table. */
405 #define GOT_ENTRY_SIZE 8
407 /* The size in bytes of an entry in the procedure linkage table. */
409 #define PLT_ENTRY_SIZE 16
411 /* The first entry in a procedure linkage table looks like this. See the
412 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
414 static const bfd_byte elf_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
416 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
417 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
418 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
421 /* Subsequent entries in a procedure linkage table look like this. */
423 static const bfd_byte elf_x86_64_plt_entry[PLT_ENTRY_SIZE] =
425 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
426 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
427 0x68, /* pushq immediate */
428 0, 0, 0, 0, /* replaced with index into relocation table. */
429 0xe9, /* jmp relative */
430 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
433 /* x86-64 ELF linker hash entry. */
435 struct elf_x86_64_link_hash_entry
437 struct elf_link_hash_entry elf;
439 /* Track dynamic relocs copied for this symbol. */
440 struct elf_dyn_relocs *dyn_relocs;
442 #define GOT_UNKNOWN 0
446 #define GOT_TLS_GDESC 4
447 #define GOT_TLS_GD_BOTH_P(type) \
448 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
449 #define GOT_TLS_GD_P(type) \
450 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
451 #define GOT_TLS_GDESC_P(type) \
452 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
453 #define GOT_TLS_GD_ANY_P(type) \
454 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
455 unsigned char tls_type;
457 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
458 starting at the end of the jump table. */
462 #define elf_x86_64_hash_entry(ent) \
463 ((struct elf_x86_64_link_hash_entry *)(ent))
465 struct elf_x86_64_obj_tdata
467 struct elf_obj_tdata root;
469 /* tls_type for each local got entry. */
470 char *local_got_tls_type;
472 /* GOTPLT entries for TLS descriptors. */
473 bfd_vma *local_tlsdesc_gotent;
476 #define elf_x86_64_tdata(abfd) \
477 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
479 #define elf_x86_64_local_got_tls_type(abfd) \
480 (elf_x86_64_tdata (abfd)->local_got_tls_type)
482 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
483 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
485 #define is_x86_64_elf(bfd) \
486 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
487 && elf_tdata (bfd) != NULL \
488 && elf_object_id (bfd) == X86_64_ELF_DATA)
491 elf_x86_64_mkobject (bfd *abfd)
493 return bfd_elf_allocate_object (abfd, sizeof (struct elf_x86_64_obj_tdata),
497 /* x86-64 ELF linker hash table. */
499 struct elf_x86_64_link_hash_table
501 struct elf_link_hash_table elf;
503 /* Short-cuts to get to dynamic linker sections. */
509 bfd_signed_vma refcount;
513 /* The amount of space used by the jump slots in the GOT. */
514 bfd_vma sgotplt_jump_table_size;
516 /* Small local sym cache. */
517 struct sym_cache sym_cache;
519 bfd_vma (*r_info) (bfd_vma, bfd_vma);
520 bfd_vma (*r_sym) (bfd_vma);
521 unsigned int pointer_r_type;
522 const char *dynamic_interpreter;
523 int dynamic_interpreter_size;
525 /* _TLS_MODULE_BASE_ symbol. */
526 struct bfd_link_hash_entry *tls_module_base;
528 /* Used by local STT_GNU_IFUNC symbols. */
529 htab_t loc_hash_table;
530 void * loc_hash_memory;
532 /* The offset into splt of the PLT entry for the TLS descriptor
533 resolver. Special values are 0, if not necessary (or not found
534 to be necessary yet), and -1 if needed but not determined
537 /* The offset into sgot of the GOT entry used by the PLT entry
542 /* Get the x86-64 ELF linker hash table from a link_info structure. */
544 #define elf_x86_64_hash_table(p) \
545 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
546 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
548 #define elf_x86_64_compute_jump_table_size(htab) \
549 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
551 /* Create an entry in an x86-64 ELF linker hash table. */
553 static struct bfd_hash_entry *
554 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
555 struct bfd_hash_table *table,
558 /* Allocate the structure if it has not already been allocated by a
562 entry = (struct bfd_hash_entry *)
563 bfd_hash_allocate (table,
564 sizeof (struct elf_x86_64_link_hash_entry));
569 /* Call the allocation method of the superclass. */
570 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
573 struct elf_x86_64_link_hash_entry *eh;
575 eh = (struct elf_x86_64_link_hash_entry *) entry;
576 eh->dyn_relocs = NULL;
577 eh->tls_type = GOT_UNKNOWN;
578 eh->tlsdesc_got = (bfd_vma) -1;
584 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
585 for local symbol so that we can handle local STT_GNU_IFUNC symbols
586 as global symbol. We reuse indx and dynstr_index for local symbol
587 hash since they aren't used by global symbols in this backend. */
590 elf_x86_64_local_htab_hash (const void *ptr)
592 struct elf_link_hash_entry *h
593 = (struct elf_link_hash_entry *) ptr;
594 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
597 /* Compare local hash entries. */
600 elf_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
602 struct elf_link_hash_entry *h1
603 = (struct elf_link_hash_entry *) ptr1;
604 struct elf_link_hash_entry *h2
605 = (struct elf_link_hash_entry *) ptr2;
607 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
610 /* Find and/or create a hash entry for local symbol. */
612 static struct elf_link_hash_entry *
613 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table *htab,
614 bfd *abfd, const Elf_Internal_Rela *rel,
617 struct elf_x86_64_link_hash_entry e, *ret;
618 asection *sec = abfd->sections;
619 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
620 htab->r_sym (rel->r_info));
623 e.elf.indx = sec->id;
624 e.elf.dynstr_index = htab->r_sym (rel->r_info);
625 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
626 create ? INSERT : NO_INSERT);
633 ret = (struct elf_x86_64_link_hash_entry *) *slot;
637 ret = (struct elf_x86_64_link_hash_entry *)
638 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
639 sizeof (struct elf_x86_64_link_hash_entry));
642 memset (ret, 0, sizeof (*ret));
643 ret->elf.indx = sec->id;
644 ret->elf.dynstr_index = htab->r_sym (rel->r_info);
645 ret->elf.dynindx = -1;
651 /* Create an X86-64 ELF linker hash table. */
653 static struct bfd_link_hash_table *
654 elf_x86_64_link_hash_table_create (bfd *abfd)
656 struct elf_x86_64_link_hash_table *ret;
657 bfd_size_type amt = sizeof (struct elf_x86_64_link_hash_table);
659 ret = (struct elf_x86_64_link_hash_table *) bfd_malloc (amt);
663 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
664 elf_x86_64_link_hash_newfunc,
665 sizeof (struct elf_x86_64_link_hash_entry),
674 ret->sym_cache.abfd = NULL;
675 ret->tlsdesc_plt = 0;
676 ret->tlsdesc_got = 0;
677 ret->tls_ld_got.refcount = 0;
678 ret->sgotplt_jump_table_size = 0;
679 ret->tls_module_base = NULL;
683 ret->r_info = elf64_r_info;
684 ret->r_sym = elf64_r_sym;
685 ret->pointer_r_type = R_X86_64_64;
686 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
687 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
691 ret->r_info = elf32_r_info;
692 ret->r_sym = elf32_r_sym;
693 ret->pointer_r_type = R_X86_64_32;
694 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
695 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
698 ret->loc_hash_table = htab_try_create (1024,
699 elf_x86_64_local_htab_hash,
700 elf_x86_64_local_htab_eq,
702 ret->loc_hash_memory = objalloc_create ();
703 if (!ret->loc_hash_table || !ret->loc_hash_memory)
709 return &ret->elf.root;
712 /* Destroy an X86-64 ELF linker hash table. */
715 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
717 struct elf_x86_64_link_hash_table *htab
718 = (struct elf_x86_64_link_hash_table *) hash;
720 if (htab->loc_hash_table)
721 htab_delete (htab->loc_hash_table);
722 if (htab->loc_hash_memory)
723 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
724 _bfd_generic_link_hash_table_free (hash);
727 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
728 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
732 elf_x86_64_create_dynamic_sections (bfd *dynobj,
733 struct bfd_link_info *info)
735 struct elf_x86_64_link_hash_table *htab;
737 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
740 htab = elf_x86_64_hash_table (info);
744 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
746 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
749 || (!info->shared && !htab->srelbss))
755 /* Copy the extra info we tack onto an elf_link_hash_entry. */
758 elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
759 struct elf_link_hash_entry *dir,
760 struct elf_link_hash_entry *ind)
762 struct elf_x86_64_link_hash_entry *edir, *eind;
764 edir = (struct elf_x86_64_link_hash_entry *) dir;
765 eind = (struct elf_x86_64_link_hash_entry *) ind;
767 if (eind->dyn_relocs != NULL)
769 if (edir->dyn_relocs != NULL)
771 struct elf_dyn_relocs **pp;
772 struct elf_dyn_relocs *p;
774 /* Add reloc counts against the indirect sym to the direct sym
775 list. Merge any entries against the same section. */
776 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
778 struct elf_dyn_relocs *q;
780 for (q = edir->dyn_relocs; q != NULL; q = q->next)
781 if (q->sec == p->sec)
783 q->pc_count += p->pc_count;
784 q->count += p->count;
791 *pp = edir->dyn_relocs;
794 edir->dyn_relocs = eind->dyn_relocs;
795 eind->dyn_relocs = NULL;
798 if (ind->root.type == bfd_link_hash_indirect
799 && dir->got.refcount <= 0)
801 edir->tls_type = eind->tls_type;
802 eind->tls_type = GOT_UNKNOWN;
805 if (ELIMINATE_COPY_RELOCS
806 && ind->root.type != bfd_link_hash_indirect
807 && dir->dynamic_adjusted)
809 /* If called to transfer flags for a weakdef during processing
810 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
811 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
812 dir->ref_dynamic |= ind->ref_dynamic;
813 dir->ref_regular |= ind->ref_regular;
814 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
815 dir->needs_plt |= ind->needs_plt;
816 dir->pointer_equality_needed |= ind->pointer_equality_needed;
819 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
823 elf64_x86_64_elf_object_p (bfd *abfd)
825 /* Set the right machine number for an x86-64 elf64 file. */
826 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
844 /* Return TRUE if the TLS access code sequence support transition
848 elf_x86_64_check_tls_transition (bfd *abfd,
849 struct bfd_link_info *info,
852 Elf_Internal_Shdr *symtab_hdr,
853 struct elf_link_hash_entry **sym_hashes,
855 const Elf_Internal_Rela *rel,
856 const Elf_Internal_Rela *relend)
859 unsigned long r_symndx;
860 struct elf_link_hash_entry *h;
862 struct elf_x86_64_link_hash_table *htab;
864 /* Get the section contents. */
865 if (contents == NULL)
867 if (elf_section_data (sec)->this_hdr.contents != NULL)
868 contents = elf_section_data (sec)->this_hdr.contents;
871 /* FIXME: How to better handle error condition? */
872 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
875 /* Cache the section contents for elf_link_input_bfd. */
876 elf_section_data (sec)->this_hdr.contents = contents;
880 htab = elf_x86_64_hash_table (info);
881 offset = rel->r_offset;
886 if ((rel + 1) >= relend)
889 if (r_type == R_X86_64_TLSGD)
891 /* Check transition from GD access model. For 64bit, only
892 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
893 .word 0x6666; rex64; call __tls_get_addr
894 can transit to different access model. For 32bit, only
895 leaq foo@tlsgd(%rip), %rdi
896 .word 0x6666; rex64; call __tls_get_addr
897 can transit to different access model. */
899 static x86_64_opcode32 call = { { 0x66, 0x66, 0x48, 0xe8 } };
900 if ((offset + 12) > sec->size
901 || bfd_get_32 (abfd, contents + offset + 4) != call.i)
906 static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } };
908 || bfd_get_32 (abfd, contents + offset - 4) != leaq.i)
913 static x86_64_opcode16 lea = { { 0x8d, 0x3d } };
915 || bfd_get_8 (abfd, contents + offset - 3) != 0x48
916 || bfd_get_16 (abfd, contents + offset - 2) != lea.i)
922 /* Check transition from LD access model. Only
923 leaq foo@tlsld(%rip), %rdi;
925 can transit to different access model. */
927 static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
930 if (offset < 3 || (offset + 9) > sec->size)
933 op.i = bfd_get_32 (abfd, contents + offset - 3);
934 op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
939 r_symndx = htab->r_sym (rel[1].r_info);
940 if (r_symndx < symtab_hdr->sh_info)
943 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
944 /* Use strncmp to check __tls_get_addr since __tls_get_addr
947 && h->root.root.string != NULL
948 && (ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PC32
949 || ELF32_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
950 && (strncmp (h->root.root.string,
951 "__tls_get_addr", 14) == 0));
953 case R_X86_64_GOTTPOFF:
954 /* Check transition from IE access model:
955 mov foo@gottpoff(%rip), %reg
956 add foo@gottpoff(%rip), %reg
959 /* Check REX prefix first. */
960 if (offset >= 3 && (offset + 4) <= sec->size)
962 val = bfd_get_8 (abfd, contents + offset - 3);
963 if (val != 0x48 && val != 0x4c)
965 /* X32 may have 0x44 REX prefix or no REX prefix. */
972 /* X32 may not have any REX prefix. */
975 if (offset < 2 || (offset + 3) > sec->size)
979 val = bfd_get_8 (abfd, contents + offset - 2);
980 if (val != 0x8b && val != 0x03)
983 val = bfd_get_8 (abfd, contents + offset - 1);
984 return (val & 0xc7) == 5;
986 case R_X86_64_GOTPC32_TLSDESC:
987 /* Check transition from GDesc access model:
988 leaq x@tlsdesc(%rip), %rax
990 Make sure it's a leaq adding rip to a 32-bit offset
991 into any register, although it's probably almost always
994 if (offset < 3 || (offset + 4) > sec->size)
997 val = bfd_get_8 (abfd, contents + offset - 3);
998 if ((val & 0xfb) != 0x48)
1001 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
1004 val = bfd_get_8 (abfd, contents + offset - 1);
1005 return (val & 0xc7) == 0x05;
1007 case R_X86_64_TLSDESC_CALL:
1008 /* Check transition from GDesc access model:
1009 call *x@tlsdesc(%rax)
1011 if (offset + 2 <= sec->size)
1013 /* Make sure that it's a call *x@tlsdesc(%rax). */
1014 static x86_64_opcode16 call = { { 0xff, 0x10 } };
1015 return bfd_get_16 (abfd, contents + offset) == call.i;
1025 /* Return TRUE if the TLS access transition is OK or no transition
1026 will be performed. Update R_TYPE if there is a transition. */
1029 elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
1030 asection *sec, bfd_byte *contents,
1031 Elf_Internal_Shdr *symtab_hdr,
1032 struct elf_link_hash_entry **sym_hashes,
1033 unsigned int *r_type, int tls_type,
1034 const Elf_Internal_Rela *rel,
1035 const Elf_Internal_Rela *relend,
1036 struct elf_link_hash_entry *h,
1037 unsigned long r_symndx)
1039 unsigned int from_type = *r_type;
1040 unsigned int to_type = from_type;
1041 bfd_boolean check = TRUE;
1043 /* Skip TLS transition for functions. */
1045 && (h->type == STT_FUNC
1046 || h->type == STT_GNU_IFUNC))
1051 case R_X86_64_TLSGD:
1052 case R_X86_64_GOTPC32_TLSDESC:
1053 case R_X86_64_TLSDESC_CALL:
1054 case R_X86_64_GOTTPOFF:
1055 if (info->executable)
1058 to_type = R_X86_64_TPOFF32;
1060 to_type = R_X86_64_GOTTPOFF;
1063 /* When we are called from elf_x86_64_relocate_section,
1064 CONTENTS isn't NULL and there may be additional transitions
1065 based on TLS_TYPE. */
1066 if (contents != NULL)
1068 unsigned int new_to_type = to_type;
1070 if (info->executable
1073 && tls_type == GOT_TLS_IE)
1074 new_to_type = R_X86_64_TPOFF32;
1076 if (to_type == R_X86_64_TLSGD
1077 || to_type == R_X86_64_GOTPC32_TLSDESC
1078 || to_type == R_X86_64_TLSDESC_CALL)
1080 if (tls_type == GOT_TLS_IE)
1081 new_to_type = R_X86_64_GOTTPOFF;
1084 /* We checked the transition before when we were called from
1085 elf_x86_64_check_relocs. We only want to check the new
1086 transition which hasn't been checked before. */
1087 check = new_to_type != to_type && from_type == to_type;
1088 to_type = new_to_type;
1093 case R_X86_64_TLSLD:
1094 if (info->executable)
1095 to_type = R_X86_64_TPOFF32;
1102 /* Return TRUE if there is no transition. */
1103 if (from_type == to_type)
1106 /* Check if the transition can be performed. */
1108 && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents,
1109 symtab_hdr, sym_hashes,
1110 from_type, rel, relend))
1112 reloc_howto_type *from, *to;
1115 from = elf_x86_64_rtype_to_howto (abfd, from_type);
1116 to = elf_x86_64_rtype_to_howto (abfd, to_type);
1119 name = h->root.root.string;
1122 struct elf_x86_64_link_hash_table *htab;
1124 htab = elf_x86_64_hash_table (info);
1129 Elf_Internal_Sym *isym;
1131 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1133 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1137 (*_bfd_error_handler)
1138 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1139 "in section `%A' failed"),
1140 abfd, sec, from->name, to->name, name,
1141 (unsigned long) rel->r_offset);
1142 bfd_set_error (bfd_error_bad_value);
1150 /* Look through the relocs for a section during the first phase, and
1151 calculate needed space in the global offset table, procedure
1152 linkage table, and dynamic reloc sections. */
1155 elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1157 const Elf_Internal_Rela *relocs)
1159 struct elf_x86_64_link_hash_table *htab;
1160 Elf_Internal_Shdr *symtab_hdr;
1161 struct elf_link_hash_entry **sym_hashes;
1162 const Elf_Internal_Rela *rel;
1163 const Elf_Internal_Rela *rel_end;
1166 if (info->relocatable)
1169 BFD_ASSERT (is_x86_64_elf (abfd));
1171 htab = elf_x86_64_hash_table (info);
1175 symtab_hdr = &elf_symtab_hdr (abfd);
1176 sym_hashes = elf_sym_hashes (abfd);
1180 rel_end = relocs + sec->reloc_count;
1181 for (rel = relocs; rel < rel_end; rel++)
1183 unsigned int r_type;
1184 unsigned long r_symndx;
1185 struct elf_link_hash_entry *h;
1186 Elf_Internal_Sym *isym;
1189 r_symndx = htab->r_sym (rel->r_info);
1190 r_type = ELF32_R_TYPE (rel->r_info);
1192 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1194 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1199 if (r_symndx < symtab_hdr->sh_info)
1201 /* A local symbol. */
1202 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1207 /* Check relocation against local STT_GNU_IFUNC symbol. */
1208 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1210 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel,
1215 /* Fake a STT_GNU_IFUNC symbol. */
1216 h->type = STT_GNU_IFUNC;
1219 h->forced_local = 1;
1220 h->root.type = bfd_link_hash_defined;
1228 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1229 while (h->root.type == bfd_link_hash_indirect
1230 || h->root.type == bfd_link_hash_warning)
1231 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1234 /* Check invalid x32 relocations. */
1235 if (!ABI_64_P (abfd))
1242 /* Allow R_X86_64_64 relocations in SEC_DEBUGGING sections
1243 when building shared libraries. */
1245 && !info->executable
1246 && (sec->flags & SEC_DEBUGGING) != 0)
1249 case R_X86_64_DTPOFF64:
1250 case R_X86_64_TPOFF64:
1252 case R_X86_64_GOTOFF64:
1253 case R_X86_64_GOT64:
1254 case R_X86_64_GOTPCREL64:
1255 case R_X86_64_GOTPC64:
1256 case R_X86_64_GOTPLT64:
1257 case R_X86_64_PLTOFF64:
1260 name = h->root.root.string;
1262 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1264 (*_bfd_error_handler)
1265 (_("%B: relocation %s against symbol `%s' isn't "
1266 "supported in x32 mode"), abfd,
1267 x86_64_elf_howto_table[r_type].name, name);
1268 bfd_set_error (bfd_error_bad_value);
1276 /* Create the ifunc sections for static executables. If we
1277 never see an indirect function symbol nor we are building
1278 a static executable, those sections will be empty and
1279 won't appear in output. */
1290 case R_X86_64_PLT32:
1291 case R_X86_64_GOTPCREL:
1292 case R_X86_64_GOTPCREL64:
1293 if (htab->elf.dynobj == NULL)
1294 htab->elf.dynobj = abfd;
1295 if (!_bfd_elf_create_ifunc_sections (htab->elf.dynobj, info))
1300 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1301 it here if it is defined in a non-shared object. */
1302 if (h->type == STT_GNU_IFUNC
1305 /* It is referenced by a non-shared object. */
1309 /* STT_GNU_IFUNC symbol must go through PLT. */
1310 h->plt.refcount += 1;
1312 /* STT_GNU_IFUNC needs dynamic sections. */
1313 if (htab->elf.dynobj == NULL)
1314 htab->elf.dynobj = abfd;
1319 if (h->root.root.string)
1320 name = h->root.root.string;
1322 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1324 (*_bfd_error_handler)
1325 (_("%B: relocation %s against STT_GNU_IFUNC "
1326 "symbol `%s' isn't handled by %s"), abfd,
1327 x86_64_elf_howto_table[r_type].name,
1328 name, __FUNCTION__);
1329 bfd_set_error (bfd_error_bad_value);
1333 if (ABI_64_P (abfd))
1337 h->pointer_equality_needed = 1;
1340 /* We must copy these reloc types into the output
1341 file. Create a reloc section in dynobj and
1342 make room for this reloc. */
1343 sreloc = _bfd_elf_create_ifunc_dyn_reloc
1344 (abfd, info, sec, sreloc,
1345 &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs);
1356 if (r_type != R_X86_64_PC32
1357 && r_type != R_X86_64_PC64)
1358 h->pointer_equality_needed = 1;
1361 case R_X86_64_PLT32:
1364 case R_X86_64_GOTPCREL:
1365 case R_X86_64_GOTPCREL64:
1366 h->got.refcount += 1;
1367 if (htab->elf.sgot == NULL
1368 && !_bfd_elf_create_got_section (htab->elf.dynobj,
1378 if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
1379 symtab_hdr, sym_hashes,
1380 &r_type, GOT_UNKNOWN,
1381 rel, rel_end, h, r_symndx))
1386 case R_X86_64_TLSLD:
1387 htab->tls_ld_got.refcount += 1;
1390 case R_X86_64_TPOFF32:
1391 if (!info->executable && ABI_64_P (abfd))
1394 name = h->root.root.string;
1396 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1398 (*_bfd_error_handler)
1399 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1401 x86_64_elf_howto_table[r_type].name, name);
1402 bfd_set_error (bfd_error_bad_value);
1407 case R_X86_64_GOTTPOFF:
1408 if (!info->executable)
1409 info->flags |= DF_STATIC_TLS;
1412 case R_X86_64_GOT32:
1413 case R_X86_64_GOTPCREL:
1414 case R_X86_64_TLSGD:
1415 case R_X86_64_GOT64:
1416 case R_X86_64_GOTPCREL64:
1417 case R_X86_64_GOTPLT64:
1418 case R_X86_64_GOTPC32_TLSDESC:
1419 case R_X86_64_TLSDESC_CALL:
1420 /* This symbol requires a global offset table entry. */
1422 int tls_type, old_tls_type;
1426 default: tls_type = GOT_NORMAL; break;
1427 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1428 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1429 case R_X86_64_GOTPC32_TLSDESC:
1430 case R_X86_64_TLSDESC_CALL:
1431 tls_type = GOT_TLS_GDESC; break;
1436 if (r_type == R_X86_64_GOTPLT64)
1438 /* This relocation indicates that we also need
1439 a PLT entry, as this is a function. We don't need
1440 a PLT entry for local symbols. */
1442 h->plt.refcount += 1;
1444 h->got.refcount += 1;
1445 old_tls_type = elf_x86_64_hash_entry (h)->tls_type;
1449 bfd_signed_vma *local_got_refcounts;
1451 /* This is a global offset table entry for a local symbol. */
1452 local_got_refcounts = elf_local_got_refcounts (abfd);
1453 if (local_got_refcounts == NULL)
1457 size = symtab_hdr->sh_info;
1458 size *= sizeof (bfd_signed_vma)
1459 + sizeof (bfd_vma) + sizeof (char);
1460 local_got_refcounts = ((bfd_signed_vma *)
1461 bfd_zalloc (abfd, size));
1462 if (local_got_refcounts == NULL)
1464 elf_local_got_refcounts (abfd) = local_got_refcounts;
1465 elf_x86_64_local_tlsdesc_gotent (abfd)
1466 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1467 elf_x86_64_local_got_tls_type (abfd)
1468 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1470 local_got_refcounts[r_symndx] += 1;
1472 = elf_x86_64_local_got_tls_type (abfd) [r_symndx];
1475 /* If a TLS symbol is accessed using IE at least once,
1476 there is no point to use dynamic model for it. */
1477 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1478 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1479 || tls_type != GOT_TLS_IE))
1481 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1482 tls_type = old_tls_type;
1483 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1484 && GOT_TLS_GD_ANY_P (tls_type))
1485 tls_type |= old_tls_type;
1489 name = h->root.root.string;
1491 name = bfd_elf_sym_name (abfd, symtab_hdr,
1493 (*_bfd_error_handler)
1494 (_("%B: '%s' accessed both as normal and thread local symbol"),
1500 if (old_tls_type != tls_type)
1503 elf_x86_64_hash_entry (h)->tls_type = tls_type;
1505 elf_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1510 case R_X86_64_GOTOFF64:
1511 case R_X86_64_GOTPC32:
1512 case R_X86_64_GOTPC64:
1514 if (htab->elf.sgot == NULL)
1516 if (htab->elf.dynobj == NULL)
1517 htab->elf.dynobj = abfd;
1518 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
1524 case R_X86_64_PLT32:
1525 /* This symbol requires a procedure linkage table entry. We
1526 actually build the entry in adjust_dynamic_symbol,
1527 because this might be a case of linking PIC code which is
1528 never referenced by a dynamic object, in which case we
1529 don't need to generate a procedure linkage table entry
1532 /* If this is a local symbol, we resolve it directly without
1533 creating a procedure linkage table entry. */
1538 h->plt.refcount += 1;
1541 case R_X86_64_PLTOFF64:
1542 /* This tries to form the 'address' of a function relative
1543 to GOT. For global symbols we need a PLT entry. */
1547 h->plt.refcount += 1;
1552 if (!ABI_64_P (abfd))
1557 /* Let's help debug shared library creation. These relocs
1558 cannot be used in shared libs. Don't error out for
1559 sections we don't care about, such as debug sections or
1560 non-constant sections. */
1562 && (sec->flags & SEC_ALLOC) != 0
1563 && (sec->flags & SEC_READONLY) != 0)
1566 name = h->root.root.string;
1568 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1569 (*_bfd_error_handler)
1570 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1571 abfd, x86_64_elf_howto_table[r_type].name, name);
1572 bfd_set_error (bfd_error_bad_value);
1583 if (h != NULL && info->executable)
1585 /* If this reloc is in a read-only section, we might
1586 need a copy reloc. We can't check reliably at this
1587 stage whether the section is read-only, as input
1588 sections have not yet been mapped to output sections.
1589 Tentatively set the flag for now, and correct in
1590 adjust_dynamic_symbol. */
1593 /* We may need a .plt entry if the function this reloc
1594 refers to is in a shared lib. */
1595 h->plt.refcount += 1;
1596 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1597 h->pointer_equality_needed = 1;
1600 /* If we are creating a shared library, and this is a reloc
1601 against a global symbol, or a non PC relative reloc
1602 against a local symbol, then we need to copy the reloc
1603 into the shared library. However, if we are linking with
1604 -Bsymbolic, we do not need to copy a reloc against a
1605 global symbol which is defined in an object we are
1606 including in the link (i.e., DEF_REGULAR is set). At
1607 this point we have not seen all the input files, so it is
1608 possible that DEF_REGULAR is not set now but will be set
1609 later (it is never cleared). In case of a weak definition,
1610 DEF_REGULAR may be cleared later by a strong definition in
1611 a shared library. We account for that possibility below by
1612 storing information in the relocs_copied field of the hash
1613 table entry. A similar situation occurs when creating
1614 shared libraries and symbol visibility changes render the
1617 If on the other hand, we are creating an executable, we
1618 may need to keep relocations for symbols satisfied by a
1619 dynamic library if we manage to avoid copy relocs for the
1622 && (sec->flags & SEC_ALLOC) != 0
1623 && (! IS_X86_64_PCREL_TYPE (r_type)
1625 && (! SYMBOLIC_BIND (info, h)
1626 || h->root.type == bfd_link_hash_defweak
1627 || !h->def_regular))))
1628 || (ELIMINATE_COPY_RELOCS
1630 && (sec->flags & SEC_ALLOC) != 0
1632 && (h->root.type == bfd_link_hash_defweak
1633 || !h->def_regular)))
1635 struct elf_dyn_relocs *p;
1636 struct elf_dyn_relocs **head;
1638 /* We must copy these reloc types into the output file.
1639 Create a reloc section in dynobj and make room for
1643 if (htab->elf.dynobj == NULL)
1644 htab->elf.dynobj = abfd;
1646 sreloc = _bfd_elf_make_dynamic_reloc_section
1647 (sec, htab->elf.dynobj, ABI_64_P (abfd) ? 3 : 2,
1648 abfd, /*rela?*/ TRUE);
1654 /* If this is a global symbol, we count the number of
1655 relocations we need for this symbol. */
1658 head = &((struct elf_x86_64_link_hash_entry *) h)->dyn_relocs;
1662 /* Track dynamic relocs needed for local syms too.
1663 We really need local syms available to do this
1668 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1673 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1677 /* Beware of type punned pointers vs strict aliasing
1679 vpp = &(elf_section_data (s)->local_dynrel);
1680 head = (struct elf_dyn_relocs **)vpp;
1684 if (p == NULL || p->sec != sec)
1686 bfd_size_type amt = sizeof *p;
1688 p = ((struct elf_dyn_relocs *)
1689 bfd_alloc (htab->elf.dynobj, amt));
1700 if (IS_X86_64_PCREL_TYPE (r_type))
1705 /* This relocation describes the C++ object vtable hierarchy.
1706 Reconstruct it for later use during GC. */
1707 case R_X86_64_GNU_VTINHERIT:
1708 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1712 /* This relocation describes which C++ vtable entries are actually
1713 used. Record for later use during GC. */
1714 case R_X86_64_GNU_VTENTRY:
1715 BFD_ASSERT (h != NULL);
1717 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1729 /* Return the section that should be marked against GC for a given
1733 elf_x86_64_gc_mark_hook (asection *sec,
1734 struct bfd_link_info *info,
1735 Elf_Internal_Rela *rel,
1736 struct elf_link_hash_entry *h,
1737 Elf_Internal_Sym *sym)
1740 switch (ELF32_R_TYPE (rel->r_info))
1742 case R_X86_64_GNU_VTINHERIT:
1743 case R_X86_64_GNU_VTENTRY:
1747 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1750 /* Update the got entry reference counts for the section being removed. */
1753 elf_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1755 const Elf_Internal_Rela *relocs)
1757 struct elf_x86_64_link_hash_table *htab;
1758 Elf_Internal_Shdr *symtab_hdr;
1759 struct elf_link_hash_entry **sym_hashes;
1760 bfd_signed_vma *local_got_refcounts;
1761 const Elf_Internal_Rela *rel, *relend;
1763 if (info->relocatable)
1766 htab = elf_x86_64_hash_table (info);
1770 elf_section_data (sec)->local_dynrel = NULL;
1772 symtab_hdr = &elf_symtab_hdr (abfd);
1773 sym_hashes = elf_sym_hashes (abfd);
1774 local_got_refcounts = elf_local_got_refcounts (abfd);
1776 htab = elf_x86_64_hash_table (info);
1777 relend = relocs + sec->reloc_count;
1778 for (rel = relocs; rel < relend; rel++)
1780 unsigned long r_symndx;
1781 unsigned int r_type;
1782 struct elf_link_hash_entry *h = NULL;
1784 r_symndx = htab->r_sym (rel->r_info);
1785 if (r_symndx >= symtab_hdr->sh_info)
1787 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1788 while (h->root.type == bfd_link_hash_indirect
1789 || h->root.type == bfd_link_hash_warning)
1790 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1794 /* A local symbol. */
1795 Elf_Internal_Sym *isym;
1797 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1800 /* Check relocation against local STT_GNU_IFUNC symbol. */
1802 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1804 h = elf_x86_64_get_local_sym_hash (htab, abfd, rel, FALSE);
1812 struct elf_x86_64_link_hash_entry *eh;
1813 struct elf_dyn_relocs **pp;
1814 struct elf_dyn_relocs *p;
1816 eh = (struct elf_x86_64_link_hash_entry *) h;
1818 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1821 /* Everything must go for SEC. */
1827 r_type = ELF32_R_TYPE (rel->r_info);
1828 if (! elf_x86_64_tls_transition (info, abfd, sec, NULL,
1829 symtab_hdr, sym_hashes,
1830 &r_type, GOT_UNKNOWN,
1831 rel, relend, h, r_symndx))
1836 case R_X86_64_TLSLD:
1837 if (htab->tls_ld_got.refcount > 0)
1838 htab->tls_ld_got.refcount -= 1;
1841 case R_X86_64_TLSGD:
1842 case R_X86_64_GOTPC32_TLSDESC:
1843 case R_X86_64_TLSDESC_CALL:
1844 case R_X86_64_GOTTPOFF:
1845 case R_X86_64_GOT32:
1846 case R_X86_64_GOTPCREL:
1847 case R_X86_64_GOT64:
1848 case R_X86_64_GOTPCREL64:
1849 case R_X86_64_GOTPLT64:
1852 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
1853 h->plt.refcount -= 1;
1854 if (h->got.refcount > 0)
1855 h->got.refcount -= 1;
1856 if (h->type == STT_GNU_IFUNC)
1858 if (h->plt.refcount > 0)
1859 h->plt.refcount -= 1;
1862 else if (local_got_refcounts != NULL)
1864 if (local_got_refcounts[r_symndx] > 0)
1865 local_got_refcounts[r_symndx] -= 1;
1879 && (h == NULL || h->type != STT_GNU_IFUNC))
1883 case R_X86_64_PLT32:
1884 case R_X86_64_PLTOFF64:
1887 if (h->plt.refcount > 0)
1888 h->plt.refcount -= 1;
1900 /* Adjust a symbol defined by a dynamic object and referenced by a
1901 regular object. The current definition is in some section of the
1902 dynamic object, but we're not including those sections. We have to
1903 change the definition to something the rest of the link can
1907 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
1908 struct elf_link_hash_entry *h)
1910 struct elf_x86_64_link_hash_table *htab;
1913 /* STT_GNU_IFUNC symbol must go through PLT. */
1914 if (h->type == STT_GNU_IFUNC)
1916 if (h->plt.refcount <= 0)
1918 h->plt.offset = (bfd_vma) -1;
1924 /* If this is a function, put it in the procedure linkage table. We
1925 will fill in the contents of the procedure linkage table later,
1926 when we know the address of the .got section. */
1927 if (h->type == STT_FUNC
1930 if (h->plt.refcount <= 0
1931 || SYMBOL_CALLS_LOCAL (info, h)
1932 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1933 && h->root.type == bfd_link_hash_undefweak))
1935 /* This case can occur if we saw a PLT32 reloc in an input
1936 file, but the symbol was never referred to by a dynamic
1937 object, or if all references were garbage collected. In
1938 such a case, we don't actually need to build a procedure
1939 linkage table, and we can just do a PC32 reloc instead. */
1940 h->plt.offset = (bfd_vma) -1;
1947 /* It's possible that we incorrectly decided a .plt reloc was
1948 needed for an R_X86_64_PC32 reloc to a non-function sym in
1949 check_relocs. We can't decide accurately between function and
1950 non-function syms in check-relocs; Objects loaded later in
1951 the link may change h->type. So fix it now. */
1952 h->plt.offset = (bfd_vma) -1;
1954 /* If this is a weak symbol, and there is a real definition, the
1955 processor independent code will have arranged for us to see the
1956 real definition first, and we can just use the same value. */
1957 if (h->u.weakdef != NULL)
1959 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1960 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1961 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1962 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1963 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1964 h->non_got_ref = h->u.weakdef->non_got_ref;
1968 /* This is a reference to a symbol defined by a dynamic object which
1969 is not a function. */
1971 /* If we are creating a shared library, we must presume that the
1972 only references to the symbol are via the global offset table.
1973 For such cases we need not do anything here; the relocations will
1974 be handled correctly by relocate_section. */
1978 /* If there are no references to this symbol that do not use the
1979 GOT, we don't need to generate a copy reloc. */
1980 if (!h->non_got_ref)
1983 /* If -z nocopyreloc was given, we won't generate them either. */
1984 if (info->nocopyreloc)
1990 if (ELIMINATE_COPY_RELOCS)
1992 struct elf_x86_64_link_hash_entry * eh;
1993 struct elf_dyn_relocs *p;
1995 eh = (struct elf_x86_64_link_hash_entry *) h;
1996 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1998 s = p->sec->output_section;
1999 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2003 /* If we didn't find any dynamic relocs in read-only sections, then
2004 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2014 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
2015 h->root.root.string);
2019 /* We must allocate the symbol in our .dynbss section, which will
2020 become part of the .bss section of the executable. There will be
2021 an entry for this symbol in the .dynsym section. The dynamic
2022 object will contain position independent code, so all references
2023 from the dynamic object to this symbol will go through the global
2024 offset table. The dynamic linker will use the .dynsym entry to
2025 determine the address it must put in the global offset table, so
2026 both the dynamic object and the regular object will refer to the
2027 same memory location for the variable. */
2029 htab = elf_x86_64_hash_table (info);
2033 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2034 to copy the initial value out of the dynamic object and into the
2035 runtime process image. */
2036 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2038 const struct elf_backend_data *bed;
2039 bed = get_elf_backend_data (info->output_bfd);
2040 htab->srelbss->size += bed->s->sizeof_rela;
2046 return _bfd_elf_adjust_dynamic_copy (h, s);
2049 /* Allocate space in .plt, .got and associated reloc sections for
2053 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2055 struct bfd_link_info *info;
2056 struct elf_x86_64_link_hash_table *htab;
2057 struct elf_x86_64_link_hash_entry *eh;
2058 struct elf_dyn_relocs *p;
2059 const struct elf_backend_data *bed;
2061 if (h->root.type == bfd_link_hash_indirect)
2064 eh = (struct elf_x86_64_link_hash_entry *) h;
2066 info = (struct bfd_link_info *) inf;
2067 htab = elf_x86_64_hash_table (info);
2070 bed = get_elf_backend_data (info->output_bfd);
2072 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2073 here if it is defined and referenced in a non-shared object. */
2074 if (h->type == STT_GNU_IFUNC
2076 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
2080 else if (htab->elf.dynamic_sections_created
2081 && h->plt.refcount > 0)
2083 /* Make sure this symbol is output as a dynamic symbol.
2084 Undefined weak syms won't yet be marked as dynamic. */
2085 if (h->dynindx == -1
2086 && !h->forced_local)
2088 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2093 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2095 asection *s = htab->elf.splt;
2097 /* If this is the first .plt entry, make room for the special
2100 s->size += PLT_ENTRY_SIZE;
2102 h->plt.offset = s->size;
2104 /* If this symbol is not defined in a regular file, and we are
2105 not generating a shared library, then set the symbol to this
2106 location in the .plt. This is required to make function
2107 pointers compare as equal between the normal executable and
2108 the shared library. */
2112 h->root.u.def.section = s;
2113 h->root.u.def.value = h->plt.offset;
2116 /* Make room for this entry. */
2117 s->size += PLT_ENTRY_SIZE;
2119 /* We also need to make an entry in the .got.plt section, which
2120 will be placed in the .got section by the linker script. */
2121 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
2123 /* We also need to make an entry in the .rela.plt section. */
2124 htab->elf.srelplt->size += bed->s->sizeof_rela;
2125 htab->elf.srelplt->reloc_count++;
2129 h->plt.offset = (bfd_vma) -1;
2135 h->plt.offset = (bfd_vma) -1;
2139 eh->tlsdesc_got = (bfd_vma) -1;
2141 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2142 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2143 if (h->got.refcount > 0
2146 && elf_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
2148 h->got.offset = (bfd_vma) -1;
2150 else if (h->got.refcount > 0)
2154 int tls_type = elf_x86_64_hash_entry (h)->tls_type;
2156 /* Make sure this symbol is output as a dynamic symbol.
2157 Undefined weak syms won't yet be marked as dynamic. */
2158 if (h->dynindx == -1
2159 && !h->forced_local)
2161 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2165 if (GOT_TLS_GDESC_P (tls_type))
2167 eh->tlsdesc_got = htab->elf.sgotplt->size
2168 - elf_x86_64_compute_jump_table_size (htab);
2169 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2170 h->got.offset = (bfd_vma) -2;
2172 if (! GOT_TLS_GDESC_P (tls_type)
2173 || GOT_TLS_GD_P (tls_type))
2176 h->got.offset = s->size;
2177 s->size += GOT_ENTRY_SIZE;
2178 if (GOT_TLS_GD_P (tls_type))
2179 s->size += GOT_ENTRY_SIZE;
2181 dyn = htab->elf.dynamic_sections_created;
2182 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2184 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2185 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2186 || tls_type == GOT_TLS_IE)
2187 htab->elf.srelgot->size += bed->s->sizeof_rela;
2188 else if (GOT_TLS_GD_P (tls_type))
2189 htab->elf.srelgot->size += 2 * bed->s->sizeof_rela;
2190 else if (! GOT_TLS_GDESC_P (tls_type)
2191 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2192 || h->root.type != bfd_link_hash_undefweak)
2194 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2195 htab->elf.srelgot->size += bed->s->sizeof_rela;
2196 if (GOT_TLS_GDESC_P (tls_type))
2198 htab->elf.srelplt->size += bed->s->sizeof_rela;
2199 htab->tlsdesc_plt = (bfd_vma) -1;
2203 h->got.offset = (bfd_vma) -1;
2205 if (eh->dyn_relocs == NULL)
2208 /* In the shared -Bsymbolic case, discard space allocated for
2209 dynamic pc-relative relocs against symbols which turn out to be
2210 defined in regular objects. For the normal shared case, discard
2211 space for pc-relative relocs that have become local due to symbol
2212 visibility changes. */
2216 /* Relocs that use pc_count are those that appear on a call
2217 insn, or certain REL relocs that can generated via assembly.
2218 We want calls to protected symbols to resolve directly to the
2219 function rather than going via the plt. If people want
2220 function pointer comparisons to work as expected then they
2221 should avoid writing weird assembly. */
2222 if (SYMBOL_CALLS_LOCAL (info, h))
2224 struct elf_dyn_relocs **pp;
2226 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2228 p->count -= p->pc_count;
2237 /* Also discard relocs on undefined weak syms with non-default
2239 if (eh->dyn_relocs != NULL
2240 && h->root.type == bfd_link_hash_undefweak)
2242 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2243 eh->dyn_relocs = NULL;
2245 /* Make sure undefined weak symbols are output as a dynamic
2247 else if (h->dynindx == -1
2248 && ! h->forced_local
2249 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2254 else if (ELIMINATE_COPY_RELOCS)
2256 /* For the non-shared case, discard space for relocs against
2257 symbols which turn out to need copy relocs or are not
2263 || (htab->elf.dynamic_sections_created
2264 && (h->root.type == bfd_link_hash_undefweak
2265 || h->root.type == bfd_link_hash_undefined))))
2267 /* Make sure this symbol is output as a dynamic symbol.
2268 Undefined weak syms won't yet be marked as dynamic. */
2269 if (h->dynindx == -1
2270 && ! h->forced_local
2271 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2274 /* If that succeeded, we know we'll be keeping all the
2276 if (h->dynindx != -1)
2280 eh->dyn_relocs = NULL;
2285 /* Finally, allocate space. */
2286 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2290 sreloc = elf_section_data (p->sec)->sreloc;
2292 BFD_ASSERT (sreloc != NULL);
2294 sreloc->size += p->count * bed->s->sizeof_rela;
2300 /* Allocate space in .plt, .got and associated reloc sections for
2301 local dynamic relocs. */
2304 elf_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
2306 struct elf_link_hash_entry *h
2307 = (struct elf_link_hash_entry *) *slot;
2309 if (h->type != STT_GNU_IFUNC
2313 || h->root.type != bfd_link_hash_defined)
2316 return elf_x86_64_allocate_dynrelocs (h, inf);
2319 /* Find any dynamic relocs that apply to read-only sections. */
2322 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
2325 struct elf_x86_64_link_hash_entry *eh;
2326 struct elf_dyn_relocs *p;
2328 /* Skip local IFUNC symbols. */
2329 if (h->forced_local && h->type == STT_GNU_IFUNC)
2332 eh = (struct elf_x86_64_link_hash_entry *) h;
2333 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2335 asection *s = p->sec->output_section;
2337 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2339 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2341 info->flags |= DF_TEXTREL;
2343 if (info->warn_shared_textrel && info->shared)
2344 info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2345 p->sec->owner, h->root.root.string,
2348 /* Not an error, just cut short the traversal. */
2355 /* Set the sizes of the dynamic sections. */
2358 elf_x86_64_size_dynamic_sections (bfd *output_bfd,
2359 struct bfd_link_info *info)
2361 struct elf_x86_64_link_hash_table *htab;
2366 const struct elf_backend_data *bed;
2368 htab = elf_x86_64_hash_table (info);
2371 bed = get_elf_backend_data (output_bfd);
2373 dynobj = htab->elf.dynobj;
2377 if (htab->elf.dynamic_sections_created)
2379 /* Set the contents of the .interp section to the interpreter. */
2380 if (info->executable)
2382 s = bfd_get_section_by_name (dynobj, ".interp");
2385 s->size = htab->dynamic_interpreter_size;
2386 s->contents = (unsigned char *) htab->dynamic_interpreter;
2390 /* Set up .got offsets for local syms, and space for local dynamic
2392 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2394 bfd_signed_vma *local_got;
2395 bfd_signed_vma *end_local_got;
2396 char *local_tls_type;
2397 bfd_vma *local_tlsdesc_gotent;
2398 bfd_size_type locsymcount;
2399 Elf_Internal_Shdr *symtab_hdr;
2402 if (! is_x86_64_elf (ibfd))
2405 for (s = ibfd->sections; s != NULL; s = s->next)
2407 struct elf_dyn_relocs *p;
2409 for (p = (struct elf_dyn_relocs *)
2410 (elf_section_data (s)->local_dynrel);
2414 if (!bfd_is_abs_section (p->sec)
2415 && bfd_is_abs_section (p->sec->output_section))
2417 /* Input section has been discarded, either because
2418 it is a copy of a linkonce section or due to
2419 linker script /DISCARD/, so we'll be discarding
2422 else if (p->count != 0)
2424 srel = elf_section_data (p->sec)->sreloc;
2425 srel->size += p->count * bed->s->sizeof_rela;
2426 if ((p->sec->output_section->flags & SEC_READONLY) != 0
2427 && (info->flags & DF_TEXTREL) == 0)
2429 info->flags |= DF_TEXTREL;
2430 if (info->warn_shared_textrel && info->shared)
2431 info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2432 p->sec->owner, p->sec);
2438 local_got = elf_local_got_refcounts (ibfd);
2442 symtab_hdr = &elf_symtab_hdr (ibfd);
2443 locsymcount = symtab_hdr->sh_info;
2444 end_local_got = local_got + locsymcount;
2445 local_tls_type = elf_x86_64_local_got_tls_type (ibfd);
2446 local_tlsdesc_gotent = elf_x86_64_local_tlsdesc_gotent (ibfd);
2448 srel = htab->elf.srelgot;
2449 for (; local_got < end_local_got;
2450 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2452 *local_tlsdesc_gotent = (bfd_vma) -1;
2455 if (GOT_TLS_GDESC_P (*local_tls_type))
2457 *local_tlsdesc_gotent = htab->elf.sgotplt->size
2458 - elf_x86_64_compute_jump_table_size (htab);
2459 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2460 *local_got = (bfd_vma) -2;
2462 if (! GOT_TLS_GDESC_P (*local_tls_type)
2463 || GOT_TLS_GD_P (*local_tls_type))
2465 *local_got = s->size;
2466 s->size += GOT_ENTRY_SIZE;
2467 if (GOT_TLS_GD_P (*local_tls_type))
2468 s->size += GOT_ENTRY_SIZE;
2471 || GOT_TLS_GD_ANY_P (*local_tls_type)
2472 || *local_tls_type == GOT_TLS_IE)
2474 if (GOT_TLS_GDESC_P (*local_tls_type))
2476 htab->elf.srelplt->size
2477 += bed->s->sizeof_rela;
2478 htab->tlsdesc_plt = (bfd_vma) -1;
2480 if (! GOT_TLS_GDESC_P (*local_tls_type)
2481 || GOT_TLS_GD_P (*local_tls_type))
2482 srel->size += bed->s->sizeof_rela;
2486 *local_got = (bfd_vma) -1;
2490 if (htab->tls_ld_got.refcount > 0)
2492 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2494 htab->tls_ld_got.offset = htab->elf.sgot->size;
2495 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
2496 htab->elf.srelgot->size += bed->s->sizeof_rela;
2499 htab->tls_ld_got.offset = -1;
2501 /* Allocate global sym .plt and .got entries, and space for global
2502 sym dynamic relocs. */
2503 elf_link_hash_traverse (&htab->elf, elf_x86_64_allocate_dynrelocs,
2506 /* Allocate .plt and .got entries, and space for local symbols. */
2507 htab_traverse (htab->loc_hash_table,
2508 elf_x86_64_allocate_local_dynrelocs,
2511 /* For every jump slot reserved in the sgotplt, reloc_count is
2512 incremented. However, when we reserve space for TLS descriptors,
2513 it's not incremented, so in order to compute the space reserved
2514 for them, it suffices to multiply the reloc count by the jump
2516 if (htab->elf.srelplt)
2517 htab->sgotplt_jump_table_size
2518 = elf_x86_64_compute_jump_table_size (htab);
2520 if (htab->tlsdesc_plt)
2522 /* If we're not using lazy TLS relocations, don't generate the
2523 PLT and GOT entries they require. */
2524 if ((info->flags & DF_BIND_NOW))
2525 htab->tlsdesc_plt = 0;
2528 htab->tlsdesc_got = htab->elf.sgot->size;
2529 htab->elf.sgot->size += GOT_ENTRY_SIZE;
2530 /* Reserve room for the initial entry.
2531 FIXME: we could probably do away with it in this case. */
2532 if (htab->elf.splt->size == 0)
2533 htab->elf.splt->size += PLT_ENTRY_SIZE;
2534 htab->tlsdesc_plt = htab->elf.splt->size;
2535 htab->elf.splt->size += PLT_ENTRY_SIZE;
2539 if (htab->elf.sgotplt)
2541 struct elf_link_hash_entry *got;
2542 got = elf_link_hash_lookup (elf_hash_table (info),
2543 "_GLOBAL_OFFSET_TABLE_",
2544 FALSE, FALSE, FALSE);
2546 /* Don't allocate .got.plt section if there are no GOT nor PLT
2547 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2549 || !got->ref_regular_nonweak)
2550 && (htab->elf.sgotplt->size
2551 == get_elf_backend_data (output_bfd)->got_header_size)
2552 && (htab->elf.splt == NULL
2553 || htab->elf.splt->size == 0)
2554 && (htab->elf.sgot == NULL
2555 || htab->elf.sgot->size == 0)
2556 && (htab->elf.iplt == NULL
2557 || htab->elf.iplt->size == 0)
2558 && (htab->elf.igotplt == NULL
2559 || htab->elf.igotplt->size == 0))
2560 htab->elf.sgotplt->size = 0;
2563 /* We now have determined the sizes of the various dynamic sections.
2564 Allocate memory for them. */
2566 for (s = dynobj->sections; s != NULL; s = s->next)
2568 if ((s->flags & SEC_LINKER_CREATED) == 0)
2571 if (s == htab->elf.splt
2572 || s == htab->elf.sgot
2573 || s == htab->elf.sgotplt
2574 || s == htab->elf.iplt
2575 || s == htab->elf.igotplt
2576 || s == htab->sdynbss)
2578 /* Strip this section if we don't need it; see the
2581 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2583 if (s->size != 0 && s != htab->elf.srelplt)
2586 /* We use the reloc_count field as a counter if we need
2587 to copy relocs into the output file. */
2588 if (s != htab->elf.srelplt)
2593 /* It's not one of our sections, so don't allocate space. */
2599 /* If we don't need this section, strip it from the
2600 output file. This is mostly to handle .rela.bss and
2601 .rela.plt. We must create both sections in
2602 create_dynamic_sections, because they must be created
2603 before the linker maps input sections to output
2604 sections. The linker does that before
2605 adjust_dynamic_symbol is called, and it is that
2606 function which decides whether anything needs to go
2607 into these sections. */
2609 s->flags |= SEC_EXCLUDE;
2613 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2616 /* Allocate memory for the section contents. We use bfd_zalloc
2617 here in case unused entries are not reclaimed before the
2618 section's contents are written out. This should not happen,
2619 but this way if it does, we get a R_X86_64_NONE reloc instead
2621 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2622 if (s->contents == NULL)
2626 if (htab->elf.dynamic_sections_created)
2628 /* Add some entries to the .dynamic section. We fill in the
2629 values later, in elf_x86_64_finish_dynamic_sections, but we
2630 must add the entries now so that we get the correct size for
2631 the .dynamic section. The DT_DEBUG entry is filled in by the
2632 dynamic linker and used by the debugger. */
2633 #define add_dynamic_entry(TAG, VAL) \
2634 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2636 if (info->executable)
2638 if (!add_dynamic_entry (DT_DEBUG, 0))
2642 if (htab->elf.splt->size != 0)
2644 if (!add_dynamic_entry (DT_PLTGOT, 0)
2645 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2646 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2647 || !add_dynamic_entry (DT_JMPREL, 0))
2650 if (htab->tlsdesc_plt
2651 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2652 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2658 if (!add_dynamic_entry (DT_RELA, 0)
2659 || !add_dynamic_entry (DT_RELASZ, 0)
2660 || !add_dynamic_entry (DT_RELAENT, bed->s->sizeof_rela))
2663 /* If any dynamic relocs apply to a read-only section,
2664 then we need a DT_TEXTREL entry. */
2665 if ((info->flags & DF_TEXTREL) == 0)
2666 elf_link_hash_traverse (&htab->elf,
2667 elf_x86_64_readonly_dynrelocs,
2670 if ((info->flags & DF_TEXTREL) != 0)
2672 if (!add_dynamic_entry (DT_TEXTREL, 0))
2677 #undef add_dynamic_entry
2683 elf_x86_64_always_size_sections (bfd *output_bfd,
2684 struct bfd_link_info *info)
2686 asection *tls_sec = elf_hash_table (info)->tls_sec;
2690 struct elf_link_hash_entry *tlsbase;
2692 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2693 "_TLS_MODULE_BASE_",
2694 FALSE, FALSE, FALSE);
2696 if (tlsbase && tlsbase->type == STT_TLS)
2698 struct elf_x86_64_link_hash_table *htab;
2699 struct bfd_link_hash_entry *bh = NULL;
2700 const struct elf_backend_data *bed
2701 = get_elf_backend_data (output_bfd);
2703 htab = elf_x86_64_hash_table (info);
2707 if (!(_bfd_generic_link_add_one_symbol
2708 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2709 tls_sec, 0, NULL, FALSE,
2710 bed->collect, &bh)))
2713 htab->tls_module_base = bh;
2715 tlsbase = (struct elf_link_hash_entry *)bh;
2716 tlsbase->def_regular = 1;
2717 tlsbase->other = STV_HIDDEN;
2718 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2725 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2726 executables. Rather than setting it to the beginning of the TLS
2727 section, we have to set it to the end. This function may be called
2728 multiple times, it is idempotent. */
2731 elf_x86_64_set_tls_module_base (struct bfd_link_info *info)
2733 struct elf_x86_64_link_hash_table *htab;
2734 struct bfd_link_hash_entry *base;
2736 if (!info->executable)
2739 htab = elf_x86_64_hash_table (info);
2743 base = htab->tls_module_base;
2747 base->u.def.value = htab->elf.tls_size;
2750 /* Return the base VMA address which should be subtracted from real addresses
2751 when resolving @dtpoff relocation.
2752 This is PT_TLS segment p_vaddr. */
2755 elf_x86_64_dtpoff_base (struct bfd_link_info *info)
2757 /* If tls_sec is NULL, we should have signalled an error already. */
2758 if (elf_hash_table (info)->tls_sec == NULL)
2760 return elf_hash_table (info)->tls_sec->vma;
2763 /* Return the relocation value for @tpoff relocation
2764 if STT_TLS virtual address is ADDRESS. */
2767 elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
2769 struct elf_link_hash_table *htab = elf_hash_table (info);
2770 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
2771 bfd_vma static_tls_size;
2773 /* If tls_segment is NULL, we should have signalled an error already. */
2774 if (htab->tls_sec == NULL)
2777 /* Consider special static TLS alignment requirements. */
2778 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
2779 return address - static_tls_size - htab->tls_sec->vma;
2782 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2786 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2788 /* Opcode Instruction
2791 0x0f 0x8x conditional jump */
2793 && (contents [offset - 1] == 0xe8
2794 || contents [offset - 1] == 0xe9))
2796 && contents [offset - 2] == 0x0f
2797 && (contents [offset - 1] & 0xf0) == 0x80));
2800 /* Relocate an x86_64 ELF section. */
2803 elf_x86_64_relocate_section (bfd *output_bfd,
2804 struct bfd_link_info *info,
2806 asection *input_section,
2808 Elf_Internal_Rela *relocs,
2809 Elf_Internal_Sym *local_syms,
2810 asection **local_sections)
2812 struct elf_x86_64_link_hash_table *htab;
2813 Elf_Internal_Shdr *symtab_hdr;
2814 struct elf_link_hash_entry **sym_hashes;
2815 bfd_vma *local_got_offsets;
2816 bfd_vma *local_tlsdesc_gotents;
2817 Elf_Internal_Rela *rel;
2818 Elf_Internal_Rela *relend;
2820 BFD_ASSERT (is_x86_64_elf (input_bfd));
2822 htab = elf_x86_64_hash_table (info);
2825 symtab_hdr = &elf_symtab_hdr (input_bfd);
2826 sym_hashes = elf_sym_hashes (input_bfd);
2827 local_got_offsets = elf_local_got_offsets (input_bfd);
2828 local_tlsdesc_gotents = elf_x86_64_local_tlsdesc_gotent (input_bfd);
2830 elf_x86_64_set_tls_module_base (info);
2833 relend = relocs + input_section->reloc_count;
2834 for (; rel < relend; rel++)
2836 unsigned int r_type;
2837 reloc_howto_type *howto;
2838 unsigned long r_symndx;
2839 struct elf_link_hash_entry *h;
2840 Elf_Internal_Sym *sym;
2842 bfd_vma off, offplt;
2844 bfd_boolean unresolved_reloc;
2845 bfd_reloc_status_type r;
2849 r_type = ELF32_R_TYPE (rel->r_info);
2850 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2851 || r_type == (int) R_X86_64_GNU_VTENTRY)
2854 if (r_type >= R_X86_64_max)
2856 bfd_set_error (bfd_error_bad_value);
2860 howto = x86_64_elf_howto_table + r_type;
2861 r_symndx = htab->r_sym (rel->r_info);
2865 unresolved_reloc = FALSE;
2866 if (r_symndx < symtab_hdr->sh_info)
2868 sym = local_syms + r_symndx;
2869 sec = local_sections[r_symndx];
2871 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
2874 /* Relocate against local STT_GNU_IFUNC symbol. */
2875 if (!info->relocatable
2876 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2878 h = elf_x86_64_get_local_sym_hash (htab, input_bfd,
2883 /* Set STT_GNU_IFUNC symbol value. */
2884 h->root.u.def.value = sym->st_value;
2885 h->root.u.def.section = sec;
2890 bfd_boolean warned ATTRIBUTE_UNUSED;
2892 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2893 r_symndx, symtab_hdr, sym_hashes,
2895 unresolved_reloc, warned);
2898 if (sec != NULL && elf_discarded_section (sec))
2899 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2900 rel, relend, howto, contents);
2902 if (info->relocatable)
2905 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2906 it here if it is defined in a non-shared object. */
2908 && h->type == STT_GNU_IFUNC
2915 if ((input_section->flags & SEC_ALLOC) == 0
2916 || h->plt.offset == (bfd_vma) -1)
2919 /* STT_GNU_IFUNC symbol must go through PLT. */
2920 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
2921 relocation = (plt->output_section->vma
2922 + plt->output_offset + h->plt.offset);
2927 if (h->root.root.string)
2928 name = h->root.root.string;
2930 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
2932 (*_bfd_error_handler)
2933 (_("%B: relocation %s against STT_GNU_IFUNC "
2934 "symbol `%s' isn't handled by %s"), input_bfd,
2935 x86_64_elf_howto_table[r_type].name,
2936 name, __FUNCTION__);
2937 bfd_set_error (bfd_error_bad_value);
2946 if (ABI_64_P (output_bfd))
2950 if (rel->r_addend != 0)
2952 if (h->root.root.string)
2953 name = h->root.root.string;
2955 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
2957 (*_bfd_error_handler)
2958 (_("%B: relocation %s against STT_GNU_IFUNC "
2959 "symbol `%s' has non-zero addend: %d"),
2960 input_bfd, x86_64_elf_howto_table[r_type].name,
2961 name, rel->r_addend);
2962 bfd_set_error (bfd_error_bad_value);
2966 /* Generate dynamic relcoation only when there is a
2967 non-GOF reference in a shared object. */
2968 if (info->shared && h->non_got_ref)
2970 Elf_Internal_Rela outrel;
2973 /* Need a dynamic relocation to get the real function
2975 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2979 if (outrel.r_offset == (bfd_vma) -1
2980 || outrel.r_offset == (bfd_vma) -2)
2983 outrel.r_offset += (input_section->output_section->vma
2984 + input_section->output_offset);
2986 if (h->dynindx == -1
2988 || info->executable)
2990 /* This symbol is resolved locally. */
2991 outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
2992 outrel.r_addend = (h->root.u.def.value
2993 + h->root.u.def.section->output_section->vma
2994 + h->root.u.def.section->output_offset);
2998 outrel.r_info = htab->r_info (h->dynindx, r_type);
2999 outrel.r_addend = 0;
3002 sreloc = htab->elf.irelifunc;
3003 elf_append_rela (output_bfd, sreloc, &outrel);
3005 /* If this reloc is against an external symbol, we
3006 do not want to fiddle with the addend. Otherwise,
3007 we need to include the symbol value so that it
3008 becomes an addend for the dynamic reloc. For an
3009 internal symbol, we have updated addend. */
3015 case R_X86_64_PLT32:
3018 case R_X86_64_GOTPCREL:
3019 case R_X86_64_GOTPCREL64:
3020 base_got = htab->elf.sgot;
3021 off = h->got.offset;
3023 if (base_got == NULL)
3026 if (off == (bfd_vma) -1)
3028 /* We can't use h->got.offset here to save state, or
3029 even just remember the offset, as finish_dynamic_symbol
3030 would use that as offset into .got. */
3032 if (htab->elf.splt != NULL)
3034 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3035 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3036 base_got = htab->elf.sgotplt;
3040 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
3041 off = plt_index * GOT_ENTRY_SIZE;
3042 base_got = htab->elf.igotplt;
3045 if (h->dynindx == -1
3049 /* This references the local defitionion. We must
3050 initialize this entry in the global offset table.
3051 Since the offset must always be a multiple of 8,
3052 we use the least significant bit to record
3053 whether we have initialized it already.
3055 When doing a dynamic link, we create a .rela.got
3056 relocation entry to initialize the value. This
3057 is done in the finish_dynamic_symbol routine. */
3062 bfd_put_64 (output_bfd, relocation,
3063 base_got->contents + off);
3064 /* Note that this is harmless for the GOTPLT64
3065 case, as -1 | 1 still is -1. */
3071 relocation = (base_got->output_section->vma
3072 + base_got->output_offset + off);
3078 /* When generating a shared object, the relocations handled here are
3079 copied into the output file to be resolved at run time. */
3082 case R_X86_64_GOT32:
3083 case R_X86_64_GOT64:
3084 /* Relocation is to the entry for this symbol in the global
3086 case R_X86_64_GOTPCREL:
3087 case R_X86_64_GOTPCREL64:
3088 /* Use global offset table entry as symbol value. */
3089 case R_X86_64_GOTPLT64:
3090 /* This is the same as GOT64 for relocation purposes, but
3091 indicates the existence of a PLT entry. The difficulty is,
3092 that we must calculate the GOT slot offset from the PLT
3093 offset, if this symbol got a PLT entry (it was global).
3094 Additionally if it's computed from the PLT entry, then that
3095 GOT offset is relative to .got.plt, not to .got. */
3096 base_got = htab->elf.sgot;
3098 if (htab->elf.sgot == NULL)
3105 off = h->got.offset;
3107 && h->plt.offset != (bfd_vma)-1
3108 && off == (bfd_vma)-1)
3110 /* We can't use h->got.offset here to save
3111 state, or even just remember the offset, as
3112 finish_dynamic_symbol would use that as offset into
3114 bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3115 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3116 base_got = htab->elf.sgotplt;
3119 dyn = htab->elf.dynamic_sections_created;
3121 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3123 && SYMBOL_REFERENCES_LOCAL (info, h))
3124 || (ELF_ST_VISIBILITY (h->other)
3125 && h->root.type == bfd_link_hash_undefweak))
3127 /* This is actually a static link, or it is a -Bsymbolic
3128 link and the symbol is defined locally, or the symbol
3129 was forced to be local because of a version file. We
3130 must initialize this entry in the global offset table.
3131 Since the offset must always be a multiple of 8, we
3132 use the least significant bit to record whether we
3133 have initialized it already.
3135 When doing a dynamic link, we create a .rela.got
3136 relocation entry to initialize the value. This is
3137 done in the finish_dynamic_symbol routine. */
3142 bfd_put_64 (output_bfd, relocation,
3143 base_got->contents + off);
3144 /* Note that this is harmless for the GOTPLT64 case,
3145 as -1 | 1 still is -1. */
3150 unresolved_reloc = FALSE;
3154 if (local_got_offsets == NULL)
3157 off = local_got_offsets[r_symndx];
3159 /* The offset must always be a multiple of 8. We use
3160 the least significant bit to record whether we have
3161 already generated the necessary reloc. */
3166 bfd_put_64 (output_bfd, relocation,
3167 base_got->contents + off);
3172 Elf_Internal_Rela outrel;
3174 /* We need to generate a R_X86_64_RELATIVE reloc
3175 for the dynamic linker. */
3176 s = htab->elf.srelgot;
3180 outrel.r_offset = (base_got->output_section->vma
3181 + base_got->output_offset
3183 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3184 outrel.r_addend = relocation;
3185 elf_append_rela (output_bfd, s, &outrel);
3188 local_got_offsets[r_symndx] |= 1;
3192 if (off >= (bfd_vma) -2)
3195 relocation = base_got->output_section->vma
3196 + base_got->output_offset + off;
3197 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
3198 relocation -= htab->elf.sgotplt->output_section->vma
3199 - htab->elf.sgotplt->output_offset;
3203 case R_X86_64_GOTOFF64:
3204 /* Relocation is relative to the start of the global offset
3207 /* Check to make sure it isn't a protected function symbol
3208 for shared library since it may not be local when used
3209 as function address. */
3213 && h->type == STT_FUNC
3214 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3216 (*_bfd_error_handler)
3217 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3218 input_bfd, h->root.root.string);
3219 bfd_set_error (bfd_error_bad_value);
3223 /* Note that sgot is not involved in this
3224 calculation. We always want the start of .got.plt. If we
3225 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3226 permitted by the ABI, we might have to change this
3228 relocation -= htab->elf.sgotplt->output_section->vma
3229 + htab->elf.sgotplt->output_offset;
3232 case R_X86_64_GOTPC32:
3233 case R_X86_64_GOTPC64:
3234 /* Use global offset table as symbol value. */
3235 relocation = htab->elf.sgotplt->output_section->vma
3236 + htab->elf.sgotplt->output_offset;
3237 unresolved_reloc = FALSE;
3240 case R_X86_64_PLTOFF64:
3241 /* Relocation is PLT entry relative to GOT. For local
3242 symbols it's the symbol itself relative to GOT. */
3244 /* See PLT32 handling. */
3245 && h->plt.offset != (bfd_vma) -1
3246 && htab->elf.splt != NULL)
3248 relocation = (htab->elf.splt->output_section->vma
3249 + htab->elf.splt->output_offset
3251 unresolved_reloc = FALSE;
3254 relocation -= htab->elf.sgotplt->output_section->vma
3255 + htab->elf.sgotplt->output_offset;
3258 case R_X86_64_PLT32:
3259 /* Relocation is to the entry for this symbol in the
3260 procedure linkage table. */
3262 /* Resolve a PLT32 reloc against a local symbol directly,
3263 without using the procedure linkage table. */
3267 if (h->plt.offset == (bfd_vma) -1
3268 || htab->elf.splt == NULL)
3270 /* We didn't make a PLT entry for this symbol. This
3271 happens when statically linking PIC code, or when
3272 using -Bsymbolic. */
3276 relocation = (htab->elf.splt->output_section->vma
3277 + htab->elf.splt->output_offset
3279 unresolved_reloc = FALSE;
3286 && ABI_64_P (output_bfd)
3287 && (input_section->flags & SEC_ALLOC) != 0
3288 && (input_section->flags & SEC_READONLY) != 0
3291 bfd_boolean fail = FALSE;
3293 = (r_type == R_X86_64_PC32
3294 && is_32bit_relative_branch (contents, rel->r_offset));
3296 if (SYMBOL_REFERENCES_LOCAL (info, h))
3298 /* Symbol is referenced locally. Make sure it is
3299 defined locally or for a branch. */
3300 fail = !h->def_regular && !branch;
3304 /* Symbol isn't referenced locally. We only allow
3305 branch to symbol with non-default visibility. */
3307 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
3314 const char *pic = "";
3316 switch (ELF_ST_VISIBILITY (h->other))
3319 v = _("hidden symbol");
3322 v = _("internal symbol");
3325 v = _("protected symbol");
3329 pic = _("; recompile with -fPIC");
3334 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3336 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3338 (*_bfd_error_handler) (fmt, input_bfd,
3339 x86_64_elf_howto_table[r_type].name,
3340 v, h->root.root.string, pic);
3341 bfd_set_error (bfd_error_bad_value);
3352 /* FIXME: The ABI says the linker should make sure the value is
3353 the same when it's zeroextended to 64 bit. */
3355 if ((input_section->flags & SEC_ALLOC) == 0)
3360 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3361 || h->root.type != bfd_link_hash_undefweak)
3362 && (! IS_X86_64_PCREL_TYPE (r_type)
3363 || ! SYMBOL_CALLS_LOCAL (info, h)))
3364 || (ELIMINATE_COPY_RELOCS
3371 || h->root.type == bfd_link_hash_undefweak
3372 || h->root.type == bfd_link_hash_undefined)))
3374 Elf_Internal_Rela outrel;
3375 bfd_boolean skip, relocate;
3378 /* When generating a shared object, these relocations
3379 are copied into the output file to be resolved at run
3385 _bfd_elf_section_offset (output_bfd, info, input_section,
3387 if (outrel.r_offset == (bfd_vma) -1)
3389 else if (outrel.r_offset == (bfd_vma) -2)
3390 skip = TRUE, relocate = TRUE;
3392 outrel.r_offset += (input_section->output_section->vma
3393 + input_section->output_offset);
3396 memset (&outrel, 0, sizeof outrel);
3398 /* h->dynindx may be -1 if this symbol was marked to
3402 && (IS_X86_64_PCREL_TYPE (r_type)
3404 || ! SYMBOLIC_BIND (info, h)
3405 || ! h->def_regular))
3407 outrel.r_info = htab->r_info (h->dynindx, r_type);
3408 outrel.r_addend = rel->r_addend;
3412 /* This symbol is local, or marked to become local. */
3413 if (r_type == htab->pointer_r_type)
3416 outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
3417 outrel.r_addend = relocation + rel->r_addend;
3423 if (bfd_is_abs_section (sec))
3425 else if (sec == NULL || sec->owner == NULL)
3427 bfd_set_error (bfd_error_bad_value);
3434 /* We are turning this relocation into one
3435 against a section symbol. It would be
3436 proper to subtract the symbol's value,
3437 osec->vma, from the emitted reloc addend,
3438 but ld.so expects buggy relocs. */
3439 osec = sec->output_section;
3440 sindx = elf_section_data (osec)->dynindx;
3443 asection *oi = htab->elf.text_index_section;
3444 sindx = elf_section_data (oi)->dynindx;
3446 BFD_ASSERT (sindx != 0);
3449 outrel.r_info = htab->r_info (sindx, r_type);
3450 outrel.r_addend = relocation + rel->r_addend;
3454 sreloc = elf_section_data (input_section)->sreloc;
3456 if (sreloc == NULL || sreloc->contents == NULL)
3458 r = bfd_reloc_notsupported;
3459 goto check_relocation_error;
3462 elf_append_rela (output_bfd, sreloc, &outrel);
3464 /* If this reloc is against an external symbol, we do
3465 not want to fiddle with the addend. Otherwise, we
3466 need to include the symbol value so that it becomes
3467 an addend for the dynamic reloc. */
3474 case R_X86_64_TLSGD:
3475 case R_X86_64_GOTPC32_TLSDESC:
3476 case R_X86_64_TLSDESC_CALL:
3477 case R_X86_64_GOTTPOFF:
3478 tls_type = GOT_UNKNOWN;
3479 if (h == NULL && local_got_offsets)
3480 tls_type = elf_x86_64_local_got_tls_type (input_bfd) [r_symndx];
3482 tls_type = elf_x86_64_hash_entry (h)->tls_type;
3484 if (! elf_x86_64_tls_transition (info, input_bfd,
3485 input_section, contents,
3486 symtab_hdr, sym_hashes,
3487 &r_type, tls_type, rel,
3488 relend, h, r_symndx))
3491 if (r_type == R_X86_64_TPOFF32)
3493 bfd_vma roff = rel->r_offset;
3495 BFD_ASSERT (! unresolved_reloc);
3497 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3499 /* GD->LE transition. For 64bit, change
3500 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3501 .word 0x6666; rex64; call __tls_get_addr
3504 leaq foo@tpoff(%rax), %rax
3506 leaq foo@tlsgd(%rip), %rdi
3507 .word 0x6666; rex64; call __tls_get_addr
3510 leaq foo@tpoff(%rax), %rax */
3511 if (ABI_64_P (output_bfd))
3512 memcpy (contents + roff - 4,
3513 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3516 memcpy (contents + roff - 3,
3517 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3519 bfd_put_32 (output_bfd,
3520 elf_x86_64_tpoff (info, relocation),
3521 contents + roff + 8);
3522 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3526 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3528 /* GDesc -> LE transition.
3529 It's originally something like:
3530 leaq x@tlsdesc(%rip), %rax
3533 movl $x@tpoff, %rax. */
3535 unsigned int val, type;
3537 type = bfd_get_8 (input_bfd, contents + roff - 3);
3538 val = bfd_get_8 (input_bfd, contents + roff - 1);
3539 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
3540 contents + roff - 3);
3541 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
3542 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3543 contents + roff - 1);
3544 bfd_put_32 (output_bfd,
3545 elf_x86_64_tpoff (info, relocation),
3549 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3551 /* GDesc -> LE transition.
3556 bfd_put_8 (output_bfd, 0x66, contents + roff);
3557 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3560 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
3562 /* IE->LE transition:
3563 Originally it can be one of:
3564 movq foo@gottpoff(%rip), %reg
3565 addq foo@gottpoff(%rip), %reg
3568 leaq foo(%reg), %reg
3571 unsigned int val, type, reg;
3573 val = bfd_get_8 (input_bfd, contents + roff - 3);
3574 type = bfd_get_8 (input_bfd, contents + roff - 2);
3575 reg = bfd_get_8 (input_bfd, contents + roff - 1);
3581 bfd_put_8 (output_bfd, 0x49,
3582 contents + roff - 3);
3583 else if (!ABI_64_P (output_bfd) && val == 0x44)
3584 bfd_put_8 (output_bfd, 0x41,
3585 contents + roff - 3);
3586 bfd_put_8 (output_bfd, 0xc7,
3587 contents + roff - 2);
3588 bfd_put_8 (output_bfd, 0xc0 | reg,
3589 contents + roff - 1);
3593 /* addq -> addq - addressing with %rsp/%r12 is
3596 bfd_put_8 (output_bfd, 0x49,
3597 contents + roff - 3);
3598 else if (!ABI_64_P (output_bfd) && val == 0x44)
3599 bfd_put_8 (output_bfd, 0x41,
3600 contents + roff - 3);
3601 bfd_put_8 (output_bfd, 0x81,
3602 contents + roff - 2);
3603 bfd_put_8 (output_bfd, 0xc0 | reg,
3604 contents + roff - 1);
3610 bfd_put_8 (output_bfd, 0x4d,
3611 contents + roff - 3);
3612 else if (!ABI_64_P (output_bfd) && val == 0x44)
3613 bfd_put_8 (output_bfd, 0x45,
3614 contents + roff - 3);
3615 bfd_put_8 (output_bfd, 0x8d,
3616 contents + roff - 2);
3617 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
3618 contents + roff - 1);
3620 bfd_put_32 (output_bfd,
3621 elf_x86_64_tpoff (info, relocation),
3629 if (htab->elf.sgot == NULL)
3634 off = h->got.offset;
3635 offplt = elf_x86_64_hash_entry (h)->tlsdesc_got;
3639 if (local_got_offsets == NULL)
3642 off = local_got_offsets[r_symndx];
3643 offplt = local_tlsdesc_gotents[r_symndx];
3650 Elf_Internal_Rela outrel;
3654 if (htab->elf.srelgot == NULL)
3657 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3659 if (GOT_TLS_GDESC_P (tls_type))
3661 outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC);
3662 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3663 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
3664 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3665 + htab->elf.sgotplt->output_offset
3667 + htab->sgotplt_jump_table_size);
3668 sreloc = htab->elf.srelplt;
3670 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
3672 outrel.r_addend = 0;
3673 elf_append_rela (output_bfd, sreloc, &outrel);
3676 sreloc = htab->elf.srelgot;
3678 outrel.r_offset = (htab->elf.sgot->output_section->vma
3679 + htab->elf.sgot->output_offset + off);
3681 if (GOT_TLS_GD_P (tls_type))
3682 dr_type = R_X86_64_DTPMOD64;
3683 else if (GOT_TLS_GDESC_P (tls_type))
3686 dr_type = R_X86_64_TPOFF64;
3688 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
3689 outrel.r_addend = 0;
3690 if ((dr_type == R_X86_64_TPOFF64
3691 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3692 outrel.r_addend = relocation - elf_x86_64_dtpoff_base (info);
3693 outrel.r_info = htab->r_info (indx, dr_type);
3695 elf_append_rela (output_bfd, sreloc, &outrel);
3697 if (GOT_TLS_GD_P (tls_type))
3701 BFD_ASSERT (! unresolved_reloc);
3702 bfd_put_64 (output_bfd,
3703 relocation - elf_x86_64_dtpoff_base (info),
3704 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3708 bfd_put_64 (output_bfd, 0,
3709 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3710 outrel.r_info = htab->r_info (indx,
3712 outrel.r_offset += GOT_ENTRY_SIZE;
3713 elf_append_rela (output_bfd, sreloc,
3722 local_got_offsets[r_symndx] |= 1;
3725 if (off >= (bfd_vma) -2
3726 && ! GOT_TLS_GDESC_P (tls_type))
3728 if (r_type == ELF32_R_TYPE (rel->r_info))
3730 if (r_type == R_X86_64_GOTPC32_TLSDESC
3731 || r_type == R_X86_64_TLSDESC_CALL)
3732 relocation = htab->elf.sgotplt->output_section->vma
3733 + htab->elf.sgotplt->output_offset
3734 + offplt + htab->sgotplt_jump_table_size;
3736 relocation = htab->elf.sgot->output_section->vma
3737 + htab->elf.sgot->output_offset + off;
3738 unresolved_reloc = FALSE;
3742 bfd_vma roff = rel->r_offset;
3744 if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3746 /* GD->IE transition. For 64bit, change
3747 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3748 .word 0x6666; rex64; call __tls_get_addr@plt
3751 addq foo@gottpoff(%rip), %rax
3753 leaq foo@tlsgd(%rip), %rdi
3754 .word 0x6666; rex64; call __tls_get_addr@plt
3757 addq foo@gottpoff(%rip), %rax */
3758 if (ABI_64_P (output_bfd))
3759 memcpy (contents + roff - 4,
3760 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3763 memcpy (contents + roff - 3,
3764 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3767 relocation = (htab->elf.sgot->output_section->vma
3768 + htab->elf.sgot->output_offset + off
3770 - input_section->output_section->vma
3771 - input_section->output_offset
3773 bfd_put_32 (output_bfd, relocation,
3774 contents + roff + 8);
3775 /* Skip R_X86_64_PLT32. */
3779 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3781 /* GDesc -> IE transition.
3782 It's originally something like:
3783 leaq x@tlsdesc(%rip), %rax
3786 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3788 /* Now modify the instruction as appropriate. To
3789 turn a leaq into a movq in the form we use it, it
3790 suffices to change the second byte from 0x8d to
3792 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3794 bfd_put_32 (output_bfd,
3795 htab->elf.sgot->output_section->vma
3796 + htab->elf.sgot->output_offset + off
3798 - input_section->output_section->vma
3799 - input_section->output_offset
3804 else if (ELF32_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3806 /* GDesc -> IE transition.
3813 bfd_put_8 (output_bfd, 0x66, contents + roff);
3814 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3822 case R_X86_64_TLSLD:
3823 if (! elf_x86_64_tls_transition (info, input_bfd,
3824 input_section, contents,
3825 symtab_hdr, sym_hashes,
3826 &r_type, GOT_UNKNOWN,
3827 rel, relend, h, r_symndx))
3830 if (r_type != R_X86_64_TLSLD)
3832 /* LD->LE transition:
3833 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3834 For 64bit, we change it into:
3835 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
3836 For 32bit, we change it into:
3837 nopl 0x0(%rax); movl %fs:0, %eax. */
3839 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3840 if (ABI_64_P (output_bfd))
3841 memcpy (contents + rel->r_offset - 3,
3842 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3844 memcpy (contents + rel->r_offset - 3,
3845 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3846 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3851 if (htab->elf.sgot == NULL)
3854 off = htab->tls_ld_got.offset;
3859 Elf_Internal_Rela outrel;
3861 if (htab->elf.srelgot == NULL)
3864 outrel.r_offset = (htab->elf.sgot->output_section->vma
3865 + htab->elf.sgot->output_offset + off);
3867 bfd_put_64 (output_bfd, 0,
3868 htab->elf.sgot->contents + off);
3869 bfd_put_64 (output_bfd, 0,
3870 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3871 outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64);
3872 outrel.r_addend = 0;
3873 elf_append_rela (output_bfd, htab->elf.srelgot,
3875 htab->tls_ld_got.offset |= 1;
3877 relocation = htab->elf.sgot->output_section->vma
3878 + htab->elf.sgot->output_offset + off;
3879 unresolved_reloc = FALSE;
3882 case R_X86_64_DTPOFF32:
3883 if (!info->executable|| (input_section->flags & SEC_CODE) == 0)
3884 relocation -= elf_x86_64_dtpoff_base (info);
3886 relocation = elf_x86_64_tpoff (info, relocation);
3889 case R_X86_64_TPOFF32:
3890 case R_X86_64_TPOFF64:
3891 BFD_ASSERT (info->executable);
3892 relocation = elf_x86_64_tpoff (info, relocation);
3899 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3900 because such sections are not SEC_ALLOC and thus ld.so will
3901 not process them. */
3902 if (unresolved_reloc
3903 && !((input_section->flags & SEC_DEBUGGING) != 0
3905 (*_bfd_error_handler)
3906 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3909 (long) rel->r_offset,
3911 h->root.root.string);
3914 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3915 contents, rel->r_offset,
3916 relocation, rel->r_addend);
3918 check_relocation_error:
3919 if (r != bfd_reloc_ok)
3924 name = h->root.root.string;
3927 name = bfd_elf_string_from_elf_section (input_bfd,
3928 symtab_hdr->sh_link,
3933 name = bfd_section_name (input_bfd, sec);
3936 if (r == bfd_reloc_overflow)
3938 if (! ((*info->callbacks->reloc_overflow)
3939 (info, (h ? &h->root : NULL), name, howto->name,
3940 (bfd_vma) 0, input_bfd, input_section,
3946 (*_bfd_error_handler)
3947 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3948 input_bfd, input_section,
3949 (long) rel->r_offset, name, (int) r);
3958 /* Finish up dynamic symbol handling. We set the contents of various
3959 dynamic sections here. */
3962 elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
3963 struct bfd_link_info *info,
3964 struct elf_link_hash_entry *h,
3965 Elf_Internal_Sym *sym)
3967 struct elf_x86_64_link_hash_table *htab;
3969 htab = elf_x86_64_hash_table (info);
3973 if (h->plt.offset != (bfd_vma) -1)
3977 Elf_Internal_Rela rela;
3979 asection *plt, *gotplt, *relplt;
3980 const struct elf_backend_data *bed;
3982 /* When building a static executable, use .iplt, .igot.plt and
3983 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3984 if (htab->elf.splt != NULL)
3986 plt = htab->elf.splt;
3987 gotplt = htab->elf.sgotplt;
3988 relplt = htab->elf.srelplt;
3992 plt = htab->elf.iplt;
3993 gotplt = htab->elf.igotplt;
3994 relplt = htab->elf.irelplt;
3997 /* This symbol has an entry in the procedure linkage table. Set
3999 if ((h->dynindx == -1
4000 && !((h->forced_local || info->executable)
4002 && h->type == STT_GNU_IFUNC))
4008 /* Get the index in the procedure linkage table which
4009 corresponds to this symbol. This is the index of this symbol
4010 in all the symbols for which we are making plt entries. The
4011 first entry in the procedure linkage table is reserved.
4013 Get the offset into the .got table of the entry that
4014 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4015 bytes. The first three are reserved for the dynamic linker.
4017 For static executables, we don't reserve anything. */
4019 if (plt == htab->elf.splt)
4021 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
4022 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
4026 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
4027 got_offset = plt_index * GOT_ENTRY_SIZE;
4030 /* Fill in the entry in the procedure linkage table. */
4031 memcpy (plt->contents + h->plt.offset, elf_x86_64_plt_entry,
4034 /* Insert the relocation positions of the plt section. The magic
4035 numbers at the end of the statements are the positions of the
4036 relocations in the plt section. */
4037 /* Put offset for jmp *name@GOTPCREL(%rip), since the
4038 instruction uses 6 bytes, subtract this value. */
4039 bfd_put_32 (output_bfd,
4040 (gotplt->output_section->vma
4041 + gotplt->output_offset
4043 - plt->output_section->vma
4044 - plt->output_offset
4047 plt->contents + h->plt.offset + 2);
4049 /* Don't fill PLT entry for static executables. */
4050 if (plt == htab->elf.splt)
4052 /* Put relocation index. */
4053 bfd_put_32 (output_bfd, plt_index,
4054 plt->contents + h->plt.offset + 7);
4055 /* Put offset for jmp .PLT0. */
4056 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
4057 plt->contents + h->plt.offset + 12);
4060 /* Fill in the entry in the global offset table, initially this
4061 points to the pushq instruction in the PLT which is at offset 6. */
4062 bfd_put_64 (output_bfd, (plt->output_section->vma
4063 + plt->output_offset
4064 + h->plt.offset + 6),
4065 gotplt->contents + got_offset);
4067 /* Fill in the entry in the .rela.plt section. */
4068 rela.r_offset = (gotplt->output_section->vma
4069 + gotplt->output_offset
4071 if (h->dynindx == -1
4072 || ((info->executable
4073 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4075 && h->type == STT_GNU_IFUNC))
4077 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4078 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4079 rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
4080 rela.r_addend = (h->root.u.def.value
4081 + h->root.u.def.section->output_section->vma
4082 + h->root.u.def.section->output_offset);
4086 rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT);
4090 bed = get_elf_backend_data (output_bfd);
4091 loc = relplt->contents + plt_index * bed->s->sizeof_rela;
4092 bed->s->swap_reloca_out (output_bfd, &rela, loc);
4094 if (!h->def_regular)
4096 /* Mark the symbol as undefined, rather than as defined in
4097 the .plt section. Leave the value if there were any
4098 relocations where pointer equality matters (this is a clue
4099 for the dynamic linker, to make function pointer
4100 comparisons work between an application and shared
4101 library), otherwise set it to zero. If a function is only
4102 called from a binary, there is no need to slow down
4103 shared libraries because of that. */
4104 sym->st_shndx = SHN_UNDEF;
4105 if (!h->pointer_equality_needed)
4110 if (h->got.offset != (bfd_vma) -1
4111 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h)->tls_type)
4112 && elf_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
4114 Elf_Internal_Rela rela;
4116 /* This symbol has an entry in the global offset table. Set it
4118 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
4121 rela.r_offset = (htab->elf.sgot->output_section->vma
4122 + htab->elf.sgot->output_offset
4123 + (h->got.offset &~ (bfd_vma) 1));
4125 /* If this is a static link, or it is a -Bsymbolic link and the
4126 symbol is defined locally or was forced to be local because
4127 of a version file, we just want to emit a RELATIVE reloc.
4128 The entry in the global offset table will already have been
4129 initialized in the relocate_section function. */
4131 && h->type == STT_GNU_IFUNC)
4135 /* Generate R_X86_64_GLOB_DAT. */
4142 if (!h->pointer_equality_needed)
4145 /* For non-shared object, we can't use .got.plt, which
4146 contains the real function addres if we need pointer
4147 equality. We load the GOT entry with the PLT entry. */
4148 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4149 bfd_put_64 (output_bfd, (plt->output_section->vma
4150 + plt->output_offset
4152 htab->elf.sgot->contents + h->got.offset);
4156 else if (info->shared
4157 && SYMBOL_REFERENCES_LOCAL (info, h))
4159 if (!h->def_regular)
4161 BFD_ASSERT((h->got.offset & 1) != 0);
4162 rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4163 rela.r_addend = (h->root.u.def.value
4164 + h->root.u.def.section->output_section->vma
4165 + h->root.u.def.section->output_offset);
4169 BFD_ASSERT((h->got.offset & 1) == 0);
4171 bfd_put_64 (output_bfd, (bfd_vma) 0,
4172 htab->elf.sgot->contents + h->got.offset);
4173 rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT);
4177 elf_append_rela (output_bfd, htab->elf.srelgot, &rela);
4182 Elf_Internal_Rela rela;
4184 /* This symbol needs a copy reloc. Set it up. */
4186 if (h->dynindx == -1
4187 || (h->root.type != bfd_link_hash_defined
4188 && h->root.type != bfd_link_hash_defweak)
4189 || htab->srelbss == NULL)
4192 rela.r_offset = (h->root.u.def.value
4193 + h->root.u.def.section->output_section->vma
4194 + h->root.u.def.section->output_offset);
4195 rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
4197 elf_append_rela (output_bfd, htab->srelbss, &rela);
4200 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4201 be NULL for local symbols. */
4203 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
4204 || h == htab->elf.hgot))
4205 sym->st_shndx = SHN_ABS;
4210 /* Finish up local dynamic symbol handling. We set the contents of
4211 various dynamic sections here. */
4214 elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
4216 struct elf_link_hash_entry *h
4217 = (struct elf_link_hash_entry *) *slot;
4218 struct bfd_link_info *info
4219 = (struct bfd_link_info *) inf;
4221 return elf_x86_64_finish_dynamic_symbol (info->output_bfd,
4225 /* Used to decide how to sort relocs in an optimal manner for the
4226 dynamic linker, before writing them out. */
4228 static enum elf_reloc_type_class
4229 elf_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
4231 switch ((int) ELF32_R_TYPE (rela->r_info))
4233 case R_X86_64_RELATIVE:
4234 return reloc_class_relative;
4235 case R_X86_64_JUMP_SLOT:
4236 return reloc_class_plt;
4238 return reloc_class_copy;
4240 return reloc_class_normal;
4244 /* Finish up the dynamic sections. */
4247 elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
4248 struct bfd_link_info *info)
4250 struct elf_x86_64_link_hash_table *htab;
4254 htab = elf_x86_64_hash_table (info);
4258 dynobj = htab->elf.dynobj;
4259 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4261 if (htab->elf.dynamic_sections_created)
4263 bfd_byte *dyncon, *dynconend;
4264 const struct elf_backend_data *bed;
4265 bfd_size_type sizeof_dyn;
4267 if (sdyn == NULL || htab->elf.sgot == NULL)
4270 bed = get_elf_backend_data (dynobj);
4271 sizeof_dyn = bed->s->sizeof_dyn;
4272 dyncon = sdyn->contents;
4273 dynconend = sdyn->contents + sdyn->size;
4274 for (; dyncon < dynconend; dyncon += sizeof_dyn)
4276 Elf_Internal_Dyn dyn;
4279 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
4287 s = htab->elf.sgotplt;
4288 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4292 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
4296 s = htab->elf.srelplt->output_section;
4297 dyn.d_un.d_val = s->size;
4301 /* The procedure linkage table relocs (DT_JMPREL) should
4302 not be included in the overall relocs (DT_RELA).
4303 Therefore, we override the DT_RELASZ entry here to
4304 make it not include the JMPREL relocs. Since the
4305 linker script arranges for .rela.plt to follow all
4306 other relocation sections, we don't have to worry
4307 about changing the DT_RELA entry. */
4308 if (htab->elf.srelplt != NULL)
4310 s = htab->elf.srelplt->output_section;
4311 dyn.d_un.d_val -= s->size;
4315 case DT_TLSDESC_PLT:
4317 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4318 + htab->tlsdesc_plt;
4321 case DT_TLSDESC_GOT:
4323 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4324 + htab->tlsdesc_got;
4328 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
4331 /* Fill in the special first entry in the procedure linkage table. */
4332 if (htab->elf.splt && htab->elf.splt->size > 0)
4334 /* Fill in the first entry in the procedure linkage table. */
4335 memcpy (htab->elf.splt->contents, elf_x86_64_plt0_entry,
4337 /* Add offset for pushq GOT+8(%rip), since the instruction
4338 uses 6 bytes subtract this value. */
4339 bfd_put_32 (output_bfd,
4340 (htab->elf.sgotplt->output_section->vma
4341 + htab->elf.sgotplt->output_offset
4343 - htab->elf.splt->output_section->vma
4344 - htab->elf.splt->output_offset
4346 htab->elf.splt->contents + 2);
4347 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4348 the end of the instruction. */
4349 bfd_put_32 (output_bfd,
4350 (htab->elf.sgotplt->output_section->vma
4351 + htab->elf.sgotplt->output_offset
4353 - htab->elf.splt->output_section->vma
4354 - htab->elf.splt->output_offset
4356 htab->elf.splt->contents + 8);
4358 elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize =
4361 if (htab->tlsdesc_plt)
4363 bfd_put_64 (output_bfd, (bfd_vma) 0,
4364 htab->elf.sgot->contents + htab->tlsdesc_got);
4366 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
4367 elf_x86_64_plt0_entry,
4370 /* Add offset for pushq GOT+8(%rip), since the
4371 instruction uses 6 bytes subtract this value. */
4372 bfd_put_32 (output_bfd,
4373 (htab->elf.sgotplt->output_section->vma
4374 + htab->elf.sgotplt->output_offset
4376 - htab->elf.splt->output_section->vma
4377 - htab->elf.splt->output_offset
4380 htab->elf.splt->contents + htab->tlsdesc_plt + 2);
4381 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4382 htab->tlsdesc_got. The 12 is the offset to the end of
4384 bfd_put_32 (output_bfd,
4385 (htab->elf.sgot->output_section->vma
4386 + htab->elf.sgot->output_offset
4388 - htab->elf.splt->output_section->vma
4389 - htab->elf.splt->output_offset
4392 htab->elf.splt->contents + htab->tlsdesc_plt + 8);
4397 if (htab->elf.sgotplt)
4399 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
4401 (*_bfd_error_handler)
4402 (_("discarded output section: `%A'"), htab->elf.sgotplt);
4406 /* Fill in the first three entries in the global offset table. */
4407 if (htab->elf.sgotplt->size > 0)
4409 /* Set the first entry in the global offset table to the address of
4410 the dynamic section. */
4412 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
4414 bfd_put_64 (output_bfd,
4415 sdyn->output_section->vma + sdyn->output_offset,
4416 htab->elf.sgotplt->contents);
4417 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4418 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
4419 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
4422 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
4426 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4427 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
4430 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4431 htab_traverse (htab->loc_hash_table,
4432 elf_x86_64_finish_local_dynamic_symbol,
4438 /* Return address for Ith PLT stub in section PLT, for relocation REL
4439 or (bfd_vma) -1 if it should not be included. */
4442 elf_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
4443 const arelent *rel ATTRIBUTE_UNUSED)
4445 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
4448 /* Handle an x86-64 specific section when reading an object file. This
4449 is called when elfcode.h finds a section with an unknown type. */
4452 elf_x86_64_section_from_shdr (bfd *abfd,
4453 Elf_Internal_Shdr *hdr,
4457 if (hdr->sh_type != SHT_X86_64_UNWIND)
4460 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
4466 /* Hook called by the linker routine which adds symbols from an object
4467 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4471 elf_x86_64_add_symbol_hook (bfd *abfd,
4472 struct bfd_link_info *info,
4473 Elf_Internal_Sym *sym,
4474 const char **namep ATTRIBUTE_UNUSED,
4475 flagword *flagsp ATTRIBUTE_UNUSED,
4481 switch (sym->st_shndx)
4483 case SHN_X86_64_LCOMMON:
4484 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
4487 lcomm = bfd_make_section_with_flags (abfd,
4491 | SEC_LINKER_CREATED));
4494 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
4497 *valp = sym->st_size;
4501 if ((abfd->flags & DYNAMIC) == 0
4502 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
4503 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
4504 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4510 /* Given a BFD section, try to locate the corresponding ELF section
4514 elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4515 asection *sec, int *index_return)
4517 if (sec == &_bfd_elf_large_com_section)
4519 *index_return = SHN_X86_64_LCOMMON;
4525 /* Process a symbol. */
4528 elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
4531 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
4533 switch (elfsym->internal_elf_sym.st_shndx)
4535 case SHN_X86_64_LCOMMON:
4536 asym->section = &_bfd_elf_large_com_section;
4537 asym->value = elfsym->internal_elf_sym.st_size;
4538 /* Common symbol doesn't set BSF_GLOBAL. */
4539 asym->flags &= ~BSF_GLOBAL;
4545 elf_x86_64_common_definition (Elf_Internal_Sym *sym)
4547 return (sym->st_shndx == SHN_COMMON
4548 || sym->st_shndx == SHN_X86_64_LCOMMON);
4552 elf_x86_64_common_section_index (asection *sec)
4554 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4557 return SHN_X86_64_LCOMMON;
4561 elf_x86_64_common_section (asection *sec)
4563 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4564 return bfd_com_section_ptr;
4566 return &_bfd_elf_large_com_section;
4570 elf_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4571 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
4572 struct elf_link_hash_entry *h,
4573 Elf_Internal_Sym *sym,
4575 bfd_vma *pvalue ATTRIBUTE_UNUSED,
4576 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
4577 bfd_boolean *skip ATTRIBUTE_UNUSED,
4578 bfd_boolean *override ATTRIBUTE_UNUSED,
4579 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
4580 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
4581 bfd_boolean *newdyn ATTRIBUTE_UNUSED,
4582 bfd_boolean *newdef,
4583 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
4584 bfd_boolean *newweak ATTRIBUTE_UNUSED,
4585 bfd *abfd ATTRIBUTE_UNUSED,
4587 bfd_boolean *olddyn ATTRIBUTE_UNUSED,
4588 bfd_boolean *olddef,
4589 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
4590 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
4594 /* A normal common symbol and a large common symbol result in a
4595 normal common symbol. We turn the large common symbol into a
4598 && h->root.type == bfd_link_hash_common
4600 && bfd_is_com_section (*sec)
4603 if (sym->st_shndx == SHN_COMMON
4604 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
4606 h->root.u.c.p->section
4607 = bfd_make_section_old_way (oldbfd, "COMMON");
4608 h->root.u.c.p->section->flags = SEC_ALLOC;
4610 else if (sym->st_shndx == SHN_X86_64_LCOMMON
4611 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
4612 *psec = *sec = bfd_com_section_ptr;
4619 elf_x86_64_additional_program_headers (bfd *abfd,
4620 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4625 /* Check to see if we need a large readonly segment. */
4626 s = bfd_get_section_by_name (abfd, ".lrodata");
4627 if (s && (s->flags & SEC_LOAD))
4630 /* Check to see if we need a large data segment. Since .lbss sections
4631 is placed right after the .bss section, there should be no need for
4632 a large data segment just because of .lbss. */
4633 s = bfd_get_section_by_name (abfd, ".ldata");
4634 if (s && (s->flags & SEC_LOAD))
4640 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4643 elf_x86_64_hash_symbol (struct elf_link_hash_entry *h)
4645 if (h->plt.offset != (bfd_vma) -1
4647 && !h->pointer_equality_needed)
4650 return _bfd_elf_hash_symbol (h);
4653 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4656 elf_x86_64_relocs_compatible (const bfd_target *input,
4657 const bfd_target *output)
4659 return ((xvec_get_elf_backend_data (input)->s->elfclass
4660 == xvec_get_elf_backend_data (output)->s->elfclass)
4661 && _bfd_elf_relocs_compatible (input, output));
4664 static const struct bfd_elf_special_section
4665 elf_x86_64_special_sections[]=
4667 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4668 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4669 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
4670 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4671 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4672 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4673 { NULL, 0, 0, 0, 0 }
4676 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4677 #define TARGET_LITTLE_NAME "elf64-x86-64"
4678 #define ELF_ARCH bfd_arch_i386
4679 #define ELF_TARGET_ID X86_64_ELF_DATA
4680 #define ELF_MACHINE_CODE EM_X86_64
4681 #define ELF_MAXPAGESIZE 0x200000
4682 #define ELF_MINPAGESIZE 0x1000
4683 #define ELF_COMMONPAGESIZE 0x1000
4685 #define elf_backend_can_gc_sections 1
4686 #define elf_backend_can_refcount 1
4687 #define elf_backend_want_got_plt 1
4688 #define elf_backend_plt_readonly 1
4689 #define elf_backend_want_plt_sym 0
4690 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4691 #define elf_backend_rela_normal 1
4693 #define elf_info_to_howto elf_x86_64_info_to_howto
4695 #define bfd_elf64_bfd_link_hash_table_create \
4696 elf_x86_64_link_hash_table_create
4697 #define bfd_elf64_bfd_link_hash_table_free \
4698 elf_x86_64_link_hash_table_free
4699 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4700 #define bfd_elf64_bfd_reloc_name_lookup \
4701 elf_x86_64_reloc_name_lookup
4703 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4704 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4705 #define elf_backend_check_relocs elf_x86_64_check_relocs
4706 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
4707 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
4708 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
4709 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
4710 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
4711 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
4712 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
4713 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
4714 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
4715 #define elf_backend_relocate_section elf_x86_64_relocate_section
4716 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
4717 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
4718 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4719 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
4720 #define elf_backend_object_p elf64_x86_64_elf_object_p
4721 #define bfd_elf64_mkobject elf_x86_64_mkobject
4723 #define elf_backend_section_from_shdr \
4724 elf_x86_64_section_from_shdr
4726 #define elf_backend_section_from_bfd_section \
4727 elf_x86_64_elf_section_from_bfd_section
4728 #define elf_backend_add_symbol_hook \
4729 elf_x86_64_add_symbol_hook
4730 #define elf_backend_symbol_processing \
4731 elf_x86_64_symbol_processing
4732 #define elf_backend_common_section_index \
4733 elf_x86_64_common_section_index
4734 #define elf_backend_common_section \
4735 elf_x86_64_common_section
4736 #define elf_backend_common_definition \
4737 elf_x86_64_common_definition
4738 #define elf_backend_merge_symbol \
4739 elf_x86_64_merge_symbol
4740 #define elf_backend_special_sections \
4741 elf_x86_64_special_sections
4742 #define elf_backend_additional_program_headers \
4743 elf_x86_64_additional_program_headers
4744 #define elf_backend_hash_symbol \
4745 elf_x86_64_hash_symbol
4747 #undef elf_backend_post_process_headers
4748 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4750 #include "elf64-target.h"
4752 /* FreeBSD support. */
4754 #undef TARGET_LITTLE_SYM
4755 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4756 #undef TARGET_LITTLE_NAME
4757 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4760 #define ELF_OSABI ELFOSABI_FREEBSD
4763 #define elf64_bed elf64_x86_64_fbsd_bed
4765 #include "elf64-target.h"
4767 /* Solaris 2 support. */
4769 #undef TARGET_LITTLE_SYM
4770 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4771 #undef TARGET_LITTLE_NAME
4772 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4774 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4775 objects won't be recognized. */
4779 #define elf64_bed elf64_x86_64_sol2_bed
4781 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
4783 #undef elf_backend_static_tls_alignment
4784 #define elf_backend_static_tls_alignment 16
4786 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4788 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4790 #undef elf_backend_want_plt_sym
4791 #define elf_backend_want_plt_sym 1
4793 #include "elf64-target.h"
4795 /* Intel L1OM support. */
4798 elf64_l1om_elf_object_p (bfd *abfd)
4800 /* Set the right machine number for an L1OM elf64 file. */
4801 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
4805 #undef TARGET_LITTLE_SYM
4806 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
4807 #undef TARGET_LITTLE_NAME
4808 #define TARGET_LITTLE_NAME "elf64-l1om"
4810 #define ELF_ARCH bfd_arch_l1om
4812 #undef ELF_MACHINE_CODE
4813 #define ELF_MACHINE_CODE EM_L1OM
4818 #define elf64_bed elf64_l1om_bed
4820 #undef elf_backend_object_p
4821 #define elf_backend_object_p elf64_l1om_elf_object_p
4823 #undef elf_backend_post_process_headers
4824 #undef elf_backend_static_tls_alignment
4826 #undef elf_backend_want_plt_sym
4827 #define elf_backend_want_plt_sym 0
4829 #include "elf64-target.h"
4831 /* FreeBSD L1OM support. */
4833 #undef TARGET_LITTLE_SYM
4834 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
4835 #undef TARGET_LITTLE_NAME
4836 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
4839 #define ELF_OSABI ELFOSABI_FREEBSD
4842 #define elf64_bed elf64_l1om_fbsd_bed
4844 #undef elf_backend_post_process_headers
4845 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4847 #include "elf64-target.h"
4849 /* 32bit x86-64 support. */
4852 elf32_x86_64_elf_object_p (bfd *abfd)
4854 /* Set the right machine number for an x86-64 elf32 file. */
4855 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32);
4859 #undef TARGET_LITTLE_SYM
4860 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
4861 #undef TARGET_LITTLE_NAME
4862 #define TARGET_LITTLE_NAME "elf32-x86-64"
4865 #define ELF_ARCH bfd_arch_i386
4867 #undef ELF_MACHINE_CODE
4868 #define ELF_MACHINE_CODE EM_X86_64
4870 #define bfd_elf32_bfd_link_hash_table_create \
4871 elf_x86_64_link_hash_table_create
4872 #define bfd_elf32_bfd_link_hash_table_free \
4873 elf_x86_64_link_hash_table_free
4874 #define bfd_elf32_bfd_reloc_type_lookup \
4875 elf_x86_64_reloc_type_lookup
4876 #define bfd_elf32_bfd_reloc_name_lookup \
4877 elf_x86_64_reloc_name_lookup
4878 #define bfd_elf32_mkobject \
4883 #undef elf_backend_post_process_headers
4885 #undef elf_backend_object_p
4886 #define elf_backend_object_p \
4887 elf32_x86_64_elf_object_p
4889 #undef elf_backend_bfd_from_remote_memory
4890 #define elf_backend_bfd_from_remote_memory \
4891 _bfd_elf32_bfd_from_remote_memory
4893 #undef elf_backend_size_info
4894 #define elf_backend_size_info \
4895 _bfd_elf32_size_info
4897 #include "elf32-target.h"