1 /* X86-64 specific support for ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Jan Hubicka <jh@suse.cz>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "bfd_stdint.h"
33 #include "elf/x86-64.h"
35 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
36 #define MINUS_ONE (~ (bfd_vma) 0)
38 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
39 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
40 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
41 since they are the same. */
43 #define ABI_64_P(abfd) \
44 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
46 /* The relocation "howto" table. Order of fields:
47 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
48 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
49 static reloc_howto_type x86_64_elf_howto_table
[] =
51 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
52 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
54 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
55 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
57 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
58 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
61 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
63 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
64 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
66 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
69 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
72 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
73 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
75 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
76 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
78 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
79 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
81 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
82 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
84 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
85 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
87 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
89 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
91 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
92 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
93 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
94 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
95 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
98 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
101 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
102 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
104 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
105 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
107 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
108 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
110 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
113 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
114 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
116 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
117 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
119 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
122 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
123 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
124 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
125 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
126 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
127 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
128 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
129 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
131 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
132 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
134 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
135 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
136 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
137 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
138 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
140 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
141 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
145 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
146 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
147 "R_X86_64_GOTPC32_TLSDESC",
148 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
149 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
150 complain_overflow_dont
, bfd_elf_generic_reloc
,
151 "R_X86_64_TLSDESC_CALL",
153 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
154 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
156 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
157 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
158 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
161 /* We have a gap in the reloc numbers here.
162 R_X86_64_standard counts the number up to this point, and
163 R_X86_64_vt_offset is the value to subtract from a reloc type of
164 R_X86_64_GNU_VT* to form an index into this table. */
165 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
166 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
168 /* GNU extension to record C++ vtable hierarchy. */
169 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
170 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
172 /* GNU extension to record C++ vtable member usage. */
173 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
174 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
178 #define IS_X86_64_PCREL_TYPE(TYPE) \
179 ( ((TYPE) == R_X86_64_PC8) \
180 || ((TYPE) == R_X86_64_PC16) \
181 || ((TYPE) == R_X86_64_PC32) \
182 || ((TYPE) == R_X86_64_PC64))
184 /* Map BFD relocs to the x86_64 elf relocs. */
187 bfd_reloc_code_real_type bfd_reloc_val
;
188 unsigned char elf_reloc_val
;
191 static const struct elf_reloc_map x86_64_reloc_map
[] =
193 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
194 { BFD_RELOC_64
, R_X86_64_64
, },
195 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
196 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
197 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
198 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
199 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
200 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
201 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
202 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
203 { BFD_RELOC_32
, R_X86_64_32
, },
204 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
205 { BFD_RELOC_16
, R_X86_64_16
, },
206 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
207 { BFD_RELOC_8
, R_X86_64_8
, },
208 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
209 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
210 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
211 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
212 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
213 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
214 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
215 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
216 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
217 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
218 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
219 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
220 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
221 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
222 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
223 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
224 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
225 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
226 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
227 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
228 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
229 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
230 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
233 static reloc_howto_type
*
234 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
238 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
239 || r_type
>= (unsigned int) R_X86_64_max
)
241 if (r_type
>= (unsigned int) R_X86_64_standard
)
243 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
245 r_type
= R_X86_64_NONE
;
250 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
251 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
252 return &x86_64_elf_howto_table
[i
];
255 /* Given a BFD reloc type, return a HOWTO structure. */
256 static reloc_howto_type
*
257 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
258 bfd_reloc_code_real_type code
)
262 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
265 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
266 return elf_x86_64_rtype_to_howto (abfd
,
267 x86_64_reloc_map
[i
].elf_reloc_val
);
272 static reloc_howto_type
*
273 elf_x86_64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
279 i
< (sizeof (x86_64_elf_howto_table
)
280 / sizeof (x86_64_elf_howto_table
[0]));
282 if (x86_64_elf_howto_table
[i
].name
!= NULL
283 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
284 return &x86_64_elf_howto_table
[i
];
289 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
292 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
293 Elf_Internal_Rela
*dst
)
297 r_type
= ELF32_R_TYPE (dst
->r_info
);
298 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
299 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
302 /* Support for core dump NOTE sections. */
304 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
309 switch (note
->descsz
)
314 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
316 elf_tdata (abfd
)->core_signal
317 = bfd_get_16 (abfd
, note
->descdata
+ 12);
320 elf_tdata (abfd
)->core_lwpid
321 = bfd_get_32 (abfd
, note
->descdata
+ 32);
330 /* Make a ".reg/999" section. */
331 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
332 size
, note
->descpos
+ offset
);
336 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
338 switch (note
->descsz
)
343 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
344 elf_tdata (abfd
)->core_pid
345 = bfd_get_32 (abfd
, note
->descdata
+ 24);
346 elf_tdata (abfd
)->core_program
347 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
348 elf_tdata (abfd
)->core_command
349 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
352 /* Note that for some reason, a spurious space is tacked
353 onto the end of the args in some (at least one anyway)
354 implementations, so strip it off if it exists. */
357 char *command
= elf_tdata (abfd
)->core_command
;
358 int n
= strlen (command
);
360 if (0 < n
&& command
[n
- 1] == ' ')
361 command
[n
- 1] = '\0';
367 /* Functions for the x86-64 ELF linker. */
369 /* The name of the dynamic interpreter. This is put in the .interp
372 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
373 #define ELF32_DYNAMIC_INTERPRETER "/lib/ld32.so.1"
375 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
376 copying dynamic variables from a shared lib into an app's dynbss
377 section, and instead use a dynamic relocation to point into the
379 #define ELIMINATE_COPY_RELOCS 1
381 /* The size in bytes of an entry in the global offset table. */
383 #define GOT_ENTRY_SIZE 8
385 /* The size in bytes of an entry in the procedure linkage table. */
387 #define PLT_ENTRY_SIZE 16
389 /* The first entry in a procedure linkage table looks like this. See the
390 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
392 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
394 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
395 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
396 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
399 /* Subsequent entries in a procedure linkage table look like this. */
401 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
403 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
404 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
405 0x68, /* pushq immediate */
406 0, 0, 0, 0, /* replaced with index into relocation table. */
407 0xe9, /* jmp relative */
408 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
411 /* x86-64 ELF linker hash entry. */
413 struct elf_x86_64_link_hash_entry
415 struct elf_link_hash_entry elf
;
417 /* Track dynamic relocs copied for this symbol. */
418 struct elf_dyn_relocs
*dyn_relocs
;
420 #define GOT_UNKNOWN 0
424 #define GOT_TLS_GDESC 4
425 #define GOT_TLS_GD_BOTH_P(type) \
426 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
427 #define GOT_TLS_GD_P(type) \
428 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
429 #define GOT_TLS_GDESC_P(type) \
430 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
431 #define GOT_TLS_GD_ANY_P(type) \
432 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
433 unsigned char tls_type
;
435 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
436 starting at the end of the jump table. */
440 #define elf_x86_64_hash_entry(ent) \
441 ((struct elf_x86_64_link_hash_entry *)(ent))
443 struct elf_x86_64_obj_tdata
445 struct elf_obj_tdata root
;
447 /* tls_type for each local got entry. */
448 char *local_got_tls_type
;
450 /* GOTPLT entries for TLS descriptors. */
451 bfd_vma
*local_tlsdesc_gotent
;
454 #define elf_x86_64_tdata(abfd) \
455 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
457 #define elf_x86_64_local_got_tls_type(abfd) \
458 (elf_x86_64_tdata (abfd)->local_got_tls_type)
460 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
461 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
463 #define is_x86_64_elf(bfd) \
464 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
465 && elf_tdata (bfd) != NULL \
466 && elf_object_id (bfd) == X86_64_ELF_DATA)
469 elf_x86_64_mkobject (bfd
*abfd
)
471 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
475 /* x86-64 ELF linker hash table. */
477 struct elf_x86_64_link_hash_table
479 struct elf_link_hash_table elf
;
481 /* Short-cuts to get to dynamic linker sections. */
487 bfd_signed_vma refcount
;
491 /* The amount of space used by the jump slots in the GOT. */
492 bfd_vma sgotplt_jump_table_size
;
494 /* Small local sym cache. */
495 struct sym_cache sym_cache
;
497 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
498 bfd_vma (*r_sym
) (bfd_vma
);
499 unsigned int pointer_r_type
;
500 const char *dynamic_interpreter
;
501 int dynamic_interpreter_size
;
503 /* _TLS_MODULE_BASE_ symbol. */
504 struct bfd_link_hash_entry
*tls_module_base
;
506 /* Used by local STT_GNU_IFUNC symbols. */
507 htab_t loc_hash_table
;
508 void * loc_hash_memory
;
510 /* The offset into splt of the PLT entry for the TLS descriptor
511 resolver. Special values are 0, if not necessary (or not found
512 to be necessary yet), and -1 if needed but not determined
515 /* The offset into sgot of the GOT entry used by the PLT entry
520 /* Get the x86-64 ELF linker hash table from a link_info structure. */
522 #define elf_x86_64_hash_table(p) \
523 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
524 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
526 #define elf_x86_64_compute_jump_table_size(htab) \
527 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
529 /* Create an entry in an x86-64 ELF linker hash table. */
531 static struct bfd_hash_entry
*
532 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
533 struct bfd_hash_table
*table
,
536 /* Allocate the structure if it has not already been allocated by a
540 entry
= (struct bfd_hash_entry
*)
541 bfd_hash_allocate (table
,
542 sizeof (struct elf_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 elf_x86_64_link_hash_entry
*eh
;
553 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
554 eh
->dyn_relocs
= NULL
;
555 eh
->tls_type
= GOT_UNKNOWN
;
556 eh
->tlsdesc_got
= (bfd_vma
) -1;
562 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
563 for local symbol so that we can handle local STT_GNU_IFUNC symbols
564 as global symbol. We reuse indx and dynstr_index for local symbol
565 hash since they aren't used by global symbols in this backend. */
568 elf_x86_64_local_htab_hash (const void *ptr
)
570 struct elf_link_hash_entry
*h
571 = (struct elf_link_hash_entry
*) ptr
;
572 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
575 /* Compare local hash entries. */
578 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
580 struct elf_link_hash_entry
*h1
581 = (struct elf_link_hash_entry
*) ptr1
;
582 struct elf_link_hash_entry
*h2
583 = (struct elf_link_hash_entry
*) ptr2
;
585 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
588 /* Find and/or create a hash entry for local symbol. */
590 static struct elf_link_hash_entry
*
591 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
592 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
595 struct elf_x86_64_link_hash_entry e
, *ret
;
596 asection
*sec
= abfd
->sections
;
597 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
598 htab
->r_sym (rel
->r_info
));
601 e
.elf
.indx
= sec
->id
;
602 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
603 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
604 create
? INSERT
: NO_INSERT
);
611 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
615 ret
= (struct elf_x86_64_link_hash_entry
*)
616 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
617 sizeof (struct elf_x86_64_link_hash_entry
));
620 memset (ret
, 0, sizeof (*ret
));
621 ret
->elf
.indx
= sec
->id
;
622 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
623 ret
->elf
.dynindx
= -1;
629 /* Create an X86-64 ELF linker hash table. */
631 static struct bfd_link_hash_table
*
632 elf_x86_64_link_hash_table_create (bfd
*abfd
)
634 struct elf_x86_64_link_hash_table
*ret
;
635 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
637 ret
= (struct elf_x86_64_link_hash_table
*) bfd_malloc (amt
);
641 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
642 elf_x86_64_link_hash_newfunc
,
643 sizeof (struct elf_x86_64_link_hash_entry
),
652 ret
->sym_cache
.abfd
= NULL
;
653 ret
->tlsdesc_plt
= 0;
654 ret
->tlsdesc_got
= 0;
655 ret
->tls_ld_got
.refcount
= 0;
656 ret
->sgotplt_jump_table_size
= 0;
657 ret
->tls_module_base
= NULL
;
661 ret
->r_info
= elf64_r_info
;
662 ret
->r_sym
= elf64_r_sym
;
663 ret
->pointer_r_type
= R_X86_64_64
;
664 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
665 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
669 ret
->r_info
= elf32_r_info
;
670 ret
->r_sym
= elf32_r_sym
;
671 ret
->pointer_r_type
= R_X86_64_32
;
672 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
673 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
676 ret
->loc_hash_table
= htab_try_create (1024,
677 elf_x86_64_local_htab_hash
,
678 elf_x86_64_local_htab_eq
,
680 ret
->loc_hash_memory
= objalloc_create ();
681 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
687 return &ret
->elf
.root
;
690 /* Destroy an X86-64 ELF linker hash table. */
693 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
695 struct elf_x86_64_link_hash_table
*htab
696 = (struct elf_x86_64_link_hash_table
*) hash
;
698 if (htab
->loc_hash_table
)
699 htab_delete (htab
->loc_hash_table
);
700 if (htab
->loc_hash_memory
)
701 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
702 _bfd_generic_link_hash_table_free (hash
);
705 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
706 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
710 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
711 struct bfd_link_info
*info
)
713 struct elf_x86_64_link_hash_table
*htab
;
715 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
718 htab
= elf_x86_64_hash_table (info
);
722 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
724 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
727 || (!info
->shared
&& !htab
->srelbss
))
733 /* Copy the extra info we tack onto an elf_link_hash_entry. */
736 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
737 struct elf_link_hash_entry
*dir
,
738 struct elf_link_hash_entry
*ind
)
740 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
742 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
743 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
745 if (eind
->dyn_relocs
!= NULL
)
747 if (edir
->dyn_relocs
!= NULL
)
749 struct elf_dyn_relocs
**pp
;
750 struct elf_dyn_relocs
*p
;
752 /* Add reloc counts against the indirect sym to the direct sym
753 list. Merge any entries against the same section. */
754 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
756 struct elf_dyn_relocs
*q
;
758 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
759 if (q
->sec
== p
->sec
)
761 q
->pc_count
+= p
->pc_count
;
762 q
->count
+= p
->count
;
769 *pp
= edir
->dyn_relocs
;
772 edir
->dyn_relocs
= eind
->dyn_relocs
;
773 eind
->dyn_relocs
= NULL
;
776 if (ind
->root
.type
== bfd_link_hash_indirect
777 && dir
->got
.refcount
<= 0)
779 edir
->tls_type
= eind
->tls_type
;
780 eind
->tls_type
= GOT_UNKNOWN
;
783 if (ELIMINATE_COPY_RELOCS
784 && ind
->root
.type
!= bfd_link_hash_indirect
785 && dir
->dynamic_adjusted
)
787 /* If called to transfer flags for a weakdef during processing
788 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
789 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
790 dir
->ref_dynamic
|= ind
->ref_dynamic
;
791 dir
->ref_regular
|= ind
->ref_regular
;
792 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
793 dir
->needs_plt
|= ind
->needs_plt
;
794 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
797 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
801 elf64_x86_64_elf_object_p (bfd
*abfd
)
803 /* Set the right machine number for an x86-64 elf64 file. */
804 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
822 /* Return TRUE if the TLS access code sequence support transition
826 elf_x86_64_check_tls_transition (bfd
*abfd
,
827 struct bfd_link_info
*info
,
830 Elf_Internal_Shdr
*symtab_hdr
,
831 struct elf_link_hash_entry
**sym_hashes
,
833 const Elf_Internal_Rela
*rel
,
834 const Elf_Internal_Rela
*relend
)
837 unsigned long r_symndx
;
838 struct elf_link_hash_entry
*h
;
840 struct elf_x86_64_link_hash_table
*htab
;
842 /* Get the section contents. */
843 if (contents
== NULL
)
845 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
846 contents
= elf_section_data (sec
)->this_hdr
.contents
;
849 /* FIXME: How to better handle error condition? */
850 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
853 /* Cache the section contents for elf_link_input_bfd. */
854 elf_section_data (sec
)->this_hdr
.contents
= contents
;
858 htab
= elf_x86_64_hash_table (info
);
859 offset
= rel
->r_offset
;
864 if ((rel
+ 1) >= relend
)
867 if (r_type
== R_X86_64_TLSGD
)
869 /* Check transition from GD access model. For 64bit, only
870 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
871 .word 0x6666; rex64; call __tls_get_addr
872 can transit to different access model. For 32bit, only
873 leaq foo@tlsgd(%rip), %rdi
874 .word 0x6666; rex64; call __tls_get_addr
875 can transit to different access model. */
877 static x86_64_opcode32 call
= { { 0x66, 0x66, 0x48, 0xe8 } };
878 if ((offset
+ 12) > sec
->size
879 || bfd_get_32 (abfd
, contents
+ offset
+ 4) != call
.i
)
884 static x86_64_opcode32 leaq
= { { 0x66, 0x48, 0x8d, 0x3d } };
886 || bfd_get_32 (abfd
, contents
+ offset
- 4) != leaq
.i
)
891 static x86_64_opcode16 lea
= { { 0x8d, 0x3d } };
893 || bfd_get_8 (abfd
, contents
+ offset
- 3) != 0x48
894 || bfd_get_16 (abfd
, contents
+ offset
- 2) != lea
.i
)
900 /* Check transition from LD access model. Only
901 leaq foo@tlsld(%rip), %rdi;
903 can transit to different access model. */
905 static x86_64_opcode32 ld
= { { 0x48, 0x8d, 0x3d, 0xe8 } };
908 if (offset
< 3 || (offset
+ 9) > sec
->size
)
911 op
.i
= bfd_get_32 (abfd
, contents
+ offset
- 3);
912 op
.c
[3] = bfd_get_8 (abfd
, contents
+ offset
+ 4);
917 r_symndx
= htab
->r_sym (rel
[1].r_info
);
918 if (r_symndx
< symtab_hdr
->sh_info
)
921 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
922 /* Use strncmp to check __tls_get_addr since __tls_get_addr
925 && h
->root
.root
.string
!= NULL
926 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
927 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
928 && (strncmp (h
->root
.root
.string
,
929 "__tls_get_addr", 14) == 0));
931 case R_X86_64_GOTTPOFF
:
932 /* Check transition from IE access model:
933 mov foo@gottpoff(%rip), %reg
934 add foo@gottpoff(%rip), %reg
937 /* Check REX prefix first. */
938 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
940 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
941 if (val
!= 0x48 && val
!= 0x4c)
943 /* X32 may have 0x44 REX prefix or no REX prefix. */
950 /* X32 may not have any REX prefix. */
953 if (offset
< 2 || (offset
+ 3) > sec
->size
)
957 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
958 if (val
!= 0x8b && val
!= 0x03)
961 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
962 return (val
& 0xc7) == 5;
964 case R_X86_64_GOTPC32_TLSDESC
:
965 /* Check transition from GDesc access model:
966 leaq x@tlsdesc(%rip), %rax
968 Make sure it's a leaq adding rip to a 32-bit offset
969 into any register, although it's probably almost always
972 if (offset
< 3 || (offset
+ 4) > sec
->size
)
975 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
976 if ((val
& 0xfb) != 0x48)
979 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
982 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
983 return (val
& 0xc7) == 0x05;
985 case R_X86_64_TLSDESC_CALL
:
986 /* Check transition from GDesc access model:
987 call *x@tlsdesc(%rax)
989 if (offset
+ 2 <= sec
->size
)
991 /* Make sure that it's a call *x@tlsdesc(%rax). */
992 static x86_64_opcode16 call
= { { 0xff, 0x10 } };
993 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
1003 /* Return TRUE if the TLS access transition is OK or no transition
1004 will be performed. Update R_TYPE if there is a transition. */
1007 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1008 asection
*sec
, bfd_byte
*contents
,
1009 Elf_Internal_Shdr
*symtab_hdr
,
1010 struct elf_link_hash_entry
**sym_hashes
,
1011 unsigned int *r_type
, int tls_type
,
1012 const Elf_Internal_Rela
*rel
,
1013 const Elf_Internal_Rela
*relend
,
1014 struct elf_link_hash_entry
*h
,
1015 unsigned long r_symndx
)
1017 unsigned int from_type
= *r_type
;
1018 unsigned int to_type
= from_type
;
1019 bfd_boolean check
= TRUE
;
1021 /* Skip TLS transition for functions. */
1023 && (h
->type
== STT_FUNC
1024 || h
->type
== STT_GNU_IFUNC
))
1029 case R_X86_64_TLSGD
:
1030 case R_X86_64_GOTPC32_TLSDESC
:
1031 case R_X86_64_TLSDESC_CALL
:
1032 case R_X86_64_GOTTPOFF
:
1033 if (info
->executable
)
1036 to_type
= R_X86_64_TPOFF32
;
1038 to_type
= R_X86_64_GOTTPOFF
;
1041 /* When we are called from elf_x86_64_relocate_section,
1042 CONTENTS isn't NULL and there may be additional transitions
1043 based on TLS_TYPE. */
1044 if (contents
!= NULL
)
1046 unsigned int new_to_type
= to_type
;
1048 if (info
->executable
1051 && tls_type
== GOT_TLS_IE
)
1052 new_to_type
= R_X86_64_TPOFF32
;
1054 if (to_type
== R_X86_64_TLSGD
1055 || to_type
== R_X86_64_GOTPC32_TLSDESC
1056 || to_type
== R_X86_64_TLSDESC_CALL
)
1058 if (tls_type
== GOT_TLS_IE
)
1059 new_to_type
= R_X86_64_GOTTPOFF
;
1062 /* We checked the transition before when we were called from
1063 elf_x86_64_check_relocs. We only want to check the new
1064 transition which hasn't been checked before. */
1065 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1066 to_type
= new_to_type
;
1071 case R_X86_64_TLSLD
:
1072 if (info
->executable
)
1073 to_type
= R_X86_64_TPOFF32
;
1080 /* Return TRUE if there is no transition. */
1081 if (from_type
== to_type
)
1084 /* Check if the transition can be performed. */
1086 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1087 symtab_hdr
, sym_hashes
,
1088 from_type
, rel
, relend
))
1090 reloc_howto_type
*from
, *to
;
1093 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1094 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1097 name
= h
->root
.root
.string
;
1100 struct elf_x86_64_link_hash_table
*htab
;
1102 htab
= elf_x86_64_hash_table (info
);
1107 Elf_Internal_Sym
*isym
;
1109 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1111 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1115 (*_bfd_error_handler
)
1116 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1117 "in section `%A' failed"),
1118 abfd
, sec
, from
->name
, to
->name
, name
,
1119 (unsigned long) rel
->r_offset
);
1120 bfd_set_error (bfd_error_bad_value
);
1128 /* Look through the relocs for a section during the first phase, and
1129 calculate needed space in the global offset table, procedure
1130 linkage table, and dynamic reloc sections. */
1133 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1135 const Elf_Internal_Rela
*relocs
)
1137 struct elf_x86_64_link_hash_table
*htab
;
1138 Elf_Internal_Shdr
*symtab_hdr
;
1139 struct elf_link_hash_entry
**sym_hashes
;
1140 const Elf_Internal_Rela
*rel
;
1141 const Elf_Internal_Rela
*rel_end
;
1144 if (info
->relocatable
)
1147 BFD_ASSERT (is_x86_64_elf (abfd
));
1149 htab
= elf_x86_64_hash_table (info
);
1153 symtab_hdr
= &elf_symtab_hdr (abfd
);
1154 sym_hashes
= elf_sym_hashes (abfd
);
1158 rel_end
= relocs
+ sec
->reloc_count
;
1159 for (rel
= relocs
; rel
< rel_end
; rel
++)
1161 unsigned int r_type
;
1162 unsigned long r_symndx
;
1163 struct elf_link_hash_entry
*h
;
1164 Elf_Internal_Sym
*isym
;
1167 r_symndx
= htab
->r_sym (rel
->r_info
);
1168 r_type
= ELF32_R_TYPE (rel
->r_info
);
1170 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1172 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1177 if (r_symndx
< symtab_hdr
->sh_info
)
1179 /* A local symbol. */
1180 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1185 /* Check relocation against local STT_GNU_IFUNC symbol. */
1186 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1188 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1193 /* Fake a STT_GNU_IFUNC symbol. */
1194 h
->type
= STT_GNU_IFUNC
;
1197 h
->forced_local
= 1;
1198 h
->root
.type
= bfd_link_hash_defined
;
1206 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1207 while (h
->root
.type
== bfd_link_hash_indirect
1208 || h
->root
.type
== bfd_link_hash_warning
)
1209 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1212 /* Check invalid x32 relocations. */
1213 if (!ABI_64_P (abfd
))
1220 case R_X86_64_DTPOFF64
:
1221 case R_X86_64_TPOFF64
:
1223 case R_X86_64_GOTOFF64
:
1224 case R_X86_64_GOT64
:
1225 case R_X86_64_GOTPCREL64
:
1226 case R_X86_64_GOTPC64
:
1227 case R_X86_64_GOTPLT64
:
1228 case R_X86_64_PLTOFF64
:
1231 name
= h
->root
.root
.string
;
1233 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1235 (*_bfd_error_handler
)
1236 (_("%B: relocation %s against symbol `%s' isn't "
1237 "supported in x32 mode"), abfd
,
1238 x86_64_elf_howto_table
[r_type
].name
, name
);
1239 bfd_set_error (bfd_error_bad_value
);
1247 /* Create the ifunc sections for static executables. If we
1248 never see an indirect function symbol nor we are building
1249 a static executable, those sections will be empty and
1250 won't appear in output. */
1261 case R_X86_64_PLT32
:
1262 case R_X86_64_GOTPCREL
:
1263 case R_X86_64_GOTPCREL64
:
1264 if (htab
->elf
.dynobj
== NULL
)
1265 htab
->elf
.dynobj
= abfd
;
1266 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1271 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1272 it here if it is defined in a non-shared object. */
1273 if (h
->type
== STT_GNU_IFUNC
1276 /* It is referenced by a non-shared object. */
1280 /* STT_GNU_IFUNC symbol must go through PLT. */
1281 h
->plt
.refcount
+= 1;
1283 /* STT_GNU_IFUNC needs dynamic sections. */
1284 if (htab
->elf
.dynobj
== NULL
)
1285 htab
->elf
.dynobj
= abfd
;
1290 if (h
->root
.root
.string
)
1291 name
= h
->root
.root
.string
;
1293 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1295 (*_bfd_error_handler
)
1296 (_("%B: relocation %s against STT_GNU_IFUNC "
1297 "symbol `%s' isn't handled by %s"), abfd
,
1298 x86_64_elf_howto_table
[r_type
].name
,
1299 name
, __FUNCTION__
);
1300 bfd_set_error (bfd_error_bad_value
);
1304 if (ABI_64_P (abfd
))
1308 h
->pointer_equality_needed
= 1;
1311 /* We must copy these reloc types into the output
1312 file. Create a reloc section in dynobj and
1313 make room for this reloc. */
1314 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1315 (abfd
, info
, sec
, sreloc
,
1316 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1327 if (r_type
!= R_X86_64_PC32
1328 && r_type
!= R_X86_64_PC64
)
1329 h
->pointer_equality_needed
= 1;
1332 case R_X86_64_PLT32
:
1335 case R_X86_64_GOTPCREL
:
1336 case R_X86_64_GOTPCREL64
:
1337 h
->got
.refcount
+= 1;
1338 if (htab
->elf
.sgot
== NULL
1339 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1349 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1350 symtab_hdr
, sym_hashes
,
1351 &r_type
, GOT_UNKNOWN
,
1352 rel
, rel_end
, h
, r_symndx
))
1357 case R_X86_64_TLSLD
:
1358 htab
->tls_ld_got
.refcount
+= 1;
1361 case R_X86_64_TPOFF32
:
1362 if (!info
->executable
&& ABI_64_P (abfd
))
1365 name
= h
->root
.root
.string
;
1367 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1369 (*_bfd_error_handler
)
1370 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1372 x86_64_elf_howto_table
[r_type
].name
, name
);
1373 bfd_set_error (bfd_error_bad_value
);
1378 case R_X86_64_GOTTPOFF
:
1379 if (!info
->executable
)
1380 info
->flags
|= DF_STATIC_TLS
;
1383 case R_X86_64_GOT32
:
1384 case R_X86_64_GOTPCREL
:
1385 case R_X86_64_TLSGD
:
1386 case R_X86_64_GOT64
:
1387 case R_X86_64_GOTPCREL64
:
1388 case R_X86_64_GOTPLT64
:
1389 case R_X86_64_GOTPC32_TLSDESC
:
1390 case R_X86_64_TLSDESC_CALL
:
1391 /* This symbol requires a global offset table entry. */
1393 int tls_type
, old_tls_type
;
1397 default: tls_type
= GOT_NORMAL
; break;
1398 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1399 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1400 case R_X86_64_GOTPC32_TLSDESC
:
1401 case R_X86_64_TLSDESC_CALL
:
1402 tls_type
= GOT_TLS_GDESC
; break;
1407 if (r_type
== R_X86_64_GOTPLT64
)
1409 /* This relocation indicates that we also need
1410 a PLT entry, as this is a function. We don't need
1411 a PLT entry for local symbols. */
1413 h
->plt
.refcount
+= 1;
1415 h
->got
.refcount
+= 1;
1416 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1420 bfd_signed_vma
*local_got_refcounts
;
1422 /* This is a global offset table entry for a local symbol. */
1423 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1424 if (local_got_refcounts
== NULL
)
1428 size
= symtab_hdr
->sh_info
;
1429 size
*= sizeof (bfd_signed_vma
)
1430 + sizeof (bfd_vma
) + sizeof (char);
1431 local_got_refcounts
= ((bfd_signed_vma
*)
1432 bfd_zalloc (abfd
, size
));
1433 if (local_got_refcounts
== NULL
)
1435 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1436 elf_x86_64_local_tlsdesc_gotent (abfd
)
1437 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1438 elf_x86_64_local_got_tls_type (abfd
)
1439 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1441 local_got_refcounts
[r_symndx
] += 1;
1443 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1446 /* If a TLS symbol is accessed using IE at least once,
1447 there is no point to use dynamic model for it. */
1448 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1449 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1450 || tls_type
!= GOT_TLS_IE
))
1452 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1453 tls_type
= old_tls_type
;
1454 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1455 && GOT_TLS_GD_ANY_P (tls_type
))
1456 tls_type
|= old_tls_type
;
1460 name
= h
->root
.root
.string
;
1462 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1464 (*_bfd_error_handler
)
1465 (_("%B: '%s' accessed both as normal and thread local symbol"),
1471 if (old_tls_type
!= tls_type
)
1474 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1476 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1481 case R_X86_64_GOTOFF64
:
1482 case R_X86_64_GOTPC32
:
1483 case R_X86_64_GOTPC64
:
1485 if (htab
->elf
.sgot
== NULL
)
1487 if (htab
->elf
.dynobj
== NULL
)
1488 htab
->elf
.dynobj
= abfd
;
1489 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1495 case R_X86_64_PLT32
:
1496 /* This symbol requires a procedure linkage table entry. We
1497 actually build the entry in adjust_dynamic_symbol,
1498 because this might be a case of linking PIC code which is
1499 never referenced by a dynamic object, in which case we
1500 don't need to generate a procedure linkage table entry
1503 /* If this is a local symbol, we resolve it directly without
1504 creating a procedure linkage table entry. */
1509 h
->plt
.refcount
+= 1;
1512 case R_X86_64_PLTOFF64
:
1513 /* This tries to form the 'address' of a function relative
1514 to GOT. For global symbols we need a PLT entry. */
1518 h
->plt
.refcount
+= 1;
1523 if (!ABI_64_P (abfd
))
1528 /* Let's help debug shared library creation. These relocs
1529 cannot be used in shared libs. Don't error out for
1530 sections we don't care about, such as debug sections or
1531 non-constant sections. */
1533 && (sec
->flags
& SEC_ALLOC
) != 0
1534 && (sec
->flags
& SEC_READONLY
) != 0)
1537 name
= h
->root
.root
.string
;
1539 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1540 (*_bfd_error_handler
)
1541 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1542 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1543 bfd_set_error (bfd_error_bad_value
);
1554 if (h
!= NULL
&& info
->executable
)
1556 /* If this reloc is in a read-only section, we might
1557 need a copy reloc. We can't check reliably at this
1558 stage whether the section is read-only, as input
1559 sections have not yet been mapped to output sections.
1560 Tentatively set the flag for now, and correct in
1561 adjust_dynamic_symbol. */
1564 /* We may need a .plt entry if the function this reloc
1565 refers to is in a shared lib. */
1566 h
->plt
.refcount
+= 1;
1567 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1568 h
->pointer_equality_needed
= 1;
1571 /* If we are creating a shared library, and this is a reloc
1572 against a global symbol, or a non PC relative reloc
1573 against a local symbol, then we need to copy the reloc
1574 into the shared library. However, if we are linking with
1575 -Bsymbolic, we do not need to copy a reloc against a
1576 global symbol which is defined in an object we are
1577 including in the link (i.e., DEF_REGULAR is set). At
1578 this point we have not seen all the input files, so it is
1579 possible that DEF_REGULAR is not set now but will be set
1580 later (it is never cleared). In case of a weak definition,
1581 DEF_REGULAR may be cleared later by a strong definition in
1582 a shared library. We account for that possibility below by
1583 storing information in the relocs_copied field of the hash
1584 table entry. A similar situation occurs when creating
1585 shared libraries and symbol visibility changes render the
1588 If on the other hand, we are creating an executable, we
1589 may need to keep relocations for symbols satisfied by a
1590 dynamic library if we manage to avoid copy relocs for the
1593 && (sec
->flags
& SEC_ALLOC
) != 0
1594 && (! IS_X86_64_PCREL_TYPE (r_type
)
1596 && (! SYMBOLIC_BIND (info
, h
)
1597 || h
->root
.type
== bfd_link_hash_defweak
1598 || !h
->def_regular
))))
1599 || (ELIMINATE_COPY_RELOCS
1601 && (sec
->flags
& SEC_ALLOC
) != 0
1603 && (h
->root
.type
== bfd_link_hash_defweak
1604 || !h
->def_regular
)))
1606 struct elf_dyn_relocs
*p
;
1607 struct elf_dyn_relocs
**head
;
1609 /* We must copy these reloc types into the output file.
1610 Create a reloc section in dynobj and make room for
1614 if (htab
->elf
.dynobj
== NULL
)
1615 htab
->elf
.dynobj
= abfd
;
1617 sreloc
= _bfd_elf_make_dynamic_reloc_section
1618 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1619 abfd
, /*rela?*/ TRUE
);
1625 /* If this is a global symbol, we count the number of
1626 relocations we need for this symbol. */
1629 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1633 /* Track dynamic relocs needed for local syms too.
1634 We really need local syms available to do this
1639 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1644 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1648 /* Beware of type punned pointers vs strict aliasing
1650 vpp
= &(elf_section_data (s
)->local_dynrel
);
1651 head
= (struct elf_dyn_relocs
**)vpp
;
1655 if (p
== NULL
|| p
->sec
!= sec
)
1657 bfd_size_type amt
= sizeof *p
;
1659 p
= ((struct elf_dyn_relocs
*)
1660 bfd_alloc (htab
->elf
.dynobj
, amt
));
1671 if (IS_X86_64_PCREL_TYPE (r_type
))
1676 /* This relocation describes the C++ object vtable hierarchy.
1677 Reconstruct it for later use during GC. */
1678 case R_X86_64_GNU_VTINHERIT
:
1679 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1683 /* This relocation describes which C++ vtable entries are actually
1684 used. Record for later use during GC. */
1685 case R_X86_64_GNU_VTENTRY
:
1686 BFD_ASSERT (h
!= NULL
);
1688 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1700 /* Return the section that should be marked against GC for a given
1704 elf_x86_64_gc_mark_hook (asection
*sec
,
1705 struct bfd_link_info
*info
,
1706 Elf_Internal_Rela
*rel
,
1707 struct elf_link_hash_entry
*h
,
1708 Elf_Internal_Sym
*sym
)
1711 switch (ELF32_R_TYPE (rel
->r_info
))
1713 case R_X86_64_GNU_VTINHERIT
:
1714 case R_X86_64_GNU_VTENTRY
:
1718 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1721 /* Update the got entry reference counts for the section being removed. */
1724 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1726 const Elf_Internal_Rela
*relocs
)
1728 struct elf_x86_64_link_hash_table
*htab
;
1729 Elf_Internal_Shdr
*symtab_hdr
;
1730 struct elf_link_hash_entry
**sym_hashes
;
1731 bfd_signed_vma
*local_got_refcounts
;
1732 const Elf_Internal_Rela
*rel
, *relend
;
1734 if (info
->relocatable
)
1737 htab
= elf_x86_64_hash_table (info
);
1741 elf_section_data (sec
)->local_dynrel
= NULL
;
1743 symtab_hdr
= &elf_symtab_hdr (abfd
);
1744 sym_hashes
= elf_sym_hashes (abfd
);
1745 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1747 htab
= elf_x86_64_hash_table (info
);
1748 relend
= relocs
+ sec
->reloc_count
;
1749 for (rel
= relocs
; rel
< relend
; rel
++)
1751 unsigned long r_symndx
;
1752 unsigned int r_type
;
1753 struct elf_link_hash_entry
*h
= NULL
;
1755 r_symndx
= htab
->r_sym (rel
->r_info
);
1756 if (r_symndx
>= symtab_hdr
->sh_info
)
1758 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1759 while (h
->root
.type
== bfd_link_hash_indirect
1760 || h
->root
.type
== bfd_link_hash_warning
)
1761 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1765 /* A local symbol. */
1766 Elf_Internal_Sym
*isym
;
1768 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1771 /* Check relocation against local STT_GNU_IFUNC symbol. */
1773 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1775 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1783 struct elf_x86_64_link_hash_entry
*eh
;
1784 struct elf_dyn_relocs
**pp
;
1785 struct elf_dyn_relocs
*p
;
1787 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
1789 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1792 /* Everything must go for SEC. */
1798 r_type
= ELF32_R_TYPE (rel
->r_info
);
1799 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1800 symtab_hdr
, sym_hashes
,
1801 &r_type
, GOT_UNKNOWN
,
1802 rel
, relend
, h
, r_symndx
))
1807 case R_X86_64_TLSLD
:
1808 if (htab
->tls_ld_got
.refcount
> 0)
1809 htab
->tls_ld_got
.refcount
-= 1;
1812 case R_X86_64_TLSGD
:
1813 case R_X86_64_GOTPC32_TLSDESC
:
1814 case R_X86_64_TLSDESC_CALL
:
1815 case R_X86_64_GOTTPOFF
:
1816 case R_X86_64_GOT32
:
1817 case R_X86_64_GOTPCREL
:
1818 case R_X86_64_GOT64
:
1819 case R_X86_64_GOTPCREL64
:
1820 case R_X86_64_GOTPLT64
:
1823 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
1824 h
->plt
.refcount
-= 1;
1825 if (h
->got
.refcount
> 0)
1826 h
->got
.refcount
-= 1;
1827 if (h
->type
== STT_GNU_IFUNC
)
1829 if (h
->plt
.refcount
> 0)
1830 h
->plt
.refcount
-= 1;
1833 else if (local_got_refcounts
!= NULL
)
1835 if (local_got_refcounts
[r_symndx
] > 0)
1836 local_got_refcounts
[r_symndx
] -= 1;
1850 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1854 case R_X86_64_PLT32
:
1855 case R_X86_64_PLTOFF64
:
1858 if (h
->plt
.refcount
> 0)
1859 h
->plt
.refcount
-= 1;
1871 /* Adjust a symbol defined by a dynamic object and referenced by a
1872 regular object. The current definition is in some section of the
1873 dynamic object, but we're not including those sections. We have to
1874 change the definition to something the rest of the link can
1878 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1879 struct elf_link_hash_entry
*h
)
1881 struct elf_x86_64_link_hash_table
*htab
;
1884 /* STT_GNU_IFUNC symbol must go through PLT. */
1885 if (h
->type
== STT_GNU_IFUNC
)
1887 if (h
->plt
.refcount
<= 0)
1889 h
->plt
.offset
= (bfd_vma
) -1;
1895 /* If this is a function, put it in the procedure linkage table. We
1896 will fill in the contents of the procedure linkage table later,
1897 when we know the address of the .got section. */
1898 if (h
->type
== STT_FUNC
1901 if (h
->plt
.refcount
<= 0
1902 || SYMBOL_CALLS_LOCAL (info
, h
)
1903 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1904 && h
->root
.type
== bfd_link_hash_undefweak
))
1906 /* This case can occur if we saw a PLT32 reloc in an input
1907 file, but the symbol was never referred to by a dynamic
1908 object, or if all references were garbage collected. In
1909 such a case, we don't actually need to build a procedure
1910 linkage table, and we can just do a PC32 reloc instead. */
1911 h
->plt
.offset
= (bfd_vma
) -1;
1918 /* It's possible that we incorrectly decided a .plt reloc was
1919 needed for an R_X86_64_PC32 reloc to a non-function sym in
1920 check_relocs. We can't decide accurately between function and
1921 non-function syms in check-relocs; Objects loaded later in
1922 the link may change h->type. So fix it now. */
1923 h
->plt
.offset
= (bfd_vma
) -1;
1925 /* If this is a weak symbol, and there is a real definition, the
1926 processor independent code will have arranged for us to see the
1927 real definition first, and we can just use the same value. */
1928 if (h
->u
.weakdef
!= NULL
)
1930 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1931 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1932 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1933 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1934 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1935 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1939 /* This is a reference to a symbol defined by a dynamic object which
1940 is not a function. */
1942 /* If we are creating a shared library, we must presume that the
1943 only references to the symbol are via the global offset table.
1944 For such cases we need not do anything here; the relocations will
1945 be handled correctly by relocate_section. */
1949 /* If there are no references to this symbol that do not use the
1950 GOT, we don't need to generate a copy reloc. */
1951 if (!h
->non_got_ref
)
1954 /* If -z nocopyreloc was given, we won't generate them either. */
1955 if (info
->nocopyreloc
)
1961 if (ELIMINATE_COPY_RELOCS
)
1963 struct elf_x86_64_link_hash_entry
* eh
;
1964 struct elf_dyn_relocs
*p
;
1966 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
1967 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1969 s
= p
->sec
->output_section
;
1970 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1974 /* If we didn't find any dynamic relocs in read-only sections, then
1975 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1985 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1986 h
->root
.root
.string
);
1990 /* We must allocate the symbol in our .dynbss section, which will
1991 become part of the .bss section of the executable. There will be
1992 an entry for this symbol in the .dynsym section. The dynamic
1993 object will contain position independent code, so all references
1994 from the dynamic object to this symbol will go through the global
1995 offset table. The dynamic linker will use the .dynsym entry to
1996 determine the address it must put in the global offset table, so
1997 both the dynamic object and the regular object will refer to the
1998 same memory location for the variable. */
2000 htab
= elf_x86_64_hash_table (info
);
2004 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2005 to copy the initial value out of the dynamic object and into the
2006 runtime process image. */
2007 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2009 const struct elf_backend_data
*bed
;
2010 bed
= get_elf_backend_data (info
->output_bfd
);
2011 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2017 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2020 /* Allocate space in .plt, .got and associated reloc sections for
2024 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2026 struct bfd_link_info
*info
;
2027 struct elf_x86_64_link_hash_table
*htab
;
2028 struct elf_x86_64_link_hash_entry
*eh
;
2029 struct elf_dyn_relocs
*p
;
2030 const struct elf_backend_data
*bed
;
2032 if (h
->root
.type
== bfd_link_hash_indirect
)
2035 if (h
->root
.type
== bfd_link_hash_warning
)
2036 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2037 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2039 info
= (struct bfd_link_info
*) inf
;
2040 htab
= elf_x86_64_hash_table (info
);
2043 bed
= get_elf_backend_data (info
->output_bfd
);
2045 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2046 here if it is defined and referenced in a non-shared object. */
2047 if (h
->type
== STT_GNU_IFUNC
2049 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2053 else if (htab
->elf
.dynamic_sections_created
2054 && h
->plt
.refcount
> 0)
2056 /* Make sure this symbol is output as a dynamic symbol.
2057 Undefined weak syms won't yet be marked as dynamic. */
2058 if (h
->dynindx
== -1
2059 && !h
->forced_local
)
2061 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2066 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2068 asection
*s
= htab
->elf
.splt
;
2070 /* If this is the first .plt entry, make room for the special
2073 s
->size
+= PLT_ENTRY_SIZE
;
2075 h
->plt
.offset
= s
->size
;
2077 /* If this symbol is not defined in a regular file, and we are
2078 not generating a shared library, then set the symbol to this
2079 location in the .plt. This is required to make function
2080 pointers compare as equal between the normal executable and
2081 the shared library. */
2085 h
->root
.u
.def
.section
= s
;
2086 h
->root
.u
.def
.value
= h
->plt
.offset
;
2089 /* Make room for this entry. */
2090 s
->size
+= PLT_ENTRY_SIZE
;
2092 /* We also need to make an entry in the .got.plt section, which
2093 will be placed in the .got section by the linker script. */
2094 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2096 /* We also need to make an entry in the .rela.plt section. */
2097 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2098 htab
->elf
.srelplt
->reloc_count
++;
2102 h
->plt
.offset
= (bfd_vma
) -1;
2108 h
->plt
.offset
= (bfd_vma
) -1;
2112 eh
->tlsdesc_got
= (bfd_vma
) -1;
2114 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2115 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2116 if (h
->got
.refcount
> 0
2119 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2121 h
->got
.offset
= (bfd_vma
) -1;
2123 else if (h
->got
.refcount
> 0)
2127 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2129 /* Make sure this symbol is output as a dynamic symbol.
2130 Undefined weak syms won't yet be marked as dynamic. */
2131 if (h
->dynindx
== -1
2132 && !h
->forced_local
)
2134 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2138 if (GOT_TLS_GDESC_P (tls_type
))
2140 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2141 - elf_x86_64_compute_jump_table_size (htab
);
2142 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2143 h
->got
.offset
= (bfd_vma
) -2;
2145 if (! GOT_TLS_GDESC_P (tls_type
)
2146 || GOT_TLS_GD_P (tls_type
))
2149 h
->got
.offset
= s
->size
;
2150 s
->size
+= GOT_ENTRY_SIZE
;
2151 if (GOT_TLS_GD_P (tls_type
))
2152 s
->size
+= GOT_ENTRY_SIZE
;
2154 dyn
= htab
->elf
.dynamic_sections_created
;
2155 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2157 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2158 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2159 || tls_type
== GOT_TLS_IE
)
2160 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2161 else if (GOT_TLS_GD_P (tls_type
))
2162 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2163 else if (! GOT_TLS_GDESC_P (tls_type
)
2164 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2165 || h
->root
.type
!= bfd_link_hash_undefweak
)
2167 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2168 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2169 if (GOT_TLS_GDESC_P (tls_type
))
2171 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2172 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2176 h
->got
.offset
= (bfd_vma
) -1;
2178 if (eh
->dyn_relocs
== NULL
)
2181 /* In the shared -Bsymbolic case, discard space allocated for
2182 dynamic pc-relative relocs against symbols which turn out to be
2183 defined in regular objects. For the normal shared case, discard
2184 space for pc-relative relocs that have become local due to symbol
2185 visibility changes. */
2189 /* Relocs that use pc_count are those that appear on a call
2190 insn, or certain REL relocs that can generated via assembly.
2191 We want calls to protected symbols to resolve directly to the
2192 function rather than going via the plt. If people want
2193 function pointer comparisons to work as expected then they
2194 should avoid writing weird assembly. */
2195 if (SYMBOL_CALLS_LOCAL (info
, h
))
2197 struct elf_dyn_relocs
**pp
;
2199 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2201 p
->count
-= p
->pc_count
;
2210 /* Also discard relocs on undefined weak syms with non-default
2212 if (eh
->dyn_relocs
!= NULL
2213 && h
->root
.type
== bfd_link_hash_undefweak
)
2215 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2216 eh
->dyn_relocs
= NULL
;
2218 /* Make sure undefined weak symbols are output as a dynamic
2220 else if (h
->dynindx
== -1
2221 && ! h
->forced_local
2222 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2227 else if (ELIMINATE_COPY_RELOCS
)
2229 /* For the non-shared case, discard space for relocs against
2230 symbols which turn out to need copy relocs or are not
2236 || (htab
->elf
.dynamic_sections_created
2237 && (h
->root
.type
== bfd_link_hash_undefweak
2238 || h
->root
.type
== bfd_link_hash_undefined
))))
2240 /* Make sure this symbol is output as a dynamic symbol.
2241 Undefined weak syms won't yet be marked as dynamic. */
2242 if (h
->dynindx
== -1
2243 && ! h
->forced_local
2244 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2247 /* If that succeeded, we know we'll be keeping all the
2249 if (h
->dynindx
!= -1)
2253 eh
->dyn_relocs
= NULL
;
2258 /* Finally, allocate space. */
2259 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2263 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2265 BFD_ASSERT (sreloc
!= NULL
);
2267 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2273 /* Allocate space in .plt, .got and associated reloc sections for
2274 local dynamic relocs. */
2277 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2279 struct elf_link_hash_entry
*h
2280 = (struct elf_link_hash_entry
*) *slot
;
2282 if (h
->type
!= STT_GNU_IFUNC
2286 || h
->root
.type
!= bfd_link_hash_defined
)
2289 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2292 /* Find any dynamic relocs that apply to read-only sections. */
2295 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2298 struct elf_x86_64_link_hash_entry
*eh
;
2299 struct elf_dyn_relocs
*p
;
2301 if (h
->root
.type
== bfd_link_hash_warning
)
2302 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2304 /* Skip local IFUNC symbols. */
2305 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2308 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2309 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2311 asection
*s
= p
->sec
->output_section
;
2313 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2315 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2317 info
->flags
|= DF_TEXTREL
;
2319 if (info
->warn_shared_textrel
&& info
->shared
)
2320 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2321 p
->sec
->owner
, h
->root
.root
.string
,
2324 /* Not an error, just cut short the traversal. */
2331 /* Set the sizes of the dynamic sections. */
2334 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2335 struct bfd_link_info
*info
)
2337 struct elf_x86_64_link_hash_table
*htab
;
2342 const struct elf_backend_data
*bed
;
2344 htab
= elf_x86_64_hash_table (info
);
2347 bed
= get_elf_backend_data (output_bfd
);
2349 dynobj
= htab
->elf
.dynobj
;
2353 if (htab
->elf
.dynamic_sections_created
)
2355 /* Set the contents of the .interp section to the interpreter. */
2356 if (info
->executable
)
2358 s
= bfd_get_section_by_name (dynobj
, ".interp");
2361 s
->size
= htab
->dynamic_interpreter_size
;
2362 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2366 /* Set up .got offsets for local syms, and space for local dynamic
2368 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2370 bfd_signed_vma
*local_got
;
2371 bfd_signed_vma
*end_local_got
;
2372 char *local_tls_type
;
2373 bfd_vma
*local_tlsdesc_gotent
;
2374 bfd_size_type locsymcount
;
2375 Elf_Internal_Shdr
*symtab_hdr
;
2378 if (! is_x86_64_elf (ibfd
))
2381 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2383 struct elf_dyn_relocs
*p
;
2385 for (p
= (struct elf_dyn_relocs
*)
2386 (elf_section_data (s
)->local_dynrel
);
2390 if (!bfd_is_abs_section (p
->sec
)
2391 && bfd_is_abs_section (p
->sec
->output_section
))
2393 /* Input section has been discarded, either because
2394 it is a copy of a linkonce section or due to
2395 linker script /DISCARD/, so we'll be discarding
2398 else if (p
->count
!= 0)
2400 srel
= elf_section_data (p
->sec
)->sreloc
;
2401 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2402 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2403 && (info
->flags
& DF_TEXTREL
) == 0)
2405 info
->flags
|= DF_TEXTREL
;
2406 if (info
->warn_shared_textrel
&& info
->shared
)
2407 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2408 p
->sec
->owner
, p
->sec
);
2414 local_got
= elf_local_got_refcounts (ibfd
);
2418 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2419 locsymcount
= symtab_hdr
->sh_info
;
2420 end_local_got
= local_got
+ locsymcount
;
2421 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2422 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2424 srel
= htab
->elf
.srelgot
;
2425 for (; local_got
< end_local_got
;
2426 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2428 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2431 if (GOT_TLS_GDESC_P (*local_tls_type
))
2433 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2434 - elf_x86_64_compute_jump_table_size (htab
);
2435 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2436 *local_got
= (bfd_vma
) -2;
2438 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2439 || GOT_TLS_GD_P (*local_tls_type
))
2441 *local_got
= s
->size
;
2442 s
->size
+= GOT_ENTRY_SIZE
;
2443 if (GOT_TLS_GD_P (*local_tls_type
))
2444 s
->size
+= GOT_ENTRY_SIZE
;
2447 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2448 || *local_tls_type
== GOT_TLS_IE
)
2450 if (GOT_TLS_GDESC_P (*local_tls_type
))
2452 htab
->elf
.srelplt
->size
2453 += bed
->s
->sizeof_rela
;
2454 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2456 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2457 || GOT_TLS_GD_P (*local_tls_type
))
2458 srel
->size
+= bed
->s
->sizeof_rela
;
2462 *local_got
= (bfd_vma
) -1;
2466 if (htab
->tls_ld_got
.refcount
> 0)
2468 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2470 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2471 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2472 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2475 htab
->tls_ld_got
.offset
= -1;
2477 /* Allocate global sym .plt and .got entries, and space for global
2478 sym dynamic relocs. */
2479 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2482 /* Allocate .plt and .got entries, and space for local symbols. */
2483 htab_traverse (htab
->loc_hash_table
,
2484 elf_x86_64_allocate_local_dynrelocs
,
2487 /* For every jump slot reserved in the sgotplt, reloc_count is
2488 incremented. However, when we reserve space for TLS descriptors,
2489 it's not incremented, so in order to compute the space reserved
2490 for them, it suffices to multiply the reloc count by the jump
2492 if (htab
->elf
.srelplt
)
2493 htab
->sgotplt_jump_table_size
2494 = elf_x86_64_compute_jump_table_size (htab
);
2496 if (htab
->tlsdesc_plt
)
2498 /* If we're not using lazy TLS relocations, don't generate the
2499 PLT and GOT entries they require. */
2500 if ((info
->flags
& DF_BIND_NOW
))
2501 htab
->tlsdesc_plt
= 0;
2504 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2505 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2506 /* Reserve room for the initial entry.
2507 FIXME: we could probably do away with it in this case. */
2508 if (htab
->elf
.splt
->size
== 0)
2509 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2510 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2511 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2515 if (htab
->elf
.sgotplt
)
2517 struct elf_link_hash_entry
*got
;
2518 got
= elf_link_hash_lookup (elf_hash_table (info
),
2519 "_GLOBAL_OFFSET_TABLE_",
2520 FALSE
, FALSE
, FALSE
);
2522 /* Don't allocate .got.plt section if there are no GOT nor PLT
2523 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2525 || !got
->ref_regular_nonweak
)
2526 && (htab
->elf
.sgotplt
->size
2527 == get_elf_backend_data (output_bfd
)->got_header_size
)
2528 && (htab
->elf
.splt
== NULL
2529 || htab
->elf
.splt
->size
== 0)
2530 && (htab
->elf
.sgot
== NULL
2531 || htab
->elf
.sgot
->size
== 0)
2532 && (htab
->elf
.iplt
== NULL
2533 || htab
->elf
.iplt
->size
== 0)
2534 && (htab
->elf
.igotplt
== NULL
2535 || htab
->elf
.igotplt
->size
== 0))
2536 htab
->elf
.sgotplt
->size
= 0;
2539 /* We now have determined the sizes of the various dynamic sections.
2540 Allocate memory for them. */
2542 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2544 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2547 if (s
== htab
->elf
.splt
2548 || s
== htab
->elf
.sgot
2549 || s
== htab
->elf
.sgotplt
2550 || s
== htab
->elf
.iplt
2551 || s
== htab
->elf
.igotplt
2552 || s
== htab
->sdynbss
)
2554 /* Strip this section if we don't need it; see the
2557 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2559 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2562 /* We use the reloc_count field as a counter if we need
2563 to copy relocs into the output file. */
2564 if (s
!= htab
->elf
.srelplt
)
2569 /* It's not one of our sections, so don't allocate space. */
2575 /* If we don't need this section, strip it from the
2576 output file. This is mostly to handle .rela.bss and
2577 .rela.plt. We must create both sections in
2578 create_dynamic_sections, because they must be created
2579 before the linker maps input sections to output
2580 sections. The linker does that before
2581 adjust_dynamic_symbol is called, and it is that
2582 function which decides whether anything needs to go
2583 into these sections. */
2585 s
->flags
|= SEC_EXCLUDE
;
2589 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2592 /* Allocate memory for the section contents. We use bfd_zalloc
2593 here in case unused entries are not reclaimed before the
2594 section's contents are written out. This should not happen,
2595 but this way if it does, we get a R_X86_64_NONE reloc instead
2597 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2598 if (s
->contents
== NULL
)
2602 if (htab
->elf
.dynamic_sections_created
)
2604 /* Add some entries to the .dynamic section. We fill in the
2605 values later, in elf_x86_64_finish_dynamic_sections, but we
2606 must add the entries now so that we get the correct size for
2607 the .dynamic section. The DT_DEBUG entry is filled in by the
2608 dynamic linker and used by the debugger. */
2609 #define add_dynamic_entry(TAG, VAL) \
2610 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2612 if (info
->executable
)
2614 if (!add_dynamic_entry (DT_DEBUG
, 0))
2618 if (htab
->elf
.splt
->size
!= 0)
2620 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2621 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2622 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2623 || !add_dynamic_entry (DT_JMPREL
, 0))
2626 if (htab
->tlsdesc_plt
2627 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2628 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2634 if (!add_dynamic_entry (DT_RELA
, 0)
2635 || !add_dynamic_entry (DT_RELASZ
, 0)
2636 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2639 /* If any dynamic relocs apply to a read-only section,
2640 then we need a DT_TEXTREL entry. */
2641 if ((info
->flags
& DF_TEXTREL
) == 0)
2642 elf_link_hash_traverse (&htab
->elf
,
2643 elf_x86_64_readonly_dynrelocs
,
2646 if ((info
->flags
& DF_TEXTREL
) != 0)
2648 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2653 #undef add_dynamic_entry
2659 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2660 struct bfd_link_info
*info
)
2662 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2666 struct elf_link_hash_entry
*tlsbase
;
2668 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2669 "_TLS_MODULE_BASE_",
2670 FALSE
, FALSE
, FALSE
);
2672 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2674 struct elf_x86_64_link_hash_table
*htab
;
2675 struct bfd_link_hash_entry
*bh
= NULL
;
2676 const struct elf_backend_data
*bed
2677 = get_elf_backend_data (output_bfd
);
2679 htab
= elf_x86_64_hash_table (info
);
2683 if (!(_bfd_generic_link_add_one_symbol
2684 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2685 tls_sec
, 0, NULL
, FALSE
,
2686 bed
->collect
, &bh
)))
2689 htab
->tls_module_base
= bh
;
2691 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2692 tlsbase
->def_regular
= 1;
2693 tlsbase
->other
= STV_HIDDEN
;
2694 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2701 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2702 executables. Rather than setting it to the beginning of the TLS
2703 section, we have to set it to the end. This function may be called
2704 multiple times, it is idempotent. */
2707 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2709 struct elf_x86_64_link_hash_table
*htab
;
2710 struct bfd_link_hash_entry
*base
;
2712 if (!info
->executable
)
2715 htab
= elf_x86_64_hash_table (info
);
2719 base
= htab
->tls_module_base
;
2723 base
->u
.def
.value
= htab
->elf
.tls_size
;
2726 /* Return the base VMA address which should be subtracted from real addresses
2727 when resolving @dtpoff relocation.
2728 This is PT_TLS segment p_vaddr. */
2731 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2733 /* If tls_sec is NULL, we should have signalled an error already. */
2734 if (elf_hash_table (info
)->tls_sec
== NULL
)
2736 return elf_hash_table (info
)->tls_sec
->vma
;
2739 /* Return the relocation value for @tpoff relocation
2740 if STT_TLS virtual address is ADDRESS. */
2743 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2745 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2746 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2747 bfd_vma static_tls_size
;
2749 /* If tls_segment is NULL, we should have signalled an error already. */
2750 if (htab
->tls_sec
== NULL
)
2753 /* Consider special static TLS alignment requirements. */
2754 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2755 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2758 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2762 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2764 /* Opcode Instruction
2767 0x0f 0x8x conditional jump */
2769 && (contents
[offset
- 1] == 0xe8
2770 || contents
[offset
- 1] == 0xe9))
2772 && contents
[offset
- 2] == 0x0f
2773 && (contents
[offset
- 1] & 0xf0) == 0x80));
2776 /* Relocate an x86_64 ELF section. */
2779 elf_x86_64_relocate_section (bfd
*output_bfd
,
2780 struct bfd_link_info
*info
,
2782 asection
*input_section
,
2784 Elf_Internal_Rela
*relocs
,
2785 Elf_Internal_Sym
*local_syms
,
2786 asection
**local_sections
)
2788 struct elf_x86_64_link_hash_table
*htab
;
2789 Elf_Internal_Shdr
*symtab_hdr
;
2790 struct elf_link_hash_entry
**sym_hashes
;
2791 bfd_vma
*local_got_offsets
;
2792 bfd_vma
*local_tlsdesc_gotents
;
2793 Elf_Internal_Rela
*rel
;
2794 Elf_Internal_Rela
*relend
;
2796 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2798 htab
= elf_x86_64_hash_table (info
);
2801 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2802 sym_hashes
= elf_sym_hashes (input_bfd
);
2803 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2804 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
2806 elf_x86_64_set_tls_module_base (info
);
2809 relend
= relocs
+ input_section
->reloc_count
;
2810 for (; rel
< relend
; rel
++)
2812 unsigned int r_type
;
2813 reloc_howto_type
*howto
;
2814 unsigned long r_symndx
;
2815 struct elf_link_hash_entry
*h
;
2816 Elf_Internal_Sym
*sym
;
2818 bfd_vma off
, offplt
;
2820 bfd_boolean unresolved_reloc
;
2821 bfd_reloc_status_type r
;
2825 r_type
= ELF32_R_TYPE (rel
->r_info
);
2826 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2827 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2830 if (r_type
>= R_X86_64_max
)
2832 bfd_set_error (bfd_error_bad_value
);
2836 howto
= x86_64_elf_howto_table
+ r_type
;
2837 r_symndx
= htab
->r_sym (rel
->r_info
);
2841 unresolved_reloc
= FALSE
;
2842 if (r_symndx
< symtab_hdr
->sh_info
)
2844 sym
= local_syms
+ r_symndx
;
2845 sec
= local_sections
[r_symndx
];
2847 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2850 /* Relocate against local STT_GNU_IFUNC symbol. */
2851 if (!info
->relocatable
2852 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2854 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
2859 /* Set STT_GNU_IFUNC symbol value. */
2860 h
->root
.u
.def
.value
= sym
->st_value
;
2861 h
->root
.u
.def
.section
= sec
;
2866 bfd_boolean warned ATTRIBUTE_UNUSED
;
2868 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2869 r_symndx
, symtab_hdr
, sym_hashes
,
2871 unresolved_reloc
, warned
);
2874 if (sec
!= NULL
&& elf_discarded_section (sec
))
2875 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2876 rel
, relend
, howto
, contents
);
2878 if (info
->relocatable
)
2881 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2882 it here if it is defined in a non-shared object. */
2884 && h
->type
== STT_GNU_IFUNC
2891 if ((input_section
->flags
& SEC_ALLOC
) == 0
2892 || h
->plt
.offset
== (bfd_vma
) -1)
2895 /* STT_GNU_IFUNC symbol must go through PLT. */
2896 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
2897 relocation
= (plt
->output_section
->vma
2898 + plt
->output_offset
+ h
->plt
.offset
);
2903 if (h
->root
.root
.string
)
2904 name
= h
->root
.root
.string
;
2906 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2908 (*_bfd_error_handler
)
2909 (_("%B: relocation %s against STT_GNU_IFUNC "
2910 "symbol `%s' isn't handled by %s"), input_bfd
,
2911 x86_64_elf_howto_table
[r_type
].name
,
2912 name
, __FUNCTION__
);
2913 bfd_set_error (bfd_error_bad_value
);
2922 if (ABI_64_P (output_bfd
))
2926 if (rel
->r_addend
!= 0)
2928 if (h
->root
.root
.string
)
2929 name
= h
->root
.root
.string
;
2931 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2933 (*_bfd_error_handler
)
2934 (_("%B: relocation %s against STT_GNU_IFUNC "
2935 "symbol `%s' has non-zero addend: %d"),
2936 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
2937 name
, rel
->r_addend
);
2938 bfd_set_error (bfd_error_bad_value
);
2942 /* Generate dynamic relcoation only when there is a
2943 non-GOF reference in a shared object. */
2944 if (info
->shared
&& h
->non_got_ref
)
2946 Elf_Internal_Rela outrel
;
2949 /* Need a dynamic relocation to get the real function
2951 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2955 if (outrel
.r_offset
== (bfd_vma
) -1
2956 || outrel
.r_offset
== (bfd_vma
) -2)
2959 outrel
.r_offset
+= (input_section
->output_section
->vma
2960 + input_section
->output_offset
);
2962 if (h
->dynindx
== -1
2964 || info
->executable
)
2966 /* This symbol is resolved locally. */
2967 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2968 outrel
.r_addend
= (h
->root
.u
.def
.value
2969 + h
->root
.u
.def
.section
->output_section
->vma
2970 + h
->root
.u
.def
.section
->output_offset
);
2974 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2975 outrel
.r_addend
= 0;
2978 sreloc
= htab
->elf
.irelifunc
;
2979 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2981 /* If this reloc is against an external symbol, we
2982 do not want to fiddle with the addend. Otherwise,
2983 we need to include the symbol value so that it
2984 becomes an addend for the dynamic reloc. For an
2985 internal symbol, we have updated addend. */
2991 case R_X86_64_PLT32
:
2994 case R_X86_64_GOTPCREL
:
2995 case R_X86_64_GOTPCREL64
:
2996 base_got
= htab
->elf
.sgot
;
2997 off
= h
->got
.offset
;
2999 if (base_got
== NULL
)
3002 if (off
== (bfd_vma
) -1)
3004 /* We can't use h->got.offset here to save state, or
3005 even just remember the offset, as finish_dynamic_symbol
3006 would use that as offset into .got. */
3008 if (htab
->elf
.splt
!= NULL
)
3010 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3011 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3012 base_got
= htab
->elf
.sgotplt
;
3016 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3017 off
= plt_index
* GOT_ENTRY_SIZE
;
3018 base_got
= htab
->elf
.igotplt
;
3021 if (h
->dynindx
== -1
3025 /* This references the local defitionion. We must
3026 initialize this entry in the global offset table.
3027 Since the offset must always be a multiple of 8,
3028 we use the least significant bit to record
3029 whether we have initialized it already.
3031 When doing a dynamic link, we create a .rela.got
3032 relocation entry to initialize the value. This
3033 is 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
3041 case, as -1 | 1 still is -1. */
3047 relocation
= (base_got
->output_section
->vma
3048 + base_got
->output_offset
+ off
);
3054 /* When generating a shared object, the relocations handled here are
3055 copied into the output file to be resolved at run time. */
3058 case R_X86_64_GOT32
:
3059 case R_X86_64_GOT64
:
3060 /* Relocation is to the entry for this symbol in the global
3062 case R_X86_64_GOTPCREL
:
3063 case R_X86_64_GOTPCREL64
:
3064 /* Use global offset table entry as symbol value. */
3065 case R_X86_64_GOTPLT64
:
3066 /* This is the same as GOT64 for relocation purposes, but
3067 indicates the existence of a PLT entry. The difficulty is,
3068 that we must calculate the GOT slot offset from the PLT
3069 offset, if this symbol got a PLT entry (it was global).
3070 Additionally if it's computed from the PLT entry, then that
3071 GOT offset is relative to .got.plt, not to .got. */
3072 base_got
= htab
->elf
.sgot
;
3074 if (htab
->elf
.sgot
== NULL
)
3081 off
= h
->got
.offset
;
3083 && h
->plt
.offset
!= (bfd_vma
)-1
3084 && off
== (bfd_vma
)-1)
3086 /* We can't use h->got.offset here to save
3087 state, or even just remember the offset, as
3088 finish_dynamic_symbol would use that as offset into
3090 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3091 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3092 base_got
= htab
->elf
.sgotplt
;
3095 dyn
= htab
->elf
.dynamic_sections_created
;
3097 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3099 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3100 || (ELF_ST_VISIBILITY (h
->other
)
3101 && h
->root
.type
== bfd_link_hash_undefweak
))
3103 /* This is actually a static link, or it is a -Bsymbolic
3104 link and the symbol is defined locally, or the symbol
3105 was forced to be local because of a version file. We
3106 must initialize this entry in the global offset table.
3107 Since the offset must always be a multiple of 8, we
3108 use the least significant bit to record whether we
3109 have initialized it already.
3111 When doing a dynamic link, we create a .rela.got
3112 relocation entry to initialize the value. This is
3113 done in the finish_dynamic_symbol routine. */
3118 bfd_put_64 (output_bfd
, relocation
,
3119 base_got
->contents
+ off
);
3120 /* Note that this is harmless for the GOTPLT64 case,
3121 as -1 | 1 still is -1. */
3126 unresolved_reloc
= FALSE
;
3130 if (local_got_offsets
== NULL
)
3133 off
= local_got_offsets
[r_symndx
];
3135 /* The offset must always be a multiple of 8. We use
3136 the least significant bit to record whether we have
3137 already generated the necessary reloc. */
3142 bfd_put_64 (output_bfd
, relocation
,
3143 base_got
->contents
+ off
);
3148 Elf_Internal_Rela outrel
;
3150 /* We need to generate a R_X86_64_RELATIVE reloc
3151 for the dynamic linker. */
3152 s
= htab
->elf
.srelgot
;
3156 outrel
.r_offset
= (base_got
->output_section
->vma
3157 + base_got
->output_offset
3159 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3160 outrel
.r_addend
= relocation
;
3161 elf_append_rela (output_bfd
, s
, &outrel
);
3164 local_got_offsets
[r_symndx
] |= 1;
3168 if (off
>= (bfd_vma
) -2)
3171 relocation
= base_got
->output_section
->vma
3172 + base_got
->output_offset
+ off
;
3173 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3174 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3175 - htab
->elf
.sgotplt
->output_offset
;
3179 case R_X86_64_GOTOFF64
:
3180 /* Relocation is relative to the start of the global offset
3183 /* Check to make sure it isn't a protected function symbol
3184 for shared library since it may not be local when used
3185 as function address. */
3189 && h
->type
== STT_FUNC
3190 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3192 (*_bfd_error_handler
)
3193 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3194 input_bfd
, h
->root
.root
.string
);
3195 bfd_set_error (bfd_error_bad_value
);
3199 /* Note that sgot is not involved in this
3200 calculation. We always want the start of .got.plt. If we
3201 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3202 permitted by the ABI, we might have to change this
3204 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3205 + htab
->elf
.sgotplt
->output_offset
;
3208 case R_X86_64_GOTPC32
:
3209 case R_X86_64_GOTPC64
:
3210 /* Use global offset table as symbol value. */
3211 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3212 + htab
->elf
.sgotplt
->output_offset
;
3213 unresolved_reloc
= FALSE
;
3216 case R_X86_64_PLTOFF64
:
3217 /* Relocation is PLT entry relative to GOT. For local
3218 symbols it's the symbol itself relative to GOT. */
3220 /* See PLT32 handling. */
3221 && h
->plt
.offset
!= (bfd_vma
) -1
3222 && htab
->elf
.splt
!= NULL
)
3224 relocation
= (htab
->elf
.splt
->output_section
->vma
3225 + htab
->elf
.splt
->output_offset
3227 unresolved_reloc
= FALSE
;
3230 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3231 + htab
->elf
.sgotplt
->output_offset
;
3234 case R_X86_64_PLT32
:
3235 /* Relocation is to the entry for this symbol in the
3236 procedure linkage table. */
3238 /* Resolve a PLT32 reloc against a local symbol directly,
3239 without using the procedure linkage table. */
3243 if (h
->plt
.offset
== (bfd_vma
) -1
3244 || htab
->elf
.splt
== NULL
)
3246 /* We didn't make a PLT entry for this symbol. This
3247 happens when statically linking PIC code, or when
3248 using -Bsymbolic. */
3252 relocation
= (htab
->elf
.splt
->output_section
->vma
3253 + htab
->elf
.splt
->output_offset
3255 unresolved_reloc
= FALSE
;
3262 && ABI_64_P (output_bfd
)
3263 && (input_section
->flags
& SEC_ALLOC
) != 0
3264 && (input_section
->flags
& SEC_READONLY
) != 0
3267 bfd_boolean fail
= FALSE
;
3269 = (r_type
== R_X86_64_PC32
3270 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3272 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3274 /* Symbol is referenced locally. Make sure it is
3275 defined locally or for a branch. */
3276 fail
= !h
->def_regular
&& !branch
;
3280 /* Symbol isn't referenced locally. We only allow
3281 branch to symbol with non-default visibility. */
3283 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3290 const char *pic
= "";
3292 switch (ELF_ST_VISIBILITY (h
->other
))
3295 v
= _("hidden symbol");
3298 v
= _("internal symbol");
3301 v
= _("protected symbol");
3305 pic
= _("; recompile with -fPIC");
3310 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3312 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3314 (*_bfd_error_handler
) (fmt
, input_bfd
,
3315 x86_64_elf_howto_table
[r_type
].name
,
3316 v
, h
->root
.root
.string
, pic
);
3317 bfd_set_error (bfd_error_bad_value
);
3328 /* FIXME: The ABI says the linker should make sure the value is
3329 the same when it's zeroextended to 64 bit. */
3331 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3336 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3337 || h
->root
.type
!= bfd_link_hash_undefweak
)
3338 && (! IS_X86_64_PCREL_TYPE (r_type
)
3339 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3340 || (ELIMINATE_COPY_RELOCS
3347 || h
->root
.type
== bfd_link_hash_undefweak
3348 || h
->root
.type
== bfd_link_hash_undefined
)))
3350 Elf_Internal_Rela outrel
;
3351 bfd_boolean skip
, relocate
;
3354 /* When generating a shared object, these relocations
3355 are copied into the output file to be resolved at run
3361 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3363 if (outrel
.r_offset
== (bfd_vma
) -1)
3365 else if (outrel
.r_offset
== (bfd_vma
) -2)
3366 skip
= TRUE
, relocate
= TRUE
;
3368 outrel
.r_offset
+= (input_section
->output_section
->vma
3369 + input_section
->output_offset
);
3372 memset (&outrel
, 0, sizeof outrel
);
3374 /* h->dynindx may be -1 if this symbol was marked to
3378 && (IS_X86_64_PCREL_TYPE (r_type
)
3380 || ! SYMBOLIC_BIND (info
, h
)
3381 || ! h
->def_regular
))
3383 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3384 outrel
.r_addend
= rel
->r_addend
;
3388 /* This symbol is local, or marked to become local. */
3389 if (r_type
== htab
->pointer_r_type
)
3392 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3393 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3399 if (bfd_is_abs_section (sec
))
3401 else if (sec
== NULL
|| sec
->owner
== NULL
)
3403 bfd_set_error (bfd_error_bad_value
);
3410 /* We are turning this relocation into one
3411 against a section symbol. It would be
3412 proper to subtract the symbol's value,
3413 osec->vma, from the emitted reloc addend,
3414 but ld.so expects buggy relocs. */
3415 osec
= sec
->output_section
;
3416 sindx
= elf_section_data (osec
)->dynindx
;
3419 asection
*oi
= htab
->elf
.text_index_section
;
3420 sindx
= elf_section_data (oi
)->dynindx
;
3422 BFD_ASSERT (sindx
!= 0);
3425 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3426 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3430 sreloc
= elf_section_data (input_section
)->sreloc
;
3432 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3434 r
= bfd_reloc_notsupported
;
3435 goto check_relocation_error
;
3438 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3440 /* If this reloc is against an external symbol, we do
3441 not want to fiddle with the addend. Otherwise, we
3442 need to include the symbol value so that it becomes
3443 an addend for the dynamic reloc. */
3450 case R_X86_64_TLSGD
:
3451 case R_X86_64_GOTPC32_TLSDESC
:
3452 case R_X86_64_TLSDESC_CALL
:
3453 case R_X86_64_GOTTPOFF
:
3454 tls_type
= GOT_UNKNOWN
;
3455 if (h
== NULL
&& local_got_offsets
)
3456 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3458 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3460 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3461 input_section
, contents
,
3462 symtab_hdr
, sym_hashes
,
3463 &r_type
, tls_type
, rel
,
3464 relend
, h
, r_symndx
))
3467 if (r_type
== R_X86_64_TPOFF32
)
3469 bfd_vma roff
= rel
->r_offset
;
3471 BFD_ASSERT (! unresolved_reloc
);
3473 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3475 /* GD->LE transition. For 64bit, change
3476 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3477 .word 0x6666; rex64; call __tls_get_addr
3480 leaq foo@tpoff(%rax), %rax
3482 leaq foo@tlsgd(%rip), %rdi
3483 .word 0x6666; rex64; call __tls_get_addr
3486 leaq foo@tpoff(%rax), %rax */
3487 if (ABI_64_P (output_bfd
))
3488 memcpy (contents
+ roff
- 4,
3489 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3492 memcpy (contents
+ roff
- 3,
3493 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3495 bfd_put_32 (output_bfd
,
3496 elf_x86_64_tpoff (info
, relocation
),
3497 contents
+ roff
+ 8);
3498 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3502 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3504 /* GDesc -> LE transition.
3505 It's originally something like:
3506 leaq x@tlsdesc(%rip), %rax
3509 movl $x@tpoff, %rax. */
3511 unsigned int val
, type
;
3513 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3514 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3515 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3516 contents
+ roff
- 3);
3517 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3518 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3519 contents
+ roff
- 1);
3520 bfd_put_32 (output_bfd
,
3521 elf_x86_64_tpoff (info
, relocation
),
3525 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3527 /* GDesc -> LE transition.
3532 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3533 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3536 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3538 /* IE->LE transition:
3539 Originally it can be one of:
3540 movq foo@gottpoff(%rip), %reg
3541 addq foo@gottpoff(%rip), %reg
3544 leaq foo(%reg), %reg
3547 unsigned int val
, type
, reg
;
3549 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3550 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3551 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3557 bfd_put_8 (output_bfd
, 0x49,
3558 contents
+ roff
- 3);
3559 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3560 bfd_put_8 (output_bfd
, 0x41,
3561 contents
+ roff
- 3);
3562 bfd_put_8 (output_bfd
, 0xc7,
3563 contents
+ roff
- 2);
3564 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3565 contents
+ roff
- 1);
3569 /* addq -> addq - addressing with %rsp/%r12 is
3572 bfd_put_8 (output_bfd
, 0x49,
3573 contents
+ roff
- 3);
3574 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3575 bfd_put_8 (output_bfd
, 0x41,
3576 contents
+ roff
- 3);
3577 bfd_put_8 (output_bfd
, 0x81,
3578 contents
+ roff
- 2);
3579 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3580 contents
+ roff
- 1);
3586 bfd_put_8 (output_bfd
, 0x4d,
3587 contents
+ roff
- 3);
3588 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3589 bfd_put_8 (output_bfd
, 0x45,
3590 contents
+ roff
- 3);
3591 bfd_put_8 (output_bfd
, 0x8d,
3592 contents
+ roff
- 2);
3593 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3594 contents
+ roff
- 1);
3596 bfd_put_32 (output_bfd
,
3597 elf_x86_64_tpoff (info
, relocation
),
3605 if (htab
->elf
.sgot
== NULL
)
3610 off
= h
->got
.offset
;
3611 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3615 if (local_got_offsets
== NULL
)
3618 off
= local_got_offsets
[r_symndx
];
3619 offplt
= local_tlsdesc_gotents
[r_symndx
];
3626 Elf_Internal_Rela outrel
;
3630 if (htab
->elf
.srelgot
== NULL
)
3633 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3635 if (GOT_TLS_GDESC_P (tls_type
))
3637 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3638 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3639 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3640 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3641 + htab
->elf
.sgotplt
->output_offset
3643 + htab
->sgotplt_jump_table_size
);
3644 sreloc
= htab
->elf
.srelplt
;
3646 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3648 outrel
.r_addend
= 0;
3649 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3652 sreloc
= htab
->elf
.srelgot
;
3654 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3655 + htab
->elf
.sgot
->output_offset
+ off
);
3657 if (GOT_TLS_GD_P (tls_type
))
3658 dr_type
= R_X86_64_DTPMOD64
;
3659 else if (GOT_TLS_GDESC_P (tls_type
))
3662 dr_type
= R_X86_64_TPOFF64
;
3664 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3665 outrel
.r_addend
= 0;
3666 if ((dr_type
== R_X86_64_TPOFF64
3667 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3668 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3669 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3671 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3673 if (GOT_TLS_GD_P (tls_type
))
3677 BFD_ASSERT (! unresolved_reloc
);
3678 bfd_put_64 (output_bfd
,
3679 relocation
- elf_x86_64_dtpoff_base (info
),
3680 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3684 bfd_put_64 (output_bfd
, 0,
3685 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3686 outrel
.r_info
= htab
->r_info (indx
,
3688 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3689 elf_append_rela (output_bfd
, sreloc
,
3698 local_got_offsets
[r_symndx
] |= 1;
3701 if (off
>= (bfd_vma
) -2
3702 && ! GOT_TLS_GDESC_P (tls_type
))
3704 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3706 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3707 || r_type
== R_X86_64_TLSDESC_CALL
)
3708 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3709 + htab
->elf
.sgotplt
->output_offset
3710 + offplt
+ htab
->sgotplt_jump_table_size
;
3712 relocation
= htab
->elf
.sgot
->output_section
->vma
3713 + htab
->elf
.sgot
->output_offset
+ off
;
3714 unresolved_reloc
= FALSE
;
3718 bfd_vma roff
= rel
->r_offset
;
3720 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3722 /* GD->IE transition. For 64bit, change
3723 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3724 .word 0x6666; rex64; call __tls_get_addr@plt
3727 addq foo@gottpoff(%rip), %rax
3729 leaq foo@tlsgd(%rip), %rdi
3730 .word 0x6666; rex64; call __tls_get_addr@plt
3733 addq foo@gottpoff(%rip), %rax */
3734 if (ABI_64_P (output_bfd
))
3735 memcpy (contents
+ roff
- 4,
3736 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3739 memcpy (contents
+ roff
- 3,
3740 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3743 relocation
= (htab
->elf
.sgot
->output_section
->vma
3744 + htab
->elf
.sgot
->output_offset
+ off
3746 - input_section
->output_section
->vma
3747 - input_section
->output_offset
3749 bfd_put_32 (output_bfd
, relocation
,
3750 contents
+ roff
+ 8);
3751 /* Skip R_X86_64_PLT32. */
3755 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3757 /* GDesc -> IE transition.
3758 It's originally something like:
3759 leaq x@tlsdesc(%rip), %rax
3762 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3764 /* Now modify the instruction as appropriate. To
3765 turn a leaq into a movq in the form we use it, it
3766 suffices to change the second byte from 0x8d to
3768 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3770 bfd_put_32 (output_bfd
,
3771 htab
->elf
.sgot
->output_section
->vma
3772 + htab
->elf
.sgot
->output_offset
+ off
3774 - input_section
->output_section
->vma
3775 - input_section
->output_offset
3780 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3782 /* GDesc -> IE transition.
3789 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3790 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3798 case R_X86_64_TLSLD
:
3799 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3800 input_section
, contents
,
3801 symtab_hdr
, sym_hashes
,
3802 &r_type
, GOT_UNKNOWN
,
3803 rel
, relend
, h
, r_symndx
))
3806 if (r_type
!= R_X86_64_TLSLD
)
3808 /* LD->LE transition:
3809 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3810 For 64bit, we change it into:
3811 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
3812 For 32bit, we change it into:
3813 nopl 0x0(%rax); movl %fs:0, %eax. */
3815 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3816 if (ABI_64_P (output_bfd
))
3817 memcpy (contents
+ rel
->r_offset
- 3,
3818 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3820 memcpy (contents
+ rel
->r_offset
- 3,
3821 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3822 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3827 if (htab
->elf
.sgot
== NULL
)
3830 off
= htab
->tls_ld_got
.offset
;
3835 Elf_Internal_Rela outrel
;
3837 if (htab
->elf
.srelgot
== NULL
)
3840 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3841 + htab
->elf
.sgot
->output_offset
+ off
);
3843 bfd_put_64 (output_bfd
, 0,
3844 htab
->elf
.sgot
->contents
+ off
);
3845 bfd_put_64 (output_bfd
, 0,
3846 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3847 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
3848 outrel
.r_addend
= 0;
3849 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
3851 htab
->tls_ld_got
.offset
|= 1;
3853 relocation
= htab
->elf
.sgot
->output_section
->vma
3854 + htab
->elf
.sgot
->output_offset
+ off
;
3855 unresolved_reloc
= FALSE
;
3858 case R_X86_64_DTPOFF32
:
3859 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
3860 relocation
-= elf_x86_64_dtpoff_base (info
);
3862 relocation
= elf_x86_64_tpoff (info
, relocation
);
3865 case R_X86_64_TPOFF32
:
3866 case R_X86_64_TPOFF64
:
3867 BFD_ASSERT (info
->executable
);
3868 relocation
= elf_x86_64_tpoff (info
, relocation
);
3875 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3876 because such sections are not SEC_ALLOC and thus ld.so will
3877 not process them. */
3878 if (unresolved_reloc
3879 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3881 (*_bfd_error_handler
)
3882 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3885 (long) rel
->r_offset
,
3887 h
->root
.root
.string
);
3890 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3891 contents
, rel
->r_offset
,
3892 relocation
, rel
->r_addend
);
3894 check_relocation_error
:
3895 if (r
!= bfd_reloc_ok
)
3900 name
= h
->root
.root
.string
;
3903 name
= bfd_elf_string_from_elf_section (input_bfd
,
3904 symtab_hdr
->sh_link
,
3909 name
= bfd_section_name (input_bfd
, sec
);
3912 if (r
== bfd_reloc_overflow
)
3914 if (! ((*info
->callbacks
->reloc_overflow
)
3915 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3916 (bfd_vma
) 0, input_bfd
, input_section
,
3922 (*_bfd_error_handler
)
3923 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3924 input_bfd
, input_section
,
3925 (long) rel
->r_offset
, name
, (int) r
);
3934 /* Finish up dynamic symbol handling. We set the contents of various
3935 dynamic sections here. */
3938 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3939 struct bfd_link_info
*info
,
3940 struct elf_link_hash_entry
*h
,
3941 Elf_Internal_Sym
*sym
)
3943 struct elf_x86_64_link_hash_table
*htab
;
3945 htab
= elf_x86_64_hash_table (info
);
3949 if (h
->plt
.offset
!= (bfd_vma
) -1)
3953 Elf_Internal_Rela rela
;
3955 asection
*plt
, *gotplt
, *relplt
;
3956 const struct elf_backend_data
*bed
;
3958 /* When building a static executable, use .iplt, .igot.plt and
3959 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3960 if (htab
->elf
.splt
!= NULL
)
3962 plt
= htab
->elf
.splt
;
3963 gotplt
= htab
->elf
.sgotplt
;
3964 relplt
= htab
->elf
.srelplt
;
3968 plt
= htab
->elf
.iplt
;
3969 gotplt
= htab
->elf
.igotplt
;
3970 relplt
= htab
->elf
.irelplt
;
3973 /* This symbol has an entry in the procedure linkage table. Set
3975 if ((h
->dynindx
== -1
3976 && !((h
->forced_local
|| info
->executable
)
3978 && h
->type
== STT_GNU_IFUNC
))
3984 /* Get the index in the procedure linkage table which
3985 corresponds to this symbol. This is the index of this symbol
3986 in all the symbols for which we are making plt entries. The
3987 first entry in the procedure linkage table is reserved.
3989 Get the offset into the .got table of the entry that
3990 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3991 bytes. The first three are reserved for the dynamic linker.
3993 For static executables, we don't reserve anything. */
3995 if (plt
== htab
->elf
.splt
)
3997 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3998 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4002 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4003 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
4006 /* Fill in the entry in the procedure linkage table. */
4007 memcpy (plt
->contents
+ h
->plt
.offset
, elf_x86_64_plt_entry
,
4010 /* Insert the relocation positions of the plt section. The magic
4011 numbers at the end of the statements are the positions of the
4012 relocations in the plt section. */
4013 /* Put offset for jmp *name@GOTPCREL(%rip), since the
4014 instruction uses 6 bytes, subtract this value. */
4015 bfd_put_32 (output_bfd
,
4016 (gotplt
->output_section
->vma
4017 + gotplt
->output_offset
4019 - plt
->output_section
->vma
4020 - plt
->output_offset
4023 plt
->contents
+ h
->plt
.offset
+ 2);
4025 /* Don't fill PLT entry for static executables. */
4026 if (plt
== htab
->elf
.splt
)
4028 /* Put relocation index. */
4029 bfd_put_32 (output_bfd
, plt_index
,
4030 plt
->contents
+ h
->plt
.offset
+ 7);
4031 /* Put offset for jmp .PLT0. */
4032 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4033 plt
->contents
+ h
->plt
.offset
+ 12);
4036 /* Fill in the entry in the global offset table, initially this
4037 points to the pushq instruction in the PLT which is at offset 6. */
4038 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4039 + plt
->output_offset
4040 + h
->plt
.offset
+ 6),
4041 gotplt
->contents
+ got_offset
);
4043 /* Fill in the entry in the .rela.plt section. */
4044 rela
.r_offset
= (gotplt
->output_section
->vma
4045 + gotplt
->output_offset
4047 if (h
->dynindx
== -1
4048 || ((info
->executable
4049 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4051 && h
->type
== STT_GNU_IFUNC
))
4053 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4054 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4055 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4056 rela
.r_addend
= (h
->root
.u
.def
.value
4057 + h
->root
.u
.def
.section
->output_section
->vma
4058 + h
->root
.u
.def
.section
->output_offset
);
4062 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4066 bed
= get_elf_backend_data (output_bfd
);
4067 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4068 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4070 if (!h
->def_regular
)
4072 /* Mark the symbol as undefined, rather than as defined in
4073 the .plt section. Leave the value if there were any
4074 relocations where pointer equality matters (this is a clue
4075 for the dynamic linker, to make function pointer
4076 comparisons work between an application and shared
4077 library), otherwise set it to zero. If a function is only
4078 called from a binary, there is no need to slow down
4079 shared libraries because of that. */
4080 sym
->st_shndx
= SHN_UNDEF
;
4081 if (!h
->pointer_equality_needed
)
4086 if (h
->got
.offset
!= (bfd_vma
) -1
4087 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4088 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4090 Elf_Internal_Rela rela
;
4092 /* This symbol has an entry in the global offset table. Set it
4094 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4097 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4098 + htab
->elf
.sgot
->output_offset
4099 + (h
->got
.offset
&~ (bfd_vma
) 1));
4101 /* If this is a static link, or it is a -Bsymbolic link and the
4102 symbol is defined locally or was forced to be local because
4103 of a version file, we just want to emit a RELATIVE reloc.
4104 The entry in the global offset table will already have been
4105 initialized in the relocate_section function. */
4107 && h
->type
== STT_GNU_IFUNC
)
4111 /* Generate R_X86_64_GLOB_DAT. */
4118 if (!h
->pointer_equality_needed
)
4121 /* For non-shared object, we can't use .got.plt, which
4122 contains the real function addres if we need pointer
4123 equality. We load the GOT entry with the PLT entry. */
4124 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4125 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4126 + plt
->output_offset
4128 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4132 else if (info
->shared
4133 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4135 if (!h
->def_regular
)
4137 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4138 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4139 rela
.r_addend
= (h
->root
.u
.def
.value
4140 + h
->root
.u
.def
.section
->output_section
->vma
4141 + h
->root
.u
.def
.section
->output_offset
);
4145 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4147 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4148 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4149 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4153 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4158 Elf_Internal_Rela rela
;
4160 /* This symbol needs a copy reloc. Set it up. */
4162 if (h
->dynindx
== -1
4163 || (h
->root
.type
!= bfd_link_hash_defined
4164 && h
->root
.type
!= bfd_link_hash_defweak
)
4165 || htab
->srelbss
== NULL
)
4168 rela
.r_offset
= (h
->root
.u
.def
.value
4169 + h
->root
.u
.def
.section
->output_section
->vma
4170 + h
->root
.u
.def
.section
->output_offset
);
4171 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4173 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4176 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4177 be NULL for local symbols. */
4179 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4180 || h
== htab
->elf
.hgot
))
4181 sym
->st_shndx
= SHN_ABS
;
4186 /* Finish up local dynamic symbol handling. We set the contents of
4187 various dynamic sections here. */
4190 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4192 struct elf_link_hash_entry
*h
4193 = (struct elf_link_hash_entry
*) *slot
;
4194 struct bfd_link_info
*info
4195 = (struct bfd_link_info
*) inf
;
4197 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4201 /* Used to decide how to sort relocs in an optimal manner for the
4202 dynamic linker, before writing them out. */
4204 static enum elf_reloc_type_class
4205 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4207 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4209 case R_X86_64_RELATIVE
:
4210 return reloc_class_relative
;
4211 case R_X86_64_JUMP_SLOT
:
4212 return reloc_class_plt
;
4214 return reloc_class_copy
;
4216 return reloc_class_normal
;
4220 /* Finish up the dynamic sections. */
4223 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4224 struct bfd_link_info
*info
)
4226 struct elf_x86_64_link_hash_table
*htab
;
4230 htab
= elf_x86_64_hash_table (info
);
4234 dynobj
= htab
->elf
.dynobj
;
4235 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4237 if (htab
->elf
.dynamic_sections_created
)
4239 bfd_byte
*dyncon
, *dynconend
;
4240 const struct elf_backend_data
*bed
;
4241 bfd_size_type sizeof_dyn
;
4243 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4246 bed
= get_elf_backend_data (dynobj
);
4247 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4248 dyncon
= sdyn
->contents
;
4249 dynconend
= sdyn
->contents
+ sdyn
->size
;
4250 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4252 Elf_Internal_Dyn dyn
;
4255 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4263 s
= htab
->elf
.sgotplt
;
4264 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4268 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4272 s
= htab
->elf
.srelplt
->output_section
;
4273 dyn
.d_un
.d_val
= s
->size
;
4277 /* The procedure linkage table relocs (DT_JMPREL) should
4278 not be included in the overall relocs (DT_RELA).
4279 Therefore, we override the DT_RELASZ entry here to
4280 make it not include the JMPREL relocs. Since the
4281 linker script arranges for .rela.plt to follow all
4282 other relocation sections, we don't have to worry
4283 about changing the DT_RELA entry. */
4284 if (htab
->elf
.srelplt
!= NULL
)
4286 s
= htab
->elf
.srelplt
->output_section
;
4287 dyn
.d_un
.d_val
-= s
->size
;
4291 case DT_TLSDESC_PLT
:
4293 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4294 + htab
->tlsdesc_plt
;
4297 case DT_TLSDESC_GOT
:
4299 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4300 + htab
->tlsdesc_got
;
4304 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4307 /* Fill in the special first entry in the procedure linkage table. */
4308 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4310 /* Fill in the first entry in the procedure linkage table. */
4311 memcpy (htab
->elf
.splt
->contents
, elf_x86_64_plt0_entry
,
4313 /* Add offset for pushq GOT+8(%rip), since the instruction
4314 uses 6 bytes subtract this value. */
4315 bfd_put_32 (output_bfd
,
4316 (htab
->elf
.sgotplt
->output_section
->vma
4317 + htab
->elf
.sgotplt
->output_offset
4319 - htab
->elf
.splt
->output_section
->vma
4320 - htab
->elf
.splt
->output_offset
4322 htab
->elf
.splt
->contents
+ 2);
4323 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4324 the end of the instruction. */
4325 bfd_put_32 (output_bfd
,
4326 (htab
->elf
.sgotplt
->output_section
->vma
4327 + htab
->elf
.sgotplt
->output_offset
4329 - htab
->elf
.splt
->output_section
->vma
4330 - htab
->elf
.splt
->output_offset
4332 htab
->elf
.splt
->contents
+ 8);
4334 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
=
4337 if (htab
->tlsdesc_plt
)
4339 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4340 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4342 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4343 elf_x86_64_plt0_entry
,
4346 /* Add offset for pushq GOT+8(%rip), since the
4347 instruction uses 6 bytes subtract this value. */
4348 bfd_put_32 (output_bfd
,
4349 (htab
->elf
.sgotplt
->output_section
->vma
4350 + htab
->elf
.sgotplt
->output_offset
4352 - htab
->elf
.splt
->output_section
->vma
4353 - htab
->elf
.splt
->output_offset
4356 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 2);
4357 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4358 htab->tlsdesc_got. The 12 is the offset to the end of
4360 bfd_put_32 (output_bfd
,
4361 (htab
->elf
.sgot
->output_section
->vma
4362 + htab
->elf
.sgot
->output_offset
4364 - htab
->elf
.splt
->output_section
->vma
4365 - htab
->elf
.splt
->output_offset
4368 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
4373 if (htab
->elf
.sgotplt
)
4375 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4377 (*_bfd_error_handler
)
4378 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4382 /* Fill in the first three entries in the global offset table. */
4383 if (htab
->elf
.sgotplt
->size
> 0)
4385 /* Set the first entry in the global offset table to the address of
4386 the dynamic section. */
4388 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4390 bfd_put_64 (output_bfd
,
4391 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4392 htab
->elf
.sgotplt
->contents
);
4393 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4394 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4395 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4398 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4402 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4403 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4406 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4407 htab_traverse (htab
->loc_hash_table
,
4408 elf_x86_64_finish_local_dynamic_symbol
,
4414 /* Return address for Ith PLT stub in section PLT, for relocation REL
4415 or (bfd_vma) -1 if it should not be included. */
4418 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4419 const arelent
*rel ATTRIBUTE_UNUSED
)
4421 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4424 /* Handle an x86-64 specific section when reading an object file. This
4425 is called when elfcode.h finds a section with an unknown type. */
4428 elf_x86_64_section_from_shdr (bfd
*abfd
,
4429 Elf_Internal_Shdr
*hdr
,
4433 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4436 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4442 /* Hook called by the linker routine which adds symbols from an object
4443 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4447 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4448 struct bfd_link_info
*info
,
4449 Elf_Internal_Sym
*sym
,
4450 const char **namep ATTRIBUTE_UNUSED
,
4451 flagword
*flagsp ATTRIBUTE_UNUSED
,
4457 switch (sym
->st_shndx
)
4459 case SHN_X86_64_LCOMMON
:
4460 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4463 lcomm
= bfd_make_section_with_flags (abfd
,
4467 | SEC_LINKER_CREATED
));
4470 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4473 *valp
= sym
->st_size
;
4477 if ((abfd
->flags
& DYNAMIC
) == 0
4478 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4479 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4480 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4486 /* Given a BFD section, try to locate the corresponding ELF section
4490 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4491 asection
*sec
, int *index_return
)
4493 if (sec
== &_bfd_elf_large_com_section
)
4495 *index_return
= SHN_X86_64_LCOMMON
;
4501 /* Process a symbol. */
4504 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4507 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4509 switch (elfsym
->internal_elf_sym
.st_shndx
)
4511 case SHN_X86_64_LCOMMON
:
4512 asym
->section
= &_bfd_elf_large_com_section
;
4513 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4514 /* Common symbol doesn't set BSF_GLOBAL. */
4515 asym
->flags
&= ~BSF_GLOBAL
;
4521 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4523 return (sym
->st_shndx
== SHN_COMMON
4524 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4528 elf_x86_64_common_section_index (asection
*sec
)
4530 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4533 return SHN_X86_64_LCOMMON
;
4537 elf_x86_64_common_section (asection
*sec
)
4539 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4540 return bfd_com_section_ptr
;
4542 return &_bfd_elf_large_com_section
;
4546 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4547 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4548 struct elf_link_hash_entry
*h
,
4549 Elf_Internal_Sym
*sym
,
4551 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4552 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4553 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4554 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4555 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4556 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4557 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4558 bfd_boolean
*newdef
,
4559 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4560 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4561 bfd
*abfd ATTRIBUTE_UNUSED
,
4563 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4564 bfd_boolean
*olddef
,
4565 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4566 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4570 /* A normal common symbol and a large common symbol result in a
4571 normal common symbol. We turn the large common symbol into a
4574 && h
->root
.type
== bfd_link_hash_common
4576 && bfd_is_com_section (*sec
)
4579 if (sym
->st_shndx
== SHN_COMMON
4580 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4582 h
->root
.u
.c
.p
->section
4583 = bfd_make_section_old_way (oldbfd
, "COMMON");
4584 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4586 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4587 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4588 *psec
= *sec
= bfd_com_section_ptr
;
4595 elf_x86_64_additional_program_headers (bfd
*abfd
,
4596 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4601 /* Check to see if we need a large readonly segment. */
4602 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4603 if (s
&& (s
->flags
& SEC_LOAD
))
4606 /* Check to see if we need a large data segment. Since .lbss sections
4607 is placed right after the .bss section, there should be no need for
4608 a large data segment just because of .lbss. */
4609 s
= bfd_get_section_by_name (abfd
, ".ldata");
4610 if (s
&& (s
->flags
& SEC_LOAD
))
4616 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4619 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4621 if (h
->plt
.offset
!= (bfd_vma
) -1
4623 && !h
->pointer_equality_needed
)
4626 return _bfd_elf_hash_symbol (h
);
4629 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4632 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4633 const bfd_target
*output
)
4635 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4636 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4637 && _bfd_elf_relocs_compatible (input
, output
));
4640 static const struct bfd_elf_special_section
4641 elf_x86_64_special_sections
[]=
4643 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4644 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4645 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4646 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4647 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4648 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4649 { NULL
, 0, 0, 0, 0 }
4652 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4653 #define TARGET_LITTLE_NAME "elf64-x86-64"
4654 #define ELF_ARCH bfd_arch_i386
4655 #define ELF_TARGET_ID X86_64_ELF_DATA
4656 #define ELF_MACHINE_CODE EM_X86_64
4657 #define ELF_MAXPAGESIZE 0x200000
4658 #define ELF_MINPAGESIZE 0x1000
4659 #define ELF_COMMONPAGESIZE 0x1000
4661 #define elf_backend_can_gc_sections 1
4662 #define elf_backend_can_refcount 1
4663 #define elf_backend_want_got_plt 1
4664 #define elf_backend_plt_readonly 1
4665 #define elf_backend_want_plt_sym 0
4666 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4667 #define elf_backend_rela_normal 1
4669 #define elf_info_to_howto elf_x86_64_info_to_howto
4671 #define bfd_elf64_bfd_link_hash_table_create \
4672 elf_x86_64_link_hash_table_create
4673 #define bfd_elf64_bfd_link_hash_table_free \
4674 elf_x86_64_link_hash_table_free
4675 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4676 #define bfd_elf64_bfd_reloc_name_lookup \
4677 elf_x86_64_reloc_name_lookup
4679 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4680 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4681 #define elf_backend_check_relocs elf_x86_64_check_relocs
4682 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
4683 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
4684 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
4685 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
4686 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
4687 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
4688 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
4689 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
4690 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
4691 #define elf_backend_relocate_section elf_x86_64_relocate_section
4692 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
4693 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
4694 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4695 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
4696 #define elf_backend_object_p elf64_x86_64_elf_object_p
4697 #define bfd_elf64_mkobject elf_x86_64_mkobject
4699 #define elf_backend_section_from_shdr \
4700 elf_x86_64_section_from_shdr
4702 #define elf_backend_section_from_bfd_section \
4703 elf_x86_64_elf_section_from_bfd_section
4704 #define elf_backend_add_symbol_hook \
4705 elf_x86_64_add_symbol_hook
4706 #define elf_backend_symbol_processing \
4707 elf_x86_64_symbol_processing
4708 #define elf_backend_common_section_index \
4709 elf_x86_64_common_section_index
4710 #define elf_backend_common_section \
4711 elf_x86_64_common_section
4712 #define elf_backend_common_definition \
4713 elf_x86_64_common_definition
4714 #define elf_backend_merge_symbol \
4715 elf_x86_64_merge_symbol
4716 #define elf_backend_special_sections \
4717 elf_x86_64_special_sections
4718 #define elf_backend_additional_program_headers \
4719 elf_x86_64_additional_program_headers
4720 #define elf_backend_hash_symbol \
4721 elf_x86_64_hash_symbol
4723 #undef elf_backend_post_process_headers
4724 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4726 #include "elf64-target.h"
4728 /* FreeBSD support. */
4730 #undef TARGET_LITTLE_SYM
4731 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4732 #undef TARGET_LITTLE_NAME
4733 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4736 #define ELF_OSABI ELFOSABI_FREEBSD
4739 #define elf64_bed elf64_x86_64_fbsd_bed
4741 #include "elf64-target.h"
4743 /* Solaris 2 support. */
4745 #undef TARGET_LITTLE_SYM
4746 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4747 #undef TARGET_LITTLE_NAME
4748 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4750 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4751 objects won't be recognized. */
4755 #define elf64_bed elf64_x86_64_sol2_bed
4757 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
4759 #undef elf_backend_static_tls_alignment
4760 #define elf_backend_static_tls_alignment 16
4762 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4764 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4766 #undef elf_backend_want_plt_sym
4767 #define elf_backend_want_plt_sym 1
4769 #include "elf64-target.h"
4771 /* Intel L1OM support. */
4774 elf64_l1om_elf_object_p (bfd
*abfd
)
4776 /* Set the right machine number for an L1OM elf64 file. */
4777 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
4781 #undef TARGET_LITTLE_SYM
4782 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
4783 #undef TARGET_LITTLE_NAME
4784 #define TARGET_LITTLE_NAME "elf64-l1om"
4786 #define ELF_ARCH bfd_arch_l1om
4788 #undef ELF_MACHINE_CODE
4789 #define ELF_MACHINE_CODE EM_L1OM
4794 #define elf64_bed elf64_l1om_bed
4796 #undef elf_backend_object_p
4797 #define elf_backend_object_p elf64_l1om_elf_object_p
4799 #undef elf_backend_post_process_headers
4800 #undef elf_backend_static_tls_alignment
4802 #undef elf_backend_want_plt_sym
4803 #define elf_backend_want_plt_sym 0
4805 #include "elf64-target.h"
4807 /* FreeBSD L1OM support. */
4809 #undef TARGET_LITTLE_SYM
4810 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
4811 #undef TARGET_LITTLE_NAME
4812 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
4815 #define ELF_OSABI ELFOSABI_FREEBSD
4818 #define elf64_bed elf64_l1om_fbsd_bed
4820 #undef elf_backend_post_process_headers
4821 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4823 #include "elf64-target.h"
4825 /* 32bit x86-64 support. */
4828 elf32_x86_64_elf_object_p (bfd
*abfd
)
4830 /* Set the right machine number for an x86-64 elf32 file. */
4831 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
4835 #undef TARGET_LITTLE_SYM
4836 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
4837 #undef TARGET_LITTLE_NAME
4838 #define TARGET_LITTLE_NAME "elf32-x86-64"
4841 #define ELF_ARCH bfd_arch_i386
4843 #undef ELF_MACHINE_CODE
4844 #define ELF_MACHINE_CODE EM_X86_64
4846 #define bfd_elf32_bfd_link_hash_table_create \
4847 elf_x86_64_link_hash_table_create
4848 #define bfd_elf32_bfd_link_hash_table_free \
4849 elf_x86_64_link_hash_table_free
4850 #define bfd_elf32_bfd_reloc_type_lookup \
4851 elf_x86_64_reloc_type_lookup
4852 #define bfd_elf32_bfd_reloc_name_lookup \
4853 elf_x86_64_reloc_name_lookup
4854 #define bfd_elf32_mkobject \
4859 #undef elf_backend_post_process_headers
4861 #undef elf_backend_object_p
4862 #define elf_backend_object_p \
4863 elf32_x86_64_elf_object_p
4865 #undef elf_backend_bfd_from_remote_memory
4866 #define elf_backend_bfd_from_remote_memory \
4867 _bfd_elf32_bfd_from_remote_memory
4869 #undef elf_backend_size_info
4870 #define elf_backend_size_info \
4871 _bfd_elf32_size_info
4873 #include "elf32-target.h"