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 && htab
->elf
.splt
!= NULL
)
4699 if (htab
->plt_bnd
!= NULL
)
4701 resolved_plt
= htab
->plt_bnd
;
4702 plt_offset
= eh
->plt_bnd
.offset
;
4706 resolved_plt
= htab
->elf
.splt
;
4707 plt_offset
= h
->plt
.offset
;
4710 relocation
= (resolved_plt
->output_section
->vma
4711 + resolved_plt
->output_offset
4713 unresolved_reloc
= FALSE
;
4716 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4717 + htab
->elf
.sgotplt
->output_offset
;
4720 case R_X86_64_PLT32
:
4721 case R_X86_64_PLT32_BND
:
4722 /* Relocation is to the entry for this symbol in the
4723 procedure linkage table. */
4725 /* Resolve a PLT32 reloc against a local symbol directly,
4726 without using the procedure linkage table. */
4730 if ((h
->plt
.offset
== (bfd_vma
) -1
4731 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4732 || htab
->elf
.splt
== NULL
)
4734 /* We didn't make a PLT entry for this symbol. This
4735 happens when statically linking PIC code, or when
4736 using -Bsymbolic. */
4740 if (h
->plt
.offset
!= (bfd_vma
) -1)
4742 if (htab
->plt_bnd
!= NULL
)
4744 resolved_plt
= htab
->plt_bnd
;
4745 plt_offset
= eh
->plt_bnd
.offset
;
4749 resolved_plt
= htab
->elf
.splt
;
4750 plt_offset
= h
->plt
.offset
;
4755 /* Use the GOT PLT. */
4756 resolved_plt
= htab
->plt_got
;
4757 plt_offset
= eh
->plt_got
.offset
;
4760 relocation
= (resolved_plt
->output_section
->vma
4761 + resolved_plt
->output_offset
4763 unresolved_reloc
= FALSE
;
4766 case R_X86_64_SIZE32
:
4767 case R_X86_64_SIZE64
:
4768 /* Set to symbol size. */
4769 relocation
= st_size
;
4775 case R_X86_64_PC32_BND
:
4776 /* Don't complain about -fPIC if the symbol is undefined when
4777 building executable unless it is unresolved weak symbol. */
4778 if ((input_section
->flags
& SEC_ALLOC
) != 0
4779 && (input_section
->flags
& SEC_READONLY
) != 0
4781 && ((bfd_link_executable (info
)
4782 && h
->root
.type
== bfd_link_hash_undefweak
4783 && !resolved_to_zero
)
4784 || (bfd_link_pic (info
)
4785 && !(bfd_link_pie (info
)
4786 && h
->root
.type
== bfd_link_hash_undefined
))))
4788 bfd_boolean fail
= FALSE
;
4790 = ((r_type
== R_X86_64_PC32
4791 || r_type
== R_X86_64_PC32_BND
)
4792 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4794 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4796 /* Symbol is referenced locally. Make sure it is
4797 defined locally or for a branch. */
4798 fail
= !h
->def_regular
&& !branch
;
4800 else if (!(bfd_link_pie (info
)
4801 && (h
->needs_copy
|| eh
->needs_copy
)))
4803 /* Symbol doesn't need copy reloc and isn't referenced
4804 locally. We only allow branch to symbol with
4805 non-default visibility. */
4807 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4811 return elf_x86_64_need_pic (input_bfd
, input_section
,
4812 h
, NULL
, NULL
, howto
);
4821 /* FIXME: The ABI says the linker should make sure the value is
4822 the same when it's zeroextended to 64 bit. */
4825 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4828 /* Don't copy a pc-relative relocation into the output file
4829 if the symbol needs copy reloc or the symbol is undefined
4830 when building executable. Copy dynamic function pointer
4831 relocations. Don't generate dynamic relocations against
4832 resolved undefined weak symbols in PIE. */
4833 if ((bfd_link_pic (info
)
4834 && !(bfd_link_pie (info
)
4838 || h
->root
.type
== bfd_link_hash_undefined
)
4839 && (IS_X86_64_PCREL_TYPE (r_type
)
4840 || r_type
== R_X86_64_SIZE32
4841 || r_type
== R_X86_64_SIZE64
))
4843 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4844 && !resolved_to_zero
)
4845 || h
->root
.type
!= bfd_link_hash_undefweak
))
4846 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4847 && r_type
!= R_X86_64_SIZE32
4848 && r_type
!= R_X86_64_SIZE64
)
4849 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4850 || (ELIMINATE_COPY_RELOCS
4851 && !bfd_link_pic (info
)
4855 || eh
->func_pointer_refcount
> 0
4856 || (h
->root
.type
== bfd_link_hash_undefweak
4857 && !resolved_to_zero
))
4858 && ((h
->def_dynamic
&& !h
->def_regular
)
4859 /* Undefined weak symbol is bound locally when
4861 || h
->root
.type
== bfd_link_hash_undefined
)))
4863 Elf_Internal_Rela outrel
;
4864 bfd_boolean skip
, relocate
;
4867 /* When generating a shared object, these relocations
4868 are copied into the output file to be resolved at run
4874 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4876 if (outrel
.r_offset
== (bfd_vma
) -1)
4878 else if (outrel
.r_offset
== (bfd_vma
) -2)
4879 skip
= TRUE
, relocate
= TRUE
;
4881 outrel
.r_offset
+= (input_section
->output_section
->vma
4882 + input_section
->output_offset
);
4885 memset (&outrel
, 0, sizeof outrel
);
4887 /* h->dynindx may be -1 if this symbol was marked to
4891 && (IS_X86_64_PCREL_TYPE (r_type
)
4892 || !(bfd_link_executable (info
)
4893 || SYMBOLIC_BIND (info
, h
))
4894 || ! h
->def_regular
))
4896 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4897 outrel
.r_addend
= rel
->r_addend
;
4901 /* This symbol is local, or marked to become local.
4902 When relocation overflow check is disabled, we
4903 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4904 if (r_type
== htab
->pointer_r_type
4905 || (r_type
== R_X86_64_32
4906 && info
->no_reloc_overflow_check
))
4909 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4910 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4912 else if (r_type
== R_X86_64_64
4913 && !ABI_64_P (output_bfd
))
4916 outrel
.r_info
= htab
->r_info (0,
4917 R_X86_64_RELATIVE64
);
4918 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4919 /* Check addend overflow. */
4920 if ((outrel
.r_addend
& 0x80000000)
4921 != (rel
->r_addend
& 0x80000000))
4924 int addend
= rel
->r_addend
;
4925 if (h
&& h
->root
.root
.string
)
4926 name
= h
->root
.root
.string
;
4928 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4932 /* xgettext:c-format */
4933 (_("%B: addend -0x%x in relocation %s against "
4934 "symbol `%s' at 0x%lx in section `%A' is "
4936 input_bfd
, input_section
, addend
,
4938 (unsigned long) rel
->r_offset
);
4941 /* xgettext:c-format */
4942 (_("%B: addend 0x%x in relocation %s against "
4943 "symbol `%s' at 0x%lx in section `%A' is "
4945 input_bfd
, input_section
, addend
,
4947 (unsigned long) rel
->r_offset
);
4948 bfd_set_error (bfd_error_bad_value
);
4956 if (bfd_is_abs_section (sec
))
4958 else if (sec
== NULL
|| sec
->owner
== NULL
)
4960 bfd_set_error (bfd_error_bad_value
);
4967 /* We are turning this relocation into one
4968 against a section symbol. It would be
4969 proper to subtract the symbol's value,
4970 osec->vma, from the emitted reloc addend,
4971 but ld.so expects buggy relocs. */
4972 osec
= sec
->output_section
;
4973 sindx
= elf_section_data (osec
)->dynindx
;
4976 asection
*oi
= htab
->elf
.text_index_section
;
4977 sindx
= elf_section_data (oi
)->dynindx
;
4979 BFD_ASSERT (sindx
!= 0);
4982 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
4983 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4987 sreloc
= elf_section_data (input_section
)->sreloc
;
4989 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4991 r
= bfd_reloc_notsupported
;
4992 goto check_relocation_error
;
4995 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4997 /* If this reloc is against an external symbol, we do
4998 not want to fiddle with the addend. Otherwise, we
4999 need to include the symbol value so that it becomes
5000 an addend for the dynamic reloc. */
5007 case R_X86_64_TLSGD
:
5008 case R_X86_64_GOTPC32_TLSDESC
:
5009 case R_X86_64_TLSDESC_CALL
:
5010 case R_X86_64_GOTTPOFF
:
5011 tls_type
= GOT_UNKNOWN
;
5012 if (h
== NULL
&& local_got_offsets
)
5013 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5015 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5017 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5018 input_section
, contents
,
5019 symtab_hdr
, sym_hashes
,
5020 &r_type
, tls_type
, rel
,
5021 relend
, h
, r_symndx
, TRUE
))
5024 if (r_type
== R_X86_64_TPOFF32
)
5026 bfd_vma roff
= rel
->r_offset
;
5028 BFD_ASSERT (! unresolved_reloc
);
5030 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5032 /* GD->LE transition. For 64bit, change
5033 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5034 .word 0x6666; rex64; call __tls_get_addr@PLT
5036 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5038 call *__tls_get_addr@GOTPCREL(%rip)
5039 which may be converted to
5040 addr32 call __tls_get_addr
5043 leaq foo@tpoff(%rax), %rax
5045 leaq foo@tlsgd(%rip), %rdi
5046 .word 0x6666; rex64; call __tls_get_addr@PLT
5048 leaq foo@tlsgd(%rip), %rdi
5050 call *__tls_get_addr@GOTPCREL(%rip)
5051 which may be converted to
5052 addr32 call __tls_get_addr
5055 leaq foo@tpoff(%rax), %rax
5056 For largepic, change:
5057 leaq foo@tlsgd(%rip), %rdi
5058 movabsq $__tls_get_addr@pltoff, %rax
5063 leaq foo@tpoff(%rax), %rax
5064 nopw 0x0(%rax,%rax,1) */
5066 if (ABI_64_P (output_bfd
))
5068 if (contents
[roff
+ 5] == 0xb8)
5070 memcpy (contents
+ roff
- 3,
5071 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5072 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5076 memcpy (contents
+ roff
- 4,
5077 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5081 memcpy (contents
+ roff
- 3,
5082 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5084 bfd_put_32 (output_bfd
,
5085 elf_x86_64_tpoff (info
, relocation
),
5086 contents
+ roff
+ 8 + largepic
);
5087 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5088 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5093 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5095 /* GDesc -> LE transition.
5096 It's originally something like:
5097 leaq x@tlsdesc(%rip), %rax
5100 movl $x@tpoff, %rax. */
5102 unsigned int val
, type
;
5104 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5105 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5106 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5107 contents
+ roff
- 3);
5108 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5109 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5110 contents
+ roff
- 1);
5111 bfd_put_32 (output_bfd
,
5112 elf_x86_64_tpoff (info
, relocation
),
5116 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5118 /* GDesc -> LE transition.
5123 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5124 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5127 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5129 /* IE->LE transition:
5130 For 64bit, originally it can be one of:
5131 movq foo@gottpoff(%rip), %reg
5132 addq foo@gottpoff(%rip), %reg
5135 leaq foo(%reg), %reg
5137 For 32bit, originally it can be one of:
5138 movq foo@gottpoff(%rip), %reg
5139 addl foo@gottpoff(%rip), %reg
5142 leal foo(%reg), %reg
5145 unsigned int val
, type
, reg
;
5148 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5151 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5152 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5158 bfd_put_8 (output_bfd
, 0x49,
5159 contents
+ roff
- 3);
5160 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5161 bfd_put_8 (output_bfd
, 0x41,
5162 contents
+ roff
- 3);
5163 bfd_put_8 (output_bfd
, 0xc7,
5164 contents
+ roff
- 2);
5165 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5166 contents
+ roff
- 1);
5170 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5173 bfd_put_8 (output_bfd
, 0x49,
5174 contents
+ roff
- 3);
5175 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5176 bfd_put_8 (output_bfd
, 0x41,
5177 contents
+ roff
- 3);
5178 bfd_put_8 (output_bfd
, 0x81,
5179 contents
+ roff
- 2);
5180 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5181 contents
+ roff
- 1);
5185 /* addq/addl -> leaq/leal */
5187 bfd_put_8 (output_bfd
, 0x4d,
5188 contents
+ roff
- 3);
5189 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5190 bfd_put_8 (output_bfd
, 0x45,
5191 contents
+ roff
- 3);
5192 bfd_put_8 (output_bfd
, 0x8d,
5193 contents
+ roff
- 2);
5194 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5195 contents
+ roff
- 1);
5197 bfd_put_32 (output_bfd
,
5198 elf_x86_64_tpoff (info
, relocation
),
5206 if (htab
->elf
.sgot
== NULL
)
5211 off
= h
->got
.offset
;
5212 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5216 if (local_got_offsets
== NULL
)
5219 off
= local_got_offsets
[r_symndx
];
5220 offplt
= local_tlsdesc_gotents
[r_symndx
];
5227 Elf_Internal_Rela outrel
;
5231 if (htab
->elf
.srelgot
== NULL
)
5234 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5236 if (GOT_TLS_GDESC_P (tls_type
))
5238 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5239 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5240 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5241 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5242 + htab
->elf
.sgotplt
->output_offset
5244 + htab
->sgotplt_jump_table_size
);
5245 sreloc
= htab
->elf
.srelplt
;
5247 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5249 outrel
.r_addend
= 0;
5250 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5253 sreloc
= htab
->elf
.srelgot
;
5255 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5256 + htab
->elf
.sgot
->output_offset
+ off
);
5258 if (GOT_TLS_GD_P (tls_type
))
5259 dr_type
= R_X86_64_DTPMOD64
;
5260 else if (GOT_TLS_GDESC_P (tls_type
))
5263 dr_type
= R_X86_64_TPOFF64
;
5265 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5266 outrel
.r_addend
= 0;
5267 if ((dr_type
== R_X86_64_TPOFF64
5268 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5269 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5270 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5272 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5274 if (GOT_TLS_GD_P (tls_type
))
5278 BFD_ASSERT (! unresolved_reloc
);
5279 bfd_put_64 (output_bfd
,
5280 relocation
- elf_x86_64_dtpoff_base (info
),
5281 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5285 bfd_put_64 (output_bfd
, 0,
5286 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5287 outrel
.r_info
= htab
->r_info (indx
,
5289 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5290 elf_append_rela (output_bfd
, sreloc
,
5299 local_got_offsets
[r_symndx
] |= 1;
5302 if (off
>= (bfd_vma
) -2
5303 && ! GOT_TLS_GDESC_P (tls_type
))
5305 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5307 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5308 || r_type
== R_X86_64_TLSDESC_CALL
)
5309 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5310 + htab
->elf
.sgotplt
->output_offset
5311 + offplt
+ htab
->sgotplt_jump_table_size
;
5313 relocation
= htab
->elf
.sgot
->output_section
->vma
5314 + htab
->elf
.sgot
->output_offset
+ off
;
5315 unresolved_reloc
= FALSE
;
5319 bfd_vma roff
= rel
->r_offset
;
5321 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5323 /* GD->IE transition. For 64bit, change
5324 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5325 .word 0x6666; rex64; call __tls_get_addr@PLT
5327 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5329 call *__tls_get_addr@GOTPCREL(%rip
5330 which may be converted to
5331 addr32 call __tls_get_addr
5334 addq foo@gottpoff(%rip), %rax
5336 leaq foo@tlsgd(%rip), %rdi
5337 .word 0x6666; rex64; call __tls_get_addr@PLT
5339 leaq foo@tlsgd(%rip), %rdi
5341 call *__tls_get_addr@GOTPCREL(%rip)
5342 which may be converted to
5343 addr32 call __tls_get_addr
5346 addq foo@gottpoff(%rip), %rax
5347 For largepic, change:
5348 leaq foo@tlsgd(%rip), %rdi
5349 movabsq $__tls_get_addr@pltoff, %rax
5354 addq foo@gottpoff(%rax), %rax
5355 nopw 0x0(%rax,%rax,1) */
5357 if (ABI_64_P (output_bfd
))
5359 if (contents
[roff
+ 5] == 0xb8)
5361 memcpy (contents
+ roff
- 3,
5362 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5363 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5367 memcpy (contents
+ roff
- 4,
5368 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5372 memcpy (contents
+ roff
- 3,
5373 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5376 relocation
= (htab
->elf
.sgot
->output_section
->vma
5377 + htab
->elf
.sgot
->output_offset
+ off
5380 - input_section
->output_section
->vma
5381 - input_section
->output_offset
5383 bfd_put_32 (output_bfd
, relocation
,
5384 contents
+ roff
+ 8 + largepic
);
5385 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5390 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5392 /* GDesc -> IE transition.
5393 It's originally something like:
5394 leaq x@tlsdesc(%rip), %rax
5397 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5399 /* Now modify the instruction as appropriate. To
5400 turn a leaq into a movq in the form we use it, it
5401 suffices to change the second byte from 0x8d to
5403 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5405 bfd_put_32 (output_bfd
,
5406 htab
->elf
.sgot
->output_section
->vma
5407 + htab
->elf
.sgot
->output_offset
+ off
5409 - input_section
->output_section
->vma
5410 - input_section
->output_offset
5415 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5417 /* GDesc -> IE transition.
5424 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5425 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5433 case R_X86_64_TLSLD
:
5434 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5435 input_section
, contents
,
5436 symtab_hdr
, sym_hashes
,
5437 &r_type
, GOT_UNKNOWN
, rel
,
5438 relend
, h
, r_symndx
, TRUE
))
5441 if (r_type
!= R_X86_64_TLSLD
)
5443 /* LD->LE transition:
5444 leaq foo@tlsld(%rip), %rdi
5445 call __tls_get_addr@PLT
5446 For 64bit, we change it into:
5447 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5448 For 32bit, we change it into:
5449 nopl 0x0(%rax); movl %fs:0, %eax
5451 leaq foo@tlsld(%rip), %rdi;
5452 call *__tls_get_addr@GOTPCREL(%rip)
5453 which may be converted to
5454 addr32 call __tls_get_addr
5455 For 64bit, we change it into:
5456 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5457 For 32bit, we change it into:
5458 nopw 0x0(%rax); movl %fs:0, %eax
5459 For largepic, change:
5460 leaq foo@tlsgd(%rip), %rdi
5461 movabsq $__tls_get_addr@pltoff, %rax
5465 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5468 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5469 if (ABI_64_P (output_bfd
))
5471 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5472 memcpy (contents
+ rel
->r_offset
- 3,
5473 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5474 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5475 else if (contents
[rel
->r_offset
+ 4] == 0xff
5476 || contents
[rel
->r_offset
+ 4] == 0x67)
5477 memcpy (contents
+ rel
->r_offset
- 3,
5478 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5481 memcpy (contents
+ rel
->r_offset
- 3,
5482 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5486 if (contents
[rel
->r_offset
+ 4] == 0xff)
5487 memcpy (contents
+ rel
->r_offset
- 3,
5488 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5491 memcpy (contents
+ rel
->r_offset
- 3,
5492 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5494 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5495 and R_X86_64_PLTOFF64. */
5501 if (htab
->elf
.sgot
== NULL
)
5504 off
= htab
->tls_ld_got
.offset
;
5509 Elf_Internal_Rela outrel
;
5511 if (htab
->elf
.srelgot
== NULL
)
5514 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5515 + htab
->elf
.sgot
->output_offset
+ off
);
5517 bfd_put_64 (output_bfd
, 0,
5518 htab
->elf
.sgot
->contents
+ off
);
5519 bfd_put_64 (output_bfd
, 0,
5520 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5521 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5522 outrel
.r_addend
= 0;
5523 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5525 htab
->tls_ld_got
.offset
|= 1;
5527 relocation
= htab
->elf
.sgot
->output_section
->vma
5528 + htab
->elf
.sgot
->output_offset
+ off
;
5529 unresolved_reloc
= FALSE
;
5532 case R_X86_64_DTPOFF32
:
5533 if (!bfd_link_executable (info
)
5534 || (input_section
->flags
& SEC_CODE
) == 0)
5535 relocation
-= elf_x86_64_dtpoff_base (info
);
5537 relocation
= elf_x86_64_tpoff (info
, relocation
);
5540 case R_X86_64_TPOFF32
:
5541 case R_X86_64_TPOFF64
:
5542 BFD_ASSERT (bfd_link_executable (info
));
5543 relocation
= elf_x86_64_tpoff (info
, relocation
);
5546 case R_X86_64_DTPOFF64
:
5547 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5548 relocation
-= elf_x86_64_dtpoff_base (info
);
5555 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5556 because such sections are not SEC_ALLOC and thus ld.so will
5557 not process them. */
5558 if (unresolved_reloc
5559 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5561 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5562 rel
->r_offset
) != (bfd_vma
) -1)
5565 /* xgettext:c-format */
5566 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5569 (long) rel
->r_offset
,
5571 h
->root
.root
.string
);
5576 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5577 contents
, rel
->r_offset
,
5578 relocation
, rel
->r_addend
);
5580 check_relocation_error
:
5581 if (r
!= bfd_reloc_ok
)
5586 name
= h
->root
.root
.string
;
5589 name
= bfd_elf_string_from_elf_section (input_bfd
,
5590 symtab_hdr
->sh_link
,
5595 name
= bfd_section_name (input_bfd
, sec
);
5598 if (r
== bfd_reloc_overflow
)
5599 (*info
->callbacks
->reloc_overflow
)
5600 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5601 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5605 /* xgettext:c-format */
5606 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5607 input_bfd
, input_section
,
5608 (long) rel
->r_offset
, name
, (int) r
);
5619 Elf_Internal_Shdr
*rel_hdr
;
5620 size_t deleted
= rel
- wrel
;
5622 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5623 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5624 if (rel_hdr
->sh_size
== 0)
5626 /* It is too late to remove an empty reloc section. Leave
5628 ??? What is wrong with an empty section??? */
5629 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5632 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5633 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5634 input_section
->reloc_count
-= deleted
;
5640 /* Finish up dynamic symbol handling. We set the contents of various
5641 dynamic sections here. */
5644 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5645 struct bfd_link_info
*info
,
5646 struct elf_link_hash_entry
*h
,
5647 Elf_Internal_Sym
*sym
)
5649 struct elf_x86_64_link_hash_table
*htab
;
5650 const struct elf_x86_64_backend_data
*abed
;
5651 bfd_boolean use_plt_bnd
;
5652 struct elf_x86_64_link_hash_entry
*eh
;
5653 bfd_boolean local_undefweak
;
5655 htab
= elf_x86_64_hash_table (info
);
5659 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5660 section only if there is .plt section. */
5661 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5663 ? &elf_x86_64_bnd_arch_bed
5664 : get_elf_x86_64_backend_data (output_bfd
));
5666 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5668 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5669 resolved undefined weak symbols in executable so that their
5670 references have value 0 at run-time. */
5671 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5675 if (h
->plt
.offset
!= (bfd_vma
) -1)
5678 bfd_vma got_offset
, plt_offset
, plt_plt_offset
, plt_got_offset
;
5679 bfd_vma plt_plt_insn_end
, plt_got_insn_size
;
5680 Elf_Internal_Rela rela
;
5682 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5683 const struct elf_backend_data
*bed
;
5684 bfd_vma plt_got_pcrel_offset
;
5686 /* When building a static executable, use .iplt, .igot.plt and
5687 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5688 if (htab
->elf
.splt
!= NULL
)
5690 plt
= htab
->elf
.splt
;
5691 gotplt
= htab
->elf
.sgotplt
;
5692 relplt
= htab
->elf
.srelplt
;
5696 plt
= htab
->elf
.iplt
;
5697 gotplt
= htab
->elf
.igotplt
;
5698 relplt
= htab
->elf
.irelplt
;
5701 /* This symbol has an entry in the procedure linkage table. Set
5703 if ((h
->dynindx
== -1
5705 && !((h
->forced_local
|| bfd_link_executable (info
))
5707 && h
->type
== STT_GNU_IFUNC
))
5713 /* Get the index in the procedure linkage table which
5714 corresponds to this symbol. This is the index of this symbol
5715 in all the symbols for which we are making plt entries. The
5716 first entry in the procedure linkage table is reserved.
5718 Get the offset into the .got table of the entry that
5719 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5720 bytes. The first three are reserved for the dynamic linker.
5722 For static executables, we don't reserve anything. */
5724 if (plt
== htab
->elf
.splt
)
5726 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
5727 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5731 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
5732 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5735 plt_plt_insn_end
= abed
->plt_plt_insn_end
;
5736 plt_plt_offset
= abed
->plt_plt_offset
;
5737 plt_got_insn_size
= abed
->plt_got_insn_size
;
5738 plt_got_offset
= abed
->plt_got_offset
;
5741 /* Use the second PLT with BND relocations. */
5742 const bfd_byte
*plt_entry
, *plt2_entry
;
5744 if (eh
->has_bnd_reloc
)
5746 plt_entry
= elf_x86_64_bnd_plt_entry
;
5747 plt2_entry
= elf_x86_64_bnd_plt2_entry
;
5751 plt_entry
= elf_x86_64_legacy_plt_entry
;
5752 plt2_entry
= elf_x86_64_legacy_plt2_entry
;
5754 /* Subtract 1 since there is no BND prefix. */
5755 plt_plt_insn_end
-= 1;
5756 plt_plt_offset
-= 1;
5757 plt_got_insn_size
-= 1;
5758 plt_got_offset
-= 1;
5761 BFD_ASSERT (sizeof (elf_x86_64_bnd_plt_entry
)
5762 == sizeof (elf_x86_64_legacy_plt_entry
));
5764 /* Fill in the entry in the procedure linkage table. */
5765 memcpy (plt
->contents
+ h
->plt
.offset
,
5766 plt_entry
, sizeof (elf_x86_64_legacy_plt_entry
));
5767 /* Fill in the entry in the second PLT. */
5768 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5769 plt2_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5771 resolved_plt
= htab
->plt_bnd
;
5772 plt_offset
= eh
->plt_bnd
.offset
;
5776 /* Fill in the entry in the procedure linkage table. */
5777 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
5778 abed
->plt_entry_size
);
5781 plt_offset
= h
->plt
.offset
;
5784 /* Insert the relocation positions of the plt section. */
5786 /* Put offset the PC-relative instruction referring to the GOT entry,
5787 subtracting the size of that instruction. */
5788 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5789 + gotplt
->output_offset
5791 - resolved_plt
->output_section
->vma
5792 - resolved_plt
->output_offset
5794 - plt_got_insn_size
);
5796 /* Check PC-relative offset overflow in PLT entry. */
5797 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5798 /* xgettext:c-format */
5799 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5800 output_bfd
, h
->root
.root
.string
);
5802 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5803 resolved_plt
->contents
+ plt_offset
+ plt_got_offset
);
5805 /* Fill in the entry in the global offset table, initially this
5806 points to the second part of the PLT entry. Leave the entry
5807 as zero for undefined weak symbol in PIE. No PLT relocation
5808 against undefined weak symbol in PIE. */
5809 if (!local_undefweak
)
5811 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5812 + plt
->output_offset
5814 + abed
->plt_lazy_offset
),
5815 gotplt
->contents
+ got_offset
);
5817 /* Fill in the entry in the .rela.plt section. */
5818 rela
.r_offset
= (gotplt
->output_section
->vma
5819 + gotplt
->output_offset
5821 if (h
->dynindx
== -1
5822 || ((bfd_link_executable (info
)
5823 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5825 && h
->type
== STT_GNU_IFUNC
))
5827 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5828 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5829 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5830 rela
.r_addend
= (h
->root
.u
.def
.value
5831 + h
->root
.u
.def
.section
->output_section
->vma
5832 + h
->root
.u
.def
.section
->output_offset
);
5833 /* R_X86_64_IRELATIVE comes last. */
5834 plt_index
= htab
->next_irelative_index
--;
5838 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5840 plt_index
= htab
->next_jump_slot_index
++;
5843 /* Don't fill PLT entry for static executables. */
5844 if (plt
== htab
->elf
.splt
)
5846 bfd_vma plt0_offset
= h
->plt
.offset
+ plt_plt_insn_end
;
5848 /* Put relocation index. */
5849 bfd_put_32 (output_bfd
, plt_index
,
5850 (plt
->contents
+ h
->plt
.offset
5851 + abed
->plt_reloc_offset
));
5853 /* Put offset for jmp .PLT0 and check for overflow. We don't
5854 check relocation index for overflow since branch displacement
5855 will overflow first. */
5856 if (plt0_offset
> 0x80000000)
5857 /* xgettext:c-format */
5858 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5859 output_bfd
, h
->root
.root
.string
);
5860 bfd_put_32 (output_bfd
, - plt0_offset
,
5861 plt
->contents
+ h
->plt
.offset
+ plt_plt_offset
);
5864 bed
= get_elf_backend_data (output_bfd
);
5865 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
5866 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
5869 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5871 bfd_vma got_offset
, plt_offset
, plt_got_offset
, plt_got_insn_size
;
5872 asection
*plt
, *got
;
5873 bfd_boolean got_after_plt
;
5874 int32_t got_pcrel_offset
;
5875 const bfd_byte
*got_plt_entry
;
5877 /* Set the entry in the GOT procedure linkage table. */
5878 plt
= htab
->plt_got
;
5879 got
= htab
->elf
.sgot
;
5880 got_offset
= h
->got
.offset
;
5882 if (got_offset
== (bfd_vma
) -1
5883 || h
->type
== STT_GNU_IFUNC
5888 /* Use the second PLT entry template for the GOT PLT since they
5889 are the identical. */
5890 plt_got_insn_size
= elf_x86_64_bnd_arch_bed
.plt_got_insn_size
;
5891 plt_got_offset
= elf_x86_64_bnd_arch_bed
.plt_got_offset
;
5892 if (eh
->has_bnd_reloc
)
5893 got_plt_entry
= elf_x86_64_bnd_plt2_entry
;
5896 got_plt_entry
= elf_x86_64_legacy_plt2_entry
;
5898 /* Subtract 1 since there is no BND prefix. */
5899 plt_got_insn_size
-= 1;
5900 plt_got_offset
-= 1;
5903 /* Fill in the entry in the GOT procedure linkage table. */
5904 plt_offset
= eh
->plt_got
.offset
;
5905 memcpy (plt
->contents
+ plt_offset
,
5906 got_plt_entry
, sizeof (elf_x86_64_legacy_plt2_entry
));
5908 /* Put offset the PC-relative instruction referring to the GOT
5909 entry, subtracting the size of that instruction. */
5910 got_pcrel_offset
= (got
->output_section
->vma
5911 + got
->output_offset
5913 - plt
->output_section
->vma
5914 - plt
->output_offset
5916 - plt_got_insn_size
);
5918 /* Check PC-relative offset overflow in GOT PLT entry. */
5919 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
5920 if ((got_after_plt
&& got_pcrel_offset
< 0)
5921 || (!got_after_plt
&& got_pcrel_offset
> 0))
5922 /* xgettext:c-format */
5923 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5924 output_bfd
, h
->root
.root
.string
);
5926 bfd_put_32 (output_bfd
, got_pcrel_offset
,
5927 plt
->contents
+ plt_offset
+ plt_got_offset
);
5930 if (!local_undefweak
5932 && (h
->plt
.offset
!= (bfd_vma
) -1
5933 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5935 /* Mark the symbol as undefined, rather than as defined in
5936 the .plt section. Leave the value if there were any
5937 relocations where pointer equality matters (this is a clue
5938 for the dynamic linker, to make function pointer
5939 comparisons work between an application and shared
5940 library), otherwise set it to zero. If a function is only
5941 called from a binary, there is no need to slow down
5942 shared libraries because of that. */
5943 sym
->st_shndx
= SHN_UNDEF
;
5944 if (!h
->pointer_equality_needed
)
5948 /* Don't generate dynamic GOT relocation against undefined weak
5949 symbol in executable. */
5950 if (h
->got
.offset
!= (bfd_vma
) -1
5951 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
5952 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
5953 && !local_undefweak
)
5955 Elf_Internal_Rela rela
;
5956 asection
*relgot
= htab
->elf
.srelgot
;
5958 /* This symbol has an entry in the global offset table. Set it
5960 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5963 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5964 + htab
->elf
.sgot
->output_offset
5965 + (h
->got
.offset
&~ (bfd_vma
) 1));
5967 /* If this is a static link, or it is a -Bsymbolic link and the
5968 symbol is defined locally or was forced to be local because
5969 of a version file, we just want to emit a RELATIVE reloc.
5970 The entry in the global offset table will already have been
5971 initialized in the relocate_section function. */
5973 && h
->type
== STT_GNU_IFUNC
)
5975 if (h
->plt
.offset
== (bfd_vma
) -1)
5977 /* STT_GNU_IFUNC is referenced without PLT. */
5978 if (htab
->elf
.splt
== NULL
)
5980 /* use .rel[a].iplt section to store .got relocations
5981 in static executable. */
5982 relgot
= htab
->elf
.irelplt
;
5984 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5986 rela
.r_info
= htab
->r_info (0,
5987 R_X86_64_IRELATIVE
);
5988 rela
.r_addend
= (h
->root
.u
.def
.value
5989 + h
->root
.u
.def
.section
->output_section
->vma
5990 + h
->root
.u
.def
.section
->output_offset
);
5995 else if (bfd_link_pic (info
))
5997 /* Generate R_X86_64_GLOB_DAT. */
6004 if (!h
->pointer_equality_needed
)
6007 /* For non-shared object, we can't use .got.plt, which
6008 contains the real function addres if we need pointer
6009 equality. We load the GOT entry with the PLT entry. */
6010 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6011 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6012 + plt
->output_offset
6014 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6018 else if (bfd_link_pic (info
)
6019 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6021 if (!h
->def_regular
)
6023 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6024 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6025 rela
.r_addend
= (h
->root
.u
.def
.value
6026 + h
->root
.u
.def
.section
->output_section
->vma
6027 + h
->root
.u
.def
.section
->output_offset
);
6031 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6033 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6034 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6035 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6039 elf_append_rela (output_bfd
, relgot
, &rela
);
6044 Elf_Internal_Rela rela
;
6046 /* This symbol needs a copy reloc. Set it up. */
6048 if (h
->dynindx
== -1
6049 || (h
->root
.type
!= bfd_link_hash_defined
6050 && h
->root
.type
!= bfd_link_hash_defweak
)
6051 || htab
->srelbss
== NULL
)
6054 rela
.r_offset
= (h
->root
.u
.def
.value
6055 + h
->root
.u
.def
.section
->output_section
->vma
6056 + h
->root
.u
.def
.section
->output_offset
);
6057 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6059 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
6065 /* Finish up local dynamic symbol handling. We set the contents of
6066 various dynamic sections here. */
6069 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6071 struct elf_link_hash_entry
*h
6072 = (struct elf_link_hash_entry
*) *slot
;
6073 struct bfd_link_info
*info
6074 = (struct bfd_link_info
*) inf
;
6076 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6080 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6081 here since undefined weak symbol may not be dynamic and may not be
6082 called for elf_x86_64_finish_dynamic_symbol. */
6085 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6088 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6089 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6091 if (h
->root
.type
!= bfd_link_hash_undefweak
6092 || h
->dynindx
!= -1)
6095 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6099 /* Used to decide how to sort relocs in an optimal manner for the
6100 dynamic linker, before writing them out. */
6102 static enum elf_reloc_type_class
6103 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6104 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6105 const Elf_Internal_Rela
*rela
)
6107 bfd
*abfd
= info
->output_bfd
;
6108 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6109 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6111 if (htab
->elf
.dynsym
!= NULL
6112 && htab
->elf
.dynsym
->contents
!= NULL
)
6114 /* Check relocation against STT_GNU_IFUNC symbol if there are
6116 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6117 if (r_symndx
!= STN_UNDEF
)
6119 Elf_Internal_Sym sym
;
6120 if (!bed
->s
->swap_symbol_in (abfd
,
6121 (htab
->elf
.dynsym
->contents
6122 + r_symndx
* bed
->s
->sizeof_sym
),
6126 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6127 return reloc_class_ifunc
;
6131 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6133 case R_X86_64_IRELATIVE
:
6134 return reloc_class_ifunc
;
6135 case R_X86_64_RELATIVE
:
6136 case R_X86_64_RELATIVE64
:
6137 return reloc_class_relative
;
6138 case R_X86_64_JUMP_SLOT
:
6139 return reloc_class_plt
;
6141 return reloc_class_copy
;
6143 return reloc_class_normal
;
6147 /* Finish up the dynamic sections. */
6150 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6151 struct bfd_link_info
*info
)
6153 struct elf_x86_64_link_hash_table
*htab
;
6156 const struct elf_x86_64_backend_data
*abed
;
6158 htab
= elf_x86_64_hash_table (info
);
6162 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
6163 section only if there is .plt section. */
6164 abed
= (htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
6165 ? &elf_x86_64_bnd_arch_bed
6166 : get_elf_x86_64_backend_data (output_bfd
));
6168 dynobj
= htab
->elf
.dynobj
;
6169 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6171 if (htab
->elf
.dynamic_sections_created
)
6173 bfd_byte
*dyncon
, *dynconend
;
6174 const struct elf_backend_data
*bed
;
6175 bfd_size_type sizeof_dyn
;
6177 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6180 bed
= get_elf_backend_data (dynobj
);
6181 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6182 dyncon
= sdyn
->contents
;
6183 dynconend
= sdyn
->contents
+ sdyn
->size
;
6184 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6186 Elf_Internal_Dyn dyn
;
6189 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6197 s
= htab
->elf
.sgotplt
;
6198 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6202 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6206 s
= htab
->elf
.srelplt
->output_section
;
6207 dyn
.d_un
.d_val
= s
->size
;
6211 /* The procedure linkage table relocs (DT_JMPREL) should
6212 not be included in the overall relocs (DT_RELA).
6213 Therefore, we override the DT_RELASZ entry here to
6214 make it not include the JMPREL relocs. Since the
6215 linker script arranges for .rela.plt to follow all
6216 other relocation sections, we don't have to worry
6217 about changing the DT_RELA entry. */
6218 if (htab
->elf
.srelplt
!= NULL
)
6220 s
= htab
->elf
.srelplt
->output_section
;
6221 dyn
.d_un
.d_val
-= s
->size
;
6225 case DT_TLSDESC_PLT
:
6227 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6228 + htab
->tlsdesc_plt
;
6231 case DT_TLSDESC_GOT
:
6233 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6234 + htab
->tlsdesc_got
;
6238 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6241 /* Fill in the special first entry in the procedure linkage table. */
6242 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6244 /* Fill in the first entry in the procedure linkage table. */
6245 memcpy (htab
->elf
.splt
->contents
,
6246 abed
->plt0_entry
, abed
->plt_entry_size
);
6247 /* Add offset for pushq GOT+8(%rip), since the instruction
6248 uses 6 bytes subtract this value. */
6249 bfd_put_32 (output_bfd
,
6250 (htab
->elf
.sgotplt
->output_section
->vma
6251 + htab
->elf
.sgotplt
->output_offset
6253 - htab
->elf
.splt
->output_section
->vma
6254 - htab
->elf
.splt
->output_offset
6256 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
6257 /* Add offset for the PC-relative instruction accessing GOT+16,
6258 subtracting the offset to the end of that instruction. */
6259 bfd_put_32 (output_bfd
,
6260 (htab
->elf
.sgotplt
->output_section
->vma
6261 + htab
->elf
.sgotplt
->output_offset
6263 - htab
->elf
.splt
->output_section
->vma
6264 - htab
->elf
.splt
->output_offset
6265 - abed
->plt0_got2_insn_end
),
6266 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
6268 elf_section_data (htab
->elf
.splt
->output_section
)
6269 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
6271 if (htab
->tlsdesc_plt
)
6273 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6274 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6276 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6277 abed
->plt0_entry
, abed
->plt_entry_size
);
6279 /* Add offset for pushq GOT+8(%rip), since the
6280 instruction uses 6 bytes subtract this value. */
6281 bfd_put_32 (output_bfd
,
6282 (htab
->elf
.sgotplt
->output_section
->vma
6283 + htab
->elf
.sgotplt
->output_offset
6285 - htab
->elf
.splt
->output_section
->vma
6286 - htab
->elf
.splt
->output_offset
6289 htab
->elf
.splt
->contents
6290 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
6291 /* Add offset for the PC-relative instruction accessing GOT+TDG,
6292 where TGD stands for htab->tlsdesc_got, subtracting the offset
6293 to the end of that instruction. */
6294 bfd_put_32 (output_bfd
,
6295 (htab
->elf
.sgot
->output_section
->vma
6296 + htab
->elf
.sgot
->output_offset
6298 - htab
->elf
.splt
->output_section
->vma
6299 - htab
->elf
.splt
->output_offset
6301 - abed
->plt0_got2_insn_end
),
6302 htab
->elf
.splt
->contents
6303 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
6308 if (htab
->plt_bnd
!= NULL
)
6309 elf_section_data (htab
->plt_bnd
->output_section
)
6310 ->this_hdr
.sh_entsize
= sizeof (elf_x86_64_bnd_plt2_entry
);
6312 if (htab
->elf
.sgotplt
)
6314 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6317 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6321 /* Fill in the first three entries in the global offset table. */
6322 if (htab
->elf
.sgotplt
->size
> 0)
6324 /* Set the first entry in the global offset table to the address of
6325 the dynamic section. */
6327 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6329 bfd_put_64 (output_bfd
,
6330 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6331 htab
->elf
.sgotplt
->contents
);
6332 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6333 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6334 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6337 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
6341 /* Adjust .eh_frame for .plt section. */
6342 if (htab
->plt_eh_frame
!= NULL
6343 && htab
->plt_eh_frame
->contents
!= NULL
)
6345 if (htab
->elf
.splt
!= NULL
6346 && htab
->elf
.splt
->size
!= 0
6347 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6348 && htab
->elf
.splt
->output_section
!= NULL
6349 && htab
->plt_eh_frame
->output_section
!= NULL
)
6351 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6352 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6353 + htab
->plt_eh_frame
->output_offset
6354 + PLT_FDE_START_OFFSET
;
6355 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6356 htab
->plt_eh_frame
->contents
6357 + PLT_FDE_START_OFFSET
);
6359 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6361 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6363 htab
->plt_eh_frame
->contents
))
6368 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6369 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6372 /* Fill PLT entries for undefined weak symbols in PIE. */
6373 if (bfd_link_pie (info
))
6374 bfd_hash_traverse (&info
->hash
->table
,
6375 elf_x86_64_pie_finish_undefweak_symbol
,
6381 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6382 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6383 It has to be done before elf_link_sort_relocs is called so that
6384 dynamic relocations are properly sorted. */
6387 elf_x86_64_output_arch_local_syms
6388 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6389 struct bfd_link_info
*info
,
6390 void *flaginfo ATTRIBUTE_UNUSED
,
6391 int (*func
) (void *, const char *,
6394 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6396 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6400 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6401 htab_traverse (htab
->loc_hash_table
,
6402 elf_x86_64_finish_local_dynamic_symbol
,
6408 /* Return an array of PLT entry symbol values. */
6411 elf_x86_64_get_plt_sym_val (bfd
*abfd
, asymbol
**dynsyms
, asection
*plt
,
6414 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
6417 bfd_vma
*plt_sym_val
;
6419 bfd_byte
*plt_contents
;
6420 const struct elf_x86_64_backend_data
*bed
;
6421 Elf_Internal_Shdr
*hdr
;
6424 /* Get the .plt section contents. PLT passed down may point to the
6425 .plt.bnd section. Make sure that PLT always points to the .plt
6427 plt_bnd
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6432 plt
= bfd_get_section_by_name (abfd
, ".plt");
6435 bed
= &elf_x86_64_bnd_arch_bed
;
6438 bed
= get_elf_x86_64_backend_data (abfd
);
6440 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6441 if (plt_contents
== NULL
)
6443 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6444 plt_contents
, 0, plt
->size
))
6447 free (plt_contents
);
6451 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
6452 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
6455 hdr
= &elf_section_data (relplt
)->this_hdr
;
6456 count
= relplt
->size
/ hdr
->sh_entsize
;
6458 plt_sym_val
= (bfd_vma
*) bfd_malloc (sizeof (bfd_vma
) * count
);
6459 if (plt_sym_val
== NULL
)
6462 for (i
= 0; i
< count
; i
++)
6463 plt_sym_val
[i
] = -1;
6465 plt_offset
= bed
->plt_entry_size
;
6466 p
= relplt
->relocation
;
6467 for (i
= 0; i
< count
; i
++, p
++)
6471 /* Skip unknown relocation. */
6472 if (p
->howto
== NULL
)
6475 if (p
->howto
->type
!= R_X86_64_JUMP_SLOT
6476 && p
->howto
->type
!= R_X86_64_IRELATIVE
)
6479 reloc_index
= H_GET_32 (abfd
, (plt_contents
+ plt_offset
6480 + bed
->plt_reloc_offset
));
6481 if (reloc_index
< count
)
6485 /* This is the index in .plt section. */
6486 long plt_index
= plt_offset
/ bed
->plt_entry_size
;
6487 /* Store VMA + the offset in .plt.bnd section. */
6488 plt_sym_val
[reloc_index
] =
6490 + (plt_index
- 1) * sizeof (elf_x86_64_legacy_plt2_entry
));
6493 plt_sym_val
[reloc_index
] = plt
->vma
+ plt_offset
;
6495 plt_offset
+= bed
->plt_entry_size
;
6497 /* PR binutils/18437: Skip extra relocations in the .rela.plt
6499 if (plt_offset
>= plt
->size
)
6503 free (plt_contents
);
6508 /* Similar to _bfd_elf_get_synthetic_symtab, with .plt.bnd section
6512 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6519 /* Pass the .plt.bnd section to _bfd_elf_ifunc_get_synthetic_symtab
6520 as PLT if it exists. */
6521 asection
*plt
= bfd_get_section_by_name (abfd
, ".plt.bnd");
6523 plt
= bfd_get_section_by_name (abfd
, ".plt");
6524 return _bfd_elf_ifunc_get_synthetic_symtab (abfd
, symcount
, syms
,
6525 dynsymcount
, dynsyms
, ret
,
6527 elf_x86_64_get_plt_sym_val
);
6530 /* Handle an x86-64 specific section when reading an object file. This
6531 is called when elfcode.h finds a section with an unknown type. */
6534 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6535 const char *name
, int shindex
)
6537 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6540 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6546 /* Hook called by the linker routine which adds symbols from an object
6547 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6551 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6552 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6553 Elf_Internal_Sym
*sym
,
6554 const char **namep ATTRIBUTE_UNUSED
,
6555 flagword
*flagsp ATTRIBUTE_UNUSED
,
6561 switch (sym
->st_shndx
)
6563 case SHN_X86_64_LCOMMON
:
6564 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6567 lcomm
= bfd_make_section_with_flags (abfd
,
6571 | SEC_LINKER_CREATED
));
6574 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6577 *valp
= sym
->st_size
;
6585 /* Given a BFD section, try to locate the corresponding ELF section
6589 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6590 asection
*sec
, int *index_return
)
6592 if (sec
== &_bfd_elf_large_com_section
)
6594 *index_return
= SHN_X86_64_LCOMMON
;
6600 /* Process a symbol. */
6603 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6606 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6608 switch (elfsym
->internal_elf_sym
.st_shndx
)
6610 case SHN_X86_64_LCOMMON
:
6611 asym
->section
= &_bfd_elf_large_com_section
;
6612 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6613 /* Common symbol doesn't set BSF_GLOBAL. */
6614 asym
->flags
&= ~BSF_GLOBAL
;
6620 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6622 return (sym
->st_shndx
== SHN_COMMON
6623 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6627 elf_x86_64_common_section_index (asection
*sec
)
6629 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6632 return SHN_X86_64_LCOMMON
;
6636 elf_x86_64_common_section (asection
*sec
)
6638 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6639 return bfd_com_section_ptr
;
6641 return &_bfd_elf_large_com_section
;
6645 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6646 const Elf_Internal_Sym
*sym
,
6651 const asection
*oldsec
)
6653 /* A normal common symbol and a large common symbol result in a
6654 normal common symbol. We turn the large common symbol into a
6657 && h
->root
.type
== bfd_link_hash_common
6659 && bfd_is_com_section (*psec
)
6662 if (sym
->st_shndx
== SHN_COMMON
6663 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6665 h
->root
.u
.c
.p
->section
6666 = bfd_make_section_old_way (oldbfd
, "COMMON");
6667 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6669 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6670 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6671 *psec
= bfd_com_section_ptr
;
6678 elf_x86_64_additional_program_headers (bfd
*abfd
,
6679 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6684 /* Check to see if we need a large readonly segment. */
6685 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6686 if (s
&& (s
->flags
& SEC_LOAD
))
6689 /* Check to see if we need a large data segment. Since .lbss sections
6690 is placed right after the .bss section, there should be no need for
6691 a large data segment just because of .lbss. */
6692 s
= bfd_get_section_by_name (abfd
, ".ldata");
6693 if (s
&& (s
->flags
& SEC_LOAD
))
6699 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6702 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6704 if (h
->plt
.offset
!= (bfd_vma
) -1
6706 && !h
->pointer_equality_needed
)
6709 return _bfd_elf_hash_symbol (h
);
6712 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6715 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6716 const bfd_target
*output
)
6718 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6719 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6720 && _bfd_elf_relocs_compatible (input
, output
));
6723 static const struct bfd_elf_special_section
6724 elf_x86_64_special_sections
[]=
6726 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6727 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6728 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
6729 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6730 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6731 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6732 { NULL
, 0, 0, 0, 0 }
6735 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6736 #define TARGET_LITTLE_NAME "elf64-x86-64"
6737 #define ELF_ARCH bfd_arch_i386
6738 #define ELF_TARGET_ID X86_64_ELF_DATA
6739 #define ELF_MACHINE_CODE EM_X86_64
6740 #define ELF_MAXPAGESIZE 0x200000
6741 #define ELF_MINPAGESIZE 0x1000
6742 #define ELF_COMMONPAGESIZE 0x1000
6744 #define elf_backend_can_gc_sections 1
6745 #define elf_backend_can_refcount 1
6746 #define elf_backend_want_got_plt 1
6747 #define elf_backend_plt_readonly 1
6748 #define elf_backend_want_plt_sym 0
6749 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6750 #define elf_backend_rela_normal 1
6751 #define elf_backend_plt_alignment 4
6752 #define elf_backend_extern_protected_data 1
6753 #define elf_backend_caches_rawsize 1
6755 #define elf_info_to_howto elf_x86_64_info_to_howto
6757 #define bfd_elf64_bfd_link_hash_table_create \
6758 elf_x86_64_link_hash_table_create
6759 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
6760 #define bfd_elf64_bfd_reloc_name_lookup \
6761 elf_x86_64_reloc_name_lookup
6763 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
6764 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
6765 #define elf_backend_check_relocs elf_x86_64_check_relocs
6766 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
6767 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
6768 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
6769 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
6770 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
6771 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
6772 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
6773 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
6775 #define elf_backend_write_core_note elf_x86_64_write_core_note
6777 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
6778 #define elf_backend_relocate_section elf_x86_64_relocate_section
6779 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
6780 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
6781 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
6782 #define elf_backend_object_p elf64_x86_64_elf_object_p
6783 #define bfd_elf64_mkobject elf_x86_64_mkobject
6784 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
6786 #define elf_backend_section_from_shdr \
6787 elf_x86_64_section_from_shdr
6789 #define elf_backend_section_from_bfd_section \
6790 elf_x86_64_elf_section_from_bfd_section
6791 #define elf_backend_add_symbol_hook \
6792 elf_x86_64_add_symbol_hook
6793 #define elf_backend_symbol_processing \
6794 elf_x86_64_symbol_processing
6795 #define elf_backend_common_section_index \
6796 elf_x86_64_common_section_index
6797 #define elf_backend_common_section \
6798 elf_x86_64_common_section
6799 #define elf_backend_common_definition \
6800 elf_x86_64_common_definition
6801 #define elf_backend_merge_symbol \
6802 elf_x86_64_merge_symbol
6803 #define elf_backend_special_sections \
6804 elf_x86_64_special_sections
6805 #define elf_backend_additional_program_headers \
6806 elf_x86_64_additional_program_headers
6807 #define elf_backend_hash_symbol \
6808 elf_x86_64_hash_symbol
6809 #define elf_backend_omit_section_dynsym \
6810 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
6811 #define elf_backend_fixup_symbol \
6812 elf_x86_64_fixup_symbol
6814 #include "elf64-target.h"
6816 /* CloudABI support. */
6818 #undef TARGET_LITTLE_SYM
6819 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
6820 #undef TARGET_LITTLE_NAME
6821 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
6824 #define ELF_OSABI ELFOSABI_CLOUDABI
6827 #define elf64_bed elf64_x86_64_cloudabi_bed
6829 #include "elf64-target.h"
6831 /* FreeBSD support. */
6833 #undef TARGET_LITTLE_SYM
6834 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
6835 #undef TARGET_LITTLE_NAME
6836 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
6839 #define ELF_OSABI ELFOSABI_FREEBSD
6842 #define elf64_bed elf64_x86_64_fbsd_bed
6844 #include "elf64-target.h"
6846 /* Solaris 2 support. */
6848 #undef TARGET_LITTLE_SYM
6849 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
6850 #undef TARGET_LITTLE_NAME
6851 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
6853 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6854 objects won't be recognized. */
6858 #define elf64_bed elf64_x86_64_sol2_bed
6860 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
6862 #undef elf_backend_static_tls_alignment
6863 #define elf_backend_static_tls_alignment 16
6865 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6867 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6869 #undef elf_backend_want_plt_sym
6870 #define elf_backend_want_plt_sym 1
6872 #undef elf_backend_strtab_flags
6873 #define elf_backend_strtab_flags SHF_STRINGS
6876 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6877 bfd
*obfd ATTRIBUTE_UNUSED
,
6878 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6879 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6881 /* PR 19938: FIXME: Need to add code for setting the sh_info
6882 and sh_link fields of Solaris specific section types. */
6886 #undef elf_backend_copy_special_section_fields
6887 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
6889 #include "elf64-target.h"
6891 /* Native Client support. */
6894 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
6896 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
6897 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
6901 #undef TARGET_LITTLE_SYM
6902 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
6903 #undef TARGET_LITTLE_NAME
6904 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
6906 #define elf64_bed elf64_x86_64_nacl_bed
6908 #undef ELF_MAXPAGESIZE
6909 #undef ELF_MINPAGESIZE
6910 #undef ELF_COMMONPAGESIZE
6911 #define ELF_MAXPAGESIZE 0x10000
6912 #define ELF_MINPAGESIZE 0x10000
6913 #define ELF_COMMONPAGESIZE 0x10000
6915 /* Restore defaults. */
6917 #undef elf_backend_static_tls_alignment
6918 #undef elf_backend_want_plt_sym
6919 #define elf_backend_want_plt_sym 0
6920 #undef elf_backend_strtab_flags
6921 #undef elf_backend_copy_special_section_fields
6923 /* NaCl uses substantially different PLT entries for the same effects. */
6925 #undef elf_backend_plt_alignment
6926 #define elf_backend_plt_alignment 5
6927 #define NACL_PLT_ENTRY_SIZE 64
6928 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6930 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
6932 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
6933 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
6934 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6935 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6936 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6938 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
6939 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
6941 /* 32 bytes of nop to pad out to the standard size. */
6942 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6943 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6944 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6945 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6946 0x66, /* excess data16 prefix */
6950 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6952 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
6953 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6954 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6955 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6957 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
6958 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6959 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6961 /* Lazy GOT entries point here (32-byte aligned). */
6962 0x68, /* pushq immediate */
6963 0, 0, 0, 0, /* replaced with index into relocation table. */
6964 0xe9, /* jmp relative */
6965 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
6967 /* 22 bytes of nop to pad out to the standard size. */
6968 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6969 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6970 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
6973 /* .eh_frame covering the .plt section. */
6975 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
6977 #if (PLT_CIE_LENGTH != 20 \
6978 || PLT_FDE_LENGTH != 36 \
6979 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6980 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6981 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
6983 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6984 0, 0, 0, 0, /* CIE ID */
6985 1, /* CIE version */
6986 'z', 'R', 0, /* Augmentation string */
6987 1, /* Code alignment factor */
6988 0x78, /* Data alignment factor */
6989 16, /* Return address column */
6990 1, /* Augmentation size */
6991 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6992 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
6993 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
6994 DW_CFA_nop
, DW_CFA_nop
,
6996 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6997 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
6998 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
6999 0, 0, 0, 0, /* .plt size goes here */
7000 0, /* Augmentation size */
7001 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
7002 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7003 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
7004 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7005 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7006 13, /* Block length */
7007 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7008 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7009 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7010 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7011 DW_CFA_nop
, DW_CFA_nop
7014 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7016 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7017 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7018 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7019 2, /* plt0_got1_offset */
7020 9, /* plt0_got2_offset */
7021 13, /* plt0_got2_insn_end */
7022 3, /* plt_got_offset */
7023 33, /* plt_reloc_offset */
7024 38, /* plt_plt_offset */
7025 7, /* plt_got_insn_size */
7026 42, /* plt_plt_insn_end */
7027 32, /* plt_lazy_offset */
7028 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7029 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
7032 #undef elf_backend_arch_data
7033 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7035 #undef elf_backend_object_p
7036 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7037 #undef elf_backend_modify_segment_map
7038 #define elf_backend_modify_segment_map nacl_modify_segment_map
7039 #undef elf_backend_modify_program_headers
7040 #define elf_backend_modify_program_headers nacl_modify_program_headers
7041 #undef elf_backend_final_write_processing
7042 #define elf_backend_final_write_processing nacl_final_write_processing
7044 #include "elf64-target.h"
7046 /* Native Client x32 support. */
7049 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7051 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7052 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7056 #undef TARGET_LITTLE_SYM
7057 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7058 #undef TARGET_LITTLE_NAME
7059 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7061 #define elf32_bed elf32_x86_64_nacl_bed
7063 #define bfd_elf32_bfd_link_hash_table_create \
7064 elf_x86_64_link_hash_table_create
7065 #define bfd_elf32_bfd_reloc_type_lookup \
7066 elf_x86_64_reloc_type_lookup
7067 #define bfd_elf32_bfd_reloc_name_lookup \
7068 elf_x86_64_reloc_name_lookup
7069 #define bfd_elf32_mkobject \
7071 #define bfd_elf32_get_synthetic_symtab \
7072 elf_x86_64_get_synthetic_symtab
7074 #undef elf_backend_object_p
7075 #define elf_backend_object_p \
7076 elf32_x86_64_nacl_elf_object_p
7078 #undef elf_backend_bfd_from_remote_memory
7079 #define elf_backend_bfd_from_remote_memory \
7080 _bfd_elf32_bfd_from_remote_memory
7082 #undef elf_backend_size_info
7083 #define elf_backend_size_info \
7084 _bfd_elf32_size_info
7086 #include "elf32-target.h"
7088 /* Restore defaults. */
7089 #undef elf_backend_object_p
7090 #define elf_backend_object_p elf64_x86_64_elf_object_p
7091 #undef elf_backend_bfd_from_remote_memory
7092 #undef elf_backend_size_info
7093 #undef elf_backend_modify_segment_map
7094 #undef elf_backend_modify_program_headers
7095 #undef elf_backend_final_write_processing
7097 /* Intel L1OM support. */
7100 elf64_l1om_elf_object_p (bfd
*abfd
)
7102 /* Set the right machine number for an L1OM elf64 file. */
7103 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7107 #undef TARGET_LITTLE_SYM
7108 #define TARGET_LITTLE_SYM l1om_elf64_vec
7109 #undef TARGET_LITTLE_NAME
7110 #define TARGET_LITTLE_NAME "elf64-l1om"
7112 #define ELF_ARCH bfd_arch_l1om
7114 #undef ELF_MACHINE_CODE
7115 #define ELF_MACHINE_CODE EM_L1OM
7120 #define elf64_bed elf64_l1om_bed
7122 #undef elf_backend_object_p
7123 #define elf_backend_object_p elf64_l1om_elf_object_p
7125 /* Restore defaults. */
7126 #undef ELF_MAXPAGESIZE
7127 #undef ELF_MINPAGESIZE
7128 #undef ELF_COMMONPAGESIZE
7129 #define ELF_MAXPAGESIZE 0x200000
7130 #define ELF_MINPAGESIZE 0x1000
7131 #define ELF_COMMONPAGESIZE 0x1000
7132 #undef elf_backend_plt_alignment
7133 #define elf_backend_plt_alignment 4
7134 #undef elf_backend_arch_data
7135 #define elf_backend_arch_data &elf_x86_64_arch_bed
7137 #include "elf64-target.h"
7139 /* FreeBSD L1OM support. */
7141 #undef TARGET_LITTLE_SYM
7142 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7143 #undef TARGET_LITTLE_NAME
7144 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7147 #define ELF_OSABI ELFOSABI_FREEBSD
7150 #define elf64_bed elf64_l1om_fbsd_bed
7152 #include "elf64-target.h"
7154 /* Intel K1OM support. */
7157 elf64_k1om_elf_object_p (bfd
*abfd
)
7159 /* Set the right machine number for an K1OM elf64 file. */
7160 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7164 #undef TARGET_LITTLE_SYM
7165 #define TARGET_LITTLE_SYM k1om_elf64_vec
7166 #undef TARGET_LITTLE_NAME
7167 #define TARGET_LITTLE_NAME "elf64-k1om"
7169 #define ELF_ARCH bfd_arch_k1om
7171 #undef ELF_MACHINE_CODE
7172 #define ELF_MACHINE_CODE EM_K1OM
7177 #define elf64_bed elf64_k1om_bed
7179 #undef elf_backend_object_p
7180 #define elf_backend_object_p elf64_k1om_elf_object_p
7182 #undef elf_backend_static_tls_alignment
7184 #undef elf_backend_want_plt_sym
7185 #define elf_backend_want_plt_sym 0
7187 #include "elf64-target.h"
7189 /* FreeBSD K1OM support. */
7191 #undef TARGET_LITTLE_SYM
7192 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7193 #undef TARGET_LITTLE_NAME
7194 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7197 #define ELF_OSABI ELFOSABI_FREEBSD
7200 #define elf64_bed elf64_k1om_fbsd_bed
7202 #include "elf64-target.h"
7204 /* 32bit x86-64 support. */
7206 #undef TARGET_LITTLE_SYM
7207 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7208 #undef TARGET_LITTLE_NAME
7209 #define TARGET_LITTLE_NAME "elf32-x86-64"
7213 #define ELF_ARCH bfd_arch_i386
7215 #undef ELF_MACHINE_CODE
7216 #define ELF_MACHINE_CODE EM_X86_64
7220 #undef elf_backend_object_p
7221 #define elf_backend_object_p \
7222 elf32_x86_64_elf_object_p
7224 #undef elf_backend_bfd_from_remote_memory
7225 #define elf_backend_bfd_from_remote_memory \
7226 _bfd_elf32_bfd_from_remote_memory
7228 #undef elf_backend_size_info
7229 #define elf_backend_size_info \
7230 _bfd_elf32_size_info
7232 #include "elf32-target.h"