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 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
986 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
987 flags
| SEC_READONLY
);
988 if (htab
->plt_eh_frame
== NULL
989 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
992 htab
->plt_eh_frame
->size
= sizeof (elf_x86_64_eh_frame_plt
);
993 htab
->plt_eh_frame
->contents
994 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
995 memcpy (htab
->plt_eh_frame
->contents
, elf_x86_64_eh_frame_plt
,
996 sizeof (elf_x86_64_eh_frame_plt
));
1001 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1004 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
1005 struct elf_link_hash_entry
*dir
,
1006 struct elf_link_hash_entry
*ind
)
1008 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
1010 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
1011 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
1013 if (eind
->dyn_relocs
!= NULL
)
1015 if (edir
->dyn_relocs
!= NULL
)
1017 struct elf_dyn_relocs
**pp
;
1018 struct elf_dyn_relocs
*p
;
1020 /* Add reloc counts against the indirect sym to the direct sym
1021 list. Merge any entries against the same section. */
1022 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1024 struct elf_dyn_relocs
*q
;
1026 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1027 if (q
->sec
== p
->sec
)
1029 q
->pc_count
+= p
->pc_count
;
1030 q
->count
+= p
->count
;
1037 *pp
= edir
->dyn_relocs
;
1040 edir
->dyn_relocs
= eind
->dyn_relocs
;
1041 eind
->dyn_relocs
= NULL
;
1044 if (ind
->root
.type
== bfd_link_hash_indirect
1045 && dir
->got
.refcount
<= 0)
1047 edir
->tls_type
= eind
->tls_type
;
1048 eind
->tls_type
= GOT_UNKNOWN
;
1051 if (ELIMINATE_COPY_RELOCS
1052 && ind
->root
.type
!= bfd_link_hash_indirect
1053 && dir
->dynamic_adjusted
)
1055 /* If called to transfer flags for a weakdef during processing
1056 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1057 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1058 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1059 dir
->ref_regular
|= ind
->ref_regular
;
1060 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1061 dir
->needs_plt
|= ind
->needs_plt
;
1062 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1065 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1069 elf64_x86_64_elf_object_p (bfd
*abfd
)
1071 /* Set the right machine number for an x86-64 elf64 file. */
1072 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1076 /* Return TRUE if the TLS access code sequence support transition
1080 elf_x86_64_check_tls_transition (bfd
*abfd
,
1081 struct bfd_link_info
*info
,
1084 Elf_Internal_Shdr
*symtab_hdr
,
1085 struct elf_link_hash_entry
**sym_hashes
,
1086 unsigned int r_type
,
1087 const Elf_Internal_Rela
*rel
,
1088 const Elf_Internal_Rela
*relend
)
1091 unsigned long r_symndx
;
1092 struct elf_link_hash_entry
*h
;
1094 struct elf_x86_64_link_hash_table
*htab
;
1096 /* Get the section contents. */
1097 if (contents
== NULL
)
1099 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1100 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1103 /* FIXME: How to better handle error condition? */
1104 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1107 /* Cache the section contents for elf_link_input_bfd. */
1108 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1112 htab
= elf_x86_64_hash_table (info
);
1113 offset
= rel
->r_offset
;
1116 case R_X86_64_TLSGD
:
1117 case R_X86_64_TLSLD
:
1118 if ((rel
+ 1) >= relend
)
1121 if (r_type
== R_X86_64_TLSGD
)
1123 /* Check transition from GD access model. For 64bit, only
1124 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1125 .word 0x6666; rex64; call __tls_get_addr
1126 can transit to different access model. For 32bit, only
1127 leaq foo@tlsgd(%rip), %rdi
1128 .word 0x6666; rex64; call __tls_get_addr
1129 can transit to different access model. */
1131 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1132 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1134 if ((offset
+ 12) > sec
->size
1135 || memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1138 if (ABI_64_P (abfd
))
1141 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1147 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1153 /* Check transition from LD access model. Only
1154 leaq foo@tlsld(%rip), %rdi;
1156 can transit to different access model. */
1158 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1160 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1163 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0
1164 || 0xe8 != *(contents
+ offset
+ 4))
1168 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1169 if (r_symndx
< symtab_hdr
->sh_info
)
1172 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1173 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1174 may be versioned. */
1176 && h
->root
.root
.string
!= NULL
1177 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1178 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
1179 && (strncmp (h
->root
.root
.string
,
1180 "__tls_get_addr", 14) == 0));
1182 case R_X86_64_GOTTPOFF
:
1183 /* Check transition from IE access model:
1184 mov foo@gottpoff(%rip), %reg
1185 add foo@gottpoff(%rip), %reg
1188 /* Check REX prefix first. */
1189 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1191 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1192 if (val
!= 0x48 && val
!= 0x4c)
1194 /* X32 may have 0x44 REX prefix or no REX prefix. */
1195 if (ABI_64_P (abfd
))
1201 /* X32 may not have any REX prefix. */
1202 if (ABI_64_P (abfd
))
1204 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1208 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1209 if (val
!= 0x8b && val
!= 0x03)
1212 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1213 return (val
& 0xc7) == 5;
1215 case R_X86_64_GOTPC32_TLSDESC
:
1216 /* Check transition from GDesc access model:
1217 leaq x@tlsdesc(%rip), %rax
1219 Make sure it's a leaq adding rip to a 32-bit offset
1220 into any register, although it's probably almost always
1223 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1226 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1227 if ((val
& 0xfb) != 0x48)
1230 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1233 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1234 return (val
& 0xc7) == 0x05;
1236 case R_X86_64_TLSDESC_CALL
:
1237 /* Check transition from GDesc access model:
1238 call *x@tlsdesc(%rax)
1240 if (offset
+ 2 <= sec
->size
)
1242 /* Make sure that it's a call *x@tlsdesc(%rax). */
1243 static const unsigned char call
[] = { 0xff, 0x10 };
1244 return memcmp (contents
+ offset
, call
, 2) == 0;
1254 /* Return TRUE if the TLS access transition is OK or no transition
1255 will be performed. Update R_TYPE if there is a transition. */
1258 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1259 asection
*sec
, bfd_byte
*contents
,
1260 Elf_Internal_Shdr
*symtab_hdr
,
1261 struct elf_link_hash_entry
**sym_hashes
,
1262 unsigned int *r_type
, int tls_type
,
1263 const Elf_Internal_Rela
*rel
,
1264 const Elf_Internal_Rela
*relend
,
1265 struct elf_link_hash_entry
*h
,
1266 unsigned long r_symndx
)
1268 unsigned int from_type
= *r_type
;
1269 unsigned int to_type
= from_type
;
1270 bfd_boolean check
= TRUE
;
1272 /* Skip TLS transition for functions. */
1274 && (h
->type
== STT_FUNC
1275 || h
->type
== STT_GNU_IFUNC
))
1280 case R_X86_64_TLSGD
:
1281 case R_X86_64_GOTPC32_TLSDESC
:
1282 case R_X86_64_TLSDESC_CALL
:
1283 case R_X86_64_GOTTPOFF
:
1284 if (info
->executable
)
1287 to_type
= R_X86_64_TPOFF32
;
1289 to_type
= R_X86_64_GOTTPOFF
;
1292 /* When we are called from elf_x86_64_relocate_section,
1293 CONTENTS isn't NULL and there may be additional transitions
1294 based on TLS_TYPE. */
1295 if (contents
!= NULL
)
1297 unsigned int new_to_type
= to_type
;
1299 if (info
->executable
1302 && tls_type
== GOT_TLS_IE
)
1303 new_to_type
= R_X86_64_TPOFF32
;
1305 if (to_type
== R_X86_64_TLSGD
1306 || to_type
== R_X86_64_GOTPC32_TLSDESC
1307 || to_type
== R_X86_64_TLSDESC_CALL
)
1309 if (tls_type
== GOT_TLS_IE
)
1310 new_to_type
= R_X86_64_GOTTPOFF
;
1313 /* We checked the transition before when we were called from
1314 elf_x86_64_check_relocs. We only want to check the new
1315 transition which hasn't been checked before. */
1316 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1317 to_type
= new_to_type
;
1322 case R_X86_64_TLSLD
:
1323 if (info
->executable
)
1324 to_type
= R_X86_64_TPOFF32
;
1331 /* Return TRUE if there is no transition. */
1332 if (from_type
== to_type
)
1335 /* Check if the transition can be performed. */
1337 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1338 symtab_hdr
, sym_hashes
,
1339 from_type
, rel
, relend
))
1341 reloc_howto_type
*from
, *to
;
1344 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1345 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1348 name
= h
->root
.root
.string
;
1351 struct elf_x86_64_link_hash_table
*htab
;
1353 htab
= elf_x86_64_hash_table (info
);
1358 Elf_Internal_Sym
*isym
;
1360 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1362 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1366 (*_bfd_error_handler
)
1367 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1368 "in section `%A' failed"),
1369 abfd
, sec
, from
->name
, to
->name
, name
,
1370 (unsigned long) rel
->r_offset
);
1371 bfd_set_error (bfd_error_bad_value
);
1379 /* Look through the relocs for a section during the first phase, and
1380 calculate needed space in the global offset table, procedure
1381 linkage table, and dynamic reloc sections. */
1384 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1386 const Elf_Internal_Rela
*relocs
)
1388 struct elf_x86_64_link_hash_table
*htab
;
1389 Elf_Internal_Shdr
*symtab_hdr
;
1390 struct elf_link_hash_entry
**sym_hashes
;
1391 const Elf_Internal_Rela
*rel
;
1392 const Elf_Internal_Rela
*rel_end
;
1395 if (info
->relocatable
)
1398 BFD_ASSERT (is_x86_64_elf (abfd
));
1400 htab
= elf_x86_64_hash_table (info
);
1404 symtab_hdr
= &elf_symtab_hdr (abfd
);
1405 sym_hashes
= elf_sym_hashes (abfd
);
1409 rel_end
= relocs
+ sec
->reloc_count
;
1410 for (rel
= relocs
; rel
< rel_end
; rel
++)
1412 unsigned int r_type
;
1413 unsigned long r_symndx
;
1414 struct elf_link_hash_entry
*h
;
1415 Elf_Internal_Sym
*isym
;
1418 r_symndx
= htab
->r_sym (rel
->r_info
);
1419 r_type
= ELF32_R_TYPE (rel
->r_info
);
1421 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1423 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1428 if (r_symndx
< symtab_hdr
->sh_info
)
1430 /* A local symbol. */
1431 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1436 /* Check relocation against local STT_GNU_IFUNC symbol. */
1437 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1439 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1444 /* Fake a STT_GNU_IFUNC symbol. */
1445 h
->type
= STT_GNU_IFUNC
;
1448 h
->forced_local
= 1;
1449 h
->root
.type
= bfd_link_hash_defined
;
1457 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1458 while (h
->root
.type
== bfd_link_hash_indirect
1459 || h
->root
.type
== bfd_link_hash_warning
)
1460 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1463 /* Check invalid x32 relocations. */
1464 if (!ABI_64_P (abfd
))
1470 case R_X86_64_DTPOFF64
:
1471 case R_X86_64_TPOFF64
:
1473 case R_X86_64_GOTOFF64
:
1474 case R_X86_64_GOT64
:
1475 case R_X86_64_GOTPCREL64
:
1476 case R_X86_64_GOTPC64
:
1477 case R_X86_64_GOTPLT64
:
1478 case R_X86_64_PLTOFF64
:
1481 name
= h
->root
.root
.string
;
1483 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1485 (*_bfd_error_handler
)
1486 (_("%B: relocation %s against symbol `%s' isn't "
1487 "supported in x32 mode"), abfd
,
1488 x86_64_elf_howto_table
[r_type
].name
, name
);
1489 bfd_set_error (bfd_error_bad_value
);
1497 /* Create the ifunc sections for static executables. If we
1498 never see an indirect function symbol nor we are building
1499 a static executable, those sections will be empty and
1500 won't appear in output. */
1511 case R_X86_64_PLT32
:
1512 case R_X86_64_GOTPCREL
:
1513 case R_X86_64_GOTPCREL64
:
1514 if (htab
->elf
.dynobj
== NULL
)
1515 htab
->elf
.dynobj
= abfd
;
1516 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1521 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1522 it here if it is defined in a non-shared object. */
1523 if (h
->type
== STT_GNU_IFUNC
1526 /* It is referenced by a non-shared object. */
1530 /* STT_GNU_IFUNC symbol must go through PLT. */
1531 h
->plt
.refcount
+= 1;
1533 /* STT_GNU_IFUNC needs dynamic sections. */
1534 if (htab
->elf
.dynobj
== NULL
)
1535 htab
->elf
.dynobj
= abfd
;
1540 if (h
->root
.root
.string
)
1541 name
= h
->root
.root
.string
;
1543 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1545 (*_bfd_error_handler
)
1546 (_("%B: relocation %s against STT_GNU_IFUNC "
1547 "symbol `%s' isn't handled by %s"), abfd
,
1548 x86_64_elf_howto_table
[r_type
].name
,
1549 name
, __FUNCTION__
);
1550 bfd_set_error (bfd_error_bad_value
);
1554 if (ABI_64_P (abfd
))
1558 h
->pointer_equality_needed
= 1;
1561 /* We must copy these reloc types into the output
1562 file. Create a reloc section in dynobj and
1563 make room for this reloc. */
1564 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1565 (abfd
, info
, sec
, sreloc
,
1566 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1577 if (r_type
!= R_X86_64_PC32
1578 && r_type
!= R_X86_64_PC64
)
1579 h
->pointer_equality_needed
= 1;
1582 case R_X86_64_PLT32
:
1585 case R_X86_64_GOTPCREL
:
1586 case R_X86_64_GOTPCREL64
:
1587 h
->got
.refcount
+= 1;
1588 if (htab
->elf
.sgot
== NULL
1589 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1599 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1600 symtab_hdr
, sym_hashes
,
1601 &r_type
, GOT_UNKNOWN
,
1602 rel
, rel_end
, h
, r_symndx
))
1607 case R_X86_64_TLSLD
:
1608 htab
->tls_ld_got
.refcount
+= 1;
1611 case R_X86_64_TPOFF32
:
1612 if (!info
->executable
&& ABI_64_P (abfd
))
1615 name
= h
->root
.root
.string
;
1617 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1619 (*_bfd_error_handler
)
1620 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1622 x86_64_elf_howto_table
[r_type
].name
, name
);
1623 bfd_set_error (bfd_error_bad_value
);
1628 case R_X86_64_GOTTPOFF
:
1629 if (!info
->executable
)
1630 info
->flags
|= DF_STATIC_TLS
;
1633 case R_X86_64_GOT32
:
1634 case R_X86_64_GOTPCREL
:
1635 case R_X86_64_TLSGD
:
1636 case R_X86_64_GOT64
:
1637 case R_X86_64_GOTPCREL64
:
1638 case R_X86_64_GOTPLT64
:
1639 case R_X86_64_GOTPC32_TLSDESC
:
1640 case R_X86_64_TLSDESC_CALL
:
1641 /* This symbol requires a global offset table entry. */
1643 int tls_type
, old_tls_type
;
1647 default: tls_type
= GOT_NORMAL
; break;
1648 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1649 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1650 case R_X86_64_GOTPC32_TLSDESC
:
1651 case R_X86_64_TLSDESC_CALL
:
1652 tls_type
= GOT_TLS_GDESC
; break;
1657 if (r_type
== R_X86_64_GOTPLT64
)
1659 /* This relocation indicates that we also need
1660 a PLT entry, as this is a function. We don't need
1661 a PLT entry for local symbols. */
1663 h
->plt
.refcount
+= 1;
1665 h
->got
.refcount
+= 1;
1666 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1670 bfd_signed_vma
*local_got_refcounts
;
1672 /* This is a global offset table entry for a local symbol. */
1673 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1674 if (local_got_refcounts
== NULL
)
1678 size
= symtab_hdr
->sh_info
;
1679 size
*= sizeof (bfd_signed_vma
)
1680 + sizeof (bfd_vma
) + sizeof (char);
1681 local_got_refcounts
= ((bfd_signed_vma
*)
1682 bfd_zalloc (abfd
, size
));
1683 if (local_got_refcounts
== NULL
)
1685 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1686 elf_x86_64_local_tlsdesc_gotent (abfd
)
1687 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1688 elf_x86_64_local_got_tls_type (abfd
)
1689 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1691 local_got_refcounts
[r_symndx
] += 1;
1693 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1696 /* If a TLS symbol is accessed using IE at least once,
1697 there is no point to use dynamic model for it. */
1698 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1699 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1700 || tls_type
!= GOT_TLS_IE
))
1702 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1703 tls_type
= old_tls_type
;
1704 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1705 && GOT_TLS_GD_ANY_P (tls_type
))
1706 tls_type
|= old_tls_type
;
1710 name
= h
->root
.root
.string
;
1712 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1714 (*_bfd_error_handler
)
1715 (_("%B: '%s' accessed both as normal and thread local symbol"),
1721 if (old_tls_type
!= tls_type
)
1724 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1726 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1731 case R_X86_64_GOTOFF64
:
1732 case R_X86_64_GOTPC32
:
1733 case R_X86_64_GOTPC64
:
1735 if (htab
->elf
.sgot
== NULL
)
1737 if (htab
->elf
.dynobj
== NULL
)
1738 htab
->elf
.dynobj
= abfd
;
1739 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1745 case R_X86_64_PLT32
:
1746 /* This symbol requires a procedure linkage table entry. We
1747 actually build the entry in adjust_dynamic_symbol,
1748 because this might be a case of linking PIC code which is
1749 never referenced by a dynamic object, in which case we
1750 don't need to generate a procedure linkage table entry
1753 /* If this is a local symbol, we resolve it directly without
1754 creating a procedure linkage table entry. */
1759 h
->plt
.refcount
+= 1;
1762 case R_X86_64_PLTOFF64
:
1763 /* This tries to form the 'address' of a function relative
1764 to GOT. For global symbols we need a PLT entry. */
1768 h
->plt
.refcount
+= 1;
1773 if (!ABI_64_P (abfd
))
1778 /* Let's help debug shared library creation. These relocs
1779 cannot be used in shared libs. Don't error out for
1780 sections we don't care about, such as debug sections or
1781 non-constant sections. */
1783 && (sec
->flags
& SEC_ALLOC
) != 0
1784 && (sec
->flags
& SEC_READONLY
) != 0)
1787 name
= h
->root
.root
.string
;
1789 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1790 (*_bfd_error_handler
)
1791 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1792 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1793 bfd_set_error (bfd_error_bad_value
);
1804 if (h
!= NULL
&& info
->executable
)
1806 /* If this reloc is in a read-only section, we might
1807 need a copy reloc. We can't check reliably at this
1808 stage whether the section is read-only, as input
1809 sections have not yet been mapped to output sections.
1810 Tentatively set the flag for now, and correct in
1811 adjust_dynamic_symbol. */
1814 /* We may need a .plt entry if the function this reloc
1815 refers to is in a shared lib. */
1816 h
->plt
.refcount
+= 1;
1817 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1818 h
->pointer_equality_needed
= 1;
1821 /* If we are creating a shared library, and this is a reloc
1822 against a global symbol, or a non PC relative reloc
1823 against a local symbol, then we need to copy the reloc
1824 into the shared library. However, if we are linking with
1825 -Bsymbolic, we do not need to copy a reloc against a
1826 global symbol which is defined in an object we are
1827 including in the link (i.e., DEF_REGULAR is set). At
1828 this point we have not seen all the input files, so it is
1829 possible that DEF_REGULAR is not set now but will be set
1830 later (it is never cleared). In case of a weak definition,
1831 DEF_REGULAR may be cleared later by a strong definition in
1832 a shared library. We account for that possibility below by
1833 storing information in the relocs_copied field of the hash
1834 table entry. A similar situation occurs when creating
1835 shared libraries and symbol visibility changes render the
1838 If on the other hand, we are creating an executable, we
1839 may need to keep relocations for symbols satisfied by a
1840 dynamic library if we manage to avoid copy relocs for the
1843 && (sec
->flags
& SEC_ALLOC
) != 0
1844 && (! IS_X86_64_PCREL_TYPE (r_type
)
1846 && (! SYMBOLIC_BIND (info
, h
)
1847 || h
->root
.type
== bfd_link_hash_defweak
1848 || !h
->def_regular
))))
1849 || (ELIMINATE_COPY_RELOCS
1851 && (sec
->flags
& SEC_ALLOC
) != 0
1853 && (h
->root
.type
== bfd_link_hash_defweak
1854 || !h
->def_regular
)))
1856 struct elf_dyn_relocs
*p
;
1857 struct elf_dyn_relocs
**head
;
1859 /* We must copy these reloc types into the output file.
1860 Create a reloc section in dynobj and make room for
1864 if (htab
->elf
.dynobj
== NULL
)
1865 htab
->elf
.dynobj
= abfd
;
1867 sreloc
= _bfd_elf_make_dynamic_reloc_section
1868 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1869 abfd
, /*rela?*/ TRUE
);
1875 /* If this is a global symbol, we count the number of
1876 relocations we need for this symbol. */
1879 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1883 /* Track dynamic relocs needed for local syms too.
1884 We really need local syms available to do this
1889 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1894 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1898 /* Beware of type punned pointers vs strict aliasing
1900 vpp
= &(elf_section_data (s
)->local_dynrel
);
1901 head
= (struct elf_dyn_relocs
**)vpp
;
1905 if (p
== NULL
|| p
->sec
!= sec
)
1907 bfd_size_type amt
= sizeof *p
;
1909 p
= ((struct elf_dyn_relocs
*)
1910 bfd_alloc (htab
->elf
.dynobj
, amt
));
1921 if (IS_X86_64_PCREL_TYPE (r_type
))
1926 /* This relocation describes the C++ object vtable hierarchy.
1927 Reconstruct it for later use during GC. */
1928 case R_X86_64_GNU_VTINHERIT
:
1929 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1933 /* This relocation describes which C++ vtable entries are actually
1934 used. Record for later use during GC. */
1935 case R_X86_64_GNU_VTENTRY
:
1936 BFD_ASSERT (h
!= NULL
);
1938 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1950 /* Return the section that should be marked against GC for a given
1954 elf_x86_64_gc_mark_hook (asection
*sec
,
1955 struct bfd_link_info
*info
,
1956 Elf_Internal_Rela
*rel
,
1957 struct elf_link_hash_entry
*h
,
1958 Elf_Internal_Sym
*sym
)
1961 switch (ELF32_R_TYPE (rel
->r_info
))
1963 case R_X86_64_GNU_VTINHERIT
:
1964 case R_X86_64_GNU_VTENTRY
:
1968 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1971 /* Update the got entry reference counts for the section being removed. */
1974 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1976 const Elf_Internal_Rela
*relocs
)
1978 struct elf_x86_64_link_hash_table
*htab
;
1979 Elf_Internal_Shdr
*symtab_hdr
;
1980 struct elf_link_hash_entry
**sym_hashes
;
1981 bfd_signed_vma
*local_got_refcounts
;
1982 const Elf_Internal_Rela
*rel
, *relend
;
1984 if (info
->relocatable
)
1987 htab
= elf_x86_64_hash_table (info
);
1991 elf_section_data (sec
)->local_dynrel
= NULL
;
1993 symtab_hdr
= &elf_symtab_hdr (abfd
);
1994 sym_hashes
= elf_sym_hashes (abfd
);
1995 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1997 htab
= elf_x86_64_hash_table (info
);
1998 relend
= relocs
+ sec
->reloc_count
;
1999 for (rel
= relocs
; rel
< relend
; rel
++)
2001 unsigned long r_symndx
;
2002 unsigned int r_type
;
2003 struct elf_link_hash_entry
*h
= NULL
;
2005 r_symndx
= htab
->r_sym (rel
->r_info
);
2006 if (r_symndx
>= symtab_hdr
->sh_info
)
2008 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2009 while (h
->root
.type
== bfd_link_hash_indirect
2010 || h
->root
.type
== bfd_link_hash_warning
)
2011 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2015 /* A local symbol. */
2016 Elf_Internal_Sym
*isym
;
2018 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2021 /* Check relocation against local STT_GNU_IFUNC symbol. */
2023 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2025 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
2033 struct elf_x86_64_link_hash_entry
*eh
;
2034 struct elf_dyn_relocs
**pp
;
2035 struct elf_dyn_relocs
*p
;
2037 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2039 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2042 /* Everything must go for SEC. */
2048 r_type
= ELF32_R_TYPE (rel
->r_info
);
2049 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
2050 symtab_hdr
, sym_hashes
,
2051 &r_type
, GOT_UNKNOWN
,
2052 rel
, relend
, h
, r_symndx
))
2057 case R_X86_64_TLSLD
:
2058 if (htab
->tls_ld_got
.refcount
> 0)
2059 htab
->tls_ld_got
.refcount
-= 1;
2062 case R_X86_64_TLSGD
:
2063 case R_X86_64_GOTPC32_TLSDESC
:
2064 case R_X86_64_TLSDESC_CALL
:
2065 case R_X86_64_GOTTPOFF
:
2066 case R_X86_64_GOT32
:
2067 case R_X86_64_GOTPCREL
:
2068 case R_X86_64_GOT64
:
2069 case R_X86_64_GOTPCREL64
:
2070 case R_X86_64_GOTPLT64
:
2073 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2074 h
->plt
.refcount
-= 1;
2075 if (h
->got
.refcount
> 0)
2076 h
->got
.refcount
-= 1;
2077 if (h
->type
== STT_GNU_IFUNC
)
2079 if (h
->plt
.refcount
> 0)
2080 h
->plt
.refcount
-= 1;
2083 else if (local_got_refcounts
!= NULL
)
2085 if (local_got_refcounts
[r_symndx
] > 0)
2086 local_got_refcounts
[r_symndx
] -= 1;
2100 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2104 case R_X86_64_PLT32
:
2105 case R_X86_64_PLTOFF64
:
2108 if (h
->plt
.refcount
> 0)
2109 h
->plt
.refcount
-= 1;
2121 /* Adjust a symbol defined by a dynamic object and referenced by a
2122 regular object. The current definition is in some section of the
2123 dynamic object, but we're not including those sections. We have to
2124 change the definition to something the rest of the link can
2128 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2129 struct elf_link_hash_entry
*h
)
2131 struct elf_x86_64_link_hash_table
*htab
;
2134 /* STT_GNU_IFUNC symbol must go through PLT. */
2135 if (h
->type
== STT_GNU_IFUNC
)
2137 if (h
->plt
.refcount
<= 0)
2139 h
->plt
.offset
= (bfd_vma
) -1;
2145 /* If this is a function, put it in the procedure linkage table. We
2146 will fill in the contents of the procedure linkage table later,
2147 when we know the address of the .got section. */
2148 if (h
->type
== STT_FUNC
2151 if (h
->plt
.refcount
<= 0
2152 || SYMBOL_CALLS_LOCAL (info
, h
)
2153 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2154 && h
->root
.type
== bfd_link_hash_undefweak
))
2156 /* This case can occur if we saw a PLT32 reloc in an input
2157 file, but the symbol was never referred to by a dynamic
2158 object, or if all references were garbage collected. In
2159 such a case, we don't actually need to build a procedure
2160 linkage table, and we can just do a PC32 reloc instead. */
2161 h
->plt
.offset
= (bfd_vma
) -1;
2168 /* It's possible that we incorrectly decided a .plt reloc was
2169 needed for an R_X86_64_PC32 reloc to a non-function sym in
2170 check_relocs. We can't decide accurately between function and
2171 non-function syms in check-relocs; Objects loaded later in
2172 the link may change h->type. So fix it now. */
2173 h
->plt
.offset
= (bfd_vma
) -1;
2175 /* If this is a weak symbol, and there is a real definition, the
2176 processor independent code will have arranged for us to see the
2177 real definition first, and we can just use the same value. */
2178 if (h
->u
.weakdef
!= NULL
)
2180 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2181 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2182 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2183 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2184 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2185 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2189 /* This is a reference to a symbol defined by a dynamic object which
2190 is not a function. */
2192 /* If we are creating a shared library, we must presume that the
2193 only references to the symbol are via the global offset table.
2194 For such cases we need not do anything here; the relocations will
2195 be handled correctly by relocate_section. */
2199 /* If there are no references to this symbol that do not use the
2200 GOT, we don't need to generate a copy reloc. */
2201 if (!h
->non_got_ref
)
2204 /* If -z nocopyreloc was given, we won't generate them either. */
2205 if (info
->nocopyreloc
)
2211 if (ELIMINATE_COPY_RELOCS
)
2213 struct elf_x86_64_link_hash_entry
* eh
;
2214 struct elf_dyn_relocs
*p
;
2216 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2217 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2219 s
= p
->sec
->output_section
;
2220 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2224 /* If we didn't find any dynamic relocs in read-only sections, then
2225 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2233 /* We must allocate the symbol in our .dynbss section, which will
2234 become part of the .bss section of the executable. There will be
2235 an entry for this symbol in the .dynsym section. The dynamic
2236 object will contain position independent code, so all references
2237 from the dynamic object to this symbol will go through the global
2238 offset table. The dynamic linker will use the .dynsym entry to
2239 determine the address it must put in the global offset table, so
2240 both the dynamic object and the regular object will refer to the
2241 same memory location for the variable. */
2243 htab
= elf_x86_64_hash_table (info
);
2247 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2248 to copy the initial value out of the dynamic object and into the
2249 runtime process image. */
2250 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2252 const struct elf_backend_data
*bed
;
2253 bed
= get_elf_backend_data (info
->output_bfd
);
2254 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2260 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2263 /* Allocate space in .plt, .got and associated reloc sections for
2267 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2269 struct bfd_link_info
*info
;
2270 struct elf_x86_64_link_hash_table
*htab
;
2271 struct elf_x86_64_link_hash_entry
*eh
;
2272 struct elf_dyn_relocs
*p
;
2273 const struct elf_backend_data
*bed
;
2274 unsigned int plt_entry_size
;
2276 if (h
->root
.type
== bfd_link_hash_indirect
)
2279 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2281 info
= (struct bfd_link_info
*) inf
;
2282 htab
= elf_x86_64_hash_table (info
);
2285 bed
= get_elf_backend_data (info
->output_bfd
);
2286 plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
2288 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2289 here if it is defined and referenced in a non-shared object. */
2290 if (h
->type
== STT_GNU_IFUNC
2292 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2296 else if (htab
->elf
.dynamic_sections_created
2297 && h
->plt
.refcount
> 0)
2299 /* Make sure this symbol is output as a dynamic symbol.
2300 Undefined weak syms won't yet be marked as dynamic. */
2301 if (h
->dynindx
== -1
2302 && !h
->forced_local
)
2304 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2309 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2311 asection
*s
= htab
->elf
.splt
;
2313 /* If this is the first .plt entry, make room for the special
2316 s
->size
+= plt_entry_size
;
2318 h
->plt
.offset
= s
->size
;
2320 /* If this symbol is not defined in a regular file, and we are
2321 not generating a shared library, then set the symbol to this
2322 location in the .plt. This is required to make function
2323 pointers compare as equal between the normal executable and
2324 the shared library. */
2328 h
->root
.u
.def
.section
= s
;
2329 h
->root
.u
.def
.value
= h
->plt
.offset
;
2332 /* Make room for this entry. */
2333 s
->size
+= plt_entry_size
;
2335 /* We also need to make an entry in the .got.plt section, which
2336 will be placed in the .got section by the linker script. */
2337 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2339 /* We also need to make an entry in the .rela.plt section. */
2340 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2341 htab
->elf
.srelplt
->reloc_count
++;
2345 h
->plt
.offset
= (bfd_vma
) -1;
2351 h
->plt
.offset
= (bfd_vma
) -1;
2355 eh
->tlsdesc_got
= (bfd_vma
) -1;
2357 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2358 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2359 if (h
->got
.refcount
> 0
2362 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2364 h
->got
.offset
= (bfd_vma
) -1;
2366 else if (h
->got
.refcount
> 0)
2370 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2372 /* Make sure this symbol is output as a dynamic symbol.
2373 Undefined weak syms won't yet be marked as dynamic. */
2374 if (h
->dynindx
== -1
2375 && !h
->forced_local
)
2377 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2381 if (GOT_TLS_GDESC_P (tls_type
))
2383 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2384 - elf_x86_64_compute_jump_table_size (htab
);
2385 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2386 h
->got
.offset
= (bfd_vma
) -2;
2388 if (! GOT_TLS_GDESC_P (tls_type
)
2389 || GOT_TLS_GD_P (tls_type
))
2392 h
->got
.offset
= s
->size
;
2393 s
->size
+= GOT_ENTRY_SIZE
;
2394 if (GOT_TLS_GD_P (tls_type
))
2395 s
->size
+= GOT_ENTRY_SIZE
;
2397 dyn
= htab
->elf
.dynamic_sections_created
;
2398 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2400 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2401 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2402 || tls_type
== GOT_TLS_IE
)
2403 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2404 else if (GOT_TLS_GD_P (tls_type
))
2405 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2406 else if (! GOT_TLS_GDESC_P (tls_type
)
2407 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2408 || h
->root
.type
!= bfd_link_hash_undefweak
)
2410 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2411 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2412 if (GOT_TLS_GDESC_P (tls_type
))
2414 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2415 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2419 h
->got
.offset
= (bfd_vma
) -1;
2421 if (eh
->dyn_relocs
== NULL
)
2424 /* In the shared -Bsymbolic case, discard space allocated for
2425 dynamic pc-relative relocs against symbols which turn out to be
2426 defined in regular objects. For the normal shared case, discard
2427 space for pc-relative relocs that have become local due to symbol
2428 visibility changes. */
2432 /* Relocs that use pc_count are those that appear on a call
2433 insn, or certain REL relocs that can generated via assembly.
2434 We want calls to protected symbols to resolve directly to the
2435 function rather than going via the plt. If people want
2436 function pointer comparisons to work as expected then they
2437 should avoid writing weird assembly. */
2438 if (SYMBOL_CALLS_LOCAL (info
, h
))
2440 struct elf_dyn_relocs
**pp
;
2442 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2444 p
->count
-= p
->pc_count
;
2453 /* Also discard relocs on undefined weak syms with non-default
2455 if (eh
->dyn_relocs
!= NULL
2456 && h
->root
.type
== bfd_link_hash_undefweak
)
2458 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2459 eh
->dyn_relocs
= NULL
;
2461 /* Make sure undefined weak symbols are output as a dynamic
2463 else if (h
->dynindx
== -1
2464 && ! h
->forced_local
2465 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2470 else if (ELIMINATE_COPY_RELOCS
)
2472 /* For the non-shared case, discard space for relocs against
2473 symbols which turn out to need copy relocs or are not
2479 || (htab
->elf
.dynamic_sections_created
2480 && (h
->root
.type
== bfd_link_hash_undefweak
2481 || h
->root
.type
== bfd_link_hash_undefined
))))
2483 /* Make sure this symbol is output as a dynamic symbol.
2484 Undefined weak syms won't yet be marked as dynamic. */
2485 if (h
->dynindx
== -1
2486 && ! h
->forced_local
2487 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2490 /* If that succeeded, we know we'll be keeping all the
2492 if (h
->dynindx
!= -1)
2496 eh
->dyn_relocs
= NULL
;
2501 /* Finally, allocate space. */
2502 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2506 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2508 BFD_ASSERT (sreloc
!= NULL
);
2510 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2516 /* Allocate space in .plt, .got and associated reloc sections for
2517 local dynamic relocs. */
2520 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2522 struct elf_link_hash_entry
*h
2523 = (struct elf_link_hash_entry
*) *slot
;
2525 if (h
->type
!= STT_GNU_IFUNC
2529 || h
->root
.type
!= bfd_link_hash_defined
)
2532 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2535 /* Find any dynamic relocs that apply to read-only sections. */
2538 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2541 struct elf_x86_64_link_hash_entry
*eh
;
2542 struct elf_dyn_relocs
*p
;
2544 /* Skip local IFUNC symbols. */
2545 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2548 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2549 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2551 asection
*s
= p
->sec
->output_section
;
2553 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2555 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2557 info
->flags
|= DF_TEXTREL
;
2559 if (info
->warn_shared_textrel
&& info
->shared
)
2560 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2561 p
->sec
->owner
, h
->root
.root
.string
,
2564 /* Not an error, just cut short the traversal. */
2571 /* Set the sizes of the dynamic sections. */
2574 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2575 struct bfd_link_info
*info
)
2577 struct elf_x86_64_link_hash_table
*htab
;
2582 const struct elf_backend_data
*bed
;
2584 htab
= elf_x86_64_hash_table (info
);
2587 bed
= get_elf_backend_data (output_bfd
);
2589 dynobj
= htab
->elf
.dynobj
;
2593 if (htab
->elf
.dynamic_sections_created
)
2595 /* Set the contents of the .interp section to the interpreter. */
2596 if (info
->executable
)
2598 s
= bfd_get_section_by_name (dynobj
, ".interp");
2601 s
->size
= htab
->dynamic_interpreter_size
;
2602 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2606 /* Set up .got offsets for local syms, and space for local dynamic
2608 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2610 bfd_signed_vma
*local_got
;
2611 bfd_signed_vma
*end_local_got
;
2612 char *local_tls_type
;
2613 bfd_vma
*local_tlsdesc_gotent
;
2614 bfd_size_type locsymcount
;
2615 Elf_Internal_Shdr
*symtab_hdr
;
2618 if (! is_x86_64_elf (ibfd
))
2621 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2623 struct elf_dyn_relocs
*p
;
2625 for (p
= (struct elf_dyn_relocs
*)
2626 (elf_section_data (s
)->local_dynrel
);
2630 if (!bfd_is_abs_section (p
->sec
)
2631 && bfd_is_abs_section (p
->sec
->output_section
))
2633 /* Input section has been discarded, either because
2634 it is a copy of a linkonce section or due to
2635 linker script /DISCARD/, so we'll be discarding
2638 else if (p
->count
!= 0)
2640 srel
= elf_section_data (p
->sec
)->sreloc
;
2641 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2642 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2643 && (info
->flags
& DF_TEXTREL
) == 0)
2645 info
->flags
|= DF_TEXTREL
;
2646 if (info
->warn_shared_textrel
&& info
->shared
)
2647 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2648 p
->sec
->owner
, p
->sec
);
2654 local_got
= elf_local_got_refcounts (ibfd
);
2658 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2659 locsymcount
= symtab_hdr
->sh_info
;
2660 end_local_got
= local_got
+ locsymcount
;
2661 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2662 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2664 srel
= htab
->elf
.srelgot
;
2665 for (; local_got
< end_local_got
;
2666 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2668 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2671 if (GOT_TLS_GDESC_P (*local_tls_type
))
2673 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2674 - elf_x86_64_compute_jump_table_size (htab
);
2675 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2676 *local_got
= (bfd_vma
) -2;
2678 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2679 || GOT_TLS_GD_P (*local_tls_type
))
2681 *local_got
= s
->size
;
2682 s
->size
+= GOT_ENTRY_SIZE
;
2683 if (GOT_TLS_GD_P (*local_tls_type
))
2684 s
->size
+= GOT_ENTRY_SIZE
;
2687 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2688 || *local_tls_type
== GOT_TLS_IE
)
2690 if (GOT_TLS_GDESC_P (*local_tls_type
))
2692 htab
->elf
.srelplt
->size
2693 += bed
->s
->sizeof_rela
;
2694 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2696 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2697 || GOT_TLS_GD_P (*local_tls_type
))
2698 srel
->size
+= bed
->s
->sizeof_rela
;
2702 *local_got
= (bfd_vma
) -1;
2706 if (htab
->tls_ld_got
.refcount
> 0)
2708 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2710 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2711 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2712 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2715 htab
->tls_ld_got
.offset
= -1;
2717 /* Allocate global sym .plt and .got entries, and space for global
2718 sym dynamic relocs. */
2719 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2722 /* Allocate .plt and .got entries, and space for local symbols. */
2723 htab_traverse (htab
->loc_hash_table
,
2724 elf_x86_64_allocate_local_dynrelocs
,
2727 /* For every jump slot reserved in the sgotplt, reloc_count is
2728 incremented. However, when we reserve space for TLS descriptors,
2729 it's not incremented, so in order to compute the space reserved
2730 for them, it suffices to multiply the reloc count by the jump
2733 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2734 so that R_X86_64_IRELATIVE entries come last. */
2735 if (htab
->elf
.srelplt
)
2737 htab
->sgotplt_jump_table_size
2738 = elf_x86_64_compute_jump_table_size (htab
);
2739 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2741 else if (htab
->elf
.irelplt
)
2742 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2744 if (htab
->tlsdesc_plt
)
2746 /* If we're not using lazy TLS relocations, don't generate the
2747 PLT and GOT entries they require. */
2748 if ((info
->flags
& DF_BIND_NOW
))
2749 htab
->tlsdesc_plt
= 0;
2752 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2753 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2754 /* Reserve room for the initial entry.
2755 FIXME: we could probably do away with it in this case. */
2756 if (htab
->elf
.splt
->size
== 0)
2757 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2758 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2759 htab
->elf
.splt
->size
+= GET_PLT_ENTRY_SIZE (output_bfd
);
2763 if (htab
->elf
.sgotplt
)
2765 struct elf_link_hash_entry
*got
;
2766 got
= elf_link_hash_lookup (elf_hash_table (info
),
2767 "_GLOBAL_OFFSET_TABLE_",
2768 FALSE
, FALSE
, FALSE
);
2770 /* Don't allocate .got.plt section if there are no GOT nor PLT
2771 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2773 || !got
->ref_regular_nonweak
)
2774 && (htab
->elf
.sgotplt
->size
2775 == get_elf_backend_data (output_bfd
)->got_header_size
)
2776 && (htab
->elf
.splt
== NULL
2777 || htab
->elf
.splt
->size
== 0)
2778 && (htab
->elf
.sgot
== NULL
2779 || htab
->elf
.sgot
->size
== 0)
2780 && (htab
->elf
.iplt
== NULL
2781 || htab
->elf
.iplt
->size
== 0)
2782 && (htab
->elf
.igotplt
== NULL
2783 || htab
->elf
.igotplt
->size
== 0))
2784 htab
->elf
.sgotplt
->size
= 0;
2787 /* We now have determined the sizes of the various dynamic sections.
2788 Allocate memory for them. */
2790 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2792 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2795 if (s
== htab
->elf
.splt
2796 || s
== htab
->elf
.sgot
2797 || s
== htab
->elf
.sgotplt
2798 || s
== htab
->elf
.iplt
2799 || s
== htab
->elf
.igotplt
2800 || s
== htab
->sdynbss
)
2802 /* Strip this section if we don't need it; see the
2805 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2807 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2810 /* We use the reloc_count field as a counter if we need
2811 to copy relocs into the output file. */
2812 if (s
!= htab
->elf
.srelplt
)
2817 /* It's not one of our sections, so don't allocate space. */
2823 /* If we don't need this section, strip it from the
2824 output file. This is mostly to handle .rela.bss and
2825 .rela.plt. We must create both sections in
2826 create_dynamic_sections, because they must be created
2827 before the linker maps input sections to output
2828 sections. The linker does that before
2829 adjust_dynamic_symbol is called, and it is that
2830 function which decides whether anything needs to go
2831 into these sections. */
2833 s
->flags
|= SEC_EXCLUDE
;
2837 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2840 /* Allocate memory for the section contents. We use bfd_zalloc
2841 here in case unused entries are not reclaimed before the
2842 section's contents are written out. This should not happen,
2843 but this way if it does, we get a R_X86_64_NONE reloc instead
2845 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2846 if (s
->contents
== NULL
)
2850 if (htab
->plt_eh_frame
!= NULL
2851 && htab
->elf
.splt
!= NULL
2852 && htab
->elf
.splt
->size
!= 0
2853 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2854 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2855 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2857 if (htab
->elf
.dynamic_sections_created
)
2859 /* Add some entries to the .dynamic section. We fill in the
2860 values later, in elf_x86_64_finish_dynamic_sections, but we
2861 must add the entries now so that we get the correct size for
2862 the .dynamic section. The DT_DEBUG entry is filled in by the
2863 dynamic linker and used by the debugger. */
2864 #define add_dynamic_entry(TAG, VAL) \
2865 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2867 if (info
->executable
)
2869 if (!add_dynamic_entry (DT_DEBUG
, 0))
2873 if (htab
->elf
.splt
->size
!= 0)
2875 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2876 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2877 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2878 || !add_dynamic_entry (DT_JMPREL
, 0))
2881 if (htab
->tlsdesc_plt
2882 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2883 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2889 if (!add_dynamic_entry (DT_RELA
, 0)
2890 || !add_dynamic_entry (DT_RELASZ
, 0)
2891 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2894 /* If any dynamic relocs apply to a read-only section,
2895 then we need a DT_TEXTREL entry. */
2896 if ((info
->flags
& DF_TEXTREL
) == 0)
2897 elf_link_hash_traverse (&htab
->elf
,
2898 elf_x86_64_readonly_dynrelocs
,
2901 if ((info
->flags
& DF_TEXTREL
) != 0)
2903 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2908 #undef add_dynamic_entry
2914 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2915 struct bfd_link_info
*info
)
2917 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2921 struct elf_link_hash_entry
*tlsbase
;
2923 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2924 "_TLS_MODULE_BASE_",
2925 FALSE
, FALSE
, FALSE
);
2927 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2929 struct elf_x86_64_link_hash_table
*htab
;
2930 struct bfd_link_hash_entry
*bh
= NULL
;
2931 const struct elf_backend_data
*bed
2932 = get_elf_backend_data (output_bfd
);
2934 htab
= elf_x86_64_hash_table (info
);
2938 if (!(_bfd_generic_link_add_one_symbol
2939 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2940 tls_sec
, 0, NULL
, FALSE
,
2941 bed
->collect
, &bh
)))
2944 htab
->tls_module_base
= bh
;
2946 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2947 tlsbase
->def_regular
= 1;
2948 tlsbase
->other
= STV_HIDDEN
;
2949 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2956 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2957 executables. Rather than setting it to the beginning of the TLS
2958 section, we have to set it to the end. This function may be called
2959 multiple times, it is idempotent. */
2962 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2964 struct elf_x86_64_link_hash_table
*htab
;
2965 struct bfd_link_hash_entry
*base
;
2967 if (!info
->executable
)
2970 htab
= elf_x86_64_hash_table (info
);
2974 base
= htab
->tls_module_base
;
2978 base
->u
.def
.value
= htab
->elf
.tls_size
;
2981 /* Return the base VMA address which should be subtracted from real addresses
2982 when resolving @dtpoff relocation.
2983 This is PT_TLS segment p_vaddr. */
2986 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2988 /* If tls_sec is NULL, we should have signalled an error already. */
2989 if (elf_hash_table (info
)->tls_sec
== NULL
)
2991 return elf_hash_table (info
)->tls_sec
->vma
;
2994 /* Return the relocation value for @tpoff relocation
2995 if STT_TLS virtual address is ADDRESS. */
2998 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3000 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3001 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
3002 bfd_vma static_tls_size
;
3004 /* If tls_segment is NULL, we should have signalled an error already. */
3005 if (htab
->tls_sec
== NULL
)
3008 /* Consider special static TLS alignment requirements. */
3009 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
3010 return address
- static_tls_size
- htab
->tls_sec
->vma
;
3013 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
3017 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
3019 /* Opcode Instruction
3022 0x0f 0x8x conditional jump */
3024 && (contents
[offset
- 1] == 0xe8
3025 || contents
[offset
- 1] == 0xe9))
3027 && contents
[offset
- 2] == 0x0f
3028 && (contents
[offset
- 1] & 0xf0) == 0x80));
3031 /* Relocate an x86_64 ELF section. */
3034 elf_x86_64_relocate_section (bfd
*output_bfd
,
3035 struct bfd_link_info
*info
,
3037 asection
*input_section
,
3039 Elf_Internal_Rela
*relocs
,
3040 Elf_Internal_Sym
*local_syms
,
3041 asection
**local_sections
)
3043 struct elf_x86_64_link_hash_table
*htab
;
3044 Elf_Internal_Shdr
*symtab_hdr
;
3045 struct elf_link_hash_entry
**sym_hashes
;
3046 bfd_vma
*local_got_offsets
;
3047 bfd_vma
*local_tlsdesc_gotents
;
3048 Elf_Internal_Rela
*rel
;
3049 Elf_Internal_Rela
*relend
;
3050 const unsigned int plt_entry_size
= GET_PLT_ENTRY_SIZE (info
->output_bfd
);
3052 BFD_ASSERT (is_x86_64_elf (input_bfd
));
3054 htab
= elf_x86_64_hash_table (info
);
3057 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
3058 sym_hashes
= elf_sym_hashes (input_bfd
);
3059 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3060 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
3062 elf_x86_64_set_tls_module_base (info
);
3065 relend
= relocs
+ input_section
->reloc_count
;
3066 for (; rel
< relend
; rel
++)
3068 unsigned int r_type
;
3069 reloc_howto_type
*howto
;
3070 unsigned long r_symndx
;
3071 struct elf_link_hash_entry
*h
;
3072 Elf_Internal_Sym
*sym
;
3074 bfd_vma off
, offplt
;
3076 bfd_boolean unresolved_reloc
;
3077 bfd_reloc_status_type r
;
3081 r_type
= ELF32_R_TYPE (rel
->r_info
);
3082 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3083 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3086 if (r_type
>= R_X86_64_max
)
3088 bfd_set_error (bfd_error_bad_value
);
3092 if (r_type
!= (int) R_X86_64_32
3093 || ABI_64_P (output_bfd
))
3094 howto
= x86_64_elf_howto_table
+ r_type
;
3096 howto
= (x86_64_elf_howto_table
3097 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3098 r_symndx
= htab
->r_sym (rel
->r_info
);
3102 unresolved_reloc
= FALSE
;
3103 if (r_symndx
< symtab_hdr
->sh_info
)
3105 sym
= local_syms
+ r_symndx
;
3106 sec
= local_sections
[r_symndx
];
3108 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3111 /* Relocate against local STT_GNU_IFUNC symbol. */
3112 if (!info
->relocatable
3113 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3115 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3120 /* Set STT_GNU_IFUNC symbol value. */
3121 h
->root
.u
.def
.value
= sym
->st_value
;
3122 h
->root
.u
.def
.section
= sec
;
3127 bfd_boolean warned ATTRIBUTE_UNUSED
;
3129 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3130 r_symndx
, symtab_hdr
, sym_hashes
,
3132 unresolved_reloc
, warned
);
3135 if (sec
!= NULL
&& elf_discarded_section (sec
))
3136 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3137 rel
, relend
, howto
, contents
);
3139 if (info
->relocatable
)
3142 if (rel
->r_addend
== 0
3143 && r_type
== R_X86_64_64
3144 && !ABI_64_P (output_bfd
))
3146 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3147 it to 64bit if addend is zero. */
3148 r_type
= R_X86_64_32
;
3149 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3152 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3153 it here if it is defined in a non-shared object. */
3155 && h
->type
== STT_GNU_IFUNC
3162 if ((input_section
->flags
& SEC_ALLOC
) == 0
3163 || h
->plt
.offset
== (bfd_vma
) -1)
3166 /* STT_GNU_IFUNC symbol must go through PLT. */
3167 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3168 relocation
= (plt
->output_section
->vma
3169 + plt
->output_offset
+ h
->plt
.offset
);
3174 if (h
->root
.root
.string
)
3175 name
= h
->root
.root
.string
;
3177 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3179 (*_bfd_error_handler
)
3180 (_("%B: relocation %s against STT_GNU_IFUNC "
3181 "symbol `%s' isn't handled by %s"), input_bfd
,
3182 x86_64_elf_howto_table
[r_type
].name
,
3183 name
, __FUNCTION__
);
3184 bfd_set_error (bfd_error_bad_value
);
3193 if (ABI_64_P (output_bfd
))
3197 if (rel
->r_addend
!= 0)
3199 if (h
->root
.root
.string
)
3200 name
= h
->root
.root
.string
;
3202 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3204 (*_bfd_error_handler
)
3205 (_("%B: relocation %s against STT_GNU_IFUNC "
3206 "symbol `%s' has non-zero addend: %d"),
3207 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3208 name
, rel
->r_addend
);
3209 bfd_set_error (bfd_error_bad_value
);
3213 /* Generate dynamic relcoation only when there is a
3214 non-GOT reference in a shared object. */
3215 if (info
->shared
&& h
->non_got_ref
)
3217 Elf_Internal_Rela outrel
;
3220 /* Need a dynamic relocation to get the real function
3222 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3226 if (outrel
.r_offset
== (bfd_vma
) -1
3227 || outrel
.r_offset
== (bfd_vma
) -2)
3230 outrel
.r_offset
+= (input_section
->output_section
->vma
3231 + input_section
->output_offset
);
3233 if (h
->dynindx
== -1
3235 || info
->executable
)
3237 /* This symbol is resolved locally. */
3238 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3239 outrel
.r_addend
= (h
->root
.u
.def
.value
3240 + h
->root
.u
.def
.section
->output_section
->vma
3241 + h
->root
.u
.def
.section
->output_offset
);
3245 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3246 outrel
.r_addend
= 0;
3249 sreloc
= htab
->elf
.irelifunc
;
3250 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3252 /* If this reloc is against an external symbol, we
3253 do not want to fiddle with the addend. Otherwise,
3254 we need to include the symbol value so that it
3255 becomes an addend for the dynamic reloc. For an
3256 internal symbol, we have updated addend. */
3262 case R_X86_64_PLT32
:
3265 case R_X86_64_GOTPCREL
:
3266 case R_X86_64_GOTPCREL64
:
3267 base_got
= htab
->elf
.sgot
;
3268 off
= h
->got
.offset
;
3270 if (base_got
== NULL
)
3273 if (off
== (bfd_vma
) -1)
3275 /* We can't use h->got.offset here to save state, or
3276 even just remember the offset, as finish_dynamic_symbol
3277 would use that as offset into .got. */
3279 if (htab
->elf
.splt
!= NULL
)
3281 plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3282 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3283 base_got
= htab
->elf
.sgotplt
;
3287 plt_index
= h
->plt
.offset
/ plt_entry_size
;
3288 off
= plt_index
* GOT_ENTRY_SIZE
;
3289 base_got
= htab
->elf
.igotplt
;
3292 if (h
->dynindx
== -1
3296 /* This references the local defitionion. We must
3297 initialize this entry in the global offset table.
3298 Since the offset must always be a multiple of 8,
3299 we use the least significant bit to record
3300 whether we have initialized it already.
3302 When doing a dynamic link, we create a .rela.got
3303 relocation entry to initialize the value. This
3304 is done in the finish_dynamic_symbol routine. */
3309 bfd_put_64 (output_bfd
, relocation
,
3310 base_got
->contents
+ off
);
3311 /* Note that this is harmless for the GOTPLT64
3312 case, as -1 | 1 still is -1. */
3318 relocation
= (base_got
->output_section
->vma
3319 + base_got
->output_offset
+ off
);
3325 /* When generating a shared object, the relocations handled here are
3326 copied into the output file to be resolved at run time. */
3329 case R_X86_64_GOT32
:
3330 case R_X86_64_GOT64
:
3331 /* Relocation is to the entry for this symbol in the global
3333 case R_X86_64_GOTPCREL
:
3334 case R_X86_64_GOTPCREL64
:
3335 /* Use global offset table entry as symbol value. */
3336 case R_X86_64_GOTPLT64
:
3337 /* This is the same as GOT64 for relocation purposes, but
3338 indicates the existence of a PLT entry. The difficulty is,
3339 that we must calculate the GOT slot offset from the PLT
3340 offset, if this symbol got a PLT entry (it was global).
3341 Additionally if it's computed from the PLT entry, then that
3342 GOT offset is relative to .got.plt, not to .got. */
3343 base_got
= htab
->elf
.sgot
;
3345 if (htab
->elf
.sgot
== NULL
)
3352 off
= h
->got
.offset
;
3354 && h
->plt
.offset
!= (bfd_vma
)-1
3355 && off
== (bfd_vma
)-1)
3357 /* We can't use h->got.offset here to save
3358 state, or even just remember the offset, as
3359 finish_dynamic_symbol would use that as offset into
3361 bfd_vma plt_index
= h
->plt
.offset
/ plt_entry_size
- 1;
3362 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3363 base_got
= htab
->elf
.sgotplt
;
3366 dyn
= htab
->elf
.dynamic_sections_created
;
3368 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3370 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3371 || (ELF_ST_VISIBILITY (h
->other
)
3372 && h
->root
.type
== bfd_link_hash_undefweak
))
3374 /* This is actually a static link, or it is a -Bsymbolic
3375 link and the symbol is defined locally, or the symbol
3376 was forced to be local because of a version file. We
3377 must initialize this entry in the global offset table.
3378 Since the offset must always be a multiple of 8, we
3379 use the least significant bit to record whether we
3380 have initialized it already.
3382 When doing a dynamic link, we create a .rela.got
3383 relocation entry to initialize the value. This is
3384 done in the finish_dynamic_symbol routine. */
3389 bfd_put_64 (output_bfd
, relocation
,
3390 base_got
->contents
+ off
);
3391 /* Note that this is harmless for the GOTPLT64 case,
3392 as -1 | 1 still is -1. */
3397 unresolved_reloc
= FALSE
;
3401 if (local_got_offsets
== NULL
)
3404 off
= local_got_offsets
[r_symndx
];
3406 /* The offset must always be a multiple of 8. We use
3407 the least significant bit to record whether we have
3408 already generated the necessary reloc. */
3413 bfd_put_64 (output_bfd
, relocation
,
3414 base_got
->contents
+ off
);
3419 Elf_Internal_Rela outrel
;
3421 /* We need to generate a R_X86_64_RELATIVE reloc
3422 for the dynamic linker. */
3423 s
= htab
->elf
.srelgot
;
3427 outrel
.r_offset
= (base_got
->output_section
->vma
3428 + base_got
->output_offset
3430 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3431 outrel
.r_addend
= relocation
;
3432 elf_append_rela (output_bfd
, s
, &outrel
);
3435 local_got_offsets
[r_symndx
] |= 1;
3439 if (off
>= (bfd_vma
) -2)
3442 relocation
= base_got
->output_section
->vma
3443 + base_got
->output_offset
+ off
;
3444 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3445 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3446 - htab
->elf
.sgotplt
->output_offset
;
3450 case R_X86_64_GOTOFF64
:
3451 /* Relocation is relative to the start of the global offset
3454 /* Check to make sure it isn't a protected function symbol
3455 for shared library since it may not be local when used
3456 as function address. */
3460 && h
->type
== STT_FUNC
3461 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3463 (*_bfd_error_handler
)
3464 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3465 input_bfd
, h
->root
.root
.string
);
3466 bfd_set_error (bfd_error_bad_value
);
3470 /* Note that sgot is not involved in this
3471 calculation. We always want the start of .got.plt. If we
3472 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3473 permitted by the ABI, we might have to change this
3475 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3476 + htab
->elf
.sgotplt
->output_offset
;
3479 case R_X86_64_GOTPC32
:
3480 case R_X86_64_GOTPC64
:
3481 /* Use global offset table as symbol value. */
3482 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3483 + htab
->elf
.sgotplt
->output_offset
;
3484 unresolved_reloc
= FALSE
;
3487 case R_X86_64_PLTOFF64
:
3488 /* Relocation is PLT entry relative to GOT. For local
3489 symbols it's the symbol itself relative to GOT. */
3491 /* See PLT32 handling. */
3492 && h
->plt
.offset
!= (bfd_vma
) -1
3493 && htab
->elf
.splt
!= NULL
)
3495 relocation
= (htab
->elf
.splt
->output_section
->vma
3496 + htab
->elf
.splt
->output_offset
3498 unresolved_reloc
= FALSE
;
3501 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3502 + htab
->elf
.sgotplt
->output_offset
;
3505 case R_X86_64_PLT32
:
3506 /* Relocation is to the entry for this symbol in the
3507 procedure linkage table. */
3509 /* Resolve a PLT32 reloc against a local symbol directly,
3510 without using the procedure linkage table. */
3514 if (h
->plt
.offset
== (bfd_vma
) -1
3515 || htab
->elf
.splt
== NULL
)
3517 /* We didn't make a PLT entry for this symbol. This
3518 happens when statically linking PIC code, or when
3519 using -Bsymbolic. */
3523 relocation
= (htab
->elf
.splt
->output_section
->vma
3524 + htab
->elf
.splt
->output_offset
3526 unresolved_reloc
= FALSE
;
3533 && (input_section
->flags
& SEC_ALLOC
) != 0
3534 && (input_section
->flags
& SEC_READONLY
) != 0
3537 bfd_boolean fail
= FALSE
;
3539 = (r_type
== R_X86_64_PC32
3540 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3542 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3544 /* Symbol is referenced locally. Make sure it is
3545 defined locally or for a branch. */
3546 fail
= !h
->def_regular
&& !branch
;
3550 /* Symbol isn't referenced locally. We only allow
3551 branch to symbol with non-default visibility. */
3553 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3560 const char *pic
= "";
3562 switch (ELF_ST_VISIBILITY (h
->other
))
3565 v
= _("hidden symbol");
3568 v
= _("internal symbol");
3571 v
= _("protected symbol");
3575 pic
= _("; recompile with -fPIC");
3580 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3582 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3584 (*_bfd_error_handler
) (fmt
, input_bfd
,
3585 x86_64_elf_howto_table
[r_type
].name
,
3586 v
, h
->root
.root
.string
, pic
);
3587 bfd_set_error (bfd_error_bad_value
);
3598 /* FIXME: The ABI says the linker should make sure the value is
3599 the same when it's zeroextended to 64 bit. */
3601 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3606 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3607 || h
->root
.type
!= bfd_link_hash_undefweak
)
3608 && (! IS_X86_64_PCREL_TYPE (r_type
)
3609 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3610 || (ELIMINATE_COPY_RELOCS
3617 || h
->root
.type
== bfd_link_hash_undefweak
3618 || h
->root
.type
== bfd_link_hash_undefined
)))
3620 Elf_Internal_Rela outrel
;
3621 bfd_boolean skip
, relocate
;
3624 /* When generating a shared object, these relocations
3625 are copied into the output file to be resolved at run
3631 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3633 if (outrel
.r_offset
== (bfd_vma
) -1)
3635 else if (outrel
.r_offset
== (bfd_vma
) -2)
3636 skip
= TRUE
, relocate
= TRUE
;
3638 outrel
.r_offset
+= (input_section
->output_section
->vma
3639 + input_section
->output_offset
);
3642 memset (&outrel
, 0, sizeof outrel
);
3644 /* h->dynindx may be -1 if this symbol was marked to
3648 && (IS_X86_64_PCREL_TYPE (r_type
)
3650 || ! SYMBOLIC_BIND (info
, h
)
3651 || ! h
->def_regular
))
3653 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3654 outrel
.r_addend
= rel
->r_addend
;
3658 /* This symbol is local, or marked to become local. */
3659 if (r_type
== htab
->pointer_r_type
)
3662 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3663 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3665 else if (r_type
== R_X86_64_64
3666 && !ABI_64_P (output_bfd
))
3669 outrel
.r_info
= htab
->r_info (0,
3670 R_X86_64_RELATIVE64
);
3671 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3677 if (bfd_is_abs_section (sec
))
3679 else if (sec
== NULL
|| sec
->owner
== NULL
)
3681 bfd_set_error (bfd_error_bad_value
);
3688 /* We are turning this relocation into one
3689 against a section symbol. It would be
3690 proper to subtract the symbol's value,
3691 osec->vma, from the emitted reloc addend,
3692 but ld.so expects buggy relocs. */
3693 osec
= sec
->output_section
;
3694 sindx
= elf_section_data (osec
)->dynindx
;
3697 asection
*oi
= htab
->elf
.text_index_section
;
3698 sindx
= elf_section_data (oi
)->dynindx
;
3700 BFD_ASSERT (sindx
!= 0);
3703 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3704 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3708 sreloc
= elf_section_data (input_section
)->sreloc
;
3710 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3712 r
= bfd_reloc_notsupported
;
3713 goto check_relocation_error
;
3716 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3718 /* If this reloc is against an external symbol, we do
3719 not want to fiddle with the addend. Otherwise, we
3720 need to include the symbol value so that it becomes
3721 an addend for the dynamic reloc. */
3728 case R_X86_64_TLSGD
:
3729 case R_X86_64_GOTPC32_TLSDESC
:
3730 case R_X86_64_TLSDESC_CALL
:
3731 case R_X86_64_GOTTPOFF
:
3732 tls_type
= GOT_UNKNOWN
;
3733 if (h
== NULL
&& local_got_offsets
)
3734 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3736 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3738 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3739 input_section
, contents
,
3740 symtab_hdr
, sym_hashes
,
3741 &r_type
, tls_type
, rel
,
3742 relend
, h
, r_symndx
))
3745 if (r_type
== R_X86_64_TPOFF32
)
3747 bfd_vma roff
= rel
->r_offset
;
3749 BFD_ASSERT (! unresolved_reloc
);
3751 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3753 /* GD->LE transition. For 64bit, change
3754 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3755 .word 0x6666; rex64; call __tls_get_addr
3758 leaq foo@tpoff(%rax), %rax
3760 leaq foo@tlsgd(%rip), %rdi
3761 .word 0x6666; rex64; call __tls_get_addr
3764 leaq foo@tpoff(%rax), %rax */
3765 if (ABI_64_P (output_bfd
))
3766 memcpy (contents
+ roff
- 4,
3767 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3770 memcpy (contents
+ roff
- 3,
3771 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3773 bfd_put_32 (output_bfd
,
3774 elf_x86_64_tpoff (info
, relocation
),
3775 contents
+ roff
+ 8);
3776 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3780 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3782 /* GDesc -> LE transition.
3783 It's originally something like:
3784 leaq x@tlsdesc(%rip), %rax
3787 movl $x@tpoff, %rax. */
3789 unsigned int val
, type
;
3791 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3792 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3793 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3794 contents
+ roff
- 3);
3795 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3796 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3797 contents
+ roff
- 1);
3798 bfd_put_32 (output_bfd
,
3799 elf_x86_64_tpoff (info
, relocation
),
3803 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3805 /* GDesc -> LE transition.
3810 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3811 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3814 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3816 /* IE->LE transition:
3817 Originally it can be one of:
3818 movq foo@gottpoff(%rip), %reg
3819 addq foo@gottpoff(%rip), %reg
3822 leaq foo(%reg), %reg
3825 unsigned int val
, type
, reg
;
3827 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3828 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3829 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3835 bfd_put_8 (output_bfd
, 0x49,
3836 contents
+ roff
- 3);
3837 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3838 bfd_put_8 (output_bfd
, 0x41,
3839 contents
+ roff
- 3);
3840 bfd_put_8 (output_bfd
, 0xc7,
3841 contents
+ roff
- 2);
3842 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3843 contents
+ roff
- 1);
3847 /* addq -> addq - addressing with %rsp/%r12 is
3850 bfd_put_8 (output_bfd
, 0x49,
3851 contents
+ roff
- 3);
3852 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3853 bfd_put_8 (output_bfd
, 0x41,
3854 contents
+ roff
- 3);
3855 bfd_put_8 (output_bfd
, 0x81,
3856 contents
+ roff
- 2);
3857 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3858 contents
+ roff
- 1);
3864 bfd_put_8 (output_bfd
, 0x4d,
3865 contents
+ roff
- 3);
3866 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3867 bfd_put_8 (output_bfd
, 0x45,
3868 contents
+ roff
- 3);
3869 bfd_put_8 (output_bfd
, 0x8d,
3870 contents
+ roff
- 2);
3871 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3872 contents
+ roff
- 1);
3874 bfd_put_32 (output_bfd
,
3875 elf_x86_64_tpoff (info
, relocation
),
3883 if (htab
->elf
.sgot
== NULL
)
3888 off
= h
->got
.offset
;
3889 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3893 if (local_got_offsets
== NULL
)
3896 off
= local_got_offsets
[r_symndx
];
3897 offplt
= local_tlsdesc_gotents
[r_symndx
];
3904 Elf_Internal_Rela outrel
;
3908 if (htab
->elf
.srelgot
== NULL
)
3911 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3913 if (GOT_TLS_GDESC_P (tls_type
))
3915 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3916 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3917 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3918 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3919 + htab
->elf
.sgotplt
->output_offset
3921 + htab
->sgotplt_jump_table_size
);
3922 sreloc
= htab
->elf
.srelplt
;
3924 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3926 outrel
.r_addend
= 0;
3927 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3930 sreloc
= htab
->elf
.srelgot
;
3932 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3933 + htab
->elf
.sgot
->output_offset
+ off
);
3935 if (GOT_TLS_GD_P (tls_type
))
3936 dr_type
= R_X86_64_DTPMOD64
;
3937 else if (GOT_TLS_GDESC_P (tls_type
))
3940 dr_type
= R_X86_64_TPOFF64
;
3942 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3943 outrel
.r_addend
= 0;
3944 if ((dr_type
== R_X86_64_TPOFF64
3945 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3946 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3947 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3949 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3951 if (GOT_TLS_GD_P (tls_type
))
3955 BFD_ASSERT (! unresolved_reloc
);
3956 bfd_put_64 (output_bfd
,
3957 relocation
- elf_x86_64_dtpoff_base (info
),
3958 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3962 bfd_put_64 (output_bfd
, 0,
3963 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3964 outrel
.r_info
= htab
->r_info (indx
,
3966 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3967 elf_append_rela (output_bfd
, sreloc
,
3976 local_got_offsets
[r_symndx
] |= 1;
3979 if (off
>= (bfd_vma
) -2
3980 && ! GOT_TLS_GDESC_P (tls_type
))
3982 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3984 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3985 || r_type
== R_X86_64_TLSDESC_CALL
)
3986 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3987 + htab
->elf
.sgotplt
->output_offset
3988 + offplt
+ htab
->sgotplt_jump_table_size
;
3990 relocation
= htab
->elf
.sgot
->output_section
->vma
3991 + htab
->elf
.sgot
->output_offset
+ off
;
3992 unresolved_reloc
= FALSE
;
3996 bfd_vma roff
= rel
->r_offset
;
3998 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
4000 /* GD->IE transition. For 64bit, change
4001 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
4002 .word 0x6666; rex64; call __tls_get_addr@plt
4005 addq foo@gottpoff(%rip), %rax
4007 leaq foo@tlsgd(%rip), %rdi
4008 .word 0x6666; rex64; call __tls_get_addr@plt
4011 addq foo@gottpoff(%rip), %rax */
4012 if (ABI_64_P (output_bfd
))
4013 memcpy (contents
+ roff
- 4,
4014 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4017 memcpy (contents
+ roff
- 3,
4018 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
4021 relocation
= (htab
->elf
.sgot
->output_section
->vma
4022 + htab
->elf
.sgot
->output_offset
+ off
4024 - input_section
->output_section
->vma
4025 - input_section
->output_offset
4027 bfd_put_32 (output_bfd
, relocation
,
4028 contents
+ roff
+ 8);
4029 /* Skip R_X86_64_PLT32. */
4033 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
4035 /* GDesc -> IE transition.
4036 It's originally something like:
4037 leaq x@tlsdesc(%rip), %rax
4040 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
4042 /* Now modify the instruction as appropriate. To
4043 turn a leaq into a movq in the form we use it, it
4044 suffices to change the second byte from 0x8d to
4046 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
4048 bfd_put_32 (output_bfd
,
4049 htab
->elf
.sgot
->output_section
->vma
4050 + htab
->elf
.sgot
->output_offset
+ off
4052 - input_section
->output_section
->vma
4053 - input_section
->output_offset
4058 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
4060 /* GDesc -> IE transition.
4067 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
4068 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4076 case R_X86_64_TLSLD
:
4077 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4078 input_section
, contents
,
4079 symtab_hdr
, sym_hashes
,
4080 &r_type
, GOT_UNKNOWN
,
4081 rel
, relend
, h
, r_symndx
))
4084 if (r_type
!= R_X86_64_TLSLD
)
4086 /* LD->LE transition:
4087 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4088 For 64bit, we change it into:
4089 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4090 For 32bit, we change it into:
4091 nopl 0x0(%rax); movl %fs:0, %eax. */
4093 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4094 if (ABI_64_P (output_bfd
))
4095 memcpy (contents
+ rel
->r_offset
- 3,
4096 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4098 memcpy (contents
+ rel
->r_offset
- 3,
4099 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4100 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4105 if (htab
->elf
.sgot
== NULL
)
4108 off
= htab
->tls_ld_got
.offset
;
4113 Elf_Internal_Rela outrel
;
4115 if (htab
->elf
.srelgot
== NULL
)
4118 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4119 + htab
->elf
.sgot
->output_offset
+ off
);
4121 bfd_put_64 (output_bfd
, 0,
4122 htab
->elf
.sgot
->contents
+ off
);
4123 bfd_put_64 (output_bfd
, 0,
4124 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4125 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4126 outrel
.r_addend
= 0;
4127 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4129 htab
->tls_ld_got
.offset
|= 1;
4131 relocation
= htab
->elf
.sgot
->output_section
->vma
4132 + htab
->elf
.sgot
->output_offset
+ off
;
4133 unresolved_reloc
= FALSE
;
4136 case R_X86_64_DTPOFF32
:
4137 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4138 relocation
-= elf_x86_64_dtpoff_base (info
);
4140 relocation
= elf_x86_64_tpoff (info
, relocation
);
4143 case R_X86_64_TPOFF32
:
4144 case R_X86_64_TPOFF64
:
4145 BFD_ASSERT (info
->executable
);
4146 relocation
= elf_x86_64_tpoff (info
, relocation
);
4153 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4154 because such sections are not SEC_ALLOC and thus ld.so will
4155 not process them. */
4156 if (unresolved_reloc
4157 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4159 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4160 rel
->r_offset
) != (bfd_vma
) -1)
4161 (*_bfd_error_handler
)
4162 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4165 (long) rel
->r_offset
,
4167 h
->root
.root
.string
);
4170 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4171 contents
, rel
->r_offset
,
4172 relocation
, rel
->r_addend
);
4174 check_relocation_error
:
4175 if (r
!= bfd_reloc_ok
)
4180 name
= h
->root
.root
.string
;
4183 name
= bfd_elf_string_from_elf_section (input_bfd
,
4184 symtab_hdr
->sh_link
,
4189 name
= bfd_section_name (input_bfd
, sec
);
4192 if (r
== bfd_reloc_overflow
)
4194 if (! ((*info
->callbacks
->reloc_overflow
)
4195 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4196 (bfd_vma
) 0, input_bfd
, input_section
,
4202 (*_bfd_error_handler
)
4203 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4204 input_bfd
, input_section
,
4205 (long) rel
->r_offset
, name
, (int) r
);
4214 /* Finish up dynamic symbol handling. We set the contents of various
4215 dynamic sections here. */
4218 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4219 struct bfd_link_info
*info
,
4220 struct elf_link_hash_entry
*h
,
4221 Elf_Internal_Sym
*sym
)
4223 struct elf_x86_64_link_hash_table
*htab
;
4224 const struct elf_x86_64_backend_data
*const abed
4225 = get_elf_x86_64_backend_data (output_bfd
);
4227 htab
= elf_x86_64_hash_table (info
);
4231 if (h
->plt
.offset
!= (bfd_vma
) -1)
4235 Elf_Internal_Rela rela
;
4237 asection
*plt
, *gotplt
, *relplt
;
4238 const struct elf_backend_data
*bed
;
4240 /* When building a static executable, use .iplt, .igot.plt and
4241 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4242 if (htab
->elf
.splt
!= NULL
)
4244 plt
= htab
->elf
.splt
;
4245 gotplt
= htab
->elf
.sgotplt
;
4246 relplt
= htab
->elf
.srelplt
;
4250 plt
= htab
->elf
.iplt
;
4251 gotplt
= htab
->elf
.igotplt
;
4252 relplt
= htab
->elf
.irelplt
;
4255 /* This symbol has an entry in the procedure linkage table. Set
4257 if ((h
->dynindx
== -1
4258 && !((h
->forced_local
|| info
->executable
)
4260 && h
->type
== STT_GNU_IFUNC
))
4266 /* Get the index in the procedure linkage table which
4267 corresponds to this symbol. This is the index of this symbol
4268 in all the symbols for which we are making plt entries. The
4269 first entry in the procedure linkage table is reserved.
4271 Get the offset into the .got table of the entry that
4272 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4273 bytes. The first three are reserved for the dynamic linker.
4275 For static executables, we don't reserve anything. */
4277 if (plt
== htab
->elf
.splt
)
4279 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
- 1;
4280 got_offset
= (got_offset
+ 3) * GOT_ENTRY_SIZE
;
4284 got_offset
= h
->plt
.offset
/ abed
->plt_entry_size
;
4285 got_offset
= got_offset
* GOT_ENTRY_SIZE
;
4288 /* Fill in the entry in the procedure linkage table. */
4289 memcpy (plt
->contents
+ h
->plt
.offset
, abed
->plt_entry
,
4290 abed
->plt_entry_size
);
4292 /* Insert the relocation positions of the plt section. */
4294 /* Put offset the PC-relative instruction referring to the GOT entry,
4295 subtracting the size of that instruction. */
4296 bfd_put_32 (output_bfd
,
4297 (gotplt
->output_section
->vma
4298 + gotplt
->output_offset
4300 - plt
->output_section
->vma
4301 - plt
->output_offset
4303 - abed
->plt_got_insn_size
),
4304 plt
->contents
+ h
->plt
.offset
+ abed
->plt_got_offset
);
4306 /* Fill in the entry in the global offset table, initially this
4307 points to the second part of the PLT entry. */
4308 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4309 + plt
->output_offset
4310 + h
->plt
.offset
+ abed
->plt_lazy_offset
),
4311 gotplt
->contents
+ got_offset
);
4313 /* Fill in the entry in the .rela.plt section. */
4314 rela
.r_offset
= (gotplt
->output_section
->vma
4315 + gotplt
->output_offset
4317 if (h
->dynindx
== -1
4318 || ((info
->executable
4319 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4321 && h
->type
== STT_GNU_IFUNC
))
4323 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4324 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4325 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4326 rela
.r_addend
= (h
->root
.u
.def
.value
4327 + h
->root
.u
.def
.section
->output_section
->vma
4328 + h
->root
.u
.def
.section
->output_offset
);
4329 /* R_X86_64_IRELATIVE comes last. */
4330 plt_index
= htab
->next_irelative_index
--;
4334 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4336 plt_index
= htab
->next_jump_slot_index
++;
4339 /* Don't fill PLT entry for static executables. */
4340 if (plt
== htab
->elf
.splt
)
4342 /* Put relocation index. */
4343 bfd_put_32 (output_bfd
, plt_index
,
4344 plt
->contents
+ h
->plt
.offset
+ abed
->plt_reloc_offset
);
4345 /* Put offset for jmp .PLT0. */
4346 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ abed
->plt_plt_insn_end
),
4347 plt
->contents
+ h
->plt
.offset
+ abed
->plt_plt_offset
);
4350 bed
= get_elf_backend_data (output_bfd
);
4351 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4352 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4354 if (!h
->def_regular
)
4356 /* Mark the symbol as undefined, rather than as defined in
4357 the .plt section. Leave the value if there were any
4358 relocations where pointer equality matters (this is a clue
4359 for the dynamic linker, to make function pointer
4360 comparisons work between an application and shared
4361 library), otherwise set it to zero. If a function is only
4362 called from a binary, there is no need to slow down
4363 shared libraries because of that. */
4364 sym
->st_shndx
= SHN_UNDEF
;
4365 if (!h
->pointer_equality_needed
)
4370 if (h
->got
.offset
!= (bfd_vma
) -1
4371 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4372 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4374 Elf_Internal_Rela rela
;
4376 /* This symbol has an entry in the global offset table. Set it
4378 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4381 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4382 + htab
->elf
.sgot
->output_offset
4383 + (h
->got
.offset
&~ (bfd_vma
) 1));
4385 /* If this is a static link, or it is a -Bsymbolic link and the
4386 symbol is defined locally or was forced to be local because
4387 of a version file, we just want to emit a RELATIVE reloc.
4388 The entry in the global offset table will already have been
4389 initialized in the relocate_section function. */
4391 && h
->type
== STT_GNU_IFUNC
)
4395 /* Generate R_X86_64_GLOB_DAT. */
4402 if (!h
->pointer_equality_needed
)
4405 /* For non-shared object, we can't use .got.plt, which
4406 contains the real function addres if we need pointer
4407 equality. We load the GOT entry with the PLT entry. */
4408 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4409 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4410 + plt
->output_offset
4412 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4416 else if (info
->shared
4417 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4419 if (!h
->def_regular
)
4421 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4422 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4423 rela
.r_addend
= (h
->root
.u
.def
.value
4424 + h
->root
.u
.def
.section
->output_section
->vma
4425 + h
->root
.u
.def
.section
->output_offset
);
4429 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4431 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4432 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4433 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4437 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4442 Elf_Internal_Rela rela
;
4444 /* This symbol needs a copy reloc. Set it up. */
4446 if (h
->dynindx
== -1
4447 || (h
->root
.type
!= bfd_link_hash_defined
4448 && h
->root
.type
!= bfd_link_hash_defweak
)
4449 || htab
->srelbss
== NULL
)
4452 rela
.r_offset
= (h
->root
.u
.def
.value
4453 + h
->root
.u
.def
.section
->output_section
->vma
4454 + h
->root
.u
.def
.section
->output_offset
);
4455 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4457 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4460 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4461 be NULL for local symbols. */
4463 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4464 || h
== htab
->elf
.hgot
))
4465 sym
->st_shndx
= SHN_ABS
;
4470 /* Finish up local dynamic symbol handling. We set the contents of
4471 various dynamic sections here. */
4474 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4476 struct elf_link_hash_entry
*h
4477 = (struct elf_link_hash_entry
*) *slot
;
4478 struct bfd_link_info
*info
4479 = (struct bfd_link_info
*) inf
;
4481 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4485 /* Used to decide how to sort relocs in an optimal manner for the
4486 dynamic linker, before writing them out. */
4488 static enum elf_reloc_type_class
4489 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4491 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4493 case R_X86_64_RELATIVE
:
4494 return reloc_class_relative
;
4495 case R_X86_64_JUMP_SLOT
:
4496 return reloc_class_plt
;
4498 return reloc_class_copy
;
4500 return reloc_class_normal
;
4504 /* Finish up the dynamic sections. */
4507 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4508 struct bfd_link_info
*info
)
4510 struct elf_x86_64_link_hash_table
*htab
;
4513 const struct elf_x86_64_backend_data
*const abed
4514 = get_elf_x86_64_backend_data (output_bfd
);
4516 htab
= elf_x86_64_hash_table (info
);
4520 dynobj
= htab
->elf
.dynobj
;
4521 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4523 if (htab
->elf
.dynamic_sections_created
)
4525 bfd_byte
*dyncon
, *dynconend
;
4526 const struct elf_backend_data
*bed
;
4527 bfd_size_type sizeof_dyn
;
4529 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4532 bed
= get_elf_backend_data (dynobj
);
4533 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4534 dyncon
= sdyn
->contents
;
4535 dynconend
= sdyn
->contents
+ sdyn
->size
;
4536 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4538 Elf_Internal_Dyn dyn
;
4541 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4549 s
= htab
->elf
.sgotplt
;
4550 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4554 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4558 s
= htab
->elf
.srelplt
->output_section
;
4559 dyn
.d_un
.d_val
= s
->size
;
4563 /* The procedure linkage table relocs (DT_JMPREL) should
4564 not be included in the overall relocs (DT_RELA).
4565 Therefore, we override the DT_RELASZ entry here to
4566 make it not include the JMPREL relocs. Since the
4567 linker script arranges for .rela.plt to follow all
4568 other relocation sections, we don't have to worry
4569 about changing the DT_RELA entry. */
4570 if (htab
->elf
.srelplt
!= NULL
)
4572 s
= htab
->elf
.srelplt
->output_section
;
4573 dyn
.d_un
.d_val
-= s
->size
;
4577 case DT_TLSDESC_PLT
:
4579 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4580 + htab
->tlsdesc_plt
;
4583 case DT_TLSDESC_GOT
:
4585 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4586 + htab
->tlsdesc_got
;
4590 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4593 /* Fill in the special first entry in the procedure linkage table. */
4594 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4596 /* Fill in the first entry in the procedure linkage table. */
4597 memcpy (htab
->elf
.splt
->contents
,
4598 abed
->plt0_entry
, abed
->plt_entry_size
);
4599 /* Add offset for pushq GOT+8(%rip), since the instruction
4600 uses 6 bytes subtract this value. */
4601 bfd_put_32 (output_bfd
,
4602 (htab
->elf
.sgotplt
->output_section
->vma
4603 + htab
->elf
.sgotplt
->output_offset
4605 - htab
->elf
.splt
->output_section
->vma
4606 - htab
->elf
.splt
->output_offset
4608 htab
->elf
.splt
->contents
+ abed
->plt0_got1_offset
);
4609 /* Add offset for the PC-relative instruction accessing GOT+16,
4610 subtracting the offset to the end of that instruction. */
4611 bfd_put_32 (output_bfd
,
4612 (htab
->elf
.sgotplt
->output_section
->vma
4613 + htab
->elf
.sgotplt
->output_offset
4615 - htab
->elf
.splt
->output_section
->vma
4616 - htab
->elf
.splt
->output_offset
4617 - abed
->plt0_got2_insn_end
),
4618 htab
->elf
.splt
->contents
+ abed
->plt0_got2_offset
);
4620 elf_section_data (htab
->elf
.splt
->output_section
)
4621 ->this_hdr
.sh_entsize
= abed
->plt_entry_size
;
4623 if (htab
->tlsdesc_plt
)
4625 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4626 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4628 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4629 abed
->plt0_entry
, abed
->plt_entry_size
);
4631 /* Add offset for pushq GOT+8(%rip), since the
4632 instruction uses 6 bytes subtract this value. */
4633 bfd_put_32 (output_bfd
,
4634 (htab
->elf
.sgotplt
->output_section
->vma
4635 + htab
->elf
.sgotplt
->output_offset
4637 - htab
->elf
.splt
->output_section
->vma
4638 - htab
->elf
.splt
->output_offset
4641 htab
->elf
.splt
->contents
4642 + htab
->tlsdesc_plt
+ abed
->plt0_got1_offset
);
4643 /* Add offset for the PC-relative instruction accessing GOT+TDG,
4644 where TGD stands for htab->tlsdesc_got, subtracting the offset
4645 to the end of that instruction. */
4646 bfd_put_32 (output_bfd
,
4647 (htab
->elf
.sgot
->output_section
->vma
4648 + htab
->elf
.sgot
->output_offset
4650 - htab
->elf
.splt
->output_section
->vma
4651 - htab
->elf
.splt
->output_offset
4653 - abed
->plt0_got2_insn_end
),
4654 htab
->elf
.splt
->contents
4655 + htab
->tlsdesc_plt
+ abed
->plt0_got2_offset
);
4660 if (htab
->elf
.sgotplt
)
4662 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4664 (*_bfd_error_handler
)
4665 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4669 /* Fill in the first three entries in the global offset table. */
4670 if (htab
->elf
.sgotplt
->size
> 0)
4672 /* Set the first entry in the global offset table to the address of
4673 the dynamic section. */
4675 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4677 bfd_put_64 (output_bfd
,
4678 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4679 htab
->elf
.sgotplt
->contents
);
4680 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4681 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4682 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4685 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4689 /* Adjust .eh_frame for .plt section. */
4690 if (htab
->plt_eh_frame
!= NULL
)
4692 if (htab
->elf
.splt
!= NULL
4693 && htab
->elf
.splt
->size
!= 0
4694 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4695 && htab
->elf
.splt
->output_section
!= NULL
4696 && htab
->plt_eh_frame
->output_section
!= NULL
)
4698 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4699 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4700 + htab
->plt_eh_frame
->output_offset
4701 + PLT_FDE_START_OFFSET
;
4702 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4703 htab
->plt_eh_frame
->contents
4704 + PLT_FDE_START_OFFSET
);
4706 if (htab
->plt_eh_frame
->sec_info_type
4707 == ELF_INFO_TYPE_EH_FRAME
)
4709 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4711 htab
->plt_eh_frame
->contents
))
4716 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4717 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4720 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4721 htab_traverse (htab
->loc_hash_table
,
4722 elf_x86_64_finish_local_dynamic_symbol
,
4728 /* Return address for Ith PLT stub in section PLT, for relocation REL
4729 or (bfd_vma) -1 if it should not be included. */
4732 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4733 const arelent
*rel ATTRIBUTE_UNUSED
)
4735 return plt
->vma
+ (i
+ 1) * GET_PLT_ENTRY_SIZE (plt
->owner
);
4738 /* Handle an x86-64 specific section when reading an object file. This
4739 is called when elfcode.h finds a section with an unknown type. */
4742 elf_x86_64_section_from_shdr (bfd
*abfd
,
4743 Elf_Internal_Shdr
*hdr
,
4747 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4750 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4756 /* Hook called by the linker routine which adds symbols from an object
4757 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4761 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4762 struct bfd_link_info
*info
,
4763 Elf_Internal_Sym
*sym
,
4764 const char **namep ATTRIBUTE_UNUSED
,
4765 flagword
*flagsp ATTRIBUTE_UNUSED
,
4771 switch (sym
->st_shndx
)
4773 case SHN_X86_64_LCOMMON
:
4774 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4777 lcomm
= bfd_make_section_with_flags (abfd
,
4781 | SEC_LINKER_CREATED
));
4784 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4787 *valp
= sym
->st_size
;
4791 if ((abfd
->flags
& DYNAMIC
) == 0
4792 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4793 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4794 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4800 /* Given a BFD section, try to locate the corresponding ELF section
4804 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4805 asection
*sec
, int *index_return
)
4807 if (sec
== &_bfd_elf_large_com_section
)
4809 *index_return
= SHN_X86_64_LCOMMON
;
4815 /* Process a symbol. */
4818 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4821 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4823 switch (elfsym
->internal_elf_sym
.st_shndx
)
4825 case SHN_X86_64_LCOMMON
:
4826 asym
->section
= &_bfd_elf_large_com_section
;
4827 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4828 /* Common symbol doesn't set BSF_GLOBAL. */
4829 asym
->flags
&= ~BSF_GLOBAL
;
4835 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4837 return (sym
->st_shndx
== SHN_COMMON
4838 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4842 elf_x86_64_common_section_index (asection
*sec
)
4844 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4847 return SHN_X86_64_LCOMMON
;
4851 elf_x86_64_common_section (asection
*sec
)
4853 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4854 return bfd_com_section_ptr
;
4856 return &_bfd_elf_large_com_section
;
4860 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4861 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4862 struct elf_link_hash_entry
*h
,
4863 Elf_Internal_Sym
*sym
,
4865 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4866 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4867 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4868 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4869 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4870 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4871 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4872 bfd_boolean
*newdef
,
4873 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4874 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4875 bfd
*abfd ATTRIBUTE_UNUSED
,
4877 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4878 bfd_boolean
*olddef
,
4879 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4880 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4884 /* A normal common symbol and a large common symbol result in a
4885 normal common symbol. We turn the large common symbol into a
4888 && h
->root
.type
== bfd_link_hash_common
4890 && bfd_is_com_section (*sec
)
4893 if (sym
->st_shndx
== SHN_COMMON
4894 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4896 h
->root
.u
.c
.p
->section
4897 = bfd_make_section_old_way (oldbfd
, "COMMON");
4898 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4900 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4901 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4902 *psec
= *sec
= bfd_com_section_ptr
;
4909 elf_x86_64_additional_program_headers (bfd
*abfd
,
4910 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4915 /* Check to see if we need a large readonly segment. */
4916 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4917 if (s
&& (s
->flags
& SEC_LOAD
))
4920 /* Check to see if we need a large data segment. Since .lbss sections
4921 is placed right after the .bss section, there should be no need for
4922 a large data segment just because of .lbss. */
4923 s
= bfd_get_section_by_name (abfd
, ".ldata");
4924 if (s
&& (s
->flags
& SEC_LOAD
))
4930 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4933 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4935 if (h
->plt
.offset
!= (bfd_vma
) -1
4937 && !h
->pointer_equality_needed
)
4940 return _bfd_elf_hash_symbol (h
);
4943 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4946 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4947 const bfd_target
*output
)
4949 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4950 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4951 && _bfd_elf_relocs_compatible (input
, output
));
4954 static const struct bfd_elf_special_section
4955 elf_x86_64_special_sections
[]=
4957 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4958 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4959 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4960 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4961 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4962 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4963 { NULL
, 0, 0, 0, 0 }
4966 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4967 #define TARGET_LITTLE_NAME "elf64-x86-64"
4968 #define ELF_ARCH bfd_arch_i386
4969 #define ELF_TARGET_ID X86_64_ELF_DATA
4970 #define ELF_MACHINE_CODE EM_X86_64
4971 #define ELF_MAXPAGESIZE 0x200000
4972 #define ELF_MINPAGESIZE 0x1000
4973 #define ELF_COMMONPAGESIZE 0x1000
4975 #define elf_backend_can_gc_sections 1
4976 #define elf_backend_can_refcount 1
4977 #define elf_backend_want_got_plt 1
4978 #define elf_backend_plt_readonly 1
4979 #define elf_backend_want_plt_sym 0
4980 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4981 #define elf_backend_rela_normal 1
4982 #define elf_backend_plt_alignment 4
4984 #define elf_info_to_howto elf_x86_64_info_to_howto
4986 #define bfd_elf64_bfd_link_hash_table_create \
4987 elf_x86_64_link_hash_table_create
4988 #define bfd_elf64_bfd_link_hash_table_free \
4989 elf_x86_64_link_hash_table_free
4990 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4991 #define bfd_elf64_bfd_reloc_name_lookup \
4992 elf_x86_64_reloc_name_lookup
4994 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4995 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4996 #define elf_backend_check_relocs elf_x86_64_check_relocs
4997 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
4998 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
4999 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
5000 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
5001 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
5002 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
5003 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
5004 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
5006 #define elf_backend_write_core_note elf_x86_64_write_core_note
5008 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
5009 #define elf_backend_relocate_section elf_x86_64_relocate_section
5010 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
5011 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
5012 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
5013 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
5014 #define elf_backend_object_p elf64_x86_64_elf_object_p
5015 #define bfd_elf64_mkobject elf_x86_64_mkobject
5017 #define elf_backend_section_from_shdr \
5018 elf_x86_64_section_from_shdr
5020 #define elf_backend_section_from_bfd_section \
5021 elf_x86_64_elf_section_from_bfd_section
5022 #define elf_backend_add_symbol_hook \
5023 elf_x86_64_add_symbol_hook
5024 #define elf_backend_symbol_processing \
5025 elf_x86_64_symbol_processing
5026 #define elf_backend_common_section_index \
5027 elf_x86_64_common_section_index
5028 #define elf_backend_common_section \
5029 elf_x86_64_common_section
5030 #define elf_backend_common_definition \
5031 elf_x86_64_common_definition
5032 #define elf_backend_merge_symbol \
5033 elf_x86_64_merge_symbol
5034 #define elf_backend_special_sections \
5035 elf_x86_64_special_sections
5036 #define elf_backend_additional_program_headers \
5037 elf_x86_64_additional_program_headers
5038 #define elf_backend_hash_symbol \
5039 elf_x86_64_hash_symbol
5041 #define elf_backend_post_process_headers _bfd_elf_set_osabi
5043 #include "elf64-target.h"
5045 /* FreeBSD support. */
5047 #undef TARGET_LITTLE_SYM
5048 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
5049 #undef TARGET_LITTLE_NAME
5050 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
5053 #define ELF_OSABI ELFOSABI_FREEBSD
5056 #define elf64_bed elf64_x86_64_fbsd_bed
5058 #include "elf64-target.h"
5060 /* Solaris 2 support. */
5062 #undef TARGET_LITTLE_SYM
5063 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
5064 #undef TARGET_LITTLE_NAME
5065 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
5067 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
5068 objects won't be recognized. */
5072 #define elf64_bed elf64_x86_64_sol2_bed
5074 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
5076 #undef elf_backend_static_tls_alignment
5077 #define elf_backend_static_tls_alignment 16
5079 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5081 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5083 #undef elf_backend_want_plt_sym
5084 #define elf_backend_want_plt_sym 1
5086 #include "elf64-target.h"
5088 /* Intel L1OM support. */
5091 elf64_l1om_elf_object_p (bfd
*abfd
)
5093 /* Set the right machine number for an L1OM elf64 file. */
5094 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5098 #undef TARGET_LITTLE_SYM
5099 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5100 #undef TARGET_LITTLE_NAME
5101 #define TARGET_LITTLE_NAME "elf64-l1om"
5103 #define ELF_ARCH bfd_arch_l1om
5105 #undef ELF_MACHINE_CODE
5106 #define ELF_MACHINE_CODE EM_L1OM
5111 #define elf64_bed elf64_l1om_bed
5113 #undef elf_backend_object_p
5114 #define elf_backend_object_p elf64_l1om_elf_object_p
5116 #undef elf_backend_static_tls_alignment
5118 #undef elf_backend_want_plt_sym
5119 #define elf_backend_want_plt_sym 0
5121 #include "elf64-target.h"
5123 /* FreeBSD L1OM support. */
5125 #undef TARGET_LITTLE_SYM
5126 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5127 #undef TARGET_LITTLE_NAME
5128 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5131 #define ELF_OSABI ELFOSABI_FREEBSD
5134 #define elf64_bed elf64_l1om_fbsd_bed
5136 #include "elf64-target.h"
5138 /* Intel K1OM support. */
5141 elf64_k1om_elf_object_p (bfd
*abfd
)
5143 /* Set the right machine number for an K1OM elf64 file. */
5144 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5148 #undef TARGET_LITTLE_SYM
5149 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5150 #undef TARGET_LITTLE_NAME
5151 #define TARGET_LITTLE_NAME "elf64-k1om"
5153 #define ELF_ARCH bfd_arch_k1om
5155 #undef ELF_MACHINE_CODE
5156 #define ELF_MACHINE_CODE EM_K1OM
5161 #define elf64_bed elf64_k1om_bed
5163 #undef elf_backend_object_p
5164 #define elf_backend_object_p elf64_k1om_elf_object_p
5166 #undef elf_backend_static_tls_alignment
5168 #undef elf_backend_want_plt_sym
5169 #define elf_backend_want_plt_sym 0
5171 #include "elf64-target.h"
5173 /* FreeBSD K1OM support. */
5175 #undef TARGET_LITTLE_SYM
5176 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5177 #undef TARGET_LITTLE_NAME
5178 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5181 #define ELF_OSABI ELFOSABI_FREEBSD
5184 #define elf64_bed elf64_k1om_fbsd_bed
5186 #include "elf64-target.h"
5188 /* 32bit x86-64 support. */
5191 elf32_x86_64_elf_object_p (bfd
*abfd
)
5193 /* Set the right machine number for an x86-64 elf32 file. */
5194 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
5198 #undef TARGET_LITTLE_SYM
5199 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5200 #undef TARGET_LITTLE_NAME
5201 #define TARGET_LITTLE_NAME "elf32-x86-64"
5204 #define ELF_ARCH bfd_arch_i386
5206 #undef ELF_MACHINE_CODE
5207 #define ELF_MACHINE_CODE EM_X86_64
5209 #define bfd_elf32_bfd_link_hash_table_create \
5210 elf_x86_64_link_hash_table_create
5211 #define bfd_elf32_bfd_link_hash_table_free \
5212 elf_x86_64_link_hash_table_free
5213 #define bfd_elf32_bfd_reloc_type_lookup \
5214 elf_x86_64_reloc_type_lookup
5215 #define bfd_elf32_bfd_reloc_name_lookup \
5216 elf_x86_64_reloc_name_lookup
5217 #define bfd_elf32_mkobject \
5222 #undef elf_backend_object_p
5223 #define elf_backend_object_p \
5224 elf32_x86_64_elf_object_p
5226 #undef elf_backend_bfd_from_remote_memory
5227 #define elf_backend_bfd_from_remote_memory \
5228 _bfd_elf32_bfd_from_remote_memory
5230 #undef elf_backend_size_info
5231 #define elf_backend_size_info \
5232 _bfd_elf32_size_info
5234 #include "elf32-target.h"