1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010 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_lwpid
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_pid
336 = bfd_get_32 (abfd, note->descdata + 24);
337 elf_tdata (abfd)->core_program
338 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
339 elf_tdata (abfd)->core_command
340 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
343 /* Note that for some reason, a spurious space is tacked
344 onto the end of the args in some (at least one anyway)
345 implementations, so strip it off if it exists. */
348 char *command = elf_tdata (abfd)->core_command;
349 int n = strlen (command);
351 if (0 < n && command[n - 1] == ' ')
352 command[n - 1] = '\0';
358 /* Functions for the x86-64 ELF linker. */
360 /* The name of the dynamic interpreter. This is put in the .interp
363 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
365 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
366 copying dynamic variables from a shared lib into an app's dynbss
367 section, and instead use a dynamic relocation to point into the
369 #define ELIMINATE_COPY_RELOCS 1
371 /* The size in bytes of an entry in the global offset table. */
373 #define GOT_ENTRY_SIZE 8
375 /* The size in bytes of an entry in the procedure linkage table. */
377 #define PLT_ENTRY_SIZE 16
379 /* The first entry in a procedure linkage table looks like this. See the
380 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
382 static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
384 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
385 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
386 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
389 /* Subsequent entries in a procedure linkage table look like this. */
391 static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
393 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
394 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
395 0x68, /* pushq immediate */
396 0, 0, 0, 0, /* replaced with index into relocation table. */
397 0xe9, /* jmp relative */
398 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
401 /* x86-64 ELF linker hash entry. */
403 struct elf64_x86_64_link_hash_entry
405 struct elf_link_hash_entry elf;
407 /* Track dynamic relocs copied for this symbol. */
408 struct elf_dyn_relocs *dyn_relocs;
410 #define GOT_UNKNOWN 0
414 #define GOT_TLS_GDESC 4
415 #define GOT_TLS_GD_BOTH_P(type) \
416 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
417 #define GOT_TLS_GD_P(type) \
418 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
419 #define GOT_TLS_GDESC_P(type) \
420 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
421 #define GOT_TLS_GD_ANY_P(type) \
422 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
423 unsigned char tls_type;
425 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
426 starting at the end of the jump table. */
430 #define elf64_x86_64_hash_entry(ent) \
431 ((struct elf64_x86_64_link_hash_entry *)(ent))
433 struct elf64_x86_64_obj_tdata
435 struct elf_obj_tdata root;
437 /* tls_type for each local got entry. */
438 char *local_got_tls_type;
440 /* GOTPLT entries for TLS descriptors. */
441 bfd_vma *local_tlsdesc_gotent;
444 #define elf64_x86_64_tdata(abfd) \
445 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
447 #define elf64_x86_64_local_got_tls_type(abfd) \
448 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
450 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
451 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
453 #define is_x86_64_elf(bfd) \
454 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
455 && elf_tdata (bfd) != NULL \
456 && elf_object_id (bfd) == X86_64_ELF_DATA)
459 elf64_x86_64_mkobject (bfd *abfd)
461 return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata),
465 /* x86-64 ELF linker hash table. */
467 struct elf64_x86_64_link_hash_table
469 struct elf_link_hash_table elf;
471 /* Short-cuts to get to dynamic linker sections. */
477 bfd_signed_vma refcount;
481 /* The amount of space used by the jump slots in the GOT. */
482 bfd_vma sgotplt_jump_table_size;
484 /* Small local sym cache. */
485 struct sym_cache sym_cache;
487 /* _TLS_MODULE_BASE_ symbol. */
488 struct bfd_link_hash_entry *tls_module_base;
490 /* Used by local STT_GNU_IFUNC symbols. */
491 htab_t loc_hash_table;
492 void * loc_hash_memory;
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 /* Get the x86-64 ELF linker hash table from a link_info structure. */
506 #define elf64_x86_64_hash_table(p) \
507 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
508 == X86_64_ELF_DATA ? ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) : NULL)
510 #define elf64_x86_64_compute_jump_table_size(htab) \
511 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
513 /* Create an entry in an x86-64 ELF linker hash table. */
515 static struct bfd_hash_entry *
516 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
517 struct bfd_hash_table *table,
520 /* Allocate the structure if it has not already been allocated by a
524 entry = (struct bfd_hash_entry *)
525 bfd_hash_allocate (table,
526 sizeof (struct elf64_x86_64_link_hash_entry));
531 /* Call the allocation method of the superclass. */
532 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
535 struct elf64_x86_64_link_hash_entry *eh;
537 eh = (struct elf64_x86_64_link_hash_entry *) entry;
538 eh->dyn_relocs = NULL;
539 eh->tls_type = GOT_UNKNOWN;
540 eh->tlsdesc_got = (bfd_vma) -1;
546 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
547 for local symbol so that we can handle local STT_GNU_IFUNC symbols
548 as global symbol. We reuse indx and dynstr_index for local symbol
549 hash since they aren't used by global symbols in this backend. */
552 elf64_x86_64_local_htab_hash (const void *ptr)
554 struct elf_link_hash_entry *h
555 = (struct elf_link_hash_entry *) ptr;
556 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
559 /* Compare local hash entries. */
562 elf64_x86_64_local_htab_eq (const void *ptr1, const void *ptr2)
564 struct elf_link_hash_entry *h1
565 = (struct elf_link_hash_entry *) ptr1;
566 struct elf_link_hash_entry *h2
567 = (struct elf_link_hash_entry *) ptr2;
569 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
572 /* Find and/or create a hash entry for local symbol. */
574 static struct elf_link_hash_entry *
575 elf64_x86_64_get_local_sym_hash (struct elf64_x86_64_link_hash_table *htab,
576 bfd *abfd, const Elf_Internal_Rela *rel,
579 struct elf64_x86_64_link_hash_entry e, *ret;
580 asection *sec = abfd->sections;
581 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
582 ELF64_R_SYM (rel->r_info));
585 e.elf.indx = sec->id;
586 e.elf.dynstr_index = ELF64_R_SYM (rel->r_info);
587 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
588 create ? INSERT : NO_INSERT);
595 ret = (struct elf64_x86_64_link_hash_entry *) *slot;
599 ret = (struct elf64_x86_64_link_hash_entry *)
600 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
601 sizeof (struct elf64_x86_64_link_hash_entry));
604 memset (ret, 0, sizeof (*ret));
605 ret->elf.indx = sec->id;
606 ret->elf.dynstr_index = ELF64_R_SYM (rel->r_info);
607 ret->elf.dynindx = -1;
613 /* Create an X86-64 ELF linker hash table. */
615 static struct bfd_link_hash_table *
616 elf64_x86_64_link_hash_table_create (bfd *abfd)
618 struct elf64_x86_64_link_hash_table *ret;
619 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
621 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
625 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
626 elf64_x86_64_link_hash_newfunc,
627 sizeof (struct elf64_x86_64_link_hash_entry),
636 ret->sym_cache.abfd = NULL;
637 ret->tlsdesc_plt = 0;
638 ret->tlsdesc_got = 0;
639 ret->tls_ld_got.refcount = 0;
640 ret->sgotplt_jump_table_size = 0;
641 ret->tls_module_base = NULL;
643 ret->loc_hash_table = htab_try_create (1024,
644 elf64_x86_64_local_htab_hash,
645 elf64_x86_64_local_htab_eq,
647 ret->loc_hash_memory = objalloc_create ();
648 if (!ret->loc_hash_table || !ret->loc_hash_memory)
654 return &ret->elf.root;
657 /* Destroy an X86-64 ELF linker hash table. */
660 elf64_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
662 struct elf64_x86_64_link_hash_table *htab
663 = (struct elf64_x86_64_link_hash_table *) hash;
665 if (htab->loc_hash_table)
666 htab_delete (htab->loc_hash_table);
667 if (htab->loc_hash_memory)
668 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
669 _bfd_generic_link_hash_table_free (hash);
672 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
673 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
677 elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
679 struct elf64_x86_64_link_hash_table *htab;
681 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
684 htab = elf64_x86_64_hash_table (info);
688 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
690 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
693 || (!info->shared && !htab->srelbss))
699 /* Copy the extra info we tack onto an elf_link_hash_entry. */
702 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
703 struct elf_link_hash_entry *dir,
704 struct elf_link_hash_entry *ind)
706 struct elf64_x86_64_link_hash_entry *edir, *eind;
708 edir = (struct elf64_x86_64_link_hash_entry *) dir;
709 eind = (struct elf64_x86_64_link_hash_entry *) ind;
711 if (eind->dyn_relocs != NULL)
713 if (edir->dyn_relocs != NULL)
715 struct elf_dyn_relocs **pp;
716 struct elf_dyn_relocs *p;
718 /* Add reloc counts against the indirect sym to the direct sym
719 list. Merge any entries against the same section. */
720 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
722 struct elf_dyn_relocs *q;
724 for (q = edir->dyn_relocs; q != NULL; q = q->next)
725 if (q->sec == p->sec)
727 q->pc_count += p->pc_count;
728 q->count += p->count;
735 *pp = edir->dyn_relocs;
738 edir->dyn_relocs = eind->dyn_relocs;
739 eind->dyn_relocs = NULL;
742 if (ind->root.type == bfd_link_hash_indirect
743 && dir->got.refcount <= 0)
745 edir->tls_type = eind->tls_type;
746 eind->tls_type = GOT_UNKNOWN;
749 if (ELIMINATE_COPY_RELOCS
750 && ind->root.type != bfd_link_hash_indirect
751 && dir->dynamic_adjusted)
753 /* If called to transfer flags for a weakdef during processing
754 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
755 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
756 dir->ref_dynamic |= ind->ref_dynamic;
757 dir->ref_regular |= ind->ref_regular;
758 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
759 dir->needs_plt |= ind->needs_plt;
760 dir->pointer_equality_needed |= ind->pointer_equality_needed;
763 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
767 elf64_x86_64_elf_object_p (bfd *abfd)
769 /* Set the right machine number for an x86-64 elf64 file. */
770 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
788 /* Return TRUE if the TLS access code sequence support transition
792 elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec,
794 Elf_Internal_Shdr *symtab_hdr,
795 struct elf_link_hash_entry **sym_hashes,
797 const Elf_Internal_Rela *rel,
798 const Elf_Internal_Rela *relend)
801 unsigned long r_symndx;
802 struct elf_link_hash_entry *h;
805 /* Get the section contents. */
806 if (contents == NULL)
808 if (elf_section_data (sec)->this_hdr.contents != NULL)
809 contents = elf_section_data (sec)->this_hdr.contents;
812 /* FIXME: How to better handle error condition? */
813 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
816 /* Cache the section contents for elf_link_input_bfd. */
817 elf_section_data (sec)->this_hdr.contents = contents;
821 offset = rel->r_offset;
826 if ((rel + 1) >= relend)
829 if (r_type == R_X86_64_TLSGD)
831 /* Check transition from GD access model. Only
832 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
833 .word 0x6666; rex64; call __tls_get_addr
834 can transit to different access model. */
836 static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } },
837 call = { { 0x66, 0x66, 0x48, 0xe8 } };
839 || (offset + 12) > sec->size
840 || bfd_get_32 (abfd, contents + offset - 4) != leaq.i
841 || bfd_get_32 (abfd, contents + offset + 4) != call.i)
846 /* Check transition from LD access model. Only
847 leaq foo@tlsld(%rip), %rdi;
849 can transit to different access model. */
851 static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
854 if (offset < 3 || (offset + 9) > sec->size)
857 op.i = bfd_get_32 (abfd, contents + offset - 3);
858 op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
863 r_symndx = ELF64_R_SYM (rel[1].r_info);
864 if (r_symndx < symtab_hdr->sh_info)
867 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
868 /* Use strncmp to check __tls_get_addr since __tls_get_addr
871 && h->root.root.string != NULL
872 && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32
873 || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
874 && (strncmp (h->root.root.string,
875 "__tls_get_addr", 14) == 0));
877 case R_X86_64_GOTTPOFF:
878 /* Check transition from IE access model:
879 movq foo@gottpoff(%rip), %reg
880 addq foo@gottpoff(%rip), %reg
883 if (offset < 3 || (offset + 4) > sec->size)
886 val = bfd_get_8 (abfd, contents + offset - 3);
887 if (val != 0x48 && val != 0x4c)
890 val = bfd_get_8 (abfd, contents + offset - 2);
891 if (val != 0x8b && val != 0x03)
894 val = bfd_get_8 (abfd, contents + offset - 1);
895 return (val & 0xc7) == 5;
897 case R_X86_64_GOTPC32_TLSDESC:
898 /* Check transition from GDesc access model:
899 leaq x@tlsdesc(%rip), %rax
901 Make sure it's a leaq adding rip to a 32-bit offset
902 into any register, although it's probably almost always
905 if (offset < 3 || (offset + 4) > sec->size)
908 val = bfd_get_8 (abfd, contents + offset - 3);
909 if ((val & 0xfb) != 0x48)
912 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
915 val = bfd_get_8 (abfd, contents + offset - 1);
916 return (val & 0xc7) == 0x05;
918 case R_X86_64_TLSDESC_CALL:
919 /* Check transition from GDesc access model:
920 call *x@tlsdesc(%rax)
922 if (offset + 2 <= sec->size)
924 /* Make sure that it's a call *x@tlsdesc(%rax). */
925 static x86_64_opcode16 call = { { 0xff, 0x10 } };
926 return bfd_get_16 (abfd, contents + offset) == call.i;
936 /* Return TRUE if the TLS access transition is OK or no transition
937 will be performed. Update R_TYPE if there is a transition. */
940 elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
941 asection *sec, bfd_byte *contents,
942 Elf_Internal_Shdr *symtab_hdr,
943 struct elf_link_hash_entry **sym_hashes,
944 unsigned int *r_type, int tls_type,
945 const Elf_Internal_Rela *rel,
946 const Elf_Internal_Rela *relend,
947 struct elf_link_hash_entry *h,
948 unsigned long r_symndx)
950 unsigned int from_type = *r_type;
951 unsigned int to_type = from_type;
952 bfd_boolean check = TRUE;
954 /* Skip TLS transition for functions. */
956 && (h->type == STT_FUNC
957 || h->type == STT_GNU_IFUNC))
963 case R_X86_64_GOTPC32_TLSDESC:
964 case R_X86_64_TLSDESC_CALL:
965 case R_X86_64_GOTTPOFF:
966 if (info->executable)
969 to_type = R_X86_64_TPOFF32;
971 to_type = R_X86_64_GOTTPOFF;
974 /* When we are called from elf64_x86_64_relocate_section,
975 CONTENTS isn't NULL and there may be additional transitions
976 based on TLS_TYPE. */
977 if (contents != NULL)
979 unsigned int new_to_type = to_type;
984 && tls_type == GOT_TLS_IE)
985 new_to_type = R_X86_64_TPOFF32;
987 if (to_type == R_X86_64_TLSGD
988 || to_type == R_X86_64_GOTPC32_TLSDESC
989 || to_type == R_X86_64_TLSDESC_CALL)
991 if (tls_type == GOT_TLS_IE)
992 new_to_type = R_X86_64_GOTTPOFF;
995 /* We checked the transition before when we were called from
996 elf64_x86_64_check_relocs. We only want to check the new
997 transition which hasn't been checked before. */
998 check = new_to_type != to_type && from_type == to_type;
999 to_type = new_to_type;
1004 case R_X86_64_TLSLD:
1005 if (info->executable)
1006 to_type = R_X86_64_TPOFF32;
1013 /* Return TRUE if there is no transition. */
1014 if (from_type == to_type)
1017 /* Check if the transition can be performed. */
1019 && ! elf64_x86_64_check_tls_transition (abfd, sec, contents,
1020 symtab_hdr, sym_hashes,
1021 from_type, rel, relend))
1023 reloc_howto_type *from, *to;
1026 from = elf64_x86_64_rtype_to_howto (abfd, from_type);
1027 to = elf64_x86_64_rtype_to_howto (abfd, to_type);
1030 name = h->root.root.string;
1033 struct elf64_x86_64_link_hash_table *htab;
1035 htab = elf64_x86_64_hash_table (info);
1040 Elf_Internal_Sym *isym;
1042 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1044 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1048 (*_bfd_error_handler)
1049 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1050 "in section `%A' failed"),
1051 abfd, sec, from->name, to->name, name,
1052 (unsigned long) rel->r_offset);
1053 bfd_set_error (bfd_error_bad_value);
1061 /* Look through the relocs for a section during the first phase, and
1062 calculate needed space in the global offset table, procedure
1063 linkage table, and dynamic reloc sections. */
1066 elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1068 const Elf_Internal_Rela *relocs)
1070 struct elf64_x86_64_link_hash_table *htab;
1071 Elf_Internal_Shdr *symtab_hdr;
1072 struct elf_link_hash_entry **sym_hashes;
1073 const Elf_Internal_Rela *rel;
1074 const Elf_Internal_Rela *rel_end;
1077 if (info->relocatable)
1080 BFD_ASSERT (is_x86_64_elf (abfd));
1082 htab = elf64_x86_64_hash_table (info);
1086 symtab_hdr = &elf_symtab_hdr (abfd);
1087 sym_hashes = elf_sym_hashes (abfd);
1091 rel_end = relocs + sec->reloc_count;
1092 for (rel = relocs; rel < rel_end; rel++)
1094 unsigned int r_type;
1095 unsigned long r_symndx;
1096 struct elf_link_hash_entry *h;
1097 Elf_Internal_Sym *isym;
1100 r_symndx = ELF64_R_SYM (rel->r_info);
1101 r_type = ELF64_R_TYPE (rel->r_info);
1103 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1105 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1110 if (r_symndx < symtab_hdr->sh_info)
1112 /* A local symbol. */
1113 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1118 /* Check relocation against local STT_GNU_IFUNC symbol. */
1119 if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1121 h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel,
1126 /* Fake a STT_GNU_IFUNC symbol. */
1127 h->type = STT_GNU_IFUNC;
1130 h->forced_local = 1;
1131 h->root.type = bfd_link_hash_defined;
1139 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1140 while (h->root.type == bfd_link_hash_indirect
1141 || h->root.type == bfd_link_hash_warning)
1142 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1147 /* Create the ifunc sections for static executables. If we
1148 never see an indirect function symbol nor we are building
1149 a static executable, those sections will be empty and
1150 won't appear in output. */
1161 case R_X86_64_PLT32:
1162 case R_X86_64_GOTPCREL:
1163 case R_X86_64_GOTPCREL64:
1164 if (!_bfd_elf_create_ifunc_sections (abfd, info))
1169 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1170 it here if it is defined in a non-shared object. */
1171 if (h->type == STT_GNU_IFUNC
1174 /* It is referenced by a non-shared object. */
1178 /* STT_GNU_IFUNC symbol must go through PLT. */
1179 h->plt.refcount += 1;
1181 /* STT_GNU_IFUNC needs dynamic sections. */
1182 if (htab->elf.dynobj == NULL)
1183 htab->elf.dynobj = abfd;
1188 if (h->root.root.string)
1189 name = h->root.root.string;
1191 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1193 (*_bfd_error_handler)
1194 (_("%B: relocation %s against STT_GNU_IFUNC "
1195 "symbol `%s' isn't handled by %s"), abfd,
1196 x86_64_elf_howto_table[r_type].name,
1197 name, __FUNCTION__);
1198 bfd_set_error (bfd_error_bad_value);
1203 h->pointer_equality_needed = 1;
1206 /* We must copy these reloc types into the output
1207 file. Create a reloc section in dynobj and
1208 make room for this reloc. */
1209 sreloc = _bfd_elf_create_ifunc_dyn_reloc
1210 (abfd, info, sec, sreloc,
1211 &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs);
1222 if (r_type != R_X86_64_PC32
1223 && r_type != R_X86_64_PC64)
1224 h->pointer_equality_needed = 1;
1227 case R_X86_64_PLT32:
1230 case R_X86_64_GOTPCREL:
1231 case R_X86_64_GOTPCREL64:
1232 h->got.refcount += 1;
1233 if (htab->elf.sgot == NULL
1234 && !_bfd_elf_create_got_section (htab->elf.dynobj,
1244 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1245 symtab_hdr, sym_hashes,
1246 &r_type, GOT_UNKNOWN,
1247 rel, rel_end, h, r_symndx))
1252 case R_X86_64_TLSLD:
1253 htab->tls_ld_got.refcount += 1;
1256 case R_X86_64_TPOFF32:
1257 if (!info->executable)
1260 name = h->root.root.string;
1262 name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
1264 (*_bfd_error_handler)
1265 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1267 x86_64_elf_howto_table[r_type].name, name);
1268 bfd_set_error (bfd_error_bad_value);
1273 case R_X86_64_GOTTPOFF:
1274 if (!info->executable)
1275 info->flags |= DF_STATIC_TLS;
1278 case R_X86_64_GOT32:
1279 case R_X86_64_GOTPCREL:
1280 case R_X86_64_TLSGD:
1281 case R_X86_64_GOT64:
1282 case R_X86_64_GOTPCREL64:
1283 case R_X86_64_GOTPLT64:
1284 case R_X86_64_GOTPC32_TLSDESC:
1285 case R_X86_64_TLSDESC_CALL:
1286 /* This symbol requires a global offset table entry. */
1288 int tls_type, old_tls_type;
1292 default: tls_type = GOT_NORMAL; break;
1293 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1294 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1295 case R_X86_64_GOTPC32_TLSDESC:
1296 case R_X86_64_TLSDESC_CALL:
1297 tls_type = GOT_TLS_GDESC; break;
1302 if (r_type == R_X86_64_GOTPLT64)
1304 /* This relocation indicates that we also need
1305 a PLT entry, as this is a function. We don't need
1306 a PLT entry for local symbols. */
1308 h->plt.refcount += 1;
1310 h->got.refcount += 1;
1311 old_tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1315 bfd_signed_vma *local_got_refcounts;
1317 /* This is a global offset table entry for a local symbol. */
1318 local_got_refcounts = elf_local_got_refcounts (abfd);
1319 if (local_got_refcounts == NULL)
1323 size = symtab_hdr->sh_info;
1324 size *= sizeof (bfd_signed_vma)
1325 + sizeof (bfd_vma) + sizeof (char);
1326 local_got_refcounts = ((bfd_signed_vma *)
1327 bfd_zalloc (abfd, size));
1328 if (local_got_refcounts == NULL)
1330 elf_local_got_refcounts (abfd) = local_got_refcounts;
1331 elf64_x86_64_local_tlsdesc_gotent (abfd)
1332 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1333 elf64_x86_64_local_got_tls_type (abfd)
1334 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1336 local_got_refcounts[r_symndx] += 1;
1338 = elf64_x86_64_local_got_tls_type (abfd) [r_symndx];
1341 /* If a TLS symbol is accessed using IE at least once,
1342 there is no point to use dynamic model for it. */
1343 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1344 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1345 || tls_type != GOT_TLS_IE))
1347 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1348 tls_type = old_tls_type;
1349 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1350 && GOT_TLS_GD_ANY_P (tls_type))
1351 tls_type |= old_tls_type;
1355 name = h->root.root.string;
1357 name = bfd_elf_sym_name (abfd, symtab_hdr,
1359 (*_bfd_error_handler)
1360 (_("%B: '%s' accessed both as normal and thread local symbol"),
1366 if (old_tls_type != tls_type)
1369 elf64_x86_64_hash_entry (h)->tls_type = tls_type;
1371 elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1376 case R_X86_64_GOTOFF64:
1377 case R_X86_64_GOTPC32:
1378 case R_X86_64_GOTPC64:
1380 if (htab->elf.sgot == NULL)
1382 if (htab->elf.dynobj == NULL)
1383 htab->elf.dynobj = abfd;
1384 if (!_bfd_elf_create_got_section (htab->elf.dynobj,
1390 case R_X86_64_PLT32:
1391 /* This symbol requires a procedure linkage table entry. We
1392 actually build the entry in adjust_dynamic_symbol,
1393 because this might be a case of linking PIC code which is
1394 never referenced by a dynamic object, in which case we
1395 don't need to generate a procedure linkage table entry
1398 /* If this is a local symbol, we resolve it directly without
1399 creating a procedure linkage table entry. */
1404 h->plt.refcount += 1;
1407 case R_X86_64_PLTOFF64:
1408 /* This tries to form the 'address' of a function relative
1409 to GOT. For global symbols we need a PLT entry. */
1413 h->plt.refcount += 1;
1421 /* Let's help debug shared library creation. These relocs
1422 cannot be used in shared libs. Don't error out for
1423 sections we don't care about, such as debug sections or
1424 non-constant sections. */
1426 && (sec->flags & SEC_ALLOC) != 0
1427 && (sec->flags & SEC_READONLY) != 0)
1430 name = h->root.root.string;
1432 name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
1433 (*_bfd_error_handler)
1434 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1435 abfd, x86_64_elf_howto_table[r_type].name, name);
1436 bfd_set_error (bfd_error_bad_value);
1446 if (h != NULL && info->executable)
1448 /* If this reloc is in a read-only section, we might
1449 need a copy reloc. We can't check reliably at this
1450 stage whether the section is read-only, as input
1451 sections have not yet been mapped to output sections.
1452 Tentatively set the flag for now, and correct in
1453 adjust_dynamic_symbol. */
1456 /* We may need a .plt entry if the function this reloc
1457 refers to is in a shared lib. */
1458 h->plt.refcount += 1;
1459 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1460 h->pointer_equality_needed = 1;
1463 /* If we are creating a shared library, and this is a reloc
1464 against a global symbol, or a non PC relative reloc
1465 against a local symbol, then we need to copy the reloc
1466 into the shared library. However, if we are linking with
1467 -Bsymbolic, we do not need to copy a reloc against a
1468 global symbol which is defined in an object we are
1469 including in the link (i.e., DEF_REGULAR is set). At
1470 this point we have not seen all the input files, so it is
1471 possible that DEF_REGULAR is not set now but will be set
1472 later (it is never cleared). In case of a weak definition,
1473 DEF_REGULAR may be cleared later by a strong definition in
1474 a shared library. We account for that possibility below by
1475 storing information in the relocs_copied field of the hash
1476 table entry. A similar situation occurs when creating
1477 shared libraries and symbol visibility changes render the
1480 If on the other hand, we are creating an executable, we
1481 may need to keep relocations for symbols satisfied by a
1482 dynamic library if we manage to avoid copy relocs for the
1485 && (sec->flags & SEC_ALLOC) != 0
1486 && (! IS_X86_64_PCREL_TYPE (r_type)
1488 && (! SYMBOLIC_BIND (info, h)
1489 || h->root.type == bfd_link_hash_defweak
1490 || !h->def_regular))))
1491 || (ELIMINATE_COPY_RELOCS
1493 && (sec->flags & SEC_ALLOC) != 0
1495 && (h->root.type == bfd_link_hash_defweak
1496 || !h->def_regular)))
1498 struct elf_dyn_relocs *p;
1499 struct elf_dyn_relocs **head;
1501 /* We must copy these reloc types into the output file.
1502 Create a reloc section in dynobj and make room for
1506 if (htab->elf.dynobj == NULL)
1507 htab->elf.dynobj = abfd;
1509 sreloc = _bfd_elf_make_dynamic_reloc_section
1510 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
1516 /* If this is a global symbol, we count the number of
1517 relocations we need for this symbol. */
1520 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
1524 /* Track dynamic relocs needed for local syms too.
1525 We really need local syms available to do this
1530 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1535 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1539 /* Beware of type punned pointers vs strict aliasing
1541 vpp = &(elf_section_data (s)->local_dynrel);
1542 head = (struct elf_dyn_relocs **)vpp;
1546 if (p == NULL || p->sec != sec)
1548 bfd_size_type amt = sizeof *p;
1550 p = ((struct elf_dyn_relocs *)
1551 bfd_alloc (htab->elf.dynobj, amt));
1562 if (IS_X86_64_PCREL_TYPE (r_type))
1567 /* This relocation describes the C++ object vtable hierarchy.
1568 Reconstruct it for later use during GC. */
1569 case R_X86_64_GNU_VTINHERIT:
1570 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1574 /* This relocation describes which C++ vtable entries are actually
1575 used. Record for later use during GC. */
1576 case R_X86_64_GNU_VTENTRY:
1577 BFD_ASSERT (h != NULL);
1579 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1591 /* Return the section that should be marked against GC for a given
1595 elf64_x86_64_gc_mark_hook (asection *sec,
1596 struct bfd_link_info *info,
1597 Elf_Internal_Rela *rel,
1598 struct elf_link_hash_entry *h,
1599 Elf_Internal_Sym *sym)
1602 switch (ELF64_R_TYPE (rel->r_info))
1604 case R_X86_64_GNU_VTINHERIT:
1605 case R_X86_64_GNU_VTENTRY:
1609 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1612 /* Update the got entry reference counts for the section being removed. */
1615 elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1617 const Elf_Internal_Rela *relocs)
1619 struct elf64_x86_64_link_hash_table *htab;
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 htab = elf64_x86_64_hash_table (info);
1632 elf_section_data (sec)->local_dynrel = NULL;
1634 symtab_hdr = &elf_symtab_hdr (abfd);
1635 sym_hashes = elf_sym_hashes (abfd);
1636 local_got_refcounts = elf_local_got_refcounts (abfd);
1638 relend = relocs + sec->reloc_count;
1639 for (rel = relocs; rel < relend; rel++)
1641 unsigned long r_symndx;
1642 unsigned int r_type;
1643 struct elf_link_hash_entry *h = NULL;
1645 r_symndx = ELF64_R_SYM (rel->r_info);
1646 if (r_symndx >= symtab_hdr->sh_info)
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;
1655 /* A local symbol. */
1656 Elf_Internal_Sym *isym;
1658 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1661 /* Check relocation against local STT_GNU_IFUNC symbol. */
1663 && ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1665 h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel,
1674 struct elf64_x86_64_link_hash_entry *eh;
1675 struct elf_dyn_relocs **pp;
1676 struct elf_dyn_relocs *p;
1678 eh = (struct elf64_x86_64_link_hash_entry *) h;
1680 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1683 /* Everything must go for SEC. */
1689 r_type = ELF32_R_TYPE (rel->r_info);
1690 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1691 symtab_hdr, sym_hashes,
1692 &r_type, GOT_UNKNOWN,
1693 rel, relend, h, r_symndx))
1698 case R_X86_64_TLSLD:
1699 if (htab->tls_ld_got.refcount > 0)
1700 htab->tls_ld_got.refcount -= 1;
1703 case R_X86_64_TLSGD:
1704 case R_X86_64_GOTPC32_TLSDESC:
1705 case R_X86_64_TLSDESC_CALL:
1706 case R_X86_64_GOTTPOFF:
1707 case R_X86_64_GOT32:
1708 case R_X86_64_GOTPCREL:
1709 case R_X86_64_GOT64:
1710 case R_X86_64_GOTPCREL64:
1711 case R_X86_64_GOTPLT64:
1714 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
1715 h->plt.refcount -= 1;
1716 if (h->got.refcount > 0)
1717 h->got.refcount -= 1;
1718 if (h->type == STT_GNU_IFUNC)
1720 if (h->plt.refcount > 0)
1721 h->plt.refcount -= 1;
1724 else if (local_got_refcounts != NULL)
1726 if (local_got_refcounts[r_symndx] > 0)
1727 local_got_refcounts[r_symndx] -= 1;
1741 && (h == NULL || h->type != STT_GNU_IFUNC))
1745 case R_X86_64_PLT32:
1746 case R_X86_64_PLTOFF64:
1749 if (h->plt.refcount > 0)
1750 h->plt.refcount -= 1;
1762 /* Adjust a symbol defined by a dynamic object and referenced by a
1763 regular object. The current definition is in some section of the
1764 dynamic object, but we're not including those sections. We have to
1765 change the definition to something the rest of the link can
1769 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
1770 struct elf_link_hash_entry *h)
1772 struct elf64_x86_64_link_hash_table *htab;
1775 /* STT_GNU_IFUNC symbol must go through PLT. */
1776 if (h->type == STT_GNU_IFUNC)
1778 if (h->plt.refcount <= 0)
1780 h->plt.offset = (bfd_vma) -1;
1786 /* If this is a function, put it in the procedure linkage table. We
1787 will fill in the contents of the procedure linkage table later,
1788 when we know the address of the .got section. */
1789 if (h->type == STT_FUNC
1792 if (h->plt.refcount <= 0
1793 || SYMBOL_CALLS_LOCAL (info, h)
1794 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1795 && h->root.type == bfd_link_hash_undefweak))
1797 /* This case can occur if we saw a PLT32 reloc in an input
1798 file, but the symbol was never referred to by a dynamic
1799 object, or if all references were garbage collected. In
1800 such a case, we don't actually need to build a procedure
1801 linkage table, and we can just do a PC32 reloc instead. */
1802 h->plt.offset = (bfd_vma) -1;
1809 /* It's possible that we incorrectly decided a .plt reloc was
1810 needed for an R_X86_64_PC32 reloc to a non-function sym in
1811 check_relocs. We can't decide accurately between function and
1812 non-function syms in check-relocs; Objects loaded later in
1813 the link may change h->type. So fix it now. */
1814 h->plt.offset = (bfd_vma) -1;
1816 /* If this is a weak symbol, and there is a real definition, the
1817 processor independent code will have arranged for us to see the
1818 real definition first, and we can just use the same value. */
1819 if (h->u.weakdef != NULL)
1821 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1822 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1823 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1824 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1825 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1826 h->non_got_ref = h->u.weakdef->non_got_ref;
1830 /* This is a reference to a symbol defined by a dynamic object which
1831 is not a function. */
1833 /* If we are creating a shared library, we must presume that the
1834 only references to the symbol are via the global offset table.
1835 For such cases we need not do anything here; the relocations will
1836 be handled correctly by relocate_section. */
1840 /* If there are no references to this symbol that do not use the
1841 GOT, we don't need to generate a copy reloc. */
1842 if (!h->non_got_ref)
1845 /* If -z nocopyreloc was given, we won't generate them either. */
1846 if (info->nocopyreloc)
1852 if (ELIMINATE_COPY_RELOCS)
1854 struct elf64_x86_64_link_hash_entry * eh;
1855 struct elf_dyn_relocs *p;
1857 eh = (struct elf64_x86_64_link_hash_entry *) h;
1858 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1860 s = p->sec->output_section;
1861 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1865 /* If we didn't find any dynamic relocs in read-only sections, then
1866 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1876 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1877 h->root.root.string);
1881 /* We must allocate the symbol in our .dynbss section, which will
1882 become part of the .bss section of the executable. There will be
1883 an entry for this symbol in the .dynsym section. The dynamic
1884 object will contain position independent code, so all references
1885 from the dynamic object to this symbol will go through the global
1886 offset table. The dynamic linker will use the .dynsym entry to
1887 determine the address it must put in the global offset table, so
1888 both the dynamic object and the regular object will refer to the
1889 same memory location for the variable. */
1891 htab = elf64_x86_64_hash_table (info);
1895 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1896 to copy the initial value out of the dynamic object and into the
1897 runtime process image. */
1898 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1900 htab->srelbss->size += sizeof (Elf64_External_Rela);
1906 return _bfd_elf_adjust_dynamic_copy (h, s);
1909 /* Allocate space in .plt, .got and associated reloc sections for
1913 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1915 struct bfd_link_info *info;
1916 struct elf64_x86_64_link_hash_table *htab;
1917 struct elf64_x86_64_link_hash_entry *eh;
1918 struct elf_dyn_relocs *p;
1920 if (h->root.type == bfd_link_hash_indirect)
1923 if (h->root.type == bfd_link_hash_warning)
1924 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1925 eh = (struct elf64_x86_64_link_hash_entry *) h;
1927 info = (struct bfd_link_info *) inf;
1928 htab = elf64_x86_64_hash_table (info);
1932 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1933 here if it is defined and referenced in a non-shared object. */
1934 if (h->type == STT_GNU_IFUNC
1936 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
1940 else if (htab->elf.dynamic_sections_created
1941 && h->plt.refcount > 0)
1943 /* Make sure this symbol is output as a dynamic symbol.
1944 Undefined weak syms won't yet be marked as dynamic. */
1945 if (h->dynindx == -1
1946 && !h->forced_local)
1948 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1953 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1955 asection *s = htab->elf.splt;
1957 /* If this is the first .plt entry, make room for the special
1960 s->size += PLT_ENTRY_SIZE;
1962 h->plt.offset = s->size;
1964 /* If this symbol is not defined in a regular file, and we are
1965 not generating a shared library, then set the symbol to this
1966 location in the .plt. This is required to make function
1967 pointers compare as equal between the normal executable and
1968 the shared library. */
1972 h->root.u.def.section = s;
1973 h->root.u.def.value = h->plt.offset;
1976 /* Make room for this entry. */
1977 s->size += PLT_ENTRY_SIZE;
1979 /* We also need to make an entry in the .got.plt section, which
1980 will be placed in the .got section by the linker script. */
1981 htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
1983 /* We also need to make an entry in the .rela.plt section. */
1984 htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
1985 htab->elf.srelplt->reloc_count++;
1989 h->plt.offset = (bfd_vma) -1;
1995 h->plt.offset = (bfd_vma) -1;
1999 eh->tlsdesc_got = (bfd_vma) -1;
2001 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2002 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2003 if (h->got.refcount > 0
2006 && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
2008 h->got.offset = (bfd_vma) -1;
2010 else if (h->got.refcount > 0)
2014 int tls_type = elf64_x86_64_hash_entry (h)->tls_type;
2016 /* Make sure this symbol is output as a dynamic symbol.
2017 Undefined weak syms won't yet be marked as dynamic. */
2018 if (h->dynindx == -1
2019 && !h->forced_local)
2021 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2025 if (GOT_TLS_GDESC_P (tls_type))
2027 eh->tlsdesc_got = htab->elf.sgotplt->size
2028 - elf64_x86_64_compute_jump_table_size (htab);
2029 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2030 h->got.offset = (bfd_vma) -2;
2032 if (! GOT_TLS_GDESC_P (tls_type)
2033 || GOT_TLS_GD_P (tls_type))
2036 h->got.offset = s->size;
2037 s->size += GOT_ENTRY_SIZE;
2038 if (GOT_TLS_GD_P (tls_type))
2039 s->size += GOT_ENTRY_SIZE;
2041 dyn = htab->elf.dynamic_sections_created;
2042 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2044 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2045 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
2046 || tls_type == GOT_TLS_IE)
2047 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2048 else if (GOT_TLS_GD_P (tls_type))
2049 htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela);
2050 else if (! GOT_TLS_GDESC_P (tls_type)
2051 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2052 || h->root.type != bfd_link_hash_undefweak)
2054 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
2055 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2056 if (GOT_TLS_GDESC_P (tls_type))
2058 htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
2059 htab->tlsdesc_plt = (bfd_vma) -1;
2063 h->got.offset = (bfd_vma) -1;
2065 if (eh->dyn_relocs == NULL)
2068 /* In the shared -Bsymbolic case, discard space allocated for
2069 dynamic pc-relative relocs against symbols which turn out to be
2070 defined in regular objects. For the normal shared case, discard
2071 space for pc-relative relocs that have become local due to symbol
2072 visibility changes. */
2076 /* Relocs that use pc_count are those that appear on a call
2077 insn, or certain REL relocs that can generated via assembly.
2078 We want calls to protected symbols to resolve directly to the
2079 function rather than going via the plt. If people want
2080 function pointer comparisons to work as expected then they
2081 should avoid writing weird assembly. */
2082 if (SYMBOL_CALLS_LOCAL (info, h))
2084 struct elf_dyn_relocs **pp;
2086 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2088 p->count -= p->pc_count;
2097 /* Also discard relocs on undefined weak syms with non-default
2099 if (eh->dyn_relocs != NULL
2100 && h->root.type == bfd_link_hash_undefweak)
2102 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2103 eh->dyn_relocs = NULL;
2105 /* Make sure undefined weak symbols are output as a dynamic
2107 else if (h->dynindx == -1
2108 && ! h->forced_local
2109 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2114 else if (ELIMINATE_COPY_RELOCS)
2116 /* For the non-shared case, discard space for relocs against
2117 symbols which turn out to need copy relocs or are not
2123 || (htab->elf.dynamic_sections_created
2124 && (h->root.type == bfd_link_hash_undefweak
2125 || h->root.type == bfd_link_hash_undefined))))
2127 /* Make sure this symbol is output as a dynamic symbol.
2128 Undefined weak syms won't yet be marked as dynamic. */
2129 if (h->dynindx == -1
2130 && ! h->forced_local
2131 && ! bfd_elf_link_record_dynamic_symbol (info, h))
2134 /* If that succeeded, we know we'll be keeping all the
2136 if (h->dynindx != -1)
2140 eh->dyn_relocs = NULL;
2145 /* Finally, allocate space. */
2146 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2150 sreloc = elf_section_data (p->sec)->sreloc;
2152 BFD_ASSERT (sreloc != NULL);
2154 sreloc->size += p->count * sizeof (Elf64_External_Rela);
2160 /* Allocate space in .plt, .got and associated reloc sections for
2161 local dynamic relocs. */
2164 elf64_x86_64_allocate_local_dynrelocs (void **slot, void *inf)
2166 struct elf_link_hash_entry *h
2167 = (struct elf_link_hash_entry *) *slot;
2169 if (h->type != STT_GNU_IFUNC
2173 || h->root.type != bfd_link_hash_defined)
2176 return elf64_x86_64_allocate_dynrelocs (h, inf);
2179 /* Find any dynamic relocs that apply to read-only sections. */
2182 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2184 struct elf64_x86_64_link_hash_entry *eh;
2185 struct elf_dyn_relocs *p;
2187 if (h->root.type == bfd_link_hash_warning)
2188 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2190 eh = (struct elf64_x86_64_link_hash_entry *) h;
2191 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2193 asection *s = p->sec->output_section;
2195 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2197 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2199 info->flags |= DF_TEXTREL;
2201 /* Not an error, just cut short the traversal. */
2208 /* Set the sizes of the dynamic sections. */
2211 elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2212 struct bfd_link_info *info)
2214 struct elf64_x86_64_link_hash_table *htab;
2220 htab = elf64_x86_64_hash_table (info);
2224 dynobj = htab->elf.dynobj;
2228 if (htab->elf.dynamic_sections_created)
2230 /* Set the contents of the .interp section to the interpreter. */
2231 if (info->executable)
2233 s = bfd_get_section_by_name (dynobj, ".interp");
2236 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2237 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2241 /* Set up .got offsets for local syms, and space for local dynamic
2243 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2245 bfd_signed_vma *local_got;
2246 bfd_signed_vma *end_local_got;
2247 char *local_tls_type;
2248 bfd_vma *local_tlsdesc_gotent;
2249 bfd_size_type locsymcount;
2250 Elf_Internal_Shdr *symtab_hdr;
2253 if (! is_x86_64_elf (ibfd))
2256 for (s = ibfd->sections; s != NULL; s = s->next)
2258 struct elf_dyn_relocs *p;
2260 for (p = (struct elf_dyn_relocs *)
2261 (elf_section_data (s)->local_dynrel);
2265 if (!bfd_is_abs_section (p->sec)
2266 && bfd_is_abs_section (p->sec->output_section))
2268 /* Input section has been discarded, either because
2269 it is a copy of a linkonce section or due to
2270 linker script /DISCARD/, so we'll be discarding
2273 else if (p->count != 0)
2275 srel = elf_section_data (p->sec)->sreloc;
2276 srel->size += p->count * sizeof (Elf64_External_Rela);
2277 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2278 info->flags |= DF_TEXTREL;
2283 local_got = elf_local_got_refcounts (ibfd);
2287 symtab_hdr = &elf_symtab_hdr (ibfd);
2288 locsymcount = symtab_hdr->sh_info;
2289 end_local_got = local_got + locsymcount;
2290 local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
2291 local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd);
2293 srel = htab->elf.srelgot;
2294 for (; local_got < end_local_got;
2295 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2297 *local_tlsdesc_gotent = (bfd_vma) -1;
2300 if (GOT_TLS_GDESC_P (*local_tls_type))
2302 *local_tlsdesc_gotent = htab->elf.sgotplt->size
2303 - elf64_x86_64_compute_jump_table_size (htab);
2304 htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE;
2305 *local_got = (bfd_vma) -2;
2307 if (! GOT_TLS_GDESC_P (*local_tls_type)
2308 || GOT_TLS_GD_P (*local_tls_type))
2310 *local_got = s->size;
2311 s->size += GOT_ENTRY_SIZE;
2312 if (GOT_TLS_GD_P (*local_tls_type))
2313 s->size += GOT_ENTRY_SIZE;
2316 || GOT_TLS_GD_ANY_P (*local_tls_type)
2317 || *local_tls_type == GOT_TLS_IE)
2319 if (GOT_TLS_GDESC_P (*local_tls_type))
2321 htab->elf.srelplt->size
2322 += sizeof (Elf64_External_Rela);
2323 htab->tlsdesc_plt = (bfd_vma) -1;
2325 if (! GOT_TLS_GDESC_P (*local_tls_type)
2326 || GOT_TLS_GD_P (*local_tls_type))
2327 srel->size += sizeof (Elf64_External_Rela);
2331 *local_got = (bfd_vma) -1;
2335 if (htab->tls_ld_got.refcount > 0)
2337 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2339 htab->tls_ld_got.offset = htab->elf.sgot->size;
2340 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
2341 htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
2344 htab->tls_ld_got.offset = -1;
2346 /* Allocate global sym .plt and .got entries, and space for global
2347 sym dynamic relocs. */
2348 elf_link_hash_traverse (&htab->elf, elf64_x86_64_allocate_dynrelocs,
2351 /* Allocate .plt and .got entries, and space for local symbols. */
2352 htab_traverse (htab->loc_hash_table,
2353 elf64_x86_64_allocate_local_dynrelocs,
2356 /* For every jump slot reserved in the sgotplt, reloc_count is
2357 incremented. However, when we reserve space for TLS descriptors,
2358 it's not incremented, so in order to compute the space reserved
2359 for them, it suffices to multiply the reloc count by the jump
2361 if (htab->elf.srelplt)
2362 htab->sgotplt_jump_table_size
2363 = elf64_x86_64_compute_jump_table_size (htab);
2365 if (htab->tlsdesc_plt)
2367 /* If we're not using lazy TLS relocations, don't generate the
2368 PLT and GOT entries they require. */
2369 if ((info->flags & DF_BIND_NOW))
2370 htab->tlsdesc_plt = 0;
2373 htab->tlsdesc_got = htab->elf.sgot->size;
2374 htab->elf.sgot->size += GOT_ENTRY_SIZE;
2375 /* Reserve room for the initial entry.
2376 FIXME: we could probably do away with it in this case. */
2377 if (htab->elf.splt->size == 0)
2378 htab->elf.splt->size += PLT_ENTRY_SIZE;
2379 htab->tlsdesc_plt = htab->elf.splt->size;
2380 htab->elf.splt->size += PLT_ENTRY_SIZE;
2384 if (htab->elf.sgotplt)
2386 struct elf_link_hash_entry *got;
2387 got = elf_link_hash_lookup (elf_hash_table (info),
2388 "_GLOBAL_OFFSET_TABLE_",
2389 FALSE, FALSE, FALSE);
2391 /* Don't allocate .got.plt section if there are no GOT nor PLT
2392 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2394 || !got->ref_regular_nonweak)
2395 && (htab->elf.sgotplt->size
2396 == get_elf_backend_data (output_bfd)->got_header_size)
2397 && (htab->elf.splt == NULL
2398 || htab->elf.splt->size == 0)
2399 && (htab->elf.sgot == NULL
2400 || htab->elf.sgot->size == 0)
2401 && (htab->elf.iplt == NULL
2402 || htab->elf.iplt->size == 0)
2403 && (htab->elf.igotplt == NULL
2404 || htab->elf.igotplt->size == 0))
2405 htab->elf.sgotplt->size = 0;
2408 /* We now have determined the sizes of the various dynamic sections.
2409 Allocate memory for them. */
2411 for (s = dynobj->sections; s != NULL; s = s->next)
2413 if ((s->flags & SEC_LINKER_CREATED) == 0)
2416 if (s == htab->elf.splt
2417 || s == htab->elf.sgot
2418 || s == htab->elf.sgotplt
2419 || s == htab->elf.iplt
2420 || s == htab->elf.igotplt
2421 || s == htab->sdynbss)
2423 /* Strip this section if we don't need it; see the
2426 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2428 if (s->size != 0 && s != htab->elf.srelplt)
2431 /* We use the reloc_count field as a counter if we need
2432 to copy relocs into the output file. */
2433 if (s != htab->elf.srelplt)
2438 /* It's not one of our sections, so don't allocate space. */
2444 /* If we don't need this section, strip it from the
2445 output file. This is mostly to handle .rela.bss and
2446 .rela.plt. We must create both sections in
2447 create_dynamic_sections, because they must be created
2448 before the linker maps input sections to output
2449 sections. The linker does that before
2450 adjust_dynamic_symbol is called, and it is that
2451 function which decides whether anything needs to go
2452 into these sections. */
2454 s->flags |= SEC_EXCLUDE;
2458 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2461 /* Allocate memory for the section contents. We use bfd_zalloc
2462 here in case unused entries are not reclaimed before the
2463 section's contents are written out. This should not happen,
2464 but this way if it does, we get a R_X86_64_NONE reloc instead
2466 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2467 if (s->contents == NULL)
2471 if (htab->elf.dynamic_sections_created)
2473 /* Add some entries to the .dynamic section. We fill in the
2474 values later, in elf64_x86_64_finish_dynamic_sections, but we
2475 must add the entries now so that we get the correct size for
2476 the .dynamic section. The DT_DEBUG entry is filled in by the
2477 dynamic linker and used by the debugger. */
2478 #define add_dynamic_entry(TAG, VAL) \
2479 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2481 if (info->executable)
2483 if (!add_dynamic_entry (DT_DEBUG, 0))
2487 if (htab->elf.splt->size != 0)
2489 if (!add_dynamic_entry (DT_PLTGOT, 0)
2490 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2491 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2492 || !add_dynamic_entry (DT_JMPREL, 0))
2495 if (htab->tlsdesc_plt
2496 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2497 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2503 if (!add_dynamic_entry (DT_RELA, 0)
2504 || !add_dynamic_entry (DT_RELASZ, 0)
2505 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
2508 /* If any dynamic relocs apply to a read-only section,
2509 then we need a DT_TEXTREL entry. */
2510 if ((info->flags & DF_TEXTREL) == 0)
2511 elf_link_hash_traverse (&htab->elf,
2512 elf64_x86_64_readonly_dynrelocs,
2515 if ((info->flags & DF_TEXTREL) != 0)
2517 if (!add_dynamic_entry (DT_TEXTREL, 0))
2522 #undef add_dynamic_entry
2528 elf64_x86_64_always_size_sections (bfd *output_bfd,
2529 struct bfd_link_info *info)
2531 asection *tls_sec = elf_hash_table (info)->tls_sec;
2535 struct elf_link_hash_entry *tlsbase;
2537 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2538 "_TLS_MODULE_BASE_",
2539 FALSE, FALSE, FALSE);
2541 if (tlsbase && tlsbase->type == STT_TLS)
2543 struct elf64_x86_64_link_hash_table *htab;
2544 struct bfd_link_hash_entry *bh = NULL;
2545 const struct elf_backend_data *bed
2546 = get_elf_backend_data (output_bfd);
2548 htab = elf64_x86_64_hash_table (info);
2552 if (!(_bfd_generic_link_add_one_symbol
2553 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2554 tls_sec, 0, NULL, FALSE,
2555 bed->collect, &bh)))
2558 htab->tls_module_base = bh;
2560 tlsbase = (struct elf_link_hash_entry *)bh;
2561 tlsbase->def_regular = 1;
2562 tlsbase->other = STV_HIDDEN;
2563 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2570 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2571 executables. Rather than setting it to the beginning of the TLS
2572 section, we have to set it to the end. This function may be called
2573 multiple times, it is idempotent. */
2576 elf64_x86_64_set_tls_module_base (struct bfd_link_info *info)
2578 struct elf64_x86_64_link_hash_table *htab;
2579 struct bfd_link_hash_entry *base;
2581 if (!info->executable)
2584 htab = elf64_x86_64_hash_table (info);
2588 base = htab->tls_module_base;
2592 base->u.def.value = htab->elf.tls_size;
2595 /* Return the base VMA address which should be subtracted from real addresses
2596 when resolving @dtpoff relocation.
2597 This is PT_TLS segment p_vaddr. */
2600 elf64_x86_64_dtpoff_base (struct bfd_link_info *info)
2602 /* If tls_sec is NULL, we should have signalled an error already. */
2603 if (elf_hash_table (info)->tls_sec == NULL)
2605 return elf_hash_table (info)->tls_sec->vma;
2608 /* Return the relocation value for @tpoff relocation
2609 if STT_TLS virtual address is ADDRESS. */
2612 elf64_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
2614 struct elf_link_hash_table *htab = elf_hash_table (info);
2615 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
2616 bfd_vma static_tls_size;
2618 /* If tls_segment is NULL, we should have signalled an error already. */
2619 if (htab->tls_sec == NULL)
2622 /* Consider special static TLS alignment requirements. */
2623 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
2624 return address - static_tls_size - htab->tls_sec->vma;
2627 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2631 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2633 /* Opcode Instruction
2636 0x0f 0x8x conditional jump */
2638 && (contents [offset - 1] == 0xe8
2639 || contents [offset - 1] == 0xe9))
2641 && contents [offset - 2] == 0x0f
2642 && (contents [offset - 1] & 0xf0) == 0x80));
2646 elf64_x86_64_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
2648 bfd_byte *loc = s->contents;
2649 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
2650 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
2651 <= s->contents + s->size);
2652 bfd_elf64_swap_reloca_out (abfd, rel, loc);
2655 /* Relocate an x86_64 ELF section. */
2658 elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
2659 bfd *input_bfd, asection *input_section,
2660 bfd_byte *contents, Elf_Internal_Rela *relocs,
2661 Elf_Internal_Sym *local_syms,
2662 asection **local_sections)
2664 struct elf64_x86_64_link_hash_table *htab;
2665 Elf_Internal_Shdr *symtab_hdr;
2666 struct elf_link_hash_entry **sym_hashes;
2667 bfd_vma *local_got_offsets;
2668 bfd_vma *local_tlsdesc_gotents;
2669 Elf_Internal_Rela *rel;
2670 Elf_Internal_Rela *relend;
2672 BFD_ASSERT (is_x86_64_elf (input_bfd));
2674 htab = elf64_x86_64_hash_table (info);
2677 symtab_hdr = &elf_symtab_hdr (input_bfd);
2678 sym_hashes = elf_sym_hashes (input_bfd);
2679 local_got_offsets = elf_local_got_offsets (input_bfd);
2680 local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
2682 elf64_x86_64_set_tls_module_base (info);
2685 relend = relocs + input_section->reloc_count;
2686 for (; rel < relend; rel++)
2688 unsigned int r_type;
2689 reloc_howto_type *howto;
2690 unsigned long r_symndx;
2691 struct elf_link_hash_entry *h;
2692 Elf_Internal_Sym *sym;
2694 bfd_vma off, offplt;
2696 bfd_boolean unresolved_reloc;
2697 bfd_reloc_status_type r;
2701 r_type = ELF64_R_TYPE (rel->r_info);
2702 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2703 || r_type == (int) R_X86_64_GNU_VTENTRY)
2706 if (r_type >= R_X86_64_max)
2708 bfd_set_error (bfd_error_bad_value);
2712 howto = x86_64_elf_howto_table + r_type;
2713 r_symndx = ELF64_R_SYM (rel->r_info);
2717 unresolved_reloc = FALSE;
2718 if (r_symndx < symtab_hdr->sh_info)
2720 sym = local_syms + r_symndx;
2721 sec = local_sections[r_symndx];
2723 relocation = _bfd_elf_rela_local_sym (output_bfd, sym,
2726 /* Relocate against local STT_GNU_IFUNC symbol. */
2727 if (!info->relocatable
2728 && ELF64_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2730 h = elf64_x86_64_get_local_sym_hash (htab, input_bfd,
2735 /* Set STT_GNU_IFUNC symbol value. */
2736 h->root.u.def.value = sym->st_value;
2737 h->root.u.def.section = sec;
2742 bfd_boolean warned ATTRIBUTE_UNUSED;
2744 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2745 r_symndx, symtab_hdr, sym_hashes,
2747 unresolved_reloc, warned);
2750 if (sec != NULL && elf_discarded_section (sec))
2751 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2752 rel, relend, howto, contents);
2754 if (info->relocatable)
2757 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2758 it here if it is defined in a non-shared object. */
2760 && h->type == STT_GNU_IFUNC
2767 if ((input_section->flags & SEC_ALLOC) == 0
2768 || h->plt.offset == (bfd_vma) -1)
2771 /* STT_GNU_IFUNC symbol must go through PLT. */
2772 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
2773 relocation = (plt->output_section->vma
2774 + plt->output_offset + h->plt.offset);
2779 if (h->root.root.string)
2780 name = h->root.root.string;
2782 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
2784 (*_bfd_error_handler)
2785 (_("%B: relocation %s against STT_GNU_IFUNC "
2786 "symbol `%s' isn't handled by %s"), input_bfd,
2787 x86_64_elf_howto_table[r_type].name,
2788 name, __FUNCTION__);
2789 bfd_set_error (bfd_error_bad_value);
2798 if (rel->r_addend != 0)
2800 if (h->root.root.string)
2801 name = h->root.root.string;
2803 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
2805 (*_bfd_error_handler)
2806 (_("%B: relocation %s against STT_GNU_IFUNC "
2807 "symbol `%s' has non-zero addend: %d"),
2808 input_bfd, x86_64_elf_howto_table[r_type].name,
2809 name, rel->r_addend);
2810 bfd_set_error (bfd_error_bad_value);
2814 /* Generate dynamic relcoation only when there is a
2815 non-GOF reference in a shared object. */
2816 if (info->shared && h->non_got_ref)
2818 Elf_Internal_Rela outrel;
2821 /* Need a dynamic relocation to get the real function
2823 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2827 if (outrel.r_offset == (bfd_vma) -1
2828 || outrel.r_offset == (bfd_vma) -2)
2831 outrel.r_offset += (input_section->output_section->vma
2832 + input_section->output_offset);
2834 if (h->dynindx == -1
2836 || info->executable)
2838 /* This symbol is resolved locally. */
2839 outrel.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE);
2840 outrel.r_addend = (h->root.u.def.value
2841 + h->root.u.def.section->output_section->vma
2842 + h->root.u.def.section->output_offset);
2846 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2847 outrel.r_addend = 0;
2850 sreloc = htab->elf.irelifunc;
2851 elf64_x86_64_append_rela (output_bfd, sreloc, &outrel);
2853 /* If this reloc is against an external symbol, we
2854 do not want to fiddle with the addend. Otherwise,
2855 we need to include the symbol value so that it
2856 becomes an addend for the dynamic reloc. For an
2857 internal symbol, we have updated addend. */
2864 case R_X86_64_PLT32:
2867 case R_X86_64_GOTPCREL:
2868 case R_X86_64_GOTPCREL64:
2869 base_got = htab->elf.sgot;
2870 off = h->got.offset;
2872 if (base_got == NULL)
2875 if (off == (bfd_vma) -1)
2877 /* We can't use h->got.offset here to save state, or
2878 even just remember the offset, as finish_dynamic_symbol
2879 would use that as offset into .got. */
2881 if (htab->elf.splt != NULL)
2883 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2884 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2885 base_got = htab->elf.sgotplt;
2889 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
2890 off = plt_index * GOT_ENTRY_SIZE;
2891 base_got = htab->elf.igotplt;
2894 if (h->dynindx == -1
2898 /* This references the local defitionion. We must
2899 initialize this entry in the global offset table.
2900 Since the offset must always be a multiple of 8,
2901 we use the least significant bit to record
2902 whether we have initialized it already.
2904 When doing a dynamic link, we create a .rela.got
2905 relocation entry to initialize the value. This
2906 is done in the finish_dynamic_symbol routine. */
2911 bfd_put_64 (output_bfd, relocation,
2912 base_got->contents + off);
2913 /* Note that this is harmless for the GOTPLT64
2914 case, as -1 | 1 still is -1. */
2920 relocation = (base_got->output_section->vma
2921 + base_got->output_offset + off);
2923 if (r_type != R_X86_64_GOTPCREL
2924 && r_type != R_X86_64_GOTPCREL64)
2927 if (htab->elf.splt != NULL)
2928 gotplt = htab->elf.sgotplt;
2930 gotplt = htab->elf.igotplt;
2931 relocation -= (gotplt->output_section->vma
2932 - gotplt->output_offset);
2939 /* When generating a shared object, the relocations handled here are
2940 copied into the output file to be resolved at run time. */
2943 case R_X86_64_GOT32:
2944 case R_X86_64_GOT64:
2945 /* Relocation is to the entry for this symbol in the global
2947 case R_X86_64_GOTPCREL:
2948 case R_X86_64_GOTPCREL64:
2949 /* Use global offset table entry as symbol value. */
2950 case R_X86_64_GOTPLT64:
2951 /* This is the same as GOT64 for relocation purposes, but
2952 indicates the existence of a PLT entry. The difficulty is,
2953 that we must calculate the GOT slot offset from the PLT
2954 offset, if this symbol got a PLT entry (it was global).
2955 Additionally if it's computed from the PLT entry, then that
2956 GOT offset is relative to .got.plt, not to .got. */
2957 base_got = htab->elf.sgot;
2959 if (htab->elf.sgot == NULL)
2966 off = h->got.offset;
2968 && h->plt.offset != (bfd_vma)-1
2969 && off == (bfd_vma)-1)
2971 /* We can't use h->got.offset here to save
2972 state, or even just remember the offset, as
2973 finish_dynamic_symbol would use that as offset into
2975 bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2976 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2977 base_got = htab->elf.sgotplt;
2980 dyn = htab->elf.dynamic_sections_created;
2982 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2984 && SYMBOL_REFERENCES_LOCAL (info, h))
2985 || (ELF_ST_VISIBILITY (h->other)
2986 && h->root.type == bfd_link_hash_undefweak))
2988 /* This is actually a static link, or it is a -Bsymbolic
2989 link and the symbol is defined locally, or the symbol
2990 was forced to be local because of a version file. We
2991 must initialize this entry in the global offset table.
2992 Since the offset must always be a multiple of 8, we
2993 use the least significant bit to record whether we
2994 have initialized it already.
2996 When doing a dynamic link, we create a .rela.got
2997 relocation entry to initialize the value. This is
2998 done in the finish_dynamic_symbol routine. */
3003 bfd_put_64 (output_bfd, relocation,
3004 base_got->contents + off);
3005 /* Note that this is harmless for the GOTPLT64 case,
3006 as -1 | 1 still is -1. */
3011 unresolved_reloc = FALSE;
3015 if (local_got_offsets == NULL)
3018 off = local_got_offsets[r_symndx];
3020 /* The offset must always be a multiple of 8. We use
3021 the least significant bit to record whether we have
3022 already generated the necessary reloc. */
3027 bfd_put_64 (output_bfd, relocation,
3028 base_got->contents + off);
3033 Elf_Internal_Rela outrel;
3035 /* We need to generate a R_X86_64_RELATIVE reloc
3036 for the dynamic linker. */
3037 s = htab->elf.srelgot;
3041 outrel.r_offset = (base_got->output_section->vma
3042 + base_got->output_offset
3044 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3045 outrel.r_addend = relocation;
3046 elf64_x86_64_append_rela (output_bfd, s, &outrel);
3049 local_got_offsets[r_symndx] |= 1;
3053 if (off >= (bfd_vma) -2)
3056 relocation = base_got->output_section->vma
3057 + base_got->output_offset + off;
3058 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
3059 relocation -= htab->elf.sgotplt->output_section->vma
3060 - htab->elf.sgotplt->output_offset;
3064 case R_X86_64_GOTOFF64:
3065 /* Relocation is relative to the start of the global offset
3068 /* Check to make sure it isn't a protected function symbol
3069 for shared library since it may not be local when used
3070 as function address. */
3074 && h->type == STT_FUNC
3075 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
3077 (*_bfd_error_handler)
3078 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3079 input_bfd, h->root.root.string);
3080 bfd_set_error (bfd_error_bad_value);
3084 /* Note that sgot is not involved in this
3085 calculation. We always want the start of .got.plt. If we
3086 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3087 permitted by the ABI, we might have to change this
3089 relocation -= htab->elf.sgotplt->output_section->vma
3090 + htab->elf.sgotplt->output_offset;
3093 case R_X86_64_GOTPC32:
3094 case R_X86_64_GOTPC64:
3095 /* Use global offset table as symbol value. */
3096 relocation = htab->elf.sgotplt->output_section->vma
3097 + htab->elf.sgotplt->output_offset;
3098 unresolved_reloc = FALSE;
3101 case R_X86_64_PLTOFF64:
3102 /* Relocation is PLT entry relative to GOT. For local
3103 symbols it's the symbol itself relative to GOT. */
3105 /* See PLT32 handling. */
3106 && h->plt.offset != (bfd_vma) -1
3107 && htab->elf.splt != NULL)
3109 relocation = (htab->elf.splt->output_section->vma
3110 + htab->elf.splt->output_offset
3112 unresolved_reloc = FALSE;
3115 relocation -= htab->elf.sgotplt->output_section->vma
3116 + htab->elf.sgotplt->output_offset;
3119 case R_X86_64_PLT32:
3120 /* Relocation is to the entry for this symbol in the
3121 procedure linkage table. */
3123 /* Resolve a PLT32 reloc against a local symbol directly,
3124 without using the procedure linkage table. */
3128 if (h->plt.offset == (bfd_vma) -1
3129 || htab->elf.splt == NULL)
3131 /* We didn't make a PLT entry for this symbol. This
3132 happens when statically linking PIC code, or when
3133 using -Bsymbolic. */
3137 relocation = (htab->elf.splt->output_section->vma
3138 + htab->elf.splt->output_offset
3140 unresolved_reloc = FALSE;
3147 && (input_section->flags & SEC_ALLOC) != 0
3148 && (input_section->flags & SEC_READONLY) != 0
3151 bfd_boolean fail = FALSE;
3153 = (r_type == R_X86_64_PC32
3154 && is_32bit_relative_branch (contents, rel->r_offset));
3156 if (SYMBOL_REFERENCES_LOCAL (info, h))
3158 /* Symbol is referenced locally. Make sure it is
3159 defined locally or for a branch. */
3160 fail = !h->def_regular && !branch;
3164 /* Symbol isn't referenced locally. We only allow
3165 branch to symbol with non-default visibility. */
3167 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
3174 const char *pic = "";
3176 switch (ELF_ST_VISIBILITY (h->other))
3179 v = _("hidden symbol");
3182 v = _("internal symbol");
3185 v = _("protected symbol");
3189 pic = _("; recompile with -fPIC");
3194 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3196 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3198 (*_bfd_error_handler) (fmt, input_bfd,
3199 x86_64_elf_howto_table[r_type].name,
3200 v, h->root.root.string, pic);
3201 bfd_set_error (bfd_error_bad_value);
3212 /* FIXME: The ABI says the linker should make sure the value is
3213 the same when it's zeroextended to 64 bit. */
3215 if ((input_section->flags & SEC_ALLOC) == 0)
3220 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3221 || h->root.type != bfd_link_hash_undefweak)
3222 && (! IS_X86_64_PCREL_TYPE (r_type)
3223 || ! SYMBOL_CALLS_LOCAL (info, h)))
3224 || (ELIMINATE_COPY_RELOCS
3231 || h->root.type == bfd_link_hash_undefweak
3232 || h->root.type == bfd_link_hash_undefined)))
3234 Elf_Internal_Rela outrel;
3235 bfd_boolean skip, relocate;
3238 /* When generating a shared object, these relocations
3239 are copied into the output file to be resolved at run
3245 _bfd_elf_section_offset (output_bfd, info, input_section,
3247 if (outrel.r_offset == (bfd_vma) -1)
3249 else if (outrel.r_offset == (bfd_vma) -2)
3250 skip = TRUE, relocate = TRUE;
3252 outrel.r_offset += (input_section->output_section->vma
3253 + input_section->output_offset);
3256 memset (&outrel, 0, sizeof outrel);
3258 /* h->dynindx may be -1 if this symbol was marked to
3262 && (IS_X86_64_PCREL_TYPE (r_type)
3264 || ! SYMBOLIC_BIND (info, h)
3265 || ! h->def_regular))
3267 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
3268 outrel.r_addend = rel->r_addend;
3272 /* This symbol is local, or marked to become local. */
3273 if (r_type == R_X86_64_64)
3276 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3277 outrel.r_addend = relocation + rel->r_addend;
3283 if (bfd_is_abs_section (sec))
3285 else if (sec == NULL || sec->owner == NULL)
3287 bfd_set_error (bfd_error_bad_value);
3294 /* We are turning this relocation into one
3295 against a section symbol. It would be
3296 proper to subtract the symbol's value,
3297 osec->vma, from the emitted reloc addend,
3298 but ld.so expects buggy relocs. */
3299 osec = sec->output_section;
3300 sindx = elf_section_data (osec)->dynindx;
3303 asection *oi = htab->elf.text_index_section;
3304 sindx = elf_section_data (oi)->dynindx;
3306 BFD_ASSERT (sindx != 0);
3309 outrel.r_info = ELF64_R_INFO (sindx, r_type);
3310 outrel.r_addend = relocation + rel->r_addend;
3314 sreloc = elf_section_data (input_section)->sreloc;
3316 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
3318 elf64_x86_64_append_rela (output_bfd, sreloc, &outrel);
3320 /* If this reloc is against an external symbol, we do
3321 not want to fiddle with the addend. Otherwise, we
3322 need to include the symbol value so that it becomes
3323 an addend for the dynamic reloc. */
3330 case R_X86_64_TLSGD:
3331 case R_X86_64_GOTPC32_TLSDESC:
3332 case R_X86_64_TLSDESC_CALL:
3333 case R_X86_64_GOTTPOFF:
3334 tls_type = GOT_UNKNOWN;
3335 if (h == NULL && local_got_offsets)
3336 tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx];
3338 tls_type = elf64_x86_64_hash_entry (h)->tls_type;
3340 if (! elf64_x86_64_tls_transition (info, input_bfd,
3341 input_section, contents,
3342 symtab_hdr, sym_hashes,
3343 &r_type, tls_type, rel,
3344 relend, h, r_symndx))
3347 if (r_type == R_X86_64_TPOFF32)
3349 bfd_vma roff = rel->r_offset;
3351 BFD_ASSERT (! unresolved_reloc);
3353 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3355 /* GD->LE transition.
3356 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3357 .word 0x6666; rex64; call __tls_get_addr
3360 leaq foo@tpoff(%rax), %rax */
3361 memcpy (contents + roff - 4,
3362 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3364 bfd_put_32 (output_bfd,
3365 elf64_x86_64_tpoff (info, relocation),
3366 contents + roff + 8);
3367 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3371 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3373 /* GDesc -> LE transition.
3374 It's originally something like:
3375 leaq x@tlsdesc(%rip), %rax
3378 movl $x@tpoff, %rax. */
3380 unsigned int val, type;
3382 type = bfd_get_8 (input_bfd, contents + roff - 3);
3383 val = bfd_get_8 (input_bfd, contents + roff - 1);
3384 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
3385 contents + roff - 3);
3386 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
3387 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
3388 contents + roff - 1);
3389 bfd_put_32 (output_bfd,
3390 elf64_x86_64_tpoff (info, relocation),
3394 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3396 /* GDesc -> LE transition.
3401 bfd_put_8 (output_bfd, 0x66, contents + roff);
3402 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3405 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
3407 /* IE->LE transition:
3408 Originally it can be one of:
3409 movq foo@gottpoff(%rip), %reg
3410 addq foo@gottpoff(%rip), %reg
3413 leaq foo(%reg), %reg
3416 unsigned int val, type, reg;
3418 val = bfd_get_8 (input_bfd, contents + roff - 3);
3419 type = bfd_get_8 (input_bfd, contents + roff - 2);
3420 reg = bfd_get_8 (input_bfd, contents + roff - 1);
3426 bfd_put_8 (output_bfd, 0x49,
3427 contents + roff - 3);
3428 bfd_put_8 (output_bfd, 0xc7,
3429 contents + roff - 2);
3430 bfd_put_8 (output_bfd, 0xc0 | reg,
3431 contents + roff - 1);
3435 /* addq -> addq - addressing with %rsp/%r12 is
3438 bfd_put_8 (output_bfd, 0x49,
3439 contents + roff - 3);
3440 bfd_put_8 (output_bfd, 0x81,
3441 contents + roff - 2);
3442 bfd_put_8 (output_bfd, 0xc0 | reg,
3443 contents + roff - 1);
3449 bfd_put_8 (output_bfd, 0x4d,
3450 contents + roff - 3);
3451 bfd_put_8 (output_bfd, 0x8d,
3452 contents + roff - 2);
3453 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
3454 contents + roff - 1);
3456 bfd_put_32 (output_bfd,
3457 elf64_x86_64_tpoff (info, relocation),
3465 if (htab->elf.sgot == NULL)
3470 off = h->got.offset;
3471 offplt = elf64_x86_64_hash_entry (h)->tlsdesc_got;
3475 if (local_got_offsets == NULL)
3478 off = local_got_offsets[r_symndx];
3479 offplt = local_tlsdesc_gotents[r_symndx];
3486 Elf_Internal_Rela outrel;
3490 if (htab->elf.srelgot == NULL)
3493 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3495 if (GOT_TLS_GDESC_P (tls_type))
3497 outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC);
3498 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3499 + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size);
3500 outrel.r_offset = (htab->elf.sgotplt->output_section->vma
3501 + htab->elf.sgotplt->output_offset
3503 + htab->sgotplt_jump_table_size);
3504 sreloc = htab->elf.srelplt;
3506 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3508 outrel.r_addend = 0;
3509 elf64_x86_64_append_rela (output_bfd, sreloc, &outrel);
3512 sreloc = htab->elf.srelgot;
3514 outrel.r_offset = (htab->elf.sgot->output_section->vma
3515 + htab->elf.sgot->output_offset + off);
3517 if (GOT_TLS_GD_P (tls_type))
3518 dr_type = R_X86_64_DTPMOD64;
3519 else if (GOT_TLS_GDESC_P (tls_type))
3522 dr_type = R_X86_64_TPOFF64;
3524 bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off);
3525 outrel.r_addend = 0;
3526 if ((dr_type == R_X86_64_TPOFF64
3527 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3528 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3529 outrel.r_info = ELF64_R_INFO (indx, dr_type);
3531 elf64_x86_64_append_rela (output_bfd, sreloc, &outrel);
3533 if (GOT_TLS_GD_P (tls_type))
3537 BFD_ASSERT (! unresolved_reloc);
3538 bfd_put_64 (output_bfd,
3539 relocation - elf64_x86_64_dtpoff_base (info),
3540 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3544 bfd_put_64 (output_bfd, 0,
3545 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3546 outrel.r_info = ELF64_R_INFO (indx,
3548 outrel.r_offset += GOT_ENTRY_SIZE;
3549 elf64_x86_64_append_rela (output_bfd, sreloc,
3558 local_got_offsets[r_symndx] |= 1;
3561 if (off >= (bfd_vma) -2
3562 && ! GOT_TLS_GDESC_P (tls_type))
3564 if (r_type == ELF64_R_TYPE (rel->r_info))
3566 if (r_type == R_X86_64_GOTPC32_TLSDESC
3567 || r_type == R_X86_64_TLSDESC_CALL)
3568 relocation = htab->elf.sgotplt->output_section->vma
3569 + htab->elf.sgotplt->output_offset
3570 + offplt + htab->sgotplt_jump_table_size;
3572 relocation = htab->elf.sgot->output_section->vma
3573 + htab->elf.sgot->output_offset + off;
3574 unresolved_reloc = FALSE;
3578 bfd_vma roff = rel->r_offset;
3580 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3582 /* GD->IE transition.
3583 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3584 .word 0x6666; rex64; call __tls_get_addr@plt
3587 addq foo@gottpoff(%rip), %rax */
3588 memcpy (contents + roff - 4,
3589 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3592 relocation = (htab->elf.sgot->output_section->vma
3593 + htab->elf.sgot->output_offset + off
3595 - input_section->output_section->vma
3596 - input_section->output_offset
3598 bfd_put_32 (output_bfd, relocation,
3599 contents + roff + 8);
3600 /* Skip R_X86_64_PLT32. */
3604 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3606 /* GDesc -> IE transition.
3607 It's originally something like:
3608 leaq x@tlsdesc(%rip), %rax
3611 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3613 /* Now modify the instruction as appropriate. To
3614 turn a leaq into a movq in the form we use it, it
3615 suffices to change the second byte from 0x8d to
3617 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3619 bfd_put_32 (output_bfd,
3620 htab->elf.sgot->output_section->vma
3621 + htab->elf.sgot->output_offset + off
3623 - input_section->output_section->vma
3624 - input_section->output_offset
3629 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3631 /* GDesc -> IE transition.
3638 bfd_put_8 (output_bfd, 0x66, contents + roff);
3639 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3647 case R_X86_64_TLSLD:
3648 if (! elf64_x86_64_tls_transition (info, input_bfd,
3649 input_section, contents,
3650 symtab_hdr, sym_hashes,
3651 &r_type, GOT_UNKNOWN,
3652 rel, relend, h, r_symndx))
3655 if (r_type != R_X86_64_TLSLD)
3657 /* LD->LE transition:
3658 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3660 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3662 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3663 memcpy (contents + rel->r_offset - 3,
3664 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3665 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3670 if (htab->elf.sgot == NULL)
3673 off = htab->tls_ld_got.offset;
3678 Elf_Internal_Rela outrel;
3680 if (htab->elf.srelgot == NULL)
3683 outrel.r_offset = (htab->elf.sgot->output_section->vma
3684 + htab->elf.sgot->output_offset + off);
3686 bfd_put_64 (output_bfd, 0,
3687 htab->elf.sgot->contents + off);
3688 bfd_put_64 (output_bfd, 0,
3689 htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
3690 outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64);
3691 outrel.r_addend = 0;
3692 elf64_x86_64_append_rela (output_bfd, htab->elf.srelgot,
3694 htab->tls_ld_got.offset |= 1;
3696 relocation = htab->elf.sgot->output_section->vma
3697 + htab->elf.sgot->output_offset + off;
3698 unresolved_reloc = FALSE;
3701 case R_X86_64_DTPOFF32:
3702 if (!info->executable|| (input_section->flags & SEC_CODE) == 0)
3703 relocation -= elf64_x86_64_dtpoff_base (info);
3705 relocation = elf64_x86_64_tpoff (info, relocation);
3708 case R_X86_64_TPOFF32:
3709 BFD_ASSERT (info->executable);
3710 relocation = elf64_x86_64_tpoff (info, relocation);
3717 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3718 because such sections are not SEC_ALLOC and thus ld.so will
3719 not process them. */
3720 if (unresolved_reloc
3721 && !((input_section->flags & SEC_DEBUGGING) != 0
3723 (*_bfd_error_handler)
3724 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3727 (long) rel->r_offset,
3729 h->root.root.string);
3732 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3733 contents, rel->r_offset,
3734 relocation, rel->r_addend);
3736 if (r != bfd_reloc_ok)
3741 name = h->root.root.string;
3744 name = bfd_elf_string_from_elf_section (input_bfd,
3745 symtab_hdr->sh_link,
3750 name = bfd_section_name (input_bfd, sec);
3753 if (r == bfd_reloc_overflow)
3755 if (! ((*info->callbacks->reloc_overflow)
3756 (info, (h ? &h->root : NULL), name, howto->name,
3757 (bfd_vma) 0, input_bfd, input_section,
3763 (*_bfd_error_handler)
3764 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3765 input_bfd, input_section,
3766 (long) rel->r_offset, name, (int) r);
3775 /* Finish up dynamic symbol handling. We set the contents of various
3776 dynamic sections here. */
3779 elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
3780 struct bfd_link_info *info,
3781 struct elf_link_hash_entry *h,
3782 Elf_Internal_Sym *sym)
3784 struct elf64_x86_64_link_hash_table *htab;
3786 htab = elf64_x86_64_hash_table (info);
3790 if (h->plt.offset != (bfd_vma) -1)
3794 Elf_Internal_Rela rela;
3796 asection *plt, *gotplt, *relplt;
3798 /* When building a static executable, use .iplt, .igot.plt and
3799 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3800 if (htab->elf.splt != NULL)
3802 plt = htab->elf.splt;
3803 gotplt = htab->elf.sgotplt;
3804 relplt = htab->elf.srelplt;
3808 plt = htab->elf.iplt;
3809 gotplt = htab->elf.igotplt;
3810 relplt = htab->elf.irelplt;
3813 /* This symbol has an entry in the procedure linkage table. Set
3815 if ((h->dynindx == -1
3816 && !((h->forced_local || info->executable)
3818 && h->type == STT_GNU_IFUNC))
3824 /* Get the index in the procedure linkage table which
3825 corresponds to this symbol. This is the index of this symbol
3826 in all the symbols for which we are making plt entries. The
3827 first entry in the procedure linkage table is reserved.
3829 Get the offset into the .got table of the entry that
3830 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3831 bytes. The first three are reserved for the dynamic linker.
3833 For static executables, we don't reserve anything. */
3835 if (plt == htab->elf.splt)
3837 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3838 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
3842 plt_index = h->plt.offset / PLT_ENTRY_SIZE;
3843 got_offset = plt_index * GOT_ENTRY_SIZE;
3846 /* Fill in the entry in the procedure linkage table. */
3847 memcpy (plt->contents + h->plt.offset, elf64_x86_64_plt_entry,
3850 /* Insert the relocation positions of the plt section. The magic
3851 numbers at the end of the statements are the positions of the
3852 relocations in the plt section. */
3853 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3854 instruction uses 6 bytes, subtract this value. */
3855 bfd_put_32 (output_bfd,
3856 (gotplt->output_section->vma
3857 + gotplt->output_offset
3859 - plt->output_section->vma
3860 - plt->output_offset
3863 plt->contents + h->plt.offset + 2);
3865 /* Don't fill PLT entry for static executables. */
3866 if (plt == htab->elf.splt)
3868 /* Put relocation index. */
3869 bfd_put_32 (output_bfd, plt_index,
3870 plt->contents + h->plt.offset + 7);
3871 /* Put offset for jmp .PLT0. */
3872 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
3873 plt->contents + h->plt.offset + 12);
3876 /* Fill in the entry in the global offset table, initially this
3877 points to the pushq instruction in the PLT which is at offset 6. */
3878 bfd_put_64 (output_bfd, (plt->output_section->vma
3879 + plt->output_offset
3880 + h->plt.offset + 6),
3881 gotplt->contents + got_offset);
3883 /* Fill in the entry in the .rela.plt section. */
3884 rela.r_offset = (gotplt->output_section->vma
3885 + gotplt->output_offset
3887 if (h->dynindx == -1
3888 || ((info->executable
3889 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3891 && h->type == STT_GNU_IFUNC))
3893 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3894 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
3895 rela.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE);
3896 rela.r_addend = (h->root.u.def.value
3897 + h->root.u.def.section->output_section->vma
3898 + h->root.u.def.section->output_offset);
3902 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
3905 loc = relplt->contents + plt_index * sizeof (Elf64_External_Rela);
3906 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3908 if (!h->def_regular)
3910 /* Mark the symbol as undefined, rather than as defined in
3911 the .plt section. Leave the value if there were any
3912 relocations where pointer equality matters (this is a clue
3913 for the dynamic linker, to make function pointer
3914 comparisons work between an application and shared
3915 library), otherwise set it to zero. If a function is only
3916 called from a binary, there is no need to slow down
3917 shared libraries because of that. */
3918 sym->st_shndx = SHN_UNDEF;
3919 if (!h->pointer_equality_needed)
3924 if (h->got.offset != (bfd_vma) -1
3925 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type)
3926 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
3928 Elf_Internal_Rela rela;
3930 /* This symbol has an entry in the global offset table. Set it
3932 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
3935 rela.r_offset = (htab->elf.sgot->output_section->vma
3936 + htab->elf.sgot->output_offset
3937 + (h->got.offset &~ (bfd_vma) 1));
3939 /* If this is a static link, or it is a -Bsymbolic link and the
3940 symbol is defined locally or was forced to be local because
3941 of a version file, we just want to emit a RELATIVE reloc.
3942 The entry in the global offset table will already have been
3943 initialized in the relocate_section function. */
3945 && h->type == STT_GNU_IFUNC)
3949 /* Generate R_X86_64_GLOB_DAT. */
3956 if (!h->pointer_equality_needed)
3959 /* For non-shared object, we can't use .got.plt, which
3960 contains the real function addres if we need pointer
3961 equality. We load the GOT entry with the PLT entry. */
3962 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
3963 bfd_put_64 (output_bfd, (plt->output_section->vma
3964 + plt->output_offset
3966 htab->elf.sgot->contents + h->got.offset);
3970 else if (info->shared
3971 && SYMBOL_REFERENCES_LOCAL (info, h))
3973 if (!h->def_regular)
3975 BFD_ASSERT((h->got.offset & 1) != 0);
3976 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3977 rela.r_addend = (h->root.u.def.value
3978 + h->root.u.def.section->output_section->vma
3979 + h->root.u.def.section->output_offset);
3983 BFD_ASSERT((h->got.offset & 1) == 0);
3985 bfd_put_64 (output_bfd, (bfd_vma) 0,
3986 htab->elf.sgot->contents + h->got.offset);
3987 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
3991 elf64_x86_64_append_rela (output_bfd, htab->elf.srelgot, &rela);
3996 Elf_Internal_Rela rela;
3998 /* This symbol needs a copy reloc. Set it up. */
4000 if (h->dynindx == -1
4001 || (h->root.type != bfd_link_hash_defined
4002 && h->root.type != bfd_link_hash_defweak)
4003 || htab->srelbss == NULL)
4006 rela.r_offset = (h->root.u.def.value
4007 + h->root.u.def.section->output_section->vma
4008 + h->root.u.def.section->output_offset);
4009 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
4011 elf64_x86_64_append_rela (output_bfd, htab->srelbss, &rela);
4014 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4015 be NULL for local symbols. */
4017 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
4018 || h == htab->elf.hgot))
4019 sym->st_shndx = SHN_ABS;
4024 /* Finish up local dynamic symbol handling. We set the contents of
4025 various dynamic sections here. */
4028 elf64_x86_64_finish_local_dynamic_symbol (void **slot, void *inf)
4030 struct elf_link_hash_entry *h
4031 = (struct elf_link_hash_entry *) *slot;
4032 struct bfd_link_info *info
4033 = (struct bfd_link_info *) inf;
4035 return elf64_x86_64_finish_dynamic_symbol (info->output_bfd,
4039 /* Used to decide how to sort relocs in an optimal manner for the
4040 dynamic linker, before writing them out. */
4042 static enum elf_reloc_type_class
4043 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
4045 switch ((int) ELF64_R_TYPE (rela->r_info))
4047 case R_X86_64_RELATIVE:
4048 return reloc_class_relative;
4049 case R_X86_64_JUMP_SLOT:
4050 return reloc_class_plt;
4052 return reloc_class_copy;
4054 return reloc_class_normal;
4058 /* Finish up the dynamic sections. */
4061 elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4063 struct elf64_x86_64_link_hash_table *htab;
4067 htab = elf64_x86_64_hash_table (info);
4071 dynobj = htab->elf.dynobj;
4072 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4074 if (htab->elf.dynamic_sections_created)
4076 Elf64_External_Dyn *dyncon, *dynconend;
4078 if (sdyn == NULL || htab->elf.sgot == NULL)
4081 dyncon = (Elf64_External_Dyn *) sdyn->contents;
4082 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
4083 for (; dyncon < dynconend; dyncon++)
4085 Elf_Internal_Dyn dyn;
4088 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
4096 s = htab->elf.sgotplt;
4097 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4101 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
4105 s = htab->elf.srelplt->output_section;
4106 dyn.d_un.d_val = s->size;
4110 /* The procedure linkage table relocs (DT_JMPREL) should
4111 not be included in the overall relocs (DT_RELA).
4112 Therefore, we override the DT_RELASZ entry here to
4113 make it not include the JMPREL relocs. Since the
4114 linker script arranges for .rela.plt to follow all
4115 other relocation sections, we don't have to worry
4116 about changing the DT_RELA entry. */
4117 if (htab->elf.srelplt != NULL)
4119 s = htab->elf.srelplt->output_section;
4120 dyn.d_un.d_val -= s->size;
4124 case DT_TLSDESC_PLT:
4126 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4127 + htab->tlsdesc_plt;
4130 case DT_TLSDESC_GOT:
4132 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
4133 + htab->tlsdesc_got;
4137 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
4140 /* Fill in the special first entry in the procedure linkage table. */
4141 if (htab->elf.splt && htab->elf.splt->size > 0)
4143 /* Fill in the first entry in the procedure linkage table. */
4144 memcpy (htab->elf.splt->contents, elf64_x86_64_plt0_entry,
4146 /* Add offset for pushq GOT+8(%rip), since the instruction
4147 uses 6 bytes subtract this value. */
4148 bfd_put_32 (output_bfd,
4149 (htab->elf.sgotplt->output_section->vma
4150 + htab->elf.sgotplt->output_offset
4152 - htab->elf.splt->output_section->vma
4153 - htab->elf.splt->output_offset
4155 htab->elf.splt->contents + 2);
4156 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4157 the end of the instruction. */
4158 bfd_put_32 (output_bfd,
4159 (htab->elf.sgotplt->output_section->vma
4160 + htab->elf.sgotplt->output_offset
4162 - htab->elf.splt->output_section->vma
4163 - htab->elf.splt->output_offset
4165 htab->elf.splt->contents + 8);
4167 elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize =
4170 if (htab->tlsdesc_plt)
4172 bfd_put_64 (output_bfd, (bfd_vma) 0,
4173 htab->elf.sgot->contents + htab->tlsdesc_got);
4175 memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
4176 elf64_x86_64_plt0_entry,
4179 /* Add offset for pushq GOT+8(%rip), since the
4180 instruction uses 6 bytes subtract this value. */
4181 bfd_put_32 (output_bfd,
4182 (htab->elf.sgotplt->output_section->vma
4183 + htab->elf.sgotplt->output_offset
4185 - htab->elf.splt->output_section->vma
4186 - htab->elf.splt->output_offset
4189 htab->elf.splt->contents + htab->tlsdesc_plt + 2);
4190 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4191 htab->tlsdesc_got. The 12 is the offset to the end of
4193 bfd_put_32 (output_bfd,
4194 (htab->elf.sgot->output_section->vma
4195 + htab->elf.sgot->output_offset
4197 - htab->elf.splt->output_section->vma
4198 - htab->elf.splt->output_offset
4201 htab->elf.splt->contents + htab->tlsdesc_plt + 8);
4206 if (htab->elf.sgotplt)
4208 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
4210 (*_bfd_error_handler)
4211 (_("discarded output section: `%A'"), htab->elf.sgotplt);
4215 /* Fill in the first three entries in the global offset table. */
4216 if (htab->elf.sgotplt->size > 0)
4218 /* Set the first entry in the global offset table to the address of
4219 the dynamic section. */
4221 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents);
4223 bfd_put_64 (output_bfd,
4224 sdyn->output_section->vma + sdyn->output_offset,
4225 htab->elf.sgotplt->contents);
4226 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4227 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
4228 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2);
4231 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
4235 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4236 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
4239 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4240 htab_traverse (htab->loc_hash_table,
4241 elf64_x86_64_finish_local_dynamic_symbol,
4247 /* Return address for Ith PLT stub in section PLT, for relocation REL
4248 or (bfd_vma) -1 if it should not be included. */
4251 elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
4252 const arelent *rel ATTRIBUTE_UNUSED)
4254 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
4257 /* Handle an x86-64 specific section when reading an object file. This
4258 is called when elfcode.h finds a section with an unknown type. */
4261 elf64_x86_64_section_from_shdr (bfd *abfd,
4262 Elf_Internal_Shdr *hdr,
4266 if (hdr->sh_type != SHT_X86_64_UNWIND)
4269 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
4275 /* Hook called by the linker routine which adds symbols from an object
4276 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4280 elf64_x86_64_add_symbol_hook (bfd *abfd,
4281 struct bfd_link_info *info,
4282 Elf_Internal_Sym *sym,
4283 const char **namep ATTRIBUTE_UNUSED,
4284 flagword *flagsp ATTRIBUTE_UNUSED,
4290 switch (sym->st_shndx)
4292 case SHN_X86_64_LCOMMON:
4293 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
4296 lcomm = bfd_make_section_with_flags (abfd,
4300 | SEC_LINKER_CREATED));
4303 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
4306 *valp = sym->st_size;
4310 if ((abfd->flags & DYNAMIC) == 0
4311 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
4312 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
4313 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4319 /* Given a BFD section, try to locate the corresponding ELF section
4323 elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4324 asection *sec, int *index_return)
4326 if (sec == &_bfd_elf_large_com_section)
4328 *index_return = SHN_X86_64_LCOMMON;
4334 /* Process a symbol. */
4337 elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
4340 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
4342 switch (elfsym->internal_elf_sym.st_shndx)
4344 case SHN_X86_64_LCOMMON:
4345 asym->section = &_bfd_elf_large_com_section;
4346 asym->value = elfsym->internal_elf_sym.st_size;
4347 /* Common symbol doesn't set BSF_GLOBAL. */
4348 asym->flags &= ~BSF_GLOBAL;
4354 elf64_x86_64_common_definition (Elf_Internal_Sym *sym)
4356 return (sym->st_shndx == SHN_COMMON
4357 || sym->st_shndx == SHN_X86_64_LCOMMON);
4361 elf64_x86_64_common_section_index (asection *sec)
4363 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4366 return SHN_X86_64_LCOMMON;
4370 elf64_x86_64_common_section (asection *sec)
4372 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
4373 return bfd_com_section_ptr;
4375 return &_bfd_elf_large_com_section;
4379 elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4380 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
4381 struct elf_link_hash_entry *h,
4382 Elf_Internal_Sym *sym,
4384 bfd_vma *pvalue ATTRIBUTE_UNUSED,
4385 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
4386 bfd_boolean *skip ATTRIBUTE_UNUSED,
4387 bfd_boolean *override ATTRIBUTE_UNUSED,
4388 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
4389 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
4390 bfd_boolean *newdef ATTRIBUTE_UNUSED,
4391 bfd_boolean *newdyn,
4392 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
4393 bfd_boolean *newweak ATTRIBUTE_UNUSED,
4394 bfd *abfd ATTRIBUTE_UNUSED,
4396 bfd_boolean *olddef ATTRIBUTE_UNUSED,
4397 bfd_boolean *olddyn,
4398 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
4399 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
4403 /* A normal common symbol and a large common symbol result in a
4404 normal common symbol. We turn the large common symbol into a
4407 && h->root.type == bfd_link_hash_common
4409 && bfd_is_com_section (*sec)
4412 if (sym->st_shndx == SHN_COMMON
4413 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
4415 h->root.u.c.p->section
4416 = bfd_make_section_old_way (oldbfd, "COMMON");
4417 h->root.u.c.p->section->flags = SEC_ALLOC;
4419 else if (sym->st_shndx == SHN_X86_64_LCOMMON
4420 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
4421 *psec = *sec = bfd_com_section_ptr;
4428 elf64_x86_64_additional_program_headers (bfd *abfd,
4429 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4434 /* Check to see if we need a large readonly segment. */
4435 s = bfd_get_section_by_name (abfd, ".lrodata");
4436 if (s && (s->flags & SEC_LOAD))
4439 /* Check to see if we need a large data segment. Since .lbss sections
4440 is placed right after the .bss section, there should be no need for
4441 a large data segment just because of .lbss. */
4442 s = bfd_get_section_by_name (abfd, ".ldata");
4443 if (s && (s->flags & SEC_LOAD))
4449 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4452 elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h)
4454 if (h->plt.offset != (bfd_vma) -1
4456 && !h->pointer_equality_needed)
4459 return _bfd_elf_hash_symbol (h);
4462 static const struct bfd_elf_special_section
4463 elf64_x86_64_special_sections[]=
4465 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4466 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4467 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
4468 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4469 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
4470 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
4471 { NULL, 0, 0, 0, 0 }
4474 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4475 #define TARGET_LITTLE_NAME "elf64-x86-64"
4476 #define ELF_ARCH bfd_arch_i386
4477 #define ELF_TARGET_ID X86_64_ELF_DATA
4478 #define ELF_MACHINE_CODE EM_X86_64
4479 #define ELF_MAXPAGESIZE 0x200000
4480 #define ELF_MINPAGESIZE 0x1000
4481 #define ELF_COMMONPAGESIZE 0x1000
4483 #define elf_backend_can_gc_sections 1
4484 #define elf_backend_can_refcount 1
4485 #define elf_backend_want_got_plt 1
4486 #define elf_backend_plt_readonly 1
4487 #define elf_backend_want_plt_sym 0
4488 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4489 #define elf_backend_rela_normal 1
4491 #define elf_info_to_howto elf64_x86_64_info_to_howto
4493 #define bfd_elf64_bfd_link_hash_table_create \
4494 elf64_x86_64_link_hash_table_create
4495 #define bfd_elf64_bfd_link_hash_table_free \
4496 elf64_x86_64_link_hash_table_free
4497 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
4498 #define bfd_elf64_bfd_reloc_name_lookup \
4499 elf64_x86_64_reloc_name_lookup
4501 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
4502 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4503 #define elf_backend_check_relocs elf64_x86_64_check_relocs
4504 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
4505 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
4506 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
4507 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
4508 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
4509 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
4510 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
4511 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
4512 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
4513 #define elf_backend_relocate_section elf64_x86_64_relocate_section
4514 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
4515 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
4516 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4517 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
4518 #define elf_backend_object_p elf64_x86_64_elf_object_p
4519 #define bfd_elf64_mkobject elf64_x86_64_mkobject
4521 #define elf_backend_section_from_shdr \
4522 elf64_x86_64_section_from_shdr
4524 #define elf_backend_section_from_bfd_section \
4525 elf64_x86_64_elf_section_from_bfd_section
4526 #define elf_backend_add_symbol_hook \
4527 elf64_x86_64_add_symbol_hook
4528 #define elf_backend_symbol_processing \
4529 elf64_x86_64_symbol_processing
4530 #define elf_backend_common_section_index \
4531 elf64_x86_64_common_section_index
4532 #define elf_backend_common_section \
4533 elf64_x86_64_common_section
4534 #define elf_backend_common_definition \
4535 elf64_x86_64_common_definition
4536 #define elf_backend_merge_symbol \
4537 elf64_x86_64_merge_symbol
4538 #define elf_backend_special_sections \
4539 elf64_x86_64_special_sections
4540 #define elf_backend_additional_program_headers \
4541 elf64_x86_64_additional_program_headers
4542 #define elf_backend_hash_symbol \
4543 elf64_x86_64_hash_symbol
4545 #undef elf_backend_post_process_headers
4546 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4548 #include "elf64-target.h"
4550 /* FreeBSD support. */
4552 #undef TARGET_LITTLE_SYM
4553 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4554 #undef TARGET_LITTLE_NAME
4555 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4558 #define ELF_OSABI ELFOSABI_FREEBSD
4561 #define elf64_bed elf64_x86_64_fbsd_bed
4563 #include "elf64-target.h"
4565 /* Solaris 2 support. */
4567 #undef TARGET_LITTLE_SYM
4568 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4569 #undef TARGET_LITTLE_NAME
4570 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4572 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4573 objects won't be recognized. */
4577 #define elf64_bed elf64_x86_64_sol2_bed
4579 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
4581 #undef elf_backend_static_tls_alignment
4582 #define elf_backend_static_tls_alignment 16
4584 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4586 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4588 #undef elf_backend_want_plt_sym
4589 #define elf_backend_want_plt_sym 1
4591 #include "elf64-target.h"
4593 /* Intel L1OM support. */
4596 elf64_l1om_elf_object_p (bfd *abfd)
4598 /* Set the right machine number for an L1OM elf64 file. */
4599 bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
4603 #undef TARGET_LITTLE_SYM
4604 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
4605 #undef TARGET_LITTLE_NAME
4606 #define TARGET_LITTLE_NAME "elf64-l1om"
4608 #define ELF_ARCH bfd_arch_l1om
4610 #undef ELF_MACHINE_CODE
4611 #define ELF_MACHINE_CODE EM_L1OM
4616 #define elf64_bed elf64_l1om_bed
4618 #undef elf_backend_object_p
4619 #define elf_backend_object_p elf64_l1om_elf_object_p
4621 #undef elf_backend_post_process_headers
4622 #undef elf_backend_static_tls_alignment
4624 #include "elf64-target.h"
4626 /* FreeBSD L1OM support. */
4628 #undef TARGET_LITTLE_SYM
4629 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
4630 #undef TARGET_LITTLE_NAME
4631 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
4634 #define ELF_OSABI ELFOSABI_FREEBSD
4637 #define elf64_bed elf64_l1om_fbsd_bed
4639 #undef elf_backend_post_process_headers
4640 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4642 #include "elf64-target.h"