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. */
22 #include "elfxx-x86.h"
25 #include "libiberty.h"
27 #include "opcode/i386.h"
28 #include "elf/x86-64.h"
35 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
36 #define MINUS_ONE (~ (bfd_vma) 0)
38 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
39 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
40 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
41 since they are the same. */
43 /* The relocation "howto" table. Order of fields:
44 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
45 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
46 static reloc_howto_type x86_64_elf_howto_table
[] =
48 HOWTO(R_X86_64_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
49 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
51 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
52 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
54 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
55 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
58 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
61 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
63 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
66 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
69 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
70 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
72 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
73 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
75 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
76 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
78 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
79 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
81 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
82 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
84 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
86 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
88 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
89 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
90 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
91 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
92 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
95 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
96 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
98 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
101 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
102 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
104 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
105 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
107 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
108 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
110 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
111 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
113 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
114 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
116 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
117 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
119 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
120 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
121 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
122 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
123 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
124 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
125 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
126 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
128 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
129 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
131 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
132 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
133 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
134 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
135 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
137 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
138 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
140 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
141 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
143 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
144 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
146 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
147 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
148 "R_X86_64_GOTPC32_TLSDESC",
149 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
150 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
151 complain_overflow_dont
, bfd_elf_generic_reloc
,
152 "R_X86_64_TLSDESC_CALL",
154 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
155 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
157 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
158 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
159 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
161 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
162 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
164 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
165 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
167 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
168 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
170 HOWTO(R_X86_64_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
171 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", FALSE
, 0xffffffff,
173 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
174 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", FALSE
, 0xffffffff,
177 /* We have a gap in the reloc numbers here.
178 R_X86_64_standard counts the number up to this point, and
179 R_X86_64_vt_offset is the value to subtract from a reloc type of
180 R_X86_64_GNU_VT* to form an index into this table. */
181 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
182 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
184 /* GNU extension to record C++ vtable hierarchy. */
185 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
186 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
188 /* GNU extension to record C++ vtable member usage. */
189 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
190 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
193 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
194 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
195 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
199 #define IS_X86_64_PCREL_TYPE(TYPE) \
200 ( ((TYPE) == R_X86_64_PC8) \
201 || ((TYPE) == R_X86_64_PC16) \
202 || ((TYPE) == R_X86_64_PC32) \
203 || ((TYPE) == R_X86_64_PC32_BND) \
204 || ((TYPE) == R_X86_64_PC64))
206 /* Map BFD relocs to the x86_64 elf relocs. */
209 bfd_reloc_code_real_type bfd_reloc_val
;
210 unsigned char elf_reloc_val
;
213 static const struct elf_reloc_map x86_64_reloc_map
[] =
215 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
216 { BFD_RELOC_64
, R_X86_64_64
, },
217 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
218 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
219 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
220 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
221 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
222 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
223 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
224 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
225 { BFD_RELOC_32
, R_X86_64_32
, },
226 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
227 { BFD_RELOC_16
, R_X86_64_16
, },
228 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
229 { BFD_RELOC_8
, R_X86_64_8
, },
230 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
231 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
232 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
233 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
234 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
235 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
236 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
237 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
238 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
239 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
240 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
241 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
242 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
243 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
244 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
245 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
246 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
247 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
248 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
249 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
250 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
251 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
252 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
253 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
254 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
255 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
256 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
257 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
258 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
261 static reloc_howto_type
*
262 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
266 if (r_type
== (unsigned int) R_X86_64_32
)
271 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
273 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
274 || r_type
>= (unsigned int) R_X86_64_max
)
276 if (r_type
>= (unsigned int) R_X86_64_standard
)
278 /* xgettext:c-format */
279 _bfd_error_handler (_("%B: invalid relocation type %d"),
281 r_type
= R_X86_64_NONE
;
286 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
287 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
288 return &x86_64_elf_howto_table
[i
];
291 /* Given a BFD reloc type, return a HOWTO structure. */
292 static reloc_howto_type
*
293 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
294 bfd_reloc_code_real_type code
)
298 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
301 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
302 return elf_x86_64_rtype_to_howto (abfd
,
303 x86_64_reloc_map
[i
].elf_reloc_val
);
308 static reloc_howto_type
*
309 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
314 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
316 /* Get x32 R_X86_64_32. */
317 reloc_howto_type
*reloc
318 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
319 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
323 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
324 if (x86_64_elf_howto_table
[i
].name
!= NULL
325 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
326 return &x86_64_elf_howto_table
[i
];
331 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
334 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
335 Elf_Internal_Rela
*dst
)
339 r_type
= ELF32_R_TYPE (dst
->r_info
);
340 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
341 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
344 /* Support for core dump NOTE sections. */
346 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
351 switch (note
->descsz
)
356 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
358 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
361 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
369 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
371 elf_tdata (abfd
)->core
->signal
372 = bfd_get_16 (abfd
, note
->descdata
+ 12);
375 elf_tdata (abfd
)->core
->lwpid
376 = bfd_get_32 (abfd
, note
->descdata
+ 32);
385 /* Make a ".reg/999" section. */
386 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
387 size
, note
->descpos
+ offset
);
391 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
393 switch (note
->descsz
)
398 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
399 elf_tdata (abfd
)->core
->pid
400 = bfd_get_32 (abfd
, note
->descdata
+ 12);
401 elf_tdata (abfd
)->core
->program
402 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
403 elf_tdata (abfd
)->core
->command
404 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
407 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
408 elf_tdata (abfd
)->core
->pid
409 = bfd_get_32 (abfd
, note
->descdata
+ 24);
410 elf_tdata (abfd
)->core
->program
411 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
412 elf_tdata (abfd
)->core
->command
413 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
416 /* Note that for some reason, a spurious space is tacked
417 onto the end of the args in some (at least one anyway)
418 implementations, so strip it off if it exists. */
421 char *command
= elf_tdata (abfd
)->core
->command
;
422 int n
= strlen (command
);
424 if (0 < n
&& command
[n
- 1] == ' ')
425 command
[n
- 1] = '\0';
433 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
436 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
438 const char *fname
, *psargs
;
449 va_start (ap
, note_type
);
450 fname
= va_arg (ap
, const char *);
451 psargs
= va_arg (ap
, const char *);
454 if (bed
->s
->elfclass
== ELFCLASS32
)
457 memset (&data
, 0, sizeof (data
));
458 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
459 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
460 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
461 &data
, sizeof (data
));
466 memset (&data
, 0, sizeof (data
));
467 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
468 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
469 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
470 &data
, sizeof (data
));
475 va_start (ap
, note_type
);
476 pid
= va_arg (ap
, long);
477 cursig
= va_arg (ap
, int);
478 gregs
= va_arg (ap
, const void *);
481 if (bed
->s
->elfclass
== ELFCLASS32
)
483 if (bed
->elf_machine_code
== EM_X86_64
)
485 prstatusx32_t prstat
;
486 memset (&prstat
, 0, sizeof (prstat
));
488 prstat
.pr_cursig
= cursig
;
489 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
490 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
491 &prstat
, sizeof (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
));
507 memset (&prstat
, 0, sizeof (prstat
));
509 prstat
.pr_cursig
= cursig
;
510 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
511 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
512 &prstat
, sizeof (prstat
));
519 /* Functions for the x86-64 ELF linker. */
521 /* The size in bytes of an entry in the global offset table. */
523 #define GOT_ENTRY_SIZE 8
525 /* The size in bytes of an entry in the lazy procedure linkage table. */
527 #define LAZY_PLT_ENTRY_SIZE 16
529 /* The size in bytes of an entry in the non-lazy procedure linkage
532 #define NON_LAZY_PLT_ENTRY_SIZE 8
534 /* The first entry in a lazy procedure linkage table looks like this.
535 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
538 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
540 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
541 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
542 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
545 /* Subsequent entries in a lazy procedure linkage table look like this. */
547 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
549 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
550 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
551 0x68, /* pushq immediate */
552 0, 0, 0, 0, /* replaced with index into relocation table. */
553 0xe9, /* jmp relative */
554 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
557 /* The first entry in a lazy procedure linkage table with BND prefix
560 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
562 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
563 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
564 0x0f, 0x1f, 0 /* nopl (%rax) */
567 /* Subsequent entries for branches with BND prefx in a lazy procedure
568 linkage table look like this. */
570 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
572 0x68, 0, 0, 0, 0, /* pushq immediate */
573 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
574 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
577 /* The first entry in the IBT-enabled lazy procedure linkage table is the
578 the same as the lazy PLT with BND prefix so that bound registers are
579 preserved when control is passed to dynamic linker. Subsequent
580 entries for a IBT-enabled lazy procedure linkage table look like
583 static const bfd_byte elf_x86_64_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
585 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
586 0x68, 0, 0, 0, 0, /* pushq immediate */
587 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
591 /* The first entry in the x32 IBT-enabled lazy procedure linkage table
592 is the same as the normal lazy PLT. Subsequent entries for an
593 x32 IBT-enabled lazy procedure linkage table look like this. */
595 static const bfd_byte elf_x32_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
597 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
598 0x68, 0, 0, 0, 0, /* pushq immediate */
599 0xe9, 0, 0, 0, 0, /* jmpq relative */
600 0x66, 0x90 /* xchg %ax,%ax */
603 /* Entries in the non-lazey procedure linkage table look like this. */
605 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
607 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
608 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
609 0x66, 0x90 /* xchg %ax,%ax */
612 /* Entries for branches with BND prefix in the non-lazey procedure
613 linkage table look like this. */
615 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
617 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
618 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
622 /* Entries for branches with IBT-enabled in the non-lazey procedure
623 linkage table look like this. They have the same size as the lazy
626 static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
628 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
629 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
630 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
631 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */
634 /* Entries for branches with IBT-enabled in the x32 non-lazey procedure
635 linkage table look like this. They have the same size as the lazy
638 static const bfd_byte elf_x32_non_lazy_ibt_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
640 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
641 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
642 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
643 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
646 /* .eh_frame covering the lazy .plt section. */
648 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
650 #define PLT_CIE_LENGTH 20
651 #define PLT_FDE_LENGTH 36
652 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
653 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
654 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
655 0, 0, 0, 0, /* CIE ID */
657 'z', 'R', 0, /* Augmentation string */
658 1, /* Code alignment factor */
659 0x78, /* Data alignment factor */
660 16, /* Return address column */
661 1, /* Augmentation size */
662 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
663 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
664 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
665 DW_CFA_nop
, DW_CFA_nop
,
667 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
668 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
669 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
670 0, 0, 0, 0, /* .plt size goes here */
671 0, /* Augmentation size */
672 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
673 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
674 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
675 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
676 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
677 11, /* Block length */
678 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
679 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
680 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
681 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
682 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
685 /* .eh_frame covering the lazy BND .plt section. */
687 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
689 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
690 0, 0, 0, 0, /* CIE ID */
692 'z', 'R', 0, /* Augmentation string */
693 1, /* Code alignment factor */
694 0x78, /* Data alignment factor */
695 16, /* Return address column */
696 1, /* Augmentation size */
697 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
698 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
699 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
700 DW_CFA_nop
, DW_CFA_nop
,
702 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
703 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
704 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
705 0, 0, 0, 0, /* .plt size goes here */
706 0, /* Augmentation size */
707 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
708 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
709 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
710 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
711 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
712 11, /* Block length */
713 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
714 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
715 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
716 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
717 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
720 /* .eh_frame covering the lazy .plt section with IBT-enabled. */
722 static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt
[] =
724 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
725 0, 0, 0, 0, /* CIE ID */
727 'z', 'R', 0, /* Augmentation string */
728 1, /* Code alignment factor */
729 0x78, /* Data alignment factor */
730 16, /* Return address column */
731 1, /* Augmentation size */
732 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
733 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
734 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
735 DW_CFA_nop
, DW_CFA_nop
,
737 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
738 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
739 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
740 0, 0, 0, 0, /* .plt size goes here */
741 0, /* Augmentation size */
742 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
743 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
744 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
745 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
746 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
747 11, /* Block length */
748 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
749 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
750 DW_OP_lit15
, DW_OP_and
, DW_OP_lit10
, DW_OP_ge
,
751 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
752 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
755 /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */
757 static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt
[] =
759 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
760 0, 0, 0, 0, /* CIE ID */
762 'z', 'R', 0, /* Augmentation string */
763 1, /* Code alignment factor */
764 0x78, /* Data alignment factor */
765 16, /* Return address column */
766 1, /* Augmentation size */
767 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
768 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
769 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
770 DW_CFA_nop
, DW_CFA_nop
,
772 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
773 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
774 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
775 0, 0, 0, 0, /* .plt size goes here */
776 0, /* Augmentation size */
777 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
778 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
779 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
780 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
781 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
782 11, /* Block length */
783 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
784 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
785 DW_OP_lit15
, DW_OP_and
, DW_OP_lit9
, DW_OP_ge
,
786 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
787 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
790 /* .eh_frame covering the non-lazy .plt section. */
792 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
794 #define PLT_GOT_FDE_LENGTH 20
795 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
796 0, 0, 0, 0, /* CIE ID */
798 'z', 'R', 0, /* Augmentation string */
799 1, /* Code alignment factor */
800 0x78, /* Data alignment factor */
801 16, /* Return address column */
802 1, /* Augmentation size */
803 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
804 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
805 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
806 DW_CFA_nop
, DW_CFA_nop
,
808 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
809 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
810 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
811 0, 0, 0, 0, /* non-lazy .plt size goes here */
812 0, /* Augmentation size */
813 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
814 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
817 /* Architecture-specific backend data for x86-64. */
819 struct elf_x86_64_backend_data
829 #define get_elf_x86_64_arch_data(bed) \
830 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
832 #define get_elf_x86_64_backend_data(abfd) \
833 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
835 /* These are the standard parameters. */
836 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt
=
838 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
839 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
840 elf_x86_64_lazy_plt_entry
, /* plt_entry */
841 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
842 2, /* plt0_got1_offset */
843 8, /* plt0_got2_offset */
844 12, /* plt0_got2_insn_end */
845 2, /* plt_got_offset */
846 7, /* plt_reloc_offset */
847 12, /* plt_plt_offset */
848 6, /* plt_got_insn_size */
849 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
850 6, /* plt_lazy_offset */
851 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
852 elf_x86_64_lazy_plt_entry
, /* pic_plt_entry */
853 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
854 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
857 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
859 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
860 elf_x86_64_non_lazy_plt_entry
, /* pic_plt_entry */
861 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
862 2, /* plt_got_offset */
863 6, /* plt_got_insn_size */
864 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
865 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
868 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
870 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
871 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
872 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
873 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
874 2, /* plt0_got1_offset */
875 1+8, /* plt0_got2_offset */
876 1+12, /* plt0_got2_insn_end */
877 1+2, /* plt_got_offset */
878 1, /* plt_reloc_offset */
879 7, /* plt_plt_offset */
880 1+6, /* plt_got_insn_size */
881 11, /* plt_plt_insn_end */
882 0, /* plt_lazy_offset */
883 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
884 elf_x86_64_lazy_bnd_plt_entry
, /* pic_plt_entry */
885 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
886 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
889 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
891 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
892 elf_x86_64_non_lazy_bnd_plt_entry
, /* pic_plt_entry */
893 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
894 1+2, /* plt_got_offset */
895 1+6, /* plt_got_insn_size */
896 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
897 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
900 static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt
=
902 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
903 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
904 elf_x86_64_lazy_ibt_plt_entry
, /* plt_entry */
905 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
906 2, /* plt0_got1_offset */
907 1+8, /* plt0_got2_offset */
908 1+12, /* plt0_got2_insn_end */
909 4+1+2, /* plt_got_offset */
910 4+1, /* plt_reloc_offset */
911 4+1+6, /* plt_plt_offset */
912 4+1+6, /* plt_got_insn_size */
913 4+1+5+5, /* plt_plt_insn_end */
914 0, /* plt_lazy_offset */
915 elf_x86_64_lazy_bnd_plt0_entry
, /* pic_plt0_entry */
916 elf_x86_64_lazy_ibt_plt_entry
, /* pic_plt_entry */
917 elf_x86_64_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
918 sizeof (elf_x86_64_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
921 static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt
=
923 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
924 LAZY_PLT_ENTRY_SIZE
, /* plt0_entry_size */
925 elf_x32_lazy_ibt_plt_entry
, /* plt_entry */
926 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
927 2, /* plt0_got1_offset */
928 8, /* plt0_got2_offset */
929 12, /* plt0_got2_insn_end */
930 4+2, /* plt_got_offset */
931 4+1, /* plt_reloc_offset */
932 4+6, /* plt_plt_offset */
933 4+6, /* plt_got_insn_size */
934 4+5+5, /* plt_plt_insn_end */
935 0, /* plt_lazy_offset */
936 elf_x86_64_lazy_plt0_entry
, /* pic_plt0_entry */
937 elf_x32_lazy_ibt_plt_entry
, /* pic_plt_entry */
938 elf_x32_eh_frame_lazy_ibt_plt
, /* eh_frame_plt */
939 sizeof (elf_x32_eh_frame_lazy_ibt_plt
) /* eh_frame_plt_size */
942 static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt
=
944 elf_x86_64_non_lazy_ibt_plt_entry
, /* plt_entry */
945 elf_x86_64_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
946 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
947 4+1+2, /* plt_got_offset */
948 4+1+6, /* plt_got_insn_size */
949 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
950 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
953 static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt
=
955 elf_x32_non_lazy_ibt_plt_entry
, /* plt_entry */
956 elf_x32_non_lazy_ibt_plt_entry
, /* pic_plt_entry */
957 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
958 4+2, /* plt_got_offset */
959 4+6, /* plt_got_insn_size */
960 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
961 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
964 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
969 #define elf_backend_arch_data &elf_x86_64_arch_bed
971 /* Values in tls_type of x86 ELF linker hash entry. */
973 #define GOT_TLS_GDESC 4
974 #define GOT_TLS_GD_BOTH_P(type) \
975 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
976 #define GOT_TLS_GD_P(type) \
977 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
978 #define GOT_TLS_GDESC_P(type) \
979 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
980 #define GOT_TLS_GD_ANY_P(type) \
981 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
983 #define is_x86_64_elf(bfd) \
984 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
985 && elf_tdata (bfd) != NULL \
986 && elf_object_id (bfd) == X86_64_ELF_DATA)
988 #define elf_x86_64_compute_jump_table_size(htab) \
989 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
992 elf64_x86_64_elf_object_p (bfd
*abfd
)
994 /* Set the right machine number for an x86-64 elf64 file. */
995 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1000 elf32_x86_64_elf_object_p (bfd
*abfd
)
1002 /* Set the right machine number for an x86-64 elf32 file. */
1003 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1007 /* Return TRUE if the TLS access code sequence support transition
1011 elf_x86_64_check_tls_transition (bfd
*abfd
,
1012 struct bfd_link_info
*info
,
1015 Elf_Internal_Shdr
*symtab_hdr
,
1016 struct elf_link_hash_entry
**sym_hashes
,
1017 unsigned int r_type
,
1018 const Elf_Internal_Rela
*rel
,
1019 const Elf_Internal_Rela
*relend
)
1022 unsigned long r_symndx
;
1023 bfd_boolean largepic
= FALSE
;
1024 struct elf_link_hash_entry
*h
;
1026 struct elf_x86_link_hash_table
*htab
;
1028 bfd_boolean indirect_call
;
1030 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1031 offset
= rel
->r_offset
;
1034 case R_X86_64_TLSGD
:
1035 case R_X86_64_TLSLD
:
1036 if ((rel
+ 1) >= relend
)
1039 if (r_type
== R_X86_64_TLSGD
)
1041 /* Check transition from GD access model. For 64bit, only
1042 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1043 .word 0x6666; rex64; call __tls_get_addr@PLT
1045 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1047 call *__tls_get_addr@GOTPCREL(%rip)
1048 which may be converted to
1049 addr32 call __tls_get_addr
1050 can transit to different access model. For 32bit, only
1051 leaq foo@tlsgd(%rip), %rdi
1052 .word 0x6666; rex64; call __tls_get_addr@PLT
1054 leaq foo@tlsgd(%rip), %rdi
1056 call *__tls_get_addr@GOTPCREL(%rip)
1057 which may be converted to
1058 addr32 call __tls_get_addr
1059 can transit to different access model. For largepic,
1061 leaq foo@tlsgd(%rip), %rdi
1062 movabsq $__tls_get_addr@pltoff, %rax
1066 leaq foo@tlsgd(%rip), %rdi
1067 movabsq $__tls_get_addr@pltoff, %rax
1071 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1073 if ((offset
+ 12) > sec
->size
)
1076 call
= contents
+ offset
+ 4;
1078 || !((call
[1] == 0x48
1086 && call
[3] == 0xe8)))
1088 if (!ABI_64_P (abfd
)
1089 || (offset
+ 19) > sec
->size
1091 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1092 || memcmp (call
, "\x48\xb8", 2) != 0
1096 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1097 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1101 else if (ABI_64_P (abfd
))
1104 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1110 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1113 indirect_call
= call
[2] == 0xff;
1117 /* Check transition from LD access model. Only
1118 leaq foo@tlsld(%rip), %rdi;
1119 call __tls_get_addr@PLT
1121 leaq foo@tlsld(%rip), %rdi;
1122 call *__tls_get_addr@GOTPCREL(%rip)
1123 which may be converted to
1124 addr32 call __tls_get_addr
1125 can transit to different access model. For largepic
1127 leaq foo@tlsld(%rip), %rdi
1128 movabsq $__tls_get_addr@pltoff, %rax
1132 leaq foo@tlsld(%rip), %rdi
1133 movabsq $__tls_get_addr@pltoff, %rax
1137 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1139 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1142 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1145 call
= contents
+ offset
+ 4;
1146 if (!(call
[0] == 0xe8
1147 || (call
[0] == 0xff && call
[1] == 0x15)
1148 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1150 if (!ABI_64_P (abfd
)
1151 || (offset
+ 19) > sec
->size
1152 || memcmp (call
, "\x48\xb8", 2) != 0
1156 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1157 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1161 indirect_call
= call
[0] == 0xff;
1164 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1165 if (r_symndx
< symtab_hdr
->sh_info
)
1168 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1170 || !((struct elf_x86_link_hash_entry
*) h
)->tls_get_addr
)
1173 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1174 else if (indirect_call
)
1175 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1177 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1178 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1180 case R_X86_64_GOTTPOFF
:
1181 /* Check transition from IE access model:
1182 mov foo@gottpoff(%rip), %reg
1183 add foo@gottpoff(%rip), %reg
1186 /* Check REX prefix first. */
1187 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1189 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1190 if (val
!= 0x48 && val
!= 0x4c)
1192 /* X32 may have 0x44 REX prefix or no REX prefix. */
1193 if (ABI_64_P (abfd
))
1199 /* X32 may not have any REX prefix. */
1200 if (ABI_64_P (abfd
))
1202 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1206 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1207 if (val
!= 0x8b && val
!= 0x03)
1210 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1211 return (val
& 0xc7) == 5;
1213 case R_X86_64_GOTPC32_TLSDESC
:
1214 /* Check transition from GDesc access model:
1215 leaq x@tlsdesc(%rip), %rax
1217 Make sure it's a leaq adding rip to a 32-bit offset
1218 into any register, although it's probably almost always
1221 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1224 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1225 if ((val
& 0xfb) != 0x48)
1228 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1231 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1232 return (val
& 0xc7) == 0x05;
1234 case R_X86_64_TLSDESC_CALL
:
1235 /* Check transition from GDesc access model:
1236 call *x@tlsdesc(%rax)
1238 if (offset
+ 2 <= sec
->size
)
1240 /* Make sure that it's a call *x@tlsdesc(%rax). */
1241 call
= contents
+ offset
;
1242 return call
[0] == 0xff && call
[1] == 0x10;
1252 /* Return TRUE if the TLS access transition is OK or no transition
1253 will be performed. Update R_TYPE if there is a transition. */
1256 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1257 asection
*sec
, bfd_byte
*contents
,
1258 Elf_Internal_Shdr
*symtab_hdr
,
1259 struct elf_link_hash_entry
**sym_hashes
,
1260 unsigned int *r_type
, int tls_type
,
1261 const Elf_Internal_Rela
*rel
,
1262 const Elf_Internal_Rela
*relend
,
1263 struct elf_link_hash_entry
*h
,
1264 unsigned long r_symndx
,
1265 bfd_boolean from_relocate_section
)
1267 unsigned int from_type
= *r_type
;
1268 unsigned int to_type
= from_type
;
1269 bfd_boolean check
= TRUE
;
1271 /* Skip TLS transition for functions. */
1273 && (h
->type
== STT_FUNC
1274 || h
->type
== STT_GNU_IFUNC
))
1279 case R_X86_64_TLSGD
:
1280 case R_X86_64_GOTPC32_TLSDESC
:
1281 case R_X86_64_TLSDESC_CALL
:
1282 case R_X86_64_GOTTPOFF
:
1283 if (bfd_link_executable (info
))
1286 to_type
= R_X86_64_TPOFF32
;
1288 to_type
= R_X86_64_GOTTPOFF
;
1291 /* When we are called from elf_x86_64_relocate_section, there may
1292 be additional transitions based on TLS_TYPE. */
1293 if (from_relocate_section
)
1295 unsigned int new_to_type
= to_type
;
1297 if (bfd_link_executable (info
)
1300 && tls_type
== GOT_TLS_IE
)
1301 new_to_type
= R_X86_64_TPOFF32
;
1303 if (to_type
== R_X86_64_TLSGD
1304 || to_type
== R_X86_64_GOTPC32_TLSDESC
1305 || to_type
== R_X86_64_TLSDESC_CALL
)
1307 if (tls_type
== GOT_TLS_IE
)
1308 new_to_type
= R_X86_64_GOTTPOFF
;
1311 /* We checked the transition before when we were called from
1312 elf_x86_64_check_relocs. We only want to check the new
1313 transition which hasn't been checked before. */
1314 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1315 to_type
= new_to_type
;
1320 case R_X86_64_TLSLD
:
1321 if (bfd_link_executable (info
))
1322 to_type
= R_X86_64_TPOFF32
;
1329 /* Return TRUE if there is no transition. */
1330 if (from_type
== to_type
)
1333 /* Check if the transition can be performed. */
1335 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1336 symtab_hdr
, sym_hashes
,
1337 from_type
, rel
, relend
))
1339 reloc_howto_type
*from
, *to
;
1342 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1343 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1346 name
= h
->root
.root
.string
;
1349 struct elf_x86_link_hash_table
*htab
;
1351 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1356 Elf_Internal_Sym
*isym
;
1358 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1360 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1365 /* xgettext:c-format */
1366 (_("%B: TLS transition from %s to %s against `%s' at %#Lx "
1367 "in section `%A' failed"),
1368 abfd
, from
->name
, to
->name
, name
, rel
->r_offset
, sec
);
1369 bfd_set_error (bfd_error_bad_value
);
1377 /* Rename some of the generic section flags to better document how they
1379 #define need_convert_load sec_flg0
1380 #define check_relocs_failed sec_flg1
1383 elf_x86_64_need_pic (struct bfd_link_info
*info
,
1384 bfd
*input_bfd
, asection
*sec
,
1385 struct elf_link_hash_entry
*h
,
1386 Elf_Internal_Shdr
*symtab_hdr
,
1387 Elf_Internal_Sym
*isym
,
1388 reloc_howto_type
*howto
)
1391 const char *und
= "";
1392 const char *pic
= "";
1398 name
= h
->root
.root
.string
;
1399 switch (ELF_ST_VISIBILITY (h
->other
))
1402 v
= _("hidden symbol ");
1405 v
= _("internal symbol ");
1408 v
= _("protected symbol ");
1411 if (((struct elf_x86_link_hash_entry
*) h
)->def_protected
)
1412 v
= _("protected symbol ");
1415 pic
= _("; recompile with -fPIC");
1419 if (!h
->def_regular
&& !h
->def_dynamic
)
1420 und
= _("undefined ");
1424 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1425 pic
= _("; recompile with -fPIC");
1428 if (bfd_link_dll (info
))
1429 object
= _("a shared object");
1430 else if (bfd_link_pie (info
))
1431 object
= _("a PIE object");
1433 object
= _("a PDE object");
1435 /* xgettext:c-format */
1436 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1437 "not be used when making %s%s"),
1438 input_bfd
, howto
->name
, und
, v
, name
,
1440 bfd_set_error (bfd_error_bad_value
);
1441 sec
->check_relocs_failed
= 1;
1445 /* With the local symbol, foo, we convert
1446 mov foo@GOTPCREL(%rip), %reg
1450 call/jmp *foo@GOTPCREL(%rip)
1452 nop call foo/jmp foo nop
1453 When PIC is false, convert
1454 test %reg, foo@GOTPCREL(%rip)
1458 binop foo@GOTPCREL(%rip), %reg
1461 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1465 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1467 Elf_Internal_Rela
*irel
,
1468 struct elf_link_hash_entry
*h
,
1469 bfd_boolean
*converted
,
1470 struct bfd_link_info
*link_info
)
1472 struct elf_x86_link_hash_table
*htab
;
1474 bfd_boolean require_reloc_pc32
;
1476 bfd_boolean to_reloc_pc32
;
1479 bfd_signed_vma raddend
;
1480 unsigned int opcode
;
1482 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1483 unsigned int r_symndx
;
1485 bfd_vma roff
= irel
->r_offset
;
1487 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1490 raddend
= irel
->r_addend
;
1491 /* Addend for 32-bit PC-relative relocation must be -4. */
1495 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
1496 is_pic
= bfd_link_pic (link_info
);
1498 relocx
= (r_type
== R_X86_64_GOTPCRELX
1499 || r_type
== R_X86_64_REX_GOTPCRELX
);
1501 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1504 = link_info
->disable_target_specific_optimizations
> 1;
1506 r_symndx
= htab
->r_sym (irel
->r_info
);
1508 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1510 /* Convert mov to lea since it has been done for a while. */
1513 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1514 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1515 test, xor instructions. */
1520 /* We convert only to R_X86_64_PC32:
1522 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1523 3. require_reloc_pc32 is true.
1526 to_reloc_pc32
= (opcode
== 0xff
1528 || require_reloc_pc32
1531 /* Get the symbol referred to by the reloc. */
1534 Elf_Internal_Sym
*isym
1535 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1537 /* Skip relocation against undefined symbols. */
1538 if (isym
->st_shndx
== SHN_UNDEF
)
1541 symtype
= ELF_ST_TYPE (isym
->st_info
);
1543 if (isym
->st_shndx
== SHN_ABS
)
1544 tsec
= bfd_abs_section_ptr
;
1545 else if (isym
->st_shndx
== SHN_COMMON
)
1546 tsec
= bfd_com_section_ptr
;
1547 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1548 tsec
= &_bfd_elf_large_com_section
;
1550 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1552 toff
= isym
->st_value
;
1556 /* Undefined weak symbol is only bound locally in executable
1557 and its reference is resolved as 0 without relocation
1558 overflow. We can only perform this optimization for
1559 GOTPCRELX relocations since we need to modify REX byte.
1560 It is OK convert mov with R_X86_64_GOTPCREL to
1562 if ((relocx
|| opcode
== 0x8b)
1563 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1566 elf_x86_hash_entry (h
)))
1570 /* Skip for branch instructions since R_X86_64_PC32
1572 if (require_reloc_pc32
)
1577 /* For non-branch instructions, we can convert to
1578 R_X86_64_32/R_X86_64_32S since we know if there
1580 to_reloc_pc32
= FALSE
;
1583 /* Since we don't know the current PC when PIC is true,
1584 we can't convert to R_X86_64_PC32. */
1585 if (to_reloc_pc32
&& is_pic
)
1590 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1591 ld.so may use its link-time address. */
1592 else if (h
->start_stop
1594 || h
->root
.type
== bfd_link_hash_defined
1595 || h
->root
.type
== bfd_link_hash_defweak
)
1596 && h
!= htab
->elf
.hdynamic
1597 && SYMBOL_REFERENCES_LOCAL (link_info
, h
)))
1599 /* bfd_link_hash_new or bfd_link_hash_undefined is
1600 set by an assignment in a linker script in
1601 bfd_elf_record_link_assignment. start_stop is set
1602 on __start_SECNAME/__stop_SECNAME which mark section
1606 && (h
->root
.type
== bfd_link_hash_new
1607 || h
->root
.type
== bfd_link_hash_undefined
1608 || ((h
->root
.type
== bfd_link_hash_defined
1609 || h
->root
.type
== bfd_link_hash_defweak
)
1610 && h
->root
.u
.def
.section
== bfd_und_section_ptr
))))
1612 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1613 if (require_reloc_pc32
)
1617 tsec
= h
->root
.u
.def
.section
;
1618 toff
= h
->root
.u
.def
.value
;
1625 /* Don't convert GOTPCREL relocation against large section. */
1626 if (elf_section_data (tsec
) != NULL
1627 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1630 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1634 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1636 /* At this stage in linking, no SEC_MERGE symbol has been
1637 adjusted, so all references to such symbols need to be
1638 passed through _bfd_merged_section_offset. (Later, in
1639 relocate_section, all SEC_MERGE symbols *except* for
1640 section symbols have been adjusted.)
1642 gas may reduce relocations against symbols in SEC_MERGE
1643 sections to a relocation against the section symbol when
1644 the original addend was zero. When the reloc is against
1645 a section symbol we should include the addend in the
1646 offset passed to _bfd_merged_section_offset, since the
1647 location of interest is the original symbol. On the
1648 other hand, an access to "sym+addend" where "sym" is not
1649 a section symbol should not include the addend; Such an
1650 access is presumed to be an offset from "sym"; The
1651 location of interest is just "sym". */
1652 if (symtype
== STT_SECTION
)
1655 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1656 elf_section_data (tsec
)->sec_info
,
1659 if (symtype
!= STT_SECTION
)
1665 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1666 if (tsec
->output_section
== sec
->output_section
)
1668 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
1673 bfd_signed_vma distance
;
1675 /* At this point, we don't know the load addresses of TSEC
1676 section nor SEC section. We estimate the distrance between
1677 SEC and TSEC. We store the estimated distances in the
1678 compressed_size field of the output section, which is only
1679 used to decompress the compressed input section. */
1680 if (sec
->output_section
->compressed_size
== 0)
1683 bfd_size_type size
= 0;
1684 for (asect
= link_info
->output_bfd
->sections
;
1686 asect
= asect
->next
)
1687 /* Skip debug sections since compressed_size is used to
1688 compress debug sections. */
1689 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
1692 for (i
= asect
->map_head
.s
;
1696 size
= align_power (size
, i
->alignment_power
);
1699 asect
->compressed_size
= size
;
1703 /* Don't convert GOTPCREL relocations if TSEC isn't placed
1705 distance
= (tsec
->output_section
->compressed_size
1706 - sec
->output_section
->compressed_size
);
1710 /* Take PT_GNU_RELRO segment into account by adding
1712 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
1713 - roff
+ 0x80000000) > 0xffffffff)
1720 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
1725 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
1727 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1730 /* Convert to "jmp foo nop". */
1733 nop_offset
= irel
->r_offset
+ 3;
1734 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1735 irel
->r_offset
-= 1;
1736 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1740 struct elf_x86_link_hash_entry
*eh
1741 = (struct elf_x86_link_hash_entry
*) h
;
1743 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
1746 /* To support TLS optimization, always use addr32 prefix for
1747 "call *__tls_get_addr@GOTPCREL(%rip)". */
1748 if (eh
&& eh
->tls_get_addr
)
1751 nop_offset
= irel
->r_offset
- 2;
1755 nop
= link_info
->call_nop_byte
;
1756 if (link_info
->call_nop_as_suffix
)
1758 nop_offset
= irel
->r_offset
+ 3;
1759 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
1760 irel
->r_offset
-= 1;
1761 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
1764 nop_offset
= irel
->r_offset
- 2;
1767 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
1768 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
1769 r_type
= R_X86_64_PC32
;
1774 unsigned int rex_mask
= REX_R
;
1776 if (r_type
== R_X86_64_REX_GOTPCRELX
)
1777 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
1785 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1786 "lea foo(%rip), %reg". */
1788 r_type
= R_X86_64_PC32
;
1792 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
1793 "mov $foo, %reg". */
1795 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1796 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1797 if ((rex
& REX_W
) != 0
1798 && ABI_64_P (link_info
->output_bfd
))
1800 /* Keep the REX_W bit in REX byte for LP64. */
1801 r_type
= R_X86_64_32S
;
1802 goto rewrite_modrm_rex
;
1806 /* If the REX_W bit in REX byte isn't needed,
1807 use R_X86_64_32 and clear the W bit to avoid
1808 sign-extend imm32 to imm64. */
1809 r_type
= R_X86_64_32
;
1810 /* Clear the W bit in REX byte. */
1812 goto rewrite_modrm_rex
;
1818 /* R_X86_64_PC32 isn't supported. */
1822 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
1825 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
1826 "test $foo, %reg". */
1827 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
1832 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
1833 "binop $foo, %reg". */
1834 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
1838 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
1839 overflow when sign-extending imm32 to imm64. */
1840 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
1843 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
1847 /* Move the R bit to the B bit in REX byte. */
1848 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
1849 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
1852 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
1856 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
1859 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
1866 /* Look through the relocs for a section during the first phase, and
1867 calculate needed space in the global offset table, procedure
1868 linkage table, and dynamic reloc sections. */
1871 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1873 const Elf_Internal_Rela
*relocs
)
1875 struct elf_x86_link_hash_table
*htab
;
1876 Elf_Internal_Shdr
*symtab_hdr
;
1877 struct elf_link_hash_entry
**sym_hashes
;
1878 const Elf_Internal_Rela
*rel
;
1879 const Elf_Internal_Rela
*rel_end
;
1883 if (bfd_link_relocatable (info
))
1886 /* Don't do anything special with non-loaded, non-alloced sections.
1887 In particular, any relocs in such sections should not affect GOT
1888 and PLT reference counting (ie. we don't allow them to create GOT
1889 or PLT entries), there's no possibility or desire to optimize TLS
1890 relocs, and there's not much point in propagating relocs to shared
1891 libs that the dynamic linker won't relocate. */
1892 if ((sec
->flags
& SEC_ALLOC
) == 0)
1895 BFD_ASSERT (is_x86_64_elf (abfd
));
1897 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
1900 sec
->check_relocs_failed
= 1;
1904 /* Get the section contents. */
1905 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1906 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1907 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1909 sec
->check_relocs_failed
= 1;
1913 symtab_hdr
= &elf_symtab_hdr (abfd
);
1914 sym_hashes
= elf_sym_hashes (abfd
);
1918 rel_end
= relocs
+ sec
->reloc_count
;
1919 for (rel
= relocs
; rel
< rel_end
; rel
++)
1921 unsigned int r_type
;
1922 unsigned int r_symndx
;
1923 struct elf_link_hash_entry
*h
;
1924 struct elf_x86_link_hash_entry
*eh
;
1925 Elf_Internal_Sym
*isym
;
1927 bfd_boolean size_reloc
;
1929 r_symndx
= htab
->r_sym (rel
->r_info
);
1930 r_type
= ELF32_R_TYPE (rel
->r_info
);
1932 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1934 /* xgettext:c-format */
1935 _bfd_error_handler (_("%B: bad symbol index: %d"),
1940 if (r_symndx
< symtab_hdr
->sh_info
)
1942 /* A local symbol. */
1943 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1948 /* Check relocation against local STT_GNU_IFUNC symbol. */
1949 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1951 h
= _bfd_elf_x86_get_local_sym_hash (htab
, abfd
, rel
,
1956 /* Fake a STT_GNU_IFUNC symbol. */
1957 h
->root
.root
.string
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1959 h
->type
= STT_GNU_IFUNC
;
1962 h
->forced_local
= 1;
1963 h
->root
.type
= bfd_link_hash_defined
;
1971 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1972 while (h
->root
.type
== bfd_link_hash_indirect
1973 || h
->root
.type
== bfd_link_hash_warning
)
1974 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1977 /* Check invalid x32 relocations. */
1978 if (!ABI_64_P (abfd
))
1984 case R_X86_64_DTPOFF64
:
1985 case R_X86_64_TPOFF64
:
1987 case R_X86_64_GOTOFF64
:
1988 case R_X86_64_GOT64
:
1989 case R_X86_64_GOTPCREL64
:
1990 case R_X86_64_GOTPC64
:
1991 case R_X86_64_GOTPLT64
:
1992 case R_X86_64_PLTOFF64
:
1995 name
= h
->root
.root
.string
;
1997 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2000 /* xgettext:c-format */
2001 (_("%B: relocation %s against symbol `%s' isn't "
2002 "supported in x32 mode"), abfd
,
2003 x86_64_elf_howto_table
[r_type
].name
, name
);
2004 bfd_set_error (bfd_error_bad_value
);
2012 /* It is referenced by a non-shared object. */
2014 h
->root
.non_ir_ref_regular
= 1;
2016 if (h
->type
== STT_GNU_IFUNC
)
2017 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2018 |= elf_gnu_symbol_ifunc
;
2021 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2022 symtab_hdr
, sym_hashes
,
2023 &r_type
, GOT_UNKNOWN
,
2024 rel
, rel_end
, h
, r_symndx
, FALSE
))
2027 eh
= (struct elf_x86_link_hash_entry
*) h
;
2030 case R_X86_64_TLSLD
:
2031 htab
->tls_ld_or_ldm_got
.refcount
+= 1;
2034 case R_X86_64_TPOFF32
:
2035 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2036 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2037 &x86_64_elf_howto_table
[r_type
]);
2039 eh
->has_got_reloc
= 1;
2042 case R_X86_64_GOTTPOFF
:
2043 if (!bfd_link_executable (info
))
2044 info
->flags
|= DF_STATIC_TLS
;
2047 case R_X86_64_GOT32
:
2048 case R_X86_64_GOTPCREL
:
2049 case R_X86_64_GOTPCRELX
:
2050 case R_X86_64_REX_GOTPCRELX
:
2051 case R_X86_64_TLSGD
:
2052 case R_X86_64_GOT64
:
2053 case R_X86_64_GOTPCREL64
:
2054 case R_X86_64_GOTPLT64
:
2055 case R_X86_64_GOTPC32_TLSDESC
:
2056 case R_X86_64_TLSDESC_CALL
:
2057 /* This symbol requires a global offset table entry. */
2059 int tls_type
, old_tls_type
;
2063 default: tls_type
= GOT_NORMAL
; break;
2064 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2065 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2066 case R_X86_64_GOTPC32_TLSDESC
:
2067 case R_X86_64_TLSDESC_CALL
:
2068 tls_type
= GOT_TLS_GDESC
; break;
2073 h
->got
.refcount
+= 1;
2074 old_tls_type
= eh
->tls_type
;
2078 bfd_signed_vma
*local_got_refcounts
;
2080 /* This is a global offset table entry for a local symbol. */
2081 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2082 if (local_got_refcounts
== NULL
)
2086 size
= symtab_hdr
->sh_info
;
2087 size
*= sizeof (bfd_signed_vma
)
2088 + sizeof (bfd_vma
) + sizeof (char);
2089 local_got_refcounts
= ((bfd_signed_vma
*)
2090 bfd_zalloc (abfd
, size
));
2091 if (local_got_refcounts
== NULL
)
2093 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2094 elf_x86_local_tlsdesc_gotent (abfd
)
2095 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2096 elf_x86_local_got_tls_type (abfd
)
2097 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2099 local_got_refcounts
[r_symndx
] += 1;
2101 = elf_x86_local_got_tls_type (abfd
) [r_symndx
];
2104 /* If a TLS symbol is accessed using IE at least once,
2105 there is no point to use dynamic model for it. */
2106 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2107 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2108 || tls_type
!= GOT_TLS_IE
))
2110 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2111 tls_type
= old_tls_type
;
2112 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2113 && GOT_TLS_GD_ANY_P (tls_type
))
2114 tls_type
|= old_tls_type
;
2118 name
= h
->root
.root
.string
;
2120 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2123 /* xgettext:c-format */
2124 (_("%B: '%s' accessed both as normal and"
2125 " thread local symbol"),
2127 bfd_set_error (bfd_error_bad_value
);
2132 if (old_tls_type
!= tls_type
)
2135 eh
->tls_type
= tls_type
;
2137 elf_x86_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2142 case R_X86_64_GOTOFF64
:
2143 case R_X86_64_GOTPC32
:
2144 case R_X86_64_GOTPC64
:
2147 eh
->has_got_reloc
= 1;
2150 case R_X86_64_PLT32
:
2151 case R_X86_64_PLT32_BND
:
2152 /* This symbol requires a procedure linkage table entry. We
2153 actually build the entry in adjust_dynamic_symbol,
2154 because this might be a case of linking PIC code which is
2155 never referenced by a dynamic object, in which case we
2156 don't need to generate a procedure linkage table entry
2159 /* If this is a local symbol, we resolve it directly without
2160 creating a procedure linkage table entry. */
2164 eh
->has_got_reloc
= 1;
2166 h
->plt
.refcount
+= 1;
2169 case R_X86_64_PLTOFF64
:
2170 /* This tries to form the 'address' of a function relative
2171 to GOT. For global symbols we need a PLT entry. */
2175 h
->plt
.refcount
+= 1;
2179 case R_X86_64_SIZE32
:
2180 case R_X86_64_SIZE64
:
2185 if (!ABI_64_P (abfd
))
2191 /* Check relocation overflow as these relocs may lead to
2192 run-time relocation overflow. Don't error out for
2193 sections we don't care about, such as debug sections or
2194 when relocation overflow check is disabled. */
2195 if (!info
->no_reloc_overflow_check
2196 && (bfd_link_pic (info
)
2197 || (bfd_link_executable (info
)
2201 && (sec
->flags
& SEC_READONLY
) == 0)))
2202 return elf_x86_64_need_pic (info
, abfd
, sec
, h
, symtab_hdr
, isym
,
2203 &x86_64_elf_howto_table
[r_type
]);
2209 case R_X86_64_PC32_BND
:
2213 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2214 eh
->has_non_got_reloc
= 1;
2215 /* We are called after all symbols have been resolved. Only
2216 relocation against STT_GNU_IFUNC symbol must go through
2219 && (bfd_link_executable (info
)
2220 || h
->type
== STT_GNU_IFUNC
))
2222 /* If this reloc is in a read-only section, we might
2223 need a copy reloc. We can't check reliably at this
2224 stage whether the section is read-only, as input
2225 sections have not yet been mapped to output sections.
2226 Tentatively set the flag for now, and correct in
2227 adjust_dynamic_symbol. */
2230 /* We may need a .plt entry if the symbol is a function
2231 defined in a shared lib or is a STT_GNU_IFUNC function
2232 referenced from the code or read-only section. */
2234 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2235 h
->plt
.refcount
+= 1;
2237 if (r_type
== R_X86_64_PC32
)
2239 /* Since something like ".long foo - ." may be used
2240 as pointer, make sure that PLT is used if foo is
2241 a function defined in a shared library. */
2242 if ((sec
->flags
& SEC_CODE
) == 0)
2243 h
->pointer_equality_needed
= 1;
2245 else if (r_type
!= R_X86_64_PC32_BND
2246 && r_type
!= R_X86_64_PC64
)
2248 h
->pointer_equality_needed
= 1;
2249 /* At run-time, R_X86_64_64 can be resolved for both
2250 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2251 can only be resolved for x32. */
2252 if ((sec
->flags
& SEC_READONLY
) == 0
2253 && (r_type
== R_X86_64_64
2254 || (!ABI_64_P (abfd
)
2255 && (r_type
== R_X86_64_32
2256 || r_type
== R_X86_64_32S
))))
2257 eh
->func_pointer_refcount
+= 1;
2263 /* If we are creating a shared library, and this is a reloc
2264 against a global symbol, or a non PC relative reloc
2265 against a local symbol, then we need to copy the reloc
2266 into the shared library. However, if we are linking with
2267 -Bsymbolic, we do not need to copy a reloc against a
2268 global symbol which is defined in an object we are
2269 including in the link (i.e., DEF_REGULAR is set). At
2270 this point we have not seen all the input files, so it is
2271 possible that DEF_REGULAR is not set now but will be set
2272 later (it is never cleared). In case of a weak definition,
2273 DEF_REGULAR may be cleared later by a strong definition in
2274 a shared library. We account for that possibility below by
2275 storing information in the relocs_copied field of the hash
2276 table entry. A similar situation occurs when creating
2277 shared libraries and symbol visibility changes render the
2280 If on the other hand, we are creating an executable, we
2281 may need to keep relocations for symbols satisfied by a
2282 dynamic library if we manage to avoid copy relocs for the
2285 Generate dynamic pointer relocation against STT_GNU_IFUNC
2286 symbol in the non-code section. */
2287 if ((bfd_link_pic (info
)
2288 && (! IS_X86_64_PCREL_TYPE (r_type
)
2290 && (! (bfd_link_pie (info
)
2291 || SYMBOLIC_BIND (info
, h
))
2292 || h
->root
.type
== bfd_link_hash_defweak
2293 || !h
->def_regular
))))
2295 && h
->type
== STT_GNU_IFUNC
2296 && r_type
== htab
->pointer_r_type
2297 && (sec
->flags
& SEC_CODE
) == 0)
2298 || (ELIMINATE_COPY_RELOCS
2299 && !bfd_link_pic (info
)
2301 && (h
->root
.type
== bfd_link_hash_defweak
2302 || !h
->def_regular
)))
2304 struct elf_dyn_relocs
*p
;
2305 struct elf_dyn_relocs
**head
;
2307 /* We must copy these reloc types into the output file.
2308 Create a reloc section in dynobj and make room for
2312 sreloc
= _bfd_elf_make_dynamic_reloc_section
2313 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2314 abfd
, /*rela?*/ TRUE
);
2320 /* If this is a global symbol, we count the number of
2321 relocations we need for this symbol. */
2323 head
= &eh
->dyn_relocs
;
2326 /* Track dynamic relocs needed for local syms too.
2327 We really need local syms available to do this
2332 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2337 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2341 /* Beware of type punned pointers vs strict aliasing
2343 vpp
= &(elf_section_data (s
)->local_dynrel
);
2344 head
= (struct elf_dyn_relocs
**)vpp
;
2348 if (p
== NULL
|| p
->sec
!= sec
)
2350 bfd_size_type amt
= sizeof *p
;
2352 p
= ((struct elf_dyn_relocs
*)
2353 bfd_alloc (htab
->elf
.dynobj
, amt
));
2364 /* Count size relocation as PC-relative relocation. */
2365 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2370 /* This relocation describes the C++ object vtable hierarchy.
2371 Reconstruct it for later use during GC. */
2372 case R_X86_64_GNU_VTINHERIT
:
2373 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2377 /* This relocation describes which C++ vtable entries are actually
2378 used. Record for later use during GC. */
2379 case R_X86_64_GNU_VTENTRY
:
2380 BFD_ASSERT (h
!= NULL
);
2382 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2390 if ((r_type
== R_X86_64_GOTPCREL
2391 || r_type
== R_X86_64_GOTPCRELX
2392 || r_type
== R_X86_64_REX_GOTPCRELX
)
2393 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2394 sec
->need_convert_load
= 1;
2397 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2399 if (!info
->keep_memory
)
2403 /* Cache the section contents for elf_link_input_bfd. */
2404 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2411 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2413 sec
->check_relocs_failed
= 1;
2417 /* Return the section that should be marked against GC for a given
2421 elf_x86_64_gc_mark_hook (asection
*sec
,
2422 struct bfd_link_info
*info
,
2423 Elf_Internal_Rela
*rel
,
2424 struct elf_link_hash_entry
*h
,
2425 Elf_Internal_Sym
*sym
)
2428 switch (ELF32_R_TYPE (rel
->r_info
))
2430 case R_X86_64_GNU_VTINHERIT
:
2431 case R_X86_64_GNU_VTENTRY
:
2435 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2438 /* Allocate space in .plt, .got and associated reloc sections for
2442 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2444 struct bfd_link_info
*info
;
2445 struct elf_x86_link_hash_table
*htab
;
2446 struct elf_x86_link_hash_entry
*eh
;
2447 struct elf_dyn_relocs
*p
;
2448 const struct elf_backend_data
*bed
;
2449 unsigned int plt_entry_size
;
2450 bfd_boolean resolved_to_zero
;
2452 if (h
->root
.type
== bfd_link_hash_indirect
)
2455 eh
= (struct elf_x86_link_hash_entry
*) h
;
2457 info
= (struct bfd_link_info
*) inf
;
2458 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2461 bed
= get_elf_backend_data (info
->output_bfd
);
2463 plt_entry_size
= htab
->plt
.plt_entry_size
;
2465 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2470 /* We can't use the GOT PLT if pointer equality is needed since
2471 finish_dynamic_symbol won't clear symbol value and the dynamic
2472 linker won't update the GOT slot. We will get into an infinite
2473 loop at run-time. */
2474 if (htab
->plt_got
!= NULL
2475 && h
->type
!= STT_GNU_IFUNC
2476 && !h
->pointer_equality_needed
2477 && h
->plt
.refcount
> 0
2478 && h
->got
.refcount
> 0)
2480 /* Don't use the regular PLT if there are both GOT and GOTPLT
2482 h
->plt
.offset
= (bfd_vma
) -1;
2484 /* Use the GOT PLT. */
2485 eh
->plt_got
.refcount
= 1;
2488 /* Clear the reference count of function pointer relocations if
2489 symbol isn't a normal function. */
2490 if (h
->type
!= STT_FUNC
)
2491 eh
->func_pointer_refcount
= 0;
2493 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2494 here if it is defined and referenced in a non-shared object. */
2495 if (h
->type
== STT_GNU_IFUNC
2498 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2500 &htab
->readonly_dynrelocs_against_ifunc
,
2504 GOT_ENTRY_SIZE
, TRUE
))
2506 asection
*s
= htab
->plt_second
;
2507 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
2509 /* Use the second PLT section if it is created. */
2510 eh
->plt_second
.offset
= s
->size
;
2512 /* Make room for this entry in the second PLT section. */
2513 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2521 /* Don't create the PLT entry if there are only function pointer
2522 relocations which can be resolved at run-time. */
2523 else if (htab
->elf
.dynamic_sections_created
2524 && (h
->plt
.refcount
> eh
->func_pointer_refcount
2525 || eh
->plt_got
.refcount
> 0))
2527 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
2529 /* Clear the reference count of function pointer relocations
2531 eh
->func_pointer_refcount
= 0;
2533 /* Make sure this symbol is output as a dynamic symbol.
2534 Undefined weak syms won't yet be marked as dynamic. */
2535 if (h
->dynindx
== -1
2537 && !resolved_to_zero
2538 && h
->root
.type
== bfd_link_hash_undefweak
)
2540 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2544 if (bfd_link_pic (info
)
2545 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2547 asection
*s
= htab
->elf
.splt
;
2548 asection
*second_s
= htab
->plt_second
;
2549 asection
*got_s
= htab
->plt_got
;
2551 /* If this is the first .plt entry, make room for the special
2552 first entry. The .plt section is used by prelink to undo
2553 prelinking for dynamic relocations. */
2555 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
2558 eh
->plt_got
.offset
= got_s
->size
;
2561 h
->plt
.offset
= s
->size
;
2563 eh
->plt_second
.offset
= second_s
->size
;
2566 /* If this symbol is not defined in a regular file, and we are
2567 not generating a shared library, then set the symbol to this
2568 location in the .plt. This is required to make function
2569 pointers compare as equal between the normal executable and
2570 the shared library. */
2571 if (! bfd_link_pic (info
)
2576 /* We need to make a call to the entry of the GOT PLT
2577 instead of regular PLT entry. */
2578 h
->root
.u
.def
.section
= got_s
;
2579 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
2585 /* We need to make a call to the entry of the
2586 second PLT instead of regular PLT entry. */
2587 h
->root
.u
.def
.section
= second_s
;
2588 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
2592 h
->root
.u
.def
.section
= s
;
2593 h
->root
.u
.def
.value
= h
->plt
.offset
;
2598 /* Make room for this entry. */
2600 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2603 s
->size
+= plt_entry_size
;
2605 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
2607 /* We also need to make an entry in the .got.plt section,
2608 which will be placed in the .got section by the linker
2610 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2612 /* There should be no PLT relocation against resolved
2613 undefined weak symbol in executable. */
2614 if (!resolved_to_zero
)
2616 /* We also need to make an entry in the .rela.plt
2618 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2619 htab
->elf
.srelplt
->reloc_count
++;
2625 eh
->plt_got
.offset
= (bfd_vma
) -1;
2626 h
->plt
.offset
= (bfd_vma
) -1;
2632 eh
->plt_got
.offset
= (bfd_vma
) -1;
2633 h
->plt
.offset
= (bfd_vma
) -1;
2637 eh
->tlsdesc_got
= (bfd_vma
) -1;
2639 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2640 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2641 if (h
->got
.refcount
> 0
2642 && bfd_link_executable (info
)
2644 && elf_x86_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2646 h
->got
.offset
= (bfd_vma
) -1;
2648 else if (h
->got
.refcount
> 0)
2652 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
2654 /* Make sure this symbol is output as a dynamic symbol.
2655 Undefined weak syms won't yet be marked as dynamic. */
2656 if (h
->dynindx
== -1
2658 && !resolved_to_zero
2659 && h
->root
.type
== bfd_link_hash_undefweak
)
2661 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2665 if (GOT_TLS_GDESC_P (tls_type
))
2667 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2668 - elf_x86_64_compute_jump_table_size (htab
);
2669 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2670 h
->got
.offset
= (bfd_vma
) -2;
2672 if (! GOT_TLS_GDESC_P (tls_type
)
2673 || GOT_TLS_GD_P (tls_type
))
2676 h
->got
.offset
= s
->size
;
2677 s
->size
+= GOT_ENTRY_SIZE
;
2678 if (GOT_TLS_GD_P (tls_type
))
2679 s
->size
+= GOT_ENTRY_SIZE
;
2681 dyn
= htab
->elf
.dynamic_sections_created
;
2682 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2683 and two if global. R_X86_64_GOTTPOFF needs one dynamic
2684 relocation. No dynamic relocation against resolved undefined
2685 weak symbol in executable. */
2686 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2687 || tls_type
== GOT_TLS_IE
)
2688 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2689 else if (GOT_TLS_GD_P (tls_type
))
2690 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2691 else if (! GOT_TLS_GDESC_P (tls_type
)
2692 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2693 && !resolved_to_zero
)
2694 || h
->root
.type
!= bfd_link_hash_undefweak
)
2695 && (bfd_link_pic (info
)
2696 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2697 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2698 if (GOT_TLS_GDESC_P (tls_type
))
2700 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2701 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2705 h
->got
.offset
= (bfd_vma
) -1;
2707 if (eh
->dyn_relocs
== NULL
)
2710 /* In the shared -Bsymbolic case, discard space allocated for
2711 dynamic pc-relative relocs against symbols which turn out to be
2712 defined in regular objects. For the normal shared case, discard
2713 space for pc-relative relocs that have become local due to symbol
2714 visibility changes. */
2716 if (bfd_link_pic (info
))
2718 /* Relocs that use pc_count are those that appear on a call
2719 insn, or certain REL relocs that can generated via assembly.
2720 We want calls to protected symbols to resolve directly to the
2721 function rather than going via the plt. If people want
2722 function pointer comparisons to work as expected then they
2723 should avoid writing weird assembly. */
2724 if (SYMBOL_CALLS_LOCAL (info
, h
))
2726 struct elf_dyn_relocs
**pp
;
2728 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2730 p
->count
-= p
->pc_count
;
2739 /* Also discard relocs on undefined weak syms with non-default
2740 visibility or in PIE. */
2741 if (eh
->dyn_relocs
!= NULL
)
2743 if (h
->root
.type
== bfd_link_hash_undefweak
)
2745 /* Undefined weak symbol is never bound locally in shared
2747 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2748 || resolved_to_zero
)
2749 eh
->dyn_relocs
= NULL
;
2750 else if (h
->dynindx
== -1
2751 && ! h
->forced_local
2752 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2755 /* For PIE, discard space for pc-relative relocs against
2756 symbols which turn out to need copy relocs. */
2757 else if (bfd_link_executable (info
)
2758 && (h
->needs_copy
|| eh
->needs_copy
)
2762 struct elf_dyn_relocs
**pp
;
2764 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2766 if (p
->pc_count
!= 0)
2774 else if (ELIMINATE_COPY_RELOCS
)
2776 /* For the non-shared case, discard space for relocs against
2777 symbols which turn out to need copy relocs or are not
2778 dynamic. Keep dynamic relocations for run-time function
2779 pointer initialization. */
2781 if ((!h
->non_got_ref
2782 || eh
->func_pointer_refcount
> 0
2783 || (h
->root
.type
== bfd_link_hash_undefweak
2784 && !resolved_to_zero
))
2787 || (htab
->elf
.dynamic_sections_created
2788 && (h
->root
.type
== bfd_link_hash_undefweak
2789 || h
->root
.type
== bfd_link_hash_undefined
))))
2791 /* Make sure this symbol is output as a dynamic symbol.
2792 Undefined weak syms won't yet be marked as dynamic. */
2793 if (h
->dynindx
== -1
2794 && ! h
->forced_local
2795 && ! resolved_to_zero
2796 && h
->root
.type
== bfd_link_hash_undefweak
2797 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2800 /* If that succeeded, we know we'll be keeping all the
2802 if (h
->dynindx
!= -1)
2806 eh
->dyn_relocs
= NULL
;
2807 eh
->func_pointer_refcount
= 0;
2812 /* Finally, allocate space. */
2813 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2817 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2819 BFD_ASSERT (sreloc
!= NULL
);
2821 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2827 /* Allocate space in .plt, .got and associated reloc sections for
2828 local dynamic relocs. */
2831 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2833 struct elf_link_hash_entry
*h
2834 = (struct elf_link_hash_entry
*) *slot
;
2836 if (h
->type
!= STT_GNU_IFUNC
2840 || h
->root
.type
!= bfd_link_hash_defined
)
2843 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2846 /* Convert load via the GOT slot to load immediate. */
2849 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
2850 struct bfd_link_info
*link_info
)
2852 Elf_Internal_Shdr
*symtab_hdr
;
2853 Elf_Internal_Rela
*internal_relocs
;
2854 Elf_Internal_Rela
*irel
, *irelend
;
2856 struct elf_x86_link_hash_table
*htab
;
2857 bfd_boolean changed
;
2858 bfd_signed_vma
*local_got_refcounts
;
2860 /* Don't even try to convert non-ELF outputs. */
2861 if (!is_elf_hash_table (link_info
->hash
))
2864 /* Nothing to do if there is no need or no output. */
2865 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
2866 || sec
->need_convert_load
== 0
2867 || bfd_is_abs_section (sec
->output_section
))
2870 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2872 /* Load the relocations for this section. */
2873 internal_relocs
= (_bfd_elf_link_read_relocs
2874 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2875 link_info
->keep_memory
));
2876 if (internal_relocs
== NULL
)
2880 htab
= elf_x86_hash_table (link_info
, X86_64_ELF_DATA
);
2881 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2883 /* Get the section contents. */
2884 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2885 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2888 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2892 irelend
= internal_relocs
+ sec
->reloc_count
;
2893 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2895 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
2896 unsigned int r_symndx
;
2897 struct elf_link_hash_entry
*h
;
2898 bfd_boolean converted
;
2900 if (r_type
!= R_X86_64_GOTPCRELX
2901 && r_type
!= R_X86_64_REX_GOTPCRELX
2902 && r_type
!= R_X86_64_GOTPCREL
)
2905 r_symndx
= htab
->r_sym (irel
->r_info
);
2906 if (r_symndx
< symtab_hdr
->sh_info
)
2907 h
= _bfd_elf_x86_get_local_sym_hash (htab
, sec
->owner
,
2908 (const Elf_Internal_Rela
*) irel
,
2912 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
2913 while (h
->root
.type
== bfd_link_hash_indirect
2914 || h
->root
.type
== bfd_link_hash_warning
)
2915 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2918 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
2919 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
2923 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
2924 &converted
, link_info
))
2929 changed
= converted
;
2932 if (h
->got
.refcount
> 0)
2933 h
->got
.refcount
-= 1;
2937 if (local_got_refcounts
!= NULL
2938 && local_got_refcounts
[r_symndx
] > 0)
2939 local_got_refcounts
[r_symndx
] -= 1;
2944 if (contents
!= NULL
2945 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2947 if (!changed
&& !link_info
->keep_memory
)
2951 /* Cache the section contents for elf_link_input_bfd. */
2952 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2956 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2959 free (internal_relocs
);
2961 elf_section_data (sec
)->relocs
= internal_relocs
;
2967 if (contents
!= NULL
2968 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2970 if (internal_relocs
!= NULL
2971 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2972 free (internal_relocs
);
2976 /* Set the sizes of the dynamic sections. */
2979 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2980 struct bfd_link_info
*info
)
2982 struct elf_x86_link_hash_table
*htab
;
2987 const struct elf_backend_data
*bed
;
2989 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
2992 bed
= get_elf_backend_data (output_bfd
);
2994 dynobj
= htab
->elf
.dynobj
;
2998 /* Set up .got offsets for local syms, and space for local dynamic
3000 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3002 bfd_signed_vma
*local_got
;
3003 bfd_signed_vma
*end_local_got
;
3004 char *local_tls_type
;
3005 bfd_vma
*local_tlsdesc_gotent
;
3006 bfd_size_type locsymcount
;
3007 Elf_Internal_Shdr
*symtab_hdr
;
3010 if (! is_x86_64_elf (ibfd
))
3013 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3015 struct elf_dyn_relocs
*p
;
3017 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3020 for (p
= (struct elf_dyn_relocs
*)
3021 (elf_section_data (s
)->local_dynrel
);
3025 if (!bfd_is_abs_section (p
->sec
)
3026 && bfd_is_abs_section (p
->sec
->output_section
))
3028 /* Input section has been discarded, either because
3029 it is a copy of a linkonce section or due to
3030 linker script /DISCARD/, so we'll be discarding
3033 else if (p
->count
!= 0)
3035 srel
= elf_section_data (p
->sec
)->sreloc
;
3036 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3037 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3038 && (info
->flags
& DF_TEXTREL
) == 0)
3040 info
->flags
|= DF_TEXTREL
;
3041 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3042 || info
->error_textrel
)
3043 /* xgettext:c-format */
3044 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3045 p
->sec
->owner
, p
->sec
);
3051 local_got
= elf_local_got_refcounts (ibfd
);
3055 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3056 locsymcount
= symtab_hdr
->sh_info
;
3057 end_local_got
= local_got
+ locsymcount
;
3058 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
3059 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
3061 srel
= htab
->elf
.srelgot
;
3062 for (; local_got
< end_local_got
;
3063 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3065 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3068 if (GOT_TLS_GDESC_P (*local_tls_type
))
3070 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3071 - elf_x86_64_compute_jump_table_size (htab
);
3072 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3073 *local_got
= (bfd_vma
) -2;
3075 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3076 || GOT_TLS_GD_P (*local_tls_type
))
3078 *local_got
= s
->size
;
3079 s
->size
+= GOT_ENTRY_SIZE
;
3080 if (GOT_TLS_GD_P (*local_tls_type
))
3081 s
->size
+= GOT_ENTRY_SIZE
;
3083 if (bfd_link_pic (info
)
3084 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3085 || *local_tls_type
== GOT_TLS_IE
)
3087 if (GOT_TLS_GDESC_P (*local_tls_type
))
3089 htab
->elf
.srelplt
->size
3090 += bed
->s
->sizeof_rela
;
3091 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3093 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3094 || GOT_TLS_GD_P (*local_tls_type
))
3095 srel
->size
+= bed
->s
->sizeof_rela
;
3099 *local_got
= (bfd_vma
) -1;
3103 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
3105 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3107 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
3108 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3109 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3112 htab
->tls_ld_or_ldm_got
.offset
= -1;
3114 /* Allocate global sym .plt and .got entries, and space for global
3115 sym dynamic relocs. */
3116 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3119 /* Allocate .plt and .got entries, and space for local symbols. */
3120 htab_traverse (htab
->loc_hash_table
,
3121 elf_x86_64_allocate_local_dynrelocs
,
3124 /* For every jump slot reserved in the sgotplt, reloc_count is
3125 incremented. However, when we reserve space for TLS descriptors,
3126 it's not incremented, so in order to compute the space reserved
3127 for them, it suffices to multiply the reloc count by the jump
3130 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3131 so that R_X86_64_IRELATIVE entries come last. */
3132 if (htab
->elf
.srelplt
)
3134 htab
->sgotplt_jump_table_size
3135 = elf_x86_64_compute_jump_table_size (htab
);
3136 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3138 else if (htab
->elf
.irelplt
)
3139 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3141 if (htab
->tlsdesc_plt
)
3143 /* If we're not using lazy TLS relocations, don't generate the
3144 PLT and GOT entries they require. */
3145 if ((info
->flags
& DF_BIND_NOW
))
3146 htab
->tlsdesc_plt
= 0;
3149 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3150 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3151 /* Reserve room for the initial entry.
3152 FIXME: we could probably do away with it in this case. */
3153 if (htab
->elf
.splt
->size
== 0)
3154 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
3155 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3156 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
3160 if (htab
->elf
.sgotplt
)
3162 /* Don't allocate .got.plt section if there are no GOT nor PLT
3163 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3164 if ((htab
->elf
.hgot
== NULL
3165 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3166 && (htab
->elf
.sgotplt
->size
3167 == get_elf_backend_data (output_bfd
)->got_header_size
)
3168 && (htab
->elf
.splt
== NULL
3169 || htab
->elf
.splt
->size
== 0)
3170 && (htab
->elf
.sgot
== NULL
3171 || htab
->elf
.sgot
->size
== 0)
3172 && (htab
->elf
.iplt
== NULL
3173 || htab
->elf
.iplt
->size
== 0)
3174 && (htab
->elf
.igotplt
== NULL
3175 || htab
->elf
.igotplt
->size
== 0))
3176 htab
->elf
.sgotplt
->size
= 0;
3179 if (_bfd_elf_eh_frame_present (info
))
3181 if (htab
->plt_eh_frame
!= NULL
3182 && htab
->elf
.splt
!= NULL
3183 && htab
->elf
.splt
->size
!= 0
3184 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3185 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
3187 if (htab
->plt_got_eh_frame
!= NULL
3188 && htab
->plt_got
!= NULL
3189 && htab
->plt_got
->size
!= 0
3190 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3191 htab
->plt_got_eh_frame
->size
3192 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3194 /* Unwind info for the second PLT and .plt.got sections are
3196 if (htab
->plt_second_eh_frame
!= NULL
3197 && htab
->plt_second
!= NULL
3198 && htab
->plt_second
->size
!= 0
3199 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
3200 htab
->plt_second_eh_frame
->size
3201 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3204 /* We now have determined the sizes of the various dynamic sections.
3205 Allocate memory for them. */
3207 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3209 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3212 if (s
== htab
->elf
.splt
3213 || s
== htab
->elf
.sgot
3214 || s
== htab
->elf
.sgotplt
3215 || s
== htab
->elf
.iplt
3216 || s
== htab
->elf
.igotplt
3217 || s
== htab
->plt_second
3218 || s
== htab
->plt_got
3219 || s
== htab
->plt_eh_frame
3220 || s
== htab
->plt_got_eh_frame
3221 || s
== htab
->plt_second_eh_frame
3222 || s
== htab
->elf
.sdynbss
3223 || s
== htab
->elf
.sdynrelro
)
3225 /* Strip this section if we don't need it; see the
3228 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3230 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3233 /* We use the reloc_count field as a counter if we need
3234 to copy relocs into the output file. */
3235 if (s
!= htab
->elf
.srelplt
)
3240 /* It's not one of our sections, so don't allocate space. */
3246 /* If we don't need this section, strip it from the
3247 output file. This is mostly to handle .rela.bss and
3248 .rela.plt. We must create both sections in
3249 create_dynamic_sections, because they must be created
3250 before the linker maps input sections to output
3251 sections. The linker does that before
3252 adjust_dynamic_symbol is called, and it is that
3253 function which decides whether anything needs to go
3254 into these sections. */
3256 s
->flags
|= SEC_EXCLUDE
;
3260 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3263 /* Allocate memory for the section contents. We use bfd_zalloc
3264 here in case unused entries are not reclaimed before the
3265 section's contents are written out. This should not happen,
3266 but this way if it does, we get a R_X86_64_NONE reloc instead
3268 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3269 if (s
->contents
== NULL
)
3273 if (htab
->plt_eh_frame
!= NULL
3274 && htab
->plt_eh_frame
->contents
!= NULL
)
3276 memcpy (htab
->plt_eh_frame
->contents
,
3277 htab
->plt
.eh_frame_plt
, htab
->plt_eh_frame
->size
);
3278 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3279 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3282 if (htab
->plt_got_eh_frame
!= NULL
3283 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3285 memcpy (htab
->plt_got_eh_frame
->contents
,
3286 htab
->non_lazy_plt
->eh_frame_plt
,
3287 htab
->plt_got_eh_frame
->size
);
3288 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3289 (htab
->plt_got_eh_frame
->contents
3290 + PLT_FDE_LEN_OFFSET
));
3293 if (htab
->plt_second_eh_frame
!= NULL
3294 && htab
->plt_second_eh_frame
->contents
!= NULL
)
3296 memcpy (htab
->plt_second_eh_frame
->contents
,
3297 htab
->non_lazy_plt
->eh_frame_plt
,
3298 htab
->plt_second_eh_frame
->size
);
3299 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
3300 (htab
->plt_second_eh_frame
->contents
3301 + PLT_FDE_LEN_OFFSET
));
3304 if (htab
->elf
.dynamic_sections_created
)
3306 /* Add some entries to the .dynamic section. We fill in the
3307 values later, in elf_x86_64_finish_dynamic_sections, but we
3308 must add the entries now so that we get the correct size for
3309 the .dynamic section. The DT_DEBUG entry is filled in by the
3310 dynamic linker and used by the debugger. */
3311 #define add_dynamic_entry(TAG, VAL) \
3312 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3314 if (bfd_link_executable (info
))
3316 if (!add_dynamic_entry (DT_DEBUG
, 0))
3320 if (htab
->elf
.splt
->size
!= 0)
3322 /* DT_PLTGOT is used by prelink even if there is no PLT
3324 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3328 if (htab
->elf
.srelplt
->size
!= 0)
3330 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3331 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3332 || !add_dynamic_entry (DT_JMPREL
, 0))
3336 if (htab
->tlsdesc_plt
3337 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
3338 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
3343 if (!add_dynamic_entry (DT_RELA
, 0)
3344 || !add_dynamic_entry (DT_RELASZ
, 0)
3345 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
3348 /* If any dynamic relocs apply to a read-only section,
3349 then we need a DT_TEXTREL entry. */
3350 if ((info
->flags
& DF_TEXTREL
) == 0)
3351 elf_link_hash_traverse (&htab
->elf
,
3352 _bfd_x86_elf_readonly_dynrelocs
,
3355 if ((info
->flags
& DF_TEXTREL
) != 0)
3357 if (htab
->readonly_dynrelocs_against_ifunc
)
3359 info
->callbacks
->einfo
3360 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3361 bfd_set_error (bfd_error_bad_value
);
3365 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3370 #undef add_dynamic_entry
3375 /* Return the relocation value for @tpoff relocation
3376 if STT_TLS virtual address is ADDRESS. */
3379 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3381 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3382 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3383 bfd_vma static_tls_size
;
3385 /* If tls_segment is NULL, we should have signalled an error already. */
3386 if (htab
->tls_sec
== NULL
)
3389 /* Consider special static TLS alignment requirements. */
3390 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3391 return address
- static_tls_size
- htab
->tls_sec
->vma
;
3394 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3398 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
3400 /* Opcode Instruction
3403 0x0f 0x8x conditional jump */
3405 && (contents
[offset
- 1] == 0xe8
3406 || contents
[offset
- 1] == 0xe9))
3408 && contents
[offset
- 2] == 0x0f
3409 && (contents
[offset
- 1] & 0xf0) == 0x80));
3412 /* Relocate an x86_64 ELF section. */
3415 elf_x86_64_relocate_section (bfd
*output_bfd
,
3416 struct bfd_link_info
*info
,
3418 asection
*input_section
,
3420 Elf_Internal_Rela
*relocs
,
3421 Elf_Internal_Sym
*local_syms
,
3422 asection
**local_sections
)
3424 struct elf_x86_link_hash_table
*htab
;
3425 Elf_Internal_Shdr
*symtab_hdr
;
3426 struct elf_link_hash_entry
**sym_hashes
;
3427 bfd_vma
*local_got_offsets
;
3428 bfd_vma
*local_tlsdesc_gotents
;
3429 Elf_Internal_Rela
*rel
;
3430 Elf_Internal_Rela
*wrel
;
3431 Elf_Internal_Rela
*relend
;
3432 unsigned int plt_entry_size
;
3434 BFD_ASSERT (is_x86_64_elf (input_bfd
));
3436 /* Skip if check_relocs failed. */
3437 if (input_section
->check_relocs_failed
)
3440 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
3443 plt_entry_size
= htab
->plt
.plt_entry_size
;
3444 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3445 sym_hashes
= elf_sym_hashes (input_bfd
);
3446 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3447 local_tlsdesc_gotents
= elf_x86_local_tlsdesc_gotent (input_bfd
);
3449 _bfd_x86_elf_set_tls_module_base (info
);
3451 rel
= wrel
= relocs
;
3452 relend
= relocs
+ input_section
->reloc_count
;
3453 for (; rel
< relend
; wrel
++, rel
++)
3455 unsigned int r_type
;
3456 reloc_howto_type
*howto
;
3457 unsigned long r_symndx
;
3458 struct elf_link_hash_entry
*h
;
3459 struct elf_x86_link_hash_entry
*eh
;
3460 Elf_Internal_Sym
*sym
;
3462 bfd_vma off
, offplt
, plt_offset
;
3464 bfd_boolean unresolved_reloc
;
3465 bfd_reloc_status_type r
;
3467 asection
*base_got
, *resolved_plt
;
3469 bfd_boolean resolved_to_zero
;
3470 bfd_boolean relative_reloc
;
3472 r_type
= ELF32_R_TYPE (rel
->r_info
);
3473 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3474 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3481 if (r_type
>= (int) R_X86_64_standard
)
3482 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
3484 if (r_type
!= (int) R_X86_64_32
3485 || ABI_64_P (output_bfd
))
3486 howto
= x86_64_elf_howto_table
+ r_type
;
3488 howto
= (x86_64_elf_howto_table
3489 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3490 r_symndx
= htab
->r_sym (rel
->r_info
);
3494 unresolved_reloc
= FALSE
;
3495 if (r_symndx
< symtab_hdr
->sh_info
)
3497 sym
= local_syms
+ r_symndx
;
3498 sec
= local_sections
[r_symndx
];
3500 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3502 st_size
= sym
->st_size
;
3504 /* Relocate against local STT_GNU_IFUNC symbol. */
3505 if (!bfd_link_relocatable (info
)
3506 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3508 h
= _bfd_elf_x86_get_local_sym_hash (htab
, input_bfd
,
3513 /* Set STT_GNU_IFUNC symbol value. */
3514 h
->root
.u
.def
.value
= sym
->st_value
;
3515 h
->root
.u
.def
.section
= sec
;
3520 bfd_boolean warned ATTRIBUTE_UNUSED
;
3521 bfd_boolean ignored ATTRIBUTE_UNUSED
;
3523 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3524 r_symndx
, symtab_hdr
, sym_hashes
,
3526 unresolved_reloc
, warned
, ignored
);
3530 if (sec
!= NULL
&& discarded_section (sec
))
3532 _bfd_clear_contents (howto
, input_bfd
, input_section
,
3533 contents
+ rel
->r_offset
);
3534 wrel
->r_offset
= rel
->r_offset
;
3538 /* For ld -r, remove relocations in debug sections against
3539 sections defined in discarded sections. Not done for
3540 eh_frame editing code expects to be present. */
3541 if (bfd_link_relocatable (info
)
3542 && (input_section
->flags
& SEC_DEBUGGING
))
3548 if (bfd_link_relocatable (info
))
3555 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
3557 if (r_type
== R_X86_64_64
)
3559 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
3560 zero-extend it to 64bit if addend is zero. */
3561 r_type
= R_X86_64_32
;
3562 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3564 else if (r_type
== R_X86_64_SIZE64
)
3566 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
3567 zero-extend it to 64bit if addend is zero. */
3568 r_type
= R_X86_64_SIZE32
;
3569 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3573 eh
= (struct elf_x86_link_hash_entry
*) h
;
3575 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3576 it here if it is defined in a non-shared object. */
3578 && h
->type
== STT_GNU_IFUNC
3584 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3586 /* Dynamic relocs are not propagated for SEC_DEBUGGING
3587 sections because such sections are not SEC_ALLOC and
3588 thus ld.so will not process them. */
3589 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
3599 case R_X86_64_GOTPCREL
:
3600 case R_X86_64_GOTPCRELX
:
3601 case R_X86_64_REX_GOTPCRELX
:
3602 case R_X86_64_GOTPCREL64
:
3603 base_got
= htab
->elf
.sgot
;
3604 off
= h
->got
.offset
;
3606 if (base_got
== NULL
)
3609 if (off
== (bfd_vma
) -1)
3611 /* We can't use h->got.offset here to save state, or
3612 even just remember the offset, as finish_dynamic_symbol
3613 would use that as offset into .got. */
3615 if (h
->plt
.offset
== (bfd_vma
) -1)
3618 if (htab
->elf
.splt
!= NULL
)
3620 plt_index
= (h
->plt
.offset
/ plt_entry_size
3621 - htab
->plt
.has_plt0
);
3622 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3623 base_got
= htab
->elf
.sgotplt
;
3627 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3628 off
= plt_index
* GOT_ENTRY_SIZE
;
3629 base_got
= htab
->elf
.igotplt
;
3632 if (h
->dynindx
== -1
3636 /* This references the local defitionion. We must
3637 initialize this entry in the global offset table.
3638 Since the offset must always be a multiple of 8,
3639 we use the least significant bit to record
3640 whether we have initialized it already.
3642 When doing a dynamic link, we create a .rela.got
3643 relocation entry to initialize the value. This
3644 is done in the finish_dynamic_symbol routine. */
3649 bfd_put_64 (output_bfd
, relocation
,
3650 base_got
->contents
+ off
);
3651 /* Note that this is harmless for the GOTPLT64
3652 case, as -1 | 1 still is -1. */
3658 relocation
= (base_got
->output_section
->vma
3659 + base_got
->output_offset
+ off
);
3664 if (h
->plt
.offset
== (bfd_vma
) -1)
3666 /* Handle static pointers of STT_GNU_IFUNC symbols. */
3667 if (r_type
== htab
->pointer_r_type
3668 && (input_section
->flags
& SEC_CODE
) == 0)
3669 goto do_ifunc_pointer
;
3670 goto bad_ifunc_reloc
;
3673 /* STT_GNU_IFUNC symbol must go through PLT. */
3674 if (htab
->elf
.splt
!= NULL
)
3676 if (htab
->plt_second
!= NULL
)
3678 resolved_plt
= htab
->plt_second
;
3679 plt_offset
= eh
->plt_second
.offset
;
3683 resolved_plt
= htab
->elf
.splt
;
3684 plt_offset
= h
->plt
.offset
;
3689 resolved_plt
= htab
->elf
.iplt
;
3690 plt_offset
= h
->plt
.offset
;
3693 relocation
= (resolved_plt
->output_section
->vma
3694 + resolved_plt
->output_offset
+ plt_offset
);
3700 if (h
->root
.root
.string
)
3701 name
= h
->root
.root
.string
;
3703 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3706 /* xgettext:c-format */
3707 (_("%B: relocation %s against STT_GNU_IFUNC "
3708 "symbol `%s' isn't supported"), input_bfd
,
3710 bfd_set_error (bfd_error_bad_value
);
3714 if (bfd_link_pic (info
))
3719 if (ABI_64_P (output_bfd
))
3724 if (rel
->r_addend
!= 0)
3726 if (h
->root
.root
.string
)
3727 name
= h
->root
.root
.string
;
3729 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3732 /* xgettext:c-format */
3733 (_("%B: relocation %s against STT_GNU_IFUNC "
3734 "symbol `%s' has non-zero addend: %Ld"),
3735 input_bfd
, howto
->name
, name
, rel
->r_addend
);
3736 bfd_set_error (bfd_error_bad_value
);
3740 /* Generate dynamic relcoation only when there is a
3741 non-GOT reference in a shared object or there is no
3743 if ((bfd_link_pic (info
) && h
->non_got_ref
)
3744 || h
->plt
.offset
== (bfd_vma
) -1)
3746 Elf_Internal_Rela outrel
;
3749 /* Need a dynamic relocation to get the real function
3751 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3755 if (outrel
.r_offset
== (bfd_vma
) -1
3756 || outrel
.r_offset
== (bfd_vma
) -2)
3759 outrel
.r_offset
+= (input_section
->output_section
->vma
3760 + input_section
->output_offset
);
3762 if (h
->dynindx
== -1
3764 || bfd_link_executable (info
))
3766 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
3767 h
->root
.root
.string
,
3768 h
->root
.u
.def
.section
->owner
);
3770 /* This symbol is resolved locally. */
3771 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3772 outrel
.r_addend
= (h
->root
.u
.def
.value
3773 + h
->root
.u
.def
.section
->output_section
->vma
3774 + h
->root
.u
.def
.section
->output_offset
);
3778 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3779 outrel
.r_addend
= 0;
3782 /* Dynamic relocations are stored in
3783 1. .rela.ifunc section in PIC object.
3784 2. .rela.got section in dynamic executable.
3785 3. .rela.iplt section in static executable. */
3786 if (bfd_link_pic (info
))
3787 sreloc
= htab
->elf
.irelifunc
;
3788 else if (htab
->elf
.splt
!= NULL
)
3789 sreloc
= htab
->elf
.srelgot
;
3791 sreloc
= htab
->elf
.irelplt
;
3792 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3794 /* If this reloc is against an external symbol, we
3795 do not want to fiddle with the addend. Otherwise,
3796 we need to include the symbol value so that it
3797 becomes an addend for the dynamic reloc. For an
3798 internal symbol, we have updated addend. */
3803 case R_X86_64_PC32_BND
:
3805 case R_X86_64_PLT32
:
3806 case R_X86_64_PLT32_BND
:
3811 resolved_to_zero
= (eh
!= NULL
3812 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3817 /* When generating a shared object, the relocations handled here are
3818 copied into the output file to be resolved at run time. */
3821 case R_X86_64_GOT32
:
3822 case R_X86_64_GOT64
:
3823 /* Relocation is to the entry for this symbol in the global
3825 case R_X86_64_GOTPCREL
:
3826 case R_X86_64_GOTPCRELX
:
3827 case R_X86_64_REX_GOTPCRELX
:
3828 case R_X86_64_GOTPCREL64
:
3829 /* Use global offset table entry as symbol value. */
3830 case R_X86_64_GOTPLT64
:
3831 /* This is obsolete and treated the same as GOT64. */
3832 base_got
= htab
->elf
.sgot
;
3834 if (htab
->elf
.sgot
== NULL
)
3837 relative_reloc
= FALSE
;
3842 off
= h
->got
.offset
;
3844 && h
->plt
.offset
!= (bfd_vma
)-1
3845 && off
== (bfd_vma
)-1)
3847 /* We can't use h->got.offset here to save
3848 state, or even just remember the offset, as
3849 finish_dynamic_symbol would use that as offset into
3851 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
3852 - htab
->plt
.has_plt0
);
3853 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3854 base_got
= htab
->elf
.sgotplt
;
3857 dyn
= htab
->elf
.dynamic_sections_created
;
3859 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
3860 || (bfd_link_pic (info
)
3861 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3862 || (ELF_ST_VISIBILITY (h
->other
)
3863 && h
->root
.type
== bfd_link_hash_undefweak
))
3865 /* This is actually a static link, or it is a -Bsymbolic
3866 link and the symbol is defined locally, or the symbol
3867 was forced to be local because of a version file. We
3868 must initialize this entry in the global offset table.
3869 Since the offset must always be a multiple of 8, we
3870 use the least significant bit to record whether we
3871 have initialized it already.
3873 When doing a dynamic link, we create a .rela.got
3874 relocation entry to initialize the value. This is
3875 done in the finish_dynamic_symbol routine. */
3880 bfd_put_64 (output_bfd
, relocation
,
3881 base_got
->contents
+ off
);
3882 /* Note that this is harmless for the GOTPLT64 case,
3883 as -1 | 1 still is -1. */
3886 if (h
->dynindx
== -1
3888 && h
->root
.type
!= bfd_link_hash_undefweak
3889 && bfd_link_pic (info
))
3891 /* If this symbol isn't dynamic in PIC,
3892 generate R_X86_64_RELATIVE here. */
3893 eh
->no_finish_dynamic_symbol
= 1;
3894 relative_reloc
= TRUE
;
3899 unresolved_reloc
= FALSE
;
3903 if (local_got_offsets
== NULL
)
3906 off
= local_got_offsets
[r_symndx
];
3908 /* The offset must always be a multiple of 8. We use
3909 the least significant bit to record whether we have
3910 already generated the necessary reloc. */
3915 bfd_put_64 (output_bfd
, relocation
,
3916 base_got
->contents
+ off
);
3917 local_got_offsets
[r_symndx
] |= 1;
3919 if (bfd_link_pic (info
))
3920 relative_reloc
= TRUE
;
3927 Elf_Internal_Rela outrel
;
3929 /* We need to generate a R_X86_64_RELATIVE reloc
3930 for the dynamic linker. */
3931 s
= htab
->elf
.srelgot
;
3935 outrel
.r_offset
= (base_got
->output_section
->vma
3936 + base_got
->output_offset
3938 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3939 outrel
.r_addend
= relocation
;
3940 elf_append_rela (output_bfd
, s
, &outrel
);
3943 if (off
>= (bfd_vma
) -2)
3946 relocation
= base_got
->output_section
->vma
3947 + base_got
->output_offset
+ off
;
3948 if (r_type
!= R_X86_64_GOTPCREL
3949 && r_type
!= R_X86_64_GOTPCRELX
3950 && r_type
!= R_X86_64_REX_GOTPCRELX
3951 && r_type
!= R_X86_64_GOTPCREL64
)
3952 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3953 - htab
->elf
.sgotplt
->output_offset
;
3957 case R_X86_64_GOTOFF64
:
3958 /* Relocation is relative to the start of the global offset
3961 /* Check to make sure it isn't a protected function or data
3962 symbol for shared library since it may not be local when
3963 used as function address or with copy relocation. We also
3964 need to make sure that a symbol is referenced locally. */
3965 if (bfd_link_pic (info
) && h
)
3967 if (!h
->def_regular
)
3971 switch (ELF_ST_VISIBILITY (h
->other
))
3974 v
= _("hidden symbol");
3977 v
= _("internal symbol");
3980 v
= _("protected symbol");
3988 /* xgettext:c-format */
3989 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
3990 " `%s' can not be used when making a shared object"),
3991 input_bfd
, v
, h
->root
.root
.string
);
3992 bfd_set_error (bfd_error_bad_value
);
3995 else if (!bfd_link_executable (info
)
3996 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
3997 && (h
->type
== STT_FUNC
3998 || h
->type
== STT_OBJECT
)
3999 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4002 /* xgettext:c-format */
4003 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4004 " `%s' can not be used when making a shared object"),
4006 h
->type
== STT_FUNC
? "function" : "data",
4007 h
->root
.root
.string
);
4008 bfd_set_error (bfd_error_bad_value
);
4013 /* Note that sgot is not involved in this
4014 calculation. We always want the start of .got.plt. If we
4015 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4016 permitted by the ABI, we might have to change this
4018 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4019 + htab
->elf
.sgotplt
->output_offset
;
4022 case R_X86_64_GOTPC32
:
4023 case R_X86_64_GOTPC64
:
4024 /* Use global offset table as symbol value. */
4025 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4026 + htab
->elf
.sgotplt
->output_offset
;
4027 unresolved_reloc
= FALSE
;
4030 case R_X86_64_PLTOFF64
:
4031 /* Relocation is PLT entry relative to GOT. For local
4032 symbols it's the symbol itself relative to GOT. */
4034 /* See PLT32 handling. */
4035 && (h
->plt
.offset
!= (bfd_vma
) -1
4036 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4037 && htab
->elf
.splt
!= NULL
)
4039 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4041 /* Use the GOT PLT. */
4042 resolved_plt
= htab
->plt_got
;
4043 plt_offset
= eh
->plt_got
.offset
;
4045 else if (htab
->plt_second
!= NULL
)
4047 resolved_plt
= htab
->plt_second
;
4048 plt_offset
= eh
->plt_second
.offset
;
4052 resolved_plt
= htab
->elf
.splt
;
4053 plt_offset
= h
->plt
.offset
;
4056 relocation
= (resolved_plt
->output_section
->vma
4057 + resolved_plt
->output_offset
4059 unresolved_reloc
= FALSE
;
4062 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4063 + htab
->elf
.sgotplt
->output_offset
;
4066 case R_X86_64_PLT32
:
4067 case R_X86_64_PLT32_BND
:
4068 /* Relocation is to the entry for this symbol in the
4069 procedure linkage table. */
4071 /* Resolve a PLT32 reloc against a local symbol directly,
4072 without using the procedure linkage table. */
4076 if ((h
->plt
.offset
== (bfd_vma
) -1
4077 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4078 || htab
->elf
.splt
== NULL
)
4080 /* We didn't make a PLT entry for this symbol. This
4081 happens when statically linking PIC code, or when
4082 using -Bsymbolic. */
4086 if (h
->plt
.offset
!= (bfd_vma
) -1)
4088 if (htab
->plt_second
!= NULL
)
4090 resolved_plt
= htab
->plt_second
;
4091 plt_offset
= eh
->plt_second
.offset
;
4095 resolved_plt
= htab
->elf
.splt
;
4096 plt_offset
= h
->plt
.offset
;
4101 /* Use the GOT PLT. */
4102 resolved_plt
= htab
->plt_got
;
4103 plt_offset
= eh
->plt_got
.offset
;
4106 relocation
= (resolved_plt
->output_section
->vma
4107 + resolved_plt
->output_offset
4109 unresolved_reloc
= FALSE
;
4112 case R_X86_64_SIZE32
:
4113 case R_X86_64_SIZE64
:
4114 /* Set to symbol size. */
4115 relocation
= st_size
;
4121 case R_X86_64_PC32_BND
:
4122 /* Don't complain about -fPIC if the symbol is undefined when
4123 building executable unless it is unresolved weak symbol or
4124 -z nocopyreloc is used. */
4125 if ((input_section
->flags
& SEC_ALLOC
) != 0
4126 && (input_section
->flags
& SEC_READONLY
) != 0
4128 && ((bfd_link_executable (info
)
4129 && ((h
->root
.type
== bfd_link_hash_undefweak
4130 && !resolved_to_zero
)
4131 || ((info
->nocopyreloc
4132 || (eh
->def_protected
4133 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
4135 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))))
4136 || bfd_link_dll (info
)))
4138 bfd_boolean fail
= FALSE
;
4140 = ((r_type
== R_X86_64_PC32
4141 || r_type
== R_X86_64_PC32_BND
)
4142 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4144 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4146 /* Symbol is referenced locally. Make sure it is
4147 defined locally or for a branch. */
4148 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4151 else if (!(bfd_link_pie (info
)
4152 && (h
->needs_copy
|| eh
->needs_copy
)))
4154 /* Symbol doesn't need copy reloc and isn't referenced
4155 locally. We only allow branch to symbol with
4156 non-default visibility. */
4158 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4162 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
4163 h
, NULL
, NULL
, howto
);
4172 /* FIXME: The ABI says the linker should make sure the value is
4173 the same when it's zeroextended to 64 bit. */
4176 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4179 /* Don't copy a pc-relative relocation into the output file
4180 if the symbol needs copy reloc or the symbol is undefined
4181 when building executable. Copy dynamic function pointer
4182 relocations. Don't generate dynamic relocations against
4183 resolved undefined weak symbols in PIE. */
4184 if ((bfd_link_pic (info
)
4185 && !(bfd_link_pie (info
)
4189 || h
->root
.type
== bfd_link_hash_undefined
)
4190 && (IS_X86_64_PCREL_TYPE (r_type
)
4191 || r_type
== R_X86_64_SIZE32
4192 || r_type
== R_X86_64_SIZE64
))
4194 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4195 && !resolved_to_zero
)
4196 || h
->root
.type
!= bfd_link_hash_undefweak
))
4197 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4198 && r_type
!= R_X86_64_SIZE32
4199 && r_type
!= R_X86_64_SIZE64
)
4200 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4201 || (ELIMINATE_COPY_RELOCS
4202 && !bfd_link_pic (info
)
4206 || eh
->func_pointer_refcount
> 0
4207 || (h
->root
.type
== bfd_link_hash_undefweak
4208 && !resolved_to_zero
))
4209 && ((h
->def_dynamic
&& !h
->def_regular
)
4210 /* Undefined weak symbol is bound locally when
4212 || h
->root
.type
== bfd_link_hash_undefined
)))
4214 Elf_Internal_Rela outrel
;
4215 bfd_boolean skip
, relocate
;
4218 /* When generating a shared object, these relocations
4219 are copied into the output file to be resolved at run
4225 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4227 if (outrel
.r_offset
== (bfd_vma
) -1)
4229 else if (outrel
.r_offset
== (bfd_vma
) -2)
4230 skip
= TRUE
, relocate
= TRUE
;
4232 outrel
.r_offset
+= (input_section
->output_section
->vma
4233 + input_section
->output_offset
);
4236 memset (&outrel
, 0, sizeof outrel
);
4238 /* h->dynindx may be -1 if this symbol was marked to
4242 && (IS_X86_64_PCREL_TYPE (r_type
)
4243 || !(bfd_link_executable (info
)
4244 || SYMBOLIC_BIND (info
, h
))
4245 || ! h
->def_regular
))
4247 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4248 outrel
.r_addend
= rel
->r_addend
;
4252 /* This symbol is local, or marked to become local.
4253 When relocation overflow check is disabled, we
4254 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4255 if (r_type
== htab
->pointer_r_type
4256 || (r_type
== R_X86_64_32
4257 && info
->no_reloc_overflow_check
))
4260 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4261 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4263 else if (r_type
== R_X86_64_64
4264 && !ABI_64_P (output_bfd
))
4267 outrel
.r_info
= htab
->r_info (0,
4268 R_X86_64_RELATIVE64
);
4269 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4270 /* Check addend overflow. */
4271 if ((outrel
.r_addend
& 0x80000000)
4272 != (rel
->r_addend
& 0x80000000))
4275 int addend
= rel
->r_addend
;
4276 if (h
&& h
->root
.root
.string
)
4277 name
= h
->root
.root
.string
;
4279 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4282 /* xgettext:c-format */
4283 (_("%B: addend %s%#x in relocation %s against "
4284 "symbol `%s' at %#Lx in section `%A' is "
4286 input_bfd
, addend
< 0 ? "-" : "", addend
,
4287 howto
->name
, name
, rel
->r_offset
, input_section
);
4288 bfd_set_error (bfd_error_bad_value
);
4296 if (bfd_is_abs_section (sec
))
4298 else if (sec
== NULL
|| sec
->owner
== NULL
)
4300 bfd_set_error (bfd_error_bad_value
);
4307 /* We are turning this relocation into one
4308 against a section symbol. It would be
4309 proper to subtract the symbol's value,
4310 osec->vma, from the emitted reloc addend,
4311 but ld.so expects buggy relocs. */
4312 osec
= sec
->output_section
;
4313 sindx
= elf_section_data (osec
)->dynindx
;
4316 asection
*oi
= htab
->elf
.text_index_section
;
4317 sindx
= elf_section_data (oi
)->dynindx
;
4319 BFD_ASSERT (sindx
!= 0);
4322 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
4323 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4327 sreloc
= elf_section_data (input_section
)->sreloc
;
4329 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4331 r
= bfd_reloc_notsupported
;
4332 goto check_relocation_error
;
4335 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4337 /* If this reloc is against an external symbol, we do
4338 not want to fiddle with the addend. Otherwise, we
4339 need to include the symbol value so that it becomes
4340 an addend for the dynamic reloc. */
4347 case R_X86_64_TLSGD
:
4348 case R_X86_64_GOTPC32_TLSDESC
:
4349 case R_X86_64_TLSDESC_CALL
:
4350 case R_X86_64_GOTTPOFF
:
4351 tls_type
= GOT_UNKNOWN
;
4352 if (h
== NULL
&& local_got_offsets
)
4353 tls_type
= elf_x86_local_got_tls_type (input_bfd
) [r_symndx
];
4355 tls_type
= elf_x86_hash_entry (h
)->tls_type
;
4357 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4358 input_section
, contents
,
4359 symtab_hdr
, sym_hashes
,
4360 &r_type
, tls_type
, rel
,
4361 relend
, h
, r_symndx
, TRUE
))
4364 if (r_type
== R_X86_64_TPOFF32
)
4366 bfd_vma roff
= rel
->r_offset
;
4368 BFD_ASSERT (! unresolved_reloc
);
4370 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4372 /* GD->LE transition. For 64bit, change
4373 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4374 .word 0x6666; rex64; call __tls_get_addr@PLT
4376 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4378 call *__tls_get_addr@GOTPCREL(%rip)
4379 which may be converted to
4380 addr32 call __tls_get_addr
4383 leaq foo@tpoff(%rax), %rax
4385 leaq foo@tlsgd(%rip), %rdi
4386 .word 0x6666; rex64; call __tls_get_addr@PLT
4388 leaq foo@tlsgd(%rip), %rdi
4390 call *__tls_get_addr@GOTPCREL(%rip)
4391 which may be converted to
4392 addr32 call __tls_get_addr
4395 leaq foo@tpoff(%rax), %rax
4396 For largepic, change:
4397 leaq foo@tlsgd(%rip), %rdi
4398 movabsq $__tls_get_addr@pltoff, %rax
4403 leaq foo@tpoff(%rax), %rax
4404 nopw 0x0(%rax,%rax,1) */
4406 if (ABI_64_P (output_bfd
))
4408 if (contents
[roff
+ 5] == 0xb8)
4410 memcpy (contents
+ roff
- 3,
4411 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
4412 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4416 memcpy (contents
+ roff
- 4,
4417 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4421 memcpy (contents
+ roff
- 3,
4422 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
4424 bfd_put_32 (output_bfd
,
4425 elf_x86_64_tpoff (info
, relocation
),
4426 contents
+ roff
+ 8 + largepic
);
4427 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
4428 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
4433 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4435 /* GDesc -> LE transition.
4436 It's originally something like:
4437 leaq x@tlsdesc(%rip), %rax
4440 movl $x@tpoff, %rax. */
4442 unsigned int val
, type
;
4444 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
4445 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4446 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
4447 contents
+ roff
- 3);
4448 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
4449 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
4450 contents
+ roff
- 1);
4451 bfd_put_32 (output_bfd
,
4452 elf_x86_64_tpoff (info
, relocation
),
4456 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4458 /* GDesc -> LE transition.
4463 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4464 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4467 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
4469 /* IE->LE transition:
4470 For 64bit, originally it can be one of:
4471 movq foo@gottpoff(%rip), %reg
4472 addq foo@gottpoff(%rip), %reg
4475 leaq foo(%reg), %reg
4477 For 32bit, originally it can be one of:
4478 movq foo@gottpoff(%rip), %reg
4479 addl foo@gottpoff(%rip), %reg
4482 leal foo(%reg), %reg
4485 unsigned int val
, type
, reg
;
4488 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
4491 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
4492 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
4498 bfd_put_8 (output_bfd
, 0x49,
4499 contents
+ roff
- 3);
4500 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4501 bfd_put_8 (output_bfd
, 0x41,
4502 contents
+ roff
- 3);
4503 bfd_put_8 (output_bfd
, 0xc7,
4504 contents
+ roff
- 2);
4505 bfd_put_8 (output_bfd
, 0xc0 | reg
,
4506 contents
+ roff
- 1);
4510 /* addq/addl -> addq/addl - addressing with %rsp/%r12
4513 bfd_put_8 (output_bfd
, 0x49,
4514 contents
+ roff
- 3);
4515 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4516 bfd_put_8 (output_bfd
, 0x41,
4517 contents
+ roff
- 3);
4518 bfd_put_8 (output_bfd
, 0x81,
4519 contents
+ roff
- 2);
4520 bfd_put_8 (output_bfd
, 0xc0 | reg
,
4521 contents
+ roff
- 1);
4525 /* addq/addl -> leaq/leal */
4527 bfd_put_8 (output_bfd
, 0x4d,
4528 contents
+ roff
- 3);
4529 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
4530 bfd_put_8 (output_bfd
, 0x45,
4531 contents
+ roff
- 3);
4532 bfd_put_8 (output_bfd
, 0x8d,
4533 contents
+ roff
- 2);
4534 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
4535 contents
+ roff
- 1);
4537 bfd_put_32 (output_bfd
,
4538 elf_x86_64_tpoff (info
, relocation
),
4546 if (htab
->elf
.sgot
== NULL
)
4551 off
= h
->got
.offset
;
4552 offplt
= elf_x86_hash_entry (h
)->tlsdesc_got
;
4556 if (local_got_offsets
== NULL
)
4559 off
= local_got_offsets
[r_symndx
];
4560 offplt
= local_tlsdesc_gotents
[r_symndx
];
4567 Elf_Internal_Rela outrel
;
4571 if (htab
->elf
.srelgot
== NULL
)
4574 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4576 if (GOT_TLS_GDESC_P (tls_type
))
4578 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
4579 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
4580 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
4581 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
4582 + htab
->elf
.sgotplt
->output_offset
4584 + htab
->sgotplt_jump_table_size
);
4585 sreloc
= htab
->elf
.srelplt
;
4587 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
4589 outrel
.r_addend
= 0;
4590 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4593 sreloc
= htab
->elf
.srelgot
;
4595 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4596 + htab
->elf
.sgot
->output_offset
+ off
);
4598 if (GOT_TLS_GD_P (tls_type
))
4599 dr_type
= R_X86_64_DTPMOD64
;
4600 else if (GOT_TLS_GDESC_P (tls_type
))
4603 dr_type
= R_X86_64_TPOFF64
;
4605 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
4606 outrel
.r_addend
= 0;
4607 if ((dr_type
== R_X86_64_TPOFF64
4608 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
4609 outrel
.r_addend
= relocation
- _bfd_x86_elf_dtpoff_base (info
);
4610 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
4612 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4614 if (GOT_TLS_GD_P (tls_type
))
4618 BFD_ASSERT (! unresolved_reloc
);
4619 bfd_put_64 (output_bfd
,
4620 relocation
- _bfd_x86_elf_dtpoff_base (info
),
4621 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4625 bfd_put_64 (output_bfd
, 0,
4626 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4627 outrel
.r_info
= htab
->r_info (indx
,
4629 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
4630 elf_append_rela (output_bfd
, sreloc
,
4639 local_got_offsets
[r_symndx
] |= 1;
4642 if (off
>= (bfd_vma
) -2
4643 && ! GOT_TLS_GDESC_P (tls_type
))
4645 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
4647 if (r_type
== R_X86_64_GOTPC32_TLSDESC
4648 || r_type
== R_X86_64_TLSDESC_CALL
)
4649 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4650 + htab
->elf
.sgotplt
->output_offset
4651 + offplt
+ htab
->sgotplt_jump_table_size
;
4653 relocation
= htab
->elf
.sgot
->output_section
->vma
4654 + htab
->elf
.sgot
->output_offset
+ off
;
4655 unresolved_reloc
= FALSE
;
4659 bfd_vma roff
= rel
->r_offset
;
4661 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4663 /* GD->IE transition. For 64bit, change
4664 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4665 .word 0x6666; rex64; call __tls_get_addr@PLT
4667 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4669 call *__tls_get_addr@GOTPCREL(%rip
4670 which may be converted to
4671 addr32 call __tls_get_addr
4674 addq foo@gottpoff(%rip), %rax
4676 leaq foo@tlsgd(%rip), %rdi
4677 .word 0x6666; rex64; call __tls_get_addr@PLT
4679 leaq foo@tlsgd(%rip), %rdi
4681 call *__tls_get_addr@GOTPCREL(%rip)
4682 which may be converted to
4683 addr32 call __tls_get_addr
4686 addq foo@gottpoff(%rip), %rax
4687 For largepic, change:
4688 leaq foo@tlsgd(%rip), %rdi
4689 movabsq $__tls_get_addr@pltoff, %rax
4694 addq foo@gottpoff(%rax), %rax
4695 nopw 0x0(%rax,%rax,1) */
4697 if (ABI_64_P (output_bfd
))
4699 if (contents
[roff
+ 5] == 0xb8)
4701 memcpy (contents
+ roff
- 3,
4702 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
4703 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
4707 memcpy (contents
+ roff
- 4,
4708 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4712 memcpy (contents
+ roff
- 3,
4713 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4716 relocation
= (htab
->elf
.sgot
->output_section
->vma
4717 + htab
->elf
.sgot
->output_offset
+ off
4720 - input_section
->output_section
->vma
4721 - input_section
->output_offset
4723 bfd_put_32 (output_bfd
, relocation
,
4724 contents
+ roff
+ 8 + largepic
);
4725 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
4730 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4732 /* GDesc -> IE transition.
4733 It's originally something like:
4734 leaq x@tlsdesc(%rip), %rax
4737 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4739 /* Now modify the instruction as appropriate. To
4740 turn a leaq into a movq in the form we use it, it
4741 suffices to change the second byte from 0x8d to
4743 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4745 bfd_put_32 (output_bfd
,
4746 htab
->elf
.sgot
->output_section
->vma
4747 + htab
->elf
.sgot
->output_offset
+ off
4749 - input_section
->output_section
->vma
4750 - input_section
->output_offset
4755 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4757 /* GDesc -> IE transition.
4764 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4765 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4773 case R_X86_64_TLSLD
:
4774 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4775 input_section
, contents
,
4776 symtab_hdr
, sym_hashes
,
4777 &r_type
, GOT_UNKNOWN
, rel
,
4778 relend
, h
, r_symndx
, TRUE
))
4781 if (r_type
!= R_X86_64_TLSLD
)
4783 /* LD->LE transition:
4784 leaq foo@tlsld(%rip), %rdi
4785 call __tls_get_addr@PLT
4786 For 64bit, we change it into:
4787 .word 0x6666; .byte 0x66; movq %fs:0, %rax
4788 For 32bit, we change it into:
4789 nopl 0x0(%rax); movl %fs:0, %eax
4791 leaq foo@tlsld(%rip), %rdi;
4792 call *__tls_get_addr@GOTPCREL(%rip)
4793 which may be converted to
4794 addr32 call __tls_get_addr
4795 For 64bit, we change it into:
4796 .word 0x6666; .word 0x6666; movq %fs:0, %rax
4797 For 32bit, we change it into:
4798 nopw 0x0(%rax); movl %fs:0, %eax
4799 For largepic, change:
4800 leaq foo@tlsgd(%rip), %rdi
4801 movabsq $__tls_get_addr@pltoff, %rax
4805 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
4808 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4809 if (ABI_64_P (output_bfd
))
4811 if (contents
[rel
->r_offset
+ 5] == 0xb8)
4812 memcpy (contents
+ rel
->r_offset
- 3,
4813 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
4814 "\x64\x48\x8b\x04\x25\0\0\0", 22);
4815 else if (contents
[rel
->r_offset
+ 4] == 0xff
4816 || contents
[rel
->r_offset
+ 4] == 0x67)
4817 memcpy (contents
+ rel
->r_offset
- 3,
4818 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
4821 memcpy (contents
+ rel
->r_offset
- 3,
4822 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4826 if (contents
[rel
->r_offset
+ 4] == 0xff)
4827 memcpy (contents
+ rel
->r_offset
- 3,
4828 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
4831 memcpy (contents
+ rel
->r_offset
- 3,
4832 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4834 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
4835 and R_X86_64_PLTOFF64. */
4841 if (htab
->elf
.sgot
== NULL
)
4844 off
= htab
->tls_ld_or_ldm_got
.offset
;
4849 Elf_Internal_Rela outrel
;
4851 if (htab
->elf
.srelgot
== NULL
)
4854 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4855 + htab
->elf
.sgot
->output_offset
+ off
);
4857 bfd_put_64 (output_bfd
, 0,
4858 htab
->elf
.sgot
->contents
+ off
);
4859 bfd_put_64 (output_bfd
, 0,
4860 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4861 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4862 outrel
.r_addend
= 0;
4863 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4865 htab
->tls_ld_or_ldm_got
.offset
|= 1;
4867 relocation
= htab
->elf
.sgot
->output_section
->vma
4868 + htab
->elf
.sgot
->output_offset
+ off
;
4869 unresolved_reloc
= FALSE
;
4872 case R_X86_64_DTPOFF32
:
4873 if (!bfd_link_executable (info
)
4874 || (input_section
->flags
& SEC_CODE
) == 0)
4875 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4877 relocation
= elf_x86_64_tpoff (info
, relocation
);
4880 case R_X86_64_TPOFF32
:
4881 case R_X86_64_TPOFF64
:
4882 BFD_ASSERT (bfd_link_executable (info
));
4883 relocation
= elf_x86_64_tpoff (info
, relocation
);
4886 case R_X86_64_DTPOFF64
:
4887 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
4888 relocation
-= _bfd_x86_elf_dtpoff_base (info
);
4895 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4896 because such sections are not SEC_ALLOC and thus ld.so will
4897 not process them. */
4898 if (unresolved_reloc
4899 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4901 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4902 rel
->r_offset
) != (bfd_vma
) -1)
4907 sec
= h
->root
.u
.def
.section
;
4908 if ((info
->nocopyreloc
4909 || (eh
->def_protected
4910 && elf_has_no_copy_on_protected (h
->root
.u
.def
.section
->owner
)))
4911 && !(h
->root
.u
.def
.section
->flags
& SEC_CODE
))
4912 return elf_x86_64_need_pic (info
, input_bfd
, input_section
,
4913 h
, NULL
, NULL
, howto
);
4918 /* xgettext:c-format */
4919 (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
4924 h
->root
.root
.string
);
4930 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4931 contents
, rel
->r_offset
,
4932 relocation
, rel
->r_addend
);
4934 check_relocation_error
:
4935 if (r
!= bfd_reloc_ok
)
4940 name
= h
->root
.root
.string
;
4943 name
= bfd_elf_string_from_elf_section (input_bfd
,
4944 symtab_hdr
->sh_link
,
4949 name
= bfd_section_name (input_bfd
, sec
);
4952 if (r
== bfd_reloc_overflow
)
4953 (*info
->callbacks
->reloc_overflow
)
4954 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4955 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
4959 /* xgettext:c-format */
4960 (_("%B(%A+%#Lx): reloc against `%s': error %d"),
4961 input_bfd
, input_section
,
4962 rel
->r_offset
, name
, (int) r
);
4973 Elf_Internal_Shdr
*rel_hdr
;
4974 size_t deleted
= rel
- wrel
;
4976 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
4977 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4978 if (rel_hdr
->sh_size
== 0)
4980 /* It is too late to remove an empty reloc section. Leave
4982 ??? What is wrong with an empty section??? */
4983 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
4986 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
4987 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
4988 input_section
->reloc_count
-= deleted
;
4994 /* Finish up dynamic symbol handling. We set the contents of various
4995 dynamic sections here. */
4998 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4999 struct bfd_link_info
*info
,
5000 struct elf_link_hash_entry
*h
,
5001 Elf_Internal_Sym
*sym
)
5003 struct elf_x86_link_hash_table
*htab
;
5004 bfd_boolean use_plt_second
;
5005 struct elf_x86_link_hash_entry
*eh
;
5006 bfd_boolean local_undefweak
;
5008 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
5012 /* Use the second PLT section only if there is .plt section. */
5013 use_plt_second
= htab
->elf
.splt
!= NULL
&& htab
->plt_second
!= NULL
;
5015 eh
= (struct elf_x86_link_hash_entry
*) h
;
5016 if (eh
->no_finish_dynamic_symbol
)
5019 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5020 resolved undefined weak symbols in executable so that their
5021 references have value 0 at run-time. */
5022 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5027 if (h
->plt
.offset
!= (bfd_vma
) -1)
5030 bfd_vma got_offset
, plt_offset
;
5031 Elf_Internal_Rela rela
;
5033 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5034 const struct elf_backend_data
*bed
;
5035 bfd_vma plt_got_pcrel_offset
;
5037 /* When building a static executable, use .iplt, .igot.plt and
5038 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5039 if (htab
->elf
.splt
!= NULL
)
5041 plt
= htab
->elf
.splt
;
5042 gotplt
= htab
->elf
.sgotplt
;
5043 relplt
= htab
->elf
.srelplt
;
5047 plt
= htab
->elf
.iplt
;
5048 gotplt
= htab
->elf
.igotplt
;
5049 relplt
= htab
->elf
.irelplt
;
5052 /* This symbol has an entry in the procedure linkage table. Set
5054 if ((h
->dynindx
== -1
5056 && !((h
->forced_local
|| bfd_link_executable (info
))
5058 && h
->type
== STT_GNU_IFUNC
))
5064 /* Get the index in the procedure linkage table which
5065 corresponds to this symbol. This is the index of this symbol
5066 in all the symbols for which we are making plt entries. The
5067 first entry in the procedure linkage table is reserved.
5069 Get the offset into the .got table of the entry that
5070 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5071 bytes. The first three are reserved for the dynamic linker.
5073 For static executables, we don't reserve anything. */
5075 if (plt
== htab
->elf
.splt
)
5077 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
5078 - htab
->plt
.has_plt0
);
5079 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5083 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
5084 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5087 /* Fill in the entry in the procedure linkage table. */
5088 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5089 htab
->plt
.plt_entry_size
);
5092 memcpy (htab
->plt_second
->contents
+ eh
->plt_second
.offset
,
5093 htab
->non_lazy_plt
->plt_entry
,
5094 htab
->non_lazy_plt
->plt_entry_size
);
5096 resolved_plt
= htab
->plt_second
;
5097 plt_offset
= eh
->plt_second
.offset
;
5102 plt_offset
= h
->plt
.offset
;
5105 /* Insert the relocation positions of the plt section. */
5107 /* Put offset the PC-relative instruction referring to the GOT entry,
5108 subtracting the size of that instruction. */
5109 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5110 + gotplt
->output_offset
5112 - resolved_plt
->output_section
->vma
5113 - resolved_plt
->output_offset
5115 - htab
->plt
.plt_got_insn_size
);
5117 /* Check PC-relative offset overflow in PLT entry. */
5118 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5119 /* xgettext:c-format */
5120 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5121 output_bfd
, h
->root
.root
.string
);
5123 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5124 (resolved_plt
->contents
+ plt_offset
5125 + htab
->plt
.plt_got_offset
));
5127 /* Fill in the entry in the global offset table, initially this
5128 points to the second part of the PLT entry. Leave the entry
5129 as zero for undefined weak symbol in PIE. No PLT relocation
5130 against undefined weak symbol in PIE. */
5131 if (!local_undefweak
)
5133 if (htab
->plt
.has_plt0
)
5134 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5135 + plt
->output_offset
5137 + htab
->lazy_plt
->plt_lazy_offset
),
5138 gotplt
->contents
+ got_offset
);
5140 /* Fill in the entry in the .rela.plt section. */
5141 rela
.r_offset
= (gotplt
->output_section
->vma
5142 + gotplt
->output_offset
5144 if (h
->dynindx
== -1
5145 || ((bfd_link_executable (info
)
5146 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5148 && h
->type
== STT_GNU_IFUNC
))
5150 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5151 h
->root
.root
.string
,
5152 h
->root
.u
.def
.section
->owner
);
5154 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5155 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5156 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5157 rela
.r_addend
= (h
->root
.u
.def
.value
5158 + h
->root
.u
.def
.section
->output_section
->vma
5159 + h
->root
.u
.def
.section
->output_offset
);
5160 /* R_X86_64_IRELATIVE comes last. */
5161 plt_index
= htab
->next_irelative_index
--;
5165 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5167 plt_index
= htab
->next_jump_slot_index
++;
5170 /* Don't fill the second and third slots in PLT entry for
5171 static executables nor without PLT0. */
5172 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5175 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
5177 /* Put relocation index. */
5178 bfd_put_32 (output_bfd
, plt_index
,
5179 (plt
->contents
+ h
->plt
.offset
5180 + htab
->lazy_plt
->plt_reloc_offset
));
5182 /* Put offset for jmp .PLT0 and check for overflow. We don't
5183 check relocation index for overflow since branch displacement
5184 will overflow first. */
5185 if (plt0_offset
> 0x80000000)
5186 /* xgettext:c-format */
5187 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5188 output_bfd
, h
->root
.root
.string
);
5189 bfd_put_32 (output_bfd
, - plt0_offset
,
5190 (plt
->contents
+ h
->plt
.offset
5191 + htab
->lazy_plt
->plt_plt_offset
));
5194 bed
= get_elf_backend_data (output_bfd
);
5195 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
5196 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
5199 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5201 bfd_vma got_offset
, plt_offset
;
5202 asection
*plt
, *got
;
5203 bfd_boolean got_after_plt
;
5204 int32_t got_pcrel_offset
;
5206 /* Set the entry in the GOT procedure linkage table. */
5207 plt
= htab
->plt_got
;
5208 got
= htab
->elf
.sgot
;
5209 got_offset
= h
->got
.offset
;
5211 if (got_offset
== (bfd_vma
) -1
5212 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
5217 /* Use the non-lazy PLT entry template for the GOT PLT since they
5218 are the identical. */
5219 /* Fill in the entry in the GOT procedure linkage table. */
5220 plt_offset
= eh
->plt_got
.offset
;
5221 memcpy (plt
->contents
+ plt_offset
,
5222 htab
->non_lazy_plt
->plt_entry
,
5223 htab
->non_lazy_plt
->plt_entry_size
);
5225 /* Put offset the PC-relative instruction referring to the GOT
5226 entry, subtracting the size of that instruction. */
5227 got_pcrel_offset
= (got
->output_section
->vma
5228 + got
->output_offset
5230 - plt
->output_section
->vma
5231 - plt
->output_offset
5233 - htab
->non_lazy_plt
->plt_got_insn_size
);
5235 /* Check PC-relative offset overflow in GOT PLT entry. */
5236 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
5237 if ((got_after_plt
&& got_pcrel_offset
< 0)
5238 || (!got_after_plt
&& got_pcrel_offset
> 0))
5239 /* xgettext:c-format */
5240 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5241 output_bfd
, h
->root
.root
.string
);
5243 bfd_put_32 (output_bfd
, got_pcrel_offset
,
5244 (plt
->contents
+ plt_offset
5245 + htab
->non_lazy_plt
->plt_got_offset
));
5248 if (!local_undefweak
5250 && (h
->plt
.offset
!= (bfd_vma
) -1
5251 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5253 /* Mark the symbol as undefined, rather than as defined in
5254 the .plt section. Leave the value if there were any
5255 relocations where pointer equality matters (this is a clue
5256 for the dynamic linker, to make function pointer
5257 comparisons work between an application and shared
5258 library), otherwise set it to zero. If a function is only
5259 called from a binary, there is no need to slow down
5260 shared libraries because of that. */
5261 sym
->st_shndx
= SHN_UNDEF
;
5262 if (!h
->pointer_equality_needed
)
5266 /* Don't generate dynamic GOT relocation against undefined weak
5267 symbol in executable. */
5268 if (h
->got
.offset
!= (bfd_vma
) -1
5269 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
5270 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
5271 && !local_undefweak
)
5273 Elf_Internal_Rela rela
;
5274 asection
*relgot
= htab
->elf
.srelgot
;
5276 /* This symbol has an entry in the global offset table. Set it
5278 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5281 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5282 + htab
->elf
.sgot
->output_offset
5283 + (h
->got
.offset
&~ (bfd_vma
) 1));
5285 /* If this is a static link, or it is a -Bsymbolic link and the
5286 symbol is defined locally or was forced to be local because
5287 of a version file, we just want to emit a RELATIVE reloc.
5288 The entry in the global offset table will already have been
5289 initialized in the relocate_section function. */
5291 && h
->type
== STT_GNU_IFUNC
)
5293 if (h
->plt
.offset
== (bfd_vma
) -1)
5295 /* STT_GNU_IFUNC is referenced without PLT. */
5296 if (htab
->elf
.splt
== NULL
)
5298 /* use .rel[a].iplt section to store .got relocations
5299 in static executable. */
5300 relgot
= htab
->elf
.irelplt
;
5302 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5304 info
->callbacks
->minfo (_("Local IFUNC function `%s' in %B\n"),
5306 h
->root
.root
.string
,
5307 h
->root
.u
.def
.section
->owner
);
5309 rela
.r_info
= htab
->r_info (0,
5310 R_X86_64_IRELATIVE
);
5311 rela
.r_addend
= (h
->root
.u
.def
.value
5312 + h
->root
.u
.def
.section
->output_section
->vma
5313 + h
->root
.u
.def
.section
->output_offset
);
5318 else if (bfd_link_pic (info
))
5320 /* Generate R_X86_64_GLOB_DAT. */
5328 if (!h
->pointer_equality_needed
)
5331 /* For non-shared object, we can't use .got.plt, which
5332 contains the real function addres if we need pointer
5333 equality. We load the GOT entry with the PLT entry. */
5334 if (htab
->plt_second
!= NULL
)
5336 plt
= htab
->plt_second
;
5337 plt_offset
= eh
->plt_second
.offset
;
5341 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5342 plt_offset
= h
->plt
.offset
;
5344 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5345 + plt
->output_offset
5347 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5351 else if (bfd_link_pic (info
)
5352 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5354 if (!h
->def_regular
)
5356 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5357 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5358 rela
.r_addend
= (h
->root
.u
.def
.value
5359 + h
->root
.u
.def
.section
->output_section
->vma
5360 + h
->root
.u
.def
.section
->output_offset
);
5364 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5366 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5367 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5368 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
5372 elf_append_rela (output_bfd
, relgot
, &rela
);
5377 Elf_Internal_Rela rela
;
5380 /* This symbol needs a copy reloc. Set it up. */
5382 if (h
->dynindx
== -1
5383 || (h
->root
.type
!= bfd_link_hash_defined
5384 && h
->root
.type
!= bfd_link_hash_defweak
)
5385 || htab
->elf
.srelbss
== NULL
5386 || htab
->elf
.sreldynrelro
== NULL
)
5389 rela
.r_offset
= (h
->root
.u
.def
.value
5390 + h
->root
.u
.def
.section
->output_section
->vma
5391 + h
->root
.u
.def
.section
->output_offset
);
5392 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
5394 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
5395 s
= htab
->elf
.sreldynrelro
;
5397 s
= htab
->elf
.srelbss
;
5398 elf_append_rela (output_bfd
, s
, &rela
);
5404 /* Finish up local dynamic symbol handling. We set the contents of
5405 various dynamic sections here. */
5408 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
5410 struct elf_link_hash_entry
*h
5411 = (struct elf_link_hash_entry
*) *slot
;
5412 struct bfd_link_info
*info
5413 = (struct bfd_link_info
*) inf
;
5415 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
5419 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
5420 here since undefined weak symbol may not be dynamic and may not be
5421 called for elf_x86_64_finish_dynamic_symbol. */
5424 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
5427 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
5428 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5430 if (h
->root
.type
!= bfd_link_hash_undefweak
5431 || h
->dynindx
!= -1)
5434 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
5438 /* Used to decide how to sort relocs in an optimal manner for the
5439 dynamic linker, before writing them out. */
5441 static enum elf_reloc_type_class
5442 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
5443 const asection
*rel_sec ATTRIBUTE_UNUSED
,
5444 const Elf_Internal_Rela
*rela
)
5446 bfd
*abfd
= info
->output_bfd
;
5447 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
5448 struct elf_x86_link_hash_table
*htab
5449 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
5451 if (htab
->elf
.dynsym
!= NULL
5452 && htab
->elf
.dynsym
->contents
!= NULL
)
5454 /* Check relocation against STT_GNU_IFUNC symbol if there are
5456 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
5457 if (r_symndx
!= STN_UNDEF
)
5459 Elf_Internal_Sym sym
;
5460 if (!bed
->s
->swap_symbol_in (abfd
,
5461 (htab
->elf
.dynsym
->contents
5462 + r_symndx
* bed
->s
->sizeof_sym
),
5466 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
5467 return reloc_class_ifunc
;
5471 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5473 case R_X86_64_IRELATIVE
:
5474 return reloc_class_ifunc
;
5475 case R_X86_64_RELATIVE
:
5476 case R_X86_64_RELATIVE64
:
5477 return reloc_class_relative
;
5478 case R_X86_64_JUMP_SLOT
:
5479 return reloc_class_plt
;
5481 return reloc_class_copy
;
5483 return reloc_class_normal
;
5487 /* Finish up the dynamic sections. */
5490 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
5491 struct bfd_link_info
*info
)
5493 struct elf_x86_link_hash_table
*htab
;
5497 htab
= elf_x86_hash_table (info
, X86_64_ELF_DATA
);
5501 dynobj
= htab
->elf
.dynobj
;
5502 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
5504 if (htab
->elf
.dynamic_sections_created
)
5506 bfd_byte
*dyncon
, *dynconend
;
5507 const struct elf_backend_data
*bed
;
5508 bfd_size_type sizeof_dyn
;
5510 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
5513 bed
= get_elf_backend_data (dynobj
);
5514 sizeof_dyn
= bed
->s
->sizeof_dyn
;
5515 dyncon
= sdyn
->contents
;
5516 dynconend
= sdyn
->contents
+ sdyn
->size
;
5517 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
5519 Elf_Internal_Dyn dyn
;
5522 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
5530 s
= htab
->elf
.sgotplt
;
5531 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5535 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
5539 s
= htab
->elf
.srelplt
->output_section
;
5540 dyn
.d_un
.d_val
= s
->size
;
5543 case DT_TLSDESC_PLT
:
5545 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
5546 + htab
->tlsdesc_plt
;
5549 case DT_TLSDESC_GOT
:
5551 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
5552 + htab
->tlsdesc_got
;
5556 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
5559 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
5561 elf_section_data (htab
->elf
.splt
->output_section
)
5562 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
5564 if (htab
->plt
.has_plt0
)
5566 /* Fill in the special first entry in the procedure linkage
5568 memcpy (htab
->elf
.splt
->contents
,
5569 htab
->lazy_plt
->plt0_entry
,
5570 htab
->lazy_plt
->plt0_entry_size
);
5571 /* Add offset for pushq GOT+8(%rip), since the instruction
5572 uses 6 bytes subtract this value. */
5573 bfd_put_32 (output_bfd
,
5574 (htab
->elf
.sgotplt
->output_section
->vma
5575 + htab
->elf
.sgotplt
->output_offset
5577 - htab
->elf
.splt
->output_section
->vma
5578 - htab
->elf
.splt
->output_offset
5580 (htab
->elf
.splt
->contents
5581 + htab
->lazy_plt
->plt0_got1_offset
));
5582 /* Add offset for the PC-relative instruction accessing
5583 GOT+16, subtracting the offset to the end of that
5585 bfd_put_32 (output_bfd
,
5586 (htab
->elf
.sgotplt
->output_section
->vma
5587 + htab
->elf
.sgotplt
->output_offset
5589 - htab
->elf
.splt
->output_section
->vma
5590 - htab
->elf
.splt
->output_offset
5591 - htab
->lazy_plt
->plt0_got2_insn_end
),
5592 (htab
->elf
.splt
->contents
5593 + htab
->lazy_plt
->plt0_got2_offset
));
5595 if (htab
->tlsdesc_plt
)
5597 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5598 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
5600 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
5601 htab
->lazy_plt
->plt0_entry
,
5602 htab
->lazy_plt
->plt0_entry_size
);
5604 /* Add offset for pushq GOT+8(%rip), since the
5605 instruction uses 6 bytes subtract this value. */
5606 bfd_put_32 (output_bfd
,
5607 (htab
->elf
.sgotplt
->output_section
->vma
5608 + htab
->elf
.sgotplt
->output_offset
5610 - htab
->elf
.splt
->output_section
->vma
5611 - htab
->elf
.splt
->output_offset
5614 (htab
->elf
.splt
->contents
5616 + htab
->lazy_plt
->plt0_got1_offset
));
5617 /* Add offset for the PC-relative instruction accessing
5618 GOT+TDG, where TDG stands for htab->tlsdesc_got,
5619 subtracting the offset to the end of that
5621 bfd_put_32 (output_bfd
,
5622 (htab
->elf
.sgot
->output_section
->vma
5623 + htab
->elf
.sgot
->output_offset
5625 - htab
->elf
.splt
->output_section
->vma
5626 - htab
->elf
.splt
->output_offset
5628 - htab
->lazy_plt
->plt0_got2_insn_end
),
5629 (htab
->elf
.splt
->contents
5631 + htab
->lazy_plt
->plt0_got2_offset
));
5636 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
5637 elf_section_data (htab
->plt_got
->output_section
)
5638 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5640 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
5641 elf_section_data (htab
->plt_second
->output_section
)
5642 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
5645 /* GOT is always created in setup_gnu_properties. But it may not be
5647 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
5649 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
5652 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
5656 /* Set the first entry in the global offset table to the address of
5657 the dynamic section. */
5659 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
5661 bfd_put_64 (output_bfd
,
5662 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5663 htab
->elf
.sgotplt
->contents
);
5664 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
5665 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5666 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
5667 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5668 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
5670 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
5674 /* Adjust .eh_frame for .plt section. */
5675 if (htab
->plt_eh_frame
!= NULL
5676 && htab
->plt_eh_frame
->contents
!= NULL
)
5678 if (htab
->elf
.splt
!= NULL
5679 && htab
->elf
.splt
->size
!= 0
5680 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
5681 && htab
->elf
.splt
->output_section
!= NULL
5682 && htab
->plt_eh_frame
->output_section
!= NULL
)
5684 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
5685 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
5686 + htab
->plt_eh_frame
->output_offset
5687 + PLT_FDE_START_OFFSET
;
5688 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5689 htab
->plt_eh_frame
->contents
5690 + PLT_FDE_START_OFFSET
);
5692 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5694 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5696 htab
->plt_eh_frame
->contents
))
5701 /* Adjust .eh_frame for .plt.got section. */
5702 if (htab
->plt_got_eh_frame
!= NULL
5703 && htab
->plt_got_eh_frame
->contents
!= NULL
)
5705 if (htab
->plt_got
!= NULL
5706 && htab
->plt_got
->size
!= 0
5707 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
5708 && htab
->plt_got
->output_section
!= NULL
5709 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
5711 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
5712 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
5713 + htab
->plt_got_eh_frame
->output_offset
5714 + PLT_FDE_START_OFFSET
;
5715 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5716 htab
->plt_got_eh_frame
->contents
5717 + PLT_FDE_START_OFFSET
);
5719 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
5721 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5722 htab
->plt_got_eh_frame
,
5723 htab
->plt_got_eh_frame
->contents
))
5728 /* Adjust .eh_frame for the second PLT section. */
5729 if (htab
->plt_second_eh_frame
!= NULL
5730 && htab
->plt_second_eh_frame
->contents
!= NULL
)
5732 if (htab
->plt_second
!= NULL
5733 && htab
->plt_second
->size
!= 0
5734 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
5735 && htab
->plt_second
->output_section
!= NULL
5736 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
5738 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
5739 bfd_vma eh_frame_start
5740 = (htab
->plt_second_eh_frame
->output_section
->vma
5741 + htab
->plt_second_eh_frame
->output_offset
5742 + PLT_FDE_START_OFFSET
);
5743 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
5744 htab
->plt_second_eh_frame
->contents
5745 + PLT_FDE_START_OFFSET
);
5747 if (htab
->plt_second_eh_frame
->sec_info_type
5748 == SEC_INFO_TYPE_EH_FRAME
)
5750 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
5751 htab
->plt_second_eh_frame
,
5752 htab
->plt_second_eh_frame
->contents
))
5757 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
5758 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
5761 /* Fill PLT entries for undefined weak symbols in PIE. */
5762 if (bfd_link_pie (info
))
5763 bfd_hash_traverse (&info
->hash
->table
,
5764 elf_x86_64_pie_finish_undefweak_symbol
,
5770 /* Fill PLT/GOT entries and allocate dynamic relocations for local
5771 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
5772 It has to be done before elf_link_sort_relocs is called so that
5773 dynamic relocations are properly sorted. */
5776 elf_x86_64_output_arch_local_syms
5777 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5778 struct bfd_link_info
*info
,
5779 void *flaginfo ATTRIBUTE_UNUSED
,
5780 int (*func
) (void *, const char *,
5783 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
5785 struct elf_x86_link_hash_table
*htab
5786 = elf_x86_hash_table (info
, X86_64_ELF_DATA
);
5790 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
5791 htab_traverse (htab
->loc_hash_table
,
5792 elf_x86_64_finish_local_dynamic_symbol
,
5798 /* Forward declaration. */
5799 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
;
5801 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
5802 dynamic relocations. */
5805 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
5806 long symcount ATTRIBUTE_UNUSED
,
5807 asymbol
**syms ATTRIBUTE_UNUSED
,
5814 bfd_byte
*plt_contents
;
5816 const struct elf_x86_lazy_plt_layout
*lazy_plt
;
5817 const struct elf_x86_non_lazy_plt_layout
*non_lazy_plt
;
5818 const struct elf_x86_lazy_plt_layout
*lazy_bnd_plt
;
5819 const struct elf_x86_non_lazy_plt_layout
*non_lazy_bnd_plt
;
5820 const struct elf_x86_lazy_plt_layout
*lazy_ibt_plt
;
5821 const struct elf_x86_non_lazy_plt_layout
*non_lazy_ibt_plt
;
5823 enum elf_x86_plt_type plt_type
;
5824 struct elf_x86_plt plts
[] =
5826 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
5827 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
5828 { ".plt.sec", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
5829 { ".plt.bnd", NULL
, NULL
, plt_second
, 0, 0, 0, 0 },
5830 { NULL
, NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 }
5835 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
5838 if (dynsymcount
<= 0)
5841 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
5845 if (get_elf_x86_64_backend_data (abfd
)->os
== is_normal
)
5847 lazy_plt
= &elf_x86_64_lazy_plt
;
5848 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
5849 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
5850 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
5851 if (ABI_64_P (abfd
))
5853 lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
5854 non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
5858 lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
5859 non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
5864 lazy_plt
= &elf_x86_64_nacl_plt
;
5865 non_lazy_plt
= NULL
;
5866 lazy_bnd_plt
= NULL
;
5867 non_lazy_bnd_plt
= NULL
;
5868 lazy_ibt_plt
= NULL
;
5869 non_lazy_ibt_plt
= NULL
;
5873 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
5875 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
5876 if (plt
== NULL
|| plt
->size
== 0)
5879 /* Get the PLT section contents. */
5880 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
5881 if (plt_contents
== NULL
)
5883 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
5884 plt_contents
, 0, plt
->size
))
5886 free (plt_contents
);
5890 /* Check what kind of PLT it is. */
5891 plt_type
= plt_unknown
;
5892 if (plts
[j
].type
== plt_unknown
5893 && (plt
->size
>= (lazy_plt
->plt_entry_size
5894 + lazy_plt
->plt_entry_size
)))
5896 /* Match lazy PLT first. Need to check the first two
5898 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
5899 lazy_plt
->plt0_got1_offset
) == 0)
5900 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
5902 plt_type
= plt_lazy
;
5903 else if (lazy_bnd_plt
!= NULL
5904 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
5905 lazy_bnd_plt
->plt0_got1_offset
) == 0)
5906 && (memcmp (plt_contents
+ 6,
5907 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
5909 plt_type
= plt_lazy
| plt_second
;
5910 /* The fist entry in the lazy IBT PLT is the same as the
5912 if ((memcmp (plt_contents
+ lazy_ibt_plt
->plt_entry_size
,
5913 lazy_ibt_plt
->plt_entry
,
5914 lazy_ibt_plt
->plt_got_offset
) == 0))
5915 lazy_plt
= lazy_ibt_plt
;
5917 lazy_plt
= lazy_bnd_plt
;
5921 if (non_lazy_plt
!= NULL
5922 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
)
5923 && plt
->size
>= non_lazy_plt
->plt_entry_size
)
5925 /* Match non-lazy PLT. */
5926 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
5927 non_lazy_plt
->plt_got_offset
) == 0)
5928 plt_type
= plt_non_lazy
;
5931 if (plt_type
== plt_unknown
|| plt_type
== plt_second
)
5933 if (non_lazy_bnd_plt
!= NULL
5934 && plt
->size
>= non_lazy_bnd_plt
->plt_entry_size
5935 && (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
5936 non_lazy_bnd_plt
->plt_got_offset
) == 0))
5938 /* Match BND PLT. */
5939 plt_type
= plt_second
;
5940 non_lazy_plt
= non_lazy_bnd_plt
;
5942 else if (non_lazy_ibt_plt
!= NULL
5943 && plt
->size
>= non_lazy_ibt_plt
->plt_entry_size
5944 && (memcmp (plt_contents
,
5945 non_lazy_ibt_plt
->plt_entry
,
5946 non_lazy_ibt_plt
->plt_got_offset
) == 0))
5948 /* Match IBT PLT. */
5949 plt_type
= plt_second
;
5950 non_lazy_plt
= non_lazy_ibt_plt
;
5954 if (plt_type
== plt_unknown
)
5956 free (plt_contents
);
5961 plts
[j
].type
= plt_type
;
5963 if ((plt_type
& plt_lazy
))
5965 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
5966 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
5967 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
5968 /* Skip PLT0 in lazy PLT. */
5973 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
5974 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
5975 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
5979 /* Skip lazy PLT when the second PLT is used. */
5980 if (plt_type
== (plt_lazy
| plt_second
))
5984 n
= plt
->size
/ plts
[j
].plt_entry_size
;
5989 plts
[j
].contents
= plt_contents
;
5992 return _bfd_x86_elf_get_synthetic_symtab (abfd
, count
, relsize
,
5993 (bfd_vma
) 0, plts
, dynsyms
,
5997 /* Handle an x86-64 specific section when reading an object file. This
5998 is called when elfcode.h finds a section with an unknown type. */
6001 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6002 const char *name
, int shindex
)
6004 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6007 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6013 /* Hook called by the linker routine which adds symbols from an object
6014 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6018 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6019 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6020 Elf_Internal_Sym
*sym
,
6021 const char **namep ATTRIBUTE_UNUSED
,
6022 flagword
*flagsp ATTRIBUTE_UNUSED
,
6028 switch (sym
->st_shndx
)
6030 case SHN_X86_64_LCOMMON
:
6031 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6034 lcomm
= bfd_make_section_with_flags (abfd
,
6038 | SEC_LINKER_CREATED
));
6041 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6044 *valp
= sym
->st_size
;
6052 /* Given a BFD section, try to locate the corresponding ELF section
6056 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6057 asection
*sec
, int *index_return
)
6059 if (sec
== &_bfd_elf_large_com_section
)
6061 *index_return
= SHN_X86_64_LCOMMON
;
6067 /* Process a symbol. */
6070 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6073 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6075 switch (elfsym
->internal_elf_sym
.st_shndx
)
6077 case SHN_X86_64_LCOMMON
:
6078 asym
->section
= &_bfd_elf_large_com_section
;
6079 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6080 /* Common symbol doesn't set BSF_GLOBAL. */
6081 asym
->flags
&= ~BSF_GLOBAL
;
6087 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6089 return (sym
->st_shndx
== SHN_COMMON
6090 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6094 elf_x86_64_common_section_index (asection
*sec
)
6096 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6099 return SHN_X86_64_LCOMMON
;
6103 elf_x86_64_common_section (asection
*sec
)
6105 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6106 return bfd_com_section_ptr
;
6108 return &_bfd_elf_large_com_section
;
6112 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6113 const Elf_Internal_Sym
*sym
,
6118 const asection
*oldsec
)
6120 /* A normal common symbol and a large common symbol result in a
6121 normal common symbol. We turn the large common symbol into a
6124 && h
->root
.type
== bfd_link_hash_common
6126 && bfd_is_com_section (*psec
)
6129 if (sym
->st_shndx
== SHN_COMMON
6130 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6132 h
->root
.u
.c
.p
->section
6133 = bfd_make_section_old_way (oldbfd
, "COMMON");
6134 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6136 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6137 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6138 *psec
= bfd_com_section_ptr
;
6145 elf_x86_64_additional_program_headers (bfd
*abfd
,
6146 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6151 /* Check to see if we need a large readonly segment. */
6152 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6153 if (s
&& (s
->flags
& SEC_LOAD
))
6156 /* Check to see if we need a large data segment. Since .lbss sections
6157 is placed right after the .bss section, there should be no need for
6158 a large data segment just because of .lbss. */
6159 s
= bfd_get_section_by_name (abfd
, ".ldata");
6160 if (s
&& (s
->flags
& SEC_LOAD
))
6166 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6169 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6170 const bfd_target
*output
)
6172 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6173 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6174 && _bfd_elf_relocs_compatible (input
, output
));
6177 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
6178 with GNU properties if found. Otherwise, return NULL. */
6181 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
6183 struct elf_x86_plt_layout_table plt_layout
;
6185 plt_layout
.is_vxworks
= FALSE
;
6186 if (get_elf_x86_64_backend_data (info
->output_bfd
)->os
== is_normal
)
6190 plt_layout
.lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
6191 plt_layout
.non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
6195 plt_layout
.lazy_plt
= &elf_x86_64_lazy_plt
;
6196 plt_layout
.non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
6199 if (ABI_64_P (info
->output_bfd
))
6201 plt_layout
.lazy_ibt_plt
= &elf_x86_64_lazy_ibt_plt
;
6202 plt_layout
.non_lazy_ibt_plt
= &elf_x86_64_non_lazy_ibt_plt
;
6206 plt_layout
.lazy_ibt_plt
= &elf_x32_lazy_ibt_plt
;
6207 plt_layout
.non_lazy_ibt_plt
= &elf_x32_non_lazy_ibt_plt
;
6209 plt_layout
.normal_target
= TRUE
;
6213 plt_layout
.lazy_plt
= &elf_x86_64_nacl_plt
;
6214 plt_layout
.non_lazy_plt
= NULL
;
6215 plt_layout
.lazy_ibt_plt
= NULL
;
6216 plt_layout
.non_lazy_ibt_plt
= NULL
;
6217 plt_layout
.normal_target
= FALSE
;
6220 return _bfd_x86_elf_link_setup_gnu_properties (info
, &plt_layout
);
6223 static const struct bfd_elf_special_section
6224 elf_x86_64_special_sections
[]=
6226 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6227 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6228 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
6229 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6230 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
6231 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
6232 { NULL
, 0, 0, 0, 0 }
6235 #define TARGET_LITTLE_SYM x86_64_elf64_vec
6236 #define TARGET_LITTLE_NAME "elf64-x86-64"
6237 #define ELF_ARCH bfd_arch_i386
6238 #define ELF_TARGET_ID X86_64_ELF_DATA
6239 #define ELF_MACHINE_CODE EM_X86_64
6240 #define ELF_MAXPAGESIZE 0x200000
6241 #define ELF_MINPAGESIZE 0x1000
6242 #define ELF_COMMONPAGESIZE 0x1000
6244 #define elf_backend_can_gc_sections 1
6245 #define elf_backend_can_refcount 1
6246 #define elf_backend_want_got_plt 1
6247 #define elf_backend_plt_readonly 1
6248 #define elf_backend_want_plt_sym 0
6249 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
6250 #define elf_backend_rela_normal 1
6251 #define elf_backend_plt_alignment 4
6252 #define elf_backend_extern_protected_data 1
6253 #define elf_backend_caches_rawsize 1
6254 #define elf_backend_dtrel_excludes_plt 1
6255 #define elf_backend_want_dynrelro 1
6257 #define elf_info_to_howto elf_x86_64_info_to_howto
6259 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
6260 #define bfd_elf64_bfd_reloc_name_lookup \
6261 elf_x86_64_reloc_name_lookup
6263 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
6264 #define elf_backend_check_relocs elf_x86_64_check_relocs
6265 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
6266 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
6267 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
6268 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
6269 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
6270 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
6271 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
6273 #define elf_backend_write_core_note elf_x86_64_write_core_note
6275 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
6276 #define elf_backend_relocate_section elf_x86_64_relocate_section
6277 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
6278 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
6279 #define elf_backend_object_p elf64_x86_64_elf_object_p
6280 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
6282 #define elf_backend_section_from_shdr \
6283 elf_x86_64_section_from_shdr
6285 #define elf_backend_section_from_bfd_section \
6286 elf_x86_64_elf_section_from_bfd_section
6287 #define elf_backend_add_symbol_hook \
6288 elf_x86_64_add_symbol_hook
6289 #define elf_backend_symbol_processing \
6290 elf_x86_64_symbol_processing
6291 #define elf_backend_common_section_index \
6292 elf_x86_64_common_section_index
6293 #define elf_backend_common_section \
6294 elf_x86_64_common_section
6295 #define elf_backend_common_definition \
6296 elf_x86_64_common_definition
6297 #define elf_backend_merge_symbol \
6298 elf_x86_64_merge_symbol
6299 #define elf_backend_special_sections \
6300 elf_x86_64_special_sections
6301 #define elf_backend_additional_program_headers \
6302 elf_x86_64_additional_program_headers
6303 #define elf_backend_setup_gnu_properties \
6304 elf_x86_64_link_setup_gnu_properties
6306 #include "elf64-target.h"
6308 /* CloudABI support. */
6310 #undef TARGET_LITTLE_SYM
6311 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
6312 #undef TARGET_LITTLE_NAME
6313 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
6316 #define ELF_OSABI ELFOSABI_CLOUDABI
6319 #define elf64_bed elf64_x86_64_cloudabi_bed
6321 #include "elf64-target.h"
6323 /* FreeBSD support. */
6325 #undef TARGET_LITTLE_SYM
6326 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
6327 #undef TARGET_LITTLE_NAME
6328 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
6331 #define ELF_OSABI ELFOSABI_FREEBSD
6334 #define elf64_bed elf64_x86_64_fbsd_bed
6336 #include "elf64-target.h"
6338 /* Solaris 2 support. */
6340 #undef TARGET_LITTLE_SYM
6341 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
6342 #undef TARGET_LITTLE_NAME
6343 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
6345 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
6346 objects won't be recognized. */
6350 #define elf64_bed elf64_x86_64_sol2_bed
6352 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
6354 #undef elf_backend_static_tls_alignment
6355 #define elf_backend_static_tls_alignment 16
6357 /* The Solaris 2 ABI requires a plt symbol on all platforms.
6359 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
6361 #undef elf_backend_want_plt_sym
6362 #define elf_backend_want_plt_sym 1
6364 #undef elf_backend_strtab_flags
6365 #define elf_backend_strtab_flags SHF_STRINGS
6368 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
6369 bfd
*obfd ATTRIBUTE_UNUSED
,
6370 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
6371 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
6373 /* PR 19938: FIXME: Need to add code for setting the sh_info
6374 and sh_link fields of Solaris specific section types. */
6378 #undef elf_backend_copy_special_section_fields
6379 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
6381 #include "elf64-target.h"
6383 /* Native Client support. */
6386 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
6388 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
6389 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
6393 #undef TARGET_LITTLE_SYM
6394 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
6395 #undef TARGET_LITTLE_NAME
6396 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
6398 #define elf64_bed elf64_x86_64_nacl_bed
6400 #undef ELF_MAXPAGESIZE
6401 #undef ELF_MINPAGESIZE
6402 #undef ELF_COMMONPAGESIZE
6403 #define ELF_MAXPAGESIZE 0x10000
6404 #define ELF_MINPAGESIZE 0x10000
6405 #define ELF_COMMONPAGESIZE 0x10000
6407 /* Restore defaults. */
6409 #undef elf_backend_static_tls_alignment
6410 #undef elf_backend_want_plt_sym
6411 #define elf_backend_want_plt_sym 0
6412 #undef elf_backend_strtab_flags
6413 #undef elf_backend_copy_special_section_fields
6415 /* NaCl uses substantially different PLT entries for the same effects. */
6417 #undef elf_backend_plt_alignment
6418 #define elf_backend_plt_alignment 5
6419 #define NACL_PLT_ENTRY_SIZE 64
6420 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
6422 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
6424 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
6425 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
6426 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6427 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6428 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6430 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
6431 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
6433 /* 32 bytes of nop to pad out to the standard size. */
6434 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6435 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6436 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6437 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6438 0x66, /* excess data16 prefix */
6442 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
6444 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
6445 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
6446 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
6447 0x41, 0xff, 0xe3, /* jmpq *%r11 */
6449 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
6450 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6451 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6453 /* Lazy GOT entries point here (32-byte aligned). */
6454 0x68, /* pushq immediate */
6455 0, 0, 0, 0, /* replaced with index into relocation table. */
6456 0xe9, /* jmp relative */
6457 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
6459 /* 22 bytes of nop to pad out to the standard size. */
6460 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
6461 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
6462 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
6465 /* .eh_frame covering the .plt section. */
6467 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
6469 #if (PLT_CIE_LENGTH != 20 \
6470 || PLT_FDE_LENGTH != 36 \
6471 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
6472 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
6473 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
6475 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
6476 0, 0, 0, 0, /* CIE ID */
6477 1, /* CIE version */
6478 'z', 'R', 0, /* Augmentation string */
6479 1, /* Code alignment factor */
6480 0x78, /* Data alignment factor */
6481 16, /* Return address column */
6482 1, /* Augmentation size */
6483 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
6484 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
6485 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
6486 DW_CFA_nop
, DW_CFA_nop
,
6488 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
6489 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
6490 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
6491 0, 0, 0, 0, /* .plt size goes here */
6492 0, /* Augmentation size */
6493 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
6494 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
6495 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
6496 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
6497 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
6498 13, /* Block length */
6499 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
6500 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
6501 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
6502 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
6503 DW_CFA_nop
, DW_CFA_nop
6506 static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt
=
6508 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
6509 NACL_PLT_ENTRY_SIZE
, /* plt0_entry_size */
6510 elf_x86_64_nacl_plt_entry
, /* plt_entry */
6511 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
6512 2, /* plt0_got1_offset */
6513 9, /* plt0_got2_offset */
6514 13, /* plt0_got2_insn_end */
6515 3, /* plt_got_offset */
6516 33, /* plt_reloc_offset */
6517 38, /* plt_plt_offset */
6518 7, /* plt_got_insn_size */
6519 42, /* plt_plt_insn_end */
6520 32, /* plt_lazy_offset */
6521 elf_x86_64_nacl_plt0_entry
, /* pic_plt0_entry */
6522 elf_x86_64_nacl_plt_entry
, /* pic_plt_entry */
6523 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
6524 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
6527 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
6532 #undef elf_backend_arch_data
6533 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
6535 #undef elf_backend_object_p
6536 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
6537 #undef elf_backend_modify_segment_map
6538 #define elf_backend_modify_segment_map nacl_modify_segment_map
6539 #undef elf_backend_modify_program_headers
6540 #define elf_backend_modify_program_headers nacl_modify_program_headers
6541 #undef elf_backend_final_write_processing
6542 #define elf_backend_final_write_processing nacl_final_write_processing
6544 #include "elf64-target.h"
6546 /* Native Client x32 support. */
6549 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
6551 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
6552 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
6556 #undef TARGET_LITTLE_SYM
6557 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
6558 #undef TARGET_LITTLE_NAME
6559 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
6561 #define elf32_bed elf32_x86_64_nacl_bed
6563 #define bfd_elf32_bfd_reloc_type_lookup \
6564 elf_x86_64_reloc_type_lookup
6565 #define bfd_elf32_bfd_reloc_name_lookup \
6566 elf_x86_64_reloc_name_lookup
6567 #define bfd_elf32_get_synthetic_symtab \
6568 elf_x86_64_get_synthetic_symtab
6570 #undef elf_backend_object_p
6571 #define elf_backend_object_p \
6572 elf32_x86_64_nacl_elf_object_p
6574 #undef elf_backend_bfd_from_remote_memory
6575 #define elf_backend_bfd_from_remote_memory \
6576 _bfd_elf32_bfd_from_remote_memory
6578 #undef elf_backend_size_info
6579 #define elf_backend_size_info \
6580 _bfd_elf32_size_info
6582 #include "elf32-target.h"
6584 /* Restore defaults. */
6585 #undef elf_backend_object_p
6586 #define elf_backend_object_p elf64_x86_64_elf_object_p
6587 #undef elf_backend_bfd_from_remote_memory
6588 #undef elf_backend_size_info
6589 #undef elf_backend_modify_segment_map
6590 #undef elf_backend_modify_program_headers
6591 #undef elf_backend_final_write_processing
6593 /* Intel L1OM support. */
6596 elf64_l1om_elf_object_p (bfd
*abfd
)
6598 /* Set the right machine number for an L1OM elf64 file. */
6599 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
6603 #undef TARGET_LITTLE_SYM
6604 #define TARGET_LITTLE_SYM l1om_elf64_vec
6605 #undef TARGET_LITTLE_NAME
6606 #define TARGET_LITTLE_NAME "elf64-l1om"
6608 #define ELF_ARCH bfd_arch_l1om
6610 #undef ELF_MACHINE_CODE
6611 #define ELF_MACHINE_CODE EM_L1OM
6616 #define elf64_bed elf64_l1om_bed
6618 #undef elf_backend_object_p
6619 #define elf_backend_object_p elf64_l1om_elf_object_p
6621 /* Restore defaults. */
6622 #undef ELF_MAXPAGESIZE
6623 #undef ELF_MINPAGESIZE
6624 #undef ELF_COMMONPAGESIZE
6625 #define ELF_MAXPAGESIZE 0x200000
6626 #define ELF_MINPAGESIZE 0x1000
6627 #define ELF_COMMONPAGESIZE 0x1000
6628 #undef elf_backend_plt_alignment
6629 #define elf_backend_plt_alignment 4
6630 #undef elf_backend_arch_data
6631 #define elf_backend_arch_data &elf_x86_64_arch_bed
6633 #include "elf64-target.h"
6635 /* FreeBSD L1OM support. */
6637 #undef TARGET_LITTLE_SYM
6638 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
6639 #undef TARGET_LITTLE_NAME
6640 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
6643 #define ELF_OSABI ELFOSABI_FREEBSD
6646 #define elf64_bed elf64_l1om_fbsd_bed
6648 #include "elf64-target.h"
6650 /* Intel K1OM support. */
6653 elf64_k1om_elf_object_p (bfd
*abfd
)
6655 /* Set the right machine number for an K1OM elf64 file. */
6656 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
6660 #undef TARGET_LITTLE_SYM
6661 #define TARGET_LITTLE_SYM k1om_elf64_vec
6662 #undef TARGET_LITTLE_NAME
6663 #define TARGET_LITTLE_NAME "elf64-k1om"
6665 #define ELF_ARCH bfd_arch_k1om
6667 #undef ELF_MACHINE_CODE
6668 #define ELF_MACHINE_CODE EM_K1OM
6673 #define elf64_bed elf64_k1om_bed
6675 #undef elf_backend_object_p
6676 #define elf_backend_object_p elf64_k1om_elf_object_p
6678 #undef elf_backend_static_tls_alignment
6680 #undef elf_backend_want_plt_sym
6681 #define elf_backend_want_plt_sym 0
6683 #include "elf64-target.h"
6685 /* FreeBSD K1OM support. */
6687 #undef TARGET_LITTLE_SYM
6688 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
6689 #undef TARGET_LITTLE_NAME
6690 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
6693 #define ELF_OSABI ELFOSABI_FREEBSD
6696 #define elf64_bed elf64_k1om_fbsd_bed
6698 #include "elf64-target.h"
6700 /* 32bit x86-64 support. */
6702 #undef TARGET_LITTLE_SYM
6703 #define TARGET_LITTLE_SYM x86_64_elf32_vec
6704 #undef TARGET_LITTLE_NAME
6705 #define TARGET_LITTLE_NAME "elf32-x86-64"
6709 #define ELF_ARCH bfd_arch_i386
6711 #undef ELF_MACHINE_CODE
6712 #define ELF_MACHINE_CODE EM_X86_64
6716 #undef elf_backend_object_p
6717 #define elf_backend_object_p \
6718 elf32_x86_64_elf_object_p
6720 #undef elf_backend_bfd_from_remote_memory
6721 #define elf_backend_bfd_from_remote_memory \
6722 _bfd_elf32_bfd_from_remote_memory
6724 #undef elf_backend_size_info
6725 #define elf_backend_size_info \
6726 _bfd_elf32_size_info
6728 #include "elf32-target.h"