1 /* X86-64 specific support for ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Jan Hubicka <jh@suse.cz>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
29 #include "bfd_stdint.h"
33 #include "libiberty.h"
35 #include "elf/x86-64.h"
42 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
43 #define MINUS_ONE (~ (bfd_vma) 0)
45 /* Since both 32-bit and 64-bit x86-64 encode relocation type in the
46 identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get
47 relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE
48 since they are the same. */
50 #define ABI_64_P(abfd) \
51 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
53 /* The relocation "howto" table. Order of fields:
54 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
55 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
56 static reloc_howto_type x86_64_elf_howto_table
[] =
58 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
59 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
61 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
64 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
65 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
67 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
71 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
74 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
79 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
80 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
82 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
85 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
86 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
88 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
89 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
91 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
92 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
94 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
95 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
96 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
98 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
99 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
100 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
101 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
102 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
103 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
105 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
106 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
108 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
111 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
112 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
114 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
115 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
117 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
118 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
120 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
121 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
123 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
124 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
126 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
127 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
129 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
130 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
131 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
132 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
133 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
134 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
135 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
136 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
138 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
139 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
141 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
142 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
143 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
144 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
145 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
147 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
148 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
152 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
153 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
154 "R_X86_64_GOTPC32_TLSDESC",
155 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
156 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
157 complain_overflow_dont
, bfd_elf_generic_reloc
,
158 "R_X86_64_TLSDESC_CALL",
160 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
161 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
163 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
164 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
165 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
167 HOWTO(R_X86_64_RELATIVE64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
168 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE64", FALSE
, MINUS_ONE
,
171 /* We have a gap in the reloc numbers here.
172 R_X86_64_standard counts the number up to this point, and
173 R_X86_64_vt_offset is the value to subtract from a reloc type of
174 R_X86_64_GNU_VT* to form an index into this table. */
175 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
176 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
178 /* GNU extension to record C++ vtable hierarchy. */
179 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
180 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
182 /* GNU extension to record C++ vtable member usage. */
183 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
184 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
187 /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
188 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
189 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
193 #define IS_X86_64_PCREL_TYPE(TYPE) \
194 ( ((TYPE) == R_X86_64_PC8) \
195 || ((TYPE) == R_X86_64_PC16) \
196 || ((TYPE) == R_X86_64_PC32) \
197 || ((TYPE) == R_X86_64_PC64))
199 /* Map BFD relocs to the x86_64 elf relocs. */
202 bfd_reloc_code_real_type bfd_reloc_val
;
203 unsigned char elf_reloc_val
;
206 static const struct elf_reloc_map x86_64_reloc_map
[] =
208 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
209 { BFD_RELOC_64
, R_X86_64_64
, },
210 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
211 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
212 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
213 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
214 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
215 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
216 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
217 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
218 { BFD_RELOC_32
, R_X86_64_32
, },
219 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
220 { BFD_RELOC_16
, R_X86_64_16
, },
221 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
222 { BFD_RELOC_8
, R_X86_64_8
, },
223 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
224 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
225 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
226 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
227 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
228 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
229 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
230 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
231 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
232 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
233 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
234 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
235 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
236 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
237 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
238 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
239 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
240 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
241 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
242 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
243 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
244 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
245 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
248 static reloc_howto_type
*
249 elf_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
253 if (r_type
== (unsigned int) R_X86_64_32
)
258 i
= ARRAY_SIZE (x86_64_elf_howto_table
) - 1;
260 else if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
261 || r_type
>= (unsigned int) R_X86_64_max
)
263 if (r_type
>= (unsigned int) R_X86_64_standard
)
265 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
267 r_type
= R_X86_64_NONE
;
272 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
273 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
274 return &x86_64_elf_howto_table
[i
];
277 /* Given a BFD reloc type, return a HOWTO structure. */
278 static reloc_howto_type
*
279 elf_x86_64_reloc_type_lookup (bfd
*abfd
,
280 bfd_reloc_code_real_type code
)
284 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
287 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
288 return elf_x86_64_rtype_to_howto (abfd
,
289 x86_64_reloc_map
[i
].elf_reloc_val
);
294 static reloc_howto_type
*
295 elf_x86_64_reloc_name_lookup (bfd
*abfd
,
300 if (!ABI_64_P (abfd
) && strcasecmp (r_name
, "R_X86_64_32") == 0)
302 /* Get x32 R_X86_64_32. */
303 reloc_howto_type
*reloc
304 = &x86_64_elf_howto_table
[ARRAY_SIZE (x86_64_elf_howto_table
) - 1];
305 BFD_ASSERT (reloc
->type
== (unsigned int) R_X86_64_32
);
309 for (i
= 0; i
< ARRAY_SIZE (x86_64_elf_howto_table
); i
++)
310 if (x86_64_elf_howto_table
[i
].name
!= NULL
311 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
312 return &x86_64_elf_howto_table
[i
];
317 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
320 elf_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
321 Elf_Internal_Rela
*dst
)
325 r_type
= ELF32_R_TYPE (dst
->r_info
);
326 cache_ptr
->howto
= elf_x86_64_rtype_to_howto (abfd
, r_type
);
327 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
330 /* Support for core dump NOTE sections. */
332 elf_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
337 switch (note
->descsz
)
342 case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */
344 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
347 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
355 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
357 elf_tdata (abfd
)->core_signal
358 = bfd_get_16 (abfd
, note
->descdata
+ 12);
361 elf_tdata (abfd
)->core_lwpid
362 = bfd_get_32 (abfd
, note
->descdata
+ 32);
371 /* Make a ".reg/999" section. */
372 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
373 size
, note
->descpos
+ offset
);
377 elf_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
379 switch (note
->descsz
)
384 case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
385 elf_tdata (abfd
)->core_pid
386 = bfd_get_32 (abfd
, note
->descdata
+ 12);
387 elf_tdata (abfd
)->core_program
388 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
389 elf_tdata (abfd
)->core_command
390 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
393 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
394 elf_tdata (abfd
)->core_pid
395 = bfd_get_32 (abfd
, note
->descdata
+ 24);
396 elf_tdata (abfd
)->core_program
397 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
398 elf_tdata (abfd
)->core_command
399 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
402 /* Note that for some reason, a spurious space is tacked
403 onto the end of the args in some (at least one anyway)
404 implementations, so strip it off if it exists. */
407 char *command
= elf_tdata (abfd
)->core_command
;
408 int n
= strlen (command
);
410 if (0 < n
&& command
[n
- 1] == ' ')
411 command
[n
- 1] = '\0';
419 elf_x86_64_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
422 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
424 const char *fname
, *psargs
;
435 va_start (ap
, note_type
);
436 fname
= va_arg (ap
, const char *);
437 psargs
= va_arg (ap
, const char *);
440 if (bed
->s
->elfclass
== ELFCLASS32
)
443 memset (&data
, 0, sizeof (data
));
444 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
445 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
446 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
447 &data
, sizeof (data
));
452 memset (&data
, 0, sizeof (data
));
453 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
454 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
455 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
456 &data
, sizeof (data
));
461 va_start (ap
, note_type
);
462 pid
= va_arg (ap
, long);
463 cursig
= va_arg (ap
, int);
464 gregs
= va_arg (ap
, const void *);
467 if (bed
->s
->elfclass
== ELFCLASS32
)
469 if (bed
->elf_machine_code
== EM_X86_64
)
471 prstatusx32_t prstat
;
472 memset (&prstat
, 0, sizeof (prstat
));
474 prstat
.pr_cursig
= cursig
;
475 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
476 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
477 &prstat
, sizeof (prstat
));
482 memset (&prstat
, 0, sizeof (prstat
));
484 prstat
.pr_cursig
= cursig
;
485 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
486 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
487 &prstat
, sizeof (prstat
));
493 memset (&prstat
, 0, sizeof (prstat
));
495 prstat
.pr_cursig
= cursig
;
496 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
497 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
,
498 &prstat
, sizeof (prstat
));
505 /* Functions for the x86-64 ELF linker. */
507 /* The name of the dynamic interpreter. This is put in the .interp
510 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
511 #define ELF32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
513 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
514 copying dynamic variables from a shared lib into an app's dynbss
515 section, and instead use a dynamic relocation to point into the
517 #define ELIMINATE_COPY_RELOCS 1
519 /* The size in bytes of an entry in the global offset table. */
521 #define GOT_ENTRY_SIZE 8
523 /* The size in bytes of an entry in the procedure linkage table. */
525 #define PLT_ENTRY_SIZE 16
527 /* The first entry in a procedure linkage table looks like this. See the
528 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
530 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
532 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
533 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
534 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
537 /* Subsequent entries in a procedure linkage table look like this. */
539 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
541 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
542 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
543 0x68, /* pushq immediate */
544 0, 0, 0, 0, /* replaced with index into relocation table. */
545 0xe9, /* jmp relative */
546 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
549 /* .eh_frame covering the .plt section. */
551 static const bfd_byte elf_x86_64_eh_frame_plt
[] =
553 #define PLT_CIE_LENGTH 20
554 #define PLT_FDE_LENGTH 36
555 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
556 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
557 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
558 0, 0, 0, 0, /* CIE ID */
560 'z', 'R', 0, /* Augmentation string */
561 1, /* Code alignment factor */
562 0x78, /* Data alignment factor */
563 16, /* Return address column */
564 1, /* Augmentation size */
565 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
566 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
567 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
568 DW_CFA_nop
, DW_CFA_nop
,
570 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
571 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
572 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
573 0, 0, 0, 0, /* .plt size goes here */
574 0, /* Augmentation size */
575 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
576 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
577 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
578 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
579 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
580 11, /* Block length */
581 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
582 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
583 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
584 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
585 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
588 /* Architecture-specific backend data for x86-64. */
590 struct elf_x86_64_backend_data
592 /* Templates for the initial PLT entry and for subsequent entries. */
593 const bfd_byte
*plt0_entry
;
594 const bfd_byte
*plt_entry
;
595 unsigned int plt_entry_size
; /* Size of each PLT entry. */
597 /* Offsets into plt0_entry that are to be replaced with GOT[1] and GOT[2]. */
598 unsigned int plt0_got1_offset
;
599 unsigned int plt0_got2_offset
;
601 /* Offset of the end of the PC-relative instruction containing
603 unsigned int plt0_got2_insn_end
;
605 /* Offsets into plt_entry that are to be replaced with... */
606 unsigned int plt_got_offset
; /* ... address of this symbol in .got. */
607 unsigned int plt_reloc_offset
; /* ... offset into relocation table. */
608 unsigned int plt_plt_offset
; /* ... offset to start of .plt. */
610 /* Length of the PC-relative instruction containing plt_got_offset. */
611 unsigned int plt_got_insn_size
;
613 /* Offset of the end of the PC-relative jump to plt0_entry. */
614 unsigned int plt_plt_insn_end
;
616 /* Offset into plt_entry where the initial value of the GOT entry points. */
617 unsigned int plt_lazy_offset
;
619 /* .eh_frame covering the .plt section. */
620 const bfd_byte
*eh_frame_plt
;
621 unsigned int eh_frame_plt_size
;
624 #define get_elf_x86_64_backend_data(abfd) \
625 ((const struct elf_x86_64_backend_data *) \
626 get_elf_backend_data (abfd)->arch_data)
628 #define GET_PLT_ENTRY_SIZE(abfd) \
629 get_elf_x86_64_backend_data (abfd)->plt_entry_size
631 /* These are the standard parameters. */
632 static const struct elf_x86_64_backend_data elf_x86_64_arch_bed
=
634 elf_x86_64_plt0_entry
, /* plt0_entry */
635 elf_x86_64_plt_entry
, /* plt_entry */
636 sizeof (elf_x86_64_plt_entry
), /* plt_entry_size */
637 2, /* plt0_got1_offset */
638 8, /* plt0_got2_offset */
639 12, /* plt0_got2_insn_end */
640 2, /* plt_got_offset */
641 7, /* plt_reloc_offset */
642 12, /* plt_plt_offset */
643 6, /* plt_got_insn_size */
644 PLT_ENTRY_SIZE
, /* plt_plt_insn_end */
645 6, /* plt_lazy_offset */
646 elf_x86_64_eh_frame_plt
, /* eh_frame_plt */
647 sizeof (elf_x86_64_eh_frame_plt
), /* eh_frame_plt_size */
650 #define elf_backend_arch_data &elf_x86_64_arch_bed
652 /* x86-64 ELF linker hash entry. */
654 struct elf_x86_64_link_hash_entry
656 struct elf_link_hash_entry elf
;
658 /* Track dynamic relocs copied for this symbol. */
659 struct elf_dyn_relocs
*dyn_relocs
;
661 #define GOT_UNKNOWN 0
665 #define GOT_TLS_GDESC 4
666 #define GOT_TLS_GD_BOTH_P(type) \
667 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
668 #define GOT_TLS_GD_P(type) \
669 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
670 #define GOT_TLS_GDESC_P(type) \
671 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
672 #define GOT_TLS_GD_ANY_P(type) \
673 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
674 unsigned char tls_type
;
676 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
677 starting at the end of the jump table. */
681 #define elf_x86_64_hash_entry(ent) \
682 ((struct elf_x86_64_link_hash_entry *)(ent))
684 struct elf_x86_64_obj_tdata
686 struct elf_obj_tdata root
;
688 /* tls_type for each local got entry. */
689 char *local_got_tls_type
;
691 /* GOTPLT entries for TLS descriptors. */
692 bfd_vma
*local_tlsdesc_gotent
;
695 #define elf_x86_64_tdata(abfd) \
696 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
698 #define elf_x86_64_local_got_tls_type(abfd) \
699 (elf_x86_64_tdata (abfd)->local_got_tls_type)
701 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
702 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
704 #define is_x86_64_elf(bfd) \
705 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
706 && elf_tdata (bfd) != NULL \
707 && elf_object_id (bfd) == X86_64_ELF_DATA)
710 elf_x86_64_mkobject (bfd
*abfd
)
712 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
716 /* x86-64 ELF linker hash table. */
718 struct elf_x86_64_link_hash_table
720 struct elf_link_hash_table elf
;
722 /* Short-cuts to get to dynamic linker sections. */
725 asection
*plt_eh_frame
;
729 bfd_signed_vma refcount
;
733 /* The amount of space used by the jump slots in the GOT. */
734 bfd_vma sgotplt_jump_table_size
;
736 /* Small local sym cache. */
737 struct sym_cache sym_cache
;
739 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
740 bfd_vma (*r_sym
) (bfd_vma
);
741 unsigned int pointer_r_type
;
742 const char *dynamic_interpreter
;
743 int dynamic_interpreter_size
;
745 /* _TLS_MODULE_BASE_ symbol. */
746 struct bfd_link_hash_entry
*tls_module_base
;
748 /* Used by local STT_GNU_IFUNC symbols. */
749 htab_t loc_hash_table
;
750 void * loc_hash_memory
;
752 /* The offset into splt of the PLT entry for the TLS descriptor
753 resolver. Special values are 0, if not necessary (or not found
754 to be necessary yet), and -1 if needed but not determined
757 /* The offset into sgot of the GOT entry used by the PLT entry
761 /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */
762 bfd_vma next_jump_slot_index
;
763 /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */
764 bfd_vma next_irelative_index
;
767 /* Get the x86-64 ELF linker hash table from a link_info structure. */
769 #define elf_x86_64_hash_table(p) \
770 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
771 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
773 #define elf_x86_64_compute_jump_table_size(htab) \
774 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
776 /* Create an entry in an x86-64 ELF linker hash table. */
778 static struct bfd_hash_entry
*
779 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
780 struct bfd_hash_table
*table
,
783 /* Allocate the structure if it has not already been allocated by a
787 entry
= (struct bfd_hash_entry
*)
788 bfd_hash_allocate (table
,
789 sizeof (struct elf_x86_64_link_hash_entry
));
794 /* Call the allocation method of the superclass. */
795 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
798 struct elf_x86_64_link_hash_entry
*eh
;
800 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
801 eh
->dyn_relocs
= NULL
;
802 eh
->tls_type
= GOT_UNKNOWN
;
803 eh
->tlsdesc_got
= (bfd_vma
) -1;
809 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
810 for local symbol so that we can handle local STT_GNU_IFUNC symbols
811 as global symbol. We reuse indx and dynstr_index for local symbol
812 hash since they aren't used by global symbols in this backend. */
815 elf_x86_64_local_htab_hash (const void *ptr
)
817 struct elf_link_hash_entry
*h
818 = (struct elf_link_hash_entry
*) ptr
;
819 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
822 /* Compare local hash entries. */
825 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
827 struct elf_link_hash_entry
*h1
828 = (struct elf_link_hash_entry
*) ptr1
;
829 struct elf_link_hash_entry
*h2
830 = (struct elf_link_hash_entry
*) ptr2
;
832 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
835 /* Find and/or create a hash entry for local symbol. */
837 static struct elf_link_hash_entry
*
838 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
839 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
842 struct elf_x86_64_link_hash_entry e
, *ret
;
843 asection
*sec
= abfd
->sections
;
844 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
845 htab
->r_sym (rel
->r_info
));
848 e
.elf
.indx
= sec
->id
;
849 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
850 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
851 create
? INSERT
: NO_INSERT
);
858 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
862 ret
= (struct elf_x86_64_link_hash_entry
*)
863 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
864 sizeof (struct elf_x86_64_link_hash_entry
));
867 memset (ret
, 0, sizeof (*ret
));
868 ret
->elf
.indx
= sec
->id
;
869 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
870 ret
->elf
.dynindx
= -1;
876 /* Create an X86-64 ELF linker hash table. */
878 static struct bfd_link_hash_table
*
879 elf_x86_64_link_hash_table_create (bfd
*abfd
)
881 struct elf_x86_64_link_hash_table
*ret
;
882 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
884 ret
= (struct elf_x86_64_link_hash_table
*) bfd_malloc (amt
);
888 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
889 elf_x86_64_link_hash_newfunc
,
890 sizeof (struct elf_x86_64_link_hash_entry
),
899 ret
->plt_eh_frame
= NULL
;
900 ret
->sym_cache
.abfd
= NULL
;
901 ret
->tlsdesc_plt
= 0;
902 ret
->tlsdesc_got
= 0;
903 ret
->tls_ld_got
.refcount
= 0;
904 ret
->sgotplt_jump_table_size
= 0;
905 ret
->tls_module_base
= NULL
;
906 ret
->next_jump_slot_index
= 0;
907 ret
->next_irelative_index
= 0;
911 ret
->r_info
= elf64_r_info
;
912 ret
->r_sym
= elf64_r_sym
;
913 ret
->pointer_r_type
= R_X86_64_64
;
914 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
915 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
919 ret
->r_info
= elf32_r_info
;
920 ret
->r_sym
= elf32_r_sym
;
921 ret
->pointer_r_type
= R_X86_64_32
;
922 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
923 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
926 ret
->loc_hash_table
= htab_try_create (1024,
927 elf_x86_64_local_htab_hash
,
928 elf_x86_64_local_htab_eq
,
930 ret
->loc_hash_memory
= objalloc_create ();
931 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
937 return &ret
->elf
.root
;
940 /* Destroy an X86-64 ELF linker hash table. */
943 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
945 struct elf_x86_64_link_hash_table
*htab
946 = (struct elf_x86_64_link_hash_table
*) hash
;
948 if (htab
->loc_hash_table
)
949 htab_delete (htab
->loc_hash_table
);
950 if (htab
->loc_hash_memory
)
951 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
952 _bfd_generic_link_hash_table_free (hash
);
955 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
956 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
960 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
961 struct bfd_link_info
*info
)
963 struct elf_x86_64_link_hash_table
*htab
;
965 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
968 htab
= elf_x86_64_hash_table (info
);
972 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
974 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
977 || (!info
->shared
&& !htab
->srelbss
))
980 if (!info
->no_ld_generated_unwind_info
981 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
982 && htab
->elf
.splt
!= NULL
)
984 const struct elf_x86_64_backend_data
*const abed
985 = get_elf_x86_64_backend_data (dynobj
);
986 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
988 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
989 flags
| SEC_READONLY
);
990 if (htab
->plt_eh_frame
== NULL
991 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
994 htab
->plt_eh_frame
->size
= abed
->eh_frame_plt_size
;
995 htab
->plt_eh_frame
->contents
996 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
997 memcpy (htab
->plt_eh_frame
->contents
,
998 abed
->eh_frame_plt
, abed
->eh_frame_plt_size
);
1003 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1006 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1007 struct elf_link_hash_entry
*dir
,
1008 struct elf_link_hash_entry
*ind
)
1010 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1012 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1013 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1015 if (eind
->dyn_relocs
!= NULL
)
1017 if (edir
->dyn_relocs
!= NULL
)
1019 struct elf_dyn_relocs
**pp
;
1020 struct elf_dyn_relocs
*p
;
1022 /* Add reloc counts against the indirect sym to the direct sym
1023 list. Merge any entries against the same section. */
1024 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1026 struct elf_dyn_relocs
*q
;
1028 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1029 if (q
->sec
== p
->sec
)
1031 q
->pc_count
+= p
->pc_count
;
1032 q
->count
+= p
->count
;
1039 *pp
= edir
->dyn_relocs
;
1042 edir
->dyn_relocs
= eind
->dyn_relocs
;
1043 eind
->dyn_relocs
= NULL
;
1046 if (ind
->root
.type
== bfd_link_hash_indirect
1047 && dir
->got
.refcount
<= 0)
1049 edir
->tls_type
= eind
->tls_type
;
1050 eind
->tls_type
= GOT_UNKNOWN
;
1053 if (ELIMINATE_COPY_RELOCS
1054 && ind
->root
.type
!= bfd_link_hash_indirect
1055 && dir
->dynamic_adjusted
)
1057 /* If called to transfer flags for a weakdef during processing
1058 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1059 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1060 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1061 dir
->ref_regular
|= ind
->ref_regular
;
1062 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1063 dir
->needs_plt
|= ind
->needs_plt
;
1064 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1067 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1071 elf64_x86_64_elf_object_p (bfd
*abfd
)
1073 /* Set the right machine number for an x86-64 elf64 file. */
1074 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1078 /* Return TRUE if the TLS access code sequence support transition
1082 elf_x86_64_check_tls_transition (bfd
*abfd
,
1083 struct bfd_link_info
*info
,
1086 Elf_Internal_Shdr
*symtab_hdr
,
1087 struct elf_link_hash_entry
**sym_hashes
,
1088 unsigned int r_type
,
1089 const Elf_Internal_Rela
*rel
,
1090 const Elf_Internal_Rela
*relend
)
1093 unsigned long r_symndx
;
1094 struct elf_link_hash_entry
*h
;
1096 struct elf_x86_64_link_hash_table
*htab
;
1098 /* Get the section contents. */
1099 if (contents
== NULL
)
1101 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1102 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1105 /* FIXME: How to better handle error condition? */
1106 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1109 /* Cache the section contents for elf_link_input_bfd. */
1110 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1114 htab
= elf_x86_64_hash_table (info
);
1115 offset
= rel
->r_offset
;
1118 case R_X86_64_TLSGD
:
1119 case R_X86_64_TLSLD
:
1120 if ((rel
+ 1) >= relend
)
1123 if (r_type
== R_X86_64_TLSGD
)
1125 /* Check transition from GD access model. For 64bit, only
1126 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1127 .word 0x6666; rex64; call __tls_get_addr
1128 can transit to different access model. For 32bit, only
1129 leaq foo@tlsgd(%rip), %rdi
1130 .word 0x6666; rex64; call __tls_get_addr
1131 can transit to different access model. */
1133 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1134 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1136 if ((offset
+ 12) > sec
->size
1137 || memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1140 if (ABI_64_P (abfd
))
1143 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1149 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1155 /* Check transition from LD access model. Only
1156 leaq foo@tlsld(%rip), %rdi;
1158 can transit to different access model. */
1160 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1162 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1165 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0
1166 || 0xe8 != *(contents
+ offset
+ 4))
1170 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1171 if (r_symndx
< symtab_hdr
->sh_info
)
1174 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1175 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1176 may be versioned. */
1178 && h
->root
.root
.string
!= NULL
1179 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1180 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
1181 && (strncmp (h
->root
.root
.string
,
1182 "__tls_get_addr", 14) == 0));
1184 case R_X86_64_GOTTPOFF
:
1185 /* Check transition from IE access model:
1186 mov foo@gottpoff(%rip), %reg
1187 add foo@gottpoff(%rip), %reg
1190 /* Check REX prefix first. */
1191 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1193 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1194 if (val
!= 0x48 && val
!= 0x4c)
1196 /* X32 may have 0x44 REX prefix or no REX prefix. */
1197 if (ABI_64_P (abfd
))
1203 /* X32 may not have any REX prefix. */
1204 if (ABI_64_P (abfd
))
1206 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1210 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1211 if (val
!= 0x8b && val
!= 0x03)
1214 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1215 return (val
& 0xc7) == 5;
1217 case R_X86_64_GOTPC32_TLSDESC
:
1218 /* Check transition from GDesc access model:
1219 leaq x@tlsdesc(%rip), %rax
1221 Make sure it's a leaq adding rip to a 32-bit offset
1222 into any register, although it's probably almost always
1225 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1228 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1229 if ((val
& 0xfb) != 0x48)
1232 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1235 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1236 return (val
& 0xc7) == 0x05;
1238 case R_X86_64_TLSDESC_CALL
:
1239 /* Check transition from GDesc access model:
1240 call *x@tlsdesc(%rax)
1242 if (offset
+ 2 <= sec
->size
)
1244 /* Make sure that it's a call *x@tlsdesc(%rax). */
1245 static const unsigned char call
[] = { 0xff, 0x10 };
1246 return memcmp (contents
+ offset
, call
, 2) == 0;
1256 /* Return TRUE if the TLS access transition is OK or no transition
1257 will be performed. Update R_TYPE if there is a transition. */
1260 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1261 asection
*sec
, bfd_byte
*contents
,
1262 Elf_Internal_Shdr
*symtab_hdr
,
1263 struct elf_link_hash_entry
**sym_hashes
,
1264 unsigned int *r_type
, int tls_type
,
1265 const Elf_Internal_Rela
*rel
,
1266 const Elf_Internal_Rela
*relend
,
1267 struct elf_link_hash_entry
*h
,
1268 unsigned long r_symndx
)
1270 unsigned int from_type
= *r_type
;
1271 unsigned int to_type
= from_type
;
1272 bfd_boolean check
= TRUE
;
1274 /* Skip TLS transition for functions. */
1276 && (h
->type
== STT_FUNC
1277 || h
->type
== STT_GNU_IFUNC
))
1282 case R_X86_64_TLSGD
:
1283 case R_X86_64_GOTPC32_TLSDESC
:
1284 case R_X86_64_TLSDESC_CALL
:
1285 case R_X86_64_GOTTPOFF
:
1286 if (info
->executable
)
1289 to_type
= R_X86_64_TPOFF32
;
1291 to_type
= R_X86_64_GOTTPOFF
;
1294 /* When we are called from elf_x86_64_relocate_section,
1295 CONTENTS isn't NULL and there may be additional transitions
1296 based on TLS_TYPE. */
1297 if (contents
!= NULL
)
1299 unsigned int new_to_type
= to_type
;
1301 if (info
->executable
1304 && tls_type
== GOT_TLS_IE
)
1305 new_to_type
= R_X86_64_TPOFF32
;
1307 if (to_type
== R_X86_64_TLSGD
1308 || to_type
== R_X86_64_GOTPC32_TLSDESC
1309 || to_type
== R_X86_64_TLSDESC_CALL
)
1311 if (tls_type
== GOT_TLS_IE
)
1312 new_to_type
= R_X86_64_GOTTPOFF
;
1315 /* We checked the transition before when we were called from
1316 elf_x86_64_check_relocs. We only want to check the new
1317 transition which hasn't been checked before. */
1318 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1319 to_type
= new_to_type
;
1324 case R_X86_64_TLSLD
:
1325 if (info
->executable
)
1326 to_type
= R_X86_64_TPOFF32
;
1333 /* Return TRUE if there is no transition. */
1334 if (from_type
== to_type
)
1337 /* Check if the transition can be performed. */
1339 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1340 symtab_hdr
, sym_hashes
,
1341 from_type
, rel
, relend
))
1343 reloc_howto_type
*from
, *to
;
1346 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1347 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1350 name
= h
->root
.root
.string
;
1353 struct elf_x86_64_link_hash_table
*htab
;
1355 htab
= elf_x86_64_hash_table (info
);
1360 Elf_Internal_Sym
*isym
;
1362 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1364 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1368 (*_bfd_error_handler
)
1369 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1370 "in section `%A' failed"),
1371 abfd
, sec
, from
->name
, to
->name
, name
,
1372 (unsigned long) rel
->r_offset
);
1373 bfd_set_error (bfd_error_bad_value
);
1381 /* Look through the relocs for a section during the first phase, and
1382 calculate needed space in the global offset table, procedure
1383 linkage table, and dynamic reloc sections. */
1386 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1388 const Elf_Internal_Rela
*relocs
)
1390 struct elf_x86_64_link_hash_table
*htab
;
1391 Elf_Internal_Shdr
*symtab_hdr
;
1392 struct elf_link_hash_entry
**sym_hashes
;
1393 const Elf_Internal_Rela
*rel
;
1394 const Elf_Internal_Rela
*rel_end
;
1397 if (info
->relocatable
)
1400 BFD_ASSERT (is_x86_64_elf (abfd
));
1402 htab
= elf_x86_64_hash_table (info
);
1406 symtab_hdr
= &elf_symtab_hdr (abfd
);
1407 sym_hashes
= elf_sym_hashes (abfd
);
1411 rel_end
= relocs
+ sec
->reloc_count
;
1412 for (rel
= relocs
; rel
< rel_end
; rel
++)
1414 unsigned int r_type
;
1415 unsigned long r_symndx
;
1416 struct elf_link_hash_entry
*h
;
1417 Elf_Internal_Sym
*isym
;
1420 r_symndx
= htab
->r_sym (rel
->r_info
);
1421 r_type
= ELF32_R_TYPE (rel
->r_info
);
1423 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1425 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1430 if (r_symndx
< symtab_hdr
->sh_info
)
1432 /* A local symbol. */
1433 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1438 /* Check relocation against local STT_GNU_IFUNC symbol. */
1439 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1441 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1446 /* Fake a STT_GNU_IFUNC symbol. */
1447 h
->type
= STT_GNU_IFUNC
;
1450 h
->forced_local
= 1;
1451 h
->root
.type
= bfd_link_hash_defined
;
1459 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1460 while (h
->root
.type
== bfd_link_hash_indirect
1461 || h
->root
.type
== bfd_link_hash_warning
)
1462 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1465 /* Check invalid x32 relocations. */
1466 if (!ABI_64_P (abfd
))
1472 case R_X86_64_DTPOFF64
:
1473 case R_X86_64_TPOFF64
:
1475 case R_X86_64_GOTOFF64
:
1476 case R_X86_64_GOT64
:
1477 case R_X86_64_GOTPCREL64
:
1478 case R_X86_64_GOTPC64
:
1479 case R_X86_64_GOTPLT64
:
1480 case R_X86_64_PLTOFF64
:
1483 name
= h
->root
.root
.string
;
1485 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1487 (*_bfd_error_handler
)
1488 (_("%B: relocation %s against symbol `%s' isn't "
1489 "supported in x32 mode"), abfd
,
1490 x86_64_elf_howto_table
[r_type
].name
, name
);
1491 bfd_set_error (bfd_error_bad_value
);
1499 /* Create the ifunc sections for static executables. If we
1500 never see an indirect function symbol nor we are building
1501 a static executable, those sections will be empty and
1502 won't appear in output. */
1513 case R_X86_64_PLT32
:
1514 case R_X86_64_GOTPCREL
:
1515 case R_X86_64_GOTPCREL64
:
1516 if (htab
->elf
.dynobj
== NULL
)
1517 htab
->elf
.dynobj
= abfd
;
1518 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1523 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1524 it here if it is defined in a non-shared object. */
1525 if (h
->type
== STT_GNU_IFUNC
1528 /* It is referenced by a non-shared object. */
1532 /* STT_GNU_IFUNC symbol must go through PLT. */
1533 h
->plt
.refcount
+= 1;
1535 /* STT_GNU_IFUNC needs dynamic sections. */
1536 if (htab
->elf
.dynobj
== NULL
)
1537 htab
->elf
.dynobj
= abfd
;
1542 if (h
->root
.root
.string
)
1543 name
= h
->root
.root
.string
;
1545 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1547 (*_bfd_error_handler
)
1548 (_("%B: relocation %s against STT_GNU_IFUNC "
1549 "symbol `%s' isn't handled by %s"), abfd
,
1550 x86_64_elf_howto_table
[r_type
].name
,
1551 name
, __FUNCTION__
);
1552 bfd_set_error (bfd_error_bad_value
);
1556 if (ABI_64_P (abfd
))
1560 h
->pointer_equality_needed
= 1;
1563 /* We must copy these reloc types into the output
1564 file. Create a reloc section in dynobj and
1565 make room for this reloc. */
1566 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1567 (abfd
, info
, sec
, sreloc
,
1568 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1579 if (r_type
!= R_X86_64_PC32
1580 && r_type
!= R_X86_64_PC64
)
1581 h
->pointer_equality_needed
= 1;
1584 case R_X86_64_PLT32
:
1587 case R_X86_64_GOTPCREL
:
1588 case R_X86_64_GOTPCREL64
:
1589 h
->got
.refcount
+= 1;
1590 if (htab
->elf
.sgot
== NULL
1591 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1601 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1602 symtab_hdr
, sym_hashes
,
1603 &r_type
, GOT_UNKNOWN
,
1604 rel
, rel_end
, h
, r_symndx
))
1609 case R_X86_64_TLSLD
:
1610 htab
->tls_ld_got
.refcount
+= 1;
1613 case R_X86_64_TPOFF32
:
1614 if (!info
->executable
&& ABI_64_P (abfd
))
1617 name
= h
->root
.root
.string
;
1619 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1621 (*_bfd_error_handler
)
1622 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1624 x86_64_elf_howto_table
[r_type
].name
, name
);
1625 bfd_set_error (bfd_error_bad_value
);
1630 case R_X86_64_GOTTPOFF
:
1631 if (!info
->executable
)
1632 info
->flags
|= DF_STATIC_TLS
;
1635 case R_X86_64_GOT32
:
1636 case R_X86_64_GOTPCREL
:
1637 case R_X86_64_TLSGD
:
1638 case R_X86_64_GOT64
:
1639 case R_X86_64_GOTPCREL64
:
1640 case R_X86_64_GOTPLT64
:
1641 case R_X86_64_GOTPC32_TLSDESC
:
1642 case R_X86_64_TLSDESC_CALL
:
1643 /* This symbol requires a global offset table entry. */
1645 int tls_type
, old_tls_type
;
1649 default: tls_type
= GOT_NORMAL
; break;
1650 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1651 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1652 case R_X86_64_GOTPC32_TLSDESC
:
1653 case R_X86_64_TLSDESC_CALL
:
1654 tls_type
= GOT_TLS_GDESC
; break;
1659 if (r_type
== R_X86_64_GOTPLT64
)
1661 /* This relocation indicates that we also need
1662 a PLT entry, as this is a function. We don't need
1663 a PLT entry for local symbols. */
1665 h
->plt
.refcount
+= 1;
1667 h
->got
.refcount
+= 1;
1668 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1672 bfd_signed_vma
*local_got_refcounts
;
1674 /* This is a global offset table entry for a local symbol. */
1675 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1676 if (local_got_refcounts
== NULL
)
1680 size
= symtab_hdr
->sh_info
;
1681 size
*= sizeof (bfd_signed_vma
)
1682 + sizeof (bfd_vma
) + sizeof (char);
1683 local_got_refcounts
= ((bfd_signed_vma
*)
1684 bfd_zalloc (abfd
, size
));
1685 if (local_got_refcounts
== NULL
)
1687 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1688 elf_x86_64_local_tlsdesc_gotent (abfd
)
1689 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1690 elf_x86_64_local_got_tls_type (abfd
)
1691 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1693 local_got_refcounts
[r_symndx
] += 1;
1695 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1698 /* If a TLS symbol is accessed using IE at least once,
1699 there is no point to use dynamic model for it. */
1700 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1701 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1702 || tls_type
!= GOT_TLS_IE
))
1704 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1705 tls_type
= old_tls_type
;
1706 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1707 && GOT_TLS_GD_ANY_P (tls_type
))
1708 tls_type
|= old_tls_type
;
1712 name
= h
->root
.root
.string
;
1714 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1716 (*_bfd_error_handler
)
1717 (_("%B: '%s' accessed both as normal and thread local symbol"),
1723 if (old_tls_type
!= tls_type
)
1726 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1728 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1733 case R_X86_64_GOTOFF64
:
1734 case R_X86_64_GOTPC32
:
1735 case R_X86_64_GOTPC64
:
1737 if (htab
->elf
.sgot
== NULL
)
1739 if (htab
->elf
.dynobj
== NULL
)
1740 htab
->elf
.dynobj
= abfd
;
1741 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1747 case R_X86_64_PLT32
:
1748 /* This symbol requires a procedure linkage table entry. We
1749 actually build the entry in adjust_dynamic_symbol,
1750 because this might be a case of linking PIC code which is
1751 never referenced by a dynamic object, in which case we
1752 don't need to generate a procedure linkage table entry
1755 /* If this is a local symbol, we resolve it directly without
1756 creating a procedure linkage table entry. */
1761 h
->plt
.refcount
+= 1;
1764 case R_X86_64_PLTOFF64
:
1765 /* This tries to form the 'address' of a function relative
1766 to GOT. For global symbols we need a PLT entry. */
1770 h
->plt
.refcount
+= 1;
1775 if (!ABI_64_P (abfd
))
1780 /* Let's help debug shared library creation. These relocs
1781 cannot be used in shared libs. Don't error out for
1782 sections we don't care about, such as debug sections or
1783 non-constant sections. */
1785 && (sec
->flags
& SEC_ALLOC
) != 0
1786 && (sec
->flags
& SEC_READONLY
) != 0)
1789 name
= h
->root
.root
.string
;
1791 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1792 (*_bfd_error_handler
)
1793 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1794 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1795 bfd_set_error (bfd_error_bad_value
);
1806 if (h
!= NULL
&& info
->executable
)
1808 /* If this reloc is in a read-only section, we might
1809 need a copy reloc. We can't check reliably at this
1810 stage whether the section is read-only, as input
1811 sections have not yet been mapped to output sections.
1812 Tentatively set the flag for now, and correct in
1813 adjust_dynamic_symbol. */
1816 /* We may need a .plt entry if the function this reloc
1817 refers to is in a shared lib. */
1818 h
->plt
.refcount
+= 1;
1819 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1820 h
->pointer_equality_needed
= 1;
1823 /* If we are creating a shared library, and this is a reloc
1824 against a global symbol, or a non PC relative reloc
1825 against a local symbol, then we need to copy the reloc
1826 into the shared library. However, if we are linking with
1827 -Bsymbolic, we do not need to copy a reloc against a
1828 global symbol which is defined in an object we are
1829 including in the link (i.e., DEF_REGULAR is set). At
1830 this point we have not seen all the input files, so it is
1831 possible that DEF_REGULAR is not set now but will be set
1832 later (it is never cleared). In case of a weak definition,
1833 DEF_REGULAR may be cleared later by a strong definition in
1834 a shared library. We account for that possibility below by
1835 storing information in the relocs_copied field of the hash
1836 table entry. A similar situation occurs when creating
1837 shared libraries and symbol visibility changes render the
1840 If on the other hand, we are creating an executable, we
1841 may need to keep relocations for symbols satisfied by a
1842 dynamic library if we manage to avoid copy relocs for the
1845 && (sec
->flags
& SEC_ALLOC
) != 0
1846 && (! IS_X86_64_PCREL_TYPE (r_type
)
1848 && (! SYMBOLIC_BIND (info
, h
)
1849 || h
->root
.type
== bfd_link_hash_defweak
1850 || !h
->def_regular
))))
1851 || (ELIMINATE_COPY_RELOCS
1853 && (sec
->flags
& SEC_ALLOC
) != 0
1855 && (h
->root
.type
== bfd_link_hash_defweak
1856 || !h
->def_regular
)))
1858 struct elf_dyn_relocs
*p
;
1859 struct elf_dyn_relocs
**head
;
1861 /* We must copy these reloc types into the output file.
1862 Create a reloc section in dynobj and make room for
1866 if (htab
->elf
.dynobj
== NULL
)
1867 htab
->elf
.dynobj
= abfd
;
1869 sreloc
= _bfd_elf_make_dynamic_reloc_section
1870 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1871 abfd
, /*rela?*/ TRUE
);
1877 /* If this is a global symbol, we count the number of
1878 relocations we need for this symbol. */
1881 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1885 /* Track dynamic relocs needed for local syms too.
1886 We really need local syms available to do this
1891 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1896 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1900 /* Beware of type punned pointers vs strict aliasing
1902 vpp
= &(elf_section_data (s
)->local_dynrel
);
1903 head
= (struct elf_dyn_relocs
**)vpp
;
1907 if (p
== NULL
|| p
->sec
!= sec
)
1909 bfd_size_type amt
= sizeof *p
;
1911 p
= ((struct elf_dyn_relocs
*)
1912 bfd_alloc (htab
->elf
.dynobj
, amt
));
1923 if (IS_X86_64_PCREL_TYPE (r_type
))
1928 /* This relocation describes the C++ object vtable hierarchy.
1929 Reconstruct it for later use during GC. */
1930 case R_X86_64_GNU_VTINHERIT
:
1931 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1935 /* This relocation describes which C++ vtable entries are actually
1936 used. Record for later use during GC. */
1937 case R_X86_64_GNU_VTENTRY
:
1938 BFD_ASSERT (h
!= NULL
);
1940 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1952 /* Return the section that should be marked against GC for a given
1956 elf_x86_64_gc_mark_hook (asection
*sec
,
1957 struct bfd_link_info
*info
,
1958 Elf_Internal_Rela
*rel
,
1959 struct elf_link_hash_entry
*h
,
1960 Elf_Internal_Sym
*sym
)
1963 switch (ELF32_R_TYPE (rel
->r_info
))
1965 case R_X86_64_GNU_VTINHERIT
:
1966 case R_X86_64_GNU_VTENTRY
:
1970 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1973 /* Update the got entry reference counts for the section being removed. */
1976 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1978 const Elf_Internal_Rela
*relocs
)
1980 struct elf_x86_64_link_hash_table
*htab
;
1981 Elf_Internal_Shdr
*symtab_hdr
;
1982 struct elf_link_hash_entry
**sym_hashes
;
1983 bfd_signed_vma
*local_got_refcounts
;
1984 const Elf_Internal_Rela
*rel
, *relend
;
1986 if (info
->relocatable
)
1989 htab
= elf_x86_64_hash_table (info
);
1993 elf_section_data (sec
)->local_dynrel
= NULL
;
1995 symtab_hdr
= &elf_symtab_hdr (abfd
);
1996 sym_hashes
= elf_sym_hashes (abfd
);
1997 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1999 htab
= elf_x86_64_hash_table (info
);
2000 relend
= relocs
+ sec
->reloc_count
;
2001 for (rel
= relocs
; rel
< relend
; rel
++)
2003 unsigned long r_symndx
;
2004 unsigned int r_type
;
2005 struct elf_link_hash_entry
*h
= NULL
;
2007 r_symndx
= htab
->r_sym (rel
->r_info
);
2008 if (r_symndx
>= symtab_hdr
->sh_info
)
2010 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2011 while (h
->root
.type
== bfd_link_hash_indirect
2012 || h
->root
.type
== bfd_link_hash_warning
)
2013 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2017 /* A local symbol. */
2018 Elf_Internal_Sym
*isym
;
2020 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2023 /* Check relocation against local STT_GNU_IFUNC symbol. */
2025 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2027 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2035 struct elf_x86_64_link_hash_entry
*eh
;
2036 struct elf_dyn_relocs
**pp
;
2037 struct elf_dyn_relocs
*p
;
2039 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2041 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2044 /* Everything must go for SEC. */
2050 r_type
= ELF32_R_TYPE (rel
->r_info
);
2051 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
2052 symtab_hdr
, sym_hashes
,
2053 &r_type
, GOT_UNKNOWN
,
2054 rel
, relend
, h
, r_symndx
))
2059 case R_X86_64_TLSLD
:
2060 if (htab
->tls_ld_got
.refcount
> 0)
2061 htab
->tls_ld_got
.refcount
-= 1;
2064 case R_X86_64_TLSGD
:
2065 case R_X86_64_GOTPC32_TLSDESC
:
2066 case R_X86_64_TLSDESC_CALL
:
2067 case R_X86_64_GOTTPOFF
:
2068 case R_X86_64_GOT32
:
2069 case R_X86_64_GOTPCREL
:
2070 case R_X86_64_GOT64
:
2071 case R_X86_64_GOTPCREL64
:
2072 case R_X86_64_GOTPLT64
:
2075 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2076 h
->plt
.refcount
-= 1;
2077 if (h
->got
.refcount
> 0)
2078 h
->got
.refcount
-= 1;
2079 if (h
->type
== STT_GNU_IFUNC
)
2081 if (h
->plt
.refcount
> 0)
2082 h
->plt
.refcount
-= 1;
2085 else if (local_got_refcounts
!= NULL
)
2087 if (local_got_refcounts
[r_symndx
] > 0)
2088 local_got_refcounts
[r_symndx
] -= 1;
2102 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2106 case R_X86_64_PLT32
:
2107 case R_X86_64_PLTOFF64
:
2110 if (h
->plt
.refcount
> 0)
2111 h
->plt
.refcount
-= 1;
2123 /* Adjust a symbol defined by a dynamic object and referenced by a
2124 regular object. The current definition is in some section of the
2125 dynamic object, but we're not including those sections. We have to
2126 change the definition to something the rest of the link can
2130 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2131 struct elf_link_hash_entry
*h
)
2133 struct elf_x86_64_link_hash_table
*htab
;
2136 /* STT_GNU_IFUNC symbol must go through PLT. */
2137 if (h
->type
== STT_GNU_IFUNC
)
2139 if (h
->plt
.refcount
<= 0)
2141 h
->plt
.offset
= (bfd_vma
) -1;
2147 /* If this is a function, put it in the procedure linkage table. We
2148 will fill in the contents of the procedure linkage table later,
2149 when we know the address of the .got section. */
2150 if (h
->type
== STT_FUNC
2153 if (h
->plt
.refcount
<= 0
2154 || SYMBOL_CALLS_LOCAL (info
, h
)
2155 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2156 && h
->root
.type
== bfd_link_hash_undefweak
))
2158 /* This case can occur if we saw a PLT32 reloc in an input
2159 file, but the symbol was never referred to by a dynamic
2160 object, or if all references were garbage collected. In
2161 such a case, we don't actually need to build a procedure
2162 linkage table, and we can just do a PC32 reloc instead. */
2163 h
->plt
.offset
= (bfd_vma
) -1;
2170 /* It's possible that we incorrectly decided a .plt reloc was
2171 needed for an R_X86_64_PC32 reloc to a non-function sym in
2172 check_relocs. We can't decide accurately between function and
2173 non-function syms in check-relocs; Objects loaded later in
2174 the link may change h->type. So fix it now. */
2175 h
->plt
.offset
= (bfd_vma
) -1;
2177 /* If this is a weak symbol, and there is a real definition, the
2178 processor independent code will have arranged for us to see the
2179 real definition first, and we can just use the same value. */
2180 if (h
->u
.weakdef
!= NULL
)
2182 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2183 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2184 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2185 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2186 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2187 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2191 /* This is a reference to a symbol defined by a dynamic object which
2192 is not a function. */
2194 /* If we are creating a shared library, we must presume that the
2195 only references to the symbol are via the global offset table.
2196 For such cases we need not do anything here; the relocations will
2197 be handled correctly by relocate_section. */
2201 /* If there are no references to this symbol that do not use the
2202 GOT, we don't need to generate a copy reloc. */
2203 if (!h
->non_got_ref
)
2206 /* If -z nocopyreloc was given, we won't generate them either. */
2207 if (info
->nocopyreloc
)
2213 if (ELIMINATE_COPY_RELOCS
)
2215 struct elf_x86_64_link_hash_entry
* eh
;
2216 struct elf_dyn_relocs
*p
;
2218 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2219 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2221 s
= p
->sec
->output_section
;
2222 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2226 /* If we didn't find any dynamic relocs in read-only sections, then
2227 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2235 /* We must allocate the symbol in our .dynbss section, which will
2236 become part of the .bss section of the executable. There will be
2237 an entry for this symbol in the .dynsym section. The dynamic
2238 object will contain position independent code, so all references
2239 from the dynamic object to this symbol will go through the global
2240 offset table. The dynamic linker will use the .dynsym entry to
2241 determine the address it must put in the global offset table, so
2242 both the dynamic object and the regular object will refer to the
2243 same memory location for the variable. */
2245 htab
= elf_x86_64_hash_table (info
);
2249 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2250 to copy the initial value out of the dynamic object and into the
2251 runtime process image. */
2252 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2254 const struct elf_backend_data
*bed
;
2255 bed
= get_elf_backend_data (info
->output_bfd
);
2256 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2262 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2265 /* Allocate space in .plt, .got and associated reloc sections for
2269 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2271 struct bfd_link_info
*info
;
2272 struct elf_x86_64_link_hash_table
*htab
;
2273 struct elf_x86_64_link_hash_entry
*eh
;
2274 struct elf_dyn_relocs
*p
;
2275 const struct elf_backend_data
*bed
;
2276 unsigned int plt_entry_size
;
2278 if (h
->root
.type
== bfd_link_hash_indirect
)
2281 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2283 info
= (struct bfd_link_info
*) inf
;
2284 htab
= elf_x86_64_hash_table (info
);
2287 bed
= get_elf_backend_data (info
->output_bfd
);
2288 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2290 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2291 here if it is defined and referenced in a non-shared object. */
2292 if (h
->type
== STT_GNU_IFUNC
2294 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2298 else if (htab
->elf
.dynamic_sections_created
2299 && h
->plt
.refcount
> 0)
2301 /* Make sure this symbol is output as a dynamic symbol.
2302 Undefined weak syms won't yet be marked as dynamic. */
2303 if (h
->dynindx
== -1
2304 && !h
->forced_local
)
2306 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2311 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2313 asection
*s
= htab
->elf
.splt
;
2315 /* If this is the first .plt entry, make room for the special
2318 s
->size
+= plt_entry_size
;
2320 h
->plt
.offset
= s
->size
;
2322 /* If this symbol is not defined in a regular file, and we are
2323 not generating a shared library, then set the symbol to this
2324 location in the .plt. This is required to make function
2325 pointers compare as equal between the normal executable and
2326 the shared library. */
2330 h
->root
.u
.def
.section
= s
;
2331 h
->root
.u
.def
.value
= h
->plt
.offset
;
2334 /* Make room for this entry. */
2335 s
->size
+= plt_entry_size
;
2337 /* We also need to make an entry in the .got.plt section, which
2338 will be placed in the .got section by the linker script. */
2339 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2341 /* We also need to make an entry in the .rela.plt section. */
2342 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2343 htab
->elf
.srelplt
->reloc_count
++;
2347 h
->plt
.offset
= (bfd_vma
) -1;
2353 h
->plt
.offset
= (bfd_vma
) -1;
2357 eh
->tlsdesc_got
= (bfd_vma
) -1;
2359 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2360 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2361 if (h
->got
.refcount
> 0
2364 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2366 h
->got
.offset
= (bfd_vma
) -1;
2368 else if (h
->got
.refcount
> 0)
2372 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2374 /* Make sure this symbol is output as a dynamic symbol.
2375 Undefined weak syms won't yet be marked as dynamic. */
2376 if (h
->dynindx
== -1
2377 && !h
->forced_local
)
2379 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2383 if (GOT_TLS_GDESC_P (tls_type
))
2385 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2386 - elf_x86_64_compute_jump_table_size (htab
);
2387 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2388 h
->got
.offset
= (bfd_vma
) -2;
2390 if (! GOT_TLS_GDESC_P (tls_type
)
2391 || GOT_TLS_GD_P (tls_type
))
2394 h
->got
.offset
= s
->size
;
2395 s
->size
+= GOT_ENTRY_SIZE
;
2396 if (GOT_TLS_GD_P (tls_type
))
2397 s
->size
+= GOT_ENTRY_SIZE
;
2399 dyn
= htab
->elf
.dynamic_sections_created
;
2400 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2402 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2403 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2404 || tls_type
== GOT_TLS_IE
)
2405 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2406 else if (GOT_TLS_GD_P (tls_type
))
2407 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2408 else if (! GOT_TLS_GDESC_P (tls_type
)
2409 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2410 || h
->root
.type
!= bfd_link_hash_undefweak
)
2412 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2413 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2414 if (GOT_TLS_GDESC_P (tls_type
))
2416 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2417 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2421 h
->got
.offset
= (bfd_vma
) -1;
2423 if (eh
->dyn_relocs
== NULL
)
2426 /* In the shared -Bsymbolic case, discard space allocated for
2427 dynamic pc-relative relocs against symbols which turn out to be
2428 defined in regular objects. For the normal shared case, discard
2429 space for pc-relative relocs that have become local due to symbol
2430 visibility changes. */
2434 /* Relocs that use pc_count are those that appear on a call
2435 insn, or certain REL relocs that can generated via assembly.
2436 We want calls to protected symbols to resolve directly to the
2437 function rather than going via the plt. If people want
2438 function pointer comparisons to work as expected then they
2439 should avoid writing weird assembly. */
2440 if (SYMBOL_CALLS_LOCAL (info
, h
))
2442 struct elf_dyn_relocs
**pp
;
2444 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2446 p
->count
-= p
->pc_count
;
2455 /* Also discard relocs on undefined weak syms with non-default
2457 if (eh
->dyn_relocs
!= NULL
2458 && h
->root
.type
== bfd_link_hash_undefweak
)
2460 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2461 eh
->dyn_relocs
= NULL
;
2463 /* Make sure undefined weak symbols are output as a dynamic
2465 else if (h
->dynindx
== -1
2466 && ! h
->forced_local
2467 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2472 else if (ELIMINATE_COPY_RELOCS
)
2474 /* For the non-shared case, discard space for relocs against
2475 symbols which turn out to need copy relocs or are not
2481 || (htab
->elf
.dynamic_sections_created
2482 && (h
->root
.type
== bfd_link_hash_undefweak
2483 || h
->root
.type
== bfd_link_hash_undefined
))))
2485 /* Make sure this symbol is output as a dynamic symbol.
2486 Undefined weak syms won't yet be marked as dynamic. */
2487 if (h
->dynindx
== -1
2488 && ! h
->forced_local
2489 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2492 /* If that succeeded, we know we'll be keeping all the
2494 if (h
->dynindx
!= -1)
2498 eh
->dyn_relocs
= NULL
;
2503 /* Finally, allocate space. */
2504 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2508 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2510 BFD_ASSERT (sreloc
!= NULL
);
2512 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2518 /* Allocate space in .plt, .got and associated reloc sections for
2519 local dynamic relocs. */
2522 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2524 struct elf_link_hash_entry
*h
2525 = (struct elf_link_hash_entry
*) *slot
;
2527 if (h
->type
!= STT_GNU_IFUNC
2531 || h
->root
.type
!= bfd_link_hash_defined
)
2534 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2537 /* Find any dynamic relocs that apply to read-only sections. */
2540 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2543 struct elf_x86_64_link_hash_entry
*eh
;
2544 struct elf_dyn_relocs
*p
;
2546 /* Skip local IFUNC symbols. */
2547 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2550 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2551 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2553 asection
*s
= p
->sec
->output_section
;
2555 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2557 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2559 info
->flags
|= DF_TEXTREL
;
2561 if (info
->warn_shared_textrel
&& info
->shared
)
2562 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2563 p
->sec
->owner
, h
->root
.root
.string
,
2566 /* Not an error, just cut short the traversal. */
2573 /* Set the sizes of the dynamic sections. */
2576 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2577 struct bfd_link_info
*info
)
2579 struct elf_x86_64_link_hash_table
*htab
;
2584 const struct elf_backend_data
*bed
;
2586 htab
= elf_x86_64_hash_table (info
);
2589 bed
= get_elf_backend_data (output_bfd
);
2591 dynobj
= htab
->elf
.dynobj
;
2595 if (htab
->elf
.dynamic_sections_created
)
2597 /* Set the contents of the .interp section to the interpreter. */
2598 if (info
->executable
)
2600 s
= bfd_get_section_by_name (dynobj
, ".interp");
2603 s
->size
= htab
->dynamic_interpreter_size
;
2604 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2608 /* Set up .got offsets for local syms, and space for local dynamic
2610 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2612 bfd_signed_vma
*local_got
;
2613 bfd_signed_vma
*end_local_got
;
2614 char *local_tls_type
;
2615 bfd_vma
*local_tlsdesc_gotent
;
2616 bfd_size_type locsymcount
;
2617 Elf_Internal_Shdr
*symtab_hdr
;
2620 if (! is_x86_64_elf (ibfd
))
2623 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2625 struct elf_dyn_relocs
*p
;
2627 for (p
= (struct elf_dyn_relocs
*)
2628 (elf_section_data (s
)->local_dynrel
);
2632 if (!bfd_is_abs_section (p
->sec
)
2633 && bfd_is_abs_section (p
->sec
->output_section
))
2635 /* Input section has been discarded, either because
2636 it is a copy of a linkonce section or due to
2637 linker script /DISCARD/, so we'll be discarding
2640 else if (p
->count
!= 0)
2642 srel
= elf_section_data (p
->sec
)->sreloc
;
2643 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2644 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2645 && (info
->flags
& DF_TEXTREL
) == 0)
2647 info
->flags
|= DF_TEXTREL
;
2648 if (info
->warn_shared_textrel
&& info
->shared
)
2649 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2650 p
->sec
->owner
, p
->sec
);
2656 local_got
= elf_local_got_refcounts (ibfd
);
2660 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2661 locsymcount
= symtab_hdr
->sh_info
;
2662 end_local_got
= local_got
+ locsymcount
;
2663 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2664 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2666 srel
= htab
->elf
.srelgot
;
2667 for (; local_got
< end_local_got
;
2668 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2670 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2673 if (GOT_TLS_GDESC_P (*local_tls_type
))
2675 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2676 - elf_x86_64_compute_jump_table_size (htab
);
2677 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2678 *local_got
= (bfd_vma
) -2;
2680 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2681 || GOT_TLS_GD_P (*local_tls_type
))
2683 *local_got
= s
->size
;
2684 s
->size
+= GOT_ENTRY_SIZE
;
2685 if (GOT_TLS_GD_P (*local_tls_type
))
2686 s
->size
+= GOT_ENTRY_SIZE
;
2689 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2690 || *local_tls_type
== GOT_TLS_IE
)
2692 if (GOT_TLS_GDESC_P (*local_tls_type
))
2694 htab
->elf
.srelplt
->size
2695 += bed
->s
->sizeof_rela
;
2696 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2698 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2699 || GOT_TLS_GD_P (*local_tls_type
))
2700 srel
->size
+= bed
->s
->sizeof_rela
;
2704 *local_got
= (bfd_vma
) -1;
2708 if (htab
->tls_ld_got
.refcount
> 0)
2710 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2712 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2713 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2714 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2717 htab
->tls_ld_got
.offset
= -1;
2719 /* Allocate global sym .plt and .got entries, and space for global
2720 sym dynamic relocs. */
2721 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2724 /* Allocate .plt and .got entries, and space for local symbols. */
2725 htab_traverse (htab
->loc_hash_table
,
2726 elf_x86_64_allocate_local_dynrelocs
,
2729 /* For every jump slot reserved in the sgotplt, reloc_count is
2730 incremented. However, when we reserve space for TLS descriptors,
2731 it's not incremented, so in order to compute the space reserved
2732 for them, it suffices to multiply the reloc count by the jump
2735 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2736 so that R_X86_64_IRELATIVE entries come last. */
2737 if (htab
->elf
.srelplt
)
2739 htab
->sgotplt_jump_table_size
2740 = elf_x86_64_compute_jump_table_size (htab
);
2741 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2743 else if (htab
->elf
.irelplt
)
2744 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2746 if (htab
->tlsdesc_plt
)
2748 /* If we're not using lazy TLS relocations, don't generate the
2749 PLT and GOT entries they require. */
2750 if ((info
->flags
& DF_BIND_NOW
))
2751 htab
->tlsdesc_plt
= 0;
2754 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2755 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2756 /* Reserve room for the initial entry.
2757 FIXME: we could probably do away with it in this case. */
2758 if (htab
->elf
.splt
->size
== 0)
2759 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2760 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2761 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2765 if (htab
->elf
.sgotplt
)
2767 struct elf_link_hash_entry
*got
;
2768 got
= elf_link_hash_lookup (elf_hash_table (info
),
2769 "_GLOBAL_OFFSET_TABLE_",
2770 FALSE
, FALSE
, FALSE
);
2772 /* Don't allocate .got.plt section if there are no GOT nor PLT
2773 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2775 || !got
->ref_regular_nonweak
)
2776 && (htab
->elf
.sgotplt
->size
2777 == get_elf_backend_data (output_bfd
)->got_header_size
)
2778 && (htab
->elf
.splt
== NULL
2779 || htab
->elf
.splt
->size
== 0)
2780 && (htab
->elf
.sgot
== NULL
2781 || htab
->elf
.sgot
->size
== 0)
2782 && (htab
->elf
.iplt
== NULL
2783 || htab
->elf
.iplt
->size
== 0)
2784 && (htab
->elf
.igotplt
== NULL
2785 || htab
->elf
.igotplt
->size
== 0))
2786 htab
->elf
.sgotplt
->size
= 0;
2789 /* We now have determined the sizes of the various dynamic sections.
2790 Allocate memory for them. */
2792 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2794 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2797 if (s
== htab
->elf
.splt
2798 || s
== htab
->elf
.sgot
2799 || s
== htab
->elf
.sgotplt
2800 || s
== htab
->elf
.iplt
2801 || s
== htab
->elf
.igotplt
2802 || s
== htab
->sdynbss
)
2804 /* Strip this section if we don't need it; see the
2807 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2809 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2812 /* We use the reloc_count field as a counter if we need
2813 to copy relocs into the output file. */
2814 if (s
!= htab
->elf
.srelplt
)
2819 /* It's not one of our sections, so don't allocate space. */
2825 /* If we don't need this section, strip it from the
2826 output file. This is mostly to handle .rela.bss and
2827 .rela.plt. We must create both sections in
2828 create_dynamic_sections, because they must be created
2829 before the linker maps input sections to output
2830 sections. The linker does that before
2831 adjust_dynamic_symbol is called, and it is that
2832 function which decides whether anything needs to go
2833 into these sections. */
2835 s
->flags
|= SEC_EXCLUDE
;
2839 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2842 /* Allocate memory for the section contents. We use bfd_zalloc
2843 here in case unused entries are not reclaimed before the
2844 section's contents are written out. This should not happen,
2845 but this way if it does, we get a R_X86_64_NONE reloc instead
2847 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2848 if (s
->contents
== NULL
)
2852 if (htab
->plt_eh_frame
!= NULL
2853 && htab
->elf
.splt
!= NULL
2854 && htab
->elf
.splt
->size
!= 0
2855 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2856 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2857 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2859 if (htab
->elf
.dynamic_sections_created
)
2861 /* Add some entries to the .dynamic section. We fill in the
2862 values later, in elf_x86_64_finish_dynamic_sections, but we
2863 must add the entries now so that we get the correct size for
2864 the .dynamic section. The DT_DEBUG entry is filled in by the
2865 dynamic linker and used by the debugger. */
2866 #define add_dynamic_entry(TAG, VAL) \
2867 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2869 if (info
->executable
)
2871 if (!add_dynamic_entry (DT_DEBUG
, 0))
2875 if (htab
->elf
.splt
->size
!= 0)
2877 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2878 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2879 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2880 || !add_dynamic_entry (DT_JMPREL
, 0))
2883 if (htab
->tlsdesc_plt
2884 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2885 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2891 if (!add_dynamic_entry (DT_RELA
, 0)
2892 || !add_dynamic_entry (DT_RELASZ
, 0)
2893 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2896 /* If any dynamic relocs apply to a read-only section,
2897 then we need a DT_TEXTREL entry. */
2898 if ((info
->flags
& DF_TEXTREL
) == 0)
2899 elf_link_hash_traverse (&htab
->elf
,
2900 elf_x86_64_readonly_dynrelocs
,
2903 if ((info
->flags
& DF_TEXTREL
) != 0)
2905 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2910 #undef add_dynamic_entry
2916 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2917 struct bfd_link_info
*info
)
2919 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2923 struct elf_link_hash_entry
*tlsbase
;
2925 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2926 "_TLS_MODULE_BASE_",
2927 FALSE
, FALSE
, FALSE
);
2929 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2931 struct elf_x86_64_link_hash_table
*htab
;
2932 struct bfd_link_hash_entry
*bh
= NULL
;
2933 const struct elf_backend_data
*bed
2934 = get_elf_backend_data (output_bfd
);
2936 htab
= elf_x86_64_hash_table (info
);
2940 if (!(_bfd_generic_link_add_one_symbol
2941 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2942 tls_sec
, 0, NULL
, FALSE
,
2943 bed
->collect
, &bh
)))
2946 htab
->tls_module_base
= bh
;
2948 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2949 tlsbase
->def_regular
= 1;
2950 tlsbase
->other
= STV_HIDDEN
;
2951 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2958 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2959 executables. Rather than setting it to the beginning of the TLS
2960 section, we have to set it to the end. This function may be called
2961 multiple times, it is idempotent. */
2964 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2966 struct elf_x86_64_link_hash_table
*htab
;
2967 struct bfd_link_hash_entry
*base
;
2969 if (!info
->executable
)
2972 htab
= elf_x86_64_hash_table (info
);
2976 base
= htab
->tls_module_base
;
2980 base
->u
.def
.value
= htab
->elf
.tls_size
;
2983 /* Return the base VMA address which should be subtracted from real addresses
2984 when resolving @dtpoff relocation.
2985 This is PT_TLS segment p_vaddr. */
2988 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2990 /* If tls_sec is NULL, we should have signalled an error already. */
2991 if (elf_hash_table (info
)->tls_sec
== NULL
)
2993 return elf_hash_table (info
)->tls_sec
->vma
;
2996 /* Return the relocation value for @tpoff relocation
2997 if STT_TLS virtual address is ADDRESS. */
3000 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3002 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3003 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3004 bfd_vma static_tls_size
;
3006 /* If tls_segment is NULL, we should have signalled an error already. */
3007 if (htab
->tls_sec
== NULL
)
3010 /* Consider special static TLS alignment requirements. */
3011 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3012 return address
- static_tls_size
- htab
->tls_sec
->vma
;
3015 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3019 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
3021 /* Opcode Instruction
3024 0x0f 0x8x conditional jump */
3026 && (contents
[offset
- 1] == 0xe8
3027 || contents
[offset
- 1] == 0xe9))
3029 && contents
[offset
- 2] == 0x0f
3030 && (contents
[offset
- 1] & 0xf0) == 0x80));
3033 /* Relocate an x86_64 ELF section. */
3036 elf_x86_64_relocate_section (bfd
*output_bfd
,
3037 struct bfd_link_info
*info
,
3039 asection
*input_section
,
3041 Elf_Internal_Rela
*relocs
,
3042 Elf_Internal_Sym
*local_syms
,
3043 asection
**local_sections
)
3045 struct elf_x86_64_link_hash_table
*htab
;
3046 Elf_Internal_Shdr
*symtab_hdr
;
3047 struct elf_link_hash_entry
**sym_hashes
;
3048 bfd_vma
*local_got_offsets
;
3049 bfd_vma
*local_tlsdesc_gotents
;
3050 Elf_Internal_Rela
*rel
;
3051 Elf_Internal_Rela
*relend
;
3052 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3054 BFD_ASSERT (is_x86_64_elf (input_bfd
));
3056 htab
= elf_x86_64_hash_table (info
);
3059 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3060 sym_hashes
= elf_sym_hashes (input_bfd
);
3061 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3062 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
3064 elf_x86_64_set_tls_module_base (info
);
3067 relend
= relocs
+ input_section
->reloc_count
;
3068 for (; rel
< relend
; rel
++)
3070 unsigned int r_type
;
3071 reloc_howto_type
*howto
;
3072 unsigned long r_symndx
;
3073 struct elf_link_hash_entry
*h
;
3074 Elf_Internal_Sym
*sym
;
3076 bfd_vma off
, offplt
;
3078 bfd_boolean unresolved_reloc
;
3079 bfd_reloc_status_type r
;
3083 r_type
= ELF32_R_TYPE (rel
->r_info
);
3084 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3085 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3088 if (r_type
>= R_X86_64_max
)
3090 bfd_set_error (bfd_error_bad_value
);
3094 if (r_type
!= (int) R_X86_64_32
3095 || ABI_64_P (output_bfd
))
3096 howto
= x86_64_elf_howto_table
+ r_type
;
3098 howto
= (x86_64_elf_howto_table
3099 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3100 r_symndx
= htab
->r_sym (rel
->r_info
);
3104 unresolved_reloc
= FALSE
;
3105 if (r_symndx
< symtab_hdr
->sh_info
)
3107 sym
= local_syms
+ r_symndx
;
3108 sec
= local_sections
[r_symndx
];
3110 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3113 /* Relocate against local STT_GNU_IFUNC symbol. */
3114 if (!info
->relocatable
3115 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3117 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3122 /* Set STT_GNU_IFUNC symbol value. */
3123 h
->root
.u
.def
.value
= sym
->st_value
;
3124 h
->root
.u
.def
.section
= sec
;
3129 bfd_boolean warned ATTRIBUTE_UNUSED
;
3131 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3132 r_symndx
, symtab_hdr
, sym_hashes
,
3134 unresolved_reloc
, warned
);
3137 if (sec
!= NULL
&& elf_discarded_section (sec
))
3138 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3139 rel
, relend
, howto
, contents
);
3141 if (info
->relocatable
)
3144 if (rel
->r_addend
== 0
3145 && r_type
== R_X86_64_64
3146 && !ABI_64_P (output_bfd
))
3148 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3149 it to 64bit if addend is zero. */
3150 r_type
= R_X86_64_32
;
3151 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3154 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3155 it here if it is defined in a non-shared object. */
3157 && h
->type
== STT_GNU_IFUNC
3164 if ((input_section
->flags
& SEC_ALLOC
) == 0
3165 || h
->plt
.offset
== (bfd_vma
) -1)
3168 /* STT_GNU_IFUNC symbol must go through PLT. */
3169 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3170 relocation
= (plt
->output_section
->vma
3171 + plt
->output_offset
+ h
->plt
.offset
);
3176 if (h
->root
.root
.string
)
3177 name
= h
->root
.root
.string
;
3179 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3181 (*_bfd_error_handler
)
3182 (_("%B: relocation %s against STT_GNU_IFUNC "
3183 "symbol `%s' isn't handled by %s"), input_bfd
,
3184 x86_64_elf_howto_table
[r_type
].name
,
3185 name
, __FUNCTION__
);
3186 bfd_set_error (bfd_error_bad_value
);
3195 if (ABI_64_P (output_bfd
))
3199 if (rel
->r_addend
!= 0)
3201 if (h
->root
.root
.string
)
3202 name
= h
->root
.root
.string
;
3204 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3206 (*_bfd_error_handler
)
3207 (_("%B: relocation %s against STT_GNU_IFUNC "
3208 "symbol `%s' has non-zero addend: %d"),
3209 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3210 name
, rel
->r_addend
);
3211 bfd_set_error (bfd_error_bad_value
);
3215 /* Generate dynamic relcoation only when there is a
3216 non-GOT reference in a shared object. */
3217 if (info
->shared
&& h
->non_got_ref
)
3219 Elf_Internal_Rela outrel
;
3222 /* Need a dynamic relocation to get the real function
3224 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3228 if (outrel
.r_offset
== (bfd_vma
) -1
3229 || outrel
.r_offset
== (bfd_vma
) -2)
3232 outrel
.r_offset
+= (input_section
->output_section
->vma
3233 + input_section
->output_offset
);
3235 if (h
->dynindx
== -1
3237 || info
->executable
)
3239 /* This symbol is resolved locally. */
3240 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3241 outrel
.r_addend
= (h
->root
.u
.def
.value
3242 + h
->root
.u
.def
.section
->output_section
->vma
3243 + h
->root
.u
.def
.section
->output_offset
);
3247 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3248 outrel
.r_addend
= 0;
3251 sreloc
= htab
->elf
.irelifunc
;
3252 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3254 /* If this reloc is against an external symbol, we
3255 do not want to fiddle with the addend. Otherwise,
3256 we need to include the symbol value so that it
3257 becomes an addend for the dynamic reloc. For an
3258 internal symbol, we have updated addend. */
3264 case R_X86_64_PLT32
:
3267 case R_X86_64_GOTPCREL
:
3268 case R_X86_64_GOTPCREL64
:
3269 base_got
= htab
->elf
.sgot
;
3270 off
= h
->got
.offset
;
3272 if (base_got
== NULL
)
3275 if (off
== (bfd_vma
) -1)
3277 /* We can't use h->got.offset here to save state, or
3278 even just remember the offset, as finish_dynamic_symbol
3279 would use that as offset into .got. */
3281 if (htab
->elf
.splt
!= NULL
)
3283 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3284 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3285 base_got
= htab
->elf
.sgotplt
;
3289 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3290 off
= plt_index
* GOT_ENTRY_SIZE
;
3291 base_got
= htab
->elf
.igotplt
;
3294 if (h
->dynindx
== -1
3298 /* This references the local defitionion. We must
3299 initialize this entry in the global offset table.
3300 Since the offset must always be a multiple of 8,
3301 we use the least significant bit to record
3302 whether we have initialized it already.
3304 When doing a dynamic link, we create a .rela.got
3305 relocation entry to initialize the value. This
3306 is done in the finish_dynamic_symbol routine. */
3311 bfd_put_64 (output_bfd
, relocation
,
3312 base_got
->contents
+ off
);
3313 /* Note that this is harmless for the GOTPLT64
3314 case, as -1 | 1 still is -1. */
3320 relocation
= (base_got
->output_section
->vma
3321 + base_got
->output_offset
+ off
);
3327 /* When generating a shared object, the relocations handled here are
3328 copied into the output file to be resolved at run time. */
3331 case R_X86_64_GOT32
:
3332 case R_X86_64_GOT64
:
3333 /* Relocation is to the entry for this symbol in the global
3335 case R_X86_64_GOTPCREL
:
3336 case R_X86_64_GOTPCREL64
:
3337 /* Use global offset table entry as symbol value. */
3338 case R_X86_64_GOTPLT64
:
3339 /* This is the same as GOT64 for relocation purposes, but
3340 indicates the existence of a PLT entry. The difficulty is,
3341 that we must calculate the GOT slot offset from the PLT
3342 offset, if this symbol got a PLT entry (it was global).
3343 Additionally if it's computed from the PLT entry, then that
3344 GOT offset is relative to .got.plt, not to .got. */
3345 base_got
= htab
->elf
.sgot
;
3347 if (htab
->elf
.sgot
== NULL
)
3354 off
= h
->got
.offset
;
3356 && h
->plt
.offset
!= (bfd_vma
)-1
3357 && off
== (bfd_vma
)-1)
3359 /* We can't use h->got.offset here to save
3360 state, or even just remember the offset, as
3361 finish_dynamic_symbol would use that as offset into
3363 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3364 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3365 base_got
= htab
->elf
.sgotplt
;
3368 dyn
= htab
->elf
.dynamic_sections_created
;
3370 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3372 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3373 || (ELF_ST_VISIBILITY (h
->other
)
3374 && h
->root
.type
== bfd_link_hash_undefweak
))
3376 /* This is actually a static link, or it is a -Bsymbolic
3377 link and the symbol is defined locally, or the symbol
3378 was forced to be local because of a version file. We
3379 must initialize this entry in the global offset table.
3380 Since the offset must always be a multiple of 8, we
3381 use the least significant bit to record whether we
3382 have initialized it already.
3384 When doing a dynamic link, we create a .rela.got
3385 relocation entry to initialize the value. This is
3386 done in the finish_dynamic_symbol routine. */
3391 bfd_put_64 (output_bfd
, relocation
,
3392 base_got
->contents
+ off
);
3393 /* Note that this is harmless for the GOTPLT64 case,
3394 as -1 | 1 still is -1. */
3399 unresolved_reloc
= FALSE
;
3403 if (local_got_offsets
== NULL
)
3406 off
= local_got_offsets
[r_symndx
];
3408 /* The offset must always be a multiple of 8. We use
3409 the least significant bit to record whether we have
3410 already generated the necessary reloc. */
3415 bfd_put_64 (output_bfd
, relocation
,
3416 base_got
->contents
+ off
);
3421 Elf_Internal_Rela outrel
;
3423 /* We need to generate a R_X86_64_RELATIVE reloc
3424 for the dynamic linker. */
3425 s
= htab
->elf
.srelgot
;
3429 outrel
.r_offset
= (base_got
->output_section
->vma
3430 + base_got
->output_offset
3432 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3433 outrel
.r_addend
= relocation
;
3434 elf_append_rela (output_bfd
, s
, &outrel
);
3437 local_got_offsets
[r_symndx
] |= 1;
3441 if (off
>= (bfd_vma
) -2)
3444 relocation
= base_got
->output_section
->vma
3445 + base_got
->output_offset
+ off
;
3446 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3447 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3448 - htab
->elf
.sgotplt
->output_offset
;
3452 case R_X86_64_GOTOFF64
:
3453 /* Relocation is relative to the start of the global offset
3456 /* Check to make sure it isn't a protected function symbol
3457 for shared library since it may not be local when used
3458 as function address. */
3462 && h
->type
== STT_FUNC
3463 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3465 (*_bfd_error_handler
)
3466 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3467 input_bfd
, h
->root
.root
.string
);
3468 bfd_set_error (bfd_error_bad_value
);
3472 /* Note that sgot is not involved in this
3473 calculation. We always want the start of .got.plt. If we
3474 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3475 permitted by the ABI, we might have to change this
3477 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3478 + htab
->elf
.sgotplt
->output_offset
;
3481 case R_X86_64_GOTPC32
:
3482 case R_X86_64_GOTPC64
:
3483 /* Use global offset table as symbol value. */
3484 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3485 + htab
->elf
.sgotplt
->output_offset
;
3486 unresolved_reloc
= FALSE
;
3489 case R_X86_64_PLTOFF64
:
3490 /* Relocation is PLT entry relative to GOT. For local
3491 symbols it's the symbol itself relative to GOT. */
3493 /* See PLT32 handling. */
3494 && h
->plt
.offset
!= (bfd_vma
) -1
3495 && htab
->elf
.splt
!= NULL
)
3497 relocation
= (htab
->elf
.splt
->output_section
->vma
3498 + htab
->elf
.splt
->output_offset
3500 unresolved_reloc
= FALSE
;
3503 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3504 + htab
->elf
.sgotplt
->output_offset
;
3507 case R_X86_64_PLT32
:
3508 /* Relocation is to the entry for this symbol in the
3509 procedure linkage table. */
3511 /* Resolve a PLT32 reloc against a local symbol directly,
3512 without using the procedure linkage table. */
3516 if (h
->plt
.offset
== (bfd_vma
) -1
3517 || htab
->elf
.splt
== NULL
)
3519 /* We didn't make a PLT entry for this symbol. This
3520 happens when statically linking PIC code, or when
3521 using -Bsymbolic. */
3525 relocation
= (htab
->elf
.splt
->output_section
->vma
3526 + htab
->elf
.splt
->output_offset
3528 unresolved_reloc
= FALSE
;
3535 && (input_section
->flags
& SEC_ALLOC
) != 0
3536 && (input_section
->flags
& SEC_READONLY
) != 0
3539 bfd_boolean fail
= FALSE
;
3541 = (r_type
== R_X86_64_PC32
3542 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3544 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3546 /* Symbol is referenced locally. Make sure it is
3547 defined locally or for a branch. */
3548 fail
= !h
->def_regular
&& !branch
;
3552 /* Symbol isn't referenced locally. We only allow
3553 branch to symbol with non-default visibility. */
3555 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3562 const char *pic
= "";
3564 switch (ELF_ST_VISIBILITY (h
->other
))
3567 v
= _("hidden symbol");
3570 v
= _("internal symbol");
3573 v
= _("protected symbol");
3577 pic
= _("; recompile with -fPIC");
3582 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3584 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3586 (*_bfd_error_handler
) (fmt
, input_bfd
,
3587 x86_64_elf_howto_table
[r_type
].name
,
3588 v
, h
->root
.root
.string
, pic
);
3589 bfd_set_error (bfd_error_bad_value
);
3600 /* FIXME: The ABI says the linker should make sure the value is
3601 the same when it's zeroextended to 64 bit. */
3603 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3608 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3609 || h
->root
.type
!= bfd_link_hash_undefweak
)
3610 && (! IS_X86_64_PCREL_TYPE (r_type
)
3611 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3612 || (ELIMINATE_COPY_RELOCS
3619 || h
->root
.type
== bfd_link_hash_undefweak
3620 || h
->root
.type
== bfd_link_hash_undefined
)))
3622 Elf_Internal_Rela outrel
;
3623 bfd_boolean skip
, relocate
;
3626 /* When generating a shared object, these relocations
3627 are copied into the output file to be resolved at run
3633 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3635 if (outrel
.r_offset
== (bfd_vma
) -1)
3637 else if (outrel
.r_offset
== (bfd_vma
) -2)
3638 skip
= TRUE
, relocate
= TRUE
;
3640 outrel
.r_offset
+= (input_section
->output_section
->vma
3641 + input_section
->output_offset
);
3644 memset (&outrel
, 0, sizeof outrel
);
3646 /* h->dynindx may be -1 if this symbol was marked to
3650 && (IS_X86_64_PCREL_TYPE (r_type
)
3652 || ! SYMBOLIC_BIND (info
, h
)
3653 || ! h
->def_regular
))
3655 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3656 outrel
.r_addend
= rel
->r_addend
;
3660 /* This symbol is local, or marked to become local. */
3661 if (r_type
== htab
->pointer_r_type
)
3664 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3665 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3667 else if (r_type
== R_X86_64_64
3668 && !ABI_64_P (output_bfd
))
3671 outrel
.r_info
= htab
->r_info (0,
3672 R_X86_64_RELATIVE64
);
3673 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3679 if (bfd_is_abs_section (sec
))
3681 else if (sec
== NULL
|| sec
->owner
== NULL
)
3683 bfd_set_error (bfd_error_bad_value
);
3690 /* We are turning this relocation into one
3691 against a section symbol. It would be
3692 proper to subtract the symbol's value,
3693 osec->vma, from the emitted reloc addend,
3694 but ld.so expects buggy relocs. */
3695 osec
= sec
->output_section
;
3696 sindx
= elf_section_data (osec
)->dynindx
;
3699 asection
*oi
= htab
->elf
.text_index_section
;
3700 sindx
= elf_section_data (oi
)->dynindx
;
3702 BFD_ASSERT (sindx
!= 0);
3705 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3706 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3710 sreloc
= elf_section_data (input_section
)->sreloc
;
3712 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3714 r
= bfd_reloc_notsupported
;
3715 goto check_relocation_error
;
3718 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3720 /* If this reloc is against an external symbol, we do
3721 not want to fiddle with the addend. Otherwise, we
3722 need to include the symbol value so that it becomes
3723 an addend for the dynamic reloc. */
3730 case R_X86_64_TLSGD
:
3731 case R_X86_64_GOTPC32_TLSDESC
:
3732 case R_X86_64_TLSDESC_CALL
:
3733 case R_X86_64_GOTTPOFF
:
3734 tls_type
= GOT_UNKNOWN
;
3735 if (h
== NULL
&& local_got_offsets
)
3736 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3738 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3740 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3741 input_section
, contents
,
3742 symtab_hdr
, sym_hashes
,
3743 &r_type
, tls_type
, rel
,
3744 relend
, h
, r_symndx
))
3747 if (r_type
== R_X86_64_TPOFF32
)
3749 bfd_vma roff
= rel
->r_offset
;
3751 BFD_ASSERT (! unresolved_reloc
);
3753 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3755 /* GD->LE transition. For 64bit, change
3756 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3757 .word 0x6666; rex64; call __tls_get_addr
3760 leaq foo@tpoff(%rax), %rax
3762 leaq foo@tlsgd(%rip), %rdi
3763 .word 0x6666; rex64; call __tls_get_addr
3766 leaq foo@tpoff(%rax), %rax */
3767 if (ABI_64_P (output_bfd
))
3768 memcpy (contents
+ roff
- 4,
3769 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3772 memcpy (contents
+ roff
- 3,
3773 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3775 bfd_put_32 (output_bfd
,
3776 elf_x86_64_tpoff (info
, relocation
),
3777 contents
+ roff
+ 8);
3778 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3782 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3784 /* GDesc -> LE transition.
3785 It's originally something like:
3786 leaq x@tlsdesc(%rip), %rax
3789 movl $x@tpoff, %rax. */
3791 unsigned int val
, type
;
3793 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3794 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3795 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3796 contents
+ roff
- 3);
3797 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3798 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3799 contents
+ roff
- 1);
3800 bfd_put_32 (output_bfd
,
3801 elf_x86_64_tpoff (info
, relocation
),
3805 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3807 /* GDesc -> LE transition.
3812 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3813 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3816 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3818 /* IE->LE transition:
3819 Originally it can be one of:
3820 movq foo@gottpoff(%rip), %reg
3821 addq foo@gottpoff(%rip), %reg
3824 leaq foo(%reg), %reg
3827 unsigned int val
, type
, reg
;
3829 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3830 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3831 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3837 bfd_put_8 (output_bfd
, 0x49,
3838 contents
+ roff
- 3);
3839 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3840 bfd_put_8 (output_bfd
, 0x41,
3841 contents
+ roff
- 3);
3842 bfd_put_8 (output_bfd
, 0xc7,
3843 contents
+ roff
- 2);
3844 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3845 contents
+ roff
- 1);
3849 /* addq -> addq - addressing with %rsp/%r12 is
3852 bfd_put_8 (output_bfd
, 0x49,
3853 contents
+ roff
- 3);
3854 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3855 bfd_put_8 (output_bfd
, 0x41,
3856 contents
+ roff
- 3);
3857 bfd_put_8 (output_bfd
, 0x81,
3858 contents
+ roff
- 2);
3859 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3860 contents
+ roff
- 1);
3866 bfd_put_8 (output_bfd
, 0x4d,
3867 contents
+ roff
- 3);
3868 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3869 bfd_put_8 (output_bfd
, 0x45,
3870 contents
+ roff
- 3);
3871 bfd_put_8 (output_bfd
, 0x8d,
3872 contents
+ roff
- 2);
3873 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3874 contents
+ roff
- 1);
3876 bfd_put_32 (output_bfd
,
3877 elf_x86_64_tpoff (info
, relocation
),
3885 if (htab
->elf
.sgot
== NULL
)
3890 off
= h
->got
.offset
;
3891 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3895 if (local_got_offsets
== NULL
)
3898 off
= local_got_offsets
[r_symndx
];
3899 offplt
= local_tlsdesc_gotents
[r_symndx
];
3906 Elf_Internal_Rela outrel
;
3910 if (htab
->elf
.srelgot
== NULL
)
3913 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3915 if (GOT_TLS_GDESC_P (tls_type
))
3917 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3918 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3919 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3920 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3921 + htab
->elf
.sgotplt
->output_offset
3923 + htab
->sgotplt_jump_table_size
);
3924 sreloc
= htab
->elf
.srelplt
;
3926 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3928 outrel
.r_addend
= 0;
3929 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3932 sreloc
= htab
->elf
.srelgot
;
3934 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3935 + htab
->elf
.sgot
->output_offset
+ off
);
3937 if (GOT_TLS_GD_P (tls_type
))
3938 dr_type
= R_X86_64_DTPMOD64
;
3939 else if (GOT_TLS_GDESC_P (tls_type
))
3942 dr_type
= R_X86_64_TPOFF64
;
3944 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3945 outrel
.r_addend
= 0;
3946 if ((dr_type
== R_X86_64_TPOFF64
3947 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3948 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3949 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3951 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3953 if (GOT_TLS_GD_P (tls_type
))
3957 BFD_ASSERT (! unresolved_reloc
);
3958 bfd_put_64 (output_bfd
,
3959 relocation
- elf_x86_64_dtpoff_base (info
),
3960 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3964 bfd_put_64 (output_bfd
, 0,
3965 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3966 outrel
.r_info
= htab
->r_info (indx
,
3968 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3969 elf_append_rela (output_bfd
, sreloc
,
3978 local_got_offsets
[r_symndx
] |= 1;
3981 if (off
>= (bfd_vma
) -2
3982 && ! GOT_TLS_GDESC_P (tls_type
))
3984 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3986 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3987 || r_type
== R_X86_64_TLSDESC_CALL
)
3988 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3989 + htab
->elf
.sgotplt
->output_offset
3990 + offplt
+ htab
->sgotplt_jump_table_size
;
3992 relocation
= htab
->elf
.sgot
->output_section
->vma
3993 + htab
->elf
.sgot
->output_offset
+ off
;
3994 unresolved_reloc
= FALSE
;
3998 bfd_vma roff
= rel
->r_offset
;
4000 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4002 /* GD->IE transition. For 64bit, change
4003 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4004 .word 0x6666; rex64; call __tls_get_addr@plt
4007 addq foo@gottpoff(%rip), %rax
4009 leaq foo@tlsgd(%rip), %rdi
4010 .word 0x6666; rex64; call __tls_get_addr@plt
4013 addq foo@gottpoff(%rip), %rax */
4014 if (ABI_64_P (output_bfd
))
4015 memcpy (contents
+ roff
- 4,
4016 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4019 memcpy (contents
+ roff
- 3,
4020 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4023 relocation
= (htab
->elf
.sgot
->output_section
->vma
4024 + htab
->elf
.sgot
->output_offset
+ off
4026 - input_section
->output_section
->vma
4027 - input_section
->output_offset
4029 bfd_put_32 (output_bfd
, relocation
,
4030 contents
+ roff
+ 8);
4031 /* Skip R_X86_64_PLT32. */
4035 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4037 /* GDesc -> IE transition.
4038 It's originally something like:
4039 leaq x@tlsdesc(%rip), %rax
4042 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4044 /* Now modify the instruction as appropriate. To
4045 turn a leaq into a movq in the form we use it, it
4046 suffices to change the second byte from 0x8d to
4048 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4050 bfd_put_32 (output_bfd
,
4051 htab
->elf
.sgot
->output_section
->vma
4052 + htab
->elf
.sgot
->output_offset
+ off
4054 - input_section
->output_section
->vma
4055 - input_section
->output_offset
4060 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4062 /* GDesc -> IE transition.
4069 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4070 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4078 case R_X86_64_TLSLD
:
4079 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4080 input_section
, contents
,
4081 symtab_hdr
, sym_hashes
,
4082 &r_type
, GOT_UNKNOWN
,
4083 rel
, relend
, h
, r_symndx
))
4086 if (r_type
!= R_X86_64_TLSLD
)
4088 /* LD->LE transition:
4089 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4090 For 64bit, we change it into:
4091 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4092 For 32bit, we change it into:
4093 nopl 0x0(%rax); movl %fs:0, %eax. */
4095 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4096 if (ABI_64_P (output_bfd
))
4097 memcpy (contents
+ rel
->r_offset
- 3,
4098 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4100 memcpy (contents
+ rel
->r_offset
- 3,
4101 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4102 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4107 if (htab
->elf
.sgot
== NULL
)
4110 off
= htab
->tls_ld_got
.offset
;
4115 Elf_Internal_Rela outrel
;
4117 if (htab
->elf
.srelgot
== NULL
)
4120 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4121 + htab
->elf
.sgot
->output_offset
+ off
);
4123 bfd_put_64 (output_bfd
, 0,
4124 htab
->elf
.sgot
->contents
+ off
);
4125 bfd_put_64 (output_bfd
, 0,
4126 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4127 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4128 outrel
.r_addend
= 0;
4129 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4131 htab
->tls_ld_got
.offset
|= 1;
4133 relocation
= htab
->elf
.sgot
->output_section
->vma
4134 + htab
->elf
.sgot
->output_offset
+ off
;
4135 unresolved_reloc
= FALSE
;
4138 case R_X86_64_DTPOFF32
:
4139 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4140 relocation
-= elf_x86_64_dtpoff_base (info
);
4142 relocation
= elf_x86_64_tpoff (info
, relocation
);
4145 case R_X86_64_TPOFF32
:
4146 case R_X86_64_TPOFF64
:
4147 BFD_ASSERT (info
->executable
);
4148 relocation
= elf_x86_64_tpoff (info
, relocation
);
4155 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4156 because such sections are not SEC_ALLOC and thus ld.so will
4157 not process them. */
4158 if (unresolved_reloc
4159 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4161 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4162 rel
->r_offset
) != (bfd_vma
) -1)
4163 (*_bfd_error_handler
)
4164 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4167 (long) rel
->r_offset
,
4169 h
->root
.root
.string
);
4172 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4173 contents
, rel
->r_offset
,
4174 relocation
, rel
->r_addend
);
4176 check_relocation_error
:
4177 if (r
!= bfd_reloc_ok
)
4182 name
= h
->root
.root
.string
;
4185 name
= bfd_elf_string_from_elf_section (input_bfd
,
4186 symtab_hdr
->sh_link
,
4191 name
= bfd_section_name (input_bfd
, sec
);
4194 if (r
== bfd_reloc_overflow
)
4196 if (! ((*info
->callbacks
->reloc_overflow
)
4197 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4198 (bfd_vma
) 0, input_bfd
, input_section
,
4204 (*_bfd_error_handler
)
4205 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4206 input_bfd
, input_section
,
4207 (long) rel
->r_offset
, name
, (int) r
);
4216 /* Finish up dynamic symbol handling. We set the contents of various
4217 dynamic sections here. */
4220 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4221 struct bfd_link_info
*info
,
4222 struct elf_link_hash_entry
*h
,
4223 Elf_Internal_Sym
*sym
)
4225 struct elf_x86_64_link_hash_table
*htab
;
4226 const struct elf_x86_64_backend_data
*const abed
4227 = get_elf_x86_64_backend_data (output_bfd
);
4229 htab
= elf_x86_64_hash_table (info
);
4233 if (h
->plt
.offset
!= (bfd_vma
) -1)
4237 Elf_Internal_Rela rela
;
4239 asection
*plt
, *gotplt
, *relplt
;
4240 const struct elf_backend_data
*bed
;
4242 /* When building a static executable, use .iplt, .igot.plt and
4243 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4244 if (htab
->elf
.splt
!= NULL
)
4246 plt
= htab
->elf
.splt
;
4247 gotplt
= htab
->elf
.sgotplt
;
4248 relplt
= htab
->elf
.srelplt
;
4252 plt
= htab
->elf
.iplt
;
4253 gotplt
= htab
->elf
.igotplt
;
4254 relplt
= htab
->elf
.irelplt
;
4257 /* This symbol has an entry in the procedure linkage table. Set
4259 if ((h
->dynindx
== -1
4260 && !((h
->forced_local
|| info
->executable
)
4262 && h
->type
== STT_GNU_IFUNC
))
4268 /* Get the index in the procedure linkage table which
4269 corresponds to this symbol. This is the index of this symbol
4270 in all the symbols for which we are making plt entries. The
4271 first entry in the procedure linkage table is reserved.
4273 Get the offset into the .got table of the entry that
4274 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4275 bytes. The first three are reserved for the dynamic linker.
4277 For static executables, we don't reserve anything. */
4279 if (plt
== htab
->elf
.splt
)
4281 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
4282 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4286 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
4287 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4290 /* Fill in the entry in the procedure linkage table. */
4291 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
4292 abed
->plt_entry_size
);
4294 /* Insert the relocation positions of the plt section. */
4296 /* Put offset the PC-relative instruction referring to the GOT entry,
4297 subtracting the size of that instruction. */
4298 bfd_put_32 (output_bfd
,
4299 (gotplt
->output_section
->vma
4300 + gotplt
->output_offset
4302 - plt
->output_section
->vma
4303 - plt
->output_offset
4305 - abed
->plt_got_insn_size
),
4306 plt
->contents
+ h
->plt
.offset
+ abed
->plt_got_offset
);
4308 /* Fill in the entry in the global offset table, initially this
4309 points to the second part of the PLT entry. */
4310 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4311 + plt
->output_offset
4312 + h
->plt
.offset
+ abed
->plt_lazy_offset
),
4313 gotplt
->contents
+ got_offset
);
4315 /* Fill in the entry in the .rela.plt section. */
4316 rela
.r_offset
= (gotplt
->output_section
->vma
4317 + gotplt
->output_offset
4319 if (h
->dynindx
== -1
4320 || ((info
->executable
4321 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4323 && h
->type
== STT_GNU_IFUNC
))
4325 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4326 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4327 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4328 rela
.r_addend
= (h
->root
.u
.def
.value
4329 + h
->root
.u
.def
.section
->output_section
->vma
4330 + h
->root
.u
.def
.section
->output_offset
);
4331 /* R_X86_64_IRELATIVE comes last. */
4332 plt_index
= htab
->next_irelative_index
--;
4336 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4338 plt_index
= htab
->next_jump_slot_index
++;
4341 /* Don't fill PLT entry for static executables. */
4342 if (plt
== htab
->elf
.splt
)
4344 /* Put relocation index. */
4345 bfd_put_32 (output_bfd
, plt_index
,
4346 plt
->contents
+ h
->plt
.offset
+ abed
->plt_reloc_offset
);
4347 /* Put offset for jmp .PLT0. */
4348 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ abed
->plt_plt_insn_end
),
4349 plt
->contents
+ h
->plt
.offset
+ abed
->plt_plt_offset
);
4352 bed
= get_elf_backend_data (output_bfd
);
4353 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4354 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4356 if (!h
->def_regular
)
4358 /* Mark the symbol as undefined, rather than as defined in
4359 the .plt section. Leave the value if there were any
4360 relocations where pointer equality matters (this is a clue
4361 for the dynamic linker, to make function pointer
4362 comparisons work between an application and shared
4363 library), otherwise set it to zero. If a function is only
4364 called from a binary, there is no need to slow down
4365 shared libraries because of that. */
4366 sym
->st_shndx
= SHN_UNDEF
;
4367 if (!h
->pointer_equality_needed
)
4372 if (h
->got
.offset
!= (bfd_vma
) -1
4373 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4374 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4376 Elf_Internal_Rela rela
;
4378 /* This symbol has an entry in the global offset table. Set it
4380 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4383 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4384 + htab
->elf
.sgot
->output_offset
4385 + (h
->got
.offset
&~ (bfd_vma
) 1));
4387 /* If this is a static link, or it is a -Bsymbolic link and the
4388 symbol is defined locally or was forced to be local because
4389 of a version file, we just want to emit a RELATIVE reloc.
4390 The entry in the global offset table will already have been
4391 initialized in the relocate_section function. */
4393 && h
->type
== STT_GNU_IFUNC
)
4397 /* Generate R_X86_64_GLOB_DAT. */
4404 if (!h
->pointer_equality_needed
)
4407 /* For non-shared object, we can't use .got.plt, which
4408 contains the real function addres if we need pointer
4409 equality. We load the GOT entry with the PLT entry. */
4410 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4411 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4412 + plt
->output_offset
4414 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4418 else if (info
->shared
4419 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4421 if (!h
->def_regular
)
4423 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4424 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4425 rela
.r_addend
= (h
->root
.u
.def
.value
4426 + h
->root
.u
.def
.section
->output_section
->vma
4427 + h
->root
.u
.def
.section
->output_offset
);
4431 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4433 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4434 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4435 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4439 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4444 Elf_Internal_Rela rela
;
4446 /* This symbol needs a copy reloc. Set it up. */
4448 if (h
->dynindx
== -1
4449 || (h
->root
.type
!= bfd_link_hash_defined
4450 && h
->root
.type
!= bfd_link_hash_defweak
)
4451 || htab
->srelbss
== NULL
)
4454 rela
.r_offset
= (h
->root
.u
.def
.value
4455 + h
->root
.u
.def
.section
->output_section
->vma
4456 + h
->root
.u
.def
.section
->output_offset
);
4457 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4459 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4462 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4463 be NULL for local symbols. */
4465 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4466 || h
== htab
->elf
.hgot
))
4467 sym
->st_shndx
= SHN_ABS
;
4472 /* Finish up local dynamic symbol handling. We set the contents of
4473 various dynamic sections here. */
4476 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4478 struct elf_link_hash_entry
*h
4479 = (struct elf_link_hash_entry
*) *slot
;
4480 struct bfd_link_info
*info
4481 = (struct bfd_link_info
*) inf
;
4483 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4487 /* Used to decide how to sort relocs in an optimal manner for the
4488 dynamic linker, before writing them out. */
4490 static enum elf_reloc_type_class
4491 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4493 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4495 case R_X86_64_RELATIVE
:
4496 return reloc_class_relative
;
4497 case R_X86_64_JUMP_SLOT
:
4498 return reloc_class_plt
;
4500 return reloc_class_copy
;
4502 return reloc_class_normal
;
4506 /* Finish up the dynamic sections. */
4509 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4510 struct bfd_link_info
*info
)
4512 struct elf_x86_64_link_hash_table
*htab
;
4515 const struct elf_x86_64_backend_data
*const abed
4516 = get_elf_x86_64_backend_data (output_bfd
);
4518 htab
= elf_x86_64_hash_table (info
);
4522 dynobj
= htab
->elf
.dynobj
;
4523 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4525 if (htab
->elf
.dynamic_sections_created
)
4527 bfd_byte
*dyncon
, *dynconend
;
4528 const struct elf_backend_data
*bed
;
4529 bfd_size_type sizeof_dyn
;
4531 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4534 bed
= get_elf_backend_data (dynobj
);
4535 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4536 dyncon
= sdyn
->contents
;
4537 dynconend
= sdyn
->contents
+ sdyn
->size
;
4538 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4540 Elf_Internal_Dyn dyn
;
4543 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4551 s
= htab
->elf
.sgotplt
;
4552 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4556 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4560 s
= htab
->elf
.srelplt
->output_section
;
4561 dyn
.d_un
.d_val
= s
->size
;
4565 /* The procedure linkage table relocs (DT_JMPREL) should
4566 not be included in the overall relocs (DT_RELA).
4567 Therefore, we override the DT_RELASZ entry here to
4568 make it not include the JMPREL relocs. Since the
4569 linker script arranges for .rela.plt to follow all
4570 other relocation sections, we don't have to worry
4571 about changing the DT_RELA entry. */
4572 if (htab
->elf
.srelplt
!= NULL
)
4574 s
= htab
->elf
.srelplt
->output_section
;
4575 dyn
.d_un
.d_val
-= s
->size
;
4579 case DT_TLSDESC_PLT
:
4581 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4582 + htab
->tlsdesc_plt
;
4585 case DT_TLSDESC_GOT
:
4587 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4588 + htab
->tlsdesc_got
;
4592 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4595 /* Fill in the special first entry in the procedure linkage table. */
4596 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4598 /* Fill in the first entry in the procedure linkage table. */
4599 memcpy (htab
->elf
.splt
->contents
,
4600 abed
->plt0_entry
, abed
->plt_entry_size
);
4601 /* Add offset for pushq GOT+8(%rip), since the instruction
4602 uses 6 bytes subtract this value. */
4603 bfd_put_32 (output_bfd
,
4604 (htab
->elf
.sgotplt
->output_section
->vma
4605 + htab
->elf
.sgotplt
->output_offset
4607 - htab
->elf
.splt
->output_section
->vma
4608 - htab
->elf
.splt
->output_offset
4610 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
4611 /* Add offset for the PC-relative instruction accessing GOT+16,
4612 subtracting the offset to the end of that instruction. */
4613 bfd_put_32 (output_bfd
,
4614 (htab
->elf
.sgotplt
->output_section
->vma
4615 + htab
->elf
.sgotplt
->output_offset
4617 - htab
->elf
.splt
->output_section
->vma
4618 - htab
->elf
.splt
->output_offset
4619 - abed
->plt0_got2_insn_end
),
4620 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
4622 elf_section_data (htab
->elf
.splt
->output_section
)
4623 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
4625 if (htab
->tlsdesc_plt
)
4627 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4628 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4630 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4631 abed
->plt0_entry
, abed
->plt_entry_size
);
4633 /* Add offset for pushq GOT+8(%rip), since the
4634 instruction uses 6 bytes subtract this value. */
4635 bfd_put_32 (output_bfd
,
4636 (htab
->elf
.sgotplt
->output_section
->vma
4637 + htab
->elf
.sgotplt
->output_offset
4639 - htab
->elf
.splt
->output_section
->vma
4640 - htab
->elf
.splt
->output_offset
4643 htab
->elf
.splt
->contents
4644 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
4645 /* Add offset for the PC-relative instruction accessing GOT+TDG,
4646 where TGD stands for htab->tlsdesc_got, subtracting the offset
4647 to the end of that instruction. */
4648 bfd_put_32 (output_bfd
,
4649 (htab
->elf
.sgot
->output_section
->vma
4650 + htab
->elf
.sgot
->output_offset
4652 - htab
->elf
.splt
->output_section
->vma
4653 - htab
->elf
.splt
->output_offset
4655 - abed
->plt0_got2_insn_end
),
4656 htab
->elf
.splt
->contents
4657 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
4662 if (htab
->elf
.sgotplt
)
4664 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4666 (*_bfd_error_handler
)
4667 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4671 /* Fill in the first three entries in the global offset table. */
4672 if (htab
->elf
.sgotplt
->size
> 0)
4674 /* Set the first entry in the global offset table to the address of
4675 the dynamic section. */
4677 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4679 bfd_put_64 (output_bfd
,
4680 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4681 htab
->elf
.sgotplt
->contents
);
4682 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4683 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4684 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4687 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4691 /* Adjust .eh_frame for .plt section. */
4692 if (htab
->plt_eh_frame
!= NULL
)
4694 if (htab
->elf
.splt
!= NULL
4695 && htab
->elf
.splt
->size
!= 0
4696 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4697 && htab
->elf
.splt
->output_section
!= NULL
4698 && htab
->plt_eh_frame
->output_section
!= NULL
)
4700 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4701 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4702 + htab
->plt_eh_frame
->output_offset
4703 + PLT_FDE_START_OFFSET
;
4704 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4705 htab
->plt_eh_frame
->contents
4706 + PLT_FDE_START_OFFSET
);
4708 if (htab
->plt_eh_frame
->sec_info_type
4709 == ELF_INFO_TYPE_EH_FRAME
)
4711 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4713 htab
->plt_eh_frame
->contents
))
4718 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4719 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4722 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4723 htab_traverse (htab
->loc_hash_table
,
4724 elf_x86_64_finish_local_dynamic_symbol
,
4730 /* Return address for Ith PLT stub in section PLT, for relocation REL
4731 or (bfd_vma) -1 if it should not be included. */
4734 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4735 const arelent
*rel ATTRIBUTE_UNUSED
)
4737 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4740 /* Handle an x86-64 specific section when reading an object file. This
4741 is called when elfcode.h finds a section with an unknown type. */
4744 elf_x86_64_section_from_shdr (bfd
*abfd
,
4745 Elf_Internal_Shdr
*hdr
,
4749 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4752 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4758 /* Hook called by the linker routine which adds symbols from an object
4759 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4763 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4764 struct bfd_link_info
*info
,
4765 Elf_Internal_Sym
*sym
,
4766 const char **namep ATTRIBUTE_UNUSED
,
4767 flagword
*flagsp ATTRIBUTE_UNUSED
,
4773 switch (sym
->st_shndx
)
4775 case SHN_X86_64_LCOMMON
:
4776 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4779 lcomm
= bfd_make_section_with_flags (abfd
,
4783 | SEC_LINKER_CREATED
));
4786 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4789 *valp
= sym
->st_size
;
4793 if ((abfd
->flags
& DYNAMIC
) == 0
4794 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4795 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4796 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4802 /* Given a BFD section, try to locate the corresponding ELF section
4806 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4807 asection
*sec
, int *index_return
)
4809 if (sec
== &_bfd_elf_large_com_section
)
4811 *index_return
= SHN_X86_64_LCOMMON
;
4817 /* Process a symbol. */
4820 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4823 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4825 switch (elfsym
->internal_elf_sym
.st_shndx
)
4827 case SHN_X86_64_LCOMMON
:
4828 asym
->section
= &_bfd_elf_large_com_section
;
4829 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4830 /* Common symbol doesn't set BSF_GLOBAL. */
4831 asym
->flags
&= ~BSF_GLOBAL
;
4837 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4839 return (sym
->st_shndx
== SHN_COMMON
4840 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4844 elf_x86_64_common_section_index (asection
*sec
)
4846 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4849 return SHN_X86_64_LCOMMON
;
4853 elf_x86_64_common_section (asection
*sec
)
4855 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4856 return bfd_com_section_ptr
;
4858 return &_bfd_elf_large_com_section
;
4862 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4863 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4864 struct elf_link_hash_entry
*h
,
4865 Elf_Internal_Sym
*sym
,
4867 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4868 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4869 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4870 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4871 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4872 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4873 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4874 bfd_boolean
*newdef
,
4875 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4876 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4877 bfd
*abfd ATTRIBUTE_UNUSED
,
4879 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4880 bfd_boolean
*olddef
,
4881 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4882 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4886 /* A normal common symbol and a large common symbol result in a
4887 normal common symbol. We turn the large common symbol into a
4890 && h
->root
.type
== bfd_link_hash_common
4892 && bfd_is_com_section (*sec
)
4895 if (sym
->st_shndx
== SHN_COMMON
4896 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4898 h
->root
.u
.c
.p
->section
4899 = bfd_make_section_old_way (oldbfd
, "COMMON");
4900 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4902 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4903 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4904 *psec
= *sec
= bfd_com_section_ptr
;
4911 elf_x86_64_additional_program_headers (bfd
*abfd
,
4912 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4917 /* Check to see if we need a large readonly segment. */
4918 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4919 if (s
&& (s
->flags
& SEC_LOAD
))
4922 /* Check to see if we need a large data segment. Since .lbss sections
4923 is placed right after the .bss section, there should be no need for
4924 a large data segment just because of .lbss. */
4925 s
= bfd_get_section_by_name (abfd
, ".ldata");
4926 if (s
&& (s
->flags
& SEC_LOAD
))
4932 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4935 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4937 if (h
->plt
.offset
!= (bfd_vma
) -1
4939 && !h
->pointer_equality_needed
)
4942 return _bfd_elf_hash_symbol (h
);
4945 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4948 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4949 const bfd_target
*output
)
4951 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4952 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4953 && _bfd_elf_relocs_compatible (input
, output
));
4956 static const struct bfd_elf_special_section
4957 elf_x86_64_special_sections
[]=
4959 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4960 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4961 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4962 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4963 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4964 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4965 { NULL
, 0, 0, 0, 0 }
4968 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4969 #define TARGET_LITTLE_NAME "elf64-x86-64"
4970 #define ELF_ARCH bfd_arch_i386
4971 #define ELF_TARGET_ID X86_64_ELF_DATA
4972 #define ELF_MACHINE_CODE EM_X86_64
4973 #define ELF_MAXPAGESIZE 0x200000
4974 #define ELF_MINPAGESIZE 0x1000
4975 #define ELF_COMMONPAGESIZE 0x1000
4977 #define elf_backend_can_gc_sections 1
4978 #define elf_backend_can_refcount 1
4979 #define elf_backend_want_got_plt 1
4980 #define elf_backend_plt_readonly 1
4981 #define elf_backend_want_plt_sym 0
4982 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4983 #define elf_backend_rela_normal 1
4984 #define elf_backend_plt_alignment 4
4986 #define elf_info_to_howto elf_x86_64_info_to_howto
4988 #define bfd_elf64_bfd_link_hash_table_create \
4989 elf_x86_64_link_hash_table_create
4990 #define bfd_elf64_bfd_link_hash_table_free \
4991 elf_x86_64_link_hash_table_free
4992 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4993 #define bfd_elf64_bfd_reloc_name_lookup \
4994 elf_x86_64_reloc_name_lookup
4996 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4997 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4998 #define elf_backend_check_relocs elf_x86_64_check_relocs
4999 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
5000 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
5001 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5002 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5003 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
5004 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
5005 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5006 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5008 #define elf_backend_write_core_note elf_x86_64_write_core_note
5010 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5011 #define elf_backend_relocate_section elf_x86_64_relocate_section
5012 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
5013 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5014 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5015 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
5016 #define elf_backend_object_p elf64_x86_64_elf_object_p
5017 #define bfd_elf64_mkobject elf_x86_64_mkobject
5019 #define elf_backend_section_from_shdr \
5020 elf_x86_64_section_from_shdr
5022 #define elf_backend_section_from_bfd_section \
5023 elf_x86_64_elf_section_from_bfd_section
5024 #define elf_backend_add_symbol_hook \
5025 elf_x86_64_add_symbol_hook
5026 #define elf_backend_symbol_processing \
5027 elf_x86_64_symbol_processing
5028 #define elf_backend_common_section_index \
5029 elf_x86_64_common_section_index
5030 #define elf_backend_common_section \
5031 elf_x86_64_common_section
5032 #define elf_backend_common_definition \
5033 elf_x86_64_common_definition
5034 #define elf_backend_merge_symbol \
5035 elf_x86_64_merge_symbol
5036 #define elf_backend_special_sections \
5037 elf_x86_64_special_sections
5038 #define elf_backend_additional_program_headers \
5039 elf_x86_64_additional_program_headers
5040 #define elf_backend_hash_symbol \
5041 elf_x86_64_hash_symbol
5043 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5045 #include "elf64-target.h"
5047 /* FreeBSD support. */
5049 #undef TARGET_LITTLE_SYM
5050 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
5051 #undef TARGET_LITTLE_NAME
5052 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5055 #define ELF_OSABI ELFOSABI_FREEBSD
5058 #define elf64_bed elf64_x86_64_fbsd_bed
5060 #include "elf64-target.h"
5062 /* Solaris 2 support. */
5064 #undef TARGET_LITTLE_SYM
5065 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
5066 #undef TARGET_LITTLE_NAME
5067 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5069 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5070 objects won't be recognized. */
5074 #define elf64_bed elf64_x86_64_sol2_bed
5076 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5078 #undef elf_backend_static_tls_alignment
5079 #define elf_backend_static_tls_alignment 16
5081 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5083 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5085 #undef elf_backend_want_plt_sym
5086 #define elf_backend_want_plt_sym 1
5088 #include "elf64-target.h"
5090 /* Intel L1OM support. */
5093 elf64_l1om_elf_object_p (bfd
*abfd
)
5095 /* Set the right machine number for an L1OM elf64 file. */
5096 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5100 #undef TARGET_LITTLE_SYM
5101 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5102 #undef TARGET_LITTLE_NAME
5103 #define TARGET_LITTLE_NAME "elf64-l1om"
5105 #define ELF_ARCH bfd_arch_l1om
5107 #undef ELF_MACHINE_CODE
5108 #define ELF_MACHINE_CODE EM_L1OM
5113 #define elf64_bed elf64_l1om_bed
5115 #undef elf_backend_object_p
5116 #define elf_backend_object_p elf64_l1om_elf_object_p
5118 #undef elf_backend_static_tls_alignment
5120 #undef elf_backend_want_plt_sym
5121 #define elf_backend_want_plt_sym 0
5123 #include "elf64-target.h"
5125 /* FreeBSD L1OM support. */
5127 #undef TARGET_LITTLE_SYM
5128 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5129 #undef TARGET_LITTLE_NAME
5130 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5133 #define ELF_OSABI ELFOSABI_FREEBSD
5136 #define elf64_bed elf64_l1om_fbsd_bed
5138 #include "elf64-target.h"
5140 /* Intel K1OM support. */
5143 elf64_k1om_elf_object_p (bfd
*abfd
)
5145 /* Set the right machine number for an K1OM elf64 file. */
5146 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5150 #undef TARGET_LITTLE_SYM
5151 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5152 #undef TARGET_LITTLE_NAME
5153 #define TARGET_LITTLE_NAME "elf64-k1om"
5155 #define ELF_ARCH bfd_arch_k1om
5157 #undef ELF_MACHINE_CODE
5158 #define ELF_MACHINE_CODE EM_K1OM
5163 #define elf64_bed elf64_k1om_bed
5165 #undef elf_backend_object_p
5166 #define elf_backend_object_p elf64_k1om_elf_object_p
5168 #undef elf_backend_static_tls_alignment
5170 #undef elf_backend_want_plt_sym
5171 #define elf_backend_want_plt_sym 0
5173 #include "elf64-target.h"
5175 /* FreeBSD K1OM support. */
5177 #undef TARGET_LITTLE_SYM
5178 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5179 #undef TARGET_LITTLE_NAME
5180 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5183 #define ELF_OSABI ELFOSABI_FREEBSD
5186 #define elf64_bed elf64_k1om_fbsd_bed
5188 #include "elf64-target.h"
5190 /* 32bit x86-64 support. */
5193 elf32_x86_64_elf_object_p (bfd
*abfd
)
5195 /* Set the right machine number for an x86-64 elf32 file. */
5196 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
5200 #undef TARGET_LITTLE_SYM
5201 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5202 #undef TARGET_LITTLE_NAME
5203 #define TARGET_LITTLE_NAME "elf32-x86-64"
5206 #define ELF_ARCH bfd_arch_i386
5208 #undef ELF_MACHINE_CODE
5209 #define ELF_MACHINE_CODE EM_X86_64
5211 #define bfd_elf32_bfd_link_hash_table_create \
5212 elf_x86_64_link_hash_table_create
5213 #define bfd_elf32_bfd_link_hash_table_free \
5214 elf_x86_64_link_hash_table_free
5215 #define bfd_elf32_bfd_reloc_type_lookup \
5216 elf_x86_64_reloc_type_lookup
5217 #define bfd_elf32_bfd_reloc_name_lookup \
5218 elf_x86_64_reloc_name_lookup
5219 #define bfd_elf32_mkobject \
5224 #undef elf_backend_object_p
5225 #define elf_backend_object_p \
5226 elf32_x86_64_elf_object_p
5228 #undef elf_backend_bfd_from_remote_memory
5229 #define elf_backend_bfd_from_remote_memory \
5230 _bfd_elf32_bfd_from_remote_memory
5232 #undef elf_backend_size_info
5233 #define elf_backend_size_info \
5234 _bfd_elf32_size_info
5236 #include "elf32-target.h"