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 it 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_malloc (amt
);
347 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
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
)
1081 if (h
->root
.type
== bfd_link_hash_warning
)
1082 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1084 info
= (struct bfd_link_info
*) inf
;
1085 htab
= elf64_x86_64_hash_table (info
);
1087 if (htab
->elf
.dynamic_sections_created
1088 && h
->plt
.refcount
> 0)
1090 /* Make sure this symbol is output as a dynamic symbol.
1091 Undefined weak syms won't yet be marked as dynamic. */
1092 if (h
->dynindx
== -1
1093 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1095 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1099 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1101 asection
*s
= htab
->splt
;
1103 /* If this is the first .plt entry, make room for the special
1105 if (s
->_raw_size
== 0)
1106 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1108 h
->plt
.offset
= s
->_raw_size
;
1110 /* If this symbol is not defined in a regular file, and we are
1111 not generating a shared library, then set the symbol to this
1112 location in the .plt. This is required to make function
1113 pointers compare as equal between the normal executable and
1114 the shared library. */
1116 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1118 h
->root
.u
.def
.section
= s
;
1119 h
->root
.u
.def
.value
= h
->plt
.offset
;
1122 /* Make room for this entry. */
1123 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1125 /* We also need to make an entry in the .got.plt section, which
1126 will be placed in the .got section by the linker script. */
1127 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1129 /* We also need to make an entry in the .rela.plt section. */
1130 htab
->srelplt
->_raw_size
+= sizeof (Elf64_External_Rela
);
1134 h
->plt
.offset
= (bfd_vma
) -1;
1135 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1140 h
->plt
.offset
= (bfd_vma
) -1;
1141 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1144 if (h
->got
.refcount
> 0)
1149 /* Make sure this symbol is output as a dynamic symbol.
1150 Undefined weak syms won't yet be marked as dynamic. */
1151 if (h
->dynindx
== -1
1152 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1154 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1159 h
->got
.offset
= s
->_raw_size
;
1160 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1161 dyn
= htab
->elf
.dynamic_sections_created
;
1162 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1163 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1166 h
->got
.offset
= (bfd_vma
) -1;
1168 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1169 if (eh
->dyn_relocs
== NULL
)
1172 /* In the shared -Bsymbolic case, discard space allocated for
1173 dynamic pc-relative relocs against symbols which turn out to be
1174 defined in regular objects. For the normal shared case, discard
1175 space for pc-relative relocs that have become local due to symbol
1176 visibility changes. */
1180 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1181 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1184 struct elf64_x86_64_dyn_relocs
**pp
;
1186 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1188 p
->count
-= p
->pc_count
;
1199 /* For the non-shared case, discard space for relocs against
1200 symbols which turn out to need copy relocs or are not
1203 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1204 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1205 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1206 || (htab
->elf
.dynamic_sections_created
1207 && (h
->root
.type
== bfd_link_hash_undefweak
1208 || h
->root
.type
== bfd_link_hash_undefined
))))
1210 /* Make sure this symbol is output as a dynamic symbol.
1211 Undefined weak syms won't yet be marked as dynamic. */
1212 if (h
->dynindx
== -1
1213 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1215 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1219 /* If that succeeded, we know we'll be keeping all the
1221 if (h
->dynindx
!= -1)
1225 eh
->dyn_relocs
= NULL
;
1230 /* Finally, allocate space. */
1231 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1233 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1234 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1240 /* Find any dynamic relocs that apply to read-only sections. */
1243 readonly_dynrelocs (h
, inf
)
1244 struct elf_link_hash_entry
*h
;
1247 struct elf64_x86_64_link_hash_entry
*eh
;
1248 struct elf64_x86_64_dyn_relocs
*p
;
1250 if (h
->root
.type
== bfd_link_hash_warning
)
1251 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1253 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1254 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1256 asection
*s
= p
->sec
->output_section
;
1258 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1260 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1262 info
->flags
|= DF_TEXTREL
;
1264 /* Not an error, just cut short the traversal. */
1271 /* Set the sizes of the dynamic sections. */
1274 elf64_x86_64_size_dynamic_sections (output_bfd
, info
)
1275 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1276 struct bfd_link_info
*info
;
1278 struct elf64_x86_64_link_hash_table
*htab
;
1284 htab
= elf64_x86_64_hash_table (info
);
1285 dynobj
= htab
->elf
.dynobj
;
1289 if (htab
->elf
.dynamic_sections_created
)
1291 /* Set the contents of the .interp section to the interpreter. */
1294 s
= bfd_get_section_by_name (dynobj
, ".interp");
1297 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1298 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1302 /* Set up .got offsets for local syms, and space for local dynamic
1304 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1306 bfd_signed_vma
*local_got
;
1307 bfd_signed_vma
*end_local_got
;
1308 bfd_size_type locsymcount
;
1309 Elf_Internal_Shdr
*symtab_hdr
;
1312 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1315 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1317 struct elf64_x86_64_dyn_relocs
*p
;
1319 for (p
= *((struct elf64_x86_64_dyn_relocs
**)
1320 &elf_section_data (s
)->local_dynrel
);
1324 if (!bfd_is_abs_section (p
->sec
)
1325 && bfd_is_abs_section (p
->sec
->output_section
))
1327 /* Input section has been discarded, either because
1328 it is a copy of a linkonce section or due to
1329 linker script /DISCARD/, so we'll be discarding
1332 else if (p
->count
!= 0)
1334 srel
= elf_section_data (p
->sec
)->sreloc
;
1335 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1336 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1337 info
->flags
|= DF_TEXTREL
;
1343 local_got
= elf_local_got_refcounts (ibfd
);
1347 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1348 locsymcount
= symtab_hdr
->sh_info
;
1349 end_local_got
= local_got
+ locsymcount
;
1351 srel
= htab
->srelgot
;
1352 for (; local_got
< end_local_got
; ++local_got
)
1356 *local_got
= s
->_raw_size
;
1357 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1359 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
1362 *local_got
= (bfd_vma
) -1;
1366 /* Allocate global sym .plt and .got entries, and space for global
1367 sym dynamic relocs. */
1368 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1370 /* We now have determined the sizes of the various dynamic sections.
1371 Allocate memory for them. */
1373 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1375 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1380 || s
== htab
->sgotplt
)
1382 /* Strip this section if we don't need it; see the
1385 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
1387 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
1390 /* We use the reloc_count field as a counter if we need
1391 to copy relocs into the output file. */
1396 /* It's not one of our sections, so don't allocate space. */
1400 if (s
->_raw_size
== 0)
1402 /* If we don't need this section, strip it from the
1403 output file. This is mostly to handle .rela.bss and
1404 .rela.plt. We must create both sections in
1405 create_dynamic_sections, because they must be created
1406 before the linker maps input sections to output
1407 sections. The linker does that before
1408 adjust_dynamic_symbol is called, and it is that
1409 function which decides whether anything needs to go
1410 into these sections. */
1412 _bfd_strip_section_from_output (info
, s
);
1416 /* Allocate memory for the section contents. We use bfd_zalloc
1417 here in case unused entries are not reclaimed before the
1418 section's contents are written out. This should not happen,
1419 but this way if it does, we get a R_X86_64_NONE reloc instead
1421 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1422 if (s
->contents
== NULL
)
1426 if (htab
->elf
.dynamic_sections_created
)
1428 /* Add some entries to the .dynamic section. We fill in the
1429 values later, in elf64_x86_64_finish_dynamic_sections, but we
1430 must add the entries now so that we get the correct size for
1431 the .dynamic section. The DT_DEBUG entry is filled in by the
1432 dynamic linker and used by the debugger. */
1433 #define add_dynamic_entry(TAG, VAL) \
1434 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1438 if (!add_dynamic_entry (DT_DEBUG
, 0))
1442 if (htab
->splt
->_raw_size
!= 0)
1444 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1445 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1446 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1447 || !add_dynamic_entry (DT_JMPREL
, 0))
1453 if (!add_dynamic_entry (DT_RELA
, 0)
1454 || !add_dynamic_entry (DT_RELASZ
, 0)
1455 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1458 /* If any dynamic relocs apply to a read-only section,
1459 then we need a DT_TEXTREL entry. */
1460 if ((info
->flags
& DF_TEXTREL
) == 0)
1461 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
1464 if ((info
->flags
& DF_TEXTREL
) != 0)
1466 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1471 #undef add_dynamic_entry
1476 /* Relocate an x86_64 ELF section. */
1479 elf64_x86_64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1480 contents
, relocs
, local_syms
, local_sections
)
1482 struct bfd_link_info
*info
;
1484 asection
*input_section
;
1486 Elf_Internal_Rela
*relocs
;
1487 Elf_Internal_Sym
*local_syms
;
1488 asection
**local_sections
;
1490 struct elf64_x86_64_link_hash_table
*htab
;
1491 Elf_Internal_Shdr
*symtab_hdr
;
1492 struct elf_link_hash_entry
**sym_hashes
;
1493 bfd_vma
*local_got_offsets
;
1494 Elf_Internal_Rela
*rel
;
1495 Elf_Internal_Rela
*relend
;
1497 htab
= elf64_x86_64_hash_table (info
);
1498 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1499 sym_hashes
= elf_sym_hashes (input_bfd
);
1500 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1503 relend
= relocs
+ input_section
->reloc_count
;
1504 for (; rel
< relend
; rel
++)
1507 reloc_howto_type
*howto
;
1508 unsigned long r_symndx
;
1509 struct elf_link_hash_entry
*h
;
1510 Elf_Internal_Sym
*sym
;
1514 boolean unresolved_reloc
;
1515 bfd_reloc_status_type r
;
1517 r_type
= ELF64_R_TYPE (rel
->r_info
);
1518 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
1519 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
1522 if (r_type
< 0 || r_type
>= R_X86_64_max
)
1524 bfd_set_error (bfd_error_bad_value
);
1527 howto
= x86_64_elf_howto_table
+ r_type
;
1529 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1531 if (info
->relocateable
)
1533 /* This is a relocateable link. We don't have to change
1534 anything, unless the reloc is against a section symbol,
1535 in which case we have to adjust according to where the
1536 section symbol winds up in the output section. */
1537 if (r_symndx
< symtab_hdr
->sh_info
)
1539 sym
= local_syms
+ r_symndx
;
1540 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1542 sec
= local_sections
[r_symndx
];
1543 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1550 /* This is a final link. */
1554 unresolved_reloc
= false;
1555 if (r_symndx
< symtab_hdr
->sh_info
)
1557 sym
= local_syms
+ r_symndx
;
1558 sec
= local_sections
[r_symndx
];
1560 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1564 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1565 while (h
->root
.type
== bfd_link_hash_indirect
1566 || h
->root
.type
== bfd_link_hash_warning
)
1567 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1569 if (h
->root
.type
== bfd_link_hash_defined
1570 || h
->root
.type
== bfd_link_hash_defweak
)
1572 sec
= h
->root
.u
.def
.section
;
1573 if (sec
->output_section
== NULL
)
1575 /* Set a flag that will be cleared later if we find a
1576 relocation value for this symbol. output_section
1577 is typically NULL for symbols satisfied by a shared
1579 unresolved_reloc
= true;
1583 relocation
= (h
->root
.u
.def
.value
1584 + sec
->output_section
->vma
1585 + sec
->output_offset
);
1587 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1589 else if (info
->shared
1590 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
1591 && !info
->no_undefined
1592 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1596 if (! ((*info
->callbacks
->undefined_symbol
)
1597 (info
, h
->root
.root
.string
, input_bfd
,
1598 input_section
, rel
->r_offset
,
1599 (!info
->shared
|| info
->no_undefined
1600 || ELF_ST_VISIBILITY (h
->other
)))))
1605 /* When generating a shared object, the relocations handled here are
1606 copied into the output file to be resolved at run time. */
1609 case R_X86_64_GOT32
:
1610 /* Relocation is to the entry for this symbol in the global
1612 case R_X86_64_GOTPCREL
:
1613 /* Use global offset table as symbol value. */
1614 if (htab
->sgot
== NULL
)
1621 off
= h
->got
.offset
;
1622 dyn
= htab
->elf
.dynamic_sections_created
;
1624 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
1628 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
1629 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1631 /* This is actually a static link, or it is a -Bsymbolic
1632 link and the symbol is defined locally, or the symbol
1633 was forced to be local because of a version file. We
1634 must initialize this entry in the global offset table.
1635 Since the offset must always be a multiple of 8, we
1636 use the least significant bit to record whether we
1637 have initialized it already.
1639 When doing a dynamic link, we create a .rela.got
1640 relocation entry to initialize the value. This is
1641 done in the finish_dynamic_symbol routine. */
1646 bfd_put_64 (output_bfd
, relocation
,
1647 htab
->sgot
->contents
+ off
);
1652 unresolved_reloc
= false;
1656 if (local_got_offsets
== NULL
)
1659 off
= local_got_offsets
[r_symndx
];
1661 /* The offset must always be a multiple of 8. We use
1662 the least significant bit to record whether we have
1663 already generated the necessary reloc. */
1668 bfd_put_64 (output_bfd
, relocation
,
1669 htab
->sgot
->contents
+ off
);
1674 Elf_Internal_Rela outrel
;
1675 Elf64_External_Rela
*loc
;
1677 /* We need to generate a R_X86_64_RELATIVE reloc
1678 for the dynamic linker. */
1679 srelgot
= htab
->srelgot
;
1680 if (srelgot
== NULL
)
1683 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
1684 + htab
->sgot
->output_offset
1686 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
1687 outrel
.r_addend
= relocation
;
1688 loc
= (Elf64_External_Rela
*) srelgot
->contents
;
1689 loc
+= srelgot
->reloc_count
++;
1690 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1693 local_got_offsets
[r_symndx
] |= 1;
1697 if (off
>= (bfd_vma
) -2)
1700 relocation
= htab
->sgot
->output_offset
+ off
;
1701 if (r_type
== R_X86_64_GOTPCREL
)
1702 relocation
+= htab
->sgot
->output_section
->vma
;
1706 case R_X86_64_PLT32
:
1707 /* Relocation is to the entry for this symbol in the
1708 procedure linkage table. */
1710 /* Resolve a PLT32 reloc against a local symbol directly,
1711 without using the procedure linkage table. */
1715 if (h
->plt
.offset
== (bfd_vma
) -1
1716 || htab
->splt
== NULL
)
1718 /* We didn't make a PLT entry for this symbol. This
1719 happens when statically linking PIC code, or when
1720 using -Bsymbolic. */
1724 relocation
= (htab
->splt
->output_section
->vma
1725 + htab
->splt
->output_offset
1727 unresolved_reloc
= false;
1737 /* FIXME: The ABI says the linker should make sure the value is
1738 the same when it's zeroextended to 64 bit. */
1740 /* r_symndx will be zero only for relocs against symbols
1741 from removed linkonce sections, or sections discarded by
1744 || (input_section
->flags
& SEC_ALLOC
) == 0)
1748 && ((r_type
!= R_X86_64_PC8
1749 && r_type
!= R_X86_64_PC16
1750 && r_type
!= R_X86_64_PC32
)
1753 && (! info
->symbolic
1754 || (h
->elf_link_hash_flags
1755 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1759 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1760 && (((h
->elf_link_hash_flags
1761 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1762 && (h
->elf_link_hash_flags
1763 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1764 || h
->root
.type
== bfd_link_hash_undefweak
1765 || h
->root
.type
== bfd_link_hash_undefined
)))
1767 Elf_Internal_Rela outrel
;
1768 boolean skip
, relocate
;
1770 Elf64_External_Rela
*loc
;
1772 /* When generating a shared object, these relocations
1773 are copied into the output file to be resolved at run
1780 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1782 if (outrel
.r_offset
== (bfd_vma
) -1)
1784 else if (outrel
.r_offset
== (bfd_vma
) -2)
1785 skip
= true, relocate
= true;
1787 outrel
.r_offset
+= (input_section
->output_section
->vma
1788 + input_section
->output_offset
);
1791 memset (&outrel
, 0, sizeof outrel
);
1793 /* h->dynindx may be -1 if this symbol was marked to
1797 && (r_type
== R_X86_64_PC8
1798 || r_type
== R_X86_64_PC16
1799 || r_type
== R_X86_64_PC32
1802 || (h
->elf_link_hash_flags
1803 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1805 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
1806 outrel
.r_addend
= rel
->r_addend
;
1810 /* This symbol is local, or marked to become local. */
1812 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
1813 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1816 sreloc
= elf_section_data (input_section
)->sreloc
;
1820 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
1821 loc
+= sreloc
->reloc_count
++;
1822 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1824 /* If this reloc is against an external symbol, we do
1825 not want to fiddle with the addend. Otherwise, we
1826 need to include the symbol value so that it becomes
1827 an addend for the dynamic reloc. */
1838 /* FIXME: Why do we allow debugging sections to escape this error?
1839 More importantly, why do we not emit dynamic relocs for
1840 R_386_32 above in debugging sections (which are ! SEC_ALLOC)?
1841 If we had emitted the dynamic reloc, we could remove the
1843 if (unresolved_reloc
1845 && (input_section
->flags
& SEC_DEBUGGING
) != 0
1846 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
1847 (*_bfd_error_handler
)
1848 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
1849 bfd_archive_filename (input_bfd
),
1850 bfd_get_section_name (input_bfd
, input_section
),
1851 (long) rel
->r_offset
,
1852 h
->root
.root
.string
);
1854 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1855 contents
, rel
->r_offset
,
1856 relocation
, rel
->r_addend
);
1858 if (r
!= bfd_reloc_ok
)
1863 name
= h
->root
.root
.string
;
1866 name
= bfd_elf_string_from_elf_section (input_bfd
,
1867 symtab_hdr
->sh_link
,
1872 name
= bfd_section_name (input_bfd
, sec
);
1875 if (r
== bfd_reloc_overflow
)
1878 if (! ((*info
->callbacks
->reloc_overflow
)
1879 (info
, name
, howto
->name
, (bfd_vma
) 0,
1880 input_bfd
, input_section
, rel
->r_offset
)))
1885 (*_bfd_error_handler
)
1886 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
1887 bfd_archive_filename (input_bfd
),
1888 bfd_get_section_name (input_bfd
, input_section
),
1889 (long) rel
->r_offset
, name
, (int) r
);
1898 /* Finish up dynamic symbol handling. We set the contents of various
1899 dynamic sections here. */
1902 elf64_x86_64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1904 struct bfd_link_info
*info
;
1905 struct elf_link_hash_entry
*h
;
1906 Elf_Internal_Sym
*sym
;
1908 struct elf64_x86_64_link_hash_table
*htab
;
1910 htab
= elf64_x86_64_hash_table (info
);
1912 if (h
->plt
.offset
!= (bfd_vma
) -1)
1916 Elf_Internal_Rela rela
;
1917 Elf64_External_Rela
*loc
;
1919 /* This symbol has an entry in the procedure linkage table. Set
1922 if (h
->dynindx
== -1
1923 || htab
->splt
== NULL
1924 || htab
->sgotplt
== NULL
1925 || htab
->srelplt
== NULL
)
1928 /* Get the index in the procedure linkage table which
1929 corresponds to this symbol. This is the index of this symbol
1930 in all the symbols for which we are making plt entries. The
1931 first entry in the procedure linkage table is reserved. */
1932 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1934 /* Get the offset into the .got table of the entry that
1935 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
1936 bytes. The first three are reserved for the dynamic linker. */
1937 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
1939 /* Fill in the entry in the procedure linkage table. */
1940 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
1943 /* Insert the relocation positions of the plt section. The magic
1944 numbers at the end of the statements are the positions of the
1945 relocations in the plt section. */
1946 /* Put offset for jmp *name@GOTPCREL(%rip), since the
1947 instruction uses 6 bytes, subtract this value. */
1948 bfd_put_32 (output_bfd
,
1949 (htab
->sgotplt
->output_section
->vma
1950 + htab
->sgotplt
->output_offset
1952 - htab
->splt
->output_section
->vma
1953 - htab
->splt
->output_offset
1956 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
1957 /* Put relocation index. */
1958 bfd_put_32 (output_bfd
, plt_index
,
1959 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
1960 /* Put offset for jmp .PLT0. */
1961 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
1962 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
1964 /* Fill in the entry in the global offset table, initially this
1965 points to the pushq instruction in the PLT which is at offset 6. */
1966 bfd_put_64 (output_bfd
, (htab
->splt
->output_section
->vma
1967 + htab
->splt
->output_offset
1968 + h
->plt
.offset
+ 6),
1969 htab
->sgotplt
->contents
+ got_offset
);
1971 /* Fill in the entry in the .rela.plt section. */
1972 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
1973 + htab
->sgotplt
->output_offset
1975 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
1977 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
+ plt_index
;
1978 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
1980 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1982 /* Mark the symbol as undefined, rather than as defined in
1983 the .plt section. Leave the value alone. This is a clue
1984 for the dynamic linker, to make function pointer
1985 comparisons work between an application and shared
1987 sym
->st_shndx
= SHN_UNDEF
;
1991 if (h
->got
.offset
!= (bfd_vma
) -1)
1993 Elf_Internal_Rela rela
;
1994 Elf64_External_Rela
*loc
;
1996 /* This symbol has an entry in the global offset table. Set it
1999 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
2002 rela
.r_offset
= (htab
->sgot
->output_section
->vma
2003 + htab
->sgot
->output_offset
2004 + (h
->got
.offset
&~ (bfd_vma
) 1));
2006 /* If this is a static link, or it is a -Bsymbolic link and the
2007 symbol is defined locally or was forced to be local because
2008 of a version file, we just want to emit a RELATIVE reloc.
2009 The entry in the global offset table will already have been
2010 initialized in the relocate_section function. */
2014 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2015 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2017 BFD_ASSERT((h
->got
.offset
& 1) != 0);
2018 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2019 rela
.r_addend
= (h
->root
.u
.def
.value
2020 + h
->root
.u
.def
.section
->output_section
->vma
2021 + h
->root
.u
.def
.section
->output_offset
);
2025 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2026 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2027 htab
->sgot
->contents
+ h
->got
.offset
);
2028 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
2032 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
2033 loc
+= htab
->srelgot
->reloc_count
++;
2034 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2037 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2039 Elf_Internal_Rela rela
;
2040 Elf64_External_Rela
*loc
;
2042 /* This symbol needs a copy reloc. Set it up. */
2044 if (h
->dynindx
== -1
2045 || (h
->root
.type
!= bfd_link_hash_defined
2046 && h
->root
.type
!= bfd_link_hash_defweak
)
2047 || htab
->srelbss
== NULL
)
2050 rela
.r_offset
= (h
->root
.u
.def
.value
2051 + h
->root
.u
.def
.section
->output_section
->vma
2052 + h
->root
.u
.def
.section
->output_offset
);
2053 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
2055 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
2056 loc
+= htab
->srelbss
->reloc_count
++;
2057 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2060 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2061 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2062 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2063 sym
->st_shndx
= SHN_ABS
;
2068 /* Used to decide how to sort relocs in an optimal manner for the
2069 dynamic linker, before writing them out. */
2071 static enum elf_reloc_type_class
2072 elf64_x86_64_reloc_type_class (rela
)
2073 const Elf_Internal_Rela
*rela
;
2075 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2077 case R_X86_64_RELATIVE
:
2078 return reloc_class_relative
;
2079 case R_X86_64_JUMP_SLOT
:
2080 return reloc_class_plt
;
2082 return reloc_class_copy
;
2084 return reloc_class_normal
;
2088 /* Finish up the dynamic sections. */
2091 elf64_x86_64_finish_dynamic_sections (output_bfd
, info
)
2093 struct bfd_link_info
*info
;
2095 struct elf64_x86_64_link_hash_table
*htab
;
2099 htab
= elf64_x86_64_hash_table (info
);
2100 dynobj
= htab
->elf
.dynobj
;
2101 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2103 if (htab
->elf
.dynamic_sections_created
)
2105 Elf64_External_Dyn
*dyncon
, *dynconend
;
2107 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
2110 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2111 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2112 for (; dyncon
< dynconend
; dyncon
++)
2114 Elf_Internal_Dyn dyn
;
2117 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2125 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
2129 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
2133 s
= htab
->srelplt
->output_section
;
2134 if (s
->_cooked_size
!= 0)
2135 dyn
.d_un
.d_val
= s
->_cooked_size
;
2137 dyn
.d_un
.d_val
= s
->_raw_size
;
2141 /* The procedure linkage table relocs (DT_JMPREL) should
2142 not be included in the overall relocs (DT_RELA).
2143 Therefore, we override the DT_RELASZ entry here to
2144 make it not include the JMPREL relocs. Since the
2145 linker script arranges for .rela.plt to follow all
2146 other relocation sections, we don't have to worry
2147 about changing the DT_RELA entry. */
2148 if (htab
->srelplt
!= NULL
)
2150 s
= htab
->srelplt
->output_section
;
2151 if (s
->_cooked_size
!= 0)
2152 dyn
.d_un
.d_val
-= s
->_cooked_size
;
2154 dyn
.d_un
.d_val
-= s
->_raw_size
;
2159 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2162 /* Fill in the special first entry in the procedure linkage table. */
2163 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
2165 /* Fill in the first entry in the procedure linkage table. */
2166 memcpy (htab
->splt
->contents
, elf64_x86_64_plt0_entry
,
2168 /* Add offset for pushq GOT+8(%rip), since the instruction
2169 uses 6 bytes subtract this value. */
2170 bfd_put_32 (output_bfd
,
2171 (htab
->sgotplt
->output_section
->vma
2172 + htab
->sgotplt
->output_offset
2174 - htab
->splt
->output_section
->vma
2175 - htab
->splt
->output_offset
2177 htab
->splt
->contents
+ 2);
2178 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
2179 the end of the instruction. */
2180 bfd_put_32 (output_bfd
,
2181 (htab
->sgotplt
->output_section
->vma
2182 + htab
->sgotplt
->output_offset
2184 - htab
->splt
->output_section
->vma
2185 - htab
->splt
->output_offset
2187 htab
->splt
->contents
+ 8);
2189 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
=
2196 /* Fill in the first three entries in the global offset table. */
2197 if (htab
->sgotplt
->_raw_size
> 0)
2199 /* Set the first entry in the global offset table to the address of
2200 the dynamic section. */
2202 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
);
2204 bfd_put_64 (output_bfd
,
2205 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2206 htab
->sgotplt
->contents
);
2207 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
2208 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
);
2209 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
2212 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
=
2220 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
2221 #define TARGET_LITTLE_NAME "elf64-x86-64"
2222 #define ELF_ARCH bfd_arch_i386
2223 #define ELF_MACHINE_CODE EM_X86_64
2224 #define ELF_MAXPAGESIZE 0x100000
2226 #define elf_backend_can_gc_sections 1
2227 #define elf_backend_can_refcount 1
2228 #define elf_backend_want_got_plt 1
2229 #define elf_backend_plt_readonly 1
2230 #define elf_backend_want_plt_sym 0
2231 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
2232 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2234 #define elf_info_to_howto elf64_x86_64_info_to_howto
2236 #define bfd_elf64_bfd_link_hash_table_create \
2237 elf64_x86_64_link_hash_table_create
2238 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
2240 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
2241 #define elf_backend_check_relocs elf64_x86_64_check_relocs
2242 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
2243 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
2244 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
2245 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
2246 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
2247 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
2248 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
2249 #define elf_backend_relocate_section elf64_x86_64_relocate_section
2250 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
2251 #define elf_backend_object_p elf64_x86_64_elf_object_p
2253 #include "elf64-target.h"