1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2016 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 /* Architecture-specific backend data for x86-64. */
664 struct elf_x86_64_backend_data
666 /* Templates for the initial PLT entry and for subsequent entries. */
667 const bfd_byte
*plt0_entry
;
668 const bfd_byte
*plt_entry
;
669 unsigned int plt_entry_size
; /* Size of each PLT entry. */
671 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
672 unsigned int plt0_got1_offset
;
673 unsigned int plt0_got2_offset
;
675 /* Offset of the end of the PC-relative instruction containing
677 unsigned int plt0_got2_insn_end
;
679 /* Offsets into plt_entry that are to be replaced with... */
680 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
681 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
682 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
684 /* Length of the PC-relative instruction containing plt_got_offset. */
685 unsigned int plt_got_insn_size
;
687 /* Offset of the end of the PC-relative jump to plt0_entry. */
688 unsigned int plt_plt_insn_end
;
690 /* Offset into plt_entry where the initial value of the GOT entry points. */
691 unsigned int plt_lazy_offset
;
693 /* .eh_frame covering the .plt section. */
694 const bfd_byte
*eh_frame_plt
;
695 unsigned int eh_frame_plt_size
;
698 #define get_elf_x86_64_arch_data(bed) \
699 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
701 #define get_elf_x86_64_backend_data(abfd) \
702 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
704 #define GET_PLT_ENTRY_SIZE(abfd) \
705 get_elf_x86_64_backend_data (abfd)->plt_entry_size
707 /* These are the standard parameters. */
708 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
710 elf_x86_64_plt0_entry
, /* plt0_entry */
711 elf_x86_64_plt_entry
, /* plt_entry */
712 sizeof (elf_x86_64_plt_entry
), /* plt_entry_size */
713 2, /* plt0_got1_offset */
714 8, /* plt0_got2_offset */
715 12, /* plt0_got2_insn_end */
716 2, /* plt_got_offset */
717 7, /* plt_reloc_offset */
718 12, /* plt_plt_offset */
719 6, /* plt_got_insn_size */
720 PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
721 6, /* plt_lazy_offset */
722 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
723 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
726 static const struct elf_x86_64_backend_data elf_x86_64_bnd_arch_bed
=
728 elf_x86_64_bnd_plt0_entry
, /* plt0_entry */
729 elf_x86_64_bnd_plt_entry
, /* plt_entry */
730 sizeof (elf_x86_64_bnd_plt_entry
), /* plt_entry_size */
731 2, /* plt0_got1_offset */
732 1+8, /* plt0_got2_offset */
733 1+12, /* plt0_got2_insn_end */
734 1+2, /* plt_got_offset */
735 1, /* plt_reloc_offset */
736 7, /* plt_plt_offset */
737 1+6, /* plt_got_insn_size */
738 11, /* plt_plt_insn_end */
739 0, /* plt_lazy_offset */
740 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
741 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
744 #define elf_backend_arch_data &elf_x86_64_arch_bed
746 /* Is a undefined weak symbol which is resolved to 0. Reference to an
747 undefined weak symbol is resolved to 0 when building executable if
749 1. Has non-GOT/non-PLT relocations in text section. Or
750 2. Has no GOT/PLT relocation.
752 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
753 ((EH)->elf.root.type == bfd_link_hash_undefweak \
754 && bfd_link_executable (INFO) \
755 && (elf_x86_64_hash_table (INFO)->interp == NULL \
757 || (EH)->has_non_got_reloc \
758 || !(INFO)->dynamic_undefined_weak))
760 /* x86-64 ELF linker hash entry. */
762 struct elf_x86_64_link_hash_entry
764 struct elf_link_hash_entry elf
;
766 /* Track dynamic relocs copied for this symbol. */
767 struct elf_dyn_relocs
*dyn_relocs
;
769 #define GOT_UNKNOWN 0
773 #define GOT_TLS_GDESC 4
774 #define GOT_TLS_GD_BOTH_P(type) \
775 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
776 #define GOT_TLS_GD_P(type) \
777 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
778 #define GOT_TLS_GDESC_P(type) \
779 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
780 #define GOT_TLS_GD_ANY_P(type) \
781 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
782 unsigned char tls_type
;
784 /* TRUE if a weak symbol with a real definition needs a copy reloc.
785 When there is a weak symbol with a real definition, the processor
786 independent code will have arranged for us to see the real
787 definition first. We need to copy the needs_copy bit from the
788 real definition and check it when allowing copy reloc in PIE. */
789 unsigned int needs_copy
: 1;
791 /* TRUE if symbol has at least one BND relocation. */
792 unsigned int has_bnd_reloc
: 1;
794 /* TRUE if symbol has GOT or PLT relocations. */
795 unsigned int has_got_reloc
: 1;
797 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
798 unsigned int has_non_got_reloc
: 1;
800 /* 0: symbol isn't __tls_get_addr.
801 1: symbol is __tls_get_addr.
802 2: symbol is unknown. */
803 unsigned int tls_get_addr
: 2;
805 /* Reference count of C/C++ function pointer relocations in read-write
806 section which can be resolved at run-time. */
807 bfd_signed_vma func_pointer_refcount
;
809 /* Information about the GOT PLT entry. Filled when there are both
810 GOT and PLT relocations against the same function. */
811 union gotplt_union plt_got
;
813 /* Information about the second PLT entry. Filled when has_bnd_reloc is
815 union gotplt_union plt_bnd
;
817 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
818 starting at the end of the jump table. */
822 #define elf_x86_64_hash_entry(ent) \
823 ((struct elf_x86_64_link_hash_entry *)(ent))
825 struct elf_x86_64_obj_tdata
827 struct elf_obj_tdata root
;
829 /* tls_type for each local got entry. */
830 char *local_got_tls_type
;
832 /* GOTPLT entries for TLS descriptors. */
833 bfd_vma
*local_tlsdesc_gotent
;
836 #define elf_x86_64_tdata(abfd) \
837 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
839 #define elf_x86_64_local_got_tls_type(abfd) \
840 (elf_x86_64_tdata (abfd)->local_got_tls_type)
842 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
843 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
845 #define is_x86_64_elf(bfd) \
846 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
847 && elf_tdata (bfd) != NULL \
848 && elf_object_id (bfd) == X86_64_ELF_DATA)
851 elf_x86_64_mkobject (bfd
*abfd
)
853 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
857 /* x86-64 ELF linker hash table. */
859 struct elf_x86_64_link_hash_table
861 struct elf_link_hash_table elf
;
863 /* Short-cuts to get to dynamic linker sections. */
867 asection
*plt_eh_frame
;
873 bfd_signed_vma refcount
;
877 /* The amount of space used by the jump slots in the GOT. */
878 bfd_vma sgotplt_jump_table_size
;
880 /* Small local sym cache. */
881 struct sym_cache sym_cache
;
883 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
884 bfd_vma (*r_sym
) (bfd_vma
);
885 unsigned int pointer_r_type
;
886 const char *dynamic_interpreter
;
887 int dynamic_interpreter_size
;
889 /* _TLS_MODULE_BASE_ symbol. */
890 struct bfd_link_hash_entry
*tls_module_base
;
892 /* Used by local STT_GNU_IFUNC symbols. */
893 htab_t loc_hash_table
;
894 void * loc_hash_memory
;
896 /* The offset into splt of the PLT entry for the TLS descriptor
897 resolver. Special values are 0, if not necessary (or not found
898 to be necessary yet), and -1 if needed but not determined
901 /* The offset into sgot of the GOT entry used by the PLT entry
905 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
906 bfd_vma next_jump_slot_index
;
907 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
908 bfd_vma next_irelative_index
;
910 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
911 to read-only sections. */
912 bfd_boolean readonly_dynrelocs_against_ifunc
;
915 /* Get the x86-64 ELF linker hash table from a link_info structure. */
917 #define elf_x86_64_hash_table(p) \
918 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
919 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
921 #define elf_x86_64_compute_jump_table_size(htab) \
922 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
924 /* Create an entry in an x86-64 ELF linker hash table. */
926 static struct bfd_hash_entry
*
927 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
928 struct bfd_hash_table
*table
,
931 /* Allocate the structure if it has not already been allocated by a
935 entry
= (struct bfd_hash_entry
*)
936 bfd_hash_allocate (table
,
937 sizeof (struct elf_x86_64_link_hash_entry
));
942 /* Call the allocation method of the superclass. */
943 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
946 struct elf_x86_64_link_hash_entry
*eh
;
948 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
949 eh
->dyn_relocs
= NULL
;
950 eh
->tls_type
= GOT_UNKNOWN
;
952 eh
->has_bnd_reloc
= 0;
953 eh
->has_got_reloc
= 0;
954 eh
->has_non_got_reloc
= 0;
955 eh
->tls_get_addr
= 2;
956 eh
->func_pointer_refcount
= 0;
957 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
958 eh
->plt_got
.offset
= (bfd_vma
) -1;
959 eh
->tlsdesc_got
= (bfd_vma
) -1;
965 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
966 for local symbol so that we can handle local STT_GNU_IFUNC symbols
967 as global symbol. We reuse indx and dynstr_index for local symbol
968 hash since they aren't used by global symbols in this backend. */
971 elf_x86_64_local_htab_hash (const void *ptr
)
973 struct elf_link_hash_entry
*h
974 = (struct elf_link_hash_entry
*) ptr
;
975 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
978 /* Compare local hash entries. */
981 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
983 struct elf_link_hash_entry
*h1
984 = (struct elf_link_hash_entry
*) ptr1
;
985 struct elf_link_hash_entry
*h2
986 = (struct elf_link_hash_entry
*) ptr2
;
988 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
991 /* Find and/or create a hash entry for local symbol. */
993 static struct elf_link_hash_entry
*
994 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
995 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
998 struct elf_x86_64_link_hash_entry e
, *ret
;
999 asection
*sec
= abfd
->sections
;
1000 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1001 htab
->r_sym (rel
->r_info
));
1004 e
.elf
.indx
= sec
->id
;
1005 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1006 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1007 create
? INSERT
: NO_INSERT
);
1014 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1018 ret
= (struct elf_x86_64_link_hash_entry
*)
1019 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1020 sizeof (struct elf_x86_64_link_hash_entry
));
1023 memset (ret
, 0, sizeof (*ret
));
1024 ret
->elf
.indx
= sec
->id
;
1025 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1026 ret
->elf
.dynindx
= -1;
1027 ret
->func_pointer_refcount
= 0;
1028 ret
->plt_got
.offset
= (bfd_vma
) -1;
1034 /* Destroy an X86-64 ELF linker hash table. */
1037 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1039 struct elf_x86_64_link_hash_table
*htab
1040 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1042 if (htab
->loc_hash_table
)
1043 htab_delete (htab
->loc_hash_table
);
1044 if (htab
->loc_hash_memory
)
1045 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1046 _bfd_elf_link_hash_table_free (obfd
);
1049 /* Create an X86-64 ELF linker hash table. */
1051 static struct bfd_link_hash_table
*
1052 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1054 struct elf_x86_64_link_hash_table
*ret
;
1055 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1057 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1061 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1062 elf_x86_64_link_hash_newfunc
,
1063 sizeof (struct elf_x86_64_link_hash_entry
),
1070 if (ABI_64_P (abfd
))
1072 ret
->r_info
= elf64_r_info
;
1073 ret
->r_sym
= elf64_r_sym
;
1074 ret
->pointer_r_type
= R_X86_64_64
;
1075 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1076 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1080 ret
->r_info
= elf32_r_info
;
1081 ret
->r_sym
= elf32_r_sym
;
1082 ret
->pointer_r_type
= R_X86_64_32
;
1083 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1084 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1087 ret
->loc_hash_table
= htab_try_create (1024,
1088 elf_x86_64_local_htab_hash
,
1089 elf_x86_64_local_htab_eq
,
1091 ret
->loc_hash_memory
= objalloc_create ();
1092 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1094 elf_x86_64_link_hash_table_free (abfd
);
1097 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1099 return &ret
->elf
.root
;
1102 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
1103 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1107 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
1108 struct bfd_link_info
*info
)
1110 struct elf_x86_64_link_hash_table
*htab
;
1112 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1115 htab
= elf_x86_64_hash_table (info
);
1119 /* Set the contents of the .interp section to the interpreter. */
1120 if (bfd_link_executable (info
) && !info
->nointerp
)
1122 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
1125 s
->size
= htab
->dynamic_interpreter_size
;
1126 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
1130 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
1134 if (bfd_link_executable (info
))
1136 /* Always allow copy relocs for building executables. */
1137 asection
*s
= bfd_get_linker_section (dynobj
, ".rela.bss");
1140 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
1141 s
= bfd_make_section_anyway_with_flags (dynobj
,
1143 (bed
->dynamic_sec_flags
1146 || ! bfd_set_section_alignment (dynobj
, s
,
1147 bed
->s
->log_file_align
))
1153 if (!info
->no_ld_generated_unwind_info
1154 && htab
->plt_eh_frame
== NULL
1155 && htab
->elf
.splt
!= NULL
)
1157 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1158 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1159 | SEC_LINKER_CREATED
);
1161 = bfd_make_section_anyway_with_flags (dynobj
, ".eh_frame", flags
);
1162 if (htab
->plt_eh_frame
== NULL
1163 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
1167 /* Align .got section to its entry size. */
1168 if (htab
->elf
.sgot
!= NULL
1169 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgot
, 3))
1172 /* Align .got.plt section to its entry size. */
1173 if (htab
->elf
.sgotplt
!= NULL
1174 && !bfd_set_section_alignment (dynobj
, htab
->elf
.sgotplt
, 3))
1180 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1183 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1184 struct elf_link_hash_entry
*dir
,
1185 struct elf_link_hash_entry
*ind
)
1187 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1189 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1190 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1192 if (!edir
->has_bnd_reloc
)
1193 edir
->has_bnd_reloc
= eind
->has_bnd_reloc
;
1195 if (!edir
->has_got_reloc
)
1196 edir
->has_got_reloc
= eind
->has_got_reloc
;
1198 if (!edir
->has_non_got_reloc
)
1199 edir
->has_non_got_reloc
= eind
->has_non_got_reloc
;
1201 if (eind
->dyn_relocs
!= NULL
)
1203 if (edir
->dyn_relocs
!= NULL
)
1205 struct elf_dyn_relocs
**pp
;
1206 struct elf_dyn_relocs
*p
;
1208 /* Add reloc counts against the indirect sym to the direct sym
1209 list. Merge any entries against the same section. */
1210 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1212 struct elf_dyn_relocs
*q
;
1214 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1215 if (q
->sec
== p
->sec
)
1217 q
->pc_count
+= p
->pc_count
;
1218 q
->count
+= p
->count
;
1225 *pp
= edir
->dyn_relocs
;
1228 edir
->dyn_relocs
= eind
->dyn_relocs
;
1229 eind
->dyn_relocs
= NULL
;
1232 if (ind
->root
.type
== bfd_link_hash_indirect
1233 && dir
->got
.refcount
<= 0)
1235 edir
->tls_type
= eind
->tls_type
;
1236 eind
->tls_type
= GOT_UNKNOWN
;
1239 if (ELIMINATE_COPY_RELOCS
1240 && ind
->root
.type
!= bfd_link_hash_indirect
1241 && dir
->dynamic_adjusted
)
1243 /* If called to transfer flags for a weakdef during processing
1244 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1245 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1246 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1247 dir
->ref_regular
|= ind
->ref_regular
;
1248 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1249 dir
->needs_plt
|= ind
->needs_plt
;
1250 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1254 if (eind
->func_pointer_refcount
> 0)
1256 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1257 eind
->func_pointer_refcount
= 0;
1260 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1265 elf64_x86_64_elf_object_p (bfd
*abfd
)
1267 /* Set the right machine number for an x86-64 elf64 file. */
1268 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1273 elf32_x86_64_elf_object_p (bfd
*abfd
)
1275 /* Set the right machine number for an x86-64 elf32 file. */
1276 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1280 /* Return TRUE if the TLS access code sequence support transition
1284 elf_x86_64_check_tls_transition (bfd
*abfd
,
1285 struct bfd_link_info
*info
,
1288 Elf_Internal_Shdr
*symtab_hdr
,
1289 struct elf_link_hash_entry
**sym_hashes
,
1290 unsigned int r_type
,
1291 const Elf_Internal_Rela
*rel
,
1292 const Elf_Internal_Rela
*relend
)
1295 unsigned long r_symndx
;
1296 bfd_boolean largepic
= FALSE
;
1297 struct elf_link_hash_entry
*h
;
1299 struct elf_x86_64_link_hash_table
*htab
;
1301 bfd_boolean indirect_call
, tls_get_addr
;
1303 htab
= elf_x86_64_hash_table (info
);
1304 offset
= rel
->r_offset
;
1307 case R_X86_64_TLSGD
:
1308 case R_X86_64_TLSLD
:
1309 if ((rel
+ 1) >= relend
)
1312 if (r_type
== R_X86_64_TLSGD
)
1314 /* Check transition from GD access model. For 64bit, only
1315 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1316 .word 0x6666; rex64; call __tls_get_addr@PLT
1318 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1320 call *__tls_get_addr@GOTPCREL(%rip)
1321 which may be converted to
1322 addr32 call __tls_get_addr
1323 can transit to different access model. For 32bit, only
1324 leaq foo@tlsgd(%rip), %rdi
1325 .word 0x6666; rex64; call __tls_get_addr@PLT
1327 leaq foo@tlsgd(%rip), %rdi
1329 call *__tls_get_addr@GOTPCREL(%rip)
1330 which may be converted to
1331 addr32 call __tls_get_addr
1332 can transit to different access model. For largepic,
1334 leaq foo@tlsgd(%rip), %rdi
1335 movabsq $__tls_get_addr@pltoff, %rax
1339 leaq foo@tlsgd(%rip), %rdi
1340 movabsq $__tls_get_addr@pltoff, %rax
1344 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1346 if ((offset
+ 12) > sec
->size
)
1349 call
= contents
+ offset
+ 4;
1351 || !((call
[1] == 0x48
1359 && call
[3] == 0xe8)))
1361 if (!ABI_64_P (abfd
)
1362 || (offset
+ 19) > sec
->size
1364 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1365 || memcmp (call
, "\x48\xb8", 2) != 0
1369 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1370 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1374 else if (ABI_64_P (abfd
))
1377 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1383 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1386 indirect_call
= call
[2] == 0xff;
1390 /* Check transition from LD access model. Only
1391 leaq foo@tlsld(%rip), %rdi;
1392 call __tls_get_addr@PLT
1394 leaq foo@tlsld(%rip), %rdi;
1395 call *__tls_get_addr@GOTPCREL(%rip)
1396 which may be converted to
1397 addr32 call __tls_get_addr
1398 can transit to different access model. For largepic
1400 leaq foo@tlsld(%rip), %rdi
1401 movabsq $__tls_get_addr@pltoff, %rax
1405 leaq foo@tlsld(%rip), %rdi
1406 movabsq $__tls_get_addr@pltoff, %rax
1410 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1412 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1415 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1418 call
= contents
+ offset
+ 4;
1419 if (!(call
[0] == 0xe8
1420 || (call
[0] == 0xff && call
[1] == 0x15)
1421 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1423 if (!ABI_64_P (abfd
)
1424 || (offset
+ 19) > sec
->size
1425 || memcmp (call
, "\x48\xb8", 2) != 0
1429 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1430 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1434 indirect_call
= call
[0] == 0xff;
1437 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1438 if (r_symndx
< symtab_hdr
->sh_info
)
1441 tls_get_addr
= FALSE
;
1442 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1443 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1445 struct elf_x86_64_link_hash_entry
*eh
1446 = (struct elf_x86_64_link_hash_entry
*) h
;
1447 tls_get_addr
= eh
->tls_get_addr
== 1;
1448 if (eh
->tls_get_addr
> 1)
1450 /* Use strncmp to check __tls_get_addr since
1451 __tls_get_addr may be versioned. */
1452 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1455 eh
->tls_get_addr
= 1;
1456 tls_get_addr
= TRUE
;
1459 eh
->tls_get_addr
= 0;
1466 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1467 else if (indirect_call
)
1468 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1470 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1471 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1473 case R_X86_64_GOTTPOFF
:
1474 /* Check transition from IE access model:
1475 mov foo@gottpoff(%rip), %reg
1476 add foo@gottpoff(%rip), %reg
1479 /* Check REX prefix first. */
1480 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1482 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1483 if (val
!= 0x48 && val
!= 0x4c)
1485 /* X32 may have 0x44 REX prefix or no REX prefix. */
1486 if (ABI_64_P (abfd
))
1492 /* X32 may not have any REX prefix. */
1493 if (ABI_64_P (abfd
))
1495 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1499 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1500 if (val
!= 0x8b && val
!= 0x03)
1503 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1504 return (val
& 0xc7) == 5;
1506 case R_X86_64_GOTPC32_TLSDESC
:
1507 /* Check transition from GDesc access model:
1508 leaq x@tlsdesc(%rip), %rax
1510 Make sure it's a leaq adding rip to a 32-bit offset
1511 into any register, although it's probably almost always
1514 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1517 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1518 if ((val
& 0xfb) != 0x48)
1521 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1524 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1525 return (val
& 0xc7) == 0x05;
1527 case R_X86_64_TLSDESC_CALL
:
1528 /* Check transition from GDesc access model:
1529 call *x@tlsdesc(%rax)
1531 if (offset
+ 2 <= sec
->size
)
1533 /* Make sure that it's a call *x@tlsdesc(%rax). */
1534 call
= contents
+ offset
;
1535 return call
[0] == 0xff && call
[1] == 0x10;
1545 /* Return TRUE if the TLS access transition is OK or no transition
1546 will be performed. Update R_TYPE if there is a transition. */
1549 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1550 asection
*sec
, bfd_byte
*contents
,
1551 Elf_Internal_Shdr
*symtab_hdr
,
1552 struct elf_link_hash_entry
**sym_hashes
,
1553 unsigned int *r_type
, int tls_type
,
1554 const Elf_Internal_Rela
*rel
,
1555 const Elf_Internal_Rela
*relend
,
1556 struct elf_link_hash_entry
*h
,
1557 unsigned long r_symndx
,
1558 bfd_boolean from_relocate_section
)
1560 unsigned int from_type
= *r_type
;
1561 unsigned int to_type
= from_type
;
1562 bfd_boolean check
= TRUE
;
1564 /* Skip TLS transition for functions. */
1566 && (h
->type
== STT_FUNC
1567 || h
->type
== STT_GNU_IFUNC
))
1572 case R_X86_64_TLSGD
:
1573 case R_X86_64_GOTPC32_TLSDESC
:
1574 case R_X86_64_TLSDESC_CALL
:
1575 case R_X86_64_GOTTPOFF
:
1576 if (bfd_link_executable (info
))
1579 to_type
= R_X86_64_TPOFF32
;
1581 to_type
= R_X86_64_GOTTPOFF
;
1584 /* When we are called from elf_x86_64_relocate_section, there may
1585 be additional transitions based on TLS_TYPE. */
1586 if (from_relocate_section
)
1588 unsigned int new_to_type
= to_type
;
1590 if (bfd_link_executable (info
)
1593 && tls_type
== GOT_TLS_IE
)
1594 new_to_type
= R_X86_64_TPOFF32
;
1596 if (to_type
== R_X86_64_TLSGD
1597 || to_type
== R_X86_64_GOTPC32_TLSDESC
1598 || to_type
== R_X86_64_TLSDESC_CALL
)
1600 if (tls_type
== GOT_TLS_IE
)
1601 new_to_type
= R_X86_64_GOTTPOFF
;
1604 /* We checked the transition before when we were called from
1605 elf_x86_64_check_relocs. We only want to check the new
1606 transition which hasn't been checked before. */
1607 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1608 to_type
= new_to_type
;
1613 case R_X86_64_TLSLD
:
1614 if (bfd_link_executable (info
))
1615 to_type
= R_X86_64_TPOFF32
;
1622 /* Return TRUE if there is no transition. */
1623 if (from_type
== to_type
)
1626 /* Check if the transition can be performed. */
1628 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1629 symtab_hdr
, sym_hashes
,
1630 from_type
, rel
, relend
))
1632 reloc_howto_type
*from
, *to
;
1635 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1636 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1639 name
= h
->root
.root
.string
;
1642 struct elf_x86_64_link_hash_table
*htab
;
1644 htab
= elf_x86_64_hash_table (info
);
1649 Elf_Internal_Sym
*isym
;
1651 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1653 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1658 /* xgettext:c-format */
1659 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1660 "in section `%A' failed"),
1661 abfd
, sec
, from
->name
, to
->name
, name
,
1662 (unsigned long) rel
->r_offset
);
1663 bfd_set_error (bfd_error_bad_value
);
1671 /* Rename some of the generic section flags to better document how they
1673 #define need_convert_load sec_flg0
1674 #define check_relocs_failed sec_flg1
1677 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1678 struct elf_link_hash_entry
*h
,
1679 Elf_Internal_Shdr
*symtab_hdr
,
1680 Elf_Internal_Sym
*isym
,
1681 reloc_howto_type
*howto
)
1684 const char *und
= "";
1685 const char *pic
= "";
1690 name
= h
->root
.root
.string
;
1691 switch (ELF_ST_VISIBILITY (h
->other
))
1694 v
= _("hidden symbol ");
1697 v
= _("internal symbol ");
1700 v
= _("protected symbol ");
1704 pic
= _("; recompile with -fPIC");
1708 if (!h
->def_regular
&& !h
->def_dynamic
)
1709 und
= _("undefined ");
1713 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1714 pic
= _("; recompile with -fPIC");
1717 /* xgettext:c-format */
1718 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1719 "not be used when making a shared object%s"),
1720 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1721 bfd_set_error (bfd_error_bad_value
);
1722 sec
->check_relocs_failed
= 1;
1726 /* With the local symbol, foo, we convert
1727 mov foo@GOTPCREL(%rip), %reg
1731 call/jmp *foo@GOTPCREL(%rip)
1733 nop call foo/jmp foo nop
1734 When PIC is false, convert
1735 test %reg, foo@GOTPCREL(%rip)
1739 binop foo@GOTPCREL(%rip), %reg
1742 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1746 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1748 Elf_Internal_Rela
*irel
,
1749 struct elf_link_hash_entry
*h
,
1750 bfd_boolean
*converted
,
1751 struct bfd_link_info
*link_info
)
1753 struct elf_x86_64_link_hash_table
*htab
;
1755 bfd_boolean require_reloc_pc32
;
1757 bfd_boolean to_reloc_pc32
;
1760 bfd_signed_vma raddend
;
1761 unsigned int opcode
;
1763 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1764 unsigned int r_symndx
;
1766 bfd_vma roff
= irel
->r_offset
;
1768 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1771 raddend
= irel
->r_addend
;
1772 /* Addend for 32-bit PC-relative relocation must be -4. */
1776 htab
= elf_x86_64_hash_table (link_info
);
1777 is_pic
= bfd_link_pic (link_info
);
1779 relocx
= (r_type
== R_X86_64_GOTPCRELX
1780 || r_type
== R_X86_64_REX_GOTPCRELX
);
1782 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1785 = link_info
->disable_target_specific_optimizations
> 1;
1787 r_symndx
= htab
->r_sym (irel
->r_info
);
1789 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1791 /* Convert mov to lea since it has been done for a while. */
1794 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1795 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1796 test, xor instructions. */
1801 /* We convert only to R_X86_64_PC32:
1803 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1804 3. require_reloc_pc32 is true.
1807 to_reloc_pc32
= (opcode
== 0xff
1809 || require_reloc_pc32
1812 /* Get the symbol referred to by the reloc. */
1815 Elf_Internal_Sym
*isym
1816 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1818 /* Skip relocation against undefined symbols. */
1819 if (isym
->st_shndx
== SHN_UNDEF
)
1822 symtype
= ELF_ST_TYPE (isym
->st_info
);
1824 if (isym
->st_shndx
== SHN_ABS
)
1825 tsec
= bfd_abs_section_ptr
;
1826 else if (isym
->st_shndx
== SHN_COMMON
)
1827 tsec
= bfd_com_section_ptr
;
1828 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1829 tsec
= &_bfd_elf_large_com_section
;
1831 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1833 toff
= isym
->st_value
;
1837 /* Undefined weak symbol is only bound locally in executable
1838 and its reference is resolved as 0 without relocation
1839 overflow. We can only perform this optimization for
1840 GOTPCRELX relocations since we need to modify REX byte.
1841 It is OK convert mov with R_X86_64_GOTPCREL to
1843 if ((relocx
|| opcode
== 0x8b)
1844 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1846 elf_x86_64_hash_entry (h
)))
1850 /* Skip for branch instructions since R_X86_64_PC32
1852 if (require_reloc_pc32
)
1857 /* For non-branch instructions, we can convert to
1858 R_X86_64_32/R_X86_64_32S since we know if there
1860 to_reloc_pc32
= FALSE
;
1863 /* Since we don't know the current PC when PIC is true,
1864 we can't convert to R_X86_64_PC32. */
1865 if (to_reloc_pc32
&& is_pic
)
1870 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1871 ld.so may use its link-time address. */
1872 else if ((h
->def_regular
1873 || h
->root
.type
== bfd_link_hash_defined
1874 || h
->root
.type
== bfd_link_hash_defweak
)
1875 && h
!= htab
->elf
.hdynamic
1876 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1878 /* bfd_link_hash_new or bfd_link_hash_undefined is
1879 set by an assignment in a linker script in
1880 bfd_elf_record_link_assignment. */
1882 && (h
->root
.type
== bfd_link_hash_new
1883 || h
->root
.type
== bfd_link_hash_undefined
1884 || ((h
->root
.type
== bfd_link_hash_defined
1885 || h
->root
.type
== bfd_link_hash_defweak
)
1886 && h
->root
.u
.def
.section
== bfd_und_section_ptr
)))
1888 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1889 if (require_reloc_pc32
)
1893 tsec
= h
->root
.u
.def
.section
;
1894 toff
= h
->root
.u
.def
.value
;
1901 /* Don't convert GOTPCREL relocation against large section. */
1902 if (elf_section_data (tsec
) != NULL
1903 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1906 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1910 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1912 /* At this stage in linking, no SEC_MERGE symbol has been
1913 adjusted, so all references to such symbols need to be
1914 passed through _bfd_merged_section_offset. (Later, in
1915 relocate_section, all SEC_MERGE symbols *except* for
1916 section symbols have been adjusted.)
1918 gas may reduce relocations against symbols in SEC_MERGE
1919 sections to a relocation against the section symbol when
1920 the original addend was zero. When the reloc is against
1921 a section symbol we should include the addend in the
1922 offset passed to _bfd_merged_section_offset, since the
1923 location of interest is the original symbol. On the
1924 other hand, an access to "sym+addend" where "sym" is not
1925 a section symbol should not include the addend; Such an
1926 access is presumed to be an offset from "sym"; The
1927 location of interest is just "sym". */
1928 if (symtype
== STT_SECTION
)
1931 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1932 elf_section_data (tsec
)->sec_info
,
1935 if (symtype
!= STT_SECTION
)
1941 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1942 if (tsec
->output_section
== sec
->output_section
)
1944 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
1949 bfd_signed_vma distance
;
1951 /* At this point, we don't know the load addresses of TSEC
1952 section nor SEC section. We estimate the distrance between
1953 SEC and TSEC. We store the estimated distances in the
1954 compressed_size field of the output section, which is only
1955 used to decompress the compressed input section. */
1956 if (sec
->output_section
->compressed_size
== 0)
1959 bfd_size_type size
= 0;
1960 for (asect
= link_info
->output_bfd
->sections
;
1962 asect
= asect
->next
)
1963 /* Skip debug sections since compressed_size is used to
1964 compress debug sections. */
1965 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
1968 for (i
= asect
->map_head
.s
;
1972 size
= align_power (size
, i
->alignment_power
);
1975 asect
->compressed_size
= size
;
1979 /* Don't convert GOTPCREL relocations if TSEC isn't placed
1981 distance
= (tsec
->output_section
->compressed_size
1982 - sec
->output_section
->compressed_size
);
1986 /* Take PT_GNU_RELRO segment into account by adding
1988 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
1989 - roff
+ 0x80000000) > 0xffffffff)
1996 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2001 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2003 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2006 /* Convert to "jmp foo nop". */
2009 nop_offset
= irel
->r_offset
+ 3;
2010 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2011 irel
->r_offset
-= 1;
2012 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2016 struct elf_x86_64_link_hash_entry
*eh
2017 = (struct elf_x86_64_link_hash_entry
*) h
;
2019 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2022 /* To support TLS optimization, always use addr32 prefix for
2023 "call *__tls_get_addr@GOTPCREL(%rip)". */
2024 if (eh
&& eh
->tls_get_addr
== 1)
2027 nop_offset
= irel
->r_offset
- 2;
2031 nop
= link_info
->call_nop_byte
;
2032 if (link_info
->call_nop_as_suffix
)
2034 nop_offset
= irel
->r_offset
+ 3;
2035 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2036 irel
->r_offset
-= 1;
2037 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2040 nop_offset
= irel
->r_offset
- 2;
2043 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2044 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2045 r_type
= R_X86_64_PC32
;
2050 unsigned int rex_mask
= REX_R
;
2052 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2053 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2061 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2062 "lea foo(%rip), %reg". */
2064 r_type
= R_X86_64_PC32
;
2068 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2069 "mov $foo, %reg". */
2071 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2072 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2073 if ((rex
& REX_W
) != 0
2074 && ABI_64_P (link_info
->output_bfd
))
2076 /* Keep the REX_W bit in REX byte for LP64. */
2077 r_type
= R_X86_64_32S
;
2078 goto rewrite_modrm_rex
;
2082 /* If the REX_W bit in REX byte isn't needed,
2083 use R_X86_64_32 and clear the W bit to avoid
2084 sign-extend imm32 to imm64. */
2085 r_type
= R_X86_64_32
;
2086 /* Clear the W bit in REX byte. */
2088 goto rewrite_modrm_rex
;
2094 /* R_X86_64_PC32 isn't supported. */
2098 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2101 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2102 "test $foo, %reg". */
2103 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2108 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2109 "binop $foo, %reg". */
2110 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2114 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2115 overflow when sign-extending imm32 to imm64. */
2116 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2119 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2123 /* Move the R bit to the B bit in REX byte. */
2124 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2125 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2128 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2132 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2135 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2142 /* Look through the relocs for a section during the first phase, and
2143 calculate needed space in the global offset table, procedure
2144 linkage table, and dynamic reloc sections. */
2147 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2149 const Elf_Internal_Rela
*relocs
)
2151 struct elf_x86_64_link_hash_table
*htab
;
2152 Elf_Internal_Shdr
*symtab_hdr
;
2153 struct elf_link_hash_entry
**sym_hashes
;
2154 const Elf_Internal_Rela
*rel
;
2155 const Elf_Internal_Rela
*rel_end
;
2158 bfd_boolean use_plt_got
;
2160 if (bfd_link_relocatable (info
))
2163 /* Don't do anything special with non-loaded, non-alloced sections.
2164 In particular, any relocs in such sections should not affect GOT
2165 and PLT reference counting (ie. we don't allow them to create GOT
2166 or PLT entries), there's no possibility or desire to optimize TLS
2167 relocs, and there's not much point in propagating relocs to shared
2168 libs that the dynamic linker won't relocate. */
2169 if ((sec
->flags
& SEC_ALLOC
) == 0)
2172 BFD_ASSERT (is_x86_64_elf (abfd
));
2174 htab
= elf_x86_64_hash_table (info
);
2177 sec
->check_relocs_failed
= 1;
2181 /* Get the section contents. */
2182 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2183 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2184 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2186 sec
->check_relocs_failed
= 1;
2190 use_plt_got
= get_elf_x86_64_backend_data (abfd
) == &elf_x86_64_arch_bed
;
2192 symtab_hdr
= &elf_symtab_hdr (abfd
);
2193 sym_hashes
= elf_sym_hashes (abfd
);
2197 rel_end
= relocs
+ sec
->reloc_count
;
2198 for (rel
= relocs
; rel
< rel_end
; rel
++)
2200 unsigned int r_type
;
2201 unsigned long r_symndx
;
2202 struct elf_link_hash_entry
*h
;
2203 struct elf_x86_64_link_hash_entry
*eh
;
2204 Elf_Internal_Sym
*isym
;
2206 bfd_boolean size_reloc
;
2208 r_symndx
= htab
->r_sym (rel
->r_info
);
2209 r_type
= ELF32_R_TYPE (rel
->r_info
);
2211 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2213 /* xgettext:c-format */
2214 _bfd_error_handler (_("%B: bad symbol index: %d"),
2219 if (r_symndx
< symtab_hdr
->sh_info
)
2221 /* A local symbol. */
2222 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2227 /* Check relocation against local STT_GNU_IFUNC symbol. */
2228 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2230 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2235 /* Fake a STT_GNU_IFUNC symbol. */
2236 h
->type
= STT_GNU_IFUNC
;
2239 h
->forced_local
= 1;
2240 h
->root
.type
= bfd_link_hash_defined
;
2248 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2249 while (h
->root
.type
== bfd_link_hash_indirect
2250 || h
->root
.type
== bfd_link_hash_warning
)
2251 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2254 /* Check invalid x32 relocations. */
2255 if (!ABI_64_P (abfd
))
2261 case R_X86_64_DTPOFF64
:
2262 case R_X86_64_TPOFF64
:
2264 case R_X86_64_GOTOFF64
:
2265 case R_X86_64_GOT64
:
2266 case R_X86_64_GOTPCREL64
:
2267 case R_X86_64_GOTPC64
:
2268 case R_X86_64_GOTPLT64
:
2269 case R_X86_64_PLTOFF64
:
2272 name
= h
->root
.root
.string
;
2274 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2277 /* xgettext:c-format */
2278 (_("%B: relocation %s against symbol `%s' isn't "
2279 "supported in x32 mode"), abfd
,
2280 x86_64_elf_howto_table
[r_type
].name
, name
);
2281 bfd_set_error (bfd_error_bad_value
);
2294 case R_X86_64_PC32_BND
:
2295 case R_X86_64_PLT32_BND
:
2297 case R_X86_64_PLT32
:
2300 /* MPX PLT is supported only if elf_x86_64_arch_bed
2301 is used in 64-bit mode. */
2304 && (get_elf_x86_64_backend_data (abfd
)
2305 == &elf_x86_64_arch_bed
))
2307 elf_x86_64_hash_entry (h
)->has_bnd_reloc
= 1;
2309 /* Create the second PLT for Intel MPX support. */
2310 if (htab
->plt_bnd
== NULL
)
2312 unsigned int plt_bnd_align
;
2313 const struct elf_backend_data
*bed
;
2315 bed
= get_elf_backend_data (info
->output_bfd
);
2316 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt2_entry
) == 8
2317 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2318 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2321 if (htab
->elf
.dynobj
== NULL
)
2322 htab
->elf
.dynobj
= abfd
;
2324 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2326 (bed
->dynamic_sec_flags
2331 if (htab
->plt_bnd
== NULL
2332 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2342 case R_X86_64_GOTPCREL
:
2343 case R_X86_64_GOTPCRELX
:
2344 case R_X86_64_REX_GOTPCRELX
:
2345 case R_X86_64_GOTPCREL64
:
2346 if (htab
->elf
.dynobj
== NULL
)
2347 htab
->elf
.dynobj
= abfd
;
2348 /* Create the ifunc sections for static executables. */
2349 if (h
->type
== STT_GNU_IFUNC
2350 && !_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
,
2356 /* It is referenced by a non-shared object. */
2358 h
->root
.non_ir_ref
= 1;
2360 if (h
->type
== STT_GNU_IFUNC
)
2361 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2362 |= elf_gnu_symbol_ifunc
;
2365 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2366 symtab_hdr
, sym_hashes
,
2367 &r_type
, GOT_UNKNOWN
,
2368 rel
, rel_end
, h
, r_symndx
, FALSE
))
2371 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2374 case R_X86_64_TLSLD
:
2375 htab
->tls_ld_got
.refcount
+= 1;
2378 case R_X86_64_TPOFF32
:
2379 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2380 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2381 &x86_64_elf_howto_table
[r_type
]);
2383 eh
->has_got_reloc
= 1;
2386 case R_X86_64_GOTTPOFF
:
2387 if (!bfd_link_executable (info
))
2388 info
->flags
|= DF_STATIC_TLS
;
2391 case R_X86_64_GOT32
:
2392 case R_X86_64_GOTPCREL
:
2393 case R_X86_64_GOTPCRELX
:
2394 case R_X86_64_REX_GOTPCRELX
:
2395 case R_X86_64_TLSGD
:
2396 case R_X86_64_GOT64
:
2397 case R_X86_64_GOTPCREL64
:
2398 case R_X86_64_GOTPLT64
:
2399 case R_X86_64_GOTPC32_TLSDESC
:
2400 case R_X86_64_TLSDESC_CALL
:
2401 /* This symbol requires a global offset table entry. */
2403 int tls_type
, old_tls_type
;
2407 default: tls_type
= GOT_NORMAL
; break;
2408 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2409 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2410 case R_X86_64_GOTPC32_TLSDESC
:
2411 case R_X86_64_TLSDESC_CALL
:
2412 tls_type
= GOT_TLS_GDESC
; break;
2417 h
->got
.refcount
+= 1;
2418 old_tls_type
= eh
->tls_type
;
2422 bfd_signed_vma
*local_got_refcounts
;
2424 /* This is a global offset table entry for a local symbol. */
2425 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2426 if (local_got_refcounts
== NULL
)
2430 size
= symtab_hdr
->sh_info
;
2431 size
*= sizeof (bfd_signed_vma
)
2432 + sizeof (bfd_vma
) + sizeof (char);
2433 local_got_refcounts
= ((bfd_signed_vma
*)
2434 bfd_zalloc (abfd
, size
));
2435 if (local_got_refcounts
== NULL
)
2437 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2438 elf_x86_64_local_tlsdesc_gotent (abfd
)
2439 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2440 elf_x86_64_local_got_tls_type (abfd
)
2441 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2443 local_got_refcounts
[r_symndx
] += 1;
2445 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2448 /* If a TLS symbol is accessed using IE at least once,
2449 there is no point to use dynamic model for it. */
2450 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2451 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2452 || tls_type
!= GOT_TLS_IE
))
2454 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2455 tls_type
= old_tls_type
;
2456 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2457 && GOT_TLS_GD_ANY_P (tls_type
))
2458 tls_type
|= old_tls_type
;
2462 name
= h
->root
.root
.string
;
2464 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2467 /* xgettext:c-format */
2468 (_("%B: '%s' accessed both as normal and thread local symbol"),
2470 bfd_set_error (bfd_error_bad_value
);
2475 if (old_tls_type
!= tls_type
)
2478 eh
->tls_type
= tls_type
;
2480 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2485 case R_X86_64_GOTOFF64
:
2486 case R_X86_64_GOTPC32
:
2487 case R_X86_64_GOTPC64
:
2490 eh
->has_got_reloc
= 1;
2491 if (htab
->elf
.sgot
== NULL
)
2493 if (htab
->elf
.dynobj
== NULL
)
2494 htab
->elf
.dynobj
= abfd
;
2495 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
2501 case R_X86_64_PLT32
:
2502 case R_X86_64_PLT32_BND
:
2503 /* This symbol requires a procedure linkage table entry. We
2504 actually build the entry in adjust_dynamic_symbol,
2505 because this might be a case of linking PIC code which is
2506 never referenced by a dynamic object, in which case we
2507 don't need to generate a procedure linkage table entry
2510 /* If this is a local symbol, we resolve it directly without
2511 creating a procedure linkage table entry. */
2515 eh
->has_got_reloc
= 1;
2517 h
->plt
.refcount
+= 1;
2520 case R_X86_64_PLTOFF64
:
2521 /* This tries to form the 'address' of a function relative
2522 to GOT. For global symbols we need a PLT entry. */
2526 h
->plt
.refcount
+= 1;
2530 case R_X86_64_SIZE32
:
2531 case R_X86_64_SIZE64
:
2536 if (!ABI_64_P (abfd
))
2542 /* Check relocation overflow as these relocs may lead to
2543 run-time relocation overflow. Don't error out for
2544 sections we don't care about, such as debug sections or
2545 when relocation overflow check is disabled. */
2546 if (!info
->no_reloc_overflow_check
2547 && (bfd_link_pic (info
)
2548 || (bfd_link_executable (info
)
2552 && (sec
->flags
& SEC_READONLY
) == 0)))
2553 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2554 &x86_64_elf_howto_table
[r_type
]);
2560 case R_X86_64_PC32_BND
:
2564 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2565 eh
->has_non_got_reloc
= 1;
2566 /* We are called after all symbols have been resolved. Only
2567 relocation against STT_GNU_IFUNC symbol must go through
2570 && (bfd_link_executable (info
)
2571 || h
->type
== STT_GNU_IFUNC
))
2573 /* If this reloc is in a read-only section, we might
2574 need a copy reloc. We can't check reliably at this
2575 stage whether the section is read-only, as input
2576 sections have not yet been mapped to output sections.
2577 Tentatively set the flag for now, and correct in
2578 adjust_dynamic_symbol. */
2581 /* We may need a .plt entry if the symbol is a function
2582 defined in a shared lib or is a STT_GNU_IFUNC function
2583 referenced from the code or read-only section. */
2585 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2586 h
->plt
.refcount
+= 1;
2588 if (r_type
== R_X86_64_PC32
)
2590 /* Since something like ".long foo - ." may be used
2591 as pointer, make sure that PLT is used if foo is
2592 a function defined in a shared library. */
2593 if ((sec
->flags
& SEC_CODE
) == 0)
2594 h
->pointer_equality_needed
= 1;
2596 else if (r_type
!= R_X86_64_PC32_BND
2597 && r_type
!= R_X86_64_PC64
)
2599 h
->pointer_equality_needed
= 1;
2600 /* At run-time, R_X86_64_64 can be resolved for both
2601 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2602 can only be resolved for x32. */
2603 if ((sec
->flags
& SEC_READONLY
) == 0
2604 && (r_type
== R_X86_64_64
2605 || (!ABI_64_P (abfd
)
2606 && (r_type
== R_X86_64_32
2607 || r_type
== R_X86_64_32S
))))
2608 eh
->func_pointer_refcount
+= 1;
2614 /* If we are creating a shared library, and this is a reloc
2615 against a global symbol, or a non PC relative reloc
2616 against a local symbol, then we need to copy the reloc
2617 into the shared library. However, if we are linking with
2618 -Bsymbolic, we do not need to copy a reloc against a
2619 global symbol which is defined in an object we are
2620 including in the link (i.e., DEF_REGULAR is set). At
2621 this point we have not seen all the input files, so it is
2622 possible that DEF_REGULAR is not set now but will be set
2623 later (it is never cleared). In case of a weak definition,
2624 DEF_REGULAR may be cleared later by a strong definition in
2625 a shared library. We account for that possibility below by
2626 storing information in the relocs_copied field of the hash
2627 table entry. A similar situation occurs when creating
2628 shared libraries and symbol visibility changes render the
2631 If on the other hand, we are creating an executable, we
2632 may need to keep relocations for symbols satisfied by a
2633 dynamic library if we manage to avoid copy relocs for the
2636 Generate dynamic pointer relocation against STT_GNU_IFUNC
2637 symbol in the non-code section. */
2638 if ((bfd_link_pic (info
)
2639 && (! IS_X86_64_PCREL_TYPE (r_type
)
2641 && (! (bfd_link_pie (info
)
2642 || SYMBOLIC_BIND (info
, h
))
2643 || h
->root
.type
== bfd_link_hash_defweak
2644 || !h
->def_regular
))))
2646 && h
->type
== STT_GNU_IFUNC
2647 && r_type
== htab
->pointer_r_type
2648 && (sec
->flags
& SEC_CODE
) == 0)
2649 || (ELIMINATE_COPY_RELOCS
2650 && !bfd_link_pic (info
)
2652 && (h
->root
.type
== bfd_link_hash_defweak
2653 || !h
->def_regular
)))
2655 struct elf_dyn_relocs
*p
;
2656 struct elf_dyn_relocs
**head
;
2658 /* We must copy these reloc types into the output file.
2659 Create a reloc section in dynobj and make room for
2663 if (htab
->elf
.dynobj
== NULL
)
2664 htab
->elf
.dynobj
= abfd
;
2666 sreloc
= _bfd_elf_make_dynamic_reloc_section
2667 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2668 abfd
, /*rela?*/ TRUE
);
2674 /* If this is a global symbol, we count the number of
2675 relocations we need for this symbol. */
2677 head
= &eh
->dyn_relocs
;
2680 /* Track dynamic relocs needed for local syms too.
2681 We really need local syms available to do this
2686 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2691 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2695 /* Beware of type punned pointers vs strict aliasing
2697 vpp
= &(elf_section_data (s
)->local_dynrel
);
2698 head
= (struct elf_dyn_relocs
**)vpp
;
2702 if (p
== NULL
|| p
->sec
!= sec
)
2704 bfd_size_type amt
= sizeof *p
;
2706 p
= ((struct elf_dyn_relocs
*)
2707 bfd_alloc (htab
->elf
.dynobj
, amt
));
2718 /* Count size relocation as PC-relative relocation. */
2719 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2724 /* This relocation describes the C++ object vtable hierarchy.
2725 Reconstruct it for later use during GC. */
2726 case R_X86_64_GNU_VTINHERIT
:
2727 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2731 /* This relocation describes which C++ vtable entries are actually
2732 used. Record for later use during GC. */
2733 case R_X86_64_GNU_VTENTRY
:
2734 BFD_ASSERT (h
!= NULL
);
2736 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2746 && h
->plt
.refcount
> 0
2747 && (((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
2748 || h
->got
.refcount
> 0)
2749 && htab
->plt_got
== NULL
)
2751 /* Create the GOT procedure linkage table. */
2752 unsigned int plt_got_align
;
2753 const struct elf_backend_data
*bed
;
2755 bed
= get_elf_backend_data (info
->output_bfd
);
2756 BFD_ASSERT (sizeof (elf_x86_64_legacy_plt2_entry
) == 8
2757 && (sizeof (elf_x86_64_bnd_plt2_entry
)
2758 == sizeof (elf_x86_64_legacy_plt2_entry
)));
2761 if (htab
->elf
.dynobj
== NULL
)
2762 htab
->elf
.dynobj
= abfd
;
2764 = bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2766 (bed
->dynamic_sec_flags
2771 if (htab
->plt_got
== NULL
2772 || !bfd_set_section_alignment (htab
->elf
.dynobj
,
2778 if ((r_type
== R_X86_64_GOTPCREL
2779 || r_type
== R_X86_64_GOTPCRELX
2780 || r_type
== R_X86_64_REX_GOTPCRELX
)
2781 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2782 sec
->need_convert_load
= 1;
2785 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2787 if (!info
->keep_memory
)
2791 /* Cache the section contents for elf_link_input_bfd. */
2792 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2799 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2801 sec
->check_relocs_failed
= 1;
2805 /* Return the section that should be marked against GC for a given
2809 elf_x86_64_gc_mark_hook (asection
*sec
,
2810 struct bfd_link_info
*info
,
2811 Elf_Internal_Rela
*rel
,
2812 struct elf_link_hash_entry
*h
,
2813 Elf_Internal_Sym
*sym
)
2816 switch (ELF32_R_TYPE (rel
->r_info
))
2818 case R_X86_64_GNU_VTINHERIT
:
2819 case R_X86_64_GNU_VTENTRY
:
2823 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2826 /* Remove undefined weak symbol from the dynamic symbol table if it
2827 is resolved to 0. */
2830 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2831 struct elf_link_hash_entry
*h
)
2833 if (h
->dynindx
!= -1
2834 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2835 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2836 elf_x86_64_hash_entry (h
)))
2839 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2845 /* Adjust a symbol defined by a dynamic object and referenced by a
2846 regular object. The current definition is in some section of the
2847 dynamic object, but we're not including those sections. We have to
2848 change the definition to something the rest of the link can
2852 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2853 struct elf_link_hash_entry
*h
)
2855 struct elf_x86_64_link_hash_table
*htab
;
2857 struct elf_x86_64_link_hash_entry
*eh
;
2858 struct elf_dyn_relocs
*p
;
2860 /* STT_GNU_IFUNC symbol must go through PLT. */
2861 if (h
->type
== STT_GNU_IFUNC
)
2863 /* All local STT_GNU_IFUNC references must be treate as local
2864 calls via local PLT. */
2866 && SYMBOL_CALLS_LOCAL (info
, h
))
2868 bfd_size_type pc_count
= 0, count
= 0;
2869 struct elf_dyn_relocs
**pp
;
2871 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2872 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2874 pc_count
+= p
->pc_count
;
2875 p
->count
-= p
->pc_count
;
2884 if (pc_count
|| count
)
2889 /* Increment PLT reference count only for PC-relative
2892 if (h
->plt
.refcount
<= 0)
2893 h
->plt
.refcount
= 1;
2895 h
->plt
.refcount
+= 1;
2900 if (h
->plt
.refcount
<= 0)
2902 h
->plt
.offset
= (bfd_vma
) -1;
2908 /* If this is a function, put it in the procedure linkage table. We
2909 will fill in the contents of the procedure linkage table later,
2910 when we know the address of the .got section. */
2911 if (h
->type
== STT_FUNC
2914 if (h
->plt
.refcount
<= 0
2915 || SYMBOL_CALLS_LOCAL (info
, h
)
2916 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2917 && h
->root
.type
== bfd_link_hash_undefweak
))
2919 /* This case can occur if we saw a PLT32 reloc in an input
2920 file, but the symbol was never referred to by a dynamic
2921 object, or if all references were garbage collected. In
2922 such a case, we don't actually need to build a procedure
2923 linkage table, and we can just do a PC32 reloc instead. */
2924 h
->plt
.offset
= (bfd_vma
) -1;
2931 /* It's possible that we incorrectly decided a .plt reloc was
2932 needed for an R_X86_64_PC32 reloc to a non-function sym in
2933 check_relocs. We can't decide accurately between function and
2934 non-function syms in check-relocs; Objects loaded later in
2935 the link may change h->type. So fix it now. */
2936 h
->plt
.offset
= (bfd_vma
) -1;
2938 /* If this is a weak symbol, and there is a real definition, the
2939 processor independent code will have arranged for us to see the
2940 real definition first, and we can just use the same value. */
2941 if (h
->u
.weakdef
!= NULL
)
2943 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2944 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2945 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2946 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2947 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2949 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2950 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2951 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
2956 /* This is a reference to a symbol defined by a dynamic object which
2957 is not a function. */
2959 /* If we are creating a shared library, we must presume that the
2960 only references to the symbol are via the global offset table.
2961 For such cases we need not do anything here; the relocations will
2962 be handled correctly by relocate_section. */
2963 if (!bfd_link_executable (info
))
2966 /* If there are no references to this symbol that do not use the
2967 GOT, we don't need to generate a copy reloc. */
2968 if (!h
->non_got_ref
)
2971 /* If -z nocopyreloc was given, we won't generate them either. */
2972 if (info
->nocopyreloc
)
2978 if (ELIMINATE_COPY_RELOCS
)
2980 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2981 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2983 s
= p
->sec
->output_section
;
2984 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2988 /* If we didn't find any dynamic relocs in read-only sections, then
2989 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2997 /* We must allocate the symbol in our .dynbss section, which will
2998 become part of the .bss section of the executable. There will be
2999 an entry for this symbol in the .dynsym section. The dynamic
3000 object will contain position independent code, so all references
3001 from the dynamic object to this symbol will go through the global
3002 offset table. The dynamic linker will use the .dynsym entry to
3003 determine the address it must put in the global offset table, so
3004 both the dynamic object and the regular object will refer to the
3005 same memory location for the variable. */
3007 htab
= elf_x86_64_hash_table (info
);
3011 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3012 to copy the initial value out of the dynamic object and into the
3013 runtime process image. */
3014 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3016 const struct elf_backend_data
*bed
;
3017 bed
= get_elf_backend_data (info
->output_bfd
);
3018 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
3024 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3027 /* Allocate space in .plt, .got and associated reloc sections for
3031 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3033 struct bfd_link_info
*info
;
3034 struct elf_x86_64_link_hash_table
*htab
;
3035 struct elf_x86_64_link_hash_entry
*eh
;
3036 struct elf_dyn_relocs
*p
;
3037 const struct elf_backend_data
*bed
;
3038 unsigned int plt_entry_size
;
3039 bfd_boolean resolved_to_zero
;
3041 if (h
->root
.type
== bfd_link_hash_indirect
)
3044 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3046 info
= (struct bfd_link_info
*) inf
;
3047 htab
= elf_x86_64_hash_table (info
);
3050 bed
= get_elf_backend_data (info
->output_bfd
);
3051 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3053 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3057 /* We can't use the GOT PLT if pointer equality is needed since
3058 finish_dynamic_symbol won't clear symbol value and the dynamic
3059 linker won't update the GOT slot. We will get into an infinite
3060 loop at run-time. */
3061 if (htab
->plt_got
!= NULL
3062 && h
->type
!= STT_GNU_IFUNC
3063 && !h
->pointer_equality_needed
3064 && h
->plt
.refcount
> 0
3065 && h
->got
.refcount
> 0)
3067 /* Don't use the regular PLT if there are both GOT and GOTPLT
3069 h
->plt
.offset
= (bfd_vma
) -1;
3071 /* Use the GOT PLT. */
3072 eh
->plt_got
.refcount
= 1;
3075 /* Clear the reference count of function pointer relocations if
3076 symbol isn't a normal function. */
3077 if (h
->type
!= STT_FUNC
)
3078 eh
->func_pointer_refcount
= 0;
3080 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3081 here if it is defined and referenced in a non-shared object. */
3082 if (h
->type
== STT_GNU_IFUNC
3085 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3087 &htab
->readonly_dynrelocs_against_ifunc
,
3090 GOT_ENTRY_SIZE
, TRUE
))
3092 asection
*s
= htab
->plt_bnd
;
3093 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3095 /* Use the .plt.bnd section if it is created. */
3096 eh
->plt_bnd
.offset
= s
->size
;
3098 /* Make room for this entry in the .plt.bnd section. */
3099 s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3107 /* Don't create the PLT entry if there are only function pointer
3108 relocations which can be resolved at run-time. */
3109 else if (htab
->elf
.dynamic_sections_created
3110 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3111 || eh
->plt_got
.refcount
> 0))
3113 bfd_boolean use_plt_got
;
3115 /* Clear the reference count of function pointer relocations
3117 eh
->func_pointer_refcount
= 0;
3119 if ((info
->flags
& DF_BIND_NOW
) && !h
->pointer_equality_needed
)
3121 /* Don't use the regular PLT for DF_BIND_NOW. */
3122 h
->plt
.offset
= (bfd_vma
) -1;
3124 /* Use the GOT PLT. */
3125 h
->got
.refcount
= 1;
3126 eh
->plt_got
.refcount
= 1;
3129 use_plt_got
= eh
->plt_got
.refcount
> 0;
3131 /* Make sure this symbol is output as a dynamic symbol.
3132 Undefined weak syms won't yet be marked as dynamic. */
3133 if (h
->dynindx
== -1
3135 && !resolved_to_zero
)
3137 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3141 if (bfd_link_pic (info
)
3142 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3144 asection
*s
= htab
->elf
.splt
;
3145 asection
*bnd_s
= htab
->plt_bnd
;
3146 asection
*got_s
= htab
->plt_got
;
3148 /* If this is the first .plt entry, make room for the special
3149 first entry. The .plt section is used by prelink to undo
3150 prelinking for dynamic relocations. */
3152 s
->size
= plt_entry_size
;
3155 eh
->plt_got
.offset
= got_s
->size
;
3158 h
->plt
.offset
= s
->size
;
3160 eh
->plt_bnd
.offset
= bnd_s
->size
;
3163 /* If this symbol is not defined in a regular file, and we are
3164 not generating a shared library, then set the symbol to this
3165 location in the .plt. This is required to make function
3166 pointers compare as equal between the normal executable and
3167 the shared library. */
3168 if (! bfd_link_pic (info
)
3173 /* We need to make a call to the entry of the GOT PLT
3174 instead of regular PLT entry. */
3175 h
->root
.u
.def
.section
= got_s
;
3176 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3182 /* We need to make a call to the entry of the second
3183 PLT instead of regular PLT entry. */
3184 h
->root
.u
.def
.section
= bnd_s
;
3185 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
3189 h
->root
.u
.def
.section
= s
;
3190 h
->root
.u
.def
.value
= h
->plt
.offset
;
3195 /* Make room for this entry. */
3197 got_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3200 s
->size
+= plt_entry_size
;
3202 bnd_s
->size
+= sizeof (elf_x86_64_legacy_plt2_entry
);
3204 /* We also need to make an entry in the .got.plt section,
3205 which will be placed in the .got section by the linker
3207 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3209 /* There should be no PLT relocation against resolved
3210 undefined weak symbol in executable. */
3211 if (!resolved_to_zero
)
3213 /* We also need to make an entry in the .rela.plt
3215 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3216 htab
->elf
.srelplt
->reloc_count
++;
3222 eh
->plt_got
.offset
= (bfd_vma
) -1;
3223 h
->plt
.offset
= (bfd_vma
) -1;
3229 eh
->plt_got
.offset
= (bfd_vma
) -1;
3230 h
->plt
.offset
= (bfd_vma
) -1;
3234 eh
->tlsdesc_got
= (bfd_vma
) -1;
3236 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3237 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3238 if (h
->got
.refcount
> 0
3239 && bfd_link_executable (info
)
3241 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3243 h
->got
.offset
= (bfd_vma
) -1;
3245 else if (h
->got
.refcount
> 0)
3249 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3251 /* Make sure this symbol is output as a dynamic symbol.
3252 Undefined weak syms won't yet be marked as dynamic. */
3253 if (h
->dynindx
== -1
3255 && !resolved_to_zero
)
3257 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3261 if (GOT_TLS_GDESC_P (tls_type
))
3263 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3264 - elf_x86_64_compute_jump_table_size (htab
);
3265 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3266 h
->got
.offset
= (bfd_vma
) -2;
3268 if (! GOT_TLS_GDESC_P (tls_type
)
3269 || GOT_TLS_GD_P (tls_type
))
3272 h
->got
.offset
= s
->size
;
3273 s
->size
+= GOT_ENTRY_SIZE
;
3274 if (GOT_TLS_GD_P (tls_type
))
3275 s
->size
+= GOT_ENTRY_SIZE
;
3277 dyn
= htab
->elf
.dynamic_sections_created
;
3278 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3279 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3280 relocation. No dynamic relocation against resolved undefined
3281 weak symbol in executable. */
3282 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3283 || tls_type
== GOT_TLS_IE
)
3284 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3285 else if (GOT_TLS_GD_P (tls_type
))
3286 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3287 else if (! GOT_TLS_GDESC_P (tls_type
)
3288 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3289 && !resolved_to_zero
)
3290 || h
->root
.type
!= bfd_link_hash_undefweak
)
3291 && (bfd_link_pic (info
)
3292 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3293 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3294 if (GOT_TLS_GDESC_P (tls_type
))
3296 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3297 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3301 h
->got
.offset
= (bfd_vma
) -1;
3303 if (eh
->dyn_relocs
== NULL
)
3306 /* In the shared -Bsymbolic case, discard space allocated for
3307 dynamic pc-relative relocs against symbols which turn out to be
3308 defined in regular objects. For the normal shared case, discard
3309 space for pc-relative relocs that have become local due to symbol
3310 visibility changes. */
3312 if (bfd_link_pic (info
))
3314 /* Relocs that use pc_count are those that appear on a call
3315 insn, or certain REL relocs that can generated via assembly.
3316 We want calls to protected symbols to resolve directly to the
3317 function rather than going via the plt. If people want
3318 function pointer comparisons to work as expected then they
3319 should avoid writing weird assembly. */
3320 if (SYMBOL_CALLS_LOCAL (info
, h
))
3322 struct elf_dyn_relocs
**pp
;
3324 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3326 p
->count
-= p
->pc_count
;
3335 /* Also discard relocs on undefined weak syms with non-default
3336 visibility or in PIE. */
3337 if (eh
->dyn_relocs
!= NULL
)
3339 if (h
->root
.type
== bfd_link_hash_undefweak
)
3341 /* Undefined weak symbol is never bound locally in shared
3343 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3344 || resolved_to_zero
)
3345 eh
->dyn_relocs
= NULL
;
3346 else if (h
->dynindx
== -1
3347 && ! h
->forced_local
3348 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3351 /* For PIE, discard space for pc-relative relocs against
3352 symbols which turn out to need copy relocs. */
3353 else if (bfd_link_executable (info
)
3354 && (h
->needs_copy
|| eh
->needs_copy
)
3358 struct elf_dyn_relocs
**pp
;
3360 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3362 if (p
->pc_count
!= 0)
3370 else if (ELIMINATE_COPY_RELOCS
)
3372 /* For the non-shared case, discard space for relocs against
3373 symbols which turn out to need copy relocs or are not
3374 dynamic. Keep dynamic relocations for run-time function
3375 pointer initialization. */
3377 if ((!h
->non_got_ref
3378 || eh
->func_pointer_refcount
> 0
3379 || (h
->root
.type
== bfd_link_hash_undefweak
3380 && !resolved_to_zero
))
3383 || (htab
->elf
.dynamic_sections_created
3384 && (h
->root
.type
== bfd_link_hash_undefweak
3385 || h
->root
.type
== bfd_link_hash_undefined
))))
3387 /* Make sure this symbol is output as a dynamic symbol.
3388 Undefined weak syms won't yet be marked as dynamic. */
3389 if (h
->dynindx
== -1
3390 && ! h
->forced_local
3391 && ! resolved_to_zero
3392 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3395 /* If that succeeded, we know we'll be keeping all the
3397 if (h
->dynindx
!= -1)
3401 eh
->dyn_relocs
= NULL
;
3402 eh
->func_pointer_refcount
= 0;
3407 /* Finally, allocate space. */
3408 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3412 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3414 BFD_ASSERT (sreloc
!= NULL
);
3416 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3422 /* Allocate space in .plt, .got and associated reloc sections for
3423 local dynamic relocs. */
3426 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3428 struct elf_link_hash_entry
*h
3429 = (struct elf_link_hash_entry
*) *slot
;
3431 if (h
->type
!= STT_GNU_IFUNC
3435 || h
->root
.type
!= bfd_link_hash_defined
)
3438 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3441 /* Find any dynamic relocs that apply to read-only sections. */
3444 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3447 struct elf_x86_64_link_hash_entry
*eh
;
3448 struct elf_dyn_relocs
*p
;
3450 /* Skip local IFUNC symbols. */
3451 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3454 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3455 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3457 asection
*s
= p
->sec
->output_section
;
3459 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3461 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3463 info
->flags
|= DF_TEXTREL
;
3465 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3466 || info
->error_textrel
)
3467 /* xgettext:c-format */
3468 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3469 p
->sec
->owner
, h
->root
.root
.string
,
3472 /* Not an error, just cut short the traversal. */
3479 /* Convert load via the GOT slot to load immediate. */
3482 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3483 struct bfd_link_info
*link_info
)
3485 Elf_Internal_Shdr
*symtab_hdr
;
3486 Elf_Internal_Rela
*internal_relocs
;
3487 Elf_Internal_Rela
*irel
, *irelend
;
3489 struct elf_x86_64_link_hash_table
*htab
;
3490 bfd_boolean changed
;
3491 bfd_signed_vma
*local_got_refcounts
;
3493 /* Don't even try to convert non-ELF outputs. */
3494 if (!is_elf_hash_table (link_info
->hash
))
3497 /* Nothing to do if there is no need or no output. */
3498 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3499 || sec
->need_convert_load
== 0
3500 || bfd_is_abs_section (sec
->output_section
))
3503 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3505 /* Load the relocations for this section. */
3506 internal_relocs
= (_bfd_elf_link_read_relocs
3507 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3508 link_info
->keep_memory
));
3509 if (internal_relocs
== NULL
)
3513 htab
= elf_x86_64_hash_table (link_info
);
3514 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3516 /* Get the section contents. */
3517 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3518 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3521 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3525 irelend
= internal_relocs
+ sec
->reloc_count
;
3526 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3528 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3529 unsigned int r_symndx
;
3530 struct elf_link_hash_entry
*h
;
3531 bfd_boolean converted
;
3533 if (r_type
!= R_X86_64_GOTPCRELX
3534 && r_type
!= R_X86_64_REX_GOTPCRELX
3535 && r_type
!= R_X86_64_GOTPCREL
)
3538 r_symndx
= htab
->r_sym (irel
->r_info
);
3539 if (r_symndx
< symtab_hdr
->sh_info
)
3540 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3541 (const Elf_Internal_Rela
*) irel
,
3545 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3546 while (h
->root
.type
== bfd_link_hash_indirect
3547 || h
->root
.type
== bfd_link_hash_warning
)
3548 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3551 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3552 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3556 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3557 &converted
, link_info
))
3562 changed
= converted
;
3565 if (h
->got
.refcount
> 0)
3566 h
->got
.refcount
-= 1;
3570 if (local_got_refcounts
!= NULL
3571 && local_got_refcounts
[r_symndx
] > 0)
3572 local_got_refcounts
[r_symndx
] -= 1;
3577 if (contents
!= NULL
3578 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3580 if (!changed
&& !link_info
->keep_memory
)
3584 /* Cache the section contents for elf_link_input_bfd. */
3585 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3589 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3592 free (internal_relocs
);
3594 elf_section_data (sec
)->relocs
= internal_relocs
;
3600 if (contents
!= NULL
3601 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3603 if (internal_relocs
!= NULL
3604 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3605 free (internal_relocs
);
3609 /* Set the sizes of the dynamic sections. */
3612 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3613 struct bfd_link_info
*info
)
3615 struct elf_x86_64_link_hash_table
*htab
;
3620 const struct elf_backend_data
*bed
;
3622 htab
= elf_x86_64_hash_table (info
);
3625 bed
= get_elf_backend_data (output_bfd
);
3627 dynobj
= htab
->elf
.dynobj
;
3631 /* Set up .got offsets for local syms, and space for local dynamic
3633 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3635 bfd_signed_vma
*local_got
;
3636 bfd_signed_vma
*end_local_got
;
3637 char *local_tls_type
;
3638 bfd_vma
*local_tlsdesc_gotent
;
3639 bfd_size_type locsymcount
;
3640 Elf_Internal_Shdr
*symtab_hdr
;
3643 if (! is_x86_64_elf (ibfd
))
3646 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3648 struct elf_dyn_relocs
*p
;
3650 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3653 for (p
= (struct elf_dyn_relocs
*)
3654 (elf_section_data (s
)->local_dynrel
);
3658 if (!bfd_is_abs_section (p
->sec
)
3659 && bfd_is_abs_section (p
->sec
->output_section
))
3661 /* Input section has been discarded, either because
3662 it is a copy of a linkonce section or due to
3663 linker script /DISCARD/, so we'll be discarding
3666 else if (p
->count
!= 0)
3668 srel
= elf_section_data (p
->sec
)->sreloc
;
3669 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3670 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3671 && (info
->flags
& DF_TEXTREL
) == 0)
3673 info
->flags
|= DF_TEXTREL
;
3674 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3675 || info
->error_textrel
)
3676 /* xgettext:c-format */
3677 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3678 p
->sec
->owner
, p
->sec
);
3684 local_got
= elf_local_got_refcounts (ibfd
);
3688 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3689 locsymcount
= symtab_hdr
->sh_info
;
3690 end_local_got
= local_got
+ locsymcount
;
3691 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3692 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3694 srel
= htab
->elf
.srelgot
;
3695 for (; local_got
< end_local_got
;
3696 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3698 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3701 if (GOT_TLS_GDESC_P (*local_tls_type
))
3703 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3704 - elf_x86_64_compute_jump_table_size (htab
);
3705 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3706 *local_got
= (bfd_vma
) -2;
3708 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3709 || GOT_TLS_GD_P (*local_tls_type
))
3711 *local_got
= s
->size
;
3712 s
->size
+= GOT_ENTRY_SIZE
;
3713 if (GOT_TLS_GD_P (*local_tls_type
))
3714 s
->size
+= GOT_ENTRY_SIZE
;
3716 if (bfd_link_pic (info
)
3717 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3718 || *local_tls_type
== GOT_TLS_IE
)
3720 if (GOT_TLS_GDESC_P (*local_tls_type
))
3722 htab
->elf
.srelplt
->size
3723 += bed
->s
->sizeof_rela
;
3724 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3726 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3727 || GOT_TLS_GD_P (*local_tls_type
))
3728 srel
->size
+= bed
->s
->sizeof_rela
;
3732 *local_got
= (bfd_vma
) -1;
3736 if (htab
->tls_ld_got
.refcount
> 0)
3738 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3740 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3741 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3742 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3745 htab
->tls_ld_got
.offset
= -1;
3747 /* Allocate global sym .plt and .got entries, and space for global
3748 sym dynamic relocs. */
3749 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3752 /* Allocate .plt and .got entries, and space for local symbols. */
3753 htab_traverse (htab
->loc_hash_table
,
3754 elf_x86_64_allocate_local_dynrelocs
,
3757 /* For every jump slot reserved in the sgotplt, reloc_count is
3758 incremented. However, when we reserve space for TLS descriptors,
3759 it's not incremented, so in order to compute the space reserved
3760 for them, it suffices to multiply the reloc count by the jump
3763 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3764 so that R_X86_64_IRELATIVE entries come last. */
3765 if (htab
->elf
.srelplt
)
3767 htab
->sgotplt_jump_table_size
3768 = elf_x86_64_compute_jump_table_size (htab
);
3769 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3771 else if (htab
->elf
.irelplt
)
3772 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3774 if (htab
->tlsdesc_plt
)
3776 /* If we're not using lazy TLS relocations, don't generate the
3777 PLT and GOT entries they require. */
3778 if ((info
->flags
& DF_BIND_NOW
))
3779 htab
->tlsdesc_plt
= 0;
3782 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3783 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3784 /* Reserve room for the initial entry.
3785 FIXME: we could probably do away with it in this case. */
3786 if (htab
->elf
.splt
->size
== 0)
3787 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3788 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3789 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
3793 if (htab
->elf
.sgotplt
)
3795 /* Don't allocate .got.plt section if there are no GOT nor PLT
3796 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3797 if ((htab
->elf
.hgot
== NULL
3798 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3799 && (htab
->elf
.sgotplt
->size
3800 == get_elf_backend_data (output_bfd
)->got_header_size
)
3801 && (htab
->elf
.splt
== NULL
3802 || htab
->elf
.splt
->size
== 0)
3803 && (htab
->elf
.sgot
== NULL
3804 || htab
->elf
.sgot
->size
== 0)
3805 && (htab
->elf
.iplt
== NULL
3806 || htab
->elf
.iplt
->size
== 0)
3807 && (htab
->elf
.igotplt
== NULL
3808 || htab
->elf
.igotplt
->size
== 0))
3809 htab
->elf
.sgotplt
->size
= 0;
3812 if (htab
->plt_eh_frame
!= NULL
3813 && htab
->elf
.splt
!= NULL
3814 && htab
->elf
.splt
->size
!= 0
3815 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
)
3816 && _bfd_elf_eh_frame_present (info
))
3818 const struct elf_x86_64_backend_data
*arch_data
3819 = get_elf_x86_64_arch_data (bed
);
3820 htab
->plt_eh_frame
->size
= arch_data
->eh_frame_plt_size
;
3823 /* We now have determined the sizes of the various dynamic sections.
3824 Allocate memory for them. */
3826 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3828 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3831 if (s
== htab
->elf
.splt
3832 || s
== htab
->elf
.sgot
3833 || s
== htab
->elf
.sgotplt
3834 || s
== htab
->elf
.iplt
3835 || s
== htab
->elf
.igotplt
3836 || s
== htab
->plt_bnd
3837 || s
== htab
->plt_got
3838 || s
== htab
->plt_eh_frame
3839 || s
== htab
->sdynbss
)
3841 /* Strip this section if we don't need it; see the
3844 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3846 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3849 /* We use the reloc_count field as a counter if we need
3850 to copy relocs into the output file. */
3851 if (s
!= htab
->elf
.srelplt
)
3856 /* It's not one of our sections, so don't allocate space. */
3862 /* If we don't need this section, strip it from the
3863 output file. This is mostly to handle .rela.bss and
3864 .rela.plt. We must create both sections in
3865 create_dynamic_sections, because they must be created
3866 before the linker maps input sections to output
3867 sections. The linker does that before
3868 adjust_dynamic_symbol is called, and it is that
3869 function which decides whether anything needs to go
3870 into these sections. */
3872 s
->flags
|= SEC_EXCLUDE
;
3876 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3879 /* Allocate memory for the section contents. We use bfd_zalloc
3880 here in case unused entries are not reclaimed before the
3881 section's contents are written out. This should not happen,
3882 but this way if it does, we get a R_X86_64_NONE reloc instead
3884 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3885 if (s
->contents
== NULL
)
3889 if (htab
->plt_eh_frame
!= NULL
3890 && htab
->plt_eh_frame
->contents
!= NULL
)
3892 const struct elf_x86_64_backend_data
*arch_data
3893 = get_elf_x86_64_arch_data (bed
);
3895 memcpy (htab
->plt_eh_frame
->contents
,
3896 arch_data
->eh_frame_plt
, htab
->plt_eh_frame
->size
);
3897 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3898 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3901 if (htab
->elf
.dynamic_sections_created
)
3903 /* Add some entries to the .dynamic section. We fill in the
3904 values later, in elf_x86_64_finish_dynamic_sections, but we
3905 must add the entries now so that we get the correct size for
3906 the .dynamic section. The DT_DEBUG entry is filled in by the
3907 dynamic linker and used by the debugger. */
3908 #define add_dynamic_entry(TAG, VAL) \
3909 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3911 if (bfd_link_executable (info
))
3913 if (!add_dynamic_entry (DT_DEBUG
, 0))
3917 if (htab
->elf
.splt
->size
!= 0)
3919 /* DT_PLTGOT is used by prelink even if there is no PLT
3921 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3924 if (htab
->elf
.srelplt
->size
!= 0)
3926 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3927 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3928 || !add_dynamic_entry (DT_JMPREL
, 0))
3932 if (htab
->tlsdesc_plt
3933 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
3934 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
3940 if (!add_dynamic_entry (DT_RELA
, 0)
3941 || !add_dynamic_entry (DT_RELASZ
, 0)
3942 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
3945 /* If any dynamic relocs apply to a read-only section,
3946 then we need a DT_TEXTREL entry. */
3947 if ((info
->flags
& DF_TEXTREL
) == 0)
3948 elf_link_hash_traverse (&htab
->elf
,
3949 elf_x86_64_readonly_dynrelocs
,
3952 if ((info
->flags
& DF_TEXTREL
) != 0)
3954 if (htab
->readonly_dynrelocs_against_ifunc
)
3956 info
->callbacks
->einfo
3957 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3958 bfd_set_error (bfd_error_bad_value
);
3962 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3967 #undef add_dynamic_entry
3973 elf_x86_64_always_size_sections (bfd
*output_bfd
,
3974 struct bfd_link_info
*info
)
3976 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3980 struct elf_link_hash_entry
*tlsbase
;
3982 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3983 "_TLS_MODULE_BASE_",
3984 FALSE
, FALSE
, FALSE
);
3986 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3988 struct elf_x86_64_link_hash_table
*htab
;
3989 struct bfd_link_hash_entry
*bh
= NULL
;
3990 const struct elf_backend_data
*bed
3991 = get_elf_backend_data (output_bfd
);
3993 htab
= elf_x86_64_hash_table (info
);
3997 if (!(_bfd_generic_link_add_one_symbol
3998 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3999 tls_sec
, 0, NULL
, FALSE
,
4000 bed
->collect
, &bh
)))
4003 htab
->tls_module_base
= bh
;
4005 tlsbase
= (struct elf_link_hash_entry
*)bh
;
4006 tlsbase
->def_regular
= 1;
4007 tlsbase
->other
= STV_HIDDEN
;
4008 tlsbase
->root
.linker_def
= 1;
4009 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4016 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4017 executables. Rather than setting it to the beginning of the TLS
4018 section, we have to set it to the end. This function may be called
4019 multiple times, it is idempotent. */
4022 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4024 struct elf_x86_64_link_hash_table
*htab
;
4025 struct bfd_link_hash_entry
*base
;
4027 if (!bfd_link_executable (info
))
4030 htab
= elf_x86_64_hash_table (info
);
4034 base
= htab
->tls_module_base
;
4038 base
->u
.def
.value
= htab
->elf
.tls_size
;
4041 /* Return the base VMA address which should be subtracted from real addresses
4042 when resolving @dtpoff relocation.
4043 This is PT_TLS segment p_vaddr. */
4046 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4048 /* If tls_sec is NULL, we should have signalled an error already. */
4049 if (elf_hash_table (info
)->tls_sec
== NULL
)
4051 return elf_hash_table (info
)->tls_sec
->vma
;
4054 /* Return the relocation value for @tpoff relocation
4055 if STT_TLS virtual address is ADDRESS. */
4058 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4060 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4061 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4062 bfd_vma static_tls_size
;
4064 /* If tls_segment is NULL, we should have signalled an error already. */
4065 if (htab
->tls_sec
== NULL
)
4068 /* Consider special static TLS alignment requirements. */
4069 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4070 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4073 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4077 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4079 /* Opcode Instruction
4082 0x0f 0x8x conditional jump */
4084 && (contents
[offset
- 1] == 0xe8
4085 || contents
[offset
- 1] == 0xe9))
4087 && contents
[offset
- 2] == 0x0f
4088 && (contents
[offset
- 1] & 0xf0) == 0x80));
4091 /* Relocate an x86_64 ELF section. */
4094 elf_x86_64_relocate_section (bfd
*output_bfd
,
4095 struct bfd_link_info
*info
,
4097 asection
*input_section
,
4099 Elf_Internal_Rela
*relocs
,
4100 Elf_Internal_Sym
*local_syms
,
4101 asection
**local_sections
)
4103 struct elf_x86_64_link_hash_table
*htab
;
4104 Elf_Internal_Shdr
*symtab_hdr
;
4105 struct elf_link_hash_entry
**sym_hashes
;
4106 bfd_vma
*local_got_offsets
;
4107 bfd_vma
*local_tlsdesc_gotents
;
4108 Elf_Internal_Rela
*rel
;
4109 Elf_Internal_Rela
*wrel
;
4110 Elf_Internal_Rela
*relend
;
4111 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
4113 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4115 /* Skip if check_relocs failed. */
4116 if (input_section
->check_relocs_failed
)
4119 htab
= elf_x86_64_hash_table (info
);
4122 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4123 sym_hashes
= elf_sym_hashes (input_bfd
);
4124 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4125 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4127 elf_x86_64_set_tls_module_base (info
);
4129 rel
= wrel
= relocs
;
4130 relend
= relocs
+ input_section
->reloc_count
;
4131 for (; rel
< relend
; wrel
++, rel
++)
4133 unsigned int r_type
;
4134 reloc_howto_type
*howto
;
4135 unsigned long r_symndx
;
4136 struct elf_link_hash_entry
*h
;
4137 struct elf_x86_64_link_hash_entry
*eh
;
4138 Elf_Internal_Sym
*sym
;
4140 bfd_vma off
, offplt
, plt_offset
;
4142 bfd_boolean unresolved_reloc
;
4143 bfd_reloc_status_type r
;
4145 asection
*base_got
, *resolved_plt
;
4147 bfd_boolean resolved_to_zero
;
4149 r_type
= ELF32_R_TYPE (rel
->r_info
);
4150 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4151 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4158 if (r_type
>= (int) R_X86_64_standard
)
4161 /* xgettext:c-format */
4162 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4163 input_bfd
, input_section
, r_type
);
4164 bfd_set_error (bfd_error_bad_value
);
4168 if (r_type
!= (int) R_X86_64_32
4169 || ABI_64_P (output_bfd
))
4170 howto
= x86_64_elf_howto_table
+ r_type
;
4172 howto
= (x86_64_elf_howto_table
4173 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4174 r_symndx
= htab
->r_sym (rel
->r_info
);
4178 unresolved_reloc
= FALSE
;
4179 if (r_symndx
< symtab_hdr
->sh_info
)
4181 sym
= local_syms
+ r_symndx
;
4182 sec
= local_sections
[r_symndx
];
4184 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4186 st_size
= sym
->st_size
;
4188 /* Relocate against local STT_GNU_IFUNC symbol. */
4189 if (!bfd_link_relocatable (info
)
4190 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4192 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4197 /* Set STT_GNU_IFUNC symbol value. */
4198 h
->root
.u
.def
.value
= sym
->st_value
;
4199 h
->root
.u
.def
.section
= sec
;
4204 bfd_boolean warned ATTRIBUTE_UNUSED
;
4205 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4207 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4208 r_symndx
, symtab_hdr
, sym_hashes
,
4210 unresolved_reloc
, warned
, ignored
);
4214 if (sec
!= NULL
&& discarded_section (sec
))
4216 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4217 contents
+ rel
->r_offset
);
4218 wrel
->r_offset
= rel
->r_offset
;
4222 /* For ld -r, remove relocations in debug sections against
4223 sections defined in discarded sections. Not done for
4224 eh_frame editing code expects to be present. */
4225 if (bfd_link_relocatable (info
)
4226 && (input_section
->flags
& SEC_DEBUGGING
))
4232 if (bfd_link_relocatable (info
))
4239 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4241 if (r_type
== R_X86_64_64
)
4243 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4244 zero-extend it to 64bit if addend is zero. */
4245 r_type
= R_X86_64_32
;
4246 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4248 else if (r_type
== R_X86_64_SIZE64
)
4250 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4251 zero-extend it to 64bit if addend is zero. */
4252 r_type
= R_X86_64_SIZE32
;
4253 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4257 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4259 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4260 it here if it is defined in a non-shared object. */
4262 && h
->type
== STT_GNU_IFUNC
4268 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4270 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4271 sections because such sections are not SEC_ALLOC and
4272 thus ld.so will not process them. */
4273 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4283 case R_X86_64_GOTPCREL
:
4284 case R_X86_64_GOTPCRELX
:
4285 case R_X86_64_REX_GOTPCRELX
:
4286 case R_X86_64_GOTPCREL64
:
4287 base_got
= htab
->elf
.sgot
;
4288 off
= h
->got
.offset
;
4290 if (base_got
== NULL
)
4293 if (off
== (bfd_vma
) -1)
4295 /* We can't use h->got.offset here to save state, or
4296 even just remember the offset, as finish_dynamic_symbol
4297 would use that as offset into .got. */
4299 if (h
->plt
.offset
== (bfd_vma
) -1)
4302 if (htab
->elf
.splt
!= NULL
)
4304 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4305 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4306 base_got
= htab
->elf
.sgotplt
;
4310 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4311 off
= plt_index
* GOT_ENTRY_SIZE
;
4312 base_got
= htab
->elf
.igotplt
;
4315 if (h
->dynindx
== -1
4319 /* This references the local defitionion. We must
4320 initialize this entry in the global offset table.
4321 Since the offset must always be a multiple of 8,
4322 we use the least significant bit to record
4323 whether we have initialized it already.
4325 When doing a dynamic link, we create a .rela.got
4326 relocation entry to initialize the value. This
4327 is done in the finish_dynamic_symbol routine. */
4332 bfd_put_64 (output_bfd
, relocation
,
4333 base_got
->contents
+ off
);
4334 /* Note that this is harmless for the GOTPLT64
4335 case, as -1 | 1 still is -1. */
4341 relocation
= (base_got
->output_section
->vma
4342 + base_got
->output_offset
+ off
);
4347 if (h
->plt
.offset
== (bfd_vma
) -1)
4349 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4350 if (r_type
== htab
->pointer_r_type
4351 && (input_section
->flags
& SEC_CODE
) == 0)
4352 goto do_ifunc_pointer
;
4353 goto bad_ifunc_reloc
;
4356 /* STT_GNU_IFUNC symbol must go through PLT. */
4357 if (htab
->elf
.splt
!= NULL
)
4359 if (htab
->plt_bnd
!= NULL
)
4361 resolved_plt
= htab
->plt_bnd
;
4362 plt_offset
= eh
->plt_bnd
.offset
;
4366 resolved_plt
= htab
->elf
.splt
;
4367 plt_offset
= h
->plt
.offset
;
4372 resolved_plt
= htab
->elf
.iplt
;
4373 plt_offset
= h
->plt
.offset
;
4376 relocation
= (resolved_plt
->output_section
->vma
4377 + resolved_plt
->output_offset
+ plt_offset
);
4383 if (h
->root
.root
.string
)
4384 name
= h
->root
.root
.string
;
4386 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4389 /* xgettext:c-format */
4390 (_("%B: relocation %s against STT_GNU_IFUNC "
4391 "symbol `%s' isn't supported"), input_bfd
,
4393 bfd_set_error (bfd_error_bad_value
);
4397 if (bfd_link_pic (info
))
4402 if (ABI_64_P (output_bfd
))
4407 if (rel
->r_addend
!= 0)
4409 if (h
->root
.root
.string
)
4410 name
= h
->root
.root
.string
;
4412 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4415 /* xgettext:c-format */
4416 (_("%B: relocation %s against STT_GNU_IFUNC "
4417 "symbol `%s' has non-zero addend: %d"),
4418 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4419 bfd_set_error (bfd_error_bad_value
);
4423 /* Generate dynamic relcoation only when there is a
4424 non-GOT reference in a shared object or there is no
4426 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4427 || h
->plt
.offset
== (bfd_vma
) -1)
4429 Elf_Internal_Rela outrel
;
4432 /* Need a dynamic relocation to get the real function
4434 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4438 if (outrel
.r_offset
== (bfd_vma
) -1
4439 || outrel
.r_offset
== (bfd_vma
) -2)
4442 outrel
.r_offset
+= (input_section
->output_section
->vma
4443 + input_section
->output_offset
);
4445 if (h
->dynindx
== -1
4447 || bfd_link_executable (info
))
4449 /* This symbol is resolved locally. */
4450 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4451 outrel
.r_addend
= (h
->root
.u
.def
.value
4452 + h
->root
.u
.def
.section
->output_section
->vma
4453 + h
->root
.u
.def
.section
->output_offset
);
4457 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4458 outrel
.r_addend
= 0;
4461 /* Dynamic relocations are stored in
4462 1. .rela.ifunc section in PIC object.
4463 2. .rela.got section in dynamic executable.
4464 3. .rela.iplt section in static executable. */
4465 if (bfd_link_pic (info
))
4466 sreloc
= htab
->elf
.irelifunc
;
4467 else if (htab
->elf
.splt
!= NULL
)
4468 sreloc
= htab
->elf
.srelgot
;
4470 sreloc
= htab
->elf
.irelplt
;
4471 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4473 /* If this reloc is against an external symbol, we
4474 do not want to fiddle with the addend. Otherwise,
4475 we need to include the symbol value so that it
4476 becomes an addend for the dynamic reloc. For an
4477 internal symbol, we have updated addend. */
4482 case R_X86_64_PC32_BND
:
4484 case R_X86_64_PLT32
:
4485 case R_X86_64_PLT32_BND
:
4490 resolved_to_zero
= (eh
!= NULL
4491 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4495 /* When generating a shared object, the relocations handled here are
4496 copied into the output file to be resolved at run time. */
4499 case R_X86_64_GOT32
:
4500 case R_X86_64_GOT64
:
4501 /* Relocation is to the entry for this symbol in the global
4503 case R_X86_64_GOTPCREL
:
4504 case R_X86_64_GOTPCRELX
:
4505 case R_X86_64_REX_GOTPCRELX
:
4506 case R_X86_64_GOTPCREL64
:
4507 /* Use global offset table entry as symbol value. */
4508 case R_X86_64_GOTPLT64
:
4509 /* This is obsolete and treated the the same as GOT64. */
4510 base_got
= htab
->elf
.sgot
;
4512 if (htab
->elf
.sgot
== NULL
)
4519 off
= h
->got
.offset
;
4521 && h
->plt
.offset
!= (bfd_vma
)-1
4522 && off
== (bfd_vma
)-1)
4524 /* We can't use h->got.offset here to save
4525 state, or even just remember the offset, as
4526 finish_dynamic_symbol would use that as offset into
4528 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
4529 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4530 base_got
= htab
->elf
.sgotplt
;
4533 dyn
= htab
->elf
.dynamic_sections_created
;
4535 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4536 || (bfd_link_pic (info
)
4537 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4538 || (ELF_ST_VISIBILITY (h
->other
)
4539 && h
->root
.type
== bfd_link_hash_undefweak
))
4541 /* This is actually a static link, or it is a -Bsymbolic
4542 link and the symbol is defined locally, or the symbol
4543 was forced to be local because of a version file. We
4544 must initialize this entry in the global offset table.
4545 Since the offset must always be a multiple of 8, we
4546 use the least significant bit to record whether we
4547 have initialized it already.
4549 When doing a dynamic link, we create a .rela.got
4550 relocation entry to initialize the value. This is
4551 done in the finish_dynamic_symbol routine. */
4556 bfd_put_64 (output_bfd
, relocation
,
4557 base_got
->contents
+ off
);
4558 /* Note that this is harmless for the GOTPLT64 case,
4559 as -1 | 1 still is -1. */
4564 unresolved_reloc
= FALSE
;
4568 if (local_got_offsets
== NULL
)
4571 off
= local_got_offsets
[r_symndx
];
4573 /* The offset must always be a multiple of 8. We use
4574 the least significant bit to record whether we have
4575 already generated the necessary reloc. */
4580 bfd_put_64 (output_bfd
, relocation
,
4581 base_got
->contents
+ off
);
4583 if (bfd_link_pic (info
))
4586 Elf_Internal_Rela outrel
;
4588 /* We need to generate a R_X86_64_RELATIVE reloc
4589 for the dynamic linker. */
4590 s
= htab
->elf
.srelgot
;
4594 outrel
.r_offset
= (base_got
->output_section
->vma
4595 + base_got
->output_offset
4597 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4598 outrel
.r_addend
= relocation
;
4599 elf_append_rela (output_bfd
, s
, &outrel
);
4602 local_got_offsets
[r_symndx
] |= 1;
4606 if (off
>= (bfd_vma
) -2)
4609 relocation
= base_got
->output_section
->vma
4610 + base_got
->output_offset
+ off
;
4611 if (r_type
!= R_X86_64_GOTPCREL
4612 && r_type
!= R_X86_64_GOTPCRELX
4613 && r_type
!= R_X86_64_REX_GOTPCRELX
4614 && r_type
!= R_X86_64_GOTPCREL64
)
4615 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4616 - htab
->elf
.sgotplt
->output_offset
;
4620 case R_X86_64_GOTOFF64
:
4621 /* Relocation is relative to the start of the global offset
4624 /* Check to make sure it isn't a protected function or data
4625 symbol for shared library since it may not be local when
4626 used as function address or with copy relocation. We also
4627 need to make sure that a symbol is referenced locally. */
4628 if (bfd_link_pic (info
) && h
)
4630 if (!h
->def_regular
)
4634 switch (ELF_ST_VISIBILITY (h
->other
))
4637 v
= _("hidden symbol");
4640 v
= _("internal symbol");
4643 v
= _("protected symbol");
4651 /* xgettext:c-format */
4652 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s `%s' can not be used when making a shared object"),
4653 input_bfd
, v
, h
->root
.root
.string
);
4654 bfd_set_error (bfd_error_bad_value
);
4657 else if (!bfd_link_executable (info
)
4658 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4659 && (h
->type
== STT_FUNC
4660 || h
->type
== STT_OBJECT
)
4661 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4664 /* xgettext:c-format */
4665 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"),
4667 h
->type
== STT_FUNC
? "function" : "data",
4668 h
->root
.root
.string
);
4669 bfd_set_error (bfd_error_bad_value
);
4674 /* Note that sgot is not involved in this
4675 calculation. We always want the start of .got.plt. If we
4676 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4677 permitted by the ABI, we might have to change this
4679 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4680 + htab
->elf
.sgotplt
->output_offset
;
4683 case R_X86_64_GOTPC32
:
4684 case R_X86_64_GOTPC64
:
4685 /* Use global offset table as symbol value. */
4686 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4687 + htab
->elf
.sgotplt
->output_offset
;
4688 unresolved_reloc
= FALSE
;
4691 case R_X86_64_PLTOFF64
:
4692 /* Relocation is PLT entry relative to GOT. For local
4693 symbols it's the symbol itself relative to GOT. */
4695 /* See PLT32 handling. */
4696 && (h
->plt
.offset
!= (bfd_vma
) -1
4697 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4698 && htab
->elf
.splt
!= NULL
)
4700 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4702 /* Use the GOT PLT. */
4703 resolved_plt
= htab
->plt_got
;
4704 plt_offset
= eh
->plt_got
.offset
;
4706 else if (htab
->plt_bnd
!= NULL
)
4708 resolved_plt
= htab
->plt_bnd
;
4709 plt_offset
= eh
->plt_bnd
.offset
;
4713 resolved_plt
= htab
->elf
.splt
;
4714 plt_offset
= h
->plt
.offset
;
4717 relocation
= (resolved_plt
->output_section
->vma
4718 + resolved_plt
->output_offset
4720 unresolved_reloc
= FALSE
;
4723 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4724 + htab
->elf
.sgotplt
->output_offset
;
4727 case R_X86_64_PLT32
:
4728 case R_X86_64_PLT32_BND
:
4729 /* Relocation is to the entry for this symbol in the
4730 procedure linkage table. */
4732 /* Resolve a PLT32 reloc against a local symbol directly,
4733 without using the procedure linkage table. */
4737 if ((h
->plt
.offset
== (bfd_vma
) -1
4738 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4739 || htab
->elf
.splt
== NULL
)
4741 /* We didn't make a PLT entry for this symbol. This
4742 happens when statically linking PIC code, or when
4743 using -Bsymbolic. */
4747 if (h
->plt
.offset
!= (bfd_vma
) -1)
4749 if (htab
->plt_bnd
!= NULL
)
4751 resolved_plt
= htab
->plt_bnd
;
4752 plt_offset
= eh
->plt_bnd
.offset
;
4756 resolved_plt
= htab
->elf
.splt
;
4757 plt_offset
= h
->plt
.offset
;
4762 /* Use the GOT PLT. */
4763 resolved_plt
= htab
->plt_got
;
4764 plt_offset
= eh
->plt_got
.offset
;
4767 relocation
= (resolved_plt
->output_section
->vma
4768 + resolved_plt
->output_offset
4770 unresolved_reloc
= FALSE
;
4773 case R_X86_64_SIZE32
:
4774 case R_X86_64_SIZE64
:
4775 /* Set to symbol size. */
4776 relocation
= st_size
;
4782 case R_X86_64_PC32_BND
:
4783 /* Don't complain about -fPIC if the symbol is undefined when
4784 building executable unless it is unresolved weak symbol. */
4785 if ((input_section
->flags
& SEC_ALLOC
) != 0
4786 && (input_section
->flags
& SEC_READONLY
) != 0
4788 && ((bfd_link_executable (info
)
4789 && h
->root
.type
== bfd_link_hash_undefweak
4790 && !resolved_to_zero
)
4791 || (bfd_link_pic (info
)
4792 && !(bfd_link_pie (info
)
4793 && h
->root
.type
== bfd_link_hash_undefined
))))
4795 bfd_boolean fail
= FALSE
;
4797 = ((r_type
== R_X86_64_PC32
4798 || r_type
== R_X86_64_PC32_BND
)
4799 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4801 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4803 /* Symbol is referenced locally. Make sure it is
4804 defined locally or for a branch. */
4805 fail
= !h
->def_regular
&& !branch
;
4807 else if (!(bfd_link_pie (info
)
4808 && (h
->needs_copy
|| eh
->needs_copy
)))
4810 /* Symbol doesn't need copy reloc and isn't referenced
4811 locally. We only allow branch to symbol with
4812 non-default visibility. */
4814 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4818 return elf_x86_64_need_pic (input_bfd
, input_section
,
4819 h
, NULL
, NULL
, howto
);
4828 /* FIXME: The ABI says the linker should make sure the value is
4829 the same when it's zeroextended to 64 bit. */
4832 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4835 /* Don't copy a pc-relative relocation into the output file
4836 if the symbol needs copy reloc or the symbol is undefined
4837 when building executable. Copy dynamic function pointer
4838 relocations. Don't generate dynamic relocations against
4839 resolved undefined weak symbols in PIE. */
4840 if ((bfd_link_pic (info
)
4841 && !(bfd_link_pie (info
)
4845 || h
->root
.type
== bfd_link_hash_undefined
)
4846 && (IS_X86_64_PCREL_TYPE (r_type
)
4847 || r_type
== R_X86_64_SIZE32
4848 || r_type
== R_X86_64_SIZE64
))
4850 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4851 && !resolved_to_zero
)
4852 || h
->root
.type
!= bfd_link_hash_undefweak
))
4853 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4854 && r_type
!= R_X86_64_SIZE32
4855 && r_type
!= R_X86_64_SIZE64
)
4856 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4857 || (ELIMINATE_COPY_RELOCS
4858 && !bfd_link_pic (info
)
4862 || eh
->func_pointer_refcount
> 0
4863 || (h
->root
.type
== bfd_link_hash_undefweak
4864 && !resolved_to_zero
))
4865 && ((h
->def_dynamic
&& !h
->def_regular
)
4866 /* Undefined weak symbol is bound locally when
4868 || h
->root
.type
== bfd_link_hash_undefined
)))
4870 Elf_Internal_Rela outrel
;
4871 bfd_boolean skip
, relocate
;
4874 /* When generating a shared object, these relocations
4875 are copied into the output file to be resolved at run
4881 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4883 if (outrel
.r_offset
== (bfd_vma
) -1)
4885 else if (outrel
.r_offset
== (bfd_vma
) -2)
4886 skip
= TRUE
, relocate
= TRUE
;
4888 outrel
.r_offset
+= (input_section
->output_section
->vma
4889 + input_section
->output_offset
);
4892 memset (&outrel
, 0, sizeof outrel
);
4894 /* h->dynindx may be -1 if this symbol was marked to
4898 && (IS_X86_64_PCREL_TYPE (r_type
)
4899 || !(bfd_link_executable (info
)
4900 || SYMBOLIC_BIND (info
, h
))
4901 || ! h
->def_regular
))
4903 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4904 outrel
.r_addend
= rel
->r_addend
;
4908 /* This symbol is local, or marked to become local.
4909 When relocation overflow check is disabled, we
4910 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4911 if (r_type
== htab
->pointer_r_type
4912 || (r_type
== R_X86_64_32
4913 && info
->no_reloc_overflow_check
))
4916 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4917 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4919 else if (r_type
== R_X86_64_64
4920 && !ABI_64_P (output_bfd
))
4923 outrel
.r_info
= htab
->r_info (0,
4924 R_X86_64_RELATIVE64
);
4925 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4926 /* Check addend overflow. */
4927 if ((outrel
.r_addend
& 0x80000000)
4928 != (rel
->r_addend
& 0x80000000))
4931 int addend
= rel
->r_addend
;
4932 if (h
&& h
->root
.root
.string
)
4933 name
= h
->root
.root
.string
;
4935 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4939 /* xgettext:c-format */
4940 (_("%B: addend -0x%x in relocation %s against "
4941 "symbol `%s' at 0x%lx in section `%A' is "
4943 input_bfd
, input_section
, addend
,
4945 (unsigned long) rel
->r_offset
);
4948 /* xgettext:c-format */
4949 (_("%B: addend 0x%x in relocation %s against "
4950 "symbol `%s' at 0x%lx in section `%A' is "
4952 input_bfd
, input_section
, addend
,
4954 (unsigned long) rel
->r_offset
);
4955 bfd_set_error (bfd_error_bad_value
);
4963 if (bfd_is_abs_section (sec
))
4965 else if (sec
== NULL
|| sec
->owner
== NULL
)
4967 bfd_set_error (bfd_error_bad_value
);
4974 /* We are turning this relocation into one
4975 against a section symbol. It would be
4976 proper to subtract the symbol's value,
4977 osec->vma, from the emitted reloc addend,
4978 but ld.so expects buggy relocs. */
4979 osec
= sec
->output_section
;
4980 sindx
= elf_section_data (osec
)->dynindx
;
4983 asection
*oi
= htab
->elf
.text_index_section
;
4984 sindx
= elf_section_data (oi
)->dynindx
;
4986 BFD_ASSERT (sindx
!= 0);
4989 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
4990 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4994 sreloc
= elf_section_data (input_section
)->sreloc
;
4996 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4998 r
= bfd_reloc_notsupported
;
4999 goto check_relocation_error
;
5002 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5004 /* If this reloc is against an external symbol, we do
5005 not want to fiddle with the addend. Otherwise, we
5006 need to include the symbol value so that it becomes
5007 an addend for the dynamic reloc. */
5014 case R_X86_64_TLSGD
:
5015 case R_X86_64_GOTPC32_TLSDESC
:
5016 case R_X86_64_TLSDESC_CALL
:
5017 case R_X86_64_GOTTPOFF
:
5018 tls_type
= GOT_UNKNOWN
;
5019 if (h
== NULL
&& local_got_offsets
)
5020 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5022 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5024 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5025 input_section
, contents
,
5026 symtab_hdr
, sym_hashes
,
5027 &r_type
, tls_type
, rel
,
5028 relend
, h
, r_symndx
, TRUE
))
5031 if (r_type
== R_X86_64_TPOFF32
)
5033 bfd_vma roff
= rel
->r_offset
;
5035 BFD_ASSERT (! unresolved_reloc
);
5037 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5039 /* GD->LE transition. For 64bit, change
5040 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5041 .word 0x6666; rex64; call __tls_get_addr@PLT
5043 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5045 call *__tls_get_addr@GOTPCREL(%rip)
5046 which may be converted to
5047 addr32 call __tls_get_addr
5050 leaq foo@tpoff(%rax), %rax
5052 leaq foo@tlsgd(%rip), %rdi
5053 .word 0x6666; rex64; call __tls_get_addr@PLT
5055 leaq foo@tlsgd(%rip), %rdi
5057 call *__tls_get_addr@GOTPCREL(%rip)
5058 which may be converted to
5059 addr32 call __tls_get_addr
5062 leaq foo@tpoff(%rax), %rax
5063 For largepic, change:
5064 leaq foo@tlsgd(%rip), %rdi
5065 movabsq $__tls_get_addr@pltoff, %rax
5070 leaq foo@tpoff(%rax), %rax
5071 nopw 0x0(%rax,%rax,1) */
5073 if (ABI_64_P (output_bfd
))
5075 if (contents
[roff
+ 5] == 0xb8)
5077 memcpy (contents
+ roff
- 3,
5078 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5079 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5083 memcpy (contents
+ roff
- 4,
5084 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5088 memcpy (contents
+ roff
- 3,
5089 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5091 bfd_put_32 (output_bfd
,
5092 elf_x86_64_tpoff (info
, relocation
),
5093 contents
+ roff
+ 8 + largepic
);
5094 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5095 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5100 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5102 /* GDesc -> LE transition.
5103 It's originally something like:
5104 leaq x@tlsdesc(%rip), %rax
5107 movl $x@tpoff, %rax. */
5109 unsigned int val
, type
;
5111 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5112 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5113 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5114 contents
+ roff
- 3);
5115 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5116 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5117 contents
+ roff
- 1);
5118 bfd_put_32 (output_bfd
,
5119 elf_x86_64_tpoff (info
, relocation
),
5123 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5125 /* GDesc -> LE transition.
5130 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5131 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5134 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5136 /* IE->LE transition:
5137 For 64bit, originally it can be one of:
5138 movq foo@gottpoff(%rip), %reg
5139 addq foo@gottpoff(%rip), %reg
5142 leaq foo(%reg), %reg
5144 For 32bit, originally it can be one of:
5145 movq foo@gottpoff(%rip), %reg
5146 addl foo@gottpoff(%rip), %reg
5149 leal foo(%reg), %reg
5152 unsigned int val
, type
, reg
;
5155 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5158 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5159 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5165 bfd_put_8 (output_bfd
, 0x49,
5166 contents
+ roff
- 3);
5167 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5168 bfd_put_8 (output_bfd
, 0x41,
5169 contents
+ roff
- 3);
5170 bfd_put_8 (output_bfd
, 0xc7,
5171 contents
+ roff
- 2);
5172 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5173 contents
+ roff
- 1);
5177 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5180 bfd_put_8 (output_bfd
, 0x49,
5181 contents
+ roff
- 3);
5182 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5183 bfd_put_8 (output_bfd
, 0x41,
5184 contents
+ roff
- 3);
5185 bfd_put_8 (output_bfd
, 0x81,
5186 contents
+ roff
- 2);
5187 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5188 contents
+ roff
- 1);
5192 /* addq/addl -> leaq/leal */
5194 bfd_put_8 (output_bfd
, 0x4d,
5195 contents
+ roff
- 3);
5196 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5197 bfd_put_8 (output_bfd
, 0x45,
5198 contents
+ roff
- 3);
5199 bfd_put_8 (output_bfd
, 0x8d,
5200 contents
+ roff
- 2);
5201 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5202 contents
+ roff
- 1);
5204 bfd_put_32 (output_bfd
,
5205 elf_x86_64_tpoff (info
, relocation
),
5213 if (htab
->elf
.sgot
== NULL
)
5218 off
= h
->got
.offset
;
5219 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5223 if (local_got_offsets
== NULL
)
5226 off
= local_got_offsets
[r_symndx
];
5227 offplt
= local_tlsdesc_gotents
[r_symndx
];
5234 Elf_Internal_Rela outrel
;
5238 if (htab
->elf
.srelgot
== NULL
)
5241 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5243 if (GOT_TLS_GDESC_P (tls_type
))
5245 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5246 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5247 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5248 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5249 + htab
->elf
.sgotplt
->output_offset
5251 + htab
->sgotplt_jump_table_size
);
5252 sreloc
= htab
->elf
.srelplt
;
5254 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5256 outrel
.r_addend
= 0;
5257 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5260 sreloc
= htab
->elf
.srelgot
;
5262 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5263 + htab
->elf
.sgot
->output_offset
+ off
);
5265 if (GOT_TLS_GD_P (tls_type
))
5266 dr_type
= R_X86_64_DTPMOD64
;
5267 else if (GOT_TLS_GDESC_P (tls_type
))
5270 dr_type
= R_X86_64_TPOFF64
;
5272 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5273 outrel
.r_addend
= 0;
5274 if ((dr_type
== R_X86_64_TPOFF64
5275 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5276 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5277 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5279 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5281 if (GOT_TLS_GD_P (tls_type
))
5285 BFD_ASSERT (! unresolved_reloc
);
5286 bfd_put_64 (output_bfd
,
5287 relocation
- elf_x86_64_dtpoff_base (info
),
5288 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5292 bfd_put_64 (output_bfd
, 0,
5293 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5294 outrel
.r_info
= htab
->r_info (indx
,
5296 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5297 elf_append_rela (output_bfd
, sreloc
,
5306 local_got_offsets
[r_symndx
] |= 1;
5309 if (off
>= (bfd_vma
) -2
5310 && ! GOT_TLS_GDESC_P (tls_type
))
5312 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5314 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5315 || r_type
== R_X86_64_TLSDESC_CALL
)
5316 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5317 + htab
->elf
.sgotplt
->output_offset
5318 + offplt
+ htab
->sgotplt_jump_table_size
;
5320 relocation
= htab
->elf
.sgot
->output_section
->vma
5321 + htab
->elf
.sgot
->output_offset
+ off
;
5322 unresolved_reloc
= FALSE
;
5326 bfd_vma roff
= rel
->r_offset
;
5328 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5330 /* GD->IE transition. For 64bit, change
5331 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5332 .word 0x6666; rex64; call __tls_get_addr@PLT
5334 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5336 call *__tls_get_addr@GOTPCREL(%rip
5337 which may be converted to
5338 addr32 call __tls_get_addr
5341 addq foo@gottpoff(%rip), %rax
5343 leaq foo@tlsgd(%rip), %rdi
5344 .word 0x6666; rex64; call __tls_get_addr@PLT
5346 leaq foo@tlsgd(%rip), %rdi
5348 call *__tls_get_addr@GOTPCREL(%rip)
5349 which may be converted to
5350 addr32 call __tls_get_addr
5353 addq foo@gottpoff(%rip), %rax
5354 For largepic, change:
5355 leaq foo@tlsgd(%rip), %rdi
5356 movabsq $__tls_get_addr@pltoff, %rax
5361 addq foo@gottpoff(%rax), %rax
5362 nopw 0x0(%rax,%rax,1) */
5364 if (ABI_64_P (output_bfd
))
5366 if (contents
[roff
+ 5] == 0xb8)
5368 memcpy (contents
+ roff
- 3,
5369 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5370 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5374 memcpy (contents
+ roff
- 4,
5375 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5379 memcpy (contents
+ roff
- 3,
5380 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5383 relocation
= (htab
->elf
.sgot
->output_section
->vma
5384 + htab
->elf
.sgot
->output_offset
+ off
5387 - input_section
->output_section
->vma
5388 - input_section
->output_offset
5390 bfd_put_32 (output_bfd
, relocation
,
5391 contents
+ roff
+ 8 + largepic
);
5392 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5397 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5399 /* GDesc -> IE transition.
5400 It's originally something like:
5401 leaq x@tlsdesc(%rip), %rax
5404 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5406 /* Now modify the instruction as appropriate. To
5407 turn a leaq into a movq in the form we use it, it
5408 suffices to change the second byte from 0x8d to
5410 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5412 bfd_put_32 (output_bfd
,
5413 htab
->elf
.sgot
->output_section
->vma
5414 + htab
->elf
.sgot
->output_offset
+ off
5416 - input_section
->output_section
->vma
5417 - input_section
->output_offset
5422 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5424 /* GDesc -> IE transition.
5431 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5432 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5440 case R_X86_64_TLSLD
:
5441 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5442 input_section
, contents
,
5443 symtab_hdr
, sym_hashes
,
5444 &r_type
, GOT_UNKNOWN
, rel
,
5445 relend
, h
, r_symndx
, TRUE
))
5448 if (r_type
!= R_X86_64_TLSLD
)
5450 /* LD->LE transition:
5451 leaq foo@tlsld(%rip), %rdi
5452 call __tls_get_addr@PLT
5453 For 64bit, we change it into:
5454 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5455 For 32bit, we change it into:
5456 nopl 0x0(%rax); movl %fs:0, %eax
5458 leaq foo@tlsld(%rip), %rdi;
5459 call *__tls_get_addr@GOTPCREL(%rip)
5460 which may be converted to
5461 addr32 call __tls_get_addr
5462 For 64bit, we change it into:
5463 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5464 For 32bit, we change it into:
5465 nopw 0x0(%rax); movl %fs:0, %eax
5466 For largepic, change:
5467 leaq foo@tlsgd(%rip), %rdi
5468 movabsq $__tls_get_addr@pltoff, %rax
5472 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5475 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5476 if (ABI_64_P (output_bfd
))
5478 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5479 memcpy (contents
+ rel
->r_offset
- 3,
5480 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5481 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5482 else if (contents
[rel
->r_offset
+ 4] == 0xff
5483 || contents
[rel
->r_offset
+ 4] == 0x67)
5484 memcpy (contents
+ rel
->r_offset
- 3,
5485 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5488 memcpy (contents
+ rel
->r_offset
- 3,
5489 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5493 if (contents
[rel
->r_offset
+ 4] == 0xff)
5494 memcpy (contents
+ rel
->r_offset
- 3,
5495 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5498 memcpy (contents
+ rel
->r_offset
- 3,
5499 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5501 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5502 and R_X86_64_PLTOFF64. */
5508 if (htab
->elf
.sgot
== NULL
)
5511 off
= htab
->tls_ld_got
.offset
;
5516 Elf_Internal_Rela outrel
;
5518 if (htab
->elf
.srelgot
== NULL
)
5521 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5522 + htab
->elf
.sgot
->output_offset
+ off
);
5524 bfd_put_64 (output_bfd
, 0,
5525 htab
->elf
.sgot
->contents
+ off
);
5526 bfd_put_64 (output_bfd
, 0,
5527 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5528 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5529 outrel
.r_addend
= 0;
5530 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5532 htab
->tls_ld_got
.offset
|= 1;
5534 relocation
= htab
->elf
.sgot
->output_section
->vma
5535 + htab
->elf
.sgot
->output_offset
+ off
;
5536 unresolved_reloc
= FALSE
;
5539 case R_X86_64_DTPOFF32
:
5540 if (!bfd_link_executable (info
)
5541 || (input_section
->flags
& SEC_CODE
) == 0)
5542 relocation
-= elf_x86_64_dtpoff_base (info
);
5544 relocation
= elf_x86_64_tpoff (info
, relocation
);
5547 case R_X86_64_TPOFF32
:
5548 case R_X86_64_TPOFF64
:
5549 BFD_ASSERT (bfd_link_executable (info
));
5550 relocation
= elf_x86_64_tpoff (info
, relocation
);
5553 case R_X86_64_DTPOFF64
:
5554 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5555 relocation
-= elf_x86_64_dtpoff_base (info
);
5562 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5563 because such sections are not SEC_ALLOC and thus ld.so will
5564 not process them. */
5565 if (unresolved_reloc
5566 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5568 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5569 rel
->r_offset
) != (bfd_vma
) -1)
5572 /* xgettext:c-format */
5573 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5576 (long) rel
->r_offset
,
5578 h
->root
.root
.string
);
5583 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5584 contents
, rel
->r_offset
,
5585 relocation
, rel
->r_addend
);
5587 check_relocation_error
:
5588 if (r
!= bfd_reloc_ok
)
5593 name
= h
->root
.root
.string
;
5596 name
= bfd_elf_string_from_elf_section (input_bfd
,
5597 symtab_hdr
->sh_link
,
5602 name
= bfd_section_name (input_bfd
, sec
);
5605 if (r
== bfd_reloc_overflow
)
5606 (*info
->callbacks
->reloc_overflow
)
5607 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5608 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5612 /* xgettext:c-format */
5613 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5614 input_bfd
, input_section
,
5615 (long) rel
->r_offset
, name
, (int) r
);
5626 Elf_Internal_Shdr
*rel_hdr
;
5627 size_t deleted
= rel
- wrel
;
5629 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5630 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5631 if (rel_hdr
->sh_size
== 0)
5633 /* It is too late to remove an empty reloc section. Leave
5635 ??? What is wrong with an empty section??? */
5636 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5639 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5640 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5641 input_section
->reloc_count
-= deleted
;
5647 /* Finish up dynamic symbol handling. We set the contents of various
5648 dynamic sections here. */
5651 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5652 struct bfd_link_info
*info
,
5653 struct elf_link_hash_entry
*h
,
5654 Elf_Internal_Sym
*sym
)
5656 struct elf_x86_64_link_hash_table
*htab
;
5657 const struct elf_x86_64_backend_data
*abed
;
5658 bfd_boolean use_plt_bnd
;
5659 struct elf_x86_64_link_hash_entry
*eh
;
5660 bfd_boolean local_undefweak
;
5662 htab
= elf_x86_64_hash_table (info
);
5666 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5667 section only if there is .plt section. */
5668 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5670 ? &elf_x86_64_bnd_arch_bed
5671 : get_elf_x86_64_backend_data (output_bfd
));
5673 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5675 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5676 resolved undefined weak symbols in executable so that their
5677 references have value 0 at run-time. */
5678 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5682 if (h
->plt
.offset
!= (bfd_vma
) -1)
5685 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
5686 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
5687 Elf_Internal_Rela rela
;
5689 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5690 const struct elf_backend_data
*bed
;
5691 bfd_vma plt_got_pcrel_offset
;
5693 /* When building a static executable, use .iplt, .igot.plt and
5694 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5695 if (htab
->elf
.splt
!= NULL
)
5697 plt
= htab
->elf
.splt
;
5698 gotplt
= htab
->elf
.sgotplt
;
5699 relplt
= htab
->elf
.srelplt
;
5703 plt
= htab
->elf
.iplt
;
5704 gotplt
= htab
->elf
.igotplt
;
5705 relplt
= htab
->elf
.irelplt
;
5708 /* This symbol has an entry in the procedure linkage table. Set
5710 if ((h
->dynindx
== -1
5712 && !((h
->forced_local
|| bfd_link_executable (info
))
5714 && h
->type
== STT_GNU_IFUNC
))
5720 /* Get the index in the procedure linkage table which
5721 corresponds to this symbol. This is the index of this symbol
5722 in all the symbols for which we are making plt entries. The
5723 first entry in the procedure linkage table is reserved.
5725 Get the offset into the .got table of the entry that
5726 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5727 bytes. The first three are reserved for the dynamic linker.
5729 For static executables, we don't reserve anything. */
5731 if (plt
== htab
->elf
.splt
)
5733 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
5734 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5738 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
5739 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5742 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
5743 plt_plt_offset
= abed
->plt_plt_offset
;
5744 plt_got_insn_size
= abed
->plt_got_insn_size
;
5745 plt_got_offset
= abed
->plt_got_offset
;
5748 /* Use the second PLT with BND relocations. */
5749 const bfd_byte
*plt_entry
, *plt2_entry
;
5751 if (eh
->has_bnd_reloc
)
5753 plt_entry
= elf_x86_64_bnd_plt_entry
;
5754 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
5758 plt_entry
= elf_x86_64_legacy_plt_entry
;
5759 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
5761 /* Subtract 1 since there is no BND prefix. */
5762 plt_plt_insn_end
-= 1;
5763 plt_plt_offset
-= 1;
5764 plt_got_insn_size
-= 1;
5765 plt_got_offset
-= 1;
5768 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
5769 == sizeof (elf_x86_64_legacy_plt_entry
));
5771 /* Fill in the entry in the procedure linkage table. */
5772 memcpy (plt
->contents
+ h
->plt
.offset
,
5773 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
5774 /* Fill in the entry in the second PLT. */
5775 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5776 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5778 resolved_plt
= htab
->plt_bnd
;
5779 plt_offset
= eh
->plt_bnd
.offset
;
5783 /* Fill in the entry in the procedure linkage table. */
5784 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
5785 abed
->plt_entry_size
);
5788 plt_offset
= h
->plt
.offset
;
5791 /* Insert the relocation positions of the plt section. */
5793 /* Put offset the PC-relative instruction referring to the GOT entry,
5794 subtracting the size of that instruction. */
5795 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5796 + gotplt
->output_offset
5798 - resolved_plt
->output_section
->vma
5799 - resolved_plt
->output_offset
5801 - plt_got_insn_size
);
5803 /* Check PC-relative offset overflow in PLT entry. */
5804 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5805 /* xgettext:c-format */
5806 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5807 output_bfd
, h
->root
.root
.string
);
5809 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5810 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
5812 /* Fill in the entry in the global offset table, initially this
5813 points to the second part of the PLT entry. Leave the entry
5814 as zero for undefined weak symbol in PIE. No PLT relocation
5815 against undefined weak symbol in PIE. */
5816 if (!local_undefweak
)
5818 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5819 + plt
->output_offset
5821 + abed
->plt_lazy_offset
),
5822 gotplt
->contents
+ got_offset
);
5824 /* Fill in the entry in the .rela.plt section. */
5825 rela
.r_offset
= (gotplt
->output_section
->vma
5826 + gotplt
->output_offset
5828 if (h
->dynindx
== -1
5829 || ((bfd_link_executable (info
)
5830 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5832 && h
->type
== STT_GNU_IFUNC
))
5834 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5835 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5836 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5837 rela
.r_addend
= (h
->root
.u
.def
.value
5838 + h
->root
.u
.def
.section
->output_section
->vma
5839 + h
->root
.u
.def
.section
->output_offset
);
5840 /* R_X86_64_IRELATIVE comes last. */
5841 plt_index
= htab
->next_irelative_index
--;
5845 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5847 plt_index
= htab
->next_jump_slot_index
++;
5850 /* Don't fill PLT entry for static executables. */
5851 if (plt
== htab
->elf
.splt
)
5853 bfd_vma plt0_offset
= h
->plt
.offset
+ plt_plt_insn_end
;
5855 /* Put relocation index. */
5856 bfd_put_32 (output_bfd
, plt_index
,
5857 (plt
->contents
+ h
->plt
.offset
5858 + abed
->plt_reloc_offset
));
5860 /* Put offset for jmp .PLT0 and check for overflow. We don't
5861 check relocation index for overflow since branch displacement
5862 will overflow first. */
5863 if (plt0_offset
> 0x80000000)
5864 /* xgettext:c-format */
5865 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5866 output_bfd
, h
->root
.root
.string
);
5867 bfd_put_32 (output_bfd
, - plt0_offset
,
5868 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
5871 bed
= get_elf_backend_data (output_bfd
);
5872 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
5873 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
5876 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5878 bfd_vma got_offset
, plt_offset
, plt_got_offset
, plt_got_insn_size
;
5879 asection
*plt
, *got
;
5880 bfd_boolean got_after_plt
;
5881 int32_t got_pcrel_offset
;
5882 const bfd_byte
*got_plt_entry
;
5884 /* Set the entry in the GOT procedure linkage table. */
5885 plt
= htab
->plt_got
;
5886 got
= htab
->elf
.sgot
;
5887 got_offset
= h
->got
.offset
;
5889 if (got_offset
== (bfd_vma
) -1
5890 || h
->type
== STT_GNU_IFUNC
5895 /* Use the second PLT entry template for the GOT PLT since they
5896 are the identical. */
5897 plt_got_insn_size
= elf_x86_64_bnd_arch_bed
.plt_got_insn_size
;
5898 plt_got_offset
= elf_x86_64_bnd_arch_bed
.plt_got_offset
;
5899 if (eh
->has_bnd_reloc
)
5900 got_plt_entry
= elf_x86_64_bnd_plt2_entry
;
5903 got_plt_entry
= elf_x86_64_legacy_plt2_entry
;
5905 /* Subtract 1 since there is no BND prefix. */
5906 plt_got_insn_size
-= 1;
5907 plt_got_offset
-= 1;
5910 /* Fill in the entry in the GOT procedure linkage table. */
5911 plt_offset
= eh
->plt_got
.offset
;
5912 memcpy (plt
->contents
+ plt_offset
,
5913 got_plt_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5915 /* Put offset the PC-relative instruction referring to the GOT
5916 entry, subtracting the size of that instruction. */
5917 got_pcrel_offset
= (got
->output_section
->vma
5918 + got
->output_offset
5920 - plt
->output_section
->vma
5921 - plt
->output_offset
5923 - plt_got_insn_size
);
5925 /* Check PC-relative offset overflow in GOT PLT entry. */
5926 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
5927 if ((got_after_plt
&& got_pcrel_offset
< 0)
5928 || (!got_after_plt
&& got_pcrel_offset
> 0))
5929 /* xgettext:c-format */
5930 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5931 output_bfd
, h
->root
.root
.string
);
5933 bfd_put_32 (output_bfd
, got_pcrel_offset
,
5934 plt
->contents
+ plt_offset
+ plt_got_offset
);
5937 if (!local_undefweak
5939 && (h
->plt
.offset
!= (bfd_vma
) -1
5940 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5942 /* Mark the symbol as undefined, rather than as defined in
5943 the .plt section. Leave the value if there were any
5944 relocations where pointer equality matters (this is a clue
5945 for the dynamic linker, to make function pointer
5946 comparisons work between an application and shared
5947 library), otherwise set it to zero. If a function is only
5948 called from a binary, there is no need to slow down
5949 shared libraries because of that. */
5950 sym
->st_shndx
= SHN_UNDEF
;
5951 if (!h
->pointer_equality_needed
)
5955 /* Don't generate dynamic GOT relocation against undefined weak
5956 symbol in executable. */
5957 if (h
->got
.offset
!= (bfd_vma
) -1
5958 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
5959 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
5960 && !local_undefweak
)
5962 Elf_Internal_Rela rela
;
5963 asection
*relgot
= htab
->elf
.srelgot
;
5965 /* This symbol has an entry in the global offset table. Set it
5967 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5970 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5971 + htab
->elf
.sgot
->output_offset
5972 + (h
->got
.offset
&~ (bfd_vma
) 1));
5974 /* If this is a static link, or it is a -Bsymbolic link and the
5975 symbol is defined locally or was forced to be local because
5976 of a version file, we just want to emit a RELATIVE reloc.
5977 The entry in the global offset table will already have been
5978 initialized in the relocate_section function. */
5980 && h
->type
== STT_GNU_IFUNC
)
5982 if (h
->plt
.offset
== (bfd_vma
) -1)
5984 /* STT_GNU_IFUNC is referenced without PLT. */
5985 if (htab
->elf
.splt
== NULL
)
5987 /* use .rel[a].iplt section to store .got relocations
5988 in static executable. */
5989 relgot
= htab
->elf
.irelplt
;
5991 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5993 rela
.r_info
= htab
->r_info (0,
5994 R_X86_64_IRELATIVE
);
5995 rela
.r_addend
= (h
->root
.u
.def
.value
5996 + h
->root
.u
.def
.section
->output_section
->vma
5997 + h
->root
.u
.def
.section
->output_offset
);
6002 else if (bfd_link_pic (info
))
6004 /* Generate R_X86_64_GLOB_DAT. */
6011 if (!h
->pointer_equality_needed
)
6014 /* For non-shared object, we can't use .got.plt, which
6015 contains the real function addres if we need pointer
6016 equality. We load the GOT entry with the PLT entry. */
6017 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6018 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6019 + plt
->output_offset
6021 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6025 else if (bfd_link_pic (info
)
6026 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6028 if (!h
->def_regular
)
6030 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6031 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6032 rela
.r_addend
= (h
->root
.u
.def
.value
6033 + h
->root
.u
.def
.section
->output_section
->vma
6034 + h
->root
.u
.def
.section
->output_offset
);
6038 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6040 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6041 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6042 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6046 elf_append_rela (output_bfd
, relgot
, &rela
);
6051 Elf_Internal_Rela rela
;
6053 /* This symbol needs a copy reloc. Set it up. */
6055 if (h
->dynindx
== -1
6056 || (h
->root
.type
!= bfd_link_hash_defined
6057 && h
->root
.type
!= bfd_link_hash_defweak
)
6058 || htab
->srelbss
== NULL
)
6061 rela
.r_offset
= (h
->root
.u
.def
.value
6062 + h
->root
.u
.def
.section
->output_section
->vma
6063 + h
->root
.u
.def
.section
->output_offset
);
6064 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6066 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
6072 /* Finish up local dynamic symbol handling. We set the contents of
6073 various dynamic sections here. */
6076 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6078 struct elf_link_hash_entry
*h
6079 = (struct elf_link_hash_entry
*) *slot
;
6080 struct bfd_link_info
*info
6081 = (struct bfd_link_info
*) inf
;
6083 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6087 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6088 here since undefined weak symbol may not be dynamic and may not be
6089 called for elf_x86_64_finish_dynamic_symbol. */
6092 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6095 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6096 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6098 if (h
->root
.type
!= bfd_link_hash_undefweak
6099 || h
->dynindx
!= -1)
6102 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6106 /* Used to decide how to sort relocs in an optimal manner for the
6107 dynamic linker, before writing them out. */
6109 static enum elf_reloc_type_class
6110 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6111 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6112 const Elf_Internal_Rela
*rela
)
6114 bfd
*abfd
= info
->output_bfd
;
6115 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6116 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6118 if (htab
->elf
.dynsym
!= NULL
6119 && htab
->elf
.dynsym
->contents
!= NULL
)
6121 /* Check relocation against STT_GNU_IFUNC symbol if there are
6123 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6124 if (r_symndx
!= STN_UNDEF
)
6126 Elf_Internal_Sym sym
;
6127 if (!bed
->s
->swap_symbol_in (abfd
,
6128 (htab
->elf
.dynsym
->contents
6129 + r_symndx
* bed
->s
->sizeof_sym
),
6133 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6134 return reloc_class_ifunc
;
6138 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6140 case R_X86_64_IRELATIVE
:
6141 return reloc_class_ifunc
;
6142 case R_X86_64_RELATIVE
:
6143 case R_X86_64_RELATIVE64
:
6144 return reloc_class_relative
;
6145 case R_X86_64_JUMP_SLOT
:
6146 return reloc_class_plt
;
6148 return reloc_class_copy
;
6150 return reloc_class_normal
;
6154 /* Finish up the dynamic sections. */
6157 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6158 struct bfd_link_info
*info
)
6160 struct elf_x86_64_link_hash_table
*htab
;
6163 const struct elf_x86_64_backend_data
*abed
;
6165 htab
= elf_x86_64_hash_table (info
);
6169 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6170 section only if there is .plt section. */
6171 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
6172 ? &elf_x86_64_bnd_arch_bed
6173 : get_elf_x86_64_backend_data (output_bfd
));
6175 dynobj
= htab
->elf
.dynobj
;
6176 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6178 if (htab
->elf
.dynamic_sections_created
)
6180 bfd_byte
*dyncon
, *dynconend
;
6181 const struct elf_backend_data
*bed
;
6182 bfd_size_type sizeof_dyn
;
6184 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6187 bed
= get_elf_backend_data (dynobj
);
6188 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6189 dyncon
= sdyn
->contents
;
6190 dynconend
= sdyn
->contents
+ sdyn
->size
;
6191 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6193 Elf_Internal_Dyn dyn
;
6196 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6204 s
= htab
->elf
.sgotplt
;
6205 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6209 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6213 s
= htab
->elf
.srelplt
->output_section
;
6214 dyn
.d_un
.d_val
= s
->size
;
6217 case DT_TLSDESC_PLT
:
6219 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6220 + htab
->tlsdesc_plt
;
6223 case DT_TLSDESC_GOT
:
6225 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6226 + htab
->tlsdesc_got
;
6230 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6233 /* Fill in the special first entry in the procedure linkage table. */
6234 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6236 /* Fill in the first entry in the procedure linkage table. */
6237 memcpy (htab
->elf
.splt
->contents
,
6238 abed
->plt0_entry
, abed
->plt_entry_size
);
6239 /* Add offset for pushq GOT+8(%rip), since the instruction
6240 uses 6 bytes subtract this value. */
6241 bfd_put_32 (output_bfd
,
6242 (htab
->elf
.sgotplt
->output_section
->vma
6243 + htab
->elf
.sgotplt
->output_offset
6245 - htab
->elf
.splt
->output_section
->vma
6246 - htab
->elf
.splt
->output_offset
6248 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
6249 /* Add offset for the PC-relative instruction accessing GOT+16,
6250 subtracting the offset to the end of that instruction. */
6251 bfd_put_32 (output_bfd
,
6252 (htab
->elf
.sgotplt
->output_section
->vma
6253 + htab
->elf
.sgotplt
->output_offset
6255 - htab
->elf
.splt
->output_section
->vma
6256 - htab
->elf
.splt
->output_offset
6257 - abed
->plt0_got2_insn_end
),
6258 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
6260 elf_section_data (htab
->elf
.splt
->output_section
)
6261 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
6263 if (htab
->tlsdesc_plt
)
6265 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6266 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6268 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6269 abed
->plt0_entry
, abed
->plt_entry_size
);
6271 /* Add offset for pushq GOT+8(%rip), since the
6272 instruction uses 6 bytes subtract this value. */
6273 bfd_put_32 (output_bfd
,
6274 (htab
->elf
.sgotplt
->output_section
->vma
6275 + htab
->elf
.sgotplt
->output_offset
6277 - htab
->elf
.splt
->output_section
->vma
6278 - htab
->elf
.splt
->output_offset
6281 htab
->elf
.splt
->contents
6282 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
6283 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6284 where TGD stands for htab->tlsdesc_got, subtracting the offset
6285 to the end of that instruction. */
6286 bfd_put_32 (output_bfd
,
6287 (htab
->elf
.sgot
->output_section
->vma
6288 + htab
->elf
.sgot
->output_offset
6290 - htab
->elf
.splt
->output_section
->vma
6291 - htab
->elf
.splt
->output_offset
6293 - abed
->plt0_got2_insn_end
),
6294 htab
->elf
.splt
->contents
6295 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
6300 if (htab
->plt_bnd
!= NULL
)
6301 elf_section_data (htab
->plt_bnd
->output_section
)
6302 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
6304 if (htab
->elf
.sgotplt
)
6306 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6309 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6313 /* Fill in the first three entries in the global offset table. */
6314 if (htab
->elf
.sgotplt
->size
> 0)
6316 /* Set the first entry in the global offset table to the address of
6317 the dynamic section. */
6319 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6321 bfd_put_64 (output_bfd
,
6322 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6323 htab
->elf
.sgotplt
->contents
);
6324 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6325 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6326 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6329 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
6333 /* Adjust .eh_frame for .plt section. */
6334 if (htab
->plt_eh_frame
!= NULL
6335 && htab
->plt_eh_frame
->contents
!= NULL
)
6337 if (htab
->elf
.splt
!= NULL
6338 && htab
->elf
.splt
->size
!= 0
6339 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6340 && htab
->elf
.splt
->output_section
!= NULL
6341 && htab
->plt_eh_frame
->output_section
!= NULL
)
6343 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6344 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6345 + htab
->plt_eh_frame
->output_offset
6346 + PLT_FDE_START_OFFSET
;
6347 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6348 htab
->plt_eh_frame
->contents
6349 + PLT_FDE_START_OFFSET
);
6351 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6353 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6355 htab
->plt_eh_frame
->contents
))
6360 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6361 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6364 /* Fill PLT entries for undefined weak symbols in PIE. */
6365 if (bfd_link_pie (info
))
6366 bfd_hash_traverse (&info
->hash
->table
,
6367 elf_x86_64_pie_finish_undefweak_symbol
,
6373 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6374 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6375 It has to be done before elf_link_sort_relocs is called so that
6376 dynamic relocations are properly sorted. */
6379 elf_x86_64_output_arch_local_syms
6380 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6381 struct bfd_link_info
*info
,
6382 void *flaginfo ATTRIBUTE_UNUSED
,
6383 int (*func
) (void *, const char *,
6386 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6388 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6392 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6393 htab_traverse (htab
->loc_hash_table
,
6394 elf_x86_64_finish_local_dynamic_symbol
,
6400 /* Return an array of PLT entry symbol values. */
6403 elf_x86_64_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6406 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6409 bfd_vma
*plt_sym_val
;
6411 bfd_byte
*plt_contents
;
6412 const struct elf_x86_64_backend_data
*bed
;
6413 Elf_Internal_Shdr
*hdr
;
6416 /* Get the .plt section contents. PLT passed down may point to the
6417 .plt.bnd section. Make sure that PLT always points to the .plt
6419 plt_bnd
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6424 plt
= bfd_get_section_by_name (abfd
, ".plt");
6427 bed
= &elf_x86_64_bnd_arch_bed
;
6430 bed
= get_elf_x86_64_backend_data (abfd
);
6432 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6433 if (plt_contents
== NULL
)
6435 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6436 plt_contents
, 0, plt
->size
))
6439 free (plt_contents
);
6443 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6444 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6447 hdr
= &elf_section_data (relplt
)->this_hdr
;
6448 count
= relplt
->size
/ hdr
->sh_entsize
;
6450 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6451 if (plt_sym_val
== NULL
)
6454 for (i
= 0; i
< count
; i
++)
6455 plt_sym_val
[i
] = -1;
6457 plt_offset
= bed
->plt_entry_size
;
6458 p
= relplt
->relocation
;
6459 for (i
= 0; i
< count
; i
++, p
++)
6463 /* Skip unknown relocation. */
6464 if (p
->howto
== NULL
)
6467 if (p
->howto
->type
!= R_X86_64_JUMP_SLOT
6468 && p
->howto
->type
!= R_X86_64_IRELATIVE
)
6471 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6472 + bed
->plt_reloc_offset
));
6473 if (reloc_index
< count
)
6477 /* This is the index in .plt section. */
6478 long plt_index
= plt_offset
/ bed
->plt_entry_size
;
6479 /* Store VMA + the offset in .plt.bnd section. */
6480 plt_sym_val
[reloc_index
] =
6482 + (plt_index
- 1) * sizeof (elf_x86_64_legacy_plt2_entry
));
6485 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6487 plt_offset
+= bed
->plt_entry_size
;
6489 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6491 if (plt_offset
>= plt
->size
)
6495 free (plt_contents
);
6500 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6504 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6511 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6512 as PLT if it exists. */
6513 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6515 plt
= bfd_get_section_by_name (abfd
, ".plt");
6516 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6517 dynsymcount
, dynsyms
, ret
,
6519 elf_x86_64_get_plt_sym_val
);
6522 /* Handle an x86-64 specific section when reading an object file. This
6523 is called when elfcode.h finds a section with an unknown type. */
6526 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6527 const char *name
, int shindex
)
6529 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6532 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6538 /* Hook called by the linker routine which adds symbols from an object
6539 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6543 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6544 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6545 Elf_Internal_Sym
*sym
,
6546 const char **namep ATTRIBUTE_UNUSED
,
6547 flagword
*flagsp ATTRIBUTE_UNUSED
,
6553 switch (sym
->st_shndx
)
6555 case SHN_X86_64_LCOMMON
:
6556 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6559 lcomm
= bfd_make_section_with_flags (abfd
,
6563 | SEC_LINKER_CREATED
));
6566 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6569 *valp
= sym
->st_size
;
6577 /* Given a BFD section, try to locate the corresponding ELF section
6581 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6582 asection
*sec
, int *index_return
)
6584 if (sec
== &_bfd_elf_large_com_section
)
6586 *index_return
= SHN_X86_64_LCOMMON
;
6592 /* Process a symbol. */
6595 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6598 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6600 switch (elfsym
->internal_elf_sym
.st_shndx
)
6602 case SHN_X86_64_LCOMMON
:
6603 asym
->section
= &_bfd_elf_large_com_section
;
6604 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6605 /* Common symbol doesn't set BSF_GLOBAL. */
6606 asym
->flags
&= ~BSF_GLOBAL
;
6612 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6614 return (sym
->st_shndx
== SHN_COMMON
6615 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6619 elf_x86_64_common_section_index (asection
*sec
)
6621 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6624 return SHN_X86_64_LCOMMON
;
6628 elf_x86_64_common_section (asection
*sec
)
6630 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6631 return bfd_com_section_ptr
;
6633 return &_bfd_elf_large_com_section
;
6637 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6638 const Elf_Internal_Sym
*sym
,
6643 const asection
*oldsec
)
6645 /* A normal common symbol and a large common symbol result in a
6646 normal common symbol. We turn the large common symbol into a
6649 && h
->root
.type
== bfd_link_hash_common
6651 && bfd_is_com_section (*psec
)
6654 if (sym
->st_shndx
== SHN_COMMON
6655 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6657 h
->root
.u
.c
.p
->section
6658 = bfd_make_section_old_way (oldbfd
, "COMMON");
6659 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6661 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6662 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6663 *psec
= bfd_com_section_ptr
;
6670 elf_x86_64_additional_program_headers (bfd
*abfd
,
6671 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6676 /* Check to see if we need a large readonly segment. */
6677 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6678 if (s
&& (s
->flags
& SEC_LOAD
))
6681 /* Check to see if we need a large data segment. Since .lbss sections
6682 is placed right after the .bss section, there should be no need for
6683 a large data segment just because of .lbss. */
6684 s
= bfd_get_section_by_name (abfd
, ".ldata");
6685 if (s
&& (s
->flags
& SEC_LOAD
))
6691 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6694 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6696 if (h
->plt
.offset
!= (bfd_vma
) -1
6698 && !h
->pointer_equality_needed
)
6701 return _bfd_elf_hash_symbol (h
);
6704 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6707 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6708 const bfd_target
*output
)
6710 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6711 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6712 && _bfd_elf_relocs_compatible (input
, output
));
6715 static const struct bfd_elf_special_section
6716 elf_x86_64_special_sections
[]=
6718 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6719 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6720 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
6721 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6722 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6723 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6724 { NULL
, 0, 0, 0, 0 }
6727 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6728 #define TARGET_LITTLE_NAME "elf64-x86-64"
6729 #define ELF_ARCH bfd_arch_i386
6730 #define ELF_TARGET_ID X86_64_ELF_DATA
6731 #define ELF_MACHINE_CODE EM_X86_64
6732 #define ELF_MAXPAGESIZE 0x200000
6733 #define ELF_MINPAGESIZE 0x1000
6734 #define ELF_COMMONPAGESIZE 0x1000
6736 #define elf_backend_can_gc_sections 1
6737 #define elf_backend_can_refcount 1
6738 #define elf_backend_want_got_plt 1
6739 #define elf_backend_plt_readonly 1
6740 #define elf_backend_want_plt_sym 0
6741 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6742 #define elf_backend_rela_normal 1
6743 #define elf_backend_plt_alignment 4
6744 #define elf_backend_extern_protected_data 1
6745 #define elf_backend_caches_rawsize 1
6746 #define elf_backend_dtrel_excludes_plt 1
6748 #define elf_info_to_howto elf_x86_64_info_to_howto
6750 #define bfd_elf64_bfd_link_hash_table_create \
6751 elf_x86_64_link_hash_table_create
6752 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
6753 #define bfd_elf64_bfd_reloc_name_lookup \
6754 elf_x86_64_reloc_name_lookup
6756 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
6757 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
6758 #define elf_backend_check_relocs elf_x86_64_check_relocs
6759 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
6760 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
6761 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
6762 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
6763 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
6764 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
6765 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
6766 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
6768 #define elf_backend_write_core_note elf_x86_64_write_core_note
6770 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
6771 #define elf_backend_relocate_section elf_x86_64_relocate_section
6772 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
6773 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
6774 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
6775 #define elf_backend_object_p elf64_x86_64_elf_object_p
6776 #define bfd_elf64_mkobject elf_x86_64_mkobject
6777 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
6779 #define elf_backend_section_from_shdr \
6780 elf_x86_64_section_from_shdr
6782 #define elf_backend_section_from_bfd_section \
6783 elf_x86_64_elf_section_from_bfd_section
6784 #define elf_backend_add_symbol_hook \
6785 elf_x86_64_add_symbol_hook
6786 #define elf_backend_symbol_processing \
6787 elf_x86_64_symbol_processing
6788 #define elf_backend_common_section_index \
6789 elf_x86_64_common_section_index
6790 #define elf_backend_common_section \
6791 elf_x86_64_common_section
6792 #define elf_backend_common_definition \
6793 elf_x86_64_common_definition
6794 #define elf_backend_merge_symbol \
6795 elf_x86_64_merge_symbol
6796 #define elf_backend_special_sections \
6797 elf_x86_64_special_sections
6798 #define elf_backend_additional_program_headers \
6799 elf_x86_64_additional_program_headers
6800 #define elf_backend_hash_symbol \
6801 elf_x86_64_hash_symbol
6802 #define elf_backend_omit_section_dynsym \
6803 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
6804 #define elf_backend_fixup_symbol \
6805 elf_x86_64_fixup_symbol
6807 #include "elf64-target.h"
6809 /* CloudABI support. */
6811 #undef TARGET_LITTLE_SYM
6812 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
6813 #undef TARGET_LITTLE_NAME
6814 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
6817 #define ELF_OSABI ELFOSABI_CLOUDABI
6820 #define elf64_bed elf64_x86_64_cloudabi_bed
6822 #include "elf64-target.h"
6824 /* FreeBSD support. */
6826 #undef TARGET_LITTLE_SYM
6827 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
6828 #undef TARGET_LITTLE_NAME
6829 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
6832 #define ELF_OSABI ELFOSABI_FREEBSD
6835 #define elf64_bed elf64_x86_64_fbsd_bed
6837 #include "elf64-target.h"
6839 /* Solaris 2 support. */
6841 #undef TARGET_LITTLE_SYM
6842 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
6843 #undef TARGET_LITTLE_NAME
6844 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
6846 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6847 objects won't be recognized. */
6851 #define elf64_bed elf64_x86_64_sol2_bed
6853 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
6855 #undef elf_backend_static_tls_alignment
6856 #define elf_backend_static_tls_alignment 16
6858 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6860 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6862 #undef elf_backend_want_plt_sym
6863 #define elf_backend_want_plt_sym 1
6865 #undef elf_backend_strtab_flags
6866 #define elf_backend_strtab_flags SHF_STRINGS
6869 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6870 bfd
*obfd ATTRIBUTE_UNUSED
,
6871 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6872 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6874 /* PR 19938: FIXME: Need to add code for setting the sh_info
6875 and sh_link fields of Solaris specific section types. */
6879 #undef elf_backend_copy_special_section_fields
6880 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
6882 #include "elf64-target.h"
6884 /* Native Client support. */
6887 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
6889 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
6890 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
6894 #undef TARGET_LITTLE_SYM
6895 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
6896 #undef TARGET_LITTLE_NAME
6897 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
6899 #define elf64_bed elf64_x86_64_nacl_bed
6901 #undef ELF_MAXPAGESIZE
6902 #undef ELF_MINPAGESIZE
6903 #undef ELF_COMMONPAGESIZE
6904 #define ELF_MAXPAGESIZE 0x10000
6905 #define ELF_MINPAGESIZE 0x10000
6906 #define ELF_COMMONPAGESIZE 0x10000
6908 /* Restore defaults. */
6910 #undef elf_backend_static_tls_alignment
6911 #undef elf_backend_want_plt_sym
6912 #define elf_backend_want_plt_sym 0
6913 #undef elf_backend_strtab_flags
6914 #undef elf_backend_copy_special_section_fields
6916 /* NaCl uses substantially different PLT entries for the same effects. */
6918 #undef elf_backend_plt_alignment
6919 #define elf_backend_plt_alignment 5
6920 #define NACL_PLT_ENTRY_SIZE 64
6921 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6923 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
6925 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
6926 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
6927 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6928 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6929 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6931 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
6932 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
6934 /* 32 bytes of nop to pad out to the standard size. */
6935 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6936 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6937 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6938 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6939 0x66, /* excess data16 prefix */
6943 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6945 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
6946 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6947 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6948 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6950 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
6951 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6952 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6954 /* Lazy GOT entries point here (32-byte aligned). */
6955 0x68, /* pushq immediate */
6956 0, 0, 0, 0, /* replaced with index into relocation table. */
6957 0xe9, /* jmp relative */
6958 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
6960 /* 22 bytes of nop to pad out to the standard size. */
6961 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6962 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6963 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
6966 /* .eh_frame covering the .plt section. */
6968 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
6970 #if (PLT_CIE_LENGTH != 20 \
6971 || PLT_FDE_LENGTH != 36 \
6972 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6973 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6974 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
6976 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6977 0, 0, 0, 0, /* CIE ID */
6978 1, /* CIE version */
6979 'z', 'R', 0, /* Augmentation string */
6980 1, /* Code alignment factor */
6981 0x78, /* Data alignment factor */
6982 16, /* Return address column */
6983 1, /* Augmentation size */
6984 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6985 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
6986 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
6987 DW_CFA_nop
, DW_CFA_nop
,
6989 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6990 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
6991 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
6992 0, 0, 0, 0, /* .plt size goes here */
6993 0, /* Augmentation size */
6994 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
6995 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6996 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
6997 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6998 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6999 13, /* Block length */
7000 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7001 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7002 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7003 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7004 DW_CFA_nop
, DW_CFA_nop
7007 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7009 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7010 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7011 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7012 2, /* plt0_got1_offset */
7013 9, /* plt0_got2_offset */
7014 13, /* plt0_got2_insn_end */
7015 3, /* plt_got_offset */
7016 33, /* plt_reloc_offset */
7017 38, /* plt_plt_offset */
7018 7, /* plt_got_insn_size */
7019 42, /* plt_plt_insn_end */
7020 32, /* plt_lazy_offset */
7021 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7022 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
7025 #undef elf_backend_arch_data
7026 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7028 #undef elf_backend_object_p
7029 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7030 #undef elf_backend_modify_segment_map
7031 #define elf_backend_modify_segment_map nacl_modify_segment_map
7032 #undef elf_backend_modify_program_headers
7033 #define elf_backend_modify_program_headers nacl_modify_program_headers
7034 #undef elf_backend_final_write_processing
7035 #define elf_backend_final_write_processing nacl_final_write_processing
7037 #include "elf64-target.h"
7039 /* Native Client x32 support. */
7042 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7044 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7045 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7049 #undef TARGET_LITTLE_SYM
7050 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7051 #undef TARGET_LITTLE_NAME
7052 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7054 #define elf32_bed elf32_x86_64_nacl_bed
7056 #define bfd_elf32_bfd_link_hash_table_create \
7057 elf_x86_64_link_hash_table_create
7058 #define bfd_elf32_bfd_reloc_type_lookup \
7059 elf_x86_64_reloc_type_lookup
7060 #define bfd_elf32_bfd_reloc_name_lookup \
7061 elf_x86_64_reloc_name_lookup
7062 #define bfd_elf32_mkobject \
7064 #define bfd_elf32_get_synthetic_symtab \
7065 elf_x86_64_get_synthetic_symtab
7067 #undef elf_backend_object_p
7068 #define elf_backend_object_p \
7069 elf32_x86_64_nacl_elf_object_p
7071 #undef elf_backend_bfd_from_remote_memory
7072 #define elf_backend_bfd_from_remote_memory \
7073 _bfd_elf32_bfd_from_remote_memory
7075 #undef elf_backend_size_info
7076 #define elf_backend_size_info \
7077 _bfd_elf32_size_info
7079 #include "elf32-target.h"
7081 /* Restore defaults. */
7082 #undef elf_backend_object_p
7083 #define elf_backend_object_p elf64_x86_64_elf_object_p
7084 #undef elf_backend_bfd_from_remote_memory
7085 #undef elf_backend_size_info
7086 #undef elf_backend_modify_segment_map
7087 #undef elf_backend_modify_program_headers
7088 #undef elf_backend_final_write_processing
7090 /* Intel L1OM support. */
7093 elf64_l1om_elf_object_p (bfd
*abfd
)
7095 /* Set the right machine number for an L1OM elf64 file. */
7096 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7100 #undef TARGET_LITTLE_SYM
7101 #define TARGET_LITTLE_SYM l1om_elf64_vec
7102 #undef TARGET_LITTLE_NAME
7103 #define TARGET_LITTLE_NAME "elf64-l1om"
7105 #define ELF_ARCH bfd_arch_l1om
7107 #undef ELF_MACHINE_CODE
7108 #define ELF_MACHINE_CODE EM_L1OM
7113 #define elf64_bed elf64_l1om_bed
7115 #undef elf_backend_object_p
7116 #define elf_backend_object_p elf64_l1om_elf_object_p
7118 /* Restore defaults. */
7119 #undef ELF_MAXPAGESIZE
7120 #undef ELF_MINPAGESIZE
7121 #undef ELF_COMMONPAGESIZE
7122 #define ELF_MAXPAGESIZE 0x200000
7123 #define ELF_MINPAGESIZE 0x1000
7124 #define ELF_COMMONPAGESIZE 0x1000
7125 #undef elf_backend_plt_alignment
7126 #define elf_backend_plt_alignment 4
7127 #undef elf_backend_arch_data
7128 #define elf_backend_arch_data &elf_x86_64_arch_bed
7130 #include "elf64-target.h"
7132 /* FreeBSD L1OM support. */
7134 #undef TARGET_LITTLE_SYM
7135 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7136 #undef TARGET_LITTLE_NAME
7137 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7140 #define ELF_OSABI ELFOSABI_FREEBSD
7143 #define elf64_bed elf64_l1om_fbsd_bed
7145 #include "elf64-target.h"
7147 /* Intel K1OM support. */
7150 elf64_k1om_elf_object_p (bfd
*abfd
)
7152 /* Set the right machine number for an K1OM elf64 file. */
7153 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7157 #undef TARGET_LITTLE_SYM
7158 #define TARGET_LITTLE_SYM k1om_elf64_vec
7159 #undef TARGET_LITTLE_NAME
7160 #define TARGET_LITTLE_NAME "elf64-k1om"
7162 #define ELF_ARCH bfd_arch_k1om
7164 #undef ELF_MACHINE_CODE
7165 #define ELF_MACHINE_CODE EM_K1OM
7170 #define elf64_bed elf64_k1om_bed
7172 #undef elf_backend_object_p
7173 #define elf_backend_object_p elf64_k1om_elf_object_p
7175 #undef elf_backend_static_tls_alignment
7177 #undef elf_backend_want_plt_sym
7178 #define elf_backend_want_plt_sym 0
7180 #include "elf64-target.h"
7182 /* FreeBSD K1OM support. */
7184 #undef TARGET_LITTLE_SYM
7185 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7186 #undef TARGET_LITTLE_NAME
7187 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7190 #define ELF_OSABI ELFOSABI_FREEBSD
7193 #define elf64_bed elf64_k1om_fbsd_bed
7195 #include "elf64-target.h"
7197 /* 32bit x86-64 support. */
7199 #undef TARGET_LITTLE_SYM
7200 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7201 #undef TARGET_LITTLE_NAME
7202 #define TARGET_LITTLE_NAME "elf32-x86-64"
7206 #define ELF_ARCH bfd_arch_i386
7208 #undef ELF_MACHINE_CODE
7209 #define ELF_MACHINE_CODE EM_X86_64
7213 #undef elf_backend_object_p
7214 #define elf_backend_object_p \
7215 elf32_x86_64_elf_object_p
7217 #undef elf_backend_bfd_from_remote_memory
7218 #define elf_backend_bfd_from_remote_memory \
7219 _bfd_elf32_bfd_from_remote_memory
7221 #undef elf_backend_size_info
7222 #define elf_backend_size_info \
7223 _bfd_elf32_size_info
7225 #include "elf32-target.h"