* elf64-mips.c (UNUSED_RELOC): Define.
[binutils.git] / bfd / elf64-x86-64.c
blobef7842145b19def6d46692aa592b1ac3e02095f2
1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
26 #include "elf/x86-64.h"
28 /* We use only the RELA entries. */
29 #define USE_RELA
31 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
32 #define MINUS_ONE (~ (bfd_vma) 0)
34 /* The relocation "howto" table. Order of fields:
35 type, size, bitsize, pc_relative, complain_on_overflow,
36 special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
37 static reloc_howto_type x86_64_elf_howto_table[] =
39 HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont,
40 bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0x00000000, 0x00000000,
41 false),
42 HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
43 bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE,
44 false),
45 HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed,
46 bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff,
47 true),
48 HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed,
49 bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff,
50 false),
51 HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed,
52 bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff,
53 true),
54 HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield,
55 bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff,
56 false),
57 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
58 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE,
59 MINUS_ONE, false),
60 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
61 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE,
62 MINUS_ONE, false),
63 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
64 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE,
65 MINUS_ONE, false),
66 HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true,0 , complain_overflow_signed,
67 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0xffffffff,
68 0xffffffff, true),
69 HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned,
70 bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
71 false),
72 HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed,
73 bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff,
74 false),
75 HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
76 bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false),
77 HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield,
78 bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true),
79 HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_signed,
80 bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),
81 HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
82 bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true),
84 /* GNU extension to record C++ vtable hierarchy. */
85 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, false, 0, complain_overflow_dont,
86 NULL, "R_X86_64_GNU_VTINHERIT", false, 0, 0, false),
88 /* GNU extension to record C++ vtable member usage. */
89 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, false, 0, complain_overflow_dont,
90 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", false, 0, 0,
91 false)
94 /* Map BFD relocs to the x86_64 elf relocs. */
95 struct elf_reloc_map
97 bfd_reloc_code_real_type bfd_reloc_val;
98 unsigned char elf_reloc_val;
101 static CONST struct elf_reloc_map x86_64_reloc_map[] =
103 { BFD_RELOC_NONE, R_X86_64_NONE, },
104 { BFD_RELOC_64, R_X86_64_64, },
105 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
106 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
107 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
108 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
109 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
110 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
111 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
112 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
113 { BFD_RELOC_32, R_X86_64_32, },
114 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
115 { BFD_RELOC_16, R_X86_64_16, },
116 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
117 { BFD_RELOC_8, R_X86_64_8, },
118 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
119 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
120 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
123 static reloc_howto_type *elf64_x86_64_reloc_type_lookup
124 PARAMS ((bfd *, bfd_reloc_code_real_type));
125 static void elf64_x86_64_info_to_howto
126 PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
127 static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create
128 PARAMS ((bfd *));
129 static boolean elf64_x86_64_elf_object_p PARAMS ((bfd *abfd));
130 static boolean elf64_x86_64_check_relocs
131 PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
132 const Elf_Internal_Rela *));
133 static asection *elf64_x86_64_gc_mark_hook
134 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
135 struct elf_link_hash_entry *, Elf_Internal_Sym *));
137 static boolean elf64_x86_64_gc_sweep_hook
138 PARAMS ((bfd *, struct bfd_link_info *, asection *,
139 const Elf_Internal_Rela *));
141 static struct bfd_hash_entry *elf64_x86_64_link_hash_newfunc
142 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
143 static boolean elf64_x86_64_adjust_dynamic_symbol
144 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
146 static boolean elf64_x86_64_size_dynamic_sections
147 PARAMS ((bfd *, struct bfd_link_info *));
148 static boolean elf64_x86_64_relocate_section
149 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
150 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
151 static boolean elf64_x86_64_finish_dynamic_symbol
152 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
153 Elf_Internal_Sym *sym));
154 static boolean elf64_x86_64_finish_dynamic_sections
155 PARAMS ((bfd *, struct bfd_link_info *));
157 /* Given a BFD reloc type, return a HOWTO structure. */
158 static reloc_howto_type *
159 elf64_x86_64_reloc_type_lookup (abfd, code)
160 bfd *abfd ATTRIBUTE_UNUSED;
161 bfd_reloc_code_real_type code;
163 unsigned int i;
164 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
165 i++)
167 if (x86_64_reloc_map[i].bfd_reloc_val == code)
168 return &x86_64_elf_howto_table[(int)
169 x86_64_reloc_map[i].elf_reloc_val];
171 return 0;
174 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
176 static void
177 elf64_x86_64_info_to_howto (abfd, cache_ptr, dst)
178 bfd *abfd ATTRIBUTE_UNUSED;
179 arelent *cache_ptr;
180 Elf64_Internal_Rela *dst;
182 unsigned r_type, i;
184 r_type = ELF64_R_TYPE (dst->r_info);
185 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT)
187 BFD_ASSERT (r_type <= (unsigned int) R_X86_64_PC8);
188 i = r_type;
190 else
192 BFD_ASSERT (r_type < (unsigned int) R_X86_64_max);
193 i = r_type - ((unsigned int) R_X86_64_GNU_VTINHERIT - R_X86_64_PC8 - 1);
195 cache_ptr->howto = &x86_64_elf_howto_table[i];
196 BFD_ASSERT (r_type == cache_ptr->howto->type);
199 /* Functions for the x86-64 ELF linker. */
201 /* The name of the dynamic interpreter. This is put in the .interp
202 section. */
204 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
206 /* The size in bytes of an entry in the global offset table. */
208 #define GOT_ENTRY_SIZE 8
210 /* The size in bytes of an entry in the procedure linkage table. */
212 #define PLT_ENTRY_SIZE 16
214 /* The first entry in a procedure linkage table looks like this. See the
215 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
217 static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
219 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
220 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
221 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
224 /* Subsequent entries in a procedure linkage table look like this. */
226 static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
228 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
229 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
230 0x68, /* pushq immediate */
231 0, 0, 0, 0, /* replaced with index into relocation table. */
232 0xe9, /* jmp relative */
233 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
236 /* The x86-64 linker needs to keep track of the number of relocs that
237 it decides to copy in check_relocs for each symbol. This is so
238 that it can discard PC relative relocs if it doesn't need them when
239 linking with -Bsymbolic. We store the information in a field
240 extending the regular ELF linker hash table. */
242 /* This structure keeps track of the number of PC relative relocs we
243 have copied for a given symbol. */
245 struct elf64_x86_64_pcrel_relocs_copied
247 /* Next section. */
248 struct elf64_x86_64_pcrel_relocs_copied *next;
249 /* A section in dynobj. */
250 asection *section;
251 /* Number of relocs copied in this section. */
252 bfd_size_type count;
255 /* x86-64 ELF linker hash entry. */
257 struct elf64_x86_64_link_hash_entry
259 struct elf_link_hash_entry root;
261 /* Number of PC relative relocs copied for this symbol. */
262 struct elf64_x86_64_pcrel_relocs_copied *pcrel_relocs_copied;
265 /* x86-64 ELF linker hash table. */
267 struct elf64_x86_64_link_hash_table
269 struct elf_link_hash_table root;
272 /* Declare this now that the above structures are defined. */
274 static boolean elf64_x86_64_discard_copies
275 PARAMS ((struct elf64_x86_64_link_hash_entry *, PTR));
277 /* Traverse an x86-64 ELF linker hash table. */
279 #define elf64_x86_64_link_hash_traverse(table, func, info) \
280 (elf_link_hash_traverse \
281 (&(table)->root, \
282 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
283 (info)))
285 /* Get the x86-64 ELF linker hash table from a link_info structure. */
287 #define elf64_x86_64_hash_table(p) \
288 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
290 /* Create an entry in an x86-64 ELF linker hash table. */
292 static struct bfd_hash_entry *
293 elf64_x86_64_link_hash_newfunc (entry, table, string)
294 struct bfd_hash_entry *entry;
295 struct bfd_hash_table *table;
296 const char *string;
298 struct elf64_x86_64_link_hash_entry *ret =
299 (struct elf64_x86_64_link_hash_entry *) entry;
301 /* Allocate the structure if it has not already been allocated by a
302 subclass. */
303 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
304 ret = ((struct elf64_x86_64_link_hash_entry *)
305 bfd_hash_allocate (table,
306 sizeof (struct elf64_x86_64_link_hash_entry)));
307 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
308 return (struct bfd_hash_entry *) ret;
310 /* Call the allocation method of the superclass. */
311 ret = ((struct elf64_x86_64_link_hash_entry *)
312 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
313 table, string));
314 if (ret != (struct elf64_x86_64_link_hash_entry *) NULL)
316 ret->pcrel_relocs_copied = NULL;
319 return (struct bfd_hash_entry *) ret;
322 /* Create an X86-64 ELF linker hash table. */
324 static struct bfd_link_hash_table *
325 elf64_x86_64_link_hash_table_create (abfd)
326 bfd *abfd;
328 struct elf64_x86_64_link_hash_table *ret;
330 ret = ((struct elf64_x86_64_link_hash_table *)
331 bfd_alloc (abfd, sizeof (struct elf64_x86_64_link_hash_table)));
332 if (ret == (struct elf64_x86_64_link_hash_table *) NULL)
333 return NULL;
335 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
336 elf64_x86_64_link_hash_newfunc))
338 bfd_release (abfd, ret);
339 return NULL;
342 return &ret->root.root;
345 static boolean
346 elf64_x86_64_elf_object_p (abfd)
347 bfd *abfd;
349 /* Set the right machine number for an x86-64 elf64 file. */
350 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
351 return true;
354 /* Look through the relocs for a section during the first phase, and
355 allocate space in the global offset table or procedure linkage
356 table. */
358 static boolean
359 elf64_x86_64_check_relocs (abfd, info, sec, relocs)
360 bfd *abfd;
361 struct bfd_link_info *info;
362 asection *sec;
363 const Elf_Internal_Rela *relocs;
365 bfd *dynobj;
366 Elf_Internal_Shdr *symtab_hdr;
367 struct elf_link_hash_entry **sym_hashes;
368 bfd_signed_vma *local_got_refcounts;
369 const Elf_Internal_Rela *rel;
370 const Elf_Internal_Rela *rel_end;
371 asection *sgot;
372 asection *srelgot;
373 asection *sreloc;
375 if (info->relocateable)
376 return true;
378 dynobj = elf_hash_table (info)->dynobj;
379 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
380 sym_hashes = elf_sym_hashes (abfd);
381 local_got_refcounts = elf_local_got_refcounts (abfd);
383 sgot = srelgot = sreloc = NULL;
384 rel_end = relocs + sec->reloc_count;
385 for (rel = relocs; rel < rel_end; rel++)
387 unsigned long r_symndx;
388 struct elf_link_hash_entry *h;
390 r_symndx = ELF64_R_SYM (rel->r_info);
391 if (r_symndx < symtab_hdr->sh_info)
392 h = NULL;
393 else
394 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
396 /* Some relocs require a global offset table. */
397 if (dynobj == NULL)
399 switch (ELF64_R_TYPE (rel->r_info))
401 case R_X86_64_GOT32:
402 case R_X86_64_GOTPCREL:
403 elf_hash_table (info)->dynobj = dynobj = abfd;
404 if (! _bfd_elf_create_got_section (dynobj, info))
405 return false;
406 break;
410 switch (ELF64_R_TYPE (rel->r_info))
412 case R_X86_64_GOTPCREL:
413 case R_X86_64_GOT32:
414 /* This symbol requires a global offset table entry. */
416 if (sgot == NULL)
418 sgot = bfd_get_section_by_name (dynobj, ".got");
419 BFD_ASSERT (sgot != NULL);
422 if (srelgot == NULL && (h != NULL || info->shared))
424 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
425 if (srelgot == NULL)
427 srelgot = bfd_make_section (dynobj, ".rela.got");
428 if (srelgot == NULL
429 || ! bfd_set_section_flags (dynobj, srelgot,
430 (SEC_ALLOC
431 | SEC_LOAD
432 | SEC_HAS_CONTENTS
433 | SEC_IN_MEMORY
434 | SEC_LINKER_CREATED
435 | SEC_READONLY))
436 || ! bfd_set_section_alignment (dynobj, srelgot, 3))
437 return false;
441 if (h != NULL)
443 if (h->got.refcount == -1)
445 h->got.refcount = 1;
447 /* Make sure this symbol is output as a dynamic symbol. */
448 if (h->dynindx == -1)
450 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
451 return false;
454 sgot->_raw_size += GOT_ENTRY_SIZE;
455 srelgot->_raw_size += sizeof (Elf64_External_Rela);
457 else
458 h->got.refcount += 1;
460 else
462 /* This is a global offset table entry for a local symbol. */
463 if (local_got_refcounts == NULL)
465 size_t size;
467 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
468 local_got_refcounts = ((bfd_signed_vma *)
469 bfd_alloc (abfd, size));
470 if (local_got_refcounts == NULL)
471 return false;
472 elf_local_got_refcounts (abfd) = local_got_refcounts;
473 memset (local_got_refcounts, -1, size);
475 if (local_got_refcounts[r_symndx] == -1)
477 local_got_refcounts[r_symndx] = 1;
479 sgot->_raw_size += GOT_ENTRY_SIZE;
480 if (info->shared)
482 /* If we are generating a shared object, we need to
483 output a R_X86_64_RELATIVE reloc so that the dynamic
484 linker can adjust this GOT entry. */
485 srelgot->_raw_size += sizeof (Elf64_External_Rela);
488 else
489 local_got_refcounts[r_symndx] += 1;
491 break;
493 case R_X86_64_PLT32:
494 /* This symbol requires a procedure linkage table entry. We
495 actually build the entry in adjust_dynamic_symbol,
496 because this might be a case of linking PIC code which is
497 never referenced by a dynamic object, in which case we
498 don't need to generate a procedure linkage table entry
499 after all. */
501 /* If this is a local symbol, we resolve it directly without
502 creating a procedure linkage table entry. */
503 if (h == NULL)
504 continue;
506 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
507 if (h->plt.refcount == -1)
508 h->plt.refcount = 1;
509 else
510 h->plt.refcount += 1;
511 break;
513 case R_X86_64_8:
514 case R_X86_64_16:
515 case R_X86_64_32:
516 case R_X86_64_64:
517 case R_X86_64_32S:
518 case R_X86_64_PC32:
519 if (h != NULL)
520 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
522 /* If we are creating a shared library, and this is a reloc
523 against a global symbol, or a non PC relative reloc
524 against a local symbol, then we need to copy the reloc
525 into the shared library. However, if we are linking with
526 -Bsymbolic, we do not need to copy a reloc against a
527 global symbol which is defined in an object we are
528 including in the link (i.e., DEF_REGULAR is set). At
529 this point we have not seen all the input files, so it is
530 possible that DEF_REGULAR is not set now but will be set
531 later (it is never cleared). We account for that
532 possibility below by storing information in the
533 pcrel_relocs_copied field of the hash table entry.
534 A similar situation occurs when creating shared libraries
535 and symbol visibility changes render the symbol local. */
536 if (info->shared
537 && (sec->flags & SEC_ALLOC) != 0
538 && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8)
539 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16)
540 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32))
541 || (h != NULL
542 && (! info->symbolic
543 || (h->elf_link_hash_flags
544 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
546 /* When creating a shared object, we must copy these
547 reloc types into the output file. We create a reloc
548 section in dynobj and make room for this reloc. */
549 if (sreloc == NULL)
551 const char *name;
553 name = (bfd_elf_string_from_elf_section
554 (abfd,
555 elf_elfheader (abfd)->e_shstrndx,
556 elf_section_data (sec)->rel_hdr.sh_name));
557 if (name == NULL)
558 return false;
560 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
561 && strcmp (bfd_get_section_name (abfd, sec),
562 name + 5) == 0);
564 sreloc = bfd_get_section_by_name (dynobj, name);
565 if (sreloc == NULL)
567 flagword flags;
569 sreloc = bfd_make_section (dynobj, name);
570 flags = (SEC_HAS_CONTENTS | SEC_READONLY
571 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
572 if ((sec->flags & SEC_ALLOC) != 0)
573 flags |= SEC_ALLOC | SEC_LOAD;
574 if (sreloc == NULL
575 || ! bfd_set_section_flags (dynobj, sreloc, flags)
576 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
577 return false;
581 sreloc->_raw_size += sizeof (Elf64_External_Rela);
583 /* If this is a global symbol, we count the number of PC
584 relative relocations we have entered for this symbol,
585 so that we can discard them later as necessary. Note
586 that this function is only called if we are using an
587 elf64_x86_64 linker hash table, which means that h is
588 really a pointer to an elf64_x86_64_link_hash_entry. */
589 if (h != NULL
590 && ((ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8)
591 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16)
592 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)))
594 struct elf64_x86_64_link_hash_entry *eh;
595 struct elf64_x86_64_pcrel_relocs_copied *p;
597 eh = (struct elf64_x86_64_link_hash_entry *) h;
599 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
600 if (p->section == sreloc)
601 break;
603 if (p == NULL)
605 p = ((struct elf64_x86_64_pcrel_relocs_copied *)
606 bfd_alloc (dynobj, sizeof *p));
607 if (p == NULL)
608 return false;
609 p->next = eh->pcrel_relocs_copied;
610 eh->pcrel_relocs_copied = p;
611 p->section = sreloc;
612 p->count = 0;
615 ++p->count;
618 break;
620 /* This relocation describes the C++ object vtable hierarchy.
621 Reconstruct it for later use during GC. */
622 case R_X86_64_GNU_VTINHERIT:
623 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
624 return false;
625 break;
627 /* This relocation describes which C++ vtable entries are actually
628 used. Record for later use during GC. */
629 case R_X86_64_GNU_VTENTRY:
630 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
631 return false;
632 break;
636 return true;
639 /* Return the section that should be marked against GC for a given
640 relocation. */
642 static asection *
643 elf64_x86_64_gc_mark_hook (abfd, info, rel, h, sym)
644 bfd *abfd;
645 struct bfd_link_info *info ATTRIBUTE_UNUSED;
646 Elf_Internal_Rela *rel ATTRIBUTE_UNUSED;
647 struct elf_link_hash_entry *h;
648 Elf_Internal_Sym *sym;
650 if (h != NULL)
652 switch (ELF64_R_TYPE (rel->r_info))
654 case R_X86_64_GNU_VTINHERIT:
655 case R_X86_64_GNU_VTENTRY:
656 break;
658 default:
659 switch (h->root.type)
661 case bfd_link_hash_defined:
662 case bfd_link_hash_defweak:
663 return h->root.u.def.section;
665 case bfd_link_hash_common:
666 return h->root.u.c.p->section;
668 default:
669 break;
673 else
675 if (!(elf_bad_symtab (abfd)
676 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
677 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
678 && sym->st_shndx != SHN_COMMON))
680 return bfd_section_from_elf_index (abfd, sym->st_shndx);
684 return NULL;
687 /* Update the got entry reference counts for the section being removed. */
689 static boolean
690 elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs)
691 bfd *abfd;
692 struct bfd_link_info *info ATTRIBUTE_UNUSED;
693 asection *sec;
694 const Elf_Internal_Rela *relocs;
696 Elf_Internal_Shdr *symtab_hdr;
697 struct elf_link_hash_entry **sym_hashes;
698 bfd_signed_vma *local_got_refcounts;
699 const Elf_Internal_Rela *rel, *relend;
700 unsigned long r_symndx;
701 struct elf_link_hash_entry *h;
702 bfd *dynobj;
703 asection *sgot;
704 asection *srelgot;
706 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
707 sym_hashes = elf_sym_hashes (abfd);
708 local_got_refcounts = elf_local_got_refcounts (abfd);
710 dynobj = elf_hash_table (info)->dynobj;
711 if (dynobj == NULL)
712 return true;
714 sgot = bfd_get_section_by_name (dynobj, ".got");
715 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
717 relend = relocs + sec->reloc_count;
718 for (rel = relocs; rel < relend; rel++)
719 switch (ELF64_R_TYPE (rel->r_info))
721 case R_X86_64_GOT32:
722 case R_X86_64_GOTPCREL:
723 r_symndx = ELF64_R_SYM (rel->r_info);
724 if (r_symndx >= symtab_hdr->sh_info)
726 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
727 if (h->got.refcount > 0)
729 h->got.refcount -= 1;
730 if (h->got.refcount == 0)
732 sgot->_raw_size -= GOT_ENTRY_SIZE;
733 srelgot->_raw_size -= sizeof (Elf64_External_Rela);
737 else if (local_got_refcounts != NULL)
739 if (local_got_refcounts[r_symndx] > 0)
741 local_got_refcounts[r_symndx] -= 1;
742 if (local_got_refcounts[r_symndx] == 0)
744 sgot->_raw_size -= GOT_ENTRY_SIZE;
745 if (info->shared)
746 srelgot->_raw_size -= sizeof (Elf64_External_Rela);
750 break;
752 case R_X86_64_PLT32:
753 r_symndx = ELF64_R_SYM (rel->r_info);
754 if (r_symndx >= symtab_hdr->sh_info)
756 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
757 if (h->plt.refcount > 0)
758 h->plt.refcount -= 1;
760 break;
762 default:
763 break;
766 return true;
769 /* Adjust a symbol defined by a dynamic object and referenced by a
770 regular object. The current definition is in some section of the
771 dynamic object, but we're not including those sections. We have to
772 change the definition to something the rest of the link can
773 understand. */
775 static boolean
776 elf64_x86_64_adjust_dynamic_symbol (info, h)
777 struct bfd_link_info *info;
778 struct elf_link_hash_entry *h;
780 bfd *dynobj;
781 asection *s;
782 unsigned int power_of_two;
784 dynobj = elf_hash_table (info)->dynobj;
786 /* Make sure we know what is going on here. */
787 BFD_ASSERT (dynobj != NULL
788 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
789 || h->weakdef != NULL
790 || ((h->elf_link_hash_flags
791 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
792 && (h->elf_link_hash_flags
793 & ELF_LINK_HASH_REF_REGULAR) != 0
794 && (h->elf_link_hash_flags
795 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
797 /* If this is a function, put it in the procedure linkage table. We
798 will fill in the contents of the procedure linkage table later,
799 when we know the address of the .got section. */
800 if (h->type == STT_FUNC
801 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
803 if ((! info->shared
804 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
805 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
806 || (info->shared && h->plt.refcount <= 0))
808 /* This case can occur if we saw a PLT32 reloc in an input
809 file, but the symbol was never referred to by a dynamic
810 object, or if all references were garbage collected. In
811 such a case, we don't actually need to build a procedure
812 linkage table, and we can just do a PC32 reloc instead. */
813 h->plt.offset = (bfd_vma) -1;
814 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
815 return true;
818 /* Make sure this symbol is output as a dynamic symbol. */
819 if (h->dynindx == -1)
821 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
822 return false;
825 s = bfd_get_section_by_name (dynobj, ".plt");
826 BFD_ASSERT (s != NULL);
828 /* If this is the first .plt entry, make room for the special
829 first entry. */
830 if (s->_raw_size == 0)
831 s->_raw_size = PLT_ENTRY_SIZE;
833 /* If this symbol is not defined in a regular file, and we are
834 not generating a shared library, then set the symbol to this
835 location in the .plt. This is required to make function
836 pointers compare as equal between the normal executable and
837 the shared library. */
838 if (! info->shared
839 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
841 h->root.u.def.section = s;
842 h->root.u.def.value = s->_raw_size;
845 h->plt.offset = s->_raw_size;
847 /* Make room for this entry. */
848 s->_raw_size += PLT_ENTRY_SIZE;
850 /* We also need to make an entry in the .got.plt section, which
851 will be placed in the .got section by the linker script. */
852 s = bfd_get_section_by_name (dynobj, ".got.plt");
853 BFD_ASSERT (s != NULL);
854 s->_raw_size += GOT_ENTRY_SIZE;
856 /* We also need to make an entry in the .rela.plt section. */
857 s = bfd_get_section_by_name (dynobj, ".rela.plt");
858 BFD_ASSERT (s != NULL);
859 s->_raw_size += sizeof (Elf64_External_Rela);
861 return true;
864 /* If this is a weak symbol, and there is a real definition, the
865 processor independent code will have arranged for us to see the
866 real definition first, and we can just use the same value. */
867 if (h->weakdef != NULL)
869 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
870 || h->weakdef->root.type == bfd_link_hash_defweak);
871 h->root.u.def.section = h->weakdef->root.u.def.section;
872 h->root.u.def.value = h->weakdef->root.u.def.value;
873 return true;
876 /* This is a reference to a symbol defined by a dynamic object which
877 is not a function. */
879 /* If we are creating a shared library, we must presume that the
880 only references to the symbol are via the global offset table.
881 For such cases we need not do anything here; the relocations will
882 be handled correctly by relocate_section. */
883 if (info->shared)
884 return true;
886 /* If there are no references to this symbol that do not use the
887 GOT, we don't need to generate a copy reloc. */
888 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
889 return true;
891 /* We must allocate the symbol in our .dynbss section, which will
892 become part of the .bss section of the executable. There will be
893 an entry for this symbol in the .dynsym section. The dynamic
894 object will contain position independent code, so all references
895 from the dynamic object to this symbol will go through the global
896 offset table. The dynamic linker will use the .dynsym entry to
897 determine the address it must put in the global offset table, so
898 both the dynamic object and the regular object will refer to the
899 same memory location for the variable. */
901 s = bfd_get_section_by_name (dynobj, ".dynbss");
902 BFD_ASSERT (s != NULL);
904 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
905 to copy the initial value out of the dynamic object and into the
906 runtime process image. We need to remember the offset into the
907 .rela.bss section we are going to use. */
908 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
910 asection *srel;
912 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
913 BFD_ASSERT (srel != NULL);
914 srel->_raw_size += sizeof (Elf64_External_Rela);
915 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
918 /* We need to figure out the alignment required for this symbol. I
919 have no idea how ELF linkers handle this. 16-bytes is the size
920 of the largest type that requires hard alignment -- long double. */
921 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
922 this construct. */
923 power_of_two = bfd_log2 (h->size);
924 if (power_of_two > 4)
925 power_of_two = 4;
927 /* Apply the required alignment. */
928 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
929 if (power_of_two > bfd_get_section_alignment (dynobj, s))
931 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
932 return false;
935 /* Define the symbol as being at this point in the section. */
936 h->root.u.def.section = s;
937 h->root.u.def.value = s->_raw_size;
939 /* Increment the section size to make room for the symbol. */
940 s->_raw_size += h->size;
942 return true;
945 /* Set the sizes of the dynamic sections. */
947 static boolean
948 elf64_x86_64_size_dynamic_sections (output_bfd, info)
949 bfd *output_bfd;
950 struct bfd_link_info *info;
952 bfd *dynobj;
953 asection *s;
954 boolean plt;
955 boolean relocs;
956 boolean reltext;
958 dynobj = elf_hash_table (info)->dynobj;
959 BFD_ASSERT (dynobj != NULL);
961 if (elf_hash_table (info)->dynamic_sections_created)
963 /* Set the contents of the .interp section to the interpreter. */
964 if (! info->shared)
966 s = bfd_get_section_by_name (dynobj, ".interp");
967 BFD_ASSERT (s != NULL);
968 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
969 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
972 else
974 /* We may have created entries in the .rela.got section.
975 However, if we are not creating the dynamic sections, we will
976 not actually use these entries. Reset the size of .rela.got,
977 which will cause it to get stripped from the output file
978 below. */
979 s = bfd_get_section_by_name (dynobj, ".rela.got");
980 if (s != NULL)
981 s->_raw_size = 0;
984 /* If this is a -Bsymbolic shared link, then we need to discard all
985 PC relative relocs against symbols defined in a regular object.
986 We allocated space for them in the check_relocs routine, but we
987 will not fill them in in the relocate_section routine. */
988 if (info->shared)
989 elf64_x86_64_link_hash_traverse (elf64_x86_64_hash_table (info),
990 elf64_x86_64_discard_copies,
991 (PTR) info);
993 /* The check_relocs and adjust_dynamic_symbol entry points have
994 determined the sizes of the various dynamic sections. Allocate
995 memory for them. */
996 plt = relocs = reltext = false;
997 for (s = dynobj->sections; s != NULL; s = s->next)
999 const char *name;
1000 boolean strip;
1002 if ((s->flags & SEC_LINKER_CREATED) == 0)
1003 continue;
1005 /* It's OK to base decisions on the section name, because none
1006 of the dynobj section names depend upon the input files. */
1007 name = bfd_get_section_name (dynobj, s);
1009 strip = false;
1010 if (strcmp (name, ".plt") == 0)
1012 if (s->_raw_size == 0)
1014 /* Strip this section if we don't need it; see the
1015 comment below. */
1016 strip = true;
1018 else
1020 /* Remember whether there is a PLT. */
1021 plt = true;
1024 else if (strncmp (name, ".rela", 5) == 0)
1026 if (s->_raw_size == 0)
1028 /* If we don't need this section, strip it from the
1029 output file. This is mostly to handle .rela.bss and
1030 .rela.plt. We must create both sections in
1031 create_dynamic_sections, because they must be created
1032 before the linker maps input sections to output
1033 sections. The linker does that before
1034 adjust_dynamic_symbol is called, and it is that
1035 function which decides whether anything needs to go
1036 into these sections. */
1037 strip = true;
1039 else
1041 asection *target;
1043 /* Remember whether there are any reloc sections other
1044 than .rela.plt. */
1045 if (strcmp (name, ".rela.plt") != 0)
1047 const char *outname;
1049 relocs = true;
1051 /* If this relocation section applies to a read only
1052 section, then we probably need a DT_TEXTREL
1053 entry. The entries in the .rela.plt section
1054 really apply to the .got section, which we
1055 created ourselves and so know is not readonly. */
1056 outname = bfd_get_section_name (output_bfd,
1057 s->output_section);
1058 target = bfd_get_section_by_name (output_bfd, outname + 5);
1059 if (target != NULL
1060 && (target->flags & SEC_READONLY) != 0
1061 && (target->flags & SEC_ALLOC) != 0)
1062 reltext = true;
1065 /* We use the reloc_count field as a counter if we need
1066 to copy relocs into the output file. */
1067 s->reloc_count = 0;
1070 else if (strncmp (name, ".got", 4) != 0)
1072 /* It's not one of our sections, so don't allocate space. */
1073 continue;
1076 if (strip)
1078 _bfd_strip_section_from_output (info, s);
1079 continue;
1082 /* Allocate memory for the section contents. We use bfd_zalloc
1083 here in case unused entries are not reclaimed before the
1084 section's contents are written out. This should not happen,
1085 but this way if it does, we get a R_X86_64_NONE reloc instead
1086 of garbage. */
1087 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1088 if (s->contents == NULL && s->_raw_size != 0)
1089 return false;
1092 if (elf_hash_table (info)->dynamic_sections_created)
1094 /* Add some entries to the .dynamic section. We fill in the
1095 values later, in elf64_x86_64_finish_dynamic_sections, but we
1096 must add the entries now so that we get the correct size for
1097 the .dynamic section. The DT_DEBUG entry is filled in by the
1098 dynamic linker and used by the debugger. */
1099 if (! info->shared)
1101 if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
1102 return false;
1105 if (plt)
1107 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
1108 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1109 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1110 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
1111 return false;
1114 if (relocs)
1116 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
1117 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
1118 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
1119 sizeof (Elf64_External_Rela)))
1120 return false;
1123 if (reltext)
1125 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
1126 return false;
1127 info->flags |= DF_TEXTREL;
1131 return true;
1134 /* This function is called via elf64_x86_64_link_hash_traverse if we are
1135 creating a shared object. In the -Bsymbolic case, it discards the
1136 space allocated to copy PC relative relocs against symbols which
1137 are defined in regular objects. For the normal non-symbolic case,
1138 we also discard space for relocs that have become local due to
1139 symbol visibility changes. We allocated space for them in the
1140 check_relocs routine, but we won't fill them in in the
1141 relocate_section routine. */
1143 static boolean
1144 elf64_x86_64_discard_copies (h, inf)
1145 struct elf64_x86_64_link_hash_entry *h;
1146 PTR inf;
1148 struct elf64_x86_64_pcrel_relocs_copied *s;
1149 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1151 /* If a symbol has been forced local or we have found a regular
1152 definition for the symbolic link case, then we won't be needing
1153 any relocs. */
1154 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1155 && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
1156 || info->symbolic))
1158 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1159 s->section->_raw_size -= s->count * sizeof (Elf64_External_Rela);
1162 return true;
1165 /* Relocate an x86_64 ELF section. */
1167 static boolean
1168 elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
1169 contents, relocs, local_syms, local_sections)
1170 bfd *output_bfd;
1171 struct bfd_link_info *info;
1172 bfd *input_bfd;
1173 asection *input_section;
1174 bfd_byte *contents;
1175 Elf_Internal_Rela *relocs;
1176 Elf_Internal_Sym *local_syms;
1177 asection **local_sections;
1179 bfd *dynobj;
1180 Elf_Internal_Shdr *symtab_hdr;
1181 struct elf_link_hash_entry **sym_hashes;
1182 bfd_vma *local_got_offsets;
1183 asection *sgot;
1184 asection *splt;
1185 asection *sreloc;
1186 Elf_Internal_Rela *rela;
1187 Elf_Internal_Rela *relend;
1189 dynobj = elf_hash_table (info)->dynobj;
1190 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1191 sym_hashes = elf_sym_hashes (input_bfd);
1192 local_got_offsets = elf_local_got_offsets (input_bfd);
1194 sreloc = splt = sgot = NULL;
1195 if (dynobj != NULL)
1197 splt = bfd_get_section_by_name (dynobj, ".plt");
1198 sgot = bfd_get_section_by_name (dynobj, ".got");
1201 rela = relocs;
1202 relend = relocs + input_section->reloc_count;
1203 for (; rela < relend; rela++)
1205 int r_type;
1206 reloc_howto_type *howto;
1207 unsigned long r_symndx;
1208 struct elf_link_hash_entry *h;
1209 Elf_Internal_Sym *sym;
1210 asection *sec;
1211 bfd_vma relocation;
1212 bfd_reloc_status_type r;
1213 unsigned int indx;
1215 r_type = ELF64_R_TYPE (rela->r_info);
1216 if (r_type == (int) R_X86_64_GNU_VTINHERIT
1217 || r_type == (int) R_X86_64_GNU_VTENTRY)
1218 continue;
1220 if ((indx = (unsigned) r_type) >= R_X86_64_max)
1222 bfd_set_error (bfd_error_bad_value);
1223 return false;
1225 howto = x86_64_elf_howto_table + indx;
1227 r_symndx = ELF64_R_SYM (rela->r_info);
1229 if (info->relocateable)
1231 /* This is a relocateable link. We don't have to change
1232 anything, unless the reloc is against a section symbol,
1233 in which case we have to adjust according to where the
1234 section symbol winds up in the output section. */
1235 if (r_symndx < symtab_hdr->sh_info)
1237 sym = local_syms + r_symndx;
1238 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1240 sec = local_sections[r_symndx];
1241 rela->r_addend += sec->output_offset + sym->st_value;
1245 continue;
1248 /* This is a final link. */
1249 h = NULL;
1250 sym = NULL;
1251 sec = NULL;
1252 if (r_symndx < symtab_hdr->sh_info)
1254 sym = local_syms + r_symndx;
1255 sec = local_sections[r_symndx];
1256 relocation = (sec->output_section->vma
1257 + sec->output_offset
1258 + sym->st_value);
1260 else
1262 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1263 while (h->root.type == bfd_link_hash_indirect
1264 || h->root.type == bfd_link_hash_warning)
1265 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1266 if (h->root.type == bfd_link_hash_defined
1267 || h->root.type == bfd_link_hash_defweak)
1269 sec = h->root.u.def.section;
1270 if ((r_type == R_X86_64_PLT32
1271 && splt != NULL
1272 && h->plt.offset != (bfd_vma) -1)
1273 || ((r_type == R_X86_64_GOT32 || r_type == R_X86_64_GOTPCREL)
1274 && elf_hash_table (info)->dynamic_sections_created
1275 && (!info->shared
1276 || (! info->symbolic && h->dynindx != -1)
1277 || (h->elf_link_hash_flags
1278 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1279 || (info->shared
1280 && ((! info->symbolic && h->dynindx != -1)
1281 || (h->elf_link_hash_flags
1282 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1283 && (r_type == R_X86_64_8
1284 || r_type == R_X86_64_16
1285 || r_type == R_X86_64_32
1286 || r_type == R_X86_64_64
1287 || r_type == R_X86_64_PC8
1288 || r_type == R_X86_64_PC16
1289 || r_type == R_X86_64_PC32)
1290 && ((input_section->flags & SEC_ALLOC) != 0
1291 /* DWARF will emit R_X86_64_32 relocations in its
1292 sections against symbols defined externally
1293 in shared libraries. We can't do anything
1294 with them here. */
1295 || ((input_section->flags & SEC_DEBUGGING) != 0
1296 && (h->elf_link_hash_flags
1297 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
1299 /* In these cases, we don't need the relocation
1300 value. We check specially because in some
1301 obscure cases sec->output_section will be NULL. */
1302 relocation = 0;
1304 else if (sec->output_section == NULL)
1306 (*_bfd_error_handler)
1307 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
1308 bfd_get_filename (input_bfd), h->root.root.string,
1309 bfd_get_section_name (input_bfd, input_section));
1310 relocation = 0;
1312 else
1313 relocation = (h->root.u.def.value
1314 + sec->output_section->vma
1315 + sec->output_offset);
1317 else if (h->root.type == bfd_link_hash_undefweak)
1318 relocation = 0;
1319 else if (info->shared && !info->symbolic && !info->no_undefined
1320 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1321 relocation = 0;
1322 else
1324 if (! ((*info->callbacks->undefined_symbol)
1325 (info, h->root.root.string, input_bfd,
1326 input_section, rela->r_offset,
1327 (!info->shared || info->no_undefined
1328 || ELF_ST_VISIBILITY (h->other)))))
1329 return false;
1330 relocation = 0;
1334 /* When generating a shared object, the relocations handled here are
1335 copied into the output file to be resolved at run time. */
1336 switch (r_type)
1338 case R_X86_64_GOT32:
1339 /* Relocation is to the entry for this symbol in the global
1340 offset table. */
1341 case R_X86_64_GOTPCREL:
1342 /* Use global offset table as symbol value. */
1343 BFD_ASSERT (sgot != NULL);
1345 if (h != NULL)
1347 bfd_vma off = h->got.offset;
1348 BFD_ASSERT (off != (bfd_vma) -1);
1350 if (! elf_hash_table (info)->dynamic_sections_created
1351 || (info->shared
1352 && (info->symbolic || h->dynindx == -1)
1353 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1355 /* This is actually a static link, or it is a -Bsymbolic
1356 link and the symbol is defined locally, or the symbol
1357 was forced to be local because of a version file. We
1358 must initialize this entry in the global offset table.
1359 Since the offset must always be a multiple of 8, we
1360 use the least significant bit to record whether we
1361 have initialized it already.
1363 When doing a dynamic link, we create a .rela.got
1364 relocation entry to initialize the value. This is
1365 done in the finish_dynamic_symbol routine. */
1366 if ((off & 1) != 0)
1367 off &= ~1;
1368 else
1370 bfd_put_64 (output_bfd, relocation,
1371 sgot->contents + off);
1372 h->got.offset |= 1;
1375 if (r_type == R_X86_64_GOTPCREL)
1376 relocation = sgot->output_section->vma + sgot->output_offset + off;
1377 else
1378 relocation = sgot->output_offset + off;
1380 else
1382 bfd_vma off;
1384 BFD_ASSERT (local_got_offsets != NULL
1385 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1387 off = local_got_offsets[r_symndx];
1389 /* The offset must always be a multiple of 8. We use
1390 the least significant bit to record whether we have
1391 already generated the necessary reloc. */
1392 if ((off & 1) != 0)
1393 off &= ~1;
1394 else
1396 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
1398 if (info->shared)
1400 asection *srelgot;
1401 Elf_Internal_Rela outrel;
1403 /* We need to generate a R_X86_64_RELATIVE reloc
1404 for the dynamic linker. */
1405 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1406 BFD_ASSERT (srelgot != NULL);
1408 outrel.r_offset = (sgot->output_section->vma
1409 + sgot->output_offset
1410 + off);
1411 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1412 outrel.r_addend = relocation;
1413 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
1414 (((Elf64_External_Rela *)
1415 srelgot->contents)
1416 + srelgot->reloc_count));
1417 ++srelgot->reloc_count;
1420 local_got_offsets[r_symndx] |= 1;
1423 if (r_type == R_X86_64_GOTPCREL)
1424 relocation = sgot->output_section->vma + sgot->output_offset + off;
1425 else
1426 relocation = sgot->output_offset + off;
1429 break;
1431 case R_X86_64_PLT32:
1432 /* Relocation is to the entry for this symbol in the
1433 procedure linkage table. */
1435 /* Resolve a PLT32 reloc against a local symbol directly,
1436 without using the procedure linkage table. */
1437 if (h == NULL)
1438 break;
1440 if (h->plt.offset == (bfd_vma) -1 || splt == NULL)
1442 /* We didn't make a PLT entry for this symbol. This
1443 happens when statically linking PIC code, or when
1444 using -Bsymbolic. */
1445 break;
1448 relocation = (splt->output_section->vma
1449 + splt->output_offset
1450 + h->plt.offset);
1451 break;
1453 case R_X86_64_PC8:
1454 case R_X86_64_PC16:
1455 case R_X86_64_PC32:
1456 if (h == NULL || h->dynindx == -1
1457 || (info->symbolic
1458 && h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1459 break;
1460 /* Fall through. */
1461 case R_X86_64_8:
1462 case R_X86_64_16:
1463 case R_X86_64_32:
1464 case R_X86_64_64:
1465 /* FIXME: The ABI says the linker should make sure the value is
1466 the same when it's zeroextended to 64 bit. */
1467 if (info->shared && (input_section->flags & SEC_ALLOC) != 0)
1469 Elf_Internal_Rela outrel;
1470 boolean skip, relocate;
1472 /* When generating a shared object, these relocations
1473 are copied into the output file to be resolved at run
1474 time. */
1476 if (sreloc == NULL)
1478 const char *name;
1480 name = (bfd_elf_string_from_elf_section
1481 (input_bfd,
1482 elf_elfheader (input_bfd)->e_shstrndx,
1483 elf_section_data (input_section)->rel_hdr.sh_name));
1484 if (name == NULL)
1485 return false;
1487 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1488 && strcmp (bfd_get_section_name (input_bfd,
1489 input_section),
1490 name + 5) == 0);
1492 sreloc = bfd_get_section_by_name (dynobj, name);
1493 BFD_ASSERT (sreloc != NULL);
1496 skip = false;
1498 if (elf_section_data (input_section)->stab_info == NULL)
1499 outrel.r_offset = rela->r_offset;
1500 else
1502 bfd_vma off;
1504 off = (_bfd_stab_section_offset
1505 (output_bfd, &elf_hash_table (info)->stab_info,
1506 input_section,
1507 &elf_section_data (input_section)->stab_info,
1508 rela->r_offset));
1509 if (off == (bfd_vma) -1)
1510 skip = true;
1511 outrel.r_offset = off;
1514 outrel.r_offset += (input_section->output_section->vma
1515 + input_section->output_offset);
1517 if (skip)
1519 memset (&outrel, 0, sizeof outrel);
1520 relocate = false;
1522 /* h->dynindx may be -1 if this symbol was marked to
1523 become local. */
1524 else if (h != NULL
1525 && ((! info->symbolic && h->dynindx != -1)
1526 || (h->elf_link_hash_flags
1527 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1529 BFD_ASSERT (h->dynindx != -1);
1530 relocate = false;
1531 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
1532 outrel.r_addend = relocation + rela->r_addend;
1534 else
1536 if (r_type == R_X86_64_64)
1538 relocate = true;
1539 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1540 outrel.r_addend = relocation + rela->r_addend;
1542 else
1544 long indx;
1546 if (h == NULL)
1547 sec = local_sections[r_symndx];
1548 else
1550 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1551 || (h->root.type
1552 == bfd_link_hash_defweak));
1553 sec = h->root.u.def.section;
1555 if (sec != NULL && bfd_is_abs_section (sec))
1556 indx = 0;
1557 else if (sec == NULL || sec->owner == NULL)
1559 bfd_set_error (bfd_error_bad_value);
1560 return false;
1562 else
1564 asection *osec;
1566 osec = sec->output_section;
1567 indx = elf_section_data (osec)->dynindx;
1568 BFD_ASSERT (indx > 0);
1571 relocate = false;
1572 outrel.r_info = ELF64_R_INFO (indx, r_type);
1573 outrel.r_addend = relocation + rela->r_addend;
1578 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
1579 (((Elf64_External_Rela *)
1580 sreloc->contents)
1581 + sreloc->reloc_count));
1582 ++sreloc->reloc_count;
1584 /* If this reloc is against an external symbol, we do
1585 not want to fiddle with the addend. Otherwise, we
1586 need to include the symbol value so that it becomes
1587 an addend for the dynamic reloc. */
1588 if (! relocate)
1589 continue;
1592 break;
1594 default:
1595 break;
1598 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1599 contents, rela->r_offset,
1600 relocation, rela->r_addend);
1602 if (r != bfd_reloc_ok)
1604 switch (r)
1606 default:
1607 case bfd_reloc_outofrange:
1608 abort ();
1609 case bfd_reloc_overflow:
1611 const char *name;
1613 if (h != NULL)
1614 name = h->root.root.string;
1615 else
1617 name = bfd_elf_string_from_elf_section (input_bfd,
1618 symtab_hdr->sh_link,
1619 sym->st_name);
1620 if (name == NULL)
1621 return false;
1622 if (*name == '\0')
1623 name = bfd_section_name (input_bfd, sec);
1625 if (! ((*info->callbacks->reloc_overflow)
1626 (info, name, howto->name, (bfd_vma) 0,
1627 input_bfd, input_section, rela->r_offset)))
1628 return false;
1630 break;
1635 return true;
1638 /* Finish up dynamic symbol handling. We set the contents of various
1639 dynamic sections here. */
1641 static boolean
1642 elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym)
1643 bfd *output_bfd;
1644 struct bfd_link_info *info;
1645 struct elf_link_hash_entry *h;
1646 Elf_Internal_Sym *sym;
1648 bfd *dynobj;
1650 dynobj = elf_hash_table (info)->dynobj;
1652 if (h->plt.offset != (bfd_vma) -1)
1654 asection *splt;
1655 asection *sgot;
1656 asection *srela;
1657 bfd_vma plt_index;
1658 bfd_vma got_offset;
1659 Elf_Internal_Rela rela;
1661 /* This symbol has an entry in the procedure linkage table. Set
1662 it up. */
1664 BFD_ASSERT (h->dynindx != -1);
1666 splt = bfd_get_section_by_name (dynobj, ".plt");
1667 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1668 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1669 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1671 /* Get the index in the procedure linkage table which
1672 corresponds to this symbol. This is the index of this symbol
1673 in all the symbols for which we are making plt entries. The
1674 first entry in the procedure linkage table is reserved. */
1675 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1677 /* Get the offset into the .got table of the entry that
1678 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
1679 bytes. The first three are reserved for the dynamic linker. */
1680 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
1682 /* Fill in the entry in the procedure linkage table. */
1683 memcpy (splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
1684 PLT_ENTRY_SIZE);
1686 /* Insert the relocation positions of the plt section. The magic
1687 numbers at the end of the statements are the positions of the
1688 relocations in the plt section. */
1689 /* Put offset for jmp *name@GOTPCREL(%rip), since the
1690 instruction uses 6 bytes, subtract this value. */
1691 bfd_put_32 (output_bfd,
1692 (sgot->output_section->vma
1693 + sgot->output_offset
1694 + got_offset
1695 - splt->output_section->vma
1696 - splt->output_offset
1697 - h->plt.offset
1698 - 6),
1699 splt->contents + h->plt.offset + 2);
1700 /* Put relocation index. */
1701 bfd_put_32 (output_bfd, plt_index,
1702 splt->contents + h->plt.offset + 7);
1703 /* Put offset for jmp .PLT0. */
1704 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
1705 splt->contents + h->plt.offset + 12);
1707 /* Fill in the entry in the global offset table, initially this
1708 points to the pushq instruction in the PLT which is at offset 6. */
1709 bfd_put_64 (output_bfd, (splt->output_section->vma + splt->output_offset
1710 + h->plt.offset + 6),
1711 sgot->contents + got_offset);
1713 /* Fill in the entry in the .rela.plt section. */
1714 rela.r_offset = (sgot->output_section->vma
1715 + sgot->output_offset
1716 + got_offset);
1717 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
1718 rela.r_addend = 0;
1719 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1720 ((Elf64_External_Rela *) srela->contents
1721 + plt_index));
1723 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1725 /* Mark the symbol as undefined, rather than as defined in
1726 the .plt section. Leave the value alone. */
1727 sym->st_shndx = SHN_UNDEF;
1728 /* If the symbol is weak, we do need to clear the value.
1729 Otherwise, the PLT entry would provide a definition for
1730 the symbol even if the symbol wasn't defined anywhere,
1731 and so the symbol would never be NULL. */
1732 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
1733 == 0)
1734 sym->st_value = 0;
1738 if (h->got.offset != (bfd_vma) -1)
1740 asection *sgot;
1741 asection *srela;
1742 Elf_Internal_Rela rela;
1744 /* This symbol has an entry in the global offset table. Set it
1745 up. */
1747 sgot = bfd_get_section_by_name (dynobj, ".got");
1748 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1749 BFD_ASSERT (sgot != NULL && srela != NULL);
1751 rela.r_offset = (sgot->output_section->vma
1752 + sgot->output_offset
1753 + (h->got.offset &~ 1));
1755 /* If this is a static link, or it is a -Bsymbolic link and the
1756 symbol is defined locally or was forced to be local because
1757 of a version file, we just want to emit a RELATIVE reloc.
1758 The entry in the global offset table will already have been
1759 initialized in the relocate_section function. */
1760 if (! elf_hash_table (info)->dynamic_sections_created
1761 || (info->shared
1762 && (info->symbolic || h->dynindx == -1)
1763 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1765 BFD_ASSERT((h->got.offset & 1) != 0);
1766 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1767 rela.r_addend = (h->root.u.def.value
1768 + h->root.u.def.section->output_section->vma
1769 + h->root.u.def.section->output_offset);
1771 else
1773 BFD_ASSERT((h->got.offset & 1) == 0);
1774 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
1775 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
1776 rela.r_addend = 0;
1779 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1780 ((Elf64_External_Rela *) srela->contents
1781 + srela->reloc_count));
1782 ++srela->reloc_count;
1785 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1787 asection *s;
1788 Elf_Internal_Rela rela;
1790 /* This symbol needs a copy reloc. Set it up. */
1792 BFD_ASSERT (h->dynindx != -1
1793 && (h->root.type == bfd_link_hash_defined
1794 || h->root.type == bfd_link_hash_defweak));
1796 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1797 ".rela.bss");
1798 BFD_ASSERT (s != NULL);
1800 rela.r_offset = (h->root.u.def.value
1801 + h->root.u.def.section->output_section->vma
1802 + h->root.u.def.section->output_offset);
1803 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
1804 rela.r_addend = 0;
1805 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1806 ((Elf64_External_Rela *) s->contents
1807 + s->reloc_count));
1808 ++s->reloc_count;
1811 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1812 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1813 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1814 sym->st_shndx = SHN_ABS;
1816 return true;
1819 /* Finish up the dynamic sections. */
1821 static boolean
1822 elf64_x86_64_finish_dynamic_sections (output_bfd, info)
1823 bfd *output_bfd;
1824 struct bfd_link_info *info;
1826 bfd *dynobj;
1827 asection *sdyn;
1828 asection *sgot;
1830 dynobj = elf_hash_table (info)->dynobj;
1832 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1833 BFD_ASSERT (sgot != NULL);
1834 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1836 if (elf_hash_table (info)->dynamic_sections_created)
1838 asection *splt;
1839 Elf64_External_Dyn *dyncon, *dynconend;
1841 BFD_ASSERT (sdyn != NULL);
1843 dyncon = (Elf64_External_Dyn *) sdyn->contents;
1844 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1845 for (; dyncon < dynconend; dyncon++)
1847 Elf_Internal_Dyn dyn;
1848 const char *name;
1849 asection *s;
1851 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
1853 switch (dyn.d_tag)
1855 default:
1856 continue;
1858 case DT_PLTGOT:
1859 name = ".got";
1860 goto get_vma;
1862 case DT_JMPREL:
1863 name = ".rela.plt";
1865 get_vma:
1866 s = bfd_get_section_by_name (output_bfd, name);
1867 BFD_ASSERT (s != NULL);
1868 dyn.d_un.d_ptr = s->vma;
1869 break;
1871 case DT_RELASZ:
1872 /* FIXME: This comment and code is from elf64-alpha.c: */
1873 /* My interpretation of the TIS v1.1 ELF document indicates
1874 that RELASZ should not include JMPREL. This is not what
1875 the rest of the BFD does. It is, however, what the
1876 glibc ld.so wants. Do this fixup here until we found
1877 out who is right. */
1878 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1879 if (s)
1881 /* Subtract JMPREL size from RELASZ. */
1882 dyn.d_un.d_val -=
1883 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
1885 break;
1887 case DT_PLTRELSZ:
1888 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1889 BFD_ASSERT (s != NULL);
1890 dyn.d_un.d_val =
1891 (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size);
1892 break;
1894 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
1897 /* Initialize the contents of the .plt section. */
1898 splt = bfd_get_section_by_name (dynobj, ".plt");
1899 BFD_ASSERT (splt != NULL);
1900 if (splt->_raw_size > 0)
1902 /* Fill in the first entry in the procedure linkage table. */
1903 memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE);
1904 /* Add offset for pushq GOT+8(%rip), since the instruction
1905 uses 6 bytes subtract this value. */
1906 bfd_put_32 (output_bfd,
1907 (sgot->output_section->vma
1908 + sgot->output_offset
1910 - splt->output_section->vma
1911 - splt->output_offset
1912 - 6),
1913 splt->contents + 2);
1914 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
1915 the end of the instruction. */
1916 bfd_put_32 (output_bfd,
1917 (sgot->output_section->vma
1918 + sgot->output_offset
1919 + 16
1920 - splt->output_section->vma
1921 - splt->output_offset
1922 - 12),
1923 splt->contents + 8);
1927 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
1928 PLT_ENTRY_SIZE;
1931 /* Set the first entry in the global offset table to the address of
1932 the dynamic section. */
1933 if (sgot->_raw_size > 0)
1935 if (sdyn == NULL)
1936 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
1937 else
1938 bfd_put_64 (output_bfd,
1939 sdyn->output_section->vma + sdyn->output_offset,
1940 sgot->contents);
1941 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
1942 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE);
1943 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE*2);
1946 elf_section_data (sgot->output_section)->this_hdr.sh_entsize =
1947 GOT_ENTRY_SIZE;
1949 return true;
1952 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
1953 #define TARGET_LITTLE_NAME "elf64-x86-64"
1954 #define ELF_ARCH bfd_arch_i386
1955 #define ELF_MACHINE_CODE EM_X86_64
1956 #define ELF_MAXPAGESIZE 0x100000
1958 #define elf_backend_can_gc_sections 1
1959 #define elf_backend_want_got_plt 1
1960 #define elf_backend_plt_readonly 1
1961 #define elf_backend_want_plt_sym 0
1962 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
1963 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
1965 #define elf_info_to_howto elf64_x86_64_info_to_howto
1967 #define bfd_elf64_bfd_final_link _bfd_elf64_gc_common_final_link
1968 #define bfd_elf64_bfd_link_hash_table_create \
1969 elf64_x86_64_link_hash_table_create
1970 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
1972 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
1973 #define elf_backend_check_relocs elf64_x86_64_check_relocs
1974 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
1975 #define elf_backend_finish_dynamic_sections \
1976 elf64_x86_64_finish_dynamic_sections
1977 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
1978 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
1979 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
1980 #define elf_backend_relocate_section elf64_x86_64_relocate_section
1981 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
1982 #define elf_backend_object_p elf64_x86_64_elf_object_p
1984 #include "elf64-target.h"