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. */
28 #include "bfd_stdint.h"
32 #include "libiberty.h"
34 #include "opcode/i386.h"
35 #include "elf/x86-64.h"
42 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
43 #define MINUS_ONE (~ (bfd_vma) 0)
45 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
46 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
47 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
48 since they are the same. */
50 #define ABI_64_P(abfd) \
51 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
53 /* The relocation "howto" table. Order of fields:
54 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
55 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
56 static reloc_howto_type x86_64_elf_howto_table
[] =
58 HOWTO(R_X86_64_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
59 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
61 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
64 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
65 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
67 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
71 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
74 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
79 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
82 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
85 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
86 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
88 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
89 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
91 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
92 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
94 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
96 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
98 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
100 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
102 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
105 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
108 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
111 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
112 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
114 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
115 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
117 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
118 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
120 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
121 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
123 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
124 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
126 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
129 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
131 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
132 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
133 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
134 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
135 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
136 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
138 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
139 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
141 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
142 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
143 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
144 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
145 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
147 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
148 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
150 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
151 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
153 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
154 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
156 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
157 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
158 "R_X86_64_GOTPC32_TLSDESC",
159 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
160 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
161 complain_overflow_dont
, bfd_elf_generic_reloc
,
162 "R_X86_64_TLSDESC_CALL",
164 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
165 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
167 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
168 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
169 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
171 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
172 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
174 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
175 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
177 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
178 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
180 HOWTO(R_X86_64_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
181 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", FALSE
, 0xffffffff,
183 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
184 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", FALSE
, 0xffffffff,
187 /* We have a gap in the reloc numbers here.
188 R_X86_64_standard counts the number up to this point, and
189 R_X86_64_vt_offset is the value to subtract from a reloc type of
190 R_X86_64_GNU_VT* to form an index into this table. */
191 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
192 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
194 /* GNU extension to record C++ vtable hierarchy. */
195 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
196 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
198 /* GNU extension to record C++ vtable member usage. */
199 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
200 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
203 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
204 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
205 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
209 #define IS_X86_64_PCREL_TYPE(TYPE) \
210 ( ((TYPE) == R_X86_64_PC8) \
211 || ((TYPE) == R_X86_64_PC16) \
212 || ((TYPE) == R_X86_64_PC32) \
213 || ((TYPE) == R_X86_64_PC32_BND) \
214 || ((TYPE) == R_X86_64_PC64))
216 /* Map BFD relocs to the x86_64 elf relocs. */
219 bfd_reloc_code_real_type bfd_reloc_val
;
220 unsigned char elf_reloc_val
;
223 static const struct elf_reloc_map x86_64_reloc_map
[] =
225 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
226 { BFD_RELOC_64
, R_X86_64_64
, },
227 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
228 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
229 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
230 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
231 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
232 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
233 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
234 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
235 { BFD_RELOC_32
, R_X86_64_32
, },
236 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
237 { BFD_RELOC_16
, R_X86_64_16
, },
238 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
239 { BFD_RELOC_8
, R_X86_64_8
, },
240 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
241 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
242 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
243 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
244 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
245 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
246 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
247 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
248 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
249 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
250 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
251 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
252 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
253 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
254 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
255 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
256 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
257 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
258 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
259 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
260 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
261 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
262 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
263 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
264 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
265 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
266 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
267 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
268 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
271 static reloc_howto_type
*
272 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
276 if (r_type
== (unsigned int) R_X86_64_32
)
281 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
283 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
284 || r_type
>= (unsigned int) R_X86_64_max
)
286 if (r_type
>= (unsigned int) R_X86_64_standard
)
288 /* xgettext:c-format */
289 _bfd_error_handler (_("%B: invalid relocation type %d"),
291 r_type
= R_X86_64_NONE
;
296 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
297 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
298 return &x86_64_elf_howto_table
[i
];
301 /* Given a BFD reloc type, return a HOWTO structure. */
302 static reloc_howto_type
*
303 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
304 bfd_reloc_code_real_type code
)
308 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
311 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
312 return elf_x86_64_rtype_to_howto (abfd
,
313 x86_64_reloc_map
[i
].elf_reloc_val
);
318 static reloc_howto_type
*
319 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
324 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
326 /* Get x32 R_X86_64_32. */
327 reloc_howto_type
*reloc
328 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
329 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
333 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
334 if (x86_64_elf_howto_table
[i
].name
!= NULL
335 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
336 return &x86_64_elf_howto_table
[i
];
341 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
344 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
345 Elf_Internal_Rela
*dst
)
349 r_type
= ELF32_R_TYPE (dst
->r_info
);
350 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
351 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
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 name of the dynamic interpreter. This is put in the .interp
534 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
535 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
537 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
538 copying dynamic variables from a shared lib into an app's dynbss
539 section, and instead use a dynamic relocation to point into the
541 #define ELIMINATE_COPY_RELOCS 1
543 /* The size in bytes of an entry in the global offset table. */
545 #define GOT_ENTRY_SIZE 8
547 /* The size in bytes of an entry in the procedure linkage table. */
549 #define PLT_ENTRY_SIZE 16
551 /* The first entry in a procedure linkage table looks like this. See the
552 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
554 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
556 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
557 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
558 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
561 /* Subsequent entries in a procedure linkage table look like this. */
563 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
565 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
566 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
567 0x68, /* pushq immediate */
568 0, 0, 0, 0, /* replaced with index into relocation table. */
569 0xe9, /* jmp relative */
570 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
573 /* The first entry in a procedure linkage table with BND relocations
576 static const bfd_byte elf_x86_64_bnd_plt0_entry
[PLT_ENTRY_SIZE
] =
578 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
579 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
580 0x0f, 0x1f, 0 /* nopl (%rax) */
583 /* Subsequent entries for legacy branches in a procedure linkage table
584 with BND relocations look like this. */
586 static const bfd_byte elf_x86_64_legacy_plt_entry
[PLT_ENTRY_SIZE
] =
588 0x68, 0, 0, 0, 0, /* pushq immediate */
589 0xe9, 0, 0, 0, 0, /* jmpq relative */
590 0x66, 0x0f, 0x1f, 0x44, 0, 0 /* nopw (%rax,%rax,1) */
593 /* Subsequent entries for branches with BND prefx in a procedure linkage
594 table with BND relocations look like this. */
596 static const bfd_byte elf_x86_64_bnd_plt_entry
[PLT_ENTRY_SIZE
] =
598 0x68, 0, 0, 0, 0, /* pushq immediate */
599 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
600 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
603 /* Entries for legacy branches in the second procedure linkage table
606 static const bfd_byte elf_x86_64_legacy_plt2_entry
[8] =
608 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
609 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
610 0x66, 0x90 /* xchg %ax,%ax */
613 /* Entries for branches with BND prefix in the second procedure linkage
614 table look like this. */
616 static const bfd_byte elf_x86_64_bnd_plt2_entry
[8] =
618 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
619 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
623 /* .eh_frame covering the .plt section. */
625 static const bfd_byte elf_x86_64_eh_frame_plt
[] =
627 #define PLT_CIE_LENGTH 20
628 #define PLT_FDE_LENGTH 36
629 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
630 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
631 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
632 0, 0, 0, 0, /* CIE ID */
634 'z', 'R', 0, /* Augmentation string */
635 1, /* Code alignment factor */
636 0x78, /* Data alignment factor */
637 16, /* Return address column */
638 1, /* Augmentation size */
639 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
640 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
641 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
642 DW_CFA_nop
, DW_CFA_nop
,
644 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
645 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
646 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
647 0, 0, 0, 0, /* .plt size goes here */
648 0, /* Augmentation size */
649 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
650 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
651 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
652 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
653 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
654 11, /* Block length */
655 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
656 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
657 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
658 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
659 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
662 /* .eh_frame covering the BND .plt section. */
664 static const bfd_byte elf_x86_64_eh_frame_bnd_plt
[] =
666 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
667 0, 0, 0, 0, /* CIE ID */
669 'z', 'R', 0, /* Augmentation string */
670 1, /* Code alignment factor */
671 0x78, /* Data alignment factor */
672 16, /* Return address column */
673 1, /* Augmentation size */
674 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
675 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
676 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
677 DW_CFA_nop
, DW_CFA_nop
,
679 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
680 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
681 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
682 0, 0, 0, 0, /* .plt size goes here */
683 0, /* Augmentation size */
684 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
685 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
686 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
687 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
688 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
689 11, /* Block length */
690 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
691 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
692 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
693 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
694 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
697 /* .eh_frame covering the .plt.got section. */
699 static const bfd_byte elf_x86_64_eh_frame_plt_got
[] =
701 #define PLT_GOT_FDE_LENGTH 20
702 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
703 0, 0, 0, 0, /* CIE ID */
705 'z', 'R', 0, /* Augmentation string */
706 1, /* Code alignment factor */
707 0x78, /* Data alignment factor */
708 16, /* Return address column */
709 1, /* Augmentation size */
710 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
711 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
712 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
713 DW_CFA_nop
, DW_CFA_nop
,
715 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
716 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
717 0, 0, 0, 0, /* the start of .plt.got goes here */
718 0, 0, 0, 0, /* .plt.got size goes here */
719 0, /* Augmentation size */
720 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
721 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
724 /* Architecture-specific backend data for x86-64. */
726 struct elf_x86_64_backend_data
728 /* Templates for the initial PLT entry and for subsequent entries. */
729 const bfd_byte
*plt0_entry
;
730 const bfd_byte
*plt_entry
;
731 unsigned int plt_entry_size
; /* Size of each PLT entry. */
733 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
734 unsigned int plt0_got1_offset
;
735 unsigned int plt0_got2_offset
;
737 /* Offset of the end of the PC-relative instruction containing
739 unsigned int plt0_got2_insn_end
;
741 /* Offsets into plt_entry that are to be replaced with... */
742 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
743 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
744 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
746 /* Length of the PC-relative instruction containing plt_got_offset. */
747 unsigned int plt_got_insn_size
;
749 /* Offset of the end of the PC-relative jump to plt0_entry. */
750 unsigned int plt_plt_insn_end
;
752 /* Offset into plt_entry where the initial value of the GOT entry points. */
753 unsigned int plt_lazy_offset
;
755 /* .eh_frame covering the .plt section. */
756 const bfd_byte
*eh_frame_plt
;
757 unsigned int eh_frame_plt_size
;
759 /* .eh_frame covering the .plt.got section. */
760 const bfd_byte
*eh_frame_plt_got
;
761 unsigned int eh_frame_plt_got_size
;
764 #define get_elf_x86_64_arch_data(bed) \
765 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
767 #define get_elf_x86_64_backend_data(abfd) \
768 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
770 #define GET_PLT_ENTRY_SIZE(abfd) \
771 get_elf_x86_64_backend_data (abfd)->plt_entry_size
773 /* These are the standard parameters. */
774 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
776 elf_x86_64_plt0_entry
, /* plt0_entry */
777 elf_x86_64_plt_entry
, /* plt_entry */
778 sizeof (elf_x86_64_plt_entry
), /* plt_entry_size */
779 2, /* plt0_got1_offset */
780 8, /* plt0_got2_offset */
781 12, /* plt0_got2_insn_end */
782 2, /* plt_got_offset */
783 7, /* plt_reloc_offset */
784 12, /* plt_plt_offset */
785 6, /* plt_got_insn_size */
786 PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
787 6, /* plt_lazy_offset */
788 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
789 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
790 elf_x86_64_eh_frame_plt_got
, /* eh_frame_plt_got */
791 sizeof (elf_x86_64_eh_frame_plt_got
), /* eh_frame_plt_got_size */
794 static const struct elf_x86_64_backend_data elf_x86_64_bnd_arch_bed
=
796 elf_x86_64_bnd_plt0_entry
, /* plt0_entry */
797 elf_x86_64_bnd_plt_entry
, /* plt_entry */
798 sizeof (elf_x86_64_bnd_plt_entry
), /* plt_entry_size */
799 2, /* plt0_got1_offset */
800 1+8, /* plt0_got2_offset */
801 1+12, /* plt0_got2_insn_end */
802 1+2, /* plt_got_offset */
803 1, /* plt_reloc_offset */
804 7, /* plt_plt_offset */
805 1+6, /* plt_got_insn_size */
806 11, /* plt_plt_insn_end */
807 0, /* plt_lazy_offset */
808 elf_x86_64_eh_frame_bnd_plt
, /* eh_frame_plt */
809 sizeof (elf_x86_64_eh_frame_bnd_plt
), /* eh_frame_plt_size */
810 elf_x86_64_eh_frame_plt_got
, /* eh_frame_plt_got */
811 sizeof (elf_x86_64_eh_frame_plt_got
), /* eh_frame_plt_got_size */
814 #define elf_backend_arch_data &elf_x86_64_arch_bed
816 /* Is a undefined weak symbol which is resolved to 0. Reference to an
817 undefined weak symbol is resolved to 0 when building executable if
819 1. Has non-GOT/non-PLT relocations in text section. Or
820 2. Has no GOT/PLT relocation.
822 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
823 ((EH)->elf.root.type == bfd_link_hash_undefweak \
824 && bfd_link_executable (INFO) \
825 && (elf_x86_64_hash_table (INFO)->interp == NULL \
827 || (EH)->has_non_got_reloc \
828 || !(INFO)->dynamic_undefined_weak))
830 /* x86-64 ELF linker hash entry. */
832 struct elf_x86_64_link_hash_entry
834 struct elf_link_hash_entry elf
;
836 /* Track dynamic relocs copied for this symbol. */
837 struct elf_dyn_relocs
*dyn_relocs
;
839 #define GOT_UNKNOWN 0
843 #define GOT_TLS_GDESC 4
844 #define GOT_TLS_GD_BOTH_P(type) \
845 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
846 #define GOT_TLS_GD_P(type) \
847 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
848 #define GOT_TLS_GDESC_P(type) \
849 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
850 #define GOT_TLS_GD_ANY_P(type) \
851 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
852 unsigned char tls_type
;
854 /* TRUE if a weak symbol with a real definition needs a copy reloc.
855 When there is a weak symbol with a real definition, the processor
856 independent code will have arranged for us to see the real
857 definition first. We need to copy the needs_copy bit from the
858 real definition and check it when allowing copy reloc in PIE. */
859 unsigned int needs_copy
: 1;
861 /* TRUE if symbol has GOT or PLT relocations. */
862 unsigned int has_got_reloc
: 1;
864 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
865 unsigned int has_non_got_reloc
: 1;
867 /* Don't call finish_dynamic_symbol on this symbol. */
868 unsigned int no_finish_dynamic_symbol
: 1;
870 /* 0: symbol isn't __tls_get_addr.
871 1: symbol is __tls_get_addr.
872 2: symbol is unknown. */
873 unsigned int tls_get_addr
: 2;
875 /* Reference count of C/C++ function pointer relocations in read-write
876 section which can be resolved at run-time. */
877 bfd_signed_vma func_pointer_refcount
;
879 /* Information about the GOT PLT entry. Filled when there are both
880 GOT and PLT relocations against the same function. */
881 union gotplt_union plt_got
;
883 /* Information about the second PLT entry. Filled when info>bndplt is
885 union gotplt_union plt_bnd
;
887 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
888 starting at the end of the jump table. */
892 #define elf_x86_64_hash_entry(ent) \
893 ((struct elf_x86_64_link_hash_entry *)(ent))
895 struct elf_x86_64_obj_tdata
897 struct elf_obj_tdata root
;
899 /* tls_type for each local got entry. */
900 char *local_got_tls_type
;
902 /* GOTPLT entries for TLS descriptors. */
903 bfd_vma
*local_tlsdesc_gotent
;
906 #define elf_x86_64_tdata(abfd) \
907 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
909 #define elf_x86_64_local_got_tls_type(abfd) \
910 (elf_x86_64_tdata (abfd)->local_got_tls_type)
912 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
913 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
915 #define is_x86_64_elf(bfd) \
916 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
917 && elf_tdata (bfd) != NULL \
918 && elf_object_id (bfd) == X86_64_ELF_DATA)
921 elf_x86_64_mkobject (bfd
*abfd
)
923 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
927 /* x86-64 ELF linker hash table. */
929 struct elf_x86_64_link_hash_table
931 struct elf_link_hash_table elf
;
933 /* Short-cuts to get to dynamic linker sections. */
935 asection
*plt_eh_frame
;
937 asection
*plt_bnd_eh_frame
;
939 asection
*plt_got_eh_frame
;
943 bfd_signed_vma refcount
;
947 /* The amount of space used by the jump slots in the GOT. */
948 bfd_vma sgotplt_jump_table_size
;
950 /* Small local sym cache. */
951 struct sym_cache sym_cache
;
953 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
954 bfd_vma (*r_sym
) (bfd_vma
);
955 unsigned int pointer_r_type
;
956 const char *dynamic_interpreter
;
957 int dynamic_interpreter_size
;
959 /* _TLS_MODULE_BASE_ symbol. */
960 struct bfd_link_hash_entry
*tls_module_base
;
962 /* Used by local STT_GNU_IFUNC symbols. */
963 htab_t loc_hash_table
;
964 void * loc_hash_memory
;
966 /* The offset into splt of the PLT entry for the TLS descriptor
967 resolver. Special values are 0, if not necessary (or not found
968 to be necessary yet), and -1 if needed but not determined
971 /* The offset into sgot of the GOT entry used by the PLT entry
975 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
976 bfd_vma next_jump_slot_index
;
977 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
978 bfd_vma next_irelative_index
;
980 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
981 to read-only sections. */
982 bfd_boolean readonly_dynrelocs_against_ifunc
;
985 /* Get the x86-64 ELF linker hash table from a link_info structure. */
987 #define elf_x86_64_hash_table(p) \
988 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
989 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
991 #define elf_x86_64_compute_jump_table_size(htab) \
992 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
994 /* Create an entry in an x86-64 ELF linker hash table. */
996 static struct bfd_hash_entry
*
997 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
998 struct bfd_hash_table
*table
,
1001 /* Allocate the structure if it has not already been allocated by a
1005 entry
= (struct bfd_hash_entry
*)
1006 bfd_hash_allocate (table
,
1007 sizeof (struct elf_x86_64_link_hash_entry
));
1012 /* Call the allocation method of the superclass. */
1013 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1016 struct elf_x86_64_link_hash_entry
*eh
;
1018 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
1019 eh
->dyn_relocs
= NULL
;
1020 eh
->tls_type
= GOT_UNKNOWN
;
1022 eh
->has_got_reloc
= 0;
1023 eh
->has_non_got_reloc
= 0;
1024 eh
->no_finish_dynamic_symbol
= 0;
1025 eh
->tls_get_addr
= 2;
1026 eh
->func_pointer_refcount
= 0;
1027 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
1028 eh
->plt_got
.offset
= (bfd_vma
) -1;
1029 eh
->tlsdesc_got
= (bfd_vma
) -1;
1035 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1036 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1037 as global symbol. We reuse indx and dynstr_index for local symbol
1038 hash since they aren't used by global symbols in this backend. */
1041 elf_x86_64_local_htab_hash (const void *ptr
)
1043 struct elf_link_hash_entry
*h
1044 = (struct elf_link_hash_entry
*) ptr
;
1045 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1048 /* Compare local hash entries. */
1051 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
1053 struct elf_link_hash_entry
*h1
1054 = (struct elf_link_hash_entry
*) ptr1
;
1055 struct elf_link_hash_entry
*h2
1056 = (struct elf_link_hash_entry
*) ptr2
;
1058 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1061 /* Find and/or create a hash entry for local symbol. */
1063 static struct elf_link_hash_entry
*
1064 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
1065 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1068 struct elf_x86_64_link_hash_entry e
, *ret
;
1069 asection
*sec
= abfd
->sections
;
1070 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1071 htab
->r_sym (rel
->r_info
));
1074 e
.elf
.indx
= sec
->id
;
1075 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1076 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1077 create
? INSERT
: NO_INSERT
);
1084 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1088 ret
= (struct elf_x86_64_link_hash_entry
*)
1089 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1090 sizeof (struct elf_x86_64_link_hash_entry
));
1093 memset (ret
, 0, sizeof (*ret
));
1094 ret
->elf
.indx
= sec
->id
;
1095 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1096 ret
->elf
.dynindx
= -1;
1097 ret
->func_pointer_refcount
= 0;
1098 ret
->plt_got
.offset
= (bfd_vma
) -1;
1104 /* Destroy an X86-64 ELF linker hash table. */
1107 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1109 struct elf_x86_64_link_hash_table
*htab
1110 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1112 if (htab
->loc_hash_table
)
1113 htab_delete (htab
->loc_hash_table
);
1114 if (htab
->loc_hash_memory
)
1115 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1116 _bfd_elf_link_hash_table_free (obfd
);
1119 /* Create an X86-64 ELF linker hash table. */
1121 static struct bfd_link_hash_table
*
1122 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1124 struct elf_x86_64_link_hash_table
*ret
;
1125 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1127 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1131 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1132 elf_x86_64_link_hash_newfunc
,
1133 sizeof (struct elf_x86_64_link_hash_entry
),
1140 if (ABI_64_P (abfd
))
1142 ret
->r_info
= elf64_r_info
;
1143 ret
->r_sym
= elf64_r_sym
;
1144 ret
->pointer_r_type
= R_X86_64_64
;
1145 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1146 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1150 ret
->r_info
= elf32_r_info
;
1151 ret
->r_sym
= elf32_r_sym
;
1152 ret
->pointer_r_type
= R_X86_64_32
;
1153 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1154 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1157 ret
->loc_hash_table
= htab_try_create (1024,
1158 elf_x86_64_local_htab_hash
,
1159 elf_x86_64_local_htab_eq
,
1161 ret
->loc_hash_memory
= objalloc_create ();
1162 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1164 elf_x86_64_link_hash_table_free (abfd
);
1167 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1169 return &ret
->elf
.root
;
1172 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1173 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1177 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
1178 struct bfd_link_info
*info
)
1180 struct elf_x86_64_link_hash_table
*htab
;
1182 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1185 htab
= elf_x86_64_hash_table (info
);
1189 /* Set the contents of the .interp section to the interpreter. */
1190 if (bfd_link_executable (info
) && !info
->nointerp
)
1192 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1195 s
->size
= htab
->dynamic_interpreter_size
;
1196 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
1200 if (!info
->no_ld_generated_unwind_info
1201 && htab
->plt_eh_frame
== NULL
1202 && htab
->elf
.splt
!= NULL
)
1204 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1205 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1206 | SEC_LINKER_CREATED
);
1208 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1209 if (htab
->plt_eh_frame
== NULL
1210 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
,
1211 ABI_64_P (dynobj
) ? 3 : 2))
1215 /* Align .got section to its entry size. */
1216 if (htab
->elf
.sgot
!= NULL
1217 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgot
, 3))
1220 /* Align .got.plt section to its entry size. */
1221 if (htab
->elf
.sgotplt
!= NULL
1222 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgotplt
, 3))
1228 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1231 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1232 struct elf_link_hash_entry
*dir
,
1233 struct elf_link_hash_entry
*ind
)
1235 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1237 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1238 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1240 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1241 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1243 if (eind
->dyn_relocs
!= NULL
)
1245 if (edir
->dyn_relocs
!= NULL
)
1247 struct elf_dyn_relocs
**pp
;
1248 struct elf_dyn_relocs
*p
;
1250 /* Add reloc counts against the indirect sym to the direct sym
1251 list. Merge any entries against the same section. */
1252 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1254 struct elf_dyn_relocs
*q
;
1256 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1257 if (q
->sec
== p
->sec
)
1259 q
->pc_count
+= p
->pc_count
;
1260 q
->count
+= p
->count
;
1267 *pp
= edir
->dyn_relocs
;
1270 edir
->dyn_relocs
= eind
->dyn_relocs
;
1271 eind
->dyn_relocs
= NULL
;
1274 if (ind
->root
.type
== bfd_link_hash_indirect
1275 && dir
->got
.refcount
<= 0)
1277 edir
->tls_type
= eind
->tls_type
;
1278 eind
->tls_type
= GOT_UNKNOWN
;
1281 if (ELIMINATE_COPY_RELOCS
1282 && ind
->root
.type
!= bfd_link_hash_indirect
1283 && dir
->dynamic_adjusted
)
1285 /* If called to transfer flags for a weakdef during processing
1286 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1287 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1288 if (dir
->versioned
!= versioned_hidden
)
1289 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1290 dir
->ref_regular
|= ind
->ref_regular
;
1291 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1292 dir
->needs_plt
|= ind
->needs_plt
;
1293 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1297 if (eind
->func_pointer_refcount
> 0)
1299 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1300 eind
->func_pointer_refcount
= 0;
1303 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1308 elf64_x86_64_elf_object_p (bfd
*abfd
)
1310 /* Set the right machine number for an x86-64 elf64 file. */
1311 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1316 elf32_x86_64_elf_object_p (bfd
*abfd
)
1318 /* Set the right machine number for an x86-64 elf32 file. */
1319 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1323 /* Return TRUE if the TLS access code sequence support transition
1327 elf_x86_64_check_tls_transition (bfd
*abfd
,
1328 struct bfd_link_info
*info
,
1331 Elf_Internal_Shdr
*symtab_hdr
,
1332 struct elf_link_hash_entry
**sym_hashes
,
1333 unsigned int r_type
,
1334 const Elf_Internal_Rela
*rel
,
1335 const Elf_Internal_Rela
*relend
)
1338 unsigned long r_symndx
;
1339 bfd_boolean largepic
= FALSE
;
1340 struct elf_link_hash_entry
*h
;
1342 struct elf_x86_64_link_hash_table
*htab
;
1344 bfd_boolean indirect_call
, tls_get_addr
;
1346 htab
= elf_x86_64_hash_table (info
);
1347 offset
= rel
->r_offset
;
1350 case R_X86_64_TLSGD
:
1351 case R_X86_64_TLSLD
:
1352 if ((rel
+ 1) >= relend
)
1355 if (r_type
== R_X86_64_TLSGD
)
1357 /* Check transition from GD access model. For 64bit, only
1358 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1359 .word 0x6666; rex64; call __tls_get_addr@PLT
1361 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1363 call *__tls_get_addr@GOTPCREL(%rip)
1364 which may be converted to
1365 addr32 call __tls_get_addr
1366 can transit to different access model. For 32bit, only
1367 leaq foo@tlsgd(%rip), %rdi
1368 .word 0x6666; rex64; call __tls_get_addr@PLT
1370 leaq foo@tlsgd(%rip), %rdi
1372 call *__tls_get_addr@GOTPCREL(%rip)
1373 which may be converted to
1374 addr32 call __tls_get_addr
1375 can transit to different access model. For largepic,
1377 leaq foo@tlsgd(%rip), %rdi
1378 movabsq $__tls_get_addr@pltoff, %rax
1382 leaq foo@tlsgd(%rip), %rdi
1383 movabsq $__tls_get_addr@pltoff, %rax
1387 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1389 if ((offset
+ 12) > sec
->size
)
1392 call
= contents
+ offset
+ 4;
1394 || !((call
[1] == 0x48
1402 && call
[3] == 0xe8)))
1404 if (!ABI_64_P (abfd
)
1405 || (offset
+ 19) > sec
->size
1407 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1408 || memcmp (call
, "\x48\xb8", 2) != 0
1412 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1413 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1417 else if (ABI_64_P (abfd
))
1420 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1426 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1429 indirect_call
= call
[2] == 0xff;
1433 /* Check transition from LD access model. Only
1434 leaq foo@tlsld(%rip), %rdi;
1435 call __tls_get_addr@PLT
1437 leaq foo@tlsld(%rip), %rdi;
1438 call *__tls_get_addr@GOTPCREL(%rip)
1439 which may be converted to
1440 addr32 call __tls_get_addr
1441 can transit to different access model. For largepic
1443 leaq foo@tlsld(%rip), %rdi
1444 movabsq $__tls_get_addr@pltoff, %rax
1448 leaq foo@tlsld(%rip), %rdi
1449 movabsq $__tls_get_addr@pltoff, %rax
1453 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1455 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1458 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1461 call
= contents
+ offset
+ 4;
1462 if (!(call
[0] == 0xe8
1463 || (call
[0] == 0xff && call
[1] == 0x15)
1464 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1466 if (!ABI_64_P (abfd
)
1467 || (offset
+ 19) > sec
->size
1468 || memcmp (call
, "\x48\xb8", 2) != 0
1472 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1473 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1477 indirect_call
= call
[0] == 0xff;
1480 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1481 if (r_symndx
< symtab_hdr
->sh_info
)
1484 tls_get_addr
= FALSE
;
1485 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1486 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1488 struct elf_x86_64_link_hash_entry
*eh
1489 = (struct elf_x86_64_link_hash_entry
*) h
;
1490 tls_get_addr
= eh
->tls_get_addr
== 1;
1491 if (eh
->tls_get_addr
> 1)
1493 /* Use strncmp to check __tls_get_addr since
1494 __tls_get_addr may be versioned. */
1495 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1498 eh
->tls_get_addr
= 1;
1499 tls_get_addr
= TRUE
;
1502 eh
->tls_get_addr
= 0;
1509 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1510 else if (indirect_call
)
1511 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1513 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1514 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1516 case R_X86_64_GOTTPOFF
:
1517 /* Check transition from IE access model:
1518 mov foo@gottpoff(%rip), %reg
1519 add foo@gottpoff(%rip), %reg
1522 /* Check REX prefix first. */
1523 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1525 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1526 if (val
!= 0x48 && val
!= 0x4c)
1528 /* X32 may have 0x44 REX prefix or no REX prefix. */
1529 if (ABI_64_P (abfd
))
1535 /* X32 may not have any REX prefix. */
1536 if (ABI_64_P (abfd
))
1538 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1542 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1543 if (val
!= 0x8b && val
!= 0x03)
1546 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1547 return (val
& 0xc7) == 5;
1549 case R_X86_64_GOTPC32_TLSDESC
:
1550 /* Check transition from GDesc access model:
1551 leaq x@tlsdesc(%rip), %rax
1553 Make sure it's a leaq adding rip to a 32-bit offset
1554 into any register, although it's probably almost always
1557 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1560 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1561 if ((val
& 0xfb) != 0x48)
1564 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1567 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1568 return (val
& 0xc7) == 0x05;
1570 case R_X86_64_TLSDESC_CALL
:
1571 /* Check transition from GDesc access model:
1572 call *x@tlsdesc(%rax)
1574 if (offset
+ 2 <= sec
->size
)
1576 /* Make sure that it's a call *x@tlsdesc(%rax). */
1577 call
= contents
+ offset
;
1578 return call
[0] == 0xff && call
[1] == 0x10;
1588 /* Return TRUE if the TLS access transition is OK or no transition
1589 will be performed. Update R_TYPE if there is a transition. */
1592 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1593 asection
*sec
, bfd_byte
*contents
,
1594 Elf_Internal_Shdr
*symtab_hdr
,
1595 struct elf_link_hash_entry
**sym_hashes
,
1596 unsigned int *r_type
, int tls_type
,
1597 const Elf_Internal_Rela
*rel
,
1598 const Elf_Internal_Rela
*relend
,
1599 struct elf_link_hash_entry
*h
,
1600 unsigned long r_symndx
,
1601 bfd_boolean from_relocate_section
)
1603 unsigned int from_type
= *r_type
;
1604 unsigned int to_type
= from_type
;
1605 bfd_boolean check
= TRUE
;
1607 /* Skip TLS transition for functions. */
1609 && (h
->type
== STT_FUNC
1610 || h
->type
== STT_GNU_IFUNC
))
1615 case R_X86_64_TLSGD
:
1616 case R_X86_64_GOTPC32_TLSDESC
:
1617 case R_X86_64_TLSDESC_CALL
:
1618 case R_X86_64_GOTTPOFF
:
1619 if (bfd_link_executable (info
))
1622 to_type
= R_X86_64_TPOFF32
;
1624 to_type
= R_X86_64_GOTTPOFF
;
1627 /* When we are called from elf_x86_64_relocate_section, there may
1628 be additional transitions based on TLS_TYPE. */
1629 if (from_relocate_section
)
1631 unsigned int new_to_type
= to_type
;
1633 if (bfd_link_executable (info
)
1636 && tls_type
== GOT_TLS_IE
)
1637 new_to_type
= R_X86_64_TPOFF32
;
1639 if (to_type
== R_X86_64_TLSGD
1640 || to_type
== R_X86_64_GOTPC32_TLSDESC
1641 || to_type
== R_X86_64_TLSDESC_CALL
)
1643 if (tls_type
== GOT_TLS_IE
)
1644 new_to_type
= R_X86_64_GOTTPOFF
;
1647 /* We checked the transition before when we were called from
1648 elf_x86_64_check_relocs. We only want to check the new
1649 transition which hasn't been checked before. */
1650 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1651 to_type
= new_to_type
;
1656 case R_X86_64_TLSLD
:
1657 if (bfd_link_executable (info
))
1658 to_type
= R_X86_64_TPOFF32
;
1665 /* Return TRUE if there is no transition. */
1666 if (from_type
== to_type
)
1669 /* Check if the transition can be performed. */
1671 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1672 symtab_hdr
, sym_hashes
,
1673 from_type
, rel
, relend
))
1675 reloc_howto_type
*from
, *to
;
1678 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1679 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1682 name
= h
->root
.root
.string
;
1685 struct elf_x86_64_link_hash_table
*htab
;
1687 htab
= elf_x86_64_hash_table (info
);
1692 Elf_Internal_Sym
*isym
;
1694 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1696 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1701 /* xgettext:c-format */
1702 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1703 "in section `%A' failed"),
1704 abfd
, from
->name
, to
->name
, name
,
1705 (unsigned long) rel
->r_offset
, sec
);
1706 bfd_set_error (bfd_error_bad_value
);
1714 /* Rename some of the generic section flags to better document how they
1716 #define need_convert_load sec_flg0
1717 #define check_relocs_failed sec_flg1
1720 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1721 struct elf_link_hash_entry
*h
,
1722 Elf_Internal_Shdr
*symtab_hdr
,
1723 Elf_Internal_Sym
*isym
,
1724 reloc_howto_type
*howto
)
1727 const char *und
= "";
1728 const char *pic
= "";
1733 name
= h
->root
.root
.string
;
1734 switch (ELF_ST_VISIBILITY (h
->other
))
1737 v
= _("hidden symbol ");
1740 v
= _("internal symbol ");
1743 v
= _("protected symbol ");
1747 pic
= _("; recompile with -fPIC");
1751 if (!h
->def_regular
&& !h
->def_dynamic
)
1752 und
= _("undefined ");
1756 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1757 pic
= _("; recompile with -fPIC");
1760 /* xgettext:c-format */
1761 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1762 "not be used when making a shared object%s"),
1763 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1764 bfd_set_error (bfd_error_bad_value
);
1765 sec
->check_relocs_failed
= 1;
1769 /* With the local symbol, foo, we convert
1770 mov foo@GOTPCREL(%rip), %reg
1774 call/jmp *foo@GOTPCREL(%rip)
1776 nop call foo/jmp foo nop
1777 When PIC is false, convert
1778 test %reg, foo@GOTPCREL(%rip)
1782 binop foo@GOTPCREL(%rip), %reg
1785 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1789 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1791 Elf_Internal_Rela
*irel
,
1792 struct elf_link_hash_entry
*h
,
1793 bfd_boolean
*converted
,
1794 struct bfd_link_info
*link_info
)
1796 struct elf_x86_64_link_hash_table
*htab
;
1798 bfd_boolean require_reloc_pc32
;
1800 bfd_boolean to_reloc_pc32
;
1803 bfd_signed_vma raddend
;
1804 unsigned int opcode
;
1806 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1807 unsigned int r_symndx
;
1809 bfd_vma roff
= irel
->r_offset
;
1811 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1814 raddend
= irel
->r_addend
;
1815 /* Addend for 32-bit PC-relative relocation must be -4. */
1819 htab
= elf_x86_64_hash_table (link_info
);
1820 is_pic
= bfd_link_pic (link_info
);
1822 relocx
= (r_type
== R_X86_64_GOTPCRELX
1823 || r_type
== R_X86_64_REX_GOTPCRELX
);
1825 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1828 = link_info
->disable_target_specific_optimizations
> 1;
1830 r_symndx
= htab
->r_sym (irel
->r_info
);
1832 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1834 /* Convert mov to lea since it has been done for a while. */
1837 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1838 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1839 test, xor instructions. */
1844 /* We convert only to R_X86_64_PC32:
1846 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1847 3. require_reloc_pc32 is true.
1850 to_reloc_pc32
= (opcode
== 0xff
1852 || require_reloc_pc32
1855 /* Get the symbol referred to by the reloc. */
1858 Elf_Internal_Sym
*isym
1859 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1861 /* Skip relocation against undefined symbols. */
1862 if (isym
->st_shndx
== SHN_UNDEF
)
1865 symtype
= ELF_ST_TYPE (isym
->st_info
);
1867 if (isym
->st_shndx
== SHN_ABS
)
1868 tsec
= bfd_abs_section_ptr
;
1869 else if (isym
->st_shndx
== SHN_COMMON
)
1870 tsec
= bfd_com_section_ptr
;
1871 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1872 tsec
= &_bfd_elf_large_com_section
;
1874 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1876 toff
= isym
->st_value
;
1880 /* Undefined weak symbol is only bound locally in executable
1881 and its reference is resolved as 0 without relocation
1882 overflow. We can only perform this optimization for
1883 GOTPCRELX relocations since we need to modify REX byte.
1884 It is OK convert mov with R_X86_64_GOTPCREL to
1886 if ((relocx
|| opcode
== 0x8b)
1887 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1889 elf_x86_64_hash_entry (h
)))
1893 /* Skip for branch instructions since R_X86_64_PC32
1895 if (require_reloc_pc32
)
1900 /* For non-branch instructions, we can convert to
1901 R_X86_64_32/R_X86_64_32S since we know if there
1903 to_reloc_pc32
= FALSE
;
1906 /* Since we don't know the current PC when PIC is true,
1907 we can't convert to R_X86_64_PC32. */
1908 if (to_reloc_pc32
&& is_pic
)
1913 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1914 ld.so may use its link-time address. */
1915 else if ((h
->def_regular
1916 || h
->root
.type
== bfd_link_hash_defined
1917 || h
->root
.type
== bfd_link_hash_defweak
)
1918 && h
!= htab
->elf
.hdynamic
1919 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1921 /* bfd_link_hash_new or bfd_link_hash_undefined is
1922 set by an assignment in a linker script in
1923 bfd_elf_record_link_assignment. */
1925 && (h
->root
.type
== bfd_link_hash_new
1926 || h
->root
.type
== bfd_link_hash_undefined
1927 || ((h
->root
.type
== bfd_link_hash_defined
1928 || h
->root
.type
== bfd_link_hash_defweak
)
1929 && h
->root
.u
.def
.section
== bfd_und_section_ptr
)))
1931 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1932 if (require_reloc_pc32
)
1936 tsec
= h
->root
.u
.def
.section
;
1937 toff
= h
->root
.u
.def
.value
;
1944 /* Don't convert GOTPCREL relocation against large section. */
1945 if (elf_section_data (tsec
) != NULL
1946 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1949 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1953 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1955 /* At this stage in linking, no SEC_MERGE symbol has been
1956 adjusted, so all references to such symbols need to be
1957 passed through _bfd_merged_section_offset. (Later, in
1958 relocate_section, all SEC_MERGE symbols *except* for
1959 section symbols have been adjusted.)
1961 gas may reduce relocations against symbols in SEC_MERGE
1962 sections to a relocation against the section symbol when
1963 the original addend was zero. When the reloc is against
1964 a section symbol we should include the addend in the
1965 offset passed to _bfd_merged_section_offset, since the
1966 location of interest is the original symbol. On the
1967 other hand, an access to "sym+addend" where "sym" is not
1968 a section symbol should not include the addend; Such an
1969 access is presumed to be an offset from "sym"; The
1970 location of interest is just "sym". */
1971 if (symtype
== STT_SECTION
)
1974 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1975 elf_section_data (tsec
)->sec_info
,
1978 if (symtype
!= STT_SECTION
)
1984 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1985 if (tsec
->output_section
== sec
->output_section
)
1987 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
1992 bfd_signed_vma distance
;
1994 /* At this point, we don't know the load addresses of TSEC
1995 section nor SEC section. We estimate the distrance between
1996 SEC and TSEC. We store the estimated distances in the
1997 compressed_size field of the output section, which is only
1998 used to decompress the compressed input section. */
1999 if (sec
->output_section
->compressed_size
== 0)
2002 bfd_size_type size
= 0;
2003 for (asect
= link_info
->output_bfd
->sections
;
2005 asect
= asect
->next
)
2006 /* Skip debug sections since compressed_size is used to
2007 compress debug sections. */
2008 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
2011 for (i
= asect
->map_head
.s
;
2015 size
= align_power (size
, i
->alignment_power
);
2018 asect
->compressed_size
= size
;
2022 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2024 distance
= (tsec
->output_section
->compressed_size
2025 - sec
->output_section
->compressed_size
);
2029 /* Take PT_GNU_RELRO segment into account by adding
2031 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
2032 - roff
+ 0x80000000) > 0xffffffff)
2039 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2044 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2046 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2049 /* Convert to "jmp foo nop". */
2052 nop_offset
= irel
->r_offset
+ 3;
2053 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2054 irel
->r_offset
-= 1;
2055 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2059 struct elf_x86_64_link_hash_entry
*eh
2060 = (struct elf_x86_64_link_hash_entry
*) h
;
2062 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2065 /* To support TLS optimization, always use addr32 prefix for
2066 "call *__tls_get_addr@GOTPCREL(%rip)". */
2067 if (eh
&& eh
->tls_get_addr
== 1)
2070 nop_offset
= irel
->r_offset
- 2;
2074 nop
= link_info
->call_nop_byte
;
2075 if (link_info
->call_nop_as_suffix
)
2077 nop_offset
= irel
->r_offset
+ 3;
2078 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2079 irel
->r_offset
-= 1;
2080 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2083 nop_offset
= irel
->r_offset
- 2;
2086 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2087 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2088 r_type
= R_X86_64_PC32
;
2093 unsigned int rex_mask
= REX_R
;
2095 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2096 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2104 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2105 "lea foo(%rip), %reg". */
2107 r_type
= R_X86_64_PC32
;
2111 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2112 "mov $foo, %reg". */
2114 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2115 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2116 if ((rex
& REX_W
) != 0
2117 && ABI_64_P (link_info
->output_bfd
))
2119 /* Keep the REX_W bit in REX byte for LP64. */
2120 r_type
= R_X86_64_32S
;
2121 goto rewrite_modrm_rex
;
2125 /* If the REX_W bit in REX byte isn't needed,
2126 use R_X86_64_32 and clear the W bit to avoid
2127 sign-extend imm32 to imm64. */
2128 r_type
= R_X86_64_32
;
2129 /* Clear the W bit in REX byte. */
2131 goto rewrite_modrm_rex
;
2137 /* R_X86_64_PC32 isn't supported. */
2141 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2144 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2145 "test $foo, %reg". */
2146 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2151 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2152 "binop $foo, %reg". */
2153 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2157 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2158 overflow when sign-extending imm32 to imm64. */
2159 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2162 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2166 /* Move the R bit to the B bit in REX byte. */
2167 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2168 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2171 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2175 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2178 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2185 /* Look through the relocs for a section during the first phase, and
2186 calculate needed space in the global offset table, procedure
2187 linkage table, and dynamic reloc sections. */
2190 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2192 const Elf_Internal_Rela
*relocs
)
2194 struct elf_x86_64_link_hash_table
*htab
;
2195 Elf_Internal_Shdr
*symtab_hdr
;
2196 struct elf_link_hash_entry
**sym_hashes
;
2197 const Elf_Internal_Rela
*rel
;
2198 const Elf_Internal_Rela
*rel_end
;
2201 bfd_boolean use_plt_got
;
2203 if (bfd_link_relocatable (info
))
2206 /* Don't do anything special with non-loaded, non-alloced sections.
2207 In particular, any relocs in such sections should not affect GOT
2208 and PLT reference counting (ie. we don't allow them to create GOT
2209 or PLT entries), there's no possibility or desire to optimize TLS
2210 relocs, and there's not much point in propagating relocs to shared
2211 libs that the dynamic linker won't relocate. */
2212 if ((sec
->flags
& SEC_ALLOC
) == 0)
2215 BFD_ASSERT (is_x86_64_elf (abfd
));
2217 htab
= elf_x86_64_hash_table (info
);
2220 sec
->check_relocs_failed
= 1;
2224 /* Get the section contents. */
2225 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2226 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2227 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2229 sec
->check_relocs_failed
= 1;
2233 use_plt_got
= get_elf_x86_64_backend_data (abfd
) == &elf_x86_64_arch_bed
;
2235 symtab_hdr
= &elf_symtab_hdr (abfd
);
2236 sym_hashes
= elf_sym_hashes (abfd
);
2240 rel_end
= relocs
+ sec
->reloc_count
;
2241 for (rel
= relocs
; rel
< rel_end
; rel
++)
2243 unsigned int r_type
;
2244 unsigned long r_symndx
;
2245 struct elf_link_hash_entry
*h
;
2246 struct elf_x86_64_link_hash_entry
*eh
;
2247 Elf_Internal_Sym
*isym
;
2249 bfd_boolean size_reloc
;
2251 r_symndx
= htab
->r_sym (rel
->r_info
);
2252 r_type
= ELF32_R_TYPE (rel
->r_info
);
2254 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2256 /* xgettext:c-format */
2257 _bfd_error_handler (_("%B: bad symbol index: %d"),
2262 if (r_symndx
< symtab_hdr
->sh_info
)
2264 /* A local symbol. */
2265 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2270 /* Check relocation against local STT_GNU_IFUNC symbol. */
2271 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2273 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2278 /* Fake a STT_GNU_IFUNC symbol. */
2279 h
->type
= STT_GNU_IFUNC
;
2282 h
->forced_local
= 1;
2283 h
->root
.type
= bfd_link_hash_defined
;
2291 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2292 while (h
->root
.type
== bfd_link_hash_indirect
2293 || h
->root
.type
== bfd_link_hash_warning
)
2294 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2297 /* Check invalid x32 relocations. */
2298 if (!ABI_64_P (abfd
))
2304 case R_X86_64_DTPOFF64
:
2305 case R_X86_64_TPOFF64
:
2307 case R_X86_64_GOTOFF64
:
2308 case R_X86_64_GOT64
:
2309 case R_X86_64_GOTPCREL64
:
2310 case R_X86_64_GOTPC64
:
2311 case R_X86_64_GOTPLT64
:
2312 case R_X86_64_PLTOFF64
:
2315 name
= h
->root
.root
.string
;
2317 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2320 /* xgettext:c-format */
2321 (_("%B: relocation %s against symbol `%s' isn't "
2322 "supported in x32 mode"), abfd
,
2323 x86_64_elf_howto_table
[r_type
].name
, name
);
2324 bfd_set_error (bfd_error_bad_value
);
2337 case R_X86_64_PC32_BND
:
2338 case R_X86_64_PLT32_BND
:
2340 case R_X86_64_PLT32
:
2343 /* MPX PLT is supported only if elf_x86_64_arch_bed
2344 is used in 64-bit mode. */
2347 && (get_elf_x86_64_backend_data (abfd
)
2348 == &elf_x86_64_arch_bed
))
2350 /* Create the second PLT for Intel MPX support. */
2351 if (htab
->plt_bnd
== NULL
)
2353 const struct elf_backend_data
*bed
;
2355 bed
= get_elf_backend_data (info
->output_bfd
);
2356 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry
) == 8
2357 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2358 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2360 if (htab
->elf
.dynobj
== NULL
)
2361 htab
->elf
.dynobj
= abfd
;
2363 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2365 (bed
->dynamic_sec_flags
2370 if (htab
->plt_bnd
== NULL
2371 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2377 if (!info
->no_ld_generated_unwind_info
2378 && htab
->plt_bnd_eh_frame
== NULL
)
2380 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2381 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2382 | SEC_LINKER_CREATED
);
2383 htab
->plt_bnd_eh_frame
2384 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2387 if (htab
->plt_bnd_eh_frame
== NULL
2388 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2389 htab
->plt_bnd_eh_frame
,
2398 case R_X86_64_GOTPCREL
:
2399 case R_X86_64_GOTPCRELX
:
2400 case R_X86_64_REX_GOTPCRELX
:
2401 case R_X86_64_GOTPCREL64
:
2402 if (htab
->elf
.dynobj
== NULL
)
2403 htab
->elf
.dynobj
= abfd
;
2404 /* Create the ifunc sections for static executables. */
2405 if (h
->type
== STT_GNU_IFUNC
2406 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
2412 /* It is referenced by a non-shared object. */
2414 h
->root
.non_ir_ref
= 1;
2416 if (h
->type
== STT_GNU_IFUNC
)
2417 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2418 |= elf_gnu_symbol_ifunc
;
2421 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2422 symtab_hdr
, sym_hashes
,
2423 &r_type
, GOT_UNKNOWN
,
2424 rel
, rel_end
, h
, r_symndx
, FALSE
))
2427 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2430 case R_X86_64_TLSLD
:
2431 htab
->tls_ld_got
.refcount
+= 1;
2434 case R_X86_64_TPOFF32
:
2435 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2436 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2437 &x86_64_elf_howto_table
[r_type
]);
2439 eh
->has_got_reloc
= 1;
2442 case R_X86_64_GOTTPOFF
:
2443 if (!bfd_link_executable (info
))
2444 info
->flags
|= DF_STATIC_TLS
;
2447 case R_X86_64_GOT32
:
2448 case R_X86_64_GOTPCREL
:
2449 case R_X86_64_GOTPCRELX
:
2450 case R_X86_64_REX_GOTPCRELX
:
2451 case R_X86_64_TLSGD
:
2452 case R_X86_64_GOT64
:
2453 case R_X86_64_GOTPCREL64
:
2454 case R_X86_64_GOTPLT64
:
2455 case R_X86_64_GOTPC32_TLSDESC
:
2456 case R_X86_64_TLSDESC_CALL
:
2457 /* This symbol requires a global offset table entry. */
2459 int tls_type
, old_tls_type
;
2463 default: tls_type
= GOT_NORMAL
; break;
2464 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2465 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2466 case R_X86_64_GOTPC32_TLSDESC
:
2467 case R_X86_64_TLSDESC_CALL
:
2468 tls_type
= GOT_TLS_GDESC
; break;
2473 h
->got
.refcount
+= 1;
2474 old_tls_type
= eh
->tls_type
;
2478 bfd_signed_vma
*local_got_refcounts
;
2480 /* This is a global offset table entry for a local symbol. */
2481 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2482 if (local_got_refcounts
== NULL
)
2486 size
= symtab_hdr
->sh_info
;
2487 size
*= sizeof (bfd_signed_vma
)
2488 + sizeof (bfd_vma
) + sizeof (char);
2489 local_got_refcounts
= ((bfd_signed_vma
*)
2490 bfd_zalloc (abfd
, size
));
2491 if (local_got_refcounts
== NULL
)
2493 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2494 elf_x86_64_local_tlsdesc_gotent (abfd
)
2495 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2496 elf_x86_64_local_got_tls_type (abfd
)
2497 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2499 local_got_refcounts
[r_symndx
] += 1;
2501 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2504 /* If a TLS symbol is accessed using IE at least once,
2505 there is no point to use dynamic model for it. */
2506 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2507 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2508 || tls_type
!= GOT_TLS_IE
))
2510 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2511 tls_type
= old_tls_type
;
2512 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2513 && GOT_TLS_GD_ANY_P (tls_type
))
2514 tls_type
|= old_tls_type
;
2518 name
= h
->root
.root
.string
;
2520 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2523 /* xgettext:c-format */
2524 (_("%B: '%s' accessed both as normal and"
2525 " thread local symbol"),
2527 bfd_set_error (bfd_error_bad_value
);
2532 if (old_tls_type
!= tls_type
)
2535 eh
->tls_type
= tls_type
;
2537 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2542 case R_X86_64_GOTOFF64
:
2543 case R_X86_64_GOTPC32
:
2544 case R_X86_64_GOTPC64
:
2547 eh
->has_got_reloc
= 1;
2548 if (htab
->elf
.sgot
== NULL
)
2550 if (htab
->elf
.dynobj
== NULL
)
2551 htab
->elf
.dynobj
= abfd
;
2552 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
2558 case R_X86_64_PLT32
:
2559 case R_X86_64_PLT32_BND
:
2560 /* This symbol requires a procedure linkage table entry. We
2561 actually build the entry in adjust_dynamic_symbol,
2562 because this might be a case of linking PIC code which is
2563 never referenced by a dynamic object, in which case we
2564 don't need to generate a procedure linkage table entry
2567 /* If this is a local symbol, we resolve it directly without
2568 creating a procedure linkage table entry. */
2572 eh
->has_got_reloc
= 1;
2574 h
->plt
.refcount
+= 1;
2577 case R_X86_64_PLTOFF64
:
2578 /* This tries to form the 'address' of a function relative
2579 to GOT. For global symbols we need a PLT entry. */
2583 h
->plt
.refcount
+= 1;
2587 case R_X86_64_SIZE32
:
2588 case R_X86_64_SIZE64
:
2593 if (!ABI_64_P (abfd
))
2599 /* Check relocation overflow as these relocs may lead to
2600 run-time relocation overflow. Don't error out for
2601 sections we don't care about, such as debug sections or
2602 when relocation overflow check is disabled. */
2603 if (!info
->no_reloc_overflow_check
2604 && (bfd_link_pic (info
)
2605 || (bfd_link_executable (info
)
2609 && (sec
->flags
& SEC_READONLY
) == 0)))
2610 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2611 &x86_64_elf_howto_table
[r_type
]);
2617 case R_X86_64_PC32_BND
:
2621 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2622 eh
->has_non_got_reloc
= 1;
2623 /* We are called after all symbols have been resolved. Only
2624 relocation against STT_GNU_IFUNC symbol must go through
2627 && (bfd_link_executable (info
)
2628 || h
->type
== STT_GNU_IFUNC
))
2630 /* If this reloc is in a read-only section, we might
2631 need a copy reloc. We can't check reliably at this
2632 stage whether the section is read-only, as input
2633 sections have not yet been mapped to output sections.
2634 Tentatively set the flag for now, and correct in
2635 adjust_dynamic_symbol. */
2638 /* We may need a .plt entry if the symbol is a function
2639 defined in a shared lib or is a STT_GNU_IFUNC function
2640 referenced from the code or read-only section. */
2642 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2643 h
->plt
.refcount
+= 1;
2645 if (r_type
== R_X86_64_PC32
)
2647 /* Since something like ".long foo - ." may be used
2648 as pointer, make sure that PLT is used if foo is
2649 a function defined in a shared library. */
2650 if ((sec
->flags
& SEC_CODE
) == 0)
2651 h
->pointer_equality_needed
= 1;
2653 else if (r_type
!= R_X86_64_PC32_BND
2654 && r_type
!= R_X86_64_PC64
)
2656 h
->pointer_equality_needed
= 1;
2657 /* At run-time, R_X86_64_64 can be resolved for both
2658 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2659 can only be resolved for x32. */
2660 if ((sec
->flags
& SEC_READONLY
) == 0
2661 && (r_type
== R_X86_64_64
2662 || (!ABI_64_P (abfd
)
2663 && (r_type
== R_X86_64_32
2664 || r_type
== R_X86_64_32S
))))
2665 eh
->func_pointer_refcount
+= 1;
2671 /* If we are creating a shared library, and this is a reloc
2672 against a global symbol, or a non PC relative reloc
2673 against a local symbol, then we need to copy the reloc
2674 into the shared library. However, if we are linking with
2675 -Bsymbolic, we do not need to copy a reloc against a
2676 global symbol which is defined in an object we are
2677 including in the link (i.e., DEF_REGULAR is set). At
2678 this point we have not seen all the input files, so it is
2679 possible that DEF_REGULAR is not set now but will be set
2680 later (it is never cleared). In case of a weak definition,
2681 DEF_REGULAR may be cleared later by a strong definition in
2682 a shared library. We account for that possibility below by
2683 storing information in the relocs_copied field of the hash
2684 table entry. A similar situation occurs when creating
2685 shared libraries and symbol visibility changes render the
2688 If on the other hand, we are creating an executable, we
2689 may need to keep relocations for symbols satisfied by a
2690 dynamic library if we manage to avoid copy relocs for the
2693 Generate dynamic pointer relocation against STT_GNU_IFUNC
2694 symbol in the non-code section. */
2695 if ((bfd_link_pic (info
)
2696 && (! IS_X86_64_PCREL_TYPE (r_type
)
2698 && (! (bfd_link_pie (info
)
2699 || SYMBOLIC_BIND (info
, h
))
2700 || h
->root
.type
== bfd_link_hash_defweak
2701 || !h
->def_regular
))))
2703 && h
->type
== STT_GNU_IFUNC
2704 && r_type
== htab
->pointer_r_type
2705 && (sec
->flags
& SEC_CODE
) == 0)
2706 || (ELIMINATE_COPY_RELOCS
2707 && !bfd_link_pic (info
)
2709 && (h
->root
.type
== bfd_link_hash_defweak
2710 || !h
->def_regular
)))
2712 struct elf_dyn_relocs
*p
;
2713 struct elf_dyn_relocs
**head
;
2715 /* We must copy these reloc types into the output file.
2716 Create a reloc section in dynobj and make room for
2720 if (htab
->elf
.dynobj
== NULL
)
2721 htab
->elf
.dynobj
= abfd
;
2723 sreloc
= _bfd_elf_make_dynamic_reloc_section
2724 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2725 abfd
, /*rela?*/ TRUE
);
2731 /* If this is a global symbol, we count the number of
2732 relocations we need for this symbol. */
2734 head
= &eh
->dyn_relocs
;
2737 /* Track dynamic relocs needed for local syms too.
2738 We really need local syms available to do this
2743 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2748 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2752 /* Beware of type punned pointers vs strict aliasing
2754 vpp
= &(elf_section_data (s
)->local_dynrel
);
2755 head
= (struct elf_dyn_relocs
**)vpp
;
2759 if (p
== NULL
|| p
->sec
!= sec
)
2761 bfd_size_type amt
= sizeof *p
;
2763 p
= ((struct elf_dyn_relocs
*)
2764 bfd_alloc (htab
->elf
.dynobj
, amt
));
2775 /* Count size relocation as PC-relative relocation. */
2776 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2781 /* This relocation describes the C++ object vtable hierarchy.
2782 Reconstruct it for later use during GC. */
2783 case R_X86_64_GNU_VTINHERIT
:
2784 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2788 /* This relocation describes which C++ vtable entries are actually
2789 used. Record for later use during GC. */
2790 case R_X86_64_GNU_VTENTRY
:
2791 BFD_ASSERT (h
!= NULL
);
2793 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2803 && h
->plt
.refcount
> 0
2804 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2805 || h
->got
.refcount
> 0)
2806 && htab
->plt_got
== NULL
)
2808 /* Create the GOT procedure linkage table. */
2809 unsigned int plt_got_align
;
2810 const struct elf_backend_data
*bed
;
2812 bed
= get_elf_backend_data (info
->output_bfd
);
2813 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry
) == 8
2814 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2815 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2818 if (htab
->elf
.dynobj
== NULL
)
2819 htab
->elf
.dynobj
= abfd
;
2821 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2823 (bed
->dynamic_sec_flags
2828 if (htab
->plt_got
== NULL
2829 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2834 if (!info
->no_ld_generated_unwind_info
2835 && htab
->plt_got_eh_frame
== NULL
2836 && get_elf_x86_64_backend_data (abfd
)->eh_frame_plt_got
!= NULL
)
2838 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2839 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2840 | SEC_LINKER_CREATED
);
2841 htab
->plt_got_eh_frame
2842 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2845 if (htab
->plt_got_eh_frame
== NULL
2846 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2847 htab
->plt_got_eh_frame
,
2848 ABI_64_P (htab
->elf
.dynobj
) ? 3 : 2))
2853 if ((r_type
== R_X86_64_GOTPCREL
2854 || r_type
== R_X86_64_GOTPCRELX
2855 || r_type
== R_X86_64_REX_GOTPCRELX
)
2856 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2857 sec
->need_convert_load
= 1;
2860 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2862 if (!info
->keep_memory
)
2866 /* Cache the section contents for elf_link_input_bfd. */
2867 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2874 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2876 sec
->check_relocs_failed
= 1;
2880 /* Return the section that should be marked against GC for a given
2884 elf_x86_64_gc_mark_hook (asection
*sec
,
2885 struct bfd_link_info
*info
,
2886 Elf_Internal_Rela
*rel
,
2887 struct elf_link_hash_entry
*h
,
2888 Elf_Internal_Sym
*sym
)
2891 switch (ELF32_R_TYPE (rel
->r_info
))
2893 case R_X86_64_GNU_VTINHERIT
:
2894 case R_X86_64_GNU_VTENTRY
:
2898 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2901 /* Remove undefined weak symbol from the dynamic symbol table if it
2902 is resolved to 0. */
2905 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2906 struct elf_link_hash_entry
*h
)
2908 if (h
->dynindx
!= -1
2909 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2910 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2911 elf_x86_64_hash_entry (h
)))
2914 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2920 /* Adjust a symbol defined by a dynamic object and referenced by a
2921 regular object. The current definition is in some section of the
2922 dynamic object, but we're not including those sections. We have to
2923 change the definition to something the rest of the link can
2927 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2928 struct elf_link_hash_entry
*h
)
2930 struct elf_x86_64_link_hash_table
*htab
;
2932 struct elf_x86_64_link_hash_entry
*eh
;
2933 struct elf_dyn_relocs
*p
;
2935 /* STT_GNU_IFUNC symbol must go through PLT. */
2936 if (h
->type
== STT_GNU_IFUNC
)
2938 /* All local STT_GNU_IFUNC references must be treate as local
2939 calls via local PLT. */
2941 && SYMBOL_CALLS_LOCAL (info
, h
))
2943 bfd_size_type pc_count
= 0, count
= 0;
2944 struct elf_dyn_relocs
**pp
;
2946 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2947 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2949 pc_count
+= p
->pc_count
;
2950 p
->count
-= p
->pc_count
;
2959 if (pc_count
|| count
)
2964 /* Increment PLT reference count only for PC-relative
2967 if (h
->plt
.refcount
<= 0)
2968 h
->plt
.refcount
= 1;
2970 h
->plt
.refcount
+= 1;
2975 if (h
->plt
.refcount
<= 0)
2977 h
->plt
.offset
= (bfd_vma
) -1;
2983 /* If this is a function, put it in the procedure linkage table. We
2984 will fill in the contents of the procedure linkage table later,
2985 when we know the address of the .got section. */
2986 if (h
->type
== STT_FUNC
2989 if (h
->plt
.refcount
<= 0
2990 || SYMBOL_CALLS_LOCAL (info
, h
)
2991 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2992 && h
->root
.type
== bfd_link_hash_undefweak
))
2994 /* This case can occur if we saw a PLT32 reloc in an input
2995 file, but the symbol was never referred to by a dynamic
2996 object, or if all references were garbage collected. In
2997 such a case, we don't actually need to build a procedure
2998 linkage table, and we can just do a PC32 reloc instead. */
2999 h
->plt
.offset
= (bfd_vma
) -1;
3006 /* It's possible that we incorrectly decided a .plt reloc was
3007 needed for an R_X86_64_PC32 reloc to a non-function sym in
3008 check_relocs. We can't decide accurately between function and
3009 non-function syms in check-relocs; Objects loaded later in
3010 the link may change h->type. So fix it now. */
3011 h
->plt
.offset
= (bfd_vma
) -1;
3013 /* If this is a weak symbol, and there is a real definition, the
3014 processor independent code will have arranged for us to see the
3015 real definition first, and we can just use the same value. */
3016 if (h
->u
.weakdef
!= NULL
)
3018 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3019 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3020 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3021 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3022 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
3024 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3025 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3026 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
3031 /* This is a reference to a symbol defined by a dynamic object which
3032 is not a function. */
3034 /* If we are creating a shared library, we must presume that the
3035 only references to the symbol are via the global offset table.
3036 For such cases we need not do anything here; the relocations will
3037 be handled correctly by relocate_section. */
3038 if (!bfd_link_executable (info
))
3041 /* If there are no references to this symbol that do not use the
3042 GOT, we don't need to generate a copy reloc. */
3043 if (!h
->non_got_ref
)
3046 /* If -z nocopyreloc was given, we won't generate them either. */
3047 if (info
->nocopyreloc
)
3053 if (ELIMINATE_COPY_RELOCS
)
3055 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3056 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3058 s
= p
->sec
->output_section
;
3059 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3063 /* If we didn't find any dynamic relocs in read-only sections, then
3064 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3072 /* We must allocate the symbol in our .dynbss section, which will
3073 become part of the .bss section of the executable. There will be
3074 an entry for this symbol in the .dynsym section. The dynamic
3075 object will contain position independent code, so all references
3076 from the dynamic object to this symbol will go through the global
3077 offset table. The dynamic linker will use the .dynsym entry to
3078 determine the address it must put in the global offset table, so
3079 both the dynamic object and the regular object will refer to the
3080 same memory location for the variable. */
3082 htab
= elf_x86_64_hash_table (info
);
3086 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3087 to copy the initial value out of the dynamic object and into the
3088 runtime process image. */
3089 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3091 s
= htab
->elf
.sdynrelro
;
3092 srel
= htab
->elf
.sreldynrelro
;
3096 s
= htab
->elf
.sdynbss
;
3097 srel
= htab
->elf
.srelbss
;
3099 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3101 const struct elf_backend_data
*bed
;
3102 bed
= get_elf_backend_data (info
->output_bfd
);
3103 srel
->size
+= bed
->s
->sizeof_rela
;
3107 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3110 /* Allocate space in .plt, .got and associated reloc sections for
3114 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3116 struct bfd_link_info
*info
;
3117 struct elf_x86_64_link_hash_table
*htab
;
3118 struct elf_x86_64_link_hash_entry
*eh
;
3119 struct elf_dyn_relocs
*p
;
3120 const struct elf_backend_data
*bed
;
3121 unsigned int plt_entry_size
;
3122 bfd_boolean resolved_to_zero
;
3124 if (h
->root
.type
== bfd_link_hash_indirect
)
3127 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3129 info
= (struct bfd_link_info
*) inf
;
3130 htab
= elf_x86_64_hash_table (info
);
3133 bed
= get_elf_backend_data (info
->output_bfd
);
3134 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3136 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3140 /* We can't use the GOT PLT if pointer equality is needed since
3141 finish_dynamic_symbol won't clear symbol value and the dynamic
3142 linker won't update the GOT slot. We will get into an infinite
3143 loop at run-time. */
3144 if (htab
->plt_got
!= NULL
3145 && h
->type
!= STT_GNU_IFUNC
3146 && !h
->pointer_equality_needed
3147 && h
->plt
.refcount
> 0
3148 && h
->got
.refcount
> 0)
3150 /* Don't use the regular PLT if there are both GOT and GOTPLT
3152 h
->plt
.offset
= (bfd_vma
) -1;
3154 /* Use the GOT PLT. */
3155 eh
->plt_got
.refcount
= 1;
3158 /* Clear the reference count of function pointer relocations if
3159 symbol isn't a normal function. */
3160 if (h
->type
!= STT_FUNC
)
3161 eh
->func_pointer_refcount
= 0;
3163 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3164 here if it is defined and referenced in a non-shared object. */
3165 if (h
->type
== STT_GNU_IFUNC
3168 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3170 &htab
->readonly_dynrelocs_against_ifunc
,
3173 GOT_ENTRY_SIZE
, TRUE
))
3175 asection
*s
= htab
->plt_bnd
;
3176 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3178 /* Use the .plt.bnd section if it is created. */
3179 eh
->plt_bnd
.offset
= s
->size
;
3181 /* Make room for this entry in the .plt.bnd section. */
3182 s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3190 /* Don't create the PLT entry if there are only function pointer
3191 relocations which can be resolved at run-time. */
3192 else if (htab
->elf
.dynamic_sections_created
3193 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3194 || eh
->plt_got
.refcount
> 0))
3196 bfd_boolean use_plt_got
;
3198 /* Clear the reference count of function pointer relocations
3200 eh
->func_pointer_refcount
= 0;
3202 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
3204 /* Don't use the regular PLT for DF_BIND_NOW. */
3205 h
->plt
.offset
= (bfd_vma
) -1;
3207 /* Use the GOT PLT. */
3208 h
->got
.refcount
= 1;
3209 eh
->plt_got
.refcount
= 1;
3212 use_plt_got
= eh
->plt_got
.refcount
> 0;
3214 /* Make sure this symbol is output as a dynamic symbol.
3215 Undefined weak syms won't yet be marked as dynamic. */
3216 if (h
->dynindx
== -1
3218 && !resolved_to_zero
3219 && h
->root
.type
== bfd_link_hash_undefweak
)
3221 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3225 if (bfd_link_pic (info
)
3226 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3228 asection
*s
= htab
->elf
.splt
;
3229 asection
*bnd_s
= htab
->plt_bnd
;
3230 asection
*got_s
= htab
->plt_got
;
3232 /* If this is the first .plt entry, make room for the special
3233 first entry. The .plt section is used by prelink to undo
3234 prelinking for dynamic relocations. */
3236 s
->size
= plt_entry_size
;
3239 eh
->plt_got
.offset
= got_s
->size
;
3242 h
->plt
.offset
= s
->size
;
3244 eh
->plt_bnd
.offset
= bnd_s
->size
;
3247 /* If this symbol is not defined in a regular file, and we are
3248 not generating a shared library, then set the symbol to this
3249 location in the .plt. This is required to make function
3250 pointers compare as equal between the normal executable and
3251 the shared library. */
3252 if (! bfd_link_pic (info
)
3257 /* We need to make a call to the entry of the GOT PLT
3258 instead of regular PLT entry. */
3259 h
->root
.u
.def
.section
= got_s
;
3260 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3266 /* We need to make a call to the entry of the second
3267 PLT instead of regular PLT entry. */
3268 h
->root
.u
.def
.section
= bnd_s
;
3269 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
3273 h
->root
.u
.def
.section
= s
;
3274 h
->root
.u
.def
.value
= h
->plt
.offset
;
3279 /* Make room for this entry. */
3281 got_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3284 s
->size
+= plt_entry_size
;
3286 bnd_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3288 /* We also need to make an entry in the .got.plt section,
3289 which will be placed in the .got section by the linker
3291 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3293 /* There should be no PLT relocation against resolved
3294 undefined weak symbol in executable. */
3295 if (!resolved_to_zero
)
3297 /* We also need to make an entry in the .rela.plt
3299 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3300 htab
->elf
.srelplt
->reloc_count
++;
3306 eh
->plt_got
.offset
= (bfd_vma
) -1;
3307 h
->plt
.offset
= (bfd_vma
) -1;
3313 eh
->plt_got
.offset
= (bfd_vma
) -1;
3314 h
->plt
.offset
= (bfd_vma
) -1;
3318 eh
->tlsdesc_got
= (bfd_vma
) -1;
3320 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3321 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3322 if (h
->got
.refcount
> 0
3323 && bfd_link_executable (info
)
3325 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3327 h
->got
.offset
= (bfd_vma
) -1;
3329 else if (h
->got
.refcount
> 0)
3333 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3335 /* Make sure this symbol is output as a dynamic symbol.
3336 Undefined weak syms won't yet be marked as dynamic. */
3337 if (h
->dynindx
== -1
3339 && !resolved_to_zero
3340 && h
->root
.type
== bfd_link_hash_undefweak
)
3342 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3346 if (GOT_TLS_GDESC_P (tls_type
))
3348 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3349 - elf_x86_64_compute_jump_table_size (htab
);
3350 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3351 h
->got
.offset
= (bfd_vma
) -2;
3353 if (! GOT_TLS_GDESC_P (tls_type
)
3354 || GOT_TLS_GD_P (tls_type
))
3357 h
->got
.offset
= s
->size
;
3358 s
->size
+= GOT_ENTRY_SIZE
;
3359 if (GOT_TLS_GD_P (tls_type
))
3360 s
->size
+= GOT_ENTRY_SIZE
;
3362 dyn
= htab
->elf
.dynamic_sections_created
;
3363 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3364 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3365 relocation. No dynamic relocation against resolved undefined
3366 weak symbol in executable. */
3367 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3368 || tls_type
== GOT_TLS_IE
)
3369 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3370 else if (GOT_TLS_GD_P (tls_type
))
3371 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3372 else if (! GOT_TLS_GDESC_P (tls_type
)
3373 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3374 && !resolved_to_zero
)
3375 || h
->root
.type
!= bfd_link_hash_undefweak
)
3376 && (bfd_link_pic (info
)
3377 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3378 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3379 if (GOT_TLS_GDESC_P (tls_type
))
3381 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3382 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3386 h
->got
.offset
= (bfd_vma
) -1;
3388 if (eh
->dyn_relocs
== NULL
)
3391 /* In the shared -Bsymbolic case, discard space allocated for
3392 dynamic pc-relative relocs against symbols which turn out to be
3393 defined in regular objects. For the normal shared case, discard
3394 space for pc-relative relocs that have become local due to symbol
3395 visibility changes. */
3397 if (bfd_link_pic (info
))
3399 /* Relocs that use pc_count are those that appear on a call
3400 insn, or certain REL relocs that can generated via assembly.
3401 We want calls to protected symbols to resolve directly to the
3402 function rather than going via the plt. If people want
3403 function pointer comparisons to work as expected then they
3404 should avoid writing weird assembly. */
3405 if (SYMBOL_CALLS_LOCAL (info
, h
))
3407 struct elf_dyn_relocs
**pp
;
3409 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3411 p
->count
-= p
->pc_count
;
3420 /* Also discard relocs on undefined weak syms with non-default
3421 visibility or in PIE. */
3422 if (eh
->dyn_relocs
!= NULL
)
3424 if (h
->root
.type
== bfd_link_hash_undefweak
)
3426 /* Undefined weak symbol is never bound locally in shared
3428 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3429 || resolved_to_zero
)
3430 eh
->dyn_relocs
= NULL
;
3431 else if (h
->dynindx
== -1
3432 && ! h
->forced_local
3433 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3436 /* For PIE, discard space for pc-relative relocs against
3437 symbols which turn out to need copy relocs. */
3438 else if (bfd_link_executable (info
)
3439 && (h
->needs_copy
|| eh
->needs_copy
)
3443 struct elf_dyn_relocs
**pp
;
3445 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3447 if (p
->pc_count
!= 0)
3455 else if (ELIMINATE_COPY_RELOCS
)
3457 /* For the non-shared case, discard space for relocs against
3458 symbols which turn out to need copy relocs or are not
3459 dynamic. Keep dynamic relocations for run-time function
3460 pointer initialization. */
3462 if ((!h
->non_got_ref
3463 || eh
->func_pointer_refcount
> 0
3464 || (h
->root
.type
== bfd_link_hash_undefweak
3465 && !resolved_to_zero
))
3468 || (htab
->elf
.dynamic_sections_created
3469 && (h
->root
.type
== bfd_link_hash_undefweak
3470 || h
->root
.type
== bfd_link_hash_undefined
))))
3472 /* Make sure this symbol is output as a dynamic symbol.
3473 Undefined weak syms won't yet be marked as dynamic. */
3474 if (h
->dynindx
== -1
3475 && ! h
->forced_local
3476 && ! resolved_to_zero
3477 && h
->root
.type
== bfd_link_hash_undefweak
3478 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3481 /* If that succeeded, we know we'll be keeping all the
3483 if (h
->dynindx
!= -1)
3487 eh
->dyn_relocs
= NULL
;
3488 eh
->func_pointer_refcount
= 0;
3493 /* Finally, allocate space. */
3494 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3498 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3500 BFD_ASSERT (sreloc
!= NULL
);
3502 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3508 /* Allocate space in .plt, .got and associated reloc sections for
3509 local dynamic relocs. */
3512 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3514 struct elf_link_hash_entry
*h
3515 = (struct elf_link_hash_entry
*) *slot
;
3517 if (h
->type
!= STT_GNU_IFUNC
3521 || h
->root
.type
!= bfd_link_hash_defined
)
3524 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3527 /* Find any dynamic relocs that apply to read-only sections. */
3530 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3533 struct elf_x86_64_link_hash_entry
*eh
;
3534 struct elf_dyn_relocs
*p
;
3536 /* Skip local IFUNC symbols. */
3537 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3540 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3541 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3543 asection
*s
= p
->sec
->output_section
;
3545 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3547 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3549 info
->flags
|= DF_TEXTREL
;
3551 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3552 || info
->error_textrel
)
3553 /* xgettext:c-format */
3554 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3555 p
->sec
->owner
, h
->root
.root
.string
,
3558 /* Not an error, just cut short the traversal. */
3565 /* Convert load via the GOT slot to load immediate. */
3568 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3569 struct bfd_link_info
*link_info
)
3571 Elf_Internal_Shdr
*symtab_hdr
;
3572 Elf_Internal_Rela
*internal_relocs
;
3573 Elf_Internal_Rela
*irel
, *irelend
;
3575 struct elf_x86_64_link_hash_table
*htab
;
3576 bfd_boolean changed
;
3577 bfd_signed_vma
*local_got_refcounts
;
3579 /* Don't even try to convert non-ELF outputs. */
3580 if (!is_elf_hash_table (link_info
->hash
))
3583 /* Nothing to do if there is no need or no output. */
3584 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3585 || sec
->need_convert_load
== 0
3586 || bfd_is_abs_section (sec
->output_section
))
3589 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3591 /* Load the relocations for this section. */
3592 internal_relocs
= (_bfd_elf_link_read_relocs
3593 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3594 link_info
->keep_memory
));
3595 if (internal_relocs
== NULL
)
3599 htab
= elf_x86_64_hash_table (link_info
);
3600 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3602 /* Get the section contents. */
3603 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3604 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3607 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3611 irelend
= internal_relocs
+ sec
->reloc_count
;
3612 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3614 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3615 unsigned int r_symndx
;
3616 struct elf_link_hash_entry
*h
;
3617 bfd_boolean converted
;
3619 if (r_type
!= R_X86_64_GOTPCRELX
3620 && r_type
!= R_X86_64_REX_GOTPCRELX
3621 && r_type
!= R_X86_64_GOTPCREL
)
3624 r_symndx
= htab
->r_sym (irel
->r_info
);
3625 if (r_symndx
< symtab_hdr
->sh_info
)
3626 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3627 (const Elf_Internal_Rela
*) irel
,
3631 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3632 while (h
->root
.type
== bfd_link_hash_indirect
3633 || h
->root
.type
== bfd_link_hash_warning
)
3634 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3637 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3638 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3642 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3643 &converted
, link_info
))
3648 changed
= converted
;
3651 if (h
->got
.refcount
> 0)
3652 h
->got
.refcount
-= 1;
3656 if (local_got_refcounts
!= NULL
3657 && local_got_refcounts
[r_symndx
] > 0)
3658 local_got_refcounts
[r_symndx
] -= 1;
3663 if (contents
!= NULL
3664 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3666 if (!changed
&& !link_info
->keep_memory
)
3670 /* Cache the section contents for elf_link_input_bfd. */
3671 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3675 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3678 free (internal_relocs
);
3680 elf_section_data (sec
)->relocs
= internal_relocs
;
3686 if (contents
!= NULL
3687 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3689 if (internal_relocs
!= NULL
3690 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3691 free (internal_relocs
);
3695 /* Set the sizes of the dynamic sections. */
3698 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3699 struct bfd_link_info
*info
)
3701 struct elf_x86_64_link_hash_table
*htab
;
3706 const struct elf_backend_data
*bed
;
3707 const struct elf_x86_64_backend_data
*arch_data
;
3709 htab
= elf_x86_64_hash_table (info
);
3712 bed
= get_elf_backend_data (output_bfd
);
3714 dynobj
= htab
->elf
.dynobj
;
3718 /* Set up .got offsets for local syms, and space for local dynamic
3720 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3722 bfd_signed_vma
*local_got
;
3723 bfd_signed_vma
*end_local_got
;
3724 char *local_tls_type
;
3725 bfd_vma
*local_tlsdesc_gotent
;
3726 bfd_size_type locsymcount
;
3727 Elf_Internal_Shdr
*symtab_hdr
;
3730 if (! is_x86_64_elf (ibfd
))
3733 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3735 struct elf_dyn_relocs
*p
;
3737 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3740 for (p
= (struct elf_dyn_relocs
*)
3741 (elf_section_data (s
)->local_dynrel
);
3745 if (!bfd_is_abs_section (p
->sec
)
3746 && bfd_is_abs_section (p
->sec
->output_section
))
3748 /* Input section has been discarded, either because
3749 it is a copy of a linkonce section or due to
3750 linker script /DISCARD/, so we'll be discarding
3753 else if (p
->count
!= 0)
3755 srel
= elf_section_data (p
->sec
)->sreloc
;
3756 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3757 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3758 && (info
->flags
& DF_TEXTREL
) == 0)
3760 info
->flags
|= DF_TEXTREL
;
3761 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3762 || info
->error_textrel
)
3763 /* xgettext:c-format */
3764 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3765 p
->sec
->owner
, p
->sec
);
3771 local_got
= elf_local_got_refcounts (ibfd
);
3775 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3776 locsymcount
= symtab_hdr
->sh_info
;
3777 end_local_got
= local_got
+ locsymcount
;
3778 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3779 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3781 srel
= htab
->elf
.srelgot
;
3782 for (; local_got
< end_local_got
;
3783 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3785 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3788 if (GOT_TLS_GDESC_P (*local_tls_type
))
3790 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3791 - elf_x86_64_compute_jump_table_size (htab
);
3792 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3793 *local_got
= (bfd_vma
) -2;
3795 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3796 || GOT_TLS_GD_P (*local_tls_type
))
3798 *local_got
= s
->size
;
3799 s
->size
+= GOT_ENTRY_SIZE
;
3800 if (GOT_TLS_GD_P (*local_tls_type
))
3801 s
->size
+= GOT_ENTRY_SIZE
;
3803 if (bfd_link_pic (info
)
3804 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3805 || *local_tls_type
== GOT_TLS_IE
)
3807 if (GOT_TLS_GDESC_P (*local_tls_type
))
3809 htab
->elf
.srelplt
->size
3810 += bed
->s
->sizeof_rela
;
3811 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3813 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3814 || GOT_TLS_GD_P (*local_tls_type
))
3815 srel
->size
+= bed
->s
->sizeof_rela
;
3819 *local_got
= (bfd_vma
) -1;
3823 if (htab
->tls_ld_got
.refcount
> 0)
3825 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3827 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3828 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3829 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3832 htab
->tls_ld_got
.offset
= -1;
3834 /* Allocate global sym .plt and .got entries, and space for global
3835 sym dynamic relocs. */
3836 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3839 /* Allocate .plt and .got entries, and space for local symbols. */
3840 htab_traverse (htab
->loc_hash_table
,
3841 elf_x86_64_allocate_local_dynrelocs
,
3844 /* For every jump slot reserved in the sgotplt, reloc_count is
3845 incremented. However, when we reserve space for TLS descriptors,
3846 it's not incremented, so in order to compute the space reserved
3847 for them, it suffices to multiply the reloc count by the jump
3850 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3851 so that R_X86_64_IRELATIVE entries come last. */
3852 if (htab
->elf
.srelplt
)
3854 htab
->sgotplt_jump_table_size
3855 = elf_x86_64_compute_jump_table_size (htab
);
3856 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3858 else if (htab
->elf
.irelplt
)
3859 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3861 if (htab
->tlsdesc_plt
)
3863 /* If we're not using lazy TLS relocations, don't generate the
3864 PLT and GOT entries they require. */
3865 if ((info
->flags
& DF_BIND_NOW
))
3866 htab
->tlsdesc_plt
= 0;
3869 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3870 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3871 /* Reserve room for the initial entry.
3872 FIXME: we could probably do away with it in this case. */
3873 if (htab
->elf
.splt
->size
== 0)
3874 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3875 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3876 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3880 if (htab
->elf
.sgotplt
)
3882 /* Don't allocate .got.plt section if there are no GOT nor PLT
3883 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3884 if ((htab
->elf
.hgot
== NULL
3885 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3886 && (htab
->elf
.sgotplt
->size
3887 == get_elf_backend_data (output_bfd
)->got_header_size
)
3888 && (htab
->elf
.splt
== NULL
3889 || htab
->elf
.splt
->size
== 0)
3890 && (htab
->elf
.sgot
== NULL
3891 || htab
->elf
.sgot
->size
== 0)
3892 && (htab
->elf
.iplt
== NULL
3893 || htab
->elf
.iplt
->size
== 0)
3894 && (htab
->elf
.igotplt
== NULL
3895 || htab
->elf
.igotplt
->size
== 0))
3896 htab
->elf
.sgotplt
->size
= 0;
3899 arch_data
= (htab
->plt_bnd
!= NULL
3900 ? &elf_x86_64_bnd_arch_bed
3901 : get_elf_x86_64_arch_data (bed
));
3903 if (_bfd_elf_eh_frame_present (info
))
3905 if (htab
->plt_eh_frame
!= NULL
3906 && htab
->elf
.splt
!= NULL
3907 && htab
->elf
.splt
->size
!= 0
3908 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3909 htab
->plt_eh_frame
->size
= arch_data
->eh_frame_plt_size
;
3911 if (htab
->plt_got_eh_frame
!= NULL
3912 && htab
->plt_got
!= NULL
3913 && htab
->plt_got
->size
!= 0
3914 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3915 htab
->plt_got_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3917 /* Unwind info for .plt.bnd and .plt.got sections are
3919 if (htab
->plt_bnd_eh_frame
!= NULL
3920 && htab
->plt_bnd
!= NULL
3921 && htab
->plt_bnd
->size
!= 0
3922 && !bfd_is_abs_section (htab
->plt_bnd
->output_section
))
3923 htab
->plt_bnd_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3926 /* We now have determined the sizes of the various dynamic sections.
3927 Allocate memory for them. */
3929 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3931 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3934 if (s
== htab
->elf
.splt
3935 || s
== htab
->elf
.sgot
3936 || s
== htab
->elf
.sgotplt
3937 || s
== htab
->elf
.iplt
3938 || s
== htab
->elf
.igotplt
3939 || s
== htab
->plt_bnd
3940 || s
== htab
->plt_got
3941 || s
== htab
->plt_eh_frame
3942 || s
== htab
->plt_got_eh_frame
3943 || s
== htab
->plt_bnd_eh_frame
3944 || s
== htab
->elf
.sdynbss
3945 || s
== htab
->elf
.sdynrelro
)
3947 /* Strip this section if we don't need it; see the
3950 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3952 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3955 /* We use the reloc_count field as a counter if we need
3956 to copy relocs into the output file. */
3957 if (s
!= htab
->elf
.srelplt
)
3962 /* It's not one of our sections, so don't allocate space. */
3968 /* If we don't need this section, strip it from the
3969 output file. This is mostly to handle .rela.bss and
3970 .rela.plt. We must create both sections in
3971 create_dynamic_sections, because they must be created
3972 before the linker maps input sections to output
3973 sections. The linker does that before
3974 adjust_dynamic_symbol is called, and it is that
3975 function which decides whether anything needs to go
3976 into these sections. */
3978 s
->flags
|= SEC_EXCLUDE
;
3982 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3985 /* Allocate memory for the section contents. We use bfd_zalloc
3986 here in case unused entries are not reclaimed before the
3987 section's contents are written out. This should not happen,
3988 but this way if it does, we get a R_X86_64_NONE reloc instead
3990 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3991 if (s
->contents
== NULL
)
3995 if (htab
->plt_eh_frame
!= NULL
3996 && htab
->plt_eh_frame
->contents
!= NULL
)
3998 memcpy (htab
->plt_eh_frame
->contents
,
3999 arch_data
->eh_frame_plt
, htab
->plt_eh_frame
->size
);
4000 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
4001 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
4004 if (htab
->plt_got_eh_frame
!= NULL
4005 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4007 memcpy (htab
->plt_got_eh_frame
->contents
,
4008 arch_data
->eh_frame_plt_got
,
4009 htab
->plt_got_eh_frame
->size
);
4010 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
4011 (htab
->plt_got_eh_frame
->contents
4012 + PLT_FDE_LEN_OFFSET
));
4015 if (htab
->plt_bnd_eh_frame
!= NULL
4016 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
4018 memcpy (htab
->plt_bnd_eh_frame
->contents
,
4019 arch_data
->eh_frame_plt_got
,
4020 htab
->plt_bnd_eh_frame
->size
);
4021 bfd_put_32 (dynobj
, htab
->plt_bnd
->size
,
4022 (htab
->plt_bnd_eh_frame
->contents
4023 + PLT_FDE_LEN_OFFSET
));
4026 if (htab
->elf
.dynamic_sections_created
)
4028 /* Add some entries to the .dynamic section. We fill in the
4029 values later, in elf_x86_64_finish_dynamic_sections, but we
4030 must add the entries now so that we get the correct size for
4031 the .dynamic section. The DT_DEBUG entry is filled in by the
4032 dynamic linker and used by the debugger. */
4033 #define add_dynamic_entry(TAG, VAL) \
4034 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4036 if (bfd_link_executable (info
))
4038 if (!add_dynamic_entry (DT_DEBUG
, 0))
4042 if (htab
->elf
.splt
->size
!= 0)
4044 /* DT_PLTGOT is used by prelink even if there is no PLT
4046 if (!add_dynamic_entry (DT_PLTGOT
, 0))
4050 if (htab
->elf
.srelplt
->size
!= 0)
4052 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
4053 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4054 || !add_dynamic_entry (DT_JMPREL
, 0))
4058 if (htab
->tlsdesc_plt
4059 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
4060 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
4065 if (!add_dynamic_entry (DT_RELA
, 0)
4066 || !add_dynamic_entry (DT_RELASZ
, 0)
4067 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
4070 /* If any dynamic relocs apply to a read-only section,
4071 then we need a DT_TEXTREL entry. */
4072 if ((info
->flags
& DF_TEXTREL
) == 0)
4073 elf_link_hash_traverse (&htab
->elf
,
4074 elf_x86_64_readonly_dynrelocs
,
4077 if ((info
->flags
& DF_TEXTREL
) != 0)
4079 if (htab
->readonly_dynrelocs_against_ifunc
)
4081 info
->callbacks
->einfo
4082 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4083 bfd_set_error (bfd_error_bad_value
);
4087 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4092 #undef add_dynamic_entry
4098 elf_x86_64_always_size_sections (bfd
*output_bfd
,
4099 struct bfd_link_info
*info
)
4101 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
4105 struct elf_link_hash_entry
*tlsbase
;
4107 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
4108 "_TLS_MODULE_BASE_",
4109 FALSE
, FALSE
, FALSE
);
4111 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
4113 struct elf_x86_64_link_hash_table
*htab
;
4114 struct bfd_link_hash_entry
*bh
= NULL
;
4115 const struct elf_backend_data
*bed
4116 = get_elf_backend_data (output_bfd
);
4118 htab
= elf_x86_64_hash_table (info
);
4122 if (!(_bfd_generic_link_add_one_symbol
4123 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
4124 tls_sec
, 0, NULL
, FALSE
,
4125 bed
->collect
, &bh
)))
4128 htab
->tls_module_base
= bh
;
4130 tlsbase
= (struct elf_link_hash_entry
*)bh
;
4131 tlsbase
->def_regular
= 1;
4132 tlsbase
->other
= STV_HIDDEN
;
4133 tlsbase
->root
.linker_def
= 1;
4134 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4141 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4142 executables. Rather than setting it to the beginning of the TLS
4143 section, we have to set it to the end. This function may be called
4144 multiple times, it is idempotent. */
4147 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4149 struct elf_x86_64_link_hash_table
*htab
;
4150 struct bfd_link_hash_entry
*base
;
4152 if (!bfd_link_executable (info
))
4155 htab
= elf_x86_64_hash_table (info
);
4159 base
= htab
->tls_module_base
;
4163 base
->u
.def
.value
= htab
->elf
.tls_size
;
4166 /* Return the base VMA address which should be subtracted from real addresses
4167 when resolving @dtpoff relocation.
4168 This is PT_TLS segment p_vaddr. */
4171 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4173 /* If tls_sec is NULL, we should have signalled an error already. */
4174 if (elf_hash_table (info
)->tls_sec
== NULL
)
4176 return elf_hash_table (info
)->tls_sec
->vma
;
4179 /* Return the relocation value for @tpoff relocation
4180 if STT_TLS virtual address is ADDRESS. */
4183 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4185 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4186 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4187 bfd_vma static_tls_size
;
4189 /* If tls_segment is NULL, we should have signalled an error already. */
4190 if (htab
->tls_sec
== NULL
)
4193 /* Consider special static TLS alignment requirements. */
4194 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4195 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4198 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4202 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4204 /* Opcode Instruction
4207 0x0f 0x8x conditional jump */
4209 && (contents
[offset
- 1] == 0xe8
4210 || contents
[offset
- 1] == 0xe9))
4212 && contents
[offset
- 2] == 0x0f
4213 && (contents
[offset
- 1] & 0xf0) == 0x80));
4216 /* Relocate an x86_64 ELF section. */
4219 elf_x86_64_relocate_section (bfd
*output_bfd
,
4220 struct bfd_link_info
*info
,
4222 asection
*input_section
,
4224 Elf_Internal_Rela
*relocs
,
4225 Elf_Internal_Sym
*local_syms
,
4226 asection
**local_sections
)
4228 struct elf_x86_64_link_hash_table
*htab
;
4229 Elf_Internal_Shdr
*symtab_hdr
;
4230 struct elf_link_hash_entry
**sym_hashes
;
4231 bfd_vma
*local_got_offsets
;
4232 bfd_vma
*local_tlsdesc_gotents
;
4233 Elf_Internal_Rela
*rel
;
4234 Elf_Internal_Rela
*wrel
;
4235 Elf_Internal_Rela
*relend
;
4236 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
4238 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4240 /* Skip if check_relocs failed. */
4241 if (input_section
->check_relocs_failed
)
4244 htab
= elf_x86_64_hash_table (info
);
4247 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4248 sym_hashes
= elf_sym_hashes (input_bfd
);
4249 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4250 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4252 elf_x86_64_set_tls_module_base (info
);
4254 rel
= wrel
= relocs
;
4255 relend
= relocs
+ input_section
->reloc_count
;
4256 for (; rel
< relend
; wrel
++, rel
++)
4258 unsigned int r_type
;
4259 reloc_howto_type
*howto
;
4260 unsigned long r_symndx
;
4261 struct elf_link_hash_entry
*h
;
4262 struct elf_x86_64_link_hash_entry
*eh
;
4263 Elf_Internal_Sym
*sym
;
4265 bfd_vma off
, offplt
, plt_offset
;
4267 bfd_boolean unresolved_reloc
;
4268 bfd_reloc_status_type r
;
4270 asection
*base_got
, *resolved_plt
;
4272 bfd_boolean resolved_to_zero
;
4273 bfd_boolean relative_reloc
;
4275 r_type
= ELF32_R_TYPE (rel
->r_info
);
4276 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4277 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4284 if (r_type
>= (int) R_X86_64_standard
)
4287 /* xgettext:c-format */
4288 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4289 input_bfd
, r_type
, input_section
);
4290 bfd_set_error (bfd_error_bad_value
);
4294 if (r_type
!= (int) R_X86_64_32
4295 || ABI_64_P (output_bfd
))
4296 howto
= x86_64_elf_howto_table
+ r_type
;
4298 howto
= (x86_64_elf_howto_table
4299 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4300 r_symndx
= htab
->r_sym (rel
->r_info
);
4304 unresolved_reloc
= FALSE
;
4305 if (r_symndx
< symtab_hdr
->sh_info
)
4307 sym
= local_syms
+ r_symndx
;
4308 sec
= local_sections
[r_symndx
];
4310 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4312 st_size
= sym
->st_size
;
4314 /* Relocate against local STT_GNU_IFUNC symbol. */
4315 if (!bfd_link_relocatable (info
)
4316 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4318 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4323 /* Set STT_GNU_IFUNC symbol value. */
4324 h
->root
.u
.def
.value
= sym
->st_value
;
4325 h
->root
.u
.def
.section
= sec
;
4330 bfd_boolean warned ATTRIBUTE_UNUSED
;
4331 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4333 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4334 r_symndx
, symtab_hdr
, sym_hashes
,
4336 unresolved_reloc
, warned
, ignored
);
4340 if (sec
!= NULL
&& discarded_section (sec
))
4342 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4343 contents
+ rel
->r_offset
);
4344 wrel
->r_offset
= rel
->r_offset
;
4348 /* For ld -r, remove relocations in debug sections against
4349 sections defined in discarded sections. Not done for
4350 eh_frame editing code expects to be present. */
4351 if (bfd_link_relocatable (info
)
4352 && (input_section
->flags
& SEC_DEBUGGING
))
4358 if (bfd_link_relocatable (info
))
4365 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4367 if (r_type
== R_X86_64_64
)
4369 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4370 zero-extend it to 64bit if addend is zero. */
4371 r_type
= R_X86_64_32
;
4372 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4374 else if (r_type
== R_X86_64_SIZE64
)
4376 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4377 zero-extend it to 64bit if addend is zero. */
4378 r_type
= R_X86_64_SIZE32
;
4379 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4383 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4385 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4386 it here if it is defined in a non-shared object. */
4388 && h
->type
== STT_GNU_IFUNC
4394 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4396 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4397 sections because such sections are not SEC_ALLOC and
4398 thus ld.so will not process them. */
4399 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4409 case R_X86_64_GOTPCREL
:
4410 case R_X86_64_GOTPCRELX
:
4411 case R_X86_64_REX_GOTPCRELX
:
4412 case R_X86_64_GOTPCREL64
:
4413 base_got
= htab
->elf
.sgot
;
4414 off
= h
->got
.offset
;
4416 if (base_got
== NULL
)
4419 if (off
== (bfd_vma
) -1)
4421 /* We can't use h->got.offset here to save state, or
4422 even just remember the offset, as finish_dynamic_symbol
4423 would use that as offset into .got. */
4425 if (h
->plt
.offset
== (bfd_vma
) -1)
4428 if (htab
->elf
.splt
!= NULL
)
4430 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4431 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4432 base_got
= htab
->elf
.sgotplt
;
4436 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4437 off
= plt_index
* GOT_ENTRY_SIZE
;
4438 base_got
= htab
->elf
.igotplt
;
4441 if (h
->dynindx
== -1
4445 /* This references the local defitionion. We must
4446 initialize this entry in the global offset table.
4447 Since the offset must always be a multiple of 8,
4448 we use the least significant bit to record
4449 whether we have initialized it already.
4451 When doing a dynamic link, we create a .rela.got
4452 relocation entry to initialize the value. This
4453 is done in the finish_dynamic_symbol routine. */
4458 bfd_put_64 (output_bfd
, relocation
,
4459 base_got
->contents
+ off
);
4460 /* Note that this is harmless for the GOTPLT64
4461 case, as -1 | 1 still is -1. */
4467 relocation
= (base_got
->output_section
->vma
4468 + base_got
->output_offset
+ off
);
4473 if (h
->plt
.offset
== (bfd_vma
) -1)
4475 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4476 if (r_type
== htab
->pointer_r_type
4477 && (input_section
->flags
& SEC_CODE
) == 0)
4478 goto do_ifunc_pointer
;
4479 goto bad_ifunc_reloc
;
4482 /* STT_GNU_IFUNC symbol must go through PLT. */
4483 if (htab
->elf
.splt
!= NULL
)
4485 if (htab
->plt_bnd
!= NULL
)
4487 resolved_plt
= htab
->plt_bnd
;
4488 plt_offset
= eh
->plt_bnd
.offset
;
4492 resolved_plt
= htab
->elf
.splt
;
4493 plt_offset
= h
->plt
.offset
;
4498 resolved_plt
= htab
->elf
.iplt
;
4499 plt_offset
= h
->plt
.offset
;
4502 relocation
= (resolved_plt
->output_section
->vma
4503 + resolved_plt
->output_offset
+ plt_offset
);
4509 if (h
->root
.root
.string
)
4510 name
= h
->root
.root
.string
;
4512 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4515 /* xgettext:c-format */
4516 (_("%B: relocation %s against STT_GNU_IFUNC "
4517 "symbol `%s' isn't supported"), input_bfd
,
4519 bfd_set_error (bfd_error_bad_value
);
4523 if (bfd_link_pic (info
))
4528 if (ABI_64_P (output_bfd
))
4533 if (rel
->r_addend
!= 0)
4535 if (h
->root
.root
.string
)
4536 name
= h
->root
.root
.string
;
4538 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4541 /* xgettext:c-format */
4542 (_("%B: relocation %s against STT_GNU_IFUNC "
4543 "symbol `%s' has non-zero addend: %d"),
4544 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4545 bfd_set_error (bfd_error_bad_value
);
4549 /* Generate dynamic relcoation only when there is a
4550 non-GOT reference in a shared object or there is no
4552 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4553 || h
->plt
.offset
== (bfd_vma
) -1)
4555 Elf_Internal_Rela outrel
;
4558 /* Need a dynamic relocation to get the real function
4560 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4564 if (outrel
.r_offset
== (bfd_vma
) -1
4565 || outrel
.r_offset
== (bfd_vma
) -2)
4568 outrel
.r_offset
+= (input_section
->output_section
->vma
4569 + input_section
->output_offset
);
4571 if (h
->dynindx
== -1
4573 || bfd_link_executable (info
))
4575 /* This symbol is resolved locally. */
4576 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4577 outrel
.r_addend
= (h
->root
.u
.def
.value
4578 + h
->root
.u
.def
.section
->output_section
->vma
4579 + h
->root
.u
.def
.section
->output_offset
);
4583 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4584 outrel
.r_addend
= 0;
4587 /* Dynamic relocations are stored in
4588 1. .rela.ifunc section in PIC object.
4589 2. .rela.got section in dynamic executable.
4590 3. .rela.iplt section in static executable. */
4591 if (bfd_link_pic (info
))
4592 sreloc
= htab
->elf
.irelifunc
;
4593 else if (htab
->elf
.splt
!= NULL
)
4594 sreloc
= htab
->elf
.srelgot
;
4596 sreloc
= htab
->elf
.irelplt
;
4597 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4599 /* If this reloc is against an external symbol, we
4600 do not want to fiddle with the addend. Otherwise,
4601 we need to include the symbol value so that it
4602 becomes an addend for the dynamic reloc. For an
4603 internal symbol, we have updated addend. */
4608 case R_X86_64_PC32_BND
:
4610 case R_X86_64_PLT32
:
4611 case R_X86_64_PLT32_BND
:
4616 resolved_to_zero
= (eh
!= NULL
4617 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4621 /* When generating a shared object, the relocations handled here are
4622 copied into the output file to be resolved at run time. */
4625 case R_X86_64_GOT32
:
4626 case R_X86_64_GOT64
:
4627 /* Relocation is to the entry for this symbol in the global
4629 case R_X86_64_GOTPCREL
:
4630 case R_X86_64_GOTPCRELX
:
4631 case R_X86_64_REX_GOTPCRELX
:
4632 case R_X86_64_GOTPCREL64
:
4633 /* Use global offset table entry as symbol value. */
4634 case R_X86_64_GOTPLT64
:
4635 /* This is obsolete and treated the the same as GOT64. */
4636 base_got
= htab
->elf
.sgot
;
4638 if (htab
->elf
.sgot
== NULL
)
4641 relative_reloc
= FALSE
;
4646 off
= h
->got
.offset
;
4648 && h
->plt
.offset
!= (bfd_vma
)-1
4649 && off
== (bfd_vma
)-1)
4651 /* We can't use h->got.offset here to save
4652 state, or even just remember the offset, as
4653 finish_dynamic_symbol would use that as offset into
4655 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4656 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4657 base_got
= htab
->elf
.sgotplt
;
4660 dyn
= htab
->elf
.dynamic_sections_created
;
4662 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4663 || (bfd_link_pic (info
)
4664 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4665 || (ELF_ST_VISIBILITY (h
->other
)
4666 && h
->root
.type
== bfd_link_hash_undefweak
))
4668 /* This is actually a static link, or it is a -Bsymbolic
4669 link and the symbol is defined locally, or the symbol
4670 was forced to be local because of a version file. We
4671 must initialize this entry in the global offset table.
4672 Since the offset must always be a multiple of 8, we
4673 use the least significant bit to record whether we
4674 have initialized it already.
4676 When doing a dynamic link, we create a .rela.got
4677 relocation entry to initialize the value. This is
4678 done in the finish_dynamic_symbol routine. */
4683 bfd_put_64 (output_bfd
, relocation
,
4684 base_got
->contents
+ off
);
4685 /* Note that this is harmless for the GOTPLT64 case,
4686 as -1 | 1 still is -1. */
4689 if (h
->dynindx
== -1
4691 && h
->root
.type
!= bfd_link_hash_undefweak
4692 && bfd_link_pic (info
))
4694 /* If this symbol isn't dynamic in PIC,
4695 generate R_X86_64_RELATIVE here. */
4696 eh
->no_finish_dynamic_symbol
= 1;
4697 relative_reloc
= TRUE
;
4702 unresolved_reloc
= FALSE
;
4706 if (local_got_offsets
== NULL
)
4709 off
= local_got_offsets
[r_symndx
];
4711 /* The offset must always be a multiple of 8. We use
4712 the least significant bit to record whether we have
4713 already generated the necessary reloc. */
4718 bfd_put_64 (output_bfd
, relocation
,
4719 base_got
->contents
+ off
);
4720 local_got_offsets
[r_symndx
] |= 1;
4722 if (bfd_link_pic (info
))
4723 relative_reloc
= TRUE
;
4730 Elf_Internal_Rela outrel
;
4732 /* We need to generate a R_X86_64_RELATIVE reloc
4733 for the dynamic linker. */
4734 s
= htab
->elf
.srelgot
;
4738 outrel
.r_offset
= (base_got
->output_section
->vma
4739 + base_got
->output_offset
4741 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4742 outrel
.r_addend
= relocation
;
4743 elf_append_rela (output_bfd
, s
, &outrel
);
4746 if (off
>= (bfd_vma
) -2)
4749 relocation
= base_got
->output_section
->vma
4750 + base_got
->output_offset
+ off
;
4751 if (r_type
!= R_X86_64_GOTPCREL
4752 && r_type
!= R_X86_64_GOTPCRELX
4753 && r_type
!= R_X86_64_REX_GOTPCRELX
4754 && r_type
!= R_X86_64_GOTPCREL64
)
4755 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4756 - htab
->elf
.sgotplt
->output_offset
;
4760 case R_X86_64_GOTOFF64
:
4761 /* Relocation is relative to the start of the global offset
4764 /* Check to make sure it isn't a protected function or data
4765 symbol for shared library since it may not be local when
4766 used as function address or with copy relocation. We also
4767 need to make sure that a symbol is referenced locally. */
4768 if (bfd_link_pic (info
) && h
)
4770 if (!h
->def_regular
)
4774 switch (ELF_ST_VISIBILITY (h
->other
))
4777 v
= _("hidden symbol");
4780 v
= _("internal symbol");
4783 v
= _("protected symbol");
4791 /* xgettext:c-format */
4792 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4793 " `%s' can not be used when making a shared object"),
4794 input_bfd
, v
, h
->root
.root
.string
);
4795 bfd_set_error (bfd_error_bad_value
);
4798 else if (!bfd_link_executable (info
)
4799 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4800 && (h
->type
== STT_FUNC
4801 || h
->type
== STT_OBJECT
)
4802 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4805 /* xgettext:c-format */
4806 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4807 " `%s' can not be used when making a shared object"),
4809 h
->type
== STT_FUNC
? "function" : "data",
4810 h
->root
.root
.string
);
4811 bfd_set_error (bfd_error_bad_value
);
4816 /* Note that sgot is not involved in this
4817 calculation. We always want the start of .got.plt. If we
4818 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4819 permitted by the ABI, we might have to change this
4821 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4822 + htab
->elf
.sgotplt
->output_offset
;
4825 case R_X86_64_GOTPC32
:
4826 case R_X86_64_GOTPC64
:
4827 /* Use global offset table as symbol value. */
4828 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4829 + htab
->elf
.sgotplt
->output_offset
;
4830 unresolved_reloc
= FALSE
;
4833 case R_X86_64_PLTOFF64
:
4834 /* Relocation is PLT entry relative to GOT. For local
4835 symbols it's the symbol itself relative to GOT. */
4837 /* See PLT32 handling. */
4838 && (h
->plt
.offset
!= (bfd_vma
) -1
4839 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4840 && htab
->elf
.splt
!= NULL
)
4842 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4844 /* Use the GOT PLT. */
4845 resolved_plt
= htab
->plt_got
;
4846 plt_offset
= eh
->plt_got
.offset
;
4848 else if (htab
->plt_bnd
!= NULL
)
4850 resolved_plt
= htab
->plt_bnd
;
4851 plt_offset
= eh
->plt_bnd
.offset
;
4855 resolved_plt
= htab
->elf
.splt
;
4856 plt_offset
= h
->plt
.offset
;
4859 relocation
= (resolved_plt
->output_section
->vma
4860 + resolved_plt
->output_offset
4862 unresolved_reloc
= FALSE
;
4865 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4866 + htab
->elf
.sgotplt
->output_offset
;
4869 case R_X86_64_PLT32
:
4870 case R_X86_64_PLT32_BND
:
4871 /* Relocation is to the entry for this symbol in the
4872 procedure linkage table. */
4874 /* Resolve a PLT32 reloc against a local symbol directly,
4875 without using the procedure linkage table. */
4879 if ((h
->plt
.offset
== (bfd_vma
) -1
4880 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4881 || htab
->elf
.splt
== NULL
)
4883 /* We didn't make a PLT entry for this symbol. This
4884 happens when statically linking PIC code, or when
4885 using -Bsymbolic. */
4889 if (h
->plt
.offset
!= (bfd_vma
) -1)
4891 if (htab
->plt_bnd
!= NULL
)
4893 resolved_plt
= htab
->plt_bnd
;
4894 plt_offset
= eh
->plt_bnd
.offset
;
4898 resolved_plt
= htab
->elf
.splt
;
4899 plt_offset
= h
->plt
.offset
;
4904 /* Use the GOT PLT. */
4905 resolved_plt
= htab
->plt_got
;
4906 plt_offset
= eh
->plt_got
.offset
;
4909 relocation
= (resolved_plt
->output_section
->vma
4910 + resolved_plt
->output_offset
4912 unresolved_reloc
= FALSE
;
4915 case R_X86_64_SIZE32
:
4916 case R_X86_64_SIZE64
:
4917 /* Set to symbol size. */
4918 relocation
= st_size
;
4924 case R_X86_64_PC32_BND
:
4925 /* Don't complain about -fPIC if the symbol is undefined when
4926 building executable unless it is unresolved weak symbol. */
4927 if ((input_section
->flags
& SEC_ALLOC
) != 0
4928 && (input_section
->flags
& SEC_READONLY
) != 0
4930 && ((bfd_link_executable (info
)
4931 && h
->root
.type
== bfd_link_hash_undefweak
4932 && !resolved_to_zero
)
4933 || (bfd_link_pic (info
)
4934 && !(bfd_link_pie (info
)
4935 && h
->root
.type
== bfd_link_hash_undefined
))))
4937 bfd_boolean fail
= FALSE
;
4939 = ((r_type
== R_X86_64_PC32
4940 || r_type
== R_X86_64_PC32_BND
)
4941 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4943 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4945 /* Symbol is referenced locally. Make sure it is
4946 defined locally or for a branch. */
4947 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4950 else if (!(bfd_link_pie (info
)
4951 && (h
->needs_copy
|| eh
->needs_copy
)))
4953 /* Symbol doesn't need copy reloc and isn't referenced
4954 locally. We only allow branch to symbol with
4955 non-default visibility. */
4957 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4961 return elf_x86_64_need_pic (input_bfd
, input_section
,
4962 h
, NULL
, NULL
, howto
);
4971 /* FIXME: The ABI says the linker should make sure the value is
4972 the same when it's zeroextended to 64 bit. */
4975 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4978 /* Don't copy a pc-relative relocation into the output file
4979 if the symbol needs copy reloc or the symbol is undefined
4980 when building executable. Copy dynamic function pointer
4981 relocations. Don't generate dynamic relocations against
4982 resolved undefined weak symbols in PIE. */
4983 if ((bfd_link_pic (info
)
4984 && !(bfd_link_pie (info
)
4988 || h
->root
.type
== bfd_link_hash_undefined
)
4989 && (IS_X86_64_PCREL_TYPE (r_type
)
4990 || r_type
== R_X86_64_SIZE32
4991 || r_type
== R_X86_64_SIZE64
))
4993 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4994 && !resolved_to_zero
)
4995 || h
->root
.type
!= bfd_link_hash_undefweak
))
4996 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4997 && r_type
!= R_X86_64_SIZE32
4998 && r_type
!= R_X86_64_SIZE64
)
4999 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
5000 || (ELIMINATE_COPY_RELOCS
5001 && !bfd_link_pic (info
)
5005 || eh
->func_pointer_refcount
> 0
5006 || (h
->root
.type
== bfd_link_hash_undefweak
5007 && !resolved_to_zero
))
5008 && ((h
->def_dynamic
&& !h
->def_regular
)
5009 /* Undefined weak symbol is bound locally when
5011 || h
->root
.type
== bfd_link_hash_undefined
)))
5013 Elf_Internal_Rela outrel
;
5014 bfd_boolean skip
, relocate
;
5017 /* When generating a shared object, these relocations
5018 are copied into the output file to be resolved at run
5024 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5026 if (outrel
.r_offset
== (bfd_vma
) -1)
5028 else if (outrel
.r_offset
== (bfd_vma
) -2)
5029 skip
= TRUE
, relocate
= TRUE
;
5031 outrel
.r_offset
+= (input_section
->output_section
->vma
5032 + input_section
->output_offset
);
5035 memset (&outrel
, 0, sizeof outrel
);
5037 /* h->dynindx may be -1 if this symbol was marked to
5041 && (IS_X86_64_PCREL_TYPE (r_type
)
5042 || !(bfd_link_executable (info
)
5043 || SYMBOLIC_BIND (info
, h
))
5044 || ! h
->def_regular
))
5046 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
5047 outrel
.r_addend
= rel
->r_addend
;
5051 /* This symbol is local, or marked to become local.
5052 When relocation overflow check is disabled, we
5053 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
5054 if (r_type
== htab
->pointer_r_type
5055 || (r_type
== R_X86_64_32
5056 && info
->no_reloc_overflow_check
))
5059 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5060 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5062 else if (r_type
== R_X86_64_64
5063 && !ABI_64_P (output_bfd
))
5066 outrel
.r_info
= htab
->r_info (0,
5067 R_X86_64_RELATIVE64
);
5068 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5069 /* Check addend overflow. */
5070 if ((outrel
.r_addend
& 0x80000000)
5071 != (rel
->r_addend
& 0x80000000))
5074 int addend
= rel
->r_addend
;
5075 if (h
&& h
->root
.root
.string
)
5076 name
= h
->root
.root
.string
;
5078 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5082 /* xgettext:c-format */
5083 (_("%B: addend -0x%x in relocation %s against "
5084 "symbol `%s' at 0x%lx in section `%A' is "
5086 input_bfd
, addend
, howto
->name
, name
,
5087 (unsigned long) rel
->r_offset
, input_section
);
5090 /* xgettext:c-format */
5091 (_("%B: addend 0x%x in relocation %s against "
5092 "symbol `%s' at 0x%lx in section `%A' is "
5094 input_bfd
, addend
, howto
->name
, name
,
5095 (unsigned long) rel
->r_offset
, input_section
);
5096 bfd_set_error (bfd_error_bad_value
);
5104 if (bfd_is_abs_section (sec
))
5106 else if (sec
== NULL
|| sec
->owner
== NULL
)
5108 bfd_set_error (bfd_error_bad_value
);
5115 /* We are turning this relocation into one
5116 against a section symbol. It would be
5117 proper to subtract the symbol's value,
5118 osec->vma, from the emitted reloc addend,
5119 but ld.so expects buggy relocs. */
5120 osec
= sec
->output_section
;
5121 sindx
= elf_section_data (osec
)->dynindx
;
5124 asection
*oi
= htab
->elf
.text_index_section
;
5125 sindx
= elf_section_data (oi
)->dynindx
;
5127 BFD_ASSERT (sindx
!= 0);
5130 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
5131 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5135 sreloc
= elf_section_data (input_section
)->sreloc
;
5137 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5139 r
= bfd_reloc_notsupported
;
5140 goto check_relocation_error
;
5143 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5145 /* If this reloc is against an external symbol, we do
5146 not want to fiddle with the addend. Otherwise, we
5147 need to include the symbol value so that it becomes
5148 an addend for the dynamic reloc. */
5155 case R_X86_64_TLSGD
:
5156 case R_X86_64_GOTPC32_TLSDESC
:
5157 case R_X86_64_TLSDESC_CALL
:
5158 case R_X86_64_GOTTPOFF
:
5159 tls_type
= GOT_UNKNOWN
;
5160 if (h
== NULL
&& local_got_offsets
)
5161 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5163 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5165 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5166 input_section
, contents
,
5167 symtab_hdr
, sym_hashes
,
5168 &r_type
, tls_type
, rel
,
5169 relend
, h
, r_symndx
, TRUE
))
5172 if (r_type
== R_X86_64_TPOFF32
)
5174 bfd_vma roff
= rel
->r_offset
;
5176 BFD_ASSERT (! unresolved_reloc
);
5178 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5180 /* GD->LE transition. For 64bit, change
5181 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5182 .word 0x6666; rex64; call __tls_get_addr@PLT
5184 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5186 call *__tls_get_addr@GOTPCREL(%rip)
5187 which may be converted to
5188 addr32 call __tls_get_addr
5191 leaq foo@tpoff(%rax), %rax
5193 leaq foo@tlsgd(%rip), %rdi
5194 .word 0x6666; rex64; call __tls_get_addr@PLT
5196 leaq foo@tlsgd(%rip), %rdi
5198 call *__tls_get_addr@GOTPCREL(%rip)
5199 which may be converted to
5200 addr32 call __tls_get_addr
5203 leaq foo@tpoff(%rax), %rax
5204 For largepic, change:
5205 leaq foo@tlsgd(%rip), %rdi
5206 movabsq $__tls_get_addr@pltoff, %rax
5211 leaq foo@tpoff(%rax), %rax
5212 nopw 0x0(%rax,%rax,1) */
5214 if (ABI_64_P (output_bfd
))
5216 if (contents
[roff
+ 5] == 0xb8)
5218 memcpy (contents
+ roff
- 3,
5219 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5220 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5224 memcpy (contents
+ roff
- 4,
5225 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5229 memcpy (contents
+ roff
- 3,
5230 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5232 bfd_put_32 (output_bfd
,
5233 elf_x86_64_tpoff (info
, relocation
),
5234 contents
+ roff
+ 8 + largepic
);
5235 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5236 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5241 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5243 /* GDesc -> LE transition.
5244 It's originally something like:
5245 leaq x@tlsdesc(%rip), %rax
5248 movl $x@tpoff, %rax. */
5250 unsigned int val
, type
;
5252 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5253 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5254 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5255 contents
+ roff
- 3);
5256 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5257 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5258 contents
+ roff
- 1);
5259 bfd_put_32 (output_bfd
,
5260 elf_x86_64_tpoff (info
, relocation
),
5264 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5266 /* GDesc -> LE transition.
5271 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5272 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5275 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5277 /* IE->LE transition:
5278 For 64bit, originally it can be one of:
5279 movq foo@gottpoff(%rip), %reg
5280 addq foo@gottpoff(%rip), %reg
5283 leaq foo(%reg), %reg
5285 For 32bit, originally it can be one of:
5286 movq foo@gottpoff(%rip), %reg
5287 addl foo@gottpoff(%rip), %reg
5290 leal foo(%reg), %reg
5293 unsigned int val
, type
, reg
;
5296 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5299 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5300 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5306 bfd_put_8 (output_bfd
, 0x49,
5307 contents
+ roff
- 3);
5308 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5309 bfd_put_8 (output_bfd
, 0x41,
5310 contents
+ roff
- 3);
5311 bfd_put_8 (output_bfd
, 0xc7,
5312 contents
+ roff
- 2);
5313 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5314 contents
+ roff
- 1);
5318 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5321 bfd_put_8 (output_bfd
, 0x49,
5322 contents
+ roff
- 3);
5323 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5324 bfd_put_8 (output_bfd
, 0x41,
5325 contents
+ roff
- 3);
5326 bfd_put_8 (output_bfd
, 0x81,
5327 contents
+ roff
- 2);
5328 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5329 contents
+ roff
- 1);
5333 /* addq/addl -> leaq/leal */
5335 bfd_put_8 (output_bfd
, 0x4d,
5336 contents
+ roff
- 3);
5337 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5338 bfd_put_8 (output_bfd
, 0x45,
5339 contents
+ roff
- 3);
5340 bfd_put_8 (output_bfd
, 0x8d,
5341 contents
+ roff
- 2);
5342 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5343 contents
+ roff
- 1);
5345 bfd_put_32 (output_bfd
,
5346 elf_x86_64_tpoff (info
, relocation
),
5354 if (htab
->elf
.sgot
== NULL
)
5359 off
= h
->got
.offset
;
5360 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5364 if (local_got_offsets
== NULL
)
5367 off
= local_got_offsets
[r_symndx
];
5368 offplt
= local_tlsdesc_gotents
[r_symndx
];
5375 Elf_Internal_Rela outrel
;
5379 if (htab
->elf
.srelgot
== NULL
)
5382 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5384 if (GOT_TLS_GDESC_P (tls_type
))
5386 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5387 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5388 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5389 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5390 + htab
->elf
.sgotplt
->output_offset
5392 + htab
->sgotplt_jump_table_size
);
5393 sreloc
= htab
->elf
.srelplt
;
5395 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5397 outrel
.r_addend
= 0;
5398 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5401 sreloc
= htab
->elf
.srelgot
;
5403 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5404 + htab
->elf
.sgot
->output_offset
+ off
);
5406 if (GOT_TLS_GD_P (tls_type
))
5407 dr_type
= R_X86_64_DTPMOD64
;
5408 else if (GOT_TLS_GDESC_P (tls_type
))
5411 dr_type
= R_X86_64_TPOFF64
;
5413 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5414 outrel
.r_addend
= 0;
5415 if ((dr_type
== R_X86_64_TPOFF64
5416 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5417 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5418 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5420 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5422 if (GOT_TLS_GD_P (tls_type
))
5426 BFD_ASSERT (! unresolved_reloc
);
5427 bfd_put_64 (output_bfd
,
5428 relocation
- elf_x86_64_dtpoff_base (info
),
5429 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5433 bfd_put_64 (output_bfd
, 0,
5434 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5435 outrel
.r_info
= htab
->r_info (indx
,
5437 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5438 elf_append_rela (output_bfd
, sreloc
,
5447 local_got_offsets
[r_symndx
] |= 1;
5450 if (off
>= (bfd_vma
) -2
5451 && ! GOT_TLS_GDESC_P (tls_type
))
5453 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5455 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5456 || r_type
== R_X86_64_TLSDESC_CALL
)
5457 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5458 + htab
->elf
.sgotplt
->output_offset
5459 + offplt
+ htab
->sgotplt_jump_table_size
;
5461 relocation
= htab
->elf
.sgot
->output_section
->vma
5462 + htab
->elf
.sgot
->output_offset
+ off
;
5463 unresolved_reloc
= FALSE
;
5467 bfd_vma roff
= rel
->r_offset
;
5469 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5471 /* GD->IE transition. For 64bit, change
5472 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5473 .word 0x6666; rex64; call __tls_get_addr@PLT
5475 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5477 call *__tls_get_addr@GOTPCREL(%rip
5478 which may be converted to
5479 addr32 call __tls_get_addr
5482 addq foo@gottpoff(%rip), %rax
5484 leaq foo@tlsgd(%rip), %rdi
5485 .word 0x6666; rex64; call __tls_get_addr@PLT
5487 leaq foo@tlsgd(%rip), %rdi
5489 call *__tls_get_addr@GOTPCREL(%rip)
5490 which may be converted to
5491 addr32 call __tls_get_addr
5494 addq foo@gottpoff(%rip), %rax
5495 For largepic, change:
5496 leaq foo@tlsgd(%rip), %rdi
5497 movabsq $__tls_get_addr@pltoff, %rax
5502 addq foo@gottpoff(%rax), %rax
5503 nopw 0x0(%rax,%rax,1) */
5505 if (ABI_64_P (output_bfd
))
5507 if (contents
[roff
+ 5] == 0xb8)
5509 memcpy (contents
+ roff
- 3,
5510 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5511 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5515 memcpy (contents
+ roff
- 4,
5516 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5520 memcpy (contents
+ roff
- 3,
5521 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5524 relocation
= (htab
->elf
.sgot
->output_section
->vma
5525 + htab
->elf
.sgot
->output_offset
+ off
5528 - input_section
->output_section
->vma
5529 - input_section
->output_offset
5531 bfd_put_32 (output_bfd
, relocation
,
5532 contents
+ roff
+ 8 + largepic
);
5533 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5538 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5540 /* GDesc -> IE transition.
5541 It's originally something like:
5542 leaq x@tlsdesc(%rip), %rax
5545 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5547 /* Now modify the instruction as appropriate. To
5548 turn a leaq into a movq in the form we use it, it
5549 suffices to change the second byte from 0x8d to
5551 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5553 bfd_put_32 (output_bfd
,
5554 htab
->elf
.sgot
->output_section
->vma
5555 + htab
->elf
.sgot
->output_offset
+ off
5557 - input_section
->output_section
->vma
5558 - input_section
->output_offset
5563 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5565 /* GDesc -> IE transition.
5572 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5573 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5581 case R_X86_64_TLSLD
:
5582 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5583 input_section
, contents
,
5584 symtab_hdr
, sym_hashes
,
5585 &r_type
, GOT_UNKNOWN
, rel
,
5586 relend
, h
, r_symndx
, TRUE
))
5589 if (r_type
!= R_X86_64_TLSLD
)
5591 /* LD->LE transition:
5592 leaq foo@tlsld(%rip), %rdi
5593 call __tls_get_addr@PLT
5594 For 64bit, we change it into:
5595 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5596 For 32bit, we change it into:
5597 nopl 0x0(%rax); movl %fs:0, %eax
5599 leaq foo@tlsld(%rip), %rdi;
5600 call *__tls_get_addr@GOTPCREL(%rip)
5601 which may be converted to
5602 addr32 call __tls_get_addr
5603 For 64bit, we change it into:
5604 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5605 For 32bit, we change it into:
5606 nopw 0x0(%rax); movl %fs:0, %eax
5607 For largepic, change:
5608 leaq foo@tlsgd(%rip), %rdi
5609 movabsq $__tls_get_addr@pltoff, %rax
5613 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5616 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5617 if (ABI_64_P (output_bfd
))
5619 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5620 memcpy (contents
+ rel
->r_offset
- 3,
5621 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5622 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5623 else if (contents
[rel
->r_offset
+ 4] == 0xff
5624 || contents
[rel
->r_offset
+ 4] == 0x67)
5625 memcpy (contents
+ rel
->r_offset
- 3,
5626 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5629 memcpy (contents
+ rel
->r_offset
- 3,
5630 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5634 if (contents
[rel
->r_offset
+ 4] == 0xff)
5635 memcpy (contents
+ rel
->r_offset
- 3,
5636 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5639 memcpy (contents
+ rel
->r_offset
- 3,
5640 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5642 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5643 and R_X86_64_PLTOFF64. */
5649 if (htab
->elf
.sgot
== NULL
)
5652 off
= htab
->tls_ld_got
.offset
;
5657 Elf_Internal_Rela outrel
;
5659 if (htab
->elf
.srelgot
== NULL
)
5662 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5663 + htab
->elf
.sgot
->output_offset
+ off
);
5665 bfd_put_64 (output_bfd
, 0,
5666 htab
->elf
.sgot
->contents
+ off
);
5667 bfd_put_64 (output_bfd
, 0,
5668 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5669 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5670 outrel
.r_addend
= 0;
5671 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5673 htab
->tls_ld_got
.offset
|= 1;
5675 relocation
= htab
->elf
.sgot
->output_section
->vma
5676 + htab
->elf
.sgot
->output_offset
+ off
;
5677 unresolved_reloc
= FALSE
;
5680 case R_X86_64_DTPOFF32
:
5681 if (!bfd_link_executable (info
)
5682 || (input_section
->flags
& SEC_CODE
) == 0)
5683 relocation
-= elf_x86_64_dtpoff_base (info
);
5685 relocation
= elf_x86_64_tpoff (info
, relocation
);
5688 case R_X86_64_TPOFF32
:
5689 case R_X86_64_TPOFF64
:
5690 BFD_ASSERT (bfd_link_executable (info
));
5691 relocation
= elf_x86_64_tpoff (info
, relocation
);
5694 case R_X86_64_DTPOFF64
:
5695 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5696 relocation
-= elf_x86_64_dtpoff_base (info
);
5703 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5704 because such sections are not SEC_ALLOC and thus ld.so will
5705 not process them. */
5706 if (unresolved_reloc
5707 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5709 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5710 rel
->r_offset
) != (bfd_vma
) -1)
5713 /* xgettext:c-format */
5714 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5717 (long) rel
->r_offset
,
5719 h
->root
.root
.string
);
5724 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5725 contents
, rel
->r_offset
,
5726 relocation
, rel
->r_addend
);
5728 check_relocation_error
:
5729 if (r
!= bfd_reloc_ok
)
5734 name
= h
->root
.root
.string
;
5737 name
= bfd_elf_string_from_elf_section (input_bfd
,
5738 symtab_hdr
->sh_link
,
5743 name
= bfd_section_name (input_bfd
, sec
);
5746 if (r
== bfd_reloc_overflow
)
5747 (*info
->callbacks
->reloc_overflow
)
5748 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5749 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5753 /* xgettext:c-format */
5754 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5755 input_bfd
, input_section
,
5756 (long) rel
->r_offset
, name
, (int) r
);
5767 Elf_Internal_Shdr
*rel_hdr
;
5768 size_t deleted
= rel
- wrel
;
5770 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5771 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5772 if (rel_hdr
->sh_size
== 0)
5774 /* It is too late to remove an empty reloc section. Leave
5776 ??? What is wrong with an empty section??? */
5777 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5780 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5781 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5782 input_section
->reloc_count
-= deleted
;
5788 /* Finish up dynamic symbol handling. We set the contents of various
5789 dynamic sections here. */
5792 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5793 struct bfd_link_info
*info
,
5794 struct elf_link_hash_entry
*h
,
5795 Elf_Internal_Sym
*sym
)
5797 struct elf_x86_64_link_hash_table
*htab
;
5798 const struct elf_x86_64_backend_data
*abed
;
5799 bfd_boolean use_plt_bnd
;
5800 struct elf_x86_64_link_hash_entry
*eh
;
5801 bfd_boolean local_undefweak
;
5803 htab
= elf_x86_64_hash_table (info
);
5807 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5808 section only if there is .plt section. */
5809 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5811 ? &elf_x86_64_bnd_arch_bed
5812 : get_elf_x86_64_backend_data (output_bfd
));
5814 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5815 if (eh
->no_finish_dynamic_symbol
)
5818 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5819 resolved undefined weak symbols in executable so that their
5820 references have value 0 at run-time. */
5821 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5825 if (h
->plt
.offset
!= (bfd_vma
) -1)
5828 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
5829 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
5830 Elf_Internal_Rela rela
;
5832 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5833 const struct elf_backend_data
*bed
;
5834 bfd_vma plt_got_pcrel_offset
;
5836 /* When building a static executable, use .iplt, .igot.plt and
5837 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5838 if (htab
->elf
.splt
!= NULL
)
5840 plt
= htab
->elf
.splt
;
5841 gotplt
= htab
->elf
.sgotplt
;
5842 relplt
= htab
->elf
.srelplt
;
5846 plt
= htab
->elf
.iplt
;
5847 gotplt
= htab
->elf
.igotplt
;
5848 relplt
= htab
->elf
.irelplt
;
5851 /* This symbol has an entry in the procedure linkage table. Set
5853 if ((h
->dynindx
== -1
5855 && !((h
->forced_local
|| bfd_link_executable (info
))
5857 && h
->type
== STT_GNU_IFUNC
))
5863 /* Get the index in the procedure linkage table which
5864 corresponds to this symbol. This is the index of this symbol
5865 in all the symbols for which we are making plt entries. The
5866 first entry in the procedure linkage table is reserved.
5868 Get the offset into the .got table of the entry that
5869 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5870 bytes. The first three are reserved for the dynamic linker.
5872 For static executables, we don't reserve anything. */
5874 if (plt
== htab
->elf
.splt
)
5876 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
5877 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5881 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
5882 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5885 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
5886 plt_plt_offset
= abed
->plt_plt_offset
;
5887 plt_got_insn_size
= abed
->plt_got_insn_size
;
5888 plt_got_offset
= abed
->plt_got_offset
;
5891 /* Use the second PLT with BND relocations. */
5892 const bfd_byte
*plt_entry
, *plt2_entry
;
5896 plt_entry
= elf_x86_64_bnd_plt_entry
;
5897 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
5901 plt_entry
= elf_x86_64_legacy_plt_entry
;
5902 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
5904 /* Subtract 1 since there is no BND prefix. */
5905 plt_plt_insn_end
-= 1;
5906 plt_plt_offset
-= 1;
5907 plt_got_insn_size
-= 1;
5908 plt_got_offset
-= 1;
5911 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
5912 == sizeof (elf_x86_64_legacy_plt_entry
));
5914 /* Fill in the entry in the procedure linkage table. */
5915 memcpy (plt
->contents
+ h
->plt
.offset
,
5916 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
5917 /* Fill in the entry in the second PLT. */
5918 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5919 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5921 resolved_plt
= htab
->plt_bnd
;
5922 plt_offset
= eh
->plt_bnd
.offset
;
5926 /* Fill in the entry in the procedure linkage table. */
5927 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
5928 abed
->plt_entry_size
);
5931 plt_offset
= h
->plt
.offset
;
5934 /* Insert the relocation positions of the plt section. */
5936 /* Put offset the PC-relative instruction referring to the GOT entry,
5937 subtracting the size of that instruction. */
5938 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5939 + gotplt
->output_offset
5941 - resolved_plt
->output_section
->vma
5942 - resolved_plt
->output_offset
5944 - plt_got_insn_size
);
5946 /* Check PC-relative offset overflow in PLT entry. */
5947 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5948 /* xgettext:c-format */
5949 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5950 output_bfd
, h
->root
.root
.string
);
5952 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5953 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
5955 /* Fill in the entry in the global offset table, initially this
5956 points to the second part of the PLT entry. Leave the entry
5957 as zero for undefined weak symbol in PIE. No PLT relocation
5958 against undefined weak symbol in PIE. */
5959 if (!local_undefweak
)
5961 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5962 + plt
->output_offset
5964 + abed
->plt_lazy_offset
),
5965 gotplt
->contents
+ got_offset
);
5967 /* Fill in the entry in the .rela.plt section. */
5968 rela
.r_offset
= (gotplt
->output_section
->vma
5969 + gotplt
->output_offset
5971 if (h
->dynindx
== -1
5972 || ((bfd_link_executable (info
)
5973 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5975 && h
->type
== STT_GNU_IFUNC
))
5977 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5978 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5979 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5980 rela
.r_addend
= (h
->root
.u
.def
.value
5981 + h
->root
.u
.def
.section
->output_section
->vma
5982 + h
->root
.u
.def
.section
->output_offset
);
5983 /* R_X86_64_IRELATIVE comes last. */
5984 plt_index
= htab
->next_irelative_index
--;
5988 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5990 plt_index
= htab
->next_jump_slot_index
++;
5993 /* Don't fill PLT entry for static executables. */
5994 if (plt
== htab
->elf
.splt
)
5996 bfd_vma plt0_offset
= h
->plt
.offset
+ plt_plt_insn_end
;
5998 /* Put relocation index. */
5999 bfd_put_32 (output_bfd
, plt_index
,
6000 (plt
->contents
+ h
->plt
.offset
6001 + abed
->plt_reloc_offset
));
6003 /* Put offset for jmp .PLT0 and check for overflow. We don't
6004 check relocation index for overflow since branch displacement
6005 will overflow first. */
6006 if (plt0_offset
> 0x80000000)
6007 /* xgettext:c-format */
6008 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
6009 output_bfd
, h
->root
.root
.string
);
6010 bfd_put_32 (output_bfd
, - plt0_offset
,
6011 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
6014 bed
= get_elf_backend_data (output_bfd
);
6015 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
6016 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
6019 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
6021 bfd_vma got_offset
, plt_offset
, plt_got_offset
, plt_got_insn_size
;
6022 asection
*plt
, *got
;
6023 bfd_boolean got_after_plt
;
6024 int32_t got_pcrel_offset
;
6025 const bfd_byte
*got_plt_entry
;
6027 /* Set the entry in the GOT procedure linkage table. */
6028 plt
= htab
->plt_got
;
6029 got
= htab
->elf
.sgot
;
6030 got_offset
= h
->got
.offset
;
6032 if (got_offset
== (bfd_vma
) -1
6033 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
6038 /* Use the second PLT entry template for the GOT PLT since they
6039 are the identical. */
6040 plt_got_insn_size
= elf_x86_64_bnd_arch_bed
.plt_got_insn_size
;
6041 plt_got_offset
= elf_x86_64_bnd_arch_bed
.plt_got_offset
;
6043 got_plt_entry
= elf_x86_64_bnd_plt2_entry
;
6046 got_plt_entry
= elf_x86_64_legacy_plt2_entry
;
6048 /* Subtract 1 since there is no BND prefix. */
6049 plt_got_insn_size
-= 1;
6050 plt_got_offset
-= 1;
6053 /* Fill in the entry in the GOT procedure linkage table. */
6054 plt_offset
= eh
->plt_got
.offset
;
6055 memcpy (plt
->contents
+ plt_offset
,
6056 got_plt_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
6058 /* Put offset the PC-relative instruction referring to the GOT
6059 entry, subtracting the size of that instruction. */
6060 got_pcrel_offset
= (got
->output_section
->vma
6061 + got
->output_offset
6063 - plt
->output_section
->vma
6064 - plt
->output_offset
6066 - plt_got_insn_size
);
6068 /* Check PC-relative offset overflow in GOT PLT entry. */
6069 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
6070 if ((got_after_plt
&& got_pcrel_offset
< 0)
6071 || (!got_after_plt
&& got_pcrel_offset
> 0))
6072 /* xgettext:c-format */
6073 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
6074 output_bfd
, h
->root
.root
.string
);
6076 bfd_put_32 (output_bfd
, got_pcrel_offset
,
6077 plt
->contents
+ plt_offset
+ plt_got_offset
);
6080 if (!local_undefweak
6082 && (h
->plt
.offset
!= (bfd_vma
) -1
6083 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
6085 /* Mark the symbol as undefined, rather than as defined in
6086 the .plt section. Leave the value if there were any
6087 relocations where pointer equality matters (this is a clue
6088 for the dynamic linker, to make function pointer
6089 comparisons work between an application and shared
6090 library), otherwise set it to zero. If a function is only
6091 called from a binary, there is no need to slow down
6092 shared libraries because of that. */
6093 sym
->st_shndx
= SHN_UNDEF
;
6094 if (!h
->pointer_equality_needed
)
6098 /* Don't generate dynamic GOT relocation against undefined weak
6099 symbol in executable. */
6100 if (h
->got
.offset
!= (bfd_vma
) -1
6101 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
6102 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
6103 && !local_undefweak
)
6105 Elf_Internal_Rela rela
;
6106 asection
*relgot
= htab
->elf
.srelgot
;
6108 /* This symbol has an entry in the global offset table. Set it
6110 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
6113 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
6114 + htab
->elf
.sgot
->output_offset
6115 + (h
->got
.offset
&~ (bfd_vma
) 1));
6117 /* If this is a static link, or it is a -Bsymbolic link and the
6118 symbol is defined locally or was forced to be local because
6119 of a version file, we just want to emit a RELATIVE reloc.
6120 The entry in the global offset table will already have been
6121 initialized in the relocate_section function. */
6123 && h
->type
== STT_GNU_IFUNC
)
6125 if (h
->plt
.offset
== (bfd_vma
) -1)
6127 /* STT_GNU_IFUNC is referenced without PLT. */
6128 if (htab
->elf
.splt
== NULL
)
6130 /* use .rel[a].iplt section to store .got relocations
6131 in static executable. */
6132 relgot
= htab
->elf
.irelplt
;
6134 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
6136 rela
.r_info
= htab
->r_info (0,
6137 R_X86_64_IRELATIVE
);
6138 rela
.r_addend
= (h
->root
.u
.def
.value
6139 + h
->root
.u
.def
.section
->output_section
->vma
6140 + h
->root
.u
.def
.section
->output_offset
);
6145 else if (bfd_link_pic (info
))
6147 /* Generate R_X86_64_GLOB_DAT. */
6154 if (!h
->pointer_equality_needed
)
6157 /* For non-shared object, we can't use .got.plt, which
6158 contains the real function addres if we need pointer
6159 equality. We load the GOT entry with the PLT entry. */
6160 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6161 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6162 + plt
->output_offset
6164 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6168 else if (bfd_link_pic (info
)
6169 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6171 if (!h
->def_regular
)
6173 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6174 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6175 rela
.r_addend
= (h
->root
.u
.def
.value
6176 + h
->root
.u
.def
.section
->output_section
->vma
6177 + h
->root
.u
.def
.section
->output_offset
);
6181 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6183 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6184 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6185 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6189 elf_append_rela (output_bfd
, relgot
, &rela
);
6194 Elf_Internal_Rela rela
;
6197 /* This symbol needs a copy reloc. Set it up. */
6199 if (h
->dynindx
== -1
6200 || (h
->root
.type
!= bfd_link_hash_defined
6201 && h
->root
.type
!= bfd_link_hash_defweak
)
6202 || htab
->elf
.srelbss
== NULL
6203 || htab
->elf
.sreldynrelro
== NULL
)
6206 rela
.r_offset
= (h
->root
.u
.def
.value
6207 + h
->root
.u
.def
.section
->output_section
->vma
6208 + h
->root
.u
.def
.section
->output_offset
);
6209 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6211 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6212 s
= htab
->elf
.sreldynrelro
;
6214 s
= htab
->elf
.srelbss
;
6215 elf_append_rela (output_bfd
, s
, &rela
);
6221 /* Finish up local dynamic symbol handling. We set the contents of
6222 various dynamic sections here. */
6225 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6227 struct elf_link_hash_entry
*h
6228 = (struct elf_link_hash_entry
*) *slot
;
6229 struct bfd_link_info
*info
6230 = (struct bfd_link_info
*) inf
;
6232 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6236 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6237 here since undefined weak symbol may not be dynamic and may not be
6238 called for elf_x86_64_finish_dynamic_symbol. */
6241 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6244 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6245 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6247 if (h
->root
.type
!= bfd_link_hash_undefweak
6248 || h
->dynindx
!= -1)
6251 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6255 /* Used to decide how to sort relocs in an optimal manner for the
6256 dynamic linker, before writing them out. */
6258 static enum elf_reloc_type_class
6259 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6260 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6261 const Elf_Internal_Rela
*rela
)
6263 bfd
*abfd
= info
->output_bfd
;
6264 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6265 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6267 if (htab
->elf
.dynsym
!= NULL
6268 && htab
->elf
.dynsym
->contents
!= NULL
)
6270 /* Check relocation against STT_GNU_IFUNC symbol if there are
6272 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6273 if (r_symndx
!= STN_UNDEF
)
6275 Elf_Internal_Sym sym
;
6276 if (!bed
->s
->swap_symbol_in (abfd
,
6277 (htab
->elf
.dynsym
->contents
6278 + r_symndx
* bed
->s
->sizeof_sym
),
6282 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6283 return reloc_class_ifunc
;
6287 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6289 case R_X86_64_IRELATIVE
:
6290 return reloc_class_ifunc
;
6291 case R_X86_64_RELATIVE
:
6292 case R_X86_64_RELATIVE64
:
6293 return reloc_class_relative
;
6294 case R_X86_64_JUMP_SLOT
:
6295 return reloc_class_plt
;
6297 return reloc_class_copy
;
6299 return reloc_class_normal
;
6303 /* Finish up the dynamic sections. */
6306 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6307 struct bfd_link_info
*info
)
6309 struct elf_x86_64_link_hash_table
*htab
;
6312 const struct elf_x86_64_backend_data
*abed
;
6314 htab
= elf_x86_64_hash_table (info
);
6318 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6319 section only if there is .plt section. */
6320 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
6321 ? &elf_x86_64_bnd_arch_bed
6322 : get_elf_x86_64_backend_data (output_bfd
));
6324 dynobj
= htab
->elf
.dynobj
;
6325 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6327 if (htab
->elf
.dynamic_sections_created
)
6329 bfd_byte
*dyncon
, *dynconend
;
6330 const struct elf_backend_data
*bed
;
6331 bfd_size_type sizeof_dyn
;
6333 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6336 bed
= get_elf_backend_data (dynobj
);
6337 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6338 dyncon
= sdyn
->contents
;
6339 dynconend
= sdyn
->contents
+ sdyn
->size
;
6340 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6342 Elf_Internal_Dyn dyn
;
6345 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6353 s
= htab
->elf
.sgotplt
;
6354 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6358 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6362 s
= htab
->elf
.srelplt
->output_section
;
6363 dyn
.d_un
.d_val
= s
->size
;
6366 case DT_TLSDESC_PLT
:
6368 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6369 + htab
->tlsdesc_plt
;
6372 case DT_TLSDESC_GOT
:
6374 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6375 + htab
->tlsdesc_got
;
6379 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6382 /* Fill in the special first entry in the procedure linkage table. */
6383 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6385 /* Fill in the first entry in the procedure linkage table. */
6386 memcpy (htab
->elf
.splt
->contents
,
6387 abed
->plt0_entry
, abed
->plt_entry_size
);
6388 /* Add offset for pushq GOT+8(%rip), since the instruction
6389 uses 6 bytes subtract this value. */
6390 bfd_put_32 (output_bfd
,
6391 (htab
->elf
.sgotplt
->output_section
->vma
6392 + htab
->elf
.sgotplt
->output_offset
6394 - htab
->elf
.splt
->output_section
->vma
6395 - htab
->elf
.splt
->output_offset
6397 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
6398 /* Add offset for the PC-relative instruction accessing GOT+16,
6399 subtracting the offset to the end of that instruction. */
6400 bfd_put_32 (output_bfd
,
6401 (htab
->elf
.sgotplt
->output_section
->vma
6402 + htab
->elf
.sgotplt
->output_offset
6404 - htab
->elf
.splt
->output_section
->vma
6405 - htab
->elf
.splt
->output_offset
6406 - abed
->plt0_got2_insn_end
),
6407 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
6409 elf_section_data (htab
->elf
.splt
->output_section
)
6410 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
6412 if (htab
->tlsdesc_plt
)
6414 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6415 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6417 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6418 abed
->plt0_entry
, abed
->plt_entry_size
);
6420 /* Add offset for pushq GOT+8(%rip), since the
6421 instruction uses 6 bytes subtract this value. */
6422 bfd_put_32 (output_bfd
,
6423 (htab
->elf
.sgotplt
->output_section
->vma
6424 + htab
->elf
.sgotplt
->output_offset
6426 - htab
->elf
.splt
->output_section
->vma
6427 - htab
->elf
.splt
->output_offset
6430 htab
->elf
.splt
->contents
6431 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
6432 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6433 where TGD stands for htab->tlsdesc_got, subtracting the offset
6434 to the end of that instruction. */
6435 bfd_put_32 (output_bfd
,
6436 (htab
->elf
.sgot
->output_section
->vma
6437 + htab
->elf
.sgot
->output_offset
6439 - htab
->elf
.splt
->output_section
->vma
6440 - htab
->elf
.splt
->output_offset
6442 - abed
->plt0_got2_insn_end
),
6443 htab
->elf
.splt
->contents
6444 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
6449 if (htab
->plt_bnd
!= NULL
)
6450 elf_section_data (htab
->plt_bnd
->output_section
)
6451 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
6453 if (htab
->elf
.sgotplt
)
6455 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6458 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6462 /* Fill in the first three entries in the global offset table. */
6463 if (htab
->elf
.sgotplt
->size
> 0)
6465 /* Set the first entry in the global offset table to the address of
6466 the dynamic section. */
6468 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6470 bfd_put_64 (output_bfd
,
6471 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6472 htab
->elf
.sgotplt
->contents
);
6473 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6474 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6475 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6478 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
6482 /* Adjust .eh_frame for .plt section. */
6483 if (htab
->plt_eh_frame
!= NULL
6484 && htab
->plt_eh_frame
->contents
!= NULL
)
6486 if (htab
->elf
.splt
!= NULL
6487 && htab
->elf
.splt
->size
!= 0
6488 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6489 && htab
->elf
.splt
->output_section
!= NULL
6490 && htab
->plt_eh_frame
->output_section
!= NULL
)
6492 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6493 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6494 + htab
->plt_eh_frame
->output_offset
6495 + PLT_FDE_START_OFFSET
;
6496 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6497 htab
->plt_eh_frame
->contents
6498 + PLT_FDE_START_OFFSET
);
6500 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6502 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6504 htab
->plt_eh_frame
->contents
))
6509 /* Adjust .eh_frame for .plt.got section. */
6510 if (htab
->plt_got_eh_frame
!= NULL
6511 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6513 if (htab
->plt_got
!= NULL
6514 && htab
->plt_got
->size
!= 0
6515 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6516 && htab
->plt_got
->output_section
!= NULL
6517 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6519 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6520 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6521 + htab
->plt_got_eh_frame
->output_offset
6522 + PLT_FDE_START_OFFSET
;
6523 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6524 htab
->plt_got_eh_frame
->contents
6525 + PLT_FDE_START_OFFSET
);
6527 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6529 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6530 htab
->plt_got_eh_frame
,
6531 htab
->plt_got_eh_frame
->contents
))
6536 /* Adjust .eh_frame for .plt.bnd section. */
6537 if (htab
->plt_bnd_eh_frame
!= NULL
6538 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
6540 if (htab
->plt_bnd
!= NULL
6541 && htab
->plt_bnd
->size
!= 0
6542 && (htab
->plt_bnd
->flags
& SEC_EXCLUDE
) == 0
6543 && htab
->plt_bnd
->output_section
!= NULL
6544 && htab
->plt_bnd_eh_frame
->output_section
!= NULL
)
6546 bfd_vma plt_start
= htab
->plt_bnd
->output_section
->vma
;
6547 bfd_vma eh_frame_start
= htab
->plt_bnd_eh_frame
->output_section
->vma
6548 + htab
->plt_bnd_eh_frame
->output_offset
6549 + PLT_FDE_START_OFFSET
;
6550 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6551 htab
->plt_bnd_eh_frame
->contents
6552 + PLT_FDE_START_OFFSET
);
6554 if (htab
->plt_bnd_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6556 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6557 htab
->plt_bnd_eh_frame
,
6558 htab
->plt_bnd_eh_frame
->contents
))
6563 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6564 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6567 /* Fill PLT entries for undefined weak symbols in PIE. */
6568 if (bfd_link_pie (info
))
6569 bfd_hash_traverse (&info
->hash
->table
,
6570 elf_x86_64_pie_finish_undefweak_symbol
,
6576 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6577 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6578 It has to be done before elf_link_sort_relocs is called so that
6579 dynamic relocations are properly sorted. */
6582 elf_x86_64_output_arch_local_syms
6583 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6584 struct bfd_link_info
*info
,
6585 void *flaginfo ATTRIBUTE_UNUSED
,
6586 int (*func
) (void *, const char *,
6589 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6591 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6595 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6596 htab_traverse (htab
->loc_hash_table
,
6597 elf_x86_64_finish_local_dynamic_symbol
,
6603 /* Return an array of PLT entry symbol values. */
6606 elf_x86_64_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6609 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6612 bfd_vma
*plt_sym_val
;
6614 bfd_byte
*plt_contents
;
6615 const struct elf_x86_64_backend_data
*bed
;
6616 Elf_Internal_Shdr
*hdr
;
6619 /* Get the .plt section contents. PLT passed down may point to the
6620 .plt.bnd section. Make sure that PLT always points to the .plt
6622 plt_bnd
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6627 plt
= bfd_get_section_by_name (abfd
, ".plt");
6630 bed
= &elf_x86_64_bnd_arch_bed
;
6633 bed
= get_elf_x86_64_backend_data (abfd
);
6635 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6636 if (plt_contents
== NULL
)
6638 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6639 plt_contents
, 0, plt
->size
))
6642 free (plt_contents
);
6646 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6647 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6650 hdr
= &elf_section_data (relplt
)->this_hdr
;
6651 count
= relplt
->size
/ hdr
->sh_entsize
;
6653 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6654 if (plt_sym_val
== NULL
)
6657 for (i
= 0; i
< count
; i
++)
6658 plt_sym_val
[i
] = -1;
6660 plt_offset
= bed
->plt_entry_size
;
6661 p
= relplt
->relocation
;
6662 for (i
= 0; i
< count
; i
++, p
++)
6666 /* Skip unknown relocation. */
6667 if (p
->howto
== NULL
)
6670 if (p
->howto
->type
!= R_X86_64_JUMP_SLOT
6671 && p
->howto
->type
!= R_X86_64_IRELATIVE
)
6674 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6675 + bed
->plt_reloc_offset
));
6676 if (reloc_index
< count
)
6680 /* This is the index in .plt section. */
6681 long plt_index
= plt_offset
/ bed
->plt_entry_size
;
6682 /* Store VMA + the offset in .plt.bnd section. */
6683 plt_sym_val
[reloc_index
] =
6685 + (plt_index
- 1) * sizeof (elf_x86_64_legacy_plt2_entry
));
6688 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6690 plt_offset
+= bed
->plt_entry_size
;
6692 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6694 if (plt_offset
>= plt
->size
)
6698 free (plt_contents
);
6703 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6707 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6714 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6715 as PLT if it exists. */
6716 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6718 plt
= bfd_get_section_by_name (abfd
, ".plt");
6719 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6720 dynsymcount
, dynsyms
, ret
,
6722 elf_x86_64_get_plt_sym_val
);
6725 /* Handle an x86-64 specific section when reading an object file. This
6726 is called when elfcode.h finds a section with an unknown type. */
6729 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6730 const char *name
, int shindex
)
6732 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6735 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6741 /* Hook called by the linker routine which adds symbols from an object
6742 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6746 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6747 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6748 Elf_Internal_Sym
*sym
,
6749 const char **namep ATTRIBUTE_UNUSED
,
6750 flagword
*flagsp ATTRIBUTE_UNUSED
,
6756 switch (sym
->st_shndx
)
6758 case SHN_X86_64_LCOMMON
:
6759 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6762 lcomm
= bfd_make_section_with_flags (abfd
,
6766 | SEC_LINKER_CREATED
));
6769 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6772 *valp
= sym
->st_size
;
6780 /* Given a BFD section, try to locate the corresponding ELF section
6784 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6785 asection
*sec
, int *index_return
)
6787 if (sec
== &_bfd_elf_large_com_section
)
6789 *index_return
= SHN_X86_64_LCOMMON
;
6795 /* Process a symbol. */
6798 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6801 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6803 switch (elfsym
->internal_elf_sym
.st_shndx
)
6805 case SHN_X86_64_LCOMMON
:
6806 asym
->section
= &_bfd_elf_large_com_section
;
6807 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6808 /* Common symbol doesn't set BSF_GLOBAL. */
6809 asym
->flags
&= ~BSF_GLOBAL
;
6815 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6817 return (sym
->st_shndx
== SHN_COMMON
6818 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6822 elf_x86_64_common_section_index (asection
*sec
)
6824 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6827 return SHN_X86_64_LCOMMON
;
6831 elf_x86_64_common_section (asection
*sec
)
6833 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6834 return bfd_com_section_ptr
;
6836 return &_bfd_elf_large_com_section
;
6840 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6841 const Elf_Internal_Sym
*sym
,
6846 const asection
*oldsec
)
6848 /* A normal common symbol and a large common symbol result in a
6849 normal common symbol. We turn the large common symbol into a
6852 && h
->root
.type
== bfd_link_hash_common
6854 && bfd_is_com_section (*psec
)
6857 if (sym
->st_shndx
== SHN_COMMON
6858 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6860 h
->root
.u
.c
.p
->section
6861 = bfd_make_section_old_way (oldbfd
, "COMMON");
6862 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6864 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6865 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6866 *psec
= bfd_com_section_ptr
;
6873 elf_x86_64_additional_program_headers (bfd
*abfd
,
6874 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6879 /* Check to see if we need a large readonly segment. */
6880 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6881 if (s
&& (s
->flags
& SEC_LOAD
))
6884 /* Check to see if we need a large data segment. Since .lbss sections
6885 is placed right after the .bss section, there should be no need for
6886 a large data segment just because of .lbss. */
6887 s
= bfd_get_section_by_name (abfd
, ".ldata");
6888 if (s
&& (s
->flags
& SEC_LOAD
))
6894 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6897 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6899 if (h
->plt
.offset
!= (bfd_vma
) -1
6901 && !h
->pointer_equality_needed
)
6904 return _bfd_elf_hash_symbol (h
);
6907 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6910 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6911 const bfd_target
*output
)
6913 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6914 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6915 && _bfd_elf_relocs_compatible (input
, output
));
6918 /* Parse x86-64 GNU properties. */
6920 static enum elf_property_kind
6921 elf_x86_64_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6922 bfd_byte
*ptr
, unsigned int datasz
)
6928 case GNU_PROPERTY_X86_ISA_1_USED
:
6929 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6933 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6934 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6935 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>")),
6937 return property_corrupt
;
6939 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6940 prop
->u
.number
= bfd_h_get_32 (abfd
, ptr
);
6941 prop
->pr_kind
= property_number
;
6945 return property_ignored
;
6948 return property_number
;
6951 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
6952 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6953 should be merged with ABFD. */
6956 elf_x86_64_merge_gnu_properties (bfd
*abfd ATTRIBUTE_UNUSED
,
6957 elf_property
*aprop
,
6958 elf_property
*bprop
)
6960 unsigned int number
;
6961 bfd_boolean updated
= FALSE
;
6962 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6966 case GNU_PROPERTY_X86_ISA_1_USED
:
6967 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6968 if (aprop
!= NULL
&& bprop
!= NULL
)
6970 number
= aprop
->u
.number
;
6971 aprop
->u
.number
= number
| bprop
->u
.number
;
6972 updated
= number
!= (unsigned int) aprop
->u
.number
;
6976 /* Return TRUE if APROP is NULL to indicate that BPROP should
6977 be added to ABFD. */
6978 updated
= aprop
== NULL
;
6983 /* Never should happen. */
6990 static const struct bfd_elf_special_section
6991 elf_x86_64_special_sections
[]=
6993 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6994 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6995 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
6996 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6997 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6998 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6999 { NULL
, 0, 0, 0, 0 }
7002 #define TARGET_LITTLE_SYM x86_64_elf64_vec
7003 #define TARGET_LITTLE_NAME "elf64-x86-64"
7004 #define ELF_ARCH bfd_arch_i386
7005 #define ELF_TARGET_ID X86_64_ELF_DATA
7006 #define ELF_MACHINE_CODE EM_X86_64
7007 #define ELF_MAXPAGESIZE 0x200000
7008 #define ELF_MINPAGESIZE 0x1000
7009 #define ELF_COMMONPAGESIZE 0x1000
7011 #define elf_backend_can_gc_sections 1
7012 #define elf_backend_can_refcount 1
7013 #define elf_backend_want_got_plt 1
7014 #define elf_backend_plt_readonly 1
7015 #define elf_backend_want_plt_sym 0
7016 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
7017 #define elf_backend_rela_normal 1
7018 #define elf_backend_plt_alignment 4
7019 #define elf_backend_extern_protected_data 1
7020 #define elf_backend_caches_rawsize 1
7021 #define elf_backend_dtrel_excludes_plt 1
7022 #define elf_backend_want_dynrelro 1
7024 #define elf_info_to_howto elf_x86_64_info_to_howto
7026 #define bfd_elf64_bfd_link_hash_table_create \
7027 elf_x86_64_link_hash_table_create
7028 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7029 #define bfd_elf64_bfd_reloc_name_lookup \
7030 elf_x86_64_reloc_name_lookup
7032 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7033 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7034 #define elf_backend_check_relocs elf_x86_64_check_relocs
7035 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7036 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
7037 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7038 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7039 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7040 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7041 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7042 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7044 #define elf_backend_write_core_note elf_x86_64_write_core_note
7046 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7047 #define elf_backend_relocate_section elf_x86_64_relocate_section
7048 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7049 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7050 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7051 #define elf_backend_object_p elf64_x86_64_elf_object_p
7052 #define bfd_elf64_mkobject elf_x86_64_mkobject
7053 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7055 #define elf_backend_section_from_shdr \
7056 elf_x86_64_section_from_shdr
7058 #define elf_backend_section_from_bfd_section \
7059 elf_x86_64_elf_section_from_bfd_section
7060 #define elf_backend_add_symbol_hook \
7061 elf_x86_64_add_symbol_hook
7062 #define elf_backend_symbol_processing \
7063 elf_x86_64_symbol_processing
7064 #define elf_backend_common_section_index \
7065 elf_x86_64_common_section_index
7066 #define elf_backend_common_section \
7067 elf_x86_64_common_section
7068 #define elf_backend_common_definition \
7069 elf_x86_64_common_definition
7070 #define elf_backend_merge_symbol \
7071 elf_x86_64_merge_symbol
7072 #define elf_backend_special_sections \
7073 elf_x86_64_special_sections
7074 #define elf_backend_additional_program_headers \
7075 elf_x86_64_additional_program_headers
7076 #define elf_backend_hash_symbol \
7077 elf_x86_64_hash_symbol
7078 #define elf_backend_omit_section_dynsym \
7079 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7080 #define elf_backend_fixup_symbol \
7081 elf_x86_64_fixup_symbol
7082 #define elf_backend_parse_gnu_properties \
7083 elf_x86_64_parse_gnu_properties
7084 #define elf_backend_merge_gnu_properties \
7085 elf_x86_64_merge_gnu_properties
7087 #include "elf64-target.h"
7089 /* CloudABI support. */
7091 #undef TARGET_LITTLE_SYM
7092 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7093 #undef TARGET_LITTLE_NAME
7094 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7097 #define ELF_OSABI ELFOSABI_CLOUDABI
7100 #define elf64_bed elf64_x86_64_cloudabi_bed
7102 #include "elf64-target.h"
7104 /* FreeBSD support. */
7106 #undef TARGET_LITTLE_SYM
7107 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7108 #undef TARGET_LITTLE_NAME
7109 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7112 #define ELF_OSABI ELFOSABI_FREEBSD
7115 #define elf64_bed elf64_x86_64_fbsd_bed
7117 #include "elf64-target.h"
7119 /* Solaris 2 support. */
7121 #undef TARGET_LITTLE_SYM
7122 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7123 #undef TARGET_LITTLE_NAME
7124 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7126 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7127 objects won't be recognized. */
7131 #define elf64_bed elf64_x86_64_sol2_bed
7133 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7135 #undef elf_backend_static_tls_alignment
7136 #define elf_backend_static_tls_alignment 16
7138 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7140 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7142 #undef elf_backend_want_plt_sym
7143 #define elf_backend_want_plt_sym 1
7145 #undef elf_backend_strtab_flags
7146 #define elf_backend_strtab_flags SHF_STRINGS
7149 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7150 bfd
*obfd ATTRIBUTE_UNUSED
,
7151 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7152 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7154 /* PR 19938: FIXME: Need to add code for setting the sh_info
7155 and sh_link fields of Solaris specific section types. */
7159 #undef elf_backend_copy_special_section_fields
7160 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7162 #include "elf64-target.h"
7164 /* Native Client support. */
7167 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
7169 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7170 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
7174 #undef TARGET_LITTLE_SYM
7175 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7176 #undef TARGET_LITTLE_NAME
7177 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7179 #define elf64_bed elf64_x86_64_nacl_bed
7181 #undef ELF_MAXPAGESIZE
7182 #undef ELF_MINPAGESIZE
7183 #undef ELF_COMMONPAGESIZE
7184 #define ELF_MAXPAGESIZE 0x10000
7185 #define ELF_MINPAGESIZE 0x10000
7186 #define ELF_COMMONPAGESIZE 0x10000
7188 /* Restore defaults. */
7190 #undef elf_backend_static_tls_alignment
7191 #undef elf_backend_want_plt_sym
7192 #define elf_backend_want_plt_sym 0
7193 #undef elf_backend_strtab_flags
7194 #undef elf_backend_copy_special_section_fields
7196 /* NaCl uses substantially different PLT entries for the same effects. */
7198 #undef elf_backend_plt_alignment
7199 #define elf_backend_plt_alignment 5
7200 #define NACL_PLT_ENTRY_SIZE 64
7201 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7203 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
7205 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7206 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7207 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7208 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7209 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7211 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7212 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7214 /* 32 bytes of nop to pad out to the standard size. */
7215 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7216 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7217 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7218 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7219 0x66, /* excess data16 prefix */
7223 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7225 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7226 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7227 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7228 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7230 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7231 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7232 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7234 /* Lazy GOT entries point here (32-byte aligned). */
7235 0x68, /* pushq immediate */
7236 0, 0, 0, 0, /* replaced with index into relocation table. */
7237 0xe9, /* jmp relative */
7238 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7240 /* 22 bytes of nop to pad out to the standard size. */
7241 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7242 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7243 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7246 /* .eh_frame covering the .plt section. */
7248 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
7250 #if (PLT_CIE_LENGTH != 20 \
7251 || PLT_FDE_LENGTH != 36 \
7252 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7253 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7254 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7256 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7257 0, 0, 0, 0, /* CIE ID */
7258 1, /* CIE version */
7259 'z', 'R', 0, /* Augmentation string */
7260 1, /* Code alignment factor */
7261 0x78, /* Data alignment factor */
7262 16, /* Return address column */
7263 1, /* Augmentation size */
7264 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7265 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7266 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7267 DW_CFA_nop
, DW_CFA_nop
,
7269 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7270 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
7271 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7272 0, 0, 0, 0, /* .plt size goes here */
7273 0, /* Augmentation size */
7274 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
7275 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7276 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
7277 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7278 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7279 13, /* Block length */
7280 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7281 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7282 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7283 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7284 DW_CFA_nop
, DW_CFA_nop
7287 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7289 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7290 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7291 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7292 2, /* plt0_got1_offset */
7293 9, /* plt0_got2_offset */
7294 13, /* plt0_got2_insn_end */
7295 3, /* plt_got_offset */
7296 33, /* plt_reloc_offset */
7297 38, /* plt_plt_offset */
7298 7, /* plt_got_insn_size */
7299 42, /* plt_plt_insn_end */
7300 32, /* plt_lazy_offset */
7301 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7302 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
7303 NULL
, /* eh_frame_plt_got */
7304 0, /* eh_frame_plt_got_size */
7307 #undef elf_backend_arch_data
7308 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7310 #undef elf_backend_object_p
7311 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7312 #undef elf_backend_modify_segment_map
7313 #define elf_backend_modify_segment_map nacl_modify_segment_map
7314 #undef elf_backend_modify_program_headers
7315 #define elf_backend_modify_program_headers nacl_modify_program_headers
7316 #undef elf_backend_final_write_processing
7317 #define elf_backend_final_write_processing nacl_final_write_processing
7319 #include "elf64-target.h"
7321 /* Native Client x32 support. */
7324 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7326 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7327 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7331 #undef TARGET_LITTLE_SYM
7332 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7333 #undef TARGET_LITTLE_NAME
7334 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7336 #define elf32_bed elf32_x86_64_nacl_bed
7338 #define bfd_elf32_bfd_link_hash_table_create \
7339 elf_x86_64_link_hash_table_create
7340 #define bfd_elf32_bfd_reloc_type_lookup \
7341 elf_x86_64_reloc_type_lookup
7342 #define bfd_elf32_bfd_reloc_name_lookup \
7343 elf_x86_64_reloc_name_lookup
7344 #define bfd_elf32_mkobject \
7346 #define bfd_elf32_get_synthetic_symtab \
7347 elf_x86_64_get_synthetic_symtab
7349 #undef elf_backend_object_p
7350 #define elf_backend_object_p \
7351 elf32_x86_64_nacl_elf_object_p
7353 #undef elf_backend_bfd_from_remote_memory
7354 #define elf_backend_bfd_from_remote_memory \
7355 _bfd_elf32_bfd_from_remote_memory
7357 #undef elf_backend_size_info
7358 #define elf_backend_size_info \
7359 _bfd_elf32_size_info
7361 #include "elf32-target.h"
7363 /* Restore defaults. */
7364 #undef elf_backend_object_p
7365 #define elf_backend_object_p elf64_x86_64_elf_object_p
7366 #undef elf_backend_bfd_from_remote_memory
7367 #undef elf_backend_size_info
7368 #undef elf_backend_modify_segment_map
7369 #undef elf_backend_modify_program_headers
7370 #undef elf_backend_final_write_processing
7372 /* Intel L1OM support. */
7375 elf64_l1om_elf_object_p (bfd
*abfd
)
7377 /* Set the right machine number for an L1OM elf64 file. */
7378 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7382 #undef TARGET_LITTLE_SYM
7383 #define TARGET_LITTLE_SYM l1om_elf64_vec
7384 #undef TARGET_LITTLE_NAME
7385 #define TARGET_LITTLE_NAME "elf64-l1om"
7387 #define ELF_ARCH bfd_arch_l1om
7389 #undef ELF_MACHINE_CODE
7390 #define ELF_MACHINE_CODE EM_L1OM
7395 #define elf64_bed elf64_l1om_bed
7397 #undef elf_backend_object_p
7398 #define elf_backend_object_p elf64_l1om_elf_object_p
7400 /* Restore defaults. */
7401 #undef ELF_MAXPAGESIZE
7402 #undef ELF_MINPAGESIZE
7403 #undef ELF_COMMONPAGESIZE
7404 #define ELF_MAXPAGESIZE 0x200000
7405 #define ELF_MINPAGESIZE 0x1000
7406 #define ELF_COMMONPAGESIZE 0x1000
7407 #undef elf_backend_plt_alignment
7408 #define elf_backend_plt_alignment 4
7409 #undef elf_backend_arch_data
7410 #define elf_backend_arch_data &elf_x86_64_arch_bed
7412 #include "elf64-target.h"
7414 /* FreeBSD L1OM support. */
7416 #undef TARGET_LITTLE_SYM
7417 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7418 #undef TARGET_LITTLE_NAME
7419 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7422 #define ELF_OSABI ELFOSABI_FREEBSD
7425 #define elf64_bed elf64_l1om_fbsd_bed
7427 #include "elf64-target.h"
7429 /* Intel K1OM support. */
7432 elf64_k1om_elf_object_p (bfd
*abfd
)
7434 /* Set the right machine number for an K1OM elf64 file. */
7435 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7439 #undef TARGET_LITTLE_SYM
7440 #define TARGET_LITTLE_SYM k1om_elf64_vec
7441 #undef TARGET_LITTLE_NAME
7442 #define TARGET_LITTLE_NAME "elf64-k1om"
7444 #define ELF_ARCH bfd_arch_k1om
7446 #undef ELF_MACHINE_CODE
7447 #define ELF_MACHINE_CODE EM_K1OM
7452 #define elf64_bed elf64_k1om_bed
7454 #undef elf_backend_object_p
7455 #define elf_backend_object_p elf64_k1om_elf_object_p
7457 #undef elf_backend_static_tls_alignment
7459 #undef elf_backend_want_plt_sym
7460 #define elf_backend_want_plt_sym 0
7462 #include "elf64-target.h"
7464 /* FreeBSD K1OM support. */
7466 #undef TARGET_LITTLE_SYM
7467 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7468 #undef TARGET_LITTLE_NAME
7469 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7472 #define ELF_OSABI ELFOSABI_FREEBSD
7475 #define elf64_bed elf64_k1om_fbsd_bed
7477 #include "elf64-target.h"
7479 /* 32bit x86-64 support. */
7481 #undef TARGET_LITTLE_SYM
7482 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7483 #undef TARGET_LITTLE_NAME
7484 #define TARGET_LITTLE_NAME "elf32-x86-64"
7488 #define ELF_ARCH bfd_arch_i386
7490 #undef ELF_MACHINE_CODE
7491 #define ELF_MACHINE_CODE EM_X86_64
7495 #undef elf_backend_object_p
7496 #define elf_backend_object_p \
7497 elf32_x86_64_elf_object_p
7499 #undef elf_backend_bfd_from_remote_memory
7500 #define elf_backend_bfd_from_remote_memory \
7501 _bfd_elf32_bfd_from_remote_memory
7503 #undef elf_backend_size_info
7504 #define elf_backend_size_info \
7505 _bfd_elf32_size_info
7507 #include "elf32-target.h"