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 X86_PCREL_TYPE_P(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 #define X86_SIZE_TYPE_P(TYPE) \
210 ((TYPE) == R_X86_64_SIZE32 || (TYPE) == R_X86_64_SIZE64)
212 /* Map BFD relocs to the x86_64 elf relocs. */
215 bfd_reloc_code_real_type bfd_reloc_val
;
216 unsigned char elf_reloc_val
;
219 static const struct elf_reloc_map x86_64_reloc_map
[] =
221 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
222 { BFD_RELOC_64
, R_X86_64_64
, },
223 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
224 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
225 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
226 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
227 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
228 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
229 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
230 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
231 { BFD_RELOC_32
, R_X86_64_32
, },
232 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
233 { BFD_RELOC_16
, R_X86_64_16
, },
234 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
235 { BFD_RELOC_8
, R_X86_64_8
, },
236 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
237 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
238 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
239 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
240 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
241 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
242 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
243 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
244 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
245 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
246 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
247 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
248 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
249 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
250 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
251 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
252 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
253 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
254 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
255 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
256 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
257 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
258 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
259 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
260 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
261 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
262 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
263 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
264 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
267 static reloc_howto_type
*
268 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
272 if (r_type
== (unsigned int) R_X86_64_32
)
277 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
279 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
280 || r_type
>= (unsigned int) R_X86_64_max
)
282 if (r_type
>= (unsigned int) R_X86_64_standard
)
284 /* xgettext:c-format */
285 _bfd_error_handler (_("%B: invalid relocation type %d"),
287 r_type
= R_X86_64_NONE
;
292 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
293 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
294 return &x86_64_elf_howto_table
[i
];
297 /* Given a BFD reloc type, return a HOWTO structure. */
298 static reloc_howto_type
*
299 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
300 bfd_reloc_code_real_type code
)
304 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
307 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
308 return elf_x86_64_rtype_to_howto (abfd
,
309 x86_64_reloc_map
[i
].elf_reloc_val
);
314 static reloc_howto_type
*
315 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
320 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
322 /* Get x32 R_X86_64_32. */
323 reloc_howto_type
*reloc
324 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
325 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
329 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
330 if (x86_64_elf_howto_table
[i
].name
!= NULL
331 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
332 return &x86_64_elf_howto_table
[i
];
337 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
340 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
341 Elf_Internal_Rela
*dst
)
345 r_type
= ELF32_R_TYPE (dst
->r_info
);
346 if (r_type
!= (unsigned int) R_X86_64_GNU_VTINHERIT
347 && r_type
!= (unsigned int) R_X86_64_GNU_VTENTRY
)
348 r_type
&= ~R_X86_64_converted_reloc_bit
;
349 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
351 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
|| cache_ptr
->howto
->type
== R_X86_64_NONE
);
354 /* Support for core dump NOTE sections. */
356 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
361 switch (note
->descsz
)
366 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
368 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
371 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
379 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
381 elf_tdata (abfd
)->core
->signal
382 = bfd_get_16 (abfd
, note
->descdata
+ 12);
385 elf_tdata (abfd
)->core
->lwpid
386 = bfd_get_32 (abfd
, note
->descdata
+ 32);
395 /* Make a ".reg/999" section. */
396 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
397 size
, note
->descpos
+ offset
);
401 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
403 switch (note
->descsz
)
408 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
409 elf_tdata (abfd
)->core
->pid
410 = bfd_get_32 (abfd
, note
->descdata
+ 12);
411 elf_tdata (abfd
)->core
->program
412 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
413 elf_tdata (abfd
)->core
->command
414 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
417 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
418 elf_tdata (abfd
)->core
->pid
419 = bfd_get_32 (abfd
, note
->descdata
+ 24);
420 elf_tdata (abfd
)->core
->program
421 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
422 elf_tdata (abfd
)->core
->command
423 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
426 /* Note that for some reason, a spurious space is tacked
427 onto the end of the args in some (at least one anyway)
428 implementations, so strip it off if it exists. */
431 char *command
= elf_tdata (abfd
)->core
->command
;
432 int n
= strlen (command
);
434 if (0 < n
&& command
[n
- 1] == ' ')
435 command
[n
- 1] = '\0';
443 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
446 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
448 const char *fname
, *psargs
;
459 va_start (ap
, note_type
);
460 fname
= va_arg (ap
, const char *);
461 psargs
= va_arg (ap
, const char *);
464 if (bed
->s
->elfclass
== ELFCLASS32
)
467 memset (&data
, 0, sizeof (data
));
468 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
469 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
470 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
471 &data
, sizeof (data
));
476 memset (&data
, 0, sizeof (data
));
477 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
478 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
479 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
480 &data
, sizeof (data
));
485 va_start (ap
, note_type
);
486 pid
= va_arg (ap
, long);
487 cursig
= va_arg (ap
, int);
488 gregs
= va_arg (ap
, const void *);
491 if (bed
->s
->elfclass
== ELFCLASS32
)
493 if (bed
->elf_machine_code
== EM_X86_64
)
495 prstatusx32_t prstat
;
496 memset (&prstat
, 0, sizeof (prstat
));
498 prstat
.pr_cursig
= cursig
;
499 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
500 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
501 &prstat
, sizeof (prstat
));
506 memset (&prstat
, 0, sizeof (prstat
));
508 prstat
.pr_cursig
= cursig
;
509 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
510 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
511 &prstat
, sizeof (prstat
));
517 memset (&prstat
, 0, sizeof (prstat
));
519 prstat
.pr_cursig
= cursig
;
520 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
521 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
522 &prstat
, sizeof (prstat
));
529 /* Functions for the x86-64 ELF linker. */
531 /* The size in bytes of an entry in the global offset table. */
533 #define GOT_ENTRY_SIZE 8
535 /* The size in bytes of an entry in the lazy procedure linkage table. */
537 #define LAZY_PLT_ENTRY_SIZE 16
539 /* The size in bytes of an entry in the non-lazy procedure linkage
542 #define NON_LAZY_PLT_ENTRY_SIZE 8
544 /* The first entry in a lazy procedure linkage table looks like this.
545 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
548 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
550 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
551 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
552 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
555 /* Subsequent entries in a lazy procedure linkage table look like this. */
557 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
559 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
560 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
561 0x68, /* pushq immediate */
562 0, 0, 0, 0, /* replaced with index into relocation table. */
563 0xe9, /* jmp relative */
564 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
567 /* The first entry in a lazy procedure linkage table with BND prefix
570 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
572 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
573 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
574 0x0f, 0x1f, 0 /* nopl (%rax) */
577 /* Subsequent entries for branches with BND prefx in a lazy procedure
578 linkage table look like this. */
580 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
582 0x68, 0, 0, 0, 0, /* pushq immediate */
583 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
584 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
587 /* The first entry in the IBT-enabled lazy procedure linkage table is the
588 the same as the lazy PLT with BND prefix so that bound registers are
589 preserved when control is passed to dynamic linker. Subsequent
590 entries for a IBT-enabled lazy procedure linkage table look like
593 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
595 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
596 0x68, 0, 0, 0, 0, /* pushq immediate */
597 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
601 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
602 is the same as the normal lazy PLT. Subsequent entries for an
603 x32 IBT-enabled lazy procedure linkage table look like this. */
605 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
607 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
608 0x68, 0, 0, 0, 0, /* pushq immediate */
609 0xe9, 0, 0, 0, 0, /* jmpq relative */
610 0x66, 0x90 /* xchg %ax,%ax */
613 /* Entries in the non-lazey procedure linkage table look like this. */
615 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
617 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
618 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
619 0x66, 0x90 /* xchg %ax,%ax */
622 /* Entries for branches with BND prefix in the non-lazey procedure
623 linkage table look like this. */
625 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
627 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
628 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
632 /* Entries for branches with IBT-enabled in the non-lazey procedure
633 linkage table look like this. They have the same size as the lazy
636 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
638 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
639 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
640 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
641 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
644 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
645 linkage table look like this. They have the same size as the lazy
648 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
650 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
651 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
652 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
653 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
656 /* .eh_frame covering the lazy .plt section. */
658 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
660 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
661 0, 0, 0, 0, /* CIE ID */
663 'z', 'R', 0, /* Augmentation string */
664 1, /* Code alignment factor */
665 0x78, /* Data alignment factor */
666 16, /* Return address column */
667 1, /* Augmentation size */
668 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
669 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
670 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
671 DW_CFA_nop
, DW_CFA_nop
,
673 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
674 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
675 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
676 0, 0, 0, 0, /* .plt size goes here */
677 0, /* Augmentation size */
678 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
679 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
680 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
681 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
682 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
683 11, /* Block length */
684 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
685 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
686 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
687 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
688 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
691 /* .eh_frame covering the lazy BND .plt section. */
693 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
695 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
696 0, 0, 0, 0, /* CIE ID */
698 'z', 'R', 0, /* Augmentation string */
699 1, /* Code alignment factor */
700 0x78, /* Data alignment factor */
701 16, /* Return address column */
702 1, /* Augmentation size */
703 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
704 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
705 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
706 DW_CFA_nop
, DW_CFA_nop
,
708 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
709 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
710 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
711 0, 0, 0, 0, /* .plt size goes here */
712 0, /* Augmentation size */
713 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
714 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
715 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
716 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
717 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
718 11, /* Block length */
719 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
720 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
721 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
722 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
723 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
726 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
728 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
730 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
731 0, 0, 0, 0, /* CIE ID */
733 'z', 'R', 0, /* Augmentation string */
734 1, /* Code alignment factor */
735 0x78, /* Data alignment factor */
736 16, /* Return address column */
737 1, /* Augmentation size */
738 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
739 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
740 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
741 DW_CFA_nop
, DW_CFA_nop
,
743 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
744 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
745 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
746 0, 0, 0, 0, /* .plt size goes here */
747 0, /* Augmentation size */
748 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
749 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
750 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
751 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
752 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
753 11, /* Block length */
754 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
755 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
756 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
757 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
758 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
761 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
763 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
765 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
766 0, 0, 0, 0, /* CIE ID */
768 'z', 'R', 0, /* Augmentation string */
769 1, /* Code alignment factor */
770 0x78, /* Data alignment factor */
771 16, /* Return address column */
772 1, /* Augmentation size */
773 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
774 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
775 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
776 DW_CFA_nop
, DW_CFA_nop
,
778 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
779 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
780 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
781 0, 0, 0, 0, /* .plt size goes here */
782 0, /* Augmentation size */
783 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
784 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
785 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
786 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
787 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
788 11, /* Block length */
789 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
790 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
791 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
792 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
793 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
796 /* .eh_frame covering the non-lazy .plt section. */
798 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
800 #define PLT_GOT_FDE_LENGTH 20
801 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
802 0, 0, 0, 0, /* CIE ID */
804 'z', 'R', 0, /* Augmentation string */
805 1, /* Code alignment factor */
806 0x78, /* Data alignment factor */
807 16, /* Return address column */
808 1, /* Augmentation size */
809 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
810 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
811 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
812 DW_CFA_nop
, DW_CFA_nop
,
814 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
815 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
816 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
817 0, 0, 0, 0, /* non-lazy .plt size goes here */
818 0, /* Augmentation size */
819 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
820 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
823 /* Architecture-specific backend data for x86-64. */
825 struct elf_x86_64_backend_data
835 #define get_elf_x86_64_arch_data(bed) \
836 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
838 #define get_elf_x86_64_backend_data(abfd) \
839 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
841 /* These are the standard parameters. */
842 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
844 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
845 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
846 elf_x86_64_lazy_plt_entry
, /* plt_entry */
847 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
848 2, /* plt0_got1_offset */
849 8, /* plt0_got2_offset */
850 12, /* plt0_got2_insn_end */
851 2, /* plt_got_offset */
852 7, /* plt_reloc_offset */
853 12, /* plt_plt_offset */
854 6, /* plt_got_insn_size */
855 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
856 6, /* plt_lazy_offset */
857 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
858 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
859 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
860 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
863 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
865 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
866 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
867 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
868 2, /* plt_got_offset */
869 6, /* plt_got_insn_size */
870 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
871 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
874 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
876 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
877 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
878 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
879 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
880 2, /* plt0_got1_offset */
881 1+8, /* plt0_got2_offset */
882 1+12, /* plt0_got2_insn_end */
883 1+2, /* plt_got_offset */
884 1, /* plt_reloc_offset */
885 7, /* plt_plt_offset */
886 1+6, /* plt_got_insn_size */
887 11, /* plt_plt_insn_end */
888 0, /* plt_lazy_offset */
889 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
890 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
891 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
892 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
895 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
897 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
898 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
899 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
900 1+2, /* plt_got_offset */
901 1+6, /* plt_got_insn_size */
902 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
903 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
906 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
908 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
909 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
910 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
911 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
912 2, /* plt0_got1_offset */
913 1+8, /* plt0_got2_offset */
914 1+12, /* plt0_got2_insn_end */
915 4+1+2, /* plt_got_offset */
916 4+1, /* plt_reloc_offset */
917 4+1+6, /* plt_plt_offset */
918 4+1+6, /* plt_got_insn_size */
919 4+1+5+5, /* plt_plt_insn_end */
920 0, /* plt_lazy_offset */
921 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
922 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
923 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
924 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
927 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
929 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
930 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
931 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
932 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
933 2, /* plt0_got1_offset */
934 8, /* plt0_got2_offset */
935 12, /* plt0_got2_insn_end */
936 4+2, /* plt_got_offset */
937 4+1, /* plt_reloc_offset */
938 4+6, /* plt_plt_offset */
939 4+6, /* plt_got_insn_size */
940 4+5+5, /* plt_plt_insn_end */
941 0, /* plt_lazy_offset */
942 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
943 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
944 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
945 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
948 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
950 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
951 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
952 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
953 4+1+2, /* plt_got_offset */
954 4+1+6, /* plt_got_insn_size */
955 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
956 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
959 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
961 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
962 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
963 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
964 4+2, /* plt_got_offset */
965 4+6, /* plt_got_insn_size */
966 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
967 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
970 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
975 #define elf_backend_arch_data &elf_x86_64_arch_bed
978 elf64_x86_64_elf_object_p (bfd
*abfd
)
980 /* Set the right machine number for an x86-64 elf64 file. */
981 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
986 elf32_x86_64_elf_object_p (bfd
*abfd
)
988 /* Set the right machine number for an x86-64 elf32 file. */
989 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
993 /* Return TRUE if the TLS access code sequence support transition
997 elf_x86_64_check_tls_transition (bfd
*abfd
,
998 struct bfd_link_info
*info
,
1001 Elf_Internal_Shdr
*symtab_hdr
,
1002 struct elf_link_hash_entry
**sym_hashes
,
1003 unsigned int r_type
,
1004 const Elf_Internal_Rela
*rel
,
1005 const Elf_Internal_Rela
*relend
)
1008 unsigned long r_symndx
;
1009 bfd_boolean largepic
= FALSE
;
1010 struct elf_link_hash_entry
*h
;
1012 struct elf_x86_link_hash_table
*htab
;
1014 bfd_boolean indirect_call
;
1016 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1017 offset
= rel
->r_offset
;
1020 case R_X86_64_TLSGD
:
1021 case R_X86_64_TLSLD
:
1022 if ((rel
+ 1) >= relend
)
1025 if (r_type
== R_X86_64_TLSGD
)
1027 /* Check transition from GD access model. For 64bit, only
1028 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1029 .word 0x6666; rex64; call __tls_get_addr@PLT
1031 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1033 call *__tls_get_addr@GOTPCREL(%rip)
1034 which may be converted to
1035 addr32 call __tls_get_addr
1036 can transit to different access model. For 32bit, only
1037 leaq foo@tlsgd(%rip), %rdi
1038 .word 0x6666; rex64; call __tls_get_addr@PLT
1040 leaq foo@tlsgd(%rip), %rdi
1042 call *__tls_get_addr@GOTPCREL(%rip)
1043 which may be converted to
1044 addr32 call __tls_get_addr
1045 can transit to different access model. For largepic,
1047 leaq foo@tlsgd(%rip), %rdi
1048 movabsq $__tls_get_addr@pltoff, %rax
1052 leaq foo@tlsgd(%rip), %rdi
1053 movabsq $__tls_get_addr@pltoff, %rax
1057 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1059 if ((offset
+ 12) > sec
->size
)
1062 call
= contents
+ offset
+ 4;
1064 || !((call
[1] == 0x48
1072 && call
[3] == 0xe8)))
1074 if (!ABI_64_P (abfd
)
1075 || (offset
+ 19) > sec
->size
1077 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1078 || memcmp (call
, "\x48\xb8", 2) != 0
1082 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1083 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1087 else if (ABI_64_P (abfd
))
1090 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1096 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1099 indirect_call
= call
[2] == 0xff;
1103 /* Check transition from LD access model. Only
1104 leaq foo@tlsld(%rip), %rdi;
1105 call __tls_get_addr@PLT
1107 leaq foo@tlsld(%rip), %rdi;
1108 call *__tls_get_addr@GOTPCREL(%rip)
1109 which may be converted to
1110 addr32 call __tls_get_addr
1111 can transit to different access model. For largepic
1113 leaq foo@tlsld(%rip), %rdi
1114 movabsq $__tls_get_addr@pltoff, %rax
1118 leaq foo@tlsld(%rip), %rdi
1119 movabsq $__tls_get_addr@pltoff, %rax
1123 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1125 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1128 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1131 call
= contents
+ offset
+ 4;
1132 if (!(call
[0] == 0xe8
1133 || (call
[0] == 0xff && call
[1] == 0x15)
1134 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1136 if (!ABI_64_P (abfd
)
1137 || (offset
+ 19) > sec
->size
1138 || memcmp (call
, "\x48\xb8", 2) != 0
1142 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1143 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1147 indirect_call
= call
[0] == 0xff;
1150 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1151 if (r_symndx
< symtab_hdr
->sh_info
)
1154 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1156 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1160 r_type
= (ELF32_R_TYPE (rel
[1].r_info
)
1161 & ~R_X86_64_converted_reloc_bit
);
1163 return r_type
== R_X86_64_PLTOFF64
;
1164 else if (indirect_call
)
1165 return r_type
== R_X86_64_GOTPCRELX
;
1167 return (r_type
== R_X86_64_PC32
|| r_type
== R_X86_64_PLT32
);
1170 case R_X86_64_GOTTPOFF
:
1171 /* Check transition from IE access model:
1172 mov foo@gottpoff(%rip), %reg
1173 add foo@gottpoff(%rip), %reg
1176 /* Check REX prefix first. */
1177 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1179 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1180 if (val
!= 0x48 && val
!= 0x4c)
1182 /* X32 may have 0x44 REX prefix or no REX prefix. */
1183 if (ABI_64_P (abfd
))
1189 /* X32 may not have any REX prefix. */
1190 if (ABI_64_P (abfd
))
1192 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1196 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1197 if (val
!= 0x8b && val
!= 0x03)
1200 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1201 return (val
& 0xc7) == 5;
1203 case R_X86_64_GOTPC32_TLSDESC
:
1204 /* Check transition from GDesc access model:
1205 leaq x@tlsdesc(%rip), %rax
1207 Make sure it's a leaq adding rip to a 32-bit offset
1208 into any register, although it's probably almost always
1211 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1214 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1215 if ((val
& 0xfb) != 0x48)
1218 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1221 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1222 return (val
& 0xc7) == 0x05;
1224 case R_X86_64_TLSDESC_CALL
:
1225 /* Check transition from GDesc access model:
1226 call *x@tlsdesc(%rax)
1228 if (offset
+ 2 <= sec
->size
)
1230 /* Make sure that it's a call *x@tlsdesc(%rax). */
1231 call
= contents
+ offset
;
1232 return call
[0] == 0xff && call
[1] == 0x10;
1242 /* Return TRUE if the TLS access transition is OK or no transition
1243 will be performed. Update R_TYPE if there is a transition. */
1246 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1247 asection
*sec
, bfd_byte
*contents
,
1248 Elf_Internal_Shdr
*symtab_hdr
,
1249 struct elf_link_hash_entry
**sym_hashes
,
1250 unsigned int *r_type
, int tls_type
,
1251 const Elf_Internal_Rela
*rel
,
1252 const Elf_Internal_Rela
*relend
,
1253 struct elf_link_hash_entry
*h
,
1254 unsigned long r_symndx
,
1255 bfd_boolean from_relocate_section
)
1257 unsigned int from_type
= *r_type
;
1258 unsigned int to_type
= from_type
;
1259 bfd_boolean check
= TRUE
;
1261 /* Skip TLS transition for functions. */
1263 && (h
->type
== STT_FUNC
1264 || h
->type
== STT_GNU_IFUNC
))
1269 case R_X86_64_TLSGD
:
1270 case R_X86_64_GOTPC32_TLSDESC
:
1271 case R_X86_64_TLSDESC_CALL
:
1272 case R_X86_64_GOTTPOFF
:
1273 if (bfd_link_executable (info
))
1276 to_type
= R_X86_64_TPOFF32
;
1278 to_type
= R_X86_64_GOTTPOFF
;
1281 /* When we are called from elf_x86_64_relocate_section, there may
1282 be additional transitions based on TLS_TYPE. */
1283 if (from_relocate_section
)
1285 unsigned int new_to_type
= to_type
;
1287 if (TLS_TRANSITION_IE_TO_LE_P (info
, h
, tls_type
))
1288 new_to_type
= R_X86_64_TPOFF32
;
1290 if (to_type
== R_X86_64_TLSGD
1291 || to_type
== R_X86_64_GOTPC32_TLSDESC
1292 || to_type
== R_X86_64_TLSDESC_CALL
)
1294 if (tls_type
== GOT_TLS_IE
)
1295 new_to_type
= R_X86_64_GOTTPOFF
;
1298 /* We checked the transition before when we were called from
1299 elf_x86_64_check_relocs. We only want to check the new
1300 transition which hasn't been checked before. */
1301 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1302 to_type
= new_to_type
;
1307 case R_X86_64_TLSLD
:
1308 if (bfd_link_executable (info
))
1309 to_type
= R_X86_64_TPOFF32
;
1316 /* Return TRUE if there is no transition. */
1317 if (from_type
== to_type
)
1320 /* Check if the transition can be performed. */
1322 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1323 symtab_hdr
, sym_hashes
,
1324 from_type
, rel
, relend
))
1326 reloc_howto_type
*from
, *to
;
1329 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1330 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1333 name
= h
->root
.root
.string
;
1336 struct elf_x86_link_hash_table
*htab
;
1338 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1343 Elf_Internal_Sym
*isym
;
1345 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1347 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1352 /* xgettext:c-format */
1353 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1354 "in section `%A' failed"),
1355 abfd
, from
->name
, to
->name
, name
, rel
->r_offset
, sec
);
1356 bfd_set_error (bfd_error_bad_value
);
1364 /* Rename some of the generic section flags to better document how they
1366 #define check_relocs_failed sec_flg0
1369 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1370 bfd
*input_bfd
, asection
*sec
,
1371 struct elf_link_hash_entry
*h
,
1372 Elf_Internal_Shdr
*symtab_hdr
,
1373 Elf_Internal_Sym
*isym
,
1374 reloc_howto_type
*howto
)
1377 const char *und
= "";
1378 const char *pic
= "";
1384 name
= h
->root
.root
.string
;
1385 switch (ELF_ST_VISIBILITY (h
->other
))
1388 v
= _("hidden symbol ");
1391 v
= _("internal symbol ");
1394 v
= _("protected symbol ");
1397 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1398 v
= _("protected symbol ");
1401 pic
= _("; recompile with -fPIC");
1405 if (!h
->def_regular
&& !h
->def_dynamic
)
1406 und
= _("undefined ");
1410 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1411 pic
= _("; recompile with -fPIC");
1414 if (bfd_link_dll (info
))
1415 object
= _("a shared object");
1416 else if (bfd_link_pie (info
))
1417 object
= _("a PIE object");
1419 object
= _("a PDE object");
1421 /* xgettext:c-format */
1422 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1423 "not be used when making %s%s"),
1424 input_bfd
, howto
->name
, und
, v
, name
,
1426 bfd_set_error (bfd_error_bad_value
);
1427 sec
->check_relocs_failed
= 1;
1431 /* With the local symbol, foo, we convert
1432 mov foo@GOTPCREL(%rip), %reg
1436 call/jmp *foo@GOTPCREL(%rip)
1438 nop call foo/jmp foo nop
1439 When PIC is false, convert
1440 test %reg, foo@GOTPCREL(%rip)
1444 binop foo@GOTPCREL(%rip), %reg
1447 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1451 elf_x86_64_convert_load_reloc (bfd
*abfd
,
1453 unsigned int *r_type_p
,
1454 Elf_Internal_Rela
*irel
,
1455 struct elf_link_hash_entry
*h
,
1456 bfd_boolean
*converted
,
1457 struct bfd_link_info
*link_info
)
1459 struct elf_x86_link_hash_table
*htab
;
1461 bfd_boolean no_overflow
;
1463 bfd_boolean to_reloc_pc32
;
1465 bfd_signed_vma raddend
;
1466 unsigned int opcode
;
1468 unsigned int r_type
= *r_type_p
;
1469 unsigned int r_symndx
;
1470 bfd_vma roff
= irel
->r_offset
;
1472 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1475 raddend
= irel
->r_addend
;
1476 /* Addend for 32-bit PC-relative relocation must be -4. */
1480 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1481 is_pic
= bfd_link_pic (link_info
);
1483 relocx
= (r_type
== R_X86_64_GOTPCRELX
1484 || r_type
== R_X86_64_REX_GOTPCRELX
);
1486 /* TRUE if --no-relax is used. */
1487 no_overflow
= link_info
->disable_target_specific_optimizations
> 1;
1489 r_symndx
= htab
->r_sym (irel
->r_info
);
1491 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1493 /* Convert mov to lea since it has been done for a while. */
1496 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1497 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1498 test, xor instructions. */
1503 /* We convert only to R_X86_64_PC32:
1505 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1506 3. no_overflow is true.
1509 to_reloc_pc32
= (opcode
== 0xff
1514 /* Get the symbol referred to by the reloc. */
1517 Elf_Internal_Sym
*isym
1518 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1520 /* Skip relocation against undefined symbols. */
1521 if (isym
->st_shndx
== SHN_UNDEF
)
1524 if (isym
->st_shndx
== SHN_ABS
)
1525 tsec
= bfd_abs_section_ptr
;
1526 else if (isym
->st_shndx
== SHN_COMMON
)
1527 tsec
= bfd_com_section_ptr
;
1528 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1529 tsec
= &_bfd_elf_large_com_section
;
1531 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1535 /* Undefined weak symbol is only bound locally in executable
1536 and its reference is resolved as 0 without relocation
1537 overflow. We can only perform this optimization for
1538 GOTPCRELX relocations since we need to modify REX byte.
1539 It is OK convert mov with R_X86_64_GOTPCREL to
1541 bfd_boolean local_ref
;
1542 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
1544 /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
1545 local_ref
= SYMBOL_REFERENCES_LOCAL_P (link_info
, h
);
1546 if ((relocx
|| opcode
== 0x8b)
1547 && (h
->root
.type
== bfd_link_hash_undefweak
1553 /* Skip for branch instructions since R_X86_64_PC32
1560 /* For non-branch instructions, we can convert to
1561 R_X86_64_32/R_X86_64_32S since we know if there
1563 to_reloc_pc32
= FALSE
;
1566 /* Since we don't know the current PC when PIC is true,
1567 we can't convert to R_X86_64_PC32. */
1568 if (to_reloc_pc32
&& is_pic
)
1573 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1574 ld.so may use its link-time address. */
1575 else if (h
->start_stop
1578 || h
->root
.type
== bfd_link_hash_defined
1579 || h
->root
.type
== bfd_link_hash_defweak
)
1580 && h
!= htab
->elf
.hdynamic
1583 /* bfd_link_hash_new or bfd_link_hash_undefined is
1584 set by an assignment in a linker script in
1585 bfd_elf_record_link_assignment. start_stop is set
1586 on __start_SECNAME/__stop_SECNAME which mark section
1591 && (h
->root
.type
== bfd_link_hash_new
1592 || h
->root
.type
== bfd_link_hash_undefined
1593 || ((h
->root
.type
== bfd_link_hash_defined
1594 || h
->root
.type
== bfd_link_hash_defweak
)
1595 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1597 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1602 tsec
= h
->root
.u
.def
.section
;
1608 /* Don't convert GOTPCREL relocation against large section. */
1609 if (elf_section_data (tsec
) != NULL
1610 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1613 /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */
1620 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1625 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1627 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1630 /* Convert to "jmp foo nop". */
1633 nop_offset
= irel
->r_offset
+ 3;
1634 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1635 irel
->r_offset
-= 1;
1636 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1640 struct elf_x86_link_hash_entry
*eh
1641 = (struct elf_x86_link_hash_entry
*) h
;
1643 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1646 /* To support TLS optimization, always use addr32 prefix for
1647 "call *__tls_get_addr@GOTPCREL(%rip)". */
1648 if (eh
&& eh
->tls_get_addr
)
1651 nop_offset
= irel
->r_offset
- 2;
1655 nop
= link_info
->call_nop_byte
;
1656 if (link_info
->call_nop_as_suffix
)
1658 nop_offset
= irel
->r_offset
+ 3;
1659 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1660 irel
->r_offset
-= 1;
1661 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1664 nop_offset
= irel
->r_offset
- 2;
1667 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1668 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1669 r_type
= R_X86_64_PC32
;
1674 unsigned int rex_mask
= REX_R
;
1676 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1677 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1685 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1686 "lea foo(%rip), %reg". */
1688 r_type
= R_X86_64_PC32
;
1692 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1693 "mov $foo, %reg". */
1695 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1696 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1697 if ((rex
& REX_W
) != 0
1698 && ABI_64_P (link_info
->output_bfd
))
1700 /* Keep the REX_W bit in REX byte for LP64. */
1701 r_type
= R_X86_64_32S
;
1702 goto rewrite_modrm_rex
;
1706 /* If the REX_W bit in REX byte isn't needed,
1707 use R_X86_64_32 and clear the W bit to avoid
1708 sign-extend imm32 to imm64. */
1709 r_type
= R_X86_64_32
;
1710 /* Clear the W bit in REX byte. */
1712 goto rewrite_modrm_rex
;
1718 /* R_X86_64_PC32 isn't supported. */
1722 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1725 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1726 "test $foo, %reg". */
1727 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1732 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1733 "binop $foo, %reg". */
1734 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1738 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1739 overflow when sign-extending imm32 to imm64. */
1740 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1743 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1747 /* Move the R bit to the B bit in REX byte. */
1748 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1749 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1752 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1756 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1760 irel
->r_info
= htab
->r_info (r_symndx
,
1761 r_type
| R_X86_64_converted_reloc_bit
);
1768 /* Look through the relocs for a section during the first phase, and
1769 calculate needed space in the global offset table, procedure
1770 linkage table, and dynamic reloc sections. */
1773 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1775 const Elf_Internal_Rela
*relocs
)
1777 struct elf_x86_link_hash_table
*htab
;
1778 Elf_Internal_Shdr
*symtab_hdr
;
1779 struct elf_link_hash_entry
**sym_hashes
;
1780 const Elf_Internal_Rela
*rel
;
1781 const Elf_Internal_Rela
*rel_end
;
1784 bfd_boolean converted
;
1786 if (bfd_link_relocatable (info
))
1789 /* Don't do anything special with non-loaded, non-alloced sections.
1790 In particular, any relocs in such sections should not affect GOT
1791 and PLT reference counting (ie. we don't allow them to create GOT
1792 or PLT entries), there's no possibility or desire to optimize TLS
1793 relocs, and there's not much point in propagating relocs to shared
1794 libs that the dynamic linker won't relocate. */
1795 if ((sec
->flags
& SEC_ALLOC
) == 0)
1798 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1801 sec
->check_relocs_failed
= 1;
1805 BFD_ASSERT (is_x86_elf (abfd
, htab
));
1807 /* Get the section contents. */
1808 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1809 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1810 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1812 sec
->check_relocs_failed
= 1;
1816 symtab_hdr
= &elf_symtab_hdr (abfd
);
1817 sym_hashes
= elf_sym_hashes (abfd
);
1823 rel_end
= relocs
+ sec
->reloc_count
;
1824 for (rel
= relocs
; rel
< rel_end
; rel
++)
1826 unsigned int r_type
;
1827 unsigned int r_symndx
;
1828 struct elf_link_hash_entry
*h
;
1829 struct elf_x86_link_hash_entry
*eh
;
1830 Elf_Internal_Sym
*isym
;
1832 bfd_boolean size_reloc
;
1833 bfd_boolean converted_reloc
;
1835 r_symndx
= htab
->r_sym (rel
->r_info
);
1836 r_type
= ELF32_R_TYPE (rel
->r_info
);
1838 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1840 /* xgettext:c-format */
1841 _bfd_error_handler (_("%B: bad symbol index: %d"),
1846 if (r_symndx
< symtab_hdr
->sh_info
)
1848 /* A local symbol. */
1849 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1854 /* Check relocation against local STT_GNU_IFUNC symbol. */
1855 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1857 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1862 /* Fake a STT_GNU_IFUNC symbol. */
1863 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1865 h
->type
= STT_GNU_IFUNC
;
1868 h
->forced_local
= 1;
1869 h
->root
.type
= bfd_link_hash_defined
;
1877 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1878 while (h
->root
.type
== bfd_link_hash_indirect
1879 || h
->root
.type
== bfd_link_hash_warning
)
1880 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1883 /* Check invalid x32 relocations. */
1884 if (!ABI_64_P (abfd
))
1890 case R_X86_64_DTPOFF64
:
1891 case R_X86_64_TPOFF64
:
1893 case R_X86_64_GOTOFF64
:
1894 case R_X86_64_GOT64
:
1895 case R_X86_64_GOTPCREL64
:
1896 case R_X86_64_GOTPC64
:
1897 case R_X86_64_GOTPLT64
:
1898 case R_X86_64_PLTOFF64
:
1901 name
= h
->root
.root
.string
;
1903 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1906 /* xgettext:c-format */
1907 (_("%B: relocation %s against symbol `%s' isn't "
1908 "supported in x32 mode"), abfd
,
1909 x86_64_elf_howto_table
[r_type
].name
, name
);
1910 bfd_set_error (bfd_error_bad_value
);
1918 /* It is referenced by a non-shared object. */
1920 h
->root
.non_ir_ref_regular
= 1;
1922 if (h
->type
== STT_GNU_IFUNC
)
1923 elf_tdata (info
->output_bfd
)->has_gnu_symbols
1924 |= elf_gnu_symbol_ifunc
;
1927 converted_reloc
= FALSE
;
1928 if ((r_type
== R_X86_64_GOTPCREL
1929 || r_type
== R_X86_64_GOTPCRELX
1930 || r_type
== R_X86_64_REX_GOTPCRELX
)
1931 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
1933 Elf_Internal_Rela
*irel
= (Elf_Internal_Rela
*) rel
;
1934 if (!elf_x86_64_convert_load_reloc (abfd
, contents
, &r_type
,
1935 irel
, h
, &converted_reloc
,
1939 if (converted_reloc
)
1943 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
1944 symtab_hdr
, sym_hashes
,
1945 &r_type
, GOT_UNKNOWN
,
1946 rel
, rel_end
, h
, r_symndx
, FALSE
))
1949 eh
= (struct elf_x86_link_hash_entry
*) h
;
1952 case R_X86_64_TLSLD
:
1953 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
1956 case R_X86_64_TPOFF32
:
1957 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
1958 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
1959 &x86_64_elf_howto_table
[r_type
]);
1961 eh
->has_got_reloc
= 1;
1964 case R_X86_64_GOTTPOFF
:
1965 if (!bfd_link_executable (info
))
1966 info
->flags
|= DF_STATIC_TLS
;
1969 case R_X86_64_GOT32
:
1970 case R_X86_64_GOTPCREL
:
1971 case R_X86_64_GOTPCRELX
:
1972 case R_X86_64_REX_GOTPCRELX
:
1973 case R_X86_64_TLSGD
:
1974 case R_X86_64_GOT64
:
1975 case R_X86_64_GOTPCREL64
:
1976 case R_X86_64_GOTPLT64
:
1977 case R_X86_64_GOTPC32_TLSDESC
:
1978 case R_X86_64_TLSDESC_CALL
:
1979 /* This symbol requires a global offset table entry. */
1981 int tls_type
, old_tls_type
;
1985 default: tls_type
= GOT_NORMAL
; break;
1986 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1987 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1988 case R_X86_64_GOTPC32_TLSDESC
:
1989 case R_X86_64_TLSDESC_CALL
:
1990 tls_type
= GOT_TLS_GDESC
; break;
1995 h
->got
.refcount
+= 1;
1996 old_tls_type
= eh
->tls_type
;
2000 bfd_signed_vma
*local_got_refcounts
;
2002 /* This is a global offset table entry for a local symbol. */
2003 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2004 if (local_got_refcounts
== NULL
)
2008 size
= symtab_hdr
->sh_info
;
2009 size
*= sizeof (bfd_signed_vma
)
2010 + sizeof (bfd_vma
) + sizeof (char);
2011 local_got_refcounts
= ((bfd_signed_vma
*)
2012 bfd_zalloc (abfd
, size
));
2013 if (local_got_refcounts
== NULL
)
2015 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2016 elf_x86_local_tlsdesc_gotent (abfd
)
2017 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2018 elf_x86_local_got_tls_type (abfd
)
2019 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2021 local_got_refcounts
[r_symndx
] += 1;
2023 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2026 /* If a TLS symbol is accessed using IE at least once,
2027 there is no point to use dynamic model for it. */
2028 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2029 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2030 || tls_type
!= GOT_TLS_IE
))
2032 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2033 tls_type
= old_tls_type
;
2034 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2035 && GOT_TLS_GD_ANY_P (tls_type
))
2036 tls_type
|= old_tls_type
;
2040 name
= h
->root
.root
.string
;
2042 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2045 /* xgettext:c-format */
2046 (_("%B: '%s' accessed both as normal and"
2047 " thread local symbol"),
2049 bfd_set_error (bfd_error_bad_value
);
2054 if (old_tls_type
!= tls_type
)
2057 eh
->tls_type
= tls_type
;
2059 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2064 case R_X86_64_GOTOFF64
:
2065 case R_X86_64_GOTPC32
:
2066 case R_X86_64_GOTPC64
:
2069 eh
->has_got_reloc
= 1;
2072 case R_X86_64_PLT32
:
2073 case R_X86_64_PLT32_BND
:
2074 /* This symbol requires a procedure linkage table entry. We
2075 actually build the entry in adjust_dynamic_symbol,
2076 because this might be a case of linking PIC code which is
2077 never referenced by a dynamic object, in which case we
2078 don't need to generate a procedure linkage table entry
2081 /* If this is a local symbol, we resolve it directly without
2082 creating a procedure linkage table entry. */
2086 eh
->has_got_reloc
= 1;
2088 h
->plt
.refcount
+= 1;
2091 case R_X86_64_PLTOFF64
:
2092 /* This tries to form the 'address' of a function relative
2093 to GOT. For global symbols we need a PLT entry. */
2097 h
->plt
.refcount
+= 1;
2101 case R_X86_64_SIZE32
:
2102 case R_X86_64_SIZE64
:
2107 if (!ABI_64_P (abfd
))
2113 /* Check relocation overflow as these relocs may lead to
2114 run-time relocation overflow. Don't error out for
2115 sections we don't care about, such as debug sections or
2116 when relocation overflow check is disabled. */
2117 if (!info
->no_reloc_overflow_check
2119 && (bfd_link_pic (info
)
2120 || (bfd_link_executable (info
)
2124 && (sec
->flags
& SEC_READONLY
) == 0)))
2125 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2126 &x86_64_elf_howto_table
[r_type
]);
2132 case R_X86_64_PC32_BND
:
2136 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2137 eh
->has_non_got_reloc
= 1;
2138 /* We are called after all symbols have been resolved. Only
2139 relocation against STT_GNU_IFUNC symbol must go through
2142 && (bfd_link_executable (info
)
2143 || h
->type
== STT_GNU_IFUNC
))
2145 /* If this reloc is in a read-only section, we might
2146 need a copy reloc. We can't check reliably at this
2147 stage whether the section is read-only, as input
2148 sections have not yet been mapped to output sections.
2149 Tentatively set the flag for now, and correct in
2150 adjust_dynamic_symbol. */
2153 /* We may need a .plt entry if the symbol is a function
2154 defined in a shared lib or is a STT_GNU_IFUNC function
2155 referenced from the code or read-only section. */
2157 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2158 h
->plt
.refcount
+= 1;
2160 if (r_type
== R_X86_64_PC32
)
2162 /* Since something like ".long foo - ." may be used
2163 as pointer, make sure that PLT is used if foo is
2164 a function defined in a shared library. */
2165 if ((sec
->flags
& SEC_CODE
) == 0)
2166 h
->pointer_equality_needed
= 1;
2168 else if (r_type
!= R_X86_64_PC32_BND
2169 && r_type
!= R_X86_64_PC64
)
2171 h
->pointer_equality_needed
= 1;
2172 /* At run-time, R_X86_64_64 can be resolved for both
2173 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2174 can only be resolved for x32. */
2175 if ((sec
->flags
& SEC_READONLY
) == 0
2176 && (r_type
== R_X86_64_64
2177 || (!ABI_64_P (abfd
)
2178 && (r_type
== R_X86_64_32
2179 || r_type
== R_X86_64_32S
))))
2180 eh
->func_pointer_refcount
+= 1;
2186 if (NEED_DYNAMIC_RELOCATION_P (info
, h
, sec
, r_type
,
2187 htab
->pointer_r_type
))
2189 struct elf_dyn_relocs
*p
;
2190 struct elf_dyn_relocs
**head
;
2192 /* We must copy these reloc types into the output file.
2193 Create a reloc section in dynobj and make room for
2197 sreloc
= _bfd_elf_make_dynamic_reloc_section
2198 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2199 abfd
, /*rela?*/ TRUE
);
2205 /* If this is a global symbol, we count the number of
2206 relocations we need for this symbol. */
2208 head
= &eh
->dyn_relocs
;
2211 /* Track dynamic relocs needed for local syms too.
2212 We really need local syms available to do this
2217 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2222 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2226 /* Beware of type punned pointers vs strict aliasing
2228 vpp
= &(elf_section_data (s
)->local_dynrel
);
2229 head
= (struct elf_dyn_relocs
**)vpp
;
2233 if (p
== NULL
|| p
->sec
!= sec
)
2235 bfd_size_type amt
= sizeof *p
;
2237 p
= ((struct elf_dyn_relocs
*)
2238 bfd_alloc (htab
->elf
.dynobj
, amt
));
2249 /* Count size relocation as PC-relative relocation. */
2250 if (X86_PCREL_TYPE_P (r_type
) || size_reloc
)
2255 /* This relocation describes the C++ object vtable hierarchy.
2256 Reconstruct it for later use during GC. */
2257 case R_X86_64_GNU_VTINHERIT
:
2258 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2262 /* This relocation describes which C++ vtable entries are actually
2263 used. Record for later use during GC. */
2264 case R_X86_64_GNU_VTENTRY
:
2265 BFD_ASSERT (h
!= NULL
);
2267 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2276 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2278 if (!converted
&& !info
->keep_memory
)
2282 /* Cache the section contents for elf_link_input_bfd if any
2283 load is converted or --no-keep-memory isn't used. */
2284 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2288 /* Cache relocations if any load is converted. */
2289 if (elf_section_data (sec
)->relocs
!= relocs
&& converted
)
2290 elf_section_data (sec
)->relocs
= (Elf_Internal_Rela
*) relocs
;
2295 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2297 sec
->check_relocs_failed
= 1;
2301 /* Return the relocation value for @tpoff relocation
2302 if STT_TLS virtual address is ADDRESS. */
2305 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2307 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2308 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2309 bfd_vma static_tls_size
;
2311 /* If tls_segment is NULL, we should have signalled an error already. */
2312 if (htab
->tls_sec
== NULL
)
2315 /* Consider special static TLS alignment requirements. */
2316 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2317 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2320 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2324 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2326 /* Opcode Instruction
2329 0x0f 0x8x conditional jump */
2331 && (contents
[offset
- 1] == 0xe8
2332 || contents
[offset
- 1] == 0xe9))
2334 && contents
[offset
- 2] == 0x0f
2335 && (contents
[offset
- 1] & 0xf0) == 0x80));
2338 /* Relocate an x86_64 ELF section. */
2341 elf_x86_64_relocate_section (bfd
*output_bfd
,
2342 struct bfd_link_info
*info
,
2344 asection
*input_section
,
2346 Elf_Internal_Rela
*relocs
,
2347 Elf_Internal_Sym
*local_syms
,
2348 asection
**local_sections
)
2350 struct elf_x86_link_hash_table
*htab
;
2351 Elf_Internal_Shdr
*symtab_hdr
;
2352 struct elf_link_hash_entry
**sym_hashes
;
2353 bfd_vma
*local_got_offsets
;
2354 bfd_vma
*local_tlsdesc_gotents
;
2355 Elf_Internal_Rela
*rel
;
2356 Elf_Internal_Rela
*wrel
;
2357 Elf_Internal_Rela
*relend
;
2358 unsigned int plt_entry_size
;
2360 /* Skip if check_relocs failed. */
2361 if (input_section
->check_relocs_failed
)
2364 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2368 BFD_ASSERT (is_x86_elf (input_bfd
, htab
));
2370 plt_entry_size
= htab
->plt
.plt_entry_size
;
2371 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2372 sym_hashes
= elf_sym_hashes (input_bfd
);
2373 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2374 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
2376 _bfd_x86_elf_set_tls_module_base (info
);
2378 rel
= wrel
= relocs
;
2379 relend
= relocs
+ input_section
->reloc_count
;
2380 for (; rel
< relend
; wrel
++, rel
++)
2382 unsigned int r_type
, r_type_tls
;
2383 reloc_howto_type
*howto
;
2384 unsigned long r_symndx
;
2385 struct elf_link_hash_entry
*h
;
2386 struct elf_x86_link_hash_entry
*eh
;
2387 Elf_Internal_Sym
*sym
;
2389 bfd_vma off
, offplt
, plt_offset
;
2391 bfd_boolean unresolved_reloc
;
2392 bfd_reloc_status_type r
;
2394 asection
*base_got
, *resolved_plt
;
2396 bfd_boolean resolved_to_zero
;
2397 bfd_boolean relative_reloc
;
2398 bfd_boolean converted_reloc
;
2399 bfd_boolean need_copy_reloc_in_pie
;
2401 r_type
= ELF32_R_TYPE (rel
->r_info
);
2402 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2403 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2410 converted_reloc
= (r_type
& R_X86_64_converted_reloc_bit
) != 0;
2411 r_type
&= ~R_X86_64_converted_reloc_bit
;
2413 if (r_type
>= (int) R_X86_64_standard
)
2414 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
2416 if (r_type
!= (int) R_X86_64_32
2417 || ABI_64_P (output_bfd
))
2418 howto
= x86_64_elf_howto_table
+ r_type
;
2420 howto
= (x86_64_elf_howto_table
2421 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
2422 r_symndx
= htab
->r_sym (rel
->r_info
);
2426 unresolved_reloc
= FALSE
;
2427 if (r_symndx
< symtab_hdr
->sh_info
)
2429 sym
= local_syms
+ r_symndx
;
2430 sec
= local_sections
[r_symndx
];
2432 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2434 st_size
= sym
->st_size
;
2436 /* Relocate against local STT_GNU_IFUNC symbol. */
2437 if (!bfd_link_relocatable (info
)
2438 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2440 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
2445 /* Set STT_GNU_IFUNC symbol value. */
2446 h
->root
.u
.def
.value
= sym
->st_value
;
2447 h
->root
.u
.def
.section
= sec
;
2452 bfd_boolean warned ATTRIBUTE_UNUSED
;
2453 bfd_boolean ignored ATTRIBUTE_UNUSED
;
2455 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2456 r_symndx
, symtab_hdr
, sym_hashes
,
2458 unresolved_reloc
, warned
, ignored
);
2462 if (sec
!= NULL
&& discarded_section (sec
))
2464 _bfd_clear_contents (howto
, input_bfd
, input_section
,
2465 contents
+ rel
->r_offset
);
2466 wrel
->r_offset
= rel
->r_offset
;
2470 /* For ld -r, remove relocations in debug sections against
2471 sections defined in discarded sections. Not done for
2472 eh_frame editing code expects to be present. */
2473 if (bfd_link_relocatable (info
)
2474 && (input_section
->flags
& SEC_DEBUGGING
))
2480 if (bfd_link_relocatable (info
))
2487 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
2489 if (r_type
== R_X86_64_64
)
2491 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
2492 zero-extend it to 64bit if addend is zero. */
2493 r_type
= R_X86_64_32
;
2494 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2496 else if (r_type
== R_X86_64_SIZE64
)
2498 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
2499 zero-extend it to 64bit if addend is zero. */
2500 r_type
= R_X86_64_SIZE32
;
2501 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
2505 eh
= (struct elf_x86_link_hash_entry
*) h
;
2507 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2508 it here if it is defined in a non-shared object. */
2510 && h
->type
== STT_GNU_IFUNC
2516 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2518 /* Dynamic relocs are not propagated for SEC_DEBUGGING
2519 sections because such sections are not SEC_ALLOC and
2520 thus ld.so will not process them. */
2521 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
2531 case R_X86_64_GOTPCREL
:
2532 case R_X86_64_GOTPCRELX
:
2533 case R_X86_64_REX_GOTPCRELX
:
2534 case R_X86_64_GOTPCREL64
:
2535 base_got
= htab
->elf
.sgot
;
2536 off
= h
->got
.offset
;
2538 if (base_got
== NULL
)
2541 if (off
== (bfd_vma
) -1)
2543 /* We can't use h->got.offset here to save state, or
2544 even just remember the offset, as finish_dynamic_symbol
2545 would use that as offset into .got. */
2547 if (h
->plt
.offset
== (bfd_vma
) -1)
2550 if (htab
->elf
.splt
!= NULL
)
2552 plt_index
= (h
->plt
.offset
/ plt_entry_size
2553 - htab
->plt
.has_plt0
);
2554 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2555 base_got
= htab
->elf
.sgotplt
;
2559 plt_index
= h
->plt
.offset
/ plt_entry_size
;
2560 off
= plt_index
* GOT_ENTRY_SIZE
;
2561 base_got
= htab
->elf
.igotplt
;
2564 if (h
->dynindx
== -1
2568 /* This references the local defitionion. We must
2569 initialize this entry in the global offset table.
2570 Since the offset must always be a multiple of 8,
2571 we use the least significant bit to record
2572 whether we have initialized it already.
2574 When doing a dynamic link, we create a .rela.got
2575 relocation entry to initialize the value. This
2576 is done in the finish_dynamic_symbol routine. */
2581 bfd_put_64 (output_bfd
, relocation
,
2582 base_got
->contents
+ off
);
2583 /* Note that this is harmless for the GOTPLT64
2584 case, as -1 | 1 still is -1. */
2590 relocation
= (base_got
->output_section
->vma
2591 + base_got
->output_offset
+ off
);
2596 if (h
->plt
.offset
== (bfd_vma
) -1)
2598 /* Handle static pointers of STT_GNU_IFUNC symbols. */
2599 if (r_type
== htab
->pointer_r_type
2600 && (input_section
->flags
& SEC_CODE
) == 0)
2601 goto do_ifunc_pointer
;
2602 goto bad_ifunc_reloc
;
2605 /* STT_GNU_IFUNC symbol must go through PLT. */
2606 if (htab
->elf
.splt
!= NULL
)
2608 if (htab
->plt_second
!= NULL
)
2610 resolved_plt
= htab
->plt_second
;
2611 plt_offset
= eh
->plt_second
.offset
;
2615 resolved_plt
= htab
->elf
.splt
;
2616 plt_offset
= h
->plt
.offset
;
2621 resolved_plt
= htab
->elf
.iplt
;
2622 plt_offset
= h
->plt
.offset
;
2625 relocation
= (resolved_plt
->output_section
->vma
2626 + resolved_plt
->output_offset
+ plt_offset
);
2632 if (h
->root
.root
.string
)
2633 name
= h
->root
.root
.string
;
2635 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2638 /* xgettext:c-format */
2639 (_("%B: relocation %s against STT_GNU_IFUNC "
2640 "symbol `%s' isn't supported"), input_bfd
,
2642 bfd_set_error (bfd_error_bad_value
);
2646 if (bfd_link_pic (info
))
2651 if (ABI_64_P (output_bfd
))
2656 if (rel
->r_addend
!= 0)
2658 if (h
->root
.root
.string
)
2659 name
= h
->root
.root
.string
;
2661 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2664 /* xgettext:c-format */
2665 (_("%B: relocation %s against STT_GNU_IFUNC "
2666 "symbol `%s' has non-zero addend: %Ld"),
2667 input_bfd
, howto
->name
, name
, rel
->r_addend
);
2668 bfd_set_error (bfd_error_bad_value
);
2672 /* Generate dynamic relcoation only when there is a
2673 non-GOT reference in a shared object or there is no
2675 if ((bfd_link_pic (info
) && h
->non_got_ref
)
2676 || h
->plt
.offset
== (bfd_vma
) -1)
2678 Elf_Internal_Rela outrel
;
2681 /* Need a dynamic relocation to get the real function
2683 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2687 if (outrel
.r_offset
== (bfd_vma
) -1
2688 || outrel
.r_offset
== (bfd_vma
) -2)
2691 outrel
.r_offset
+= (input_section
->output_section
->vma
2692 + input_section
->output_offset
);
2694 if (POINTER_LOCAL_IFUNC_P (info
, h
))
2696 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
2697 h
->root
.root
.string
,
2698 h
->root
.u
.def
.section
->owner
);
2700 /* This symbol is resolved locally. */
2701 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
2702 outrel
.r_addend
= (h
->root
.u
.def
.value
2703 + h
->root
.u
.def
.section
->output_section
->vma
2704 + h
->root
.u
.def
.section
->output_offset
);
2708 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
2709 outrel
.r_addend
= 0;
2712 /* Dynamic relocations are stored in
2713 1. .rela.ifunc section in PIC object.
2714 2. .rela.got section in dynamic executable.
2715 3. .rela.iplt section in static executable. */
2716 if (bfd_link_pic (info
))
2717 sreloc
= htab
->elf
.irelifunc
;
2718 else if (htab
->elf
.splt
!= NULL
)
2719 sreloc
= htab
->elf
.srelgot
;
2721 sreloc
= htab
->elf
.irelplt
;
2722 elf_append_rela (output_bfd
, sreloc
, &outrel
);
2724 /* If this reloc is against an external symbol, we
2725 do not want to fiddle with the addend. Otherwise,
2726 we need to include the symbol value so that it
2727 becomes an addend for the dynamic reloc. For an
2728 internal symbol, we have updated addend. */
2733 case R_X86_64_PC32_BND
:
2735 case R_X86_64_PLT32
:
2736 case R_X86_64_PLT32_BND
:
2741 resolved_to_zero
= (eh
!= NULL
2742 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
));
2744 /* When generating a shared object, the relocations handled here are
2745 copied into the output file to be resolved at run time. */
2748 case R_X86_64_GOT32
:
2749 case R_X86_64_GOT64
:
2750 /* Relocation is to the entry for this symbol in the global
2752 case R_X86_64_GOTPCREL
:
2753 case R_X86_64_GOTPCRELX
:
2754 case R_X86_64_REX_GOTPCRELX
:
2755 case R_X86_64_GOTPCREL64
:
2756 /* Use global offset table entry as symbol value. */
2757 case R_X86_64_GOTPLT64
:
2758 /* This is obsolete and treated the same as GOT64. */
2759 base_got
= htab
->elf
.sgot
;
2761 if (htab
->elf
.sgot
== NULL
)
2764 relative_reloc
= FALSE
;
2767 off
= h
->got
.offset
;
2769 && h
->plt
.offset
!= (bfd_vma
)-1
2770 && off
== (bfd_vma
)-1)
2772 /* We can't use h->got.offset here to save
2773 state, or even just remember the offset, as
2774 finish_dynamic_symbol would use that as offset into
2776 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
2777 - htab
->plt
.has_plt0
);
2778 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2779 base_got
= htab
->elf
.sgotplt
;
2782 if (RESOLVED_LOCALLY_P (info
, h
, htab
))
2784 /* We must initialize this entry in the global offset
2785 table. Since the offset must always be a multiple
2786 of 8, we use the least significant bit to record
2787 whether we have initialized it already.
2789 When doing a dynamic link, we create a .rela.got
2790 relocation entry to initialize the value. This is
2791 done in the finish_dynamic_symbol routine. */
2796 bfd_put_64 (output_bfd
, relocation
,
2797 base_got
->contents
+ off
);
2798 /* Note that this is harmless for the GOTPLT64 case,
2799 as -1 | 1 still is -1. */
2802 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
2804 /* If this symbol isn't dynamic in PIC,
2805 generate R_X86_64_RELATIVE here. */
2806 eh
->no_finish_dynamic_symbol
= 1;
2807 relative_reloc
= TRUE
;
2812 unresolved_reloc
= FALSE
;
2816 if (local_got_offsets
== NULL
)
2819 off
= local_got_offsets
[r_symndx
];
2821 /* The offset must always be a multiple of 8. We use
2822 the least significant bit to record whether we have
2823 already generated the necessary reloc. */
2828 bfd_put_64 (output_bfd
, relocation
,
2829 base_got
->contents
+ off
);
2830 local_got_offsets
[r_symndx
] |= 1;
2832 if (bfd_link_pic (info
))
2833 relative_reloc
= TRUE
;
2840 Elf_Internal_Rela outrel
;
2842 /* We need to generate a R_X86_64_RELATIVE reloc
2843 for the dynamic linker. */
2844 s
= htab
->elf
.srelgot
;
2848 outrel
.r_offset
= (base_got
->output_section
->vma
2849 + base_got
->output_offset
2851 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
2852 outrel
.r_addend
= relocation
;
2853 elf_append_rela (output_bfd
, s
, &outrel
);
2856 if (off
>= (bfd_vma
) -2)
2859 relocation
= base_got
->output_section
->vma
2860 + base_got
->output_offset
+ off
;
2861 if (r_type
!= R_X86_64_GOTPCREL
2862 && r_type
!= R_X86_64_GOTPCRELX
2863 && r_type
!= R_X86_64_REX_GOTPCRELX
2864 && r_type
!= R_X86_64_GOTPCREL64
)
2865 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2866 - htab
->elf
.sgotplt
->output_offset
;
2870 case R_X86_64_GOTOFF64
:
2871 /* Relocation is relative to the start of the global offset
2874 /* Check to make sure it isn't a protected function or data
2875 symbol for shared library since it may not be local when
2876 used as function address or with copy relocation. We also
2877 need to make sure that a symbol is referenced locally. */
2878 if (bfd_link_pic (info
) && h
)
2880 if (!h
->def_regular
)
2884 switch (ELF_ST_VISIBILITY (h
->other
))
2887 v
= _("hidden symbol");
2890 v
= _("internal symbol");
2893 v
= _("protected symbol");
2901 /* xgettext:c-format */
2902 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
2903 " `%s' can not be used when making a shared object"),
2904 input_bfd
, v
, h
->root
.root
.string
);
2905 bfd_set_error (bfd_error_bad_value
);
2908 else if (!bfd_link_executable (info
)
2909 && !SYMBOL_REFERENCES_LOCAL_P (info
, h
)
2910 && (h
->type
== STT_FUNC
2911 || h
->type
== STT_OBJECT
)
2912 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2915 /* xgettext:c-format */
2916 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
2917 " `%s' can not be used when making a shared object"),
2919 h
->type
== STT_FUNC
? "function" : "data",
2920 h
->root
.root
.string
);
2921 bfd_set_error (bfd_error_bad_value
);
2926 /* Note that sgot is not involved in this
2927 calculation. We always want the start of .got.plt. If we
2928 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2929 permitted by the ABI, we might have to change this
2931 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2932 + htab
->elf
.sgotplt
->output_offset
;
2935 case R_X86_64_GOTPC32
:
2936 case R_X86_64_GOTPC64
:
2937 /* Use global offset table as symbol value. */
2938 relocation
= htab
->elf
.sgotplt
->output_section
->vma
2939 + htab
->elf
.sgotplt
->output_offset
;
2940 unresolved_reloc
= FALSE
;
2943 case R_X86_64_PLTOFF64
:
2944 /* Relocation is PLT entry relative to GOT. For local
2945 symbols it's the symbol itself relative to GOT. */
2947 /* See PLT32 handling. */
2948 && (h
->plt
.offset
!= (bfd_vma
) -1
2949 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
2950 && htab
->elf
.splt
!= NULL
)
2952 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
2954 /* Use the GOT PLT. */
2955 resolved_plt
= htab
->plt_got
;
2956 plt_offset
= eh
->plt_got
.offset
;
2958 else if (htab
->plt_second
!= NULL
)
2960 resolved_plt
= htab
->plt_second
;
2961 plt_offset
= eh
->plt_second
.offset
;
2965 resolved_plt
= htab
->elf
.splt
;
2966 plt_offset
= h
->plt
.offset
;
2969 relocation
= (resolved_plt
->output_section
->vma
2970 + resolved_plt
->output_offset
2972 unresolved_reloc
= FALSE
;
2975 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
2976 + htab
->elf
.sgotplt
->output_offset
;
2979 case R_X86_64_PLT32
:
2980 case R_X86_64_PLT32_BND
:
2981 /* Relocation is to the entry for this symbol in the
2982 procedure linkage table. */
2984 /* Resolve a PLT32 reloc against a local symbol directly,
2985 without using the procedure linkage table. */
2989 if ((h
->plt
.offset
== (bfd_vma
) -1
2990 && eh
->plt_got
.offset
== (bfd_vma
) -1)
2991 || htab
->elf
.splt
== NULL
)
2993 /* We didn't make a PLT entry for this symbol. This
2994 happens when statically linking PIC code, or when
2995 using -Bsymbolic. */
2999 if (h
->plt
.offset
!= (bfd_vma
) -1)
3001 if (htab
->plt_second
!= NULL
)
3003 resolved_plt
= htab
->plt_second
;
3004 plt_offset
= eh
->plt_second
.offset
;
3008 resolved_plt
= htab
->elf
.splt
;
3009 plt_offset
= h
->plt
.offset
;
3014 /* Use the GOT PLT. */
3015 resolved_plt
= htab
->plt_got
;
3016 plt_offset
= eh
->plt_got
.offset
;
3019 relocation
= (resolved_plt
->output_section
->vma
3020 + resolved_plt
->output_offset
3022 unresolved_reloc
= FALSE
;
3025 case R_X86_64_SIZE32
:
3026 case R_X86_64_SIZE64
:
3027 /* Set to symbol size. */
3028 relocation
= st_size
;
3034 case R_X86_64_PC32_BND
:
3035 /* Don't complain about -fPIC if the symbol is undefined when
3036 building executable unless it is unresolved weak symbol or
3037 -z nocopyreloc is used. */
3038 if ((input_section
->flags
& SEC_ALLOC
) != 0
3039 && (input_section
->flags
& SEC_READONLY
) != 0
3041 && ((bfd_link_executable (info
)
3042 && ((h
->root
.type
== bfd_link_hash_undefweak
3043 && !resolved_to_zero
)
3044 || ((info
->nocopyreloc
3045 || (eh
->def_protected
3046 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
3048 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
3049 || bfd_link_dll (info
)))
3051 bfd_boolean fail
= FALSE
;
3053 = ((r_type
== R_X86_64_PC32
3054 || r_type
== R_X86_64_PC32_BND
)
3055 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3057 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
3059 /* Symbol is referenced locally. Make sure it is
3060 defined locally or for a branch. */
3061 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
3064 else if (!(bfd_link_pie (info
)
3065 && (h
->needs_copy
|| eh
->needs_copy
)))
3067 /* Symbol doesn't need copy reloc and isn't referenced
3068 locally. We only allow branch to symbol with
3069 non-default visibility. */
3071 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3075 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3076 h
, NULL
, NULL
, howto
);
3085 /* FIXME: The ABI says the linker should make sure the value is
3086 the same when it's zeroextended to 64 bit. */
3089 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3092 need_copy_reloc_in_pie
= (bfd_link_pie (info
)
3097 == bfd_link_hash_undefined
))
3098 && (X86_PCREL_TYPE_P (r_type
)
3099 || X86_SIZE_TYPE_P (r_type
)));
3101 if (GENERATE_DYNAMIC_RELOCATION_P (info
, eh
, r_type
,
3102 need_copy_reloc_in_pie
,
3103 resolved_to_zero
, FALSE
))
3105 Elf_Internal_Rela outrel
;
3106 bfd_boolean skip
, relocate
;
3109 /* When generating a shared object, these relocations
3110 are copied into the output file to be resolved at run
3116 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3118 if (outrel
.r_offset
== (bfd_vma
) -1)
3120 else if (outrel
.r_offset
== (bfd_vma
) -2)
3121 skip
= TRUE
, relocate
= TRUE
;
3123 outrel
.r_offset
+= (input_section
->output_section
->vma
3124 + input_section
->output_offset
);
3127 memset (&outrel
, 0, sizeof outrel
);
3129 /* h->dynindx may be -1 if this symbol was marked to
3133 && (X86_PCREL_TYPE_P (r_type
)
3134 || !(bfd_link_executable (info
)
3135 || SYMBOLIC_BIND (info
, h
))
3136 || ! h
->def_regular
))
3138 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3139 outrel
.r_addend
= rel
->r_addend
;
3143 /* This symbol is local, or marked to become local.
3144 When relocation overflow check is disabled, we
3145 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
3146 if (r_type
== htab
->pointer_r_type
3147 || (r_type
== R_X86_64_32
3148 && info
->no_reloc_overflow_check
))
3151 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3152 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3154 else if (r_type
== R_X86_64_64
3155 && !ABI_64_P (output_bfd
))
3158 outrel
.r_info
= htab
->r_info (0,
3159 R_X86_64_RELATIVE64
);
3160 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3161 /* Check addend overflow. */
3162 if ((outrel
.r_addend
& 0x80000000)
3163 != (rel
->r_addend
& 0x80000000))
3166 int addend
= rel
->r_addend
;
3167 if (h
&& h
->root
.root
.string
)
3168 name
= h
->root
.root
.string
;
3170 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3173 /* xgettext:c-format */
3174 (_("%B: addend %s%#x in relocation %s against "
3175 "symbol `%s' at %#Lx in section `%A' is "
3177 input_bfd
, addend
< 0 ? "-" : "", addend
,
3178 howto
->name
, name
, rel
->r_offset
, input_section
);
3179 bfd_set_error (bfd_error_bad_value
);
3187 if (bfd_is_abs_section (sec
))
3189 else if (sec
== NULL
|| sec
->owner
== NULL
)
3191 bfd_set_error (bfd_error_bad_value
);
3198 /* We are turning this relocation into one
3199 against a section symbol. It would be
3200 proper to subtract the symbol's value,
3201 osec->vma, from the emitted reloc addend,
3202 but ld.so expects buggy relocs. */
3203 osec
= sec
->output_section
;
3204 sindx
= elf_section_data (osec
)->dynindx
;
3207 asection
*oi
= htab
->elf
.text_index_section
;
3208 sindx
= elf_section_data (oi
)->dynindx
;
3210 BFD_ASSERT (sindx
!= 0);
3213 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3214 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3218 sreloc
= elf_section_data (input_section
)->sreloc
;
3220 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3222 r
= bfd_reloc_notsupported
;
3223 goto check_relocation_error
;
3226 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3228 /* If this reloc is against an external symbol, we do
3229 not want to fiddle with the addend. Otherwise, we
3230 need to include the symbol value so that it becomes
3231 an addend for the dynamic reloc. */
3238 case R_X86_64_TLSGD
:
3239 case R_X86_64_GOTPC32_TLSDESC
:
3240 case R_X86_64_TLSDESC_CALL
:
3241 case R_X86_64_GOTTPOFF
:
3242 tls_type
= GOT_UNKNOWN
;
3243 if (h
== NULL
&& local_got_offsets
)
3244 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
3246 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
3248 r_type_tls
= r_type
;
3249 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3250 input_section
, contents
,
3251 symtab_hdr
, sym_hashes
,
3252 &r_type_tls
, tls_type
, rel
,
3253 relend
, h
, r_symndx
, TRUE
))
3256 if (r_type_tls
== R_X86_64_TPOFF32
)
3258 bfd_vma roff
= rel
->r_offset
;
3260 BFD_ASSERT (! unresolved_reloc
);
3262 if (r_type
== R_X86_64_TLSGD
)
3264 /* GD->LE transition. For 64bit, change
3265 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3266 .word 0x6666; rex64; call __tls_get_addr@PLT
3268 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3270 call *__tls_get_addr@GOTPCREL(%rip)
3271 which may be converted to
3272 addr32 call __tls_get_addr
3275 leaq foo@tpoff(%rax), %rax
3277 leaq foo@tlsgd(%rip), %rdi
3278 .word 0x6666; rex64; call __tls_get_addr@PLT
3280 leaq foo@tlsgd(%rip), %rdi
3282 call *__tls_get_addr@GOTPCREL(%rip)
3283 which may be converted to
3284 addr32 call __tls_get_addr
3287 leaq foo@tpoff(%rax), %rax
3288 For largepic, change:
3289 leaq foo@tlsgd(%rip), %rdi
3290 movabsq $__tls_get_addr@pltoff, %rax
3295 leaq foo@tpoff(%rax), %rax
3296 nopw 0x0(%rax,%rax,1) */
3298 if (ABI_64_P (output_bfd
))
3300 if (contents
[roff
+ 5] == 0xb8)
3302 memcpy (contents
+ roff
- 3,
3303 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
3304 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3308 memcpy (contents
+ roff
- 4,
3309 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3313 memcpy (contents
+ roff
- 3,
3314 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3316 bfd_put_32 (output_bfd
,
3317 elf_x86_64_tpoff (info
, relocation
),
3318 contents
+ roff
+ 8 + largepic
);
3319 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
3320 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
3325 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3327 /* GDesc -> LE transition.
3328 It's originally something like:
3329 leaq x@tlsdesc(%rip), %rax
3332 movl $x@tpoff, %rax. */
3334 unsigned int val
, type
;
3336 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3337 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3338 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3339 contents
+ roff
- 3);
3340 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3341 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3342 contents
+ roff
- 1);
3343 bfd_put_32 (output_bfd
,
3344 elf_x86_64_tpoff (info
, relocation
),
3348 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3350 /* GDesc -> LE transition.
3355 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3356 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3359 else if (r_type
== R_X86_64_GOTTPOFF
)
3361 /* IE->LE transition:
3362 For 64bit, originally it can be one of:
3363 movq foo@gottpoff(%rip), %reg
3364 addq foo@gottpoff(%rip), %reg
3367 leaq foo(%reg), %reg
3369 For 32bit, originally it can be one of:
3370 movq foo@gottpoff(%rip), %reg
3371 addl foo@gottpoff(%rip), %reg
3374 leal foo(%reg), %reg
3377 unsigned int val
, type
, reg
;
3380 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3383 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3384 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3390 bfd_put_8 (output_bfd
, 0x49,
3391 contents
+ roff
- 3);
3392 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3393 bfd_put_8 (output_bfd
, 0x41,
3394 contents
+ roff
- 3);
3395 bfd_put_8 (output_bfd
, 0xc7,
3396 contents
+ roff
- 2);
3397 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3398 contents
+ roff
- 1);
3402 /* addq/addl -> addq/addl - addressing with %rsp/%r12
3405 bfd_put_8 (output_bfd
, 0x49,
3406 contents
+ roff
- 3);
3407 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3408 bfd_put_8 (output_bfd
, 0x41,
3409 contents
+ roff
- 3);
3410 bfd_put_8 (output_bfd
, 0x81,
3411 contents
+ roff
- 2);
3412 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3413 contents
+ roff
- 1);
3417 /* addq/addl -> leaq/leal */
3419 bfd_put_8 (output_bfd
, 0x4d,
3420 contents
+ roff
- 3);
3421 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3422 bfd_put_8 (output_bfd
, 0x45,
3423 contents
+ roff
- 3);
3424 bfd_put_8 (output_bfd
, 0x8d,
3425 contents
+ roff
- 2);
3426 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3427 contents
+ roff
- 1);
3429 bfd_put_32 (output_bfd
,
3430 elf_x86_64_tpoff (info
, relocation
),
3438 if (htab
->elf
.sgot
== NULL
)
3443 off
= h
->got
.offset
;
3444 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
3448 if (local_got_offsets
== NULL
)
3451 off
= local_got_offsets
[r_symndx
];
3452 offplt
= local_tlsdesc_gotents
[r_symndx
];
3459 Elf_Internal_Rela outrel
;
3463 if (htab
->elf
.srelgot
== NULL
)
3466 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3468 if (GOT_TLS_GDESC_P (tls_type
))
3470 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3471 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3472 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3473 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3474 + htab
->elf
.sgotplt
->output_offset
3476 + htab
->sgotplt_jump_table_size
);
3477 sreloc
= htab
->elf
.srelplt
;
3479 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3481 outrel
.r_addend
= 0;
3482 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3485 sreloc
= htab
->elf
.srelgot
;
3487 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3488 + htab
->elf
.sgot
->output_offset
+ off
);
3490 if (GOT_TLS_GD_P (tls_type
))
3491 dr_type
= R_X86_64_DTPMOD64
;
3492 else if (GOT_TLS_GDESC_P (tls_type
))
3495 dr_type
= R_X86_64_TPOFF64
;
3497 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3498 outrel
.r_addend
= 0;
3499 if ((dr_type
== R_X86_64_TPOFF64
3500 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3501 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
3502 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3504 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3506 if (GOT_TLS_GD_P (tls_type
))
3510 BFD_ASSERT (! unresolved_reloc
);
3511 bfd_put_64 (output_bfd
,
3512 relocation
- _bfd_x86_elf_dtpoff_base (info
),
3513 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3517 bfd_put_64 (output_bfd
, 0,
3518 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3519 outrel
.r_info
= htab
->r_info (indx
,
3521 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3522 elf_append_rela (output_bfd
, sreloc
,
3531 local_got_offsets
[r_symndx
] |= 1;
3534 if (off
>= (bfd_vma
) -2
3535 && ! GOT_TLS_GDESC_P (tls_type
))
3537 if (r_type_tls
== r_type
)
3539 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3540 || r_type
== R_X86_64_TLSDESC_CALL
)
3541 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3542 + htab
->elf
.sgotplt
->output_offset
3543 + offplt
+ htab
->sgotplt_jump_table_size
;
3545 relocation
= htab
->elf
.sgot
->output_section
->vma
3546 + htab
->elf
.sgot
->output_offset
+ off
;
3547 unresolved_reloc
= FALSE
;
3551 bfd_vma roff
= rel
->r_offset
;
3553 if (r_type
== R_X86_64_TLSGD
)
3555 /* GD->IE transition. For 64bit, change
3556 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3557 .word 0x6666; rex64; call __tls_get_addr@PLT
3559 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3561 call *__tls_get_addr@GOTPCREL(%rip
3562 which may be converted to
3563 addr32 call __tls_get_addr
3566 addq foo@gottpoff(%rip), %rax
3568 leaq foo@tlsgd(%rip), %rdi
3569 .word 0x6666; rex64; call __tls_get_addr@PLT
3571 leaq foo@tlsgd(%rip), %rdi
3573 call *__tls_get_addr@GOTPCREL(%rip)
3574 which may be converted to
3575 addr32 call __tls_get_addr
3578 addq foo@gottpoff(%rip), %rax
3579 For largepic, change:
3580 leaq foo@tlsgd(%rip), %rdi
3581 movabsq $__tls_get_addr@pltoff, %rax
3586 addq foo@gottpoff(%rax), %rax
3587 nopw 0x0(%rax,%rax,1) */
3589 if (ABI_64_P (output_bfd
))
3591 if (contents
[roff
+ 5] == 0xb8)
3593 memcpy (contents
+ roff
- 3,
3594 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
3595 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
3599 memcpy (contents
+ roff
- 4,
3600 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3604 memcpy (contents
+ roff
- 3,
3605 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3608 relocation
= (htab
->elf
.sgot
->output_section
->vma
3609 + htab
->elf
.sgot
->output_offset
+ off
3612 - input_section
->output_section
->vma
3613 - input_section
->output_offset
3615 bfd_put_32 (output_bfd
, relocation
,
3616 contents
+ roff
+ 8 + largepic
);
3617 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
3622 else if (r_type
== R_X86_64_GOTPC32_TLSDESC
)
3624 /* GDesc -> IE transition.
3625 It's originally something like:
3626 leaq x@tlsdesc(%rip), %rax
3629 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3631 /* Now modify the instruction as appropriate. To
3632 turn a leaq into a movq in the form we use it, it
3633 suffices to change the second byte from 0x8d to
3635 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3637 bfd_put_32 (output_bfd
,
3638 htab
->elf
.sgot
->output_section
->vma
3639 + htab
->elf
.sgot
->output_offset
+ off
3641 - input_section
->output_section
->vma
3642 - input_section
->output_offset
3647 else if (r_type
== R_X86_64_TLSDESC_CALL
)
3649 /* GDesc -> IE transition.
3656 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3657 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3665 case R_X86_64_TLSLD
:
3666 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3667 input_section
, contents
,
3668 symtab_hdr
, sym_hashes
,
3669 &r_type
, GOT_UNKNOWN
, rel
,
3670 relend
, h
, r_symndx
, TRUE
))
3673 if (r_type
!= R_X86_64_TLSLD
)
3675 /* LD->LE transition:
3676 leaq foo@tlsld(%rip), %rdi
3677 call __tls_get_addr@PLT
3678 For 64bit, we change it into:
3679 .word 0x6666; .byte 0x66; movq %fs:0, %rax
3680 For 32bit, we change it into:
3681 nopl 0x0(%rax); movl %fs:0, %eax
3683 leaq foo@tlsld(%rip), %rdi;
3684 call *__tls_get_addr@GOTPCREL(%rip)
3685 which may be converted to
3686 addr32 call __tls_get_addr
3687 For 64bit, we change it into:
3688 .word 0x6666; .word 0x6666; movq %fs:0, %rax
3689 For 32bit, we change it into:
3690 nopw 0x0(%rax); movl %fs:0, %eax
3691 For largepic, change:
3692 leaq foo@tlsgd(%rip), %rdi
3693 movabsq $__tls_get_addr@pltoff, %rax
3697 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
3700 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3701 if (ABI_64_P (output_bfd
))
3703 if (contents
[rel
->r_offset
+ 5] == 0xb8)
3704 memcpy (contents
+ rel
->r_offset
- 3,
3705 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
3706 "\x64\x48\x8b\x04\x25\0\0\0", 22);
3707 else if (contents
[rel
->r_offset
+ 4] == 0xff
3708 || contents
[rel
->r_offset
+ 4] == 0x67)
3709 memcpy (contents
+ rel
->r_offset
- 3,
3710 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
3713 memcpy (contents
+ rel
->r_offset
- 3,
3714 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3718 if (contents
[rel
->r_offset
+ 4] == 0xff)
3719 memcpy (contents
+ rel
->r_offset
- 3,
3720 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
3723 memcpy (contents
+ rel
->r_offset
- 3,
3724 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
3726 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
3727 and R_X86_64_PLTOFF64. */
3733 if (htab
->elf
.sgot
== NULL
)
3736 off
= htab
->tls_ld_or_ldm_got
.offset
;
3741 Elf_Internal_Rela outrel
;
3743 if (htab
->elf
.srelgot
== NULL
)
3746 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3747 + htab
->elf
.sgot
->output_offset
+ off
);
3749 bfd_put_64 (output_bfd
, 0,
3750 htab
->elf
.sgot
->contents
+ off
);
3751 bfd_put_64 (output_bfd
, 0,
3752 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3753 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
3754 outrel
.r_addend
= 0;
3755 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
3757 htab
->tls_ld_or_ldm_got
.offset
|= 1;
3759 relocation
= htab
->elf
.sgot
->output_section
->vma
3760 + htab
->elf
.sgot
->output_offset
+ off
;
3761 unresolved_reloc
= FALSE
;
3764 case R_X86_64_DTPOFF32
:
3765 if (!bfd_link_executable (info
)
3766 || (input_section
->flags
& SEC_CODE
) == 0)
3767 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3769 relocation
= elf_x86_64_tpoff (info
, relocation
);
3772 case R_X86_64_TPOFF32
:
3773 case R_X86_64_TPOFF64
:
3774 BFD_ASSERT (bfd_link_executable (info
));
3775 relocation
= elf_x86_64_tpoff (info
, relocation
);
3778 case R_X86_64_DTPOFF64
:
3779 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
3780 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
3787 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3788 because such sections are not SEC_ALLOC and thus ld.so will
3789 not process them. */
3790 if (unresolved_reloc
3791 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3793 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3794 rel
->r_offset
) != (bfd_vma
) -1)
3799 sec
= h
->root
.u
.def
.section
;
3800 if ((info
->nocopyreloc
3801 || (eh
->def_protected
3802 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
3803 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
3804 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
3805 h
, NULL
, NULL
, howto
);
3810 /* xgettext:c-format */
3811 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
3816 h
->root
.root
.string
);
3822 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3823 contents
, rel
->r_offset
,
3824 relocation
, rel
->r_addend
);
3826 check_relocation_error
:
3827 if (r
!= bfd_reloc_ok
)
3832 name
= h
->root
.root
.string
;
3835 name
= bfd_elf_string_from_elf_section (input_bfd
,
3836 symtab_hdr
->sh_link
,
3841 name
= bfd_section_name (input_bfd
, sec
);
3844 if (r
== bfd_reloc_overflow
)
3846 if (converted_reloc
)
3848 info
->callbacks
->einfo
3849 (_("%F%P: failed to convert GOTPCREL relocation; relink with --no-relax\n"));
3852 (*info
->callbacks
->reloc_overflow
)
3853 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3854 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3859 /* xgettext:c-format */
3860 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
3861 input_bfd
, input_section
,
3862 rel
->r_offset
, name
, (int) r
);
3873 Elf_Internal_Shdr
*rel_hdr
;
3874 size_t deleted
= rel
- wrel
;
3876 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
3877 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3878 if (rel_hdr
->sh_size
== 0)
3880 /* It is too late to remove an empty reloc section. Leave
3882 ??? What is wrong with an empty section??? */
3883 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
3886 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
3887 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
3888 input_section
->reloc_count
-= deleted
;
3894 /* Finish up dynamic symbol handling. We set the contents of various
3895 dynamic sections here. */
3898 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3899 struct bfd_link_info
*info
,
3900 struct elf_link_hash_entry
*h
,
3901 Elf_Internal_Sym
*sym
)
3903 struct elf_x86_link_hash_table
*htab
;
3904 bfd_boolean use_plt_second
;
3905 struct elf_x86_link_hash_entry
*eh
;
3906 bfd_boolean local_undefweak
;
3908 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
3912 /* Use the second PLT section only if there is .plt section. */
3913 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
3915 eh
= (struct elf_x86_link_hash_entry
*) h
;
3916 if (eh
->no_finish_dynamic_symbol
)
3919 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
3920 resolved undefined weak symbols in executable so that their
3921 references have value 0 at run-time. */
3922 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
3924 if (h
->plt
.offset
!= (bfd_vma
) -1)
3927 bfd_vma got_offset
, plt_offset
;
3928 Elf_Internal_Rela rela
;
3930 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
3931 const struct elf_backend_data
*bed
;
3932 bfd_vma plt_got_pcrel_offset
;
3934 /* When building a static executable, use .iplt, .igot.plt and
3935 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3936 if (htab
->elf
.splt
!= NULL
)
3938 plt
= htab
->elf
.splt
;
3939 gotplt
= htab
->elf
.sgotplt
;
3940 relplt
= htab
->elf
.srelplt
;
3944 plt
= htab
->elf
.iplt
;
3945 gotplt
= htab
->elf
.igotplt
;
3946 relplt
= htab
->elf
.irelplt
;
3949 /* This symbol has an entry in the procedure linkage table. Set
3951 if ((h
->dynindx
== -1
3953 && !((h
->forced_local
|| bfd_link_executable (info
))
3955 && h
->type
== STT_GNU_IFUNC
))
3961 /* Get the index in the procedure linkage table which
3962 corresponds to this symbol. This is the index of this symbol
3963 in all the symbols for which we are making plt entries. The
3964 first entry in the procedure linkage table is reserved.
3966 Get the offset into the .got table of the entry that
3967 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3968 bytes. The first three are reserved for the dynamic linker.
3970 For static executables, we don't reserve anything. */
3972 if (plt
== htab
->elf
.splt
)
3974 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
3975 - htab
->plt
.has_plt0
);
3976 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
3980 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
3981 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
3984 /* Fill in the entry in the procedure linkage table. */
3985 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
3986 htab
->plt
.plt_entry_size
);
3989 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
3990 htab
->non_lazy_plt
->plt_entry
,
3991 htab
->non_lazy_plt
->plt_entry_size
);
3993 resolved_plt
= htab
->plt_second
;
3994 plt_offset
= eh
->plt_second
.offset
;
3999 plt_offset
= h
->plt
.offset
;
4002 /* Insert the relocation positions of the plt section. */
4004 /* Put offset the PC-relative instruction referring to the GOT entry,
4005 subtracting the size of that instruction. */
4006 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
4007 + gotplt
->output_offset
4009 - resolved_plt
->output_section
->vma
4010 - resolved_plt
->output_offset
4012 - htab
->plt
.plt_got_insn_size
);
4014 /* Check PC-relative offset overflow in PLT entry. */
4015 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
4016 /* xgettext:c-format */
4017 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
4018 output_bfd
, h
->root
.root
.string
);
4020 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
4021 (resolved_plt
->contents
+ plt_offset
4022 + htab
->plt
.plt_got_offset
));
4024 /* Fill in the entry in the global offset table, initially this
4025 points to the second part of the PLT entry. Leave the entry
4026 as zero for undefined weak symbol in PIE. No PLT relocation
4027 against undefined weak symbol in PIE. */
4028 if (!local_undefweak
)
4030 if (htab
->plt
.has_plt0
)
4031 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4032 + plt
->output_offset
4034 + htab
->lazy_plt
->plt_lazy_offset
),
4035 gotplt
->contents
+ got_offset
);
4037 /* Fill in the entry in the .rela.plt section. */
4038 rela
.r_offset
= (gotplt
->output_section
->vma
4039 + gotplt
->output_offset
4041 if (PLT_LOCAL_IFUNC_P (info
, h
))
4043 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4044 h
->root
.root
.string
,
4045 h
->root
.u
.def
.section
->owner
);
4047 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4048 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4049 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4050 rela
.r_addend
= (h
->root
.u
.def
.value
4051 + h
->root
.u
.def
.section
->output_section
->vma
4052 + h
->root
.u
.def
.section
->output_offset
);
4053 /* R_X86_64_IRELATIVE comes last. */
4054 plt_index
= htab
->next_irelative_index
--;
4058 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4060 plt_index
= htab
->next_jump_slot_index
++;
4063 /* Don't fill the second and third slots in PLT entry for
4064 static executables nor without PLT0. */
4065 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
4068 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
4070 /* Put relocation index. */
4071 bfd_put_32 (output_bfd
, plt_index
,
4072 (plt
->contents
+ h
->plt
.offset
4073 + htab
->lazy_plt
->plt_reloc_offset
));
4075 /* Put offset for jmp .PLT0 and check for overflow. We don't
4076 check relocation index for overflow since branch displacement
4077 will overflow first. */
4078 if (plt0_offset
> 0x80000000)
4079 /* xgettext:c-format */
4080 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
4081 output_bfd
, h
->root
.root
.string
);
4082 bfd_put_32 (output_bfd
, - plt0_offset
,
4083 (plt
->contents
+ h
->plt
.offset
4084 + htab
->lazy_plt
->plt_plt_offset
));
4087 bed
= get_elf_backend_data (output_bfd
);
4088 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4089 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4092 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4094 bfd_vma got_offset
, plt_offset
;
4095 asection
*plt
, *got
;
4096 bfd_boolean got_after_plt
;
4097 int32_t got_pcrel_offset
;
4099 /* Set the entry in the GOT procedure linkage table. */
4100 plt
= htab
->plt_got
;
4101 got
= htab
->elf
.sgot
;
4102 got_offset
= h
->got
.offset
;
4104 if (got_offset
== (bfd_vma
) -1
4105 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
4110 /* Use the non-lazy PLT entry template for the GOT PLT since they
4111 are the identical. */
4112 /* Fill in the entry in the GOT procedure linkage table. */
4113 plt_offset
= eh
->plt_got
.offset
;
4114 memcpy (plt
->contents
+ plt_offset
,
4115 htab
->non_lazy_plt
->plt_entry
,
4116 htab
->non_lazy_plt
->plt_entry_size
);
4118 /* Put offset the PC-relative instruction referring to the GOT
4119 entry, subtracting the size of that instruction. */
4120 got_pcrel_offset
= (got
->output_section
->vma
4121 + got
->output_offset
4123 - plt
->output_section
->vma
4124 - plt
->output_offset
4126 - htab
->non_lazy_plt
->plt_got_insn_size
);
4128 /* Check PC-relative offset overflow in GOT PLT entry. */
4129 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
4130 if ((got_after_plt
&& got_pcrel_offset
< 0)
4131 || (!got_after_plt
&& got_pcrel_offset
> 0))
4132 /* xgettext:c-format */
4133 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
4134 output_bfd
, h
->root
.root
.string
);
4136 bfd_put_32 (output_bfd
, got_pcrel_offset
,
4137 (plt
->contents
+ plt_offset
4138 + htab
->non_lazy_plt
->plt_got_offset
));
4141 if (!local_undefweak
4143 && (h
->plt
.offset
!= (bfd_vma
) -1
4144 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
4146 /* Mark the symbol as undefined, rather than as defined in
4147 the .plt section. Leave the value if there were any
4148 relocations where pointer equality matters (this is a clue
4149 for the dynamic linker, to make function pointer
4150 comparisons work between an application and shared
4151 library), otherwise set it to zero. If a function is only
4152 called from a binary, there is no need to slow down
4153 shared libraries because of that. */
4154 sym
->st_shndx
= SHN_UNDEF
;
4155 if (!h
->pointer_equality_needed
)
4159 /* Don't generate dynamic GOT relocation against undefined weak
4160 symbol in executable. */
4161 if (h
->got
.offset
!= (bfd_vma
) -1
4162 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
4163 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
4164 && !local_undefweak
)
4166 Elf_Internal_Rela rela
;
4167 asection
*relgot
= htab
->elf
.srelgot
;
4169 /* This symbol has an entry in the global offset table. Set it
4171 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4174 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4175 + htab
->elf
.sgot
->output_offset
4176 + (h
->got
.offset
&~ (bfd_vma
) 1));
4178 /* If this is a static link, or it is a -Bsymbolic link and the
4179 symbol is defined locally or was forced to be local because
4180 of a version file, we just want to emit a RELATIVE reloc.
4181 The entry in the global offset table will already have been
4182 initialized in the relocate_section function. */
4184 && h
->type
== STT_GNU_IFUNC
)
4186 if (h
->plt
.offset
== (bfd_vma
) -1)
4188 /* STT_GNU_IFUNC is referenced without PLT. */
4189 if (htab
->elf
.splt
== NULL
)
4191 /* use .rel[a].iplt section to store .got relocations
4192 in static executable. */
4193 relgot
= htab
->elf
.irelplt
;
4195 if (SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4197 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4198 h
->root
.root
.string
,
4199 h
->root
.u
.def
.section
->owner
);
4201 rela
.r_info
= htab
->r_info (0,
4202 R_X86_64_IRELATIVE
);
4203 rela
.r_addend
= (h
->root
.u
.def
.value
4204 + h
->root
.u
.def
.section
->output_section
->vma
4205 + h
->root
.u
.def
.section
->output_offset
);
4210 else if (bfd_link_pic (info
))
4212 /* Generate R_X86_64_GLOB_DAT. */
4220 if (!h
->pointer_equality_needed
)
4223 /* For non-shared object, we can't use .got.plt, which
4224 contains the real function addres if we need pointer
4225 equality. We load the GOT entry with the PLT entry. */
4226 if (htab
->plt_second
!= NULL
)
4228 plt
= htab
->plt_second
;
4229 plt_offset
= eh
->plt_second
.offset
;
4233 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4234 plt_offset
= h
->plt
.offset
;
4236 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4237 + plt
->output_offset
4239 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4243 else if (bfd_link_pic (info
)
4244 && SYMBOL_REFERENCES_LOCAL_P (info
, h
))
4246 if (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
4248 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4249 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4250 rela
.r_addend
= (h
->root
.u
.def
.value
4251 + h
->root
.u
.def
.section
->output_section
->vma
4252 + h
->root
.u
.def
.section
->output_offset
);
4256 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4258 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4259 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4260 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4264 elf_append_rela (output_bfd
, relgot
, &rela
);
4269 Elf_Internal_Rela rela
;
4272 /* This symbol needs a copy reloc. Set it up. */
4274 if (h
->dynindx
== -1
4275 || (h
->root
.type
!= bfd_link_hash_defined
4276 && h
->root
.type
!= bfd_link_hash_defweak
)
4277 || htab
->elf
.srelbss
== NULL
4278 || htab
->elf
.sreldynrelro
== NULL
)
4281 rela
.r_offset
= (h
->root
.u
.def
.value
4282 + h
->root
.u
.def
.section
->output_section
->vma
4283 + h
->root
.u
.def
.section
->output_offset
);
4284 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4286 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
4287 s
= htab
->elf
.sreldynrelro
;
4289 s
= htab
->elf
.srelbss
;
4290 elf_append_rela (output_bfd
, s
, &rela
);
4296 /* Finish up local dynamic symbol handling. We set the contents of
4297 various dynamic sections here. */
4300 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4302 struct elf_link_hash_entry
*h
4303 = (struct elf_link_hash_entry
*) *slot
;
4304 struct bfd_link_info
*info
4305 = (struct bfd_link_info
*) inf
;
4307 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4311 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4312 here since undefined weak symbol may not be dynamic and may not be
4313 called for elf_x86_64_finish_dynamic_symbol. */
4316 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
4319 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
4320 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4322 if (h
->root
.type
!= bfd_link_hash_undefweak
4323 || h
->dynindx
!= -1)
4326 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4330 /* Used to decide how to sort relocs in an optimal manner for the
4331 dynamic linker, before writing them out. */
4333 static enum elf_reloc_type_class
4334 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
4335 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4336 const Elf_Internal_Rela
*rela
)
4338 bfd
*abfd
= info
->output_bfd
;
4339 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4340 struct elf_x86_link_hash_table
*htab
4341 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4343 if (htab
->elf
.dynsym
!= NULL
4344 && htab
->elf
.dynsym
->contents
!= NULL
)
4346 /* Check relocation against STT_GNU_IFUNC symbol if there are
4348 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
4349 if (r_symndx
!= STN_UNDEF
)
4351 Elf_Internal_Sym sym
;
4352 if (!bed
->s
->swap_symbol_in (abfd
,
4353 (htab
->elf
.dynsym
->contents
4354 + r_symndx
* bed
->s
->sizeof_sym
),
4358 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
4359 return reloc_class_ifunc
;
4363 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4365 case R_X86_64_IRELATIVE
:
4366 return reloc_class_ifunc
;
4367 case R_X86_64_RELATIVE
:
4368 case R_X86_64_RELATIVE64
:
4369 return reloc_class_relative
;
4370 case R_X86_64_JUMP_SLOT
:
4371 return reloc_class_plt
;
4373 return reloc_class_copy
;
4375 return reloc_class_normal
;
4379 /* Finish up the dynamic sections. */
4382 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4383 struct bfd_link_info
*info
)
4385 struct elf_x86_link_hash_table
*htab
;
4389 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4393 dynobj
= htab
->elf
.dynobj
;
4394 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4396 if (htab
->elf
.dynamic_sections_created
)
4398 bfd_byte
*dyncon
, *dynconend
;
4399 const struct elf_backend_data
*bed
;
4400 bfd_size_type sizeof_dyn
;
4402 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4405 bed
= get_elf_backend_data (dynobj
);
4406 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4407 dyncon
= sdyn
->contents
;
4408 dynconend
= sdyn
->contents
+ sdyn
->size
;
4409 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4411 Elf_Internal_Dyn dyn
;
4414 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4422 s
= htab
->elf
.sgotplt
;
4423 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4427 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4431 s
= htab
->elf
.srelplt
->output_section
;
4432 dyn
.d_un
.d_val
= s
->size
;
4435 case DT_TLSDESC_PLT
:
4437 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4438 + htab
->tlsdesc_plt
;
4441 case DT_TLSDESC_GOT
:
4443 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4444 + htab
->tlsdesc_got
;
4448 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4451 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4453 elf_section_data (htab
->elf
.splt
->output_section
)
4454 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
4456 if (htab
->plt
.has_plt0
)
4458 /* Fill in the special first entry in the procedure linkage
4460 memcpy (htab
->elf
.splt
->contents
,
4461 htab
->lazy_plt
->plt0_entry
,
4462 htab
->lazy_plt
->plt0_entry_size
);
4463 /* Add offset for pushq GOT+8(%rip), since the instruction
4464 uses 6 bytes subtract this value. */
4465 bfd_put_32 (output_bfd
,
4466 (htab
->elf
.sgotplt
->output_section
->vma
4467 + htab
->elf
.sgotplt
->output_offset
4469 - htab
->elf
.splt
->output_section
->vma
4470 - htab
->elf
.splt
->output_offset
4472 (htab
->elf
.splt
->contents
4473 + htab
->lazy_plt
->plt0_got1_offset
));
4474 /* Add offset for the PC-relative instruction accessing
4475 GOT+16, subtracting the offset to the end of that
4477 bfd_put_32 (output_bfd
,
4478 (htab
->elf
.sgotplt
->output_section
->vma
4479 + htab
->elf
.sgotplt
->output_offset
4481 - htab
->elf
.splt
->output_section
->vma
4482 - htab
->elf
.splt
->output_offset
4483 - htab
->lazy_plt
->plt0_got2_insn_end
),
4484 (htab
->elf
.splt
->contents
4485 + htab
->lazy_plt
->plt0_got2_offset
));
4487 if (htab
->tlsdesc_plt
)
4489 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4490 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4492 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4493 htab
->lazy_plt
->plt0_entry
,
4494 htab
->lazy_plt
->plt0_entry_size
);
4496 /* Add offset for pushq GOT+8(%rip), since the
4497 instruction uses 6 bytes subtract this value. */
4498 bfd_put_32 (output_bfd
,
4499 (htab
->elf
.sgotplt
->output_section
->vma
4500 + htab
->elf
.sgotplt
->output_offset
4502 - htab
->elf
.splt
->output_section
->vma
4503 - htab
->elf
.splt
->output_offset
4506 (htab
->elf
.splt
->contents
4508 + htab
->lazy_plt
->plt0_got1_offset
));
4509 /* Add offset for the PC-relative instruction accessing
4510 GOT+TDG, where TDG stands for htab->tlsdesc_got,
4511 subtracting the offset to the end of that
4513 bfd_put_32 (output_bfd
,
4514 (htab
->elf
.sgot
->output_section
->vma
4515 + htab
->elf
.sgot
->output_offset
4517 - htab
->elf
.splt
->output_section
->vma
4518 - htab
->elf
.splt
->output_offset
4520 - htab
->lazy_plt
->plt0_got2_insn_end
),
4521 (htab
->elf
.splt
->contents
4523 + htab
->lazy_plt
->plt0_got2_offset
));
4528 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
4529 elf_section_data (htab
->plt_got
->output_section
)
4530 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4532 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
4533 elf_section_data (htab
->plt_second
->output_section
)
4534 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
4537 /* GOT is always created in setup_gnu_properties. But it may not be
4539 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
4541 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4544 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4548 /* Set the first entry in the global offset table to the address of
4549 the dynamic section. */
4551 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4553 bfd_put_64 (output_bfd
,
4554 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4555 htab
->elf
.sgotplt
->contents
);
4556 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4557 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4558 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4559 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4560 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4562 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
4566 /* Adjust .eh_frame for .plt section. */
4567 if (htab
->plt_eh_frame
!= NULL
4568 && htab
->plt_eh_frame
->contents
!= NULL
)
4570 if (htab
->elf
.splt
!= NULL
4571 && htab
->elf
.splt
->size
!= 0
4572 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4573 && htab
->elf
.splt
->output_section
!= NULL
4574 && htab
->plt_eh_frame
->output_section
!= NULL
)
4576 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4577 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4578 + htab
->plt_eh_frame
->output_offset
4579 + PLT_FDE_START_OFFSET
;
4580 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4581 htab
->plt_eh_frame
->contents
4582 + PLT_FDE_START_OFFSET
);
4584 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4586 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4588 htab
->plt_eh_frame
->contents
))
4593 /* Adjust .eh_frame for .plt.got section. */
4594 if (htab
->plt_got_eh_frame
!= NULL
4595 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4597 if (htab
->plt_got
!= NULL
4598 && htab
->plt_got
->size
!= 0
4599 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
4600 && htab
->plt_got
->output_section
!= NULL
4601 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
4603 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
4604 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
4605 + htab
->plt_got_eh_frame
->output_offset
4606 + PLT_FDE_START_OFFSET
;
4607 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4608 htab
->plt_got_eh_frame
->contents
4609 + PLT_FDE_START_OFFSET
);
4611 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
4613 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4614 htab
->plt_got_eh_frame
,
4615 htab
->plt_got_eh_frame
->contents
))
4620 /* Adjust .eh_frame for the second PLT section. */
4621 if (htab
->plt_second_eh_frame
!= NULL
4622 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4624 if (htab
->plt_second
!= NULL
4625 && htab
->plt_second
->size
!= 0
4626 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
4627 && htab
->plt_second
->output_section
!= NULL
4628 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
4630 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
4631 bfd_vma eh_frame_start
4632 = (htab
->plt_second_eh_frame
->output_section
->vma
4633 + htab
->plt_second_eh_frame
->output_offset
4634 + PLT_FDE_START_OFFSET
);
4635 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4636 htab
->plt_second_eh_frame
->contents
4637 + PLT_FDE_START_OFFSET
);
4639 if (htab
->plt_second_eh_frame
->sec_info_type
4640 == SEC_INFO_TYPE_EH_FRAME
)
4642 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4643 htab
->plt_second_eh_frame
,
4644 htab
->plt_second_eh_frame
->contents
))
4649 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4650 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4653 /* Fill PLT entries for undefined weak symbols in PIE. */
4654 if (bfd_link_pie (info
))
4655 bfd_hash_traverse (&info
->hash
->table
,
4656 elf_x86_64_pie_finish_undefweak_symbol
,
4662 /* Fill PLT/GOT entries and allocate dynamic relocations for local
4663 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
4664 It has to be done before elf_link_sort_relocs is called so that
4665 dynamic relocations are properly sorted. */
4668 elf_x86_64_output_arch_local_syms
4669 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4670 struct bfd_link_info
*info
,
4671 void *flaginfo ATTRIBUTE_UNUSED
,
4672 int (*func
) (void *, const char *,
4675 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
4677 struct elf_x86_link_hash_table
*htab
4678 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
4682 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4683 htab_traverse (htab
->loc_hash_table
,
4684 elf_x86_64_finish_local_dynamic_symbol
,
4690 /* Forward declaration. */
4691 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
;
4693 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
4694 dynamic relocations. */
4697 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
4698 long symcount ATTRIBUTE_UNUSED
,
4699 asymbol
**syms ATTRIBUTE_UNUSED
,
4706 bfd_byte
*plt_contents
;
4708 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
4709 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
4710 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
4711 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
4712 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
4713 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
4715 enum elf_x86_plt_type plt_type
;
4716 struct elf_x86_plt plts
[] =
4718 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
4719 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
4720 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4721 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
4722 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
4727 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
4730 if (dynsymcount
<= 0)
4733 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4737 if (get_elf_x86_64_backend_data (abfd
)->os
== is_normal
)
4739 lazy_plt
= &elf_x86_64_lazy_plt
;
4740 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
4741 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
4742 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
4743 if (ABI_64_P (abfd
))
4745 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
4746 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
4750 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
4751 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
4756 lazy_plt
= &elf_x86_64_nacl_plt
;
4757 non_lazy_plt
= NULL
;
4758 lazy_bnd_plt
= NULL
;
4759 non_lazy_bnd_plt
= NULL
;
4760 lazy_ibt_plt
= NULL
;
4761 non_lazy_ibt_plt
= NULL
;
4765 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
4767 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
4768 if (plt
== NULL
|| plt
->size
== 0)
4771 /* Get the PLT section contents. */
4772 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
4773 if (plt_contents
== NULL
)
4775 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
4776 plt_contents
, 0, plt
->size
))
4778 free (plt_contents
);
4782 /* Check what kind of PLT it is. */
4783 plt_type
= plt_unknown
;
4784 if (plts
[j
].type
== plt_unknown
4785 && (plt
->size
>= (lazy_plt
->plt_entry_size
4786 + lazy_plt
->plt_entry_size
)))
4788 /* Match lazy PLT first. Need to check the first two
4790 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
4791 lazy_plt
->plt0_got1_offset
) == 0)
4792 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
4794 plt_type
= plt_lazy
;
4795 else if (lazy_bnd_plt
!= NULL
4796 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
4797 lazy_bnd_plt
->plt0_got1_offset
) == 0)
4798 && (memcmp (plt_contents
+ 6,
4799 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
4801 plt_type
= plt_lazy
| plt_second
;
4802 /* The fist entry in the lazy IBT PLT is the same as the
4804 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
4805 lazy_ibt_plt
->plt_entry
,
4806 lazy_ibt_plt
->plt_got_offset
) == 0))
4807 lazy_plt
= lazy_ibt_plt
;
4809 lazy_plt
= lazy_bnd_plt
;
4813 if (non_lazy_plt
!= NULL
4814 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
4815 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
4817 /* Match non-lazy PLT. */
4818 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
4819 non_lazy_plt
->plt_got_offset
) == 0)
4820 plt_type
= plt_non_lazy
;
4823 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
4825 if (non_lazy_bnd_plt
!= NULL
4826 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
4827 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
4828 non_lazy_bnd_plt
->plt_got_offset
) == 0))
4830 /* Match BND PLT. */
4831 plt_type
= plt_second
;
4832 non_lazy_plt
= non_lazy_bnd_plt
;
4834 else if (non_lazy_ibt_plt
!= NULL
4835 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
4836 && (memcmp (plt_contents
,
4837 non_lazy_ibt_plt
->plt_entry
,
4838 non_lazy_ibt_plt
->plt_got_offset
) == 0))
4840 /* Match IBT PLT. */
4841 plt_type
= plt_second
;
4842 non_lazy_plt
= non_lazy_ibt_plt
;
4846 if (plt_type
== plt_unknown
)
4848 free (plt_contents
);
4853 plts
[j
].type
= plt_type
;
4855 if ((plt_type
& plt_lazy
))
4857 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
4858 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
4859 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
4860 /* Skip PLT0 in lazy PLT. */
4865 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
4866 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
4867 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
4871 /* Skip lazy PLT when the second PLT is used. */
4872 if (plt_type
== (plt_lazy
| plt_second
))
4876 n
= plt
->size
/ plts
[j
].plt_entry_size
;
4881 plts
[j
].contents
= plt_contents
;
4884 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
4885 (bfd_vma
) 0, plts
, dynsyms
,
4889 /* Handle an x86-64 specific section when reading an object file. This
4890 is called when elfcode.h finds a section with an unknown type. */
4893 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
4894 const char *name
, int shindex
)
4896 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4899 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4905 /* Hook called by the linker routine which adds symbols from an object
4906 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4910 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4911 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4912 Elf_Internal_Sym
*sym
,
4913 const char **namep ATTRIBUTE_UNUSED
,
4914 flagword
*flagsp ATTRIBUTE_UNUSED
,
4920 switch (sym
->st_shndx
)
4922 case SHN_X86_64_LCOMMON
:
4923 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4926 lcomm
= bfd_make_section_with_flags (abfd
,
4930 | SEC_LINKER_CREATED
));
4933 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4936 *valp
= sym
->st_size
;
4944 /* Given a BFD section, try to locate the corresponding ELF section
4948 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4949 asection
*sec
, int *index_return
)
4951 if (sec
== &_bfd_elf_large_com_section
)
4953 *index_return
= SHN_X86_64_LCOMMON
;
4959 /* Process a symbol. */
4962 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4965 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4967 switch (elfsym
->internal_elf_sym
.st_shndx
)
4969 case SHN_X86_64_LCOMMON
:
4970 asym
->section
= &_bfd_elf_large_com_section
;
4971 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4972 /* Common symbol doesn't set BSF_GLOBAL. */
4973 asym
->flags
&= ~BSF_GLOBAL
;
4979 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4981 return (sym
->st_shndx
== SHN_COMMON
4982 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4986 elf_x86_64_common_section_index (asection
*sec
)
4988 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4991 return SHN_X86_64_LCOMMON
;
4995 elf_x86_64_common_section (asection
*sec
)
4997 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4998 return bfd_com_section_ptr
;
5000 return &_bfd_elf_large_com_section
;
5004 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
5005 const Elf_Internal_Sym
*sym
,
5010 const asection
*oldsec
)
5012 /* A normal common symbol and a large common symbol result in a
5013 normal common symbol. We turn the large common symbol into a
5016 && h
->root
.type
== bfd_link_hash_common
5018 && bfd_is_com_section (*psec
)
5021 if (sym
->st_shndx
== SHN_COMMON
5022 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
5024 h
->root
.u
.c
.p
->section
5025 = bfd_make_section_old_way (oldbfd
, "COMMON");
5026 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
5028 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
5029 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
5030 *psec
= bfd_com_section_ptr
;
5037 elf_x86_64_additional_program_headers (bfd
*abfd
,
5038 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
5043 /* Check to see if we need a large readonly segment. */
5044 s
= bfd_get_section_by_name (abfd
, ".lrodata");
5045 if (s
&& (s
->flags
& SEC_LOAD
))
5048 /* Check to see if we need a large data segment. Since .lbss sections
5049 is placed right after the .bss section, there should be no need for
5050 a large data segment just because of .lbss. */
5051 s
= bfd_get_section_by_name (abfd
, ".ldata");
5052 if (s
&& (s
->flags
& SEC_LOAD
))
5058 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
5061 elf_x86_64_relocs_compatible (const bfd_target
*input
,
5062 const bfd_target
*output
)
5064 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
5065 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
5066 && _bfd_elf_relocs_compatible (input
, output
));
5069 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
5070 with GNU properties if found. Otherwise, return NULL. */
5073 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
5075 struct elf_x86_init_table init_table
;
5077 if ((int) R_X86_64_standard
>= (int) R_X86_64_converted_reloc_bit
5078 || (int) R_X86_64_max
<= (int) R_X86_64_converted_reloc_bit
5079 || ((int) (R_X86_64_GNU_VTINHERIT
| R_X86_64_converted_reloc_bit
)
5080 != (int) R_X86_64_GNU_VTINHERIT
)
5081 || ((int) (R_X86_64_GNU_VTENTRY
| R_X86_64_converted_reloc_bit
)
5082 != (int) R_X86_64_GNU_VTENTRY
))
5085 init_table
.is_vxworks
= FALSE
;
5086 if (get_elf_x86_64_backend_data (info
->output_bfd
)->os
== is_normal
)
5090 init_table
.lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
5091 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
5095 init_table
.lazy_plt
= &elf_x86_64_lazy_plt
;
5096 init_table
.non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
5099 if (ABI_64_P (info
->output_bfd
))
5101 init_table
.lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
5102 init_table
.non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
5106 init_table
.lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
5107 init_table
.non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
5109 init_table
.normal_target
= TRUE
;
5113 init_table
.lazy_plt
= &elf_x86_64_nacl_plt
;
5114 init_table
.non_lazy_plt
= NULL
;
5115 init_table
.lazy_ibt_plt
= NULL
;
5116 init_table
.non_lazy_ibt_plt
= NULL
;
5117 init_table
.normal_target
= FALSE
;
5120 if (ABI_64_P (info
->output_bfd
))
5122 init_table
.r_info
= elf64_r_info
;
5123 init_table
.r_sym
= elf64_r_sym
;
5127 init_table
.r_info
= elf32_r_info
;
5128 init_table
.r_sym
= elf32_r_sym
;
5131 return _bfd_x86_elf_link_setup_gnu_properties (info
, &init_table
);
5134 static const struct bfd_elf_special_section
5135 elf_x86_64_special_sections
[]=
5137 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5138 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5139 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
5140 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5141 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
5142 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
5143 { NULL
, 0, 0, 0, 0 }
5146 #define TARGET_LITTLE_SYM x86_64_elf64_vec
5147 #define TARGET_LITTLE_NAME "elf64-x86-64"
5148 #define ELF_ARCH bfd_arch_i386
5149 #define ELF_TARGET_ID X86_64_ELF_DATA
5150 #define ELF_MACHINE_CODE EM_X86_64
5151 #define ELF_MAXPAGESIZE 0x200000
5152 #define ELF_MINPAGESIZE 0x1000
5153 #define ELF_COMMONPAGESIZE 0x1000
5155 #define elf_backend_can_gc_sections 1
5156 #define elf_backend_can_refcount 1
5157 #define elf_backend_want_got_plt 1
5158 #define elf_backend_plt_readonly 1
5159 #define elf_backend_want_plt_sym 0
5160 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
5161 #define elf_backend_rela_normal 1
5162 #define elf_backend_plt_alignment 4
5163 #define elf_backend_extern_protected_data 1
5164 #define elf_backend_caches_rawsize 1
5165 #define elf_backend_dtrel_excludes_plt 1
5166 #define elf_backend_want_dynrelro 1
5168 #define elf_info_to_howto elf_x86_64_info_to_howto
5170 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5171 #define bfd_elf64_bfd_reloc_name_lookup \
5172 elf_x86_64_reloc_name_lookup
5174 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5175 #define elf_backend_check_relocs elf_x86_64_check_relocs
5176 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5177 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5178 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5179 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
5180 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5181 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5183 #define elf_backend_write_core_note elf_x86_64_write_core_note
5185 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5186 #define elf_backend_relocate_section elf_x86_64_relocate_section
5187 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5188 #define elf_backend_object_p elf64_x86_64_elf_object_p
5189 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
5191 #define elf_backend_section_from_shdr \
5192 elf_x86_64_section_from_shdr
5194 #define elf_backend_section_from_bfd_section \
5195 elf_x86_64_elf_section_from_bfd_section
5196 #define elf_backend_add_symbol_hook \
5197 elf_x86_64_add_symbol_hook
5198 #define elf_backend_symbol_processing \
5199 elf_x86_64_symbol_processing
5200 #define elf_backend_common_section_index \
5201 elf_x86_64_common_section_index
5202 #define elf_backend_common_section \
5203 elf_x86_64_common_section
5204 #define elf_backend_common_definition \
5205 elf_x86_64_common_definition
5206 #define elf_backend_merge_symbol \
5207 elf_x86_64_merge_symbol
5208 #define elf_backend_special_sections \
5209 elf_x86_64_special_sections
5210 #define elf_backend_additional_program_headers \
5211 elf_x86_64_additional_program_headers
5212 #define elf_backend_setup_gnu_properties \
5213 elf_x86_64_link_setup_gnu_properties
5215 #include "elf64-target.h"
5217 /* CloudABI support. */
5219 #undef TARGET_LITTLE_SYM
5220 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
5221 #undef TARGET_LITTLE_NAME
5222 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
5225 #define ELF_OSABI ELFOSABI_CLOUDABI
5228 #define elf64_bed elf64_x86_64_cloudabi_bed
5230 #include "elf64-target.h"
5232 /* FreeBSD support. */
5234 #undef TARGET_LITTLE_SYM
5235 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
5236 #undef TARGET_LITTLE_NAME
5237 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5240 #define ELF_OSABI ELFOSABI_FREEBSD
5243 #define elf64_bed elf64_x86_64_fbsd_bed
5245 #include "elf64-target.h"
5247 /* Solaris 2 support. */
5249 #undef TARGET_LITTLE_SYM
5250 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
5251 #undef TARGET_LITTLE_NAME
5252 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5254 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5255 objects won't be recognized. */
5259 #define elf64_bed elf64_x86_64_sol2_bed
5261 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5263 #undef elf_backend_static_tls_alignment
5264 #define elf_backend_static_tls_alignment 16
5266 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5268 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5270 #undef elf_backend_want_plt_sym
5271 #define elf_backend_want_plt_sym 1
5273 #undef elf_backend_strtab_flags
5274 #define elf_backend_strtab_flags SHF_STRINGS
5277 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
5278 bfd
*obfd ATTRIBUTE_UNUSED
,
5279 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
5280 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
5282 /* PR 19938: FIXME: Need to add code for setting the sh_info
5283 and sh_link fields of Solaris specific section types. */
5287 #undef elf_backend_copy_special_section_fields
5288 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
5290 #include "elf64-target.h"
5292 /* Native Client support. */
5295 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
5297 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
5298 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
5302 #undef TARGET_LITTLE_SYM
5303 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
5304 #undef TARGET_LITTLE_NAME
5305 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5307 #define elf64_bed elf64_x86_64_nacl_bed
5309 #undef ELF_MAXPAGESIZE
5310 #undef ELF_MINPAGESIZE
5311 #undef ELF_COMMONPAGESIZE
5312 #define ELF_MAXPAGESIZE 0x10000
5313 #define ELF_MINPAGESIZE 0x10000
5314 #define ELF_COMMONPAGESIZE 0x10000
5316 /* Restore defaults. */
5318 #undef elf_backend_static_tls_alignment
5319 #undef elf_backend_want_plt_sym
5320 #define elf_backend_want_plt_sym 0
5321 #undef elf_backend_strtab_flags
5322 #undef elf_backend_copy_special_section_fields
5324 /* NaCl uses substantially different PLT entries for the same effects. */
5326 #undef elf_backend_plt_alignment
5327 #define elf_backend_plt_alignment 5
5328 #define NACL_PLT_ENTRY_SIZE 64
5329 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5331 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
5333 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5334 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5335 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5336 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5337 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5339 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
5340 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
5342 /* 32 bytes of nop to pad out to the standard size. */
5343 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5344 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5345 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5346 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5347 0x66, /* excess data16 prefix */
5351 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5353 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5354 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5355 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5356 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5358 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5359 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5360 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5362 /* Lazy GOT entries point here (32-byte aligned). */
5363 0x68, /* pushq immediate */
5364 0, 0, 0, 0, /* replaced with index into relocation table. */
5365 0xe9, /* jmp relative */
5366 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5368 /* 22 bytes of nop to pad out to the standard size. */
5369 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
5370 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5371 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5374 /* .eh_frame covering the .plt section. */
5376 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
5378 #if (PLT_CIE_LENGTH != 20 \
5379 || PLT_FDE_LENGTH != 36 \
5380 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5381 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5382 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5384 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5385 0, 0, 0, 0, /* CIE ID */
5386 1, /* CIE version */
5387 'z', 'R', 0, /* Augmentation string */
5388 1, /* Code alignment factor */
5389 0x78, /* Data alignment factor */
5390 16, /* Return address column */
5391 1, /* Augmentation size */
5392 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5393 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5394 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5395 DW_CFA_nop
, DW_CFA_nop
,
5397 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5398 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
5399 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5400 0, 0, 0, 0, /* .plt size goes here */
5401 0, /* Augmentation size */
5402 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
5403 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5404 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
5405 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5406 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5407 13, /* Block length */
5408 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
5409 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
5410 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5411 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
5412 DW_CFA_nop
, DW_CFA_nop
5415 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
=
5417 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
5418 NACL_PLT_ENTRY_SIZE
, /* plt0_entry_size */
5419 elf_x86_64_nacl_plt_entry
, /* plt_entry */
5420 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5421 2, /* plt0_got1_offset */
5422 9, /* plt0_got2_offset */
5423 13, /* plt0_got2_insn_end */
5424 3, /* plt_got_offset */
5425 33, /* plt_reloc_offset */
5426 38, /* plt_plt_offset */
5427 7, /* plt_got_insn_size */
5428 42, /* plt_plt_insn_end */
5429 32, /* plt_lazy_offset */
5430 elf_x86_64_nacl_plt0_entry
, /* pic_plt0_entry */
5431 elf_x86_64_nacl_plt_entry
, /* pic_plt_entry */
5432 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
5433 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
5436 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
5441 #undef elf_backend_arch_data
5442 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5444 #undef elf_backend_object_p
5445 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
5446 #undef elf_backend_modify_segment_map
5447 #define elf_backend_modify_segment_map nacl_modify_segment_map
5448 #undef elf_backend_modify_program_headers
5449 #define elf_backend_modify_program_headers nacl_modify_program_headers
5450 #undef elf_backend_final_write_processing
5451 #define elf_backend_final_write_processing nacl_final_write_processing
5453 #include "elf64-target.h"
5455 /* Native Client x32 support. */
5458 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
5460 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
5461 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
5465 #undef TARGET_LITTLE_SYM
5466 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
5467 #undef TARGET_LITTLE_NAME
5468 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5470 #define elf32_bed elf32_x86_64_nacl_bed
5472 #define bfd_elf32_bfd_reloc_type_lookup \
5473 elf_x86_64_reloc_type_lookup
5474 #define bfd_elf32_bfd_reloc_name_lookup \
5475 elf_x86_64_reloc_name_lookup
5476 #define bfd_elf32_get_synthetic_symtab \
5477 elf_x86_64_get_synthetic_symtab
5479 #undef elf_backend_object_p
5480 #define elf_backend_object_p \
5481 elf32_x86_64_nacl_elf_object_p
5483 #undef elf_backend_bfd_from_remote_memory
5484 #define elf_backend_bfd_from_remote_memory \
5485 _bfd_elf32_bfd_from_remote_memory
5487 #undef elf_backend_size_info
5488 #define elf_backend_size_info \
5489 _bfd_elf32_size_info
5491 #include "elf32-target.h"
5493 /* Restore defaults. */
5494 #undef elf_backend_object_p
5495 #define elf_backend_object_p elf64_x86_64_elf_object_p
5496 #undef elf_backend_bfd_from_remote_memory
5497 #undef elf_backend_size_info
5498 #undef elf_backend_modify_segment_map
5499 #undef elf_backend_modify_program_headers
5500 #undef elf_backend_final_write_processing
5502 /* Intel L1OM support. */
5505 elf64_l1om_elf_object_p (bfd
*abfd
)
5507 /* Set the right machine number for an L1OM elf64 file. */
5508 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5512 #undef TARGET_LITTLE_SYM
5513 #define TARGET_LITTLE_SYM l1om_elf64_vec
5514 #undef TARGET_LITTLE_NAME
5515 #define TARGET_LITTLE_NAME "elf64-l1om"
5517 #define ELF_ARCH bfd_arch_l1om
5519 #undef ELF_MACHINE_CODE
5520 #define ELF_MACHINE_CODE EM_L1OM
5525 #define elf64_bed elf64_l1om_bed
5527 #undef elf_backend_object_p
5528 #define elf_backend_object_p elf64_l1om_elf_object_p
5530 /* Restore defaults. */
5531 #undef ELF_MAXPAGESIZE
5532 #undef ELF_MINPAGESIZE
5533 #undef ELF_COMMONPAGESIZE
5534 #define ELF_MAXPAGESIZE 0x200000
5535 #define ELF_MINPAGESIZE 0x1000
5536 #define ELF_COMMONPAGESIZE 0x1000
5537 #undef elf_backend_plt_alignment
5538 #define elf_backend_plt_alignment 4
5539 #undef elf_backend_arch_data
5540 #define elf_backend_arch_data &elf_x86_64_arch_bed
5542 #include "elf64-target.h"
5544 /* FreeBSD L1OM support. */
5546 #undef TARGET_LITTLE_SYM
5547 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
5548 #undef TARGET_LITTLE_NAME
5549 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5552 #define ELF_OSABI ELFOSABI_FREEBSD
5555 #define elf64_bed elf64_l1om_fbsd_bed
5557 #include "elf64-target.h"
5559 /* Intel K1OM support. */
5562 elf64_k1om_elf_object_p (bfd
*abfd
)
5564 /* Set the right machine number for an K1OM elf64 file. */
5565 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5569 #undef TARGET_LITTLE_SYM
5570 #define TARGET_LITTLE_SYM k1om_elf64_vec
5571 #undef TARGET_LITTLE_NAME
5572 #define TARGET_LITTLE_NAME "elf64-k1om"
5574 #define ELF_ARCH bfd_arch_k1om
5576 #undef ELF_MACHINE_CODE
5577 #define ELF_MACHINE_CODE EM_K1OM
5582 #define elf64_bed elf64_k1om_bed
5584 #undef elf_backend_object_p
5585 #define elf_backend_object_p elf64_k1om_elf_object_p
5587 #undef elf_backend_static_tls_alignment
5589 #undef elf_backend_want_plt_sym
5590 #define elf_backend_want_plt_sym 0
5592 #include "elf64-target.h"
5594 /* FreeBSD K1OM support. */
5596 #undef TARGET_LITTLE_SYM
5597 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
5598 #undef TARGET_LITTLE_NAME
5599 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5602 #define ELF_OSABI ELFOSABI_FREEBSD
5605 #define elf64_bed elf64_k1om_fbsd_bed
5607 #include "elf64-target.h"
5609 /* 32bit x86-64 support. */
5611 #undef TARGET_LITTLE_SYM
5612 #define TARGET_LITTLE_SYM x86_64_elf32_vec
5613 #undef TARGET_LITTLE_NAME
5614 #define TARGET_LITTLE_NAME "elf32-x86-64"
5618 #define ELF_ARCH bfd_arch_i386
5620 #undef ELF_MACHINE_CODE
5621 #define ELF_MACHINE_CODE EM_X86_64
5625 #undef elf_backend_object_p
5626 #define elf_backend_object_p \
5627 elf32_x86_64_elf_object_p
5629 #undef elf_backend_bfd_from_remote_memory
5630 #define elf_backend_bfd_from_remote_memory \
5631 _bfd_elf32_bfd_from_remote_memory
5633 #undef elf_backend_size_info
5634 #define elf_backend_size_info \
5635 _bfd_elf32_size_info
5637 #include "elf32-target.h"