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. */
30 #include "bfd_stdint.h"
34 #include "libiberty.h"
36 #include "elf/x86-64.h"
43 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
44 #define MINUS_ONE (~ (bfd_vma) 0)
46 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
47 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
48 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
49 since they are the same. */
51 #define ABI_64_P(abfd) \
52 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
54 /* The relocation "howto" table. Order of fields:
55 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
56 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
57 static reloc_howto_type x86_64_elf_howto_table
[] =
59 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
60 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
62 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
65 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
66 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
68 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
69 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
71 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
72 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
74 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
75 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
77 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
78 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
80 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
81 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
83 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
86 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
87 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
89 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
90 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
92 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
93 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
95 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
97 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
98 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
99 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
100 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
101 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
102 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
103 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
104 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
106 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
107 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
109 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
110 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
112 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
113 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
115 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
116 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
118 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
119 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
121 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
122 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
124 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
125 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
127 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
128 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
130 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
131 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
132 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
133 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
134 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
135 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
136 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
137 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
139 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
140 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
142 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
143 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
144 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
145 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
146 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
148 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
149 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
151 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
152 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
154 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
155 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
157 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
158 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
159 "R_X86_64_GOTPC32_TLSDESC",
160 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
161 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
162 complain_overflow_dont
, bfd_elf_generic_reloc
,
163 "R_X86_64_TLSDESC_CALL",
165 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
166 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
168 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
169 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
170 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
172 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
173 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
175 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
176 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
178 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
179 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
182 /* We have a gap in the reloc numbers here.
183 R_X86_64_standard counts the number up to this point, and
184 R_X86_64_vt_offset is the value to subtract from a reloc type of
185 R_X86_64_GNU_VT* to form an index into this table. */
186 #define R_X86_64_standard (R_X86_64_PLT32_BND + 1)
187 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
189 /* GNU extension to record C++ vtable hierarchy. */
190 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
191 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
193 /* GNU extension to record C++ vtable member usage. */
194 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
195 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
198 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
199 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
200 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
204 #define IS_X86_64_PCREL_TYPE(TYPE) \
205 ( ((TYPE) == R_X86_64_PC8) \
206 || ((TYPE) == R_X86_64_PC16) \
207 || ((TYPE) == R_X86_64_PC32) \
208 || ((TYPE) == R_X86_64_PC32_BND) \
209 || ((TYPE) == R_X86_64_PC64))
211 /* Map BFD relocs to the x86_64 elf relocs. */
214 bfd_reloc_code_real_type bfd_reloc_val
;
215 unsigned char elf_reloc_val
;
218 static const struct elf_reloc_map x86_64_reloc_map
[] =
220 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
221 { BFD_RELOC_64
, R_X86_64_64
, },
222 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
223 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
224 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
225 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
226 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
227 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
228 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
229 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
230 { BFD_RELOC_32
, R_X86_64_32
, },
231 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
232 { BFD_RELOC_16
, R_X86_64_16
, },
233 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
234 { BFD_RELOC_8
, R_X86_64_8
, },
235 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
236 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
237 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
238 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
239 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
240 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
241 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
242 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
243 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
244 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
245 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
246 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
247 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
248 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
249 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
250 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
251 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
252 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
253 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
254 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
255 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
256 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
257 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
258 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
,},
259 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
,},
260 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
261 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
264 static reloc_howto_type
*
265 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
269 if (r_type
== (unsigned int) R_X86_64_32
)
274 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
276 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
277 || r_type
>= (unsigned int) R_X86_64_max
)
279 if (r_type
>= (unsigned int) R_X86_64_standard
)
281 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
283 r_type
= R_X86_64_NONE
;
288 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
289 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
290 return &x86_64_elf_howto_table
[i
];
293 /* Given a BFD reloc type, return a HOWTO structure. */
294 static reloc_howto_type
*
295 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
296 bfd_reloc_code_real_type code
)
300 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
303 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
304 return elf_x86_64_rtype_to_howto (abfd
,
305 x86_64_reloc_map
[i
].elf_reloc_val
);
310 static reloc_howto_type
*
311 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
316 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
318 /* Get x32 R_X86_64_32. */
319 reloc_howto_type
*reloc
320 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
321 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
325 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
326 if (x86_64_elf_howto_table
[i
].name
!= NULL
327 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
328 return &x86_64_elf_howto_table
[i
];
333 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
336 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
337 Elf_Internal_Rela
*dst
)
341 r_type
= ELF32_R_TYPE (dst
->r_info
);
342 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
343 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
346 /* Support for core dump NOTE sections. */
348 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
353 switch (note
->descsz
)
358 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
360 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
363 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
371 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
373 elf_tdata (abfd
)->core
->signal
374 = bfd_get_16 (abfd
, note
->descdata
+ 12);
377 elf_tdata (abfd
)->core
->lwpid
378 = bfd_get_32 (abfd
, note
->descdata
+ 32);
387 /* Make a ".reg/999" section. */
388 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
389 size
, note
->descpos
+ offset
);
393 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
395 switch (note
->descsz
)
400 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
401 elf_tdata (abfd
)->core
->pid
402 = bfd_get_32 (abfd
, note
->descdata
+ 12);
403 elf_tdata (abfd
)->core
->program
404 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
405 elf_tdata (abfd
)->core
->command
406 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
409 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
410 elf_tdata (abfd
)->core
->pid
411 = bfd_get_32 (abfd
, note
->descdata
+ 24);
412 elf_tdata (abfd
)->core
->program
413 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
414 elf_tdata (abfd
)->core
->command
415 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
418 /* Note that for some reason, a spurious space is tacked
419 onto the end of the args in some (at least one anyway)
420 implementations, so strip it off if it exists. */
423 char *command
= elf_tdata (abfd
)->core
->command
;
424 int n
= strlen (command
);
426 if (0 < n
&& command
[n
- 1] == ' ')
427 command
[n
- 1] = '\0';
435 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
438 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
440 const char *fname
, *psargs
;
451 va_start (ap
, note_type
);
452 fname
= va_arg (ap
, const char *);
453 psargs
= va_arg (ap
, const char *);
456 if (bed
->s
->elfclass
== ELFCLASS32
)
459 memset (&data
, 0, sizeof (data
));
460 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
461 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
462 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
463 &data
, sizeof (data
));
468 memset (&data
, 0, sizeof (data
));
469 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
470 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
471 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
472 &data
, sizeof (data
));
477 va_start (ap
, note_type
);
478 pid
= va_arg (ap
, long);
479 cursig
= va_arg (ap
, int);
480 gregs
= va_arg (ap
, const void *);
483 if (bed
->s
->elfclass
== ELFCLASS32
)
485 if (bed
->elf_machine_code
== EM_X86_64
)
487 prstatusx32_t prstat
;
488 memset (&prstat
, 0, sizeof (prstat
));
490 prstat
.pr_cursig
= cursig
;
491 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
492 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
493 &prstat
, sizeof (prstat
));
498 memset (&prstat
, 0, sizeof (prstat
));
500 prstat
.pr_cursig
= cursig
;
501 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
502 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
503 &prstat
, sizeof (prstat
));
509 memset (&prstat
, 0, sizeof (prstat
));
511 prstat
.pr_cursig
= cursig
;
512 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
513 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
514 &prstat
, sizeof (prstat
));
521 /* Functions for the x86-64 ELF linker. */
523 /* The name of the dynamic interpreter. This is put in the .interp
526 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
527 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
529 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
530 copying dynamic variables from a shared lib into an app's dynbss
531 section, and instead use a dynamic relocation to point into the
533 #define ELIMINATE_COPY_RELOCS 1
535 /* The size in bytes of an entry in the global offset table. */
537 #define GOT_ENTRY_SIZE 8
539 /* The size in bytes of an entry in the procedure linkage table. */
541 #define PLT_ENTRY_SIZE 16
543 /* The first entry in a procedure linkage table looks like this. See the
544 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
546 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
548 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
549 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
550 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
553 /* Subsequent entries in a procedure linkage table look like this. */
555 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
557 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
558 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
559 0x68, /* pushq immediate */
560 0, 0, 0, 0, /* replaced with index into relocation table. */
561 0xe9, /* jmp relative */
562 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
565 /* The first entry in a procedure linkage table with BND relocations
568 static const bfd_byte elf_x86_64_bnd_plt0_entry
[PLT_ENTRY_SIZE
] =
570 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
571 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
572 0x0f, 0x1f, 0 /* nopl (%rax) */
575 /* Subsequent entries for legacy branches in a procedure linkage table
576 with BND relocations look like this. */
578 static const bfd_byte elf_x86_64_legacy_plt_entry
[PLT_ENTRY_SIZE
] =
580 0x68, 0, 0, 0, 0, /* pushq immediate */
581 0xe9, 0, 0, 0, 0, /* jmpq relative */
582 0x66, 0x0f, 0x1f, 0x44, 0, 0 /* nopw (%rax,%rax,1) */
585 /* Subsequent entries for branches with BND prefx in a procedure linkage
586 table with BND relocations look like this. */
588 static const bfd_byte elf_x86_64_bnd_plt_entry
[PLT_ENTRY_SIZE
] =
590 0x68, 0, 0, 0, 0, /* pushq immediate */
591 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
592 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
595 /* Entries for legacy branches in the second procedure linkage table
598 static const bfd_byte elf_x86_64_legacy_plt2_entry
[8] =
600 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
601 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
602 0x66, 0x90 /* xchg %ax,%ax */
605 /* Entries for branches with BND prefix in the second procedure linkage
606 table look like this. */
608 static const bfd_byte elf_x86_64_bnd_plt2_entry
[8] =
610 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
611 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
615 /* .eh_frame covering the .plt section. */
617 static const bfd_byte elf_x86_64_eh_frame_plt
[] =
619 #define PLT_CIE_LENGTH 20
620 #define PLT_FDE_LENGTH 36
621 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
622 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
623 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
624 0, 0, 0, 0, /* CIE ID */
626 'z', 'R', 0, /* Augmentation string */
627 1, /* Code alignment factor */
628 0x78, /* Data alignment factor */
629 16, /* Return address column */
630 1, /* Augmentation size */
631 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
632 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
633 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
634 DW_CFA_nop
, DW_CFA_nop
,
636 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
637 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
638 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
639 0, 0, 0, 0, /* .plt size goes here */
640 0, /* Augmentation size */
641 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
642 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
643 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
644 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
645 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
646 11, /* Block length */
647 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
648 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
649 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
650 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
651 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
654 /* Architecture-specific backend data for x86-64. */
656 struct elf_x86_64_backend_data
658 /* Templates for the initial PLT entry and for subsequent entries. */
659 const bfd_byte
*plt0_entry
;
660 const bfd_byte
*plt_entry
;
661 unsigned int plt_entry_size
; /* Size of each PLT entry. */
663 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
664 unsigned int plt0_got1_offset
;
665 unsigned int plt0_got2_offset
;
667 /* Offset of the end of the PC-relative instruction containing
669 unsigned int plt0_got2_insn_end
;
671 /* Offsets into plt_entry that are to be replaced with... */
672 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
673 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
674 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
676 /* Length of the PC-relative instruction containing plt_got_offset. */
677 unsigned int plt_got_insn_size
;
679 /* Offset of the end of the PC-relative jump to plt0_entry. */
680 unsigned int plt_plt_insn_end
;
682 /* Offset into plt_entry where the initial value of the GOT entry points. */
683 unsigned int plt_lazy_offset
;
685 /* .eh_frame covering the .plt section. */
686 const bfd_byte
*eh_frame_plt
;
687 unsigned int eh_frame_plt_size
;
690 #define get_elf_x86_64_arch_data(bed) \
691 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
693 #define get_elf_x86_64_backend_data(abfd) \
694 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
696 #define GET_PLT_ENTRY_SIZE(abfd) \
697 get_elf_x86_64_backend_data (abfd)->plt_entry_size
699 /* These are the standard parameters. */
700 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
702 elf_x86_64_plt0_entry
, /* plt0_entry */
703 elf_x86_64_plt_entry
, /* plt_entry */
704 sizeof (elf_x86_64_plt_entry
), /* plt_entry_size */
705 2, /* plt0_got1_offset */
706 8, /* plt0_got2_offset */
707 12, /* plt0_got2_insn_end */
708 2, /* plt_got_offset */
709 7, /* plt_reloc_offset */
710 12, /* plt_plt_offset */
711 6, /* plt_got_insn_size */
712 PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
713 6, /* plt_lazy_offset */
714 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
715 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
718 static const struct elf_x86_64_backend_data elf_x86_64_bnd_arch_bed
=
720 elf_x86_64_bnd_plt0_entry
, /* plt0_entry */
721 elf_x86_64_bnd_plt_entry
, /* plt_entry */
722 sizeof (elf_x86_64_bnd_plt_entry
), /* plt_entry_size */
723 2, /* plt0_got1_offset */
724 1+8, /* plt0_got2_offset */
725 1+12, /* plt0_got2_insn_end */
726 1+2, /* plt_got_offset */
727 1, /* plt_reloc_offset */
728 7, /* plt_plt_offset */
729 1+6, /* plt_got_insn_size */
730 11, /* plt_plt_insn_end */
731 0, /* plt_lazy_offset */
732 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
733 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
736 #define elf_backend_arch_data &elf_x86_64_arch_bed
738 /* x86-64 ELF linker hash entry. */
740 struct elf_x86_64_link_hash_entry
742 struct elf_link_hash_entry elf
;
744 /* Track dynamic relocs copied for this symbol. */
745 struct elf_dyn_relocs
*dyn_relocs
;
747 #define GOT_UNKNOWN 0
751 #define GOT_TLS_GDESC 4
752 #define GOT_TLS_GD_BOTH_P(type) \
753 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
754 #define GOT_TLS_GD_P(type) \
755 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
756 #define GOT_TLS_GDESC_P(type) \
757 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
758 #define GOT_TLS_GD_ANY_P(type) \
759 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
760 unsigned char tls_type
;
762 /* TRUE if symbol has at least one BND relocation. */
763 bfd_boolean has_bnd_reloc
;
765 /* Information about the second PLT entry. Filled when has_bnd_reloc is
767 union gotplt_union plt_bnd
;
769 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
770 starting at the end of the jump table. */
774 #define elf_x86_64_hash_entry(ent) \
775 ((struct elf_x86_64_link_hash_entry *)(ent))
777 struct elf_x86_64_obj_tdata
779 struct elf_obj_tdata root
;
781 /* tls_type for each local got entry. */
782 char *local_got_tls_type
;
784 /* GOTPLT entries for TLS descriptors. */
785 bfd_vma
*local_tlsdesc_gotent
;
788 #define elf_x86_64_tdata(abfd) \
789 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
791 #define elf_x86_64_local_got_tls_type(abfd) \
792 (elf_x86_64_tdata (abfd)->local_got_tls_type)
794 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
795 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
797 #define is_x86_64_elf(bfd) \
798 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
799 && elf_tdata (bfd) != NULL \
800 && elf_object_id (bfd) == X86_64_ELF_DATA)
803 elf_x86_64_mkobject (bfd
*abfd
)
805 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
809 /* x86-64 ELF linker hash table. */
811 struct elf_x86_64_link_hash_table
813 struct elf_link_hash_table elf
;
815 /* Short-cuts to get to dynamic linker sections. */
818 asection
*plt_eh_frame
;
823 bfd_signed_vma refcount
;
827 /* The amount of space used by the jump slots in the GOT. */
828 bfd_vma sgotplt_jump_table_size
;
830 /* Small local sym cache. */
831 struct sym_cache sym_cache
;
833 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
834 bfd_vma (*r_sym
) (bfd_vma
);
835 unsigned int pointer_r_type
;
836 const char *dynamic_interpreter
;
837 int dynamic_interpreter_size
;
839 /* _TLS_MODULE_BASE_ symbol. */
840 struct bfd_link_hash_entry
*tls_module_base
;
842 /* Used by local STT_GNU_IFUNC symbols. */
843 htab_t loc_hash_table
;
844 void * loc_hash_memory
;
846 /* The offset into splt of the PLT entry for the TLS descriptor
847 resolver. Special values are 0, if not necessary (or not found
848 to be necessary yet), and -1 if needed but not determined
851 /* The offset into sgot of the GOT entry used by the PLT entry
855 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
856 bfd_vma next_jump_slot_index
;
857 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
858 bfd_vma next_irelative_index
;
861 /* Get the x86-64 ELF linker hash table from a link_info structure. */
863 #define elf_x86_64_hash_table(p) \
864 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
865 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
867 #define elf_x86_64_compute_jump_table_size(htab) \
868 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
870 /* Create an entry in an x86-64 ELF linker hash table. */
872 static struct bfd_hash_entry
*
873 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
874 struct bfd_hash_table
*table
,
877 /* Allocate the structure if it has not already been allocated by a
881 entry
= (struct bfd_hash_entry
*)
882 bfd_hash_allocate (table
,
883 sizeof (struct elf_x86_64_link_hash_entry
));
888 /* Call the allocation method of the superclass. */
889 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
892 struct elf_x86_64_link_hash_entry
*eh
;
894 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
895 eh
->dyn_relocs
= NULL
;
896 eh
->tls_type
= GOT_UNKNOWN
;
897 eh
->has_bnd_reloc
= FALSE
;
898 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
899 eh
->tlsdesc_got
= (bfd_vma
) -1;
905 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
906 for local symbol so that we can handle local STT_GNU_IFUNC symbols
907 as global symbol. We reuse indx and dynstr_index for local symbol
908 hash since they aren't used by global symbols in this backend. */
911 elf_x86_64_local_htab_hash (const void *ptr
)
913 struct elf_link_hash_entry
*h
914 = (struct elf_link_hash_entry
*) ptr
;
915 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
918 /* Compare local hash entries. */
921 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
923 struct elf_link_hash_entry
*h1
924 = (struct elf_link_hash_entry
*) ptr1
;
925 struct elf_link_hash_entry
*h2
926 = (struct elf_link_hash_entry
*) ptr2
;
928 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
931 /* Find and/or create a hash entry for local symbol. */
933 static struct elf_link_hash_entry
*
934 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
935 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
938 struct elf_x86_64_link_hash_entry e
, *ret
;
939 asection
*sec
= abfd
->sections
;
940 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
941 htab
->r_sym (rel
->r_info
));
944 e
.elf
.indx
= sec
->id
;
945 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
946 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
947 create
? INSERT
: NO_INSERT
);
954 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
958 ret
= (struct elf_x86_64_link_hash_entry
*)
959 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
960 sizeof (struct elf_x86_64_link_hash_entry
));
963 memset (ret
, 0, sizeof (*ret
));
964 ret
->elf
.indx
= sec
->id
;
965 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
966 ret
->elf
.dynindx
= -1;
972 /* Create an X86-64 ELF linker hash table. */
974 static struct bfd_link_hash_table
*
975 elf_x86_64_link_hash_table_create (bfd
*abfd
)
977 struct elf_x86_64_link_hash_table
*ret
;
978 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
980 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
984 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
985 elf_x86_64_link_hash_newfunc
,
986 sizeof (struct elf_x86_64_link_hash_entry
),
995 ret
->r_info
= elf64_r_info
;
996 ret
->r_sym
= elf64_r_sym
;
997 ret
->pointer_r_type
= R_X86_64_64
;
998 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
999 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1003 ret
->r_info
= elf32_r_info
;
1004 ret
->r_sym
= elf32_r_sym
;
1005 ret
->pointer_r_type
= R_X86_64_32
;
1006 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1007 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1010 ret
->loc_hash_table
= htab_try_create (1024,
1011 elf_x86_64_local_htab_hash
,
1012 elf_x86_64_local_htab_eq
,
1014 ret
->loc_hash_memory
= objalloc_create ();
1015 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1021 return &ret
->elf
.root
;
1024 /* Destroy an X86-64 ELF linker hash table. */
1027 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
1029 struct elf_x86_64_link_hash_table
*htab
1030 = (struct elf_x86_64_link_hash_table
*) hash
;
1032 if (htab
->loc_hash_table
)
1033 htab_delete (htab
->loc_hash_table
);
1034 if (htab
->loc_hash_memory
)
1035 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1036 _bfd_elf_link_hash_table_free (hash
);
1039 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1040 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1044 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
1045 struct bfd_link_info
*info
)
1047 struct elf_x86_64_link_hash_table
*htab
;
1049 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1052 htab
= elf_x86_64_hash_table (info
);
1056 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
1058 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
1061 || (!info
->shared
&& !htab
->srelbss
))
1064 if (!info
->no_ld_generated_unwind_info
1065 && htab
->plt_eh_frame
== NULL
1066 && htab
->elf
.splt
!= NULL
)
1068 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1069 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1070 | SEC_LINKER_CREATED
);
1072 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1073 if (htab
->plt_eh_frame
== NULL
1074 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
1080 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1083 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1084 struct elf_link_hash_entry
*dir
,
1085 struct elf_link_hash_entry
*ind
)
1087 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1089 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1090 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1092 if (!edir
->has_bnd_reloc
)
1093 edir
->has_bnd_reloc
= eind
->has_bnd_reloc
;
1095 if (eind
->dyn_relocs
!= NULL
)
1097 if (edir
->dyn_relocs
!= NULL
)
1099 struct elf_dyn_relocs
**pp
;
1100 struct elf_dyn_relocs
*p
;
1102 /* Add reloc counts against the indirect sym to the direct sym
1103 list. Merge any entries against the same section. */
1104 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1106 struct elf_dyn_relocs
*q
;
1108 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1109 if (q
->sec
== p
->sec
)
1111 q
->pc_count
+= p
->pc_count
;
1112 q
->count
+= p
->count
;
1119 *pp
= edir
->dyn_relocs
;
1122 edir
->dyn_relocs
= eind
->dyn_relocs
;
1123 eind
->dyn_relocs
= NULL
;
1126 if (ind
->root
.type
== bfd_link_hash_indirect
1127 && dir
->got
.refcount
<= 0)
1129 edir
->tls_type
= eind
->tls_type
;
1130 eind
->tls_type
= GOT_UNKNOWN
;
1133 if (ELIMINATE_COPY_RELOCS
1134 && ind
->root
.type
!= bfd_link_hash_indirect
1135 && dir
->dynamic_adjusted
)
1137 /* If called to transfer flags for a weakdef during processing
1138 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1139 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1140 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1141 dir
->ref_regular
|= ind
->ref_regular
;
1142 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1143 dir
->needs_plt
|= ind
->needs_plt
;
1144 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1147 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1151 elf64_x86_64_elf_object_p (bfd
*abfd
)
1153 /* Set the right machine number for an x86-64 elf64 file. */
1154 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1159 elf32_x86_64_elf_object_p (bfd
*abfd
)
1161 /* Set the right machine number for an x86-64 elf32 file. */
1162 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1166 /* Return TRUE if the TLS access code sequence support transition
1170 elf_x86_64_check_tls_transition (bfd
*abfd
,
1171 struct bfd_link_info
*info
,
1174 Elf_Internal_Shdr
*symtab_hdr
,
1175 struct elf_link_hash_entry
**sym_hashes
,
1176 unsigned int r_type
,
1177 const Elf_Internal_Rela
*rel
,
1178 const Elf_Internal_Rela
*relend
)
1181 unsigned long r_symndx
;
1182 bfd_boolean largepic
= FALSE
;
1183 struct elf_link_hash_entry
*h
;
1185 struct elf_x86_64_link_hash_table
*htab
;
1187 /* Get the section contents. */
1188 if (contents
== NULL
)
1190 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1191 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1194 /* FIXME: How to better handle error condition? */
1195 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1198 /* Cache the section contents for elf_link_input_bfd. */
1199 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1203 htab
= elf_x86_64_hash_table (info
);
1204 offset
= rel
->r_offset
;
1207 case R_X86_64_TLSGD
:
1208 case R_X86_64_TLSLD
:
1209 if ((rel
+ 1) >= relend
)
1212 if (r_type
== R_X86_64_TLSGD
)
1214 /* Check transition from GD access model. For 64bit, only
1215 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1216 .word 0x6666; rex64; call __tls_get_addr
1217 can transit to different access model. For 32bit, only
1218 leaq foo@tlsgd(%rip), %rdi
1219 .word 0x6666; rex64; call __tls_get_addr
1220 can transit to different access model. For largepic
1222 leaq foo@tlsgd(%rip), %rdi
1223 movabsq $__tls_get_addr@pltoff, %rax
1227 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1228 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1230 if ((offset
+ 12) > sec
->size
)
1233 if (memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1235 if (!ABI_64_P (abfd
)
1236 || (offset
+ 19) > sec
->size
1238 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0
1239 || memcmp (contents
+ offset
+ 4, "\x48\xb8", 2) != 0
1240 || memcmp (contents
+ offset
+ 14, "\x48\x01\xd8\xff\xd0", 5)
1245 else if (ABI_64_P (abfd
))
1248 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1254 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1260 /* Check transition from LD access model. Only
1261 leaq foo@tlsld(%rip), %rdi;
1263 can transit to different access model. For largepic
1265 leaq foo@tlsld(%rip), %rdi
1266 movabsq $__tls_get_addr@pltoff, %rax
1270 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1272 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1275 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1278 if (0xe8 != *(contents
+ offset
+ 4))
1280 if (!ABI_64_P (abfd
)
1281 || (offset
+ 19) > sec
->size
1282 || memcmp (contents
+ offset
+ 4, "\x48\xb8", 2) != 0
1283 || memcmp (contents
+ offset
+ 14, "\x48\x01\xd8\xff\xd0", 5)
1290 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1291 if (r_symndx
< symtab_hdr
->sh_info
)
1294 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1295 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1296 may be versioned. */
1298 && h
->root
.root
.string
!= NULL
1300 ? ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
1301 : (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1302 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
))
1303 && (strncmp (h
->root
.root
.string
,
1304 "__tls_get_addr", 14) == 0));
1306 case R_X86_64_GOTTPOFF
:
1307 /* Check transition from IE access model:
1308 mov foo@gottpoff(%rip), %reg
1309 add foo@gottpoff(%rip), %reg
1312 /* Check REX prefix first. */
1313 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1315 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1316 if (val
!= 0x48 && val
!= 0x4c)
1318 /* X32 may have 0x44 REX prefix or no REX prefix. */
1319 if (ABI_64_P (abfd
))
1325 /* X32 may not have any REX prefix. */
1326 if (ABI_64_P (abfd
))
1328 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1332 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1333 if (val
!= 0x8b && val
!= 0x03)
1336 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1337 return (val
& 0xc7) == 5;
1339 case R_X86_64_GOTPC32_TLSDESC
:
1340 /* Check transition from GDesc access model:
1341 leaq x@tlsdesc(%rip), %rax
1343 Make sure it's a leaq adding rip to a 32-bit offset
1344 into any register, although it's probably almost always
1347 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1350 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1351 if ((val
& 0xfb) != 0x48)
1354 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1357 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1358 return (val
& 0xc7) == 0x05;
1360 case R_X86_64_TLSDESC_CALL
:
1361 /* Check transition from GDesc access model:
1362 call *x@tlsdesc(%rax)
1364 if (offset
+ 2 <= sec
->size
)
1366 /* Make sure that it's a call *x@tlsdesc(%rax). */
1367 static const unsigned char call
[] = { 0xff, 0x10 };
1368 return memcmp (contents
+ offset
, call
, 2) == 0;
1378 /* Return TRUE if the TLS access transition is OK or no transition
1379 will be performed. Update R_TYPE if there is a transition. */
1382 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1383 asection
*sec
, bfd_byte
*contents
,
1384 Elf_Internal_Shdr
*symtab_hdr
,
1385 struct elf_link_hash_entry
**sym_hashes
,
1386 unsigned int *r_type
, int tls_type
,
1387 const Elf_Internal_Rela
*rel
,
1388 const Elf_Internal_Rela
*relend
,
1389 struct elf_link_hash_entry
*h
,
1390 unsigned long r_symndx
)
1392 unsigned int from_type
= *r_type
;
1393 unsigned int to_type
= from_type
;
1394 bfd_boolean check
= TRUE
;
1396 /* Skip TLS transition for functions. */
1398 && (h
->type
== STT_FUNC
1399 || h
->type
== STT_GNU_IFUNC
))
1404 case R_X86_64_TLSGD
:
1405 case R_X86_64_GOTPC32_TLSDESC
:
1406 case R_X86_64_TLSDESC_CALL
:
1407 case R_X86_64_GOTTPOFF
:
1408 if (info
->executable
)
1411 to_type
= R_X86_64_TPOFF32
;
1413 to_type
= R_X86_64_GOTTPOFF
;
1416 /* When we are called from elf_x86_64_relocate_section,
1417 CONTENTS isn't NULL and there may be additional transitions
1418 based on TLS_TYPE. */
1419 if (contents
!= NULL
)
1421 unsigned int new_to_type
= to_type
;
1423 if (info
->executable
1426 && tls_type
== GOT_TLS_IE
)
1427 new_to_type
= R_X86_64_TPOFF32
;
1429 if (to_type
== R_X86_64_TLSGD
1430 || to_type
== R_X86_64_GOTPC32_TLSDESC
1431 || to_type
== R_X86_64_TLSDESC_CALL
)
1433 if (tls_type
== GOT_TLS_IE
)
1434 new_to_type
= R_X86_64_GOTTPOFF
;
1437 /* We checked the transition before when we were called from
1438 elf_x86_64_check_relocs. We only want to check the new
1439 transition which hasn't been checked before. */
1440 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1441 to_type
= new_to_type
;
1446 case R_X86_64_TLSLD
:
1447 if (info
->executable
)
1448 to_type
= R_X86_64_TPOFF32
;
1455 /* Return TRUE if there is no transition. */
1456 if (from_type
== to_type
)
1459 /* Check if the transition can be performed. */
1461 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1462 symtab_hdr
, sym_hashes
,
1463 from_type
, rel
, relend
))
1465 reloc_howto_type
*from
, *to
;
1468 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1469 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1472 name
= h
->root
.root
.string
;
1475 struct elf_x86_64_link_hash_table
*htab
;
1477 htab
= elf_x86_64_hash_table (info
);
1482 Elf_Internal_Sym
*isym
;
1484 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1486 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1490 (*_bfd_error_handler
)
1491 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1492 "in section `%A' failed"),
1493 abfd
, sec
, from
->name
, to
->name
, name
,
1494 (unsigned long) rel
->r_offset
);
1495 bfd_set_error (bfd_error_bad_value
);
1503 /* Look through the relocs for a section during the first phase, and
1504 calculate needed space in the global offset table, procedure
1505 linkage table, and dynamic reloc sections. */
1508 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1510 const Elf_Internal_Rela
*relocs
)
1512 struct elf_x86_64_link_hash_table
*htab
;
1513 Elf_Internal_Shdr
*symtab_hdr
;
1514 struct elf_link_hash_entry
**sym_hashes
;
1515 const Elf_Internal_Rela
*rel
;
1516 const Elf_Internal_Rela
*rel_end
;
1519 if (info
->relocatable
)
1522 BFD_ASSERT (is_x86_64_elf (abfd
));
1524 htab
= elf_x86_64_hash_table (info
);
1528 symtab_hdr
= &elf_symtab_hdr (abfd
);
1529 sym_hashes
= elf_sym_hashes (abfd
);
1533 rel_end
= relocs
+ sec
->reloc_count
;
1534 for (rel
= relocs
; rel
< rel_end
; rel
++)
1536 unsigned int r_type
;
1537 unsigned long r_symndx
;
1538 struct elf_link_hash_entry
*h
;
1539 Elf_Internal_Sym
*isym
;
1541 bfd_boolean size_reloc
;
1543 r_symndx
= htab
->r_sym (rel
->r_info
);
1544 r_type
= ELF32_R_TYPE (rel
->r_info
);
1546 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1548 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1553 if (r_symndx
< symtab_hdr
->sh_info
)
1555 /* A local symbol. */
1556 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1561 /* Check relocation against local STT_GNU_IFUNC symbol. */
1562 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1564 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1569 /* Fake a STT_GNU_IFUNC symbol. */
1570 h
->type
= STT_GNU_IFUNC
;
1573 h
->forced_local
= 1;
1574 h
->root
.type
= bfd_link_hash_defined
;
1582 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1583 while (h
->root
.type
== bfd_link_hash_indirect
1584 || h
->root
.type
== bfd_link_hash_warning
)
1585 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1588 /* Check invalid x32 relocations. */
1589 if (!ABI_64_P (abfd
))
1595 case R_X86_64_DTPOFF64
:
1596 case R_X86_64_TPOFF64
:
1598 case R_X86_64_GOTOFF64
:
1599 case R_X86_64_GOT64
:
1600 case R_X86_64_GOTPCREL64
:
1601 case R_X86_64_GOTPC64
:
1602 case R_X86_64_GOTPLT64
:
1603 case R_X86_64_PLTOFF64
:
1606 name
= h
->root
.root
.string
;
1608 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1610 (*_bfd_error_handler
)
1611 (_("%B: relocation %s against symbol `%s' isn't "
1612 "supported in x32 mode"), abfd
,
1613 x86_64_elf_howto_table
[r_type
].name
, name
);
1614 bfd_set_error (bfd_error_bad_value
);
1622 /* Create the ifunc sections for static executables. If we
1623 never see an indirect function symbol nor we are building
1624 a static executable, those sections will be empty and
1625 won't appear in output. */
1631 case R_X86_64_PC32_BND
:
1632 case R_X86_64_PLT32_BND
:
1633 /* MPX PLT is supported only if elf_x86_64_arch_bed
1634 is used in 64-bit mode. */
1636 && (get_elf_x86_64_backend_data (abfd
)
1637 == &elf_x86_64_arch_bed
))
1639 elf_x86_64_hash_entry (h
)->has_bnd_reloc
= TRUE
;
1641 /* Create the second PLT for Intel MPX support. */
1642 if (htab
->plt_bnd
== NULL
)
1644 unsigned int plt_bnd_align
;
1645 const struct elf_backend_data
*bed
;
1647 bed
= get_elf_backend_data (info
->output_bfd
);
1648 switch (sizeof (elf_x86_64_bnd_plt2_entry
))
1660 if (htab
->elf
.dynobj
== NULL
)
1661 htab
->elf
.dynobj
= abfd
;
1663 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
1665 (bed
->dynamic_sec_flags
1670 if (htab
->plt_bnd
== NULL
1671 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
1683 case R_X86_64_PLT32
:
1684 case R_X86_64_GOTPCREL
:
1685 case R_X86_64_GOTPCREL64
:
1686 if (htab
->elf
.dynobj
== NULL
)
1687 htab
->elf
.dynobj
= abfd
;
1688 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1693 /* It is referenced by a non-shared object. */
1695 h
->root
.non_ir_ref
= 1;
1698 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1699 symtab_hdr
, sym_hashes
,
1700 &r_type
, GOT_UNKNOWN
,
1701 rel
, rel_end
, h
, r_symndx
))
1706 case R_X86_64_TLSLD
:
1707 htab
->tls_ld_got
.refcount
+= 1;
1710 case R_X86_64_TPOFF32
:
1711 if (!info
->executable
&& ABI_64_P (abfd
))
1714 name
= h
->root
.root
.string
;
1716 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1718 (*_bfd_error_handler
)
1719 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1721 x86_64_elf_howto_table
[r_type
].name
, name
);
1722 bfd_set_error (bfd_error_bad_value
);
1727 case R_X86_64_GOTTPOFF
:
1728 if (!info
->executable
)
1729 info
->flags
|= DF_STATIC_TLS
;
1732 case R_X86_64_GOT32
:
1733 case R_X86_64_GOTPCREL
:
1734 case R_X86_64_TLSGD
:
1735 case R_X86_64_GOT64
:
1736 case R_X86_64_GOTPCREL64
:
1737 case R_X86_64_GOTPLT64
:
1738 case R_X86_64_GOTPC32_TLSDESC
:
1739 case R_X86_64_TLSDESC_CALL
:
1740 /* This symbol requires a global offset table entry. */
1742 int tls_type
, old_tls_type
;
1746 default: tls_type
= GOT_NORMAL
; break;
1747 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1748 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1749 case R_X86_64_GOTPC32_TLSDESC
:
1750 case R_X86_64_TLSDESC_CALL
:
1751 tls_type
= GOT_TLS_GDESC
; break;
1756 if (r_type
== R_X86_64_GOTPLT64
)
1758 /* This relocation indicates that we also need
1759 a PLT entry, as this is a function. We don't need
1760 a PLT entry for local symbols. */
1762 h
->plt
.refcount
+= 1;
1764 h
->got
.refcount
+= 1;
1765 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1769 bfd_signed_vma
*local_got_refcounts
;
1771 /* This is a global offset table entry for a local symbol. */
1772 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1773 if (local_got_refcounts
== NULL
)
1777 size
= symtab_hdr
->sh_info
;
1778 size
*= sizeof (bfd_signed_vma
)
1779 + sizeof (bfd_vma
) + sizeof (char);
1780 local_got_refcounts
= ((bfd_signed_vma
*)
1781 bfd_zalloc (abfd
, size
));
1782 if (local_got_refcounts
== NULL
)
1784 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1785 elf_x86_64_local_tlsdesc_gotent (abfd
)
1786 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1787 elf_x86_64_local_got_tls_type (abfd
)
1788 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1790 local_got_refcounts
[r_symndx
] += 1;
1792 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1795 /* If a TLS symbol is accessed using IE at least once,
1796 there is no point to use dynamic model for it. */
1797 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1798 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1799 || tls_type
!= GOT_TLS_IE
))
1801 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1802 tls_type
= old_tls_type
;
1803 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1804 && GOT_TLS_GD_ANY_P (tls_type
))
1805 tls_type
|= old_tls_type
;
1809 name
= h
->root
.root
.string
;
1811 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1813 (*_bfd_error_handler
)
1814 (_("%B: '%s' accessed both as normal and thread local symbol"),
1816 bfd_set_error (bfd_error_bad_value
);
1821 if (old_tls_type
!= tls_type
)
1824 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1826 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1831 case R_X86_64_GOTOFF64
:
1832 case R_X86_64_GOTPC32
:
1833 case R_X86_64_GOTPC64
:
1835 if (htab
->elf
.sgot
== NULL
)
1837 if (htab
->elf
.dynobj
== NULL
)
1838 htab
->elf
.dynobj
= abfd
;
1839 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1845 case R_X86_64_PLT32
:
1846 case R_X86_64_PLT32_BND
:
1847 /* This symbol requires a procedure linkage table entry. We
1848 actually build the entry in adjust_dynamic_symbol,
1849 because this might be a case of linking PIC code which is
1850 never referenced by a dynamic object, in which case we
1851 don't need to generate a procedure linkage table entry
1854 /* If this is a local symbol, we resolve it directly without
1855 creating a procedure linkage table entry. */
1860 h
->plt
.refcount
+= 1;
1863 case R_X86_64_PLTOFF64
:
1864 /* This tries to form the 'address' of a function relative
1865 to GOT. For global symbols we need a PLT entry. */
1869 h
->plt
.refcount
+= 1;
1873 case R_X86_64_SIZE32
:
1874 case R_X86_64_SIZE64
:
1879 if (!ABI_64_P (abfd
))
1884 /* Let's help debug shared library creation. These relocs
1885 cannot be used in shared libs. Don't error out for
1886 sections we don't care about, such as debug sections or
1887 non-constant sections. */
1889 && (sec
->flags
& SEC_ALLOC
) != 0
1890 && (sec
->flags
& SEC_READONLY
) != 0)
1893 name
= h
->root
.root
.string
;
1895 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1896 (*_bfd_error_handler
)
1897 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1898 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1899 bfd_set_error (bfd_error_bad_value
);
1907 case R_X86_64_PC32_BND
:
1911 if (h
!= NULL
&& info
->executable
)
1913 /* If this reloc is in a read-only section, we might
1914 need a copy reloc. We can't check reliably at this
1915 stage whether the section is read-only, as input
1916 sections have not yet been mapped to output sections.
1917 Tentatively set the flag for now, and correct in
1918 adjust_dynamic_symbol. */
1921 /* We may need a .plt entry if the function this reloc
1922 refers to is in a shared lib. */
1923 h
->plt
.refcount
+= 1;
1924 if (r_type
!= R_X86_64_PC32
1925 && r_type
!= R_X86_64_PC32_BND
1926 && r_type
!= R_X86_64_PC64
)
1927 h
->pointer_equality_needed
= 1;
1932 /* If we are creating a shared library, and this is a reloc
1933 against a global symbol, or a non PC relative reloc
1934 against a local symbol, then we need to copy the reloc
1935 into the shared library. However, if we are linking with
1936 -Bsymbolic, we do not need to copy a reloc against a
1937 global symbol which is defined in an object we are
1938 including in the link (i.e., DEF_REGULAR is set). At
1939 this point we have not seen all the input files, so it is
1940 possible that DEF_REGULAR is not set now but will be set
1941 later (it is never cleared). In case of a weak definition,
1942 DEF_REGULAR may be cleared later by a strong definition in
1943 a shared library. We account for that possibility below by
1944 storing information in the relocs_copied field of the hash
1945 table entry. A similar situation occurs when creating
1946 shared libraries and symbol visibility changes render the
1949 If on the other hand, we are creating an executable, we
1950 may need to keep relocations for symbols satisfied by a
1951 dynamic library if we manage to avoid copy relocs for the
1954 && (sec
->flags
& SEC_ALLOC
) != 0
1955 && (! IS_X86_64_PCREL_TYPE (r_type
)
1957 && (! SYMBOLIC_BIND (info
, h
)
1958 || h
->root
.type
== bfd_link_hash_defweak
1959 || !h
->def_regular
))))
1960 || (ELIMINATE_COPY_RELOCS
1962 && (sec
->flags
& SEC_ALLOC
) != 0
1964 && (h
->root
.type
== bfd_link_hash_defweak
1965 || !h
->def_regular
)))
1967 struct elf_dyn_relocs
*p
;
1968 struct elf_dyn_relocs
**head
;
1970 /* We must copy these reloc types into the output file.
1971 Create a reloc section in dynobj and make room for
1975 if (htab
->elf
.dynobj
== NULL
)
1976 htab
->elf
.dynobj
= abfd
;
1978 sreloc
= _bfd_elf_make_dynamic_reloc_section
1979 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1980 abfd
, /*rela?*/ TRUE
);
1986 /* If this is a global symbol, we count the number of
1987 relocations we need for this symbol. */
1990 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1994 /* Track dynamic relocs needed for local syms too.
1995 We really need local syms available to do this
2000 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2005 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2009 /* Beware of type punned pointers vs strict aliasing
2011 vpp
= &(elf_section_data (s
)->local_dynrel
);
2012 head
= (struct elf_dyn_relocs
**)vpp
;
2016 if (p
== NULL
|| p
->sec
!= sec
)
2018 bfd_size_type amt
= sizeof *p
;
2020 p
= ((struct elf_dyn_relocs
*)
2021 bfd_alloc (htab
->elf
.dynobj
, amt
));
2032 /* Count size relocation as PC-relative relocation. */
2033 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2038 /* This relocation describes the C++ object vtable hierarchy.
2039 Reconstruct it for later use during GC. */
2040 case R_X86_64_GNU_VTINHERIT
:
2041 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2045 /* This relocation describes which C++ vtable entries are actually
2046 used. Record for later use during GC. */
2047 case R_X86_64_GNU_VTENTRY
:
2048 BFD_ASSERT (h
!= NULL
);
2050 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2062 /* Return the section that should be marked against GC for a given
2066 elf_x86_64_gc_mark_hook (asection
*sec
,
2067 struct bfd_link_info
*info
,
2068 Elf_Internal_Rela
*rel
,
2069 struct elf_link_hash_entry
*h
,
2070 Elf_Internal_Sym
*sym
)
2073 switch (ELF32_R_TYPE (rel
->r_info
))
2075 case R_X86_64_GNU_VTINHERIT
:
2076 case R_X86_64_GNU_VTENTRY
:
2080 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2083 /* Update the got entry reference counts for the section being removed. */
2086 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
2088 const Elf_Internal_Rela
*relocs
)
2090 struct elf_x86_64_link_hash_table
*htab
;
2091 Elf_Internal_Shdr
*symtab_hdr
;
2092 struct elf_link_hash_entry
**sym_hashes
;
2093 bfd_signed_vma
*local_got_refcounts
;
2094 const Elf_Internal_Rela
*rel
, *relend
;
2096 if (info
->relocatable
)
2099 htab
= elf_x86_64_hash_table (info
);
2103 elf_section_data (sec
)->local_dynrel
= NULL
;
2105 symtab_hdr
= &elf_symtab_hdr (abfd
);
2106 sym_hashes
= elf_sym_hashes (abfd
);
2107 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2109 htab
= elf_x86_64_hash_table (info
);
2110 relend
= relocs
+ sec
->reloc_count
;
2111 for (rel
= relocs
; rel
< relend
; rel
++)
2113 unsigned long r_symndx
;
2114 unsigned int r_type
;
2115 struct elf_link_hash_entry
*h
= NULL
;
2117 r_symndx
= htab
->r_sym (rel
->r_info
);
2118 if (r_symndx
>= symtab_hdr
->sh_info
)
2120 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2121 while (h
->root
.type
== bfd_link_hash_indirect
2122 || h
->root
.type
== bfd_link_hash_warning
)
2123 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2127 /* A local symbol. */
2128 Elf_Internal_Sym
*isym
;
2130 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2133 /* Check relocation against local STT_GNU_IFUNC symbol. */
2135 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2137 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2145 struct elf_x86_64_link_hash_entry
*eh
;
2146 struct elf_dyn_relocs
**pp
;
2147 struct elf_dyn_relocs
*p
;
2149 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2151 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2154 /* Everything must go for SEC. */
2160 r_type
= ELF32_R_TYPE (rel
->r_info
);
2161 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
2162 symtab_hdr
, sym_hashes
,
2163 &r_type
, GOT_UNKNOWN
,
2164 rel
, relend
, h
, r_symndx
))
2169 case R_X86_64_TLSLD
:
2170 if (htab
->tls_ld_got
.refcount
> 0)
2171 htab
->tls_ld_got
.refcount
-= 1;
2174 case R_X86_64_TLSGD
:
2175 case R_X86_64_GOTPC32_TLSDESC
:
2176 case R_X86_64_TLSDESC_CALL
:
2177 case R_X86_64_GOTTPOFF
:
2178 case R_X86_64_GOT32
:
2179 case R_X86_64_GOTPCREL
:
2180 case R_X86_64_GOT64
:
2181 case R_X86_64_GOTPCREL64
:
2182 case R_X86_64_GOTPLT64
:
2185 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2186 h
->plt
.refcount
-= 1;
2187 if (h
->got
.refcount
> 0)
2188 h
->got
.refcount
-= 1;
2189 if (h
->type
== STT_GNU_IFUNC
)
2191 if (h
->plt
.refcount
> 0)
2192 h
->plt
.refcount
-= 1;
2195 else if (local_got_refcounts
!= NULL
)
2197 if (local_got_refcounts
[r_symndx
] > 0)
2198 local_got_refcounts
[r_symndx
] -= 1;
2210 case R_X86_64_PC32_BND
:
2212 case R_X86_64_SIZE32
:
2213 case R_X86_64_SIZE64
:
2215 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2219 case R_X86_64_PLT32
:
2220 case R_X86_64_PLT32_BND
:
2221 case R_X86_64_PLTOFF64
:
2224 if (h
->plt
.refcount
> 0)
2225 h
->plt
.refcount
-= 1;
2237 /* Adjust a symbol defined by a dynamic object and referenced by a
2238 regular object. The current definition is in some section of the
2239 dynamic object, but we're not including those sections. We have to
2240 change the definition to something the rest of the link can
2244 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2245 struct elf_link_hash_entry
*h
)
2247 struct elf_x86_64_link_hash_table
*htab
;
2249 struct elf_x86_64_link_hash_entry
*eh
;
2250 struct elf_dyn_relocs
*p
;
2252 /* STT_GNU_IFUNC symbol must go through PLT. */
2253 if (h
->type
== STT_GNU_IFUNC
)
2255 /* All local STT_GNU_IFUNC references must be treate as local
2256 calls via local PLT. */
2258 && SYMBOL_CALLS_LOCAL (info
, h
))
2260 bfd_size_type pc_count
= 0, count
= 0;
2261 struct elf_dyn_relocs
**pp
;
2263 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2264 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2266 pc_count
+= p
->pc_count
;
2267 p
->count
-= p
->pc_count
;
2276 if (pc_count
|| count
)
2280 if (h
->plt
.refcount
<= 0)
2281 h
->plt
.refcount
= 1;
2283 h
->plt
.refcount
+= 1;
2287 if (h
->plt
.refcount
<= 0)
2289 h
->plt
.offset
= (bfd_vma
) -1;
2295 /* If this is a function, put it in the procedure linkage table. We
2296 will fill in the contents of the procedure linkage table later,
2297 when we know the address of the .got section. */
2298 if (h
->type
== STT_FUNC
2301 if (h
->plt
.refcount
<= 0
2302 || SYMBOL_CALLS_LOCAL (info
, h
)
2303 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2304 && h
->root
.type
== bfd_link_hash_undefweak
))
2306 /* This case can occur if we saw a PLT32 reloc in an input
2307 file, but the symbol was never referred to by a dynamic
2308 object, or if all references were garbage collected. In
2309 such a case, we don't actually need to build a procedure
2310 linkage table, and we can just do a PC32 reloc instead. */
2311 h
->plt
.offset
= (bfd_vma
) -1;
2318 /* It's possible that we incorrectly decided a .plt reloc was
2319 needed for an R_X86_64_PC32 reloc to a non-function sym in
2320 check_relocs. We can't decide accurately between function and
2321 non-function syms in check-relocs; Objects loaded later in
2322 the link may change h->type. So fix it now. */
2323 h
->plt
.offset
= (bfd_vma
) -1;
2325 /* If this is a weak symbol, and there is a real definition, the
2326 processor independent code will have arranged for us to see the
2327 real definition first, and we can just use the same value. */
2328 if (h
->u
.weakdef
!= NULL
)
2330 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2331 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2332 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2333 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2334 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2335 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2339 /* This is a reference to a symbol defined by a dynamic object which
2340 is not a function. */
2342 /* If we are creating a shared library, we must presume that the
2343 only references to the symbol are via the global offset table.
2344 For such cases we need not do anything here; the relocations will
2345 be handled correctly by relocate_section. */
2349 /* If there are no references to this symbol that do not use the
2350 GOT, we don't need to generate a copy reloc. */
2351 if (!h
->non_got_ref
)
2354 /* If -z nocopyreloc was given, we won't generate them either. */
2355 if (info
->nocopyreloc
)
2361 if (ELIMINATE_COPY_RELOCS
)
2363 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2364 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2366 s
= p
->sec
->output_section
;
2367 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2371 /* If we didn't find any dynamic relocs in read-only sections, then
2372 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2380 /* We must allocate the symbol in our .dynbss section, which will
2381 become part of the .bss section of the executable. There will be
2382 an entry for this symbol in the .dynsym section. The dynamic
2383 object will contain position independent code, so all references
2384 from the dynamic object to this symbol will go through the global
2385 offset table. The dynamic linker will use the .dynsym entry to
2386 determine the address it must put in the global offset table, so
2387 both the dynamic object and the regular object will refer to the
2388 same memory location for the variable. */
2390 htab
= elf_x86_64_hash_table (info
);
2394 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2395 to copy the initial value out of the dynamic object and into the
2396 runtime process image. */
2397 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2399 const struct elf_backend_data
*bed
;
2400 bed
= get_elf_backend_data (info
->output_bfd
);
2401 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2407 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2410 /* Allocate space in .plt, .got and associated reloc sections for
2414 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2416 struct bfd_link_info
*info
;
2417 struct elf_x86_64_link_hash_table
*htab
;
2418 struct elf_x86_64_link_hash_entry
*eh
;
2419 struct elf_dyn_relocs
*p
;
2420 const struct elf_backend_data
*bed
;
2421 unsigned int plt_entry_size
;
2423 if (h
->root
.type
== bfd_link_hash_indirect
)
2426 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2428 info
= (struct bfd_link_info
*) inf
;
2429 htab
= elf_x86_64_hash_table (info
);
2432 bed
= get_elf_backend_data (info
->output_bfd
);
2433 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2435 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2436 here if it is defined and referenced in a non-shared object. */
2437 if (h
->type
== STT_GNU_IFUNC
2440 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2446 asection
*s
= htab
->plt_bnd
;
2447 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2449 /* Use the .plt.bnd section if it is created. */
2450 eh
->plt_bnd
.offset
= s
->size
;
2452 /* Make room for this entry in the .plt.bnd section. */
2453 s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
2461 else if (htab
->elf
.dynamic_sections_created
2462 && h
->plt
.refcount
> 0)
2464 /* Make sure this symbol is output as a dynamic symbol.
2465 Undefined weak syms won't yet be marked as dynamic. */
2466 if (h
->dynindx
== -1
2467 && !h
->forced_local
)
2469 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2474 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2476 asection
*s
= htab
->elf
.splt
;
2477 asection
*bnd_s
= htab
->plt_bnd
;
2479 /* If this is the first .plt entry, make room for the special
2482 s
->size
= plt_entry_size
;
2484 h
->plt
.offset
= s
->size
;
2486 eh
->plt_bnd
.offset
= bnd_s
->size
;
2488 /* If this symbol is not defined in a regular file, and we are
2489 not generating a shared library, then set the symbol to this
2490 location in the .plt. This is required to make function
2491 pointers compare as equal between the normal executable and
2492 the shared library. */
2498 /* We need to make a call to the entry of the second
2499 PLT instead of regular PLT entry. */
2500 h
->root
.u
.def
.section
= bnd_s
;
2501 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
2505 h
->root
.u
.def
.section
= s
;
2506 h
->root
.u
.def
.value
= h
->plt
.offset
;
2510 /* Make room for this entry. */
2511 s
->size
+= plt_entry_size
;
2514 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry
)
2515 == sizeof (elf_x86_64_legacy_plt2_entry
));
2516 bnd_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
2519 /* We also need to make an entry in the .got.plt section, which
2520 will be placed in the .got section by the linker script. */
2521 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2523 /* We also need to make an entry in the .rela.plt section. */
2524 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2525 htab
->elf
.srelplt
->reloc_count
++;
2529 h
->plt
.offset
= (bfd_vma
) -1;
2535 h
->plt
.offset
= (bfd_vma
) -1;
2539 eh
->tlsdesc_got
= (bfd_vma
) -1;
2541 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2542 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2543 if (h
->got
.refcount
> 0
2546 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2548 h
->got
.offset
= (bfd_vma
) -1;
2550 else if (h
->got
.refcount
> 0)
2554 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2556 /* Make sure this symbol is output as a dynamic symbol.
2557 Undefined weak syms won't yet be marked as dynamic. */
2558 if (h
->dynindx
== -1
2559 && !h
->forced_local
)
2561 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2565 if (GOT_TLS_GDESC_P (tls_type
))
2567 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2568 - elf_x86_64_compute_jump_table_size (htab
);
2569 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2570 h
->got
.offset
= (bfd_vma
) -2;
2572 if (! GOT_TLS_GDESC_P (tls_type
)
2573 || GOT_TLS_GD_P (tls_type
))
2576 h
->got
.offset
= s
->size
;
2577 s
->size
+= GOT_ENTRY_SIZE
;
2578 if (GOT_TLS_GD_P (tls_type
))
2579 s
->size
+= GOT_ENTRY_SIZE
;
2581 dyn
= htab
->elf
.dynamic_sections_created
;
2582 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2584 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2585 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2586 || tls_type
== GOT_TLS_IE
)
2587 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2588 else if (GOT_TLS_GD_P (tls_type
))
2589 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2590 else if (! GOT_TLS_GDESC_P (tls_type
)
2591 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2592 || h
->root
.type
!= bfd_link_hash_undefweak
)
2594 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2595 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2596 if (GOT_TLS_GDESC_P (tls_type
))
2598 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2599 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2603 h
->got
.offset
= (bfd_vma
) -1;
2605 if (eh
->dyn_relocs
== NULL
)
2608 /* In the shared -Bsymbolic case, discard space allocated for
2609 dynamic pc-relative relocs against symbols which turn out to be
2610 defined in regular objects. For the normal shared case, discard
2611 space for pc-relative relocs that have become local due to symbol
2612 visibility changes. */
2616 /* Relocs that use pc_count are those that appear on a call
2617 insn, or certain REL relocs that can generated via assembly.
2618 We want calls to protected symbols to resolve directly to the
2619 function rather than going via the plt. If people want
2620 function pointer comparisons to work as expected then they
2621 should avoid writing weird assembly. */
2622 if (SYMBOL_CALLS_LOCAL (info
, h
))
2624 struct elf_dyn_relocs
**pp
;
2626 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2628 p
->count
-= p
->pc_count
;
2637 /* Also discard relocs on undefined weak syms with non-default
2639 if (eh
->dyn_relocs
!= NULL
2640 && h
->root
.type
== bfd_link_hash_undefweak
)
2642 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2643 eh
->dyn_relocs
= NULL
;
2645 /* Make sure undefined weak symbols are output as a dynamic
2647 else if (h
->dynindx
== -1
2648 && ! h
->forced_local
2649 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2654 else if (ELIMINATE_COPY_RELOCS
)
2656 /* For the non-shared case, discard space for relocs against
2657 symbols which turn out to need copy relocs or are not
2663 || (htab
->elf
.dynamic_sections_created
2664 && (h
->root
.type
== bfd_link_hash_undefweak
2665 || h
->root
.type
== bfd_link_hash_undefined
))))
2667 /* Make sure this symbol is output as a dynamic symbol.
2668 Undefined weak syms won't yet be marked as dynamic. */
2669 if (h
->dynindx
== -1
2670 && ! h
->forced_local
2671 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2674 /* If that succeeded, we know we'll be keeping all the
2676 if (h
->dynindx
!= -1)
2680 eh
->dyn_relocs
= NULL
;
2685 /* Finally, allocate space. */
2686 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2690 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2692 BFD_ASSERT (sreloc
!= NULL
);
2694 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2700 /* Allocate space in .plt, .got and associated reloc sections for
2701 local dynamic relocs. */
2704 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2706 struct elf_link_hash_entry
*h
2707 = (struct elf_link_hash_entry
*) *slot
;
2709 if (h
->type
!= STT_GNU_IFUNC
2713 || h
->root
.type
!= bfd_link_hash_defined
)
2716 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2719 /* Find any dynamic relocs that apply to read-only sections. */
2722 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2725 struct elf_x86_64_link_hash_entry
*eh
;
2726 struct elf_dyn_relocs
*p
;
2728 /* Skip local IFUNC symbols. */
2729 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2732 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2733 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2735 asection
*s
= p
->sec
->output_section
;
2737 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2739 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2741 info
->flags
|= DF_TEXTREL
;
2743 if (info
->warn_shared_textrel
&& info
->shared
)
2744 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2745 p
->sec
->owner
, h
->root
.root
.string
,
2748 /* Not an error, just cut short the traversal. */
2756 mov foo@GOTPCREL(%rip), %reg
2759 with the local symbol, foo. */
2762 elf_x86_64_convert_mov_to_lea (bfd
*abfd
, asection
*sec
,
2763 struct bfd_link_info
*link_info
)
2765 Elf_Internal_Shdr
*symtab_hdr
;
2766 Elf_Internal_Rela
*internal_relocs
;
2767 Elf_Internal_Rela
*irel
, *irelend
;
2769 struct elf_x86_64_link_hash_table
*htab
;
2770 bfd_boolean changed_contents
;
2771 bfd_boolean changed_relocs
;
2772 bfd_signed_vma
*local_got_refcounts
;
2774 /* Don't even try to convert non-ELF outputs. */
2775 if (!is_elf_hash_table (link_info
->hash
))
2778 /* Nothing to do if there are no codes, no relocations or no output. */
2779 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2780 || sec
->reloc_count
== 0
2781 || discarded_section (sec
))
2784 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2786 /* Load the relocations for this section. */
2787 internal_relocs
= (_bfd_elf_link_read_relocs
2788 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2789 link_info
->keep_memory
));
2790 if (internal_relocs
== NULL
)
2793 htab
= elf_x86_64_hash_table (link_info
);
2794 changed_contents
= FALSE
;
2795 changed_relocs
= FALSE
;
2796 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2798 /* Get the section contents. */
2799 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2800 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2803 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2807 irelend
= internal_relocs
+ sec
->reloc_count
;
2808 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2810 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2811 unsigned int r_symndx
= htab
->r_sym (irel
->r_info
);
2813 struct elf_link_hash_entry
*h
;
2815 if (r_type
!= R_X86_64_GOTPCREL
)
2818 /* Get the symbol referred to by the reloc. */
2819 if (r_symndx
< symtab_hdr
->sh_info
)
2821 Elf_Internal_Sym
*isym
;
2823 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2826 /* STT_GNU_IFUNC must keep R_X86_64_GOTPCREL relocation. */
2827 if (ELF_ST_TYPE (isym
->st_info
) != STT_GNU_IFUNC
2828 && bfd_get_8 (input_bfd
,
2829 contents
+ irel
->r_offset
- 2) == 0x8b)
2831 bfd_put_8 (output_bfd
, 0x8d,
2832 contents
+ irel
->r_offset
- 2);
2833 irel
->r_info
= htab
->r_info (r_symndx
, R_X86_64_PC32
);
2834 if (local_got_refcounts
!= NULL
2835 && local_got_refcounts
[r_symndx
] > 0)
2836 local_got_refcounts
[r_symndx
] -= 1;
2837 changed_contents
= TRUE
;
2838 changed_relocs
= TRUE
;
2843 indx
= r_symndx
- symtab_hdr
->sh_info
;
2844 h
= elf_sym_hashes (abfd
)[indx
];
2845 BFD_ASSERT (h
!= NULL
);
2847 while (h
->root
.type
== bfd_link_hash_indirect
2848 || h
->root
.type
== bfd_link_hash_warning
)
2849 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2851 /* STT_GNU_IFUNC must keep R_X86_64_GOTPCREL relocation. We also
2852 avoid optimizing _DYNAMIC since ld.so may use its link-time
2855 && h
->type
!= STT_GNU_IFUNC
2856 && h
!= htab
->elf
.hdynamic
2857 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)
2858 && bfd_get_8 (input_bfd
,
2859 contents
+ irel
->r_offset
- 2) == 0x8b)
2861 bfd_put_8 (output_bfd
, 0x8d,
2862 contents
+ irel
->r_offset
- 2);
2863 irel
->r_info
= htab
->r_info (r_symndx
, R_X86_64_PC32
);
2864 if (h
->got
.refcount
> 0)
2865 h
->got
.refcount
-= 1;
2866 changed_contents
= TRUE
;
2867 changed_relocs
= TRUE
;
2871 if (contents
!= NULL
2872 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2874 if (!changed_contents
&& !link_info
->keep_memory
)
2878 /* Cache the section contents for elf_link_input_bfd. */
2879 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2883 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2885 if (!changed_relocs
)
2886 free (internal_relocs
);
2888 elf_section_data (sec
)->relocs
= internal_relocs
;
2894 if (contents
!= NULL
2895 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2897 if (internal_relocs
!= NULL
2898 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2899 free (internal_relocs
);
2903 /* Set the sizes of the dynamic sections. */
2906 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2907 struct bfd_link_info
*info
)
2909 struct elf_x86_64_link_hash_table
*htab
;
2914 const struct elf_backend_data
*bed
;
2916 htab
= elf_x86_64_hash_table (info
);
2919 bed
= get_elf_backend_data (output_bfd
);
2921 dynobj
= htab
->elf
.dynobj
;
2925 if (htab
->elf
.dynamic_sections_created
)
2927 /* Set the contents of the .interp section to the interpreter. */
2928 if (info
->executable
)
2930 s
= bfd_get_linker_section (dynobj
, ".interp");
2933 s
->size
= htab
->dynamic_interpreter_size
;
2934 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2938 /* Set up .got offsets for local syms, and space for local dynamic
2940 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2942 bfd_signed_vma
*local_got
;
2943 bfd_signed_vma
*end_local_got
;
2944 char *local_tls_type
;
2945 bfd_vma
*local_tlsdesc_gotent
;
2946 bfd_size_type locsymcount
;
2947 Elf_Internal_Shdr
*symtab_hdr
;
2950 if (! is_x86_64_elf (ibfd
))
2953 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2955 struct elf_dyn_relocs
*p
;
2957 if (!elf_x86_64_convert_mov_to_lea (ibfd
, s
, info
))
2960 for (p
= (struct elf_dyn_relocs
*)
2961 (elf_section_data (s
)->local_dynrel
);
2965 if (!bfd_is_abs_section (p
->sec
)
2966 && bfd_is_abs_section (p
->sec
->output_section
))
2968 /* Input section has been discarded, either because
2969 it is a copy of a linkonce section or due to
2970 linker script /DISCARD/, so we'll be discarding
2973 else if (p
->count
!= 0)
2975 srel
= elf_section_data (p
->sec
)->sreloc
;
2976 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2977 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2978 && (info
->flags
& DF_TEXTREL
) == 0)
2980 info
->flags
|= DF_TEXTREL
;
2981 if (info
->warn_shared_textrel
&& info
->shared
)
2982 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2983 p
->sec
->owner
, p
->sec
);
2989 local_got
= elf_local_got_refcounts (ibfd
);
2993 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2994 locsymcount
= symtab_hdr
->sh_info
;
2995 end_local_got
= local_got
+ locsymcount
;
2996 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2997 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2999 srel
= htab
->elf
.srelgot
;
3000 for (; local_got
< end_local_got
;
3001 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3003 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3006 if (GOT_TLS_GDESC_P (*local_tls_type
))
3008 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3009 - elf_x86_64_compute_jump_table_size (htab
);
3010 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3011 *local_got
= (bfd_vma
) -2;
3013 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3014 || GOT_TLS_GD_P (*local_tls_type
))
3016 *local_got
= s
->size
;
3017 s
->size
+= GOT_ENTRY_SIZE
;
3018 if (GOT_TLS_GD_P (*local_tls_type
))
3019 s
->size
+= GOT_ENTRY_SIZE
;
3022 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3023 || *local_tls_type
== GOT_TLS_IE
)
3025 if (GOT_TLS_GDESC_P (*local_tls_type
))
3027 htab
->elf
.srelplt
->size
3028 += bed
->s
->sizeof_rela
;
3029 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3031 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3032 || GOT_TLS_GD_P (*local_tls_type
))
3033 srel
->size
+= bed
->s
->sizeof_rela
;
3037 *local_got
= (bfd_vma
) -1;
3041 if (htab
->tls_ld_got
.refcount
> 0)
3043 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3045 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3046 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3047 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3050 htab
->tls_ld_got
.offset
= -1;
3052 /* Allocate global sym .plt and .got entries, and space for global
3053 sym dynamic relocs. */
3054 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3057 /* Allocate .plt and .got entries, and space for local symbols. */
3058 htab_traverse (htab
->loc_hash_table
,
3059 elf_x86_64_allocate_local_dynrelocs
,
3062 /* For every jump slot reserved in the sgotplt, reloc_count is
3063 incremented. However, when we reserve space for TLS descriptors,
3064 it's not incremented, so in order to compute the space reserved
3065 for them, it suffices to multiply the reloc count by the jump
3068 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3069 so that R_X86_64_IRELATIVE entries come last. */
3070 if (htab
->elf
.srelplt
)
3072 htab
->sgotplt_jump_table_size
3073 = elf_x86_64_compute_jump_table_size (htab
);
3074 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3076 else if (htab
->elf
.irelplt
)
3077 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3079 if (htab
->tlsdesc_plt
)
3081 /* If we're not using lazy TLS relocations, don't generate the
3082 PLT and GOT entries they require. */
3083 if ((info
->flags
& DF_BIND_NOW
))
3084 htab
->tlsdesc_plt
= 0;
3087 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3088 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3089 /* Reserve room for the initial entry.
3090 FIXME: we could probably do away with it in this case. */
3091 if (htab
->elf
.splt
->size
== 0)
3092 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3093 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3094 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3098 if (htab
->elf
.sgotplt
)
3100 /* Don't allocate .got.plt section if there are no GOT nor PLT
3101 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3102 if ((htab
->elf
.hgot
== NULL
3103 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3104 && (htab
->elf
.sgotplt
->size
3105 == get_elf_backend_data (output_bfd
)->got_header_size
)
3106 && (htab
->elf
.splt
== NULL
3107 || htab
->elf
.splt
->size
== 0)
3108 && (htab
->elf
.sgot
== NULL
3109 || htab
->elf
.sgot
->size
== 0)
3110 && (htab
->elf
.iplt
== NULL
3111 || htab
->elf
.iplt
->size
== 0)
3112 && (htab
->elf
.igotplt
== NULL
3113 || htab
->elf
.igotplt
->size
== 0))
3114 htab
->elf
.sgotplt
->size
= 0;
3117 if (htab
->plt_eh_frame
!= NULL
3118 && htab
->elf
.splt
!= NULL
3119 && htab
->elf
.splt
->size
!= 0
3120 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
)
3121 && _bfd_elf_eh_frame_present (info
))
3123 const struct elf_x86_64_backend_data
*arch_data
3124 = get_elf_x86_64_arch_data (bed
);
3125 htab
->plt_eh_frame
->size
= arch_data
->eh_frame_plt_size
;
3128 /* We now have determined the sizes of the various dynamic sections.
3129 Allocate memory for them. */
3131 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3133 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3136 if (s
== htab
->elf
.splt
3137 || s
== htab
->elf
.sgot
3138 || s
== htab
->elf
.sgotplt
3139 || s
== htab
->elf
.iplt
3140 || s
== htab
->elf
.igotplt
3141 || s
== htab
->plt_bnd
3142 || s
== htab
->plt_eh_frame
3143 || s
== htab
->sdynbss
)
3145 /* Strip this section if we don't need it; see the
3148 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3150 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3153 /* We use the reloc_count field as a counter if we need
3154 to copy relocs into the output file. */
3155 if (s
!= htab
->elf
.srelplt
)
3160 /* It's not one of our sections, so don't allocate space. */
3166 /* If we don't need this section, strip it from the
3167 output file. This is mostly to handle .rela.bss and
3168 .rela.plt. We must create both sections in
3169 create_dynamic_sections, because they must be created
3170 before the linker maps input sections to output
3171 sections. The linker does that before
3172 adjust_dynamic_symbol is called, and it is that
3173 function which decides whether anything needs to go
3174 into these sections. */
3176 s
->flags
|= SEC_EXCLUDE
;
3180 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3183 /* Allocate memory for the section contents. We use bfd_zalloc
3184 here in case unused entries are not reclaimed before the
3185 section's contents are written out. This should not happen,
3186 but this way if it does, we get a R_X86_64_NONE reloc instead
3188 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3189 if (s
->contents
== NULL
)
3193 if (htab
->plt_eh_frame
!= NULL
3194 && htab
->plt_eh_frame
->contents
!= NULL
)
3196 const struct elf_x86_64_backend_data
*arch_data
3197 = get_elf_x86_64_arch_data (bed
);
3199 memcpy (htab
->plt_eh_frame
->contents
,
3200 arch_data
->eh_frame_plt
, htab
->plt_eh_frame
->size
);
3201 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3202 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3205 if (htab
->elf
.dynamic_sections_created
)
3207 /* Add some entries to the .dynamic section. We fill in the
3208 values later, in elf_x86_64_finish_dynamic_sections, but we
3209 must add the entries now so that we get the correct size for
3210 the .dynamic section. The DT_DEBUG entry is filled in by the
3211 dynamic linker and used by the debugger. */
3212 #define add_dynamic_entry(TAG, VAL) \
3213 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3215 if (info
->executable
)
3217 if (!add_dynamic_entry (DT_DEBUG
, 0))
3221 if (htab
->elf
.splt
->size
!= 0)
3223 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3224 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3225 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3226 || !add_dynamic_entry (DT_JMPREL
, 0))
3229 if (htab
->tlsdesc_plt
3230 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
3231 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
3237 if (!add_dynamic_entry (DT_RELA
, 0)
3238 || !add_dynamic_entry (DT_RELASZ
, 0)
3239 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
3242 /* If any dynamic relocs apply to a read-only section,
3243 then we need a DT_TEXTREL entry. */
3244 if ((info
->flags
& DF_TEXTREL
) == 0)
3245 elf_link_hash_traverse (&htab
->elf
,
3246 elf_x86_64_readonly_dynrelocs
,
3249 if ((info
->flags
& DF_TEXTREL
) != 0)
3251 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3256 #undef add_dynamic_entry
3262 elf_x86_64_always_size_sections (bfd
*output_bfd
,
3263 struct bfd_link_info
*info
)
3265 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3269 struct elf_link_hash_entry
*tlsbase
;
3271 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3272 "_TLS_MODULE_BASE_",
3273 FALSE
, FALSE
, FALSE
);
3275 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3277 struct elf_x86_64_link_hash_table
*htab
;
3278 struct bfd_link_hash_entry
*bh
= NULL
;
3279 const struct elf_backend_data
*bed
3280 = get_elf_backend_data (output_bfd
);
3282 htab
= elf_x86_64_hash_table (info
);
3286 if (!(_bfd_generic_link_add_one_symbol
3287 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3288 tls_sec
, 0, NULL
, FALSE
,
3289 bed
->collect
, &bh
)))
3292 htab
->tls_module_base
= bh
;
3294 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3295 tlsbase
->def_regular
= 1;
3296 tlsbase
->other
= STV_HIDDEN
;
3297 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
3304 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
3305 executables. Rather than setting it to the beginning of the TLS
3306 section, we have to set it to the end. This function may be called
3307 multiple times, it is idempotent. */
3310 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
3312 struct elf_x86_64_link_hash_table
*htab
;
3313 struct bfd_link_hash_entry
*base
;
3315 if (!info
->executable
)
3318 htab
= elf_x86_64_hash_table (info
);
3322 base
= htab
->tls_module_base
;
3326 base
->u
.def
.value
= htab
->elf
.tls_size
;
3329 /* Return the base VMA address which should be subtracted from real addresses
3330 when resolving @dtpoff relocation.
3331 This is PT_TLS segment p_vaddr. */
3334 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
3336 /* If tls_sec is NULL, we should have signalled an error already. */
3337 if (elf_hash_table (info
)->tls_sec
== NULL
)
3339 return elf_hash_table (info
)->tls_sec
->vma
;
3342 /* Return the relocation value for @tpoff relocation
3343 if STT_TLS virtual address is ADDRESS. */
3346 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3348 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3349 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3350 bfd_vma static_tls_size
;
3352 /* If tls_segment is NULL, we should have signalled an error already. */
3353 if (htab
->tls_sec
== NULL
)
3356 /* Consider special static TLS alignment requirements. */
3357 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3358 return address
- static_tls_size
- htab
->tls_sec
->vma
;
3361 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3365 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
3367 /* Opcode Instruction
3370 0x0f 0x8x conditional jump */
3372 && (contents
[offset
- 1] == 0xe8
3373 || contents
[offset
- 1] == 0xe9))
3375 && contents
[offset
- 2] == 0x0f
3376 && (contents
[offset
- 1] & 0xf0) == 0x80));
3379 /* Relocate an x86_64 ELF section. */
3382 elf_x86_64_relocate_section (bfd
*output_bfd
,
3383 struct bfd_link_info
*info
,
3385 asection
*input_section
,
3387 Elf_Internal_Rela
*relocs
,
3388 Elf_Internal_Sym
*local_syms
,
3389 asection
**local_sections
)
3391 struct elf_x86_64_link_hash_table
*htab
;
3392 Elf_Internal_Shdr
*symtab_hdr
;
3393 struct elf_link_hash_entry
**sym_hashes
;
3394 bfd_vma
*local_got_offsets
;
3395 bfd_vma
*local_tlsdesc_gotents
;
3396 Elf_Internal_Rela
*rel
;
3397 Elf_Internal_Rela
*relend
;
3398 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3400 BFD_ASSERT (is_x86_64_elf (input_bfd
));
3402 htab
= elf_x86_64_hash_table (info
);
3405 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3406 sym_hashes
= elf_sym_hashes (input_bfd
);
3407 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3408 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
3410 elf_x86_64_set_tls_module_base (info
);
3413 relend
= relocs
+ input_section
->reloc_count
;
3414 for (; rel
< relend
; rel
++)
3416 unsigned int r_type
;
3417 reloc_howto_type
*howto
;
3418 unsigned long r_symndx
;
3419 struct elf_link_hash_entry
*h
;
3420 struct elf_x86_64_link_hash_entry
*eh
;
3421 Elf_Internal_Sym
*sym
;
3423 bfd_vma off
, offplt
, plt_offset
;
3425 bfd_boolean unresolved_reloc
;
3426 bfd_reloc_status_type r
;
3428 asection
*base_got
, *resolved_plt
;
3431 r_type
= ELF32_R_TYPE (rel
->r_info
);
3432 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3433 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3436 if (r_type
>= (int) R_X86_64_standard
)
3438 (*_bfd_error_handler
)
3439 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
3440 input_bfd
, input_section
, r_type
);
3441 bfd_set_error (bfd_error_bad_value
);
3445 if (r_type
!= (int) R_X86_64_32
3446 || ABI_64_P (output_bfd
))
3447 howto
= x86_64_elf_howto_table
+ r_type
;
3449 howto
= (x86_64_elf_howto_table
3450 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3451 r_symndx
= htab
->r_sym (rel
->r_info
);
3455 unresolved_reloc
= FALSE
;
3456 if (r_symndx
< symtab_hdr
->sh_info
)
3458 sym
= local_syms
+ r_symndx
;
3459 sec
= local_sections
[r_symndx
];
3461 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3463 st_size
= sym
->st_size
;
3465 /* Relocate against local STT_GNU_IFUNC symbol. */
3466 if (!info
->relocatable
3467 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3469 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3474 /* Set STT_GNU_IFUNC symbol value. */
3475 h
->root
.u
.def
.value
= sym
->st_value
;
3476 h
->root
.u
.def
.section
= sec
;
3481 bfd_boolean warned ATTRIBUTE_UNUSED
;
3482 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3484 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3485 r_symndx
, symtab_hdr
, sym_hashes
,
3487 unresolved_reloc
, warned
, ignored
);
3491 if (sec
!= NULL
&& discarded_section (sec
))
3492 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3493 rel
, 1, relend
, howto
, 0, contents
);
3495 if (info
->relocatable
)
3498 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
3500 if (r_type
== R_X86_64_64
)
3502 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
3503 zero-extend it to 64bit if addend is zero. */
3504 r_type
= R_X86_64_32
;
3505 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3507 else if (r_type
== R_X86_64_SIZE64
)
3509 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
3510 zero-extend it to 64bit if addend is zero. */
3511 r_type
= R_X86_64_SIZE32
;
3512 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3516 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3518 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3519 it here if it is defined in a non-shared object. */
3521 && h
->type
== STT_GNU_IFUNC
3527 if ((input_section
->flags
& SEC_ALLOC
) == 0
3528 || h
->plt
.offset
== (bfd_vma
) -1)
3531 /* STT_GNU_IFUNC symbol must go through PLT. */
3532 if (htab
->elf
.splt
!= NULL
)
3534 if (htab
->plt_bnd
!= NULL
)
3536 resolved_plt
= htab
->plt_bnd
;
3537 plt_offset
= eh
->plt_bnd
.offset
;
3541 resolved_plt
= htab
->elf
.splt
;
3542 plt_offset
= h
->plt
.offset
;
3547 resolved_plt
= htab
->elf
.iplt
;
3548 plt_offset
= h
->plt
.offset
;
3551 relocation
= (resolved_plt
->output_section
->vma
3552 + resolved_plt
->output_offset
+ plt_offset
);
3557 if (h
->root
.root
.string
)
3558 name
= h
->root
.root
.string
;
3560 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3562 (*_bfd_error_handler
)
3563 (_("%B: relocation %s against STT_GNU_IFUNC "
3564 "symbol `%s' isn't handled by %s"), input_bfd
,
3565 x86_64_elf_howto_table
[r_type
].name
,
3566 name
, __FUNCTION__
);
3567 bfd_set_error (bfd_error_bad_value
);
3576 if (ABI_64_P (output_bfd
))
3580 if (rel
->r_addend
!= 0)
3582 if (h
->root
.root
.string
)
3583 name
= h
->root
.root
.string
;
3585 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3587 (*_bfd_error_handler
)
3588 (_("%B: relocation %s against STT_GNU_IFUNC "
3589 "symbol `%s' has non-zero addend: %d"),
3590 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3591 name
, rel
->r_addend
);
3592 bfd_set_error (bfd_error_bad_value
);
3596 /* Generate dynamic relcoation only when there is a
3597 non-GOT reference in a shared object. */
3598 if (info
->shared
&& h
->non_got_ref
)
3600 Elf_Internal_Rela outrel
;
3603 /* Need a dynamic relocation to get the real function
3605 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3609 if (outrel
.r_offset
== (bfd_vma
) -1
3610 || outrel
.r_offset
== (bfd_vma
) -2)
3613 outrel
.r_offset
+= (input_section
->output_section
->vma
3614 + input_section
->output_offset
);
3616 if (h
->dynindx
== -1
3618 || info
->executable
)
3620 /* This symbol is resolved locally. */
3621 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3622 outrel
.r_addend
= (h
->root
.u
.def
.value
3623 + h
->root
.u
.def
.section
->output_section
->vma
3624 + h
->root
.u
.def
.section
->output_offset
);
3628 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3629 outrel
.r_addend
= 0;
3632 sreloc
= htab
->elf
.irelifunc
;
3633 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3635 /* If this reloc is against an external symbol, we
3636 do not want to fiddle with the addend. Otherwise,
3637 we need to include the symbol value so that it
3638 becomes an addend for the dynamic reloc. For an
3639 internal symbol, we have updated addend. */
3644 case R_X86_64_PC32_BND
:
3646 case R_X86_64_PLT32
:
3647 case R_X86_64_PLT32_BND
:
3650 case R_X86_64_GOTPCREL
:
3651 case R_X86_64_GOTPCREL64
:
3652 base_got
= htab
->elf
.sgot
;
3653 off
= h
->got
.offset
;
3655 if (base_got
== NULL
)
3658 if (off
== (bfd_vma
) -1)
3660 /* We can't use h->got.offset here to save state, or
3661 even just remember the offset, as finish_dynamic_symbol
3662 would use that as offset into .got. */
3664 if (htab
->elf
.splt
!= NULL
)
3666 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3667 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3668 base_got
= htab
->elf
.sgotplt
;
3672 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3673 off
= plt_index
* GOT_ENTRY_SIZE
;
3674 base_got
= htab
->elf
.igotplt
;
3677 if (h
->dynindx
== -1
3681 /* This references the local defitionion. We must
3682 initialize this entry in the global offset table.
3683 Since the offset must always be a multiple of 8,
3684 we use the least significant bit to record
3685 whether we have initialized it already.
3687 When doing a dynamic link, we create a .rela.got
3688 relocation entry to initialize the value. This
3689 is done in the finish_dynamic_symbol routine. */
3694 bfd_put_64 (output_bfd
, relocation
,
3695 base_got
->contents
+ off
);
3696 /* Note that this is harmless for the GOTPLT64
3697 case, as -1 | 1 still is -1. */
3703 relocation
= (base_got
->output_section
->vma
3704 + base_got
->output_offset
+ off
);
3710 /* When generating a shared object, the relocations handled here are
3711 copied into the output file to be resolved at run time. */
3714 case R_X86_64_GOT32
:
3715 case R_X86_64_GOT64
:
3716 /* Relocation is to the entry for this symbol in the global
3718 case R_X86_64_GOTPCREL
:
3719 case R_X86_64_GOTPCREL64
:
3720 /* Use global offset table entry as symbol value. */
3721 case R_X86_64_GOTPLT64
:
3722 /* This is the same as GOT64 for relocation purposes, but
3723 indicates the existence of a PLT entry. The difficulty is,
3724 that we must calculate the GOT slot offset from the PLT
3725 offset, if this symbol got a PLT entry (it was global).
3726 Additionally if it's computed from the PLT entry, then that
3727 GOT offset is relative to .got.plt, not to .got. */
3728 base_got
= htab
->elf
.sgot
;
3730 if (htab
->elf
.sgot
== NULL
)
3737 off
= h
->got
.offset
;
3739 && h
->plt
.offset
!= (bfd_vma
)-1
3740 && off
== (bfd_vma
)-1)
3742 /* We can't use h->got.offset here to save
3743 state, or even just remember the offset, as
3744 finish_dynamic_symbol would use that as offset into
3746 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3747 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3748 base_got
= htab
->elf
.sgotplt
;
3751 dyn
= htab
->elf
.dynamic_sections_created
;
3753 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3755 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3756 || (ELF_ST_VISIBILITY (h
->other
)
3757 && h
->root
.type
== bfd_link_hash_undefweak
))
3759 /* This is actually a static link, or it is a -Bsymbolic
3760 link and the symbol is defined locally, or the symbol
3761 was forced to be local because of a version file. We
3762 must initialize this entry in the global offset table.
3763 Since the offset must always be a multiple of 8, we
3764 use the least significant bit to record whether we
3765 have initialized it already.
3767 When doing a dynamic link, we create a .rela.got
3768 relocation entry to initialize the value. This is
3769 done in the finish_dynamic_symbol routine. */
3774 bfd_put_64 (output_bfd
, relocation
,
3775 base_got
->contents
+ off
);
3776 /* Note that this is harmless for the GOTPLT64 case,
3777 as -1 | 1 still is -1. */
3782 unresolved_reloc
= FALSE
;
3786 if (local_got_offsets
== NULL
)
3789 off
= local_got_offsets
[r_symndx
];
3791 /* The offset must always be a multiple of 8. We use
3792 the least significant bit to record whether we have
3793 already generated the necessary reloc. */
3798 bfd_put_64 (output_bfd
, relocation
,
3799 base_got
->contents
+ off
);
3804 Elf_Internal_Rela outrel
;
3806 /* We need to generate a R_X86_64_RELATIVE reloc
3807 for the dynamic linker. */
3808 s
= htab
->elf
.srelgot
;
3812 outrel
.r_offset
= (base_got
->output_section
->vma
3813 + base_got
->output_offset
3815 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3816 outrel
.r_addend
= relocation
;
3817 elf_append_rela (output_bfd
, s
, &outrel
);
3820 local_got_offsets
[r_symndx
] |= 1;
3824 if (off
>= (bfd_vma
) -2)
3827 relocation
= base_got
->output_section
->vma
3828 + base_got
->output_offset
+ off
;
3829 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3830 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3831 - htab
->elf
.sgotplt
->output_offset
;
3835 case R_X86_64_GOTOFF64
:
3836 /* Relocation is relative to the start of the global offset
3839 /* Check to make sure it isn't a protected function symbol
3840 for shared library since it may not be local when used
3841 as function address. */
3842 if (!info
->executable
3844 && !SYMBOLIC_BIND (info
, h
)
3846 && h
->type
== STT_FUNC
3847 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3849 (*_bfd_error_handler
)
3850 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3851 input_bfd
, h
->root
.root
.string
);
3852 bfd_set_error (bfd_error_bad_value
);
3856 /* Note that sgot is not involved in this
3857 calculation. We always want the start of .got.plt. If we
3858 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3859 permitted by the ABI, we might have to change this
3861 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3862 + htab
->elf
.sgotplt
->output_offset
;
3865 case R_X86_64_GOTPC32
:
3866 case R_X86_64_GOTPC64
:
3867 /* Use global offset table as symbol value. */
3868 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3869 + htab
->elf
.sgotplt
->output_offset
;
3870 unresolved_reloc
= FALSE
;
3873 case R_X86_64_PLTOFF64
:
3874 /* Relocation is PLT entry relative to GOT. For local
3875 symbols it's the symbol itself relative to GOT. */
3877 /* See PLT32 handling. */
3878 && h
->plt
.offset
!= (bfd_vma
) -1
3879 && htab
->elf
.splt
!= NULL
)
3881 if (htab
->plt_bnd
!= NULL
)
3883 resolved_plt
= htab
->plt_bnd
;
3884 plt_offset
= eh
->plt_bnd
.offset
;
3888 resolved_plt
= htab
->elf
.splt
;
3889 plt_offset
= h
->plt
.offset
;
3892 relocation
= (resolved_plt
->output_section
->vma
3893 + resolved_plt
->output_offset
3895 unresolved_reloc
= FALSE
;
3898 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3899 + htab
->elf
.sgotplt
->output_offset
;
3902 case R_X86_64_PLT32
:
3903 case R_X86_64_PLT32_BND
:
3904 /* Relocation is to the entry for this symbol in the
3905 procedure linkage table. */
3907 /* Resolve a PLT32 reloc against a local symbol directly,
3908 without using the procedure linkage table. */
3912 if (h
->plt
.offset
== (bfd_vma
) -1
3913 || htab
->elf
.splt
== NULL
)
3915 /* We didn't make a PLT entry for this symbol. This
3916 happens when statically linking PIC code, or when
3917 using -Bsymbolic. */
3921 if (htab
->plt_bnd
!= NULL
)
3923 resolved_plt
= htab
->plt_bnd
;
3924 plt_offset
= eh
->plt_bnd
.offset
;
3928 resolved_plt
= htab
->elf
.splt
;
3929 plt_offset
= h
->plt
.offset
;
3932 relocation
= (resolved_plt
->output_section
->vma
3933 + resolved_plt
->output_offset
3935 unresolved_reloc
= FALSE
;
3938 case R_X86_64_SIZE32
:
3939 case R_X86_64_SIZE64
:
3940 /* Set to symbol size. */
3941 relocation
= st_size
;
3947 case R_X86_64_PC32_BND
:
3949 && (input_section
->flags
& SEC_ALLOC
) != 0
3950 && (input_section
->flags
& SEC_READONLY
) != 0
3953 bfd_boolean fail
= FALSE
;
3955 = ((r_type
== R_X86_64_PC32
3956 || r_type
== R_X86_64_PC32_BND
)
3957 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3959 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3961 /* Symbol is referenced locally. Make sure it is
3962 defined locally or for a branch. */
3963 fail
= !h
->def_regular
&& !branch
;
3967 /* Symbol isn't referenced locally. We only allow
3968 branch to symbol with non-default visibility. */
3970 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3977 const char *pic
= "";
3979 switch (ELF_ST_VISIBILITY (h
->other
))
3982 v
= _("hidden symbol");
3985 v
= _("internal symbol");
3988 v
= _("protected symbol");
3992 pic
= _("; recompile with -fPIC");
3997 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3999 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
4001 (*_bfd_error_handler
) (fmt
, input_bfd
,
4002 x86_64_elf_howto_table
[r_type
].name
,
4003 v
, h
->root
.root
.string
, pic
);
4004 bfd_set_error (bfd_error_bad_value
);
4015 /* FIXME: The ABI says the linker should make sure the value is
4016 the same when it's zeroextended to 64 bit. */
4019 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4024 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4025 || h
->root
.type
!= bfd_link_hash_undefweak
)
4026 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4027 && r_type
!= R_X86_64_SIZE32
4028 && r_type
!= R_X86_64_SIZE64
)
4029 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4030 || (ELIMINATE_COPY_RELOCS
4037 || h
->root
.type
== bfd_link_hash_undefweak
4038 || h
->root
.type
== bfd_link_hash_undefined
)))
4040 Elf_Internal_Rela outrel
;
4041 bfd_boolean skip
, relocate
;
4044 /* When generating a shared object, these relocations
4045 are copied into the output file to be resolved at run
4051 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4053 if (outrel
.r_offset
== (bfd_vma
) -1)
4055 else if (outrel
.r_offset
== (bfd_vma
) -2)
4056 skip
= TRUE
, relocate
= TRUE
;
4058 outrel
.r_offset
+= (input_section
->output_section
->vma
4059 + input_section
->output_offset
);
4062 memset (&outrel
, 0, sizeof outrel
);
4064 /* h->dynindx may be -1 if this symbol was marked to
4068 && (IS_X86_64_PCREL_TYPE (r_type
)
4070 || ! SYMBOLIC_BIND (info
, h
)
4071 || ! h
->def_regular
))
4073 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4074 outrel
.r_addend
= rel
->r_addend
;
4078 /* This symbol is local, or marked to become local. */
4079 if (r_type
== htab
->pointer_r_type
)
4082 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4083 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4085 else if (r_type
== R_X86_64_64
4086 && !ABI_64_P (output_bfd
))
4089 outrel
.r_info
= htab
->r_info (0,
4090 R_X86_64_RELATIVE64
);
4091 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4092 /* Check addend overflow. */
4093 if ((outrel
.r_addend
& 0x80000000)
4094 != (rel
->r_addend
& 0x80000000))
4097 int addend
= rel
->r_addend
;
4098 if (h
&& h
->root
.root
.string
)
4099 name
= h
->root
.root
.string
;
4101 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4104 (*_bfd_error_handler
)
4105 (_("%B: addend -0x%x in relocation %s against "
4106 "symbol `%s' at 0x%lx in section `%A' is "
4108 input_bfd
, input_section
, addend
,
4109 x86_64_elf_howto_table
[r_type
].name
,
4110 name
, (unsigned long) rel
->r_offset
);
4112 (*_bfd_error_handler
)
4113 (_("%B: addend 0x%x in relocation %s against "
4114 "symbol `%s' at 0x%lx in section `%A' is "
4116 input_bfd
, input_section
, addend
,
4117 x86_64_elf_howto_table
[r_type
].name
,
4118 name
, (unsigned long) rel
->r_offset
);
4119 bfd_set_error (bfd_error_bad_value
);
4127 if (bfd_is_abs_section (sec
))
4129 else if (sec
== NULL
|| sec
->owner
== NULL
)
4131 bfd_set_error (bfd_error_bad_value
);
4138 /* We are turning this relocation into one
4139 against a section symbol. It would be
4140 proper to subtract the symbol's value,
4141 osec->vma, from the emitted reloc addend,
4142 but ld.so expects buggy relocs. */
4143 osec
= sec
->output_section
;
4144 sindx
= elf_section_data (osec
)->dynindx
;
4147 asection
*oi
= htab
->elf
.text_index_section
;
4148 sindx
= elf_section_data (oi
)->dynindx
;
4150 BFD_ASSERT (sindx
!= 0);
4153 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
4154 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4158 sreloc
= elf_section_data (input_section
)->sreloc
;
4160 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4162 r
= bfd_reloc_notsupported
;
4163 goto check_relocation_error
;
4166 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4168 /* If this reloc is against an external symbol, we do
4169 not want to fiddle with the addend. Otherwise, we
4170 need to include the symbol value so that it becomes
4171 an addend for the dynamic reloc. */
4178 case R_X86_64_TLSGD
:
4179 case R_X86_64_GOTPC32_TLSDESC
:
4180 case R_X86_64_TLSDESC_CALL
:
4181 case R_X86_64_GOTTPOFF
:
4182 tls_type
= GOT_UNKNOWN
;
4183 if (h
== NULL
&& local_got_offsets
)
4184 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
4186 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
4188 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4189 input_section
, contents
,
4190 symtab_hdr
, sym_hashes
,
4191 &r_type
, tls_type
, rel
,
4192 relend
, h
, r_symndx
))
4195 if (r_type
== R_X86_64_TPOFF32
)
4197 bfd_vma roff
= rel
->r_offset
;
4199 BFD_ASSERT (! unresolved_reloc
);
4201 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4203 /* GD->LE transition. For 64bit, change
4204 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4205 .word 0x6666; rex64; call __tls_get_addr
4208 leaq foo@tpoff(%rax), %rax
4210 leaq foo@tlsgd(%rip), %rdi
4211 .word 0x6666; rex64; call __tls_get_addr
4214 leaq foo@tpoff(%rax), %rax
4215 For largepic, change:
4216 leaq foo@tlsgd(%rip), %rdi
4217 movabsq $__tls_get_addr@pltoff, %rax
4222 leaq foo@tpoff(%rax), %rax
4223 nopw 0x0(%rax,%rax,1) */
4225 if (ABI_64_P (output_bfd
)
4226 && contents
[roff
+ 5] == (bfd_byte
) '\xb8')
4228 memcpy (contents
+ roff
- 3,
4229 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
4230 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4233 else if (ABI_64_P (output_bfd
))
4234 memcpy (contents
+ roff
- 4,
4235 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4238 memcpy (contents
+ roff
- 3,
4239 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4241 bfd_put_32 (output_bfd
,
4242 elf_x86_64_tpoff (info
, relocation
),
4243 contents
+ roff
+ 8 + largepic
);
4244 /* Skip R_X86_64_PC32/R_X86_64_PLT32/R_X86_64_PLTOFF64. */
4248 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4250 /* GDesc -> LE transition.
4251 It's originally something like:
4252 leaq x@tlsdesc(%rip), %rax
4255 movl $x@tpoff, %rax. */
4257 unsigned int val
, type
;
4259 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
4260 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4261 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
4262 contents
+ roff
- 3);
4263 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
4264 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4265 contents
+ roff
- 1);
4266 bfd_put_32 (output_bfd
,
4267 elf_x86_64_tpoff (info
, relocation
),
4271 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4273 /* GDesc -> LE transition.
4278 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4279 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4282 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
4284 /* IE->LE transition:
4285 Originally it can be one of:
4286 movq foo@gottpoff(%rip), %reg
4287 addq foo@gottpoff(%rip), %reg
4290 leaq foo(%reg), %reg
4293 unsigned int val
, type
, reg
;
4295 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
4296 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
4297 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4303 bfd_put_8 (output_bfd
, 0x49,
4304 contents
+ roff
- 3);
4305 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4306 bfd_put_8 (output_bfd
, 0x41,
4307 contents
+ roff
- 3);
4308 bfd_put_8 (output_bfd
, 0xc7,
4309 contents
+ roff
- 2);
4310 bfd_put_8 (output_bfd
, 0xc0 | reg
,
4311 contents
+ roff
- 1);
4315 /* addq -> addq - addressing with %rsp/%r12 is
4318 bfd_put_8 (output_bfd
, 0x49,
4319 contents
+ roff
- 3);
4320 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4321 bfd_put_8 (output_bfd
, 0x41,
4322 contents
+ roff
- 3);
4323 bfd_put_8 (output_bfd
, 0x81,
4324 contents
+ roff
- 2);
4325 bfd_put_8 (output_bfd
, 0xc0 | reg
,
4326 contents
+ roff
- 1);
4332 bfd_put_8 (output_bfd
, 0x4d,
4333 contents
+ roff
- 3);
4334 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4335 bfd_put_8 (output_bfd
, 0x45,
4336 contents
+ roff
- 3);
4337 bfd_put_8 (output_bfd
, 0x8d,
4338 contents
+ roff
- 2);
4339 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
4340 contents
+ roff
- 1);
4342 bfd_put_32 (output_bfd
,
4343 elf_x86_64_tpoff (info
, relocation
),
4351 if (htab
->elf
.sgot
== NULL
)
4356 off
= h
->got
.offset
;
4357 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
4361 if (local_got_offsets
== NULL
)
4364 off
= local_got_offsets
[r_symndx
];
4365 offplt
= local_tlsdesc_gotents
[r_symndx
];
4372 Elf_Internal_Rela outrel
;
4376 if (htab
->elf
.srelgot
== NULL
)
4379 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4381 if (GOT_TLS_GDESC_P (tls_type
))
4383 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
4384 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
4385 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
4386 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4387 + htab
->elf
.sgotplt
->output_offset
4389 + htab
->sgotplt_jump_table_size
);
4390 sreloc
= htab
->elf
.srelplt
;
4392 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
4394 outrel
.r_addend
= 0;
4395 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4398 sreloc
= htab
->elf
.srelgot
;
4400 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4401 + htab
->elf
.sgot
->output_offset
+ off
);
4403 if (GOT_TLS_GD_P (tls_type
))
4404 dr_type
= R_X86_64_DTPMOD64
;
4405 else if (GOT_TLS_GDESC_P (tls_type
))
4408 dr_type
= R_X86_64_TPOFF64
;
4410 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
4411 outrel
.r_addend
= 0;
4412 if ((dr_type
== R_X86_64_TPOFF64
4413 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
4414 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
4415 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
4417 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4419 if (GOT_TLS_GD_P (tls_type
))
4423 BFD_ASSERT (! unresolved_reloc
);
4424 bfd_put_64 (output_bfd
,
4425 relocation
- elf_x86_64_dtpoff_base (info
),
4426 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4430 bfd_put_64 (output_bfd
, 0,
4431 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4432 outrel
.r_info
= htab
->r_info (indx
,
4434 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
4435 elf_append_rela (output_bfd
, sreloc
,
4444 local_got_offsets
[r_symndx
] |= 1;
4447 if (off
>= (bfd_vma
) -2
4448 && ! GOT_TLS_GDESC_P (tls_type
))
4450 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4452 if (r_type
== R_X86_64_GOTPC32_TLSDESC
4453 || r_type
== R_X86_64_TLSDESC_CALL
)
4454 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4455 + htab
->elf
.sgotplt
->output_offset
4456 + offplt
+ htab
->sgotplt_jump_table_size
;
4458 relocation
= htab
->elf
.sgot
->output_section
->vma
4459 + htab
->elf
.sgot
->output_offset
+ off
;
4460 unresolved_reloc
= FALSE
;
4464 bfd_vma roff
= rel
->r_offset
;
4466 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4468 /* GD->IE transition. For 64bit, change
4469 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4470 .word 0x6666; rex64; call __tls_get_addr@plt
4473 addq foo@gottpoff(%rip), %rax
4475 leaq foo@tlsgd(%rip), %rdi
4476 .word 0x6666; rex64; call __tls_get_addr@plt
4479 addq foo@gottpoff(%rip), %rax
4480 For largepic, change:
4481 leaq foo@tlsgd(%rip), %rdi
4482 movabsq $__tls_get_addr@pltoff, %rax
4487 addq foo@gottpoff(%rax), %rax
4488 nopw 0x0(%rax,%rax,1) */
4490 if (ABI_64_P (output_bfd
)
4491 && contents
[roff
+ 5] == (bfd_byte
) '\xb8')
4493 memcpy (contents
+ roff
- 3,
4494 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
4495 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4498 else if (ABI_64_P (output_bfd
))
4499 memcpy (contents
+ roff
- 4,
4500 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4503 memcpy (contents
+ roff
- 3,
4504 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4507 relocation
= (htab
->elf
.sgot
->output_section
->vma
4508 + htab
->elf
.sgot
->output_offset
+ off
4511 - input_section
->output_section
->vma
4512 - input_section
->output_offset
4514 bfd_put_32 (output_bfd
, relocation
,
4515 contents
+ roff
+ 8 + largepic
);
4516 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
4520 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4522 /* GDesc -> IE transition.
4523 It's originally something like:
4524 leaq x@tlsdesc(%rip), %rax
4527 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4529 /* Now modify the instruction as appropriate. To
4530 turn a leaq into a movq in the form we use it, it
4531 suffices to change the second byte from 0x8d to
4533 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4535 bfd_put_32 (output_bfd
,
4536 htab
->elf
.sgot
->output_section
->vma
4537 + htab
->elf
.sgot
->output_offset
+ off
4539 - input_section
->output_section
->vma
4540 - input_section
->output_offset
4545 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4547 /* GDesc -> IE transition.
4554 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4555 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4563 case R_X86_64_TLSLD
:
4564 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4565 input_section
, contents
,
4566 symtab_hdr
, sym_hashes
,
4567 &r_type
, GOT_UNKNOWN
,
4568 rel
, relend
, h
, r_symndx
))
4571 if (r_type
!= R_X86_64_TLSLD
)
4573 /* LD->LE transition:
4574 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4575 For 64bit, we change it into:
4576 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4577 For 32bit, we change it into:
4578 nopl 0x0(%rax); movl %fs:0, %eax.
4579 For largepic, change:
4580 leaq foo@tlsgd(%rip), %rdi
4581 movabsq $__tls_get_addr@pltoff, %rax
4585 data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)
4588 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4589 if (ABI_64_P (output_bfd
)
4590 && contents
[rel
->r_offset
+ 5] == (bfd_byte
) '\xb8')
4591 memcpy (contents
+ rel
->r_offset
- 3,
4592 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
4593 "\x64\x48\x8b\x04\x25\0\0\0", 22);
4594 else if (ABI_64_P (output_bfd
))
4595 memcpy (contents
+ rel
->r_offset
- 3,
4596 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4598 memcpy (contents
+ rel
->r_offset
- 3,
4599 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4600 /* Skip R_X86_64_PC32/R_X86_64_PLT32/R_X86_64_PLTOFF64. */
4605 if (htab
->elf
.sgot
== NULL
)
4608 off
= htab
->tls_ld_got
.offset
;
4613 Elf_Internal_Rela outrel
;
4615 if (htab
->elf
.srelgot
== NULL
)
4618 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4619 + htab
->elf
.sgot
->output_offset
+ off
);
4621 bfd_put_64 (output_bfd
, 0,
4622 htab
->elf
.sgot
->contents
+ off
);
4623 bfd_put_64 (output_bfd
, 0,
4624 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4625 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4626 outrel
.r_addend
= 0;
4627 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4629 htab
->tls_ld_got
.offset
|= 1;
4631 relocation
= htab
->elf
.sgot
->output_section
->vma
4632 + htab
->elf
.sgot
->output_offset
+ off
;
4633 unresolved_reloc
= FALSE
;
4636 case R_X86_64_DTPOFF32
:
4637 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4638 relocation
-= elf_x86_64_dtpoff_base (info
);
4640 relocation
= elf_x86_64_tpoff (info
, relocation
);
4643 case R_X86_64_TPOFF32
:
4644 case R_X86_64_TPOFF64
:
4645 BFD_ASSERT (info
->executable
);
4646 relocation
= elf_x86_64_tpoff (info
, relocation
);
4649 case R_X86_64_DTPOFF64
:
4650 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
4651 relocation
-= elf_x86_64_dtpoff_base (info
);
4658 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4659 because such sections are not SEC_ALLOC and thus ld.so will
4660 not process them. */
4661 if (unresolved_reloc
4662 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4664 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4665 rel
->r_offset
) != (bfd_vma
) -1)
4667 (*_bfd_error_handler
)
4668 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4671 (long) rel
->r_offset
,
4673 h
->root
.root
.string
);
4678 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4679 contents
, rel
->r_offset
,
4680 relocation
, rel
->r_addend
);
4682 check_relocation_error
:
4683 if (r
!= bfd_reloc_ok
)
4688 name
= h
->root
.root
.string
;
4691 name
= bfd_elf_string_from_elf_section (input_bfd
,
4692 symtab_hdr
->sh_link
,
4697 name
= bfd_section_name (input_bfd
, sec
);
4700 if (r
== bfd_reloc_overflow
)
4702 if (! ((*info
->callbacks
->reloc_overflow
)
4703 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4704 (bfd_vma
) 0, input_bfd
, input_section
,
4710 (*_bfd_error_handler
)
4711 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4712 input_bfd
, input_section
,
4713 (long) rel
->r_offset
, name
, (int) r
);
4722 /* Finish up dynamic symbol handling. We set the contents of various
4723 dynamic sections here. */
4726 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4727 struct bfd_link_info
*info
,
4728 struct elf_link_hash_entry
*h
,
4729 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
4731 struct elf_x86_64_link_hash_table
*htab
;
4732 const struct elf_x86_64_backend_data
*abed
;
4733 bfd_boolean use_plt_bnd
;
4735 htab
= elf_x86_64_hash_table (info
);
4739 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
4740 section only if there is .plt section. */
4741 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
4743 ? &elf_x86_64_bnd_arch_bed
4744 : get_elf_x86_64_backend_data (output_bfd
));
4746 if (h
->plt
.offset
!= (bfd_vma
) -1)
4749 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
4750 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
4751 Elf_Internal_Rela rela
;
4753 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
4754 const struct elf_backend_data
*bed
;
4756 /* When building a static executable, use .iplt, .igot.plt and
4757 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4758 if (htab
->elf
.splt
!= NULL
)
4760 plt
= htab
->elf
.splt
;
4761 gotplt
= htab
->elf
.sgotplt
;
4762 relplt
= htab
->elf
.srelplt
;
4766 plt
= htab
->elf
.iplt
;
4767 gotplt
= htab
->elf
.igotplt
;
4768 relplt
= htab
->elf
.irelplt
;
4771 /* This symbol has an entry in the procedure linkage table. Set
4773 if ((h
->dynindx
== -1
4774 && !((h
->forced_local
|| info
->executable
)
4776 && h
->type
== STT_GNU_IFUNC
))
4782 /* Get the index in the procedure linkage table which
4783 corresponds to this symbol. This is the index of this symbol
4784 in all the symbols for which we are making plt entries. The
4785 first entry in the procedure linkage table is reserved.
4787 Get the offset into the .got table of the entry that
4788 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4789 bytes. The first three are reserved for the dynamic linker.
4791 For static executables, we don't reserve anything. */
4793 if (plt
== htab
->elf
.splt
)
4795 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
4796 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4800 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
4801 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4804 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
4805 plt_plt_offset
= abed
->plt_plt_offset
;
4806 plt_got_insn_size
= abed
->plt_got_insn_size
;
4807 plt_got_offset
= abed
->plt_got_offset
;
4810 /* Use the second PLT with BND relocations. */
4811 const bfd_byte
*plt_entry
, *plt2_entry
;
4812 struct elf_x86_64_link_hash_entry
*eh
4813 = (struct elf_x86_64_link_hash_entry
*) h
;
4815 if (eh
->has_bnd_reloc
)
4817 plt_entry
= elf_x86_64_bnd_plt_entry
;
4818 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
4822 plt_entry
= elf_x86_64_legacy_plt_entry
;
4823 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
4825 /* Subtract 1 since there is no BND prefix. */
4826 plt_plt_insn_end
-= 1;
4827 plt_plt_offset
-= 1;
4828 plt_got_insn_size
-= 1;
4829 plt_got_offset
-= 1;
4832 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
4833 == sizeof (elf_x86_64_legacy_plt_entry
));
4835 /* Fill in the entry in the procedure linkage table. */
4836 memcpy (plt
->contents
+ h
->plt
.offset
,
4837 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
4838 /* Fill in the entry in the second PLT. */
4839 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
4840 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
4842 resolved_plt
= htab
->plt_bnd
;
4843 plt_offset
= eh
->plt_bnd
.offset
;
4847 /* Fill in the entry in the procedure linkage table. */
4848 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
4849 abed
->plt_entry_size
);
4852 plt_offset
= h
->plt
.offset
;
4855 /* Insert the relocation positions of the plt section. */
4857 /* Put offset the PC-relative instruction referring to the GOT entry,
4858 subtracting the size of that instruction. */
4859 bfd_put_32 (output_bfd
,
4860 (gotplt
->output_section
->vma
4861 + gotplt
->output_offset
4863 - resolved_plt
->output_section
->vma
4864 - resolved_plt
->output_offset
4866 - plt_got_insn_size
),
4867 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
4869 /* Fill in the entry in the global offset table, initially this
4870 points to the second part of the PLT entry. */
4871 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4872 + plt
->output_offset
4873 + h
->plt
.offset
+ abed
->plt_lazy_offset
),
4874 gotplt
->contents
+ got_offset
);
4876 /* Fill in the entry in the .rela.plt section. */
4877 rela
.r_offset
= (gotplt
->output_section
->vma
4878 + gotplt
->output_offset
4880 if (h
->dynindx
== -1
4881 || ((info
->executable
4882 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4884 && h
->type
== STT_GNU_IFUNC
))
4886 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4887 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4888 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4889 rela
.r_addend
= (h
->root
.u
.def
.value
4890 + h
->root
.u
.def
.section
->output_section
->vma
4891 + h
->root
.u
.def
.section
->output_offset
);
4892 /* R_X86_64_IRELATIVE comes last. */
4893 plt_index
= htab
->next_irelative_index
--;
4897 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4899 plt_index
= htab
->next_jump_slot_index
++;
4902 /* Don't fill PLT entry for static executables. */
4903 if (plt
== htab
->elf
.splt
)
4905 /* Put relocation index. */
4906 bfd_put_32 (output_bfd
, plt_index
,
4907 plt
->contents
+ h
->plt
.offset
+ abed
->plt_reloc_offset
);
4908 /* Put offset for jmp .PLT0. */
4909 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ plt_plt_insn_end
),
4910 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
4913 bed
= get_elf_backend_data (output_bfd
);
4914 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4915 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4917 if (!h
->def_regular
)
4919 /* Mark the symbol as undefined, rather than as defined in
4920 the .plt section. Leave the value if there were any
4921 relocations where pointer equality matters (this is a clue
4922 for the dynamic linker, to make function pointer
4923 comparisons work between an application and shared
4924 library), otherwise set it to zero. If a function is only
4925 called from a binary, there is no need to slow down
4926 shared libraries because of that. */
4927 sym
->st_shndx
= SHN_UNDEF
;
4928 if (!h
->pointer_equality_needed
)
4933 if (h
->got
.offset
!= (bfd_vma
) -1
4934 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4935 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4937 Elf_Internal_Rela rela
;
4939 /* This symbol has an entry in the global offset table. Set it
4941 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4944 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4945 + htab
->elf
.sgot
->output_offset
4946 + (h
->got
.offset
&~ (bfd_vma
) 1));
4948 /* If this is a static link, or it is a -Bsymbolic link and the
4949 symbol is defined locally or was forced to be local because
4950 of a version file, we just want to emit a RELATIVE reloc.
4951 The entry in the global offset table will already have been
4952 initialized in the relocate_section function. */
4954 && h
->type
== STT_GNU_IFUNC
)
4958 /* Generate R_X86_64_GLOB_DAT. */
4965 if (!h
->pointer_equality_needed
)
4968 /* For non-shared object, we can't use .got.plt, which
4969 contains the real function addres if we need pointer
4970 equality. We load the GOT entry with the PLT entry. */
4971 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4972 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4973 + plt
->output_offset
4975 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4979 else if (info
->shared
4980 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4982 if (!h
->def_regular
)
4984 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4985 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4986 rela
.r_addend
= (h
->root
.u
.def
.value
4987 + h
->root
.u
.def
.section
->output_section
->vma
4988 + h
->root
.u
.def
.section
->output_offset
);
4992 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4994 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4995 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4996 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
5000 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
5005 Elf_Internal_Rela rela
;
5007 /* This symbol needs a copy reloc. Set it up. */
5009 if (h
->dynindx
== -1
5010 || (h
->root
.type
!= bfd_link_hash_defined
5011 && h
->root
.type
!= bfd_link_hash_defweak
)
5012 || htab
->srelbss
== NULL
)
5015 rela
.r_offset
= (h
->root
.u
.def
.value
5016 + h
->root
.u
.def
.section
->output_section
->vma
5017 + h
->root
.u
.def
.section
->output_offset
);
5018 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
5020 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
5026 /* Finish up local dynamic symbol handling. We set the contents of
5027 various dynamic sections here. */
5030 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
5032 struct elf_link_hash_entry
*h
5033 = (struct elf_link_hash_entry
*) *slot
;
5034 struct bfd_link_info
*info
5035 = (struct bfd_link_info
*) inf
;
5037 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
5041 /* Used to decide how to sort relocs in an optimal manner for the
5042 dynamic linker, before writing them out. */
5044 static enum elf_reloc_type_class
5045 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5046 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5047 const Elf_Internal_Rela
*rela
)
5049 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5051 case R_X86_64_RELATIVE
:
5052 case R_X86_64_RELATIVE64
:
5053 return reloc_class_relative
;
5054 case R_X86_64_JUMP_SLOT
:
5055 return reloc_class_plt
;
5057 return reloc_class_copy
;
5059 return reloc_class_normal
;
5063 /* Finish up the dynamic sections. */
5066 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
5067 struct bfd_link_info
*info
)
5069 struct elf_x86_64_link_hash_table
*htab
;
5072 const struct elf_x86_64_backend_data
*abed
;
5074 htab
= elf_x86_64_hash_table (info
);
5078 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5079 section only if there is .plt section. */
5080 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
5081 ? &elf_x86_64_bnd_arch_bed
5082 : get_elf_x86_64_backend_data (output_bfd
));
5084 dynobj
= htab
->elf
.dynobj
;
5085 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5087 if (htab
->elf
.dynamic_sections_created
)
5089 bfd_byte
*dyncon
, *dynconend
;
5090 const struct elf_backend_data
*bed
;
5091 bfd_size_type sizeof_dyn
;
5093 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5096 bed
= get_elf_backend_data (dynobj
);
5097 sizeof_dyn
= bed
->s
->sizeof_dyn
;
5098 dyncon
= sdyn
->contents
;
5099 dynconend
= sdyn
->contents
+ sdyn
->size
;
5100 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
5102 Elf_Internal_Dyn dyn
;
5105 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
5113 s
= htab
->elf
.sgotplt
;
5114 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5118 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
5122 s
= htab
->elf
.srelplt
->output_section
;
5123 dyn
.d_un
.d_val
= s
->size
;
5127 /* The procedure linkage table relocs (DT_JMPREL) should
5128 not be included in the overall relocs (DT_RELA).
5129 Therefore, we override the DT_RELASZ entry here to
5130 make it not include the JMPREL relocs. Since the
5131 linker script arranges for .rela.plt to follow all
5132 other relocation sections, we don't have to worry
5133 about changing the DT_RELA entry. */
5134 if (htab
->elf
.srelplt
!= NULL
)
5136 s
= htab
->elf
.srelplt
->output_section
;
5137 dyn
.d_un
.d_val
-= s
->size
;
5141 case DT_TLSDESC_PLT
:
5143 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
5144 + htab
->tlsdesc_plt
;
5147 case DT_TLSDESC_GOT
:
5149 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
5150 + htab
->tlsdesc_got
;
5154 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
5157 /* Fill in the special first entry in the procedure linkage table. */
5158 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5160 /* Fill in the first entry in the procedure linkage table. */
5161 memcpy (htab
->elf
.splt
->contents
,
5162 abed
->plt0_entry
, abed
->plt_entry_size
);
5163 /* Add offset for pushq GOT+8(%rip), since the instruction
5164 uses 6 bytes subtract this value. */
5165 bfd_put_32 (output_bfd
,
5166 (htab
->elf
.sgotplt
->output_section
->vma
5167 + htab
->elf
.sgotplt
->output_offset
5169 - htab
->elf
.splt
->output_section
->vma
5170 - htab
->elf
.splt
->output_offset
5172 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
5173 /* Add offset for the PC-relative instruction accessing GOT+16,
5174 subtracting the offset to the end of that instruction. */
5175 bfd_put_32 (output_bfd
,
5176 (htab
->elf
.sgotplt
->output_section
->vma
5177 + htab
->elf
.sgotplt
->output_offset
5179 - htab
->elf
.splt
->output_section
->vma
5180 - htab
->elf
.splt
->output_offset
5181 - abed
->plt0_got2_insn_end
),
5182 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
5184 elf_section_data (htab
->elf
.splt
->output_section
)
5185 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
5187 if (htab
->tlsdesc_plt
)
5189 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5190 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
5192 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
5193 abed
->plt0_entry
, abed
->plt_entry_size
);
5195 /* Add offset for pushq GOT+8(%rip), since the
5196 instruction uses 6 bytes subtract this value. */
5197 bfd_put_32 (output_bfd
,
5198 (htab
->elf
.sgotplt
->output_section
->vma
5199 + htab
->elf
.sgotplt
->output_offset
5201 - htab
->elf
.splt
->output_section
->vma
5202 - htab
->elf
.splt
->output_offset
5205 htab
->elf
.splt
->contents
5206 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
5207 /* Add offset for the PC-relative instruction accessing GOT+TDG,
5208 where TGD stands for htab->tlsdesc_got, subtracting the offset
5209 to the end of that instruction. */
5210 bfd_put_32 (output_bfd
,
5211 (htab
->elf
.sgot
->output_section
->vma
5212 + htab
->elf
.sgot
->output_offset
5214 - htab
->elf
.splt
->output_section
->vma
5215 - htab
->elf
.splt
->output_offset
5217 - abed
->plt0_got2_insn_end
),
5218 htab
->elf
.splt
->contents
5219 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
5224 if (htab
->plt_bnd
!= NULL
)
5225 elf_section_data (htab
->plt_bnd
->output_section
)
5226 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
5228 if (htab
->elf
.sgotplt
)
5230 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5232 (*_bfd_error_handler
)
5233 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5237 /* Fill in the first three entries in the global offset table. */
5238 if (htab
->elf
.sgotplt
->size
> 0)
5240 /* Set the first entry in the global offset table to the address of
5241 the dynamic section. */
5243 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
5245 bfd_put_64 (output_bfd
,
5246 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5247 htab
->elf
.sgotplt
->contents
);
5248 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
5249 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
5250 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
5253 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
5257 /* Adjust .eh_frame for .plt section. */
5258 if (htab
->plt_eh_frame
!= NULL
5259 && htab
->plt_eh_frame
->contents
!= NULL
)
5261 if (htab
->elf
.splt
!= NULL
5262 && htab
->elf
.splt
->size
!= 0
5263 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5264 && htab
->elf
.splt
->output_section
!= NULL
5265 && htab
->plt_eh_frame
->output_section
!= NULL
)
5267 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5268 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5269 + htab
->plt_eh_frame
->output_offset
5270 + PLT_FDE_START_OFFSET
;
5271 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5272 htab
->plt_eh_frame
->contents
5273 + PLT_FDE_START_OFFSET
);
5275 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5277 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5279 htab
->plt_eh_frame
->contents
))
5284 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5285 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
5288 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5289 htab_traverse (htab
->loc_hash_table
,
5290 elf_x86_64_finish_local_dynamic_symbol
,
5296 /* Return address for Ith PLT stub in section PLT, for relocation REL
5297 or (bfd_vma) -1 if it should not be included. */
5300 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
5301 const arelent
*rel ATTRIBUTE_UNUSED
)
5303 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
5306 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
5310 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
5317 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5320 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
5324 Elf_Internal_Shdr
*hdr
;
5329 plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
5330 /* Use the generic ELF version if there is no .plt.bnd section. */
5332 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
5333 dynsymcount
, dynsyms
, ret
);
5337 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
5340 if (dynsymcount
<= 0)
5343 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
5347 hdr
= &elf_section_data (relplt
)->this_hdr
;
5348 if (hdr
->sh_link
!= elf_dynsymtab (abfd
)
5349 || (hdr
->sh_type
!= SHT_REL
&& hdr
->sh_type
!= SHT_RELA
))
5352 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
5353 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
5356 count
= relplt
->size
/ hdr
->sh_entsize
;
5357 size
= count
* sizeof (asymbol
);
5358 p
= relplt
->relocation
;
5359 for (i
= 0; i
< count
; i
++, p
+= bed
->s
->int_rels_per_ext_rel
)
5361 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
5363 size
+= sizeof ("+0x") - 1 + 8 + 8;
5366 s
= *ret
= (asymbol
*) bfd_malloc (size
);
5370 names
= (char *) (s
+ count
);
5371 p
= relplt
->relocation
;
5374 for (i
= 0; i
< count
; i
++, p
++)
5378 *s
= **p
->sym_ptr_ptr
;
5379 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
5380 we are defining a symbol, ensure one of them is set. */
5381 if ((s
->flags
& BSF_LOCAL
) == 0)
5382 s
->flags
|= BSF_GLOBAL
;
5383 s
->flags
|= BSF_SYNTHETIC
;
5388 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
5389 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
5395 memcpy (names
, "+0x", sizeof ("+0x") - 1);
5396 names
+= sizeof ("+0x") - 1;
5397 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
5398 for (a
= buf
; *a
== '0'; ++a
)
5401 memcpy (names
, a
, len
);
5404 memcpy (names
, "@plt", sizeof ("@plt"));
5405 names
+= sizeof ("@plt");
5407 addr
+= sizeof (elf_x86_64_legacy_plt2_entry
);
5413 /* Handle an x86-64 specific section when reading an object file. This
5414 is called when elfcode.h finds a section with an unknown type. */
5417 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
5418 const char *name
, int shindex
)
5420 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
5423 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5429 /* Hook called by the linker routine which adds symbols from an object
5430 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
5434 elf_x86_64_add_symbol_hook (bfd
*abfd
,
5435 struct bfd_link_info
*info
,
5436 Elf_Internal_Sym
*sym
,
5437 const char **namep ATTRIBUTE_UNUSED
,
5438 flagword
*flagsp ATTRIBUTE_UNUSED
,
5444 switch (sym
->st_shndx
)
5446 case SHN_X86_64_LCOMMON
:
5447 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
5450 lcomm
= bfd_make_section_with_flags (abfd
,
5454 | SEC_LINKER_CREATED
));
5457 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
5460 *valp
= sym
->st_size
;
5464 if ((abfd
->flags
& DYNAMIC
) == 0
5465 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
5466 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
5467 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
5473 /* Given a BFD section, try to locate the corresponding ELF section
5477 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5478 asection
*sec
, int *index_return
)
5480 if (sec
== &_bfd_elf_large_com_section
)
5482 *index_return
= SHN_X86_64_LCOMMON
;
5488 /* Process a symbol. */
5491 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5494 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5496 switch (elfsym
->internal_elf_sym
.st_shndx
)
5498 case SHN_X86_64_LCOMMON
:
5499 asym
->section
= &_bfd_elf_large_com_section
;
5500 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5501 /* Common symbol doesn't set BSF_GLOBAL. */
5502 asym
->flags
&= ~BSF_GLOBAL
;
5508 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
5510 return (sym
->st_shndx
== SHN_COMMON
5511 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
5515 elf_x86_64_common_section_index (asection
*sec
)
5517 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5520 return SHN_X86_64_LCOMMON
;
5524 elf_x86_64_common_section (asection
*sec
)
5526 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5527 return bfd_com_section_ptr
;
5529 return &_bfd_elf_large_com_section
;
5533 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5534 const Elf_Internal_Sym
*sym
,
5539 const asection
*oldsec
)
5541 /* A normal common symbol and a large common symbol result in a
5542 normal common symbol. We turn the large common symbol into a
5545 && h
->root
.type
== bfd_link_hash_common
5547 && bfd_is_com_section (*psec
)
5550 if (sym
->st_shndx
== SHN_COMMON
5551 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5553 h
->root
.u
.c
.p
->section
5554 = bfd_make_section_old_way (oldbfd
, "COMMON");
5555 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5557 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5558 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5559 *psec
= bfd_com_section_ptr
;
5566 elf_x86_64_additional_program_headers (bfd
*abfd
,
5567 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5572 /* Check to see if we need a large readonly segment. */
5573 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5574 if (s
&& (s
->flags
& SEC_LOAD
))
5577 /* Check to see if we need a large data segment. Since .lbss sections
5578 is placed right after the .bss section, there should be no need for
5579 a large data segment just because of .lbss. */
5580 s
= bfd_get_section_by_name (abfd
, ".ldata");
5581 if (s
&& (s
->flags
& SEC_LOAD
))
5587 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5590 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
5592 if (h
->plt
.offset
!= (bfd_vma
) -1
5594 && !h
->pointer_equality_needed
)
5597 return _bfd_elf_hash_symbol (h
);
5600 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5603 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5604 const bfd_target
*output
)
5606 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5607 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5608 && _bfd_elf_relocs_compatible (input
, output
));
5611 static const struct bfd_elf_special_section
5612 elf_x86_64_special_sections
[]=
5614 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5615 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5616 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
5617 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5618 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5619 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5620 { NULL
, 0, 0, 0, 0 }
5623 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
5624 #define TARGET_LITTLE_NAME "elf64-x86-64"
5625 #define ELF_ARCH bfd_arch_i386
5626 #define ELF_TARGET_ID X86_64_ELF_DATA
5627 #define ELF_MACHINE_CODE EM_X86_64
5628 #define ELF_MAXPAGESIZE 0x200000
5629 #define ELF_MINPAGESIZE 0x1000
5630 #define ELF_COMMONPAGESIZE 0x1000
5632 #define elf_backend_can_gc_sections 1
5633 #define elf_backend_can_refcount 1
5634 #define elf_backend_want_got_plt 1
5635 #define elf_backend_plt_readonly 1
5636 #define elf_backend_want_plt_sym 0
5637 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5638 #define elf_backend_rela_normal 1
5639 #define elf_backend_plt_alignment 4
5641 #define elf_info_to_howto elf_x86_64_info_to_howto
5643 #define bfd_elf64_bfd_link_hash_table_create \
5644 elf_x86_64_link_hash_table_create
5645 #define bfd_elf64_bfd_link_hash_table_free \
5646 elf_x86_64_link_hash_table_free
5647 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5648 #define bfd_elf64_bfd_reloc_name_lookup \
5649 elf_x86_64_reloc_name_lookup
5651 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
5652 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5653 #define elf_backend_check_relocs elf_x86_64_check_relocs
5654 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
5655 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
5656 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5657 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5658 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
5659 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
5660 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5661 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5663 #define elf_backend_write_core_note elf_x86_64_write_core_note
5665 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5666 #define elf_backend_relocate_section elf_x86_64_relocate_section
5667 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
5668 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5669 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5670 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
5671 #define elf_backend_object_p elf64_x86_64_elf_object_p
5672 #define bfd_elf64_mkobject elf_x86_64_mkobject
5673 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5675 #define elf_backend_section_from_shdr \
5676 elf_x86_64_section_from_shdr
5678 #define elf_backend_section_from_bfd_section \
5679 elf_x86_64_elf_section_from_bfd_section
5680 #define elf_backend_add_symbol_hook \
5681 elf_x86_64_add_symbol_hook
5682 #define elf_backend_symbol_processing \
5683 elf_x86_64_symbol_processing
5684 #define elf_backend_common_section_index \
5685 elf_x86_64_common_section_index
5686 #define elf_backend_common_section \
5687 elf_x86_64_common_section
5688 #define elf_backend_common_definition \
5689 elf_x86_64_common_definition
5690 #define elf_backend_merge_symbol \
5691 elf_x86_64_merge_symbol
5692 #define elf_backend_special_sections \
5693 elf_x86_64_special_sections
5694 #define elf_backend_additional_program_headers \
5695 elf_x86_64_additional_program_headers
5696 #define elf_backend_hash_symbol \
5697 elf_x86_64_hash_symbol
5699 #include "elf64-target.h"
5701 /* FreeBSD support. */
5703 #undef TARGET_LITTLE_SYM
5704 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
5705 #undef TARGET_LITTLE_NAME
5706 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5709 #define ELF_OSABI ELFOSABI_FREEBSD
5712 #define elf64_bed elf64_x86_64_fbsd_bed
5714 #include "elf64-target.h"
5716 /* Solaris 2 support. */
5718 #undef TARGET_LITTLE_SYM
5719 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
5720 #undef TARGET_LITTLE_NAME
5721 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5723 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5724 objects won't be recognized. */
5728 #define elf64_bed elf64_x86_64_sol2_bed
5730 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5732 #undef elf_backend_static_tls_alignment
5733 #define elf_backend_static_tls_alignment 16
5735 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5737 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5739 #undef elf_backend_want_plt_sym
5740 #define elf_backend_want_plt_sym 1
5742 #include "elf64-target.h"
5744 #undef bfd_elf64_get_synthetic_symtab
5746 /* Native Client support. */
5749 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
5751 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
5752 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
5756 #undef TARGET_LITTLE_SYM
5757 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_nacl_vec
5758 #undef TARGET_LITTLE_NAME
5759 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5761 #define elf64_bed elf64_x86_64_nacl_bed
5763 #undef ELF_MAXPAGESIZE
5764 #undef ELF_MINPAGESIZE
5765 #undef ELF_COMMONPAGESIZE
5766 #define ELF_MAXPAGESIZE 0x10000
5767 #define ELF_MINPAGESIZE 0x10000
5768 #define ELF_COMMONPAGESIZE 0x10000
5770 /* Restore defaults. */
5772 #undef elf_backend_static_tls_alignment
5773 #undef elf_backend_want_plt_sym
5774 #define elf_backend_want_plt_sym 0
5776 /* NaCl uses substantially different PLT entries for the same effects. */
5778 #undef elf_backend_plt_alignment
5779 #define elf_backend_plt_alignment 5
5780 #define NACL_PLT_ENTRY_SIZE 64
5781 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5783 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
5785 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5786 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5787 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5788 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5789 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5791 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
5792 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
5794 /* 32 bytes of nop to pad out to the standard size. */
5795 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5796 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5797 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5798 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5799 0x66, /* excess data32 prefix */
5803 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5805 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5806 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5807 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5808 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5810 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5811 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5812 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5814 /* Lazy GOT entries point here (32-byte aligned). */
5815 0x68, /* pushq immediate */
5816 0, 0, 0, 0, /* replaced with index into relocation table. */
5817 0xe9, /* jmp relative */
5818 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5820 /* 22 bytes of nop to pad out to the standard size. */
5821 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5822 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5823 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5826 /* .eh_frame covering the .plt section. */
5828 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
5830 #if (PLT_CIE_LENGTH != 20 \
5831 || PLT_FDE_LENGTH != 36 \
5832 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5833 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5834 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5836 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5837 0, 0, 0, 0, /* CIE ID */
5838 1, /* CIE version */
5839 'z', 'R', 0, /* Augmentation string */
5840 1, /* Code alignment factor */
5841 0x78, /* Data alignment factor */
5842 16, /* Return address column */
5843 1, /* Augmentation size */
5844 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5845 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5846 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5847 DW_CFA_nop
, DW_CFA_nop
,
5849 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5850 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
5851 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5852 0, 0, 0, 0, /* .plt size goes here */
5853 0, /* Augmentation size */
5854 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
5855 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5856 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
5857 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5858 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5859 13, /* Block length */
5860 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
5861 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
5862 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5863 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
5864 DW_CFA_nop
, DW_CFA_nop
5867 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
5869 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
5870 elf_x86_64_nacl_plt_entry
, /* plt_entry */
5871 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5872 2, /* plt0_got1_offset */
5873 9, /* plt0_got2_offset */
5874 13, /* plt0_got2_insn_end */
5875 3, /* plt_got_offset */
5876 33, /* plt_reloc_offset */
5877 38, /* plt_plt_offset */
5878 7, /* plt_got_insn_size */
5879 42, /* plt_plt_insn_end */
5880 32, /* plt_lazy_offset */
5881 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
5882 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
5885 #undef elf_backend_arch_data
5886 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5888 #undef elf_backend_object_p
5889 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
5890 #undef elf_backend_modify_segment_map
5891 #define elf_backend_modify_segment_map nacl_modify_segment_map
5892 #undef elf_backend_modify_program_headers
5893 #define elf_backend_modify_program_headers nacl_modify_program_headers
5894 #undef elf_backend_final_write_processing
5895 #define elf_backend_final_write_processing nacl_final_write_processing
5897 #include "elf64-target.h"
5899 /* Native Client x32 support. */
5902 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
5904 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
5905 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
5909 #undef TARGET_LITTLE_SYM
5910 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_nacl_vec
5911 #undef TARGET_LITTLE_NAME
5912 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5914 #define elf32_bed elf32_x86_64_nacl_bed
5916 #define bfd_elf32_bfd_link_hash_table_create \
5917 elf_x86_64_link_hash_table_create
5918 #define bfd_elf32_bfd_link_hash_table_free \
5919 elf_x86_64_link_hash_table_free
5920 #define bfd_elf32_bfd_reloc_type_lookup \
5921 elf_x86_64_reloc_type_lookup
5922 #define bfd_elf32_bfd_reloc_name_lookup \
5923 elf_x86_64_reloc_name_lookup
5924 #define bfd_elf32_mkobject \
5927 #undef elf_backend_object_p
5928 #define elf_backend_object_p \
5929 elf32_x86_64_nacl_elf_object_p
5931 #undef elf_backend_bfd_from_remote_memory
5932 #define elf_backend_bfd_from_remote_memory \
5933 _bfd_elf32_bfd_from_remote_memory
5935 #undef elf_backend_size_info
5936 #define elf_backend_size_info \
5937 _bfd_elf32_size_info
5939 #include "elf32-target.h"
5941 /* Restore defaults. */
5942 #undef elf_backend_object_p
5943 #define elf_backend_object_p elf64_x86_64_elf_object_p
5944 #undef elf_backend_bfd_from_remote_memory
5945 #undef elf_backend_size_info
5946 #undef elf_backend_modify_segment_map
5947 #undef elf_backend_modify_program_headers
5948 #undef elf_backend_final_write_processing
5950 /* Intel L1OM support. */
5953 elf64_l1om_elf_object_p (bfd
*abfd
)
5955 /* Set the right machine number for an L1OM elf64 file. */
5956 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5960 #undef TARGET_LITTLE_SYM
5961 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5962 #undef TARGET_LITTLE_NAME
5963 #define TARGET_LITTLE_NAME "elf64-l1om"
5965 #define ELF_ARCH bfd_arch_l1om
5967 #undef ELF_MACHINE_CODE
5968 #define ELF_MACHINE_CODE EM_L1OM
5973 #define elf64_bed elf64_l1om_bed
5975 #undef elf_backend_object_p
5976 #define elf_backend_object_p elf64_l1om_elf_object_p
5978 /* Restore defaults. */
5979 #undef ELF_MAXPAGESIZE
5980 #undef ELF_MINPAGESIZE
5981 #undef ELF_COMMONPAGESIZE
5982 #define ELF_MAXPAGESIZE 0x200000
5983 #define ELF_MINPAGESIZE 0x1000
5984 #define ELF_COMMONPAGESIZE 0x1000
5985 #undef elf_backend_plt_alignment
5986 #define elf_backend_plt_alignment 4
5987 #undef elf_backend_arch_data
5988 #define elf_backend_arch_data &elf_x86_64_arch_bed
5990 #include "elf64-target.h"
5992 /* FreeBSD L1OM support. */
5994 #undef TARGET_LITTLE_SYM
5995 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5996 #undef TARGET_LITTLE_NAME
5997 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
6000 #define ELF_OSABI ELFOSABI_FREEBSD
6003 #define elf64_bed elf64_l1om_fbsd_bed
6005 #include "elf64-target.h"
6007 /* Intel K1OM support. */
6010 elf64_k1om_elf_object_p (bfd
*abfd
)
6012 /* Set the right machine number for an K1OM elf64 file. */
6013 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
6017 #undef TARGET_LITTLE_SYM
6018 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
6019 #undef TARGET_LITTLE_NAME
6020 #define TARGET_LITTLE_NAME "elf64-k1om"
6022 #define ELF_ARCH bfd_arch_k1om
6024 #undef ELF_MACHINE_CODE
6025 #define ELF_MACHINE_CODE EM_K1OM
6030 #define elf64_bed elf64_k1om_bed
6032 #undef elf_backend_object_p
6033 #define elf_backend_object_p elf64_k1om_elf_object_p
6035 #undef elf_backend_static_tls_alignment
6037 #undef elf_backend_want_plt_sym
6038 #define elf_backend_want_plt_sym 0
6040 #include "elf64-target.h"
6042 /* FreeBSD K1OM support. */
6044 #undef TARGET_LITTLE_SYM
6045 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
6046 #undef TARGET_LITTLE_NAME
6047 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
6050 #define ELF_OSABI ELFOSABI_FREEBSD
6053 #define elf64_bed elf64_k1om_fbsd_bed
6055 #include "elf64-target.h"
6057 /* 32bit x86-64 support. */
6059 #undef TARGET_LITTLE_SYM
6060 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
6061 #undef TARGET_LITTLE_NAME
6062 #define TARGET_LITTLE_NAME "elf32-x86-64"
6066 #define ELF_ARCH bfd_arch_i386
6068 #undef ELF_MACHINE_CODE
6069 #define ELF_MACHINE_CODE EM_X86_64
6073 #undef elf_backend_object_p
6074 #define elf_backend_object_p \
6075 elf32_x86_64_elf_object_p
6077 #undef elf_backend_bfd_from_remote_memory
6078 #define elf_backend_bfd_from_remote_memory \
6079 _bfd_elf32_bfd_from_remote_memory
6081 #undef elf_backend_size_info
6082 #define elf_backend_size_info \
6083 _bfd_elf32_size_info
6085 #include "elf32-target.h"