1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
32 #include "libiberty.h"
34 #include "opcode/i386.h"
35 #include "elf/x86-64.h"
42 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
43 #define MINUS_ONE (~ (bfd_vma) 0)
45 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
46 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
47 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
48 since they are the same. */
50 #define ABI_64_P(abfd) \
51 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
53 /* The relocation "howto" table. Order of fields:
54 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
55 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
56 static reloc_howto_type x86_64_elf_howto_table
[] =
58 HOWTO(R_X86_64_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
59 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
61 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
64 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
65 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
67 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
71 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
74 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
79 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
82 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
85 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
86 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
88 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
89 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
91 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
92 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
94 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
96 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
98 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
100 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
102 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
105 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
108 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
111 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
112 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
114 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
115 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
117 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
118 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
120 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
121 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
123 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
124 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
126 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
129 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
131 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
132 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
133 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
134 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
135 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
136 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
138 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
139 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
141 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
142 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
143 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
144 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
145 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
147 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
148 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
150 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
151 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
153 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
154 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
156 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
157 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
158 "R_X86_64_GOTPC32_TLSDESC",
159 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
160 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
161 complain_overflow_dont
, bfd_elf_generic_reloc
,
162 "R_X86_64_TLSDESC_CALL",
164 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
165 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
167 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
168 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
169 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
171 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
172 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
174 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
175 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
177 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
178 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
180 HOWTO(R_X86_64_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
181 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", FALSE
, 0xffffffff,
183 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
184 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", FALSE
, 0xffffffff,
187 /* We have a gap in the reloc numbers here.
188 R_X86_64_standard counts the number up to this point, and
189 R_X86_64_vt_offset is the value to subtract from a reloc type of
190 R_X86_64_GNU_VT* to form an index into this table. */
191 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
192 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
194 /* GNU extension to record C++ vtable hierarchy. */
195 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
196 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
198 /* GNU extension to record C++ vtable member usage. */
199 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
200 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
203 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
204 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
205 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
209 #define IS_X86_64_PCREL_TYPE(TYPE) \
210 ( ((TYPE) == R_X86_64_PC8) \
211 || ((TYPE) == R_X86_64_PC16) \
212 || ((TYPE) == R_X86_64_PC32) \
213 || ((TYPE) == R_X86_64_PC32_BND) \
214 || ((TYPE) == R_X86_64_PC64))
216 /* Map BFD relocs to the x86_64 elf relocs. */
219 bfd_reloc_code_real_type bfd_reloc_val
;
220 unsigned char elf_reloc_val
;
223 static const struct elf_reloc_map x86_64_reloc_map
[] =
225 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
226 { BFD_RELOC_64
, R_X86_64_64
, },
227 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
228 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
229 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
230 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
231 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
232 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
233 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
234 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
235 { BFD_RELOC_32
, R_X86_64_32
, },
236 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
237 { BFD_RELOC_16
, R_X86_64_16
, },
238 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
239 { BFD_RELOC_8
, R_X86_64_8
, },
240 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
241 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
242 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
243 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
244 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
245 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
246 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
247 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
248 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
249 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
250 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
251 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
252 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
253 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
254 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
255 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
256 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
257 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
258 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
259 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
260 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
261 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
262 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
263 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
264 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
265 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
266 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
267 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
268 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
271 static reloc_howto_type
*
272 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
276 if (r_type
== (unsigned int) R_X86_64_32
)
281 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
283 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
284 || r_type
>= (unsigned int) R_X86_64_max
)
286 if (r_type
>= (unsigned int) R_X86_64_standard
)
288 /* xgettext:c-format */
289 _bfd_error_handler (_("%B: invalid relocation type %d"),
291 r_type
= R_X86_64_NONE
;
296 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
297 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
298 return &x86_64_elf_howto_table
[i
];
301 /* Given a BFD reloc type, return a HOWTO structure. */
302 static reloc_howto_type
*
303 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
304 bfd_reloc_code_real_type code
)
308 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
311 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
312 return elf_x86_64_rtype_to_howto (abfd
,
313 x86_64_reloc_map
[i
].elf_reloc_val
);
318 static reloc_howto_type
*
319 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
324 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
326 /* Get x32 R_X86_64_32. */
327 reloc_howto_type
*reloc
328 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
329 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
333 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
334 if (x86_64_elf_howto_table
[i
].name
!= NULL
335 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
336 return &x86_64_elf_howto_table
[i
];
341 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
344 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
345 Elf_Internal_Rela
*dst
)
349 r_type
= ELF32_R_TYPE (dst
->r_info
);
350 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
351 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
354 /* Support for core dump NOTE sections. */
356 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
361 switch (note
->descsz
)
366 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
368 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
371 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
379 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
381 elf_tdata (abfd
)->core
->signal
382 = bfd_get_16 (abfd
, note
->descdata
+ 12);
385 elf_tdata (abfd
)->core
->lwpid
386 = bfd_get_32 (abfd
, note
->descdata
+ 32);
395 /* Make a ".reg/999" section. */
396 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
397 size
, note
->descpos
+ offset
);
401 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
403 switch (note
->descsz
)
408 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
409 elf_tdata (abfd
)->core
->pid
410 = bfd_get_32 (abfd
, note
->descdata
+ 12);
411 elf_tdata (abfd
)->core
->program
412 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
413 elf_tdata (abfd
)->core
->command
414 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
417 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
418 elf_tdata (abfd
)->core
->pid
419 = bfd_get_32 (abfd
, note
->descdata
+ 24);
420 elf_tdata (abfd
)->core
->program
421 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
422 elf_tdata (abfd
)->core
->command
423 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
426 /* Note that for some reason, a spurious space is tacked
427 onto the end of the args in some (at least one anyway)
428 implementations, so strip it off if it exists. */
431 char *command
= elf_tdata (abfd
)->core
->command
;
432 int n
= strlen (command
);
434 if (0 < n
&& command
[n
- 1] == ' ')
435 command
[n
- 1] = '\0';
443 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
446 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
448 const char *fname
, *psargs
;
459 va_start (ap
, note_type
);
460 fname
= va_arg (ap
, const char *);
461 psargs
= va_arg (ap
, const char *);
464 if (bed
->s
->elfclass
== ELFCLASS32
)
467 memset (&data
, 0, sizeof (data
));
468 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
469 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
470 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
471 &data
, sizeof (data
));
476 memset (&data
, 0, sizeof (data
));
477 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
478 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
479 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
480 &data
, sizeof (data
));
485 va_start (ap
, note_type
);
486 pid
= va_arg (ap
, long);
487 cursig
= va_arg (ap
, int);
488 gregs
= va_arg (ap
, const void *);
491 if (bed
->s
->elfclass
== ELFCLASS32
)
493 if (bed
->elf_machine_code
== EM_X86_64
)
495 prstatusx32_t prstat
;
496 memset (&prstat
, 0, sizeof (prstat
));
498 prstat
.pr_cursig
= cursig
;
499 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
500 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
501 &prstat
, sizeof (prstat
));
506 memset (&prstat
, 0, sizeof (prstat
));
508 prstat
.pr_cursig
= cursig
;
509 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
510 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
511 &prstat
, sizeof (prstat
));
517 memset (&prstat
, 0, sizeof (prstat
));
519 prstat
.pr_cursig
= cursig
;
520 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
521 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
522 &prstat
, sizeof (prstat
));
529 /* Functions for the x86-64 ELF linker. */
531 /* The name of the dynamic interpreter. This is put in the .interp
534 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
535 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
537 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
538 copying dynamic variables from a shared lib into an app's dynbss
539 section, and instead use a dynamic relocation to point into the
541 #define ELIMINATE_COPY_RELOCS 1
543 /* The size in bytes of an entry in the global offset table. */
545 #define GOT_ENTRY_SIZE 8
547 /* The size in bytes of an entry in the lazy procedure linkage table. */
549 #define LAZY_PLT_ENTRY_SIZE 16
551 /* The size in bytes of an entry in the non-lazy procedure linkage
554 #define NON_LAZY_PLT_ENTRY_SIZE 8
556 /* The first entry in a lazy procedure linkage table looks like this.
557 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
560 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
562 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
563 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
564 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
567 /* Subsequent entries in a lazy procedure linkage table look like this. */
569 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
571 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
572 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
573 0x68, /* pushq immediate */
574 0, 0, 0, 0, /* replaced with index into relocation table. */
575 0xe9, /* jmp relative */
576 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
579 /* The first entry in a lazy procedure linkage table with BND prefix
582 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
584 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
585 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
586 0x0f, 0x1f, 0 /* nopl (%rax) */
589 /* Subsequent entries for branches with BND prefx in a lazy procedure
590 linkage table look like this. */
592 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
594 0x68, 0, 0, 0, 0, /* pushq immediate */
595 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
596 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
599 /* The first entry in the IBT-enabled lazy procedure linkage table is the
600 the same as the lazy PLT with BND prefix so that bound registers are
601 preserved when control is passed to dynamic linker. Subsequent
602 entries for a IBT-enabled lazy procedure linkage table look like
605 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
607 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
608 0x68, 0, 0, 0, 0, /* pushq immediate */
609 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
613 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
614 is the the same as the normal lazy PLT. Subsequent entries for an
615 x32 IBT-enabled lazy procedure linkage table look like this. */
617 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
619 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
620 0x68, 0, 0, 0, 0, /* pushq immediate */
621 0xe9, 0, 0, 0, 0, /* jmpq relative */
622 0x66, 0x90 /* xchg %ax,%ax */
625 /* Entries in the non-lazey procedure linkage table look like this. */
627 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
629 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
630 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
631 0x66, 0x90 /* xchg %ax,%ax */
634 /* Entries for branches with BND prefix in the non-lazey procedure
635 linkage table look like this. */
637 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
639 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
640 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
644 /* Entries for branches with IBT-enabled in the non-lazey procedure
645 linkage table look like this. They have the same size as the lazy
648 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
650 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
651 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
652 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
653 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
656 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
657 linkage table look like this. They have the same size as the lazy
660 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
662 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
663 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
664 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
665 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
668 /* .eh_frame covering the lazy .plt section. */
670 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
672 #define PLT_CIE_LENGTH 20
673 #define PLT_FDE_LENGTH 36
674 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
675 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
676 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
677 0, 0, 0, 0, /* CIE ID */
679 'z', 'R', 0, /* Augmentation string */
680 1, /* Code alignment factor */
681 0x78, /* Data alignment factor */
682 16, /* Return address column */
683 1, /* Augmentation size */
684 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
685 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
686 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
687 DW_CFA_nop
, DW_CFA_nop
,
689 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
690 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
691 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
692 0, 0, 0, 0, /* .plt size goes here */
693 0, /* Augmentation size */
694 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
695 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
696 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
697 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
698 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
699 11, /* Block length */
700 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
701 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
702 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
703 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
704 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
707 /* .eh_frame covering the lazy BND .plt section. */
709 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
711 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
712 0, 0, 0, 0, /* CIE ID */
714 'z', 'R', 0, /* Augmentation string */
715 1, /* Code alignment factor */
716 0x78, /* Data alignment factor */
717 16, /* Return address column */
718 1, /* Augmentation size */
719 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
720 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
721 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
722 DW_CFA_nop
, DW_CFA_nop
,
724 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
725 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
726 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
727 0, 0, 0, 0, /* .plt size goes here */
728 0, /* Augmentation size */
729 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
730 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
731 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
732 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
733 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
734 11, /* Block length */
735 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
736 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
737 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
738 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
739 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
742 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
744 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
746 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
747 0, 0, 0, 0, /* CIE ID */
749 'z', 'R', 0, /* Augmentation string */
750 1, /* Code alignment factor */
751 0x78, /* Data alignment factor */
752 16, /* Return address column */
753 1, /* Augmentation size */
754 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
755 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
756 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
757 DW_CFA_nop
, DW_CFA_nop
,
759 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
760 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
761 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
762 0, 0, 0, 0, /* .plt size goes here */
763 0, /* Augmentation size */
764 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
765 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
766 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
767 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
768 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
769 11, /* Block length */
770 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
771 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
772 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
773 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
774 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
777 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
779 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
781 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
782 0, 0, 0, 0, /* CIE ID */
784 'z', 'R', 0, /* Augmentation string */
785 1, /* Code alignment factor */
786 0x78, /* Data alignment factor */
787 16, /* Return address column */
788 1, /* Augmentation size */
789 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
790 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
791 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
792 DW_CFA_nop
, DW_CFA_nop
,
794 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
795 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
796 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
797 0, 0, 0, 0, /* .plt size goes here */
798 0, /* Augmentation size */
799 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
800 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
801 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
802 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
803 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
804 11, /* Block length */
805 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
806 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
807 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
808 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
809 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
812 /* .eh_frame covering the non-lazy .plt section. */
814 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
816 #define PLT_GOT_FDE_LENGTH 20
817 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
818 0, 0, 0, 0, /* CIE ID */
820 'z', 'R', 0, /* Augmentation string */
821 1, /* Code alignment factor */
822 0x78, /* Data alignment factor */
823 16, /* Return address column */
824 1, /* Augmentation size */
825 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
826 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
827 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
828 DW_CFA_nop
, DW_CFA_nop
,
830 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
831 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
832 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
833 0, 0, 0, 0, /* non-lazy .plt size goes here */
834 0, /* Augmentation size */
835 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
836 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
839 struct elf_x86_64_lazy_plt_layout
841 /* Templates for the initial PLT entry and for subsequent entries. */
842 const bfd_byte
*plt0_entry
;
843 const bfd_byte
*plt_entry
;
844 unsigned int plt_entry_size
; /* Size of each PLT entry. */
846 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
847 unsigned int plt0_got1_offset
;
848 unsigned int plt0_got2_offset
;
850 /* Offset of the end of the PC-relative instruction containing
852 unsigned int plt0_got2_insn_end
;
854 /* Offsets into plt_entry that are to be replaced with... */
855 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
856 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
857 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
859 /* Length of the PC-relative instruction containing plt_got_offset. */
860 unsigned int plt_got_insn_size
;
862 /* Offset of the end of the PC-relative jump to plt0_entry. */
863 unsigned int plt_plt_insn_end
;
865 /* Offset into plt_entry where the initial value of the GOT entry points. */
866 unsigned int plt_lazy_offset
;
868 /* .eh_frame covering the lazy .plt section. */
869 const bfd_byte
*eh_frame_plt
;
870 unsigned int eh_frame_plt_size
;
873 struct elf_x86_64_non_lazy_plt_layout
875 /* Template for the lazy PLT entries. */
876 const bfd_byte
*plt_entry
;
877 unsigned int plt_entry_size
; /* Size of each PLT entry. */
879 /* Offsets into plt_entry that are to be replaced with... */
880 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
882 /* Length of the PC-relative instruction containing plt_got_offset. */
883 unsigned int plt_got_insn_size
;
885 /* .eh_frame covering the non-lazy .plt section. */
886 const bfd_byte
*eh_frame_plt
;
887 unsigned int eh_frame_plt_size
;
890 struct elf_x86_64_plt_layout
892 /* Template for the PLT entries. */
893 const bfd_byte
*plt_entry
;
894 unsigned int plt_entry_size
; /* Size of each PLT entry. */
897 unsigned int has_plt0
;
899 /* Offsets into plt_entry that are to be replaced with... */
900 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
902 /* Length of the PC-relative instruction containing plt_got_offset. */
903 unsigned int plt_got_insn_size
;
905 /* .eh_frame covering the .plt section. */
906 const bfd_byte
*eh_frame_plt
;
907 unsigned int eh_frame_plt_size
;
910 /* Architecture-specific backend data for x86-64. */
912 struct elf_x86_64_backend_data
922 #define get_elf_x86_64_arch_data(bed) \
923 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
925 #define get_elf_x86_64_backend_data(abfd) \
926 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
928 /* These are the standard parameters. */
929 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_lazy_plt
=
931 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
932 elf_x86_64_lazy_plt_entry
, /* plt_entry */
933 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
934 2, /* plt0_got1_offset */
935 8, /* plt0_got2_offset */
936 12, /* plt0_got2_insn_end */
937 2, /* plt_got_offset */
938 7, /* plt_reloc_offset */
939 12, /* plt_plt_offset */
940 6, /* plt_got_insn_size */
941 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
942 6, /* plt_lazy_offset */
943 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
944 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
947 static const struct elf_x86_64_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
949 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
950 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
951 2, /* plt_got_offset */
952 6, /* plt_got_insn_size */
953 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
954 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
957 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
959 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
960 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
961 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
962 2, /* plt0_got1_offset */
963 1+8, /* plt0_got2_offset */
964 1+12, /* plt0_got2_insn_end */
965 1+2, /* plt_got_offset */
966 1, /* plt_reloc_offset */
967 7, /* plt_plt_offset */
968 1+6, /* plt_got_insn_size */
969 11, /* plt_plt_insn_end */
970 0, /* plt_lazy_offset */
971 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
972 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
975 static const struct elf_x86_64_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
977 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
978 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
979 1+2, /* plt_got_offset */
980 1+6, /* plt_got_insn_size */
981 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
982 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
985 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
987 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
988 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
989 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
990 2, /* plt0_got1_offset */
991 1+8, /* plt0_got2_offset */
992 1+12, /* plt0_got2_insn_end */
993 4+1+2, /* plt_got_offset */
994 4+1, /* plt_reloc_offset */
995 4+1+6, /* plt_plt_offset */
996 4+1+6, /* plt_got_insn_size */
997 4+1+5+5, /* plt_plt_insn_end */
998 0, /* plt_lazy_offset */
999 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1000 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1003 static const struct elf_x86_64_lazy_plt_layout elf_x32_lazy_ibt_plt
=
1005 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
1006 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
1007 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1008 2, /* plt0_got1_offset */
1009 8, /* plt0_got2_offset */
1010 12, /* plt0_got2_insn_end */
1011 4+2, /* plt_got_offset */
1012 4+1, /* plt_reloc_offset */
1013 4+6, /* plt_plt_offset */
1014 4+6, /* plt_got_insn_size */
1015 4+5+5, /* plt_plt_insn_end */
1016 0, /* plt_lazy_offset */
1017 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
1018 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
1021 static const struct elf_x86_64_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
1023 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
1024 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1025 4+1+2, /* plt_got_offset */
1026 4+1+6, /* plt_got_insn_size */
1027 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1028 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1031 static const struct elf_x86_64_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
1033 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
1034 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
1035 4+2, /* plt_got_offset */
1036 4+6, /* plt_got_insn_size */
1037 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
1038 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
1041 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
1046 #define elf_backend_arch_data &elf_x86_64_arch_bed
1048 /* Is a undefined weak symbol which is resolved to 0. Reference to an
1049 undefined weak symbol is resolved to 0 when building executable if
1050 it isn't dynamic and
1051 1. Has non-GOT/non-PLT relocations in text section. Or
1052 2. Has no GOT/PLT relocation.
1053 Local undefined weak symbol is always resolved to 0.
1055 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
1056 ((EH)->elf.root.type == bfd_link_hash_undefweak \
1057 && ((EH)->elf.forced_local \
1058 || (bfd_link_executable (INFO) \
1059 && (elf_x86_64_hash_table (INFO)->interp == NULL \
1061 || (EH)->has_non_got_reloc \
1062 || !(INFO)->dynamic_undefined_weak))))
1064 /* x86-64 ELF linker hash entry. */
1066 struct elf_x86_64_link_hash_entry
1068 struct elf_link_hash_entry elf
;
1070 /* Track dynamic relocs copied for this symbol. */
1071 struct elf_dyn_relocs
*dyn_relocs
;
1073 #define GOT_UNKNOWN 0
1074 #define GOT_NORMAL 1
1075 #define GOT_TLS_GD 2
1076 #define GOT_TLS_IE 3
1077 #define GOT_TLS_GDESC 4
1078 #define GOT_TLS_GD_BOTH_P(type) \
1079 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
1080 #define GOT_TLS_GD_P(type) \
1081 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
1082 #define GOT_TLS_GDESC_P(type) \
1083 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
1084 #define GOT_TLS_GD_ANY_P(type) \
1085 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
1086 unsigned char tls_type
;
1088 /* TRUE if a weak symbol with a real definition needs a copy reloc.
1089 When there is a weak symbol with a real definition, the processor
1090 independent code will have arranged for us to see the real
1091 definition first. We need to copy the needs_copy bit from the
1092 real definition and check it when allowing copy reloc in PIE. */
1093 unsigned int needs_copy
: 1;
1095 /* TRUE if symbol has GOT or PLT relocations. */
1096 unsigned int has_got_reloc
: 1;
1098 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
1099 unsigned int has_non_got_reloc
: 1;
1101 /* Don't call finish_dynamic_symbol on this symbol. */
1102 unsigned int no_finish_dynamic_symbol
: 1;
1104 /* 0: symbol isn't __tls_get_addr.
1105 1: symbol is __tls_get_addr.
1106 2: symbol is unknown. */
1107 unsigned int tls_get_addr
: 2;
1109 /* Reference count of C/C++ function pointer relocations in read-write
1110 section which can be resolved at run-time. */
1111 bfd_signed_vma func_pointer_refcount
;
1113 /* Information about the GOT PLT entry. Filled when there are both
1114 GOT and PLT relocations against the same function. */
1115 union gotplt_union plt_got
;
1117 /* Information about the second PLT entry. */
1118 union gotplt_union plt_second
;
1120 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
1121 starting at the end of the jump table. */
1122 bfd_vma tlsdesc_got
;
1125 #define elf_x86_64_hash_entry(ent) \
1126 ((struct elf_x86_64_link_hash_entry *)(ent))
1128 struct elf_x86_64_obj_tdata
1130 struct elf_obj_tdata root
;
1132 /* tls_type for each local got entry. */
1133 char *local_got_tls_type
;
1135 /* GOTPLT entries for TLS descriptors. */
1136 bfd_vma
*local_tlsdesc_gotent
;
1139 #define elf_x86_64_tdata(abfd) \
1140 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
1142 #define elf_x86_64_local_got_tls_type(abfd) \
1143 (elf_x86_64_tdata (abfd)->local_got_tls_type)
1145 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
1146 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
1148 #define is_x86_64_elf(bfd) \
1149 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1150 && elf_tdata (bfd) != NULL \
1151 && elf_object_id (bfd) == X86_64_ELF_DATA)
1154 elf_x86_64_mkobject (bfd
*abfd
)
1156 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
1160 /* x86-64 ELF linker hash table. */
1162 struct elf_x86_64_link_hash_table
1164 struct elf_link_hash_table elf
;
1166 /* Short-cuts to get to dynamic linker sections. */
1168 asection
*plt_eh_frame
;
1169 asection
*plt_second
;
1170 asection
*plt_second_eh_frame
;
1172 asection
*plt_got_eh_frame
;
1174 /* Parameters describing PLT generation, lazy or non-lazy. */
1175 struct elf_x86_64_plt_layout plt
;
1177 /* Parameters describing lazy PLT generation. */
1178 const struct elf_x86_64_lazy_plt_layout
*lazy_plt
;
1180 /* Parameters describing non-lazy PLT generation. */
1181 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_plt
;
1185 bfd_signed_vma refcount
;
1189 /* The amount of space used by the jump slots in the GOT. */
1190 bfd_vma sgotplt_jump_table_size
;
1192 /* Small local sym cache. */
1193 struct sym_cache sym_cache
;
1195 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
1196 bfd_vma (*r_sym
) (bfd_vma
);
1197 unsigned int pointer_r_type
;
1198 const char *dynamic_interpreter
;
1199 int dynamic_interpreter_size
;
1201 /* _TLS_MODULE_BASE_ symbol. */
1202 struct bfd_link_hash_entry
*tls_module_base
;
1204 /* Used by local STT_GNU_IFUNC symbols. */
1205 htab_t loc_hash_table
;
1206 void * loc_hash_memory
;
1208 /* The offset into splt of the PLT entry for the TLS descriptor
1209 resolver. Special values are 0, if not necessary (or not found
1210 to be necessary yet), and -1 if needed but not determined
1212 bfd_vma tlsdesc_plt
;
1213 /* The offset into sgot of the GOT entry used by the PLT entry
1215 bfd_vma tlsdesc_got
;
1217 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
1218 bfd_vma next_jump_slot_index
;
1219 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
1220 bfd_vma next_irelative_index
;
1222 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
1223 to read-only sections. */
1224 bfd_boolean readonly_dynrelocs_against_ifunc
;
1227 /* Get the x86-64 ELF linker hash table from a link_info structure. */
1229 #define elf_x86_64_hash_table(p) \
1230 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1231 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
1233 #define elf_x86_64_compute_jump_table_size(htab) \
1234 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
1236 /* Create an entry in an x86-64 ELF linker hash table. */
1238 static struct bfd_hash_entry
*
1239 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1240 struct bfd_hash_table
*table
,
1243 /* Allocate the structure if it has not already been allocated by a
1247 entry
= (struct bfd_hash_entry
*)
1248 bfd_hash_allocate (table
,
1249 sizeof (struct elf_x86_64_link_hash_entry
));
1254 /* Call the allocation method of the superclass. */
1255 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1258 struct elf_x86_64_link_hash_entry
*eh
;
1260 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
1261 eh
->dyn_relocs
= NULL
;
1262 eh
->tls_type
= GOT_UNKNOWN
;
1264 eh
->has_got_reloc
= 0;
1265 eh
->has_non_got_reloc
= 0;
1266 eh
->no_finish_dynamic_symbol
= 0;
1267 eh
->tls_get_addr
= 2;
1268 eh
->func_pointer_refcount
= 0;
1269 eh
->plt_second
.offset
= (bfd_vma
) -1;
1270 eh
->plt_got
.offset
= (bfd_vma
) -1;
1271 eh
->tlsdesc_got
= (bfd_vma
) -1;
1277 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1278 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1279 as global symbol. We reuse indx and dynstr_index for local symbol
1280 hash since they aren't used by global symbols in this backend. */
1283 elf_x86_64_local_htab_hash (const void *ptr
)
1285 struct elf_link_hash_entry
*h
1286 = (struct elf_link_hash_entry
*) ptr
;
1287 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1290 /* Compare local hash entries. */
1293 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
1295 struct elf_link_hash_entry
*h1
1296 = (struct elf_link_hash_entry
*) ptr1
;
1297 struct elf_link_hash_entry
*h2
1298 = (struct elf_link_hash_entry
*) ptr2
;
1300 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1303 /* Find and/or create a hash entry for local symbol. */
1305 static struct elf_link_hash_entry
*
1306 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
1307 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1310 struct elf_x86_64_link_hash_entry e
, *ret
;
1311 asection
*sec
= abfd
->sections
;
1312 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1313 htab
->r_sym (rel
->r_info
));
1316 e
.elf
.indx
= sec
->id
;
1317 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1318 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1319 create
? INSERT
: NO_INSERT
);
1326 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1330 ret
= (struct elf_x86_64_link_hash_entry
*)
1331 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1332 sizeof (struct elf_x86_64_link_hash_entry
));
1335 memset (ret
, 0, sizeof (*ret
));
1336 ret
->elf
.indx
= sec
->id
;
1337 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1338 ret
->elf
.dynindx
= -1;
1339 ret
->func_pointer_refcount
= 0;
1340 ret
->plt_got
.offset
= (bfd_vma
) -1;
1346 /* Destroy an X86-64 ELF linker hash table. */
1349 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1351 struct elf_x86_64_link_hash_table
*htab
1352 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1354 if (htab
->loc_hash_table
)
1355 htab_delete (htab
->loc_hash_table
);
1356 if (htab
->loc_hash_memory
)
1357 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1358 _bfd_elf_link_hash_table_free (obfd
);
1361 /* Create an X86-64 ELF linker hash table. */
1363 static struct bfd_link_hash_table
*
1364 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1366 struct elf_x86_64_link_hash_table
*ret
;
1367 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1369 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1373 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1374 elf_x86_64_link_hash_newfunc
,
1375 sizeof (struct elf_x86_64_link_hash_entry
),
1382 if (ABI_64_P (abfd
))
1384 ret
->r_info
= elf64_r_info
;
1385 ret
->r_sym
= elf64_r_sym
;
1386 ret
->pointer_r_type
= R_X86_64_64
;
1387 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1388 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1392 ret
->r_info
= elf32_r_info
;
1393 ret
->r_sym
= elf32_r_sym
;
1394 ret
->pointer_r_type
= R_X86_64_32
;
1395 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1396 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1399 ret
->loc_hash_table
= htab_try_create (1024,
1400 elf_x86_64_local_htab_hash
,
1401 elf_x86_64_local_htab_eq
,
1403 ret
->loc_hash_memory
= objalloc_create ();
1404 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1406 elf_x86_64_link_hash_table_free (abfd
);
1409 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1411 return &ret
->elf
.root
;
1414 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1417 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1418 struct elf_link_hash_entry
*dir
,
1419 struct elf_link_hash_entry
*ind
)
1421 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1423 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1424 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1426 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1427 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1429 if (eind
->dyn_relocs
!= NULL
)
1431 if (edir
->dyn_relocs
!= NULL
)
1433 struct elf_dyn_relocs
**pp
;
1434 struct elf_dyn_relocs
*p
;
1436 /* Add reloc counts against the indirect sym to the direct sym
1437 list. Merge any entries against the same section. */
1438 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1440 struct elf_dyn_relocs
*q
;
1442 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1443 if (q
->sec
== p
->sec
)
1445 q
->pc_count
+= p
->pc_count
;
1446 q
->count
+= p
->count
;
1453 *pp
= edir
->dyn_relocs
;
1456 edir
->dyn_relocs
= eind
->dyn_relocs
;
1457 eind
->dyn_relocs
= NULL
;
1460 if (ind
->root
.type
== bfd_link_hash_indirect
1461 && dir
->got
.refcount
<= 0)
1463 edir
->tls_type
= eind
->tls_type
;
1464 eind
->tls_type
= GOT_UNKNOWN
;
1467 if (ELIMINATE_COPY_RELOCS
1468 && ind
->root
.type
!= bfd_link_hash_indirect
1469 && dir
->dynamic_adjusted
)
1471 /* If called to transfer flags for a weakdef during processing
1472 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1473 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1474 if (dir
->versioned
!= versioned_hidden
)
1475 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1476 dir
->ref_regular
|= ind
->ref_regular
;
1477 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1478 dir
->needs_plt
|= ind
->needs_plt
;
1479 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1483 if (eind
->func_pointer_refcount
> 0)
1485 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1486 eind
->func_pointer_refcount
= 0;
1489 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1494 elf64_x86_64_elf_object_p (bfd
*abfd
)
1496 /* Set the right machine number for an x86-64 elf64 file. */
1497 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1502 elf32_x86_64_elf_object_p (bfd
*abfd
)
1504 /* Set the right machine number for an x86-64 elf32 file. */
1505 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1509 /* Return TRUE if the TLS access code sequence support transition
1513 elf_x86_64_check_tls_transition (bfd
*abfd
,
1514 struct bfd_link_info
*info
,
1517 Elf_Internal_Shdr
*symtab_hdr
,
1518 struct elf_link_hash_entry
**sym_hashes
,
1519 unsigned int r_type
,
1520 const Elf_Internal_Rela
*rel
,
1521 const Elf_Internal_Rela
*relend
)
1524 unsigned long r_symndx
;
1525 bfd_boolean largepic
= FALSE
;
1526 struct elf_link_hash_entry
*h
;
1528 struct elf_x86_64_link_hash_table
*htab
;
1530 bfd_boolean indirect_call
, tls_get_addr
;
1532 htab
= elf_x86_64_hash_table (info
);
1533 offset
= rel
->r_offset
;
1536 case R_X86_64_TLSGD
:
1537 case R_X86_64_TLSLD
:
1538 if ((rel
+ 1) >= relend
)
1541 if (r_type
== R_X86_64_TLSGD
)
1543 /* Check transition from GD access model. For 64bit, only
1544 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1545 .word 0x6666; rex64; call __tls_get_addr@PLT
1547 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1549 call *__tls_get_addr@GOTPCREL(%rip)
1550 which may be converted to
1551 addr32 call __tls_get_addr
1552 can transit to different access model. For 32bit, only
1553 leaq foo@tlsgd(%rip), %rdi
1554 .word 0x6666; rex64; call __tls_get_addr@PLT
1556 leaq foo@tlsgd(%rip), %rdi
1558 call *__tls_get_addr@GOTPCREL(%rip)
1559 which may be converted to
1560 addr32 call __tls_get_addr
1561 can transit to different access model. For largepic,
1563 leaq foo@tlsgd(%rip), %rdi
1564 movabsq $__tls_get_addr@pltoff, %rax
1568 leaq foo@tlsgd(%rip), %rdi
1569 movabsq $__tls_get_addr@pltoff, %rax
1573 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1575 if ((offset
+ 12) > sec
->size
)
1578 call
= contents
+ offset
+ 4;
1580 || !((call
[1] == 0x48
1588 && call
[3] == 0xe8)))
1590 if (!ABI_64_P (abfd
)
1591 || (offset
+ 19) > sec
->size
1593 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1594 || memcmp (call
, "\x48\xb8", 2) != 0
1598 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1599 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1603 else if (ABI_64_P (abfd
))
1606 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1612 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1615 indirect_call
= call
[2] == 0xff;
1619 /* Check transition from LD access model. Only
1620 leaq foo@tlsld(%rip), %rdi;
1621 call __tls_get_addr@PLT
1623 leaq foo@tlsld(%rip), %rdi;
1624 call *__tls_get_addr@GOTPCREL(%rip)
1625 which may be converted to
1626 addr32 call __tls_get_addr
1627 can transit to different access model. For largepic
1629 leaq foo@tlsld(%rip), %rdi
1630 movabsq $__tls_get_addr@pltoff, %rax
1634 leaq foo@tlsld(%rip), %rdi
1635 movabsq $__tls_get_addr@pltoff, %rax
1639 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1641 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1644 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1647 call
= contents
+ offset
+ 4;
1648 if (!(call
[0] == 0xe8
1649 || (call
[0] == 0xff && call
[1] == 0x15)
1650 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1652 if (!ABI_64_P (abfd
)
1653 || (offset
+ 19) > sec
->size
1654 || memcmp (call
, "\x48\xb8", 2) != 0
1658 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1659 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1663 indirect_call
= call
[0] == 0xff;
1666 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1667 if (r_symndx
< symtab_hdr
->sh_info
)
1670 tls_get_addr
= FALSE
;
1671 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1672 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1674 struct elf_x86_64_link_hash_entry
*eh
1675 = (struct elf_x86_64_link_hash_entry
*) h
;
1676 tls_get_addr
= eh
->tls_get_addr
== 1;
1677 if (eh
->tls_get_addr
> 1)
1679 /* Use strncmp to check __tls_get_addr since
1680 __tls_get_addr may be versioned. */
1681 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1684 eh
->tls_get_addr
= 1;
1685 tls_get_addr
= TRUE
;
1688 eh
->tls_get_addr
= 0;
1695 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1696 else if (indirect_call
)
1697 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1699 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1700 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1702 case R_X86_64_GOTTPOFF
:
1703 /* Check transition from IE access model:
1704 mov foo@gottpoff(%rip), %reg
1705 add foo@gottpoff(%rip), %reg
1708 /* Check REX prefix first. */
1709 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1711 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1712 if (val
!= 0x48 && val
!= 0x4c)
1714 /* X32 may have 0x44 REX prefix or no REX prefix. */
1715 if (ABI_64_P (abfd
))
1721 /* X32 may not have any REX prefix. */
1722 if (ABI_64_P (abfd
))
1724 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1728 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1729 if (val
!= 0x8b && val
!= 0x03)
1732 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1733 return (val
& 0xc7) == 5;
1735 case R_X86_64_GOTPC32_TLSDESC
:
1736 /* Check transition from GDesc access model:
1737 leaq x@tlsdesc(%rip), %rax
1739 Make sure it's a leaq adding rip to a 32-bit offset
1740 into any register, although it's probably almost always
1743 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1746 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1747 if ((val
& 0xfb) != 0x48)
1750 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1753 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1754 return (val
& 0xc7) == 0x05;
1756 case R_X86_64_TLSDESC_CALL
:
1757 /* Check transition from GDesc access model:
1758 call *x@tlsdesc(%rax)
1760 if (offset
+ 2 <= sec
->size
)
1762 /* Make sure that it's a call *x@tlsdesc(%rax). */
1763 call
= contents
+ offset
;
1764 return call
[0] == 0xff && call
[1] == 0x10;
1774 /* Return TRUE if the TLS access transition is OK or no transition
1775 will be performed. Update R_TYPE if there is a transition. */
1778 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1779 asection
*sec
, bfd_byte
*contents
,
1780 Elf_Internal_Shdr
*symtab_hdr
,
1781 struct elf_link_hash_entry
**sym_hashes
,
1782 unsigned int *r_type
, int tls_type
,
1783 const Elf_Internal_Rela
*rel
,
1784 const Elf_Internal_Rela
*relend
,
1785 struct elf_link_hash_entry
*h
,
1786 unsigned long r_symndx
,
1787 bfd_boolean from_relocate_section
)
1789 unsigned int from_type
= *r_type
;
1790 unsigned int to_type
= from_type
;
1791 bfd_boolean check
= TRUE
;
1793 /* Skip TLS transition for functions. */
1795 && (h
->type
== STT_FUNC
1796 || h
->type
== STT_GNU_IFUNC
))
1801 case R_X86_64_TLSGD
:
1802 case R_X86_64_GOTPC32_TLSDESC
:
1803 case R_X86_64_TLSDESC_CALL
:
1804 case R_X86_64_GOTTPOFF
:
1805 if (bfd_link_executable (info
))
1808 to_type
= R_X86_64_TPOFF32
;
1810 to_type
= R_X86_64_GOTTPOFF
;
1813 /* When we are called from elf_x86_64_relocate_section, there may
1814 be additional transitions based on TLS_TYPE. */
1815 if (from_relocate_section
)
1817 unsigned int new_to_type
= to_type
;
1819 if (bfd_link_executable (info
)
1822 && tls_type
== GOT_TLS_IE
)
1823 new_to_type
= R_X86_64_TPOFF32
;
1825 if (to_type
== R_X86_64_TLSGD
1826 || to_type
== R_X86_64_GOTPC32_TLSDESC
1827 || to_type
== R_X86_64_TLSDESC_CALL
)
1829 if (tls_type
== GOT_TLS_IE
)
1830 new_to_type
= R_X86_64_GOTTPOFF
;
1833 /* We checked the transition before when we were called from
1834 elf_x86_64_check_relocs. We only want to check the new
1835 transition which hasn't been checked before. */
1836 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1837 to_type
= new_to_type
;
1842 case R_X86_64_TLSLD
:
1843 if (bfd_link_executable (info
))
1844 to_type
= R_X86_64_TPOFF32
;
1851 /* Return TRUE if there is no transition. */
1852 if (from_type
== to_type
)
1855 /* Check if the transition can be performed. */
1857 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1858 symtab_hdr
, sym_hashes
,
1859 from_type
, rel
, relend
))
1861 reloc_howto_type
*from
, *to
;
1864 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1865 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1868 name
= h
->root
.root
.string
;
1871 struct elf_x86_64_link_hash_table
*htab
;
1873 htab
= elf_x86_64_hash_table (info
);
1878 Elf_Internal_Sym
*isym
;
1880 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1882 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1887 /* xgettext:c-format */
1888 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1889 "in section `%A' failed"),
1890 abfd
, from
->name
, to
->name
, name
, rel
->r_offset
, sec
);
1891 bfd_set_error (bfd_error_bad_value
);
1899 /* Rename some of the generic section flags to better document how they
1901 #define need_convert_load sec_flg0
1902 #define check_relocs_failed sec_flg1
1905 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1906 struct elf_link_hash_entry
*h
,
1907 Elf_Internal_Shdr
*symtab_hdr
,
1908 Elf_Internal_Sym
*isym
,
1909 reloc_howto_type
*howto
)
1912 const char *und
= "";
1913 const char *pic
= "";
1918 name
= h
->root
.root
.string
;
1919 switch (ELF_ST_VISIBILITY (h
->other
))
1922 v
= _("hidden symbol ");
1925 v
= _("internal symbol ");
1928 v
= _("protected symbol ");
1932 pic
= _("; recompile with -fPIC");
1936 if (!h
->def_regular
&& !h
->def_dynamic
)
1937 und
= _("undefined ");
1941 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1942 pic
= _("; recompile with -fPIC");
1945 /* xgettext:c-format */
1946 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1947 "not be used when making a shared object%s"),
1948 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1949 bfd_set_error (bfd_error_bad_value
);
1950 sec
->check_relocs_failed
= 1;
1954 /* With the local symbol, foo, we convert
1955 mov foo@GOTPCREL(%rip), %reg
1959 call/jmp *foo@GOTPCREL(%rip)
1961 nop call foo/jmp foo nop
1962 When PIC is false, convert
1963 test %reg, foo@GOTPCREL(%rip)
1967 binop foo@GOTPCREL(%rip), %reg
1970 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1974 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1976 Elf_Internal_Rela
*irel
,
1977 struct elf_link_hash_entry
*h
,
1978 bfd_boolean
*converted
,
1979 struct bfd_link_info
*link_info
)
1981 struct elf_x86_64_link_hash_table
*htab
;
1983 bfd_boolean require_reloc_pc32
;
1985 bfd_boolean to_reloc_pc32
;
1988 bfd_signed_vma raddend
;
1989 unsigned int opcode
;
1991 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1992 unsigned int r_symndx
;
1994 bfd_vma roff
= irel
->r_offset
;
1996 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1999 raddend
= irel
->r_addend
;
2000 /* Addend for 32-bit PC-relative relocation must be -4. */
2004 htab
= elf_x86_64_hash_table (link_info
);
2005 is_pic
= bfd_link_pic (link_info
);
2007 relocx
= (r_type
== R_X86_64_GOTPCRELX
2008 || r_type
== R_X86_64_REX_GOTPCRELX
);
2010 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
2013 = link_info
->disable_target_specific_optimizations
> 1;
2015 r_symndx
= htab
->r_sym (irel
->r_info
);
2017 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
2019 /* Convert mov to lea since it has been done for a while. */
2022 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
2023 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
2024 test, xor instructions. */
2029 /* We convert only to R_X86_64_PC32:
2031 2. R_X86_64_GOTPCREL since we can't modify REX byte.
2032 3. require_reloc_pc32 is true.
2035 to_reloc_pc32
= (opcode
== 0xff
2037 || require_reloc_pc32
2040 /* Get the symbol referred to by the reloc. */
2043 Elf_Internal_Sym
*isym
2044 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
2046 /* Skip relocation against undefined symbols. */
2047 if (isym
->st_shndx
== SHN_UNDEF
)
2050 symtype
= ELF_ST_TYPE (isym
->st_info
);
2052 if (isym
->st_shndx
== SHN_ABS
)
2053 tsec
= bfd_abs_section_ptr
;
2054 else if (isym
->st_shndx
== SHN_COMMON
)
2055 tsec
= bfd_com_section_ptr
;
2056 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
2057 tsec
= &_bfd_elf_large_com_section
;
2059 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2061 toff
= isym
->st_value
;
2065 /* Undefined weak symbol is only bound locally in executable
2066 and its reference is resolved as 0 without relocation
2067 overflow. We can only perform this optimization for
2068 GOTPCRELX relocations since we need to modify REX byte.
2069 It is OK convert mov with R_X86_64_GOTPCREL to
2071 if ((relocx
|| opcode
== 0x8b)
2072 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
2074 elf_x86_64_hash_entry (h
)))
2078 /* Skip for branch instructions since R_X86_64_PC32
2080 if (require_reloc_pc32
)
2085 /* For non-branch instructions, we can convert to
2086 R_X86_64_32/R_X86_64_32S since we know if there
2088 to_reloc_pc32
= FALSE
;
2091 /* Since we don't know the current PC when PIC is true,
2092 we can't convert to R_X86_64_PC32. */
2093 if (to_reloc_pc32
&& is_pic
)
2098 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
2099 ld.so may use its link-time address. */
2100 else if (h
->start_stop
2102 || h
->root
.type
== bfd_link_hash_defined
2103 || h
->root
.type
== bfd_link_hash_defweak
)
2104 && h
!= htab
->elf
.hdynamic
2105 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
2107 /* bfd_link_hash_new or bfd_link_hash_undefined is
2108 set by an assignment in a linker script in
2109 bfd_elf_record_link_assignment. start_stop is set
2110 on __start_SECNAME/__stop_SECNAME which mark section
2114 && (h
->root
.type
== bfd_link_hash_new
2115 || h
->root
.type
== bfd_link_hash_undefined
2116 || ((h
->root
.type
== bfd_link_hash_defined
2117 || h
->root
.type
== bfd_link_hash_defweak
)
2118 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
2120 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
2121 if (require_reloc_pc32
)
2125 tsec
= h
->root
.u
.def
.section
;
2126 toff
= h
->root
.u
.def
.value
;
2133 /* Don't convert GOTPCREL relocation against large section. */
2134 if (elf_section_data (tsec
) != NULL
2135 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
2138 /* We can only estimate relocation overflow for R_X86_64_PC32. */
2142 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
2144 /* At this stage in linking, no SEC_MERGE symbol has been
2145 adjusted, so all references to such symbols need to be
2146 passed through _bfd_merged_section_offset. (Later, in
2147 relocate_section, all SEC_MERGE symbols *except* for
2148 section symbols have been adjusted.)
2150 gas may reduce relocations against symbols in SEC_MERGE
2151 sections to a relocation against the section symbol when
2152 the original addend was zero. When the reloc is against
2153 a section symbol we should include the addend in the
2154 offset passed to _bfd_merged_section_offset, since the
2155 location of interest is the original symbol. On the
2156 other hand, an access to "sym+addend" where "sym" is not
2157 a section symbol should not include the addend; Such an
2158 access is presumed to be an offset from "sym"; The
2159 location of interest is just "sym". */
2160 if (symtype
== STT_SECTION
)
2163 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
2164 elf_section_data (tsec
)->sec_info
,
2167 if (symtype
!= STT_SECTION
)
2173 /* Don't convert if R_X86_64_PC32 relocation overflows. */
2174 if (tsec
->output_section
== sec
->output_section
)
2176 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
2181 bfd_signed_vma distance
;
2183 /* At this point, we don't know the load addresses of TSEC
2184 section nor SEC section. We estimate the distrance between
2185 SEC and TSEC. We store the estimated distances in the
2186 compressed_size field of the output section, which is only
2187 used to decompress the compressed input section. */
2188 if (sec
->output_section
->compressed_size
== 0)
2191 bfd_size_type size
= 0;
2192 for (asect
= link_info
->output_bfd
->sections
;
2194 asect
= asect
->next
)
2195 /* Skip debug sections since compressed_size is used to
2196 compress debug sections. */
2197 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
2200 for (i
= asect
->map_head
.s
;
2204 size
= align_power (size
, i
->alignment_power
);
2207 asect
->compressed_size
= size
;
2211 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2213 distance
= (tsec
->output_section
->compressed_size
2214 - sec
->output_section
->compressed_size
);
2218 /* Take PT_GNU_RELRO segment into account by adding
2220 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
2221 - roff
+ 0x80000000) > 0xffffffff)
2228 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2233 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2235 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2238 /* Convert to "jmp foo nop". */
2241 nop_offset
= irel
->r_offset
+ 3;
2242 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2243 irel
->r_offset
-= 1;
2244 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2248 struct elf_x86_64_link_hash_entry
*eh
2249 = (struct elf_x86_64_link_hash_entry
*) h
;
2251 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2254 /* To support TLS optimization, always use addr32 prefix for
2255 "call *__tls_get_addr@GOTPCREL(%rip)". */
2256 if (eh
&& eh
->tls_get_addr
== 1)
2259 nop_offset
= irel
->r_offset
- 2;
2263 nop
= link_info
->call_nop_byte
;
2264 if (link_info
->call_nop_as_suffix
)
2266 nop_offset
= irel
->r_offset
+ 3;
2267 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2268 irel
->r_offset
-= 1;
2269 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2272 nop_offset
= irel
->r_offset
- 2;
2275 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2276 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2277 r_type
= R_X86_64_PC32
;
2282 unsigned int rex_mask
= REX_R
;
2284 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2285 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2293 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2294 "lea foo(%rip), %reg". */
2296 r_type
= R_X86_64_PC32
;
2300 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2301 "mov $foo, %reg". */
2303 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2304 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2305 if ((rex
& REX_W
) != 0
2306 && ABI_64_P (link_info
->output_bfd
))
2308 /* Keep the REX_W bit in REX byte for LP64. */
2309 r_type
= R_X86_64_32S
;
2310 goto rewrite_modrm_rex
;
2314 /* If the REX_W bit in REX byte isn't needed,
2315 use R_X86_64_32 and clear the W bit to avoid
2316 sign-extend imm32 to imm64. */
2317 r_type
= R_X86_64_32
;
2318 /* Clear the W bit in REX byte. */
2320 goto rewrite_modrm_rex
;
2326 /* R_X86_64_PC32 isn't supported. */
2330 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2333 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2334 "test $foo, %reg". */
2335 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2340 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2341 "binop $foo, %reg". */
2342 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2346 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2347 overflow when sign-extending imm32 to imm64. */
2348 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2351 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2355 /* Move the R bit to the B bit in REX byte. */
2356 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2357 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2360 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2364 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2367 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2374 /* Look through the relocs for a section during the first phase, and
2375 calculate needed space in the global offset table, procedure
2376 linkage table, and dynamic reloc sections. */
2379 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2381 const Elf_Internal_Rela
*relocs
)
2383 struct elf_x86_64_link_hash_table
*htab
;
2384 Elf_Internal_Shdr
*symtab_hdr
;
2385 struct elf_link_hash_entry
**sym_hashes
;
2386 const Elf_Internal_Rela
*rel
;
2387 const Elf_Internal_Rela
*rel_end
;
2391 if (bfd_link_relocatable (info
))
2394 /* Don't do anything special with non-loaded, non-alloced sections.
2395 In particular, any relocs in such sections should not affect GOT
2396 and PLT reference counting (ie. we don't allow them to create GOT
2397 or PLT entries), there's no possibility or desire to optimize TLS
2398 relocs, and there's not much point in propagating relocs to shared
2399 libs that the dynamic linker won't relocate. */
2400 if ((sec
->flags
& SEC_ALLOC
) == 0)
2403 BFD_ASSERT (is_x86_64_elf (abfd
));
2405 htab
= elf_x86_64_hash_table (info
);
2408 sec
->check_relocs_failed
= 1;
2412 /* Get the section contents. */
2413 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2414 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2415 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2417 sec
->check_relocs_failed
= 1;
2421 symtab_hdr
= &elf_symtab_hdr (abfd
);
2422 sym_hashes
= elf_sym_hashes (abfd
);
2426 rel_end
= relocs
+ sec
->reloc_count
;
2427 for (rel
= relocs
; rel
< rel_end
; rel
++)
2429 unsigned int r_type
;
2430 unsigned int r_symndx
;
2431 struct elf_link_hash_entry
*h
;
2432 struct elf_x86_64_link_hash_entry
*eh
;
2433 Elf_Internal_Sym
*isym
;
2435 bfd_boolean size_reloc
;
2437 r_symndx
= htab
->r_sym (rel
->r_info
);
2438 r_type
= ELF32_R_TYPE (rel
->r_info
);
2440 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2442 /* xgettext:c-format */
2443 _bfd_error_handler (_("%B: bad symbol index: %d"),
2448 if (r_symndx
< symtab_hdr
->sh_info
)
2450 /* A local symbol. */
2451 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2456 /* Check relocation against local STT_GNU_IFUNC symbol. */
2457 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2459 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2464 /* Fake a STT_GNU_IFUNC symbol. */
2465 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2467 h
->type
= STT_GNU_IFUNC
;
2470 h
->forced_local
= 1;
2471 h
->root
.type
= bfd_link_hash_defined
;
2479 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2480 while (h
->root
.type
== bfd_link_hash_indirect
2481 || h
->root
.type
== bfd_link_hash_warning
)
2482 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2485 /* Check invalid x32 relocations. */
2486 if (!ABI_64_P (abfd
))
2492 case R_X86_64_DTPOFF64
:
2493 case R_X86_64_TPOFF64
:
2495 case R_X86_64_GOTOFF64
:
2496 case R_X86_64_GOT64
:
2497 case R_X86_64_GOTPCREL64
:
2498 case R_X86_64_GOTPC64
:
2499 case R_X86_64_GOTPLT64
:
2500 case R_X86_64_PLTOFF64
:
2503 name
= h
->root
.root
.string
;
2505 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2508 /* xgettext:c-format */
2509 (_("%B: relocation %s against symbol `%s' isn't "
2510 "supported in x32 mode"), abfd
,
2511 x86_64_elf_howto_table
[r_type
].name
, name
);
2512 bfd_set_error (bfd_error_bad_value
);
2520 /* It is referenced by a non-shared object. */
2522 h
->root
.non_ir_ref_regular
= 1;
2524 if (h
->type
== STT_GNU_IFUNC
)
2525 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2526 |= elf_gnu_symbol_ifunc
;
2529 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2530 symtab_hdr
, sym_hashes
,
2531 &r_type
, GOT_UNKNOWN
,
2532 rel
, rel_end
, h
, r_symndx
, FALSE
))
2535 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2538 case R_X86_64_TLSLD
:
2539 htab
->tls_ld_got
.refcount
+= 1;
2542 case R_X86_64_TPOFF32
:
2543 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2544 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2545 &x86_64_elf_howto_table
[r_type
]);
2547 eh
->has_got_reloc
= 1;
2550 case R_X86_64_GOTTPOFF
:
2551 if (!bfd_link_executable (info
))
2552 info
->flags
|= DF_STATIC_TLS
;
2555 case R_X86_64_GOT32
:
2556 case R_X86_64_GOTPCREL
:
2557 case R_X86_64_GOTPCRELX
:
2558 case R_X86_64_REX_GOTPCRELX
:
2559 case R_X86_64_TLSGD
:
2560 case R_X86_64_GOT64
:
2561 case R_X86_64_GOTPCREL64
:
2562 case R_X86_64_GOTPLT64
:
2563 case R_X86_64_GOTPC32_TLSDESC
:
2564 case R_X86_64_TLSDESC_CALL
:
2565 /* This symbol requires a global offset table entry. */
2567 int tls_type
, old_tls_type
;
2571 default: tls_type
= GOT_NORMAL
; break;
2572 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2573 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2574 case R_X86_64_GOTPC32_TLSDESC
:
2575 case R_X86_64_TLSDESC_CALL
:
2576 tls_type
= GOT_TLS_GDESC
; break;
2581 h
->got
.refcount
+= 1;
2582 old_tls_type
= eh
->tls_type
;
2586 bfd_signed_vma
*local_got_refcounts
;
2588 /* This is a global offset table entry for a local symbol. */
2589 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2590 if (local_got_refcounts
== NULL
)
2594 size
= symtab_hdr
->sh_info
;
2595 size
*= sizeof (bfd_signed_vma
)
2596 + sizeof (bfd_vma
) + sizeof (char);
2597 local_got_refcounts
= ((bfd_signed_vma
*)
2598 bfd_zalloc (abfd
, size
));
2599 if (local_got_refcounts
== NULL
)
2601 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2602 elf_x86_64_local_tlsdesc_gotent (abfd
)
2603 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2604 elf_x86_64_local_got_tls_type (abfd
)
2605 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2607 local_got_refcounts
[r_symndx
] += 1;
2609 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2612 /* If a TLS symbol is accessed using IE at least once,
2613 there is no point to use dynamic model for it. */
2614 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2615 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2616 || tls_type
!= GOT_TLS_IE
))
2618 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2619 tls_type
= old_tls_type
;
2620 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2621 && GOT_TLS_GD_ANY_P (tls_type
))
2622 tls_type
|= old_tls_type
;
2626 name
= h
->root
.root
.string
;
2628 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2631 /* xgettext:c-format */
2632 (_("%B: '%s' accessed both as normal and"
2633 " thread local symbol"),
2635 bfd_set_error (bfd_error_bad_value
);
2640 if (old_tls_type
!= tls_type
)
2643 eh
->tls_type
= tls_type
;
2645 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2650 case R_X86_64_GOTOFF64
:
2651 case R_X86_64_GOTPC32
:
2652 case R_X86_64_GOTPC64
:
2655 eh
->has_got_reloc
= 1;
2658 case R_X86_64_PLT32
:
2659 case R_X86_64_PLT32_BND
:
2660 /* This symbol requires a procedure linkage table entry. We
2661 actually build the entry in adjust_dynamic_symbol,
2662 because this might be a case of linking PIC code which is
2663 never referenced by a dynamic object, in which case we
2664 don't need to generate a procedure linkage table entry
2667 /* If this is a local symbol, we resolve it directly without
2668 creating a procedure linkage table entry. */
2672 eh
->has_got_reloc
= 1;
2674 h
->plt
.refcount
+= 1;
2677 case R_X86_64_PLTOFF64
:
2678 /* This tries to form the 'address' of a function relative
2679 to GOT. For global symbols we need a PLT entry. */
2683 h
->plt
.refcount
+= 1;
2687 case R_X86_64_SIZE32
:
2688 case R_X86_64_SIZE64
:
2693 if (!ABI_64_P (abfd
))
2699 /* Check relocation overflow as these relocs may lead to
2700 run-time relocation overflow. Don't error out for
2701 sections we don't care about, such as debug sections or
2702 when relocation overflow check is disabled. */
2703 if (!info
->no_reloc_overflow_check
2704 && (bfd_link_pic (info
)
2705 || (bfd_link_executable (info
)
2709 && (sec
->flags
& SEC_READONLY
) == 0)))
2710 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2711 &x86_64_elf_howto_table
[r_type
]);
2717 case R_X86_64_PC32_BND
:
2721 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2722 eh
->has_non_got_reloc
= 1;
2723 /* We are called after all symbols have been resolved. Only
2724 relocation against STT_GNU_IFUNC symbol must go through
2727 && (bfd_link_executable (info
)
2728 || h
->type
== STT_GNU_IFUNC
))
2730 /* If this reloc is in a read-only section, we might
2731 need a copy reloc. We can't check reliably at this
2732 stage whether the section is read-only, as input
2733 sections have not yet been mapped to output sections.
2734 Tentatively set the flag for now, and correct in
2735 adjust_dynamic_symbol. */
2738 /* We may need a .plt entry if the symbol is a function
2739 defined in a shared lib or is a STT_GNU_IFUNC function
2740 referenced from the code or read-only section. */
2742 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2743 h
->plt
.refcount
+= 1;
2745 if (r_type
== R_X86_64_PC32
)
2747 /* Since something like ".long foo - ." may be used
2748 as pointer, make sure that PLT is used if foo is
2749 a function defined in a shared library. */
2750 if ((sec
->flags
& SEC_CODE
) == 0)
2751 h
->pointer_equality_needed
= 1;
2753 else if (r_type
!= R_X86_64_PC32_BND
2754 && r_type
!= R_X86_64_PC64
)
2756 h
->pointer_equality_needed
= 1;
2757 /* At run-time, R_X86_64_64 can be resolved for both
2758 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2759 can only be resolved for x32. */
2760 if ((sec
->flags
& SEC_READONLY
) == 0
2761 && (r_type
== R_X86_64_64
2762 || (!ABI_64_P (abfd
)
2763 && (r_type
== R_X86_64_32
2764 || r_type
== R_X86_64_32S
))))
2765 eh
->func_pointer_refcount
+= 1;
2771 /* If we are creating a shared library, and this is a reloc
2772 against a global symbol, or a non PC relative reloc
2773 against a local symbol, then we need to copy the reloc
2774 into the shared library. However, if we are linking with
2775 -Bsymbolic, we do not need to copy a reloc against a
2776 global symbol which is defined in an object we are
2777 including in the link (i.e., DEF_REGULAR is set). At
2778 this point we have not seen all the input files, so it is
2779 possible that DEF_REGULAR is not set now but will be set
2780 later (it is never cleared). In case of a weak definition,
2781 DEF_REGULAR may be cleared later by a strong definition in
2782 a shared library. We account for that possibility below by
2783 storing information in the relocs_copied field of the hash
2784 table entry. A similar situation occurs when creating
2785 shared libraries and symbol visibility changes render the
2788 If on the other hand, we are creating an executable, we
2789 may need to keep relocations for symbols satisfied by a
2790 dynamic library if we manage to avoid copy relocs for the
2793 Generate dynamic pointer relocation against STT_GNU_IFUNC
2794 symbol in the non-code section. */
2795 if ((bfd_link_pic (info
)
2796 && (! IS_X86_64_PCREL_TYPE (r_type
)
2798 && (! (bfd_link_pie (info
)
2799 || SYMBOLIC_BIND (info
, h
))
2800 || h
->root
.type
== bfd_link_hash_defweak
2801 || !h
->def_regular
))))
2803 && h
->type
== STT_GNU_IFUNC
2804 && r_type
== htab
->pointer_r_type
2805 && (sec
->flags
& SEC_CODE
) == 0)
2806 || (ELIMINATE_COPY_RELOCS
2807 && !bfd_link_pic (info
)
2809 && (h
->root
.type
== bfd_link_hash_defweak
2810 || !h
->def_regular
)))
2812 struct elf_dyn_relocs
*p
;
2813 struct elf_dyn_relocs
**head
;
2815 /* We must copy these reloc types into the output file.
2816 Create a reloc section in dynobj and make room for
2820 sreloc
= _bfd_elf_make_dynamic_reloc_section
2821 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2822 abfd
, /*rela?*/ TRUE
);
2828 /* If this is a global symbol, we count the number of
2829 relocations we need for this symbol. */
2831 head
= &eh
->dyn_relocs
;
2834 /* Track dynamic relocs needed for local syms too.
2835 We really need local syms available to do this
2840 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2845 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2849 /* Beware of type punned pointers vs strict aliasing
2851 vpp
= &(elf_section_data (s
)->local_dynrel
);
2852 head
= (struct elf_dyn_relocs
**)vpp
;
2856 if (p
== NULL
|| p
->sec
!= sec
)
2858 bfd_size_type amt
= sizeof *p
;
2860 p
= ((struct elf_dyn_relocs
*)
2861 bfd_alloc (htab
->elf
.dynobj
, amt
));
2872 /* Count size relocation as PC-relative relocation. */
2873 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2878 /* This relocation describes the C++ object vtable hierarchy.
2879 Reconstruct it for later use during GC. */
2880 case R_X86_64_GNU_VTINHERIT
:
2881 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2885 /* This relocation describes which C++ vtable entries are actually
2886 used. Record for later use during GC. */
2887 case R_X86_64_GNU_VTENTRY
:
2888 BFD_ASSERT (h
!= NULL
);
2890 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2898 if ((r_type
== R_X86_64_GOTPCREL
2899 || r_type
== R_X86_64_GOTPCRELX
2900 || r_type
== R_X86_64_REX_GOTPCRELX
)
2901 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2902 sec
->need_convert_load
= 1;
2905 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2907 if (!info
->keep_memory
)
2911 /* Cache the section contents for elf_link_input_bfd. */
2912 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2919 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2921 sec
->check_relocs_failed
= 1;
2925 /* Return the section that should be marked against GC for a given
2929 elf_x86_64_gc_mark_hook (asection
*sec
,
2930 struct bfd_link_info
*info
,
2931 Elf_Internal_Rela
*rel
,
2932 struct elf_link_hash_entry
*h
,
2933 Elf_Internal_Sym
*sym
)
2936 switch (ELF32_R_TYPE (rel
->r_info
))
2938 case R_X86_64_GNU_VTINHERIT
:
2939 case R_X86_64_GNU_VTENTRY
:
2943 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2946 /* Remove undefined weak symbol from the dynamic symbol table if it
2947 is resolved to 0. */
2950 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2951 struct elf_link_hash_entry
*h
)
2953 if (h
->dynindx
!= -1
2954 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2955 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2956 elf_x86_64_hash_entry (h
)))
2959 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2965 /* Adjust a symbol defined by a dynamic object and referenced by a
2966 regular object. The current definition is in some section of the
2967 dynamic object, but we're not including those sections. We have to
2968 change the definition to something the rest of the link can
2972 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2973 struct elf_link_hash_entry
*h
)
2975 struct elf_x86_64_link_hash_table
*htab
;
2977 struct elf_x86_64_link_hash_entry
*eh
;
2978 struct elf_dyn_relocs
*p
;
2980 /* STT_GNU_IFUNC symbol must go through PLT. */
2981 if (h
->type
== STT_GNU_IFUNC
)
2983 /* All local STT_GNU_IFUNC references must be treate as local
2984 calls via local PLT. */
2986 && SYMBOL_CALLS_LOCAL (info
, h
))
2988 bfd_size_type pc_count
= 0, count
= 0;
2989 struct elf_dyn_relocs
**pp
;
2991 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2992 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2994 pc_count
+= p
->pc_count
;
2995 p
->count
-= p
->pc_count
;
3004 if (pc_count
|| count
)
3009 /* Increment PLT reference count only for PC-relative
3012 if (h
->plt
.refcount
<= 0)
3013 h
->plt
.refcount
= 1;
3015 h
->plt
.refcount
+= 1;
3020 if (h
->plt
.refcount
<= 0)
3022 h
->plt
.offset
= (bfd_vma
) -1;
3028 /* If this is a function, put it in the procedure linkage table. We
3029 will fill in the contents of the procedure linkage table later,
3030 when we know the address of the .got section. */
3031 if (h
->type
== STT_FUNC
3034 if (h
->plt
.refcount
<= 0
3035 || SYMBOL_CALLS_LOCAL (info
, h
)
3036 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3037 && h
->root
.type
== bfd_link_hash_undefweak
))
3039 /* This case can occur if we saw a PLT32 reloc in an input
3040 file, but the symbol was never referred to by a dynamic
3041 object, or if all references were garbage collected. In
3042 such a case, we don't actually need to build a procedure
3043 linkage table, and we can just do a PC32 reloc instead. */
3044 h
->plt
.offset
= (bfd_vma
) -1;
3051 /* It's possible that we incorrectly decided a .plt reloc was
3052 needed for an R_X86_64_PC32 reloc to a non-function sym in
3053 check_relocs. We can't decide accurately between function and
3054 non-function syms in check-relocs; Objects loaded later in
3055 the link may change h->type. So fix it now. */
3056 h
->plt
.offset
= (bfd_vma
) -1;
3058 /* If this is a weak symbol, and there is a real definition, the
3059 processor independent code will have arranged for us to see the
3060 real definition first, and we can just use the same value. */
3061 if (h
->u
.weakdef
!= NULL
)
3063 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3064 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3065 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3066 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3067 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
3069 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3070 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3071 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
3076 /* This is a reference to a symbol defined by a dynamic object which
3077 is not a function. */
3079 /* If we are creating a shared library, we must presume that the
3080 only references to the symbol are via the global offset table.
3081 For such cases we need not do anything here; the relocations will
3082 be handled correctly by relocate_section. */
3083 if (!bfd_link_executable (info
))
3086 /* If there are no references to this symbol that do not use the
3087 GOT, we don't need to generate a copy reloc. */
3088 if (!h
->non_got_ref
)
3091 /* If -z nocopyreloc was given, we won't generate them either. */
3092 if (info
->nocopyreloc
)
3098 if (ELIMINATE_COPY_RELOCS
)
3100 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3101 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3103 s
= p
->sec
->output_section
;
3104 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3108 /* If we didn't find any dynamic relocs in read-only sections, then
3109 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3117 /* We must allocate the symbol in our .dynbss section, which will
3118 become part of the .bss section of the executable. There will be
3119 an entry for this symbol in the .dynsym section. The dynamic
3120 object will contain position independent code, so all references
3121 from the dynamic object to this symbol will go through the global
3122 offset table. The dynamic linker will use the .dynsym entry to
3123 determine the address it must put in the global offset table, so
3124 both the dynamic object and the regular object will refer to the
3125 same memory location for the variable. */
3127 htab
= elf_x86_64_hash_table (info
);
3131 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
3132 to copy the initial value out of the dynamic object and into the
3133 runtime process image. */
3134 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3136 s
= htab
->elf
.sdynrelro
;
3137 srel
= htab
->elf
.sreldynrelro
;
3141 s
= htab
->elf
.sdynbss
;
3142 srel
= htab
->elf
.srelbss
;
3144 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3146 const struct elf_backend_data
*bed
;
3147 bed
= get_elf_backend_data (info
->output_bfd
);
3148 srel
->size
+= bed
->s
->sizeof_rela
;
3152 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3155 /* Allocate space in .plt, .got and associated reloc sections for
3159 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3161 struct bfd_link_info
*info
;
3162 struct elf_x86_64_link_hash_table
*htab
;
3163 struct elf_x86_64_link_hash_entry
*eh
;
3164 struct elf_dyn_relocs
*p
;
3165 const struct elf_backend_data
*bed
;
3166 unsigned int plt_entry_size
;
3167 bfd_boolean resolved_to_zero
;
3169 if (h
->root
.type
== bfd_link_hash_indirect
)
3172 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3174 info
= (struct bfd_link_info
*) inf
;
3175 htab
= elf_x86_64_hash_table (info
);
3178 bed
= get_elf_backend_data (info
->output_bfd
);
3179 plt_entry_size
= htab
->plt
.plt_entry_size
;
3181 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3185 /* We can't use the GOT PLT if pointer equality is needed since
3186 finish_dynamic_symbol won't clear symbol value and the dynamic
3187 linker won't update the GOT slot. We will get into an infinite
3188 loop at run-time. */
3189 if (htab
->plt_got
!= NULL
3190 && h
->type
!= STT_GNU_IFUNC
3191 && !h
->pointer_equality_needed
3192 && h
->plt
.refcount
> 0
3193 && h
->got
.refcount
> 0)
3195 /* Don't use the regular PLT if there are both GOT and GOTPLT
3197 h
->plt
.offset
= (bfd_vma
) -1;
3199 /* Use the GOT PLT. */
3200 eh
->plt_got
.refcount
= 1;
3203 /* Clear the reference count of function pointer relocations if
3204 symbol isn't a normal function. */
3205 if (h
->type
!= STT_FUNC
)
3206 eh
->func_pointer_refcount
= 0;
3208 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3209 here if it is defined and referenced in a non-shared object. */
3210 if (h
->type
== STT_GNU_IFUNC
3213 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3215 &htab
->readonly_dynrelocs_against_ifunc
,
3219 GOT_ENTRY_SIZE
, TRUE
))
3221 asection
*s
= htab
->plt_second
;
3222 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3224 /* Use the second PLT section if it is created. */
3225 eh
->plt_second
.offset
= s
->size
;
3227 /* Make room for this entry in the second PLT section. */
3228 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3236 /* Don't create the PLT entry if there are only function pointer
3237 relocations which can be resolved at run-time. */
3238 else if (htab
->elf
.dynamic_sections_created
3239 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3240 || eh
->plt_got
.refcount
> 0))
3242 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
3244 /* Clear the reference count of function pointer relocations
3246 eh
->func_pointer_refcount
= 0;
3248 /* Make sure this symbol is output as a dynamic symbol.
3249 Undefined weak syms won't yet be marked as dynamic. */
3250 if (h
->dynindx
== -1
3252 && !resolved_to_zero
3253 && h
->root
.type
== bfd_link_hash_undefweak
)
3255 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3259 if (bfd_link_pic (info
)
3260 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3262 asection
*s
= htab
->elf
.splt
;
3263 asection
*second_s
= htab
->plt_second
;
3264 asection
*got_s
= htab
->plt_got
;
3266 /* If this is the first .plt entry, make room for the special
3267 first entry. The .plt section is used by prelink to undo
3268 prelinking for dynamic relocations. */
3270 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
3273 eh
->plt_got
.offset
= got_s
->size
;
3276 h
->plt
.offset
= s
->size
;
3278 eh
->plt_second
.offset
= second_s
->size
;
3281 /* If this symbol is not defined in a regular file, and we are
3282 not generating a shared library, then set the symbol to this
3283 location in the .plt. This is required to make function
3284 pointers compare as equal between the normal executable and
3285 the shared library. */
3286 if (! bfd_link_pic (info
)
3291 /* We need to make a call to the entry of the GOT PLT
3292 instead of regular PLT entry. */
3293 h
->root
.u
.def
.section
= got_s
;
3294 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3300 /* We need to make a call to the entry of the
3301 second PLT instead of regular PLT entry. */
3302 h
->root
.u
.def
.section
= second_s
;
3303 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
3307 h
->root
.u
.def
.section
= s
;
3308 h
->root
.u
.def
.value
= h
->plt
.offset
;
3313 /* Make room for this entry. */
3315 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3318 s
->size
+= plt_entry_size
;
3320 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3322 /* We also need to make an entry in the .got.plt section,
3323 which will be placed in the .got section by the linker
3325 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3327 /* There should be no PLT relocation against resolved
3328 undefined weak symbol in executable. */
3329 if (!resolved_to_zero
)
3331 /* We also need to make an entry in the .rela.plt
3333 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3334 htab
->elf
.srelplt
->reloc_count
++;
3340 eh
->plt_got
.offset
= (bfd_vma
) -1;
3341 h
->plt
.offset
= (bfd_vma
) -1;
3347 eh
->plt_got
.offset
= (bfd_vma
) -1;
3348 h
->plt
.offset
= (bfd_vma
) -1;
3352 eh
->tlsdesc_got
= (bfd_vma
) -1;
3354 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3355 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3356 if (h
->got
.refcount
> 0
3357 && bfd_link_executable (info
)
3359 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3361 h
->got
.offset
= (bfd_vma
) -1;
3363 else if (h
->got
.refcount
> 0)
3367 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3369 /* Make sure this symbol is output as a dynamic symbol.
3370 Undefined weak syms won't yet be marked as dynamic. */
3371 if (h
->dynindx
== -1
3373 && !resolved_to_zero
3374 && h
->root
.type
== bfd_link_hash_undefweak
)
3376 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3380 if (GOT_TLS_GDESC_P (tls_type
))
3382 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3383 - elf_x86_64_compute_jump_table_size (htab
);
3384 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3385 h
->got
.offset
= (bfd_vma
) -2;
3387 if (! GOT_TLS_GDESC_P (tls_type
)
3388 || GOT_TLS_GD_P (tls_type
))
3391 h
->got
.offset
= s
->size
;
3392 s
->size
+= GOT_ENTRY_SIZE
;
3393 if (GOT_TLS_GD_P (tls_type
))
3394 s
->size
+= GOT_ENTRY_SIZE
;
3396 dyn
= htab
->elf
.dynamic_sections_created
;
3397 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3398 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3399 relocation. No dynamic relocation against resolved undefined
3400 weak symbol in executable. */
3401 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3402 || tls_type
== GOT_TLS_IE
)
3403 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3404 else if (GOT_TLS_GD_P (tls_type
))
3405 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3406 else if (! GOT_TLS_GDESC_P (tls_type
)
3407 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3408 && !resolved_to_zero
)
3409 || h
->root
.type
!= bfd_link_hash_undefweak
)
3410 && (bfd_link_pic (info
)
3411 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3412 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3413 if (GOT_TLS_GDESC_P (tls_type
))
3415 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3416 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3420 h
->got
.offset
= (bfd_vma
) -1;
3422 if (eh
->dyn_relocs
== NULL
)
3425 /* In the shared -Bsymbolic case, discard space allocated for
3426 dynamic pc-relative relocs against symbols which turn out to be
3427 defined in regular objects. For the normal shared case, discard
3428 space for pc-relative relocs that have become local due to symbol
3429 visibility changes. */
3431 if (bfd_link_pic (info
))
3433 /* Relocs that use pc_count are those that appear on a call
3434 insn, or certain REL relocs that can generated via assembly.
3435 We want calls to protected symbols to resolve directly to the
3436 function rather than going via the plt. If people want
3437 function pointer comparisons to work as expected then they
3438 should avoid writing weird assembly. */
3439 if (SYMBOL_CALLS_LOCAL (info
, h
))
3441 struct elf_dyn_relocs
**pp
;
3443 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3445 p
->count
-= p
->pc_count
;
3454 /* Also discard relocs on undefined weak syms with non-default
3455 visibility or in PIE. */
3456 if (eh
->dyn_relocs
!= NULL
)
3458 if (h
->root
.type
== bfd_link_hash_undefweak
)
3460 /* Undefined weak symbol is never bound locally in shared
3462 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3463 || resolved_to_zero
)
3464 eh
->dyn_relocs
= NULL
;
3465 else if (h
->dynindx
== -1
3466 && ! h
->forced_local
3467 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3470 /* For PIE, discard space for pc-relative relocs against
3471 symbols which turn out to need copy relocs. */
3472 else if (bfd_link_executable (info
)
3473 && (h
->needs_copy
|| eh
->needs_copy
)
3477 struct elf_dyn_relocs
**pp
;
3479 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3481 if (p
->pc_count
!= 0)
3489 else if (ELIMINATE_COPY_RELOCS
)
3491 /* For the non-shared case, discard space for relocs against
3492 symbols which turn out to need copy relocs or are not
3493 dynamic. Keep dynamic relocations for run-time function
3494 pointer initialization. */
3496 if ((!h
->non_got_ref
3497 || eh
->func_pointer_refcount
> 0
3498 || (h
->root
.type
== bfd_link_hash_undefweak
3499 && !resolved_to_zero
))
3502 || (htab
->elf
.dynamic_sections_created
3503 && (h
->root
.type
== bfd_link_hash_undefweak
3504 || h
->root
.type
== bfd_link_hash_undefined
))))
3506 /* Make sure this symbol is output as a dynamic symbol.
3507 Undefined weak syms won't yet be marked as dynamic. */
3508 if (h
->dynindx
== -1
3509 && ! h
->forced_local
3510 && ! resolved_to_zero
3511 && h
->root
.type
== bfd_link_hash_undefweak
3512 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3515 /* If that succeeded, we know we'll be keeping all the
3517 if (h
->dynindx
!= -1)
3521 eh
->dyn_relocs
= NULL
;
3522 eh
->func_pointer_refcount
= 0;
3527 /* Finally, allocate space. */
3528 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3532 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3534 BFD_ASSERT (sreloc
!= NULL
);
3536 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3542 /* Allocate space in .plt, .got and associated reloc sections for
3543 local dynamic relocs. */
3546 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3548 struct elf_link_hash_entry
*h
3549 = (struct elf_link_hash_entry
*) *slot
;
3551 if (h
->type
!= STT_GNU_IFUNC
3555 || h
->root
.type
!= bfd_link_hash_defined
)
3558 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3561 /* Find any dynamic relocs that apply to read-only sections. */
3564 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3567 struct elf_x86_64_link_hash_entry
*eh
;
3568 struct elf_dyn_relocs
*p
;
3570 /* Skip local IFUNC symbols. */
3571 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3574 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3575 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3577 asection
*s
= p
->sec
->output_section
;
3579 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3581 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3583 info
->flags
|= DF_TEXTREL
;
3585 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3586 || info
->error_textrel
)
3587 /* xgettext:c-format */
3588 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3589 p
->sec
->owner
, h
->root
.root
.string
,
3592 /* Not an error, just cut short the traversal. */
3599 /* Convert load via the GOT slot to load immediate. */
3602 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3603 struct bfd_link_info
*link_info
)
3605 Elf_Internal_Shdr
*symtab_hdr
;
3606 Elf_Internal_Rela
*internal_relocs
;
3607 Elf_Internal_Rela
*irel
, *irelend
;
3609 struct elf_x86_64_link_hash_table
*htab
;
3610 bfd_boolean changed
;
3611 bfd_signed_vma
*local_got_refcounts
;
3613 /* Don't even try to convert non-ELF outputs. */
3614 if (!is_elf_hash_table (link_info
->hash
))
3617 /* Nothing to do if there is no need or no output. */
3618 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3619 || sec
->need_convert_load
== 0
3620 || bfd_is_abs_section (sec
->output_section
))
3623 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3625 /* Load the relocations for this section. */
3626 internal_relocs
= (_bfd_elf_link_read_relocs
3627 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3628 link_info
->keep_memory
));
3629 if (internal_relocs
== NULL
)
3633 htab
= elf_x86_64_hash_table (link_info
);
3634 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3636 /* Get the section contents. */
3637 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3638 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3641 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3645 irelend
= internal_relocs
+ sec
->reloc_count
;
3646 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3648 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3649 unsigned int r_symndx
;
3650 struct elf_link_hash_entry
*h
;
3651 bfd_boolean converted
;
3653 if (r_type
!= R_X86_64_GOTPCRELX
3654 && r_type
!= R_X86_64_REX_GOTPCRELX
3655 && r_type
!= R_X86_64_GOTPCREL
)
3658 r_symndx
= htab
->r_sym (irel
->r_info
);
3659 if (r_symndx
< symtab_hdr
->sh_info
)
3660 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3661 (const Elf_Internal_Rela
*) irel
,
3665 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3666 while (h
->root
.type
== bfd_link_hash_indirect
3667 || h
->root
.type
== bfd_link_hash_warning
)
3668 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3671 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3672 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3676 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3677 &converted
, link_info
))
3682 changed
= converted
;
3685 if (h
->got
.refcount
> 0)
3686 h
->got
.refcount
-= 1;
3690 if (local_got_refcounts
!= NULL
3691 && local_got_refcounts
[r_symndx
] > 0)
3692 local_got_refcounts
[r_symndx
] -= 1;
3697 if (contents
!= NULL
3698 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3700 if (!changed
&& !link_info
->keep_memory
)
3704 /* Cache the section contents for elf_link_input_bfd. */
3705 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3709 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3712 free (internal_relocs
);
3714 elf_section_data (sec
)->relocs
= internal_relocs
;
3720 if (contents
!= NULL
3721 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3723 if (internal_relocs
!= NULL
3724 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3725 free (internal_relocs
);
3729 /* Set the sizes of the dynamic sections. */
3732 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3733 struct bfd_link_info
*info
)
3735 struct elf_x86_64_link_hash_table
*htab
;
3740 const struct elf_backend_data
*bed
;
3742 htab
= elf_x86_64_hash_table (info
);
3745 bed
= get_elf_backend_data (output_bfd
);
3747 dynobj
= htab
->elf
.dynobj
;
3751 /* Set up .got offsets for local syms, and space for local dynamic
3753 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3755 bfd_signed_vma
*local_got
;
3756 bfd_signed_vma
*end_local_got
;
3757 char *local_tls_type
;
3758 bfd_vma
*local_tlsdesc_gotent
;
3759 bfd_size_type locsymcount
;
3760 Elf_Internal_Shdr
*symtab_hdr
;
3763 if (! is_x86_64_elf (ibfd
))
3766 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3768 struct elf_dyn_relocs
*p
;
3770 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3773 for (p
= (struct elf_dyn_relocs
*)
3774 (elf_section_data (s
)->local_dynrel
);
3778 if (!bfd_is_abs_section (p
->sec
)
3779 && bfd_is_abs_section (p
->sec
->output_section
))
3781 /* Input section has been discarded, either because
3782 it is a copy of a linkonce section or due to
3783 linker script /DISCARD/, so we'll be discarding
3786 else if (p
->count
!= 0)
3788 srel
= elf_section_data (p
->sec
)->sreloc
;
3789 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3790 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3791 && (info
->flags
& DF_TEXTREL
) == 0)
3793 info
->flags
|= DF_TEXTREL
;
3794 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3795 || info
->error_textrel
)
3796 /* xgettext:c-format */
3797 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3798 p
->sec
->owner
, p
->sec
);
3804 local_got
= elf_local_got_refcounts (ibfd
);
3808 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3809 locsymcount
= symtab_hdr
->sh_info
;
3810 end_local_got
= local_got
+ locsymcount
;
3811 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3812 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3814 srel
= htab
->elf
.srelgot
;
3815 for (; local_got
< end_local_got
;
3816 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3818 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3821 if (GOT_TLS_GDESC_P (*local_tls_type
))
3823 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3824 - elf_x86_64_compute_jump_table_size (htab
);
3825 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3826 *local_got
= (bfd_vma
) -2;
3828 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3829 || GOT_TLS_GD_P (*local_tls_type
))
3831 *local_got
= s
->size
;
3832 s
->size
+= GOT_ENTRY_SIZE
;
3833 if (GOT_TLS_GD_P (*local_tls_type
))
3834 s
->size
+= GOT_ENTRY_SIZE
;
3836 if (bfd_link_pic (info
)
3837 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3838 || *local_tls_type
== GOT_TLS_IE
)
3840 if (GOT_TLS_GDESC_P (*local_tls_type
))
3842 htab
->elf
.srelplt
->size
3843 += bed
->s
->sizeof_rela
;
3844 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3846 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3847 || GOT_TLS_GD_P (*local_tls_type
))
3848 srel
->size
+= bed
->s
->sizeof_rela
;
3852 *local_got
= (bfd_vma
) -1;
3856 if (htab
->tls_ld_got
.refcount
> 0)
3858 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3860 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3861 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3862 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3865 htab
->tls_ld_got
.offset
= -1;
3867 /* Allocate global sym .plt and .got entries, and space for global
3868 sym dynamic relocs. */
3869 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3872 /* Allocate .plt and .got entries, and space for local symbols. */
3873 htab_traverse (htab
->loc_hash_table
,
3874 elf_x86_64_allocate_local_dynrelocs
,
3877 /* For every jump slot reserved in the sgotplt, reloc_count is
3878 incremented. However, when we reserve space for TLS descriptors,
3879 it's not incremented, so in order to compute the space reserved
3880 for them, it suffices to multiply the reloc count by the jump
3883 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3884 so that R_X86_64_IRELATIVE entries come last. */
3885 if (htab
->elf
.srelplt
)
3887 htab
->sgotplt_jump_table_size
3888 = elf_x86_64_compute_jump_table_size (htab
);
3889 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3891 else if (htab
->elf
.irelplt
)
3892 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3894 if (htab
->tlsdesc_plt
)
3896 /* If we're not using lazy TLS relocations, don't generate the
3897 PLT and GOT entries they require. */
3898 if ((info
->flags
& DF_BIND_NOW
))
3899 htab
->tlsdesc_plt
= 0;
3902 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3903 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3904 /* Reserve room for the initial entry.
3905 FIXME: we could probably do away with it in this case. */
3906 if (htab
->elf
.splt
->size
== 0)
3907 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
3908 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3909 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
3913 if (htab
->elf
.sgotplt
)
3915 /* Don't allocate .got.plt section if there are no GOT nor PLT
3916 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3917 if ((htab
->elf
.hgot
== NULL
3918 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3919 && (htab
->elf
.sgotplt
->size
3920 == get_elf_backend_data (output_bfd
)->got_header_size
)
3921 && (htab
->elf
.splt
== NULL
3922 || htab
->elf
.splt
->size
== 0)
3923 && (htab
->elf
.sgot
== NULL
3924 || htab
->elf
.sgot
->size
== 0)
3925 && (htab
->elf
.iplt
== NULL
3926 || htab
->elf
.iplt
->size
== 0)
3927 && (htab
->elf
.igotplt
== NULL
3928 || htab
->elf
.igotplt
->size
== 0))
3929 htab
->elf
.sgotplt
->size
= 0;
3932 if (_bfd_elf_eh_frame_present (info
))
3934 if (htab
->plt_eh_frame
!= NULL
3935 && htab
->elf
.splt
!= NULL
3936 && htab
->elf
.splt
->size
!= 0
3937 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3938 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
3940 if (htab
->plt_got_eh_frame
!= NULL
3941 && htab
->plt_got
!= NULL
3942 && htab
->plt_got
->size
!= 0
3943 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3944 htab
->plt_got_eh_frame
->size
3945 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3947 /* Unwind info for the second PLT and .plt.got sections are
3949 if (htab
->plt_second_eh_frame
!= NULL
3950 && htab
->plt_second
!= NULL
3951 && htab
->plt_second
->size
!= 0
3952 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
3953 htab
->plt_second_eh_frame
->size
3954 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3957 /* We now have determined the sizes of the various dynamic sections.
3958 Allocate memory for them. */
3960 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3962 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3965 if (s
== htab
->elf
.splt
3966 || s
== htab
->elf
.sgot
3967 || s
== htab
->elf
.sgotplt
3968 || s
== htab
->elf
.iplt
3969 || s
== htab
->elf
.igotplt
3970 || s
== htab
->plt_second
3971 || s
== htab
->plt_got
3972 || s
== htab
->plt_eh_frame
3973 || s
== htab
->plt_got_eh_frame
3974 || s
== htab
->plt_second_eh_frame
3975 || s
== htab
->elf
.sdynbss
3976 || s
== htab
->elf
.sdynrelro
)
3978 /* Strip this section if we don't need it; see the
3981 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3983 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3986 /* We use the reloc_count field as a counter if we need
3987 to copy relocs into the output file. */
3988 if (s
!= htab
->elf
.srelplt
)
3993 /* It's not one of our sections, so don't allocate space. */
3999 /* If we don't need this section, strip it from the
4000 output file. This is mostly to handle .rela.bss and
4001 .rela.plt. We must create both sections in
4002 create_dynamic_sections, because they must be created
4003 before the linker maps input sections to output
4004 sections. The linker does that before
4005 adjust_dynamic_symbol is called, and it is that
4006 function which decides whether anything needs to go
4007 into these sections. */
4009 s
->flags
|= SEC_EXCLUDE
;
4013 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
4016 /* Allocate memory for the section contents. We use bfd_zalloc
4017 here in case unused entries are not reclaimed before the
4018 section's contents are written out. This should not happen,
4019 but this way if it does, we get a R_X86_64_NONE reloc instead
4021 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4022 if (s
->contents
== NULL
)
4026 if (htab
->plt_eh_frame
!= NULL
4027 && htab
->plt_eh_frame
->contents
!= NULL
)
4029 memcpy (htab
->plt_eh_frame
->contents
,
4030 htab
->plt
.eh_frame_plt
, htab
->plt_eh_frame
->size
);
4031 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
4032 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
4035 if (htab
->plt_got_eh_frame
!= NULL
4036 && htab
->plt_got_eh_frame
->contents
!= NULL
)
4038 memcpy (htab
->plt_got_eh_frame
->contents
,
4039 htab
->non_lazy_plt
->eh_frame_plt
,
4040 htab
->plt_got_eh_frame
->size
);
4041 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
4042 (htab
->plt_got_eh_frame
->contents
4043 + PLT_FDE_LEN_OFFSET
));
4046 if (htab
->plt_second_eh_frame
!= NULL
4047 && htab
->plt_second_eh_frame
->contents
!= NULL
)
4049 memcpy (htab
->plt_second_eh_frame
->contents
,
4050 htab
->non_lazy_plt
->eh_frame_plt
,
4051 htab
->plt_second_eh_frame
->size
);
4052 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
4053 (htab
->plt_second_eh_frame
->contents
4054 + PLT_FDE_LEN_OFFSET
));
4057 if (htab
->elf
.dynamic_sections_created
)
4059 /* Add some entries to the .dynamic section. We fill in the
4060 values later, in elf_x86_64_finish_dynamic_sections, but we
4061 must add the entries now so that we get the correct size for
4062 the .dynamic section. The DT_DEBUG entry is filled in by the
4063 dynamic linker and used by the debugger. */
4064 #define add_dynamic_entry(TAG, VAL) \
4065 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4067 if (bfd_link_executable (info
))
4069 if (!add_dynamic_entry (DT_DEBUG
, 0))
4073 if (htab
->elf
.splt
->size
!= 0)
4075 /* DT_PLTGOT is used by prelink even if there is no PLT
4077 if (!add_dynamic_entry (DT_PLTGOT
, 0))
4081 if (htab
->elf
.srelplt
->size
!= 0)
4083 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
4084 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4085 || !add_dynamic_entry (DT_JMPREL
, 0))
4089 if (htab
->tlsdesc_plt
4090 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
4091 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
4096 if (!add_dynamic_entry (DT_RELA
, 0)
4097 || !add_dynamic_entry (DT_RELASZ
, 0)
4098 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
4101 /* If any dynamic relocs apply to a read-only section,
4102 then we need a DT_TEXTREL entry. */
4103 if ((info
->flags
& DF_TEXTREL
) == 0)
4104 elf_link_hash_traverse (&htab
->elf
,
4105 elf_x86_64_readonly_dynrelocs
,
4108 if ((info
->flags
& DF_TEXTREL
) != 0)
4110 if (htab
->readonly_dynrelocs_against_ifunc
)
4112 info
->callbacks
->einfo
4113 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
4114 bfd_set_error (bfd_error_bad_value
);
4118 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4123 #undef add_dynamic_entry
4129 elf_x86_64_always_size_sections (bfd
*output_bfd
,
4130 struct bfd_link_info
*info
)
4132 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
4136 struct elf_link_hash_entry
*tlsbase
;
4138 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
4139 "_TLS_MODULE_BASE_",
4140 FALSE
, FALSE
, FALSE
);
4142 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
4144 struct elf_x86_64_link_hash_table
*htab
;
4145 struct bfd_link_hash_entry
*bh
= NULL
;
4146 const struct elf_backend_data
*bed
4147 = get_elf_backend_data (output_bfd
);
4149 htab
= elf_x86_64_hash_table (info
);
4153 if (!(_bfd_generic_link_add_one_symbol
4154 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
4155 tls_sec
, 0, NULL
, FALSE
,
4156 bed
->collect
, &bh
)))
4159 htab
->tls_module_base
= bh
;
4161 tlsbase
= (struct elf_link_hash_entry
*)bh
;
4162 tlsbase
->def_regular
= 1;
4163 tlsbase
->other
= STV_HIDDEN
;
4164 tlsbase
->root
.linker_def
= 1;
4165 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4172 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4173 executables. Rather than setting it to the beginning of the TLS
4174 section, we have to set it to the end. This function may be called
4175 multiple times, it is idempotent. */
4178 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4180 struct elf_x86_64_link_hash_table
*htab
;
4181 struct bfd_link_hash_entry
*base
;
4183 if (!bfd_link_executable (info
))
4186 htab
= elf_x86_64_hash_table (info
);
4190 base
= htab
->tls_module_base
;
4194 base
->u
.def
.value
= htab
->elf
.tls_size
;
4197 /* Return the base VMA address which should be subtracted from real addresses
4198 when resolving @dtpoff relocation.
4199 This is PT_TLS segment p_vaddr. */
4202 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4204 /* If tls_sec is NULL, we should have signalled an error already. */
4205 if (elf_hash_table (info
)->tls_sec
== NULL
)
4207 return elf_hash_table (info
)->tls_sec
->vma
;
4210 /* Return the relocation value for @tpoff relocation
4211 if STT_TLS virtual address is ADDRESS. */
4214 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4216 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4217 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4218 bfd_vma static_tls_size
;
4220 /* If tls_segment is NULL, we should have signalled an error already. */
4221 if (htab
->tls_sec
== NULL
)
4224 /* Consider special static TLS alignment requirements. */
4225 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4226 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4229 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4233 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4235 /* Opcode Instruction
4238 0x0f 0x8x conditional jump */
4240 && (contents
[offset
- 1] == 0xe8
4241 || contents
[offset
- 1] == 0xe9))
4243 && contents
[offset
- 2] == 0x0f
4244 && (contents
[offset
- 1] & 0xf0) == 0x80));
4247 /* Relocate an x86_64 ELF section. */
4250 elf_x86_64_relocate_section (bfd
*output_bfd
,
4251 struct bfd_link_info
*info
,
4253 asection
*input_section
,
4255 Elf_Internal_Rela
*relocs
,
4256 Elf_Internal_Sym
*local_syms
,
4257 asection
**local_sections
)
4259 struct elf_x86_64_link_hash_table
*htab
;
4260 Elf_Internal_Shdr
*symtab_hdr
;
4261 struct elf_link_hash_entry
**sym_hashes
;
4262 bfd_vma
*local_got_offsets
;
4263 bfd_vma
*local_tlsdesc_gotents
;
4264 Elf_Internal_Rela
*rel
;
4265 Elf_Internal_Rela
*wrel
;
4266 Elf_Internal_Rela
*relend
;
4267 unsigned int plt_entry_size
;
4269 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4271 /* Skip if check_relocs failed. */
4272 if (input_section
->check_relocs_failed
)
4275 htab
= elf_x86_64_hash_table (info
);
4278 plt_entry_size
= htab
->plt
.plt_entry_size
;
4279 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4280 sym_hashes
= elf_sym_hashes (input_bfd
);
4281 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4282 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4284 elf_x86_64_set_tls_module_base (info
);
4286 rel
= wrel
= relocs
;
4287 relend
= relocs
+ input_section
->reloc_count
;
4288 for (; rel
< relend
; wrel
++, rel
++)
4290 unsigned int r_type
;
4291 reloc_howto_type
*howto
;
4292 unsigned long r_symndx
;
4293 struct elf_link_hash_entry
*h
;
4294 struct elf_x86_64_link_hash_entry
*eh
;
4295 Elf_Internal_Sym
*sym
;
4297 bfd_vma off
, offplt
, plt_offset
;
4299 bfd_boolean unresolved_reloc
;
4300 bfd_reloc_status_type r
;
4302 asection
*base_got
, *resolved_plt
;
4304 bfd_boolean resolved_to_zero
;
4305 bfd_boolean relative_reloc
;
4307 r_type
= ELF32_R_TYPE (rel
->r_info
);
4308 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4309 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4316 if (r_type
>= (int) R_X86_64_standard
)
4319 /* xgettext:c-format */
4320 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4321 input_bfd
, r_type
, input_section
);
4322 bfd_set_error (bfd_error_bad_value
);
4326 if (r_type
!= (int) R_X86_64_32
4327 || ABI_64_P (output_bfd
))
4328 howto
= x86_64_elf_howto_table
+ r_type
;
4330 howto
= (x86_64_elf_howto_table
4331 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4332 r_symndx
= htab
->r_sym (rel
->r_info
);
4336 unresolved_reloc
= FALSE
;
4337 if (r_symndx
< symtab_hdr
->sh_info
)
4339 sym
= local_syms
+ r_symndx
;
4340 sec
= local_sections
[r_symndx
];
4342 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4344 st_size
= sym
->st_size
;
4346 /* Relocate against local STT_GNU_IFUNC symbol. */
4347 if (!bfd_link_relocatable (info
)
4348 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4350 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4355 /* Set STT_GNU_IFUNC symbol value. */
4356 h
->root
.u
.def
.value
= sym
->st_value
;
4357 h
->root
.u
.def
.section
= sec
;
4362 bfd_boolean warned ATTRIBUTE_UNUSED
;
4363 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4365 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4366 r_symndx
, symtab_hdr
, sym_hashes
,
4368 unresolved_reloc
, warned
, ignored
);
4372 if (sec
!= NULL
&& discarded_section (sec
))
4374 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4375 contents
+ rel
->r_offset
);
4376 wrel
->r_offset
= rel
->r_offset
;
4380 /* For ld -r, remove relocations in debug sections against
4381 sections defined in discarded sections. Not done for
4382 eh_frame editing code expects to be present. */
4383 if (bfd_link_relocatable (info
)
4384 && (input_section
->flags
& SEC_DEBUGGING
))
4390 if (bfd_link_relocatable (info
))
4397 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4399 if (r_type
== R_X86_64_64
)
4401 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4402 zero-extend it to 64bit if addend is zero. */
4403 r_type
= R_X86_64_32
;
4404 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4406 else if (r_type
== R_X86_64_SIZE64
)
4408 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4409 zero-extend it to 64bit if addend is zero. */
4410 r_type
= R_X86_64_SIZE32
;
4411 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4415 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4417 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4418 it here if it is defined in a non-shared object. */
4420 && h
->type
== STT_GNU_IFUNC
4426 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4428 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4429 sections because such sections are not SEC_ALLOC and
4430 thus ld.so will not process them. */
4431 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4441 case R_X86_64_GOTPCREL
:
4442 case R_X86_64_GOTPCRELX
:
4443 case R_X86_64_REX_GOTPCRELX
:
4444 case R_X86_64_GOTPCREL64
:
4445 base_got
= htab
->elf
.sgot
;
4446 off
= h
->got
.offset
;
4448 if (base_got
== NULL
)
4451 if (off
== (bfd_vma
) -1)
4453 /* We can't use h->got.offset here to save state, or
4454 even just remember the offset, as finish_dynamic_symbol
4455 would use that as offset into .got. */
4457 if (h
->plt
.offset
== (bfd_vma
) -1)
4460 if (htab
->elf
.splt
!= NULL
)
4462 plt_index
= (h
->plt
.offset
/ plt_entry_size
4463 - htab
->plt
.has_plt0
);
4464 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4465 base_got
= htab
->elf
.sgotplt
;
4469 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4470 off
= plt_index
* GOT_ENTRY_SIZE
;
4471 base_got
= htab
->elf
.igotplt
;
4474 if (h
->dynindx
== -1
4478 /* This references the local defitionion. We must
4479 initialize this entry in the global offset table.
4480 Since the offset must always be a multiple of 8,
4481 we use the least significant bit to record
4482 whether we have initialized it already.
4484 When doing a dynamic link, we create a .rela.got
4485 relocation entry to initialize the value. This
4486 is done in the finish_dynamic_symbol routine. */
4491 bfd_put_64 (output_bfd
, relocation
,
4492 base_got
->contents
+ off
);
4493 /* Note that this is harmless for the GOTPLT64
4494 case, as -1 | 1 still is -1. */
4500 relocation
= (base_got
->output_section
->vma
4501 + base_got
->output_offset
+ off
);
4506 if (h
->plt
.offset
== (bfd_vma
) -1)
4508 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4509 if (r_type
== htab
->pointer_r_type
4510 && (input_section
->flags
& SEC_CODE
) == 0)
4511 goto do_ifunc_pointer
;
4512 goto bad_ifunc_reloc
;
4515 /* STT_GNU_IFUNC symbol must go through PLT. */
4516 if (htab
->elf
.splt
!= NULL
)
4518 if (htab
->plt_second
!= NULL
)
4520 resolved_plt
= htab
->plt_second
;
4521 plt_offset
= eh
->plt_second
.offset
;
4525 resolved_plt
= htab
->elf
.splt
;
4526 plt_offset
= h
->plt
.offset
;
4531 resolved_plt
= htab
->elf
.iplt
;
4532 plt_offset
= h
->plt
.offset
;
4535 relocation
= (resolved_plt
->output_section
->vma
4536 + resolved_plt
->output_offset
+ plt_offset
);
4542 if (h
->root
.root
.string
)
4543 name
= h
->root
.root
.string
;
4545 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4548 /* xgettext:c-format */
4549 (_("%B: relocation %s against STT_GNU_IFUNC "
4550 "symbol `%s' isn't supported"), input_bfd
,
4552 bfd_set_error (bfd_error_bad_value
);
4556 if (bfd_link_pic (info
))
4561 if (ABI_64_P (output_bfd
))
4566 if (rel
->r_addend
!= 0)
4568 if (h
->root
.root
.string
)
4569 name
= h
->root
.root
.string
;
4571 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4574 /* xgettext:c-format */
4575 (_("%B: relocation %s against STT_GNU_IFUNC "
4576 "symbol `%s' has non-zero addend: %Ld"),
4577 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4578 bfd_set_error (bfd_error_bad_value
);
4582 /* Generate dynamic relcoation only when there is a
4583 non-GOT reference in a shared object or there is no
4585 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4586 || h
->plt
.offset
== (bfd_vma
) -1)
4588 Elf_Internal_Rela outrel
;
4591 /* Need a dynamic relocation to get the real function
4593 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4597 if (outrel
.r_offset
== (bfd_vma
) -1
4598 || outrel
.r_offset
== (bfd_vma
) -2)
4601 outrel
.r_offset
+= (input_section
->output_section
->vma
4602 + input_section
->output_offset
);
4604 if (h
->dynindx
== -1
4606 || bfd_link_executable (info
))
4608 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
4609 h
->root
.root
.string
,
4610 h
->root
.u
.def
.section
->owner
);
4612 /* This symbol is resolved locally. */
4613 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4614 outrel
.r_addend
= (h
->root
.u
.def
.value
4615 + h
->root
.u
.def
.section
->output_section
->vma
4616 + h
->root
.u
.def
.section
->output_offset
);
4620 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4621 outrel
.r_addend
= 0;
4624 /* Dynamic relocations are stored in
4625 1. .rela.ifunc section in PIC object.
4626 2. .rela.got section in dynamic executable.
4627 3. .rela.iplt section in static executable. */
4628 if (bfd_link_pic (info
))
4629 sreloc
= htab
->elf
.irelifunc
;
4630 else if (htab
->elf
.splt
!= NULL
)
4631 sreloc
= htab
->elf
.srelgot
;
4633 sreloc
= htab
->elf
.irelplt
;
4634 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4636 /* If this reloc is against an external symbol, we
4637 do not want to fiddle with the addend. Otherwise,
4638 we need to include the symbol value so that it
4639 becomes an addend for the dynamic reloc. For an
4640 internal symbol, we have updated addend. */
4645 case R_X86_64_PC32_BND
:
4647 case R_X86_64_PLT32
:
4648 case R_X86_64_PLT32_BND
:
4653 resolved_to_zero
= (eh
!= NULL
4654 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4658 /* When generating a shared object, the relocations handled here are
4659 copied into the output file to be resolved at run time. */
4662 case R_X86_64_GOT32
:
4663 case R_X86_64_GOT64
:
4664 /* Relocation is to the entry for this symbol in the global
4666 case R_X86_64_GOTPCREL
:
4667 case R_X86_64_GOTPCRELX
:
4668 case R_X86_64_REX_GOTPCRELX
:
4669 case R_X86_64_GOTPCREL64
:
4670 /* Use global offset table entry as symbol value. */
4671 case R_X86_64_GOTPLT64
:
4672 /* This is obsolete and treated the the same as GOT64. */
4673 base_got
= htab
->elf
.sgot
;
4675 if (htab
->elf
.sgot
== NULL
)
4678 relative_reloc
= FALSE
;
4683 off
= h
->got
.offset
;
4685 && h
->plt
.offset
!= (bfd_vma
)-1
4686 && off
== (bfd_vma
)-1)
4688 /* We can't use h->got.offset here to save
4689 state, or even just remember the offset, as
4690 finish_dynamic_symbol would use that as offset into
4692 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
4693 - htab
->plt
.has_plt0
);
4694 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4695 base_got
= htab
->elf
.sgotplt
;
4698 dyn
= htab
->elf
.dynamic_sections_created
;
4700 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4701 || (bfd_link_pic (info
)
4702 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4703 || (ELF_ST_VISIBILITY (h
->other
)
4704 && h
->root
.type
== bfd_link_hash_undefweak
))
4706 /* This is actually a static link, or it is a -Bsymbolic
4707 link and the symbol is defined locally, or the symbol
4708 was forced to be local because of a version file. We
4709 must initialize this entry in the global offset table.
4710 Since the offset must always be a multiple of 8, we
4711 use the least significant bit to record whether we
4712 have initialized it already.
4714 When doing a dynamic link, we create a .rela.got
4715 relocation entry to initialize the value. This is
4716 done in the finish_dynamic_symbol routine. */
4721 bfd_put_64 (output_bfd
, relocation
,
4722 base_got
->contents
+ off
);
4723 /* Note that this is harmless for the GOTPLT64 case,
4724 as -1 | 1 still is -1. */
4727 if (h
->dynindx
== -1
4729 && h
->root
.type
!= bfd_link_hash_undefweak
4730 && bfd_link_pic (info
))
4732 /* If this symbol isn't dynamic in PIC,
4733 generate R_X86_64_RELATIVE here. */
4734 eh
->no_finish_dynamic_symbol
= 1;
4735 relative_reloc
= TRUE
;
4740 unresolved_reloc
= FALSE
;
4744 if (local_got_offsets
== NULL
)
4747 off
= local_got_offsets
[r_symndx
];
4749 /* The offset must always be a multiple of 8. We use
4750 the least significant bit to record whether we have
4751 already generated the necessary reloc. */
4756 bfd_put_64 (output_bfd
, relocation
,
4757 base_got
->contents
+ off
);
4758 local_got_offsets
[r_symndx
] |= 1;
4760 if (bfd_link_pic (info
))
4761 relative_reloc
= TRUE
;
4768 Elf_Internal_Rela outrel
;
4770 /* We need to generate a R_X86_64_RELATIVE reloc
4771 for the dynamic linker. */
4772 s
= htab
->elf
.srelgot
;
4776 outrel
.r_offset
= (base_got
->output_section
->vma
4777 + base_got
->output_offset
4779 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4780 outrel
.r_addend
= relocation
;
4781 elf_append_rela (output_bfd
, s
, &outrel
);
4784 if (off
>= (bfd_vma
) -2)
4787 relocation
= base_got
->output_section
->vma
4788 + base_got
->output_offset
+ off
;
4789 if (r_type
!= R_X86_64_GOTPCREL
4790 && r_type
!= R_X86_64_GOTPCRELX
4791 && r_type
!= R_X86_64_REX_GOTPCRELX
4792 && r_type
!= R_X86_64_GOTPCREL64
)
4793 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4794 - htab
->elf
.sgotplt
->output_offset
;
4798 case R_X86_64_GOTOFF64
:
4799 /* Relocation is relative to the start of the global offset
4802 /* Check to make sure it isn't a protected function or data
4803 symbol for shared library since it may not be local when
4804 used as function address or with copy relocation. We also
4805 need to make sure that a symbol is referenced locally. */
4806 if (bfd_link_pic (info
) && h
)
4808 if (!h
->def_regular
)
4812 switch (ELF_ST_VISIBILITY (h
->other
))
4815 v
= _("hidden symbol");
4818 v
= _("internal symbol");
4821 v
= _("protected symbol");
4829 /* xgettext:c-format */
4830 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4831 " `%s' can not be used when making a shared object"),
4832 input_bfd
, v
, h
->root
.root
.string
);
4833 bfd_set_error (bfd_error_bad_value
);
4836 else if (!bfd_link_executable (info
)
4837 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4838 && (h
->type
== STT_FUNC
4839 || h
->type
== STT_OBJECT
)
4840 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4843 /* xgettext:c-format */
4844 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4845 " `%s' can not be used when making a shared object"),
4847 h
->type
== STT_FUNC
? "function" : "data",
4848 h
->root
.root
.string
);
4849 bfd_set_error (bfd_error_bad_value
);
4854 /* Note that sgot is not involved in this
4855 calculation. We always want the start of .got.plt. If we
4856 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4857 permitted by the ABI, we might have to change this
4859 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4860 + htab
->elf
.sgotplt
->output_offset
;
4863 case R_X86_64_GOTPC32
:
4864 case R_X86_64_GOTPC64
:
4865 /* Use global offset table as symbol value. */
4866 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4867 + htab
->elf
.sgotplt
->output_offset
;
4868 unresolved_reloc
= FALSE
;
4871 case R_X86_64_PLTOFF64
:
4872 /* Relocation is PLT entry relative to GOT. For local
4873 symbols it's the symbol itself relative to GOT. */
4875 /* See PLT32 handling. */
4876 && (h
->plt
.offset
!= (bfd_vma
) -1
4877 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4878 && htab
->elf
.splt
!= NULL
)
4880 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4882 /* Use the GOT PLT. */
4883 resolved_plt
= htab
->plt_got
;
4884 plt_offset
= eh
->plt_got
.offset
;
4886 else if (htab
->plt_second
!= NULL
)
4888 resolved_plt
= htab
->plt_second
;
4889 plt_offset
= eh
->plt_second
.offset
;
4893 resolved_plt
= htab
->elf
.splt
;
4894 plt_offset
= h
->plt
.offset
;
4897 relocation
= (resolved_plt
->output_section
->vma
4898 + resolved_plt
->output_offset
4900 unresolved_reloc
= FALSE
;
4903 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4904 + htab
->elf
.sgotplt
->output_offset
;
4907 case R_X86_64_PLT32
:
4908 case R_X86_64_PLT32_BND
:
4909 /* Relocation is to the entry for this symbol in the
4910 procedure linkage table. */
4912 /* Resolve a PLT32 reloc against a local symbol directly,
4913 without using the procedure linkage table. */
4917 if ((h
->plt
.offset
== (bfd_vma
) -1
4918 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4919 || htab
->elf
.splt
== NULL
)
4921 /* We didn't make a PLT entry for this symbol. This
4922 happens when statically linking PIC code, or when
4923 using -Bsymbolic. */
4927 if (h
->plt
.offset
!= (bfd_vma
) -1)
4929 if (htab
->plt_second
!= NULL
)
4931 resolved_plt
= htab
->plt_second
;
4932 plt_offset
= eh
->plt_second
.offset
;
4936 resolved_plt
= htab
->elf
.splt
;
4937 plt_offset
= h
->plt
.offset
;
4942 /* Use the GOT PLT. */
4943 resolved_plt
= htab
->plt_got
;
4944 plt_offset
= eh
->plt_got
.offset
;
4947 relocation
= (resolved_plt
->output_section
->vma
4948 + resolved_plt
->output_offset
4950 unresolved_reloc
= FALSE
;
4953 case R_X86_64_SIZE32
:
4954 case R_X86_64_SIZE64
:
4955 /* Set to symbol size. */
4956 relocation
= st_size
;
4962 case R_X86_64_PC32_BND
:
4963 /* Don't complain about -fPIC if the symbol is undefined when
4964 building executable unless it is unresolved weak symbol. */
4965 if ((input_section
->flags
& SEC_ALLOC
) != 0
4966 && (input_section
->flags
& SEC_READONLY
) != 0
4968 && ((bfd_link_executable (info
)
4969 && h
->root
.type
== bfd_link_hash_undefweak
4970 && !resolved_to_zero
)
4971 || bfd_link_dll (info
)))
4973 bfd_boolean fail
= FALSE
;
4975 = ((r_type
== R_X86_64_PC32
4976 || r_type
== R_X86_64_PC32_BND
)
4977 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4979 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4981 /* Symbol is referenced locally. Make sure it is
4982 defined locally or for a branch. */
4983 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4986 else if (!(bfd_link_pie (info
)
4987 && (h
->needs_copy
|| eh
->needs_copy
)))
4989 /* Symbol doesn't need copy reloc and isn't referenced
4990 locally. We only allow branch to symbol with
4991 non-default visibility. */
4993 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4997 return elf_x86_64_need_pic (input_bfd
, input_section
,
4998 h
, NULL
, NULL
, howto
);
5007 /* FIXME: The ABI says the linker should make sure the value is
5008 the same when it's zeroextended to 64 bit. */
5011 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5014 /* Don't copy a pc-relative relocation into the output file
5015 if the symbol needs copy reloc or the symbol is undefined
5016 when building executable. Copy dynamic function pointer
5017 relocations. Don't generate dynamic relocations against
5018 resolved undefined weak symbols in PIE. */
5019 if ((bfd_link_pic (info
)
5020 && !(bfd_link_pie (info
)
5024 || h
->root
.type
== bfd_link_hash_undefined
)
5025 && (IS_X86_64_PCREL_TYPE (r_type
)
5026 || r_type
== R_X86_64_SIZE32
5027 || r_type
== R_X86_64_SIZE64
))
5029 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5030 && !resolved_to_zero
)
5031 || h
->root
.type
!= bfd_link_hash_undefweak
))
5032 && ((! IS_X86_64_PCREL_TYPE (r_type
)
5033 && r_type
!= R_X86_64_SIZE32
5034 && r_type
!= R_X86_64_SIZE64
)
5035 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
5036 || (ELIMINATE_COPY_RELOCS
5037 && !bfd_link_pic (info
)
5041 || eh
->func_pointer_refcount
> 0
5042 || (h
->root
.type
== bfd_link_hash_undefweak
5043 && !resolved_to_zero
))
5044 && ((h
->def_dynamic
&& !h
->def_regular
)
5045 /* Undefined weak symbol is bound locally when
5047 || h
->root
.type
== bfd_link_hash_undefined
)))
5049 Elf_Internal_Rela outrel
;
5050 bfd_boolean skip
, relocate
;
5053 /* When generating a shared object, these relocations
5054 are copied into the output file to be resolved at run
5060 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5062 if (outrel
.r_offset
== (bfd_vma
) -1)
5064 else if (outrel
.r_offset
== (bfd_vma
) -2)
5065 skip
= TRUE
, relocate
= TRUE
;
5067 outrel
.r_offset
+= (input_section
->output_section
->vma
5068 + input_section
->output_offset
);
5071 memset (&outrel
, 0, sizeof outrel
);
5073 /* h->dynindx may be -1 if this symbol was marked to
5077 && (IS_X86_64_PCREL_TYPE (r_type
)
5078 || !(bfd_link_executable (info
)
5079 || SYMBOLIC_BIND (info
, h
))
5080 || ! h
->def_regular
))
5082 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
5083 outrel
.r_addend
= rel
->r_addend
;
5087 /* This symbol is local, or marked to become local.
5088 When relocation overflow check is disabled, we
5089 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
5090 if (r_type
== htab
->pointer_r_type
5091 || (r_type
== R_X86_64_32
5092 && info
->no_reloc_overflow_check
))
5095 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5096 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5098 else if (r_type
== R_X86_64_64
5099 && !ABI_64_P (output_bfd
))
5102 outrel
.r_info
= htab
->r_info (0,
5103 R_X86_64_RELATIVE64
);
5104 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5105 /* Check addend overflow. */
5106 if ((outrel
.r_addend
& 0x80000000)
5107 != (rel
->r_addend
& 0x80000000))
5110 int addend
= rel
->r_addend
;
5111 if (h
&& h
->root
.root
.string
)
5112 name
= h
->root
.root
.string
;
5114 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5117 /* xgettext:c-format */
5118 (_("%B: addend %s%#x in relocation %s against "
5119 "symbol `%s' at %#Lx in section `%A' is "
5121 input_bfd
, addend
< 0 ? "-" : "", addend
,
5122 howto
->name
, name
, rel
->r_offset
, input_section
);
5123 bfd_set_error (bfd_error_bad_value
);
5131 if (bfd_is_abs_section (sec
))
5133 else if (sec
== NULL
|| sec
->owner
== NULL
)
5135 bfd_set_error (bfd_error_bad_value
);
5142 /* We are turning this relocation into one
5143 against a section symbol. It would be
5144 proper to subtract the symbol's value,
5145 osec->vma, from the emitted reloc addend,
5146 but ld.so expects buggy relocs. */
5147 osec
= sec
->output_section
;
5148 sindx
= elf_section_data (osec
)->dynindx
;
5151 asection
*oi
= htab
->elf
.text_index_section
;
5152 sindx
= elf_section_data (oi
)->dynindx
;
5154 BFD_ASSERT (sindx
!= 0);
5157 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
5158 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5162 sreloc
= elf_section_data (input_section
)->sreloc
;
5164 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5166 r
= bfd_reloc_notsupported
;
5167 goto check_relocation_error
;
5170 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5172 /* If this reloc is against an external symbol, we do
5173 not want to fiddle with the addend. Otherwise, we
5174 need to include the symbol value so that it becomes
5175 an addend for the dynamic reloc. */
5182 case R_X86_64_TLSGD
:
5183 case R_X86_64_GOTPC32_TLSDESC
:
5184 case R_X86_64_TLSDESC_CALL
:
5185 case R_X86_64_GOTTPOFF
:
5186 tls_type
= GOT_UNKNOWN
;
5187 if (h
== NULL
&& local_got_offsets
)
5188 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5190 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5192 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5193 input_section
, contents
,
5194 symtab_hdr
, sym_hashes
,
5195 &r_type
, tls_type
, rel
,
5196 relend
, h
, r_symndx
, TRUE
))
5199 if (r_type
== R_X86_64_TPOFF32
)
5201 bfd_vma roff
= rel
->r_offset
;
5203 BFD_ASSERT (! unresolved_reloc
);
5205 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5207 /* GD->LE transition. For 64bit, change
5208 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5209 .word 0x6666; rex64; call __tls_get_addr@PLT
5211 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5213 call *__tls_get_addr@GOTPCREL(%rip)
5214 which may be converted to
5215 addr32 call __tls_get_addr
5218 leaq foo@tpoff(%rax), %rax
5220 leaq foo@tlsgd(%rip), %rdi
5221 .word 0x6666; rex64; call __tls_get_addr@PLT
5223 leaq foo@tlsgd(%rip), %rdi
5225 call *__tls_get_addr@GOTPCREL(%rip)
5226 which may be converted to
5227 addr32 call __tls_get_addr
5230 leaq foo@tpoff(%rax), %rax
5231 For largepic, change:
5232 leaq foo@tlsgd(%rip), %rdi
5233 movabsq $__tls_get_addr@pltoff, %rax
5238 leaq foo@tpoff(%rax), %rax
5239 nopw 0x0(%rax,%rax,1) */
5241 if (ABI_64_P (output_bfd
))
5243 if (contents
[roff
+ 5] == 0xb8)
5245 memcpy (contents
+ roff
- 3,
5246 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5247 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5251 memcpy (contents
+ roff
- 4,
5252 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5256 memcpy (contents
+ roff
- 3,
5257 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5259 bfd_put_32 (output_bfd
,
5260 elf_x86_64_tpoff (info
, relocation
),
5261 contents
+ roff
+ 8 + largepic
);
5262 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5263 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5268 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5270 /* GDesc -> LE transition.
5271 It's originally something like:
5272 leaq x@tlsdesc(%rip), %rax
5275 movl $x@tpoff, %rax. */
5277 unsigned int val
, type
;
5279 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5280 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5281 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5282 contents
+ roff
- 3);
5283 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5284 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5285 contents
+ roff
- 1);
5286 bfd_put_32 (output_bfd
,
5287 elf_x86_64_tpoff (info
, relocation
),
5291 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5293 /* GDesc -> LE transition.
5298 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5299 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5302 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5304 /* IE->LE transition:
5305 For 64bit, originally it can be one of:
5306 movq foo@gottpoff(%rip), %reg
5307 addq foo@gottpoff(%rip), %reg
5310 leaq foo(%reg), %reg
5312 For 32bit, originally it can be one of:
5313 movq foo@gottpoff(%rip), %reg
5314 addl foo@gottpoff(%rip), %reg
5317 leal foo(%reg), %reg
5320 unsigned int val
, type
, reg
;
5323 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5326 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5327 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5333 bfd_put_8 (output_bfd
, 0x49,
5334 contents
+ roff
- 3);
5335 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5336 bfd_put_8 (output_bfd
, 0x41,
5337 contents
+ roff
- 3);
5338 bfd_put_8 (output_bfd
, 0xc7,
5339 contents
+ roff
- 2);
5340 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5341 contents
+ roff
- 1);
5345 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5348 bfd_put_8 (output_bfd
, 0x49,
5349 contents
+ roff
- 3);
5350 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5351 bfd_put_8 (output_bfd
, 0x41,
5352 contents
+ roff
- 3);
5353 bfd_put_8 (output_bfd
, 0x81,
5354 contents
+ roff
- 2);
5355 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5356 contents
+ roff
- 1);
5360 /* addq/addl -> leaq/leal */
5362 bfd_put_8 (output_bfd
, 0x4d,
5363 contents
+ roff
- 3);
5364 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5365 bfd_put_8 (output_bfd
, 0x45,
5366 contents
+ roff
- 3);
5367 bfd_put_8 (output_bfd
, 0x8d,
5368 contents
+ roff
- 2);
5369 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5370 contents
+ roff
- 1);
5372 bfd_put_32 (output_bfd
,
5373 elf_x86_64_tpoff (info
, relocation
),
5381 if (htab
->elf
.sgot
== NULL
)
5386 off
= h
->got
.offset
;
5387 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5391 if (local_got_offsets
== NULL
)
5394 off
= local_got_offsets
[r_symndx
];
5395 offplt
= local_tlsdesc_gotents
[r_symndx
];
5402 Elf_Internal_Rela outrel
;
5406 if (htab
->elf
.srelgot
== NULL
)
5409 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5411 if (GOT_TLS_GDESC_P (tls_type
))
5413 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5414 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5415 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5416 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5417 + htab
->elf
.sgotplt
->output_offset
5419 + htab
->sgotplt_jump_table_size
);
5420 sreloc
= htab
->elf
.srelplt
;
5422 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5424 outrel
.r_addend
= 0;
5425 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5428 sreloc
= htab
->elf
.srelgot
;
5430 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5431 + htab
->elf
.sgot
->output_offset
+ off
);
5433 if (GOT_TLS_GD_P (tls_type
))
5434 dr_type
= R_X86_64_DTPMOD64
;
5435 else if (GOT_TLS_GDESC_P (tls_type
))
5438 dr_type
= R_X86_64_TPOFF64
;
5440 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5441 outrel
.r_addend
= 0;
5442 if ((dr_type
== R_X86_64_TPOFF64
5443 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5444 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5445 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5447 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5449 if (GOT_TLS_GD_P (tls_type
))
5453 BFD_ASSERT (! unresolved_reloc
);
5454 bfd_put_64 (output_bfd
,
5455 relocation
- elf_x86_64_dtpoff_base (info
),
5456 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5460 bfd_put_64 (output_bfd
, 0,
5461 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5462 outrel
.r_info
= htab
->r_info (indx
,
5464 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5465 elf_append_rela (output_bfd
, sreloc
,
5474 local_got_offsets
[r_symndx
] |= 1;
5477 if (off
>= (bfd_vma
) -2
5478 && ! GOT_TLS_GDESC_P (tls_type
))
5480 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5482 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5483 || r_type
== R_X86_64_TLSDESC_CALL
)
5484 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5485 + htab
->elf
.sgotplt
->output_offset
5486 + offplt
+ htab
->sgotplt_jump_table_size
;
5488 relocation
= htab
->elf
.sgot
->output_section
->vma
5489 + htab
->elf
.sgot
->output_offset
+ off
;
5490 unresolved_reloc
= FALSE
;
5494 bfd_vma roff
= rel
->r_offset
;
5496 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5498 /* GD->IE transition. For 64bit, change
5499 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5500 .word 0x6666; rex64; call __tls_get_addr@PLT
5502 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5504 call *__tls_get_addr@GOTPCREL(%rip
5505 which may be converted to
5506 addr32 call __tls_get_addr
5509 addq foo@gottpoff(%rip), %rax
5511 leaq foo@tlsgd(%rip), %rdi
5512 .word 0x6666; rex64; call __tls_get_addr@PLT
5514 leaq foo@tlsgd(%rip), %rdi
5516 call *__tls_get_addr@GOTPCREL(%rip)
5517 which may be converted to
5518 addr32 call __tls_get_addr
5521 addq foo@gottpoff(%rip), %rax
5522 For largepic, change:
5523 leaq foo@tlsgd(%rip), %rdi
5524 movabsq $__tls_get_addr@pltoff, %rax
5529 addq foo@gottpoff(%rax), %rax
5530 nopw 0x0(%rax,%rax,1) */
5532 if (ABI_64_P (output_bfd
))
5534 if (contents
[roff
+ 5] == 0xb8)
5536 memcpy (contents
+ roff
- 3,
5537 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5538 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5542 memcpy (contents
+ roff
- 4,
5543 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5547 memcpy (contents
+ roff
- 3,
5548 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5551 relocation
= (htab
->elf
.sgot
->output_section
->vma
5552 + htab
->elf
.sgot
->output_offset
+ off
5555 - input_section
->output_section
->vma
5556 - input_section
->output_offset
5558 bfd_put_32 (output_bfd
, relocation
,
5559 contents
+ roff
+ 8 + largepic
);
5560 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5565 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5567 /* GDesc -> IE transition.
5568 It's originally something like:
5569 leaq x@tlsdesc(%rip), %rax
5572 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5574 /* Now modify the instruction as appropriate. To
5575 turn a leaq into a movq in the form we use it, it
5576 suffices to change the second byte from 0x8d to
5578 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5580 bfd_put_32 (output_bfd
,
5581 htab
->elf
.sgot
->output_section
->vma
5582 + htab
->elf
.sgot
->output_offset
+ off
5584 - input_section
->output_section
->vma
5585 - input_section
->output_offset
5590 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5592 /* GDesc -> IE transition.
5599 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5600 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5608 case R_X86_64_TLSLD
:
5609 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5610 input_section
, contents
,
5611 symtab_hdr
, sym_hashes
,
5612 &r_type
, GOT_UNKNOWN
, rel
,
5613 relend
, h
, r_symndx
, TRUE
))
5616 if (r_type
!= R_X86_64_TLSLD
)
5618 /* LD->LE transition:
5619 leaq foo@tlsld(%rip), %rdi
5620 call __tls_get_addr@PLT
5621 For 64bit, we change it into:
5622 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5623 For 32bit, we change it into:
5624 nopl 0x0(%rax); movl %fs:0, %eax
5626 leaq foo@tlsld(%rip), %rdi;
5627 call *__tls_get_addr@GOTPCREL(%rip)
5628 which may be converted to
5629 addr32 call __tls_get_addr
5630 For 64bit, we change it into:
5631 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5632 For 32bit, we change it into:
5633 nopw 0x0(%rax); movl %fs:0, %eax
5634 For largepic, change:
5635 leaq foo@tlsgd(%rip), %rdi
5636 movabsq $__tls_get_addr@pltoff, %rax
5640 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5643 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5644 if (ABI_64_P (output_bfd
))
5646 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5647 memcpy (contents
+ rel
->r_offset
- 3,
5648 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5649 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5650 else if (contents
[rel
->r_offset
+ 4] == 0xff
5651 || contents
[rel
->r_offset
+ 4] == 0x67)
5652 memcpy (contents
+ rel
->r_offset
- 3,
5653 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5656 memcpy (contents
+ rel
->r_offset
- 3,
5657 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5661 if (contents
[rel
->r_offset
+ 4] == 0xff)
5662 memcpy (contents
+ rel
->r_offset
- 3,
5663 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5666 memcpy (contents
+ rel
->r_offset
- 3,
5667 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5669 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5670 and R_X86_64_PLTOFF64. */
5676 if (htab
->elf
.sgot
== NULL
)
5679 off
= htab
->tls_ld_got
.offset
;
5684 Elf_Internal_Rela outrel
;
5686 if (htab
->elf
.srelgot
== NULL
)
5689 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5690 + htab
->elf
.sgot
->output_offset
+ off
);
5692 bfd_put_64 (output_bfd
, 0,
5693 htab
->elf
.sgot
->contents
+ off
);
5694 bfd_put_64 (output_bfd
, 0,
5695 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5696 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5697 outrel
.r_addend
= 0;
5698 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5700 htab
->tls_ld_got
.offset
|= 1;
5702 relocation
= htab
->elf
.sgot
->output_section
->vma
5703 + htab
->elf
.sgot
->output_offset
+ off
;
5704 unresolved_reloc
= FALSE
;
5707 case R_X86_64_DTPOFF32
:
5708 if (!bfd_link_executable (info
)
5709 || (input_section
->flags
& SEC_CODE
) == 0)
5710 relocation
-= elf_x86_64_dtpoff_base (info
);
5712 relocation
= elf_x86_64_tpoff (info
, relocation
);
5715 case R_X86_64_TPOFF32
:
5716 case R_X86_64_TPOFF64
:
5717 BFD_ASSERT (bfd_link_executable (info
));
5718 relocation
= elf_x86_64_tpoff (info
, relocation
);
5721 case R_X86_64_DTPOFF64
:
5722 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5723 relocation
-= elf_x86_64_dtpoff_base (info
);
5730 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5731 because such sections are not SEC_ALLOC and thus ld.so will
5732 not process them. */
5733 if (unresolved_reloc
5734 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5736 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5737 rel
->r_offset
) != (bfd_vma
) -1)
5740 /* xgettext:c-format */
5741 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
5746 h
->root
.root
.string
);
5751 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5752 contents
, rel
->r_offset
,
5753 relocation
, rel
->r_addend
);
5755 check_relocation_error
:
5756 if (r
!= bfd_reloc_ok
)
5761 name
= h
->root
.root
.string
;
5764 name
= bfd_elf_string_from_elf_section (input_bfd
,
5765 symtab_hdr
->sh_link
,
5770 name
= bfd_section_name (input_bfd
, sec
);
5773 if (r
== bfd_reloc_overflow
)
5774 (*info
->callbacks
->reloc_overflow
)
5775 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5776 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5780 /* xgettext:c-format */
5781 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
5782 input_bfd
, input_section
,
5783 rel
->r_offset
, name
, (int) r
);
5794 Elf_Internal_Shdr
*rel_hdr
;
5795 size_t deleted
= rel
- wrel
;
5797 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5798 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5799 if (rel_hdr
->sh_size
== 0)
5801 /* It is too late to remove an empty reloc section. Leave
5803 ??? What is wrong with an empty section??? */
5804 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5807 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5808 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5809 input_section
->reloc_count
-= deleted
;
5815 /* Finish up dynamic symbol handling. We set the contents of various
5816 dynamic sections here. */
5819 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5820 struct bfd_link_info
*info
,
5821 struct elf_link_hash_entry
*h
,
5822 Elf_Internal_Sym
*sym
)
5824 struct elf_x86_64_link_hash_table
*htab
;
5825 bfd_boolean use_plt_second
;
5826 struct elf_x86_64_link_hash_entry
*eh
;
5827 bfd_boolean local_undefweak
;
5829 htab
= elf_x86_64_hash_table (info
);
5833 /* Use the second PLT section only if there is .plt section. */
5834 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5836 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5837 if (eh
->no_finish_dynamic_symbol
)
5840 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5841 resolved undefined weak symbols in executable so that their
5842 references have value 0 at run-time. */
5843 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5847 if (h
->plt
.offset
!= (bfd_vma
) -1)
5850 bfd_vma got_offset
, plt_offset
;
5851 Elf_Internal_Rela rela
;
5853 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5854 const struct elf_backend_data
*bed
;
5855 bfd_vma plt_got_pcrel_offset
;
5857 /* When building a static executable, use .iplt, .igot.plt and
5858 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5859 if (htab
->elf
.splt
!= NULL
)
5861 plt
= htab
->elf
.splt
;
5862 gotplt
= htab
->elf
.sgotplt
;
5863 relplt
= htab
->elf
.srelplt
;
5867 plt
= htab
->elf
.iplt
;
5868 gotplt
= htab
->elf
.igotplt
;
5869 relplt
= htab
->elf
.irelplt
;
5872 /* This symbol has an entry in the procedure linkage table. Set
5874 if ((h
->dynindx
== -1
5876 && !((h
->forced_local
|| bfd_link_executable (info
))
5878 && h
->type
== STT_GNU_IFUNC
))
5884 /* Get the index in the procedure linkage table which
5885 corresponds to this symbol. This is the index of this symbol
5886 in all the symbols for which we are making plt entries. The
5887 first entry in the procedure linkage table is reserved.
5889 Get the offset into the .got table of the entry that
5890 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5891 bytes. The first three are reserved for the dynamic linker.
5893 For static executables, we don't reserve anything. */
5895 if (plt
== htab
->elf
.splt
)
5897 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
5898 - htab
->plt
.has_plt0
);
5899 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5903 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
5904 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5907 /* Fill in the entry in the procedure linkage table. */
5908 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5909 htab
->plt
.plt_entry_size
);
5912 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5913 htab
->non_lazy_plt
->plt_entry
,
5914 htab
->non_lazy_plt
->plt_entry_size
);
5916 resolved_plt
= htab
->plt_second
;
5917 plt_offset
= eh
->plt_second
.offset
;
5922 plt_offset
= h
->plt
.offset
;
5925 /* Insert the relocation positions of the plt section. */
5927 /* Put offset the PC-relative instruction referring to the GOT entry,
5928 subtracting the size of that instruction. */
5929 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5930 + gotplt
->output_offset
5932 - resolved_plt
->output_section
->vma
5933 - resolved_plt
->output_offset
5935 - htab
->plt
.plt_got_insn_size
);
5937 /* Check PC-relative offset overflow in PLT entry. */
5938 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5939 /* xgettext:c-format */
5940 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5941 output_bfd
, h
->root
.root
.string
);
5943 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5944 (resolved_plt
->contents
+ plt_offset
5945 + htab
->plt
.plt_got_offset
));
5947 /* Fill in the entry in the global offset table, initially this
5948 points to the second part of the PLT entry. Leave the entry
5949 as zero for undefined weak symbol in PIE. No PLT relocation
5950 against undefined weak symbol in PIE. */
5951 if (!local_undefweak
)
5953 if (htab
->plt
.has_plt0
)
5954 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5955 + plt
->output_offset
5957 + htab
->lazy_plt
->plt_lazy_offset
),
5958 gotplt
->contents
+ got_offset
);
5960 /* Fill in the entry in the .rela.plt section. */
5961 rela
.r_offset
= (gotplt
->output_section
->vma
5962 + gotplt
->output_offset
5964 if (h
->dynindx
== -1
5965 || ((bfd_link_executable (info
)
5966 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5968 && h
->type
== STT_GNU_IFUNC
))
5970 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5971 h
->root
.root
.string
,
5972 h
->root
.u
.def
.section
->owner
);
5974 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5975 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5976 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5977 rela
.r_addend
= (h
->root
.u
.def
.value
5978 + h
->root
.u
.def
.section
->output_section
->vma
5979 + h
->root
.u
.def
.section
->output_offset
);
5980 /* R_X86_64_IRELATIVE comes last. */
5981 plt_index
= htab
->next_irelative_index
--;
5985 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5987 plt_index
= htab
->next_jump_slot_index
++;
5990 /* Don't fill the second and third slots in PLT entry for
5991 static executables nor without PLT0. */
5992 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5995 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
5997 /* Put relocation index. */
5998 bfd_put_32 (output_bfd
, plt_index
,
5999 (plt
->contents
+ h
->plt
.offset
6000 + htab
->lazy_plt
->plt_reloc_offset
));
6002 /* Put offset for jmp .PLT0 and check for overflow. We don't
6003 check relocation index for overflow since branch displacement
6004 will overflow first. */
6005 if (plt0_offset
> 0x80000000)
6006 /* xgettext:c-format */
6007 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
6008 output_bfd
, h
->root
.root
.string
);
6009 bfd_put_32 (output_bfd
, - plt0_offset
,
6010 (plt
->contents
+ h
->plt
.offset
6011 + htab
->lazy_plt
->plt_plt_offset
));
6014 bed
= get_elf_backend_data (output_bfd
);
6015 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
6016 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
6019 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
6021 bfd_vma got_offset
, plt_offset
;
6022 asection
*plt
, *got
;
6023 bfd_boolean got_after_plt
;
6024 int32_t got_pcrel_offset
;
6026 /* Set the entry in the GOT procedure linkage table. */
6027 plt
= htab
->plt_got
;
6028 got
= htab
->elf
.sgot
;
6029 got_offset
= h
->got
.offset
;
6031 if (got_offset
== (bfd_vma
) -1
6032 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
6037 /* Use the non-lazy PLT entry template for the GOT PLT since they
6038 are the identical. */
6039 /* Fill in the entry in the GOT procedure linkage table. */
6040 plt_offset
= eh
->plt_got
.offset
;
6041 memcpy (plt
->contents
+ plt_offset
,
6042 htab
->non_lazy_plt
->plt_entry
,
6043 htab
->non_lazy_plt
->plt_entry_size
);
6045 /* Put offset the PC-relative instruction referring to the GOT
6046 entry, subtracting the size of that instruction. */
6047 got_pcrel_offset
= (got
->output_section
->vma
6048 + got
->output_offset
6050 - plt
->output_section
->vma
6051 - plt
->output_offset
6053 - htab
->non_lazy_plt
->plt_got_insn_size
);
6055 /* Check PC-relative offset overflow in GOT PLT entry. */
6056 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
6057 if ((got_after_plt
&& got_pcrel_offset
< 0)
6058 || (!got_after_plt
&& got_pcrel_offset
> 0))
6059 /* xgettext:c-format */
6060 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
6061 output_bfd
, h
->root
.root
.string
);
6063 bfd_put_32 (output_bfd
, got_pcrel_offset
,
6064 (plt
->contents
+ plt_offset
6065 + htab
->non_lazy_plt
->plt_got_offset
));
6068 if (!local_undefweak
6070 && (h
->plt
.offset
!= (bfd_vma
) -1
6071 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
6073 /* Mark the symbol as undefined, rather than as defined in
6074 the .plt section. Leave the value if there were any
6075 relocations where pointer equality matters (this is a clue
6076 for the dynamic linker, to make function pointer
6077 comparisons work between an application and shared
6078 library), otherwise set it to zero. If a function is only
6079 called from a binary, there is no need to slow down
6080 shared libraries because of that. */
6081 sym
->st_shndx
= SHN_UNDEF
;
6082 if (!h
->pointer_equality_needed
)
6086 /* Don't generate dynamic GOT relocation against undefined weak
6087 symbol in executable. */
6088 if (h
->got
.offset
!= (bfd_vma
) -1
6089 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
6090 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
6091 && !local_undefweak
)
6093 Elf_Internal_Rela rela
;
6094 asection
*relgot
= htab
->elf
.srelgot
;
6096 /* This symbol has an entry in the global offset table. Set it
6098 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
6101 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
6102 + htab
->elf
.sgot
->output_offset
6103 + (h
->got
.offset
&~ (bfd_vma
) 1));
6105 /* If this is a static link, or it is a -Bsymbolic link and the
6106 symbol is defined locally or was forced to be local because
6107 of a version file, we just want to emit a RELATIVE reloc.
6108 The entry in the global offset table will already have been
6109 initialized in the relocate_section function. */
6111 && h
->type
== STT_GNU_IFUNC
)
6113 if (h
->plt
.offset
== (bfd_vma
) -1)
6115 /* STT_GNU_IFUNC is referenced without PLT. */
6116 if (htab
->elf
.splt
== NULL
)
6118 /* use .rel[a].iplt section to store .got relocations
6119 in static executable. */
6120 relgot
= htab
->elf
.irelplt
;
6122 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
6124 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
6126 h
->root
.root
.string
,
6127 h
->root
.u
.def
.section
->owner
);
6129 rela
.r_info
= htab
->r_info (0,
6130 R_X86_64_IRELATIVE
);
6131 rela
.r_addend
= (h
->root
.u
.def
.value
6132 + h
->root
.u
.def
.section
->output_section
->vma
6133 + h
->root
.u
.def
.section
->output_offset
);
6138 else if (bfd_link_pic (info
))
6140 /* Generate R_X86_64_GLOB_DAT. */
6148 if (!h
->pointer_equality_needed
)
6151 /* For non-shared object, we can't use .got.plt, which
6152 contains the real function addres if we need pointer
6153 equality. We load the GOT entry with the PLT entry. */
6154 if (htab
->plt_second
!= NULL
)
6156 plt
= htab
->plt_second
;
6157 plt_offset
= eh
->plt_second
.offset
;
6161 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
6162 plt_offset
= h
->plt
.offset
;
6164 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
6165 + plt
->output_offset
6167 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6171 else if (bfd_link_pic (info
)
6172 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6174 if (!h
->def_regular
)
6176 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6177 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
6178 rela
.r_addend
= (h
->root
.u
.def
.value
6179 + h
->root
.u
.def
.section
->output_section
->vma
6180 + h
->root
.u
.def
.section
->output_offset
);
6184 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6186 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6187 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6188 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6192 elf_append_rela (output_bfd
, relgot
, &rela
);
6197 Elf_Internal_Rela rela
;
6200 /* This symbol needs a copy reloc. Set it up. */
6202 if (h
->dynindx
== -1
6203 || (h
->root
.type
!= bfd_link_hash_defined
6204 && h
->root
.type
!= bfd_link_hash_defweak
)
6205 || htab
->elf
.srelbss
== NULL
6206 || htab
->elf
.sreldynrelro
== NULL
)
6209 rela
.r_offset
= (h
->root
.u
.def
.value
6210 + h
->root
.u
.def
.section
->output_section
->vma
6211 + h
->root
.u
.def
.section
->output_offset
);
6212 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6214 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6215 s
= htab
->elf
.sreldynrelro
;
6217 s
= htab
->elf
.srelbss
;
6218 elf_append_rela (output_bfd
, s
, &rela
);
6224 /* Finish up local dynamic symbol handling. We set the contents of
6225 various dynamic sections here. */
6228 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6230 struct elf_link_hash_entry
*h
6231 = (struct elf_link_hash_entry
*) *slot
;
6232 struct bfd_link_info
*info
6233 = (struct bfd_link_info
*) inf
;
6235 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6239 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6240 here since undefined weak symbol may not be dynamic and may not be
6241 called for elf_x86_64_finish_dynamic_symbol. */
6244 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6247 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6248 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6250 if (h
->root
.type
!= bfd_link_hash_undefweak
6251 || h
->dynindx
!= -1)
6254 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6258 /* Used to decide how to sort relocs in an optimal manner for the
6259 dynamic linker, before writing them out. */
6261 static enum elf_reloc_type_class
6262 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6263 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6264 const Elf_Internal_Rela
*rela
)
6266 bfd
*abfd
= info
->output_bfd
;
6267 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6268 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6270 if (htab
->elf
.dynsym
!= NULL
6271 && htab
->elf
.dynsym
->contents
!= NULL
)
6273 /* Check relocation against STT_GNU_IFUNC symbol if there are
6275 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6276 if (r_symndx
!= STN_UNDEF
)
6278 Elf_Internal_Sym sym
;
6279 if (!bed
->s
->swap_symbol_in (abfd
,
6280 (htab
->elf
.dynsym
->contents
6281 + r_symndx
* bed
->s
->sizeof_sym
),
6285 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6286 return reloc_class_ifunc
;
6290 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6292 case R_X86_64_IRELATIVE
:
6293 return reloc_class_ifunc
;
6294 case R_X86_64_RELATIVE
:
6295 case R_X86_64_RELATIVE64
:
6296 return reloc_class_relative
;
6297 case R_X86_64_JUMP_SLOT
:
6298 return reloc_class_plt
;
6300 return reloc_class_copy
;
6302 return reloc_class_normal
;
6306 /* Finish up the dynamic sections. */
6309 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6310 struct bfd_link_info
*info
)
6312 struct elf_x86_64_link_hash_table
*htab
;
6316 htab
= elf_x86_64_hash_table (info
);
6320 dynobj
= htab
->elf
.dynobj
;
6321 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6323 if (htab
->elf
.dynamic_sections_created
)
6325 bfd_byte
*dyncon
, *dynconend
;
6326 const struct elf_backend_data
*bed
;
6327 bfd_size_type sizeof_dyn
;
6329 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6332 bed
= get_elf_backend_data (dynobj
);
6333 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6334 dyncon
= sdyn
->contents
;
6335 dynconend
= sdyn
->contents
+ sdyn
->size
;
6336 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6338 Elf_Internal_Dyn dyn
;
6341 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6349 s
= htab
->elf
.sgotplt
;
6350 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6354 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6358 s
= htab
->elf
.srelplt
->output_section
;
6359 dyn
.d_un
.d_val
= s
->size
;
6362 case DT_TLSDESC_PLT
:
6364 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6365 + htab
->tlsdesc_plt
;
6368 case DT_TLSDESC_GOT
:
6370 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6371 + htab
->tlsdesc_got
;
6375 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6378 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6380 elf_section_data (htab
->elf
.splt
->output_section
)
6381 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
6383 if (htab
->plt
.has_plt0
)
6385 /* Fill in the special first entry in the procedure linkage
6387 memcpy (htab
->elf
.splt
->contents
,
6388 htab
->lazy_plt
->plt0_entry
,
6389 htab
->lazy_plt
->plt_entry_size
);
6390 /* Add offset for pushq GOT+8(%rip), since the instruction
6391 uses 6 bytes subtract this value. */
6392 bfd_put_32 (output_bfd
,
6393 (htab
->elf
.sgotplt
->output_section
->vma
6394 + htab
->elf
.sgotplt
->output_offset
6396 - htab
->elf
.splt
->output_section
->vma
6397 - htab
->elf
.splt
->output_offset
6399 (htab
->elf
.splt
->contents
6400 + htab
->lazy_plt
->plt0_got1_offset
));
6401 /* Add offset for the PC-relative instruction accessing
6402 GOT+16, subtracting the offset to the end of that
6404 bfd_put_32 (output_bfd
,
6405 (htab
->elf
.sgotplt
->output_section
->vma
6406 + htab
->elf
.sgotplt
->output_offset
6408 - htab
->elf
.splt
->output_section
->vma
6409 - htab
->elf
.splt
->output_offset
6410 - htab
->lazy_plt
->plt0_got2_insn_end
),
6411 (htab
->elf
.splt
->contents
6412 + htab
->lazy_plt
->plt0_got2_offset
));
6414 if (htab
->tlsdesc_plt
)
6416 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6417 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6419 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6420 htab
->lazy_plt
->plt0_entry
,
6421 htab
->lazy_plt
->plt_entry_size
);
6423 /* Add offset for pushq GOT+8(%rip), since the
6424 instruction uses 6 bytes subtract this value. */
6425 bfd_put_32 (output_bfd
,
6426 (htab
->elf
.sgotplt
->output_section
->vma
6427 + htab
->elf
.sgotplt
->output_offset
6429 - htab
->elf
.splt
->output_section
->vma
6430 - htab
->elf
.splt
->output_offset
6433 (htab
->elf
.splt
->contents
6435 + htab
->lazy_plt
->plt0_got1_offset
));
6436 /* Add offset for the PC-relative instruction accessing
6437 GOT+TDG, where TDG stands for htab->tlsdesc_got,
6438 subtracting the offset to the end of that
6440 bfd_put_32 (output_bfd
,
6441 (htab
->elf
.sgot
->output_section
->vma
6442 + htab
->elf
.sgot
->output_offset
6444 - htab
->elf
.splt
->output_section
->vma
6445 - htab
->elf
.splt
->output_offset
6447 - htab
->lazy_plt
->plt0_got2_insn_end
),
6448 (htab
->elf
.splt
->contents
6450 + htab
->lazy_plt
->plt0_got2_offset
));
6456 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
6457 elf_section_data (htab
->plt_got
->output_section
)
6458 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6460 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
6461 elf_section_data (htab
->plt_second
->output_section
)
6462 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6464 /* GOT is always created in setup_gnu_properties. But it may not be
6466 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
6468 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6471 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6475 /* Set the first entry in the global offset table to the address of
6476 the dynamic section. */
6478 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6480 bfd_put_64 (output_bfd
,
6481 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6482 htab
->elf
.sgotplt
->contents
);
6483 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6484 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6485 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6486 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6487 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6489 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
6493 /* Adjust .eh_frame for .plt section. */
6494 if (htab
->plt_eh_frame
!= NULL
6495 && htab
->plt_eh_frame
->contents
!= NULL
)
6497 if (htab
->elf
.splt
!= NULL
6498 && htab
->elf
.splt
->size
!= 0
6499 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6500 && htab
->elf
.splt
->output_section
!= NULL
6501 && htab
->plt_eh_frame
->output_section
!= NULL
)
6503 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6504 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6505 + htab
->plt_eh_frame
->output_offset
6506 + PLT_FDE_START_OFFSET
;
6507 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6508 htab
->plt_eh_frame
->contents
6509 + PLT_FDE_START_OFFSET
);
6511 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6513 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6515 htab
->plt_eh_frame
->contents
))
6520 /* Adjust .eh_frame for .plt.got section. */
6521 if (htab
->plt_got_eh_frame
!= NULL
6522 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6524 if (htab
->plt_got
!= NULL
6525 && htab
->plt_got
->size
!= 0
6526 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6527 && htab
->plt_got
->output_section
!= NULL
6528 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6530 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6531 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6532 + htab
->plt_got_eh_frame
->output_offset
6533 + PLT_FDE_START_OFFSET
;
6534 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6535 htab
->plt_got_eh_frame
->contents
6536 + PLT_FDE_START_OFFSET
);
6538 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6540 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6541 htab
->plt_got_eh_frame
,
6542 htab
->plt_got_eh_frame
->contents
))
6547 /* Adjust .eh_frame for the second PLT section. */
6548 if (htab
->plt_second_eh_frame
!= NULL
6549 && htab
->plt_second_eh_frame
->contents
!= NULL
)
6551 if (htab
->plt_second
!= NULL
6552 && htab
->plt_second
->size
!= 0
6553 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
6554 && htab
->plt_second
->output_section
!= NULL
6555 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
6557 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
6558 bfd_vma eh_frame_start
6559 = (htab
->plt_second_eh_frame
->output_section
->vma
6560 + htab
->plt_second_eh_frame
->output_offset
6561 + PLT_FDE_START_OFFSET
);
6562 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6563 htab
->plt_second_eh_frame
->contents
6564 + PLT_FDE_START_OFFSET
);
6566 if (htab
->plt_second_eh_frame
->sec_info_type
6567 == SEC_INFO_TYPE_EH_FRAME
)
6569 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6570 htab
->plt_second_eh_frame
,
6571 htab
->plt_second_eh_frame
->contents
))
6576 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6577 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6580 /* Fill PLT entries for undefined weak symbols in PIE. */
6581 if (bfd_link_pie (info
))
6582 bfd_hash_traverse (&info
->hash
->table
,
6583 elf_x86_64_pie_finish_undefweak_symbol
,
6589 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6590 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6591 It has to be done before elf_link_sort_relocs is called so that
6592 dynamic relocations are properly sorted. */
6595 elf_x86_64_output_arch_local_syms
6596 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6597 struct bfd_link_info
*info
,
6598 void *flaginfo ATTRIBUTE_UNUSED
,
6599 int (*func
) (void *, const char *,
6602 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6604 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6608 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6609 htab_traverse (htab
->loc_hash_table
,
6610 elf_x86_64_finish_local_dynamic_symbol
,
6616 /* Sort relocs into address order. */
6619 compare_relocs (const void *ap
, const void *bp
)
6621 const arelent
*a
= * (const arelent
**) ap
;
6622 const arelent
*b
= * (const arelent
**) bp
;
6624 if (a
->address
> b
->address
)
6626 else if (a
->address
< b
->address
)
6632 enum elf_x86_64_plt_type
6636 plt_second
= 1 << 1,
6640 struct elf_x86_64_plt
6645 enum elf_x86_64_plt_type type
;
6646 unsigned int plt_got_offset
;
6647 unsigned int plt_got_insn_size
;
6648 unsigned int plt_entry_size
;
6652 /* Forward declaration. */
6653 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_nacl_plt
;
6655 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6656 dynamic relocations. */
6659 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6660 long symcount ATTRIBUTE_UNUSED
,
6661 asymbol
**syms ATTRIBUTE_UNUSED
,
6666 long size
, count
, i
, n
;
6668 unsigned int plt_got_offset
, plt_entry_size
, plt_got_insn_size
;
6670 bfd_byte
*plt_contents
;
6671 long dynrelcount
, relsize
;
6672 arelent
**dynrelbuf
;
6673 const struct elf_x86_64_lazy_plt_layout
*lazy_plt
;
6674 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_plt
;
6675 const struct elf_x86_64_lazy_plt_layout
*lazy_bnd_plt
;
6676 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_bnd_plt
;
6677 const struct elf_x86_64_lazy_plt_layout
*lazy_ibt_plt
;
6678 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_ibt_plt
;
6681 enum elf_x86_64_plt_type plt_type
;
6682 struct elf_x86_64_plt plts
[] =
6684 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
6685 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
6686 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
6687 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
6688 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
6693 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
6696 if (dynsymcount
<= 0)
6699 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
6703 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6704 if (dynrelbuf
== NULL
)
6707 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6710 /* Sort the relocs by address. */
6711 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*), compare_relocs
);
6713 if (get_elf_x86_64_backend_data (abfd
)->os
== is_normal
)
6715 lazy_plt
= &elf_x86_64_lazy_plt
;
6716 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
6717 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
6718 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
6719 if (ABI_64_P (abfd
))
6721 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
6722 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
6726 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
6727 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
6732 lazy_plt
= &elf_x86_64_nacl_plt
;
6733 non_lazy_plt
= NULL
;
6734 lazy_bnd_plt
= NULL
;
6735 non_lazy_bnd_plt
= NULL
;
6736 lazy_ibt_plt
= NULL
;
6737 non_lazy_ibt_plt
= NULL
;
6741 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6743 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
6747 /* Get the PLT section contents. */
6748 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6749 if (plt_contents
== NULL
)
6751 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6752 plt_contents
, 0, plt
->size
))
6754 free (plt_contents
);
6758 /* Check what kind of PLT it is. */
6759 plt_type
= plt_unknown
;
6760 if (plts
[j
].type
== plt_unknown
)
6762 /* Match lazy PLT first. Need to check the first two
6764 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
6765 lazy_plt
->plt0_got1_offset
) == 0)
6766 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
6768 plt_type
= plt_lazy
;
6769 else if (lazy_bnd_plt
!= NULL
6770 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
6771 lazy_bnd_plt
->plt0_got1_offset
) == 0)
6772 && (memcmp (plt_contents
+ 6,
6773 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
6775 plt_type
= plt_lazy
| plt_second
;
6776 /* The fist entry in the lazy IBT PLT is the same as the
6778 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
6779 lazy_ibt_plt
->plt_entry
,
6780 lazy_ibt_plt
->plt_got_offset
) == 0))
6781 lazy_plt
= lazy_ibt_plt
;
6783 lazy_plt
= lazy_bnd_plt
;
6787 if (non_lazy_plt
!= NULL
6788 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
))
6790 /* Match non-lazy PLT. */
6791 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
6792 non_lazy_plt
->plt_got_offset
) == 0)
6793 plt_type
= plt_non_lazy
;
6796 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
6798 if (non_lazy_bnd_plt
!= NULL
6799 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
6800 non_lazy_bnd_plt
->plt_got_offset
) == 0))
6802 /* Match BND PLT. */
6803 plt_type
= plt_second
;
6804 non_lazy_plt
= non_lazy_bnd_plt
;
6806 else if (non_lazy_ibt_plt
!= NULL
6807 && (memcmp (plt_contents
,
6808 non_lazy_ibt_plt
->plt_entry
,
6809 non_lazy_ibt_plt
->plt_got_offset
) == 0))
6811 /* Match IBT PLT. */
6812 plt_type
= plt_second
;
6813 non_lazy_plt
= non_lazy_ibt_plt
;
6817 if (plt_type
== plt_unknown
)
6821 plts
[j
].type
= plt_type
;
6823 if ((plt_type
& plt_lazy
))
6825 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
6826 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
6827 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
6828 /* Skip PLT0 in lazy PLT. */
6833 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
6834 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
6835 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
6839 /* Skip lazy PLT when the second PLT is used. */
6840 if (plt_type
== (plt_lazy
| plt_second
))
6844 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6849 plts
[j
].contents
= plt_contents
;
6852 size
= count
* sizeof (asymbol
);
6853 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6857 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6858 if (plts
[j
].contents
!= NULL
)
6859 free (plts
[j
].contents
);
6864 /* Check for each PLT section. */
6867 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6868 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6873 plt_got_offset
= plts
[j
].plt_got_offset
;
6874 plt_got_insn_size
= plts
[j
].plt_got_insn_size
;
6875 plt_entry_size
= plts
[j
].plt_entry_size
;
6879 if ((plts
[j
].type
& plt_lazy
))
6881 /* Skip PLT0 in lazy PLT. */
6883 offset
= plt_entry_size
;
6891 /* Check each PLT entry against dynamic relocations. */
6892 for (; k
< plts
[j
].count
; k
++)
6899 /* Get the PC-relative offset, a signed 32-bit integer. */
6900 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6902 got_vma
= plt
->vma
+ offset
+ off
+ plt_got_insn_size
;
6904 /* Binary search. */
6908 while ((min
+ 1) < max
)
6912 mid
= (min
+ max
) / 2;
6914 if (got_vma
> r
->address
)
6916 else if (got_vma
< r
->address
)
6925 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6926 if (got_vma
== p
->address
6928 && (p
->howto
->type
== R_X86_64_JUMP_SLOT
6929 || p
->howto
->type
== R_X86_64_GLOB_DAT
6930 || p
->howto
->type
== R_X86_64_IRELATIVE
))
6932 *s
= **p
->sym_ptr_ptr
;
6933 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6934 set. Since we are defining a symbol, ensure one
6936 if ((s
->flags
& BSF_LOCAL
) == 0)
6937 s
->flags
|= BSF_GLOBAL
;
6938 s
->flags
|= BSF_SYNTHETIC
;
6939 /* This is no longer a section symbol. */
6940 s
->flags
&= ~BSF_SECTION_SYM
;
6942 s
->the_bfd
= plt
->owner
;
6944 /* Store relocation for later use. */
6946 /* Add @plt to function name later. */
6947 size
+= strlen (s
->name
) + sizeof ("@plt");
6949 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
6953 offset
+= plt_entry_size
;
6957 /* PLT entries with R_X86_64_TLSDESC relocations are skipped. */
6963 /* Allocate space for @plt suffixes. */
6964 names
= (char *) bfd_malloc (size
);
6969 for (i
= 0; i
< count
; i
++)
6971 /* Add @plt to function name. */
6972 arelent
*p
= (arelent
*) s
->udata
.p
;
6975 size
= strlen (s
->name
);
6976 memcpy (names
, s
->name
, size
);
6983 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6984 names
+= sizeof ("+0x") - 1;
6985 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6986 for (a
= buf
; *a
== '0'; ++a
)
6989 memcpy (names
, a
, size
);
6992 memcpy (names
, "@plt", sizeof ("@plt"));
6993 names
+= sizeof ("@plt");
6997 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6998 if (plts
[j
].contents
!= NULL
)
6999 free (plts
[j
].contents
);
7006 /* Handle an x86-64 specific section when reading an object file. This
7007 is called when elfcode.h finds a section with an unknown type. */
7010 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
7011 const char *name
, int shindex
)
7013 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
7016 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7022 /* Hook called by the linker routine which adds symbols from an object
7023 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
7027 elf_x86_64_add_symbol_hook (bfd
*abfd
,
7028 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7029 Elf_Internal_Sym
*sym
,
7030 const char **namep ATTRIBUTE_UNUSED
,
7031 flagword
*flagsp ATTRIBUTE_UNUSED
,
7037 switch (sym
->st_shndx
)
7039 case SHN_X86_64_LCOMMON
:
7040 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
7043 lcomm
= bfd_make_section_with_flags (abfd
,
7047 | SEC_LINKER_CREATED
));
7050 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
7053 *valp
= sym
->st_size
;
7061 /* Given a BFD section, try to locate the corresponding ELF section
7065 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
7066 asection
*sec
, int *index_return
)
7068 if (sec
== &_bfd_elf_large_com_section
)
7070 *index_return
= SHN_X86_64_LCOMMON
;
7076 /* Process a symbol. */
7079 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
7082 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
7084 switch (elfsym
->internal_elf_sym
.st_shndx
)
7086 case SHN_X86_64_LCOMMON
:
7087 asym
->section
= &_bfd_elf_large_com_section
;
7088 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
7089 /* Common symbol doesn't set BSF_GLOBAL. */
7090 asym
->flags
&= ~BSF_GLOBAL
;
7096 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
7098 return (sym
->st_shndx
== SHN_COMMON
7099 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
7103 elf_x86_64_common_section_index (asection
*sec
)
7105 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
7108 return SHN_X86_64_LCOMMON
;
7112 elf_x86_64_common_section (asection
*sec
)
7114 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
7115 return bfd_com_section_ptr
;
7117 return &_bfd_elf_large_com_section
;
7121 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
7122 const Elf_Internal_Sym
*sym
,
7127 const asection
*oldsec
)
7129 /* A normal common symbol and a large common symbol result in a
7130 normal common symbol. We turn the large common symbol into a
7133 && h
->root
.type
== bfd_link_hash_common
7135 && bfd_is_com_section (*psec
)
7138 if (sym
->st_shndx
== SHN_COMMON
7139 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
7141 h
->root
.u
.c
.p
->section
7142 = bfd_make_section_old_way (oldbfd
, "COMMON");
7143 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
7145 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
7146 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
7147 *psec
= bfd_com_section_ptr
;
7154 elf_x86_64_additional_program_headers (bfd
*abfd
,
7155 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
7160 /* Check to see if we need a large readonly segment. */
7161 s
= bfd_get_section_by_name (abfd
, ".lrodata");
7162 if (s
&& (s
->flags
& SEC_LOAD
))
7165 /* Check to see if we need a large data segment. Since .lbss sections
7166 is placed right after the .bss section, there should be no need for
7167 a large data segment just because of .lbss. */
7168 s
= bfd_get_section_by_name (abfd
, ".ldata");
7169 if (s
&& (s
->flags
& SEC_LOAD
))
7175 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
7178 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
7180 if (h
->plt
.offset
!= (bfd_vma
) -1
7182 && !h
->pointer_equality_needed
)
7185 return _bfd_elf_hash_symbol (h
);
7188 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
7191 elf_x86_64_relocs_compatible (const bfd_target
*input
,
7192 const bfd_target
*output
)
7194 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
7195 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
7196 && _bfd_elf_relocs_compatible (input
, output
));
7199 /* Parse x86-64 GNU properties. */
7201 static enum elf_property_kind
7202 elf_x86_64_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
7203 bfd_byte
*ptr
, unsigned int datasz
)
7209 case GNU_PROPERTY_X86_ISA_1_USED
:
7210 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
7211 case GNU_PROPERTY_X86_FEATURE_1_AND
:
7215 ((type
== GNU_PROPERTY_X86_ISA_1_USED
7216 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
7217 : (type
== GNU_PROPERTY_X86_ISA_1_NEEDED
7218 ? _("error: %B: <corrupt x86 ISA needed size: 0x%x>")
7219 : _("error: %B: <corrupt x86 feature size: 0x%x>"))),
7221 return property_corrupt
;
7223 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
7224 /* Combine properties of the same type. */
7225 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
7226 prop
->pr_kind
= property_number
;
7230 return property_ignored
;
7233 return property_number
;
7236 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
7237 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
7238 should be merged with ABFD. */
7241 elf_x86_64_merge_gnu_properties (struct bfd_link_info
*info
,
7242 bfd
*abfd ATTRIBUTE_UNUSED
,
7243 elf_property
*aprop
,
7244 elf_property
*bprop
)
7246 unsigned int number
, features
;
7247 bfd_boolean updated
= FALSE
;
7248 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
7252 case GNU_PROPERTY_X86_ISA_1_USED
:
7253 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
7254 if (aprop
!= NULL
&& bprop
!= NULL
)
7256 number
= aprop
->u
.number
;
7257 aprop
->u
.number
= number
| bprop
->u
.number
;
7258 updated
= number
!= (unsigned int) aprop
->u
.number
;
7262 /* Return TRUE if APROP is NULL to indicate that BPROP should
7263 be added to ABFD. */
7264 updated
= aprop
== NULL
;
7268 case GNU_PROPERTY_X86_FEATURE_1_AND
:
7269 /* Only one of APROP and BPROP can be NULL:
7270 1. APROP & BPROP when both APROP and BPROP aren't NULL.
7271 2. If APROP is NULL, remove x86 feature.
7272 3. Otherwise, do nothing.
7274 if (aprop
!= NULL
&& bprop
!= NULL
)
7278 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
7280 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
7281 number
= aprop
->u
.number
;
7282 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
7283 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
7284 aprop
->u
.number
= (number
& bprop
->u
.number
) | features
;
7285 updated
= number
!= (unsigned int) aprop
->u
.number
;
7286 /* Remove the property if all feature bits are cleared. */
7287 if (aprop
->u
.number
== 0)
7288 aprop
->pr_kind
= property_remove
;
7294 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
7296 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
7299 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
7300 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
7303 number
= aprop
->u
.number
;
7304 aprop
->u
.number
= number
| features
;
7305 updated
= number
!= (unsigned int) aprop
->u
.number
;
7309 bprop
->u
.number
|= features
;
7313 else if (aprop
!= NULL
)
7315 aprop
->pr_kind
= property_remove
;
7322 /* Never should happen. */
7329 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
7330 with GNU properties if found. Otherwise, return NULL. */
7333 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
7335 bfd_boolean normal_target
;
7336 bfd_boolean lazy_plt
;
7337 asection
*sec
, *pltsec
;
7339 bfd_boolean use_ibt_plt
;
7340 unsigned int plt_alignment
, features
;
7341 struct elf_x86_64_link_hash_table
*htab
;
7346 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
7348 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
7351 /* Turn on GNU_PROPERTY_X86_FEATURE_1_IBT and
7352 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
7356 for (pbfd
= info
->input_bfds
;
7358 pbfd
= pbfd
->link
.next
)
7359 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
7360 && bfd_count_sections (pbfd
) != 0)
7364 if (elf_properties (pbfd
) != NULL
)
7366 /* Find a normal input file with GNU property note. */
7367 prop
= _bfd_elf_get_property (pbfd
,
7368 GNU_PROPERTY_X86_FEATURE_1_AND
,
7370 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
7371 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
7372 prop
->u
.number
|= features
;
7373 prop
->pr_kind
= property_number
;
7378 if (pbfd
== NULL
&& ebfd
!= NULL
)
7380 /* Create GNU_PROPERTY_X86_FEATURE_1_IBT if needed. */
7381 prop
= _bfd_elf_get_property (ebfd
,
7382 GNU_PROPERTY_X86_FEATURE_1_AND
,
7384 prop
->u
.number
= features
;
7385 prop
->pr_kind
= property_number
;
7387 sec
= bfd_make_section_with_flags (ebfd
,
7388 NOTE_GNU_PROPERTY_SECTION_NAME
,
7396 info
->callbacks
->einfo (_("%F: failed to create GNU property section\n"));
7398 if (!bfd_set_section_alignment (ebfd
, sec
,
7399 ABI_64_P (ebfd
) ? 3 : 2))
7402 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
7406 elf_section_type (sec
) = SHT_NOTE
;
7410 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
7412 if (bfd_link_relocatable (info
))
7415 htab
= elf_x86_64_hash_table (info
);
7419 use_ibt_plt
= info
->ibtplt
|| info
->ibt
;
7420 if (!use_ibt_plt
&& pbfd
!= NULL
)
7422 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
7423 elf_property_list
*p
;
7425 /* The property list is sorted in order of type. */
7426 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
7428 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
7430 use_ibt_plt
= !!(p
->property
.u
.number
7431 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
7434 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
7439 dynobj
= htab
->elf
.dynobj
;
7441 /* Set htab->elf.dynobj here so that there is no need to check and
7442 set it in check_relocs. */
7447 htab
->elf
.dynobj
= pbfd
;
7454 /* Find a normal input file to hold linker created
7456 for (abfd
= info
->input_bfds
;
7458 abfd
= abfd
->link
.next
)
7460 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
7462 htab
->elf
.dynobj
= abfd
;
7469 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
7470 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
7471 canonical function address. */
7472 htab
->plt
.has_plt0
= 1;
7474 if (get_elf_x86_64_backend_data (info
->output_bfd
)->os
7479 if (ABI_64_P (dynobj
))
7481 htab
->lazy_plt
= &elf_x86_64_lazy_ibt_plt
;
7482 htab
->non_lazy_plt
= &elf_x86_64_non_lazy_ibt_plt
;
7486 htab
->lazy_plt
= &elf_x32_lazy_ibt_plt
;
7487 htab
->non_lazy_plt
= &elf_x32_non_lazy_ibt_plt
;
7490 else if (info
->bndplt
)
7492 htab
->lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
7493 htab
->non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
7497 htab
->lazy_plt
= &elf_x86_64_lazy_plt
;
7498 htab
->non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
7500 normal_target
= TRUE
;
7504 htab
->lazy_plt
= &elf_x86_64_nacl_plt
;
7505 htab
->non_lazy_plt
= NULL
;
7506 normal_target
= FALSE
;
7509 pltsec
= htab
->elf
.splt
;
7511 /* If the non-lazy PLT is available, use it for all PLT entries if
7512 there are no PLT0 or no .plt section. */
7513 if (htab
->non_lazy_plt
!= NULL
7514 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
7518 = htab
->non_lazy_plt
->plt_entry
;
7519 htab
->plt
.plt_entry_size
7520 = htab
->non_lazy_plt
->plt_entry_size
;
7521 htab
->plt
.plt_got_offset
7522 = htab
->non_lazy_plt
->plt_got_offset
;
7523 htab
->plt
.plt_got_insn_size
7524 = htab
->non_lazy_plt
->plt_got_insn_size
;
7525 htab
->plt
.eh_frame_plt_size
7526 = htab
->non_lazy_plt
->eh_frame_plt_size
;
7527 htab
->plt
.eh_frame_plt
7528 = htab
->non_lazy_plt
->eh_frame_plt
;
7534 = htab
->lazy_plt
->plt_entry
;
7535 htab
->plt
.plt_entry_size
7536 = htab
->lazy_plt
->plt_entry_size
;
7537 htab
->plt
.plt_got_offset
7538 = htab
->lazy_plt
->plt_got_offset
;
7539 htab
->plt
.plt_got_insn_size
7540 = htab
->lazy_plt
->plt_got_insn_size
;
7541 htab
->plt
.eh_frame_plt_size
7542 = htab
->lazy_plt
->eh_frame_plt_size
;
7543 htab
->plt
.eh_frame_plt
7544 = htab
->lazy_plt
->eh_frame_plt
;
7547 /* Return if there are no normal input files. */
7551 /* Since create_dynamic_sections isn't always called, but GOT
7552 relocations need GOT relocations, create them here so that we
7553 don't need to do it in check_relocs. */
7554 if (htab
->elf
.sgot
== NULL
7555 && !_bfd_elf_create_got_section (dynobj
, info
))
7556 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
7558 /* Align .got and .got.plt sections to their entry size. Do it here
7559 instead of in create_dynamic_sections so that they are always
7560 properly aligned even if create_dynamic_sections isn't called. */
7561 sec
= htab
->elf
.sgot
;
7562 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7563 goto error_alignment
;
7565 sec
= htab
->elf
.sgotplt
;
7566 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7567 goto error_alignment
;
7569 /* Create the ifunc sections here so that check_relocs can be
7571 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
7572 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
7574 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
7578 /* Whe creating executable, set the contents of the .interp
7579 section to the interpreter. */
7580 if (bfd_link_executable (info
) && !info
->nointerp
)
7582 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
7585 s
->size
= htab
->dynamic_interpreter_size
;
7586 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
7590 /* Don't change PLT section alignment for NaCl since it uses
7591 64-byte PLT entry and sets PLT section alignment to 32
7592 bytes. Don't create additional PLT sections for NaCl. */
7595 const struct elf_backend_data
*bed
7596 = get_elf_backend_data (dynobj
);
7597 flagword pltflags
= (bed
->dynamic_sec_flags
7602 unsigned int non_lazy_plt_alignment
7603 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
7606 if (!bfd_set_section_alignment (sec
->owner
, sec
,
7608 goto error_alignment
;
7610 /* Create the GOT procedure linkage table. */
7611 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7615 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
7617 if (!bfd_set_section_alignment (dynobj
, sec
,
7618 non_lazy_plt_alignment
))
7619 goto error_alignment
;
7621 htab
->plt_got
= sec
;
7629 /* Create the second PLT for Intel IBT support. IBT
7630 PLT is supported only for non-NaCl target and is
7631 is needed only for lazy binding. */
7632 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7636 info
->callbacks
->einfo (_("%F: failed to create IBT-enabled PLT section\n"));
7638 if (!bfd_set_section_alignment (dynobj
, sec
,
7640 goto error_alignment
;
7642 else if (info
->bndplt
&& ABI_64_P (dynobj
))
7644 /* Create the second PLT for Intel MPX support. MPX
7645 PLT is supported only for non-NaCl target in 64-bit
7646 mode and is needed only for lazy binding. */
7647 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7651 info
->callbacks
->einfo (_("%F: failed to create BND PLT section\n"));
7653 if (!bfd_set_section_alignment (dynobj
, sec
,
7654 non_lazy_plt_alignment
))
7655 goto error_alignment
;
7658 htab
->plt_second
= sec
;
7662 if (!info
->no_ld_generated_unwind_info
)
7664 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
7665 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7666 | SEC_LINKER_CREATED
);
7668 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7672 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7674 if (!bfd_set_section_alignment (dynobj
, sec
,
7675 ABI_64_P (dynobj
) ? 3 : 2))
7676 goto error_alignment
;
7678 htab
->plt_eh_frame
= sec
;
7680 if (htab
->plt_got
!= NULL
)
7682 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7686 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7688 if (!bfd_set_section_alignment (dynobj
, sec
,
7689 ABI_64_P (dynobj
) ? 3 : 2))
7690 goto error_alignment
;
7692 htab
->plt_got_eh_frame
= sec
;
7695 if (htab
->plt_second
!= NULL
)
7697 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7701 info
->callbacks
->einfo (_("%F: failed to create BND PLT .eh_frame section\n"));
7703 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7704 goto error_alignment
;
7706 htab
->plt_second_eh_frame
= sec
;
7713 /* The .iplt section is used for IFUNC symbols in static
7715 sec
= htab
->elf
.iplt
;
7717 && !bfd_set_section_alignment (sec
->owner
, sec
,
7719 goto error_alignment
;
7725 static const struct bfd_elf_special_section
7726 elf_x86_64_special_sections
[]=
7728 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7729 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7730 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
7731 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7732 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7733 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7734 { NULL
, 0, 0, 0, 0 }
7737 #define TARGET_LITTLE_SYM x86_64_elf64_vec
7738 #define TARGET_LITTLE_NAME "elf64-x86-64"
7739 #define ELF_ARCH bfd_arch_i386
7740 #define ELF_TARGET_ID X86_64_ELF_DATA
7741 #define ELF_MACHINE_CODE EM_X86_64
7742 #define ELF_MAXPAGESIZE 0x200000
7743 #define ELF_MINPAGESIZE 0x1000
7744 #define ELF_COMMONPAGESIZE 0x1000
7746 #define elf_backend_can_gc_sections 1
7747 #define elf_backend_can_refcount 1
7748 #define elf_backend_want_got_plt 1
7749 #define elf_backend_plt_readonly 1
7750 #define elf_backend_want_plt_sym 0
7751 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
7752 #define elf_backend_rela_normal 1
7753 #define elf_backend_plt_alignment 4
7754 #define elf_backend_extern_protected_data 1
7755 #define elf_backend_caches_rawsize 1
7756 #define elf_backend_dtrel_excludes_plt 1
7757 #define elf_backend_want_dynrelro 1
7759 #define elf_info_to_howto elf_x86_64_info_to_howto
7761 #define bfd_elf64_bfd_link_hash_table_create \
7762 elf_x86_64_link_hash_table_create
7763 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7764 #define bfd_elf64_bfd_reloc_name_lookup \
7765 elf_x86_64_reloc_name_lookup
7767 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7768 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7769 #define elf_backend_check_relocs elf_x86_64_check_relocs
7770 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7771 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7772 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7773 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7774 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7775 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7776 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7777 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7779 #define elf_backend_write_core_note elf_x86_64_write_core_note
7781 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7782 #define elf_backend_relocate_section elf_x86_64_relocate_section
7783 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7784 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7785 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7786 #define elf_backend_object_p elf64_x86_64_elf_object_p
7787 #define bfd_elf64_mkobject elf_x86_64_mkobject
7788 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7790 #define elf_backend_section_from_shdr \
7791 elf_x86_64_section_from_shdr
7793 #define elf_backend_section_from_bfd_section \
7794 elf_x86_64_elf_section_from_bfd_section
7795 #define elf_backend_add_symbol_hook \
7796 elf_x86_64_add_symbol_hook
7797 #define elf_backend_symbol_processing \
7798 elf_x86_64_symbol_processing
7799 #define elf_backend_common_section_index \
7800 elf_x86_64_common_section_index
7801 #define elf_backend_common_section \
7802 elf_x86_64_common_section
7803 #define elf_backend_common_definition \
7804 elf_x86_64_common_definition
7805 #define elf_backend_merge_symbol \
7806 elf_x86_64_merge_symbol
7807 #define elf_backend_special_sections \
7808 elf_x86_64_special_sections
7809 #define elf_backend_additional_program_headers \
7810 elf_x86_64_additional_program_headers
7811 #define elf_backend_hash_symbol \
7812 elf_x86_64_hash_symbol
7813 #define elf_backend_omit_section_dynsym \
7814 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7815 #define elf_backend_fixup_symbol \
7816 elf_x86_64_fixup_symbol
7817 #define elf_backend_parse_gnu_properties \
7818 elf_x86_64_parse_gnu_properties
7819 #define elf_backend_merge_gnu_properties \
7820 elf_x86_64_merge_gnu_properties
7821 #define elf_backend_setup_gnu_properties \
7822 elf_x86_64_link_setup_gnu_properties
7824 #include "elf64-target.h"
7826 /* CloudABI support. */
7828 #undef TARGET_LITTLE_SYM
7829 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7830 #undef TARGET_LITTLE_NAME
7831 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7834 #define ELF_OSABI ELFOSABI_CLOUDABI
7837 #define elf64_bed elf64_x86_64_cloudabi_bed
7839 #include "elf64-target.h"
7841 /* FreeBSD support. */
7843 #undef TARGET_LITTLE_SYM
7844 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7845 #undef TARGET_LITTLE_NAME
7846 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7849 #define ELF_OSABI ELFOSABI_FREEBSD
7852 #define elf64_bed elf64_x86_64_fbsd_bed
7854 #include "elf64-target.h"
7856 /* Solaris 2 support. */
7858 #undef TARGET_LITTLE_SYM
7859 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7860 #undef TARGET_LITTLE_NAME
7861 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7863 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7864 objects won't be recognized. */
7868 #define elf64_bed elf64_x86_64_sol2_bed
7870 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7872 #undef elf_backend_static_tls_alignment
7873 #define elf_backend_static_tls_alignment 16
7875 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7877 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7879 #undef elf_backend_want_plt_sym
7880 #define elf_backend_want_plt_sym 1
7882 #undef elf_backend_strtab_flags
7883 #define elf_backend_strtab_flags SHF_STRINGS
7886 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7887 bfd
*obfd ATTRIBUTE_UNUSED
,
7888 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7889 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7891 /* PR 19938: FIXME: Need to add code for setting the sh_info
7892 and sh_link fields of Solaris specific section types. */
7896 #undef elf_backend_copy_special_section_fields
7897 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7899 #include "elf64-target.h"
7901 /* Native Client support. */
7904 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
7906 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7907 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
7911 #undef TARGET_LITTLE_SYM
7912 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7913 #undef TARGET_LITTLE_NAME
7914 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7916 #define elf64_bed elf64_x86_64_nacl_bed
7918 #undef ELF_MAXPAGESIZE
7919 #undef ELF_MINPAGESIZE
7920 #undef ELF_COMMONPAGESIZE
7921 #define ELF_MAXPAGESIZE 0x10000
7922 #define ELF_MINPAGESIZE 0x10000
7923 #define ELF_COMMONPAGESIZE 0x10000
7925 /* Restore defaults. */
7927 #undef elf_backend_static_tls_alignment
7928 #undef elf_backend_want_plt_sym
7929 #define elf_backend_want_plt_sym 0
7930 #undef elf_backend_strtab_flags
7931 #undef elf_backend_copy_special_section_fields
7933 /* NaCl uses substantially different PLT entries for the same effects. */
7935 #undef elf_backend_plt_alignment
7936 #define elf_backend_plt_alignment 5
7937 #define NACL_PLT_ENTRY_SIZE 64
7938 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7940 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
7942 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7943 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7944 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7945 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7946 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7948 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7949 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7951 /* 32 bytes of nop to pad out to the standard size. */
7952 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7953 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7954 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7955 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7956 0x66, /* excess data16 prefix */
7960 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7962 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7963 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7964 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7965 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7967 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7968 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7969 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7971 /* Lazy GOT entries point here (32-byte aligned). */
7972 0x68, /* pushq immediate */
7973 0, 0, 0, 0, /* replaced with index into relocation table. */
7974 0xe9, /* jmp relative */
7975 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7977 /* 22 bytes of nop to pad out to the standard size. */
7978 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7979 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7980 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7983 /* .eh_frame covering the .plt section. */
7985 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
7987 #if (PLT_CIE_LENGTH != 20 \
7988 || PLT_FDE_LENGTH != 36 \
7989 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7990 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7991 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7993 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7994 0, 0, 0, 0, /* CIE ID */
7995 1, /* CIE version */
7996 'z', 'R', 0, /* Augmentation string */
7997 1, /* Code alignment factor */
7998 0x78, /* Data alignment factor */
7999 16, /* Return address column */
8000 1, /* Augmentation size */
8001 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
8002 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
8003 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
8004 DW_CFA_nop
, DW_CFA_nop
,
8006 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
8007 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
8008 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
8009 0, 0, 0, 0, /* .plt size goes here */
8010 0, /* Augmentation size */
8011 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
8012 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
8013 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
8014 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
8015 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
8016 13, /* Block length */
8017 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
8018 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
8019 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
8020 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
8021 DW_CFA_nop
, DW_CFA_nop
8024 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_nacl_plt
=
8026 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
8027 elf_x86_64_nacl_plt_entry
, /* plt_entry */
8028 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
8029 2, /* plt0_got1_offset */
8030 9, /* plt0_got2_offset */
8031 13, /* plt0_got2_insn_end */
8032 3, /* plt_got_offset */
8033 33, /* plt_reloc_offset */
8034 38, /* plt_plt_offset */
8035 7, /* plt_got_insn_size */
8036 42, /* plt_plt_insn_end */
8037 32, /* plt_lazy_offset */
8038 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
8039 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
8042 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
8047 #undef elf_backend_arch_data
8048 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
8050 #undef elf_backend_object_p
8051 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
8052 #undef elf_backend_modify_segment_map
8053 #define elf_backend_modify_segment_map nacl_modify_segment_map
8054 #undef elf_backend_modify_program_headers
8055 #define elf_backend_modify_program_headers nacl_modify_program_headers
8056 #undef elf_backend_final_write_processing
8057 #define elf_backend_final_write_processing nacl_final_write_processing
8059 #include "elf64-target.h"
8061 /* Native Client x32 support. */
8064 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
8066 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
8067 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
8071 #undef TARGET_LITTLE_SYM
8072 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
8073 #undef TARGET_LITTLE_NAME
8074 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
8076 #define elf32_bed elf32_x86_64_nacl_bed
8078 #define bfd_elf32_bfd_link_hash_table_create \
8079 elf_x86_64_link_hash_table_create
8080 #define bfd_elf32_bfd_reloc_type_lookup \
8081 elf_x86_64_reloc_type_lookup
8082 #define bfd_elf32_bfd_reloc_name_lookup \
8083 elf_x86_64_reloc_name_lookup
8084 #define bfd_elf32_mkobject \
8086 #define bfd_elf32_get_synthetic_symtab \
8087 elf_x86_64_get_synthetic_symtab
8089 #undef elf_backend_object_p
8090 #define elf_backend_object_p \
8091 elf32_x86_64_nacl_elf_object_p
8093 #undef elf_backend_bfd_from_remote_memory
8094 #define elf_backend_bfd_from_remote_memory \
8095 _bfd_elf32_bfd_from_remote_memory
8097 #undef elf_backend_size_info
8098 #define elf_backend_size_info \
8099 _bfd_elf32_size_info
8101 #include "elf32-target.h"
8103 /* Restore defaults. */
8104 #undef elf_backend_object_p
8105 #define elf_backend_object_p elf64_x86_64_elf_object_p
8106 #undef elf_backend_bfd_from_remote_memory
8107 #undef elf_backend_size_info
8108 #undef elf_backend_modify_segment_map
8109 #undef elf_backend_modify_program_headers
8110 #undef elf_backend_final_write_processing
8112 /* Intel L1OM support. */
8115 elf64_l1om_elf_object_p (bfd
*abfd
)
8117 /* Set the right machine number for an L1OM elf64 file. */
8118 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
8122 #undef TARGET_LITTLE_SYM
8123 #define TARGET_LITTLE_SYM l1om_elf64_vec
8124 #undef TARGET_LITTLE_NAME
8125 #define TARGET_LITTLE_NAME "elf64-l1om"
8127 #define ELF_ARCH bfd_arch_l1om
8129 #undef ELF_MACHINE_CODE
8130 #define ELF_MACHINE_CODE EM_L1OM
8135 #define elf64_bed elf64_l1om_bed
8137 #undef elf_backend_object_p
8138 #define elf_backend_object_p elf64_l1om_elf_object_p
8140 /* Restore defaults. */
8141 #undef ELF_MAXPAGESIZE
8142 #undef ELF_MINPAGESIZE
8143 #undef ELF_COMMONPAGESIZE
8144 #define ELF_MAXPAGESIZE 0x200000
8145 #define ELF_MINPAGESIZE 0x1000
8146 #define ELF_COMMONPAGESIZE 0x1000
8147 #undef elf_backend_plt_alignment
8148 #define elf_backend_plt_alignment 4
8149 #undef elf_backend_arch_data
8150 #define elf_backend_arch_data &elf_x86_64_arch_bed
8152 #include "elf64-target.h"
8154 /* FreeBSD L1OM support. */
8156 #undef TARGET_LITTLE_SYM
8157 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
8158 #undef TARGET_LITTLE_NAME
8159 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
8162 #define ELF_OSABI ELFOSABI_FREEBSD
8165 #define elf64_bed elf64_l1om_fbsd_bed
8167 #include "elf64-target.h"
8169 /* Intel K1OM support. */
8172 elf64_k1om_elf_object_p (bfd
*abfd
)
8174 /* Set the right machine number for an K1OM elf64 file. */
8175 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
8179 #undef TARGET_LITTLE_SYM
8180 #define TARGET_LITTLE_SYM k1om_elf64_vec
8181 #undef TARGET_LITTLE_NAME
8182 #define TARGET_LITTLE_NAME "elf64-k1om"
8184 #define ELF_ARCH bfd_arch_k1om
8186 #undef ELF_MACHINE_CODE
8187 #define ELF_MACHINE_CODE EM_K1OM
8192 #define elf64_bed elf64_k1om_bed
8194 #undef elf_backend_object_p
8195 #define elf_backend_object_p elf64_k1om_elf_object_p
8197 #undef elf_backend_static_tls_alignment
8199 #undef elf_backend_want_plt_sym
8200 #define elf_backend_want_plt_sym 0
8202 #include "elf64-target.h"
8204 /* FreeBSD K1OM support. */
8206 #undef TARGET_LITTLE_SYM
8207 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
8208 #undef TARGET_LITTLE_NAME
8209 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
8212 #define ELF_OSABI ELFOSABI_FREEBSD
8215 #define elf64_bed elf64_k1om_fbsd_bed
8217 #include "elf64-target.h"
8219 /* 32bit x86-64 support. */
8221 #undef TARGET_LITTLE_SYM
8222 #define TARGET_LITTLE_SYM x86_64_elf32_vec
8223 #undef TARGET_LITTLE_NAME
8224 #define TARGET_LITTLE_NAME "elf32-x86-64"
8228 #define ELF_ARCH bfd_arch_i386
8230 #undef ELF_MACHINE_CODE
8231 #define ELF_MACHINE_CODE EM_X86_64
8235 #undef elf_backend_object_p
8236 #define elf_backend_object_p \
8237 elf32_x86_64_elf_object_p
8239 #undef elf_backend_bfd_from_remote_memory
8240 #define elf_backend_bfd_from_remote_memory \
8241 _bfd_elf32_bfd_from_remote_memory
8243 #undef elf_backend_size_info
8244 #define elf_backend_size_info \
8245 _bfd_elf32_size_info
8247 #include "elf32-target.h"