1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka <jh@suse.cz>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
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 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
529 struct bfd_hash_table *table,
532 /* Allocate the structure if it has not already been allocated by a
536 entry = bfd_hash_allocate (table,
537 sizeof (struct elf64_x86_64_link_hash_entry));
542 /* Call the allocation method of the superclass. */
543 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
546 struct elf64_x86_64_link_hash_entry *eh;
548 eh = (struct elf64_x86_64_link_hash_entry *) entry;
549 eh->dyn_relocs = NULL;
550 eh->tls_type = GOT_UNKNOWN;
551 eh->tlsdesc_got = (bfd_vma) -1;
557 /* Create an X86-64 ELF linker hash table. */
559 static struct bfd_link_hash_table *
560 elf64_x86_64_link_hash_table_create (bfd *abfd)
562 struct elf64_x86_64_link_hash_table *ret;
563 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
565 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
569 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
570 elf64_x86_64_link_hash_newfunc,
571 sizeof (struct elf64_x86_64_link_hash_entry)))
584 ret->sym_sec.abfd = NULL;
585 ret->tlsdesc_plt = 0;
586 ret->tlsdesc_got = 0;
587 ret->tls_ld_got.refcount = 0;
588 ret->sgotplt_jump_table_size = 0;
589 ret->tls_module_base = NULL;
591 return &ret->elf.root;
594 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
595 shortcuts to them in our hash table. */
598 elf64_x86_64_create_got_section (bfd *dynobj, struct bfd_link_info *info)
600 struct elf64_x86_64_link_hash_table *htab;
602 if (! _bfd_elf_create_got_section (dynobj, info))
605 htab = elf64_x86_64_hash_table (info);
606 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
607 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
608 if (!htab->sgot || !htab->sgotplt)
611 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got",
612 (SEC_ALLOC | SEC_LOAD
617 if (htab->srelgot == NULL
618 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
623 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
624 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
628 elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
630 struct elf64_x86_64_link_hash_table *htab;
632 htab = elf64_x86_64_hash_table (info);
633 if (!htab->sgot && !elf64_x86_64_create_got_section (dynobj, info))
636 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
639 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
640 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
641 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
643 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
645 if (!htab->splt || !htab->srelplt || !htab->sdynbss
646 || (!info->shared && !htab->srelbss))
652 /* Copy the extra info we tack onto an elf_link_hash_entry. */
655 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
656 struct elf_link_hash_entry *dir,
657 struct elf_link_hash_entry *ind)
659 struct elf64_x86_64_link_hash_entry *edir, *eind;
661 edir = (struct elf64_x86_64_link_hash_entry *) dir;
662 eind = (struct elf64_x86_64_link_hash_entry *) ind;
664 if (eind->dyn_relocs != NULL)
666 if (edir->dyn_relocs != NULL)
668 struct elf64_x86_64_dyn_relocs **pp;
669 struct elf64_x86_64_dyn_relocs *p;
671 /* Add reloc counts against the indirect sym to the direct sym
672 list. Merge any entries against the same section. */
673 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
675 struct elf64_x86_64_dyn_relocs *q;
677 for (q = edir->dyn_relocs; q != NULL; q = q->next)
678 if (q->sec == p->sec)
680 q->pc_count += p->pc_count;
681 q->count += p->count;
688 *pp = edir->dyn_relocs;
691 edir->dyn_relocs = eind->dyn_relocs;
692 eind->dyn_relocs = NULL;
695 if (ind->root.type == bfd_link_hash_indirect
696 && dir->got.refcount <= 0)
698 edir->tls_type = eind->tls_type;
699 eind->tls_type = GOT_UNKNOWN;
702 if (ELIMINATE_COPY_RELOCS
703 && ind->root.type != bfd_link_hash_indirect
704 && dir->dynamic_adjusted)
706 /* If called to transfer flags for a weakdef during processing
707 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
708 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
709 dir->ref_dynamic |= ind->ref_dynamic;
710 dir->ref_regular |= ind->ref_regular;
711 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
712 dir->needs_plt |= ind->needs_plt;
713 dir->pointer_equality_needed |= ind->pointer_equality_needed;
716 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
720 elf64_x86_64_elf_object_p (bfd *abfd)
722 /* Set the right machine number for an x86-64 elf64 file. */
723 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
741 /* Return TRUE if the TLS access code sequence support transition
745 elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec,
747 Elf_Internal_Shdr *symtab_hdr,
748 struct elf_link_hash_entry **sym_hashes,
750 const Elf_Internal_Rela *rel,
751 const Elf_Internal_Rela *relend)
754 unsigned long r_symndx;
755 struct elf_link_hash_entry *h;
758 /* Get the section contents. */
759 if (contents == NULL)
761 if (elf_section_data (sec)->this_hdr.contents != NULL)
762 contents = elf_section_data (sec)->this_hdr.contents;
765 /* FIXME: How to better handle error condition? */
766 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
769 /* Cache the section contents for elf_link_input_bfd. */
770 elf_section_data (sec)->this_hdr.contents = contents;
774 offset = rel->r_offset;
779 if ((rel + 1) >= relend)
782 if (r_type == R_X86_64_TLSGD)
784 /* Check transition from GD access model. Only
785 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
786 .word 0x6666; rex64; call __tls_get_addr
787 can transit to different access model. */
789 static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } },
790 call = { { 0x66, 0x66, 0x48, 0xe8 } };
792 || (offset + 12) > sec->size
793 || bfd_get_32 (abfd, contents + offset - 4) != leaq.i
794 || bfd_get_32 (abfd, contents + offset + 4) != call.i)
799 /* Check transition from LD access model. Only
800 leaq foo@tlsld(%rip), %rdi;
802 can transit to different access model. */
804 static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } };
807 if (offset < 3 || (offset + 9) > sec->size)
810 op.i = bfd_get_32 (abfd, contents + offset - 3);
811 op.c[3] = bfd_get_8 (abfd, contents + offset + 4);
816 r_symndx = ELF64_R_SYM (rel[1].r_info);
817 if (r_symndx < symtab_hdr->sh_info)
820 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
821 /* Use strncmp to check __tls_get_addr since __tls_get_addr
824 && h->root.root.string != NULL
825 && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32
826 || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
827 && (strncmp (h->root.root.string,
828 "__tls_get_addr", 14) == 0));
830 case R_X86_64_GOTTPOFF:
831 /* Check transition from IE access model:
832 movq foo@gottpoff(%rip), %reg
833 addq foo@gottpoff(%rip), %reg
836 if (offset < 3 || (offset + 4) > sec->size)
839 val = bfd_get_8 (abfd, contents + offset - 3);
840 if (val != 0x48 && val != 0x4c)
843 val = bfd_get_8 (abfd, contents + offset - 2);
844 if (val != 0x8b && val != 0x03)
847 val = bfd_get_8 (abfd, contents + offset - 1);
848 return (val & 0xc7) == 5;
850 case R_X86_64_GOTPC32_TLSDESC:
851 /* Check transition from GDesc access model:
852 leaq x@tlsdesc(%rip), %rax
854 Make sure it's a leaq adding rip to a 32-bit offset
855 into any register, although it's probably almost always
858 if (offset < 3 || (offset + 4) > sec->size)
861 val = bfd_get_8 (abfd, contents + offset - 3);
862 if ((val & 0xfb) != 0x48)
865 if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
868 val = bfd_get_8 (abfd, contents + offset - 1);
869 return (val & 0xc7) == 0x05;
871 case R_X86_64_TLSDESC_CALL:
872 /* Check transition from GDesc access model:
873 call *x@tlsdesc(%rax)
875 if (offset + 2 <= sec->size)
877 /* Make sure that it's a call *x@tlsdesc(%rax). */
878 static x86_64_opcode16 call = { { 0xff, 0x10 } };
879 return bfd_get_16 (abfd, contents + offset) == call.i;
889 /* Return TRUE if the TLS access transition is OK or no transition
890 will be performed. Update R_TYPE if there is a transition. */
893 elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
894 asection *sec, bfd_byte *contents,
895 Elf_Internal_Shdr *symtab_hdr,
896 struct elf_link_hash_entry **sym_hashes,
897 unsigned int *r_type, int tls_type,
898 const Elf_Internal_Rela *rel,
899 const Elf_Internal_Rela *relend,
900 struct elf_link_hash_entry *h)
902 unsigned int from_type = *r_type;
903 unsigned int to_type = from_type;
904 bfd_boolean check = TRUE;
909 case R_X86_64_GOTPC32_TLSDESC:
910 case R_X86_64_TLSDESC_CALL:
911 case R_X86_64_GOTTPOFF:
915 to_type = R_X86_64_TPOFF32;
917 to_type = R_X86_64_GOTTPOFF;
920 /* When we are called from elf64_x86_64_relocate_section,
921 CONTENTS isn't NULL and there may be additional transitions
922 based on TLS_TYPE. */
923 if (contents != NULL)
925 unsigned int new_to_type = to_type;
930 && tls_type == GOT_TLS_IE)
931 new_to_type = R_X86_64_TPOFF32;
933 if (to_type == R_X86_64_TLSGD
934 || to_type == R_X86_64_GOTPC32_TLSDESC
935 || to_type == R_X86_64_TLSDESC_CALL)
937 if (tls_type == GOT_TLS_IE)
938 new_to_type = R_X86_64_GOTTPOFF;
941 /* We checked the transition before when we were called from
942 elf64_x86_64_check_relocs. We only want to check the new
943 transition which hasn't been checked before. */
944 check = new_to_type != to_type && from_type == to_type;
945 to_type = new_to_type;
952 to_type = R_X86_64_TPOFF32;
959 /* Return TRUE if there is no transition. */
960 if (from_type == to_type)
963 /* Check if the transition can be performed. */
965 && ! elf64_x86_64_check_tls_transition (abfd, sec, contents,
966 symtab_hdr, sym_hashes,
967 from_type, rel, relend))
969 reloc_howto_type *from, *to;
971 from = elf64_x86_64_rtype_to_howto (abfd, from_type);
972 to = elf64_x86_64_rtype_to_howto (abfd, to_type);
974 (*_bfd_error_handler)
975 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
976 "in section `%A' failed"),
977 abfd, sec, from->name, to->name,
978 h ? h->root.root.string : "a local symbol",
979 (unsigned long) rel->r_offset);
980 bfd_set_error (bfd_error_bad_value);
988 /* Look through the relocs for a section during the first phase, and
989 calculate needed space in the global offset table, procedure
990 linkage table, and dynamic reloc sections. */
993 elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
995 const Elf_Internal_Rela *relocs)
997 struct elf64_x86_64_link_hash_table *htab;
998 Elf_Internal_Shdr *symtab_hdr;
999 struct elf_link_hash_entry **sym_hashes;
1000 const Elf_Internal_Rela *rel;
1001 const Elf_Internal_Rela *rel_end;
1004 if (info->relocatable)
1007 BFD_ASSERT (is_x86_64_elf (abfd));
1009 htab = elf64_x86_64_hash_table (info);
1010 symtab_hdr = &elf_symtab_hdr (abfd);
1011 sym_hashes = elf_sym_hashes (abfd);
1015 rel_end = relocs + sec->reloc_count;
1016 for (rel = relocs; rel < rel_end; rel++)
1018 unsigned int r_type;
1019 unsigned long r_symndx;
1020 struct elf_link_hash_entry *h;
1022 r_symndx = ELF64_R_SYM (rel->r_info);
1023 r_type = ELF64_R_TYPE (rel->r_info);
1025 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1027 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1032 if (r_symndx < symtab_hdr->sh_info)
1036 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1037 while (h->root.type == bfd_link_hash_indirect
1038 || h->root.type == bfd_link_hash_warning)
1039 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1042 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1043 symtab_hdr, sym_hashes,
1044 &r_type, GOT_UNKNOWN,
1050 case R_X86_64_TLSLD:
1051 htab->tls_ld_got.refcount += 1;
1054 case R_X86_64_TPOFF32:
1057 (*_bfd_error_handler)
1058 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1060 x86_64_elf_howto_table[r_type].name,
1061 (h) ? h->root.root.string : "a local symbol");
1062 bfd_set_error (bfd_error_bad_value);
1067 case R_X86_64_GOTTPOFF:
1069 info->flags |= DF_STATIC_TLS;
1072 case R_X86_64_GOT32:
1073 case R_X86_64_GOTPCREL:
1074 case R_X86_64_TLSGD:
1075 case R_X86_64_GOT64:
1076 case R_X86_64_GOTPCREL64:
1077 case R_X86_64_GOTPLT64:
1078 case R_X86_64_GOTPC32_TLSDESC:
1079 case R_X86_64_TLSDESC_CALL:
1080 /* This symbol requires a global offset table entry. */
1082 int tls_type, old_tls_type;
1086 default: tls_type = GOT_NORMAL; break;
1087 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break;
1088 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break;
1089 case R_X86_64_GOTPC32_TLSDESC:
1090 case R_X86_64_TLSDESC_CALL:
1091 tls_type = GOT_TLS_GDESC; break;
1096 if (r_type == R_X86_64_GOTPLT64)
1098 /* This relocation indicates that we also need
1099 a PLT entry, as this is a function. We don't need
1100 a PLT entry for local symbols. */
1102 h->plt.refcount += 1;
1104 h->got.refcount += 1;
1105 old_tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1109 bfd_signed_vma *local_got_refcounts;
1111 /* This is a global offset table entry for a local symbol. */
1112 local_got_refcounts = elf_local_got_refcounts (abfd);
1113 if (local_got_refcounts == NULL)
1117 size = symtab_hdr->sh_info;
1118 size *= sizeof (bfd_signed_vma)
1119 + sizeof (bfd_vma) + sizeof (char);
1120 local_got_refcounts = ((bfd_signed_vma *)
1121 bfd_zalloc (abfd, size));
1122 if (local_got_refcounts == NULL)
1124 elf_local_got_refcounts (abfd) = local_got_refcounts;
1125 elf64_x86_64_local_tlsdesc_gotent (abfd)
1126 = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
1127 elf64_x86_64_local_got_tls_type (abfd)
1128 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
1130 local_got_refcounts[r_symndx] += 1;
1132 = elf64_x86_64_local_got_tls_type (abfd) [r_symndx];
1135 /* If a TLS symbol is accessed using IE at least once,
1136 there is no point to use dynamic model for it. */
1137 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1138 && (! GOT_TLS_GD_ANY_P (old_tls_type)
1139 || tls_type != GOT_TLS_IE))
1141 if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type))
1142 tls_type = old_tls_type;
1143 else if (GOT_TLS_GD_ANY_P (old_tls_type)
1144 && GOT_TLS_GD_ANY_P (tls_type))
1145 tls_type |= old_tls_type;
1148 (*_bfd_error_handler)
1149 (_("%B: '%s' accessed both as normal and thread local symbol"),
1150 abfd, h ? h->root.root.string : "<local>");
1155 if (old_tls_type != tls_type)
1158 elf64_x86_64_hash_entry (h)->tls_type = tls_type;
1160 elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type;
1165 case R_X86_64_GOTOFF64:
1166 case R_X86_64_GOTPC32:
1167 case R_X86_64_GOTPC64:
1169 if (htab->sgot == NULL)
1171 if (htab->elf.dynobj == NULL)
1172 htab->elf.dynobj = abfd;
1173 if (!elf64_x86_64_create_got_section (htab->elf.dynobj,
1179 case R_X86_64_PLT32:
1180 /* This symbol requires a procedure linkage table entry. We
1181 actually build the entry in adjust_dynamic_symbol,
1182 because this might be a case of linking PIC code which is
1183 never referenced by a dynamic object, in which case we
1184 don't need to generate a procedure linkage table entry
1187 /* If this is a local symbol, we resolve it directly without
1188 creating a procedure linkage table entry. */
1193 h->plt.refcount += 1;
1196 case R_X86_64_PLTOFF64:
1197 /* This tries to form the 'address' of a function relative
1198 to GOT. For global symbols we need a PLT entry. */
1202 h->plt.refcount += 1;
1210 /* Let's help debug shared library creation. These relocs
1211 cannot be used in shared libs. Don't error out for
1212 sections we don't care about, such as debug sections or
1213 non-constant sections. */
1215 && (sec->flags & SEC_ALLOC) != 0
1216 && (sec->flags & SEC_READONLY) != 0)
1218 (*_bfd_error_handler)
1219 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1221 x86_64_elf_howto_table[r_type].name,
1222 (h) ? h->root.root.string : "a local symbol");
1223 bfd_set_error (bfd_error_bad_value);
1233 if (h != NULL && !info->shared)
1235 /* If this reloc is in a read-only section, we might
1236 need a copy reloc. We can't check reliably at this
1237 stage whether the section is read-only, as input
1238 sections have not yet been mapped to output sections.
1239 Tentatively set the flag for now, and correct in
1240 adjust_dynamic_symbol. */
1243 /* We may need a .plt entry if the function this reloc
1244 refers to is in a shared lib. */
1245 h->plt.refcount += 1;
1246 if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64)
1247 h->pointer_equality_needed = 1;
1250 /* If we are creating a shared library, and this is a reloc
1251 against a global symbol, or a non PC relative reloc
1252 against a local symbol, then we need to copy the reloc
1253 into the shared library. However, if we are linking with
1254 -Bsymbolic, we do not need to copy a reloc against a
1255 global symbol which is defined in an object we are
1256 including in the link (i.e., DEF_REGULAR is set). At
1257 this point we have not seen all the input files, so it is
1258 possible that DEF_REGULAR is not set now but will be set
1259 later (it is never cleared). In case of a weak definition,
1260 DEF_REGULAR may be cleared later by a strong definition in
1261 a shared library. We account for that possibility below by
1262 storing information in the relocs_copied field of the hash
1263 table entry. A similar situation occurs when creating
1264 shared libraries and symbol visibility changes render the
1267 If on the other hand, we are creating an executable, we
1268 may need to keep relocations for symbols satisfied by a
1269 dynamic library if we manage to avoid copy relocs for the
1272 && (sec->flags & SEC_ALLOC) != 0
1273 && (! IS_X86_64_PCREL_TYPE (r_type)
1275 && (! SYMBOLIC_BIND (info, h)
1276 || h->root.type == bfd_link_hash_defweak
1277 || !h->def_regular))))
1278 || (ELIMINATE_COPY_RELOCS
1280 && (sec->flags & SEC_ALLOC) != 0
1282 && (h->root.type == bfd_link_hash_defweak
1283 || !h->def_regular)))
1285 struct elf64_x86_64_dyn_relocs *p;
1286 struct elf64_x86_64_dyn_relocs **head;
1288 /* We must copy these reloc types into the output file.
1289 Create a reloc section in dynobj and make room for
1293 if (htab->elf.dynobj == NULL)
1294 htab->elf.dynobj = abfd;
1296 sreloc = _bfd_elf_make_dynamic_reloc_section
1297 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
1302 /* Create the ifunc section, even if we will not encounter an
1303 indirect function symbol. We may not even see one in the input
1304 object file, but we can still encounter them in libraries. */
1305 (void) _bfd_elf_make_ifunc_reloc_section
1306 (abfd, sec, htab->elf.dynobj, 2);
1309 /* If this is a global symbol, we count the number of
1310 relocations we need for this symbol. */
1313 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
1318 /* Track dynamic relocs needed for local syms too.
1319 We really need local syms available to do this
1323 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
1328 /* Beware of type punned pointers vs strict aliasing
1330 vpp = &(elf_section_data (s)->local_dynrel);
1331 head = (struct elf64_x86_64_dyn_relocs **)vpp;
1335 if (p == NULL || p->sec != sec)
1337 bfd_size_type amt = sizeof *p;
1339 p = ((struct elf64_x86_64_dyn_relocs *)
1340 bfd_alloc (htab->elf.dynobj, amt));
1351 if (IS_X86_64_PCREL_TYPE (r_type))
1356 /* This relocation describes the C++ object vtable hierarchy.
1357 Reconstruct it for later use during GC. */
1358 case R_X86_64_GNU_VTINHERIT:
1359 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1363 /* This relocation describes which C++ vtable entries are actually
1364 used. Record for later use during GC. */
1365 case R_X86_64_GNU_VTENTRY:
1366 BFD_ASSERT (h != NULL);
1368 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1380 /* Return the section that should be marked against GC for a given
1384 elf64_x86_64_gc_mark_hook (asection *sec,
1385 struct bfd_link_info *info,
1386 Elf_Internal_Rela *rel,
1387 struct elf_link_hash_entry *h,
1388 Elf_Internal_Sym *sym)
1391 switch (ELF64_R_TYPE (rel->r_info))
1393 case R_X86_64_GNU_VTINHERIT:
1394 case R_X86_64_GNU_VTENTRY:
1398 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1401 /* Update the got entry reference counts for the section being removed. */
1404 elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1406 const Elf_Internal_Rela *relocs)
1408 Elf_Internal_Shdr *symtab_hdr;
1409 struct elf_link_hash_entry **sym_hashes;
1410 bfd_signed_vma *local_got_refcounts;
1411 const Elf_Internal_Rela *rel, *relend;
1413 if (info->relocatable)
1416 elf_section_data (sec)->local_dynrel = NULL;
1418 symtab_hdr = &elf_symtab_hdr (abfd);
1419 sym_hashes = elf_sym_hashes (abfd);
1420 local_got_refcounts = elf_local_got_refcounts (abfd);
1422 relend = relocs + sec->reloc_count;
1423 for (rel = relocs; rel < relend; rel++)
1425 unsigned long r_symndx;
1426 unsigned int r_type;
1427 struct elf_link_hash_entry *h = NULL;
1429 r_symndx = ELF64_R_SYM (rel->r_info);
1430 if (r_symndx >= symtab_hdr->sh_info)
1432 struct elf64_x86_64_link_hash_entry *eh;
1433 struct elf64_x86_64_dyn_relocs **pp;
1434 struct elf64_x86_64_dyn_relocs *p;
1436 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1437 while (h->root.type == bfd_link_hash_indirect
1438 || h->root.type == bfd_link_hash_warning)
1439 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1440 eh = (struct elf64_x86_64_link_hash_entry *) h;
1442 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1445 /* Everything must go for SEC. */
1451 r_type = ELF64_R_TYPE (rel->r_info);
1452 if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
1453 symtab_hdr, sym_hashes,
1454 &r_type, GOT_UNKNOWN,
1460 case R_X86_64_TLSLD:
1461 if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0)
1462 elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1;
1465 case R_X86_64_TLSGD:
1466 case R_X86_64_GOTPC32_TLSDESC:
1467 case R_X86_64_TLSDESC_CALL:
1468 case R_X86_64_GOTTPOFF:
1469 case R_X86_64_GOT32:
1470 case R_X86_64_GOTPCREL:
1471 case R_X86_64_GOT64:
1472 case R_X86_64_GOTPCREL64:
1473 case R_X86_64_GOTPLT64:
1476 if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
1477 h->plt.refcount -= 1;
1478 if (h->got.refcount > 0)
1479 h->got.refcount -= 1;
1481 else if (local_got_refcounts != NULL)
1483 if (local_got_refcounts[r_symndx] > 0)
1484 local_got_refcounts[r_symndx] -= 1;
1501 case R_X86_64_PLT32:
1502 case R_X86_64_PLTOFF64:
1505 if (h->plt.refcount > 0)
1506 h->plt.refcount -= 1;
1518 /* Adjust a symbol defined by a dynamic object and referenced by a
1519 regular object. The current definition is in some section of the
1520 dynamic object, but we're not including those sections. We have to
1521 change the definition to something the rest of the link can
1525 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
1526 struct elf_link_hash_entry *h)
1528 struct elf64_x86_64_link_hash_table *htab;
1531 /* If this is a function, put it in the procedure linkage table. We
1532 will fill in the contents of the procedure linkage table later,
1533 when we know the address of the .got section. */
1534 if (h->type == STT_FUNC
1537 if (h->plt.refcount <= 0
1538 || SYMBOL_CALLS_LOCAL (info, h)
1539 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1540 && h->root.type == bfd_link_hash_undefweak))
1542 /* This case can occur if we saw a PLT32 reloc in an input
1543 file, but the symbol was never referred to by a dynamic
1544 object, or if all references were garbage collected. In
1545 such a case, we don't actually need to build a procedure
1546 linkage table, and we can just do a PC32 reloc instead. */
1547 h->plt.offset = (bfd_vma) -1;
1554 /* It's possible that we incorrectly decided a .plt reloc was
1555 needed for an R_X86_64_PC32 reloc to a non-function sym in
1556 check_relocs. We can't decide accurately between function and
1557 non-function syms in check-relocs; Objects loaded later in
1558 the link may change h->type. So fix it now. */
1559 h->plt.offset = (bfd_vma) -1;
1561 /* If this is a weak symbol, and there is a real definition, the
1562 processor independent code will have arranged for us to see the
1563 real definition first, and we can just use the same value. */
1564 if (h->u.weakdef != NULL)
1566 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1567 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1568 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1569 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1570 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1571 h->non_got_ref = h->u.weakdef->non_got_ref;
1575 /* This is a reference to a symbol defined by a dynamic object which
1576 is not a function. */
1578 /* If we are creating a shared library, we must presume that the
1579 only references to the symbol are via the global offset table.
1580 For such cases we need not do anything here; the relocations will
1581 be handled correctly by relocate_section. */
1585 /* If there are no references to this symbol that do not use the
1586 GOT, we don't need to generate a copy reloc. */
1587 if (!h->non_got_ref)
1590 /* If -z nocopyreloc was given, we won't generate them either. */
1591 if (info->nocopyreloc)
1597 if (ELIMINATE_COPY_RELOCS)
1599 struct elf64_x86_64_link_hash_entry * eh;
1600 struct elf64_x86_64_dyn_relocs *p;
1602 eh = (struct elf64_x86_64_link_hash_entry *) h;
1603 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1605 s = p->sec->output_section;
1606 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1610 /* If we didn't find any dynamic relocs in read-only sections, then
1611 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1621 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1622 h->root.root.string);
1626 /* We must allocate the symbol in our .dynbss section, which will
1627 become part of the .bss section of the executable. There will be
1628 an entry for this symbol in the .dynsym section. The dynamic
1629 object will contain position independent code, so all references
1630 from the dynamic object to this symbol will go through the global
1631 offset table. The dynamic linker will use the .dynsym entry to
1632 determine the address it must put in the global offset table, so
1633 both the dynamic object and the regular object will refer to the
1634 same memory location for the variable. */
1636 htab = elf64_x86_64_hash_table (info);
1638 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1639 to copy the initial value out of the dynamic object and into the
1640 runtime process image. */
1641 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1643 htab->srelbss->size += sizeof (Elf64_External_Rela);
1649 return _bfd_elf_adjust_dynamic_copy (h, s);
1652 /* Allocate space in .plt, .got and associated reloc sections for
1656 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1658 struct bfd_link_info *info;
1659 struct elf64_x86_64_link_hash_table *htab;
1660 struct elf64_x86_64_link_hash_entry *eh;
1661 struct elf64_x86_64_dyn_relocs *p;
1662 bfd_boolean use_indirect_section = FALSE;
1664 if (h->root.type == bfd_link_hash_indirect)
1667 if (h->root.type == bfd_link_hash_warning)
1668 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1670 info = (struct bfd_link_info *) inf;
1671 htab = elf64_x86_64_hash_table (info);
1673 if (htab->elf.dynamic_sections_created
1674 && h->plt.refcount > 0)
1676 /* Make sure this symbol is output as a dynamic symbol.
1677 Undefined weak syms won't yet be marked as dynamic. */
1678 if (h->dynindx == -1
1679 && !h->forced_local)
1681 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1686 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1688 asection *s = htab->splt;
1690 /* If this is the first .plt entry, make room for the special
1693 s->size += PLT_ENTRY_SIZE;
1695 h->plt.offset = s->size;
1697 /* If this symbol is not defined in a regular file, and we are
1698 not generating a shared library, then set the symbol to this
1699 location in the .plt. This is required to make function
1700 pointers compare as equal between the normal executable and
1701 the shared library. */
1705 h->root.u.def.section = s;
1706 h->root.u.def.value = h->plt.offset;
1709 /* Make room for this entry. */
1710 s->size += PLT_ENTRY_SIZE;
1712 /* We also need to make an entry in the .got.plt section, which
1713 will be placed in the .got section by the linker script. */
1714 htab->sgotplt->size += GOT_ENTRY_SIZE;
1716 /* We also need to make an entry in the .rela.plt section. */
1717 htab->srelplt->size += sizeof (Elf64_External_Rela);
1718 htab->srelplt->reloc_count++;
1722 h->plt.offset = (bfd_vma) -1;
1728 h->plt.offset = (bfd_vma) -1;
1732 eh = (struct elf64_x86_64_link_hash_entry *) h;
1733 eh->tlsdesc_got = (bfd_vma) -1;
1735 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1736 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1737 if (h->got.refcount > 0
1740 && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
1742 h->got.offset = (bfd_vma) -1;
1744 else if (h->got.refcount > 0)
1748 int tls_type = elf64_x86_64_hash_entry (h)->tls_type;
1750 /* Make sure this symbol is output as a dynamic symbol.
1751 Undefined weak syms won't yet be marked as dynamic. */
1752 if (h->dynindx == -1
1753 && !h->forced_local)
1755 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1759 if (GOT_TLS_GDESC_P (tls_type))
1761 eh->tlsdesc_got = htab->sgotplt->size
1762 - elf64_x86_64_compute_jump_table_size (htab);
1763 htab->sgotplt->size += 2 * GOT_ENTRY_SIZE;
1764 h->got.offset = (bfd_vma) -2;
1766 if (! GOT_TLS_GDESC_P (tls_type)
1767 || GOT_TLS_GD_P (tls_type))
1770 h->got.offset = s->size;
1771 s->size += GOT_ENTRY_SIZE;
1772 if (GOT_TLS_GD_P (tls_type))
1773 s->size += GOT_ENTRY_SIZE;
1775 dyn = htab->elf.dynamic_sections_created;
1776 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
1778 R_X86_64_GOTTPOFF needs one dynamic relocation. */
1779 if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
1780 || tls_type == GOT_TLS_IE)
1781 htab->srelgot->size += sizeof (Elf64_External_Rela);
1782 else if (GOT_TLS_GD_P (tls_type))
1783 htab->srelgot->size += 2 * sizeof (Elf64_External_Rela);
1784 else if (! GOT_TLS_GDESC_P (tls_type)
1785 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1786 || h->root.type != bfd_link_hash_undefweak)
1788 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
1789 htab->srelgot->size += sizeof (Elf64_External_Rela);
1790 if (GOT_TLS_GDESC_P (tls_type))
1792 htab->srelplt->size += sizeof (Elf64_External_Rela);
1793 htab->tlsdesc_plt = (bfd_vma) -1;
1797 h->got.offset = (bfd_vma) -1;
1799 if (eh->dyn_relocs == NULL)
1802 /* In the shared -Bsymbolic case, discard space allocated for
1803 dynamic pc-relative relocs against symbols which turn out to be
1804 defined in regular objects. For the normal shared case, discard
1805 space for pc-relative relocs that have become local due to symbol
1806 visibility changes. */
1810 /* Relocs that use pc_count are those that appear on a call
1811 insn, or certain REL relocs that can generated via assembly.
1812 We want calls to protected symbols to resolve directly to the
1813 function rather than going via the plt. If people want
1814 function pointer comparisons to work as expected then they
1815 should avoid writing weird assembly. */
1816 if (SYMBOL_CALLS_LOCAL (info, h))
1818 struct elf64_x86_64_dyn_relocs **pp;
1820 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1822 p->count -= p->pc_count;
1831 /* Also discard relocs on undefined weak syms with non-default
1833 if (eh->dyn_relocs != NULL
1834 && h->root.type == bfd_link_hash_undefweak)
1836 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
1837 eh->dyn_relocs = NULL;
1839 /* Make sure undefined weak symbols are output as a dynamic
1841 else if (h->dynindx == -1
1842 && ! h->forced_local
1843 && ! bfd_elf_link_record_dynamic_symbol (info, h))
1847 else if (_bfd_elf_is_ifunc_symbol (info->output_bfd, h)
1849 && ! h->forced_local)
1851 if (bfd_elf_link_record_dynamic_symbol (info, h)
1852 && h->dynindx != -1)
1853 use_indirect_section = TRUE;
1857 else if (ELIMINATE_COPY_RELOCS)
1859 /* For the non-shared case, discard space for relocs against
1860 symbols which turn out to need copy relocs or are not
1866 || (htab->elf.dynamic_sections_created
1867 && (h->root.type == bfd_link_hash_undefweak
1868 || h->root.type == bfd_link_hash_undefined))))
1870 /* Make sure this symbol is output as a dynamic symbol.
1871 Undefined weak syms won't yet be marked as dynamic. */
1872 if (h->dynindx == -1
1873 && ! h->forced_local
1874 && ! bfd_elf_link_record_dynamic_symbol (info, h))
1877 /* If that succeeded, we know we'll be keeping all the
1879 if (h->dynindx != -1)
1883 eh->dyn_relocs = NULL;
1888 /* Finally, allocate space. */
1889 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1893 if (use_indirect_section)
1894 sreloc = elf_section_data (p->sec)->indirect_relocs;
1896 sreloc = elf_section_data (p->sec)->sreloc;
1898 BFD_ASSERT (sreloc != NULL);
1900 sreloc->size += p->count * sizeof (Elf64_External_Rela);
1906 /* Find any dynamic relocs that apply to read-only sections. */
1909 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
1911 struct elf64_x86_64_link_hash_entry *eh;
1912 struct elf64_x86_64_dyn_relocs *p;
1914 if (h->root.type == bfd_link_hash_warning)
1915 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1917 eh = (struct elf64_x86_64_link_hash_entry *) h;
1918 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1920 asection *s = p->sec->output_section;
1922 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1924 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1926 info->flags |= DF_TEXTREL;
1928 /* Not an error, just cut short the traversal. */
1935 /* Set the sizes of the dynamic sections. */
1938 elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
1939 struct bfd_link_info *info)
1941 struct elf64_x86_64_link_hash_table *htab;
1947 htab = elf64_x86_64_hash_table (info);
1948 dynobj = htab->elf.dynobj;
1952 if (htab->elf.dynamic_sections_created)
1954 /* Set the contents of the .interp section to the interpreter. */
1955 if (info->executable)
1957 s = bfd_get_section_by_name (dynobj, ".interp");
1960 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1961 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1965 /* Set up .got offsets for local syms, and space for local dynamic
1967 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1969 bfd_signed_vma *local_got;
1970 bfd_signed_vma *end_local_got;
1971 char *local_tls_type;
1972 bfd_vma *local_tlsdesc_gotent;
1973 bfd_size_type locsymcount;
1974 Elf_Internal_Shdr *symtab_hdr;
1977 if (! is_x86_64_elf (ibfd))
1980 for (s = ibfd->sections; s != NULL; s = s->next)
1982 struct elf64_x86_64_dyn_relocs *p;
1984 for (p = (struct elf64_x86_64_dyn_relocs *)
1985 (elf_section_data (s)->local_dynrel);
1989 if (!bfd_is_abs_section (p->sec)
1990 && bfd_is_abs_section (p->sec->output_section))
1992 /* Input section has been discarded, either because
1993 it is a copy of a linkonce section or due to
1994 linker script /DISCARD/, so we'll be discarding
1997 else if (p->count != 0)
1999 srel = elf_section_data (p->sec)->sreloc;
2000 srel->size += p->count * sizeof (Elf64_External_Rela);
2001 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2002 info->flags |= DF_TEXTREL;
2007 local_got = elf_local_got_refcounts (ibfd);
2011 symtab_hdr = &elf_symtab_hdr (ibfd);
2012 locsymcount = symtab_hdr->sh_info;
2013 end_local_got = local_got + locsymcount;
2014 local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
2015 local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd);
2017 srel = htab->srelgot;
2018 for (; local_got < end_local_got;
2019 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
2021 *local_tlsdesc_gotent = (bfd_vma) -1;
2024 if (GOT_TLS_GDESC_P (*local_tls_type))
2026 *local_tlsdesc_gotent = htab->sgotplt->size
2027 - elf64_x86_64_compute_jump_table_size (htab);
2028 htab->sgotplt->size += 2 * GOT_ENTRY_SIZE;
2029 *local_got = (bfd_vma) -2;
2031 if (! GOT_TLS_GDESC_P (*local_tls_type)
2032 || GOT_TLS_GD_P (*local_tls_type))
2034 *local_got = s->size;
2035 s->size += GOT_ENTRY_SIZE;
2036 if (GOT_TLS_GD_P (*local_tls_type))
2037 s->size += GOT_ENTRY_SIZE;
2040 || GOT_TLS_GD_ANY_P (*local_tls_type)
2041 || *local_tls_type == GOT_TLS_IE)
2043 if (GOT_TLS_GDESC_P (*local_tls_type))
2045 htab->srelplt->size += sizeof (Elf64_External_Rela);
2046 htab->tlsdesc_plt = (bfd_vma) -1;
2048 if (! GOT_TLS_GDESC_P (*local_tls_type)
2049 || GOT_TLS_GD_P (*local_tls_type))
2050 srel->size += sizeof (Elf64_External_Rela);
2054 *local_got = (bfd_vma) -1;
2058 if (htab->tls_ld_got.refcount > 0)
2060 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2062 htab->tls_ld_got.offset = htab->sgot->size;
2063 htab->sgot->size += 2 * GOT_ENTRY_SIZE;
2064 htab->srelgot->size += sizeof (Elf64_External_Rela);
2067 htab->tls_ld_got.offset = -1;
2069 /* Allocate global sym .plt and .got entries, and space for global
2070 sym dynamic relocs. */
2071 elf_link_hash_traverse (&htab->elf, elf64_x86_64_allocate_dynrelocs,
2074 /* For every jump slot reserved in the sgotplt, reloc_count is
2075 incremented. However, when we reserve space for TLS descriptors,
2076 it's not incremented, so in order to compute the space reserved
2077 for them, it suffices to multiply the reloc count by the jump
2080 htab->sgotplt_jump_table_size
2081 = elf64_x86_64_compute_jump_table_size (htab);
2083 if (htab->tlsdesc_plt)
2085 /* If we're not using lazy TLS relocations, don't generate the
2086 PLT and GOT entries they require. */
2087 if ((info->flags & DF_BIND_NOW))
2088 htab->tlsdesc_plt = 0;
2091 htab->tlsdesc_got = htab->sgot->size;
2092 htab->sgot->size += GOT_ENTRY_SIZE;
2093 /* Reserve room for the initial entry.
2094 FIXME: we could probably do away with it in this case. */
2095 if (htab->splt->size == 0)
2096 htab->splt->size += PLT_ENTRY_SIZE;
2097 htab->tlsdesc_plt = htab->splt->size;
2098 htab->splt->size += PLT_ENTRY_SIZE;
2102 /* We now have determined the sizes of the various dynamic sections.
2103 Allocate memory for them. */
2105 for (s = dynobj->sections; s != NULL; s = s->next)
2107 if ((s->flags & SEC_LINKER_CREATED) == 0)
2112 || s == htab->sgotplt
2113 || s == htab->sdynbss)
2115 /* Strip this section if we don't need it; see the
2118 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
2120 if (s->size != 0 && s != htab->srelplt)
2123 /* We use the reloc_count field as a counter if we need
2124 to copy relocs into the output file. */
2125 if (s != htab->srelplt)
2130 /* It's not one of our sections, so don't allocate space. */
2136 /* If we don't need this section, strip it from the
2137 output file. This is mostly to handle .rela.bss and
2138 .rela.plt. We must create both sections in
2139 create_dynamic_sections, because they must be created
2140 before the linker maps input sections to output
2141 sections. The linker does that before
2142 adjust_dynamic_symbol is called, and it is that
2143 function which decides whether anything needs to go
2144 into these sections. */
2146 s->flags |= SEC_EXCLUDE;
2150 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2153 /* Allocate memory for the section contents. We use bfd_zalloc
2154 here in case unused entries are not reclaimed before the
2155 section's contents are written out. This should not happen,
2156 but this way if it does, we get a R_X86_64_NONE reloc instead
2158 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2159 if (s->contents == NULL)
2163 if (htab->elf.dynamic_sections_created)
2165 /* Add some entries to the .dynamic section. We fill in the
2166 values later, in elf64_x86_64_finish_dynamic_sections, but we
2167 must add the entries now so that we get the correct size for
2168 the .dynamic section. The DT_DEBUG entry is filled in by the
2169 dynamic linker and used by the debugger. */
2170 #define add_dynamic_entry(TAG, VAL) \
2171 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2173 if (info->executable)
2175 if (!add_dynamic_entry (DT_DEBUG, 0))
2179 if (htab->splt->size != 0)
2181 if (!add_dynamic_entry (DT_PLTGOT, 0)
2182 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2183 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2184 || !add_dynamic_entry (DT_JMPREL, 0))
2187 if (htab->tlsdesc_plt
2188 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
2189 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
2195 if (!add_dynamic_entry (DT_RELA, 0)
2196 || !add_dynamic_entry (DT_RELASZ, 0)
2197 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
2200 /* If any dynamic relocs apply to a read-only section,
2201 then we need a DT_TEXTREL entry. */
2202 if ((info->flags & DF_TEXTREL) == 0)
2203 elf_link_hash_traverse (&htab->elf,
2204 elf64_x86_64_readonly_dynrelocs,
2207 if ((info->flags & DF_TEXTREL) != 0)
2209 if (!add_dynamic_entry (DT_TEXTREL, 0))
2214 #undef add_dynamic_entry
2220 elf64_x86_64_always_size_sections (bfd *output_bfd,
2221 struct bfd_link_info *info)
2223 asection *tls_sec = elf_hash_table (info)->tls_sec;
2227 struct elf_link_hash_entry *tlsbase;
2229 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
2230 "_TLS_MODULE_BASE_",
2231 FALSE, FALSE, FALSE);
2233 if (tlsbase && tlsbase->type == STT_TLS)
2235 struct bfd_link_hash_entry *bh = NULL;
2236 const struct elf_backend_data *bed
2237 = get_elf_backend_data (output_bfd);
2239 if (!(_bfd_generic_link_add_one_symbol
2240 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
2241 tls_sec, 0, NULL, FALSE,
2242 bed->collect, &bh)))
2245 elf64_x86_64_hash_table (info)->tls_module_base = bh;
2247 tlsbase = (struct elf_link_hash_entry *)bh;
2248 tlsbase->def_regular = 1;
2249 tlsbase->other = STV_HIDDEN;
2250 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
2257 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2258 executables. Rather than setting it to the beginning of the TLS
2259 section, we have to set it to the end. This function may be called
2260 multiple times, it is idempotent. */
2263 elf64_x86_64_set_tls_module_base (struct bfd_link_info *info)
2265 struct bfd_link_hash_entry *base;
2267 if (!info->executable)
2270 base = elf64_x86_64_hash_table (info)->tls_module_base;
2275 base->u.def.value = elf_hash_table (info)->tls_size;
2278 /* Return the base VMA address which should be subtracted from real addresses
2279 when resolving @dtpoff relocation.
2280 This is PT_TLS segment p_vaddr. */
2283 elf64_x86_64_dtpoff_base (struct bfd_link_info *info)
2285 /* If tls_sec is NULL, we should have signalled an error already. */
2286 if (elf_hash_table (info)->tls_sec == NULL)
2288 return elf_hash_table (info)->tls_sec->vma;
2291 /* Return the relocation value for @tpoff relocation
2292 if STT_TLS virtual address is ADDRESS. */
2295 elf64_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address)
2297 struct elf_link_hash_table *htab = elf_hash_table (info);
2299 /* If tls_segment is NULL, we should have signalled an error already. */
2300 if (htab->tls_sec == NULL)
2302 return address - htab->tls_size - htab->tls_sec->vma;
2305 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2309 is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
2311 /* Opcode Instruction
2314 0x0f 0x8x conditional jump */
2316 && (contents [offset - 1] == 0xe8
2317 || contents [offset - 1] == 0xe9))
2319 && contents [offset - 2] == 0x0f
2320 && (contents [offset - 1] & 0xf0) == 0x80));
2323 /* Relocate an x86_64 ELF section. */
2326 elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
2327 bfd *input_bfd, asection *input_section,
2328 bfd_byte *contents, Elf_Internal_Rela *relocs,
2329 Elf_Internal_Sym *local_syms,
2330 asection **local_sections)
2332 struct elf64_x86_64_link_hash_table *htab;
2333 Elf_Internal_Shdr *symtab_hdr;
2334 struct elf_link_hash_entry **sym_hashes;
2335 bfd_vma *local_got_offsets;
2336 bfd_vma *local_tlsdesc_gotents;
2337 Elf_Internal_Rela *rel;
2338 Elf_Internal_Rela *relend;
2340 BFD_ASSERT (is_x86_64_elf (input_bfd));
2342 htab = elf64_x86_64_hash_table (info);
2343 symtab_hdr = &elf_symtab_hdr (input_bfd);
2344 sym_hashes = elf_sym_hashes (input_bfd);
2345 local_got_offsets = elf_local_got_offsets (input_bfd);
2346 local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
2348 elf64_x86_64_set_tls_module_base (info);
2351 relend = relocs + input_section->reloc_count;
2352 for (; rel < relend; rel++)
2354 unsigned int r_type;
2355 reloc_howto_type *howto;
2356 unsigned long r_symndx;
2357 struct elf_link_hash_entry *h;
2358 Elf_Internal_Sym *sym;
2360 bfd_vma off, offplt;
2362 bfd_boolean unresolved_reloc;
2363 bfd_reloc_status_type r;
2366 r_type = ELF64_R_TYPE (rel->r_info);
2367 if (r_type == (int) R_X86_64_GNU_VTINHERIT
2368 || r_type == (int) R_X86_64_GNU_VTENTRY)
2371 if (r_type >= R_X86_64_max)
2373 bfd_set_error (bfd_error_bad_value);
2377 howto = x86_64_elf_howto_table + r_type;
2378 r_symndx = ELF64_R_SYM (rel->r_info);
2382 unresolved_reloc = FALSE;
2383 if (r_symndx < symtab_hdr->sh_info)
2385 sym = local_syms + r_symndx;
2386 sec = local_sections[r_symndx];
2388 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2394 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2395 r_symndx, symtab_hdr, sym_hashes,
2397 unresolved_reloc, warned);
2400 if (sec != NULL && elf_discarded_section (sec))
2402 /* For relocs against symbols from removed linkonce sections,
2403 or sections discarded by a linker script, we just want the
2404 section contents zeroed. Avoid any special processing. */
2405 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2411 if (info->relocatable)
2414 /* When generating a shared object, the relocations handled here are
2415 copied into the output file to be resolved at run time. */
2419 case R_X86_64_GOT32:
2420 case R_X86_64_GOT64:
2421 /* Relocation is to the entry for this symbol in the global
2423 case R_X86_64_GOTPCREL:
2424 case R_X86_64_GOTPCREL64:
2425 /* Use global offset table entry as symbol value. */
2426 case R_X86_64_GOTPLT64:
2427 /* This is the same as GOT64 for relocation purposes, but
2428 indicates the existence of a PLT entry. The difficulty is,
2429 that we must calculate the GOT slot offset from the PLT
2430 offset, if this symbol got a PLT entry (it was global).
2431 Additionally if it's computed from the PLT entry, then that
2432 GOT offset is relative to .got.plt, not to .got. */
2433 base_got = htab->sgot;
2435 if (htab->sgot == NULL)
2442 off = h->got.offset;
2444 && h->plt.offset != (bfd_vma)-1
2445 && off == (bfd_vma)-1)
2447 /* We can't use h->got.offset here to save
2448 state, or even just remember the offset, as
2449 finish_dynamic_symbol would use that as offset into
2451 bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
2452 off = (plt_index + 3) * GOT_ENTRY_SIZE;
2453 base_got = htab->sgotplt;
2456 dyn = htab->elf.dynamic_sections_created;
2458 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2460 && SYMBOL_REFERENCES_LOCAL (info, h))
2461 || (ELF_ST_VISIBILITY (h->other)
2462 && h->root.type == bfd_link_hash_undefweak))
2464 /* This is actually a static link, or it is a -Bsymbolic
2465 link and the symbol is defined locally, or the symbol
2466 was forced to be local because of a version file. We
2467 must initialize this entry in the global offset table.
2468 Since the offset must always be a multiple of 8, we
2469 use the least significant bit to record whether we
2470 have initialized it already.
2472 When doing a dynamic link, we create a .rela.got
2473 relocation entry to initialize the value. This is
2474 done in the finish_dynamic_symbol routine. */
2479 bfd_put_64 (output_bfd, relocation,
2480 base_got->contents + off);
2481 /* Note that this is harmless for the GOTPLT64 case,
2482 as -1 | 1 still is -1. */
2487 unresolved_reloc = FALSE;
2491 if (local_got_offsets == NULL)
2494 off = local_got_offsets[r_symndx];
2496 /* The offset must always be a multiple of 8. We use
2497 the least significant bit to record whether we have
2498 already generated the necessary reloc. */
2503 bfd_put_64 (output_bfd, relocation,
2504 base_got->contents + off);
2509 Elf_Internal_Rela outrel;
2512 /* We need to generate a R_X86_64_RELATIVE reloc
2513 for the dynamic linker. */
2518 outrel.r_offset = (base_got->output_section->vma
2519 + base_got->output_offset
2521 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
2522 outrel.r_addend = relocation;
2524 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
2525 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2528 local_got_offsets[r_symndx] |= 1;
2532 if (off >= (bfd_vma) -2)
2535 relocation = base_got->output_section->vma
2536 + base_got->output_offset + off;
2537 if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
2538 relocation -= htab->sgotplt->output_section->vma
2539 - htab->sgotplt->output_offset;
2543 case R_X86_64_GOTOFF64:
2544 /* Relocation is relative to the start of the global offset
2547 /* Check to make sure it isn't a protected function symbol
2548 for shared library since it may not be local when used
2549 as function address. */
2553 && h->type == STT_FUNC
2554 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
2556 (*_bfd_error_handler)
2557 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
2558 input_bfd, h->root.root.string);
2559 bfd_set_error (bfd_error_bad_value);
2563 /* Note that sgot is not involved in this
2564 calculation. We always want the start of .got.plt. If we
2565 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2566 permitted by the ABI, we might have to change this
2568 relocation -= htab->sgotplt->output_section->vma
2569 + htab->sgotplt->output_offset;
2572 case R_X86_64_GOTPC32:
2573 case R_X86_64_GOTPC64:
2574 /* Use global offset table as symbol value. */
2575 relocation = htab->sgotplt->output_section->vma
2576 + htab->sgotplt->output_offset;
2577 unresolved_reloc = FALSE;
2580 case R_X86_64_PLTOFF64:
2581 /* Relocation is PLT entry relative to GOT. For local
2582 symbols it's the symbol itself relative to GOT. */
2584 /* See PLT32 handling. */
2585 && h->plt.offset != (bfd_vma) -1
2586 && htab->splt != NULL)
2588 relocation = (htab->splt->output_section->vma
2589 + htab->splt->output_offset
2591 unresolved_reloc = FALSE;
2594 relocation -= htab->sgotplt->output_section->vma
2595 + htab->sgotplt->output_offset;
2598 case R_X86_64_PLT32:
2599 /* Relocation is to the entry for this symbol in the
2600 procedure linkage table. */
2602 /* Resolve a PLT32 reloc against a local symbol directly,
2603 without using the procedure linkage table. */
2607 if (h->plt.offset == (bfd_vma) -1
2608 || htab->splt == NULL)
2610 /* We didn't make a PLT entry for this symbol. This
2611 happens when statically linking PIC code, or when
2612 using -Bsymbolic. */
2616 relocation = (htab->splt->output_section->vma
2617 + htab->splt->output_offset
2619 unresolved_reloc = FALSE;
2626 && (input_section->flags & SEC_ALLOC) != 0
2627 && (input_section->flags & SEC_READONLY) != 0
2630 bfd_boolean fail = FALSE;
2632 = (r_type == R_X86_64_PC32
2633 && is_32bit_relative_branch (contents, rel->r_offset));
2635 if (SYMBOL_REFERENCES_LOCAL (info, h))
2637 /* Symbol is referenced locally. Make sure it is
2638 defined locally or for a branch. */
2639 fail = !h->def_regular && !branch;
2643 /* Symbol isn't referenced locally. We only allow
2644 branch to symbol with non-default visibility. */
2646 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
2653 const char *pic = "";
2655 switch (ELF_ST_VISIBILITY (h->other))
2658 v = _("hidden symbol");
2661 v = _("internal symbol");
2664 v = _("protected symbol");
2668 pic = _("; recompile with -fPIC");
2673 fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
2675 fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
2677 (*_bfd_error_handler) (fmt, input_bfd,
2678 x86_64_elf_howto_table[r_type].name,
2679 v, h->root.root.string, pic);
2680 bfd_set_error (bfd_error_bad_value);
2691 /* FIXME: The ABI says the linker should make sure the value is
2692 the same when it's zeroextended to 64 bit. */
2694 if ((input_section->flags & SEC_ALLOC) == 0)
2699 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2700 || h->root.type != bfd_link_hash_undefweak)
2701 && (! IS_X86_64_PCREL_TYPE (r_type)
2702 || ! SYMBOL_CALLS_LOCAL (info, h)))
2706 && ! h->forced_local
2707 && ((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs != NULL
2708 && _bfd_elf_is_ifunc_symbol (output_bfd, h))
2709 || (ELIMINATE_COPY_RELOCS
2716 || h->root.type == bfd_link_hash_undefweak
2717 || h->root.type == bfd_link_hash_undefined)))
2719 Elf_Internal_Rela outrel;
2721 bfd_boolean skip, relocate;
2724 /* When generating a shared object, these relocations
2725 are copied into the output file to be resolved at run
2731 _bfd_elf_section_offset (output_bfd, info, input_section,
2733 if (outrel.r_offset == (bfd_vma) -1)
2735 else if (outrel.r_offset == (bfd_vma) -2)
2736 skip = TRUE, relocate = TRUE;
2738 outrel.r_offset += (input_section->output_section->vma
2739 + input_section->output_offset);
2742 memset (&outrel, 0, sizeof outrel);
2744 /* h->dynindx may be -1 if this symbol was marked to
2748 && (IS_X86_64_PCREL_TYPE (r_type)
2750 || ! SYMBOLIC_BIND (info, h)
2751 || ! h->def_regular))
2753 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2754 outrel.r_addend = rel->r_addend;
2758 /* This symbol is local, or marked to become local. */
2759 if (r_type == R_X86_64_64)
2762 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
2763 outrel.r_addend = relocation + rel->r_addend;
2769 if (bfd_is_abs_section (sec))
2771 else if (sec == NULL || sec->owner == NULL)
2773 bfd_set_error (bfd_error_bad_value);
2780 /* We are turning this relocation into one
2781 against a section symbol. It would be
2782 proper to subtract the symbol's value,
2783 osec->vma, from the emitted reloc addend,
2784 but ld.so expects buggy relocs. */
2785 osec = sec->output_section;
2786 sindx = elf_section_data (osec)->dynindx;
2789 asection *oi = htab->elf.text_index_section;
2790 sindx = elf_section_data (oi)->dynindx;
2792 BFD_ASSERT (sindx != 0);
2795 outrel.r_info = ELF64_R_INFO (sindx, r_type);
2796 outrel.r_addend = relocation + rel->r_addend;
2803 && ! h->forced_local
2804 && _bfd_elf_is_ifunc_symbol (output_bfd, h)
2805 && elf_section_data (input_section)->indirect_relocs != NULL
2806 && elf_section_data (input_section)->indirect_relocs->contents != NULL)
2807 sreloc = elf_section_data (input_section)->indirect_relocs;
2809 sreloc = elf_section_data (input_section)->sreloc;
2811 BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
2813 loc = sreloc->contents;
2814 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
2815 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2817 /* If this reloc is against an external symbol, we do
2818 not want to fiddle with the addend. Otherwise, we
2819 need to include the symbol value so that it becomes
2820 an addend for the dynamic reloc. */
2827 case R_X86_64_TLSGD:
2828 case R_X86_64_GOTPC32_TLSDESC:
2829 case R_X86_64_TLSDESC_CALL:
2830 case R_X86_64_GOTTPOFF:
2831 tls_type = GOT_UNKNOWN;
2832 if (h == NULL && local_got_offsets)
2833 tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx];
2835 tls_type = elf64_x86_64_hash_entry (h)->tls_type;
2837 if (! elf64_x86_64_tls_transition (info, input_bfd,
2838 input_section, contents,
2839 symtab_hdr, sym_hashes,
2840 &r_type, tls_type, rel,
2844 if (r_type == R_X86_64_TPOFF32)
2846 bfd_vma roff = rel->r_offset;
2848 BFD_ASSERT (! unresolved_reloc);
2850 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
2852 /* GD->LE transition.
2853 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2854 .word 0x6666; rex64; call __tls_get_addr
2857 leaq foo@tpoff(%rax), %rax */
2858 memcpy (contents + roff - 4,
2859 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
2861 bfd_put_32 (output_bfd,
2862 elf64_x86_64_tpoff (info, relocation),
2863 contents + roff + 8);
2864 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
2868 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
2870 /* GDesc -> LE transition.
2871 It's originally something like:
2872 leaq x@tlsdesc(%rip), %rax
2878 unsigned int val, type, type2;
2880 type = bfd_get_8 (input_bfd, contents + roff - 3);
2881 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
2882 val = bfd_get_8 (input_bfd, contents + roff - 1);
2883 bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),
2884 contents + roff - 3);
2885 bfd_put_8 (output_bfd, 0xc7, contents + roff - 2);
2886 bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
2887 contents + roff - 1);
2888 bfd_put_32 (output_bfd,
2889 elf64_x86_64_tpoff (info, relocation),
2893 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
2895 /* GDesc -> LE transition.
2900 bfd_put_8 (output_bfd, 0x66, contents + roff);
2901 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
2904 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF)
2906 /* IE->LE transition:
2907 Originally it can be one of:
2908 movq foo@gottpoff(%rip), %reg
2909 addq foo@gottpoff(%rip), %reg
2912 leaq foo(%reg), %reg
2915 unsigned int val, type, reg;
2917 val = bfd_get_8 (input_bfd, contents + roff - 3);
2918 type = bfd_get_8 (input_bfd, contents + roff - 2);
2919 reg = bfd_get_8 (input_bfd, contents + roff - 1);
2925 bfd_put_8 (output_bfd, 0x49,
2926 contents + roff - 3);
2927 bfd_put_8 (output_bfd, 0xc7,
2928 contents + roff - 2);
2929 bfd_put_8 (output_bfd, 0xc0 | reg,
2930 contents + roff - 1);
2934 /* addq -> addq - addressing with %rsp/%r12 is
2937 bfd_put_8 (output_bfd, 0x49,
2938 contents + roff - 3);
2939 bfd_put_8 (output_bfd, 0x81,
2940 contents + roff - 2);
2941 bfd_put_8 (output_bfd, 0xc0 | reg,
2942 contents + roff - 1);
2948 bfd_put_8 (output_bfd, 0x4d,
2949 contents + roff - 3);
2950 bfd_put_8 (output_bfd, 0x8d,
2951 contents + roff - 2);
2952 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),
2953 contents + roff - 1);
2955 bfd_put_32 (output_bfd,
2956 elf64_x86_64_tpoff (info, relocation),
2964 if (htab->sgot == NULL)
2969 off = h->got.offset;
2970 offplt = elf64_x86_64_hash_entry (h)->tlsdesc_got;
2974 if (local_got_offsets == NULL)
2977 off = local_got_offsets[r_symndx];
2978 offplt = local_tlsdesc_gotents[r_symndx];
2985 Elf_Internal_Rela outrel;
2990 if (htab->srelgot == NULL)
2993 indx = h && h->dynindx != -1 ? h->dynindx : 0;
2995 if (GOT_TLS_GDESC_P (tls_type))
2997 outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC);
2998 BFD_ASSERT (htab->sgotplt_jump_table_size + offplt
2999 + 2 * GOT_ENTRY_SIZE <= htab->sgotplt->size);
3000 outrel.r_offset = (htab->sgotplt->output_section->vma
3001 + htab->sgotplt->output_offset
3003 + htab->sgotplt_jump_table_size);
3004 sreloc = htab->srelplt;
3005 loc = sreloc->contents;
3006 loc += sreloc->reloc_count++
3007 * sizeof (Elf64_External_Rela);
3008 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3009 <= sreloc->contents + sreloc->size);
3011 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3013 outrel.r_addend = 0;
3014 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3017 sreloc = htab->srelgot;
3019 outrel.r_offset = (htab->sgot->output_section->vma
3020 + htab->sgot->output_offset + off);
3022 if (GOT_TLS_GD_P (tls_type))
3023 dr_type = R_X86_64_DTPMOD64;
3024 else if (GOT_TLS_GDESC_P (tls_type))
3027 dr_type = R_X86_64_TPOFF64;
3029 bfd_put_64 (output_bfd, 0, htab->sgot->contents + off);
3030 outrel.r_addend = 0;
3031 if ((dr_type == R_X86_64_TPOFF64
3032 || dr_type == R_X86_64_TLSDESC) && indx == 0)
3033 outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info);
3034 outrel.r_info = ELF64_R_INFO (indx, dr_type);
3036 loc = sreloc->contents;
3037 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
3038 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3039 <= sreloc->contents + sreloc->size);
3040 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3042 if (GOT_TLS_GD_P (tls_type))
3046 BFD_ASSERT (! unresolved_reloc);
3047 bfd_put_64 (output_bfd,
3048 relocation - elf64_x86_64_dtpoff_base (info),
3049 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3053 bfd_put_64 (output_bfd, 0,
3054 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3055 outrel.r_info = ELF64_R_INFO (indx,
3057 outrel.r_offset += GOT_ENTRY_SIZE;
3058 sreloc->reloc_count++;
3059 loc += sizeof (Elf64_External_Rela);
3060 BFD_ASSERT (loc + sizeof (Elf64_External_Rela)
3061 <= sreloc->contents + sreloc->size);
3062 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3070 local_got_offsets[r_symndx] |= 1;
3073 if (off >= (bfd_vma) -2
3074 && ! GOT_TLS_GDESC_P (tls_type))
3076 if (r_type == ELF64_R_TYPE (rel->r_info))
3078 if (r_type == R_X86_64_GOTPC32_TLSDESC
3079 || r_type == R_X86_64_TLSDESC_CALL)
3080 relocation = htab->sgotplt->output_section->vma
3081 + htab->sgotplt->output_offset
3082 + offplt + htab->sgotplt_jump_table_size;
3084 relocation = htab->sgot->output_section->vma
3085 + htab->sgot->output_offset + off;
3086 unresolved_reloc = FALSE;
3090 bfd_vma roff = rel->r_offset;
3092 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD)
3094 /* GD->IE transition.
3095 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3096 .word 0x6666; rex64; call __tls_get_addr@plt
3099 addq foo@gottpoff(%rip), %rax */
3100 memcpy (contents + roff - 4,
3101 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3104 relocation = (htab->sgot->output_section->vma
3105 + htab->sgot->output_offset + off
3107 - input_section->output_section->vma
3108 - input_section->output_offset
3110 bfd_put_32 (output_bfd, relocation,
3111 contents + roff + 8);
3112 /* Skip R_X86_64_PLT32. */
3116 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC)
3118 /* GDesc -> IE transition.
3119 It's originally something like:
3120 leaq x@tlsdesc(%rip), %rax
3123 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax
3126 unsigned int val, type, type2;
3128 type = bfd_get_8 (input_bfd, contents + roff - 3);
3129 type2 = bfd_get_8 (input_bfd, contents + roff - 2);
3130 val = bfd_get_8 (input_bfd, contents + roff - 1);
3132 /* Now modify the instruction as appropriate. To
3133 turn a leaq into a movq in the form we use it, it
3134 suffices to change the second byte from 0x8d to
3136 bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
3138 bfd_put_32 (output_bfd,
3139 htab->sgot->output_section->vma
3140 + htab->sgot->output_offset + off
3142 - input_section->output_section->vma
3143 - input_section->output_offset
3148 else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL)
3150 /* GDesc -> IE transition.
3157 unsigned int val, type;
3159 type = bfd_get_8 (input_bfd, contents + roff);
3160 val = bfd_get_8 (input_bfd, contents + roff + 1);
3161 bfd_put_8 (output_bfd, 0x66, contents + roff);
3162 bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
3170 case R_X86_64_TLSLD:
3171 if (! elf64_x86_64_tls_transition (info, input_bfd,
3172 input_section, contents,
3173 symtab_hdr, sym_hashes,
3174 &r_type, GOT_UNKNOWN,
3178 if (r_type != R_X86_64_TLSLD)
3180 /* LD->LE transition:
3181 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3183 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3185 BFD_ASSERT (r_type == R_X86_64_TPOFF32);
3186 memcpy (contents + rel->r_offset - 3,
3187 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3188 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3193 if (htab->sgot == NULL)
3196 off = htab->tls_ld_got.offset;
3201 Elf_Internal_Rela outrel;
3204 if (htab->srelgot == NULL)
3207 outrel.r_offset = (htab->sgot->output_section->vma
3208 + htab->sgot->output_offset + off);
3210 bfd_put_64 (output_bfd, 0,
3211 htab->sgot->contents + off);
3212 bfd_put_64 (output_bfd, 0,
3213 htab->sgot->contents + off + GOT_ENTRY_SIZE);
3214 outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64);
3215 outrel.r_addend = 0;
3216 loc = htab->srelgot->contents;
3217 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3218 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3219 htab->tls_ld_got.offset |= 1;
3221 relocation = htab->sgot->output_section->vma
3222 + htab->sgot->output_offset + off;
3223 unresolved_reloc = FALSE;
3226 case R_X86_64_DTPOFF32:
3227 if (info->shared || (input_section->flags & SEC_CODE) == 0)
3228 relocation -= elf64_x86_64_dtpoff_base (info);
3230 relocation = elf64_x86_64_tpoff (info, relocation);
3233 case R_X86_64_TPOFF32:
3234 BFD_ASSERT (! info->shared);
3235 relocation = elf64_x86_64_tpoff (info, relocation);
3242 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3243 because such sections are not SEC_ALLOC and thus ld.so will
3244 not process them. */
3245 if (unresolved_reloc
3246 && !((input_section->flags & SEC_DEBUGGING) != 0
3248 (*_bfd_error_handler)
3249 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3252 (long) rel->r_offset,
3254 h->root.root.string);
3256 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3257 contents, rel->r_offset,
3258 relocation, rel->r_addend);
3260 if (r != bfd_reloc_ok)
3265 name = h->root.root.string;
3268 name = bfd_elf_string_from_elf_section (input_bfd,
3269 symtab_hdr->sh_link,
3274 name = bfd_section_name (input_bfd, sec);
3277 if (r == bfd_reloc_overflow)
3279 if (! ((*info->callbacks->reloc_overflow)
3280 (info, (h ? &h->root : NULL), name, howto->name,
3281 (bfd_vma) 0, input_bfd, input_section,
3287 (*_bfd_error_handler)
3288 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3289 input_bfd, input_section,
3290 (long) rel->r_offset, name, (int) r);
3299 /* Finish up dynamic symbol handling. We set the contents of various
3300 dynamic sections here. */
3303 elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
3304 struct bfd_link_info *info,
3305 struct elf_link_hash_entry *h,
3306 Elf_Internal_Sym *sym)
3308 struct elf64_x86_64_link_hash_table *htab;
3310 htab = elf64_x86_64_hash_table (info);
3312 if (h->plt.offset != (bfd_vma) -1)
3316 Elf_Internal_Rela rela;
3319 /* This symbol has an entry in the procedure linkage table. Set
3321 if (h->dynindx == -1
3322 || htab->splt == NULL
3323 || htab->sgotplt == NULL
3324 || htab->srelplt == NULL)
3327 /* Get the index in the procedure linkage table which
3328 corresponds to this symbol. This is the index of this symbol
3329 in all the symbols for which we are making plt entries. The
3330 first entry in the procedure linkage table is reserved. */
3331 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
3333 /* Get the offset into the .got table of the entry that
3334 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3335 bytes. The first three are reserved for the dynamic linker. */
3336 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
3338 /* Fill in the entry in the procedure linkage table. */
3339 memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
3342 /* Insert the relocation positions of the plt section. The magic
3343 numbers at the end of the statements are the positions of the
3344 relocations in the plt section. */
3345 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3346 instruction uses 6 bytes, subtract this value. */
3347 bfd_put_32 (output_bfd,
3348 (htab->sgotplt->output_section->vma
3349 + htab->sgotplt->output_offset
3351 - htab->splt->output_section->vma
3352 - htab->splt->output_offset
3355 htab->splt->contents + h->plt.offset + 2);
3356 /* Put relocation index. */
3357 bfd_put_32 (output_bfd, plt_index,
3358 htab->splt->contents + h->plt.offset + 7);
3359 /* Put offset for jmp .PLT0. */
3360 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
3361 htab->splt->contents + h->plt.offset + 12);
3363 /* Fill in the entry in the global offset table, initially this
3364 points to the pushq instruction in the PLT which is at offset 6. */
3365 bfd_put_64 (output_bfd, (htab->splt->output_section->vma
3366 + htab->splt->output_offset
3367 + h->plt.offset + 6),
3368 htab->sgotplt->contents + got_offset);
3370 /* Fill in the entry in the .rela.plt section. */
3371 rela.r_offset = (htab->sgotplt->output_section->vma
3372 + htab->sgotplt->output_offset
3374 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
3376 loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela);
3377 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3379 if (!h->def_regular)
3381 /* Mark the symbol as undefined, rather than as defined in
3382 the .plt section. Leave the value if there were any
3383 relocations where pointer equality matters (this is a clue
3384 for the dynamic linker, to make function pointer
3385 comparisons work between an application and shared
3386 library), otherwise set it to zero. If a function is only
3387 called from a binary, there is no need to slow down
3388 shared libraries because of that. */
3389 sym->st_shndx = SHN_UNDEF;
3390 if (!h->pointer_equality_needed)
3395 if (h->got.offset != (bfd_vma) -1
3396 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type)
3397 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE)
3399 Elf_Internal_Rela rela;
3402 /* This symbol has an entry in the global offset table. Set it
3404 if (htab->sgot == NULL || htab->srelgot == NULL)
3407 rela.r_offset = (htab->sgot->output_section->vma
3408 + htab->sgot->output_offset
3409 + (h->got.offset &~ (bfd_vma) 1));
3411 /* If this is a static link, or it is a -Bsymbolic link and the
3412 symbol is defined locally or was forced to be local because
3413 of a version file, we just want to emit a RELATIVE reloc.
3414 The entry in the global offset table will already have been
3415 initialized in the relocate_section function. */
3417 && SYMBOL_REFERENCES_LOCAL (info, h))
3419 if (!h->def_regular)
3421 BFD_ASSERT((h->got.offset & 1) != 0);
3422 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
3423 rela.r_addend = (h->root.u.def.value
3424 + h->root.u.def.section->output_section->vma
3425 + h->root.u.def.section->output_offset);
3429 BFD_ASSERT((h->got.offset & 1) == 0);
3430 bfd_put_64 (output_bfd, (bfd_vma) 0,
3431 htab->sgot->contents + h->got.offset);
3432 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
3436 loc = htab->srelgot->contents;
3437 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3438 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3443 Elf_Internal_Rela rela;
3446 /* This symbol needs a copy reloc. Set it up. */
3448 if (h->dynindx == -1
3449 || (h->root.type != bfd_link_hash_defined
3450 && h->root.type != bfd_link_hash_defweak)
3451 || htab->srelbss == NULL)
3454 rela.r_offset = (h->root.u.def.value
3455 + h->root.u.def.section->output_section->vma
3456 + h->root.u.def.section->output_offset);
3457 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
3459 loc = htab->srelbss->contents;
3460 loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
3461 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3464 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3465 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3466 || h == htab->elf.hgot)
3467 sym->st_shndx = SHN_ABS;
3472 /* Used to decide how to sort relocs in an optimal manner for the
3473 dynamic linker, before writing them out. */
3475 static enum elf_reloc_type_class
3476 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela)
3478 switch ((int) ELF64_R_TYPE (rela->r_info))
3480 case R_X86_64_RELATIVE:
3481 return reloc_class_relative;
3482 case R_X86_64_JUMP_SLOT:
3483 return reloc_class_plt;
3485 return reloc_class_copy;
3487 return reloc_class_normal;
3491 /* Finish up the dynamic sections. */
3494 elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3496 struct elf64_x86_64_link_hash_table *htab;
3500 htab = elf64_x86_64_hash_table (info);
3501 dynobj = htab->elf.dynobj;
3502 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3504 if (htab->elf.dynamic_sections_created)
3506 Elf64_External_Dyn *dyncon, *dynconend;
3508 if (sdyn == NULL || htab->sgot == NULL)
3511 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3512 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3513 for (; dyncon < dynconend; dyncon++)
3515 Elf_Internal_Dyn dyn;
3518 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3527 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3531 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
3535 s = htab->srelplt->output_section;
3536 dyn.d_un.d_val = s->size;
3540 /* The procedure linkage table relocs (DT_JMPREL) should
3541 not be included in the overall relocs (DT_RELA).
3542 Therefore, we override the DT_RELASZ entry here to
3543 make it not include the JMPREL relocs. Since the
3544 linker script arranges for .rela.plt to follow all
3545 other relocation sections, we don't have to worry
3546 about changing the DT_RELA entry. */
3547 if (htab->srelplt != NULL)
3549 s = htab->srelplt->output_section;
3550 dyn.d_un.d_val -= s->size;
3554 case DT_TLSDESC_PLT:
3556 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
3557 + htab->tlsdesc_plt;
3560 case DT_TLSDESC_GOT:
3562 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
3563 + htab->tlsdesc_got;
3567 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3570 /* Fill in the special first entry in the procedure linkage table. */
3571 if (htab->splt && htab->splt->size > 0)
3573 /* Fill in the first entry in the procedure linkage table. */
3574 memcpy (htab->splt->contents, elf64_x86_64_plt0_entry,
3576 /* Add offset for pushq GOT+8(%rip), since the instruction
3577 uses 6 bytes subtract this value. */
3578 bfd_put_32 (output_bfd,
3579 (htab->sgotplt->output_section->vma
3580 + htab->sgotplt->output_offset
3582 - htab->splt->output_section->vma
3583 - htab->splt->output_offset
3585 htab->splt->contents + 2);
3586 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
3587 the end of the instruction. */
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 + 8);
3597 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize =
3600 if (htab->tlsdesc_plt)
3602 bfd_put_64 (output_bfd, (bfd_vma) 0,
3603 htab->sgot->contents + htab->tlsdesc_got);
3605 memcpy (htab->splt->contents + htab->tlsdesc_plt,
3606 elf64_x86_64_plt0_entry,
3609 /* Add offset for pushq GOT+8(%rip), since the
3610 instruction uses 6 bytes subtract this value. */
3611 bfd_put_32 (output_bfd,
3612 (htab->sgotplt->output_section->vma
3613 + htab->sgotplt->output_offset
3615 - htab->splt->output_section->vma
3616 - htab->splt->output_offset
3619 htab->splt->contents + htab->tlsdesc_plt + 2);
3620 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
3621 htab->tlsdesc_got. The 12 is the offset to the end of
3623 bfd_put_32 (output_bfd,
3624 (htab->sgot->output_section->vma
3625 + htab->sgot->output_offset
3627 - htab->splt->output_section->vma
3628 - htab->splt->output_offset
3631 htab->splt->contents + htab->tlsdesc_plt + 8);
3638 /* Fill in the first three entries in the global offset table. */
3639 if (htab->sgotplt->size > 0)
3641 /* Set the first entry in the global offset table to the address of
3642 the dynamic section. */
3644 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents);
3646 bfd_put_64 (output_bfd,
3647 sdyn->output_section->vma + sdyn->output_offset,
3648 htab->sgotplt->contents);
3649 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
3650 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE);
3651 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2);
3654 elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize =
3658 if (htab->sgot && htab->sgot->size > 0)
3659 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize
3665 /* Return address for Ith PLT stub in section PLT, for relocation REL
3666 or (bfd_vma) -1 if it should not be included. */
3669 elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt,
3670 const arelent *rel ATTRIBUTE_UNUSED)
3672 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
3675 /* Handle an x86-64 specific section when reading an object file. This
3676 is called when elfcode.h finds a section with an unknown type. */
3679 elf64_x86_64_section_from_shdr (bfd *abfd,
3680 Elf_Internal_Shdr *hdr,
3684 if (hdr->sh_type != SHT_X86_64_UNWIND)
3687 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
3693 /* Hook called by the linker routine which adds symbols from an object
3694 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
3698 elf64_x86_64_add_symbol_hook (bfd *abfd,
3699 struct bfd_link_info *info,
3700 Elf_Internal_Sym *sym,
3701 const char **namep ATTRIBUTE_UNUSED,
3702 flagword *flagsp ATTRIBUTE_UNUSED,
3708 switch (sym->st_shndx)
3710 case SHN_X86_64_LCOMMON:
3711 lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON");
3714 lcomm = bfd_make_section_with_flags (abfd,
3718 | SEC_LINKER_CREATED));
3721 elf_section_flags (lcomm) |= SHF_X86_64_LARGE;
3724 *valp = sym->st_size;
3728 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
3729 elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
3735 /* Given a BFD section, try to locate the corresponding ELF section
3739 elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3740 asection *sec, int *index)
3742 if (sec == &_bfd_elf_large_com_section)
3744 *index = SHN_X86_64_LCOMMON;
3750 /* Process a symbol. */
3753 elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
3756 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
3758 switch (elfsym->internal_elf_sym.st_shndx)
3760 case SHN_X86_64_LCOMMON:
3761 asym->section = &_bfd_elf_large_com_section;
3762 asym->value = elfsym->internal_elf_sym.st_size;
3763 /* Common symbol doesn't set BSF_GLOBAL. */
3764 asym->flags &= ~BSF_GLOBAL;
3770 elf64_x86_64_common_definition (Elf_Internal_Sym *sym)
3772 return (sym->st_shndx == SHN_COMMON
3773 || sym->st_shndx == SHN_X86_64_LCOMMON);
3777 elf64_x86_64_common_section_index (asection *sec)
3779 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
3782 return SHN_X86_64_LCOMMON;
3786 elf64_x86_64_common_section (asection *sec)
3788 if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0)
3789 return bfd_com_section_ptr;
3791 return &_bfd_elf_large_com_section;
3795 elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3796 struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED,
3797 struct elf_link_hash_entry *h,
3798 Elf_Internal_Sym *sym,
3800 bfd_vma *pvalue ATTRIBUTE_UNUSED,
3801 unsigned int *pold_alignment ATTRIBUTE_UNUSED,
3802 bfd_boolean *skip ATTRIBUTE_UNUSED,
3803 bfd_boolean *override ATTRIBUTE_UNUSED,
3804 bfd_boolean *type_change_ok ATTRIBUTE_UNUSED,
3805 bfd_boolean *size_change_ok ATTRIBUTE_UNUSED,
3806 bfd_boolean *newdef ATTRIBUTE_UNUSED,
3807 bfd_boolean *newdyn,
3808 bfd_boolean *newdyncommon ATTRIBUTE_UNUSED,
3809 bfd_boolean *newweak ATTRIBUTE_UNUSED,
3810 bfd *abfd ATTRIBUTE_UNUSED,
3812 bfd_boolean *olddef ATTRIBUTE_UNUSED,
3813 bfd_boolean *olddyn,
3814 bfd_boolean *olddyncommon ATTRIBUTE_UNUSED,
3815 bfd_boolean *oldweak ATTRIBUTE_UNUSED,
3819 /* A normal common symbol and a large common symbol result in a
3820 normal common symbol. We turn the large common symbol into a
3823 && h->root.type == bfd_link_hash_common
3825 && bfd_is_com_section (*sec)
3828 if (sym->st_shndx == SHN_COMMON
3829 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0)
3831 h->root.u.c.p->section
3832 = bfd_make_section_old_way (oldbfd, "COMMON");
3833 h->root.u.c.p->section->flags = SEC_ALLOC;
3835 else if (sym->st_shndx == SHN_X86_64_LCOMMON
3836 && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0)
3837 *psec = *sec = bfd_com_section_ptr;
3844 elf64_x86_64_additional_program_headers (bfd *abfd,
3845 struct bfd_link_info *info ATTRIBUTE_UNUSED)
3850 /* Check to see if we need a large readonly segment. */
3851 s = bfd_get_section_by_name (abfd, ".lrodata");
3852 if (s && (s->flags & SEC_LOAD))
3855 /* Check to see if we need a large data segment. Since .lbss sections
3856 is placed right after the .bss section, there should be no need for
3857 a large data segment just because of .lbss. */
3858 s = bfd_get_section_by_name (abfd, ".ldata");
3859 if (s && (s->flags & SEC_LOAD))
3865 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3868 elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h)
3870 if (h->plt.offset != (bfd_vma) -1
3872 && !h->pointer_equality_needed)
3875 return _bfd_elf_hash_symbol (h);
3878 static const struct bfd_elf_special_section
3879 elf64_x86_64_special_sections[]=
3881 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3882 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
3883 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE},
3884 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3885 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE},
3886 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE},
3887 { NULL, 0, 0, 0, 0 }
3890 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
3891 #define TARGET_LITTLE_NAME "elf64-x86-64"
3892 #define ELF_ARCH bfd_arch_i386
3893 #define ELF_MACHINE_CODE EM_X86_64
3894 #define ELF_MAXPAGESIZE 0x200000
3895 #define ELF_MINPAGESIZE 0x1000
3896 #define ELF_COMMONPAGESIZE 0x1000
3898 #define elf_backend_can_gc_sections 1
3899 #define elf_backend_can_refcount 1
3900 #define elf_backend_want_got_plt 1
3901 #define elf_backend_plt_readonly 1
3902 #define elf_backend_want_plt_sym 0
3903 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
3904 #define elf_backend_rela_normal 1
3906 #define elf_info_to_howto elf64_x86_64_info_to_howto
3908 #define bfd_elf64_bfd_link_hash_table_create \
3909 elf64_x86_64_link_hash_table_create
3910 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
3911 #define bfd_elf64_bfd_reloc_name_lookup \
3912 elf64_x86_64_reloc_name_lookup
3914 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
3915 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
3916 #define elf_backend_check_relocs elf64_x86_64_check_relocs
3917 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
3918 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
3919 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
3920 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
3921 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
3922 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
3923 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
3924 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
3925 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
3926 #define elf_backend_relocate_section elf64_x86_64_relocate_section
3927 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
3928 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
3929 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
3930 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
3931 #define elf_backend_object_p elf64_x86_64_elf_object_p
3932 #define bfd_elf64_mkobject elf64_x86_64_mkobject
3934 #define elf_backend_section_from_shdr \
3935 elf64_x86_64_section_from_shdr
3937 #define elf_backend_section_from_bfd_section \
3938 elf64_x86_64_elf_section_from_bfd_section
3939 #define elf_backend_add_symbol_hook \
3940 elf64_x86_64_add_symbol_hook
3941 #define elf_backend_symbol_processing \
3942 elf64_x86_64_symbol_processing
3943 #define elf_backend_common_section_index \
3944 elf64_x86_64_common_section_index
3945 #define elf_backend_common_section \
3946 elf64_x86_64_common_section
3947 #define elf_backend_common_definition \
3948 elf64_x86_64_common_definition
3949 #define elf_backend_merge_symbol \
3950 elf64_x86_64_merge_symbol
3951 #define elf_backend_special_sections \
3952 elf64_x86_64_special_sections
3953 #define elf_backend_additional_program_headers \
3954 elf64_x86_64_additional_program_headers
3955 #define elf_backend_hash_symbol \
3956 elf64_x86_64_hash_symbol
3958 #undef elf_backend_post_process_headers
3959 #define elf_backend_post_process_headers _bfd_elf_set_osabi
3961 #include "elf64-target.h"
3963 /* FreeBSD support. */
3965 #undef TARGET_LITTLE_SYM
3966 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
3967 #undef TARGET_LITTLE_NAME
3968 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
3971 #define ELF_OSABI ELFOSABI_FREEBSD
3974 #define elf64_bed elf64_x86_64_fbsd_bed
3976 #include "elf64-target.h"