1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka <jh@suse.cz>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
32 #include "elf/x86-64.h"
34 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
35 #define MINUS_ONE (~ (bfd_vma) 0)
37 /* The relocation "howto" table. Order of fields:
38 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
39 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
40 static reloc_howto_type x86_64_elf_howto_table[] =
42 HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
43 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
45 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
46 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
48 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
49 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
51 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
52 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
54 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
55 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
58 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
61 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
63 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
64 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
66 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
67 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
69 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
70 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
72 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
73 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
75 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
76 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
78 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
79 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
80 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
81 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
82 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
83 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
84 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
85 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
86 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
87 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
89 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
90 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
92 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
93 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
95 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
96 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
98 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
99 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
101 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
102 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
104 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
105 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
107 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
108 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
110 HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
111 bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
113 HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
114 bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
115 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
116 HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
117 bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
118 FALSE, 0xffffffff, 0xffffffff, TRUE),
119 HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
120 bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
122 HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
123 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
125 HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
126 bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
127 FALSE, MINUS_ONE, MINUS_ONE, TRUE),
128 HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
129 bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
131 HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
132 bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
136 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
137 complain_overflow_bitfield, bfd_elf_generic_reloc,
138 "R_X86_64_GOTPC32_TLSDESC",
139 FALSE, 0xffffffff, 0xffffffff, TRUE),
140 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
141 complain_overflow_dont, bfd_elf_generic_reloc,
142 "R_X86_64_TLSDESC_CALL",
144 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
145 complain_overflow_bitfield, bfd_elf_generic_reloc,
147 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
148 HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
149 bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE,
152 /* We have a gap in the reloc numbers here.
153 R_X86_64_standard counts the number up to this point, and
154 R_X86_64_vt_offset is the value to subtract from a reloc type of
155 R_X86_64_GNU_VT* to form an index into this table. */
156 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
157 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
159 /* GNU extension to record C++ vtable hierarchy. */
160 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
161 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
163 /* GNU extension to record C++ vtable member usage. */
164 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
165 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
169 #define IS_X86_64_PCREL_TYPE(TYPE) \
170 ( ((TYPE) == R_X86_64_PC8) \
171 || ((TYPE) == R_X86_64_PC16) \
172 || ((TYPE) == R_X86_64_PC32) \
173 || ((TYPE) == R_X86_64_PC64))
175 /* Map BFD relocs to the x86_64 elf relocs. */
178 bfd_reloc_code_real_type bfd_reloc_val;
179 unsigned char elf_reloc_val;
182 static const struct elf_reloc_map x86_64_reloc_map[] =
184 { BFD_RELOC_NONE, R_X86_64_NONE, },
185 { BFD_RELOC_64, R_X86_64_64, },
186 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
187 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
188 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
189 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
190 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
191 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
192 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
193 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
194 { BFD_RELOC_32, R_X86_64_32, },
195 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
196 { BFD_RELOC_16, R_X86_64_16, },
197 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
198 { BFD_RELOC_8, R_X86_64_8, },
199 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
200 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
201 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
202 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
203 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
204 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
205 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
206 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
207 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
208 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
209 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
210 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
211 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
212 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
213 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
214 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
215 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
216 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
217 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
218 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
219 { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, },
220 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
221 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
224 static reloc_howto_type *
225 elf64_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
229 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
230 || r_type >= (unsigned int) R_X86_64_max)
232 if (r_type >= (unsigned int) R_X86_64_standard)
234 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
236 r_type = R_X86_64_NONE;
241 i = r_type - (unsigned int) R_X86_64_vt_offset;
242 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
243 return &x86_64_elf_howto_table[i];
246 /* Given a BFD reloc type, return a HOWTO structure. */
247 static reloc_howto_type *
248 elf64_x86_64_reloc_type_lookup (bfd *abfd,
249 bfd_reloc_code_real_type code)
253 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
256 if (x86_64_reloc_map[i].bfd_reloc_val == code)
257 return elf64_x86_64_rtype_to_howto (abfd,
258 x86_64_reloc_map[i].elf_reloc_val);
263 static reloc_howto_type *
264 elf64_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
270 i < (sizeof (x86_64_elf_howto_table)
271 / sizeof (x86_64_elf_howto_table[0]));
273 if (x86_64_elf_howto_table[i].name != NULL
274 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
275 return &x86_64_elf_howto_table[i];
280 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
283 elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
284 Elf_Internal_Rela *dst)
288 r_type = ELF64_R_TYPE (dst->r_info);
289 cache_ptr->howto = elf64_x86_64_rtype_to_howto (abfd, r_type);
290 BFD_ASSERT (r_type == cache_ptr->howto->type);
293 /* Support for core dump NOTE sections. */
295 elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
300 switch (note->descsz)
305 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
307 elf_tdata (abfd)->core_signal
308 = bfd_get_16 (abfd, note->descdata + 12);
311 elf_tdata (abfd)->core_pid
312 = bfd_get_32 (abfd, note->descdata + 32);
321 /* Make a ".reg/999" section. */
322 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
323 size, note->descpos + offset);
327 elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
329 switch (note->descsz)
334 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
335 elf_tdata (abfd)->core_program
336 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
337 elf_tdata (abfd)->core_command
338 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
341 /* Note that for some reason, a spurious space is tacked
342 onto the end of the args in some (at least one anyway)
343 implementations, so strip it off if it exists. */
346 char *command = elf_tdata (abfd)->core_command;
347 int n = strlen (command);
349 if (0 < n && command[n - 1] == ' ')
350 command[n - 1] = '\0';
356 /* Functions for the x86-64 ELF linker. */
358 /* The name of the dynamic interpreter. This is put in the .interp
361 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
363 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
364 copying dynamic variables from a shared lib into an app's dynbss
365 section, and instead use a dynamic relocation to point into the
367 #define ELIMINATE_COPY_RELOCS 1
369 /* The size in bytes of an entry in the global offset table. */
371 #define GOT_ENTRY_SIZE 8
373 /* The size in bytes of an entry in the procedure linkage table. */
375 #define PLT_ENTRY_SIZE 16
377 /* The first entry in a procedure linkage table looks like this. See the
378 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
380 static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
382 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
383 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
384 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
387 /* Subsequent entries in a procedure linkage table look like this. */
389 static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
391 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
392 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
393 0x68, /* pushq immediate */
394 0, 0, 0, 0, /* replaced with index into relocation table. */
395 0xe9, /* jmp relative */
396 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
399 /* The x86-64 linker needs to keep track of the number of relocs that
400 it decides to copy as dynamic relocs in check_relocs for each symbol.
401 This is so that it can later discard them if they are found to be
402 unnecessary. We store the information in a field extending the
403 regular ELF linker hash table. */
405 struct elf64_x86_64_dyn_relocs
408 struct elf64_x86_64_dyn_relocs *next;
410 /* The input section of the reloc. */
413 /* Total number of relocs copied for the input section. */
416 /* Number of pc-relative relocs copied for the input section. */
417 bfd_size_type pc_count;
420 /* x86-64 ELF linker hash entry. */
422 struct elf64_x86_64_link_hash_entry
424 struct elf_link_hash_entry elf;
426 /* Track dynamic relocs copied for this symbol. */
427 struct elf64_x86_64_dyn_relocs *dyn_relocs;
429 #define GOT_UNKNOWN 0
433 #define GOT_TLS_GDESC 4
434 #define GOT_TLS_GD_BOTH_P(type) \
435 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
436 #define GOT_TLS_GD_P(type) \
437 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
438 #define GOT_TLS_GDESC_P(type) \
439 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
440 #define GOT_TLS_GD_ANY_P(type) \
441 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
442 unsigned char tls_type;
444 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
445 starting at the end of the jump table. */
449 #define elf64_x86_64_hash_entry(ent) \
450 ((struct elf64_x86_64_link_hash_entry *)(ent))
452 struct elf64_x86_64_obj_tdata
454 struct elf_obj_tdata root;
456 /* tls_type for each local got entry. */
457 char *local_got_tls_type;
459 /* GOTPLT entries for TLS descriptors. */
460 bfd_vma *local_tlsdesc_gotent;
463 #define elf64_x86_64_tdata(abfd) \
464 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
466 #define elf64_x86_64_local_got_tls_type(abfd) \
467 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
469 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
470 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
472 #define is_x86_64_elf(bfd) \
473 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
474 && elf_tdata (bfd) != NULL \
475 && elf_object_id (bfd) == X86_64_ELF_TDATA)
478 elf64_x86_64_mkobject (bfd *abfd)
480 return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata),
484 /* x86-64 ELF linker hash table. */
486 struct elf64_x86_64_link_hash_table
488 struct elf_link_hash_table elf;
490 /* Short-cuts to get to dynamic linker sections. */
494 /* The offset into splt of the PLT entry for the TLS descriptor
495 resolver. Special values are 0, if not necessary (or not found
496 to be necessary yet), and -1 if needed but not determined
499 /* The offset into sgot of the GOT entry used by the PLT entry
504 bfd_signed_vma refcount;
508 /* The amount of space used by the jump slots in the GOT. */
509 bfd_vma sgotplt_jump_table_size;
511 /* Small local sym to section mapping cache. */
512 struct sym_sec_cache sym_sec;
514 /* _TLS_MODULE_BASE_ symbol. */
515 struct bfd_link_hash_entry *tls_module_base;
517 /* Used by local STT_GNU_IFUNC symbols. */
518 htab_t loc_hash_table;
519 void *loc_hash_memory;
522 /* Get the x86-64 ELF linker hash table from a link_info structure. */
524 #define elf64_x86_64_hash_table(p) \
525 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
527 #define elf64_x86_64_compute_jump_table_size(htab) \
528 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
530 /* Create an entry in an x86-64 ELF linker hash table. */
532 static struct bfd_hash_entry *
533 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
534 struct bfd_hash_table *table,
537 /* Allocate the structure if it has not already been allocated by a
541 entry = bfd_hash_allocate (table,
542 sizeof (struct elf64_x86_64_link_hash_entry));
547 /* Call the allocation method of the superclass. */
548 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
551 struct elf64_x86_64_link_hash_entry *eh;
553 eh = (struct elf64_x86_64_link_hash_entry *) entry;
554 eh->dyn_relocs = NULL;
555 eh->tls_type = GOT_UNKNOWN;
556 eh->tlsdesc_got = (bfd_vma) -1;
562 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
563 for local symbol so that we can handle local STT_GNU_IFUNC symbols
564 as global symbol. We reuse indx and dynstr_index for local symbol
565 hash since they aren't used by global symbols in this backend. */
568 elf64_x86_64_local_htab_hash (const void *ptr)
570 struct elf_link_hash_entry *h
571 = (struct elf_link_hash_entry *) ptr;
572 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
575 /* Compare local hash entries. */
578 elf64_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
580 struct elf_link_hash_entry *h1
581 = (struct elf_link_hash_entry *) ptr1;
582 struct elf_link_hash_entry *h2
583 = (struct elf_link_hash_entry *) ptr2;
585 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
588 /* Find and/or create a hash entry for local symbol. */
590 static struct elf_link_hash_entry *
591 elf64_x86_64_get_local_sym_hash (struct elf64_x86_64_link_hash_table *htab,
592 bfd *abfd, const Elf_Internal_Rela *rel,
595 struct elf64_x86_64_link_hash_entry e, *ret;
596 asection *sec = abfd->sections;
597 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
598 ELF64_R_SYM (rel->r_info));
601 e.elf.indx = sec->id;
602 e.elf.dynstr_index = ELF64_R_SYM (rel->r_info);
603 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
604 create ? INSERT : NO_INSERT);
611 ret = (struct elf64_x86_64_link_hash_entry *) *slot;
615 ret = (struct elf64_x86_64_link_hash_entry *)
616 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
617 sizeof (struct elf64_x86_64_link_hash_entry));
620 memset (ret, 0, sizeof (*ret));
621 ret->elf.indx = sec->id;
622 ret->elf.dynstr_index = ELF64_R_SYM (rel->r_info);
623 ret->elf.dynindx = -1;
624 ret->elf.plt.offset = (bfd_vma) -1;
625 ret->elf.got.offset = (bfd_vma) -1;
631 /* Create an X86-64 ELF linker hash table. */
633 static struct bfd_link_hash_table *
634 elf64_x86_64_link_hash_table_create (bfd *abfd)
636 struct elf64_x86_64_link_hash_table *ret;
637 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
639 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
643 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
644 elf64_x86_64_link_hash_newfunc,
645 sizeof (struct elf64_x86_64_link_hash_entry)))
653 ret->sym_sec.abfd = NULL;
654 ret->tlsdesc_plt = 0;
655 ret->tlsdesc_got = 0;
656 ret->tls_ld_got.refcount = 0;
657 ret->sgotplt_jump_table_size = 0;
658 ret->tls_module_base = NULL;
660 ret->loc_hash_table = htab_try_create (1024,
661 elf64_x86_64_local_htab_hash,
662 elf64_x86_64_local_htab_eq,
664 ret->loc_hash_memory = objalloc_create ();
665 if (!ret->loc_hash_table || !ret->loc_hash_memory)
671 return &ret->elf.root;
674 /* Destroy an X86-64 ELF linker hash table. */
677 elf64_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
679 struct elf64_x86_64_link_hash_table *htab
680 = (struct elf64_x86_64_link_hash_table *) hash;
682 if (htab->loc_hash_table)
683 htab_delete (htab->loc_hash_table);
684 if (htab->loc_hash_memory)
685 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
686 _bfd_generic_link_hash_table_free (hash);
689 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
690 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
694 elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
696 struct elf64_x86_64_link_hash_table *htab;
698 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
701 htab = elf64_x86_64_hash_table (info);
702 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
704 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
707 || (!info->shared && !htab->srelbss))
713 /* Copy the extra info we tack onto an elf_link_hash_entry. */
716 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
717 struct elf_link_hash_entry *dir,
718 struct elf_link_hash_entry *ind)
720 struct elf64_x86_64_link_hash_entry *edir, *eind;
722 edir = (struct elf64_x86_64_link_hash_entry *) dir;
723 eind = (struct elf64_x86_64_link_hash_entry *) ind;
725 if (eind->dyn_relocs != NULL)
727 if (edir->dyn_relocs != NULL)
729 struct elf64_x86_64_dyn_relocs **pp;
730 struct elf64_x86_64_dyn_relocs *p;
732 /* Add reloc counts against the indirect sym to the direct sym
733 list. Merge any entries against the same section. */
734 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
736 struct elf64_x86_64_dyn_relocs *q;
738 for (q = edir->dyn_relocs; q != NULL; q = q->next)
739 if (q->sec == p->sec)
741 q->pc_count += p->pc_count;
742 q->count += p->count;
749 *pp = edir->dyn_relocs;
752 edir->dyn_relocs = eind->dyn_relocs;
753 eind->dyn_relocs = NULL;
756 if (ind->root.type == bfd_link_hash_indirect
757 && dir->got.refcount <= 0)
759 edir->tls_type = eind->tls_type;
760 eind->tls_type = GOT_UNKNOWN;
763 if (ELIMINATE_COPY_RELOCS
764 && ind->root.type != bfd_link_hash_indirect
765 && dir->dynamic_adjusted)
767 /* If called to transfer flags for a weakdef during processing
768 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
769 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
770 dir->ref_dynamic |= ind->ref_dynamic;
771 dir->ref_regular |= ind->ref_regular;
772 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
773 dir->needs_plt |= ind->needs_plt;
774 dir->pointer_equality_needed |= ind->pointer_equality_needed;
777 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
781 elf64_x86_64_elf_object_p (bfd *abfd)
783 /* Set the right machine number for an x86-64 elf64 file. */
784 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
802 /* Return TRUE if the TLS access code sequence support transition
806 elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec,
808 Elf_Internal_Shdr *symtab_hdr,
809 struct elf_link_hash_entry **sym_hashes,
811 const Elf_Internal_Rela *rel,
812 const Elf_Internal_Rela *relend)
815 unsigned long r_symndx;
816 struct elf_link_hash_entry *h;
819 /* Get the section contents. */
820 if (contents == NULL)
822 if (elf_section_data (sec)->this_hdr.contents != NULL)
823 contents = elf_section_data (sec)->this_hdr.contents;
826 /* FIXME: How to better handle error condition? */
827 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
830 /* Cache the section contents for elf_link_input_bfd. */
831 elf_section_data (sec)->this_hdr.contents = contents;
835 offset = rel->r_offset;
840 if ((rel + 1) >= relend)
843 if (r_type == R_X86_64_TLSGD)
845 /* Check transition from GD access model. Only
846 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
847 .word 0x6666; rex64; call __tls_get_addr
848 can transit to different access model. */
850 static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } },
851 call = { { 0x66, 0x66, 0x48, 0xe8 } };
853 || (offset + 12) > sec->size
854 || bfd_get_32 (abfd, contents + offset - 4) != leaq.i
855 || bfd_get_32 (abfd, contents + offset + 4) != call.i)
860 /* Check transition from LD access model. Only
861 leaq foo@tlsld(%rip), %rdi;
863 can transit to different access model. */
865 static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
868 if (offset < 3 || (offset + 9) > sec->size)
871 op.i = bfd_get_32 (abfd, contents + offset - 3);
872 op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
877 r_symndx = ELF64_R_SYM (rel[1].r_info);
878 if (r_symndx < symtab_hdr->sh_info)
881 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
882 /* Use strncmp to check __tls_get_addr since __tls_get_addr
885 && h->root.root.string != NULL
886 && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32
887 || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
888 && (strncmp (h->root.root.string,
889 "__tls_get_addr", 14) == 0));
891 case R_X86_64_GOTTPOFF:
892 /* Check transition from IE access model:
893 movq foo@gottpoff(%rip), %reg
894 addq foo@gottpoff(%rip), %reg
897 if (offset < 3 || (offset + 4) > sec->size)
900 val = bfd_get_8 (abfd, contents + offset - 3);
901 if (val != 0x48 && val != 0x4c)
904 val = bfd_get_8 (abfd, contents + offset - 2);
905 if (val != 0x8b && val != 0x03)
908 val = bfd_get_8 (abfd, contents + offset - 1);
909 return (val & 0xc7) == 5;
911 case R_X86_64_GOTPC32_TLSDESC:
912 /* Check transition from GDesc access model:
913 leaq x@tlsdesc(%rip), %rax
915 Make sure it's a leaq adding rip to a 32-bit offset
916 into any register, although it's probably almost always
919 if (offset < 3 || (offset + 4) > sec->size)
922 val = bfd_get_8 (abfd, contents + offset - 3);
923 if ((val & 0xfb) != 0x48)
926 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
929 val = bfd_get_8 (abfd, contents + offset - 1);
930 return (val & 0xc7) == 0x05;
932 case R_X86_64_TLSDESC_CALL:
933 /* Check transition from GDesc access model:
934 call *x@tlsdesc(%rax)
936 if (offset + 2 <= sec->size)
938 /* Make sure that it's a call *x@tlsdesc(%rax). */
939 static x86_64_opcode16 call = { { 0xff, 0x10 } };
940 return bfd_get_16 (abfd, contents + offset) == call.i;
950 /* Return TRUE if the TLS access transition is OK or no transition
951 will be performed. Update R_TYPE if there is a transition. */
954 elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
955 asection *sec, bfd_byte *contents,
956 Elf_Internal_Shdr *symtab_hdr,
957 struct elf_link_hash_entry **sym_hashes,
958 unsigned int *r_type, int tls_type,
959 const Elf_Internal_Rela *rel,
960 const Elf_Internal_Rela *relend,
961 struct elf_link_hash_entry *h)
963 unsigned int from_type = *r_type;
964 unsigned int to_type = from_type;
965 bfd_boolean check = TRUE;
970 case R_X86_64_GOTPC32_TLSDESC:
971 case R_X86_64_TLSDESC_CALL:
972 case R_X86_64_GOTTPOFF:
976 to_type = R_X86_64_TPOFF32;
978 to_type = R_X86_64_GOTTPOFF;
981 /* When we are called from elf64_x86_64_relocate_section,
982 CONTENTS isn't NULL and there may be additional transitions
983 based on TLS_TYPE. */
984 if (contents != NULL)
986 unsigned int new_to_type = to_type;
991 && tls_type == GOT_TLS_IE)
992 new_to_type = R_X86_64_TPOFF32;
994 if (to_type == R_X86_64_TLSGD
995 || to_type == R_X86_64_GOTPC32_TLSDESC
996 || to_type == R_X86_64_TLSDESC_CALL)
998 if (tls_type == GOT_TLS_IE)
999 new_to_type = R_X86_64_GOTTPOFF;
1002 /* We checked the transition before when we were called from
1003 elf64_x86_64_check_relocs. We only want to check the new
1004 transition which hasn't been checked before. */
1005 check = new_to_type != to_type && from_type == to_type;
1006 to_type = new_to_type;
1011 case R_X86_64_TLSLD:
1013 to_type = R_X86_64_TPOFF32;
1020 /* Return TRUE if there is no transition. */
1021 if (from_type == to_type)
1024 /* Check if the transition can be performed. */
1026 && ! elf64_x86_64_check_tls_transition (abfd, sec, contents,
1027 symtab_hdr, sym_hashes,
1028 from_type, rel, relend))
1030 reloc_howto_type *from, *to;
1032 from = elf64_x86_64_rtype_to_howto (abfd, from_type);
1033 to = elf64_x86_64_rtype_to_howto (abfd, to_type);
1035 (*_bfd_error_handler)
1036 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1037 "in section `%A' failed"),
1038 abfd, sec, from->name, to->name,
1039 h ? h->root.root.string : "a local symbol",
1040 (unsigned long) rel->r_offset);
1041 bfd_set_error (bfd_error_bad_value);
1049 /* Look through the relocs for a section during the first phase, and
1050 calculate needed space in the global offset table, procedure
1051 linkage table, and dynamic reloc sections. */
1054 elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1056 const Elf_Internal_Rela *relocs)
1058 struct elf64_x86_64_link_hash_table *htab;
1059 Elf_Internal_Shdr *symtab_hdr;
1060 struct elf_link_hash_entry **sym_hashes;
1061 const Elf_Internal_Rela *rel;
1062 const Elf_Internal_Rela *rel_end;
1064 Elf_Internal_Sym *isymbuf;
1066 if (info->relocatable)
1069 BFD_ASSERT (is_x86_64_elf (abfd));
1071 htab = elf64_x86_64_hash_table (info);
1072 symtab_hdr = &elf_symtab_hdr (abfd);
1073 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1074 sym_hashes = elf_sym_hashes (abfd);
1078 rel_end = relocs + sec->reloc_count;
1079 for (rel = relocs; rel < rel_end; rel++)
1081 unsigned int r_type;
1082 unsigned long r_symndx;
1083 struct elf_link_hash_entry *h;
1085 r_symndx = ELF64_R_SYM (rel->r_info);
1086 r_type = ELF64_R_TYPE (rel->r_info);
1088 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1090 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1095 if (r_symndx < symtab_hdr->sh_info)
1097 /* A local symbol. */
1098 Elf_Internal_Sym *isym;
1100 /* Read this BFD's local symbols. */
1101 if (isymbuf == NULL)
1103 if (isymbuf == NULL)
1104 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
1105 symtab_hdr->sh_info, 0,
1107 if (isymbuf == NULL)
1111 /* Check relocation against local STT_GNU_IFUNC symbol. */
1112 isym = isymbuf + r_symndx;
1113 if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1115 h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel,
1120 /* Fake a STT_GNU_IFUNC symbol. */
1121 h->type = STT_GNU_IFUNC;
1124 h->forced_local = 1;
1125 h->root.type = bfd_link_hash_defined;
1132 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1133 while (h->root.type == bfd_link_hash_indirect
1134 || h->root.type == bfd_link_hash_warning)
1135 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1140 /* Create the ifunc sections for static executables. If we
1141 never see an indirect function symbol nor we are building
1142 a static executable, those sections will be empty and
1143 won't appear in output. */
1154 case R_X86_64_PLT32:
1155 case R_X86_64_GOTPCREL:
1156 case R_X86_64_GOTPCREL64:
1157 if (!_bfd_elf_create_ifunc_sections (abfd, info))
1162 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1163 it here if it is defined in a non-shared object. */
1164 if (h->type == STT_GNU_IFUNC
1167 /* It is referenced by a non-shared object. */
1170 /* STT_GNU_IFUNC symbol must go through PLT. */
1171 h->plt.refcount += 1;
1173 /* STT_GNU_IFUNC needs dynamic sections. */
1174 if (htab->elf.dynobj == NULL)
1175 htab->elf.dynobj = abfd;
1180 (*_bfd_error_handler)
1181 (_("%B: relocation %s against STT_GNU_IFUNC "
1182 "symbol `%s' isn't handled by %s"), abfd,
1183 x86_64_elf_howto_table[r_type].name,
1184 (h->root.root.string
1185 ? h->root.root.string : "a local symbol"),
1187 bfd_set_error (bfd_error_bad_value);
1192 h->pointer_equality_needed = 1;
1195 struct elf64_x86_64_dyn_relocs *p;
1196 struct elf64_x86_64_dyn_relocs **head;
1198 /* We must copy these reloc types into the output
1199 file. Create a reloc section in dynobj and
1200 make room for this reloc. */
1203 if (htab->elf.dynobj == NULL)
1204 htab->elf.dynobj = abfd;
1206 sreloc = _bfd_elf_make_dynamic_reloc_section
1207 (sec, htab->elf.dynobj, 3, abfd, TRUE);
1213 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
1215 if (p == NULL || p->sec != sec)
1217 bfd_size_type amt = sizeof *p;
1219 p = ((struct elf64_x86_64_dyn_relocs *)
1220 bfd_alloc (htab->elf.dynobj, amt));
1238 if (r_type != R_X86_64_PC32
1239 && r_type != R_X86_64_PC64)
1240 h->pointer_equality_needed = 1;
1243 case R_X86_64_PLT32:
1246 case R_X86_64_GOTPCREL:
1247 case R_X86_64_GOTPCREL64:
1248 h->got.refcount += 1;
1249 if (htab->elf.sgot == NULL
1250 && !_bfd_elf_create_got_section (htab->elf.dynobj,
1260 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1261 symtab_hdr, sym_hashes,
1262 &r_type, GOT_UNKNOWN,
1268 case R_X86_64_TLSLD:
1269 htab->tls_ld_got.refcount += 1;
1272 case R_X86_64_TPOFF32:
1275 (*_bfd_error_handler)
1276 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1278 x86_64_elf_howto_table[r_type].name,
1279 (h) ? h->root.root.string : "a local symbol");
1280 bfd_set_error (bfd_error_bad_value);
1285 case R_X86_64_GOTTPOFF:
1287 info->flags |= DF_STATIC_TLS;
1290 case R_X86_64_GOT32:
1291 case R_X86_64_GOTPCREL:
1292 case R_X86_64_TLSGD:
1293 case R_X86_64_GOT64:
1294 case R_X86_64_GOTPCREL64:
1295 case R_X86_64_GOTPLT64:
1296 case R_X86_64_GOTPC32_TLSDESC:
1297 case R_X86_64_TLSDESC_CALL:
1298 /* This symbol requires a global offset table entry. */
1300 int tls_type, old_tls_type;
1304 default: tls_type = GOT_NORMAL; break;
1305 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1306 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1307 case R_X86_64_GOTPC32_TLSDESC:
1308 case R_X86_64_TLSDESC_CALL:
1309 tls_type = GOT_TLS_GDESC; break;
1314 if (r_type == R_X86_64_GOTPLT64)
1316 /* This relocation indicates that we also need
1317 a PLT entry, as this is a function. We don't need
1318 a PLT entry for local symbols. */
1320 h->plt.refcount += 1;
1322 h->got.refcount += 1;
1323 old_tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1327 bfd_signed_vma *local_got_refcounts;
1329 /* This is a global offset table entry for a local symbol. */
1330 local_got_refcounts = elf_local_got_refcounts (abfd);
1331 if (local_got_refcounts == NULL)
1335 size = symtab_hdr->sh_info;
1336 size *= sizeof (bfd_signed_vma)
1337 + sizeof (bfd_vma) + sizeof (char);
1338 local_got_refcounts = ((bfd_signed_vma *)
1339 bfd_zalloc (abfd, size));
1340 if (local_got_refcounts == NULL)
1342 elf_local_got_refcounts (abfd) = local_got_refcounts;
1343 elf64_x86_64_local_tlsdesc_gotent (abfd)
1344 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1345 elf64_x86_64_local_got_tls_type (abfd)
1346 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1348 local_got_refcounts[r_symndx] += 1;
1350 = elf64_x86_64_local_got_tls_type (abfd) [r_symndx];
1353 /* If a TLS symbol is accessed using IE at least once,
1354 there is no point to use dynamic model for it. */
1355 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1356 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1357 || tls_type != GOT_TLS_IE))
1359 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1360 tls_type = old_tls_type;
1361 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1362 && GOT_TLS_GD_ANY_P (tls_type))
1363 tls_type |= old_tls_type;
1366 (*_bfd_error_handler)
1367 (_("%B: '%s' accessed both as normal and thread local symbol"),
1368 abfd, h ? h->root.root.string : "<local>");
1373 if (old_tls_type != tls_type)
1376 elf64_x86_64_hash_entry (h)->tls_type = tls_type;
1378 elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1383 case R_X86_64_GOTOFF64:
1384 case R_X86_64_GOTPC32:
1385 case R_X86_64_GOTPC64:
1387 if (htab->elf.sgot == NULL)
1389 if (htab->elf.dynobj == NULL)
1390 htab->elf.dynobj = abfd;
1391 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
1397 case R_X86_64_PLT32:
1398 /* This symbol requires a procedure linkage table entry. We
1399 actually build the entry in adjust_dynamic_symbol,
1400 because this might be a case of linking PIC code which is
1401 never referenced by a dynamic object, in which case we
1402 don't need to generate a procedure linkage table entry
1405 /* If this is a local symbol, we resolve it directly without
1406 creating a procedure linkage table entry. */
1411 h->plt.refcount += 1;
1414 case R_X86_64_PLTOFF64:
1415 /* This tries to form the 'address' of a function relative
1416 to GOT. For global symbols we need a PLT entry. */
1420 h->plt.refcount += 1;
1428 /* Let's help debug shared library creation. These relocs
1429 cannot be used in shared libs. Don't error out for
1430 sections we don't care about, such as debug sections or
1431 non-constant sections. */
1433 && (sec->flags & SEC_ALLOC) != 0
1434 && (sec->flags & SEC_READONLY) != 0)
1436 (*_bfd_error_handler)
1437 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1439 x86_64_elf_howto_table[r_type].name,
1440 (h) ? h->root.root.string : "a local symbol");
1441 bfd_set_error (bfd_error_bad_value);
1451 if (h != NULL && info->executable)
1453 /* If this reloc is in a read-only section, we might
1454 need a copy reloc. We can't check reliably at this
1455 stage whether the section is read-only, as input
1456 sections have not yet been mapped to output sections.
1457 Tentatively set the flag for now, and correct in
1458 adjust_dynamic_symbol. */
1461 /* We may need a .plt entry if the function this reloc
1462 refers to is in a shared lib. */
1463 h->plt.refcount += 1;
1464 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1465 h->pointer_equality_needed = 1;
1468 /* If we are creating a shared library, and this is a reloc
1469 against a global symbol, or a non PC relative reloc
1470 against a local symbol, then we need to copy the reloc
1471 into the shared library. However, if we are linking with
1472 -Bsymbolic, we do not need to copy a reloc against a
1473 global symbol which is defined in an object we are
1474 including in the link (i.e., DEF_REGULAR is set). At
1475 this point we have not seen all the input files, so it is
1476 possible that DEF_REGULAR is not set now but will be set
1477 later (it is never cleared). In case of a weak definition,
1478 DEF_REGULAR may be cleared later by a strong definition in
1479 a shared library. We account for that possibility below by
1480 storing information in the relocs_copied field of the hash
1481 table entry. A similar situation occurs when creating
1482 shared libraries and symbol visibility changes render the
1485 If on the other hand, we are creating an executable, we
1486 may need to keep relocations for symbols satisfied by a
1487 dynamic library if we manage to avoid copy relocs for the
1490 && (sec->flags & SEC_ALLOC) != 0
1491 && (! IS_X86_64_PCREL_TYPE (r_type)
1493 && (! SYMBOLIC_BIND (info, h)
1494 || h->root.type == bfd_link_hash_defweak
1495 || !h->def_regular))))
1496 || (ELIMINATE_COPY_RELOCS
1498 && (sec->flags & SEC_ALLOC) != 0
1500 && (h->root.type == bfd_link_hash_defweak
1501 || !h->def_regular)))
1503 struct elf64_x86_64_dyn_relocs *p;
1504 struct elf64_x86_64_dyn_relocs **head;
1506 /* We must copy these reloc types into the output file.
1507 Create a reloc section in dynobj and make room for
1511 if (htab->elf.dynobj == NULL)
1512 htab->elf.dynobj = abfd;
1514 sreloc = _bfd_elf_make_dynamic_reloc_section
1515 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
1521 /* If this is a global symbol, we count the number of
1522 relocations we need for this symbol. */
1525 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
1530 /* Track dynamic relocs needed for local syms too.
1531 We really need local syms available to do this
1535 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
1540 /* Beware of type punned pointers vs strict aliasing
1542 vpp = &(elf_section_data (s)->local_dynrel);
1543 head = (struct elf64_x86_64_dyn_relocs **)vpp;
1547 if (p == NULL || p->sec != sec)
1549 bfd_size_type amt = sizeof *p;
1551 p = ((struct elf64_x86_64_dyn_relocs *)
1552 bfd_alloc (htab->elf.dynobj, amt));
1563 if (IS_X86_64_PCREL_TYPE (r_type))
1568 /* This relocation describes the C++ object vtable hierarchy.
1569 Reconstruct it for later use during GC. */
1570 case R_X86_64_GNU_VTINHERIT:
1571 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1575 /* This relocation describes which C++ vtable entries are actually
1576 used. Record for later use during GC. */
1577 case R_X86_64_GNU_VTENTRY:
1578 BFD_ASSERT (h != NULL);
1580 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1592 /* Return the section that should be marked against GC for a given
1596 elf64_x86_64_gc_mark_hook (asection *sec,
1597 struct bfd_link_info *info,
1598 Elf_Internal_Rela *rel,
1599 struct elf_link_hash_entry *h,
1600 Elf_Internal_Sym *sym)
1603 switch (ELF64_R_TYPE (rel->r_info))
1605 case R_X86_64_GNU_VTINHERIT:
1606 case R_X86_64_GNU_VTENTRY:
1610 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1613 /* Update the got entry reference counts for the section being removed. */
1616 elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1618 const Elf_Internal_Rela *relocs)
1620 Elf_Internal_Shdr *symtab_hdr;
1621 struct elf_link_hash_entry **sym_hashes;
1622 bfd_signed_vma *local_got_refcounts;
1623 const Elf_Internal_Rela *rel, *relend;
1625 if (info->relocatable)
1628 elf_section_data (sec)->local_dynrel = NULL;
1630 symtab_hdr = &elf_symtab_hdr (abfd);
1631 sym_hashes = elf_sym_hashes (abfd);
1632 local_got_refcounts = elf_local_got_refcounts (abfd);
1634 relend = relocs + sec->reloc_count;
1635 for (rel = relocs; rel < relend; rel++)
1637 unsigned long r_symndx;
1638 unsigned int r_type;
1639 struct elf_link_hash_entry *h = NULL;
1641 r_symndx = ELF64_R_SYM (rel->r_info);
1642 if (r_symndx >= symtab_hdr->sh_info)
1644 struct elf64_x86_64_link_hash_entry *eh;
1645 struct elf64_x86_64_dyn_relocs **pp;
1646 struct elf64_x86_64_dyn_relocs *p;
1648 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1649 while (h->root.type == bfd_link_hash_indirect
1650 || h->root.type == bfd_link_hash_warning)
1651 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1652 eh = (struct elf64_x86_64_link_hash_entry *) h;
1654 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1657 /* Everything must go for SEC. */
1663 r_type = ELF64_R_TYPE (rel->r_info);
1664 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1665 symtab_hdr, sym_hashes,
1666 &r_type, GOT_UNKNOWN,
1672 case R_X86_64_TLSLD:
1673 if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0)
1674 elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1;
1677 case R_X86_64_TLSGD:
1678 case R_X86_64_GOTPC32_TLSDESC:
1679 case R_X86_64_TLSDESC_CALL:
1680 case R_X86_64_GOTTPOFF:
1681 case R_X86_64_GOT32:
1682 case R_X86_64_GOTPCREL:
1683 case R_X86_64_GOT64:
1684 case R_X86_64_GOTPCREL64:
1685 case R_X86_64_GOTPLT64:
1688 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
1689 h->plt.refcount -= 1;
1690 if (h->got.refcount > 0)
1691 h->got.refcount -= 1;
1693 else if (local_got_refcounts != NULL)
1695 if (local_got_refcounts[r_symndx] > 0)
1696 local_got_refcounts[r_symndx] -= 1;
1713 case R_X86_64_PLT32:
1714 case R_X86_64_PLTOFF64:
1717 if (h->plt.refcount > 0)
1718 h->plt.refcount -= 1;
1730 /* Adjust a symbol defined by a dynamic object and referenced by a
1731 regular object. The current definition is in some section of the
1732 dynamic object, but we're not including those sections. We have to
1733 change the definition to something the rest of the link can
1737 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
1738 struct elf_link_hash_entry *h)
1740 struct elf64_x86_64_link_hash_table *htab;
1743 /* STT_GNU_IFUNC symbol must go through PLT. */
1744 if (h->type == STT_GNU_IFUNC)
1746 if (h->plt.refcount <= 0)
1748 h->plt.offset = (bfd_vma) -1;
1754 /* If this is a function, put it in the procedure linkage table. We
1755 will fill in the contents of the procedure linkage table later,
1756 when we know the address of the .got section. */
1757 if (h->type == STT_FUNC
1760 if (h->plt.refcount <= 0
1761 || SYMBOL_CALLS_LOCAL (info, h)
1762 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1763 && h->root.type == bfd_link_hash_undefweak))
1765 /* This case can occur if we saw a PLT32 reloc in an input
1766 file, but the symbol was never referred to by a dynamic
1767 object, or if all references were garbage collected. In
1768 such a case, we don't actually need to build a procedure
1769 linkage table, and we can just do a PC32 reloc instead. */
1770 h->plt.offset = (bfd_vma) -1;
1777 /* It's possible that we incorrectly decided a .plt reloc was
1778 needed for an R_X86_64_PC32 reloc to a non-function sym in
1779 check_relocs. We can't decide accurately between function and
1780 non-function syms in check-relocs; Objects loaded later in
1781 the link may change h->type. So fix it now. */
1782 h->plt.offset = (bfd_vma) -1;
1784 /* If this is a weak symbol, and there is a real definition, the
1785 processor independent code will have arranged for us to see the
1786 real definition first, and we can just use the same value. */
1787 if (h->u.weakdef != NULL)
1789 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1790 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1791 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1792 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1793 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1794 h->non_got_ref = h->u.weakdef->non_got_ref;
1798 /* This is a reference to a symbol defined by a dynamic object which
1799 is not a function. */
1801 /* If we are creating a shared library, we must presume that the
1802 only references to the symbol are via the global offset table.
1803 For such cases we need not do anything here; the relocations will
1804 be handled correctly by relocate_section. */
1808 /* If there are no references to this symbol that do not use the
1809 GOT, we don't need to generate a copy reloc. */
1810 if (!h->non_got_ref)
1813 /* If -z nocopyreloc was given, we won't generate them either. */
1814 if (info->nocopyreloc)
1820 if (ELIMINATE_COPY_RELOCS)
1822 struct elf64_x86_64_link_hash_entry * eh;
1823 struct elf64_x86_64_dyn_relocs *p;
1825 eh = (struct elf64_x86_64_link_hash_entry *) h;
1826 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1828 s = p->sec->output_section;
1829 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1833 /* If we didn't find any dynamic relocs in read-only sections, then
1834 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1844 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1845 h->root.root.string);
1849 /* We must allocate the symbol in our .dynbss section, which will
1850 become part of the .bss section of the executable. There will be
1851 an entry for this symbol in the .dynsym section. The dynamic
1852 object will contain position independent code, so all references
1853 from the dynamic object to this symbol will go through the global
1854 offset table. The dynamic linker will use the .dynsym entry to
1855 determine the address it must put in the global offset table, so
1856 both the dynamic object and the regular object will refer to the
1857 same memory location for the variable. */
1859 htab = elf64_x86_64_hash_table (info);
1861 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1862 to copy the initial value out of the dynamic object and into the
1863 runtime process image. */
1864 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1866 htab->srelbss->size += sizeof (Elf64_External_Rela);
1872 return _bfd_elf_adjust_dynamic_copy (h, s);
1875 /* Allocate space in .plt, .got and associated reloc sections for
1879 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1881 struct bfd_link_info *info;
1882 struct elf64_x86_64_link_hash_table *htab;
1883 struct elf64_x86_64_link_hash_entry *eh;
1884 struct elf64_x86_64_dyn_relocs *p;
1886 if (h->root.type == bfd_link_hash_indirect)
1889 if (h->root.type == bfd_link_hash_warning)
1890 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1891 eh = (struct elf64_x86_64_link_hash_entry *) h;
1893 info = (struct bfd_link_info *) inf;
1894 htab = elf64_x86_64_hash_table (info);
1896 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1897 here if it is defined and referenced in a non-shared object. */
1898 if (h->type == STT_GNU_IFUNC
1901 asection *plt, *gotplt, *relplt;
1903 /* When a shared library references a STT_GNU_IFUNC symbol
1904 defined in executable, the address of the resolved function
1905 may be used. But in non-shared executable, the address of
1906 its .plt slot may be used. Pointer equality may not work
1907 correctly. PIE should be used if pointer equality is
1910 && (h->dynindx != -1
1911 || info->export_dynamic)
1912 && h->pointer_equality_needed)
1914 info->callbacks->einfo
1915 (_("%F%P: dynamic STT_GNU_IFUNC symbol `%s' with pointer "
1916 "equality in `%B' can not be used when making an "
1917 "executable; recompile with -fPIE and relink with -pie\n"),
1918 h->root.root.string,
1919 h->root.u.def.section->owner);
1920 bfd_set_error (bfd_error_bad_value);
1924 /* Return and discard space for dynamic relocations against it if
1925 it is never referenced in a non-shared object. */
1926 if (!h->ref_regular)
1928 if (h->plt.refcount > 0
1929 || h->got.refcount > 0)
1931 h->got.offset = (bfd_vma) -1;
1932 eh->dyn_relocs = NULL;
1936 /* When building a static executable, use .iplt, .igot.plt and
1937 .rela.iplt sections for STT_GNU_IFUNC symbols. */
1938 if (htab->elf.splt != NULL)
1940 plt = htab->elf.splt;
1941 gotplt = htab->elf.sgotplt;
1942 relplt = htab->elf.srelplt;
1944 /* If this is the first .plt entry, make room for the special
1947 plt->size += PLT_ENTRY_SIZE;
1951 plt = htab->elf.iplt;
1952 gotplt = htab->elf.igotplt;
1953 relplt = htab->elf.irelplt;
1956 /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
1957 the original value for R_X86_64_IRELATIVE. */
1958 h->plt.offset = plt->size;
1960 /* Make room for this entry in the .plt/.iplt section. */
1961 plt->size += PLT_ENTRY_SIZE;
1963 /* We also need to make an entry in the .got.plt/.got.iplt
1964 section, which will be placed in the .got section by the
1966 gotplt->size += GOT_ENTRY_SIZE;
1968 /* We also need to make an entry in the .rela.plt/.rela.iplt
1970 relplt->size += sizeof (Elf64_External_Rela);
1971 relplt->reloc_count++;
1973 /* We need dynamic relocation for STT_GNU_IFUNC symbol only
1974 when there is a non-GOT reference in a shared object. */
1977 eh->dyn_relocs = NULL;
1979 /* Finally, allocate space. */
1980 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1981 htab->elf.irelifunc->size
1982 += p->count * sizeof (Elf64_External_Rela);
1984 /* For STT_GNU_IFUNC symbol, .got.plt has the real function
1985 addres and .got has the PLT entry adddress. We will load
1986 the GOT entry with the PLT entry in finish_dynamic_symbol if
1987 it is used. For branch, it uses .got.plt. For symbol value,
1988 1. Use .got.plt in a shared object if it is forced local or
1990 2. Use .got.plt in a non-shared object if pointer equality
1992 3. Use .got.plt in PIE.
1993 4. Use .got.plt if .got isn't used.
1994 5. Otherwise use .got so that it can be shared among different
1995 objects at run-time.
1996 We only need to relocate .got entry in shared object. */
1998 && (h->dynindx == -1
1999 || h->forced_local))
2001 && !h->pointer_equality_needed)
2002 || (info->executable && info->shared)
2003 || htab->elf.sgot == NULL)
2006 h->got.offset = (bfd_vma) -1;
2010 h->got.offset = htab->elf.sgot->size;
2011 htab->elf.sgot->size += GOT_ENTRY_SIZE;
2013 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2018 else if (htab->elf.dynamic_sections_created
2019 && h->plt.refcount > 0)
2021 /* Make sure this symbol is output as a dynamic symbol.
2022 Undefined weak syms won't yet be marked as dynamic. */
2023 if (h->dynindx == -1
2024 && !h->forced_local)
2026 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2031 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2033 asection *s = htab->elf.splt;
2035 /* If this is the first .plt entry, make room for the special
2038 s->size += PLT_ENTRY_SIZE;
2040 h->plt.offset = s->size;
2042 /* If this symbol is not defined in a regular file, and we are
2043 not generating a shared library, then set the symbol to this
2044 location in the .plt. This is required to make function
2045 pointers compare as equal between the normal executable and
2046 the shared library. */
2050 h->root.u.def.section = s;
2051 h->root.u.def.value = h->plt.offset;
2054 /* Make room for this entry. */
2055 s->size += PLT_ENTRY_SIZE;
2057 /* We also need to make an entry in the .got.plt section, which
2058 will be placed in the .got section by the linker script. */
2059 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
2061 /* We also need to make an entry in the .rela.plt section. */
2062 htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
2063 htab->elf.srelplt->reloc_count++;
2067 h->plt.offset = (bfd_vma) -1;
2073 h->plt.offset = (bfd_vma) -1;
2077 eh->tlsdesc_got = (bfd_vma) -1;
2079 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2080 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2081 if (h->got.refcount > 0
2084 && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
2086 h->got.offset = (bfd_vma) -1;
2088 else if (h->got.refcount > 0)
2092 int tls_type = elf64_x86_64_hash_entry (h)->tls_type;
2094 /* Make sure this symbol is output as a dynamic symbol.
2095 Undefined weak syms won't yet be marked as dynamic. */
2096 if (h->dynindx == -1
2097 && !h->forced_local)
2099 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2103 if (GOT_TLS_GDESC_P (tls_type))
2105 eh->tlsdesc_got = htab->elf.sgotplt->size
2106 - elf64_x86_64_compute_jump_table_size (htab);
2107 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2108 h->got.offset = (bfd_vma) -2;
2110 if (! GOT_TLS_GDESC_P (tls_type)
2111 || GOT_TLS_GD_P (tls_type))
2114 h->got.offset = s->size;
2115 s->size += GOT_ENTRY_SIZE;
2116 if (GOT_TLS_GD_P (tls_type))
2117 s->size += GOT_ENTRY_SIZE;
2119 dyn = htab->elf.dynamic_sections_created;
2120 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2122 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2123 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2124 || tls_type == GOT_TLS_IE)
2125 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2126 else if (GOT_TLS_GD_P (tls_type))
2127 htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela);
2128 else if (! GOT_TLS_GDESC_P (tls_type)
2129 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2130 || h->root.type != bfd_link_hash_undefweak)
2132 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2133 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2134 if (GOT_TLS_GDESC_P (tls_type))
2136 htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
2137 htab->tlsdesc_plt = (bfd_vma) -1;
2141 h->got.offset = (bfd_vma) -1;
2143 if (eh->dyn_relocs == NULL)
2146 /* In the shared -Bsymbolic case, discard space allocated for
2147 dynamic pc-relative relocs against symbols which turn out to be
2148 defined in regular objects. For the normal shared case, discard
2149 space for pc-relative relocs that have become local due to symbol
2150 visibility changes. */
2154 /* Relocs that use pc_count are those that appear on a call
2155 insn, or certain REL relocs that can generated via assembly.
2156 We want calls to protected symbols to resolve directly to the
2157 function rather than going via the plt. If people want
2158 function pointer comparisons to work as expected then they
2159 should avoid writing weird assembly. */
2160 if (SYMBOL_CALLS_LOCAL (info, h))
2162 struct elf64_x86_64_dyn_relocs **pp;
2164 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2166 p->count -= p->pc_count;
2175 /* Also discard relocs on undefined weak syms with non-default
2177 if (eh->dyn_relocs != NULL
2178 && h->root.type == bfd_link_hash_undefweak)
2180 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2181 eh->dyn_relocs = NULL;
2183 /* Make sure undefined weak symbols are output as a dynamic
2185 else if (h->dynindx == -1
2186 && ! h->forced_local
2187 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2192 else if (ELIMINATE_COPY_RELOCS)
2194 /* For the non-shared case, discard space for relocs against
2195 symbols which turn out to need copy relocs or are not
2201 || (htab->elf.dynamic_sections_created
2202 && (h->root.type == bfd_link_hash_undefweak
2203 || h->root.type == bfd_link_hash_undefined))))
2205 /* Make sure this symbol is output as a dynamic symbol.
2206 Undefined weak syms won't yet be marked as dynamic. */
2207 if (h->dynindx == -1
2208 && ! h->forced_local
2209 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2212 /* If that succeeded, we know we'll be keeping all the
2214 if (h->dynindx != -1)
2218 eh->dyn_relocs = NULL;
2223 /* Finally, allocate space. */
2224 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2228 sreloc = elf_section_data (p->sec)->sreloc;
2230 BFD_ASSERT (sreloc != NULL);
2232 sreloc->size += p->count * sizeof (Elf64_External_Rela);
2238 /* Allocate space in .plt, .got and associated reloc sections for
2239 local dynamic relocs. */
2242 elf64_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
2244 struct elf_link_hash_entry *h
2245 = (struct elf_link_hash_entry *) *slot;
2247 if (h->type != STT_GNU_IFUNC
2251 || h->root.type != bfd_link_hash_defined)
2254 return elf64_x86_64_allocate_dynrelocs (h, inf);
2257 /* Find any dynamic relocs that apply to read-only sections. */
2260 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2262 struct elf64_x86_64_link_hash_entry *eh;
2263 struct elf64_x86_64_dyn_relocs *p;
2265 if (h->root.type == bfd_link_hash_warning)
2266 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2268 eh = (struct elf64_x86_64_link_hash_entry *) h;
2269 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2271 asection *s = p->sec->output_section;
2273 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2275 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2277 info->flags |= DF_TEXTREL;
2279 /* Not an error, just cut short the traversal. */
2286 /* Set the sizes of the dynamic sections. */
2289 elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2290 struct bfd_link_info *info)
2292 struct elf64_x86_64_link_hash_table *htab;
2298 htab = elf64_x86_64_hash_table (info);
2299 dynobj = htab->elf.dynobj;
2303 if (htab->elf.dynamic_sections_created)
2305 /* Set the contents of the .interp section to the interpreter. */
2306 if (info->executable)
2308 s = bfd_get_section_by_name (dynobj, ".interp");
2311 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2312 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2316 /* Set up .got offsets for local syms, and space for local dynamic
2318 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2320 bfd_signed_vma *local_got;
2321 bfd_signed_vma *end_local_got;
2322 char *local_tls_type;
2323 bfd_vma *local_tlsdesc_gotent;
2324 bfd_size_type locsymcount;
2325 Elf_Internal_Shdr *symtab_hdr;
2328 if (! is_x86_64_elf (ibfd))
2331 for (s = ibfd->sections; s != NULL; s = s->next)
2333 struct elf64_x86_64_dyn_relocs *p;
2335 for (p = (struct elf64_x86_64_dyn_relocs *)
2336 (elf_section_data (s)->local_dynrel);
2340 if (!bfd_is_abs_section (p->sec)
2341 && bfd_is_abs_section (p->sec->output_section))
2343 /* Input section has been discarded, either because
2344 it is a copy of a linkonce section or due to
2345 linker script /DISCARD/, so we'll be discarding
2348 else if (p->count != 0)
2350 srel = elf_section_data (p->sec)->sreloc;
2351 srel->size += p->count * sizeof (Elf64_External_Rela);
2352 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2353 info->flags |= DF_TEXTREL;
2358 local_got = elf_local_got_refcounts (ibfd);
2362 symtab_hdr = &elf_symtab_hdr (ibfd);
2363 locsymcount = symtab_hdr->sh_info;
2364 end_local_got = local_got + locsymcount;
2365 local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
2366 local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd);
2368 srel = htab->elf.srelgot;
2369 for (; local_got < end_local_got;
2370 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2372 *local_tlsdesc_gotent = (bfd_vma) -1;
2375 if (GOT_TLS_GDESC_P (*local_tls_type))
2377 *local_tlsdesc_gotent = htab->elf.sgotplt->size
2378 - elf64_x86_64_compute_jump_table_size (htab);
2379 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2380 *local_got = (bfd_vma) -2;
2382 if (! GOT_TLS_GDESC_P (*local_tls_type)
2383 || GOT_TLS_GD_P (*local_tls_type))
2385 *local_got = s->size;
2386 s->size += GOT_ENTRY_SIZE;
2387 if (GOT_TLS_GD_P (*local_tls_type))
2388 s->size += GOT_ENTRY_SIZE;
2391 || GOT_TLS_GD_ANY_P (*local_tls_type)
2392 || *local_tls_type == GOT_TLS_IE)
2394 if (GOT_TLS_GDESC_P (*local_tls_type))
2396 htab->elf.srelplt->size
2397 += sizeof (Elf64_External_Rela);
2398 htab->tlsdesc_plt = (bfd_vma) -1;
2400 if (! GOT_TLS_GDESC_P (*local_tls_type)
2401 || GOT_TLS_GD_P (*local_tls_type))
2402 srel->size += sizeof (Elf64_External_Rela);
2406 *local_got = (bfd_vma) -1;
2410 if (htab->tls_ld_got.refcount > 0)
2412 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2414 htab->tls_ld_got.offset = htab->elf.sgot->size;
2415 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
2416 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2419 htab->tls_ld_got.offset = -1;
2421 /* Allocate global sym .plt and .got entries, and space for global
2422 sym dynamic relocs. */
2423 elf_link_hash_traverse (&htab->elf, elf64_x86_64_allocate_dynrelocs,
2426 /* Allocate .plt and .got entries, and space for local symbols. */
2427 htab_traverse (htab->loc_hash_table,
2428 elf64_x86_64_allocate_local_dynrelocs,
2431 /* For every jump slot reserved in the sgotplt, reloc_count is
2432 incremented. However, when we reserve space for TLS descriptors,
2433 it's not incremented, so in order to compute the space reserved
2434 for them, it suffices to multiply the reloc count by the jump
2436 if (htab->elf.srelplt)
2437 htab->sgotplt_jump_table_size
2438 = elf64_x86_64_compute_jump_table_size (htab);
2440 if (htab->tlsdesc_plt)
2442 /* If we're not using lazy TLS relocations, don't generate the
2443 PLT and GOT entries they require. */
2444 if ((info->flags & DF_BIND_NOW))
2445 htab->tlsdesc_plt = 0;
2448 htab->tlsdesc_got = htab->elf.sgot->size;
2449 htab->elf.sgot->size += GOT_ENTRY_SIZE;
2450 /* Reserve room for the initial entry.
2451 FIXME: we could probably do away with it in this case. */
2452 if (htab->elf.splt->size == 0)
2453 htab->elf.splt->size += PLT_ENTRY_SIZE;
2454 htab->tlsdesc_plt = htab->elf.splt->size;
2455 htab->elf.splt->size += PLT_ENTRY_SIZE;
2459 /* We now have determined the sizes of the various dynamic sections.
2460 Allocate memory for them. */
2462 for (s = dynobj->sections; s != NULL; s = s->next)
2464 if ((s->flags & SEC_LINKER_CREATED) == 0)
2467 if (s == htab->elf.splt
2468 || s == htab->elf.sgot
2469 || s == htab->elf.sgotplt
2470 || s == htab->elf.iplt
2471 || s == htab->elf.igotplt
2472 || s == htab->sdynbss)
2474 /* Strip this section if we don't need it; see the
2477 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2479 if (s->size != 0 && s != htab->elf.srelplt)
2482 /* We use the reloc_count field as a counter if we need
2483 to copy relocs into the output file. */
2484 if (s != htab->elf.srelplt)
2489 /* It's not one of our sections, so don't allocate space. */
2495 /* If we don't need this section, strip it from the
2496 output file. This is mostly to handle .rela.bss and
2497 .rela.plt. We must create both sections in
2498 create_dynamic_sections, because they must be created
2499 before the linker maps input sections to output
2500 sections. The linker does that before
2501 adjust_dynamic_symbol is called, and it is that
2502 function which decides whether anything needs to go
2503 into these sections. */
2505 s->flags |= SEC_EXCLUDE;
2509 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2512 /* Allocate memory for the section contents. We use bfd_zalloc
2513 here in case unused entries are not reclaimed before the
2514 section's contents are written out. This should not happen,
2515 but this way if it does, we get a R_X86_64_NONE reloc instead
2517 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2518 if (s->contents == NULL)
2522 if (htab->elf.dynamic_sections_created)
2524 /* Add some entries to the .dynamic section. We fill in the
2525 values later, in elf64_x86_64_finish_dynamic_sections, but we
2526 must add the entries now so that we get the correct size for
2527 the .dynamic section. The DT_DEBUG entry is filled in by the
2528 dynamic linker and used by the debugger. */
2529 #define add_dynamic_entry(TAG, VAL) \
2530 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2532 if (info->executable)
2534 if (!add_dynamic_entry (DT_DEBUG, 0))
2538 if (htab->elf.splt->size != 0)
2540 if (!add_dynamic_entry (DT_PLTGOT, 0)
2541 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2542 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2543 || !add_dynamic_entry (DT_JMPREL, 0))
2546 if (htab->tlsdesc_plt
2547 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2548 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2554 if (!add_dynamic_entry (DT_RELA, 0)
2555 || !add_dynamic_entry (DT_RELASZ, 0)
2556 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
2559 /* If any dynamic relocs apply to a read-only section,
2560 then we need a DT_TEXTREL entry. */
2561 if ((info->flags & DF_TEXTREL) == 0)
2562 elf_link_hash_traverse (&htab->elf,
2563 elf64_x86_64_readonly_dynrelocs,
2566 if ((info->flags & DF_TEXTREL) != 0)
2568 if (!add_dynamic_entry (DT_TEXTREL, 0))
2573 #undef add_dynamic_entry
2579 elf64_x86_64_always_size_sections (bfd *output_bfd,
2580 struct bfd_link_info *info)
2582 asection *tls_sec = elf_hash_table (info)->tls_sec;
2586 struct elf_link_hash_entry *tlsbase;
2588 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2589 "_TLS_MODULE_BASE_",
2590 FALSE, FALSE, FALSE);
2592 if (tlsbase && tlsbase->type == STT_TLS)
2594 struct bfd_link_hash_entry *bh = NULL;
2595 const struct elf_backend_data *bed
2596 = get_elf_backend_data (output_bfd);
2598 if (!(_bfd_generic_link_add_one_symbol
2599 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2600 tls_sec, 0, NULL, FALSE,
2601 bed->collect, &bh)))
2604 elf64_x86_64_hash_table (info)->tls_module_base = bh;
2606 tlsbase = (struct elf_link_hash_entry *)bh;
2607 tlsbase->def_regular = 1;
2608 tlsbase->other = STV_HIDDEN;
2609 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2616 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2617 executables. Rather than setting it to the beginning of the TLS
2618 section, we have to set it to the end. This function may be called
2619 multiple times, it is idempotent. */
2622 elf64_x86_64_set_tls_module_base (struct bfd_link_info *info)
2624 struct bfd_link_hash_entry *base;
2626 if (!info->executable)
2629 base = elf64_x86_64_hash_table (info)->tls_module_base;
2634 base->u.def.value = elf_hash_table (info)->tls_size;
2637 /* Return the base VMA address which should be subtracted from real addresses
2638 when resolving @dtpoff relocation.
2639 This is PT_TLS segment p_vaddr. */
2642 elf64_x86_64_dtpoff_base (struct bfd_link_info *info)
2644 /* If tls_sec is NULL, we should have signalled an error already. */
2645 if (elf_hash_table (info)->tls_sec == NULL)
2647 return elf_hash_table (info)->tls_sec->vma;
2650 /* Return the relocation value for @tpoff relocation
2651 if STT_TLS virtual address is ADDRESS. */
2654 elf64_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
2656 struct elf_link_hash_table *htab = elf_hash_table (info);
2658 /* If tls_segment is NULL, we should have signalled an error already. */
2659 if (htab->tls_sec == NULL)
2661 return address - htab->tls_size - htab->tls_sec->vma;
2664 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2668 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2670 /* Opcode Instruction
2673 0x0f 0x8x conditional jump */
2675 && (contents [offset - 1] == 0xe8
2676 || contents [offset - 1] == 0xe9))
2678 && contents [offset - 2] == 0x0f
2679 && (contents [offset - 1] & 0xf0) == 0x80));
2682 /* Relocate an x86_64 ELF section. */
2685 elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
2686 bfd *input_bfd, asection *input_section,
2687 bfd_byte *contents, Elf_Internal_Rela *relocs,
2688 Elf_Internal_Sym *local_syms,
2689 asection **local_sections)
2691 struct elf64_x86_64_link_hash_table *htab;
2692 Elf_Internal_Shdr *symtab_hdr;
2693 struct elf_link_hash_entry **sym_hashes;
2694 bfd_vma *local_got_offsets;
2695 bfd_vma *local_tlsdesc_gotents;
2696 Elf_Internal_Rela *rel;
2697 Elf_Internal_Rela *relend;
2699 BFD_ASSERT (is_x86_64_elf (input_bfd));
2701 htab = elf64_x86_64_hash_table (info);
2702 symtab_hdr = &elf_symtab_hdr (input_bfd);
2703 sym_hashes = elf_sym_hashes (input_bfd);
2704 local_got_offsets = elf_local_got_offsets (input_bfd);
2705 local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
2707 elf64_x86_64_set_tls_module_base (info);
2710 relend = relocs + input_section->reloc_count;
2711 for (; rel < relend; rel++)
2713 unsigned int r_type;
2714 reloc_howto_type *howto;
2715 unsigned long r_symndx;
2716 struct elf_link_hash_entry *h;
2717 Elf_Internal_Sym *sym;
2719 bfd_vma off, offplt;
2721 bfd_boolean unresolved_reloc;
2722 bfd_reloc_status_type r;
2726 r_type = ELF64_R_TYPE (rel->r_info);
2727 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2728 || r_type == (int) R_X86_64_GNU_VTENTRY)
2731 if (r_type >= R_X86_64_max)
2733 bfd_set_error (bfd_error_bad_value);
2737 howto = x86_64_elf_howto_table + r_type;
2738 r_symndx = ELF64_R_SYM (rel->r_info);
2742 unresolved_reloc = FALSE;
2743 if (r_symndx < symtab_hdr->sh_info)
2745 sym = local_syms + r_symndx;
2746 sec = local_sections[r_symndx];
2748 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
2751 /* Relocate against local STT_GNU_IFUNC symbol. */
2752 if (ELF64_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2754 h = elf64_x86_64_get_local_sym_hash (htab, input_bfd,
2759 /* Set STT_GNU_IFUNC symbol value. */
2760 h->root.u.def.value = sym->st_value;
2761 h->root.u.def.section = sec;
2768 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2769 r_symndx, symtab_hdr, sym_hashes,
2771 unresolved_reloc, warned);
2774 if (sec != NULL && elf_discarded_section (sec))
2776 /* For relocs against symbols from removed linkonce sections,
2777 or sections discarded by a linker script, we just want the
2778 section contents zeroed. Avoid any special processing. */
2779 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2785 if (info->relocatable)
2788 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2789 it here if it is defined in a non-shared object. */
2791 && h->type == STT_GNU_IFUNC
2797 if ((input_section->flags & SEC_ALLOC) == 0
2798 || h->plt.offset == (bfd_vma) -1)
2801 /* STT_GNU_IFUNC symbol must go through PLT. */
2802 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
2803 relocation = (plt->output_section->vma
2804 + plt->output_offset + h->plt.offset);
2809 (*_bfd_error_handler)
2810 (_("%B: relocation %s against STT_GNU_IFUNC "
2811 "symbol `%s' isn't handled by %s"), input_bfd,
2812 x86_64_elf_howto_table[r_type].name,
2813 (h->root.root.string
2814 ? h->root.root.string : "a local symbol"),
2816 bfd_set_error (bfd_error_bad_value);
2825 if (rel->r_addend != 0)
2827 (*_bfd_error_handler)
2828 (_("%B: relocation %s against STT_GNU_IFUNC "
2829 "symbol `%s' has non-zero addend: %d"),
2830 input_bfd, x86_64_elf_howto_table[r_type].name,
2831 (h->root.root.string
2832 ? h->root.root.string : "a local symbol"),
2834 bfd_set_error (bfd_error_bad_value);
2838 /* Generate dynamic relcoation only when there is a
2839 non-GOF reference in a shared object. */
2840 if (info->shared && h->non_got_ref)
2842 Elf_Internal_Rela outrel;
2846 /* Need a dynamic relocation to get the real function
2848 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2852 if (outrel.r_offset == (bfd_vma) -1
2853 || outrel.r_offset == (bfd_vma) -2)
2856 outrel.r_offset += (input_section->output_section->vma
2857 + input_section->output_offset);
2859 if (h->dynindx == -1
2861 || info->executable)
2863 /* This symbol is resolved locally. */
2864 outrel.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE);
2865 outrel.r_addend = (h->root.u.def.value
2866 + h->root.u.def.section->output_section->vma
2867 + h->root.u.def.section->output_offset);
2871 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2872 outrel.r_addend = 0;
2875 sreloc = htab->elf.irelifunc;
2876 loc = sreloc->contents;
2877 loc += (sreloc->reloc_count++
2878 * sizeof (Elf64_External_Rela));
2879 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2881 /* If this reloc is against an external symbol, we
2882 do not want to fiddle with the addend. Otherwise,
2883 we need to include the symbol value so that it
2884 becomes an addend for the dynamic reloc. For an
2885 internal symbol, we have updated addend. */
2892 case R_X86_64_PLT32:
2895 case R_X86_64_GOTPCREL:
2896 case R_X86_64_GOTPCREL64:
2897 base_got = htab->elf.sgot;
2898 off = h->got.offset;
2900 if (base_got == NULL)
2903 if (off == (bfd_vma) -1)
2905 /* We can't use h->got.offset here to save state, or
2906 even just remember the offset, as finish_dynamic_symbol
2907 would use that as offset into .got. */
2909 if (htab->elf.splt != NULL)
2911 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2912 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2913 base_got = htab->elf.sgotplt;
2917 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
2918 off = plt_index * GOT_ENTRY_SIZE;
2919 base_got = htab->elf.igotplt;
2922 if (h->dynindx == -1
2926 /* This references the local defitionion. We must
2927 initialize this entry in the global offset table.
2928 Since the offset must always be a multiple of 8,
2929 we use the least significant bit to record
2930 whether we have initialized it already.
2932 When doing a dynamic link, we create a .rela.got
2933 relocation entry to initialize the value. This
2934 is done in the finish_dynamic_symbol routine. */
2939 bfd_put_64 (output_bfd, relocation,
2940 base_got->contents + off);
2941 /* Note that this is harmless for the GOTPLT64
2942 case, as -1 | 1 still is -1. */
2948 relocation = (base_got->output_section->vma
2949 + base_got->output_offset + off);
2951 if (r_type != R_X86_64_GOTPCREL
2952 && r_type != R_X86_64_GOTPCREL64)
2955 if (htab->elf.splt != NULL)
2956 gotplt = htab->elf.sgotplt;
2958 gotplt = htab->elf.igotplt;
2959 relocation -= (gotplt->output_section->vma
2960 - gotplt->output_offset);
2967 /* When generating a shared object, the relocations handled here are
2968 copied into the output file to be resolved at run time. */
2971 case R_X86_64_GOT32:
2972 case R_X86_64_GOT64:
2973 /* Relocation is to the entry for this symbol in the global
2975 case R_X86_64_GOTPCREL:
2976 case R_X86_64_GOTPCREL64:
2977 /* Use global offset table entry as symbol value. */
2978 case R_X86_64_GOTPLT64:
2979 /* This is the same as GOT64 for relocation purposes, but
2980 indicates the existence of a PLT entry. The difficulty is,
2981 that we must calculate the GOT slot offset from the PLT
2982 offset, if this symbol got a PLT entry (it was global).
2983 Additionally if it's computed from the PLT entry, then that
2984 GOT offset is relative to .got.plt, not to .got. */
2985 base_got = htab->elf.sgot;
2987 if (htab->elf.sgot == NULL)
2994 off = h->got.offset;
2996 && h->plt.offset != (bfd_vma)-1
2997 && off == (bfd_vma)-1)
2999 /* We can't use h->got.offset here to save
3000 state, or even just remember the offset, as
3001 finish_dynamic_symbol would use that as offset into
3003 bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3004 off = (plt_index + 3) * GOT_ENTRY_SIZE;
3005 base_got = htab->elf.sgotplt;
3008 dyn = htab->elf.dynamic_sections_created;
3010 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3012 && SYMBOL_REFERENCES_LOCAL (info, h))
3013 || (ELF_ST_VISIBILITY (h->other)
3014 && h->root.type == bfd_link_hash_undefweak))
3016 /* This is actually a static link, or it is a -Bsymbolic
3017 link and the symbol is defined locally, or the symbol
3018 was forced to be local because of a version file. We
3019 must initialize this entry in the global offset table.
3020 Since the offset must always be a multiple of 8, we
3021 use the least significant bit to record whether we
3022 have initialized it already.
3024 When doing a dynamic link, we create a .rela.got
3025 relocation entry to initialize the value. This is
3026 done in the finish_dynamic_symbol routine. */
3031 bfd_put_64 (output_bfd, relocation,
3032 base_got->contents + off);
3033 /* Note that this is harmless for the GOTPLT64 case,
3034 as -1 | 1 still is -1. */
3039 unresolved_reloc = FALSE;
3043 if (local_got_offsets == NULL)
3046 off = local_got_offsets[r_symndx];
3048 /* The offset must always be a multiple of 8. We use
3049 the least significant bit to record whether we have
3050 already generated the necessary reloc. */
3055 bfd_put_64 (output_bfd, relocation,
3056 base_got->contents + off);
3061 Elf_Internal_Rela outrel;
3064 /* We need to generate a R_X86_64_RELATIVE reloc
3065 for the dynamic linker. */
3066 s = htab->elf.srelgot;
3070 outrel.r_offset = (base_got->output_section->vma
3071 + base_got->output_offset
3073 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3074 outrel.r_addend = relocation;
3076 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
3077 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3080 local_got_offsets[r_symndx] |= 1;
3084 if (off >= (bfd_vma) -2)
3087 relocation = base_got->output_section->vma
3088 + base_got->output_offset + off;
3089 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
3090 relocation -= htab->elf.sgotplt->output_section->vma
3091 - htab->elf.sgotplt->output_offset;
3095 case R_X86_64_GOTOFF64:
3096 /* Relocation is relative to the start of the global offset
3099 /* Check to make sure it isn't a protected function symbol
3100 for shared library since it may not be local when used
3101 as function address. */
3105 && h->type == STT_FUNC
3106 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3108 (*_bfd_error_handler)
3109 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3110 input_bfd, h->root.root.string);
3111 bfd_set_error (bfd_error_bad_value);
3115 /* Note that sgot is not involved in this
3116 calculation. We always want the start of .got.plt. If we
3117 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3118 permitted by the ABI, we might have to change this
3120 relocation -= htab->elf.sgotplt->output_section->vma
3121 + htab->elf.sgotplt->output_offset;
3124 case R_X86_64_GOTPC32:
3125 case R_X86_64_GOTPC64:
3126 /* Use global offset table as symbol value. */
3127 relocation = htab->elf.sgotplt->output_section->vma
3128 + htab->elf.sgotplt->output_offset;
3129 unresolved_reloc = FALSE;
3132 case R_X86_64_PLTOFF64:
3133 /* Relocation is PLT entry relative to GOT. For local
3134 symbols it's the symbol itself relative to GOT. */
3136 /* See PLT32 handling. */
3137 && h->plt.offset != (bfd_vma) -1
3138 && htab->elf.splt != NULL)
3140 relocation = (htab->elf.splt->output_section->vma
3141 + htab->elf.splt->output_offset
3143 unresolved_reloc = FALSE;
3146 relocation -= htab->elf.sgotplt->output_section->vma
3147 + htab->elf.sgotplt->output_offset;
3150 case R_X86_64_PLT32:
3151 /* Relocation is to the entry for this symbol in the
3152 procedure linkage table. */
3154 /* Resolve a PLT32 reloc against a local symbol directly,
3155 without using the procedure linkage table. */
3159 if (h->plt.offset == (bfd_vma) -1
3160 || htab->elf.splt == NULL)
3162 /* We didn't make a PLT entry for this symbol. This
3163 happens when statically linking PIC code, or when
3164 using -Bsymbolic. */
3168 relocation = (htab->elf.splt->output_section->vma
3169 + htab->elf.splt->output_offset
3171 unresolved_reloc = FALSE;
3178 && (input_section->flags & SEC_ALLOC) != 0
3179 && (input_section->flags & SEC_READONLY) != 0
3182 bfd_boolean fail = FALSE;
3184 = (r_type == R_X86_64_PC32
3185 && is_32bit_relative_branch (contents, rel->r_offset));
3187 if (SYMBOL_REFERENCES_LOCAL (info, h))
3189 /* Symbol is referenced locally. Make sure it is
3190 defined locally or for a branch. */
3191 fail = !h->def_regular && !branch;
3195 /* Symbol isn't referenced locally. We only allow
3196 branch to symbol with non-default visibility. */
3198 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
3205 const char *pic = "";
3207 switch (ELF_ST_VISIBILITY (h->other))
3210 v = _("hidden symbol");
3213 v = _("internal symbol");
3216 v = _("protected symbol");
3220 pic = _("; recompile with -fPIC");
3225 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3227 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3229 (*_bfd_error_handler) (fmt, input_bfd,
3230 x86_64_elf_howto_table[r_type].name,
3231 v, h->root.root.string, pic);
3232 bfd_set_error (bfd_error_bad_value);
3243 /* FIXME: The ABI says the linker should make sure the value is
3244 the same when it's zeroextended to 64 bit. */
3246 if ((input_section->flags & SEC_ALLOC) == 0)
3251 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3252 || h->root.type != bfd_link_hash_undefweak)
3253 && (! IS_X86_64_PCREL_TYPE (r_type)
3254 || ! SYMBOL_CALLS_LOCAL (info, h)))
3255 || (ELIMINATE_COPY_RELOCS
3262 || h->root.type == bfd_link_hash_undefweak
3263 || h->root.type == bfd_link_hash_undefined)))
3265 Elf_Internal_Rela outrel;
3267 bfd_boolean skip, relocate;
3270 /* When generating a shared object, these relocations
3271 are copied into the output file to be resolved at run
3277 _bfd_elf_section_offset (output_bfd, info, input_section,
3279 if (outrel.r_offset == (bfd_vma) -1)
3281 else if (outrel.r_offset == (bfd_vma) -2)
3282 skip = TRUE, relocate = TRUE;
3284 outrel.r_offset += (input_section->output_section->vma
3285 + input_section->output_offset);
3288 memset (&outrel, 0, sizeof outrel);
3290 /* h->dynindx may be -1 if this symbol was marked to
3294 && (IS_X86_64_PCREL_TYPE (r_type)
3296 || ! SYMBOLIC_BIND (info, h)
3297 || ! h->def_regular))
3299 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
3300 outrel.r_addend = rel->r_addend;
3304 /* This symbol is local, or marked to become local. */
3305 if (r_type == R_X86_64_64)
3308 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3309 outrel.r_addend = relocation + rel->r_addend;
3315 if (bfd_is_abs_section (sec))
3317 else if (sec == NULL || sec->owner == NULL)
3319 bfd_set_error (bfd_error_bad_value);
3326 /* We are turning this relocation into one
3327 against a section symbol. It would be
3328 proper to subtract the symbol's value,
3329 osec->vma, from the emitted reloc addend,
3330 but ld.so expects buggy relocs. */
3331 osec = sec->output_section;
3332 sindx = elf_section_data (osec)->dynindx;
3335 asection *oi = htab->elf.text_index_section;
3336 sindx = elf_section_data (oi)->dynindx;
3338 BFD_ASSERT (sindx != 0);
3341 outrel.r_info = ELF64_R_INFO (sindx, r_type);
3342 outrel.r_addend = relocation + rel->r_addend;
3346 sreloc = elf_section_data (input_section)->sreloc;
3348 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
3350 loc = sreloc->contents;
3351 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
3352 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3354 /* If this reloc is against an external symbol, we do
3355 not want to fiddle with the addend. Otherwise, we
3356 need to include the symbol value so that it becomes
3357 an addend for the dynamic reloc. */
3364 case R_X86_64_TLSGD:
3365 case R_X86_64_GOTPC32_TLSDESC:
3366 case R_X86_64_TLSDESC_CALL:
3367 case R_X86_64_GOTTPOFF:
3368 tls_type = GOT_UNKNOWN;
3369 if (h == NULL && local_got_offsets)
3370 tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx];
3372 tls_type = elf64_x86_64_hash_entry (h)->tls_type;
3374 if (! elf64_x86_64_tls_transition (info, input_bfd,
3375 input_section, contents,
3376 symtab_hdr, sym_hashes,
3377 &r_type, tls_type, rel,
3381 if (r_type == R_X86_64_TPOFF32)
3383 bfd_vma roff = rel->r_offset;
3385 BFD_ASSERT (! unresolved_reloc);
3387 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3389 /* GD->LE transition.
3390 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3391 .word 0x6666; rex64; call __tls_get_addr
3394 leaq foo@tpoff(%rax), %rax */
3395 memcpy (contents + roff - 4,
3396 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3398 bfd_put_32 (output_bfd,
3399 elf64_x86_64_tpoff (info, relocation),
3400 contents + roff + 8);
3401 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3405 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3407 /* GDesc -> LE transition.
3408 It's originally something like:
3409 leaq x@tlsdesc(%rip), %rax
3415 unsigned int val, type, type2;
3417 type = bfd_get_8 (input_bfd, contents + roff - 3);
3418 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
3419 val = bfd_get_8 (input_bfd, contents + roff - 1);
3420 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
3421 contents + roff - 3);
3422 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
3423 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3424 contents + roff - 1);
3425 bfd_put_32 (output_bfd,
3426 elf64_x86_64_tpoff (info, relocation),
3430 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3432 /* GDesc -> LE transition.
3437 bfd_put_8 (output_bfd, 0x66, contents + roff);
3438 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3441 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
3443 /* IE->LE transition:
3444 Originally it can be one of:
3445 movq foo@gottpoff(%rip), %reg
3446 addq foo@gottpoff(%rip), %reg
3449 leaq foo(%reg), %reg
3452 unsigned int val, type, reg;
3454 val = bfd_get_8 (input_bfd, contents + roff - 3);
3455 type = bfd_get_8 (input_bfd, contents + roff - 2);
3456 reg = bfd_get_8 (input_bfd, contents + roff - 1);
3462 bfd_put_8 (output_bfd, 0x49,
3463 contents + roff - 3);
3464 bfd_put_8 (output_bfd, 0xc7,
3465 contents + roff - 2);
3466 bfd_put_8 (output_bfd, 0xc0 | reg,
3467 contents + roff - 1);
3471 /* addq -> addq - addressing with %rsp/%r12 is
3474 bfd_put_8 (output_bfd, 0x49,
3475 contents + roff - 3);
3476 bfd_put_8 (output_bfd, 0x81,
3477 contents + roff - 2);
3478 bfd_put_8 (output_bfd, 0xc0 | reg,
3479 contents + roff - 1);
3485 bfd_put_8 (output_bfd, 0x4d,
3486 contents + roff - 3);
3487 bfd_put_8 (output_bfd, 0x8d,
3488 contents + roff - 2);
3489 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
3490 contents + roff - 1);
3492 bfd_put_32 (output_bfd,
3493 elf64_x86_64_tpoff (info, relocation),
3501 if (htab->elf.sgot == NULL)
3506 off = h->got.offset;
3507 offplt = elf64_x86_64_hash_entry (h)->tlsdesc_got;
3511 if (local_got_offsets == NULL)
3514 off = local_got_offsets[r_symndx];
3515 offplt = local_tlsdesc_gotents[r_symndx];
3522 Elf_Internal_Rela outrel;
3527 if (htab->elf.srelgot == NULL)
3530 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3532 if (GOT_TLS_GDESC_P (tls_type))
3534 outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC);
3535 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3536 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
3537 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3538 + htab->elf.sgotplt->output_offset
3540 + htab->sgotplt_jump_table_size);
3541 sreloc = htab->elf.srelplt;
3542 loc = sreloc->contents;
3543 loc += sreloc->reloc_count++
3544 * sizeof (Elf64_External_Rela);
3545 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3546 <= sreloc->contents + sreloc->size);
3548 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3550 outrel.r_addend = 0;
3551 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3554 sreloc = htab->elf.srelgot;
3556 outrel.r_offset = (htab->elf.sgot->output_section->vma
3557 + htab->elf.sgot->output_offset + off);
3559 if (GOT_TLS_GD_P (tls_type))
3560 dr_type = R_X86_64_DTPMOD64;
3561 else if (GOT_TLS_GDESC_P (tls_type))
3564 dr_type = R_X86_64_TPOFF64;
3566 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
3567 outrel.r_addend = 0;
3568 if ((dr_type == R_X86_64_TPOFF64
3569 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3570 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3571 outrel.r_info = ELF64_R_INFO (indx, dr_type);
3573 loc = sreloc->contents;
3574 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
3575 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3576 <= sreloc->contents + sreloc->size);
3577 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3579 if (GOT_TLS_GD_P (tls_type))
3583 BFD_ASSERT (! unresolved_reloc);
3584 bfd_put_64 (output_bfd,
3585 relocation - elf64_x86_64_dtpoff_base (info),
3586 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3590 bfd_put_64 (output_bfd, 0,
3591 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3592 outrel.r_info = ELF64_R_INFO (indx,
3594 outrel.r_offset += GOT_ENTRY_SIZE;
3595 sreloc->reloc_count++;
3596 loc += sizeof (Elf64_External_Rela);
3597 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3598 <= sreloc->contents + sreloc->size);
3599 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3607 local_got_offsets[r_symndx] |= 1;
3610 if (off >= (bfd_vma) -2
3611 && ! GOT_TLS_GDESC_P (tls_type))
3613 if (r_type == ELF64_R_TYPE (rel->r_info))
3615 if (r_type == R_X86_64_GOTPC32_TLSDESC
3616 || r_type == R_X86_64_TLSDESC_CALL)
3617 relocation = htab->elf.sgotplt->output_section->vma
3618 + htab->elf.sgotplt->output_offset
3619 + offplt + htab->sgotplt_jump_table_size;
3621 relocation = htab->elf.sgot->output_section->vma
3622 + htab->elf.sgot->output_offset + off;
3623 unresolved_reloc = FALSE;
3627 bfd_vma roff = rel->r_offset;
3629 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3631 /* GD->IE transition.
3632 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3633 .word 0x6666; rex64; call __tls_get_addr@plt
3636 addq foo@gottpoff(%rip), %rax */
3637 memcpy (contents + roff - 4,
3638 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3641 relocation = (htab->elf.sgot->output_section->vma
3642 + htab->elf.sgot->output_offset + off
3644 - input_section->output_section->vma
3645 - input_section->output_offset
3647 bfd_put_32 (output_bfd, relocation,
3648 contents + roff + 8);
3649 /* Skip R_X86_64_PLT32. */
3653 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3655 /* GDesc -> IE transition.
3656 It's originally something like:
3657 leaq x@tlsdesc(%rip), %rax
3660 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax
3663 unsigned int val, type, type2;
3665 type = bfd_get_8 (input_bfd, contents + roff - 3);
3666 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
3667 val = bfd_get_8 (input_bfd, contents + roff - 1);
3669 /* Now modify the instruction as appropriate. To
3670 turn a leaq into a movq in the form we use it, it
3671 suffices to change the second byte from 0x8d to
3673 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3675 bfd_put_32 (output_bfd,
3676 htab->elf.sgot->output_section->vma
3677 + htab->elf.sgot->output_offset + off
3679 - input_section->output_section->vma
3680 - input_section->output_offset
3685 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3687 /* GDesc -> IE transition.
3694 unsigned int val, type;
3696 type = bfd_get_8 (input_bfd, contents + roff);
3697 val = bfd_get_8 (input_bfd, contents + roff + 1);
3698 bfd_put_8 (output_bfd, 0x66, contents + roff);
3699 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3707 case R_X86_64_TLSLD:
3708 if (! elf64_x86_64_tls_transition (info, input_bfd,
3709 input_section, contents,
3710 symtab_hdr, sym_hashes,
3711 &r_type, GOT_UNKNOWN,
3715 if (r_type != R_X86_64_TLSLD)
3717 /* LD->LE transition:
3718 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3720 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3722 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3723 memcpy (contents + rel->r_offset - 3,
3724 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3725 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3730 if (htab->elf.sgot == NULL)
3733 off = htab->tls_ld_got.offset;
3738 Elf_Internal_Rela outrel;
3741 if (htab->elf.srelgot == NULL)
3744 outrel.r_offset = (htab->elf.sgot->output_section->vma
3745 + htab->elf.sgot->output_offset + off);
3747 bfd_put_64 (output_bfd, 0,
3748 htab->elf.sgot->contents + off);
3749 bfd_put_64 (output_bfd, 0,
3750 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3751 outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64);
3752 outrel.r_addend = 0;
3753 loc = htab->elf.srelgot->contents;
3754 loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3755 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3756 htab->tls_ld_got.offset |= 1;
3758 relocation = htab->elf.sgot->output_section->vma
3759 + htab->elf.sgot->output_offset + off;
3760 unresolved_reloc = FALSE;
3763 case R_X86_64_DTPOFF32:
3764 if (info->shared || (input_section->flags & SEC_CODE) == 0)
3765 relocation -= elf64_x86_64_dtpoff_base (info);
3767 relocation = elf64_x86_64_tpoff (info, relocation);
3770 case R_X86_64_TPOFF32:
3771 BFD_ASSERT (! info->shared);
3772 relocation = elf64_x86_64_tpoff (info, relocation);
3779 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3780 because such sections are not SEC_ALLOC and thus ld.so will
3781 not process them. */
3782 if (unresolved_reloc
3783 && !((input_section->flags & SEC_DEBUGGING) != 0
3785 (*_bfd_error_handler)
3786 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3789 (long) rel->r_offset,
3791 h->root.root.string);
3794 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3795 contents, rel->r_offset,
3796 relocation, rel->r_addend);
3798 if (r != bfd_reloc_ok)
3803 name = h->root.root.string;
3806 name = bfd_elf_string_from_elf_section (input_bfd,
3807 symtab_hdr->sh_link,
3812 name = bfd_section_name (input_bfd, sec);
3815 if (r == bfd_reloc_overflow)
3817 if (! ((*info->callbacks->reloc_overflow)
3818 (info, (h ? &h->root : NULL), name, howto->name,
3819 (bfd_vma) 0, input_bfd, input_section,
3825 (*_bfd_error_handler)
3826 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3827 input_bfd, input_section,
3828 (long) rel->r_offset, name, (int) r);
3837 /* Finish up dynamic symbol handling. We set the contents of various
3838 dynamic sections here. */
3841 elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
3842 struct bfd_link_info *info,
3843 struct elf_link_hash_entry *h,
3844 Elf_Internal_Sym *sym)
3846 struct elf64_x86_64_link_hash_table *htab;
3848 htab = elf64_x86_64_hash_table (info);
3850 if (h->plt.offset != (bfd_vma) -1)
3854 Elf_Internal_Rela rela;
3856 asection *plt, *gotplt, *relplt;
3858 /* When building a static executable, use .iplt, .igot.plt and
3859 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3860 if (htab->elf.splt != NULL)
3862 plt = htab->elf.splt;
3863 gotplt = htab->elf.sgotplt;
3864 relplt = htab->elf.srelplt;
3868 plt = htab->elf.iplt;
3869 gotplt = htab->elf.igotplt;
3870 relplt = htab->elf.irelplt;
3873 /* This symbol has an entry in the procedure linkage table. Set
3875 if ((h->dynindx == -1
3876 && !((h->forced_local || info->executable)
3878 && h->type == STT_GNU_IFUNC))
3884 /* Get the index in the procedure linkage table which
3885 corresponds to this symbol. This is the index of this symbol
3886 in all the symbols for which we are making plt entries. The
3887 first entry in the procedure linkage table is reserved.
3889 Get the offset into the .got table of the entry that
3890 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3891 bytes. The first three are reserved for the dynamic linker.
3893 For static executables, we don't reserve anything. */
3895 if (plt == htab->elf.splt)
3897 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3898 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
3902 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
3903 got_offset = plt_index * GOT_ENTRY_SIZE;
3906 /* Fill in the entry in the procedure linkage table. */
3907 memcpy (plt->contents + h->plt.offset, elf64_x86_64_plt_entry,
3910 /* Insert the relocation positions of the plt section. The magic
3911 numbers at the end of the statements are the positions of the
3912 relocations in the plt section. */
3913 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3914 instruction uses 6 bytes, subtract this value. */
3915 bfd_put_32 (output_bfd,
3916 (gotplt->output_section->vma
3917 + gotplt->output_offset
3919 - plt->output_section->vma
3920 - plt->output_offset
3923 plt->contents + h->plt.offset + 2);
3925 /* Don't fill PLT entry for static executables. */
3926 if (plt == htab->elf.splt)
3928 /* Put relocation index. */
3929 bfd_put_32 (output_bfd, plt_index,
3930 plt->contents + h->plt.offset + 7);
3931 /* Put offset for jmp .PLT0. */
3932 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
3933 plt->contents + h->plt.offset + 12);
3936 /* Fill in the entry in the global offset table, initially this
3937 points to the pushq instruction in the PLT which is at offset 6. */
3938 bfd_put_64 (output_bfd, (plt->output_section->vma
3939 + plt->output_offset
3940 + h->plt.offset + 6),
3941 gotplt->contents + got_offset);
3943 /* Fill in the entry in the .rela.plt section. */
3944 rela.r_offset = (gotplt->output_section->vma
3945 + gotplt->output_offset
3947 if (h->dynindx == -1
3948 || ((info->executable
3949 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3951 && h->type == STT_GNU_IFUNC))
3953 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3954 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
3955 rela.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE);
3956 rela.r_addend = (h->root.u.def.value
3957 + h->root.u.def.section->output_section->vma
3958 + h->root.u.def.section->output_offset);
3962 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
3965 loc = relplt->contents + plt_index * sizeof (Elf64_External_Rela);
3966 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3968 if (!h->def_regular)
3970 /* Mark the symbol as undefined, rather than as defined in
3971 the .plt section. Leave the value if there were any
3972 relocations where pointer equality matters (this is a clue
3973 for the dynamic linker, to make function pointer
3974 comparisons work between an application and shared
3975 library), otherwise set it to zero. If a function is only
3976 called from a binary, there is no need to slow down
3977 shared libraries because of that. */
3978 sym->st_shndx = SHN_UNDEF;
3979 if (!h->pointer_equality_needed)
3984 if (h->got.offset != (bfd_vma) -1
3985 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type)
3986 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
3988 Elf_Internal_Rela rela;
3991 /* This symbol has an entry in the global offset table. Set it
3993 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
3996 rela.r_offset = (htab->elf.sgot->output_section->vma
3997 + htab->elf.sgot->output_offset
3998 + (h->got.offset &~ (bfd_vma) 1));
4000 /* If this is a static link, or it is a -Bsymbolic link and the
4001 symbol is defined locally or was forced to be local because
4002 of a version file, we just want to emit a RELATIVE reloc.
4003 The entry in the global offset table will already have been
4004 initialized in the relocate_section function. */
4006 && h->type == STT_GNU_IFUNC)
4010 /* Generate R_X86_64_GLOB_DAT. */
4015 if (!h->pointer_equality_needed)
4018 /* For non-shared object, we can't use .got.plt, which
4019 contains the real function addres if we need pointer
4020 equality. We load the GOT entry with the PLT entry. */
4021 asection *plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4022 bfd_put_64 (output_bfd, (plt->output_section->vma
4023 + plt->output_offset
4025 htab->elf.sgot->contents + h->got.offset);
4029 else if (info->shared
4030 && SYMBOL_REFERENCES_LOCAL (info, h))
4032 if (!h->def_regular)
4034 BFD_ASSERT((h->got.offset & 1) != 0);
4035 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
4036 rela.r_addend = (h->root.u.def.value
4037 + h->root.u.def.section->output_section->vma
4038 + h->root.u.def.section->output_offset);
4042 BFD_ASSERT((h->got.offset & 1) == 0);
4044 bfd_put_64 (output_bfd, (bfd_vma) 0,
4045 htab->elf.sgot->contents + h->got.offset);
4046 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
4050 loc = htab->elf.srelgot->contents;
4051 loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
4052 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
4057 Elf_Internal_Rela rela;
4060 /* This symbol needs a copy reloc. Set it up. */
4062 if (h->dynindx == -1
4063 || (h->root.type != bfd_link_hash_defined
4064 && h->root.type != bfd_link_hash_defweak)
4065 || htab->srelbss == NULL)
4068 rela.r_offset = (h->root.u.def.value
4069 + h->root.u.def.section->output_section->vma
4070 + h->root.u.def.section->output_offset);
4071 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
4073 loc = htab->srelbss->contents;
4074 loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
4075 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
4078 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4079 be NULL for local symbols. */
4081 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
4082 || h == htab->elf.hgot))
4083 sym->st_shndx = SHN_ABS;
4088 /* Finish up local dynamic symbol handling. We set the contents of
4089 various dynamic sections here. */
4092 elf64_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
4094 struct elf_link_hash_entry *h
4095 = (struct elf_link_hash_entry *) *slot;
4096 struct bfd_link_info *info
4097 = (struct bfd_link_info *) inf;
4099 return elf64_x86_64_finish_dynamic_symbol (info->output_bfd,
4103 /* Used to decide how to sort relocs in an optimal manner for the
4104 dynamic linker, before writing them out. */
4106 static enum elf_reloc_type_class
4107 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
4109 switch ((int) ELF64_R_TYPE (rela->r_info))
4111 case R_X86_64_RELATIVE:
4112 return reloc_class_relative;
4113 case R_X86_64_JUMP_SLOT:
4114 return reloc_class_plt;
4116 return reloc_class_copy;
4118 return reloc_class_normal;
4122 /* Finish up the dynamic sections. */
4125 elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4127 struct elf64_x86_64_link_hash_table *htab;
4131 htab = elf64_x86_64_hash_table (info);
4132 dynobj = htab->elf.dynobj;
4133 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4135 if (htab->elf.dynamic_sections_created)
4137 Elf64_External_Dyn *dyncon, *dynconend;
4139 if (sdyn == NULL || htab->elf.sgot == NULL)
4142 dyncon = (Elf64_External_Dyn *) sdyn->contents;
4143 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
4144 for (; dyncon < dynconend; dyncon++)
4146 Elf_Internal_Dyn dyn;
4149 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
4157 s = htab->elf.sgotplt;
4158 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4162 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
4166 s = htab->elf.srelplt->output_section;
4167 dyn.d_un.d_val = s->size;
4171 /* The procedure linkage table relocs (DT_JMPREL) should
4172 not be included in the overall relocs (DT_RELA).
4173 Therefore, we override the DT_RELASZ entry here to
4174 make it not include the JMPREL relocs. Since the
4175 linker script arranges for .rela.plt to follow all
4176 other relocation sections, we don't have to worry
4177 about changing the DT_RELA entry. */
4178 if (htab->elf.srelplt != NULL)
4180 s = htab->elf.srelplt->output_section;
4181 dyn.d_un.d_val -= s->size;
4185 case DT_TLSDESC_PLT:
4187 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4188 + htab->tlsdesc_plt;
4191 case DT_TLSDESC_GOT:
4193 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4194 + htab->tlsdesc_got;
4198 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
4201 /* Fill in the special first entry in the procedure linkage table. */
4202 if (htab->elf.splt && htab->elf.splt->size > 0)
4204 /* Fill in the first entry in the procedure linkage table. */
4205 memcpy (htab->elf.splt->contents, elf64_x86_64_plt0_entry,
4207 /* Add offset for pushq GOT+8(%rip), since the instruction
4208 uses 6 bytes subtract this value. */
4209 bfd_put_32 (output_bfd,
4210 (htab->elf.sgotplt->output_section->vma
4211 + htab->elf.sgotplt->output_offset
4213 - htab->elf.splt->output_section->vma
4214 - htab->elf.splt->output_offset
4216 htab->elf.splt->contents + 2);
4217 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4218 the end of the instruction. */
4219 bfd_put_32 (output_bfd,
4220 (htab->elf.sgotplt->output_section->vma
4221 + htab->elf.sgotplt->output_offset
4223 - htab->elf.splt->output_section->vma
4224 - htab->elf.splt->output_offset
4226 htab->elf.splt->contents + 8);
4228 elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize =
4231 if (htab->tlsdesc_plt)
4233 bfd_put_64 (output_bfd, (bfd_vma) 0,
4234 htab->elf.sgot->contents + htab->tlsdesc_got);
4236 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
4237 elf64_x86_64_plt0_entry,
4240 /* Add offset for pushq GOT+8(%rip), since the
4241 instruction uses 6 bytes subtract this value. */
4242 bfd_put_32 (output_bfd,
4243 (htab->elf.sgotplt->output_section->vma
4244 + htab->elf.sgotplt->output_offset
4246 - htab->elf.splt->output_section->vma
4247 - htab->elf.splt->output_offset
4250 htab->elf.splt->contents + htab->tlsdesc_plt + 2);
4251 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4252 htab->tlsdesc_got. The 12 is the offset to the end of
4254 bfd_put_32 (output_bfd,
4255 (htab->elf.sgot->output_section->vma
4256 + htab->elf.sgot->output_offset
4258 - htab->elf.splt->output_section->vma
4259 - htab->elf.splt->output_offset
4262 htab->elf.splt->contents + htab->tlsdesc_plt + 8);
4267 if (htab->elf.sgotplt)
4269 /* Fill in the first three entries in the global offset table. */
4270 if (htab->elf.sgotplt->size > 0)
4272 /* Set the first entry in the global offset table to the address of
4273 the dynamic section. */
4275 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
4277 bfd_put_64 (output_bfd,
4278 sdyn->output_section->vma + sdyn->output_offset,
4279 htab->elf.sgotplt->contents);
4280 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4281 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
4282 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
4285 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
4289 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4290 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
4293 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4294 htab_traverse (htab->loc_hash_table,
4295 elf64_x86_64_finish_local_dynamic_symbol,
4301 /* Return address for Ith PLT stub in section PLT, for relocation REL
4302 or (bfd_vma) -1 if it should not be included. */
4305 elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
4306 const arelent *rel ATTRIBUTE_UNUSED)
4308 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
4311 /* Handle an x86-64 specific section when reading an object file. This
4312 is called when elfcode.h finds a section with an unknown type. */
4315 elf64_x86_64_section_from_shdr (bfd *abfd,
4316 Elf_Internal_Shdr *hdr,
4320 if (hdr->sh_type != SHT_X86_64_UNWIND)
4323 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
4329 /* Hook called by the linker routine which adds symbols from an object
4330 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4334 elf64_x86_64_add_symbol_hook (bfd *abfd,
4335 struct bfd_link_info *info,
4336 Elf_Internal_Sym *sym,
4337 const char **namep ATTRIBUTE_UNUSED,
4338 flagword *flagsp ATTRIBUTE_UNUSED,
4344 switch (sym->st_shndx)
4346 case SHN_X86_64_LCOMMON:
4347 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
4350 lcomm = bfd_make_section_with_flags (abfd,
4354 | SEC_LINKER_CREATED));
4357 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
4360 *valp = sym->st_size;
4364 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
4365 elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
4371 /* Given a BFD section, try to locate the corresponding ELF section
4375 elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4376 asection *sec, int *index)
4378 if (sec == &_bfd_elf_large_com_section)
4380 *index = SHN_X86_64_LCOMMON;
4386 /* Process a symbol. */
4389 elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
4392 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
4394 switch (elfsym->internal_elf_sym.st_shndx)
4396 case SHN_X86_64_LCOMMON:
4397 asym->section = &_bfd_elf_large_com_section;
4398 asym->value = elfsym->internal_elf_sym.st_size;
4399 /* Common symbol doesn't set BSF_GLOBAL. */
4400 asym->flags &= ~BSF_GLOBAL;
4406 elf64_x86_64_common_definition (Elf_Internal_Sym *sym)
4408 return (sym->st_shndx == SHN_COMMON
4409 || sym->st_shndx == SHN_X86_64_LCOMMON);
4413 elf64_x86_64_common_section_index (asection *sec)
4415 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4418 return SHN_X86_64_LCOMMON;
4422 elf64_x86_64_common_section (asection *sec)
4424 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4425 return bfd_com_section_ptr;
4427 return &_bfd_elf_large_com_section;
4431 elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4432 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
4433 struct elf_link_hash_entry *h,
4434 Elf_Internal_Sym *sym,
4436 bfd_vma *pvalue ATTRIBUTE_UNUSED,
4437 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
4438 bfd_boolean *skip ATTRIBUTE_UNUSED,
4439 bfd_boolean *override ATTRIBUTE_UNUSED,
4440 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
4441 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
4442 bfd_boolean *newdef ATTRIBUTE_UNUSED,
4443 bfd_boolean *newdyn,
4444 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
4445 bfd_boolean *newweak ATTRIBUTE_UNUSED,
4446 bfd *abfd ATTRIBUTE_UNUSED,
4448 bfd_boolean *olddef ATTRIBUTE_UNUSED,
4449 bfd_boolean *olddyn,
4450 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
4451 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
4455 /* A normal common symbol and a large common symbol result in a
4456 normal common symbol. We turn the large common symbol into a
4459 && h->root.type == bfd_link_hash_common
4461 && bfd_is_com_section (*sec)
4464 if (sym->st_shndx == SHN_COMMON
4465 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
4467 h->root.u.c.p->section
4468 = bfd_make_section_old_way (oldbfd, "COMMON");
4469 h->root.u.c.p->section->flags = SEC_ALLOC;
4471 else if (sym->st_shndx == SHN_X86_64_LCOMMON
4472 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
4473 *psec = *sec = bfd_com_section_ptr;
4480 elf64_x86_64_additional_program_headers (bfd *abfd,
4481 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4486 /* Check to see if we need a large readonly segment. */
4487 s = bfd_get_section_by_name (abfd, ".lrodata");
4488 if (s && (s->flags & SEC_LOAD))
4491 /* Check to see if we need a large data segment. Since .lbss sections
4492 is placed right after the .bss section, there should be no need for
4493 a large data segment just because of .lbss. */
4494 s = bfd_get_section_by_name (abfd, ".ldata");
4495 if (s && (s->flags & SEC_LOAD))
4501 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4504 elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h)
4506 if (h->plt.offset != (bfd_vma) -1
4508 && !h->pointer_equality_needed)
4511 return _bfd_elf_hash_symbol (h);
4514 static const struct bfd_elf_special_section
4515 elf64_x86_64_special_sections[]=
4517 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4518 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4519 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
4520 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4521 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4522 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4523 { NULL, 0, 0, 0, 0 }
4526 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4527 #define TARGET_LITTLE_NAME "elf64-x86-64"
4528 #define ELF_ARCH bfd_arch_i386
4529 #define ELF_MACHINE_CODE EM_X86_64
4530 #define ELF_MAXPAGESIZE 0x200000
4531 #define ELF_MINPAGESIZE 0x1000
4532 #define ELF_COMMONPAGESIZE 0x1000
4534 #define elf_backend_can_gc_sections 1
4535 #define elf_backend_can_refcount 1
4536 #define elf_backend_want_got_plt 1
4537 #define elf_backend_plt_readonly 1
4538 #define elf_backend_want_plt_sym 0
4539 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4540 #define elf_backend_rela_normal 1
4542 #define elf_info_to_howto elf64_x86_64_info_to_howto
4544 #define bfd_elf64_bfd_link_hash_table_create \
4545 elf64_x86_64_link_hash_table_create
4546 #define bfd_elf64_bfd_link_hash_table_free \
4547 elf64_x86_64_link_hash_table_free
4548 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
4549 #define bfd_elf64_bfd_reloc_name_lookup \
4550 elf64_x86_64_reloc_name_lookup
4552 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
4553 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4554 #define elf_backend_check_relocs elf64_x86_64_check_relocs
4555 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
4556 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
4557 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
4558 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
4559 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
4560 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
4561 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
4562 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
4563 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
4564 #define elf_backend_relocate_section elf64_x86_64_relocate_section
4565 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
4566 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
4567 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4568 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
4569 #define elf_backend_object_p elf64_x86_64_elf_object_p
4570 #define bfd_elf64_mkobject elf64_x86_64_mkobject
4572 #define elf_backend_section_from_shdr \
4573 elf64_x86_64_section_from_shdr
4575 #define elf_backend_section_from_bfd_section \
4576 elf64_x86_64_elf_section_from_bfd_section
4577 #define elf_backend_add_symbol_hook \
4578 elf64_x86_64_add_symbol_hook
4579 #define elf_backend_symbol_processing \
4580 elf64_x86_64_symbol_processing
4581 #define elf_backend_common_section_index \
4582 elf64_x86_64_common_section_index
4583 #define elf_backend_common_section \
4584 elf64_x86_64_common_section
4585 #define elf_backend_common_definition \
4586 elf64_x86_64_common_definition
4587 #define elf_backend_merge_symbol \
4588 elf64_x86_64_merge_symbol
4589 #define elf_backend_special_sections \
4590 elf64_x86_64_special_sections
4591 #define elf_backend_additional_program_headers \
4592 elf64_x86_64_additional_program_headers
4593 #define elf_backend_hash_symbol \
4594 elf64_x86_64_hash_symbol
4596 #undef elf_backend_post_process_headers
4597 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4599 #include "elf64-target.h"
4601 /* FreeBSD support. */
4603 #undef TARGET_LITTLE_SYM
4604 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4605 #undef TARGET_LITTLE_NAME
4606 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4609 #define ELF_OSABI ELFOSABI_FREEBSD
4612 #define elf64_bed elf64_x86_64_fbsd_bed
4614 #include "elf64-target.h"