1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2020 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"
25 #include "libiberty.h"
27 #include "opcode/i386.h"
28 #include "elf/x86-64.h"
35 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
36 #define MINUS_ONE (~ (bfd_vma) 0)
38 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
39 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
40 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
41 since they are the same. */
43 /* The relocation "howto" table. Order of fields:
44 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
45 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
46 static reloc_howto_type x86_64_elf_howto_table
[] =
48 HOWTO(R_X86_64_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
49 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
51 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
54 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
55 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
58 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
61 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
63 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
66 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
69 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
72 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
73 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
75 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
76 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
78 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
79 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
81 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
82 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
84 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
86 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
88 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
90 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
91 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
92 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
95 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
98 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
101 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
102 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
104 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
105 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
107 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
108 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
110 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
113 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
114 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
116 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
119 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
121 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
122 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
123 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
124 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
125 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
126 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
128 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
129 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
131 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
132 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
133 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
134 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
135 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
137 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
138 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
140 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
141 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
143 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
144 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
146 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
147 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
148 "R_X86_64_GOTPC32_TLSDESC",
149 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
150 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
151 complain_overflow_dont
, bfd_elf_generic_reloc
,
152 "R_X86_64_TLSDESC_CALL",
154 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
155 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
157 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
158 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
159 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
161 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
162 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
164 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
165 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
167 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
168 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
170 HOWTO(R_X86_64_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
171 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", FALSE
, 0xffffffff,
173 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
174 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", FALSE
, 0xffffffff,
177 /* We have a gap in the reloc numbers here.
178 R_X86_64_standard counts the number up to this point, and
179 R_X86_64_vt_offset is the value to subtract from a reloc type of
180 R_X86_64_GNU_VT* to form an index into this table. */
181 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
182 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
184 /* GNU extension to record C++ vtable hierarchy. */
185 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
186 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
188 /* GNU extension to record C++ vtable member usage. */
189 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
190 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
193 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
194 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
195 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
199 #define X86_PCREL_TYPE_P(TYPE) \
200 ( ((TYPE) == R_X86_64_PC8) \
201 || ((TYPE) == R_X86_64_PC16) \
202 || ((TYPE) == R_X86_64_PC32) \
203 || ((TYPE) == R_X86_64_PC32_BND) \
204 || ((TYPE) == R_X86_64_PC64))
206 #define X86_SIZE_TYPE_P(TYPE) \
207 ((TYPE) == R_X86_64_SIZE32 || (TYPE) == R_X86_64_SIZE64)
209 /* Map BFD relocs to the x86_64 elf relocs. */
212 bfd_reloc_code_real_type bfd_reloc_val
;
213 unsigned char elf_reloc_val
;
216 static const struct elf_reloc_map x86_64_reloc_map
[] =
218 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
219 { BFD_RELOC_64
, R_X86_64_64
, },
220 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
221 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
222 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
223 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
224 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
225 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
226 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
227 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
228 { BFD_RELOC_32
, R_X86_64_32
, },
229 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
230 { BFD_RELOC_16
, R_X86_64_16
, },
231 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
232 { BFD_RELOC_8
, R_X86_64_8
, },
233 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
234 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
235 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
236 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
237 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
238 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
239 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
240 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
241 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
242 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
243 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
244 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
245 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
246 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
247 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
248 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
249 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
250 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
251 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
252 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
253 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
254 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
255 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
256 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
257 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
258 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
259 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
260 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
261 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
264 static reloc_howto_type
*
265 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
269 if (r_type
== (unsigned int) R_X86_64_32
)
274 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
276 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
277 || r_type
>= (unsigned int) R_X86_64_max
)
279 if (r_type
>= (unsigned int) R_X86_64_standard
)
281 /* xgettext:c-format */
282 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
284 bfd_set_error (bfd_error_bad_value
);
290 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
291 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
292 return &x86_64_elf_howto_table
[i
];
295 /* Given a BFD reloc type, return a HOWTO structure. */
296 static reloc_howto_type
*
297 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
298 bfd_reloc_code_real_type code
)
302 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
305 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
306 return elf_x86_64_rtype_to_howto (abfd
,
307 x86_64_reloc_map
[i
].elf_reloc_val
);
312 static reloc_howto_type
*
313 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
318 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
320 /* Get x32 R_X86_64_32. */
321 reloc_howto_type
*reloc
322 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
323 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
327 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
328 if (x86_64_elf_howto_table
[i
].name
!= NULL
329 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
330 return &x86_64_elf_howto_table
[i
];
335 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
338 elf_x86_64_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
339 Elf_Internal_Rela
*dst
)
343 r_type
= ELF32_R_TYPE (dst
->r_info
);
344 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
345 if (cache_ptr
->howto
== NULL
)
347 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
|| cache_ptr
->howto
->type
== R_X86_64_NONE
);
351 /* Support for core dump NOTE sections. */
353 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
358 switch (note
->descsz
)
363 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
365 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
368 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
376 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
378 elf_tdata (abfd
)->core
->signal
379 = bfd_get_16 (abfd
, note
->descdata
+ 12);
382 elf_tdata (abfd
)->core
->lwpid
383 = bfd_get_32 (abfd
, note
->descdata
+ 32);
392 /* Make a ".reg/999" section. */
393 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
394 size
, note
->descpos
+ offset
);
398 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
400 switch (note
->descsz
)
405 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
406 elf_tdata (abfd
)->core
->pid
407 = bfd_get_32 (abfd
, note
->descdata
+ 12);
408 elf_tdata (abfd
)->core
->program
409 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
410 elf_tdata (abfd
)->core
->command
411 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
414 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
415 elf_tdata (abfd
)->core
->pid
416 = bfd_get_32 (abfd
, note
->descdata
+ 24);
417 elf_tdata (abfd
)->core
->program
418 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
419 elf_tdata (abfd
)->core
->command
420 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
423 /* Note that for some reason, a spurious space is tacked
424 onto the end of the args in some (at least one anyway)
425 implementations, so strip it off if it exists. */
428 char *command
= elf_tdata (abfd
)->core
->command
;
429 int n
= strlen (command
);
431 if (0 < n
&& command
[n
- 1] == ' ')
432 command
[n
- 1] = '\0';
439 # if GCC_VERSION >= 8000
440 # pragma GCC diagnostic push
441 # pragma GCC diagnostic ignored "-Wstringop-truncation"
444 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
447 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
449 const char *fname
, *psargs
;
460 va_start (ap
, note_type
);
461 fname
= va_arg (ap
, const char *);
462 psargs
= va_arg (ap
, const char *);
465 if (bed
->s
->elfclass
== ELFCLASS32
)
468 memset (&data
, 0, sizeof (data
));
469 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
470 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
471 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
472 &data
, sizeof (data
));
477 memset (&data
, 0, sizeof (data
));
478 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
479 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
480 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
481 &data
, sizeof (data
));
486 va_start (ap
, note_type
);
487 pid
= va_arg (ap
, long);
488 cursig
= va_arg (ap
, int);
489 gregs
= va_arg (ap
, const void *);
492 if (bed
->s
->elfclass
== ELFCLASS32
)
494 if (bed
->elf_machine_code
== EM_X86_64
)
496 prstatusx32_t prstat
;
497 memset (&prstat
, 0, sizeof (prstat
));
499 prstat
.pr_cursig
= cursig
;
500 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
501 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
502 &prstat
, sizeof (prstat
));
507 memset (&prstat
, 0, sizeof (prstat
));
509 prstat
.pr_cursig
= cursig
;
510 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
511 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
512 &prstat
, sizeof (prstat
));
518 memset (&prstat
, 0, sizeof (prstat
));
520 prstat
.pr_cursig
= cursig
;
521 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
522 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
523 &prstat
, sizeof (prstat
));
528 # if GCC_VERSION >= 8000
529 # pragma GCC diagnostic pop
533 /* Functions for the x86-64 ELF linker. */
535 /* The size in bytes of an entry in the global offset table. */
537 #define GOT_ENTRY_SIZE 8
539 /* The size in bytes of an entry in the lazy procedure linkage table. */
541 #define LAZY_PLT_ENTRY_SIZE 16
543 /* The size in bytes of an entry in the non-lazy procedure linkage
546 #define NON_LAZY_PLT_ENTRY_SIZE 8
548 /* The first entry in a lazy procedure linkage table looks like this.
549 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
552 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
554 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
555 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
556 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
559 /* Subsequent entries in a lazy procedure linkage table look like this. */
561 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
563 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
564 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
565 0x68, /* pushq immediate */
566 0, 0, 0, 0, /* replaced with index into relocation table. */
567 0xe9, /* jmp relative */
568 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
571 /* The first entry in a lazy procedure linkage table with BND prefix
574 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
576 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
577 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
578 0x0f, 0x1f, 0 /* nopl (%rax) */
581 /* Subsequent entries for branches with BND prefx in a lazy procedure
582 linkage table look like this. */
584 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
586 0x68, 0, 0, 0, 0, /* pushq immediate */
587 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
588 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
591 /* The first entry in the IBT-enabled lazy procedure linkage table is the
592 the same as the lazy PLT with BND prefix so that bound registers are
593 preserved when control is passed to dynamic linker. Subsequent
594 entries for a IBT-enabled lazy procedure linkage table look like
597 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
599 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
600 0x68, 0, 0, 0, 0, /* pushq immediate */
601 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
605 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
606 is the same as the normal lazy PLT. Subsequent entries for an
607 x32 IBT-enabled lazy procedure linkage table look like this. */
609 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
611 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
612 0x68, 0, 0, 0, 0, /* pushq immediate */
613 0xe9, 0, 0, 0, 0, /* jmpq relative */
614 0x66, 0x90 /* xchg %ax,%ax */
617 /* Entries in the non-lazey procedure linkage table look like this. */
619 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
621 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
622 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
623 0x66, 0x90 /* xchg %ax,%ax */
626 /* Entries for branches with BND prefix in the non-lazey procedure
627 linkage table look like this. */
629 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
631 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
632 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
636 /* Entries for branches with IBT-enabled in the non-lazey procedure
637 linkage table look like this. They have the same size as the lazy
640 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
642 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
643 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
644 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
645 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
648 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
649 linkage table look like this. They have the same size as the lazy
652 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
654 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
655 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
656 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
657 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
660 /* The TLSDESC entry in a lazy procedure linkage table. */
661 static const bfd_byte elf_x86_64_tlsdesc_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
663 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
664 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
665 0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */
668 /* .eh_frame covering the lazy .plt section. */
670 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
672 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
673 0, 0, 0, 0, /* CIE ID */
675 'z', 'R', 0, /* Augmentation string */
676 1, /* Code alignment factor */
677 0x78, /* Data alignment factor */
678 16, /* Return address column */
679 1, /* Augmentation size */
680 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
681 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
682 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
683 DW_CFA_nop
, DW_CFA_nop
,
685 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
686 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
687 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
688 0, 0, 0, 0, /* .plt size goes here */
689 0, /* Augmentation size */
690 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
691 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
692 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
693 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
694 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
695 11, /* Block length */
696 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
697 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
698 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
699 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
700 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
703 /* .eh_frame covering the lazy BND .plt section. */
705 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
707 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
708 0, 0, 0, 0, /* CIE ID */
710 'z', 'R', 0, /* Augmentation string */
711 1, /* Code alignment factor */
712 0x78, /* Data alignment factor */
713 16, /* Return address column */
714 1, /* Augmentation size */
715 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
716 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
717 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
718 DW_CFA_nop
, DW_CFA_nop
,
720 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
721 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
722 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
723 0, 0, 0, 0, /* .plt size goes here */
724 0, /* Augmentation size */
725 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
726 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
727 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
728 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
729 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
730 11, /* Block length */
731 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
732 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
733 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
734 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
735 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
738 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
740 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
742 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
743 0, 0, 0, 0, /* CIE ID */
745 'z', 'R', 0, /* Augmentation string */
746 1, /* Code alignment factor */
747 0x78, /* Data alignment factor */
748 16, /* Return address column */
749 1, /* Augmentation size */
750 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
751 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
752 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
753 DW_CFA_nop
, DW_CFA_nop
,
755 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
756 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
757 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
758 0, 0, 0, 0, /* .plt size goes here */
759 0, /* Augmentation size */
760 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
761 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
762 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
763 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
764 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
765 11, /* Block length */
766 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
767 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
768 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
769 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
770 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
773 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
775 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
777 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
778 0, 0, 0, 0, /* CIE ID */
780 'z', 'R', 0, /* Augmentation string */
781 1, /* Code alignment factor */
782 0x78, /* Data alignment factor */
783 16, /* Return address column */
784 1, /* Augmentation size */
785 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
786 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
787 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
788 DW_CFA_nop
, DW_CFA_nop
,
790 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
791 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
792 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
793 0, 0, 0, 0, /* .plt size goes here */
794 0, /* Augmentation size */
795 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
796 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
797 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
798 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
799 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
800 11, /* Block length */
801 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
802 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
803 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
804 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
805 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
808 /* .eh_frame covering the non-lazy .plt section. */
810 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
812 #define PLT_GOT_FDE_LENGTH 20
813 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
814 0, 0, 0, 0, /* CIE ID */
816 'z', 'R', 0, /* Augmentation string */
817 1, /* Code alignment factor */
818 0x78, /* Data alignment factor */
819 16, /* Return address column */
820 1, /* Augmentation size */
821 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
822 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
823 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
824 DW_CFA_nop
, DW_CFA_nop
,
826 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
827 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
828 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
829 0, 0, 0, 0, /* non-lazy .plt size goes here */
830 0, /* Augmentation size */
831 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
832 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
835 /* These are the standard parameters. */
836 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
838 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
839 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
840 elf_x86_64_lazy_plt_entry
, /* plt_entry */
841 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
842 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
843 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
844 6, /* plt_tlsdesc_got1_offset */
845 12, /* plt_tlsdesc_got2_offset */
846 10, /* plt_tlsdesc_got1_insn_end */
847 16, /* plt_tlsdesc_got2_insn_end */
848 2, /* plt0_got1_offset */
849 8, /* plt0_got2_offset */
850 12, /* plt0_got2_insn_end */
851 2, /* plt_got_offset */
852 7, /* plt_reloc_offset */
853 12, /* plt_plt_offset */
854 6, /* plt_got_insn_size */
855 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
856 6, /* plt_lazy_offset */
857 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
858 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
859 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
860 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
863 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
865 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
866 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
867 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
868 2, /* plt_got_offset */
869 6, /* plt_got_insn_size */
870 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
871 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
874 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
876 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
877 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
878 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
879 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
880 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
881 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
882 6, /* plt_tlsdesc_got1_offset */
883 12, /* plt_tlsdesc_got2_offset */
884 10, /* plt_tlsdesc_got1_insn_end */
885 16, /* plt_tlsdesc_got2_insn_end */
886 2, /* plt0_got1_offset */
887 1+8, /* plt0_got2_offset */
888 1+12, /* plt0_got2_insn_end */
889 1+2, /* plt_got_offset */
890 1, /* plt_reloc_offset */
891 7, /* plt_plt_offset */
892 1+6, /* plt_got_insn_size */
893 11, /* plt_plt_insn_end */
894 0, /* plt_lazy_offset */
895 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
896 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
897 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
898 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
901 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
903 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
904 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
905 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
906 1+2, /* plt_got_offset */
907 1+6, /* plt_got_insn_size */
908 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
909 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
912 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
914 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
915 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
916 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
917 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
918 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
919 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
920 6, /* plt_tlsdesc_got1_offset */
921 12, /* plt_tlsdesc_got2_offset */
922 10, /* plt_tlsdesc_got1_insn_end */
923 16, /* plt_tlsdesc_got2_insn_end */
924 2, /* plt0_got1_offset */
925 1+8, /* plt0_got2_offset */
926 1+12, /* plt0_got2_insn_end */
927 4+1+2, /* plt_got_offset */
928 4+1, /* plt_reloc_offset */
929 4+1+6, /* plt_plt_offset */
930 4+1+6, /* plt_got_insn_size */
931 4+1+5+5, /* plt_plt_insn_end */
932 0, /* plt_lazy_offset */
933 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
934 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
935 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
936 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
939 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
941 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
942 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
943 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
944 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
945 elf_x86_64_tlsdesc_plt_entry
, /* plt_tlsdesc_entry */
946 LAZY_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
947 6, /* plt_tlsdesc_got1_offset */
948 12, /* plt_tlsdesc_got2_offset */
949 10, /* plt_tlsdesc_got1_insn_end */
950 16, /* plt_tlsdesc_got2_insn_end */
951 2, /* plt0_got1_offset */
952 8, /* plt0_got2_offset */
953 12, /* plt0_got2_insn_end */
954 4+2, /* plt_got_offset */
955 4+1, /* plt_reloc_offset */
956 4+6, /* plt_plt_offset */
957 4+6, /* plt_got_insn_size */
958 4+5+5, /* plt_plt_insn_end */
959 0, /* plt_lazy_offset */
960 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
961 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
962 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
963 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
966 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
968 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
969 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
970 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
971 4+1+2, /* plt_got_offset */
972 4+1+6, /* plt_got_insn_size */
973 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
974 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
977 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
979 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
980 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
981 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
982 4+2, /* plt_got_offset */
983 4+6, /* plt_got_insn_size */
984 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
985 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
990 elf64_x86_64_elf_object_p (bfd
*abfd
)
992 /* Set the right machine number for an x86-64 elf64 file. */
993 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
998 elf32_x86_64_elf_object_p (bfd
*abfd
)
1000 /* Set the right machine number for an x86-64 elf32 file. */
1001 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1005 /* Return TRUE if the TLS access code sequence support transition
1009 elf_x86_64_check_tls_transition (bfd
*abfd
,
1010 struct bfd_link_info
*info
,
1013 Elf_Internal_Shdr
*symtab_hdr
,
1014 struct elf_link_hash_entry
**sym_hashes
,
1015 unsigned int r_type
,
1016 const Elf_Internal_Rela
*rel
,
1017 const Elf_Internal_Rela
*relend
)
1020 unsigned long r_symndx
;
1021 bfd_boolean largepic
= FALSE
;
1022 struct elf_link_hash_entry
*h
;
1024 struct elf_x86_link_hash_table
*htab
;
1026 bfd_boolean indirect_call
;
1028 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1029 offset
= rel
->r_offset
;
1032 case R_X86_64_TLSGD
:
1033 case R_X86_64_TLSLD
:
1034 if ((rel
+ 1) >= relend
)
1037 if (r_type
== R_X86_64_TLSGD
)
1039 /* Check transition from GD access model. For 64bit, only
1040 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1041 .word 0x6666; rex64; call __tls_get_addr@PLT
1043 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1045 call *__tls_get_addr@GOTPCREL(%rip)
1046 which may be converted to
1047 addr32 call __tls_get_addr
1048 can transit to different access model. For 32bit, only
1049 leaq foo@tlsgd(%rip), %rdi
1050 .word 0x6666; rex64; call __tls_get_addr@PLT
1052 leaq foo@tlsgd(%rip), %rdi
1054 call *__tls_get_addr@GOTPCREL(%rip)
1055 which may be converted to
1056 addr32 call __tls_get_addr
1057 can transit to different access model. For largepic,
1059 leaq foo@tlsgd(%rip), %rdi
1060 movabsq $__tls_get_addr@pltoff, %rax
1064 leaq foo@tlsgd(%rip), %rdi
1065 movabsq $__tls_get_addr@pltoff, %rax
1069 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1071 if ((offset
+ 12) > sec
->size
)
1074 call
= contents
+ offset
+ 4;
1076 || !((call
[1] == 0x48
1084 && call
[3] == 0xe8)))
1086 if (!ABI_64_P (abfd
)
1087 || (offset
+ 19) > sec
->size
1089 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1090 || memcmp (call
, "\x48\xb8", 2) != 0
1094 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1095 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1099 else if (ABI_64_P (abfd
))
1102 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1108 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1111 indirect_call
= call
[2] == 0xff;
1115 /* Check transition from LD access model. Only
1116 leaq foo@tlsld(%rip), %rdi;
1117 call __tls_get_addr@PLT
1119 leaq foo@tlsld(%rip), %rdi;
1120 call *__tls_get_addr@GOTPCREL(%rip)
1121 which may be converted to
1122 addr32 call __tls_get_addr
1123 can transit to different access model. For largepic
1125 leaq foo@tlsld(%rip), %rdi
1126 movabsq $__tls_get_addr@pltoff, %rax
1130 leaq foo@tlsld(%rip), %rdi
1131 movabsq $__tls_get_addr@pltoff, %rax
1135 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1137 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1140 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1143 call
= contents
+ offset
+ 4;
1144 if (!(call
[0] == 0xe8
1145 || (call
[0] == 0xff && call
[1] == 0x15)
1146 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1148 if (!ABI_64_P (abfd
)
1149 || (offset
+ 19) > sec
->size
1150 || memcmp (call
, "\x48\xb8", 2) != 0
1154 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1155 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1159 indirect_call
= call
[0] == 0xff;
1162 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1163 if (r_symndx
< symtab_hdr
->sh_info
)
1166 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1168 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1172 r_type
= (ELF32_R_TYPE (rel
[1].r_info
)
1173 & ~R_X86_64_converted_reloc_bit
);
1175 return r_type
== R_X86_64_PLTOFF64
;
1176 else if (indirect_call
)
1177 return r_type
== R_X86_64_GOTPCRELX
;
1179 return (r_type
== R_X86_64_PC32
|| r_type
== R_X86_64_PLT32
);
1182 case R_X86_64_GOTTPOFF
:
1183 /* Check transition from IE access model:
1184 mov foo@gottpoff(%rip), %reg
1185 add foo@gottpoff(%rip), %reg
1188 /* Check REX prefix first. */
1189 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1191 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1192 if (val
!= 0x48 && val
!= 0x4c)
1194 /* X32 may have 0x44 REX prefix or no REX prefix. */
1195 if (ABI_64_P (abfd
))
1201 /* X32 may not have any REX prefix. */
1202 if (ABI_64_P (abfd
))
1204 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1208 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1209 if (val
!= 0x8b && val
!= 0x03)
1212 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1213 return (val
& 0xc7) == 5;
1215 case R_X86_64_GOTPC32_TLSDESC
:
1216 /* Check transition from GDesc access model:
1217 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
1218 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
1220 Make sure it's a leaq adding rip to a 32-bit offset
1221 into any register, although it's probably almost always
1224 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1227 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1229 if (val
!= 0x48 && (ABI_64_P (abfd
) || val
!= 0x40))
1232 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1235 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1236 return (val
& 0xc7) == 0x05;
1238 case R_X86_64_TLSDESC_CALL
:
1239 /* Check transition from GDesc access model:
1240 call *x@tlsdesc(%rax) <--- LP64 mode.
1241 call *x@tlsdesc(%eax) <--- X32 mode.
1243 if (offset
+ 2 <= sec
->size
)
1245 unsigned int prefix
;
1246 call
= contents
+ offset
;
1248 if (!ABI_64_P (abfd
))
1250 /* Check for call *x@tlsdesc(%eax). */
1251 if (call
[0] == 0x67)
1254 if (offset
+ 3 > sec
->size
)
1258 /* Make sure that it's a call *x@tlsdesc(%rax). */
1259 return call
[prefix
] == 0xff && call
[1 + prefix
] == 0x10;
1269 /* Return TRUE if the TLS access transition is OK or no transition
1270 will be performed. Update R_TYPE if there is a transition. */
1273 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1274 asection
*sec
, bfd_byte
*contents
,
1275 Elf_Internal_Shdr
*symtab_hdr
,
1276 struct elf_link_hash_entry
**sym_hashes
,
1277 unsigned int *r_type
, int tls_type
,
1278 const Elf_Internal_Rela
*rel
,
1279 const Elf_Internal_Rela
*relend
,
1280 struct elf_link_hash_entry
*h
,
1281 unsigned long r_symndx
,
1282 bfd_boolean from_relocate_section
)
1284 unsigned int from_type
= *r_type
;
1285 unsigned int to_type
= from_type
;
1286 bfd_boolean check
= TRUE
;
1288 /* Skip TLS transition for functions. */
1290 && (h
->type
== STT_FUNC
1291 || h
->type
== STT_GNU_IFUNC
))
1296 case R_X86_64_TLSGD
:
1297 case R_X86_64_GOTPC32_TLSDESC
:
1298 case R_X86_64_TLSDESC_CALL
:
1299 case R_X86_64_GOTTPOFF
:
1300 if (bfd_link_executable (info
))
1303 to_type
= R_X86_64_TPOFF32
;
1305 to_type
= R_X86_64_GOTTPOFF
;
1308 /* When we are called from elf_x86_64_relocate_section, there may
1309 be additional transitions based on TLS_TYPE. */
1310 if (from_relocate_section
)
1312 unsigned int new_to_type
= to_type
;
1314 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1315 new_to_type
= R_X86_64_TPOFF32
;
1317 if (to_type
== R_X86_64_TLSGD
1318 || to_type
== R_X86_64_GOTPC32_TLSDESC
1319 || to_type
== R_X86_64_TLSDESC_CALL
)
1321 if (tls_type
== GOT_TLS_IE
)
1322 new_to_type
= R_X86_64_GOTTPOFF
;
1325 /* We checked the transition before when we were called from
1326 elf_x86_64_check_relocs. We only want to check the new
1327 transition which hasn't been checked before. */
1328 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1329 to_type
= new_to_type
;
1334 case R_X86_64_TLSLD
:
1335 if (bfd_link_executable (info
))
1336 to_type
= R_X86_64_TPOFF32
;
1343 /* Return TRUE if there is no transition. */
1344 if (from_type
== to_type
)
1347 /* Check if the transition can be performed. */
1349 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1350 symtab_hdr
, sym_hashes
,
1351 from_type
, rel
, relend
))
1353 reloc_howto_type
*from
, *to
;
1356 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1357 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1359 if (from
== NULL
|| to
== NULL
)
1363 name
= h
->root
.root
.string
;
1366 struct elf_x86_link_hash_table
*htab
;
1368 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1373 Elf_Internal_Sym
*isym
;
1375 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1377 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1382 /* xgettext:c-format */
1383 (_("%pB: TLS transition from %s to %s against `%s' at %#" PRIx64
1384 " in section `%pA' failed"),
1385 abfd
, from
->name
, to
->name
, name
, (uint64_t) rel
->r_offset
, sec
);
1386 bfd_set_error (bfd_error_bad_value
);
1394 /* Rename some of the generic section flags to better document how they
1396 #define check_relocs_failed sec_flg0
1399 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1400 bfd
*input_bfd
, asection
*sec
,
1401 struct elf_link_hash_entry
*h
,
1402 Elf_Internal_Shdr
*symtab_hdr
,
1403 Elf_Internal_Sym
*isym
,
1404 reloc_howto_type
*howto
)
1407 const char *und
= "";
1408 const char *pic
= "";
1414 name
= h
->root
.root
.string
;
1415 switch (ELF_ST_VISIBILITY (h
->other
))
1418 v
= _("hidden symbol ");
1421 v
= _("internal symbol ");
1424 v
= _("protected symbol ");
1427 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1428 v
= _("protected symbol ");
1435 if (!SYMBOL_DEFINED_NON_SHARED_P (h
) && !h
->def_dynamic
)
1436 und
= _("undefined ");
1440 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1444 if (bfd_link_dll (info
))
1446 object
= _("a shared object");
1448 pic
= _("; recompile with -fPIC");
1452 if (bfd_link_pie (info
))
1453 object
= _("a PIE object");
1455 object
= _("a PDE object");
1457 pic
= _("; recompile with -fPIE");
1460 /* xgettext:c-format */
1461 _bfd_error_handler (_("%pB: relocation %s against %s%s`%s' can "
1462 "not be used when making %s%s"),
1463 input_bfd
, howto
->name
, und
, v
, name
,
1465 bfd_set_error (bfd_error_bad_value
);
1466 sec
->check_relocs_failed
= 1;
1470 /* With the local symbol, foo, we convert
1471 mov foo@GOTPCREL(%rip), %reg
1475 call/jmp *foo@GOTPCREL(%rip)
1477 nop call foo/jmp foo nop
1478 When PIC is false, convert
1479 test %reg, foo@GOTPCREL(%rip)
1483 binop foo@GOTPCREL(%rip), %reg
1486 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1490 elf_x86_64_convert_load_reloc (bfd
*abfd
,
1492 unsigned int *r_type_p
,
1493 Elf_Internal_Rela
*irel
,
1494 struct elf_link_hash_entry
*h
,
1495 bfd_boolean
*converted
,
1496 struct bfd_link_info
*link_info
)
1498 struct elf_x86_link_hash_table
*htab
;
1500 bfd_boolean no_overflow
;
1502 bfd_boolean to_reloc_pc32
;
1503 bfd_boolean abs_symbol
;
1504 bfd_boolean local_ref
;
1506 bfd_signed_vma raddend
;
1507 unsigned int opcode
;
1509 unsigned int r_type
= *r_type_p
;
1510 unsigned int r_symndx
;
1511 bfd_vma roff
= irel
->r_offset
;
1512 bfd_vma abs_relocation
;
1514 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1517 raddend
= irel
->r_addend
;
1518 /* Addend for 32-bit PC-relative relocation must be -4. */
1522 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1523 is_pic
= bfd_link_pic (link_info
);
1525 relocx
= (r_type
== R_X86_64_GOTPCRELX
1526 || r_type
== R_X86_64_REX_GOTPCRELX
);
1528 /* TRUE if --no-relax is used. */
1529 no_overflow
= link_info
->disable_target_specific_optimizations
> 1;
1531 r_symndx
= htab
->r_sym (irel
->r_info
);
1533 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1535 /* Convert mov to lea since it has been done for a while. */
1538 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1539 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1540 test, xor instructions. */
1545 /* We convert only to R_X86_64_PC32:
1547 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1548 3. no_overflow is true.
1551 to_reloc_pc32
= (opcode
== 0xff
1559 /* Get the symbol referred to by the reloc. */
1562 Elf_Internal_Sym
*isym
1563 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1565 /* Skip relocation against undefined symbols. */
1566 if (isym
->st_shndx
== SHN_UNDEF
)
1570 if (isym
->st_shndx
== SHN_ABS
)
1572 tsec
= bfd_abs_section_ptr
;
1574 abs_relocation
= isym
->st_value
;
1576 else if (isym
->st_shndx
== SHN_COMMON
)
1577 tsec
= bfd_com_section_ptr
;
1578 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1579 tsec
= &_bfd_elf_large_com_section
;
1581 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1585 /* Undefined weak symbol is only bound locally in executable
1586 and its reference is resolved as 0 without relocation
1587 overflow. We can only perform this optimization for
1588 GOTPCRELX relocations since we need to modify REX byte.
1589 It is OK convert mov with R_X86_64_GOTPCREL to
1591 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
1593 abs_symbol
= ABS_SYMBOL_P (h
);
1594 abs_relocation
= h
->root
.u
.def
.value
;
1596 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1597 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1598 if ((relocx
|| opcode
== 0x8b)
1599 && (h
->root
.type
== bfd_link_hash_undefweak
1605 /* Skip for branch instructions since R_X86_64_PC32
1612 /* For non-branch instructions, we can convert to
1613 R_X86_64_32/R_X86_64_32S since we know if there
1615 to_reloc_pc32
= FALSE
;
1618 /* Since we don't know the current PC when PIC is true,
1619 we can't convert to R_X86_64_PC32. */
1620 if (to_reloc_pc32
&& is_pic
)
1625 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1626 ld.so may use its link-time address. */
1627 else if (h
->start_stop
1630 || h
->root
.type
== bfd_link_hash_defined
1631 || h
->root
.type
== bfd_link_hash_defweak
)
1632 && h
!= htab
->elf
.hdynamic
1635 /* bfd_link_hash_new or bfd_link_hash_undefined is
1636 set by an assignment in a linker script in
1637 bfd_elf_record_link_assignment. start_stop is set
1638 on __start_SECNAME/__stop_SECNAME which mark section
1643 && (h
->root
.type
== bfd_link_hash_new
1644 || h
->root
.type
== bfd_link_hash_undefined
1645 || ((h
->root
.type
== bfd_link_hash_defined
1646 || h
->root
.type
== bfd_link_hash_defweak
)
1647 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1649 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1654 tsec
= h
->root
.u
.def
.section
;
1660 /* Don't convert GOTPCREL relocation against large section. */
1661 if (elf_section_data (tsec
) != NULL
1662 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1665 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1672 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1677 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1679 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1682 /* Convert to "jmp foo nop". */
1685 nop_offset
= irel
->r_offset
+ 3;
1686 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1687 irel
->r_offset
-= 1;
1688 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1692 struct elf_x86_link_hash_entry
*eh
1693 = (struct elf_x86_link_hash_entry
*) h
;
1695 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1698 /* To support TLS optimization, always use addr32 prefix for
1699 "call *__tls_get_addr@GOTPCREL(%rip)". */
1700 if (eh
&& eh
->tls_get_addr
)
1703 nop_offset
= irel
->r_offset
- 2;
1707 nop
= htab
->params
->call_nop_byte
;
1708 if (htab
->params
->call_nop_as_suffix
)
1710 nop_offset
= irel
->r_offset
+ 3;
1711 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1712 irel
->r_offset
-= 1;
1713 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1716 nop_offset
= irel
->r_offset
- 2;
1719 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1720 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1721 r_type
= R_X86_64_PC32
;
1726 unsigned int rex_mask
= REX_R
;
1728 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1729 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1735 if (abs_symbol
&& local_ref
)
1736 to_reloc_pc32
= FALSE
;
1740 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1741 "lea foo(%rip), %reg". */
1743 r_type
= R_X86_64_PC32
;
1747 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1748 "mov $foo, %reg". */
1750 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1751 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1752 if ((rex
& REX_W
) != 0
1753 && ABI_64_P (link_info
->output_bfd
))
1755 /* Keep the REX_W bit in REX byte for LP64. */
1756 r_type
= R_X86_64_32S
;
1757 goto rewrite_modrm_rex
;
1761 /* If the REX_W bit in REX byte isn't needed,
1762 use R_X86_64_32 and clear the W bit to avoid
1763 sign-extend imm32 to imm64. */
1764 r_type
= R_X86_64_32
;
1765 /* Clear the W bit in REX byte. */
1767 goto rewrite_modrm_rex
;
1773 /* R_X86_64_PC32 isn't supported. */
1777 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1780 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1781 "test $foo, %reg". */
1782 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1787 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1788 "binop $foo, %reg". */
1789 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1793 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1794 overflow when sign-extending imm32 to imm64. */
1795 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1800 /* Check if R_X86_64_32S/R_X86_64_32 fits. */
1801 if (r_type
== R_X86_64_32S
)
1803 if ((abs_relocation
+ 0x80000000) > 0xffffffff)
1808 if (abs_relocation
> 0xffffffff)
1813 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1817 /* Move the R bit to the B bit in REX byte. */
1818 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1819 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1822 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1826 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1830 irel
->r_info
= htab
->r_info (r_symndx
,
1831 r_type
| R_X86_64_converted_reloc_bit
);
1838 /* Look through the relocs for a section during the first phase, and
1839 calculate needed space in the global offset table, procedure
1840 linkage table, and dynamic reloc sections. */
1843 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1845 const Elf_Internal_Rela
*relocs
)
1847 struct elf_x86_link_hash_table
*htab
;
1848 Elf_Internal_Shdr
*symtab_hdr
;
1849 struct elf_link_hash_entry
**sym_hashes
;
1850 const Elf_Internal_Rela
*rel
;
1851 const Elf_Internal_Rela
*rel_end
;
1854 bfd_boolean converted
;
1856 if (bfd_link_relocatable (info
))
1859 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1862 sec
->check_relocs_failed
= 1;
1866 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1868 /* Get the section contents. */
1869 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1870 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1871 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1873 sec
->check_relocs_failed
= 1;
1877 symtab_hdr
= &elf_symtab_hdr (abfd
);
1878 sym_hashes
= elf_sym_hashes (abfd
);
1884 rel_end
= relocs
+ sec
->reloc_count
;
1885 for (rel
= relocs
; rel
< rel_end
; rel
++)
1887 unsigned int r_type
;
1888 unsigned int r_symndx
;
1889 struct elf_link_hash_entry
*h
;
1890 struct elf_x86_link_hash_entry
*eh
;
1891 Elf_Internal_Sym
*isym
;
1893 bfd_boolean size_reloc
;
1894 bfd_boolean converted_reloc
;
1895 bfd_boolean no_dynreloc
;
1897 r_symndx
= htab
->r_sym (rel
->r_info
);
1898 r_type
= ELF32_R_TYPE (rel
->r_info
);
1900 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1902 /* xgettext:c-format */
1903 _bfd_error_handler (_("%pB: bad symbol index: %d"),
1908 if (r_symndx
< symtab_hdr
->sh_info
)
1910 /* A local symbol. */
1911 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1916 /* Check relocation against local STT_GNU_IFUNC symbol. */
1917 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1919 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1924 /* Fake a STT_GNU_IFUNC symbol. */
1925 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1927 h
->type
= STT_GNU_IFUNC
;
1930 h
->forced_local
= 1;
1931 h
->root
.type
= bfd_link_hash_defined
;
1939 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1940 while (h
->root
.type
== bfd_link_hash_indirect
1941 || h
->root
.type
== bfd_link_hash_warning
)
1942 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1945 /* Check invalid x32 relocations. */
1946 if (!ABI_64_P (abfd
))
1952 case R_X86_64_DTPOFF64
:
1953 case R_X86_64_TPOFF64
:
1955 case R_X86_64_GOTOFF64
:
1956 case R_X86_64_GOT64
:
1957 case R_X86_64_GOTPCREL64
:
1958 case R_X86_64_GOTPC64
:
1959 case R_X86_64_GOTPLT64
:
1960 case R_X86_64_PLTOFF64
:
1963 name
= h
->root
.root
.string
;
1965 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1968 /* xgettext:c-format */
1969 (_("%pB: relocation %s against symbol `%s' isn't "
1970 "supported in x32 mode"), abfd
,
1971 x86_64_elf_howto_table
[r_type
].name
, name
);
1972 bfd_set_error (bfd_error_bad_value
);
1980 /* It is referenced by a non-shared object. */
1984 converted_reloc
= FALSE
;
1985 if ((r_type
== R_X86_64_GOTPCREL
1986 || r_type
== R_X86_64_GOTPCRELX
1987 || r_type
== R_X86_64_REX_GOTPCRELX
)
1988 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1990 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1991 if (!elf_x86_64_convert_load_reloc (abfd
, contents
, &r_type
,
1992 irel
, h
, &converted_reloc
,
1996 if (converted_reloc
)
2000 if (!_bfd_elf_x86_valid_reloc_p (sec
, info
, htab
, rel
, h
, isym
,
2001 symtab_hdr
, &no_dynreloc
))
2004 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2005 symtab_hdr
, sym_hashes
,
2006 &r_type
, GOT_UNKNOWN
,
2007 rel
, rel_end
, h
, r_symndx
, FALSE
))
2010 /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
2011 if (h
== htab
->elf
.hgot
)
2012 htab
->got_referenced
= TRUE
;
2014 eh
= (struct elf_x86_link_hash_entry
*) h
;
2017 case R_X86_64_TLSLD
:
2018 htab
->tls_ld_or_ldm_got
.refcount
= 1;
2021 case R_X86_64_TPOFF32
:
2022 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2023 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2024 &x86_64_elf_howto_table
[r_type
]);
2026 eh
->zero_undefweak
&= 0x2;
2029 case R_X86_64_GOTTPOFF
:
2030 if (!bfd_link_executable (info
))
2031 info
->flags
|= DF_STATIC_TLS
;
2034 case R_X86_64_GOT32
:
2035 case R_X86_64_GOTPCREL
:
2036 case R_X86_64_GOTPCRELX
:
2037 case R_X86_64_REX_GOTPCRELX
:
2038 case R_X86_64_TLSGD
:
2039 case R_X86_64_GOT64
:
2040 case R_X86_64_GOTPCREL64
:
2041 case R_X86_64_GOTPLT64
:
2042 case R_X86_64_GOTPC32_TLSDESC
:
2043 case R_X86_64_TLSDESC_CALL
:
2044 /* This symbol requires a global offset table entry. */
2046 int tls_type
, old_tls_type
;
2051 tls_type
= GOT_NORMAL
;
2054 if (ABS_SYMBOL_P (h
))
2057 else if (isym
->st_shndx
== SHN_ABS
)
2060 case R_X86_64_TLSGD
:
2061 tls_type
= GOT_TLS_GD
;
2063 case R_X86_64_GOTTPOFF
:
2064 tls_type
= GOT_TLS_IE
;
2066 case R_X86_64_GOTPC32_TLSDESC
:
2067 case R_X86_64_TLSDESC_CALL
:
2068 tls_type
= GOT_TLS_GDESC
;
2074 h
->got
.refcount
= 1;
2075 old_tls_type
= eh
->tls_type
;
2079 bfd_signed_vma
*local_got_refcounts
;
2081 /* This is a global offset table entry for a local symbol. */
2082 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2083 if (local_got_refcounts
== NULL
)
2087 size
= symtab_hdr
->sh_info
;
2088 size
*= sizeof (bfd_signed_vma
)
2089 + sizeof (bfd_vma
) + sizeof (char);
2090 local_got_refcounts
= ((bfd_signed_vma
*)
2091 bfd_zalloc (abfd
, size
));
2092 if (local_got_refcounts
== NULL
)
2094 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2095 elf_x86_local_tlsdesc_gotent (abfd
)
2096 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2097 elf_x86_local_got_tls_type (abfd
)
2098 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2100 local_got_refcounts
[r_symndx
] = 1;
2102 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2105 /* If a TLS symbol is accessed using IE at least once,
2106 there is no point to use dynamic model for it. */
2107 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2108 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2109 || tls_type
!= GOT_TLS_IE
))
2111 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2112 tls_type
= old_tls_type
;
2113 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2114 && GOT_TLS_GD_ANY_P (tls_type
))
2115 tls_type
|= old_tls_type
;
2119 name
= h
->root
.root
.string
;
2121 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2124 /* xgettext:c-format */
2125 (_("%pB: '%s' accessed both as normal and"
2126 " thread local symbol"),
2128 bfd_set_error (bfd_error_bad_value
);
2133 if (old_tls_type
!= tls_type
)
2136 eh
->tls_type
= tls_type
;
2138 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2143 case R_X86_64_GOTOFF64
:
2144 case R_X86_64_GOTPC32
:
2145 case R_X86_64_GOTPC64
:
2148 eh
->zero_undefweak
&= 0x2;
2151 case R_X86_64_PLT32
:
2152 case R_X86_64_PLT32_BND
:
2153 /* This symbol requires a procedure linkage table entry. We
2154 actually build the entry in adjust_dynamic_symbol,
2155 because this might be a case of linking PIC code which is
2156 never referenced by a dynamic object, in which case we
2157 don't need to generate a procedure linkage table entry
2160 /* If this is a local symbol, we resolve it directly without
2161 creating a procedure linkage table entry. */
2165 eh
->zero_undefweak
&= 0x2;
2167 h
->plt
.refcount
= 1;
2170 case R_X86_64_PLTOFF64
:
2171 /* This tries to form the 'address' of a function relative
2172 to GOT. For global symbols we need a PLT entry. */
2176 h
->plt
.refcount
= 1;
2180 case R_X86_64_SIZE32
:
2181 case R_X86_64_SIZE64
:
2186 if (!ABI_64_P (abfd
))
2192 /* Check relocation overflow as these relocs may lead to
2193 run-time relocation overflow. Don't error out for
2194 sections we don't care about, such as debug sections or
2195 when relocation overflow check is disabled. */
2196 if (!htab
->params
->no_reloc_overflow_check
2198 && (bfd_link_pic (info
)
2199 || (bfd_link_executable (info
)
2203 && (sec
->flags
& SEC_READONLY
) == 0)))
2204 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2205 &x86_64_elf_howto_table
[r_type
]);
2211 case R_X86_64_PC32_BND
:
2215 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2216 eh
->zero_undefweak
|= 0x2;
2217 /* We are called after all symbols have been resolved. Only
2218 relocation against STT_GNU_IFUNC symbol must go through
2221 && (bfd_link_executable (info
)
2222 || h
->type
== STT_GNU_IFUNC
))
2224 bfd_boolean func_pointer_ref
= FALSE
;
2226 if (r_type
== R_X86_64_PC32
)
2228 /* Since something like ".long foo - ." may be used
2229 as pointer, make sure that PLT is used if foo is
2230 a function defined in a shared library. */
2231 if ((sec
->flags
& SEC_CODE
) == 0)
2233 h
->pointer_equality_needed
= 1;
2234 if (bfd_link_pie (info
)
2235 && h
->type
== STT_FUNC
2240 h
->plt
.refcount
= 1;
2244 else if (r_type
!= R_X86_64_PC32_BND
2245 && r_type
!= R_X86_64_PC64
)
2247 h
->pointer_equality_needed
= 1;
2248 /* At run-time, R_X86_64_64 can be resolved for both
2249 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2250 can only be resolved for x32. */
2251 if ((sec
->flags
& SEC_READONLY
) == 0
2252 && (r_type
== R_X86_64_64
2253 || (!ABI_64_P (abfd
)
2254 && (r_type
== R_X86_64_32
2255 || r_type
== R_X86_64_32S
))))
2256 func_pointer_ref
= TRUE
;
2259 if (!func_pointer_ref
)
2261 /* If this reloc is in a read-only section, we might
2262 need a copy reloc. We can't check reliably at this
2263 stage whether the section is read-only, as input
2264 sections have not yet been mapped to output sections.
2265 Tentatively set the flag for now, and correct in
2266 adjust_dynamic_symbol. */
2269 /* We may need a .plt entry if the symbol is a function
2270 defined in a shared lib or is a function referenced
2271 from the code or read-only section. */
2273 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2274 h
->plt
.refcount
= 1;
2281 && NEED_DYNAMIC_RELOCATION_P (info
, TRUE
, h
, sec
, r_type
,
2282 htab
->pointer_r_type
))
2284 struct elf_dyn_relocs
*p
;
2285 struct elf_dyn_relocs
**head
;
2287 /* We must copy these reloc types into the output file.
2288 Create a reloc section in dynobj and make room for
2292 sreloc
= _bfd_elf_make_dynamic_reloc_section
2293 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2294 abfd
, /*rela?*/ TRUE
);
2300 /* If this is a global symbol, we count the number of
2301 relocations we need for this symbol. */
2303 head
= &h
->dyn_relocs
;
2306 /* Track dynamic relocs needed for local syms too.
2307 We really need local syms available to do this
2312 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2317 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2321 /* Beware of type punned pointers vs strict aliasing
2323 vpp
= &(elf_section_data (s
)->local_dynrel
);
2324 head
= (struct elf_dyn_relocs
**)vpp
;
2328 if (p
== NULL
|| p
->sec
!= sec
)
2330 size_t amt
= sizeof *p
;
2332 p
= ((struct elf_dyn_relocs
*)
2333 bfd_alloc (htab
->elf
.dynobj
, amt
));
2344 /* Count size relocation as PC-relative relocation. */
2345 if (X86_PCREL_TYPE_P (r_type
) || size_reloc
)
2350 /* This relocation describes the C++ object vtable hierarchy.
2351 Reconstruct it for later use during GC. */
2352 case R_X86_64_GNU_VTINHERIT
:
2353 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2357 /* This relocation describes which C++ vtable entries are actually
2358 used. Record for later use during GC. */
2359 case R_X86_64_GNU_VTENTRY
:
2360 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2369 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2371 if (!converted
&& !info
->keep_memory
)
2375 /* Cache the section contents for elf_link_input_bfd if any
2376 load is converted or --no-keep-memory isn't used. */
2377 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2381 /* Cache relocations if any load is converted. */
2382 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
2383 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
2388 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2390 sec
->check_relocs_failed
= 1;
2394 /* Return the relocation value for @tpoff relocation
2395 if STT_TLS virtual address is ADDRESS. */
2398 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2400 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2401 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2402 bfd_vma static_tls_size
;
2404 /* If tls_segment is NULL, we should have signalled an error already. */
2405 if (htab
->tls_sec
== NULL
)
2408 /* Consider special static TLS alignment requirements. */
2409 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2410 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2413 /* Relocate an x86_64 ELF section. */
2416 elf_x86_64_relocate_section (bfd
*output_bfd
,
2417 struct bfd_link_info
*info
,
2419 asection
*input_section
,
2421 Elf_Internal_Rela
*relocs
,
2422 Elf_Internal_Sym
*local_syms
,
2423 asection
**local_sections
)
2425 struct elf_x86_link_hash_table
*htab
;
2426 Elf_Internal_Shdr
*symtab_hdr
;
2427 struct elf_link_hash_entry
**sym_hashes
;
2428 bfd_vma
*local_got_offsets
;
2429 bfd_vma
*local_tlsdesc_gotents
;
2430 Elf_Internal_Rela
*rel
;
2431 Elf_Internal_Rela
*wrel
;
2432 Elf_Internal_Rela
*relend
;
2433 unsigned int plt_entry_size
;
2435 /* Skip if check_relocs failed. */
2436 if (input_section
->check_relocs_failed
)
2439 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2443 if (!is_x86_elf (input_bfd
, htab
))
2445 bfd_set_error (bfd_error_wrong_format
);
2449 plt_entry_size
= htab
->plt
.plt_entry_size
;
2450 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2451 sym_hashes
= elf_sym_hashes (input_bfd
);
2452 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2453 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2455 _bfd_x86_elf_set_tls_module_base (info
);
2457 rel
= wrel
= relocs
;
2458 relend
= relocs
+ input_section
->reloc_count
;
2459 for (; rel
< relend
; wrel
++, rel
++)
2461 unsigned int r_type
, r_type_tls
;
2462 reloc_howto_type
*howto
;
2463 unsigned long r_symndx
;
2464 struct elf_link_hash_entry
*h
;
2465 struct elf_x86_link_hash_entry
*eh
;
2466 Elf_Internal_Sym
*sym
;
2468 bfd_vma off
, offplt
, plt_offset
;
2470 bfd_boolean unresolved_reloc
;
2471 bfd_reloc_status_type r
;
2473 asection
*base_got
, *resolved_plt
;
2475 bfd_boolean resolved_to_zero
;
2476 bfd_boolean relative_reloc
;
2477 bfd_boolean converted_reloc
;
2478 bfd_boolean need_copy_reloc_in_pie
;
2479 bfd_boolean no_copyreloc_p
;
2481 r_type
= ELF32_R_TYPE (rel
->r_info
);
2482 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2483 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2490 r_symndx
= htab
->r_sym (rel
->r_info
);
2491 converted_reloc
= (r_type
& R_X86_64_converted_reloc_bit
) != 0;
2492 if (converted_reloc
)
2494 r_type
&= ~R_X86_64_converted_reloc_bit
;
2495 rel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2498 howto
= elf_x86_64_rtype_to_howto (input_bfd
, r_type
);
2500 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2505 unresolved_reloc
= FALSE
;
2506 if (r_symndx
< symtab_hdr
->sh_info
)
2508 sym
= local_syms
+ r_symndx
;
2509 sec
= local_sections
[r_symndx
];
2511 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2513 st_size
= sym
->st_size
;
2515 /* Relocate against local STT_GNU_IFUNC symbol. */
2516 if (!bfd_link_relocatable (info
)
2517 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2519 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
2524 /* Set STT_GNU_IFUNC symbol value. */
2525 h
->root
.u
.def
.value
= sym
->st_value
;
2526 h
->root
.u
.def
.section
= sec
;
2531 bfd_boolean warned ATTRIBUTE_UNUSED
;
2532 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2534 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2535 r_symndx
, symtab_hdr
, sym_hashes
,
2537 unresolved_reloc
, warned
, ignored
);
2541 if (sec
!= NULL
&& discarded_section (sec
))
2543 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2544 contents
, rel
->r_offset
);
2545 wrel
->r_offset
= rel
->r_offset
;
2549 /* For ld -r, remove relocations in debug sections against
2550 sections defined in discarded sections. Not done for
2551 eh_frame editing code expects to be present. */
2552 if (bfd_link_relocatable (info
)
2553 && (input_section
->flags
& SEC_DEBUGGING
))
2559 if (bfd_link_relocatable (info
))
2566 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
2568 if (r_type
== R_X86_64_64
)
2570 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2571 zero-extend it to 64bit if addend is zero. */
2572 r_type
= R_X86_64_32
;
2573 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2575 else if (r_type
== R_X86_64_SIZE64
)
2577 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2578 zero-extend it to 64bit if addend is zero. */
2579 r_type
= R_X86_64_SIZE32
;
2580 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2584 eh
= (struct elf_x86_link_hash_entry
*) h
;
2586 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2587 it here if it is defined in a non-shared object. */
2589 && h
->type
== STT_GNU_IFUNC
2595 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2597 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
2598 STT_GNU_IFUNC symbol as STT_FUNC. */
2599 if (elf_section_type (input_section
) == SHT_NOTE
)
2601 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2602 sections because such sections are not SEC_ALLOC and
2603 thus ld.so will not process them. */
2604 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2614 case R_X86_64_GOTPCREL
:
2615 case R_X86_64_GOTPCRELX
:
2616 case R_X86_64_REX_GOTPCRELX
:
2617 case R_X86_64_GOTPCREL64
:
2618 base_got
= htab
->elf
.sgot
;
2619 off
= h
->got
.offset
;
2621 if (base_got
== NULL
)
2624 if (off
== (bfd_vma
) -1)
2626 /* We can't use h->got.offset here to save state, or
2627 even just remember the offset, as finish_dynamic_symbol
2628 would use that as offset into .got. */
2630 if (h
->plt
.offset
== (bfd_vma
) -1)
2633 if (htab
->elf
.splt
!= NULL
)
2635 plt_index
= (h
->plt
.offset
/ plt_entry_size
2636 - htab
->plt
.has_plt0
);
2637 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2638 base_got
= htab
->elf
.sgotplt
;
2642 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2643 off
= plt_index
* GOT_ENTRY_SIZE
;
2644 base_got
= htab
->elf
.igotplt
;
2647 if (h
->dynindx
== -1
2651 /* This references the local defitionion. We must
2652 initialize this entry in the global offset table.
2653 Since the offset must always be a multiple of 8,
2654 we use the least significant bit to record
2655 whether we have initialized it already.
2657 When doing a dynamic link, we create a .rela.got
2658 relocation entry to initialize the value. This
2659 is done in the finish_dynamic_symbol routine. */
2664 bfd_put_64 (output_bfd
, relocation
,
2665 base_got
->contents
+ off
);
2666 /* Note that this is harmless for the GOTPLT64
2667 case, as -1 | 1 still is -1. */
2673 relocation
= (base_got
->output_section
->vma
2674 + base_got
->output_offset
+ off
);
2679 if (h
->plt
.offset
== (bfd_vma
) -1)
2681 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2682 if (r_type
== htab
->pointer_r_type
2683 && (input_section
->flags
& SEC_CODE
) == 0)
2684 goto do_ifunc_pointer
;
2685 goto bad_ifunc_reloc
;
2688 /* STT_GNU_IFUNC symbol must go through PLT. */
2689 if (htab
->elf
.splt
!= NULL
)
2691 if (htab
->plt_second
!= NULL
)
2693 resolved_plt
= htab
->plt_second
;
2694 plt_offset
= eh
->plt_second
.offset
;
2698 resolved_plt
= htab
->elf
.splt
;
2699 plt_offset
= h
->plt
.offset
;
2704 resolved_plt
= htab
->elf
.iplt
;
2705 plt_offset
= h
->plt
.offset
;
2708 relocation
= (resolved_plt
->output_section
->vma
2709 + resolved_plt
->output_offset
+ plt_offset
);
2715 if (h
->root
.root
.string
)
2716 name
= h
->root
.root
.string
;
2718 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2721 /* xgettext:c-format */
2722 (_("%pB: relocation %s against STT_GNU_IFUNC "
2723 "symbol `%s' isn't supported"), input_bfd
,
2725 bfd_set_error (bfd_error_bad_value
);
2729 if (bfd_link_pic (info
))
2734 if (ABI_64_P (output_bfd
))
2739 if (rel
->r_addend
!= 0)
2741 if (h
->root
.root
.string
)
2742 name
= h
->root
.root
.string
;
2744 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2747 /* xgettext:c-format */
2748 (_("%pB: relocation %s against STT_GNU_IFUNC "
2749 "symbol `%s' has non-zero addend: %" PRId64
),
2750 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
2751 bfd_set_error (bfd_error_bad_value
);
2755 /* Generate dynamic relcoation only when there is a
2756 non-GOT reference in a shared object or there is no
2758 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2759 || h
->plt
.offset
== (bfd_vma
) -1)
2761 Elf_Internal_Rela outrel
;
2764 /* Need a dynamic relocation to get the real function
2766 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2770 if (outrel
.r_offset
== (bfd_vma
) -1
2771 || outrel
.r_offset
== (bfd_vma
) -2)
2774 outrel
.r_offset
+= (input_section
->output_section
->vma
2775 + input_section
->output_offset
);
2777 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2779 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
2780 h
->root
.root
.string
,
2781 h
->root
.u
.def
.section
->owner
);
2783 /* This symbol is resolved locally. */
2784 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2785 outrel
.r_addend
= (h
->root
.u
.def
.value
2786 + h
->root
.u
.def
.section
->output_section
->vma
2787 + h
->root
.u
.def
.section
->output_offset
);
2791 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2792 outrel
.r_addend
= 0;
2795 /* Dynamic relocations are stored in
2796 1. .rela.ifunc section in PIC object.
2797 2. .rela.got section in dynamic executable.
2798 3. .rela.iplt section in static executable. */
2799 if (bfd_link_pic (info
))
2800 sreloc
= htab
->elf
.irelifunc
;
2801 else if (htab
->elf
.splt
!= NULL
)
2802 sreloc
= htab
->elf
.srelgot
;
2804 sreloc
= htab
->elf
.irelplt
;
2805 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2807 /* If this reloc is against an external symbol, we
2808 do not want to fiddle with the addend. Otherwise,
2809 we need to include the symbol value so that it
2810 becomes an addend for the dynamic reloc. For an
2811 internal symbol, we have updated addend. */
2816 case R_X86_64_PC32_BND
:
2818 case R_X86_64_PLT32
:
2819 case R_X86_64_PLT32_BND
:
2825 resolved_to_zero
= (eh
!= NULL
2826 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2828 /* When generating a shared object, the relocations handled here are
2829 copied into the output file to be resolved at run time. */
2832 case R_X86_64_GOT32
:
2833 case R_X86_64_GOT64
:
2834 /* Relocation is to the entry for this symbol in the global
2836 case R_X86_64_GOTPCREL
:
2837 case R_X86_64_GOTPCRELX
:
2838 case R_X86_64_REX_GOTPCRELX
:
2839 case R_X86_64_GOTPCREL64
:
2840 /* Use global offset table entry as symbol value. */
2841 case R_X86_64_GOTPLT64
:
2842 /* This is obsolete and treated the same as GOT64. */
2843 base_got
= htab
->elf
.sgot
;
2845 if (htab
->elf
.sgot
== NULL
)
2848 relative_reloc
= FALSE
;
2851 off
= h
->got
.offset
;
2853 && h
->plt
.offset
!= (bfd_vma
)-1
2854 && off
== (bfd_vma
)-1)
2856 /* We can't use h->got.offset here to save
2857 state, or even just remember the offset, as
2858 finish_dynamic_symbol would use that as offset into
2860 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
2861 - htab
->plt
.has_plt0
);
2862 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2863 base_got
= htab
->elf
.sgotplt
;
2866 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2868 /* We must initialize this entry in the global offset
2869 table. Since the offset must always be a multiple
2870 of 8, we use the least significant bit to record
2871 whether we have initialized it already.
2873 When doing a dynamic link, we create a .rela.got
2874 relocation entry to initialize the value. This is
2875 done in the finish_dynamic_symbol routine. */
2880 bfd_put_64 (output_bfd
, relocation
,
2881 base_got
->contents
+ off
);
2882 /* Note that this is harmless for the GOTPLT64 case,
2883 as -1 | 1 still is -1. */
2886 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
2888 /* If this symbol isn't dynamic in PIC,
2889 generate R_X86_64_RELATIVE here. */
2890 eh
->no_finish_dynamic_symbol
= 1;
2891 relative_reloc
= TRUE
;
2896 unresolved_reloc
= FALSE
;
2900 if (local_got_offsets
== NULL
)
2903 off
= local_got_offsets
[r_symndx
];
2905 /* The offset must always be a multiple of 8. We use
2906 the least significant bit to record whether we have
2907 already generated the necessary reloc. */
2912 bfd_put_64 (output_bfd
, relocation
,
2913 base_got
->contents
+ off
);
2914 local_got_offsets
[r_symndx
] |= 1;
2916 /* NB: GOTPCREL relocations against local absolute
2917 symbol store relocation value in the GOT slot
2918 without relative relocation. */
2919 if (bfd_link_pic (info
)
2920 && !(sym
->st_shndx
== SHN_ABS
2921 && (r_type
== R_X86_64_GOTPCREL
2922 || r_type
== R_X86_64_GOTPCRELX
2923 || r_type
== R_X86_64_REX_GOTPCRELX
)))
2924 relative_reloc
= TRUE
;
2931 Elf_Internal_Rela outrel
;
2933 /* We need to generate a R_X86_64_RELATIVE reloc
2934 for the dynamic linker. */
2935 s
= htab
->elf
.srelgot
;
2939 outrel
.r_offset
= (base_got
->output_section
->vma
2940 + base_got
->output_offset
2942 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
2943 outrel
.r_addend
= relocation
;
2944 elf_append_rela (output_bfd
, s
, &outrel
);
2947 if (off
>= (bfd_vma
) -2)
2950 relocation
= base_got
->output_section
->vma
2951 + base_got
->output_offset
+ off
;
2952 if (r_type
!= R_X86_64_GOTPCREL
2953 && r_type
!= R_X86_64_GOTPCRELX
2954 && r_type
!= R_X86_64_REX_GOTPCRELX
2955 && r_type
!= R_X86_64_GOTPCREL64
)
2956 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2957 - htab
->elf
.sgotplt
->output_offset
;
2961 case R_X86_64_GOTOFF64
:
2962 /* Relocation is relative to the start of the global offset
2965 /* Check to make sure it isn't a protected function or data
2966 symbol for shared library since it may not be local when
2967 used as function address or with copy relocation. We also
2968 need to make sure that a symbol is referenced locally. */
2969 if (bfd_link_pic (info
) && h
)
2971 if (!h
->def_regular
)
2975 switch (ELF_ST_VISIBILITY (h
->other
))
2978 v
= _("hidden symbol");
2981 v
= _("internal symbol");
2984 v
= _("protected symbol");
2992 /* xgettext:c-format */
2993 (_("%pB: relocation R_X86_64_GOTOFF64 against undefined %s"
2994 " `%s' can not be used when making a shared object"),
2995 input_bfd
, v
, h
->root
.root
.string
);
2996 bfd_set_error (bfd_error_bad_value
);
2999 else if (!bfd_link_executable (info
)
3000 && !SYMBOL_REFERENCES_LOCAL_P (info
, h
)
3001 && (h
->type
== STT_FUNC
3002 || h
->type
== STT_OBJECT
)
3003 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3006 /* xgettext:c-format */
3007 (_("%pB: relocation R_X86_64_GOTOFF64 against protected %s"
3008 " `%s' can not be used when making a shared object"),
3010 h
->type
== STT_FUNC
? "function" : "data",
3011 h
->root
.root
.string
);
3012 bfd_set_error (bfd_error_bad_value
);
3017 /* Note that sgot is not involved in this
3018 calculation. We always want the start of .got.plt. If we
3019 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3020 permitted by the ABI, we might have to change this
3022 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3023 + htab
->elf
.sgotplt
->output_offset
;
3026 case R_X86_64_GOTPC32
:
3027 case R_X86_64_GOTPC64
:
3028 /* Use global offset table as symbol value. */
3029 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3030 + htab
->elf
.sgotplt
->output_offset
;
3031 unresolved_reloc
= FALSE
;
3034 case R_X86_64_PLTOFF64
:
3035 /* Relocation is PLT entry relative to GOT. For local
3036 symbols it's the symbol itself relative to GOT. */
3038 /* See PLT32 handling. */
3039 && (h
->plt
.offset
!= (bfd_vma
) -1
3040 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
3041 && htab
->elf
.splt
!= NULL
)
3043 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
3045 /* Use the GOT PLT. */
3046 resolved_plt
= htab
->plt_got
;
3047 plt_offset
= eh
->plt_got
.offset
;
3049 else if (htab
->plt_second
!= NULL
)
3051 resolved_plt
= htab
->plt_second
;
3052 plt_offset
= eh
->plt_second
.offset
;
3056 resolved_plt
= htab
->elf
.splt
;
3057 plt_offset
= h
->plt
.offset
;
3060 relocation
= (resolved_plt
->output_section
->vma
3061 + resolved_plt
->output_offset
3063 unresolved_reloc
= FALSE
;
3066 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3067 + htab
->elf
.sgotplt
->output_offset
;
3070 case R_X86_64_PLT32
:
3071 case R_X86_64_PLT32_BND
:
3072 /* Relocation is to the entry for this symbol in the
3073 procedure linkage table. */
3075 /* Resolve a PLT32 reloc against a local symbol directly,
3076 without using the procedure linkage table. */
3080 if ((h
->plt
.offset
== (bfd_vma
) -1
3081 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3082 || htab
->elf
.splt
== NULL
)
3084 /* We didn't make a PLT entry for this symbol. This
3085 happens when statically linking PIC code, or when
3086 using -Bsymbolic. */
3091 if (h
->plt
.offset
!= (bfd_vma
) -1)
3093 if (htab
->plt_second
!= NULL
)
3095 resolved_plt
= htab
->plt_second
;
3096 plt_offset
= eh
->plt_second
.offset
;
3100 resolved_plt
= htab
->elf
.splt
;
3101 plt_offset
= h
->plt
.offset
;
3106 /* Use the GOT PLT. */
3107 resolved_plt
= htab
->plt_got
;
3108 plt_offset
= eh
->plt_got
.offset
;
3111 relocation
= (resolved_plt
->output_section
->vma
3112 + resolved_plt
->output_offset
3114 unresolved_reloc
= FALSE
;
3117 case R_X86_64_SIZE32
:
3118 case R_X86_64_SIZE64
:
3119 /* Set to symbol size. */
3120 relocation
= st_size
;
3126 case R_X86_64_PC32_BND
:
3127 /* Don't complain about -fPIC if the symbol is undefined when
3128 building executable unless it is unresolved weak symbol,
3129 references a dynamic definition in PIE or -z nocopyreloc
3132 = (info
->nocopyreloc
3134 && !h
->root
.linker_def
3135 && !h
->root
.ldscript_def
3136 && eh
->def_protected
3137 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)));
3139 if ((input_section
->flags
& SEC_ALLOC
) != 0
3140 && (input_section
->flags
& SEC_READONLY
) != 0
3142 && ((bfd_link_executable (info
)
3143 && ((h
->root
.type
== bfd_link_hash_undefweak
3145 || !UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3147 || (bfd_link_pie (info
)
3148 && !SYMBOL_DEFINED_NON_SHARED_P (h
)
3152 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
3153 || bfd_link_dll (info
)))
3155 bfd_boolean fail
= FALSE
;
3156 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3158 /* Symbol is referenced locally. Make sure it is
3160 fail
= !SYMBOL_DEFINED_NON_SHARED_P (h
);
3162 else if (bfd_link_pie (info
))
3164 /* We can only use PC-relative relocations in PIE
3165 from non-code sections. */
3166 if (h
->type
== STT_FUNC
3167 && (sec
->flags
& SEC_CODE
) != 0)
3170 else if (no_copyreloc_p
|| bfd_link_dll (info
))
3172 /* Symbol doesn't need copy reloc and isn't
3173 referenced locally. Don't allow PC-relative
3174 relocations against default and protected
3175 symbols since address of protected function
3176 and location of protected data may not be in
3177 the shared object. */
3178 fail
= (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3179 || ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
);
3183 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3184 h
, NULL
, NULL
, howto
);
3186 /* Since x86-64 has PC-relative PLT, we can use PLT in PIE
3187 as function address. */
3189 && (input_section
->flags
& SEC_CODE
) == 0
3190 && bfd_link_pie (info
)
3191 && h
->type
== STT_FUNC
3202 /* FIXME: The ABI says the linker should make sure the value is
3203 the same when it's zeroextended to 64 bit. */
3206 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3209 need_copy_reloc_in_pie
= (bfd_link_pie (info
)
3214 == bfd_link_hash_undefined
))
3215 && (X86_PCREL_TYPE_P (r_type
)
3216 || X86_SIZE_TYPE_P (r_type
)));
3218 if (GENERATE_DYNAMIC_RELOCATION_P (info
, eh
, r_type
, sec
,
3219 need_copy_reloc_in_pie
,
3220 resolved_to_zero
, FALSE
))
3222 Elf_Internal_Rela outrel
;
3223 bfd_boolean skip
, relocate
;
3226 /* When generating a shared object, these relocations
3227 are copied into the output file to be resolved at run
3233 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3235 if (outrel
.r_offset
== (bfd_vma
) -1)
3237 else if (outrel
.r_offset
== (bfd_vma
) -2)
3238 skip
= TRUE
, relocate
= TRUE
;
3240 outrel
.r_offset
+= (input_section
->output_section
->vma
3241 + input_section
->output_offset
);
3244 memset (&outrel
, 0, sizeof outrel
);
3246 else if (COPY_INPUT_RELOC_P (info
, h
, r_type
))
3248 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3249 outrel
.r_addend
= rel
->r_addend
;
3253 /* This symbol is local, or marked to become local.
3254 When relocation overflow check is disabled, we
3255 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3256 if (r_type
== htab
->pointer_r_type
3257 || (r_type
== R_X86_64_32
3258 && htab
->params
->no_reloc_overflow_check
))
3261 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3262 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3264 else if (r_type
== R_X86_64_64
3265 && !ABI_64_P (output_bfd
))
3268 outrel
.r_info
= htab
->r_info (0,
3269 R_X86_64_RELATIVE64
);
3270 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3271 /* Check addend overflow. */
3272 if ((outrel
.r_addend
& 0x80000000)
3273 != (rel
->r_addend
& 0x80000000))
3276 int addend
= rel
->r_addend
;
3277 if (h
&& h
->root
.root
.string
)
3278 name
= h
->root
.root
.string
;
3280 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3283 /* xgettext:c-format */
3284 (_("%pB: addend %s%#x in relocation %s against "
3285 "symbol `%s' at %#" PRIx64
3286 " in section `%pA' is out of range"),
3287 input_bfd
, addend
< 0 ? "-" : "", addend
,
3288 howto
->name
, name
, (uint64_t) rel
->r_offset
,
3290 bfd_set_error (bfd_error_bad_value
);
3298 if (bfd_is_abs_section (sec
))
3300 else if (sec
== NULL
|| sec
->owner
== NULL
)
3302 bfd_set_error (bfd_error_bad_value
);
3309 /* We are turning this relocation into one
3310 against a section symbol. It would be
3311 proper to subtract the symbol's value,
3312 osec->vma, from the emitted reloc addend,
3313 but ld.so expects buggy relocs. */
3314 osec
= sec
->output_section
;
3315 sindx
= elf_section_data (osec
)->dynindx
;
3318 asection
*oi
= htab
->elf
.text_index_section
;
3319 sindx
= elf_section_data (oi
)->dynindx
;
3321 BFD_ASSERT (sindx
!= 0);
3324 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3325 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3329 sreloc
= elf_section_data (input_section
)->sreloc
;
3331 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3333 r
= bfd_reloc_notsupported
;
3334 goto check_relocation_error
;
3337 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3339 /* If this reloc is against an external symbol, we do
3340 not want to fiddle with the addend. Otherwise, we
3341 need to include the symbol value so that it becomes
3342 an addend for the dynamic reloc. */
3349 case R_X86_64_TLSGD
:
3350 case R_X86_64_GOTPC32_TLSDESC
:
3351 case R_X86_64_TLSDESC_CALL
:
3352 case R_X86_64_GOTTPOFF
:
3353 tls_type
= GOT_UNKNOWN
;
3354 if (h
== NULL
&& local_got_offsets
)
3355 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3357 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
3359 r_type_tls
= r_type
;
3360 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3361 input_section
, contents
,
3362 symtab_hdr
, sym_hashes
,
3363 &r_type_tls
, tls_type
, rel
,
3364 relend
, h
, r_symndx
, TRUE
))
3367 if (r_type_tls
== R_X86_64_TPOFF32
)
3369 bfd_vma roff
= rel
->r_offset
;
3371 BFD_ASSERT (! unresolved_reloc
);
3373 if (r_type
== R_X86_64_TLSGD
)
3375 /* GD->LE transition. For 64bit, change
3376 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3377 .word 0x6666; rex64; call __tls_get_addr@PLT
3379 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3381 call *__tls_get_addr@GOTPCREL(%rip)
3382 which may be converted to
3383 addr32 call __tls_get_addr
3386 leaq foo@tpoff(%rax), %rax
3388 leaq foo@tlsgd(%rip), %rdi
3389 .word 0x6666; rex64; call __tls_get_addr@PLT
3391 leaq foo@tlsgd(%rip), %rdi
3393 call *__tls_get_addr@GOTPCREL(%rip)
3394 which may be converted to
3395 addr32 call __tls_get_addr
3398 leaq foo@tpoff(%rax), %rax
3399 For largepic, change:
3400 leaq foo@tlsgd(%rip), %rdi
3401 movabsq $__tls_get_addr@pltoff, %rax
3406 leaq foo@tpoff(%rax), %rax
3407 nopw 0x0(%rax,%rax,1) */
3409 if (ABI_64_P (output_bfd
))
3411 if (contents
[roff
+ 5] == 0xb8)
3414 || (roff
- 3 + 22) > input_section
->size
)
3417 info
->callbacks
->einfo
3418 (_("%F%P: corrupt input: %pB\n"),
3422 memcpy (contents
+ roff
- 3,
3423 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3424 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3430 || (roff
- 4 + 16) > input_section
->size
)
3432 memcpy (contents
+ roff
- 4,
3433 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3440 || (roff
- 3 + 15) > input_section
->size
)
3442 memcpy (contents
+ roff
- 3,
3443 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3446 bfd_put_32 (output_bfd
,
3447 elf_x86_64_tpoff (info
, relocation
),
3448 contents
+ roff
+ 8 + largepic
);
3449 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3450 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3455 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3457 /* GDesc -> LE transition.
3458 It's originally something like:
3459 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3460 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3463 movq $x@tpoff, %rax <--- LP64 mode.
3464 rex movl $x@tpoff, %eax <--- X32 mode.
3467 unsigned int val
, type
;
3471 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3472 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3473 bfd_put_8 (output_bfd
,
3474 (type
& 0x48) | ((type
>> 2) & 1),
3475 contents
+ roff
- 3);
3476 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3477 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3478 contents
+ roff
- 1);
3479 bfd_put_32 (output_bfd
,
3480 elf_x86_64_tpoff (info
, relocation
),
3484 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3486 /* GDesc -> LE transition.
3488 call *(%rax) <--- LP64 mode.
3489 call *(%eax) <--- X32 mode.
3491 xchg %ax,%ax <-- LP64 mode.
3492 nopl (%rax) <-- X32 mode.
3494 unsigned int prefix
= 0;
3495 if (!ABI_64_P (input_bfd
))
3497 /* Check for call *x@tlsdesc(%eax). */
3498 if (contents
[roff
] == 0x67)
3503 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
3504 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
3505 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
3509 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3510 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3514 else if (r_type
== R_X86_64_GOTTPOFF
)
3516 /* IE->LE transition:
3517 For 64bit, originally it can be one of:
3518 movq foo@gottpoff(%rip), %reg
3519 addq foo@gottpoff(%rip), %reg
3522 leaq foo(%reg), %reg
3524 For 32bit, originally it can be one of:
3525 movq foo@gottpoff(%rip), %reg
3526 addl foo@gottpoff(%rip), %reg
3529 leal foo(%reg), %reg
3532 unsigned int val
, type
, reg
;
3535 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3542 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3543 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3552 bfd_put_8 (output_bfd
, 0x49,
3553 contents
+ roff
- 3);
3555 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3559 bfd_put_8 (output_bfd
, 0x41,
3560 contents
+ roff
- 3);
3562 bfd_put_8 (output_bfd
, 0xc7,
3563 contents
+ roff
- 2);
3564 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3565 contents
+ roff
- 1);
3569 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3575 bfd_put_8 (output_bfd
, 0x49,
3576 contents
+ roff
- 3);
3578 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3582 bfd_put_8 (output_bfd
, 0x41,
3583 contents
+ roff
- 3);
3585 bfd_put_8 (output_bfd
, 0x81,
3586 contents
+ roff
- 2);
3587 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3588 contents
+ roff
- 1);
3592 /* addq/addl -> leaq/leal */
3597 bfd_put_8 (output_bfd
, 0x4d,
3598 contents
+ roff
- 3);
3600 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3604 bfd_put_8 (output_bfd
, 0x45,
3605 contents
+ roff
- 3);
3607 bfd_put_8 (output_bfd
, 0x8d,
3608 contents
+ roff
- 2);
3609 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3610 contents
+ roff
- 1);
3612 bfd_put_32 (output_bfd
,
3613 elf_x86_64_tpoff (info
, relocation
),
3621 if (htab
->elf
.sgot
== NULL
)
3626 off
= h
->got
.offset
;
3627 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3631 if (local_got_offsets
== NULL
)
3634 off
= local_got_offsets
[r_symndx
];
3635 offplt
= local_tlsdesc_gotents
[r_symndx
];
3642 Elf_Internal_Rela outrel
;
3646 if (htab
->elf
.srelgot
== NULL
)
3649 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3651 if (GOT_TLS_GDESC_P (tls_type
))
3653 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3654 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3655 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3656 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3657 + htab
->elf
.sgotplt
->output_offset
3659 + htab
->sgotplt_jump_table_size
);
3660 sreloc
= htab
->elf
.srelplt
;
3662 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3664 outrel
.r_addend
= 0;
3665 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3668 sreloc
= htab
->elf
.srelgot
;
3670 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3671 + htab
->elf
.sgot
->output_offset
+ off
);
3673 if (GOT_TLS_GD_P (tls_type
))
3674 dr_type
= R_X86_64_DTPMOD64
;
3675 else if (GOT_TLS_GDESC_P (tls_type
))
3678 dr_type
= R_X86_64_TPOFF64
;
3680 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3681 outrel
.r_addend
= 0;
3682 if ((dr_type
== R_X86_64_TPOFF64
3683 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3684 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3685 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3687 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3689 if (GOT_TLS_GD_P (tls_type
))
3693 BFD_ASSERT (! unresolved_reloc
);
3694 bfd_put_64 (output_bfd
,
3695 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3696 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3700 bfd_put_64 (output_bfd
, 0,
3701 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3702 outrel
.r_info
= htab
->r_info (indx
,
3704 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3705 elf_append_rela (output_bfd
, sreloc
,
3714 local_got_offsets
[r_symndx
] |= 1;
3717 if (off
>= (bfd_vma
) -2
3718 && ! GOT_TLS_GDESC_P (tls_type
))
3720 if (r_type_tls
== r_type
)
3722 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3723 || r_type
== R_X86_64_TLSDESC_CALL
)
3724 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3725 + htab
->elf
.sgotplt
->output_offset
3726 + offplt
+ htab
->sgotplt_jump_table_size
;
3728 relocation
= htab
->elf
.sgot
->output_section
->vma
3729 + htab
->elf
.sgot
->output_offset
+ off
;
3730 unresolved_reloc
= FALSE
;
3734 bfd_vma roff
= rel
->r_offset
;
3736 if (r_type
== R_X86_64_TLSGD
)
3738 /* GD->IE transition. For 64bit, change
3739 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3740 .word 0x6666; rex64; call __tls_get_addr@PLT
3742 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3744 call *__tls_get_addr@GOTPCREL(%rip
3745 which may be converted to
3746 addr32 call __tls_get_addr
3749 addq foo@gottpoff(%rip), %rax
3751 leaq foo@tlsgd(%rip), %rdi
3752 .word 0x6666; rex64; call __tls_get_addr@PLT
3754 leaq foo@tlsgd(%rip), %rdi
3756 call *__tls_get_addr@GOTPCREL(%rip)
3757 which may be converted to
3758 addr32 call __tls_get_addr
3761 addq foo@gottpoff(%rip), %rax
3762 For largepic, change:
3763 leaq foo@tlsgd(%rip), %rdi
3764 movabsq $__tls_get_addr@pltoff, %rax
3769 addq foo@gottpoff(%rax), %rax
3770 nopw 0x0(%rax,%rax,1) */
3772 if (ABI_64_P (output_bfd
))
3774 if (contents
[roff
+ 5] == 0xb8)
3777 || (roff
- 3 + 22) > input_section
->size
)
3779 memcpy (contents
+ roff
- 3,
3780 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3781 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3787 || (roff
- 4 + 16) > input_section
->size
)
3789 memcpy (contents
+ roff
- 4,
3790 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3797 || (roff
- 3 + 15) > input_section
->size
)
3799 memcpy (contents
+ roff
- 3,
3800 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3804 relocation
= (htab
->elf
.sgot
->output_section
->vma
3805 + htab
->elf
.sgot
->output_offset
+ off
3808 - input_section
->output_section
->vma
3809 - input_section
->output_offset
3811 bfd_put_32 (output_bfd
, relocation
,
3812 contents
+ roff
+ 8 + largepic
);
3813 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3818 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3820 /* GDesc -> IE transition.
3821 It's originally something like:
3822 leaq x@tlsdesc(%rip), %rax <--- LP64 mode.
3823 rex leal x@tlsdesc(%rip), %eax <--- X32 mode.
3826 # before xchg %ax,%ax in LP64 mode.
3827 movq x@gottpoff(%rip), %rax
3828 # before nopl (%rax) in X32 mode.
3829 rex movl x@gottpoff(%rip), %eax
3832 /* Now modify the instruction as appropriate. To
3833 turn a lea into a mov in the form we use it, it
3834 suffices to change the second byte from 0x8d to
3838 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3840 bfd_put_32 (output_bfd
,
3841 htab
->elf
.sgot
->output_section
->vma
3842 + htab
->elf
.sgot
->output_offset
+ off
3844 - input_section
->output_section
->vma
3845 - input_section
->output_offset
3850 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3852 /* GDesc -> IE transition.
3854 call *(%rax) <--- LP64 mode.
3855 call *(%eax) <--- X32 mode.
3858 xchg %ax, %ax <-- LP64 mode.
3859 nopl (%rax) <-- X32 mode.
3862 unsigned int prefix
= 0;
3863 if (!ABI_64_P (input_bfd
))
3865 /* Check for call *x@tlsdesc(%eax). */
3866 if (contents
[roff
] == 0x67)
3871 bfd_put_8 (output_bfd
, 0x0f, contents
+ roff
);
3872 bfd_put_8 (output_bfd
, 0x1f, contents
+ roff
+ 1);
3873 bfd_put_8 (output_bfd
, 0x00, contents
+ roff
+ 2);
3877 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3878 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3887 case R_X86_64_TLSLD
:
3888 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3889 input_section
, contents
,
3890 symtab_hdr
, sym_hashes
,
3891 &r_type
, GOT_UNKNOWN
, rel
,
3892 relend
, h
, r_symndx
, TRUE
))
3895 if (r_type
!= R_X86_64_TLSLD
)
3897 /* LD->LE transition:
3898 leaq foo@tlsld(%rip), %rdi
3899 call __tls_get_addr@PLT
3900 For 64bit, we change it into:
3901 .word 0x6666; .byte 0x66; movq %fs:0, %rax
3902 For 32bit, we change it into:
3903 nopl 0x0(%rax); movl %fs:0, %eax
3905 leaq foo@tlsld(%rip), %rdi;
3906 call *__tls_get_addr@GOTPCREL(%rip)
3907 which may be converted to
3908 addr32 call __tls_get_addr
3909 For 64bit, we change it into:
3910 .word 0x6666; .word 0x6666; movq %fs:0, %rax
3911 For 32bit, we change it into:
3912 nopw 0x0(%rax); movl %fs:0, %eax
3913 For largepic, change:
3914 leaq foo@tlsgd(%rip), %rdi
3915 movabsq $__tls_get_addr@pltoff, %rax
3919 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
3922 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3923 if (ABI_64_P (output_bfd
))
3925 if ((rel
->r_offset
+ 5) >= input_section
->size
)
3927 if (contents
[rel
->r_offset
+ 5] == 0xb8)
3929 if (rel
->r_offset
< 3
3930 || (rel
->r_offset
- 3 + 22) > input_section
->size
)
3932 memcpy (contents
+ rel
->r_offset
- 3,
3933 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
3934 "\x64\x48\x8b\x04\x25\0\0\0", 22);
3936 else if (contents
[rel
->r_offset
+ 4] == 0xff
3937 || contents
[rel
->r_offset
+ 4] == 0x67)
3939 if (rel
->r_offset
< 3
3940 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
3942 memcpy (contents
+ rel
->r_offset
- 3,
3943 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
3949 if (rel
->r_offset
< 3
3950 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
3952 memcpy (contents
+ rel
->r_offset
- 3,
3953 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3958 if ((rel
->r_offset
+ 4) >= input_section
->size
)
3960 if (contents
[rel
->r_offset
+ 4] == 0xff)
3962 if (rel
->r_offset
< 3
3963 || (rel
->r_offset
- 3 + 13) > input_section
->size
)
3965 memcpy (contents
+ rel
->r_offset
- 3,
3966 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
3971 if (rel
->r_offset
< 3
3972 || (rel
->r_offset
- 3 + 12) > input_section
->size
)
3974 memcpy (contents
+ rel
->r_offset
- 3,
3975 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3978 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
3979 and R_X86_64_PLTOFF64. */
3985 if (htab
->elf
.sgot
== NULL
)
3988 off
= htab
->tls_ld_or_ldm_got
.offset
;
3993 Elf_Internal_Rela outrel
;
3995 if (htab
->elf
.srelgot
== NULL
)
3998 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3999 + htab
->elf
.sgot
->output_offset
+ off
);
4001 bfd_put_64 (output_bfd
, 0,
4002 htab
->elf
.sgot
->contents
+ off
);
4003 bfd_put_64 (output_bfd
, 0,
4004 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4005 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4006 outrel
.r_addend
= 0;
4007 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4009 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4011 relocation
= htab
->elf
.sgot
->output_section
->vma
4012 + htab
->elf
.sgot
->output_offset
+ off
;
4013 unresolved_reloc
= FALSE
;
4016 case R_X86_64_DTPOFF32
:
4017 if (!bfd_link_executable (info
)
4018 || (input_section
->flags
& SEC_CODE
) == 0)
4019 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4021 relocation
= elf_x86_64_tpoff (info
, relocation
);
4024 case R_X86_64_TPOFF32
:
4025 case R_X86_64_TPOFF64
:
4026 BFD_ASSERT (bfd_link_executable (info
));
4027 relocation
= elf_x86_64_tpoff (info
, relocation
);
4030 case R_X86_64_DTPOFF64
:
4031 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
4032 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4039 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4040 because such sections are not SEC_ALLOC and thus ld.so will
4041 not process them. */
4042 if (unresolved_reloc
4043 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4045 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4046 rel
->r_offset
) != (bfd_vma
) -1)
4051 sec
= h
->root
.u
.def
.section
;
4052 if ((info
->nocopyreloc
4053 || (eh
->def_protected
4054 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
4055 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
4056 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
4057 h
, NULL
, NULL
, howto
);
4062 /* xgettext:c-format */
4063 (_("%pB(%pA+%#" PRIx64
"): "
4064 "unresolvable %s relocation against symbol `%s'"),
4067 (uint64_t) rel
->r_offset
,
4069 h
->root
.root
.string
);
4075 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4076 contents
, rel
->r_offset
,
4077 relocation
, rel
->r_addend
);
4079 check_relocation_error
:
4080 if (r
!= bfd_reloc_ok
)
4085 name
= h
->root
.root
.string
;
4088 name
= bfd_elf_string_from_elf_section (input_bfd
,
4089 symtab_hdr
->sh_link
,
4094 name
= bfd_section_name (sec
);
4097 if (r
== bfd_reloc_overflow
)
4099 if (converted_reloc
)
4101 info
->callbacks
->einfo
4102 (_("%F%P: failed to convert GOTPCREL relocation; relink with --no-relax\n"));
4105 (*info
->callbacks
->reloc_overflow
)
4106 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4107 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4112 /* xgettext:c-format */
4113 (_("%pB(%pA+%#" PRIx64
"): reloc against `%s': error %d"),
4114 input_bfd
, input_section
,
4115 (uint64_t) rel
->r_offset
, name
, (int) r
);
4126 Elf_Internal_Shdr
*rel_hdr
;
4127 size_t deleted
= rel
- wrel
;
4129 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4130 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4131 if (rel_hdr
->sh_size
== 0)
4133 /* It is too late to remove an empty reloc section. Leave
4135 ??? What is wrong with an empty section??? */
4136 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4139 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4140 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4141 input_section
->reloc_count
-= deleted
;
4147 /* Finish up dynamic symbol handling. We set the contents of various
4148 dynamic sections here. */
4151 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4152 struct bfd_link_info
*info
,
4153 struct elf_link_hash_entry
*h
,
4154 Elf_Internal_Sym
*sym
)
4156 struct elf_x86_link_hash_table
*htab
;
4157 bfd_boolean use_plt_second
;
4158 struct elf_x86_link_hash_entry
*eh
;
4159 bfd_boolean local_undefweak
;
4161 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4165 /* Use the second PLT section only if there is .plt section. */
4166 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
4168 eh
= (struct elf_x86_link_hash_entry
*) h
;
4169 if (eh
->no_finish_dynamic_symbol
)
4172 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4173 resolved undefined weak symbols in executable so that their
4174 references have value 0 at run-time. */
4175 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
4177 if (h
->plt
.offset
!= (bfd_vma
) -1)
4180 bfd_vma got_offset
, plt_offset
;
4181 Elf_Internal_Rela rela
;
4183 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
4184 const struct elf_backend_data
*bed
;
4185 bfd_vma plt_got_pcrel_offset
;
4187 /* When building a static executable, use .iplt, .igot.plt and
4188 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4189 if (htab
->elf
.splt
!= NULL
)
4191 plt
= htab
->elf
.splt
;
4192 gotplt
= htab
->elf
.sgotplt
;
4193 relplt
= htab
->elf
.srelplt
;
4197 plt
= htab
->elf
.iplt
;
4198 gotplt
= htab
->elf
.igotplt
;
4199 relplt
= htab
->elf
.irelplt
;
4202 VERIFY_PLT_ENTRY (info
, h
, plt
, gotplt
, relplt
, local_undefweak
)
4204 /* Get the index in the procedure linkage table which
4205 corresponds to this symbol. This is the index of this symbol
4206 in all the symbols for which we are making plt entries. The
4207 first entry in the procedure linkage table is reserved.
4209 Get the offset into the .got table of the entry that
4210 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4211 bytes. The first three are reserved for the dynamic linker.
4213 For static executables, we don't reserve anything. */
4215 if (plt
== htab
->elf
.splt
)
4217 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
4218 - htab
->plt
.has_plt0
);
4219 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4223 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
4224 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4227 /* Fill in the entry in the procedure linkage table. */
4228 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4229 htab
->plt
.plt_entry_size
);
4232 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4233 htab
->non_lazy_plt
->plt_entry
,
4234 htab
->non_lazy_plt
->plt_entry_size
);
4236 resolved_plt
= htab
->plt_second
;
4237 plt_offset
= eh
->plt_second
.offset
;
4242 plt_offset
= h
->plt
.offset
;
4245 /* Insert the relocation positions of the plt section. */
4247 /* Put offset the PC-relative instruction referring to the GOT entry,
4248 subtracting the size of that instruction. */
4249 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
4250 + gotplt
->output_offset
4252 - resolved_plt
->output_section
->vma
4253 - resolved_plt
->output_offset
4255 - htab
->plt
.plt_got_insn_size
);
4257 /* Check PC-relative offset overflow in PLT entry. */
4258 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
4259 /* xgettext:c-format */
4260 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in PLT entry for `%s'\n"),
4261 output_bfd
, h
->root
.root
.string
);
4263 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
4264 (resolved_plt
->contents
+ plt_offset
4265 + htab
->plt
.plt_got_offset
));
4267 /* Fill in the entry in the global offset table, initially this
4268 points to the second part of the PLT entry. Leave the entry
4269 as zero for undefined weak symbol in PIE. No PLT relocation
4270 against undefined weak symbol in PIE. */
4271 if (!local_undefweak
)
4273 if (htab
->plt
.has_plt0
)
4274 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4275 + plt
->output_offset
4277 + htab
->lazy_plt
->plt_lazy_offset
),
4278 gotplt
->contents
+ got_offset
);
4280 /* Fill in the entry in the .rela.plt section. */
4281 rela
.r_offset
= (gotplt
->output_section
->vma
4282 + gotplt
->output_offset
4284 if (PLT_LOCAL_IFUNC_P (info
, h
))
4286 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4287 h
->root
.root
.string
,
4288 h
->root
.u
.def
.section
->owner
);
4290 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4291 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4292 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4293 rela
.r_addend
= (h
->root
.u
.def
.value
4294 + h
->root
.u
.def
.section
->output_section
->vma
4295 + h
->root
.u
.def
.section
->output_offset
);
4296 /* R_X86_64_IRELATIVE comes last. */
4297 plt_index
= htab
->next_irelative_index
--;
4301 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4303 plt_index
= htab
->next_jump_slot_index
++;
4306 /* Don't fill the second and third slots in PLT entry for
4307 static executables nor without PLT0. */
4308 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4311 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
4313 /* Put relocation index. */
4314 bfd_put_32 (output_bfd
, plt_index
,
4315 (plt
->contents
+ h
->plt
.offset
4316 + htab
->lazy_plt
->plt_reloc_offset
));
4318 /* Put offset for jmp .PLT0 and check for overflow. We don't
4319 check relocation index for overflow since branch displacement
4320 will overflow first. */
4321 if (plt0_offset
> 0x80000000)
4322 /* xgettext:c-format */
4323 info
->callbacks
->einfo (_("%F%pB: branch displacement overflow in PLT entry for `%s'\n"),
4324 output_bfd
, h
->root
.root
.string
);
4325 bfd_put_32 (output_bfd
, - plt0_offset
,
4326 (plt
->contents
+ h
->plt
.offset
4327 + htab
->lazy_plt
->plt_plt_offset
));
4330 bed
= get_elf_backend_data (output_bfd
);
4331 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4332 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4335 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4337 bfd_vma got_offset
, plt_offset
;
4338 asection
*plt
, *got
;
4339 bfd_boolean got_after_plt
;
4340 int32_t got_pcrel_offset
;
4342 /* Set the entry in the GOT procedure linkage table. */
4343 plt
= htab
->plt_got
;
4344 got
= htab
->elf
.sgot
;
4345 got_offset
= h
->got
.offset
;
4347 if (got_offset
== (bfd_vma
) -1
4348 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
4353 /* Use the non-lazy PLT entry template for the GOT PLT since they
4354 are the identical. */
4355 /* Fill in the entry in the GOT procedure linkage table. */
4356 plt_offset
= eh
->plt_got
.offset
;
4357 memcpy (plt
->contents
+ plt_offset
,
4358 htab
->non_lazy_plt
->plt_entry
,
4359 htab
->non_lazy_plt
->plt_entry_size
);
4361 /* Put offset the PC-relative instruction referring to the GOT
4362 entry, subtracting the size of that instruction. */
4363 got_pcrel_offset
= (got
->output_section
->vma
4364 + got
->output_offset
4366 - plt
->output_section
->vma
4367 - plt
->output_offset
4369 - htab
->non_lazy_plt
->plt_got_insn_size
);
4371 /* Check PC-relative offset overflow in GOT PLT entry. */
4372 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
4373 if ((got_after_plt
&& got_pcrel_offset
< 0)
4374 || (!got_after_plt
&& got_pcrel_offset
> 0))
4375 /* xgettext:c-format */
4376 info
->callbacks
->einfo (_("%F%pB: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4377 output_bfd
, h
->root
.root
.string
);
4379 bfd_put_32 (output_bfd
, got_pcrel_offset
,
4380 (plt
->contents
+ plt_offset
4381 + htab
->non_lazy_plt
->plt_got_offset
));
4384 if (!local_undefweak
4386 && (h
->plt
.offset
!= (bfd_vma
) -1
4387 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4389 /* Mark the symbol as undefined, rather than as defined in
4390 the .plt section. Leave the value if there were any
4391 relocations where pointer equality matters (this is a clue
4392 for the dynamic linker, to make function pointer
4393 comparisons work between an application and shared
4394 library), otherwise set it to zero. If a function is only
4395 called from a binary, there is no need to slow down
4396 shared libraries because of that. */
4397 sym
->st_shndx
= SHN_UNDEF
;
4398 if (!h
->pointer_equality_needed
)
4402 _bfd_x86_elf_link_fixup_ifunc_symbol (info
, htab
, h
, sym
);
4404 /* Don't generate dynamic GOT relocation against undefined weak
4405 symbol in executable. */
4406 if (h
->got
.offset
!= (bfd_vma
) -1
4407 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
4408 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
4409 && !local_undefweak
)
4411 Elf_Internal_Rela rela
;
4412 asection
*relgot
= htab
->elf
.srelgot
;
4414 /* This symbol has an entry in the global offset table. Set it
4416 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4419 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4420 + htab
->elf
.sgot
->output_offset
4421 + (h
->got
.offset
&~ (bfd_vma
) 1));
4423 /* If this is a static link, or it is a -Bsymbolic link and the
4424 symbol is defined locally or was forced to be local because
4425 of a version file, we just want to emit a RELATIVE reloc.
4426 The entry in the global offset table will already have been
4427 initialized in the relocate_section function. */
4429 && h
->type
== STT_GNU_IFUNC
)
4431 if (h
->plt
.offset
== (bfd_vma
) -1)
4433 /* STT_GNU_IFUNC is referenced without PLT. */
4434 if (htab
->elf
.splt
== NULL
)
4436 /* use .rel[a].iplt section to store .got relocations
4437 in static executable. */
4438 relgot
= htab
->elf
.irelplt
;
4440 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4442 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %pB\n"),
4443 h
->root
.root
.string
,
4444 h
->root
.u
.def
.section
->owner
);
4446 rela
.r_info
= htab
->r_info (0,
4447 R_X86_64_IRELATIVE
);
4448 rela
.r_addend
= (h
->root
.u
.def
.value
4449 + h
->root
.u
.def
.section
->output_section
->vma
4450 + h
->root
.u
.def
.section
->output_offset
);
4455 else if (bfd_link_pic (info
))
4457 /* Generate R_X86_64_GLOB_DAT. */
4465 if (!h
->pointer_equality_needed
)
4468 /* For non-shared object, we can't use .got.plt, which
4469 contains the real function addres if we need pointer
4470 equality. We load the GOT entry with the PLT entry. */
4471 if (htab
->plt_second
!= NULL
)
4473 plt
= htab
->plt_second
;
4474 plt_offset
= eh
->plt_second
.offset
;
4478 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4479 plt_offset
= h
->plt
.offset
;
4481 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4482 + plt
->output_offset
4484 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4488 else if (bfd_link_pic (info
)
4489 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4491 if (!SYMBOL_DEFINED_NON_SHARED_P (h
))
4493 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4494 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4495 rela
.r_addend
= (h
->root
.u
.def
.value
4496 + h
->root
.u
.def
.section
->output_section
->vma
4497 + h
->root
.u
.def
.section
->output_offset
);
4501 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4503 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4504 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4505 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4509 elf_append_rela (output_bfd
, relgot
, &rela
);
4514 Elf_Internal_Rela rela
;
4517 /* This symbol needs a copy reloc. Set it up. */
4518 VERIFY_COPY_RELOC (h
, htab
)
4520 rela
.r_offset
= (h
->root
.u
.def
.value
4521 + h
->root
.u
.def
.section
->output_section
->vma
4522 + h
->root
.u
.def
.section
->output_offset
);
4523 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4525 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4526 s
= htab
->elf
.sreldynrelro
;
4528 s
= htab
->elf
.srelbss
;
4529 elf_append_rela (output_bfd
, s
, &rela
);
4535 /* Finish up local dynamic symbol handling. We set the contents of
4536 various dynamic sections here. */
4539 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4541 struct elf_link_hash_entry
*h
4542 = (struct elf_link_hash_entry
*) *slot
;
4543 struct bfd_link_info
*info
4544 = (struct bfd_link_info
*) inf
;
4546 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4550 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4551 here since undefined weak symbol may not be dynamic and may not be
4552 called for elf_x86_64_finish_dynamic_symbol. */
4555 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4558 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4559 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4561 if (h
->root
.type
!= bfd_link_hash_undefweak
4562 || h
->dynindx
!= -1)
4565 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4569 /* Used to decide how to sort relocs in an optimal manner for the
4570 dynamic linker, before writing them out. */
4572 static enum elf_reloc_type_class
4573 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
4574 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4575 const Elf_Internal_Rela
*rela
)
4577 bfd
*abfd
= info
->output_bfd
;
4578 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4579 struct elf_x86_link_hash_table
*htab
4580 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4582 if (htab
->elf
.dynsym
!= NULL
4583 && htab
->elf
.dynsym
->contents
!= NULL
)
4585 /* Check relocation against STT_GNU_IFUNC symbol if there are
4587 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
4588 if (r_symndx
!= STN_UNDEF
)
4590 Elf_Internal_Sym sym
;
4591 if (!bed
->s
->swap_symbol_in (abfd
,
4592 (htab
->elf
.dynsym
->contents
4593 + r_symndx
* bed
->s
->sizeof_sym
),
4597 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4598 return reloc_class_ifunc
;
4602 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4604 case R_X86_64_IRELATIVE
:
4605 return reloc_class_ifunc
;
4606 case R_X86_64_RELATIVE
:
4607 case R_X86_64_RELATIVE64
:
4608 return reloc_class_relative
;
4609 case R_X86_64_JUMP_SLOT
:
4610 return reloc_class_plt
;
4612 return reloc_class_copy
;
4614 return reloc_class_normal
;
4618 /* Finish up the dynamic sections. */
4621 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4622 struct bfd_link_info
*info
)
4624 struct elf_x86_link_hash_table
*htab
;
4626 htab
= _bfd_x86_elf_finish_dynamic_sections (output_bfd
, info
);
4630 if (! htab
->elf
.dynamic_sections_created
)
4633 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4635 elf_section_data (htab
->elf
.splt
->output_section
)
4636 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
4638 if (htab
->plt
.has_plt0
)
4640 /* Fill in the special first entry in the procedure linkage
4642 memcpy (htab
->elf
.splt
->contents
,
4643 htab
->lazy_plt
->plt0_entry
,
4644 htab
->lazy_plt
->plt0_entry_size
);
4645 /* Add offset for pushq GOT+8(%rip), since the instruction
4646 uses 6 bytes subtract this value. */
4647 bfd_put_32 (output_bfd
,
4648 (htab
->elf
.sgotplt
->output_section
->vma
4649 + htab
->elf
.sgotplt
->output_offset
4651 - htab
->elf
.splt
->output_section
->vma
4652 - htab
->elf
.splt
->output_offset
4654 (htab
->elf
.splt
->contents
4655 + htab
->lazy_plt
->plt0_got1_offset
));
4656 /* Add offset for the PC-relative instruction accessing
4657 GOT+16, subtracting the offset to the end of that
4659 bfd_put_32 (output_bfd
,
4660 (htab
->elf
.sgotplt
->output_section
->vma
4661 + htab
->elf
.sgotplt
->output_offset
4663 - htab
->elf
.splt
->output_section
->vma
4664 - htab
->elf
.splt
->output_offset
4665 - htab
->lazy_plt
->plt0_got2_insn_end
),
4666 (htab
->elf
.splt
->contents
4667 + htab
->lazy_plt
->plt0_got2_offset
));
4670 if (htab
->elf
.tlsdesc_plt
)
4672 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4673 htab
->elf
.sgot
->contents
+ htab
->elf
.tlsdesc_got
);
4675 memcpy (htab
->elf
.splt
->contents
+ htab
->elf
.tlsdesc_plt
,
4676 htab
->lazy_plt
->plt_tlsdesc_entry
,
4677 htab
->lazy_plt
->plt_tlsdesc_entry_size
);
4679 /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4
4680 bytes and the instruction uses 6 bytes, subtract these
4682 bfd_put_32 (output_bfd
,
4683 (htab
->elf
.sgotplt
->output_section
->vma
4684 + htab
->elf
.sgotplt
->output_offset
4686 - htab
->elf
.splt
->output_section
->vma
4687 - htab
->elf
.splt
->output_offset
4688 - htab
->elf
.tlsdesc_plt
4689 - htab
->lazy_plt
->plt_tlsdesc_got1_insn_end
),
4690 (htab
->elf
.splt
->contents
4691 + htab
->elf
.tlsdesc_plt
4692 + htab
->lazy_plt
->plt_tlsdesc_got1_offset
));
4693 /* Add offset for indirect branch via GOT+TDG, where TDG
4694 stands for htab->tlsdesc_got, subtracting the offset
4695 to the end of that instruction. */
4696 bfd_put_32 (output_bfd
,
4697 (htab
->elf
.sgot
->output_section
->vma
4698 + htab
->elf
.sgot
->output_offset
4699 + htab
->elf
.tlsdesc_got
4700 - htab
->elf
.splt
->output_section
->vma
4701 - htab
->elf
.splt
->output_offset
4702 - htab
->elf
.tlsdesc_plt
4703 - htab
->lazy_plt
->plt_tlsdesc_got2_insn_end
),
4704 (htab
->elf
.splt
->contents
4705 + htab
->elf
.tlsdesc_plt
4706 + htab
->lazy_plt
->plt_tlsdesc_got2_offset
));
4710 /* Fill PLT entries for undefined weak symbols in PIE. */
4711 if (bfd_link_pie (info
))
4712 bfd_hash_traverse (&info
->hash
->table
,
4713 elf_x86_64_pie_finish_undefweak_symbol
,
4719 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4720 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4721 It has to be done before elf_link_sort_relocs is called so that
4722 dynamic relocations are properly sorted. */
4725 elf_x86_64_output_arch_local_syms
4726 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4727 struct bfd_link_info
*info
,
4728 void *flaginfo ATTRIBUTE_UNUSED
,
4729 int (*func
) (void *, const char *,
4732 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4734 struct elf_x86_link_hash_table
*htab
4735 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4739 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4740 htab_traverse (htab
->loc_hash_table
,
4741 elf_x86_64_finish_local_dynamic_symbol
,
4747 /* Forward declaration. */
4748 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
;
4750 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4751 dynamic relocations. */
4754 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
4755 long symcount ATTRIBUTE_UNUSED
,
4756 asymbol
**syms ATTRIBUTE_UNUSED
,
4763 bfd_byte
*plt_contents
;
4765 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4766 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4767 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
4768 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
4769 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4770 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4772 enum elf_x86_plt_type plt_type
;
4773 struct elf_x86_plt plts
[] =
4775 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4776 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4777 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4778 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4779 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4784 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4787 if (dynsymcount
<= 0)
4790 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4794 if (get_elf_backend_data (abfd
)->target_os
!= is_nacl
)
4796 lazy_plt
= &elf_x86_64_lazy_plt
;
4797 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
4798 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
4799 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
4800 if (ABI_64_P (abfd
))
4802 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
4803 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
4807 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4808 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4813 lazy_plt
= &elf_x86_64_nacl_plt
;
4814 non_lazy_plt
= NULL
;
4815 lazy_bnd_plt
= NULL
;
4816 non_lazy_bnd_plt
= NULL
;
4817 lazy_ibt_plt
= NULL
;
4818 non_lazy_ibt_plt
= NULL
;
4822 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4824 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4825 if (plt
== NULL
|| plt
->size
== 0)
4828 /* Get the PLT section contents. */
4829 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4830 if (plt_contents
== NULL
)
4832 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4833 plt_contents
, 0, plt
->size
))
4835 free (plt_contents
);
4839 /* Check what kind of PLT it is. */
4840 plt_type
= plt_unknown
;
4841 if (plts
[j
].type
== plt_unknown
4842 && (plt
->size
>= (lazy_plt
->plt_entry_size
4843 + lazy_plt
->plt_entry_size
)))
4845 /* Match lazy PLT first. Need to check the first two
4847 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4848 lazy_plt
->plt0_got1_offset
) == 0)
4849 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
4851 plt_type
= plt_lazy
;
4852 else if (lazy_bnd_plt
!= NULL
4853 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
4854 lazy_bnd_plt
->plt0_got1_offset
) == 0)
4855 && (memcmp (plt_contents
+ 6,
4856 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
4858 plt_type
= plt_lazy
| plt_second
;
4859 /* The fist entry in the lazy IBT PLT is the same as the
4861 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
4862 lazy_ibt_plt
->plt_entry
,
4863 lazy_ibt_plt
->plt_got_offset
) == 0))
4864 lazy_plt
= lazy_ibt_plt
;
4866 lazy_plt
= lazy_bnd_plt
;
4870 if (non_lazy_plt
!= NULL
4871 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4872 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4874 /* Match non-lazy PLT. */
4875 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4876 non_lazy_plt
->plt_got_offset
) == 0)
4877 plt_type
= plt_non_lazy
;
4880 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4882 if (non_lazy_bnd_plt
!= NULL
4883 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
4884 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
4885 non_lazy_bnd_plt
->plt_got_offset
) == 0))
4887 /* Match BND PLT. */
4888 plt_type
= plt_second
;
4889 non_lazy_plt
= non_lazy_bnd_plt
;
4891 else if (non_lazy_ibt_plt
!= NULL
4892 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
4893 && (memcmp (plt_contents
,
4894 non_lazy_ibt_plt
->plt_entry
,
4895 non_lazy_ibt_plt
->plt_got_offset
) == 0))
4897 /* Match IBT PLT. */
4898 plt_type
= plt_second
;
4899 non_lazy_plt
= non_lazy_ibt_plt
;
4903 if (plt_type
== plt_unknown
)
4905 free (plt_contents
);
4910 plts
[j
].type
= plt_type
;
4912 if ((plt_type
& plt_lazy
))
4914 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4915 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
4916 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4917 /* Skip PLT0 in lazy PLT. */
4922 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4923 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
4924 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4928 /* Skip lazy PLT when the second PLT is used. */
4929 if (plt_type
== (plt_lazy
| plt_second
))
4933 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4938 plts
[j
].contents
= plt_contents
;
4941 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4942 (bfd_vma
) 0, plts
, dynsyms
,
4946 /* Handle an x86-64 specific section when reading an object file. This
4947 is called when elfcode.h finds a section with an unknown type. */
4950 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
4951 const char *name
, int shindex
)
4953 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4956 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4962 /* Hook called by the linker routine which adds symbols from an object
4963 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4967 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4968 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4969 Elf_Internal_Sym
*sym
,
4970 const char **namep ATTRIBUTE_UNUSED
,
4971 flagword
*flagsp ATTRIBUTE_UNUSED
,
4977 switch (sym
->st_shndx
)
4979 case SHN_X86_64_LCOMMON
:
4980 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4983 lcomm
= bfd_make_section_with_flags (abfd
,
4987 | SEC_LINKER_CREATED
));
4990 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4993 *valp
= sym
->st_size
;
5001 /* Given a BFD section, try to locate the corresponding ELF section
5005 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5006 asection
*sec
, int *index_return
)
5008 if (sec
== &_bfd_elf_large_com_section
)
5010 *index_return
= SHN_X86_64_LCOMMON
;
5016 /* Process a symbol. */
5019 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5022 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5024 switch (elfsym
->internal_elf_sym
.st_shndx
)
5026 case SHN_X86_64_LCOMMON
:
5027 asym
->section
= &_bfd_elf_large_com_section
;
5028 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5029 /* Common symbol doesn't set BSF_GLOBAL. */
5030 asym
->flags
&= ~BSF_GLOBAL
;
5036 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
5038 return (sym
->st_shndx
== SHN_COMMON
5039 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
5043 elf_x86_64_common_section_index (asection
*sec
)
5045 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5048 return SHN_X86_64_LCOMMON
;
5052 elf_x86_64_common_section (asection
*sec
)
5054 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5055 return bfd_com_section_ptr
;
5057 return &_bfd_elf_large_com_section
;
5061 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5062 const Elf_Internal_Sym
*sym
,
5067 const asection
*oldsec
)
5069 /* A normal common symbol and a large common symbol result in a
5070 normal common symbol. We turn the large common symbol into a
5073 && h
->root
.type
== bfd_link_hash_common
5075 && bfd_is_com_section (*psec
)
5078 if (sym
->st_shndx
== SHN_COMMON
5079 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5081 h
->root
.u
.c
.p
->section
5082 = bfd_make_section_old_way (oldbfd
, "COMMON");
5083 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5085 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5086 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5087 *psec
= bfd_com_section_ptr
;
5094 elf_x86_64_additional_program_headers (bfd
*abfd
,
5095 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5100 /* Check to see if we need a large readonly segment. */
5101 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5102 if (s
&& (s
->flags
& SEC_LOAD
))
5105 /* Check to see if we need a large data segment. Since .lbss sections
5106 is placed right after the .bss section, there should be no need for
5107 a large data segment just because of .lbss. */
5108 s
= bfd_get_section_by_name (abfd
, ".ldata");
5109 if (s
&& (s
->flags
& SEC_LOAD
))
5115 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5118 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5119 const bfd_target
*output
)
5121 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5122 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5123 && _bfd_elf_relocs_compatible (input
, output
));
5126 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5127 with GNU properties if found. Otherwise, return NULL. */
5130 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
5132 struct elf_x86_init_table init_table
;
5134 if ((int) R_X86_64_standard
>= (int) R_X86_64_converted_reloc_bit
5135 || (int) R_X86_64_max
<= (int) R_X86_64_converted_reloc_bit
5136 || ((int) (R_X86_64_GNU_VTINHERIT
| R_X86_64_converted_reloc_bit
)
5137 != (int) R_X86_64_GNU_VTINHERIT
)
5138 || ((int) (R_X86_64_GNU_VTENTRY
| R_X86_64_converted_reloc_bit
)
5139 != (int) R_X86_64_GNU_VTENTRY
))
5142 /* This is unused for x86-64. */
5143 init_table
.plt0_pad_byte
= 0x90;
5145 if (get_elf_backend_data (info
->output_bfd
)->target_os
!= is_nacl
)
5147 const struct elf_backend_data
*bed
5148 = get_elf_backend_data (info
->output_bfd
);
5149 struct elf_x86_link_hash_table
*htab
5150 = elf_x86_hash_table (info
, bed
->target_id
);
5153 if (htab
->params
->bndplt
)
5155 init_table
.lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
5156 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
5160 init_table
.lazy_plt
= &elf_x86_64_lazy_plt
;
5161 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
5164 if (ABI_64_P (info
->output_bfd
))
5166 init_table
.lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
5167 init_table
.non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
5171 init_table
.lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
5172 init_table
.non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
5177 init_table
.lazy_plt
= &elf_x86_64_nacl_plt
;
5178 init_table
.non_lazy_plt
= NULL
;
5179 init_table
.lazy_ibt_plt
= NULL
;
5180 init_table
.non_lazy_ibt_plt
= NULL
;
5183 if (ABI_64_P (info
->output_bfd
))
5185 init_table
.r_info
= elf64_r_info
;
5186 init_table
.r_sym
= elf64_r_sym
;
5190 init_table
.r_info
= elf32_r_info
;
5191 init_table
.r_sym
= elf32_r_sym
;
5194 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
5197 static const struct bfd_elf_special_section
5198 elf_x86_64_special_sections
[]=
5200 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5201 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5202 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
5203 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5204 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5205 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5206 { NULL
, 0, 0, 0, 0 }
5209 #define TARGET_LITTLE_SYM x86_64_elf64_vec
5210 #define TARGET_LITTLE_NAME "elf64-x86-64"
5211 #define ELF_ARCH bfd_arch_i386
5212 #define ELF_TARGET_ID X86_64_ELF_DATA
5213 #define ELF_MACHINE_CODE EM_X86_64
5214 #if DEFAULT_LD_Z_SEPARATE_CODE
5215 # define ELF_MAXPAGESIZE 0x1000
5217 # define ELF_MAXPAGESIZE 0x200000
5219 #define ELF_MINPAGESIZE 0x1000
5220 #define ELF_COMMONPAGESIZE 0x1000
5222 #define elf_backend_can_gc_sections 1
5223 #define elf_backend_can_refcount 1
5224 #define elf_backend_want_got_plt 1
5225 #define elf_backend_plt_readonly 1
5226 #define elf_backend_want_plt_sym 0
5227 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5228 #define elf_backend_rela_normal 1
5229 #define elf_backend_plt_alignment 4
5230 #define elf_backend_extern_protected_data 1
5231 #define elf_backend_caches_rawsize 1
5232 #define elf_backend_dtrel_excludes_plt 1
5233 #define elf_backend_want_dynrelro 1
5235 #define elf_info_to_howto elf_x86_64_info_to_howto
5237 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5238 #define bfd_elf64_bfd_reloc_name_lookup \
5239 elf_x86_64_reloc_name_lookup
5241 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5242 #define elf_backend_check_relocs elf_x86_64_check_relocs
5243 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5244 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5245 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5246 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
5247 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5248 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5250 #define elf_backend_write_core_note elf_x86_64_write_core_note
5252 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5253 #define elf_backend_relocate_section elf_x86_64_relocate_section
5254 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5255 #define elf_backend_object_p elf64_x86_64_elf_object_p
5256 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5258 #define elf_backend_section_from_shdr \
5259 elf_x86_64_section_from_shdr
5261 #define elf_backend_section_from_bfd_section \
5262 elf_x86_64_elf_section_from_bfd_section
5263 #define elf_backend_add_symbol_hook \
5264 elf_x86_64_add_symbol_hook
5265 #define elf_backend_symbol_processing \
5266 elf_x86_64_symbol_processing
5267 #define elf_backend_common_section_index \
5268 elf_x86_64_common_section_index
5269 #define elf_backend_common_section \
5270 elf_x86_64_common_section
5271 #define elf_backend_common_definition \
5272 elf_x86_64_common_definition
5273 #define elf_backend_merge_symbol \
5274 elf_x86_64_merge_symbol
5275 #define elf_backend_special_sections \
5276 elf_x86_64_special_sections
5277 #define elf_backend_additional_program_headers \
5278 elf_x86_64_additional_program_headers
5279 #define elf_backend_setup_gnu_properties \
5280 elf_x86_64_link_setup_gnu_properties
5281 #define elf_backend_hide_symbol \
5282 _bfd_x86_elf_hide_symbol
5285 #define elf64_bed elf64_x86_64_bed
5287 #include "elf64-target.h"
5289 /* CloudABI support. */
5291 #undef TARGET_LITTLE_SYM
5292 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
5293 #undef TARGET_LITTLE_NAME
5294 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
5297 #define ELF_OSABI ELFOSABI_CLOUDABI
5300 #define elf64_bed elf64_x86_64_cloudabi_bed
5302 #include "elf64-target.h"
5304 /* FreeBSD support. */
5306 #undef TARGET_LITTLE_SYM
5307 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
5308 #undef TARGET_LITTLE_NAME
5309 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5312 #define ELF_OSABI ELFOSABI_FREEBSD
5315 #define elf64_bed elf64_x86_64_fbsd_bed
5317 #include "elf64-target.h"
5319 /* Solaris 2 support. */
5321 #undef TARGET_LITTLE_SYM
5322 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
5323 #undef TARGET_LITTLE_NAME
5324 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5326 #undef ELF_TARGET_OS
5327 #define ELF_TARGET_OS is_solaris
5329 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5330 objects won't be recognized. */
5334 #define elf64_bed elf64_x86_64_sol2_bed
5336 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5338 #undef elf_backend_static_tls_alignment
5339 #define elf_backend_static_tls_alignment 16
5341 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5343 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5345 #undef elf_backend_want_plt_sym
5346 #define elf_backend_want_plt_sym 1
5348 #undef elf_backend_strtab_flags
5349 #define elf_backend_strtab_flags SHF_STRINGS
5352 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
5353 bfd
*obfd ATTRIBUTE_UNUSED
,
5354 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
5355 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
5357 /* PR 19938: FIXME: Need to add code for setting the sh_info
5358 and sh_link fields of Solaris specific section types. */
5362 #undef elf_backend_copy_special_section_fields
5363 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
5365 #include "elf64-target.h"
5367 /* Native Client support. */
5370 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
5372 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
5373 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
5377 #undef TARGET_LITTLE_SYM
5378 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
5379 #undef TARGET_LITTLE_NAME
5380 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5382 #define elf64_bed elf64_x86_64_nacl_bed
5384 #undef ELF_MAXPAGESIZE
5385 #undef ELF_MINPAGESIZE
5386 #undef ELF_COMMONPAGESIZE
5387 #define ELF_MAXPAGESIZE 0x10000
5388 #define ELF_MINPAGESIZE 0x10000
5389 #define ELF_COMMONPAGESIZE 0x10000
5391 /* Restore defaults. */
5393 #undef elf_backend_static_tls_alignment
5394 #undef elf_backend_want_plt_sym
5395 #define elf_backend_want_plt_sym 0
5396 #undef elf_backend_strtab_flags
5397 #undef elf_backend_copy_special_section_fields
5399 /* NaCl uses substantially different PLT entries for the same effects. */
5401 #undef elf_backend_plt_alignment
5402 #define elf_backend_plt_alignment 5
5403 #define NACL_PLT_ENTRY_SIZE 64
5404 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5406 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
5408 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5409 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5410 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5411 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5412 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5414 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
5415 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
5417 /* 32 bytes of nop to pad out to the standard size. */
5418 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5419 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5420 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5421 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5422 0x66, /* excess data16 prefix */
5426 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5428 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5429 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5430 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5431 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5433 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5434 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5435 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5437 /* Lazy GOT entries point here (32-byte aligned). */
5438 0x68, /* pushq immediate */
5439 0, 0, 0, 0, /* replaced with index into relocation table. */
5440 0xe9, /* jmp relative */
5441 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5443 /* 22 bytes of nop to pad out to the standard size. */
5444 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5445 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5446 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5449 /* .eh_frame covering the .plt section. */
5451 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
5453 #if (PLT_CIE_LENGTH != 20 \
5454 || PLT_FDE_LENGTH != 36 \
5455 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5456 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5457 # error "Need PLT_CIE_LENGTH parameters for eh_frame_plt offsets!"
5459 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5460 0, 0, 0, 0, /* CIE ID */
5461 1, /* CIE version */
5462 'z', 'R', 0, /* Augmentation string */
5463 1, /* Code alignment factor */
5464 0x78, /* Data alignment factor */
5465 16, /* Return address column */
5466 1, /* Augmentation size */
5467 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5468 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5469 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5470 DW_CFA_nop
, DW_CFA_nop
,
5472 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5473 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
5474 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5475 0, 0, 0, 0, /* .plt size goes here */
5476 0, /* Augmentation size */
5477 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
5478 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5479 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
5480 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5481 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5482 13, /* Block length */
5483 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
5484 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
5485 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5486 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
5487 DW_CFA_nop
, DW_CFA_nop
5490 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
=
5492 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
5493 NACL_PLT_ENTRY_SIZE
, /* plt0_entry_size */
5494 elf_x86_64_nacl_plt_entry
, /* plt_entry */
5495 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5496 elf_x86_64_nacl_plt0_entry
, /* plt_tlsdesc_entry */
5497 NACL_PLT_ENTRY_SIZE
, /* plt_tlsdesc_entry_size */
5498 2, /* plt_tlsdesc_got1_offset */
5499 9, /* plt_tlsdesc_got2_offset */
5500 6, /* plt_tlsdesc_got1_insn_end */
5501 13, /* plt_tlsdesc_got2_insn_end */
5502 2, /* plt0_got1_offset */
5503 9, /* plt0_got2_offset */
5504 13, /* plt0_got2_insn_end */
5505 3, /* plt_got_offset */
5506 33, /* plt_reloc_offset */
5507 38, /* plt_plt_offset */
5508 7, /* plt_got_insn_size */
5509 42, /* plt_plt_insn_end */
5510 32, /* plt_lazy_offset */
5511 elf_x86_64_nacl_plt0_entry
, /* pic_plt0_entry */
5512 elf_x86_64_nacl_plt_entry
, /* pic_plt_entry */
5513 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
5514 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
5517 #undef ELF_TARGET_OS
5518 #define ELF_TARGET_OS is_nacl
5520 #undef elf_backend_object_p
5521 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
5522 #undef elf_backend_modify_segment_map
5523 #define elf_backend_modify_segment_map nacl_modify_segment_map
5524 #undef elf_backend_modify_headers
5525 #define elf_backend_modify_headers nacl_modify_headers
5526 #undef elf_backend_final_write_processing
5527 #define elf_backend_final_write_processing nacl_final_write_processing
5529 #include "elf64-target.h"
5531 /* Native Client x32 support. */
5534 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
5536 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
5537 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
5541 #undef TARGET_LITTLE_SYM
5542 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
5543 #undef TARGET_LITTLE_NAME
5544 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5546 #define elf32_bed elf32_x86_64_nacl_bed
5548 #define bfd_elf32_bfd_reloc_type_lookup \
5549 elf_x86_64_reloc_type_lookup
5550 #define bfd_elf32_bfd_reloc_name_lookup \
5551 elf_x86_64_reloc_name_lookup
5552 #define bfd_elf32_get_synthetic_symtab \
5553 elf_x86_64_get_synthetic_symtab
5555 #undef elf_backend_object_p
5556 #define elf_backend_object_p \
5557 elf32_x86_64_nacl_elf_object_p
5559 #undef elf_backend_bfd_from_remote_memory
5560 #define elf_backend_bfd_from_remote_memory \
5561 _bfd_elf32_bfd_from_remote_memory
5563 #undef elf_backend_size_info
5564 #define elf_backend_size_info \
5565 _bfd_elf32_size_info
5568 #define elf32_bed elf32_x86_64_bed
5570 #include "elf32-target.h"
5572 /* Restore defaults. */
5573 #undef elf_backend_object_p
5574 #define elf_backend_object_p elf64_x86_64_elf_object_p
5575 #undef elf_backend_bfd_from_remote_memory
5576 #undef elf_backend_size_info
5577 #undef elf_backend_modify_segment_map
5578 #undef elf_backend_modify_headers
5579 #undef elf_backend_final_write_processing
5581 /* Intel L1OM support. */
5584 elf64_l1om_elf_object_p (bfd
*abfd
)
5586 /* Set the right machine number for an L1OM elf64 file. */
5587 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5591 #undef TARGET_LITTLE_SYM
5592 #define TARGET_LITTLE_SYM l1om_elf64_vec
5593 #undef TARGET_LITTLE_NAME
5594 #define TARGET_LITTLE_NAME "elf64-l1om"
5596 #define ELF_ARCH bfd_arch_l1om
5598 #undef ELF_MACHINE_CODE
5599 #define ELF_MACHINE_CODE EM_L1OM
5604 #define elf64_bed elf64_l1om_bed
5606 #undef elf_backend_object_p
5607 #define elf_backend_object_p elf64_l1om_elf_object_p
5609 /* Restore defaults. */
5610 #undef ELF_MAXPAGESIZE
5611 #undef ELF_MINPAGESIZE
5612 #undef ELF_COMMONPAGESIZE
5613 #if DEFAULT_LD_Z_SEPARATE_CODE
5614 # define ELF_MAXPAGESIZE 0x1000
5616 # define ELF_MAXPAGESIZE 0x200000
5618 #define ELF_MINPAGESIZE 0x1000
5619 #define ELF_COMMONPAGESIZE 0x1000
5620 #undef elf_backend_plt_alignment
5621 #define elf_backend_plt_alignment 4
5622 #undef ELF_TARGET_OS
5624 #include "elf64-target.h"
5626 /* FreeBSD L1OM support. */
5628 #undef TARGET_LITTLE_SYM
5629 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
5630 #undef TARGET_LITTLE_NAME
5631 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5634 #define ELF_OSABI ELFOSABI_FREEBSD
5637 #define elf64_bed elf64_l1om_fbsd_bed
5639 #include "elf64-target.h"
5641 /* Intel K1OM support. */
5644 elf64_k1om_elf_object_p (bfd
*abfd
)
5646 /* Set the right machine number for an K1OM elf64 file. */
5647 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5651 #undef TARGET_LITTLE_SYM
5652 #define TARGET_LITTLE_SYM k1om_elf64_vec
5653 #undef TARGET_LITTLE_NAME
5654 #define TARGET_LITTLE_NAME "elf64-k1om"
5656 #define ELF_ARCH bfd_arch_k1om
5658 #undef ELF_MACHINE_CODE
5659 #define ELF_MACHINE_CODE EM_K1OM
5664 #define elf64_bed elf64_k1om_bed
5666 #undef elf_backend_object_p
5667 #define elf_backend_object_p elf64_k1om_elf_object_p
5669 #undef elf_backend_static_tls_alignment
5671 #undef elf_backend_want_plt_sym
5672 #define elf_backend_want_plt_sym 0
5674 #include "elf64-target.h"
5676 /* FreeBSD K1OM support. */
5678 #undef TARGET_LITTLE_SYM
5679 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
5680 #undef TARGET_LITTLE_NAME
5681 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5684 #define ELF_OSABI ELFOSABI_FREEBSD
5687 #define elf64_bed elf64_k1om_fbsd_bed
5689 #include "elf64-target.h"
5691 /* 32bit x86-64 support. */
5693 #undef TARGET_LITTLE_SYM
5694 #define TARGET_LITTLE_SYM x86_64_elf32_vec
5695 #undef TARGET_LITTLE_NAME
5696 #define TARGET_LITTLE_NAME "elf32-x86-64"
5700 #define ELF_ARCH bfd_arch_i386
5702 #undef ELF_MACHINE_CODE
5703 #define ELF_MACHINE_CODE EM_X86_64
5707 #undef elf_backend_object_p
5708 #define elf_backend_object_p \
5709 elf32_x86_64_elf_object_p
5711 #undef elf_backend_bfd_from_remote_memory
5712 #define elf_backend_bfd_from_remote_memory \
5713 _bfd_elf32_bfd_from_remote_memory
5715 #undef elf_backend_size_info
5716 #define elf_backend_size_info \
5717 _bfd_elf32_size_info
5719 #include "elf32-target.h"