1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka <jh@suse.cz>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
32 #include "elf/x86-64.h"
34 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
35 #define MINUS_ONE (~ (bfd_vma) 0)
37 /* The relocation "howto" table. Order of fields:
38 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
39 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
40 static reloc_howto_type x86_64_elf_howto_table
[] =
42 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
43 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
45 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
48 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
49 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
51 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
52 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
54 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
55 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
63 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
66 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
69 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
70 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
72 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
73 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
75 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
76 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
78 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
79 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
80 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
81 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
82 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
84 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
85 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
86 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
89 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
92 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
95 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
96 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
98 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
99 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
101 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
102 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
104 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
105 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
107 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
108 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
110 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
111 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
113 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
115 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
116 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
117 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
118 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
119 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
120 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
122 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
123 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
125 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
126 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
127 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
128 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
129 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
131 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
132 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
136 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
137 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
138 "R_X86_64_GOTPC32_TLSDESC",
139 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
140 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
141 complain_overflow_dont
, bfd_elf_generic_reloc
,
142 "R_X86_64_TLSDESC_CALL",
144 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
145 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
147 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
148 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
149 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
152 /* We have a gap in the reloc numbers here.
153 R_X86_64_standard counts the number up to this point, and
154 R_X86_64_vt_offset is the value to subtract from a reloc type of
155 R_X86_64_GNU_VT* to form an index into this table. */
156 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
157 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
159 /* GNU extension to record C++ vtable hierarchy. */
160 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
161 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
163 /* GNU extension to record C++ vtable member usage. */
164 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
165 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
169 #define IS_X86_64_PCREL_TYPE(TYPE) \
170 ( ((TYPE) == R_X86_64_PC8) \
171 || ((TYPE) == R_X86_64_PC16) \
172 || ((TYPE) == R_X86_64_PC32) \
173 || ((TYPE) == R_X86_64_PC64))
175 /* Map BFD relocs to the x86_64 elf relocs. */
178 bfd_reloc_code_real_type bfd_reloc_val
;
179 unsigned char elf_reloc_val
;
182 static const struct elf_reloc_map x86_64_reloc_map
[] =
184 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
185 { BFD_RELOC_64
, R_X86_64_64
, },
186 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
187 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
188 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
189 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
190 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
191 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
192 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
193 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
194 { BFD_RELOC_32
, R_X86_64_32
, },
195 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
196 { BFD_RELOC_16
, R_X86_64_16
, },
197 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
198 { BFD_RELOC_8
, R_X86_64_8
, },
199 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
200 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
201 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
202 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
203 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
204 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
205 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
206 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
207 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
208 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
209 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
210 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
211 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
212 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
213 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
214 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
215 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
216 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
217 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
218 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
219 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
220 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
221 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
224 static reloc_howto_type
*
225 elf64_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
229 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
230 || r_type
>= (unsigned int) R_X86_64_max
)
232 if (r_type
>= (unsigned int) R_X86_64_standard
)
234 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
236 r_type
= R_X86_64_NONE
;
241 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
242 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
243 return &x86_64_elf_howto_table
[i
];
246 /* Given a BFD reloc type, return a HOWTO structure. */
247 static reloc_howto_type
*
248 elf64_x86_64_reloc_type_lookup (bfd
*abfd
,
249 bfd_reloc_code_real_type code
)
253 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
256 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
257 return elf64_x86_64_rtype_to_howto (abfd
,
258 x86_64_reloc_map
[i
].elf_reloc_val
);
263 static reloc_howto_type
*
264 elf64_x86_64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
270 i
< (sizeof (x86_64_elf_howto_table
)
271 / sizeof (x86_64_elf_howto_table
[0]));
273 if (x86_64_elf_howto_table
[i
].name
!= NULL
274 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
275 return &x86_64_elf_howto_table
[i
];
280 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
283 elf64_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
284 Elf_Internal_Rela
*dst
)
288 r_type
= ELF64_R_TYPE (dst
->r_info
);
289 cache_ptr
->howto
= elf64_x86_64_rtype_to_howto (abfd
, r_type
);
290 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
293 /* Support for core dump NOTE sections. */
295 elf64_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
300 switch (note
->descsz
)
305 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
307 elf_tdata (abfd
)->core_signal
308 = bfd_get_16 (abfd
, note
->descdata
+ 12);
311 elf_tdata (abfd
)->core_pid
312 = bfd_get_32 (abfd
, note
->descdata
+ 32);
321 /* Make a ".reg/999" section. */
322 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
323 size
, note
->descpos
+ offset
);
327 elf64_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
329 switch (note
->descsz
)
334 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
335 elf_tdata (abfd
)->core_program
336 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
337 elf_tdata (abfd
)->core_command
338 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
341 /* Note that for some reason, a spurious space is tacked
342 onto the end of the args in some (at least one anyway)
343 implementations, so strip it off if it exists. */
346 char *command
= elf_tdata (abfd
)->core_command
;
347 int n
= strlen (command
);
349 if (0 < n
&& command
[n
- 1] == ' ')
350 command
[n
- 1] = '\0';
356 /* Functions for the x86-64 ELF linker. */
358 /* The name of the dynamic interpreter. This is put in the .interp
361 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
363 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
364 copying dynamic variables from a shared lib into an app's dynbss
365 section, and instead use a dynamic relocation to point into the
367 #define ELIMINATE_COPY_RELOCS 1
369 /* The size in bytes of an entry in the global offset table. */
371 #define GOT_ENTRY_SIZE 8
373 /* The size in bytes of an entry in the procedure linkage table. */
375 #define PLT_ENTRY_SIZE 16
377 /* The first entry in a procedure linkage table looks like this. See the
378 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
380 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
382 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
383 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
384 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
387 /* Subsequent entries in a procedure linkage table look like this. */
389 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
391 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
392 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
393 0x68, /* pushq immediate */
394 0, 0, 0, 0, /* replaced with index into relocation table. */
395 0xe9, /* jmp relative */
396 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
399 /* The x86-64 linker needs to keep track of the number of relocs that
400 it decides to copy as dynamic relocs in check_relocs for each symbol.
401 This is so that it can later discard them if they are found to be
402 unnecessary. We store the information in a field extending the
403 regular ELF linker hash table. */
405 struct elf64_x86_64_dyn_relocs
408 struct elf64_x86_64_dyn_relocs
*next
;
410 /* The input section of the reloc. */
413 /* Total number of relocs copied for the input section. */
416 /* Number of pc-relative relocs copied for the input section. */
417 bfd_size_type pc_count
;
420 /* x86-64 ELF linker hash entry. */
422 struct elf64_x86_64_link_hash_entry
424 struct elf_link_hash_entry elf
;
426 /* Track dynamic relocs copied for this symbol. */
427 struct elf64_x86_64_dyn_relocs
*dyn_relocs
;
429 #define GOT_UNKNOWN 0
433 #define GOT_TLS_GDESC 4
434 #define GOT_TLS_GD_BOTH_P(type) \
435 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
436 #define GOT_TLS_GD_P(type) \
437 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
438 #define GOT_TLS_GDESC_P(type) \
439 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
440 #define GOT_TLS_GD_ANY_P(type) \
441 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
442 unsigned char tls_type
;
444 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
445 starting at the end of the jump table. */
449 #define elf64_x86_64_hash_entry(ent) \
450 ((struct elf64_x86_64_link_hash_entry *)(ent))
452 struct elf64_x86_64_obj_tdata
454 struct elf_obj_tdata root
;
456 /* tls_type for each local got entry. */
457 char *local_got_tls_type
;
459 /* GOTPLT entries for TLS descriptors. */
460 bfd_vma
*local_tlsdesc_gotent
;
463 #define elf64_x86_64_tdata(abfd) \
464 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
466 #define elf64_x86_64_local_got_tls_type(abfd) \
467 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
469 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
470 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
472 #define is_x86_64_elf(bfd) \
473 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
474 && elf_tdata (bfd) != NULL \
475 && elf_object_id (bfd) == X86_64_ELF_TDATA)
478 elf64_x86_64_mkobject (bfd
*abfd
)
480 return bfd_elf_allocate_object (abfd
, sizeof (struct elf64_x86_64_obj_tdata
),
484 /* x86-64 ELF linker hash table. */
486 struct elf64_x86_64_link_hash_table
488 struct elf_link_hash_table elf
;
490 /* Short-cuts to get to dynamic linker sections. */
494 /* The offset into splt of the PLT entry for the TLS descriptor
495 resolver. Special values are 0, if not necessary (or not found
496 to be necessary yet), and -1 if needed but not determined
499 /* The offset into sgot of the GOT entry used by the PLT entry
504 bfd_signed_vma refcount
;
508 /* The amount of space used by the jump slots in the GOT. */
509 bfd_vma sgotplt_jump_table_size
;
511 /* Small local sym to section mapping cache. */
512 struct sym_sec_cache sym_sec
;
514 /* _TLS_MODULE_BASE_ symbol. */
515 struct bfd_link_hash_entry
*tls_module_base
;
517 /* Used by local STT_GNU_IFUNC symbols. */
518 htab_t loc_hash_table
;
519 void *loc_hash_memory
;
522 /* Get the x86-64 ELF linker hash table from a link_info structure. */
524 #define elf64_x86_64_hash_table(p) \
525 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
527 #define elf64_x86_64_compute_jump_table_size(htab) \
528 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
530 /* Create an entry in an x86-64 ELF linker hash table. */
532 static struct bfd_hash_entry
*
533 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
534 struct bfd_hash_table
*table
,
537 /* Allocate the structure if it has not already been allocated by a
541 entry
= bfd_hash_allocate (table
,
542 sizeof (struct elf64_x86_64_link_hash_entry
));
547 /* Call the allocation method of the superclass. */
548 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
551 struct elf64_x86_64_link_hash_entry
*eh
;
553 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
554 eh
->dyn_relocs
= NULL
;
555 eh
->tls_type
= GOT_UNKNOWN
;
556 eh
->tlsdesc_got
= (bfd_vma
) -1;
563 elf64_x86_64_local_hash (int id
, int r_sym
)
565 return ((((id
& 0xff) << 24) | ((id
& 0xff00) << 8))
566 ^ r_sym
^ (id
>> 16));
569 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
570 for local symbol so that we can handle local STT_GNU_IFUNC symbols
571 as global symbol. We reuse indx and dynstr_index for local symbol
572 hash since they aren't used by global symbols in this backend. */
575 elf64_x86_64_local_htab_hash (const void *ptr
)
577 struct elf_link_hash_entry
*h
578 = (struct elf_link_hash_entry
*) ptr
;
579 return elf64_x86_64_local_hash (h
->indx
, h
->dynstr_index
);
582 /* Compare local hash entries. */
585 elf64_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
587 struct elf_link_hash_entry
*h1
588 = (struct elf_link_hash_entry
*) ptr1
;
589 struct elf_link_hash_entry
*h2
590 = (struct elf_link_hash_entry
*) ptr2
;
592 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
595 /* Find and/or create a hash entry for local symbol. */
597 static struct elf_link_hash_entry
*
598 elf64_x86_64_get_local_sym_hash (struct elf64_x86_64_link_hash_table
*htab
,
599 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
602 struct elf64_x86_64_link_hash_entry e
, *ret
;
603 asection
*sec
= abfd
->sections
;
604 hashval_t h
= elf64_x86_64_local_hash (sec
->id
,
605 ELF64_R_SYM (rel
->r_info
));
608 e
.elf
.indx
= sec
->id
;
609 e
.elf
.dynstr_index
= ELF64_R_SYM (rel
->r_info
);
610 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
611 create
? INSERT
: NO_INSERT
);
618 ret
= (struct elf64_x86_64_link_hash_entry
*) *slot
;
622 ret
= (struct elf64_x86_64_link_hash_entry
*)
623 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
624 sizeof (struct elf64_x86_64_link_hash_entry
));
627 memset (ret
, 0, sizeof (*ret
));
628 ret
->elf
.indx
= sec
->id
;
629 ret
->elf
.dynstr_index
= ELF64_R_SYM (rel
->r_info
);
630 ret
->elf
.dynindx
= -1;
631 ret
->elf
.plt
.offset
= (bfd_vma
) -1;
632 ret
->elf
.got
.offset
= (bfd_vma
) -1;
638 /* Create an X86-64 ELF linker hash table. */
640 static struct bfd_link_hash_table
*
641 elf64_x86_64_link_hash_table_create (bfd
*abfd
)
643 struct elf64_x86_64_link_hash_table
*ret
;
644 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
646 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_malloc (amt
);
650 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
651 elf64_x86_64_link_hash_newfunc
,
652 sizeof (struct elf64_x86_64_link_hash_entry
)))
660 ret
->sym_sec
.abfd
= NULL
;
661 ret
->tlsdesc_plt
= 0;
662 ret
->tlsdesc_got
= 0;
663 ret
->tls_ld_got
.refcount
= 0;
664 ret
->sgotplt_jump_table_size
= 0;
665 ret
->tls_module_base
= NULL
;
667 ret
->loc_hash_table
= htab_try_create (1024,
668 elf64_x86_64_local_htab_hash
,
669 elf64_x86_64_local_htab_eq
,
671 ret
->loc_hash_memory
= objalloc_create ();
672 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
678 return &ret
->elf
.root
;
681 /* Destroy an X86-64 ELF linker hash table. */
684 elf64_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
686 struct elf64_x86_64_link_hash_table
*htab
687 = (struct elf64_x86_64_link_hash_table
*) hash
;
689 if (htab
->loc_hash_table
)
690 htab_delete (htab
->loc_hash_table
);
691 if (htab
->loc_hash_memory
)
692 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
693 _bfd_generic_link_hash_table_free (hash
);
696 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
697 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
701 elf64_x86_64_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
703 struct elf64_x86_64_link_hash_table
*htab
;
705 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
708 htab
= elf64_x86_64_hash_table (info
);
709 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
711 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
714 || (!info
->shared
&& !htab
->srelbss
))
720 /* Copy the extra info we tack onto an elf_link_hash_entry. */
723 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
724 struct elf_link_hash_entry
*dir
,
725 struct elf_link_hash_entry
*ind
)
727 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
729 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
730 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
732 if (eind
->dyn_relocs
!= NULL
)
734 if (edir
->dyn_relocs
!= NULL
)
736 struct elf64_x86_64_dyn_relocs
**pp
;
737 struct elf64_x86_64_dyn_relocs
*p
;
739 /* Add reloc counts against the indirect sym to the direct sym
740 list. Merge any entries against the same section. */
741 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
743 struct elf64_x86_64_dyn_relocs
*q
;
745 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
746 if (q
->sec
== p
->sec
)
748 q
->pc_count
+= p
->pc_count
;
749 q
->count
+= p
->count
;
756 *pp
= edir
->dyn_relocs
;
759 edir
->dyn_relocs
= eind
->dyn_relocs
;
760 eind
->dyn_relocs
= NULL
;
763 if (ind
->root
.type
== bfd_link_hash_indirect
764 && dir
->got
.refcount
<= 0)
766 edir
->tls_type
= eind
->tls_type
;
767 eind
->tls_type
= GOT_UNKNOWN
;
770 if (ELIMINATE_COPY_RELOCS
771 && ind
->root
.type
!= bfd_link_hash_indirect
772 && dir
->dynamic_adjusted
)
774 /* If called to transfer flags for a weakdef during processing
775 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
776 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
777 dir
->ref_dynamic
|= ind
->ref_dynamic
;
778 dir
->ref_regular
|= ind
->ref_regular
;
779 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
780 dir
->needs_plt
|= ind
->needs_plt
;
781 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
784 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
788 elf64_x86_64_elf_object_p (bfd
*abfd
)
790 /* Set the right machine number for an x86-64 elf64 file. */
791 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
809 /* Return TRUE if the TLS access code sequence support transition
813 elf64_x86_64_check_tls_transition (bfd
*abfd
, asection
*sec
,
815 Elf_Internal_Shdr
*symtab_hdr
,
816 struct elf_link_hash_entry
**sym_hashes
,
818 const Elf_Internal_Rela
*rel
,
819 const Elf_Internal_Rela
*relend
)
822 unsigned long r_symndx
;
823 struct elf_link_hash_entry
*h
;
826 /* Get the section contents. */
827 if (contents
== NULL
)
829 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
830 contents
= elf_section_data (sec
)->this_hdr
.contents
;
833 /* FIXME: How to better handle error condition? */
834 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
837 /* Cache the section contents for elf_link_input_bfd. */
838 elf_section_data (sec
)->this_hdr
.contents
= contents
;
842 offset
= rel
->r_offset
;
847 if ((rel
+ 1) >= relend
)
850 if (r_type
== R_X86_64_TLSGD
)
852 /* Check transition from GD access model. Only
853 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
854 .word 0x6666; rex64; call __tls_get_addr
855 can transit to different access model. */
857 static x86_64_opcode32 leaq
= { { 0x66, 0x48, 0x8d, 0x3d } },
858 call
= { { 0x66, 0x66, 0x48, 0xe8 } };
860 || (offset
+ 12) > sec
->size
861 || bfd_get_32 (abfd
, contents
+ offset
- 4) != leaq
.i
862 || bfd_get_32 (abfd
, contents
+ offset
+ 4) != call
.i
)
867 /* Check transition from LD access model. Only
868 leaq foo@tlsld(%rip), %rdi;
870 can transit to different access model. */
872 static x86_64_opcode32 ld
= { { 0x48, 0x8d, 0x3d, 0xe8 } };
875 if (offset
< 3 || (offset
+ 9) > sec
->size
)
878 op
.i
= bfd_get_32 (abfd
, contents
+ offset
- 3);
879 op
.c
[3] = bfd_get_8 (abfd
, contents
+ offset
+ 4);
884 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
885 if (r_symndx
< symtab_hdr
->sh_info
)
888 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
889 /* Use strncmp to check __tls_get_addr since __tls_get_addr
892 && h
->root
.root
.string
!= NULL
893 && (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
894 || ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
895 && (strncmp (h
->root
.root
.string
,
896 "__tls_get_addr", 14) == 0));
898 case R_X86_64_GOTTPOFF
:
899 /* Check transition from IE access model:
900 movq foo@gottpoff(%rip), %reg
901 addq foo@gottpoff(%rip), %reg
904 if (offset
< 3 || (offset
+ 4) > sec
->size
)
907 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
908 if (val
!= 0x48 && val
!= 0x4c)
911 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
912 if (val
!= 0x8b && val
!= 0x03)
915 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
916 return (val
& 0xc7) == 5;
918 case R_X86_64_GOTPC32_TLSDESC
:
919 /* Check transition from GDesc access model:
920 leaq x@tlsdesc(%rip), %rax
922 Make sure it's a leaq adding rip to a 32-bit offset
923 into any register, although it's probably almost always
926 if (offset
< 3 || (offset
+ 4) > sec
->size
)
929 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
930 if ((val
& 0xfb) != 0x48)
933 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
936 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
937 return (val
& 0xc7) == 0x05;
939 case R_X86_64_TLSDESC_CALL
:
940 /* Check transition from GDesc access model:
941 call *x@tlsdesc(%rax)
943 if (offset
+ 2 <= sec
->size
)
945 /* Make sure that it's a call *x@tlsdesc(%rax). */
946 static x86_64_opcode16 call
= { { 0xff, 0x10 } };
947 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
957 /* Return TRUE if the TLS access transition is OK or no transition
958 will be performed. Update R_TYPE if there is a transition. */
961 elf64_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
962 asection
*sec
, bfd_byte
*contents
,
963 Elf_Internal_Shdr
*symtab_hdr
,
964 struct elf_link_hash_entry
**sym_hashes
,
965 unsigned int *r_type
, int tls_type
,
966 const Elf_Internal_Rela
*rel
,
967 const Elf_Internal_Rela
*relend
,
968 struct elf_link_hash_entry
*h
)
970 unsigned int from_type
= *r_type
;
971 unsigned int to_type
= from_type
;
972 bfd_boolean check
= TRUE
;
977 case R_X86_64_GOTPC32_TLSDESC
:
978 case R_X86_64_TLSDESC_CALL
:
979 case R_X86_64_GOTTPOFF
:
983 to_type
= R_X86_64_TPOFF32
;
985 to_type
= R_X86_64_GOTTPOFF
;
988 /* When we are called from elf64_x86_64_relocate_section,
989 CONTENTS isn't NULL and there may be additional transitions
990 based on TLS_TYPE. */
991 if (contents
!= NULL
)
993 unsigned int new_to_type
= to_type
;
998 && tls_type
== GOT_TLS_IE
)
999 new_to_type
= R_X86_64_TPOFF32
;
1001 if (to_type
== R_X86_64_TLSGD
1002 || to_type
== R_X86_64_GOTPC32_TLSDESC
1003 || to_type
== R_X86_64_TLSDESC_CALL
)
1005 if (tls_type
== GOT_TLS_IE
)
1006 new_to_type
= R_X86_64_GOTTPOFF
;
1009 /* We checked the transition before when we were called from
1010 elf64_x86_64_check_relocs. We only want to check the new
1011 transition which hasn't been checked before. */
1012 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1013 to_type
= new_to_type
;
1018 case R_X86_64_TLSLD
:
1020 to_type
= R_X86_64_TPOFF32
;
1027 /* Return TRUE if there is no transition. */
1028 if (from_type
== to_type
)
1031 /* Check if the transition can be performed. */
1033 && ! elf64_x86_64_check_tls_transition (abfd
, sec
, contents
,
1034 symtab_hdr
, sym_hashes
,
1035 from_type
, rel
, relend
))
1037 reloc_howto_type
*from
, *to
;
1039 from
= elf64_x86_64_rtype_to_howto (abfd
, from_type
);
1040 to
= elf64_x86_64_rtype_to_howto (abfd
, to_type
);
1042 (*_bfd_error_handler
)
1043 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1044 "in section `%A' failed"),
1045 abfd
, sec
, from
->name
, to
->name
,
1046 h
? h
->root
.root
.string
: "a local symbol",
1047 (unsigned long) rel
->r_offset
);
1048 bfd_set_error (bfd_error_bad_value
);
1056 /* Look through the relocs for a section during the first phase, and
1057 calculate needed space in the global offset table, procedure
1058 linkage table, and dynamic reloc sections. */
1061 elf64_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1063 const Elf_Internal_Rela
*relocs
)
1065 struct elf64_x86_64_link_hash_table
*htab
;
1066 Elf_Internal_Shdr
*symtab_hdr
;
1067 struct elf_link_hash_entry
**sym_hashes
;
1068 const Elf_Internal_Rela
*rel
;
1069 const Elf_Internal_Rela
*rel_end
;
1071 Elf_Internal_Sym
*isymbuf
;
1073 if (info
->relocatable
)
1076 BFD_ASSERT (is_x86_64_elf (abfd
));
1078 htab
= elf64_x86_64_hash_table (info
);
1079 symtab_hdr
= &elf_symtab_hdr (abfd
);
1080 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1081 sym_hashes
= elf_sym_hashes (abfd
);
1085 rel_end
= relocs
+ sec
->reloc_count
;
1086 for (rel
= relocs
; rel
< rel_end
; rel
++)
1088 unsigned int r_type
;
1089 unsigned long r_symndx
;
1090 struct elf_link_hash_entry
*h
;
1092 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1093 r_type
= ELF64_R_TYPE (rel
->r_info
);
1095 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1097 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1102 if (r_symndx
< symtab_hdr
->sh_info
)
1104 /* A local symbol. */
1105 Elf_Internal_Sym
*isym
;
1107 /* Read this BFD's local symbols. */
1108 if (isymbuf
== NULL
)
1110 if (isymbuf
== NULL
)
1111 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1112 symtab_hdr
->sh_info
, 0,
1114 if (isymbuf
== NULL
)
1118 /* Check relocation against local STT_GNU_IFUNC symbol. */
1119 isym
= isymbuf
+ r_symndx
;
1120 if (ELF64_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1122 h
= elf64_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1127 /* Fake a STT_GNU_IFUNC symbol. */
1128 h
->type
= STT_GNU_IFUNC
;
1131 h
->forced_local
= 1;
1132 h
->root
.type
= bfd_link_hash_defined
;
1139 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1140 while (h
->root
.type
== bfd_link_hash_indirect
1141 || h
->root
.type
== bfd_link_hash_warning
)
1142 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1147 /* Create the ifunc sections for static executables. If we
1148 never see an indirect function symbol nor we are building
1149 a static executable, those sections will be empty and
1150 won't appear in output. */
1161 case R_X86_64_PLT32
:
1162 case R_X86_64_GOTPCREL
:
1163 case R_X86_64_GOTPCREL64
:
1164 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1169 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1170 it here if it is defined in a non-shared object. */
1171 if (h
->type
== STT_GNU_IFUNC
1174 /* It is referenced by a non-shared object. */
1177 /* STT_GNU_IFUNC symbol must go through PLT. */
1178 h
->plt
.refcount
+= 1;
1180 /* STT_GNU_IFUNC needs dynamic sections. */
1181 if (htab
->elf
.dynobj
== NULL
)
1182 htab
->elf
.dynobj
= abfd
;
1187 (*_bfd_error_handler
)
1188 (_("%B: relocation %s against STT_GNU_IFUNC "
1189 "symbol `%s' isn't handled by %s"), abfd
,
1190 x86_64_elf_howto_table
[r_type
].name
,
1191 (h
->root
.root
.string
1192 ? h
->root
.root
.string
: "a local symbol"),
1194 bfd_set_error (bfd_error_bad_value
);
1199 h
->pointer_equality_needed
= 1;
1202 struct elf64_x86_64_dyn_relocs
*p
;
1203 struct elf64_x86_64_dyn_relocs
**head
;
1205 /* We must copy these reloc types into the output
1206 file. Create a reloc section in dynobj and
1207 make room for this reloc. */
1210 if (htab
->elf
.dynobj
== NULL
)
1211 htab
->elf
.dynobj
= abfd
;
1213 sreloc
= _bfd_elf_make_dynamic_reloc_section
1214 (sec
, htab
->elf
.dynobj
, 3, abfd
, TRUE
);
1220 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1222 if (p
== NULL
|| p
->sec
!= sec
)
1224 bfd_size_type amt
= sizeof *p
;
1226 p
= ((struct elf64_x86_64_dyn_relocs
*)
1227 bfd_alloc (htab
->elf
.dynobj
, amt
));
1245 if (r_type
!= R_X86_64_PC32
1246 && r_type
!= R_X86_64_PC64
)
1247 h
->pointer_equality_needed
= 1;
1250 case R_X86_64_PLT32
:
1253 case R_X86_64_GOTPCREL
:
1254 case R_X86_64_GOTPCREL64
:
1255 h
->got
.refcount
+= 1;
1256 if (htab
->elf
.sgot
== NULL
1257 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1267 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1268 symtab_hdr
, sym_hashes
,
1269 &r_type
, GOT_UNKNOWN
,
1275 case R_X86_64_TLSLD
:
1276 htab
->tls_ld_got
.refcount
+= 1;
1279 case R_X86_64_TPOFF32
:
1282 (*_bfd_error_handler
)
1283 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1285 x86_64_elf_howto_table
[r_type
].name
,
1286 (h
) ? h
->root
.root
.string
: "a local symbol");
1287 bfd_set_error (bfd_error_bad_value
);
1292 case R_X86_64_GOTTPOFF
:
1294 info
->flags
|= DF_STATIC_TLS
;
1297 case R_X86_64_GOT32
:
1298 case R_X86_64_GOTPCREL
:
1299 case R_X86_64_TLSGD
:
1300 case R_X86_64_GOT64
:
1301 case R_X86_64_GOTPCREL64
:
1302 case R_X86_64_GOTPLT64
:
1303 case R_X86_64_GOTPC32_TLSDESC
:
1304 case R_X86_64_TLSDESC_CALL
:
1305 /* This symbol requires a global offset table entry. */
1307 int tls_type
, old_tls_type
;
1311 default: tls_type
= GOT_NORMAL
; break;
1312 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1313 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1314 case R_X86_64_GOTPC32_TLSDESC
:
1315 case R_X86_64_TLSDESC_CALL
:
1316 tls_type
= GOT_TLS_GDESC
; break;
1321 if (r_type
== R_X86_64_GOTPLT64
)
1323 /* This relocation indicates that we also need
1324 a PLT entry, as this is a function. We don't need
1325 a PLT entry for local symbols. */
1327 h
->plt
.refcount
+= 1;
1329 h
->got
.refcount
+= 1;
1330 old_tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1334 bfd_signed_vma
*local_got_refcounts
;
1336 /* This is a global offset table entry for a local symbol. */
1337 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1338 if (local_got_refcounts
== NULL
)
1342 size
= symtab_hdr
->sh_info
;
1343 size
*= sizeof (bfd_signed_vma
)
1344 + sizeof (bfd_vma
) + sizeof (char);
1345 local_got_refcounts
= ((bfd_signed_vma
*)
1346 bfd_zalloc (abfd
, size
));
1347 if (local_got_refcounts
== NULL
)
1349 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1350 elf64_x86_64_local_tlsdesc_gotent (abfd
)
1351 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1352 elf64_x86_64_local_got_tls_type (abfd
)
1353 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1355 local_got_refcounts
[r_symndx
] += 1;
1357 = elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1360 /* If a TLS symbol is accessed using IE at least once,
1361 there is no point to use dynamic model for it. */
1362 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1363 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1364 || tls_type
!= GOT_TLS_IE
))
1366 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1367 tls_type
= old_tls_type
;
1368 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1369 && GOT_TLS_GD_ANY_P (tls_type
))
1370 tls_type
|= old_tls_type
;
1373 (*_bfd_error_handler
)
1374 (_("%B: '%s' accessed both as normal and thread local symbol"),
1375 abfd
, h
? h
->root
.root
.string
: "<local>");
1380 if (old_tls_type
!= tls_type
)
1383 elf64_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1385 elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1390 case R_X86_64_GOTOFF64
:
1391 case R_X86_64_GOTPC32
:
1392 case R_X86_64_GOTPC64
:
1394 if (htab
->elf
.sgot
== NULL
)
1396 if (htab
->elf
.dynobj
== NULL
)
1397 htab
->elf
.dynobj
= abfd
;
1398 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1404 case R_X86_64_PLT32
:
1405 /* This symbol requires a procedure linkage table entry. We
1406 actually build the entry in adjust_dynamic_symbol,
1407 because this might be a case of linking PIC code which is
1408 never referenced by a dynamic object, in which case we
1409 don't need to generate a procedure linkage table entry
1412 /* If this is a local symbol, we resolve it directly without
1413 creating a procedure linkage table entry. */
1418 h
->plt
.refcount
+= 1;
1421 case R_X86_64_PLTOFF64
:
1422 /* This tries to form the 'address' of a function relative
1423 to GOT. For global symbols we need a PLT entry. */
1427 h
->plt
.refcount
+= 1;
1435 /* Let's help debug shared library creation. These relocs
1436 cannot be used in shared libs. Don't error out for
1437 sections we don't care about, such as debug sections or
1438 non-constant sections. */
1440 && (sec
->flags
& SEC_ALLOC
) != 0
1441 && (sec
->flags
& SEC_READONLY
) != 0)
1443 (*_bfd_error_handler
)
1444 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1446 x86_64_elf_howto_table
[r_type
].name
,
1447 (h
) ? h
->root
.root
.string
: "a local symbol");
1448 bfd_set_error (bfd_error_bad_value
);
1458 if (h
!= NULL
&& info
->executable
)
1460 /* If this reloc is in a read-only section, we might
1461 need a copy reloc. We can't check reliably at this
1462 stage whether the section is read-only, as input
1463 sections have not yet been mapped to output sections.
1464 Tentatively set the flag for now, and correct in
1465 adjust_dynamic_symbol. */
1468 /* We may need a .plt entry if the function this reloc
1469 refers to is in a shared lib. */
1470 h
->plt
.refcount
+= 1;
1471 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1472 h
->pointer_equality_needed
= 1;
1475 /* If we are creating a shared library, and this is a reloc
1476 against a global symbol, or a non PC relative reloc
1477 against a local symbol, then we need to copy the reloc
1478 into the shared library. However, if we are linking with
1479 -Bsymbolic, we do not need to copy a reloc against a
1480 global symbol which is defined in an object we are
1481 including in the link (i.e., DEF_REGULAR is set). At
1482 this point we have not seen all the input files, so it is
1483 possible that DEF_REGULAR is not set now but will be set
1484 later (it is never cleared). In case of a weak definition,
1485 DEF_REGULAR may be cleared later by a strong definition in
1486 a shared library. We account for that possibility below by
1487 storing information in the relocs_copied field of the hash
1488 table entry. A similar situation occurs when creating
1489 shared libraries and symbol visibility changes render the
1492 If on the other hand, we are creating an executable, we
1493 may need to keep relocations for symbols satisfied by a
1494 dynamic library if we manage to avoid copy relocs for the
1497 && (sec
->flags
& SEC_ALLOC
) != 0
1498 && (! IS_X86_64_PCREL_TYPE (r_type
)
1500 && (! SYMBOLIC_BIND (info
, h
)
1501 || h
->root
.type
== bfd_link_hash_defweak
1502 || !h
->def_regular
))))
1503 || (ELIMINATE_COPY_RELOCS
1505 && (sec
->flags
& SEC_ALLOC
) != 0
1507 && (h
->root
.type
== bfd_link_hash_defweak
1508 || !h
->def_regular
)))
1510 struct elf64_x86_64_dyn_relocs
*p
;
1511 struct elf64_x86_64_dyn_relocs
**head
;
1513 /* We must copy these reloc types into the output file.
1514 Create a reloc section in dynobj and make room for
1518 if (htab
->elf
.dynobj
== NULL
)
1519 htab
->elf
.dynobj
= abfd
;
1521 sreloc
= _bfd_elf_make_dynamic_reloc_section
1522 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
1528 /* If this is a global symbol, we count the number of
1529 relocations we need for this symbol. */
1532 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1537 /* Track dynamic relocs needed for local syms too.
1538 We really need local syms available to do this
1542 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1547 /* Beware of type punned pointers vs strict aliasing
1549 vpp
= &(elf_section_data (s
)->local_dynrel
);
1550 head
= (struct elf64_x86_64_dyn_relocs
**)vpp
;
1554 if (p
== NULL
|| p
->sec
!= sec
)
1556 bfd_size_type amt
= sizeof *p
;
1558 p
= ((struct elf64_x86_64_dyn_relocs
*)
1559 bfd_alloc (htab
->elf
.dynobj
, amt
));
1570 if (IS_X86_64_PCREL_TYPE (r_type
))
1575 /* This relocation describes the C++ object vtable hierarchy.
1576 Reconstruct it for later use during GC. */
1577 case R_X86_64_GNU_VTINHERIT
:
1578 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1582 /* This relocation describes which C++ vtable entries are actually
1583 used. Record for later use during GC. */
1584 case R_X86_64_GNU_VTENTRY
:
1585 BFD_ASSERT (h
!= NULL
);
1587 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1599 /* Return the section that should be marked against GC for a given
1603 elf64_x86_64_gc_mark_hook (asection
*sec
,
1604 struct bfd_link_info
*info
,
1605 Elf_Internal_Rela
*rel
,
1606 struct elf_link_hash_entry
*h
,
1607 Elf_Internal_Sym
*sym
)
1610 switch (ELF64_R_TYPE (rel
->r_info
))
1612 case R_X86_64_GNU_VTINHERIT
:
1613 case R_X86_64_GNU_VTENTRY
:
1617 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1620 /* Update the got entry reference counts for the section being removed. */
1623 elf64_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1625 const Elf_Internal_Rela
*relocs
)
1627 Elf_Internal_Shdr
*symtab_hdr
;
1628 struct elf_link_hash_entry
**sym_hashes
;
1629 bfd_signed_vma
*local_got_refcounts
;
1630 const Elf_Internal_Rela
*rel
, *relend
;
1632 if (info
->relocatable
)
1635 elf_section_data (sec
)->local_dynrel
= NULL
;
1637 symtab_hdr
= &elf_symtab_hdr (abfd
);
1638 sym_hashes
= elf_sym_hashes (abfd
);
1639 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1641 relend
= relocs
+ sec
->reloc_count
;
1642 for (rel
= relocs
; rel
< relend
; rel
++)
1644 unsigned long r_symndx
;
1645 unsigned int r_type
;
1646 struct elf_link_hash_entry
*h
= NULL
;
1648 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1649 if (r_symndx
>= symtab_hdr
->sh_info
)
1651 struct elf64_x86_64_link_hash_entry
*eh
;
1652 struct elf64_x86_64_dyn_relocs
**pp
;
1653 struct elf64_x86_64_dyn_relocs
*p
;
1655 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1656 while (h
->root
.type
== bfd_link_hash_indirect
1657 || h
->root
.type
== bfd_link_hash_warning
)
1658 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1659 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1661 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1664 /* Everything must go for SEC. */
1670 r_type
= ELF64_R_TYPE (rel
->r_info
);
1671 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1672 symtab_hdr
, sym_hashes
,
1673 &r_type
, GOT_UNKNOWN
,
1679 case R_X86_64_TLSLD
:
1680 if (elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
> 0)
1681 elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
-= 1;
1684 case R_X86_64_TLSGD
:
1685 case R_X86_64_GOTPC32_TLSDESC
:
1686 case R_X86_64_TLSDESC_CALL
:
1687 case R_X86_64_GOTTPOFF
:
1688 case R_X86_64_GOT32
:
1689 case R_X86_64_GOTPCREL
:
1690 case R_X86_64_GOT64
:
1691 case R_X86_64_GOTPCREL64
:
1692 case R_X86_64_GOTPLT64
:
1695 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
1696 h
->plt
.refcount
-= 1;
1697 if (h
->got
.refcount
> 0)
1698 h
->got
.refcount
-= 1;
1700 else if (local_got_refcounts
!= NULL
)
1702 if (local_got_refcounts
[r_symndx
] > 0)
1703 local_got_refcounts
[r_symndx
] -= 1;
1720 case R_X86_64_PLT32
:
1721 case R_X86_64_PLTOFF64
:
1724 if (h
->plt
.refcount
> 0)
1725 h
->plt
.refcount
-= 1;
1737 /* Adjust a symbol defined by a dynamic object and referenced by a
1738 regular object. The current definition is in some section of the
1739 dynamic object, but we're not including those sections. We have to
1740 change the definition to something the rest of the link can
1744 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1745 struct elf_link_hash_entry
*h
)
1747 struct elf64_x86_64_link_hash_table
*htab
;
1750 /* STT_GNU_IFUNC symbol must go through PLT. */
1751 if (h
->type
== STT_GNU_IFUNC
)
1753 if (h
->plt
.refcount
<= 0)
1755 h
->plt
.offset
= (bfd_vma
) -1;
1761 /* If this is a function, put it in the procedure linkage table. We
1762 will fill in the contents of the procedure linkage table later,
1763 when we know the address of the .got section. */
1764 if (h
->type
== STT_FUNC
1767 if (h
->plt
.refcount
<= 0
1768 || SYMBOL_CALLS_LOCAL (info
, h
)
1769 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1770 && h
->root
.type
== bfd_link_hash_undefweak
))
1772 /* This case can occur if we saw a PLT32 reloc in an input
1773 file, but the symbol was never referred to by a dynamic
1774 object, or if all references were garbage collected. In
1775 such a case, we don't actually need to build a procedure
1776 linkage table, and we can just do a PC32 reloc instead. */
1777 h
->plt
.offset
= (bfd_vma
) -1;
1784 /* It's possible that we incorrectly decided a .plt reloc was
1785 needed for an R_X86_64_PC32 reloc to a non-function sym in
1786 check_relocs. We can't decide accurately between function and
1787 non-function syms in check-relocs; Objects loaded later in
1788 the link may change h->type. So fix it now. */
1789 h
->plt
.offset
= (bfd_vma
) -1;
1791 /* If this is a weak symbol, and there is a real definition, the
1792 processor independent code will have arranged for us to see the
1793 real definition first, and we can just use the same value. */
1794 if (h
->u
.weakdef
!= NULL
)
1796 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1797 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1798 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1799 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1800 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1801 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1805 /* This is a reference to a symbol defined by a dynamic object which
1806 is not a function. */
1808 /* If we are creating a shared library, we must presume that the
1809 only references to the symbol are via the global offset table.
1810 For such cases we need not do anything here; the relocations will
1811 be handled correctly by relocate_section. */
1815 /* If there are no references to this symbol that do not use the
1816 GOT, we don't need to generate a copy reloc. */
1817 if (!h
->non_got_ref
)
1820 /* If -z nocopyreloc was given, we won't generate them either. */
1821 if (info
->nocopyreloc
)
1827 if (ELIMINATE_COPY_RELOCS
)
1829 struct elf64_x86_64_link_hash_entry
* eh
;
1830 struct elf64_x86_64_dyn_relocs
*p
;
1832 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1833 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1835 s
= p
->sec
->output_section
;
1836 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1840 /* If we didn't find any dynamic relocs in read-only sections, then
1841 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1851 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1852 h
->root
.root
.string
);
1856 /* We must allocate the symbol in our .dynbss section, which will
1857 become part of the .bss section of the executable. There will be
1858 an entry for this symbol in the .dynsym section. The dynamic
1859 object will contain position independent code, so all references
1860 from the dynamic object to this symbol will go through the global
1861 offset table. The dynamic linker will use the .dynsym entry to
1862 determine the address it must put in the global offset table, so
1863 both the dynamic object and the regular object will refer to the
1864 same memory location for the variable. */
1866 htab
= elf64_x86_64_hash_table (info
);
1868 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1869 to copy the initial value out of the dynamic object and into the
1870 runtime process image. */
1871 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1873 htab
->srelbss
->size
+= sizeof (Elf64_External_Rela
);
1879 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1882 /* Allocate space in .plt, .got and associated reloc sections for
1886 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
1888 struct bfd_link_info
*info
;
1889 struct elf64_x86_64_link_hash_table
*htab
;
1890 struct elf64_x86_64_link_hash_entry
*eh
;
1891 struct elf64_x86_64_dyn_relocs
*p
;
1893 if (h
->root
.type
== bfd_link_hash_indirect
)
1896 if (h
->root
.type
== bfd_link_hash_warning
)
1897 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1898 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1900 info
= (struct bfd_link_info
*) inf
;
1901 htab
= elf64_x86_64_hash_table (info
);
1903 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1904 here if it is defined and referenced in a non-shared object. */
1905 if (h
->type
== STT_GNU_IFUNC
1908 asection
*plt
, *gotplt
, *relplt
;
1910 /* When a shared library references a STT_GNU_IFUNC symbol
1911 defined in executable, the address of the resolved function
1912 may be used. But in non-shared executable, the address of
1913 its .plt slot may be used. Pointer equality may not work
1914 correctly. PIE should be used if pointer equality is
1917 && (h
->dynindx
!= -1
1918 || info
->export_dynamic
)
1919 && h
->pointer_equality_needed
)
1921 info
->callbacks
->einfo
1922 (_("%F%P: dynamic STT_GNU_IFUNC symbol `%s' with pointer "
1923 "equality in `%B' can not be used when making an "
1924 "executable; recompile with -fPIE and relink with -pie\n"),
1925 h
->root
.root
.string
,
1926 h
->root
.u
.def
.section
->owner
);
1927 bfd_set_error (bfd_error_bad_value
);
1931 /* Return and discard space for dynamic relocations against it if
1932 it is never referenced in a non-shared object. */
1933 if (!h
->ref_regular
)
1935 if (h
->plt
.refcount
> 0
1936 || h
->got
.refcount
> 0)
1938 h
->got
.offset
= (bfd_vma
) -1;
1939 eh
->dyn_relocs
= NULL
;
1943 /* When building a static executable, use .iplt, .igot.plt and
1944 .rela.iplt sections for STT_GNU_IFUNC symbols. */
1945 if (htab
->elf
.splt
!= NULL
)
1947 plt
= htab
->elf
.splt
;
1948 gotplt
= htab
->elf
.sgotplt
;
1949 relplt
= htab
->elf
.srelplt
;
1951 /* If this is the first .plt entry, make room for the special
1954 plt
->size
+= PLT_ENTRY_SIZE
;
1958 plt
= htab
->elf
.iplt
;
1959 gotplt
= htab
->elf
.igotplt
;
1960 relplt
= htab
->elf
.irelplt
;
1963 /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
1964 the original value for R_X86_64_IRELATIVE. */
1965 h
->plt
.offset
= plt
->size
;
1967 /* Make room for this entry in the .plt/.iplt section. */
1968 plt
->size
+= PLT_ENTRY_SIZE
;
1970 /* We also need to make an entry in the .got.plt/.got.iplt
1971 section, which will be placed in the .got section by the
1973 gotplt
->size
+= GOT_ENTRY_SIZE
;
1975 /* We also need to make an entry in the .rela.plt/.rela.iplt
1977 relplt
->size
+= sizeof (Elf64_External_Rela
);
1978 relplt
->reloc_count
++;
1980 /* We need dynamic relocation for STT_GNU_IFUNC symbol only
1981 when there is a non-GOT reference in a shared object. */
1984 eh
->dyn_relocs
= NULL
;
1986 /* Finally, allocate space. */
1987 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1988 htab
->elf
.irelifunc
->size
1989 += p
->count
* sizeof (Elf64_External_Rela
);
1991 /* For STT_GNU_IFUNC symbol, .got.plt has the real function
1992 addres and .got has the PLT entry adddress. We will load
1993 the GOT entry with the PLT entry in finish_dynamic_symbol if
1994 it is used. For branch, it uses .got.plt. For symbol value,
1995 1. Use .got.plt in a shared object if it is forced local or
1997 2. Use .got.plt in a non-shared object if pointer equality
1999 3. Use .got.plt in PIE.
2000 4. Use .got.plt if .got isn't used.
2001 5. Otherwise use .got so that it can be shared among different
2002 objects at run-time.
2003 We only need to relocate .got entry in shared object. */
2005 && (h
->dynindx
== -1
2006 || h
->forced_local
))
2008 && !h
->pointer_equality_needed
)
2009 || (info
->executable
&& info
->shared
)
2010 || htab
->elf
.sgot
== NULL
)
2013 h
->got
.offset
= (bfd_vma
) -1;
2017 h
->got
.offset
= htab
->elf
.sgot
->size
;
2018 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2020 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2025 else if (htab
->elf
.dynamic_sections_created
2026 && h
->plt
.refcount
> 0)
2028 /* Make sure this symbol is output as a dynamic symbol.
2029 Undefined weak syms won't yet be marked as dynamic. */
2030 if (h
->dynindx
== -1
2031 && !h
->forced_local
)
2033 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2038 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2040 asection
*s
= htab
->elf
.splt
;
2042 /* If this is the first .plt entry, make room for the special
2045 s
->size
+= PLT_ENTRY_SIZE
;
2047 h
->plt
.offset
= s
->size
;
2049 /* If this symbol is not defined in a regular file, and we are
2050 not generating a shared library, then set the symbol to this
2051 location in the .plt. This is required to make function
2052 pointers compare as equal between the normal executable and
2053 the shared library. */
2057 h
->root
.u
.def
.section
= s
;
2058 h
->root
.u
.def
.value
= h
->plt
.offset
;
2061 /* Make room for this entry. */
2062 s
->size
+= PLT_ENTRY_SIZE
;
2064 /* We also need to make an entry in the .got.plt section, which
2065 will be placed in the .got section by the linker script. */
2066 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2068 /* We also need to make an entry in the .rela.plt section. */
2069 htab
->elf
.srelplt
->size
+= sizeof (Elf64_External_Rela
);
2070 htab
->elf
.srelplt
->reloc_count
++;
2074 h
->plt
.offset
= (bfd_vma
) -1;
2080 h
->plt
.offset
= (bfd_vma
) -1;
2084 eh
->tlsdesc_got
= (bfd_vma
) -1;
2086 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2087 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2088 if (h
->got
.refcount
> 0
2091 && elf64_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2093 h
->got
.offset
= (bfd_vma
) -1;
2095 else if (h
->got
.refcount
> 0)
2099 int tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
2101 /* Make sure this symbol is output as a dynamic symbol.
2102 Undefined weak syms won't yet be marked as dynamic. */
2103 if (h
->dynindx
== -1
2104 && !h
->forced_local
)
2106 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2110 if (GOT_TLS_GDESC_P (tls_type
))
2112 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2113 - elf64_x86_64_compute_jump_table_size (htab
);
2114 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2115 h
->got
.offset
= (bfd_vma
) -2;
2117 if (! GOT_TLS_GDESC_P (tls_type
)
2118 || GOT_TLS_GD_P (tls_type
))
2121 h
->got
.offset
= s
->size
;
2122 s
->size
+= GOT_ENTRY_SIZE
;
2123 if (GOT_TLS_GD_P (tls_type
))
2124 s
->size
+= GOT_ENTRY_SIZE
;
2126 dyn
= htab
->elf
.dynamic_sections_created
;
2127 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2129 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2130 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2131 || tls_type
== GOT_TLS_IE
)
2132 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2133 else if (GOT_TLS_GD_P (tls_type
))
2134 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf64_External_Rela
);
2135 else if (! GOT_TLS_GDESC_P (tls_type
)
2136 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2137 || h
->root
.type
!= bfd_link_hash_undefweak
)
2139 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2140 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2141 if (GOT_TLS_GDESC_P (tls_type
))
2143 htab
->elf
.srelplt
->size
+= sizeof (Elf64_External_Rela
);
2144 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2148 h
->got
.offset
= (bfd_vma
) -1;
2150 if (eh
->dyn_relocs
== NULL
)
2153 /* In the shared -Bsymbolic case, discard space allocated for
2154 dynamic pc-relative relocs against symbols which turn out to be
2155 defined in regular objects. For the normal shared case, discard
2156 space for pc-relative relocs that have become local due to symbol
2157 visibility changes. */
2161 /* Relocs that use pc_count are those that appear on a call
2162 insn, or certain REL relocs that can generated via assembly.
2163 We want calls to protected symbols to resolve directly to the
2164 function rather than going via the plt. If people want
2165 function pointer comparisons to work as expected then they
2166 should avoid writing weird assembly. */
2167 if (SYMBOL_CALLS_LOCAL (info
, h
))
2169 struct elf64_x86_64_dyn_relocs
**pp
;
2171 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2173 p
->count
-= p
->pc_count
;
2182 /* Also discard relocs on undefined weak syms with non-default
2184 if (eh
->dyn_relocs
!= NULL
2185 && h
->root
.type
== bfd_link_hash_undefweak
)
2187 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2188 eh
->dyn_relocs
= NULL
;
2190 /* Make sure undefined weak symbols are output as a dynamic
2192 else if (h
->dynindx
== -1
2193 && ! h
->forced_local
2194 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2199 else if (ELIMINATE_COPY_RELOCS
)
2201 /* For the non-shared case, discard space for relocs against
2202 symbols which turn out to need copy relocs or are not
2208 || (htab
->elf
.dynamic_sections_created
2209 && (h
->root
.type
== bfd_link_hash_undefweak
2210 || h
->root
.type
== bfd_link_hash_undefined
))))
2212 /* Make sure this symbol is output as a dynamic symbol.
2213 Undefined weak syms won't yet be marked as dynamic. */
2214 if (h
->dynindx
== -1
2215 && ! h
->forced_local
2216 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2219 /* If that succeeded, we know we'll be keeping all the
2221 if (h
->dynindx
!= -1)
2225 eh
->dyn_relocs
= NULL
;
2230 /* Finally, allocate space. */
2231 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2235 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2237 BFD_ASSERT (sreloc
!= NULL
);
2239 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2245 /* Allocate space in .plt, .got and associated reloc sections for
2246 local dynamic relocs. */
2249 elf64_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2251 struct elf_link_hash_entry
*h
2252 = (struct elf_link_hash_entry
*) *slot
;
2254 if (h
->type
!= STT_GNU_IFUNC
2258 || h
->root
.type
!= bfd_link_hash_defined
)
2261 return elf64_x86_64_allocate_dynrelocs (h
, inf
);
2264 /* Find any dynamic relocs that apply to read-only sections. */
2267 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2269 struct elf64_x86_64_link_hash_entry
*eh
;
2270 struct elf64_x86_64_dyn_relocs
*p
;
2272 if (h
->root
.type
== bfd_link_hash_warning
)
2273 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2275 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
2276 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2278 asection
*s
= p
->sec
->output_section
;
2280 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2282 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2284 info
->flags
|= DF_TEXTREL
;
2286 /* Not an error, just cut short the traversal. */
2293 /* Set the sizes of the dynamic sections. */
2296 elf64_x86_64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2297 struct bfd_link_info
*info
)
2299 struct elf64_x86_64_link_hash_table
*htab
;
2305 htab
= elf64_x86_64_hash_table (info
);
2306 dynobj
= htab
->elf
.dynobj
;
2310 if (htab
->elf
.dynamic_sections_created
)
2312 /* Set the contents of the .interp section to the interpreter. */
2313 if (info
->executable
)
2315 s
= bfd_get_section_by_name (dynobj
, ".interp");
2318 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2319 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2323 /* Set up .got offsets for local syms, and space for local dynamic
2325 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2327 bfd_signed_vma
*local_got
;
2328 bfd_signed_vma
*end_local_got
;
2329 char *local_tls_type
;
2330 bfd_vma
*local_tlsdesc_gotent
;
2331 bfd_size_type locsymcount
;
2332 Elf_Internal_Shdr
*symtab_hdr
;
2335 if (! is_x86_64_elf (ibfd
))
2338 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2340 struct elf64_x86_64_dyn_relocs
*p
;
2342 for (p
= (struct elf64_x86_64_dyn_relocs
*)
2343 (elf_section_data (s
)->local_dynrel
);
2347 if (!bfd_is_abs_section (p
->sec
)
2348 && bfd_is_abs_section (p
->sec
->output_section
))
2350 /* Input section has been discarded, either because
2351 it is a copy of a linkonce section or due to
2352 linker script /DISCARD/, so we'll be discarding
2355 else if (p
->count
!= 0)
2357 srel
= elf_section_data (p
->sec
)->sreloc
;
2358 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2359 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2360 info
->flags
|= DF_TEXTREL
;
2365 local_got
= elf_local_got_refcounts (ibfd
);
2369 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2370 locsymcount
= symtab_hdr
->sh_info
;
2371 end_local_got
= local_got
+ locsymcount
;
2372 local_tls_type
= elf64_x86_64_local_got_tls_type (ibfd
);
2373 local_tlsdesc_gotent
= elf64_x86_64_local_tlsdesc_gotent (ibfd
);
2375 srel
= htab
->elf
.srelgot
;
2376 for (; local_got
< end_local_got
;
2377 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2379 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2382 if (GOT_TLS_GDESC_P (*local_tls_type
))
2384 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2385 - elf64_x86_64_compute_jump_table_size (htab
);
2386 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2387 *local_got
= (bfd_vma
) -2;
2389 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2390 || GOT_TLS_GD_P (*local_tls_type
))
2392 *local_got
= s
->size
;
2393 s
->size
+= GOT_ENTRY_SIZE
;
2394 if (GOT_TLS_GD_P (*local_tls_type
))
2395 s
->size
+= GOT_ENTRY_SIZE
;
2398 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2399 || *local_tls_type
== GOT_TLS_IE
)
2401 if (GOT_TLS_GDESC_P (*local_tls_type
))
2403 htab
->elf
.srelplt
->size
2404 += sizeof (Elf64_External_Rela
);
2405 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2407 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2408 || GOT_TLS_GD_P (*local_tls_type
))
2409 srel
->size
+= sizeof (Elf64_External_Rela
);
2413 *local_got
= (bfd_vma
) -1;
2417 if (htab
->tls_ld_got
.refcount
> 0)
2419 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2421 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2422 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2423 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2426 htab
->tls_ld_got
.offset
= -1;
2428 /* Allocate global sym .plt and .got entries, and space for global
2429 sym dynamic relocs. */
2430 elf_link_hash_traverse (&htab
->elf
, elf64_x86_64_allocate_dynrelocs
,
2433 /* Allocate .plt and .got entries, and space for local symbols. */
2434 htab_traverse (htab
->loc_hash_table
,
2435 elf64_x86_64_allocate_local_dynrelocs
,
2438 /* For every jump slot reserved in the sgotplt, reloc_count is
2439 incremented. However, when we reserve space for TLS descriptors,
2440 it's not incremented, so in order to compute the space reserved
2441 for them, it suffices to multiply the reloc count by the jump
2443 if (htab
->elf
.srelplt
)
2444 htab
->sgotplt_jump_table_size
2445 = elf64_x86_64_compute_jump_table_size (htab
);
2447 if (htab
->tlsdesc_plt
)
2449 /* If we're not using lazy TLS relocations, don't generate the
2450 PLT and GOT entries they require. */
2451 if ((info
->flags
& DF_BIND_NOW
))
2452 htab
->tlsdesc_plt
= 0;
2455 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2456 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2457 /* Reserve room for the initial entry.
2458 FIXME: we could probably do away with it in this case. */
2459 if (htab
->elf
.splt
->size
== 0)
2460 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2461 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2462 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2466 /* We now have determined the sizes of the various dynamic sections.
2467 Allocate memory for them. */
2469 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2471 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2474 if (s
== htab
->elf
.splt
2475 || s
== htab
->elf
.sgot
2476 || s
== htab
->elf
.sgotplt
2477 || s
== htab
->elf
.iplt
2478 || s
== htab
->elf
.igotplt
2479 || s
== htab
->sdynbss
)
2481 /* Strip this section if we don't need it; see the
2484 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2486 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2489 /* We use the reloc_count field as a counter if we need
2490 to copy relocs into the output file. */
2491 if (s
!= htab
->elf
.srelplt
)
2496 /* It's not one of our sections, so don't allocate space. */
2502 /* If we don't need this section, strip it from the
2503 output file. This is mostly to handle .rela.bss and
2504 .rela.plt. We must create both sections in
2505 create_dynamic_sections, because they must be created
2506 before the linker maps input sections to output
2507 sections. The linker does that before
2508 adjust_dynamic_symbol is called, and it is that
2509 function which decides whether anything needs to go
2510 into these sections. */
2512 s
->flags
|= SEC_EXCLUDE
;
2516 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2519 /* Allocate memory for the section contents. We use bfd_zalloc
2520 here in case unused entries are not reclaimed before the
2521 section's contents are written out. This should not happen,
2522 but this way if it does, we get a R_X86_64_NONE reloc instead
2524 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2525 if (s
->contents
== NULL
)
2529 if (htab
->elf
.dynamic_sections_created
)
2531 /* Add some entries to the .dynamic section. We fill in the
2532 values later, in elf64_x86_64_finish_dynamic_sections, but we
2533 must add the entries now so that we get the correct size for
2534 the .dynamic section. The DT_DEBUG entry is filled in by the
2535 dynamic linker and used by the debugger. */
2536 #define add_dynamic_entry(TAG, VAL) \
2537 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2539 if (info
->executable
)
2541 if (!add_dynamic_entry (DT_DEBUG
, 0))
2545 if (htab
->elf
.splt
->size
!= 0)
2547 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2548 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2549 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2550 || !add_dynamic_entry (DT_JMPREL
, 0))
2553 if (htab
->tlsdesc_plt
2554 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2555 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2561 if (!add_dynamic_entry (DT_RELA
, 0)
2562 || !add_dynamic_entry (DT_RELASZ
, 0)
2563 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2566 /* If any dynamic relocs apply to a read-only section,
2567 then we need a DT_TEXTREL entry. */
2568 if ((info
->flags
& DF_TEXTREL
) == 0)
2569 elf_link_hash_traverse (&htab
->elf
,
2570 elf64_x86_64_readonly_dynrelocs
,
2573 if ((info
->flags
& DF_TEXTREL
) != 0)
2575 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2580 #undef add_dynamic_entry
2586 elf64_x86_64_always_size_sections (bfd
*output_bfd
,
2587 struct bfd_link_info
*info
)
2589 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2593 struct elf_link_hash_entry
*tlsbase
;
2595 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2596 "_TLS_MODULE_BASE_",
2597 FALSE
, FALSE
, FALSE
);
2599 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2601 struct bfd_link_hash_entry
*bh
= NULL
;
2602 const struct elf_backend_data
*bed
2603 = get_elf_backend_data (output_bfd
);
2605 if (!(_bfd_generic_link_add_one_symbol
2606 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2607 tls_sec
, 0, NULL
, FALSE
,
2608 bed
->collect
, &bh
)))
2611 elf64_x86_64_hash_table (info
)->tls_module_base
= bh
;
2613 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2614 tlsbase
->def_regular
= 1;
2615 tlsbase
->other
= STV_HIDDEN
;
2616 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2623 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2624 executables. Rather than setting it to the beginning of the TLS
2625 section, we have to set it to the end. This function may be called
2626 multiple times, it is idempotent. */
2629 elf64_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2631 struct bfd_link_hash_entry
*base
;
2633 if (!info
->executable
)
2636 base
= elf64_x86_64_hash_table (info
)->tls_module_base
;
2641 base
->u
.def
.value
= elf_hash_table (info
)->tls_size
;
2644 /* Return the base VMA address which should be subtracted from real addresses
2645 when resolving @dtpoff relocation.
2646 This is PT_TLS segment p_vaddr. */
2649 elf64_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2651 /* If tls_sec is NULL, we should have signalled an error already. */
2652 if (elf_hash_table (info
)->tls_sec
== NULL
)
2654 return elf_hash_table (info
)->tls_sec
->vma
;
2657 /* Return the relocation value for @tpoff relocation
2658 if STT_TLS virtual address is ADDRESS. */
2661 elf64_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2663 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2665 /* If tls_segment is NULL, we should have signalled an error already. */
2666 if (htab
->tls_sec
== NULL
)
2668 return address
- htab
->tls_size
- htab
->tls_sec
->vma
;
2671 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2675 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2677 /* Opcode Instruction
2680 0x0f 0x8x conditional jump */
2682 && (contents
[offset
- 1] == 0xe8
2683 || contents
[offset
- 1] == 0xe9))
2685 && contents
[offset
- 2] == 0x0f
2686 && (contents
[offset
- 1] & 0xf0) == 0x80));
2689 /* Relocate an x86_64 ELF section. */
2692 elf64_x86_64_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
2693 bfd
*input_bfd
, asection
*input_section
,
2694 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
2695 Elf_Internal_Sym
*local_syms
,
2696 asection
**local_sections
)
2698 struct elf64_x86_64_link_hash_table
*htab
;
2699 Elf_Internal_Shdr
*symtab_hdr
;
2700 struct elf_link_hash_entry
**sym_hashes
;
2701 bfd_vma
*local_got_offsets
;
2702 bfd_vma
*local_tlsdesc_gotents
;
2703 Elf_Internal_Rela
*rel
;
2704 Elf_Internal_Rela
*relend
;
2706 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2708 htab
= elf64_x86_64_hash_table (info
);
2709 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2710 sym_hashes
= elf_sym_hashes (input_bfd
);
2711 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2712 local_tlsdesc_gotents
= elf64_x86_64_local_tlsdesc_gotent (input_bfd
);
2714 elf64_x86_64_set_tls_module_base (info
);
2717 relend
= relocs
+ input_section
->reloc_count
;
2718 for (; rel
< relend
; rel
++)
2720 unsigned int r_type
;
2721 reloc_howto_type
*howto
;
2722 unsigned long r_symndx
;
2723 struct elf_link_hash_entry
*h
;
2724 Elf_Internal_Sym
*sym
;
2726 bfd_vma off
, offplt
;
2728 bfd_boolean unresolved_reloc
;
2729 bfd_reloc_status_type r
;
2733 r_type
= ELF64_R_TYPE (rel
->r_info
);
2734 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2735 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2738 if (r_type
>= R_X86_64_max
)
2740 bfd_set_error (bfd_error_bad_value
);
2744 howto
= x86_64_elf_howto_table
+ r_type
;
2745 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2749 unresolved_reloc
= FALSE
;
2750 if (r_symndx
< symtab_hdr
->sh_info
)
2752 sym
= local_syms
+ r_symndx
;
2753 sec
= local_sections
[r_symndx
];
2755 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2758 /* Relocate against local STT_GNU_IFUNC symbol. */
2759 if (ELF64_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2761 h
= elf64_x86_64_get_local_sym_hash (htab
, input_bfd
,
2766 /* Set STT_GNU_IFUNC symbol value. */
2767 h
->root
.u
.def
.value
= sym
->st_value
;
2768 h
->root
.u
.def
.section
= sec
;
2775 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2776 r_symndx
, symtab_hdr
, sym_hashes
,
2778 unresolved_reloc
, warned
);
2781 if (sec
!= NULL
&& elf_discarded_section (sec
))
2783 /* For relocs against symbols from removed linkonce sections,
2784 or sections discarded by a linker script, we just want the
2785 section contents zeroed. Avoid any special processing. */
2786 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2792 if (info
->relocatable
)
2795 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2796 it here if it is defined in a non-shared object. */
2798 && h
->type
== STT_GNU_IFUNC
2804 if ((input_section
->flags
& SEC_ALLOC
) == 0
2805 || h
->plt
.offset
== (bfd_vma
) -1)
2808 /* STT_GNU_IFUNC symbol must go through PLT. */
2809 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
2810 relocation
= (plt
->output_section
->vma
2811 + plt
->output_offset
+ h
->plt
.offset
);
2816 (*_bfd_error_handler
)
2817 (_("%B: relocation %s against STT_GNU_IFUNC "
2818 "symbol `%s' isn't handled by %s"), input_bfd
,
2819 x86_64_elf_howto_table
[r_type
].name
,
2820 (h
->root
.root
.string
2821 ? h
->root
.root
.string
: "a local symbol"),
2823 bfd_set_error (bfd_error_bad_value
);
2832 if (rel
->r_addend
!= 0)
2834 (*_bfd_error_handler
)
2835 (_("%B: relocation %s against STT_GNU_IFUNC "
2836 "symbol `%s' has non-zero addend: %d"),
2837 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
2838 (h
->root
.root
.string
2839 ? h
->root
.root
.string
: "a local symbol"),
2841 bfd_set_error (bfd_error_bad_value
);
2845 /* Generate dynamic relcoation only when there is a
2846 non-GOF reference in a shared object. */
2847 if (info
->shared
&& h
->non_got_ref
)
2849 Elf_Internal_Rela outrel
;
2853 /* Need a dynamic relocation to get the real function
2855 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2859 if (outrel
.r_offset
== (bfd_vma
) -1
2860 || outrel
.r_offset
== (bfd_vma
) -2)
2863 outrel
.r_offset
+= (input_section
->output_section
->vma
2864 + input_section
->output_offset
);
2866 if (h
->dynindx
== -1
2868 || info
->executable
)
2870 /* This symbol is resolved locally. */
2871 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_IRELATIVE
);
2872 outrel
.r_addend
= (h
->root
.u
.def
.value
2873 + h
->root
.u
.def
.section
->output_section
->vma
2874 + h
->root
.u
.def
.section
->output_offset
);
2878 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2879 outrel
.r_addend
= 0;
2882 sreloc
= htab
->elf
.irelifunc
;
2883 loc
= sreloc
->contents
;
2884 loc
+= (sreloc
->reloc_count
++
2885 * sizeof (Elf64_External_Rela
));
2886 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2888 /* If this reloc is against an external symbol, we
2889 do not want to fiddle with the addend. Otherwise,
2890 we need to include the symbol value so that it
2891 becomes an addend for the dynamic reloc. For an
2892 internal symbol, we have updated addend. */
2899 case R_X86_64_PLT32
:
2902 case R_X86_64_GOTPCREL
:
2903 case R_X86_64_GOTPCREL64
:
2904 base_got
= htab
->elf
.sgot
;
2905 off
= h
->got
.offset
;
2907 if (base_got
== NULL
)
2910 if (off
== (bfd_vma
) -1)
2912 /* We can't use h->got.offset here to save state, or
2913 even just remember the offset, as finish_dynamic_symbol
2914 would use that as offset into .got. */
2916 if (htab
->elf
.splt
!= NULL
)
2918 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2919 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2920 base_got
= htab
->elf
.sgotplt
;
2924 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
2925 off
= plt_index
* GOT_ENTRY_SIZE
;
2926 base_got
= htab
->elf
.igotplt
;
2929 if (h
->dynindx
== -1
2933 /* This references the local defitionion. We must
2934 initialize this entry in the global offset table.
2935 Since the offset must always be a multiple of 8,
2936 we use the least significant bit to record
2937 whether we have initialized it already.
2939 When doing a dynamic link, we create a .rela.got
2940 relocation entry to initialize the value. This
2941 is done in the finish_dynamic_symbol routine. */
2946 bfd_put_64 (output_bfd
, relocation
,
2947 base_got
->contents
+ off
);
2948 /* Note that this is harmless for the GOTPLT64
2949 case, as -1 | 1 still is -1. */
2955 relocation
= (base_got
->output_section
->vma
2956 + base_got
->output_offset
+ off
);
2958 if (r_type
!= R_X86_64_GOTPCREL
2959 && r_type
!= R_X86_64_GOTPCREL64
)
2962 if (htab
->elf
.splt
!= NULL
)
2963 gotplt
= htab
->elf
.sgotplt
;
2965 gotplt
= htab
->elf
.igotplt
;
2966 relocation
-= (gotplt
->output_section
->vma
2967 - gotplt
->output_offset
);
2974 /* When generating a shared object, the relocations handled here are
2975 copied into the output file to be resolved at run time. */
2978 case R_X86_64_GOT32
:
2979 case R_X86_64_GOT64
:
2980 /* Relocation is to the entry for this symbol in the global
2982 case R_X86_64_GOTPCREL
:
2983 case R_X86_64_GOTPCREL64
:
2984 /* Use global offset table entry as symbol value. */
2985 case R_X86_64_GOTPLT64
:
2986 /* This is the same as GOT64 for relocation purposes, but
2987 indicates the existence of a PLT entry. The difficulty is,
2988 that we must calculate the GOT slot offset from the PLT
2989 offset, if this symbol got a PLT entry (it was global).
2990 Additionally if it's computed from the PLT entry, then that
2991 GOT offset is relative to .got.plt, not to .got. */
2992 base_got
= htab
->elf
.sgot
;
2994 if (htab
->elf
.sgot
== NULL
)
3001 off
= h
->got
.offset
;
3003 && h
->plt
.offset
!= (bfd_vma
)-1
3004 && off
== (bfd_vma
)-1)
3006 /* We can't use h->got.offset here to save
3007 state, or even just remember the offset, as
3008 finish_dynamic_symbol would use that as offset into
3010 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3011 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3012 base_got
= htab
->elf
.sgotplt
;
3015 dyn
= htab
->elf
.dynamic_sections_created
;
3017 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3019 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3020 || (ELF_ST_VISIBILITY (h
->other
)
3021 && h
->root
.type
== bfd_link_hash_undefweak
))
3023 /* This is actually a static link, or it is a -Bsymbolic
3024 link and the symbol is defined locally, or the symbol
3025 was forced to be local because of a version file. We
3026 must initialize this entry in the global offset table.
3027 Since the offset must always be a multiple of 8, we
3028 use the least significant bit to record whether we
3029 have initialized it already.
3031 When doing a dynamic link, we create a .rela.got
3032 relocation entry to initialize the value. This is
3033 done in the finish_dynamic_symbol routine. */
3038 bfd_put_64 (output_bfd
, relocation
,
3039 base_got
->contents
+ off
);
3040 /* Note that this is harmless for the GOTPLT64 case,
3041 as -1 | 1 still is -1. */
3046 unresolved_reloc
= FALSE
;
3050 if (local_got_offsets
== NULL
)
3053 off
= local_got_offsets
[r_symndx
];
3055 /* The offset must always be a multiple of 8. We use
3056 the least significant bit to record whether we have
3057 already generated the necessary reloc. */
3062 bfd_put_64 (output_bfd
, relocation
,
3063 base_got
->contents
+ off
);
3068 Elf_Internal_Rela outrel
;
3071 /* We need to generate a R_X86_64_RELATIVE reloc
3072 for the dynamic linker. */
3073 s
= htab
->elf
.srelgot
;
3077 outrel
.r_offset
= (base_got
->output_section
->vma
3078 + base_got
->output_offset
3080 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3081 outrel
.r_addend
= relocation
;
3083 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3084 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3087 local_got_offsets
[r_symndx
] |= 1;
3091 if (off
>= (bfd_vma
) -2)
3094 relocation
= base_got
->output_section
->vma
3095 + base_got
->output_offset
+ off
;
3096 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3097 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3098 - htab
->elf
.sgotplt
->output_offset
;
3102 case R_X86_64_GOTOFF64
:
3103 /* Relocation is relative to the start of the global offset
3106 /* Check to make sure it isn't a protected function symbol
3107 for shared library since it may not be local when used
3108 as function address. */
3112 && h
->type
== STT_FUNC
3113 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3115 (*_bfd_error_handler
)
3116 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3117 input_bfd
, h
->root
.root
.string
);
3118 bfd_set_error (bfd_error_bad_value
);
3122 /* Note that sgot is not involved in this
3123 calculation. We always want the start of .got.plt. If we
3124 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3125 permitted by the ABI, we might have to change this
3127 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3128 + htab
->elf
.sgotplt
->output_offset
;
3131 case R_X86_64_GOTPC32
:
3132 case R_X86_64_GOTPC64
:
3133 /* Use global offset table as symbol value. */
3134 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3135 + htab
->elf
.sgotplt
->output_offset
;
3136 unresolved_reloc
= FALSE
;
3139 case R_X86_64_PLTOFF64
:
3140 /* Relocation is PLT entry relative to GOT. For local
3141 symbols it's the symbol itself relative to GOT. */
3143 /* See PLT32 handling. */
3144 && h
->plt
.offset
!= (bfd_vma
) -1
3145 && htab
->elf
.splt
!= NULL
)
3147 relocation
= (htab
->elf
.splt
->output_section
->vma
3148 + htab
->elf
.splt
->output_offset
3150 unresolved_reloc
= FALSE
;
3153 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3154 + htab
->elf
.sgotplt
->output_offset
;
3157 case R_X86_64_PLT32
:
3158 /* Relocation is to the entry for this symbol in the
3159 procedure linkage table. */
3161 /* Resolve a PLT32 reloc against a local symbol directly,
3162 without using the procedure linkage table. */
3166 if (h
->plt
.offset
== (bfd_vma
) -1
3167 || htab
->elf
.splt
== NULL
)
3169 /* We didn't make a PLT entry for this symbol. This
3170 happens when statically linking PIC code, or when
3171 using -Bsymbolic. */
3175 relocation
= (htab
->elf
.splt
->output_section
->vma
3176 + htab
->elf
.splt
->output_offset
3178 unresolved_reloc
= FALSE
;
3185 && (input_section
->flags
& SEC_ALLOC
) != 0
3186 && (input_section
->flags
& SEC_READONLY
) != 0
3189 bfd_boolean fail
= FALSE
;
3191 = (r_type
== R_X86_64_PC32
3192 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3194 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3196 /* Symbol is referenced locally. Make sure it is
3197 defined locally or for a branch. */
3198 fail
= !h
->def_regular
&& !branch
;
3202 /* Symbol isn't referenced locally. We only allow
3203 branch to symbol with non-default visibility. */
3205 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3212 const char *pic
= "";
3214 switch (ELF_ST_VISIBILITY (h
->other
))
3217 v
= _("hidden symbol");
3220 v
= _("internal symbol");
3223 v
= _("protected symbol");
3227 pic
= _("; recompile with -fPIC");
3232 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3234 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3236 (*_bfd_error_handler
) (fmt
, input_bfd
,
3237 x86_64_elf_howto_table
[r_type
].name
,
3238 v
, h
->root
.root
.string
, pic
);
3239 bfd_set_error (bfd_error_bad_value
);
3250 /* FIXME: The ABI says the linker should make sure the value is
3251 the same when it's zeroextended to 64 bit. */
3253 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3258 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3259 || h
->root
.type
!= bfd_link_hash_undefweak
)
3260 && (! IS_X86_64_PCREL_TYPE (r_type
)
3261 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3262 || (ELIMINATE_COPY_RELOCS
3269 || h
->root
.type
== bfd_link_hash_undefweak
3270 || h
->root
.type
== bfd_link_hash_undefined
)))
3272 Elf_Internal_Rela outrel
;
3274 bfd_boolean skip
, relocate
;
3277 /* When generating a shared object, these relocations
3278 are copied into the output file to be resolved at run
3284 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3286 if (outrel
.r_offset
== (bfd_vma
) -1)
3288 else if (outrel
.r_offset
== (bfd_vma
) -2)
3289 skip
= TRUE
, relocate
= TRUE
;
3291 outrel
.r_offset
+= (input_section
->output_section
->vma
3292 + input_section
->output_offset
);
3295 memset (&outrel
, 0, sizeof outrel
);
3297 /* h->dynindx may be -1 if this symbol was marked to
3301 && (IS_X86_64_PCREL_TYPE (r_type
)
3303 || ! SYMBOLIC_BIND (info
, h
)
3304 || ! h
->def_regular
))
3306 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3307 outrel
.r_addend
= rel
->r_addend
;
3311 /* This symbol is local, or marked to become local. */
3312 if (r_type
== R_X86_64_64
)
3315 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3316 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3322 if (bfd_is_abs_section (sec
))
3324 else if (sec
== NULL
|| sec
->owner
== NULL
)
3326 bfd_set_error (bfd_error_bad_value
);
3333 /* We are turning this relocation into one
3334 against a section symbol. It would be
3335 proper to subtract the symbol's value,
3336 osec->vma, from the emitted reloc addend,
3337 but ld.so expects buggy relocs. */
3338 osec
= sec
->output_section
;
3339 sindx
= elf_section_data (osec
)->dynindx
;
3342 asection
*oi
= htab
->elf
.text_index_section
;
3343 sindx
= elf_section_data (oi
)->dynindx
;
3345 BFD_ASSERT (sindx
!= 0);
3348 outrel
.r_info
= ELF64_R_INFO (sindx
, r_type
);
3349 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3353 sreloc
= elf_section_data (input_section
)->sreloc
;
3355 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3357 loc
= sreloc
->contents
;
3358 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3359 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3361 /* If this reloc is against an external symbol, we do
3362 not want to fiddle with the addend. Otherwise, we
3363 need to include the symbol value so that it becomes
3364 an addend for the dynamic reloc. */
3371 case R_X86_64_TLSGD
:
3372 case R_X86_64_GOTPC32_TLSDESC
:
3373 case R_X86_64_TLSDESC_CALL
:
3374 case R_X86_64_GOTTPOFF
:
3375 tls_type
= GOT_UNKNOWN
;
3376 if (h
== NULL
&& local_got_offsets
)
3377 tls_type
= elf64_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3379 tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
3381 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3382 input_section
, contents
,
3383 symtab_hdr
, sym_hashes
,
3384 &r_type
, tls_type
, rel
,
3388 if (r_type
== R_X86_64_TPOFF32
)
3390 bfd_vma roff
= rel
->r_offset
;
3392 BFD_ASSERT (! unresolved_reloc
);
3394 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3396 /* GD->LE transition.
3397 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3398 .word 0x6666; rex64; call __tls_get_addr
3401 leaq foo@tpoff(%rax), %rax */
3402 memcpy (contents
+ roff
- 4,
3403 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3405 bfd_put_32 (output_bfd
,
3406 elf64_x86_64_tpoff (info
, relocation
),
3407 contents
+ roff
+ 8);
3408 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3412 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3414 /* GDesc -> LE transition.
3415 It's originally something like:
3416 leaq x@tlsdesc(%rip), %rax
3422 unsigned int val
, type
, type2
;
3424 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3425 type2
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3426 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3427 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3428 contents
+ roff
- 3);
3429 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3430 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3431 contents
+ roff
- 1);
3432 bfd_put_32 (output_bfd
,
3433 elf64_x86_64_tpoff (info
, relocation
),
3437 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3439 /* GDesc -> LE transition.
3444 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3445 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3448 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3450 /* IE->LE transition:
3451 Originally it can be one of:
3452 movq foo@gottpoff(%rip), %reg
3453 addq foo@gottpoff(%rip), %reg
3456 leaq foo(%reg), %reg
3459 unsigned int val
, type
, reg
;
3461 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3462 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3463 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3469 bfd_put_8 (output_bfd
, 0x49,
3470 contents
+ roff
- 3);
3471 bfd_put_8 (output_bfd
, 0xc7,
3472 contents
+ roff
- 2);
3473 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3474 contents
+ roff
- 1);
3478 /* addq -> addq - addressing with %rsp/%r12 is
3481 bfd_put_8 (output_bfd
, 0x49,
3482 contents
+ roff
- 3);
3483 bfd_put_8 (output_bfd
, 0x81,
3484 contents
+ roff
- 2);
3485 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3486 contents
+ roff
- 1);
3492 bfd_put_8 (output_bfd
, 0x4d,
3493 contents
+ roff
- 3);
3494 bfd_put_8 (output_bfd
, 0x8d,
3495 contents
+ roff
- 2);
3496 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3497 contents
+ roff
- 1);
3499 bfd_put_32 (output_bfd
,
3500 elf64_x86_64_tpoff (info
, relocation
),
3508 if (htab
->elf
.sgot
== NULL
)
3513 off
= h
->got
.offset
;
3514 offplt
= elf64_x86_64_hash_entry (h
)->tlsdesc_got
;
3518 if (local_got_offsets
== NULL
)
3521 off
= local_got_offsets
[r_symndx
];
3522 offplt
= local_tlsdesc_gotents
[r_symndx
];
3529 Elf_Internal_Rela outrel
;
3534 if (htab
->elf
.srelgot
== NULL
)
3537 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3539 if (GOT_TLS_GDESC_P (tls_type
))
3541 outrel
.r_info
= ELF64_R_INFO (indx
, R_X86_64_TLSDESC
);
3542 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3543 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3544 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3545 + htab
->elf
.sgotplt
->output_offset
3547 + htab
->sgotplt_jump_table_size
);
3548 sreloc
= htab
->elf
.srelplt
;
3549 loc
= sreloc
->contents
;
3550 loc
+= sreloc
->reloc_count
++
3551 * sizeof (Elf64_External_Rela
);
3552 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3553 <= sreloc
->contents
+ sreloc
->size
);
3555 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3557 outrel
.r_addend
= 0;
3558 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3561 sreloc
= htab
->elf
.srelgot
;
3563 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3564 + htab
->elf
.sgot
->output_offset
+ off
);
3566 if (GOT_TLS_GD_P (tls_type
))
3567 dr_type
= R_X86_64_DTPMOD64
;
3568 else if (GOT_TLS_GDESC_P (tls_type
))
3571 dr_type
= R_X86_64_TPOFF64
;
3573 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3574 outrel
.r_addend
= 0;
3575 if ((dr_type
== R_X86_64_TPOFF64
3576 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3577 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3578 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
3580 loc
= sreloc
->contents
;
3581 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3582 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3583 <= sreloc
->contents
+ sreloc
->size
);
3584 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3586 if (GOT_TLS_GD_P (tls_type
))
3590 BFD_ASSERT (! unresolved_reloc
);
3591 bfd_put_64 (output_bfd
,
3592 relocation
- elf64_x86_64_dtpoff_base (info
),
3593 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3597 bfd_put_64 (output_bfd
, 0,
3598 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3599 outrel
.r_info
= ELF64_R_INFO (indx
,
3601 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3602 sreloc
->reloc_count
++;
3603 loc
+= sizeof (Elf64_External_Rela
);
3604 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3605 <= sreloc
->contents
+ sreloc
->size
);
3606 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3614 local_got_offsets
[r_symndx
] |= 1;
3617 if (off
>= (bfd_vma
) -2
3618 && ! GOT_TLS_GDESC_P (tls_type
))
3620 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
3622 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3623 || r_type
== R_X86_64_TLSDESC_CALL
)
3624 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3625 + htab
->elf
.sgotplt
->output_offset
3626 + offplt
+ htab
->sgotplt_jump_table_size
;
3628 relocation
= htab
->elf
.sgot
->output_section
->vma
3629 + htab
->elf
.sgot
->output_offset
+ off
;
3630 unresolved_reloc
= FALSE
;
3634 bfd_vma roff
= rel
->r_offset
;
3636 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3638 /* GD->IE transition.
3639 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3640 .word 0x6666; rex64; call __tls_get_addr@plt
3643 addq foo@gottpoff(%rip), %rax */
3644 memcpy (contents
+ roff
- 4,
3645 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3648 relocation
= (htab
->elf
.sgot
->output_section
->vma
3649 + htab
->elf
.sgot
->output_offset
+ off
3651 - input_section
->output_section
->vma
3652 - input_section
->output_offset
3654 bfd_put_32 (output_bfd
, relocation
,
3655 contents
+ roff
+ 8);
3656 /* Skip R_X86_64_PLT32. */
3660 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3662 /* GDesc -> IE transition.
3663 It's originally something like:
3664 leaq x@tlsdesc(%rip), %rax
3667 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax
3670 unsigned int val
, type
, type2
;
3672 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3673 type2
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3674 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3676 /* Now modify the instruction as appropriate. To
3677 turn a leaq into a movq in the form we use it, it
3678 suffices to change the second byte from 0x8d to
3680 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3682 bfd_put_32 (output_bfd
,
3683 htab
->elf
.sgot
->output_section
->vma
3684 + htab
->elf
.sgot
->output_offset
+ off
3686 - input_section
->output_section
->vma
3687 - input_section
->output_offset
3692 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3694 /* GDesc -> IE transition.
3701 unsigned int val
, type
;
3703 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
3704 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
3705 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3706 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3714 case R_X86_64_TLSLD
:
3715 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3716 input_section
, contents
,
3717 symtab_hdr
, sym_hashes
,
3718 &r_type
, GOT_UNKNOWN
,
3722 if (r_type
!= R_X86_64_TLSLD
)
3724 /* LD->LE transition:
3725 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3727 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3729 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3730 memcpy (contents
+ rel
->r_offset
- 3,
3731 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3732 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3737 if (htab
->elf
.sgot
== NULL
)
3740 off
= htab
->tls_ld_got
.offset
;
3745 Elf_Internal_Rela outrel
;
3748 if (htab
->elf
.srelgot
== NULL
)
3751 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3752 + htab
->elf
.sgot
->output_offset
+ off
);
3754 bfd_put_64 (output_bfd
, 0,
3755 htab
->elf
.sgot
->contents
+ off
);
3756 bfd_put_64 (output_bfd
, 0,
3757 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3758 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_DTPMOD64
);
3759 outrel
.r_addend
= 0;
3760 loc
= htab
->elf
.srelgot
->contents
;
3761 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3762 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3763 htab
->tls_ld_got
.offset
|= 1;
3765 relocation
= htab
->elf
.sgot
->output_section
->vma
3766 + htab
->elf
.sgot
->output_offset
+ off
;
3767 unresolved_reloc
= FALSE
;
3770 case R_X86_64_DTPOFF32
:
3771 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3772 relocation
-= elf64_x86_64_dtpoff_base (info
);
3774 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3777 case R_X86_64_TPOFF32
:
3778 BFD_ASSERT (! info
->shared
);
3779 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3786 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3787 because such sections are not SEC_ALLOC and thus ld.so will
3788 not process them. */
3789 if (unresolved_reloc
3790 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3792 (*_bfd_error_handler
)
3793 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3796 (long) rel
->r_offset
,
3798 h
->root
.root
.string
);
3801 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3802 contents
, rel
->r_offset
,
3803 relocation
, rel
->r_addend
);
3805 if (r
!= bfd_reloc_ok
)
3810 name
= h
->root
.root
.string
;
3813 name
= bfd_elf_string_from_elf_section (input_bfd
,
3814 symtab_hdr
->sh_link
,
3819 name
= bfd_section_name (input_bfd
, sec
);
3822 if (r
== bfd_reloc_overflow
)
3824 if (! ((*info
->callbacks
->reloc_overflow
)
3825 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3826 (bfd_vma
) 0, input_bfd
, input_section
,
3832 (*_bfd_error_handler
)
3833 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3834 input_bfd
, input_section
,
3835 (long) rel
->r_offset
, name
, (int) r
);
3844 /* Finish up dynamic symbol handling. We set the contents of various
3845 dynamic sections here. */
3848 elf64_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3849 struct bfd_link_info
*info
,
3850 struct elf_link_hash_entry
*h
,
3851 Elf_Internal_Sym
*sym
)
3853 struct elf64_x86_64_link_hash_table
*htab
;
3855 htab
= elf64_x86_64_hash_table (info
);
3857 if (h
->plt
.offset
!= (bfd_vma
) -1)
3861 Elf_Internal_Rela rela
;
3863 asection
*plt
, *gotplt
, *relplt
;
3865 /* When building a static executable, use .iplt, .igot.plt and
3866 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3867 if (htab
->elf
.splt
!= NULL
)
3869 plt
= htab
->elf
.splt
;
3870 gotplt
= htab
->elf
.sgotplt
;
3871 relplt
= htab
->elf
.srelplt
;
3875 plt
= htab
->elf
.iplt
;
3876 gotplt
= htab
->elf
.igotplt
;
3877 relplt
= htab
->elf
.irelplt
;
3880 /* This symbol has an entry in the procedure linkage table. Set
3882 if ((h
->dynindx
== -1
3883 && !((h
->forced_local
|| info
->executable
)
3885 && h
->type
== STT_GNU_IFUNC
))
3891 /* Get the index in the procedure linkage table which
3892 corresponds to this symbol. This is the index of this symbol
3893 in all the symbols for which we are making plt entries. The
3894 first entry in the procedure linkage table is reserved.
3896 Get the offset into the .got table of the entry that
3897 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3898 bytes. The first three are reserved for the dynamic linker.
3900 For static executables, we don't reserve anything. */
3902 if (plt
== htab
->elf
.splt
)
3904 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3905 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3909 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3910 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
3913 /* Fill in the entry in the procedure linkage table. */
3914 memcpy (plt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
3917 /* Insert the relocation positions of the plt section. The magic
3918 numbers at the end of the statements are the positions of the
3919 relocations in the plt section. */
3920 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3921 instruction uses 6 bytes, subtract this value. */
3922 bfd_put_32 (output_bfd
,
3923 (gotplt
->output_section
->vma
3924 + gotplt
->output_offset
3926 - plt
->output_section
->vma
3927 - plt
->output_offset
3930 plt
->contents
+ h
->plt
.offset
+ 2);
3932 /* Don't fill PLT entry for static executables. */
3933 if (plt
== htab
->elf
.splt
)
3935 /* Put relocation index. */
3936 bfd_put_32 (output_bfd
, plt_index
,
3937 plt
->contents
+ h
->plt
.offset
+ 7);
3938 /* Put offset for jmp .PLT0. */
3939 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3940 plt
->contents
+ h
->plt
.offset
+ 12);
3943 /* Fill in the entry in the global offset table, initially this
3944 points to the pushq instruction in the PLT which is at offset 6. */
3945 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
3946 + plt
->output_offset
3947 + h
->plt
.offset
+ 6),
3948 gotplt
->contents
+ got_offset
);
3950 /* Fill in the entry in the .rela.plt section. */
3951 rela
.r_offset
= (gotplt
->output_section
->vma
3952 + gotplt
->output_offset
3954 if (h
->dynindx
== -1
3955 || ((info
->executable
3956 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3958 && h
->type
== STT_GNU_IFUNC
))
3960 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3961 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
3962 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_IRELATIVE
);
3963 rela
.r_addend
= (h
->root
.u
.def
.value
3964 + h
->root
.u
.def
.section
->output_section
->vma
3965 + h
->root
.u
.def
.section
->output_offset
);
3969 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
3972 loc
= relplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3973 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3975 if (!h
->def_regular
)
3977 /* Mark the symbol as undefined, rather than as defined in
3978 the .plt section. Leave the value if there were any
3979 relocations where pointer equality matters (this is a clue
3980 for the dynamic linker, to make function pointer
3981 comparisons work between an application and shared
3982 library), otherwise set it to zero. If a function is only
3983 called from a binary, there is no need to slow down
3984 shared libraries because of that. */
3985 sym
->st_shndx
= SHN_UNDEF
;
3986 if (!h
->pointer_equality_needed
)
3991 if (h
->got
.offset
!= (bfd_vma
) -1
3992 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h
)->tls_type
)
3993 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
3995 Elf_Internal_Rela rela
;
3998 /* This symbol has an entry in the global offset table. Set it
4000 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4003 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4004 + htab
->elf
.sgot
->output_offset
4005 + (h
->got
.offset
&~ (bfd_vma
) 1));
4007 /* If this is a static link, or it is a -Bsymbolic link and the
4008 symbol is defined locally or was forced to be local because
4009 of a version file, we just want to emit a RELATIVE reloc.
4010 The entry in the global offset table will already have been
4011 initialized in the relocate_section function. */
4013 && h
->type
== STT_GNU_IFUNC
)
4017 /* Generate R_X86_64_GLOB_DAT. */
4022 if (!h
->pointer_equality_needed
)
4025 /* For non-shared object, we can't use .got.plt, which
4026 contains the real function addres if we need pointer
4027 equality. We load the GOT entry with the PLT entry. */
4028 asection
*plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4029 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4030 + plt
->output_offset
4032 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4036 else if (info
->shared
4037 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4039 if (!h
->def_regular
)
4041 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4042 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
4043 rela
.r_addend
= (h
->root
.u
.def
.value
4044 + h
->root
.u
.def
.section
->output_section
->vma
4045 + h
->root
.u
.def
.section
->output_offset
);
4049 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4051 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4052 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4053 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
4057 loc
= htab
->elf
.srelgot
->contents
;
4058 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4059 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4064 Elf_Internal_Rela rela
;
4067 /* This symbol needs a copy reloc. Set it up. */
4069 if (h
->dynindx
== -1
4070 || (h
->root
.type
!= bfd_link_hash_defined
4071 && h
->root
.type
!= bfd_link_hash_defweak
)
4072 || htab
->srelbss
== NULL
)
4075 rela
.r_offset
= (h
->root
.u
.def
.value
4076 + h
->root
.u
.def
.section
->output_section
->vma
4077 + h
->root
.u
.def
.section
->output_offset
);
4078 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
4080 loc
= htab
->srelbss
->contents
;
4081 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4082 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4085 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4086 be NULL for local symbols. */
4088 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4089 || h
== htab
->elf
.hgot
))
4090 sym
->st_shndx
= SHN_ABS
;
4095 /* Finish up local dynamic symbol handling. We set the contents of
4096 various dynamic sections here. */
4099 elf64_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4101 struct elf_link_hash_entry
*h
4102 = (struct elf_link_hash_entry
*) *slot
;
4103 struct bfd_link_info
*info
4104 = (struct bfd_link_info
*) inf
;
4106 return elf64_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4110 /* Used to decide how to sort relocs in an optimal manner for the
4111 dynamic linker, before writing them out. */
4113 static enum elf_reloc_type_class
4114 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4116 switch ((int) ELF64_R_TYPE (rela
->r_info
))
4118 case R_X86_64_RELATIVE
:
4119 return reloc_class_relative
;
4120 case R_X86_64_JUMP_SLOT
:
4121 return reloc_class_plt
;
4123 return reloc_class_copy
;
4125 return reloc_class_normal
;
4129 /* Finish up the dynamic sections. */
4132 elf64_x86_64_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
4134 struct elf64_x86_64_link_hash_table
*htab
;
4138 htab
= elf64_x86_64_hash_table (info
);
4139 dynobj
= htab
->elf
.dynobj
;
4140 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4142 if (htab
->elf
.dynamic_sections_created
)
4144 Elf64_External_Dyn
*dyncon
, *dynconend
;
4146 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4149 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4150 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4151 for (; dyncon
< dynconend
; dyncon
++)
4153 Elf_Internal_Dyn dyn
;
4156 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4164 s
= htab
->elf
.sgotplt
;
4165 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4169 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4173 s
= htab
->elf
.srelplt
->output_section
;
4174 dyn
.d_un
.d_val
= s
->size
;
4178 /* The procedure linkage table relocs (DT_JMPREL) should
4179 not be included in the overall relocs (DT_RELA).
4180 Therefore, we override the DT_RELASZ entry here to
4181 make it not include the JMPREL relocs. Since the
4182 linker script arranges for .rela.plt to follow all
4183 other relocation sections, we don't have to worry
4184 about changing the DT_RELA entry. */
4185 if (htab
->elf
.srelplt
!= NULL
)
4187 s
= htab
->elf
.srelplt
->output_section
;
4188 dyn
.d_un
.d_val
-= s
->size
;
4192 case DT_TLSDESC_PLT
:
4194 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4195 + htab
->tlsdesc_plt
;
4198 case DT_TLSDESC_GOT
:
4200 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4201 + htab
->tlsdesc_got
;
4205 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4208 /* Fill in the special first entry in the procedure linkage table. */
4209 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4211 /* Fill in the first entry in the procedure linkage table. */
4212 memcpy (htab
->elf
.splt
->contents
, elf64_x86_64_plt0_entry
,
4214 /* Add offset for pushq GOT+8(%rip), since the instruction
4215 uses 6 bytes subtract this value. */
4216 bfd_put_32 (output_bfd
,
4217 (htab
->elf
.sgotplt
->output_section
->vma
4218 + htab
->elf
.sgotplt
->output_offset
4220 - htab
->elf
.splt
->output_section
->vma
4221 - htab
->elf
.splt
->output_offset
4223 htab
->elf
.splt
->contents
+ 2);
4224 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4225 the end of the instruction. */
4226 bfd_put_32 (output_bfd
,
4227 (htab
->elf
.sgotplt
->output_section
->vma
4228 + htab
->elf
.sgotplt
->output_offset
4230 - htab
->elf
.splt
->output_section
->vma
4231 - htab
->elf
.splt
->output_offset
4233 htab
->elf
.splt
->contents
+ 8);
4235 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
=
4238 if (htab
->tlsdesc_plt
)
4240 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4241 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4243 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4244 elf64_x86_64_plt0_entry
,
4247 /* Add offset for pushq GOT+8(%rip), since the
4248 instruction uses 6 bytes subtract this value. */
4249 bfd_put_32 (output_bfd
,
4250 (htab
->elf
.sgotplt
->output_section
->vma
4251 + htab
->elf
.sgotplt
->output_offset
4253 - htab
->elf
.splt
->output_section
->vma
4254 - htab
->elf
.splt
->output_offset
4257 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 2);
4258 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4259 htab->tlsdesc_got. The 12 is the offset to the end of
4261 bfd_put_32 (output_bfd
,
4262 (htab
->elf
.sgot
->output_section
->vma
4263 + htab
->elf
.sgot
->output_offset
4265 - htab
->elf
.splt
->output_section
->vma
4266 - htab
->elf
.splt
->output_offset
4269 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
4274 if (htab
->elf
.sgotplt
)
4276 /* Fill in the first three entries in the global offset table. */
4277 if (htab
->elf
.sgotplt
->size
> 0)
4279 /* Set the first entry in the global offset table to the address of
4280 the dynamic section. */
4282 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4284 bfd_put_64 (output_bfd
,
4285 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4286 htab
->elf
.sgotplt
->contents
);
4287 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4288 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4289 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4292 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4296 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4297 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4300 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4301 htab_traverse (htab
->loc_hash_table
,
4302 elf64_x86_64_finish_local_dynamic_symbol
,
4308 /* Return address for Ith PLT stub in section PLT, for relocation REL
4309 or (bfd_vma) -1 if it should not be included. */
4312 elf64_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4313 const arelent
*rel ATTRIBUTE_UNUSED
)
4315 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4318 /* Handle an x86-64 specific section when reading an object file. This
4319 is called when elfcode.h finds a section with an unknown type. */
4322 elf64_x86_64_section_from_shdr (bfd
*abfd
,
4323 Elf_Internal_Shdr
*hdr
,
4327 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4330 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4336 /* Hook called by the linker routine which adds symbols from an object
4337 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4341 elf64_x86_64_add_symbol_hook (bfd
*abfd
,
4342 struct bfd_link_info
*info
,
4343 Elf_Internal_Sym
*sym
,
4344 const char **namep ATTRIBUTE_UNUSED
,
4345 flagword
*flagsp ATTRIBUTE_UNUSED
,
4351 switch (sym
->st_shndx
)
4353 case SHN_X86_64_LCOMMON
:
4354 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4357 lcomm
= bfd_make_section_with_flags (abfd
,
4361 | SEC_LINKER_CREATED
));
4364 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4367 *valp
= sym
->st_size
;
4371 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4372 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4378 /* Given a BFD section, try to locate the corresponding ELF section
4382 elf64_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4383 asection
*sec
, int *index
)
4385 if (sec
== &_bfd_elf_large_com_section
)
4387 *index
= SHN_X86_64_LCOMMON
;
4393 /* Process a symbol. */
4396 elf64_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4399 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4401 switch (elfsym
->internal_elf_sym
.st_shndx
)
4403 case SHN_X86_64_LCOMMON
:
4404 asym
->section
= &_bfd_elf_large_com_section
;
4405 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4406 /* Common symbol doesn't set BSF_GLOBAL. */
4407 asym
->flags
&= ~BSF_GLOBAL
;
4413 elf64_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4415 return (sym
->st_shndx
== SHN_COMMON
4416 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4420 elf64_x86_64_common_section_index (asection
*sec
)
4422 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4425 return SHN_X86_64_LCOMMON
;
4429 elf64_x86_64_common_section (asection
*sec
)
4431 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4432 return bfd_com_section_ptr
;
4434 return &_bfd_elf_large_com_section
;
4438 elf64_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4439 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4440 struct elf_link_hash_entry
*h
,
4441 Elf_Internal_Sym
*sym
,
4443 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4444 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4445 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4446 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4447 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4448 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4449 bfd_boolean
*newdef ATTRIBUTE_UNUSED
,
4450 bfd_boolean
*newdyn
,
4451 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4452 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4453 bfd
*abfd ATTRIBUTE_UNUSED
,
4455 bfd_boolean
*olddef ATTRIBUTE_UNUSED
,
4456 bfd_boolean
*olddyn
,
4457 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4458 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4462 /* A normal common symbol and a large common symbol result in a
4463 normal common symbol. We turn the large common symbol into a
4466 && h
->root
.type
== bfd_link_hash_common
4468 && bfd_is_com_section (*sec
)
4471 if (sym
->st_shndx
== SHN_COMMON
4472 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4474 h
->root
.u
.c
.p
->section
4475 = bfd_make_section_old_way (oldbfd
, "COMMON");
4476 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4478 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4479 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4480 *psec
= *sec
= bfd_com_section_ptr
;
4487 elf64_x86_64_additional_program_headers (bfd
*abfd
,
4488 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4493 /* Check to see if we need a large readonly segment. */
4494 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4495 if (s
&& (s
->flags
& SEC_LOAD
))
4498 /* Check to see if we need a large data segment. Since .lbss sections
4499 is placed right after the .bss section, there should be no need for
4500 a large data segment just because of .lbss. */
4501 s
= bfd_get_section_by_name (abfd
, ".ldata");
4502 if (s
&& (s
->flags
& SEC_LOAD
))
4508 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4511 elf64_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4513 if (h
->plt
.offset
!= (bfd_vma
) -1
4515 && !h
->pointer_equality_needed
)
4518 return _bfd_elf_hash_symbol (h
);
4521 static const struct bfd_elf_special_section
4522 elf64_x86_64_special_sections
[]=
4524 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4525 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4526 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4527 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4528 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4529 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4530 { NULL
, 0, 0, 0, 0 }
4533 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4534 #define TARGET_LITTLE_NAME "elf64-x86-64"
4535 #define ELF_ARCH bfd_arch_i386
4536 #define ELF_MACHINE_CODE EM_X86_64
4537 #define ELF_MAXPAGESIZE 0x200000
4538 #define ELF_MINPAGESIZE 0x1000
4539 #define ELF_COMMONPAGESIZE 0x1000
4541 #define elf_backend_can_gc_sections 1
4542 #define elf_backend_can_refcount 1
4543 #define elf_backend_want_got_plt 1
4544 #define elf_backend_plt_readonly 1
4545 #define elf_backend_want_plt_sym 0
4546 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4547 #define elf_backend_rela_normal 1
4549 #define elf_info_to_howto elf64_x86_64_info_to_howto
4551 #define bfd_elf64_bfd_link_hash_table_create \
4552 elf64_x86_64_link_hash_table_create
4553 #define bfd_elf64_bfd_link_hash_table_free \
4554 elf64_x86_64_link_hash_table_free
4555 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
4556 #define bfd_elf64_bfd_reloc_name_lookup \
4557 elf64_x86_64_reloc_name_lookup
4559 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
4560 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4561 #define elf_backend_check_relocs elf64_x86_64_check_relocs
4562 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
4563 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
4564 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
4565 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
4566 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
4567 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
4568 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
4569 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
4570 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
4571 #define elf_backend_relocate_section elf64_x86_64_relocate_section
4572 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
4573 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
4574 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4575 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
4576 #define elf_backend_object_p elf64_x86_64_elf_object_p
4577 #define bfd_elf64_mkobject elf64_x86_64_mkobject
4579 #define elf_backend_section_from_shdr \
4580 elf64_x86_64_section_from_shdr
4582 #define elf_backend_section_from_bfd_section \
4583 elf64_x86_64_elf_section_from_bfd_section
4584 #define elf_backend_add_symbol_hook \
4585 elf64_x86_64_add_symbol_hook
4586 #define elf_backend_symbol_processing \
4587 elf64_x86_64_symbol_processing
4588 #define elf_backend_common_section_index \
4589 elf64_x86_64_common_section_index
4590 #define elf_backend_common_section \
4591 elf64_x86_64_common_section
4592 #define elf_backend_common_definition \
4593 elf64_x86_64_common_definition
4594 #define elf_backend_merge_symbol \
4595 elf64_x86_64_merge_symbol
4596 #define elf_backend_special_sections \
4597 elf64_x86_64_special_sections
4598 #define elf_backend_additional_program_headers \
4599 elf64_x86_64_additional_program_headers
4600 #define elf_backend_hash_symbol \
4601 elf64_x86_64_hash_symbol
4603 #undef elf_backend_post_process_headers
4604 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4606 #include "elf64-target.h"
4608 /* FreeBSD support. */
4610 #undef TARGET_LITTLE_SYM
4611 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4612 #undef TARGET_LITTLE_NAME
4613 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4616 #define ELF_OSABI ELFOSABI_FREEBSD
4619 #define elf64_bed elf64_x86_64_fbsd_bed
4621 #include "elf64-target.h"