1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2022 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
)
392 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
393 elf_tdata (abfd
)->core
->pid
394 = bfd_get_32 (abfd
, note
->descdata
+ 12);
395 elf_tdata (abfd
)->core
->program
396 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
397 elf_tdata (abfd
)->core
->command
398 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
401 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
402 elf_tdata (abfd
)->core
->pid
403 = bfd_get_32 (abfd
, note
->descdata
+ 24);
404 elf_tdata (abfd
)->core
->program
405 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
406 elf_tdata (abfd
)->core
->command
407 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
410 /* Note that for some reason, a spurious space is tacked
411 onto the end of the args in some (at least one anyway)
412 implementations, so strip it off if it exists. */
415 char *command
= elf_tdata (abfd
)->core
->command
;
416 int n
= strlen (command
);
418 if (0 < n
&& command
[n
- 1] == ' ')
419 command
[n
- 1] = '\0';
426 # if GCC_VERSION >= 8000
427 # pragma GCC diagnostic push
428 # pragma GCC diagnostic ignored "-Wstringop-truncation"
431 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
434 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
436 const char *fname
, *psargs
;
447 va_start (ap
, note_type
);
448 fname
= va_arg (ap
, const char *);
449 psargs
= va_arg (ap
, const char *);
452 if (bed
->s
->elfclass
== ELFCLASS32
)
455 memset (&data
, 0, sizeof (data
));
456 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
457 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
458 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
459 &data
, sizeof (data
));
464 memset (&data
, 0, sizeof (data
));
465 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
466 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
467 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
468 &data
, sizeof (data
));
473 va_start (ap
, note_type
);
474 pid
= va_arg (ap
, long);
475 cursig
= va_arg (ap
, int);
476 gregs
= va_arg (ap
, const void *);
479 if (bed
->s
->elfclass
== ELFCLASS32
)
481 if (bed
->elf_machine_code
== EM_X86_64
)
483 prstatusx32_t prstat
;
484 memset (&prstat
, 0, sizeof (prstat
));
486 prstat
.pr_cursig
= cursig
;
487 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
488 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
489 &prstat
, sizeof (prstat
));
494 memset (&prstat
, 0, sizeof (prstat
));
496 prstat
.pr_cursig
= cursig
;
497 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
498 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
499 &prstat
, sizeof (prstat
));
505 memset (&prstat
, 0, sizeof (prstat
));
507 prstat
.pr_cursig
= cursig
;
508 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
509 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
510 &prstat
, sizeof (prstat
));
515 # if GCC_VERSION >= 8000
516 # pragma GCC diagnostic pop
520 /* Functions for the x86-64 ELF linker. */
522 /* The size in bytes of an entry in the global offset table. */
524 #define GOT_ENTRY_SIZE 8
526 /* The size in bytes of an entry in the lazy procedure linkage table. */
528 #define LAZY_PLT_ENTRY_SIZE 16
530 /* The size in bytes of an entry in the non-lazy procedure linkage
533 #define NON_LAZY_PLT_ENTRY_SIZE 8
535 /* The first entry in a lazy procedure linkage table looks like this.
536 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
539 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
541 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
542 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
543 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
546 /* Subsequent entries in a lazy procedure linkage table look like this. */
548 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
550 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
551 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
552 0x68, /* pushq immediate */
553 0, 0, 0, 0, /* replaced with index into relocation table. */
554 0xe9, /* jmp relative */
555 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
558 /* The first entry in a lazy procedure linkage table with BND prefix
561 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
563 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
564 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
565 0x0f, 0x1f, 0 /* nopl (%rax) */
568 /* Subsequent entries for branches with BND prefx in a lazy procedure
569 linkage table look like this. */
571 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
573 0x68, 0, 0, 0, 0, /* pushq immediate */
574 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
575 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
578 /* The first entry in the IBT-enabled lazy procedure linkage table is the
579 the same as the lazy PLT with BND prefix so that bound registers are
580 preserved when control is passed to dynamic linker. Subsequent
581 entries for a IBT-enabled lazy procedure linkage table look like
584 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
586 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
587 0x68, 0, 0, 0, 0, /* pushq immediate */
588 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
592 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
593 is the same as the normal lazy PLT. Subsequent entries for an
594 x32 IBT-enabled lazy procedure linkage table look like this. */
596 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
598 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
599 0x68, 0, 0, 0, 0, /* pushq immediate */
600 0xe9, 0, 0, 0, 0, /* jmpq relative */
601 0x66, 0x90 /* xchg %ax,%ax */
604 /* Entries in the non-lazey procedure linkage table look like this. */
606 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
608 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
609 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
610 0x66, 0x90 /* xchg %ax,%ax */
613 /* Entries for branches with BND prefix in the non-lazey procedure
614 linkage table look like this. */
616 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
618 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
619 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
623 /* Entries for branches with IBT-enabled in the non-lazey procedure
624 linkage table look like this. They have the same size as the lazy
627 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
629 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
630 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
631 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
632 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
635 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
636 linkage table look like this. They have the same size as the lazy
639 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
641 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
642 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
643 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
644 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
647 /* The TLSDESC entry in a lazy procedure linkage table. */
648 static const bfd_byte elf_x86_64_tlsdesc_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
650 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
651 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
652 0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */
655 /* .eh_frame covering the lazy .plt section. */
657 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
659 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
660 0, 0, 0, 0, /* CIE ID */
662 'z', 'R', 0, /* Augmentation string */
663 1, /* Code alignment factor */
664 0x78, /* Data alignment factor */
665 16, /* Return address column */
666 1, /* Augmentation size */
667 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
668 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
669 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
670 DW_CFA_nop
, DW_CFA_nop
,
672 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
673 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
674 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
675 0, 0, 0, 0, /* .plt size goes here */
676 0, /* Augmentation size */
677 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
678 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
679 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
680 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
681 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
682 11, /* Block length */
683 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
684 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
685 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
686 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
687 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
690 /* .eh_frame covering the lazy BND .plt section. */
692 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
694 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
695 0, 0, 0, 0, /* CIE ID */
697 'z', 'R', 0, /* Augmentation string */
698 1, /* Code alignment factor */
699 0x78, /* Data alignment factor */
700 16, /* Return address column */
701 1, /* Augmentation size */
702 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
703 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
704 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
705 DW_CFA_nop
, DW_CFA_nop
,
707 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
708 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
709 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
710 0, 0, 0, 0, /* .plt size goes here */
711 0, /* Augmentation size */
712 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
713 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
714 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
715 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
716 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
717 11, /* Block length */
718 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
719 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
720 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
721 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
722 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
725 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
727 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
729 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
730 0, 0, 0, 0, /* CIE ID */
732 'z', 'R', 0, /* Augmentation string */
733 1, /* Code alignment factor */
734 0x78, /* Data alignment factor */
735 16, /* Return address column */
736 1, /* Augmentation size */
737 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
738 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
739 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
740 DW_CFA_nop
, DW_CFA_nop
,
742 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
743 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
744 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
745 0, 0, 0, 0, /* .plt size goes here */
746 0, /* Augmentation size */
747 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
748 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
749 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
750 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
751 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
752 11, /* Block length */
753 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
754 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
755 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
756 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
757 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
760 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
762 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
764 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
765 0, 0, 0, 0, /* CIE ID */
767 'z', 'R', 0, /* Augmentation string */
768 1, /* Code alignment factor */
769 0x78, /* Data alignment factor */
770 16, /* Return address column */
771 1, /* Augmentation size */
772 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
773 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
774 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
775 DW_CFA_nop
, DW_CFA_nop
,
777 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
778 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
779 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
780 0, 0, 0, 0, /* .plt size goes here */
781 0, /* Augmentation size */
782 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
783 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
784 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
785 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
786 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
787 11, /* Block length */
788 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
789 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
790 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
791 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
792 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
795 /* .eh_frame covering the non-lazy .plt section. */
797 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
799 #define PLT_GOT_FDE_LENGTH 20
800 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
801 0, 0, 0, 0, /* CIE ID */
803 'z', 'R', 0, /* Augmentation string */
804 1, /* Code alignment factor */
805 0x78, /* Data alignment factor */
806 16, /* Return address column */
807 1, /* Augmentation size */
808 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
809 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
810 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
811 DW_CFA_nop
, DW_CFA_nop
,
813 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
814 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
815 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
816 0, 0, 0, 0, /* non-lazy .plt size goes here */
817 0, /* Augmentation size */
818 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
819 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
822 static const sframe_frame_row_entry elf_x86_64_sframe_null_fre
=
825 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
826 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
829 /* .sframe FRE covering the .plt section entry. */
830 static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre1
=
832 0, /* SFrame FRE start address. */
833 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
834 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
837 /* .sframe FRE covering the .plt section entry. */
838 static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre2
=
840 6, /* SFrame FRE start address. */
841 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
842 {24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
845 /* .sframe FRE covering the .plt section entry. */
846 static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre1
=
848 0, /* SFrame FRE start address. */
849 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
850 {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
853 /* .sframe FRE covering the .plt section entry. */
854 static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre2
=
856 11, /* SFrame FRE start address. */
857 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
858 {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
861 /* .sframe FRE covering the second .plt section entry. */
862 static const sframe_frame_row_entry elf_x86_64_sframe_sec_pltn_fre1
=
864 0, /* SFrame FRE start address. */
865 SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP
, 1, SFRAME_FRE_OFFSET_1B
), /* FRE info. */
866 {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* 12 bytes. */
869 /* SFrame helper object for non-lazy PLT. Also used for IBT enabled PLT. */
870 static const struct elf_x86_sframe_plt elf_x86_64_sframe_non_lazy_plt
=
873 2, /* Number of FREs for PLT0. */
874 /* Array of SFrame FREs for plt0. */
875 { &elf_x86_64_sframe_plt0_fre1
, &elf_x86_64_sframe_plt0_fre2
},
877 1, /* Number of FREs for PLTn. */
878 /* Array of SFrame FREs for plt. */
879 { &elf_x86_64_sframe_sec_pltn_fre1
, &elf_x86_64_sframe_null_fre
},
881 0, /* There is no second PLT necessary. */
882 { &elf_x86_64_sframe_null_fre
}
885 /* SFrame helper object for lazy PLT. Also used for IBT enabled PLT. */
886 static const struct elf_x86_sframe_plt elf_x86_64_sframe_plt
=
889 2, /* Number of FREs for PLT0. */
890 /* Array of SFrame FREs for plt0. */
891 { &elf_x86_64_sframe_plt0_fre1
, &elf_x86_64_sframe_plt0_fre2
},
893 2, /* Number of FREs for PLTn. */
894 /* Array of SFrame FREs for plt. */
895 { &elf_x86_64_sframe_pltn_fre1
, &elf_x86_64_sframe_pltn_fre2
},
896 NON_LAZY_PLT_ENTRY_SIZE
,
897 1, /* Number of FREs for PLTn for second PLT. */
898 /* FREs for second plt ( unwind info for .plt.got is
899 identical). Used when IBT or non-lazy PLT is in effect. */
900 { &elf_x86_64_sframe_sec_pltn_fre1
}
903 /* These are the standard parameters. */
904 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
906 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
907 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
908 elf_x86_64_lazy_plt_entry
, /* plt_entry */
909 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
910 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
911 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
912 6, /* plt_tlsdesc_got1_offset */
913 12, /* plt_tlsdesc_got2_offset */
914 10, /* plt_tlsdesc_got1_insn_end */
915 16, /* plt_tlsdesc_got2_insn_end */
916 2, /* plt0_got1_offset */
917 8, /* plt0_got2_offset */
918 12, /* plt0_got2_insn_end */
919 2, /* plt_got_offset */
920 7, /* plt_reloc_offset */
921 12, /* plt_plt_offset */
922 6, /* plt_got_insn_size */
923 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
924 6, /* plt_lazy_offset */
925 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
926 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
927 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
928 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
931 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
933 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
934 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
935 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
936 2, /* plt_got_offset */
937 6, /* plt_got_insn_size */
938 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
939 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
942 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
944 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
945 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
946 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
947 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
948 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
949 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
950 6, /* plt_tlsdesc_got1_offset */
951 12, /* plt_tlsdesc_got2_offset */
952 10, /* plt_tlsdesc_got1_insn_end */
953 16, /* plt_tlsdesc_got2_insn_end */
954 2, /* plt0_got1_offset */
955 1+8, /* plt0_got2_offset */
956 1+12, /* plt0_got2_insn_end */
957 1+2, /* plt_got_offset */
958 1, /* plt_reloc_offset */
959 7, /* plt_plt_offset */
960 1+6, /* plt_got_insn_size */
961 11, /* plt_plt_insn_end */
962 0, /* plt_lazy_offset */
963 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
964 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
965 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
966 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
969 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
971 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
972 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
973 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
974 1+2, /* plt_got_offset */
975 1+6, /* plt_got_insn_size */
976 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
977 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
980 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
982 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
983 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
984 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
985 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
986 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
987 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
988 6, /* plt_tlsdesc_got1_offset */
989 12, /* plt_tlsdesc_got2_offset */
990 10, /* plt_tlsdesc_got1_insn_end */
991 16, /* plt_tlsdesc_got2_insn_end */
992 2, /* plt0_got1_offset */
993 1+8, /* plt0_got2_offset */
994 1+12, /* plt0_got2_insn_end */
995 4+1+2, /* plt_got_offset */
996 4+1, /* plt_reloc_offset */
997 4+1+6, /* plt_plt_offset */
998 4+1+6, /* plt_got_insn_size */
999 4+1+5+5, /* plt_plt_insn_end */
1000 0, /* plt_lazy_offset */
1001 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
1002 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
1003 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1004 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1007 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
1009 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
1010 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
1011 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
1012 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1013 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
1014 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
1015 6, /* plt_tlsdesc_got1_offset */
1016 12, /* plt_tlsdesc_got2_offset */
1017 10, /* plt_tlsdesc_got1_insn_end */
1018 16, /* plt_tlsdesc_got2_insn_end */
1019 2, /* plt0_got1_offset */
1020 8, /* plt0_got2_offset */
1021 12, /* plt0_got2_insn_end */
1022 4+2, /* plt_got_offset */
1023 4+1, /* plt_reloc_offset */
1024 4+6, /* plt_plt_offset */
1025 4+6, /* plt_got_insn_size */
1026 4+5+5, /* plt_plt_insn_end */
1027 0, /* plt_lazy_offset */
1028 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
1029 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
1030 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1031 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1034 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
1036 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
1037 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
1038 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1039 4+1+2, /* plt_got_offset */
1040 4+1+6, /* plt_got_insn_size */
1041 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1042 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1045 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
1047 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
1048 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
1049 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1050 4+2, /* plt_got_offset */
1051 4+6, /* plt_got_insn_size */
1052 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1053 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1057 elf64_x86_64_elf_object_p (bfd
*abfd
)
1059 /* Set the right machine number for an x86-64 elf64 file. */
1060 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1065 elf32_x86_64_elf_object_p (bfd
*abfd
)
1067 /* Set the right machine number for an x86-64 elf32 file. */
1068 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1072 /* Return TRUE if the TLS access code sequence support transition
1076 elf_x86_64_check_tls_transition (bfd
*abfd
,
1077 struct bfd_link_info
*info
,
1080 Elf_Internal_Shdr
*symtab_hdr
,
1081 struct elf_link_hash_entry
**sym_hashes
,
1082 unsigned int r_type
,
1083 const Elf_Internal_Rela
*rel
,
1084 const Elf_Internal_Rela
*relend
)
1087 unsigned long r_symndx
;
1088 bool largepic
= false;
1089 struct elf_link_hash_entry
*h
;
1091 struct elf_x86_link_hash_table
*htab
;
1095 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1096 offset
= rel
->r_offset
;
1099 case R_X86_64_TLSGD
:
1100 case R_X86_64_TLSLD
:
1101 if ((rel
+ 1) >= relend
)
1104 if (r_type
== R_X86_64_TLSGD
)
1106 /* Check transition from GD access model. For 64bit, only
1107 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1108 .word 0x6666; rex64; call __tls_get_addr@PLT
1110 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1112 call *__tls_get_addr@GOTPCREL(%rip)
1113 which may be converted to
1114 addr32 call __tls_get_addr
1115 can transit to different access model. For 32bit, only
1116 leaq foo@tlsgd(%rip), %rdi
1117 .word 0x6666; rex64; call __tls_get_addr@PLT
1119 leaq foo@tlsgd(%rip), %rdi
1121 call *__tls_get_addr@GOTPCREL(%rip)
1122 which may be converted to
1123 addr32 call __tls_get_addr
1124 can transit to different access model. For largepic,
1126 leaq foo@tlsgd(%rip), %rdi
1127 movabsq $__tls_get_addr@pltoff, %rax
1131 leaq foo@tlsgd(%rip), %rdi
1132 movabsq $__tls_get_addr@pltoff, %rax
1136 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1138 if ((offset
+ 12) > sec
->size
)
1141 call
= contents
+ offset
+ 4;
1143 || !((call
[1] == 0x48
1151 && call
[3] == 0xe8)))
1153 if (!ABI_64_P (abfd
)
1154 || (offset
+ 19) > sec
->size
1156 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1157 || memcmp (call
, "\x48\xb8", 2) != 0
1161 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1162 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1166 else if (ABI_64_P (abfd
))
1169 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1175 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1178 indirect_call
= call
[2] == 0xff;
1182 /* Check transition from LD access model. Only
1183 leaq foo@tlsld(%rip), %rdi;
1184 call __tls_get_addr@PLT
1186 leaq foo@tlsld(%rip), %rdi;
1187 call *__tls_get_addr@GOTPCREL(%rip)
1188 which may be converted to
1189 addr32 call __tls_get_addr
1190 can transit to different access model. For largepic
1192 leaq foo@tlsld(%rip), %rdi
1193 movabsq $__tls_get_addr@pltoff, %rax
1197 leaq foo@tlsld(%rip), %rdi
1198 movabsq $__tls_get_addr@pltoff, %rax
1202 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1204 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1207 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1210 call
= contents
+ offset
+ 4;
1211 if (!(call
[0] == 0xe8
1212 || (call
[0] == 0xff && call
[1] == 0x15)
1213 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1215 if (!ABI_64_P (abfd
)
1216 || (offset
+ 19) > sec
->size
1217 || memcmp (call
, "\x48\xb8", 2) != 0
1221 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1222 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1226 indirect_call
= call
[0] == 0xff;
1229 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1230 if (r_symndx
< symtab_hdr
->sh_info
)
1233 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1235 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1239 r_type
= (ELF32_R_TYPE (rel
[1].r_info
)
1240 & ~R_X86_64_converted_reloc_bit
);
1242 return r_type
== R_X86_64_PLTOFF64
;
1243 else if (indirect_call
)
1244 return r_type
== R_X86_64_GOTPCRELX
;
1246 return (r_type
== R_X86_64_PC32
|| r_type
== R_X86_64_PLT32
);
1249 case R_X86_64_GOTTPOFF
:
1250 /* Check transition from IE access model:
1251 mov foo@gottpoff(%rip), %reg
1252 add foo@gottpoff(%rip), %reg
1255 /* Check REX prefix first. */
1256 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1258 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1259 if (val
!= 0x48 && val
!= 0x4c)
1261 /* X32 may have 0x44 REX prefix or no REX prefix. */
1262 if (ABI_64_P (abfd
))
1268 /* X32 may not have any REX prefix. */
1269 if (ABI_64_P (abfd
))
1271 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1275 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1276 if (val
!= 0x8b && val
!= 0x03)
1279 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1280 return (val
& 0xc7) == 5;
1282 case R_X86_64_GOTPC32_TLSDESC
:
1283 /* Check transition from GDesc access model:
1284 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
1285 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
1287 Make sure it's a leaq adding rip to a 32-bit offset
1288 into any register, although it's probably almost always
1291 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1294 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1296 if (val
!= 0x48 && (ABI_64_P (abfd
) || val
!= 0x40))
1299 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1302 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1303 return (val
& 0xc7) == 0x05;
1305 case R_X86_64_TLSDESC_CALL
:
1306 /* Check transition from GDesc access model:
1307 call *x@tlsdesc(%rax) <--- LP64 mode.
1308 call *x@tlsdesc(%eax) <--- X32 mode.
1310 if (offset
+ 2 <= sec
->size
)
1312 unsigned int prefix
;
1313 call
= contents
+ offset
;
1315 if (!ABI_64_P (abfd
))
1317 /* Check for call *x@tlsdesc(%eax). */
1318 if (call
[0] == 0x67)
1321 if (offset
+ 3 > sec
->size
)
1325 /* Make sure that it's a call *x@tlsdesc(%rax). */
1326 return call
[prefix
] == 0xff && call
[1 + prefix
] == 0x10;
1336 /* Return TRUE if the TLS access transition is OK or no transition
1337 will be performed. Update R_TYPE if there is a transition. */
1340 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1341 asection
*sec
, bfd_byte
*contents
,
1342 Elf_Internal_Shdr
*symtab_hdr
,
1343 struct elf_link_hash_entry
**sym_hashes
,
1344 unsigned int *r_type
, int tls_type
,
1345 const Elf_Internal_Rela
*rel
,
1346 const Elf_Internal_Rela
*relend
,
1347 struct elf_link_hash_entry
*h
,
1348 unsigned long r_symndx
,
1349 bool from_relocate_section
)
1351 unsigned int from_type
= *r_type
;
1352 unsigned int to_type
= from_type
;
1355 /* Skip TLS transition for functions. */
1357 && (h
->type
== STT_FUNC
1358 || h
->type
== STT_GNU_IFUNC
))
1363 case R_X86_64_TLSGD
:
1364 case R_X86_64_GOTPC32_TLSDESC
:
1365 case R_X86_64_TLSDESC_CALL
:
1366 case R_X86_64_GOTTPOFF
:
1367 if (bfd_link_executable (info
))
1370 to_type
= R_X86_64_TPOFF32
;
1372 to_type
= R_X86_64_GOTTPOFF
;
1375 /* When we are called from elf_x86_64_relocate_section, there may
1376 be additional transitions based on TLS_TYPE. */
1377 if (from_relocate_section
)
1379 unsigned int new_to_type
= to_type
;
1381 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1382 new_to_type
= R_X86_64_TPOFF32
;
1384 if (to_type
== R_X86_64_TLSGD
1385 || to_type
== R_X86_64_GOTPC32_TLSDESC
1386 || to_type
== R_X86_64_TLSDESC_CALL
)
1388 if (tls_type
== GOT_TLS_IE
)
1389 new_to_type
= R_X86_64_GOTTPOFF
;
1392 /* We checked the transition before when we were called from
1393 elf_x86_64_scan_relocs. We only want to check the new
1394 transition which hasn't been checked before. */
1395 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1396 to_type
= new_to_type
;
1401 case R_X86_64_TLSLD
:
1402 if (bfd_link_executable (info
))
1403 to_type
= R_X86_64_TPOFF32
;
1410 /* Return TRUE if there is no transition. */
1411 if (from_type
== to_type
)
1414 /* Check if the transition can be performed. */
1416 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1417 symtab_hdr
, sym_hashes
,
1418 from_type
, rel
, relend
))
1420 reloc_howto_type
*from
, *to
;
1423 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1424 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1426 if (from
== NULL
|| to
== NULL
)
1430 name
= h
->root
.root
.string
;
1433 struct elf_x86_link_hash_table
*htab
;
1435 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1440 Elf_Internal_Sym
*isym
;
1442 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1444 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1449 /* xgettext:c-format */
1450 (_("%pB: TLS transition from %s to %s against `%s' at %#" PRIx64
1451 " in section `%pA' failed"),
1452 abfd
, from
->name
, to
->name
, name
, (uint64_t) rel
->r_offset
, sec
);
1453 bfd_set_error (bfd_error_bad_value
);
1462 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1463 bfd
*input_bfd
, asection
*sec
,
1464 struct elf_link_hash_entry
*h
,
1465 Elf_Internal_Shdr
*symtab_hdr
,
1466 Elf_Internal_Sym
*isym
,
1467 reloc_howto_type
*howto
)
1470 const char *und
= "";
1471 const char *pic
= "";
1477 name
= h
->root
.root
.string
;
1478 switch (ELF_ST_VISIBILITY (h
->other
))
1481 v
= _("hidden symbol ");
1484 v
= _("internal symbol ");
1487 v
= _("protected symbol ");
1490 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1491 v
= _("protected symbol ");
1498 if (!SYMBOL_DEFINED_NON_SHARED_P (h
) && !h
->def_dynamic
)
1499 und
= _("undefined ");
1503 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1507 if (bfd_link_dll (info
))
1509 object
= _("a shared object");
1511 pic
= _("; recompile with -fPIC");
1515 if (bfd_link_pie (info
))
1516 object
= _("a PIE object");
1518 object
= _("a PDE object");
1520 pic
= _("; recompile with -fPIE");
1523 /* xgettext:c-format */
1524 _bfd_error_handler (_("%pB: relocation %s against %s%s`%s' can "
1525 "not be used when making %s%s"),
1526 input_bfd
, howto
->name
, und
, v
, name
,
1528 bfd_set_error (bfd_error_bad_value
);
1529 sec
->check_relocs_failed
= 1;
1533 /* With the local symbol, foo, we convert
1534 mov foo@GOTPCREL(%rip), %reg
1538 call/jmp *foo@GOTPCREL(%rip)
1540 nop call foo/jmp foo nop
1541 When PIC is false, convert
1542 test %reg, foo@GOTPCREL(%rip)
1546 binop foo@GOTPCREL(%rip), %reg
1549 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1553 elf_x86_64_convert_load_reloc (bfd
*abfd
,
1555 unsigned int *r_type_p
,
1556 Elf_Internal_Rela
*irel
,
1557 struct elf_link_hash_entry
*h
,
1559 struct bfd_link_info
*link_info
)
1561 struct elf_x86_link_hash_table
*htab
;
1569 bfd_signed_vma raddend
;
1570 unsigned int opcode
;
1572 unsigned int r_type
= *r_type_p
;
1573 unsigned int r_symndx
;
1574 bfd_vma roff
= irel
->r_offset
;
1575 bfd_vma abs_relocation
;
1577 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1580 raddend
= irel
->r_addend
;
1581 /* Addend for 32-bit PC-relative relocation must be -4. */
1585 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1586 is_pic
= bfd_link_pic (link_info
);
1588 relocx
= (r_type
== R_X86_64_GOTPCRELX
1589 || r_type
== R_X86_64_REX_GOTPCRELX
);
1591 /* TRUE if --no-relax is used. */
1592 no_overflow
= link_info
->disable_target_specific_optimizations
> 1;
1594 r_symndx
= htab
->r_sym (irel
->r_info
);
1596 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1598 /* Convert mov to lea since it has been done for a while. */
1601 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1602 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1603 test, xor instructions. */
1608 /* We convert only to R_X86_64_PC32:
1610 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1611 3. no_overflow is true.
1614 to_reloc_pc32
= (opcode
== 0xff
1622 /* Get the symbol referred to by the reloc. */
1625 Elf_Internal_Sym
*isym
1626 = bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, abfd
, r_symndx
);
1628 /* Skip relocation against undefined symbols. */
1629 if (isym
->st_shndx
== SHN_UNDEF
)
1633 if (isym
->st_shndx
== SHN_ABS
)
1635 tsec
= bfd_abs_section_ptr
;
1637 abs_relocation
= isym
->st_value
;
1639 else if (isym
->st_shndx
== SHN_COMMON
)
1640 tsec
= bfd_com_section_ptr
;
1641 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1642 tsec
= &_bfd_elf_large_com_section
;
1644 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1648 /* Undefined weak symbol is only bound locally in executable
1649 and its reference is resolved as 0 without relocation
1650 overflow. We can only perform this optimization for
1651 GOTPCRELX relocations since we need to modify REX byte.
1652 It is OK convert mov with R_X86_64_GOTPCREL to
1654 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
1656 abs_symbol
= ABS_SYMBOL_P (h
);
1657 abs_relocation
= h
->root
.u
.def
.value
;
1659 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1660 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1661 if ((relocx
|| opcode
== 0x8b)
1662 && (h
->root
.type
== bfd_link_hash_undefweak
1668 /* Skip for branch instructions since R_X86_64_PC32
1675 /* For non-branch instructions, we can convert to
1676 R_X86_64_32/R_X86_64_32S since we know if there
1678 to_reloc_pc32
= false;
1681 /* Since we don't know the current PC when PIC is true,
1682 we can't convert to R_X86_64_PC32. */
1683 if (to_reloc_pc32
&& is_pic
)
1688 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1689 ld.so may use its link-time address. */
1690 else if (h
->start_stop
1693 || h
->root
.type
== bfd_link_hash_defined
1694 || h
->root
.type
== bfd_link_hash_defweak
)
1695 && h
!= htab
->elf
.hdynamic
1698 /* bfd_link_hash_new or bfd_link_hash_undefined is
1699 set by an assignment in a linker script in
1700 bfd_elf_record_link_assignment. start_stop is set
1701 on __start_SECNAME/__stop_SECNAME which mark section
1706 && (h
->root
.type
== bfd_link_hash_new
1707 || h
->root
.type
== bfd_link_hash_undefined
1708 || ((h
->root
.type
== bfd_link_hash_defined
1709 || h
->root
.type
== bfd_link_hash_defweak
)
1710 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1712 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1717 tsec
= h
->root
.u
.def
.section
;
1723 /* Don't convert GOTPCREL relocation against large section. */
1724 if (elf_section_data (tsec
) != NULL
1725 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1728 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1735 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1740 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1742 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1745 /* Convert to "jmp foo nop". */
1748 nop_offset
= irel
->r_offset
+ 3;
1749 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1750 irel
->r_offset
-= 1;
1751 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1755 struct elf_x86_link_hash_entry
*eh
1756 = (struct elf_x86_link_hash_entry
*) h
;
1758 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1761 /* To support TLS optimization, always use addr32 prefix for
1762 "call *__tls_get_addr@GOTPCREL(%rip)". */
1763 if (eh
&& eh
->tls_get_addr
)
1766 nop_offset
= irel
->r_offset
- 2;
1770 nop
= htab
->params
->call_nop_byte
;
1771 if (htab
->params
->call_nop_as_suffix
)
1773 nop_offset
= irel
->r_offset
+ 3;
1774 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1775 irel
->r_offset
-= 1;
1776 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1779 nop_offset
= irel
->r_offset
- 2;
1782 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1783 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1784 r_type
= R_X86_64_PC32
;
1789 unsigned int rex_mask
= REX_R
;
1791 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1792 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1798 if (abs_symbol
&& local_ref
&& relocx
)
1799 to_reloc_pc32
= false;
1803 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1804 "lea foo(%rip), %reg". */
1806 r_type
= R_X86_64_PC32
;
1810 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1811 "mov $foo, %reg". */
1813 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1814 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1815 if ((rex
& REX_W
) != 0
1816 && ABI_64_P (link_info
->output_bfd
))
1818 /* Keep the REX_W bit in REX byte for LP64. */
1819 r_type
= R_X86_64_32S
;
1820 goto rewrite_modrm_rex
;
1824 /* If the REX_W bit in REX byte isn't needed,
1825 use R_X86_64_32 and clear the W bit to avoid
1826 sign-extend imm32 to imm64. */
1827 r_type
= R_X86_64_32
;
1828 /* Clear the W bit in REX byte. */
1830 goto rewrite_modrm_rex
;
1836 /* R_X86_64_PC32 isn't supported. */
1840 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1843 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1844 "test $foo, %reg". */
1845 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1850 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1851 "binop $foo, %reg". */
1852 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1856 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1857 overflow when sign-extending imm32 to imm64. */
1858 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1863 /* Check if R_X86_64_32S/R_X86_64_32 fits. */
1864 if (r_type
== R_X86_64_32S
)
1866 if ((abs_relocation
+ 0x80000000) > 0xffffffff)
1871 if (abs_relocation
> 0xffffffff)
1876 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1880 /* Move the R bit to the B bit in REX byte. */
1881 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1882 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1885 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1889 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1893 irel
->r_info
= htab
->r_info (r_symndx
,
1894 r_type
| R_X86_64_converted_reloc_bit
);
1901 /* Look through the relocs for a section during the first phase, and
1902 calculate needed space in the global offset table, and procedure
1906 elf_x86_64_scan_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1908 const Elf_Internal_Rela
*relocs
)
1910 struct elf_x86_link_hash_table
*htab
;
1911 Elf_Internal_Shdr
*symtab_hdr
;
1912 struct elf_link_hash_entry
**sym_hashes
;
1913 const Elf_Internal_Rela
*rel
;
1914 const Elf_Internal_Rela
*rel_end
;
1918 if (bfd_link_relocatable (info
))
1921 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1924 sec
->check_relocs_failed
= 1;
1928 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1930 /* Get the section contents. */
1931 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1932 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1933 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1935 sec
->check_relocs_failed
= 1;
1939 symtab_hdr
= &elf_symtab_hdr (abfd
);
1940 sym_hashes
= elf_sym_hashes (abfd
);
1944 rel_end
= relocs
+ sec
->reloc_count
;
1945 for (rel
= relocs
; rel
< rel_end
; rel
++)
1947 unsigned int r_type
;
1948 unsigned int r_symndx
;
1949 struct elf_link_hash_entry
*h
;
1950 struct elf_x86_link_hash_entry
*eh
;
1951 Elf_Internal_Sym
*isym
;
1954 bool converted_reloc
;
1957 r_symndx
= htab
->r_sym (rel
->r_info
);
1958 r_type
= ELF32_R_TYPE (rel
->r_info
);
1960 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1962 /* xgettext:c-format */
1963 _bfd_error_handler (_("%pB: bad symbol index: %d"),
1968 if (r_symndx
< symtab_hdr
->sh_info
)
1970 /* A local symbol. */
1971 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
1976 /* Check relocation against local STT_GNU_IFUNC symbol. */
1977 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1979 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1984 /* Fake a STT_GNU_IFUNC symbol. */
1985 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1987 h
->type
= STT_GNU_IFUNC
;
1990 h
->forced_local
= 1;
1991 h
->root
.type
= bfd_link_hash_defined
;
1999 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2000 while (h
->root
.type
== bfd_link_hash_indirect
2001 || h
->root
.type
== bfd_link_hash_warning
)
2002 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2005 /* Check invalid x32 relocations. */
2006 if (!ABI_64_P (abfd
))
2012 case R_X86_64_DTPOFF64
:
2013 case R_X86_64_TPOFF64
:
2015 case R_X86_64_GOTOFF64
:
2016 case R_X86_64_GOT64
:
2017 case R_X86_64_GOTPCREL64
:
2018 case R_X86_64_GOTPC64
:
2019 case R_X86_64_GOTPLT64
:
2020 case R_X86_64_PLTOFF64
:
2023 name
= h
->root
.root
.string
;
2025 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2028 /* xgettext:c-format */
2029 (_("%pB: relocation %s against symbol `%s' isn't "
2030 "supported in x32 mode"), abfd
,
2031 x86_64_elf_howto_table
[r_type
].name
, name
);
2032 bfd_set_error (bfd_error_bad_value
);
2038 eh
= (struct elf_x86_link_hash_entry
*) h
;
2042 /* It is referenced by a non-shared object. */
2046 converted_reloc
= false;
2047 if ((r_type
== R_X86_64_GOTPCREL
2048 || r_type
== R_X86_64_GOTPCRELX
2049 || r_type
== R_X86_64_REX_GOTPCRELX
)
2050 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2052 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
2053 if (!elf_x86_64_convert_load_reloc (abfd
, contents
, &r_type
,
2054 irel
, h
, &converted_reloc
,
2058 if (converted_reloc
)
2062 if (!_bfd_elf_x86_valid_reloc_p (sec
, info
, htab
, rel
, h
, isym
,
2063 symtab_hdr
, &no_dynreloc
))
2066 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2067 symtab_hdr
, sym_hashes
,
2068 &r_type
, GOT_UNKNOWN
,
2069 rel
, rel_end
, h
, r_symndx
, false))
2072 /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
2073 if (h
== htab
->elf
.hgot
)
2074 htab
->got_referenced
= true;
2078 case R_X86_64_TLSLD
:
2079 htab
->tls_ld_or_ldm_got
.refcount
= 1;
2082 case R_X86_64_TPOFF32
:
2083 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2084 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2085 &x86_64_elf_howto_table
[r_type
]);
2087 eh
->zero_undefweak
&= 0x2;
2090 case R_X86_64_GOTTPOFF
:
2091 if (!bfd_link_executable (info
))
2092 info
->flags
|= DF_STATIC_TLS
;
2095 case R_X86_64_GOT32
:
2096 case R_X86_64_GOTPCREL
:
2097 case R_X86_64_GOTPCRELX
:
2098 case R_X86_64_REX_GOTPCRELX
:
2099 case R_X86_64_TLSGD
:
2100 case R_X86_64_GOT64
:
2101 case R_X86_64_GOTPCREL64
:
2102 case R_X86_64_GOTPLT64
:
2103 case R_X86_64_GOTPC32_TLSDESC
:
2104 case R_X86_64_TLSDESC_CALL
:
2105 /* This symbol requires a global offset table entry. */
2107 int tls_type
, old_tls_type
;
2112 tls_type
= GOT_NORMAL
;
2115 if (ABS_SYMBOL_P (h
))
2118 else if (isym
->st_shndx
== SHN_ABS
)
2121 case R_X86_64_TLSGD
:
2122 tls_type
= GOT_TLS_GD
;
2124 case R_X86_64_GOTTPOFF
:
2125 tls_type
= GOT_TLS_IE
;
2127 case R_X86_64_GOTPC32_TLSDESC
:
2128 case R_X86_64_TLSDESC_CALL
:
2129 tls_type
= GOT_TLS_GDESC
;
2135 h
->got
.refcount
= 1;
2136 old_tls_type
= eh
->tls_type
;
2140 bfd_signed_vma
*local_got_refcounts
;
2142 if (!elf_x86_allocate_local_got_info (abfd
,
2143 symtab_hdr
->sh_info
))
2146 /* This is a global offset table entry for a local symbol. */
2147 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2148 local_got_refcounts
[r_symndx
] = 1;
2150 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2153 /* If a TLS symbol is accessed using IE at least once,
2154 there is no point to use dynamic model for it. */
2155 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2156 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2157 || tls_type
!= GOT_TLS_IE
))
2159 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2160 tls_type
= old_tls_type
;
2161 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2162 && GOT_TLS_GD_ANY_P (tls_type
))
2163 tls_type
|= old_tls_type
;
2167 name
= h
->root
.root
.string
;
2169 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2172 /* xgettext:c-format */
2173 (_("%pB: '%s' accessed both as normal and"
2174 " thread local symbol"),
2176 bfd_set_error (bfd_error_bad_value
);
2181 if (old_tls_type
!= tls_type
)
2184 eh
->tls_type
= tls_type
;
2186 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2191 case R_X86_64_GOTOFF64
:
2192 case R_X86_64_GOTPC32
:
2193 case R_X86_64_GOTPC64
:
2196 eh
->zero_undefweak
&= 0x2;
2199 case R_X86_64_PLT32
:
2200 case R_X86_64_PLT32_BND
:
2201 /* This symbol requires a procedure linkage table entry. We
2202 actually build the entry in adjust_dynamic_symbol,
2203 because this might be a case of linking PIC code which is
2204 never referenced by a dynamic object, in which case we
2205 don't need to generate a procedure linkage table entry
2208 /* If this is a local symbol, we resolve it directly without
2209 creating a procedure linkage table entry. */
2213 eh
->zero_undefweak
&= 0x2;
2215 h
->plt
.refcount
= 1;
2218 case R_X86_64_PLTOFF64
:
2219 /* This tries to form the 'address' of a function relative
2220 to GOT. For global symbols we need a PLT entry. */
2224 h
->plt
.refcount
= 1;
2228 case R_X86_64_SIZE32
:
2229 case R_X86_64_SIZE64
:
2234 if (!ABI_64_P (abfd
))
2240 /* Check relocation overflow as these relocs may lead to
2241 run-time relocation overflow. Don't error out for
2242 sections we don't care about, such as debug sections or
2243 when relocation overflow check is disabled. */
2244 if (!htab
->params
->no_reloc_overflow_check
2246 && (bfd_link_pic (info
)
2247 || (bfd_link_executable (info
)
2251 && (sec
->flags
& SEC_READONLY
) == 0)))
2252 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2253 &x86_64_elf_howto_table
[r_type
]);
2259 case R_X86_64_PC32_BND
:
2263 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2264 eh
->zero_undefweak
|= 0x2;
2265 /* We are called after all symbols have been resolved. Only
2266 relocation against STT_GNU_IFUNC symbol must go through
2269 && (bfd_link_executable (info
)
2270 || h
->type
== STT_GNU_IFUNC
))
2272 bool func_pointer_ref
= false;
2274 if (r_type
== R_X86_64_PC32
)
2276 /* Since something like ".long foo - ." may be used
2277 as pointer, make sure that PLT is used if foo is
2278 a function defined in a shared library. */
2279 if ((sec
->flags
& SEC_CODE
) == 0)
2281 h
->pointer_equality_needed
= 1;
2282 if (bfd_link_pie (info
)
2283 && h
->type
== STT_FUNC
2288 h
->plt
.refcount
= 1;
2292 else if (r_type
!= R_X86_64_PC32_BND
2293 && r_type
!= R_X86_64_PC64
)
2295 /* At run-time, R_X86_64_64 can be resolved for both
2296 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2297 can only be resolved for x32. Function pointer
2298 reference doesn't need PLT for pointer equality. */
2299 if ((sec
->flags
& SEC_READONLY
) == 0
2300 && (r_type
== R_X86_64_64
2301 || (!ABI_64_P (abfd
)
2302 && (r_type
== R_X86_64_32
2303 || r_type
== R_X86_64_32S
))))
2304 func_pointer_ref
= true;
2306 /* IFUNC symbol needs pointer equality in PDE so that
2307 function pointer reference will be resolved to its
2308 PLT entry directly. */
2309 if (!func_pointer_ref
2310 || (bfd_link_pde (info
)
2311 && h
->type
== STT_GNU_IFUNC
))
2312 h
->pointer_equality_needed
= 1;
2315 if (!func_pointer_ref
)
2317 /* If this reloc is in a read-only section, we might
2318 need a copy reloc. We can't check reliably at this
2319 stage whether the section is read-only, as input
2320 sections have not yet been mapped to output sections.
2321 Tentatively set the flag for now, and correct in
2322 adjust_dynamic_symbol. */
2325 if (!elf_has_indirect_extern_access (sec
->owner
))
2326 eh
->non_got_ref_without_indirect_extern_access
= 1;
2328 /* We may need a .plt entry if the symbol is a function
2329 defined in a shared lib or is a function referenced
2330 from the code or read-only section. */
2332 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2333 h
->plt
.refcount
= 1;
2335 if (htab
->elf
.target_os
!= is_solaris
2336 && h
->pointer_equality_needed
2337 && h
->type
== STT_FUNC
2338 && eh
->def_protected
2339 && !SYMBOL_DEFINED_NON_SHARED_P (h
)
2342 /* Disallow non-canonical reference to canonical
2343 protected function. */
2345 /* xgettext:c-format */
2346 (_("%pB: non-canonical reference to canonical "
2347 "protected function `%s' in %pB"),
2348 abfd
, h
->root
.root
.string
,
2349 h
->root
.u
.def
.section
->owner
);
2350 bfd_set_error (bfd_error_bad_value
);
2359 && NEED_DYNAMIC_RELOCATION_P (true, info
, true, h
, sec
,
2361 htab
->pointer_r_type
))
2363 struct elf_dyn_relocs
*p
;
2364 struct elf_dyn_relocs
**head
;
2366 /* If this is a global symbol, we count the number of
2367 relocations we need for this symbol. */
2369 head
= &h
->dyn_relocs
;
2372 /* Track dynamic relocs needed for local syms too.
2373 We really need local syms available to do this
2378 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2383 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2387 /* Beware of type punned pointers vs strict aliasing
2389 vpp
= &(elf_section_data (s
)->local_dynrel
);
2390 head
= (struct elf_dyn_relocs
**)vpp
;
2394 if (p
== NULL
|| p
->sec
!= sec
)
2396 size_t amt
= sizeof *p
;
2398 p
= ((struct elf_dyn_relocs
*)
2399 bfd_alloc (htab
->elf
.dynobj
, amt
));
2410 /* Count size relocation as PC-relative relocation. */
2411 if (X86_PCREL_TYPE_P (true, r_type
) || size_reloc
)
2416 /* This relocation describes the C++ object vtable hierarchy.
2417 Reconstruct it for later use during GC. */
2418 case R_X86_64_GNU_VTINHERIT
:
2419 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2423 /* This relocation describes which C++ vtable entries are actually
2424 used. Record for later use during GC. */
2425 case R_X86_64_GNU_VTENTRY
:
2426 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2435 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2437 if (!converted
&& !_bfd_link_keep_memory (info
))
2441 /* Cache the section contents for elf_link_input_bfd if any
2442 load is converted or --no-keep-memory isn't used. */
2443 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2444 info
->cache_size
+= sec
->size
;
2448 /* Cache relocations if any load is converted. */
2449 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
2450 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
2455 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2457 sec
->check_relocs_failed
= 1;
2462 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2463 struct bfd_link_info
*info
)
2467 /* Scan relocations after rel_from_abs has been set on __ehdr_start. */
2468 for (abfd
= info
->input_bfds
;
2469 abfd
!= (bfd
*) NULL
;
2470 abfd
= abfd
->link
.next
)
2471 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2472 && !_bfd_elf_link_iterate_on_relocs (abfd
, info
,
2473 elf_x86_64_scan_relocs
))
2476 return _bfd_x86_elf_always_size_sections (output_bfd
, info
);
2479 /* Return the relocation value for @tpoff relocation
2480 if STT_TLS virtual address is ADDRESS. */
2483 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2485 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2486 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2487 bfd_vma static_tls_size
;
2489 /* If tls_segment is NULL, we should have signalled an error already. */
2490 if (htab
->tls_sec
== NULL
)
2493 /* Consider special static TLS alignment requirements. */
2494 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2495 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2498 /* Relocate an x86_64 ELF section. */
2501 elf_x86_64_relocate_section (bfd
*output_bfd
,
2502 struct bfd_link_info
*info
,
2504 asection
*input_section
,
2506 Elf_Internal_Rela
*relocs
,
2507 Elf_Internal_Sym
*local_syms
,
2508 asection
**local_sections
)
2510 struct elf_x86_link_hash_table
*htab
;
2511 Elf_Internal_Shdr
*symtab_hdr
;
2512 struct elf_link_hash_entry
**sym_hashes
;
2513 bfd_vma
*local_got_offsets
;
2514 bfd_vma
*local_tlsdesc_gotents
;
2515 Elf_Internal_Rela
*rel
;
2516 Elf_Internal_Rela
*wrel
;
2517 Elf_Internal_Rela
*relend
;
2518 unsigned int plt_entry_size
;
2521 /* Skip if check_relocs or scan_relocs failed. */
2522 if (input_section
->check_relocs_failed
)
2525 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2529 if (!is_x86_elf (input_bfd
, htab
))
2531 bfd_set_error (bfd_error_wrong_format
);
2535 plt_entry_size
= htab
->plt
.plt_entry_size
;
2536 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2537 sym_hashes
= elf_sym_hashes (input_bfd
);
2538 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2539 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2541 _bfd_x86_elf_set_tls_module_base (info
);
2544 rel
= wrel
= relocs
;
2545 relend
= relocs
+ input_section
->reloc_count
;
2546 for (; rel
< relend
; wrel
++, rel
++)
2548 unsigned int r_type
, r_type_tls
;
2549 reloc_howto_type
*howto
;
2550 unsigned long r_symndx
;
2551 struct elf_link_hash_entry
*h
;
2552 struct elf_x86_link_hash_entry
*eh
;
2553 Elf_Internal_Sym
*sym
;
2555 bfd_vma off
, offplt
, plt_offset
;
2557 bool unresolved_reloc
;
2558 bfd_reloc_status_type r
;
2560 asection
*base_got
, *resolved_plt
;
2562 bool resolved_to_zero
;
2563 bool relative_reloc
;
2564 bool converted_reloc
;
2565 bool need_copy_reloc_in_pie
;
2566 bool no_copyreloc_p
;
2568 r_type
= ELF32_R_TYPE (rel
->r_info
);
2569 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2570 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2577 r_symndx
= htab
->r_sym (rel
->r_info
);
2578 converted_reloc
= (r_type
& R_X86_64_converted_reloc_bit
) != 0;
2579 if (converted_reloc
)
2581 r_type
&= ~R_X86_64_converted_reloc_bit
;
2582 rel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2585 howto
= elf_x86_64_rtype_to_howto (input_bfd
, r_type
);
2587 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2592 unresolved_reloc
= false;
2593 if (r_symndx
< symtab_hdr
->sh_info
)
2595 sym
= local_syms
+ r_symndx
;
2596 sec
= local_sections
[r_symndx
];
2598 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2600 st_size
= sym
->st_size
;
2602 /* Relocate against local STT_GNU_IFUNC symbol. */
2603 if (!bfd_link_relocatable (info
)
2604 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2606 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
2611 /* Set STT_GNU_IFUNC symbol value. */
2612 h
->root
.u
.def
.value
= sym
->st_value
;
2613 h
->root
.u
.def
.section
= sec
;
2618 bool warned ATTRIBUTE_UNUSED
;
2619 bool ignored ATTRIBUTE_UNUSED
;
2621 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2622 r_symndx
, symtab_hdr
, sym_hashes
,
2624 unresolved_reloc
, warned
, ignored
);
2628 if (sec
!= NULL
&& discarded_section (sec
))
2630 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2631 contents
, rel
->r_offset
);
2632 wrel
->r_offset
= rel
->r_offset
;
2636 /* For ld -r, remove relocations in debug sections against
2637 sections defined in discarded sections. Not done for
2638 eh_frame editing code expects to be present. */
2639 if (bfd_link_relocatable (info
)
2640 && (input_section
->flags
& SEC_DEBUGGING
))
2646 if (bfd_link_relocatable (info
))
2653 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
2655 if (r_type
== R_X86_64_64
)
2657 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2658 zero-extend it to 64bit if addend is zero. */
2659 r_type
= R_X86_64_32
;
2660 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2662 else if (r_type
== R_X86_64_SIZE64
)
2664 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2665 zero-extend it to 64bit if addend is zero. */
2666 r_type
= R_X86_64_SIZE32
;
2667 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2671 eh
= (struct elf_x86_link_hash_entry
*) h
;
2673 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2674 it here if it is defined in a non-shared object. */
2676 && h
->type
== STT_GNU_IFUNC
2682 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2684 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
2685 STT_GNU_IFUNC symbol as STT_FUNC. */
2686 if (elf_section_type (input_section
) == SHT_NOTE
)
2688 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2689 sections because such sections are not SEC_ALLOC and
2690 thus ld.so will not process them. */
2691 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2701 case R_X86_64_GOTPCREL
:
2702 case R_X86_64_GOTPCRELX
:
2703 case R_X86_64_REX_GOTPCRELX
:
2704 case R_X86_64_GOTPCREL64
:
2705 base_got
= htab
->elf
.sgot
;
2706 off
= h
->got
.offset
;
2708 if (base_got
== NULL
)
2711 if (off
== (bfd_vma
) -1)
2713 /* We can't use h->got.offset here to save state, or
2714 even just remember the offset, as finish_dynamic_symbol
2715 would use that as offset into .got. */
2717 if (h
->plt
.offset
== (bfd_vma
) -1)
2720 if (htab
->elf
.splt
!= NULL
)
2722 plt_index
= (h
->plt
.offset
/ plt_entry_size
2723 - htab
->plt
.has_plt0
);
2724 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2725 base_got
= htab
->elf
.sgotplt
;
2729 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2730 off
= plt_index
* GOT_ENTRY_SIZE
;
2731 base_got
= htab
->elf
.igotplt
;
2734 if (h
->dynindx
== -1
2738 /* This references the local defitionion. We must
2739 initialize this entry in the global offset table.
2740 Since the offset must always be a multiple of 8,
2741 we use the least significant bit to record
2742 whether we have initialized it already.
2744 When doing a dynamic link, we create a .rela.got
2745 relocation entry to initialize the value. This
2746 is done in the finish_dynamic_symbol routine. */
2751 bfd_put_64 (output_bfd
, relocation
,
2752 base_got
->contents
+ off
);
2753 /* Note that this is harmless for the GOTPLT64
2754 case, as -1 | 1 still is -1. */
2760 relocation
= (base_got
->output_section
->vma
2761 + base_got
->output_offset
+ off
);
2766 if (h
->plt
.offset
== (bfd_vma
) -1)
2768 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2769 if (r_type
== htab
->pointer_r_type
2770 && (input_section
->flags
& SEC_CODE
) == 0)
2771 goto do_ifunc_pointer
;
2772 goto bad_ifunc_reloc
;
2775 /* STT_GNU_IFUNC symbol must go through PLT. */
2776 if (htab
->elf
.splt
!= NULL
)
2778 if (htab
->plt_second
!= NULL
)
2780 resolved_plt
= htab
->plt_second
;
2781 plt_offset
= eh
->plt_second
.offset
;
2785 resolved_plt
= htab
->elf
.splt
;
2786 plt_offset
= h
->plt
.offset
;
2791 resolved_plt
= htab
->elf
.iplt
;
2792 plt_offset
= h
->plt
.offset
;
2795 relocation
= (resolved_plt
->output_section
->vma
2796 + resolved_plt
->output_offset
+ plt_offset
);
2802 if (h
->root
.root
.string
)
2803 name
= h
->root
.root
.string
;
2805 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2808 /* xgettext:c-format */
2809 (_("%pB: relocation %s against STT_GNU_IFUNC "
2810 "symbol `%s' isn't supported"), input_bfd
,
2812 bfd_set_error (bfd_error_bad_value
);
2816 if (bfd_link_pic (info
))
2821 if (ABI_64_P (output_bfd
))
2826 if (rel
->r_addend
!= 0)
2828 if (h
->root
.root
.string
)
2829 name
= h
->root
.root
.string
;
2831 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2834 /* xgettext:c-format */
2835 (_("%pB: relocation %s against STT_GNU_IFUNC "
2836 "symbol `%s' has non-zero addend: %" PRId64
),
2837 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
2838 bfd_set_error (bfd_error_bad_value
);
2842 /* Generate dynamic relcoation only when there is a
2843 non-GOT reference in a shared object or there is no
2845 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2846 || h
->plt
.offset
== (bfd_vma
) -1)
2848 Elf_Internal_Rela outrel
;
2851 /* Need a dynamic relocation to get the real function
2853 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2857 if (outrel
.r_offset
== (bfd_vma
) -1
2858 || outrel
.r_offset
== (bfd_vma
) -2)
2861 outrel
.r_offset
+= (input_section
->output_section
->vma
2862 + input_section
->output_offset
);
2864 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2866 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
2867 h
->root
.root
.string
,
2868 h
->root
.u
.def
.section
->owner
);
2870 /* This symbol is resolved locally. */
2871 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2872 outrel
.r_addend
= (h
->root
.u
.def
.value
2873 + h
->root
.u
.def
.section
->output_section
->vma
2874 + h
->root
.u
.def
.section
->output_offset
);
2876 if (htab
->params
->report_relative_reloc
)
2877 _bfd_x86_elf_link_report_relative_reloc
2878 (info
, input_section
, h
, sym
,
2879 "R_X86_64_IRELATIVE", &outrel
);
2883 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2884 outrel
.r_addend
= 0;
2887 /* Dynamic relocations are stored in
2888 1. .rela.ifunc section in PIC object.
2889 2. .rela.got section in dynamic executable.
2890 3. .rela.iplt section in static executable. */
2891 if (bfd_link_pic (info
))
2892 sreloc
= htab
->elf
.irelifunc
;
2893 else if (htab
->elf
.splt
!= NULL
)
2894 sreloc
= htab
->elf
.srelgot
;
2896 sreloc
= htab
->elf
.irelplt
;
2897 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2899 /* If this reloc is against an external symbol, we
2900 do not want to fiddle with the addend. Otherwise,
2901 we need to include the symbol value so that it
2902 becomes an addend for the dynamic reloc. For an
2903 internal symbol, we have updated addend. */
2908 case R_X86_64_PC32_BND
:
2910 case R_X86_64_PLT32
:
2911 case R_X86_64_PLT32_BND
:
2917 resolved_to_zero
= (eh
!= NULL
2918 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2920 /* When generating a shared object, the relocations handled here are
2921 copied into the output file to be resolved at run time. */
2924 case R_X86_64_GOT32
:
2925 case R_X86_64_GOT64
:
2926 /* Relocation is to the entry for this symbol in the global
2928 case R_X86_64_GOTPCREL
:
2929 case R_X86_64_GOTPCRELX
:
2930 case R_X86_64_REX_GOTPCRELX
:
2931 case R_X86_64_GOTPCREL64
:
2932 /* Use global offset table entry as symbol value. */
2933 case R_X86_64_GOTPLT64
:
2934 /* This is obsolete and treated the same as GOT64. */
2935 base_got
= htab
->elf
.sgot
;
2937 if (htab
->elf
.sgot
== NULL
)
2940 relative_reloc
= false;
2943 off
= h
->got
.offset
;
2945 && h
->plt
.offset
!= (bfd_vma
)-1
2946 && off
== (bfd_vma
)-1)
2948 /* We can't use h->got.offset here to save
2949 state, or even just remember the offset, as
2950 finish_dynamic_symbol would use that as offset into
2952 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
2953 - htab
->plt
.has_plt0
);
2954 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2955 base_got
= htab
->elf
.sgotplt
;
2958 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2960 /* We must initialize this entry in the global offset
2961 table. Since the offset must always be a multiple
2962 of 8, we use the least significant bit to record
2963 whether we have initialized it already.
2965 When doing a dynamic link, we create a .rela.got
2966 relocation entry to initialize the value. This is
2967 done in the finish_dynamic_symbol routine. */
2972 bfd_put_64 (output_bfd
, relocation
,
2973 base_got
->contents
+ off
);
2974 /* Note that this is harmless for the GOTPLT64 case,
2975 as -1 | 1 still is -1. */
2978 /* NB: Don't generate relative relocation here if
2979 it has been generated by DT_RELR. */
2980 if (!info
->enable_dt_relr
2981 && GENERATE_RELATIVE_RELOC_P (info
, h
))
2983 /* If this symbol isn't dynamic in PIC,
2984 generate R_X86_64_RELATIVE here. */
2985 eh
->no_finish_dynamic_symbol
= 1;
2986 relative_reloc
= true;
2991 unresolved_reloc
= false;
2995 if (local_got_offsets
== NULL
)
2998 off
= local_got_offsets
[r_symndx
];
3000 /* The offset must always be a multiple of 8. We use
3001 the least significant bit to record whether we have
3002 already generated the necessary reloc. */
3007 bfd_put_64 (output_bfd
, relocation
,
3008 base_got
->contents
+ off
);
3009 local_got_offsets
[r_symndx
] |= 1;
3011 /* NB: GOTPCREL relocations against local absolute
3012 symbol store relocation value in the GOT slot
3013 without relative relocation. Don't generate
3014 relative relocation here if it has been generated
3016 if (!info
->enable_dt_relr
3017 && bfd_link_pic (info
)
3018 && !(sym
->st_shndx
== SHN_ABS
3019 && (r_type
== R_X86_64_GOTPCREL
3020 || r_type
== R_X86_64_GOTPCRELX
3021 || r_type
== R_X86_64_REX_GOTPCRELX
)))
3022 relative_reloc
= true;
3029 Elf_Internal_Rela outrel
;
3031 /* We need to generate a R_X86_64_RELATIVE reloc
3032 for the dynamic linker. */
3033 s
= htab
->elf
.srelgot
;
3037 outrel
.r_offset
= (base_got
->output_section
->vma
3038 + base_got
->output_offset
3040 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3041 outrel
.r_addend
= relocation
;
3043 if (htab
->params
->report_relative_reloc
)
3044 _bfd_x86_elf_link_report_relative_reloc
3045 (info
, input_section
, h
, sym
, "R_X86_64_RELATIVE",
3048 elf_append_rela (output_bfd
, s
, &outrel
);
3051 if (off
>= (bfd_vma
) -2)
3054 relocation
= base_got
->output_section
->vma
3055 + base_got
->output_offset
+ off
;
3056 if (r_type
!= R_X86_64_GOTPCREL
3057 && r_type
!= R_X86_64_GOTPCRELX
3058 && r_type
!= R_X86_64_REX_GOTPCRELX
3059 && r_type
!= R_X86_64_GOTPCREL64
)
3060 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3061 - htab
->elf
.sgotplt
->output_offset
;
3065 case R_X86_64_GOTOFF64
:
3066 /* Relocation is relative to the start of the global offset
3069 /* Check to make sure it isn't a protected function or data
3070 symbol for shared library since it may not be local when
3071 used as function address or with copy relocation. We also
3072 need to make sure that a symbol is referenced locally. */
3073 if (bfd_link_pic (info
) && h
)
3075 if (!h
->def_regular
)
3079 switch (ELF_ST_VISIBILITY (h
->other
))
3082 v
= _("hidden symbol");
3085 v
= _("internal symbol");
3088 v
= _("protected symbol");
3096 /* xgettext:c-format */
3097 (_("%pB: relocation R_X86_64_GOTOFF64 against undefined %s"
3098 " `%s' can not be used when making a shared object"),
3099 input_bfd
, v
, h
->root
.root
.string
);
3100 bfd_set_error (bfd_error_bad_value
);
3103 else if (!bfd_link_executable (info
)
3104 && !SYMBOL_REFERENCES_LOCAL_P (info
, h
)
3105 && (h
->type
== STT_FUNC
3106 || h
->type
== STT_OBJECT
)
3107 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3110 /* xgettext:c-format */
3111 (_("%pB: relocation R_X86_64_GOTOFF64 against protected %s"
3112 " `%s' can not be used when making a shared object"),
3114 h
->type
== STT_FUNC
? "function" : "data",
3115 h
->root
.root
.string
);
3116 bfd_set_error (bfd_error_bad_value
);
3121 /* Note that sgot is not involved in this
3122 calculation. We always want the start of .got.plt. If we
3123 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3124 permitted by the ABI, we might have to change this
3126 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3127 + htab
->elf
.sgotplt
->output_offset
;
3130 case R_X86_64_GOTPC32
:
3131 case R_X86_64_GOTPC64
:
3132 /* Use global offset table as symbol value. */
3133 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3134 + htab
->elf
.sgotplt
->output_offset
;
3135 unresolved_reloc
= false;
3138 case R_X86_64_PLTOFF64
:
3139 /* Relocation is PLT entry relative to GOT. For local
3140 symbols it's the symbol itself relative to GOT. */
3142 /* See PLT32 handling. */
3143 && (h
->plt
.offset
!= (bfd_vma
) -1
3144 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
3145 && htab
->elf
.splt
!= NULL
)
3147 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3149 /* Use the GOT PLT. */
3150 resolved_plt
= htab
->plt_got
;
3151 plt_offset
= eh
->plt_got
.offset
;
3153 else if (htab
->plt_second
!= NULL
)
3155 resolved_plt
= htab
->plt_second
;
3156 plt_offset
= eh
->plt_second
.offset
;
3160 resolved_plt
= htab
->elf
.splt
;
3161 plt_offset
= h
->plt
.offset
;
3164 relocation
= (resolved_plt
->output_section
->vma
3165 + resolved_plt
->output_offset
3167 unresolved_reloc
= false;
3170 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3171 + htab
->elf
.sgotplt
->output_offset
;
3174 case R_X86_64_PLT32
:
3175 case R_X86_64_PLT32_BND
:
3176 /* Relocation is to the entry for this symbol in the
3177 procedure linkage table. */
3179 /* Resolve a PLT32 reloc against a local symbol directly,
3180 without using the procedure linkage table. */
3184 if ((h
->plt
.offset
== (bfd_vma
) -1
3185 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3186 || htab
->elf
.splt
== NULL
)
3188 /* We didn't make a PLT entry for this symbol. This
3189 happens when statically linking PIC code, or when
3190 using -Bsymbolic. */
3195 if (h
->plt
.offset
!= (bfd_vma
) -1)
3197 if (htab
->plt_second
!= NULL
)
3199 resolved_plt
= htab
->plt_second
;
3200 plt_offset
= eh
->plt_second
.offset
;
3204 resolved_plt
= htab
->elf
.splt
;
3205 plt_offset
= h
->plt
.offset
;
3210 /* Use the GOT PLT. */
3211 resolved_plt
= htab
->plt_got
;
3212 plt_offset
= eh
->plt_got
.offset
;
3215 relocation
= (resolved_plt
->output_section
->vma
3216 + resolved_plt
->output_offset
3218 unresolved_reloc
= false;
3221 case R_X86_64_SIZE32
:
3222 case R_X86_64_SIZE64
:
3223 /* Set to symbol size. */
3224 relocation
= st_size
;
3230 case R_X86_64_PC32_BND
:
3231 /* Don't complain about -fPIC if the symbol is undefined when
3232 building executable unless it is unresolved weak symbol,
3233 references a dynamic definition in PIE or -z nocopyreloc
3236 = (info
->nocopyreloc
3238 && !h
->root
.linker_def
3239 && !h
->root
.ldscript_def
3240 && eh
->def_protected
));
3242 if ((input_section
->flags
& SEC_ALLOC
) != 0
3243 && (input_section
->flags
& SEC_READONLY
) != 0
3245 && ((bfd_link_executable (info
)
3246 && ((h
->root
.type
== bfd_link_hash_undefweak
3248 || !UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3250 || (bfd_link_pie (info
)
3251 && !SYMBOL_DEFINED_NON_SHARED_P (h
)
3255 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
3256 || (bfd_link_pie (info
)
3257 && h
->root
.type
== bfd_link_hash_undefweak
)
3258 || bfd_link_dll (info
)))
3261 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3263 /* Symbol is referenced locally. Make sure it is
3265 fail
= !SYMBOL_DEFINED_NON_SHARED_P (h
);
3267 else if (bfd_link_pie (info
))
3269 /* We can only use PC-relative relocations in PIE
3270 from non-code sections. */
3271 if (h
->root
.type
== bfd_link_hash_undefweak
3272 || (h
->type
== STT_FUNC
3273 && (sec
->flags
& SEC_CODE
) != 0))
3276 else if (no_copyreloc_p
|| bfd_link_dll (info
))
3278 /* Symbol doesn't need copy reloc and isn't
3279 referenced locally. Don't allow PC-relative
3280 relocations against default and protected
3281 symbols since address of protected function
3282 and location of protected data may not be in
3283 the shared object. */
3284 fail
= (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3285 || ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
);
3289 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3290 h
, NULL
, NULL
, howto
);
3292 /* Since x86-64 has PC-relative PLT, we can use PLT in PIE
3293 as function address. */
3295 && (input_section
->flags
& SEC_CODE
) == 0
3296 && bfd_link_pie (info
)
3297 && h
->type
== STT_FUNC
3308 /* FIXME: The ABI says the linker should make sure the value is
3309 the same when it's zeroextended to 64 bit. */
3312 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3315 need_copy_reloc_in_pie
= (bfd_link_pie (info
)
3320 == bfd_link_hash_undefined
))
3321 && (X86_PCREL_TYPE_P (true, r_type
)
3322 || X86_SIZE_TYPE_P (true,
3325 if (GENERATE_DYNAMIC_RELOCATION_P (true, info
, eh
, r_type
, sec
,
3326 need_copy_reloc_in_pie
,
3327 resolved_to_zero
, false))
3329 Elf_Internal_Rela outrel
;
3330 bool skip
, relocate
;
3331 bool generate_dynamic_reloc
= true;
3333 const char *relative_reloc_name
= NULL
;
3335 /* When generating a shared object, these relocations
3336 are copied into the output file to be resolved at run
3342 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3344 if (outrel
.r_offset
== (bfd_vma
) -1)
3346 else if (outrel
.r_offset
== (bfd_vma
) -2)
3347 skip
= true, relocate
= true;
3349 outrel
.r_offset
+= (input_section
->output_section
->vma
3350 + input_section
->output_offset
);
3353 memset (&outrel
, 0, sizeof outrel
);
3355 else if (COPY_INPUT_RELOC_P (true, info
, h
, r_type
))
3357 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3358 outrel
.r_addend
= rel
->r_addend
;
3362 /* This symbol is local, or marked to become local.
3363 When relocation overflow check is disabled, we
3364 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3365 if (r_type
== htab
->pointer_r_type
3366 || (r_type
== R_X86_64_32
3367 && htab
->params
->no_reloc_overflow_check
))
3370 /* NB: Don't generate relative relocation here if
3371 it has been generated by DT_RELR. */
3372 if (info
->enable_dt_relr
)
3373 generate_dynamic_reloc
= false;
3377 htab
->r_info (0, R_X86_64_RELATIVE
);
3378 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3379 relative_reloc_name
= "R_X86_64_RELATIVE";
3382 else if (r_type
== R_X86_64_64
3383 && !ABI_64_P (output_bfd
))
3386 outrel
.r_info
= htab
->r_info (0,
3387 R_X86_64_RELATIVE64
);
3388 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3389 relative_reloc_name
= "R_X86_64_RELATIVE64";
3390 /* Check addend overflow. */
3391 if ((outrel
.r_addend
& 0x80000000)
3392 != (rel
->r_addend
& 0x80000000))
3395 int addend
= rel
->r_addend
;
3396 if (h
&& h
->root
.root
.string
)
3397 name
= h
->root
.root
.string
;
3399 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3402 /* xgettext:c-format */
3403 (_("%pB: addend %s%#x in relocation %s against "
3404 "symbol `%s' at %#" PRIx64
3405 " in section `%pA' is out of range"),
3406 input_bfd
, addend
< 0 ? "-" : "", addend
,
3407 howto
->name
, name
, (uint64_t) rel
->r_offset
,
3409 bfd_set_error (bfd_error_bad_value
);
3417 if (bfd_is_abs_section (sec
))
3419 else if (sec
== NULL
|| sec
->owner
== NULL
)
3421 bfd_set_error (bfd_error_bad_value
);
3428 /* We are turning this relocation into one
3429 against a section symbol. It would be
3430 proper to subtract the symbol's value,
3431 osec->vma, from the emitted reloc addend,
3432 but ld.so expects buggy relocs. */
3433 osec
= sec
->output_section
;
3434 sindx
= elf_section_data (osec
)->dynindx
;
3437 asection
*oi
= htab
->elf
.text_index_section
;
3438 sindx
= elf_section_data (oi
)->dynindx
;
3440 BFD_ASSERT (sindx
!= 0);
3443 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3444 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3448 if (generate_dynamic_reloc
)
3450 sreloc
= elf_section_data (input_section
)->sreloc
;
3452 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3454 r
= bfd_reloc_notsupported
;
3455 goto check_relocation_error
;
3458 if (relative_reloc_name
3459 && htab
->params
->report_relative_reloc
)
3460 _bfd_x86_elf_link_report_relative_reloc
3461 (info
, input_section
, h
, sym
,
3462 relative_reloc_name
, &outrel
);
3464 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3467 /* If this reloc is against an external symbol, we do
3468 not want to fiddle with the addend. Otherwise, we
3469 need to include the symbol value so that it becomes
3470 an addend for the dynamic reloc. */
3477 case R_X86_64_TLSGD
:
3478 case R_X86_64_GOTPC32_TLSDESC
:
3479 case R_X86_64_TLSDESC_CALL
:
3480 case R_X86_64_GOTTPOFF
:
3481 tls_type
= GOT_UNKNOWN
;
3482 if (h
== NULL
&& local_got_offsets
)
3483 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3485 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
3487 r_type_tls
= r_type
;
3488 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3489 input_section
, contents
,
3490 symtab_hdr
, sym_hashes
,
3491 &r_type_tls
, tls_type
, rel
,
3492 relend
, h
, r_symndx
, true))
3495 if (r_type_tls
== R_X86_64_TPOFF32
)
3497 bfd_vma roff
= rel
->r_offset
;
3499 BFD_ASSERT (! unresolved_reloc
);
3501 if (r_type
== R_X86_64_TLSGD
)
3503 /* GD->LE transition. For 64bit, change
3504 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3505 .word 0x6666; rex64; call __tls_get_addr@PLT
3507 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3509 call *__tls_get_addr@GOTPCREL(%rip)
3510 which may be converted to
3511 addr32 call __tls_get_addr
3514 leaq foo@tpoff(%rax), %rax
3516 leaq foo@tlsgd(%rip), %rdi
3517 .word 0x6666; rex64; call __tls_get_addr@PLT
3519 leaq foo@tlsgd(%rip), %rdi
3521 call *__tls_get_addr@GOTPCREL(%rip)
3522 which may be converted to
3523 addr32 call __tls_get_addr
3526 leaq foo@tpoff(%rax), %rax
3527 For largepic, change:
3528 leaq foo@tlsgd(%rip), %rdi
3529 movabsq $__tls_get_addr@pltoff, %rax
3534 leaq foo@tpoff(%rax), %rax
3535 nopw 0x0(%rax,%rax,1) */
3537 if (ABI_64_P (output_bfd
))
3539 if (contents
[roff
+ 5] == 0xb8)
3542 || (roff
- 3 + 22) > input_section
->size
)
3545 info
->callbacks
->einfo
3546 (_("%F%P: corrupt input: %pB\n"),
3550 memcpy (contents
+ roff
- 3,
3551 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3552 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3558 || (roff
- 4 + 16) > input_section
->size
)
3560 memcpy (contents
+ roff
- 4,
3561 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3568 || (roff
- 3 + 15) > input_section
->size
)
3570 memcpy (contents
+ roff
- 3,
3571 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3574 bfd_put_32 (output_bfd
,
3575 elf_x86_64_tpoff (info
, relocation
),
3576 contents
+ roff
+ 8 + largepic
);
3577 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3578 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3583 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3585 /* GDesc -> LE transition.
3586 It's originally something like:
3587 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3588 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3591 movq $x@tpoff, %rax <--- LP64 mode.
3592 rex movl $x@tpoff, %eax <--- X32 mode.
3595 unsigned int val
, type
;
3599 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3600 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3601 bfd_put_8 (output_bfd
,
3602 (type
& 0x48) | ((type
>> 2) & 1),
3603 contents
+ roff
- 3);
3604 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3605 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3606 contents
+ roff
- 1);
3607 bfd_put_32 (output_bfd
,
3608 elf_x86_64_tpoff (info
, relocation
),
3612 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3614 /* GDesc -> LE transition.
3616 call *(%rax) <--- LP64 mode.
3617 call *(%eax) <--- X32 mode.
3619 xchg %ax,%ax <-- LP64 mode.
3620 nopl (%rax) <-- X32 mode.
3622 unsigned int prefix
= 0;
3623 if (!ABI_64_P (input_bfd
))
3625 /* Check for call *x@tlsdesc(%eax). */
3626 if (contents
[roff
] == 0x67)
3631 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
3632 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
3633 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
3637 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3638 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3642 else if (r_type
== R_X86_64_GOTTPOFF
)
3644 /* IE->LE transition:
3645 For 64bit, originally it can be one of:
3646 movq foo@gottpoff(%rip), %reg
3647 addq foo@gottpoff(%rip), %reg
3650 leaq foo(%reg), %reg
3652 For 32bit, originally it can be one of:
3653 movq foo@gottpoff(%rip), %reg
3654 addl foo@gottpoff(%rip), %reg
3657 leal foo(%reg), %reg
3660 unsigned int val
, type
, reg
;
3663 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3670 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3671 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3680 bfd_put_8 (output_bfd
, 0x49,
3681 contents
+ roff
- 3);
3683 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3687 bfd_put_8 (output_bfd
, 0x41,
3688 contents
+ roff
- 3);
3690 bfd_put_8 (output_bfd
, 0xc7,
3691 contents
+ roff
- 2);
3692 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3693 contents
+ roff
- 1);
3697 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3703 bfd_put_8 (output_bfd
, 0x49,
3704 contents
+ roff
- 3);
3706 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3710 bfd_put_8 (output_bfd
, 0x41,
3711 contents
+ roff
- 3);
3713 bfd_put_8 (output_bfd
, 0x81,
3714 contents
+ roff
- 2);
3715 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3716 contents
+ roff
- 1);
3720 /* addq/addl -> leaq/leal */
3725 bfd_put_8 (output_bfd
, 0x4d,
3726 contents
+ roff
- 3);
3728 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3732 bfd_put_8 (output_bfd
, 0x45,
3733 contents
+ roff
- 3);
3735 bfd_put_8 (output_bfd
, 0x8d,
3736 contents
+ roff
- 2);
3737 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3738 contents
+ roff
- 1);
3740 bfd_put_32 (output_bfd
,
3741 elf_x86_64_tpoff (info
, relocation
),
3749 if (htab
->elf
.sgot
== NULL
)
3754 off
= h
->got
.offset
;
3755 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3759 if (local_got_offsets
== NULL
)
3762 off
= local_got_offsets
[r_symndx
];
3763 offplt
= local_tlsdesc_gotents
[r_symndx
];
3770 Elf_Internal_Rela outrel
;
3774 if (htab
->elf
.srelgot
== NULL
)
3777 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3779 if (GOT_TLS_GDESC_P (tls_type
))
3781 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3782 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3783 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3784 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3785 + htab
->elf
.sgotplt
->output_offset
3787 + htab
->sgotplt_jump_table_size
);
3788 sreloc
= htab
->elf
.srelplt
;
3790 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3792 outrel
.r_addend
= 0;
3793 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3796 sreloc
= htab
->elf
.srelgot
;
3798 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3799 + htab
->elf
.sgot
->output_offset
+ off
);
3801 if (GOT_TLS_GD_P (tls_type
))
3802 dr_type
= R_X86_64_DTPMOD64
;
3803 else if (GOT_TLS_GDESC_P (tls_type
))
3806 dr_type
= R_X86_64_TPOFF64
;
3808 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3809 outrel
.r_addend
= 0;
3810 if ((dr_type
== R_X86_64_TPOFF64
3811 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3812 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3813 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3815 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3817 if (GOT_TLS_GD_P (tls_type
))
3821 BFD_ASSERT (! unresolved_reloc
);
3822 bfd_put_64 (output_bfd
,
3823 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3824 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3828 bfd_put_64 (output_bfd
, 0,
3829 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3830 outrel
.r_info
= htab
->r_info (indx
,
3832 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3833 elf_append_rela (output_bfd
, sreloc
,
3842 local_got_offsets
[r_symndx
] |= 1;
3845 if (off
>= (bfd_vma
) -2
3846 && ! GOT_TLS_GDESC_P (tls_type
))
3848 if (r_type_tls
== r_type
)
3850 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3851 || r_type
== R_X86_64_TLSDESC_CALL
)
3852 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3853 + htab
->elf
.sgotplt
->output_offset
3854 + offplt
+ htab
->sgotplt_jump_table_size
;
3856 relocation
= htab
->elf
.sgot
->output_section
->vma
3857 + htab
->elf
.sgot
->output_offset
+ off
;
3858 unresolved_reloc
= false;
3862 bfd_vma roff
= rel
->r_offset
;
3864 if (r_type
== R_X86_64_TLSGD
)
3866 /* GD->IE transition. For 64bit, change
3867 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3868 .word 0x6666; rex64; call __tls_get_addr@PLT
3870 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3872 call *__tls_get_addr@GOTPCREL(%rip
3873 which may be converted to
3874 addr32 call __tls_get_addr
3877 addq foo@gottpoff(%rip), %rax
3879 leaq foo@tlsgd(%rip), %rdi
3880 .word 0x6666; rex64; call __tls_get_addr@PLT
3882 leaq foo@tlsgd(%rip), %rdi
3884 call *__tls_get_addr@GOTPCREL(%rip)
3885 which may be converted to
3886 addr32 call __tls_get_addr
3889 addq foo@gottpoff(%rip), %rax
3890 For largepic, change:
3891 leaq foo@tlsgd(%rip), %rdi
3892 movabsq $__tls_get_addr@pltoff, %rax
3897 addq foo@gottpoff(%rax), %rax
3898 nopw 0x0(%rax,%rax,1) */
3900 if (ABI_64_P (output_bfd
))
3902 if (contents
[roff
+ 5] == 0xb8)
3905 || (roff
- 3 + 22) > input_section
->size
)
3907 memcpy (contents
+ roff
- 3,
3908 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3909 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3915 || (roff
- 4 + 16) > input_section
->size
)
3917 memcpy (contents
+ roff
- 4,
3918 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3925 || (roff
- 3 + 15) > input_section
->size
)
3927 memcpy (contents
+ roff
- 3,
3928 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3932 relocation
= (htab
->elf
.sgot
->output_section
->vma
3933 + htab
->elf
.sgot
->output_offset
+ off
3936 - input_section
->output_section
->vma
3937 - input_section
->output_offset
3939 bfd_put_32 (output_bfd
, relocation
,
3940 contents
+ roff
+ 8 + largepic
);
3941 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3946 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3948 /* GDesc -> IE transition.
3949 It's originally something like:
3950 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3951 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3954 # before xchg %ax,%ax in LP64 mode.
3955 movq x@gottpoff(%rip), %rax
3956 # before nopl (%rax) in X32 mode.
3957 rex movl x@gottpoff(%rip), %eax
3960 /* Now modify the instruction as appropriate. To
3961 turn a lea into a mov in the form we use it, it
3962 suffices to change the second byte from 0x8d to
3966 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3968 bfd_put_32 (output_bfd
,
3969 htab
->elf
.sgot
->output_section
->vma
3970 + htab
->elf
.sgot
->output_offset
+ off
3972 - input_section
->output_section
->vma
3973 - input_section
->output_offset
3978 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3980 /* GDesc -> IE transition.
3982 call *(%rax) <--- LP64 mode.
3983 call *(%eax) <--- X32 mode.
3986 xchg %ax, %ax <-- LP64 mode.
3987 nopl (%rax) <-- X32 mode.
3990 unsigned int prefix
= 0;
3991 if (!ABI_64_P (input_bfd
))
3993 /* Check for call *x@tlsdesc(%eax). */
3994 if (contents
[roff
] == 0x67)
3999 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
4000 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
4001 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
4005 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4006 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4015 case R_X86_64_TLSLD
:
4016 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4017 input_section
, contents
,
4018 symtab_hdr
, sym_hashes
,
4019 &r_type
, GOT_UNKNOWN
, rel
,
4020 relend
, h
, r_symndx
, true))
4023 if (r_type
!= R_X86_64_TLSLD
)
4025 /* LD->LE transition:
4026 leaq foo@tlsld(%rip), %rdi
4027 call __tls_get_addr@PLT
4028 For 64bit, we change it into:
4029 .word 0x6666; .byte 0x66; movq %fs:0, %rax
4030 For 32bit, we change it into:
4031 nopl 0x0(%rax); movl %fs:0, %eax
4033 leaq foo@tlsld(%rip), %rdi;
4034 call *__tls_get_addr@GOTPCREL(%rip)
4035 which may be converted to
4036 addr32 call __tls_get_addr
4037 For 64bit, we change it into:
4038 .word 0x6666; .word 0x6666; movq %fs:0, %rax
4039 For 32bit, we change it into:
4040 nopw 0x0(%rax); movl %fs:0, %eax
4041 For largepic, change:
4042 leaq foo@tlsgd(%rip), %rdi
4043 movabsq $__tls_get_addr@pltoff, %rax
4047 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
4050 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4051 if (ABI_64_P (output_bfd
))
4053 if ((rel
->r_offset
+ 5) >= input_section
->size
)
4055 if (contents
[rel
->r_offset
+ 5] == 0xb8)
4057 if (rel
->r_offset
< 3
4058 || (rel
->r_offset
- 3 + 22) > input_section
->size
)
4060 memcpy (contents
+ rel
->r_offset
- 3,
4061 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
4062 "\x64\x48\x8b\x04\x25\0\0\0", 22);
4064 else if (contents
[rel
->r_offset
+ 4] == 0xff
4065 || contents
[rel
->r_offset
+ 4] == 0x67)
4067 if (rel
->r_offset
< 3
4068 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
4070 memcpy (contents
+ rel
->r_offset
- 3,
4071 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
4077 if (rel
->r_offset
< 3
4078 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
4080 memcpy (contents
+ rel
->r_offset
- 3,
4081 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4086 if ((rel
->r_offset
+ 4) >= input_section
->size
)
4088 if (contents
[rel
->r_offset
+ 4] == 0xff)
4090 if (rel
->r_offset
< 3
4091 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
4093 memcpy (contents
+ rel
->r_offset
- 3,
4094 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
4099 if (rel
->r_offset
< 3
4100 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
4102 memcpy (contents
+ rel
->r_offset
- 3,
4103 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4106 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
4107 and R_X86_64_PLTOFF64. */
4113 if (htab
->elf
.sgot
== NULL
)
4116 off
= htab
->tls_ld_or_ldm_got
.offset
;
4121 Elf_Internal_Rela outrel
;
4123 if (htab
->elf
.srelgot
== NULL
)
4126 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4127 + htab
->elf
.sgot
->output_offset
+ off
);
4129 bfd_put_64 (output_bfd
, 0,
4130 htab
->elf
.sgot
->contents
+ off
);
4131 bfd_put_64 (output_bfd
, 0,
4132 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4133 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4134 outrel
.r_addend
= 0;
4135 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4137 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4139 relocation
= htab
->elf
.sgot
->output_section
->vma
4140 + htab
->elf
.sgot
->output_offset
+ off
;
4141 unresolved_reloc
= false;
4144 case R_X86_64_DTPOFF32
:
4145 if (!bfd_link_executable (info
)
4146 || (input_section
->flags
& SEC_CODE
) == 0)
4147 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4149 relocation
= elf_x86_64_tpoff (info
, relocation
);
4152 case R_X86_64_TPOFF32
:
4153 case R_X86_64_TPOFF64
:
4154 BFD_ASSERT (bfd_link_executable (info
));
4155 relocation
= elf_x86_64_tpoff (info
, relocation
);
4158 case R_X86_64_DTPOFF64
:
4159 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
4160 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4167 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4168 because such sections are not SEC_ALLOC and thus ld.so will
4169 not process them. */
4170 if (unresolved_reloc
4171 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4173 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4174 rel
->r_offset
) != (bfd_vma
) -1)
4179 sec
= h
->root
.u
.def
.section
;
4180 if ((info
->nocopyreloc
|| eh
->def_protected
)
4181 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
4182 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
4183 h
, NULL
, NULL
, howto
);
4188 /* xgettext:c-format */
4189 (_("%pB(%pA+%#" PRIx64
"): "
4190 "unresolvable %s relocation against symbol `%s'"),
4193 (uint64_t) rel
->r_offset
,
4195 h
->root
.root
.string
);
4201 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4202 contents
, rel
->r_offset
,
4203 relocation
, rel
->r_addend
);
4205 check_relocation_error
:
4206 if (r
!= bfd_reloc_ok
)
4211 name
= h
->root
.root
.string
;
4214 name
= bfd_elf_string_from_elf_section (input_bfd
,
4215 symtab_hdr
->sh_link
,
4220 name
= bfd_section_name (sec
);
4223 if (r
== bfd_reloc_overflow
)
4225 if (converted_reloc
)
4227 info
->callbacks
->einfo
4228 ("%X%H:", input_bfd
, input_section
, rel
->r_offset
);
4229 info
->callbacks
->einfo
4230 (_(" failed to convert GOTPCREL relocation against "
4231 "'%s'; relink with --no-relax\n"),
4236 (*info
->callbacks
->reloc_overflow
)
4237 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4238 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4243 /* xgettext:c-format */
4244 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
4245 input_bfd
, input_section
,
4246 (uint64_t) rel
->r_offset
, name
, (int) r
);
4257 Elf_Internal_Shdr
*rel_hdr
;
4258 size_t deleted
= rel
- wrel
;
4260 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4261 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4262 if (rel_hdr
->sh_size
== 0)
4264 /* It is too late to remove an empty reloc section. Leave
4266 ??? What is wrong with an empty section??? */
4267 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4270 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4271 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4272 input_section
->reloc_count
-= deleted
;
4278 /* Finish up dynamic symbol handling. We set the contents of various
4279 dynamic sections here. */
4282 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4283 struct bfd_link_info
*info
,
4284 struct elf_link_hash_entry
*h
,
4285 Elf_Internal_Sym
*sym
)
4287 struct elf_x86_link_hash_table
*htab
;
4288 bool use_plt_second
;
4289 struct elf_x86_link_hash_entry
*eh
;
4290 bool local_undefweak
;
4292 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4296 /* Use the second PLT section only if there is .plt section. */
4297 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
4299 eh
= (struct elf_x86_link_hash_entry
*) h
;
4300 if (eh
->no_finish_dynamic_symbol
)
4303 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4304 resolved undefined weak symbols in executable so that their
4305 references have value 0 at run-time. */
4306 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
4308 if (h
->plt
.offset
!= (bfd_vma
) -1)
4311 bfd_vma got_offset
, plt_offset
;
4312 Elf_Internal_Rela rela
;
4314 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
4315 const struct elf_backend_data
*bed
;
4316 bfd_vma plt_got_pcrel_offset
;
4318 /* When building a static executable, use .iplt, .igot.plt and
4319 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4320 if (htab
->elf
.splt
!= NULL
)
4322 plt
= htab
->elf
.splt
;
4323 gotplt
= htab
->elf
.sgotplt
;
4324 relplt
= htab
->elf
.srelplt
;
4328 plt
= htab
->elf
.iplt
;
4329 gotplt
= htab
->elf
.igotplt
;
4330 relplt
= htab
->elf
.irelplt
;
4333 VERIFY_PLT_ENTRY (info
, h
, plt
, gotplt
, relplt
, local_undefweak
)
4335 /* Get the index in the procedure linkage table which
4336 corresponds to this symbol. This is the index of this symbol
4337 in all the symbols for which we are making plt entries. The
4338 first entry in the procedure linkage table is reserved.
4340 Get the offset into the .got table of the entry that
4341 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4342 bytes. The first three are reserved for the dynamic linker.
4344 For static executables, we don't reserve anything. */
4346 if (plt
== htab
->elf
.splt
)
4348 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
4349 - htab
->plt
.has_plt0
);
4350 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4354 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
4355 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4358 /* Fill in the entry in the procedure linkage table. */
4359 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4360 htab
->plt
.plt_entry_size
);
4363 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4364 htab
->non_lazy_plt
->plt_entry
,
4365 htab
->non_lazy_plt
->plt_entry_size
);
4367 resolved_plt
= htab
->plt_second
;
4368 plt_offset
= eh
->plt_second
.offset
;
4373 plt_offset
= h
->plt
.offset
;
4376 /* Insert the relocation positions of the plt section. */
4378 /* Put offset the PC-relative instruction referring to the GOT entry,
4379 subtracting the size of that instruction. */
4380 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
4381 + gotplt
->output_offset
4383 - resolved_plt
->output_section
->vma
4384 - resolved_plt
->output_offset
4386 - htab
->plt
.plt_got_insn_size
);
4388 /* Check PC-relative offset overflow in PLT entry. */
4389 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
4390 /* xgettext:c-format */
4391 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in PLT entry for `%s'\n"),
4392 output_bfd
, h
->root
.root
.string
);
4394 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
4395 (resolved_plt
->contents
+ plt_offset
4396 + htab
->plt
.plt_got_offset
));
4398 /* Fill in the entry in the global offset table, initially this
4399 points to the second part of the PLT entry. Leave the entry
4400 as zero for undefined weak symbol in PIE. No PLT relocation
4401 against undefined weak symbol in PIE. */
4402 if (!local_undefweak
)
4404 if (htab
->plt
.has_plt0
)
4405 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4406 + plt
->output_offset
4408 + htab
->lazy_plt
->plt_lazy_offset
),
4409 gotplt
->contents
+ got_offset
);
4411 /* Fill in the entry in the .rela.plt section. */
4412 rela
.r_offset
= (gotplt
->output_section
->vma
4413 + gotplt
->output_offset
4415 if (PLT_LOCAL_IFUNC_P (info
, h
))
4417 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4418 h
->root
.root
.string
,
4419 h
->root
.u
.def
.section
->owner
);
4421 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4422 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4423 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4424 rela
.r_addend
= (h
->root
.u
.def
.value
4425 + h
->root
.u
.def
.section
->output_section
->vma
4426 + h
->root
.u
.def
.section
->output_offset
);
4428 if (htab
->params
->report_relative_reloc
)
4429 _bfd_x86_elf_link_report_relative_reloc
4430 (info
, relplt
, h
, sym
, "R_X86_64_IRELATIVE", &rela
);
4432 /* R_X86_64_IRELATIVE comes last. */
4433 plt_index
= htab
->next_irelative_index
--;
4437 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4439 plt_index
= htab
->next_jump_slot_index
++;
4442 /* Don't fill the second and third slots in PLT entry for
4443 static executables nor without PLT0. */
4444 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4447 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
4449 /* Put relocation index. */
4450 bfd_put_32 (output_bfd
, plt_index
,
4451 (plt
->contents
+ h
->plt
.offset
4452 + htab
->lazy_plt
->plt_reloc_offset
));
4454 /* Put offset for jmp .PLT0 and check for overflow. We don't
4455 check relocation index for overflow since branch displacement
4456 will overflow first. */
4457 if (plt0_offset
> 0x80000000)
4458 /* xgettext:c-format */
4459 info
->callbacks
->einfo (_("%F%pB: branch displacement overflow in PLT entry for `%s'\n"),
4460 output_bfd
, h
->root
.root
.string
);
4461 bfd_put_32 (output_bfd
, - plt0_offset
,
4462 (plt
->contents
+ h
->plt
.offset
4463 + htab
->lazy_plt
->plt_plt_offset
));
4466 bed
= get_elf_backend_data (output_bfd
);
4467 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4468 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4471 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4473 bfd_vma got_offset
, plt_offset
;
4474 asection
*plt
, *got
;
4476 int32_t got_pcrel_offset
;
4478 /* Set the entry in the GOT procedure linkage table. */
4479 plt
= htab
->plt_got
;
4480 got
= htab
->elf
.sgot
;
4481 got_offset
= h
->got
.offset
;
4483 if (got_offset
== (bfd_vma
) -1
4484 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
4489 /* Use the non-lazy PLT entry template for the GOT PLT since they
4490 are the identical. */
4491 /* Fill in the entry in the GOT procedure linkage table. */
4492 plt_offset
= eh
->plt_got
.offset
;
4493 memcpy (plt
->contents
+ plt_offset
,
4494 htab
->non_lazy_plt
->plt_entry
,
4495 htab
->non_lazy_plt
->plt_entry_size
);
4497 /* Put offset the PC-relative instruction referring to the GOT
4498 entry, subtracting the size of that instruction. */
4499 got_pcrel_offset
= (got
->output_section
->vma
4500 + got
->output_offset
4502 - plt
->output_section
->vma
4503 - plt
->output_offset
4505 - htab
->non_lazy_plt
->plt_got_insn_size
);
4507 /* Check PC-relative offset overflow in GOT PLT entry. */
4508 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
4509 if ((got_after_plt
&& got_pcrel_offset
< 0)
4510 || (!got_after_plt
&& got_pcrel_offset
> 0))
4511 /* xgettext:c-format */
4512 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4513 output_bfd
, h
->root
.root
.string
);
4515 bfd_put_32 (output_bfd
, got_pcrel_offset
,
4516 (plt
->contents
+ plt_offset
4517 + htab
->non_lazy_plt
->plt_got_offset
));
4520 if (!local_undefweak
4522 && (h
->plt
.offset
!= (bfd_vma
) -1
4523 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4525 /* Mark the symbol as undefined, rather than as defined in
4526 the .plt section. Leave the value if there were any
4527 relocations where pointer equality matters (this is a clue
4528 for the dynamic linker, to make function pointer
4529 comparisons work between an application and shared
4530 library), otherwise set it to zero. If a function is only
4531 called from a binary, there is no need to slow down
4532 shared libraries because of that. */
4533 sym
->st_shndx
= SHN_UNDEF
;
4534 if (!h
->pointer_equality_needed
)
4538 _bfd_x86_elf_link_fixup_ifunc_symbol (info
, htab
, h
, sym
);
4540 /* Don't generate dynamic GOT relocation against undefined weak
4541 symbol in executable. */
4542 if (h
->got
.offset
!= (bfd_vma
) -1
4543 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
4544 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
4545 && !local_undefweak
)
4547 Elf_Internal_Rela rela
;
4548 asection
*relgot
= htab
->elf
.srelgot
;
4549 const char *relative_reloc_name
= NULL
;
4550 bool generate_dynamic_reloc
= true;
4552 /* This symbol has an entry in the global offset table. Set it
4554 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4557 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4558 + htab
->elf
.sgot
->output_offset
4559 + (h
->got
.offset
&~ (bfd_vma
) 1));
4561 /* If this is a static link, or it is a -Bsymbolic link and the
4562 symbol is defined locally or was forced to be local because
4563 of a version file, we just want to emit a RELATIVE reloc.
4564 The entry in the global offset table will already have been
4565 initialized in the relocate_section function. */
4567 && h
->type
== STT_GNU_IFUNC
)
4569 if (h
->plt
.offset
== (bfd_vma
) -1)
4571 /* STT_GNU_IFUNC is referenced without PLT. */
4572 if (htab
->elf
.splt
== NULL
)
4574 /* use .rel[a].iplt section to store .got relocations
4575 in static executable. */
4576 relgot
= htab
->elf
.irelplt
;
4578 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4580 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4581 h
->root
.root
.string
,
4582 h
->root
.u
.def
.section
->owner
);
4584 rela
.r_info
= htab
->r_info (0,
4585 R_X86_64_IRELATIVE
);
4586 rela
.r_addend
= (h
->root
.u
.def
.value
4587 + h
->root
.u
.def
.section
->output_section
->vma
4588 + h
->root
.u
.def
.section
->output_offset
);
4589 relative_reloc_name
= "R_X86_64_IRELATIVE";
4594 else if (bfd_link_pic (info
))
4596 /* Generate R_X86_64_GLOB_DAT. */
4604 if (!h
->pointer_equality_needed
)
4607 /* For non-shared object, we can't use .got.plt, which
4608 contains the real function addres if we need pointer
4609 equality. We load the GOT entry with the PLT entry. */
4610 if (htab
->plt_second
!= NULL
)
4612 plt
= htab
->plt_second
;
4613 plt_offset
= eh
->plt_second
.offset
;
4617 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4618 plt_offset
= h
->plt
.offset
;
4620 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4621 + plt
->output_offset
4623 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4627 else if (bfd_link_pic (info
)
4628 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4630 if (!SYMBOL_DEFINED_NON_SHARED_P (h
))
4632 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4633 if (info
->enable_dt_relr
)
4634 generate_dynamic_reloc
= false;
4637 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4638 rela
.r_addend
= (h
->root
.u
.def
.value
4639 + h
->root
.u
.def
.section
->output_section
->vma
4640 + h
->root
.u
.def
.section
->output_offset
);
4641 relative_reloc_name
= "R_X86_64_RELATIVE";
4646 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4648 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4649 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4650 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4654 if (generate_dynamic_reloc
)
4656 if (relative_reloc_name
!= NULL
4657 && htab
->params
->report_relative_reloc
)
4658 _bfd_x86_elf_link_report_relative_reloc
4659 (info
, relgot
, h
, sym
, relative_reloc_name
, &rela
);
4661 elf_append_rela (output_bfd
, relgot
, &rela
);
4667 Elf_Internal_Rela rela
;
4670 /* This symbol needs a copy reloc. Set it up. */
4671 VERIFY_COPY_RELOC (h
, htab
)
4673 rela
.r_offset
= (h
->root
.u
.def
.value
4674 + h
->root
.u
.def
.section
->output_section
->vma
4675 + h
->root
.u
.def
.section
->output_offset
);
4676 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4678 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4679 s
= htab
->elf
.sreldynrelro
;
4681 s
= htab
->elf
.srelbss
;
4682 elf_append_rela (output_bfd
, s
, &rela
);
4688 /* Finish up local dynamic symbol handling. We set the contents of
4689 various dynamic sections here. */
4692 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4694 struct elf_link_hash_entry
*h
4695 = (struct elf_link_hash_entry
*) *slot
;
4696 struct bfd_link_info
*info
4697 = (struct bfd_link_info
*) inf
;
4699 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4703 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4704 here since undefined weak symbol may not be dynamic and may not be
4705 called for elf_x86_64_finish_dynamic_symbol. */
4708 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4711 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4712 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4714 if (h
->root
.type
!= bfd_link_hash_undefweak
4715 || h
->dynindx
!= -1)
4718 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4722 /* Used to decide how to sort relocs in an optimal manner for the
4723 dynamic linker, before writing them out. */
4725 static enum elf_reloc_type_class
4726 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
4727 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4728 const Elf_Internal_Rela
*rela
)
4730 bfd
*abfd
= info
->output_bfd
;
4731 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4732 struct elf_x86_link_hash_table
*htab
4733 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4735 if (htab
->elf
.dynsym
!= NULL
4736 && htab
->elf
.dynsym
->contents
!= NULL
)
4738 /* Check relocation against STT_GNU_IFUNC symbol if there are
4740 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
4741 if (r_symndx
!= STN_UNDEF
)
4743 Elf_Internal_Sym sym
;
4744 if (!bed
->s
->swap_symbol_in (abfd
,
4745 (htab
->elf
.dynsym
->contents
4746 + r_symndx
* bed
->s
->sizeof_sym
),
4750 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4751 return reloc_class_ifunc
;
4755 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4757 case R_X86_64_IRELATIVE
:
4758 return reloc_class_ifunc
;
4759 case R_X86_64_RELATIVE
:
4760 case R_X86_64_RELATIVE64
:
4761 return reloc_class_relative
;
4762 case R_X86_64_JUMP_SLOT
:
4763 return reloc_class_plt
;
4765 return reloc_class_copy
;
4767 return reloc_class_normal
;
4771 /* Finish up the dynamic sections. */
4774 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4775 struct bfd_link_info
*info
)
4777 struct elf_x86_link_hash_table
*htab
;
4779 htab
= _bfd_x86_elf_finish_dynamic_sections (output_bfd
, info
);
4783 if (! htab
->elf
.dynamic_sections_created
)
4786 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4788 if (bfd_is_abs_section (htab
->elf
.splt
->output_section
))
4790 info
->callbacks
->einfo
4791 (_("%F%P: discarded output section: `%pA'\n"),
4796 elf_section_data (htab
->elf
.splt
->output_section
)
4797 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
4799 if (htab
->plt
.has_plt0
)
4801 /* Fill in the special first entry in the procedure linkage
4803 memcpy (htab
->elf
.splt
->contents
,
4804 htab
->lazy_plt
->plt0_entry
,
4805 htab
->lazy_plt
->plt0_entry_size
);
4806 /* Add offset for pushq GOT+8(%rip), since the instruction
4807 uses 6 bytes subtract this value. */
4808 bfd_put_32 (output_bfd
,
4809 (htab
->elf
.sgotplt
->output_section
->vma
4810 + htab
->elf
.sgotplt
->output_offset
4812 - htab
->elf
.splt
->output_section
->vma
4813 - htab
->elf
.splt
->output_offset
4815 (htab
->elf
.splt
->contents
4816 + htab
->lazy_plt
->plt0_got1_offset
));
4817 /* Add offset for the PC-relative instruction accessing
4818 GOT+16, subtracting the offset to the end of that
4820 bfd_put_32 (output_bfd
,
4821 (htab
->elf
.sgotplt
->output_section
->vma
4822 + htab
->elf
.sgotplt
->output_offset
4824 - htab
->elf
.splt
->output_section
->vma
4825 - htab
->elf
.splt
->output_offset
4826 - htab
->lazy_plt
->plt0_got2_insn_end
),
4827 (htab
->elf
.splt
->contents
4828 + htab
->lazy_plt
->plt0_got2_offset
));
4831 if (htab
->elf
.tlsdesc_plt
)
4833 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4834 htab
->elf
.sgot
->contents
+ htab
->elf
.tlsdesc_got
);
4836 memcpy (htab
->elf
.splt
->contents
+ htab
->elf
.tlsdesc_plt
,
4837 htab
->lazy_plt
->plt_tlsdesc_entry
,
4838 htab
->lazy_plt
->plt_tlsdesc_entry_size
);
4840 /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4
4841 bytes and the instruction uses 6 bytes, subtract these
4843 bfd_put_32 (output_bfd
,
4844 (htab
->elf
.sgotplt
->output_section
->vma
4845 + htab
->elf
.sgotplt
->output_offset
4847 - htab
->elf
.splt
->output_section
->vma
4848 - htab
->elf
.splt
->output_offset
4849 - htab
->elf
.tlsdesc_plt
4850 - htab
->lazy_plt
->plt_tlsdesc_got1_insn_end
),
4851 (htab
->elf
.splt
->contents
4852 + htab
->elf
.tlsdesc_plt
4853 + htab
->lazy_plt
->plt_tlsdesc_got1_offset
));
4854 /* Add offset for indirect branch via GOT+TDG, where TDG
4855 stands for htab->tlsdesc_got, subtracting the offset
4856 to the end of that instruction. */
4857 bfd_put_32 (output_bfd
,
4858 (htab
->elf
.sgot
->output_section
->vma
4859 + htab
->elf
.sgot
->output_offset
4860 + htab
->elf
.tlsdesc_got
4861 - htab
->elf
.splt
->output_section
->vma
4862 - htab
->elf
.splt
->output_offset
4863 - htab
->elf
.tlsdesc_plt
4864 - htab
->lazy_plt
->plt_tlsdesc_got2_insn_end
),
4865 (htab
->elf
.splt
->contents
4866 + htab
->elf
.tlsdesc_plt
4867 + htab
->lazy_plt
->plt_tlsdesc_got2_offset
));
4871 /* Fill PLT entries for undefined weak symbols in PIE. */
4872 if (bfd_link_pie (info
))
4873 bfd_hash_traverse (&info
->hash
->table
,
4874 elf_x86_64_pie_finish_undefweak_symbol
,
4880 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4881 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4882 It has to be done before elf_link_sort_relocs is called so that
4883 dynamic relocations are properly sorted. */
4886 elf_x86_64_output_arch_local_syms
4887 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4888 struct bfd_link_info
*info
,
4889 void *flaginfo ATTRIBUTE_UNUSED
,
4890 int (*func
) (void *, const char *,
4893 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4895 struct elf_x86_link_hash_table
*htab
4896 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4900 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4901 htab_traverse (htab
->loc_hash_table
,
4902 elf_x86_64_finish_local_dynamic_symbol
,
4908 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4909 dynamic relocations. */
4912 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
4913 long symcount ATTRIBUTE_UNUSED
,
4914 asymbol
**syms ATTRIBUTE_UNUSED
,
4921 bfd_byte
*plt_contents
;
4923 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4924 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4925 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
4926 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
4927 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4928 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4929 const struct elf_x86_lazy_plt_layout
*x32_lazy_ibt_plt
;
4930 const struct elf_x86_non_lazy_plt_layout
*x32_non_lazy_ibt_plt
;
4932 enum elf_x86_plt_type plt_type
;
4933 struct elf_x86_plt plts
[] =
4935 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4936 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4937 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4938 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4939 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4944 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4947 if (dynsymcount
<= 0)
4950 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4954 lazy_plt
= &elf_x86_64_lazy_plt
;
4955 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
4956 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
4957 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
4958 if (ABI_64_P (abfd
))
4960 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
4961 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
4962 x32_lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4963 x32_non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4967 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4968 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4969 x32_lazy_ibt_plt
= NULL
;
4970 x32_non_lazy_ibt_plt
= NULL
;
4974 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4976 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4977 if (plt
== NULL
|| plt
->size
== 0)
4980 /* Get the PLT section contents. */
4981 if (!bfd_malloc_and_get_section (abfd
, plt
, &plt_contents
))
4984 /* Check what kind of PLT it is. */
4985 plt_type
= plt_unknown
;
4986 if (plts
[j
].type
== plt_unknown
4987 && (plt
->size
>= (lazy_plt
->plt_entry_size
4988 + lazy_plt
->plt_entry_size
)))
4990 /* Match lazy PLT first. Need to check the first two
4992 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4993 lazy_plt
->plt0_got1_offset
) == 0)
4994 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
4997 if (x32_lazy_ibt_plt
!= NULL
4998 && (memcmp (plt_contents
4999 + x32_lazy_ibt_plt
->plt_entry_size
,
5000 x32_lazy_ibt_plt
->plt_entry
,
5001 x32_lazy_ibt_plt
->plt_got_offset
) == 0))
5003 /* The fist entry in the x32 lazy IBT PLT is the same
5005 plt_type
= plt_lazy
| plt_second
;
5006 lazy_plt
= x32_lazy_ibt_plt
;
5009 plt_type
= plt_lazy
;
5011 else if (lazy_bnd_plt
!= NULL
5012 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
5013 lazy_bnd_plt
->plt0_got1_offset
) == 0)
5014 && (memcmp (plt_contents
+ 6,
5015 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
5017 plt_type
= plt_lazy
| plt_second
;
5018 /* The fist entry in the lazy IBT PLT is the same as the
5020 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
5021 lazy_ibt_plt
->plt_entry
,
5022 lazy_ibt_plt
->plt_got_offset
) == 0))
5023 lazy_plt
= lazy_ibt_plt
;
5025 lazy_plt
= lazy_bnd_plt
;
5029 if (non_lazy_plt
!= NULL
5030 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5031 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5033 /* Match non-lazy PLT. */
5034 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5035 non_lazy_plt
->plt_got_offset
) == 0)
5036 plt_type
= plt_non_lazy
;
5039 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5041 if (non_lazy_bnd_plt
!= NULL
5042 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
5043 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
5044 non_lazy_bnd_plt
->plt_got_offset
) == 0))
5046 /* Match BND PLT. */
5047 plt_type
= plt_second
;
5048 non_lazy_plt
= non_lazy_bnd_plt
;
5050 else if (non_lazy_ibt_plt
!= NULL
5051 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
5052 && (memcmp (plt_contents
,
5053 non_lazy_ibt_plt
->plt_entry
,
5054 non_lazy_ibt_plt
->plt_got_offset
) == 0))
5056 /* Match IBT PLT. */
5057 plt_type
= plt_second
;
5058 non_lazy_plt
= non_lazy_ibt_plt
;
5060 else if (x32_non_lazy_ibt_plt
!= NULL
5061 && plt
->size
>= x32_non_lazy_ibt_plt
->plt_entry_size
5062 && (memcmp (plt_contents
,
5063 x32_non_lazy_ibt_plt
->plt_entry
,
5064 x32_non_lazy_ibt_plt
->plt_got_offset
) == 0))
5066 /* Match x32 IBT PLT. */
5067 plt_type
= plt_second
;
5068 non_lazy_plt
= x32_non_lazy_ibt_plt
;
5072 if (plt_type
== plt_unknown
)
5074 free (plt_contents
);
5079 plts
[j
].type
= plt_type
;
5081 if ((plt_type
& plt_lazy
))
5083 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5084 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
5085 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5086 /* Skip PLT0 in lazy PLT. */
5091 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5092 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
5093 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5097 /* Skip lazy PLT when the second PLT is used. */
5098 if (plt_type
== (plt_lazy
| plt_second
))
5102 n
= plt
->size
/ plts
[j
].plt_entry_size
;
5107 plts
[j
].contents
= plt_contents
;
5110 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
5111 (bfd_vma
) 0, plts
, dynsyms
,
5115 /* Handle an x86-64 specific section when reading an object file. This
5116 is called when elfcode.h finds a section with an unknown type. */
5119 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
5120 const char *name
, int shindex
)
5122 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
5125 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5131 /* Hook called by the linker routine which adds symbols from an object
5132 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
5136 elf_x86_64_add_symbol_hook (bfd
*abfd
,
5137 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5138 Elf_Internal_Sym
*sym
,
5139 const char **namep ATTRIBUTE_UNUSED
,
5140 flagword
*flagsp ATTRIBUTE_UNUSED
,
5146 switch (sym
->st_shndx
)
5148 case SHN_X86_64_LCOMMON
:
5149 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
5152 lcomm
= bfd_make_section_with_flags (abfd
,
5156 | SEC_LINKER_CREATED
));
5159 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
5162 *valp
= sym
->st_size
;
5170 /* Given a BFD section, try to locate the corresponding ELF section
5174 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5175 asection
*sec
, int *index_return
)
5177 if (sec
== &_bfd_elf_large_com_section
)
5179 *index_return
= SHN_X86_64_LCOMMON
;
5185 /* Process a symbol. */
5188 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5191 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5193 switch (elfsym
->internal_elf_sym
.st_shndx
)
5195 case SHN_X86_64_LCOMMON
:
5196 asym
->section
= &_bfd_elf_large_com_section
;
5197 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5198 /* Common symbol doesn't set BSF_GLOBAL. */
5199 asym
->flags
&= ~BSF_GLOBAL
;
5205 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
5207 return (sym
->st_shndx
== SHN_COMMON
5208 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
5212 elf_x86_64_common_section_index (asection
*sec
)
5214 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5217 return SHN_X86_64_LCOMMON
;
5221 elf_x86_64_common_section (asection
*sec
)
5223 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5224 return bfd_com_section_ptr
;
5226 return &_bfd_elf_large_com_section
;
5230 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5231 const Elf_Internal_Sym
*sym
,
5236 const asection
*oldsec
)
5238 /* A normal common symbol and a large common symbol result in a
5239 normal common symbol. We turn the large common symbol into a
5242 && h
->root
.type
== bfd_link_hash_common
5244 && bfd_is_com_section (*psec
)
5247 if (sym
->st_shndx
== SHN_COMMON
5248 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5250 h
->root
.u
.c
.p
->section
5251 = bfd_make_section_old_way (oldbfd
, "COMMON");
5252 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5254 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5255 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5256 *psec
= bfd_com_section_ptr
;
5263 elf_x86_64_additional_program_headers (bfd
*abfd
,
5264 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5269 /* Check to see if we need a large readonly segment. */
5270 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5271 if (s
&& (s
->flags
& SEC_LOAD
))
5274 /* Check to see if we need a large data segment. Since .lbss sections
5275 is placed right after the .bss section, there should be no need for
5276 a large data segment just because of .lbss. */
5277 s
= bfd_get_section_by_name (abfd
, ".ldata");
5278 if (s
&& (s
->flags
& SEC_LOAD
))
5284 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5287 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5288 const bfd_target
*output
)
5290 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5291 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5292 && _bfd_elf_relocs_compatible (input
, output
));
5295 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5296 with GNU properties if found. Otherwise, return NULL. */
5299 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
5301 struct elf_x86_init_table init_table
;
5302 const struct elf_backend_data
*bed
;
5303 struct elf_x86_link_hash_table
*htab
;
5305 if ((int) R_X86_64_standard
>= (int) R_X86_64_converted_reloc_bit
5306 || (int) R_X86_64_max
<= (int) R_X86_64_converted_reloc_bit
5307 || ((int) (R_X86_64_GNU_VTINHERIT
| R_X86_64_converted_reloc_bit
)
5308 != (int) R_X86_64_GNU_VTINHERIT
)
5309 || ((int) (R_X86_64_GNU_VTENTRY
| R_X86_64_converted_reloc_bit
)
5310 != (int) R_X86_64_GNU_VTENTRY
))
5313 /* This is unused for x86-64. */
5314 init_table
.plt0_pad_byte
= 0x90;
5316 bed
= get_elf_backend_data (info
->output_bfd
);
5317 htab
= elf_x86_hash_table (info
, bed
->target_id
);
5320 if (htab
->params
->bndplt
)
5322 init_table
.lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
5323 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
5327 init_table
.lazy_plt
= &elf_x86_64_lazy_plt
;
5328 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"