1 /* X86-64 specific support for ELF
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
32 #include "libiberty.h"
34 #include "opcode/i386.h"
35 #include "elf/x86-64.h"
42 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
43 #define MINUS_ONE (~ (bfd_vma) 0)
45 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
46 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
47 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
48 since they are the same. */
50 #define ABI_64_P(abfd) \
51 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
53 /* The relocation "howto" table. Order of fields:
54 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
55 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
56 static reloc_howto_type x86_64_elf_howto_table
[] =
58 HOWTO(R_X86_64_NONE
, 0, 3, 0, FALSE
, 0, complain_overflow_dont
,
59 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
61 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
64 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
65 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
67 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
71 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
74 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
79 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
82 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
85 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
86 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
88 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
89 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
91 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
92 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
94 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
96 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
98 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
100 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
102 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
105 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
108 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
111 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
112 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
114 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
115 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
117 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
118 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
120 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
121 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
123 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
124 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
126 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
129 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
131 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
132 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
133 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
134 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
135 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
136 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
138 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
139 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
141 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
142 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
143 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
144 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
145 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
147 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
148 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
150 HOWTO(R_X86_64_SIZE32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
151 bfd_elf_generic_reloc
, "R_X86_64_SIZE32", FALSE
, 0xffffffff, 0xffffffff,
153 HOWTO(R_X86_64_SIZE64
, 0, 4, 64, FALSE
, 0, complain_overflow_unsigned
,
154 bfd_elf_generic_reloc
, "R_X86_64_SIZE64", FALSE
, MINUS_ONE
, MINUS_ONE
,
156 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
157 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
158 "R_X86_64_GOTPC32_TLSDESC",
159 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
160 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
161 complain_overflow_dont
, bfd_elf_generic_reloc
,
162 "R_X86_64_TLSDESC_CALL",
164 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
165 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
167 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
168 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
169 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
171 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
172 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
174 HOWTO(R_X86_64_PC32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
175 bfd_elf_generic_reloc
, "R_X86_64_PC32_BND", FALSE
, 0xffffffff, 0xffffffff,
177 HOWTO(R_X86_64_PLT32_BND
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
178 bfd_elf_generic_reloc
, "R_X86_64_PLT32_BND", FALSE
, 0xffffffff, 0xffffffff,
180 HOWTO(R_X86_64_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
181 bfd_elf_generic_reloc
, "R_X86_64_GOTPCRELX", FALSE
, 0xffffffff,
183 HOWTO(R_X86_64_REX_GOTPCRELX
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
184 bfd_elf_generic_reloc
, "R_X86_64_REX_GOTPCRELX", FALSE
, 0xffffffff,
187 /* We have a gap in the reloc numbers here.
188 R_X86_64_standard counts the number up to this point, and
189 R_X86_64_vt_offset is the value to subtract from a reloc type of
190 R_X86_64_GNU_VT* to form an index into this table. */
191 #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1)
192 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
194 /* GNU extension to record C++ vtable hierarchy. */
195 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
196 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
198 /* GNU extension to record C++ vtable member usage. */
199 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
200 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
203 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
204 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
205 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
209 #define IS_X86_64_PCREL_TYPE(TYPE) \
210 ( ((TYPE) == R_X86_64_PC8) \
211 || ((TYPE) == R_X86_64_PC16) \
212 || ((TYPE) == R_X86_64_PC32) \
213 || ((TYPE) == R_X86_64_PC32_BND) \
214 || ((TYPE) == R_X86_64_PC64))
216 /* Map BFD relocs to the x86_64 elf relocs. */
219 bfd_reloc_code_real_type bfd_reloc_val
;
220 unsigned char elf_reloc_val
;
223 static const struct elf_reloc_map x86_64_reloc_map
[] =
225 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
226 { BFD_RELOC_64
, R_X86_64_64
, },
227 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
228 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
229 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
230 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
231 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
232 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
233 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
234 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
235 { BFD_RELOC_32
, R_X86_64_32
, },
236 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
237 { BFD_RELOC_16
, R_X86_64_16
, },
238 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
239 { BFD_RELOC_8
, R_X86_64_8
, },
240 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
241 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
242 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
243 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
244 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
245 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
246 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
247 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
248 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
249 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
250 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
251 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
252 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
253 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
254 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
255 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
256 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
257 { BFD_RELOC_SIZE32
, R_X86_64_SIZE32
, },
258 { BFD_RELOC_SIZE64
, R_X86_64_SIZE64
, },
259 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
260 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
261 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
262 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
263 { BFD_RELOC_X86_64_PC32_BND
, R_X86_64_PC32_BND
, },
264 { BFD_RELOC_X86_64_PLT32_BND
, R_X86_64_PLT32_BND
, },
265 { BFD_RELOC_X86_64_GOTPCRELX
, R_X86_64_GOTPCRELX
, },
266 { BFD_RELOC_X86_64_REX_GOTPCRELX
, R_X86_64_REX_GOTPCRELX
, },
267 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
268 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
271 static reloc_howto_type
*
272 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
276 if (r_type
== (unsigned int) R_X86_64_32
)
281 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
283 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
284 || r_type
>= (unsigned int) R_X86_64_max
)
286 if (r_type
>= (unsigned int) R_X86_64_standard
)
288 /* xgettext:c-format */
289 _bfd_error_handler (_("%B: invalid relocation type %d"),
291 r_type
= R_X86_64_NONE
;
296 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
297 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
298 return &x86_64_elf_howto_table
[i
];
301 /* Given a BFD reloc type, return a HOWTO structure. */
302 static reloc_howto_type
*
303 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
304 bfd_reloc_code_real_type code
)
308 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
311 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
312 return elf_x86_64_rtype_to_howto (abfd
,
313 x86_64_reloc_map
[i
].elf_reloc_val
);
318 static reloc_howto_type
*
319 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
324 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
326 /* Get x32 R_X86_64_32. */
327 reloc_howto_type
*reloc
328 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
329 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
333 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
334 if (x86_64_elf_howto_table
[i
].name
!= NULL
335 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
336 return &x86_64_elf_howto_table
[i
];
341 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
344 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
345 Elf_Internal_Rela
*dst
)
349 r_type
= ELF32_R_TYPE (dst
->r_info
);
350 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
351 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
354 /* Support for core dump NOTE sections. */
356 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
361 switch (note
->descsz
)
366 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
368 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
371 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
379 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
381 elf_tdata (abfd
)->core
->signal
382 = bfd_get_16 (abfd
, note
->descdata
+ 12);
385 elf_tdata (abfd
)->core
->lwpid
386 = bfd_get_32 (abfd
, note
->descdata
+ 32);
395 /* Make a ".reg/999" section. */
396 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
397 size
, note
->descpos
+ offset
);
401 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
403 switch (note
->descsz
)
408 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
409 elf_tdata (abfd
)->core
->pid
410 = bfd_get_32 (abfd
, note
->descdata
+ 12);
411 elf_tdata (abfd
)->core
->program
412 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
413 elf_tdata (abfd
)->core
->command
414 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
417 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
418 elf_tdata (abfd
)->core
->pid
419 = bfd_get_32 (abfd
, note
->descdata
+ 24);
420 elf_tdata (abfd
)->core
->program
421 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
422 elf_tdata (abfd
)->core
->command
423 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
426 /* Note that for some reason, a spurious space is tacked
427 onto the end of the args in some (at least one anyway)
428 implementations, so strip it off if it exists. */
431 char *command
= elf_tdata (abfd
)->core
->command
;
432 int n
= strlen (command
);
434 if (0 < n
&& command
[n
- 1] == ' ')
435 command
[n
- 1] = '\0';
443 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
446 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
448 const char *fname
, *psargs
;
459 va_start (ap
, note_type
);
460 fname
= va_arg (ap
, const char *);
461 psargs
= va_arg (ap
, const char *);
464 if (bed
->s
->elfclass
== ELFCLASS32
)
467 memset (&data
, 0, sizeof (data
));
468 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
469 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
470 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
471 &data
, sizeof (data
));
476 memset (&data
, 0, sizeof (data
));
477 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
478 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
479 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
480 &data
, sizeof (data
));
485 va_start (ap
, note_type
);
486 pid
= va_arg (ap
, long);
487 cursig
= va_arg (ap
, int);
488 gregs
= va_arg (ap
, const void *);
491 if (bed
->s
->elfclass
== ELFCLASS32
)
493 if (bed
->elf_machine_code
== EM_X86_64
)
495 prstatusx32_t prstat
;
496 memset (&prstat
, 0, sizeof (prstat
));
498 prstat
.pr_cursig
= cursig
;
499 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
500 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
501 &prstat
, sizeof (prstat
));
506 memset (&prstat
, 0, sizeof (prstat
));
508 prstat
.pr_cursig
= cursig
;
509 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
510 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
511 &prstat
, sizeof (prstat
));
517 memset (&prstat
, 0, sizeof (prstat
));
519 prstat
.pr_cursig
= cursig
;
520 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
521 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
522 &prstat
, sizeof (prstat
));
529 /* Functions for the x86-64 ELF linker. */
531 /* The name of the dynamic interpreter. This is put in the .interp
534 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
535 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
537 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
538 copying dynamic variables from a shared lib into an app's dynbss
539 section, and instead use a dynamic relocation to point into the
541 #define ELIMINATE_COPY_RELOCS 1
543 /* The size in bytes of an entry in the global offset table. */
545 #define GOT_ENTRY_SIZE 8
547 /* The size in bytes of an entry in the lazy procedure linkage table. */
549 #define LAZY_PLT_ENTRY_SIZE 16
551 /* The size in bytes of an entry in the non-lazy procedure linkage
554 #define NON_LAZY_PLT_ENTRY_SIZE 8
556 /* The first entry in a lazy procedure linkage table looks like this.
557 See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this
560 static const bfd_byte elf_x86_64_lazy_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
562 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
563 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
564 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
567 /* Subsequent entries in a lazy procedure linkage table look like this. */
569 static const bfd_byte elf_x86_64_lazy_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
571 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
572 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
573 0x68, /* pushq immediate */
574 0, 0, 0, 0, /* replaced with index into relocation table. */
575 0xe9, /* jmp relative */
576 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
579 /* The first entry in a lazy procedure linkage table with BND prefix
582 static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry
[LAZY_PLT_ENTRY_SIZE
] =
584 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
585 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */
586 0x0f, 0x1f, 0 /* nopl (%rax) */
589 /* Subsequent entries for branches with BND prefx in a lazy procedure
590 linkage table look like this. */
592 static const bfd_byte elf_x86_64_lazy_bnd_plt_entry
[LAZY_PLT_ENTRY_SIZE
] =
594 0x68, 0, 0, 0, 0, /* pushq immediate */
595 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */
596 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */
599 /* Entries in the non-lazey procedure linkage table look like this. */
601 static const bfd_byte elf_x86_64_non_lazy_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
603 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
604 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
605 0x66, 0x90 /* xchg %ax,%ax */
608 /* Entries for branches with BND prefix in the non-lazey procedure
609 linkage table look like this. */
611 static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry
[NON_LAZY_PLT_ENTRY_SIZE
] =
613 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */
614 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
618 /* .eh_frame covering the lazy .plt section. */
620 static const bfd_byte elf_x86_64_eh_frame_lazy_plt
[] =
622 #define PLT_CIE_LENGTH 20
623 #define PLT_FDE_LENGTH 36
624 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
625 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
626 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
627 0, 0, 0, 0, /* CIE ID */
629 'z', 'R', 0, /* Augmentation string */
630 1, /* Code alignment factor */
631 0x78, /* Data alignment factor */
632 16, /* Return address column */
633 1, /* Augmentation size */
634 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
635 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
636 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
637 DW_CFA_nop
, DW_CFA_nop
,
639 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
640 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
641 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
642 0, 0, 0, 0, /* .plt size goes here */
643 0, /* Augmentation size */
644 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
645 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
646 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
647 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
648 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
649 11, /* Block length */
650 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
651 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
652 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
653 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
654 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
657 /* .eh_frame covering the lazy BND .plt section. */
659 static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt
[] =
661 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
662 0, 0, 0, 0, /* CIE ID */
664 'z', 'R', 0, /* Augmentation string */
665 1, /* Code alignment factor */
666 0x78, /* Data alignment factor */
667 16, /* Return address column */
668 1, /* Augmentation size */
669 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
670 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
671 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
672 DW_CFA_nop
, DW_CFA_nop
,
674 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
675 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
676 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
677 0, 0, 0, 0, /* .plt size goes here */
678 0, /* Augmentation size */
679 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
680 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
681 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
682 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
683 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
684 11, /* Block length */
685 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
686 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
687 DW_OP_lit15
, DW_OP_and
, DW_OP_lit5
, DW_OP_ge
,
688 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
689 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
692 /* .eh_frame covering the non-lazy .plt section. */
694 static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt
[] =
696 #define PLT_GOT_FDE_LENGTH 20
697 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
698 0, 0, 0, 0, /* CIE ID */
700 'z', 'R', 0, /* Augmentation string */
701 1, /* Code alignment factor */
702 0x78, /* Data alignment factor */
703 16, /* Return address column */
704 1, /* Augmentation size */
705 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
706 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
707 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
708 DW_CFA_nop
, DW_CFA_nop
,
710 PLT_GOT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
711 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
712 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
713 0, 0, 0, 0, /* non-lazy .plt size goes here */
714 0, /* Augmentation size */
715 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
,
716 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
719 struct elf_x86_64_lazy_plt_layout
721 /* Templates for the initial PLT entry and for subsequent entries. */
722 const bfd_byte
*plt0_entry
;
723 const bfd_byte
*plt_entry
;
724 unsigned int plt_entry_size
; /* Size of each PLT entry. */
726 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
727 unsigned int plt0_got1_offset
;
728 unsigned int plt0_got2_offset
;
730 /* Offset of the end of the PC-relative instruction containing
732 unsigned int plt0_got2_insn_end
;
734 /* Offsets into plt_entry that are to be replaced with... */
735 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
736 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
737 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
739 /* Length of the PC-relative instruction containing plt_got_offset. */
740 unsigned int plt_got_insn_size
;
742 /* Offset of the end of the PC-relative jump to plt0_entry. */
743 unsigned int plt_plt_insn_end
;
745 /* Offset into plt_entry where the initial value of the GOT entry points. */
746 unsigned int plt_lazy_offset
;
748 /* .eh_frame covering the lazy .plt section. */
749 const bfd_byte
*eh_frame_plt
;
750 unsigned int eh_frame_plt_size
;
753 struct elf_x86_64_non_lazy_plt_layout
755 /* Template for the lazy PLT entries. */
756 const bfd_byte
*plt_entry
;
757 unsigned int plt_entry_size
; /* Size of each PLT entry. */
759 /* Offsets into plt_entry that are to be replaced with... */
760 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
762 /* Length of the PC-relative instruction containing plt_got_offset. */
763 unsigned int plt_got_insn_size
;
765 /* .eh_frame covering the non-lazy .plt section. */
766 const bfd_byte
*eh_frame_plt
;
767 unsigned int eh_frame_plt_size
;
770 struct elf_x86_64_plt_layout
772 /* Template for the PLT entries. */
773 const bfd_byte
*plt_entry
;
774 unsigned int plt_entry_size
; /* Size of each PLT entry. */
777 unsigned int has_plt0
;
779 /* Offsets into plt_entry that are to be replaced with... */
780 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
782 /* Length of the PC-relative instruction containing plt_got_offset. */
783 unsigned int plt_got_insn_size
;
785 /* .eh_frame covering the .plt section. */
786 const bfd_byte
*eh_frame_plt
;
787 unsigned int eh_frame_plt_size
;
790 /* Architecture-specific backend data for x86-64. */
792 struct elf_x86_64_backend_data
802 #define get_elf_x86_64_arch_data(bed) \
803 ((const struct elf_x86_64_backend_data *) (bed)->arch_data)
805 #define get_elf_x86_64_backend_data(abfd) \
806 get_elf_x86_64_arch_data (get_elf_backend_data (abfd))
808 /* These are the standard parameters. */
809 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_lazy_plt
=
811 elf_x86_64_lazy_plt0_entry
, /* plt0_entry */
812 elf_x86_64_lazy_plt_entry
, /* plt_entry */
813 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
814 2, /* plt0_got1_offset */
815 8, /* plt0_got2_offset */
816 12, /* plt0_got2_insn_end */
817 2, /* plt_got_offset */
818 7, /* plt_reloc_offset */
819 12, /* plt_plt_offset */
820 6, /* plt_got_insn_size */
821 LAZY_PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
822 6, /* plt_lazy_offset */
823 elf_x86_64_eh_frame_lazy_plt
, /* eh_frame_plt */
824 sizeof (elf_x86_64_eh_frame_lazy_plt
) /* eh_frame_plt_size */
827 static const struct elf_x86_64_non_lazy_plt_layout elf_x86_64_non_lazy_plt
=
829 elf_x86_64_non_lazy_plt_entry
, /* plt_entry */
830 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
831 2, /* plt_got_offset */
832 6, /* plt_got_insn_size */
833 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
834 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
837 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_lazy_bnd_plt
=
839 elf_x86_64_lazy_bnd_plt0_entry
, /* plt0_entry */
840 elf_x86_64_lazy_bnd_plt_entry
, /* plt_entry */
841 LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
842 2, /* plt0_got1_offset */
843 1+8, /* plt0_got2_offset */
844 1+12, /* plt0_got2_insn_end */
845 1+2, /* plt_got_offset */
846 1, /* plt_reloc_offset */
847 7, /* plt_plt_offset */
848 1+6, /* plt_got_insn_size */
849 11, /* plt_plt_insn_end */
850 0, /* plt_lazy_offset */
851 elf_x86_64_eh_frame_lazy_bnd_plt
, /* eh_frame_plt */
852 sizeof (elf_x86_64_eh_frame_lazy_bnd_plt
) /* eh_frame_plt_size */
855 static const struct elf_x86_64_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt
=
857 elf_x86_64_non_lazy_bnd_plt_entry
, /* plt_entry */
858 NON_LAZY_PLT_ENTRY_SIZE
, /* plt_entry_size */
859 1+2, /* plt_got_offset */
860 1+6, /* plt_got_insn_size */
861 elf_x86_64_eh_frame_non_lazy_plt
, /* eh_frame_plt */
862 sizeof (elf_x86_64_eh_frame_non_lazy_plt
) /* eh_frame_plt_size */
865 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
870 #define elf_backend_arch_data &elf_x86_64_arch_bed
872 /* Is a undefined weak symbol which is resolved to 0. Reference to an
873 undefined weak symbol is resolved to 0 when building executable if
875 1. Has non-GOT/non-PLT relocations in text section. Or
876 2. Has no GOT/PLT relocation.
878 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, GOT_RELOC, EH) \
879 ((EH)->elf.root.type == bfd_link_hash_undefweak \
880 && bfd_link_executable (INFO) \
881 && (elf_x86_64_hash_table (INFO)->interp == NULL \
883 || (EH)->has_non_got_reloc \
884 || !(INFO)->dynamic_undefined_weak))
886 /* x86-64 ELF linker hash entry. */
888 struct elf_x86_64_link_hash_entry
890 struct elf_link_hash_entry elf
;
892 /* Track dynamic relocs copied for this symbol. */
893 struct elf_dyn_relocs
*dyn_relocs
;
895 #define GOT_UNKNOWN 0
899 #define GOT_TLS_GDESC 4
900 #define GOT_TLS_GD_BOTH_P(type) \
901 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
902 #define GOT_TLS_GD_P(type) \
903 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
904 #define GOT_TLS_GDESC_P(type) \
905 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
906 #define GOT_TLS_GD_ANY_P(type) \
907 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
908 unsigned char tls_type
;
910 /* TRUE if a weak symbol with a real definition needs a copy reloc.
911 When there is a weak symbol with a real definition, the processor
912 independent code will have arranged for us to see the real
913 definition first. We need to copy the needs_copy bit from the
914 real definition and check it when allowing copy reloc in PIE. */
915 unsigned int needs_copy
: 1;
917 /* TRUE if symbol has GOT or PLT relocations. */
918 unsigned int has_got_reloc
: 1;
920 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
921 unsigned int has_non_got_reloc
: 1;
923 /* Don't call finish_dynamic_symbol on this symbol. */
924 unsigned int no_finish_dynamic_symbol
: 1;
926 /* 0: symbol isn't __tls_get_addr.
927 1: symbol is __tls_get_addr.
928 2: symbol is unknown. */
929 unsigned int tls_get_addr
: 2;
931 /* Reference count of C/C++ function pointer relocations in read-write
932 section which can be resolved at run-time. */
933 bfd_signed_vma func_pointer_refcount
;
935 /* Information about the GOT PLT entry. Filled when there are both
936 GOT and PLT relocations against the same function. */
937 union gotplt_union plt_got
;
939 /* Information about the second PLT entry. Filled when info>bndplt is
941 union gotplt_union plt_bnd
;
943 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
944 starting at the end of the jump table. */
948 #define elf_x86_64_hash_entry(ent) \
949 ((struct elf_x86_64_link_hash_entry *)(ent))
951 struct elf_x86_64_obj_tdata
953 struct elf_obj_tdata root
;
955 /* tls_type for each local got entry. */
956 char *local_got_tls_type
;
958 /* GOTPLT entries for TLS descriptors. */
959 bfd_vma
*local_tlsdesc_gotent
;
962 #define elf_x86_64_tdata(abfd) \
963 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
965 #define elf_x86_64_local_got_tls_type(abfd) \
966 (elf_x86_64_tdata (abfd)->local_got_tls_type)
968 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
969 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
971 #define is_x86_64_elf(bfd) \
972 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
973 && elf_tdata (bfd) != NULL \
974 && elf_object_id (bfd) == X86_64_ELF_DATA)
977 elf_x86_64_mkobject (bfd
*abfd
)
979 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
983 /* x86-64 ELF linker hash table. */
985 struct elf_x86_64_link_hash_table
987 struct elf_link_hash_table elf
;
989 /* Short-cuts to get to dynamic linker sections. */
991 asection
*plt_eh_frame
;
993 asection
*plt_bnd_eh_frame
;
995 asection
*plt_got_eh_frame
;
997 /* Parameters describing PLT generation, lazy or non-lazy. */
998 struct elf_x86_64_plt_layout plt
;
1000 /* Parameters describing lazy PLT generation. */
1001 const struct elf_x86_64_lazy_plt_layout
*lazy_plt
;
1003 /* Parameters describing non-lazy PLT generation. */
1004 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_plt
;
1008 bfd_signed_vma refcount
;
1012 /* The amount of space used by the jump slots in the GOT. */
1013 bfd_vma sgotplt_jump_table_size
;
1015 /* Small local sym cache. */
1016 struct sym_cache sym_cache
;
1018 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
1019 bfd_vma (*r_sym
) (bfd_vma
);
1020 unsigned int pointer_r_type
;
1021 const char *dynamic_interpreter
;
1022 int dynamic_interpreter_size
;
1024 /* _TLS_MODULE_BASE_ symbol. */
1025 struct bfd_link_hash_entry
*tls_module_base
;
1027 /* Used by local STT_GNU_IFUNC symbols. */
1028 htab_t loc_hash_table
;
1029 void * loc_hash_memory
;
1031 /* The offset into splt of the PLT entry for the TLS descriptor
1032 resolver. Special values are 0, if not necessary (or not found
1033 to be necessary yet), and -1 if needed but not determined
1035 bfd_vma tlsdesc_plt
;
1036 /* The offset into sgot of the GOT entry used by the PLT entry
1038 bfd_vma tlsdesc_got
;
1040 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
1041 bfd_vma next_jump_slot_index
;
1042 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
1043 bfd_vma next_irelative_index
;
1045 /* TRUE if there are dynamic relocs against IFUNC symbols that apply
1046 to read-only sections. */
1047 bfd_boolean readonly_dynrelocs_against_ifunc
;
1050 /* Get the x86-64 ELF linker hash table from a link_info structure. */
1052 #define elf_x86_64_hash_table(p) \
1053 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1054 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
1056 #define elf_x86_64_compute_jump_table_size(htab) \
1057 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
1059 /* Create an entry in an x86-64 ELF linker hash table. */
1061 static struct bfd_hash_entry
*
1062 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1063 struct bfd_hash_table
*table
,
1066 /* Allocate the structure if it has not already been allocated by a
1070 entry
= (struct bfd_hash_entry
*)
1071 bfd_hash_allocate (table
,
1072 sizeof (struct elf_x86_64_link_hash_entry
));
1077 /* Call the allocation method of the superclass. */
1078 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1081 struct elf_x86_64_link_hash_entry
*eh
;
1083 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
1084 eh
->dyn_relocs
= NULL
;
1085 eh
->tls_type
= GOT_UNKNOWN
;
1087 eh
->has_got_reloc
= 0;
1088 eh
->has_non_got_reloc
= 0;
1089 eh
->no_finish_dynamic_symbol
= 0;
1090 eh
->tls_get_addr
= 2;
1091 eh
->func_pointer_refcount
= 0;
1092 eh
->plt_bnd
.offset
= (bfd_vma
) -1;
1093 eh
->plt_got
.offset
= (bfd_vma
) -1;
1094 eh
->tlsdesc_got
= (bfd_vma
) -1;
1100 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1101 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1102 as global symbol. We reuse indx and dynstr_index for local symbol
1103 hash since they aren't used by global symbols in this backend. */
1106 elf_x86_64_local_htab_hash (const void *ptr
)
1108 struct elf_link_hash_entry
*h
1109 = (struct elf_link_hash_entry
*) ptr
;
1110 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
1113 /* Compare local hash entries. */
1116 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
1118 struct elf_link_hash_entry
*h1
1119 = (struct elf_link_hash_entry
*) ptr1
;
1120 struct elf_link_hash_entry
*h2
1121 = (struct elf_link_hash_entry
*) ptr2
;
1123 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
1126 /* Find and/or create a hash entry for local symbol. */
1128 static struct elf_link_hash_entry
*
1129 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
1130 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1133 struct elf_x86_64_link_hash_entry e
, *ret
;
1134 asection
*sec
= abfd
->sections
;
1135 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1136 htab
->r_sym (rel
->r_info
));
1139 e
.elf
.indx
= sec
->id
;
1140 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1141 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
1142 create
? INSERT
: NO_INSERT
);
1149 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
1153 ret
= (struct elf_x86_64_link_hash_entry
*)
1154 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
1155 sizeof (struct elf_x86_64_link_hash_entry
));
1158 memset (ret
, 0, sizeof (*ret
));
1159 ret
->elf
.indx
= sec
->id
;
1160 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
1161 ret
->elf
.dynindx
= -1;
1162 ret
->func_pointer_refcount
= 0;
1163 ret
->plt_got
.offset
= (bfd_vma
) -1;
1169 /* Destroy an X86-64 ELF linker hash table. */
1172 elf_x86_64_link_hash_table_free (bfd
*obfd
)
1174 struct elf_x86_64_link_hash_table
*htab
1175 = (struct elf_x86_64_link_hash_table
*) obfd
->link
.hash
;
1177 if (htab
->loc_hash_table
)
1178 htab_delete (htab
->loc_hash_table
);
1179 if (htab
->loc_hash_memory
)
1180 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
1181 _bfd_elf_link_hash_table_free (obfd
);
1184 /* Create an X86-64 ELF linker hash table. */
1186 static struct bfd_link_hash_table
*
1187 elf_x86_64_link_hash_table_create (bfd
*abfd
)
1189 struct elf_x86_64_link_hash_table
*ret
;
1190 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
1192 ret
= (struct elf_x86_64_link_hash_table
*) bfd_zmalloc (amt
);
1196 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1197 elf_x86_64_link_hash_newfunc
,
1198 sizeof (struct elf_x86_64_link_hash_entry
),
1205 if (ABI_64_P (abfd
))
1207 ret
->r_info
= elf64_r_info
;
1208 ret
->r_sym
= elf64_r_sym
;
1209 ret
->pointer_r_type
= R_X86_64_64
;
1210 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
1211 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
1215 ret
->r_info
= elf32_r_info
;
1216 ret
->r_sym
= elf32_r_sym
;
1217 ret
->pointer_r_type
= R_X86_64_32
;
1218 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
1219 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
1222 ret
->loc_hash_table
= htab_try_create (1024,
1223 elf_x86_64_local_htab_hash
,
1224 elf_x86_64_local_htab_eq
,
1226 ret
->loc_hash_memory
= objalloc_create ();
1227 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1229 elf_x86_64_link_hash_table_free (abfd
);
1232 ret
->elf
.root
.hash_table_free
= elf_x86_64_link_hash_table_free
;
1234 return &ret
->elf
.root
;
1237 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1240 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1241 struct elf_link_hash_entry
*dir
,
1242 struct elf_link_hash_entry
*ind
)
1244 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1246 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1247 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1249 edir
->has_got_reloc
|= eind
->has_got_reloc
;
1250 edir
->has_non_got_reloc
|= eind
->has_non_got_reloc
;
1252 if (eind
->dyn_relocs
!= NULL
)
1254 if (edir
->dyn_relocs
!= NULL
)
1256 struct elf_dyn_relocs
**pp
;
1257 struct elf_dyn_relocs
*p
;
1259 /* Add reloc counts against the indirect sym to the direct sym
1260 list. Merge any entries against the same section. */
1261 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1263 struct elf_dyn_relocs
*q
;
1265 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1266 if (q
->sec
== p
->sec
)
1268 q
->pc_count
+= p
->pc_count
;
1269 q
->count
+= p
->count
;
1276 *pp
= edir
->dyn_relocs
;
1279 edir
->dyn_relocs
= eind
->dyn_relocs
;
1280 eind
->dyn_relocs
= NULL
;
1283 if (ind
->root
.type
== bfd_link_hash_indirect
1284 && dir
->got
.refcount
<= 0)
1286 edir
->tls_type
= eind
->tls_type
;
1287 eind
->tls_type
= GOT_UNKNOWN
;
1290 if (ELIMINATE_COPY_RELOCS
1291 && ind
->root
.type
!= bfd_link_hash_indirect
1292 && dir
->dynamic_adjusted
)
1294 /* If called to transfer flags for a weakdef during processing
1295 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1296 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1297 if (dir
->versioned
!= versioned_hidden
)
1298 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1299 dir
->ref_regular
|= ind
->ref_regular
;
1300 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1301 dir
->needs_plt
|= ind
->needs_plt
;
1302 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1306 if (eind
->func_pointer_refcount
> 0)
1308 edir
->func_pointer_refcount
+= eind
->func_pointer_refcount
;
1309 eind
->func_pointer_refcount
= 0;
1312 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1317 elf64_x86_64_elf_object_p (bfd
*abfd
)
1319 /* Set the right machine number for an x86-64 elf64 file. */
1320 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1325 elf32_x86_64_elf_object_p (bfd
*abfd
)
1327 /* Set the right machine number for an x86-64 elf32 file. */
1328 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1332 /* Return TRUE if the TLS access code sequence support transition
1336 elf_x86_64_check_tls_transition (bfd
*abfd
,
1337 struct bfd_link_info
*info
,
1340 Elf_Internal_Shdr
*symtab_hdr
,
1341 struct elf_link_hash_entry
**sym_hashes
,
1342 unsigned int r_type
,
1343 const Elf_Internal_Rela
*rel
,
1344 const Elf_Internal_Rela
*relend
)
1347 unsigned long r_symndx
;
1348 bfd_boolean largepic
= FALSE
;
1349 struct elf_link_hash_entry
*h
;
1351 struct elf_x86_64_link_hash_table
*htab
;
1353 bfd_boolean indirect_call
, tls_get_addr
;
1355 htab
= elf_x86_64_hash_table (info
);
1356 offset
= rel
->r_offset
;
1359 case R_X86_64_TLSGD
:
1360 case R_X86_64_TLSLD
:
1361 if ((rel
+ 1) >= relend
)
1364 if (r_type
== R_X86_64_TLSGD
)
1366 /* Check transition from GD access model. For 64bit, only
1367 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1368 .word 0x6666; rex64; call __tls_get_addr@PLT
1370 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1372 call *__tls_get_addr@GOTPCREL(%rip)
1373 which may be converted to
1374 addr32 call __tls_get_addr
1375 can transit to different access model. For 32bit, only
1376 leaq foo@tlsgd(%rip), %rdi
1377 .word 0x6666; rex64; call __tls_get_addr@PLT
1379 leaq foo@tlsgd(%rip), %rdi
1381 call *__tls_get_addr@GOTPCREL(%rip)
1382 which may be converted to
1383 addr32 call __tls_get_addr
1384 can transit to different access model. For largepic,
1386 leaq foo@tlsgd(%rip), %rdi
1387 movabsq $__tls_get_addr@pltoff, %rax
1391 leaq foo@tlsgd(%rip), %rdi
1392 movabsq $__tls_get_addr@pltoff, %rax
1396 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1398 if ((offset
+ 12) > sec
->size
)
1401 call
= contents
+ offset
+ 4;
1403 || !((call
[1] == 0x48
1411 && call
[3] == 0xe8)))
1413 if (!ABI_64_P (abfd
)
1414 || (offset
+ 19) > sec
->size
1416 || memcmp (call
- 7, leaq
+ 1, 3) != 0
1417 || memcmp (call
, "\x48\xb8", 2) != 0
1421 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1422 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1426 else if (ABI_64_P (abfd
))
1429 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1435 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1438 indirect_call
= call
[2] == 0xff;
1442 /* Check transition from LD access model. Only
1443 leaq foo@tlsld(%rip), %rdi;
1444 call __tls_get_addr@PLT
1446 leaq foo@tlsld(%rip), %rdi;
1447 call *__tls_get_addr@GOTPCREL(%rip)
1448 which may be converted to
1449 addr32 call __tls_get_addr
1450 can transit to different access model. For largepic
1452 leaq foo@tlsld(%rip), %rdi
1453 movabsq $__tls_get_addr@pltoff, %rax
1457 leaq foo@tlsld(%rip), %rdi
1458 movabsq $__tls_get_addr@pltoff, %rax
1462 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1464 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1467 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0)
1470 call
= contents
+ offset
+ 4;
1471 if (!(call
[0] == 0xe8
1472 || (call
[0] == 0xff && call
[1] == 0x15)
1473 || (call
[0] == 0x67 && call
[1] == 0xe8)))
1475 if (!ABI_64_P (abfd
)
1476 || (offset
+ 19) > sec
->size
1477 || memcmp (call
, "\x48\xb8", 2) != 0
1481 || !((call
[10] == 0x48 && call
[12] == 0xd8)
1482 || (call
[10] == 0x4c && call
[12] == 0xf8)))
1486 indirect_call
= call
[0] == 0xff;
1489 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1490 if (r_symndx
< symtab_hdr
->sh_info
)
1493 tls_get_addr
= FALSE
;
1494 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1495 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1497 struct elf_x86_64_link_hash_entry
*eh
1498 = (struct elf_x86_64_link_hash_entry
*) h
;
1499 tls_get_addr
= eh
->tls_get_addr
== 1;
1500 if (eh
->tls_get_addr
> 1)
1502 /* Use strncmp to check __tls_get_addr since
1503 __tls_get_addr may be versioned. */
1504 if (strncmp (h
->root
.root
.string
, "__tls_get_addr", 14)
1507 eh
->tls_get_addr
= 1;
1508 tls_get_addr
= TRUE
;
1511 eh
->tls_get_addr
= 0;
1518 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLTOFF64
;
1519 else if (indirect_call
)
1520 return ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_GOTPCRELX
;
1522 return (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1523 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
1525 case R_X86_64_GOTTPOFF
:
1526 /* Check transition from IE access model:
1527 mov foo@gottpoff(%rip), %reg
1528 add foo@gottpoff(%rip), %reg
1531 /* Check REX prefix first. */
1532 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1534 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1535 if (val
!= 0x48 && val
!= 0x4c)
1537 /* X32 may have 0x44 REX prefix or no REX prefix. */
1538 if (ABI_64_P (abfd
))
1544 /* X32 may not have any REX prefix. */
1545 if (ABI_64_P (abfd
))
1547 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1551 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1552 if (val
!= 0x8b && val
!= 0x03)
1555 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1556 return (val
& 0xc7) == 5;
1558 case R_X86_64_GOTPC32_TLSDESC
:
1559 /* Check transition from GDesc access model:
1560 leaq x@tlsdesc(%rip), %rax
1562 Make sure it's a leaq adding rip to a 32-bit offset
1563 into any register, although it's probably almost always
1566 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1569 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1570 if ((val
& 0xfb) != 0x48)
1573 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1576 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1577 return (val
& 0xc7) == 0x05;
1579 case R_X86_64_TLSDESC_CALL
:
1580 /* Check transition from GDesc access model:
1581 call *x@tlsdesc(%rax)
1583 if (offset
+ 2 <= sec
->size
)
1585 /* Make sure that it's a call *x@tlsdesc(%rax). */
1586 call
= contents
+ offset
;
1587 return call
[0] == 0xff && call
[1] == 0x10;
1597 /* Return TRUE if the TLS access transition is OK or no transition
1598 will be performed. Update R_TYPE if there is a transition. */
1601 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1602 asection
*sec
, bfd_byte
*contents
,
1603 Elf_Internal_Shdr
*symtab_hdr
,
1604 struct elf_link_hash_entry
**sym_hashes
,
1605 unsigned int *r_type
, int tls_type
,
1606 const Elf_Internal_Rela
*rel
,
1607 const Elf_Internal_Rela
*relend
,
1608 struct elf_link_hash_entry
*h
,
1609 unsigned long r_symndx
,
1610 bfd_boolean from_relocate_section
)
1612 unsigned int from_type
= *r_type
;
1613 unsigned int to_type
= from_type
;
1614 bfd_boolean check
= TRUE
;
1616 /* Skip TLS transition for functions. */
1618 && (h
->type
== STT_FUNC
1619 || h
->type
== STT_GNU_IFUNC
))
1624 case R_X86_64_TLSGD
:
1625 case R_X86_64_GOTPC32_TLSDESC
:
1626 case R_X86_64_TLSDESC_CALL
:
1627 case R_X86_64_GOTTPOFF
:
1628 if (bfd_link_executable (info
))
1631 to_type
= R_X86_64_TPOFF32
;
1633 to_type
= R_X86_64_GOTTPOFF
;
1636 /* When we are called from elf_x86_64_relocate_section, there may
1637 be additional transitions based on TLS_TYPE. */
1638 if (from_relocate_section
)
1640 unsigned int new_to_type
= to_type
;
1642 if (bfd_link_executable (info
)
1645 && tls_type
== GOT_TLS_IE
)
1646 new_to_type
= R_X86_64_TPOFF32
;
1648 if (to_type
== R_X86_64_TLSGD
1649 || to_type
== R_X86_64_GOTPC32_TLSDESC
1650 || to_type
== R_X86_64_TLSDESC_CALL
)
1652 if (tls_type
== GOT_TLS_IE
)
1653 new_to_type
= R_X86_64_GOTTPOFF
;
1656 /* We checked the transition before when we were called from
1657 elf_x86_64_check_relocs. We only want to check the new
1658 transition which hasn't been checked before. */
1659 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1660 to_type
= new_to_type
;
1665 case R_X86_64_TLSLD
:
1666 if (bfd_link_executable (info
))
1667 to_type
= R_X86_64_TPOFF32
;
1674 /* Return TRUE if there is no transition. */
1675 if (from_type
== to_type
)
1678 /* Check if the transition can be performed. */
1680 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1681 symtab_hdr
, sym_hashes
,
1682 from_type
, rel
, relend
))
1684 reloc_howto_type
*from
, *to
;
1687 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1688 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1691 name
= h
->root
.root
.string
;
1694 struct elf_x86_64_link_hash_table
*htab
;
1696 htab
= elf_x86_64_hash_table (info
);
1701 Elf_Internal_Sym
*isym
;
1703 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1705 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1710 /* xgettext:c-format */
1711 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1712 "in section `%A' failed"),
1713 abfd
, from
->name
, to
->name
, name
,
1714 (unsigned long) rel
->r_offset
, sec
);
1715 bfd_set_error (bfd_error_bad_value
);
1723 /* Rename some of the generic section flags to better document how they
1725 #define need_convert_load sec_flg0
1726 #define check_relocs_failed sec_flg1
1729 elf_x86_64_need_pic (bfd
*input_bfd
, asection
*sec
,
1730 struct elf_link_hash_entry
*h
,
1731 Elf_Internal_Shdr
*symtab_hdr
,
1732 Elf_Internal_Sym
*isym
,
1733 reloc_howto_type
*howto
)
1736 const char *und
= "";
1737 const char *pic
= "";
1742 name
= h
->root
.root
.string
;
1743 switch (ELF_ST_VISIBILITY (h
->other
))
1746 v
= _("hidden symbol ");
1749 v
= _("internal symbol ");
1752 v
= _("protected symbol ");
1756 pic
= _("; recompile with -fPIC");
1760 if (!h
->def_regular
&& !h
->def_dynamic
)
1761 und
= _("undefined ");
1765 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, isym
, NULL
);
1766 pic
= _("; recompile with -fPIC");
1769 /* xgettext:c-format */
1770 _bfd_error_handler (_("%B: relocation %s against %s%s`%s' can "
1771 "not be used when making a shared object%s"),
1772 input_bfd
, howto
->name
, und
, v
, name
, pic
);
1773 bfd_set_error (bfd_error_bad_value
);
1774 sec
->check_relocs_failed
= 1;
1778 /* With the local symbol, foo, we convert
1779 mov foo@GOTPCREL(%rip), %reg
1783 call/jmp *foo@GOTPCREL(%rip)
1785 nop call foo/jmp foo nop
1786 When PIC is false, convert
1787 test %reg, foo@GOTPCREL(%rip)
1791 binop foo@GOTPCREL(%rip), %reg
1794 where binop is one of adc, add, and, cmp, or, sbb, sub, xor
1798 elf_x86_64_convert_load_reloc (bfd
*abfd
, asection
*sec
,
1800 Elf_Internal_Rela
*irel
,
1801 struct elf_link_hash_entry
*h
,
1802 bfd_boolean
*converted
,
1803 struct bfd_link_info
*link_info
)
1805 struct elf_x86_64_link_hash_table
*htab
;
1807 bfd_boolean require_reloc_pc32
;
1809 bfd_boolean to_reloc_pc32
;
1812 bfd_signed_vma raddend
;
1813 unsigned int opcode
;
1815 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
1816 unsigned int r_symndx
;
1818 bfd_vma roff
= irel
->r_offset
;
1820 if (roff
< (r_type
== R_X86_64_REX_GOTPCRELX
? 3 : 2))
1823 raddend
= irel
->r_addend
;
1824 /* Addend for 32-bit PC-relative relocation must be -4. */
1828 htab
= elf_x86_64_hash_table (link_info
);
1829 is_pic
= bfd_link_pic (link_info
);
1831 relocx
= (r_type
== R_X86_64_GOTPCRELX
1832 || r_type
== R_X86_64_REX_GOTPCRELX
);
1834 /* TRUE if we can convert only to R_X86_64_PC32. Enable it for
1837 = link_info
->disable_target_specific_optimizations
> 1;
1839 r_symndx
= htab
->r_sym (irel
->r_info
);
1841 opcode
= bfd_get_8 (abfd
, contents
+ roff
- 2);
1843 /* Convert mov to lea since it has been done for a while. */
1846 /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX
1847 for call, jmp or one of adc, add, and, cmp, or, sbb, sub,
1848 test, xor instructions. */
1853 /* We convert only to R_X86_64_PC32:
1855 2. R_X86_64_GOTPCREL since we can't modify REX byte.
1856 3. require_reloc_pc32 is true.
1859 to_reloc_pc32
= (opcode
== 0xff
1861 || require_reloc_pc32
1864 /* Get the symbol referred to by the reloc. */
1867 Elf_Internal_Sym
*isym
1868 = bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
1870 /* Skip relocation against undefined symbols. */
1871 if (isym
->st_shndx
== SHN_UNDEF
)
1874 symtype
= ELF_ST_TYPE (isym
->st_info
);
1876 if (isym
->st_shndx
== SHN_ABS
)
1877 tsec
= bfd_abs_section_ptr
;
1878 else if (isym
->st_shndx
== SHN_COMMON
)
1879 tsec
= bfd_com_section_ptr
;
1880 else if (isym
->st_shndx
== SHN_X86_64_LCOMMON
)
1881 tsec
= &_bfd_elf_large_com_section
;
1883 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1885 toff
= isym
->st_value
;
1889 /* Undefined weak symbol is only bound locally in executable
1890 and its reference is resolved as 0 without relocation
1891 overflow. We can only perform this optimization for
1892 GOTPCRELX relocations since we need to modify REX byte.
1893 It is OK convert mov with R_X86_64_GOTPCREL to
1895 if ((relocx
|| opcode
== 0x8b)
1896 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (link_info
,
1898 elf_x86_64_hash_entry (h
)))
1902 /* Skip for branch instructions since R_X86_64_PC32
1904 if (require_reloc_pc32
)
1909 /* For non-branch instructions, we can convert to
1910 R_X86_64_32/R_X86_64_32S since we know if there
1912 to_reloc_pc32
= FALSE
;
1915 /* Since we don't know the current PC when PIC is true,
1916 we can't convert to R_X86_64_PC32. */
1917 if (to_reloc_pc32
&& is_pic
)
1922 /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since
1923 ld.so may use its link-time address. */
1924 else if ((h
->def_regular
1925 || h
->root
.type
== bfd_link_hash_defined
1926 || h
->root
.type
== bfd_link_hash_defweak
)
1927 && h
!= htab
->elf
.hdynamic
1928 && SYMBOL_REFERENCES_LOCAL (link_info
, h
))
1930 /* bfd_link_hash_new or bfd_link_hash_undefined is
1931 set by an assignment in a linker script in
1932 bfd_elf_record_link_assignment. */
1934 && (h
->root
.type
== bfd_link_hash_new
1935 || h
->root
.type
== bfd_link_hash_undefined
1936 || ((h
->root
.type
== bfd_link_hash_defined
1937 || h
->root
.type
== bfd_link_hash_defweak
)
1938 && h
->root
.u
.def
.section
== bfd_und_section_ptr
)))
1940 /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */
1941 if (require_reloc_pc32
)
1945 tsec
= h
->root
.u
.def
.section
;
1946 toff
= h
->root
.u
.def
.value
;
1953 /* Don't convert GOTPCREL relocation against large section. */
1954 if (elf_section_data (tsec
) != NULL
1955 && (elf_section_flags (tsec
) & SHF_X86_64_LARGE
) != 0)
1958 /* We can only estimate relocation overflow for R_X86_64_PC32. */
1962 if (tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
1964 /* At this stage in linking, no SEC_MERGE symbol has been
1965 adjusted, so all references to such symbols need to be
1966 passed through _bfd_merged_section_offset. (Later, in
1967 relocate_section, all SEC_MERGE symbols *except* for
1968 section symbols have been adjusted.)
1970 gas may reduce relocations against symbols in SEC_MERGE
1971 sections to a relocation against the section symbol when
1972 the original addend was zero. When the reloc is against
1973 a section symbol we should include the addend in the
1974 offset passed to _bfd_merged_section_offset, since the
1975 location of interest is the original symbol. On the
1976 other hand, an access to "sym+addend" where "sym" is not
1977 a section symbol should not include the addend; Such an
1978 access is presumed to be an offset from "sym"; The
1979 location of interest is just "sym". */
1980 if (symtype
== STT_SECTION
)
1983 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1984 elf_section_data (tsec
)->sec_info
,
1987 if (symtype
!= STT_SECTION
)
1993 /* Don't convert if R_X86_64_PC32 relocation overflows. */
1994 if (tsec
->output_section
== sec
->output_section
)
1996 if ((toff
- roff
+ 0x80000000) > 0xffffffff)
2001 bfd_signed_vma distance
;
2003 /* At this point, we don't know the load addresses of TSEC
2004 section nor SEC section. We estimate the distrance between
2005 SEC and TSEC. We store the estimated distances in the
2006 compressed_size field of the output section, which is only
2007 used to decompress the compressed input section. */
2008 if (sec
->output_section
->compressed_size
== 0)
2011 bfd_size_type size
= 0;
2012 for (asect
= link_info
->output_bfd
->sections
;
2014 asect
= asect
->next
)
2015 /* Skip debug sections since compressed_size is used to
2016 compress debug sections. */
2017 if ((asect
->flags
& SEC_DEBUGGING
) == 0)
2020 for (i
= asect
->map_head
.s
;
2024 size
= align_power (size
, i
->alignment_power
);
2027 asect
->compressed_size
= size
;
2031 /* Don't convert GOTPCREL relocations if TSEC isn't placed
2033 distance
= (tsec
->output_section
->compressed_size
2034 - sec
->output_section
->compressed_size
);
2038 /* Take PT_GNU_RELRO segment into account by adding
2040 if ((toff
+ distance
+ get_elf_backend_data (abfd
)->maxpagesize
2041 - roff
+ 0x80000000) > 0xffffffff)
2048 /* We have "call/jmp *foo@GOTPCREL(%rip)". */
2053 /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to
2055 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2058 /* Convert to "jmp foo nop". */
2061 nop_offset
= irel
->r_offset
+ 3;
2062 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2063 irel
->r_offset
-= 1;
2064 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2068 struct elf_x86_64_link_hash_entry
*eh
2069 = (struct elf_x86_64_link_hash_entry
*) h
;
2071 /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
2074 /* To support TLS optimization, always use addr32 prefix for
2075 "call *__tls_get_addr@GOTPCREL(%rip)". */
2076 if (eh
&& eh
->tls_get_addr
== 1)
2079 nop_offset
= irel
->r_offset
- 2;
2083 nop
= link_info
->call_nop_byte
;
2084 if (link_info
->call_nop_as_suffix
)
2086 nop_offset
= irel
->r_offset
+ 3;
2087 disp
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
2088 irel
->r_offset
-= 1;
2089 bfd_put_32 (abfd
, disp
, contents
+ irel
->r_offset
);
2092 nop_offset
= irel
->r_offset
- 2;
2095 bfd_put_8 (abfd
, nop
, contents
+ nop_offset
);
2096 bfd_put_8 (abfd
, modrm
, contents
+ irel
->r_offset
- 1);
2097 r_type
= R_X86_64_PC32
;
2102 unsigned int rex_mask
= REX_R
;
2104 if (r_type
== R_X86_64_REX_GOTPCRELX
)
2105 rex
= bfd_get_8 (abfd
, contents
+ roff
- 3);
2113 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2114 "lea foo(%rip), %reg". */
2116 r_type
= R_X86_64_PC32
;
2120 /* Convert "mov foo@GOTPCREL(%rip), %reg" to
2121 "mov $foo, %reg". */
2123 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2124 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2125 if ((rex
& REX_W
) != 0
2126 && ABI_64_P (link_info
->output_bfd
))
2128 /* Keep the REX_W bit in REX byte for LP64. */
2129 r_type
= R_X86_64_32S
;
2130 goto rewrite_modrm_rex
;
2134 /* If the REX_W bit in REX byte isn't needed,
2135 use R_X86_64_32 and clear the W bit to avoid
2136 sign-extend imm32 to imm64. */
2137 r_type
= R_X86_64_32
;
2138 /* Clear the W bit in REX byte. */
2140 goto rewrite_modrm_rex
;
2146 /* R_X86_64_PC32 isn't supported. */
2150 modrm
= bfd_get_8 (abfd
, contents
+ roff
- 1);
2153 /* Convert "test %reg, foo@GOTPCREL(%rip)" to
2154 "test $foo, %reg". */
2155 modrm
= 0xc0 | (modrm
& 0x38) >> 3;
2160 /* Convert "binop foo@GOTPCREL(%rip), %reg" to
2161 "binop $foo, %reg". */
2162 modrm
= 0xc0 | (modrm
& 0x38) >> 3 | (opcode
& 0x3c);
2166 /* Use R_X86_64_32 with 32-bit operand to avoid relocation
2167 overflow when sign-extending imm32 to imm64. */
2168 r_type
= (rex
& REX_W
) != 0 ? R_X86_64_32S
: R_X86_64_32
;
2171 bfd_put_8 (abfd
, modrm
, contents
+ roff
- 1);
2175 /* Move the R bit to the B bit in REX byte. */
2176 rex
= (rex
& ~rex_mask
) | (rex
& REX_R
) >> 2;
2177 bfd_put_8 (abfd
, rex
, contents
+ roff
- 3);
2180 /* No addend for R_X86_64_32/R_X86_64_32S relocations. */
2184 bfd_put_8 (abfd
, opcode
, contents
+ roff
- 2);
2187 irel
->r_info
= htab
->r_info (r_symndx
, r_type
);
2194 /* Look through the relocs for a section during the first phase, and
2195 calculate needed space in the global offset table, procedure
2196 linkage table, and dynamic reloc sections. */
2199 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2201 const Elf_Internal_Rela
*relocs
)
2203 struct elf_x86_64_link_hash_table
*htab
;
2204 Elf_Internal_Shdr
*symtab_hdr
;
2205 struct elf_link_hash_entry
**sym_hashes
;
2206 const Elf_Internal_Rela
*rel
;
2207 const Elf_Internal_Rela
*rel_end
;
2211 if (bfd_link_relocatable (info
))
2214 /* Don't do anything special with non-loaded, non-alloced sections.
2215 In particular, any relocs in such sections should not affect GOT
2216 and PLT reference counting (ie. we don't allow them to create GOT
2217 or PLT entries), there's no possibility or desire to optimize TLS
2218 relocs, and there's not much point in propagating relocs to shared
2219 libs that the dynamic linker won't relocate. */
2220 if ((sec
->flags
& SEC_ALLOC
) == 0)
2223 BFD_ASSERT (is_x86_64_elf (abfd
));
2225 htab
= elf_x86_64_hash_table (info
);
2228 sec
->check_relocs_failed
= 1;
2232 /* Get the section contents. */
2233 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2234 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2235 else if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2237 sec
->check_relocs_failed
= 1;
2241 symtab_hdr
= &elf_symtab_hdr (abfd
);
2242 sym_hashes
= elf_sym_hashes (abfd
);
2246 rel_end
= relocs
+ sec
->reloc_count
;
2247 for (rel
= relocs
; rel
< rel_end
; rel
++)
2249 unsigned int r_type
;
2250 unsigned long r_symndx
;
2251 struct elf_link_hash_entry
*h
;
2252 struct elf_x86_64_link_hash_entry
*eh
;
2253 Elf_Internal_Sym
*isym
;
2255 bfd_boolean size_reloc
;
2257 r_symndx
= htab
->r_sym (rel
->r_info
);
2258 r_type
= ELF32_R_TYPE (rel
->r_info
);
2260 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
2262 /* xgettext:c-format */
2263 _bfd_error_handler (_("%B: bad symbol index: %d"),
2268 if (r_symndx
< symtab_hdr
->sh_info
)
2270 /* A local symbol. */
2271 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2276 /* Check relocation against local STT_GNU_IFUNC symbol. */
2277 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2279 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
2284 /* Fake a STT_GNU_IFUNC symbol. */
2285 h
->type
= STT_GNU_IFUNC
;
2288 h
->forced_local
= 1;
2289 h
->root
.type
= bfd_link_hash_defined
;
2297 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2298 while (h
->root
.type
== bfd_link_hash_indirect
2299 || h
->root
.type
== bfd_link_hash_warning
)
2300 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2303 /* Check invalid x32 relocations. */
2304 if (!ABI_64_P (abfd
))
2310 case R_X86_64_DTPOFF64
:
2311 case R_X86_64_TPOFF64
:
2313 case R_X86_64_GOTOFF64
:
2314 case R_X86_64_GOT64
:
2315 case R_X86_64_GOTPCREL64
:
2316 case R_X86_64_GOTPC64
:
2317 case R_X86_64_GOTPLT64
:
2318 case R_X86_64_PLTOFF64
:
2321 name
= h
->root
.root
.string
;
2323 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
2326 /* xgettext:c-format */
2327 (_("%B: relocation %s against symbol `%s' isn't "
2328 "supported in x32 mode"), abfd
,
2329 x86_64_elf_howto_table
[r_type
].name
, name
);
2330 bfd_set_error (bfd_error_bad_value
);
2338 /* It is referenced by a non-shared object. */
2340 h
->root
.non_ir_ref
= 1;
2342 if (h
->type
== STT_GNU_IFUNC
)
2343 elf_tdata (info
->output_bfd
)->has_gnu_symbols
2344 |= elf_gnu_symbol_ifunc
;
2347 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, contents
,
2348 symtab_hdr
, sym_hashes
,
2349 &r_type
, GOT_UNKNOWN
,
2350 rel
, rel_end
, h
, r_symndx
, FALSE
))
2353 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2356 case R_X86_64_TLSLD
:
2357 htab
->tls_ld_got
.refcount
+= 1;
2360 case R_X86_64_TPOFF32
:
2361 if (!bfd_link_executable (info
) && ABI_64_P (abfd
))
2362 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2363 &x86_64_elf_howto_table
[r_type
]);
2365 eh
->has_got_reloc
= 1;
2368 case R_X86_64_GOTTPOFF
:
2369 if (!bfd_link_executable (info
))
2370 info
->flags
|= DF_STATIC_TLS
;
2373 case R_X86_64_GOT32
:
2374 case R_X86_64_GOTPCREL
:
2375 case R_X86_64_GOTPCRELX
:
2376 case R_X86_64_REX_GOTPCRELX
:
2377 case R_X86_64_TLSGD
:
2378 case R_X86_64_GOT64
:
2379 case R_X86_64_GOTPCREL64
:
2380 case R_X86_64_GOTPLT64
:
2381 case R_X86_64_GOTPC32_TLSDESC
:
2382 case R_X86_64_TLSDESC_CALL
:
2383 /* This symbol requires a global offset table entry. */
2385 int tls_type
, old_tls_type
;
2389 default: tls_type
= GOT_NORMAL
; break;
2390 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
2391 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
2392 case R_X86_64_GOTPC32_TLSDESC
:
2393 case R_X86_64_TLSDESC_CALL
:
2394 tls_type
= GOT_TLS_GDESC
; break;
2399 h
->got
.refcount
+= 1;
2400 old_tls_type
= eh
->tls_type
;
2404 bfd_signed_vma
*local_got_refcounts
;
2406 /* This is a global offset table entry for a local symbol. */
2407 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2408 if (local_got_refcounts
== NULL
)
2412 size
= symtab_hdr
->sh_info
;
2413 size
*= sizeof (bfd_signed_vma
)
2414 + sizeof (bfd_vma
) + sizeof (char);
2415 local_got_refcounts
= ((bfd_signed_vma
*)
2416 bfd_zalloc (abfd
, size
));
2417 if (local_got_refcounts
== NULL
)
2419 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2420 elf_x86_64_local_tlsdesc_gotent (abfd
)
2421 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2422 elf_x86_64_local_got_tls_type (abfd
)
2423 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
2425 local_got_refcounts
[r_symndx
] += 1;
2427 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
2430 /* If a TLS symbol is accessed using IE at least once,
2431 there is no point to use dynamic model for it. */
2432 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
2433 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
2434 || tls_type
!= GOT_TLS_IE
))
2436 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
2437 tls_type
= old_tls_type
;
2438 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
2439 && GOT_TLS_GD_ANY_P (tls_type
))
2440 tls_type
|= old_tls_type
;
2444 name
= h
->root
.root
.string
;
2446 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
2449 /* xgettext:c-format */
2450 (_("%B: '%s' accessed both as normal and"
2451 " thread local symbol"),
2453 bfd_set_error (bfd_error_bad_value
);
2458 if (old_tls_type
!= tls_type
)
2461 eh
->tls_type
= tls_type
;
2463 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
2468 case R_X86_64_GOTOFF64
:
2469 case R_X86_64_GOTPC32
:
2470 case R_X86_64_GOTPC64
:
2473 eh
->has_got_reloc
= 1;
2476 case R_X86_64_PLT32
:
2477 case R_X86_64_PLT32_BND
:
2478 /* This symbol requires a procedure linkage table entry. We
2479 actually build the entry in adjust_dynamic_symbol,
2480 because this might be a case of linking PIC code which is
2481 never referenced by a dynamic object, in which case we
2482 don't need to generate a procedure linkage table entry
2485 /* If this is a local symbol, we resolve it directly without
2486 creating a procedure linkage table entry. */
2490 eh
->has_got_reloc
= 1;
2492 h
->plt
.refcount
+= 1;
2495 case R_X86_64_PLTOFF64
:
2496 /* This tries to form the 'address' of a function relative
2497 to GOT. For global symbols we need a PLT entry. */
2501 h
->plt
.refcount
+= 1;
2505 case R_X86_64_SIZE32
:
2506 case R_X86_64_SIZE64
:
2511 if (!ABI_64_P (abfd
))
2517 /* Check relocation overflow as these relocs may lead to
2518 run-time relocation overflow. Don't error out for
2519 sections we don't care about, such as debug sections or
2520 when relocation overflow check is disabled. */
2521 if (!info
->no_reloc_overflow_check
2522 && (bfd_link_pic (info
)
2523 || (bfd_link_executable (info
)
2527 && (sec
->flags
& SEC_READONLY
) == 0)))
2528 return elf_x86_64_need_pic (abfd
, sec
, h
, symtab_hdr
, isym
,
2529 &x86_64_elf_howto_table
[r_type
]);
2535 case R_X86_64_PC32_BND
:
2539 if (eh
!= NULL
&& (sec
->flags
& SEC_CODE
) != 0)
2540 eh
->has_non_got_reloc
= 1;
2541 /* We are called after all symbols have been resolved. Only
2542 relocation against STT_GNU_IFUNC symbol must go through
2545 && (bfd_link_executable (info
)
2546 || h
->type
== STT_GNU_IFUNC
))
2548 /* If this reloc is in a read-only section, we might
2549 need a copy reloc. We can't check reliably at this
2550 stage whether the section is read-only, as input
2551 sections have not yet been mapped to output sections.
2552 Tentatively set the flag for now, and correct in
2553 adjust_dynamic_symbol. */
2556 /* We may need a .plt entry if the symbol is a function
2557 defined in a shared lib or is a STT_GNU_IFUNC function
2558 referenced from the code or read-only section. */
2560 || (sec
->flags
& (SEC_CODE
| SEC_READONLY
)) != 0)
2561 h
->plt
.refcount
+= 1;
2563 if (r_type
== R_X86_64_PC32
)
2565 /* Since something like ".long foo - ." may be used
2566 as pointer, make sure that PLT is used if foo is
2567 a function defined in a shared library. */
2568 if ((sec
->flags
& SEC_CODE
) == 0)
2569 h
->pointer_equality_needed
= 1;
2571 else if (r_type
!= R_X86_64_PC32_BND
2572 && r_type
!= R_X86_64_PC64
)
2574 h
->pointer_equality_needed
= 1;
2575 /* At run-time, R_X86_64_64 can be resolved for both
2576 x86-64 and x32. But R_X86_64_32 and R_X86_64_32S
2577 can only be resolved for x32. */
2578 if ((sec
->flags
& SEC_READONLY
) == 0
2579 && (r_type
== R_X86_64_64
2580 || (!ABI_64_P (abfd
)
2581 && (r_type
== R_X86_64_32
2582 || r_type
== R_X86_64_32S
))))
2583 eh
->func_pointer_refcount
+= 1;
2589 /* If we are creating a shared library, and this is a reloc
2590 against a global symbol, or a non PC relative reloc
2591 against a local symbol, then we need to copy the reloc
2592 into the shared library. However, if we are linking with
2593 -Bsymbolic, we do not need to copy a reloc against a
2594 global symbol which is defined in an object we are
2595 including in the link (i.e., DEF_REGULAR is set). At
2596 this point we have not seen all the input files, so it is
2597 possible that DEF_REGULAR is not set now but will be set
2598 later (it is never cleared). In case of a weak definition,
2599 DEF_REGULAR may be cleared later by a strong definition in
2600 a shared library. We account for that possibility below by
2601 storing information in the relocs_copied field of the hash
2602 table entry. A similar situation occurs when creating
2603 shared libraries and symbol visibility changes render the
2606 If on the other hand, we are creating an executable, we
2607 may need to keep relocations for symbols satisfied by a
2608 dynamic library if we manage to avoid copy relocs for the
2611 Generate dynamic pointer relocation against STT_GNU_IFUNC
2612 symbol in the non-code section. */
2613 if ((bfd_link_pic (info
)
2614 && (! IS_X86_64_PCREL_TYPE (r_type
)
2616 && (! (bfd_link_pie (info
)
2617 || SYMBOLIC_BIND (info
, h
))
2618 || h
->root
.type
== bfd_link_hash_defweak
2619 || !h
->def_regular
))))
2621 && h
->type
== STT_GNU_IFUNC
2622 && r_type
== htab
->pointer_r_type
2623 && (sec
->flags
& SEC_CODE
) == 0)
2624 || (ELIMINATE_COPY_RELOCS
2625 && !bfd_link_pic (info
)
2627 && (h
->root
.type
== bfd_link_hash_defweak
2628 || !h
->def_regular
)))
2630 struct elf_dyn_relocs
*p
;
2631 struct elf_dyn_relocs
**head
;
2633 /* We must copy these reloc types into the output file.
2634 Create a reloc section in dynobj and make room for
2638 sreloc
= _bfd_elf_make_dynamic_reloc_section
2639 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
2640 abfd
, /*rela?*/ TRUE
);
2646 /* If this is a global symbol, we count the number of
2647 relocations we need for this symbol. */
2649 head
= &eh
->dyn_relocs
;
2652 /* Track dynamic relocs needed for local syms too.
2653 We really need local syms available to do this
2658 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2663 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2667 /* Beware of type punned pointers vs strict aliasing
2669 vpp
= &(elf_section_data (s
)->local_dynrel
);
2670 head
= (struct elf_dyn_relocs
**)vpp
;
2674 if (p
== NULL
|| p
->sec
!= sec
)
2676 bfd_size_type amt
= sizeof *p
;
2678 p
= ((struct elf_dyn_relocs
*)
2679 bfd_alloc (htab
->elf
.dynobj
, amt
));
2690 /* Count size relocation as PC-relative relocation. */
2691 if (IS_X86_64_PCREL_TYPE (r_type
) || size_reloc
)
2696 /* This relocation describes the C++ object vtable hierarchy.
2697 Reconstruct it for later use during GC. */
2698 case R_X86_64_GNU_VTINHERIT
:
2699 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2703 /* This relocation describes which C++ vtable entries are actually
2704 used. Record for later use during GC. */
2705 case R_X86_64_GNU_VTENTRY
:
2706 BFD_ASSERT (h
!= NULL
);
2708 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2716 if ((r_type
== R_X86_64_GOTPCREL
2717 || r_type
== R_X86_64_GOTPCRELX
2718 || r_type
== R_X86_64_REX_GOTPCRELX
)
2719 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2720 sec
->need_convert_load
= 1;
2723 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2725 if (!info
->keep_memory
)
2729 /* Cache the section contents for elf_link_input_bfd. */
2730 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2737 if (elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2739 sec
->check_relocs_failed
= 1;
2743 /* Return the section that should be marked against GC for a given
2747 elf_x86_64_gc_mark_hook (asection
*sec
,
2748 struct bfd_link_info
*info
,
2749 Elf_Internal_Rela
*rel
,
2750 struct elf_link_hash_entry
*h
,
2751 Elf_Internal_Sym
*sym
)
2754 switch (ELF32_R_TYPE (rel
->r_info
))
2756 case R_X86_64_GNU_VTINHERIT
:
2757 case R_X86_64_GNU_VTENTRY
:
2761 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2764 /* Remove undefined weak symbol from the dynamic symbol table if it
2765 is resolved to 0. */
2768 elf_x86_64_fixup_symbol (struct bfd_link_info
*info
,
2769 struct elf_link_hash_entry
*h
)
2771 if (h
->dynindx
!= -1
2772 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
2773 elf_x86_64_hash_entry (h
)->has_got_reloc
,
2774 elf_x86_64_hash_entry (h
)))
2777 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2783 /* Adjust a symbol defined by a dynamic object and referenced by a
2784 regular object. The current definition is in some section of the
2785 dynamic object, but we're not including those sections. We have to
2786 change the definition to something the rest of the link can
2790 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2791 struct elf_link_hash_entry
*h
)
2793 struct elf_x86_64_link_hash_table
*htab
;
2795 struct elf_x86_64_link_hash_entry
*eh
;
2796 struct elf_dyn_relocs
*p
;
2798 /* STT_GNU_IFUNC symbol must go through PLT. */
2799 if (h
->type
== STT_GNU_IFUNC
)
2801 /* All local STT_GNU_IFUNC references must be treate as local
2802 calls via local PLT. */
2804 && SYMBOL_CALLS_LOCAL (info
, h
))
2806 bfd_size_type pc_count
= 0, count
= 0;
2807 struct elf_dyn_relocs
**pp
;
2809 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2810 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2812 pc_count
+= p
->pc_count
;
2813 p
->count
-= p
->pc_count
;
2822 if (pc_count
|| count
)
2827 /* Increment PLT reference count only for PC-relative
2830 if (h
->plt
.refcount
<= 0)
2831 h
->plt
.refcount
= 1;
2833 h
->plt
.refcount
+= 1;
2838 if (h
->plt
.refcount
<= 0)
2840 h
->plt
.offset
= (bfd_vma
) -1;
2846 /* If this is a function, put it in the procedure linkage table. We
2847 will fill in the contents of the procedure linkage table later,
2848 when we know the address of the .got section. */
2849 if (h
->type
== STT_FUNC
2852 if (h
->plt
.refcount
<= 0
2853 || SYMBOL_CALLS_LOCAL (info
, h
)
2854 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2855 && h
->root
.type
== bfd_link_hash_undefweak
))
2857 /* This case can occur if we saw a PLT32 reloc in an input
2858 file, but the symbol was never referred to by a dynamic
2859 object, or if all references were garbage collected. In
2860 such a case, we don't actually need to build a procedure
2861 linkage table, and we can just do a PC32 reloc instead. */
2862 h
->plt
.offset
= (bfd_vma
) -1;
2869 /* It's possible that we incorrectly decided a .plt reloc was
2870 needed for an R_X86_64_PC32 reloc to a non-function sym in
2871 check_relocs. We can't decide accurately between function and
2872 non-function syms in check-relocs; Objects loaded later in
2873 the link may change h->type. So fix it now. */
2874 h
->plt
.offset
= (bfd_vma
) -1;
2876 /* If this is a weak symbol, and there is a real definition, the
2877 processor independent code will have arranged for us to see the
2878 real definition first, and we can just use the same value. */
2879 if (h
->u
.weakdef
!= NULL
)
2881 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2882 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2883 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2884 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2885 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2887 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2888 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2889 eh
->needs_copy
= h
->u
.weakdef
->needs_copy
;
2894 /* This is a reference to a symbol defined by a dynamic object which
2895 is not a function. */
2897 /* If we are creating a shared library, we must presume that the
2898 only references to the symbol are via the global offset table.
2899 For such cases we need not do anything here; the relocations will
2900 be handled correctly by relocate_section. */
2901 if (!bfd_link_executable (info
))
2904 /* If there are no references to this symbol that do not use the
2905 GOT, we don't need to generate a copy reloc. */
2906 if (!h
->non_got_ref
)
2909 /* If -z nocopyreloc was given, we won't generate them either. */
2910 if (info
->nocopyreloc
)
2916 if (ELIMINATE_COPY_RELOCS
)
2918 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2919 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2921 s
= p
->sec
->output_section
;
2922 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2926 /* If we didn't find any dynamic relocs in read-only sections, then
2927 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2935 /* We must allocate the symbol in our .dynbss section, which will
2936 become part of the .bss section of the executable. There will be
2937 an entry for this symbol in the .dynsym section. The dynamic
2938 object will contain position independent code, so all references
2939 from the dynamic object to this symbol will go through the global
2940 offset table. The dynamic linker will use the .dynsym entry to
2941 determine the address it must put in the global offset table, so
2942 both the dynamic object and the regular object will refer to the
2943 same memory location for the variable. */
2945 htab
= elf_x86_64_hash_table (info
);
2949 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2950 to copy the initial value out of the dynamic object and into the
2951 runtime process image. */
2952 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2954 s
= htab
->elf
.sdynrelro
;
2955 srel
= htab
->elf
.sreldynrelro
;
2959 s
= htab
->elf
.sdynbss
;
2960 srel
= htab
->elf
.srelbss
;
2962 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2964 const struct elf_backend_data
*bed
;
2965 bed
= get_elf_backend_data (info
->output_bfd
);
2966 srel
->size
+= bed
->s
->sizeof_rela
;
2970 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2973 /* Allocate space in .plt, .got and associated reloc sections for
2977 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2979 struct bfd_link_info
*info
;
2980 struct elf_x86_64_link_hash_table
*htab
;
2981 struct elf_x86_64_link_hash_entry
*eh
;
2982 struct elf_dyn_relocs
*p
;
2983 const struct elf_backend_data
*bed
;
2984 unsigned int plt_entry_size
;
2985 bfd_boolean resolved_to_zero
;
2987 if (h
->root
.type
== bfd_link_hash_indirect
)
2990 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2992 info
= (struct bfd_link_info
*) inf
;
2993 htab
= elf_x86_64_hash_table (info
);
2996 bed
= get_elf_backend_data (info
->output_bfd
);
2997 plt_entry_size
= htab
->plt
.plt_entry_size
;
2999 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
3003 /* We can't use the GOT PLT if pointer equality is needed since
3004 finish_dynamic_symbol won't clear symbol value and the dynamic
3005 linker won't update the GOT slot. We will get into an infinite
3006 loop at run-time. */
3007 if (htab
->plt_got
!= NULL
3008 && h
->type
!= STT_GNU_IFUNC
3009 && !h
->pointer_equality_needed
3010 && h
->plt
.refcount
> 0
3011 && h
->got
.refcount
> 0)
3013 /* Don't use the regular PLT if there are both GOT and GOTPLT
3015 h
->plt
.offset
= (bfd_vma
) -1;
3017 /* Use the GOT PLT. */
3018 eh
->plt_got
.refcount
= 1;
3021 /* Clear the reference count of function pointer relocations if
3022 symbol isn't a normal function. */
3023 if (h
->type
!= STT_FUNC
)
3024 eh
->func_pointer_refcount
= 0;
3026 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
3027 here if it is defined and referenced in a non-shared object. */
3028 if (h
->type
== STT_GNU_IFUNC
3031 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
3033 &htab
->readonly_dynrelocs_against_ifunc
,
3037 GOT_ENTRY_SIZE
, TRUE
))
3039 asection
*s
= htab
->plt_bnd
;
3040 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
3042 /* Use the .plt.bnd section if it is created. */
3043 eh
->plt_bnd
.offset
= s
->size
;
3045 /* Make room for this entry in the .plt.bnd section. */
3046 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3054 /* Don't create the PLT entry if there are only function pointer
3055 relocations which can be resolved at run-time. */
3056 else if (htab
->elf
.dynamic_sections_created
3057 && (h
->plt
.refcount
> eh
->func_pointer_refcount
3058 || eh
->plt_got
.refcount
> 0))
3060 bfd_boolean use_plt_got
;
3062 /* Clear the reference count of function pointer relocations
3064 eh
->func_pointer_refcount
= 0;
3066 if (htab
->plt_got
!= NULL
3067 && (info
->flags
& DF_BIND_NOW
)
3068 && !h
->pointer_equality_needed
)
3070 /* Don't use the regular PLT for DF_BIND_NOW. */
3071 h
->plt
.offset
= (bfd_vma
) -1;
3073 /* Use the GOT PLT. */
3074 h
->got
.refcount
= 1;
3075 eh
->plt_got
.refcount
= 1;
3078 use_plt_got
= eh
->plt_got
.refcount
> 0;
3080 /* Make sure this symbol is output as a dynamic symbol.
3081 Undefined weak syms won't yet be marked as dynamic. */
3082 if (h
->dynindx
== -1
3084 && !resolved_to_zero
3085 && h
->root
.type
== bfd_link_hash_undefweak
)
3087 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3091 if (bfd_link_pic (info
)
3092 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3094 asection
*s
= htab
->elf
.splt
;
3095 asection
*bnd_s
= htab
->plt_bnd
;
3096 asection
*got_s
= htab
->plt_got
;
3098 /* If this is the first .plt entry, make room for the special
3099 first entry. The .plt section is used by prelink to undo
3100 prelinking for dynamic relocations. */
3102 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
3105 eh
->plt_got
.offset
= got_s
->size
;
3108 h
->plt
.offset
= s
->size
;
3110 eh
->plt_bnd
.offset
= bnd_s
->size
;
3113 /* If this symbol is not defined in a regular file, and we are
3114 not generating a shared library, then set the symbol to this
3115 location in the .plt. This is required to make function
3116 pointers compare as equal between the normal executable and
3117 the shared library. */
3118 if (! bfd_link_pic (info
)
3123 /* We need to make a call to the entry of the GOT PLT
3124 instead of regular PLT entry. */
3125 h
->root
.u
.def
.section
= got_s
;
3126 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
3132 /* We need to make a call to the entry of the second
3133 PLT instead of regular PLT entry. */
3134 h
->root
.u
.def
.section
= bnd_s
;
3135 h
->root
.u
.def
.value
= eh
->plt_bnd
.offset
;
3139 h
->root
.u
.def
.section
= s
;
3140 h
->root
.u
.def
.value
= h
->plt
.offset
;
3145 /* Make room for this entry. */
3147 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3150 s
->size
+= plt_entry_size
;
3152 bnd_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
3154 /* We also need to make an entry in the .got.plt section,
3155 which will be placed in the .got section by the linker
3157 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
3159 /* There should be no PLT relocation against resolved
3160 undefined weak symbol in executable. */
3161 if (!resolved_to_zero
)
3163 /* We also need to make an entry in the .rela.plt
3165 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3166 htab
->elf
.srelplt
->reloc_count
++;
3172 eh
->plt_got
.offset
= (bfd_vma
) -1;
3173 h
->plt
.offset
= (bfd_vma
) -1;
3179 eh
->plt_got
.offset
= (bfd_vma
) -1;
3180 h
->plt
.offset
= (bfd_vma
) -1;
3184 eh
->tlsdesc_got
= (bfd_vma
) -1;
3186 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
3187 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
3188 if (h
->got
.refcount
> 0
3189 && bfd_link_executable (info
)
3191 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
3193 h
->got
.offset
= (bfd_vma
) -1;
3195 else if (h
->got
.refcount
> 0)
3199 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3201 /* Make sure this symbol is output as a dynamic symbol.
3202 Undefined weak syms won't yet be marked as dynamic. */
3203 if (h
->dynindx
== -1
3205 && !resolved_to_zero
3206 && h
->root
.type
== bfd_link_hash_undefweak
)
3208 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3212 if (GOT_TLS_GDESC_P (tls_type
))
3214 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
3215 - elf_x86_64_compute_jump_table_size (htab
);
3216 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3217 h
->got
.offset
= (bfd_vma
) -2;
3219 if (! GOT_TLS_GDESC_P (tls_type
)
3220 || GOT_TLS_GD_P (tls_type
))
3223 h
->got
.offset
= s
->size
;
3224 s
->size
+= GOT_ENTRY_SIZE
;
3225 if (GOT_TLS_GD_P (tls_type
))
3226 s
->size
+= GOT_ENTRY_SIZE
;
3228 dyn
= htab
->elf
.dynamic_sections_created
;
3229 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
3230 and two if global. R_X86_64_GOTTPOFF needs one dynamic
3231 relocation. No dynamic relocation against resolved undefined
3232 weak symbol in executable. */
3233 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
3234 || tls_type
== GOT_TLS_IE
)
3235 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3236 else if (GOT_TLS_GD_P (tls_type
))
3237 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
3238 else if (! GOT_TLS_GDESC_P (tls_type
)
3239 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3240 && !resolved_to_zero
)
3241 || h
->root
.type
!= bfd_link_hash_undefweak
)
3242 && (bfd_link_pic (info
)
3243 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3244 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3245 if (GOT_TLS_GDESC_P (tls_type
))
3247 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
3248 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3252 h
->got
.offset
= (bfd_vma
) -1;
3254 if (eh
->dyn_relocs
== NULL
)
3257 /* In the shared -Bsymbolic case, discard space allocated for
3258 dynamic pc-relative relocs against symbols which turn out to be
3259 defined in regular objects. For the normal shared case, discard
3260 space for pc-relative relocs that have become local due to symbol
3261 visibility changes. */
3263 if (bfd_link_pic (info
))
3265 /* Relocs that use pc_count are those that appear on a call
3266 insn, or certain REL relocs that can generated via assembly.
3267 We want calls to protected symbols to resolve directly to the
3268 function rather than going via the plt. If people want
3269 function pointer comparisons to work as expected then they
3270 should avoid writing weird assembly. */
3271 if (SYMBOL_CALLS_LOCAL (info
, h
))
3273 struct elf_dyn_relocs
**pp
;
3275 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3277 p
->count
-= p
->pc_count
;
3286 /* Also discard relocs on undefined weak syms with non-default
3287 visibility or in PIE. */
3288 if (eh
->dyn_relocs
!= NULL
)
3290 if (h
->root
.type
== bfd_link_hash_undefweak
)
3292 /* Undefined weak symbol is never bound locally in shared
3294 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3295 || resolved_to_zero
)
3296 eh
->dyn_relocs
= NULL
;
3297 else if (h
->dynindx
== -1
3298 && ! h
->forced_local
3299 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3302 /* For PIE, discard space for pc-relative relocs against
3303 symbols which turn out to need copy relocs. */
3304 else if (bfd_link_executable (info
)
3305 && (h
->needs_copy
|| eh
->needs_copy
)
3309 struct elf_dyn_relocs
**pp
;
3311 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3313 if (p
->pc_count
!= 0)
3321 else if (ELIMINATE_COPY_RELOCS
)
3323 /* For the non-shared case, discard space for relocs against
3324 symbols which turn out to need copy relocs or are not
3325 dynamic. Keep dynamic relocations for run-time function
3326 pointer initialization. */
3328 if ((!h
->non_got_ref
3329 || eh
->func_pointer_refcount
> 0
3330 || (h
->root
.type
== bfd_link_hash_undefweak
3331 && !resolved_to_zero
))
3334 || (htab
->elf
.dynamic_sections_created
3335 && (h
->root
.type
== bfd_link_hash_undefweak
3336 || h
->root
.type
== bfd_link_hash_undefined
))))
3338 /* Make sure this symbol is output as a dynamic symbol.
3339 Undefined weak syms won't yet be marked as dynamic. */
3340 if (h
->dynindx
== -1
3341 && ! h
->forced_local
3342 && ! resolved_to_zero
3343 && h
->root
.type
== bfd_link_hash_undefweak
3344 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3347 /* If that succeeded, we know we'll be keeping all the
3349 if (h
->dynindx
!= -1)
3353 eh
->dyn_relocs
= NULL
;
3354 eh
->func_pointer_refcount
= 0;
3359 /* Finally, allocate space. */
3360 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3364 sreloc
= elf_section_data (p
->sec
)->sreloc
;
3366 BFD_ASSERT (sreloc
!= NULL
);
3368 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3374 /* Allocate space in .plt, .got and associated reloc sections for
3375 local dynamic relocs. */
3378 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
3380 struct elf_link_hash_entry
*h
3381 = (struct elf_link_hash_entry
*) *slot
;
3383 if (h
->type
!= STT_GNU_IFUNC
3387 || h
->root
.type
!= bfd_link_hash_defined
)
3390 return elf_x86_64_allocate_dynrelocs (h
, inf
);
3393 /* Find any dynamic relocs that apply to read-only sections. */
3396 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
3399 struct elf_x86_64_link_hash_entry
*eh
;
3400 struct elf_dyn_relocs
*p
;
3402 /* Skip local IFUNC symbols. */
3403 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
3406 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
3407 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3409 asection
*s
= p
->sec
->output_section
;
3411 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3413 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3415 info
->flags
|= DF_TEXTREL
;
3417 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3418 || info
->error_textrel
)
3419 /* xgettext:c-format */
3420 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
3421 p
->sec
->owner
, h
->root
.root
.string
,
3424 /* Not an error, just cut short the traversal. */
3431 /* Convert load via the GOT slot to load immediate. */
3434 elf_x86_64_convert_load (bfd
*abfd
, asection
*sec
,
3435 struct bfd_link_info
*link_info
)
3437 Elf_Internal_Shdr
*symtab_hdr
;
3438 Elf_Internal_Rela
*internal_relocs
;
3439 Elf_Internal_Rela
*irel
, *irelend
;
3441 struct elf_x86_64_link_hash_table
*htab
;
3442 bfd_boolean changed
;
3443 bfd_signed_vma
*local_got_refcounts
;
3445 /* Don't even try to convert non-ELF outputs. */
3446 if (!is_elf_hash_table (link_info
->hash
))
3449 /* Nothing to do if there is no need or no output. */
3450 if ((sec
->flags
& (SEC_CODE
| SEC_RELOC
)) != (SEC_CODE
| SEC_RELOC
)
3451 || sec
->need_convert_load
== 0
3452 || bfd_is_abs_section (sec
->output_section
))
3455 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3457 /* Load the relocations for this section. */
3458 internal_relocs
= (_bfd_elf_link_read_relocs
3459 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
3460 link_info
->keep_memory
));
3461 if (internal_relocs
== NULL
)
3465 htab
= elf_x86_64_hash_table (link_info
);
3466 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3468 /* Get the section contents. */
3469 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3470 contents
= elf_section_data (sec
)->this_hdr
.contents
;
3473 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
3477 irelend
= internal_relocs
+ sec
->reloc_count
;
3478 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3480 unsigned int r_type
= ELF32_R_TYPE (irel
->r_info
);
3481 unsigned int r_symndx
;
3482 struct elf_link_hash_entry
*h
;
3483 bfd_boolean converted
;
3485 if (r_type
!= R_X86_64_GOTPCRELX
3486 && r_type
!= R_X86_64_REX_GOTPCRELX
3487 && r_type
!= R_X86_64_GOTPCREL
)
3490 r_symndx
= htab
->r_sym (irel
->r_info
);
3491 if (r_symndx
< symtab_hdr
->sh_info
)
3492 h
= elf_x86_64_get_local_sym_hash (htab
, sec
->owner
,
3493 (const Elf_Internal_Rela
*) irel
,
3497 h
= elf_sym_hashes (abfd
)[r_symndx
- symtab_hdr
->sh_info
];
3498 while (h
->root
.type
== bfd_link_hash_indirect
3499 || h
->root
.type
== bfd_link_hash_warning
)
3500 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3503 /* STT_GNU_IFUNC must keep GOTPCREL relocations. */
3504 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3508 if (!elf_x86_64_convert_load_reloc (abfd
, sec
, contents
, irel
, h
,
3509 &converted
, link_info
))
3514 changed
= converted
;
3517 if (h
->got
.refcount
> 0)
3518 h
->got
.refcount
-= 1;
3522 if (local_got_refcounts
!= NULL
3523 && local_got_refcounts
[r_symndx
] > 0)
3524 local_got_refcounts
[r_symndx
] -= 1;
3529 if (contents
!= NULL
3530 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3532 if (!changed
&& !link_info
->keep_memory
)
3536 /* Cache the section contents for elf_link_input_bfd. */
3537 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3541 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3544 free (internal_relocs
);
3546 elf_section_data (sec
)->relocs
= internal_relocs
;
3552 if (contents
!= NULL
3553 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3555 if (internal_relocs
!= NULL
3556 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3557 free (internal_relocs
);
3561 /* Set the sizes of the dynamic sections. */
3564 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
3565 struct bfd_link_info
*info
)
3567 struct elf_x86_64_link_hash_table
*htab
;
3572 const struct elf_backend_data
*bed
;
3574 htab
= elf_x86_64_hash_table (info
);
3577 bed
= get_elf_backend_data (output_bfd
);
3579 dynobj
= htab
->elf
.dynobj
;
3583 /* Set up .got offsets for local syms, and space for local dynamic
3585 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3587 bfd_signed_vma
*local_got
;
3588 bfd_signed_vma
*end_local_got
;
3589 char *local_tls_type
;
3590 bfd_vma
*local_tlsdesc_gotent
;
3591 bfd_size_type locsymcount
;
3592 Elf_Internal_Shdr
*symtab_hdr
;
3595 if (! is_x86_64_elf (ibfd
))
3598 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3600 struct elf_dyn_relocs
*p
;
3602 if (!elf_x86_64_convert_load (ibfd
, s
, info
))
3605 for (p
= (struct elf_dyn_relocs
*)
3606 (elf_section_data (s
)->local_dynrel
);
3610 if (!bfd_is_abs_section (p
->sec
)
3611 && bfd_is_abs_section (p
->sec
->output_section
))
3613 /* Input section has been discarded, either because
3614 it is a copy of a linkonce section or due to
3615 linker script /DISCARD/, so we'll be discarding
3618 else if (p
->count
!= 0)
3620 srel
= elf_section_data (p
->sec
)->sreloc
;
3621 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
3622 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
3623 && (info
->flags
& DF_TEXTREL
) == 0)
3625 info
->flags
|= DF_TEXTREL
;
3626 if ((info
->warn_shared_textrel
&& bfd_link_pic (info
))
3627 || info
->error_textrel
)
3628 /* xgettext:c-format */
3629 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
3630 p
->sec
->owner
, p
->sec
);
3636 local_got
= elf_local_got_refcounts (ibfd
);
3640 symtab_hdr
= &elf_symtab_hdr (ibfd
);
3641 locsymcount
= symtab_hdr
->sh_info
;
3642 end_local_got
= local_got
+ locsymcount
;
3643 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
3644 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
3646 srel
= htab
->elf
.srelgot
;
3647 for (; local_got
< end_local_got
;
3648 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
3650 *local_tlsdesc_gotent
= (bfd_vma
) -1;
3653 if (GOT_TLS_GDESC_P (*local_tls_type
))
3655 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
3656 - elf_x86_64_compute_jump_table_size (htab
);
3657 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
3658 *local_got
= (bfd_vma
) -2;
3660 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3661 || GOT_TLS_GD_P (*local_tls_type
))
3663 *local_got
= s
->size
;
3664 s
->size
+= GOT_ENTRY_SIZE
;
3665 if (GOT_TLS_GD_P (*local_tls_type
))
3666 s
->size
+= GOT_ENTRY_SIZE
;
3668 if (bfd_link_pic (info
)
3669 || GOT_TLS_GD_ANY_P (*local_tls_type
)
3670 || *local_tls_type
== GOT_TLS_IE
)
3672 if (GOT_TLS_GDESC_P (*local_tls_type
))
3674 htab
->elf
.srelplt
->size
3675 += bed
->s
->sizeof_rela
;
3676 htab
->tlsdesc_plt
= (bfd_vma
) -1;
3678 if (! GOT_TLS_GDESC_P (*local_tls_type
)
3679 || GOT_TLS_GD_P (*local_tls_type
))
3680 srel
->size
+= bed
->s
->sizeof_rela
;
3684 *local_got
= (bfd_vma
) -1;
3688 if (htab
->tls_ld_got
.refcount
> 0)
3690 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
3692 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
3693 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
3694 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
3697 htab
->tls_ld_got
.offset
= -1;
3699 /* Allocate global sym .plt and .got entries, and space for global
3700 sym dynamic relocs. */
3701 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
3704 /* Allocate .plt and .got entries, and space for local symbols. */
3705 htab_traverse (htab
->loc_hash_table
,
3706 elf_x86_64_allocate_local_dynrelocs
,
3709 /* For every jump slot reserved in the sgotplt, reloc_count is
3710 incremented. However, when we reserve space for TLS descriptors,
3711 it's not incremented, so in order to compute the space reserved
3712 for them, it suffices to multiply the reloc count by the jump
3715 PR ld/13302: We start next_irelative_index at the end of .rela.plt
3716 so that R_X86_64_IRELATIVE entries come last. */
3717 if (htab
->elf
.srelplt
)
3719 htab
->sgotplt_jump_table_size
3720 = elf_x86_64_compute_jump_table_size (htab
);
3721 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
3723 else if (htab
->elf
.irelplt
)
3724 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
3726 if (htab
->tlsdesc_plt
)
3728 /* If we're not using lazy TLS relocations, don't generate the
3729 PLT and GOT entries they require. */
3730 if ((info
->flags
& DF_BIND_NOW
))
3731 htab
->tlsdesc_plt
= 0;
3734 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
3735 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
3736 /* Reserve room for the initial entry.
3737 FIXME: we could probably do away with it in this case. */
3738 if (htab
->elf
.splt
->size
== 0)
3739 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
3740 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
3741 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
3745 if (htab
->elf
.sgotplt
)
3747 /* Don't allocate .got.plt section if there are no GOT nor PLT
3748 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
3749 if ((htab
->elf
.hgot
== NULL
3750 || !htab
->elf
.hgot
->ref_regular_nonweak
)
3751 && (htab
->elf
.sgotplt
->size
3752 == get_elf_backend_data (output_bfd
)->got_header_size
)
3753 && (htab
->elf
.splt
== NULL
3754 || htab
->elf
.splt
->size
== 0)
3755 && (htab
->elf
.sgot
== NULL
3756 || htab
->elf
.sgot
->size
== 0)
3757 && (htab
->elf
.iplt
== NULL
3758 || htab
->elf
.iplt
->size
== 0)
3759 && (htab
->elf
.igotplt
== NULL
3760 || htab
->elf
.igotplt
->size
== 0))
3761 htab
->elf
.sgotplt
->size
= 0;
3764 if (_bfd_elf_eh_frame_present (info
))
3766 if (htab
->plt_eh_frame
!= NULL
3767 && htab
->elf
.splt
!= NULL
3768 && htab
->elf
.splt
->size
!= 0
3769 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
3770 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
3772 if (htab
->plt_got_eh_frame
!= NULL
3773 && htab
->plt_got
!= NULL
3774 && htab
->plt_got
->size
!= 0
3775 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
3776 htab
->plt_got_eh_frame
->size
3777 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3779 /* Unwind info for .plt.bnd and .plt.got sections are
3781 if (htab
->plt_bnd_eh_frame
!= NULL
3782 && htab
->plt_bnd
!= NULL
3783 && htab
->plt_bnd
->size
!= 0
3784 && !bfd_is_abs_section (htab
->plt_bnd
->output_section
))
3785 htab
->plt_bnd_eh_frame
->size
3786 = htab
->non_lazy_plt
->eh_frame_plt_size
;
3789 /* We now have determined the sizes of the various dynamic sections.
3790 Allocate memory for them. */
3792 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3794 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3797 if (s
== htab
->elf
.splt
3798 || s
== htab
->elf
.sgot
3799 || s
== htab
->elf
.sgotplt
3800 || s
== htab
->elf
.iplt
3801 || s
== htab
->elf
.igotplt
3802 || s
== htab
->plt_bnd
3803 || s
== htab
->plt_got
3804 || s
== htab
->plt_eh_frame
3805 || s
== htab
->plt_got_eh_frame
3806 || s
== htab
->plt_bnd_eh_frame
3807 || s
== htab
->elf
.sdynbss
3808 || s
== htab
->elf
.sdynrelro
)
3810 /* Strip this section if we don't need it; see the
3813 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
3815 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
3818 /* We use the reloc_count field as a counter if we need
3819 to copy relocs into the output file. */
3820 if (s
!= htab
->elf
.srelplt
)
3825 /* It's not one of our sections, so don't allocate space. */
3831 /* If we don't need this section, strip it from the
3832 output file. This is mostly to handle .rela.bss and
3833 .rela.plt. We must create both sections in
3834 create_dynamic_sections, because they must be created
3835 before the linker maps input sections to output
3836 sections. The linker does that before
3837 adjust_dynamic_symbol is called, and it is that
3838 function which decides whether anything needs to go
3839 into these sections. */
3841 s
->flags
|= SEC_EXCLUDE
;
3845 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3848 /* Allocate memory for the section contents. We use bfd_zalloc
3849 here in case unused entries are not reclaimed before the
3850 section's contents are written out. This should not happen,
3851 but this way if it does, we get a R_X86_64_NONE reloc instead
3853 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3854 if (s
->contents
== NULL
)
3858 if (htab
->plt_eh_frame
!= NULL
3859 && htab
->plt_eh_frame
->contents
!= NULL
)
3861 memcpy (htab
->plt_eh_frame
->contents
,
3862 htab
->plt
.eh_frame_plt
, htab
->plt_eh_frame
->size
);
3863 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
3864 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
3867 if (htab
->plt_got_eh_frame
!= NULL
3868 && htab
->plt_got_eh_frame
->contents
!= NULL
)
3870 memcpy (htab
->plt_got_eh_frame
->contents
,
3871 htab
->non_lazy_plt
->eh_frame_plt
,
3872 htab
->plt_got_eh_frame
->size
);
3873 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
3874 (htab
->plt_got_eh_frame
->contents
3875 + PLT_FDE_LEN_OFFSET
));
3878 if (htab
->plt_bnd_eh_frame
!= NULL
3879 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
3881 memcpy (htab
->plt_bnd_eh_frame
->contents
,
3882 htab
->non_lazy_plt
->eh_frame_plt
,
3883 htab
->plt_bnd_eh_frame
->size
);
3884 bfd_put_32 (dynobj
, htab
->plt_bnd
->size
,
3885 (htab
->plt_bnd_eh_frame
->contents
3886 + PLT_FDE_LEN_OFFSET
));
3889 if (htab
->elf
.dynamic_sections_created
)
3891 /* Add some entries to the .dynamic section. We fill in the
3892 values later, in elf_x86_64_finish_dynamic_sections, but we
3893 must add the entries now so that we get the correct size for
3894 the .dynamic section. The DT_DEBUG entry is filled in by the
3895 dynamic linker and used by the debugger. */
3896 #define add_dynamic_entry(TAG, VAL) \
3897 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3899 if (bfd_link_executable (info
))
3901 if (!add_dynamic_entry (DT_DEBUG
, 0))
3905 if (htab
->elf
.splt
->size
!= 0)
3907 /* DT_PLTGOT is used by prelink even if there is no PLT
3909 if (!add_dynamic_entry (DT_PLTGOT
, 0))
3913 if (htab
->elf
.srelplt
->size
!= 0)
3915 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
3916 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3917 || !add_dynamic_entry (DT_JMPREL
, 0))
3921 if (htab
->tlsdesc_plt
3922 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
3923 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
3928 if (!add_dynamic_entry (DT_RELA
, 0)
3929 || !add_dynamic_entry (DT_RELASZ
, 0)
3930 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
3933 /* If any dynamic relocs apply to a read-only section,
3934 then we need a DT_TEXTREL entry. */
3935 if ((info
->flags
& DF_TEXTREL
) == 0)
3936 elf_link_hash_traverse (&htab
->elf
,
3937 elf_x86_64_readonly_dynrelocs
,
3940 if ((info
->flags
& DF_TEXTREL
) != 0)
3942 if (htab
->readonly_dynrelocs_against_ifunc
)
3944 info
->callbacks
->einfo
3945 (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
3946 bfd_set_error (bfd_error_bad_value
);
3950 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3955 #undef add_dynamic_entry
3961 elf_x86_64_always_size_sections (bfd
*output_bfd
,
3962 struct bfd_link_info
*info
)
3964 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3968 struct elf_link_hash_entry
*tlsbase
;
3970 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3971 "_TLS_MODULE_BASE_",
3972 FALSE
, FALSE
, FALSE
);
3974 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3976 struct elf_x86_64_link_hash_table
*htab
;
3977 struct bfd_link_hash_entry
*bh
= NULL
;
3978 const struct elf_backend_data
*bed
3979 = get_elf_backend_data (output_bfd
);
3981 htab
= elf_x86_64_hash_table (info
);
3985 if (!(_bfd_generic_link_add_one_symbol
3986 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3987 tls_sec
, 0, NULL
, FALSE
,
3988 bed
->collect
, &bh
)))
3991 htab
->tls_module_base
= bh
;
3993 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3994 tlsbase
->def_regular
= 1;
3995 tlsbase
->other
= STV_HIDDEN
;
3996 tlsbase
->root
.linker_def
= 1;
3997 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
4004 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
4005 executables. Rather than setting it to the beginning of the TLS
4006 section, we have to set it to the end. This function may be called
4007 multiple times, it is idempotent. */
4010 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
4012 struct elf_x86_64_link_hash_table
*htab
;
4013 struct bfd_link_hash_entry
*base
;
4015 if (!bfd_link_executable (info
))
4018 htab
= elf_x86_64_hash_table (info
);
4022 base
= htab
->tls_module_base
;
4026 base
->u
.def
.value
= htab
->elf
.tls_size
;
4029 /* Return the base VMA address which should be subtracted from real addresses
4030 when resolving @dtpoff relocation.
4031 This is PT_TLS segment p_vaddr. */
4034 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
4036 /* If tls_sec is NULL, we should have signalled an error already. */
4037 if (elf_hash_table (info
)->tls_sec
== NULL
)
4039 return elf_hash_table (info
)->tls_sec
->vma
;
4042 /* Return the relocation value for @tpoff relocation
4043 if STT_TLS virtual address is ADDRESS. */
4046 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4048 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4049 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
4050 bfd_vma static_tls_size
;
4052 /* If tls_segment is NULL, we should have signalled an error already. */
4053 if (htab
->tls_sec
== NULL
)
4056 /* Consider special static TLS alignment requirements. */
4057 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
4058 return address
- static_tls_size
- htab
->tls_sec
->vma
;
4061 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
4065 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
4067 /* Opcode Instruction
4070 0x0f 0x8x conditional jump */
4072 && (contents
[offset
- 1] == 0xe8
4073 || contents
[offset
- 1] == 0xe9))
4075 && contents
[offset
- 2] == 0x0f
4076 && (contents
[offset
- 1] & 0xf0) == 0x80));
4079 /* Relocate an x86_64 ELF section. */
4082 elf_x86_64_relocate_section (bfd
*output_bfd
,
4083 struct bfd_link_info
*info
,
4085 asection
*input_section
,
4087 Elf_Internal_Rela
*relocs
,
4088 Elf_Internal_Sym
*local_syms
,
4089 asection
**local_sections
)
4091 struct elf_x86_64_link_hash_table
*htab
;
4092 Elf_Internal_Shdr
*symtab_hdr
;
4093 struct elf_link_hash_entry
**sym_hashes
;
4094 bfd_vma
*local_got_offsets
;
4095 bfd_vma
*local_tlsdesc_gotents
;
4096 Elf_Internal_Rela
*rel
;
4097 Elf_Internal_Rela
*wrel
;
4098 Elf_Internal_Rela
*relend
;
4099 unsigned int plt_entry_size
;
4101 BFD_ASSERT (is_x86_64_elf (input_bfd
));
4103 /* Skip if check_relocs failed. */
4104 if (input_section
->check_relocs_failed
)
4107 htab
= elf_x86_64_hash_table (info
);
4110 plt_entry_size
= htab
->plt
.plt_entry_size
;
4111 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4112 sym_hashes
= elf_sym_hashes (input_bfd
);
4113 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4114 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
4116 elf_x86_64_set_tls_module_base (info
);
4118 rel
= wrel
= relocs
;
4119 relend
= relocs
+ input_section
->reloc_count
;
4120 for (; rel
< relend
; wrel
++, rel
++)
4122 unsigned int r_type
;
4123 reloc_howto_type
*howto
;
4124 unsigned long r_symndx
;
4125 struct elf_link_hash_entry
*h
;
4126 struct elf_x86_64_link_hash_entry
*eh
;
4127 Elf_Internal_Sym
*sym
;
4129 bfd_vma off
, offplt
, plt_offset
;
4131 bfd_boolean unresolved_reloc
;
4132 bfd_reloc_status_type r
;
4134 asection
*base_got
, *resolved_plt
;
4136 bfd_boolean resolved_to_zero
;
4137 bfd_boolean relative_reloc
;
4139 r_type
= ELF32_R_TYPE (rel
->r_info
);
4140 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
4141 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
4148 if (r_type
>= (int) R_X86_64_standard
)
4151 /* xgettext:c-format */
4152 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4153 input_bfd
, r_type
, input_section
);
4154 bfd_set_error (bfd_error_bad_value
);
4158 if (r_type
!= (int) R_X86_64_32
4159 || ABI_64_P (output_bfd
))
4160 howto
= x86_64_elf_howto_table
+ r_type
;
4162 howto
= (x86_64_elf_howto_table
4163 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
4164 r_symndx
= htab
->r_sym (rel
->r_info
);
4168 unresolved_reloc
= FALSE
;
4169 if (r_symndx
< symtab_hdr
->sh_info
)
4171 sym
= local_syms
+ r_symndx
;
4172 sec
= local_sections
[r_symndx
];
4174 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
4176 st_size
= sym
->st_size
;
4178 /* Relocate against local STT_GNU_IFUNC symbol. */
4179 if (!bfd_link_relocatable (info
)
4180 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4182 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
4187 /* Set STT_GNU_IFUNC symbol value. */
4188 h
->root
.u
.def
.value
= sym
->st_value
;
4189 h
->root
.u
.def
.section
= sec
;
4194 bfd_boolean warned ATTRIBUTE_UNUSED
;
4195 bfd_boolean ignored ATTRIBUTE_UNUSED
;
4197 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4198 r_symndx
, symtab_hdr
, sym_hashes
,
4200 unresolved_reloc
, warned
, ignored
);
4204 if (sec
!= NULL
&& discarded_section (sec
))
4206 _bfd_clear_contents (howto
, input_bfd
, input_section
,
4207 contents
+ rel
->r_offset
);
4208 wrel
->r_offset
= rel
->r_offset
;
4212 /* For ld -r, remove relocations in debug sections against
4213 sections defined in discarded sections. Not done for
4214 eh_frame editing code expects to be present. */
4215 if (bfd_link_relocatable (info
)
4216 && (input_section
->flags
& SEC_DEBUGGING
))
4222 if (bfd_link_relocatable (info
))
4229 if (rel
->r_addend
== 0 && !ABI_64_P (output_bfd
))
4231 if (r_type
== R_X86_64_64
)
4233 /* For x32, treat R_X86_64_64 like R_X86_64_32 and
4234 zero-extend it to 64bit if addend is zero. */
4235 r_type
= R_X86_64_32
;
4236 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4238 else if (r_type
== R_X86_64_SIZE64
)
4240 /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and
4241 zero-extend it to 64bit if addend is zero. */
4242 r_type
= R_X86_64_SIZE32
;
4243 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
4247 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
4249 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4250 it here if it is defined in a non-shared object. */
4252 && h
->type
== STT_GNU_IFUNC
4258 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4260 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4261 sections because such sections are not SEC_ALLOC and
4262 thus ld.so will not process them. */
4263 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
4273 case R_X86_64_GOTPCREL
:
4274 case R_X86_64_GOTPCRELX
:
4275 case R_X86_64_REX_GOTPCRELX
:
4276 case R_X86_64_GOTPCREL64
:
4277 base_got
= htab
->elf
.sgot
;
4278 off
= h
->got
.offset
;
4280 if (base_got
== NULL
)
4283 if (off
== (bfd_vma
) -1)
4285 /* We can't use h->got.offset here to save state, or
4286 even just remember the offset, as finish_dynamic_symbol
4287 would use that as offset into .got. */
4289 if (h
->plt
.offset
== (bfd_vma
) -1)
4292 if (htab
->elf
.splt
!= NULL
)
4294 plt_index
= (h
->plt
.offset
/ plt_entry_size
4295 - htab
->plt
.has_plt0
);
4296 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4297 base_got
= htab
->elf
.sgotplt
;
4301 plt_index
= h
->plt
.offset
/ plt_entry_size
;
4302 off
= plt_index
* GOT_ENTRY_SIZE
;
4303 base_got
= htab
->elf
.igotplt
;
4306 if (h
->dynindx
== -1
4310 /* This references the local defitionion. We must
4311 initialize this entry in the global offset table.
4312 Since the offset must always be a multiple of 8,
4313 we use the least significant bit to record
4314 whether we have initialized it already.
4316 When doing a dynamic link, we create a .rela.got
4317 relocation entry to initialize the value. This
4318 is done in the finish_dynamic_symbol routine. */
4323 bfd_put_64 (output_bfd
, relocation
,
4324 base_got
->contents
+ off
);
4325 /* Note that this is harmless for the GOTPLT64
4326 case, as -1 | 1 still is -1. */
4332 relocation
= (base_got
->output_section
->vma
4333 + base_got
->output_offset
+ off
);
4338 if (h
->plt
.offset
== (bfd_vma
) -1)
4340 /* Handle static pointers of STT_GNU_IFUNC symbols. */
4341 if (r_type
== htab
->pointer_r_type
4342 && (input_section
->flags
& SEC_CODE
) == 0)
4343 goto do_ifunc_pointer
;
4344 goto bad_ifunc_reloc
;
4347 /* STT_GNU_IFUNC symbol must go through PLT. */
4348 if (htab
->elf
.splt
!= NULL
)
4350 if (htab
->plt_bnd
!= NULL
)
4352 resolved_plt
= htab
->plt_bnd
;
4353 plt_offset
= eh
->plt_bnd
.offset
;
4357 resolved_plt
= htab
->elf
.splt
;
4358 plt_offset
= h
->plt
.offset
;
4363 resolved_plt
= htab
->elf
.iplt
;
4364 plt_offset
= h
->plt
.offset
;
4367 relocation
= (resolved_plt
->output_section
->vma
4368 + resolved_plt
->output_offset
+ plt_offset
);
4374 if (h
->root
.root
.string
)
4375 name
= h
->root
.root
.string
;
4377 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4380 /* xgettext:c-format */
4381 (_("%B: relocation %s against STT_GNU_IFUNC "
4382 "symbol `%s' isn't supported"), input_bfd
,
4384 bfd_set_error (bfd_error_bad_value
);
4388 if (bfd_link_pic (info
))
4393 if (ABI_64_P (output_bfd
))
4398 if (rel
->r_addend
!= 0)
4400 if (h
->root
.root
.string
)
4401 name
= h
->root
.root
.string
;
4403 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4406 /* xgettext:c-format */
4407 (_("%B: relocation %s against STT_GNU_IFUNC "
4408 "symbol `%s' has non-zero addend: %d"),
4409 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4410 bfd_set_error (bfd_error_bad_value
);
4414 /* Generate dynamic relcoation only when there is a
4415 non-GOT reference in a shared object or there is no
4417 if ((bfd_link_pic (info
) && h
->non_got_ref
)
4418 || h
->plt
.offset
== (bfd_vma
) -1)
4420 Elf_Internal_Rela outrel
;
4423 /* Need a dynamic relocation to get the real function
4425 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4429 if (outrel
.r_offset
== (bfd_vma
) -1
4430 || outrel
.r_offset
== (bfd_vma
) -2)
4433 outrel
.r_offset
+= (input_section
->output_section
->vma
4434 + input_section
->output_offset
);
4436 if (h
->dynindx
== -1
4438 || bfd_link_executable (info
))
4440 /* This symbol is resolved locally. */
4441 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4442 outrel
.r_addend
= (h
->root
.u
.def
.value
4443 + h
->root
.u
.def
.section
->output_section
->vma
4444 + h
->root
.u
.def
.section
->output_offset
);
4448 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4449 outrel
.r_addend
= 0;
4452 /* Dynamic relocations are stored in
4453 1. .rela.ifunc section in PIC object.
4454 2. .rela.got section in dynamic executable.
4455 3. .rela.iplt section in static executable. */
4456 if (bfd_link_pic (info
))
4457 sreloc
= htab
->elf
.irelifunc
;
4458 else if (htab
->elf
.splt
!= NULL
)
4459 sreloc
= htab
->elf
.srelgot
;
4461 sreloc
= htab
->elf
.irelplt
;
4462 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4464 /* If this reloc is against an external symbol, we
4465 do not want to fiddle with the addend. Otherwise,
4466 we need to include the symbol value so that it
4467 becomes an addend for the dynamic reloc. For an
4468 internal symbol, we have updated addend. */
4473 case R_X86_64_PC32_BND
:
4475 case R_X86_64_PLT32
:
4476 case R_X86_64_PLT32_BND
:
4481 resolved_to_zero
= (eh
!= NULL
4482 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
4486 /* When generating a shared object, the relocations handled here are
4487 copied into the output file to be resolved at run time. */
4490 case R_X86_64_GOT32
:
4491 case R_X86_64_GOT64
:
4492 /* Relocation is to the entry for this symbol in the global
4494 case R_X86_64_GOTPCREL
:
4495 case R_X86_64_GOTPCRELX
:
4496 case R_X86_64_REX_GOTPCRELX
:
4497 case R_X86_64_GOTPCREL64
:
4498 /* Use global offset table entry as symbol value. */
4499 case R_X86_64_GOTPLT64
:
4500 /* This is obsolete and treated the the same as GOT64. */
4501 base_got
= htab
->elf
.sgot
;
4503 if (htab
->elf
.sgot
== NULL
)
4506 relative_reloc
= FALSE
;
4511 off
= h
->got
.offset
;
4513 && h
->plt
.offset
!= (bfd_vma
)-1
4514 && off
== (bfd_vma
)-1)
4516 /* We can't use h->got.offset here to save
4517 state, or even just remember the offset, as
4518 finish_dynamic_symbol would use that as offset into
4520 bfd_vma plt_index
= (h
->plt
.offset
/ plt_entry_size
4521 - htab
->plt
.has_plt0
);
4522 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4523 base_got
= htab
->elf
.sgotplt
;
4526 dyn
= htab
->elf
.dynamic_sections_created
;
4528 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4529 || (bfd_link_pic (info
)
4530 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4531 || (ELF_ST_VISIBILITY (h
->other
)
4532 && h
->root
.type
== bfd_link_hash_undefweak
))
4534 /* This is actually a static link, or it is a -Bsymbolic
4535 link and the symbol is defined locally, or the symbol
4536 was forced to be local because of a version file. We
4537 must initialize this entry in the global offset table.
4538 Since the offset must always be a multiple of 8, we
4539 use the least significant bit to record whether we
4540 have initialized it already.
4542 When doing a dynamic link, we create a .rela.got
4543 relocation entry to initialize the value. This is
4544 done in the finish_dynamic_symbol routine. */
4549 bfd_put_64 (output_bfd
, relocation
,
4550 base_got
->contents
+ off
);
4551 /* Note that this is harmless for the GOTPLT64 case,
4552 as -1 | 1 still is -1. */
4555 if (h
->dynindx
== -1
4557 && h
->root
.type
!= bfd_link_hash_undefweak
4558 && bfd_link_pic (info
))
4560 /* If this symbol isn't dynamic in PIC,
4561 generate R_X86_64_RELATIVE here. */
4562 eh
->no_finish_dynamic_symbol
= 1;
4563 relative_reloc
= TRUE
;
4568 unresolved_reloc
= FALSE
;
4572 if (local_got_offsets
== NULL
)
4575 off
= local_got_offsets
[r_symndx
];
4577 /* The offset must always be a multiple of 8. We use
4578 the least significant bit to record whether we have
4579 already generated the necessary reloc. */
4584 bfd_put_64 (output_bfd
, relocation
,
4585 base_got
->contents
+ off
);
4586 local_got_offsets
[r_symndx
] |= 1;
4588 if (bfd_link_pic (info
))
4589 relative_reloc
= TRUE
;
4596 Elf_Internal_Rela outrel
;
4598 /* We need to generate a R_X86_64_RELATIVE reloc
4599 for the dynamic linker. */
4600 s
= htab
->elf
.srelgot
;
4604 outrel
.r_offset
= (base_got
->output_section
->vma
4605 + base_got
->output_offset
4607 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4608 outrel
.r_addend
= relocation
;
4609 elf_append_rela (output_bfd
, s
, &outrel
);
4612 if (off
>= (bfd_vma
) -2)
4615 relocation
= base_got
->output_section
->vma
4616 + base_got
->output_offset
+ off
;
4617 if (r_type
!= R_X86_64_GOTPCREL
4618 && r_type
!= R_X86_64_GOTPCRELX
4619 && r_type
!= R_X86_64_REX_GOTPCRELX
4620 && r_type
!= R_X86_64_GOTPCREL64
)
4621 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4622 - htab
->elf
.sgotplt
->output_offset
;
4626 case R_X86_64_GOTOFF64
:
4627 /* Relocation is relative to the start of the global offset
4630 /* Check to make sure it isn't a protected function or data
4631 symbol for shared library since it may not be local when
4632 used as function address or with copy relocation. We also
4633 need to make sure that a symbol is referenced locally. */
4634 if (bfd_link_pic (info
) && h
)
4636 if (!h
->def_regular
)
4640 switch (ELF_ST_VISIBILITY (h
->other
))
4643 v
= _("hidden symbol");
4646 v
= _("internal symbol");
4649 v
= _("protected symbol");
4657 /* xgettext:c-format */
4658 (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s"
4659 " `%s' can not be used when making a shared object"),
4660 input_bfd
, v
, h
->root
.root
.string
);
4661 bfd_set_error (bfd_error_bad_value
);
4664 else if (!bfd_link_executable (info
)
4665 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
4666 && (h
->type
== STT_FUNC
4667 || h
->type
== STT_OBJECT
)
4668 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
4671 /* xgettext:c-format */
4672 (_("%B: relocation R_X86_64_GOTOFF64 against protected %s"
4673 " `%s' can not be used when making a shared object"),
4675 h
->type
== STT_FUNC
? "function" : "data",
4676 h
->root
.root
.string
);
4677 bfd_set_error (bfd_error_bad_value
);
4682 /* Note that sgot is not involved in this
4683 calculation. We always want the start of .got.plt. If we
4684 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
4685 permitted by the ABI, we might have to change this
4687 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4688 + htab
->elf
.sgotplt
->output_offset
;
4691 case R_X86_64_GOTPC32
:
4692 case R_X86_64_GOTPC64
:
4693 /* Use global offset table as symbol value. */
4694 relocation
= htab
->elf
.sgotplt
->output_section
->vma
4695 + htab
->elf
.sgotplt
->output_offset
;
4696 unresolved_reloc
= FALSE
;
4699 case R_X86_64_PLTOFF64
:
4700 /* Relocation is PLT entry relative to GOT. For local
4701 symbols it's the symbol itself relative to GOT. */
4703 /* See PLT32 handling. */
4704 && (h
->plt
.offset
!= (bfd_vma
) -1
4705 || eh
->plt_got
.offset
!= (bfd_vma
) -1)
4706 && htab
->elf
.splt
!= NULL
)
4708 if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
4710 /* Use the GOT PLT. */
4711 resolved_plt
= htab
->plt_got
;
4712 plt_offset
= eh
->plt_got
.offset
;
4714 else if (htab
->plt_bnd
!= NULL
)
4716 resolved_plt
= htab
->plt_bnd
;
4717 plt_offset
= eh
->plt_bnd
.offset
;
4721 resolved_plt
= htab
->elf
.splt
;
4722 plt_offset
= h
->plt
.offset
;
4725 relocation
= (resolved_plt
->output_section
->vma
4726 + resolved_plt
->output_offset
4728 unresolved_reloc
= FALSE
;
4731 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
4732 + htab
->elf
.sgotplt
->output_offset
;
4735 case R_X86_64_PLT32
:
4736 case R_X86_64_PLT32_BND
:
4737 /* Relocation is to the entry for this symbol in the
4738 procedure linkage table. */
4740 /* Resolve a PLT32 reloc against a local symbol directly,
4741 without using the procedure linkage table. */
4745 if ((h
->plt
.offset
== (bfd_vma
) -1
4746 && eh
->plt_got
.offset
== (bfd_vma
) -1)
4747 || htab
->elf
.splt
== NULL
)
4749 /* We didn't make a PLT entry for this symbol. This
4750 happens when statically linking PIC code, or when
4751 using -Bsymbolic. */
4755 if (h
->plt
.offset
!= (bfd_vma
) -1)
4757 if (htab
->plt_bnd
!= NULL
)
4759 resolved_plt
= htab
->plt_bnd
;
4760 plt_offset
= eh
->plt_bnd
.offset
;
4764 resolved_plt
= htab
->elf
.splt
;
4765 plt_offset
= h
->plt
.offset
;
4770 /* Use the GOT PLT. */
4771 resolved_plt
= htab
->plt_got
;
4772 plt_offset
= eh
->plt_got
.offset
;
4775 relocation
= (resolved_plt
->output_section
->vma
4776 + resolved_plt
->output_offset
4778 unresolved_reloc
= FALSE
;
4781 case R_X86_64_SIZE32
:
4782 case R_X86_64_SIZE64
:
4783 /* Set to symbol size. */
4784 relocation
= st_size
;
4790 case R_X86_64_PC32_BND
:
4791 /* Don't complain about -fPIC if the symbol is undefined when
4792 building executable unless it is unresolved weak symbol. */
4793 if ((input_section
->flags
& SEC_ALLOC
) != 0
4794 && (input_section
->flags
& SEC_READONLY
) != 0
4796 && ((bfd_link_executable (info
)
4797 && h
->root
.type
== bfd_link_hash_undefweak
4798 && !resolved_to_zero
)
4799 || (bfd_link_pic (info
)
4800 && !(bfd_link_pie (info
)
4801 && h
->root
.type
== bfd_link_hash_undefined
))))
4803 bfd_boolean fail
= FALSE
;
4805 = ((r_type
== R_X86_64_PC32
4806 || r_type
== R_X86_64_PC32_BND
)
4807 && is_32bit_relative_branch (contents
, rel
->r_offset
));
4809 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
4811 /* Symbol is referenced locally. Make sure it is
4812 defined locally or for a branch. */
4813 fail
= (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
))
4816 else if (!(bfd_link_pie (info
)
4817 && (h
->needs_copy
|| eh
->needs_copy
)))
4819 /* Symbol doesn't need copy reloc and isn't referenced
4820 locally. We only allow branch to symbol with
4821 non-default visibility. */
4823 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
4827 return elf_x86_64_need_pic (input_bfd
, input_section
,
4828 h
, NULL
, NULL
, howto
);
4837 /* FIXME: The ABI says the linker should make sure the value is
4838 the same when it's zeroextended to 64 bit. */
4841 if ((input_section
->flags
& SEC_ALLOC
) == 0)
4844 /* Don't copy a pc-relative relocation into the output file
4845 if the symbol needs copy reloc or the symbol is undefined
4846 when building executable. Copy dynamic function pointer
4847 relocations. Don't generate dynamic relocations against
4848 resolved undefined weak symbols in PIE. */
4849 if ((bfd_link_pic (info
)
4850 && !(bfd_link_pie (info
)
4854 || h
->root
.type
== bfd_link_hash_undefined
)
4855 && (IS_X86_64_PCREL_TYPE (r_type
)
4856 || r_type
== R_X86_64_SIZE32
4857 || r_type
== R_X86_64_SIZE64
))
4859 || ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4860 && !resolved_to_zero
)
4861 || h
->root
.type
!= bfd_link_hash_undefweak
))
4862 && ((! IS_X86_64_PCREL_TYPE (r_type
)
4863 && r_type
!= R_X86_64_SIZE32
4864 && r_type
!= R_X86_64_SIZE64
)
4865 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
4866 || (ELIMINATE_COPY_RELOCS
4867 && !bfd_link_pic (info
)
4871 || eh
->func_pointer_refcount
> 0
4872 || (h
->root
.type
== bfd_link_hash_undefweak
4873 && !resolved_to_zero
))
4874 && ((h
->def_dynamic
&& !h
->def_regular
)
4875 /* Undefined weak symbol is bound locally when
4877 || h
->root
.type
== bfd_link_hash_undefined
)))
4879 Elf_Internal_Rela outrel
;
4880 bfd_boolean skip
, relocate
;
4883 /* When generating a shared object, these relocations
4884 are copied into the output file to be resolved at run
4890 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4892 if (outrel
.r_offset
== (bfd_vma
) -1)
4894 else if (outrel
.r_offset
== (bfd_vma
) -2)
4895 skip
= TRUE
, relocate
= TRUE
;
4897 outrel
.r_offset
+= (input_section
->output_section
->vma
4898 + input_section
->output_offset
);
4901 memset (&outrel
, 0, sizeof outrel
);
4903 /* h->dynindx may be -1 if this symbol was marked to
4907 && (IS_X86_64_PCREL_TYPE (r_type
)
4908 || !(bfd_link_executable (info
)
4909 || SYMBOLIC_BIND (info
, h
))
4910 || ! h
->def_regular
))
4912 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
4913 outrel
.r_addend
= rel
->r_addend
;
4917 /* This symbol is local, or marked to become local.
4918 When relocation overflow check is disabled, we
4919 convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
4920 if (r_type
== htab
->pointer_r_type
4921 || (r_type
== R_X86_64_32
4922 && info
->no_reloc_overflow_check
))
4925 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4926 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4928 else if (r_type
== R_X86_64_64
4929 && !ABI_64_P (output_bfd
))
4932 outrel
.r_info
= htab
->r_info (0,
4933 R_X86_64_RELATIVE64
);
4934 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4935 /* Check addend overflow. */
4936 if ((outrel
.r_addend
& 0x80000000)
4937 != (rel
->r_addend
& 0x80000000))
4940 int addend
= rel
->r_addend
;
4941 if (h
&& h
->root
.root
.string
)
4942 name
= h
->root
.root
.string
;
4944 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4948 /* xgettext:c-format */
4949 (_("%B: addend -0x%x in relocation %s against "
4950 "symbol `%s' at 0x%lx in section `%A' is "
4952 input_bfd
, addend
, howto
->name
, name
,
4953 (unsigned long) rel
->r_offset
, input_section
);
4956 /* xgettext:c-format */
4957 (_("%B: addend 0x%x in relocation %s against "
4958 "symbol `%s' at 0x%lx in section `%A' is "
4960 input_bfd
, addend
, howto
->name
, name
,
4961 (unsigned long) rel
->r_offset
, input_section
);
4962 bfd_set_error (bfd_error_bad_value
);
4970 if (bfd_is_abs_section (sec
))
4972 else if (sec
== NULL
|| sec
->owner
== NULL
)
4974 bfd_set_error (bfd_error_bad_value
);
4981 /* We are turning this relocation into one
4982 against a section symbol. It would be
4983 proper to subtract the symbol's value,
4984 osec->vma, from the emitted reloc addend,
4985 but ld.so expects buggy relocs. */
4986 osec
= sec
->output_section
;
4987 sindx
= elf_section_data (osec
)->dynindx
;
4990 asection
*oi
= htab
->elf
.text_index_section
;
4991 sindx
= elf_section_data (oi
)->dynindx
;
4993 BFD_ASSERT (sindx
!= 0);
4996 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
4997 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5001 sreloc
= elf_section_data (input_section
)->sreloc
;
5003 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5005 r
= bfd_reloc_notsupported
;
5006 goto check_relocation_error
;
5009 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5011 /* If this reloc is against an external symbol, we do
5012 not want to fiddle with the addend. Otherwise, we
5013 need to include the symbol value so that it becomes
5014 an addend for the dynamic reloc. */
5021 case R_X86_64_TLSGD
:
5022 case R_X86_64_GOTPC32_TLSDESC
:
5023 case R_X86_64_TLSDESC_CALL
:
5024 case R_X86_64_GOTTPOFF
:
5025 tls_type
= GOT_UNKNOWN
;
5026 if (h
== NULL
&& local_got_offsets
)
5027 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
5029 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
5031 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5032 input_section
, contents
,
5033 symtab_hdr
, sym_hashes
,
5034 &r_type
, tls_type
, rel
,
5035 relend
, h
, r_symndx
, TRUE
))
5038 if (r_type
== R_X86_64_TPOFF32
)
5040 bfd_vma roff
= rel
->r_offset
;
5042 BFD_ASSERT (! unresolved_reloc
);
5044 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5046 /* GD->LE transition. For 64bit, change
5047 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5048 .word 0x6666; rex64; call __tls_get_addr@PLT
5050 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5052 call *__tls_get_addr@GOTPCREL(%rip)
5053 which may be converted to
5054 addr32 call __tls_get_addr
5057 leaq foo@tpoff(%rax), %rax
5059 leaq foo@tlsgd(%rip), %rdi
5060 .word 0x6666; rex64; call __tls_get_addr@PLT
5062 leaq foo@tlsgd(%rip), %rdi
5064 call *__tls_get_addr@GOTPCREL(%rip)
5065 which may be converted to
5066 addr32 call __tls_get_addr
5069 leaq foo@tpoff(%rax), %rax
5070 For largepic, change:
5071 leaq foo@tlsgd(%rip), %rdi
5072 movabsq $__tls_get_addr@pltoff, %rax
5077 leaq foo@tpoff(%rax), %rax
5078 nopw 0x0(%rax,%rax,1) */
5080 if (ABI_64_P (output_bfd
))
5082 if (contents
[roff
+ 5] == 0xb8)
5084 memcpy (contents
+ roff
- 3,
5085 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80"
5086 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5090 memcpy (contents
+ roff
- 4,
5091 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5095 memcpy (contents
+ roff
- 3,
5096 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
5098 bfd_put_32 (output_bfd
,
5099 elf_x86_64_tpoff (info
, relocation
),
5100 contents
+ roff
+ 8 + largepic
);
5101 /* Skip R_X86_64_PC32, R_X86_64_PLT32,
5102 R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */
5107 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5109 /* GDesc -> LE transition.
5110 It's originally something like:
5111 leaq x@tlsdesc(%rip), %rax
5114 movl $x@tpoff, %rax. */
5116 unsigned int val
, type
;
5118 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5119 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5120 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
5121 contents
+ roff
- 3);
5122 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
5123 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
5124 contents
+ roff
- 1);
5125 bfd_put_32 (output_bfd
,
5126 elf_x86_64_tpoff (info
, relocation
),
5130 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5132 /* GDesc -> LE transition.
5137 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5138 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5141 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
5143 /* IE->LE transition:
5144 For 64bit, originally it can be one of:
5145 movq foo@gottpoff(%rip), %reg
5146 addq foo@gottpoff(%rip), %reg
5149 leaq foo(%reg), %reg
5151 For 32bit, originally it can be one of:
5152 movq foo@gottpoff(%rip), %reg
5153 addl foo@gottpoff(%rip), %reg
5156 leal foo(%reg), %reg
5159 unsigned int val
, type
, reg
;
5162 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
5165 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
5166 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
5172 bfd_put_8 (output_bfd
, 0x49,
5173 contents
+ roff
- 3);
5174 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5175 bfd_put_8 (output_bfd
, 0x41,
5176 contents
+ roff
- 3);
5177 bfd_put_8 (output_bfd
, 0xc7,
5178 contents
+ roff
- 2);
5179 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5180 contents
+ roff
- 1);
5184 /* addq/addl -> addq/addl - addressing with %rsp/%r12
5187 bfd_put_8 (output_bfd
, 0x49,
5188 contents
+ roff
- 3);
5189 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5190 bfd_put_8 (output_bfd
, 0x41,
5191 contents
+ roff
- 3);
5192 bfd_put_8 (output_bfd
, 0x81,
5193 contents
+ roff
- 2);
5194 bfd_put_8 (output_bfd
, 0xc0 | reg
,
5195 contents
+ roff
- 1);
5199 /* addq/addl -> leaq/leal */
5201 bfd_put_8 (output_bfd
, 0x4d,
5202 contents
+ roff
- 3);
5203 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
5204 bfd_put_8 (output_bfd
, 0x45,
5205 contents
+ roff
- 3);
5206 bfd_put_8 (output_bfd
, 0x8d,
5207 contents
+ roff
- 2);
5208 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
5209 contents
+ roff
- 1);
5211 bfd_put_32 (output_bfd
,
5212 elf_x86_64_tpoff (info
, relocation
),
5220 if (htab
->elf
.sgot
== NULL
)
5225 off
= h
->got
.offset
;
5226 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
5230 if (local_got_offsets
== NULL
)
5233 off
= local_got_offsets
[r_symndx
];
5234 offplt
= local_tlsdesc_gotents
[r_symndx
];
5241 Elf_Internal_Rela outrel
;
5245 if (htab
->elf
.srelgot
== NULL
)
5248 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5250 if (GOT_TLS_GDESC_P (tls_type
))
5252 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
5253 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
5254 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
5255 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
5256 + htab
->elf
.sgotplt
->output_offset
5258 + htab
->sgotplt_jump_table_size
);
5259 sreloc
= htab
->elf
.srelplt
;
5261 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5263 outrel
.r_addend
= 0;
5264 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5267 sreloc
= htab
->elf
.srelgot
;
5269 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5270 + htab
->elf
.sgot
->output_offset
+ off
);
5272 if (GOT_TLS_GD_P (tls_type
))
5273 dr_type
= R_X86_64_DTPMOD64
;
5274 else if (GOT_TLS_GDESC_P (tls_type
))
5277 dr_type
= R_X86_64_TPOFF64
;
5279 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
5280 outrel
.r_addend
= 0;
5281 if ((dr_type
== R_X86_64_TPOFF64
5282 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
5283 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
5284 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
5286 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5288 if (GOT_TLS_GD_P (tls_type
))
5292 BFD_ASSERT (! unresolved_reloc
);
5293 bfd_put_64 (output_bfd
,
5294 relocation
- elf_x86_64_dtpoff_base (info
),
5295 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5299 bfd_put_64 (output_bfd
, 0,
5300 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5301 outrel
.r_info
= htab
->r_info (indx
,
5303 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
5304 elf_append_rela (output_bfd
, sreloc
,
5313 local_got_offsets
[r_symndx
] |= 1;
5316 if (off
>= (bfd_vma
) -2
5317 && ! GOT_TLS_GDESC_P (tls_type
))
5319 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
5321 if (r_type
== R_X86_64_GOTPC32_TLSDESC
5322 || r_type
== R_X86_64_TLSDESC_CALL
)
5323 relocation
= htab
->elf
.sgotplt
->output_section
->vma
5324 + htab
->elf
.sgotplt
->output_offset
5325 + offplt
+ htab
->sgotplt_jump_table_size
;
5327 relocation
= htab
->elf
.sgot
->output_section
->vma
5328 + htab
->elf
.sgot
->output_offset
+ off
;
5329 unresolved_reloc
= FALSE
;
5333 bfd_vma roff
= rel
->r_offset
;
5335 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
5337 /* GD->IE transition. For 64bit, change
5338 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5339 .word 0x6666; rex64; call __tls_get_addr@PLT
5341 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
5343 call *__tls_get_addr@GOTPCREL(%rip
5344 which may be converted to
5345 addr32 call __tls_get_addr
5348 addq foo@gottpoff(%rip), %rax
5350 leaq foo@tlsgd(%rip), %rdi
5351 .word 0x6666; rex64; call __tls_get_addr@PLT
5353 leaq foo@tlsgd(%rip), %rdi
5355 call *__tls_get_addr@GOTPCREL(%rip)
5356 which may be converted to
5357 addr32 call __tls_get_addr
5360 addq foo@gottpoff(%rip), %rax
5361 For largepic, change:
5362 leaq foo@tlsgd(%rip), %rdi
5363 movabsq $__tls_get_addr@pltoff, %rax
5368 addq foo@gottpoff(%rax), %rax
5369 nopw 0x0(%rax,%rax,1) */
5371 if (ABI_64_P (output_bfd
))
5373 if (contents
[roff
+ 5] == 0xb8)
5375 memcpy (contents
+ roff
- 3,
5376 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05"
5377 "\0\0\0\0\x66\x0f\x1f\x44\0", 22);
5381 memcpy (contents
+ roff
- 4,
5382 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5386 memcpy (contents
+ roff
- 3,
5387 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
5390 relocation
= (htab
->elf
.sgot
->output_section
->vma
5391 + htab
->elf
.sgot
->output_offset
+ off
5394 - input_section
->output_section
->vma
5395 - input_section
->output_offset
5397 bfd_put_32 (output_bfd
, relocation
,
5398 contents
+ roff
+ 8 + largepic
);
5399 /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */
5404 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
5406 /* GDesc -> IE transition.
5407 It's originally something like:
5408 leaq x@tlsdesc(%rip), %rax
5411 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
5413 /* Now modify the instruction as appropriate. To
5414 turn a leaq into a movq in the form we use it, it
5415 suffices to change the second byte from 0x8d to
5417 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
5419 bfd_put_32 (output_bfd
,
5420 htab
->elf
.sgot
->output_section
->vma
5421 + htab
->elf
.sgot
->output_offset
+ off
5423 - input_section
->output_section
->vma
5424 - input_section
->output_offset
5429 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
5431 /* GDesc -> IE transition.
5438 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
5439 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
5447 case R_X86_64_TLSLD
:
5448 if (! elf_x86_64_tls_transition (info
, input_bfd
,
5449 input_section
, contents
,
5450 symtab_hdr
, sym_hashes
,
5451 &r_type
, GOT_UNKNOWN
, rel
,
5452 relend
, h
, r_symndx
, TRUE
))
5455 if (r_type
!= R_X86_64_TLSLD
)
5457 /* LD->LE transition:
5458 leaq foo@tlsld(%rip), %rdi
5459 call __tls_get_addr@PLT
5460 For 64bit, we change it into:
5461 .word 0x6666; .byte 0x66; movq %fs:0, %rax
5462 For 32bit, we change it into:
5463 nopl 0x0(%rax); movl %fs:0, %eax
5465 leaq foo@tlsld(%rip), %rdi;
5466 call *__tls_get_addr@GOTPCREL(%rip)
5467 which may be converted to
5468 addr32 call __tls_get_addr
5469 For 64bit, we change it into:
5470 .word 0x6666; .word 0x6666; movq %fs:0, %rax
5471 For 32bit, we change it into:
5472 nopw 0x0(%rax); movl %fs:0, %eax
5473 For largepic, change:
5474 leaq foo@tlsgd(%rip), %rdi
5475 movabsq $__tls_get_addr@pltoff, %rax
5479 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
5482 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
5483 if (ABI_64_P (output_bfd
))
5485 if (contents
[rel
->r_offset
+ 5] == 0xb8)
5486 memcpy (contents
+ rel
->r_offset
- 3,
5487 "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0"
5488 "\x64\x48\x8b\x04\x25\0\0\0", 22);
5489 else if (contents
[rel
->r_offset
+ 4] == 0xff
5490 || contents
[rel
->r_offset
+ 4] == 0x67)
5491 memcpy (contents
+ rel
->r_offset
- 3,
5492 "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0",
5495 memcpy (contents
+ rel
->r_offset
- 3,
5496 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
5500 if (contents
[rel
->r_offset
+ 4] == 0xff)
5501 memcpy (contents
+ rel
->r_offset
- 3,
5502 "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0",
5505 memcpy (contents
+ rel
->r_offset
- 3,
5506 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
5508 /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX
5509 and R_X86_64_PLTOFF64. */
5515 if (htab
->elf
.sgot
== NULL
)
5518 off
= htab
->tls_ld_got
.offset
;
5523 Elf_Internal_Rela outrel
;
5525 if (htab
->elf
.srelgot
== NULL
)
5528 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5529 + htab
->elf
.sgot
->output_offset
+ off
);
5531 bfd_put_64 (output_bfd
, 0,
5532 htab
->elf
.sgot
->contents
+ off
);
5533 bfd_put_64 (output_bfd
, 0,
5534 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
5535 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
5536 outrel
.r_addend
= 0;
5537 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
5539 htab
->tls_ld_got
.offset
|= 1;
5541 relocation
= htab
->elf
.sgot
->output_section
->vma
5542 + htab
->elf
.sgot
->output_offset
+ off
;
5543 unresolved_reloc
= FALSE
;
5546 case R_X86_64_DTPOFF32
:
5547 if (!bfd_link_executable (info
)
5548 || (input_section
->flags
& SEC_CODE
) == 0)
5549 relocation
-= elf_x86_64_dtpoff_base (info
);
5551 relocation
= elf_x86_64_tpoff (info
, relocation
);
5554 case R_X86_64_TPOFF32
:
5555 case R_X86_64_TPOFF64
:
5556 BFD_ASSERT (bfd_link_executable (info
));
5557 relocation
= elf_x86_64_tpoff (info
, relocation
);
5560 case R_X86_64_DTPOFF64
:
5561 BFD_ASSERT ((input_section
->flags
& SEC_CODE
) == 0);
5562 relocation
-= elf_x86_64_dtpoff_base (info
);
5569 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5570 because such sections are not SEC_ALLOC and thus ld.so will
5571 not process them. */
5572 if (unresolved_reloc
5573 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5575 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5576 rel
->r_offset
) != (bfd_vma
) -1)
5579 /* xgettext:c-format */
5580 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5583 (long) rel
->r_offset
,
5585 h
->root
.root
.string
);
5590 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5591 contents
, rel
->r_offset
,
5592 relocation
, rel
->r_addend
);
5594 check_relocation_error
:
5595 if (r
!= bfd_reloc_ok
)
5600 name
= h
->root
.root
.string
;
5603 name
= bfd_elf_string_from_elf_section (input_bfd
,
5604 symtab_hdr
->sh_link
,
5609 name
= bfd_section_name (input_bfd
, sec
);
5612 if (r
== bfd_reloc_overflow
)
5613 (*info
->callbacks
->reloc_overflow
)
5614 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5615 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
5619 /* xgettext:c-format */
5620 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
5621 input_bfd
, input_section
,
5622 (long) rel
->r_offset
, name
, (int) r
);
5633 Elf_Internal_Shdr
*rel_hdr
;
5634 size_t deleted
= rel
- wrel
;
5636 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
5637 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5638 if (rel_hdr
->sh_size
== 0)
5640 /* It is too late to remove an empty reloc section. Leave
5642 ??? What is wrong with an empty section??? */
5643 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
5646 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
5647 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
5648 input_section
->reloc_count
-= deleted
;
5654 /* Finish up dynamic symbol handling. We set the contents of various
5655 dynamic sections here. */
5658 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
5659 struct bfd_link_info
*info
,
5660 struct elf_link_hash_entry
*h
,
5661 Elf_Internal_Sym
*sym
)
5663 struct elf_x86_64_link_hash_table
*htab
;
5664 bfd_boolean use_plt_bnd
;
5665 struct elf_x86_64_link_hash_entry
*eh
;
5666 bfd_boolean local_undefweak
;
5668 htab
= elf_x86_64_hash_table (info
);
5672 /* Use MPX backend data in case of BND relocation. Use .plt_bnd
5673 section only if there is .plt section. */
5674 use_plt_bnd
= htab
->elf
.splt
!= NULL
&& htab
->plt_bnd
!= NULL
;
5676 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
5677 if (eh
->no_finish_dynamic_symbol
)
5680 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
5681 resolved undefined weak symbols in executable so that their
5682 references have value 0 at run-time. */
5683 local_undefweak
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
,
5687 if (h
->plt
.offset
!= (bfd_vma
) -1)
5690 bfd_vma got_offset
, plt_offset
;
5691 Elf_Internal_Rela rela
;
5693 asection
*plt
, *gotplt
, *relplt
, *resolved_plt
;
5694 const struct elf_backend_data
*bed
;
5695 bfd_vma plt_got_pcrel_offset
;
5697 /* When building a static executable, use .iplt, .igot.plt and
5698 .rela.iplt sections for STT_GNU_IFUNC symbols. */
5699 if (htab
->elf
.splt
!= NULL
)
5701 plt
= htab
->elf
.splt
;
5702 gotplt
= htab
->elf
.sgotplt
;
5703 relplt
= htab
->elf
.srelplt
;
5707 plt
= htab
->elf
.iplt
;
5708 gotplt
= htab
->elf
.igotplt
;
5709 relplt
= htab
->elf
.irelplt
;
5712 /* This symbol has an entry in the procedure linkage table. Set
5714 if ((h
->dynindx
== -1
5716 && !((h
->forced_local
|| bfd_link_executable (info
))
5718 && h
->type
== STT_GNU_IFUNC
))
5724 /* Get the index in the procedure linkage table which
5725 corresponds to this symbol. This is the index of this symbol
5726 in all the symbols for which we are making plt entries. The
5727 first entry in the procedure linkage table is reserved.
5729 Get the offset into the .got table of the entry that
5730 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
5731 bytes. The first three are reserved for the dynamic linker.
5733 For static executables, we don't reserve anything. */
5735 if (plt
== htab
->elf
.splt
)
5737 got_offset
= (h
->plt
.offset
/ htab
->plt
.plt_entry_size
5738 - htab
->plt
.has_plt0
);
5739 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
5743 got_offset
= h
->plt
.offset
/ htab
->plt
.plt_entry_size
;
5744 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
5747 /* Fill in the entry in the procedure linkage table. */
5748 memcpy (plt
->contents
+ h
->plt
.offset
, htab
->plt
.plt_entry
,
5749 htab
->plt
.plt_entry_size
);
5752 memcpy (htab
->plt_bnd
->contents
+ eh
->plt_bnd
.offset
,
5753 htab
->non_lazy_plt
->plt_entry
,
5754 htab
->non_lazy_plt
->plt_entry_size
);
5756 resolved_plt
= htab
->plt_bnd
;
5757 plt_offset
= eh
->plt_bnd
.offset
;
5762 plt_offset
= h
->plt
.offset
;
5765 /* Insert the relocation positions of the plt section. */
5767 /* Put offset the PC-relative instruction referring to the GOT entry,
5768 subtracting the size of that instruction. */
5769 plt_got_pcrel_offset
= (gotplt
->output_section
->vma
5770 + gotplt
->output_offset
5772 - resolved_plt
->output_section
->vma
5773 - resolved_plt
->output_offset
5775 - htab
->plt
.plt_got_insn_size
);
5777 /* Check PC-relative offset overflow in PLT entry. */
5778 if ((plt_got_pcrel_offset
+ 0x80000000) > 0xffffffff)
5779 /* xgettext:c-format */
5780 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"),
5781 output_bfd
, h
->root
.root
.string
);
5783 bfd_put_32 (output_bfd
, plt_got_pcrel_offset
,
5784 (resolved_plt
->contents
+ plt_offset
5785 + htab
->plt
.plt_got_offset
));
5787 /* Fill in the entry in the global offset table, initially this
5788 points to the second part of the PLT entry. Leave the entry
5789 as zero for undefined weak symbol in PIE. No PLT relocation
5790 against undefined weak symbol in PIE. */
5791 if (!local_undefweak
)
5793 if (htab
->plt
.has_plt0
)
5794 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5795 + plt
->output_offset
5797 + htab
->lazy_plt
->plt_lazy_offset
),
5798 gotplt
->contents
+ got_offset
);
5800 /* Fill in the entry in the .rela.plt section. */
5801 rela
.r_offset
= (gotplt
->output_section
->vma
5802 + gotplt
->output_offset
5804 if (h
->dynindx
== -1
5805 || ((bfd_link_executable (info
)
5806 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5808 && h
->type
== STT_GNU_IFUNC
))
5810 /* If an STT_GNU_IFUNC symbol is locally defined, generate
5811 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
5812 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
5813 rela
.r_addend
= (h
->root
.u
.def
.value
5814 + h
->root
.u
.def
.section
->output_section
->vma
5815 + h
->root
.u
.def
.section
->output_offset
);
5816 /* R_X86_64_IRELATIVE comes last. */
5817 plt_index
= htab
->next_irelative_index
--;
5821 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
5823 plt_index
= htab
->next_jump_slot_index
++;
5826 /* Don't fill the second and third slots in PLT entry for
5827 static executables nor without PLT0. */
5828 if (plt
== htab
->elf
.splt
&& htab
->plt
.has_plt0
)
5831 = h
->plt
.offset
+ htab
->lazy_plt
->plt_plt_insn_end
;
5833 /* Put relocation index. */
5834 bfd_put_32 (output_bfd
, plt_index
,
5835 (plt
->contents
+ h
->plt
.offset
5836 + htab
->lazy_plt
->plt_reloc_offset
));
5838 /* Put offset for jmp .PLT0 and check for overflow. We don't
5839 check relocation index for overflow since branch displacement
5840 will overflow first. */
5841 if (plt0_offset
> 0x80000000)
5842 /* xgettext:c-format */
5843 info
->callbacks
->einfo (_("%F%B: branch displacement overflow in PLT entry for `%s'\n"),
5844 output_bfd
, h
->root
.root
.string
);
5845 bfd_put_32 (output_bfd
, - plt0_offset
,
5846 (plt
->contents
+ h
->plt
.offset
5847 + htab
->lazy_plt
->plt_plt_offset
));
5850 bed
= get_elf_backend_data (output_bfd
);
5851 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
5852 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
5855 else if (eh
->plt_got
.offset
!= (bfd_vma
) -1)
5857 bfd_vma got_offset
, plt_offset
;
5858 asection
*plt
, *got
;
5859 bfd_boolean got_after_plt
;
5860 int32_t got_pcrel_offset
;
5862 /* Set the entry in the GOT procedure linkage table. */
5863 plt
= htab
->plt_got
;
5864 got
= htab
->elf
.sgot
;
5865 got_offset
= h
->got
.offset
;
5867 if (got_offset
== (bfd_vma
) -1
5868 || (h
->type
== STT_GNU_IFUNC
&& h
->def_regular
)
5873 /* Use the non-lazy PLT entry template for the GOT PLT since they
5874 are the identical. */
5875 /* Fill in the entry in the GOT procedure linkage table. */
5876 plt_offset
= eh
->plt_got
.offset
;
5877 memcpy (plt
->contents
+ plt_offset
,
5878 htab
->non_lazy_plt
->plt_entry
,
5879 htab
->non_lazy_plt
->plt_entry_size
);
5881 /* Put offset the PC-relative instruction referring to the GOT
5882 entry, subtracting the size of that instruction. */
5883 got_pcrel_offset
= (got
->output_section
->vma
5884 + got
->output_offset
5886 - plt
->output_section
->vma
5887 - plt
->output_offset
5889 - htab
->non_lazy_plt
->plt_got_insn_size
);
5891 /* Check PC-relative offset overflow in GOT PLT entry. */
5892 got_after_plt
= got
->output_section
->vma
> plt
->output_section
->vma
;
5893 if ((got_after_plt
&& got_pcrel_offset
< 0)
5894 || (!got_after_plt
&& got_pcrel_offset
> 0))
5895 /* xgettext:c-format */
5896 info
->callbacks
->einfo (_("%F%B: PC-relative offset overflow in GOT PLT entry for `%s'\n"),
5897 output_bfd
, h
->root
.root
.string
);
5899 bfd_put_32 (output_bfd
, got_pcrel_offset
,
5900 (plt
->contents
+ plt_offset
5901 + htab
->non_lazy_plt
->plt_got_offset
));
5904 if (!local_undefweak
5906 && (h
->plt
.offset
!= (bfd_vma
) -1
5907 || eh
->plt_got
.offset
!= (bfd_vma
) -1))
5909 /* Mark the symbol as undefined, rather than as defined in
5910 the .plt section. Leave the value if there were any
5911 relocations where pointer equality matters (this is a clue
5912 for the dynamic linker, to make function pointer
5913 comparisons work between an application and shared
5914 library), otherwise set it to zero. If a function is only
5915 called from a binary, there is no need to slow down
5916 shared libraries because of that. */
5917 sym
->st_shndx
= SHN_UNDEF
;
5918 if (!h
->pointer_equality_needed
)
5922 /* Don't generate dynamic GOT relocation against undefined weak
5923 symbol in executable. */
5924 if (h
->got
.offset
!= (bfd_vma
) -1
5925 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
5926 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
5927 && !local_undefweak
)
5929 Elf_Internal_Rela rela
;
5930 asection
*relgot
= htab
->elf
.srelgot
;
5932 /* This symbol has an entry in the global offset table. Set it
5934 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
5937 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
5938 + htab
->elf
.sgot
->output_offset
5939 + (h
->got
.offset
&~ (bfd_vma
) 1));
5941 /* If this is a static link, or it is a -Bsymbolic link and the
5942 symbol is defined locally or was forced to be local because
5943 of a version file, we just want to emit a RELATIVE reloc.
5944 The entry in the global offset table will already have been
5945 initialized in the relocate_section function. */
5947 && h
->type
== STT_GNU_IFUNC
)
5949 if (h
->plt
.offset
== (bfd_vma
) -1)
5951 /* STT_GNU_IFUNC is referenced without PLT. */
5952 if (htab
->elf
.splt
== NULL
)
5954 /* use .rel[a].iplt section to store .got relocations
5955 in static executable. */
5956 relgot
= htab
->elf
.irelplt
;
5958 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
5960 rela
.r_info
= htab
->r_info (0,
5961 R_X86_64_IRELATIVE
);
5962 rela
.r_addend
= (h
->root
.u
.def
.value
5963 + h
->root
.u
.def
.section
->output_section
->vma
5964 + h
->root
.u
.def
.section
->output_offset
);
5969 else if (bfd_link_pic (info
))
5971 /* Generate R_X86_64_GLOB_DAT. */
5978 if (!h
->pointer_equality_needed
)
5981 /* For non-shared object, we can't use .got.plt, which
5982 contains the real function addres if we need pointer
5983 equality. We load the GOT entry with the PLT entry. */
5984 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
5985 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
5986 + plt
->output_offset
5988 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
5992 else if (bfd_link_pic (info
)
5993 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5995 if (!h
->def_regular
)
5997 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5998 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
5999 rela
.r_addend
= (h
->root
.u
.def
.value
6000 + h
->root
.u
.def
.section
->output_section
->vma
6001 + h
->root
.u
.def
.section
->output_offset
);
6005 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6007 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6008 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
6009 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
6013 elf_append_rela (output_bfd
, relgot
, &rela
);
6018 Elf_Internal_Rela rela
;
6021 /* This symbol needs a copy reloc. Set it up. */
6023 if (h
->dynindx
== -1
6024 || (h
->root
.type
!= bfd_link_hash_defined
6025 && h
->root
.type
!= bfd_link_hash_defweak
)
6026 || htab
->elf
.srelbss
== NULL
6027 || htab
->elf
.sreldynrelro
== NULL
)
6030 rela
.r_offset
= (h
->root
.u
.def
.value
6031 + h
->root
.u
.def
.section
->output_section
->vma
6032 + h
->root
.u
.def
.section
->output_offset
);
6033 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
6035 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6036 s
= htab
->elf
.sreldynrelro
;
6038 s
= htab
->elf
.srelbss
;
6039 elf_append_rela (output_bfd
, s
, &rela
);
6045 /* Finish up local dynamic symbol handling. We set the contents of
6046 various dynamic sections here. */
6049 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
6051 struct elf_link_hash_entry
*h
6052 = (struct elf_link_hash_entry
*) *slot
;
6053 struct bfd_link_info
*info
6054 = (struct bfd_link_info
*) inf
;
6056 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6060 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
6061 here since undefined weak symbol may not be dynamic and may not be
6062 called for elf_x86_64_finish_dynamic_symbol. */
6065 elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry
*bh
,
6068 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
6069 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6071 if (h
->root
.type
!= bfd_link_hash_undefweak
6072 || h
->dynindx
!= -1)
6075 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
6079 /* Used to decide how to sort relocs in an optimal manner for the
6080 dynamic linker, before writing them out. */
6082 static enum elf_reloc_type_class
6083 elf_x86_64_reloc_type_class (const struct bfd_link_info
*info
,
6084 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6085 const Elf_Internal_Rela
*rela
)
6087 bfd
*abfd
= info
->output_bfd
;
6088 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6089 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6091 if (htab
->elf
.dynsym
!= NULL
6092 && htab
->elf
.dynsym
->contents
!= NULL
)
6094 /* Check relocation against STT_GNU_IFUNC symbol if there are
6096 unsigned long r_symndx
= htab
->r_sym (rela
->r_info
);
6097 if (r_symndx
!= STN_UNDEF
)
6099 Elf_Internal_Sym sym
;
6100 if (!bed
->s
->swap_symbol_in (abfd
,
6101 (htab
->elf
.dynsym
->contents
6102 + r_symndx
* bed
->s
->sizeof_sym
),
6106 if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
6107 return reloc_class_ifunc
;
6111 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6113 case R_X86_64_IRELATIVE
:
6114 return reloc_class_ifunc
;
6115 case R_X86_64_RELATIVE
:
6116 case R_X86_64_RELATIVE64
:
6117 return reloc_class_relative
;
6118 case R_X86_64_JUMP_SLOT
:
6119 return reloc_class_plt
;
6121 return reloc_class_copy
;
6123 return reloc_class_normal
;
6127 /* Finish up the dynamic sections. */
6130 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
6131 struct bfd_link_info
*info
)
6133 struct elf_x86_64_link_hash_table
*htab
;
6137 htab
= elf_x86_64_hash_table (info
);
6141 dynobj
= htab
->elf
.dynobj
;
6142 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6144 if (htab
->elf
.dynamic_sections_created
)
6146 bfd_byte
*dyncon
, *dynconend
;
6147 const struct elf_backend_data
*bed
;
6148 bfd_size_type sizeof_dyn
;
6150 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
6153 bed
= get_elf_backend_data (dynobj
);
6154 sizeof_dyn
= bed
->s
->sizeof_dyn
;
6155 dyncon
= sdyn
->contents
;
6156 dynconend
= sdyn
->contents
+ sdyn
->size
;
6157 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
6159 Elf_Internal_Dyn dyn
;
6162 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
6170 s
= htab
->elf
.sgotplt
;
6171 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6175 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
6179 s
= htab
->elf
.srelplt
->output_section
;
6180 dyn
.d_un
.d_val
= s
->size
;
6183 case DT_TLSDESC_PLT
:
6185 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6186 + htab
->tlsdesc_plt
;
6189 case DT_TLSDESC_GOT
:
6191 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6192 + htab
->tlsdesc_got
;
6196 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
6199 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
6201 elf_section_data (htab
->elf
.splt
->output_section
)
6202 ->this_hdr
.sh_entsize
= htab
->plt
.plt_entry_size
;
6204 if (htab
->plt
.has_plt0
)
6206 /* Fill in the special first entry in the procedure linkage
6208 memcpy (htab
->elf
.splt
->contents
,
6209 htab
->lazy_plt
->plt0_entry
,
6210 htab
->lazy_plt
->plt_entry_size
);
6211 /* Add offset for pushq GOT+8(%rip), since the instruction
6212 uses 6 bytes subtract this value. */
6213 bfd_put_32 (output_bfd
,
6214 (htab
->elf
.sgotplt
->output_section
->vma
6215 + htab
->elf
.sgotplt
->output_offset
6217 - htab
->elf
.splt
->output_section
->vma
6218 - htab
->elf
.splt
->output_offset
6220 (htab
->elf
.splt
->contents
6221 + htab
->lazy_plt
->plt0_got1_offset
));
6222 /* Add offset for the PC-relative instruction accessing
6223 GOT+16, subtracting the offset to the end of that
6225 bfd_put_32 (output_bfd
,
6226 (htab
->elf
.sgotplt
->output_section
->vma
6227 + htab
->elf
.sgotplt
->output_offset
6229 - htab
->elf
.splt
->output_section
->vma
6230 - htab
->elf
.splt
->output_offset
6231 - htab
->lazy_plt
->plt0_got2_insn_end
),
6232 (htab
->elf
.splt
->contents
6233 + htab
->lazy_plt
->plt0_got2_offset
));
6235 if (htab
->tlsdesc_plt
)
6237 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6238 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
6240 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
6241 htab
->lazy_plt
->plt0_entry
,
6242 htab
->lazy_plt
->plt_entry_size
);
6244 /* Add offset for pushq GOT+8(%rip), since the
6245 instruction uses 6 bytes subtract this value. */
6246 bfd_put_32 (output_bfd
,
6247 (htab
->elf
.sgotplt
->output_section
->vma
6248 + htab
->elf
.sgotplt
->output_offset
6250 - htab
->elf
.splt
->output_section
->vma
6251 - htab
->elf
.splt
->output_offset
6254 (htab
->elf
.splt
->contents
6256 + htab
->lazy_plt
->plt0_got1_offset
));
6257 /* Add offset for the PC-relative instruction accessing
6258 GOT+TDG, where TDG stands for htab->tlsdesc_got,
6259 subtracting the offset to the end of that
6261 bfd_put_32 (output_bfd
,
6262 (htab
->elf
.sgot
->output_section
->vma
6263 + htab
->elf
.sgot
->output_offset
6265 - htab
->elf
.splt
->output_section
->vma
6266 - htab
->elf
.splt
->output_offset
6268 - htab
->lazy_plt
->plt0_got2_insn_end
),
6269 (htab
->elf
.splt
->contents
6271 + htab
->lazy_plt
->plt0_got2_offset
));
6277 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
6278 elf_section_data (htab
->plt_got
->output_section
)
6279 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6281 if (htab
->plt_bnd
!= NULL
&& htab
->plt_bnd
->size
> 0)
6282 elf_section_data (htab
->plt_bnd
->output_section
)
6283 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
6285 /* GOT is always created in setup_gnu_properties. But it may not be
6287 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
6289 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
6292 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
6296 /* Set the first entry in the global offset table to the address of
6297 the dynamic section. */
6299 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
6301 bfd_put_64 (output_bfd
,
6302 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6303 htab
->elf
.sgotplt
->contents
);
6304 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6305 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6306 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6307 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6308 htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
6310 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
6314 /* Adjust .eh_frame for .plt section. */
6315 if (htab
->plt_eh_frame
!= NULL
6316 && htab
->plt_eh_frame
->contents
!= NULL
)
6318 if (htab
->elf
.splt
!= NULL
6319 && htab
->elf
.splt
->size
!= 0
6320 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
6321 && htab
->elf
.splt
->output_section
!= NULL
6322 && htab
->plt_eh_frame
->output_section
!= NULL
)
6324 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
6325 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
6326 + htab
->plt_eh_frame
->output_offset
6327 + PLT_FDE_START_OFFSET
;
6328 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6329 htab
->plt_eh_frame
->contents
6330 + PLT_FDE_START_OFFSET
);
6332 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6334 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6336 htab
->plt_eh_frame
->contents
))
6341 /* Adjust .eh_frame for .plt.got section. */
6342 if (htab
->plt_got_eh_frame
!= NULL
6343 && htab
->plt_got_eh_frame
->contents
!= NULL
)
6345 if (htab
->plt_got
!= NULL
6346 && htab
->plt_got
->size
!= 0
6347 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
6348 && htab
->plt_got
->output_section
!= NULL
6349 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
6351 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
6352 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
6353 + htab
->plt_got_eh_frame
->output_offset
6354 + PLT_FDE_START_OFFSET
;
6355 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6356 htab
->plt_got_eh_frame
->contents
6357 + PLT_FDE_START_OFFSET
);
6359 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6361 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6362 htab
->plt_got_eh_frame
,
6363 htab
->plt_got_eh_frame
->contents
))
6368 /* Adjust .eh_frame for .plt.bnd section. */
6369 if (htab
->plt_bnd_eh_frame
!= NULL
6370 && htab
->plt_bnd_eh_frame
->contents
!= NULL
)
6372 if (htab
->plt_bnd
!= NULL
6373 && htab
->plt_bnd
->size
!= 0
6374 && (htab
->plt_bnd
->flags
& SEC_EXCLUDE
) == 0
6375 && htab
->plt_bnd
->output_section
!= NULL
6376 && htab
->plt_bnd_eh_frame
->output_section
!= NULL
)
6378 bfd_vma plt_start
= htab
->plt_bnd
->output_section
->vma
;
6379 bfd_vma eh_frame_start
= htab
->plt_bnd_eh_frame
->output_section
->vma
6380 + htab
->plt_bnd_eh_frame
->output_offset
6381 + PLT_FDE_START_OFFSET
;
6382 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
6383 htab
->plt_bnd_eh_frame
->contents
6384 + PLT_FDE_START_OFFSET
);
6386 if (htab
->plt_bnd_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
6388 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
6389 htab
->plt_bnd_eh_frame
,
6390 htab
->plt_bnd_eh_frame
->contents
))
6395 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
6396 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
6399 /* Fill PLT entries for undefined weak symbols in PIE. */
6400 if (bfd_link_pie (info
))
6401 bfd_hash_traverse (&info
->hash
->table
,
6402 elf_x86_64_pie_finish_undefweak_symbol
,
6408 /* Fill PLT/GOT entries and allocate dynamic relocations for local
6409 STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
6410 It has to be done before elf_link_sort_relocs is called so that
6411 dynamic relocations are properly sorted. */
6414 elf_x86_64_output_arch_local_syms
6415 (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6416 struct bfd_link_info
*info
,
6417 void *flaginfo ATTRIBUTE_UNUSED
,
6418 int (*func
) (void *, const char *,
6421 struct elf_link_hash_entry
*) ATTRIBUTE_UNUSED
)
6423 struct elf_x86_64_link_hash_table
*htab
= elf_x86_64_hash_table (info
);
6427 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
6428 htab_traverse (htab
->loc_hash_table
,
6429 elf_x86_64_finish_local_dynamic_symbol
,
6435 /* Sort relocs into address order. */
6438 compare_relocs (const void *ap
, const void *bp
)
6440 const arelent
*a
= * (const arelent
**) ap
;
6441 const arelent
*b
= * (const arelent
**) bp
;
6443 if (a
->address
> b
->address
)
6445 else if (a
->address
< b
->address
)
6451 enum elf_x86_64_plt_type
6459 struct elf_x86_64_plt
6464 enum elf_x86_64_plt_type type
;
6465 unsigned int plt_got_offset
;
6466 unsigned int plt_got_insn_size
;
6467 unsigned int plt_entry_size
;
6471 /* Forward declaration. */
6472 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_nacl_plt
;
6474 /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
6475 dynamic relocations. */
6478 elf_x86_64_get_synthetic_symtab (bfd
*abfd
,
6479 long symcount ATTRIBUTE_UNUSED
,
6480 asymbol
**syms ATTRIBUTE_UNUSED
,
6485 long size
, count
, i
, n
;
6487 unsigned int plt_got_offset
, plt_entry_size
, plt_got_insn_size
;
6489 bfd_byte
*plt_contents
;
6490 long dynrelcount
, relsize
;
6491 arelent
**dynrelbuf
;
6492 const struct elf_x86_64_lazy_plt_layout
*lazy_plt
;
6493 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_plt
;
6494 const struct elf_x86_64_lazy_plt_layout
*lazy_bnd_plt
;
6495 const struct elf_x86_64_non_lazy_plt_layout
*non_lazy_bnd_plt
;
6498 enum elf_x86_64_plt_type plt_type
;
6499 struct elf_x86_64_plt plts
[] =
6501 { ".plt", NULL
, NULL
, plt_unknown
, 0, 0, 0, 0 },
6502 { ".plt.got", NULL
, NULL
, plt_non_lazy
, 0, 0, 0, 0 },
6503 { ".plt.bnd", NULL
, NULL
, plt_bnd
, 0, 0, 0, 0 },
6509 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
6512 if (dynsymcount
<= 0)
6515 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
6519 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
6520 if (dynrelbuf
== NULL
)
6523 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
6526 /* Sort the relocs by address. */
6527 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*), compare_relocs
);
6529 if (get_elf_x86_64_backend_data (abfd
)->os
== is_normal
)
6531 lazy_plt
= &elf_x86_64_lazy_plt
;
6532 non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
6533 lazy_bnd_plt
= &elf_x86_64_lazy_bnd_plt
;
6534 non_lazy_bnd_plt
= &elf_x86_64_non_lazy_bnd_plt
;
6538 lazy_plt
= &elf_x86_64_nacl_plt
;
6539 non_lazy_plt
= NULL
;
6540 lazy_bnd_plt
= NULL
;
6541 non_lazy_bnd_plt
= NULL
;
6545 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6547 plt
= bfd_get_section_by_name (abfd
, plts
[j
].name
);
6551 /* Get the PLT section contents. */
6552 plt_contents
= (bfd_byte
*) bfd_malloc (plt
->size
);
6553 if (plt_contents
== NULL
)
6555 if (!bfd_get_section_contents (abfd
, (asection
*) plt
,
6556 plt_contents
, 0, plt
->size
))
6558 free (plt_contents
);
6562 /* Check what kind of PLT it is. */
6563 plt_type
= plt_unknown
;
6564 if (plts
[j
].type
== plt_unknown
)
6566 /* Match lazy PLT first. Need to check the first two
6568 if ((memcmp (plt_contents
, lazy_plt
->plt0_entry
,
6569 lazy_plt
->plt0_got1_offset
) == 0)
6570 && (memcmp (plt_contents
+ 6, lazy_plt
->plt0_entry
+ 6,
6572 plt_type
= plt_lazy
;
6573 else if (lazy_bnd_plt
!= NULL
6574 && (memcmp (plt_contents
, lazy_bnd_plt
->plt0_entry
,
6575 lazy_bnd_plt
->plt0_got1_offset
) == 0)
6576 && (memcmp (plt_contents
+ 6,
6577 lazy_bnd_plt
->plt0_entry
+ 6, 3) == 0))
6579 plt_type
= plt_lazy
| plt_bnd
;
6580 lazy_plt
= lazy_bnd_plt
;
6584 if (non_lazy_plt
!= NULL
6585 && (plt_type
== plt_unknown
|| plt_type
== plt_non_lazy
))
6587 /* Match non-lazy PLT. */
6588 if (memcmp (plt_contents
, non_lazy_plt
->plt_entry
,
6589 non_lazy_plt
->plt_got_offset
) == 0)
6590 plt_type
= plt_non_lazy
;
6593 if (non_lazy_bnd_plt
!= NULL
6594 && (plt_type
== plt_unknown
|| plt_type
== plt_bnd
))
6596 /* Match BND PLT. */
6597 if (memcmp (plt_contents
, non_lazy_bnd_plt
->plt_entry
,
6598 non_lazy_bnd_plt
->plt_got_offset
) == 0)
6601 non_lazy_plt
= non_lazy_bnd_plt
;
6605 if (plt_type
== plt_unknown
)
6609 plts
[j
].type
= plt_type
;
6611 if ((plt_type
& plt_lazy
))
6613 plts
[j
].plt_got_offset
= lazy_plt
->plt_got_offset
;
6614 plts
[j
].plt_got_insn_size
= lazy_plt
->plt_got_insn_size
;
6615 plts
[j
].plt_entry_size
= lazy_plt
->plt_entry_size
;
6616 /* Skip PLT0 in lazy PLT. */
6621 plts
[j
].plt_got_offset
= non_lazy_plt
->plt_got_offset
;
6622 plts
[j
].plt_got_insn_size
= non_lazy_plt
->plt_got_insn_size
;
6623 plts
[j
].plt_entry_size
= non_lazy_plt
->plt_entry_size
;
6627 /* Skip lazy PLT with BND. */
6628 if (plt_type
== (plt_lazy
|plt_bnd
))
6632 n
= plt
->size
/ plts
[j
].plt_entry_size
;
6637 plts
[j
].contents
= plt_contents
;
6640 size
= count
* sizeof (asymbol
);
6641 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
6645 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6646 if (plts
[j
].contents
!= NULL
)
6647 free (plts
[j
].contents
);
6652 /* Check for each PLT section. */
6655 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6656 if ((plt_contents
= plts
[j
].contents
) != NULL
)
6661 plt_got_offset
= plts
[j
].plt_got_offset
;
6662 plt_got_insn_size
= plts
[j
].plt_got_insn_size
;
6663 plt_entry_size
= plts
[j
].plt_entry_size
;
6667 if ((plts
[j
].type
& plt_lazy
))
6669 /* Skip PLT0 in lazy PLT. */
6671 offset
= plt_entry_size
;
6679 /* Check each PLT entry against dynamic relocations. */
6680 for (; k
< plts
[j
].count
; k
++)
6687 /* Get the PC-relative offset, a signed 32-bit integer. */
6688 off
= H_GET_32 (abfd
, (plt_contents
+ offset
6690 got_vma
= plt
->vma
+ offset
+ off
+ plt_got_insn_size
;
6692 /* Binary search. */
6696 while ((min
+ 1) < max
)
6700 mid
= (min
+ max
) / 2;
6702 if (got_vma
> r
->address
)
6704 else if (got_vma
< r
->address
)
6713 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
6714 if (got_vma
== p
->address
6716 && (p
->howto
->type
== R_X86_64_JUMP_SLOT
6717 || p
->howto
->type
== R_X86_64_GLOB_DAT
6718 || p
->howto
->type
== R_X86_64_IRELATIVE
))
6720 *s
= **p
->sym_ptr_ptr
;
6721 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
6722 set. Since we are defining a symbol, ensure one
6724 if ((s
->flags
& BSF_LOCAL
) == 0)
6725 s
->flags
|= BSF_GLOBAL
;
6726 s
->flags
|= BSF_SYNTHETIC
;
6727 /* This is no longer a section symbol. */
6728 s
->flags
&= ~BSF_SECTION_SYM
;
6730 s
->the_bfd
= plt
->owner
;
6732 /* Store relocation for later use. */
6734 /* Add @plt to function name later. */
6735 size
+= strlen (s
->name
) + sizeof ("@plt");
6737 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
6741 offset
+= plt_entry_size
;
6745 /* PLT entries with R_X86_64_TLSDESC relocations are skipped. */
6751 /* Allocate space for @plt suffixes. */
6752 names
= (char *) bfd_malloc (size
);
6757 for (i
= 0; i
< count
; i
++)
6759 /* Add @plt to function name. */
6760 arelent
*p
= (arelent
*) s
->udata
.p
;
6763 size
= strlen (s
->name
);
6764 memcpy (names
, s
->name
, size
);
6771 memcpy (names
, "+0x", sizeof ("+0x") - 1);
6772 names
+= sizeof ("+0x") - 1;
6773 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
6774 for (a
= buf
; *a
== '0'; ++a
)
6777 memcpy (names
, a
, size
);
6780 memcpy (names
, "@plt", sizeof ("@plt"));
6781 names
+= sizeof ("@plt");
6785 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
6786 if (plts
[j
].contents
!= NULL
)
6787 free (plts
[j
].contents
);
6794 /* Handle an x86-64 specific section when reading an object file. This
6795 is called when elfcode.h finds a section with an unknown type. */
6798 elf_x86_64_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
6799 const char *name
, int shindex
)
6801 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
6804 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6810 /* Hook called by the linker routine which adds symbols from an object
6811 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
6815 elf_x86_64_add_symbol_hook (bfd
*abfd
,
6816 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6817 Elf_Internal_Sym
*sym
,
6818 const char **namep ATTRIBUTE_UNUSED
,
6819 flagword
*flagsp ATTRIBUTE_UNUSED
,
6825 switch (sym
->st_shndx
)
6827 case SHN_X86_64_LCOMMON
:
6828 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
6831 lcomm
= bfd_make_section_with_flags (abfd
,
6835 | SEC_LINKER_CREATED
));
6838 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
6841 *valp
= sym
->st_size
;
6849 /* Given a BFD section, try to locate the corresponding ELF section
6853 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6854 asection
*sec
, int *index_return
)
6856 if (sec
== &_bfd_elf_large_com_section
)
6858 *index_return
= SHN_X86_64_LCOMMON
;
6864 /* Process a symbol. */
6867 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6870 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6872 switch (elfsym
->internal_elf_sym
.st_shndx
)
6874 case SHN_X86_64_LCOMMON
:
6875 asym
->section
= &_bfd_elf_large_com_section
;
6876 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6877 /* Common symbol doesn't set BSF_GLOBAL. */
6878 asym
->flags
&= ~BSF_GLOBAL
;
6884 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
6886 return (sym
->st_shndx
== SHN_COMMON
6887 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
6891 elf_x86_64_common_section_index (asection
*sec
)
6893 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6896 return SHN_X86_64_LCOMMON
;
6900 elf_x86_64_common_section (asection
*sec
)
6902 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
6903 return bfd_com_section_ptr
;
6905 return &_bfd_elf_large_com_section
;
6909 elf_x86_64_merge_symbol (struct elf_link_hash_entry
*h
,
6910 const Elf_Internal_Sym
*sym
,
6915 const asection
*oldsec
)
6917 /* A normal common symbol and a large common symbol result in a
6918 normal common symbol. We turn the large common symbol into a
6921 && h
->root
.type
== bfd_link_hash_common
6923 && bfd_is_com_section (*psec
)
6926 if (sym
->st_shndx
== SHN_COMMON
6927 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) != 0)
6929 h
->root
.u
.c
.p
->section
6930 = bfd_make_section_old_way (oldbfd
, "COMMON");
6931 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
6933 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
6934 && (elf_section_flags (oldsec
) & SHF_X86_64_LARGE
) == 0)
6935 *psec
= bfd_com_section_ptr
;
6942 elf_x86_64_additional_program_headers (bfd
*abfd
,
6943 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6948 /* Check to see if we need a large readonly segment. */
6949 s
= bfd_get_section_by_name (abfd
, ".lrodata");
6950 if (s
&& (s
->flags
& SEC_LOAD
))
6953 /* Check to see if we need a large data segment. Since .lbss sections
6954 is placed right after the .bss section, there should be no need for
6955 a large data segment just because of .lbss. */
6956 s
= bfd_get_section_by_name (abfd
, ".ldata");
6957 if (s
&& (s
->flags
& SEC_LOAD
))
6963 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6966 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
6968 if (h
->plt
.offset
!= (bfd_vma
) -1
6970 && !h
->pointer_equality_needed
)
6973 return _bfd_elf_hash_symbol (h
);
6976 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
6979 elf_x86_64_relocs_compatible (const bfd_target
*input
,
6980 const bfd_target
*output
)
6982 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
6983 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
6984 && _bfd_elf_relocs_compatible (input
, output
));
6987 /* Parse x86-64 GNU properties. */
6989 static enum elf_property_kind
6990 elf_x86_64_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
6991 bfd_byte
*ptr
, unsigned int datasz
)
6997 case GNU_PROPERTY_X86_ISA_1_USED
:
6998 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
7002 ((type
== GNU_PROPERTY_X86_ISA_1_USED
7003 ? _("error: %B: <corrupt x86 ISA used size: 0x%x>")
7004 : _("error: %B: <corrupt x86 ISA needed size: 0x%x>")),
7006 return property_corrupt
;
7008 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
7009 prop
->u
.number
= bfd_h_get_32 (abfd
, ptr
);
7010 prop
->pr_kind
= property_number
;
7014 return property_ignored
;
7017 return property_number
;
7020 /* Merge x86-64 GNU property BPROP with APROP. If APROP isn't NULL,
7021 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
7022 should be merged with ABFD. */
7025 elf_x86_64_merge_gnu_properties (bfd
*abfd ATTRIBUTE_UNUSED
,
7026 elf_property
*aprop
,
7027 elf_property
*bprop
)
7029 unsigned int number
;
7030 bfd_boolean updated
= FALSE
;
7031 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
7035 case GNU_PROPERTY_X86_ISA_1_USED
:
7036 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
7037 if (aprop
!= NULL
&& bprop
!= NULL
)
7039 number
= aprop
->u
.number
;
7040 aprop
->u
.number
= number
| bprop
->u
.number
;
7041 updated
= number
!= (unsigned int) aprop
->u
.number
;
7045 /* Return TRUE if APROP is NULL to indicate that BPROP should
7046 be added to ABFD. */
7047 updated
= aprop
== NULL
;
7052 /* Never should happen. */
7059 /* Set up x86-64 GNU properties. Return the first relocatable ELF input
7060 with GNU properties if found. Otherwise, return NULL. */
7063 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info
*info
)
7065 bfd_boolean normal_target
;
7066 bfd_boolean lazy_plt
;
7067 asection
*sec
, *pltsec
;
7069 unsigned int plt_alignment
;
7070 struct elf_x86_64_link_hash_table
*htab
;
7071 bfd
*pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
7073 if (bfd_link_relocatable (info
))
7076 htab
= elf_x86_64_hash_table (info
);
7080 dynobj
= htab
->elf
.dynobj
;
7082 /* Set htab->elf.dynobj here so that there is no need to check and
7083 set it in check_relocs. */
7088 /* Find a normal input file to hold linker created
7090 for (abfd
= info
->input_bfds
;
7092 abfd
= abfd
->link
.next
)
7094 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0)
7096 htab
->elf
.dynobj
= abfd
;
7102 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
7103 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
7104 canonical function address. */
7105 htab
->plt
.has_plt0
= 1;
7107 if (get_elf_x86_64_backend_data (info
->output_bfd
)->os
7112 htab
->lazy_plt
= &elf_x86_64_lazy_bnd_plt
;
7113 htab
->non_lazy_plt
= &elf_x86_64_non_lazy_bnd_plt
;
7117 htab
->lazy_plt
= &elf_x86_64_lazy_plt
;
7118 htab
->non_lazy_plt
= &elf_x86_64_non_lazy_plt
;
7120 normal_target
= TRUE
;
7124 htab
->lazy_plt
= &elf_x86_64_nacl_plt
;
7125 htab
->non_lazy_plt
= NULL
;
7126 normal_target
= FALSE
;
7129 pltsec
= htab
->elf
.splt
;
7131 /* If the non-lazy PLT is available, use it for all PLT entries if
7132 there are no PLT0 or no .plt section. */
7133 if (htab
->non_lazy_plt
!= NULL
7134 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
7138 = htab
->non_lazy_plt
->plt_entry
;
7139 htab
->plt
.plt_entry_size
7140 = htab
->non_lazy_plt
->plt_entry_size
;
7141 htab
->plt
.plt_got_offset
7142 = htab
->non_lazy_plt
->plt_got_offset
;
7143 htab
->plt
.plt_got_insn_size
7144 = htab
->non_lazy_plt
->plt_got_insn_size
;
7145 htab
->plt
.eh_frame_plt_size
7146 = htab
->non_lazy_plt
->eh_frame_plt_size
;
7147 htab
->plt
.eh_frame_plt
7148 = htab
->non_lazy_plt
->eh_frame_plt
;
7154 = htab
->lazy_plt
->plt_entry
;
7155 htab
->plt
.plt_entry_size
7156 = htab
->lazy_plt
->plt_entry_size
;
7157 htab
->plt
.plt_got_offset
7158 = htab
->lazy_plt
->plt_got_offset
;
7159 htab
->plt
.plt_got_insn_size
7160 = htab
->lazy_plt
->plt_got_insn_size
;
7161 htab
->plt
.eh_frame_plt_size
7162 = htab
->lazy_plt
->eh_frame_plt_size
;
7163 htab
->plt
.eh_frame_plt
7164 = htab
->lazy_plt
->eh_frame_plt
;
7167 /* Return if there are no normal input files. */
7171 /* Since create_dynamic_sections isn't always called, but GOT
7172 relocations need GOT relocations, create them here so that we
7173 don't need to do it in check_relocs. */
7174 if (htab
->elf
.sgot
== NULL
7175 && !_bfd_elf_create_got_section (dynobj
, info
))
7176 info
->callbacks
->einfo (_("%F: failed to create GOT sections\n"));
7178 /* Align .got and .got.plt sections to their entry size. Do it here
7179 instead of in create_dynamic_sections so that they are always
7180 properly aligned even if create_dynamic_sections isn't called. */
7181 sec
= htab
->elf
.sgot
;
7182 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7185 info
->callbacks
->einfo (_("%F%A: failed to align section\n"),
7189 sec
= htab
->elf
.sgotplt
;
7190 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7191 goto error_alignment
;
7193 /* Create the ifunc sections here so that check_relocs can be
7195 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
7196 info
->callbacks
->einfo (_("%F: failed to create ifunc sections\n"));
7198 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
7202 /* Whe creating executable, set the contents of the .interp
7203 section to the interpreter. */
7204 if (bfd_link_executable (info
) && !info
->nointerp
)
7206 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
7209 s
->size
= htab
->dynamic_interpreter_size
;
7210 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
7214 /* Don't change PLT section alignment for NaCl since it uses
7215 64-byte PLT entry and sets PLT section alignment to 32
7216 bytes. Don't create additional PLT sections for NaCl. */
7219 const struct elf_backend_data
*bed
7220 = get_elf_backend_data (dynobj
);
7221 flagword pltflags
= (bed
->dynamic_sec_flags
7226 unsigned int non_lazy_plt_alignment
7227 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
7230 if (!bfd_set_section_alignment (sec
->owner
, sec
,
7232 goto error_alignment
;
7234 /* Create the GOT procedure linkage table. */
7235 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7239 info
->callbacks
->einfo (_("%F: failed to create GOT PLT section\n"));
7241 if (!bfd_set_section_alignment (dynobj
, sec
,
7242 non_lazy_plt_alignment
))
7243 goto error_alignment
;
7245 htab
->plt_got
= sec
;
7247 /* MPX PLT is supported only for non-NaCl target in 64-bit
7248 mode and is needed only for lazy binding. */
7251 && ABI_64_P (htab
->elf
.dynobj
))
7253 /* Create the second PLT for Intel MPX support. */
7254 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7258 info
->callbacks
->einfo (_("%F: failed to create BND PLT section\n"));
7260 if (!bfd_set_section_alignment (dynobj
, sec
,
7261 non_lazy_plt_alignment
))
7262 goto error_alignment
;
7264 htab
->plt_bnd
= sec
;
7268 if (!info
->no_ld_generated_unwind_info
)
7270 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
7271 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
7272 | SEC_LINKER_CREATED
);
7274 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7278 info
->callbacks
->einfo (_("%F: failed to create PLT .eh_frame section\n"));
7280 if (!bfd_set_section_alignment (dynobj
, sec
,
7281 ABI_64_P (dynobj
) ? 3 : 2))
7282 goto error_alignment
;
7284 htab
->plt_eh_frame
= sec
;
7286 if (htab
->plt_got
!= NULL
)
7288 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7292 info
->callbacks
->einfo (_("%F: failed to create GOT PLT .eh_frame section\n"));
7294 if (!bfd_set_section_alignment (dynobj
, sec
,
7295 ABI_64_P (dynobj
) ? 3 : 2))
7296 goto error_alignment
;
7298 htab
->plt_got_eh_frame
= sec
;
7301 if (htab
->plt_bnd
!= NULL
)
7303 sec
= bfd_make_section_anyway_with_flags (dynobj
,
7307 info
->callbacks
->einfo (_("%F: failed to create BND PLT .eh_frame section\n"));
7309 if (!bfd_set_section_alignment (dynobj
, sec
, 3))
7310 goto error_alignment
;
7312 htab
->plt_bnd_eh_frame
= sec
;
7319 /* The .iplt section is used for IFUNC symbols in static
7321 sec
= htab
->elf
.iplt
;
7323 && !bfd_set_section_alignment (sec
->owner
, sec
,
7325 goto error_alignment
;
7331 static const struct bfd_elf_special_section
7332 elf_x86_64_special_sections
[]=
7334 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7335 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7336 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
7337 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7338 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
7339 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
7340 { NULL
, 0, 0, 0, 0 }
7343 #define TARGET_LITTLE_SYM x86_64_elf64_vec
7344 #define TARGET_LITTLE_NAME "elf64-x86-64"
7345 #define ELF_ARCH bfd_arch_i386
7346 #define ELF_TARGET_ID X86_64_ELF_DATA
7347 #define ELF_MACHINE_CODE EM_X86_64
7348 #define ELF_MAXPAGESIZE 0x200000
7349 #define ELF_MINPAGESIZE 0x1000
7350 #define ELF_COMMONPAGESIZE 0x1000
7352 #define elf_backend_can_gc_sections 1
7353 #define elf_backend_can_refcount 1
7354 #define elf_backend_want_got_plt 1
7355 #define elf_backend_plt_readonly 1
7356 #define elf_backend_want_plt_sym 0
7357 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
7358 #define elf_backend_rela_normal 1
7359 #define elf_backend_plt_alignment 4
7360 #define elf_backend_extern_protected_data 1
7361 #define elf_backend_caches_rawsize 1
7362 #define elf_backend_dtrel_excludes_plt 1
7363 #define elf_backend_want_dynrelro 1
7365 #define elf_info_to_howto elf_x86_64_info_to_howto
7367 #define bfd_elf64_bfd_link_hash_table_create \
7368 elf_x86_64_link_hash_table_create
7369 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
7370 #define bfd_elf64_bfd_reloc_name_lookup \
7371 elf_x86_64_reloc_name_lookup
7373 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
7374 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
7375 #define elf_backend_check_relocs elf_x86_64_check_relocs
7376 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
7377 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
7378 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
7379 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
7380 #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
7381 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
7382 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
7383 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
7385 #define elf_backend_write_core_note elf_x86_64_write_core_note
7387 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
7388 #define elf_backend_relocate_section elf_x86_64_relocate_section
7389 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
7390 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
7391 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7392 #define elf_backend_object_p elf64_x86_64_elf_object_p
7393 #define bfd_elf64_mkobject elf_x86_64_mkobject
7394 #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab
7396 #define elf_backend_section_from_shdr \
7397 elf_x86_64_section_from_shdr
7399 #define elf_backend_section_from_bfd_section \
7400 elf_x86_64_elf_section_from_bfd_section
7401 #define elf_backend_add_symbol_hook \
7402 elf_x86_64_add_symbol_hook
7403 #define elf_backend_symbol_processing \
7404 elf_x86_64_symbol_processing
7405 #define elf_backend_common_section_index \
7406 elf_x86_64_common_section_index
7407 #define elf_backend_common_section \
7408 elf_x86_64_common_section
7409 #define elf_backend_common_definition \
7410 elf_x86_64_common_definition
7411 #define elf_backend_merge_symbol \
7412 elf_x86_64_merge_symbol
7413 #define elf_backend_special_sections \
7414 elf_x86_64_special_sections
7415 #define elf_backend_additional_program_headers \
7416 elf_x86_64_additional_program_headers
7417 #define elf_backend_hash_symbol \
7418 elf_x86_64_hash_symbol
7419 #define elf_backend_omit_section_dynsym \
7420 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
7421 #define elf_backend_fixup_symbol \
7422 elf_x86_64_fixup_symbol
7423 #define elf_backend_parse_gnu_properties \
7424 elf_x86_64_parse_gnu_properties
7425 #define elf_backend_merge_gnu_properties \
7426 elf_x86_64_merge_gnu_properties
7427 #define elf_backend_setup_gnu_properties \
7428 elf_x86_64_link_setup_gnu_properties
7430 #include "elf64-target.h"
7432 /* CloudABI support. */
7434 #undef TARGET_LITTLE_SYM
7435 #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec
7436 #undef TARGET_LITTLE_NAME
7437 #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi"
7440 #define ELF_OSABI ELFOSABI_CLOUDABI
7443 #define elf64_bed elf64_x86_64_cloudabi_bed
7445 #include "elf64-target.h"
7447 /* FreeBSD support. */
7449 #undef TARGET_LITTLE_SYM
7450 #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec
7451 #undef TARGET_LITTLE_NAME
7452 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
7455 #define ELF_OSABI ELFOSABI_FREEBSD
7458 #define elf64_bed elf64_x86_64_fbsd_bed
7460 #include "elf64-target.h"
7462 /* Solaris 2 support. */
7464 #undef TARGET_LITTLE_SYM
7465 #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec
7466 #undef TARGET_LITTLE_NAME
7467 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
7469 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
7470 objects won't be recognized. */
7474 #define elf64_bed elf64_x86_64_sol2_bed
7476 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
7478 #undef elf_backend_static_tls_alignment
7479 #define elf_backend_static_tls_alignment 16
7481 /* The Solaris 2 ABI requires a plt symbol on all platforms.
7483 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
7485 #undef elf_backend_want_plt_sym
7486 #define elf_backend_want_plt_sym 1
7488 #undef elf_backend_strtab_flags
7489 #define elf_backend_strtab_flags SHF_STRINGS
7492 elf64_x86_64_copy_solaris_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
7493 bfd
*obfd ATTRIBUTE_UNUSED
,
7494 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
7495 Elf_Internal_Shdr
*osection ATTRIBUTE_UNUSED
)
7497 /* PR 19938: FIXME: Need to add code for setting the sh_info
7498 and sh_link fields of Solaris specific section types. */
7502 #undef elf_backend_copy_special_section_fields
7503 #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
7505 #include "elf64-target.h"
7507 /* Native Client support. */
7510 elf64_x86_64_nacl_elf_object_p (bfd
*abfd
)
7512 /* Set the right machine number for a NaCl x86-64 ELF64 file. */
7513 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64_nacl
);
7517 #undef TARGET_LITTLE_SYM
7518 #define TARGET_LITTLE_SYM x86_64_elf64_nacl_vec
7519 #undef TARGET_LITTLE_NAME
7520 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
7522 #define elf64_bed elf64_x86_64_nacl_bed
7524 #undef ELF_MAXPAGESIZE
7525 #undef ELF_MINPAGESIZE
7526 #undef ELF_COMMONPAGESIZE
7527 #define ELF_MAXPAGESIZE 0x10000
7528 #define ELF_MINPAGESIZE 0x10000
7529 #define ELF_COMMONPAGESIZE 0x10000
7531 /* Restore defaults. */
7533 #undef elf_backend_static_tls_alignment
7534 #undef elf_backend_want_plt_sym
7535 #define elf_backend_want_plt_sym 0
7536 #undef elf_backend_strtab_flags
7537 #undef elf_backend_copy_special_section_fields
7539 /* NaCl uses substantially different PLT entries for the same effects. */
7541 #undef elf_backend_plt_alignment
7542 #define elf_backend_plt_alignment 5
7543 #define NACL_PLT_ENTRY_SIZE 64
7544 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
7546 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
7548 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
7549 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
7550 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7551 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7552 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7554 /* 9-byte nop sequence to pad out to the next 32-byte boundary. */
7555 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw 0x0(%rax,%rax,1) */
7557 /* 32 bytes of nop to pad out to the standard size. */
7558 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7559 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7560 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7561 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7562 0x66, /* excess data16 prefix */
7566 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
7568 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
7569 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
7570 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
7571 0x41, 0xff, 0xe3, /* jmpq *%r11 */
7573 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
7574 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7575 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7577 /* Lazy GOT entries point here (32-byte aligned). */
7578 0x68, /* pushq immediate */
7579 0, 0, 0, 0, /* replaced with index into relocation table. */
7580 0xe9, /* jmp relative */
7581 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
7583 /* 22 bytes of nop to pad out to the standard size. */
7584 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data16 prefixes */
7585 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
7586 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
7589 /* .eh_frame covering the .plt section. */
7591 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
7593 #if (PLT_CIE_LENGTH != 20 \
7594 || PLT_FDE_LENGTH != 36 \
7595 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
7596 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
7597 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
7599 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
7600 0, 0, 0, 0, /* CIE ID */
7601 1, /* CIE version */
7602 'z', 'R', 0, /* Augmentation string */
7603 1, /* Code alignment factor */
7604 0x78, /* Data alignment factor */
7605 16, /* Return address column */
7606 1, /* Augmentation size */
7607 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
7608 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
7609 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
7610 DW_CFA_nop
, DW_CFA_nop
,
7612 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
7613 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
7614 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
7615 0, 0, 0, 0, /* .plt size goes here */
7616 0, /* Augmentation size */
7617 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
7618 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
7619 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
7620 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
7621 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
7622 13, /* Block length */
7623 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
7624 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
7625 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
7626 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
7627 DW_CFA_nop
, DW_CFA_nop
7630 static const struct elf_x86_64_lazy_plt_layout elf_x86_64_nacl_plt
=
7632 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
7633 elf_x86_64_nacl_plt_entry
, /* plt_entry */
7634 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
7635 2, /* plt0_got1_offset */
7636 9, /* plt0_got2_offset */
7637 13, /* plt0_got2_insn_end */
7638 3, /* plt_got_offset */
7639 33, /* plt_reloc_offset */
7640 38, /* plt_plt_offset */
7641 7, /* plt_got_insn_size */
7642 42, /* plt_plt_insn_end */
7643 32, /* plt_lazy_offset */
7644 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
7645 sizeof (elf_x86_64_nacl_eh_frame_plt
) /* eh_frame_plt_size */
7648 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
7653 #undef elf_backend_arch_data
7654 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
7656 #undef elf_backend_object_p
7657 #define elf_backend_object_p elf64_x86_64_nacl_elf_object_p
7658 #undef elf_backend_modify_segment_map
7659 #define elf_backend_modify_segment_map nacl_modify_segment_map
7660 #undef elf_backend_modify_program_headers
7661 #define elf_backend_modify_program_headers nacl_modify_program_headers
7662 #undef elf_backend_final_write_processing
7663 #define elf_backend_final_write_processing nacl_final_write_processing
7665 #include "elf64-target.h"
7667 /* Native Client x32 support. */
7670 elf32_x86_64_nacl_elf_object_p (bfd
*abfd
)
7672 /* Set the right machine number for a NaCl x86-64 ELF32 file. */
7673 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32_nacl
);
7677 #undef TARGET_LITTLE_SYM
7678 #define TARGET_LITTLE_SYM x86_64_elf32_nacl_vec
7679 #undef TARGET_LITTLE_NAME
7680 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
7682 #define elf32_bed elf32_x86_64_nacl_bed
7684 #define bfd_elf32_bfd_link_hash_table_create \
7685 elf_x86_64_link_hash_table_create
7686 #define bfd_elf32_bfd_reloc_type_lookup \
7687 elf_x86_64_reloc_type_lookup
7688 #define bfd_elf32_bfd_reloc_name_lookup \
7689 elf_x86_64_reloc_name_lookup
7690 #define bfd_elf32_mkobject \
7692 #define bfd_elf32_get_synthetic_symtab \
7693 elf_x86_64_get_synthetic_symtab
7695 #undef elf_backend_object_p
7696 #define elf_backend_object_p \
7697 elf32_x86_64_nacl_elf_object_p
7699 #undef elf_backend_bfd_from_remote_memory
7700 #define elf_backend_bfd_from_remote_memory \
7701 _bfd_elf32_bfd_from_remote_memory
7703 #undef elf_backend_size_info
7704 #define elf_backend_size_info \
7705 _bfd_elf32_size_info
7707 #include "elf32-target.h"
7709 /* Restore defaults. */
7710 #undef elf_backend_object_p
7711 #define elf_backend_object_p elf64_x86_64_elf_object_p
7712 #undef elf_backend_bfd_from_remote_memory
7713 #undef elf_backend_size_info
7714 #undef elf_backend_modify_segment_map
7715 #undef elf_backend_modify_program_headers
7716 #undef elf_backend_final_write_processing
7718 /* Intel L1OM support. */
7721 elf64_l1om_elf_object_p (bfd
*abfd
)
7723 /* Set the right machine number for an L1OM elf64 file. */
7724 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
7728 #undef TARGET_LITTLE_SYM
7729 #define TARGET_LITTLE_SYM l1om_elf64_vec
7730 #undef TARGET_LITTLE_NAME
7731 #define TARGET_LITTLE_NAME "elf64-l1om"
7733 #define ELF_ARCH bfd_arch_l1om
7735 #undef ELF_MACHINE_CODE
7736 #define ELF_MACHINE_CODE EM_L1OM
7741 #define elf64_bed elf64_l1om_bed
7743 #undef elf_backend_object_p
7744 #define elf_backend_object_p elf64_l1om_elf_object_p
7746 /* Restore defaults. */
7747 #undef ELF_MAXPAGESIZE
7748 #undef ELF_MINPAGESIZE
7749 #undef ELF_COMMONPAGESIZE
7750 #define ELF_MAXPAGESIZE 0x200000
7751 #define ELF_MINPAGESIZE 0x1000
7752 #define ELF_COMMONPAGESIZE 0x1000
7753 #undef elf_backend_plt_alignment
7754 #define elf_backend_plt_alignment 4
7755 #undef elf_backend_arch_data
7756 #define elf_backend_arch_data &elf_x86_64_arch_bed
7758 #include "elf64-target.h"
7760 /* FreeBSD L1OM support. */
7762 #undef TARGET_LITTLE_SYM
7763 #define TARGET_LITTLE_SYM l1om_elf64_fbsd_vec
7764 #undef TARGET_LITTLE_NAME
7765 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
7768 #define ELF_OSABI ELFOSABI_FREEBSD
7771 #define elf64_bed elf64_l1om_fbsd_bed
7773 #include "elf64-target.h"
7775 /* Intel K1OM support. */
7778 elf64_k1om_elf_object_p (bfd
*abfd
)
7780 /* Set the right machine number for an K1OM elf64 file. */
7781 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
7785 #undef TARGET_LITTLE_SYM
7786 #define TARGET_LITTLE_SYM k1om_elf64_vec
7787 #undef TARGET_LITTLE_NAME
7788 #define TARGET_LITTLE_NAME "elf64-k1om"
7790 #define ELF_ARCH bfd_arch_k1om
7792 #undef ELF_MACHINE_CODE
7793 #define ELF_MACHINE_CODE EM_K1OM
7798 #define elf64_bed elf64_k1om_bed
7800 #undef elf_backend_object_p
7801 #define elf_backend_object_p elf64_k1om_elf_object_p
7803 #undef elf_backend_static_tls_alignment
7805 #undef elf_backend_want_plt_sym
7806 #define elf_backend_want_plt_sym 0
7808 #include "elf64-target.h"
7810 /* FreeBSD K1OM support. */
7812 #undef TARGET_LITTLE_SYM
7813 #define TARGET_LITTLE_SYM k1om_elf64_fbsd_vec
7814 #undef TARGET_LITTLE_NAME
7815 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
7818 #define ELF_OSABI ELFOSABI_FREEBSD
7821 #define elf64_bed elf64_k1om_fbsd_bed
7823 #include "elf64-target.h"
7825 /* 32bit x86-64 support. */
7827 #undef TARGET_LITTLE_SYM
7828 #define TARGET_LITTLE_SYM x86_64_elf32_vec
7829 #undef TARGET_LITTLE_NAME
7830 #define TARGET_LITTLE_NAME "elf32-x86-64"
7834 #define ELF_ARCH bfd_arch_i386
7836 #undef ELF_MACHINE_CODE
7837 #define ELF_MACHINE_CODE EM_X86_64
7841 #undef elf_backend_object_p
7842 #define elf_backend_object_p \
7843 elf32_x86_64_elf_object_p
7845 #undef elf_backend_bfd_from_remote_memory
7846 #define elf_backend_bfd_from_remote_memory \
7847 _bfd_elf32_bfd_from_remote_memory
7849 #undef elf_backend_size_info
7850 #define elf_backend_size_info \
7851 _bfd_elf32_size_info
7853 #include "elf32-target.h"