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 at least one BND relocation. */
862 unsigned int has_bnd_reloc
: 1;
864 /* TRUE if symbol has GOT or PLT relocations. */
865 unsigned int has_got_reloc
: 1;
867 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
868 unsigned int has_non_got_reloc
: 1;
870 /* Don't call finish_dynamic_symbol on this symbol. */
871 unsigned int no_finish_dynamic_symbol
: 1;
873 /* 0: symbol isn't __tls_get_addr.
874 1: symbol is __tls_get_addr.
875 2: symbol is unknown. */
876 unsigned int tls_get_addr
: 2;
878 /* Reference count of C/C++ function pointer relocations in read-write
879 section which can be resolved at run-time. */
880 bfd_signed_vma func_pointer_refcount
;
882 /* Information about the GOT PLT entry. Filled when there are both
883 GOT and PLT relocations against the same function. */
884 union gotplt_union plt_got
;
886 /* Information about the second PLT entry. Filled when has_bnd_reloc is
888 union gotplt_union plt_bnd
;
890 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
891 starting at the end of the jump table. */
895 #define elf_x86_64_hash_entry(ent) \
896 ((struct elf_x86_64_link_hash_entry *)(ent))
898 struct elf_x86_64_obj_tdata
900 struct elf_obj_tdata root
;
902 /* tls_type for each local got entry. */
903 char *local_got_tls_type
;
905 /* GOTPLT entries for TLS descriptors. */
906 bfd_vma
*local_tlsdesc_gotent
;
909 #define elf_x86_64_tdata(abfd) \
910 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
912 #define elf_x86_64_local_got_tls_type(abfd) \
913 (elf_x86_64_tdata (abfd)->local_got_tls_type)
915 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
916 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
918 #define is_x86_64_elf(bfd) \
919 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
920 && elf_tdata (bfd) != NULL \
921 && elf_object_id (bfd) == X86_64_ELF_DATA)
924 elf_x86_64_mkobject (bfd
*abfd
)
926 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
930 /* x86-64 ELF linker hash table. */
932 struct elf_x86_64_link_hash_table
934 struct elf_link_hash_table elf
;
936 /* Short-cuts to get to dynamic linker sections. */
938 asection
*plt_eh_frame
;
940 asection
*plt_bnd_eh_frame
;
942 asection
*plt_got_eh_frame
;
946 bfd_signed_vma refcount
;
950 /* The amount of space used by the jump slots in the GOT. */
951 bfd_vma sgotplt_jump_table_size
;
953 /* Small local sym cache. */
954 struct sym_cache sym_cache
;
956 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
957 bfd_vma (*r_sym
) (bfd_vma
);
958 unsigned int pointer_r_type
;
959 const char *dynamic_interpreter
;
960 int dynamic_interpreter_size
;
962 /* _TLS_MODULE_BASE_ symbol. */
963 struct bfd_link_hash_entry
*tls_module_base
;
965 /* Used by local STT_GNU_IFUNC symbols. */
966 htab_t loc_hash_table
;
967 void * loc_hash_memory
;
969 /* The offset into splt of the PLT entry for the TLS descriptor
970 resolver. Special values are 0, if not necessary (or not found
971 to be necessary yet), and -1 if needed but not determined
974 /* The offset into sgot of the GOT entry used by the PLT entry
978 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
979 bfd_vma next_jump_slot_index
;
980 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
981 bfd_vma next_irelative_index
;
983 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
984 to read-only sections. */
985 bfd_boolean readonly_dynrelocs_against_ifunc
;
988 /* Get the x86-64 ELF linker hash table from a link_info structure. */
990 #define elf_x86_64_hash_table(p) \
991 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
992 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
994 #define elf_x86_64_compute_jump_table_size(htab) \
995 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
997 /* Create an entry in an x86-64 ELF linker hash table. */
999 static struct bfd_hash_entry
*
1000 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1001 struct bfd_hash_table
*table
,
1004 /* Allocate the structure if it has not already been allocated by a
1008 entry
= (struct bfd_hash_entry
*)
1009 bfd_hash_allocate (table
,
1010 sizeof (struct elf_x86_64_link_hash_entry
));
1015 /* Call the allocation method of the superclass. */
1016 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1019 struct elf_x86_64_link_hash_entry
*eh
;
1021 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
1022 eh
->dyn_relocs
= NULL
;
1023 eh
->tls_type
= GOT_UNKNOWN
;
1025 eh
->has_bnd_reloc
= 0;
1026 eh
->has_got_reloc
= 0;
1027 eh
->has_non_got_reloc
= 0;
1028 eh
->no_finish_dynamic_symbol
= 0;
1029 eh
->tls_get_addr
= 2;
1030 eh
->func_pointer_refcount
= 0;
1031 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
1032 eh
->plt_got
.offset
= (bfd_vma
) -1;
1033 eh
->tlsdesc_got
= (bfd_vma
) -1;
1039 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1040 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1041 as global symbol. We reuse indx and dynstr_index for local symbol
1042 hash since they aren't used by global symbols in this backend. */
1045 elf_x86_64_local_htab_hash (const void *ptr
)
1047 struct elf_link_hash_entry
*h
1048 = (struct elf_link_hash_entry
*) ptr
;
1049 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1052 /* Compare local hash entries. */
1055 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
1057 struct elf_link_hash_entry
*h1
1058 = (struct elf_link_hash_entry
*) ptr1
;
1059 struct elf_link_hash_entry
*h2
1060 = (struct elf_link_hash_entry
*) ptr2
;
1062 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1065 /* Find and/or create a hash entry for local symbol. */
1067 static struct elf_link_hash_entry
*
1068 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
1069 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1072 struct elf_x86_64_link_hash_entry e
, *ret
;
1073 asection
*sec
= abfd
->sections
;
1074 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1075 htab
->r_sym (rel
->r_info
));
1078 e
.elf
.indx
= sec
->id
;
1079 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1080 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1081 create
? INSERT
: NO_INSERT
);
1088 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1092 ret
= (struct elf_x86_64_link_hash_entry
*)
1093 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1094 sizeof (struct elf_x86_64_link_hash_entry
));
1097 memset (ret
, 0, sizeof (*ret
));
1098 ret
->elf
.indx
= sec
->id
;
1099 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1100 ret
->elf
.dynindx
= -1;
1101 ret
->func_pointer_refcount
= 0;
1102 ret
->plt_got
.offset
= (bfd_vma
) -1;
1108 /* Destroy an X86-64 ELF linker hash table. */
1111 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1113 struct elf_x86_64_link_hash_table
*htab
1114 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1116 if (htab
->loc_hash_table
)
1117 htab_delete (htab
->loc_hash_table
);
1118 if (htab
->loc_hash_memory
)
1119 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1120 _bfd_elf_link_hash_table_free (obfd
);
1123 /* Create an X86-64 ELF linker hash table. */
1125 static struct bfd_link_hash_table
*
1126 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1128 struct elf_x86_64_link_hash_table
*ret
;
1129 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1131 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1135 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1136 elf_x86_64_link_hash_newfunc
,
1137 sizeof (struct elf_x86_64_link_hash_entry
),
1144 if (ABI_64_P (abfd
))
1146 ret
->r_info
= elf64_r_info
;
1147 ret
->r_sym
= elf64_r_sym
;
1148 ret
->pointer_r_type
= R_X86_64_64
;
1149 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1150 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1154 ret
->r_info
= elf32_r_info
;
1155 ret
->r_sym
= elf32_r_sym
;
1156 ret
->pointer_r_type
= R_X86_64_32
;
1157 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1158 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1161 ret
->loc_hash_table
= htab_try_create (1024,
1162 elf_x86_64_local_htab_hash
,
1163 elf_x86_64_local_htab_eq
,
1165 ret
->loc_hash_memory
= objalloc_create ();
1166 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1168 elf_x86_64_link_hash_table_free (abfd
);
1171 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1173 return &ret
->elf
.root
;
1176 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1177 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1181 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
1182 struct bfd_link_info
*info
)
1184 struct elf_x86_64_link_hash_table
*htab
;
1186 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1189 htab
= elf_x86_64_hash_table (info
);
1193 /* Set the contents of the .interp section to the interpreter. */
1194 if (bfd_link_executable (info
) && !info
->nointerp
)
1196 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1199 s
->size
= htab
->dynamic_interpreter_size
;
1200 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
1204 if (!info
->no_ld_generated_unwind_info
1205 && htab
->plt_eh_frame
== NULL
1206 && htab
->elf
.splt
!= NULL
)
1208 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1209 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1210 | SEC_LINKER_CREATED
);
1212 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1213 if (htab
->plt_eh_frame
== NULL
1214 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
,
1215 ABI_64_P (dynobj
) ? 3 : 2))
1219 /* Align .got section to its entry size. */
1220 if (htab
->elf
.sgot
!= NULL
1221 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgot
, 3))
1224 /* Align .got.plt section to its entry size. */
1225 if (htab
->elf
.sgotplt
!= NULL
1226 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgotplt
, 3))
1232 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1235 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1236 struct elf_link_hash_entry
*dir
,
1237 struct elf_link_hash_entry
*ind
)
1239 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1241 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1242 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1244 edir
->has_bnd_reloc
|= eind
->has_bnd_reloc
;
1245 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1246 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1248 if (eind
->dyn_relocs
!= NULL
)
1250 if (edir
->dyn_relocs
!= NULL
)
1252 struct elf_dyn_relocs
**pp
;
1253 struct elf_dyn_relocs
*p
;
1255 /* Add reloc counts against the indirect sym to the direct sym
1256 list. Merge any entries against the same section. */
1257 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1259 struct elf_dyn_relocs
*q
;
1261 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1262 if (q
->sec
== p
->sec
)
1264 q
->pc_count
+= p
->pc_count
;
1265 q
->count
+= p
->count
;
1272 *pp
= edir
->dyn_relocs
;
1275 edir
->dyn_relocs
= eind
->dyn_relocs
;
1276 eind
->dyn_relocs
= NULL
;
1279 if (ind
->root
.type
== bfd_link_hash_indirect
1280 && dir
->got
.refcount
<= 0)
1282 edir
->tls_type
= eind
->tls_type
;
1283 eind
->tls_type
= GOT_UNKNOWN
;
1286 if (ELIMINATE_COPY_RELOCS
1287 && ind
->root
.type
!= bfd_link_hash_indirect
1288 && dir
->dynamic_adjusted
)
1290 /* If called to transfer flags for a weakdef during processing
1291 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1292 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1293 if (dir
->versioned
!= versioned_hidden
)
1294 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1295 dir
->ref_regular
|= ind
->ref_regular
;
1296 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1297 dir
->needs_plt
|= ind
->needs_plt
;
1298 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1302 if (eind
->func_pointer_refcount
> 0)
1304 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1305 eind
->func_pointer_refcount
= 0;
1308 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1313 elf64_x86_64_elf_object_p (bfd
*abfd
)
1315 /* Set the right machine number for an x86-64 elf64 file. */
1316 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1321 elf32_x86_64_elf_object_p (bfd
*abfd
)
1323 /* Set the right machine number for an x86-64 elf32 file. */
1324 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1328 /* Return TRUE if the TLS access code sequence support transition
1332 elf_x86_64_check_tls_transition (bfd
*abfd
,
1333 struct bfd_link_info
*info
,
1336 Elf_Internal_Shdr
*symtab_hdr
,
1337 struct elf_link_hash_entry
**sym_hashes
,
1338 unsigned int r_type
,
1339 const Elf_Internal_Rela
*rel
,
1340 const Elf_Internal_Rela
*relend
)
1343 unsigned long r_symndx
;
1344 bfd_boolean largepic
= FALSE
;
1345 struct elf_link_hash_entry
*h
;
1347 struct elf_x86_64_link_hash_table
*htab
;
1349 bfd_boolean indirect_call
, tls_get_addr
;
1351 htab
= elf_x86_64_hash_table (info
);
1352 offset
= rel
->r_offset
;
1355 case R_X86_64_TLSGD
:
1356 case R_X86_64_TLSLD
:
1357 if ((rel
+ 1) >= relend
)
1360 if (r_type
== R_X86_64_TLSGD
)
1362 /* Check transition from GD access model. For 64bit, only
1363 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1364 .word 0x6666; rex64; call __tls_get_addr@PLT
1366 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1368 call *__tls_get_addr@GOTPCREL(%rip)
1369 which may be converted to
1370 addr32 call __tls_get_addr
1371 can transit to different access model. For 32bit, only
1372 leaq foo@tlsgd(%rip), %rdi
1373 .word 0x6666; rex64; call __tls_get_addr@PLT
1375 leaq foo@tlsgd(%rip), %rdi
1377 call *__tls_get_addr@GOTPCREL(%rip)
1378 which may be converted to
1379 addr32 call __tls_get_addr
1380 can transit to different access model. For largepic,
1382 leaq foo@tlsgd(%rip), %rdi
1383 movabsq $__tls_get_addr@pltoff, %rax
1387 leaq foo@tlsgd(%rip), %rdi
1388 movabsq $__tls_get_addr@pltoff, %rax
1392 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1394 if ((offset
+ 12) > sec
->size
)
1397 call
= contents
+ offset
+ 4;
1399 || !((call
[1] == 0x48
1407 && call
[3] == 0xe8)))
1409 if (!ABI_64_P (abfd
)
1410 || (offset
+ 19) > sec
->size
1412 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1413 || memcmp (call
, "\x48\xb8", 2) != 0
1417 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1418 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1422 else if (ABI_64_P (abfd
))
1425 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1431 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1434 indirect_call
= call
[2] == 0xff;
1438 /* Check transition from LD access model. Only
1439 leaq foo@tlsld(%rip), %rdi;
1440 call __tls_get_addr@PLT
1442 leaq foo@tlsld(%rip), %rdi;
1443 call *__tls_get_addr@GOTPCREL(%rip)
1444 which may be converted to
1445 addr32 call __tls_get_addr
1446 can transit to different access model. For largepic
1448 leaq foo@tlsld(%rip), %rdi
1449 movabsq $__tls_get_addr@pltoff, %rax
1453 leaq foo@tlsld(%rip), %rdi
1454 movabsq $__tls_get_addr@pltoff, %rax
1458 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1460 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1463 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1466 call
= contents
+ offset
+ 4;
1467 if (!(call
[0] == 0xe8
1468 || (call
[0] == 0xff && call
[1] == 0x15)
1469 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1471 if (!ABI_64_P (abfd
)
1472 || (offset
+ 19) > sec
->size
1473 || memcmp (call
, "\x48\xb8", 2) != 0
1477 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1478 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1482 indirect_call
= call
[0] == 0xff;
1485 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1486 if (r_symndx
< symtab_hdr
->sh_info
)
1489 tls_get_addr
= FALSE
;
1490 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1491 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1493 struct elf_x86_64_link_hash_entry
*eh
1494 = (struct elf_x86_64_link_hash_entry
*) h
;
1495 tls_get_addr
= eh
->tls_get_addr
== 1;
1496 if (eh
->tls_get_addr
> 1)
1498 /* Use strncmp to check __tls_get_addr since
1499 __tls_get_addr may be versioned. */
1500 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1503 eh
->tls_get_addr
= 1;
1504 tls_get_addr
= TRUE
;
1507 eh
->tls_get_addr
= 0;
1514 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1515 else if (indirect_call
)
1516 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1518 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1519 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1521 case R_X86_64_GOTTPOFF
:
1522 /* Check transition from IE access model:
1523 mov foo@gottpoff(%rip), %reg
1524 add foo@gottpoff(%rip), %reg
1527 /* Check REX prefix first. */
1528 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1530 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1531 if (val
!= 0x48 && val
!= 0x4c)
1533 /* X32 may have 0x44 REX prefix or no REX prefix. */
1534 if (ABI_64_P (abfd
))
1540 /* X32 may not have any REX prefix. */
1541 if (ABI_64_P (abfd
))
1543 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1547 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1548 if (val
!= 0x8b && val
!= 0x03)
1551 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1552 return (val
& 0xc7) == 5;
1554 case R_X86_64_GOTPC32_TLSDESC
:
1555 /* Check transition from GDesc access model:
1556 leaq x@tlsdesc(%rip), %rax
1558 Make sure it's a leaq adding rip to a 32-bit offset
1559 into any register, although it's probably almost always
1562 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1565 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1566 if ((val
& 0xfb) != 0x48)
1569 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1572 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1573 return (val
& 0xc7) == 0x05;
1575 case R_X86_64_TLSDESC_CALL
:
1576 /* Check transition from GDesc access model:
1577 call *x@tlsdesc(%rax)
1579 if (offset
+ 2 <= sec
->size
)
1581 /* Make sure that it's a call *x@tlsdesc(%rax). */
1582 call
= contents
+ offset
;
1583 return call
[0] == 0xff && call
[1] == 0x10;
1593 /* Return TRUE if the TLS access transition is OK or no transition
1594 will be performed. Update R_TYPE if there is a transition. */
1597 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1598 asection
*sec
, bfd_byte
*contents
,
1599 Elf_Internal_Shdr
*symtab_hdr
,
1600 struct elf_link_hash_entry
**sym_hashes
,
1601 unsigned int *r_type
, int tls_type
,
1602 const Elf_Internal_Rela
*rel
,
1603 const Elf_Internal_Rela
*relend
,
1604 struct elf_link_hash_entry
*h
,
1605 unsigned long r_symndx
,
1606 bfd_boolean from_relocate_section
)
1608 unsigned int from_type
= *r_type
;
1609 unsigned int to_type
= from_type
;
1610 bfd_boolean check
= TRUE
;
1612 /* Skip TLS transition for functions. */
1614 && (h
->type
== STT_FUNC
1615 || h
->type
== STT_GNU_IFUNC
))
1620 case R_X86_64_TLSGD
:
1621 case R_X86_64_GOTPC32_TLSDESC
:
1622 case R_X86_64_TLSDESC_CALL
:
1623 case R_X86_64_GOTTPOFF
:
1624 if (bfd_link_executable (info
))
1627 to_type
= R_X86_64_TPOFF32
;
1629 to_type
= R_X86_64_GOTTPOFF
;
1632 /* When we are called from elf_x86_64_relocate_section, there may
1633 be additional transitions based on TLS_TYPE. */
1634 if (from_relocate_section
)
1636 unsigned int new_to_type
= to_type
;
1638 if (bfd_link_executable (info
)
1641 && tls_type
== GOT_TLS_IE
)
1642 new_to_type
= R_X86_64_TPOFF32
;
1644 if (to_type
== R_X86_64_TLSGD
1645 || to_type
== R_X86_64_GOTPC32_TLSDESC
1646 || to_type
== R_X86_64_TLSDESC_CALL
)
1648 if (tls_type
== GOT_TLS_IE
)
1649 new_to_type
= R_X86_64_GOTTPOFF
;
1652 /* We checked the transition before when we were called from
1653 elf_x86_64_check_relocs. We only want to check the new
1654 transition which hasn't been checked before. */
1655 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1656 to_type
= new_to_type
;
1661 case R_X86_64_TLSLD
:
1662 if (bfd_link_executable (info
))
1663 to_type
= R_X86_64_TPOFF32
;
1670 /* Return TRUE if there is no transition. */
1671 if (from_type
== to_type
)
1674 /* Check if the transition can be performed. */
1676 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1677 symtab_hdr
, sym_hashes
,
1678 from_type
, rel
, relend
))
1680 reloc_howto_type
*from
, *to
;
1683 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1684 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1687 name
= h
->root
.root
.string
;
1690 struct elf_x86_64_link_hash_table
*htab
;
1692 htab
= elf_x86_64_hash_table (info
);
1697 Elf_Internal_Sym
*isym
;
1699 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1701 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1706 /* xgettext:c-format */
1707 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1708 "in section `%A' failed"),
1709 abfd
, from
->name
, to
->name
, name
,
1710 (unsigned long) rel
->r_offset
, sec
);
1711 bfd_set_error (bfd_error_bad_value
);
1719 /* Rename some of the generic section flags to better document how they
1721 #define need_convert_load sec_flg0
1722 #define check_relocs_failed sec_flg1
1725 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1726 struct elf_link_hash_entry
*h
,
1727 Elf_Internal_Shdr
*symtab_hdr
,
1728 Elf_Internal_Sym
*isym
,
1729 reloc_howto_type
*howto
)
1732 const char *und
= "";
1733 const char *pic
= "";
1738 name
= h
->root
.root
.string
;
1739 switch (ELF_ST_VISIBILITY (h
->other
))
1742 v
= _("hidden symbol ");
1745 v
= _("internal symbol ");
1748 v
= _("protected symbol ");
1752 pic
= _("; recompile with -fPIC");
1756 if (!h
->def_regular
&& !h
->def_dynamic
)
1757 und
= _("undefined ");
1761 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1762 pic
= _("; recompile with -fPIC");
1765 /* xgettext:c-format */
1766 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1767 "not be used when making a shared object%s"),
1768 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1769 bfd_set_error (bfd_error_bad_value
);
1770 sec
->check_relocs_failed
= 1;
1774 /* With the local symbol, foo, we convert
1775 mov foo@GOTPCREL(%rip), %reg
1779 call/jmp *foo@GOTPCREL(%rip)
1781 nop call foo/jmp foo nop
1782 When PIC is false, convert
1783 test %reg, foo@GOTPCREL(%rip)
1787 binop foo@GOTPCREL(%rip), %reg
1790 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1794 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1796 Elf_Internal_Rela
*irel
,
1797 struct elf_link_hash_entry
*h
,
1798 bfd_boolean
*converted
,
1799 struct bfd_link_info
*link_info
)
1801 struct elf_x86_64_link_hash_table
*htab
;
1803 bfd_boolean require_reloc_pc32
;
1805 bfd_boolean to_reloc_pc32
;
1808 bfd_signed_vma raddend
;
1809 unsigned int opcode
;
1811 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1812 unsigned int r_symndx
;
1814 bfd_vma roff
= irel
->r_offset
;
1816 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1819 raddend
= irel
->r_addend
;
1820 /* Addend for 32-bit PC-relative relocation must be -4. */
1824 htab
= elf_x86_64_hash_table (link_info
);
1825 is_pic
= bfd_link_pic (link_info
);
1827 relocx
= (r_type
== R_X86_64_GOTPCRELX
1828 || r_type
== R_X86_64_REX_GOTPCRELX
);
1830 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1833 = link_info
->disable_target_specific_optimizations
> 1;
1835 r_symndx
= htab
->r_sym (irel
->r_info
);
1837 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1839 /* Convert mov to lea since it has been done for a while. */
1842 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1843 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1844 test, xor instructions. */
1849 /* We convert only to R_X86_64_PC32:
1851 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1852 3. require_reloc_pc32 is true.
1855 to_reloc_pc32
= (opcode
== 0xff
1857 || require_reloc_pc32
1860 /* Get the symbol referred to by the reloc. */
1863 Elf_Internal_Sym
*isym
1864 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1866 /* Skip relocation against undefined symbols. */
1867 if (isym
->st_shndx
== SHN_UNDEF
)
1870 symtype
= ELF_ST_TYPE (isym
->st_info
);
1872 if (isym
->st_shndx
== SHN_ABS
)
1873 tsec
= bfd_abs_section_ptr
;
1874 else if (isym
->st_shndx
== SHN_COMMON
)
1875 tsec
= bfd_com_section_ptr
;
1876 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1877 tsec
= &_bfd_elf_large_com_section
;
1879 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1881 toff
= isym
->st_value
;
1885 /* Undefined weak symbol is only bound locally in executable
1886 and its reference is resolved as 0 without relocation
1887 overflow. We can only perform this optimization for
1888 GOTPCRELX relocations since we need to modify REX byte.
1889 It is OK convert mov with R_X86_64_GOTPCREL to
1891 if ((relocx
|| opcode
== 0x8b)
1892 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1894 elf_x86_64_hash_entry (h
)))
1898 /* Skip for branch instructions since R_X86_64_PC32
1900 if (require_reloc_pc32
)
1905 /* For non-branch instructions, we can convert to
1906 R_X86_64_32/R_X86_64_32S since we know if there
1908 to_reloc_pc32
= FALSE
;
1911 /* Since we don't know the current PC when PIC is true,
1912 we can't convert to R_X86_64_PC32. */
1913 if (to_reloc_pc32
&& is_pic
)
1918 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1919 ld.so may use its link-time address. */
1920 else if ((h
->def_regular
1921 || h
->root
.type
== bfd_link_hash_defined
1922 || h
->root
.type
== bfd_link_hash_defweak
)
1923 && h
!= htab
->elf
.hdynamic
1924 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1926 /* bfd_link_hash_new or bfd_link_hash_undefined is
1927 set by an assignment in a linker script in
1928 bfd_elf_record_link_assignment. */
1930 && (h
->root
.type
== bfd_link_hash_new
1931 || h
->root
.type
== bfd_link_hash_undefined
1932 || ((h
->root
.type
== bfd_link_hash_defined
1933 || h
->root
.type
== bfd_link_hash_defweak
)
1934 && h
->root
.u
.def
.section
== bfd_und_section_ptr
)))
1936 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1937 if (require_reloc_pc32
)
1941 tsec
= h
->root
.u
.def
.section
;
1942 toff
= h
->root
.u
.def
.value
;
1949 /* Don't convert GOTPCREL relocation against large section. */
1950 if (elf_section_data (tsec
) != NULL
1951 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1954 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1958 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1960 /* At this stage in linking, no SEC_MERGE symbol has been
1961 adjusted, so all references to such symbols need to be
1962 passed through _bfd_merged_section_offset. (Later, in
1963 relocate_section, all SEC_MERGE symbols *except* for
1964 section symbols have been adjusted.)
1966 gas may reduce relocations against symbols in SEC_MERGE
1967 sections to a relocation against the section symbol when
1968 the original addend was zero. When the reloc is against
1969 a section symbol we should include the addend in the
1970 offset passed to _bfd_merged_section_offset, since the
1971 location of interest is the original symbol. On the
1972 other hand, an access to "sym+addend" where "sym" is not
1973 a section symbol should not include the addend; Such an
1974 access is presumed to be an offset from "sym"; The
1975 location of interest is just "sym". */
1976 if (symtype
== STT_SECTION
)
1979 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1980 elf_section_data (tsec
)->sec_info
,
1983 if (symtype
!= STT_SECTION
)
1989 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1990 if (tsec
->output_section
== sec
->output_section
)
1992 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
1997 bfd_signed_vma distance
;
1999 /* At this point, we don't know the load addresses of TSEC
2000 section nor SEC section. We estimate the distrance between
2001 SEC and TSEC. We store the estimated distances in the
2002 compressed_size field of the output section, which is only
2003 used to decompress the compressed input section. */
2004 if (sec
->output_section
->compressed_size
== 0)
2007 bfd_size_type size
= 0;
2008 for (asect
= link_info
->output_bfd
->sections
;
2010 asect
= asect
->next
)
2011 /* Skip debug sections since compressed_size is used to
2012 compress debug sections. */
2013 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
2016 for (i
= asect
->map_head
.s
;
2020 size
= align_power (size
, i
->alignment_power
);
2023 asect
->compressed_size
= size
;
2027 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2029 distance
= (tsec
->output_section
->compressed_size
2030 - sec
->output_section
->compressed_size
);
2034 /* Take PT_GNU_RELRO segment into account by adding
2036 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
2037 - roff
+ 0x80000000) > 0xffffffff)
2044 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2049 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2051 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2054 /* Convert to "jmp foo nop". */
2057 nop_offset
= irel
->r_offset
+ 3;
2058 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2059 irel
->r_offset
-= 1;
2060 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2064 struct elf_x86_64_link_hash_entry
*eh
2065 = (struct elf_x86_64_link_hash_entry
*) h
;
2067 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2070 /* To support TLS optimization, always use addr32 prefix for
2071 "call *__tls_get_addr@GOTPCREL(%rip)". */
2072 if (eh
&& eh
->tls_get_addr
== 1)
2075 nop_offset
= irel
->r_offset
- 2;
2079 nop
= link_info
->call_nop_byte
;
2080 if (link_info
->call_nop_as_suffix
)
2082 nop_offset
= irel
->r_offset
+ 3;
2083 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2084 irel
->r_offset
-= 1;
2085 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2088 nop_offset
= irel
->r_offset
- 2;
2091 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2092 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2093 r_type
= R_X86_64_PC32
;
2098 unsigned int rex_mask
= REX_R
;
2100 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2101 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2109 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2110 "lea foo(%rip), %reg". */
2112 r_type
= R_X86_64_PC32
;
2116 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2117 "mov $foo, %reg". */
2119 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2120 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2121 if ((rex
& REX_W
) != 0
2122 && ABI_64_P (link_info
->output_bfd
))
2124 /* Keep the REX_W bit in REX byte for LP64. */
2125 r_type
= R_X86_64_32S
;
2126 goto rewrite_modrm_rex
;
2130 /* If the REX_W bit in REX byte isn't needed,
2131 use R_X86_64_32 and clear the W bit to avoid
2132 sign-extend imm32 to imm64. */
2133 r_type
= R_X86_64_32
;
2134 /* Clear the W bit in REX byte. */
2136 goto rewrite_modrm_rex
;
2142 /* R_X86_64_PC32 isn't supported. */
2146 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2149 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2150 "test $foo, %reg". */
2151 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2156 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2157 "binop $foo, %reg". */
2158 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2162 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2163 overflow when sign-extending imm32 to imm64. */
2164 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2167 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2171 /* Move the R bit to the B bit in REX byte. */
2172 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2173 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2176 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2180 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2183 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2190 /* Look through the relocs for a section during the first phase, and
2191 calculate needed space in the global offset table, procedure
2192 linkage table, and dynamic reloc sections. */
2195 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2197 const Elf_Internal_Rela
*relocs
)
2199 struct elf_x86_64_link_hash_table
*htab
;
2200 Elf_Internal_Shdr
*symtab_hdr
;
2201 struct elf_link_hash_entry
**sym_hashes
;
2202 const Elf_Internal_Rela
*rel
;
2203 const Elf_Internal_Rela
*rel_end
;
2206 bfd_boolean use_plt_got
;
2208 if (bfd_link_relocatable (info
))
2211 /* Don't do anything special with non-loaded, non-alloced sections.
2212 In particular, any relocs in such sections should not affect GOT
2213 and PLT reference counting (ie. we don't allow them to create GOT
2214 or PLT entries), there's no possibility or desire to optimize TLS
2215 relocs, and there's not much point in propagating relocs to shared
2216 libs that the dynamic linker won't relocate. */
2217 if ((sec
->flags
& SEC_ALLOC
) == 0)
2220 BFD_ASSERT (is_x86_64_elf (abfd
));
2222 htab
= elf_x86_64_hash_table (info
);
2225 sec
->check_relocs_failed
= 1;
2229 /* Get the section contents. */
2230 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2231 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2232 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2234 sec
->check_relocs_failed
= 1;
2238 use_plt_got
= get_elf_x86_64_backend_data (abfd
) == &elf_x86_64_arch_bed
;
2240 symtab_hdr
= &elf_symtab_hdr (abfd
);
2241 sym_hashes
= elf_sym_hashes (abfd
);
2245 rel_end
= relocs
+ sec
->reloc_count
;
2246 for (rel
= relocs
; rel
< rel_end
; rel
++)
2248 unsigned int r_type
;
2249 unsigned long r_symndx
;
2250 struct elf_link_hash_entry
*h
;
2251 struct elf_x86_64_link_hash_entry
*eh
;
2252 Elf_Internal_Sym
*isym
;
2254 bfd_boolean size_reloc
;
2256 r_symndx
= htab
->r_sym (rel
->r_info
);
2257 r_type
= ELF32_R_TYPE (rel
->r_info
);
2259 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2261 /* xgettext:c-format */
2262 _bfd_error_handler (_("%B: bad symbol index: %d"),
2267 if (r_symndx
< symtab_hdr
->sh_info
)
2269 /* A local symbol. */
2270 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2275 /* Check relocation against local STT_GNU_IFUNC symbol. */
2276 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2278 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2283 /* Fake a STT_GNU_IFUNC symbol. */
2284 h
->type
= STT_GNU_IFUNC
;
2287 h
->forced_local
= 1;
2288 h
->root
.type
= bfd_link_hash_defined
;
2296 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2297 while (h
->root
.type
== bfd_link_hash_indirect
2298 || h
->root
.type
== bfd_link_hash_warning
)
2299 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2302 /* Check invalid x32 relocations. */
2303 if (!ABI_64_P (abfd
))
2309 case R_X86_64_DTPOFF64
:
2310 case R_X86_64_TPOFF64
:
2312 case R_X86_64_GOTOFF64
:
2313 case R_X86_64_GOT64
:
2314 case R_X86_64_GOTPCREL64
:
2315 case R_X86_64_GOTPC64
:
2316 case R_X86_64_GOTPLT64
:
2317 case R_X86_64_PLTOFF64
:
2320 name
= h
->root
.root
.string
;
2322 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2325 /* xgettext:c-format */
2326 (_("%B: relocation %s against symbol `%s' isn't "
2327 "supported in x32 mode"), abfd
,
2328 x86_64_elf_howto_table
[r_type
].name
, name
);
2329 bfd_set_error (bfd_error_bad_value
);
2342 case R_X86_64_PC32_BND
:
2343 case R_X86_64_PLT32_BND
:
2345 case R_X86_64_PLT32
:
2348 /* MPX PLT is supported only if elf_x86_64_arch_bed
2349 is used in 64-bit mode. */
2352 && (get_elf_x86_64_backend_data (abfd
)
2353 == &elf_x86_64_arch_bed
))
2355 elf_x86_64_hash_entry (h
)->has_bnd_reloc
= 1;
2357 /* Create the second PLT for Intel MPX support. */
2358 if (htab
->plt_bnd
== NULL
)
2360 const struct elf_backend_data
*bed
;
2362 bed
= get_elf_backend_data (info
->output_bfd
);
2363 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry
) == 8
2364 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2365 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2367 if (htab
->elf
.dynobj
== NULL
)
2368 htab
->elf
.dynobj
= abfd
;
2370 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2372 (bed
->dynamic_sec_flags
2377 if (htab
->plt_bnd
== NULL
2378 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2384 if (!info
->no_ld_generated_unwind_info
2385 && htab
->plt_bnd_eh_frame
== NULL
)
2387 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2388 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2389 | SEC_LINKER_CREATED
);
2390 htab
->plt_bnd_eh_frame
2391 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2394 if (htab
->plt_bnd_eh_frame
== NULL
2395 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2396 htab
->plt_bnd_eh_frame
,
2405 case R_X86_64_GOTPCREL
:
2406 case R_X86_64_GOTPCRELX
:
2407 case R_X86_64_REX_GOTPCRELX
:
2408 case R_X86_64_GOTPCREL64
:
2409 if (htab
->elf
.dynobj
== NULL
)
2410 htab
->elf
.dynobj
= abfd
;
2411 /* Create the ifunc sections for static executables. */
2412 if (h
->type
== STT_GNU_IFUNC
2413 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
2419 /* It is referenced by a non-shared object. */
2421 h
->root
.non_ir_ref
= 1;
2423 if (h
->type
== STT_GNU_IFUNC
)
2424 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2425 |= elf_gnu_symbol_ifunc
;
2428 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2429 symtab_hdr
, sym_hashes
,
2430 &r_type
, GOT_UNKNOWN
,
2431 rel
, rel_end
, h
, r_symndx
, FALSE
))
2434 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2437 case R_X86_64_TLSLD
:
2438 htab
->tls_ld_got
.refcount
+= 1;
2441 case R_X86_64_TPOFF32
:
2442 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2443 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2444 &x86_64_elf_howto_table
[r_type
]);
2446 eh
->has_got_reloc
= 1;
2449 case R_X86_64_GOTTPOFF
:
2450 if (!bfd_link_executable (info
))
2451 info
->flags
|= DF_STATIC_TLS
;
2454 case R_X86_64_GOT32
:
2455 case R_X86_64_GOTPCREL
:
2456 case R_X86_64_GOTPCRELX
:
2457 case R_X86_64_REX_GOTPCRELX
:
2458 case R_X86_64_TLSGD
:
2459 case R_X86_64_GOT64
:
2460 case R_X86_64_GOTPCREL64
:
2461 case R_X86_64_GOTPLT64
:
2462 case R_X86_64_GOTPC32_TLSDESC
:
2463 case R_X86_64_TLSDESC_CALL
:
2464 /* This symbol requires a global offset table entry. */
2466 int tls_type
, old_tls_type
;
2470 default: tls_type
= GOT_NORMAL
; break;
2471 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2472 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2473 case R_X86_64_GOTPC32_TLSDESC
:
2474 case R_X86_64_TLSDESC_CALL
:
2475 tls_type
= GOT_TLS_GDESC
; break;
2480 h
->got
.refcount
+= 1;
2481 old_tls_type
= eh
->tls_type
;
2485 bfd_signed_vma
*local_got_refcounts
;
2487 /* This is a global offset table entry for a local symbol. */
2488 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2489 if (local_got_refcounts
== NULL
)
2493 size
= symtab_hdr
->sh_info
;
2494 size
*= sizeof (bfd_signed_vma
)
2495 + sizeof (bfd_vma
) + sizeof (char);
2496 local_got_refcounts
= ((bfd_signed_vma
*)
2497 bfd_zalloc (abfd
, size
));
2498 if (local_got_refcounts
== NULL
)
2500 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2501 elf_x86_64_local_tlsdesc_gotent (abfd
)
2502 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2503 elf_x86_64_local_got_tls_type (abfd
)
2504 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2506 local_got_refcounts
[r_symndx
] += 1;
2508 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2511 /* If a TLS symbol is accessed using IE at least once,
2512 there is no point to use dynamic model for it. */
2513 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2514 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2515 || tls_type
!= GOT_TLS_IE
))
2517 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2518 tls_type
= old_tls_type
;
2519 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2520 && GOT_TLS_GD_ANY_P (tls_type
))
2521 tls_type
|= old_tls_type
;
2525 name
= h
->root
.root
.string
;
2527 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2530 /* xgettext:c-format */
2531 (_("%B: '%s' accessed both as normal and"
2532 " thread local symbol"),
2534 bfd_set_error (bfd_error_bad_value
);
2539 if (old_tls_type
!= tls_type
)
2542 eh
->tls_type
= tls_type
;
2544 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2549 case R_X86_64_GOTOFF64
:
2550 case R_X86_64_GOTPC32
:
2551 case R_X86_64_GOTPC64
:
2554 eh
->has_got_reloc
= 1;
2555 if (htab
->elf
.sgot
== NULL
)
2557 if (htab
->elf
.dynobj
== NULL
)
2558 htab
->elf
.dynobj
= abfd
;
2559 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
2565 case R_X86_64_PLT32
:
2566 case R_X86_64_PLT32_BND
:
2567 /* This symbol requires a procedure linkage table entry. We
2568 actually build the entry in adjust_dynamic_symbol,
2569 because this might be a case of linking PIC code which is
2570 never referenced by a dynamic object, in which case we
2571 don't need to generate a procedure linkage table entry
2574 /* If this is a local symbol, we resolve it directly without
2575 creating a procedure linkage table entry. */
2579 eh
->has_got_reloc
= 1;
2581 h
->plt
.refcount
+= 1;
2584 case R_X86_64_PLTOFF64
:
2585 /* This tries to form the 'address' of a function relative
2586 to GOT. For global symbols we need a PLT entry. */
2590 h
->plt
.refcount
+= 1;
2594 case R_X86_64_SIZE32
:
2595 case R_X86_64_SIZE64
:
2600 if (!ABI_64_P (abfd
))
2606 /* Check relocation overflow as these relocs may lead to
2607 run-time relocation overflow. Don't error out for
2608 sections we don't care about, such as debug sections or
2609 when relocation overflow check is disabled. */
2610 if (!info
->no_reloc_overflow_check
2611 && (bfd_link_pic (info
)
2612 || (bfd_link_executable (info
)
2616 && (sec
->flags
& SEC_READONLY
) == 0)))
2617 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2618 &x86_64_elf_howto_table
[r_type
]);
2624 case R_X86_64_PC32_BND
:
2628 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2629 eh
->has_non_got_reloc
= 1;
2630 /* We are called after all symbols have been resolved. Only
2631 relocation against STT_GNU_IFUNC symbol must go through
2634 && (bfd_link_executable (info
)
2635 || h
->type
== STT_GNU_IFUNC
))
2637 /* If this reloc is in a read-only section, we might
2638 need a copy reloc. We can't check reliably at this
2639 stage whether the section is read-only, as input
2640 sections have not yet been mapped to output sections.
2641 Tentatively set the flag for now, and correct in
2642 adjust_dynamic_symbol. */
2645 /* We may need a .plt entry if the symbol is a function
2646 defined in a shared lib or is a STT_GNU_IFUNC function
2647 referenced from the code or read-only section. */
2649 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2650 h
->plt
.refcount
+= 1;
2652 if (r_type
== R_X86_64_PC32
)
2654 /* Since something like ".long foo - ." may be used
2655 as pointer, make sure that PLT is used if foo is
2656 a function defined in a shared library. */
2657 if ((sec
->flags
& SEC_CODE
) == 0)
2658 h
->pointer_equality_needed
= 1;
2660 else if (r_type
!= R_X86_64_PC32_BND
2661 && r_type
!= R_X86_64_PC64
)
2663 h
->pointer_equality_needed
= 1;
2664 /* At run-time, R_X86_64_64 can be resolved for both
2665 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2666 can only be resolved for x32. */
2667 if ((sec
->flags
& SEC_READONLY
) == 0
2668 && (r_type
== R_X86_64_64
2669 || (!ABI_64_P (abfd
)
2670 && (r_type
== R_X86_64_32
2671 || r_type
== R_X86_64_32S
))))
2672 eh
->func_pointer_refcount
+= 1;
2678 /* If we are creating a shared library, and this is a reloc
2679 against a global symbol, or a non PC relative reloc
2680 against a local symbol, then we need to copy the reloc
2681 into the shared library. However, if we are linking with
2682 -Bsymbolic, we do not need to copy a reloc against a
2683 global symbol which is defined in an object we are
2684 including in the link (i.e., DEF_REGULAR is set). At
2685 this point we have not seen all the input files, so it is
2686 possible that DEF_REGULAR is not set now but will be set
2687 later (it is never cleared). In case of a weak definition,
2688 DEF_REGULAR may be cleared later by a strong definition in
2689 a shared library. We account for that possibility below by
2690 storing information in the relocs_copied field of the hash
2691 table entry. A similar situation occurs when creating
2692 shared libraries and symbol visibility changes render the
2695 If on the other hand, we are creating an executable, we
2696 may need to keep relocations for symbols satisfied by a
2697 dynamic library if we manage to avoid copy relocs for the
2700 Generate dynamic pointer relocation against STT_GNU_IFUNC
2701 symbol in the non-code section. */
2702 if ((bfd_link_pic (info
)
2703 && (! IS_X86_64_PCREL_TYPE (r_type
)
2705 && (! (bfd_link_pie (info
)
2706 || SYMBOLIC_BIND (info
, h
))
2707 || h
->root
.type
== bfd_link_hash_defweak
2708 || !h
->def_regular
))))
2710 && h
->type
== STT_GNU_IFUNC
2711 && r_type
== htab
->pointer_r_type
2712 && (sec
->flags
& SEC_CODE
) == 0)
2713 || (ELIMINATE_COPY_RELOCS
2714 && !bfd_link_pic (info
)
2716 && (h
->root
.type
== bfd_link_hash_defweak
2717 || !h
->def_regular
)))
2719 struct elf_dyn_relocs
*p
;
2720 struct elf_dyn_relocs
**head
;
2722 /* We must copy these reloc types into the output file.
2723 Create a reloc section in dynobj and make room for
2727 if (htab
->elf
.dynobj
== NULL
)
2728 htab
->elf
.dynobj
= abfd
;
2730 sreloc
= _bfd_elf_make_dynamic_reloc_section
2731 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2732 abfd
, /*rela?*/ TRUE
);
2738 /* If this is a global symbol, we count the number of
2739 relocations we need for this symbol. */
2741 head
= &eh
->dyn_relocs
;
2744 /* Track dynamic relocs needed for local syms too.
2745 We really need local syms available to do this
2750 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2755 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2759 /* Beware of type punned pointers vs strict aliasing
2761 vpp
= &(elf_section_data (s
)->local_dynrel
);
2762 head
= (struct elf_dyn_relocs
**)vpp
;
2766 if (p
== NULL
|| p
->sec
!= sec
)
2768 bfd_size_type amt
= sizeof *p
;
2770 p
= ((struct elf_dyn_relocs
*)
2771 bfd_alloc (htab
->elf
.dynobj
, amt
));
2782 /* Count size relocation as PC-relative relocation. */
2783 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2788 /* This relocation describes the C++ object vtable hierarchy.
2789 Reconstruct it for later use during GC. */
2790 case R_X86_64_GNU_VTINHERIT
:
2791 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2795 /* This relocation describes which C++ vtable entries are actually
2796 used. Record for later use during GC. */
2797 case R_X86_64_GNU_VTENTRY
:
2798 BFD_ASSERT (h
!= NULL
);
2800 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2810 && h
->plt
.refcount
> 0
2811 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2812 || h
->got
.refcount
> 0)
2813 && htab
->plt_got
== NULL
)
2815 /* Create the GOT procedure linkage table. */
2816 unsigned int plt_got_align
;
2817 const struct elf_backend_data
*bed
;
2819 bed
= get_elf_backend_data (info
->output_bfd
);
2820 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry
) == 8
2821 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2822 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2825 if (htab
->elf
.dynobj
== NULL
)
2826 htab
->elf
.dynobj
= abfd
;
2828 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2830 (bed
->dynamic_sec_flags
2835 if (htab
->plt_got
== NULL
2836 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2841 if (!info
->no_ld_generated_unwind_info
2842 && htab
->plt_got_eh_frame
== NULL
2843 && get_elf_x86_64_backend_data (abfd
)->eh_frame_plt_got
!= NULL
)
2845 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2846 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2847 | SEC_LINKER_CREATED
);
2848 htab
->plt_got_eh_frame
2849 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2852 if (htab
->plt_got_eh_frame
== NULL
2853 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2854 htab
->plt_got_eh_frame
,
2855 ABI_64_P (htab
->elf
.dynobj
) ? 3 : 2))
2860 if ((r_type
== R_X86_64_GOTPCREL
2861 || r_type
== R_X86_64_GOTPCRELX
2862 || r_type
== R_X86_64_REX_GOTPCRELX
)
2863 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2864 sec
->need_convert_load
= 1;
2867 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2869 if (!info
->keep_memory
)
2873 /* Cache the section contents for elf_link_input_bfd. */
2874 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2881 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2883 sec
->check_relocs_failed
= 1;
2887 /* Return the section that should be marked against GC for a given
2891 elf_x86_64_gc_mark_hook (asection
*sec
,
2892 struct bfd_link_info
*info
,
2893 Elf_Internal_Rela
*rel
,
2894 struct elf_link_hash_entry
*h
,
2895 Elf_Internal_Sym
*sym
)
2898 switch (ELF32_R_TYPE (rel
->r_info
))
2900 case R_X86_64_GNU_VTINHERIT
:
2901 case R_X86_64_GNU_VTENTRY
:
2905 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2908 /* Remove undefined weak symbol from the dynamic symbol table if it
2909 is resolved to 0. */
2912 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2913 struct elf_link_hash_entry
*h
)
2915 if (h
->dynindx
!= -1
2916 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2917 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2918 elf_x86_64_hash_entry (h
)))
2921 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2927 /* Adjust a symbol defined by a dynamic object and referenced by a
2928 regular object. The current definition is in some section of the
2929 dynamic object, but we're not including those sections. We have to
2930 change the definition to something the rest of the link can
2934 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2935 struct elf_link_hash_entry
*h
)
2937 struct elf_x86_64_link_hash_table
*htab
;
2939 struct elf_x86_64_link_hash_entry
*eh
;
2940 struct elf_dyn_relocs
*p
;
2942 /* STT_GNU_IFUNC symbol must go through PLT. */
2943 if (h
->type
== STT_GNU_IFUNC
)
2945 /* All local STT_GNU_IFUNC references must be treate as local
2946 calls via local PLT. */
2948 && SYMBOL_CALLS_LOCAL (info
, h
))
2950 bfd_size_type pc_count
= 0, count
= 0;
2951 struct elf_dyn_relocs
**pp
;
2953 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2954 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2956 pc_count
+= p
->pc_count
;
2957 p
->count
-= p
->pc_count
;
2966 if (pc_count
|| count
)
2971 /* Increment PLT reference count only for PC-relative
2974 if (h
->plt
.refcount
<= 0)
2975 h
->plt
.refcount
= 1;
2977 h
->plt
.refcount
+= 1;
2982 if (h
->plt
.refcount
<= 0)
2984 h
->plt
.offset
= (bfd_vma
) -1;
2990 /* If this is a function, put it in the procedure linkage table. We
2991 will fill in the contents of the procedure linkage table later,
2992 when we know the address of the .got section. */
2993 if (h
->type
== STT_FUNC
2996 if (h
->plt
.refcount
<= 0
2997 || SYMBOL_CALLS_LOCAL (info
, h
)
2998 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2999 && h
->root
.type
== bfd_link_hash_undefweak
))
3001 /* This case can occur if we saw a PLT32 reloc in an input
3002 file, but the symbol was never referred to by a dynamic
3003 object, or if all references were garbage collected. In
3004 such a case, we don't actually need to build a procedure
3005 linkage table, and we can just do a PC32 reloc instead. */
3006 h
->plt
.offset
= (bfd_vma
) -1;
3013 /* It's possible that we incorrectly decided a .plt reloc was
3014 needed for an R_X86_64_PC32 reloc to a non-function sym in
3015 check_relocs. We can't decide accurately between function and
3016 non-function syms in check-relocs; Objects loaded later in
3017 the link may change h->type. So fix it now. */
3018 h
->plt
.offset
= (bfd_vma
) -1;
3020 /* If this is a weak symbol, and there is a real definition, the
3021 processor independent code will have arranged for us to see the
3022 real definition first, and we can just use the same value. */
3023 if (h
->u
.weakdef
!= NULL
)
3025 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3026 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3027 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3028 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3029 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
3031 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3032 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3033 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
3038 /* This is a reference to a symbol defined by a dynamic object which
3039 is not a function. */
3041 /* If we are creating a shared library, we must presume that the
3042 only references to the symbol are via the global offset table.
3043 For such cases we need not do anything here; the relocations will
3044 be handled correctly by relocate_section. */
3045 if (!bfd_link_executable (info
))
3048 /* If there are no references to this symbol that do not use the
3049 GOT, we don't need to generate a copy reloc. */
3050 if (!h
->non_got_ref
)
3053 /* If -z nocopyreloc was given, we won't generate them either. */
3054 if (info
->nocopyreloc
)
3060 if (ELIMINATE_COPY_RELOCS
)
3062 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3063 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3065 s
= p
->sec
->output_section
;
3066 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3070 /* If we didn't find any dynamic relocs in read-only sections, then
3071 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3079 /* We must allocate the symbol in our .dynbss section, which will
3080 become part of the .bss section of the executable. There will be
3081 an entry for this symbol in the .dynsym section. The dynamic
3082 object will contain position independent code, so all references
3083 from the dynamic object to this symbol will go through the global
3084 offset table. The dynamic linker will use the .dynsym entry to
3085 determine the address it must put in the global offset table, so
3086 both the dynamic object and the regular object will refer to the
3087 same memory location for the variable. */
3089 htab
= elf_x86_64_hash_table (info
);
3093 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3094 to copy the initial value out of the dynamic object and into the
3095 runtime process image. */
3096 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3098 s
= htab
->elf
.sdynrelro
;
3099 srel
= htab
->elf
.sreldynrelro
;
3103 s
= htab
->elf
.sdynbss
;
3104 srel
= htab
->elf
.srelbss
;
3106 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3108 const struct elf_backend_data
*bed
;
3109 bed
= get_elf_backend_data (info
->output_bfd
);
3110 srel
->size
+= bed
->s
->sizeof_rela
;
3114 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3117 /* Allocate space in .plt, .got and associated reloc sections for
3121 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3123 struct bfd_link_info
*info
;
3124 struct elf_x86_64_link_hash_table
*htab
;
3125 struct elf_x86_64_link_hash_entry
*eh
;
3126 struct elf_dyn_relocs
*p
;
3127 const struct elf_backend_data
*bed
;
3128 unsigned int plt_entry_size
;
3129 bfd_boolean resolved_to_zero
;
3131 if (h
->root
.type
== bfd_link_hash_indirect
)
3134 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3136 info
= (struct bfd_link_info
*) inf
;
3137 htab
= elf_x86_64_hash_table (info
);
3140 bed
= get_elf_backend_data (info
->output_bfd
);
3141 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3143 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3147 /* We can't use the GOT PLT if pointer equality is needed since
3148 finish_dynamic_symbol won't clear symbol value and the dynamic
3149 linker won't update the GOT slot. We will get into an infinite
3150 loop at run-time. */
3151 if (htab
->plt_got
!= NULL
3152 && h
->type
!= STT_GNU_IFUNC
3153 && !h
->pointer_equality_needed
3154 && h
->plt
.refcount
> 0
3155 && h
->got
.refcount
> 0)
3157 /* Don't use the regular PLT if there are both GOT and GOTPLT
3159 h
->plt
.offset
= (bfd_vma
) -1;
3161 /* Use the GOT PLT. */
3162 eh
->plt_got
.refcount
= 1;
3165 /* Clear the reference count of function pointer relocations if
3166 symbol isn't a normal function. */
3167 if (h
->type
!= STT_FUNC
)
3168 eh
->func_pointer_refcount
= 0;
3170 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3171 here if it is defined and referenced in a non-shared object. */
3172 if (h
->type
== STT_GNU_IFUNC
3175 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3177 &htab
->readonly_dynrelocs_against_ifunc
,
3180 GOT_ENTRY_SIZE
, TRUE
))
3182 asection
*s
= htab
->plt_bnd
;
3183 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3185 /* Use the .plt.bnd section if it is created. */
3186 eh
->plt_bnd
.offset
= s
->size
;
3188 /* Make room for this entry in the .plt.bnd section. */
3189 s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3197 /* Don't create the PLT entry if there are only function pointer
3198 relocations which can be resolved at run-time. */
3199 else if (htab
->elf
.dynamic_sections_created
3200 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3201 || eh
->plt_got
.refcount
> 0))
3203 bfd_boolean use_plt_got
;
3205 /* Clear the reference count of function pointer relocations
3207 eh
->func_pointer_refcount
= 0;
3209 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
3211 /* Don't use the regular PLT for DF_BIND_NOW. */
3212 h
->plt
.offset
= (bfd_vma
) -1;
3214 /* Use the GOT PLT. */
3215 h
->got
.refcount
= 1;
3216 eh
->plt_got
.refcount
= 1;
3219 use_plt_got
= eh
->plt_got
.refcount
> 0;
3221 /* Make sure this symbol is output as a dynamic symbol.
3222 Undefined weak syms won't yet be marked as dynamic. */
3223 if (h
->dynindx
== -1
3225 && !resolved_to_zero
3226 && h
->root
.type
== bfd_link_hash_undefweak
)
3228 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3232 if (bfd_link_pic (info
)
3233 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3235 asection
*s
= htab
->elf
.splt
;
3236 asection
*bnd_s
= htab
->plt_bnd
;
3237 asection
*got_s
= htab
->plt_got
;
3239 /* If this is the first .plt entry, make room for the special
3240 first entry. The .plt section is used by prelink to undo
3241 prelinking for dynamic relocations. */
3243 s
->size
= plt_entry_size
;
3246 eh
->plt_got
.offset
= got_s
->size
;
3249 h
->plt
.offset
= s
->size
;
3251 eh
->plt_bnd
.offset
= bnd_s
->size
;
3254 /* If this symbol is not defined in a regular file, and we are
3255 not generating a shared library, then set the symbol to this
3256 location in the .plt. This is required to make function
3257 pointers compare as equal between the normal executable and
3258 the shared library. */
3259 if (! bfd_link_pic (info
)
3264 /* We need to make a call to the entry of the GOT PLT
3265 instead of regular PLT entry. */
3266 h
->root
.u
.def
.section
= got_s
;
3267 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3273 /* We need to make a call to the entry of the second
3274 PLT instead of regular PLT entry. */
3275 h
->root
.u
.def
.section
= bnd_s
;
3276 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
3280 h
->root
.u
.def
.section
= s
;
3281 h
->root
.u
.def
.value
= h
->plt
.offset
;
3286 /* Make room for this entry. */
3288 got_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3291 s
->size
+= plt_entry_size
;
3293 bnd_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3295 /* We also need to make an entry in the .got.plt section,
3296 which will be placed in the .got section by the linker
3298 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3300 /* There should be no PLT relocation against resolved
3301 undefined weak symbol in executable. */
3302 if (!resolved_to_zero
)
3304 /* We also need to make an entry in the .rela.plt
3306 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3307 htab
->elf
.srelplt
->reloc_count
++;
3313 eh
->plt_got
.offset
= (bfd_vma
) -1;
3314 h
->plt
.offset
= (bfd_vma
) -1;
3320 eh
->plt_got
.offset
= (bfd_vma
) -1;
3321 h
->plt
.offset
= (bfd_vma
) -1;
3325 eh
->tlsdesc_got
= (bfd_vma
) -1;
3327 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3328 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3329 if (h
->got
.refcount
> 0
3330 && bfd_link_executable (info
)
3332 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3334 h
->got
.offset
= (bfd_vma
) -1;
3336 else if (h
->got
.refcount
> 0)
3340 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3342 /* Make sure this symbol is output as a dynamic symbol.
3343 Undefined weak syms won't yet be marked as dynamic. */
3344 if (h
->dynindx
== -1
3346 && !resolved_to_zero
3347 && h
->root
.type
== bfd_link_hash_undefweak
)
3349 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3353 if (GOT_TLS_GDESC_P (tls_type
))
3355 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3356 - elf_x86_64_compute_jump_table_size (htab
);
3357 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3358 h
->got
.offset
= (bfd_vma
) -2;
3360 if (! GOT_TLS_GDESC_P (tls_type
)
3361 || GOT_TLS_GD_P (tls_type
))
3364 h
->got
.offset
= s
->size
;
3365 s
->size
+= GOT_ENTRY_SIZE
;
3366 if (GOT_TLS_GD_P (tls_type
))
3367 s
->size
+= GOT_ENTRY_SIZE
;
3369 dyn
= htab
->elf
.dynamic_sections_created
;
3370 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3371 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3372 relocation. No dynamic relocation against resolved undefined
3373 weak symbol in executable. */
3374 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3375 || tls_type
== GOT_TLS_IE
)
3376 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3377 else if (GOT_TLS_GD_P (tls_type
))
3378 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3379 else if (! GOT_TLS_GDESC_P (tls_type
)
3380 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3381 && !resolved_to_zero
)
3382 || h
->root
.type
!= bfd_link_hash_undefweak
)
3383 && (bfd_link_pic (info
)
3384 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3385 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3386 if (GOT_TLS_GDESC_P (tls_type
))
3388 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3389 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3393 h
->got
.offset
= (bfd_vma
) -1;
3395 if (eh
->dyn_relocs
== NULL
)
3398 /* In the shared -Bsymbolic case, discard space allocated for
3399 dynamic pc-relative relocs against symbols which turn out to be
3400 defined in regular objects. For the normal shared case, discard
3401 space for pc-relative relocs that have become local due to symbol
3402 visibility changes. */
3404 if (bfd_link_pic (info
))
3406 /* Relocs that use pc_count are those that appear on a call
3407 insn, or certain REL relocs that can generated via assembly.
3408 We want calls to protected symbols to resolve directly to the
3409 function rather than going via the plt. If people want
3410 function pointer comparisons to work as expected then they
3411 should avoid writing weird assembly. */
3412 if (SYMBOL_CALLS_LOCAL (info
, h
))
3414 struct elf_dyn_relocs
**pp
;
3416 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3418 p
->count
-= p
->pc_count
;
3427 /* Also discard relocs on undefined weak syms with non-default
3428 visibility or in PIE. */
3429 if (eh
->dyn_relocs
!= NULL
)
3431 if (h
->root
.type
== bfd_link_hash_undefweak
)
3433 /* Undefined weak symbol is never bound locally in shared
3435 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3436 || resolved_to_zero
)
3437 eh
->dyn_relocs
= NULL
;
3438 else if (h
->dynindx
== -1
3439 && ! h
->forced_local
3440 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3443 /* For PIE, discard space for pc-relative relocs against
3444 symbols which turn out to need copy relocs. */
3445 else if (bfd_link_executable (info
)
3446 && (h
->needs_copy
|| eh
->needs_copy
)
3450 struct elf_dyn_relocs
**pp
;
3452 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3454 if (p
->pc_count
!= 0)
3462 else if (ELIMINATE_COPY_RELOCS
)
3464 /* For the non-shared case, discard space for relocs against
3465 symbols which turn out to need copy relocs or are not
3466 dynamic. Keep dynamic relocations for run-time function
3467 pointer initialization. */
3469 if ((!h
->non_got_ref
3470 || eh
->func_pointer_refcount
> 0
3471 || (h
->root
.type
== bfd_link_hash_undefweak
3472 && !resolved_to_zero
))
3475 || (htab
->elf
.dynamic_sections_created
3476 && (h
->root
.type
== bfd_link_hash_undefweak
3477 || h
->root
.type
== bfd_link_hash_undefined
))))
3479 /* Make sure this symbol is output as a dynamic symbol.
3480 Undefined weak syms won't yet be marked as dynamic. */
3481 if (h
->dynindx
== -1
3482 && ! h
->forced_local
3483 && ! resolved_to_zero
3484 && h
->root
.type
== bfd_link_hash_undefweak
3485 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3488 /* If that succeeded, we know we'll be keeping all the
3490 if (h
->dynindx
!= -1)
3494 eh
->dyn_relocs
= NULL
;
3495 eh
->func_pointer_refcount
= 0;
3500 /* Finally, allocate space. */
3501 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3505 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3507 BFD_ASSERT (sreloc
!= NULL
);
3509 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3515 /* Allocate space in .plt, .got and associated reloc sections for
3516 local dynamic relocs. */
3519 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3521 struct elf_link_hash_entry
*h
3522 = (struct elf_link_hash_entry
*) *slot
;
3524 if (h
->type
!= STT_GNU_IFUNC
3528 || h
->root
.type
!= bfd_link_hash_defined
)
3531 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3534 /* Find any dynamic relocs that apply to read-only sections. */
3537 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3540 struct elf_x86_64_link_hash_entry
*eh
;
3541 struct elf_dyn_relocs
*p
;
3543 /* Skip local IFUNC symbols. */
3544 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3547 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3548 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3550 asection
*s
= p
->sec
->output_section
;
3552 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3554 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3556 info
->flags
|= DF_TEXTREL
;
3558 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3559 || info
->error_textrel
)
3560 /* xgettext:c-format */
3561 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3562 p
->sec
->owner
, h
->root
.root
.string
,
3565 /* Not an error, just cut short the traversal. */
3572 /* Convert load via the GOT slot to load immediate. */
3575 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3576 struct bfd_link_info
*link_info
)
3578 Elf_Internal_Shdr
*symtab_hdr
;
3579 Elf_Internal_Rela
*internal_relocs
;
3580 Elf_Internal_Rela
*irel
, *irelend
;
3582 struct elf_x86_64_link_hash_table
*htab
;
3583 bfd_boolean changed
;
3584 bfd_signed_vma
*local_got_refcounts
;
3586 /* Don't even try to convert non-ELF outputs. */
3587 if (!is_elf_hash_table (link_info
->hash
))
3590 /* Nothing to do if there is no need or no output. */
3591 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3592 || sec
->need_convert_load
== 0
3593 || bfd_is_abs_section (sec
->output_section
))
3596 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3598 /* Load the relocations for this section. */
3599 internal_relocs
= (_bfd_elf_link_read_relocs
3600 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3601 link_info
->keep_memory
));
3602 if (internal_relocs
== NULL
)
3606 htab
= elf_x86_64_hash_table (link_info
);
3607 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3609 /* Get the section contents. */
3610 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3611 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3614 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3618 irelend
= internal_relocs
+ sec
->reloc_count
;
3619 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3621 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3622 unsigned int r_symndx
;
3623 struct elf_link_hash_entry
*h
;
3624 bfd_boolean converted
;
3626 if (r_type
!= R_X86_64_GOTPCRELX
3627 && r_type
!= R_X86_64_REX_GOTPCRELX
3628 && r_type
!= R_X86_64_GOTPCREL
)
3631 r_symndx
= htab
->r_sym (irel
->r_info
);
3632 if (r_symndx
< symtab_hdr
->sh_info
)
3633 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3634 (const Elf_Internal_Rela
*) irel
,
3638 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3639 while (h
->root
.type
== bfd_link_hash_indirect
3640 || h
->root
.type
== bfd_link_hash_warning
)
3641 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3644 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3645 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3649 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3650 &converted
, link_info
))
3655 changed
= converted
;
3658 if (h
->got
.refcount
> 0)
3659 h
->got
.refcount
-= 1;
3663 if (local_got_refcounts
!= NULL
3664 && local_got_refcounts
[r_symndx
] > 0)
3665 local_got_refcounts
[r_symndx
] -= 1;
3670 if (contents
!= NULL
3671 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3673 if (!changed
&& !link_info
->keep_memory
)
3677 /* Cache the section contents for elf_link_input_bfd. */
3678 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3682 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3685 free (internal_relocs
);
3687 elf_section_data (sec
)->relocs
= internal_relocs
;
3693 if (contents
!= NULL
3694 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3696 if (internal_relocs
!= NULL
3697 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3698 free (internal_relocs
);
3702 /* Set the sizes of the dynamic sections. */
3705 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3706 struct bfd_link_info
*info
)
3708 struct elf_x86_64_link_hash_table
*htab
;
3713 const struct elf_backend_data
*bed
;
3714 const struct elf_x86_64_backend_data
*arch_data
;
3716 htab
= elf_x86_64_hash_table (info
);
3719 bed
= get_elf_backend_data (output_bfd
);
3721 dynobj
= htab
->elf
.dynobj
;
3725 /* Set up .got offsets for local syms, and space for local dynamic
3727 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3729 bfd_signed_vma
*local_got
;
3730 bfd_signed_vma
*end_local_got
;
3731 char *local_tls_type
;
3732 bfd_vma
*local_tlsdesc_gotent
;
3733 bfd_size_type locsymcount
;
3734 Elf_Internal_Shdr
*symtab_hdr
;
3737 if (! is_x86_64_elf (ibfd
))
3740 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3742 struct elf_dyn_relocs
*p
;
3744 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3747 for (p
= (struct elf_dyn_relocs
*)
3748 (elf_section_data (s
)->local_dynrel
);
3752 if (!bfd_is_abs_section (p
->sec
)
3753 && bfd_is_abs_section (p
->sec
->output_section
))
3755 /* Input section has been discarded, either because
3756 it is a copy of a linkonce section or due to
3757 linker script /DISCARD/, so we'll be discarding
3760 else if (p
->count
!= 0)
3762 srel
= elf_section_data (p
->sec
)->sreloc
;
3763 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3764 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3765 && (info
->flags
& DF_TEXTREL
) == 0)
3767 info
->flags
|= DF_TEXTREL
;
3768 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3769 || info
->error_textrel
)
3770 /* xgettext:c-format */
3771 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3772 p
->sec
->owner
, p
->sec
);
3778 local_got
= elf_local_got_refcounts (ibfd
);
3782 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3783 locsymcount
= symtab_hdr
->sh_info
;
3784 end_local_got
= local_got
+ locsymcount
;
3785 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3786 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3788 srel
= htab
->elf
.srelgot
;
3789 for (; local_got
< end_local_got
;
3790 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3792 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3795 if (GOT_TLS_GDESC_P (*local_tls_type
))
3797 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3798 - elf_x86_64_compute_jump_table_size (htab
);
3799 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3800 *local_got
= (bfd_vma
) -2;
3802 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3803 || GOT_TLS_GD_P (*local_tls_type
))
3805 *local_got
= s
->size
;
3806 s
->size
+= GOT_ENTRY_SIZE
;
3807 if (GOT_TLS_GD_P (*local_tls_type
))
3808 s
->size
+= GOT_ENTRY_SIZE
;
3810 if (bfd_link_pic (info
)
3811 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3812 || *local_tls_type
== GOT_TLS_IE
)
3814 if (GOT_TLS_GDESC_P (*local_tls_type
))
3816 htab
->elf
.srelplt
->size
3817 += bed
->s
->sizeof_rela
;
3818 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3820 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3821 || GOT_TLS_GD_P (*local_tls_type
))
3822 srel
->size
+= bed
->s
->sizeof_rela
;
3826 *local_got
= (bfd_vma
) -1;
3830 if (htab
->tls_ld_got
.refcount
> 0)
3832 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3834 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3835 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3836 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3839 htab
->tls_ld_got
.offset
= -1;
3841 /* Allocate global sym .plt and .got entries, and space for global
3842 sym dynamic relocs. */
3843 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3846 /* Allocate .plt and .got entries, and space for local symbols. */
3847 htab_traverse (htab
->loc_hash_table
,
3848 elf_x86_64_allocate_local_dynrelocs
,
3851 /* For every jump slot reserved in the sgotplt, reloc_count is
3852 incremented. However, when we reserve space for TLS descriptors,
3853 it's not incremented, so in order to compute the space reserved
3854 for them, it suffices to multiply the reloc count by the jump
3857 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3858 so that R_X86_64_IRELATIVE entries come last. */
3859 if (htab
->elf
.srelplt
)
3861 htab
->sgotplt_jump_table_size
3862 = elf_x86_64_compute_jump_table_size (htab
);
3863 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3865 else if (htab
->elf
.irelplt
)
3866 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3868 if (htab
->tlsdesc_plt
)
3870 /* If we're not using lazy TLS relocations, don't generate the
3871 PLT and GOT entries they require. */
3872 if ((info
->flags
& DF_BIND_NOW
))
3873 htab
->tlsdesc_plt
= 0;
3876 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3877 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3878 /* Reserve room for the initial entry.
3879 FIXME: we could probably do away with it in this case. */
3880 if (htab
->elf
.splt
->size
== 0)
3881 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3882 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3883 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3887 if (htab
->elf
.sgotplt
)
3889 /* Don't allocate .got.plt section if there are no GOT nor PLT
3890 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3891 if ((htab
->elf
.hgot
== NULL
3892 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3893 && (htab
->elf
.sgotplt
->size
3894 == get_elf_backend_data (output_bfd
)->got_header_size
)
3895 && (htab
->elf
.splt
== NULL
3896 || htab
->elf
.splt
->size
== 0)
3897 && (htab
->elf
.sgot
== NULL
3898 || htab
->elf
.sgot
->size
== 0)
3899 && (htab
->elf
.iplt
== NULL
3900 || htab
->elf
.iplt
->size
== 0)
3901 && (htab
->elf
.igotplt
== NULL
3902 || htab
->elf
.igotplt
->size
== 0))
3903 htab
->elf
.sgotplt
->size
= 0;
3906 arch_data
= (htab
->plt_bnd
!= NULL
3907 ? &elf_x86_64_bnd_arch_bed
3908 : get_elf_x86_64_arch_data (bed
));
3910 if (_bfd_elf_eh_frame_present (info
))
3912 if (htab
->plt_eh_frame
!= NULL
3913 && htab
->elf
.splt
!= NULL
3914 && htab
->elf
.splt
->size
!= 0
3915 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3916 htab
->plt_eh_frame
->size
= arch_data
->eh_frame_plt_size
;
3918 if (htab
->plt_got_eh_frame
!= NULL
3919 && htab
->plt_got
!= NULL
3920 && htab
->plt_got
->size
!= 0
3921 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3922 htab
->plt_got_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3924 /* Unwind info for .plt.bnd and .plt.got sections are
3926 if (htab
->plt_bnd_eh_frame
!= NULL
3927 && htab
->plt_bnd
!= NULL
3928 && htab
->plt_bnd
->size
!= 0
3929 && !bfd_is_abs_section (htab
->plt_bnd
->output_section
))
3930 htab
->plt_bnd_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3933 /* We now have determined the sizes of the various dynamic sections.
3934 Allocate memory for them. */
3936 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3938 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3941 if (s
== htab
->elf
.splt
3942 || s
== htab
->elf
.sgot
3943 || s
== htab
->elf
.sgotplt
3944 || s
== htab
->elf
.iplt
3945 || s
== htab
->elf
.igotplt
3946 || s
== htab
->plt_bnd
3947 || s
== htab
->plt_got
3948 || s
== htab
->plt_eh_frame
3949 || s
== htab
->plt_got_eh_frame
3950 || s
== htab
->plt_bnd_eh_frame
3951 || s
== htab
->elf
.sdynbss
3952 || s
== htab
->elf
.sdynrelro
)
3954 /* Strip this section if we don't need it; see the
3957 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3959 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3962 /* We use the reloc_count field as a counter if we need
3963 to copy relocs into the output file. */
3964 if (s
!= htab
->elf
.srelplt
)
3969 /* It's not one of our sections, so don't allocate space. */
3975 /* If we don't need this section, strip it from the
3976 output file. This is mostly to handle .rela.bss and
3977 .rela.plt. We must create both sections in
3978 create_dynamic_sections, because they must be created
3979 before the linker maps input sections to output
3980 sections. The linker does that before
3981 adjust_dynamic_symbol is called, and it is that
3982 function which decides whether anything needs to go
3983 into these sections. */
3985 s
->flags
|= SEC_EXCLUDE
;
3989 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3992 /* Allocate memory for the section contents. We use bfd_zalloc
3993 here in case unused entries are not reclaimed before the
3994 section's contents are written out. This should not happen,
3995 but this way if it does, we get a R_X86_64_NONE reloc instead
3997 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3998 if (s
->contents
== NULL
)
4002 if (htab
->plt_eh_frame
!= NULL
4003 && htab
->plt_eh_frame
->contents
!= NULL
)
4005 memcpy (htab
->plt_eh_frame
->contents
,
4006 arch_data
->eh_frame_plt
, htab
->plt_eh_frame
->size
);
4007 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
4008 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
4011 if (htab
->plt_got_eh_frame
!= NULL
4012 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4014 memcpy (htab
->plt_got_eh_frame
->contents
,
4015 arch_data
->eh_frame_plt_got
,
4016 htab
->plt_got_eh_frame
->size
);
4017 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
4018 (htab
->plt_got_eh_frame
->contents
4019 + PLT_FDE_LEN_OFFSET
));
4022 if (htab
->plt_bnd_eh_frame
!= NULL
4023 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
4025 memcpy (htab
->plt_bnd_eh_frame
->contents
,
4026 arch_data
->eh_frame_plt_got
,
4027 htab
->plt_bnd_eh_frame
->size
);
4028 bfd_put_32 (dynobj
, htab
->plt_bnd
->size
,
4029 (htab
->plt_bnd_eh_frame
->contents
4030 + PLT_FDE_LEN_OFFSET
));
4033 if (htab
->elf
.dynamic_sections_created
)
4035 /* Add some entries to the .dynamic section. We fill in the
4036 values later, in elf_x86_64_finish_dynamic_sections, but we
4037 must add the entries now so that we get the correct size for
4038 the .dynamic section. The DT_DEBUG entry is filled in by the
4039 dynamic linker and used by the debugger. */
4040 #define add_dynamic_entry(TAG, VAL) \
4041 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4043 if (bfd_link_executable (info
))
4045 if (!add_dynamic_entry (DT_DEBUG
, 0))
4049 if (htab
->elf
.splt
->size
!= 0)
4051 /* DT_PLTGOT is used by prelink even if there is no PLT
4053 if (!add_dynamic_entry (DT_PLTGOT
, 0))
4057 if (htab
->elf
.srelplt
->size
!= 0)
4059 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
4060 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4061 || !add_dynamic_entry (DT_JMPREL
, 0))
4065 if (htab
->tlsdesc_plt
4066 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
4067 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
4072 if (!add_dynamic_entry (DT_RELA
, 0)
4073 || !add_dynamic_entry (DT_RELASZ
, 0)
4074 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
4077 /* If any dynamic relocs apply to a read-only section,
4078 then we need a DT_TEXTREL entry. */
4079 if ((info
->flags
& DF_TEXTREL
) == 0)
4080 elf_link_hash_traverse (&htab
->elf
,
4081 elf_x86_64_readonly_dynrelocs
,
4084 if ((info
->flags
& DF_TEXTREL
) != 0)
4086 if (htab
->readonly_dynrelocs_against_ifunc
)
4088 info
->callbacks
->einfo
4089 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4090 bfd_set_error (bfd_error_bad_value
);
4094 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4099 #undef add_dynamic_entry
4105 elf_x86_64_always_size_sections (bfd
*output_bfd
,
4106 struct bfd_link_info
*info
)
4108 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
4112 struct elf_link_hash_entry
*tlsbase
;
4114 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
4115 "_TLS_MODULE_BASE_",
4116 FALSE
, FALSE
, FALSE
);
4118 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
4120 struct elf_x86_64_link_hash_table
*htab
;
4121 struct bfd_link_hash_entry
*bh
= NULL
;
4122 const struct elf_backend_data
*bed
4123 = get_elf_backend_data (output_bfd
);
4125 htab
= elf_x86_64_hash_table (info
);
4129 if (!(_bfd_generic_link_add_one_symbol
4130 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
4131 tls_sec
, 0, NULL
, FALSE
,
4132 bed
->collect
, &bh
)))
4135 htab
->tls_module_base
= bh
;
4137 tlsbase
= (struct elf_link_hash_entry
*)bh
;
4138 tlsbase
->def_regular
= 1;
4139 tlsbase
->other
= STV_HIDDEN
;
4140 tlsbase
->root
.linker_def
= 1;
4141 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4148 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4149 executables. Rather than setting it to the beginning of the TLS
4150 section, we have to set it to the end. This function may be called
4151 multiple times, it is idempotent. */
4154 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4156 struct elf_x86_64_link_hash_table
*htab
;
4157 struct bfd_link_hash_entry
*base
;
4159 if (!bfd_link_executable (info
))
4162 htab
= elf_x86_64_hash_table (info
);
4166 base
= htab
->tls_module_base
;
4170 base
->u
.def
.value
= htab
->elf
.tls_size
;
4173 /* Return the base VMA address which should be subtracted from real addresses
4174 when resolving @dtpoff relocation.
4175 This is PT_TLS segment p_vaddr. */
4178 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4180 /* If tls_sec is NULL, we should have signalled an error already. */
4181 if (elf_hash_table (info
)->tls_sec
== NULL
)
4183 return elf_hash_table (info
)->tls_sec
->vma
;
4186 /* Return the relocation value for @tpoff relocation
4187 if STT_TLS virtual address is ADDRESS. */
4190 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4192 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4193 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4194 bfd_vma static_tls_size
;
4196 /* If tls_segment is NULL, we should have signalled an error already. */
4197 if (htab
->tls_sec
== NULL
)
4200 /* Consider special static TLS alignment requirements. */
4201 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4202 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4205 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4209 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4211 /* Opcode Instruction
4214 0x0f 0x8x conditional jump */
4216 && (contents
[offset
- 1] == 0xe8
4217 || contents
[offset
- 1] == 0xe9))
4219 && contents
[offset
- 2] == 0x0f
4220 && (contents
[offset
- 1] & 0xf0) == 0x80));
4223 /* Relocate an x86_64 ELF section. */
4226 elf_x86_64_relocate_section (bfd
*output_bfd
,
4227 struct bfd_link_info
*info
,
4229 asection
*input_section
,
4231 Elf_Internal_Rela
*relocs
,
4232 Elf_Internal_Sym
*local_syms
,
4233 asection
**local_sections
)
4235 struct elf_x86_64_link_hash_table
*htab
;
4236 Elf_Internal_Shdr
*symtab_hdr
;
4237 struct elf_link_hash_entry
**sym_hashes
;
4238 bfd_vma
*local_got_offsets
;
4239 bfd_vma
*local_tlsdesc_gotents
;
4240 Elf_Internal_Rela
*rel
;
4241 Elf_Internal_Rela
*wrel
;
4242 Elf_Internal_Rela
*relend
;
4243 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
4245 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4247 /* Skip if check_relocs failed. */
4248 if (input_section
->check_relocs_failed
)
4251 htab
= elf_x86_64_hash_table (info
);
4254 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4255 sym_hashes
= elf_sym_hashes (input_bfd
);
4256 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4257 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4259 elf_x86_64_set_tls_module_base (info
);
4261 rel
= wrel
= relocs
;
4262 relend
= relocs
+ input_section
->reloc_count
;
4263 for (; rel
< relend
; wrel
++, rel
++)
4265 unsigned int r_type
;
4266 reloc_howto_type
*howto
;
4267 unsigned long r_symndx
;
4268 struct elf_link_hash_entry
*h
;
4269 struct elf_x86_64_link_hash_entry
*eh
;
4270 Elf_Internal_Sym
*sym
;
4272 bfd_vma off
, offplt
, plt_offset
;
4274 bfd_boolean unresolved_reloc
;
4275 bfd_reloc_status_type r
;
4277 asection
*base_got
, *resolved_plt
;
4279 bfd_boolean resolved_to_zero
;
4280 bfd_boolean relative_reloc
;
4282 r_type
= ELF32_R_TYPE (rel
->r_info
);
4283 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4284 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4291 if (r_type
>= (int) R_X86_64_standard
)
4294 /* xgettext:c-format */
4295 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4296 input_bfd
, r_type
, input_section
);
4297 bfd_set_error (bfd_error_bad_value
);
4301 if (r_type
!= (int) R_X86_64_32
4302 || ABI_64_P (output_bfd
))
4303 howto
= x86_64_elf_howto_table
+ r_type
;
4305 howto
= (x86_64_elf_howto_table
4306 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4307 r_symndx
= htab
->r_sym (rel
->r_info
);
4311 unresolved_reloc
= FALSE
;
4312 if (r_symndx
< symtab_hdr
->sh_info
)
4314 sym
= local_syms
+ r_symndx
;
4315 sec
= local_sections
[r_symndx
];
4317 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4319 st_size
= sym
->st_size
;
4321 /* Relocate against local STT_GNU_IFUNC symbol. */
4322 if (!bfd_link_relocatable (info
)
4323 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4325 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4330 /* Set STT_GNU_IFUNC symbol value. */
4331 h
->root
.u
.def
.value
= sym
->st_value
;
4332 h
->root
.u
.def
.section
= sec
;
4337 bfd_boolean warned ATTRIBUTE_UNUSED
;
4338 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4340 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4341 r_symndx
, symtab_hdr
, sym_hashes
,
4343 unresolved_reloc
, warned
, ignored
);
4347 if (sec
!= NULL
&& discarded_section (sec
))
4349 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4350 contents
+ rel
->r_offset
);
4351 wrel
->r_offset
= rel
->r_offset
;
4355 /* For ld -r, remove relocations in debug sections against
4356 sections defined in discarded sections. Not done for
4357 eh_frame editing code expects to be present. */
4358 if (bfd_link_relocatable (info
)
4359 && (input_section
->flags
& SEC_DEBUGGING
))
4365 if (bfd_link_relocatable (info
))
4372 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4374 if (r_type
== R_X86_64_64
)
4376 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4377 zero-extend it to 64bit if addend is zero. */
4378 r_type
= R_X86_64_32
;
4379 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4381 else if (r_type
== R_X86_64_SIZE64
)
4383 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4384 zero-extend it to 64bit if addend is zero. */
4385 r_type
= R_X86_64_SIZE32
;
4386 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4390 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4392 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4393 it here if it is defined in a non-shared object. */
4395 && h
->type
== STT_GNU_IFUNC
4401 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4403 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4404 sections because such sections are not SEC_ALLOC and
4405 thus ld.so will not process them. */
4406 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4416 case R_X86_64_GOTPCREL
:
4417 case R_X86_64_GOTPCRELX
:
4418 case R_X86_64_REX_GOTPCRELX
:
4419 case R_X86_64_GOTPCREL64
:
4420 base_got
= htab
->elf
.sgot
;
4421 off
= h
->got
.offset
;
4423 if (base_got
== NULL
)
4426 if (off
== (bfd_vma
) -1)
4428 /* We can't use h->got.offset here to save state, or
4429 even just remember the offset, as finish_dynamic_symbol
4430 would use that as offset into .got. */
4432 if (h
->plt
.offset
== (bfd_vma
) -1)
4435 if (htab
->elf
.splt
!= NULL
)
4437 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4438 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4439 base_got
= htab
->elf
.sgotplt
;
4443 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4444 off
= plt_index
* GOT_ENTRY_SIZE
;
4445 base_got
= htab
->elf
.igotplt
;
4448 if (h
->dynindx
== -1
4452 /* This references the local defitionion. We must
4453 initialize this entry in the global offset table.
4454 Since the offset must always be a multiple of 8,
4455 we use the least significant bit to record
4456 whether we have initialized it already.
4458 When doing a dynamic link, we create a .rela.got
4459 relocation entry to initialize the value. This
4460 is done in the finish_dynamic_symbol routine. */
4465 bfd_put_64 (output_bfd
, relocation
,
4466 base_got
->contents
+ off
);
4467 /* Note that this is harmless for the GOTPLT64
4468 case, as -1 | 1 still is -1. */
4474 relocation
= (base_got
->output_section
->vma
4475 + base_got
->output_offset
+ off
);
4480 if (h
->plt
.offset
== (bfd_vma
) -1)
4482 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4483 if (r_type
== htab
->pointer_r_type
4484 && (input_section
->flags
& SEC_CODE
) == 0)
4485 goto do_ifunc_pointer
;
4486 goto bad_ifunc_reloc
;
4489 /* STT_GNU_IFUNC symbol must go through PLT. */
4490 if (htab
->elf
.splt
!= NULL
)
4492 if (htab
->plt_bnd
!= NULL
)
4494 resolved_plt
= htab
->plt_bnd
;
4495 plt_offset
= eh
->plt_bnd
.offset
;
4499 resolved_plt
= htab
->elf
.splt
;
4500 plt_offset
= h
->plt
.offset
;
4505 resolved_plt
= htab
->elf
.iplt
;
4506 plt_offset
= h
->plt
.offset
;
4509 relocation
= (resolved_plt
->output_section
->vma
4510 + resolved_plt
->output_offset
+ plt_offset
);
4516 if (h
->root
.root
.string
)
4517 name
= h
->root
.root
.string
;
4519 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4522 /* xgettext:c-format */
4523 (_("%B: relocation %s against STT_GNU_IFUNC "
4524 "symbol `%s' isn't supported"), input_bfd
,
4526 bfd_set_error (bfd_error_bad_value
);
4530 if (bfd_link_pic (info
))
4535 if (ABI_64_P (output_bfd
))
4540 if (rel
->r_addend
!= 0)
4542 if (h
->root
.root
.string
)
4543 name
= h
->root
.root
.string
;
4545 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4548 /* xgettext:c-format */
4549 (_("%B: relocation %s against STT_GNU_IFUNC "
4550 "symbol `%s' has non-zero addend: %d"),
4551 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4552 bfd_set_error (bfd_error_bad_value
);
4556 /* Generate dynamic relcoation only when there is a
4557 non-GOT reference in a shared object or there is no
4559 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4560 || h
->plt
.offset
== (bfd_vma
) -1)
4562 Elf_Internal_Rela outrel
;
4565 /* Need a dynamic relocation to get the real function
4567 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4571 if (outrel
.r_offset
== (bfd_vma
) -1
4572 || outrel
.r_offset
== (bfd_vma
) -2)
4575 outrel
.r_offset
+= (input_section
->output_section
->vma
4576 + input_section
->output_offset
);
4578 if (h
->dynindx
== -1
4580 || bfd_link_executable (info
))
4582 /* This symbol is resolved locally. */
4583 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4584 outrel
.r_addend
= (h
->root
.u
.def
.value
4585 + h
->root
.u
.def
.section
->output_section
->vma
4586 + h
->root
.u
.def
.section
->output_offset
);
4590 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4591 outrel
.r_addend
= 0;
4594 /* Dynamic relocations are stored in
4595 1. .rela.ifunc section in PIC object.
4596 2. .rela.got section in dynamic executable.
4597 3. .rela.iplt section in static executable. */
4598 if (bfd_link_pic (info
))
4599 sreloc
= htab
->elf
.irelifunc
;
4600 else if (htab
->elf
.splt
!= NULL
)
4601 sreloc
= htab
->elf
.srelgot
;
4603 sreloc
= htab
->elf
.irelplt
;
4604 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4606 /* If this reloc is against an external symbol, we
4607 do not want to fiddle with the addend. Otherwise,
4608 we need to include the symbol value so that it
4609 becomes an addend for the dynamic reloc. For an
4610 internal symbol, we have updated addend. */
4615 case R_X86_64_PC32_BND
:
4617 case R_X86_64_PLT32
:
4618 case R_X86_64_PLT32_BND
:
4623 resolved_to_zero
= (eh
!= NULL
4624 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4628 /* When generating a shared object, the relocations handled here are
4629 copied into the output file to be resolved at run time. */
4632 case R_X86_64_GOT32
:
4633 case R_X86_64_GOT64
:
4634 /* Relocation is to the entry for this symbol in the global
4636 case R_X86_64_GOTPCREL
:
4637 case R_X86_64_GOTPCRELX
:
4638 case R_X86_64_REX_GOTPCRELX
:
4639 case R_X86_64_GOTPCREL64
:
4640 /* Use global offset table entry as symbol value. */
4641 case R_X86_64_GOTPLT64
:
4642 /* This is obsolete and treated the the same as GOT64. */
4643 base_got
= htab
->elf
.sgot
;
4645 if (htab
->elf
.sgot
== NULL
)
4648 relative_reloc
= FALSE
;
4653 off
= h
->got
.offset
;
4655 && h
->plt
.offset
!= (bfd_vma
)-1
4656 && off
== (bfd_vma
)-1)
4658 /* We can't use h->got.offset here to save
4659 state, or even just remember the offset, as
4660 finish_dynamic_symbol would use that as offset into
4662 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4663 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4664 base_got
= htab
->elf
.sgotplt
;
4667 dyn
= htab
->elf
.dynamic_sections_created
;
4669 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4670 || (bfd_link_pic (info
)
4671 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4672 || (ELF_ST_VISIBILITY (h
->other
)
4673 && h
->root
.type
== bfd_link_hash_undefweak
))
4675 /* This is actually a static link, or it is a -Bsymbolic
4676 link and the symbol is defined locally, or the symbol
4677 was forced to be local because of a version file. We
4678 must initialize this entry in the global offset table.
4679 Since the offset must always be a multiple of 8, we
4680 use the least significant bit to record whether we
4681 have initialized it already.
4683 When doing a dynamic link, we create a .rela.got
4684 relocation entry to initialize the value. This is
4685 done in the finish_dynamic_symbol routine. */
4690 bfd_put_64 (output_bfd
, relocation
,
4691 base_got
->contents
+ off
);
4692 /* Note that this is harmless for the GOTPLT64 case,
4693 as -1 | 1 still is -1. */
4696 if (h
->dynindx
== -1
4698 && h
->root
.type
!= bfd_link_hash_undefweak
4699 && bfd_link_pic (info
))
4701 /* If this symbol isn't dynamic in PIC,
4702 generate R_X86_64_RELATIVE here. */
4703 eh
->no_finish_dynamic_symbol
= 1;
4704 relative_reloc
= TRUE
;
4709 unresolved_reloc
= FALSE
;
4713 if (local_got_offsets
== NULL
)
4716 off
= local_got_offsets
[r_symndx
];
4718 /* The offset must always be a multiple of 8. We use
4719 the least significant bit to record whether we have
4720 already generated the necessary reloc. */
4725 bfd_put_64 (output_bfd
, relocation
,
4726 base_got
->contents
+ off
);
4727 local_got_offsets
[r_symndx
] |= 1;
4729 if (bfd_link_pic (info
))
4730 relative_reloc
= TRUE
;
4737 Elf_Internal_Rela outrel
;
4739 /* We need to generate a R_X86_64_RELATIVE reloc
4740 for the dynamic linker. */
4741 s
= htab
->elf
.srelgot
;
4745 outrel
.r_offset
= (base_got
->output_section
->vma
4746 + base_got
->output_offset
4748 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4749 outrel
.r_addend
= relocation
;
4750 elf_append_rela (output_bfd
, s
, &outrel
);
4753 if (off
>= (bfd_vma
) -2)
4756 relocation
= base_got
->output_section
->vma
4757 + base_got
->output_offset
+ off
;
4758 if (r_type
!= R_X86_64_GOTPCREL
4759 && r_type
!= R_X86_64_GOTPCRELX
4760 && r_type
!= R_X86_64_REX_GOTPCRELX
4761 && r_type
!= R_X86_64_GOTPCREL64
)
4762 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4763 - htab
->elf
.sgotplt
->output_offset
;
4767 case R_X86_64_GOTOFF64
:
4768 /* Relocation is relative to the start of the global offset
4771 /* Check to make sure it isn't a protected function or data
4772 symbol for shared library since it may not be local when
4773 used as function address or with copy relocation. We also
4774 need to make sure that a symbol is referenced locally. */
4775 if (bfd_link_pic (info
) && h
)
4777 if (!h
->def_regular
)
4781 switch (ELF_ST_VISIBILITY (h
->other
))
4784 v
= _("hidden symbol");
4787 v
= _("internal symbol");
4790 v
= _("protected symbol");
4798 /* xgettext:c-format */
4799 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4800 " `%s' can not be used when making a shared object"),
4801 input_bfd
, v
, h
->root
.root
.string
);
4802 bfd_set_error (bfd_error_bad_value
);
4805 else if (!bfd_link_executable (info
)
4806 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4807 && (h
->type
== STT_FUNC
4808 || h
->type
== STT_OBJECT
)
4809 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4812 /* xgettext:c-format */
4813 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4814 " `%s' can not be used when making a shared object"),
4816 h
->type
== STT_FUNC
? "function" : "data",
4817 h
->root
.root
.string
);
4818 bfd_set_error (bfd_error_bad_value
);
4823 /* Note that sgot is not involved in this
4824 calculation. We always want the start of .got.plt. If we
4825 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4826 permitted by the ABI, we might have to change this
4828 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4829 + htab
->elf
.sgotplt
->output_offset
;
4832 case R_X86_64_GOTPC32
:
4833 case R_X86_64_GOTPC64
:
4834 /* Use global offset table as symbol value. */
4835 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4836 + htab
->elf
.sgotplt
->output_offset
;
4837 unresolved_reloc
= FALSE
;
4840 case R_X86_64_PLTOFF64
:
4841 /* Relocation is PLT entry relative to GOT. For local
4842 symbols it's the symbol itself relative to GOT. */
4844 /* See PLT32 handling. */
4845 && (h
->plt
.offset
!= (bfd_vma
) -1
4846 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4847 && htab
->elf
.splt
!= NULL
)
4849 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4851 /* Use the GOT PLT. */
4852 resolved_plt
= htab
->plt_got
;
4853 plt_offset
= eh
->plt_got
.offset
;
4855 else if (htab
->plt_bnd
!= NULL
)
4857 resolved_plt
= htab
->plt_bnd
;
4858 plt_offset
= eh
->plt_bnd
.offset
;
4862 resolved_plt
= htab
->elf
.splt
;
4863 plt_offset
= h
->plt
.offset
;
4866 relocation
= (resolved_plt
->output_section
->vma
4867 + resolved_plt
->output_offset
4869 unresolved_reloc
= FALSE
;
4872 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4873 + htab
->elf
.sgotplt
->output_offset
;
4876 case R_X86_64_PLT32
:
4877 case R_X86_64_PLT32_BND
:
4878 /* Relocation is to the entry for this symbol in the
4879 procedure linkage table. */
4881 /* Resolve a PLT32 reloc against a local symbol directly,
4882 without using the procedure linkage table. */
4886 if ((h
->plt
.offset
== (bfd_vma
) -1
4887 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4888 || htab
->elf
.splt
== NULL
)
4890 /* We didn't make a PLT entry for this symbol. This
4891 happens when statically linking PIC code, or when
4892 using -Bsymbolic. */
4896 if (h
->plt
.offset
!= (bfd_vma
) -1)
4898 if (htab
->plt_bnd
!= NULL
)
4900 resolved_plt
= htab
->plt_bnd
;
4901 plt_offset
= eh
->plt_bnd
.offset
;
4905 resolved_plt
= htab
->elf
.splt
;
4906 plt_offset
= h
->plt
.offset
;
4911 /* Use the GOT PLT. */
4912 resolved_plt
= htab
->plt_got
;
4913 plt_offset
= eh
->plt_got
.offset
;
4916 relocation
= (resolved_plt
->output_section
->vma
4917 + resolved_plt
->output_offset
4919 unresolved_reloc
= FALSE
;
4922 case R_X86_64_SIZE32
:
4923 case R_X86_64_SIZE64
:
4924 /* Set to symbol size. */
4925 relocation
= st_size
;
4931 case R_X86_64_PC32_BND
:
4932 /* Don't complain about -fPIC if the symbol is undefined when
4933 building executable unless it is unresolved weak symbol. */
4934 if ((input_section
->flags
& SEC_ALLOC
) != 0
4935 && (input_section
->flags
& SEC_READONLY
) != 0
4937 && ((bfd_link_executable (info
)
4938 && h
->root
.type
== bfd_link_hash_undefweak
4939 && !resolved_to_zero
)
4940 || (bfd_link_pic (info
)
4941 && !(bfd_link_pie (info
)
4942 && h
->root
.type
== bfd_link_hash_undefined
))))
4944 bfd_boolean fail
= FALSE
;
4946 = ((r_type
== R_X86_64_PC32
4947 || r_type
== R_X86_64_PC32_BND
)
4948 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4950 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4952 /* Symbol is referenced locally. Make sure it is
4953 defined locally or for a branch. */
4954 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4957 else if (!(bfd_link_pie (info
)
4958 && (h
->needs_copy
|| eh
->needs_copy
)))
4960 /* Symbol doesn't need copy reloc and isn't referenced
4961 locally. We only allow branch to symbol with
4962 non-default visibility. */
4964 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4968 return elf_x86_64_need_pic (input_bfd
, input_section
,
4969 h
, NULL
, NULL
, howto
);
4978 /* FIXME: The ABI says the linker should make sure the value is
4979 the same when it's zeroextended to 64 bit. */
4982 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4985 /* Don't copy a pc-relative relocation into the output file
4986 if the symbol needs copy reloc or the symbol is undefined
4987 when building executable. Copy dynamic function pointer
4988 relocations. Don't generate dynamic relocations against
4989 resolved undefined weak symbols in PIE. */
4990 if ((bfd_link_pic (info
)
4991 && !(bfd_link_pie (info
)
4995 || h
->root
.type
== bfd_link_hash_undefined
)
4996 && (IS_X86_64_PCREL_TYPE (r_type
)
4997 || r_type
== R_X86_64_SIZE32
4998 || r_type
== R_X86_64_SIZE64
))
5000 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5001 && !resolved_to_zero
)
5002 || h
->root
.type
!= bfd_link_hash_undefweak
))
5003 && ((! IS_X86_64_PCREL_TYPE (r_type
)
5004 && r_type
!= R_X86_64_SIZE32
5005 && r_type
!= R_X86_64_SIZE64
)
5006 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
5007 || (ELIMINATE_COPY_RELOCS
5008 && !bfd_link_pic (info
)
5012 || eh
->func_pointer_refcount
> 0
5013 || (h
->root
.type
== bfd_link_hash_undefweak
5014 && !resolved_to_zero
))
5015 && ((h
->def_dynamic
&& !h
->def_regular
)
5016 /* Undefined weak symbol is bound locally when
5018 || h
->root
.type
== bfd_link_hash_undefined
)))
5020 Elf_Internal_Rela outrel
;
5021 bfd_boolean skip
, relocate
;
5024 /* When generating a shared object, these relocations
5025 are copied into the output file to be resolved at run
5031 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5033 if (outrel
.r_offset
== (bfd_vma
) -1)
5035 else if (outrel
.r_offset
== (bfd_vma
) -2)
5036 skip
= TRUE
, relocate
= TRUE
;
5038 outrel
.r_offset
+= (input_section
->output_section
->vma
5039 + input_section
->output_offset
);
5042 memset (&outrel
, 0, sizeof outrel
);
5044 /* h->dynindx may be -1 if this symbol was marked to
5048 && (IS_X86_64_PCREL_TYPE (r_type
)
5049 || !(bfd_link_executable (info
)
5050 || SYMBOLIC_BIND (info
, h
))
5051 || ! h
->def_regular
))
5053 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
5054 outrel
.r_addend
= rel
->r_addend
;
5058 /* This symbol is local, or marked to become local.
5059 When relocation overflow check is disabled, we
5060 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
5061 if (r_type
== htab
->pointer_r_type
5062 || (r_type
== R_X86_64_32
5063 && info
->no_reloc_overflow_check
))
5066 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5067 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5069 else if (r_type
== R_X86_64_64
5070 && !ABI_64_P (output_bfd
))
5073 outrel
.r_info
= htab
->r_info (0,
5074 R_X86_64_RELATIVE64
);
5075 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5076 /* Check addend overflow. */
5077 if ((outrel
.r_addend
& 0x80000000)
5078 != (rel
->r_addend
& 0x80000000))
5081 int addend
= rel
->r_addend
;
5082 if (h
&& h
->root
.root
.string
)
5083 name
= h
->root
.root
.string
;
5085 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5089 /* xgettext:c-format */
5090 (_("%B: addend -0x%x in relocation %s against "
5091 "symbol `%s' at 0x%lx in section `%A' is "
5093 input_bfd
, addend
, howto
->name
, name
,
5094 (unsigned long) rel
->r_offset
, input_section
);
5097 /* xgettext:c-format */
5098 (_("%B: addend 0x%x in relocation %s against "
5099 "symbol `%s' at 0x%lx in section `%A' is "
5101 input_bfd
, addend
, howto
->name
, name
,
5102 (unsigned long) rel
->r_offset
, input_section
);
5103 bfd_set_error (bfd_error_bad_value
);
5111 if (bfd_is_abs_section (sec
))
5113 else if (sec
== NULL
|| sec
->owner
== NULL
)
5115 bfd_set_error (bfd_error_bad_value
);
5122 /* We are turning this relocation into one
5123 against a section symbol. It would be
5124 proper to subtract the symbol's value,
5125 osec->vma, from the emitted reloc addend,
5126 but ld.so expects buggy relocs. */
5127 osec
= sec
->output_section
;
5128 sindx
= elf_section_data (osec
)->dynindx
;
5131 asection
*oi
= htab
->elf
.text_index_section
;
5132 sindx
= elf_section_data (oi
)->dynindx
;
5134 BFD_ASSERT (sindx
!= 0);
5137 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
5138 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5142 sreloc
= elf_section_data (input_section
)->sreloc
;
5144 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5146 r
= bfd_reloc_notsupported
;
5147 goto check_relocation_error
;
5150 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5152 /* If this reloc is against an external symbol, we do
5153 not want to fiddle with the addend. Otherwise, we
5154 need to include the symbol value so that it becomes
5155 an addend for the dynamic reloc. */
5162 case R_X86_64_TLSGD
:
5163 case R_X86_64_GOTPC32_TLSDESC
:
5164 case R_X86_64_TLSDESC_CALL
:
5165 case R_X86_64_GOTTPOFF
:
5166 tls_type
= GOT_UNKNOWN
;
5167 if (h
== NULL
&& local_got_offsets
)
5168 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5170 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5172 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5173 input_section
, contents
,
5174 symtab_hdr
, sym_hashes
,
5175 &r_type
, tls_type
, rel
,
5176 relend
, h
, r_symndx
, TRUE
))
5179 if (r_type
== R_X86_64_TPOFF32
)
5181 bfd_vma roff
= rel
->r_offset
;
5183 BFD_ASSERT (! unresolved_reloc
);
5185 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5187 /* GD->LE transition. For 64bit, change
5188 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5189 .word 0x6666; rex64; call __tls_get_addr@PLT
5191 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5193 call *__tls_get_addr@GOTPCREL(%rip)
5194 which may be converted to
5195 addr32 call __tls_get_addr
5198 leaq foo@tpoff(%rax), %rax
5200 leaq foo@tlsgd(%rip), %rdi
5201 .word 0x6666; rex64; call __tls_get_addr@PLT
5203 leaq foo@tlsgd(%rip), %rdi
5205 call *__tls_get_addr@GOTPCREL(%rip)
5206 which may be converted to
5207 addr32 call __tls_get_addr
5210 leaq foo@tpoff(%rax), %rax
5211 For largepic, change:
5212 leaq foo@tlsgd(%rip), %rdi
5213 movabsq $__tls_get_addr@pltoff, %rax
5218 leaq foo@tpoff(%rax), %rax
5219 nopw 0x0(%rax,%rax,1) */
5221 if (ABI_64_P (output_bfd
))
5223 if (contents
[roff
+ 5] == 0xb8)
5225 memcpy (contents
+ roff
- 3,
5226 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5227 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5231 memcpy (contents
+ roff
- 4,
5232 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5236 memcpy (contents
+ roff
- 3,
5237 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5239 bfd_put_32 (output_bfd
,
5240 elf_x86_64_tpoff (info
, relocation
),
5241 contents
+ roff
+ 8 + largepic
);
5242 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5243 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5248 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5250 /* GDesc -> LE transition.
5251 It's originally something like:
5252 leaq x@tlsdesc(%rip), %rax
5255 movl $x@tpoff, %rax. */
5257 unsigned int val
, type
;
5259 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5260 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5261 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5262 contents
+ roff
- 3);
5263 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5264 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5265 contents
+ roff
- 1);
5266 bfd_put_32 (output_bfd
,
5267 elf_x86_64_tpoff (info
, relocation
),
5271 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5273 /* GDesc -> LE transition.
5278 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5279 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5282 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5284 /* IE->LE transition:
5285 For 64bit, originally it can be one of:
5286 movq foo@gottpoff(%rip), %reg
5287 addq foo@gottpoff(%rip), %reg
5290 leaq foo(%reg), %reg
5292 For 32bit, originally it can be one of:
5293 movq foo@gottpoff(%rip), %reg
5294 addl foo@gottpoff(%rip), %reg
5297 leal foo(%reg), %reg
5300 unsigned int val
, type
, reg
;
5303 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5306 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5307 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5313 bfd_put_8 (output_bfd
, 0x49,
5314 contents
+ roff
- 3);
5315 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5316 bfd_put_8 (output_bfd
, 0x41,
5317 contents
+ roff
- 3);
5318 bfd_put_8 (output_bfd
, 0xc7,
5319 contents
+ roff
- 2);
5320 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5321 contents
+ roff
- 1);
5325 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5328 bfd_put_8 (output_bfd
, 0x49,
5329 contents
+ roff
- 3);
5330 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5331 bfd_put_8 (output_bfd
, 0x41,
5332 contents
+ roff
- 3);
5333 bfd_put_8 (output_bfd
, 0x81,
5334 contents
+ roff
- 2);
5335 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5336 contents
+ roff
- 1);
5340 /* addq/addl -> leaq/leal */
5342 bfd_put_8 (output_bfd
, 0x4d,
5343 contents
+ roff
- 3);
5344 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5345 bfd_put_8 (output_bfd
, 0x45,
5346 contents
+ roff
- 3);
5347 bfd_put_8 (output_bfd
, 0x8d,
5348 contents
+ roff
- 2);
5349 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5350 contents
+ roff
- 1);
5352 bfd_put_32 (output_bfd
,
5353 elf_x86_64_tpoff (info
, relocation
),
5361 if (htab
->elf
.sgot
== NULL
)
5366 off
= h
->got
.offset
;
5367 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5371 if (local_got_offsets
== NULL
)
5374 off
= local_got_offsets
[r_symndx
];
5375 offplt
= local_tlsdesc_gotents
[r_symndx
];
5382 Elf_Internal_Rela outrel
;
5386 if (htab
->elf
.srelgot
== NULL
)
5389 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5391 if (GOT_TLS_GDESC_P (tls_type
))
5393 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5394 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5395 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5396 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5397 + htab
->elf
.sgotplt
->output_offset
5399 + htab
->sgotplt_jump_table_size
);
5400 sreloc
= htab
->elf
.srelplt
;
5402 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5404 outrel
.r_addend
= 0;
5405 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5408 sreloc
= htab
->elf
.srelgot
;
5410 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5411 + htab
->elf
.sgot
->output_offset
+ off
);
5413 if (GOT_TLS_GD_P (tls_type
))
5414 dr_type
= R_X86_64_DTPMOD64
;
5415 else if (GOT_TLS_GDESC_P (tls_type
))
5418 dr_type
= R_X86_64_TPOFF64
;
5420 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5421 outrel
.r_addend
= 0;
5422 if ((dr_type
== R_X86_64_TPOFF64
5423 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5424 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5425 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5427 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5429 if (GOT_TLS_GD_P (tls_type
))
5433 BFD_ASSERT (! unresolved_reloc
);
5434 bfd_put_64 (output_bfd
,
5435 relocation
- elf_x86_64_dtpoff_base (info
),
5436 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5440 bfd_put_64 (output_bfd
, 0,
5441 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5442 outrel
.r_info
= htab
->r_info (indx
,
5444 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5445 elf_append_rela (output_bfd
, sreloc
,
5454 local_got_offsets
[r_symndx
] |= 1;
5457 if (off
>= (bfd_vma
) -2
5458 && ! GOT_TLS_GDESC_P (tls_type
))
5460 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5462 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5463 || r_type
== R_X86_64_TLSDESC_CALL
)
5464 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5465 + htab
->elf
.sgotplt
->output_offset
5466 + offplt
+ htab
->sgotplt_jump_table_size
;
5468 relocation
= htab
->elf
.sgot
->output_section
->vma
5469 + htab
->elf
.sgot
->output_offset
+ off
;
5470 unresolved_reloc
= FALSE
;
5474 bfd_vma roff
= rel
->r_offset
;
5476 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5478 /* GD->IE transition. For 64bit, change
5479 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5480 .word 0x6666; rex64; call __tls_get_addr@PLT
5482 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5484 call *__tls_get_addr@GOTPCREL(%rip
5485 which may be converted to
5486 addr32 call __tls_get_addr
5489 addq foo@gottpoff(%rip), %rax
5491 leaq foo@tlsgd(%rip), %rdi
5492 .word 0x6666; rex64; call __tls_get_addr@PLT
5494 leaq foo@tlsgd(%rip), %rdi
5496 call *__tls_get_addr@GOTPCREL(%rip)
5497 which may be converted to
5498 addr32 call __tls_get_addr
5501 addq foo@gottpoff(%rip), %rax
5502 For largepic, change:
5503 leaq foo@tlsgd(%rip), %rdi
5504 movabsq $__tls_get_addr@pltoff, %rax
5509 addq foo@gottpoff(%rax), %rax
5510 nopw 0x0(%rax,%rax,1) */
5512 if (ABI_64_P (output_bfd
))
5514 if (contents
[roff
+ 5] == 0xb8)
5516 memcpy (contents
+ roff
- 3,
5517 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5518 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5522 memcpy (contents
+ roff
- 4,
5523 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5527 memcpy (contents
+ roff
- 3,
5528 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5531 relocation
= (htab
->elf
.sgot
->output_section
->vma
5532 + htab
->elf
.sgot
->output_offset
+ off
5535 - input_section
->output_section
->vma
5536 - input_section
->output_offset
5538 bfd_put_32 (output_bfd
, relocation
,
5539 contents
+ roff
+ 8 + largepic
);
5540 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5545 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5547 /* GDesc -> IE transition.
5548 It's originally something like:
5549 leaq x@tlsdesc(%rip), %rax
5552 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5554 /* Now modify the instruction as appropriate. To
5555 turn a leaq into a movq in the form we use it, it
5556 suffices to change the second byte from 0x8d to
5558 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5560 bfd_put_32 (output_bfd
,
5561 htab
->elf
.sgot
->output_section
->vma
5562 + htab
->elf
.sgot
->output_offset
+ off
5564 - input_section
->output_section
->vma
5565 - input_section
->output_offset
5570 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5572 /* GDesc -> IE transition.
5579 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5580 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5588 case R_X86_64_TLSLD
:
5589 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5590 input_section
, contents
,
5591 symtab_hdr
, sym_hashes
,
5592 &r_type
, GOT_UNKNOWN
, rel
,
5593 relend
, h
, r_symndx
, TRUE
))
5596 if (r_type
!= R_X86_64_TLSLD
)
5598 /* LD->LE transition:
5599 leaq foo@tlsld(%rip), %rdi
5600 call __tls_get_addr@PLT
5601 For 64bit, we change it into:
5602 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5603 For 32bit, we change it into:
5604 nopl 0x0(%rax); movl %fs:0, %eax
5606 leaq foo@tlsld(%rip), %rdi;
5607 call *__tls_get_addr@GOTPCREL(%rip)
5608 which may be converted to
5609 addr32 call __tls_get_addr
5610 For 64bit, we change it into:
5611 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5612 For 32bit, we change it into:
5613 nopw 0x0(%rax); movl %fs:0, %eax
5614 For largepic, change:
5615 leaq foo@tlsgd(%rip), %rdi
5616 movabsq $__tls_get_addr@pltoff, %rax
5620 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5623 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5624 if (ABI_64_P (output_bfd
))
5626 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5627 memcpy (contents
+ rel
->r_offset
- 3,
5628 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5629 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5630 else if (contents
[rel
->r_offset
+ 4] == 0xff
5631 || contents
[rel
->r_offset
+ 4] == 0x67)
5632 memcpy (contents
+ rel
->r_offset
- 3,
5633 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5636 memcpy (contents
+ rel
->r_offset
- 3,
5637 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5641 if (contents
[rel
->r_offset
+ 4] == 0xff)
5642 memcpy (contents
+ rel
->r_offset
- 3,
5643 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5646 memcpy (contents
+ rel
->r_offset
- 3,
5647 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5649 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5650 and R_X86_64_PLTOFF64. */
5656 if (htab
->elf
.sgot
== NULL
)
5659 off
= htab
->tls_ld_got
.offset
;
5664 Elf_Internal_Rela outrel
;
5666 if (htab
->elf
.srelgot
== NULL
)
5669 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5670 + htab
->elf
.sgot
->output_offset
+ off
);
5672 bfd_put_64 (output_bfd
, 0,
5673 htab
->elf
.sgot
->contents
+ off
);
5674 bfd_put_64 (output_bfd
, 0,
5675 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5676 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5677 outrel
.r_addend
= 0;
5678 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5680 htab
->tls_ld_got
.offset
|= 1;
5682 relocation
= htab
->elf
.sgot
->output_section
->vma
5683 + htab
->elf
.sgot
->output_offset
+ off
;
5684 unresolved_reloc
= FALSE
;
5687 case R_X86_64_DTPOFF32
:
5688 if (!bfd_link_executable (info
)
5689 || (input_section
->flags
& SEC_CODE
) == 0)
5690 relocation
-= elf_x86_64_dtpoff_base (info
);
5692 relocation
= elf_x86_64_tpoff (info
, relocation
);
5695 case R_X86_64_TPOFF32
:
5696 case R_X86_64_TPOFF64
:
5697 BFD_ASSERT (bfd_link_executable (info
));
5698 relocation
= elf_x86_64_tpoff (info
, relocation
);
5701 case R_X86_64_DTPOFF64
:
5702 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5703 relocation
-= elf_x86_64_dtpoff_base (info
);
5710 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5711 because such sections are not SEC_ALLOC and thus ld.so will
5712 not process them. */
5713 if (unresolved_reloc
5714 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5716 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5717 rel
->r_offset
) != (bfd_vma
) -1)
5720 /* xgettext:c-format */
5721 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5724 (long) rel
->r_offset
,
5726 h
->root
.root
.string
);
5731 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5732 contents
, rel
->r_offset
,
5733 relocation
, rel
->r_addend
);
5735 check_relocation_error
:
5736 if (r
!= bfd_reloc_ok
)
5741 name
= h
->root
.root
.string
;
5744 name
= bfd_elf_string_from_elf_section (input_bfd
,
5745 symtab_hdr
->sh_link
,
5750 name
= bfd_section_name (input_bfd
, sec
);
5753 if (r
== bfd_reloc_overflow
)
5754 (*info
->callbacks
->reloc_overflow
)
5755 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5756 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5760 /* xgettext:c-format */
5761 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5762 input_bfd
, input_section
,
5763 (long) rel
->r_offset
, name
, (int) r
);
5774 Elf_Internal_Shdr
*rel_hdr
;
5775 size_t deleted
= rel
- wrel
;
5777 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5778 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5779 if (rel_hdr
->sh_size
== 0)
5781 /* It is too late to remove an empty reloc section. Leave
5783 ??? What is wrong with an empty section??? */
5784 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5787 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5788 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5789 input_section
->reloc_count
-= deleted
;
5795 /* Finish up dynamic symbol handling. We set the contents of various
5796 dynamic sections here. */
5799 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5800 struct bfd_link_info
*info
,
5801 struct elf_link_hash_entry
*h
,
5802 Elf_Internal_Sym
*sym
)
5804 struct elf_x86_64_link_hash_table
*htab
;
5805 const struct elf_x86_64_backend_data
*abed
;
5806 bfd_boolean use_plt_bnd
;
5807 struct elf_x86_64_link_hash_entry
*eh
;
5808 bfd_boolean local_undefweak
;
5810 htab
= elf_x86_64_hash_table (info
);
5814 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5815 section only if there is .plt section. */
5816 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5818 ? &elf_x86_64_bnd_arch_bed
5819 : get_elf_x86_64_backend_data (output_bfd
));
5821 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5822 if (eh
->no_finish_dynamic_symbol
)
5825 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5826 resolved undefined weak symbols in executable so that their
5827 references have value 0 at run-time. */
5828 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5832 if (h
->plt
.offset
!= (bfd_vma
) -1)
5835 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
5836 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
5837 Elf_Internal_Rela rela
;
5839 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5840 const struct elf_backend_data
*bed
;
5841 bfd_vma plt_got_pcrel_offset
;
5843 /* When building a static executable, use .iplt, .igot.plt and
5844 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5845 if (htab
->elf
.splt
!= NULL
)
5847 plt
= htab
->elf
.splt
;
5848 gotplt
= htab
->elf
.sgotplt
;
5849 relplt
= htab
->elf
.srelplt
;
5853 plt
= htab
->elf
.iplt
;
5854 gotplt
= htab
->elf
.igotplt
;
5855 relplt
= htab
->elf
.irelplt
;
5858 /* This symbol has an entry in the procedure linkage table. Set
5860 if ((h
->dynindx
== -1
5862 && !((h
->forced_local
|| bfd_link_executable (info
))
5864 && h
->type
== STT_GNU_IFUNC
))
5870 /* Get the index in the procedure linkage table which
5871 corresponds to this symbol. This is the index of this symbol
5872 in all the symbols for which we are making plt entries. The
5873 first entry in the procedure linkage table is reserved.
5875 Get the offset into the .got table of the entry that
5876 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5877 bytes. The first three are reserved for the dynamic linker.
5879 For static executables, we don't reserve anything. */
5881 if (plt
== htab
->elf
.splt
)
5883 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
5884 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5888 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
5889 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5892 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
5893 plt_plt_offset
= abed
->plt_plt_offset
;
5894 plt_got_insn_size
= abed
->plt_got_insn_size
;
5895 plt_got_offset
= abed
->plt_got_offset
;
5898 /* Use the second PLT with BND relocations. */
5899 const bfd_byte
*plt_entry
, *plt2_entry
;
5901 if (eh
->has_bnd_reloc
)
5903 plt_entry
= elf_x86_64_bnd_plt_entry
;
5904 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
5908 plt_entry
= elf_x86_64_legacy_plt_entry
;
5909 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
5911 /* Subtract 1 since there is no BND prefix. */
5912 plt_plt_insn_end
-= 1;
5913 plt_plt_offset
-= 1;
5914 plt_got_insn_size
-= 1;
5915 plt_got_offset
-= 1;
5918 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
5919 == sizeof (elf_x86_64_legacy_plt_entry
));
5921 /* Fill in the entry in the procedure linkage table. */
5922 memcpy (plt
->contents
+ h
->plt
.offset
,
5923 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
5924 /* Fill in the entry in the second PLT. */
5925 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5926 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5928 resolved_plt
= htab
->plt_bnd
;
5929 plt_offset
= eh
->plt_bnd
.offset
;
5933 /* Fill in the entry in the procedure linkage table. */
5934 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
5935 abed
->plt_entry_size
);
5938 plt_offset
= h
->plt
.offset
;
5941 /* Insert the relocation positions of the plt section. */
5943 /* Put offset the PC-relative instruction referring to the GOT entry,
5944 subtracting the size of that instruction. */
5945 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5946 + gotplt
->output_offset
5948 - resolved_plt
->output_section
->vma
5949 - resolved_plt
->output_offset
5951 - plt_got_insn_size
);
5953 /* Check PC-relative offset overflow in PLT entry. */
5954 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5955 /* xgettext:c-format */
5956 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5957 output_bfd
, h
->root
.root
.string
);
5959 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5960 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
5962 /* Fill in the entry in the global offset table, initially this
5963 points to the second part of the PLT entry. Leave the entry
5964 as zero for undefined weak symbol in PIE. No PLT relocation
5965 against undefined weak symbol in PIE. */
5966 if (!local_undefweak
)
5968 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5969 + plt
->output_offset
5971 + abed
->plt_lazy_offset
),
5972 gotplt
->contents
+ got_offset
);
5974 /* Fill in the entry in the .rela.plt section. */
5975 rela
.r_offset
= (gotplt
->output_section
->vma
5976 + gotplt
->output_offset
5978 if (h
->dynindx
== -1
5979 || ((bfd_link_executable (info
)
5980 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5982 && h
->type
== STT_GNU_IFUNC
))
5984 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5985 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5986 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5987 rela
.r_addend
= (h
->root
.u
.def
.value
5988 + h
->root
.u
.def
.section
->output_section
->vma
5989 + h
->root
.u
.def
.section
->output_offset
);
5990 /* R_X86_64_IRELATIVE comes last. */
5991 plt_index
= htab
->next_irelative_index
--;
5995 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5997 plt_index
= htab
->next_jump_slot_index
++;
6000 /* Don't fill PLT entry for static executables. */
6001 if (plt
== htab
->elf
.splt
)
6003 bfd_vma plt0_offset
= h
->plt
.offset
+ plt_plt_insn_end
;
6005 /* Put relocation index. */
6006 bfd_put_32 (output_bfd
, plt_index
,
6007 (plt
->contents
+ h
->plt
.offset
6008 + abed
->plt_reloc_offset
));
6010 /* Put offset for jmp .PLT0 and check for overflow. We don't
6011 check relocation index for overflow since branch displacement
6012 will overflow first. */
6013 if (plt0_offset
> 0x80000000)
6014 /* xgettext:c-format */
6015 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
6016 output_bfd
, h
->root
.root
.string
);
6017 bfd_put_32 (output_bfd
, - plt0_offset
,
6018 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
6021 bed
= get_elf_backend_data (output_bfd
);
6022 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
6023 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
6026 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
6028 bfd_vma got_offset
, plt_offset
, plt_got_offset
, plt_got_insn_size
;
6029 asection
*plt
, *got
;
6030 bfd_boolean got_after_plt
;
6031 int32_t got_pcrel_offset
;
6032 const bfd_byte
*got_plt_entry
;
6034 /* Set the entry in the GOT procedure linkage table. */
6035 plt
= htab
->plt_got
;
6036 got
= htab
->elf
.sgot
;
6037 got_offset
= h
->got
.offset
;
6039 if (got_offset
== (bfd_vma
) -1
6040 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
6045 /* Use the second PLT entry template for the GOT PLT since they
6046 are the identical. */
6047 plt_got_insn_size
= elf_x86_64_bnd_arch_bed
.plt_got_insn_size
;
6048 plt_got_offset
= elf_x86_64_bnd_arch_bed
.plt_got_offset
;
6049 if (eh
->has_bnd_reloc
)
6050 got_plt_entry
= elf_x86_64_bnd_plt2_entry
;
6053 got_plt_entry
= elf_x86_64_legacy_plt2_entry
;
6055 /* Subtract 1 since there is no BND prefix. */
6056 plt_got_insn_size
-= 1;
6057 plt_got_offset
-= 1;
6060 /* Fill in the entry in the GOT procedure linkage table. */
6061 plt_offset
= eh
->plt_got
.offset
;
6062 memcpy (plt
->contents
+ plt_offset
,
6063 got_plt_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
6065 /* Put offset the PC-relative instruction referring to the GOT
6066 entry, subtracting the size of that instruction. */
6067 got_pcrel_offset
= (got
->output_section
->vma
6068 + got
->output_offset
6070 - plt
->output_section
->vma
6071 - plt
->output_offset
6073 - plt_got_insn_size
);
6075 /* Check PC-relative offset overflow in GOT PLT entry. */
6076 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
6077 if ((got_after_plt
&& got_pcrel_offset
< 0)
6078 || (!got_after_plt
&& got_pcrel_offset
> 0))
6079 /* xgettext:c-format */
6080 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
6081 output_bfd
, h
->root
.root
.string
);
6083 bfd_put_32 (output_bfd
, got_pcrel_offset
,
6084 plt
->contents
+ plt_offset
+ plt_got_offset
);
6087 if (!local_undefweak
6089 && (h
->plt
.offset
!= (bfd_vma
) -1
6090 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
6092 /* Mark the symbol as undefined, rather than as defined in
6093 the .plt section. Leave the value if there were any
6094 relocations where pointer equality matters (this is a clue
6095 for the dynamic linker, to make function pointer
6096 comparisons work between an application and shared
6097 library), otherwise set it to zero. If a function is only
6098 called from a binary, there is no need to slow down
6099 shared libraries because of that. */
6100 sym
->st_shndx
= SHN_UNDEF
;
6101 if (!h
->pointer_equality_needed
)
6105 /* Don't generate dynamic GOT relocation against undefined weak
6106 symbol in executable. */
6107 if (h
->got
.offset
!= (bfd_vma
) -1
6108 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
6109 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
6110 && !local_undefweak
)
6112 Elf_Internal_Rela rela
;
6113 asection
*relgot
= htab
->elf
.srelgot
;
6115 /* This symbol has an entry in the global offset table. Set it
6117 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
6120 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
6121 + htab
->elf
.sgot
->output_offset
6122 + (h
->got
.offset
&~ (bfd_vma
) 1));
6124 /* If this is a static link, or it is a -Bsymbolic link and the
6125 symbol is defined locally or was forced to be local because
6126 of a version file, we just want to emit a RELATIVE reloc.
6127 The entry in the global offset table will already have been
6128 initialized in the relocate_section function. */
6130 && h
->type
== STT_GNU_IFUNC
)
6132 if (h
->plt
.offset
== (bfd_vma
) -1)
6134 /* STT_GNU_IFUNC is referenced without PLT. */
6135 if (htab
->elf
.splt
== NULL
)
6137 /* use .rel[a].iplt section to store .got relocations
6138 in static executable. */
6139 relgot
= htab
->elf
.irelplt
;
6141 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
6143 rela
.r_info
= htab
->r_info (0,
6144 R_X86_64_IRELATIVE
);
6145 rela
.r_addend
= (h
->root
.u
.def
.value
6146 + h
->root
.u
.def
.section
->output_section
->vma
6147 + h
->root
.u
.def
.section
->output_offset
);
6152 else if (bfd_link_pic (info
))
6154 /* Generate R_X86_64_GLOB_DAT. */
6161 if (!h
->pointer_equality_needed
)
6164 /* For non-shared object, we can't use .got.plt, which
6165 contains the real function addres if we need pointer
6166 equality. We load the GOT entry with the PLT entry. */
6167 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6168 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6169 + plt
->output_offset
6171 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6175 else if (bfd_link_pic (info
)
6176 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6178 if (!h
->def_regular
)
6180 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6181 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6182 rela
.r_addend
= (h
->root
.u
.def
.value
6183 + h
->root
.u
.def
.section
->output_section
->vma
6184 + h
->root
.u
.def
.section
->output_offset
);
6188 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6190 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6191 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6192 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6196 elf_append_rela (output_bfd
, relgot
, &rela
);
6201 Elf_Internal_Rela rela
;
6204 /* This symbol needs a copy reloc. Set it up. */
6206 if (h
->dynindx
== -1
6207 || (h
->root
.type
!= bfd_link_hash_defined
6208 && h
->root
.type
!= bfd_link_hash_defweak
)
6209 || htab
->elf
.srelbss
== NULL
6210 || htab
->elf
.sreldynrelro
== NULL
)
6213 rela
.r_offset
= (h
->root
.u
.def
.value
6214 + h
->root
.u
.def
.section
->output_section
->vma
6215 + h
->root
.u
.def
.section
->output_offset
);
6216 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6218 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6219 s
= htab
->elf
.sreldynrelro
;
6221 s
= htab
->elf
.srelbss
;
6222 elf_append_rela (output_bfd
, s
, &rela
);
6228 /* Finish up local dynamic symbol handling. We set the contents of
6229 various dynamic sections here. */
6232 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6234 struct elf_link_hash_entry
*h
6235 = (struct elf_link_hash_entry
*) *slot
;
6236 struct bfd_link_info
*info
6237 = (struct bfd_link_info
*) inf
;
6239 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6243 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6244 here since undefined weak symbol may not be dynamic and may not be
6245 called for elf_x86_64_finish_dynamic_symbol. */
6248 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6251 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6252 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6254 if (h
->root
.type
!= bfd_link_hash_undefweak
6255 || h
->dynindx
!= -1)
6258 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6262 /* Used to decide how to sort relocs in an optimal manner for the
6263 dynamic linker, before writing them out. */
6265 static enum elf_reloc_type_class
6266 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6267 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6268 const Elf_Internal_Rela
*rela
)
6270 bfd
*abfd
= info
->output_bfd
;
6271 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6272 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6274 if (htab
->elf
.dynsym
!= NULL
6275 && htab
->elf
.dynsym
->contents
!= NULL
)
6277 /* Check relocation against STT_GNU_IFUNC symbol if there are
6279 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6280 if (r_symndx
!= STN_UNDEF
)
6282 Elf_Internal_Sym sym
;
6283 if (!bed
->s
->swap_symbol_in (abfd
,
6284 (htab
->elf
.dynsym
->contents
6285 + r_symndx
* bed
->s
->sizeof_sym
),
6289 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6290 return reloc_class_ifunc
;
6294 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6296 case R_X86_64_IRELATIVE
:
6297 return reloc_class_ifunc
;
6298 case R_X86_64_RELATIVE
:
6299 case R_X86_64_RELATIVE64
:
6300 return reloc_class_relative
;
6301 case R_X86_64_JUMP_SLOT
:
6302 return reloc_class_plt
;
6304 return reloc_class_copy
;
6306 return reloc_class_normal
;
6310 /* Finish up the dynamic sections. */
6313 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6314 struct bfd_link_info
*info
)
6316 struct elf_x86_64_link_hash_table
*htab
;
6319 const struct elf_x86_64_backend_data
*abed
;
6321 htab
= elf_x86_64_hash_table (info
);
6325 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6326 section only if there is .plt section. */
6327 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
6328 ? &elf_x86_64_bnd_arch_bed
6329 : get_elf_x86_64_backend_data (output_bfd
));
6331 dynobj
= htab
->elf
.dynobj
;
6332 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6334 if (htab
->elf
.dynamic_sections_created
)
6336 bfd_byte
*dyncon
, *dynconend
;
6337 const struct elf_backend_data
*bed
;
6338 bfd_size_type sizeof_dyn
;
6340 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6343 bed
= get_elf_backend_data (dynobj
);
6344 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6345 dyncon
= sdyn
->contents
;
6346 dynconend
= sdyn
->contents
+ sdyn
->size
;
6347 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6349 Elf_Internal_Dyn dyn
;
6352 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6360 s
= htab
->elf
.sgotplt
;
6361 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6365 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6369 s
= htab
->elf
.srelplt
->output_section
;
6370 dyn
.d_un
.d_val
= s
->size
;
6373 case DT_TLSDESC_PLT
:
6375 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6376 + htab
->tlsdesc_plt
;
6379 case DT_TLSDESC_GOT
:
6381 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6382 + htab
->tlsdesc_got
;
6386 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6389 /* Fill in the special first entry in the procedure linkage table. */
6390 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6392 /* Fill in the first entry in the procedure linkage table. */
6393 memcpy (htab
->elf
.splt
->contents
,
6394 abed
->plt0_entry
, abed
->plt_entry_size
);
6395 /* Add offset for pushq GOT+8(%rip), since the instruction
6396 uses 6 bytes subtract this value. */
6397 bfd_put_32 (output_bfd
,
6398 (htab
->elf
.sgotplt
->output_section
->vma
6399 + htab
->elf
.sgotplt
->output_offset
6401 - htab
->elf
.splt
->output_section
->vma
6402 - htab
->elf
.splt
->output_offset
6404 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
6405 /* Add offset for the PC-relative instruction accessing GOT+16,
6406 subtracting the offset to the end of that instruction. */
6407 bfd_put_32 (output_bfd
,
6408 (htab
->elf
.sgotplt
->output_section
->vma
6409 + htab
->elf
.sgotplt
->output_offset
6411 - htab
->elf
.splt
->output_section
->vma
6412 - htab
->elf
.splt
->output_offset
6413 - abed
->plt0_got2_insn_end
),
6414 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
6416 elf_section_data (htab
->elf
.splt
->output_section
)
6417 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
6419 if (htab
->tlsdesc_plt
)
6421 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6422 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6424 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6425 abed
->plt0_entry
, abed
->plt_entry_size
);
6427 /* Add offset for pushq GOT+8(%rip), since the
6428 instruction uses 6 bytes subtract this value. */
6429 bfd_put_32 (output_bfd
,
6430 (htab
->elf
.sgotplt
->output_section
->vma
6431 + htab
->elf
.sgotplt
->output_offset
6433 - htab
->elf
.splt
->output_section
->vma
6434 - htab
->elf
.splt
->output_offset
6437 htab
->elf
.splt
->contents
6438 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
6439 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6440 where TGD stands for htab->tlsdesc_got, subtracting the offset
6441 to the end of that instruction. */
6442 bfd_put_32 (output_bfd
,
6443 (htab
->elf
.sgot
->output_section
->vma
6444 + htab
->elf
.sgot
->output_offset
6446 - htab
->elf
.splt
->output_section
->vma
6447 - htab
->elf
.splt
->output_offset
6449 - abed
->plt0_got2_insn_end
),
6450 htab
->elf
.splt
->contents
6451 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
6456 if (htab
->plt_bnd
!= NULL
)
6457 elf_section_data (htab
->plt_bnd
->output_section
)
6458 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
6460 if (htab
->elf
.sgotplt
)
6462 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6465 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6469 /* Fill in the first three entries in the global offset table. */
6470 if (htab
->elf
.sgotplt
->size
> 0)
6472 /* Set the first entry in the global offset table to the address of
6473 the dynamic section. */
6475 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6477 bfd_put_64 (output_bfd
,
6478 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6479 htab
->elf
.sgotplt
->contents
);
6480 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6481 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6482 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6485 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
6489 /* Adjust .eh_frame for .plt section. */
6490 if (htab
->plt_eh_frame
!= NULL
6491 && htab
->plt_eh_frame
->contents
!= NULL
)
6493 if (htab
->elf
.splt
!= NULL
6494 && htab
->elf
.splt
->size
!= 0
6495 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6496 && htab
->elf
.splt
->output_section
!= NULL
6497 && htab
->plt_eh_frame
->output_section
!= NULL
)
6499 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6500 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6501 + htab
->plt_eh_frame
->output_offset
6502 + PLT_FDE_START_OFFSET
;
6503 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6504 htab
->plt_eh_frame
->contents
6505 + PLT_FDE_START_OFFSET
);
6507 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6509 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6511 htab
->plt_eh_frame
->contents
))
6516 /* Adjust .eh_frame for .plt.got section. */
6517 if (htab
->plt_got_eh_frame
!= NULL
6518 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6520 if (htab
->plt_got
!= NULL
6521 && htab
->plt_got
->size
!= 0
6522 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6523 && htab
->plt_got
->output_section
!= NULL
6524 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6526 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6527 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6528 + htab
->plt_got_eh_frame
->output_offset
6529 + PLT_FDE_START_OFFSET
;
6530 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6531 htab
->plt_got_eh_frame
->contents
6532 + PLT_FDE_START_OFFSET
);
6534 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6536 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6537 htab
->plt_got_eh_frame
,
6538 htab
->plt_got_eh_frame
->contents
))
6543 /* Adjust .eh_frame for .plt.bnd section. */
6544 if (htab
->plt_bnd_eh_frame
!= NULL
6545 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
6547 if (htab
->plt_bnd
!= NULL
6548 && htab
->plt_bnd
->size
!= 0
6549 && (htab
->plt_bnd
->flags
& SEC_EXCLUDE
) == 0
6550 && htab
->plt_bnd
->output_section
!= NULL
6551 && htab
->plt_bnd_eh_frame
->output_section
!= NULL
)
6553 bfd_vma plt_start
= htab
->plt_bnd
->output_section
->vma
;
6554 bfd_vma eh_frame_start
= htab
->plt_bnd_eh_frame
->output_section
->vma
6555 + htab
->plt_bnd_eh_frame
->output_offset
6556 + PLT_FDE_START_OFFSET
;
6557 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6558 htab
->plt_bnd_eh_frame
->contents
6559 + PLT_FDE_START_OFFSET
);
6561 if (htab
->plt_bnd_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6563 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6564 htab
->plt_bnd_eh_frame
,
6565 htab
->plt_bnd_eh_frame
->contents
))
6570 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6571 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6574 /* Fill PLT entries for undefined weak symbols in PIE. */
6575 if (bfd_link_pie (info
))
6576 bfd_hash_traverse (&info
->hash
->table
,
6577 elf_x86_64_pie_finish_undefweak_symbol
,
6583 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6584 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6585 It has to be done before elf_link_sort_relocs is called so that
6586 dynamic relocations are properly sorted. */
6589 elf_x86_64_output_arch_local_syms
6590 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6591 struct bfd_link_info
*info
,
6592 void *flaginfo ATTRIBUTE_UNUSED
,
6593 int (*func
) (void *, const char *,
6596 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6598 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6602 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6603 htab_traverse (htab
->loc_hash_table
,
6604 elf_x86_64_finish_local_dynamic_symbol
,
6610 /* Return an array of PLT entry symbol values. */
6613 elf_x86_64_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6616 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6619 bfd_vma
*plt_sym_val
;
6621 bfd_byte
*plt_contents
;
6622 const struct elf_x86_64_backend_data
*bed
;
6623 Elf_Internal_Shdr
*hdr
;
6626 /* Get the .plt section contents. PLT passed down may point to the
6627 .plt.bnd section. Make sure that PLT always points to the .plt
6629 plt_bnd
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6634 plt
= bfd_get_section_by_name (abfd
, ".plt");
6637 bed
= &elf_x86_64_bnd_arch_bed
;
6640 bed
= get_elf_x86_64_backend_data (abfd
);
6642 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6643 if (plt_contents
== NULL
)
6645 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6646 plt_contents
, 0, plt
->size
))
6649 free (plt_contents
);
6653 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6654 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6657 hdr
= &elf_section_data (relplt
)->this_hdr
;
6658 count
= relplt
->size
/ hdr
->sh_entsize
;
6660 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6661 if (plt_sym_val
== NULL
)
6664 for (i
= 0; i
< count
; i
++)
6665 plt_sym_val
[i
] = -1;
6667 plt_offset
= bed
->plt_entry_size
;
6668 p
= relplt
->relocation
;
6669 for (i
= 0; i
< count
; i
++, p
++)
6673 /* Skip unknown relocation. */
6674 if (p
->howto
== NULL
)
6677 if (p
->howto
->type
!= R_X86_64_JUMP_SLOT
6678 && p
->howto
->type
!= R_X86_64_IRELATIVE
)
6681 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6682 + bed
->plt_reloc_offset
));
6683 if (reloc_index
< count
)
6687 /* This is the index in .plt section. */
6688 long plt_index
= plt_offset
/ bed
->plt_entry_size
;
6689 /* Store VMA + the offset in .plt.bnd section. */
6690 plt_sym_val
[reloc_index
] =
6692 + (plt_index
- 1) * sizeof (elf_x86_64_legacy_plt2_entry
));
6695 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6697 plt_offset
+= bed
->plt_entry_size
;
6699 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6701 if (plt_offset
>= plt
->size
)
6705 free (plt_contents
);
6710 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6714 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6721 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6722 as PLT if it exists. */
6723 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6725 plt
= bfd_get_section_by_name (abfd
, ".plt");
6726 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6727 dynsymcount
, dynsyms
, ret
,
6729 elf_x86_64_get_plt_sym_val
);
6732 /* Handle an x86-64 specific section when reading an object file. This
6733 is called when elfcode.h finds a section with an unknown type. */
6736 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6737 const char *name
, int shindex
)
6739 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6742 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6748 /* Hook called by the linker routine which adds symbols from an object
6749 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6753 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6754 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6755 Elf_Internal_Sym
*sym
,
6756 const char **namep ATTRIBUTE_UNUSED
,
6757 flagword
*flagsp ATTRIBUTE_UNUSED
,
6763 switch (sym
->st_shndx
)
6765 case SHN_X86_64_LCOMMON
:
6766 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6769 lcomm
= bfd_make_section_with_flags (abfd
,
6773 | SEC_LINKER_CREATED
));
6776 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6779 *valp
= sym
->st_size
;
6787 /* Given a BFD section, try to locate the corresponding ELF section
6791 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6792 asection
*sec
, int *index_return
)
6794 if (sec
== &_bfd_elf_large_com_section
)
6796 *index_return
= SHN_X86_64_LCOMMON
;
6802 /* Process a symbol. */
6805 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6808 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6810 switch (elfsym
->internal_elf_sym
.st_shndx
)
6812 case SHN_X86_64_LCOMMON
:
6813 asym
->section
= &_bfd_elf_large_com_section
;
6814 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6815 /* Common symbol doesn't set BSF_GLOBAL. */
6816 asym
->flags
&= ~BSF_GLOBAL
;
6822 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6824 return (sym
->st_shndx
== SHN_COMMON
6825 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6829 elf_x86_64_common_section_index (asection
*sec
)
6831 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6834 return SHN_X86_64_LCOMMON
;
6838 elf_x86_64_common_section (asection
*sec
)
6840 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6841 return bfd_com_section_ptr
;
6843 return &_bfd_elf_large_com_section
;
6847 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6848 const Elf_Internal_Sym
*sym
,
6853 const asection
*oldsec
)
6855 /* A normal common symbol and a large common symbol result in a
6856 normal common symbol. We turn the large common symbol into a
6859 && h
->root
.type
== bfd_link_hash_common
6861 && bfd_is_com_section (*psec
)
6864 if (sym
->st_shndx
== SHN_COMMON
6865 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6867 h
->root
.u
.c
.p
->section
6868 = bfd_make_section_old_way (oldbfd
, "COMMON");
6869 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6871 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6872 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6873 *psec
= bfd_com_section_ptr
;
6880 elf_x86_64_additional_program_headers (bfd
*abfd
,
6881 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6886 /* Check to see if we need a large readonly segment. */
6887 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6888 if (s
&& (s
->flags
& SEC_LOAD
))
6891 /* Check to see if we need a large data segment. Since .lbss sections
6892 is placed right after the .bss section, there should be no need for
6893 a large data segment just because of .lbss. */
6894 s
= bfd_get_section_by_name (abfd
, ".ldata");
6895 if (s
&& (s
->flags
& SEC_LOAD
))
6901 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6904 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6906 if (h
->plt
.offset
!= (bfd_vma
) -1
6908 && !h
->pointer_equality_needed
)
6911 return _bfd_elf_hash_symbol (h
);
6914 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6917 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6918 const bfd_target
*output
)
6920 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6921 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6922 && _bfd_elf_relocs_compatible (input
, output
));
6925 /* Parse x86-64 GNU properties. */
6927 static enum elf_property_kind
6928 elf_x86_64_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6929 bfd_byte
*ptr
, unsigned int datasz
)
6935 case GNU_PROPERTY_X86_ISA_1_USED
:
6936 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6940 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6941 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
6942 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>")),
6944 return property_corrupt
;
6946 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6947 prop
->u
.number
= bfd_h_get_32 (abfd
, ptr
);
6948 prop
->pr_kind
= property_number
;
6952 return property_ignored
;
6955 return property_number
;
6958 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
6959 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6960 should be merged with ABFD. */
6963 elf_x86_64_merge_gnu_properties (bfd
*abfd ATTRIBUTE_UNUSED
,
6964 elf_property
*aprop
,
6965 elf_property
*bprop
)
6967 unsigned int number
;
6968 bfd_boolean updated
= FALSE
;
6969 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6973 case GNU_PROPERTY_X86_ISA_1_USED
:
6974 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6975 if (aprop
!= NULL
&& bprop
!= NULL
)
6977 number
= aprop
->u
.number
;
6978 aprop
->u
.number
= number
| bprop
->u
.number
;
6979 updated
= number
!= (unsigned int) aprop
->u
.number
;
6983 /* Return TRUE if APROP is NULL to indicate that BPROP should
6984 be added to ABFD. */
6985 updated
= aprop
== NULL
;
6990 /* Never should happen. */
6997 static const struct bfd_elf_special_section
6998 elf_x86_64_special_sections
[]=
7000 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7001 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7002 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
7003 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7004 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7005 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7006 { NULL
, 0, 0, 0, 0 }
7009 #define TARGET_LITTLE_SYM x86_64_elf64_vec
7010 #define TARGET_LITTLE_NAME "elf64-x86-64"
7011 #define ELF_ARCH bfd_arch_i386
7012 #define ELF_TARGET_ID X86_64_ELF_DATA
7013 #define ELF_MACHINE_CODE EM_X86_64
7014 #define ELF_MAXPAGESIZE 0x200000
7015 #define ELF_MINPAGESIZE 0x1000
7016 #define ELF_COMMONPAGESIZE 0x1000
7018 #define elf_backend_can_gc_sections 1
7019 #define elf_backend_can_refcount 1
7020 #define elf_backend_want_got_plt 1
7021 #define elf_backend_plt_readonly 1
7022 #define elf_backend_want_plt_sym 0
7023 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
7024 #define elf_backend_rela_normal 1
7025 #define elf_backend_plt_alignment 4
7026 #define elf_backend_extern_protected_data 1
7027 #define elf_backend_caches_rawsize 1
7028 #define elf_backend_dtrel_excludes_plt 1
7029 #define elf_backend_want_dynrelro 1
7031 #define elf_info_to_howto elf_x86_64_info_to_howto
7033 #define bfd_elf64_bfd_link_hash_table_create \
7034 elf_x86_64_link_hash_table_create
7035 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7036 #define bfd_elf64_bfd_reloc_name_lookup \
7037 elf_x86_64_reloc_name_lookup
7039 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7040 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7041 #define elf_backend_check_relocs elf_x86_64_check_relocs
7042 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7043 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
7044 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7045 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7046 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7047 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7048 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7049 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7051 #define elf_backend_write_core_note elf_x86_64_write_core_note
7053 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7054 #define elf_backend_relocate_section elf_x86_64_relocate_section
7055 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7056 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7057 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7058 #define elf_backend_object_p elf64_x86_64_elf_object_p
7059 #define bfd_elf64_mkobject elf_x86_64_mkobject
7060 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7062 #define elf_backend_section_from_shdr \
7063 elf_x86_64_section_from_shdr
7065 #define elf_backend_section_from_bfd_section \
7066 elf_x86_64_elf_section_from_bfd_section
7067 #define elf_backend_add_symbol_hook \
7068 elf_x86_64_add_symbol_hook
7069 #define elf_backend_symbol_processing \
7070 elf_x86_64_symbol_processing
7071 #define elf_backend_common_section_index \
7072 elf_x86_64_common_section_index
7073 #define elf_backend_common_section \
7074 elf_x86_64_common_section
7075 #define elf_backend_common_definition \
7076 elf_x86_64_common_definition
7077 #define elf_backend_merge_symbol \
7078 elf_x86_64_merge_symbol
7079 #define elf_backend_special_sections \
7080 elf_x86_64_special_sections
7081 #define elf_backend_additional_program_headers \
7082 elf_x86_64_additional_program_headers
7083 #define elf_backend_hash_symbol \
7084 elf_x86_64_hash_symbol
7085 #define elf_backend_omit_section_dynsym \
7086 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7087 #define elf_backend_fixup_symbol \
7088 elf_x86_64_fixup_symbol
7089 #define elf_backend_parse_gnu_properties \
7090 elf_x86_64_parse_gnu_properties
7091 #define elf_backend_merge_gnu_properties \
7092 elf_x86_64_merge_gnu_properties
7094 #include "elf64-target.h"
7096 /* CloudABI support. */
7098 #undef TARGET_LITTLE_SYM
7099 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7100 #undef TARGET_LITTLE_NAME
7101 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7104 #define ELF_OSABI ELFOSABI_CLOUDABI
7107 #define elf64_bed elf64_x86_64_cloudabi_bed
7109 #include "elf64-target.h"
7111 /* FreeBSD support. */
7113 #undef TARGET_LITTLE_SYM
7114 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7115 #undef TARGET_LITTLE_NAME
7116 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7119 #define ELF_OSABI ELFOSABI_FREEBSD
7122 #define elf64_bed elf64_x86_64_fbsd_bed
7124 #include "elf64-target.h"
7126 /* Solaris 2 support. */
7128 #undef TARGET_LITTLE_SYM
7129 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7130 #undef TARGET_LITTLE_NAME
7131 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7133 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7134 objects won't be recognized. */
7138 #define elf64_bed elf64_x86_64_sol2_bed
7140 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7142 #undef elf_backend_static_tls_alignment
7143 #define elf_backend_static_tls_alignment 16
7145 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7147 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7149 #undef elf_backend_want_plt_sym
7150 #define elf_backend_want_plt_sym 1
7152 #undef elf_backend_strtab_flags
7153 #define elf_backend_strtab_flags SHF_STRINGS
7156 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7157 bfd
*obfd ATTRIBUTE_UNUSED
,
7158 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7159 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7161 /* PR 19938: FIXME: Need to add code for setting the sh_info
7162 and sh_link fields of Solaris specific section types. */
7166 #undef elf_backend_copy_special_section_fields
7167 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7169 #include "elf64-target.h"
7171 /* Native Client support. */
7174 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
7176 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7177 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
7181 #undef TARGET_LITTLE_SYM
7182 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7183 #undef TARGET_LITTLE_NAME
7184 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7186 #define elf64_bed elf64_x86_64_nacl_bed
7188 #undef ELF_MAXPAGESIZE
7189 #undef ELF_MINPAGESIZE
7190 #undef ELF_COMMONPAGESIZE
7191 #define ELF_MAXPAGESIZE 0x10000
7192 #define ELF_MINPAGESIZE 0x10000
7193 #define ELF_COMMONPAGESIZE 0x10000
7195 /* Restore defaults. */
7197 #undef elf_backend_static_tls_alignment
7198 #undef elf_backend_want_plt_sym
7199 #define elf_backend_want_plt_sym 0
7200 #undef elf_backend_strtab_flags
7201 #undef elf_backend_copy_special_section_fields
7203 /* NaCl uses substantially different PLT entries for the same effects. */
7205 #undef elf_backend_plt_alignment
7206 #define elf_backend_plt_alignment 5
7207 #define NACL_PLT_ENTRY_SIZE 64
7208 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7210 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
7212 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7213 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7214 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7215 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7216 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7218 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7219 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7221 /* 32 bytes of nop to pad out to the standard size. */
7222 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7223 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7224 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7225 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7226 0x66, /* excess data16 prefix */
7230 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7232 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7233 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7234 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7235 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7237 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7238 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7239 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7241 /* Lazy GOT entries point here (32-byte aligned). */
7242 0x68, /* pushq immediate */
7243 0, 0, 0, 0, /* replaced with index into relocation table. */
7244 0xe9, /* jmp relative */
7245 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7247 /* 22 bytes of nop to pad out to the standard size. */
7248 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7249 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7250 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7253 /* .eh_frame covering the .plt section. */
7255 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
7257 #if (PLT_CIE_LENGTH != 20 \
7258 || PLT_FDE_LENGTH != 36 \
7259 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7260 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7261 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7263 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7264 0, 0, 0, 0, /* CIE ID */
7265 1, /* CIE version */
7266 'z', 'R', 0, /* Augmentation string */
7267 1, /* Code alignment factor */
7268 0x78, /* Data alignment factor */
7269 16, /* Return address column */
7270 1, /* Augmentation size */
7271 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7272 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7273 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7274 DW_CFA_nop
, DW_CFA_nop
,
7276 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7277 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
7278 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7279 0, 0, 0, 0, /* .plt size goes here */
7280 0, /* Augmentation size */
7281 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
7282 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7283 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
7284 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7285 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7286 13, /* Block length */
7287 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7288 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7289 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7290 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7291 DW_CFA_nop
, DW_CFA_nop
7294 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7296 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7297 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7298 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7299 2, /* plt0_got1_offset */
7300 9, /* plt0_got2_offset */
7301 13, /* plt0_got2_insn_end */
7302 3, /* plt_got_offset */
7303 33, /* plt_reloc_offset */
7304 38, /* plt_plt_offset */
7305 7, /* plt_got_insn_size */
7306 42, /* plt_plt_insn_end */
7307 32, /* plt_lazy_offset */
7308 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7309 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
7310 NULL
, /* eh_frame_plt_got */
7311 0, /* eh_frame_plt_got_size */
7314 #undef elf_backend_arch_data
7315 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7317 #undef elf_backend_object_p
7318 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7319 #undef elf_backend_modify_segment_map
7320 #define elf_backend_modify_segment_map nacl_modify_segment_map
7321 #undef elf_backend_modify_program_headers
7322 #define elf_backend_modify_program_headers nacl_modify_program_headers
7323 #undef elf_backend_final_write_processing
7324 #define elf_backend_final_write_processing nacl_final_write_processing
7326 #include "elf64-target.h"
7328 /* Native Client x32 support. */
7331 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7333 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7334 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7338 #undef TARGET_LITTLE_SYM
7339 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7340 #undef TARGET_LITTLE_NAME
7341 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7343 #define elf32_bed elf32_x86_64_nacl_bed
7345 #define bfd_elf32_bfd_link_hash_table_create \
7346 elf_x86_64_link_hash_table_create
7347 #define bfd_elf32_bfd_reloc_type_lookup \
7348 elf_x86_64_reloc_type_lookup
7349 #define bfd_elf32_bfd_reloc_name_lookup \
7350 elf_x86_64_reloc_name_lookup
7351 #define bfd_elf32_mkobject \
7353 #define bfd_elf32_get_synthetic_symtab \
7354 elf_x86_64_get_synthetic_symtab
7356 #undef elf_backend_object_p
7357 #define elf_backend_object_p \
7358 elf32_x86_64_nacl_elf_object_p
7360 #undef elf_backend_bfd_from_remote_memory
7361 #define elf_backend_bfd_from_remote_memory \
7362 _bfd_elf32_bfd_from_remote_memory
7364 #undef elf_backend_size_info
7365 #define elf_backend_size_info \
7366 _bfd_elf32_size_info
7368 #include "elf32-target.h"
7370 /* Restore defaults. */
7371 #undef elf_backend_object_p
7372 #define elf_backend_object_p elf64_x86_64_elf_object_p
7373 #undef elf_backend_bfd_from_remote_memory
7374 #undef elf_backend_size_info
7375 #undef elf_backend_modify_segment_map
7376 #undef elf_backend_modify_program_headers
7377 #undef elf_backend_final_write_processing
7379 /* Intel L1OM support. */
7382 elf64_l1om_elf_object_p (bfd
*abfd
)
7384 /* Set the right machine number for an L1OM elf64 file. */
7385 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7389 #undef TARGET_LITTLE_SYM
7390 #define TARGET_LITTLE_SYM l1om_elf64_vec
7391 #undef TARGET_LITTLE_NAME
7392 #define TARGET_LITTLE_NAME "elf64-l1om"
7394 #define ELF_ARCH bfd_arch_l1om
7396 #undef ELF_MACHINE_CODE
7397 #define ELF_MACHINE_CODE EM_L1OM
7402 #define elf64_bed elf64_l1om_bed
7404 #undef elf_backend_object_p
7405 #define elf_backend_object_p elf64_l1om_elf_object_p
7407 /* Restore defaults. */
7408 #undef ELF_MAXPAGESIZE
7409 #undef ELF_MINPAGESIZE
7410 #undef ELF_COMMONPAGESIZE
7411 #define ELF_MAXPAGESIZE 0x200000
7412 #define ELF_MINPAGESIZE 0x1000
7413 #define ELF_COMMONPAGESIZE 0x1000
7414 #undef elf_backend_plt_alignment
7415 #define elf_backend_plt_alignment 4
7416 #undef elf_backend_arch_data
7417 #define elf_backend_arch_data &elf_x86_64_arch_bed
7419 #include "elf64-target.h"
7421 /* FreeBSD L1OM support. */
7423 #undef TARGET_LITTLE_SYM
7424 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7425 #undef TARGET_LITTLE_NAME
7426 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7429 #define ELF_OSABI ELFOSABI_FREEBSD
7432 #define elf64_bed elf64_l1om_fbsd_bed
7434 #include "elf64-target.h"
7436 /* Intel K1OM support. */
7439 elf64_k1om_elf_object_p (bfd
*abfd
)
7441 /* Set the right machine number for an K1OM elf64 file. */
7442 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7446 #undef TARGET_LITTLE_SYM
7447 #define TARGET_LITTLE_SYM k1om_elf64_vec
7448 #undef TARGET_LITTLE_NAME
7449 #define TARGET_LITTLE_NAME "elf64-k1om"
7451 #define ELF_ARCH bfd_arch_k1om
7453 #undef ELF_MACHINE_CODE
7454 #define ELF_MACHINE_CODE EM_K1OM
7459 #define elf64_bed elf64_k1om_bed
7461 #undef elf_backend_object_p
7462 #define elf_backend_object_p elf64_k1om_elf_object_p
7464 #undef elf_backend_static_tls_alignment
7466 #undef elf_backend_want_plt_sym
7467 #define elf_backend_want_plt_sym 0
7469 #include "elf64-target.h"
7471 /* FreeBSD K1OM support. */
7473 #undef TARGET_LITTLE_SYM
7474 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7475 #undef TARGET_LITTLE_NAME
7476 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7479 #define ELF_OSABI ELFOSABI_FREEBSD
7482 #define elf64_bed elf64_k1om_fbsd_bed
7484 #include "elf64-target.h"
7486 /* 32bit x86-64 support. */
7488 #undef TARGET_LITTLE_SYM
7489 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7490 #undef TARGET_LITTLE_NAME
7491 #define TARGET_LITTLE_NAME "elf32-x86-64"
7495 #define ELF_ARCH bfd_arch_i386
7497 #undef ELF_MACHINE_CODE
7498 #define ELF_MACHINE_CODE EM_X86_64
7502 #undef elf_backend_object_p
7503 #define elf_backend_object_p \
7504 elf32_x86_64_elf_object_p
7506 #undef elf_backend_bfd_from_remote_memory
7507 #define elf_backend_bfd_from_remote_memory \
7508 _bfd_elf32_bfd_from_remote_memory
7510 #undef elf_backend_size_info
7511 #define elf_backend_size_info \
7512 _bfd_elf32_size_info
7514 #include "elf32-target.h"