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 /* 0: symbol isn't __tls_get_addr.
871 1: symbol is __tls_get_addr.
872 2: symbol is unknown. */
873 unsigned int tls_get_addr
: 2;
875 /* Reference count of C/C++ function pointer relocations in read-write
876 section which can be resolved at run-time. */
877 bfd_signed_vma func_pointer_refcount
;
879 /* Information about the GOT PLT entry. Filled when there are both
880 GOT and PLT relocations against the same function. */
881 union gotplt_union plt_got
;
883 /* Information about the second PLT entry. Filled when has_bnd_reloc is
885 union gotplt_union plt_bnd
;
887 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
888 starting at the end of the jump table. */
892 #define elf_x86_64_hash_entry(ent) \
893 ((struct elf_x86_64_link_hash_entry *)(ent))
895 struct elf_x86_64_obj_tdata
897 struct elf_obj_tdata root
;
899 /* tls_type for each local got entry. */
900 char *local_got_tls_type
;
902 /* GOTPLT entries for TLS descriptors. */
903 bfd_vma
*local_tlsdesc_gotent
;
906 #define elf_x86_64_tdata(abfd) \
907 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
909 #define elf_x86_64_local_got_tls_type(abfd) \
910 (elf_x86_64_tdata (abfd)->local_got_tls_type)
912 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
913 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
915 #define is_x86_64_elf(bfd) \
916 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
917 && elf_tdata (bfd) != NULL \
918 && elf_object_id (bfd) == X86_64_ELF_DATA)
921 elf_x86_64_mkobject (bfd
*abfd
)
923 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
927 /* x86-64 ELF linker hash table. */
929 struct elf_x86_64_link_hash_table
931 struct elf_link_hash_table elf
;
933 /* Short-cuts to get to dynamic linker sections. */
935 asection
*plt_eh_frame
;
937 asection
*plt_bnd_eh_frame
;
939 asection
*plt_got_eh_frame
;
943 bfd_signed_vma refcount
;
947 /* The amount of space used by the jump slots in the GOT. */
948 bfd_vma sgotplt_jump_table_size
;
950 /* Small local sym cache. */
951 struct sym_cache sym_cache
;
953 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
954 bfd_vma (*r_sym
) (bfd_vma
);
955 unsigned int pointer_r_type
;
956 const char *dynamic_interpreter
;
957 int dynamic_interpreter_size
;
959 /* _TLS_MODULE_BASE_ symbol. */
960 struct bfd_link_hash_entry
*tls_module_base
;
962 /* Used by local STT_GNU_IFUNC symbols. */
963 htab_t loc_hash_table
;
964 void * loc_hash_memory
;
966 /* The offset into splt of the PLT entry for the TLS descriptor
967 resolver. Special values are 0, if not necessary (or not found
968 to be necessary yet), and -1 if needed but not determined
971 /* The offset into sgot of the GOT entry used by the PLT entry
975 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
976 bfd_vma next_jump_slot_index
;
977 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
978 bfd_vma next_irelative_index
;
980 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
981 to read-only sections. */
982 bfd_boolean readonly_dynrelocs_against_ifunc
;
985 /* Get the x86-64 ELF linker hash table from a link_info structure. */
987 #define elf_x86_64_hash_table(p) \
988 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
989 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
991 #define elf_x86_64_compute_jump_table_size(htab) \
992 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
994 /* Create an entry in an x86-64 ELF linker hash table. */
996 static struct bfd_hash_entry
*
997 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
998 struct bfd_hash_table
*table
,
1001 /* Allocate the structure if it has not already been allocated by a
1005 entry
= (struct bfd_hash_entry
*)
1006 bfd_hash_allocate (table
,
1007 sizeof (struct elf_x86_64_link_hash_entry
));
1012 /* Call the allocation method of the superclass. */
1013 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1016 struct elf_x86_64_link_hash_entry
*eh
;
1018 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
1019 eh
->dyn_relocs
= NULL
;
1020 eh
->tls_type
= GOT_UNKNOWN
;
1022 eh
->has_bnd_reloc
= 0;
1023 eh
->has_got_reloc
= 0;
1024 eh
->has_non_got_reloc
= 0;
1025 eh
->tls_get_addr
= 2;
1026 eh
->func_pointer_refcount
= 0;
1027 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
1028 eh
->plt_got
.offset
= (bfd_vma
) -1;
1029 eh
->tlsdesc_got
= (bfd_vma
) -1;
1035 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1036 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1037 as global symbol. We reuse indx and dynstr_index for local symbol
1038 hash since they aren't used by global symbols in this backend. */
1041 elf_x86_64_local_htab_hash (const void *ptr
)
1043 struct elf_link_hash_entry
*h
1044 = (struct elf_link_hash_entry
*) ptr
;
1045 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1048 /* Compare local hash entries. */
1051 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
1053 struct elf_link_hash_entry
*h1
1054 = (struct elf_link_hash_entry
*) ptr1
;
1055 struct elf_link_hash_entry
*h2
1056 = (struct elf_link_hash_entry
*) ptr2
;
1058 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1061 /* Find and/or create a hash entry for local symbol. */
1063 static struct elf_link_hash_entry
*
1064 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
1065 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1068 struct elf_x86_64_link_hash_entry e
, *ret
;
1069 asection
*sec
= abfd
->sections
;
1070 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1071 htab
->r_sym (rel
->r_info
));
1074 e
.elf
.indx
= sec
->id
;
1075 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1076 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1077 create
? INSERT
: NO_INSERT
);
1084 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1088 ret
= (struct elf_x86_64_link_hash_entry
*)
1089 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1090 sizeof (struct elf_x86_64_link_hash_entry
));
1093 memset (ret
, 0, sizeof (*ret
));
1094 ret
->elf
.indx
= sec
->id
;
1095 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1096 ret
->elf
.dynindx
= -1;
1097 ret
->func_pointer_refcount
= 0;
1098 ret
->plt_got
.offset
= (bfd_vma
) -1;
1104 /* Destroy an X86-64 ELF linker hash table. */
1107 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1109 struct elf_x86_64_link_hash_table
*htab
1110 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1112 if (htab
->loc_hash_table
)
1113 htab_delete (htab
->loc_hash_table
);
1114 if (htab
->loc_hash_memory
)
1115 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1116 _bfd_elf_link_hash_table_free (obfd
);
1119 /* Create an X86-64 ELF linker hash table. */
1121 static struct bfd_link_hash_table
*
1122 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1124 struct elf_x86_64_link_hash_table
*ret
;
1125 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1127 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1131 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1132 elf_x86_64_link_hash_newfunc
,
1133 sizeof (struct elf_x86_64_link_hash_entry
),
1140 if (ABI_64_P (abfd
))
1142 ret
->r_info
= elf64_r_info
;
1143 ret
->r_sym
= elf64_r_sym
;
1144 ret
->pointer_r_type
= R_X86_64_64
;
1145 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1146 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1150 ret
->r_info
= elf32_r_info
;
1151 ret
->r_sym
= elf32_r_sym
;
1152 ret
->pointer_r_type
= R_X86_64_32
;
1153 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1154 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1157 ret
->loc_hash_table
= htab_try_create (1024,
1158 elf_x86_64_local_htab_hash
,
1159 elf_x86_64_local_htab_eq
,
1161 ret
->loc_hash_memory
= objalloc_create ();
1162 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1164 elf_x86_64_link_hash_table_free (abfd
);
1167 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1169 return &ret
->elf
.root
;
1172 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1173 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1177 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
1178 struct bfd_link_info
*info
)
1180 struct elf_x86_64_link_hash_table
*htab
;
1182 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1185 htab
= elf_x86_64_hash_table (info
);
1189 /* Set the contents of the .interp section to the interpreter. */
1190 if (bfd_link_executable (info
) && !info
->nointerp
)
1192 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1195 s
->size
= htab
->dynamic_interpreter_size
;
1196 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
1200 if (!info
->no_ld_generated_unwind_info
1201 && htab
->plt_eh_frame
== NULL
1202 && htab
->elf
.splt
!= NULL
)
1204 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1205 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1206 | SEC_LINKER_CREATED
);
1208 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1209 if (htab
->plt_eh_frame
== NULL
1210 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
,
1211 ABI_64_P (dynobj
) ? 3 : 2))
1215 /* Align .got section to its entry size. */
1216 if (htab
->elf
.sgot
!= NULL
1217 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgot
, 3))
1220 /* Align .got.plt section to its entry size. */
1221 if (htab
->elf
.sgotplt
!= NULL
1222 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgotplt
, 3))
1228 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1231 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1232 struct elf_link_hash_entry
*dir
,
1233 struct elf_link_hash_entry
*ind
)
1235 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1237 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1238 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1240 edir
->has_bnd_reloc
|= eind
->has_bnd_reloc
;
1241 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1242 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1244 if (eind
->dyn_relocs
!= NULL
)
1246 if (edir
->dyn_relocs
!= NULL
)
1248 struct elf_dyn_relocs
**pp
;
1249 struct elf_dyn_relocs
*p
;
1251 /* Add reloc counts against the indirect sym to the direct sym
1252 list. Merge any entries against the same section. */
1253 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1255 struct elf_dyn_relocs
*q
;
1257 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1258 if (q
->sec
== p
->sec
)
1260 q
->pc_count
+= p
->pc_count
;
1261 q
->count
+= p
->count
;
1268 *pp
= edir
->dyn_relocs
;
1271 edir
->dyn_relocs
= eind
->dyn_relocs
;
1272 eind
->dyn_relocs
= NULL
;
1275 if (ind
->root
.type
== bfd_link_hash_indirect
1276 && dir
->got
.refcount
<= 0)
1278 edir
->tls_type
= eind
->tls_type
;
1279 eind
->tls_type
= GOT_UNKNOWN
;
1282 if (ELIMINATE_COPY_RELOCS
1283 && ind
->root
.type
!= bfd_link_hash_indirect
1284 && dir
->dynamic_adjusted
)
1286 /* If called to transfer flags for a weakdef during processing
1287 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1288 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1289 if (dir
->versioned
!= versioned_hidden
)
1290 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1291 dir
->ref_regular
|= ind
->ref_regular
;
1292 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1293 dir
->needs_plt
|= ind
->needs_plt
;
1294 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1298 if (eind
->func_pointer_refcount
> 0)
1300 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1301 eind
->func_pointer_refcount
= 0;
1304 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1309 elf64_x86_64_elf_object_p (bfd
*abfd
)
1311 /* Set the right machine number for an x86-64 elf64 file. */
1312 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1317 elf32_x86_64_elf_object_p (bfd
*abfd
)
1319 /* Set the right machine number for an x86-64 elf32 file. */
1320 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1324 /* Return TRUE if the TLS access code sequence support transition
1328 elf_x86_64_check_tls_transition (bfd
*abfd
,
1329 struct bfd_link_info
*info
,
1332 Elf_Internal_Shdr
*symtab_hdr
,
1333 struct elf_link_hash_entry
**sym_hashes
,
1334 unsigned int r_type
,
1335 const Elf_Internal_Rela
*rel
,
1336 const Elf_Internal_Rela
*relend
)
1339 unsigned long r_symndx
;
1340 bfd_boolean largepic
= FALSE
;
1341 struct elf_link_hash_entry
*h
;
1343 struct elf_x86_64_link_hash_table
*htab
;
1345 bfd_boolean indirect_call
, tls_get_addr
;
1347 htab
= elf_x86_64_hash_table (info
);
1348 offset
= rel
->r_offset
;
1351 case R_X86_64_TLSGD
:
1352 case R_X86_64_TLSLD
:
1353 if ((rel
+ 1) >= relend
)
1356 if (r_type
== R_X86_64_TLSGD
)
1358 /* Check transition from GD access model. For 64bit, only
1359 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1360 .word 0x6666; rex64; call __tls_get_addr@PLT
1362 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1364 call *__tls_get_addr@GOTPCREL(%rip)
1365 which may be converted to
1366 addr32 call __tls_get_addr
1367 can transit to different access model. For 32bit, only
1368 leaq foo@tlsgd(%rip), %rdi
1369 .word 0x6666; rex64; call __tls_get_addr@PLT
1371 leaq foo@tlsgd(%rip), %rdi
1373 call *__tls_get_addr@GOTPCREL(%rip)
1374 which may be converted to
1375 addr32 call __tls_get_addr
1376 can transit to different access model. For largepic,
1378 leaq foo@tlsgd(%rip), %rdi
1379 movabsq $__tls_get_addr@pltoff, %rax
1383 leaq foo@tlsgd(%rip), %rdi
1384 movabsq $__tls_get_addr@pltoff, %rax
1388 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1390 if ((offset
+ 12) > sec
->size
)
1393 call
= contents
+ offset
+ 4;
1395 || !((call
[1] == 0x48
1403 && call
[3] == 0xe8)))
1405 if (!ABI_64_P (abfd
)
1406 || (offset
+ 19) > sec
->size
1408 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1409 || memcmp (call
, "\x48\xb8", 2) != 0
1413 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1414 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1418 else if (ABI_64_P (abfd
))
1421 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1427 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1430 indirect_call
= call
[2] == 0xff;
1434 /* Check transition from LD access model. Only
1435 leaq foo@tlsld(%rip), %rdi;
1436 call __tls_get_addr@PLT
1438 leaq foo@tlsld(%rip), %rdi;
1439 call *__tls_get_addr@GOTPCREL(%rip)
1440 which may be converted to
1441 addr32 call __tls_get_addr
1442 can transit to different access model. For largepic
1444 leaq foo@tlsld(%rip), %rdi
1445 movabsq $__tls_get_addr@pltoff, %rax
1449 leaq foo@tlsld(%rip), %rdi
1450 movabsq $__tls_get_addr@pltoff, %rax
1454 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1456 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1459 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1462 call
= contents
+ offset
+ 4;
1463 if (!(call
[0] == 0xe8
1464 || (call
[0] == 0xff && call
[1] == 0x15)
1465 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1467 if (!ABI_64_P (abfd
)
1468 || (offset
+ 19) > sec
->size
1469 || memcmp (call
, "\x48\xb8", 2) != 0
1473 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1474 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1478 indirect_call
= call
[0] == 0xff;
1481 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1482 if (r_symndx
< symtab_hdr
->sh_info
)
1485 tls_get_addr
= FALSE
;
1486 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1487 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1489 struct elf_x86_64_link_hash_entry
*eh
1490 = (struct elf_x86_64_link_hash_entry
*) h
;
1491 tls_get_addr
= eh
->tls_get_addr
== 1;
1492 if (eh
->tls_get_addr
> 1)
1494 /* Use strncmp to check __tls_get_addr since
1495 __tls_get_addr may be versioned. */
1496 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1499 eh
->tls_get_addr
= 1;
1500 tls_get_addr
= TRUE
;
1503 eh
->tls_get_addr
= 0;
1510 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1511 else if (indirect_call
)
1512 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1514 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1515 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1517 case R_X86_64_GOTTPOFF
:
1518 /* Check transition from IE access model:
1519 mov foo@gottpoff(%rip), %reg
1520 add foo@gottpoff(%rip), %reg
1523 /* Check REX prefix first. */
1524 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1526 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1527 if (val
!= 0x48 && val
!= 0x4c)
1529 /* X32 may have 0x44 REX prefix or no REX prefix. */
1530 if (ABI_64_P (abfd
))
1536 /* X32 may not have any REX prefix. */
1537 if (ABI_64_P (abfd
))
1539 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1543 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1544 if (val
!= 0x8b && val
!= 0x03)
1547 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1548 return (val
& 0xc7) == 5;
1550 case R_X86_64_GOTPC32_TLSDESC
:
1551 /* Check transition from GDesc access model:
1552 leaq x@tlsdesc(%rip), %rax
1554 Make sure it's a leaq adding rip to a 32-bit offset
1555 into any register, although it's probably almost always
1558 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1561 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1562 if ((val
& 0xfb) != 0x48)
1565 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1568 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1569 return (val
& 0xc7) == 0x05;
1571 case R_X86_64_TLSDESC_CALL
:
1572 /* Check transition from GDesc access model:
1573 call *x@tlsdesc(%rax)
1575 if (offset
+ 2 <= sec
->size
)
1577 /* Make sure that it's a call *x@tlsdesc(%rax). */
1578 call
= contents
+ offset
;
1579 return call
[0] == 0xff && call
[1] == 0x10;
1589 /* Return TRUE if the TLS access transition is OK or no transition
1590 will be performed. Update R_TYPE if there is a transition. */
1593 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1594 asection
*sec
, bfd_byte
*contents
,
1595 Elf_Internal_Shdr
*symtab_hdr
,
1596 struct elf_link_hash_entry
**sym_hashes
,
1597 unsigned int *r_type
, int tls_type
,
1598 const Elf_Internal_Rela
*rel
,
1599 const Elf_Internal_Rela
*relend
,
1600 struct elf_link_hash_entry
*h
,
1601 unsigned long r_symndx
,
1602 bfd_boolean from_relocate_section
)
1604 unsigned int from_type
= *r_type
;
1605 unsigned int to_type
= from_type
;
1606 bfd_boolean check
= TRUE
;
1608 /* Skip TLS transition for functions. */
1610 && (h
->type
== STT_FUNC
1611 || h
->type
== STT_GNU_IFUNC
))
1616 case R_X86_64_TLSGD
:
1617 case R_X86_64_GOTPC32_TLSDESC
:
1618 case R_X86_64_TLSDESC_CALL
:
1619 case R_X86_64_GOTTPOFF
:
1620 if (bfd_link_executable (info
))
1623 to_type
= R_X86_64_TPOFF32
;
1625 to_type
= R_X86_64_GOTTPOFF
;
1628 /* When we are called from elf_x86_64_relocate_section, there may
1629 be additional transitions based on TLS_TYPE. */
1630 if (from_relocate_section
)
1632 unsigned int new_to_type
= to_type
;
1634 if (bfd_link_executable (info
)
1637 && tls_type
== GOT_TLS_IE
)
1638 new_to_type
= R_X86_64_TPOFF32
;
1640 if (to_type
== R_X86_64_TLSGD
1641 || to_type
== R_X86_64_GOTPC32_TLSDESC
1642 || to_type
== R_X86_64_TLSDESC_CALL
)
1644 if (tls_type
== GOT_TLS_IE
)
1645 new_to_type
= R_X86_64_GOTTPOFF
;
1648 /* We checked the transition before when we were called from
1649 elf_x86_64_check_relocs. We only want to check the new
1650 transition which hasn't been checked before. */
1651 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1652 to_type
= new_to_type
;
1657 case R_X86_64_TLSLD
:
1658 if (bfd_link_executable (info
))
1659 to_type
= R_X86_64_TPOFF32
;
1666 /* Return TRUE if there is no transition. */
1667 if (from_type
== to_type
)
1670 /* Check if the transition can be performed. */
1672 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1673 symtab_hdr
, sym_hashes
,
1674 from_type
, rel
, relend
))
1676 reloc_howto_type
*from
, *to
;
1679 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1680 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1683 name
= h
->root
.root
.string
;
1686 struct elf_x86_64_link_hash_table
*htab
;
1688 htab
= elf_x86_64_hash_table (info
);
1693 Elf_Internal_Sym
*isym
;
1695 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1697 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1702 /* xgettext:c-format */
1703 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1704 "in section `%A' failed"),
1705 abfd
, sec
, from
->name
, to
->name
, name
,
1706 (unsigned long) rel
->r_offset
);
1707 bfd_set_error (bfd_error_bad_value
);
1715 /* Rename some of the generic section flags to better document how they
1717 #define need_convert_load sec_flg0
1718 #define check_relocs_failed sec_flg1
1721 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1722 struct elf_link_hash_entry
*h
,
1723 Elf_Internal_Shdr
*symtab_hdr
,
1724 Elf_Internal_Sym
*isym
,
1725 reloc_howto_type
*howto
)
1728 const char *und
= "";
1729 const char *pic
= "";
1734 name
= h
->root
.root
.string
;
1735 switch (ELF_ST_VISIBILITY (h
->other
))
1738 v
= _("hidden symbol ");
1741 v
= _("internal symbol ");
1744 v
= _("protected symbol ");
1748 pic
= _("; recompile with -fPIC");
1752 if (!h
->def_regular
&& !h
->def_dynamic
)
1753 und
= _("undefined ");
1757 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1758 pic
= _("; recompile with -fPIC");
1761 /* xgettext:c-format */
1762 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1763 "not be used when making a shared object%s"),
1764 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1765 bfd_set_error (bfd_error_bad_value
);
1766 sec
->check_relocs_failed
= 1;
1770 /* With the local symbol, foo, we convert
1771 mov foo@GOTPCREL(%rip), %reg
1775 call/jmp *foo@GOTPCREL(%rip)
1777 nop call foo/jmp foo nop
1778 When PIC is false, convert
1779 test %reg, foo@GOTPCREL(%rip)
1783 binop foo@GOTPCREL(%rip), %reg
1786 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1790 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1792 Elf_Internal_Rela
*irel
,
1793 struct elf_link_hash_entry
*h
,
1794 bfd_boolean
*converted
,
1795 struct bfd_link_info
*link_info
)
1797 struct elf_x86_64_link_hash_table
*htab
;
1799 bfd_boolean require_reloc_pc32
;
1801 bfd_boolean to_reloc_pc32
;
1804 bfd_signed_vma raddend
;
1805 unsigned int opcode
;
1807 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1808 unsigned int r_symndx
;
1810 bfd_vma roff
= irel
->r_offset
;
1812 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1815 raddend
= irel
->r_addend
;
1816 /* Addend for 32-bit PC-relative relocation must be -4. */
1820 htab
= elf_x86_64_hash_table (link_info
);
1821 is_pic
= bfd_link_pic (link_info
);
1823 relocx
= (r_type
== R_X86_64_GOTPCRELX
1824 || r_type
== R_X86_64_REX_GOTPCRELX
);
1826 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1829 = link_info
->disable_target_specific_optimizations
> 1;
1831 r_symndx
= htab
->r_sym (irel
->r_info
);
1833 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1835 /* Convert mov to lea since it has been done for a while. */
1838 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1839 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1840 test, xor instructions. */
1845 /* We convert only to R_X86_64_PC32:
1847 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1848 3. require_reloc_pc32 is true.
1851 to_reloc_pc32
= (opcode
== 0xff
1853 || require_reloc_pc32
1856 /* Get the symbol referred to by the reloc. */
1859 Elf_Internal_Sym
*isym
1860 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1862 /* Skip relocation against undefined symbols. */
1863 if (isym
->st_shndx
== SHN_UNDEF
)
1866 symtype
= ELF_ST_TYPE (isym
->st_info
);
1868 if (isym
->st_shndx
== SHN_ABS
)
1869 tsec
= bfd_abs_section_ptr
;
1870 else if (isym
->st_shndx
== SHN_COMMON
)
1871 tsec
= bfd_com_section_ptr
;
1872 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1873 tsec
= &_bfd_elf_large_com_section
;
1875 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1877 toff
= isym
->st_value
;
1881 /* Undefined weak symbol is only bound locally in executable
1882 and its reference is resolved as 0 without relocation
1883 overflow. We can only perform this optimization for
1884 GOTPCRELX relocations since we need to modify REX byte.
1885 It is OK convert mov with R_X86_64_GOTPCREL to
1887 if ((relocx
|| opcode
== 0x8b)
1888 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1890 elf_x86_64_hash_entry (h
)))
1894 /* Skip for branch instructions since R_X86_64_PC32
1896 if (require_reloc_pc32
)
1901 /* For non-branch instructions, we can convert to
1902 R_X86_64_32/R_X86_64_32S since we know if there
1904 to_reloc_pc32
= FALSE
;
1907 /* Since we don't know the current PC when PIC is true,
1908 we can't convert to R_X86_64_PC32. */
1909 if (to_reloc_pc32
&& is_pic
)
1914 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1915 ld.so may use its link-time address. */
1916 else if ((h
->def_regular
1917 || h
->root
.type
== bfd_link_hash_defined
1918 || h
->root
.type
== bfd_link_hash_defweak
)
1919 && h
!= htab
->elf
.hdynamic
1920 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1922 /* bfd_link_hash_new or bfd_link_hash_undefined is
1923 set by an assignment in a linker script in
1924 bfd_elf_record_link_assignment. */
1926 && (h
->root
.type
== bfd_link_hash_new
1927 || h
->root
.type
== bfd_link_hash_undefined
1928 || ((h
->root
.type
== bfd_link_hash_defined
1929 || h
->root
.type
== bfd_link_hash_defweak
)
1930 && h
->root
.u
.def
.section
== bfd_und_section_ptr
)))
1932 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1933 if (require_reloc_pc32
)
1937 tsec
= h
->root
.u
.def
.section
;
1938 toff
= h
->root
.u
.def
.value
;
1945 /* Don't convert GOTPCREL relocation against large section. */
1946 if (elf_section_data (tsec
) != NULL
1947 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1950 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1954 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1956 /* At this stage in linking, no SEC_MERGE symbol has been
1957 adjusted, so all references to such symbols need to be
1958 passed through _bfd_merged_section_offset. (Later, in
1959 relocate_section, all SEC_MERGE symbols *except* for
1960 section symbols have been adjusted.)
1962 gas may reduce relocations against symbols in SEC_MERGE
1963 sections to a relocation against the section symbol when
1964 the original addend was zero. When the reloc is against
1965 a section symbol we should include the addend in the
1966 offset passed to _bfd_merged_section_offset, since the
1967 location of interest is the original symbol. On the
1968 other hand, an access to "sym+addend" where "sym" is not
1969 a section symbol should not include the addend; Such an
1970 access is presumed to be an offset from "sym"; The
1971 location of interest is just "sym". */
1972 if (symtype
== STT_SECTION
)
1975 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1976 elf_section_data (tsec
)->sec_info
,
1979 if (symtype
!= STT_SECTION
)
1985 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1986 if (tsec
->output_section
== sec
->output_section
)
1988 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
1993 bfd_signed_vma distance
;
1995 /* At this point, we don't know the load addresses of TSEC
1996 section nor SEC section. We estimate the distrance between
1997 SEC and TSEC. We store the estimated distances in the
1998 compressed_size field of the output section, which is only
1999 used to decompress the compressed input section. */
2000 if (sec
->output_section
->compressed_size
== 0)
2003 bfd_size_type size
= 0;
2004 for (asect
= link_info
->output_bfd
->sections
;
2006 asect
= asect
->next
)
2007 /* Skip debug sections since compressed_size is used to
2008 compress debug sections. */
2009 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
2012 for (i
= asect
->map_head
.s
;
2016 size
= align_power (size
, i
->alignment_power
);
2019 asect
->compressed_size
= size
;
2023 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2025 distance
= (tsec
->output_section
->compressed_size
2026 - sec
->output_section
->compressed_size
);
2030 /* Take PT_GNU_RELRO segment into account by adding
2032 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
2033 - roff
+ 0x80000000) > 0xffffffff)
2040 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2045 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2047 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2050 /* Convert to "jmp foo nop". */
2053 nop_offset
= irel
->r_offset
+ 3;
2054 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2055 irel
->r_offset
-= 1;
2056 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2060 struct elf_x86_64_link_hash_entry
*eh
2061 = (struct elf_x86_64_link_hash_entry
*) h
;
2063 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2066 /* To support TLS optimization, always use addr32 prefix for
2067 "call *__tls_get_addr@GOTPCREL(%rip)". */
2068 if (eh
&& eh
->tls_get_addr
== 1)
2071 nop_offset
= irel
->r_offset
- 2;
2075 nop
= link_info
->call_nop_byte
;
2076 if (link_info
->call_nop_as_suffix
)
2078 nop_offset
= irel
->r_offset
+ 3;
2079 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2080 irel
->r_offset
-= 1;
2081 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2084 nop_offset
= irel
->r_offset
- 2;
2087 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2088 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2089 r_type
= R_X86_64_PC32
;
2094 unsigned int rex_mask
= REX_R
;
2096 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2097 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2105 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2106 "lea foo(%rip), %reg". */
2108 r_type
= R_X86_64_PC32
;
2112 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2113 "mov $foo, %reg". */
2115 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2116 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2117 if ((rex
& REX_W
) != 0
2118 && ABI_64_P (link_info
->output_bfd
))
2120 /* Keep the REX_W bit in REX byte for LP64. */
2121 r_type
= R_X86_64_32S
;
2122 goto rewrite_modrm_rex
;
2126 /* If the REX_W bit in REX byte isn't needed,
2127 use R_X86_64_32 and clear the W bit to avoid
2128 sign-extend imm32 to imm64. */
2129 r_type
= R_X86_64_32
;
2130 /* Clear the W bit in REX byte. */
2132 goto rewrite_modrm_rex
;
2138 /* R_X86_64_PC32 isn't supported. */
2142 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2145 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2146 "test $foo, %reg". */
2147 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2152 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2153 "binop $foo, %reg". */
2154 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2158 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2159 overflow when sign-extending imm32 to imm64. */
2160 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2163 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2167 /* Move the R bit to the B bit in REX byte. */
2168 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2169 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2172 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2176 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2179 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2186 /* Look through the relocs for a section during the first phase, and
2187 calculate needed space in the global offset table, procedure
2188 linkage table, and dynamic reloc sections. */
2191 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2193 const Elf_Internal_Rela
*relocs
)
2195 struct elf_x86_64_link_hash_table
*htab
;
2196 Elf_Internal_Shdr
*symtab_hdr
;
2197 struct elf_link_hash_entry
**sym_hashes
;
2198 const Elf_Internal_Rela
*rel
;
2199 const Elf_Internal_Rela
*rel_end
;
2202 bfd_boolean use_plt_got
;
2204 if (bfd_link_relocatable (info
))
2207 /* Don't do anything special with non-loaded, non-alloced sections.
2208 In particular, any relocs in such sections should not affect GOT
2209 and PLT reference counting (ie. we don't allow them to create GOT
2210 or PLT entries), there's no possibility or desire to optimize TLS
2211 relocs, and there's not much point in propagating relocs to shared
2212 libs that the dynamic linker won't relocate. */
2213 if ((sec
->flags
& SEC_ALLOC
) == 0)
2216 BFD_ASSERT (is_x86_64_elf (abfd
));
2218 htab
= elf_x86_64_hash_table (info
);
2221 sec
->check_relocs_failed
= 1;
2225 /* Get the section contents. */
2226 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2227 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2228 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2230 sec
->check_relocs_failed
= 1;
2234 use_plt_got
= get_elf_x86_64_backend_data (abfd
) == &elf_x86_64_arch_bed
;
2236 symtab_hdr
= &elf_symtab_hdr (abfd
);
2237 sym_hashes
= elf_sym_hashes (abfd
);
2241 rel_end
= relocs
+ sec
->reloc_count
;
2242 for (rel
= relocs
; rel
< rel_end
; rel
++)
2244 unsigned int r_type
;
2245 unsigned long r_symndx
;
2246 struct elf_link_hash_entry
*h
;
2247 struct elf_x86_64_link_hash_entry
*eh
;
2248 Elf_Internal_Sym
*isym
;
2250 bfd_boolean size_reloc
;
2252 r_symndx
= htab
->r_sym (rel
->r_info
);
2253 r_type
= ELF32_R_TYPE (rel
->r_info
);
2255 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2257 /* xgettext:c-format */
2258 _bfd_error_handler (_("%B: bad symbol index: %d"),
2263 if (r_symndx
< symtab_hdr
->sh_info
)
2265 /* A local symbol. */
2266 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2271 /* Check relocation against local STT_GNU_IFUNC symbol. */
2272 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2274 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2279 /* Fake a STT_GNU_IFUNC symbol. */
2280 h
->type
= STT_GNU_IFUNC
;
2283 h
->forced_local
= 1;
2284 h
->root
.type
= bfd_link_hash_defined
;
2292 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2293 while (h
->root
.type
== bfd_link_hash_indirect
2294 || h
->root
.type
== bfd_link_hash_warning
)
2295 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2298 /* Check invalid x32 relocations. */
2299 if (!ABI_64_P (abfd
))
2305 case R_X86_64_DTPOFF64
:
2306 case R_X86_64_TPOFF64
:
2308 case R_X86_64_GOTOFF64
:
2309 case R_X86_64_GOT64
:
2310 case R_X86_64_GOTPCREL64
:
2311 case R_X86_64_GOTPC64
:
2312 case R_X86_64_GOTPLT64
:
2313 case R_X86_64_PLTOFF64
:
2316 name
= h
->root
.root
.string
;
2318 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2321 /* xgettext:c-format */
2322 (_("%B: relocation %s against symbol `%s' isn't "
2323 "supported in x32 mode"), abfd
,
2324 x86_64_elf_howto_table
[r_type
].name
, name
);
2325 bfd_set_error (bfd_error_bad_value
);
2338 case R_X86_64_PC32_BND
:
2339 case R_X86_64_PLT32_BND
:
2341 case R_X86_64_PLT32
:
2344 /* MPX PLT is supported only if elf_x86_64_arch_bed
2345 is used in 64-bit mode. */
2348 && (get_elf_x86_64_backend_data (abfd
)
2349 == &elf_x86_64_arch_bed
))
2351 elf_x86_64_hash_entry (h
)->has_bnd_reloc
= 1;
2353 /* Create the second PLT for Intel MPX support. */
2354 if (htab
->plt_bnd
== NULL
)
2356 const struct elf_backend_data
*bed
;
2358 bed
= get_elf_backend_data (info
->output_bfd
);
2359 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry
) == 8
2360 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2361 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2363 if (htab
->elf
.dynobj
== NULL
)
2364 htab
->elf
.dynobj
= abfd
;
2366 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2368 (bed
->dynamic_sec_flags
2373 if (htab
->plt_bnd
== NULL
2374 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2380 if (!info
->no_ld_generated_unwind_info
2381 && htab
->plt_bnd_eh_frame
== NULL
)
2383 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2384 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2385 | SEC_LINKER_CREATED
);
2386 htab
->plt_bnd_eh_frame
2387 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2390 if (htab
->plt_bnd_eh_frame
== NULL
2391 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2392 htab
->plt_bnd_eh_frame
,
2401 case R_X86_64_GOTPCREL
:
2402 case R_X86_64_GOTPCRELX
:
2403 case R_X86_64_REX_GOTPCRELX
:
2404 case R_X86_64_GOTPCREL64
:
2405 if (htab
->elf
.dynobj
== NULL
)
2406 htab
->elf
.dynobj
= abfd
;
2407 /* Create the ifunc sections for static executables. */
2408 if (h
->type
== STT_GNU_IFUNC
2409 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
2415 /* It is referenced by a non-shared object. */
2417 h
->root
.non_ir_ref
= 1;
2419 if (h
->type
== STT_GNU_IFUNC
)
2420 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2421 |= elf_gnu_symbol_ifunc
;
2424 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2425 symtab_hdr
, sym_hashes
,
2426 &r_type
, GOT_UNKNOWN
,
2427 rel
, rel_end
, h
, r_symndx
, FALSE
))
2430 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2433 case R_X86_64_TLSLD
:
2434 htab
->tls_ld_got
.refcount
+= 1;
2437 case R_X86_64_TPOFF32
:
2438 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2439 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2440 &x86_64_elf_howto_table
[r_type
]);
2442 eh
->has_got_reloc
= 1;
2445 case R_X86_64_GOTTPOFF
:
2446 if (!bfd_link_executable (info
))
2447 info
->flags
|= DF_STATIC_TLS
;
2450 case R_X86_64_GOT32
:
2451 case R_X86_64_GOTPCREL
:
2452 case R_X86_64_GOTPCRELX
:
2453 case R_X86_64_REX_GOTPCRELX
:
2454 case R_X86_64_TLSGD
:
2455 case R_X86_64_GOT64
:
2456 case R_X86_64_GOTPCREL64
:
2457 case R_X86_64_GOTPLT64
:
2458 case R_X86_64_GOTPC32_TLSDESC
:
2459 case R_X86_64_TLSDESC_CALL
:
2460 /* This symbol requires a global offset table entry. */
2462 int tls_type
, old_tls_type
;
2466 default: tls_type
= GOT_NORMAL
; break;
2467 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2468 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2469 case R_X86_64_GOTPC32_TLSDESC
:
2470 case R_X86_64_TLSDESC_CALL
:
2471 tls_type
= GOT_TLS_GDESC
; break;
2476 h
->got
.refcount
+= 1;
2477 old_tls_type
= eh
->tls_type
;
2481 bfd_signed_vma
*local_got_refcounts
;
2483 /* This is a global offset table entry for a local symbol. */
2484 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2485 if (local_got_refcounts
== NULL
)
2489 size
= symtab_hdr
->sh_info
;
2490 size
*= sizeof (bfd_signed_vma
)
2491 + sizeof (bfd_vma
) + sizeof (char);
2492 local_got_refcounts
= ((bfd_signed_vma
*)
2493 bfd_zalloc (abfd
, size
));
2494 if (local_got_refcounts
== NULL
)
2496 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2497 elf_x86_64_local_tlsdesc_gotent (abfd
)
2498 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2499 elf_x86_64_local_got_tls_type (abfd
)
2500 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2502 local_got_refcounts
[r_symndx
] += 1;
2504 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2507 /* If a TLS symbol is accessed using IE at least once,
2508 there is no point to use dynamic model for it. */
2509 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2510 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2511 || tls_type
!= GOT_TLS_IE
))
2513 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2514 tls_type
= old_tls_type
;
2515 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2516 && GOT_TLS_GD_ANY_P (tls_type
))
2517 tls_type
|= old_tls_type
;
2521 name
= h
->root
.root
.string
;
2523 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2526 /* xgettext:c-format */
2527 (_("%B: '%s' accessed both as normal and thread local symbol"),
2529 bfd_set_error (bfd_error_bad_value
);
2534 if (old_tls_type
!= tls_type
)
2537 eh
->tls_type
= tls_type
;
2539 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2544 case R_X86_64_GOTOFF64
:
2545 case R_X86_64_GOTPC32
:
2546 case R_X86_64_GOTPC64
:
2549 eh
->has_got_reloc
= 1;
2550 if (htab
->elf
.sgot
== NULL
)
2552 if (htab
->elf
.dynobj
== NULL
)
2553 htab
->elf
.dynobj
= abfd
;
2554 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
2560 case R_X86_64_PLT32
:
2561 case R_X86_64_PLT32_BND
:
2562 /* This symbol requires a procedure linkage table entry. We
2563 actually build the entry in adjust_dynamic_symbol,
2564 because this might be a case of linking PIC code which is
2565 never referenced by a dynamic object, in which case we
2566 don't need to generate a procedure linkage table entry
2569 /* If this is a local symbol, we resolve it directly without
2570 creating a procedure linkage table entry. */
2574 eh
->has_got_reloc
= 1;
2576 h
->plt
.refcount
+= 1;
2579 case R_X86_64_PLTOFF64
:
2580 /* This tries to form the 'address' of a function relative
2581 to GOT. For global symbols we need a PLT entry. */
2585 h
->plt
.refcount
+= 1;
2589 case R_X86_64_SIZE32
:
2590 case R_X86_64_SIZE64
:
2595 if (!ABI_64_P (abfd
))
2601 /* Check relocation overflow as these relocs may lead to
2602 run-time relocation overflow. Don't error out for
2603 sections we don't care about, such as debug sections or
2604 when relocation overflow check is disabled. */
2605 if (!info
->no_reloc_overflow_check
2606 && (bfd_link_pic (info
)
2607 || (bfd_link_executable (info
)
2611 && (sec
->flags
& SEC_READONLY
) == 0)))
2612 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2613 &x86_64_elf_howto_table
[r_type
]);
2619 case R_X86_64_PC32_BND
:
2623 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2624 eh
->has_non_got_reloc
= 1;
2625 /* We are called after all symbols have been resolved. Only
2626 relocation against STT_GNU_IFUNC symbol must go through
2629 && (bfd_link_executable (info
)
2630 || h
->type
== STT_GNU_IFUNC
))
2632 /* If this reloc is in a read-only section, we might
2633 need a copy reloc. We can't check reliably at this
2634 stage whether the section is read-only, as input
2635 sections have not yet been mapped to output sections.
2636 Tentatively set the flag for now, and correct in
2637 adjust_dynamic_symbol. */
2640 /* We may need a .plt entry if the symbol is a function
2641 defined in a shared lib or is a STT_GNU_IFUNC function
2642 referenced from the code or read-only section. */
2644 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2645 h
->plt
.refcount
+= 1;
2647 if (r_type
== R_X86_64_PC32
)
2649 /* Since something like ".long foo - ." may be used
2650 as pointer, make sure that PLT is used if foo is
2651 a function defined in a shared library. */
2652 if ((sec
->flags
& SEC_CODE
) == 0)
2653 h
->pointer_equality_needed
= 1;
2655 else if (r_type
!= R_X86_64_PC32_BND
2656 && r_type
!= R_X86_64_PC64
)
2658 h
->pointer_equality_needed
= 1;
2659 /* At run-time, R_X86_64_64 can be resolved for both
2660 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2661 can only be resolved for x32. */
2662 if ((sec
->flags
& SEC_READONLY
) == 0
2663 && (r_type
== R_X86_64_64
2664 || (!ABI_64_P (abfd
)
2665 && (r_type
== R_X86_64_32
2666 || r_type
== R_X86_64_32S
))))
2667 eh
->func_pointer_refcount
+= 1;
2673 /* If we are creating a shared library, and this is a reloc
2674 against a global symbol, or a non PC relative reloc
2675 against a local symbol, then we need to copy the reloc
2676 into the shared library. However, if we are linking with
2677 -Bsymbolic, we do not need to copy a reloc against a
2678 global symbol which is defined in an object we are
2679 including in the link (i.e., DEF_REGULAR is set). At
2680 this point we have not seen all the input files, so it is
2681 possible that DEF_REGULAR is not set now but will be set
2682 later (it is never cleared). In case of a weak definition,
2683 DEF_REGULAR may be cleared later by a strong definition in
2684 a shared library. We account for that possibility below by
2685 storing information in the relocs_copied field of the hash
2686 table entry. A similar situation occurs when creating
2687 shared libraries and symbol visibility changes render the
2690 If on the other hand, we are creating an executable, we
2691 may need to keep relocations for symbols satisfied by a
2692 dynamic library if we manage to avoid copy relocs for the
2695 Generate dynamic pointer relocation against STT_GNU_IFUNC
2696 symbol in the non-code section. */
2697 if ((bfd_link_pic (info
)
2698 && (! IS_X86_64_PCREL_TYPE (r_type
)
2700 && (! (bfd_link_pie (info
)
2701 || SYMBOLIC_BIND (info
, h
))
2702 || h
->root
.type
== bfd_link_hash_defweak
2703 || !h
->def_regular
))))
2705 && h
->type
== STT_GNU_IFUNC
2706 && r_type
== htab
->pointer_r_type
2707 && (sec
->flags
& SEC_CODE
) == 0)
2708 || (ELIMINATE_COPY_RELOCS
2709 && !bfd_link_pic (info
)
2711 && (h
->root
.type
== bfd_link_hash_defweak
2712 || !h
->def_regular
)))
2714 struct elf_dyn_relocs
*p
;
2715 struct elf_dyn_relocs
**head
;
2717 /* We must copy these reloc types into the output file.
2718 Create a reloc section in dynobj and make room for
2722 if (htab
->elf
.dynobj
== NULL
)
2723 htab
->elf
.dynobj
= abfd
;
2725 sreloc
= _bfd_elf_make_dynamic_reloc_section
2726 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2727 abfd
, /*rela?*/ TRUE
);
2733 /* If this is a global symbol, we count the number of
2734 relocations we need for this symbol. */
2736 head
= &eh
->dyn_relocs
;
2739 /* Track dynamic relocs needed for local syms too.
2740 We really need local syms available to do this
2745 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2750 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2754 /* Beware of type punned pointers vs strict aliasing
2756 vpp
= &(elf_section_data (s
)->local_dynrel
);
2757 head
= (struct elf_dyn_relocs
**)vpp
;
2761 if (p
== NULL
|| p
->sec
!= sec
)
2763 bfd_size_type amt
= sizeof *p
;
2765 p
= ((struct elf_dyn_relocs
*)
2766 bfd_alloc (htab
->elf
.dynobj
, amt
));
2777 /* Count size relocation as PC-relative relocation. */
2778 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2783 /* This relocation describes the C++ object vtable hierarchy.
2784 Reconstruct it for later use during GC. */
2785 case R_X86_64_GNU_VTINHERIT
:
2786 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2790 /* This relocation describes which C++ vtable entries are actually
2791 used. Record for later use during GC. */
2792 case R_X86_64_GNU_VTENTRY
:
2793 BFD_ASSERT (h
!= NULL
);
2795 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2805 && h
->plt
.refcount
> 0
2806 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2807 || h
->got
.refcount
> 0)
2808 && htab
->plt_got
== NULL
)
2810 /* Create the GOT procedure linkage table. */
2811 unsigned int plt_got_align
;
2812 const struct elf_backend_data
*bed
;
2814 bed
= get_elf_backend_data (info
->output_bfd
);
2815 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry
) == 8
2816 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2817 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2820 if (htab
->elf
.dynobj
== NULL
)
2821 htab
->elf
.dynobj
= abfd
;
2823 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2825 (bed
->dynamic_sec_flags
2830 if (htab
->plt_got
== NULL
2831 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2836 if (!info
->no_ld_generated_unwind_info
2837 && htab
->plt_got_eh_frame
== NULL
2838 && get_elf_x86_64_backend_data (abfd
)->eh_frame_plt_got
!= NULL
)
2840 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2841 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2842 | SEC_LINKER_CREATED
);
2843 htab
->plt_got_eh_frame
2844 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2847 if (htab
->plt_got_eh_frame
== NULL
2848 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2849 htab
->plt_got_eh_frame
,
2850 ABI_64_P (htab
->elf
.dynobj
) ? 3 : 2))
2855 if ((r_type
== R_X86_64_GOTPCREL
2856 || r_type
== R_X86_64_GOTPCRELX
2857 || r_type
== R_X86_64_REX_GOTPCRELX
)
2858 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2859 sec
->need_convert_load
= 1;
2862 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2864 if (!info
->keep_memory
)
2868 /* Cache the section contents for elf_link_input_bfd. */
2869 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2876 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2878 sec
->check_relocs_failed
= 1;
2882 /* Return the section that should be marked against GC for a given
2886 elf_x86_64_gc_mark_hook (asection
*sec
,
2887 struct bfd_link_info
*info
,
2888 Elf_Internal_Rela
*rel
,
2889 struct elf_link_hash_entry
*h
,
2890 Elf_Internal_Sym
*sym
)
2893 switch (ELF32_R_TYPE (rel
->r_info
))
2895 case R_X86_64_GNU_VTINHERIT
:
2896 case R_X86_64_GNU_VTENTRY
:
2900 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2903 /* Remove undefined weak symbol from the dynamic symbol table if it
2904 is resolved to 0. */
2907 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2908 struct elf_link_hash_entry
*h
)
2910 if (h
->dynindx
!= -1
2911 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2912 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2913 elf_x86_64_hash_entry (h
)))
2916 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2922 /* Adjust a symbol defined by a dynamic object and referenced by a
2923 regular object. The current definition is in some section of the
2924 dynamic object, but we're not including those sections. We have to
2925 change the definition to something the rest of the link can
2929 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2930 struct elf_link_hash_entry
*h
)
2932 struct elf_x86_64_link_hash_table
*htab
;
2934 struct elf_x86_64_link_hash_entry
*eh
;
2935 struct elf_dyn_relocs
*p
;
2937 /* STT_GNU_IFUNC symbol must go through PLT. */
2938 if (h
->type
== STT_GNU_IFUNC
)
2940 /* All local STT_GNU_IFUNC references must be treate as local
2941 calls via local PLT. */
2943 && SYMBOL_CALLS_LOCAL (info
, h
))
2945 bfd_size_type pc_count
= 0, count
= 0;
2946 struct elf_dyn_relocs
**pp
;
2948 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2949 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2951 pc_count
+= p
->pc_count
;
2952 p
->count
-= p
->pc_count
;
2961 if (pc_count
|| count
)
2966 /* Increment PLT reference count only for PC-relative
2969 if (h
->plt
.refcount
<= 0)
2970 h
->plt
.refcount
= 1;
2972 h
->plt
.refcount
+= 1;
2977 if (h
->plt
.refcount
<= 0)
2979 h
->plt
.offset
= (bfd_vma
) -1;
2985 /* If this is a function, put it in the procedure linkage table. We
2986 will fill in the contents of the procedure linkage table later,
2987 when we know the address of the .got section. */
2988 if (h
->type
== STT_FUNC
2991 if (h
->plt
.refcount
<= 0
2992 || SYMBOL_CALLS_LOCAL (info
, h
)
2993 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2994 && h
->root
.type
== bfd_link_hash_undefweak
))
2996 /* This case can occur if we saw a PLT32 reloc in an input
2997 file, but the symbol was never referred to by a dynamic
2998 object, or if all references were garbage collected. In
2999 such a case, we don't actually need to build a procedure
3000 linkage table, and we can just do a PC32 reloc instead. */
3001 h
->plt
.offset
= (bfd_vma
) -1;
3008 /* It's possible that we incorrectly decided a .plt reloc was
3009 needed for an R_X86_64_PC32 reloc to a non-function sym in
3010 check_relocs. We can't decide accurately between function and
3011 non-function syms in check-relocs; Objects loaded later in
3012 the link may change h->type. So fix it now. */
3013 h
->plt
.offset
= (bfd_vma
) -1;
3015 /* If this is a weak symbol, and there is a real definition, the
3016 processor independent code will have arranged for us to see the
3017 real definition first, and we can just use the same value. */
3018 if (h
->u
.weakdef
!= NULL
)
3020 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3021 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3022 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3023 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3024 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
3026 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3027 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3028 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
3033 /* This is a reference to a symbol defined by a dynamic object which
3034 is not a function. */
3036 /* If we are creating a shared library, we must presume that the
3037 only references to the symbol are via the global offset table.
3038 For such cases we need not do anything here; the relocations will
3039 be handled correctly by relocate_section. */
3040 if (!bfd_link_executable (info
))
3043 /* If there are no references to this symbol that do not use the
3044 GOT, we don't need to generate a copy reloc. */
3045 if (!h
->non_got_ref
)
3048 /* If -z nocopyreloc was given, we won't generate them either. */
3049 if (info
->nocopyreloc
)
3055 if (ELIMINATE_COPY_RELOCS
)
3057 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3058 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3060 s
= p
->sec
->output_section
;
3061 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3065 /* If we didn't find any dynamic relocs in read-only sections, then
3066 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3074 /* We must allocate the symbol in our .dynbss section, which will
3075 become part of the .bss section of the executable. There will be
3076 an entry for this symbol in the .dynsym section. The dynamic
3077 object will contain position independent code, so all references
3078 from the dynamic object to this symbol will go through the global
3079 offset table. The dynamic linker will use the .dynsym entry to
3080 determine the address it must put in the global offset table, so
3081 both the dynamic object and the regular object will refer to the
3082 same memory location for the variable. */
3084 htab
= elf_x86_64_hash_table (info
);
3088 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3089 to copy the initial value out of the dynamic object and into the
3090 runtime process image. */
3091 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3093 s
= htab
->elf
.sdynrelro
;
3094 srel
= htab
->elf
.sreldynrelro
;
3098 s
= htab
->elf
.sdynbss
;
3099 srel
= htab
->elf
.srelbss
;
3101 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3103 const struct elf_backend_data
*bed
;
3104 bed
= get_elf_backend_data (info
->output_bfd
);
3105 srel
->size
+= bed
->s
->sizeof_rela
;
3109 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3112 /* Allocate space in .plt, .got and associated reloc sections for
3116 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3118 struct bfd_link_info
*info
;
3119 struct elf_x86_64_link_hash_table
*htab
;
3120 struct elf_x86_64_link_hash_entry
*eh
;
3121 struct elf_dyn_relocs
*p
;
3122 const struct elf_backend_data
*bed
;
3123 unsigned int plt_entry_size
;
3124 bfd_boolean resolved_to_zero
;
3126 if (h
->root
.type
== bfd_link_hash_indirect
)
3129 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3131 info
= (struct bfd_link_info
*) inf
;
3132 htab
= elf_x86_64_hash_table (info
);
3135 bed
= get_elf_backend_data (info
->output_bfd
);
3136 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3138 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3142 /* We can't use the GOT PLT if pointer equality is needed since
3143 finish_dynamic_symbol won't clear symbol value and the dynamic
3144 linker won't update the GOT slot. We will get into an infinite
3145 loop at run-time. */
3146 if (htab
->plt_got
!= NULL
3147 && h
->type
!= STT_GNU_IFUNC
3148 && !h
->pointer_equality_needed
3149 && h
->plt
.refcount
> 0
3150 && h
->got
.refcount
> 0)
3152 /* Don't use the regular PLT if there are both GOT and GOTPLT
3154 h
->plt
.offset
= (bfd_vma
) -1;
3156 /* Use the GOT PLT. */
3157 eh
->plt_got
.refcount
= 1;
3160 /* Clear the reference count of function pointer relocations if
3161 symbol isn't a normal function. */
3162 if (h
->type
!= STT_FUNC
)
3163 eh
->func_pointer_refcount
= 0;
3165 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3166 here if it is defined and referenced in a non-shared object. */
3167 if (h
->type
== STT_GNU_IFUNC
3170 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3172 &htab
->readonly_dynrelocs_against_ifunc
,
3175 GOT_ENTRY_SIZE
, TRUE
))
3177 asection
*s
= htab
->plt_bnd
;
3178 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3180 /* Use the .plt.bnd section if it is created. */
3181 eh
->plt_bnd
.offset
= s
->size
;
3183 /* Make room for this entry in the .plt.bnd section. */
3184 s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3192 /* Don't create the PLT entry if there are only function pointer
3193 relocations which can be resolved at run-time. */
3194 else if (htab
->elf
.dynamic_sections_created
3195 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3196 || eh
->plt_got
.refcount
> 0))
3198 bfd_boolean use_plt_got
;
3200 /* Clear the reference count of function pointer relocations
3202 eh
->func_pointer_refcount
= 0;
3204 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
3206 /* Don't use the regular PLT for DF_BIND_NOW. */
3207 h
->plt
.offset
= (bfd_vma
) -1;
3209 /* Use the GOT PLT. */
3210 h
->got
.refcount
= 1;
3211 eh
->plt_got
.refcount
= 1;
3214 use_plt_got
= eh
->plt_got
.refcount
> 0;
3216 /* Make sure this symbol is output as a dynamic symbol.
3217 Undefined weak syms won't yet be marked as dynamic. */
3218 if (h
->dynindx
== -1
3220 && !resolved_to_zero
)
3222 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3226 if (bfd_link_pic (info
)
3227 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3229 asection
*s
= htab
->elf
.splt
;
3230 asection
*bnd_s
= htab
->plt_bnd
;
3231 asection
*got_s
= htab
->plt_got
;
3233 /* If this is the first .plt entry, make room for the special
3234 first entry. The .plt section is used by prelink to undo
3235 prelinking for dynamic relocations. */
3237 s
->size
= plt_entry_size
;
3240 eh
->plt_got
.offset
= got_s
->size
;
3243 h
->plt
.offset
= s
->size
;
3245 eh
->plt_bnd
.offset
= bnd_s
->size
;
3248 /* If this symbol is not defined in a regular file, and we are
3249 not generating a shared library, then set the symbol to this
3250 location in the .plt. This is required to make function
3251 pointers compare as equal between the normal executable and
3252 the shared library. */
3253 if (! bfd_link_pic (info
)
3258 /* We need to make a call to the entry of the GOT PLT
3259 instead of regular PLT entry. */
3260 h
->root
.u
.def
.section
= got_s
;
3261 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3267 /* We need to make a call to the entry of the second
3268 PLT instead of regular PLT entry. */
3269 h
->root
.u
.def
.section
= bnd_s
;
3270 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
3274 h
->root
.u
.def
.section
= s
;
3275 h
->root
.u
.def
.value
= h
->plt
.offset
;
3280 /* Make room for this entry. */
3282 got_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3285 s
->size
+= plt_entry_size
;
3287 bnd_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3289 /* We also need to make an entry in the .got.plt section,
3290 which will be placed in the .got section by the linker
3292 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3294 /* There should be no PLT relocation against resolved
3295 undefined weak symbol in executable. */
3296 if (!resolved_to_zero
)
3298 /* We also need to make an entry in the .rela.plt
3300 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3301 htab
->elf
.srelplt
->reloc_count
++;
3307 eh
->plt_got
.offset
= (bfd_vma
) -1;
3308 h
->plt
.offset
= (bfd_vma
) -1;
3314 eh
->plt_got
.offset
= (bfd_vma
) -1;
3315 h
->plt
.offset
= (bfd_vma
) -1;
3319 eh
->tlsdesc_got
= (bfd_vma
) -1;
3321 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3322 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3323 if (h
->got
.refcount
> 0
3324 && bfd_link_executable (info
)
3326 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3328 h
->got
.offset
= (bfd_vma
) -1;
3330 else if (h
->got
.refcount
> 0)
3334 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3336 /* Make sure this symbol is output as a dynamic symbol.
3337 Undefined weak syms won't yet be marked as dynamic. */
3338 if (h
->dynindx
== -1
3340 && !resolved_to_zero
)
3342 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3346 if (GOT_TLS_GDESC_P (tls_type
))
3348 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3349 - elf_x86_64_compute_jump_table_size (htab
);
3350 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3351 h
->got
.offset
= (bfd_vma
) -2;
3353 if (! GOT_TLS_GDESC_P (tls_type
)
3354 || GOT_TLS_GD_P (tls_type
))
3357 h
->got
.offset
= s
->size
;
3358 s
->size
+= GOT_ENTRY_SIZE
;
3359 if (GOT_TLS_GD_P (tls_type
))
3360 s
->size
+= GOT_ENTRY_SIZE
;
3362 dyn
= htab
->elf
.dynamic_sections_created
;
3363 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3364 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3365 relocation. No dynamic relocation against resolved undefined
3366 weak symbol in executable. */
3367 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3368 || tls_type
== GOT_TLS_IE
)
3369 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3370 else if (GOT_TLS_GD_P (tls_type
))
3371 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3372 else if (! GOT_TLS_GDESC_P (tls_type
)
3373 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3374 && !resolved_to_zero
)
3375 || h
->root
.type
!= bfd_link_hash_undefweak
)
3376 && (bfd_link_pic (info
)
3377 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3378 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3379 if (GOT_TLS_GDESC_P (tls_type
))
3381 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3382 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3386 h
->got
.offset
= (bfd_vma
) -1;
3388 if (eh
->dyn_relocs
== NULL
)
3391 /* In the shared -Bsymbolic case, discard space allocated for
3392 dynamic pc-relative relocs against symbols which turn out to be
3393 defined in regular objects. For the normal shared case, discard
3394 space for pc-relative relocs that have become local due to symbol
3395 visibility changes. */
3397 if (bfd_link_pic (info
))
3399 /* Relocs that use pc_count are those that appear on a call
3400 insn, or certain REL relocs that can generated via assembly.
3401 We want calls to protected symbols to resolve directly to the
3402 function rather than going via the plt. If people want
3403 function pointer comparisons to work as expected then they
3404 should avoid writing weird assembly. */
3405 if (SYMBOL_CALLS_LOCAL (info
, h
))
3407 struct elf_dyn_relocs
**pp
;
3409 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3411 p
->count
-= p
->pc_count
;
3420 /* Also discard relocs on undefined weak syms with non-default
3421 visibility or in PIE. */
3422 if (eh
->dyn_relocs
!= NULL
)
3424 if (h
->root
.type
== bfd_link_hash_undefweak
)
3426 /* Undefined weak symbol is never bound locally in shared
3428 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3429 || resolved_to_zero
)
3430 eh
->dyn_relocs
= NULL
;
3431 else if (h
->dynindx
== -1
3432 && ! h
->forced_local
3433 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3436 /* For PIE, discard space for pc-relative relocs against
3437 symbols which turn out to need copy relocs. */
3438 else if (bfd_link_executable (info
)
3439 && (h
->needs_copy
|| eh
->needs_copy
)
3443 struct elf_dyn_relocs
**pp
;
3445 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3447 if (p
->pc_count
!= 0)
3455 else if (ELIMINATE_COPY_RELOCS
)
3457 /* For the non-shared case, discard space for relocs against
3458 symbols which turn out to need copy relocs or are not
3459 dynamic. Keep dynamic relocations for run-time function
3460 pointer initialization. */
3462 if ((!h
->non_got_ref
3463 || eh
->func_pointer_refcount
> 0
3464 || (h
->root
.type
== bfd_link_hash_undefweak
3465 && !resolved_to_zero
))
3468 || (htab
->elf
.dynamic_sections_created
3469 && (h
->root
.type
== bfd_link_hash_undefweak
3470 || h
->root
.type
== bfd_link_hash_undefined
))))
3472 /* Make sure this symbol is output as a dynamic symbol.
3473 Undefined weak syms won't yet be marked as dynamic. */
3474 if (h
->dynindx
== -1
3475 && ! h
->forced_local
3476 && ! resolved_to_zero
3477 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3480 /* If that succeeded, we know we'll be keeping all the
3482 if (h
->dynindx
!= -1)
3486 eh
->dyn_relocs
= NULL
;
3487 eh
->func_pointer_refcount
= 0;
3492 /* Finally, allocate space. */
3493 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3497 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3499 BFD_ASSERT (sreloc
!= NULL
);
3501 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3507 /* Allocate space in .plt, .got and associated reloc sections for
3508 local dynamic relocs. */
3511 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3513 struct elf_link_hash_entry
*h
3514 = (struct elf_link_hash_entry
*) *slot
;
3516 if (h
->type
!= STT_GNU_IFUNC
3520 || h
->root
.type
!= bfd_link_hash_defined
)
3523 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3526 /* Find any dynamic relocs that apply to read-only sections. */
3529 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3532 struct elf_x86_64_link_hash_entry
*eh
;
3533 struct elf_dyn_relocs
*p
;
3535 /* Skip local IFUNC symbols. */
3536 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3539 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3540 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3542 asection
*s
= p
->sec
->output_section
;
3544 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3546 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3548 info
->flags
|= DF_TEXTREL
;
3550 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3551 || info
->error_textrel
)
3552 /* xgettext:c-format */
3553 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3554 p
->sec
->owner
, h
->root
.root
.string
,
3557 /* Not an error, just cut short the traversal. */
3564 /* Convert load via the GOT slot to load immediate. */
3567 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3568 struct bfd_link_info
*link_info
)
3570 Elf_Internal_Shdr
*symtab_hdr
;
3571 Elf_Internal_Rela
*internal_relocs
;
3572 Elf_Internal_Rela
*irel
, *irelend
;
3574 struct elf_x86_64_link_hash_table
*htab
;
3575 bfd_boolean changed
;
3576 bfd_signed_vma
*local_got_refcounts
;
3578 /* Don't even try to convert non-ELF outputs. */
3579 if (!is_elf_hash_table (link_info
->hash
))
3582 /* Nothing to do if there is no need or no output. */
3583 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3584 || sec
->need_convert_load
== 0
3585 || bfd_is_abs_section (sec
->output_section
))
3588 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3590 /* Load the relocations for this section. */
3591 internal_relocs
= (_bfd_elf_link_read_relocs
3592 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3593 link_info
->keep_memory
));
3594 if (internal_relocs
== NULL
)
3598 htab
= elf_x86_64_hash_table (link_info
);
3599 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3601 /* Get the section contents. */
3602 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3603 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3606 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3610 irelend
= internal_relocs
+ sec
->reloc_count
;
3611 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3613 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3614 unsigned int r_symndx
;
3615 struct elf_link_hash_entry
*h
;
3616 bfd_boolean converted
;
3618 if (r_type
!= R_X86_64_GOTPCRELX
3619 && r_type
!= R_X86_64_REX_GOTPCRELX
3620 && r_type
!= R_X86_64_GOTPCREL
)
3623 r_symndx
= htab
->r_sym (irel
->r_info
);
3624 if (r_symndx
< symtab_hdr
->sh_info
)
3625 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3626 (const Elf_Internal_Rela
*) irel
,
3630 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3631 while (h
->root
.type
== bfd_link_hash_indirect
3632 || h
->root
.type
== bfd_link_hash_warning
)
3633 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3636 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3637 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3641 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3642 &converted
, link_info
))
3647 changed
= converted
;
3650 if (h
->got
.refcount
> 0)
3651 h
->got
.refcount
-= 1;
3655 if (local_got_refcounts
!= NULL
3656 && local_got_refcounts
[r_symndx
] > 0)
3657 local_got_refcounts
[r_symndx
] -= 1;
3662 if (contents
!= NULL
3663 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3665 if (!changed
&& !link_info
->keep_memory
)
3669 /* Cache the section contents for elf_link_input_bfd. */
3670 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3674 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3677 free (internal_relocs
);
3679 elf_section_data (sec
)->relocs
= internal_relocs
;
3685 if (contents
!= NULL
3686 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3688 if (internal_relocs
!= NULL
3689 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3690 free (internal_relocs
);
3694 /* Set the sizes of the dynamic sections. */
3697 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3698 struct bfd_link_info
*info
)
3700 struct elf_x86_64_link_hash_table
*htab
;
3705 const struct elf_backend_data
*bed
;
3706 const struct elf_x86_64_backend_data
*arch_data
;
3708 htab
= elf_x86_64_hash_table (info
);
3711 bed
= get_elf_backend_data (output_bfd
);
3713 dynobj
= htab
->elf
.dynobj
;
3717 /* Set up .got offsets for local syms, and space for local dynamic
3719 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3721 bfd_signed_vma
*local_got
;
3722 bfd_signed_vma
*end_local_got
;
3723 char *local_tls_type
;
3724 bfd_vma
*local_tlsdesc_gotent
;
3725 bfd_size_type locsymcount
;
3726 Elf_Internal_Shdr
*symtab_hdr
;
3729 if (! is_x86_64_elf (ibfd
))
3732 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3734 struct elf_dyn_relocs
*p
;
3736 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3739 for (p
= (struct elf_dyn_relocs
*)
3740 (elf_section_data (s
)->local_dynrel
);
3744 if (!bfd_is_abs_section (p
->sec
)
3745 && bfd_is_abs_section (p
->sec
->output_section
))
3747 /* Input section has been discarded, either because
3748 it is a copy of a linkonce section or due to
3749 linker script /DISCARD/, so we'll be discarding
3752 else if (p
->count
!= 0)
3754 srel
= elf_section_data (p
->sec
)->sreloc
;
3755 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3756 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3757 && (info
->flags
& DF_TEXTREL
) == 0)
3759 info
->flags
|= DF_TEXTREL
;
3760 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3761 || info
->error_textrel
)
3762 /* xgettext:c-format */
3763 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3764 p
->sec
->owner
, p
->sec
);
3770 local_got
= elf_local_got_refcounts (ibfd
);
3774 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3775 locsymcount
= symtab_hdr
->sh_info
;
3776 end_local_got
= local_got
+ locsymcount
;
3777 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3778 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3780 srel
= htab
->elf
.srelgot
;
3781 for (; local_got
< end_local_got
;
3782 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3784 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3787 if (GOT_TLS_GDESC_P (*local_tls_type
))
3789 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3790 - elf_x86_64_compute_jump_table_size (htab
);
3791 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3792 *local_got
= (bfd_vma
) -2;
3794 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3795 || GOT_TLS_GD_P (*local_tls_type
))
3797 *local_got
= s
->size
;
3798 s
->size
+= GOT_ENTRY_SIZE
;
3799 if (GOT_TLS_GD_P (*local_tls_type
))
3800 s
->size
+= GOT_ENTRY_SIZE
;
3802 if (bfd_link_pic (info
)
3803 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3804 || *local_tls_type
== GOT_TLS_IE
)
3806 if (GOT_TLS_GDESC_P (*local_tls_type
))
3808 htab
->elf
.srelplt
->size
3809 += bed
->s
->sizeof_rela
;
3810 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3812 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3813 || GOT_TLS_GD_P (*local_tls_type
))
3814 srel
->size
+= bed
->s
->sizeof_rela
;
3818 *local_got
= (bfd_vma
) -1;
3822 if (htab
->tls_ld_got
.refcount
> 0)
3824 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3826 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3827 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3828 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3831 htab
->tls_ld_got
.offset
= -1;
3833 /* Allocate global sym .plt and .got entries, and space for global
3834 sym dynamic relocs. */
3835 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3838 /* Allocate .plt and .got entries, and space for local symbols. */
3839 htab_traverse (htab
->loc_hash_table
,
3840 elf_x86_64_allocate_local_dynrelocs
,
3843 /* For every jump slot reserved in the sgotplt, reloc_count is
3844 incremented. However, when we reserve space for TLS descriptors,
3845 it's not incremented, so in order to compute the space reserved
3846 for them, it suffices to multiply the reloc count by the jump
3849 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3850 so that R_X86_64_IRELATIVE entries come last. */
3851 if (htab
->elf
.srelplt
)
3853 htab
->sgotplt_jump_table_size
3854 = elf_x86_64_compute_jump_table_size (htab
);
3855 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3857 else if (htab
->elf
.irelplt
)
3858 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3860 if (htab
->tlsdesc_plt
)
3862 /* If we're not using lazy TLS relocations, don't generate the
3863 PLT and GOT entries they require. */
3864 if ((info
->flags
& DF_BIND_NOW
))
3865 htab
->tlsdesc_plt
= 0;
3868 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3869 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3870 /* Reserve room for the initial entry.
3871 FIXME: we could probably do away with it in this case. */
3872 if (htab
->elf
.splt
->size
== 0)
3873 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3874 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3875 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3879 if (htab
->elf
.sgotplt
)
3881 /* Don't allocate .got.plt section if there are no GOT nor PLT
3882 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3883 if ((htab
->elf
.hgot
== NULL
3884 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3885 && (htab
->elf
.sgotplt
->size
3886 == get_elf_backend_data (output_bfd
)->got_header_size
)
3887 && (htab
->elf
.splt
== NULL
3888 || htab
->elf
.splt
->size
== 0)
3889 && (htab
->elf
.sgot
== NULL
3890 || htab
->elf
.sgot
->size
== 0)
3891 && (htab
->elf
.iplt
== NULL
3892 || htab
->elf
.iplt
->size
== 0)
3893 && (htab
->elf
.igotplt
== NULL
3894 || htab
->elf
.igotplt
->size
== 0))
3895 htab
->elf
.sgotplt
->size
= 0;
3898 arch_data
= (htab
->plt_bnd
!= NULL
3899 ? &elf_x86_64_bnd_arch_bed
3900 : get_elf_x86_64_arch_data (bed
));
3902 if (_bfd_elf_eh_frame_present (info
))
3904 if (htab
->plt_eh_frame
!= NULL
3905 && htab
->elf
.splt
!= NULL
3906 && htab
->elf
.splt
->size
!= 0
3907 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3908 htab
->plt_eh_frame
->size
= arch_data
->eh_frame_plt_size
;
3910 if (htab
->plt_got_eh_frame
!= NULL
3911 && htab
->plt_got
!= NULL
3912 && htab
->plt_got
->size
!= 0
3913 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3914 htab
->plt_got_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3916 /* Unwind info for .plt.bnd and .plt.got sections are
3918 if (htab
->plt_bnd_eh_frame
!= NULL
3919 && htab
->plt_bnd
!= NULL
3920 && htab
->plt_bnd
->size
!= 0
3921 && !bfd_is_abs_section (htab
->plt_bnd
->output_section
))
3922 htab
->plt_bnd_eh_frame
->size
= arch_data
->eh_frame_plt_got_size
;
3925 /* We now have determined the sizes of the various dynamic sections.
3926 Allocate memory for them. */
3928 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3930 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3933 if (s
== htab
->elf
.splt
3934 || s
== htab
->elf
.sgot
3935 || s
== htab
->elf
.sgotplt
3936 || s
== htab
->elf
.iplt
3937 || s
== htab
->elf
.igotplt
3938 || s
== htab
->plt_bnd
3939 || s
== htab
->plt_got
3940 || s
== htab
->plt_eh_frame
3941 || s
== htab
->plt_got_eh_frame
3942 || s
== htab
->plt_bnd_eh_frame
3943 || s
== htab
->elf
.sdynbss
3944 || s
== htab
->elf
.sdynrelro
)
3946 /* Strip this section if we don't need it; see the
3949 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3951 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3954 /* We use the reloc_count field as a counter if we need
3955 to copy relocs into the output file. */
3956 if (s
!= htab
->elf
.srelplt
)
3961 /* It's not one of our sections, so don't allocate space. */
3967 /* If we don't need this section, strip it from the
3968 output file. This is mostly to handle .rela.bss and
3969 .rela.plt. We must create both sections in
3970 create_dynamic_sections, because they must be created
3971 before the linker maps input sections to output
3972 sections. The linker does that before
3973 adjust_dynamic_symbol is called, and it is that
3974 function which decides whether anything needs to go
3975 into these sections. */
3977 s
->flags
|= SEC_EXCLUDE
;
3981 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3984 /* Allocate memory for the section contents. We use bfd_zalloc
3985 here in case unused entries are not reclaimed before the
3986 section's contents are written out. This should not happen,
3987 but this way if it does, we get a R_X86_64_NONE reloc instead
3989 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3990 if (s
->contents
== NULL
)
3994 if (htab
->plt_eh_frame
!= NULL
3995 && htab
->plt_eh_frame
->contents
!= NULL
)
3997 memcpy (htab
->plt_eh_frame
->contents
,
3998 arch_data
->eh_frame_plt
, htab
->plt_eh_frame
->size
);
3999 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
4000 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
4003 if (htab
->plt_got_eh_frame
!= NULL
4004 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4006 memcpy (htab
->plt_got_eh_frame
->contents
,
4007 arch_data
->eh_frame_plt_got
,
4008 htab
->plt_got_eh_frame
->size
);
4009 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
4010 (htab
->plt_got_eh_frame
->contents
4011 + PLT_FDE_LEN_OFFSET
));
4014 if (htab
->plt_bnd_eh_frame
!= NULL
4015 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
4017 memcpy (htab
->plt_bnd_eh_frame
->contents
,
4018 arch_data
->eh_frame_plt_got
,
4019 htab
->plt_bnd_eh_frame
->size
);
4020 bfd_put_32 (dynobj
, htab
->plt_bnd
->size
,
4021 (htab
->plt_bnd_eh_frame
->contents
4022 + PLT_FDE_LEN_OFFSET
));
4025 if (htab
->elf
.dynamic_sections_created
)
4027 /* Add some entries to the .dynamic section. We fill in the
4028 values later, in elf_x86_64_finish_dynamic_sections, but we
4029 must add the entries now so that we get the correct size for
4030 the .dynamic section. The DT_DEBUG entry is filled in by the
4031 dynamic linker and used by the debugger. */
4032 #define add_dynamic_entry(TAG, VAL) \
4033 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4035 if (bfd_link_executable (info
))
4037 if (!add_dynamic_entry (DT_DEBUG
, 0))
4041 if (htab
->elf
.splt
->size
!= 0)
4043 /* DT_PLTGOT is used by prelink even if there is no PLT
4045 if (!add_dynamic_entry (DT_PLTGOT
, 0))
4048 if (htab
->elf
.srelplt
->size
!= 0)
4050 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
4051 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4052 || !add_dynamic_entry (DT_JMPREL
, 0))
4056 if (htab
->tlsdesc_plt
4057 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
4058 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
4064 if (!add_dynamic_entry (DT_RELA
, 0)
4065 || !add_dynamic_entry (DT_RELASZ
, 0)
4066 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
4069 /* If any dynamic relocs apply to a read-only section,
4070 then we need a DT_TEXTREL entry. */
4071 if ((info
->flags
& DF_TEXTREL
) == 0)
4072 elf_link_hash_traverse (&htab
->elf
,
4073 elf_x86_64_readonly_dynrelocs
,
4076 if ((info
->flags
& DF_TEXTREL
) != 0)
4078 if (htab
->readonly_dynrelocs_against_ifunc
)
4080 info
->callbacks
->einfo
4081 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4082 bfd_set_error (bfd_error_bad_value
);
4086 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4091 #undef add_dynamic_entry
4097 elf_x86_64_always_size_sections (bfd
*output_bfd
,
4098 struct bfd_link_info
*info
)
4100 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
4104 struct elf_link_hash_entry
*tlsbase
;
4106 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
4107 "_TLS_MODULE_BASE_",
4108 FALSE
, FALSE
, FALSE
);
4110 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
4112 struct elf_x86_64_link_hash_table
*htab
;
4113 struct bfd_link_hash_entry
*bh
= NULL
;
4114 const struct elf_backend_data
*bed
4115 = get_elf_backend_data (output_bfd
);
4117 htab
= elf_x86_64_hash_table (info
);
4121 if (!(_bfd_generic_link_add_one_symbol
4122 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
4123 tls_sec
, 0, NULL
, FALSE
,
4124 bed
->collect
, &bh
)))
4127 htab
->tls_module_base
= bh
;
4129 tlsbase
= (struct elf_link_hash_entry
*)bh
;
4130 tlsbase
->def_regular
= 1;
4131 tlsbase
->other
= STV_HIDDEN
;
4132 tlsbase
->root
.linker_def
= 1;
4133 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4140 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4141 executables. Rather than setting it to the beginning of the TLS
4142 section, we have to set it to the end. This function may be called
4143 multiple times, it is idempotent. */
4146 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4148 struct elf_x86_64_link_hash_table
*htab
;
4149 struct bfd_link_hash_entry
*base
;
4151 if (!bfd_link_executable (info
))
4154 htab
= elf_x86_64_hash_table (info
);
4158 base
= htab
->tls_module_base
;
4162 base
->u
.def
.value
= htab
->elf
.tls_size
;
4165 /* Return the base VMA address which should be subtracted from real addresses
4166 when resolving @dtpoff relocation.
4167 This is PT_TLS segment p_vaddr. */
4170 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4172 /* If tls_sec is NULL, we should have signalled an error already. */
4173 if (elf_hash_table (info
)->tls_sec
== NULL
)
4175 return elf_hash_table (info
)->tls_sec
->vma
;
4178 /* Return the relocation value for @tpoff relocation
4179 if STT_TLS virtual address is ADDRESS. */
4182 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4184 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4185 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4186 bfd_vma static_tls_size
;
4188 /* If tls_segment is NULL, we should have signalled an error already. */
4189 if (htab
->tls_sec
== NULL
)
4192 /* Consider special static TLS alignment requirements. */
4193 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4194 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4197 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4201 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4203 /* Opcode Instruction
4206 0x0f 0x8x conditional jump */
4208 && (contents
[offset
- 1] == 0xe8
4209 || contents
[offset
- 1] == 0xe9))
4211 && contents
[offset
- 2] == 0x0f
4212 && (contents
[offset
- 1] & 0xf0) == 0x80));
4215 /* Relocate an x86_64 ELF section. */
4218 elf_x86_64_relocate_section (bfd
*output_bfd
,
4219 struct bfd_link_info
*info
,
4221 asection
*input_section
,
4223 Elf_Internal_Rela
*relocs
,
4224 Elf_Internal_Sym
*local_syms
,
4225 asection
**local_sections
)
4227 struct elf_x86_64_link_hash_table
*htab
;
4228 Elf_Internal_Shdr
*symtab_hdr
;
4229 struct elf_link_hash_entry
**sym_hashes
;
4230 bfd_vma
*local_got_offsets
;
4231 bfd_vma
*local_tlsdesc_gotents
;
4232 Elf_Internal_Rela
*rel
;
4233 Elf_Internal_Rela
*wrel
;
4234 Elf_Internal_Rela
*relend
;
4235 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
4237 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4239 /* Skip if check_relocs failed. */
4240 if (input_section
->check_relocs_failed
)
4243 htab
= elf_x86_64_hash_table (info
);
4246 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4247 sym_hashes
= elf_sym_hashes (input_bfd
);
4248 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4249 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4251 elf_x86_64_set_tls_module_base (info
);
4253 rel
= wrel
= relocs
;
4254 relend
= relocs
+ input_section
->reloc_count
;
4255 for (; rel
< relend
; wrel
++, rel
++)
4257 unsigned int r_type
;
4258 reloc_howto_type
*howto
;
4259 unsigned long r_symndx
;
4260 struct elf_link_hash_entry
*h
;
4261 struct elf_x86_64_link_hash_entry
*eh
;
4262 Elf_Internal_Sym
*sym
;
4264 bfd_vma off
, offplt
, plt_offset
;
4266 bfd_boolean unresolved_reloc
;
4267 bfd_reloc_status_type r
;
4269 asection
*base_got
, *resolved_plt
;
4271 bfd_boolean resolved_to_zero
;
4273 r_type
= ELF32_R_TYPE (rel
->r_info
);
4274 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4275 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4282 if (r_type
>= (int) R_X86_64_standard
)
4285 /* xgettext:c-format */
4286 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4287 input_bfd
, input_section
, r_type
);
4288 bfd_set_error (bfd_error_bad_value
);
4292 if (r_type
!= (int) R_X86_64_32
4293 || ABI_64_P (output_bfd
))
4294 howto
= x86_64_elf_howto_table
+ r_type
;
4296 howto
= (x86_64_elf_howto_table
4297 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4298 r_symndx
= htab
->r_sym (rel
->r_info
);
4302 unresolved_reloc
= FALSE
;
4303 if (r_symndx
< symtab_hdr
->sh_info
)
4305 sym
= local_syms
+ r_symndx
;
4306 sec
= local_sections
[r_symndx
];
4308 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4310 st_size
= sym
->st_size
;
4312 /* Relocate against local STT_GNU_IFUNC symbol. */
4313 if (!bfd_link_relocatable (info
)
4314 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4316 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4321 /* Set STT_GNU_IFUNC symbol value. */
4322 h
->root
.u
.def
.value
= sym
->st_value
;
4323 h
->root
.u
.def
.section
= sec
;
4328 bfd_boolean warned ATTRIBUTE_UNUSED
;
4329 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4331 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4332 r_symndx
, symtab_hdr
, sym_hashes
,
4334 unresolved_reloc
, warned
, ignored
);
4338 if (sec
!= NULL
&& discarded_section (sec
))
4340 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4341 contents
+ rel
->r_offset
);
4342 wrel
->r_offset
= rel
->r_offset
;
4346 /* For ld -r, remove relocations in debug sections against
4347 sections defined in discarded sections. Not done for
4348 eh_frame editing code expects to be present. */
4349 if (bfd_link_relocatable (info
)
4350 && (input_section
->flags
& SEC_DEBUGGING
))
4356 if (bfd_link_relocatable (info
))
4363 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4365 if (r_type
== R_X86_64_64
)
4367 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4368 zero-extend it to 64bit if addend is zero. */
4369 r_type
= R_X86_64_32
;
4370 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4372 else if (r_type
== R_X86_64_SIZE64
)
4374 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4375 zero-extend it to 64bit if addend is zero. */
4376 r_type
= R_X86_64_SIZE32
;
4377 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4381 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4383 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4384 it here if it is defined in a non-shared object. */
4386 && h
->type
== STT_GNU_IFUNC
4392 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4394 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4395 sections because such sections are not SEC_ALLOC and
4396 thus ld.so will not process them. */
4397 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4407 case R_X86_64_GOTPCREL
:
4408 case R_X86_64_GOTPCRELX
:
4409 case R_X86_64_REX_GOTPCRELX
:
4410 case R_X86_64_GOTPCREL64
:
4411 base_got
= htab
->elf
.sgot
;
4412 off
= h
->got
.offset
;
4414 if (base_got
== NULL
)
4417 if (off
== (bfd_vma
) -1)
4419 /* We can't use h->got.offset here to save state, or
4420 even just remember the offset, as finish_dynamic_symbol
4421 would use that as offset into .got. */
4423 if (h
->plt
.offset
== (bfd_vma
) -1)
4426 if (htab
->elf
.splt
!= NULL
)
4428 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4429 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4430 base_got
= htab
->elf
.sgotplt
;
4434 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4435 off
= plt_index
* GOT_ENTRY_SIZE
;
4436 base_got
= htab
->elf
.igotplt
;
4439 if (h
->dynindx
== -1
4443 /* This references the local defitionion. We must
4444 initialize this entry in the global offset table.
4445 Since the offset must always be a multiple of 8,
4446 we use the least significant bit to record
4447 whether we have initialized it already.
4449 When doing a dynamic link, we create a .rela.got
4450 relocation entry to initialize the value. This
4451 is done in the finish_dynamic_symbol routine. */
4456 bfd_put_64 (output_bfd
, relocation
,
4457 base_got
->contents
+ off
);
4458 /* Note that this is harmless for the GOTPLT64
4459 case, as -1 | 1 still is -1. */
4465 relocation
= (base_got
->output_section
->vma
4466 + base_got
->output_offset
+ off
);
4471 if (h
->plt
.offset
== (bfd_vma
) -1)
4473 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4474 if (r_type
== htab
->pointer_r_type
4475 && (input_section
->flags
& SEC_CODE
) == 0)
4476 goto do_ifunc_pointer
;
4477 goto bad_ifunc_reloc
;
4480 /* STT_GNU_IFUNC symbol must go through PLT. */
4481 if (htab
->elf
.splt
!= NULL
)
4483 if (htab
->plt_bnd
!= NULL
)
4485 resolved_plt
= htab
->plt_bnd
;
4486 plt_offset
= eh
->plt_bnd
.offset
;
4490 resolved_plt
= htab
->elf
.splt
;
4491 plt_offset
= h
->plt
.offset
;
4496 resolved_plt
= htab
->elf
.iplt
;
4497 plt_offset
= h
->plt
.offset
;
4500 relocation
= (resolved_plt
->output_section
->vma
4501 + resolved_plt
->output_offset
+ plt_offset
);
4507 if (h
->root
.root
.string
)
4508 name
= h
->root
.root
.string
;
4510 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4513 /* xgettext:c-format */
4514 (_("%B: relocation %s against STT_GNU_IFUNC "
4515 "symbol `%s' isn't supported"), input_bfd
,
4517 bfd_set_error (bfd_error_bad_value
);
4521 if (bfd_link_pic (info
))
4526 if (ABI_64_P (output_bfd
))
4531 if (rel
->r_addend
!= 0)
4533 if (h
->root
.root
.string
)
4534 name
= h
->root
.root
.string
;
4536 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4539 /* xgettext:c-format */
4540 (_("%B: relocation %s against STT_GNU_IFUNC "
4541 "symbol `%s' has non-zero addend: %d"),
4542 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4543 bfd_set_error (bfd_error_bad_value
);
4547 /* Generate dynamic relcoation only when there is a
4548 non-GOT reference in a shared object or there is no
4550 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4551 || h
->plt
.offset
== (bfd_vma
) -1)
4553 Elf_Internal_Rela outrel
;
4556 /* Need a dynamic relocation to get the real function
4558 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4562 if (outrel
.r_offset
== (bfd_vma
) -1
4563 || outrel
.r_offset
== (bfd_vma
) -2)
4566 outrel
.r_offset
+= (input_section
->output_section
->vma
4567 + input_section
->output_offset
);
4569 if (h
->dynindx
== -1
4571 || bfd_link_executable (info
))
4573 /* This symbol is resolved locally. */
4574 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4575 outrel
.r_addend
= (h
->root
.u
.def
.value
4576 + h
->root
.u
.def
.section
->output_section
->vma
4577 + h
->root
.u
.def
.section
->output_offset
);
4581 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4582 outrel
.r_addend
= 0;
4585 /* Dynamic relocations are stored in
4586 1. .rela.ifunc section in PIC object.
4587 2. .rela.got section in dynamic executable.
4588 3. .rela.iplt section in static executable. */
4589 if (bfd_link_pic (info
))
4590 sreloc
= htab
->elf
.irelifunc
;
4591 else if (htab
->elf
.splt
!= NULL
)
4592 sreloc
= htab
->elf
.srelgot
;
4594 sreloc
= htab
->elf
.irelplt
;
4595 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4597 /* If this reloc is against an external symbol, we
4598 do not want to fiddle with the addend. Otherwise,
4599 we need to include the symbol value so that it
4600 becomes an addend for the dynamic reloc. For an
4601 internal symbol, we have updated addend. */
4606 case R_X86_64_PC32_BND
:
4608 case R_X86_64_PLT32
:
4609 case R_X86_64_PLT32_BND
:
4614 resolved_to_zero
= (eh
!= NULL
4615 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4619 /* When generating a shared object, the relocations handled here are
4620 copied into the output file to be resolved at run time. */
4623 case R_X86_64_GOT32
:
4624 case R_X86_64_GOT64
:
4625 /* Relocation is to the entry for this symbol in the global
4627 case R_X86_64_GOTPCREL
:
4628 case R_X86_64_GOTPCRELX
:
4629 case R_X86_64_REX_GOTPCRELX
:
4630 case R_X86_64_GOTPCREL64
:
4631 /* Use global offset table entry as symbol value. */
4632 case R_X86_64_GOTPLT64
:
4633 /* This is obsolete and treated the the same as GOT64. */
4634 base_got
= htab
->elf
.sgot
;
4636 if (htab
->elf
.sgot
== NULL
)
4643 off
= h
->got
.offset
;
4645 && h
->plt
.offset
!= (bfd_vma
)-1
4646 && off
== (bfd_vma
)-1)
4648 /* We can't use h->got.offset here to save
4649 state, or even just remember the offset, as
4650 finish_dynamic_symbol would use that as offset into
4652 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4653 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4654 base_got
= htab
->elf
.sgotplt
;
4657 dyn
= htab
->elf
.dynamic_sections_created
;
4659 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4660 || (bfd_link_pic (info
)
4661 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4662 || (ELF_ST_VISIBILITY (h
->other
)
4663 && h
->root
.type
== bfd_link_hash_undefweak
))
4665 /* This is actually a static link, or it is a -Bsymbolic
4666 link and the symbol is defined locally, or the symbol
4667 was forced to be local because of a version file. We
4668 must initialize this entry in the global offset table.
4669 Since the offset must always be a multiple of 8, we
4670 use the least significant bit to record whether we
4671 have initialized it already.
4673 When doing a dynamic link, we create a .rela.got
4674 relocation entry to initialize the value. This is
4675 done in the finish_dynamic_symbol routine. */
4680 bfd_put_64 (output_bfd
, relocation
,
4681 base_got
->contents
+ off
);
4682 /* Note that this is harmless for the GOTPLT64 case,
4683 as -1 | 1 still is -1. */
4688 unresolved_reloc
= FALSE
;
4692 if (local_got_offsets
== NULL
)
4695 off
= local_got_offsets
[r_symndx
];
4697 /* The offset must always be a multiple of 8. We use
4698 the least significant bit to record whether we have
4699 already generated the necessary reloc. */
4704 bfd_put_64 (output_bfd
, relocation
,
4705 base_got
->contents
+ off
);
4707 if (bfd_link_pic (info
))
4710 Elf_Internal_Rela outrel
;
4712 /* We need to generate a R_X86_64_RELATIVE reloc
4713 for the dynamic linker. */
4714 s
= htab
->elf
.srelgot
;
4718 outrel
.r_offset
= (base_got
->output_section
->vma
4719 + base_got
->output_offset
4721 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4722 outrel
.r_addend
= relocation
;
4723 elf_append_rela (output_bfd
, s
, &outrel
);
4726 local_got_offsets
[r_symndx
] |= 1;
4730 if (off
>= (bfd_vma
) -2)
4733 relocation
= base_got
->output_section
->vma
4734 + base_got
->output_offset
+ off
;
4735 if (r_type
!= R_X86_64_GOTPCREL
4736 && r_type
!= R_X86_64_GOTPCRELX
4737 && r_type
!= R_X86_64_REX_GOTPCRELX
4738 && r_type
!= R_X86_64_GOTPCREL64
)
4739 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4740 - htab
->elf
.sgotplt
->output_offset
;
4744 case R_X86_64_GOTOFF64
:
4745 /* Relocation is relative to the start of the global offset
4748 /* Check to make sure it isn't a protected function or data
4749 symbol for shared library since it may not be local when
4750 used as function address or with copy relocation. We also
4751 need to make sure that a symbol is referenced locally. */
4752 if (bfd_link_pic (info
) && h
)
4754 if (!h
->def_regular
)
4758 switch (ELF_ST_VISIBILITY (h
->other
))
4761 v
= _("hidden symbol");
4764 v
= _("internal symbol");
4767 v
= _("protected symbol");
4775 /* xgettext:c-format */
4776 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s `%s' can not be used when making a shared object"),
4777 input_bfd
, v
, h
->root
.root
.string
);
4778 bfd_set_error (bfd_error_bad_value
);
4781 else if (!bfd_link_executable (info
)
4782 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4783 && (h
->type
== STT_FUNC
4784 || h
->type
== STT_OBJECT
)
4785 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4788 /* xgettext:c-format */
4789 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"),
4791 h
->type
== STT_FUNC
? "function" : "data",
4792 h
->root
.root
.string
);
4793 bfd_set_error (bfd_error_bad_value
);
4798 /* Note that sgot is not involved in this
4799 calculation. We always want the start of .got.plt. If we
4800 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4801 permitted by the ABI, we might have to change this
4803 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4804 + htab
->elf
.sgotplt
->output_offset
;
4807 case R_X86_64_GOTPC32
:
4808 case R_X86_64_GOTPC64
:
4809 /* Use global offset table as symbol value. */
4810 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4811 + htab
->elf
.sgotplt
->output_offset
;
4812 unresolved_reloc
= FALSE
;
4815 case R_X86_64_PLTOFF64
:
4816 /* Relocation is PLT entry relative to GOT. For local
4817 symbols it's the symbol itself relative to GOT. */
4819 /* See PLT32 handling. */
4820 && (h
->plt
.offset
!= (bfd_vma
) -1
4821 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4822 && htab
->elf
.splt
!= NULL
)
4824 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4826 /* Use the GOT PLT. */
4827 resolved_plt
= htab
->plt_got
;
4828 plt_offset
= eh
->plt_got
.offset
;
4830 else if (htab
->plt_bnd
!= NULL
)
4832 resolved_plt
= htab
->plt_bnd
;
4833 plt_offset
= eh
->plt_bnd
.offset
;
4837 resolved_plt
= htab
->elf
.splt
;
4838 plt_offset
= h
->plt
.offset
;
4841 relocation
= (resolved_plt
->output_section
->vma
4842 + resolved_plt
->output_offset
4844 unresolved_reloc
= FALSE
;
4847 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4848 + htab
->elf
.sgotplt
->output_offset
;
4851 case R_X86_64_PLT32
:
4852 case R_X86_64_PLT32_BND
:
4853 /* Relocation is to the entry for this symbol in the
4854 procedure linkage table. */
4856 /* Resolve a PLT32 reloc against a local symbol directly,
4857 without using the procedure linkage table. */
4861 if ((h
->plt
.offset
== (bfd_vma
) -1
4862 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4863 || htab
->elf
.splt
== NULL
)
4865 /* We didn't make a PLT entry for this symbol. This
4866 happens when statically linking PIC code, or when
4867 using -Bsymbolic. */
4871 if (h
->plt
.offset
!= (bfd_vma
) -1)
4873 if (htab
->plt_bnd
!= NULL
)
4875 resolved_plt
= htab
->plt_bnd
;
4876 plt_offset
= eh
->plt_bnd
.offset
;
4880 resolved_plt
= htab
->elf
.splt
;
4881 plt_offset
= h
->plt
.offset
;
4886 /* Use the GOT PLT. */
4887 resolved_plt
= htab
->plt_got
;
4888 plt_offset
= eh
->plt_got
.offset
;
4891 relocation
= (resolved_plt
->output_section
->vma
4892 + resolved_plt
->output_offset
4894 unresolved_reloc
= FALSE
;
4897 case R_X86_64_SIZE32
:
4898 case R_X86_64_SIZE64
:
4899 /* Set to symbol size. */
4900 relocation
= st_size
;
4906 case R_X86_64_PC32_BND
:
4907 /* Don't complain about -fPIC if the symbol is undefined when
4908 building executable unless it is unresolved weak symbol. */
4909 if ((input_section
->flags
& SEC_ALLOC
) != 0
4910 && (input_section
->flags
& SEC_READONLY
) != 0
4912 && ((bfd_link_executable (info
)
4913 && h
->root
.type
== bfd_link_hash_undefweak
4914 && !resolved_to_zero
)
4915 || (bfd_link_pic (info
)
4916 && !(bfd_link_pie (info
)
4917 && h
->root
.type
== bfd_link_hash_undefined
))))
4919 bfd_boolean fail
= FALSE
;
4921 = ((r_type
== R_X86_64_PC32
4922 || r_type
== R_X86_64_PC32_BND
)
4923 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4925 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4927 /* Symbol is referenced locally. Make sure it is
4928 defined locally or for a branch. */
4929 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4932 else if (!(bfd_link_pie (info
)
4933 && (h
->needs_copy
|| eh
->needs_copy
)))
4935 /* Symbol doesn't need copy reloc and isn't referenced
4936 locally. We only allow branch to symbol with
4937 non-default visibility. */
4939 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4943 return elf_x86_64_need_pic (input_bfd
, input_section
,
4944 h
, NULL
, NULL
, howto
);
4953 /* FIXME: The ABI says the linker should make sure the value is
4954 the same when it's zeroextended to 64 bit. */
4957 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4960 /* Don't copy a pc-relative relocation into the output file
4961 if the symbol needs copy reloc or the symbol is undefined
4962 when building executable. Copy dynamic function pointer
4963 relocations. Don't generate dynamic relocations against
4964 resolved undefined weak symbols in PIE. */
4965 if ((bfd_link_pic (info
)
4966 && !(bfd_link_pie (info
)
4970 || h
->root
.type
== bfd_link_hash_undefined
)
4971 && (IS_X86_64_PCREL_TYPE (r_type
)
4972 || r_type
== R_X86_64_SIZE32
4973 || r_type
== R_X86_64_SIZE64
))
4975 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4976 && !resolved_to_zero
)
4977 || h
->root
.type
!= bfd_link_hash_undefweak
))
4978 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4979 && r_type
!= R_X86_64_SIZE32
4980 && r_type
!= R_X86_64_SIZE64
)
4981 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4982 || (ELIMINATE_COPY_RELOCS
4983 && !bfd_link_pic (info
)
4987 || eh
->func_pointer_refcount
> 0
4988 || (h
->root
.type
== bfd_link_hash_undefweak
4989 && !resolved_to_zero
))
4990 && ((h
->def_dynamic
&& !h
->def_regular
)
4991 /* Undefined weak symbol is bound locally when
4993 || h
->root
.type
== bfd_link_hash_undefined
)))
4995 Elf_Internal_Rela outrel
;
4996 bfd_boolean skip
, relocate
;
4999 /* When generating a shared object, these relocations
5000 are copied into the output file to be resolved at run
5006 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5008 if (outrel
.r_offset
== (bfd_vma
) -1)
5010 else if (outrel
.r_offset
== (bfd_vma
) -2)
5011 skip
= TRUE
, relocate
= TRUE
;
5013 outrel
.r_offset
+= (input_section
->output_section
->vma
5014 + input_section
->output_offset
);
5017 memset (&outrel
, 0, sizeof outrel
);
5019 /* h->dynindx may be -1 if this symbol was marked to
5023 && (IS_X86_64_PCREL_TYPE (r_type
)
5024 || !(bfd_link_executable (info
)
5025 || SYMBOLIC_BIND (info
, h
))
5026 || ! h
->def_regular
))
5028 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
5029 outrel
.r_addend
= rel
->r_addend
;
5033 /* This symbol is local, or marked to become local.
5034 When relocation overflow check is disabled, we
5035 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
5036 if (r_type
== htab
->pointer_r_type
5037 || (r_type
== R_X86_64_32
5038 && info
->no_reloc_overflow_check
))
5041 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5042 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5044 else if (r_type
== R_X86_64_64
5045 && !ABI_64_P (output_bfd
))
5048 outrel
.r_info
= htab
->r_info (0,
5049 R_X86_64_RELATIVE64
);
5050 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5051 /* Check addend overflow. */
5052 if ((outrel
.r_addend
& 0x80000000)
5053 != (rel
->r_addend
& 0x80000000))
5056 int addend
= rel
->r_addend
;
5057 if (h
&& h
->root
.root
.string
)
5058 name
= h
->root
.root
.string
;
5060 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5064 /* xgettext:c-format */
5065 (_("%B: addend -0x%x in relocation %s against "
5066 "symbol `%s' at 0x%lx in section `%A' is "
5068 input_bfd
, input_section
, addend
,
5070 (unsigned long) rel
->r_offset
);
5073 /* xgettext:c-format */
5074 (_("%B: addend 0x%x in relocation %s against "
5075 "symbol `%s' at 0x%lx in section `%A' is "
5077 input_bfd
, input_section
, addend
,
5079 (unsigned long) rel
->r_offset
);
5080 bfd_set_error (bfd_error_bad_value
);
5088 if (bfd_is_abs_section (sec
))
5090 else if (sec
== NULL
|| sec
->owner
== NULL
)
5092 bfd_set_error (bfd_error_bad_value
);
5099 /* We are turning this relocation into one
5100 against a section symbol. It would be
5101 proper to subtract the symbol's value,
5102 osec->vma, from the emitted reloc addend,
5103 but ld.so expects buggy relocs. */
5104 osec
= sec
->output_section
;
5105 sindx
= elf_section_data (osec
)->dynindx
;
5108 asection
*oi
= htab
->elf
.text_index_section
;
5109 sindx
= elf_section_data (oi
)->dynindx
;
5111 BFD_ASSERT (sindx
!= 0);
5114 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
5115 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5119 sreloc
= elf_section_data (input_section
)->sreloc
;
5121 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5123 r
= bfd_reloc_notsupported
;
5124 goto check_relocation_error
;
5127 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5129 /* If this reloc is against an external symbol, we do
5130 not want to fiddle with the addend. Otherwise, we
5131 need to include the symbol value so that it becomes
5132 an addend for the dynamic reloc. */
5139 case R_X86_64_TLSGD
:
5140 case R_X86_64_GOTPC32_TLSDESC
:
5141 case R_X86_64_TLSDESC_CALL
:
5142 case R_X86_64_GOTTPOFF
:
5143 tls_type
= GOT_UNKNOWN
;
5144 if (h
== NULL
&& local_got_offsets
)
5145 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5147 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5149 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5150 input_section
, contents
,
5151 symtab_hdr
, sym_hashes
,
5152 &r_type
, tls_type
, rel
,
5153 relend
, h
, r_symndx
, TRUE
))
5156 if (r_type
== R_X86_64_TPOFF32
)
5158 bfd_vma roff
= rel
->r_offset
;
5160 BFD_ASSERT (! unresolved_reloc
);
5162 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5164 /* GD->LE transition. For 64bit, change
5165 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5166 .word 0x6666; rex64; call __tls_get_addr@PLT
5168 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5170 call *__tls_get_addr@GOTPCREL(%rip)
5171 which may be converted to
5172 addr32 call __tls_get_addr
5175 leaq foo@tpoff(%rax), %rax
5177 leaq foo@tlsgd(%rip), %rdi
5178 .word 0x6666; rex64; call __tls_get_addr@PLT
5180 leaq foo@tlsgd(%rip), %rdi
5182 call *__tls_get_addr@GOTPCREL(%rip)
5183 which may be converted to
5184 addr32 call __tls_get_addr
5187 leaq foo@tpoff(%rax), %rax
5188 For largepic, change:
5189 leaq foo@tlsgd(%rip), %rdi
5190 movabsq $__tls_get_addr@pltoff, %rax
5195 leaq foo@tpoff(%rax), %rax
5196 nopw 0x0(%rax,%rax,1) */
5198 if (ABI_64_P (output_bfd
))
5200 if (contents
[roff
+ 5] == 0xb8)
5202 memcpy (contents
+ roff
- 3,
5203 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5204 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5208 memcpy (contents
+ roff
- 4,
5209 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5213 memcpy (contents
+ roff
- 3,
5214 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5216 bfd_put_32 (output_bfd
,
5217 elf_x86_64_tpoff (info
, relocation
),
5218 contents
+ roff
+ 8 + largepic
);
5219 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5220 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5225 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5227 /* GDesc -> LE transition.
5228 It's originally something like:
5229 leaq x@tlsdesc(%rip), %rax
5232 movl $x@tpoff, %rax. */
5234 unsigned int val
, type
;
5236 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5237 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5238 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5239 contents
+ roff
- 3);
5240 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5241 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5242 contents
+ roff
- 1);
5243 bfd_put_32 (output_bfd
,
5244 elf_x86_64_tpoff (info
, relocation
),
5248 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5250 /* GDesc -> LE transition.
5255 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5256 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5259 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5261 /* IE->LE transition:
5262 For 64bit, originally it can be one of:
5263 movq foo@gottpoff(%rip), %reg
5264 addq foo@gottpoff(%rip), %reg
5267 leaq foo(%reg), %reg
5269 For 32bit, originally it can be one of:
5270 movq foo@gottpoff(%rip), %reg
5271 addl foo@gottpoff(%rip), %reg
5274 leal foo(%reg), %reg
5277 unsigned int val
, type
, reg
;
5280 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5283 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5284 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5290 bfd_put_8 (output_bfd
, 0x49,
5291 contents
+ roff
- 3);
5292 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5293 bfd_put_8 (output_bfd
, 0x41,
5294 contents
+ roff
- 3);
5295 bfd_put_8 (output_bfd
, 0xc7,
5296 contents
+ roff
- 2);
5297 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5298 contents
+ roff
- 1);
5302 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5305 bfd_put_8 (output_bfd
, 0x49,
5306 contents
+ roff
- 3);
5307 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5308 bfd_put_8 (output_bfd
, 0x41,
5309 contents
+ roff
- 3);
5310 bfd_put_8 (output_bfd
, 0x81,
5311 contents
+ roff
- 2);
5312 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5313 contents
+ roff
- 1);
5317 /* addq/addl -> leaq/leal */
5319 bfd_put_8 (output_bfd
, 0x4d,
5320 contents
+ roff
- 3);
5321 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5322 bfd_put_8 (output_bfd
, 0x45,
5323 contents
+ roff
- 3);
5324 bfd_put_8 (output_bfd
, 0x8d,
5325 contents
+ roff
- 2);
5326 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5327 contents
+ roff
- 1);
5329 bfd_put_32 (output_bfd
,
5330 elf_x86_64_tpoff (info
, relocation
),
5338 if (htab
->elf
.sgot
== NULL
)
5343 off
= h
->got
.offset
;
5344 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5348 if (local_got_offsets
== NULL
)
5351 off
= local_got_offsets
[r_symndx
];
5352 offplt
= local_tlsdesc_gotents
[r_symndx
];
5359 Elf_Internal_Rela outrel
;
5363 if (htab
->elf
.srelgot
== NULL
)
5366 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5368 if (GOT_TLS_GDESC_P (tls_type
))
5370 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5371 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5372 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5373 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5374 + htab
->elf
.sgotplt
->output_offset
5376 + htab
->sgotplt_jump_table_size
);
5377 sreloc
= htab
->elf
.srelplt
;
5379 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5381 outrel
.r_addend
= 0;
5382 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5385 sreloc
= htab
->elf
.srelgot
;
5387 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5388 + htab
->elf
.sgot
->output_offset
+ off
);
5390 if (GOT_TLS_GD_P (tls_type
))
5391 dr_type
= R_X86_64_DTPMOD64
;
5392 else if (GOT_TLS_GDESC_P (tls_type
))
5395 dr_type
= R_X86_64_TPOFF64
;
5397 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5398 outrel
.r_addend
= 0;
5399 if ((dr_type
== R_X86_64_TPOFF64
5400 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5401 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5402 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5404 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5406 if (GOT_TLS_GD_P (tls_type
))
5410 BFD_ASSERT (! unresolved_reloc
);
5411 bfd_put_64 (output_bfd
,
5412 relocation
- elf_x86_64_dtpoff_base (info
),
5413 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5417 bfd_put_64 (output_bfd
, 0,
5418 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5419 outrel
.r_info
= htab
->r_info (indx
,
5421 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5422 elf_append_rela (output_bfd
, sreloc
,
5431 local_got_offsets
[r_symndx
] |= 1;
5434 if (off
>= (bfd_vma
) -2
5435 && ! GOT_TLS_GDESC_P (tls_type
))
5437 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5439 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5440 || r_type
== R_X86_64_TLSDESC_CALL
)
5441 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5442 + htab
->elf
.sgotplt
->output_offset
5443 + offplt
+ htab
->sgotplt_jump_table_size
;
5445 relocation
= htab
->elf
.sgot
->output_section
->vma
5446 + htab
->elf
.sgot
->output_offset
+ off
;
5447 unresolved_reloc
= FALSE
;
5451 bfd_vma roff
= rel
->r_offset
;
5453 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5455 /* GD->IE transition. For 64bit, change
5456 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5457 .word 0x6666; rex64; call __tls_get_addr@PLT
5459 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5461 call *__tls_get_addr@GOTPCREL(%rip
5462 which may be converted to
5463 addr32 call __tls_get_addr
5466 addq foo@gottpoff(%rip), %rax
5468 leaq foo@tlsgd(%rip), %rdi
5469 .word 0x6666; rex64; call __tls_get_addr@PLT
5471 leaq foo@tlsgd(%rip), %rdi
5473 call *__tls_get_addr@GOTPCREL(%rip)
5474 which may be converted to
5475 addr32 call __tls_get_addr
5478 addq foo@gottpoff(%rip), %rax
5479 For largepic, change:
5480 leaq foo@tlsgd(%rip), %rdi
5481 movabsq $__tls_get_addr@pltoff, %rax
5486 addq foo@gottpoff(%rax), %rax
5487 nopw 0x0(%rax,%rax,1) */
5489 if (ABI_64_P (output_bfd
))
5491 if (contents
[roff
+ 5] == 0xb8)
5493 memcpy (contents
+ roff
- 3,
5494 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5495 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5499 memcpy (contents
+ roff
- 4,
5500 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5504 memcpy (contents
+ roff
- 3,
5505 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5508 relocation
= (htab
->elf
.sgot
->output_section
->vma
5509 + htab
->elf
.sgot
->output_offset
+ off
5512 - input_section
->output_section
->vma
5513 - input_section
->output_offset
5515 bfd_put_32 (output_bfd
, relocation
,
5516 contents
+ roff
+ 8 + largepic
);
5517 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5522 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5524 /* GDesc -> IE transition.
5525 It's originally something like:
5526 leaq x@tlsdesc(%rip), %rax
5529 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5531 /* Now modify the instruction as appropriate. To
5532 turn a leaq into a movq in the form we use it, it
5533 suffices to change the second byte from 0x8d to
5535 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5537 bfd_put_32 (output_bfd
,
5538 htab
->elf
.sgot
->output_section
->vma
5539 + htab
->elf
.sgot
->output_offset
+ off
5541 - input_section
->output_section
->vma
5542 - input_section
->output_offset
5547 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5549 /* GDesc -> IE transition.
5556 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5557 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5565 case R_X86_64_TLSLD
:
5566 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5567 input_section
, contents
,
5568 symtab_hdr
, sym_hashes
,
5569 &r_type
, GOT_UNKNOWN
, rel
,
5570 relend
, h
, r_symndx
, TRUE
))
5573 if (r_type
!= R_X86_64_TLSLD
)
5575 /* LD->LE transition:
5576 leaq foo@tlsld(%rip), %rdi
5577 call __tls_get_addr@PLT
5578 For 64bit, we change it into:
5579 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5580 For 32bit, we change it into:
5581 nopl 0x0(%rax); movl %fs:0, %eax
5583 leaq foo@tlsld(%rip), %rdi;
5584 call *__tls_get_addr@GOTPCREL(%rip)
5585 which may be converted to
5586 addr32 call __tls_get_addr
5587 For 64bit, we change it into:
5588 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5589 For 32bit, we change it into:
5590 nopw 0x0(%rax); movl %fs:0, %eax
5591 For largepic, change:
5592 leaq foo@tlsgd(%rip), %rdi
5593 movabsq $__tls_get_addr@pltoff, %rax
5597 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5600 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5601 if (ABI_64_P (output_bfd
))
5603 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5604 memcpy (contents
+ rel
->r_offset
- 3,
5605 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5606 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5607 else if (contents
[rel
->r_offset
+ 4] == 0xff
5608 || contents
[rel
->r_offset
+ 4] == 0x67)
5609 memcpy (contents
+ rel
->r_offset
- 3,
5610 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5613 memcpy (contents
+ rel
->r_offset
- 3,
5614 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5618 if (contents
[rel
->r_offset
+ 4] == 0xff)
5619 memcpy (contents
+ rel
->r_offset
- 3,
5620 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5623 memcpy (contents
+ rel
->r_offset
- 3,
5624 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5626 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5627 and R_X86_64_PLTOFF64. */
5633 if (htab
->elf
.sgot
== NULL
)
5636 off
= htab
->tls_ld_got
.offset
;
5641 Elf_Internal_Rela outrel
;
5643 if (htab
->elf
.srelgot
== NULL
)
5646 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5647 + htab
->elf
.sgot
->output_offset
+ off
);
5649 bfd_put_64 (output_bfd
, 0,
5650 htab
->elf
.sgot
->contents
+ off
);
5651 bfd_put_64 (output_bfd
, 0,
5652 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5653 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5654 outrel
.r_addend
= 0;
5655 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5657 htab
->tls_ld_got
.offset
|= 1;
5659 relocation
= htab
->elf
.sgot
->output_section
->vma
5660 + htab
->elf
.sgot
->output_offset
+ off
;
5661 unresolved_reloc
= FALSE
;
5664 case R_X86_64_DTPOFF32
:
5665 if (!bfd_link_executable (info
)
5666 || (input_section
->flags
& SEC_CODE
) == 0)
5667 relocation
-= elf_x86_64_dtpoff_base (info
);
5669 relocation
= elf_x86_64_tpoff (info
, relocation
);
5672 case R_X86_64_TPOFF32
:
5673 case R_X86_64_TPOFF64
:
5674 BFD_ASSERT (bfd_link_executable (info
));
5675 relocation
= elf_x86_64_tpoff (info
, relocation
);
5678 case R_X86_64_DTPOFF64
:
5679 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5680 relocation
-= elf_x86_64_dtpoff_base (info
);
5687 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5688 because such sections are not SEC_ALLOC and thus ld.so will
5689 not process them. */
5690 if (unresolved_reloc
5691 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5693 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5694 rel
->r_offset
) != (bfd_vma
) -1)
5697 /* xgettext:c-format */
5698 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5701 (long) rel
->r_offset
,
5703 h
->root
.root
.string
);
5708 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5709 contents
, rel
->r_offset
,
5710 relocation
, rel
->r_addend
);
5712 check_relocation_error
:
5713 if (r
!= bfd_reloc_ok
)
5718 name
= h
->root
.root
.string
;
5721 name
= bfd_elf_string_from_elf_section (input_bfd
,
5722 symtab_hdr
->sh_link
,
5727 name
= bfd_section_name (input_bfd
, sec
);
5730 if (r
== bfd_reloc_overflow
)
5731 (*info
->callbacks
->reloc_overflow
)
5732 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5733 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5737 /* xgettext:c-format */
5738 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5739 input_bfd
, input_section
,
5740 (long) rel
->r_offset
, name
, (int) r
);
5751 Elf_Internal_Shdr
*rel_hdr
;
5752 size_t deleted
= rel
- wrel
;
5754 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5755 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5756 if (rel_hdr
->sh_size
== 0)
5758 /* It is too late to remove an empty reloc section. Leave
5760 ??? What is wrong with an empty section??? */
5761 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5764 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5765 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5766 input_section
->reloc_count
-= deleted
;
5772 /* Finish up dynamic symbol handling. We set the contents of various
5773 dynamic sections here. */
5776 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5777 struct bfd_link_info
*info
,
5778 struct elf_link_hash_entry
*h
,
5779 Elf_Internal_Sym
*sym
)
5781 struct elf_x86_64_link_hash_table
*htab
;
5782 const struct elf_x86_64_backend_data
*abed
;
5783 bfd_boolean use_plt_bnd
;
5784 struct elf_x86_64_link_hash_entry
*eh
;
5785 bfd_boolean local_undefweak
;
5787 htab
= elf_x86_64_hash_table (info
);
5791 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5792 section only if there is .plt section. */
5793 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5795 ? &elf_x86_64_bnd_arch_bed
5796 : get_elf_x86_64_backend_data (output_bfd
));
5798 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5800 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5801 resolved undefined weak symbols in executable so that their
5802 references have value 0 at run-time. */
5803 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5807 if (h
->plt
.offset
!= (bfd_vma
) -1)
5810 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
5811 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
5812 Elf_Internal_Rela rela
;
5814 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5815 const struct elf_backend_data
*bed
;
5816 bfd_vma plt_got_pcrel_offset
;
5818 /* When building a static executable, use .iplt, .igot.plt and
5819 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5820 if (htab
->elf
.splt
!= NULL
)
5822 plt
= htab
->elf
.splt
;
5823 gotplt
= htab
->elf
.sgotplt
;
5824 relplt
= htab
->elf
.srelplt
;
5828 plt
= htab
->elf
.iplt
;
5829 gotplt
= htab
->elf
.igotplt
;
5830 relplt
= htab
->elf
.irelplt
;
5833 /* This symbol has an entry in the procedure linkage table. Set
5835 if ((h
->dynindx
== -1
5837 && !((h
->forced_local
|| bfd_link_executable (info
))
5839 && h
->type
== STT_GNU_IFUNC
))
5845 /* Get the index in the procedure linkage table which
5846 corresponds to this symbol. This is the index of this symbol
5847 in all the symbols for which we are making plt entries. The
5848 first entry in the procedure linkage table is reserved.
5850 Get the offset into the .got table of the entry that
5851 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5852 bytes. The first three are reserved for the dynamic linker.
5854 For static executables, we don't reserve anything. */
5856 if (plt
== htab
->elf
.splt
)
5858 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
5859 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5863 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
5864 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5867 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
5868 plt_plt_offset
= abed
->plt_plt_offset
;
5869 plt_got_insn_size
= abed
->plt_got_insn_size
;
5870 plt_got_offset
= abed
->plt_got_offset
;
5873 /* Use the second PLT with BND relocations. */
5874 const bfd_byte
*plt_entry
, *plt2_entry
;
5876 if (eh
->has_bnd_reloc
)
5878 plt_entry
= elf_x86_64_bnd_plt_entry
;
5879 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
5883 plt_entry
= elf_x86_64_legacy_plt_entry
;
5884 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
5886 /* Subtract 1 since there is no BND prefix. */
5887 plt_plt_insn_end
-= 1;
5888 plt_plt_offset
-= 1;
5889 plt_got_insn_size
-= 1;
5890 plt_got_offset
-= 1;
5893 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
5894 == sizeof (elf_x86_64_legacy_plt_entry
));
5896 /* Fill in the entry in the procedure linkage table. */
5897 memcpy (plt
->contents
+ h
->plt
.offset
,
5898 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
5899 /* Fill in the entry in the second PLT. */
5900 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5901 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5903 resolved_plt
= htab
->plt_bnd
;
5904 plt_offset
= eh
->plt_bnd
.offset
;
5908 /* Fill in the entry in the procedure linkage table. */
5909 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
5910 abed
->plt_entry_size
);
5913 plt_offset
= h
->plt
.offset
;
5916 /* Insert the relocation positions of the plt section. */
5918 /* Put offset the PC-relative instruction referring to the GOT entry,
5919 subtracting the size of that instruction. */
5920 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5921 + gotplt
->output_offset
5923 - resolved_plt
->output_section
->vma
5924 - resolved_plt
->output_offset
5926 - plt_got_insn_size
);
5928 /* Check PC-relative offset overflow in PLT entry. */
5929 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5930 /* xgettext:c-format */
5931 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5932 output_bfd
, h
->root
.root
.string
);
5934 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5935 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
5937 /* Fill in the entry in the global offset table, initially this
5938 points to the second part of the PLT entry. Leave the entry
5939 as zero for undefined weak symbol in PIE. No PLT relocation
5940 against undefined weak symbol in PIE. */
5941 if (!local_undefweak
)
5943 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5944 + plt
->output_offset
5946 + abed
->plt_lazy_offset
),
5947 gotplt
->contents
+ got_offset
);
5949 /* Fill in the entry in the .rela.plt section. */
5950 rela
.r_offset
= (gotplt
->output_section
->vma
5951 + gotplt
->output_offset
5953 if (h
->dynindx
== -1
5954 || ((bfd_link_executable (info
)
5955 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5957 && h
->type
== STT_GNU_IFUNC
))
5959 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5960 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5961 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5962 rela
.r_addend
= (h
->root
.u
.def
.value
5963 + h
->root
.u
.def
.section
->output_section
->vma
5964 + h
->root
.u
.def
.section
->output_offset
);
5965 /* R_X86_64_IRELATIVE comes last. */
5966 plt_index
= htab
->next_irelative_index
--;
5970 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5972 plt_index
= htab
->next_jump_slot_index
++;
5975 /* Don't fill PLT entry for static executables. */
5976 if (plt
== htab
->elf
.splt
)
5978 bfd_vma plt0_offset
= h
->plt
.offset
+ plt_plt_insn_end
;
5980 /* Put relocation index. */
5981 bfd_put_32 (output_bfd
, plt_index
,
5982 (plt
->contents
+ h
->plt
.offset
5983 + abed
->plt_reloc_offset
));
5985 /* Put offset for jmp .PLT0 and check for overflow. We don't
5986 check relocation index for overflow since branch displacement
5987 will overflow first. */
5988 if (plt0_offset
> 0x80000000)
5989 /* xgettext:c-format */
5990 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5991 output_bfd
, h
->root
.root
.string
);
5992 bfd_put_32 (output_bfd
, - plt0_offset
,
5993 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
5996 bed
= get_elf_backend_data (output_bfd
);
5997 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
5998 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
6001 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
6003 bfd_vma got_offset
, plt_offset
, plt_got_offset
, plt_got_insn_size
;
6004 asection
*plt
, *got
;
6005 bfd_boolean got_after_plt
;
6006 int32_t got_pcrel_offset
;
6007 const bfd_byte
*got_plt_entry
;
6009 /* Set the entry in the GOT procedure linkage table. */
6010 plt
= htab
->plt_got
;
6011 got
= htab
->elf
.sgot
;
6012 got_offset
= h
->got
.offset
;
6014 if (got_offset
== (bfd_vma
) -1
6015 || h
->type
== STT_GNU_IFUNC
6020 /* Use the second PLT entry template for the GOT PLT since they
6021 are the identical. */
6022 plt_got_insn_size
= elf_x86_64_bnd_arch_bed
.plt_got_insn_size
;
6023 plt_got_offset
= elf_x86_64_bnd_arch_bed
.plt_got_offset
;
6024 if (eh
->has_bnd_reloc
)
6025 got_plt_entry
= elf_x86_64_bnd_plt2_entry
;
6028 got_plt_entry
= elf_x86_64_legacy_plt2_entry
;
6030 /* Subtract 1 since there is no BND prefix. */
6031 plt_got_insn_size
-= 1;
6032 plt_got_offset
-= 1;
6035 /* Fill in the entry in the GOT procedure linkage table. */
6036 plt_offset
= eh
->plt_got
.offset
;
6037 memcpy (plt
->contents
+ plt_offset
,
6038 got_plt_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
6040 /* Put offset the PC-relative instruction referring to the GOT
6041 entry, subtracting the size of that instruction. */
6042 got_pcrel_offset
= (got
->output_section
->vma
6043 + got
->output_offset
6045 - plt
->output_section
->vma
6046 - plt
->output_offset
6048 - plt_got_insn_size
);
6050 /* Check PC-relative offset overflow in GOT PLT entry. */
6051 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
6052 if ((got_after_plt
&& got_pcrel_offset
< 0)
6053 || (!got_after_plt
&& got_pcrel_offset
> 0))
6054 /* xgettext:c-format */
6055 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
6056 output_bfd
, h
->root
.root
.string
);
6058 bfd_put_32 (output_bfd
, got_pcrel_offset
,
6059 plt
->contents
+ plt_offset
+ plt_got_offset
);
6062 if (!local_undefweak
6064 && (h
->plt
.offset
!= (bfd_vma
) -1
6065 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
6067 /* Mark the symbol as undefined, rather than as defined in
6068 the .plt section. Leave the value if there were any
6069 relocations where pointer equality matters (this is a clue
6070 for the dynamic linker, to make function pointer
6071 comparisons work between an application and shared
6072 library), otherwise set it to zero. If a function is only
6073 called from a binary, there is no need to slow down
6074 shared libraries because of that. */
6075 sym
->st_shndx
= SHN_UNDEF
;
6076 if (!h
->pointer_equality_needed
)
6080 /* Don't generate dynamic GOT relocation against undefined weak
6081 symbol in executable. */
6082 if (h
->got
.offset
!= (bfd_vma
) -1
6083 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
6084 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
6085 && !local_undefweak
)
6087 Elf_Internal_Rela rela
;
6088 asection
*relgot
= htab
->elf
.srelgot
;
6090 /* This symbol has an entry in the global offset table. Set it
6092 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
6095 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
6096 + htab
->elf
.sgot
->output_offset
6097 + (h
->got
.offset
&~ (bfd_vma
) 1));
6099 /* If this is a static link, or it is a -Bsymbolic link and the
6100 symbol is defined locally or was forced to be local because
6101 of a version file, we just want to emit a RELATIVE reloc.
6102 The entry in the global offset table will already have been
6103 initialized in the relocate_section function. */
6105 && h
->type
== STT_GNU_IFUNC
)
6107 if (h
->plt
.offset
== (bfd_vma
) -1)
6109 /* STT_GNU_IFUNC is referenced without PLT. */
6110 if (htab
->elf
.splt
== NULL
)
6112 /* use .rel[a].iplt section to store .got relocations
6113 in static executable. */
6114 relgot
= htab
->elf
.irelplt
;
6116 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
6118 rela
.r_info
= htab
->r_info (0,
6119 R_X86_64_IRELATIVE
);
6120 rela
.r_addend
= (h
->root
.u
.def
.value
6121 + h
->root
.u
.def
.section
->output_section
->vma
6122 + h
->root
.u
.def
.section
->output_offset
);
6127 else if (bfd_link_pic (info
))
6129 /* Generate R_X86_64_GLOB_DAT. */
6136 if (!h
->pointer_equality_needed
)
6139 /* For non-shared object, we can't use .got.plt, which
6140 contains the real function addres if we need pointer
6141 equality. We load the GOT entry with the PLT entry. */
6142 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6143 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6144 + plt
->output_offset
6146 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6150 else if (bfd_link_pic (info
)
6151 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6153 if (!h
->def_regular
)
6155 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6156 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6157 rela
.r_addend
= (h
->root
.u
.def
.value
6158 + h
->root
.u
.def
.section
->output_section
->vma
6159 + h
->root
.u
.def
.section
->output_offset
);
6163 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6165 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6166 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6167 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6171 elf_append_rela (output_bfd
, relgot
, &rela
);
6176 Elf_Internal_Rela rela
;
6179 /* This symbol needs a copy reloc. Set it up. */
6181 if (h
->dynindx
== -1
6182 || (h
->root
.type
!= bfd_link_hash_defined
6183 && h
->root
.type
!= bfd_link_hash_defweak
)
6184 || htab
->elf
.srelbss
== NULL
6185 || htab
->elf
.sreldynrelro
== NULL
)
6188 rela
.r_offset
= (h
->root
.u
.def
.value
6189 + h
->root
.u
.def
.section
->output_section
->vma
6190 + h
->root
.u
.def
.section
->output_offset
);
6191 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6193 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6194 s
= htab
->elf
.sreldynrelro
;
6196 s
= htab
->elf
.srelbss
;
6197 elf_append_rela (output_bfd
, s
, &rela
);
6203 /* Finish up local dynamic symbol handling. We set the contents of
6204 various dynamic sections here. */
6207 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6209 struct elf_link_hash_entry
*h
6210 = (struct elf_link_hash_entry
*) *slot
;
6211 struct bfd_link_info
*info
6212 = (struct bfd_link_info
*) inf
;
6214 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6218 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6219 here since undefined weak symbol may not be dynamic and may not be
6220 called for elf_x86_64_finish_dynamic_symbol. */
6223 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6226 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6227 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6229 if (h
->root
.type
!= bfd_link_hash_undefweak
6230 || h
->dynindx
!= -1)
6233 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6237 /* Used to decide how to sort relocs in an optimal manner for the
6238 dynamic linker, before writing them out. */
6240 static enum elf_reloc_type_class
6241 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6242 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6243 const Elf_Internal_Rela
*rela
)
6245 bfd
*abfd
= info
->output_bfd
;
6246 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6247 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6249 if (htab
->elf
.dynsym
!= NULL
6250 && htab
->elf
.dynsym
->contents
!= NULL
)
6252 /* Check relocation against STT_GNU_IFUNC symbol if there are
6254 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6255 if (r_symndx
!= STN_UNDEF
)
6257 Elf_Internal_Sym sym
;
6258 if (!bed
->s
->swap_symbol_in (abfd
,
6259 (htab
->elf
.dynsym
->contents
6260 + r_symndx
* bed
->s
->sizeof_sym
),
6264 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6265 return reloc_class_ifunc
;
6269 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6271 case R_X86_64_IRELATIVE
:
6272 return reloc_class_ifunc
;
6273 case R_X86_64_RELATIVE
:
6274 case R_X86_64_RELATIVE64
:
6275 return reloc_class_relative
;
6276 case R_X86_64_JUMP_SLOT
:
6277 return reloc_class_plt
;
6279 return reloc_class_copy
;
6281 return reloc_class_normal
;
6285 /* Finish up the dynamic sections. */
6288 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6289 struct bfd_link_info
*info
)
6291 struct elf_x86_64_link_hash_table
*htab
;
6294 const struct elf_x86_64_backend_data
*abed
;
6296 htab
= elf_x86_64_hash_table (info
);
6300 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6301 section only if there is .plt section. */
6302 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
6303 ? &elf_x86_64_bnd_arch_bed
6304 : get_elf_x86_64_backend_data (output_bfd
));
6306 dynobj
= htab
->elf
.dynobj
;
6307 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6309 if (htab
->elf
.dynamic_sections_created
)
6311 bfd_byte
*dyncon
, *dynconend
;
6312 const struct elf_backend_data
*bed
;
6313 bfd_size_type sizeof_dyn
;
6315 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6318 bed
= get_elf_backend_data (dynobj
);
6319 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6320 dyncon
= sdyn
->contents
;
6321 dynconend
= sdyn
->contents
+ sdyn
->size
;
6322 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6324 Elf_Internal_Dyn dyn
;
6327 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6335 s
= htab
->elf
.sgotplt
;
6336 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6340 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6344 s
= htab
->elf
.srelplt
->output_section
;
6345 dyn
.d_un
.d_val
= s
->size
;
6348 case DT_TLSDESC_PLT
:
6350 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6351 + htab
->tlsdesc_plt
;
6354 case DT_TLSDESC_GOT
:
6356 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6357 + htab
->tlsdesc_got
;
6361 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6364 /* Fill in the special first entry in the procedure linkage table. */
6365 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6367 /* Fill in the first entry in the procedure linkage table. */
6368 memcpy (htab
->elf
.splt
->contents
,
6369 abed
->plt0_entry
, abed
->plt_entry_size
);
6370 /* Add offset for pushq GOT+8(%rip), since the instruction
6371 uses 6 bytes subtract this value. */
6372 bfd_put_32 (output_bfd
,
6373 (htab
->elf
.sgotplt
->output_section
->vma
6374 + htab
->elf
.sgotplt
->output_offset
6376 - htab
->elf
.splt
->output_section
->vma
6377 - htab
->elf
.splt
->output_offset
6379 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
6380 /* Add offset for the PC-relative instruction accessing GOT+16,
6381 subtracting the offset to the end of that instruction. */
6382 bfd_put_32 (output_bfd
,
6383 (htab
->elf
.sgotplt
->output_section
->vma
6384 + htab
->elf
.sgotplt
->output_offset
6386 - htab
->elf
.splt
->output_section
->vma
6387 - htab
->elf
.splt
->output_offset
6388 - abed
->plt0_got2_insn_end
),
6389 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
6391 elf_section_data (htab
->elf
.splt
->output_section
)
6392 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
6394 if (htab
->tlsdesc_plt
)
6396 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6397 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6399 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6400 abed
->plt0_entry
, abed
->plt_entry_size
);
6402 /* Add offset for pushq GOT+8(%rip), since the
6403 instruction uses 6 bytes subtract this value. */
6404 bfd_put_32 (output_bfd
,
6405 (htab
->elf
.sgotplt
->output_section
->vma
6406 + htab
->elf
.sgotplt
->output_offset
6408 - htab
->elf
.splt
->output_section
->vma
6409 - htab
->elf
.splt
->output_offset
6412 htab
->elf
.splt
->contents
6413 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
6414 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6415 where TGD stands for htab->tlsdesc_got, subtracting the offset
6416 to the end of that instruction. */
6417 bfd_put_32 (output_bfd
,
6418 (htab
->elf
.sgot
->output_section
->vma
6419 + htab
->elf
.sgot
->output_offset
6421 - htab
->elf
.splt
->output_section
->vma
6422 - htab
->elf
.splt
->output_offset
6424 - abed
->plt0_got2_insn_end
),
6425 htab
->elf
.splt
->contents
6426 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
6431 if (htab
->plt_bnd
!= NULL
)
6432 elf_section_data (htab
->plt_bnd
->output_section
)
6433 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
6435 if (htab
->elf
.sgotplt
)
6437 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6440 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6444 /* Fill in the first three entries in the global offset table. */
6445 if (htab
->elf
.sgotplt
->size
> 0)
6447 /* Set the first entry in the global offset table to the address of
6448 the dynamic section. */
6450 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6452 bfd_put_64 (output_bfd
,
6453 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6454 htab
->elf
.sgotplt
->contents
);
6455 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6456 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6457 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6460 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
6464 /* Adjust .eh_frame for .plt section. */
6465 if (htab
->plt_eh_frame
!= NULL
6466 && htab
->plt_eh_frame
->contents
!= NULL
)
6468 if (htab
->elf
.splt
!= NULL
6469 && htab
->elf
.splt
->size
!= 0
6470 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6471 && htab
->elf
.splt
->output_section
!= NULL
6472 && htab
->plt_eh_frame
->output_section
!= NULL
)
6474 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6475 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6476 + htab
->plt_eh_frame
->output_offset
6477 + PLT_FDE_START_OFFSET
;
6478 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6479 htab
->plt_eh_frame
->contents
6480 + PLT_FDE_START_OFFSET
);
6482 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6484 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6486 htab
->plt_eh_frame
->contents
))
6491 /* Adjust .eh_frame for .plt.got section. */
6492 if (htab
->plt_got_eh_frame
!= NULL
6493 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6495 if (htab
->plt_got
!= NULL
6496 && htab
->plt_got
->size
!= 0
6497 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6498 && htab
->plt_got
->output_section
!= NULL
6499 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6501 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6502 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6503 + htab
->plt_got_eh_frame
->output_offset
6504 + PLT_FDE_START_OFFSET
;
6505 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6506 htab
->plt_got_eh_frame
->contents
6507 + PLT_FDE_START_OFFSET
);
6509 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6511 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6512 htab
->plt_got_eh_frame
,
6513 htab
->plt_got_eh_frame
->contents
))
6518 /* Adjust .eh_frame for .plt.bnd section. */
6519 if (htab
->plt_bnd_eh_frame
!= NULL
6520 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
6522 if (htab
->plt_bnd
!= NULL
6523 && htab
->plt_bnd
->size
!= 0
6524 && (htab
->plt_bnd
->flags
& SEC_EXCLUDE
) == 0
6525 && htab
->plt_bnd
->output_section
!= NULL
6526 && htab
->plt_bnd_eh_frame
->output_section
!= NULL
)
6528 bfd_vma plt_start
= htab
->plt_bnd
->output_section
->vma
;
6529 bfd_vma eh_frame_start
= htab
->plt_bnd_eh_frame
->output_section
->vma
6530 + htab
->plt_bnd_eh_frame
->output_offset
6531 + PLT_FDE_START_OFFSET
;
6532 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6533 htab
->plt_bnd_eh_frame
->contents
6534 + PLT_FDE_START_OFFSET
);
6536 if (htab
->plt_bnd_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6538 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6539 htab
->plt_bnd_eh_frame
,
6540 htab
->plt_bnd_eh_frame
->contents
))
6545 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6546 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6549 /* Fill PLT entries for undefined weak symbols in PIE. */
6550 if (bfd_link_pie (info
))
6551 bfd_hash_traverse (&info
->hash
->table
,
6552 elf_x86_64_pie_finish_undefweak_symbol
,
6558 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6559 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6560 It has to be done before elf_link_sort_relocs is called so that
6561 dynamic relocations are properly sorted. */
6564 elf_x86_64_output_arch_local_syms
6565 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6566 struct bfd_link_info
*info
,
6567 void *flaginfo ATTRIBUTE_UNUSED
,
6568 int (*func
) (void *, const char *,
6571 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6573 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6577 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6578 htab_traverse (htab
->loc_hash_table
,
6579 elf_x86_64_finish_local_dynamic_symbol
,
6585 /* Return an array of PLT entry symbol values. */
6588 elf_x86_64_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6591 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6594 bfd_vma
*plt_sym_val
;
6596 bfd_byte
*plt_contents
;
6597 const struct elf_x86_64_backend_data
*bed
;
6598 Elf_Internal_Shdr
*hdr
;
6601 /* Get the .plt section contents. PLT passed down may point to the
6602 .plt.bnd section. Make sure that PLT always points to the .plt
6604 plt_bnd
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6609 plt
= bfd_get_section_by_name (abfd
, ".plt");
6612 bed
= &elf_x86_64_bnd_arch_bed
;
6615 bed
= get_elf_x86_64_backend_data (abfd
);
6617 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6618 if (plt_contents
== NULL
)
6620 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6621 plt_contents
, 0, plt
->size
))
6624 free (plt_contents
);
6628 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6629 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6632 hdr
= &elf_section_data (relplt
)->this_hdr
;
6633 count
= relplt
->size
/ hdr
->sh_entsize
;
6635 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6636 if (plt_sym_val
== NULL
)
6639 for (i
= 0; i
< count
; i
++)
6640 plt_sym_val
[i
] = -1;
6642 plt_offset
= bed
->plt_entry_size
;
6643 p
= relplt
->relocation
;
6644 for (i
= 0; i
< count
; i
++, p
++)
6648 /* Skip unknown relocation. */
6649 if (p
->howto
== NULL
)
6652 if (p
->howto
->type
!= R_X86_64_JUMP_SLOT
6653 && p
->howto
->type
!= R_X86_64_IRELATIVE
)
6656 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6657 + bed
->plt_reloc_offset
));
6658 if (reloc_index
< count
)
6662 /* This is the index in .plt section. */
6663 long plt_index
= plt_offset
/ bed
->plt_entry_size
;
6664 /* Store VMA + the offset in .plt.bnd section. */
6665 plt_sym_val
[reloc_index
] =
6667 + (plt_index
- 1) * sizeof (elf_x86_64_legacy_plt2_entry
));
6670 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6672 plt_offset
+= bed
->plt_entry_size
;
6674 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6676 if (plt_offset
>= plt
->size
)
6680 free (plt_contents
);
6685 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6689 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6696 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6697 as PLT if it exists. */
6698 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6700 plt
= bfd_get_section_by_name (abfd
, ".plt");
6701 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6702 dynsymcount
, dynsyms
, ret
,
6704 elf_x86_64_get_plt_sym_val
);
6707 /* Handle an x86-64 specific section when reading an object file. This
6708 is called when elfcode.h finds a section with an unknown type. */
6711 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6712 const char *name
, int shindex
)
6714 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6717 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6723 /* Hook called by the linker routine which adds symbols from an object
6724 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6728 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6729 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6730 Elf_Internal_Sym
*sym
,
6731 const char **namep ATTRIBUTE_UNUSED
,
6732 flagword
*flagsp ATTRIBUTE_UNUSED
,
6738 switch (sym
->st_shndx
)
6740 case SHN_X86_64_LCOMMON
:
6741 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6744 lcomm
= bfd_make_section_with_flags (abfd
,
6748 | SEC_LINKER_CREATED
));
6751 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6754 *valp
= sym
->st_size
;
6762 /* Given a BFD section, try to locate the corresponding ELF section
6766 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6767 asection
*sec
, int *index_return
)
6769 if (sec
== &_bfd_elf_large_com_section
)
6771 *index_return
= SHN_X86_64_LCOMMON
;
6777 /* Process a symbol. */
6780 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6783 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6785 switch (elfsym
->internal_elf_sym
.st_shndx
)
6787 case SHN_X86_64_LCOMMON
:
6788 asym
->section
= &_bfd_elf_large_com_section
;
6789 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6790 /* Common symbol doesn't set BSF_GLOBAL. */
6791 asym
->flags
&= ~BSF_GLOBAL
;
6797 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6799 return (sym
->st_shndx
== SHN_COMMON
6800 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6804 elf_x86_64_common_section_index (asection
*sec
)
6806 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6809 return SHN_X86_64_LCOMMON
;
6813 elf_x86_64_common_section (asection
*sec
)
6815 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6816 return bfd_com_section_ptr
;
6818 return &_bfd_elf_large_com_section
;
6822 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6823 const Elf_Internal_Sym
*sym
,
6828 const asection
*oldsec
)
6830 /* A normal common symbol and a large common symbol result in a
6831 normal common symbol. We turn the large common symbol into a
6834 && h
->root
.type
== bfd_link_hash_common
6836 && bfd_is_com_section (*psec
)
6839 if (sym
->st_shndx
== SHN_COMMON
6840 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6842 h
->root
.u
.c
.p
->section
6843 = bfd_make_section_old_way (oldbfd
, "COMMON");
6844 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6846 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6847 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6848 *psec
= bfd_com_section_ptr
;
6855 elf_x86_64_additional_program_headers (bfd
*abfd
,
6856 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6861 /* Check to see if we need a large readonly segment. */
6862 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6863 if (s
&& (s
->flags
& SEC_LOAD
))
6866 /* Check to see if we need a large data segment. Since .lbss sections
6867 is placed right after the .bss section, there should be no need for
6868 a large data segment just because of .lbss. */
6869 s
= bfd_get_section_by_name (abfd
, ".ldata");
6870 if (s
&& (s
->flags
& SEC_LOAD
))
6876 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6879 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6881 if (h
->plt
.offset
!= (bfd_vma
) -1
6883 && !h
->pointer_equality_needed
)
6886 return _bfd_elf_hash_symbol (h
);
6889 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6892 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6893 const bfd_target
*output
)
6895 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6896 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6897 && _bfd_elf_relocs_compatible (input
, output
));
6900 /* Parse x86-64 GNU properties. */
6902 static enum elf_property_kind
6903 elf_x86_64_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6904 bfd_byte
*ptr
, unsigned int datasz
)
6910 case GNU_PROPERTY_X86_ISA_1_USED
:
6911 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6915 ((type
== GNU_PROPERTY_X86_ISA_1_USED
6916 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>\n")
6917 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>\n")),
6919 return property_corrupt
;
6921 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
6922 prop
->u
.number
= bfd_h_get_32 (abfd
, ptr
);
6923 prop
->pr_kind
= property_number
;
6927 return property_ignored
;
6930 return property_number
;
6933 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
6934 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
6935 should be merged with ABFD. */
6938 elf_x86_64_merge_gnu_properties (bfd
*abfd ATTRIBUTE_UNUSED
,
6939 elf_property
*aprop
,
6940 elf_property
*bprop
)
6942 unsigned int number
;
6943 bfd_boolean updated
= FALSE
;
6944 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
6948 case GNU_PROPERTY_X86_ISA_1_USED
:
6949 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
6950 if (aprop
!= NULL
&& bprop
!= NULL
)
6952 number
= aprop
->u
.number
;
6953 aprop
->u
.number
= number
| bprop
->u
.number
;
6954 updated
= number
!= (unsigned int) aprop
->u
.number
;
6958 /* Return TRUE if APROP is NULL to indicate that BPROP should
6959 be added to ABFD. */
6960 updated
= aprop
== NULL
;
6965 /* Never should happen. */
6972 static const struct bfd_elf_special_section
6973 elf_x86_64_special_sections
[]=
6975 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6976 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6977 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
6978 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6979 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6980 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6981 { NULL
, 0, 0, 0, 0 }
6984 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6985 #define TARGET_LITTLE_NAME "elf64-x86-64"
6986 #define ELF_ARCH bfd_arch_i386
6987 #define ELF_TARGET_ID X86_64_ELF_DATA
6988 #define ELF_MACHINE_CODE EM_X86_64
6989 #define ELF_MAXPAGESIZE 0x200000
6990 #define ELF_MINPAGESIZE 0x1000
6991 #define ELF_COMMONPAGESIZE 0x1000
6993 #define elf_backend_can_gc_sections 1
6994 #define elf_backend_can_refcount 1
6995 #define elf_backend_want_got_plt 1
6996 #define elf_backend_plt_readonly 1
6997 #define elf_backend_want_plt_sym 0
6998 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6999 #define elf_backend_rela_normal 1
7000 #define elf_backend_plt_alignment 4
7001 #define elf_backend_extern_protected_data 1
7002 #define elf_backend_caches_rawsize 1
7003 #define elf_backend_dtrel_excludes_plt 1
7004 #define elf_backend_want_dynrelro 1
7006 #define elf_info_to_howto elf_x86_64_info_to_howto
7008 #define bfd_elf64_bfd_link_hash_table_create \
7009 elf_x86_64_link_hash_table_create
7010 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7011 #define bfd_elf64_bfd_reloc_name_lookup \
7012 elf_x86_64_reloc_name_lookup
7014 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7015 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7016 #define elf_backend_check_relocs elf_x86_64_check_relocs
7017 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7018 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
7019 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7020 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7021 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7022 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7023 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7024 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7026 #define elf_backend_write_core_note elf_x86_64_write_core_note
7028 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7029 #define elf_backend_relocate_section elf_x86_64_relocate_section
7030 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7031 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7032 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7033 #define elf_backend_object_p elf64_x86_64_elf_object_p
7034 #define bfd_elf64_mkobject elf_x86_64_mkobject
7035 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7037 #define elf_backend_section_from_shdr \
7038 elf_x86_64_section_from_shdr
7040 #define elf_backend_section_from_bfd_section \
7041 elf_x86_64_elf_section_from_bfd_section
7042 #define elf_backend_add_symbol_hook \
7043 elf_x86_64_add_symbol_hook
7044 #define elf_backend_symbol_processing \
7045 elf_x86_64_symbol_processing
7046 #define elf_backend_common_section_index \
7047 elf_x86_64_common_section_index
7048 #define elf_backend_common_section \
7049 elf_x86_64_common_section
7050 #define elf_backend_common_definition \
7051 elf_x86_64_common_definition
7052 #define elf_backend_merge_symbol \
7053 elf_x86_64_merge_symbol
7054 #define elf_backend_special_sections \
7055 elf_x86_64_special_sections
7056 #define elf_backend_additional_program_headers \
7057 elf_x86_64_additional_program_headers
7058 #define elf_backend_hash_symbol \
7059 elf_x86_64_hash_symbol
7060 #define elf_backend_omit_section_dynsym \
7061 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7062 #define elf_backend_fixup_symbol \
7063 elf_x86_64_fixup_symbol
7064 #define elf_backend_parse_gnu_properties \
7065 elf_x86_64_parse_gnu_properties
7066 #define elf_backend_merge_gnu_properties \
7067 elf_x86_64_merge_gnu_properties
7069 #include "elf64-target.h"
7071 /* CloudABI support. */
7073 #undef TARGET_LITTLE_SYM
7074 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7075 #undef TARGET_LITTLE_NAME
7076 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7079 #define ELF_OSABI ELFOSABI_CLOUDABI
7082 #define elf64_bed elf64_x86_64_cloudabi_bed
7084 #include "elf64-target.h"
7086 /* FreeBSD support. */
7088 #undef TARGET_LITTLE_SYM
7089 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7090 #undef TARGET_LITTLE_NAME
7091 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7094 #define ELF_OSABI ELFOSABI_FREEBSD
7097 #define elf64_bed elf64_x86_64_fbsd_bed
7099 #include "elf64-target.h"
7101 /* Solaris 2 support. */
7103 #undef TARGET_LITTLE_SYM
7104 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7105 #undef TARGET_LITTLE_NAME
7106 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7108 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7109 objects won't be recognized. */
7113 #define elf64_bed elf64_x86_64_sol2_bed
7115 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7117 #undef elf_backend_static_tls_alignment
7118 #define elf_backend_static_tls_alignment 16
7120 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7122 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7124 #undef elf_backend_want_plt_sym
7125 #define elf_backend_want_plt_sym 1
7127 #undef elf_backend_strtab_flags
7128 #define elf_backend_strtab_flags SHF_STRINGS
7131 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7132 bfd
*obfd ATTRIBUTE_UNUSED
,
7133 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7134 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7136 /* PR 19938: FIXME: Need to add code for setting the sh_info
7137 and sh_link fields of Solaris specific section types. */
7141 #undef elf_backend_copy_special_section_fields
7142 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7144 #include "elf64-target.h"
7146 /* Native Client support. */
7149 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
7151 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7152 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
7156 #undef TARGET_LITTLE_SYM
7157 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7158 #undef TARGET_LITTLE_NAME
7159 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7161 #define elf64_bed elf64_x86_64_nacl_bed
7163 #undef ELF_MAXPAGESIZE
7164 #undef ELF_MINPAGESIZE
7165 #undef ELF_COMMONPAGESIZE
7166 #define ELF_MAXPAGESIZE 0x10000
7167 #define ELF_MINPAGESIZE 0x10000
7168 #define ELF_COMMONPAGESIZE 0x10000
7170 /* Restore defaults. */
7172 #undef elf_backend_static_tls_alignment
7173 #undef elf_backend_want_plt_sym
7174 #define elf_backend_want_plt_sym 0
7175 #undef elf_backend_strtab_flags
7176 #undef elf_backend_copy_special_section_fields
7178 /* NaCl uses substantially different PLT entries for the same effects. */
7180 #undef elf_backend_plt_alignment
7181 #define elf_backend_plt_alignment 5
7182 #define NACL_PLT_ENTRY_SIZE 64
7183 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7185 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
7187 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7188 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7189 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7190 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7191 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7193 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7194 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7196 /* 32 bytes of nop to pad out to the standard size. */
7197 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7198 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7199 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7200 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7201 0x66, /* excess data16 prefix */
7205 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7207 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7208 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7209 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7210 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7212 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7213 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7214 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7216 /* Lazy GOT entries point here (32-byte aligned). */
7217 0x68, /* pushq immediate */
7218 0, 0, 0, 0, /* replaced with index into relocation table. */
7219 0xe9, /* jmp relative */
7220 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7222 /* 22 bytes of nop to pad out to the standard size. */
7223 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7224 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7225 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7228 /* .eh_frame covering the .plt section. */
7230 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
7232 #if (PLT_CIE_LENGTH != 20 \
7233 || PLT_FDE_LENGTH != 36 \
7234 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7235 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7236 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7238 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7239 0, 0, 0, 0, /* CIE ID */
7240 1, /* CIE version */
7241 'z', 'R', 0, /* Augmentation string */
7242 1, /* Code alignment factor */
7243 0x78, /* Data alignment factor */
7244 16, /* Return address column */
7245 1, /* Augmentation size */
7246 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7247 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7248 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7249 DW_CFA_nop
, DW_CFA_nop
,
7251 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7252 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
7253 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7254 0, 0, 0, 0, /* .plt size goes here */
7255 0, /* Augmentation size */
7256 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
7257 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7258 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
7259 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7260 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7261 13, /* Block length */
7262 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7263 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7264 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7265 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7266 DW_CFA_nop
, DW_CFA_nop
7269 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7271 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7272 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7273 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7274 2, /* plt0_got1_offset */
7275 9, /* plt0_got2_offset */
7276 13, /* plt0_got2_insn_end */
7277 3, /* plt_got_offset */
7278 33, /* plt_reloc_offset */
7279 38, /* plt_plt_offset */
7280 7, /* plt_got_insn_size */
7281 42, /* plt_plt_insn_end */
7282 32, /* plt_lazy_offset */
7283 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7284 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
7285 NULL
, /* eh_frame_plt_got */
7286 0, /* eh_frame_plt_got_size */
7289 #undef elf_backend_arch_data
7290 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7292 #undef elf_backend_object_p
7293 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7294 #undef elf_backend_modify_segment_map
7295 #define elf_backend_modify_segment_map nacl_modify_segment_map
7296 #undef elf_backend_modify_program_headers
7297 #define elf_backend_modify_program_headers nacl_modify_program_headers
7298 #undef elf_backend_final_write_processing
7299 #define elf_backend_final_write_processing nacl_final_write_processing
7301 #include "elf64-target.h"
7303 /* Native Client x32 support. */
7306 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7308 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7309 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7313 #undef TARGET_LITTLE_SYM
7314 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7315 #undef TARGET_LITTLE_NAME
7316 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7318 #define elf32_bed elf32_x86_64_nacl_bed
7320 #define bfd_elf32_bfd_link_hash_table_create \
7321 elf_x86_64_link_hash_table_create
7322 #define bfd_elf32_bfd_reloc_type_lookup \
7323 elf_x86_64_reloc_type_lookup
7324 #define bfd_elf32_bfd_reloc_name_lookup \
7325 elf_x86_64_reloc_name_lookup
7326 #define bfd_elf32_mkobject \
7328 #define bfd_elf32_get_synthetic_symtab \
7329 elf_x86_64_get_synthetic_symtab
7331 #undef elf_backend_object_p
7332 #define elf_backend_object_p \
7333 elf32_x86_64_nacl_elf_object_p
7335 #undef elf_backend_bfd_from_remote_memory
7336 #define elf_backend_bfd_from_remote_memory \
7337 _bfd_elf32_bfd_from_remote_memory
7339 #undef elf_backend_size_info
7340 #define elf_backend_size_info \
7341 _bfd_elf32_size_info
7343 #include "elf32-target.h"
7345 /* Restore defaults. */
7346 #undef elf_backend_object_p
7347 #define elf_backend_object_p elf64_x86_64_elf_object_p
7348 #undef elf_backend_bfd_from_remote_memory
7349 #undef elf_backend_size_info
7350 #undef elf_backend_modify_segment_map
7351 #undef elf_backend_modify_program_headers
7352 #undef elf_backend_final_write_processing
7354 /* Intel L1OM support. */
7357 elf64_l1om_elf_object_p (bfd
*abfd
)
7359 /* Set the right machine number for an L1OM elf64 file. */
7360 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7364 #undef TARGET_LITTLE_SYM
7365 #define TARGET_LITTLE_SYM l1om_elf64_vec
7366 #undef TARGET_LITTLE_NAME
7367 #define TARGET_LITTLE_NAME "elf64-l1om"
7369 #define ELF_ARCH bfd_arch_l1om
7371 #undef ELF_MACHINE_CODE
7372 #define ELF_MACHINE_CODE EM_L1OM
7377 #define elf64_bed elf64_l1om_bed
7379 #undef elf_backend_object_p
7380 #define elf_backend_object_p elf64_l1om_elf_object_p
7382 /* Restore defaults. */
7383 #undef ELF_MAXPAGESIZE
7384 #undef ELF_MINPAGESIZE
7385 #undef ELF_COMMONPAGESIZE
7386 #define ELF_MAXPAGESIZE 0x200000
7387 #define ELF_MINPAGESIZE 0x1000
7388 #define ELF_COMMONPAGESIZE 0x1000
7389 #undef elf_backend_plt_alignment
7390 #define elf_backend_plt_alignment 4
7391 #undef elf_backend_arch_data
7392 #define elf_backend_arch_data &elf_x86_64_arch_bed
7394 #include "elf64-target.h"
7396 /* FreeBSD L1OM support. */
7398 #undef TARGET_LITTLE_SYM
7399 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7400 #undef TARGET_LITTLE_NAME
7401 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7404 #define ELF_OSABI ELFOSABI_FREEBSD
7407 #define elf64_bed elf64_l1om_fbsd_bed
7409 #include "elf64-target.h"
7411 /* Intel K1OM support. */
7414 elf64_k1om_elf_object_p (bfd
*abfd
)
7416 /* Set the right machine number for an K1OM elf64 file. */
7417 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7421 #undef TARGET_LITTLE_SYM
7422 #define TARGET_LITTLE_SYM k1om_elf64_vec
7423 #undef TARGET_LITTLE_NAME
7424 #define TARGET_LITTLE_NAME "elf64-k1om"
7426 #define ELF_ARCH bfd_arch_k1om
7428 #undef ELF_MACHINE_CODE
7429 #define ELF_MACHINE_CODE EM_K1OM
7434 #define elf64_bed elf64_k1om_bed
7436 #undef elf_backend_object_p
7437 #define elf_backend_object_p elf64_k1om_elf_object_p
7439 #undef elf_backend_static_tls_alignment
7441 #undef elf_backend_want_plt_sym
7442 #define elf_backend_want_plt_sym 0
7444 #include "elf64-target.h"
7446 /* FreeBSD K1OM support. */
7448 #undef TARGET_LITTLE_SYM
7449 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7450 #undef TARGET_LITTLE_NAME
7451 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7454 #define ELF_OSABI ELFOSABI_FREEBSD
7457 #define elf64_bed elf64_k1om_fbsd_bed
7459 #include "elf64-target.h"
7461 /* 32bit x86-64 support. */
7463 #undef TARGET_LITTLE_SYM
7464 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7465 #undef TARGET_LITTLE_NAME
7466 #define TARGET_LITTLE_NAME "elf32-x86-64"
7470 #define ELF_ARCH bfd_arch_i386
7472 #undef ELF_MACHINE_CODE
7473 #define ELF_MACHINE_CODE EM_X86_64
7477 #undef elf_backend_object_p
7478 #define elf_backend_object_p \
7479 elf32_x86_64_elf_object_p
7481 #undef elf_backend_bfd_from_remote_memory
7482 #define elf_backend_bfd_from_remote_memory \
7483 _bfd_elf32_bfd_from_remote_memory
7485 #undef elf_backend_size_info
7486 #define elf_backend_size_info \
7487 _bfd_elf32_size_info
7489 #include "elf32-target.h"