1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka <jh@suse.cz>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
28 #include "elf/x86-64.h"
30 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
31 #define MINUS_ONE (~ (bfd_vma) 0)
33 /* The relocation "howto" table. Order of fields:
34 type, size, bitsize, pc_relative, complain_on_overflow,
35 special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
36 static reloc_howto_type x86_64_elf_howto_table
[] =
38 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
39 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
41 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
42 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
44 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
45 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
47 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
48 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
50 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
51 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
53 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
54 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
56 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
57 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
59 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
60 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
62 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
65 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
66 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
68 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
69 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
71 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
72 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
74 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
75 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
76 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
78 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_signed
,
79 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
80 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
81 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
82 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
85 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
88 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
91 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
92 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
94 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
95 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
97 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
100 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
103 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
104 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
106 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
107 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
109 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
110 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
111 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
112 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
113 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
114 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
116 /* GNU extension to record C++ vtable hierarchy. */
117 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
118 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
120 /* GNU extension to record C++ vtable member usage. */
121 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
122 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
126 /* Map BFD relocs to the x86_64 elf relocs. */
129 bfd_reloc_code_real_type bfd_reloc_val
;
130 unsigned char elf_reloc_val
;
133 static const struct elf_reloc_map x86_64_reloc_map
[] =
135 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
136 { BFD_RELOC_64
, R_X86_64_64
, },
137 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
138 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
139 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
140 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
141 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
142 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
143 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
144 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
145 { BFD_RELOC_32
, R_X86_64_32
, },
146 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
147 { BFD_RELOC_16
, R_X86_64_16
, },
148 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
149 { BFD_RELOC_8
, R_X86_64_8
, },
150 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
151 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
152 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
153 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
154 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
155 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
156 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
157 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
158 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
159 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
160 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
161 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
162 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
163 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
167 /* Given a BFD reloc type, return a HOWTO structure. */
168 static reloc_howto_type
*
169 elf64_x86_64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
170 bfd_reloc_code_real_type code
)
174 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
177 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
178 return &x86_64_elf_howto_table
[i
];
183 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
186 elf64_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
187 Elf_Internal_Rela
*dst
)
191 r_type
= ELF64_R_TYPE (dst
->r_info
);
192 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
193 || r_type
>= (unsigned int) R_X86_64_max
)
195 if (r_type
> (unsigned int) R_X86_64_GOTPC32
)
197 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
199 r_type
= R_X86_64_NONE
;
204 i
= r_type
- ((unsigned int) R_X86_64_GNU_VTINHERIT
- R_X86_64_GOTPC32
- 1);
205 cache_ptr
->howto
= &x86_64_elf_howto_table
[i
];
206 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
209 /* Support for core dump NOTE sections. */
211 elf64_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
216 switch (note
->descsz
)
221 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
223 elf_tdata (abfd
)->core_signal
224 = bfd_get_16 (abfd
, note
->descdata
+ 12);
227 elf_tdata (abfd
)->core_pid
228 = bfd_get_32 (abfd
, note
->descdata
+ 32);
237 /* Make a ".reg/999" section. */
238 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
239 size
, note
->descpos
+ offset
);
243 elf64_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
245 switch (note
->descsz
)
250 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
251 elf_tdata (abfd
)->core_program
252 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
253 elf_tdata (abfd
)->core_command
254 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
257 /* Note that for some reason, a spurious space is tacked
258 onto the end of the args in some (at least one anyway)
259 implementations, so strip it off if it exists. */
262 char *command
= elf_tdata (abfd
)->core_command
;
263 int n
= strlen (command
);
265 if (0 < n
&& command
[n
- 1] == ' ')
266 command
[n
- 1] = '\0';
272 /* Functions for the x86-64 ELF linker. */
274 /* The name of the dynamic interpreter. This is put in the .interp
277 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
279 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
280 copying dynamic variables from a shared lib into an app's dynbss
281 section, and instead use a dynamic relocation to point into the
283 #define ELIMINATE_COPY_RELOCS 1
285 /* The size in bytes of an entry in the global offset table. */
287 #define GOT_ENTRY_SIZE 8
289 /* The size in bytes of an entry in the procedure linkage table. */
291 #define PLT_ENTRY_SIZE 16
293 /* The first entry in a procedure linkage table looks like this. See the
294 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
296 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
298 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
299 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
300 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
303 /* Subsequent entries in a procedure linkage table look like this. */
305 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
307 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
308 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
309 0x68, /* pushq immediate */
310 0, 0, 0, 0, /* replaced with index into relocation table. */
311 0xe9, /* jmp relative */
312 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
315 /* The x86-64 linker needs to keep track of the number of relocs that
316 it decides to copy as dynamic relocs in check_relocs for each symbol.
317 This is so that it can later discard them if they are found to be
318 unnecessary. We store the information in a field extending the
319 regular ELF linker hash table. */
321 struct elf64_x86_64_dyn_relocs
324 struct elf64_x86_64_dyn_relocs
*next
;
326 /* The input section of the reloc. */
329 /* Total number of relocs copied for the input section. */
332 /* Number of pc-relative relocs copied for the input section. */
333 bfd_size_type pc_count
;
336 /* x86-64 ELF linker hash entry. */
338 struct elf64_x86_64_link_hash_entry
340 struct elf_link_hash_entry elf
;
342 /* Track dynamic relocs copied for this symbol. */
343 struct elf64_x86_64_dyn_relocs
*dyn_relocs
;
345 #define GOT_UNKNOWN 0
349 unsigned char tls_type
;
352 #define elf64_x86_64_hash_entry(ent) \
353 ((struct elf64_x86_64_link_hash_entry *)(ent))
355 struct elf64_x86_64_obj_tdata
357 struct elf_obj_tdata root
;
359 /* tls_type for each local got entry. */
360 char *local_got_tls_type
;
363 #define elf64_x86_64_tdata(abfd) \
364 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
366 #define elf64_x86_64_local_got_tls_type(abfd) \
367 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
370 /* x86-64 ELF linker hash table. */
372 struct elf64_x86_64_link_hash_table
374 struct elf_link_hash_table elf
;
376 /* Short-cuts to get to dynamic linker sections. */
386 bfd_signed_vma refcount
;
390 /* Small local sym to section mapping cache. */
391 struct sym_sec_cache sym_sec
;
394 /* Get the x86-64 ELF linker hash table from a link_info structure. */
396 #define elf64_x86_64_hash_table(p) \
397 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
399 /* Create an entry in an x86-64 ELF linker hash table. */
401 static struct bfd_hash_entry
*
402 link_hash_newfunc (struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
405 /* Allocate the structure if it has not already been allocated by a
409 entry
= bfd_hash_allocate (table
,
410 sizeof (struct elf64_x86_64_link_hash_entry
));
415 /* Call the allocation method of the superclass. */
416 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
419 struct elf64_x86_64_link_hash_entry
*eh
;
421 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
422 eh
->dyn_relocs
= NULL
;
423 eh
->tls_type
= GOT_UNKNOWN
;
429 /* Create an X86-64 ELF linker hash table. */
431 static struct bfd_link_hash_table
*
432 elf64_x86_64_link_hash_table_create (bfd
*abfd
)
434 struct elf64_x86_64_link_hash_table
*ret
;
435 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
437 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_malloc (amt
);
441 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
454 ret
->sym_sec
.abfd
= NULL
;
455 ret
->tls_ld_got
.refcount
= 0;
457 return &ret
->elf
.root
;
460 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
461 shortcuts to them in our hash table. */
464 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
466 struct elf64_x86_64_link_hash_table
*htab
;
468 if (! _bfd_elf_create_got_section (dynobj
, info
))
471 htab
= elf64_x86_64_hash_table (info
);
472 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
473 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
474 if (!htab
->sgot
|| !htab
->sgotplt
)
477 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rela.got",
478 (SEC_ALLOC
| SEC_LOAD
483 if (htab
->srelgot
== NULL
484 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
489 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
490 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
494 elf64_x86_64_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
496 struct elf64_x86_64_link_hash_table
*htab
;
498 htab
= elf64_x86_64_hash_table (info
);
499 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
502 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
505 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
506 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
507 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
509 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
511 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
512 || (!info
->shared
&& !htab
->srelbss
))
518 /* Copy the extra info we tack onto an elf_link_hash_entry. */
521 elf64_x86_64_copy_indirect_symbol (const struct elf_backend_data
*bed
,
522 struct elf_link_hash_entry
*dir
,
523 struct elf_link_hash_entry
*ind
)
525 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
527 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
528 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
530 if (eind
->dyn_relocs
!= NULL
)
532 if (edir
->dyn_relocs
!= NULL
)
534 struct elf64_x86_64_dyn_relocs
**pp
;
535 struct elf64_x86_64_dyn_relocs
*p
;
537 if (ind
->root
.type
== bfd_link_hash_indirect
)
540 /* Add reloc counts against the weak sym to the strong sym
541 list. Merge any entries against the same section. */
542 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
544 struct elf64_x86_64_dyn_relocs
*q
;
546 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
547 if (q
->sec
== p
->sec
)
549 q
->pc_count
+= p
->pc_count
;
550 q
->count
+= p
->count
;
557 *pp
= edir
->dyn_relocs
;
560 edir
->dyn_relocs
= eind
->dyn_relocs
;
561 eind
->dyn_relocs
= NULL
;
564 if (ind
->root
.type
== bfd_link_hash_indirect
565 && dir
->got
.refcount
<= 0)
567 edir
->tls_type
= eind
->tls_type
;
568 eind
->tls_type
= GOT_UNKNOWN
;
571 if (ELIMINATE_COPY_RELOCS
572 && ind
->root
.type
!= bfd_link_hash_indirect
573 && dir
->dynamic_adjusted
)
575 /* If called to transfer flags for a weakdef during processing
576 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
577 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
578 dir
->ref_dynamic
|= ind
->ref_dynamic
;
579 dir
->ref_regular
|= ind
->ref_regular
;
580 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
581 dir
->needs_plt
|= ind
->needs_plt
;
582 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
585 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
589 elf64_x86_64_mkobject (bfd
*abfd
)
591 bfd_size_type amt
= sizeof (struct elf64_x86_64_obj_tdata
);
592 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
593 if (abfd
->tdata
.any
== NULL
)
599 elf64_x86_64_elf_object_p (bfd
*abfd
)
601 /* Set the right machine number for an x86-64 elf64 file. */
602 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
607 elf64_x86_64_tls_transition (struct bfd_link_info
*info
, int r_type
, int is_local
)
615 case R_X86_64_GOTTPOFF
:
617 return R_X86_64_TPOFF32
;
618 return R_X86_64_GOTTPOFF
;
620 return R_X86_64_TPOFF32
;
626 /* Look through the relocs for a section during the first phase, and
627 calculate needed space in the global offset table, procedure
628 linkage table, and dynamic reloc sections. */
631 elf64_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
632 const Elf_Internal_Rela
*relocs
)
634 struct elf64_x86_64_link_hash_table
*htab
;
635 Elf_Internal_Shdr
*symtab_hdr
;
636 struct elf_link_hash_entry
**sym_hashes
;
637 const Elf_Internal_Rela
*rel
;
638 const Elf_Internal_Rela
*rel_end
;
641 if (info
->relocatable
)
644 htab
= elf64_x86_64_hash_table (info
);
645 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
646 sym_hashes
= elf_sym_hashes (abfd
);
650 rel_end
= relocs
+ sec
->reloc_count
;
651 for (rel
= relocs
; rel
< rel_end
; rel
++)
654 unsigned long r_symndx
;
655 struct elf_link_hash_entry
*h
;
657 r_symndx
= ELF64_R_SYM (rel
->r_info
);
658 r_type
= ELF64_R_TYPE (rel
->r_info
);
660 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
662 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
667 if (r_symndx
< symtab_hdr
->sh_info
)
671 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
672 while (h
->root
.type
== bfd_link_hash_indirect
673 || h
->root
.type
== bfd_link_hash_warning
)
674 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
677 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
== NULL
);
681 htab
->tls_ld_got
.refcount
+= 1;
684 case R_X86_64_TPOFF32
:
687 (*_bfd_error_handler
)
688 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
690 x86_64_elf_howto_table
[r_type
].name
,
691 (h
) ? h
->root
.root
.string
: "a local symbol");
692 bfd_set_error (bfd_error_bad_value
);
697 case R_X86_64_GOTTPOFF
:
699 info
->flags
|= DF_STATIC_TLS
;
703 case R_X86_64_GOTPCREL
:
705 /* This symbol requires a global offset table entry. */
707 int tls_type
, old_tls_type
;
711 default: tls_type
= GOT_NORMAL
; break;
712 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
713 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
718 h
->got
.refcount
+= 1;
719 old_tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
723 bfd_signed_vma
*local_got_refcounts
;
725 /* This is a global offset table entry for a local symbol. */
726 local_got_refcounts
= elf_local_got_refcounts (abfd
);
727 if (local_got_refcounts
== NULL
)
731 size
= symtab_hdr
->sh_info
;
732 size
*= sizeof (bfd_signed_vma
) + sizeof (char);
733 local_got_refcounts
= ((bfd_signed_vma
*)
734 bfd_zalloc (abfd
, size
));
735 if (local_got_refcounts
== NULL
)
737 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
738 elf64_x86_64_local_got_tls_type (abfd
)
739 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
741 local_got_refcounts
[r_symndx
] += 1;
743 = elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
];
746 /* If a TLS symbol is accessed using IE at least once,
747 there is no point to use dynamic model for it. */
748 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
749 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
751 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
752 tls_type
= old_tls_type
;
755 (*_bfd_error_handler
)
756 (_("%B: %s' accessed both as normal and thread local symbol"),
757 abfd
, h
? h
->root
.root
.string
: "<local>");
762 if (old_tls_type
!= tls_type
)
765 elf64_x86_64_hash_entry (h
)->tls_type
= tls_type
;
767 elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
772 case R_X86_64_GOTOFF64
:
773 case R_X86_64_GOTPC32
:
775 if (htab
->sgot
== NULL
)
777 if (htab
->elf
.dynobj
== NULL
)
778 htab
->elf
.dynobj
= abfd
;
779 if (!create_got_section (htab
->elf
.dynobj
, info
))
785 /* This symbol requires a procedure linkage table entry. We
786 actually build the entry in adjust_dynamic_symbol,
787 because this might be a case of linking PIC code which is
788 never referenced by a dynamic object, in which case we
789 don't need to generate a procedure linkage table entry
792 /* If this is a local symbol, we resolve it directly without
793 creating a procedure linkage table entry. */
798 h
->plt
.refcount
+= 1;
805 /* Let's help debug shared library creation. These relocs
806 cannot be used in shared libs. Don't error out for
807 sections we don't care about, such as debug sections or
808 non-constant sections. */
810 && (sec
->flags
& SEC_ALLOC
) != 0
811 && (sec
->flags
& SEC_READONLY
) != 0)
813 (*_bfd_error_handler
)
814 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
816 x86_64_elf_howto_table
[r_type
].name
,
817 (h
) ? h
->root
.root
.string
: "a local symbol");
818 bfd_set_error (bfd_error_bad_value
);
828 if (h
!= NULL
&& !info
->shared
)
830 /* If this reloc is in a read-only section, we might
831 need a copy reloc. We can't check reliably at this
832 stage whether the section is read-only, as input
833 sections have not yet been mapped to output sections.
834 Tentatively set the flag for now, and correct in
835 adjust_dynamic_symbol. */
838 /* We may need a .plt entry if the function this reloc
839 refers to is in a shared lib. */
840 h
->plt
.refcount
+= 1;
841 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
842 h
->pointer_equality_needed
= 1;
845 /* If we are creating a shared library, and this is a reloc
846 against a global symbol, or a non PC relative reloc
847 against a local symbol, then we need to copy the reloc
848 into the shared library. However, if we are linking with
849 -Bsymbolic, we do not need to copy a reloc against a
850 global symbol which is defined in an object we are
851 including in the link (i.e., DEF_REGULAR is set). At
852 this point we have not seen all the input files, so it is
853 possible that DEF_REGULAR is not set now but will be set
854 later (it is never cleared). In case of a weak definition,
855 DEF_REGULAR may be cleared later by a strong definition in
856 a shared library. We account for that possibility below by
857 storing information in the relocs_copied field of the hash
858 table entry. A similar situation occurs when creating
859 shared libraries and symbol visibility changes render the
862 If on the other hand, we are creating an executable, we
863 may need to keep relocations for symbols satisfied by a
864 dynamic library if we manage to avoid copy relocs for the
867 && (sec
->flags
& SEC_ALLOC
) != 0
868 && (((r_type
!= R_X86_64_PC8
)
869 && (r_type
!= R_X86_64_PC16
)
870 && (r_type
!= R_X86_64_PC32
)
871 && (r_type
!= R_X86_64_PC64
))
874 || h
->root
.type
== bfd_link_hash_defweak
875 || !h
->def_regular
))))
876 || (ELIMINATE_COPY_RELOCS
878 && (sec
->flags
& SEC_ALLOC
) != 0
880 && (h
->root
.type
== bfd_link_hash_defweak
881 || !h
->def_regular
)))
883 struct elf64_x86_64_dyn_relocs
*p
;
884 struct elf64_x86_64_dyn_relocs
**head
;
886 /* We must copy these reloc types into the output file.
887 Create a reloc section in dynobj and make room for
894 name
= (bfd_elf_string_from_elf_section
896 elf_elfheader (abfd
)->e_shstrndx
,
897 elf_section_data (sec
)->rel_hdr
.sh_name
));
901 if (strncmp (name
, ".rela", 5) != 0
902 || strcmp (bfd_get_section_name (abfd
, sec
),
905 (*_bfd_error_handler
)
906 (_("%B: bad relocation section name `%s\'"),
910 if (htab
->elf
.dynobj
== NULL
)
911 htab
->elf
.dynobj
= abfd
;
913 dynobj
= htab
->elf
.dynobj
;
915 sreloc
= bfd_get_section_by_name (dynobj
, name
);
920 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
921 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
922 if ((sec
->flags
& SEC_ALLOC
) != 0)
923 flags
|= SEC_ALLOC
| SEC_LOAD
;
924 sreloc
= bfd_make_section_with_flags (dynobj
,
928 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
931 elf_section_data (sec
)->sreloc
= sreloc
;
934 /* If this is a global symbol, we count the number of
935 relocations we need for this symbol. */
938 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
942 /* Track dynamic relocs needed for local syms too.
943 We really need local syms available to do this
947 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
952 head
= ((struct elf64_x86_64_dyn_relocs
**)
953 &elf_section_data (s
)->local_dynrel
);
957 if (p
== NULL
|| p
->sec
!= sec
)
959 bfd_size_type amt
= sizeof *p
;
960 p
= ((struct elf64_x86_64_dyn_relocs
*)
961 bfd_alloc (htab
->elf
.dynobj
, amt
));
972 if (r_type
== R_X86_64_PC8
973 || r_type
== R_X86_64_PC16
974 || r_type
== R_X86_64_PC32
975 || r_type
== R_X86_64_PC64
)
980 /* This relocation describes the C++ object vtable hierarchy.
981 Reconstruct it for later use during GC. */
982 case R_X86_64_GNU_VTINHERIT
:
983 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
987 /* This relocation describes which C++ vtable entries are actually
988 used. Record for later use during GC. */
989 case R_X86_64_GNU_VTENTRY
:
990 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1002 /* Return the section that should be marked against GC for a given
1006 elf64_x86_64_gc_mark_hook (asection
*sec
,
1007 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1008 Elf_Internal_Rela
*rel
,
1009 struct elf_link_hash_entry
*h
,
1010 Elf_Internal_Sym
*sym
)
1014 switch (ELF64_R_TYPE (rel
->r_info
))
1016 case R_X86_64_GNU_VTINHERIT
:
1017 case R_X86_64_GNU_VTENTRY
:
1021 switch (h
->root
.type
)
1023 case bfd_link_hash_defined
:
1024 case bfd_link_hash_defweak
:
1025 return h
->root
.u
.def
.section
;
1027 case bfd_link_hash_common
:
1028 return h
->root
.u
.c
.p
->section
;
1036 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1041 /* Update the got entry reference counts for the section being removed. */
1044 elf64_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1045 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1047 Elf_Internal_Shdr
*symtab_hdr
;
1048 struct elf_link_hash_entry
**sym_hashes
;
1049 bfd_signed_vma
*local_got_refcounts
;
1050 const Elf_Internal_Rela
*rel
, *relend
;
1052 elf_section_data (sec
)->local_dynrel
= NULL
;
1054 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1055 sym_hashes
= elf_sym_hashes (abfd
);
1056 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1058 relend
= relocs
+ sec
->reloc_count
;
1059 for (rel
= relocs
; rel
< relend
; rel
++)
1061 unsigned long r_symndx
;
1062 unsigned int r_type
;
1063 struct elf_link_hash_entry
*h
= NULL
;
1065 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1066 if (r_symndx
>= symtab_hdr
->sh_info
)
1068 struct elf64_x86_64_link_hash_entry
*eh
;
1069 struct elf64_x86_64_dyn_relocs
**pp
;
1070 struct elf64_x86_64_dyn_relocs
*p
;
1072 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1073 while (h
->root
.type
== bfd_link_hash_indirect
1074 || h
->root
.type
== bfd_link_hash_warning
)
1075 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1076 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1078 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1081 /* Everything must go for SEC. */
1087 r_type
= ELF64_R_TYPE (rel
->r_info
);
1088 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
!= NULL
);
1091 case R_X86_64_TLSLD
:
1092 if (elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
> 0)
1093 elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
-= 1;
1096 case R_X86_64_TLSGD
:
1097 case R_X86_64_GOTTPOFF
:
1098 case R_X86_64_GOT32
:
1099 case R_X86_64_GOTPCREL
:
1102 if (h
->got
.refcount
> 0)
1103 h
->got
.refcount
-= 1;
1105 else if (local_got_refcounts
!= NULL
)
1107 if (local_got_refcounts
[r_symndx
] > 0)
1108 local_got_refcounts
[r_symndx
] -= 1;
1125 case R_X86_64_PLT32
:
1128 if (h
->plt
.refcount
> 0)
1129 h
->plt
.refcount
-= 1;
1141 /* Adjust a symbol defined by a dynamic object and referenced by a
1142 regular object. The current definition is in some section of the
1143 dynamic object, but we're not including those sections. We have to
1144 change the definition to something the rest of the link can
1148 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1149 struct elf_link_hash_entry
*h
)
1151 struct elf64_x86_64_link_hash_table
*htab
;
1153 unsigned int power_of_two
;
1155 /* If this is a function, put it in the procedure linkage table. We
1156 will fill in the contents of the procedure linkage table later,
1157 when we know the address of the .got section. */
1158 if (h
->type
== STT_FUNC
1161 if (h
->plt
.refcount
<= 0
1162 || SYMBOL_CALLS_LOCAL (info
, h
)
1163 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1164 && h
->root
.type
== bfd_link_hash_undefweak
))
1166 /* This case can occur if we saw a PLT32 reloc in an input
1167 file, but the symbol was never referred to by a dynamic
1168 object, or if all references were garbage collected. In
1169 such a case, we don't actually need to build a procedure
1170 linkage table, and we can just do a PC32 reloc instead. */
1171 h
->plt
.offset
= (bfd_vma
) -1;
1178 /* It's possible that we incorrectly decided a .plt reloc was
1179 needed for an R_X86_64_PC32 reloc to a non-function sym in
1180 check_relocs. We can't decide accurately between function and
1181 non-function syms in check-relocs; Objects loaded later in
1182 the link may change h->type. So fix it now. */
1183 h
->plt
.offset
= (bfd_vma
) -1;
1185 /* If this is a weak symbol, and there is a real definition, the
1186 processor independent code will have arranged for us to see the
1187 real definition first, and we can just use the same value. */
1188 if (h
->u
.weakdef
!= NULL
)
1190 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1191 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1192 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1193 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1194 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1195 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1199 /* This is a reference to a symbol defined by a dynamic object which
1200 is not a function. */
1202 /* If we are creating a shared library, we must presume that the
1203 only references to the symbol are via the global offset table.
1204 For such cases we need not do anything here; the relocations will
1205 be handled correctly by relocate_section. */
1209 /* If there are no references to this symbol that do not use the
1210 GOT, we don't need to generate a copy reloc. */
1211 if (!h
->non_got_ref
)
1214 /* If -z nocopyreloc was given, we won't generate them either. */
1215 if (info
->nocopyreloc
)
1221 if (ELIMINATE_COPY_RELOCS
)
1223 struct elf64_x86_64_link_hash_entry
* eh
;
1224 struct elf64_x86_64_dyn_relocs
*p
;
1226 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1227 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1229 s
= p
->sec
->output_section
;
1230 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1234 /* If we didn't find any dynamic relocs in read-only sections, then
1235 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1243 /* We must allocate the symbol in our .dynbss section, which will
1244 become part of the .bss section of the executable. There will be
1245 an entry for this symbol in the .dynsym section. The dynamic
1246 object will contain position independent code, so all references
1247 from the dynamic object to this symbol will go through the global
1248 offset table. The dynamic linker will use the .dynsym entry to
1249 determine the address it must put in the global offset table, so
1250 both the dynamic object and the regular object will refer to the
1251 same memory location for the variable. */
1253 htab
= elf64_x86_64_hash_table (info
);
1255 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1256 to copy the initial value out of the dynamic object and into the
1257 runtime process image. */
1258 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1260 htab
->srelbss
->size
+= sizeof (Elf64_External_Rela
);
1264 /* We need to figure out the alignment required for this symbol. I
1265 have no idea how ELF linkers handle this. 16-bytes is the size
1266 of the largest type that requires hard alignment -- long double. */
1267 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
1269 power_of_two
= bfd_log2 (h
->size
);
1270 if (power_of_two
> 4)
1273 /* Apply the required alignment. */
1275 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
1276 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1278 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1282 /* Define the symbol as being at this point in the section. */
1283 h
->root
.u
.def
.section
= s
;
1284 h
->root
.u
.def
.value
= s
->size
;
1286 /* Increment the section size to make room for the symbol. */
1292 /* Allocate space in .plt, .got and associated reloc sections for
1296 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
1298 struct bfd_link_info
*info
;
1299 struct elf64_x86_64_link_hash_table
*htab
;
1300 struct elf64_x86_64_link_hash_entry
*eh
;
1301 struct elf64_x86_64_dyn_relocs
*p
;
1303 if (h
->root
.type
== bfd_link_hash_indirect
)
1306 if (h
->root
.type
== bfd_link_hash_warning
)
1307 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1309 info
= (struct bfd_link_info
*) inf
;
1310 htab
= elf64_x86_64_hash_table (info
);
1312 if (htab
->elf
.dynamic_sections_created
1313 && h
->plt
.refcount
> 0)
1315 /* Make sure this symbol is output as a dynamic symbol.
1316 Undefined weak syms won't yet be marked as dynamic. */
1317 if (h
->dynindx
== -1
1318 && !h
->forced_local
)
1320 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1325 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1327 asection
*s
= htab
->splt
;
1329 /* If this is the first .plt entry, make room for the special
1332 s
->size
+= PLT_ENTRY_SIZE
;
1334 h
->plt
.offset
= s
->size
;
1336 /* If this symbol is not defined in a regular file, and we are
1337 not generating a shared library, then set the symbol to this
1338 location in the .plt. This is required to make function
1339 pointers compare as equal between the normal executable and
1340 the shared library. */
1344 h
->root
.u
.def
.section
= s
;
1345 h
->root
.u
.def
.value
= h
->plt
.offset
;
1348 /* Make room for this entry. */
1349 s
->size
+= PLT_ENTRY_SIZE
;
1351 /* We also need to make an entry in the .got.plt section, which
1352 will be placed in the .got section by the linker script. */
1353 htab
->sgotplt
->size
+= GOT_ENTRY_SIZE
;
1355 /* We also need to make an entry in the .rela.plt section. */
1356 htab
->srelplt
->size
+= sizeof (Elf64_External_Rela
);
1360 h
->plt
.offset
= (bfd_vma
) -1;
1366 h
->plt
.offset
= (bfd_vma
) -1;
1370 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1371 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1372 if (h
->got
.refcount
> 0
1375 && elf64_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
1376 h
->got
.offset
= (bfd_vma
) -1;
1377 else if (h
->got
.refcount
> 0)
1381 int tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1383 /* Make sure this symbol is output as a dynamic symbol.
1384 Undefined weak syms won't yet be marked as dynamic. */
1385 if (h
->dynindx
== -1
1386 && !h
->forced_local
)
1388 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1393 h
->got
.offset
= s
->size
;
1394 s
->size
+= GOT_ENTRY_SIZE
;
1395 /* R_X86_64_TLSGD needs 2 consecutive GOT slots. */
1396 if (tls_type
== GOT_TLS_GD
)
1397 s
->size
+= GOT_ENTRY_SIZE
;
1398 dyn
= htab
->elf
.dynamic_sections_created
;
1399 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
1401 R_X86_64_GOTTPOFF needs one dynamic relocation. */
1402 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
1403 || tls_type
== GOT_TLS_IE
)
1404 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
1405 else if (tls_type
== GOT_TLS_GD
)
1406 htab
->srelgot
->size
+= 2 * sizeof (Elf64_External_Rela
);
1407 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1408 || h
->root
.type
!= bfd_link_hash_undefweak
)
1410 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1411 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
1414 h
->got
.offset
= (bfd_vma
) -1;
1416 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1417 if (eh
->dyn_relocs
== NULL
)
1420 /* In the shared -Bsymbolic case, discard space allocated for
1421 dynamic pc-relative relocs against symbols which turn out to be
1422 defined in regular objects. For the normal shared case, discard
1423 space for pc-relative relocs that have become local due to symbol
1424 visibility changes. */
1428 /* Relocs that use pc_count are those that appear on a call
1429 insn, or certain REL relocs that can generated via assembly.
1430 We want calls to protected symbols to resolve directly to the
1431 function rather than going via the plt. If people want
1432 function pointer comparisons to work as expected then they
1433 should avoid writing weird assembly. */
1434 if (SYMBOL_CALLS_LOCAL (info
, h
))
1436 struct elf64_x86_64_dyn_relocs
**pp
;
1438 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1440 p
->count
-= p
->pc_count
;
1449 /* Also discard relocs on undefined weak syms with non-default
1451 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1452 && h
->root
.type
== bfd_link_hash_undefweak
)
1453 eh
->dyn_relocs
= NULL
;
1455 else if (ELIMINATE_COPY_RELOCS
)
1457 /* For the non-shared case, discard space for relocs against
1458 symbols which turn out to need copy relocs or are not
1464 || (htab
->elf
.dynamic_sections_created
1465 && (h
->root
.type
== bfd_link_hash_undefweak
1466 || h
->root
.type
== bfd_link_hash_undefined
))))
1468 /* Make sure this symbol is output as a dynamic symbol.
1469 Undefined weak syms won't yet be marked as dynamic. */
1470 if (h
->dynindx
== -1
1471 && !h
->forced_local
)
1473 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1477 /* If that succeeded, we know we'll be keeping all the
1479 if (h
->dynindx
!= -1)
1483 eh
->dyn_relocs
= NULL
;
1488 /* Finally, allocate space. */
1489 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1491 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1492 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
1498 /* Find any dynamic relocs that apply to read-only sections. */
1501 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
1503 struct elf64_x86_64_link_hash_entry
*eh
;
1504 struct elf64_x86_64_dyn_relocs
*p
;
1506 if (h
->root
.type
== bfd_link_hash_warning
)
1507 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1509 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1510 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1512 asection
*s
= p
->sec
->output_section
;
1514 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1516 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1518 info
->flags
|= DF_TEXTREL
;
1520 /* Not an error, just cut short the traversal. */
1527 /* Set the sizes of the dynamic sections. */
1530 elf64_x86_64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1531 struct bfd_link_info
*info
)
1533 struct elf64_x86_64_link_hash_table
*htab
;
1539 htab
= elf64_x86_64_hash_table (info
);
1540 dynobj
= htab
->elf
.dynobj
;
1544 if (htab
->elf
.dynamic_sections_created
)
1546 /* Set the contents of the .interp section to the interpreter. */
1547 if (info
->executable
)
1549 s
= bfd_get_section_by_name (dynobj
, ".interp");
1552 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1553 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1557 /* Set up .got offsets for local syms, and space for local dynamic
1559 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1561 bfd_signed_vma
*local_got
;
1562 bfd_signed_vma
*end_local_got
;
1563 char *local_tls_type
;
1564 bfd_size_type locsymcount
;
1565 Elf_Internal_Shdr
*symtab_hdr
;
1568 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1571 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1573 struct elf64_x86_64_dyn_relocs
*p
;
1575 for (p
= *((struct elf64_x86_64_dyn_relocs
**)
1576 &elf_section_data (s
)->local_dynrel
);
1580 if (!bfd_is_abs_section (p
->sec
)
1581 && bfd_is_abs_section (p
->sec
->output_section
))
1583 /* Input section has been discarded, either because
1584 it is a copy of a linkonce section or due to
1585 linker script /DISCARD/, so we'll be discarding
1588 else if (p
->count
!= 0)
1590 srel
= elf_section_data (p
->sec
)->sreloc
;
1591 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
1592 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1593 info
->flags
|= DF_TEXTREL
;
1599 local_got
= elf_local_got_refcounts (ibfd
);
1603 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1604 locsymcount
= symtab_hdr
->sh_info
;
1605 end_local_got
= local_got
+ locsymcount
;
1606 local_tls_type
= elf64_x86_64_local_got_tls_type (ibfd
);
1608 srel
= htab
->srelgot
;
1609 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
1613 *local_got
= s
->size
;
1614 s
->size
+= GOT_ENTRY_SIZE
;
1615 if (*local_tls_type
== GOT_TLS_GD
)
1616 s
->size
+= GOT_ENTRY_SIZE
;
1618 || *local_tls_type
== GOT_TLS_GD
1619 || *local_tls_type
== GOT_TLS_IE
)
1620 srel
->size
+= sizeof (Elf64_External_Rela
);
1623 *local_got
= (bfd_vma
) -1;
1627 if (htab
->tls_ld_got
.refcount
> 0)
1629 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
1631 htab
->tls_ld_got
.offset
= htab
->sgot
->size
;
1632 htab
->sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
1633 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
1636 htab
->tls_ld_got
.offset
= -1;
1638 /* Allocate global sym .plt and .got entries, and space for global
1639 sym dynamic relocs. */
1640 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1642 /* We now have determined the sizes of the various dynamic sections.
1643 Allocate memory for them. */
1645 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1647 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1652 || s
== htab
->sgotplt
1653 || s
== htab
->sdynbss
)
1655 /* Strip this section if we don't need it; see the
1658 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
1660 if (s
->size
!= 0 && s
!= htab
->srelplt
)
1663 /* We use the reloc_count field as a counter if we need
1664 to copy relocs into the output file. */
1669 /* It's not one of our sections, so don't allocate space. */
1675 /* If we don't need this section, strip it from the
1676 output file. This is mostly to handle .rela.bss and
1677 .rela.plt. We must create both sections in
1678 create_dynamic_sections, because they must be created
1679 before the linker maps input sections to output
1680 sections. The linker does that before
1681 adjust_dynamic_symbol is called, and it is that
1682 function which decides whether anything needs to go
1683 into these sections. */
1685 s
->flags
|= SEC_EXCLUDE
;
1689 /* Allocate memory for the section contents. We use bfd_zalloc
1690 here in case unused entries are not reclaimed before the
1691 section's contents are written out. This should not happen,
1692 but this way if it does, we get a R_X86_64_NONE reloc instead
1694 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
1695 if (s
->contents
== NULL
)
1699 if (htab
->elf
.dynamic_sections_created
)
1701 /* Add some entries to the .dynamic section. We fill in the
1702 values later, in elf64_x86_64_finish_dynamic_sections, but we
1703 must add the entries now so that we get the correct size for
1704 the .dynamic section. The DT_DEBUG entry is filled in by the
1705 dynamic linker and used by the debugger. */
1706 #define add_dynamic_entry(TAG, VAL) \
1707 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1709 if (info
->executable
)
1711 if (!add_dynamic_entry (DT_DEBUG
, 0))
1715 if (htab
->splt
->size
!= 0)
1717 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1718 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1719 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1720 || !add_dynamic_entry (DT_JMPREL
, 0))
1726 if (!add_dynamic_entry (DT_RELA
, 0)
1727 || !add_dynamic_entry (DT_RELASZ
, 0)
1728 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1731 /* If any dynamic relocs apply to a read-only section,
1732 then we need a DT_TEXTREL entry. */
1733 if ((info
->flags
& DF_TEXTREL
) == 0)
1734 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
1737 if ((info
->flags
& DF_TEXTREL
) != 0)
1739 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1744 #undef add_dynamic_entry
1749 /* Return the base VMA address which should be subtracted from real addresses
1750 when resolving @dtpoff relocation.
1751 This is PT_TLS segment p_vaddr. */
1754 dtpoff_base (struct bfd_link_info
*info
)
1756 /* If tls_sec is NULL, we should have signalled an error already. */
1757 if (elf_hash_table (info
)->tls_sec
== NULL
)
1759 return elf_hash_table (info
)->tls_sec
->vma
;
1762 /* Return the relocation value for @tpoff relocation
1763 if STT_TLS virtual address is ADDRESS. */
1766 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
1768 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1770 /* If tls_segment is NULL, we should have signalled an error already. */
1771 if (htab
->tls_sec
== NULL
)
1773 return address
- htab
->tls_size
- htab
->tls_sec
->vma
;
1776 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
1780 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
1782 /* Opcode Instruction
1785 0x0f 0x8x conditional jump */
1787 && (contents
[offset
- 1] == 0xe8
1788 || contents
[offset
- 1] == 0xe9))
1790 && contents
[offset
- 2] == 0x0f
1791 && (contents
[offset
- 1] & 0xf0) == 0x80));
1794 /* Relocate an x86_64 ELF section. */
1797 elf64_x86_64_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
1798 bfd
*input_bfd
, asection
*input_section
,
1799 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
1800 Elf_Internal_Sym
*local_syms
,
1801 asection
**local_sections
)
1803 struct elf64_x86_64_link_hash_table
*htab
;
1804 Elf_Internal_Shdr
*symtab_hdr
;
1805 struct elf_link_hash_entry
**sym_hashes
;
1806 bfd_vma
*local_got_offsets
;
1807 Elf_Internal_Rela
*rel
;
1808 Elf_Internal_Rela
*relend
;
1810 if (info
->relocatable
)
1813 htab
= elf64_x86_64_hash_table (info
);
1814 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1815 sym_hashes
= elf_sym_hashes (input_bfd
);
1816 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1819 relend
= relocs
+ input_section
->reloc_count
;
1820 for (; rel
< relend
; rel
++)
1822 unsigned int r_type
;
1823 reloc_howto_type
*howto
;
1824 unsigned long r_symndx
;
1825 struct elf_link_hash_entry
*h
;
1826 Elf_Internal_Sym
*sym
;
1830 bfd_boolean unresolved_reloc
;
1831 bfd_reloc_status_type r
;
1834 r_type
= ELF64_R_TYPE (rel
->r_info
);
1835 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
1836 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
1839 if (r_type
>= R_X86_64_max
)
1841 bfd_set_error (bfd_error_bad_value
);
1845 howto
= x86_64_elf_howto_table
+ r_type
;
1846 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1850 unresolved_reloc
= FALSE
;
1851 if (r_symndx
< symtab_hdr
->sh_info
)
1853 sym
= local_syms
+ r_symndx
;
1854 sec
= local_sections
[r_symndx
];
1856 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1862 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1863 r_symndx
, symtab_hdr
, sym_hashes
,
1865 unresolved_reloc
, warned
);
1867 /* When generating a shared object, the relocations handled here are
1868 copied into the output file to be resolved at run time. */
1871 case R_X86_64_GOT32
:
1872 /* Relocation is to the entry for this symbol in the global
1874 case R_X86_64_GOTPCREL
:
1875 /* Use global offset table as symbol value. */
1876 if (htab
->sgot
== NULL
)
1883 off
= h
->got
.offset
;
1884 dyn
= htab
->elf
.dynamic_sections_created
;
1886 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1888 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1889 || (ELF_ST_VISIBILITY (h
->other
)
1890 && h
->root
.type
== bfd_link_hash_undefweak
))
1892 /* This is actually a static link, or it is a -Bsymbolic
1893 link and the symbol is defined locally, or the symbol
1894 was forced to be local because of a version file. We
1895 must initialize this entry in the global offset table.
1896 Since the offset must always be a multiple of 8, we
1897 use the least significant bit to record whether we
1898 have initialized it already.
1900 When doing a dynamic link, we create a .rela.got
1901 relocation entry to initialize the value. This is
1902 done in the finish_dynamic_symbol routine. */
1907 bfd_put_64 (output_bfd
, relocation
,
1908 htab
->sgot
->contents
+ off
);
1913 unresolved_reloc
= FALSE
;
1917 if (local_got_offsets
== NULL
)
1920 off
= local_got_offsets
[r_symndx
];
1922 /* The offset must always be a multiple of 8. We use
1923 the least significant bit to record whether we have
1924 already generated the necessary reloc. */
1929 bfd_put_64 (output_bfd
, relocation
,
1930 htab
->sgot
->contents
+ off
);
1935 Elf_Internal_Rela outrel
;
1938 /* We need to generate a R_X86_64_RELATIVE reloc
1939 for the dynamic linker. */
1944 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
1945 + htab
->sgot
->output_offset
1947 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
1948 outrel
.r_addend
= relocation
;
1950 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1951 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1954 local_got_offsets
[r_symndx
] |= 1;
1958 if (off
>= (bfd_vma
) -2)
1961 relocation
= htab
->sgot
->output_section
->vma
1962 + htab
->sgot
->output_offset
+ off
;
1963 if (r_type
!= R_X86_64_GOTPCREL
)
1964 relocation
-= htab
->sgotplt
->output_section
->vma
1965 - htab
->sgotplt
->output_offset
;
1969 case R_X86_64_GOTOFF64
:
1970 /* Relocation is relative to the start of the global offset
1973 /* Check to make sure it isn't a protected function symbol
1974 for shared library since it may not be local when used
1975 as function address. */
1979 && h
->type
== STT_FUNC
1980 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
1982 (*_bfd_error_handler
)
1983 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
1984 input_bfd
, h
->root
.root
.string
);
1985 bfd_set_error (bfd_error_bad_value
);
1989 /* Note that sgot is not involved in this
1990 calculation. We always want the start of .got.plt. If we
1991 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
1992 permitted by the ABI, we might have to change this
1994 relocation
-= htab
->sgotplt
->output_section
->vma
1995 + htab
->sgotplt
->output_offset
;
1998 case R_X86_64_GOTPC32
:
1999 /* Use global offset table as symbol value. */
2000 relocation
= htab
->sgotplt
->output_section
->vma
2001 + htab
->sgotplt
->output_offset
;
2002 unresolved_reloc
= FALSE
;
2005 case R_X86_64_PLT32
:
2006 /* Relocation is to the entry for this symbol in the
2007 procedure linkage table. */
2009 /* Resolve a PLT32 reloc against a local symbol directly,
2010 without using the procedure linkage table. */
2014 if (h
->plt
.offset
== (bfd_vma
) -1
2015 || htab
->splt
== NULL
)
2017 /* We didn't make a PLT entry for this symbol. This
2018 happens when statically linking PIC code, or when
2019 using -Bsymbolic. */
2023 relocation
= (htab
->splt
->output_section
->vma
2024 + htab
->splt
->output_offset
2026 unresolved_reloc
= FALSE
;
2033 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
2034 && (input_section
->flags
& SEC_ALLOC
) != 0
2035 && (input_section
->flags
& SEC_READONLY
) != 0
2037 || r_type
!= R_X86_64_PC32
2038 || h
->type
!= STT_FUNC
2039 || ELF_ST_VISIBILITY (h
->other
) != STV_PROTECTED
2040 || !is_32bit_relative_branch (contents
,
2044 && r_type
== R_X86_64_PC32
2045 && h
->type
== STT_FUNC
2046 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2047 (*_bfd_error_handler
)
2048 (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object"),
2049 input_bfd
, h
->root
.root
.string
);
2051 (*_bfd_error_handler
)
2052 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
2053 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
2054 h
->root
.root
.string
);
2055 bfd_set_error (bfd_error_bad_value
);
2065 /* FIXME: The ABI says the linker should make sure the value is
2066 the same when it's zeroextended to 64 bit. */
2068 /* r_symndx will be zero only for relocs against symbols
2069 from removed linkonce sections, or sections discarded by
2072 || (input_section
->flags
& SEC_ALLOC
) == 0)
2077 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2078 || h
->root
.type
!= bfd_link_hash_undefweak
)
2079 && ((r_type
!= R_X86_64_PC8
2080 && r_type
!= R_X86_64_PC16
2081 && r_type
!= R_X86_64_PC32
2082 && r_type
!= R_X86_64_PC64
)
2083 || !SYMBOL_CALLS_LOCAL (info
, h
)))
2084 || (ELIMINATE_COPY_RELOCS
2091 || h
->root
.type
== bfd_link_hash_undefweak
2092 || h
->root
.type
== bfd_link_hash_undefined
)))
2094 Elf_Internal_Rela outrel
;
2096 bfd_boolean skip
, relocate
;
2099 /* When generating a shared object, these relocations
2100 are copied into the output file to be resolved at run
2106 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2108 if (outrel
.r_offset
== (bfd_vma
) -1)
2110 else if (outrel
.r_offset
== (bfd_vma
) -2)
2111 skip
= TRUE
, relocate
= TRUE
;
2113 outrel
.r_offset
+= (input_section
->output_section
->vma
2114 + input_section
->output_offset
);
2117 memset (&outrel
, 0, sizeof outrel
);
2119 /* h->dynindx may be -1 if this symbol was marked to
2123 && (r_type
== R_X86_64_PC8
2124 || r_type
== R_X86_64_PC16
2125 || r_type
== R_X86_64_PC32
2126 || r_type
== R_X86_64_PC64
2129 || !h
->def_regular
))
2131 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2132 outrel
.r_addend
= rel
->r_addend
;
2136 /* This symbol is local, or marked to become local. */
2137 if (r_type
== R_X86_64_64
)
2140 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2141 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2147 if (bfd_is_abs_section (sec
))
2149 else if (sec
== NULL
|| sec
->owner
== NULL
)
2151 bfd_set_error (bfd_error_bad_value
);
2158 osec
= sec
->output_section
;
2159 sindx
= elf_section_data (osec
)->dynindx
;
2160 BFD_ASSERT (sindx
> 0);
2163 outrel
.r_info
= ELF64_R_INFO (sindx
, r_type
);
2164 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2168 sreloc
= elf_section_data (input_section
)->sreloc
;
2172 loc
= sreloc
->contents
;
2173 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2174 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2176 /* If this reloc is against an external symbol, we do
2177 not want to fiddle with the addend. Otherwise, we
2178 need to include the symbol value so that it becomes
2179 an addend for the dynamic reloc. */
2186 case R_X86_64_TLSGD
:
2187 case R_X86_64_GOTTPOFF
:
2188 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
== NULL
);
2189 tls_type
= GOT_UNKNOWN
;
2190 if (h
== NULL
&& local_got_offsets
)
2191 tls_type
= elf64_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
2194 tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
2195 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
== GOT_TLS_IE
)
2196 r_type
= R_X86_64_TPOFF32
;
2198 if (r_type
== R_X86_64_TLSGD
)
2200 if (tls_type
== GOT_TLS_IE
)
2201 r_type
= R_X86_64_GOTTPOFF
;
2204 if (r_type
== R_X86_64_TPOFF32
)
2206 BFD_ASSERT (! unresolved_reloc
);
2207 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
2210 static unsigned char tlsgd
[8]
2211 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
2213 /* GD->LE transition.
2214 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2215 .word 0x6666; rex64; call __tls_get_addr@plt
2218 leaq foo@tpoff(%rax), %rax */
2219 BFD_ASSERT (rel
->r_offset
>= 4);
2220 for (i
= 0; i
< 4; i
++)
2221 BFD_ASSERT (bfd_get_8 (input_bfd
,
2222 contents
+ rel
->r_offset
- 4 + i
)
2224 BFD_ASSERT (rel
->r_offset
+ 12 <= input_section
->size
);
2225 for (i
= 0; i
< 4; i
++)
2226 BFD_ASSERT (bfd_get_8 (input_bfd
,
2227 contents
+ rel
->r_offset
+ 4 + i
)
2229 BFD_ASSERT (rel
+ 1 < relend
);
2230 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2231 memcpy (contents
+ rel
->r_offset
- 4,
2232 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
2234 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2235 contents
+ rel
->r_offset
+ 8);
2236 /* Skip R_X86_64_PLT32. */
2242 unsigned int val
, type
, reg
;
2244 /* IE->LE transition:
2245 Originally it can be one of:
2246 movq foo@gottpoff(%rip), %reg
2247 addq foo@gottpoff(%rip), %reg
2250 leaq foo(%reg), %reg
2252 BFD_ASSERT (rel
->r_offset
>= 3);
2253 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 3);
2254 BFD_ASSERT (val
== 0x48 || val
== 0x4c);
2255 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2256 BFD_ASSERT (type
== 0x8b || type
== 0x03);
2257 reg
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2258 BFD_ASSERT ((reg
& 0xc7) == 5);
2260 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->size
);
2265 bfd_put_8 (output_bfd
, 0x49,
2266 contents
+ rel
->r_offset
- 3);
2267 bfd_put_8 (output_bfd
, 0xc7,
2268 contents
+ rel
->r_offset
- 2);
2269 bfd_put_8 (output_bfd
, 0xc0 | reg
,
2270 contents
+ rel
->r_offset
- 1);
2274 /* addq -> addq - addressing with %rsp/%r12 is
2277 bfd_put_8 (output_bfd
, 0x49,
2278 contents
+ rel
->r_offset
- 3);
2279 bfd_put_8 (output_bfd
, 0x81,
2280 contents
+ rel
->r_offset
- 2);
2281 bfd_put_8 (output_bfd
, 0xc0 | reg
,
2282 contents
+ rel
->r_offset
- 1);
2288 bfd_put_8 (output_bfd
, 0x4d,
2289 contents
+ rel
->r_offset
- 3);
2290 bfd_put_8 (output_bfd
, 0x8d,
2291 contents
+ rel
->r_offset
- 2);
2292 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
2293 contents
+ rel
->r_offset
- 1);
2295 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2296 contents
+ rel
->r_offset
);
2301 if (htab
->sgot
== NULL
)
2305 off
= h
->got
.offset
;
2308 if (local_got_offsets
== NULL
)
2311 off
= local_got_offsets
[r_symndx
];
2318 Elf_Internal_Rela outrel
;
2322 if (htab
->srelgot
== NULL
)
2325 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2326 + htab
->sgot
->output_offset
+ off
);
2328 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2329 if (r_type
== R_X86_64_TLSGD
)
2330 dr_type
= R_X86_64_DTPMOD64
;
2332 dr_type
= R_X86_64_TPOFF64
;
2334 bfd_put_64 (output_bfd
, 0, htab
->sgot
->contents
+ off
);
2335 outrel
.r_addend
= 0;
2336 if (dr_type
== R_X86_64_TPOFF64
&& indx
== 0)
2337 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2338 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
2340 loc
= htab
->srelgot
->contents
;
2341 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2342 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2344 if (r_type
== R_X86_64_TLSGD
)
2348 BFD_ASSERT (! unresolved_reloc
);
2349 bfd_put_64 (output_bfd
,
2350 relocation
- dtpoff_base (info
),
2351 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2355 bfd_put_64 (output_bfd
, 0,
2356 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2357 outrel
.r_info
= ELF64_R_INFO (indx
,
2359 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
2360 htab
->srelgot
->reloc_count
++;
2361 loc
+= sizeof (Elf64_External_Rela
);
2362 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2369 local_got_offsets
[r_symndx
] |= 1;
2372 if (off
>= (bfd_vma
) -2)
2374 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
2376 relocation
= htab
->sgot
->output_section
->vma
2377 + htab
->sgot
->output_offset
+ off
;
2378 unresolved_reloc
= FALSE
;
2383 static unsigned char tlsgd
[8]
2384 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
2386 /* GD->IE transition.
2387 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2388 .word 0x6666; rex64; call __tls_get_addr@plt
2391 addq foo@gottpoff(%rip), %rax */
2392 BFD_ASSERT (rel
->r_offset
>= 4);
2393 for (i
= 0; i
< 4; i
++)
2394 BFD_ASSERT (bfd_get_8 (input_bfd
,
2395 contents
+ rel
->r_offset
- 4 + i
)
2397 BFD_ASSERT (rel
->r_offset
+ 12 <= input_section
->size
);
2398 for (i
= 0; i
< 4; i
++)
2399 BFD_ASSERT (bfd_get_8 (input_bfd
,
2400 contents
+ rel
->r_offset
+ 4 + i
)
2402 BFD_ASSERT (rel
+ 1 < relend
);
2403 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2404 memcpy (contents
+ rel
->r_offset
- 4,
2405 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
2408 relocation
= (htab
->sgot
->output_section
->vma
2409 + htab
->sgot
->output_offset
+ off
2411 - input_section
->output_section
->vma
2412 - input_section
->output_offset
2414 bfd_put_32 (output_bfd
, relocation
,
2415 contents
+ rel
->r_offset
+ 8);
2416 /* Skip R_X86_64_PLT32. */
2422 case R_X86_64_TLSLD
:
2425 /* LD->LE transition:
2427 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr@plt.
2429 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
2430 BFD_ASSERT (rel
->r_offset
>= 3);
2431 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 3)
2433 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2)
2435 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1)
2437 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->size
);
2438 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
2440 BFD_ASSERT (rel
+ 1 < relend
);
2441 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2442 memcpy (contents
+ rel
->r_offset
- 3,
2443 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
2444 /* Skip R_X86_64_PLT32. */
2449 if (htab
->sgot
== NULL
)
2452 off
= htab
->tls_ld_got
.offset
;
2457 Elf_Internal_Rela outrel
;
2460 if (htab
->srelgot
== NULL
)
2463 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2464 + htab
->sgot
->output_offset
+ off
);
2466 bfd_put_64 (output_bfd
, 0,
2467 htab
->sgot
->contents
+ off
);
2468 bfd_put_64 (output_bfd
, 0,
2469 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2470 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_DTPMOD64
);
2471 outrel
.r_addend
= 0;
2472 loc
= htab
->srelgot
->contents
;
2473 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2474 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2475 htab
->tls_ld_got
.offset
|= 1;
2477 relocation
= htab
->sgot
->output_section
->vma
2478 + htab
->sgot
->output_offset
+ off
;
2479 unresolved_reloc
= FALSE
;
2482 case R_X86_64_DTPOFF32
:
2483 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
2484 relocation
-= dtpoff_base (info
);
2486 relocation
= tpoff (info
, relocation
);
2489 case R_X86_64_TPOFF32
:
2490 BFD_ASSERT (! info
->shared
);
2491 relocation
= tpoff (info
, relocation
);
2498 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2499 because such sections are not SEC_ALLOC and thus ld.so will
2500 not process them. */
2501 if (unresolved_reloc
2502 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2504 (*_bfd_error_handler
)
2505 (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
2508 (long) rel
->r_offset
,
2509 h
->root
.root
.string
);
2511 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2512 contents
, rel
->r_offset
,
2513 relocation
, rel
->r_addend
);
2515 if (r
!= bfd_reloc_ok
)
2520 name
= h
->root
.root
.string
;
2523 name
= bfd_elf_string_from_elf_section (input_bfd
,
2524 symtab_hdr
->sh_link
,
2529 name
= bfd_section_name (input_bfd
, sec
);
2532 if (r
== bfd_reloc_overflow
)
2535 && h
->root
.type
== bfd_link_hash_undefweak
2536 && howto
->pc_relative
)
2537 /* Ignore reloc overflow on branches to undefweak syms. */
2540 if (! ((*info
->callbacks
->reloc_overflow
)
2541 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2542 (bfd_vma
) 0, input_bfd
, input_section
,
2548 (*_bfd_error_handler
)
2549 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
2550 input_bfd
, input_section
,
2551 (long) rel
->r_offset
, name
, (int) r
);
2560 /* Finish up dynamic symbol handling. We set the contents of various
2561 dynamic sections here. */
2564 elf64_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
2565 struct bfd_link_info
*info
,
2566 struct elf_link_hash_entry
*h
,
2567 Elf_Internal_Sym
*sym
)
2569 struct elf64_x86_64_link_hash_table
*htab
;
2571 htab
= elf64_x86_64_hash_table (info
);
2573 if (h
->plt
.offset
!= (bfd_vma
) -1)
2577 Elf_Internal_Rela rela
;
2580 /* This symbol has an entry in the procedure linkage table. Set
2582 if (h
->dynindx
== -1
2583 || htab
->splt
== NULL
2584 || htab
->sgotplt
== NULL
2585 || htab
->srelplt
== NULL
)
2588 /* Get the index in the procedure linkage table which
2589 corresponds to this symbol. This is the index of this symbol
2590 in all the symbols for which we are making plt entries. The
2591 first entry in the procedure linkage table is reserved. */
2592 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2594 /* Get the offset into the .got table of the entry that
2595 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
2596 bytes. The first three are reserved for the dynamic linker. */
2597 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2599 /* Fill in the entry in the procedure linkage table. */
2600 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
2603 /* Insert the relocation positions of the plt section. The magic
2604 numbers at the end of the statements are the positions of the
2605 relocations in the plt section. */
2606 /* Put offset for jmp *name@GOTPCREL(%rip), since the
2607 instruction uses 6 bytes, subtract this value. */
2608 bfd_put_32 (output_bfd
,
2609 (htab
->sgotplt
->output_section
->vma
2610 + htab
->sgotplt
->output_offset
2612 - htab
->splt
->output_section
->vma
2613 - htab
->splt
->output_offset
2616 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
2617 /* Put relocation index. */
2618 bfd_put_32 (output_bfd
, plt_index
,
2619 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
2620 /* Put offset for jmp .PLT0. */
2621 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
2622 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
2624 /* Fill in the entry in the global offset table, initially this
2625 points to the pushq instruction in the PLT which is at offset 6. */
2626 bfd_put_64 (output_bfd
, (htab
->splt
->output_section
->vma
2627 + htab
->splt
->output_offset
2628 + h
->plt
.offset
+ 6),
2629 htab
->sgotplt
->contents
+ got_offset
);
2631 /* Fill in the entry in the .rela.plt section. */
2632 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
2633 + htab
->sgotplt
->output_offset
2635 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
2637 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
2638 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2640 if (!h
->def_regular
)
2642 /* Mark the symbol as undefined, rather than as defined in
2643 the .plt section. Leave the value if there were any
2644 relocations where pointer equality matters (this is a clue
2645 for the dynamic linker, to make function pointer
2646 comparisons work between an application and shared
2647 library), otherwise set it to zero. If a function is only
2648 called from a binary, there is no need to slow down
2649 shared libraries because of that. */
2650 sym
->st_shndx
= SHN_UNDEF
;
2651 if (!h
->pointer_equality_needed
)
2656 if (h
->got
.offset
!= (bfd_vma
) -1
2657 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_GD
2658 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
2660 Elf_Internal_Rela rela
;
2663 /* This symbol has an entry in the global offset table. Set it
2665 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
2668 rela
.r_offset
= (htab
->sgot
->output_section
->vma
2669 + htab
->sgot
->output_offset
2670 + (h
->got
.offset
&~ (bfd_vma
) 1));
2672 /* If this is a static link, or it is a -Bsymbolic link and the
2673 symbol is defined locally or was forced to be local because
2674 of a version file, we just want to emit a RELATIVE reloc.
2675 The entry in the global offset table will already have been
2676 initialized in the relocate_section function. */
2678 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2680 BFD_ASSERT((h
->got
.offset
& 1) != 0);
2681 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2682 rela
.r_addend
= (h
->root
.u
.def
.value
2683 + h
->root
.u
.def
.section
->output_section
->vma
2684 + h
->root
.u
.def
.section
->output_offset
);
2688 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2689 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2690 htab
->sgot
->contents
+ h
->got
.offset
);
2691 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
2695 loc
= htab
->srelgot
->contents
;
2696 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2697 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2702 Elf_Internal_Rela rela
;
2705 /* This symbol needs a copy reloc. Set it up. */
2707 if (h
->dynindx
== -1
2708 || (h
->root
.type
!= bfd_link_hash_defined
2709 && h
->root
.type
!= bfd_link_hash_defweak
)
2710 || htab
->srelbss
== NULL
)
2713 rela
.r_offset
= (h
->root
.u
.def
.value
2714 + h
->root
.u
.def
.section
->output_section
->vma
2715 + h
->root
.u
.def
.section
->output_offset
);
2716 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
2718 loc
= htab
->srelbss
->contents
;
2719 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2720 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2723 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2724 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2725 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2726 sym
->st_shndx
= SHN_ABS
;
2731 /* Used to decide how to sort relocs in an optimal manner for the
2732 dynamic linker, before writing them out. */
2734 static enum elf_reloc_type_class
2735 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
2737 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2739 case R_X86_64_RELATIVE
:
2740 return reloc_class_relative
;
2741 case R_X86_64_JUMP_SLOT
:
2742 return reloc_class_plt
;
2744 return reloc_class_copy
;
2746 return reloc_class_normal
;
2750 /* Finish up the dynamic sections. */
2753 elf64_x86_64_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2755 struct elf64_x86_64_link_hash_table
*htab
;
2759 htab
= elf64_x86_64_hash_table (info
);
2760 dynobj
= htab
->elf
.dynobj
;
2761 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2763 if (htab
->elf
.dynamic_sections_created
)
2765 Elf64_External_Dyn
*dyncon
, *dynconend
;
2767 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
2770 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2771 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2772 for (; dyncon
< dynconend
; dyncon
++)
2774 Elf_Internal_Dyn dyn
;
2777 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2786 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2790 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
2794 s
= htab
->srelplt
->output_section
;
2795 dyn
.d_un
.d_val
= s
->size
;
2799 /* The procedure linkage table relocs (DT_JMPREL) should
2800 not be included in the overall relocs (DT_RELA).
2801 Therefore, we override the DT_RELASZ entry here to
2802 make it not include the JMPREL relocs. Since the
2803 linker script arranges for .rela.plt to follow all
2804 other relocation sections, we don't have to worry
2805 about changing the DT_RELA entry. */
2806 if (htab
->srelplt
!= NULL
)
2808 s
= htab
->srelplt
->output_section
;
2809 dyn
.d_un
.d_val
-= s
->size
;
2814 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2817 /* Fill in the special first entry in the procedure linkage table. */
2818 if (htab
->splt
&& htab
->splt
->size
> 0)
2820 /* Fill in the first entry in the procedure linkage table. */
2821 memcpy (htab
->splt
->contents
, elf64_x86_64_plt0_entry
,
2823 /* Add offset for pushq GOT+8(%rip), since the instruction
2824 uses 6 bytes subtract this value. */
2825 bfd_put_32 (output_bfd
,
2826 (htab
->sgotplt
->output_section
->vma
2827 + htab
->sgotplt
->output_offset
2829 - htab
->splt
->output_section
->vma
2830 - htab
->splt
->output_offset
2832 htab
->splt
->contents
+ 2);
2833 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
2834 the end of the instruction. */
2835 bfd_put_32 (output_bfd
,
2836 (htab
->sgotplt
->output_section
->vma
2837 + htab
->sgotplt
->output_offset
2839 - htab
->splt
->output_section
->vma
2840 - htab
->splt
->output_offset
2842 htab
->splt
->contents
+ 8);
2844 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
=
2851 /* Fill in the first three entries in the global offset table. */
2852 if (htab
->sgotplt
->size
> 0)
2854 /* Set the first entry in the global offset table to the address of
2855 the dynamic section. */
2857 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
);
2859 bfd_put_64 (output_bfd
,
2860 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2861 htab
->sgotplt
->contents
);
2862 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
2863 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
);
2864 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
2867 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
=
2871 if (htab
->sgot
&& htab
->sgot
->size
> 0)
2872 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
2878 /* Return address for Ith PLT stub in section PLT, for relocation REL
2879 or (bfd_vma) -1 if it should not be included. */
2882 elf64_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
2883 const arelent
*rel ATTRIBUTE_UNUSED
)
2885 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
2888 /* Handle an x86-64 specific section when reading an object file. This
2889 is called when elfcode.h finds a section with an unknown type. */
2892 elf64_x86_64_section_from_shdr (bfd
*abfd
,
2893 Elf_Internal_Shdr
*hdr
,
2897 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
2900 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
2906 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
2907 #define TARGET_LITTLE_NAME "elf64-x86-64"
2908 #define ELF_ARCH bfd_arch_i386
2909 #define ELF_MACHINE_CODE EM_X86_64
2910 #define ELF_MAXPAGESIZE 0x100000
2912 #define elf_backend_can_gc_sections 1
2913 #define elf_backend_can_refcount 1
2914 #define elf_backend_want_got_plt 1
2915 #define elf_backend_plt_readonly 1
2916 #define elf_backend_want_plt_sym 0
2917 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
2918 #define elf_backend_rela_normal 1
2920 #define elf_info_to_howto elf64_x86_64_info_to_howto
2922 #define bfd_elf64_bfd_link_hash_table_create \
2923 elf64_x86_64_link_hash_table_create
2924 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
2926 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
2927 #define elf_backend_check_relocs elf64_x86_64_check_relocs
2928 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
2929 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
2930 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
2931 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
2932 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
2933 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
2934 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
2935 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
2936 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
2937 #define elf_backend_relocate_section elf64_x86_64_relocate_section
2938 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
2939 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
2940 #define elf_backend_object_p elf64_x86_64_elf_object_p
2941 #define bfd_elf64_mkobject elf64_x86_64_mkobject
2943 #define elf_backend_section_from_shdr \
2944 elf64_x86_64_section_from_shdr
2946 #include "elf64-target.h"