1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2017 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 /* Set if a relocation is converted from a GOTPCREL relocation. */
200 #define R_X86_64_converted_reloc_bit (1 << 7)
202 #define IS_X86_64_PCREL_TYPE(TYPE) \
203 ( ((TYPE) == R_X86_64_PC8) \
204 || ((TYPE) == R_X86_64_PC16) \
205 || ((TYPE) == R_X86_64_PC32) \
206 || ((TYPE) == R_X86_64_PC32_BND) \
207 || ((TYPE) == R_X86_64_PC64))
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 (_("%B: invalid relocation type %d"),
284 r_type
= R_X86_64_NONE
;
289 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
290 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
291 return &x86_64_elf_howto_table
[i
];
294 /* Given a BFD reloc type, return a HOWTO structure. */
295 static reloc_howto_type
*
296 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
297 bfd_reloc_code_real_type code
)
301 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
304 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
305 return elf_x86_64_rtype_to_howto (abfd
,
306 x86_64_reloc_map
[i
].elf_reloc_val
);
311 static reloc_howto_type
*
312 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
317 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
319 /* Get x32 R_X86_64_32. */
320 reloc_howto_type
*reloc
321 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
322 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
326 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
327 if (x86_64_elf_howto_table
[i
].name
!= NULL
328 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
329 return &x86_64_elf_howto_table
[i
];
334 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
337 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
338 Elf_Internal_Rela
*dst
)
342 r_type
= ELF32_R_TYPE (dst
->r_info
);
343 if (r_type
!= (unsigned int) R_X86_64_GNU_VTINHERIT
344 && r_type
!= (unsigned int) R_X86_64_GNU_VTENTRY
)
345 r_type
&= ~R_X86_64_converted_reloc_bit
;
346 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
347 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
350 /* Support for core dump NOTE sections. */
352 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
357 switch (note
->descsz
)
362 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
364 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
367 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
375 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
377 elf_tdata (abfd
)->core
->signal
378 = bfd_get_16 (abfd
, note
->descdata
+ 12);
381 elf_tdata (abfd
)->core
->lwpid
382 = bfd_get_32 (abfd
, note
->descdata
+ 32);
391 /* Make a ".reg/999" section. */
392 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
393 size
, note
->descpos
+ offset
);
397 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
399 switch (note
->descsz
)
404 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
405 elf_tdata (abfd
)->core
->pid
406 = bfd_get_32 (abfd
, note
->descdata
+ 12);
407 elf_tdata (abfd
)->core
->program
408 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
409 elf_tdata (abfd
)->core
->command
410 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
413 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
414 elf_tdata (abfd
)->core
->pid
415 = bfd_get_32 (abfd
, note
->descdata
+ 24);
416 elf_tdata (abfd
)->core
->program
417 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
418 elf_tdata (abfd
)->core
->command
419 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
422 /* Note that for some reason, a spurious space is tacked
423 onto the end of the args in some (at least one anyway)
424 implementations, so strip it off if it exists. */
427 char *command
= elf_tdata (abfd
)->core
->command
;
428 int n
= strlen (command
);
430 if (0 < n
&& command
[n
- 1] == ' ')
431 command
[n
- 1] = '\0';
439 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
442 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
444 const char *fname
, *psargs
;
455 va_start (ap
, note_type
);
456 fname
= va_arg (ap
, const char *);
457 psargs
= va_arg (ap
, const char *);
460 if (bed
->s
->elfclass
== ELFCLASS32
)
463 memset (&data
, 0, sizeof (data
));
464 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
465 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
466 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
467 &data
, sizeof (data
));
472 memset (&data
, 0, sizeof (data
));
473 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
474 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
475 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
476 &data
, sizeof (data
));
481 va_start (ap
, note_type
);
482 pid
= va_arg (ap
, long);
483 cursig
= va_arg (ap
, int);
484 gregs
= va_arg (ap
, const void *);
487 if (bed
->s
->elfclass
== ELFCLASS32
)
489 if (bed
->elf_machine_code
== EM_X86_64
)
491 prstatusx32_t prstat
;
492 memset (&prstat
, 0, sizeof (prstat
));
494 prstat
.pr_cursig
= cursig
;
495 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
496 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
497 &prstat
, sizeof (prstat
));
502 memset (&prstat
, 0, sizeof (prstat
));
504 prstat
.pr_cursig
= cursig
;
505 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
506 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
507 &prstat
, sizeof (prstat
));
513 memset (&prstat
, 0, sizeof (prstat
));
515 prstat
.pr_cursig
= cursig
;
516 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
517 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
518 &prstat
, sizeof (prstat
));
525 /* Functions for the x86-64 ELF linker. */
527 /* The size in bytes of an entry in the global offset table. */
529 #define GOT_ENTRY_SIZE 8
531 /* The size in bytes of an entry in the lazy procedure linkage table. */
533 #define LAZY_PLT_ENTRY_SIZE 16
535 /* The size in bytes of an entry in the non-lazy procedure linkage
538 #define NON_LAZY_PLT_ENTRY_SIZE 8
540 /* The first entry in a lazy procedure linkage table looks like this.
541 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
544 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
546 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
547 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
548 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
551 /* Subsequent entries in a lazy procedure linkage table look like this. */
553 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
555 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
556 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
557 0x68, /* pushq immediate */
558 0, 0, 0, 0, /* replaced with index into relocation table. */
559 0xe9, /* jmp relative */
560 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
563 /* The first entry in a lazy procedure linkage table with BND prefix
566 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
568 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
569 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
570 0x0f, 0x1f, 0 /* nopl (%rax) */
573 /* Subsequent entries for branches with BND prefx in a lazy procedure
574 linkage table look like this. */
576 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
578 0x68, 0, 0, 0, 0, /* pushq immediate */
579 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
580 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
583 /* The first entry in the IBT-enabled lazy procedure linkage table is the
584 the same as the lazy PLT with BND prefix so that bound registers are
585 preserved when control is passed to dynamic linker. Subsequent
586 entries for a IBT-enabled lazy procedure linkage table look like
589 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
591 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
592 0x68, 0, 0, 0, 0, /* pushq immediate */
593 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
597 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
598 is the same as the normal lazy PLT. Subsequent entries for an
599 x32 IBT-enabled lazy procedure linkage table look like this. */
601 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
603 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
604 0x68, 0, 0, 0, 0, /* pushq immediate */
605 0xe9, 0, 0, 0, 0, /* jmpq relative */
606 0x66, 0x90 /* xchg %ax,%ax */
609 /* Entries in the non-lazey procedure linkage table look like this. */
611 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
613 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
614 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
615 0x66, 0x90 /* xchg %ax,%ax */
618 /* Entries for branches with BND prefix in the non-lazey procedure
619 linkage table look like this. */
621 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
623 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
624 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
628 /* Entries for branches with IBT-enabled in the non-lazey procedure
629 linkage table look like this. They have the same size as the lazy
632 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
634 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
635 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
636 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
637 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
640 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
641 linkage table look like this. They have the same size as the lazy
644 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
646 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
647 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
648 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
649 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
652 /* .eh_frame covering the lazy .plt section. */
654 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
656 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
657 0, 0, 0, 0, /* CIE ID */
659 'z', 'R', 0, /* Augmentation string */
660 1, /* Code alignment factor */
661 0x78, /* Data alignment factor */
662 16, /* Return address column */
663 1, /* Augmentation size */
664 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
665 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
666 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
667 DW_CFA_nop
, DW_CFA_nop
,
669 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
670 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
671 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
672 0, 0, 0, 0, /* .plt size goes here */
673 0, /* Augmentation size */
674 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
675 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
676 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
677 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
678 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
679 11, /* Block length */
680 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
681 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
682 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
683 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
684 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
687 /* .eh_frame covering the lazy BND .plt section. */
689 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
691 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
692 0, 0, 0, 0, /* CIE ID */
694 'z', 'R', 0, /* Augmentation string */
695 1, /* Code alignment factor */
696 0x78, /* Data alignment factor */
697 16, /* Return address column */
698 1, /* Augmentation size */
699 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
700 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
701 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
702 DW_CFA_nop
, DW_CFA_nop
,
704 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
705 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
706 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
707 0, 0, 0, 0, /* .plt size goes here */
708 0, /* Augmentation size */
709 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
710 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
711 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
712 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
713 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
714 11, /* Block length */
715 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
716 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
717 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
718 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
719 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
722 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
724 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
726 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
727 0, 0, 0, 0, /* CIE ID */
729 'z', 'R', 0, /* Augmentation string */
730 1, /* Code alignment factor */
731 0x78, /* Data alignment factor */
732 16, /* Return address column */
733 1, /* Augmentation size */
734 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
735 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
736 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
737 DW_CFA_nop
, DW_CFA_nop
,
739 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
740 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
741 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
742 0, 0, 0, 0, /* .plt size goes here */
743 0, /* Augmentation size */
744 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
745 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
746 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
747 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
748 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
749 11, /* Block length */
750 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
751 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
752 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
753 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
754 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
757 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
759 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
761 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
762 0, 0, 0, 0, /* CIE ID */
764 'z', 'R', 0, /* Augmentation string */
765 1, /* Code alignment factor */
766 0x78, /* Data alignment factor */
767 16, /* Return address column */
768 1, /* Augmentation size */
769 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
770 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
771 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
772 DW_CFA_nop
, DW_CFA_nop
,
774 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
775 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
776 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
777 0, 0, 0, 0, /* .plt size goes here */
778 0, /* Augmentation size */
779 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
780 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
781 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
782 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
783 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
784 11, /* Block length */
785 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
786 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
787 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
788 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
789 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
792 /* .eh_frame covering the non-lazy .plt section. */
794 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
796 #define PLT_GOT_FDE_LENGTH 20
797 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
798 0, 0, 0, 0, /* CIE ID */
800 'z', 'R', 0, /* Augmentation string */
801 1, /* Code alignment factor */
802 0x78, /* Data alignment factor */
803 16, /* Return address column */
804 1, /* Augmentation size */
805 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
806 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
807 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
808 DW_CFA_nop
, DW_CFA_nop
,
810 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
811 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
812 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
813 0, 0, 0, 0, /* non-lazy .plt size goes here */
814 0, /* Augmentation size */
815 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
816 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
819 /* Architecture-specific backend data for x86-64. */
821 struct elf_x86_64_backend_data
831 #define get_elf_x86_64_arch_data(bed) \
832 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
834 #define get_elf_x86_64_backend_data(abfd) \
835 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
837 /* These are the standard parameters. */
838 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
840 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
841 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
842 elf_x86_64_lazy_plt_entry
, /* plt_entry */
843 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
844 2, /* plt0_got1_offset */
845 8, /* plt0_got2_offset */
846 12, /* plt0_got2_insn_end */
847 2, /* plt_got_offset */
848 7, /* plt_reloc_offset */
849 12, /* plt_plt_offset */
850 6, /* plt_got_insn_size */
851 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
852 6, /* plt_lazy_offset */
853 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
854 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
855 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
856 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
859 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
861 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
862 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
863 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
864 2, /* plt_got_offset */
865 6, /* plt_got_insn_size */
866 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
867 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
870 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
872 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
873 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
874 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
875 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
876 2, /* plt0_got1_offset */
877 1+8, /* plt0_got2_offset */
878 1+12, /* plt0_got2_insn_end */
879 1+2, /* plt_got_offset */
880 1, /* plt_reloc_offset */
881 7, /* plt_plt_offset */
882 1+6, /* plt_got_insn_size */
883 11, /* plt_plt_insn_end */
884 0, /* plt_lazy_offset */
885 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
886 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
887 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
888 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
891 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
893 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
894 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
895 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
896 1+2, /* plt_got_offset */
897 1+6, /* plt_got_insn_size */
898 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
899 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
902 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
904 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
905 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
906 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
907 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
908 2, /* plt0_got1_offset */
909 1+8, /* plt0_got2_offset */
910 1+12, /* plt0_got2_insn_end */
911 4+1+2, /* plt_got_offset */
912 4+1, /* plt_reloc_offset */
913 4+1+6, /* plt_plt_offset */
914 4+1+6, /* plt_got_insn_size */
915 4+1+5+5, /* plt_plt_insn_end */
916 0, /* plt_lazy_offset */
917 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
918 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
919 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
920 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
923 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
925 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
926 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
927 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
928 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
929 2, /* plt0_got1_offset */
930 8, /* plt0_got2_offset */
931 12, /* plt0_got2_insn_end */
932 4+2, /* plt_got_offset */
933 4+1, /* plt_reloc_offset */
934 4+6, /* plt_plt_offset */
935 4+6, /* plt_got_insn_size */
936 4+5+5, /* plt_plt_insn_end */
937 0, /* plt_lazy_offset */
938 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
939 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
940 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
941 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
944 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
946 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
947 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
948 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
949 4+1+2, /* plt_got_offset */
950 4+1+6, /* plt_got_insn_size */
951 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
952 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
955 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
957 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
958 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
959 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
960 4+2, /* plt_got_offset */
961 4+6, /* plt_got_insn_size */
962 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
963 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
966 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
971 #define elf_backend_arch_data &elf_x86_64_arch_bed
974 elf64_x86_64_elf_object_p (bfd
*abfd
)
976 /* Set the right machine number for an x86-64 elf64 file. */
977 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
982 elf32_x86_64_elf_object_p (bfd
*abfd
)
984 /* Set the right machine number for an x86-64 elf32 file. */
985 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
989 /* Return TRUE if the TLS access code sequence support transition
993 elf_x86_64_check_tls_transition (bfd
*abfd
,
994 struct bfd_link_info
*info
,
997 Elf_Internal_Shdr
*symtab_hdr
,
998 struct elf_link_hash_entry
**sym_hashes
,
1000 const Elf_Internal_Rela
*rel
,
1001 const Elf_Internal_Rela
*relend
)
1004 unsigned long r_symndx
;
1005 bfd_boolean largepic
= FALSE
;
1006 struct elf_link_hash_entry
*h
;
1008 struct elf_x86_link_hash_table
*htab
;
1010 bfd_boolean indirect_call
;
1012 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1013 offset
= rel
->r_offset
;
1016 case R_X86_64_TLSGD
:
1017 case R_X86_64_TLSLD
:
1018 if ((rel
+ 1) >= relend
)
1021 if (r_type
== R_X86_64_TLSGD
)
1023 /* Check transition from GD access model. For 64bit, only
1024 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1025 .word 0x6666; rex64; call __tls_get_addr@PLT
1027 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1029 call *__tls_get_addr@GOTPCREL(%rip)
1030 which may be converted to
1031 addr32 call __tls_get_addr
1032 can transit to different access model. For 32bit, only
1033 leaq foo@tlsgd(%rip), %rdi
1034 .word 0x6666; rex64; call __tls_get_addr@PLT
1036 leaq foo@tlsgd(%rip), %rdi
1038 call *__tls_get_addr@GOTPCREL(%rip)
1039 which may be converted to
1040 addr32 call __tls_get_addr
1041 can transit to different access model. For largepic,
1043 leaq foo@tlsgd(%rip), %rdi
1044 movabsq $__tls_get_addr@pltoff, %rax
1048 leaq foo@tlsgd(%rip), %rdi
1049 movabsq $__tls_get_addr@pltoff, %rax
1053 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1055 if ((offset
+ 12) > sec
->size
)
1058 call
= contents
+ offset
+ 4;
1060 || !((call
[1] == 0x48
1068 && call
[3] == 0xe8)))
1070 if (!ABI_64_P (abfd
)
1071 || (offset
+ 19) > sec
->size
1073 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1074 || memcmp (call
, "\x48\xb8", 2) != 0
1078 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1079 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1083 else if (ABI_64_P (abfd
))
1086 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1092 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1095 indirect_call
= call
[2] == 0xff;
1099 /* Check transition from LD access model. Only
1100 leaq foo@tlsld(%rip), %rdi;
1101 call __tls_get_addr@PLT
1103 leaq foo@tlsld(%rip), %rdi;
1104 call *__tls_get_addr@GOTPCREL(%rip)
1105 which may be converted to
1106 addr32 call __tls_get_addr
1107 can transit to different access model. For largepic
1109 leaq foo@tlsld(%rip), %rdi
1110 movabsq $__tls_get_addr@pltoff, %rax
1114 leaq foo@tlsld(%rip), %rdi
1115 movabsq $__tls_get_addr@pltoff, %rax
1119 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1121 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1124 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1127 call
= contents
+ offset
+ 4;
1128 if (!(call
[0] == 0xe8
1129 || (call
[0] == 0xff && call
[1] == 0x15)
1130 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1132 if (!ABI_64_P (abfd
)
1133 || (offset
+ 19) > sec
->size
1134 || memcmp (call
, "\x48\xb8", 2) != 0
1138 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1139 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1143 indirect_call
= call
[0] == 0xff;
1146 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1147 if (r_symndx
< symtab_hdr
->sh_info
)
1150 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1152 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1156 r_type
= (ELF32_R_TYPE (rel
[1].r_info
)
1157 & ~R_X86_64_converted_reloc_bit
);
1159 return r_type
== R_X86_64_PLTOFF64
;
1160 else if (indirect_call
)
1161 return r_type
== R_X86_64_GOTPCRELX
;
1163 return (r_type
== R_X86_64_PC32
|| r_type
== R_X86_64_PLT32
);
1166 case R_X86_64_GOTTPOFF
:
1167 /* Check transition from IE access model:
1168 mov foo@gottpoff(%rip), %reg
1169 add foo@gottpoff(%rip), %reg
1172 /* Check REX prefix first. */
1173 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1175 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1176 if (val
!= 0x48 && val
!= 0x4c)
1178 /* X32 may have 0x44 REX prefix or no REX prefix. */
1179 if (ABI_64_P (abfd
))
1185 /* X32 may not have any REX prefix. */
1186 if (ABI_64_P (abfd
))
1188 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1192 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1193 if (val
!= 0x8b && val
!= 0x03)
1196 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1197 return (val
& 0xc7) == 5;
1199 case R_X86_64_GOTPC32_TLSDESC
:
1200 /* Check transition from GDesc access model:
1201 leaq x@tlsdesc(%rip), %rax
1203 Make sure it's a leaq adding rip to a 32-bit offset
1204 into any register, although it's probably almost always
1207 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1210 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1211 if ((val
& 0xfb) != 0x48)
1214 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1217 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1218 return (val
& 0xc7) == 0x05;
1220 case R_X86_64_TLSDESC_CALL
:
1221 /* Check transition from GDesc access model:
1222 call *x@tlsdesc(%rax)
1224 if (offset
+ 2 <= sec
->size
)
1226 /* Make sure that it's a call *x@tlsdesc(%rax). */
1227 call
= contents
+ offset
;
1228 return call
[0] == 0xff && call
[1] == 0x10;
1238 /* Return TRUE if the TLS access transition is OK or no transition
1239 will be performed. Update R_TYPE if there is a transition. */
1242 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1243 asection
*sec
, bfd_byte
*contents
,
1244 Elf_Internal_Shdr
*symtab_hdr
,
1245 struct elf_link_hash_entry
**sym_hashes
,
1246 unsigned int *r_type
, int tls_type
,
1247 const Elf_Internal_Rela
*rel
,
1248 const Elf_Internal_Rela
*relend
,
1249 struct elf_link_hash_entry
*h
,
1250 unsigned long r_symndx
,
1251 bfd_boolean from_relocate_section
)
1253 unsigned int from_type
= *r_type
;
1254 unsigned int to_type
= from_type
;
1255 bfd_boolean check
= TRUE
;
1257 /* Skip TLS transition for functions. */
1259 && (h
->type
== STT_FUNC
1260 || h
->type
== STT_GNU_IFUNC
))
1265 case R_X86_64_TLSGD
:
1266 case R_X86_64_GOTPC32_TLSDESC
:
1267 case R_X86_64_TLSDESC_CALL
:
1268 case R_X86_64_GOTTPOFF
:
1269 if (bfd_link_executable (info
))
1272 to_type
= R_X86_64_TPOFF32
;
1274 to_type
= R_X86_64_GOTTPOFF
;
1277 /* When we are called from elf_x86_64_relocate_section, there may
1278 be additional transitions based on TLS_TYPE. */
1279 if (from_relocate_section
)
1281 unsigned int new_to_type
= to_type
;
1283 if (bfd_link_executable (info
)
1286 && tls_type
== GOT_TLS_IE
)
1287 new_to_type
= R_X86_64_TPOFF32
;
1289 if (to_type
== R_X86_64_TLSGD
1290 || to_type
== R_X86_64_GOTPC32_TLSDESC
1291 || to_type
== R_X86_64_TLSDESC_CALL
)
1293 if (tls_type
== GOT_TLS_IE
)
1294 new_to_type
= R_X86_64_GOTTPOFF
;
1297 /* We checked the transition before when we were called from
1298 elf_x86_64_check_relocs. We only want to check the new
1299 transition which hasn't been checked before. */
1300 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1301 to_type
= new_to_type
;
1306 case R_X86_64_TLSLD
:
1307 if (bfd_link_executable (info
))
1308 to_type
= R_X86_64_TPOFF32
;
1315 /* Return TRUE if there is no transition. */
1316 if (from_type
== to_type
)
1319 /* Check if the transition can be performed. */
1321 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1322 symtab_hdr
, sym_hashes
,
1323 from_type
, rel
, relend
))
1325 reloc_howto_type
*from
, *to
;
1328 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1329 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1332 name
= h
->root
.root
.string
;
1335 struct elf_x86_link_hash_table
*htab
;
1337 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1342 Elf_Internal_Sym
*isym
;
1344 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1346 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1351 /* xgettext:c-format */
1352 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1353 "in section `%A' failed"),
1354 abfd
, from
->name
, to
->name
, name
, rel
->r_offset
, sec
);
1355 bfd_set_error (bfd_error_bad_value
);
1363 /* Rename some of the generic section flags to better document how they
1365 #define check_relocs_failed sec_flg0
1368 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1369 bfd
*input_bfd
, asection
*sec
,
1370 struct elf_link_hash_entry
*h
,
1371 Elf_Internal_Shdr
*symtab_hdr
,
1372 Elf_Internal_Sym
*isym
,
1373 reloc_howto_type
*howto
)
1376 const char *und
= "";
1377 const char *pic
= "";
1383 name
= h
->root
.root
.string
;
1384 switch (ELF_ST_VISIBILITY (h
->other
))
1387 v
= _("hidden symbol ");
1390 v
= _("internal symbol ");
1393 v
= _("protected symbol ");
1396 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1397 v
= _("protected symbol ");
1400 pic
= _("; recompile with -fPIC");
1404 if (!h
->def_regular
&& !h
->def_dynamic
)
1405 und
= _("undefined ");
1409 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1410 pic
= _("; recompile with -fPIC");
1413 if (bfd_link_dll (info
))
1414 object
= _("a shared object");
1415 else if (bfd_link_pie (info
))
1416 object
= _("a PIE object");
1418 object
= _("a PDE object");
1420 /* xgettext:c-format */
1421 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1422 "not be used when making %s%s"),
1423 input_bfd
, howto
->name
, und
, v
, name
,
1425 bfd_set_error (bfd_error_bad_value
);
1426 sec
->check_relocs_failed
= 1;
1430 /* With the local symbol, foo, we convert
1431 mov foo@GOTPCREL(%rip), %reg
1435 call/jmp *foo@GOTPCREL(%rip)
1437 nop call foo/jmp foo nop
1438 When PIC is false, convert
1439 test %reg, foo@GOTPCREL(%rip)
1443 binop foo@GOTPCREL(%rip), %reg
1446 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1450 elf_x86_64_convert_load_reloc (bfd
*abfd
,
1452 unsigned int *r_type_p
,
1453 Elf_Internal_Rela
*irel
,
1454 struct elf_link_hash_entry
*h
,
1455 bfd_boolean
*converted
,
1456 struct bfd_link_info
*link_info
)
1458 struct elf_x86_link_hash_table
*htab
;
1460 bfd_boolean no_overflow
;
1462 bfd_boolean to_reloc_pc32
;
1464 bfd_signed_vma raddend
;
1465 unsigned int opcode
;
1467 unsigned int r_type
= *r_type_p
;
1468 unsigned int r_symndx
;
1469 bfd_vma roff
= irel
->r_offset
;
1471 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1474 raddend
= irel
->r_addend
;
1475 /* Addend for 32-bit PC-relative relocation must be -4. */
1479 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1480 is_pic
= bfd_link_pic (link_info
);
1482 relocx
= (r_type
== R_X86_64_GOTPCRELX
1483 || r_type
== R_X86_64_REX_GOTPCRELX
);
1485 /* TRUE if --no-relax is used. */
1486 no_overflow
= link_info
->disable_target_specific_optimizations
> 1;
1488 r_symndx
= htab
->r_sym (irel
->r_info
);
1490 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1492 /* Convert mov to lea since it has been done for a while. */
1495 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1496 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1497 test, xor instructions. */
1502 /* We convert only to R_X86_64_PC32:
1504 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1505 3. no_overflow is true.
1508 to_reloc_pc32
= (opcode
== 0xff
1513 /* Get the symbol referred to by the reloc. */
1516 Elf_Internal_Sym
*isym
1517 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1519 /* Skip relocation against undefined symbols. */
1520 if (isym
->st_shndx
== SHN_UNDEF
)
1523 if (isym
->st_shndx
== SHN_ABS
)
1524 tsec
= bfd_abs_section_ptr
;
1525 else if (isym
->st_shndx
== SHN_COMMON
)
1526 tsec
= bfd_com_section_ptr
;
1527 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1528 tsec
= &_bfd_elf_large_com_section
;
1530 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1534 /* Undefined weak symbol is only bound locally in executable
1535 and its reference is resolved as 0 without relocation
1536 overflow. We can only perform this optimization for
1537 GOTPCRELX relocations since we need to modify REX byte.
1538 It is OK convert mov with R_X86_64_GOTPCREL to
1540 bfd_boolean local_ref
;
1541 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
1543 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1544 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1545 if ((relocx
|| opcode
== 0x8b)
1546 && (h
->root
.type
== bfd_link_hash_undefweak
1552 /* Skip for branch instructions since R_X86_64_PC32
1559 /* For non-branch instructions, we can convert to
1560 R_X86_64_32/R_X86_64_32S since we know if there
1562 to_reloc_pc32
= FALSE
;
1565 /* Since we don't know the current PC when PIC is true,
1566 we can't convert to R_X86_64_PC32. */
1567 if (to_reloc_pc32
&& is_pic
)
1572 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1573 ld.so may use its link-time address. */
1574 else if (h
->start_stop
1577 || h
->root
.type
== bfd_link_hash_defined
1578 || h
->root
.type
== bfd_link_hash_defweak
)
1579 && h
!= htab
->elf
.hdynamic
1582 /* bfd_link_hash_new or bfd_link_hash_undefined is
1583 set by an assignment in a linker script in
1584 bfd_elf_record_link_assignment. start_stop is set
1585 on __start_SECNAME/__stop_SECNAME which mark section
1590 && (h
->root
.type
== bfd_link_hash_new
1591 || h
->root
.type
== bfd_link_hash_undefined
1592 || ((h
->root
.type
== bfd_link_hash_defined
1593 || h
->root
.type
== bfd_link_hash_defweak
)
1594 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1596 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1601 tsec
= h
->root
.u
.def
.section
;
1607 /* Don't convert GOTPCREL relocation against large section. */
1608 if (elf_section_data (tsec
) != NULL
1609 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1612 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1619 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1624 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1626 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1629 /* Convert to "jmp foo nop". */
1632 nop_offset
= irel
->r_offset
+ 3;
1633 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1634 irel
->r_offset
-= 1;
1635 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1639 struct elf_x86_link_hash_entry
*eh
1640 = (struct elf_x86_link_hash_entry
*) h
;
1642 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1645 /* To support TLS optimization, always use addr32 prefix for
1646 "call *__tls_get_addr@GOTPCREL(%rip)". */
1647 if (eh
&& eh
->tls_get_addr
)
1650 nop_offset
= irel
->r_offset
- 2;
1654 nop
= link_info
->call_nop_byte
;
1655 if (link_info
->call_nop_as_suffix
)
1657 nop_offset
= irel
->r_offset
+ 3;
1658 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1659 irel
->r_offset
-= 1;
1660 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1663 nop_offset
= irel
->r_offset
- 2;
1666 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1667 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1668 r_type
= R_X86_64_PC32
;
1673 unsigned int rex_mask
= REX_R
;
1675 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1676 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1684 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1685 "lea foo(%rip), %reg". */
1687 r_type
= R_X86_64_PC32
;
1691 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1692 "mov $foo, %reg". */
1694 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1695 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1696 if ((rex
& REX_W
) != 0
1697 && ABI_64_P (link_info
->output_bfd
))
1699 /* Keep the REX_W bit in REX byte for LP64. */
1700 r_type
= R_X86_64_32S
;
1701 goto rewrite_modrm_rex
;
1705 /* If the REX_W bit in REX byte isn't needed,
1706 use R_X86_64_32 and clear the W bit to avoid
1707 sign-extend imm32 to imm64. */
1708 r_type
= R_X86_64_32
;
1709 /* Clear the W bit in REX byte. */
1711 goto rewrite_modrm_rex
;
1717 /* R_X86_64_PC32 isn't supported. */
1721 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1724 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1725 "test $foo, %reg". */
1726 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1731 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1732 "binop $foo, %reg". */
1733 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1737 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1738 overflow when sign-extending imm32 to imm64. */
1739 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1742 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1746 /* Move the R bit to the B bit in REX byte. */
1747 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1748 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1751 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1755 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1759 irel
->r_info
= htab
->r_info (r_symndx
,
1760 r_type
| R_X86_64_converted_reloc_bit
);
1767 /* Look through the relocs for a section during the first phase, and
1768 calculate needed space in the global offset table, procedure
1769 linkage table, and dynamic reloc sections. */
1772 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1774 const Elf_Internal_Rela
*relocs
)
1776 struct elf_x86_link_hash_table
*htab
;
1777 Elf_Internal_Shdr
*symtab_hdr
;
1778 struct elf_link_hash_entry
**sym_hashes
;
1779 const Elf_Internal_Rela
*rel
;
1780 const Elf_Internal_Rela
*rel_end
;
1784 if (bfd_link_relocatable (info
))
1787 /* Don't do anything special with non-loaded, non-alloced sections.
1788 In particular, any relocs in such sections should not affect GOT
1789 and PLT reference counting (ie. we don't allow them to create GOT
1790 or PLT entries), there's no possibility or desire to optimize TLS
1791 relocs, and there's not much point in propagating relocs to shared
1792 libs that the dynamic linker won't relocate. */
1793 if ((sec
->flags
& SEC_ALLOC
) == 0)
1796 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1799 sec
->check_relocs_failed
= 1;
1803 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1805 /* Get the section contents. */
1806 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1807 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1808 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1810 sec
->check_relocs_failed
= 1;
1814 symtab_hdr
= &elf_symtab_hdr (abfd
);
1815 sym_hashes
= elf_sym_hashes (abfd
);
1819 rel_end
= relocs
+ sec
->reloc_count
;
1820 for (rel
= relocs
; rel
< rel_end
; rel
++)
1822 unsigned int r_type
;
1823 unsigned int r_symndx
;
1824 struct elf_link_hash_entry
*h
;
1825 struct elf_x86_link_hash_entry
*eh
;
1826 Elf_Internal_Sym
*isym
;
1828 bfd_boolean size_reloc
;
1829 bfd_boolean converted_reloc
;
1831 r_symndx
= htab
->r_sym (rel
->r_info
);
1832 r_type
= ELF32_R_TYPE (rel
->r_info
);
1834 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1836 /* xgettext:c-format */
1837 _bfd_error_handler (_("%B: bad symbol index: %d"),
1842 if (r_symndx
< symtab_hdr
->sh_info
)
1844 /* A local symbol. */
1845 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1850 /* Check relocation against local STT_GNU_IFUNC symbol. */
1851 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1853 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1858 /* Fake a STT_GNU_IFUNC symbol. */
1859 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1861 h
->type
= STT_GNU_IFUNC
;
1864 h
->forced_local
= 1;
1865 h
->root
.type
= bfd_link_hash_defined
;
1873 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1874 while (h
->root
.type
== bfd_link_hash_indirect
1875 || h
->root
.type
== bfd_link_hash_warning
)
1876 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1879 /* Check invalid x32 relocations. */
1880 if (!ABI_64_P (abfd
))
1886 case R_X86_64_DTPOFF64
:
1887 case R_X86_64_TPOFF64
:
1889 case R_X86_64_GOTOFF64
:
1890 case R_X86_64_GOT64
:
1891 case R_X86_64_GOTPCREL64
:
1892 case R_X86_64_GOTPC64
:
1893 case R_X86_64_GOTPLT64
:
1894 case R_X86_64_PLTOFF64
:
1897 name
= h
->root
.root
.string
;
1899 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1902 /* xgettext:c-format */
1903 (_("%B: relocation %s against symbol `%s' isn't "
1904 "supported in x32 mode"), abfd
,
1905 x86_64_elf_howto_table
[r_type
].name
, name
);
1906 bfd_set_error (bfd_error_bad_value
);
1914 /* It is referenced by a non-shared object. */
1916 h
->root
.non_ir_ref_regular
= 1;
1918 if (h
->type
== STT_GNU_IFUNC
)
1919 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1920 |= elf_gnu_symbol_ifunc
;
1923 converted_reloc
= FALSE
;
1924 if ((r_type
== R_X86_64_GOTPCREL
1925 || r_type
== R_X86_64_GOTPCRELX
1926 || r_type
== R_X86_64_REX_GOTPCRELX
)
1927 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1929 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1930 if (!elf_x86_64_convert_load_reloc (abfd
, contents
, &r_type
,
1931 irel
, h
, &converted_reloc
,
1936 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
1937 symtab_hdr
, sym_hashes
,
1938 &r_type
, GOT_UNKNOWN
,
1939 rel
, rel_end
, h
, r_symndx
, FALSE
))
1942 eh
= (struct elf_x86_link_hash_entry
*) h
;
1945 case R_X86_64_TLSLD
:
1946 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1949 case R_X86_64_TPOFF32
:
1950 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
1951 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
1952 &x86_64_elf_howto_table
[r_type
]);
1954 eh
->has_got_reloc
= 1;
1957 case R_X86_64_GOTTPOFF
:
1958 if (!bfd_link_executable (info
))
1959 info
->flags
|= DF_STATIC_TLS
;
1962 case R_X86_64_GOT32
:
1963 case R_X86_64_GOTPCREL
:
1964 case R_X86_64_GOTPCRELX
:
1965 case R_X86_64_REX_GOTPCRELX
:
1966 case R_X86_64_TLSGD
:
1967 case R_X86_64_GOT64
:
1968 case R_X86_64_GOTPCREL64
:
1969 case R_X86_64_GOTPLT64
:
1970 case R_X86_64_GOTPC32_TLSDESC
:
1971 case R_X86_64_TLSDESC_CALL
:
1972 /* This symbol requires a global offset table entry. */
1974 int tls_type
, old_tls_type
;
1978 default: tls_type
= GOT_NORMAL
; break;
1979 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1980 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1981 case R_X86_64_GOTPC32_TLSDESC
:
1982 case R_X86_64_TLSDESC_CALL
:
1983 tls_type
= GOT_TLS_GDESC
; break;
1988 h
->got
.refcount
+= 1;
1989 old_tls_type
= eh
->tls_type
;
1993 bfd_signed_vma
*local_got_refcounts
;
1995 /* This is a global offset table entry for a local symbol. */
1996 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1997 if (local_got_refcounts
== NULL
)
2001 size
= symtab_hdr
->sh_info
;
2002 size
*= sizeof (bfd_signed_vma
)
2003 + sizeof (bfd_vma
) + sizeof (char);
2004 local_got_refcounts
= ((bfd_signed_vma
*)
2005 bfd_zalloc (abfd
, size
));
2006 if (local_got_refcounts
== NULL
)
2008 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2009 elf_x86_local_tlsdesc_gotent (abfd
)
2010 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2011 elf_x86_local_got_tls_type (abfd
)
2012 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2014 local_got_refcounts
[r_symndx
] += 1;
2016 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2019 /* If a TLS symbol is accessed using IE at least once,
2020 there is no point to use dynamic model for it. */
2021 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2022 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2023 || tls_type
!= GOT_TLS_IE
))
2025 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2026 tls_type
= old_tls_type
;
2027 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2028 && GOT_TLS_GD_ANY_P (tls_type
))
2029 tls_type
|= old_tls_type
;
2033 name
= h
->root
.root
.string
;
2035 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2038 /* xgettext:c-format */
2039 (_("%B: '%s' accessed both as normal and"
2040 " thread local symbol"),
2042 bfd_set_error (bfd_error_bad_value
);
2047 if (old_tls_type
!= tls_type
)
2050 eh
->tls_type
= tls_type
;
2052 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2057 case R_X86_64_GOTOFF64
:
2058 case R_X86_64_GOTPC32
:
2059 case R_X86_64_GOTPC64
:
2062 eh
->has_got_reloc
= 1;
2065 case R_X86_64_PLT32
:
2066 case R_X86_64_PLT32_BND
:
2067 /* This symbol requires a procedure linkage table entry. We
2068 actually build the entry in adjust_dynamic_symbol,
2069 because this might be a case of linking PIC code which is
2070 never referenced by a dynamic object, in which case we
2071 don't need to generate a procedure linkage table entry
2074 /* If this is a local symbol, we resolve it directly without
2075 creating a procedure linkage table entry. */
2079 eh
->has_got_reloc
= 1;
2081 h
->plt
.refcount
+= 1;
2084 case R_X86_64_PLTOFF64
:
2085 /* This tries to form the 'address' of a function relative
2086 to GOT. For global symbols we need a PLT entry. */
2090 h
->plt
.refcount
+= 1;
2094 case R_X86_64_SIZE32
:
2095 case R_X86_64_SIZE64
:
2100 if (!ABI_64_P (abfd
))
2106 /* Check relocation overflow as these relocs may lead to
2107 run-time relocation overflow. Don't error out for
2108 sections we don't care about, such as debug sections or
2109 when relocation overflow check is disabled. */
2110 if (!info
->no_reloc_overflow_check
2112 && (bfd_link_pic (info
)
2113 || (bfd_link_executable (info
)
2117 && (sec
->flags
& SEC_READONLY
) == 0)))
2118 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2119 &x86_64_elf_howto_table
[r_type
]);
2125 case R_X86_64_PC32_BND
:
2129 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2130 eh
->has_non_got_reloc
= 1;
2131 /* We are called after all symbols have been resolved. Only
2132 relocation against STT_GNU_IFUNC symbol must go through
2135 && (bfd_link_executable (info
)
2136 || h
->type
== STT_GNU_IFUNC
))
2138 /* If this reloc is in a read-only section, we might
2139 need a copy reloc. We can't check reliably at this
2140 stage whether the section is read-only, as input
2141 sections have not yet been mapped to output sections.
2142 Tentatively set the flag for now, and correct in
2143 adjust_dynamic_symbol. */
2146 /* We may need a .plt entry if the symbol is a function
2147 defined in a shared lib or is a STT_GNU_IFUNC function
2148 referenced from the code or read-only section. */
2150 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2151 h
->plt
.refcount
+= 1;
2153 if (r_type
== R_X86_64_PC32
)
2155 /* Since something like ".long foo - ." may be used
2156 as pointer, make sure that PLT is used if foo is
2157 a function defined in a shared library. */
2158 if ((sec
->flags
& SEC_CODE
) == 0)
2159 h
->pointer_equality_needed
= 1;
2161 else if (r_type
!= R_X86_64_PC32_BND
2162 && r_type
!= R_X86_64_PC64
)
2164 h
->pointer_equality_needed
= 1;
2165 /* At run-time, R_X86_64_64 can be resolved for both
2166 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2167 can only be resolved for x32. */
2168 if ((sec
->flags
& SEC_READONLY
) == 0
2169 && (r_type
== R_X86_64_64
2170 || (!ABI_64_P (abfd
)
2171 && (r_type
== R_X86_64_32
2172 || r_type
== R_X86_64_32S
))))
2173 eh
->func_pointer_refcount
+= 1;
2179 /* If we are creating a shared library, and this is a reloc
2180 against a global symbol, or a non PC relative reloc
2181 against a local symbol, then we need to copy the reloc
2182 into the shared library. However, if we are linking with
2183 -Bsymbolic, we do not need to copy a reloc against a
2184 global symbol which is defined in an object we are
2185 including in the link (i.e., DEF_REGULAR is set). At
2186 this point we have not seen all the input files, so it is
2187 possible that DEF_REGULAR is not set now but will be set
2188 later (it is never cleared). In case of a weak definition,
2189 DEF_REGULAR may be cleared later by a strong definition in
2190 a shared library. We account for that possibility below by
2191 storing information in the relocs_copied field of the hash
2192 table entry. A similar situation occurs when creating
2193 shared libraries and symbol visibility changes render the
2196 If on the other hand, we are creating an executable, we
2197 may need to keep relocations for symbols satisfied by a
2198 dynamic library if we manage to avoid copy relocs for the
2201 Generate dynamic pointer relocation against STT_GNU_IFUNC
2202 symbol in the non-code section. */
2203 if ((bfd_link_pic (info
)
2204 && (! IS_X86_64_PCREL_TYPE (r_type
)
2206 && (! (bfd_link_pie (info
)
2207 || SYMBOLIC_BIND (info
, h
))
2208 || h
->root
.type
== bfd_link_hash_defweak
2209 || !h
->def_regular
))))
2211 && h
->type
== STT_GNU_IFUNC
2212 && r_type
== htab
->pointer_r_type
2213 && (sec
->flags
& SEC_CODE
) == 0)
2214 || (ELIMINATE_COPY_RELOCS
2215 && !bfd_link_pic (info
)
2217 && (h
->root
.type
== bfd_link_hash_defweak
2218 || !h
->def_regular
)))
2220 struct elf_dyn_relocs
*p
;
2221 struct elf_dyn_relocs
**head
;
2223 /* We must copy these reloc types into the output file.
2224 Create a reloc section in dynobj and make room for
2228 sreloc
= _bfd_elf_make_dynamic_reloc_section
2229 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2230 abfd
, /*rela?*/ TRUE
);
2236 /* If this is a global symbol, we count the number of
2237 relocations we need for this symbol. */
2239 head
= &eh
->dyn_relocs
;
2242 /* Track dynamic relocs needed for local syms too.
2243 We really need local syms available to do this
2248 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2253 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2257 /* Beware of type punned pointers vs strict aliasing
2259 vpp
= &(elf_section_data (s
)->local_dynrel
);
2260 head
= (struct elf_dyn_relocs
**)vpp
;
2264 if (p
== NULL
|| p
->sec
!= sec
)
2266 bfd_size_type amt
= sizeof *p
;
2268 p
= ((struct elf_dyn_relocs
*)
2269 bfd_alloc (htab
->elf
.dynobj
, amt
));
2280 /* Count size relocation as PC-relative relocation. */
2281 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2286 /* This relocation describes the C++ object vtable hierarchy.
2287 Reconstruct it for later use during GC. */
2288 case R_X86_64_GNU_VTINHERIT
:
2289 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2293 /* This relocation describes which C++ vtable entries are actually
2294 used. Record for later use during GC. */
2295 case R_X86_64_GNU_VTENTRY
:
2296 BFD_ASSERT (h
!= NULL
);
2298 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2307 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2309 if (!info
->keep_memory
)
2313 /* Cache the section contents for elf_link_input_bfd. */
2314 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2321 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2323 sec
->check_relocs_failed
= 1;
2327 /* Return the relocation value for @tpoff relocation
2328 if STT_TLS virtual address is ADDRESS. */
2331 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2333 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2334 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2335 bfd_vma static_tls_size
;
2337 /* If tls_segment is NULL, we should have signalled an error already. */
2338 if (htab
->tls_sec
== NULL
)
2341 /* Consider special static TLS alignment requirements. */
2342 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2343 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2346 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2350 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2352 /* Opcode Instruction
2355 0x0f 0x8x conditional jump */
2357 && (contents
[offset
- 1] == 0xe8
2358 || contents
[offset
- 1] == 0xe9))
2360 && contents
[offset
- 2] == 0x0f
2361 && (contents
[offset
- 1] & 0xf0) == 0x80));
2364 /* Relocate an x86_64 ELF section. */
2367 elf_x86_64_relocate_section (bfd
*output_bfd
,
2368 struct bfd_link_info
*info
,
2370 asection
*input_section
,
2372 Elf_Internal_Rela
*relocs
,
2373 Elf_Internal_Sym
*local_syms
,
2374 asection
**local_sections
)
2376 struct elf_x86_link_hash_table
*htab
;
2377 Elf_Internal_Shdr
*symtab_hdr
;
2378 struct elf_link_hash_entry
**sym_hashes
;
2379 bfd_vma
*local_got_offsets
;
2380 bfd_vma
*local_tlsdesc_gotents
;
2381 Elf_Internal_Rela
*rel
;
2382 Elf_Internal_Rela
*wrel
;
2383 Elf_Internal_Rela
*relend
;
2384 unsigned int plt_entry_size
;
2386 /* Skip if check_relocs failed. */
2387 if (input_section
->check_relocs_failed
)
2390 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2394 BFD_ASSERT (is_x86_elf (input_bfd
, htab
));
2396 plt_entry_size
= htab
->plt
.plt_entry_size
;
2397 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2398 sym_hashes
= elf_sym_hashes (input_bfd
);
2399 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2400 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2402 _bfd_x86_elf_set_tls_module_base (info
);
2404 rel
= wrel
= relocs
;
2405 relend
= relocs
+ input_section
->reloc_count
;
2406 for (; rel
< relend
; wrel
++, rel
++)
2408 unsigned int r_type
, r_type_tls
;
2409 reloc_howto_type
*howto
;
2410 unsigned long r_symndx
;
2411 struct elf_link_hash_entry
*h
;
2412 struct elf_x86_link_hash_entry
*eh
;
2413 Elf_Internal_Sym
*sym
;
2415 bfd_vma off
, offplt
, plt_offset
;
2417 bfd_boolean unresolved_reloc
;
2418 bfd_reloc_status_type r
;
2420 asection
*base_got
, *resolved_plt
;
2422 bfd_boolean resolved_to_zero
;
2423 bfd_boolean relative_reloc
;
2424 bfd_boolean converted_reloc
;
2426 r_type
= ELF32_R_TYPE (rel
->r_info
);
2427 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2428 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2435 converted_reloc
= (r_type
& R_X86_64_converted_reloc_bit
) != 0;
2436 r_type
&= ~R_X86_64_converted_reloc_bit
;
2438 if (r_type
>= (int) R_X86_64_standard
)
2439 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2441 if (r_type
!= (int) R_X86_64_32
2442 || ABI_64_P (output_bfd
))
2443 howto
= x86_64_elf_howto_table
+ r_type
;
2445 howto
= (x86_64_elf_howto_table
2446 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
2447 r_symndx
= htab
->r_sym (rel
->r_info
);
2451 unresolved_reloc
= FALSE
;
2452 if (r_symndx
< symtab_hdr
->sh_info
)
2454 sym
= local_syms
+ r_symndx
;
2455 sec
= local_sections
[r_symndx
];
2457 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2459 st_size
= sym
->st_size
;
2461 /* Relocate against local STT_GNU_IFUNC symbol. */
2462 if (!bfd_link_relocatable (info
)
2463 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2465 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
2470 /* Set STT_GNU_IFUNC symbol value. */
2471 h
->root
.u
.def
.value
= sym
->st_value
;
2472 h
->root
.u
.def
.section
= sec
;
2477 bfd_boolean warned ATTRIBUTE_UNUSED
;
2478 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2480 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2481 r_symndx
, symtab_hdr
, sym_hashes
,
2483 unresolved_reloc
, warned
, ignored
);
2487 if (sec
!= NULL
&& discarded_section (sec
))
2489 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2490 contents
+ rel
->r_offset
);
2491 wrel
->r_offset
= rel
->r_offset
;
2495 /* For ld -r, remove relocations in debug sections against
2496 sections defined in discarded sections. Not done for
2497 eh_frame editing code expects to be present. */
2498 if (bfd_link_relocatable (info
)
2499 && (input_section
->flags
& SEC_DEBUGGING
))
2505 if (bfd_link_relocatable (info
))
2512 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
2514 if (r_type
== R_X86_64_64
)
2516 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2517 zero-extend it to 64bit if addend is zero. */
2518 r_type
= R_X86_64_32
;
2519 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2521 else if (r_type
== R_X86_64_SIZE64
)
2523 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2524 zero-extend it to 64bit if addend is zero. */
2525 r_type
= R_X86_64_SIZE32
;
2526 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2530 eh
= (struct elf_x86_link_hash_entry
*) h
;
2532 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2533 it here if it is defined in a non-shared object. */
2535 && h
->type
== STT_GNU_IFUNC
2541 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2543 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2544 sections because such sections are not SEC_ALLOC and
2545 thus ld.so will not process them. */
2546 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2556 case R_X86_64_GOTPCREL
:
2557 case R_X86_64_GOTPCRELX
:
2558 case R_X86_64_REX_GOTPCRELX
:
2559 case R_X86_64_GOTPCREL64
:
2560 base_got
= htab
->elf
.sgot
;
2561 off
= h
->got
.offset
;
2563 if (base_got
== NULL
)
2566 if (off
== (bfd_vma
) -1)
2568 /* We can't use h->got.offset here to save state, or
2569 even just remember the offset, as finish_dynamic_symbol
2570 would use that as offset into .got. */
2572 if (h
->plt
.offset
== (bfd_vma
) -1)
2575 if (htab
->elf
.splt
!= NULL
)
2577 plt_index
= (h
->plt
.offset
/ plt_entry_size
2578 - htab
->plt
.has_plt0
);
2579 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2580 base_got
= htab
->elf
.sgotplt
;
2584 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2585 off
= plt_index
* GOT_ENTRY_SIZE
;
2586 base_got
= htab
->elf
.igotplt
;
2589 if (h
->dynindx
== -1
2593 /* This references the local defitionion. We must
2594 initialize this entry in the global offset table.
2595 Since the offset must always be a multiple of 8,
2596 we use the least significant bit to record
2597 whether we have initialized it already.
2599 When doing a dynamic link, we create a .rela.got
2600 relocation entry to initialize the value. This
2601 is done in the finish_dynamic_symbol routine. */
2606 bfd_put_64 (output_bfd
, relocation
,
2607 base_got
->contents
+ off
);
2608 /* Note that this is harmless for the GOTPLT64
2609 case, as -1 | 1 still is -1. */
2615 relocation
= (base_got
->output_section
->vma
2616 + base_got
->output_offset
+ off
);
2621 if (h
->plt
.offset
== (bfd_vma
) -1)
2623 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2624 if (r_type
== htab
->pointer_r_type
2625 && (input_section
->flags
& SEC_CODE
) == 0)
2626 goto do_ifunc_pointer
;
2627 goto bad_ifunc_reloc
;
2630 /* STT_GNU_IFUNC symbol must go through PLT. */
2631 if (htab
->elf
.splt
!= NULL
)
2633 if (htab
->plt_second
!= NULL
)
2635 resolved_plt
= htab
->plt_second
;
2636 plt_offset
= eh
->plt_second
.offset
;
2640 resolved_plt
= htab
->elf
.splt
;
2641 plt_offset
= h
->plt
.offset
;
2646 resolved_plt
= htab
->elf
.iplt
;
2647 plt_offset
= h
->plt
.offset
;
2650 relocation
= (resolved_plt
->output_section
->vma
2651 + resolved_plt
->output_offset
+ plt_offset
);
2657 if (h
->root
.root
.string
)
2658 name
= h
->root
.root
.string
;
2660 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2663 /* xgettext:c-format */
2664 (_("%B: relocation %s against STT_GNU_IFUNC "
2665 "symbol `%s' isn't supported"), input_bfd
,
2667 bfd_set_error (bfd_error_bad_value
);
2671 if (bfd_link_pic (info
))
2676 if (ABI_64_P (output_bfd
))
2681 if (rel
->r_addend
!= 0)
2683 if (h
->root
.root
.string
)
2684 name
= h
->root
.root
.string
;
2686 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2689 /* xgettext:c-format */
2690 (_("%B: relocation %s against STT_GNU_IFUNC "
2691 "symbol `%s' has non-zero addend: %Ld"),
2692 input_bfd
, howto
->name
, name
, rel
->r_addend
);
2693 bfd_set_error (bfd_error_bad_value
);
2697 /* Generate dynamic relcoation only when there is a
2698 non-GOT reference in a shared object or there is no
2700 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2701 || h
->plt
.offset
== (bfd_vma
) -1)
2703 Elf_Internal_Rela outrel
;
2706 /* Need a dynamic relocation to get the real function
2708 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2712 if (outrel
.r_offset
== (bfd_vma
) -1
2713 || outrel
.r_offset
== (bfd_vma
) -2)
2716 outrel
.r_offset
+= (input_section
->output_section
->vma
2717 + input_section
->output_offset
);
2719 if (h
->dynindx
== -1
2721 || bfd_link_executable (info
))
2723 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
2724 h
->root
.root
.string
,
2725 h
->root
.u
.def
.section
->owner
);
2727 /* This symbol is resolved locally. */
2728 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2729 outrel
.r_addend
= (h
->root
.u
.def
.value
2730 + h
->root
.u
.def
.section
->output_section
->vma
2731 + h
->root
.u
.def
.section
->output_offset
);
2735 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2736 outrel
.r_addend
= 0;
2739 /* Dynamic relocations are stored in
2740 1. .rela.ifunc section in PIC object.
2741 2. .rela.got section in dynamic executable.
2742 3. .rela.iplt section in static executable. */
2743 if (bfd_link_pic (info
))
2744 sreloc
= htab
->elf
.irelifunc
;
2745 else if (htab
->elf
.splt
!= NULL
)
2746 sreloc
= htab
->elf
.srelgot
;
2748 sreloc
= htab
->elf
.irelplt
;
2749 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2751 /* If this reloc is against an external symbol, we
2752 do not want to fiddle with the addend. Otherwise,
2753 we need to include the symbol value so that it
2754 becomes an addend for the dynamic reloc. For an
2755 internal symbol, we have updated addend. */
2760 case R_X86_64_PC32_BND
:
2762 case R_X86_64_PLT32
:
2763 case R_X86_64_PLT32_BND
:
2768 resolved_to_zero
= (eh
!= NULL
2769 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2771 /* When generating a shared object, the relocations handled here are
2772 copied into the output file to be resolved at run time. */
2775 case R_X86_64_GOT32
:
2776 case R_X86_64_GOT64
:
2777 /* Relocation is to the entry for this symbol in the global
2779 case R_X86_64_GOTPCREL
:
2780 case R_X86_64_GOTPCRELX
:
2781 case R_X86_64_REX_GOTPCRELX
:
2782 case R_X86_64_GOTPCREL64
:
2783 /* Use global offset table entry as symbol value. */
2784 case R_X86_64_GOTPLT64
:
2785 /* This is obsolete and treated the same as GOT64. */
2786 base_got
= htab
->elf
.sgot
;
2788 if (htab
->elf
.sgot
== NULL
)
2791 relative_reloc
= FALSE
;
2796 off
= h
->got
.offset
;
2798 && h
->plt
.offset
!= (bfd_vma
)-1
2799 && off
== (bfd_vma
)-1)
2801 /* We can't use h->got.offset here to save
2802 state, or even just remember the offset, as
2803 finish_dynamic_symbol would use that as offset into
2805 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
2806 - htab
->plt
.has_plt0
);
2807 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2808 base_got
= htab
->elf
.sgotplt
;
2811 dyn
= htab
->elf
.dynamic_sections_created
;
2813 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
2814 || (bfd_link_pic (info
)
2815 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
2816 || (ELF_ST_VISIBILITY (h
->other
)
2817 && h
->root
.type
== bfd_link_hash_undefweak
))
2819 /* This is actually a static link, or it is a -Bsymbolic
2820 link and the symbol is defined locally, or the symbol
2821 was forced to be local because of a version file. We
2822 must initialize this entry in the global offset table.
2823 Since the offset must always be a multiple of 8, we
2824 use the least significant bit to record whether we
2825 have initialized it already.
2827 When doing a dynamic link, we create a .rela.got
2828 relocation entry to initialize the value. This is
2829 done in the finish_dynamic_symbol routine. */
2834 bfd_put_64 (output_bfd
, relocation
,
2835 base_got
->contents
+ off
);
2836 /* Note that this is harmless for the GOTPLT64 case,
2837 as -1 | 1 still is -1. */
2840 if (h
->dynindx
== -1
2842 && h
->root
.type
!= bfd_link_hash_undefweak
2843 && bfd_link_pic (info
))
2845 /* If this symbol isn't dynamic in PIC,
2846 generate R_X86_64_RELATIVE here. */
2847 eh
->no_finish_dynamic_symbol
= 1;
2848 relative_reloc
= TRUE
;
2853 unresolved_reloc
= FALSE
;
2857 if (local_got_offsets
== NULL
)
2860 off
= local_got_offsets
[r_symndx
];
2862 /* The offset must always be a multiple of 8. We use
2863 the least significant bit to record whether we have
2864 already generated the necessary reloc. */
2869 bfd_put_64 (output_bfd
, relocation
,
2870 base_got
->contents
+ off
);
2871 local_got_offsets
[r_symndx
] |= 1;
2873 if (bfd_link_pic (info
))
2874 relative_reloc
= TRUE
;
2881 Elf_Internal_Rela outrel
;
2883 /* We need to generate a R_X86_64_RELATIVE reloc
2884 for the dynamic linker. */
2885 s
= htab
->elf
.srelgot
;
2889 outrel
.r_offset
= (base_got
->output_section
->vma
2890 + base_got
->output_offset
2892 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
2893 outrel
.r_addend
= relocation
;
2894 elf_append_rela (output_bfd
, s
, &outrel
);
2897 if (off
>= (bfd_vma
) -2)
2900 relocation
= base_got
->output_section
->vma
2901 + base_got
->output_offset
+ off
;
2902 if (r_type
!= R_X86_64_GOTPCREL
2903 && r_type
!= R_X86_64_GOTPCRELX
2904 && r_type
!= R_X86_64_REX_GOTPCRELX
2905 && r_type
!= R_X86_64_GOTPCREL64
)
2906 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2907 - htab
->elf
.sgotplt
->output_offset
;
2911 case R_X86_64_GOTOFF64
:
2912 /* Relocation is relative to the start of the global offset
2915 /* Check to make sure it isn't a protected function or data
2916 symbol for shared library since it may not be local when
2917 used as function address or with copy relocation. We also
2918 need to make sure that a symbol is referenced locally. */
2919 if (bfd_link_pic (info
) && h
)
2921 if (!h
->def_regular
)
2925 switch (ELF_ST_VISIBILITY (h
->other
))
2928 v
= _("hidden symbol");
2931 v
= _("internal symbol");
2934 v
= _("protected symbol");
2942 /* xgettext:c-format */
2943 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
2944 " `%s' can not be used when making a shared object"),
2945 input_bfd
, v
, h
->root
.root
.string
);
2946 bfd_set_error (bfd_error_bad_value
);
2949 else if (!bfd_link_executable (info
)
2950 && !SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2951 && (h
->type
== STT_FUNC
2952 || h
->type
== STT_OBJECT
)
2953 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2956 /* xgettext:c-format */
2957 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
2958 " `%s' can not be used when making a shared object"),
2960 h
->type
== STT_FUNC
? "function" : "data",
2961 h
->root
.root
.string
);
2962 bfd_set_error (bfd_error_bad_value
);
2967 /* Note that sgot is not involved in this
2968 calculation. We always want the start of .got.plt. If we
2969 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2970 permitted by the ABI, we might have to change this
2972 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2973 + htab
->elf
.sgotplt
->output_offset
;
2976 case R_X86_64_GOTPC32
:
2977 case R_X86_64_GOTPC64
:
2978 /* Use global offset table as symbol value. */
2979 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2980 + htab
->elf
.sgotplt
->output_offset
;
2981 unresolved_reloc
= FALSE
;
2984 case R_X86_64_PLTOFF64
:
2985 /* Relocation is PLT entry relative to GOT. For local
2986 symbols it's the symbol itself relative to GOT. */
2988 /* See PLT32 handling. */
2989 && (h
->plt
.offset
!= (bfd_vma
) -1
2990 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
2991 && htab
->elf
.splt
!= NULL
)
2993 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
2995 /* Use the GOT PLT. */
2996 resolved_plt
= htab
->plt_got
;
2997 plt_offset
= eh
->plt_got
.offset
;
2999 else if (htab
->plt_second
!= NULL
)
3001 resolved_plt
= htab
->plt_second
;
3002 plt_offset
= eh
->plt_second
.offset
;
3006 resolved_plt
= htab
->elf
.splt
;
3007 plt_offset
= h
->plt
.offset
;
3010 relocation
= (resolved_plt
->output_section
->vma
3011 + resolved_plt
->output_offset
3013 unresolved_reloc
= FALSE
;
3016 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3017 + htab
->elf
.sgotplt
->output_offset
;
3020 case R_X86_64_PLT32
:
3021 case R_X86_64_PLT32_BND
:
3022 /* Relocation is to the entry for this symbol in the
3023 procedure linkage table. */
3025 /* Resolve a PLT32 reloc against a local symbol directly,
3026 without using the procedure linkage table. */
3030 if ((h
->plt
.offset
== (bfd_vma
) -1
3031 && eh
->plt_got
.offset
== (bfd_vma
) -1)
3032 || htab
->elf
.splt
== NULL
)
3034 /* We didn't make a PLT entry for this symbol. This
3035 happens when statically linking PIC code, or when
3036 using -Bsymbolic. */
3040 if (h
->plt
.offset
!= (bfd_vma
) -1)
3042 if (htab
->plt_second
!= NULL
)
3044 resolved_plt
= htab
->plt_second
;
3045 plt_offset
= eh
->plt_second
.offset
;
3049 resolved_plt
= htab
->elf
.splt
;
3050 plt_offset
= h
->plt
.offset
;
3055 /* Use the GOT PLT. */
3056 resolved_plt
= htab
->plt_got
;
3057 plt_offset
= eh
->plt_got
.offset
;
3060 relocation
= (resolved_plt
->output_section
->vma
3061 + resolved_plt
->output_offset
3063 unresolved_reloc
= FALSE
;
3066 case R_X86_64_SIZE32
:
3067 case R_X86_64_SIZE64
:
3068 /* Set to symbol size. */
3069 relocation
= st_size
;
3075 case R_X86_64_PC32_BND
:
3076 /* Don't complain about -fPIC if the symbol is undefined when
3077 building executable unless it is unresolved weak symbol or
3078 -z nocopyreloc is used. */
3079 if ((input_section
->flags
& SEC_ALLOC
) != 0
3080 && (input_section
->flags
& SEC_READONLY
) != 0
3082 && ((bfd_link_executable (info
)
3083 && ((h
->root
.type
== bfd_link_hash_undefweak
3084 && !resolved_to_zero
)
3085 || ((info
->nocopyreloc
3086 || (eh
->def_protected
3087 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
3089 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
3090 || bfd_link_dll (info
)))
3092 bfd_boolean fail
= FALSE
;
3094 = ((r_type
== R_X86_64_PC32
3095 || r_type
== R_X86_64_PC32_BND
)
3096 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3098 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3100 /* Symbol is referenced locally. Make sure it is
3101 defined locally or for a branch. */
3102 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
3105 else if (!(bfd_link_pie (info
)
3106 && (h
->needs_copy
|| eh
->needs_copy
)))
3108 /* Symbol doesn't need copy reloc and isn't referenced
3109 locally. We only allow branch to symbol with
3110 non-default visibility. */
3112 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3116 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3117 h
, NULL
, NULL
, howto
);
3126 /* FIXME: The ABI says the linker should make sure the value is
3127 the same when it's zeroextended to 64 bit. */
3130 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3133 /* Don't copy a pc-relative relocation into the output file
3134 if the symbol needs copy reloc or the symbol is undefined
3135 when building executable. Copy dynamic function pointer
3136 relocations. Don't generate dynamic relocations against
3137 resolved undefined weak symbols in PIE. */
3138 if ((bfd_link_pic (info
)
3139 && !(bfd_link_pie (info
)
3143 || h
->root
.type
== bfd_link_hash_undefined
)
3144 && (IS_X86_64_PCREL_TYPE (r_type
)
3145 || r_type
== R_X86_64_SIZE32
3146 || r_type
== R_X86_64_SIZE64
))
3148 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3149 && !resolved_to_zero
)
3150 || h
->root
.type
!= bfd_link_hash_undefweak
))
3151 && ((! IS_X86_64_PCREL_TYPE (r_type
)
3152 && r_type
!= R_X86_64_SIZE32
3153 && r_type
!= R_X86_64_SIZE64
)
3154 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3155 || (ELIMINATE_COPY_RELOCS
3156 && !bfd_link_pic (info
)
3160 || eh
->func_pointer_refcount
> 0
3161 || (h
->root
.type
== bfd_link_hash_undefweak
3162 && !resolved_to_zero
))
3163 && ((h
->def_dynamic
&& !h
->def_regular
)
3164 /* Undefined weak symbol is bound locally when
3166 || h
->root
.type
== bfd_link_hash_undefined
)))
3168 Elf_Internal_Rela outrel
;
3169 bfd_boolean skip
, relocate
;
3172 /* When generating a shared object, these relocations
3173 are copied into the output file to be resolved at run
3179 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3181 if (outrel
.r_offset
== (bfd_vma
) -1)
3183 else if (outrel
.r_offset
== (bfd_vma
) -2)
3184 skip
= TRUE
, relocate
= TRUE
;
3186 outrel
.r_offset
+= (input_section
->output_section
->vma
3187 + input_section
->output_offset
);
3190 memset (&outrel
, 0, sizeof outrel
);
3192 /* h->dynindx may be -1 if this symbol was marked to
3196 && (IS_X86_64_PCREL_TYPE (r_type
)
3197 || !(bfd_link_executable (info
)
3198 || SYMBOLIC_BIND (info
, h
))
3199 || ! h
->def_regular
))
3201 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3202 outrel
.r_addend
= rel
->r_addend
;
3206 /* This symbol is local, or marked to become local.
3207 When relocation overflow check is disabled, we
3208 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3209 if (r_type
== htab
->pointer_r_type
3210 || (r_type
== R_X86_64_32
3211 && info
->no_reloc_overflow_check
))
3214 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3215 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3217 else if (r_type
== R_X86_64_64
3218 && !ABI_64_P (output_bfd
))
3221 outrel
.r_info
= htab
->r_info (0,
3222 R_X86_64_RELATIVE64
);
3223 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3224 /* Check addend overflow. */
3225 if ((outrel
.r_addend
& 0x80000000)
3226 != (rel
->r_addend
& 0x80000000))
3229 int addend
= rel
->r_addend
;
3230 if (h
&& h
->root
.root
.string
)
3231 name
= h
->root
.root
.string
;
3233 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3236 /* xgettext:c-format */
3237 (_("%B: addend %s%#x in relocation %s against "
3238 "symbol `%s' at %#Lx in section `%A' is "
3240 input_bfd
, addend
< 0 ? "-" : "", addend
,
3241 howto
->name
, name
, rel
->r_offset
, input_section
);
3242 bfd_set_error (bfd_error_bad_value
);
3250 if (bfd_is_abs_section (sec
))
3252 else if (sec
== NULL
|| sec
->owner
== NULL
)
3254 bfd_set_error (bfd_error_bad_value
);
3261 /* We are turning this relocation into one
3262 against a section symbol. It would be
3263 proper to subtract the symbol's value,
3264 osec->vma, from the emitted reloc addend,
3265 but ld.so expects buggy relocs. */
3266 osec
= sec
->output_section
;
3267 sindx
= elf_section_data (osec
)->dynindx
;
3270 asection
*oi
= htab
->elf
.text_index_section
;
3271 sindx
= elf_section_data (oi
)->dynindx
;
3273 BFD_ASSERT (sindx
!= 0);
3276 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3277 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3281 sreloc
= elf_section_data (input_section
)->sreloc
;
3283 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3285 r
= bfd_reloc_notsupported
;
3286 goto check_relocation_error
;
3289 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3291 /* If this reloc is against an external symbol, we do
3292 not want to fiddle with the addend. Otherwise, we
3293 need to include the symbol value so that it becomes
3294 an addend for the dynamic reloc. */
3301 case R_X86_64_TLSGD
:
3302 case R_X86_64_GOTPC32_TLSDESC
:
3303 case R_X86_64_TLSDESC_CALL
:
3304 case R_X86_64_GOTTPOFF
:
3305 tls_type
= GOT_UNKNOWN
;
3306 if (h
== NULL
&& local_got_offsets
)
3307 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3309 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
3311 r_type_tls
= r_type
;
3312 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3313 input_section
, contents
,
3314 symtab_hdr
, sym_hashes
,
3315 &r_type_tls
, tls_type
, rel
,
3316 relend
, h
, r_symndx
, TRUE
))
3319 if (r_type_tls
== R_X86_64_TPOFF32
)
3321 bfd_vma roff
= rel
->r_offset
;
3323 BFD_ASSERT (! unresolved_reloc
);
3325 if (r_type
== R_X86_64_TLSGD
)
3327 /* GD->LE transition. For 64bit, change
3328 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3329 .word 0x6666; rex64; call __tls_get_addr@PLT
3331 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3333 call *__tls_get_addr@GOTPCREL(%rip)
3334 which may be converted to
3335 addr32 call __tls_get_addr
3338 leaq foo@tpoff(%rax), %rax
3340 leaq foo@tlsgd(%rip), %rdi
3341 .word 0x6666; rex64; call __tls_get_addr@PLT
3343 leaq foo@tlsgd(%rip), %rdi
3345 call *__tls_get_addr@GOTPCREL(%rip)
3346 which may be converted to
3347 addr32 call __tls_get_addr
3350 leaq foo@tpoff(%rax), %rax
3351 For largepic, change:
3352 leaq foo@tlsgd(%rip), %rdi
3353 movabsq $__tls_get_addr@pltoff, %rax
3358 leaq foo@tpoff(%rax), %rax
3359 nopw 0x0(%rax,%rax,1) */
3361 if (ABI_64_P (output_bfd
))
3363 if (contents
[roff
+ 5] == 0xb8)
3365 memcpy (contents
+ roff
- 3,
3366 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3367 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3371 memcpy (contents
+ roff
- 4,
3372 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3376 memcpy (contents
+ roff
- 3,
3377 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3379 bfd_put_32 (output_bfd
,
3380 elf_x86_64_tpoff (info
, relocation
),
3381 contents
+ roff
+ 8 + largepic
);
3382 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3383 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3388 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3390 /* GDesc -> LE transition.
3391 It's originally something like:
3392 leaq x@tlsdesc(%rip), %rax
3395 movl $x@tpoff, %rax. */
3397 unsigned int val
, type
;
3399 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3400 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3401 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3402 contents
+ roff
- 3);
3403 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3404 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3405 contents
+ roff
- 1);
3406 bfd_put_32 (output_bfd
,
3407 elf_x86_64_tpoff (info
, relocation
),
3411 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3413 /* GDesc -> LE transition.
3418 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3419 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3422 else if (r_type
== R_X86_64_GOTTPOFF
)
3424 /* IE->LE transition:
3425 For 64bit, originally it can be one of:
3426 movq foo@gottpoff(%rip), %reg
3427 addq foo@gottpoff(%rip), %reg
3430 leaq foo(%reg), %reg
3432 For 32bit, originally it can be one of:
3433 movq foo@gottpoff(%rip), %reg
3434 addl foo@gottpoff(%rip), %reg
3437 leal foo(%reg), %reg
3440 unsigned int val
, type
, reg
;
3443 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3446 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3447 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3453 bfd_put_8 (output_bfd
, 0x49,
3454 contents
+ roff
- 3);
3455 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3456 bfd_put_8 (output_bfd
, 0x41,
3457 contents
+ roff
- 3);
3458 bfd_put_8 (output_bfd
, 0xc7,
3459 contents
+ roff
- 2);
3460 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3461 contents
+ roff
- 1);
3465 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3468 bfd_put_8 (output_bfd
, 0x49,
3469 contents
+ roff
- 3);
3470 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3471 bfd_put_8 (output_bfd
, 0x41,
3472 contents
+ roff
- 3);
3473 bfd_put_8 (output_bfd
, 0x81,
3474 contents
+ roff
- 2);
3475 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3476 contents
+ roff
- 1);
3480 /* addq/addl -> leaq/leal */
3482 bfd_put_8 (output_bfd
, 0x4d,
3483 contents
+ roff
- 3);
3484 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3485 bfd_put_8 (output_bfd
, 0x45,
3486 contents
+ roff
- 3);
3487 bfd_put_8 (output_bfd
, 0x8d,
3488 contents
+ roff
- 2);
3489 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3490 contents
+ roff
- 1);
3492 bfd_put_32 (output_bfd
,
3493 elf_x86_64_tpoff (info
, relocation
),
3501 if (htab
->elf
.sgot
== NULL
)
3506 off
= h
->got
.offset
;
3507 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3511 if (local_got_offsets
== NULL
)
3514 off
= local_got_offsets
[r_symndx
];
3515 offplt
= local_tlsdesc_gotents
[r_symndx
];
3522 Elf_Internal_Rela outrel
;
3526 if (htab
->elf
.srelgot
== NULL
)
3529 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3531 if (GOT_TLS_GDESC_P (tls_type
))
3533 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3534 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3535 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3536 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3537 + htab
->elf
.sgotplt
->output_offset
3539 + htab
->sgotplt_jump_table_size
);
3540 sreloc
= htab
->elf
.srelplt
;
3542 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3544 outrel
.r_addend
= 0;
3545 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3548 sreloc
= htab
->elf
.srelgot
;
3550 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3551 + htab
->elf
.sgot
->output_offset
+ off
);
3553 if (GOT_TLS_GD_P (tls_type
))
3554 dr_type
= R_X86_64_DTPMOD64
;
3555 else if (GOT_TLS_GDESC_P (tls_type
))
3558 dr_type
= R_X86_64_TPOFF64
;
3560 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3561 outrel
.r_addend
= 0;
3562 if ((dr_type
== R_X86_64_TPOFF64
3563 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3564 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3565 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3567 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3569 if (GOT_TLS_GD_P (tls_type
))
3573 BFD_ASSERT (! unresolved_reloc
);
3574 bfd_put_64 (output_bfd
,
3575 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3576 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3580 bfd_put_64 (output_bfd
, 0,
3581 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3582 outrel
.r_info
= htab
->r_info (indx
,
3584 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3585 elf_append_rela (output_bfd
, sreloc
,
3594 local_got_offsets
[r_symndx
] |= 1;
3597 if (off
>= (bfd_vma
) -2
3598 && ! GOT_TLS_GDESC_P (tls_type
))
3600 if (r_type_tls
== r_type
)
3602 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3603 || r_type
== R_X86_64_TLSDESC_CALL
)
3604 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3605 + htab
->elf
.sgotplt
->output_offset
3606 + offplt
+ htab
->sgotplt_jump_table_size
;
3608 relocation
= htab
->elf
.sgot
->output_section
->vma
3609 + htab
->elf
.sgot
->output_offset
+ off
;
3610 unresolved_reloc
= FALSE
;
3614 bfd_vma roff
= rel
->r_offset
;
3616 if (r_type
== R_X86_64_TLSGD
)
3618 /* GD->IE transition. For 64bit, change
3619 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3620 .word 0x6666; rex64; call __tls_get_addr@PLT
3622 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3624 call *__tls_get_addr@GOTPCREL(%rip
3625 which may be converted to
3626 addr32 call __tls_get_addr
3629 addq foo@gottpoff(%rip), %rax
3631 leaq foo@tlsgd(%rip), %rdi
3632 .word 0x6666; rex64; call __tls_get_addr@PLT
3634 leaq foo@tlsgd(%rip), %rdi
3636 call *__tls_get_addr@GOTPCREL(%rip)
3637 which may be converted to
3638 addr32 call __tls_get_addr
3641 addq foo@gottpoff(%rip), %rax
3642 For largepic, change:
3643 leaq foo@tlsgd(%rip), %rdi
3644 movabsq $__tls_get_addr@pltoff, %rax
3649 addq foo@gottpoff(%rax), %rax
3650 nopw 0x0(%rax,%rax,1) */
3652 if (ABI_64_P (output_bfd
))
3654 if (contents
[roff
+ 5] == 0xb8)
3656 memcpy (contents
+ roff
- 3,
3657 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3658 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3662 memcpy (contents
+ roff
- 4,
3663 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3667 memcpy (contents
+ roff
- 3,
3668 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3671 relocation
= (htab
->elf
.sgot
->output_section
->vma
3672 + htab
->elf
.sgot
->output_offset
+ off
3675 - input_section
->output_section
->vma
3676 - input_section
->output_offset
3678 bfd_put_32 (output_bfd
, relocation
,
3679 contents
+ roff
+ 8 + largepic
);
3680 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3685 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3687 /* GDesc -> IE transition.
3688 It's originally something like:
3689 leaq x@tlsdesc(%rip), %rax
3692 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3694 /* Now modify the instruction as appropriate. To
3695 turn a leaq into a movq in the form we use it, it
3696 suffices to change the second byte from 0x8d to
3698 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3700 bfd_put_32 (output_bfd
,
3701 htab
->elf
.sgot
->output_section
->vma
3702 + htab
->elf
.sgot
->output_offset
+ off
3704 - input_section
->output_section
->vma
3705 - input_section
->output_offset
3710 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3712 /* GDesc -> IE transition.
3719 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3720 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3728 case R_X86_64_TLSLD
:
3729 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3730 input_section
, contents
,
3731 symtab_hdr
, sym_hashes
,
3732 &r_type
, GOT_UNKNOWN
, rel
,
3733 relend
, h
, r_symndx
, TRUE
))
3736 if (r_type
!= R_X86_64_TLSLD
)
3738 /* LD->LE transition:
3739 leaq foo@tlsld(%rip), %rdi
3740 call __tls_get_addr@PLT
3741 For 64bit, we change it into:
3742 .word 0x6666; .byte 0x66; movq %fs:0, %rax
3743 For 32bit, we change it into:
3744 nopl 0x0(%rax); movl %fs:0, %eax
3746 leaq foo@tlsld(%rip), %rdi;
3747 call *__tls_get_addr@GOTPCREL(%rip)
3748 which may be converted to
3749 addr32 call __tls_get_addr
3750 For 64bit, we change it into:
3751 .word 0x6666; .word 0x6666; movq %fs:0, %rax
3752 For 32bit, we change it into:
3753 nopw 0x0(%rax); movl %fs:0, %eax
3754 For largepic, change:
3755 leaq foo@tlsgd(%rip), %rdi
3756 movabsq $__tls_get_addr@pltoff, %rax
3760 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
3763 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3764 if (ABI_64_P (output_bfd
))
3766 if (contents
[rel
->r_offset
+ 5] == 0xb8)
3767 memcpy (contents
+ rel
->r_offset
- 3,
3768 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
3769 "\x64\x48\x8b\x04\x25\0\0\0", 22);
3770 else if (contents
[rel
->r_offset
+ 4] == 0xff
3771 || contents
[rel
->r_offset
+ 4] == 0x67)
3772 memcpy (contents
+ rel
->r_offset
- 3,
3773 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
3776 memcpy (contents
+ rel
->r_offset
- 3,
3777 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3781 if (contents
[rel
->r_offset
+ 4] == 0xff)
3782 memcpy (contents
+ rel
->r_offset
- 3,
3783 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
3786 memcpy (contents
+ rel
->r_offset
- 3,
3787 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3789 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
3790 and R_X86_64_PLTOFF64. */
3796 if (htab
->elf
.sgot
== NULL
)
3799 off
= htab
->tls_ld_or_ldm_got
.offset
;
3804 Elf_Internal_Rela outrel
;
3806 if (htab
->elf
.srelgot
== NULL
)
3809 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3810 + htab
->elf
.sgot
->output_offset
+ off
);
3812 bfd_put_64 (output_bfd
, 0,
3813 htab
->elf
.sgot
->contents
+ off
);
3814 bfd_put_64 (output_bfd
, 0,
3815 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3816 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
3817 outrel
.r_addend
= 0;
3818 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
3820 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3822 relocation
= htab
->elf
.sgot
->output_section
->vma
3823 + htab
->elf
.sgot
->output_offset
+ off
;
3824 unresolved_reloc
= FALSE
;
3827 case R_X86_64_DTPOFF32
:
3828 if (!bfd_link_executable (info
)
3829 || (input_section
->flags
& SEC_CODE
) == 0)
3830 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3832 relocation
= elf_x86_64_tpoff (info
, relocation
);
3835 case R_X86_64_TPOFF32
:
3836 case R_X86_64_TPOFF64
:
3837 BFD_ASSERT (bfd_link_executable (info
));
3838 relocation
= elf_x86_64_tpoff (info
, relocation
);
3841 case R_X86_64_DTPOFF64
:
3842 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
3843 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3850 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3851 because such sections are not SEC_ALLOC and thus ld.so will
3852 not process them. */
3853 if (unresolved_reloc
3854 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3856 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3857 rel
->r_offset
) != (bfd_vma
) -1)
3862 sec
= h
->root
.u
.def
.section
;
3863 if ((info
->nocopyreloc
3864 || (eh
->def_protected
3865 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
3866 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
3867 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3868 h
, NULL
, NULL
, howto
);
3873 /* xgettext:c-format */
3874 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3879 h
->root
.root
.string
);
3885 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3886 contents
, rel
->r_offset
,
3887 relocation
, rel
->r_addend
);
3889 check_relocation_error
:
3890 if (r
!= bfd_reloc_ok
)
3895 name
= h
->root
.root
.string
;
3898 name
= bfd_elf_string_from_elf_section (input_bfd
,
3899 symtab_hdr
->sh_link
,
3904 name
= bfd_section_name (input_bfd
, sec
);
3907 if (r
== bfd_reloc_overflow
)
3909 if (converted_reloc
)
3911 info
->callbacks
->einfo
3912 (_("%F%P: failed to convert GOTPCREL relocation; relink with --no-relax\n"));
3915 (*info
->callbacks
->reloc_overflow
)
3916 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3917 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3922 /* xgettext:c-format */
3923 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
3924 input_bfd
, input_section
,
3925 rel
->r_offset
, name
, (int) r
);
3936 Elf_Internal_Shdr
*rel_hdr
;
3937 size_t deleted
= rel
- wrel
;
3939 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3940 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3941 if (rel_hdr
->sh_size
== 0)
3943 /* It is too late to remove an empty reloc section. Leave
3945 ??? What is wrong with an empty section??? */
3946 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3949 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3950 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3951 input_section
->reloc_count
-= deleted
;
3957 /* Finish up dynamic symbol handling. We set the contents of various
3958 dynamic sections here. */
3961 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3962 struct bfd_link_info
*info
,
3963 struct elf_link_hash_entry
*h
,
3964 Elf_Internal_Sym
*sym
)
3966 struct elf_x86_link_hash_table
*htab
;
3967 bfd_boolean use_plt_second
;
3968 struct elf_x86_link_hash_entry
*eh
;
3969 bfd_boolean local_undefweak
;
3971 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
3975 /* Use the second PLT section only if there is .plt section. */
3976 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3978 eh
= (struct elf_x86_link_hash_entry
*) h
;
3979 if (eh
->no_finish_dynamic_symbol
)
3982 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3983 resolved undefined weak symbols in executable so that their
3984 references have value 0 at run-time. */
3985 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3987 if (h
->plt
.offset
!= (bfd_vma
) -1)
3990 bfd_vma got_offset
, plt_offset
;
3991 Elf_Internal_Rela rela
;
3993 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
3994 const struct elf_backend_data
*bed
;
3995 bfd_vma plt_got_pcrel_offset
;
3997 /* When building a static executable, use .iplt, .igot.plt and
3998 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3999 if (htab
->elf
.splt
!= NULL
)
4001 plt
= htab
->elf
.splt
;
4002 gotplt
= htab
->elf
.sgotplt
;
4003 relplt
= htab
->elf
.srelplt
;
4007 plt
= htab
->elf
.iplt
;
4008 gotplt
= htab
->elf
.igotplt
;
4009 relplt
= htab
->elf
.irelplt
;
4012 /* This symbol has an entry in the procedure linkage table. Set
4014 if ((h
->dynindx
== -1
4016 && !((h
->forced_local
|| bfd_link_executable (info
))
4018 && h
->type
== STT_GNU_IFUNC
))
4024 /* Get the index in the procedure linkage table which
4025 corresponds to this symbol. This is the index of this symbol
4026 in all the symbols for which we are making plt entries. The
4027 first entry in the procedure linkage table is reserved.
4029 Get the offset into the .got table of the entry that
4030 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4031 bytes. The first three are reserved for the dynamic linker.
4033 For static executables, we don't reserve anything. */
4035 if (plt
== htab
->elf
.splt
)
4037 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
4038 - htab
->plt
.has_plt0
);
4039 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4043 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
4044 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4047 /* Fill in the entry in the procedure linkage table. */
4048 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
4049 htab
->plt
.plt_entry_size
);
4052 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
4053 htab
->non_lazy_plt
->plt_entry
,
4054 htab
->non_lazy_plt
->plt_entry_size
);
4056 resolved_plt
= htab
->plt_second
;
4057 plt_offset
= eh
->plt_second
.offset
;
4062 plt_offset
= h
->plt
.offset
;
4065 /* Insert the relocation positions of the plt section. */
4067 /* Put offset the PC-relative instruction referring to the GOT entry,
4068 subtracting the size of that instruction. */
4069 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
4070 + gotplt
->output_offset
4072 - resolved_plt
->output_section
->vma
4073 - resolved_plt
->output_offset
4075 - htab
->plt
.plt_got_insn_size
);
4077 /* Check PC-relative offset overflow in PLT entry. */
4078 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
4079 /* xgettext:c-format */
4080 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
4081 output_bfd
, h
->root
.root
.string
);
4083 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
4084 (resolved_plt
->contents
+ plt_offset
4085 + htab
->plt
.plt_got_offset
));
4087 /* Fill in the entry in the global offset table, initially this
4088 points to the second part of the PLT entry. Leave the entry
4089 as zero for undefined weak symbol in PIE. No PLT relocation
4090 against undefined weak symbol in PIE. */
4091 if (!local_undefweak
)
4093 if (htab
->plt
.has_plt0
)
4094 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4095 + plt
->output_offset
4097 + htab
->lazy_plt
->plt_lazy_offset
),
4098 gotplt
->contents
+ got_offset
);
4100 /* Fill in the entry in the .rela.plt section. */
4101 rela
.r_offset
= (gotplt
->output_section
->vma
4102 + gotplt
->output_offset
4104 if (h
->dynindx
== -1
4105 || ((bfd_link_executable (info
)
4106 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4108 && h
->type
== STT_GNU_IFUNC
))
4110 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4111 h
->root
.root
.string
,
4112 h
->root
.u
.def
.section
->owner
);
4114 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4115 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4116 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4117 rela
.r_addend
= (h
->root
.u
.def
.value
4118 + h
->root
.u
.def
.section
->output_section
->vma
4119 + h
->root
.u
.def
.section
->output_offset
);
4120 /* R_X86_64_IRELATIVE comes last. */
4121 plt_index
= htab
->next_irelative_index
--;
4125 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4127 plt_index
= htab
->next_jump_slot_index
++;
4130 /* Don't fill the second and third slots in PLT entry for
4131 static executables nor without PLT0. */
4132 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4135 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
4137 /* Put relocation index. */
4138 bfd_put_32 (output_bfd
, plt_index
,
4139 (plt
->contents
+ h
->plt
.offset
4140 + htab
->lazy_plt
->plt_reloc_offset
));
4142 /* Put offset for jmp .PLT0 and check for overflow. We don't
4143 check relocation index for overflow since branch displacement
4144 will overflow first. */
4145 if (plt0_offset
> 0x80000000)
4146 /* xgettext:c-format */
4147 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
4148 output_bfd
, h
->root
.root
.string
);
4149 bfd_put_32 (output_bfd
, - plt0_offset
,
4150 (plt
->contents
+ h
->plt
.offset
4151 + htab
->lazy_plt
->plt_plt_offset
));
4154 bed
= get_elf_backend_data (output_bfd
);
4155 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4156 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4159 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4161 bfd_vma got_offset
, plt_offset
;
4162 asection
*plt
, *got
;
4163 bfd_boolean got_after_plt
;
4164 int32_t got_pcrel_offset
;
4166 /* Set the entry in the GOT procedure linkage table. */
4167 plt
= htab
->plt_got
;
4168 got
= htab
->elf
.sgot
;
4169 got_offset
= h
->got
.offset
;
4171 if (got_offset
== (bfd_vma
) -1
4172 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
4177 /* Use the non-lazy PLT entry template for the GOT PLT since they
4178 are the identical. */
4179 /* Fill in the entry in the GOT procedure linkage table. */
4180 plt_offset
= eh
->plt_got
.offset
;
4181 memcpy (plt
->contents
+ plt_offset
,
4182 htab
->non_lazy_plt
->plt_entry
,
4183 htab
->non_lazy_plt
->plt_entry_size
);
4185 /* Put offset the PC-relative instruction referring to the GOT
4186 entry, subtracting the size of that instruction. */
4187 got_pcrel_offset
= (got
->output_section
->vma
4188 + got
->output_offset
4190 - plt
->output_section
->vma
4191 - plt
->output_offset
4193 - htab
->non_lazy_plt
->plt_got_insn_size
);
4195 /* Check PC-relative offset overflow in GOT PLT entry. */
4196 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
4197 if ((got_after_plt
&& got_pcrel_offset
< 0)
4198 || (!got_after_plt
&& got_pcrel_offset
> 0))
4199 /* xgettext:c-format */
4200 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4201 output_bfd
, h
->root
.root
.string
);
4203 bfd_put_32 (output_bfd
, got_pcrel_offset
,
4204 (plt
->contents
+ plt_offset
4205 + htab
->non_lazy_plt
->plt_got_offset
));
4208 if (!local_undefweak
4210 && (h
->plt
.offset
!= (bfd_vma
) -1
4211 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4213 /* Mark the symbol as undefined, rather than as defined in
4214 the .plt section. Leave the value if there were any
4215 relocations where pointer equality matters (this is a clue
4216 for the dynamic linker, to make function pointer
4217 comparisons work between an application and shared
4218 library), otherwise set it to zero. If a function is only
4219 called from a binary, there is no need to slow down
4220 shared libraries because of that. */
4221 sym
->st_shndx
= SHN_UNDEF
;
4222 if (!h
->pointer_equality_needed
)
4226 /* Don't generate dynamic GOT relocation against undefined weak
4227 symbol in executable. */
4228 if (h
->got
.offset
!= (bfd_vma
) -1
4229 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
4230 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
4231 && !local_undefweak
)
4233 Elf_Internal_Rela rela
;
4234 asection
*relgot
= htab
->elf
.srelgot
;
4236 /* This symbol has an entry in the global offset table. Set it
4238 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4241 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4242 + htab
->elf
.sgot
->output_offset
4243 + (h
->got
.offset
&~ (bfd_vma
) 1));
4245 /* If this is a static link, or it is a -Bsymbolic link and the
4246 symbol is defined locally or was forced to be local because
4247 of a version file, we just want to emit a RELATIVE reloc.
4248 The entry in the global offset table will already have been
4249 initialized in the relocate_section function. */
4251 && h
->type
== STT_GNU_IFUNC
)
4253 if (h
->plt
.offset
== (bfd_vma
) -1)
4255 /* STT_GNU_IFUNC is referenced without PLT. */
4256 if (htab
->elf
.splt
== NULL
)
4258 /* use .rel[a].iplt section to store .got relocations
4259 in static executable. */
4260 relgot
= htab
->elf
.irelplt
;
4262 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4264 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4266 h
->root
.root
.string
,
4267 h
->root
.u
.def
.section
->owner
);
4269 rela
.r_info
= htab
->r_info (0,
4270 R_X86_64_IRELATIVE
);
4271 rela
.r_addend
= (h
->root
.u
.def
.value
4272 + h
->root
.u
.def
.section
->output_section
->vma
4273 + h
->root
.u
.def
.section
->output_offset
);
4278 else if (bfd_link_pic (info
))
4280 /* Generate R_X86_64_GLOB_DAT. */
4288 if (!h
->pointer_equality_needed
)
4291 /* For non-shared object, we can't use .got.plt, which
4292 contains the real function addres if we need pointer
4293 equality. We load the GOT entry with the PLT entry. */
4294 if (htab
->plt_second
!= NULL
)
4296 plt
= htab
->plt_second
;
4297 plt_offset
= eh
->plt_second
.offset
;
4301 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4302 plt_offset
= h
->plt
.offset
;
4304 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4305 + plt
->output_offset
4307 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4311 else if (bfd_link_pic (info
)
4312 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4314 if (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
4316 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4317 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4318 rela
.r_addend
= (h
->root
.u
.def
.value
4319 + h
->root
.u
.def
.section
->output_section
->vma
4320 + h
->root
.u
.def
.section
->output_offset
);
4324 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4326 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4327 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4328 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4332 elf_append_rela (output_bfd
, relgot
, &rela
);
4337 Elf_Internal_Rela rela
;
4340 /* This symbol needs a copy reloc. Set it up. */
4342 if (h
->dynindx
== -1
4343 || (h
->root
.type
!= bfd_link_hash_defined
4344 && h
->root
.type
!= bfd_link_hash_defweak
)
4345 || htab
->elf
.srelbss
== NULL
4346 || htab
->elf
.sreldynrelro
== NULL
)
4349 rela
.r_offset
= (h
->root
.u
.def
.value
4350 + h
->root
.u
.def
.section
->output_section
->vma
4351 + h
->root
.u
.def
.section
->output_offset
);
4352 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4354 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4355 s
= htab
->elf
.sreldynrelro
;
4357 s
= htab
->elf
.srelbss
;
4358 elf_append_rela (output_bfd
, s
, &rela
);
4364 /* Finish up local dynamic symbol handling. We set the contents of
4365 various dynamic sections here. */
4368 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4370 struct elf_link_hash_entry
*h
4371 = (struct elf_link_hash_entry
*) *slot
;
4372 struct bfd_link_info
*info
4373 = (struct bfd_link_info
*) inf
;
4375 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4379 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4380 here since undefined weak symbol may not be dynamic and may not be
4381 called for elf_x86_64_finish_dynamic_symbol. */
4384 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4387 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4388 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4390 if (h
->root
.type
!= bfd_link_hash_undefweak
4391 || h
->dynindx
!= -1)
4394 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4398 /* Used to decide how to sort relocs in an optimal manner for the
4399 dynamic linker, before writing them out. */
4401 static enum elf_reloc_type_class
4402 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
4403 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4404 const Elf_Internal_Rela
*rela
)
4406 bfd
*abfd
= info
->output_bfd
;
4407 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4408 struct elf_x86_link_hash_table
*htab
4409 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4411 if (htab
->elf
.dynsym
!= NULL
4412 && htab
->elf
.dynsym
->contents
!= NULL
)
4414 /* Check relocation against STT_GNU_IFUNC symbol if there are
4416 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
4417 if (r_symndx
!= STN_UNDEF
)
4419 Elf_Internal_Sym sym
;
4420 if (!bed
->s
->swap_symbol_in (abfd
,
4421 (htab
->elf
.dynsym
->contents
4422 + r_symndx
* bed
->s
->sizeof_sym
),
4426 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4427 return reloc_class_ifunc
;
4431 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4433 case R_X86_64_IRELATIVE
:
4434 return reloc_class_ifunc
;
4435 case R_X86_64_RELATIVE
:
4436 case R_X86_64_RELATIVE64
:
4437 return reloc_class_relative
;
4438 case R_X86_64_JUMP_SLOT
:
4439 return reloc_class_plt
;
4441 return reloc_class_copy
;
4443 return reloc_class_normal
;
4447 /* Finish up the dynamic sections. */
4450 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4451 struct bfd_link_info
*info
)
4453 struct elf_x86_link_hash_table
*htab
;
4457 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4461 dynobj
= htab
->elf
.dynobj
;
4462 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4464 if (htab
->elf
.dynamic_sections_created
)
4466 bfd_byte
*dyncon
, *dynconend
;
4467 const struct elf_backend_data
*bed
;
4468 bfd_size_type sizeof_dyn
;
4470 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4473 bed
= get_elf_backend_data (dynobj
);
4474 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4475 dyncon
= sdyn
->contents
;
4476 dynconend
= sdyn
->contents
+ sdyn
->size
;
4477 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4479 Elf_Internal_Dyn dyn
;
4482 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4490 s
= htab
->elf
.sgotplt
;
4491 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4495 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4499 s
= htab
->elf
.srelplt
->output_section
;
4500 dyn
.d_un
.d_val
= s
->size
;
4503 case DT_TLSDESC_PLT
:
4505 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4506 + htab
->tlsdesc_plt
;
4509 case DT_TLSDESC_GOT
:
4511 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4512 + htab
->tlsdesc_got
;
4516 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4519 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4521 elf_section_data (htab
->elf
.splt
->output_section
)
4522 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
4524 if (htab
->plt
.has_plt0
)
4526 /* Fill in the special first entry in the procedure linkage
4528 memcpy (htab
->elf
.splt
->contents
,
4529 htab
->lazy_plt
->plt0_entry
,
4530 htab
->lazy_plt
->plt0_entry_size
);
4531 /* Add offset for pushq GOT+8(%rip), since the instruction
4532 uses 6 bytes subtract this value. */
4533 bfd_put_32 (output_bfd
,
4534 (htab
->elf
.sgotplt
->output_section
->vma
4535 + htab
->elf
.sgotplt
->output_offset
4537 - htab
->elf
.splt
->output_section
->vma
4538 - htab
->elf
.splt
->output_offset
4540 (htab
->elf
.splt
->contents
4541 + htab
->lazy_plt
->plt0_got1_offset
));
4542 /* Add offset for the PC-relative instruction accessing
4543 GOT+16, subtracting the offset to the end of that
4545 bfd_put_32 (output_bfd
,
4546 (htab
->elf
.sgotplt
->output_section
->vma
4547 + htab
->elf
.sgotplt
->output_offset
4549 - htab
->elf
.splt
->output_section
->vma
4550 - htab
->elf
.splt
->output_offset
4551 - htab
->lazy_plt
->plt0_got2_insn_end
),
4552 (htab
->elf
.splt
->contents
4553 + htab
->lazy_plt
->plt0_got2_offset
));
4555 if (htab
->tlsdesc_plt
)
4557 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4558 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4560 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4561 htab
->lazy_plt
->plt0_entry
,
4562 htab
->lazy_plt
->plt0_entry_size
);
4564 /* Add offset for pushq GOT+8(%rip), since the
4565 instruction uses 6 bytes subtract this value. */
4566 bfd_put_32 (output_bfd
,
4567 (htab
->elf
.sgotplt
->output_section
->vma
4568 + htab
->elf
.sgotplt
->output_offset
4570 - htab
->elf
.splt
->output_section
->vma
4571 - htab
->elf
.splt
->output_offset
4574 (htab
->elf
.splt
->contents
4576 + htab
->lazy_plt
->plt0_got1_offset
));
4577 /* Add offset for the PC-relative instruction accessing
4578 GOT+TDG, where TDG stands for htab->tlsdesc_got,
4579 subtracting the offset to the end of that
4581 bfd_put_32 (output_bfd
,
4582 (htab
->elf
.sgot
->output_section
->vma
4583 + htab
->elf
.sgot
->output_offset
4585 - htab
->elf
.splt
->output_section
->vma
4586 - htab
->elf
.splt
->output_offset
4588 - htab
->lazy_plt
->plt0_got2_insn_end
),
4589 (htab
->elf
.splt
->contents
4591 + htab
->lazy_plt
->plt0_got2_offset
));
4596 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
4597 elf_section_data (htab
->plt_got
->output_section
)
4598 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4600 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
4601 elf_section_data (htab
->plt_second
->output_section
)
4602 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4605 /* GOT is always created in setup_gnu_properties. But it may not be
4607 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
4609 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4612 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4616 /* Set the first entry in the global offset table to the address of
4617 the dynamic section. */
4619 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4621 bfd_put_64 (output_bfd
,
4622 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4623 htab
->elf
.sgotplt
->contents
);
4624 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4625 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4626 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4627 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4628 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4630 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
4634 /* Adjust .eh_frame for .plt section. */
4635 if (htab
->plt_eh_frame
!= NULL
4636 && htab
->plt_eh_frame
->contents
!= NULL
)
4638 if (htab
->elf
.splt
!= NULL
4639 && htab
->elf
.splt
->size
!= 0
4640 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4641 && htab
->elf
.splt
->output_section
!= NULL
4642 && htab
->plt_eh_frame
->output_section
!= NULL
)
4644 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4645 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4646 + htab
->plt_eh_frame
->output_offset
4647 + PLT_FDE_START_OFFSET
;
4648 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4649 htab
->plt_eh_frame
->contents
4650 + PLT_FDE_START_OFFSET
);
4652 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4654 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4656 htab
->plt_eh_frame
->contents
))
4661 /* Adjust .eh_frame for .plt.got section. */
4662 if (htab
->plt_got_eh_frame
!= NULL
4663 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4665 if (htab
->plt_got
!= NULL
4666 && htab
->plt_got
->size
!= 0
4667 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
4668 && htab
->plt_got
->output_section
!= NULL
4669 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
4671 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
4672 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
4673 + htab
->plt_got_eh_frame
->output_offset
4674 + PLT_FDE_START_OFFSET
;
4675 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4676 htab
->plt_got_eh_frame
->contents
4677 + PLT_FDE_START_OFFSET
);
4679 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4681 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4682 htab
->plt_got_eh_frame
,
4683 htab
->plt_got_eh_frame
->contents
))
4688 /* Adjust .eh_frame for the second PLT section. */
4689 if (htab
->plt_second_eh_frame
!= NULL
4690 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4692 if (htab
->plt_second
!= NULL
4693 && htab
->plt_second
->size
!= 0
4694 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
4695 && htab
->plt_second
->output_section
!= NULL
4696 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
4698 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
4699 bfd_vma eh_frame_start
4700 = (htab
->plt_second_eh_frame
->output_section
->vma
4701 + htab
->plt_second_eh_frame
->output_offset
4702 + PLT_FDE_START_OFFSET
);
4703 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4704 htab
->plt_second_eh_frame
->contents
4705 + PLT_FDE_START_OFFSET
);
4707 if (htab
->plt_second_eh_frame
->sec_info_type
4708 == SEC_INFO_TYPE_EH_FRAME
)
4710 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4711 htab
->plt_second_eh_frame
,
4712 htab
->plt_second_eh_frame
->contents
))
4717 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4718 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4721 /* Fill PLT entries for undefined weak symbols in PIE. */
4722 if (bfd_link_pie (info
))
4723 bfd_hash_traverse (&info
->hash
->table
,
4724 elf_x86_64_pie_finish_undefweak_symbol
,
4730 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4731 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4732 It has to be done before elf_link_sort_relocs is called so that
4733 dynamic relocations are properly sorted. */
4736 elf_x86_64_output_arch_local_syms
4737 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4738 struct bfd_link_info
*info
,
4739 void *flaginfo ATTRIBUTE_UNUSED
,
4740 int (*func
) (void *, const char *,
4743 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4745 struct elf_x86_link_hash_table
*htab
4746 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4750 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4751 htab_traverse (htab
->loc_hash_table
,
4752 elf_x86_64_finish_local_dynamic_symbol
,
4758 /* Forward declaration. */
4759 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
;
4761 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4762 dynamic relocations. */
4765 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
4766 long symcount ATTRIBUTE_UNUSED
,
4767 asymbol
**syms ATTRIBUTE_UNUSED
,
4774 bfd_byte
*plt_contents
;
4776 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4777 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4778 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
4779 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
4780 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4781 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4783 enum elf_x86_plt_type plt_type
;
4784 struct elf_x86_plt plts
[] =
4786 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4787 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4788 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4789 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4790 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4795 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4798 if (dynsymcount
<= 0)
4801 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4805 if (get_elf_x86_64_backend_data (abfd
)->os
== is_normal
)
4807 lazy_plt
= &elf_x86_64_lazy_plt
;
4808 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
4809 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
4810 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
4811 if (ABI_64_P (abfd
))
4813 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
4814 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
4818 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4819 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4824 lazy_plt
= &elf_x86_64_nacl_plt
;
4825 non_lazy_plt
= NULL
;
4826 lazy_bnd_plt
= NULL
;
4827 non_lazy_bnd_plt
= NULL
;
4828 lazy_ibt_plt
= NULL
;
4829 non_lazy_ibt_plt
= NULL
;
4833 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4835 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4836 if (plt
== NULL
|| plt
->size
== 0)
4839 /* Get the PLT section contents. */
4840 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4841 if (plt_contents
== NULL
)
4843 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4844 plt_contents
, 0, plt
->size
))
4846 free (plt_contents
);
4850 /* Check what kind of PLT it is. */
4851 plt_type
= plt_unknown
;
4852 if (plts
[j
].type
== plt_unknown
4853 && (plt
->size
>= (lazy_plt
->plt_entry_size
4854 + lazy_plt
->plt_entry_size
)))
4856 /* Match lazy PLT first. Need to check the first two
4858 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4859 lazy_plt
->plt0_got1_offset
) == 0)
4860 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
4862 plt_type
= plt_lazy
;
4863 else if (lazy_bnd_plt
!= NULL
4864 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
4865 lazy_bnd_plt
->plt0_got1_offset
) == 0)
4866 && (memcmp (plt_contents
+ 6,
4867 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
4869 plt_type
= plt_lazy
| plt_second
;
4870 /* The fist entry in the lazy IBT PLT is the same as the
4872 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
4873 lazy_ibt_plt
->plt_entry
,
4874 lazy_ibt_plt
->plt_got_offset
) == 0))
4875 lazy_plt
= lazy_ibt_plt
;
4877 lazy_plt
= lazy_bnd_plt
;
4881 if (non_lazy_plt
!= NULL
4882 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4883 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4885 /* Match non-lazy PLT. */
4886 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4887 non_lazy_plt
->plt_got_offset
) == 0)
4888 plt_type
= plt_non_lazy
;
4891 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4893 if (non_lazy_bnd_plt
!= NULL
4894 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
4895 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
4896 non_lazy_bnd_plt
->plt_got_offset
) == 0))
4898 /* Match BND PLT. */
4899 plt_type
= plt_second
;
4900 non_lazy_plt
= non_lazy_bnd_plt
;
4902 else if (non_lazy_ibt_plt
!= NULL
4903 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
4904 && (memcmp (plt_contents
,
4905 non_lazy_ibt_plt
->plt_entry
,
4906 non_lazy_ibt_plt
->plt_got_offset
) == 0))
4908 /* Match IBT PLT. */
4909 plt_type
= plt_second
;
4910 non_lazy_plt
= non_lazy_ibt_plt
;
4914 if (plt_type
== plt_unknown
)
4916 free (plt_contents
);
4921 plts
[j
].type
= plt_type
;
4923 if ((plt_type
& plt_lazy
))
4925 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4926 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
4927 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4928 /* Skip PLT0 in lazy PLT. */
4933 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4934 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
4935 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4939 /* Skip lazy PLT when the second PLT is used. */
4940 if (plt_type
== (plt_lazy
| plt_second
))
4944 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4949 plts
[j
].contents
= plt_contents
;
4952 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4953 (bfd_vma
) 0, plts
, dynsyms
,
4957 /* Handle an x86-64 specific section when reading an object file. This
4958 is called when elfcode.h finds a section with an unknown type. */
4961 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
4962 const char *name
, int shindex
)
4964 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4967 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4973 /* Hook called by the linker routine which adds symbols from an object
4974 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4978 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4979 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4980 Elf_Internal_Sym
*sym
,
4981 const char **namep ATTRIBUTE_UNUSED
,
4982 flagword
*flagsp ATTRIBUTE_UNUSED
,
4988 switch (sym
->st_shndx
)
4990 case SHN_X86_64_LCOMMON
:
4991 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4994 lcomm
= bfd_make_section_with_flags (abfd
,
4998 | SEC_LINKER_CREATED
));
5001 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
5004 *valp
= sym
->st_size
;
5012 /* Given a BFD section, try to locate the corresponding ELF section
5016 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5017 asection
*sec
, int *index_return
)
5019 if (sec
== &_bfd_elf_large_com_section
)
5021 *index_return
= SHN_X86_64_LCOMMON
;
5027 /* Process a symbol. */
5030 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5033 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5035 switch (elfsym
->internal_elf_sym
.st_shndx
)
5037 case SHN_X86_64_LCOMMON
:
5038 asym
->section
= &_bfd_elf_large_com_section
;
5039 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
5040 /* Common symbol doesn't set BSF_GLOBAL. */
5041 asym
->flags
&= ~BSF_GLOBAL
;
5047 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
5049 return (sym
->st_shndx
== SHN_COMMON
5050 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
5054 elf_x86_64_common_section_index (asection
*sec
)
5056 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5059 return SHN_X86_64_LCOMMON
;
5063 elf_x86_64_common_section (asection
*sec
)
5065 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
5066 return bfd_com_section_ptr
;
5068 return &_bfd_elf_large_com_section
;
5072 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5073 const Elf_Internal_Sym
*sym
,
5078 const asection
*oldsec
)
5080 /* A normal common symbol and a large common symbol result in a
5081 normal common symbol. We turn the large common symbol into a
5084 && h
->root
.type
== bfd_link_hash_common
5086 && bfd_is_com_section (*psec
)
5089 if (sym
->st_shndx
== SHN_COMMON
5090 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5092 h
->root
.u
.c
.p
->section
5093 = bfd_make_section_old_way (oldbfd
, "COMMON");
5094 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5096 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5097 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5098 *psec
= bfd_com_section_ptr
;
5105 elf_x86_64_additional_program_headers (bfd
*abfd
,
5106 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5111 /* Check to see if we need a large readonly segment. */
5112 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5113 if (s
&& (s
->flags
& SEC_LOAD
))
5116 /* Check to see if we need a large data segment. Since .lbss sections
5117 is placed right after the .bss section, there should be no need for
5118 a large data segment just because of .lbss. */
5119 s
= bfd_get_section_by_name (abfd
, ".ldata");
5120 if (s
&& (s
->flags
& SEC_LOAD
))
5126 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5129 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5130 const bfd_target
*output
)
5132 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5133 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5134 && _bfd_elf_relocs_compatible (input
, output
));
5137 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5138 with GNU properties if found. Otherwise, return NULL. */
5141 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
5143 struct elf_x86_init_table init_table
;
5145 if ((int) R_X86_64_standard
>= (int) R_X86_64_converted_reloc_bit
5146 || (int) R_X86_64_max
<= (int) R_X86_64_converted_reloc_bit
5147 || ((int) (R_X86_64_GNU_VTINHERIT
| R_X86_64_converted_reloc_bit
)
5148 != (int) R_X86_64_GNU_VTINHERIT
)
5149 || ((int) (R_X86_64_GNU_VTENTRY
| R_X86_64_converted_reloc_bit
)
5150 != (int) R_X86_64_GNU_VTENTRY
))
5153 init_table
.is_vxworks
= FALSE
;
5154 if (get_elf_x86_64_backend_data (info
->output_bfd
)->os
== is_normal
)
5158 init_table
.lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
5159 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
5163 init_table
.lazy_plt
= &elf_x86_64_lazy_plt
;
5164 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
5167 if (ABI_64_P (info
->output_bfd
))
5169 init_table
.lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
5170 init_table
.non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
5174 init_table
.lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
5175 init_table
.non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
5177 init_table
.normal_target
= TRUE
;
5181 init_table
.lazy_plt
= &elf_x86_64_nacl_plt
;
5182 init_table
.non_lazy_plt
= NULL
;
5183 init_table
.lazy_ibt_plt
= NULL
;
5184 init_table
.non_lazy_ibt_plt
= NULL
;
5185 init_table
.normal_target
= FALSE
;
5188 if (ABI_64_P (info
->output_bfd
))
5190 init_table
.r_info
= elf64_r_info
;
5191 init_table
.r_sym
= elf64_r_sym
;
5195 init_table
.r_info
= elf32_r_info
;
5196 init_table
.r_sym
= elf32_r_sym
;
5199 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
5202 static const struct bfd_elf_special_section
5203 elf_x86_64_special_sections
[]=
5205 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5206 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5207 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
5208 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5209 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5210 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5211 { NULL
, 0, 0, 0, 0 }
5214 #define TARGET_LITTLE_SYM x86_64_elf64_vec
5215 #define TARGET_LITTLE_NAME "elf64-x86-64"
5216 #define ELF_ARCH bfd_arch_i386
5217 #define ELF_TARGET_ID X86_64_ELF_DATA
5218 #define ELF_MACHINE_CODE EM_X86_64
5219 #define ELF_MAXPAGESIZE 0x200000
5220 #define ELF_MINPAGESIZE 0x1000
5221 #define ELF_COMMONPAGESIZE 0x1000
5223 #define elf_backend_can_gc_sections 1
5224 #define elf_backend_can_refcount 1
5225 #define elf_backend_want_got_plt 1
5226 #define elf_backend_plt_readonly 1
5227 #define elf_backend_want_plt_sym 0
5228 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5229 #define elf_backend_rela_normal 1
5230 #define elf_backend_plt_alignment 4
5231 #define elf_backend_extern_protected_data 1
5232 #define elf_backend_caches_rawsize 1
5233 #define elf_backend_dtrel_excludes_plt 1
5234 #define elf_backend_want_dynrelro 1
5236 #define elf_info_to_howto elf_x86_64_info_to_howto
5238 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5239 #define bfd_elf64_bfd_reloc_name_lookup \
5240 elf_x86_64_reloc_name_lookup
5242 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5243 #define elf_backend_check_relocs elf_x86_64_check_relocs
5244 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5245 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5246 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5247 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
5248 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5249 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5251 #define elf_backend_write_core_note elf_x86_64_write_core_note
5253 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5254 #define elf_backend_relocate_section elf_x86_64_relocate_section
5255 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5256 #define elf_backend_object_p elf64_x86_64_elf_object_p
5257 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5259 #define elf_backend_section_from_shdr \
5260 elf_x86_64_section_from_shdr
5262 #define elf_backend_section_from_bfd_section \
5263 elf_x86_64_elf_section_from_bfd_section
5264 #define elf_backend_add_symbol_hook \
5265 elf_x86_64_add_symbol_hook
5266 #define elf_backend_symbol_processing \
5267 elf_x86_64_symbol_processing
5268 #define elf_backend_common_section_index \
5269 elf_x86_64_common_section_index
5270 #define elf_backend_common_section \
5271 elf_x86_64_common_section
5272 #define elf_backend_common_definition \
5273 elf_x86_64_common_definition
5274 #define elf_backend_merge_symbol \
5275 elf_x86_64_merge_symbol
5276 #define elf_backend_special_sections \
5277 elf_x86_64_special_sections
5278 #define elf_backend_additional_program_headers \
5279 elf_x86_64_additional_program_headers
5280 #define elf_backend_setup_gnu_properties \
5281 elf_x86_64_link_setup_gnu_properties
5283 #include "elf64-target.h"
5285 /* CloudABI support. */
5287 #undef TARGET_LITTLE_SYM
5288 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
5289 #undef TARGET_LITTLE_NAME
5290 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
5293 #define ELF_OSABI ELFOSABI_CLOUDABI
5296 #define elf64_bed elf64_x86_64_cloudabi_bed
5298 #include "elf64-target.h"
5300 /* FreeBSD support. */
5302 #undef TARGET_LITTLE_SYM
5303 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
5304 #undef TARGET_LITTLE_NAME
5305 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5308 #define ELF_OSABI ELFOSABI_FREEBSD
5311 #define elf64_bed elf64_x86_64_fbsd_bed
5313 #include "elf64-target.h"
5315 /* Solaris 2 support. */
5317 #undef TARGET_LITTLE_SYM
5318 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
5319 #undef TARGET_LITTLE_NAME
5320 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5322 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5323 objects won't be recognized. */
5327 #define elf64_bed elf64_x86_64_sol2_bed
5329 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5331 #undef elf_backend_static_tls_alignment
5332 #define elf_backend_static_tls_alignment 16
5334 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5336 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5338 #undef elf_backend_want_plt_sym
5339 #define elf_backend_want_plt_sym 1
5341 #undef elf_backend_strtab_flags
5342 #define elf_backend_strtab_flags SHF_STRINGS
5345 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
5346 bfd
*obfd ATTRIBUTE_UNUSED
,
5347 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
5348 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
5350 /* PR 19938: FIXME: Need to add code for setting the sh_info
5351 and sh_link fields of Solaris specific section types. */
5355 #undef elf_backend_copy_special_section_fields
5356 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
5358 #include "elf64-target.h"
5360 /* Native Client support. */
5363 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
5365 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
5366 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
5370 #undef TARGET_LITTLE_SYM
5371 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
5372 #undef TARGET_LITTLE_NAME
5373 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5375 #define elf64_bed elf64_x86_64_nacl_bed
5377 #undef ELF_MAXPAGESIZE
5378 #undef ELF_MINPAGESIZE
5379 #undef ELF_COMMONPAGESIZE
5380 #define ELF_MAXPAGESIZE 0x10000
5381 #define ELF_MINPAGESIZE 0x10000
5382 #define ELF_COMMONPAGESIZE 0x10000
5384 /* Restore defaults. */
5386 #undef elf_backend_static_tls_alignment
5387 #undef elf_backend_want_plt_sym
5388 #define elf_backend_want_plt_sym 0
5389 #undef elf_backend_strtab_flags
5390 #undef elf_backend_copy_special_section_fields
5392 /* NaCl uses substantially different PLT entries for the same effects. */
5394 #undef elf_backend_plt_alignment
5395 #define elf_backend_plt_alignment 5
5396 #define NACL_PLT_ENTRY_SIZE 64
5397 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5399 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
5401 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5402 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5403 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5404 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5405 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5407 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
5408 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
5410 /* 32 bytes of nop to pad out to the standard size. */
5411 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5412 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5413 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5414 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5415 0x66, /* excess data16 prefix */
5419 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5421 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5422 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5423 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5424 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5426 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5427 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5428 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5430 /* Lazy GOT entries point here (32-byte aligned). */
5431 0x68, /* pushq immediate */
5432 0, 0, 0, 0, /* replaced with index into relocation table. */
5433 0xe9, /* jmp relative */
5434 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5436 /* 22 bytes of nop to pad out to the standard size. */
5437 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5438 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5439 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5442 /* .eh_frame covering the .plt section. */
5444 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
5446 #if (PLT_CIE_LENGTH != 20 \
5447 || PLT_FDE_LENGTH != 36 \
5448 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5449 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5450 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5452 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5453 0, 0, 0, 0, /* CIE ID */
5454 1, /* CIE version */
5455 'z', 'R', 0, /* Augmentation string */
5456 1, /* Code alignment factor */
5457 0x78, /* Data alignment factor */
5458 16, /* Return address column */
5459 1, /* Augmentation size */
5460 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5461 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5462 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5463 DW_CFA_nop
, DW_CFA_nop
,
5465 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5466 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
5467 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5468 0, 0, 0, 0, /* .plt size goes here */
5469 0, /* Augmentation size */
5470 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
5471 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5472 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
5473 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5474 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5475 13, /* Block length */
5476 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
5477 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
5478 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5479 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
5480 DW_CFA_nop
, DW_CFA_nop
5483 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
=
5485 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
5486 NACL_PLT_ENTRY_SIZE
, /* plt0_entry_size */
5487 elf_x86_64_nacl_plt_entry
, /* plt_entry */
5488 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5489 2, /* plt0_got1_offset */
5490 9, /* plt0_got2_offset */
5491 13, /* plt0_got2_insn_end */
5492 3, /* plt_got_offset */
5493 33, /* plt_reloc_offset */
5494 38, /* plt_plt_offset */
5495 7, /* plt_got_insn_size */
5496 42, /* plt_plt_insn_end */
5497 32, /* plt_lazy_offset */
5498 elf_x86_64_nacl_plt0_entry
, /* pic_plt0_entry */
5499 elf_x86_64_nacl_plt_entry
, /* pic_plt_entry */
5500 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
5501 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
5504 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
5509 #undef elf_backend_arch_data
5510 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5512 #undef elf_backend_object_p
5513 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
5514 #undef elf_backend_modify_segment_map
5515 #define elf_backend_modify_segment_map nacl_modify_segment_map
5516 #undef elf_backend_modify_program_headers
5517 #define elf_backend_modify_program_headers nacl_modify_program_headers
5518 #undef elf_backend_final_write_processing
5519 #define elf_backend_final_write_processing nacl_final_write_processing
5521 #include "elf64-target.h"
5523 /* Native Client x32 support. */
5526 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
5528 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
5529 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
5533 #undef TARGET_LITTLE_SYM
5534 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
5535 #undef TARGET_LITTLE_NAME
5536 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5538 #define elf32_bed elf32_x86_64_nacl_bed
5540 #define bfd_elf32_bfd_reloc_type_lookup \
5541 elf_x86_64_reloc_type_lookup
5542 #define bfd_elf32_bfd_reloc_name_lookup \
5543 elf_x86_64_reloc_name_lookup
5544 #define bfd_elf32_get_synthetic_symtab \
5545 elf_x86_64_get_synthetic_symtab
5547 #undef elf_backend_object_p
5548 #define elf_backend_object_p \
5549 elf32_x86_64_nacl_elf_object_p
5551 #undef elf_backend_bfd_from_remote_memory
5552 #define elf_backend_bfd_from_remote_memory \
5553 _bfd_elf32_bfd_from_remote_memory
5555 #undef elf_backend_size_info
5556 #define elf_backend_size_info \
5557 _bfd_elf32_size_info
5559 #include "elf32-target.h"
5561 /* Restore defaults. */
5562 #undef elf_backend_object_p
5563 #define elf_backend_object_p elf64_x86_64_elf_object_p
5564 #undef elf_backend_bfd_from_remote_memory
5565 #undef elf_backend_size_info
5566 #undef elf_backend_modify_segment_map
5567 #undef elf_backend_modify_program_headers
5568 #undef elf_backend_final_write_processing
5570 /* Intel L1OM support. */
5573 elf64_l1om_elf_object_p (bfd
*abfd
)
5575 /* Set the right machine number for an L1OM elf64 file. */
5576 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5580 #undef TARGET_LITTLE_SYM
5581 #define TARGET_LITTLE_SYM l1om_elf64_vec
5582 #undef TARGET_LITTLE_NAME
5583 #define TARGET_LITTLE_NAME "elf64-l1om"
5585 #define ELF_ARCH bfd_arch_l1om
5587 #undef ELF_MACHINE_CODE
5588 #define ELF_MACHINE_CODE EM_L1OM
5593 #define elf64_bed elf64_l1om_bed
5595 #undef elf_backend_object_p
5596 #define elf_backend_object_p elf64_l1om_elf_object_p
5598 /* Restore defaults. */
5599 #undef ELF_MAXPAGESIZE
5600 #undef ELF_MINPAGESIZE
5601 #undef ELF_COMMONPAGESIZE
5602 #define ELF_MAXPAGESIZE 0x200000
5603 #define ELF_MINPAGESIZE 0x1000
5604 #define ELF_COMMONPAGESIZE 0x1000
5605 #undef elf_backend_plt_alignment
5606 #define elf_backend_plt_alignment 4
5607 #undef elf_backend_arch_data
5608 #define elf_backend_arch_data &elf_x86_64_arch_bed
5610 #include "elf64-target.h"
5612 /* FreeBSD L1OM support. */
5614 #undef TARGET_LITTLE_SYM
5615 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
5616 #undef TARGET_LITTLE_NAME
5617 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5620 #define ELF_OSABI ELFOSABI_FREEBSD
5623 #define elf64_bed elf64_l1om_fbsd_bed
5625 #include "elf64-target.h"
5627 /* Intel K1OM support. */
5630 elf64_k1om_elf_object_p (bfd
*abfd
)
5632 /* Set the right machine number for an K1OM elf64 file. */
5633 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5637 #undef TARGET_LITTLE_SYM
5638 #define TARGET_LITTLE_SYM k1om_elf64_vec
5639 #undef TARGET_LITTLE_NAME
5640 #define TARGET_LITTLE_NAME "elf64-k1om"
5642 #define ELF_ARCH bfd_arch_k1om
5644 #undef ELF_MACHINE_CODE
5645 #define ELF_MACHINE_CODE EM_K1OM
5650 #define elf64_bed elf64_k1om_bed
5652 #undef elf_backend_object_p
5653 #define elf_backend_object_p elf64_k1om_elf_object_p
5655 #undef elf_backend_static_tls_alignment
5657 #undef elf_backend_want_plt_sym
5658 #define elf_backend_want_plt_sym 0
5660 #include "elf64-target.h"
5662 /* FreeBSD K1OM support. */
5664 #undef TARGET_LITTLE_SYM
5665 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
5666 #undef TARGET_LITTLE_NAME
5667 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5670 #define ELF_OSABI ELFOSABI_FREEBSD
5673 #define elf64_bed elf64_k1om_fbsd_bed
5675 #include "elf64-target.h"
5677 /* 32bit x86-64 support. */
5679 #undef TARGET_LITTLE_SYM
5680 #define TARGET_LITTLE_SYM x86_64_elf32_vec
5681 #undef TARGET_LITTLE_NAME
5682 #define TARGET_LITTLE_NAME "elf32-x86-64"
5686 #define ELF_ARCH bfd_arch_i386
5688 #undef ELF_MACHINE_CODE
5689 #define ELF_MACHINE_CODE EM_X86_64
5693 #undef elf_backend_object_p
5694 #define elf_backend_object_p \
5695 elf32_x86_64_elf_object_p
5697 #undef elf_backend_bfd_from_remote_memory
5698 #define elf_backend_bfd_from_remote_memory \
5699 _bfd_elf32_bfd_from_remote_memory
5701 #undef elf_backend_size_info
5702 #define elf_backend_size_info \
5703 _bfd_elf32_size_info
5705 #include "elf32-target.h"