1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
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"
30 #include "elf/x86-64.h"
32 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
33 #define MINUS_ONE (~ (bfd_vma) 0)
35 /* The relocation "howto" table. Order of fields:
36 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
37 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
38 static reloc_howto_type x86_64_elf_howto_table[] =
40 HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
41 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
43 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
44 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,
46 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
47 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,
49 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
50 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,
52 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
53 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,
55 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
56 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,
58 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
59 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,
61 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
62 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,
64 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
65 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,
67 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,
68 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,
70 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,
71 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,
74 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
77 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE),
78 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,
79 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE),
80 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
81 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE),
82 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,
83 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE),
84 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
85 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,
87 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
88 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,
90 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
91 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,
93 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
94 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,
96 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,
97 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,
99 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
100 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,
102 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,
103 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,
105 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,
106 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,
108 HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
109 bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,
111 HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
112 bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",
113 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
114 HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,
115 bfd_elf_generic_reloc, "R_X86_64_GOTPC32",
116 FALSE, 0xffffffff, 0xffffffff, TRUE),
117 HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
118 bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,
120 HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
121 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,
123 HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,
124 bfd_elf_generic_reloc, "R_X86_64_GOTPC64",
125 FALSE, MINUS_ONE, MINUS_ONE, TRUE),
126 HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
127 bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,
129 HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,
130 bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,
134 HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,
135 complain_overflow_bitfield, bfd_elf_generic_reloc,
136 "R_X86_64_GOTPC32_TLSDESC",
137 FALSE, 0xffffffff, 0xffffffff, TRUE),
138 HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,
139 complain_overflow_dont, bfd_elf_generic_reloc,
140 "R_X86_64_TLSDESC_CALL",
142 HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,
143 complain_overflow_bitfield, bfd_elf_generic_reloc,
145 FALSE, MINUS_ONE, MINUS_ONE, FALSE),
147 /* We have a gap in the reloc numbers here.
148 R_X86_64_standard counts the number up to this point, and
149 R_X86_64_vt_offset is the value to subtract from a reloc type of
150 R_X86_64_GNU_VT* to form an index into this table. */
151 #define R_X86_64_standard (R_X86_64_TLSDESC + 1)
152 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
154 /* GNU extension to record C++ vtable hierarchy. */
155 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,
156 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE),
158 /* GNU extension to record C++ vtable member usage. */
159 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,
160 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,
164 #define IS_X86_64_PCREL_TYPE(TYPE) \
165 ( ((TYPE) == R_X86_64_PC8) \
166 || ((TYPE) == R_X86_64_PC16) \
167 || ((TYPE) == R_X86_64_PC32) \
168 || ((TYPE) == R_X86_64_PC64))
170 /* Map BFD relocs to the x86_64 elf relocs. */
173 bfd_reloc_code_real_type bfd_reloc_val;
174 unsigned char elf_reloc_val;
177 static const struct elf_reloc_map x86_64_reloc_map[] =
179 { BFD_RELOC_NONE, R_X86_64_NONE, },
180 { BFD_RELOC_64, R_X86_64_64, },
181 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
182 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
183 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
184 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
185 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
186 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
187 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
188 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
189 { BFD_RELOC_32, R_X86_64_32, },
190 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
191 { BFD_RELOC_16, R_X86_64_16, },
192 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
193 { BFD_RELOC_8, R_X86_64_8, },
194 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
195 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, },
196 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, },
197 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, },
198 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, },
199 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, },
200 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, },
201 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, },
202 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, },
203 { BFD_RELOC_64_PCREL, R_X86_64_PC64, },
204 { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, },
205 { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, },
206 { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, },
207 { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, },
208 { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, },
209 { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, },
210 { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, },
211 { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, },
212 { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, },
213 { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, },
214 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
215 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
218 static reloc_howto_type *
219 elf64_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type)
223 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT
224 || r_type >= (unsigned int) R_X86_64_max)
226 if (r_type >= (unsigned int) R_X86_64_standard)
228 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
230 r_type = R_X86_64_NONE;
235 i = r_type - (unsigned int) R_X86_64_vt_offset;
236 BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type);
237 return &x86_64_elf_howto_table[i];
240 /* Given a BFD reloc type, return a HOWTO structure. */
241 static reloc_howto_type *
242 elf64_x86_64_reloc_type_lookup (bfd *abfd,
243 bfd_reloc_code_real_type code)
247 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
250 if (x86_64_reloc_map[i].bfd_reloc_val == code)
251 return elf64_x86_64_rtype_to_howto (abfd,
252 x86_64_reloc_map[i].elf_reloc_val);
257 static reloc_howto_type *
258 elf64_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
264 i < (sizeof (x86_64_elf_howto_table)
265 / sizeof (x86_64_elf_howto_table[0]));
267 if (x86_64_elf_howto_table[i].name != NULL
268 && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0)
269 return &x86_64_elf_howto_table[i];
274 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
277 elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
278 Elf_Internal_Rela *dst)
282 r_type = ELF64_R_TYPE (dst->r_info);
283 cache_ptr->howto = elf64_x86_64_rtype_to_howto (abfd, r_type);
284 BFD_ASSERT (r_type == cache_ptr->howto->type);
287 /* Support for core dump NOTE sections. */
289 elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
294 switch (note->descsz)
299 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
301 elf_tdata (abfd)->core_signal
302 = bfd_get_16 (abfd, note->descdata + 12);
305 elf_tdata (abfd)->core_pid
306 = bfd_get_32 (abfd, note->descdata + 32);
315 /* Make a ".reg/999" section. */
316 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
317 size, note->descpos + offset);
321 elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
323 switch (note->descsz)
328 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
329 elf_tdata (abfd)->core_program
330 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
331 elf_tdata (abfd)->core_command
332 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
335 /* Note that for some reason, a spurious space is tacked
336 onto the end of the args in some (at least one anyway)
337 implementations, so strip it off if it exists. */
340 char *command = elf_tdata (abfd)->core_command;
341 int n = strlen (command);
343 if (0 < n && command[n - 1] == ' ')
344 command[n - 1] = '\0';
350 /* Functions for the x86-64 ELF linker. */
352 /* The name of the dynamic interpreter. This is put in the .interp
355 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
357 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
358 copying dynamic variables from a shared lib into an app's dynbss
359 section, and instead use a dynamic relocation to point into the
361 #define ELIMINATE_COPY_RELOCS 1
363 /* The size in bytes of an entry in the global offset table. */
365 #define GOT_ENTRY_SIZE 8
367 /* The size in bytes of an entry in the procedure linkage table. */
369 #define PLT_ENTRY_SIZE 16
371 /* The first entry in a procedure linkage table looks like this. See the
372 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
374 static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
376 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
377 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
378 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
381 /* Subsequent entries in a procedure linkage table look like this. */
383 static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
385 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
386 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
387 0x68, /* pushq immediate */
388 0, 0, 0, 0, /* replaced with index into relocation table. */
389 0xe9, /* jmp relative */
390 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
393 /* The x86-64 linker needs to keep track of the number of relocs that
394 it decides to copy as dynamic relocs in check_relocs for each symbol.
395 This is so that it can later discard them if they are found to be
396 unnecessary. We store the information in a field extending the
397 regular ELF linker hash table. */
399 struct elf64_x86_64_dyn_relocs
402 struct elf64_x86_64_dyn_relocs *next;
404 /* The input section of the reloc. */
407 /* Total number of relocs copied for the input section. */
410 /* Number of pc-relative relocs copied for the input section. */
411 bfd_size_type pc_count;
414 /* x86-64 ELF linker hash entry. */
416 struct elf64_x86_64_link_hash_entry
418 struct elf_link_hash_entry elf;
420 /* Track dynamic relocs copied for this symbol. */
421 struct elf64_x86_64_dyn_relocs *dyn_relocs;
423 #define GOT_UNKNOWN 0
427 #define GOT_TLS_GDESC 4
428 #define GOT_TLS_GD_BOTH_P(type) \
429 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
430 #define GOT_TLS_GD_P(type) \
431 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
432 #define GOT_TLS_GDESC_P(type) \
433 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
434 #define GOT_TLS_GD_ANY_P(type) \
435 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
436 unsigned char tls_type;
438 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
439 starting at the end of the jump table. */
443 #define elf64_x86_64_hash_entry(ent) \
444 ((struct elf64_x86_64_link_hash_entry *)(ent))
446 struct elf64_x86_64_obj_tdata
448 struct elf_obj_tdata root;
450 /* tls_type for each local got entry. */
451 char *local_got_tls_type;
453 /* GOTPLT entries for TLS descriptors. */
454 bfd_vma *local_tlsdesc_gotent;
457 #define elf64_x86_64_tdata(abfd) \
458 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
460 #define elf64_x86_64_local_got_tls_type(abfd) \
461 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
463 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
464 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
466 #define is_x86_64_elf(bfd) \
467 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
468 && elf_tdata (bfd) != NULL \
469 && elf_object_id (bfd) == X86_64_ELF_TDATA)
472 elf64_x86_64_mkobject (bfd *abfd)
474 return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata),
478 /* x86-64 ELF linker hash table. */
480 struct elf64_x86_64_link_hash_table
482 struct elf_link_hash_table elf;
484 /* Short-cuts to get to dynamic linker sections. */
493 /* The offset into splt of the PLT entry for the TLS descriptor
494 resolver. Special values are 0, if not necessary (or not found
495 to be necessary yet), and -1 if needed but not determined
498 /* The offset into sgot of the GOT entry used by the PLT entry
503 bfd_signed_vma refcount;
507 /* The amount of space used by the jump slots in the GOT. */
508 bfd_vma sgotplt_jump_table_size;
510 /* Small local sym to section mapping cache. */
511 struct sym_sec_cache sym_sec;
513 /* _TLS_MODULE_BASE_ symbol. */
514 struct bfd_link_hash_entry *tls_module_base;
517 /* Get the x86-64 ELF linker hash table from a link_info structure. */
519 #define elf64_x86_64_hash_table(p) \
520 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
522 #define elf64_x86_64_compute_jump_table_size(htab) \
523 ((htab)->srelplt->reloc_count * GOT_ENTRY_SIZE)
525 /* Create an entry in an x86-64 ELF linker hash table. */
527 static struct bfd_hash_entry *
528 link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
531 /* Allocate the structure if it has not already been allocated by a
535 entry = bfd_hash_allocate (table,
536 sizeof (struct elf64_x86_64_link_hash_entry));
541 /* Call the allocation method of the superclass. */
542 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
545 struct elf64_x86_64_link_hash_entry *eh;
547 eh = (struct elf64_x86_64_link_hash_entry *) entry;
548 eh->dyn_relocs = NULL;
549 eh->tls_type = GOT_UNKNOWN;
550 eh->tlsdesc_got = (bfd_vma) -1;
556 /* Create an X86-64 ELF linker hash table. */
558 static struct bfd_link_hash_table *
559 elf64_x86_64_link_hash_table_create (bfd *abfd)
561 struct elf64_x86_64_link_hash_table *ret;
562 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
564 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
568 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
569 sizeof (struct elf64_x86_64_link_hash_entry)))
582 ret->sym_sec.abfd = NULL;
583 ret->tlsdesc_plt = 0;
584 ret->tlsdesc_got = 0;
585 ret->tls_ld_got.refcount = 0;
586 ret->sgotplt_jump_table_size = 0;
587 ret->tls_module_base = NULL;
589 return &ret->elf.root;
592 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
593 shortcuts to them in our hash table. */
596 create_got_section (bfd *dynobj, struct bfd_link_info *info)
598 struct elf64_x86_64_link_hash_table *htab;
600 if (! _bfd_elf_create_got_section (dynobj, info))
603 htab = elf64_x86_64_hash_table (info);
604 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
605 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
606 if (!htab->sgot || !htab->sgotplt)
609 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got",
610 (SEC_ALLOC | SEC_LOAD
615 if (htab->srelgot == NULL
616 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
621 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
622 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
626 elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
628 struct elf64_x86_64_link_hash_table *htab;
630 htab = elf64_x86_64_hash_table (info);
631 if (!htab->sgot && !create_got_section (dynobj, info))
634 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
637 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
638 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
639 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
641 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
643 if (!htab->splt || !htab->srelplt || !htab->sdynbss
644 || (!info->shared && !htab->srelbss))
650 /* Copy the extra info we tack onto an elf_link_hash_entry. */
653 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
654 struct elf_link_hash_entry *dir,
655 struct elf_link_hash_entry *ind)
657 struct elf64_x86_64_link_hash_entry *edir, *eind;
659 edir = (struct elf64_x86_64_link_hash_entry *) dir;
660 eind = (struct elf64_x86_64_link_hash_entry *) ind;
662 if (eind->dyn_relocs != NULL)
664 if (edir->dyn_relocs != NULL)
666 struct elf64_x86_64_dyn_relocs **pp;
667 struct elf64_x86_64_dyn_relocs *p;
669 /* Add reloc counts against the indirect sym to the direct sym
670 list. Merge any entries against the same section. */
671 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
673 struct elf64_x86_64_dyn_relocs *q;
675 for (q = edir->dyn_relocs; q != NULL; q = q->next)
676 if (q->sec == p->sec)
678 q->pc_count += p->pc_count;
679 q->count += p->count;
686 *pp = edir->dyn_relocs;
689 edir->dyn_relocs = eind->dyn_relocs;
690 eind->dyn_relocs = NULL;
693 if (ind->root.type == bfd_link_hash_indirect
694 && dir->got.refcount <= 0)
696 edir->tls_type = eind->tls_type;
697 eind->tls_type = GOT_UNKNOWN;
700 if (ELIMINATE_COPY_RELOCS
701 && ind->root.type != bfd_link_hash_indirect
702 && dir->dynamic_adjusted)
704 /* If called to transfer flags for a weakdef during processing
705 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
706 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
707 dir->ref_dynamic |= ind->ref_dynamic;
708 dir->ref_regular |= ind->ref_regular;
709 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
710 dir->needs_plt |= ind->needs_plt;
711 dir->pointer_equality_needed |= ind->pointer_equality_needed;
714 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
718 elf64_x86_64_elf_object_p (bfd *abfd)
720 /* Set the right machine number for an x86-64 elf64 file. */
721 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
739 /* Return TRUE if the TLS access code sequence support transition
743 elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec,
745 Elf_Internal_Shdr *symtab_hdr,
746 struct elf_link_hash_entry **sym_hashes,
748 const Elf_Internal_Rela *rel,
749 const Elf_Internal_Rela *relend)
752 unsigned long r_symndx;
753 struct elf_link_hash_entry *h;
756 /* Get the section contents. */
757 if (contents == NULL)
759 if (elf_section_data (sec)->this_hdr.contents != NULL)
760 contents = elf_section_data (sec)->this_hdr.contents;
763 /* FIXME: How to better handle error condition? */
764 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
767 /* Cache the section contents for elf_link_input_bfd. */
768 elf_section_data (sec)->this_hdr.contents = contents;
772 offset = rel->r_offset;
777 if ((rel + 1) >= relend)
780 if (r_type == R_X86_64_TLSGD)
782 /* Check transition from GD access model. Only
783 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
784 .word 0x6666; rex64; call __tls_get_addr
785 can transit to different access model. */
787 static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } },
788 call = { { 0x66, 0x66, 0x48, 0xe8 } };
790 || (offset + 12) > sec->size
791 || bfd_get_32 (abfd, contents + offset - 4) != leaq.i
792 || bfd_get_32 (abfd, contents + offset + 4) != call.i)
797 /* Check transition from LD access model. Only
798 leaq foo@tlsld(%rip), %rdi;
800 can transit to different access model. */
802 static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
805 if (offset < 3 || (offset + 9) > sec->size)
808 op.i = bfd_get_32 (abfd, contents + offset - 3);
809 op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
814 r_symndx = ELF64_R_SYM (rel[1].r_info);
815 if (r_symndx < symtab_hdr->sh_info)
818 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
819 /* Use strncmp to check __tls_get_addr since __tls_get_addr
822 && h->root.root.string != NULL
823 && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32
824 || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
825 && (strncmp (h->root.root.string,
826 "__tls_get_addr", 14) == 0));
828 case R_X86_64_GOTTPOFF:
829 /* Check transition from IE access model:
830 movq foo@gottpoff(%rip), %reg
831 addq foo@gottpoff(%rip), %reg
834 if (offset < 3 || (offset + 4) > sec->size)
837 val = bfd_get_8 (abfd, contents + offset - 3);
838 if (val != 0x48 && val != 0x4c)
841 val = bfd_get_8 (abfd, contents + offset - 2);
842 if (val != 0x8b && val != 0x03)
845 val = bfd_get_8 (abfd, contents + offset - 1);
846 return (val & 0xc7) == 5;
848 case R_X86_64_GOTPC32_TLSDESC:
849 /* Check transition from GDesc access model:
850 leaq x@tlsdesc(%rip), %rax
852 Make sure it's a leaq adding rip to a 32-bit offset
853 into any register, although it's probably almost always
856 if (offset < 3 || (offset + 4) > sec->size)
859 val = bfd_get_8 (abfd, contents + offset - 3);
860 if ((val & 0xfb) != 0x48)
863 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
866 val = bfd_get_8 (abfd, contents + offset - 1);
867 return (val & 0xc7) == 0x05;
869 case R_X86_64_TLSDESC_CALL:
870 /* Check transition from GDesc access model:
871 call *x@tlsdesc(%rax)
873 if (offset + 2 <= sec->size)
875 /* Make sure that it's a call *x@tlsdesc(%rax). */
876 static x86_64_opcode16 call = { { 0xff, 0x10 } };
877 return bfd_get_16 (abfd, contents + offset) == call.i;
887 /* Return TRUE if the TLS access transition is OK or no transition
888 will be performed. Update R_TYPE if there is a transition. */
891 elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
892 asection *sec, bfd_byte *contents,
893 Elf_Internal_Shdr *symtab_hdr,
894 struct elf_link_hash_entry **sym_hashes,
895 unsigned int *r_type, int tls_type,
896 const Elf_Internal_Rela *rel,
897 const Elf_Internal_Rela *relend,
898 struct elf_link_hash_entry *h)
900 unsigned int from_type = *r_type;
901 unsigned int to_type = from_type;
902 bfd_boolean check = TRUE;
907 case R_X86_64_GOTPC32_TLSDESC:
908 case R_X86_64_TLSDESC_CALL:
909 case R_X86_64_GOTTPOFF:
913 to_type = R_X86_64_TPOFF32;
915 to_type = R_X86_64_GOTTPOFF;
918 /* When we are called from elf64_x86_64_relocate_section,
919 CONTENTS isn't NULL and there may be additional transitions
920 based on TLS_TYPE. */
921 if (contents != NULL)
923 unsigned int new_to_type = to_type;
928 && tls_type == GOT_TLS_IE)
929 new_to_type = R_X86_64_TPOFF32;
931 if (to_type == R_X86_64_TLSGD
932 || to_type == R_X86_64_GOTPC32_TLSDESC
933 || to_type == R_X86_64_TLSDESC_CALL)
935 if (tls_type == GOT_TLS_IE)
936 new_to_type = R_X86_64_GOTTPOFF;
939 /* We checked the transition before when we were called from
940 elf64_x86_64_check_relocs. We only want to check the new
941 transition which hasn't been checked before. */
942 check = new_to_type != to_type && from_type == to_type;
943 to_type = new_to_type;
950 to_type = R_X86_64_TPOFF32;
957 /* Return TRUE if there is no transition. */
958 if (from_type == to_type)
961 /* Check if the transition can be performed. */
963 && ! elf64_x86_64_check_tls_transition (abfd, sec, contents,
964 symtab_hdr, sym_hashes,
965 from_type, rel, relend))
967 reloc_howto_type *from, *to;
969 from = elf64_x86_64_rtype_to_howto (abfd, from_type);
970 to = elf64_x86_64_rtype_to_howto (abfd, to_type);
972 (*_bfd_error_handler)
973 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
974 "in section `%A' failed"),
975 abfd, sec, from->name, to->name,
976 h ? h->root.root.string : "a local symbol",
977 (unsigned long) rel->r_offset);
978 bfd_set_error (bfd_error_bad_value);
986 /* Returns true if the hash entry refers to a symbol
987 marked for indirect handling during reloc processing. */
990 is_indirect_symbol (bfd * abfd, struct elf_link_hash_entry * h)
992 const struct elf_backend_data * bed;
994 if (abfd == NULL || h == NULL)
997 bed = get_elf_backend_data (abfd);
999 return h->type == STT_GNU_IFUNC
1000 && (bed->elf_osabi == ELFOSABI_LINUX
1001 /* GNU/Linux is still using the default value 0. */
1002 || bed->elf_osabi == ELFOSABI_NONE);
1005 /* Look through the relocs for a section during the first phase, and
1006 calculate needed space in the global offset table, procedure
1007 linkage table, and dynamic reloc sections. */
1010 elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1012 const Elf_Internal_Rela *relocs)
1014 struct elf64_x86_64_link_hash_table *htab;
1015 Elf_Internal_Shdr *symtab_hdr;
1016 struct elf_link_hash_entry **sym_hashes;
1017 const Elf_Internal_Rela *rel;
1018 const Elf_Internal_Rela *rel_end;
1021 if (info->relocatable)
1024 BFD_ASSERT (is_x86_64_elf (abfd));
1026 htab = elf64_x86_64_hash_table (info);
1027 symtab_hdr = &elf_symtab_hdr (abfd);
1028 sym_hashes = elf_sym_hashes (abfd);
1032 rel_end = relocs + sec->reloc_count;
1033 for (rel = relocs; rel < rel_end; rel++)
1035 unsigned int r_type;
1036 unsigned long r_symndx;
1037 struct elf_link_hash_entry *h;
1039 r_symndx = ELF64_R_SYM (rel->r_info);
1040 r_type = ELF64_R_TYPE (rel->r_info);
1042 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1044 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1049 if (r_symndx < symtab_hdr->sh_info)
1053 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1054 while (h->root.type == bfd_link_hash_indirect
1055 || h->root.type == bfd_link_hash_warning)
1056 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1059 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1060 symtab_hdr, sym_hashes,
1061 &r_type, GOT_UNKNOWN,
1067 case R_X86_64_TLSLD:
1068 htab->tls_ld_got.refcount += 1;
1071 case R_X86_64_TPOFF32:
1074 (*_bfd_error_handler)
1075 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1077 x86_64_elf_howto_table[r_type].name,
1078 (h) ? h->root.root.string : "a local symbol");
1079 bfd_set_error (bfd_error_bad_value);
1084 case R_X86_64_GOTTPOFF:
1086 info->flags |= DF_STATIC_TLS;
1089 case R_X86_64_GOT32:
1090 case R_X86_64_GOTPCREL:
1091 case R_X86_64_TLSGD:
1092 case R_X86_64_GOT64:
1093 case R_X86_64_GOTPCREL64:
1094 case R_X86_64_GOTPLT64:
1095 case R_X86_64_GOTPC32_TLSDESC:
1096 case R_X86_64_TLSDESC_CALL:
1097 /* This symbol requires a global offset table entry. */
1099 int tls_type, old_tls_type;
1103 default: tls_type = GOT_NORMAL; break;
1104 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1105 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1106 case R_X86_64_GOTPC32_TLSDESC:
1107 case R_X86_64_TLSDESC_CALL:
1108 tls_type = GOT_TLS_GDESC; break;
1113 if (r_type == R_X86_64_GOTPLT64)
1115 /* This relocation indicates that we also need
1116 a PLT entry, as this is a function. We don't need
1117 a PLT entry for local symbols. */
1119 h->plt.refcount += 1;
1121 h->got.refcount += 1;
1122 old_tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1126 bfd_signed_vma *local_got_refcounts;
1128 /* This is a global offset table entry for a local symbol. */
1129 local_got_refcounts = elf_local_got_refcounts (abfd);
1130 if (local_got_refcounts == NULL)
1134 size = symtab_hdr->sh_info;
1135 size *= sizeof (bfd_signed_vma)
1136 + sizeof (bfd_vma) + sizeof (char);
1137 local_got_refcounts = ((bfd_signed_vma *)
1138 bfd_zalloc (abfd, size));
1139 if (local_got_refcounts == NULL)
1141 elf_local_got_refcounts (abfd) = local_got_refcounts;
1142 elf64_x86_64_local_tlsdesc_gotent (abfd)
1143 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1144 elf64_x86_64_local_got_tls_type (abfd)
1145 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1147 local_got_refcounts[r_symndx] += 1;
1149 = elf64_x86_64_local_got_tls_type (abfd) [r_symndx];
1152 /* If a TLS symbol is accessed using IE at least once,
1153 there is no point to use dynamic model for it. */
1154 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1155 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1156 || tls_type != GOT_TLS_IE))
1158 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1159 tls_type = old_tls_type;
1160 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1161 && GOT_TLS_GD_ANY_P (tls_type))
1162 tls_type |= old_tls_type;
1165 (*_bfd_error_handler)
1166 (_("%B: '%s' accessed both as normal and thread local symbol"),
1167 abfd, h ? h->root.root.string : "<local>");
1172 if (old_tls_type != tls_type)
1175 elf64_x86_64_hash_entry (h)->tls_type = tls_type;
1177 elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1182 case R_X86_64_GOTOFF64:
1183 case R_X86_64_GOTPC32:
1184 case R_X86_64_GOTPC64:
1186 if (htab->sgot == NULL)
1188 if (htab->elf.dynobj == NULL)
1189 htab->elf.dynobj = abfd;
1190 if (!create_got_section (htab->elf.dynobj, info))
1195 case R_X86_64_PLT32:
1196 /* This symbol requires a procedure linkage table entry. We
1197 actually build the entry in adjust_dynamic_symbol,
1198 because this might be a case of linking PIC code which is
1199 never referenced by a dynamic object, in which case we
1200 don't need to generate a procedure linkage table entry
1203 /* If this is a local symbol, we resolve it directly without
1204 creating a procedure linkage table entry. */
1209 h->plt.refcount += 1;
1212 case R_X86_64_PLTOFF64:
1213 /* This tries to form the 'address' of a function relative
1214 to GOT. For global symbols we need a PLT entry. */
1218 h->plt.refcount += 1;
1226 /* Let's help debug shared library creation. These relocs
1227 cannot be used in shared libs. Don't error out for
1228 sections we don't care about, such as debug sections or
1229 non-constant sections. */
1231 && (sec->flags & SEC_ALLOC) != 0
1232 && (sec->flags & SEC_READONLY) != 0)
1234 (*_bfd_error_handler)
1235 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1237 x86_64_elf_howto_table[r_type].name,
1238 (h) ? h->root.root.string : "a local symbol");
1239 bfd_set_error (bfd_error_bad_value);
1249 if (h != NULL && !info->shared)
1251 /* If this reloc is in a read-only section, we might
1252 need a copy reloc. We can't check reliably at this
1253 stage whether the section is read-only, as input
1254 sections have not yet been mapped to output sections.
1255 Tentatively set the flag for now, and correct in
1256 adjust_dynamic_symbol. */
1259 /* We may need a .plt entry if the function this reloc
1260 refers to is in a shared lib. */
1261 h->plt.refcount += 1;
1262 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1263 h->pointer_equality_needed = 1;
1266 /* If we are creating a shared library, and this is a reloc
1267 against a global symbol, or a non PC relative reloc
1268 against a local symbol, then we need to copy the reloc
1269 into the shared library. However, if we are linking with
1270 -Bsymbolic, we do not need to copy a reloc against a
1271 global symbol which is defined in an object we are
1272 including in the link (i.e., DEF_REGULAR is set). At
1273 this point we have not seen all the input files, so it is
1274 possible that DEF_REGULAR is not set now but will be set
1275 later (it is never cleared). In case of a weak definition,
1276 DEF_REGULAR may be cleared later by a strong definition in
1277 a shared library. We account for that possibility below by
1278 storing information in the relocs_copied field of the hash
1279 table entry. A similar situation occurs when creating
1280 shared libraries and symbol visibility changes render the
1283 If on the other hand, we are creating an executable, we
1284 may need to keep relocations for symbols satisfied by a
1285 dynamic library if we manage to avoid copy relocs for the
1288 && (sec->flags & SEC_ALLOC) != 0
1289 && (! IS_X86_64_PCREL_TYPE (r_type)
1291 && (! SYMBOLIC_BIND (info, h)
1292 || h->root.type == bfd_link_hash_defweak
1293 || !h->def_regular))))
1294 || (ELIMINATE_COPY_RELOCS
1296 && (sec->flags & SEC_ALLOC) != 0
1298 && (h->root.type == bfd_link_hash_defweak
1299 || !h->def_regular)))
1301 struct elf64_x86_64_dyn_relocs *p;
1302 struct elf64_x86_64_dyn_relocs **head;
1304 /* We must copy these reloc types into the output file.
1305 Create a reloc section in dynobj and make room for
1309 if (htab->elf.dynobj == NULL)
1310 htab->elf.dynobj = abfd;
1312 sreloc = _bfd_elf_make_dynamic_reloc_section
1313 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
1318 /* Create the ifunc section, even if we will not encounter an
1319 indirect function symbol. We may not even see one in the input
1320 object file, but we can still encounter them in libraries. */
1321 (void) _bfd_elf_make_ifunc_reloc_section
1322 (abfd, sec, htab->elf.dynobj, 2);
1325 /* If this is a global symbol, we count the number of
1326 relocations we need for this symbol. */
1329 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
1334 /* Track dynamic relocs needed for local syms too.
1335 We really need local syms available to do this
1339 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
1344 /* Beware of type punned pointers vs strict aliasing
1346 vpp = &(elf_section_data (s)->local_dynrel);
1347 head = (struct elf64_x86_64_dyn_relocs **)vpp;
1351 if (p == NULL || p->sec != sec)
1353 bfd_size_type amt = sizeof *p;
1355 p = ((struct elf64_x86_64_dyn_relocs *)
1356 bfd_alloc (htab->elf.dynobj, amt));
1367 if (IS_X86_64_PCREL_TYPE (r_type))
1372 /* This relocation describes the C++ object vtable hierarchy.
1373 Reconstruct it for later use during GC. */
1374 case R_X86_64_GNU_VTINHERIT:
1375 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1379 /* This relocation describes which C++ vtable entries are actually
1380 used. Record for later use during GC. */
1381 case R_X86_64_GNU_VTENTRY:
1382 BFD_ASSERT (h != NULL);
1384 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1396 /* Return the section that should be marked against GC for a given
1400 elf64_x86_64_gc_mark_hook (asection *sec,
1401 struct bfd_link_info *info,
1402 Elf_Internal_Rela *rel,
1403 struct elf_link_hash_entry *h,
1404 Elf_Internal_Sym *sym)
1407 switch (ELF64_R_TYPE (rel->r_info))
1409 case R_X86_64_GNU_VTINHERIT:
1410 case R_X86_64_GNU_VTENTRY:
1414 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1417 /* Update the got entry reference counts for the section being removed. */
1420 elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1422 const Elf_Internal_Rela *relocs)
1424 Elf_Internal_Shdr *symtab_hdr;
1425 struct elf_link_hash_entry **sym_hashes;
1426 bfd_signed_vma *local_got_refcounts;
1427 const Elf_Internal_Rela *rel, *relend;
1429 if (info->relocatable)
1432 elf_section_data (sec)->local_dynrel = NULL;
1434 symtab_hdr = &elf_symtab_hdr (abfd);
1435 sym_hashes = elf_sym_hashes (abfd);
1436 local_got_refcounts = elf_local_got_refcounts (abfd);
1438 relend = relocs + sec->reloc_count;
1439 for (rel = relocs; rel < relend; rel++)
1441 unsigned long r_symndx;
1442 unsigned int r_type;
1443 struct elf_link_hash_entry *h = NULL;
1445 r_symndx = ELF64_R_SYM (rel->r_info);
1446 if (r_symndx >= symtab_hdr->sh_info)
1448 struct elf64_x86_64_link_hash_entry *eh;
1449 struct elf64_x86_64_dyn_relocs **pp;
1450 struct elf64_x86_64_dyn_relocs *p;
1452 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1453 while (h->root.type == bfd_link_hash_indirect
1454 || h->root.type == bfd_link_hash_warning)
1455 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1456 eh = (struct elf64_x86_64_link_hash_entry *) h;
1458 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1461 /* Everything must go for SEC. */
1467 r_type = ELF64_R_TYPE (rel->r_info);
1468 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1469 symtab_hdr, sym_hashes,
1470 &r_type, GOT_UNKNOWN,
1476 case R_X86_64_TLSLD:
1477 if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0)
1478 elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1;
1481 case R_X86_64_TLSGD:
1482 case R_X86_64_GOTPC32_TLSDESC:
1483 case R_X86_64_TLSDESC_CALL:
1484 case R_X86_64_GOTTPOFF:
1485 case R_X86_64_GOT32:
1486 case R_X86_64_GOTPCREL:
1487 case R_X86_64_GOT64:
1488 case R_X86_64_GOTPCREL64:
1489 case R_X86_64_GOTPLT64:
1492 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
1493 h->plt.refcount -= 1;
1494 if (h->got.refcount > 0)
1495 h->got.refcount -= 1;
1497 else if (local_got_refcounts != NULL)
1499 if (local_got_refcounts[r_symndx] > 0)
1500 local_got_refcounts[r_symndx] -= 1;
1517 case R_X86_64_PLT32:
1518 case R_X86_64_PLTOFF64:
1521 if (h->plt.refcount > 0)
1522 h->plt.refcount -= 1;
1534 /* Adjust a symbol defined by a dynamic object and referenced by a
1535 regular object. The current definition is in some section of the
1536 dynamic object, but we're not including those sections. We have to
1537 change the definition to something the rest of the link can
1541 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
1542 struct elf_link_hash_entry *h)
1544 struct elf64_x86_64_link_hash_table *htab;
1547 /* If this is a function, put it in the procedure linkage table. We
1548 will fill in the contents of the procedure linkage table later,
1549 when we know the address of the .got section. */
1550 if (h->type == STT_FUNC
1553 if (h->plt.refcount <= 0
1554 || SYMBOL_CALLS_LOCAL (info, h)
1555 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1556 && h->root.type == bfd_link_hash_undefweak))
1558 /* This case can occur if we saw a PLT32 reloc in an input
1559 file, but the symbol was never referred to by a dynamic
1560 object, or if all references were garbage collected. In
1561 such a case, we don't actually need to build a procedure
1562 linkage table, and we can just do a PC32 reloc instead. */
1563 h->plt.offset = (bfd_vma) -1;
1570 /* It's possible that we incorrectly decided a .plt reloc was
1571 needed for an R_X86_64_PC32 reloc to a non-function sym in
1572 check_relocs. We can't decide accurately between function and
1573 non-function syms in check-relocs; Objects loaded later in
1574 the link may change h->type. So fix it now. */
1575 h->plt.offset = (bfd_vma) -1;
1577 /* If this is a weak symbol, and there is a real definition, the
1578 processor independent code will have arranged for us to see the
1579 real definition first, and we can just use the same value. */
1580 if (h->u.weakdef != NULL)
1582 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1583 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1584 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1585 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1586 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1587 h->non_got_ref = h->u.weakdef->non_got_ref;
1591 /* This is a reference to a symbol defined by a dynamic object which
1592 is not a function. */
1594 /* If we are creating a shared library, we must presume that the
1595 only references to the symbol are via the global offset table.
1596 For such cases we need not do anything here; the relocations will
1597 be handled correctly by relocate_section. */
1601 /* If there are no references to this symbol that do not use the
1602 GOT, we don't need to generate a copy reloc. */
1603 if (!h->non_got_ref)
1606 /* If -z nocopyreloc was given, we won't generate them either. */
1607 if (info->nocopyreloc)
1613 if (ELIMINATE_COPY_RELOCS)
1615 struct elf64_x86_64_link_hash_entry * eh;
1616 struct elf64_x86_64_dyn_relocs *p;
1618 eh = (struct elf64_x86_64_link_hash_entry *) h;
1619 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1621 s = p->sec->output_section;
1622 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1626 /* If we didn't find any dynamic relocs in read-only sections, then
1627 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1637 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1638 h->root.root.string);
1642 /* We must allocate the symbol in our .dynbss section, which will
1643 become part of the .bss section of the executable. There will be
1644 an entry for this symbol in the .dynsym section. The dynamic
1645 object will contain position independent code, so all references
1646 from the dynamic object to this symbol will go through the global
1647 offset table. The dynamic linker will use the .dynsym entry to
1648 determine the address it must put in the global offset table, so
1649 both the dynamic object and the regular object will refer to the
1650 same memory location for the variable. */
1652 htab = elf64_x86_64_hash_table (info);
1654 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1655 to copy the initial value out of the dynamic object and into the
1656 runtime process image. */
1657 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1659 htab->srelbss->size += sizeof (Elf64_External_Rela);
1665 return _bfd_elf_adjust_dynamic_copy (h, s);
1668 /* Allocate space in .plt, .got and associated reloc sections for
1672 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1674 struct bfd_link_info *info;
1675 struct elf64_x86_64_link_hash_table *htab;
1676 struct elf64_x86_64_link_hash_entry *eh;
1677 struct elf64_x86_64_dyn_relocs *p;
1678 bfd_boolean use_indirect_section = FALSE;
1680 if (h->root.type == bfd_link_hash_indirect)
1683 if (h->root.type == bfd_link_hash_warning)
1684 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1686 info = (struct bfd_link_info *) inf;
1687 htab = elf64_x86_64_hash_table (info);
1689 if (htab->elf.dynamic_sections_created
1690 && h->plt.refcount > 0)
1692 /* Make sure this symbol is output as a dynamic symbol.
1693 Undefined weak syms won't yet be marked as dynamic. */
1694 if (h->dynindx == -1
1695 && !h->forced_local)
1697 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1702 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1704 asection *s = htab->splt;
1706 /* If this is the first .plt entry, make room for the special
1709 s->size += PLT_ENTRY_SIZE;
1711 h->plt.offset = s->size;
1713 /* If this symbol is not defined in a regular file, and we are
1714 not generating a shared library, then set the symbol to this
1715 location in the .plt. This is required to make function
1716 pointers compare as equal between the normal executable and
1717 the shared library. */
1721 h->root.u.def.section = s;
1722 h->root.u.def.value = h->plt.offset;
1725 /* Make room for this entry. */
1726 s->size += PLT_ENTRY_SIZE;
1728 /* We also need to make an entry in the .got.plt section, which
1729 will be placed in the .got section by the linker script. */
1730 htab->sgotplt->size += GOT_ENTRY_SIZE;
1732 /* We also need to make an entry in the .rela.plt section. */
1733 htab->srelplt->size += sizeof (Elf64_External_Rela);
1734 htab->srelplt->reloc_count++;
1738 h->plt.offset = (bfd_vma) -1;
1744 h->plt.offset = (bfd_vma) -1;
1748 eh = (struct elf64_x86_64_link_hash_entry *) h;
1749 eh->tlsdesc_got = (bfd_vma) -1;
1751 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1752 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1753 if (h->got.refcount > 0
1756 && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
1758 h->got.offset = (bfd_vma) -1;
1760 else if (h->got.refcount > 0)
1764 int tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1766 /* Make sure this symbol is output as a dynamic symbol.
1767 Undefined weak syms won't yet be marked as dynamic. */
1768 if (h->dynindx == -1
1769 && !h->forced_local)
1771 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1775 if (GOT_TLS_GDESC_P (tls_type))
1777 eh->tlsdesc_got = htab->sgotplt->size
1778 - elf64_x86_64_compute_jump_table_size (htab);
1779 htab->sgotplt->size += 2 * GOT_ENTRY_SIZE;
1780 h->got.offset = (bfd_vma) -2;
1782 if (! GOT_TLS_GDESC_P (tls_type)
1783 || GOT_TLS_GD_P (tls_type))
1786 h->got.offset = s->size;
1787 s->size += GOT_ENTRY_SIZE;
1788 if (GOT_TLS_GD_P (tls_type))
1789 s->size += GOT_ENTRY_SIZE;
1791 dyn = htab->elf.dynamic_sections_created;
1792 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
1794 R_X86_64_GOTTPOFF needs one dynamic relocation. */
1795 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
1796 || tls_type == GOT_TLS_IE)
1797 htab->srelgot->size += sizeof (Elf64_External_Rela);
1798 else if (GOT_TLS_GD_P (tls_type))
1799 htab->srelgot->size += 2 * sizeof (Elf64_External_Rela);
1800 else if (! GOT_TLS_GDESC_P (tls_type)
1801 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1802 || h->root.type != bfd_link_hash_undefweak)
1804 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
1805 htab->srelgot->size += sizeof (Elf64_External_Rela);
1806 if (GOT_TLS_GDESC_P (tls_type))
1808 htab->srelplt->size += sizeof (Elf64_External_Rela);
1809 htab->tlsdesc_plt = (bfd_vma) -1;
1813 h->got.offset = (bfd_vma) -1;
1815 if (eh->dyn_relocs == NULL)
1818 /* In the shared -Bsymbolic case, discard space allocated for
1819 dynamic pc-relative relocs against symbols which turn out to be
1820 defined in regular objects. For the normal shared case, discard
1821 space for pc-relative relocs that have become local due to symbol
1822 visibility changes. */
1826 /* Relocs that use pc_count are those that appear on a call
1827 insn, or certain REL relocs that can generated via assembly.
1828 We want calls to protected symbols to resolve directly to the
1829 function rather than going via the plt. If people want
1830 function pointer comparisons to work as expected then they
1831 should avoid writing weird assembly. */
1832 if (SYMBOL_CALLS_LOCAL (info, h))
1834 struct elf64_x86_64_dyn_relocs **pp;
1836 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1838 p->count -= p->pc_count;
1847 /* Also discard relocs on undefined weak syms with non-default
1849 if (eh->dyn_relocs != NULL
1850 && h->root.type == bfd_link_hash_undefweak)
1852 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1853 eh->dyn_relocs = NULL;
1855 /* Make sure undefined weak symbols are output as a dynamic
1857 else if (h->dynindx == -1
1858 && ! h->forced_local
1859 && ! bfd_elf_link_record_dynamic_symbol (info, h))
1863 else if (is_indirect_symbol (info->output_bfd, h)
1865 && ! h->forced_local)
1867 if (bfd_elf_link_record_dynamic_symbol (info, h)
1868 && h->dynindx != -1)
1869 use_indirect_section = TRUE;
1873 else if (ELIMINATE_COPY_RELOCS)
1875 /* For the non-shared case, discard space for relocs against
1876 symbols which turn out to need copy relocs or are not
1882 || (htab->elf.dynamic_sections_created
1883 && (h->root.type == bfd_link_hash_undefweak
1884 || h->root.type == bfd_link_hash_undefined))))
1886 /* Make sure this symbol is output as a dynamic symbol.
1887 Undefined weak syms won't yet be marked as dynamic. */
1888 if (h->dynindx == -1
1889 && ! h->forced_local
1890 && ! bfd_elf_link_record_dynamic_symbol (info, h))
1893 /* If that succeeded, we know we'll be keeping all the
1895 if (h->dynindx != -1)
1899 eh->dyn_relocs = NULL;
1904 /* Finally, allocate space. */
1905 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1909 if (use_indirect_section)
1910 sreloc = elf_section_data (p->sec)->indirect_relocs;
1912 sreloc = elf_section_data (p->sec)->sreloc;
1914 BFD_ASSERT (sreloc != NULL);
1916 sreloc->size += p->count * sizeof (Elf64_External_Rela);
1922 /* Find any dynamic relocs that apply to read-only sections. */
1925 readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1927 struct elf64_x86_64_link_hash_entry *eh;
1928 struct elf64_x86_64_dyn_relocs *p;
1930 if (h->root.type == bfd_link_hash_warning)
1931 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1933 eh = (struct elf64_x86_64_link_hash_entry *) h;
1934 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1936 asection *s = p->sec->output_section;
1938 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1940 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1942 info->flags |= DF_TEXTREL;
1944 /* Not an error, just cut short the traversal. */
1951 /* Set the sizes of the dynamic sections. */
1954 elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
1955 struct bfd_link_info *info)
1957 struct elf64_x86_64_link_hash_table *htab;
1963 htab = elf64_x86_64_hash_table (info);
1964 dynobj = htab->elf.dynobj;
1968 if (htab->elf.dynamic_sections_created)
1970 /* Set the contents of the .interp section to the interpreter. */
1971 if (info->executable)
1973 s = bfd_get_section_by_name (dynobj, ".interp");
1976 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1977 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1981 /* Set up .got offsets for local syms, and space for local dynamic
1983 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1985 bfd_signed_vma *local_got;
1986 bfd_signed_vma *end_local_got;
1987 char *local_tls_type;
1988 bfd_vma *local_tlsdesc_gotent;
1989 bfd_size_type locsymcount;
1990 Elf_Internal_Shdr *symtab_hdr;
1993 if (! is_x86_64_elf (ibfd))
1996 for (s = ibfd->sections; s != NULL; s = s->next)
1998 struct elf64_x86_64_dyn_relocs *p;
2000 for (p = (struct elf64_x86_64_dyn_relocs *)
2001 (elf_section_data (s)->local_dynrel);
2005 if (!bfd_is_abs_section (p->sec)
2006 && bfd_is_abs_section (p->sec->output_section))
2008 /* Input section has been discarded, either because
2009 it is a copy of a linkonce section or due to
2010 linker script /DISCARD/, so we'll be discarding
2013 else if (p->count != 0)
2015 srel = elf_section_data (p->sec)->sreloc;
2016 srel->size += p->count * sizeof (Elf64_External_Rela);
2017 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2018 info->flags |= DF_TEXTREL;
2023 local_got = elf_local_got_refcounts (ibfd);
2027 symtab_hdr = &elf_symtab_hdr (ibfd);
2028 locsymcount = symtab_hdr->sh_info;
2029 end_local_got = local_got + locsymcount;
2030 local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
2031 local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd);
2033 srel = htab->srelgot;
2034 for (; local_got < end_local_got;
2035 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2037 *local_tlsdesc_gotent = (bfd_vma) -1;
2040 if (GOT_TLS_GDESC_P (*local_tls_type))
2042 *local_tlsdesc_gotent = htab->sgotplt->size
2043 - elf64_x86_64_compute_jump_table_size (htab);
2044 htab->sgotplt->size += 2 * GOT_ENTRY_SIZE;
2045 *local_got = (bfd_vma) -2;
2047 if (! GOT_TLS_GDESC_P (*local_tls_type)
2048 || GOT_TLS_GD_P (*local_tls_type))
2050 *local_got = s->size;
2051 s->size += GOT_ENTRY_SIZE;
2052 if (GOT_TLS_GD_P (*local_tls_type))
2053 s->size += GOT_ENTRY_SIZE;
2056 || GOT_TLS_GD_ANY_P (*local_tls_type)
2057 || *local_tls_type == GOT_TLS_IE)
2059 if (GOT_TLS_GDESC_P (*local_tls_type))
2061 htab->srelplt->size += sizeof (Elf64_External_Rela);
2062 htab->tlsdesc_plt = (bfd_vma) -1;
2064 if (! GOT_TLS_GDESC_P (*local_tls_type)
2065 || GOT_TLS_GD_P (*local_tls_type))
2066 srel->size += sizeof (Elf64_External_Rela);
2070 *local_got = (bfd_vma) -1;
2074 if (htab->tls_ld_got.refcount > 0)
2076 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2078 htab->tls_ld_got.offset = htab->sgot->size;
2079 htab->sgot->size += 2 * GOT_ENTRY_SIZE;
2080 htab->srelgot->size += sizeof (Elf64_External_Rela);
2083 htab->tls_ld_got.offset = -1;
2085 /* Allocate global sym .plt and .got entries, and space for global
2086 sym dynamic relocs. */
2087 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
2089 /* For every jump slot reserved in the sgotplt, reloc_count is
2090 incremented. However, when we reserve space for TLS descriptors,
2091 it's not incremented, so in order to compute the space reserved
2092 for them, it suffices to multiply the reloc count by the jump
2095 htab->sgotplt_jump_table_size
2096 = elf64_x86_64_compute_jump_table_size (htab);
2098 if (htab->tlsdesc_plt)
2100 /* If we're not using lazy TLS relocations, don't generate the
2101 PLT and GOT entries they require. */
2102 if ((info->flags & DF_BIND_NOW))
2103 htab->tlsdesc_plt = 0;
2106 htab->tlsdesc_got = htab->sgot->size;
2107 htab->sgot->size += GOT_ENTRY_SIZE;
2108 /* Reserve room for the initial entry.
2109 FIXME: we could probably do away with it in this case. */
2110 if (htab->splt->size == 0)
2111 htab->splt->size += PLT_ENTRY_SIZE;
2112 htab->tlsdesc_plt = htab->splt->size;
2113 htab->splt->size += PLT_ENTRY_SIZE;
2117 /* We now have determined the sizes of the various dynamic sections.
2118 Allocate memory for them. */
2120 for (s = dynobj->sections; s != NULL; s = s->next)
2122 if ((s->flags & SEC_LINKER_CREATED) == 0)
2127 || s == htab->sgotplt
2128 || s == htab->sdynbss)
2130 /* Strip this section if we don't need it; see the
2133 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2135 if (s->size != 0 && s != htab->srelplt)
2138 /* We use the reloc_count field as a counter if we need
2139 to copy relocs into the output file. */
2140 if (s != htab->srelplt)
2145 /* It's not one of our sections, so don't allocate space. */
2151 /* If we don't need this section, strip it from the
2152 output file. This is mostly to handle .rela.bss and
2153 .rela.plt. We must create both sections in
2154 create_dynamic_sections, because they must be created
2155 before the linker maps input sections to output
2156 sections. The linker does that before
2157 adjust_dynamic_symbol is called, and it is that
2158 function which decides whether anything needs to go
2159 into these sections. */
2161 s->flags |= SEC_EXCLUDE;
2165 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2168 /* Allocate memory for the section contents. We use bfd_zalloc
2169 here in case unused entries are not reclaimed before the
2170 section's contents are written out. This should not happen,
2171 but this way if it does, we get a R_X86_64_NONE reloc instead
2173 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2174 if (s->contents == NULL)
2178 if (htab->elf.dynamic_sections_created)
2180 /* Add some entries to the .dynamic section. We fill in the
2181 values later, in elf64_x86_64_finish_dynamic_sections, but we
2182 must add the entries now so that we get the correct size for
2183 the .dynamic section. The DT_DEBUG entry is filled in by the
2184 dynamic linker and used by the debugger. */
2185 #define add_dynamic_entry(TAG, VAL) \
2186 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2188 if (info->executable)
2190 if (!add_dynamic_entry (DT_DEBUG, 0))
2194 if (htab->splt->size != 0)
2196 if (!add_dynamic_entry (DT_PLTGOT, 0)
2197 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2198 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2199 || !add_dynamic_entry (DT_JMPREL, 0))
2202 if (htab->tlsdesc_plt
2203 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2204 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2210 if (!add_dynamic_entry (DT_RELA, 0)
2211 || !add_dynamic_entry (DT_RELASZ, 0)
2212 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
2215 /* If any dynamic relocs apply to a read-only section,
2216 then we need a DT_TEXTREL entry. */
2217 if ((info->flags & DF_TEXTREL) == 0)
2218 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
2220 if ((info->flags & DF_TEXTREL) != 0)
2222 if (!add_dynamic_entry (DT_TEXTREL, 0))
2227 #undef add_dynamic_entry
2233 elf64_x86_64_always_size_sections (bfd *output_bfd,
2234 struct bfd_link_info *info)
2236 asection *tls_sec = elf_hash_table (info)->tls_sec;
2240 struct elf_link_hash_entry *tlsbase;
2242 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2243 "_TLS_MODULE_BASE_",
2244 FALSE, FALSE, FALSE);
2246 if (tlsbase && tlsbase->type == STT_TLS)
2248 struct bfd_link_hash_entry *bh = NULL;
2249 const struct elf_backend_data *bed
2250 = get_elf_backend_data (output_bfd);
2252 if (!(_bfd_generic_link_add_one_symbol
2253 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2254 tls_sec, 0, NULL, FALSE,
2255 bed->collect, &bh)))
2258 elf64_x86_64_hash_table (info)->tls_module_base = bh;
2260 tlsbase = (struct elf_link_hash_entry *)bh;
2261 tlsbase->def_regular = 1;
2262 tlsbase->other = STV_HIDDEN;
2263 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2270 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2271 executables. Rather than setting it to the beginning of the TLS
2272 section, we have to set it to the end. This function may be called
2273 multiple times, it is idempotent. */
2276 set_tls_module_base (struct bfd_link_info *info)
2278 struct bfd_link_hash_entry *base;
2280 if (!info->executable)
2283 base = elf64_x86_64_hash_table (info)->tls_module_base;
2288 base->u.def.value = elf_hash_table (info)->tls_size;
2291 /* Return the base VMA address which should be subtracted from real addresses
2292 when resolving @dtpoff relocation.
2293 This is PT_TLS segment p_vaddr. */
2296 dtpoff_base (struct bfd_link_info *info)
2298 /* If tls_sec is NULL, we should have signalled an error already. */
2299 if (elf_hash_table (info)->tls_sec == NULL)
2301 return elf_hash_table (info)->tls_sec->vma;
2304 /* Return the relocation value for @tpoff relocation
2305 if STT_TLS virtual address is ADDRESS. */
2308 tpoff (struct bfd_link_info *info, bfd_vma address)
2310 struct elf_link_hash_table *htab = elf_hash_table (info);
2312 /* If tls_segment is NULL, we should have signalled an error already. */
2313 if (htab->tls_sec == NULL)
2315 return address - htab->tls_size - htab->tls_sec->vma;
2318 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2322 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2324 /* Opcode Instruction
2327 0x0f 0x8x conditional jump */
2329 && (contents [offset - 1] == 0xe8
2330 || contents [offset - 1] == 0xe9))
2332 && contents [offset - 2] == 0x0f
2333 && (contents [offset - 1] & 0xf0) == 0x80));
2336 /* Relocate an x86_64 ELF section. */
2339 elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
2340 bfd *input_bfd, asection *input_section,
2341 bfd_byte *contents, Elf_Internal_Rela *relocs,
2342 Elf_Internal_Sym *local_syms,
2343 asection **local_sections)
2345 struct elf64_x86_64_link_hash_table *htab;
2346 Elf_Internal_Shdr *symtab_hdr;
2347 struct elf_link_hash_entry **sym_hashes;
2348 bfd_vma *local_got_offsets;
2349 bfd_vma *local_tlsdesc_gotents;
2350 Elf_Internal_Rela *rel;
2351 Elf_Internal_Rela *relend;
2353 BFD_ASSERT (is_x86_64_elf (input_bfd));
2355 htab = elf64_x86_64_hash_table (info);
2356 symtab_hdr = &elf_symtab_hdr (input_bfd);
2357 sym_hashes = elf_sym_hashes (input_bfd);
2358 local_got_offsets = elf_local_got_offsets (input_bfd);
2359 local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
2361 set_tls_module_base (info);
2364 relend = relocs + input_section->reloc_count;
2365 for (; rel < relend; rel++)
2367 unsigned int r_type;
2368 reloc_howto_type *howto;
2369 unsigned long r_symndx;
2370 struct elf_link_hash_entry *h;
2371 Elf_Internal_Sym *sym;
2373 bfd_vma off, offplt;
2375 bfd_boolean unresolved_reloc;
2376 bfd_reloc_status_type r;
2379 r_type = ELF64_R_TYPE (rel->r_info);
2380 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2381 || r_type == (int) R_X86_64_GNU_VTENTRY)
2384 if (r_type >= R_X86_64_max)
2386 bfd_set_error (bfd_error_bad_value);
2390 howto = x86_64_elf_howto_table + r_type;
2391 r_symndx = ELF64_R_SYM (rel->r_info);
2395 unresolved_reloc = FALSE;
2396 if (r_symndx < symtab_hdr->sh_info)
2398 sym = local_syms + r_symndx;
2399 sec = local_sections[r_symndx];
2401 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2407 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2408 r_symndx, symtab_hdr, sym_hashes,
2410 unresolved_reloc, warned);
2413 if (sec != NULL && elf_discarded_section (sec))
2415 /* For relocs against symbols from removed linkonce sections,
2416 or sections discarded by a linker script, we just want the
2417 section contents zeroed. Avoid any special processing. */
2418 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2424 if (info->relocatable)
2427 /* When generating a shared object, the relocations handled here are
2428 copied into the output file to be resolved at run time. */
2432 case R_X86_64_GOT32:
2433 case R_X86_64_GOT64:
2434 /* Relocation is to the entry for this symbol in the global
2436 case R_X86_64_GOTPCREL:
2437 case R_X86_64_GOTPCREL64:
2438 /* Use global offset table entry as symbol value. */
2439 case R_X86_64_GOTPLT64:
2440 /* This is the same as GOT64 for relocation purposes, but
2441 indicates the existence of a PLT entry. The difficulty is,
2442 that we must calculate the GOT slot offset from the PLT
2443 offset, if this symbol got a PLT entry (it was global).
2444 Additionally if it's computed from the PLT entry, then that
2445 GOT offset is relative to .got.plt, not to .got. */
2446 base_got = htab->sgot;
2448 if (htab->sgot == NULL)
2455 off = h->got.offset;
2457 && h->plt.offset != (bfd_vma)-1
2458 && off == (bfd_vma)-1)
2460 /* We can't use h->got.offset here to save
2461 state, or even just remember the offset, as
2462 finish_dynamic_symbol would use that as offset into
2464 bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2465 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2466 base_got = htab->sgotplt;
2469 dyn = htab->elf.dynamic_sections_created;
2471 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2473 && SYMBOL_REFERENCES_LOCAL (info, h))
2474 || (ELF_ST_VISIBILITY (h->other)
2475 && h->root.type == bfd_link_hash_undefweak))
2477 /* This is actually a static link, or it is a -Bsymbolic
2478 link and the symbol is defined locally, or the symbol
2479 was forced to be local because of a version file. We
2480 must initialize this entry in the global offset table.
2481 Since the offset must always be a multiple of 8, we
2482 use the least significant bit to record whether we
2483 have initialized it already.
2485 When doing a dynamic link, we create a .rela.got
2486 relocation entry to initialize the value. This is
2487 done in the finish_dynamic_symbol routine. */
2492 bfd_put_64 (output_bfd, relocation,
2493 base_got->contents + off);
2494 /* Note that this is harmless for the GOTPLT64 case,
2495 as -1 | 1 still is -1. */
2500 unresolved_reloc = FALSE;
2504 if (local_got_offsets == NULL)
2507 off = local_got_offsets[r_symndx];
2509 /* The offset must always be a multiple of 8. We use
2510 the least significant bit to record whether we have
2511 already generated the necessary reloc. */
2516 bfd_put_64 (output_bfd, relocation,
2517 base_got->contents + off);
2522 Elf_Internal_Rela outrel;
2525 /* We need to generate a R_X86_64_RELATIVE reloc
2526 for the dynamic linker. */
2531 outrel.r_offset = (base_got->output_section->vma
2532 + base_got->output_offset
2534 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
2535 outrel.r_addend = relocation;
2537 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
2538 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2541 local_got_offsets[r_symndx] |= 1;
2545 if (off >= (bfd_vma) -2)
2548 relocation = base_got->output_section->vma
2549 + base_got->output_offset + off;
2550 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
2551 relocation -= htab->sgotplt->output_section->vma
2552 - htab->sgotplt->output_offset;
2556 case R_X86_64_GOTOFF64:
2557 /* Relocation is relative to the start of the global offset
2560 /* Check to make sure it isn't a protected function symbol
2561 for shared library since it may not be local when used
2562 as function address. */
2566 && h->type == STT_FUNC
2567 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
2569 (*_bfd_error_handler)
2570 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
2571 input_bfd, h->root.root.string);
2572 bfd_set_error (bfd_error_bad_value);
2576 /* Note that sgot is not involved in this
2577 calculation. We always want the start of .got.plt. If we
2578 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2579 permitted by the ABI, we might have to change this
2581 relocation -= htab->sgotplt->output_section->vma
2582 + htab->sgotplt->output_offset;
2585 case R_X86_64_GOTPC32:
2586 case R_X86_64_GOTPC64:
2587 /* Use global offset table as symbol value. */
2588 relocation = htab->sgotplt->output_section->vma
2589 + htab->sgotplt->output_offset;
2590 unresolved_reloc = FALSE;
2593 case R_X86_64_PLTOFF64:
2594 /* Relocation is PLT entry relative to GOT. For local
2595 symbols it's the symbol itself relative to GOT. */
2597 /* See PLT32 handling. */
2598 && h->plt.offset != (bfd_vma) -1
2599 && htab->splt != NULL)
2601 relocation = (htab->splt->output_section->vma
2602 + htab->splt->output_offset
2604 unresolved_reloc = FALSE;
2607 relocation -= htab->sgotplt->output_section->vma
2608 + htab->sgotplt->output_offset;
2611 case R_X86_64_PLT32:
2612 /* Relocation is to the entry for this symbol in the
2613 procedure linkage table. */
2615 /* Resolve a PLT32 reloc against a local symbol directly,
2616 without using the procedure linkage table. */
2620 if (h->plt.offset == (bfd_vma) -1
2621 || htab->splt == NULL)
2623 /* We didn't make a PLT entry for this symbol. This
2624 happens when statically linking PIC code, or when
2625 using -Bsymbolic. */
2629 relocation = (htab->splt->output_section->vma
2630 + htab->splt->output_offset
2632 unresolved_reloc = FALSE;
2639 && (input_section->flags & SEC_ALLOC) != 0
2640 && (input_section->flags & SEC_READONLY) != 0
2643 bfd_boolean fail = FALSE;
2645 = (r_type == R_X86_64_PC32
2646 && is_32bit_relative_branch (contents, rel->r_offset));
2648 if (SYMBOL_REFERENCES_LOCAL (info, h))
2650 /* Symbol is referenced locally. Make sure it is
2651 defined locally or for a branch. */
2652 fail = !h->def_regular && !branch;
2656 /* Symbol isn't referenced locally. We only allow
2657 branch to symbol with non-default visibility. */
2659 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
2666 const char *pic = "";
2668 switch (ELF_ST_VISIBILITY (h->other))
2671 v = _("hidden symbol");
2674 v = _("internal symbol");
2677 v = _("protected symbol");
2681 pic = _("; recompile with -fPIC");
2686 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
2688 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
2690 (*_bfd_error_handler) (fmt, input_bfd,
2691 x86_64_elf_howto_table[r_type].name,
2692 v, h->root.root.string, pic);
2693 bfd_set_error (bfd_error_bad_value);
2704 /* FIXME: The ABI says the linker should make sure the value is
2705 the same when it's zeroextended to 64 bit. */
2707 if ((input_section->flags & SEC_ALLOC) == 0)
2712 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2713 || h->root.type != bfd_link_hash_undefweak)
2714 && (! IS_X86_64_PCREL_TYPE (r_type)
2715 || ! SYMBOL_CALLS_LOCAL (info, h)))
2719 && ! h->forced_local
2720 && ((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs != NULL
2721 && is_indirect_symbol (output_bfd, h))
2722 || (ELIMINATE_COPY_RELOCS
2729 || h->root.type == bfd_link_hash_undefweak
2730 || h->root.type == bfd_link_hash_undefined)))
2732 Elf_Internal_Rela outrel;
2734 bfd_boolean skip, relocate;
2737 /* When generating a shared object, these relocations
2738 are copied into the output file to be resolved at run
2744 _bfd_elf_section_offset (output_bfd, info, input_section,
2746 if (outrel.r_offset == (bfd_vma) -1)
2748 else if (outrel.r_offset == (bfd_vma) -2)
2749 skip = TRUE, relocate = TRUE;
2751 outrel.r_offset += (input_section->output_section->vma
2752 + input_section->output_offset);
2755 memset (&outrel, 0, sizeof outrel);
2757 /* h->dynindx may be -1 if this symbol was marked to
2761 && (IS_X86_64_PCREL_TYPE (r_type)
2763 || ! SYMBOLIC_BIND (info, h)
2764 || ! h->def_regular))
2766 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2767 outrel.r_addend = rel->r_addend;
2771 /* This symbol is local, or marked to become local. */
2772 if (r_type == R_X86_64_64)
2775 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
2776 outrel.r_addend = relocation + rel->r_addend;
2782 if (bfd_is_abs_section (sec))
2784 else if (sec == NULL || sec->owner == NULL)
2786 bfd_set_error (bfd_error_bad_value);
2793 /* We are turning this relocation into one
2794 against a section symbol. It would be
2795 proper to subtract the symbol's value,
2796 osec->vma, from the emitted reloc addend,
2797 but ld.so expects buggy relocs. */
2798 osec = sec->output_section;
2799 sindx = elf_section_data (osec)->dynindx;
2802 asection *oi = htab->elf.text_index_section;
2803 sindx = elf_section_data (oi)->dynindx;
2805 BFD_ASSERT (sindx != 0);
2808 outrel.r_info = ELF64_R_INFO (sindx, r_type);
2809 outrel.r_addend = relocation + rel->r_addend;
2816 && ! h->forced_local
2817 && is_indirect_symbol (output_bfd, h)
2818 && elf_section_data (input_section)->indirect_relocs != NULL
2819 && elf_section_data (input_section)->indirect_relocs->contents != NULL)
2820 sreloc = elf_section_data (input_section)->indirect_relocs;
2822 sreloc = elf_section_data (input_section)->sreloc;
2824 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
2826 loc = sreloc->contents;
2827 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
2828 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2830 /* If this reloc is against an external symbol, we do
2831 not want to fiddle with the addend. Otherwise, we
2832 need to include the symbol value so that it becomes
2833 an addend for the dynamic reloc. */
2840 case R_X86_64_TLSGD:
2841 case R_X86_64_GOTPC32_TLSDESC:
2842 case R_X86_64_TLSDESC_CALL:
2843 case R_X86_64_GOTTPOFF:
2844 tls_type = GOT_UNKNOWN;
2845 if (h == NULL && local_got_offsets)
2846 tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx];
2848 tls_type = elf64_x86_64_hash_entry (h)->tls_type;
2850 if (! elf64_x86_64_tls_transition (info, input_bfd,
2851 input_section, contents,
2852 symtab_hdr, sym_hashes,
2853 &r_type, tls_type, rel,
2857 if (r_type == R_X86_64_TPOFF32)
2859 bfd_vma roff = rel->r_offset;
2861 BFD_ASSERT (! unresolved_reloc);
2863 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
2865 /* GD->LE transition.
2866 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2867 .word 0x6666; rex64; call __tls_get_addr
2870 leaq foo@tpoff(%rax), %rax */
2871 memcpy (contents + roff - 4,
2872 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
2874 bfd_put_32 (output_bfd, tpoff (info, relocation),
2875 contents + roff + 8);
2876 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
2880 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
2882 /* GDesc -> LE transition.
2883 It's originally something like:
2884 leaq x@tlsdesc(%rip), %rax
2890 unsigned int val, type, type2;
2892 type = bfd_get_8 (input_bfd, contents + roff - 3);
2893 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
2894 val = bfd_get_8 (input_bfd, contents + roff - 1);
2895 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
2896 contents + roff - 3);
2897 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
2898 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
2899 contents + roff - 1);
2900 bfd_put_32 (output_bfd, tpoff (info, relocation),
2904 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
2906 /* GDesc -> LE transition.
2911 bfd_put_8 (output_bfd, 0x66, contents + roff);
2912 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
2915 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
2917 /* IE->LE transition:
2918 Originally it can be one of:
2919 movq foo@gottpoff(%rip), %reg
2920 addq foo@gottpoff(%rip), %reg
2923 leaq foo(%reg), %reg
2926 unsigned int val, type, reg;
2928 val = bfd_get_8 (input_bfd, contents + roff - 3);
2929 type = bfd_get_8 (input_bfd, contents + roff - 2);
2930 reg = bfd_get_8 (input_bfd, contents + roff - 1);
2936 bfd_put_8 (output_bfd, 0x49,
2937 contents + roff - 3);
2938 bfd_put_8 (output_bfd, 0xc7,
2939 contents + roff - 2);
2940 bfd_put_8 (output_bfd, 0xc0 | reg,
2941 contents + roff - 1);
2945 /* addq -> addq - addressing with %rsp/%r12 is
2948 bfd_put_8 (output_bfd, 0x49,
2949 contents + roff - 3);
2950 bfd_put_8 (output_bfd, 0x81,
2951 contents + roff - 2);
2952 bfd_put_8 (output_bfd, 0xc0 | reg,
2953 contents + roff - 1);
2959 bfd_put_8 (output_bfd, 0x4d,
2960 contents + roff - 3);
2961 bfd_put_8 (output_bfd, 0x8d,
2962 contents + roff - 2);
2963 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
2964 contents + roff - 1);
2966 bfd_put_32 (output_bfd, tpoff (info, relocation),
2974 if (htab->sgot == NULL)
2979 off = h->got.offset;
2980 offplt = elf64_x86_64_hash_entry (h)->tlsdesc_got;
2984 if (local_got_offsets == NULL)
2987 off = local_got_offsets[r_symndx];
2988 offplt = local_tlsdesc_gotents[r_symndx];
2995 Elf_Internal_Rela outrel;
3000 if (htab->srelgot == NULL)
3003 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3005 if (GOT_TLS_GDESC_P (tls_type))
3007 outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC);
3008 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
3009 + 2 * GOT_ENTRY_SIZE <= htab->sgotplt->size);
3010 outrel.r_offset = (htab->sgotplt->output_section->vma
3011 + htab->sgotplt->output_offset
3013 + htab->sgotplt_jump_table_size);
3014 sreloc = htab->srelplt;
3015 loc = sreloc->contents;
3016 loc += sreloc->reloc_count++
3017 * sizeof (Elf64_External_Rela);
3018 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3019 <= sreloc->contents + sreloc->size);
3021 outrel.r_addend = relocation - dtpoff_base (info);
3023 outrel.r_addend = 0;
3024 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3027 sreloc = htab->srelgot;
3029 outrel.r_offset = (htab->sgot->output_section->vma
3030 + htab->sgot->output_offset + off);
3032 if (GOT_TLS_GD_P (tls_type))
3033 dr_type = R_X86_64_DTPMOD64;
3034 else if (GOT_TLS_GDESC_P (tls_type))
3037 dr_type = R_X86_64_TPOFF64;
3039 bfd_put_64 (output_bfd, 0, htab->sgot->contents + off);
3040 outrel.r_addend = 0;
3041 if ((dr_type == R_X86_64_TPOFF64
3042 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3043 outrel.r_addend = relocation - dtpoff_base (info);
3044 outrel.r_info = ELF64_R_INFO (indx, dr_type);
3046 loc = sreloc->contents;
3047 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
3048 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3049 <= sreloc->contents + sreloc->size);
3050 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3052 if (GOT_TLS_GD_P (tls_type))
3056 BFD_ASSERT (! unresolved_reloc);
3057 bfd_put_64 (output_bfd,
3058 relocation - dtpoff_base (info),
3059 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3063 bfd_put_64 (output_bfd, 0,
3064 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3065 outrel.r_info = ELF64_R_INFO (indx,
3067 outrel.r_offset += GOT_ENTRY_SIZE;
3068 sreloc->reloc_count++;
3069 loc += sizeof (Elf64_External_Rela);
3070 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3071 <= sreloc->contents + sreloc->size);
3072 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3080 local_got_offsets[r_symndx] |= 1;
3083 if (off >= (bfd_vma) -2
3084 && ! GOT_TLS_GDESC_P (tls_type))
3086 if (r_type == ELF64_R_TYPE (rel->r_info))
3088 if (r_type == R_X86_64_GOTPC32_TLSDESC
3089 || r_type == R_X86_64_TLSDESC_CALL)
3090 relocation = htab->sgotplt->output_section->vma
3091 + htab->sgotplt->output_offset
3092 + offplt + htab->sgotplt_jump_table_size;
3094 relocation = htab->sgot->output_section->vma
3095 + htab->sgot->output_offset + off;
3096 unresolved_reloc = FALSE;
3100 bfd_vma roff = rel->r_offset;
3102 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3104 /* GD->IE transition.
3105 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3106 .word 0x6666; rex64; call __tls_get_addr@plt
3109 addq foo@gottpoff(%rip), %rax */
3110 memcpy (contents + roff - 4,
3111 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3114 relocation = (htab->sgot->output_section->vma
3115 + htab->sgot->output_offset + off
3117 - input_section->output_section->vma
3118 - input_section->output_offset
3120 bfd_put_32 (output_bfd, relocation,
3121 contents + roff + 8);
3122 /* Skip R_X86_64_PLT32. */
3126 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3128 /* GDesc -> IE transition.
3129 It's originally something like:
3130 leaq x@tlsdesc(%rip), %rax
3133 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax
3136 unsigned int val, type, type2;
3138 type = bfd_get_8 (input_bfd, contents + roff - 3);
3139 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
3140 val = bfd_get_8 (input_bfd, contents + roff - 1);
3142 /* Now modify the instruction as appropriate. To
3143 turn a leaq into a movq in the form we use it, it
3144 suffices to change the second byte from 0x8d to
3146 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3148 bfd_put_32 (output_bfd,
3149 htab->sgot->output_section->vma
3150 + htab->sgot->output_offset + off
3152 - input_section->output_section->vma
3153 - input_section->output_offset
3158 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3160 /* GDesc -> IE transition.
3167 unsigned int val, type;
3169 type = bfd_get_8 (input_bfd, contents + roff);
3170 val = bfd_get_8 (input_bfd, contents + roff + 1);
3171 bfd_put_8 (output_bfd, 0x66, contents + roff);
3172 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3180 case R_X86_64_TLSLD:
3181 if (! elf64_x86_64_tls_transition (info, input_bfd,
3182 input_section, contents,
3183 symtab_hdr, sym_hashes,
3184 &r_type, GOT_UNKNOWN,
3188 if (r_type != R_X86_64_TLSLD)
3190 /* LD->LE transition:
3191 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3193 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3195 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3196 memcpy (contents + rel->r_offset - 3,
3197 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3198 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3203 if (htab->sgot == NULL)
3206 off = htab->tls_ld_got.offset;
3211 Elf_Internal_Rela outrel;
3214 if (htab->srelgot == NULL)
3217 outrel.r_offset = (htab->sgot->output_section->vma
3218 + htab->sgot->output_offset + off);
3220 bfd_put_64 (output_bfd, 0,
3221 htab->sgot->contents + off);
3222 bfd_put_64 (output_bfd, 0,
3223 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3224 outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64);
3225 outrel.r_addend = 0;
3226 loc = htab->srelgot->contents;
3227 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3228 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3229 htab->tls_ld_got.offset |= 1;
3231 relocation = htab->sgot->output_section->vma
3232 + htab->sgot->output_offset + off;
3233 unresolved_reloc = FALSE;
3236 case R_X86_64_DTPOFF32:
3237 if (info->shared || (input_section->flags & SEC_CODE) == 0)
3238 relocation -= dtpoff_base (info);
3240 relocation = tpoff (info, relocation);
3243 case R_X86_64_TPOFF32:
3244 BFD_ASSERT (! info->shared);
3245 relocation = tpoff (info, relocation);
3252 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3253 because such sections are not SEC_ALLOC and thus ld.so will
3254 not process them. */
3255 if (unresolved_reloc
3256 && !((input_section->flags & SEC_DEBUGGING) != 0
3258 (*_bfd_error_handler)
3259 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3262 (long) rel->r_offset,
3264 h->root.root.string);
3266 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3267 contents, rel->r_offset,
3268 relocation, rel->r_addend);
3270 if (r != bfd_reloc_ok)
3275 name = h->root.root.string;
3278 name = bfd_elf_string_from_elf_section (input_bfd,
3279 symtab_hdr->sh_link,
3284 name = bfd_section_name (input_bfd, sec);
3287 if (r == bfd_reloc_overflow)
3289 if (! ((*info->callbacks->reloc_overflow)
3290 (info, (h ? &h->root : NULL), name, howto->name,
3291 (bfd_vma) 0, input_bfd, input_section,
3297 (*_bfd_error_handler)
3298 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3299 input_bfd, input_section,
3300 (long) rel->r_offset, name, (int) r);
3309 /* Finish up dynamic symbol handling. We set the contents of various
3310 dynamic sections here. */
3313 elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
3314 struct bfd_link_info *info,
3315 struct elf_link_hash_entry *h,
3316 Elf_Internal_Sym *sym)
3318 struct elf64_x86_64_link_hash_table *htab;
3320 htab = elf64_x86_64_hash_table (info);
3322 if (h->plt.offset != (bfd_vma) -1)
3326 Elf_Internal_Rela rela;
3329 /* This symbol has an entry in the procedure linkage table. Set
3331 if (h->dynindx == -1
3332 || htab->splt == NULL
3333 || htab->sgotplt == NULL
3334 || htab->srelplt == NULL)
3337 /* Get the index in the procedure linkage table which
3338 corresponds to this symbol. This is the index of this symbol
3339 in all the symbols for which we are making plt entries. The
3340 first entry in the procedure linkage table is reserved. */
3341 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3343 /* Get the offset into the .got table of the entry that
3344 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3345 bytes. The first three are reserved for the dynamic linker. */
3346 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
3348 /* Fill in the entry in the procedure linkage table. */
3349 memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
3352 /* Insert the relocation positions of the plt section. The magic
3353 numbers at the end of the statements are the positions of the
3354 relocations in the plt section. */
3355 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3356 instruction uses 6 bytes, subtract this value. */
3357 bfd_put_32 (output_bfd,
3358 (htab->sgotplt->output_section->vma
3359 + htab->sgotplt->output_offset
3361 - htab->splt->output_section->vma
3362 - htab->splt->output_offset
3365 htab->splt->contents + h->plt.offset + 2);
3366 /* Put relocation index. */
3367 bfd_put_32 (output_bfd, plt_index,
3368 htab->splt->contents + h->plt.offset + 7);
3369 /* Put offset for jmp .PLT0. */
3370 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
3371 htab->splt->contents + h->plt.offset + 12);
3373 /* Fill in the entry in the global offset table, initially this
3374 points to the pushq instruction in the PLT which is at offset 6. */
3375 bfd_put_64 (output_bfd, (htab->splt->output_section->vma
3376 + htab->splt->output_offset
3377 + h->plt.offset + 6),
3378 htab->sgotplt->contents + got_offset);
3380 /* Fill in the entry in the .rela.plt section. */
3381 rela.r_offset = (htab->sgotplt->output_section->vma
3382 + htab->sgotplt->output_offset
3384 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
3386 loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela);
3387 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3389 if (!h->def_regular)
3391 /* Mark the symbol as undefined, rather than as defined in
3392 the .plt section. Leave the value if there were any
3393 relocations where pointer equality matters (this is a clue
3394 for the dynamic linker, to make function pointer
3395 comparisons work between an application and shared
3396 library), otherwise set it to zero. If a function is only
3397 called from a binary, there is no need to slow down
3398 shared libraries because of that. */
3399 sym->st_shndx = SHN_UNDEF;
3400 if (!h->pointer_equality_needed)
3405 if (h->got.offset != (bfd_vma) -1
3406 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type)
3407 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
3409 Elf_Internal_Rela rela;
3412 /* This symbol has an entry in the global offset table. Set it
3414 if (htab->sgot == NULL || htab->srelgot == NULL)
3417 rela.r_offset = (htab->sgot->output_section->vma
3418 + htab->sgot->output_offset
3419 + (h->got.offset &~ (bfd_vma) 1));
3421 /* If this is a static link, or it is a -Bsymbolic link and the
3422 symbol is defined locally or was forced to be local because
3423 of a version file, we just want to emit a RELATIVE reloc.
3424 The entry in the global offset table will already have been
3425 initialized in the relocate_section function. */
3427 && SYMBOL_REFERENCES_LOCAL (info, h))
3429 if (!h->def_regular)
3431 BFD_ASSERT((h->got.offset & 1) != 0);
3432 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3433 rela.r_addend = (h->root.u.def.value
3434 + h->root.u.def.section->output_section->vma
3435 + h->root.u.def.section->output_offset);
3439 BFD_ASSERT((h->got.offset & 1) == 0);
3440 bfd_put_64 (output_bfd, (bfd_vma) 0,
3441 htab->sgot->contents + h->got.offset);
3442 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
3446 loc = htab->srelgot->contents;
3447 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3448 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3453 Elf_Internal_Rela rela;
3456 /* This symbol needs a copy reloc. Set it up. */
3458 if (h->dynindx == -1
3459 || (h->root.type != bfd_link_hash_defined
3460 && h->root.type != bfd_link_hash_defweak)
3461 || htab->srelbss == NULL)
3464 rela.r_offset = (h->root.u.def.value
3465 + h->root.u.def.section->output_section->vma
3466 + h->root.u.def.section->output_offset);
3467 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
3469 loc = htab->srelbss->contents;
3470 loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
3471 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3474 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3475 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3476 || h == htab->elf.hgot)
3477 sym->st_shndx = SHN_ABS;
3482 /* Used to decide how to sort relocs in an optimal manner for the
3483 dynamic linker, before writing them out. */
3485 static enum elf_reloc_type_class
3486 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
3488 switch ((int) ELF64_R_TYPE (rela->r_info))
3490 case R_X86_64_RELATIVE:
3491 return reloc_class_relative;
3492 case R_X86_64_JUMP_SLOT:
3493 return reloc_class_plt;
3495 return reloc_class_copy;
3497 return reloc_class_normal;
3501 /* Finish up the dynamic sections. */
3504 elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3506 struct elf64_x86_64_link_hash_table *htab;
3510 htab = elf64_x86_64_hash_table (info);
3511 dynobj = htab->elf.dynobj;
3512 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3514 if (htab->elf.dynamic_sections_created)
3516 Elf64_External_Dyn *dyncon, *dynconend;
3518 if (sdyn == NULL || htab->sgot == NULL)
3521 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3522 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3523 for (; dyncon < dynconend; dyncon++)
3525 Elf_Internal_Dyn dyn;
3528 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3537 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3541 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
3545 s = htab->srelplt->output_section;
3546 dyn.d_un.d_val = s->size;
3550 /* The procedure linkage table relocs (DT_JMPREL) should
3551 not be included in the overall relocs (DT_RELA).
3552 Therefore, we override the DT_RELASZ entry here to
3553 make it not include the JMPREL relocs. Since the
3554 linker script arranges for .rela.plt to follow all
3555 other relocation sections, we don't have to worry
3556 about changing the DT_RELA entry. */
3557 if (htab->srelplt != NULL)
3559 s = htab->srelplt->output_section;
3560 dyn.d_un.d_val -= s->size;
3564 case DT_TLSDESC_PLT:
3566 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
3567 + htab->tlsdesc_plt;
3570 case DT_TLSDESC_GOT:
3572 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
3573 + htab->tlsdesc_got;
3577 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3580 /* Fill in the special first entry in the procedure linkage table. */
3581 if (htab->splt && htab->splt->size > 0)
3583 /* Fill in the first entry in the procedure linkage table. */
3584 memcpy (htab->splt->contents, elf64_x86_64_plt0_entry,
3586 /* Add offset for pushq GOT+8(%rip), since the instruction
3587 uses 6 bytes subtract this value. */
3588 bfd_put_32 (output_bfd,
3589 (htab->sgotplt->output_section->vma
3590 + htab->sgotplt->output_offset
3592 - htab->splt->output_section->vma
3593 - htab->splt->output_offset
3595 htab->splt->contents + 2);
3596 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
3597 the end of the instruction. */
3598 bfd_put_32 (output_bfd,
3599 (htab->sgotplt->output_section->vma
3600 + htab->sgotplt->output_offset
3602 - htab->splt->output_section->vma
3603 - htab->splt->output_offset
3605 htab->splt->contents + 8);
3607 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize =
3610 if (htab->tlsdesc_plt)
3612 bfd_put_64 (output_bfd, (bfd_vma) 0,
3613 htab->sgot->contents + htab->tlsdesc_got);
3615 memcpy (htab->splt->contents + htab->tlsdesc_plt,
3616 elf64_x86_64_plt0_entry,
3619 /* Add offset for pushq GOT+8(%rip), since the
3620 instruction uses 6 bytes subtract this value. */
3621 bfd_put_32 (output_bfd,
3622 (htab->sgotplt->output_section->vma
3623 + htab->sgotplt->output_offset
3625 - htab->splt->output_section->vma
3626 - htab->splt->output_offset
3629 htab->splt->contents + htab->tlsdesc_plt + 2);
3630 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
3631 htab->tlsdesc_got. The 12 is the offset to the end of
3633 bfd_put_32 (output_bfd,
3634 (htab->sgot->output_section->vma
3635 + htab->sgot->output_offset
3637 - htab->splt->output_section->vma
3638 - htab->splt->output_offset
3641 htab->splt->contents + htab->tlsdesc_plt + 8);
3648 /* Fill in the first three entries in the global offset table. */
3649 if (htab->sgotplt->size > 0)
3651 /* Set the first entry in the global offset table to the address of
3652 the dynamic section. */
3654 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents);
3656 bfd_put_64 (output_bfd,
3657 sdyn->output_section->vma + sdyn->output_offset,
3658 htab->sgotplt->contents);
3659 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
3660 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE);
3661 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2);
3664 elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize =
3668 if (htab->sgot && htab->sgot->size > 0)
3669 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize
3675 /* Return address for Ith PLT stub in section PLT, for relocation REL
3676 or (bfd_vma) -1 if it should not be included. */
3679 elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
3680 const arelent *rel ATTRIBUTE_UNUSED)
3682 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
3685 /* Handle an x86-64 specific section when reading an object file. This
3686 is called when elfcode.h finds a section with an unknown type. */
3689 elf64_x86_64_section_from_shdr (bfd *abfd,
3690 Elf_Internal_Shdr *hdr,
3694 if (hdr->sh_type != SHT_X86_64_UNWIND)
3697 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
3703 /* Hook called by the linker routine which adds symbols from an object
3704 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
3708 elf64_x86_64_add_symbol_hook (bfd *abfd,
3709 struct bfd_link_info *info,
3710 Elf_Internal_Sym *sym,
3711 const char **namep ATTRIBUTE_UNUSED,
3712 flagword *flagsp ATTRIBUTE_UNUSED,
3718 switch (sym->st_shndx)
3720 case SHN_X86_64_LCOMMON:
3721 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
3724 lcomm = bfd_make_section_with_flags (abfd,
3728 | SEC_LINKER_CREATED));
3731 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
3734 *valp = sym->st_size;
3738 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
3739 elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
3745 /* Given a BFD section, try to locate the corresponding ELF section
3749 elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3750 asection *sec, int *index)
3752 if (sec == &_bfd_elf_large_com_section)
3754 *index = SHN_X86_64_LCOMMON;
3760 /* Process a symbol. */
3763 elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
3766 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
3768 switch (elfsym->internal_elf_sym.st_shndx)
3770 case SHN_X86_64_LCOMMON:
3771 asym->section = &_bfd_elf_large_com_section;
3772 asym->value = elfsym->internal_elf_sym.st_size;
3773 /* Common symbol doesn't set BSF_GLOBAL. */
3774 asym->flags &= ~BSF_GLOBAL;
3780 elf64_x86_64_common_definition (Elf_Internal_Sym *sym)
3782 return (sym->st_shndx == SHN_COMMON
3783 || sym->st_shndx == SHN_X86_64_LCOMMON);
3787 elf64_x86_64_common_section_index (asection *sec)
3789 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
3792 return SHN_X86_64_LCOMMON;
3796 elf64_x86_64_common_section (asection *sec)
3798 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
3799 return bfd_com_section_ptr;
3801 return &_bfd_elf_large_com_section;
3805 elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3806 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
3807 struct elf_link_hash_entry *h,
3808 Elf_Internal_Sym *sym,
3810 bfd_vma *pvalue ATTRIBUTE_UNUSED,
3811 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
3812 bfd_boolean *skip ATTRIBUTE_UNUSED,
3813 bfd_boolean *override ATTRIBUTE_UNUSED,
3814 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
3815 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
3816 bfd_boolean *newdef ATTRIBUTE_UNUSED,
3817 bfd_boolean *newdyn,
3818 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
3819 bfd_boolean *newweak ATTRIBUTE_UNUSED,
3820 bfd *abfd ATTRIBUTE_UNUSED,
3822 bfd_boolean *olddef ATTRIBUTE_UNUSED,
3823 bfd_boolean *olddyn,
3824 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
3825 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
3829 /* A normal common symbol and a large common symbol result in a
3830 normal common symbol. We turn the large common symbol into a
3833 && h->root.type == bfd_link_hash_common
3835 && bfd_is_com_section (*sec)
3838 if (sym->st_shndx == SHN_COMMON
3839 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
3841 h->root.u.c.p->section
3842 = bfd_make_section_old_way (oldbfd, "COMMON");
3843 h->root.u.c.p->section->flags = SEC_ALLOC;
3845 else if (sym->st_shndx == SHN_X86_64_LCOMMON
3846 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
3847 *psec = *sec = bfd_com_section_ptr;
3854 elf64_x86_64_additional_program_headers (bfd *abfd,
3855 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3860 /* Check to see if we need a large readonly segment. */
3861 s = bfd_get_section_by_name (abfd, ".lrodata");
3862 if (s && (s->flags & SEC_LOAD))
3865 /* Check to see if we need a large data segment. Since .lbss sections
3866 is placed right after the .bss section, there should be no need for
3867 a large data segment just because of .lbss. */
3868 s = bfd_get_section_by_name (abfd, ".ldata");
3869 if (s && (s->flags & SEC_LOAD))
3875 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3878 elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h)
3880 if (h->plt.offset != (bfd_vma) -1
3882 && !h->pointer_equality_needed)
3885 return _bfd_elf_hash_symbol (h);
3888 static const struct bfd_elf_special_section
3889 elf64_x86_64_special_sections[]=
3891 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3892 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
3893 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
3894 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3895 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3896 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
3897 { NULL, 0, 0, 0, 0 }
3900 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
3901 #define TARGET_LITTLE_NAME "elf64-x86-64"
3902 #define ELF_ARCH bfd_arch_i386
3903 #define ELF_MACHINE_CODE EM_X86_64
3904 #define ELF_MAXPAGESIZE 0x200000
3905 #define ELF_MINPAGESIZE 0x1000
3906 #define ELF_COMMONPAGESIZE 0x1000
3908 #define elf_backend_can_gc_sections 1
3909 #define elf_backend_can_refcount 1
3910 #define elf_backend_want_got_plt 1
3911 #define elf_backend_plt_readonly 1
3912 #define elf_backend_want_plt_sym 0
3913 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
3914 #define elf_backend_rela_normal 1
3916 #define elf_info_to_howto elf64_x86_64_info_to_howto
3918 #define bfd_elf64_bfd_link_hash_table_create \
3919 elf64_x86_64_link_hash_table_create
3920 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
3921 #define bfd_elf64_bfd_reloc_name_lookup \
3922 elf64_x86_64_reloc_name_lookup
3924 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
3925 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
3926 #define elf_backend_check_relocs elf64_x86_64_check_relocs
3927 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
3928 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
3929 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
3930 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
3931 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
3932 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
3933 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
3934 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
3935 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
3936 #define elf_backend_relocate_section elf64_x86_64_relocate_section
3937 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
3938 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
3939 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
3940 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
3941 #define elf_backend_object_p elf64_x86_64_elf_object_p
3942 #define bfd_elf64_mkobject elf64_x86_64_mkobject
3944 #define elf_backend_section_from_shdr \
3945 elf64_x86_64_section_from_shdr
3947 #define elf_backend_section_from_bfd_section \
3948 elf64_x86_64_elf_section_from_bfd_section
3949 #define elf_backend_add_symbol_hook \
3950 elf64_x86_64_add_symbol_hook
3951 #define elf_backend_symbol_processing \
3952 elf64_x86_64_symbol_processing
3953 #define elf_backend_common_section_index \
3954 elf64_x86_64_common_section_index
3955 #define elf_backend_common_section \
3956 elf64_x86_64_common_section
3957 #define elf_backend_common_definition \
3958 elf64_x86_64_common_definition
3959 #define elf_backend_merge_symbol \
3960 elf64_x86_64_merge_symbol
3961 #define elf_backend_special_sections \
3962 elf64_x86_64_special_sections
3963 #define elf_backend_additional_program_headers \
3964 elf64_x86_64_additional_program_headers
3965 #define elf_backend_hash_symbol \
3966 elf64_x86_64_hash_symbol
3968 #undef elf_backend_post_process_headers
3969 #define elf_backend_post_process_headers _bfd_elf_set_osabi
3971 #include "elf64-target.h"
3973 /* FreeBSD support. */
3975 #undef TARGET_LITTLE_SYM
3976 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
3977 #undef TARGET_LITTLE_NAME
3978 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
3981 #define ELF_OSABI ELFOSABI_FREEBSD
3984 #define elf64_bed elf64_x86_64_fbsd_bed
3986 #include "elf64-target.h"