1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002 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. */
27 #include "elf/x86-64.h"
29 /* We use only the RELA entries. */
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, size, bitsize, pc_relative, complain_on_overflow,
37 special_function, name, partial_inplace, src_mask, dst_pack, 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, 4, 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, 4, 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, 4, 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, 4, 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, 4, 32, true,0 , complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", false, 0xffffffff,
70 HOWTO(R_X86_64_32
, 0, 4, 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, 4, 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_signed
,
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),
85 /* GNU extension to record C++ vtable hierarchy. */
86 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, false, 0, complain_overflow_dont
,
87 NULL
, "R_X86_64_GNU_VTINHERIT", false, 0, 0, false),
89 /* GNU extension to record C++ vtable member usage. */
90 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, false, 0, complain_overflow_dont
,
91 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", false, 0, 0,
95 /* Map BFD relocs to the x86_64 elf relocs. */
98 bfd_reloc_code_real_type bfd_reloc_val
;
99 unsigned char elf_reloc_val
;
102 static const struct elf_reloc_map x86_64_reloc_map
[] =
104 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
105 { BFD_RELOC_64
, R_X86_64_64
, },
106 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
107 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
108 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
109 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
110 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
111 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
112 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
113 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
114 { BFD_RELOC_32
, R_X86_64_32
, },
115 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
116 { BFD_RELOC_16
, R_X86_64_16
, },
117 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
118 { BFD_RELOC_8
, R_X86_64_8
, },
119 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
120 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
121 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
124 static reloc_howto_type
*elf64_x86_64_reloc_type_lookup
125 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
126 static void elf64_x86_64_info_to_howto
127 PARAMS ((bfd
*, arelent
*, Elf64_Internal_Rela
*));
128 static struct bfd_link_hash_table
*elf64_x86_64_link_hash_table_create
130 static boolean elf64_x86_64_elf_object_p
PARAMS ((bfd
*abfd
));
131 static boolean create_got_section
132 PARAMS((bfd
*, struct bfd_link_info
*));
133 static boolean elf64_x86_64_create_dynamic_sections
134 PARAMS((bfd
*, struct bfd_link_info
*));
135 static void elf64_x86_64_copy_indirect_symbol
136 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
137 static boolean elf64_x86_64_check_relocs
138 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*sec
,
139 const Elf_Internal_Rela
*));
140 static asection
*elf64_x86_64_gc_mark_hook
141 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
142 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
144 static boolean elf64_x86_64_gc_sweep_hook
145 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
146 const Elf_Internal_Rela
*));
148 static struct bfd_hash_entry
*link_hash_newfunc
149 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
150 static boolean elf64_x86_64_adjust_dynamic_symbol
151 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
153 static boolean allocate_dynrelocs
154 PARAMS ((struct elf_link_hash_entry
*, PTR
));
155 static boolean readonly_dynrelocs
156 PARAMS ((struct elf_link_hash_entry
*, PTR
));
157 static boolean elf64_x86_64_size_dynamic_sections
158 PARAMS ((bfd
*, struct bfd_link_info
*));
159 static boolean elf64_x86_64_relocate_section
160 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
161 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
162 static boolean elf64_x86_64_finish_dynamic_symbol
163 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
164 Elf_Internal_Sym
*sym
));
165 static boolean elf64_x86_64_finish_dynamic_sections
166 PARAMS ((bfd
*, struct bfd_link_info
*));
167 static enum elf_reloc_type_class elf64_x86_64_reloc_type_class
168 PARAMS ((const Elf_Internal_Rela
*));
170 /* Given a BFD reloc type, return a HOWTO structure. */
171 static reloc_howto_type
*
172 elf64_x86_64_reloc_type_lookup (abfd
, code
)
173 bfd
*abfd ATTRIBUTE_UNUSED
;
174 bfd_reloc_code_real_type code
;
177 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
180 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
181 return &x86_64_elf_howto_table
[i
];
186 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
189 elf64_x86_64_info_to_howto (abfd
, cache_ptr
, dst
)
190 bfd
*abfd ATTRIBUTE_UNUSED
;
192 Elf64_Internal_Rela
*dst
;
196 r_type
= ELF64_R_TYPE (dst
->r_info
);
197 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
)
199 BFD_ASSERT (r_type
<= (unsigned int) R_X86_64_PC8
);
204 BFD_ASSERT (r_type
< (unsigned int) R_X86_64_max
);
205 i
= r_type
- ((unsigned int) R_X86_64_GNU_VTINHERIT
- R_X86_64_PC8
- 1);
207 cache_ptr
->howto
= &x86_64_elf_howto_table
[i
];
208 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
211 /* Functions for the x86-64 ELF linker. */
213 /* The name of the dynamic interpreter. This is put in the .interp
216 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
218 /* The size in bytes of an entry in the global offset table. */
220 #define GOT_ENTRY_SIZE 8
222 /* The size in bytes of an entry in the procedure linkage table. */
224 #define PLT_ENTRY_SIZE 16
226 /* The first entry in a procedure linkage table looks like this. See the
227 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
229 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
231 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
232 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
233 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
236 /* Subsequent entries in a procedure linkage table look like this. */
238 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
240 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
241 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
242 0x68, /* pushq immediate */
243 0, 0, 0, 0, /* replaced with index into relocation table. */
244 0xe9, /* jmp relative */
245 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
248 /* The x86-64 linker needs to keep track of the number of relocs that
249 decides to copy as dynamic relocs in check_relocs for each symbol.
250 This is so that it can later discard them if they are found to be
251 unnecessary. We store the information in a field extending the
252 regular ELF linker hash table. */
254 struct elf64_x86_64_dyn_relocs
257 struct elf64_x86_64_dyn_relocs
*next
;
259 /* The input section of the reloc. */
262 /* Total number of relocs copied for the input section. */
265 /* Number of pc-relative relocs copied for the input section. */
266 bfd_size_type pc_count
;
269 /* x86-64 ELF linker hash entry. */
271 struct elf64_x86_64_link_hash_entry
273 struct elf_link_hash_entry elf
;
275 /* Track dynamic relocs copied for this symbol. */
276 struct elf64_x86_64_dyn_relocs
*dyn_relocs
;
279 /* x86-64 ELF linker hash table. */
281 struct elf64_x86_64_link_hash_table
283 struct elf_link_hash_table elf
;
285 /* Short-cuts to get to dynamic linker sections. */
294 /* Small local sym to section mapping cache. */
295 struct sym_sec_cache sym_sec
;
298 /* Get the x86-64 ELF linker hash table from a link_info structure. */
300 #define elf64_x86_64_hash_table(p) \
301 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
303 /* Create an entry in an x86-64 ELF linker hash table. */
305 static struct bfd_hash_entry
*
306 link_hash_newfunc (entry
, table
, string
)
307 struct bfd_hash_entry
*entry
;
308 struct bfd_hash_table
*table
;
311 /* Allocate the structure if it has not already been allocated by a
315 entry
= bfd_hash_allocate (table
,
316 sizeof (struct elf64_x86_64_link_hash_entry
));
321 /* Call the allocation method of the superclass. */
322 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
325 struct elf64_x86_64_link_hash_entry
*eh
;
327 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
328 eh
->dyn_relocs
= NULL
;
334 /* Create an X86-64 ELF linker hash table. */
336 static struct bfd_link_hash_table
*
337 elf64_x86_64_link_hash_table_create (abfd
)
340 struct elf64_x86_64_link_hash_table
*ret
;
341 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
343 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_alloc (abfd
, amt
);
347 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
349 bfd_release (abfd
, ret
);
360 ret
->sym_sec
.abfd
= NULL
;
362 return &ret
->elf
.root
;
365 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
366 shortcuts to them in our hash table. */
369 create_got_section (dynobj
, info
)
371 struct bfd_link_info
*info
;
373 struct elf64_x86_64_link_hash_table
*htab
;
375 if (! _bfd_elf_create_got_section (dynobj
, info
))
378 htab
= elf64_x86_64_hash_table (info
);
379 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
380 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
381 if (!htab
->sgot
|| !htab
->sgotplt
)
384 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
385 if (htab
->srelgot
== NULL
386 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
387 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
388 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
390 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
395 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
396 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
400 elf64_x86_64_create_dynamic_sections (dynobj
, info
)
402 struct bfd_link_info
*info
;
404 struct elf64_x86_64_link_hash_table
*htab
;
406 htab
= elf64_x86_64_hash_table (info
);
407 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
410 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
413 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
414 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
415 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
417 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
419 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
420 || (!info
->shared
&& !htab
->srelbss
))
426 /* Copy the extra info we tack onto an elf_link_hash_entry. */
429 elf64_x86_64_copy_indirect_symbol (dir
, ind
)
430 struct elf_link_hash_entry
*dir
, *ind
;
432 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
434 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
435 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
437 if (eind
->dyn_relocs
!= NULL
)
439 if (edir
->dyn_relocs
!= NULL
)
441 struct elf64_x86_64_dyn_relocs
**pp
;
442 struct elf64_x86_64_dyn_relocs
*p
;
444 if (ind
->root
.type
== bfd_link_hash_indirect
)
447 /* Add reloc counts against the weak sym to the strong sym
448 list. Merge any entries against the same section. */
449 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
451 struct elf64_x86_64_dyn_relocs
*q
;
453 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
454 if (q
->sec
== p
->sec
)
456 q
->pc_count
+= p
->pc_count
;
457 q
->count
+= p
->count
;
464 *pp
= edir
->dyn_relocs
;
467 edir
->dyn_relocs
= eind
->dyn_relocs
;
468 eind
->dyn_relocs
= NULL
;
471 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
475 elf64_x86_64_elf_object_p (abfd
)
478 /* Set the right machine number for an x86-64 elf64 file. */
479 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
483 /* Look through the relocs for a section during the first phase, and
484 calculate needed space in the global offset table, procedure
485 linkage table, and dynamic reloc sections. */
488 elf64_x86_64_check_relocs (abfd
, info
, sec
, relocs
)
490 struct bfd_link_info
*info
;
492 const Elf_Internal_Rela
*relocs
;
494 struct elf64_x86_64_link_hash_table
*htab
;
495 Elf_Internal_Shdr
*symtab_hdr
;
496 struct elf_link_hash_entry
**sym_hashes
;
497 const Elf_Internal_Rela
*rel
;
498 const Elf_Internal_Rela
*rel_end
;
501 if (info
->relocateable
)
504 htab
= elf64_x86_64_hash_table (info
);
505 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
506 sym_hashes
= elf_sym_hashes (abfd
);
510 rel_end
= relocs
+ sec
->reloc_count
;
511 for (rel
= relocs
; rel
< rel_end
; rel
++)
513 unsigned long r_symndx
;
514 struct elf_link_hash_entry
*h
;
516 r_symndx
= ELF64_R_SYM (rel
->r_info
);
518 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
520 (*_bfd_error_handler
) (_("%s: bad symbol index: %d"),
521 bfd_archive_filename (abfd
),
526 if (r_symndx
< symtab_hdr
->sh_info
)
529 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
531 switch (ELF64_R_TYPE (rel
->r_info
))
534 case R_X86_64_GOTPCREL
:
535 /* This symbol requires a global offset table entry. */
538 h
->got
.refcount
+= 1;
542 bfd_signed_vma
*local_got_refcounts
;
544 /* This is a global offset table entry for a local symbol. */
545 local_got_refcounts
= elf_local_got_refcounts (abfd
);
546 if (local_got_refcounts
== NULL
)
550 size
= symtab_hdr
->sh_info
;
551 size
*= sizeof (bfd_signed_vma
);
552 local_got_refcounts
= ((bfd_signed_vma
*)
553 bfd_zalloc (abfd
, size
));
554 if (local_got_refcounts
== NULL
)
556 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
558 local_got_refcounts
[r_symndx
] += 1;
562 //case R_X86_64_GOTPCREL:
563 if (htab
->sgot
== NULL
)
565 if (htab
->elf
.dynobj
== NULL
)
566 htab
->elf
.dynobj
= abfd
;
567 if (!create_got_section (htab
->elf
.dynobj
, info
))
573 /* This symbol requires a procedure linkage table entry. We
574 actually build the entry in adjust_dynamic_symbol,
575 because this might be a case of linking PIC code which is
576 never referenced by a dynamic object, in which case we
577 don't need to generate a procedure linkage table entry
580 /* If this is a local symbol, we resolve it directly without
581 creating a procedure linkage table entry. */
585 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
586 h
->plt
.refcount
+= 1;
597 if (h
!= NULL
&& !info
->shared
)
599 /* If this reloc is in a read-only section, we might
600 need a copy reloc. We can't check reliably at this
601 stage whether the section is read-only, as input
602 sections have not yet been mapped to output sections.
603 Tentatively set the flag for now, and correct in
604 adjust_dynamic_symbol. */
605 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
607 /* We may need a .plt entry if the function this reloc
608 refers to is in a shared lib. */
609 h
->plt
.refcount
+= 1;
612 /* If we are creating a shared library, and this is a reloc
613 against a global symbol, or a non PC relative reloc
614 against a local symbol, then we need to copy the reloc
615 into the shared library. However, if we are linking with
616 -Bsymbolic, we do not need to copy a reloc against a
617 global symbol which is defined in an object we are
618 including in the link (i.e., DEF_REGULAR is set). At
619 this point we have not seen all the input files, so it is
620 possible that DEF_REGULAR is not set now but will be set
621 later (it is never cleared). In case of a weak definition,
622 DEF_REGULAR may be cleared later by a strong definition in
623 a shared library. We account for that possibility below by
624 storing information in the relocs_copied field of the hash
625 table entry. A similar situation occurs when creating
626 shared libraries and symbol visibility changes render the
629 If on the other hand, we are creating an executable, we
630 may need to keep relocations for symbols satisfied by a
631 dynamic library if we manage to avoid copy relocs for the
634 && (sec
->flags
& SEC_ALLOC
) != 0
635 && (((ELF64_R_TYPE (rel
->r_info
) != R_X86_64_PC8
)
636 && (ELF64_R_TYPE (rel
->r_info
) != R_X86_64_PC16
)
637 && (ELF64_R_TYPE (rel
->r_info
) != R_X86_64_PC32
))
640 || h
->root
.type
== bfd_link_hash_defweak
641 || (h
->elf_link_hash_flags
642 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
644 && (sec
->flags
& SEC_ALLOC
) != 0
646 && (h
->root
.type
== bfd_link_hash_defweak
647 || (h
->elf_link_hash_flags
648 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
650 struct elf64_x86_64_dyn_relocs
*p
;
651 struct elf64_x86_64_dyn_relocs
**head
;
653 /* We must copy these reloc types into the output file.
654 Create a reloc section in dynobj and make room for
661 name
= (bfd_elf_string_from_elf_section
663 elf_elfheader (abfd
)->e_shstrndx
,
664 elf_section_data (sec
)->rel_hdr
.sh_name
));
668 if (strncmp (name
, ".rela", 5) != 0
669 || strcmp (bfd_get_section_name (abfd
, sec
),
672 (*_bfd_error_handler
)
673 (_("%s: bad relocation section name `%s\'"),
674 bfd_archive_filename (abfd
), name
);
677 if (htab
->elf
.dynobj
== NULL
)
678 htab
->elf
.dynobj
= abfd
;
680 dynobj
= htab
->elf
.dynobj
;
682 sreloc
= bfd_get_section_by_name (dynobj
, name
);
687 sreloc
= bfd_make_section (dynobj
, name
);
688 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
689 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
690 if ((sec
->flags
& SEC_ALLOC
) != 0)
691 flags
|= SEC_ALLOC
| SEC_LOAD
;
693 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
694 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
697 elf_section_data (sec
)->sreloc
= sreloc
;
700 /* If this is a global symbol, we count the number of
701 relocations we need for this symbol. */
704 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
708 /* Track dynamic relocs needed for local syms too.
709 We really need local syms available to do this
713 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
718 head
= ((struct elf64_x86_64_dyn_relocs
**)
719 &elf_section_data (s
)->local_dynrel
);
723 if (p
== NULL
|| p
->sec
!= sec
)
725 bfd_size_type amt
= sizeof *p
;
726 p
= ((struct elf64_x86_64_dyn_relocs
*)
727 bfd_alloc (htab
->elf
.dynobj
, amt
));
738 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC8
739 || ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC16
740 || ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC32
)
745 /* This relocation describes the C++ object vtable hierarchy.
746 Reconstruct it for later use during GC. */
747 case R_X86_64_GNU_VTINHERIT
:
748 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
752 /* This relocation describes which C++ vtable entries are actually
753 used. Record for later use during GC. */
754 case R_X86_64_GNU_VTENTRY
:
755 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
767 /* Return the section that should be marked against GC for a given
771 elf64_x86_64_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
773 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
774 Elf_Internal_Rela
*rel
;
775 struct elf_link_hash_entry
*h
;
776 Elf_Internal_Sym
*sym
;
780 switch (ELF64_R_TYPE (rel
->r_info
))
782 case R_X86_64_GNU_VTINHERIT
:
783 case R_X86_64_GNU_VTENTRY
:
787 switch (h
->root
.type
)
789 case bfd_link_hash_defined
:
790 case bfd_link_hash_defweak
:
791 return h
->root
.u
.def
.section
;
793 case bfd_link_hash_common
:
794 return h
->root
.u
.c
.p
->section
;
803 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
809 /* Update the got entry reference counts for the section being removed. */
812 elf64_x86_64_gc_sweep_hook (abfd
, info
, sec
, relocs
)
814 struct bfd_link_info
*info
;
816 const Elf_Internal_Rela
*relocs
;
818 Elf_Internal_Shdr
*symtab_hdr
;
819 struct elf_link_hash_entry
**sym_hashes
;
820 bfd_signed_vma
*local_got_refcounts
;
821 const Elf_Internal_Rela
*rel
, *relend
;
822 unsigned long r_symndx
;
823 struct elf_link_hash_entry
*h
;
825 elf_section_data (sec
)->local_dynrel
= NULL
;
827 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
828 sym_hashes
= elf_sym_hashes (abfd
);
829 local_got_refcounts
= elf_local_got_refcounts (abfd
);
831 relend
= relocs
+ sec
->reloc_count
;
832 for (rel
= relocs
; rel
< relend
; rel
++)
833 switch (ELF64_R_TYPE (rel
->r_info
))
836 case R_X86_64_GOTPCREL
:
837 r_symndx
= ELF64_R_SYM (rel
->r_info
);
838 if (r_symndx
>= symtab_hdr
->sh_info
)
840 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
841 if (h
->got
.refcount
> 0)
842 h
->got
.refcount
-= 1;
844 else if (local_got_refcounts
!= NULL
)
846 if (local_got_refcounts
[r_symndx
] > 0)
847 local_got_refcounts
[r_symndx
] -= 1;
859 r_symndx
= ELF64_R_SYM (rel
->r_info
);
860 if (r_symndx
>= symtab_hdr
->sh_info
)
862 struct elf64_x86_64_link_hash_entry
*eh
;
863 struct elf64_x86_64_dyn_relocs
**pp
;
864 struct elf64_x86_64_dyn_relocs
*p
;
866 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
868 if (!info
->shared
&& h
->plt
.refcount
> 0)
869 h
->plt
.refcount
-= 1;
871 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
873 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
876 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC8
877 || ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC16
878 || ELF64_R_TYPE (rel
->r_info
) == R_X86_64_PC32
)
890 r_symndx
= ELF64_R_SYM (rel
->r_info
);
891 if (r_symndx
>= symtab_hdr
->sh_info
)
893 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
894 if (h
->plt
.refcount
> 0)
895 h
->plt
.refcount
-= 1;
906 /* Adjust a symbol defined by a dynamic object and referenced by a
907 regular object. The current definition is in some section of the
908 dynamic object, but we're not including those sections. We have to
909 change the definition to something the rest of the link can
913 elf64_x86_64_adjust_dynamic_symbol (info
, h
)
914 struct bfd_link_info
*info
;
915 struct elf_link_hash_entry
*h
;
917 struct elf64_x86_64_link_hash_table
*htab
;
918 struct elf64_x86_64_link_hash_entry
* eh
;
919 struct elf64_x86_64_dyn_relocs
*p
;
921 unsigned int power_of_two
;
923 /* If this is a function, put it in the procedure linkage table. We
924 will fill in the contents of the procedure linkage table later,
925 when we know the address of the .got section. */
926 if (h
->type
== STT_FUNC
927 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
929 if (h
->plt
.refcount
<= 0
931 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
932 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
933 && h
->root
.type
!= bfd_link_hash_undefweak
934 && h
->root
.type
!= bfd_link_hash_undefined
))
936 /* This case can occur if we saw a PLT32 reloc in an input
937 file, but the symbol was never referred to by a dynamic
938 object, or if all references were garbage collected. In
939 such a case, we don't actually need to build a procedure
940 linkage table, and we can just do a PC32 reloc instead. */
941 h
->plt
.offset
= (bfd_vma
) -1;
942 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
948 /* It's possible that we incorrectly decided a .plt reloc was
949 needed for an R_X86_64_PC32 reloc to a non-function sym in
950 check_relocs. We can't decide accurately between function and
951 non-function syms in check-relocs; Objects loaded later in
952 the link may change h->type. So fix it now. */
953 h
->plt
.offset
= (bfd_vma
) -1;
955 /* If this is a weak symbol, and there is a real definition, the
956 processor independent code will have arranged for us to see the
957 real definition first, and we can just use the same value. */
958 if (h
->weakdef
!= NULL
)
960 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
961 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
962 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
963 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
967 /* This is a reference to a symbol defined by a dynamic object which
968 is not a function. */
970 /* If we are creating a shared library, we must presume that the
971 only references to the symbol are via the global offset table.
972 For such cases we need not do anything here; the relocations will
973 be handled correctly by relocate_section. */
977 /* If there are no references to this symbol that do not use the
978 GOT, we don't need to generate a copy reloc. */
979 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
982 /* If -z nocopyreloc was given, we won't generate them either. */
983 if (info
->nocopyreloc
)
985 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
989 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
990 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
992 s
= p
->sec
->output_section
;
993 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
997 /* If we didn't find any dynamic relocs in read-only sections, then
998 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1001 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1005 /* We must allocate the symbol in our .dynbss section, which will
1006 become part of the .bss section of the executable. There will be
1007 an entry for this symbol in the .dynsym section. The dynamic
1008 object will contain position independent code, so all references
1009 from the dynamic object to this symbol will go through the global
1010 offset table. The dynamic linker will use the .dynsym entry to
1011 determine the address it must put in the global offset table, so
1012 both the dynamic object and the regular object will refer to the
1013 same memory location for the variable. */
1015 htab
= elf64_x86_64_hash_table (info
);
1017 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1018 to copy the initial value out of the dynamic object and into the
1019 runtime process image. */
1020 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1022 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
1023 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1026 /* We need to figure out the alignment required for this symbol. I
1027 have no idea how ELF linkers handle this. 16-bytes is the size
1028 of the largest type that requires hard alignment -- long double. */
1029 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
1031 power_of_two
= bfd_log2 (h
->size
);
1032 if (power_of_two
> 4)
1035 /* Apply the required alignment. */
1037 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1038 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1040 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1044 /* Define the symbol as being at this point in the section. */
1045 h
->root
.u
.def
.section
= s
;
1046 h
->root
.u
.def
.value
= s
->_raw_size
;
1048 /* Increment the section size to make room for the symbol. */
1049 s
->_raw_size
+= h
->size
;
1054 /* This is the condition under which elf64_x86_64_finish_dynamic_symbol
1055 will be called from elflink.h. If elflink.h doesn't call our
1056 finish_dynamic_symbol routine, we'll need to do something about
1057 initializing any .plt and .got entries in elf64_x86_64_relocate_section. */
1058 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1060 && ((INFO)->shared \
1061 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1062 && ((H)->dynindx != -1 \
1063 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1065 /* Allocate space in .plt, .got and associated reloc sections for
1069 allocate_dynrelocs (h
, inf
)
1070 struct elf_link_hash_entry
*h
;
1073 struct bfd_link_info
*info
;
1074 struct elf64_x86_64_link_hash_table
*htab
;
1075 struct elf64_x86_64_link_hash_entry
*eh
;
1076 struct elf64_x86_64_dyn_relocs
*p
;
1078 if (h
->root
.type
== bfd_link_hash_indirect
1079 || h
->root
.type
== bfd_link_hash_warning
)
1082 info
= (struct bfd_link_info
*) inf
;
1083 htab
= elf64_x86_64_hash_table (info
);
1085 if (htab
->elf
.dynamic_sections_created
1086 && h
->plt
.refcount
> 0)
1088 /* Make sure this symbol is output as a dynamic symbol.
1089 Undefined weak syms won't yet be marked as dynamic. */
1090 if (h
->dynindx
== -1
1091 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1093 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1097 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1099 asection
*s
= htab
->splt
;
1101 /* If this is the first .plt entry, make room for the special
1103 if (s
->_raw_size
== 0)
1104 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1106 h
->plt
.offset
= s
->_raw_size
;
1108 /* If this symbol is not defined in a regular file, and we are
1109 not generating a shared library, then set the symbol to this
1110 location in the .plt. This is required to make function
1111 pointers compare as equal between the normal executable and
1112 the shared library. */
1114 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1116 h
->root
.u
.def
.section
= s
;
1117 h
->root
.u
.def
.value
= h
->plt
.offset
;
1120 /* Make room for this entry. */
1121 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1123 /* We also need to make an entry in the .got.plt section, which
1124 will be placed in the .got section by the linker script. */
1125 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1127 /* We also need to make an entry in the .rela.plt section. */
1128 htab
->srelplt
->_raw_size
+= sizeof (Elf64_External_Rela
);
1132 h
->plt
.offset
= (bfd_vma
) -1;
1133 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1138 h
->plt
.offset
= (bfd_vma
) -1;
1139 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1142 if (h
->got
.refcount
> 0)
1147 /* Make sure this symbol is output as a dynamic symbol.
1148 Undefined weak syms won't yet be marked as dynamic. */
1149 if (h
->dynindx
== -1
1150 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1152 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1157 h
->got
.offset
= s
->_raw_size
;
1158 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1159 dyn
= htab
->elf
.dynamic_sections_created
;
1160 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1161 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1164 h
->got
.offset
= (bfd_vma
) -1;
1166 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1167 if (eh
->dyn_relocs
== NULL
)
1170 /* In the shared -Bsymbolic case, discard space allocated for
1171 dynamic pc-relative relocs against symbols which turn out to be
1172 defined in regular objects. For the normal shared case, discard
1173 space for pc-relative relocs that have become local due to symbol
1174 visibility changes. */
1178 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1179 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1182 struct elf64_x86_64_dyn_relocs
**pp
;
1184 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1186 p
->count
-= p
->pc_count
;
1197 /* For the non-shared case, discard space for relocs against
1198 symbols which turn out to need copy relocs or are not
1201 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1202 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1203 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1204 || (htab
->elf
.dynamic_sections_created
1205 && (h
->root
.type
== bfd_link_hash_undefweak
1206 || h
->root
.type
== bfd_link_hash_undefined
))))
1208 /* Make sure this symbol is output as a dynamic symbol.
1209 Undefined weak syms won't yet be marked as dynamic. */
1210 if (h
->dynindx
== -1
1211 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1213 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1217 /* If that succeeded, we know we'll be keeping all the
1219 if (h
->dynindx
!= -1)
1223 eh
->dyn_relocs
= NULL
;
1228 /* Finally, allocate space. */
1229 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1231 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1232 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1238 /* Find any dynamic relocs that apply to read-only sections. */
1241 readonly_dynrelocs (h
, inf
)
1242 struct elf_link_hash_entry
*h
;
1245 struct elf64_x86_64_link_hash_entry
*eh
;
1246 struct elf64_x86_64_dyn_relocs
*p
;
1248 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1249 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1251 asection
*s
= p
->sec
->output_section
;
1253 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1255 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1257 info
->flags
|= DF_TEXTREL
;
1259 /* Not an error, just cut short the traversal. */
1266 /* Set the sizes of the dynamic sections. */
1269 elf64_x86_64_size_dynamic_sections (output_bfd
, info
)
1270 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1271 struct bfd_link_info
*info
;
1273 struct elf64_x86_64_link_hash_table
*htab
;
1279 htab
= elf64_x86_64_hash_table (info
);
1280 dynobj
= htab
->elf
.dynobj
;
1284 if (htab
->elf
.dynamic_sections_created
)
1286 /* Set the contents of the .interp section to the interpreter. */
1289 s
= bfd_get_section_by_name (dynobj
, ".interp");
1292 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1293 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1297 /* Set up .got offsets for local syms, and space for local dynamic
1299 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1301 bfd_signed_vma
*local_got
;
1302 bfd_signed_vma
*end_local_got
;
1303 bfd_size_type locsymcount
;
1304 Elf_Internal_Shdr
*symtab_hdr
;
1307 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1310 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1312 struct elf64_x86_64_dyn_relocs
*p
;
1314 for (p
= *((struct elf64_x86_64_dyn_relocs
**)
1315 &elf_section_data (s
)->local_dynrel
);
1319 if (!bfd_is_abs_section (p
->sec
)
1320 && bfd_is_abs_section (p
->sec
->output_section
))
1322 /* Input section has been discarded, either because
1323 it is a copy of a linkonce section or due to
1324 linker script /DISCARD/, so we'll be discarding
1327 else if (p
->count
!= 0)
1329 srel
= elf_section_data (p
->sec
)->sreloc
;
1330 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1331 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1332 info
->flags
|= DF_TEXTREL
;
1338 local_got
= elf_local_got_refcounts (ibfd
);
1342 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1343 locsymcount
= symtab_hdr
->sh_info
;
1344 end_local_got
= local_got
+ locsymcount
;
1346 srel
= htab
->srelgot
;
1347 for (; local_got
< end_local_got
; ++local_got
)
1351 *local_got
= s
->_raw_size
;
1352 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1354 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
1357 *local_got
= (bfd_vma
) -1;
1361 /* Allocate global sym .plt and .got entries, and space for global
1362 sym dynamic relocs. */
1363 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1365 /* We now have determined the sizes of the various dynamic sections.
1366 Allocate memory for them. */
1368 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1370 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1375 || s
== htab
->sgotplt
)
1377 /* Strip this section if we don't need it; see the
1380 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
1382 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
1385 /* We use the reloc_count field as a counter if we need
1386 to copy relocs into the output file. */
1391 /* It's not one of our sections, so don't allocate space. */
1395 if (s
->_raw_size
== 0)
1397 /* If we don't need this section, strip it from the
1398 output file. This is mostly to handle .rela.bss and
1399 .rela.plt. We must create both sections in
1400 create_dynamic_sections, because they must be created
1401 before the linker maps input sections to output
1402 sections. The linker does that before
1403 adjust_dynamic_symbol is called, and it is that
1404 function which decides whether anything needs to go
1405 into these sections. */
1407 _bfd_strip_section_from_output (info
, s
);
1411 /* Allocate memory for the section contents. We use bfd_zalloc
1412 here in case unused entries are not reclaimed before the
1413 section's contents are written out. This should not happen,
1414 but this way if it does, we get a R_X86_64_NONE reloc instead
1416 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1417 if (s
->contents
== NULL
)
1421 if (htab
->elf
.dynamic_sections_created
)
1423 /* Add some entries to the .dynamic section. We fill in the
1424 values later, in elf64_x86_64_finish_dynamic_sections, but we
1425 must add the entries now so that we get the correct size for
1426 the .dynamic section. The DT_DEBUG entry is filled in by the
1427 dynamic linker and used by the debugger. */
1428 #define add_dynamic_entry(TAG, VAL) \
1429 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1433 if (!add_dynamic_entry (DT_DEBUG
, 0))
1437 if (htab
->splt
->_raw_size
!= 0)
1439 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1440 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1441 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1442 || !add_dynamic_entry (DT_JMPREL
, 0))
1448 if (!add_dynamic_entry (DT_RELA
, 0)
1449 || !add_dynamic_entry (DT_RELASZ
, 0)
1450 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1453 /* If any dynamic relocs apply to a read-only section,
1454 then we need a DT_TEXTREL entry. */
1455 if ((info
->flags
& DF_TEXTREL
) == 0)
1456 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
1459 if ((info
->flags
& DF_TEXTREL
) != 0)
1461 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1466 #undef add_dynamic_entry
1471 /* Relocate an x86_64 ELF section. */
1474 elf64_x86_64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1475 contents
, relocs
, local_syms
, local_sections
)
1477 struct bfd_link_info
*info
;
1479 asection
*input_section
;
1481 Elf_Internal_Rela
*relocs
;
1482 Elf_Internal_Sym
*local_syms
;
1483 asection
**local_sections
;
1485 struct elf64_x86_64_link_hash_table
*htab
;
1486 Elf_Internal_Shdr
*symtab_hdr
;
1487 struct elf_link_hash_entry
**sym_hashes
;
1488 bfd_vma
*local_got_offsets
;
1489 Elf_Internal_Rela
*rel
;
1490 Elf_Internal_Rela
*relend
;
1492 htab
= elf64_x86_64_hash_table (info
);
1493 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1494 sym_hashes
= elf_sym_hashes (input_bfd
);
1495 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1498 relend
= relocs
+ input_section
->reloc_count
;
1499 for (; rel
< relend
; rel
++)
1502 reloc_howto_type
*howto
;
1503 unsigned long r_symndx
;
1504 struct elf_link_hash_entry
*h
;
1505 Elf_Internal_Sym
*sym
;
1509 boolean unresolved_reloc
;
1510 bfd_reloc_status_type r
;
1512 r_type
= ELF64_R_TYPE (rel
->r_info
);
1513 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
1514 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
1517 if (r_type
< 0 || r_type
>= R_X86_64_max
)
1519 bfd_set_error (bfd_error_bad_value
);
1522 howto
= x86_64_elf_howto_table
+ r_type
;
1524 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1526 if (info
->relocateable
)
1528 /* This is a relocateable link. We don't have to change
1529 anything, unless the reloc is against a section symbol,
1530 in which case we have to adjust according to where the
1531 section symbol winds up in the output section. */
1532 if (r_symndx
< symtab_hdr
->sh_info
)
1534 sym
= local_syms
+ r_symndx
;
1535 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1537 sec
= local_sections
[r_symndx
];
1538 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1545 /* This is a final link. */
1549 unresolved_reloc
= false;
1550 if (r_symndx
< symtab_hdr
->sh_info
)
1552 sym
= local_syms
+ r_symndx
;
1553 sec
= local_sections
[r_symndx
];
1555 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1559 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1560 while (h
->root
.type
== bfd_link_hash_indirect
1561 || h
->root
.type
== bfd_link_hash_warning
)
1562 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1564 if (h
->root
.type
== bfd_link_hash_defined
1565 || h
->root
.type
== bfd_link_hash_defweak
)
1567 sec
= h
->root
.u
.def
.section
;
1568 if (sec
->output_section
== NULL
)
1570 /* Set a flag that will be cleared later if we find a
1571 relocation value for this symbol. output_section
1572 is typically NULL for symbols satisfied by a shared
1574 unresolved_reloc
= true;
1578 relocation
= (h
->root
.u
.def
.value
1579 + sec
->output_section
->vma
1580 + sec
->output_offset
);
1582 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1584 else if (info
->shared
1585 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
1586 && !info
->no_undefined
1587 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1591 if (! ((*info
->callbacks
->undefined_symbol
)
1592 (info
, h
->root
.root
.string
, input_bfd
,
1593 input_section
, rel
->r_offset
,
1594 (!info
->shared
|| info
->no_undefined
1595 || ELF_ST_VISIBILITY (h
->other
)))))
1600 /* When generating a shared object, the relocations handled here are
1601 copied into the output file to be resolved at run time. */
1604 case R_X86_64_GOT32
:
1605 /* Relocation is to the entry for this symbol in the global
1607 case R_X86_64_GOTPCREL
:
1608 /* Use global offset table as symbol value. */
1609 if (htab
->sgot
== NULL
)
1616 off
= h
->got
.offset
;
1617 dyn
= htab
->elf
.dynamic_sections_created
;
1619 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
1623 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
1624 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1626 /* This is actually a static link, or it is a -Bsymbolic
1627 link and the symbol is defined locally, or the symbol
1628 was forced to be local because of a version file. We
1629 must initialize this entry in the global offset table.
1630 Since the offset must always be a multiple of 8, we
1631 use the least significant bit to record whether we
1632 have initialized it already.
1634 When doing a dynamic link, we create a .rela.got
1635 relocation entry to initialize the value. This is
1636 done in the finish_dynamic_symbol routine. */
1641 bfd_put_64 (output_bfd
, relocation
,
1642 htab
->sgot
->contents
+ off
);
1647 unresolved_reloc
= false;
1651 if (local_got_offsets
== NULL
)
1654 off
= local_got_offsets
[r_symndx
];
1656 /* The offset must always be a multiple of 8. We use
1657 the least significant bit to record whether we have
1658 already generated the necessary reloc. */
1663 bfd_put_64 (output_bfd
, relocation
,
1664 htab
->sgot
->contents
+ off
);
1669 Elf_Internal_Rela outrel
;
1670 Elf64_External_Rela
*loc
;
1672 /* We need to generate a R_X86_64_RELATIVE reloc
1673 for the dynamic linker. */
1674 srelgot
= htab
->srelgot
;
1675 if (srelgot
== NULL
)
1678 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
1679 + htab
->sgot
->output_offset
1681 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
1682 outrel
.r_addend
= relocation
;
1683 loc
= (Elf64_External_Rela
*) srelgot
->contents
;
1684 loc
+= srelgot
->reloc_count
++;
1685 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1688 local_got_offsets
[r_symndx
] |= 1;
1692 if (off
>= (bfd_vma
) -2)
1695 relocation
= htab
->sgot
->output_offset
+ off
;
1696 if (r_type
== R_X86_64_GOTPCREL
)
1697 relocation
+= htab
->sgot
->output_section
->vma
;
1701 case R_X86_64_PLT32
:
1702 /* Relocation is to the entry for this symbol in the
1703 procedure linkage table. */
1705 /* Resolve a PLT32 reloc against a local symbol directly,
1706 without using the procedure linkage table. */
1710 if (h
->plt
.offset
== (bfd_vma
) -1
1711 || htab
->splt
== NULL
)
1713 /* We didn't make a PLT entry for this symbol. This
1714 happens when statically linking PIC code, or when
1715 using -Bsymbolic. */
1719 relocation
= (htab
->splt
->output_section
->vma
1720 + htab
->splt
->output_offset
1722 unresolved_reloc
= false;
1732 /* FIXME: The ABI says the linker should make sure the value is
1733 the same when it's zeroextended to 64 bit. */
1735 /* r_symndx will be zero only for relocs against symbols
1736 from removed linkonce sections, or sections discarded by
1739 || (input_section
->flags
& SEC_ALLOC
) == 0)
1743 && ((r_type
!= R_X86_64_PC8
1744 && r_type
!= R_X86_64_PC16
1745 && r_type
!= R_X86_64_PC32
)
1748 && (! info
->symbolic
1749 || (h
->elf_link_hash_flags
1750 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1754 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1755 && (((h
->elf_link_hash_flags
1756 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1757 && (h
->elf_link_hash_flags
1758 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1759 || h
->root
.type
== bfd_link_hash_undefweak
1760 || h
->root
.type
== bfd_link_hash_undefined
)))
1762 Elf_Internal_Rela outrel
;
1763 boolean skip
, relocate
;
1765 Elf64_External_Rela
*loc
;
1767 /* When generating a shared object, these relocations
1768 are copied into the output file to be resolved at run
1775 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1777 if (outrel
.r_offset
== (bfd_vma
) -1)
1779 else if (outrel
.r_offset
== (bfd_vma
) -2)
1780 skip
= true, relocate
= true;
1782 outrel
.r_offset
+= (input_section
->output_section
->vma
1783 + input_section
->output_offset
);
1786 memset (&outrel
, 0, sizeof outrel
);
1788 /* h->dynindx may be -1 if this symbol was marked to
1792 && (r_type
== R_X86_64_PC8
1793 || r_type
== R_X86_64_PC16
1794 || r_type
== R_X86_64_PC32
1797 || (h
->elf_link_hash_flags
1798 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1800 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
1801 outrel
.r_addend
= rel
->r_addend
;
1805 /* This symbol is local, or marked to become local. */
1807 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
1808 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1811 sreloc
= elf_section_data (input_section
)->sreloc
;
1815 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
1816 loc
+= sreloc
->reloc_count
++;
1817 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1819 /* If this reloc is against an external symbol, we do
1820 not want to fiddle with the addend. Otherwise, we
1821 need to include the symbol value so that it becomes
1822 an addend for the dynamic reloc. */
1833 /* FIXME: Why do we allow debugging sections to escape this error?
1834 More importantly, why do we not emit dynamic relocs for
1835 R_386_32 above in debugging sections (which are ! SEC_ALLOC)?
1836 If we had emitted the dynamic reloc, we could remove the
1838 if (unresolved_reloc
1840 && (input_section
->flags
& SEC_DEBUGGING
) != 0
1841 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
1842 (*_bfd_error_handler
)
1843 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
1844 bfd_archive_filename (input_bfd
),
1845 bfd_get_section_name (input_bfd
, input_section
),
1846 (long) rel
->r_offset
,
1847 h
->root
.root
.string
);
1849 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1850 contents
, rel
->r_offset
,
1851 relocation
, rel
->r_addend
);
1853 if (r
!= bfd_reloc_ok
)
1858 name
= h
->root
.root
.string
;
1861 name
= bfd_elf_string_from_elf_section (input_bfd
,
1862 symtab_hdr
->sh_link
,
1867 name
= bfd_section_name (input_bfd
, sec
);
1870 if (r
== bfd_reloc_overflow
)
1873 if (! ((*info
->callbacks
->reloc_overflow
)
1874 (info
, name
, howto
->name
, (bfd_vma
) 0,
1875 input_bfd
, input_section
, rel
->r_offset
)))
1880 (*_bfd_error_handler
)
1881 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
1882 bfd_archive_filename (input_bfd
),
1883 bfd_get_section_name (input_bfd
, input_section
),
1884 (long) rel
->r_offset
, name
, (int) r
);
1893 /* Finish up dynamic symbol handling. We set the contents of various
1894 dynamic sections here. */
1897 elf64_x86_64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1899 struct bfd_link_info
*info
;
1900 struct elf_link_hash_entry
*h
;
1901 Elf_Internal_Sym
*sym
;
1903 struct elf64_x86_64_link_hash_table
*htab
;
1905 htab
= elf64_x86_64_hash_table (info
);
1907 if (h
->plt
.offset
!= (bfd_vma
) -1)
1911 Elf_Internal_Rela rela
;
1912 Elf64_External_Rela
*loc
;
1914 /* This symbol has an entry in the procedure linkage table. Set
1917 if (h
->dynindx
== -1
1918 || htab
->splt
== NULL
1919 || htab
->sgotplt
== NULL
1920 || htab
->srelplt
== NULL
)
1923 /* Get the index in the procedure linkage table which
1924 corresponds to this symbol. This is the index of this symbol
1925 in all the symbols for which we are making plt entries. The
1926 first entry in the procedure linkage table is reserved. */
1927 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1929 /* Get the offset into the .got table of the entry that
1930 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
1931 bytes. The first three are reserved for the dynamic linker. */
1932 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
1934 /* Fill in the entry in the procedure linkage table. */
1935 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
1938 /* Insert the relocation positions of the plt section. The magic
1939 numbers at the end of the statements are the positions of the
1940 relocations in the plt section. */
1941 /* Put offset for jmp *name@GOTPCREL(%rip), since the
1942 instruction uses 6 bytes, subtract this value. */
1943 bfd_put_32 (output_bfd
,
1944 (htab
->sgotplt
->output_section
->vma
1945 + htab
->sgotplt
->output_offset
1947 - htab
->splt
->output_section
->vma
1948 - htab
->splt
->output_offset
1951 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
1952 /* Put relocation index. */
1953 bfd_put_32 (output_bfd
, plt_index
,
1954 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
1955 /* Put offset for jmp .PLT0. */
1956 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
1957 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
1959 /* Fill in the entry in the global offset table, initially this
1960 points to the pushq instruction in the PLT which is at offset 6. */
1961 bfd_put_64 (output_bfd
, (htab
->splt
->output_section
->vma
1962 + htab
->splt
->output_offset
1963 + h
->plt
.offset
+ 6),
1964 htab
->sgotplt
->contents
+ got_offset
);
1966 /* Fill in the entry in the .rela.plt section. */
1967 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
1968 + htab
->sgotplt
->output_offset
1970 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
1972 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
+ plt_index
;
1973 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
1975 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1977 /* Mark the symbol as undefined, rather than as defined in
1978 the .plt section. Leave the value alone. This is a clue
1979 for the dynamic linker, to make function pointer
1980 comparisons work between an application and shared
1982 sym
->st_shndx
= SHN_UNDEF
;
1986 if (h
->got
.offset
!= (bfd_vma
) -1)
1988 Elf_Internal_Rela rela
;
1989 Elf64_External_Rela
*loc
;
1991 /* This symbol has an entry in the global offset table. Set it
1994 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
1997 rela
.r_offset
= (htab
->sgot
->output_section
->vma
1998 + htab
->sgot
->output_offset
1999 + (h
->got
.offset
&~ (bfd_vma
) 1));
2001 /* If this is a static link, or it is a -Bsymbolic link and the
2002 symbol is defined locally or was forced to be local because
2003 of a version file, we just want to emit a RELATIVE reloc.
2004 The entry in the global offset table will already have been
2005 initialized in the relocate_section function. */
2009 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2010 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2012 BFD_ASSERT((h
->got
.offset
& 1) != 0);
2013 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2014 rela
.r_addend
= (h
->root
.u
.def
.value
2015 + h
->root
.u
.def
.section
->output_section
->vma
2016 + h
->root
.u
.def
.section
->output_offset
);
2020 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2021 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2022 htab
->sgot
->contents
+ h
->got
.offset
);
2023 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
2027 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
2028 loc
+= htab
->srelgot
->reloc_count
++;
2029 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2032 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2034 Elf_Internal_Rela rela
;
2035 Elf64_External_Rela
*loc
;
2037 /* This symbol needs a copy reloc. Set it up. */
2039 if (h
->dynindx
== -1
2040 || (h
->root
.type
!= bfd_link_hash_defined
2041 && h
->root
.type
!= bfd_link_hash_defweak
)
2042 || htab
->srelbss
== NULL
)
2045 rela
.r_offset
= (h
->root
.u
.def
.value
2046 + h
->root
.u
.def
.section
->output_section
->vma
2047 + h
->root
.u
.def
.section
->output_offset
);
2048 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
2050 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
2051 loc
+= htab
->srelbss
->reloc_count
++;
2052 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2055 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2056 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2057 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2058 sym
->st_shndx
= SHN_ABS
;
2063 /* Used to decide how to sort relocs in an optimal manner for the
2064 dynamic linker, before writing them out. */
2066 static enum elf_reloc_type_class
2067 elf64_x86_64_reloc_type_class (rela
)
2068 const Elf_Internal_Rela
*rela
;
2070 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2072 case R_X86_64_RELATIVE
:
2073 return reloc_class_relative
;
2074 case R_X86_64_JUMP_SLOT
:
2075 return reloc_class_plt
;
2077 return reloc_class_copy
;
2079 return reloc_class_normal
;
2083 /* Finish up the dynamic sections. */
2086 elf64_x86_64_finish_dynamic_sections (output_bfd
, info
)
2088 struct bfd_link_info
*info
;
2090 struct elf64_x86_64_link_hash_table
*htab
;
2094 htab
= elf64_x86_64_hash_table (info
);
2095 dynobj
= htab
->elf
.dynobj
;
2096 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2098 if (htab
->elf
.dynamic_sections_created
)
2100 Elf64_External_Dyn
*dyncon
, *dynconend
;
2102 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
2105 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2106 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2107 for (; dyncon
< dynconend
; dyncon
++)
2109 Elf_Internal_Dyn dyn
;
2112 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2120 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
2124 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
2128 s
= htab
->srelplt
->output_section
;
2129 if (s
->_cooked_size
!= 0)
2130 dyn
.d_un
.d_val
= s
->_cooked_size
;
2132 dyn
.d_un
.d_val
= s
->_raw_size
;
2136 /* The procedure linkage table relocs (DT_JMPREL) should
2137 not be included in the overall relocs (DT_RELA).
2138 Therefore, we override the DT_RELASZ entry here to
2139 make it not include the JMPREL relocs. Since the
2140 linker script arranges for .rela.plt to follow all
2141 other relocation sections, we don't have to worry
2142 about changing the DT_RELA entry. */
2143 if (htab
->srelplt
!= NULL
)
2145 s
= htab
->srelplt
->output_section
;
2146 if (s
->_cooked_size
!= 0)
2147 dyn
.d_un
.d_val
-= s
->_cooked_size
;
2149 dyn
.d_un
.d_val
-= s
->_raw_size
;
2154 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2157 /* Fill in the special first entry in the procedure linkage table. */
2158 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
2160 /* Fill in the first entry in the procedure linkage table. */
2161 memcpy (htab
->splt
->contents
, elf64_x86_64_plt0_entry
,
2163 /* Add offset for pushq GOT+8(%rip), since the instruction
2164 uses 6 bytes subtract this value. */
2165 bfd_put_32 (output_bfd
,
2166 (htab
->sgotplt
->output_section
->vma
2167 + htab
->sgotplt
->output_offset
2169 - htab
->splt
->output_section
->vma
2170 - htab
->splt
->output_offset
2172 htab
->splt
->contents
+ 2);
2173 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
2174 the end of the instruction. */
2175 bfd_put_32 (output_bfd
,
2176 (htab
->sgotplt
->output_section
->vma
2177 + htab
->sgotplt
->output_offset
2179 - htab
->splt
->output_section
->vma
2180 - htab
->splt
->output_offset
2182 htab
->splt
->contents
+ 8);
2184 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
=
2191 /* Fill in the first three entries in the global offset table. */
2192 if (htab
->sgotplt
->_raw_size
> 0)
2194 /* Set the first entry in the global offset table to the address of
2195 the dynamic section. */
2197 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
);
2199 bfd_put_64 (output_bfd
,
2200 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2201 htab
->sgotplt
->contents
);
2202 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
2203 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
);
2204 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
2207 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
=
2215 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
2216 #define TARGET_LITTLE_NAME "elf64-x86-64"
2217 #define ELF_ARCH bfd_arch_i386
2218 #define ELF_MACHINE_CODE EM_X86_64
2219 #define ELF_MAXPAGESIZE 0x100000
2221 #define elf_backend_can_gc_sections 1
2222 #define elf_backend_can_refcount 1
2223 #define elf_backend_want_got_plt 1
2224 #define elf_backend_plt_readonly 1
2225 #define elf_backend_want_plt_sym 0
2226 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
2227 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2229 #define elf_info_to_howto elf64_x86_64_info_to_howto
2231 #define bfd_elf64_bfd_link_hash_table_create \
2232 elf64_x86_64_link_hash_table_create
2233 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
2235 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
2236 #define elf_backend_check_relocs elf64_x86_64_check_relocs
2237 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
2238 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
2239 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
2240 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
2241 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
2242 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
2243 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
2244 #define elf_backend_relocate_section elf64_x86_64_relocate_section
2245 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
2246 #define elf_backend_object_p elf64_x86_64_elf_object_p
2248 #include "elf64-target.h"