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 /* x86-64 ELF linker hash entry. */
590 struct elf_x86_64_link_hash_entry
592 struct elf_link_hash_entry elf
;
594 /* Track dynamic relocs copied for this symbol. */
595 struct elf_dyn_relocs
*dyn_relocs
;
597 #define GOT_UNKNOWN 0
601 #define GOT_TLS_GDESC 4
602 #define GOT_TLS_GD_BOTH_P(type) \
603 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
604 #define GOT_TLS_GD_P(type) \
605 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
606 #define GOT_TLS_GDESC_P(type) \
607 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
608 #define GOT_TLS_GD_ANY_P(type) \
609 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
610 unsigned char tls_type
;
612 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
613 starting at the end of the jump table. */
617 #define elf_x86_64_hash_entry(ent) \
618 ((struct elf_x86_64_link_hash_entry *)(ent))
620 struct elf_x86_64_obj_tdata
622 struct elf_obj_tdata root
;
624 /* tls_type for each local got entry. */
625 char *local_got_tls_type
;
627 /* GOTPLT entries for TLS descriptors. */
628 bfd_vma
*local_tlsdesc_gotent
;
631 #define elf_x86_64_tdata(abfd) \
632 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
634 #define elf_x86_64_local_got_tls_type(abfd) \
635 (elf_x86_64_tdata (abfd)->local_got_tls_type)
637 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
638 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
640 #define is_x86_64_elf(bfd) \
641 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
642 && elf_tdata (bfd) != NULL \
643 && elf_object_id (bfd) == X86_64_ELF_DATA)
646 elf_x86_64_mkobject (bfd
*abfd
)
648 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
652 /* x86-64 ELF linker hash table. */
654 struct elf_x86_64_link_hash_table
656 struct elf_link_hash_table elf
;
658 /* Short-cuts to get to dynamic linker sections. */
661 asection
*plt_eh_frame
;
665 bfd_signed_vma refcount
;
669 /* The amount of space used by the jump slots in the GOT. */
670 bfd_vma sgotplt_jump_table_size
;
672 /* Small local sym cache. */
673 struct sym_cache sym_cache
;
675 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
676 bfd_vma (*r_sym
) (bfd_vma
);
677 unsigned int pointer_r_type
;
678 const char *dynamic_interpreter
;
679 int dynamic_interpreter_size
;
681 /* _TLS_MODULE_BASE_ symbol. */
682 struct bfd_link_hash_entry
*tls_module_base
;
684 /* Used by local STT_GNU_IFUNC symbols. */
685 htab_t loc_hash_table
;
686 void * loc_hash_memory
;
688 /* The offset into splt of the PLT entry for the TLS descriptor
689 resolver. Special values are 0, if not necessary (or not found
690 to be necessary yet), and -1 if needed but not determined
693 /* The offset into sgot of the GOT entry used by the PLT entry
697 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
698 bfd_vma next_jump_slot_index
;
699 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
700 bfd_vma next_irelative_index
;
703 /* Get the x86-64 ELF linker hash table from a link_info structure. */
705 #define elf_x86_64_hash_table(p) \
706 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
707 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
709 #define elf_x86_64_compute_jump_table_size(htab) \
710 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
712 /* Create an entry in an x86-64 ELF linker hash table. */
714 static struct bfd_hash_entry
*
715 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
716 struct bfd_hash_table
*table
,
719 /* Allocate the structure if it has not already been allocated by a
723 entry
= (struct bfd_hash_entry
*)
724 bfd_hash_allocate (table
,
725 sizeof (struct elf_x86_64_link_hash_entry
));
730 /* Call the allocation method of the superclass. */
731 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
734 struct elf_x86_64_link_hash_entry
*eh
;
736 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
737 eh
->dyn_relocs
= NULL
;
738 eh
->tls_type
= GOT_UNKNOWN
;
739 eh
->tlsdesc_got
= (bfd_vma
) -1;
745 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
746 for local symbol so that we can handle local STT_GNU_IFUNC symbols
747 as global symbol. We reuse indx and dynstr_index for local symbol
748 hash since they aren't used by global symbols in this backend. */
751 elf_x86_64_local_htab_hash (const void *ptr
)
753 struct elf_link_hash_entry
*h
754 = (struct elf_link_hash_entry
*) ptr
;
755 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
758 /* Compare local hash entries. */
761 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
763 struct elf_link_hash_entry
*h1
764 = (struct elf_link_hash_entry
*) ptr1
;
765 struct elf_link_hash_entry
*h2
766 = (struct elf_link_hash_entry
*) ptr2
;
768 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
771 /* Find and/or create a hash entry for local symbol. */
773 static struct elf_link_hash_entry
*
774 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
775 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
778 struct elf_x86_64_link_hash_entry e
, *ret
;
779 asection
*sec
= abfd
->sections
;
780 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
781 htab
->r_sym (rel
->r_info
));
784 e
.elf
.indx
= sec
->id
;
785 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
786 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
787 create
? INSERT
: NO_INSERT
);
794 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
798 ret
= (struct elf_x86_64_link_hash_entry
*)
799 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
800 sizeof (struct elf_x86_64_link_hash_entry
));
803 memset (ret
, 0, sizeof (*ret
));
804 ret
->elf
.indx
= sec
->id
;
805 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
806 ret
->elf
.dynindx
= -1;
812 /* Create an X86-64 ELF linker hash table. */
814 static struct bfd_link_hash_table
*
815 elf_x86_64_link_hash_table_create (bfd
*abfd
)
817 struct elf_x86_64_link_hash_table
*ret
;
818 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
820 ret
= (struct elf_x86_64_link_hash_table
*) bfd_malloc (amt
);
824 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
825 elf_x86_64_link_hash_newfunc
,
826 sizeof (struct elf_x86_64_link_hash_entry
),
835 ret
->plt_eh_frame
= NULL
;
836 ret
->sym_cache
.abfd
= NULL
;
837 ret
->tlsdesc_plt
= 0;
838 ret
->tlsdesc_got
= 0;
839 ret
->tls_ld_got
.refcount
= 0;
840 ret
->sgotplt_jump_table_size
= 0;
841 ret
->tls_module_base
= NULL
;
842 ret
->next_jump_slot_index
= 0;
843 ret
->next_irelative_index
= 0;
847 ret
->r_info
= elf64_r_info
;
848 ret
->r_sym
= elf64_r_sym
;
849 ret
->pointer_r_type
= R_X86_64_64
;
850 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
851 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
855 ret
->r_info
= elf32_r_info
;
856 ret
->r_sym
= elf32_r_sym
;
857 ret
->pointer_r_type
= R_X86_64_32
;
858 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
859 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
862 ret
->loc_hash_table
= htab_try_create (1024,
863 elf_x86_64_local_htab_hash
,
864 elf_x86_64_local_htab_eq
,
866 ret
->loc_hash_memory
= objalloc_create ();
867 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
873 return &ret
->elf
.root
;
876 /* Destroy an X86-64 ELF linker hash table. */
879 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
881 struct elf_x86_64_link_hash_table
*htab
882 = (struct elf_x86_64_link_hash_table
*) hash
;
884 if (htab
->loc_hash_table
)
885 htab_delete (htab
->loc_hash_table
);
886 if (htab
->loc_hash_memory
)
887 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
888 _bfd_generic_link_hash_table_free (hash
);
891 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
892 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
896 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
897 struct bfd_link_info
*info
)
899 struct elf_x86_64_link_hash_table
*htab
;
901 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
904 htab
= elf_x86_64_hash_table (info
);
908 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
910 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
913 || (!info
->shared
&& !htab
->srelbss
))
916 if (!info
->no_ld_generated_unwind_info
917 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
918 && htab
->elf
.splt
!= NULL
)
920 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
922 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
923 flags
| SEC_READONLY
);
924 if (htab
->plt_eh_frame
== NULL
925 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
928 htab
->plt_eh_frame
->size
= sizeof (elf_x86_64_eh_frame_plt
);
929 htab
->plt_eh_frame
->contents
930 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
931 memcpy (htab
->plt_eh_frame
->contents
, elf_x86_64_eh_frame_plt
,
932 sizeof (elf_x86_64_eh_frame_plt
));
937 /* Copy the extra info we tack onto an elf_link_hash_entry. */
940 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
941 struct elf_link_hash_entry
*dir
,
942 struct elf_link_hash_entry
*ind
)
944 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
946 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
947 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
949 if (eind
->dyn_relocs
!= NULL
)
951 if (edir
->dyn_relocs
!= NULL
)
953 struct elf_dyn_relocs
**pp
;
954 struct elf_dyn_relocs
*p
;
956 /* Add reloc counts against the indirect sym to the direct sym
957 list. Merge any entries against the same section. */
958 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
960 struct elf_dyn_relocs
*q
;
962 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
963 if (q
->sec
== p
->sec
)
965 q
->pc_count
+= p
->pc_count
;
966 q
->count
+= p
->count
;
973 *pp
= edir
->dyn_relocs
;
976 edir
->dyn_relocs
= eind
->dyn_relocs
;
977 eind
->dyn_relocs
= NULL
;
980 if (ind
->root
.type
== bfd_link_hash_indirect
981 && dir
->got
.refcount
<= 0)
983 edir
->tls_type
= eind
->tls_type
;
984 eind
->tls_type
= GOT_UNKNOWN
;
987 if (ELIMINATE_COPY_RELOCS
988 && ind
->root
.type
!= bfd_link_hash_indirect
989 && dir
->dynamic_adjusted
)
991 /* If called to transfer flags for a weakdef during processing
992 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
993 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
994 dir
->ref_dynamic
|= ind
->ref_dynamic
;
995 dir
->ref_regular
|= ind
->ref_regular
;
996 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
997 dir
->needs_plt
|= ind
->needs_plt
;
998 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1001 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1005 elf64_x86_64_elf_object_p (bfd
*abfd
)
1007 /* Set the right machine number for an x86-64 elf64 file. */
1008 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1012 /* Return TRUE if the TLS access code sequence support transition
1016 elf_x86_64_check_tls_transition (bfd
*abfd
,
1017 struct bfd_link_info
*info
,
1020 Elf_Internal_Shdr
*symtab_hdr
,
1021 struct elf_link_hash_entry
**sym_hashes
,
1022 unsigned int r_type
,
1023 const Elf_Internal_Rela
*rel
,
1024 const Elf_Internal_Rela
*relend
)
1027 unsigned long r_symndx
;
1028 struct elf_link_hash_entry
*h
;
1030 struct elf_x86_64_link_hash_table
*htab
;
1032 /* Get the section contents. */
1033 if (contents
== NULL
)
1035 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1036 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1039 /* FIXME: How to better handle error condition? */
1040 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1043 /* Cache the section contents for elf_link_input_bfd. */
1044 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1048 htab
= elf_x86_64_hash_table (info
);
1049 offset
= rel
->r_offset
;
1052 case R_X86_64_TLSGD
:
1053 case R_X86_64_TLSLD
:
1054 if ((rel
+ 1) >= relend
)
1057 if (r_type
== R_X86_64_TLSGD
)
1059 /* Check transition from GD access model. For 64bit, only
1060 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1061 .word 0x6666; rex64; call __tls_get_addr
1062 can transit to different access model. For 32bit, only
1063 leaq foo@tlsgd(%rip), %rdi
1064 .word 0x6666; rex64; call __tls_get_addr
1065 can transit to different access model. */
1067 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1068 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1070 if ((offset
+ 12) > sec
->size
1071 || memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1074 if (ABI_64_P (abfd
))
1077 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1083 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1089 /* Check transition from LD access model. Only
1090 leaq foo@tlsld(%rip), %rdi;
1092 can transit to different access model. */
1094 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1096 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1099 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0
1100 || 0xe8 != *(contents
+ offset
+ 4))
1104 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1105 if (r_symndx
< symtab_hdr
->sh_info
)
1108 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1109 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1110 may be versioned. */
1112 && h
->root
.root
.string
!= NULL
1113 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1114 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
1115 && (strncmp (h
->root
.root
.string
,
1116 "__tls_get_addr", 14) == 0));
1118 case R_X86_64_GOTTPOFF
:
1119 /* Check transition from IE access model:
1120 mov foo@gottpoff(%rip), %reg
1121 add foo@gottpoff(%rip), %reg
1124 /* Check REX prefix first. */
1125 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1127 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1128 if (val
!= 0x48 && val
!= 0x4c)
1130 /* X32 may have 0x44 REX prefix or no REX prefix. */
1131 if (ABI_64_P (abfd
))
1137 /* X32 may not have any REX prefix. */
1138 if (ABI_64_P (abfd
))
1140 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1144 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1145 if (val
!= 0x8b && val
!= 0x03)
1148 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1149 return (val
& 0xc7) == 5;
1151 case R_X86_64_GOTPC32_TLSDESC
:
1152 /* Check transition from GDesc access model:
1153 leaq x@tlsdesc(%rip), %rax
1155 Make sure it's a leaq adding rip to a 32-bit offset
1156 into any register, although it's probably almost always
1159 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1162 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1163 if ((val
& 0xfb) != 0x48)
1166 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1169 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1170 return (val
& 0xc7) == 0x05;
1172 case R_X86_64_TLSDESC_CALL
:
1173 /* Check transition from GDesc access model:
1174 call *x@tlsdesc(%rax)
1176 if (offset
+ 2 <= sec
->size
)
1178 /* Make sure that it's a call *x@tlsdesc(%rax). */
1179 static const unsigned char call
[] = { 0xff, 0x10 };
1180 return memcmp (contents
+ offset
, call
, 2) == 0;
1190 /* Return TRUE if the TLS access transition is OK or no transition
1191 will be performed. Update R_TYPE if there is a transition. */
1194 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1195 asection
*sec
, bfd_byte
*contents
,
1196 Elf_Internal_Shdr
*symtab_hdr
,
1197 struct elf_link_hash_entry
**sym_hashes
,
1198 unsigned int *r_type
, int tls_type
,
1199 const Elf_Internal_Rela
*rel
,
1200 const Elf_Internal_Rela
*relend
,
1201 struct elf_link_hash_entry
*h
,
1202 unsigned long r_symndx
)
1204 unsigned int from_type
= *r_type
;
1205 unsigned int to_type
= from_type
;
1206 bfd_boolean check
= TRUE
;
1208 /* Skip TLS transition for functions. */
1210 && (h
->type
== STT_FUNC
1211 || h
->type
== STT_GNU_IFUNC
))
1216 case R_X86_64_TLSGD
:
1217 case R_X86_64_GOTPC32_TLSDESC
:
1218 case R_X86_64_TLSDESC_CALL
:
1219 case R_X86_64_GOTTPOFF
:
1220 if (info
->executable
)
1223 to_type
= R_X86_64_TPOFF32
;
1225 to_type
= R_X86_64_GOTTPOFF
;
1228 /* When we are called from elf_x86_64_relocate_section,
1229 CONTENTS isn't NULL and there may be additional transitions
1230 based on TLS_TYPE. */
1231 if (contents
!= NULL
)
1233 unsigned int new_to_type
= to_type
;
1235 if (info
->executable
1238 && tls_type
== GOT_TLS_IE
)
1239 new_to_type
= R_X86_64_TPOFF32
;
1241 if (to_type
== R_X86_64_TLSGD
1242 || to_type
== R_X86_64_GOTPC32_TLSDESC
1243 || to_type
== R_X86_64_TLSDESC_CALL
)
1245 if (tls_type
== GOT_TLS_IE
)
1246 new_to_type
= R_X86_64_GOTTPOFF
;
1249 /* We checked the transition before when we were called from
1250 elf_x86_64_check_relocs. We only want to check the new
1251 transition which hasn't been checked before. */
1252 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1253 to_type
= new_to_type
;
1258 case R_X86_64_TLSLD
:
1259 if (info
->executable
)
1260 to_type
= R_X86_64_TPOFF32
;
1267 /* Return TRUE if there is no transition. */
1268 if (from_type
== to_type
)
1271 /* Check if the transition can be performed. */
1273 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1274 symtab_hdr
, sym_hashes
,
1275 from_type
, rel
, relend
))
1277 reloc_howto_type
*from
, *to
;
1280 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1281 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1284 name
= h
->root
.root
.string
;
1287 struct elf_x86_64_link_hash_table
*htab
;
1289 htab
= elf_x86_64_hash_table (info
);
1294 Elf_Internal_Sym
*isym
;
1296 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1298 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1302 (*_bfd_error_handler
)
1303 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1304 "in section `%A' failed"),
1305 abfd
, sec
, from
->name
, to
->name
, name
,
1306 (unsigned long) rel
->r_offset
);
1307 bfd_set_error (bfd_error_bad_value
);
1315 /* Look through the relocs for a section during the first phase, and
1316 calculate needed space in the global offset table, procedure
1317 linkage table, and dynamic reloc sections. */
1320 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1322 const Elf_Internal_Rela
*relocs
)
1324 struct elf_x86_64_link_hash_table
*htab
;
1325 Elf_Internal_Shdr
*symtab_hdr
;
1326 struct elf_link_hash_entry
**sym_hashes
;
1327 const Elf_Internal_Rela
*rel
;
1328 const Elf_Internal_Rela
*rel_end
;
1331 if (info
->relocatable
)
1334 BFD_ASSERT (is_x86_64_elf (abfd
));
1336 htab
= elf_x86_64_hash_table (info
);
1340 symtab_hdr
= &elf_symtab_hdr (abfd
);
1341 sym_hashes
= elf_sym_hashes (abfd
);
1345 rel_end
= relocs
+ sec
->reloc_count
;
1346 for (rel
= relocs
; rel
< rel_end
; rel
++)
1348 unsigned int r_type
;
1349 unsigned long r_symndx
;
1350 struct elf_link_hash_entry
*h
;
1351 Elf_Internal_Sym
*isym
;
1354 r_symndx
= htab
->r_sym (rel
->r_info
);
1355 r_type
= ELF32_R_TYPE (rel
->r_info
);
1357 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1359 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1364 if (r_symndx
< symtab_hdr
->sh_info
)
1366 /* A local symbol. */
1367 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1372 /* Check relocation against local STT_GNU_IFUNC symbol. */
1373 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1375 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1380 /* Fake a STT_GNU_IFUNC symbol. */
1381 h
->type
= STT_GNU_IFUNC
;
1384 h
->forced_local
= 1;
1385 h
->root
.type
= bfd_link_hash_defined
;
1393 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1394 while (h
->root
.type
== bfd_link_hash_indirect
1395 || h
->root
.type
== bfd_link_hash_warning
)
1396 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1399 /* Check invalid x32 relocations. */
1400 if (!ABI_64_P (abfd
))
1406 case R_X86_64_DTPOFF64
:
1407 case R_X86_64_TPOFF64
:
1409 case R_X86_64_GOTOFF64
:
1410 case R_X86_64_GOT64
:
1411 case R_X86_64_GOTPCREL64
:
1412 case R_X86_64_GOTPC64
:
1413 case R_X86_64_GOTPLT64
:
1414 case R_X86_64_PLTOFF64
:
1417 name
= h
->root
.root
.string
;
1419 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1421 (*_bfd_error_handler
)
1422 (_("%B: relocation %s against symbol `%s' isn't "
1423 "supported in x32 mode"), abfd
,
1424 x86_64_elf_howto_table
[r_type
].name
, name
);
1425 bfd_set_error (bfd_error_bad_value
);
1433 /* Create the ifunc sections for static executables. If we
1434 never see an indirect function symbol nor we are building
1435 a static executable, those sections will be empty and
1436 won't appear in output. */
1447 case R_X86_64_PLT32
:
1448 case R_X86_64_GOTPCREL
:
1449 case R_X86_64_GOTPCREL64
:
1450 if (htab
->elf
.dynobj
== NULL
)
1451 htab
->elf
.dynobj
= abfd
;
1452 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1457 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1458 it here if it is defined in a non-shared object. */
1459 if (h
->type
== STT_GNU_IFUNC
1462 /* It is referenced by a non-shared object. */
1466 /* STT_GNU_IFUNC symbol must go through PLT. */
1467 h
->plt
.refcount
+= 1;
1469 /* STT_GNU_IFUNC needs dynamic sections. */
1470 if (htab
->elf
.dynobj
== NULL
)
1471 htab
->elf
.dynobj
= abfd
;
1476 if (h
->root
.root
.string
)
1477 name
= h
->root
.root
.string
;
1479 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1481 (*_bfd_error_handler
)
1482 (_("%B: relocation %s against STT_GNU_IFUNC "
1483 "symbol `%s' isn't handled by %s"), abfd
,
1484 x86_64_elf_howto_table
[r_type
].name
,
1485 name
, __FUNCTION__
);
1486 bfd_set_error (bfd_error_bad_value
);
1490 if (ABI_64_P (abfd
))
1494 h
->pointer_equality_needed
= 1;
1497 /* We must copy these reloc types into the output
1498 file. Create a reloc section in dynobj and
1499 make room for this reloc. */
1500 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1501 (abfd
, info
, sec
, sreloc
,
1502 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1513 if (r_type
!= R_X86_64_PC32
1514 && r_type
!= R_X86_64_PC64
)
1515 h
->pointer_equality_needed
= 1;
1518 case R_X86_64_PLT32
:
1521 case R_X86_64_GOTPCREL
:
1522 case R_X86_64_GOTPCREL64
:
1523 h
->got
.refcount
+= 1;
1524 if (htab
->elf
.sgot
== NULL
1525 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1535 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1536 symtab_hdr
, sym_hashes
,
1537 &r_type
, GOT_UNKNOWN
,
1538 rel
, rel_end
, h
, r_symndx
))
1543 case R_X86_64_TLSLD
:
1544 htab
->tls_ld_got
.refcount
+= 1;
1547 case R_X86_64_TPOFF32
:
1548 if (!info
->executable
&& ABI_64_P (abfd
))
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 `%s' can not be used when making a shared object; recompile with -fPIC"),
1558 x86_64_elf_howto_table
[r_type
].name
, name
);
1559 bfd_set_error (bfd_error_bad_value
);
1564 case R_X86_64_GOTTPOFF
:
1565 if (!info
->executable
)
1566 info
->flags
|= DF_STATIC_TLS
;
1569 case R_X86_64_GOT32
:
1570 case R_X86_64_GOTPCREL
:
1571 case R_X86_64_TLSGD
:
1572 case R_X86_64_GOT64
:
1573 case R_X86_64_GOTPCREL64
:
1574 case R_X86_64_GOTPLT64
:
1575 case R_X86_64_GOTPC32_TLSDESC
:
1576 case R_X86_64_TLSDESC_CALL
:
1577 /* This symbol requires a global offset table entry. */
1579 int tls_type
, old_tls_type
;
1583 default: tls_type
= GOT_NORMAL
; break;
1584 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1585 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1586 case R_X86_64_GOTPC32_TLSDESC
:
1587 case R_X86_64_TLSDESC_CALL
:
1588 tls_type
= GOT_TLS_GDESC
; break;
1593 if (r_type
== R_X86_64_GOTPLT64
)
1595 /* This relocation indicates that we also need
1596 a PLT entry, as this is a function. We don't need
1597 a PLT entry for local symbols. */
1599 h
->plt
.refcount
+= 1;
1601 h
->got
.refcount
+= 1;
1602 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1606 bfd_signed_vma
*local_got_refcounts
;
1608 /* This is a global offset table entry for a local symbol. */
1609 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1610 if (local_got_refcounts
== NULL
)
1614 size
= symtab_hdr
->sh_info
;
1615 size
*= sizeof (bfd_signed_vma
)
1616 + sizeof (bfd_vma
) + sizeof (char);
1617 local_got_refcounts
= ((bfd_signed_vma
*)
1618 bfd_zalloc (abfd
, size
));
1619 if (local_got_refcounts
== NULL
)
1621 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1622 elf_x86_64_local_tlsdesc_gotent (abfd
)
1623 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1624 elf_x86_64_local_got_tls_type (abfd
)
1625 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1627 local_got_refcounts
[r_symndx
] += 1;
1629 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1632 /* If a TLS symbol is accessed using IE at least once,
1633 there is no point to use dynamic model for it. */
1634 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1635 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1636 || tls_type
!= GOT_TLS_IE
))
1638 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1639 tls_type
= old_tls_type
;
1640 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1641 && GOT_TLS_GD_ANY_P (tls_type
))
1642 tls_type
|= old_tls_type
;
1646 name
= h
->root
.root
.string
;
1648 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1650 (*_bfd_error_handler
)
1651 (_("%B: '%s' accessed both as normal and thread local symbol"),
1657 if (old_tls_type
!= tls_type
)
1660 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1662 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1667 case R_X86_64_GOTOFF64
:
1668 case R_X86_64_GOTPC32
:
1669 case R_X86_64_GOTPC64
:
1671 if (htab
->elf
.sgot
== NULL
)
1673 if (htab
->elf
.dynobj
== NULL
)
1674 htab
->elf
.dynobj
= abfd
;
1675 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1681 case R_X86_64_PLT32
:
1682 /* This symbol requires a procedure linkage table entry. We
1683 actually build the entry in adjust_dynamic_symbol,
1684 because this might be a case of linking PIC code which is
1685 never referenced by a dynamic object, in which case we
1686 don't need to generate a procedure linkage table entry
1689 /* If this is a local symbol, we resolve it directly without
1690 creating a procedure linkage table entry. */
1695 h
->plt
.refcount
+= 1;
1698 case R_X86_64_PLTOFF64
:
1699 /* This tries to form the 'address' of a function relative
1700 to GOT. For global symbols we need a PLT entry. */
1704 h
->plt
.refcount
+= 1;
1709 if (!ABI_64_P (abfd
))
1714 /* Let's help debug shared library creation. These relocs
1715 cannot be used in shared libs. Don't error out for
1716 sections we don't care about, such as debug sections or
1717 non-constant sections. */
1719 && (sec
->flags
& SEC_ALLOC
) != 0
1720 && (sec
->flags
& SEC_READONLY
) != 0)
1723 name
= h
->root
.root
.string
;
1725 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1726 (*_bfd_error_handler
)
1727 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1728 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1729 bfd_set_error (bfd_error_bad_value
);
1740 if (h
!= NULL
&& info
->executable
)
1742 /* If this reloc is in a read-only section, we might
1743 need a copy reloc. We can't check reliably at this
1744 stage whether the section is read-only, as input
1745 sections have not yet been mapped to output sections.
1746 Tentatively set the flag for now, and correct in
1747 adjust_dynamic_symbol. */
1750 /* We may need a .plt entry if the function this reloc
1751 refers to is in a shared lib. */
1752 h
->plt
.refcount
+= 1;
1753 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1754 h
->pointer_equality_needed
= 1;
1757 /* If we are creating a shared library, and this is a reloc
1758 against a global symbol, or a non PC relative reloc
1759 against a local symbol, then we need to copy the reloc
1760 into the shared library. However, if we are linking with
1761 -Bsymbolic, we do not need to copy a reloc against a
1762 global symbol which is defined in an object we are
1763 including in the link (i.e., DEF_REGULAR is set). At
1764 this point we have not seen all the input files, so it is
1765 possible that DEF_REGULAR is not set now but will be set
1766 later (it is never cleared). In case of a weak definition,
1767 DEF_REGULAR may be cleared later by a strong definition in
1768 a shared library. We account for that possibility below by
1769 storing information in the relocs_copied field of the hash
1770 table entry. A similar situation occurs when creating
1771 shared libraries and symbol visibility changes render the
1774 If on the other hand, we are creating an executable, we
1775 may need to keep relocations for symbols satisfied by a
1776 dynamic library if we manage to avoid copy relocs for the
1779 && (sec
->flags
& SEC_ALLOC
) != 0
1780 && (! IS_X86_64_PCREL_TYPE (r_type
)
1782 && (! SYMBOLIC_BIND (info
, h
)
1783 || h
->root
.type
== bfd_link_hash_defweak
1784 || !h
->def_regular
))))
1785 || (ELIMINATE_COPY_RELOCS
1787 && (sec
->flags
& SEC_ALLOC
) != 0
1789 && (h
->root
.type
== bfd_link_hash_defweak
1790 || !h
->def_regular
)))
1792 struct elf_dyn_relocs
*p
;
1793 struct elf_dyn_relocs
**head
;
1795 /* We must copy these reloc types into the output file.
1796 Create a reloc section in dynobj and make room for
1800 if (htab
->elf
.dynobj
== NULL
)
1801 htab
->elf
.dynobj
= abfd
;
1803 sreloc
= _bfd_elf_make_dynamic_reloc_section
1804 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1805 abfd
, /*rela?*/ TRUE
);
1811 /* If this is a global symbol, we count the number of
1812 relocations we need for this symbol. */
1815 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1819 /* Track dynamic relocs needed for local syms too.
1820 We really need local syms available to do this
1825 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1830 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1834 /* Beware of type punned pointers vs strict aliasing
1836 vpp
= &(elf_section_data (s
)->local_dynrel
);
1837 head
= (struct elf_dyn_relocs
**)vpp
;
1841 if (p
== NULL
|| p
->sec
!= sec
)
1843 bfd_size_type amt
= sizeof *p
;
1845 p
= ((struct elf_dyn_relocs
*)
1846 bfd_alloc (htab
->elf
.dynobj
, amt
));
1857 if (IS_X86_64_PCREL_TYPE (r_type
))
1862 /* This relocation describes the C++ object vtable hierarchy.
1863 Reconstruct it for later use during GC. */
1864 case R_X86_64_GNU_VTINHERIT
:
1865 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1869 /* This relocation describes which C++ vtable entries are actually
1870 used. Record for later use during GC. */
1871 case R_X86_64_GNU_VTENTRY
:
1872 BFD_ASSERT (h
!= NULL
);
1874 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1886 /* Return the section that should be marked against GC for a given
1890 elf_x86_64_gc_mark_hook (asection
*sec
,
1891 struct bfd_link_info
*info
,
1892 Elf_Internal_Rela
*rel
,
1893 struct elf_link_hash_entry
*h
,
1894 Elf_Internal_Sym
*sym
)
1897 switch (ELF32_R_TYPE (rel
->r_info
))
1899 case R_X86_64_GNU_VTINHERIT
:
1900 case R_X86_64_GNU_VTENTRY
:
1904 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1907 /* Update the got entry reference counts for the section being removed. */
1910 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1912 const Elf_Internal_Rela
*relocs
)
1914 struct elf_x86_64_link_hash_table
*htab
;
1915 Elf_Internal_Shdr
*symtab_hdr
;
1916 struct elf_link_hash_entry
**sym_hashes
;
1917 bfd_signed_vma
*local_got_refcounts
;
1918 const Elf_Internal_Rela
*rel
, *relend
;
1920 if (info
->relocatable
)
1923 htab
= elf_x86_64_hash_table (info
);
1927 elf_section_data (sec
)->local_dynrel
= NULL
;
1929 symtab_hdr
= &elf_symtab_hdr (abfd
);
1930 sym_hashes
= elf_sym_hashes (abfd
);
1931 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1933 htab
= elf_x86_64_hash_table (info
);
1934 relend
= relocs
+ sec
->reloc_count
;
1935 for (rel
= relocs
; rel
< relend
; rel
++)
1937 unsigned long r_symndx
;
1938 unsigned int r_type
;
1939 struct elf_link_hash_entry
*h
= NULL
;
1941 r_symndx
= htab
->r_sym (rel
->r_info
);
1942 if (r_symndx
>= symtab_hdr
->sh_info
)
1944 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1945 while (h
->root
.type
== bfd_link_hash_indirect
1946 || h
->root
.type
== bfd_link_hash_warning
)
1947 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1951 /* A local symbol. */
1952 Elf_Internal_Sym
*isym
;
1954 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1957 /* Check relocation against local STT_GNU_IFUNC symbol. */
1959 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1961 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1969 struct elf_x86_64_link_hash_entry
*eh
;
1970 struct elf_dyn_relocs
**pp
;
1971 struct elf_dyn_relocs
*p
;
1973 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
1975 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1978 /* Everything must go for SEC. */
1984 r_type
= ELF32_R_TYPE (rel
->r_info
);
1985 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1986 symtab_hdr
, sym_hashes
,
1987 &r_type
, GOT_UNKNOWN
,
1988 rel
, relend
, h
, r_symndx
))
1993 case R_X86_64_TLSLD
:
1994 if (htab
->tls_ld_got
.refcount
> 0)
1995 htab
->tls_ld_got
.refcount
-= 1;
1998 case R_X86_64_TLSGD
:
1999 case R_X86_64_GOTPC32_TLSDESC
:
2000 case R_X86_64_TLSDESC_CALL
:
2001 case R_X86_64_GOTTPOFF
:
2002 case R_X86_64_GOT32
:
2003 case R_X86_64_GOTPCREL
:
2004 case R_X86_64_GOT64
:
2005 case R_X86_64_GOTPCREL64
:
2006 case R_X86_64_GOTPLT64
:
2009 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2010 h
->plt
.refcount
-= 1;
2011 if (h
->got
.refcount
> 0)
2012 h
->got
.refcount
-= 1;
2013 if (h
->type
== STT_GNU_IFUNC
)
2015 if (h
->plt
.refcount
> 0)
2016 h
->plt
.refcount
-= 1;
2019 else if (local_got_refcounts
!= NULL
)
2021 if (local_got_refcounts
[r_symndx
] > 0)
2022 local_got_refcounts
[r_symndx
] -= 1;
2036 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2040 case R_X86_64_PLT32
:
2041 case R_X86_64_PLTOFF64
:
2044 if (h
->plt
.refcount
> 0)
2045 h
->plt
.refcount
-= 1;
2057 /* Adjust a symbol defined by a dynamic object and referenced by a
2058 regular object. The current definition is in some section of the
2059 dynamic object, but we're not including those sections. We have to
2060 change the definition to something the rest of the link can
2064 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2065 struct elf_link_hash_entry
*h
)
2067 struct elf_x86_64_link_hash_table
*htab
;
2070 /* STT_GNU_IFUNC symbol must go through PLT. */
2071 if (h
->type
== STT_GNU_IFUNC
)
2073 if (h
->plt
.refcount
<= 0)
2075 h
->plt
.offset
= (bfd_vma
) -1;
2081 /* If this is a function, put it in the procedure linkage table. We
2082 will fill in the contents of the procedure linkage table later,
2083 when we know the address of the .got section. */
2084 if (h
->type
== STT_FUNC
2087 if (h
->plt
.refcount
<= 0
2088 || SYMBOL_CALLS_LOCAL (info
, h
)
2089 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2090 && h
->root
.type
== bfd_link_hash_undefweak
))
2092 /* This case can occur if we saw a PLT32 reloc in an input
2093 file, but the symbol was never referred to by a dynamic
2094 object, or if all references were garbage collected. In
2095 such a case, we don't actually need to build a procedure
2096 linkage table, and we can just do a PC32 reloc instead. */
2097 h
->plt
.offset
= (bfd_vma
) -1;
2104 /* It's possible that we incorrectly decided a .plt reloc was
2105 needed for an R_X86_64_PC32 reloc to a non-function sym in
2106 check_relocs. We can't decide accurately between function and
2107 non-function syms in check-relocs; Objects loaded later in
2108 the link may change h->type. So fix it now. */
2109 h
->plt
.offset
= (bfd_vma
) -1;
2111 /* If this is a weak symbol, and there is a real definition, the
2112 processor independent code will have arranged for us to see the
2113 real definition first, and we can just use the same value. */
2114 if (h
->u
.weakdef
!= NULL
)
2116 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2117 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2118 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2119 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2120 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2121 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2125 /* This is a reference to a symbol defined by a dynamic object which
2126 is not a function. */
2128 /* If we are creating a shared library, we must presume that the
2129 only references to the symbol are via the global offset table.
2130 For such cases we need not do anything here; the relocations will
2131 be handled correctly by relocate_section. */
2135 /* If there are no references to this symbol that do not use the
2136 GOT, we don't need to generate a copy reloc. */
2137 if (!h
->non_got_ref
)
2140 /* If -z nocopyreloc was given, we won't generate them either. */
2141 if (info
->nocopyreloc
)
2147 if (ELIMINATE_COPY_RELOCS
)
2149 struct elf_x86_64_link_hash_entry
* eh
;
2150 struct elf_dyn_relocs
*p
;
2152 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2153 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2155 s
= p
->sec
->output_section
;
2156 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2160 /* If we didn't find any dynamic relocs in read-only sections, then
2161 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2169 /* We must allocate the symbol in our .dynbss section, which will
2170 become part of the .bss section of the executable. There will be
2171 an entry for this symbol in the .dynsym section. The dynamic
2172 object will contain position independent code, so all references
2173 from the dynamic object to this symbol will go through the global
2174 offset table. The dynamic linker will use the .dynsym entry to
2175 determine the address it must put in the global offset table, so
2176 both the dynamic object and the regular object will refer to the
2177 same memory location for the variable. */
2179 htab
= elf_x86_64_hash_table (info
);
2183 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2184 to copy the initial value out of the dynamic object and into the
2185 runtime process image. */
2186 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2188 const struct elf_backend_data
*bed
;
2189 bed
= get_elf_backend_data (info
->output_bfd
);
2190 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2196 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2199 /* Allocate space in .plt, .got and associated reloc sections for
2203 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2205 struct bfd_link_info
*info
;
2206 struct elf_x86_64_link_hash_table
*htab
;
2207 struct elf_x86_64_link_hash_entry
*eh
;
2208 struct elf_dyn_relocs
*p
;
2209 const struct elf_backend_data
*bed
;
2211 if (h
->root
.type
== bfd_link_hash_indirect
)
2214 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2216 info
= (struct bfd_link_info
*) inf
;
2217 htab
= elf_x86_64_hash_table (info
);
2220 bed
= get_elf_backend_data (info
->output_bfd
);
2222 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2223 here if it is defined and referenced in a non-shared object. */
2224 if (h
->type
== STT_GNU_IFUNC
2226 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2230 else if (htab
->elf
.dynamic_sections_created
2231 && h
->plt
.refcount
> 0)
2233 /* Make sure this symbol is output as a dynamic symbol.
2234 Undefined weak syms won't yet be marked as dynamic. */
2235 if (h
->dynindx
== -1
2236 && !h
->forced_local
)
2238 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2243 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2245 asection
*s
= htab
->elf
.splt
;
2247 /* If this is the first .plt entry, make room for the special
2250 s
->size
+= PLT_ENTRY_SIZE
;
2252 h
->plt
.offset
= s
->size
;
2254 /* If this symbol is not defined in a regular file, and we are
2255 not generating a shared library, then set the symbol to this
2256 location in the .plt. This is required to make function
2257 pointers compare as equal between the normal executable and
2258 the shared library. */
2262 h
->root
.u
.def
.section
= s
;
2263 h
->root
.u
.def
.value
= h
->plt
.offset
;
2266 /* Make room for this entry. */
2267 s
->size
+= PLT_ENTRY_SIZE
;
2269 /* We also need to make an entry in the .got.plt section, which
2270 will be placed in the .got section by the linker script. */
2271 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2273 /* We also need to make an entry in the .rela.plt section. */
2274 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2275 htab
->elf
.srelplt
->reloc_count
++;
2279 h
->plt
.offset
= (bfd_vma
) -1;
2285 h
->plt
.offset
= (bfd_vma
) -1;
2289 eh
->tlsdesc_got
= (bfd_vma
) -1;
2291 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2292 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2293 if (h
->got
.refcount
> 0
2296 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2298 h
->got
.offset
= (bfd_vma
) -1;
2300 else if (h
->got
.refcount
> 0)
2304 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2306 /* Make sure this symbol is output as a dynamic symbol.
2307 Undefined weak syms won't yet be marked as dynamic. */
2308 if (h
->dynindx
== -1
2309 && !h
->forced_local
)
2311 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2315 if (GOT_TLS_GDESC_P (tls_type
))
2317 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2318 - elf_x86_64_compute_jump_table_size (htab
);
2319 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2320 h
->got
.offset
= (bfd_vma
) -2;
2322 if (! GOT_TLS_GDESC_P (tls_type
)
2323 || GOT_TLS_GD_P (tls_type
))
2326 h
->got
.offset
= s
->size
;
2327 s
->size
+= GOT_ENTRY_SIZE
;
2328 if (GOT_TLS_GD_P (tls_type
))
2329 s
->size
+= GOT_ENTRY_SIZE
;
2331 dyn
= htab
->elf
.dynamic_sections_created
;
2332 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2334 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2335 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2336 || tls_type
== GOT_TLS_IE
)
2337 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2338 else if (GOT_TLS_GD_P (tls_type
))
2339 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2340 else if (! GOT_TLS_GDESC_P (tls_type
)
2341 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2342 || h
->root
.type
!= bfd_link_hash_undefweak
)
2344 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2345 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2346 if (GOT_TLS_GDESC_P (tls_type
))
2348 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2349 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2353 h
->got
.offset
= (bfd_vma
) -1;
2355 if (eh
->dyn_relocs
== NULL
)
2358 /* In the shared -Bsymbolic case, discard space allocated for
2359 dynamic pc-relative relocs against symbols which turn out to be
2360 defined in regular objects. For the normal shared case, discard
2361 space for pc-relative relocs that have become local due to symbol
2362 visibility changes. */
2366 /* Relocs that use pc_count are those that appear on a call
2367 insn, or certain REL relocs that can generated via assembly.
2368 We want calls to protected symbols to resolve directly to the
2369 function rather than going via the plt. If people want
2370 function pointer comparisons to work as expected then they
2371 should avoid writing weird assembly. */
2372 if (SYMBOL_CALLS_LOCAL (info
, h
))
2374 struct elf_dyn_relocs
**pp
;
2376 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2378 p
->count
-= p
->pc_count
;
2387 /* Also discard relocs on undefined weak syms with non-default
2389 if (eh
->dyn_relocs
!= NULL
2390 && h
->root
.type
== bfd_link_hash_undefweak
)
2392 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2393 eh
->dyn_relocs
= NULL
;
2395 /* Make sure undefined weak symbols are output as a dynamic
2397 else if (h
->dynindx
== -1
2398 && ! h
->forced_local
2399 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2404 else if (ELIMINATE_COPY_RELOCS
)
2406 /* For the non-shared case, discard space for relocs against
2407 symbols which turn out to need copy relocs or are not
2413 || (htab
->elf
.dynamic_sections_created
2414 && (h
->root
.type
== bfd_link_hash_undefweak
2415 || h
->root
.type
== bfd_link_hash_undefined
))))
2417 /* Make sure this symbol is output as a dynamic symbol.
2418 Undefined weak syms won't yet be marked as dynamic. */
2419 if (h
->dynindx
== -1
2420 && ! h
->forced_local
2421 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2424 /* If that succeeded, we know we'll be keeping all the
2426 if (h
->dynindx
!= -1)
2430 eh
->dyn_relocs
= NULL
;
2435 /* Finally, allocate space. */
2436 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2440 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2442 BFD_ASSERT (sreloc
!= NULL
);
2444 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2450 /* Allocate space in .plt, .got and associated reloc sections for
2451 local dynamic relocs. */
2454 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2456 struct elf_link_hash_entry
*h
2457 = (struct elf_link_hash_entry
*) *slot
;
2459 if (h
->type
!= STT_GNU_IFUNC
2463 || h
->root
.type
!= bfd_link_hash_defined
)
2466 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2469 /* Find any dynamic relocs that apply to read-only sections. */
2472 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2475 struct elf_x86_64_link_hash_entry
*eh
;
2476 struct elf_dyn_relocs
*p
;
2478 /* Skip local IFUNC symbols. */
2479 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2482 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2483 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2485 asection
*s
= p
->sec
->output_section
;
2487 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2489 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2491 info
->flags
|= DF_TEXTREL
;
2493 if (info
->warn_shared_textrel
&& info
->shared
)
2494 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2495 p
->sec
->owner
, h
->root
.root
.string
,
2498 /* Not an error, just cut short the traversal. */
2505 /* Set the sizes of the dynamic sections. */
2508 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2509 struct bfd_link_info
*info
)
2511 struct elf_x86_64_link_hash_table
*htab
;
2516 const struct elf_backend_data
*bed
;
2518 htab
= elf_x86_64_hash_table (info
);
2521 bed
= get_elf_backend_data (output_bfd
);
2523 dynobj
= htab
->elf
.dynobj
;
2527 if (htab
->elf
.dynamic_sections_created
)
2529 /* Set the contents of the .interp section to the interpreter. */
2530 if (info
->executable
)
2532 s
= bfd_get_section_by_name (dynobj
, ".interp");
2535 s
->size
= htab
->dynamic_interpreter_size
;
2536 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2540 /* Set up .got offsets for local syms, and space for local dynamic
2542 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2544 bfd_signed_vma
*local_got
;
2545 bfd_signed_vma
*end_local_got
;
2546 char *local_tls_type
;
2547 bfd_vma
*local_tlsdesc_gotent
;
2548 bfd_size_type locsymcount
;
2549 Elf_Internal_Shdr
*symtab_hdr
;
2552 if (! is_x86_64_elf (ibfd
))
2555 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2557 struct elf_dyn_relocs
*p
;
2559 for (p
= (struct elf_dyn_relocs
*)
2560 (elf_section_data (s
)->local_dynrel
);
2564 if (!bfd_is_abs_section (p
->sec
)
2565 && bfd_is_abs_section (p
->sec
->output_section
))
2567 /* Input section has been discarded, either because
2568 it is a copy of a linkonce section or due to
2569 linker script /DISCARD/, so we'll be discarding
2572 else if (p
->count
!= 0)
2574 srel
= elf_section_data (p
->sec
)->sreloc
;
2575 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2576 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2577 && (info
->flags
& DF_TEXTREL
) == 0)
2579 info
->flags
|= DF_TEXTREL
;
2580 if (info
->warn_shared_textrel
&& info
->shared
)
2581 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2582 p
->sec
->owner
, p
->sec
);
2588 local_got
= elf_local_got_refcounts (ibfd
);
2592 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2593 locsymcount
= symtab_hdr
->sh_info
;
2594 end_local_got
= local_got
+ locsymcount
;
2595 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2596 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2598 srel
= htab
->elf
.srelgot
;
2599 for (; local_got
< end_local_got
;
2600 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2602 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2605 if (GOT_TLS_GDESC_P (*local_tls_type
))
2607 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2608 - elf_x86_64_compute_jump_table_size (htab
);
2609 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2610 *local_got
= (bfd_vma
) -2;
2612 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2613 || GOT_TLS_GD_P (*local_tls_type
))
2615 *local_got
= s
->size
;
2616 s
->size
+= GOT_ENTRY_SIZE
;
2617 if (GOT_TLS_GD_P (*local_tls_type
))
2618 s
->size
+= GOT_ENTRY_SIZE
;
2621 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2622 || *local_tls_type
== GOT_TLS_IE
)
2624 if (GOT_TLS_GDESC_P (*local_tls_type
))
2626 htab
->elf
.srelplt
->size
2627 += bed
->s
->sizeof_rela
;
2628 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2630 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2631 || GOT_TLS_GD_P (*local_tls_type
))
2632 srel
->size
+= bed
->s
->sizeof_rela
;
2636 *local_got
= (bfd_vma
) -1;
2640 if (htab
->tls_ld_got
.refcount
> 0)
2642 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2644 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2645 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2646 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2649 htab
->tls_ld_got
.offset
= -1;
2651 /* Allocate global sym .plt and .got entries, and space for global
2652 sym dynamic relocs. */
2653 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2656 /* Allocate .plt and .got entries, and space for local symbols. */
2657 htab_traverse (htab
->loc_hash_table
,
2658 elf_x86_64_allocate_local_dynrelocs
,
2661 /* For every jump slot reserved in the sgotplt, reloc_count is
2662 incremented. However, when we reserve space for TLS descriptors,
2663 it's not incremented, so in order to compute the space reserved
2664 for them, it suffices to multiply the reloc count by the jump
2667 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2668 so that R_X86_64_IRELATIVE entries come last. */
2669 if (htab
->elf
.srelplt
)
2671 htab
->sgotplt_jump_table_size
2672 = elf_x86_64_compute_jump_table_size (htab
);
2673 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2675 else if (htab
->elf
.irelplt
)
2676 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2678 if (htab
->tlsdesc_plt
)
2680 /* If we're not using lazy TLS relocations, don't generate the
2681 PLT and GOT entries they require. */
2682 if ((info
->flags
& DF_BIND_NOW
))
2683 htab
->tlsdesc_plt
= 0;
2686 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2687 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2688 /* Reserve room for the initial entry.
2689 FIXME: we could probably do away with it in this case. */
2690 if (htab
->elf
.splt
->size
== 0)
2691 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2692 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2693 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2697 if (htab
->elf
.sgotplt
)
2699 struct elf_link_hash_entry
*got
;
2700 got
= elf_link_hash_lookup (elf_hash_table (info
),
2701 "_GLOBAL_OFFSET_TABLE_",
2702 FALSE
, FALSE
, FALSE
);
2704 /* Don't allocate .got.plt section if there are no GOT nor PLT
2705 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2707 || !got
->ref_regular_nonweak
)
2708 && (htab
->elf
.sgotplt
->size
2709 == get_elf_backend_data (output_bfd
)->got_header_size
)
2710 && (htab
->elf
.splt
== NULL
2711 || htab
->elf
.splt
->size
== 0)
2712 && (htab
->elf
.sgot
== NULL
2713 || htab
->elf
.sgot
->size
== 0)
2714 && (htab
->elf
.iplt
== NULL
2715 || htab
->elf
.iplt
->size
== 0)
2716 && (htab
->elf
.igotplt
== NULL
2717 || htab
->elf
.igotplt
->size
== 0))
2718 htab
->elf
.sgotplt
->size
= 0;
2721 /* We now have determined the sizes of the various dynamic sections.
2722 Allocate memory for them. */
2724 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2726 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2729 if (s
== htab
->elf
.splt
2730 || s
== htab
->elf
.sgot
2731 || s
== htab
->elf
.sgotplt
2732 || s
== htab
->elf
.iplt
2733 || s
== htab
->elf
.igotplt
2734 || s
== htab
->sdynbss
)
2736 /* Strip this section if we don't need it; see the
2739 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2741 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2744 /* We use the reloc_count field as a counter if we need
2745 to copy relocs into the output file. */
2746 if (s
!= htab
->elf
.srelplt
)
2751 /* It's not one of our sections, so don't allocate space. */
2757 /* If we don't need this section, strip it from the
2758 output file. This is mostly to handle .rela.bss and
2759 .rela.plt. We must create both sections in
2760 create_dynamic_sections, because they must be created
2761 before the linker maps input sections to output
2762 sections. The linker does that before
2763 adjust_dynamic_symbol is called, and it is that
2764 function which decides whether anything needs to go
2765 into these sections. */
2767 s
->flags
|= SEC_EXCLUDE
;
2771 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2774 /* Allocate memory for the section contents. We use bfd_zalloc
2775 here in case unused entries are not reclaimed before the
2776 section's contents are written out. This should not happen,
2777 but this way if it does, we get a R_X86_64_NONE reloc instead
2779 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2780 if (s
->contents
== NULL
)
2784 if (htab
->plt_eh_frame
!= NULL
2785 && htab
->elf
.splt
!= NULL
2786 && htab
->elf
.splt
->size
!= 0
2787 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2788 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2789 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2791 if (htab
->elf
.dynamic_sections_created
)
2793 /* Add some entries to the .dynamic section. We fill in the
2794 values later, in elf_x86_64_finish_dynamic_sections, but we
2795 must add the entries now so that we get the correct size for
2796 the .dynamic section. The DT_DEBUG entry is filled in by the
2797 dynamic linker and used by the debugger. */
2798 #define add_dynamic_entry(TAG, VAL) \
2799 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2801 if (info
->executable
)
2803 if (!add_dynamic_entry (DT_DEBUG
, 0))
2807 if (htab
->elf
.splt
->size
!= 0)
2809 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2810 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2811 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2812 || !add_dynamic_entry (DT_JMPREL
, 0))
2815 if (htab
->tlsdesc_plt
2816 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2817 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2823 if (!add_dynamic_entry (DT_RELA
, 0)
2824 || !add_dynamic_entry (DT_RELASZ
, 0)
2825 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2828 /* If any dynamic relocs apply to a read-only section,
2829 then we need a DT_TEXTREL entry. */
2830 if ((info
->flags
& DF_TEXTREL
) == 0)
2831 elf_link_hash_traverse (&htab
->elf
,
2832 elf_x86_64_readonly_dynrelocs
,
2835 if ((info
->flags
& DF_TEXTREL
) != 0)
2837 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2842 #undef add_dynamic_entry
2848 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2849 struct bfd_link_info
*info
)
2851 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2855 struct elf_link_hash_entry
*tlsbase
;
2857 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2858 "_TLS_MODULE_BASE_",
2859 FALSE
, FALSE
, FALSE
);
2861 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2863 struct elf_x86_64_link_hash_table
*htab
;
2864 struct bfd_link_hash_entry
*bh
= NULL
;
2865 const struct elf_backend_data
*bed
2866 = get_elf_backend_data (output_bfd
);
2868 htab
= elf_x86_64_hash_table (info
);
2872 if (!(_bfd_generic_link_add_one_symbol
2873 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2874 tls_sec
, 0, NULL
, FALSE
,
2875 bed
->collect
, &bh
)))
2878 htab
->tls_module_base
= bh
;
2880 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2881 tlsbase
->def_regular
= 1;
2882 tlsbase
->other
= STV_HIDDEN
;
2883 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2890 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2891 executables. Rather than setting it to the beginning of the TLS
2892 section, we have to set it to the end. This function may be called
2893 multiple times, it is idempotent. */
2896 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2898 struct elf_x86_64_link_hash_table
*htab
;
2899 struct bfd_link_hash_entry
*base
;
2901 if (!info
->executable
)
2904 htab
= elf_x86_64_hash_table (info
);
2908 base
= htab
->tls_module_base
;
2912 base
->u
.def
.value
= htab
->elf
.tls_size
;
2915 /* Return the base VMA address which should be subtracted from real addresses
2916 when resolving @dtpoff relocation.
2917 This is PT_TLS segment p_vaddr. */
2920 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2922 /* If tls_sec is NULL, we should have signalled an error already. */
2923 if (elf_hash_table (info
)->tls_sec
== NULL
)
2925 return elf_hash_table (info
)->tls_sec
->vma
;
2928 /* Return the relocation value for @tpoff relocation
2929 if STT_TLS virtual address is ADDRESS. */
2932 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2934 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2935 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2936 bfd_vma static_tls_size
;
2938 /* If tls_segment is NULL, we should have signalled an error already. */
2939 if (htab
->tls_sec
== NULL
)
2942 /* Consider special static TLS alignment requirements. */
2943 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2944 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2947 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2951 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2953 /* Opcode Instruction
2956 0x0f 0x8x conditional jump */
2958 && (contents
[offset
- 1] == 0xe8
2959 || contents
[offset
- 1] == 0xe9))
2961 && contents
[offset
- 2] == 0x0f
2962 && (contents
[offset
- 1] & 0xf0) == 0x80));
2965 /* Relocate an x86_64 ELF section. */
2968 elf_x86_64_relocate_section (bfd
*output_bfd
,
2969 struct bfd_link_info
*info
,
2971 asection
*input_section
,
2973 Elf_Internal_Rela
*relocs
,
2974 Elf_Internal_Sym
*local_syms
,
2975 asection
**local_sections
)
2977 struct elf_x86_64_link_hash_table
*htab
;
2978 Elf_Internal_Shdr
*symtab_hdr
;
2979 struct elf_link_hash_entry
**sym_hashes
;
2980 bfd_vma
*local_got_offsets
;
2981 bfd_vma
*local_tlsdesc_gotents
;
2982 Elf_Internal_Rela
*rel
;
2983 Elf_Internal_Rela
*relend
;
2985 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2987 htab
= elf_x86_64_hash_table (info
);
2990 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2991 sym_hashes
= elf_sym_hashes (input_bfd
);
2992 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2993 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
2995 elf_x86_64_set_tls_module_base (info
);
2998 relend
= relocs
+ input_section
->reloc_count
;
2999 for (; rel
< relend
; rel
++)
3001 unsigned int r_type
;
3002 reloc_howto_type
*howto
;
3003 unsigned long r_symndx
;
3004 struct elf_link_hash_entry
*h
;
3005 Elf_Internal_Sym
*sym
;
3007 bfd_vma off
, offplt
;
3009 bfd_boolean unresolved_reloc
;
3010 bfd_reloc_status_type r
;
3014 r_type
= ELF32_R_TYPE (rel
->r_info
);
3015 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3016 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3019 if (r_type
>= R_X86_64_max
)
3021 bfd_set_error (bfd_error_bad_value
);
3025 if (r_type
!= (int) R_X86_64_32
3026 || ABI_64_P (output_bfd
))
3027 howto
= x86_64_elf_howto_table
+ r_type
;
3029 howto
= (x86_64_elf_howto_table
3030 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3031 r_symndx
= htab
->r_sym (rel
->r_info
);
3035 unresolved_reloc
= FALSE
;
3036 if (r_symndx
< symtab_hdr
->sh_info
)
3038 sym
= local_syms
+ r_symndx
;
3039 sec
= local_sections
[r_symndx
];
3041 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3044 /* Relocate against local STT_GNU_IFUNC symbol. */
3045 if (!info
->relocatable
3046 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3048 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3053 /* Set STT_GNU_IFUNC symbol value. */
3054 h
->root
.u
.def
.value
= sym
->st_value
;
3055 h
->root
.u
.def
.section
= sec
;
3060 bfd_boolean warned ATTRIBUTE_UNUSED
;
3062 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3063 r_symndx
, symtab_hdr
, sym_hashes
,
3065 unresolved_reloc
, warned
);
3068 if (sec
!= NULL
&& elf_discarded_section (sec
))
3069 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3070 rel
, relend
, howto
, contents
);
3072 if (info
->relocatable
)
3075 if (rel
->r_addend
== 0
3076 && r_type
== R_X86_64_64
3077 && !ABI_64_P (output_bfd
))
3079 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3080 it to 64bit if addend is zero. */
3081 r_type
= R_X86_64_32
;
3082 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3085 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3086 it here if it is defined in a non-shared object. */
3088 && h
->type
== STT_GNU_IFUNC
3095 if ((input_section
->flags
& SEC_ALLOC
) == 0
3096 || h
->plt
.offset
== (bfd_vma
) -1)
3099 /* STT_GNU_IFUNC symbol must go through PLT. */
3100 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3101 relocation
= (plt
->output_section
->vma
3102 + plt
->output_offset
+ h
->plt
.offset
);
3107 if (h
->root
.root
.string
)
3108 name
= h
->root
.root
.string
;
3110 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3112 (*_bfd_error_handler
)
3113 (_("%B: relocation %s against STT_GNU_IFUNC "
3114 "symbol `%s' isn't handled by %s"), input_bfd
,
3115 x86_64_elf_howto_table
[r_type
].name
,
3116 name
, __FUNCTION__
);
3117 bfd_set_error (bfd_error_bad_value
);
3126 if (ABI_64_P (output_bfd
))
3130 if (rel
->r_addend
!= 0)
3132 if (h
->root
.root
.string
)
3133 name
= h
->root
.root
.string
;
3135 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3137 (*_bfd_error_handler
)
3138 (_("%B: relocation %s against STT_GNU_IFUNC "
3139 "symbol `%s' has non-zero addend: %d"),
3140 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3141 name
, rel
->r_addend
);
3142 bfd_set_error (bfd_error_bad_value
);
3146 /* Generate dynamic relcoation only when there is a
3147 non-GOT reference in a shared object. */
3148 if (info
->shared
&& h
->non_got_ref
)
3150 Elf_Internal_Rela outrel
;
3153 /* Need a dynamic relocation to get the real function
3155 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3159 if (outrel
.r_offset
== (bfd_vma
) -1
3160 || outrel
.r_offset
== (bfd_vma
) -2)
3163 outrel
.r_offset
+= (input_section
->output_section
->vma
3164 + input_section
->output_offset
);
3166 if (h
->dynindx
== -1
3168 || info
->executable
)
3170 /* This symbol is resolved locally. */
3171 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3172 outrel
.r_addend
= (h
->root
.u
.def
.value
3173 + h
->root
.u
.def
.section
->output_section
->vma
3174 + h
->root
.u
.def
.section
->output_offset
);
3178 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3179 outrel
.r_addend
= 0;
3182 sreloc
= htab
->elf
.irelifunc
;
3183 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3185 /* If this reloc is against an external symbol, we
3186 do not want to fiddle with the addend. Otherwise,
3187 we need to include the symbol value so that it
3188 becomes an addend for the dynamic reloc. For an
3189 internal symbol, we have updated addend. */
3195 case R_X86_64_PLT32
:
3198 case R_X86_64_GOTPCREL
:
3199 case R_X86_64_GOTPCREL64
:
3200 base_got
= htab
->elf
.sgot
;
3201 off
= h
->got
.offset
;
3203 if (base_got
== NULL
)
3206 if (off
== (bfd_vma
) -1)
3208 /* We can't use h->got.offset here to save state, or
3209 even just remember the offset, as finish_dynamic_symbol
3210 would use that as offset into .got. */
3212 if (htab
->elf
.splt
!= NULL
)
3214 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3215 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3216 base_got
= htab
->elf
.sgotplt
;
3220 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3221 off
= plt_index
* GOT_ENTRY_SIZE
;
3222 base_got
= htab
->elf
.igotplt
;
3225 if (h
->dynindx
== -1
3229 /* This references the local defitionion. We must
3230 initialize this entry in the global offset table.
3231 Since the offset must always be a multiple of 8,
3232 we use the least significant bit to record
3233 whether we have initialized it already.
3235 When doing a dynamic link, we create a .rela.got
3236 relocation entry to initialize the value. This
3237 is done in the finish_dynamic_symbol routine. */
3242 bfd_put_64 (output_bfd
, relocation
,
3243 base_got
->contents
+ off
);
3244 /* Note that this is harmless for the GOTPLT64
3245 case, as -1 | 1 still is -1. */
3251 relocation
= (base_got
->output_section
->vma
3252 + base_got
->output_offset
+ off
);
3258 /* When generating a shared object, the relocations handled here are
3259 copied into the output file to be resolved at run time. */
3262 case R_X86_64_GOT32
:
3263 case R_X86_64_GOT64
:
3264 /* Relocation is to the entry for this symbol in the global
3266 case R_X86_64_GOTPCREL
:
3267 case R_X86_64_GOTPCREL64
:
3268 /* Use global offset table entry as symbol value. */
3269 case R_X86_64_GOTPLT64
:
3270 /* This is the same as GOT64 for relocation purposes, but
3271 indicates the existence of a PLT entry. The difficulty is,
3272 that we must calculate the GOT slot offset from the PLT
3273 offset, if this symbol got a PLT entry (it was global).
3274 Additionally if it's computed from the PLT entry, then that
3275 GOT offset is relative to .got.plt, not to .got. */
3276 base_got
= htab
->elf
.sgot
;
3278 if (htab
->elf
.sgot
== NULL
)
3285 off
= h
->got
.offset
;
3287 && h
->plt
.offset
!= (bfd_vma
)-1
3288 && off
== (bfd_vma
)-1)
3290 /* We can't use h->got.offset here to save
3291 state, or even just remember the offset, as
3292 finish_dynamic_symbol would use that as offset into
3294 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3295 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3296 base_got
= htab
->elf
.sgotplt
;
3299 dyn
= htab
->elf
.dynamic_sections_created
;
3301 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3303 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3304 || (ELF_ST_VISIBILITY (h
->other
)
3305 && h
->root
.type
== bfd_link_hash_undefweak
))
3307 /* This is actually a static link, or it is a -Bsymbolic
3308 link and the symbol is defined locally, or the symbol
3309 was forced to be local because of a version file. We
3310 must initialize this entry in the global offset table.
3311 Since the offset must always be a multiple of 8, we
3312 use the least significant bit to record whether we
3313 have initialized it already.
3315 When doing a dynamic link, we create a .rela.got
3316 relocation entry to initialize the value. This is
3317 done in the finish_dynamic_symbol routine. */
3322 bfd_put_64 (output_bfd
, relocation
,
3323 base_got
->contents
+ off
);
3324 /* Note that this is harmless for the GOTPLT64 case,
3325 as -1 | 1 still is -1. */
3330 unresolved_reloc
= FALSE
;
3334 if (local_got_offsets
== NULL
)
3337 off
= local_got_offsets
[r_symndx
];
3339 /* The offset must always be a multiple of 8. We use
3340 the least significant bit to record whether we have
3341 already generated the necessary reloc. */
3346 bfd_put_64 (output_bfd
, relocation
,
3347 base_got
->contents
+ off
);
3352 Elf_Internal_Rela outrel
;
3354 /* We need to generate a R_X86_64_RELATIVE reloc
3355 for the dynamic linker. */
3356 s
= htab
->elf
.srelgot
;
3360 outrel
.r_offset
= (base_got
->output_section
->vma
3361 + base_got
->output_offset
3363 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3364 outrel
.r_addend
= relocation
;
3365 elf_append_rela (output_bfd
, s
, &outrel
);
3368 local_got_offsets
[r_symndx
] |= 1;
3372 if (off
>= (bfd_vma
) -2)
3375 relocation
= base_got
->output_section
->vma
3376 + base_got
->output_offset
+ off
;
3377 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3378 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3379 - htab
->elf
.sgotplt
->output_offset
;
3383 case R_X86_64_GOTOFF64
:
3384 /* Relocation is relative to the start of the global offset
3387 /* Check to make sure it isn't a protected function symbol
3388 for shared library since it may not be local when used
3389 as function address. */
3393 && h
->type
== STT_FUNC
3394 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3396 (*_bfd_error_handler
)
3397 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3398 input_bfd
, h
->root
.root
.string
);
3399 bfd_set_error (bfd_error_bad_value
);
3403 /* Note that sgot is not involved in this
3404 calculation. We always want the start of .got.plt. If we
3405 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3406 permitted by the ABI, we might have to change this
3408 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3409 + htab
->elf
.sgotplt
->output_offset
;
3412 case R_X86_64_GOTPC32
:
3413 case R_X86_64_GOTPC64
:
3414 /* Use global offset table as symbol value. */
3415 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3416 + htab
->elf
.sgotplt
->output_offset
;
3417 unresolved_reloc
= FALSE
;
3420 case R_X86_64_PLTOFF64
:
3421 /* Relocation is PLT entry relative to GOT. For local
3422 symbols it's the symbol itself relative to GOT. */
3424 /* See PLT32 handling. */
3425 && h
->plt
.offset
!= (bfd_vma
) -1
3426 && htab
->elf
.splt
!= NULL
)
3428 relocation
= (htab
->elf
.splt
->output_section
->vma
3429 + htab
->elf
.splt
->output_offset
3431 unresolved_reloc
= FALSE
;
3434 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3435 + htab
->elf
.sgotplt
->output_offset
;
3438 case R_X86_64_PLT32
:
3439 /* Relocation is to the entry for this symbol in the
3440 procedure linkage table. */
3442 /* Resolve a PLT32 reloc against a local symbol directly,
3443 without using the procedure linkage table. */
3447 if (h
->plt
.offset
== (bfd_vma
) -1
3448 || htab
->elf
.splt
== NULL
)
3450 /* We didn't make a PLT entry for this symbol. This
3451 happens when statically linking PIC code, or when
3452 using -Bsymbolic. */
3456 relocation
= (htab
->elf
.splt
->output_section
->vma
3457 + htab
->elf
.splt
->output_offset
3459 unresolved_reloc
= FALSE
;
3466 && (input_section
->flags
& SEC_ALLOC
) != 0
3467 && (input_section
->flags
& SEC_READONLY
) != 0
3470 bfd_boolean fail
= FALSE
;
3472 = (r_type
== R_X86_64_PC32
3473 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3475 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3477 /* Symbol is referenced locally. Make sure it is
3478 defined locally or for a branch. */
3479 fail
= !h
->def_regular
&& !branch
;
3483 /* Symbol isn't referenced locally. We only allow
3484 branch to symbol with non-default visibility. */
3486 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3493 const char *pic
= "";
3495 switch (ELF_ST_VISIBILITY (h
->other
))
3498 v
= _("hidden symbol");
3501 v
= _("internal symbol");
3504 v
= _("protected symbol");
3508 pic
= _("; recompile with -fPIC");
3513 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3515 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3517 (*_bfd_error_handler
) (fmt
, input_bfd
,
3518 x86_64_elf_howto_table
[r_type
].name
,
3519 v
, h
->root
.root
.string
, pic
);
3520 bfd_set_error (bfd_error_bad_value
);
3531 /* FIXME: The ABI says the linker should make sure the value is
3532 the same when it's zeroextended to 64 bit. */
3534 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3539 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3540 || h
->root
.type
!= bfd_link_hash_undefweak
)
3541 && (! IS_X86_64_PCREL_TYPE (r_type
)
3542 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3543 || (ELIMINATE_COPY_RELOCS
3550 || h
->root
.type
== bfd_link_hash_undefweak
3551 || h
->root
.type
== bfd_link_hash_undefined
)))
3553 Elf_Internal_Rela outrel
;
3554 bfd_boolean skip
, relocate
;
3557 /* When generating a shared object, these relocations
3558 are copied into the output file to be resolved at run
3564 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3566 if (outrel
.r_offset
== (bfd_vma
) -1)
3568 else if (outrel
.r_offset
== (bfd_vma
) -2)
3569 skip
= TRUE
, relocate
= TRUE
;
3571 outrel
.r_offset
+= (input_section
->output_section
->vma
3572 + input_section
->output_offset
);
3575 memset (&outrel
, 0, sizeof outrel
);
3577 /* h->dynindx may be -1 if this symbol was marked to
3581 && (IS_X86_64_PCREL_TYPE (r_type
)
3583 || ! SYMBOLIC_BIND (info
, h
)
3584 || ! h
->def_regular
))
3586 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3587 outrel
.r_addend
= rel
->r_addend
;
3591 /* This symbol is local, or marked to become local. */
3592 if (r_type
== htab
->pointer_r_type
)
3595 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3596 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3598 else if (r_type
== R_X86_64_64
3599 && !ABI_64_P (output_bfd
))
3602 outrel
.r_info
= htab
->r_info (0,
3603 R_X86_64_RELATIVE64
);
3604 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3610 if (bfd_is_abs_section (sec
))
3612 else if (sec
== NULL
|| sec
->owner
== NULL
)
3614 bfd_set_error (bfd_error_bad_value
);
3621 /* We are turning this relocation into one
3622 against a section symbol. It would be
3623 proper to subtract the symbol's value,
3624 osec->vma, from the emitted reloc addend,
3625 but ld.so expects buggy relocs. */
3626 osec
= sec
->output_section
;
3627 sindx
= elf_section_data (osec
)->dynindx
;
3630 asection
*oi
= htab
->elf
.text_index_section
;
3631 sindx
= elf_section_data (oi
)->dynindx
;
3633 BFD_ASSERT (sindx
!= 0);
3636 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3637 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3641 sreloc
= elf_section_data (input_section
)->sreloc
;
3643 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3645 r
= bfd_reloc_notsupported
;
3646 goto check_relocation_error
;
3649 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3651 /* If this reloc is against an external symbol, we do
3652 not want to fiddle with the addend. Otherwise, we
3653 need to include the symbol value so that it becomes
3654 an addend for the dynamic reloc. */
3661 case R_X86_64_TLSGD
:
3662 case R_X86_64_GOTPC32_TLSDESC
:
3663 case R_X86_64_TLSDESC_CALL
:
3664 case R_X86_64_GOTTPOFF
:
3665 tls_type
= GOT_UNKNOWN
;
3666 if (h
== NULL
&& local_got_offsets
)
3667 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3669 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3671 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3672 input_section
, contents
,
3673 symtab_hdr
, sym_hashes
,
3674 &r_type
, tls_type
, rel
,
3675 relend
, h
, r_symndx
))
3678 if (r_type
== R_X86_64_TPOFF32
)
3680 bfd_vma roff
= rel
->r_offset
;
3682 BFD_ASSERT (! unresolved_reloc
);
3684 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3686 /* GD->LE transition. For 64bit, change
3687 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3688 .word 0x6666; rex64; call __tls_get_addr
3691 leaq foo@tpoff(%rax), %rax
3693 leaq foo@tlsgd(%rip), %rdi
3694 .word 0x6666; rex64; call __tls_get_addr
3697 leaq foo@tpoff(%rax), %rax */
3698 if (ABI_64_P (output_bfd
))
3699 memcpy (contents
+ roff
- 4,
3700 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3703 memcpy (contents
+ roff
- 3,
3704 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3706 bfd_put_32 (output_bfd
,
3707 elf_x86_64_tpoff (info
, relocation
),
3708 contents
+ roff
+ 8);
3709 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3713 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3715 /* GDesc -> LE transition.
3716 It's originally something like:
3717 leaq x@tlsdesc(%rip), %rax
3720 movl $x@tpoff, %rax. */
3722 unsigned int val
, type
;
3724 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3725 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3726 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3727 contents
+ roff
- 3);
3728 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3729 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3730 contents
+ roff
- 1);
3731 bfd_put_32 (output_bfd
,
3732 elf_x86_64_tpoff (info
, relocation
),
3736 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3738 /* GDesc -> LE transition.
3743 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3744 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3747 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3749 /* IE->LE transition:
3750 Originally it can be one of:
3751 movq foo@gottpoff(%rip), %reg
3752 addq foo@gottpoff(%rip), %reg
3755 leaq foo(%reg), %reg
3758 unsigned int val
, type
, reg
;
3760 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3761 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3762 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3768 bfd_put_8 (output_bfd
, 0x49,
3769 contents
+ roff
- 3);
3770 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3771 bfd_put_8 (output_bfd
, 0x41,
3772 contents
+ roff
- 3);
3773 bfd_put_8 (output_bfd
, 0xc7,
3774 contents
+ roff
- 2);
3775 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3776 contents
+ roff
- 1);
3780 /* addq -> addq - addressing with %rsp/%r12 is
3783 bfd_put_8 (output_bfd
, 0x49,
3784 contents
+ roff
- 3);
3785 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3786 bfd_put_8 (output_bfd
, 0x41,
3787 contents
+ roff
- 3);
3788 bfd_put_8 (output_bfd
, 0x81,
3789 contents
+ roff
- 2);
3790 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3791 contents
+ roff
- 1);
3797 bfd_put_8 (output_bfd
, 0x4d,
3798 contents
+ roff
- 3);
3799 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3800 bfd_put_8 (output_bfd
, 0x45,
3801 contents
+ roff
- 3);
3802 bfd_put_8 (output_bfd
, 0x8d,
3803 contents
+ roff
- 2);
3804 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3805 contents
+ roff
- 1);
3807 bfd_put_32 (output_bfd
,
3808 elf_x86_64_tpoff (info
, relocation
),
3816 if (htab
->elf
.sgot
== NULL
)
3821 off
= h
->got
.offset
;
3822 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3826 if (local_got_offsets
== NULL
)
3829 off
= local_got_offsets
[r_symndx
];
3830 offplt
= local_tlsdesc_gotents
[r_symndx
];
3837 Elf_Internal_Rela outrel
;
3841 if (htab
->elf
.srelgot
== NULL
)
3844 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3846 if (GOT_TLS_GDESC_P (tls_type
))
3848 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3849 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3850 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3851 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3852 + htab
->elf
.sgotplt
->output_offset
3854 + htab
->sgotplt_jump_table_size
);
3855 sreloc
= htab
->elf
.srelplt
;
3857 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3859 outrel
.r_addend
= 0;
3860 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3863 sreloc
= htab
->elf
.srelgot
;
3865 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3866 + htab
->elf
.sgot
->output_offset
+ off
);
3868 if (GOT_TLS_GD_P (tls_type
))
3869 dr_type
= R_X86_64_DTPMOD64
;
3870 else if (GOT_TLS_GDESC_P (tls_type
))
3873 dr_type
= R_X86_64_TPOFF64
;
3875 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3876 outrel
.r_addend
= 0;
3877 if ((dr_type
== R_X86_64_TPOFF64
3878 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3879 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3880 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3882 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3884 if (GOT_TLS_GD_P (tls_type
))
3888 BFD_ASSERT (! unresolved_reloc
);
3889 bfd_put_64 (output_bfd
,
3890 relocation
- elf_x86_64_dtpoff_base (info
),
3891 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3895 bfd_put_64 (output_bfd
, 0,
3896 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3897 outrel
.r_info
= htab
->r_info (indx
,
3899 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3900 elf_append_rela (output_bfd
, sreloc
,
3909 local_got_offsets
[r_symndx
] |= 1;
3912 if (off
>= (bfd_vma
) -2
3913 && ! GOT_TLS_GDESC_P (tls_type
))
3915 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3917 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3918 || r_type
== R_X86_64_TLSDESC_CALL
)
3919 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3920 + htab
->elf
.sgotplt
->output_offset
3921 + offplt
+ htab
->sgotplt_jump_table_size
;
3923 relocation
= htab
->elf
.sgot
->output_section
->vma
3924 + htab
->elf
.sgot
->output_offset
+ off
;
3925 unresolved_reloc
= FALSE
;
3929 bfd_vma roff
= rel
->r_offset
;
3931 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3933 /* GD->IE transition. For 64bit, change
3934 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3935 .word 0x6666; rex64; call __tls_get_addr@plt
3938 addq foo@gottpoff(%rip), %rax
3940 leaq foo@tlsgd(%rip), %rdi
3941 .word 0x6666; rex64; call __tls_get_addr@plt
3944 addq foo@gottpoff(%rip), %rax */
3945 if (ABI_64_P (output_bfd
))
3946 memcpy (contents
+ roff
- 4,
3947 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3950 memcpy (contents
+ roff
- 3,
3951 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3954 relocation
= (htab
->elf
.sgot
->output_section
->vma
3955 + htab
->elf
.sgot
->output_offset
+ off
3957 - input_section
->output_section
->vma
3958 - input_section
->output_offset
3960 bfd_put_32 (output_bfd
, relocation
,
3961 contents
+ roff
+ 8);
3962 /* Skip R_X86_64_PLT32. */
3966 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3968 /* GDesc -> IE transition.
3969 It's originally something like:
3970 leaq x@tlsdesc(%rip), %rax
3973 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3975 /* Now modify the instruction as appropriate. To
3976 turn a leaq into a movq in the form we use it, it
3977 suffices to change the second byte from 0x8d to
3979 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3981 bfd_put_32 (output_bfd
,
3982 htab
->elf
.sgot
->output_section
->vma
3983 + htab
->elf
.sgot
->output_offset
+ off
3985 - input_section
->output_section
->vma
3986 - input_section
->output_offset
3991 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3993 /* GDesc -> IE transition.
4000 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4001 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4009 case R_X86_64_TLSLD
:
4010 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4011 input_section
, contents
,
4012 symtab_hdr
, sym_hashes
,
4013 &r_type
, GOT_UNKNOWN
,
4014 rel
, relend
, h
, r_symndx
))
4017 if (r_type
!= R_X86_64_TLSLD
)
4019 /* LD->LE transition:
4020 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4021 For 64bit, we change it into:
4022 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4023 For 32bit, we change it into:
4024 nopl 0x0(%rax); movl %fs:0, %eax. */
4026 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4027 if (ABI_64_P (output_bfd
))
4028 memcpy (contents
+ rel
->r_offset
- 3,
4029 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4031 memcpy (contents
+ rel
->r_offset
- 3,
4032 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4033 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4038 if (htab
->elf
.sgot
== NULL
)
4041 off
= htab
->tls_ld_got
.offset
;
4046 Elf_Internal_Rela outrel
;
4048 if (htab
->elf
.srelgot
== NULL
)
4051 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4052 + htab
->elf
.sgot
->output_offset
+ off
);
4054 bfd_put_64 (output_bfd
, 0,
4055 htab
->elf
.sgot
->contents
+ off
);
4056 bfd_put_64 (output_bfd
, 0,
4057 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4058 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4059 outrel
.r_addend
= 0;
4060 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4062 htab
->tls_ld_got
.offset
|= 1;
4064 relocation
= htab
->elf
.sgot
->output_section
->vma
4065 + htab
->elf
.sgot
->output_offset
+ off
;
4066 unresolved_reloc
= FALSE
;
4069 case R_X86_64_DTPOFF32
:
4070 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4071 relocation
-= elf_x86_64_dtpoff_base (info
);
4073 relocation
= elf_x86_64_tpoff (info
, relocation
);
4076 case R_X86_64_TPOFF32
:
4077 case R_X86_64_TPOFF64
:
4078 BFD_ASSERT (info
->executable
);
4079 relocation
= elf_x86_64_tpoff (info
, relocation
);
4086 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4087 because such sections are not SEC_ALLOC and thus ld.so will
4088 not process them. */
4089 if (unresolved_reloc
4090 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4092 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4093 rel
->r_offset
) != (bfd_vma
) -1)
4094 (*_bfd_error_handler
)
4095 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4098 (long) rel
->r_offset
,
4100 h
->root
.root
.string
);
4103 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4104 contents
, rel
->r_offset
,
4105 relocation
, rel
->r_addend
);
4107 check_relocation_error
:
4108 if (r
!= bfd_reloc_ok
)
4113 name
= h
->root
.root
.string
;
4116 name
= bfd_elf_string_from_elf_section (input_bfd
,
4117 symtab_hdr
->sh_link
,
4122 name
= bfd_section_name (input_bfd
, sec
);
4125 if (r
== bfd_reloc_overflow
)
4127 if (! ((*info
->callbacks
->reloc_overflow
)
4128 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4129 (bfd_vma
) 0, input_bfd
, input_section
,
4135 (*_bfd_error_handler
)
4136 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4137 input_bfd
, input_section
,
4138 (long) rel
->r_offset
, name
, (int) r
);
4147 /* Finish up dynamic symbol handling. We set the contents of various
4148 dynamic sections here. */
4151 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4152 struct bfd_link_info
*info
,
4153 struct elf_link_hash_entry
*h
,
4154 Elf_Internal_Sym
*sym
)
4156 struct elf_x86_64_link_hash_table
*htab
;
4158 htab
= elf_x86_64_hash_table (info
);
4162 if (h
->plt
.offset
!= (bfd_vma
) -1)
4166 Elf_Internal_Rela rela
;
4168 asection
*plt
, *gotplt
, *relplt
;
4169 const struct elf_backend_data
*bed
;
4171 /* When building a static executable, use .iplt, .igot.plt and
4172 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4173 if (htab
->elf
.splt
!= NULL
)
4175 plt
= htab
->elf
.splt
;
4176 gotplt
= htab
->elf
.sgotplt
;
4177 relplt
= htab
->elf
.srelplt
;
4181 plt
= htab
->elf
.iplt
;
4182 gotplt
= htab
->elf
.igotplt
;
4183 relplt
= htab
->elf
.irelplt
;
4186 /* This symbol has an entry in the procedure linkage table. Set
4188 if ((h
->dynindx
== -1
4189 && !((h
->forced_local
|| info
->executable
)
4191 && h
->type
== STT_GNU_IFUNC
))
4197 /* Get the index in the procedure linkage table which
4198 corresponds to this symbol. This is the index of this symbol
4199 in all the symbols for which we are making plt entries. The
4200 first entry in the procedure linkage table is reserved.
4202 Get the offset into the .got table of the entry that
4203 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4204 bytes. The first three are reserved for the dynamic linker.
4206 For static executables, we don't reserve anything. */
4208 if (plt
== htab
->elf
.splt
)
4210 got_offset
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4211 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4215 got_offset
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4216 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4219 /* Fill in the entry in the procedure linkage table. */
4220 memcpy (plt
->contents
+ h
->plt
.offset
, elf_x86_64_plt_entry
,
4223 /* Insert the relocation positions of the plt section. The magic
4224 numbers at the end of the statements are the positions of the
4225 relocations in the plt section. */
4226 /* Put offset for jmp *name@GOTPCREL(%rip), since the
4227 instruction uses 6 bytes, subtract this value. */
4228 bfd_put_32 (output_bfd
,
4229 (gotplt
->output_section
->vma
4230 + gotplt
->output_offset
4232 - plt
->output_section
->vma
4233 - plt
->output_offset
4236 plt
->contents
+ h
->plt
.offset
+ 2);
4238 /* Fill in the entry in the global offset table, initially this
4239 points to the pushq instruction in the PLT which is at offset 6. */
4240 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4241 + plt
->output_offset
4242 + h
->plt
.offset
+ 6),
4243 gotplt
->contents
+ got_offset
);
4245 /* Fill in the entry in the .rela.plt section. */
4246 rela
.r_offset
= (gotplt
->output_section
->vma
4247 + gotplt
->output_offset
4249 if (h
->dynindx
== -1
4250 || ((info
->executable
4251 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4253 && h
->type
== STT_GNU_IFUNC
))
4255 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4256 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4257 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4258 rela
.r_addend
= (h
->root
.u
.def
.value
4259 + h
->root
.u
.def
.section
->output_section
->vma
4260 + h
->root
.u
.def
.section
->output_offset
);
4261 /* R_X86_64_IRELATIVE comes last. */
4262 plt_index
= htab
->next_irelative_index
--;
4266 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4268 plt_index
= htab
->next_jump_slot_index
++;
4271 /* Don't fill PLT entry for static executables. */
4272 if (plt
== htab
->elf
.splt
)
4274 /* Put relocation index. */
4275 bfd_put_32 (output_bfd
, plt_index
,
4276 plt
->contents
+ h
->plt
.offset
+ 7);
4277 /* Put offset for jmp .PLT0. */
4278 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4279 plt
->contents
+ h
->plt
.offset
+ 12);
4282 bed
= get_elf_backend_data (output_bfd
);
4283 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4284 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4286 if (!h
->def_regular
)
4288 /* Mark the symbol as undefined, rather than as defined in
4289 the .plt section. Leave the value if there were any
4290 relocations where pointer equality matters (this is a clue
4291 for the dynamic linker, to make function pointer
4292 comparisons work between an application and shared
4293 library), otherwise set it to zero. If a function is only
4294 called from a binary, there is no need to slow down
4295 shared libraries because of that. */
4296 sym
->st_shndx
= SHN_UNDEF
;
4297 if (!h
->pointer_equality_needed
)
4302 if (h
->got
.offset
!= (bfd_vma
) -1
4303 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4304 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4306 Elf_Internal_Rela rela
;
4308 /* This symbol has an entry in the global offset table. Set it
4310 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4313 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4314 + htab
->elf
.sgot
->output_offset
4315 + (h
->got
.offset
&~ (bfd_vma
) 1));
4317 /* If this is a static link, or it is a -Bsymbolic link and the
4318 symbol is defined locally or was forced to be local because
4319 of a version file, we just want to emit a RELATIVE reloc.
4320 The entry in the global offset table will already have been
4321 initialized in the relocate_section function. */
4323 && h
->type
== STT_GNU_IFUNC
)
4327 /* Generate R_X86_64_GLOB_DAT. */
4334 if (!h
->pointer_equality_needed
)
4337 /* For non-shared object, we can't use .got.plt, which
4338 contains the real function addres if we need pointer
4339 equality. We load the GOT entry with the PLT entry. */
4340 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4341 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4342 + plt
->output_offset
4344 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4348 else if (info
->shared
4349 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4351 if (!h
->def_regular
)
4353 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4354 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4355 rela
.r_addend
= (h
->root
.u
.def
.value
4356 + h
->root
.u
.def
.section
->output_section
->vma
4357 + h
->root
.u
.def
.section
->output_offset
);
4361 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4363 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4364 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4365 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4369 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4374 Elf_Internal_Rela rela
;
4376 /* This symbol needs a copy reloc. Set it up. */
4378 if (h
->dynindx
== -1
4379 || (h
->root
.type
!= bfd_link_hash_defined
4380 && h
->root
.type
!= bfd_link_hash_defweak
)
4381 || htab
->srelbss
== NULL
)
4384 rela
.r_offset
= (h
->root
.u
.def
.value
4385 + h
->root
.u
.def
.section
->output_section
->vma
4386 + h
->root
.u
.def
.section
->output_offset
);
4387 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4389 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4392 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4393 be NULL for local symbols. */
4395 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4396 || h
== htab
->elf
.hgot
))
4397 sym
->st_shndx
= SHN_ABS
;
4402 /* Finish up local dynamic symbol handling. We set the contents of
4403 various dynamic sections here. */
4406 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4408 struct elf_link_hash_entry
*h
4409 = (struct elf_link_hash_entry
*) *slot
;
4410 struct bfd_link_info
*info
4411 = (struct bfd_link_info
*) inf
;
4413 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4417 /* Used to decide how to sort relocs in an optimal manner for the
4418 dynamic linker, before writing them out. */
4420 static enum elf_reloc_type_class
4421 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4423 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4425 case R_X86_64_RELATIVE
:
4426 return reloc_class_relative
;
4427 case R_X86_64_JUMP_SLOT
:
4428 return reloc_class_plt
;
4430 return reloc_class_copy
;
4432 return reloc_class_normal
;
4436 /* Finish up the dynamic sections. */
4439 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4440 struct bfd_link_info
*info
)
4442 struct elf_x86_64_link_hash_table
*htab
;
4446 htab
= elf_x86_64_hash_table (info
);
4450 dynobj
= htab
->elf
.dynobj
;
4451 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4453 if (htab
->elf
.dynamic_sections_created
)
4455 bfd_byte
*dyncon
, *dynconend
;
4456 const struct elf_backend_data
*bed
;
4457 bfd_size_type sizeof_dyn
;
4459 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4462 bed
= get_elf_backend_data (dynobj
);
4463 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4464 dyncon
= sdyn
->contents
;
4465 dynconend
= sdyn
->contents
+ sdyn
->size
;
4466 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4468 Elf_Internal_Dyn dyn
;
4471 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4479 s
= htab
->elf
.sgotplt
;
4480 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4484 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4488 s
= htab
->elf
.srelplt
->output_section
;
4489 dyn
.d_un
.d_val
= s
->size
;
4493 /* The procedure linkage table relocs (DT_JMPREL) should
4494 not be included in the overall relocs (DT_RELA).
4495 Therefore, we override the DT_RELASZ entry here to
4496 make it not include the JMPREL relocs. Since the
4497 linker script arranges for .rela.plt to follow all
4498 other relocation sections, we don't have to worry
4499 about changing the DT_RELA entry. */
4500 if (htab
->elf
.srelplt
!= NULL
)
4502 s
= htab
->elf
.srelplt
->output_section
;
4503 dyn
.d_un
.d_val
-= s
->size
;
4507 case DT_TLSDESC_PLT
:
4509 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4510 + htab
->tlsdesc_plt
;
4513 case DT_TLSDESC_GOT
:
4515 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4516 + htab
->tlsdesc_got
;
4520 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4523 /* Fill in the special first entry in the procedure linkage table. */
4524 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4526 /* Fill in the first entry in the procedure linkage table. */
4527 memcpy (htab
->elf
.splt
->contents
, elf_x86_64_plt0_entry
,
4529 /* Add offset for pushq GOT+8(%rip), since the instruction
4530 uses 6 bytes subtract this value. */
4531 bfd_put_32 (output_bfd
,
4532 (htab
->elf
.sgotplt
->output_section
->vma
4533 + htab
->elf
.sgotplt
->output_offset
4535 - htab
->elf
.splt
->output_section
->vma
4536 - htab
->elf
.splt
->output_offset
4538 htab
->elf
.splt
->contents
+ 2);
4539 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4540 the end of the instruction. */
4541 bfd_put_32 (output_bfd
,
4542 (htab
->elf
.sgotplt
->output_section
->vma
4543 + htab
->elf
.sgotplt
->output_offset
4545 - htab
->elf
.splt
->output_section
->vma
4546 - htab
->elf
.splt
->output_offset
4548 htab
->elf
.splt
->contents
+ 8);
4550 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
=
4553 if (htab
->tlsdesc_plt
)
4555 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4556 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4558 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4559 elf_x86_64_plt0_entry
,
4562 /* Add offset for pushq GOT+8(%rip), since the
4563 instruction uses 6 bytes subtract this value. */
4564 bfd_put_32 (output_bfd
,
4565 (htab
->elf
.sgotplt
->output_section
->vma
4566 + htab
->elf
.sgotplt
->output_offset
4568 - htab
->elf
.splt
->output_section
->vma
4569 - htab
->elf
.splt
->output_offset
4572 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 2);
4573 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4574 htab->tlsdesc_got. The 12 is the offset to the end of
4576 bfd_put_32 (output_bfd
,
4577 (htab
->elf
.sgot
->output_section
->vma
4578 + htab
->elf
.sgot
->output_offset
4580 - htab
->elf
.splt
->output_section
->vma
4581 - htab
->elf
.splt
->output_offset
4584 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
4589 if (htab
->elf
.sgotplt
)
4591 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4593 (*_bfd_error_handler
)
4594 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4598 /* Fill in the first three entries in the global offset table. */
4599 if (htab
->elf
.sgotplt
->size
> 0)
4601 /* Set the first entry in the global offset table to the address of
4602 the dynamic section. */
4604 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4606 bfd_put_64 (output_bfd
,
4607 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4608 htab
->elf
.sgotplt
->contents
);
4609 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4610 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4611 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4614 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4618 /* Adjust .eh_frame for .plt section. */
4619 if (htab
->plt_eh_frame
!= NULL
)
4621 if (htab
->elf
.splt
!= NULL
4622 && htab
->elf
.splt
->size
!= 0
4623 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4624 && htab
->elf
.splt
->output_section
!= NULL
4625 && htab
->plt_eh_frame
->output_section
!= NULL
)
4627 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4628 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4629 + htab
->plt_eh_frame
->output_offset
4630 + PLT_FDE_START_OFFSET
;
4631 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4632 htab
->plt_eh_frame
->contents
4633 + PLT_FDE_START_OFFSET
);
4635 if (htab
->plt_eh_frame
->sec_info_type
4636 == ELF_INFO_TYPE_EH_FRAME
)
4638 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4640 htab
->plt_eh_frame
->contents
))
4645 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4646 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4649 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4650 htab_traverse (htab
->loc_hash_table
,
4651 elf_x86_64_finish_local_dynamic_symbol
,
4657 /* Return address for Ith PLT stub in section PLT, for relocation REL
4658 or (bfd_vma) -1 if it should not be included. */
4661 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4662 const arelent
*rel ATTRIBUTE_UNUSED
)
4664 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4667 /* Handle an x86-64 specific section when reading an object file. This
4668 is called when elfcode.h finds a section with an unknown type. */
4671 elf_x86_64_section_from_shdr (bfd
*abfd
,
4672 Elf_Internal_Shdr
*hdr
,
4676 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4679 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4685 /* Hook called by the linker routine which adds symbols from an object
4686 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4690 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4691 struct bfd_link_info
*info
,
4692 Elf_Internal_Sym
*sym
,
4693 const char **namep ATTRIBUTE_UNUSED
,
4694 flagword
*flagsp ATTRIBUTE_UNUSED
,
4700 switch (sym
->st_shndx
)
4702 case SHN_X86_64_LCOMMON
:
4703 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4706 lcomm
= bfd_make_section_with_flags (abfd
,
4710 | SEC_LINKER_CREATED
));
4713 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4716 *valp
= sym
->st_size
;
4720 if ((abfd
->flags
& DYNAMIC
) == 0
4721 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4722 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4723 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4729 /* Given a BFD section, try to locate the corresponding ELF section
4733 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4734 asection
*sec
, int *index_return
)
4736 if (sec
== &_bfd_elf_large_com_section
)
4738 *index_return
= SHN_X86_64_LCOMMON
;
4744 /* Process a symbol. */
4747 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4750 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4752 switch (elfsym
->internal_elf_sym
.st_shndx
)
4754 case SHN_X86_64_LCOMMON
:
4755 asym
->section
= &_bfd_elf_large_com_section
;
4756 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4757 /* Common symbol doesn't set BSF_GLOBAL. */
4758 asym
->flags
&= ~BSF_GLOBAL
;
4764 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4766 return (sym
->st_shndx
== SHN_COMMON
4767 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4771 elf_x86_64_common_section_index (asection
*sec
)
4773 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4776 return SHN_X86_64_LCOMMON
;
4780 elf_x86_64_common_section (asection
*sec
)
4782 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4783 return bfd_com_section_ptr
;
4785 return &_bfd_elf_large_com_section
;
4789 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4790 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4791 struct elf_link_hash_entry
*h
,
4792 Elf_Internal_Sym
*sym
,
4794 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4795 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4796 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4797 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4798 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4799 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4800 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4801 bfd_boolean
*newdef
,
4802 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4803 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4804 bfd
*abfd ATTRIBUTE_UNUSED
,
4806 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4807 bfd_boolean
*olddef
,
4808 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4809 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4813 /* A normal common symbol and a large common symbol result in a
4814 normal common symbol. We turn the large common symbol into a
4817 && h
->root
.type
== bfd_link_hash_common
4819 && bfd_is_com_section (*sec
)
4822 if (sym
->st_shndx
== SHN_COMMON
4823 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4825 h
->root
.u
.c
.p
->section
4826 = bfd_make_section_old_way (oldbfd
, "COMMON");
4827 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4829 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4830 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4831 *psec
= *sec
= bfd_com_section_ptr
;
4838 elf_x86_64_additional_program_headers (bfd
*abfd
,
4839 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4844 /* Check to see if we need a large readonly segment. */
4845 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4846 if (s
&& (s
->flags
& SEC_LOAD
))
4849 /* Check to see if we need a large data segment. Since .lbss sections
4850 is placed right after the .bss section, there should be no need for
4851 a large data segment just because of .lbss. */
4852 s
= bfd_get_section_by_name (abfd
, ".ldata");
4853 if (s
&& (s
->flags
& SEC_LOAD
))
4859 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4862 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4864 if (h
->plt
.offset
!= (bfd_vma
) -1
4866 && !h
->pointer_equality_needed
)
4869 return _bfd_elf_hash_symbol (h
);
4872 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4875 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4876 const bfd_target
*output
)
4878 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4879 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4880 && _bfd_elf_relocs_compatible (input
, output
));
4883 static const struct bfd_elf_special_section
4884 elf_x86_64_special_sections
[]=
4886 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4887 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4888 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4889 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4890 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4891 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4892 { NULL
, 0, 0, 0, 0 }
4895 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4896 #define TARGET_LITTLE_NAME "elf64-x86-64"
4897 #define ELF_ARCH bfd_arch_i386
4898 #define ELF_TARGET_ID X86_64_ELF_DATA
4899 #define ELF_MACHINE_CODE EM_X86_64
4900 #define ELF_MAXPAGESIZE 0x200000
4901 #define ELF_MINPAGESIZE 0x1000
4902 #define ELF_COMMONPAGESIZE 0x1000
4904 #define elf_backend_can_gc_sections 1
4905 #define elf_backend_can_refcount 1
4906 #define elf_backend_want_got_plt 1
4907 #define elf_backend_plt_readonly 1
4908 #define elf_backend_want_plt_sym 0
4909 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4910 #define elf_backend_rela_normal 1
4911 #define elf_backend_plt_alignment 4
4913 #define elf_info_to_howto elf_x86_64_info_to_howto
4915 #define bfd_elf64_bfd_link_hash_table_create \
4916 elf_x86_64_link_hash_table_create
4917 #define bfd_elf64_bfd_link_hash_table_free \
4918 elf_x86_64_link_hash_table_free
4919 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4920 #define bfd_elf64_bfd_reloc_name_lookup \
4921 elf_x86_64_reloc_name_lookup
4923 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4924 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4925 #define elf_backend_check_relocs elf_x86_64_check_relocs
4926 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
4927 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
4928 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
4929 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
4930 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
4931 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
4932 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
4933 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
4935 #define elf_backend_write_core_note elf_x86_64_write_core_note
4937 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
4938 #define elf_backend_relocate_section elf_x86_64_relocate_section
4939 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
4940 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
4941 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4942 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
4943 #define elf_backend_object_p elf64_x86_64_elf_object_p
4944 #define bfd_elf64_mkobject elf_x86_64_mkobject
4946 #define elf_backend_section_from_shdr \
4947 elf_x86_64_section_from_shdr
4949 #define elf_backend_section_from_bfd_section \
4950 elf_x86_64_elf_section_from_bfd_section
4951 #define elf_backend_add_symbol_hook \
4952 elf_x86_64_add_symbol_hook
4953 #define elf_backend_symbol_processing \
4954 elf_x86_64_symbol_processing
4955 #define elf_backend_common_section_index \
4956 elf_x86_64_common_section_index
4957 #define elf_backend_common_section \
4958 elf_x86_64_common_section
4959 #define elf_backend_common_definition \
4960 elf_x86_64_common_definition
4961 #define elf_backend_merge_symbol \
4962 elf_x86_64_merge_symbol
4963 #define elf_backend_special_sections \
4964 elf_x86_64_special_sections
4965 #define elf_backend_additional_program_headers \
4966 elf_x86_64_additional_program_headers
4967 #define elf_backend_hash_symbol \
4968 elf_x86_64_hash_symbol
4970 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4972 #include "elf64-target.h"
4974 /* FreeBSD support. */
4976 #undef TARGET_LITTLE_SYM
4977 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4978 #undef TARGET_LITTLE_NAME
4979 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4982 #define ELF_OSABI ELFOSABI_FREEBSD
4985 #define elf64_bed elf64_x86_64_fbsd_bed
4987 #include "elf64-target.h"
4989 /* Solaris 2 support. */
4991 #undef TARGET_LITTLE_SYM
4992 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4993 #undef TARGET_LITTLE_NAME
4994 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4996 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4997 objects won't be recognized. */
5001 #define elf64_bed elf64_x86_64_sol2_bed
5003 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5005 #undef elf_backend_static_tls_alignment
5006 #define elf_backend_static_tls_alignment 16
5008 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5010 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5012 #undef elf_backend_want_plt_sym
5013 #define elf_backend_want_plt_sym 1
5015 #include "elf64-target.h"
5017 /* Intel L1OM support. */
5020 elf64_l1om_elf_object_p (bfd
*abfd
)
5022 /* Set the right machine number for an L1OM elf64 file. */
5023 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5027 #undef TARGET_LITTLE_SYM
5028 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5029 #undef TARGET_LITTLE_NAME
5030 #define TARGET_LITTLE_NAME "elf64-l1om"
5032 #define ELF_ARCH bfd_arch_l1om
5034 #undef ELF_MACHINE_CODE
5035 #define ELF_MACHINE_CODE EM_L1OM
5040 #define elf64_bed elf64_l1om_bed
5042 #undef elf_backend_object_p
5043 #define elf_backend_object_p elf64_l1om_elf_object_p
5045 #undef elf_backend_static_tls_alignment
5047 #undef elf_backend_want_plt_sym
5048 #define elf_backend_want_plt_sym 0
5050 #include "elf64-target.h"
5052 /* FreeBSD L1OM support. */
5054 #undef TARGET_LITTLE_SYM
5055 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5056 #undef TARGET_LITTLE_NAME
5057 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5060 #define ELF_OSABI ELFOSABI_FREEBSD
5063 #define elf64_bed elf64_l1om_fbsd_bed
5065 #include "elf64-target.h"
5067 /* Intel K1OM support. */
5070 elf64_k1om_elf_object_p (bfd
*abfd
)
5072 /* Set the right machine number for an K1OM elf64 file. */
5073 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5077 #undef TARGET_LITTLE_SYM
5078 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5079 #undef TARGET_LITTLE_NAME
5080 #define TARGET_LITTLE_NAME "elf64-k1om"
5082 #define ELF_ARCH bfd_arch_k1om
5084 #undef ELF_MACHINE_CODE
5085 #define ELF_MACHINE_CODE EM_K1OM
5090 #define elf64_bed elf64_k1om_bed
5092 #undef elf_backend_object_p
5093 #define elf_backend_object_p elf64_k1om_elf_object_p
5095 #undef elf_backend_static_tls_alignment
5097 #undef elf_backend_want_plt_sym
5098 #define elf_backend_want_plt_sym 0
5100 #include "elf64-target.h"
5102 /* FreeBSD K1OM support. */
5104 #undef TARGET_LITTLE_SYM
5105 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5106 #undef TARGET_LITTLE_NAME
5107 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5110 #define ELF_OSABI ELFOSABI_FREEBSD
5113 #define elf64_bed elf64_k1om_fbsd_bed
5115 #include "elf64-target.h"
5117 /* 32bit x86-64 support. */
5120 elf32_x86_64_elf_object_p (bfd
*abfd
)
5122 /* Set the right machine number for an x86-64 elf32 file. */
5123 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
5127 #undef TARGET_LITTLE_SYM
5128 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5129 #undef TARGET_LITTLE_NAME
5130 #define TARGET_LITTLE_NAME "elf32-x86-64"
5133 #define ELF_ARCH bfd_arch_i386
5135 #undef ELF_MACHINE_CODE
5136 #define ELF_MACHINE_CODE EM_X86_64
5138 #define bfd_elf32_bfd_link_hash_table_create \
5139 elf_x86_64_link_hash_table_create
5140 #define bfd_elf32_bfd_link_hash_table_free \
5141 elf_x86_64_link_hash_table_free
5142 #define bfd_elf32_bfd_reloc_type_lookup \
5143 elf_x86_64_reloc_type_lookup
5144 #define bfd_elf32_bfd_reloc_name_lookup \
5145 elf_x86_64_reloc_name_lookup
5146 #define bfd_elf32_mkobject \
5151 #undef elf_backend_object_p
5152 #define elf_backend_object_p \
5153 elf32_x86_64_elf_object_p
5155 #undef elf_backend_bfd_from_remote_memory
5156 #define elf_backend_bfd_from_remote_memory \
5157 _bfd_elf32_bfd_from_remote_memory
5159 #undef elf_backend_size_info
5160 #define elf_backend_size_info \
5161 _bfd_elf32_size_info
5163 #include "elf32-target.h"