1 /* X86-64 specific support for ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Jan Hubicka <jh@suse.cz>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "bfd_stdint.h"
33 #include "libiberty.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, 0, 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
,
152 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
153 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
154 "R_X86_64_GOTPC32_TLSDESC",
155 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
156 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
157 complain_overflow_dont
, bfd_elf_generic_reloc
,
158 "R_X86_64_TLSDESC_CALL",
160 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
161 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
163 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
164 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
165 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
167 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
168 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
171 /* We have a gap in the reloc numbers here.
172 R_X86_64_standard counts the number up to this point, and
173 R_X86_64_vt_offset is the value to subtract from a reloc type of
174 R_X86_64_GNU_VT* to form an index into this table. */
175 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
176 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
178 /* GNU extension to record C++ vtable hierarchy. */
179 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
180 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
182 /* GNU extension to record C++ vtable member usage. */
183 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
184 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
187 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
188 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
189 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
193 #define IS_X86_64_PCREL_TYPE(TYPE) \
194 ( ((TYPE) == R_X86_64_PC8) \
195 || ((TYPE) == R_X86_64_PC16) \
196 || ((TYPE) == R_X86_64_PC32) \
197 || ((TYPE) == R_X86_64_PC64))
199 /* Map BFD relocs to the x86_64 elf relocs. */
202 bfd_reloc_code_real_type bfd_reloc_val
;
203 unsigned char elf_reloc_val
;
206 static const struct elf_reloc_map x86_64_reloc_map
[] =
208 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
209 { BFD_RELOC_64
, R_X86_64_64
, },
210 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
211 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
212 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
213 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
214 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
215 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
216 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
217 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
218 { BFD_RELOC_32
, R_X86_64_32
, },
219 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
220 { BFD_RELOC_16
, R_X86_64_16
, },
221 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
222 { BFD_RELOC_8
, R_X86_64_8
, },
223 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
224 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
225 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
226 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
227 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
228 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
229 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
230 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
231 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
232 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
233 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
234 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
235 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
236 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
237 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
238 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
239 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
240 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
241 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
242 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
243 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
244 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
245 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
248 static reloc_howto_type
*
249 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
253 if (r_type
== (unsigned int) R_X86_64_32
)
258 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
260 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
261 || r_type
>= (unsigned int) R_X86_64_max
)
263 if (r_type
>= (unsigned int) R_X86_64_standard
)
265 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
267 r_type
= R_X86_64_NONE
;
272 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
273 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
274 return &x86_64_elf_howto_table
[i
];
277 /* Given a BFD reloc type, return a HOWTO structure. */
278 static reloc_howto_type
*
279 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
280 bfd_reloc_code_real_type code
)
284 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
287 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
288 return elf_x86_64_rtype_to_howto (abfd
,
289 x86_64_reloc_map
[i
].elf_reloc_val
);
294 static reloc_howto_type
*
295 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
300 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
302 /* Get x32 R_X86_64_32. */
303 reloc_howto_type
*reloc
304 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
305 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
309 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
310 if (x86_64_elf_howto_table
[i
].name
!= NULL
311 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
312 return &x86_64_elf_howto_table
[i
];
317 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
320 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
321 Elf_Internal_Rela
*dst
)
325 r_type
= ELF32_R_TYPE (dst
->r_info
);
326 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
327 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
330 /* Support for core dump NOTE sections. */
332 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
337 switch (note
->descsz
)
342 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
344 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
347 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
355 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
357 elf_tdata (abfd
)->core_signal
358 = bfd_get_16 (abfd
, note
->descdata
+ 12);
361 elf_tdata (abfd
)->core_lwpid
362 = bfd_get_32 (abfd
, note
->descdata
+ 32);
371 /* Make a ".reg/999" section. */
372 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
373 size
, note
->descpos
+ offset
);
377 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
379 switch (note
->descsz
)
384 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
385 elf_tdata (abfd
)->core_pid
386 = bfd_get_32 (abfd
, note
->descdata
+ 12);
387 elf_tdata (abfd
)->core_program
388 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
389 elf_tdata (abfd
)->core_command
390 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
393 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
394 elf_tdata (abfd
)->core_pid
395 = bfd_get_32 (abfd
, note
->descdata
+ 24);
396 elf_tdata (abfd
)->core_program
397 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
398 elf_tdata (abfd
)->core_command
399 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
402 /* Note that for some reason, a spurious space is tacked
403 onto the end of the args in some (at least one anyway)
404 implementations, so strip it off if it exists. */
407 char *command
= elf_tdata (abfd
)->core_command
;
408 int n
= strlen (command
);
410 if (0 < n
&& command
[n
- 1] == ' ')
411 command
[n
- 1] = '\0';
419 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
422 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
424 const char *fname
, *psargs
;
435 va_start (ap
, note_type
);
436 fname
= va_arg (ap
, const char *);
437 psargs
= va_arg (ap
, const char *);
440 if (bed
->s
->elfclass
== ELFCLASS32
)
443 memset (&data
, 0, sizeof (data
));
444 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
445 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
446 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
447 &data
, sizeof (data
));
452 memset (&data
, 0, sizeof (data
));
453 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
454 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
455 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
456 &data
, sizeof (data
));
461 va_start (ap
, note_type
);
462 pid
= va_arg (ap
, long);
463 cursig
= va_arg (ap
, int);
464 gregs
= va_arg (ap
, const void *);
467 if (bed
->s
->elfclass
== ELFCLASS32
)
469 if (bed
->elf_machine_code
== EM_X86_64
)
471 prstatusx32_t prstat
;
472 memset (&prstat
, 0, sizeof (prstat
));
474 prstat
.pr_cursig
= cursig
;
475 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
476 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
477 &prstat
, sizeof (prstat
));
482 memset (&prstat
, 0, sizeof (prstat
));
484 prstat
.pr_cursig
= cursig
;
485 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
486 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
487 &prstat
, sizeof (prstat
));
493 memset (&prstat
, 0, sizeof (prstat
));
495 prstat
.pr_cursig
= cursig
;
496 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
497 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
498 &prstat
, sizeof (prstat
));
505 /* Functions for the x86-64 ELF linker. */
507 /* The name of the dynamic interpreter. This is put in the .interp
510 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
511 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
513 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
514 copying dynamic variables from a shared lib into an app's dynbss
515 section, and instead use a dynamic relocation to point into the
517 #define ELIMINATE_COPY_RELOCS 1
519 /* The size in bytes of an entry in the global offset table. */
521 #define GOT_ENTRY_SIZE 8
523 /* The size in bytes of an entry in the procedure linkage table. */
525 #define PLT_ENTRY_SIZE 16
527 /* The first entry in a procedure linkage table looks like this. See the
528 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
530 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
532 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
533 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
534 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
537 /* Subsequent entries in a procedure linkage table look like this. */
539 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
541 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
542 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
543 0x68, /* pushq immediate */
544 0, 0, 0, 0, /* replaced with index into relocation table. */
545 0xe9, /* jmp relative */
546 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
549 /* .eh_frame covering the .plt section. */
551 static const bfd_byte elf_x86_64_eh_frame_plt
[] =
553 #define PLT_CIE_LENGTH 20
554 #define PLT_FDE_LENGTH 36
555 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
556 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
557 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
558 0, 0, 0, 0, /* CIE ID */
560 'z', 'R', 0, /* Augmentation string */
561 1, /* Code alignment factor */
562 0x78, /* Data alignment factor */
563 16, /* Return address column */
564 1, /* Augmentation size */
565 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
566 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
567 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
568 DW_CFA_nop
, DW_CFA_nop
,
570 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
571 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
572 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
573 0, 0, 0, 0, /* .plt size goes here */
574 0, /* Augmentation size */
575 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
576 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
577 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
578 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
579 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
580 11, /* Block length */
581 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
582 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
583 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
584 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
585 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
588 /* Architecture-specific backend data for x86-64. */
590 struct elf_x86_64_backend_data
592 /* Templates for the initial PLT entry and for subsequent entries. */
593 const bfd_byte
*plt0_entry
;
594 const bfd_byte
*plt_entry
;
595 unsigned int plt_entry_size
; /* Size of each PLT entry. */
597 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
598 unsigned int plt0_got1_offset
;
599 unsigned int plt0_got2_offset
;
601 /* Offset of the end of the PC-relative instruction containing
603 unsigned int plt0_got2_insn_end
;
605 /* Offsets into plt_entry that are to be replaced with... */
606 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
607 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
608 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
610 /* Length of the PC-relative instruction containing plt_got_offset. */
611 unsigned int plt_got_insn_size
;
613 /* Offset of the end of the PC-relative jump to plt0_entry. */
614 unsigned int plt_plt_insn_end
;
616 /* Offset into plt_entry where the initial value of the GOT entry points. */
617 unsigned int plt_lazy_offset
;
619 /* .eh_frame covering the .plt section. */
620 const bfd_byte
*eh_frame_plt
;
621 unsigned int eh_frame_plt_size
;
624 #define get_elf_x86_64_backend_data(abfd) \
625 ((const struct elf_x86_64_backend_data *) \
626 get_elf_backend_data (abfd)->arch_data)
628 #define GET_PLT_ENTRY_SIZE(abfd) \
629 get_elf_x86_64_backend_data (abfd)->plt_entry_size
631 /* These are the standard parameters. */
632 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
634 elf_x86_64_plt0_entry
, /* plt0_entry */
635 elf_x86_64_plt_entry
, /* plt_entry */
636 sizeof (elf_x86_64_plt_entry
), /* plt_entry_size */
637 2, /* plt0_got1_offset */
638 8, /* plt0_got2_offset */
639 12, /* plt0_got2_insn_end */
640 2, /* plt_got_offset */
641 7, /* plt_reloc_offset */
642 12, /* plt_plt_offset */
643 6, /* plt_got_insn_size */
644 PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
645 6, /* plt_lazy_offset */
646 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
647 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
650 #define elf_backend_arch_data &elf_x86_64_arch_bed
652 /* x86-64 ELF linker hash entry. */
654 struct elf_x86_64_link_hash_entry
656 struct elf_link_hash_entry elf
;
658 /* Track dynamic relocs copied for this symbol. */
659 struct elf_dyn_relocs
*dyn_relocs
;
661 #define GOT_UNKNOWN 0
665 #define GOT_TLS_GDESC 4
666 #define GOT_TLS_GD_BOTH_P(type) \
667 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
668 #define GOT_TLS_GD_P(type) \
669 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
670 #define GOT_TLS_GDESC_P(type) \
671 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
672 #define GOT_TLS_GD_ANY_P(type) \
673 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
674 unsigned char tls_type
;
676 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
677 starting at the end of the jump table. */
681 #define elf_x86_64_hash_entry(ent) \
682 ((struct elf_x86_64_link_hash_entry *)(ent))
684 struct elf_x86_64_obj_tdata
686 struct elf_obj_tdata root
;
688 /* tls_type for each local got entry. */
689 char *local_got_tls_type
;
691 /* GOTPLT entries for TLS descriptors. */
692 bfd_vma
*local_tlsdesc_gotent
;
695 #define elf_x86_64_tdata(abfd) \
696 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
698 #define elf_x86_64_local_got_tls_type(abfd) \
699 (elf_x86_64_tdata (abfd)->local_got_tls_type)
701 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
702 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
704 #define is_x86_64_elf(bfd) \
705 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
706 && elf_tdata (bfd) != NULL \
707 && elf_object_id (bfd) == X86_64_ELF_DATA)
710 elf_x86_64_mkobject (bfd
*abfd
)
712 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
716 /* x86-64 ELF linker hash table. */
718 struct elf_x86_64_link_hash_table
720 struct elf_link_hash_table elf
;
722 /* Short-cuts to get to dynamic linker sections. */
725 asection
*plt_eh_frame
;
729 bfd_signed_vma refcount
;
733 /* The amount of space used by the jump slots in the GOT. */
734 bfd_vma sgotplt_jump_table_size
;
736 /* Small local sym cache. */
737 struct sym_cache sym_cache
;
739 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
740 bfd_vma (*r_sym
) (bfd_vma
);
741 unsigned int pointer_r_type
;
742 const char *dynamic_interpreter
;
743 int dynamic_interpreter_size
;
745 /* _TLS_MODULE_BASE_ symbol. */
746 struct bfd_link_hash_entry
*tls_module_base
;
748 /* Used by local STT_GNU_IFUNC symbols. */
749 htab_t loc_hash_table
;
750 void * loc_hash_memory
;
752 /* The offset into splt of the PLT entry for the TLS descriptor
753 resolver. Special values are 0, if not necessary (or not found
754 to be necessary yet), and -1 if needed but not determined
757 /* The offset into sgot of the GOT entry used by the PLT entry
761 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
762 bfd_vma next_jump_slot_index
;
763 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
764 bfd_vma next_irelative_index
;
767 /* Get the x86-64 ELF linker hash table from a link_info structure. */
769 #define elf_x86_64_hash_table(p) \
770 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
771 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
773 #define elf_x86_64_compute_jump_table_size(htab) \
774 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
776 /* Create an entry in an x86-64 ELF linker hash table. */
778 static struct bfd_hash_entry
*
779 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
780 struct bfd_hash_table
*table
,
783 /* Allocate the structure if it has not already been allocated by a
787 entry
= (struct bfd_hash_entry
*)
788 bfd_hash_allocate (table
,
789 sizeof (struct elf_x86_64_link_hash_entry
));
794 /* Call the allocation method of the superclass. */
795 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
798 struct elf_x86_64_link_hash_entry
*eh
;
800 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
801 eh
->dyn_relocs
= NULL
;
802 eh
->tls_type
= GOT_UNKNOWN
;
803 eh
->tlsdesc_got
= (bfd_vma
) -1;
809 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
810 for local symbol so that we can handle local STT_GNU_IFUNC symbols
811 as global symbol. We reuse indx and dynstr_index for local symbol
812 hash since they aren't used by global symbols in this backend. */
815 elf_x86_64_local_htab_hash (const void *ptr
)
817 struct elf_link_hash_entry
*h
818 = (struct elf_link_hash_entry
*) ptr
;
819 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
822 /* Compare local hash entries. */
825 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
827 struct elf_link_hash_entry
*h1
828 = (struct elf_link_hash_entry
*) ptr1
;
829 struct elf_link_hash_entry
*h2
830 = (struct elf_link_hash_entry
*) ptr2
;
832 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
835 /* Find and/or create a hash entry for local symbol. */
837 static struct elf_link_hash_entry
*
838 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
839 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
842 struct elf_x86_64_link_hash_entry e
, *ret
;
843 asection
*sec
= abfd
->sections
;
844 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
845 htab
->r_sym (rel
->r_info
));
848 e
.elf
.indx
= sec
->id
;
849 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
850 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
851 create
? INSERT
: NO_INSERT
);
858 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
862 ret
= (struct elf_x86_64_link_hash_entry
*)
863 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
864 sizeof (struct elf_x86_64_link_hash_entry
));
867 memset (ret
, 0, sizeof (*ret
));
868 ret
->elf
.indx
= sec
->id
;
869 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
870 ret
->elf
.dynindx
= -1;
876 /* Create an X86-64 ELF linker hash table. */
878 static struct bfd_link_hash_table
*
879 elf_x86_64_link_hash_table_create (bfd
*abfd
)
881 struct elf_x86_64_link_hash_table
*ret
;
882 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
884 ret
= (struct elf_x86_64_link_hash_table
*) bfd_malloc (amt
);
888 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
889 elf_x86_64_link_hash_newfunc
,
890 sizeof (struct elf_x86_64_link_hash_entry
),
899 ret
->plt_eh_frame
= NULL
;
900 ret
->sym_cache
.abfd
= NULL
;
901 ret
->tlsdesc_plt
= 0;
902 ret
->tlsdesc_got
= 0;
903 ret
->tls_ld_got
.refcount
= 0;
904 ret
->sgotplt_jump_table_size
= 0;
905 ret
->tls_module_base
= NULL
;
906 ret
->next_jump_slot_index
= 0;
907 ret
->next_irelative_index
= 0;
911 ret
->r_info
= elf64_r_info
;
912 ret
->r_sym
= elf64_r_sym
;
913 ret
->pointer_r_type
= R_X86_64_64
;
914 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
915 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
919 ret
->r_info
= elf32_r_info
;
920 ret
->r_sym
= elf32_r_sym
;
921 ret
->pointer_r_type
= R_X86_64_32
;
922 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
923 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
926 ret
->loc_hash_table
= htab_try_create (1024,
927 elf_x86_64_local_htab_hash
,
928 elf_x86_64_local_htab_eq
,
930 ret
->loc_hash_memory
= objalloc_create ();
931 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
937 return &ret
->elf
.root
;
940 /* Destroy an X86-64 ELF linker hash table. */
943 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
945 struct elf_x86_64_link_hash_table
*htab
946 = (struct elf_x86_64_link_hash_table
*) hash
;
948 if (htab
->loc_hash_table
)
949 htab_delete (htab
->loc_hash_table
);
950 if (htab
->loc_hash_memory
)
951 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
952 _bfd_generic_link_hash_table_free (hash
);
955 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
956 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
960 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
961 struct bfd_link_info
*info
)
963 struct elf_x86_64_link_hash_table
*htab
;
965 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
968 htab
= elf_x86_64_hash_table (info
);
972 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
974 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
977 || (!info
->shared
&& !htab
->srelbss
))
980 if (!info
->no_ld_generated_unwind_info
981 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
982 && htab
->elf
.splt
!= NULL
)
984 const struct elf_x86_64_backend_data
*const abed
985 = get_elf_x86_64_backend_data (dynobj
);
986 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
988 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
989 flags
| SEC_READONLY
);
990 if (htab
->plt_eh_frame
== NULL
991 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
994 htab
->plt_eh_frame
->size
= abed
->eh_frame_plt_size
;
995 htab
->plt_eh_frame
->contents
996 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
997 memcpy (htab
->plt_eh_frame
->contents
,
998 abed
->eh_frame_plt
, abed
->eh_frame_plt_size
);
1003 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1006 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1007 struct elf_link_hash_entry
*dir
,
1008 struct elf_link_hash_entry
*ind
)
1010 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1012 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1013 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1015 if (eind
->dyn_relocs
!= NULL
)
1017 if (edir
->dyn_relocs
!= NULL
)
1019 struct elf_dyn_relocs
**pp
;
1020 struct elf_dyn_relocs
*p
;
1022 /* Add reloc counts against the indirect sym to the direct sym
1023 list. Merge any entries against the same section. */
1024 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1026 struct elf_dyn_relocs
*q
;
1028 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1029 if (q
->sec
== p
->sec
)
1031 q
->pc_count
+= p
->pc_count
;
1032 q
->count
+= p
->count
;
1039 *pp
= edir
->dyn_relocs
;
1042 edir
->dyn_relocs
= eind
->dyn_relocs
;
1043 eind
->dyn_relocs
= NULL
;
1046 if (ind
->root
.type
== bfd_link_hash_indirect
1047 && dir
->got
.refcount
<= 0)
1049 edir
->tls_type
= eind
->tls_type
;
1050 eind
->tls_type
= GOT_UNKNOWN
;
1053 if (ELIMINATE_COPY_RELOCS
1054 && ind
->root
.type
!= bfd_link_hash_indirect
1055 && dir
->dynamic_adjusted
)
1057 /* If called to transfer flags for a weakdef during processing
1058 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1059 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1060 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1061 dir
->ref_regular
|= ind
->ref_regular
;
1062 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1063 dir
->needs_plt
|= ind
->needs_plt
;
1064 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1067 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1071 elf64_x86_64_elf_object_p (bfd
*abfd
)
1073 /* Set the right machine number for an x86-64 elf64 file. */
1074 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1079 elf32_x86_64_elf_object_p (bfd
*abfd
)
1081 /* Set the right machine number for an x86-64 elf32 file. */
1082 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
1086 /* Return TRUE if the TLS access code sequence support transition
1090 elf_x86_64_check_tls_transition (bfd
*abfd
,
1091 struct bfd_link_info
*info
,
1094 Elf_Internal_Shdr
*symtab_hdr
,
1095 struct elf_link_hash_entry
**sym_hashes
,
1096 unsigned int r_type
,
1097 const Elf_Internal_Rela
*rel
,
1098 const Elf_Internal_Rela
*relend
)
1101 unsigned long r_symndx
;
1102 struct elf_link_hash_entry
*h
;
1104 struct elf_x86_64_link_hash_table
*htab
;
1106 /* Get the section contents. */
1107 if (contents
== NULL
)
1109 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1110 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1113 /* FIXME: How to better handle error condition? */
1114 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1117 /* Cache the section contents for elf_link_input_bfd. */
1118 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1122 htab
= elf_x86_64_hash_table (info
);
1123 offset
= rel
->r_offset
;
1126 case R_X86_64_TLSGD
:
1127 case R_X86_64_TLSLD
:
1128 if ((rel
+ 1) >= relend
)
1131 if (r_type
== R_X86_64_TLSGD
)
1133 /* Check transition from GD access model. For 64bit, only
1134 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1135 .word 0x6666; rex64; call __tls_get_addr
1136 can transit to different access model. For 32bit, only
1137 leaq foo@tlsgd(%rip), %rdi
1138 .word 0x6666; rex64; call __tls_get_addr
1139 can transit to different access model. */
1141 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1142 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1144 if ((offset
+ 12) > sec
->size
1145 || memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1148 if (ABI_64_P (abfd
))
1151 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1157 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1163 /* Check transition from LD access model. Only
1164 leaq foo@tlsld(%rip), %rdi;
1166 can transit to different access model. */
1168 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1170 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1173 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0
1174 || 0xe8 != *(contents
+ offset
+ 4))
1178 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1179 if (r_symndx
< symtab_hdr
->sh_info
)
1182 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1183 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1184 may be versioned. */
1186 && h
->root
.root
.string
!= NULL
1187 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1188 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
1189 && (strncmp (h
->root
.root
.string
,
1190 "__tls_get_addr", 14) == 0));
1192 case R_X86_64_GOTTPOFF
:
1193 /* Check transition from IE access model:
1194 mov foo@gottpoff(%rip), %reg
1195 add foo@gottpoff(%rip), %reg
1198 /* Check REX prefix first. */
1199 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1201 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1202 if (val
!= 0x48 && val
!= 0x4c)
1204 /* X32 may have 0x44 REX prefix or no REX prefix. */
1205 if (ABI_64_P (abfd
))
1211 /* X32 may not have any REX prefix. */
1212 if (ABI_64_P (abfd
))
1214 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1218 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1219 if (val
!= 0x8b && val
!= 0x03)
1222 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1223 return (val
& 0xc7) == 5;
1225 case R_X86_64_GOTPC32_TLSDESC
:
1226 /* Check transition from GDesc access model:
1227 leaq x@tlsdesc(%rip), %rax
1229 Make sure it's a leaq adding rip to a 32-bit offset
1230 into any register, although it's probably almost always
1233 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1236 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1237 if ((val
& 0xfb) != 0x48)
1240 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1243 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1244 return (val
& 0xc7) == 0x05;
1246 case R_X86_64_TLSDESC_CALL
:
1247 /* Check transition from GDesc access model:
1248 call *x@tlsdesc(%rax)
1250 if (offset
+ 2 <= sec
->size
)
1252 /* Make sure that it's a call *x@tlsdesc(%rax). */
1253 static const unsigned char call
[] = { 0xff, 0x10 };
1254 return memcmp (contents
+ offset
, call
, 2) == 0;
1264 /* Return TRUE if the TLS access transition is OK or no transition
1265 will be performed. Update R_TYPE if there is a transition. */
1268 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1269 asection
*sec
, bfd_byte
*contents
,
1270 Elf_Internal_Shdr
*symtab_hdr
,
1271 struct elf_link_hash_entry
**sym_hashes
,
1272 unsigned int *r_type
, int tls_type
,
1273 const Elf_Internal_Rela
*rel
,
1274 const Elf_Internal_Rela
*relend
,
1275 struct elf_link_hash_entry
*h
,
1276 unsigned long r_symndx
)
1278 unsigned int from_type
= *r_type
;
1279 unsigned int to_type
= from_type
;
1280 bfd_boolean check
= TRUE
;
1282 /* Skip TLS transition for functions. */
1284 && (h
->type
== STT_FUNC
1285 || h
->type
== STT_GNU_IFUNC
))
1290 case R_X86_64_TLSGD
:
1291 case R_X86_64_GOTPC32_TLSDESC
:
1292 case R_X86_64_TLSDESC_CALL
:
1293 case R_X86_64_GOTTPOFF
:
1294 if (info
->executable
)
1297 to_type
= R_X86_64_TPOFF32
;
1299 to_type
= R_X86_64_GOTTPOFF
;
1302 /* When we are called from elf_x86_64_relocate_section,
1303 CONTENTS isn't NULL and there may be additional transitions
1304 based on TLS_TYPE. */
1305 if (contents
!= NULL
)
1307 unsigned int new_to_type
= to_type
;
1309 if (info
->executable
1312 && tls_type
== GOT_TLS_IE
)
1313 new_to_type
= R_X86_64_TPOFF32
;
1315 if (to_type
== R_X86_64_TLSGD
1316 || to_type
== R_X86_64_GOTPC32_TLSDESC
1317 || to_type
== R_X86_64_TLSDESC_CALL
)
1319 if (tls_type
== GOT_TLS_IE
)
1320 new_to_type
= R_X86_64_GOTTPOFF
;
1323 /* We checked the transition before when we were called from
1324 elf_x86_64_check_relocs. We only want to check the new
1325 transition which hasn't been checked before. */
1326 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1327 to_type
= new_to_type
;
1332 case R_X86_64_TLSLD
:
1333 if (info
->executable
)
1334 to_type
= R_X86_64_TPOFF32
;
1341 /* Return TRUE if there is no transition. */
1342 if (from_type
== to_type
)
1345 /* Check if the transition can be performed. */
1347 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1348 symtab_hdr
, sym_hashes
,
1349 from_type
, rel
, relend
))
1351 reloc_howto_type
*from
, *to
;
1354 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1355 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1358 name
= h
->root
.root
.string
;
1361 struct elf_x86_64_link_hash_table
*htab
;
1363 htab
= elf_x86_64_hash_table (info
);
1368 Elf_Internal_Sym
*isym
;
1370 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1372 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1376 (*_bfd_error_handler
)
1377 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1378 "in section `%A' failed"),
1379 abfd
, sec
, from
->name
, to
->name
, name
,
1380 (unsigned long) rel
->r_offset
);
1381 bfd_set_error (bfd_error_bad_value
);
1389 /* Look through the relocs for a section during the first phase, and
1390 calculate needed space in the global offset table, procedure
1391 linkage table, and dynamic reloc sections. */
1394 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1396 const Elf_Internal_Rela
*relocs
)
1398 struct elf_x86_64_link_hash_table
*htab
;
1399 Elf_Internal_Shdr
*symtab_hdr
;
1400 struct elf_link_hash_entry
**sym_hashes
;
1401 const Elf_Internal_Rela
*rel
;
1402 const Elf_Internal_Rela
*rel_end
;
1405 if (info
->relocatable
)
1408 BFD_ASSERT (is_x86_64_elf (abfd
));
1410 htab
= elf_x86_64_hash_table (info
);
1414 symtab_hdr
= &elf_symtab_hdr (abfd
);
1415 sym_hashes
= elf_sym_hashes (abfd
);
1419 rel_end
= relocs
+ sec
->reloc_count
;
1420 for (rel
= relocs
; rel
< rel_end
; rel
++)
1422 unsigned int r_type
;
1423 unsigned long r_symndx
;
1424 struct elf_link_hash_entry
*h
;
1425 Elf_Internal_Sym
*isym
;
1428 r_symndx
= htab
->r_sym (rel
->r_info
);
1429 r_type
= ELF32_R_TYPE (rel
->r_info
);
1431 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1433 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1438 if (r_symndx
< symtab_hdr
->sh_info
)
1440 /* A local symbol. */
1441 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1446 /* Check relocation against local STT_GNU_IFUNC symbol. */
1447 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1449 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1454 /* Fake a STT_GNU_IFUNC symbol. */
1455 h
->type
= STT_GNU_IFUNC
;
1458 h
->forced_local
= 1;
1459 h
->root
.type
= bfd_link_hash_defined
;
1467 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1468 while (h
->root
.type
== bfd_link_hash_indirect
1469 || h
->root
.type
== bfd_link_hash_warning
)
1470 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1473 /* Check invalid x32 relocations. */
1474 if (!ABI_64_P (abfd
))
1480 case R_X86_64_DTPOFF64
:
1481 case R_X86_64_TPOFF64
:
1483 case R_X86_64_GOTOFF64
:
1484 case R_X86_64_GOT64
:
1485 case R_X86_64_GOTPCREL64
:
1486 case R_X86_64_GOTPC64
:
1487 case R_X86_64_GOTPLT64
:
1488 case R_X86_64_PLTOFF64
:
1491 name
= h
->root
.root
.string
;
1493 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1495 (*_bfd_error_handler
)
1496 (_("%B: relocation %s against symbol `%s' isn't "
1497 "supported in x32 mode"), abfd
,
1498 x86_64_elf_howto_table
[r_type
].name
, name
);
1499 bfd_set_error (bfd_error_bad_value
);
1507 /* Create the ifunc sections for static executables. If we
1508 never see an indirect function symbol nor we are building
1509 a static executable, those sections will be empty and
1510 won't appear in output. */
1521 case R_X86_64_PLT32
:
1522 case R_X86_64_GOTPCREL
:
1523 case R_X86_64_GOTPCREL64
:
1524 if (htab
->elf
.dynobj
== NULL
)
1525 htab
->elf
.dynobj
= abfd
;
1526 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1531 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1532 it here if it is defined in a non-shared object. */
1533 if (h
->type
== STT_GNU_IFUNC
1536 /* It is referenced by a non-shared object. */
1540 /* STT_GNU_IFUNC symbol must go through PLT. */
1541 h
->plt
.refcount
+= 1;
1543 /* STT_GNU_IFUNC needs dynamic sections. */
1544 if (htab
->elf
.dynobj
== NULL
)
1545 htab
->elf
.dynobj
= abfd
;
1550 if (h
->root
.root
.string
)
1551 name
= h
->root
.root
.string
;
1553 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1555 (*_bfd_error_handler
)
1556 (_("%B: relocation %s against STT_GNU_IFUNC "
1557 "symbol `%s' isn't handled by %s"), abfd
,
1558 x86_64_elf_howto_table
[r_type
].name
,
1559 name
, __FUNCTION__
);
1560 bfd_set_error (bfd_error_bad_value
);
1564 if (ABI_64_P (abfd
))
1568 h
->pointer_equality_needed
= 1;
1571 /* We must copy these reloc types into the output
1572 file. Create a reloc section in dynobj and
1573 make room for this reloc. */
1574 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1575 (abfd
, info
, sec
, sreloc
,
1576 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1587 if (r_type
!= R_X86_64_PC32
1588 && r_type
!= R_X86_64_PC64
)
1589 h
->pointer_equality_needed
= 1;
1592 case R_X86_64_PLT32
:
1595 case R_X86_64_GOTPCREL
:
1596 case R_X86_64_GOTPCREL64
:
1597 h
->got
.refcount
+= 1;
1598 if (htab
->elf
.sgot
== NULL
1599 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1609 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1610 symtab_hdr
, sym_hashes
,
1611 &r_type
, GOT_UNKNOWN
,
1612 rel
, rel_end
, h
, r_symndx
))
1617 case R_X86_64_TLSLD
:
1618 htab
->tls_ld_got
.refcount
+= 1;
1621 case R_X86_64_TPOFF32
:
1622 if (!info
->executable
&& ABI_64_P (abfd
))
1625 name
= h
->root
.root
.string
;
1627 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1629 (*_bfd_error_handler
)
1630 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1632 x86_64_elf_howto_table
[r_type
].name
, name
);
1633 bfd_set_error (bfd_error_bad_value
);
1638 case R_X86_64_GOTTPOFF
:
1639 if (!info
->executable
)
1640 info
->flags
|= DF_STATIC_TLS
;
1643 case R_X86_64_GOT32
:
1644 case R_X86_64_GOTPCREL
:
1645 case R_X86_64_TLSGD
:
1646 case R_X86_64_GOT64
:
1647 case R_X86_64_GOTPCREL64
:
1648 case R_X86_64_GOTPLT64
:
1649 case R_X86_64_GOTPC32_TLSDESC
:
1650 case R_X86_64_TLSDESC_CALL
:
1651 /* This symbol requires a global offset table entry. */
1653 int tls_type
, old_tls_type
;
1657 default: tls_type
= GOT_NORMAL
; break;
1658 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1659 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1660 case R_X86_64_GOTPC32_TLSDESC
:
1661 case R_X86_64_TLSDESC_CALL
:
1662 tls_type
= GOT_TLS_GDESC
; break;
1667 if (r_type
== R_X86_64_GOTPLT64
)
1669 /* This relocation indicates that we also need
1670 a PLT entry, as this is a function. We don't need
1671 a PLT entry for local symbols. */
1673 h
->plt
.refcount
+= 1;
1675 h
->got
.refcount
+= 1;
1676 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1680 bfd_signed_vma
*local_got_refcounts
;
1682 /* This is a global offset table entry for a local symbol. */
1683 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1684 if (local_got_refcounts
== NULL
)
1688 size
= symtab_hdr
->sh_info
;
1689 size
*= sizeof (bfd_signed_vma
)
1690 + sizeof (bfd_vma
) + sizeof (char);
1691 local_got_refcounts
= ((bfd_signed_vma
*)
1692 bfd_zalloc (abfd
, size
));
1693 if (local_got_refcounts
== NULL
)
1695 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1696 elf_x86_64_local_tlsdesc_gotent (abfd
)
1697 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1698 elf_x86_64_local_got_tls_type (abfd
)
1699 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1701 local_got_refcounts
[r_symndx
] += 1;
1703 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1706 /* If a TLS symbol is accessed using IE at least once,
1707 there is no point to use dynamic model for it. */
1708 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1709 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1710 || tls_type
!= GOT_TLS_IE
))
1712 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1713 tls_type
= old_tls_type
;
1714 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1715 && GOT_TLS_GD_ANY_P (tls_type
))
1716 tls_type
|= old_tls_type
;
1720 name
= h
->root
.root
.string
;
1722 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1724 (*_bfd_error_handler
)
1725 (_("%B: '%s' accessed both as normal and thread local symbol"),
1731 if (old_tls_type
!= tls_type
)
1734 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1736 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1741 case R_X86_64_GOTOFF64
:
1742 case R_X86_64_GOTPC32
:
1743 case R_X86_64_GOTPC64
:
1745 if (htab
->elf
.sgot
== NULL
)
1747 if (htab
->elf
.dynobj
== NULL
)
1748 htab
->elf
.dynobj
= abfd
;
1749 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1755 case R_X86_64_PLT32
:
1756 /* This symbol requires a procedure linkage table entry. We
1757 actually build the entry in adjust_dynamic_symbol,
1758 because this might be a case of linking PIC code which is
1759 never referenced by a dynamic object, in which case we
1760 don't need to generate a procedure linkage table entry
1763 /* If this is a local symbol, we resolve it directly without
1764 creating a procedure linkage table entry. */
1769 h
->plt
.refcount
+= 1;
1772 case R_X86_64_PLTOFF64
:
1773 /* This tries to form the 'address' of a function relative
1774 to GOT. For global symbols we need a PLT entry. */
1778 h
->plt
.refcount
+= 1;
1783 if (!ABI_64_P (abfd
))
1788 /* Let's help debug shared library creation. These relocs
1789 cannot be used in shared libs. Don't error out for
1790 sections we don't care about, such as debug sections or
1791 non-constant sections. */
1793 && (sec
->flags
& SEC_ALLOC
) != 0
1794 && (sec
->flags
& SEC_READONLY
) != 0)
1797 name
= h
->root
.root
.string
;
1799 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1800 (*_bfd_error_handler
)
1801 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1802 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1803 bfd_set_error (bfd_error_bad_value
);
1814 if (h
!= NULL
&& info
->executable
)
1816 /* If this reloc is in a read-only section, we might
1817 need a copy reloc. We can't check reliably at this
1818 stage whether the section is read-only, as input
1819 sections have not yet been mapped to output sections.
1820 Tentatively set the flag for now, and correct in
1821 adjust_dynamic_symbol. */
1824 /* We may need a .plt entry if the function this reloc
1825 refers to is in a shared lib. */
1826 h
->plt
.refcount
+= 1;
1827 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1828 h
->pointer_equality_needed
= 1;
1831 /* If we are creating a shared library, and this is a reloc
1832 against a global symbol, or a non PC relative reloc
1833 against a local symbol, then we need to copy the reloc
1834 into the shared library. However, if we are linking with
1835 -Bsymbolic, we do not need to copy a reloc against a
1836 global symbol which is defined in an object we are
1837 including in the link (i.e., DEF_REGULAR is set). At
1838 this point we have not seen all the input files, so it is
1839 possible that DEF_REGULAR is not set now but will be set
1840 later (it is never cleared). In case of a weak definition,
1841 DEF_REGULAR may be cleared later by a strong definition in
1842 a shared library. We account for that possibility below by
1843 storing information in the relocs_copied field of the hash
1844 table entry. A similar situation occurs when creating
1845 shared libraries and symbol visibility changes render the
1848 If on the other hand, we are creating an executable, we
1849 may need to keep relocations for symbols satisfied by a
1850 dynamic library if we manage to avoid copy relocs for the
1853 && (sec
->flags
& SEC_ALLOC
) != 0
1854 && (! IS_X86_64_PCREL_TYPE (r_type
)
1856 && (! SYMBOLIC_BIND (info
, h
)
1857 || h
->root
.type
== bfd_link_hash_defweak
1858 || !h
->def_regular
))))
1859 || (ELIMINATE_COPY_RELOCS
1861 && (sec
->flags
& SEC_ALLOC
) != 0
1863 && (h
->root
.type
== bfd_link_hash_defweak
1864 || !h
->def_regular
)))
1866 struct elf_dyn_relocs
*p
;
1867 struct elf_dyn_relocs
**head
;
1869 /* We must copy these reloc types into the output file.
1870 Create a reloc section in dynobj and make room for
1874 if (htab
->elf
.dynobj
== NULL
)
1875 htab
->elf
.dynobj
= abfd
;
1877 sreloc
= _bfd_elf_make_dynamic_reloc_section
1878 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1879 abfd
, /*rela?*/ TRUE
);
1885 /* If this is a global symbol, we count the number of
1886 relocations we need for this symbol. */
1889 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1893 /* Track dynamic relocs needed for local syms too.
1894 We really need local syms available to do this
1899 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1904 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1908 /* Beware of type punned pointers vs strict aliasing
1910 vpp
= &(elf_section_data (s
)->local_dynrel
);
1911 head
= (struct elf_dyn_relocs
**)vpp
;
1915 if (p
== NULL
|| p
->sec
!= sec
)
1917 bfd_size_type amt
= sizeof *p
;
1919 p
= ((struct elf_dyn_relocs
*)
1920 bfd_alloc (htab
->elf
.dynobj
, amt
));
1931 if (IS_X86_64_PCREL_TYPE (r_type
))
1936 /* This relocation describes the C++ object vtable hierarchy.
1937 Reconstruct it for later use during GC. */
1938 case R_X86_64_GNU_VTINHERIT
:
1939 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1943 /* This relocation describes which C++ vtable entries are actually
1944 used. Record for later use during GC. */
1945 case R_X86_64_GNU_VTENTRY
:
1946 BFD_ASSERT (h
!= NULL
);
1948 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1960 /* Return the section that should be marked against GC for a given
1964 elf_x86_64_gc_mark_hook (asection
*sec
,
1965 struct bfd_link_info
*info
,
1966 Elf_Internal_Rela
*rel
,
1967 struct elf_link_hash_entry
*h
,
1968 Elf_Internal_Sym
*sym
)
1971 switch (ELF32_R_TYPE (rel
->r_info
))
1973 case R_X86_64_GNU_VTINHERIT
:
1974 case R_X86_64_GNU_VTENTRY
:
1978 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1981 /* Update the got entry reference counts for the section being removed. */
1984 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1986 const Elf_Internal_Rela
*relocs
)
1988 struct elf_x86_64_link_hash_table
*htab
;
1989 Elf_Internal_Shdr
*symtab_hdr
;
1990 struct elf_link_hash_entry
**sym_hashes
;
1991 bfd_signed_vma
*local_got_refcounts
;
1992 const Elf_Internal_Rela
*rel
, *relend
;
1994 if (info
->relocatable
)
1997 htab
= elf_x86_64_hash_table (info
);
2001 elf_section_data (sec
)->local_dynrel
= NULL
;
2003 symtab_hdr
= &elf_symtab_hdr (abfd
);
2004 sym_hashes
= elf_sym_hashes (abfd
);
2005 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2007 htab
= elf_x86_64_hash_table (info
);
2008 relend
= relocs
+ sec
->reloc_count
;
2009 for (rel
= relocs
; rel
< relend
; rel
++)
2011 unsigned long r_symndx
;
2012 unsigned int r_type
;
2013 struct elf_link_hash_entry
*h
= NULL
;
2015 r_symndx
= htab
->r_sym (rel
->r_info
);
2016 if (r_symndx
>= symtab_hdr
->sh_info
)
2018 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2019 while (h
->root
.type
== bfd_link_hash_indirect
2020 || h
->root
.type
== bfd_link_hash_warning
)
2021 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2025 /* A local symbol. */
2026 Elf_Internal_Sym
*isym
;
2028 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2031 /* Check relocation against local STT_GNU_IFUNC symbol. */
2033 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2035 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2043 struct elf_x86_64_link_hash_entry
*eh
;
2044 struct elf_dyn_relocs
**pp
;
2045 struct elf_dyn_relocs
*p
;
2047 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2049 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2052 /* Everything must go for SEC. */
2058 r_type
= ELF32_R_TYPE (rel
->r_info
);
2059 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
2060 symtab_hdr
, sym_hashes
,
2061 &r_type
, GOT_UNKNOWN
,
2062 rel
, relend
, h
, r_symndx
))
2067 case R_X86_64_TLSLD
:
2068 if (htab
->tls_ld_got
.refcount
> 0)
2069 htab
->tls_ld_got
.refcount
-= 1;
2072 case R_X86_64_TLSGD
:
2073 case R_X86_64_GOTPC32_TLSDESC
:
2074 case R_X86_64_TLSDESC_CALL
:
2075 case R_X86_64_GOTTPOFF
:
2076 case R_X86_64_GOT32
:
2077 case R_X86_64_GOTPCREL
:
2078 case R_X86_64_GOT64
:
2079 case R_X86_64_GOTPCREL64
:
2080 case R_X86_64_GOTPLT64
:
2083 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2084 h
->plt
.refcount
-= 1;
2085 if (h
->got
.refcount
> 0)
2086 h
->got
.refcount
-= 1;
2087 if (h
->type
== STT_GNU_IFUNC
)
2089 if (h
->plt
.refcount
> 0)
2090 h
->plt
.refcount
-= 1;
2093 else if (local_got_refcounts
!= NULL
)
2095 if (local_got_refcounts
[r_symndx
] > 0)
2096 local_got_refcounts
[r_symndx
] -= 1;
2110 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2114 case R_X86_64_PLT32
:
2115 case R_X86_64_PLTOFF64
:
2118 if (h
->plt
.refcount
> 0)
2119 h
->plt
.refcount
-= 1;
2131 /* Adjust a symbol defined by a dynamic object and referenced by a
2132 regular object. The current definition is in some section of the
2133 dynamic object, but we're not including those sections. We have to
2134 change the definition to something the rest of the link can
2138 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2139 struct elf_link_hash_entry
*h
)
2141 struct elf_x86_64_link_hash_table
*htab
;
2144 /* STT_GNU_IFUNC symbol must go through PLT. */
2145 if (h
->type
== STT_GNU_IFUNC
)
2147 if (h
->plt
.refcount
<= 0)
2149 h
->plt
.offset
= (bfd_vma
) -1;
2155 /* If this is a function, put it in the procedure linkage table. We
2156 will fill in the contents of the procedure linkage table later,
2157 when we know the address of the .got section. */
2158 if (h
->type
== STT_FUNC
2161 if (h
->plt
.refcount
<= 0
2162 || SYMBOL_CALLS_LOCAL (info
, h
)
2163 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2164 && h
->root
.type
== bfd_link_hash_undefweak
))
2166 /* This case can occur if we saw a PLT32 reloc in an input
2167 file, but the symbol was never referred to by a dynamic
2168 object, or if all references were garbage collected. In
2169 such a case, we don't actually need to build a procedure
2170 linkage table, and we can just do a PC32 reloc instead. */
2171 h
->plt
.offset
= (bfd_vma
) -1;
2178 /* It's possible that we incorrectly decided a .plt reloc was
2179 needed for an R_X86_64_PC32 reloc to a non-function sym in
2180 check_relocs. We can't decide accurately between function and
2181 non-function syms in check-relocs; Objects loaded later in
2182 the link may change h->type. So fix it now. */
2183 h
->plt
.offset
= (bfd_vma
) -1;
2185 /* If this is a weak symbol, and there is a real definition, the
2186 processor independent code will have arranged for us to see the
2187 real definition first, and we can just use the same value. */
2188 if (h
->u
.weakdef
!= NULL
)
2190 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2191 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2192 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2193 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2194 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2195 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2199 /* This is a reference to a symbol defined by a dynamic object which
2200 is not a function. */
2202 /* If we are creating a shared library, we must presume that the
2203 only references to the symbol are via the global offset table.
2204 For such cases we need not do anything here; the relocations will
2205 be handled correctly by relocate_section. */
2209 /* If there are no references to this symbol that do not use the
2210 GOT, we don't need to generate a copy reloc. */
2211 if (!h
->non_got_ref
)
2214 /* If -z nocopyreloc was given, we won't generate them either. */
2215 if (info
->nocopyreloc
)
2221 if (ELIMINATE_COPY_RELOCS
)
2223 struct elf_x86_64_link_hash_entry
* eh
;
2224 struct elf_dyn_relocs
*p
;
2226 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2227 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2229 s
= p
->sec
->output_section
;
2230 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2234 /* If we didn't find any dynamic relocs in read-only sections, then
2235 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2243 /* We must allocate the symbol in our .dynbss section, which will
2244 become part of the .bss section of the executable. There will be
2245 an entry for this symbol in the .dynsym section. The dynamic
2246 object will contain position independent code, so all references
2247 from the dynamic object to this symbol will go through the global
2248 offset table. The dynamic linker will use the .dynsym entry to
2249 determine the address it must put in the global offset table, so
2250 both the dynamic object and the regular object will refer to the
2251 same memory location for the variable. */
2253 htab
= elf_x86_64_hash_table (info
);
2257 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2258 to copy the initial value out of the dynamic object and into the
2259 runtime process image. */
2260 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2262 const struct elf_backend_data
*bed
;
2263 bed
= get_elf_backend_data (info
->output_bfd
);
2264 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2270 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2273 /* Allocate space in .plt, .got and associated reloc sections for
2277 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2279 struct bfd_link_info
*info
;
2280 struct elf_x86_64_link_hash_table
*htab
;
2281 struct elf_x86_64_link_hash_entry
*eh
;
2282 struct elf_dyn_relocs
*p
;
2283 const struct elf_backend_data
*bed
;
2284 unsigned int plt_entry_size
;
2286 if (h
->root
.type
== bfd_link_hash_indirect
)
2289 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2291 info
= (struct bfd_link_info
*) inf
;
2292 htab
= elf_x86_64_hash_table (info
);
2295 bed
= get_elf_backend_data (info
->output_bfd
);
2296 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2298 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2299 here if it is defined and referenced in a non-shared object. */
2300 if (h
->type
== STT_GNU_IFUNC
2302 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2306 else if (htab
->elf
.dynamic_sections_created
2307 && h
->plt
.refcount
> 0)
2309 /* Make sure this symbol is output as a dynamic symbol.
2310 Undefined weak syms won't yet be marked as dynamic. */
2311 if (h
->dynindx
== -1
2312 && !h
->forced_local
)
2314 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2319 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2321 asection
*s
= htab
->elf
.splt
;
2323 /* If this is the first .plt entry, make room for the special
2326 s
->size
+= plt_entry_size
;
2328 h
->plt
.offset
= s
->size
;
2330 /* If this symbol is not defined in a regular file, and we are
2331 not generating a shared library, then set the symbol to this
2332 location in the .plt. This is required to make function
2333 pointers compare as equal between the normal executable and
2334 the shared library. */
2338 h
->root
.u
.def
.section
= s
;
2339 h
->root
.u
.def
.value
= h
->plt
.offset
;
2342 /* Make room for this entry. */
2343 s
->size
+= plt_entry_size
;
2345 /* We also need to make an entry in the .got.plt section, which
2346 will be placed in the .got section by the linker script. */
2347 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2349 /* We also need to make an entry in the .rela.plt section. */
2350 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2351 htab
->elf
.srelplt
->reloc_count
++;
2355 h
->plt
.offset
= (bfd_vma
) -1;
2361 h
->plt
.offset
= (bfd_vma
) -1;
2365 eh
->tlsdesc_got
= (bfd_vma
) -1;
2367 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2368 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2369 if (h
->got
.refcount
> 0
2372 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2374 h
->got
.offset
= (bfd_vma
) -1;
2376 else if (h
->got
.refcount
> 0)
2380 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2382 /* Make sure this symbol is output as a dynamic symbol.
2383 Undefined weak syms won't yet be marked as dynamic. */
2384 if (h
->dynindx
== -1
2385 && !h
->forced_local
)
2387 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2391 if (GOT_TLS_GDESC_P (tls_type
))
2393 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2394 - elf_x86_64_compute_jump_table_size (htab
);
2395 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2396 h
->got
.offset
= (bfd_vma
) -2;
2398 if (! GOT_TLS_GDESC_P (tls_type
)
2399 || GOT_TLS_GD_P (tls_type
))
2402 h
->got
.offset
= s
->size
;
2403 s
->size
+= GOT_ENTRY_SIZE
;
2404 if (GOT_TLS_GD_P (tls_type
))
2405 s
->size
+= GOT_ENTRY_SIZE
;
2407 dyn
= htab
->elf
.dynamic_sections_created
;
2408 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2410 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2411 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2412 || tls_type
== GOT_TLS_IE
)
2413 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2414 else if (GOT_TLS_GD_P (tls_type
))
2415 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2416 else if (! GOT_TLS_GDESC_P (tls_type
)
2417 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2418 || h
->root
.type
!= bfd_link_hash_undefweak
)
2420 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2421 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2422 if (GOT_TLS_GDESC_P (tls_type
))
2424 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2425 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2429 h
->got
.offset
= (bfd_vma
) -1;
2431 if (eh
->dyn_relocs
== NULL
)
2434 /* In the shared -Bsymbolic case, discard space allocated for
2435 dynamic pc-relative relocs against symbols which turn out to be
2436 defined in regular objects. For the normal shared case, discard
2437 space for pc-relative relocs that have become local due to symbol
2438 visibility changes. */
2442 /* Relocs that use pc_count are those that appear on a call
2443 insn, or certain REL relocs that can generated via assembly.
2444 We want calls to protected symbols to resolve directly to the
2445 function rather than going via the plt. If people want
2446 function pointer comparisons to work as expected then they
2447 should avoid writing weird assembly. */
2448 if (SYMBOL_CALLS_LOCAL (info
, h
))
2450 struct elf_dyn_relocs
**pp
;
2452 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2454 p
->count
-= p
->pc_count
;
2463 /* Also discard relocs on undefined weak syms with non-default
2465 if (eh
->dyn_relocs
!= NULL
2466 && h
->root
.type
== bfd_link_hash_undefweak
)
2468 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2469 eh
->dyn_relocs
= NULL
;
2471 /* Make sure undefined weak symbols are output as a dynamic
2473 else if (h
->dynindx
== -1
2474 && ! h
->forced_local
2475 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2480 else if (ELIMINATE_COPY_RELOCS
)
2482 /* For the non-shared case, discard space for relocs against
2483 symbols which turn out to need copy relocs or are not
2489 || (htab
->elf
.dynamic_sections_created
2490 && (h
->root
.type
== bfd_link_hash_undefweak
2491 || h
->root
.type
== bfd_link_hash_undefined
))))
2493 /* Make sure this symbol is output as a dynamic symbol.
2494 Undefined weak syms won't yet be marked as dynamic. */
2495 if (h
->dynindx
== -1
2496 && ! h
->forced_local
2497 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2500 /* If that succeeded, we know we'll be keeping all the
2502 if (h
->dynindx
!= -1)
2506 eh
->dyn_relocs
= NULL
;
2511 /* Finally, allocate space. */
2512 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2516 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2518 BFD_ASSERT (sreloc
!= NULL
);
2520 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2526 /* Allocate space in .plt, .got and associated reloc sections for
2527 local dynamic relocs. */
2530 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2532 struct elf_link_hash_entry
*h
2533 = (struct elf_link_hash_entry
*) *slot
;
2535 if (h
->type
!= STT_GNU_IFUNC
2539 || h
->root
.type
!= bfd_link_hash_defined
)
2542 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2545 /* Find any dynamic relocs that apply to read-only sections. */
2548 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2551 struct elf_x86_64_link_hash_entry
*eh
;
2552 struct elf_dyn_relocs
*p
;
2554 /* Skip local IFUNC symbols. */
2555 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2558 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2559 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2561 asection
*s
= p
->sec
->output_section
;
2563 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2565 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2567 info
->flags
|= DF_TEXTREL
;
2569 if (info
->warn_shared_textrel
&& info
->shared
)
2570 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2571 p
->sec
->owner
, h
->root
.root
.string
,
2574 /* Not an error, just cut short the traversal. */
2581 /* Set the sizes of the dynamic sections. */
2584 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2585 struct bfd_link_info
*info
)
2587 struct elf_x86_64_link_hash_table
*htab
;
2592 const struct elf_backend_data
*bed
;
2594 htab
= elf_x86_64_hash_table (info
);
2597 bed
= get_elf_backend_data (output_bfd
);
2599 dynobj
= htab
->elf
.dynobj
;
2603 if (htab
->elf
.dynamic_sections_created
)
2605 /* Set the contents of the .interp section to the interpreter. */
2606 if (info
->executable
)
2608 s
= bfd_get_section_by_name (dynobj
, ".interp");
2611 s
->size
= htab
->dynamic_interpreter_size
;
2612 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2616 /* Set up .got offsets for local syms, and space for local dynamic
2618 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2620 bfd_signed_vma
*local_got
;
2621 bfd_signed_vma
*end_local_got
;
2622 char *local_tls_type
;
2623 bfd_vma
*local_tlsdesc_gotent
;
2624 bfd_size_type locsymcount
;
2625 Elf_Internal_Shdr
*symtab_hdr
;
2628 if (! is_x86_64_elf (ibfd
))
2631 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2633 struct elf_dyn_relocs
*p
;
2635 for (p
= (struct elf_dyn_relocs
*)
2636 (elf_section_data (s
)->local_dynrel
);
2640 if (!bfd_is_abs_section (p
->sec
)
2641 && bfd_is_abs_section (p
->sec
->output_section
))
2643 /* Input section has been discarded, either because
2644 it is a copy of a linkonce section or due to
2645 linker script /DISCARD/, so we'll be discarding
2648 else if (p
->count
!= 0)
2650 srel
= elf_section_data (p
->sec
)->sreloc
;
2651 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2652 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2653 && (info
->flags
& DF_TEXTREL
) == 0)
2655 info
->flags
|= DF_TEXTREL
;
2656 if (info
->warn_shared_textrel
&& info
->shared
)
2657 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2658 p
->sec
->owner
, p
->sec
);
2664 local_got
= elf_local_got_refcounts (ibfd
);
2668 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2669 locsymcount
= symtab_hdr
->sh_info
;
2670 end_local_got
= local_got
+ locsymcount
;
2671 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2672 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2674 srel
= htab
->elf
.srelgot
;
2675 for (; local_got
< end_local_got
;
2676 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2678 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2681 if (GOT_TLS_GDESC_P (*local_tls_type
))
2683 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2684 - elf_x86_64_compute_jump_table_size (htab
);
2685 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2686 *local_got
= (bfd_vma
) -2;
2688 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2689 || GOT_TLS_GD_P (*local_tls_type
))
2691 *local_got
= s
->size
;
2692 s
->size
+= GOT_ENTRY_SIZE
;
2693 if (GOT_TLS_GD_P (*local_tls_type
))
2694 s
->size
+= GOT_ENTRY_SIZE
;
2697 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2698 || *local_tls_type
== GOT_TLS_IE
)
2700 if (GOT_TLS_GDESC_P (*local_tls_type
))
2702 htab
->elf
.srelplt
->size
2703 += bed
->s
->sizeof_rela
;
2704 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2706 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2707 || GOT_TLS_GD_P (*local_tls_type
))
2708 srel
->size
+= bed
->s
->sizeof_rela
;
2712 *local_got
= (bfd_vma
) -1;
2716 if (htab
->tls_ld_got
.refcount
> 0)
2718 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2720 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2721 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2722 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2725 htab
->tls_ld_got
.offset
= -1;
2727 /* Allocate global sym .plt and .got entries, and space for global
2728 sym dynamic relocs. */
2729 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2732 /* Allocate .plt and .got entries, and space for local symbols. */
2733 htab_traverse (htab
->loc_hash_table
,
2734 elf_x86_64_allocate_local_dynrelocs
,
2737 /* For every jump slot reserved in the sgotplt, reloc_count is
2738 incremented. However, when we reserve space for TLS descriptors,
2739 it's not incremented, so in order to compute the space reserved
2740 for them, it suffices to multiply the reloc count by the jump
2743 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2744 so that R_X86_64_IRELATIVE entries come last. */
2745 if (htab
->elf
.srelplt
)
2747 htab
->sgotplt_jump_table_size
2748 = elf_x86_64_compute_jump_table_size (htab
);
2749 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2751 else if (htab
->elf
.irelplt
)
2752 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2754 if (htab
->tlsdesc_plt
)
2756 /* If we're not using lazy TLS relocations, don't generate the
2757 PLT and GOT entries they require. */
2758 if ((info
->flags
& DF_BIND_NOW
))
2759 htab
->tlsdesc_plt
= 0;
2762 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2763 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2764 /* Reserve room for the initial entry.
2765 FIXME: we could probably do away with it in this case. */
2766 if (htab
->elf
.splt
->size
== 0)
2767 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2768 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2769 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2773 if (htab
->elf
.sgotplt
)
2775 struct elf_link_hash_entry
*got
;
2776 got
= elf_link_hash_lookup (elf_hash_table (info
),
2777 "_GLOBAL_OFFSET_TABLE_",
2778 FALSE
, FALSE
, FALSE
);
2780 /* Don't allocate .got.plt section if there are no GOT nor PLT
2781 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2783 || !got
->ref_regular_nonweak
)
2784 && (htab
->elf
.sgotplt
->size
2785 == get_elf_backend_data (output_bfd
)->got_header_size
)
2786 && (htab
->elf
.splt
== NULL
2787 || htab
->elf
.splt
->size
== 0)
2788 && (htab
->elf
.sgot
== NULL
2789 || htab
->elf
.sgot
->size
== 0)
2790 && (htab
->elf
.iplt
== NULL
2791 || htab
->elf
.iplt
->size
== 0)
2792 && (htab
->elf
.igotplt
== NULL
2793 || htab
->elf
.igotplt
->size
== 0))
2794 htab
->elf
.sgotplt
->size
= 0;
2797 /* We now have determined the sizes of the various dynamic sections.
2798 Allocate memory for them. */
2800 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2802 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2805 if (s
== htab
->elf
.splt
2806 || s
== htab
->elf
.sgot
2807 || s
== htab
->elf
.sgotplt
2808 || s
== htab
->elf
.iplt
2809 || s
== htab
->elf
.igotplt
2810 || s
== htab
->sdynbss
)
2812 /* Strip this section if we don't need it; see the
2815 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2817 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2820 /* We use the reloc_count field as a counter if we need
2821 to copy relocs into the output file. */
2822 if (s
!= htab
->elf
.srelplt
)
2827 /* It's not one of our sections, so don't allocate space. */
2833 /* If we don't need this section, strip it from the
2834 output file. This is mostly to handle .rela.bss and
2835 .rela.plt. We must create both sections in
2836 create_dynamic_sections, because they must be created
2837 before the linker maps input sections to output
2838 sections. The linker does that before
2839 adjust_dynamic_symbol is called, and it is that
2840 function which decides whether anything needs to go
2841 into these sections. */
2843 s
->flags
|= SEC_EXCLUDE
;
2847 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2850 /* Allocate memory for the section contents. We use bfd_zalloc
2851 here in case unused entries are not reclaimed before the
2852 section's contents are written out. This should not happen,
2853 but this way if it does, we get a R_X86_64_NONE reloc instead
2855 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2856 if (s
->contents
== NULL
)
2860 if (htab
->plt_eh_frame
!= NULL
2861 && htab
->elf
.splt
!= NULL
2862 && htab
->elf
.splt
->size
!= 0
2863 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2864 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2865 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2867 if (htab
->elf
.dynamic_sections_created
)
2869 /* Add some entries to the .dynamic section. We fill in the
2870 values later, in elf_x86_64_finish_dynamic_sections, but we
2871 must add the entries now so that we get the correct size for
2872 the .dynamic section. The DT_DEBUG entry is filled in by the
2873 dynamic linker and used by the debugger. */
2874 #define add_dynamic_entry(TAG, VAL) \
2875 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2877 if (info
->executable
)
2879 if (!add_dynamic_entry (DT_DEBUG
, 0))
2883 if (htab
->elf
.splt
->size
!= 0)
2885 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2886 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2887 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2888 || !add_dynamic_entry (DT_JMPREL
, 0))
2891 if (htab
->tlsdesc_plt
2892 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2893 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2899 if (!add_dynamic_entry (DT_RELA
, 0)
2900 || !add_dynamic_entry (DT_RELASZ
, 0)
2901 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2904 /* If any dynamic relocs apply to a read-only section,
2905 then we need a DT_TEXTREL entry. */
2906 if ((info
->flags
& DF_TEXTREL
) == 0)
2907 elf_link_hash_traverse (&htab
->elf
,
2908 elf_x86_64_readonly_dynrelocs
,
2911 if ((info
->flags
& DF_TEXTREL
) != 0)
2913 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2918 #undef add_dynamic_entry
2924 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2925 struct bfd_link_info
*info
)
2927 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2931 struct elf_link_hash_entry
*tlsbase
;
2933 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2934 "_TLS_MODULE_BASE_",
2935 FALSE
, FALSE
, FALSE
);
2937 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2939 struct elf_x86_64_link_hash_table
*htab
;
2940 struct bfd_link_hash_entry
*bh
= NULL
;
2941 const struct elf_backend_data
*bed
2942 = get_elf_backend_data (output_bfd
);
2944 htab
= elf_x86_64_hash_table (info
);
2948 if (!(_bfd_generic_link_add_one_symbol
2949 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2950 tls_sec
, 0, NULL
, FALSE
,
2951 bed
->collect
, &bh
)))
2954 htab
->tls_module_base
= bh
;
2956 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2957 tlsbase
->def_regular
= 1;
2958 tlsbase
->other
= STV_HIDDEN
;
2959 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2966 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2967 executables. Rather than setting it to the beginning of the TLS
2968 section, we have to set it to the end. This function may be called
2969 multiple times, it is idempotent. */
2972 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2974 struct elf_x86_64_link_hash_table
*htab
;
2975 struct bfd_link_hash_entry
*base
;
2977 if (!info
->executable
)
2980 htab
= elf_x86_64_hash_table (info
);
2984 base
= htab
->tls_module_base
;
2988 base
->u
.def
.value
= htab
->elf
.tls_size
;
2991 /* Return the base VMA address which should be subtracted from real addresses
2992 when resolving @dtpoff relocation.
2993 This is PT_TLS segment p_vaddr. */
2996 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2998 /* If tls_sec is NULL, we should have signalled an error already. */
2999 if (elf_hash_table (info
)->tls_sec
== NULL
)
3001 return elf_hash_table (info
)->tls_sec
->vma
;
3004 /* Return the relocation value for @tpoff relocation
3005 if STT_TLS virtual address is ADDRESS. */
3008 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3010 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3011 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3012 bfd_vma static_tls_size
;
3014 /* If tls_segment is NULL, we should have signalled an error already. */
3015 if (htab
->tls_sec
== NULL
)
3018 /* Consider special static TLS alignment requirements. */
3019 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3020 return address
- static_tls_size
- htab
->tls_sec
->vma
;
3023 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3027 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
3029 /* Opcode Instruction
3032 0x0f 0x8x conditional jump */
3034 && (contents
[offset
- 1] == 0xe8
3035 || contents
[offset
- 1] == 0xe9))
3037 && contents
[offset
- 2] == 0x0f
3038 && (contents
[offset
- 1] & 0xf0) == 0x80));
3041 /* Relocate an x86_64 ELF section. */
3044 elf_x86_64_relocate_section (bfd
*output_bfd
,
3045 struct bfd_link_info
*info
,
3047 asection
*input_section
,
3049 Elf_Internal_Rela
*relocs
,
3050 Elf_Internal_Sym
*local_syms
,
3051 asection
**local_sections
)
3053 struct elf_x86_64_link_hash_table
*htab
;
3054 Elf_Internal_Shdr
*symtab_hdr
;
3055 struct elf_link_hash_entry
**sym_hashes
;
3056 bfd_vma
*local_got_offsets
;
3057 bfd_vma
*local_tlsdesc_gotents
;
3058 Elf_Internal_Rela
*rel
;
3059 Elf_Internal_Rela
*relend
;
3060 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3062 BFD_ASSERT (is_x86_64_elf (input_bfd
));
3064 htab
= elf_x86_64_hash_table (info
);
3067 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3068 sym_hashes
= elf_sym_hashes (input_bfd
);
3069 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3070 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
3072 elf_x86_64_set_tls_module_base (info
);
3075 relend
= relocs
+ input_section
->reloc_count
;
3076 for (; rel
< relend
; rel
++)
3078 unsigned int r_type
;
3079 reloc_howto_type
*howto
;
3080 unsigned long r_symndx
;
3081 struct elf_link_hash_entry
*h
;
3082 Elf_Internal_Sym
*sym
;
3084 bfd_vma off
, offplt
;
3086 bfd_boolean unresolved_reloc
;
3087 bfd_reloc_status_type r
;
3091 r_type
= ELF32_R_TYPE (rel
->r_info
);
3092 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3093 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3096 if (r_type
>= R_X86_64_max
)
3098 bfd_set_error (bfd_error_bad_value
);
3102 if (r_type
!= (int) R_X86_64_32
3103 || ABI_64_P (output_bfd
))
3104 howto
= x86_64_elf_howto_table
+ r_type
;
3106 howto
= (x86_64_elf_howto_table
3107 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3108 r_symndx
= htab
->r_sym (rel
->r_info
);
3112 unresolved_reloc
= FALSE
;
3113 if (r_symndx
< symtab_hdr
->sh_info
)
3115 sym
= local_syms
+ r_symndx
;
3116 sec
= local_sections
[r_symndx
];
3118 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3121 /* Relocate against local STT_GNU_IFUNC symbol. */
3122 if (!info
->relocatable
3123 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3125 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3130 /* Set STT_GNU_IFUNC symbol value. */
3131 h
->root
.u
.def
.value
= sym
->st_value
;
3132 h
->root
.u
.def
.section
= sec
;
3137 bfd_boolean warned ATTRIBUTE_UNUSED
;
3139 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3140 r_symndx
, symtab_hdr
, sym_hashes
,
3142 unresolved_reloc
, warned
);
3145 if (sec
!= NULL
&& elf_discarded_section (sec
))
3146 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3147 rel
, relend
, howto
, contents
);
3149 if (info
->relocatable
)
3152 if (rel
->r_addend
== 0
3153 && r_type
== R_X86_64_64
3154 && !ABI_64_P (output_bfd
))
3156 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3157 it to 64bit if addend is zero. */
3158 r_type
= R_X86_64_32
;
3159 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3162 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3163 it here if it is defined in a non-shared object. */
3165 && h
->type
== STT_GNU_IFUNC
3172 if ((input_section
->flags
& SEC_ALLOC
) == 0
3173 || h
->plt
.offset
== (bfd_vma
) -1)
3176 /* STT_GNU_IFUNC symbol must go through PLT. */
3177 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3178 relocation
= (plt
->output_section
->vma
3179 + plt
->output_offset
+ h
->plt
.offset
);
3184 if (h
->root
.root
.string
)
3185 name
= h
->root
.root
.string
;
3187 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3189 (*_bfd_error_handler
)
3190 (_("%B: relocation %s against STT_GNU_IFUNC "
3191 "symbol `%s' isn't handled by %s"), input_bfd
,
3192 x86_64_elf_howto_table
[r_type
].name
,
3193 name
, __FUNCTION__
);
3194 bfd_set_error (bfd_error_bad_value
);
3203 if (ABI_64_P (output_bfd
))
3207 if (rel
->r_addend
!= 0)
3209 if (h
->root
.root
.string
)
3210 name
= h
->root
.root
.string
;
3212 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3214 (*_bfd_error_handler
)
3215 (_("%B: relocation %s against STT_GNU_IFUNC "
3216 "symbol `%s' has non-zero addend: %d"),
3217 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3218 name
, rel
->r_addend
);
3219 bfd_set_error (bfd_error_bad_value
);
3223 /* Generate dynamic relcoation only when there is a
3224 non-GOT reference in a shared object. */
3225 if (info
->shared
&& h
->non_got_ref
)
3227 Elf_Internal_Rela outrel
;
3230 /* Need a dynamic relocation to get the real function
3232 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3236 if (outrel
.r_offset
== (bfd_vma
) -1
3237 || outrel
.r_offset
== (bfd_vma
) -2)
3240 outrel
.r_offset
+= (input_section
->output_section
->vma
3241 + input_section
->output_offset
);
3243 if (h
->dynindx
== -1
3245 || info
->executable
)
3247 /* This symbol is resolved locally. */
3248 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3249 outrel
.r_addend
= (h
->root
.u
.def
.value
3250 + h
->root
.u
.def
.section
->output_section
->vma
3251 + h
->root
.u
.def
.section
->output_offset
);
3255 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3256 outrel
.r_addend
= 0;
3259 sreloc
= htab
->elf
.irelifunc
;
3260 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3262 /* If this reloc is against an external symbol, we
3263 do not want to fiddle with the addend. Otherwise,
3264 we need to include the symbol value so that it
3265 becomes an addend for the dynamic reloc. For an
3266 internal symbol, we have updated addend. */
3272 case R_X86_64_PLT32
:
3275 case R_X86_64_GOTPCREL
:
3276 case R_X86_64_GOTPCREL64
:
3277 base_got
= htab
->elf
.sgot
;
3278 off
= h
->got
.offset
;
3280 if (base_got
== NULL
)
3283 if (off
== (bfd_vma
) -1)
3285 /* We can't use h->got.offset here to save state, or
3286 even just remember the offset, as finish_dynamic_symbol
3287 would use that as offset into .got. */
3289 if (htab
->elf
.splt
!= NULL
)
3291 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3292 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3293 base_got
= htab
->elf
.sgotplt
;
3297 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3298 off
= plt_index
* GOT_ENTRY_SIZE
;
3299 base_got
= htab
->elf
.igotplt
;
3302 if (h
->dynindx
== -1
3306 /* This references the local defitionion. We must
3307 initialize this entry in the global offset table.
3308 Since the offset must always be a multiple of 8,
3309 we use the least significant bit to record
3310 whether we have initialized it already.
3312 When doing a dynamic link, we create a .rela.got
3313 relocation entry to initialize the value. This
3314 is done in the finish_dynamic_symbol routine. */
3319 bfd_put_64 (output_bfd
, relocation
,
3320 base_got
->contents
+ off
);
3321 /* Note that this is harmless for the GOTPLT64
3322 case, as -1 | 1 still is -1. */
3328 relocation
= (base_got
->output_section
->vma
3329 + base_got
->output_offset
+ off
);
3335 /* When generating a shared object, the relocations handled here are
3336 copied into the output file to be resolved at run time. */
3339 case R_X86_64_GOT32
:
3340 case R_X86_64_GOT64
:
3341 /* Relocation is to the entry for this symbol in the global
3343 case R_X86_64_GOTPCREL
:
3344 case R_X86_64_GOTPCREL64
:
3345 /* Use global offset table entry as symbol value. */
3346 case R_X86_64_GOTPLT64
:
3347 /* This is the same as GOT64 for relocation purposes, but
3348 indicates the existence of a PLT entry. The difficulty is,
3349 that we must calculate the GOT slot offset from the PLT
3350 offset, if this symbol got a PLT entry (it was global).
3351 Additionally if it's computed from the PLT entry, then that
3352 GOT offset is relative to .got.plt, not to .got. */
3353 base_got
= htab
->elf
.sgot
;
3355 if (htab
->elf
.sgot
== NULL
)
3362 off
= h
->got
.offset
;
3364 && h
->plt
.offset
!= (bfd_vma
)-1
3365 && off
== (bfd_vma
)-1)
3367 /* We can't use h->got.offset here to save
3368 state, or even just remember the offset, as
3369 finish_dynamic_symbol would use that as offset into
3371 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3372 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3373 base_got
= htab
->elf
.sgotplt
;
3376 dyn
= htab
->elf
.dynamic_sections_created
;
3378 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3380 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3381 || (ELF_ST_VISIBILITY (h
->other
)
3382 && h
->root
.type
== bfd_link_hash_undefweak
))
3384 /* This is actually a static link, or it is a -Bsymbolic
3385 link and the symbol is defined locally, or the symbol
3386 was forced to be local because of a version file. We
3387 must initialize this entry in the global offset table.
3388 Since the offset must always be a multiple of 8, we
3389 use the least significant bit to record whether we
3390 have initialized it already.
3392 When doing a dynamic link, we create a .rela.got
3393 relocation entry to initialize the value. This is
3394 done in the finish_dynamic_symbol routine. */
3399 bfd_put_64 (output_bfd
, relocation
,
3400 base_got
->contents
+ off
);
3401 /* Note that this is harmless for the GOTPLT64 case,
3402 as -1 | 1 still is -1. */
3407 unresolved_reloc
= FALSE
;
3411 if (local_got_offsets
== NULL
)
3414 off
= local_got_offsets
[r_symndx
];
3416 /* The offset must always be a multiple of 8. We use
3417 the least significant bit to record whether we have
3418 already generated the necessary reloc. */
3423 bfd_put_64 (output_bfd
, relocation
,
3424 base_got
->contents
+ off
);
3429 Elf_Internal_Rela outrel
;
3431 /* We need to generate a R_X86_64_RELATIVE reloc
3432 for the dynamic linker. */
3433 s
= htab
->elf
.srelgot
;
3437 outrel
.r_offset
= (base_got
->output_section
->vma
3438 + base_got
->output_offset
3440 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3441 outrel
.r_addend
= relocation
;
3442 elf_append_rela (output_bfd
, s
, &outrel
);
3445 local_got_offsets
[r_symndx
] |= 1;
3449 if (off
>= (bfd_vma
) -2)
3452 relocation
= base_got
->output_section
->vma
3453 + base_got
->output_offset
+ off
;
3454 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3455 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3456 - htab
->elf
.sgotplt
->output_offset
;
3460 case R_X86_64_GOTOFF64
:
3461 /* Relocation is relative to the start of the global offset
3464 /* Check to make sure it isn't a protected function symbol
3465 for shared library since it may not be local when used
3466 as function address. */
3467 if (!info
->executable
3469 && !SYMBOLIC_BIND (info
, h
)
3471 && h
->type
== STT_FUNC
3472 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3474 (*_bfd_error_handler
)
3475 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3476 input_bfd
, h
->root
.root
.string
);
3477 bfd_set_error (bfd_error_bad_value
);
3481 /* Note that sgot is not involved in this
3482 calculation. We always want the start of .got.plt. If we
3483 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3484 permitted by the ABI, we might have to change this
3486 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3487 + htab
->elf
.sgotplt
->output_offset
;
3490 case R_X86_64_GOTPC32
:
3491 case R_X86_64_GOTPC64
:
3492 /* Use global offset table as symbol value. */
3493 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3494 + htab
->elf
.sgotplt
->output_offset
;
3495 unresolved_reloc
= FALSE
;
3498 case R_X86_64_PLTOFF64
:
3499 /* Relocation is PLT entry relative to GOT. For local
3500 symbols it's the symbol itself relative to GOT. */
3502 /* See PLT32 handling. */
3503 && h
->plt
.offset
!= (bfd_vma
) -1
3504 && htab
->elf
.splt
!= NULL
)
3506 relocation
= (htab
->elf
.splt
->output_section
->vma
3507 + htab
->elf
.splt
->output_offset
3509 unresolved_reloc
= FALSE
;
3512 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3513 + htab
->elf
.sgotplt
->output_offset
;
3516 case R_X86_64_PLT32
:
3517 /* Relocation is to the entry for this symbol in the
3518 procedure linkage table. */
3520 /* Resolve a PLT32 reloc against a local symbol directly,
3521 without using the procedure linkage table. */
3525 if (h
->plt
.offset
== (bfd_vma
) -1
3526 || htab
->elf
.splt
== NULL
)
3528 /* We didn't make a PLT entry for this symbol. This
3529 happens when statically linking PIC code, or when
3530 using -Bsymbolic. */
3534 relocation
= (htab
->elf
.splt
->output_section
->vma
3535 + htab
->elf
.splt
->output_offset
3537 unresolved_reloc
= FALSE
;
3544 && (input_section
->flags
& SEC_ALLOC
) != 0
3545 && (input_section
->flags
& SEC_READONLY
) != 0
3548 bfd_boolean fail
= FALSE
;
3550 = (r_type
== R_X86_64_PC32
3551 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3553 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3555 /* Symbol is referenced locally. Make sure it is
3556 defined locally or for a branch. */
3557 fail
= !h
->def_regular
&& !branch
;
3561 /* Symbol isn't referenced locally. We only allow
3562 branch to symbol with non-default visibility. */
3564 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3571 const char *pic
= "";
3573 switch (ELF_ST_VISIBILITY (h
->other
))
3576 v
= _("hidden symbol");
3579 v
= _("internal symbol");
3582 v
= _("protected symbol");
3586 pic
= _("; recompile with -fPIC");
3591 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3593 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3595 (*_bfd_error_handler
) (fmt
, input_bfd
,
3596 x86_64_elf_howto_table
[r_type
].name
,
3597 v
, h
->root
.root
.string
, pic
);
3598 bfd_set_error (bfd_error_bad_value
);
3609 /* FIXME: The ABI says the linker should make sure the value is
3610 the same when it's zeroextended to 64 bit. */
3612 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3617 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3618 || h
->root
.type
!= bfd_link_hash_undefweak
)
3619 && (! IS_X86_64_PCREL_TYPE (r_type
)
3620 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3621 || (ELIMINATE_COPY_RELOCS
3628 || h
->root
.type
== bfd_link_hash_undefweak
3629 || h
->root
.type
== bfd_link_hash_undefined
)))
3631 Elf_Internal_Rela outrel
;
3632 bfd_boolean skip
, relocate
;
3635 /* When generating a shared object, these relocations
3636 are copied into the output file to be resolved at run
3642 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3644 if (outrel
.r_offset
== (bfd_vma
) -1)
3646 else if (outrel
.r_offset
== (bfd_vma
) -2)
3647 skip
= TRUE
, relocate
= TRUE
;
3649 outrel
.r_offset
+= (input_section
->output_section
->vma
3650 + input_section
->output_offset
);
3653 memset (&outrel
, 0, sizeof outrel
);
3655 /* h->dynindx may be -1 if this symbol was marked to
3659 && (IS_X86_64_PCREL_TYPE (r_type
)
3661 || ! SYMBOLIC_BIND (info
, h
)
3662 || ! h
->def_regular
))
3664 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3665 outrel
.r_addend
= rel
->r_addend
;
3669 /* This symbol is local, or marked to become local. */
3670 if (r_type
== htab
->pointer_r_type
)
3673 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3674 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3676 else if (r_type
== R_X86_64_64
3677 && !ABI_64_P (output_bfd
))
3680 outrel
.r_info
= htab
->r_info (0,
3681 R_X86_64_RELATIVE64
);
3682 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3688 if (bfd_is_abs_section (sec
))
3690 else if (sec
== NULL
|| sec
->owner
== NULL
)
3692 bfd_set_error (bfd_error_bad_value
);
3699 /* We are turning this relocation into one
3700 against a section symbol. It would be
3701 proper to subtract the symbol's value,
3702 osec->vma, from the emitted reloc addend,
3703 but ld.so expects buggy relocs. */
3704 osec
= sec
->output_section
;
3705 sindx
= elf_section_data (osec
)->dynindx
;
3708 asection
*oi
= htab
->elf
.text_index_section
;
3709 sindx
= elf_section_data (oi
)->dynindx
;
3711 BFD_ASSERT (sindx
!= 0);
3714 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3715 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3719 sreloc
= elf_section_data (input_section
)->sreloc
;
3721 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3723 r
= bfd_reloc_notsupported
;
3724 goto check_relocation_error
;
3727 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3729 /* If this reloc is against an external symbol, we do
3730 not want to fiddle with the addend. Otherwise, we
3731 need to include the symbol value so that it becomes
3732 an addend for the dynamic reloc. */
3739 case R_X86_64_TLSGD
:
3740 case R_X86_64_GOTPC32_TLSDESC
:
3741 case R_X86_64_TLSDESC_CALL
:
3742 case R_X86_64_GOTTPOFF
:
3743 tls_type
= GOT_UNKNOWN
;
3744 if (h
== NULL
&& local_got_offsets
)
3745 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3747 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3749 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3750 input_section
, contents
,
3751 symtab_hdr
, sym_hashes
,
3752 &r_type
, tls_type
, rel
,
3753 relend
, h
, r_symndx
))
3756 if (r_type
== R_X86_64_TPOFF32
)
3758 bfd_vma roff
= rel
->r_offset
;
3760 BFD_ASSERT (! unresolved_reloc
);
3762 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3764 /* GD->LE transition. For 64bit, change
3765 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3766 .word 0x6666; rex64; call __tls_get_addr
3769 leaq foo@tpoff(%rax), %rax
3771 leaq foo@tlsgd(%rip), %rdi
3772 .word 0x6666; rex64; call __tls_get_addr
3775 leaq foo@tpoff(%rax), %rax */
3776 if (ABI_64_P (output_bfd
))
3777 memcpy (contents
+ roff
- 4,
3778 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3781 memcpy (contents
+ roff
- 3,
3782 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3784 bfd_put_32 (output_bfd
,
3785 elf_x86_64_tpoff (info
, relocation
),
3786 contents
+ roff
+ 8);
3787 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3791 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3793 /* GDesc -> LE transition.
3794 It's originally something like:
3795 leaq x@tlsdesc(%rip), %rax
3798 movl $x@tpoff, %rax. */
3800 unsigned int val
, type
;
3802 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3803 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3804 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3805 contents
+ roff
- 3);
3806 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3807 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3808 contents
+ roff
- 1);
3809 bfd_put_32 (output_bfd
,
3810 elf_x86_64_tpoff (info
, relocation
),
3814 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3816 /* GDesc -> LE transition.
3821 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3822 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3825 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3827 /* IE->LE transition:
3828 Originally it can be one of:
3829 movq foo@gottpoff(%rip), %reg
3830 addq foo@gottpoff(%rip), %reg
3833 leaq foo(%reg), %reg
3836 unsigned int val
, type
, reg
;
3838 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3839 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3840 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3846 bfd_put_8 (output_bfd
, 0x49,
3847 contents
+ roff
- 3);
3848 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3849 bfd_put_8 (output_bfd
, 0x41,
3850 contents
+ roff
- 3);
3851 bfd_put_8 (output_bfd
, 0xc7,
3852 contents
+ roff
- 2);
3853 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3854 contents
+ roff
- 1);
3858 /* addq -> addq - addressing with %rsp/%r12 is
3861 bfd_put_8 (output_bfd
, 0x49,
3862 contents
+ roff
- 3);
3863 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3864 bfd_put_8 (output_bfd
, 0x41,
3865 contents
+ roff
- 3);
3866 bfd_put_8 (output_bfd
, 0x81,
3867 contents
+ roff
- 2);
3868 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3869 contents
+ roff
- 1);
3875 bfd_put_8 (output_bfd
, 0x4d,
3876 contents
+ roff
- 3);
3877 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3878 bfd_put_8 (output_bfd
, 0x45,
3879 contents
+ roff
- 3);
3880 bfd_put_8 (output_bfd
, 0x8d,
3881 contents
+ roff
- 2);
3882 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3883 contents
+ roff
- 1);
3885 bfd_put_32 (output_bfd
,
3886 elf_x86_64_tpoff (info
, relocation
),
3894 if (htab
->elf
.sgot
== NULL
)
3899 off
= h
->got
.offset
;
3900 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3904 if (local_got_offsets
== NULL
)
3907 off
= local_got_offsets
[r_symndx
];
3908 offplt
= local_tlsdesc_gotents
[r_symndx
];
3915 Elf_Internal_Rela outrel
;
3919 if (htab
->elf
.srelgot
== NULL
)
3922 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3924 if (GOT_TLS_GDESC_P (tls_type
))
3926 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3927 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3928 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3929 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3930 + htab
->elf
.sgotplt
->output_offset
3932 + htab
->sgotplt_jump_table_size
);
3933 sreloc
= htab
->elf
.srelplt
;
3935 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3937 outrel
.r_addend
= 0;
3938 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3941 sreloc
= htab
->elf
.srelgot
;
3943 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3944 + htab
->elf
.sgot
->output_offset
+ off
);
3946 if (GOT_TLS_GD_P (tls_type
))
3947 dr_type
= R_X86_64_DTPMOD64
;
3948 else if (GOT_TLS_GDESC_P (tls_type
))
3951 dr_type
= R_X86_64_TPOFF64
;
3953 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3954 outrel
.r_addend
= 0;
3955 if ((dr_type
== R_X86_64_TPOFF64
3956 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3957 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3958 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3960 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3962 if (GOT_TLS_GD_P (tls_type
))
3966 BFD_ASSERT (! unresolved_reloc
);
3967 bfd_put_64 (output_bfd
,
3968 relocation
- elf_x86_64_dtpoff_base (info
),
3969 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3973 bfd_put_64 (output_bfd
, 0,
3974 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3975 outrel
.r_info
= htab
->r_info (indx
,
3977 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3978 elf_append_rela (output_bfd
, sreloc
,
3987 local_got_offsets
[r_symndx
] |= 1;
3990 if (off
>= (bfd_vma
) -2
3991 && ! GOT_TLS_GDESC_P (tls_type
))
3993 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3995 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3996 || r_type
== R_X86_64_TLSDESC_CALL
)
3997 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3998 + htab
->elf
.sgotplt
->output_offset
3999 + offplt
+ htab
->sgotplt_jump_table_size
;
4001 relocation
= htab
->elf
.sgot
->output_section
->vma
4002 + htab
->elf
.sgot
->output_offset
+ off
;
4003 unresolved_reloc
= FALSE
;
4007 bfd_vma roff
= rel
->r_offset
;
4009 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4011 /* GD->IE transition. For 64bit, change
4012 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4013 .word 0x6666; rex64; call __tls_get_addr@plt
4016 addq foo@gottpoff(%rip), %rax
4018 leaq foo@tlsgd(%rip), %rdi
4019 .word 0x6666; rex64; call __tls_get_addr@plt
4022 addq foo@gottpoff(%rip), %rax */
4023 if (ABI_64_P (output_bfd
))
4024 memcpy (contents
+ roff
- 4,
4025 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4028 memcpy (contents
+ roff
- 3,
4029 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4032 relocation
= (htab
->elf
.sgot
->output_section
->vma
4033 + htab
->elf
.sgot
->output_offset
+ off
4035 - input_section
->output_section
->vma
4036 - input_section
->output_offset
4038 bfd_put_32 (output_bfd
, relocation
,
4039 contents
+ roff
+ 8);
4040 /* Skip R_X86_64_PLT32. */
4044 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4046 /* GDesc -> IE transition.
4047 It's originally something like:
4048 leaq x@tlsdesc(%rip), %rax
4051 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4053 /* Now modify the instruction as appropriate. To
4054 turn a leaq into a movq in the form we use it, it
4055 suffices to change the second byte from 0x8d to
4057 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4059 bfd_put_32 (output_bfd
,
4060 htab
->elf
.sgot
->output_section
->vma
4061 + htab
->elf
.sgot
->output_offset
+ off
4063 - input_section
->output_section
->vma
4064 - input_section
->output_offset
4069 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4071 /* GDesc -> IE transition.
4078 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4079 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4087 case R_X86_64_TLSLD
:
4088 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4089 input_section
, contents
,
4090 symtab_hdr
, sym_hashes
,
4091 &r_type
, GOT_UNKNOWN
,
4092 rel
, relend
, h
, r_symndx
))
4095 if (r_type
!= R_X86_64_TLSLD
)
4097 /* LD->LE transition:
4098 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4099 For 64bit, we change it into:
4100 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4101 For 32bit, we change it into:
4102 nopl 0x0(%rax); movl %fs:0, %eax. */
4104 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4105 if (ABI_64_P (output_bfd
))
4106 memcpy (contents
+ rel
->r_offset
- 3,
4107 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4109 memcpy (contents
+ rel
->r_offset
- 3,
4110 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4111 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4116 if (htab
->elf
.sgot
== NULL
)
4119 off
= htab
->tls_ld_got
.offset
;
4124 Elf_Internal_Rela outrel
;
4126 if (htab
->elf
.srelgot
== NULL
)
4129 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4130 + htab
->elf
.sgot
->output_offset
+ off
);
4132 bfd_put_64 (output_bfd
, 0,
4133 htab
->elf
.sgot
->contents
+ off
);
4134 bfd_put_64 (output_bfd
, 0,
4135 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4136 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4137 outrel
.r_addend
= 0;
4138 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4140 htab
->tls_ld_got
.offset
|= 1;
4142 relocation
= htab
->elf
.sgot
->output_section
->vma
4143 + htab
->elf
.sgot
->output_offset
+ off
;
4144 unresolved_reloc
= FALSE
;
4147 case R_X86_64_DTPOFF32
:
4148 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4149 relocation
-= elf_x86_64_dtpoff_base (info
);
4151 relocation
= elf_x86_64_tpoff (info
, relocation
);
4154 case R_X86_64_TPOFF32
:
4155 case R_X86_64_TPOFF64
:
4156 BFD_ASSERT (info
->executable
);
4157 relocation
= elf_x86_64_tpoff (info
, relocation
);
4164 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4165 because such sections are not SEC_ALLOC and thus ld.so will
4166 not process them. */
4167 if (unresolved_reloc
4168 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4170 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4171 rel
->r_offset
) != (bfd_vma
) -1)
4172 (*_bfd_error_handler
)
4173 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4176 (long) rel
->r_offset
,
4178 h
->root
.root
.string
);
4181 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4182 contents
, rel
->r_offset
,
4183 relocation
, rel
->r_addend
);
4185 check_relocation_error
:
4186 if (r
!= bfd_reloc_ok
)
4191 name
= h
->root
.root
.string
;
4194 name
= bfd_elf_string_from_elf_section (input_bfd
,
4195 symtab_hdr
->sh_link
,
4200 name
= bfd_section_name (input_bfd
, sec
);
4203 if (r
== bfd_reloc_overflow
)
4205 if (! ((*info
->callbacks
->reloc_overflow
)
4206 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4207 (bfd_vma
) 0, input_bfd
, input_section
,
4213 (*_bfd_error_handler
)
4214 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4215 input_bfd
, input_section
,
4216 (long) rel
->r_offset
, name
, (int) r
);
4225 /* Finish up dynamic symbol handling. We set the contents of various
4226 dynamic sections here. */
4229 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4230 struct bfd_link_info
*info
,
4231 struct elf_link_hash_entry
*h
,
4232 Elf_Internal_Sym
*sym
)
4234 struct elf_x86_64_link_hash_table
*htab
;
4235 const struct elf_x86_64_backend_data
*const abed
4236 = get_elf_x86_64_backend_data (output_bfd
);
4238 htab
= elf_x86_64_hash_table (info
);
4242 if (h
->plt
.offset
!= (bfd_vma
) -1)
4246 Elf_Internal_Rela rela
;
4248 asection
*plt
, *gotplt
, *relplt
;
4249 const struct elf_backend_data
*bed
;
4251 /* When building a static executable, use .iplt, .igot.plt and
4252 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4253 if (htab
->elf
.splt
!= NULL
)
4255 plt
= htab
->elf
.splt
;
4256 gotplt
= htab
->elf
.sgotplt
;
4257 relplt
= htab
->elf
.srelplt
;
4261 plt
= htab
->elf
.iplt
;
4262 gotplt
= htab
->elf
.igotplt
;
4263 relplt
= htab
->elf
.irelplt
;
4266 /* This symbol has an entry in the procedure linkage table. Set
4268 if ((h
->dynindx
== -1
4269 && !((h
->forced_local
|| info
->executable
)
4271 && h
->type
== STT_GNU_IFUNC
))
4277 /* Get the index in the procedure linkage table which
4278 corresponds to this symbol. This is the index of this symbol
4279 in all the symbols for which we are making plt entries. The
4280 first entry in the procedure linkage table is reserved.
4282 Get the offset into the .got table of the entry that
4283 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4284 bytes. The first three are reserved for the dynamic linker.
4286 For static executables, we don't reserve anything. */
4288 if (plt
== htab
->elf
.splt
)
4290 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
4291 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4295 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
4296 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4299 /* Fill in the entry in the procedure linkage table. */
4300 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
4301 abed
->plt_entry_size
);
4303 /* Insert the relocation positions of the plt section. */
4305 /* Put offset the PC-relative instruction referring to the GOT entry,
4306 subtracting the size of that instruction. */
4307 bfd_put_32 (output_bfd
,
4308 (gotplt
->output_section
->vma
4309 + gotplt
->output_offset
4311 - plt
->output_section
->vma
4312 - plt
->output_offset
4314 - abed
->plt_got_insn_size
),
4315 plt
->contents
+ h
->plt
.offset
+ abed
->plt_got_offset
);
4317 /* Fill in the entry in the global offset table, initially this
4318 points to the second part of the PLT entry. */
4319 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4320 + plt
->output_offset
4321 + h
->plt
.offset
+ abed
->plt_lazy_offset
),
4322 gotplt
->contents
+ got_offset
);
4324 /* Fill in the entry in the .rela.plt section. */
4325 rela
.r_offset
= (gotplt
->output_section
->vma
4326 + gotplt
->output_offset
4328 if (h
->dynindx
== -1
4329 || ((info
->executable
4330 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4332 && h
->type
== STT_GNU_IFUNC
))
4334 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4335 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4336 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4337 rela
.r_addend
= (h
->root
.u
.def
.value
4338 + h
->root
.u
.def
.section
->output_section
->vma
4339 + h
->root
.u
.def
.section
->output_offset
);
4340 /* R_X86_64_IRELATIVE comes last. */
4341 plt_index
= htab
->next_irelative_index
--;
4345 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4347 plt_index
= htab
->next_jump_slot_index
++;
4350 /* Don't fill PLT entry for static executables. */
4351 if (plt
== htab
->elf
.splt
)
4353 /* Put relocation index. */
4354 bfd_put_32 (output_bfd
, plt_index
,
4355 plt
->contents
+ h
->plt
.offset
+ abed
->plt_reloc_offset
);
4356 /* Put offset for jmp .PLT0. */
4357 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ abed
->plt_plt_insn_end
),
4358 plt
->contents
+ h
->plt
.offset
+ abed
->plt_plt_offset
);
4361 bed
= get_elf_backend_data (output_bfd
);
4362 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4363 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4365 if (!h
->def_regular
)
4367 /* Mark the symbol as undefined, rather than as defined in
4368 the .plt section. Leave the value if there were any
4369 relocations where pointer equality matters (this is a clue
4370 for the dynamic linker, to make function pointer
4371 comparisons work between an application and shared
4372 library), otherwise set it to zero. If a function is only
4373 called from a binary, there is no need to slow down
4374 shared libraries because of that. */
4375 sym
->st_shndx
= SHN_UNDEF
;
4376 if (!h
->pointer_equality_needed
)
4381 if (h
->got
.offset
!= (bfd_vma
) -1
4382 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4383 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4385 Elf_Internal_Rela rela
;
4387 /* This symbol has an entry in the global offset table. Set it
4389 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4392 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4393 + htab
->elf
.sgot
->output_offset
4394 + (h
->got
.offset
&~ (bfd_vma
) 1));
4396 /* If this is a static link, or it is a -Bsymbolic link and the
4397 symbol is defined locally or was forced to be local because
4398 of a version file, we just want to emit a RELATIVE reloc.
4399 The entry in the global offset table will already have been
4400 initialized in the relocate_section function. */
4402 && h
->type
== STT_GNU_IFUNC
)
4406 /* Generate R_X86_64_GLOB_DAT. */
4413 if (!h
->pointer_equality_needed
)
4416 /* For non-shared object, we can't use .got.plt, which
4417 contains the real function addres if we need pointer
4418 equality. We load the GOT entry with the PLT entry. */
4419 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4420 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4421 + plt
->output_offset
4423 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4427 else if (info
->shared
4428 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4430 if (!h
->def_regular
)
4432 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4433 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4434 rela
.r_addend
= (h
->root
.u
.def
.value
4435 + h
->root
.u
.def
.section
->output_section
->vma
4436 + h
->root
.u
.def
.section
->output_offset
);
4440 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4442 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4443 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4444 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4448 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4453 Elf_Internal_Rela rela
;
4455 /* This symbol needs a copy reloc. Set it up. */
4457 if (h
->dynindx
== -1
4458 || (h
->root
.type
!= bfd_link_hash_defined
4459 && h
->root
.type
!= bfd_link_hash_defweak
)
4460 || htab
->srelbss
== NULL
)
4463 rela
.r_offset
= (h
->root
.u
.def
.value
4464 + h
->root
.u
.def
.section
->output_section
->vma
4465 + h
->root
.u
.def
.section
->output_offset
);
4466 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4468 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4471 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4472 be NULL for local symbols. */
4474 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4475 || h
== htab
->elf
.hgot
))
4476 sym
->st_shndx
= SHN_ABS
;
4481 /* Finish up local dynamic symbol handling. We set the contents of
4482 various dynamic sections here. */
4485 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4487 struct elf_link_hash_entry
*h
4488 = (struct elf_link_hash_entry
*) *slot
;
4489 struct bfd_link_info
*info
4490 = (struct bfd_link_info
*) inf
;
4492 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4496 /* Used to decide how to sort relocs in an optimal manner for the
4497 dynamic linker, before writing them out. */
4499 static enum elf_reloc_type_class
4500 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4502 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4504 case R_X86_64_RELATIVE
:
4505 return reloc_class_relative
;
4506 case R_X86_64_JUMP_SLOT
:
4507 return reloc_class_plt
;
4509 return reloc_class_copy
;
4511 return reloc_class_normal
;
4515 /* Finish up the dynamic sections. */
4518 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4519 struct bfd_link_info
*info
)
4521 struct elf_x86_64_link_hash_table
*htab
;
4524 const struct elf_x86_64_backend_data
*const abed
4525 = get_elf_x86_64_backend_data (output_bfd
);
4527 htab
= elf_x86_64_hash_table (info
);
4531 dynobj
= htab
->elf
.dynobj
;
4532 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4534 if (htab
->elf
.dynamic_sections_created
)
4536 bfd_byte
*dyncon
, *dynconend
;
4537 const struct elf_backend_data
*bed
;
4538 bfd_size_type sizeof_dyn
;
4540 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4543 bed
= get_elf_backend_data (dynobj
);
4544 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4545 dyncon
= sdyn
->contents
;
4546 dynconend
= sdyn
->contents
+ sdyn
->size
;
4547 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4549 Elf_Internal_Dyn dyn
;
4552 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4560 s
= htab
->elf
.sgotplt
;
4561 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4565 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4569 s
= htab
->elf
.srelplt
->output_section
;
4570 dyn
.d_un
.d_val
= s
->size
;
4574 /* The procedure linkage table relocs (DT_JMPREL) should
4575 not be included in the overall relocs (DT_RELA).
4576 Therefore, we override the DT_RELASZ entry here to
4577 make it not include the JMPREL relocs. Since the
4578 linker script arranges for .rela.plt to follow all
4579 other relocation sections, we don't have to worry
4580 about changing the DT_RELA entry. */
4581 if (htab
->elf
.srelplt
!= NULL
)
4583 s
= htab
->elf
.srelplt
->output_section
;
4584 dyn
.d_un
.d_val
-= s
->size
;
4588 case DT_TLSDESC_PLT
:
4590 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4591 + htab
->tlsdesc_plt
;
4594 case DT_TLSDESC_GOT
:
4596 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4597 + htab
->tlsdesc_got
;
4601 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4604 /* Fill in the special first entry in the procedure linkage table. */
4605 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4607 /* Fill in the first entry in the procedure linkage table. */
4608 memcpy (htab
->elf
.splt
->contents
,
4609 abed
->plt0_entry
, abed
->plt_entry_size
);
4610 /* Add offset for pushq GOT+8(%rip), since the instruction
4611 uses 6 bytes subtract this value. */
4612 bfd_put_32 (output_bfd
,
4613 (htab
->elf
.sgotplt
->output_section
->vma
4614 + htab
->elf
.sgotplt
->output_offset
4616 - htab
->elf
.splt
->output_section
->vma
4617 - htab
->elf
.splt
->output_offset
4619 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
4620 /* Add offset for the PC-relative instruction accessing GOT+16,
4621 subtracting the offset to the end of that instruction. */
4622 bfd_put_32 (output_bfd
,
4623 (htab
->elf
.sgotplt
->output_section
->vma
4624 + htab
->elf
.sgotplt
->output_offset
4626 - htab
->elf
.splt
->output_section
->vma
4627 - htab
->elf
.splt
->output_offset
4628 - abed
->plt0_got2_insn_end
),
4629 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
4631 elf_section_data (htab
->elf
.splt
->output_section
)
4632 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
4634 if (htab
->tlsdesc_plt
)
4636 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4637 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4639 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4640 abed
->plt0_entry
, abed
->plt_entry_size
);
4642 /* Add offset for pushq GOT+8(%rip), since the
4643 instruction uses 6 bytes subtract this value. */
4644 bfd_put_32 (output_bfd
,
4645 (htab
->elf
.sgotplt
->output_section
->vma
4646 + htab
->elf
.sgotplt
->output_offset
4648 - htab
->elf
.splt
->output_section
->vma
4649 - htab
->elf
.splt
->output_offset
4652 htab
->elf
.splt
->contents
4653 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
4654 /* Add offset for the PC-relative instruction accessing GOT+TDG,
4655 where TGD stands for htab->tlsdesc_got, subtracting the offset
4656 to the end of that instruction. */
4657 bfd_put_32 (output_bfd
,
4658 (htab
->elf
.sgot
->output_section
->vma
4659 + htab
->elf
.sgot
->output_offset
4661 - htab
->elf
.splt
->output_section
->vma
4662 - htab
->elf
.splt
->output_offset
4664 - abed
->plt0_got2_insn_end
),
4665 htab
->elf
.splt
->contents
4666 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
4671 if (htab
->elf
.sgotplt
)
4673 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4675 (*_bfd_error_handler
)
4676 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4680 /* Fill in the first three entries in the global offset table. */
4681 if (htab
->elf
.sgotplt
->size
> 0)
4683 /* Set the first entry in the global offset table to the address of
4684 the dynamic section. */
4686 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4688 bfd_put_64 (output_bfd
,
4689 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4690 htab
->elf
.sgotplt
->contents
);
4691 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4692 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4693 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4696 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4700 /* Adjust .eh_frame for .plt section. */
4701 if (htab
->plt_eh_frame
!= NULL
)
4703 if (htab
->elf
.splt
!= NULL
4704 && htab
->elf
.splt
->size
!= 0
4705 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4706 && htab
->elf
.splt
->output_section
!= NULL
4707 && htab
->plt_eh_frame
->output_section
!= NULL
)
4709 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4710 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4711 + htab
->plt_eh_frame
->output_offset
4712 + PLT_FDE_START_OFFSET
;
4713 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4714 htab
->plt_eh_frame
->contents
4715 + PLT_FDE_START_OFFSET
);
4717 if (htab
->plt_eh_frame
->sec_info_type
4718 == ELF_INFO_TYPE_EH_FRAME
)
4720 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4722 htab
->plt_eh_frame
->contents
))
4727 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4728 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4731 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4732 htab_traverse (htab
->loc_hash_table
,
4733 elf_x86_64_finish_local_dynamic_symbol
,
4739 /* Return address for Ith PLT stub in section PLT, for relocation REL
4740 or (bfd_vma) -1 if it should not be included. */
4743 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4744 const arelent
*rel ATTRIBUTE_UNUSED
)
4746 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4749 /* Handle an x86-64 specific section when reading an object file. This
4750 is called when elfcode.h finds a section with an unknown type. */
4753 elf_x86_64_section_from_shdr (bfd
*abfd
,
4754 Elf_Internal_Shdr
*hdr
,
4758 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4761 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4767 /* Hook called by the linker routine which adds symbols from an object
4768 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4772 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4773 struct bfd_link_info
*info
,
4774 Elf_Internal_Sym
*sym
,
4775 const char **namep ATTRIBUTE_UNUSED
,
4776 flagword
*flagsp ATTRIBUTE_UNUSED
,
4782 switch (sym
->st_shndx
)
4784 case SHN_X86_64_LCOMMON
:
4785 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4788 lcomm
= bfd_make_section_with_flags (abfd
,
4792 | SEC_LINKER_CREATED
));
4795 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4798 *valp
= sym
->st_size
;
4802 if ((abfd
->flags
& DYNAMIC
) == 0
4803 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4804 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4805 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4811 /* Given a BFD section, try to locate the corresponding ELF section
4815 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4816 asection
*sec
, int *index_return
)
4818 if (sec
== &_bfd_elf_large_com_section
)
4820 *index_return
= SHN_X86_64_LCOMMON
;
4826 /* Process a symbol. */
4829 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4832 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4834 switch (elfsym
->internal_elf_sym
.st_shndx
)
4836 case SHN_X86_64_LCOMMON
:
4837 asym
->section
= &_bfd_elf_large_com_section
;
4838 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4839 /* Common symbol doesn't set BSF_GLOBAL. */
4840 asym
->flags
&= ~BSF_GLOBAL
;
4846 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4848 return (sym
->st_shndx
== SHN_COMMON
4849 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4853 elf_x86_64_common_section_index (asection
*sec
)
4855 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4858 return SHN_X86_64_LCOMMON
;
4862 elf_x86_64_common_section (asection
*sec
)
4864 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4865 return bfd_com_section_ptr
;
4867 return &_bfd_elf_large_com_section
;
4871 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4872 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4873 struct elf_link_hash_entry
*h
,
4874 Elf_Internal_Sym
*sym
,
4876 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4877 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4878 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4879 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4880 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4881 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4882 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4883 bfd_boolean
*newdef
,
4884 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4885 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4886 bfd
*abfd ATTRIBUTE_UNUSED
,
4888 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4889 bfd_boolean
*olddef
,
4890 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4891 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4895 /* A normal common symbol and a large common symbol result in a
4896 normal common symbol. We turn the large common symbol into a
4899 && h
->root
.type
== bfd_link_hash_common
4901 && bfd_is_com_section (*sec
)
4904 if (sym
->st_shndx
== SHN_COMMON
4905 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4907 h
->root
.u
.c
.p
->section
4908 = bfd_make_section_old_way (oldbfd
, "COMMON");
4909 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4911 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4912 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4913 *psec
= *sec
= bfd_com_section_ptr
;
4920 elf_x86_64_additional_program_headers (bfd
*abfd
,
4921 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4926 /* Check to see if we need a large readonly segment. */
4927 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4928 if (s
&& (s
->flags
& SEC_LOAD
))
4931 /* Check to see if we need a large data segment. Since .lbss sections
4932 is placed right after the .bss section, there should be no need for
4933 a large data segment just because of .lbss. */
4934 s
= bfd_get_section_by_name (abfd
, ".ldata");
4935 if (s
&& (s
->flags
& SEC_LOAD
))
4941 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4944 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4946 if (h
->plt
.offset
!= (bfd_vma
) -1
4948 && !h
->pointer_equality_needed
)
4951 return _bfd_elf_hash_symbol (h
);
4954 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4957 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4958 const bfd_target
*output
)
4960 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4961 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4962 && _bfd_elf_relocs_compatible (input
, output
));
4965 static const struct bfd_elf_special_section
4966 elf_x86_64_special_sections
[]=
4968 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4969 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4970 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4971 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4972 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4973 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4974 { NULL
, 0, 0, 0, 0 }
4977 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4978 #define TARGET_LITTLE_NAME "elf64-x86-64"
4979 #define ELF_ARCH bfd_arch_i386
4980 #define ELF_TARGET_ID X86_64_ELF_DATA
4981 #define ELF_MACHINE_CODE EM_X86_64
4982 #define ELF_MAXPAGESIZE 0x200000
4983 #define ELF_MINPAGESIZE 0x1000
4984 #define ELF_COMMONPAGESIZE 0x1000
4986 #define elf_backend_can_gc_sections 1
4987 #define elf_backend_can_refcount 1
4988 #define elf_backend_want_got_plt 1
4989 #define elf_backend_plt_readonly 1
4990 #define elf_backend_want_plt_sym 0
4991 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4992 #define elf_backend_rela_normal 1
4993 #define elf_backend_plt_alignment 4
4995 #define elf_info_to_howto elf_x86_64_info_to_howto
4997 #define bfd_elf64_bfd_link_hash_table_create \
4998 elf_x86_64_link_hash_table_create
4999 #define bfd_elf64_bfd_link_hash_table_free \
5000 elf_x86_64_link_hash_table_free
5001 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
5002 #define bfd_elf64_bfd_reloc_name_lookup \
5003 elf_x86_64_reloc_name_lookup
5005 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
5006 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
5007 #define elf_backend_check_relocs elf_x86_64_check_relocs
5008 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
5009 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
5010 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5011 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5012 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
5013 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
5014 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5015 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5017 #define elf_backend_write_core_note elf_x86_64_write_core_note
5019 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5020 #define elf_backend_relocate_section elf_x86_64_relocate_section
5021 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
5022 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5023 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5024 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
5025 #define elf_backend_object_p elf64_x86_64_elf_object_p
5026 #define bfd_elf64_mkobject elf_x86_64_mkobject
5028 #define elf_backend_section_from_shdr \
5029 elf_x86_64_section_from_shdr
5031 #define elf_backend_section_from_bfd_section \
5032 elf_x86_64_elf_section_from_bfd_section
5033 #define elf_backend_add_symbol_hook \
5034 elf_x86_64_add_symbol_hook
5035 #define elf_backend_symbol_processing \
5036 elf_x86_64_symbol_processing
5037 #define elf_backend_common_section_index \
5038 elf_x86_64_common_section_index
5039 #define elf_backend_common_section \
5040 elf_x86_64_common_section
5041 #define elf_backend_common_definition \
5042 elf_x86_64_common_definition
5043 #define elf_backend_merge_symbol \
5044 elf_x86_64_merge_symbol
5045 #define elf_backend_special_sections \
5046 elf_x86_64_special_sections
5047 #define elf_backend_additional_program_headers \
5048 elf_x86_64_additional_program_headers
5049 #define elf_backend_hash_symbol \
5050 elf_x86_64_hash_symbol
5052 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5054 #include "elf64-target.h"
5056 /* FreeBSD support. */
5058 #undef TARGET_LITTLE_SYM
5059 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
5060 #undef TARGET_LITTLE_NAME
5061 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5064 #define ELF_OSABI ELFOSABI_FREEBSD
5067 #define elf64_bed elf64_x86_64_fbsd_bed
5069 #include "elf64-target.h"
5071 /* Solaris 2 support. */
5073 #undef TARGET_LITTLE_SYM
5074 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
5075 #undef TARGET_LITTLE_NAME
5076 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5078 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5079 objects won't be recognized. */
5083 #define elf64_bed elf64_x86_64_sol2_bed
5085 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5087 #undef elf_backend_static_tls_alignment
5088 #define elf_backend_static_tls_alignment 16
5090 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5092 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5094 #undef elf_backend_want_plt_sym
5095 #define elf_backend_want_plt_sym 1
5097 #include "elf64-target.h"
5099 /* Native Client support. */
5101 #undef TARGET_LITTLE_SYM
5102 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_nacl_vec
5103 #undef TARGET_LITTLE_NAME
5104 #define TARGET_LITTLE_NAME "elf64-x86-64-nacl"
5106 #define elf64_bed elf64_x86_64_nacl_bed
5108 #undef ELF_MAXPAGESIZE
5109 #undef ELF_MINPAGESIZE
5110 #undef ELF_COMMONPAGESIZE
5111 #define ELF_MAXPAGESIZE 0x10000
5112 #define ELF_MINPAGESIZE 0x10000
5113 #define ELF_COMMONPAGESIZE 0x10000
5115 /* Restore defaults. */
5117 #undef elf_backend_static_tls_alignment
5118 #undef elf_backend_want_plt_sym
5119 #define elf_backend_want_plt_sym 0
5121 /* NaCl uses substantially different PLT entries for the same effects. */
5123 #undef elf_backend_plt_alignment
5124 #define elf_backend_plt_alignment 5
5125 #define NACL_PLT_ENTRY_SIZE 64
5126 #define NACLMASK 0xe0 /* 32-byte alignment mask. */
5128 static const bfd_byte elf_x86_64_nacl_plt0_entry
[NACL_PLT_ENTRY_SIZE
] =
5130 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
5131 0x4c, 0x8b, 0x1d, 16, 0, 0, 0, /* mov GOT+16(%rip), %r11 */
5132 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5133 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5134 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5136 /* 41 bytes of nop to pad out to the standard size. */
5137 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5138 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5139 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5140 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5141 0x66, 0x66, /* excess data32 prefixes */
5142 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5145 static const bfd_byte elf_x86_64_nacl_plt_entry
[NACL_PLT_ENTRY_SIZE
] =
5147 0x4c, 0x8b, 0x1d, 0, 0, 0, 0, /* mov name@GOTPCREL(%rip),%r11 */
5148 0x41, 0x83, 0xe3, NACLMASK
, /* and $-32, %r11d */
5149 0x4d, 0x01, 0xfb, /* add %r15, %r11 */
5150 0x41, 0xff, 0xe3, /* jmpq *%r11 */
5152 /* 15-byte nop sequence to pad out to the next 32-byte boundary. */
5153 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5154 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5156 /* Lazy GOT entries point here (32-byte aligned). */
5157 0x68, /* pushq immediate */
5158 0, 0, 0, 0, /* replaced with index into relocation table. */
5159 0xe9, /* jmp relative */
5160 0, 0, 0, 0, /* replaced with offset to start of .plt0. */
5162 /* 22 bytes of nop to pad out to the standard size. */
5163 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, /* excess data32 prefixes */
5164 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, /* nopw %cs:0x0(%rax,%rax,1) */
5165 0x0f, 0x1f, 0x80, 0, 0, 0, 0, /* nopl 0x0(%rax) */
5168 /* .eh_frame covering the .plt section. */
5170 static const bfd_byte elf_x86_64_nacl_eh_frame_plt
[] =
5172 #if (PLT_CIE_LENGTH != 20 \
5173 || PLT_FDE_LENGTH != 36 \
5174 || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \
5175 || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12)
5176 # error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!"
5178 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
5179 0, 0, 0, 0, /* CIE ID */
5180 1, /* CIE version */
5181 'z', 'R', 0, /* Augmentation string */
5182 1, /* Code alignment factor */
5183 0x78, /* Data alignment factor */
5184 16, /* Return address column */
5185 1, /* Augmentation size */
5186 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
5187 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
5188 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
5189 DW_CFA_nop
, DW_CFA_nop
,
5191 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
5192 PLT_CIE_LENGTH
+ 8, 0, 0, 0,/* CIE pointer */
5193 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
5194 0, 0, 0, 0, /* .plt size goes here */
5195 0, /* Augmentation size */
5196 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
5197 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
5198 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
5199 DW_CFA_advance_loc
+ 58, /* DW_CFA_advance_loc: 58 to __PLT__+64 */
5200 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
5201 13, /* Block length */
5202 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
5203 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
5204 DW_OP_const1u
, 63, DW_OP_and
, DW_OP_const1u
, 37, DW_OP_ge
,
5205 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
5206 DW_CFA_nop
, DW_CFA_nop
5209 static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed
=
5211 elf_x86_64_nacl_plt0_entry
, /* plt0_entry */
5212 elf_x86_64_nacl_plt_entry
, /* plt_entry */
5213 NACL_PLT_ENTRY_SIZE
, /* plt_entry_size */
5214 2, /* plt0_got1_offset */
5215 9, /* plt0_got2_offset */
5216 13, /* plt0_got2_insn_end */
5217 3, /* plt_got_offset */
5218 33, /* plt_reloc_offset */
5219 38, /* plt_plt_offset */
5220 7, /* plt_got_insn_size */
5221 42, /* plt_plt_insn_end */
5222 32, /* plt_lazy_offset */
5223 elf_x86_64_nacl_eh_frame_plt
, /* eh_frame_plt */
5224 sizeof (elf_x86_64_nacl_eh_frame_plt
), /* eh_frame_plt_size */
5227 #undef elf_backend_arch_data
5228 #define elf_backend_arch_data &elf_x86_64_nacl_arch_bed
5230 #include "elf64-target.h"
5232 /* Native Client x32 support. */
5234 #undef TARGET_LITTLE_SYM
5235 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_nacl_vec
5236 #undef TARGET_LITTLE_NAME
5237 #define TARGET_LITTLE_NAME "elf32-x86-64-nacl"
5239 #define elf32_bed elf32_x86_64_nacl_bed
5241 #define bfd_elf32_bfd_link_hash_table_create \
5242 elf_x86_64_link_hash_table_create
5243 #define bfd_elf32_bfd_link_hash_table_free \
5244 elf_x86_64_link_hash_table_free
5245 #define bfd_elf32_bfd_reloc_type_lookup \
5246 elf_x86_64_reloc_type_lookup
5247 #define bfd_elf32_bfd_reloc_name_lookup \
5248 elf_x86_64_reloc_name_lookup
5249 #define bfd_elf32_mkobject \
5252 #undef elf_backend_object_p
5253 #define elf_backend_object_p \
5254 elf32_x86_64_elf_object_p
5256 #undef elf_backend_bfd_from_remote_memory
5257 #define elf_backend_bfd_from_remote_memory \
5258 _bfd_elf32_bfd_from_remote_memory
5260 #undef elf_backend_size_info
5261 #define elf_backend_size_info \
5262 _bfd_elf32_size_info
5264 #include "elf32-target.h"
5266 /* Restore defaults. */
5267 #undef elf_backend_object_p
5268 #define elf_backend_object_p elf64_x86_64_elf_object_p
5269 #undef elf_backend_bfd_from_remote_memory
5270 #undef elf_backend_size_info
5272 /* Intel L1OM support. */
5275 elf64_l1om_elf_object_p (bfd
*abfd
)
5277 /* Set the right machine number for an L1OM elf64 file. */
5278 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5282 #undef TARGET_LITTLE_SYM
5283 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5284 #undef TARGET_LITTLE_NAME
5285 #define TARGET_LITTLE_NAME "elf64-l1om"
5287 #define ELF_ARCH bfd_arch_l1om
5289 #undef ELF_MACHINE_CODE
5290 #define ELF_MACHINE_CODE EM_L1OM
5295 #define elf64_bed elf64_l1om_bed
5297 #undef elf_backend_object_p
5298 #define elf_backend_object_p elf64_l1om_elf_object_p
5300 /* Restore defaults. */
5301 #undef ELF_MAXPAGESIZE
5302 #undef ELF_MINPAGESIZE
5303 #undef ELF_COMMONPAGESIZE
5304 #define ELF_MAXPAGESIZE 0x200000
5305 #define ELF_MINPAGESIZE 0x1000
5306 #define ELF_COMMONPAGESIZE 0x1000
5307 #undef elf_backend_plt_alignment
5308 #define elf_backend_plt_alignment 4
5309 #undef elf_backend_arch_data
5310 #define elf_backend_arch_data &elf_x86_64_arch_bed
5312 #include "elf64-target.h"
5314 /* FreeBSD L1OM support. */
5316 #undef TARGET_LITTLE_SYM
5317 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5318 #undef TARGET_LITTLE_NAME
5319 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5322 #define ELF_OSABI ELFOSABI_FREEBSD
5325 #define elf64_bed elf64_l1om_fbsd_bed
5327 #include "elf64-target.h"
5329 /* Intel K1OM support. */
5332 elf64_k1om_elf_object_p (bfd
*abfd
)
5334 /* Set the right machine number for an K1OM elf64 file. */
5335 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5339 #undef TARGET_LITTLE_SYM
5340 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5341 #undef TARGET_LITTLE_NAME
5342 #define TARGET_LITTLE_NAME "elf64-k1om"
5344 #define ELF_ARCH bfd_arch_k1om
5346 #undef ELF_MACHINE_CODE
5347 #define ELF_MACHINE_CODE EM_K1OM
5352 #define elf64_bed elf64_k1om_bed
5354 #undef elf_backend_object_p
5355 #define elf_backend_object_p elf64_k1om_elf_object_p
5357 #undef elf_backend_static_tls_alignment
5359 #undef elf_backend_want_plt_sym
5360 #define elf_backend_want_plt_sym 0
5362 #include "elf64-target.h"
5364 /* FreeBSD K1OM support. */
5366 #undef TARGET_LITTLE_SYM
5367 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5368 #undef TARGET_LITTLE_NAME
5369 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5372 #define ELF_OSABI ELFOSABI_FREEBSD
5375 #define elf64_bed elf64_k1om_fbsd_bed
5377 #include "elf64-target.h"
5379 /* 32bit x86-64 support. */
5381 #undef TARGET_LITTLE_SYM
5382 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5383 #undef TARGET_LITTLE_NAME
5384 #define TARGET_LITTLE_NAME "elf32-x86-64"
5388 #define ELF_ARCH bfd_arch_i386
5390 #undef ELF_MACHINE_CODE
5391 #define ELF_MACHINE_CODE EM_X86_64
5395 #undef elf_backend_object_p
5396 #define elf_backend_object_p \
5397 elf32_x86_64_elf_object_p
5399 #undef elf_backend_bfd_from_remote_memory
5400 #define elf_backend_bfd_from_remote_memory \
5401 _bfd_elf32_bfd_from_remote_memory
5403 #undef elf_backend_size_info
5404 #define elf_backend_size_info \
5405 _bfd_elf32_size_info
5407 #include "elf32-target.h"