1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "elfxx-x86.h"
24 #include "libiberty.h"
27 #include "opcode/i386.h"
34 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
35 #define MINUS_ONE (~ (bfd_vma) 0)
37 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
38 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
39 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
40 since they are the same. */
42 /* The relocation "howto" table. Order of fields:
43 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
44 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
45 static reloc_howto_type x86_64_elf_howto_table
[] =
47 HOWTO(R_X86_64_NONE
, 0, 0, 0, false, 0, complain_overflow_dont
,
48 bfd_elf_generic_reloc
, "R_X86_64_NONE", false, 0, 0x00000000,
50 HOWTO(R_X86_64_64
, 0, 8, 64, false, 0, complain_overflow_dont
,
51 bfd_elf_generic_reloc
, "R_X86_64_64", false, 0, MINUS_ONE
,
53 HOWTO(R_X86_64_PC32
, 0, 4, 32, true, 0, complain_overflow_signed
,
54 bfd_elf_generic_reloc
, "R_X86_64_PC32", false, 0, 0xffffffff,
56 HOWTO(R_X86_64_GOT32
, 0, 4, 32, false, 0, complain_overflow_signed
,
57 bfd_elf_generic_reloc
, "R_X86_64_GOT32", false, 0, 0xffffffff,
59 HOWTO(R_X86_64_PLT32
, 0, 4, 32, true, 0, complain_overflow_signed
,
60 bfd_elf_generic_reloc
, "R_X86_64_PLT32", false, 0, 0xffffffff,
62 HOWTO(R_X86_64_COPY
, 0, 4, 32, false, 0, complain_overflow_bitfield
,
63 bfd_elf_generic_reloc
, "R_X86_64_COPY", false, 0, 0xffffffff,
65 HOWTO(R_X86_64_GLOB_DAT
, 0, 8, 64, false, 0, complain_overflow_dont
,
66 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", false, 0, MINUS_ONE
,
68 HOWTO(R_X86_64_JUMP_SLOT
, 0, 8, 64, false, 0, complain_overflow_dont
,
69 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", false, 0, MINUS_ONE
,
71 HOWTO(R_X86_64_RELATIVE
, 0, 8, 64, false, 0, complain_overflow_dont
,
72 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", false, 0, MINUS_ONE
,
74 HOWTO(R_X86_64_GOTPCREL
, 0, 4, 32, true, 0, complain_overflow_signed
,
75 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", false, 0, 0xffffffff,
77 HOWTO(R_X86_64_32
, 0, 4, 32, false, 0, complain_overflow_unsigned
,
78 bfd_elf_generic_reloc
, "R_X86_64_32", false, 0, 0xffffffff,
80 HOWTO(R_X86_64_32S
, 0, 4, 32, false, 0, complain_overflow_signed
,
81 bfd_elf_generic_reloc
, "R_X86_64_32S", false, 0, 0xffffffff,
83 HOWTO(R_X86_64_16
, 0, 2, 16, false, 0, complain_overflow_bitfield
,
84 bfd_elf_generic_reloc
, "R_X86_64_16", false, 0, 0xffff, false),
85 HOWTO(R_X86_64_PC16
, 0, 2, 16, true, 0, complain_overflow_bitfield
,
86 bfd_elf_generic_reloc
, "R_X86_64_PC16", false, 0, 0xffff, true),
87 HOWTO(R_X86_64_8
, 0, 1, 8, false, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_X86_64_8", false, 0, 0xff, false),
89 HOWTO(R_X86_64_PC8
, 0, 1, 8, true, 0, complain_overflow_signed
,
90 bfd_elf_generic_reloc
, "R_X86_64_PC8", false, 0, 0xff, true),
91 HOWTO(R_X86_64_DTPMOD64
, 0, 8, 64, false, 0, complain_overflow_dont
,
92 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", false, 0, MINUS_ONE
,
94 HOWTO(R_X86_64_DTPOFF64
, 0, 8, 64, false, 0, complain_overflow_dont
,
95 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", false, 0, MINUS_ONE
,
97 HOWTO(R_X86_64_TPOFF64
, 0, 8, 64, false, 0, complain_overflow_dont
,
98 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", false, 0, MINUS_ONE
,
100 HOWTO(R_X86_64_TLSGD
, 0, 4, 32, true, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", false, 0, 0xffffffff,
103 HOWTO(R_X86_64_TLSLD
, 0, 4, 32, true, 0, complain_overflow_signed
,
104 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", false, 0, 0xffffffff,
106 HOWTO(R_X86_64_DTPOFF32
, 0, 4, 32, false, 0, complain_overflow_signed
,
107 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", false, 0, 0xffffffff,
109 HOWTO(R_X86_64_GOTTPOFF
, 0, 4, 32, true, 0, complain_overflow_signed
,
110 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", false, 0, 0xffffffff,
112 HOWTO(R_X86_64_TPOFF32
, 0, 4, 32, false, 0, complain_overflow_signed
,
113 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", false, 0, 0xffffffff,
115 HOWTO(R_X86_64_PC64
, 0, 8, 64, true, 0, complain_overflow_dont
,
116 bfd_elf_generic_reloc
, "R_X86_64_PC64", false, 0, MINUS_ONE
,
118 HOWTO(R_X86_64_GOTOFF64
, 0, 8, 64, false, 0, complain_overflow_dont
,
119 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64", false, 0, MINUS_ONE
,
121 HOWTO(R_X86_64_GOTPC32
, 0, 4, 32, true, 0, complain_overflow_signed
,
122 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32", false, 0, 0xffffffff,
124 HOWTO(R_X86_64_GOT64
, 0, 8, 64, false, 0, complain_overflow_signed
,
125 bfd_elf_generic_reloc
, "R_X86_64_GOT64", false, 0, MINUS_ONE
,
127 HOWTO(R_X86_64_GOTPCREL64
, 0, 8, 64, true, 0, complain_overflow_signed
,
128 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", false, 0, MINUS_ONE
,
130 HOWTO(R_X86_64_GOTPC64
, 0, 8, 64, true, 0, complain_overflow_signed
,
131 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64", false, 0, MINUS_ONE
,
133 HOWTO(R_X86_64_GOTPLT64
, 0, 8, 64, false, 0, complain_overflow_signed
,
134 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", false, 0, MINUS_ONE
,
136 HOWTO(R_X86_64_PLTOFF64
, 0, 8, 64, false, 0, complain_overflow_signed
,
137 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", false, 0, MINUS_ONE
,
139 HOWTO(R_X86_64_SIZE32
, 0, 4, 32, false, 0, complain_overflow_unsigned
,
140 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", false, 0, 0xffffffff,
142 HOWTO(R_X86_64_SIZE64
, 0, 8, 64, false, 0, complain_overflow_dont
,
143 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", false, 0, MINUS_ONE
,
145 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 4, 32, true, 0,
146 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
147 "R_X86_64_GOTPC32_TLSDESC", false, 0, 0xffffffff, true),
148 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, false, 0,
149 complain_overflow_dont
, bfd_elf_generic_reloc
,
150 "R_X86_64_TLSDESC_CALL",
152 HOWTO(R_X86_64_TLSDESC
, 0, 8, 64, false, 0,
153 complain_overflow_dont
, bfd_elf_generic_reloc
,
154 "R_X86_64_TLSDESC", false, 0, MINUS_ONE
, false),
155 HOWTO(R_X86_64_IRELATIVE
, 0, 8, 64, false, 0, complain_overflow_dont
,
156 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", false, 0, MINUS_ONE
,
158 HOWTO(R_X86_64_RELATIVE64
, 0, 8, 64, false, 0, complain_overflow_dont
,
159 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", false, 0, MINUS_ONE
,
161 HOWTO(R_X86_64_PC32_BND
, 0, 4, 32, true, 0, complain_overflow_signed
,
162 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", false, 0, 0xffffffff,
164 HOWTO(R_X86_64_PLT32_BND
, 0, 4, 32, true, 0, complain_overflow_signed
,
165 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", false, 0, 0xffffffff,
167 HOWTO(R_X86_64_GOTPCRELX
, 0, 4, 32, true, 0, complain_overflow_signed
,
168 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", false, 0, 0xffffffff,
170 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 4, 32, true, 0, complain_overflow_signed
,
171 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", false, 0, 0xffffffff,
174 /* We have a gap in the reloc numbers here.
175 R_X86_64_standard counts the number up to this point, and
176 R_X86_64_vt_offset is the value to subtract from a reloc type of
177 R_X86_64_GNU_VT* to form an index into this table. */
178 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
179 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
181 /* GNU extension to record C++ vtable hierarchy. */
182 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 8, 0, false, 0, complain_overflow_dont
,
183 NULL
, "R_X86_64_GNU_VTINHERIT", false, 0, 0, false),
185 /* GNU extension to record C++ vtable member usage. */
186 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 8, 0, false, 0, complain_overflow_dont
,
187 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", false, 0, 0,
190 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
191 HOWTO(R_X86_64_32
, 0, 4, 32, false, 0, complain_overflow_bitfield
,
192 bfd_elf_generic_reloc
, "R_X86_64_32", false, 0, 0xffffffff,
196 /* Map BFD relocs to the x86_64 elf relocs. */
199 bfd_reloc_code_real_type bfd_reloc_val
;
200 unsigned char elf_reloc_val
;
203 static const struct elf_reloc_map x86_64_reloc_map
[] =
205 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
206 { BFD_RELOC_64
, R_X86_64_64
, },
207 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
208 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
209 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
210 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
211 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
212 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
213 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
214 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
215 { BFD_RELOC_32
, R_X86_64_32
, },
216 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
217 { BFD_RELOC_16
, R_X86_64_16
, },
218 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
219 { BFD_RELOC_8
, R_X86_64_8
, },
220 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
221 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
222 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
223 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
224 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
225 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
226 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
227 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
228 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
229 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
230 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
231 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
232 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
233 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
234 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
235 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
236 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
237 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
238 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
239 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
240 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
241 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
242 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
243 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
244 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
245 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
246 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
247 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
248 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
251 static reloc_howto_type
*
252 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
256 if (r_type
== (unsigned int) R_X86_64_32
)
261 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
263 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
264 || r_type
>= (unsigned int) R_X86_64_max
)
266 if (r_type
>= (unsigned int) R_X86_64_standard
)
268 /* xgettext:c-format */
269 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
271 bfd_set_error (bfd_error_bad_value
);
277 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
278 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
279 return &x86_64_elf_howto_table
[i
];
282 /* Given a BFD reloc type, return a HOWTO structure. */
283 static reloc_howto_type
*
284 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
285 bfd_reloc_code_real_type code
)
289 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
292 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
293 return elf_x86_64_rtype_to_howto (abfd
,
294 x86_64_reloc_map
[i
].elf_reloc_val
);
299 static reloc_howto_type
*
300 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
305 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
307 /* Get x32 R_X86_64_32. */
308 reloc_howto_type
*reloc
309 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
310 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
314 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
315 if (x86_64_elf_howto_table
[i
].name
!= NULL
316 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
317 return &x86_64_elf_howto_table
[i
];
322 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
325 elf_x86_64_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
326 Elf_Internal_Rela
*dst
)
330 r_type
= ELF32_R_TYPE (dst
->r_info
);
331 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
332 if (cache_ptr
->howto
== NULL
)
334 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
|| cache_ptr
->howto
->type
== R_X86_64_NONE
);
338 /* Support for core dump NOTE sections. */
340 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
345 switch (note
->descsz
)
350 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
352 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
355 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
363 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
365 elf_tdata (abfd
)->core
->signal
366 = bfd_get_16 (abfd
, note
->descdata
+ 12);
369 elf_tdata (abfd
)->core
->lwpid
370 = bfd_get_32 (abfd
, note
->descdata
+ 32);
379 /* Make a ".reg/999" section. */
380 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
381 size
, note
->descpos
+ offset
);
385 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
387 switch (note
->descsz
)
393 /* sizeof (struct elf_external_linux_prpsinfo32_ugid16). */
394 elf_tdata (abfd
)->core
->pid
395 = bfd_get_32 (abfd
, note
->descdata
+ 12);
396 elf_tdata (abfd
)->core
->program
397 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
398 elf_tdata (abfd
)->core
->command
399 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
403 /* sizeof (struct elf_external_linux_prpsinfo32_ugid32). */
404 elf_tdata (abfd
)->core
->pid
405 = bfd_get_32 (abfd
, note
->descdata
+ 12);
406 elf_tdata (abfd
)->core
->program
407 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
408 elf_tdata (abfd
)->core
->command
409 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
413 /* sizeof (struct elf_prpsinfo) on Linux/x86_64. */
414 elf_tdata (abfd
)->core
->pid
415 = bfd_get_32 (abfd
, note
->descdata
+ 24);
416 elf_tdata (abfd
)->core
->program
417 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
418 elf_tdata (abfd
)->core
->command
419 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
422 /* Note that for some reason, a spurious space is tacked
423 onto the end of the args in some (at least one anyway)
424 implementations, so strip it off if it exists. */
427 char *command
= elf_tdata (abfd
)->core
->command
;
428 int n
= strlen (command
);
430 if (0 < n
&& command
[n
- 1] == ' ')
431 command
[n
- 1] = '\0';
438 # if GCC_VERSION >= 8000
439 # pragma GCC diagnostic push
440 # pragma GCC diagnostic ignored "-Wstringop-truncation"
443 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
446 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
448 const char *fname
, *psargs
;
459 va_start (ap
, note_type
);
460 fname
= va_arg (ap
, const char *);
461 psargs
= va_arg (ap
, const char *);
464 if (bed
->s
->elfclass
== ELFCLASS32
)
467 memset (&data
, 0, sizeof (data
));
468 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
469 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
470 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
471 &data
, sizeof (data
));
476 memset (&data
, 0, sizeof (data
));
477 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
478 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
479 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
480 &data
, sizeof (data
));
485 va_start (ap
, note_type
);
486 pid
= va_arg (ap
, long);
487 cursig
= va_arg (ap
, int);
488 gregs
= va_arg (ap
, const void *);
491 if (bed
->s
->elfclass
== ELFCLASS32
)
493 if (bed
->elf_machine_code
== EM_X86_64
)
495 prstatusx32_t prstat
;
496 memset (&prstat
, 0, sizeof (prstat
));
498 prstat
.pr_cursig
= cursig
;
499 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
500 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
501 &prstat
, sizeof (prstat
));
506 memset (&prstat
, 0, sizeof (prstat
));
508 prstat
.pr_cursig
= cursig
;
509 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
510 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
511 &prstat
, sizeof (prstat
));
517 memset (&prstat
, 0, sizeof (prstat
));
519 prstat
.pr_cursig
= cursig
;
520 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
521 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
522 &prstat
, sizeof (prstat
));
527 # if GCC_VERSION >= 8000
528 # pragma GCC diagnostic pop
532 /* Functions for the x86-64 ELF linker. */
534 /* The size in bytes of an entry in the global offset table. */
536 #define GOT_ENTRY_SIZE 8
538 /* The size in bytes of an entry in the lazy procedure linkage table. */
540 #define LAZY_PLT_ENTRY_SIZE 16
542 /* The size in bytes of an entry in the non-lazy procedure linkage
545 #define NON_LAZY_PLT_ENTRY_SIZE 8
547 /* The first entry in a lazy procedure linkage table looks like this.
548 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
551 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
553 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
554 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
555 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
558 /* Subsequent entries in a lazy procedure linkage table look like this. */
560 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
562 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
563 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
564 0x68, /* pushq immediate */
565 0, 0, 0, 0, /* replaced with index into relocation table. */
566 0xe9, /* jmp relative */
567 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
570 /* The first entry in a lazy procedure linkage table with BND prefix
573 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
575 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
576 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
577 0x0f, 0x1f, 0 /* nopl (%rax) */
580 /* Subsequent entries for branches with BND prefx in a lazy procedure
581 linkage table look like this. */
583 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
585 0x68, 0, 0, 0, 0, /* pushq immediate */
586 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
587 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
590 /* The first entry in the IBT-enabled lazy procedure linkage table is the
591 the same as the lazy PLT with BND prefix so that bound registers are
592 preserved when control is passed to dynamic linker. Subsequent
593 entries for a IBT-enabled lazy procedure linkage table look like
596 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
598 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
599 0x68, 0, 0, 0, 0, /* pushq immediate */
600 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
604 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
605 is the same as the normal lazy PLT. Subsequent entries for an
606 x32 IBT-enabled lazy procedure linkage table look like this. */
608 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
610 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
611 0x68, 0, 0, 0, 0, /* pushq immediate */
612 0xe9, 0, 0, 0, 0, /* jmpq relative */
613 0x66, 0x90 /* xchg %ax,%ax */
616 /* Entries in the non-lazey procedure linkage table look like this. */
618 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
620 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
621 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
622 0x66, 0x90 /* xchg %ax,%ax */
625 /* Entries for branches with BND prefix in the non-lazey procedure
626 linkage table look like this. */
628 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
630 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
631 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
635 /* Entries for branches with IBT-enabled in the non-lazey procedure
636 linkage table look like this. They have the same size as the lazy
639 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
641 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
642 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
643 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
644 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
647 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
648 linkage table look like this. They have the same size as the lazy
651 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
653 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
654 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
655 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
656 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
659 /* The TLSDESC entry in a lazy procedure linkage table. */
660 static const bfd_byte elf_x86_64_tlsdesc_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
662 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
663 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
664 0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */
667 /* .eh_frame covering the lazy .plt section. */
669 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
671 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
672 0, 0, 0, 0, /* CIE ID */
674 'z', 'R', 0, /* Augmentation string */
675 1, /* Code alignment factor */
676 0x78, /* Data alignment factor */
677 16, /* Return address column */
678 1, /* Augmentation size */
679 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
680 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
681 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
682 DW_CFA_nop
, DW_CFA_nop
,
684 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
685 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
686 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
687 0, 0, 0, 0, /* .plt size goes here */
688 0, /* Augmentation size */
689 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
690 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
691 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
692 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
693 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
694 11, /* Block length */
695 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
696 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
697 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
698 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
699 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
702 /* .eh_frame covering the lazy BND .plt section. */
704 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
706 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
707 0, 0, 0, 0, /* CIE ID */
709 'z', 'R', 0, /* Augmentation string */
710 1, /* Code alignment factor */
711 0x78, /* Data alignment factor */
712 16, /* Return address column */
713 1, /* Augmentation size */
714 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
715 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
716 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
717 DW_CFA_nop
, DW_CFA_nop
,
719 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
720 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
721 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
722 0, 0, 0, 0, /* .plt size goes here */
723 0, /* Augmentation size */
724 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
725 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
726 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
727 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
728 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
729 11, /* Block length */
730 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
731 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
732 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
733 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
734 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
737 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
739 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
741 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
742 0, 0, 0, 0, /* CIE ID */
744 'z', 'R', 0, /* Augmentation string */
745 1, /* Code alignment factor */
746 0x78, /* Data alignment factor */
747 16, /* Return address column */
748 1, /* Augmentation size */
749 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
750 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
751 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
752 DW_CFA_nop
, DW_CFA_nop
,
754 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
755 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
756 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
757 0, 0, 0, 0, /* .plt size goes here */
758 0, /* Augmentation size */
759 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
760 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
761 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
762 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
763 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
764 11, /* Block length */
765 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
766 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
767 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
768 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
769 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
772 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
774 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
776 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
777 0, 0, 0, 0, /* CIE ID */
779 'z', 'R', 0, /* Augmentation string */
780 1, /* Code alignment factor */
781 0x78, /* Data alignment factor */
782 16, /* Return address column */
783 1, /* Augmentation size */
784 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
785 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
786 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
787 DW_CFA_nop
, DW_CFA_nop
,
789 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
790 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
791 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
792 0, 0, 0, 0, /* .plt size goes here */
793 0, /* Augmentation size */
794 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
795 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
796 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
797 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
798 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
799 11, /* Block length */
800 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
801 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
802 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
803 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
804 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
807 /* .eh_frame covering the non-lazy .plt section. */
809 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
811 #define PLT_GOT_FDE_LENGTH 20
812 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
813 0, 0, 0, 0, /* CIE ID */
815 'z', 'R', 0, /* Augmentation string */
816 1, /* Code alignment factor */
817 0x78, /* Data alignment factor */
818 16, /* Return address column */
819 1, /* Augmentation size */
820 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
821 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
822 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
823 DW_CFA_nop
, DW_CFA_nop
,
825 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
826 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
827 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
828 0, 0, 0, 0, /* non-lazy .plt size goes here */
829 0, /* Augmentation size */
830 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
831 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
834 static const sframe_frame_row_entry elf_x86_64_sframe_null_fre
=
837 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
838 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
841 /* .sframe FRE covering the .plt section entry. */
842 static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre1
=
844 0, /* SFrame FRE start address. */
845 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
846 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
849 /* .sframe FRE covering the .plt section entry. */
850 static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre2
=
852 6, /* SFrame FRE start address. */
853 {24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
854 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
857 /* .sframe FRE covering the .plt section entry. */
858 static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre1
=
860 0, /* SFrame FRE start address. */
861 {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
862 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
865 /* .sframe FRE covering the .plt section entry. */
866 static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre2
=
868 11, /* SFrame FRE start address. */
869 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
870 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
873 /* .sframe FRE covering the second .plt section entry. */
874 static const sframe_frame_row_entry elf_x86_64_sframe_sec_pltn_fre1
=
876 0, /* SFrame FRE start address. */
877 {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */
878 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
) /* FRE info. */
881 /* SFrame helper object for non-lazy PLT. Also used for IBT enabled PLT. */
882 static const struct elf_x86_sframe_plt elf_x86_64_sframe_non_lazy_plt
=
885 2, /* Number of FREs for PLT0. */
886 /* Array of SFrame FREs for plt0. */
887 { &elf_x86_64_sframe_plt0_fre1
, &elf_x86_64_sframe_plt0_fre2
},
889 1, /* Number of FREs for PLTn. */
890 /* Array of SFrame FREs for plt. */
891 { &elf_x86_64_sframe_sec_pltn_fre1
, &elf_x86_64_sframe_null_fre
},
893 0, /* There is no second PLT necessary. */
894 { &elf_x86_64_sframe_null_fre
}
897 /* SFrame helper object for lazy PLT. Also used for IBT enabled PLT. */
898 static const struct elf_x86_sframe_plt elf_x86_64_sframe_plt
=
901 2, /* Number of FREs for PLT0. */
902 /* Array of SFrame FREs for plt0. */
903 { &elf_x86_64_sframe_plt0_fre1
, &elf_x86_64_sframe_plt0_fre2
},
905 2, /* Number of FREs for PLTn. */
906 /* Array of SFrame FREs for plt. */
907 { &elf_x86_64_sframe_pltn_fre1
, &elf_x86_64_sframe_pltn_fre2
},
908 NON_LAZY_PLT_ENTRY_SIZE
,
909 1, /* Number of FREs for PLTn for second PLT. */
910 /* FREs for second plt (stack trace info for .plt.got is
911 identical). Used when IBT or non-lazy PLT is in effect. */
912 { &elf_x86_64_sframe_sec_pltn_fre1
}
915 /* These are the standard parameters. */
916 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
918 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
919 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
920 elf_x86_64_lazy_plt_entry
, /* plt_entry */
921 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
922 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
923 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
924 6, /* plt_tlsdesc_got1_offset */
925 12, /* plt_tlsdesc_got2_offset */
926 10, /* plt_tlsdesc_got1_insn_end */
927 16, /* plt_tlsdesc_got2_insn_end */
928 2, /* plt0_got1_offset */
929 8, /* plt0_got2_offset */
930 12, /* plt0_got2_insn_end */
931 2, /* plt_got_offset */
932 7, /* plt_reloc_offset */
933 12, /* plt_plt_offset */
934 6, /* plt_got_insn_size */
935 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
936 6, /* plt_lazy_offset */
937 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
938 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
939 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
940 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
943 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
945 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
946 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
947 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
948 2, /* plt_got_offset */
949 6, /* plt_got_insn_size */
950 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
951 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
954 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
956 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
957 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
958 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
959 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
960 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
961 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
962 6, /* plt_tlsdesc_got1_offset */
963 12, /* plt_tlsdesc_got2_offset */
964 10, /* plt_tlsdesc_got1_insn_end */
965 16, /* plt_tlsdesc_got2_insn_end */
966 2, /* plt0_got1_offset */
967 1+8, /* plt0_got2_offset */
968 1+12, /* plt0_got2_insn_end */
969 1+2, /* plt_got_offset */
970 1, /* plt_reloc_offset */
971 7, /* plt_plt_offset */
972 1+6, /* plt_got_insn_size */
973 11, /* plt_plt_insn_end */
974 0, /* plt_lazy_offset */
975 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
976 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
977 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
978 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
981 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
983 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
984 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
985 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
986 1+2, /* plt_got_offset */
987 1+6, /* plt_got_insn_size */
988 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
989 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
992 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
994 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
995 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
996 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
997 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
998 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
999 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
1000 6, /* plt_tlsdesc_got1_offset */
1001 12, /* plt_tlsdesc_got2_offset */
1002 10, /* plt_tlsdesc_got1_insn_end */
1003 16, /* plt_tlsdesc_got2_insn_end */
1004 2, /* plt0_got1_offset */
1005 1+8, /* plt0_got2_offset */
1006 1+12, /* plt0_got2_insn_end */
1007 4+1+2, /* plt_got_offset */
1008 4+1, /* plt_reloc_offset */
1009 4+1+6, /* plt_plt_offset */
1010 4+1+6, /* plt_got_insn_size */
1011 4+1+5+5, /* plt_plt_insn_end */
1012 0, /* plt_lazy_offset */
1013 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
1014 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
1015 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1016 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1019 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
1021 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
1022 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
1023 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
1024 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1025 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
1026 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
1027 6, /* plt_tlsdesc_got1_offset */
1028 12, /* plt_tlsdesc_got2_offset */
1029 10, /* plt_tlsdesc_got1_insn_end */
1030 16, /* plt_tlsdesc_got2_insn_end */
1031 2, /* plt0_got1_offset */
1032 8, /* plt0_got2_offset */
1033 12, /* plt0_got2_insn_end */
1034 4+2, /* plt_got_offset */
1035 4+1, /* plt_reloc_offset */
1036 4+6, /* plt_plt_offset */
1037 4+6, /* plt_got_insn_size */
1038 4+5+5, /* plt_plt_insn_end */
1039 0, /* plt_lazy_offset */
1040 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
1041 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
1042 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1043 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1046 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
1048 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
1049 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
1050 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1051 4+1+2, /* plt_got_offset */
1052 4+1+6, /* plt_got_insn_size */
1053 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1054 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1057 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
1059 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
1060 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
1061 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1062 4+2, /* plt_got_offset */
1063 4+6, /* plt_got_insn_size */
1064 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1065 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1069 elf64_x86_64_elf_object_p (bfd
*abfd
)
1071 /* Set the right machine number for an x86-64 elf64 file. */
1072 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1077 elf32_x86_64_elf_object_p (bfd
*abfd
)
1079 /* Set the right machine number for an x86-64 elf32 file. */
1080 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1084 /* Return TRUE if the TLS access code sequence support transition
1088 elf_x86_64_check_tls_transition (bfd
*abfd
,
1089 struct bfd_link_info
*info
,
1092 Elf_Internal_Shdr
*symtab_hdr
,
1093 struct elf_link_hash_entry
**sym_hashes
,
1094 unsigned int r_type
,
1095 const Elf_Internal_Rela
*rel
,
1096 const Elf_Internal_Rela
*relend
)
1099 unsigned long r_symndx
;
1100 bool largepic
= false;
1101 struct elf_link_hash_entry
*h
;
1103 struct elf_x86_link_hash_table
*htab
;
1107 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1108 offset
= rel
->r_offset
;
1111 case R_X86_64_TLSGD
:
1112 case R_X86_64_TLSLD
:
1113 if ((rel
+ 1) >= relend
)
1116 if (r_type
== R_X86_64_TLSGD
)
1118 /* Check transition from GD access model. For 64bit, only
1119 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1120 .word 0x6666; rex64; call __tls_get_addr@PLT
1122 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1124 call *__tls_get_addr@GOTPCREL(%rip)
1125 which may be converted to
1126 addr32 call __tls_get_addr
1127 can transit to different access model. For 32bit, only
1128 leaq foo@tlsgd(%rip), %rdi
1129 .word 0x6666; rex64; call __tls_get_addr@PLT
1131 leaq foo@tlsgd(%rip), %rdi
1133 call *__tls_get_addr@GOTPCREL(%rip)
1134 which may be converted to
1135 addr32 call __tls_get_addr
1136 can transit to different access model. For largepic,
1138 leaq foo@tlsgd(%rip), %rdi
1139 movabsq $__tls_get_addr@pltoff, %rax
1143 leaq foo@tlsgd(%rip), %rdi
1144 movabsq $__tls_get_addr@pltoff, %rax
1148 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1150 if ((offset
+ 12) > sec
->size
)
1153 call
= contents
+ offset
+ 4;
1155 || !((call
[1] == 0x48
1163 && call
[3] == 0xe8)))
1165 if (!ABI_64_P (abfd
)
1166 || (offset
+ 19) > sec
->size
1168 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1169 || memcmp (call
, "\x48\xb8", 2) != 0
1173 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1174 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1178 else if (ABI_64_P (abfd
))
1181 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1187 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1190 indirect_call
= call
[2] == 0xff;
1194 /* Check transition from LD access model. Only
1195 leaq foo@tlsld(%rip), %rdi;
1196 call __tls_get_addr@PLT
1198 leaq foo@tlsld(%rip), %rdi;
1199 call *__tls_get_addr@GOTPCREL(%rip)
1200 which may be converted to
1201 addr32 call __tls_get_addr
1202 can transit to different access model. For largepic
1204 leaq foo@tlsld(%rip), %rdi
1205 movabsq $__tls_get_addr@pltoff, %rax
1209 leaq foo@tlsld(%rip), %rdi
1210 movabsq $__tls_get_addr@pltoff, %rax
1214 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1216 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1219 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1222 call
= contents
+ offset
+ 4;
1223 if (!(call
[0] == 0xe8
1224 || (call
[0] == 0xff && call
[1] == 0x15)
1225 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1227 if (!ABI_64_P (abfd
)
1228 || (offset
+ 19) > sec
->size
1229 || memcmp (call
, "\x48\xb8", 2) != 0
1233 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1234 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1238 indirect_call
= call
[0] == 0xff;
1241 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1242 if (r_symndx
< symtab_hdr
->sh_info
)
1245 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1247 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1251 r_type
= (ELF32_R_TYPE (rel
[1].r_info
)
1252 & ~R_X86_64_converted_reloc_bit
);
1254 return r_type
== R_X86_64_PLTOFF64
;
1255 else if (indirect_call
)
1256 return r_type
== R_X86_64_GOTPCRELX
;
1258 return (r_type
== R_X86_64_PC32
|| r_type
== R_X86_64_PLT32
);
1261 case R_X86_64_GOTTPOFF
:
1262 /* Check transition from IE access model:
1263 mov foo@gottpoff(%rip), %reg
1264 add foo@gottpoff(%rip), %reg
1267 /* Check REX prefix first. */
1268 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1270 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1271 if (val
!= 0x48 && val
!= 0x4c)
1273 /* X32 may have 0x44 REX prefix or no REX prefix. */
1274 if (ABI_64_P (abfd
))
1280 /* X32 may not have any REX prefix. */
1281 if (ABI_64_P (abfd
))
1283 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1287 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1288 if (val
!= 0x8b && val
!= 0x03)
1291 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1292 return (val
& 0xc7) == 5;
1294 case R_X86_64_GOTPC32_TLSDESC
:
1295 /* Check transition from GDesc access model:
1296 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
1297 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
1299 Make sure it's a leaq adding rip to a 32-bit offset
1300 into any register, although it's probably almost always
1303 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1306 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1308 if (val
!= 0x48 && (ABI_64_P (abfd
) || val
!= 0x40))
1311 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1314 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1315 return (val
& 0xc7) == 0x05;
1317 case R_X86_64_TLSDESC_CALL
:
1318 /* Check transition from GDesc access model:
1319 call *x@tlsdesc(%rax) <--- LP64 mode.
1320 call *x@tlsdesc(%eax) <--- X32 mode.
1322 if (offset
+ 2 <= sec
->size
)
1324 unsigned int prefix
;
1325 call
= contents
+ offset
;
1327 if (!ABI_64_P (abfd
))
1329 /* Check for call *x@tlsdesc(%eax). */
1330 if (call
[0] == 0x67)
1333 if (offset
+ 3 > sec
->size
)
1337 /* Make sure that it's a call *x@tlsdesc(%rax). */
1338 return call
[prefix
] == 0xff && call
[1 + prefix
] == 0x10;
1348 /* Return TRUE if the TLS access transition is OK or no transition
1349 will be performed. Update R_TYPE if there is a transition. */
1352 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1353 asection
*sec
, bfd_byte
*contents
,
1354 Elf_Internal_Shdr
*symtab_hdr
,
1355 struct elf_link_hash_entry
**sym_hashes
,
1356 unsigned int *r_type
, int tls_type
,
1357 const Elf_Internal_Rela
*rel
,
1358 const Elf_Internal_Rela
*relend
,
1359 struct elf_link_hash_entry
*h
,
1360 unsigned long r_symndx
,
1361 bool from_relocate_section
)
1363 unsigned int from_type
= *r_type
;
1364 unsigned int to_type
= from_type
;
1367 /* Skip TLS transition for functions. */
1369 && (h
->type
== STT_FUNC
1370 || h
->type
== STT_GNU_IFUNC
))
1375 case R_X86_64_TLSGD
:
1376 case R_X86_64_GOTPC32_TLSDESC
:
1377 case R_X86_64_TLSDESC_CALL
:
1378 case R_X86_64_GOTTPOFF
:
1379 if (bfd_link_executable (info
))
1382 to_type
= R_X86_64_TPOFF32
;
1384 to_type
= R_X86_64_GOTTPOFF
;
1387 /* When we are called from elf_x86_64_relocate_section, there may
1388 be additional transitions based on TLS_TYPE. */
1389 if (from_relocate_section
)
1391 unsigned int new_to_type
= to_type
;
1393 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1394 new_to_type
= R_X86_64_TPOFF32
;
1396 if (to_type
== R_X86_64_TLSGD
1397 || to_type
== R_X86_64_GOTPC32_TLSDESC
1398 || to_type
== R_X86_64_TLSDESC_CALL
)
1400 if (tls_type
== GOT_TLS_IE
)
1401 new_to_type
= R_X86_64_GOTTPOFF
;
1404 /* We checked the transition before when we were called from
1405 elf_x86_64_scan_relocs. We only want to check the new
1406 transition which hasn't been checked before. */
1407 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1408 to_type
= new_to_type
;
1413 case R_X86_64_TLSLD
:
1414 if (bfd_link_executable (info
))
1415 to_type
= R_X86_64_TPOFF32
;
1422 /* Return TRUE if there is no transition. */
1423 if (from_type
== to_type
)
1426 /* Check if the transition can be performed. */
1428 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1429 symtab_hdr
, sym_hashes
,
1430 from_type
, rel
, relend
))
1432 reloc_howto_type
*from
, *to
;
1435 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1436 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1438 if (from
== NULL
|| to
== NULL
)
1442 name
= h
->root
.root
.string
;
1445 struct elf_x86_link_hash_table
*htab
;
1447 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1452 Elf_Internal_Sym
*isym
;
1454 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1456 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1461 /* xgettext:c-format */
1462 (_("%pB: TLS transition from %s to %s against `%s' at %#" PRIx64
1463 " in section `%pA' failed"),
1464 abfd
, from
->name
, to
->name
, name
, (uint64_t) rel
->r_offset
, sec
);
1465 bfd_set_error (bfd_error_bad_value
);
1474 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1475 bfd
*input_bfd
, asection
*sec
,
1476 struct elf_link_hash_entry
*h
,
1477 Elf_Internal_Shdr
*symtab_hdr
,
1478 Elf_Internal_Sym
*isym
,
1479 reloc_howto_type
*howto
)
1482 const char *und
= "";
1483 const char *pic
= "";
1489 name
= h
->root
.root
.string
;
1490 switch (ELF_ST_VISIBILITY (h
->other
))
1493 v
= _("hidden symbol ");
1496 v
= _("internal symbol ");
1499 v
= _("protected symbol ");
1502 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1503 v
= _("protected symbol ");
1510 if (!SYMBOL_DEFINED_NON_SHARED_P (h
) && !h
->def_dynamic
)
1511 und
= _("undefined ");
1515 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1519 if (bfd_link_dll (info
))
1521 object
= _("a shared object");
1523 pic
= _("; recompile with -fPIC");
1527 if (bfd_link_pie (info
))
1528 object
= _("a PIE object");
1530 object
= _("a PDE object");
1532 pic
= _("; recompile with -fPIE");
1535 /* xgettext:c-format */
1536 _bfd_error_handler (_("%pB: relocation %s against %s%s`%s' can "
1537 "not be used when making %s%s"),
1538 input_bfd
, howto
->name
, und
, v
, name
,
1540 bfd_set_error (bfd_error_bad_value
);
1541 sec
->check_relocs_failed
= 1;
1545 /* With the local symbol, foo, we convert
1546 mov foo@GOTPCREL(%rip), %reg
1550 call/jmp *foo@GOTPCREL(%rip)
1552 nop call foo/jmp foo nop
1553 When PIC is false, convert
1554 test %reg, foo@GOTPCREL(%rip)
1558 binop foo@GOTPCREL(%rip), %reg
1561 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1565 elf_x86_64_convert_load_reloc (bfd
*abfd
,
1567 unsigned int *r_type_p
,
1568 Elf_Internal_Rela
*irel
,
1569 struct elf_link_hash_entry
*h
,
1571 struct bfd_link_info
*link_info
)
1573 struct elf_x86_link_hash_table
*htab
;
1581 bfd_signed_vma raddend
;
1582 unsigned int opcode
;
1584 unsigned int r_type
= *r_type_p
;
1585 unsigned int r_symndx
;
1586 bfd_vma roff
= irel
->r_offset
;
1587 bfd_vma abs_relocation
;
1589 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1592 raddend
= irel
->r_addend
;
1593 /* Addend for 32-bit PC-relative relocation must be -4. */
1597 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1598 is_pic
= bfd_link_pic (link_info
);
1600 relocx
= (r_type
== R_X86_64_GOTPCRELX
1601 || r_type
== R_X86_64_REX_GOTPCRELX
);
1603 /* TRUE if --no-relax is used. */
1604 no_overflow
= link_info
->disable_target_specific_optimizations
> 1;
1606 r_symndx
= htab
->r_sym (irel
->r_info
);
1608 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1610 /* Convert mov to lea since it has been done for a while. */
1613 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1614 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1615 test, xor instructions. */
1620 /* We convert only to R_X86_64_PC32:
1622 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1623 3. no_overflow is true.
1626 to_reloc_pc32
= (opcode
== 0xff
1634 /* Get the symbol referred to by the reloc. */
1637 Elf_Internal_Sym
*isym
1638 = bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, abfd
, r_symndx
);
1640 /* Skip relocation against undefined symbols. */
1641 if (isym
->st_shndx
== SHN_UNDEF
)
1645 if (isym
->st_shndx
== SHN_ABS
)
1647 tsec
= bfd_abs_section_ptr
;
1649 abs_relocation
= isym
->st_value
;
1651 else if (isym
->st_shndx
== SHN_COMMON
)
1652 tsec
= bfd_com_section_ptr
;
1653 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1654 tsec
= &_bfd_elf_large_com_section
;
1656 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1660 /* Undefined weak symbol is only bound locally in executable
1661 and its reference is resolved as 0 without relocation
1662 overflow. We can only perform this optimization for
1663 GOTPCRELX relocations since we need to modify REX byte.
1664 It is OK convert mov with R_X86_64_GOTPCREL to
1666 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
1668 abs_symbol
= ABS_SYMBOL_P (h
);
1669 abs_relocation
= h
->root
.u
.def
.value
;
1671 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1672 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1673 if ((relocx
|| opcode
== 0x8b)
1674 && (h
->root
.type
== bfd_link_hash_undefweak
1680 /* Skip for branch instructions since R_X86_64_PC32
1687 /* For non-branch instructions, we can convert to
1688 R_X86_64_32/R_X86_64_32S since we know if there
1690 to_reloc_pc32
= false;
1693 /* Since we don't know the current PC when PIC is true,
1694 we can't convert to R_X86_64_PC32. */
1695 if (to_reloc_pc32
&& is_pic
)
1700 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1701 ld.so may use its link-time address. */
1702 else if (h
->start_stop
1705 || h
->root
.type
== bfd_link_hash_defined
1706 || h
->root
.type
== bfd_link_hash_defweak
)
1707 && h
!= htab
->elf
.hdynamic
1710 /* bfd_link_hash_new or bfd_link_hash_undefined is
1711 set by an assignment in a linker script in
1712 bfd_elf_record_link_assignment. start_stop is set
1713 on __start_SECNAME/__stop_SECNAME which mark section
1718 && (h
->root
.type
== bfd_link_hash_new
1719 || h
->root
.type
== bfd_link_hash_undefined
1720 || ((h
->root
.type
== bfd_link_hash_defined
1721 || h
->root
.type
== bfd_link_hash_defweak
)
1722 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1724 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1729 tsec
= h
->root
.u
.def
.section
;
1735 /* Don't convert GOTPCREL relocation against large section. */
1736 if (elf_section_data (tsec
) != NULL
1737 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1740 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1747 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1752 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1754 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1757 /* Convert to "jmp foo nop". */
1760 nop_offset
= irel
->r_offset
+ 3;
1761 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1762 irel
->r_offset
-= 1;
1763 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1767 struct elf_x86_link_hash_entry
*eh
1768 = (struct elf_x86_link_hash_entry
*) h
;
1770 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1773 /* To support TLS optimization, always use addr32 prefix for
1774 "call *__tls_get_addr@GOTPCREL(%rip)". */
1775 if (eh
&& eh
->tls_get_addr
)
1778 nop_offset
= irel
->r_offset
- 2;
1782 nop
= htab
->params
->call_nop_byte
;
1783 if (htab
->params
->call_nop_as_suffix
)
1785 nop_offset
= irel
->r_offset
+ 3;
1786 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1787 irel
->r_offset
-= 1;
1788 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1791 nop_offset
= irel
->r_offset
- 2;
1794 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1795 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1796 r_type
= R_X86_64_PC32
;
1801 unsigned int rex_mask
= REX_R
;
1803 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1804 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1810 if (abs_symbol
&& local_ref
&& relocx
)
1811 to_reloc_pc32
= false;
1815 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1816 "lea foo(%rip), %reg". */
1818 r_type
= R_X86_64_PC32
;
1822 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1823 "mov $foo, %reg". */
1825 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1826 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1827 if ((rex
& REX_W
) != 0
1828 && ABI_64_P (link_info
->output_bfd
))
1830 /* Keep the REX_W bit in REX byte for LP64. */
1831 r_type
= R_X86_64_32S
;
1832 goto rewrite_modrm_rex
;
1836 /* If the REX_W bit in REX byte isn't needed,
1837 use R_X86_64_32 and clear the W bit to avoid
1838 sign-extend imm32 to imm64. */
1839 r_type
= R_X86_64_32
;
1840 /* Clear the W bit in REX byte. */
1842 goto rewrite_modrm_rex
;
1848 /* R_X86_64_PC32 isn't supported. */
1852 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1855 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1856 "test $foo, %reg". */
1857 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1862 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1863 "binop $foo, %reg". */
1864 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1868 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1869 overflow when sign-extending imm32 to imm64. */
1870 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1875 /* Check if R_X86_64_32S/R_X86_64_32 fits. */
1876 if (r_type
== R_X86_64_32S
)
1878 if ((abs_relocation
+ 0x80000000) > 0xffffffff)
1883 if (abs_relocation
> 0xffffffff)
1888 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1892 /* Move the R bit to the B bit in REX byte. */
1893 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1894 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1897 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1901 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1905 irel
->r_info
= htab
->r_info (r_symndx
,
1906 r_type
| R_X86_64_converted_reloc_bit
);
1913 /* Look through the relocs for a section during the first phase, and
1914 calculate needed space in the global offset table, and procedure
1918 elf_x86_64_scan_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1920 const Elf_Internal_Rela
*relocs
)
1922 struct elf_x86_link_hash_table
*htab
;
1923 Elf_Internal_Shdr
*symtab_hdr
;
1924 struct elf_link_hash_entry
**sym_hashes
;
1925 const Elf_Internal_Rela
*rel
;
1926 const Elf_Internal_Rela
*rel_end
;
1930 if (bfd_link_relocatable (info
))
1933 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1936 sec
->check_relocs_failed
= 1;
1940 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1942 /* Get the section contents. */
1943 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1944 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1945 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1947 sec
->check_relocs_failed
= 1;
1951 symtab_hdr
= &elf_symtab_hdr (abfd
);
1952 sym_hashes
= elf_sym_hashes (abfd
);
1956 rel_end
= relocs
+ sec
->reloc_count
;
1957 for (rel
= relocs
; rel
< rel_end
; rel
++)
1959 unsigned int r_type
;
1960 unsigned int r_symndx
;
1961 struct elf_link_hash_entry
*h
;
1962 struct elf_x86_link_hash_entry
*eh
;
1963 Elf_Internal_Sym
*isym
;
1966 bool converted_reloc
;
1969 r_symndx
= htab
->r_sym (rel
->r_info
);
1970 r_type
= ELF32_R_TYPE (rel
->r_info
);
1972 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1974 /* xgettext:c-format */
1975 _bfd_error_handler (_("%pB: bad symbol index: %d"),
1980 if (r_symndx
< symtab_hdr
->sh_info
)
1982 /* A local symbol. */
1983 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1988 /* Check relocation against local STT_GNU_IFUNC symbol. */
1989 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1991 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1996 /* Fake a STT_GNU_IFUNC symbol. */
1997 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1999 h
->type
= STT_GNU_IFUNC
;
2002 h
->forced_local
= 1;
2003 h
->root
.type
= bfd_link_hash_defined
;
2011 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2012 while (h
->root
.type
== bfd_link_hash_indirect
2013 || h
->root
.type
== bfd_link_hash_warning
)
2014 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2017 /* Check invalid x32 relocations. */
2018 if (!ABI_64_P (abfd
))
2024 case R_X86_64_DTPOFF64
:
2025 case R_X86_64_TPOFF64
:
2027 case R_X86_64_GOTOFF64
:
2028 case R_X86_64_GOT64
:
2029 case R_X86_64_GOTPCREL64
:
2030 case R_X86_64_GOTPC64
:
2031 case R_X86_64_GOTPLT64
:
2032 case R_X86_64_PLTOFF64
:
2035 name
= h
->root
.root
.string
;
2037 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2040 /* xgettext:c-format */
2041 (_("%pB: relocation %s against symbol `%s' isn't "
2042 "supported in x32 mode"), abfd
,
2043 x86_64_elf_howto_table
[r_type
].name
, name
);
2044 bfd_set_error (bfd_error_bad_value
);
2050 eh
= (struct elf_x86_link_hash_entry
*) h
;
2054 /* It is referenced by a non-shared object. */
2058 converted_reloc
= false;
2059 if ((r_type
== R_X86_64_GOTPCREL
2060 || r_type
== R_X86_64_GOTPCRELX
2061 || r_type
== R_X86_64_REX_GOTPCRELX
)
2062 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2064 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
2065 if (!elf_x86_64_convert_load_reloc (abfd
, contents
, &r_type
,
2066 irel
, h
, &converted_reloc
,
2070 if (converted_reloc
)
2074 if (!_bfd_elf_x86_valid_reloc_p (sec
, info
, htab
, rel
, h
, isym
,
2075 symtab_hdr
, &no_dynreloc
))
2078 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2079 symtab_hdr
, sym_hashes
,
2080 &r_type
, GOT_UNKNOWN
,
2081 rel
, rel_end
, h
, r_symndx
, false))
2084 /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
2085 if (h
== htab
->elf
.hgot
)
2086 htab
->got_referenced
= true;
2090 case R_X86_64_TLSLD
:
2091 htab
->tls_ld_or_ldm_got
.refcount
= 1;
2094 case R_X86_64_TPOFF32
:
2095 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2096 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2097 &x86_64_elf_howto_table
[r_type
]);
2099 eh
->zero_undefweak
&= 0x2;
2102 case R_X86_64_GOTTPOFF
:
2103 if (!bfd_link_executable (info
))
2104 info
->flags
|= DF_STATIC_TLS
;
2107 case R_X86_64_GOT32
:
2108 case R_X86_64_GOTPCREL
:
2109 case R_X86_64_GOTPCRELX
:
2110 case R_X86_64_REX_GOTPCRELX
:
2111 case R_X86_64_TLSGD
:
2112 case R_X86_64_GOT64
:
2113 case R_X86_64_GOTPCREL64
:
2114 case R_X86_64_GOTPLT64
:
2115 case R_X86_64_GOTPC32_TLSDESC
:
2116 case R_X86_64_TLSDESC_CALL
:
2117 /* This symbol requires a global offset table entry. */
2119 int tls_type
, old_tls_type
;
2124 tls_type
= GOT_NORMAL
;
2127 if (ABS_SYMBOL_P (h
))
2130 else if (isym
->st_shndx
== SHN_ABS
)
2133 case R_X86_64_TLSGD
:
2134 tls_type
= GOT_TLS_GD
;
2136 case R_X86_64_GOTTPOFF
:
2137 tls_type
= GOT_TLS_IE
;
2139 case R_X86_64_GOTPC32_TLSDESC
:
2140 case R_X86_64_TLSDESC_CALL
:
2141 tls_type
= GOT_TLS_GDESC
;
2147 h
->got
.refcount
= 1;
2148 old_tls_type
= eh
->tls_type
;
2152 bfd_signed_vma
*local_got_refcounts
;
2154 if (!elf_x86_allocate_local_got_info (abfd
,
2155 symtab_hdr
->sh_info
))
2158 /* This is a global offset table entry for a local symbol. */
2159 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2160 local_got_refcounts
[r_symndx
] = 1;
2162 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2165 /* If a TLS symbol is accessed using IE at least once,
2166 there is no point to use dynamic model for it. */
2167 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2168 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2169 || tls_type
!= GOT_TLS_IE
))
2171 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2172 tls_type
= old_tls_type
;
2173 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2174 && GOT_TLS_GD_ANY_P (tls_type
))
2175 tls_type
|= old_tls_type
;
2179 name
= h
->root
.root
.string
;
2181 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2184 /* xgettext:c-format */
2185 (_("%pB: '%s' accessed both as normal and"
2186 " thread local symbol"),
2188 bfd_set_error (bfd_error_bad_value
);
2193 if (old_tls_type
!= tls_type
)
2196 eh
->tls_type
= tls_type
;
2198 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2203 case R_X86_64_GOTOFF64
:
2204 case R_X86_64_GOTPC32
:
2205 case R_X86_64_GOTPC64
:
2208 eh
->zero_undefweak
&= 0x2;
2211 case R_X86_64_PLT32
:
2212 /* This symbol requires a procedure linkage table entry. We
2213 actually build the entry in adjust_dynamic_symbol,
2214 because this might be a case of linking PIC code which is
2215 never referenced by a dynamic object, in which case we
2216 don't need to generate a procedure linkage table entry
2219 /* If this is a local symbol, we resolve it directly without
2220 creating a procedure linkage table entry. */
2224 eh
->zero_undefweak
&= 0x2;
2226 h
->plt
.refcount
= 1;
2229 case R_X86_64_PLTOFF64
:
2230 /* This tries to form the 'address' of a function relative
2231 to GOT. For global symbols we need a PLT entry. */
2235 h
->plt
.refcount
= 1;
2239 case R_X86_64_SIZE32
:
2240 case R_X86_64_SIZE64
:
2245 if (!ABI_64_P (abfd
))
2251 /* Check relocation overflow as these relocs may lead to
2252 run-time relocation overflow. Don't error out for
2253 sections we don't care about, such as debug sections or
2254 when relocation overflow check is disabled. */
2255 if (!htab
->params
->no_reloc_overflow_check
2257 && (bfd_link_pic (info
)
2258 || (bfd_link_executable (info
)
2262 && (sec
->flags
& SEC_READONLY
) == 0)))
2263 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2264 &x86_64_elf_howto_table
[r_type
]);
2273 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2274 eh
->zero_undefweak
|= 0x2;
2275 /* We are called after all symbols have been resolved. Only
2276 relocation against STT_GNU_IFUNC symbol must go through
2279 && (bfd_link_executable (info
)
2280 || h
->type
== STT_GNU_IFUNC
))
2282 bool func_pointer_ref
= false;
2284 if (r_type
== R_X86_64_PC32
)
2286 /* Since something like ".long foo - ." may be used
2287 as pointer, make sure that PLT is used if foo is
2288 a function defined in a shared library. */
2289 if ((sec
->flags
& SEC_CODE
) == 0)
2291 h
->pointer_equality_needed
= 1;
2292 if (bfd_link_pie (info
)
2293 && h
->type
== STT_FUNC
2298 h
->plt
.refcount
= 1;
2302 else if (r_type
!= R_X86_64_PC64
)
2304 /* At run-time, R_X86_64_64 can be resolved for both
2305 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2306 can only be resolved for x32. Function pointer
2307 reference doesn't need PLT for pointer equality. */
2308 if ((sec
->flags
& SEC_READONLY
) == 0
2309 && (r_type
== R_X86_64_64
2310 || (!ABI_64_P (abfd
)
2311 && (r_type
== R_X86_64_32
2312 || r_type
== R_X86_64_32S
))))
2313 func_pointer_ref
= true;
2315 /* IFUNC symbol needs pointer equality in PDE so that
2316 function pointer reference will be resolved to its
2317 PLT entry directly. */
2318 if (!func_pointer_ref
2319 || (bfd_link_pde (info
)
2320 && h
->type
== STT_GNU_IFUNC
))
2321 h
->pointer_equality_needed
= 1;
2324 if (!func_pointer_ref
)
2326 /* If this reloc is in a read-only section, we might
2327 need a copy reloc. We can't check reliably at this
2328 stage whether the section is read-only, as input
2329 sections have not yet been mapped to output sections.
2330 Tentatively set the flag for now, and correct in
2331 adjust_dynamic_symbol. */
2334 if (!elf_has_indirect_extern_access (sec
->owner
))
2335 eh
->non_got_ref_without_indirect_extern_access
= 1;
2337 /* We may need a .plt entry if the symbol is a function
2338 defined in a shared lib or is a function referenced
2339 from the code or read-only section. */
2341 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2342 h
->plt
.refcount
= 1;
2344 if (htab
->elf
.target_os
!= is_solaris
2345 && h
->pointer_equality_needed
2346 && h
->type
== STT_FUNC
2347 && eh
->def_protected
2348 && !SYMBOL_DEFINED_NON_SHARED_P (h
)
2351 /* Disallow non-canonical reference to canonical
2352 protected function. */
2354 /* xgettext:c-format */
2355 (_("%pB: non-canonical reference to canonical "
2356 "protected function `%s' in %pB"),
2357 abfd
, h
->root
.root
.string
,
2358 h
->root
.u
.def
.section
->owner
);
2359 bfd_set_error (bfd_error_bad_value
);
2368 && NEED_DYNAMIC_RELOCATION_P (true, info
, true, h
, sec
,
2370 htab
->pointer_r_type
))
2372 struct elf_dyn_relocs
*p
;
2373 struct elf_dyn_relocs
**head
;
2375 /* If this is a global symbol, we count the number of
2376 relocations we need for this symbol. */
2378 head
= &h
->dyn_relocs
;
2381 /* Track dynamic relocs needed for local syms too.
2382 We really need local syms available to do this
2387 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2392 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2396 /* Beware of type punned pointers vs strict aliasing
2398 vpp
= &(elf_section_data (s
)->local_dynrel
);
2399 head
= (struct elf_dyn_relocs
**)vpp
;
2403 if (p
== NULL
|| p
->sec
!= sec
)
2405 size_t amt
= sizeof *p
;
2407 p
= ((struct elf_dyn_relocs
*)
2408 bfd_alloc (htab
->elf
.dynobj
, amt
));
2419 /* Count size relocation as PC-relative relocation. */
2420 if (X86_PCREL_TYPE_P (true, r_type
) || size_reloc
)
2425 /* This relocation describes the C++ object vtable hierarchy.
2426 Reconstruct it for later use during GC. */
2427 case R_X86_64_GNU_VTINHERIT
:
2428 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2432 /* This relocation describes which C++ vtable entries are actually
2433 used. Record for later use during GC. */
2434 case R_X86_64_GNU_VTENTRY
:
2435 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2444 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2446 if (!converted
&& !_bfd_link_keep_memory (info
))
2450 /* Cache the section contents for elf_link_input_bfd if any
2451 load is converted or --no-keep-memory isn't used. */
2452 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2453 info
->cache_size
+= sec
->size
;
2457 /* Cache relocations if any load is converted. */
2458 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
2459 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
2464 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2466 sec
->check_relocs_failed
= 1;
2471 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2472 struct bfd_link_info
*info
)
2476 /* Scan relocations after rel_from_abs has been set on __ehdr_start. */
2477 for (abfd
= info
->input_bfds
;
2478 abfd
!= (bfd
*) NULL
;
2479 abfd
= abfd
->link
.next
)
2480 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2481 && !_bfd_elf_link_iterate_on_relocs (abfd
, info
,
2482 elf_x86_64_scan_relocs
))
2485 return _bfd_x86_elf_always_size_sections (output_bfd
, info
);
2488 /* Return the relocation value for @tpoff relocation
2489 if STT_TLS virtual address is ADDRESS. */
2492 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2494 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2495 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2496 bfd_vma static_tls_size
;
2498 /* If tls_segment is NULL, we should have signalled an error already. */
2499 if (htab
->tls_sec
== NULL
)
2502 /* Consider special static TLS alignment requirements. */
2503 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2504 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2507 /* Relocate an x86_64 ELF section. */
2510 elf_x86_64_relocate_section (bfd
*output_bfd
,
2511 struct bfd_link_info
*info
,
2513 asection
*input_section
,
2515 Elf_Internal_Rela
*relocs
,
2516 Elf_Internal_Sym
*local_syms
,
2517 asection
**local_sections
)
2519 struct elf_x86_link_hash_table
*htab
;
2520 Elf_Internal_Shdr
*symtab_hdr
;
2521 struct elf_link_hash_entry
**sym_hashes
;
2522 bfd_vma
*local_got_offsets
;
2523 bfd_vma
*local_tlsdesc_gotents
;
2524 Elf_Internal_Rela
*rel
;
2525 Elf_Internal_Rela
*wrel
;
2526 Elf_Internal_Rela
*relend
;
2527 unsigned int plt_entry_size
;
2530 /* Skip if check_relocs or scan_relocs failed. */
2531 if (input_section
->check_relocs_failed
)
2534 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2538 if (!is_x86_elf (input_bfd
, htab
))
2540 bfd_set_error (bfd_error_wrong_format
);
2544 plt_entry_size
= htab
->plt
.plt_entry_size
;
2545 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2546 sym_hashes
= elf_sym_hashes (input_bfd
);
2547 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2548 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2550 _bfd_x86_elf_set_tls_module_base (info
);
2553 rel
= wrel
= relocs
;
2554 relend
= relocs
+ input_section
->reloc_count
;
2555 for (; rel
< relend
; wrel
++, rel
++)
2557 unsigned int r_type
, r_type_tls
;
2558 reloc_howto_type
*howto
;
2559 unsigned long r_symndx
;
2560 struct elf_link_hash_entry
*h
;
2561 struct elf_x86_link_hash_entry
*eh
;
2562 Elf_Internal_Sym
*sym
;
2564 bfd_vma off
, offplt
, plt_offset
;
2566 bool unresolved_reloc
;
2567 bfd_reloc_status_type r
;
2569 asection
*base_got
, *resolved_plt
;
2571 bool resolved_to_zero
;
2572 bool relative_reloc
;
2573 bool converted_reloc
;
2574 bool need_copy_reloc_in_pie
;
2575 bool no_copyreloc_p
;
2577 r_type
= ELF32_R_TYPE (rel
->r_info
);
2578 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2579 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2586 r_symndx
= htab
->r_sym (rel
->r_info
);
2587 converted_reloc
= (r_type
& R_X86_64_converted_reloc_bit
) != 0;
2588 if (converted_reloc
)
2590 r_type
&= ~R_X86_64_converted_reloc_bit
;
2591 rel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2594 howto
= elf_x86_64_rtype_to_howto (input_bfd
, r_type
);
2596 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2601 unresolved_reloc
= false;
2602 if (r_symndx
< symtab_hdr
->sh_info
)
2604 sym
= local_syms
+ r_symndx
;
2605 sec
= local_sections
[r_symndx
];
2607 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2609 st_size
= sym
->st_size
;
2611 /* Relocate against local STT_GNU_IFUNC symbol. */
2612 if (!bfd_link_relocatable (info
)
2613 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2615 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
2620 /* Set STT_GNU_IFUNC symbol value. */
2621 h
->root
.u
.def
.value
= sym
->st_value
;
2622 h
->root
.u
.def
.section
= sec
;
2627 bool warned ATTRIBUTE_UNUSED
;
2628 bool ignored ATTRIBUTE_UNUSED
;
2630 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2631 r_symndx
, symtab_hdr
, sym_hashes
,
2633 unresolved_reloc
, warned
, ignored
);
2637 if (sec
!= NULL
&& discarded_section (sec
))
2639 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2640 contents
, rel
->r_offset
);
2641 wrel
->r_offset
= rel
->r_offset
;
2645 /* For ld -r, remove relocations in debug sections against
2646 sections defined in discarded sections. Not done for
2647 eh_frame editing code expects to be present. */
2648 if (bfd_link_relocatable (info
)
2649 && (input_section
->flags
& SEC_DEBUGGING
))
2655 if (bfd_link_relocatable (info
))
2662 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
2664 if (r_type
== R_X86_64_64
)
2666 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2667 zero-extend it to 64bit if addend is zero. */
2668 r_type
= R_X86_64_32
;
2669 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2671 else if (r_type
== R_X86_64_SIZE64
)
2673 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2674 zero-extend it to 64bit if addend is zero. */
2675 r_type
= R_X86_64_SIZE32
;
2676 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2680 eh
= (struct elf_x86_link_hash_entry
*) h
;
2682 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2683 it here if it is defined in a non-shared object. */
2685 && h
->type
== STT_GNU_IFUNC
2691 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2693 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
2694 STT_GNU_IFUNC symbol as STT_FUNC. */
2695 if (elf_section_type (input_section
) == SHT_NOTE
)
2697 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2698 sections because such sections are not SEC_ALLOC and
2699 thus ld.so will not process them. */
2700 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2710 case R_X86_64_GOTPCREL
:
2711 case R_X86_64_GOTPCRELX
:
2712 case R_X86_64_REX_GOTPCRELX
:
2713 case R_X86_64_GOTPCREL64
:
2714 base_got
= htab
->elf
.sgot
;
2715 off
= h
->got
.offset
;
2717 if (base_got
== NULL
)
2720 if (off
== (bfd_vma
) -1)
2722 /* We can't use h->got.offset here to save state, or
2723 even just remember the offset, as finish_dynamic_symbol
2724 would use that as offset into .got. */
2726 if (h
->plt
.offset
== (bfd_vma
) -1)
2729 if (htab
->elf
.splt
!= NULL
)
2731 plt_index
= (h
->plt
.offset
/ plt_entry_size
2732 - htab
->plt
.has_plt0
);
2733 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2734 base_got
= htab
->elf
.sgotplt
;
2738 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2739 off
= plt_index
* GOT_ENTRY_SIZE
;
2740 base_got
= htab
->elf
.igotplt
;
2743 if (h
->dynindx
== -1
2747 /* This references the local defitionion. We must
2748 initialize this entry in the global offset table.
2749 Since the offset must always be a multiple of 8,
2750 we use the least significant bit to record
2751 whether we have initialized it already.
2753 When doing a dynamic link, we create a .rela.got
2754 relocation entry to initialize the value. This
2755 is done in the finish_dynamic_symbol routine. */
2760 bfd_put_64 (output_bfd
, relocation
,
2761 base_got
->contents
+ off
);
2762 /* Note that this is harmless for the GOTPLT64
2763 case, as -1 | 1 still is -1. */
2769 relocation
= (base_got
->output_section
->vma
2770 + base_got
->output_offset
+ off
);
2775 if (h
->plt
.offset
== (bfd_vma
) -1)
2777 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2778 if (r_type
== htab
->pointer_r_type
2779 && (input_section
->flags
& SEC_CODE
) == 0)
2780 goto do_ifunc_pointer
;
2781 goto bad_ifunc_reloc
;
2784 /* STT_GNU_IFUNC symbol must go through PLT. */
2785 if (htab
->elf
.splt
!= NULL
)
2787 if (htab
->plt_second
!= NULL
)
2789 resolved_plt
= htab
->plt_second
;
2790 plt_offset
= eh
->plt_second
.offset
;
2794 resolved_plt
= htab
->elf
.splt
;
2795 plt_offset
= h
->plt
.offset
;
2800 resolved_plt
= htab
->elf
.iplt
;
2801 plt_offset
= h
->plt
.offset
;
2804 relocation
= (resolved_plt
->output_section
->vma
2805 + resolved_plt
->output_offset
+ plt_offset
);
2811 if (h
->root
.root
.string
)
2812 name
= h
->root
.root
.string
;
2814 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2817 /* xgettext:c-format */
2818 (_("%pB: relocation %s against STT_GNU_IFUNC "
2819 "symbol `%s' isn't supported"), input_bfd
,
2821 bfd_set_error (bfd_error_bad_value
);
2825 if (bfd_link_pic (info
))
2830 if (ABI_64_P (output_bfd
))
2835 if (rel
->r_addend
!= 0)
2837 if (h
->root
.root
.string
)
2838 name
= h
->root
.root
.string
;
2840 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2843 /* xgettext:c-format */
2844 (_("%pB: relocation %s against STT_GNU_IFUNC "
2845 "symbol `%s' has non-zero addend: %" PRId64
),
2846 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
2847 bfd_set_error (bfd_error_bad_value
);
2851 /* Generate dynamic relcoation only when there is a
2852 non-GOT reference in a shared object or there is no
2854 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2855 || h
->plt
.offset
== (bfd_vma
) -1)
2857 Elf_Internal_Rela outrel
;
2860 /* Need a dynamic relocation to get the real function
2862 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2866 if (outrel
.r_offset
== (bfd_vma
) -1
2867 || outrel
.r_offset
== (bfd_vma
) -2)
2870 outrel
.r_offset
+= (input_section
->output_section
->vma
2871 + input_section
->output_offset
);
2873 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2875 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
2876 h
->root
.root
.string
,
2877 h
->root
.u
.def
.section
->owner
);
2879 /* This symbol is resolved locally. */
2880 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2881 outrel
.r_addend
= (h
->root
.u
.def
.value
2882 + h
->root
.u
.def
.section
->output_section
->vma
2883 + h
->root
.u
.def
.section
->output_offset
);
2885 if (htab
->params
->report_relative_reloc
)
2886 _bfd_x86_elf_link_report_relative_reloc
2887 (info
, input_section
, h
, sym
,
2888 "R_X86_64_IRELATIVE", &outrel
);
2892 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2893 outrel
.r_addend
= 0;
2896 /* Dynamic relocations are stored in
2897 1. .rela.ifunc section in PIC object.
2898 2. .rela.got section in dynamic executable.
2899 3. .rela.iplt section in static executable. */
2900 if (bfd_link_pic (info
))
2901 sreloc
= htab
->elf
.irelifunc
;
2902 else if (htab
->elf
.splt
!= NULL
)
2903 sreloc
= htab
->elf
.srelgot
;
2905 sreloc
= htab
->elf
.irelplt
;
2906 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2908 /* If this reloc is against an external symbol, we
2909 do not want to fiddle with the addend. Otherwise,
2910 we need to include the symbol value so that it
2911 becomes an addend for the dynamic reloc. For an
2912 internal symbol, we have updated addend. */
2918 case R_X86_64_PLT32
:
2924 resolved_to_zero
= (eh
!= NULL
2925 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2927 /* When generating a shared object, the relocations handled here are
2928 copied into the output file to be resolved at run time. */
2931 case R_X86_64_GOT32
:
2932 case R_X86_64_GOT64
:
2933 /* Relocation is to the entry for this symbol in the global
2935 case R_X86_64_GOTPCREL
:
2936 case R_X86_64_GOTPCRELX
:
2937 case R_X86_64_REX_GOTPCRELX
:
2938 case R_X86_64_GOTPCREL64
:
2939 /* Use global offset table entry as symbol value. */
2940 case R_X86_64_GOTPLT64
:
2941 /* This is obsolete and treated the same as GOT64. */
2942 base_got
= htab
->elf
.sgot
;
2944 if (htab
->elf
.sgot
== NULL
)
2947 relative_reloc
= false;
2950 off
= h
->got
.offset
;
2952 && h
->plt
.offset
!= (bfd_vma
)-1
2953 && off
== (bfd_vma
)-1)
2955 /* We can't use h->got.offset here to save
2956 state, or even just remember the offset, as
2957 finish_dynamic_symbol would use that as offset into
2959 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
2960 - htab
->plt
.has_plt0
);
2961 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2962 base_got
= htab
->elf
.sgotplt
;
2965 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2967 /* We must initialize this entry in the global offset
2968 table. Since the offset must always be a multiple
2969 of 8, we use the least significant bit to record
2970 whether we have initialized it already.
2972 When doing a dynamic link, we create a .rela.got
2973 relocation entry to initialize the value. This is
2974 done in the finish_dynamic_symbol routine. */
2979 bfd_put_64 (output_bfd
, relocation
,
2980 base_got
->contents
+ off
);
2981 /* Note that this is harmless for the GOTPLT64 case,
2982 as -1 | 1 still is -1. */
2985 /* NB: Don't generate relative relocation here if
2986 it has been generated by DT_RELR. */
2987 if (!info
->enable_dt_relr
2988 && GENERATE_RELATIVE_RELOC_P (info
, h
))
2990 /* If this symbol isn't dynamic in PIC,
2991 generate R_X86_64_RELATIVE here. */
2992 eh
->no_finish_dynamic_symbol
= 1;
2993 relative_reloc
= true;
2998 unresolved_reloc
= false;
3002 if (local_got_offsets
== NULL
)
3005 off
= local_got_offsets
[r_symndx
];
3007 /* The offset must always be a multiple of 8. We use
3008 the least significant bit to record whether we have
3009 already generated the necessary reloc. */
3014 bfd_put_64 (output_bfd
, relocation
,
3015 base_got
->contents
+ off
);
3016 local_got_offsets
[r_symndx
] |= 1;
3018 /* NB: GOTPCREL relocations against local absolute
3019 symbol store relocation value in the GOT slot
3020 without relative relocation. Don't generate
3021 relative relocation here if it has been generated
3023 if (!info
->enable_dt_relr
3024 && bfd_link_pic (info
)
3025 && !(sym
->st_shndx
== SHN_ABS
3026 && (r_type
== R_X86_64_GOTPCREL
3027 || r_type
== R_X86_64_GOTPCRELX
3028 || r_type
== R_X86_64_REX_GOTPCRELX
)))
3029 relative_reloc
= true;
3036 Elf_Internal_Rela outrel
;
3038 /* We need to generate a R_X86_64_RELATIVE reloc
3039 for the dynamic linker. */
3040 s
= htab
->elf
.srelgot
;
3044 outrel
.r_offset
= (base_got
->output_section
->vma
3045 + base_got
->output_offset
3047 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3048 outrel
.r_addend
= relocation
;
3050 if (htab
->params
->report_relative_reloc
)
3051 _bfd_x86_elf_link_report_relative_reloc
3052 (info
, input_section
, h
, sym
, "R_X86_64_RELATIVE",
3055 elf_append_rela (output_bfd
, s
, &outrel
);
3058 if (off
>= (bfd_vma
) -2)
3061 relocation
= base_got
->output_section
->vma
3062 + base_got
->output_offset
+ off
;
3063 if (r_type
!= R_X86_64_GOTPCREL
3064 && r_type
!= R_X86_64_GOTPCRELX
3065 && r_type
!= R_X86_64_REX_GOTPCRELX
3066 && r_type
!= R_X86_64_GOTPCREL64
)
3067 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3068 - htab
->elf
.sgotplt
->output_offset
;
3072 case R_X86_64_GOTOFF64
:
3073 /* Relocation is relative to the start of the global offset
3076 /* Check to make sure it isn't a protected function or data
3077 symbol for shared library since it may not be local when
3078 used as function address or with copy relocation. We also
3079 need to make sure that a symbol is referenced locally. */
3080 if (bfd_link_pic (info
) && h
)
3082 if (!h
->def_regular
)
3086 switch (ELF_ST_VISIBILITY (h
->other
))
3089 v
= _("hidden symbol");
3092 v
= _("internal symbol");
3095 v
= _("protected symbol");
3103 /* xgettext:c-format */
3104 (_("%pB: relocation R_X86_64_GOTOFF64 against undefined %s"
3105 " `%s' can not be used when making a shared object"),
3106 input_bfd
, v
, h
->root
.root
.string
);
3107 bfd_set_error (bfd_error_bad_value
);
3110 else if (!bfd_link_executable (info
)
3111 && !SYMBOL_REFERENCES_LOCAL_P (info
, h
)
3112 && (h
->type
== STT_FUNC
3113 || h
->type
== STT_OBJECT
)
3114 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3117 /* xgettext:c-format */
3118 (_("%pB: relocation R_X86_64_GOTOFF64 against protected %s"
3119 " `%s' can not be used when making a shared object"),
3121 h
->type
== STT_FUNC
? "function" : "data",
3122 h
->root
.root
.string
);
3123 bfd_set_error (bfd_error_bad_value
);
3128 /* Note that sgot is not involved in this
3129 calculation. We always want the start of .got.plt. If we
3130 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3131 permitted by the ABI, we might have to change this
3133 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3134 + htab
->elf
.sgotplt
->output_offset
;
3137 case R_X86_64_GOTPC32
:
3138 case R_X86_64_GOTPC64
:
3139 /* Use global offset table as symbol value. */
3140 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3141 + htab
->elf
.sgotplt
->output_offset
;
3142 unresolved_reloc
= false;
3145 case R_X86_64_PLTOFF64
:
3146 /* Relocation is PLT entry relative to GOT. For local
3147 symbols it's the symbol itself relative to GOT. */
3149 /* See PLT32 handling. */
3150 && (h
->plt
.offset
!= (bfd_vma
) -1
3151 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
3152 && htab
->elf
.splt
!= NULL
)
3154 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3156 /* Use the GOT PLT. */
3157 resolved_plt
= htab
->plt_got
;
3158 plt_offset
= eh
->plt_got
.offset
;
3160 else if (htab
->plt_second
!= NULL
)
3162 resolved_plt
= htab
->plt_second
;
3163 plt_offset
= eh
->plt_second
.offset
;
3167 resolved_plt
= htab
->elf
.splt
;
3168 plt_offset
= h
->plt
.offset
;
3171 relocation
= (resolved_plt
->output_section
->vma
3172 + resolved_plt
->output_offset
3174 unresolved_reloc
= false;
3177 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3178 + htab
->elf
.sgotplt
->output_offset
;
3181 case R_X86_64_PLT32
:
3182 /* Relocation is to the entry for this symbol in the
3183 procedure linkage table. */
3185 /* Resolve a PLT32 reloc against a local symbol directly,
3186 without using the procedure linkage table. */
3190 if ((h
->plt
.offset
== (bfd_vma
) -1
3191 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3192 || htab
->elf
.splt
== NULL
)
3194 /* We didn't make a PLT entry for this symbol. This
3195 happens when statically linking PIC code, or when
3196 using -Bsymbolic. */
3201 if (h
->plt
.offset
!= (bfd_vma
) -1)
3203 if (htab
->plt_second
!= NULL
)
3205 resolved_plt
= htab
->plt_second
;
3206 plt_offset
= eh
->plt_second
.offset
;
3210 resolved_plt
= htab
->elf
.splt
;
3211 plt_offset
= h
->plt
.offset
;
3216 /* Use the GOT PLT. */
3217 resolved_plt
= htab
->plt_got
;
3218 plt_offset
= eh
->plt_got
.offset
;
3221 relocation
= (resolved_plt
->output_section
->vma
3222 + resolved_plt
->output_offset
3224 unresolved_reloc
= false;
3227 case R_X86_64_SIZE32
:
3228 case R_X86_64_SIZE64
:
3229 /* Set to symbol size. */
3230 relocation
= st_size
;
3236 /* Don't complain about -fPIC if the symbol is undefined when
3237 building executable unless it is unresolved weak symbol,
3238 references a dynamic definition in PIE or -z nocopyreloc
3241 = (info
->nocopyreloc
3243 && !h
->root
.linker_def
3244 && !h
->root
.ldscript_def
3245 && eh
->def_protected
));
3247 if ((input_section
->flags
& SEC_ALLOC
) != 0
3248 && (input_section
->flags
& SEC_READONLY
) != 0
3250 && ((bfd_link_executable (info
)
3251 && ((h
->root
.type
== bfd_link_hash_undefweak
3253 || !UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3255 || (bfd_link_pie (info
)
3256 && !SYMBOL_DEFINED_NON_SHARED_P (h
)
3260 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
3261 || (bfd_link_pie (info
)
3262 && h
->root
.type
== bfd_link_hash_undefweak
)
3263 || bfd_link_dll (info
)))
3266 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3268 /* Symbol is referenced locally. Make sure it is
3270 fail
= !SYMBOL_DEFINED_NON_SHARED_P (h
);
3272 else if (bfd_link_pie (info
))
3274 /* We can only use PC-relative relocations in PIE
3275 from non-code sections. */
3276 if (h
->root
.type
== bfd_link_hash_undefweak
3277 || (h
->type
== STT_FUNC
3278 && (sec
->flags
& SEC_CODE
) != 0))
3281 else if (no_copyreloc_p
|| bfd_link_dll (info
))
3283 /* Symbol doesn't need copy reloc and isn't
3284 referenced locally. Don't allow PC-relative
3285 relocations against default and protected
3286 symbols since address of protected function
3287 and location of protected data may not be in
3288 the shared object. */
3289 fail
= (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3290 || ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
);
3294 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3295 h
, NULL
, NULL
, howto
);
3297 /* Since x86-64 has PC-relative PLT, we can use PLT in PIE
3298 as function address. */
3300 && (input_section
->flags
& SEC_CODE
) == 0
3301 && bfd_link_pie (info
)
3302 && h
->type
== STT_FUNC
3313 /* FIXME: The ABI says the linker should make sure the value is
3314 the same when it's zeroextended to 64 bit. */
3317 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3320 need_copy_reloc_in_pie
= (bfd_link_pie (info
)
3325 == bfd_link_hash_undefined
))
3326 && (X86_PCREL_TYPE_P (true, r_type
)
3327 || X86_SIZE_TYPE_P (true,
3330 if (GENERATE_DYNAMIC_RELOCATION_P (true, info
, eh
, r_type
, sec
,
3331 need_copy_reloc_in_pie
,
3332 resolved_to_zero
, false))
3334 Elf_Internal_Rela outrel
;
3335 bool skip
, relocate
;
3336 bool generate_dynamic_reloc
= true;
3338 const char *relative_reloc_name
= NULL
;
3340 /* When generating a shared object, these relocations
3341 are copied into the output file to be resolved at run
3347 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3349 if (outrel
.r_offset
== (bfd_vma
) -1)
3351 else if (outrel
.r_offset
== (bfd_vma
) -2)
3352 skip
= true, relocate
= true;
3354 outrel
.r_offset
+= (input_section
->output_section
->vma
3355 + input_section
->output_offset
);
3358 memset (&outrel
, 0, sizeof outrel
);
3360 else if (COPY_INPUT_RELOC_P (true, info
, h
, r_type
))
3362 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3363 outrel
.r_addend
= rel
->r_addend
;
3367 /* This symbol is local, or marked to become local.
3368 When relocation overflow check is disabled, we
3369 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3370 if (r_type
== htab
->pointer_r_type
3371 || (r_type
== R_X86_64_32
3372 && htab
->params
->no_reloc_overflow_check
))
3375 /* NB: Don't generate relative relocation here if
3376 it has been generated by DT_RELR. */
3377 if (info
->enable_dt_relr
)
3378 generate_dynamic_reloc
= false;
3382 htab
->r_info (0, R_X86_64_RELATIVE
);
3383 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3384 relative_reloc_name
= "R_X86_64_RELATIVE";
3387 else if (r_type
== R_X86_64_64
3388 && !ABI_64_P (output_bfd
))
3391 outrel
.r_info
= htab
->r_info (0,
3392 R_X86_64_RELATIVE64
);
3393 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3394 relative_reloc_name
= "R_X86_64_RELATIVE64";
3395 /* Check addend overflow. */
3396 if ((outrel
.r_addend
& 0x80000000)
3397 != (rel
->r_addend
& 0x80000000))
3400 int addend
= rel
->r_addend
;
3401 if (h
&& h
->root
.root
.string
)
3402 name
= h
->root
.root
.string
;
3404 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3407 /* xgettext:c-format */
3408 (_("%pB: addend %s%#x in relocation %s against "
3409 "symbol `%s' at %#" PRIx64
3410 " in section `%pA' is out of range"),
3411 input_bfd
, addend
< 0 ? "-" : "", addend
,
3412 howto
->name
, name
, (uint64_t) rel
->r_offset
,
3414 bfd_set_error (bfd_error_bad_value
);
3422 if (bfd_is_abs_section (sec
))
3424 else if (sec
== NULL
|| sec
->owner
== NULL
)
3426 bfd_set_error (bfd_error_bad_value
);
3433 /* We are turning this relocation into one
3434 against a section symbol. It would be
3435 proper to subtract the symbol's value,
3436 osec->vma, from the emitted reloc addend,
3437 but ld.so expects buggy relocs. */
3438 osec
= sec
->output_section
;
3439 sindx
= elf_section_data (osec
)->dynindx
;
3442 asection
*oi
= htab
->elf
.text_index_section
;
3443 sindx
= elf_section_data (oi
)->dynindx
;
3445 BFD_ASSERT (sindx
!= 0);
3448 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3449 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3453 if (generate_dynamic_reloc
)
3455 sreloc
= elf_section_data (input_section
)->sreloc
;
3457 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3459 r
= bfd_reloc_notsupported
;
3460 goto check_relocation_error
;
3463 if (relative_reloc_name
3464 && htab
->params
->report_relative_reloc
)
3465 _bfd_x86_elf_link_report_relative_reloc
3466 (info
, input_section
, h
, sym
,
3467 relative_reloc_name
, &outrel
);
3469 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3472 /* If this reloc is against an external symbol, we do
3473 not want to fiddle with the addend. Otherwise, we
3474 need to include the symbol value so that it becomes
3475 an addend for the dynamic reloc. */
3482 case R_X86_64_TLSGD
:
3483 case R_X86_64_GOTPC32_TLSDESC
:
3484 case R_X86_64_TLSDESC_CALL
:
3485 case R_X86_64_GOTTPOFF
:
3486 tls_type
= GOT_UNKNOWN
;
3487 if (h
== NULL
&& local_got_offsets
)
3488 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3490 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
3492 r_type_tls
= r_type
;
3493 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3494 input_section
, contents
,
3495 symtab_hdr
, sym_hashes
,
3496 &r_type_tls
, tls_type
, rel
,
3497 relend
, h
, r_symndx
, true))
3500 if (r_type_tls
== R_X86_64_TPOFF32
)
3502 bfd_vma roff
= rel
->r_offset
;
3504 BFD_ASSERT (! unresolved_reloc
);
3506 if (r_type
== R_X86_64_TLSGD
)
3508 /* GD->LE transition. For 64bit, change
3509 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3510 .word 0x6666; rex64; call __tls_get_addr@PLT
3512 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3514 call *__tls_get_addr@GOTPCREL(%rip)
3515 which may be converted to
3516 addr32 call __tls_get_addr
3519 leaq foo@tpoff(%rax), %rax
3521 leaq foo@tlsgd(%rip), %rdi
3522 .word 0x6666; rex64; call __tls_get_addr@PLT
3524 leaq foo@tlsgd(%rip), %rdi
3526 call *__tls_get_addr@GOTPCREL(%rip)
3527 which may be converted to
3528 addr32 call __tls_get_addr
3531 leaq foo@tpoff(%rax), %rax
3532 For largepic, change:
3533 leaq foo@tlsgd(%rip), %rdi
3534 movabsq $__tls_get_addr@pltoff, %rax
3539 leaq foo@tpoff(%rax), %rax
3540 nopw 0x0(%rax,%rax,1) */
3542 if (ABI_64_P (output_bfd
))
3544 if (contents
[roff
+ 5] == 0xb8)
3547 || (roff
- 3 + 22) > input_section
->size
)
3550 info
->callbacks
->einfo
3551 (_("%F%P: corrupt input: %pB\n"),
3555 memcpy (contents
+ roff
- 3,
3556 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3557 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3563 || (roff
- 4 + 16) > input_section
->size
)
3565 memcpy (contents
+ roff
- 4,
3566 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3573 || (roff
- 3 + 15) > input_section
->size
)
3575 memcpy (contents
+ roff
- 3,
3576 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3579 bfd_put_32 (output_bfd
,
3580 elf_x86_64_tpoff (info
, relocation
),
3581 contents
+ roff
+ 8 + largepic
);
3582 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3583 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3588 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3590 /* GDesc -> LE transition.
3591 It's originally something like:
3592 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3593 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3596 movq $x@tpoff, %rax <--- LP64 mode.
3597 rex movl $x@tpoff, %eax <--- X32 mode.
3600 unsigned int val
, type
;
3604 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3605 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3606 bfd_put_8 (output_bfd
,
3607 (type
& 0x48) | ((type
>> 2) & 1),
3608 contents
+ roff
- 3);
3609 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3610 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3611 contents
+ roff
- 1);
3612 bfd_put_32 (output_bfd
,
3613 elf_x86_64_tpoff (info
, relocation
),
3617 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3619 /* GDesc -> LE transition.
3621 call *(%rax) <--- LP64 mode.
3622 call *(%eax) <--- X32 mode.
3624 xchg %ax,%ax <-- LP64 mode.
3625 nopl (%rax) <-- X32 mode.
3627 unsigned int prefix
= 0;
3628 if (!ABI_64_P (input_bfd
))
3630 /* Check for call *x@tlsdesc(%eax). */
3631 if (contents
[roff
] == 0x67)
3636 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
3637 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
3638 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
3642 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3643 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3647 else if (r_type
== R_X86_64_GOTTPOFF
)
3649 /* IE->LE transition:
3650 For 64bit, originally it can be one of:
3651 movq foo@gottpoff(%rip), %reg
3652 addq foo@gottpoff(%rip), %reg
3655 leaq foo(%reg), %reg
3657 For 32bit, originally it can be one of:
3658 movq foo@gottpoff(%rip), %reg
3659 addl foo@gottpoff(%rip), %reg
3662 leal foo(%reg), %reg
3665 unsigned int val
, type
, reg
;
3668 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3675 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3676 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3685 bfd_put_8 (output_bfd
, 0x49,
3686 contents
+ roff
- 3);
3688 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3692 bfd_put_8 (output_bfd
, 0x41,
3693 contents
+ roff
- 3);
3695 bfd_put_8 (output_bfd
, 0xc7,
3696 contents
+ roff
- 2);
3697 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3698 contents
+ roff
- 1);
3702 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3708 bfd_put_8 (output_bfd
, 0x49,
3709 contents
+ roff
- 3);
3711 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3715 bfd_put_8 (output_bfd
, 0x41,
3716 contents
+ roff
- 3);
3718 bfd_put_8 (output_bfd
, 0x81,
3719 contents
+ roff
- 2);
3720 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3721 contents
+ roff
- 1);
3725 /* addq/addl -> leaq/leal */
3730 bfd_put_8 (output_bfd
, 0x4d,
3731 contents
+ roff
- 3);
3733 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3737 bfd_put_8 (output_bfd
, 0x45,
3738 contents
+ roff
- 3);
3740 bfd_put_8 (output_bfd
, 0x8d,
3741 contents
+ roff
- 2);
3742 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3743 contents
+ roff
- 1);
3745 bfd_put_32 (output_bfd
,
3746 elf_x86_64_tpoff (info
, relocation
),
3754 if (htab
->elf
.sgot
== NULL
)
3759 off
= h
->got
.offset
;
3760 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3764 if (local_got_offsets
== NULL
)
3767 off
= local_got_offsets
[r_symndx
];
3768 offplt
= local_tlsdesc_gotents
[r_symndx
];
3775 Elf_Internal_Rela outrel
;
3779 if (htab
->elf
.srelgot
== NULL
)
3782 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3784 if (GOT_TLS_GDESC_P (tls_type
))
3786 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3787 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3788 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3789 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3790 + htab
->elf
.sgotplt
->output_offset
3792 + htab
->sgotplt_jump_table_size
);
3793 sreloc
= htab
->elf
.srelplt
;
3795 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3797 outrel
.r_addend
= 0;
3798 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3801 sreloc
= htab
->elf
.srelgot
;
3803 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3804 + htab
->elf
.sgot
->output_offset
+ off
);
3806 if (GOT_TLS_GD_P (tls_type
))
3807 dr_type
= R_X86_64_DTPMOD64
;
3808 else if (GOT_TLS_GDESC_P (tls_type
))
3811 dr_type
= R_X86_64_TPOFF64
;
3813 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3814 outrel
.r_addend
= 0;
3815 if ((dr_type
== R_X86_64_TPOFF64
3816 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3817 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3818 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3820 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3822 if (GOT_TLS_GD_P (tls_type
))
3826 BFD_ASSERT (! unresolved_reloc
);
3827 bfd_put_64 (output_bfd
,
3828 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3829 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3833 bfd_put_64 (output_bfd
, 0,
3834 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3835 outrel
.r_info
= htab
->r_info (indx
,
3837 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3838 elf_append_rela (output_bfd
, sreloc
,
3847 local_got_offsets
[r_symndx
] |= 1;
3850 if (off
>= (bfd_vma
) -2
3851 && ! GOT_TLS_GDESC_P (tls_type
))
3853 if (r_type_tls
== r_type
)
3855 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3856 || r_type
== R_X86_64_TLSDESC_CALL
)
3857 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3858 + htab
->elf
.sgotplt
->output_offset
3859 + offplt
+ htab
->sgotplt_jump_table_size
;
3861 relocation
= htab
->elf
.sgot
->output_section
->vma
3862 + htab
->elf
.sgot
->output_offset
+ off
;
3863 unresolved_reloc
= false;
3867 bfd_vma roff
= rel
->r_offset
;
3869 if (r_type
== R_X86_64_TLSGD
)
3871 /* GD->IE transition. For 64bit, change
3872 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3873 .word 0x6666; rex64; call __tls_get_addr@PLT
3875 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3877 call *__tls_get_addr@GOTPCREL(%rip
3878 which may be converted to
3879 addr32 call __tls_get_addr
3882 addq foo@gottpoff(%rip), %rax
3884 leaq foo@tlsgd(%rip), %rdi
3885 .word 0x6666; rex64; call __tls_get_addr@PLT
3887 leaq foo@tlsgd(%rip), %rdi
3889 call *__tls_get_addr@GOTPCREL(%rip)
3890 which may be converted to
3891 addr32 call __tls_get_addr
3894 addq foo@gottpoff(%rip), %rax
3895 For largepic, change:
3896 leaq foo@tlsgd(%rip), %rdi
3897 movabsq $__tls_get_addr@pltoff, %rax
3902 addq foo@gottpoff(%rax), %rax
3903 nopw 0x0(%rax,%rax,1) */
3905 if (ABI_64_P (output_bfd
))
3907 if (contents
[roff
+ 5] == 0xb8)
3910 || (roff
- 3 + 22) > input_section
->size
)
3912 memcpy (contents
+ roff
- 3,
3913 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3914 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3920 || (roff
- 4 + 16) > input_section
->size
)
3922 memcpy (contents
+ roff
- 4,
3923 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3930 || (roff
- 3 + 15) > input_section
->size
)
3932 memcpy (contents
+ roff
- 3,
3933 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3937 relocation
= (htab
->elf
.sgot
->output_section
->vma
3938 + htab
->elf
.sgot
->output_offset
+ off
3941 - input_section
->output_section
->vma
3942 - input_section
->output_offset
3944 bfd_put_32 (output_bfd
, relocation
,
3945 contents
+ roff
+ 8 + largepic
);
3946 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3951 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3953 /* GDesc -> IE transition.
3954 It's originally something like:
3955 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3956 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3959 # before xchg %ax,%ax in LP64 mode.
3960 movq x@gottpoff(%rip), %rax
3961 # before nopl (%rax) in X32 mode.
3962 rex movl x@gottpoff(%rip), %eax
3965 /* Now modify the instruction as appropriate. To
3966 turn a lea into a mov in the form we use it, it
3967 suffices to change the second byte from 0x8d to
3971 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3973 bfd_put_32 (output_bfd
,
3974 htab
->elf
.sgot
->output_section
->vma
3975 + htab
->elf
.sgot
->output_offset
+ off
3977 - input_section
->output_section
->vma
3978 - input_section
->output_offset
3983 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3985 /* GDesc -> IE transition.
3987 call *(%rax) <--- LP64 mode.
3988 call *(%eax) <--- X32 mode.
3991 xchg %ax, %ax <-- LP64 mode.
3992 nopl (%rax) <-- X32 mode.
3995 unsigned int prefix
= 0;
3996 if (!ABI_64_P (input_bfd
))
3998 /* Check for call *x@tlsdesc(%eax). */
3999 if (contents
[roff
] == 0x67)
4004 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
4005 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
4006 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
4010 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4011 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4020 case R_X86_64_TLSLD
:
4021 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4022 input_section
, contents
,
4023 symtab_hdr
, sym_hashes
,
4024 &r_type
, GOT_UNKNOWN
, rel
,
4025 relend
, h
, r_symndx
, true))
4028 if (r_type
!= R_X86_64_TLSLD
)
4030 /* LD->LE transition:
4031 leaq foo@tlsld(%rip), %rdi
4032 call __tls_get_addr@PLT
4033 For 64bit, we change it into:
4034 .word 0x6666; .byte 0x66; movq %fs:0, %rax
4035 For 32bit, we change it into:
4036 nopl 0x0(%rax); movl %fs:0, %eax
4038 leaq foo@tlsld(%rip), %rdi;
4039 call *__tls_get_addr@GOTPCREL(%rip)
4040 which may be converted to
4041 addr32 call __tls_get_addr
4042 For 64bit, we change it into:
4043 .word 0x6666; .word 0x6666; movq %fs:0, %rax
4044 For 32bit, we change it into:
4045 nopw 0x0(%rax); movl %fs:0, %eax
4046 For largepic, change:
4047 leaq foo@tlsgd(%rip), %rdi
4048 movabsq $__tls_get_addr@pltoff, %rax
4052 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
4055 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4056 if (ABI_64_P (output_bfd
))
4058 if ((rel
->r_offset
+ 5) >= input_section
->size
)
4060 if (contents
[rel
->r_offset
+ 5] == 0xb8)
4062 if (rel
->r_offset
< 3
4063 || (rel
->r_offset
- 3 + 22) > input_section
->size
)
4065 memcpy (contents
+ rel
->r_offset
- 3,
4066 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
4067 "\x64\x48\x8b\x04\x25\0\0\0", 22);
4069 else if (contents
[rel
->r_offset
+ 4] == 0xff
4070 || contents
[rel
->r_offset
+ 4] == 0x67)
4072 if (rel
->r_offset
< 3
4073 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
4075 memcpy (contents
+ rel
->r_offset
- 3,
4076 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
4082 if (rel
->r_offset
< 3
4083 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
4085 memcpy (contents
+ rel
->r_offset
- 3,
4086 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4091 if ((rel
->r_offset
+ 4) >= input_section
->size
)
4093 if (contents
[rel
->r_offset
+ 4] == 0xff)
4095 if (rel
->r_offset
< 3
4096 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
4098 memcpy (contents
+ rel
->r_offset
- 3,
4099 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
4104 if (rel
->r_offset
< 3
4105 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
4107 memcpy (contents
+ rel
->r_offset
- 3,
4108 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4111 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
4112 and R_X86_64_PLTOFF64. */
4118 if (htab
->elf
.sgot
== NULL
)
4121 off
= htab
->tls_ld_or_ldm_got
.offset
;
4126 Elf_Internal_Rela outrel
;
4128 if (htab
->elf
.srelgot
== NULL
)
4131 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4132 + htab
->elf
.sgot
->output_offset
+ off
);
4134 bfd_put_64 (output_bfd
, 0,
4135 htab
->elf
.sgot
->contents
+ off
);
4136 bfd_put_64 (output_bfd
, 0,
4137 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4138 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4139 outrel
.r_addend
= 0;
4140 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4142 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4144 relocation
= htab
->elf
.sgot
->output_section
->vma
4145 + htab
->elf
.sgot
->output_offset
+ off
;
4146 unresolved_reloc
= false;
4149 case R_X86_64_DTPOFF32
:
4150 if (!bfd_link_executable (info
)
4151 || (input_section
->flags
& SEC_CODE
) == 0)
4152 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4154 relocation
= elf_x86_64_tpoff (info
, relocation
);
4157 case R_X86_64_TPOFF32
:
4158 case R_X86_64_TPOFF64
:
4159 BFD_ASSERT (bfd_link_executable (info
));
4160 relocation
= elf_x86_64_tpoff (info
, relocation
);
4163 case R_X86_64_DTPOFF64
:
4164 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
4165 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4172 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4173 because such sections are not SEC_ALLOC and thus ld.so will
4174 not process them. */
4175 if (unresolved_reloc
4176 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4178 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4179 rel
->r_offset
) != (bfd_vma
) -1)
4184 sec
= h
->root
.u
.def
.section
;
4185 if ((info
->nocopyreloc
|| eh
->def_protected
)
4186 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
4187 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
4188 h
, NULL
, NULL
, howto
);
4193 /* xgettext:c-format */
4194 (_("%pB(%pA+%#" PRIx64
"): "
4195 "unresolvable %s relocation against symbol `%s'"),
4198 (uint64_t) rel
->r_offset
,
4200 h
->root
.root
.string
);
4206 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4207 contents
, rel
->r_offset
,
4208 relocation
, rel
->r_addend
);
4210 check_relocation_error
:
4211 if (r
!= bfd_reloc_ok
)
4216 name
= h
->root
.root
.string
;
4219 name
= bfd_elf_string_from_elf_section (input_bfd
,
4220 symtab_hdr
->sh_link
,
4225 name
= bfd_section_name (sec
);
4228 if (r
== bfd_reloc_overflow
)
4230 if (converted_reloc
)
4232 info
->callbacks
->einfo
4233 ("%X%H:", input_bfd
, input_section
, rel
->r_offset
);
4234 info
->callbacks
->einfo
4235 (_(" failed to convert GOTPCREL relocation against "
4236 "'%s'; relink with --no-relax\n"),
4241 (*info
->callbacks
->reloc_overflow
)
4242 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4243 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4248 /* xgettext:c-format */
4249 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
4250 input_bfd
, input_section
,
4251 (uint64_t) rel
->r_offset
, name
, (int) r
);
4262 Elf_Internal_Shdr
*rel_hdr
;
4263 size_t deleted
= rel
- wrel
;
4265 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4266 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4267 if (rel_hdr
->sh_size
== 0)
4269 /* It is too late to remove an empty reloc section. Leave
4271 ??? What is wrong with an empty section??? */
4272 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4275 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4276 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4277 input_section
->reloc_count
-= deleted
;
4283 /* Finish up dynamic symbol handling. We set the contents of various
4284 dynamic sections here. */
4287 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4288 struct bfd_link_info
*info
,
4289 struct elf_link_hash_entry
*h
,
4290 Elf_Internal_Sym
*sym
)
4292 struct elf_x86_link_hash_table
*htab
;
4293 bool use_plt_second
;
4294 struct elf_x86_link_hash_entry
*eh
;
4295 bool local_undefweak
;
4297 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4301 /* Use the second PLT section only if there is .plt section. */
4302 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
4304 eh
= (struct elf_x86_link_hash_entry
*) h
;
4305 if (eh
->no_finish_dynamic_symbol
)
4308 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4309 resolved undefined weak symbols in executable so that their
4310 references have value 0 at run-time. */
4311 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
4313 if (h
->plt
.offset
!= (bfd_vma
) -1)
4316 bfd_vma got_offset
, plt_offset
;
4317 Elf_Internal_Rela rela
;
4319 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
4320 const struct elf_backend_data
*bed
;
4321 bfd_vma plt_got_pcrel_offset
;
4323 /* When building a static executable, use .iplt, .igot.plt and
4324 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4325 if (htab
->elf
.splt
!= NULL
)
4327 plt
= htab
->elf
.splt
;
4328 gotplt
= htab
->elf
.sgotplt
;
4329 relplt
= htab
->elf
.srelplt
;
4333 plt
= htab
->elf
.iplt
;
4334 gotplt
= htab
->elf
.igotplt
;
4335 relplt
= htab
->elf
.irelplt
;
4338 VERIFY_PLT_ENTRY (info
, h
, plt
, gotplt
, relplt
, local_undefweak
)
4340 /* Get the index in the procedure linkage table which
4341 corresponds to this symbol. This is the index of this symbol
4342 in all the symbols for which we are making plt entries. The
4343 first entry in the procedure linkage table is reserved.
4345 Get the offset into the .got table of the entry that
4346 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4347 bytes. The first three are reserved for the dynamic linker.
4349 For static executables, we don't reserve anything. */
4351 if (plt
== htab
->elf
.splt
)
4353 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
4354 - htab
->plt
.has_plt0
);
4355 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4359 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
4360 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4363 /* Fill in the entry in the procedure linkage table. */
4364 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4365 htab
->plt
.plt_entry_size
);
4368 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4369 htab
->non_lazy_plt
->plt_entry
,
4370 htab
->non_lazy_plt
->plt_entry_size
);
4372 resolved_plt
= htab
->plt_second
;
4373 plt_offset
= eh
->plt_second
.offset
;
4378 plt_offset
= h
->plt
.offset
;
4381 /* Insert the relocation positions of the plt section. */
4383 /* Put offset the PC-relative instruction referring to the GOT entry,
4384 subtracting the size of that instruction. */
4385 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
4386 + gotplt
->output_offset
4388 - resolved_plt
->output_section
->vma
4389 - resolved_plt
->output_offset
4391 - htab
->plt
.plt_got_insn_size
);
4393 /* Check PC-relative offset overflow in PLT entry. */
4394 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
4395 /* xgettext:c-format */
4396 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in PLT entry for `%s'\n"),
4397 output_bfd
, h
->root
.root
.string
);
4399 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
4400 (resolved_plt
->contents
+ plt_offset
4401 + htab
->plt
.plt_got_offset
));
4403 /* Fill in the entry in the global offset table, initially this
4404 points to the second part of the PLT entry. Leave the entry
4405 as zero for undefined weak symbol in PIE. No PLT relocation
4406 against undefined weak symbol in PIE. */
4407 if (!local_undefweak
)
4409 if (htab
->plt
.has_plt0
)
4410 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4411 + plt
->output_offset
4413 + htab
->lazy_plt
->plt_lazy_offset
),
4414 gotplt
->contents
+ got_offset
);
4416 /* Fill in the entry in the .rela.plt section. */
4417 rela
.r_offset
= (gotplt
->output_section
->vma
4418 + gotplt
->output_offset
4420 if (PLT_LOCAL_IFUNC_P (info
, h
))
4422 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4423 h
->root
.root
.string
,
4424 h
->root
.u
.def
.section
->owner
);
4426 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4427 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4428 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4429 rela
.r_addend
= (h
->root
.u
.def
.value
4430 + h
->root
.u
.def
.section
->output_section
->vma
4431 + h
->root
.u
.def
.section
->output_offset
);
4433 if (htab
->params
->report_relative_reloc
)
4434 _bfd_x86_elf_link_report_relative_reloc
4435 (info
, relplt
, h
, sym
, "R_X86_64_IRELATIVE", &rela
);
4437 /* R_X86_64_IRELATIVE comes last. */
4438 plt_index
= htab
->next_irelative_index
--;
4442 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4444 plt_index
= htab
->next_jump_slot_index
++;
4447 /* Don't fill the second and third slots in PLT entry for
4448 static executables nor without PLT0. */
4449 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4452 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
4454 /* Put relocation index. */
4455 bfd_put_32 (output_bfd
, plt_index
,
4456 (plt
->contents
+ h
->plt
.offset
4457 + htab
->lazy_plt
->plt_reloc_offset
));
4459 /* Put offset for jmp .PLT0 and check for overflow. We don't
4460 check relocation index for overflow since branch displacement
4461 will overflow first. */
4462 if (plt0_offset
> 0x80000000)
4463 /* xgettext:c-format */
4464 info
->callbacks
->einfo (_("%F%pB: branch displacement overflow in PLT entry for `%s'\n"),
4465 output_bfd
, h
->root
.root
.string
);
4466 bfd_put_32 (output_bfd
, - plt0_offset
,
4467 (plt
->contents
+ h
->plt
.offset
4468 + htab
->lazy_plt
->plt_plt_offset
));
4471 bed
= get_elf_backend_data (output_bfd
);
4472 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4473 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4476 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4478 bfd_vma got_offset
, plt_offset
;
4479 asection
*plt
, *got
;
4481 int32_t got_pcrel_offset
;
4483 /* Set the entry in the GOT procedure linkage table. */
4484 plt
= htab
->plt_got
;
4485 got
= htab
->elf
.sgot
;
4486 got_offset
= h
->got
.offset
;
4488 if (got_offset
== (bfd_vma
) -1
4489 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
4494 /* Use the non-lazy PLT entry template for the GOT PLT since they
4495 are the identical. */
4496 /* Fill in the entry in the GOT procedure linkage table. */
4497 plt_offset
= eh
->plt_got
.offset
;
4498 memcpy (plt
->contents
+ plt_offset
,
4499 htab
->non_lazy_plt
->plt_entry
,
4500 htab
->non_lazy_plt
->plt_entry_size
);
4502 /* Put offset the PC-relative instruction referring to the GOT
4503 entry, subtracting the size of that instruction. */
4504 got_pcrel_offset
= (got
->output_section
->vma
4505 + got
->output_offset
4507 - plt
->output_section
->vma
4508 - plt
->output_offset
4510 - htab
->non_lazy_plt
->plt_got_insn_size
);
4512 /* Check PC-relative offset overflow in GOT PLT entry. */
4513 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
4514 if ((got_after_plt
&& got_pcrel_offset
< 0)
4515 || (!got_after_plt
&& got_pcrel_offset
> 0))
4516 /* xgettext:c-format */
4517 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4518 output_bfd
, h
->root
.root
.string
);
4520 bfd_put_32 (output_bfd
, got_pcrel_offset
,
4521 (plt
->contents
+ plt_offset
4522 + htab
->non_lazy_plt
->plt_got_offset
));
4525 if (!local_undefweak
4527 && (h
->plt
.offset
!= (bfd_vma
) -1
4528 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4530 /* Mark the symbol as undefined, rather than as defined in
4531 the .plt section. Leave the value if there were any
4532 relocations where pointer equality matters (this is a clue
4533 for the dynamic linker, to make function pointer
4534 comparisons work between an application and shared
4535 library), otherwise set it to zero. If a function is only
4536 called from a binary, there is no need to slow down
4537 shared libraries because of that. */
4538 sym
->st_shndx
= SHN_UNDEF
;
4539 if (!h
->pointer_equality_needed
)
4543 _bfd_x86_elf_link_fixup_ifunc_symbol (info
, htab
, h
, sym
);
4545 /* Don't generate dynamic GOT relocation against undefined weak
4546 symbol in executable. */
4547 if (h
->got
.offset
!= (bfd_vma
) -1
4548 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
4549 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
4550 && !local_undefweak
)
4552 Elf_Internal_Rela rela
;
4553 asection
*relgot
= htab
->elf
.srelgot
;
4554 const char *relative_reloc_name
= NULL
;
4555 bool generate_dynamic_reloc
= true;
4557 /* This symbol has an entry in the global offset table. Set it
4559 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4562 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4563 + htab
->elf
.sgot
->output_offset
4564 + (h
->got
.offset
&~ (bfd_vma
) 1));
4566 /* If this is a static link, or it is a -Bsymbolic link and the
4567 symbol is defined locally or was forced to be local because
4568 of a version file, we just want to emit a RELATIVE reloc.
4569 The entry in the global offset table will already have been
4570 initialized in the relocate_section function. */
4572 && h
->type
== STT_GNU_IFUNC
)
4574 if (h
->plt
.offset
== (bfd_vma
) -1)
4576 /* STT_GNU_IFUNC is referenced without PLT. */
4577 if (htab
->elf
.splt
== NULL
)
4579 /* use .rel[a].iplt section to store .got relocations
4580 in static executable. */
4581 relgot
= htab
->elf
.irelplt
;
4583 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4585 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4586 h
->root
.root
.string
,
4587 h
->root
.u
.def
.section
->owner
);
4589 rela
.r_info
= htab
->r_info (0,
4590 R_X86_64_IRELATIVE
);
4591 rela
.r_addend
= (h
->root
.u
.def
.value
4592 + h
->root
.u
.def
.section
->output_section
->vma
4593 + h
->root
.u
.def
.section
->output_offset
);
4594 relative_reloc_name
= "R_X86_64_IRELATIVE";
4599 else if (bfd_link_pic (info
))
4601 /* Generate R_X86_64_GLOB_DAT. */
4609 if (!h
->pointer_equality_needed
)
4612 /* For non-shared object, we can't use .got.plt, which
4613 contains the real function addres if we need pointer
4614 equality. We load the GOT entry with the PLT entry. */
4615 if (htab
->plt_second
!= NULL
)
4617 plt
= htab
->plt_second
;
4618 plt_offset
= eh
->plt_second
.offset
;
4622 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4623 plt_offset
= h
->plt
.offset
;
4625 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4626 + plt
->output_offset
4628 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4632 else if (bfd_link_pic (info
)
4633 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4635 if (!SYMBOL_DEFINED_NON_SHARED_P (h
))
4637 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4638 if (info
->enable_dt_relr
)
4639 generate_dynamic_reloc
= false;
4642 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4643 rela
.r_addend
= (h
->root
.u
.def
.value
4644 + h
->root
.u
.def
.section
->output_section
->vma
4645 + h
->root
.u
.def
.section
->output_offset
);
4646 relative_reloc_name
= "R_X86_64_RELATIVE";
4651 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4653 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4654 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4655 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4659 if (generate_dynamic_reloc
)
4661 if (relative_reloc_name
!= NULL
4662 && htab
->params
->report_relative_reloc
)
4663 _bfd_x86_elf_link_report_relative_reloc
4664 (info
, relgot
, h
, sym
, relative_reloc_name
, &rela
);
4666 elf_append_rela (output_bfd
, relgot
, &rela
);
4672 Elf_Internal_Rela rela
;
4675 /* This symbol needs a copy reloc. Set it up. */
4676 VERIFY_COPY_RELOC (h
, htab
)
4678 rela
.r_offset
= (h
->root
.u
.def
.value
4679 + h
->root
.u
.def
.section
->output_section
->vma
4680 + h
->root
.u
.def
.section
->output_offset
);
4681 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4683 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4684 s
= htab
->elf
.sreldynrelro
;
4686 s
= htab
->elf
.srelbss
;
4687 elf_append_rela (output_bfd
, s
, &rela
);
4693 /* Finish up local dynamic symbol handling. We set the contents of
4694 various dynamic sections here. */
4697 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4699 struct elf_link_hash_entry
*h
4700 = (struct elf_link_hash_entry
*) *slot
;
4701 struct bfd_link_info
*info
4702 = (struct bfd_link_info
*) inf
;
4704 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4708 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4709 here since undefined weak symbol may not be dynamic and may not be
4710 called for elf_x86_64_finish_dynamic_symbol. */
4713 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4716 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4717 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4719 if (h
->root
.type
!= bfd_link_hash_undefweak
4720 || h
->dynindx
!= -1)
4723 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4727 /* Used to decide how to sort relocs in an optimal manner for the
4728 dynamic linker, before writing them out. */
4730 static enum elf_reloc_type_class
4731 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
4732 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4733 const Elf_Internal_Rela
*rela
)
4735 bfd
*abfd
= info
->output_bfd
;
4736 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4737 struct elf_x86_link_hash_table
*htab
4738 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4740 if (htab
->elf
.dynsym
!= NULL
4741 && htab
->elf
.dynsym
->contents
!= NULL
)
4743 /* Check relocation against STT_GNU_IFUNC symbol if there are
4745 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
4746 if (r_symndx
!= STN_UNDEF
)
4748 Elf_Internal_Sym sym
;
4749 if (!bed
->s
->swap_symbol_in (abfd
,
4750 (htab
->elf
.dynsym
->contents
4751 + r_symndx
* bed
->s
->sizeof_sym
),
4755 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4756 return reloc_class_ifunc
;
4760 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4762 case R_X86_64_IRELATIVE
:
4763 return reloc_class_ifunc
;
4764 case R_X86_64_RELATIVE
:
4765 case R_X86_64_RELATIVE64
:
4766 return reloc_class_relative
;
4767 case R_X86_64_JUMP_SLOT
:
4768 return reloc_class_plt
;
4770 return reloc_class_copy
;
4772 return reloc_class_normal
;
4776 /* Finish up the dynamic sections. */
4779 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4780 struct bfd_link_info
*info
)
4782 struct elf_x86_link_hash_table
*htab
;
4784 htab
= _bfd_x86_elf_finish_dynamic_sections (output_bfd
, info
);
4788 if (! htab
->elf
.dynamic_sections_created
)
4791 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4793 if (bfd_is_abs_section (htab
->elf
.splt
->output_section
))
4795 info
->callbacks
->einfo
4796 (_("%F%P: discarded output section: `%pA'\n"),
4801 elf_section_data (htab
->elf
.splt
->output_section
)
4802 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
4804 if (htab
->plt
.has_plt0
)
4806 /* Fill in the special first entry in the procedure linkage
4808 memcpy (htab
->elf
.splt
->contents
,
4809 htab
->lazy_plt
->plt0_entry
,
4810 htab
->lazy_plt
->plt0_entry_size
);
4811 /* Add offset for pushq GOT+8(%rip), since the instruction
4812 uses 6 bytes subtract this value. */
4813 bfd_put_32 (output_bfd
,
4814 (htab
->elf
.sgotplt
->output_section
->vma
4815 + htab
->elf
.sgotplt
->output_offset
4817 - htab
->elf
.splt
->output_section
->vma
4818 - htab
->elf
.splt
->output_offset
4820 (htab
->elf
.splt
->contents
4821 + htab
->lazy_plt
->plt0_got1_offset
));
4822 /* Add offset for the PC-relative instruction accessing
4823 GOT+16, subtracting the offset to the end of that
4825 bfd_put_32 (output_bfd
,
4826 (htab
->elf
.sgotplt
->output_section
->vma
4827 + htab
->elf
.sgotplt
->output_offset
4829 - htab
->elf
.splt
->output_section
->vma
4830 - htab
->elf
.splt
->output_offset
4831 - htab
->lazy_plt
->plt0_got2_insn_end
),
4832 (htab
->elf
.splt
->contents
4833 + htab
->lazy_plt
->plt0_got2_offset
));
4836 if (htab
->elf
.tlsdesc_plt
)
4838 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4839 htab
->elf
.sgot
->contents
+ htab
->elf
.tlsdesc_got
);
4841 memcpy (htab
->elf
.splt
->contents
+ htab
->elf
.tlsdesc_plt
,
4842 htab
->lazy_plt
->plt_tlsdesc_entry
,
4843 htab
->lazy_plt
->plt_tlsdesc_entry_size
);
4845 /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4
4846 bytes and the instruction uses 6 bytes, subtract these
4848 bfd_put_32 (output_bfd
,
4849 (htab
->elf
.sgotplt
->output_section
->vma
4850 + htab
->elf
.sgotplt
->output_offset
4852 - htab
->elf
.splt
->output_section
->vma
4853 - htab
->elf
.splt
->output_offset
4854 - htab
->elf
.tlsdesc_plt
4855 - htab
->lazy_plt
->plt_tlsdesc_got1_insn_end
),
4856 (htab
->elf
.splt
->contents
4857 + htab
->elf
.tlsdesc_plt
4858 + htab
->lazy_plt
->plt_tlsdesc_got1_offset
));
4859 /* Add offset for indirect branch via GOT+TDG, where TDG
4860 stands for htab->tlsdesc_got, subtracting the offset
4861 to the end of that instruction. */
4862 bfd_put_32 (output_bfd
,
4863 (htab
->elf
.sgot
->output_section
->vma
4864 + htab
->elf
.sgot
->output_offset
4865 + htab
->elf
.tlsdesc_got
4866 - htab
->elf
.splt
->output_section
->vma
4867 - htab
->elf
.splt
->output_offset
4868 - htab
->elf
.tlsdesc_plt
4869 - htab
->lazy_plt
->plt_tlsdesc_got2_insn_end
),
4870 (htab
->elf
.splt
->contents
4871 + htab
->elf
.tlsdesc_plt
4872 + htab
->lazy_plt
->plt_tlsdesc_got2_offset
));
4876 /* Fill PLT entries for undefined weak symbols in PIE. */
4877 if (bfd_link_pie (info
))
4878 bfd_hash_traverse (&info
->hash
->table
,
4879 elf_x86_64_pie_finish_undefweak_symbol
,
4885 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4886 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4887 It has to be done before elf_link_sort_relocs is called so that
4888 dynamic relocations are properly sorted. */
4891 elf_x86_64_output_arch_local_syms
4892 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4893 struct bfd_link_info
*info
,
4894 void *flaginfo ATTRIBUTE_UNUSED
,
4895 int (*func
) (void *, const char *,
4898 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4900 struct elf_x86_link_hash_table
*htab
4901 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4905 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4906 htab_traverse (htab
->loc_hash_table
,
4907 elf_x86_64_finish_local_dynamic_symbol
,
4913 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4914 dynamic relocations. */
4917 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
4918 long symcount ATTRIBUTE_UNUSED
,
4919 asymbol
**syms ATTRIBUTE_UNUSED
,
4926 bfd_byte
*plt_contents
;
4928 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4929 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4930 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
4931 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
4932 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4933 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4934 const struct elf_x86_lazy_plt_layout
*x32_lazy_ibt_plt
;
4935 const struct elf_x86_non_lazy_plt_layout
*x32_non_lazy_ibt_plt
;
4937 enum elf_x86_plt_type plt_type
;
4938 struct elf_x86_plt plts
[] =
4940 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4941 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4942 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4943 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4944 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4949 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4952 if (dynsymcount
<= 0)
4955 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4959 lazy_plt
= &elf_x86_64_lazy_plt
;
4960 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
4961 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
4962 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
4963 if (ABI_64_P (abfd
))
4965 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
4966 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
4967 x32_lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4968 x32_non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4972 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4973 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4974 x32_lazy_ibt_plt
= NULL
;
4975 x32_non_lazy_ibt_plt
= NULL
;
4979 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4981 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4984 || (plt
->flags
& SEC_HAS_CONTENTS
) == 0)
4987 /* Get the PLT section contents. */
4988 if (!bfd_malloc_and_get_section (abfd
, plt
, &plt_contents
))
4991 /* Check what kind of PLT it is. */
4992 plt_type
= plt_unknown
;
4993 if (plts
[j
].type
== plt_unknown
4994 && (plt
->size
>= (lazy_plt
->plt_entry_size
4995 + lazy_plt
->plt_entry_size
)))
4997 /* Match lazy PLT first. Need to check the first two
4999 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
5000 lazy_plt
->plt0_got1_offset
) == 0)
5001 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
5004 if (x32_lazy_ibt_plt
!= NULL
5005 && (memcmp (plt_contents
5006 + x32_lazy_ibt_plt
->plt_entry_size
,
5007 x32_lazy_ibt_plt
->plt_entry
,
5008 x32_lazy_ibt_plt
->plt_got_offset
) == 0))
5010 /* The fist entry in the x32 lazy IBT PLT is the same
5012 plt_type
= plt_lazy
| plt_second
;
5013 lazy_plt
= x32_lazy_ibt_plt
;
5016 plt_type
= plt_lazy
;
5018 else if (lazy_bnd_plt
!= NULL
5019 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
5020 lazy_bnd_plt
->plt0_got1_offset
) == 0)
5021 && (memcmp (plt_contents
+ 6,
5022 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
5024 plt_type
= plt_lazy
| plt_second
;
5025 /* The fist entry in the lazy IBT PLT is the same as the
5027 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
5028 lazy_ibt_plt
->plt_entry
,
5029 lazy_ibt_plt
->plt_got_offset
) == 0))
5030 lazy_plt
= lazy_ibt_plt
;
5032 lazy_plt
= lazy_bnd_plt
;
5036 if (non_lazy_plt
!= NULL
5037 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5038 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5040 /* Match non-lazy PLT. */
5041 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5042 non_lazy_plt
->plt_got_offset
) == 0)
5043 plt_type
= plt_non_lazy
;
5046 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5048 if (non_lazy_bnd_plt
!= NULL
5049 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
5050 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
5051 non_lazy_bnd_plt
->plt_got_offset
) == 0))
5053 /* Match BND PLT. */
5054 plt_type
= plt_second
;
5055 non_lazy_plt
= non_lazy_bnd_plt
;
5057 else if (non_lazy_ibt_plt
!= NULL
5058 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
5059 && (memcmp (plt_contents
,
5060 non_lazy_ibt_plt
->plt_entry
,
5061 non_lazy_ibt_plt
->plt_got_offset
) == 0))
5063 /* Match IBT PLT. */
5064 plt_type
= plt_second
;
5065 non_lazy_plt
= non_lazy_ibt_plt
;
5067 else if (x32_non_lazy_ibt_plt
!= NULL
5068 && plt
->size
>= x32_non_lazy_ibt_plt
->plt_entry_size
5069 && (memcmp (plt_contents
,
5070 x32_non_lazy_ibt_plt
->plt_entry
,
5071 x32_non_lazy_ibt_plt
->plt_got_offset
) == 0))
5073 /* Match x32 IBT PLT. */
5074 plt_type
= plt_second
;
5075 non_lazy_plt
= x32_non_lazy_ibt_plt
;
5079 if (plt_type
== plt_unknown
)
5081 free (plt_contents
);
5086 plts
[j
].type
= plt_type
;
5088 if ((plt_type
& plt_lazy
))
5090 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5091 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
5092 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5093 /* Skip PLT0 in lazy PLT. */
5098 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5099 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
5100 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5104 /* Skip lazy PLT when the second PLT is used. */
5105 if (plt_type
== (plt_lazy
| plt_second
))
5109 n
= plt
->size
/ plts
[j
].plt_entry_size
;
5114 plts
[j
].contents
= plt_contents
;
5117 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
5118 (bfd_vma
) 0, plts
, dynsyms
,
5122 /* Handle an x86-64 specific section when reading an object file. This
5123 is called when elfcode.h finds a section with an unknown type. */
5126 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
5127 const char *name
, int shindex
)
5129 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
5132 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5138 /* Hook called by the linker routine which adds symbols from an object
5139 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
5143 elf_x86_64_add_symbol_hook (bfd
*abfd
,
5144 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5145 Elf_Internal_Sym
*sym
,
5146 const char **namep ATTRIBUTE_UNUSED
,
5147 flagword
*flagsp ATTRIBUTE_UNUSED
,
5153 switch (sym
->st_shndx
)
5155 case SHN_X86_64_LCOMMON
:
5156 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
5159 lcomm
= bfd_make_section_with_flags (abfd
,
5163 | SEC_LINKER_CREATED
));
5166 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
5169 *valp
= sym
->st_size
;
5177 /* Given a BFD section, try to locate the corresponding ELF section
5181 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5182 asection
*sec
, int *index_return
)
5184 if (sec
== &_bfd_elf_large_com_section
)
5186 *index_return
= SHN_X86_64_LCOMMON
;
5192 /* Process a symbol. */
5195 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5198 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5200 switch (elfsym
->internal_elf_sym
.st_shndx
)
5202 case SHN_X86_64_LCOMMON
:
5203 asym
->section
= &_bfd_elf_large_com_section
;
5204 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5205 /* Common symbol doesn't set BSF_GLOBAL. */
5206 asym
->flags
&= ~BSF_GLOBAL
;
5212 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
5214 return (sym
->st_shndx
== SHN_COMMON
5215 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
5219 elf_x86_64_common_section_index (asection
*sec
)
5221 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5224 return SHN_X86_64_LCOMMON
;
5228 elf_x86_64_common_section (asection
*sec
)
5230 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5231 return bfd_com_section_ptr
;
5233 return &_bfd_elf_large_com_section
;
5237 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5238 const Elf_Internal_Sym
*sym
,
5243 const asection
*oldsec
)
5245 /* A normal common symbol and a large common symbol result in a
5246 normal common symbol. We turn the large common symbol into a
5249 && h
->root
.type
== bfd_link_hash_common
5251 && bfd_is_com_section (*psec
)
5254 if (sym
->st_shndx
== SHN_COMMON
5255 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5257 h
->root
.u
.c
.p
->section
5258 = bfd_make_section_old_way (oldbfd
, "COMMON");
5259 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5261 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5262 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5263 *psec
= bfd_com_section_ptr
;
5270 elf_x86_64_additional_program_headers (bfd
*abfd
,
5271 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5276 /* Check to see if we need a large readonly segment. */
5277 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5278 if (s
&& (s
->flags
& SEC_LOAD
))
5281 /* Check to see if we need a large data segment. Since .lbss sections
5282 is placed right after the .bss section, there should be no need for
5283 a large data segment just because of .lbss. */
5284 s
= bfd_get_section_by_name (abfd
, ".ldata");
5285 if (s
&& (s
->flags
& SEC_LOAD
))
5291 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5294 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5295 const bfd_target
*output
)
5297 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5298 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5299 && _bfd_elf_relocs_compatible (input
, output
));
5302 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5303 with GNU properties if found. Otherwise, return NULL. */
5306 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
5308 struct elf_x86_init_table init_table
;
5309 const struct elf_backend_data
*bed
;
5310 struct elf_x86_link_hash_table
*htab
;
5312 if ((int) R_X86_64_standard
>= (int) R_X86_64_converted_reloc_bit
5313 || (int) R_X86_64_max
<= (int) R_X86_64_converted_reloc_bit
5314 || ((int) (R_X86_64_GNU_VTINHERIT
| R_X86_64_converted_reloc_bit
)
5315 != (int) R_X86_64_GNU_VTINHERIT
)
5316 || ((int) (R_X86_64_GNU_VTENTRY
| R_X86_64_converted_reloc_bit
)
5317 != (int) R_X86_64_GNU_VTENTRY
))
5320 /* This is unused for x86-64. */
5321 init_table
.plt0_pad_byte
= 0x90;
5323 bed
= get_elf_backend_data (info
->output_bfd
);
5324 htab
= elf_x86_hash_table (info
, bed
->target_id
);
5328 init_table
.lazy_plt
= &elf_x86_64_lazy_plt
;
5329 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
5331 init_table
.lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
5332 init_table
.non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
5334 if (ABI_64_P (info
->output_bfd
))
5336 init_table
.sframe_lazy_plt
= &elf_x86_64_sframe_plt
;
5337 init_table
.sframe_non_lazy_plt
= &elf_x86_64_sframe_non_lazy_plt
;
5338 init_table
.sframe_lazy_ibt_plt
= &elf_x86_64_sframe_plt
;
5339 init_table
.sframe_non_lazy_ibt_plt
= &elf_x86_64_sframe_non_lazy_plt
;
5343 /* SFrame is not supported for non AMD64. */
5344 init_table
.sframe_lazy_plt
= NULL
;
5345 init_table
.sframe_non_lazy_plt
= NULL
;
5348 if (ABI_64_P (info
->output_bfd
))
5350 init_table
.r_info
= elf64_r_info
;
5351 init_table
.r_sym
= elf64_r_sym
;
5355 init_table
.r_info
= elf32_r_info
;
5356 init_table
.r_sym
= elf32_r_sym
;
5359 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
5362 static const struct bfd_elf_special_section
5363 elf_x86_64_special_sections
[]=
5365 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5366 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5367 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
5368 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5369 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5370 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5371 { NULL
, 0, 0, 0, 0 }
5374 #define TARGET_LITTLE_SYM x86_64_elf64_vec
5375 #define TARGET_LITTLE_NAME "elf64-x86-64"
5376 #define ELF_ARCH bfd_arch_i386
5377 #define ELF_TARGET_ID X86_64_ELF_DATA
5378 #define ELF_MACHINE_CODE EM_X86_64
5379 #define ELF_MAXPAGESIZE 0x1000
5380 #define ELF_COMMONPAGESIZE 0x1000
5382 #define elf_backend_can_gc_sections 1
5383 #define elf_backend_can_refcount 1
5384 #define elf_backend_want_got_plt 1
5385 #define elf_backend_plt_readonly 1
5386 #define elf_backend_want_plt_sym 0
5387 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5388 #define elf_backend_rela_normal 1
5389 #define elf_backend_plt_alignment 4
5390 #define elf_backend_caches_rawsize 1
5391 #define elf_backend_dtrel_excludes_plt 1
5392 #define elf_backend_want_dynrelro 1
5394 #define elf_info_to_howto elf_x86_64_info_to_howto
5396 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5397 #define bfd_elf64_bfd_reloc_name_lookup \
5398 elf_x86_64_reloc_name_lookup
5400 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5401 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5402 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5403 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5404 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5405 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
5406 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5407 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5409 #define elf_backend_write_core_note elf_x86_64_write_core_note
5411 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5412 #define elf_backend_relocate_section elf_x86_64_relocate_section
5413 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5414 #define elf_backend_object_p elf64_x86_64_elf_object_p
5415 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5417 #define elf_backend_section_from_shdr \
5418 elf_x86_64_section_from_shdr
5420 #define elf_backend_section_from_bfd_section \
5421 elf_x86_64_elf_section_from_bfd_section
5422 #define elf_backend_add_symbol_hook \
5423 elf_x86_64_add_symbol_hook
5424 #define elf_backend_symbol_processing \
5425 elf_x86_64_symbol_processing
5426 #define elf_backend_common_section_index \
5427 elf_x86_64_common_section_index
5428 #define elf_backend_common_section \
5429 elf_x86_64_common_section
5430 #define elf_backend_common_definition \
5431 elf_x86_64_common_definition
5432 #define elf_backend_merge_symbol \
5433 elf_x86_64_merge_symbol
5434 #define elf_backend_special_sections \
5435 elf_x86_64_special_sections
5436 #define elf_backend_additional_program_headers \
5437 elf_x86_64_additional_program_headers
5438 #define elf_backend_setup_gnu_properties \
5439 elf_x86_64_link_setup_gnu_properties
5440 #define elf_backend_hide_symbol \
5441 _bfd_x86_elf_hide_symbol
5444 #define elf64_bed elf64_x86_64_bed
5446 #include "elf64-target.h"
5448 /* CloudABI support. */
5450 #undef TARGET_LITTLE_SYM
5451 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
5452 #undef TARGET_LITTLE_NAME
5453 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
5456 #define ELF_OSABI ELFOSABI_CLOUDABI
5459 #define elf64_bed elf64_x86_64_cloudabi_bed
5461 #include "elf64-target.h"
5463 /* FreeBSD support. */
5465 #undef TARGET_LITTLE_SYM
5466 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
5467 #undef TARGET_LITTLE_NAME
5468 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5471 #define ELF_OSABI ELFOSABI_FREEBSD
5474 #define elf64_bed elf64_x86_64_fbsd_bed
5476 #include "elf64-target.h"
5478 /* Solaris 2 support. */
5480 #undef TARGET_LITTLE_SYM
5481 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
5482 #undef TARGET_LITTLE_NAME
5483 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5485 #undef ELF_TARGET_OS
5486 #define ELF_TARGET_OS is_solaris
5488 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5489 objects won't be recognized. */
5493 #define elf64_bed elf64_x86_64_sol2_bed
5495 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5497 #undef elf_backend_static_tls_alignment
5498 #define elf_backend_static_tls_alignment 16
5500 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5502 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5504 #undef elf_backend_want_plt_sym
5505 #define elf_backend_want_plt_sym 1
5507 #undef elf_backend_strtab_flags
5508 #define elf_backend_strtab_flags SHF_STRINGS
5511 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
5512 bfd
*obfd ATTRIBUTE_UNUSED
,
5513 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
5514 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
5516 /* PR 19938: FIXME: Need to add code for setting the sh_info
5517 and sh_link fields of Solaris specific section types. */
5521 #undef elf_backend_copy_special_section_fields
5522 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
5524 #include "elf64-target.h"
5526 /* Restore defaults. */
5528 #undef elf_backend_static_tls_alignment
5529 #undef elf_backend_want_plt_sym
5530 #define elf_backend_want_plt_sym 0
5531 #undef elf_backend_strtab_flags
5532 #undef elf_backend_copy_special_section_fields
5534 /* 32bit x86-64 support. */
5536 #undef TARGET_LITTLE_SYM
5537 #define TARGET_LITTLE_SYM x86_64_elf32_vec
5538 #undef TARGET_LITTLE_NAME
5539 #define TARGET_LITTLE_NAME "elf32-x86-64"
5541 #define elf32_bed elf32_x86_64_bed
5544 #define ELF_ARCH bfd_arch_i386
5546 #undef ELF_MACHINE_CODE
5547 #define ELF_MACHINE_CODE EM_X86_64
5549 #undef ELF_TARGET_OS
5552 #define bfd_elf32_bfd_reloc_type_lookup \
5553 elf_x86_64_reloc_type_lookup
5554 #define bfd_elf32_bfd_reloc_name_lookup \
5555 elf_x86_64_reloc_name_lookup
5556 #define bfd_elf32_get_synthetic_symtab \
5557 elf_x86_64_get_synthetic_symtab
5559 #undef elf_backend_object_p
5560 #define elf_backend_object_p \
5561 elf32_x86_64_elf_object_p
5563 #undef elf_backend_bfd_from_remote_memory
5564 #define elf_backend_bfd_from_remote_memory \
5565 _bfd_elf32_bfd_from_remote_memory
5567 #undef elf_backend_size_info
5568 #define elf_backend_size_info \
5569 _bfd_elf32_size_info
5571 #include "elf32-target.h"