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
);
426 const char *fname
, *psargs
;
437 va_start (ap
, note_type
);
438 fname
= va_arg (ap
, const char *);
439 psargs
= va_arg (ap
, const char *);
442 if (bed
->s
->elfclass
== ELFCLASS32
)
445 memset (&data
, 0, sizeof (data
));
446 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
447 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
448 p
= (const void *) &data
;
449 size
= sizeof (data
);
454 memset (&data
, 0, sizeof (data
));
455 strncpy (data
.pr_fname
, fname
, sizeof (data
.pr_fname
));
456 strncpy (data
.pr_psargs
, psargs
, sizeof (data
.pr_psargs
));
457 p
= (const void *) &data
;
458 size
= sizeof (data
);
463 va_start (ap
, note_type
);
464 pid
= va_arg (ap
, long);
465 cursig
= va_arg (ap
, int);
466 gregs
= va_arg (ap
, const void *);
469 if (bed
->s
->elfclass
== ELFCLASS32
)
471 if (bed
->elf_machine_code
== EM_X86_64
)
473 prstatusx32_t prstat
;
474 memset (&prstat
, 0, sizeof (prstat
));
476 prstat
.pr_cursig
= cursig
;
477 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
478 p
= (const void *) &prstat
;
479 size
= sizeof (prstat
);
484 memset (&prstat
, 0, sizeof (prstat
));
486 prstat
.pr_cursig
= cursig
;
487 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
488 p
= (const void *) &prstat
;
489 size
= sizeof (prstat
);
495 memset (&prstat
, 0, sizeof (prstat
));
497 prstat
.pr_cursig
= cursig
;
498 memcpy (&prstat
.pr_reg
, gregs
, sizeof (prstat
.pr_reg
));
499 p
= (const void *) &prstat
;
500 size
= sizeof (prstat
);
505 return elfcore_write_note (abfd
, buf
, bufsiz
, "CORE", note_type
, p
,
510 /* Functions for the x86-64 ELF linker. */
512 /* The name of the dynamic interpreter. This is put in the .interp
515 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
516 #define ELF32_DYNAMIC_INTERPRETER "/lib/ld32.so.1"
518 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
519 copying dynamic variables from a shared lib into an app's dynbss
520 section, and instead use a dynamic relocation to point into the
522 #define ELIMINATE_COPY_RELOCS 1
524 /* The size in bytes of an entry in the global offset table. */
526 #define GOT_ENTRY_SIZE 8
528 /* The size in bytes of an entry in the procedure linkage table. */
530 #define PLT_ENTRY_SIZE 16
532 /* The first entry in a procedure linkage table looks like this. See the
533 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
535 static const bfd_byte elf_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
537 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
538 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
539 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
542 /* Subsequent entries in a procedure linkage table look like this. */
544 static const bfd_byte elf_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
546 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
547 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
548 0x68, /* pushq immediate */
549 0, 0, 0, 0, /* replaced with index into relocation table. */
550 0xe9, /* jmp relative */
551 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
554 /* .eh_frame covering the .plt section. */
556 static const bfd_byte elf_x86_64_eh_frame_plt
[] =
558 #define PLT_CIE_LENGTH 20
559 #define PLT_FDE_LENGTH 36
560 #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8
561 #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12
562 PLT_CIE_LENGTH
, 0, 0, 0, /* CIE length */
563 0, 0, 0, 0, /* CIE ID */
565 'z', 'R', 0, /* Augmentation string */
566 1, /* Code alignment factor */
567 0x78, /* Data alignment factor */
568 16, /* Return address column */
569 1, /* Augmentation size */
570 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding */
571 DW_CFA_def_cfa
, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */
572 DW_CFA_offset
+ 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */
573 DW_CFA_nop
, DW_CFA_nop
,
575 PLT_FDE_LENGTH
, 0, 0, 0, /* FDE length */
576 PLT_CIE_LENGTH
+ 8, 0, 0, 0, /* CIE pointer */
577 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */
578 0, 0, 0, 0, /* .plt size goes here */
579 0, /* Augmentation size */
580 DW_CFA_def_cfa_offset
, 16, /* DW_CFA_def_cfa_offset: 16 */
581 DW_CFA_advance_loc
+ 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
582 DW_CFA_def_cfa_offset
, 24, /* DW_CFA_def_cfa_offset: 24 */
583 DW_CFA_advance_loc
+ 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
584 DW_CFA_def_cfa_expression
, /* DW_CFA_def_cfa_expression */
585 11, /* Block length */
586 DW_OP_breg7
, 8, /* DW_OP_breg7 (rsp): 8 */
587 DW_OP_breg16
, 0, /* DW_OP_breg16 (rip): 0 */
588 DW_OP_lit15
, DW_OP_and
, DW_OP_lit11
, DW_OP_ge
,
589 DW_OP_lit3
, DW_OP_shl
, DW_OP_plus
,
590 DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
, DW_CFA_nop
593 /* x86-64 ELF linker hash entry. */
595 struct elf_x86_64_link_hash_entry
597 struct elf_link_hash_entry elf
;
599 /* Track dynamic relocs copied for this symbol. */
600 struct elf_dyn_relocs
*dyn_relocs
;
602 #define GOT_UNKNOWN 0
606 #define GOT_TLS_GDESC 4
607 #define GOT_TLS_GD_BOTH_P(type) \
608 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
609 #define GOT_TLS_GD_P(type) \
610 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
611 #define GOT_TLS_GDESC_P(type) \
612 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
613 #define GOT_TLS_GD_ANY_P(type) \
614 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
615 unsigned char tls_type
;
617 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
618 starting at the end of the jump table. */
622 #define elf_x86_64_hash_entry(ent) \
623 ((struct elf_x86_64_link_hash_entry *)(ent))
625 struct elf_x86_64_obj_tdata
627 struct elf_obj_tdata root
;
629 /* tls_type for each local got entry. */
630 char *local_got_tls_type
;
632 /* GOTPLT entries for TLS descriptors. */
633 bfd_vma
*local_tlsdesc_gotent
;
636 #define elf_x86_64_tdata(abfd) \
637 ((struct elf_x86_64_obj_tdata *) (abfd)->tdata.any)
639 #define elf_x86_64_local_got_tls_type(abfd) \
640 (elf_x86_64_tdata (abfd)->local_got_tls_type)
642 #define elf_x86_64_local_tlsdesc_gotent(abfd) \
643 (elf_x86_64_tdata (abfd)->local_tlsdesc_gotent)
645 #define is_x86_64_elf(bfd) \
646 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
647 && elf_tdata (bfd) != NULL \
648 && elf_object_id (bfd) == X86_64_ELF_DATA)
651 elf_x86_64_mkobject (bfd
*abfd
)
653 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_x86_64_obj_tdata
),
657 /* x86-64 ELF linker hash table. */
659 struct elf_x86_64_link_hash_table
661 struct elf_link_hash_table elf
;
663 /* Short-cuts to get to dynamic linker sections. */
666 asection
*plt_eh_frame
;
670 bfd_signed_vma refcount
;
674 /* The amount of space used by the jump slots in the GOT. */
675 bfd_vma sgotplt_jump_table_size
;
677 /* Small local sym cache. */
678 struct sym_cache sym_cache
;
680 bfd_vma (*r_info
) (bfd_vma
, bfd_vma
);
681 bfd_vma (*r_sym
) (bfd_vma
);
682 unsigned int pointer_r_type
;
683 const char *dynamic_interpreter
;
684 int dynamic_interpreter_size
;
686 /* _TLS_MODULE_BASE_ symbol. */
687 struct bfd_link_hash_entry
*tls_module_base
;
689 /* Used by local STT_GNU_IFUNC symbols. */
690 htab_t loc_hash_table
;
691 void * loc_hash_memory
;
693 /* The offset into splt of the PLT entry for the TLS descriptor
694 resolver. Special values are 0, if not necessary (or not found
695 to be necessary yet), and -1 if needed but not determined
698 /* The offset into sgot of the GOT entry used by the PLT entry
703 /* Get the x86-64 ELF linker hash table from a link_info structure. */
705 #define elf_x86_64_hash_table(p) \
706 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
707 == X86_64_ELF_DATA ? ((struct elf_x86_64_link_hash_table *) ((p)->hash)) : NULL)
709 #define elf_x86_64_compute_jump_table_size(htab) \
710 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
712 /* Create an entry in an x86-64 ELF linker hash table. */
714 static struct bfd_hash_entry
*
715 elf_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
716 struct bfd_hash_table
*table
,
719 /* Allocate the structure if it has not already been allocated by a
723 entry
= (struct bfd_hash_entry
*)
724 bfd_hash_allocate (table
,
725 sizeof (struct elf_x86_64_link_hash_entry
));
730 /* Call the allocation method of the superclass. */
731 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
734 struct elf_x86_64_link_hash_entry
*eh
;
736 eh
= (struct elf_x86_64_link_hash_entry
*) entry
;
737 eh
->dyn_relocs
= NULL
;
738 eh
->tls_type
= GOT_UNKNOWN
;
739 eh
->tlsdesc_got
= (bfd_vma
) -1;
745 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
746 for local symbol so that we can handle local STT_GNU_IFUNC symbols
747 as global symbol. We reuse indx and dynstr_index for local symbol
748 hash since they aren't used by global symbols in this backend. */
751 elf_x86_64_local_htab_hash (const void *ptr
)
753 struct elf_link_hash_entry
*h
754 = (struct elf_link_hash_entry
*) ptr
;
755 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
758 /* Compare local hash entries. */
761 elf_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
763 struct elf_link_hash_entry
*h1
764 = (struct elf_link_hash_entry
*) ptr1
;
765 struct elf_link_hash_entry
*h2
766 = (struct elf_link_hash_entry
*) ptr2
;
768 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
771 /* Find and/or create a hash entry for local symbol. */
773 static struct elf_link_hash_entry
*
774 elf_x86_64_get_local_sym_hash (struct elf_x86_64_link_hash_table
*htab
,
775 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
778 struct elf_x86_64_link_hash_entry e
, *ret
;
779 asection
*sec
= abfd
->sections
;
780 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
781 htab
->r_sym (rel
->r_info
));
784 e
.elf
.indx
= sec
->id
;
785 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
786 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
787 create
? INSERT
: NO_INSERT
);
794 ret
= (struct elf_x86_64_link_hash_entry
*) *slot
;
798 ret
= (struct elf_x86_64_link_hash_entry
*)
799 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
800 sizeof (struct elf_x86_64_link_hash_entry
));
803 memset (ret
, 0, sizeof (*ret
));
804 ret
->elf
.indx
= sec
->id
;
805 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
806 ret
->elf
.dynindx
= -1;
812 /* Create an X86-64 ELF linker hash table. */
814 static struct bfd_link_hash_table
*
815 elf_x86_64_link_hash_table_create (bfd
*abfd
)
817 struct elf_x86_64_link_hash_table
*ret
;
818 bfd_size_type amt
= sizeof (struct elf_x86_64_link_hash_table
);
820 ret
= (struct elf_x86_64_link_hash_table
*) bfd_malloc (amt
);
824 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
825 elf_x86_64_link_hash_newfunc
,
826 sizeof (struct elf_x86_64_link_hash_entry
),
835 ret
->plt_eh_frame
= NULL
;
836 ret
->sym_cache
.abfd
= NULL
;
837 ret
->tlsdesc_plt
= 0;
838 ret
->tlsdesc_got
= 0;
839 ret
->tls_ld_got
.refcount
= 0;
840 ret
->sgotplt_jump_table_size
= 0;
841 ret
->tls_module_base
= NULL
;
845 ret
->r_info
= elf64_r_info
;
846 ret
->r_sym
= elf64_r_sym
;
847 ret
->pointer_r_type
= R_X86_64_64
;
848 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
849 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
853 ret
->r_info
= elf32_r_info
;
854 ret
->r_sym
= elf32_r_sym
;
855 ret
->pointer_r_type
= R_X86_64_32
;
856 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
857 ret
->dynamic_interpreter_size
= sizeof ELF32_DYNAMIC_INTERPRETER
;
860 ret
->loc_hash_table
= htab_try_create (1024,
861 elf_x86_64_local_htab_hash
,
862 elf_x86_64_local_htab_eq
,
864 ret
->loc_hash_memory
= objalloc_create ();
865 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
871 return &ret
->elf
.root
;
874 /* Destroy an X86-64 ELF linker hash table. */
877 elf_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
879 struct elf_x86_64_link_hash_table
*htab
880 = (struct elf_x86_64_link_hash_table
*) hash
;
882 if (htab
->loc_hash_table
)
883 htab_delete (htab
->loc_hash_table
);
884 if (htab
->loc_hash_memory
)
885 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
886 _bfd_generic_link_hash_table_free (hash
);
889 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
890 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
894 elf_x86_64_create_dynamic_sections (bfd
*dynobj
,
895 struct bfd_link_info
*info
)
897 struct elf_x86_64_link_hash_table
*htab
;
899 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
902 htab
= elf_x86_64_hash_table (info
);
906 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
908 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
911 || (!info
->shared
&& !htab
->srelbss
))
914 if (!info
->no_ld_generated_unwind_info
915 && bfd_get_section_by_name (dynobj
, ".eh_frame") == NULL
916 && htab
->elf
.splt
!= NULL
)
918 flagword flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
920 = bfd_make_section_with_flags (dynobj
, ".eh_frame",
921 flags
| SEC_READONLY
);
922 if (htab
->plt_eh_frame
== NULL
923 || !bfd_set_section_alignment (dynobj
, htab
->plt_eh_frame
, 3))
926 htab
->plt_eh_frame
->size
= sizeof (elf_x86_64_eh_frame_plt
);
927 htab
->plt_eh_frame
->contents
928 = bfd_alloc (dynobj
, htab
->plt_eh_frame
->size
);
929 memcpy (htab
->plt_eh_frame
->contents
, elf_x86_64_eh_frame_plt
,
930 sizeof (elf_x86_64_eh_frame_plt
));
935 /* Copy the extra info we tack onto an elf_link_hash_entry. */
938 elf_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
939 struct elf_link_hash_entry
*dir
,
940 struct elf_link_hash_entry
*ind
)
942 struct elf_x86_64_link_hash_entry
*edir
, *eind
;
944 edir
= (struct elf_x86_64_link_hash_entry
*) dir
;
945 eind
= (struct elf_x86_64_link_hash_entry
*) ind
;
947 if (eind
->dyn_relocs
!= NULL
)
949 if (edir
->dyn_relocs
!= NULL
)
951 struct elf_dyn_relocs
**pp
;
952 struct elf_dyn_relocs
*p
;
954 /* Add reloc counts against the indirect sym to the direct sym
955 list. Merge any entries against the same section. */
956 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
958 struct elf_dyn_relocs
*q
;
960 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
961 if (q
->sec
== p
->sec
)
963 q
->pc_count
+= p
->pc_count
;
964 q
->count
+= p
->count
;
971 *pp
= edir
->dyn_relocs
;
974 edir
->dyn_relocs
= eind
->dyn_relocs
;
975 eind
->dyn_relocs
= NULL
;
978 if (ind
->root
.type
== bfd_link_hash_indirect
979 && dir
->got
.refcount
<= 0)
981 edir
->tls_type
= eind
->tls_type
;
982 eind
->tls_type
= GOT_UNKNOWN
;
985 if (ELIMINATE_COPY_RELOCS
986 && ind
->root
.type
!= bfd_link_hash_indirect
987 && dir
->dynamic_adjusted
)
989 /* If called to transfer flags for a weakdef during processing
990 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
991 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
992 dir
->ref_dynamic
|= ind
->ref_dynamic
;
993 dir
->ref_regular
|= ind
->ref_regular
;
994 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
995 dir
->needs_plt
|= ind
->needs_plt
;
996 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
999 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1003 elf64_x86_64_elf_object_p (bfd
*abfd
)
1005 /* Set the right machine number for an x86-64 elf64 file. */
1006 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
1010 /* Return TRUE if the TLS access code sequence support transition
1014 elf_x86_64_check_tls_transition (bfd
*abfd
,
1015 struct bfd_link_info
*info
,
1018 Elf_Internal_Shdr
*symtab_hdr
,
1019 struct elf_link_hash_entry
**sym_hashes
,
1020 unsigned int r_type
,
1021 const Elf_Internal_Rela
*rel
,
1022 const Elf_Internal_Rela
*relend
)
1025 unsigned long r_symndx
;
1026 struct elf_link_hash_entry
*h
;
1028 struct elf_x86_64_link_hash_table
*htab
;
1030 /* Get the section contents. */
1031 if (contents
== NULL
)
1033 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1034 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1037 /* FIXME: How to better handle error condition? */
1038 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1041 /* Cache the section contents for elf_link_input_bfd. */
1042 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1046 htab
= elf_x86_64_hash_table (info
);
1047 offset
= rel
->r_offset
;
1050 case R_X86_64_TLSGD
:
1051 case R_X86_64_TLSLD
:
1052 if ((rel
+ 1) >= relend
)
1055 if (r_type
== R_X86_64_TLSGD
)
1057 /* Check transition from GD access model. For 64bit, only
1058 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
1059 .word 0x6666; rex64; call __tls_get_addr
1060 can transit to different access model. For 32bit, only
1061 leaq foo@tlsgd(%rip), %rdi
1062 .word 0x6666; rex64; call __tls_get_addr
1063 can transit to different access model. */
1065 static const unsigned char call
[] = { 0x66, 0x66, 0x48, 0xe8 };
1066 static const unsigned char leaq
[] = { 0x66, 0x48, 0x8d, 0x3d };
1068 if ((offset
+ 12) > sec
->size
1069 || memcmp (contents
+ offset
+ 4, call
, 4) != 0)
1072 if (ABI_64_P (abfd
))
1075 || memcmp (contents
+ offset
- 4, leaq
, 4) != 0)
1081 || memcmp (contents
+ offset
- 3, leaq
+ 1, 3) != 0)
1087 /* Check transition from LD access model. Only
1088 leaq foo@tlsld(%rip), %rdi;
1090 can transit to different access model. */
1092 static const unsigned char lea
[] = { 0x48, 0x8d, 0x3d };
1094 if (offset
< 3 || (offset
+ 9) > sec
->size
)
1097 if (memcmp (contents
+ offset
- 3, lea
, 3) != 0
1098 || 0xe8 != *(contents
+ offset
+ 4))
1102 r_symndx
= htab
->r_sym (rel
[1].r_info
);
1103 if (r_symndx
< symtab_hdr
->sh_info
)
1106 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1107 /* Use strncmp to check __tls_get_addr since __tls_get_addr
1108 may be versioned. */
1110 && h
->root
.root
.string
!= NULL
1111 && (ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
1112 || ELF32_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
1113 && (strncmp (h
->root
.root
.string
,
1114 "__tls_get_addr", 14) == 0));
1116 case R_X86_64_GOTTPOFF
:
1117 /* Check transition from IE access model:
1118 mov foo@gottpoff(%rip), %reg
1119 add foo@gottpoff(%rip), %reg
1122 /* Check REX prefix first. */
1123 if (offset
>= 3 && (offset
+ 4) <= sec
->size
)
1125 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1126 if (val
!= 0x48 && val
!= 0x4c)
1128 /* X32 may have 0x44 REX prefix or no REX prefix. */
1129 if (ABI_64_P (abfd
))
1135 /* X32 may not have any REX prefix. */
1136 if (ABI_64_P (abfd
))
1138 if (offset
< 2 || (offset
+ 3) > sec
->size
)
1142 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
1143 if (val
!= 0x8b && val
!= 0x03)
1146 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1147 return (val
& 0xc7) == 5;
1149 case R_X86_64_GOTPC32_TLSDESC
:
1150 /* Check transition from GDesc access model:
1151 leaq x@tlsdesc(%rip), %rax
1153 Make sure it's a leaq adding rip to a 32-bit offset
1154 into any register, although it's probably almost always
1157 if (offset
< 3 || (offset
+ 4) > sec
->size
)
1160 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
1161 if ((val
& 0xfb) != 0x48)
1164 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
1167 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
1168 return (val
& 0xc7) == 0x05;
1170 case R_X86_64_TLSDESC_CALL
:
1171 /* Check transition from GDesc access model:
1172 call *x@tlsdesc(%rax)
1174 if (offset
+ 2 <= sec
->size
)
1176 /* Make sure that it's a call *x@tlsdesc(%rax). */
1177 static const unsigned char call
[] = { 0xff, 0x10 };
1178 return memcmp (contents
+ offset
, call
, 2) == 0;
1188 /* Return TRUE if the TLS access transition is OK or no transition
1189 will be performed. Update R_TYPE if there is a transition. */
1192 elf_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
1193 asection
*sec
, bfd_byte
*contents
,
1194 Elf_Internal_Shdr
*symtab_hdr
,
1195 struct elf_link_hash_entry
**sym_hashes
,
1196 unsigned int *r_type
, int tls_type
,
1197 const Elf_Internal_Rela
*rel
,
1198 const Elf_Internal_Rela
*relend
,
1199 struct elf_link_hash_entry
*h
,
1200 unsigned long r_symndx
)
1202 unsigned int from_type
= *r_type
;
1203 unsigned int to_type
= from_type
;
1204 bfd_boolean check
= TRUE
;
1206 /* Skip TLS transition for functions. */
1208 && (h
->type
== STT_FUNC
1209 || h
->type
== STT_GNU_IFUNC
))
1214 case R_X86_64_TLSGD
:
1215 case R_X86_64_GOTPC32_TLSDESC
:
1216 case R_X86_64_TLSDESC_CALL
:
1217 case R_X86_64_GOTTPOFF
:
1218 if (info
->executable
)
1221 to_type
= R_X86_64_TPOFF32
;
1223 to_type
= R_X86_64_GOTTPOFF
;
1226 /* When we are called from elf_x86_64_relocate_section,
1227 CONTENTS isn't NULL and there may be additional transitions
1228 based on TLS_TYPE. */
1229 if (contents
!= NULL
)
1231 unsigned int new_to_type
= to_type
;
1233 if (info
->executable
1236 && tls_type
== GOT_TLS_IE
)
1237 new_to_type
= R_X86_64_TPOFF32
;
1239 if (to_type
== R_X86_64_TLSGD
1240 || to_type
== R_X86_64_GOTPC32_TLSDESC
1241 || to_type
== R_X86_64_TLSDESC_CALL
)
1243 if (tls_type
== GOT_TLS_IE
)
1244 new_to_type
= R_X86_64_GOTTPOFF
;
1247 /* We checked the transition before when we were called from
1248 elf_x86_64_check_relocs. We only want to check the new
1249 transition which hasn't been checked before. */
1250 check
= new_to_type
!= to_type
&& from_type
== to_type
;
1251 to_type
= new_to_type
;
1256 case R_X86_64_TLSLD
:
1257 if (info
->executable
)
1258 to_type
= R_X86_64_TPOFF32
;
1265 /* Return TRUE if there is no transition. */
1266 if (from_type
== to_type
)
1269 /* Check if the transition can be performed. */
1271 && ! elf_x86_64_check_tls_transition (abfd
, info
, sec
, contents
,
1272 symtab_hdr
, sym_hashes
,
1273 from_type
, rel
, relend
))
1275 reloc_howto_type
*from
, *to
;
1278 from
= elf_x86_64_rtype_to_howto (abfd
, from_type
);
1279 to
= elf_x86_64_rtype_to_howto (abfd
, to_type
);
1282 name
= h
->root
.root
.string
;
1285 struct elf_x86_64_link_hash_table
*htab
;
1287 htab
= elf_x86_64_hash_table (info
);
1292 Elf_Internal_Sym
*isym
;
1294 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1296 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1300 (*_bfd_error_handler
)
1301 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1302 "in section `%A' failed"),
1303 abfd
, sec
, from
->name
, to
->name
, name
,
1304 (unsigned long) rel
->r_offset
);
1305 bfd_set_error (bfd_error_bad_value
);
1313 /* Look through the relocs for a section during the first phase, and
1314 calculate needed space in the global offset table, procedure
1315 linkage table, and dynamic reloc sections. */
1318 elf_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1320 const Elf_Internal_Rela
*relocs
)
1322 struct elf_x86_64_link_hash_table
*htab
;
1323 Elf_Internal_Shdr
*symtab_hdr
;
1324 struct elf_link_hash_entry
**sym_hashes
;
1325 const Elf_Internal_Rela
*rel
;
1326 const Elf_Internal_Rela
*rel_end
;
1329 if (info
->relocatable
)
1332 BFD_ASSERT (is_x86_64_elf (abfd
));
1334 htab
= elf_x86_64_hash_table (info
);
1338 symtab_hdr
= &elf_symtab_hdr (abfd
);
1339 sym_hashes
= elf_sym_hashes (abfd
);
1343 rel_end
= relocs
+ sec
->reloc_count
;
1344 for (rel
= relocs
; rel
< rel_end
; rel
++)
1346 unsigned int r_type
;
1347 unsigned long r_symndx
;
1348 struct elf_link_hash_entry
*h
;
1349 Elf_Internal_Sym
*isym
;
1352 r_symndx
= htab
->r_sym (rel
->r_info
);
1353 r_type
= ELF32_R_TYPE (rel
->r_info
);
1355 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1357 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1362 if (r_symndx
< symtab_hdr
->sh_info
)
1364 /* A local symbol. */
1365 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1370 /* Check relocation against local STT_GNU_IFUNC symbol. */
1371 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1373 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1378 /* Fake a STT_GNU_IFUNC symbol. */
1379 h
->type
= STT_GNU_IFUNC
;
1382 h
->forced_local
= 1;
1383 h
->root
.type
= bfd_link_hash_defined
;
1391 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1392 while (h
->root
.type
== bfd_link_hash_indirect
1393 || h
->root
.type
== bfd_link_hash_warning
)
1394 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1397 /* Check invalid x32 relocations. */
1398 if (!ABI_64_P (abfd
))
1404 case R_X86_64_DTPOFF64
:
1405 case R_X86_64_TPOFF64
:
1407 case R_X86_64_GOTOFF64
:
1408 case R_X86_64_GOT64
:
1409 case R_X86_64_GOTPCREL64
:
1410 case R_X86_64_GOTPC64
:
1411 case R_X86_64_GOTPLT64
:
1412 case R_X86_64_PLTOFF64
:
1415 name
= h
->root
.root
.string
;
1417 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1419 (*_bfd_error_handler
)
1420 (_("%B: relocation %s against symbol `%s' isn't "
1421 "supported in x32 mode"), abfd
,
1422 x86_64_elf_howto_table
[r_type
].name
, name
);
1423 bfd_set_error (bfd_error_bad_value
);
1431 /* Create the ifunc sections for static executables. If we
1432 never see an indirect function symbol nor we are building
1433 a static executable, those sections will be empty and
1434 won't appear in output. */
1445 case R_X86_64_PLT32
:
1446 case R_X86_64_GOTPCREL
:
1447 case R_X86_64_GOTPCREL64
:
1448 if (htab
->elf
.dynobj
== NULL
)
1449 htab
->elf
.dynobj
= abfd
;
1450 if (!_bfd_elf_create_ifunc_sections (htab
->elf
.dynobj
, info
))
1455 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1456 it here if it is defined in a non-shared object. */
1457 if (h
->type
== STT_GNU_IFUNC
1460 /* It is referenced by a non-shared object. */
1464 /* STT_GNU_IFUNC symbol must go through PLT. */
1465 h
->plt
.refcount
+= 1;
1467 /* STT_GNU_IFUNC needs dynamic sections. */
1468 if (htab
->elf
.dynobj
== NULL
)
1469 htab
->elf
.dynobj
= abfd
;
1474 if (h
->root
.root
.string
)
1475 name
= h
->root
.root
.string
;
1477 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1479 (*_bfd_error_handler
)
1480 (_("%B: relocation %s against STT_GNU_IFUNC "
1481 "symbol `%s' isn't handled by %s"), abfd
,
1482 x86_64_elf_howto_table
[r_type
].name
,
1483 name
, __FUNCTION__
);
1484 bfd_set_error (bfd_error_bad_value
);
1488 if (ABI_64_P (abfd
))
1492 h
->pointer_equality_needed
= 1;
1495 /* We must copy these reloc types into the output
1496 file. Create a reloc section in dynobj and
1497 make room for this reloc. */
1498 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1499 (abfd
, info
, sec
, sreloc
,
1500 &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1511 if (r_type
!= R_X86_64_PC32
1512 && r_type
!= R_X86_64_PC64
)
1513 h
->pointer_equality_needed
= 1;
1516 case R_X86_64_PLT32
:
1519 case R_X86_64_GOTPCREL
:
1520 case R_X86_64_GOTPCREL64
:
1521 h
->got
.refcount
+= 1;
1522 if (htab
->elf
.sgot
== NULL
1523 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1533 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1534 symtab_hdr
, sym_hashes
,
1535 &r_type
, GOT_UNKNOWN
,
1536 rel
, rel_end
, h
, r_symndx
))
1541 case R_X86_64_TLSLD
:
1542 htab
->tls_ld_got
.refcount
+= 1;
1545 case R_X86_64_TPOFF32
:
1546 if (!info
->executable
&& ABI_64_P (abfd
))
1549 name
= h
->root
.root
.string
;
1551 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1553 (*_bfd_error_handler
)
1554 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1556 x86_64_elf_howto_table
[r_type
].name
, name
);
1557 bfd_set_error (bfd_error_bad_value
);
1562 case R_X86_64_GOTTPOFF
:
1563 if (!info
->executable
)
1564 info
->flags
|= DF_STATIC_TLS
;
1567 case R_X86_64_GOT32
:
1568 case R_X86_64_GOTPCREL
:
1569 case R_X86_64_TLSGD
:
1570 case R_X86_64_GOT64
:
1571 case R_X86_64_GOTPCREL64
:
1572 case R_X86_64_GOTPLT64
:
1573 case R_X86_64_GOTPC32_TLSDESC
:
1574 case R_X86_64_TLSDESC_CALL
:
1575 /* This symbol requires a global offset table entry. */
1577 int tls_type
, old_tls_type
;
1581 default: tls_type
= GOT_NORMAL
; break;
1582 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1583 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1584 case R_X86_64_GOTPC32_TLSDESC
:
1585 case R_X86_64_TLSDESC_CALL
:
1586 tls_type
= GOT_TLS_GDESC
; break;
1591 if (r_type
== R_X86_64_GOTPLT64
)
1593 /* This relocation indicates that we also need
1594 a PLT entry, as this is a function. We don't need
1595 a PLT entry for local symbols. */
1597 h
->plt
.refcount
+= 1;
1599 h
->got
.refcount
+= 1;
1600 old_tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
1604 bfd_signed_vma
*local_got_refcounts
;
1606 /* This is a global offset table entry for a local symbol. */
1607 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1608 if (local_got_refcounts
== NULL
)
1612 size
= symtab_hdr
->sh_info
;
1613 size
*= sizeof (bfd_signed_vma
)
1614 + sizeof (bfd_vma
) + sizeof (char);
1615 local_got_refcounts
= ((bfd_signed_vma
*)
1616 bfd_zalloc (abfd
, size
));
1617 if (local_got_refcounts
== NULL
)
1619 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1620 elf_x86_64_local_tlsdesc_gotent (abfd
)
1621 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1622 elf_x86_64_local_got_tls_type (abfd
)
1623 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1625 local_got_refcounts
[r_symndx
] += 1;
1627 = elf_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1630 /* If a TLS symbol is accessed using IE at least once,
1631 there is no point to use dynamic model for it. */
1632 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1633 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1634 || tls_type
!= GOT_TLS_IE
))
1636 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1637 tls_type
= old_tls_type
;
1638 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1639 && GOT_TLS_GD_ANY_P (tls_type
))
1640 tls_type
|= old_tls_type
;
1644 name
= h
->root
.root
.string
;
1646 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1648 (*_bfd_error_handler
)
1649 (_("%B: '%s' accessed both as normal and thread local symbol"),
1655 if (old_tls_type
!= tls_type
)
1658 elf_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1660 elf_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1665 case R_X86_64_GOTOFF64
:
1666 case R_X86_64_GOTPC32
:
1667 case R_X86_64_GOTPC64
:
1669 if (htab
->elf
.sgot
== NULL
)
1671 if (htab
->elf
.dynobj
== NULL
)
1672 htab
->elf
.dynobj
= abfd
;
1673 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1679 case R_X86_64_PLT32
:
1680 /* This symbol requires a procedure linkage table entry. We
1681 actually build the entry in adjust_dynamic_symbol,
1682 because this might be a case of linking PIC code which is
1683 never referenced by a dynamic object, in which case we
1684 don't need to generate a procedure linkage table entry
1687 /* If this is a local symbol, we resolve it directly without
1688 creating a procedure linkage table entry. */
1693 h
->plt
.refcount
+= 1;
1696 case R_X86_64_PLTOFF64
:
1697 /* This tries to form the 'address' of a function relative
1698 to GOT. For global symbols we need a PLT entry. */
1702 h
->plt
.refcount
+= 1;
1707 if (!ABI_64_P (abfd
))
1712 /* Let's help debug shared library creation. These relocs
1713 cannot be used in shared libs. Don't error out for
1714 sections we don't care about, such as debug sections or
1715 non-constant sections. */
1717 && (sec
->flags
& SEC_ALLOC
) != 0
1718 && (sec
->flags
& SEC_READONLY
) != 0)
1721 name
= h
->root
.root
.string
;
1723 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1724 (*_bfd_error_handler
)
1725 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1726 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1727 bfd_set_error (bfd_error_bad_value
);
1738 if (h
!= NULL
&& info
->executable
)
1740 /* If this reloc is in a read-only section, we might
1741 need a copy reloc. We can't check reliably at this
1742 stage whether the section is read-only, as input
1743 sections have not yet been mapped to output sections.
1744 Tentatively set the flag for now, and correct in
1745 adjust_dynamic_symbol. */
1748 /* We may need a .plt entry if the function this reloc
1749 refers to is in a shared lib. */
1750 h
->plt
.refcount
+= 1;
1751 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1752 h
->pointer_equality_needed
= 1;
1755 /* If we are creating a shared library, and this is a reloc
1756 against a global symbol, or a non PC relative reloc
1757 against a local symbol, then we need to copy the reloc
1758 into the shared library. However, if we are linking with
1759 -Bsymbolic, we do not need to copy a reloc against a
1760 global symbol which is defined in an object we are
1761 including in the link (i.e., DEF_REGULAR is set). At
1762 this point we have not seen all the input files, so it is
1763 possible that DEF_REGULAR is not set now but will be set
1764 later (it is never cleared). In case of a weak definition,
1765 DEF_REGULAR may be cleared later by a strong definition in
1766 a shared library. We account for that possibility below by
1767 storing information in the relocs_copied field of the hash
1768 table entry. A similar situation occurs when creating
1769 shared libraries and symbol visibility changes render the
1772 If on the other hand, we are creating an executable, we
1773 may need to keep relocations for symbols satisfied by a
1774 dynamic library if we manage to avoid copy relocs for the
1777 && (sec
->flags
& SEC_ALLOC
) != 0
1778 && (! IS_X86_64_PCREL_TYPE (r_type
)
1780 && (! SYMBOLIC_BIND (info
, h
)
1781 || h
->root
.type
== bfd_link_hash_defweak
1782 || !h
->def_regular
))))
1783 || (ELIMINATE_COPY_RELOCS
1785 && (sec
->flags
& SEC_ALLOC
) != 0
1787 && (h
->root
.type
== bfd_link_hash_defweak
1788 || !h
->def_regular
)))
1790 struct elf_dyn_relocs
*p
;
1791 struct elf_dyn_relocs
**head
;
1793 /* We must copy these reloc types into the output file.
1794 Create a reloc section in dynobj and make room for
1798 if (htab
->elf
.dynobj
== NULL
)
1799 htab
->elf
.dynobj
= abfd
;
1801 sreloc
= _bfd_elf_make_dynamic_reloc_section
1802 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
1803 abfd
, /*rela?*/ TRUE
);
1809 /* If this is a global symbol, we count the number of
1810 relocations we need for this symbol. */
1813 head
= &((struct elf_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1817 /* Track dynamic relocs needed for local syms too.
1818 We really need local syms available to do this
1823 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1828 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1832 /* Beware of type punned pointers vs strict aliasing
1834 vpp
= &(elf_section_data (s
)->local_dynrel
);
1835 head
= (struct elf_dyn_relocs
**)vpp
;
1839 if (p
== NULL
|| p
->sec
!= sec
)
1841 bfd_size_type amt
= sizeof *p
;
1843 p
= ((struct elf_dyn_relocs
*)
1844 bfd_alloc (htab
->elf
.dynobj
, amt
));
1855 if (IS_X86_64_PCREL_TYPE (r_type
))
1860 /* This relocation describes the C++ object vtable hierarchy.
1861 Reconstruct it for later use during GC. */
1862 case R_X86_64_GNU_VTINHERIT
:
1863 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1867 /* This relocation describes which C++ vtable entries are actually
1868 used. Record for later use during GC. */
1869 case R_X86_64_GNU_VTENTRY
:
1870 BFD_ASSERT (h
!= NULL
);
1872 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1884 /* Return the section that should be marked against GC for a given
1888 elf_x86_64_gc_mark_hook (asection
*sec
,
1889 struct bfd_link_info
*info
,
1890 Elf_Internal_Rela
*rel
,
1891 struct elf_link_hash_entry
*h
,
1892 Elf_Internal_Sym
*sym
)
1895 switch (ELF32_R_TYPE (rel
->r_info
))
1897 case R_X86_64_GNU_VTINHERIT
:
1898 case R_X86_64_GNU_VTENTRY
:
1902 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1905 /* Update the got entry reference counts for the section being removed. */
1908 elf_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1910 const Elf_Internal_Rela
*relocs
)
1912 struct elf_x86_64_link_hash_table
*htab
;
1913 Elf_Internal_Shdr
*symtab_hdr
;
1914 struct elf_link_hash_entry
**sym_hashes
;
1915 bfd_signed_vma
*local_got_refcounts
;
1916 const Elf_Internal_Rela
*rel
, *relend
;
1918 if (info
->relocatable
)
1921 htab
= elf_x86_64_hash_table (info
);
1925 elf_section_data (sec
)->local_dynrel
= NULL
;
1927 symtab_hdr
= &elf_symtab_hdr (abfd
);
1928 sym_hashes
= elf_sym_hashes (abfd
);
1929 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1931 htab
= elf_x86_64_hash_table (info
);
1932 relend
= relocs
+ sec
->reloc_count
;
1933 for (rel
= relocs
; rel
< relend
; rel
++)
1935 unsigned long r_symndx
;
1936 unsigned int r_type
;
1937 struct elf_link_hash_entry
*h
= NULL
;
1939 r_symndx
= htab
->r_sym (rel
->r_info
);
1940 if (r_symndx
>= symtab_hdr
->sh_info
)
1942 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1943 while (h
->root
.type
== bfd_link_hash_indirect
1944 || h
->root
.type
== bfd_link_hash_warning
)
1945 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1949 /* A local symbol. */
1950 Elf_Internal_Sym
*isym
;
1952 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1955 /* Check relocation against local STT_GNU_IFUNC symbol. */
1957 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1959 h
= elf_x86_64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
1967 struct elf_x86_64_link_hash_entry
*eh
;
1968 struct elf_dyn_relocs
**pp
;
1969 struct elf_dyn_relocs
*p
;
1971 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
1973 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1976 /* Everything must go for SEC. */
1982 r_type
= ELF32_R_TYPE (rel
->r_info
);
1983 if (! elf_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1984 symtab_hdr
, sym_hashes
,
1985 &r_type
, GOT_UNKNOWN
,
1986 rel
, relend
, h
, r_symndx
))
1991 case R_X86_64_TLSLD
:
1992 if (htab
->tls_ld_got
.refcount
> 0)
1993 htab
->tls_ld_got
.refcount
-= 1;
1996 case R_X86_64_TLSGD
:
1997 case R_X86_64_GOTPC32_TLSDESC
:
1998 case R_X86_64_TLSDESC_CALL
:
1999 case R_X86_64_GOTTPOFF
:
2000 case R_X86_64_GOT32
:
2001 case R_X86_64_GOTPCREL
:
2002 case R_X86_64_GOT64
:
2003 case R_X86_64_GOTPCREL64
:
2004 case R_X86_64_GOTPLT64
:
2007 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
2008 h
->plt
.refcount
-= 1;
2009 if (h
->got
.refcount
> 0)
2010 h
->got
.refcount
-= 1;
2011 if (h
->type
== STT_GNU_IFUNC
)
2013 if (h
->plt
.refcount
> 0)
2014 h
->plt
.refcount
-= 1;
2017 else if (local_got_refcounts
!= NULL
)
2019 if (local_got_refcounts
[r_symndx
] > 0)
2020 local_got_refcounts
[r_symndx
] -= 1;
2034 && (h
== NULL
|| h
->type
!= STT_GNU_IFUNC
))
2038 case R_X86_64_PLT32
:
2039 case R_X86_64_PLTOFF64
:
2042 if (h
->plt
.refcount
> 0)
2043 h
->plt
.refcount
-= 1;
2055 /* Adjust a symbol defined by a dynamic object and referenced by a
2056 regular object. The current definition is in some section of the
2057 dynamic object, but we're not including those sections. We have to
2058 change the definition to something the rest of the link can
2062 elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2063 struct elf_link_hash_entry
*h
)
2065 struct elf_x86_64_link_hash_table
*htab
;
2068 /* STT_GNU_IFUNC symbol must go through PLT. */
2069 if (h
->type
== STT_GNU_IFUNC
)
2071 if (h
->plt
.refcount
<= 0)
2073 h
->plt
.offset
= (bfd_vma
) -1;
2079 /* If this is a function, put it in the procedure linkage table. We
2080 will fill in the contents of the procedure linkage table later,
2081 when we know the address of the .got section. */
2082 if (h
->type
== STT_FUNC
2085 if (h
->plt
.refcount
<= 0
2086 || SYMBOL_CALLS_LOCAL (info
, h
)
2087 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2088 && h
->root
.type
== bfd_link_hash_undefweak
))
2090 /* This case can occur if we saw a PLT32 reloc in an input
2091 file, but the symbol was never referred to by a dynamic
2092 object, or if all references were garbage collected. In
2093 such a case, we don't actually need to build a procedure
2094 linkage table, and we can just do a PC32 reloc instead. */
2095 h
->plt
.offset
= (bfd_vma
) -1;
2102 /* It's possible that we incorrectly decided a .plt reloc was
2103 needed for an R_X86_64_PC32 reloc to a non-function sym in
2104 check_relocs. We can't decide accurately between function and
2105 non-function syms in check-relocs; Objects loaded later in
2106 the link may change h->type. So fix it now. */
2107 h
->plt
.offset
= (bfd_vma
) -1;
2109 /* If this is a weak symbol, and there is a real definition, the
2110 processor independent code will have arranged for us to see the
2111 real definition first, and we can just use the same value. */
2112 if (h
->u
.weakdef
!= NULL
)
2114 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2115 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2116 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2117 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2118 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
2119 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2123 /* This is a reference to a symbol defined by a dynamic object which
2124 is not a function. */
2126 /* If we are creating a shared library, we must presume that the
2127 only references to the symbol are via the global offset table.
2128 For such cases we need not do anything here; the relocations will
2129 be handled correctly by relocate_section. */
2133 /* If there are no references to this symbol that do not use the
2134 GOT, we don't need to generate a copy reloc. */
2135 if (!h
->non_got_ref
)
2138 /* If -z nocopyreloc was given, we won't generate them either. */
2139 if (info
->nocopyreloc
)
2145 if (ELIMINATE_COPY_RELOCS
)
2147 struct elf_x86_64_link_hash_entry
* eh
;
2148 struct elf_dyn_relocs
*p
;
2150 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2151 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2153 s
= p
->sec
->output_section
;
2154 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2158 /* If we didn't find any dynamic relocs in read-only sections, then
2159 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2169 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
2170 h
->root
.root
.string
);
2174 /* We must allocate the symbol in our .dynbss section, which will
2175 become part of the .bss section of the executable. There will be
2176 an entry for this symbol in the .dynsym section. The dynamic
2177 object will contain position independent code, so all references
2178 from the dynamic object to this symbol will go through the global
2179 offset table. The dynamic linker will use the .dynsym entry to
2180 determine the address it must put in the global offset table, so
2181 both the dynamic object and the regular object will refer to the
2182 same memory location for the variable. */
2184 htab
= elf_x86_64_hash_table (info
);
2188 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
2189 to copy the initial value out of the dynamic object and into the
2190 runtime process image. */
2191 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2193 const struct elf_backend_data
*bed
;
2194 bed
= get_elf_backend_data (info
->output_bfd
);
2195 htab
->srelbss
->size
+= bed
->s
->sizeof_rela
;
2201 return _bfd_elf_adjust_dynamic_copy (h
, s
);
2204 /* Allocate space in .plt, .got and associated reloc sections for
2208 elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2210 struct bfd_link_info
*info
;
2211 struct elf_x86_64_link_hash_table
*htab
;
2212 struct elf_x86_64_link_hash_entry
*eh
;
2213 struct elf_dyn_relocs
*p
;
2214 const struct elf_backend_data
*bed
;
2216 if (h
->root
.type
== bfd_link_hash_indirect
)
2219 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2221 info
= (struct bfd_link_info
*) inf
;
2222 htab
= elf_x86_64_hash_table (info
);
2225 bed
= get_elf_backend_data (info
->output_bfd
);
2227 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
2228 here if it is defined and referenced in a non-shared object. */
2229 if (h
->type
== STT_GNU_IFUNC
2231 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
2235 else if (htab
->elf
.dynamic_sections_created
2236 && h
->plt
.refcount
> 0)
2238 /* Make sure this symbol is output as a dynamic symbol.
2239 Undefined weak syms won't yet be marked as dynamic. */
2240 if (h
->dynindx
== -1
2241 && !h
->forced_local
)
2243 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2248 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2250 asection
*s
= htab
->elf
.splt
;
2252 /* If this is the first .plt entry, make room for the special
2255 s
->size
+= PLT_ENTRY_SIZE
;
2257 h
->plt
.offset
= s
->size
;
2259 /* If this symbol is not defined in a regular file, and we are
2260 not generating a shared library, then set the symbol to this
2261 location in the .plt. This is required to make function
2262 pointers compare as equal between the normal executable and
2263 the shared library. */
2267 h
->root
.u
.def
.section
= s
;
2268 h
->root
.u
.def
.value
= h
->plt
.offset
;
2271 /* Make room for this entry. */
2272 s
->size
+= PLT_ENTRY_SIZE
;
2274 /* We also need to make an entry in the .got.plt section, which
2275 will be placed in the .got section by the linker script. */
2276 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
2278 /* We also need to make an entry in the .rela.plt section. */
2279 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2280 htab
->elf
.srelplt
->reloc_count
++;
2284 h
->plt
.offset
= (bfd_vma
) -1;
2290 h
->plt
.offset
= (bfd_vma
) -1;
2294 eh
->tlsdesc_got
= (bfd_vma
) -1;
2296 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
2297 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
2298 if (h
->got
.refcount
> 0
2301 && elf_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2303 h
->got
.offset
= (bfd_vma
) -1;
2305 else if (h
->got
.refcount
> 0)
2309 int tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
2311 /* Make sure this symbol is output as a dynamic symbol.
2312 Undefined weak syms won't yet be marked as dynamic. */
2313 if (h
->dynindx
== -1
2314 && !h
->forced_local
)
2316 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2320 if (GOT_TLS_GDESC_P (tls_type
))
2322 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2323 - elf_x86_64_compute_jump_table_size (htab
);
2324 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2325 h
->got
.offset
= (bfd_vma
) -2;
2327 if (! GOT_TLS_GDESC_P (tls_type
)
2328 || GOT_TLS_GD_P (tls_type
))
2331 h
->got
.offset
= s
->size
;
2332 s
->size
+= GOT_ENTRY_SIZE
;
2333 if (GOT_TLS_GD_P (tls_type
))
2334 s
->size
+= GOT_ENTRY_SIZE
;
2336 dyn
= htab
->elf
.dynamic_sections_created
;
2337 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2339 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2340 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2341 || tls_type
== GOT_TLS_IE
)
2342 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2343 else if (GOT_TLS_GD_P (tls_type
))
2344 htab
->elf
.srelgot
->size
+= 2 * bed
->s
->sizeof_rela
;
2345 else if (! GOT_TLS_GDESC_P (tls_type
)
2346 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2347 || h
->root
.type
!= bfd_link_hash_undefweak
)
2349 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2350 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2351 if (GOT_TLS_GDESC_P (tls_type
))
2353 htab
->elf
.srelplt
->size
+= bed
->s
->sizeof_rela
;
2354 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2358 h
->got
.offset
= (bfd_vma
) -1;
2360 if (eh
->dyn_relocs
== NULL
)
2363 /* In the shared -Bsymbolic case, discard space allocated for
2364 dynamic pc-relative relocs against symbols which turn out to be
2365 defined in regular objects. For the normal shared case, discard
2366 space for pc-relative relocs that have become local due to symbol
2367 visibility changes. */
2371 /* Relocs that use pc_count are those that appear on a call
2372 insn, or certain REL relocs that can generated via assembly.
2373 We want calls to protected symbols to resolve directly to the
2374 function rather than going via the plt. If people want
2375 function pointer comparisons to work as expected then they
2376 should avoid writing weird assembly. */
2377 if (SYMBOL_CALLS_LOCAL (info
, h
))
2379 struct elf_dyn_relocs
**pp
;
2381 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2383 p
->count
-= p
->pc_count
;
2392 /* Also discard relocs on undefined weak syms with non-default
2394 if (eh
->dyn_relocs
!= NULL
2395 && h
->root
.type
== bfd_link_hash_undefweak
)
2397 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2398 eh
->dyn_relocs
= NULL
;
2400 /* Make sure undefined weak symbols are output as a dynamic
2402 else if (h
->dynindx
== -1
2403 && ! h
->forced_local
2404 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2409 else if (ELIMINATE_COPY_RELOCS
)
2411 /* For the non-shared case, discard space for relocs against
2412 symbols which turn out to need copy relocs or are not
2418 || (htab
->elf
.dynamic_sections_created
2419 && (h
->root
.type
== bfd_link_hash_undefweak
2420 || h
->root
.type
== bfd_link_hash_undefined
))))
2422 /* Make sure this symbol is output as a dynamic symbol.
2423 Undefined weak syms won't yet be marked as dynamic. */
2424 if (h
->dynindx
== -1
2425 && ! h
->forced_local
2426 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2429 /* If that succeeded, we know we'll be keeping all the
2431 if (h
->dynindx
!= -1)
2435 eh
->dyn_relocs
= NULL
;
2440 /* Finally, allocate space. */
2441 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2445 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2447 BFD_ASSERT (sreloc
!= NULL
);
2449 sreloc
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2455 /* Allocate space in .plt, .got and associated reloc sections for
2456 local dynamic relocs. */
2459 elf_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2461 struct elf_link_hash_entry
*h
2462 = (struct elf_link_hash_entry
*) *slot
;
2464 if (h
->type
!= STT_GNU_IFUNC
2468 || h
->root
.type
!= bfd_link_hash_defined
)
2471 return elf_x86_64_allocate_dynrelocs (h
, inf
);
2474 /* Find any dynamic relocs that apply to read-only sections. */
2477 elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
,
2480 struct elf_x86_64_link_hash_entry
*eh
;
2481 struct elf_dyn_relocs
*p
;
2483 /* Skip local IFUNC symbols. */
2484 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
2487 eh
= (struct elf_x86_64_link_hash_entry
*) h
;
2488 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2490 asection
*s
= p
->sec
->output_section
;
2492 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2494 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2496 info
->flags
|= DF_TEXTREL
;
2498 if (info
->warn_shared_textrel
&& info
->shared
)
2499 info
->callbacks
->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
2500 p
->sec
->owner
, h
->root
.root
.string
,
2503 /* Not an error, just cut short the traversal. */
2510 /* Set the sizes of the dynamic sections. */
2513 elf_x86_64_size_dynamic_sections (bfd
*output_bfd
,
2514 struct bfd_link_info
*info
)
2516 struct elf_x86_64_link_hash_table
*htab
;
2521 const struct elf_backend_data
*bed
;
2523 htab
= elf_x86_64_hash_table (info
);
2526 bed
= get_elf_backend_data (output_bfd
);
2528 dynobj
= htab
->elf
.dynobj
;
2532 if (htab
->elf
.dynamic_sections_created
)
2534 /* Set the contents of the .interp section to the interpreter. */
2535 if (info
->executable
)
2537 s
= bfd_get_section_by_name (dynobj
, ".interp");
2540 s
->size
= htab
->dynamic_interpreter_size
;
2541 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2545 /* Set up .got offsets for local syms, and space for local dynamic
2547 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2549 bfd_signed_vma
*local_got
;
2550 bfd_signed_vma
*end_local_got
;
2551 char *local_tls_type
;
2552 bfd_vma
*local_tlsdesc_gotent
;
2553 bfd_size_type locsymcount
;
2554 Elf_Internal_Shdr
*symtab_hdr
;
2557 if (! is_x86_64_elf (ibfd
))
2560 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2562 struct elf_dyn_relocs
*p
;
2564 for (p
= (struct elf_dyn_relocs
*)
2565 (elf_section_data (s
)->local_dynrel
);
2569 if (!bfd_is_abs_section (p
->sec
)
2570 && bfd_is_abs_section (p
->sec
->output_section
))
2572 /* Input section has been discarded, either because
2573 it is a copy of a linkonce section or due to
2574 linker script /DISCARD/, so we'll be discarding
2577 else if (p
->count
!= 0)
2579 srel
= elf_section_data (p
->sec
)->sreloc
;
2580 srel
->size
+= p
->count
* bed
->s
->sizeof_rela
;
2581 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2582 && (info
->flags
& DF_TEXTREL
) == 0)
2584 info
->flags
|= DF_TEXTREL
;
2585 if (info
->warn_shared_textrel
&& info
->shared
)
2586 info
->callbacks
->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
2587 p
->sec
->owner
, p
->sec
);
2593 local_got
= elf_local_got_refcounts (ibfd
);
2597 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2598 locsymcount
= symtab_hdr
->sh_info
;
2599 end_local_got
= local_got
+ locsymcount
;
2600 local_tls_type
= elf_x86_64_local_got_tls_type (ibfd
);
2601 local_tlsdesc_gotent
= elf_x86_64_local_tlsdesc_gotent (ibfd
);
2603 srel
= htab
->elf
.srelgot
;
2604 for (; local_got
< end_local_got
;
2605 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2607 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2610 if (GOT_TLS_GDESC_P (*local_tls_type
))
2612 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2613 - elf_x86_64_compute_jump_table_size (htab
);
2614 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2615 *local_got
= (bfd_vma
) -2;
2617 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2618 || GOT_TLS_GD_P (*local_tls_type
))
2620 *local_got
= s
->size
;
2621 s
->size
+= GOT_ENTRY_SIZE
;
2622 if (GOT_TLS_GD_P (*local_tls_type
))
2623 s
->size
+= GOT_ENTRY_SIZE
;
2626 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2627 || *local_tls_type
== GOT_TLS_IE
)
2629 if (GOT_TLS_GDESC_P (*local_tls_type
))
2631 htab
->elf
.srelplt
->size
2632 += bed
->s
->sizeof_rela
;
2633 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2635 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2636 || GOT_TLS_GD_P (*local_tls_type
))
2637 srel
->size
+= bed
->s
->sizeof_rela
;
2641 *local_got
= (bfd_vma
) -1;
2645 if (htab
->tls_ld_got
.refcount
> 0)
2647 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2649 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2650 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2651 htab
->elf
.srelgot
->size
+= bed
->s
->sizeof_rela
;
2654 htab
->tls_ld_got
.offset
= -1;
2656 /* Allocate global sym .plt and .got entries, and space for global
2657 sym dynamic relocs. */
2658 elf_link_hash_traverse (&htab
->elf
, elf_x86_64_allocate_dynrelocs
,
2661 /* Allocate .plt and .got entries, and space for local symbols. */
2662 htab_traverse (htab
->loc_hash_table
,
2663 elf_x86_64_allocate_local_dynrelocs
,
2666 /* For every jump slot reserved in the sgotplt, reloc_count is
2667 incremented. However, when we reserve space for TLS descriptors,
2668 it's not incremented, so in order to compute the space reserved
2669 for them, it suffices to multiply the reloc count by the jump
2671 if (htab
->elf
.srelplt
)
2672 htab
->sgotplt_jump_table_size
2673 = elf_x86_64_compute_jump_table_size (htab
);
2675 if (htab
->tlsdesc_plt
)
2677 /* If we're not using lazy TLS relocations, don't generate the
2678 PLT and GOT entries they require. */
2679 if ((info
->flags
& DF_BIND_NOW
))
2680 htab
->tlsdesc_plt
= 0;
2683 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2684 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2685 /* Reserve room for the initial entry.
2686 FIXME: we could probably do away with it in this case. */
2687 if (htab
->elf
.splt
->size
== 0)
2688 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2689 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2690 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2694 if (htab
->elf
.sgotplt
)
2696 struct elf_link_hash_entry
*got
;
2697 got
= elf_link_hash_lookup (elf_hash_table (info
),
2698 "_GLOBAL_OFFSET_TABLE_",
2699 FALSE
, FALSE
, FALSE
);
2701 /* Don't allocate .got.plt section if there are no GOT nor PLT
2702 entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
2704 || !got
->ref_regular_nonweak
)
2705 && (htab
->elf
.sgotplt
->size
2706 == get_elf_backend_data (output_bfd
)->got_header_size
)
2707 && (htab
->elf
.splt
== NULL
2708 || htab
->elf
.splt
->size
== 0)
2709 && (htab
->elf
.sgot
== NULL
2710 || htab
->elf
.sgot
->size
== 0)
2711 && (htab
->elf
.iplt
== NULL
2712 || htab
->elf
.iplt
->size
== 0)
2713 && (htab
->elf
.igotplt
== NULL
2714 || htab
->elf
.igotplt
->size
== 0))
2715 htab
->elf
.sgotplt
->size
= 0;
2718 /* We now have determined the sizes of the various dynamic sections.
2719 Allocate memory for them. */
2721 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2723 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2726 if (s
== htab
->elf
.splt
2727 || s
== htab
->elf
.sgot
2728 || s
== htab
->elf
.sgotplt
2729 || s
== htab
->elf
.iplt
2730 || s
== htab
->elf
.igotplt
2731 || s
== htab
->sdynbss
)
2733 /* Strip this section if we don't need it; see the
2736 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2738 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2741 /* We use the reloc_count field as a counter if we need
2742 to copy relocs into the output file. */
2743 if (s
!= htab
->elf
.srelplt
)
2748 /* It's not one of our sections, so don't allocate space. */
2754 /* If we don't need this section, strip it from the
2755 output file. This is mostly to handle .rela.bss and
2756 .rela.plt. We must create both sections in
2757 create_dynamic_sections, because they must be created
2758 before the linker maps input sections to output
2759 sections. The linker does that before
2760 adjust_dynamic_symbol is called, and it is that
2761 function which decides whether anything needs to go
2762 into these sections. */
2764 s
->flags
|= SEC_EXCLUDE
;
2768 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2771 /* Allocate memory for the section contents. We use bfd_zalloc
2772 here in case unused entries are not reclaimed before the
2773 section's contents are written out. This should not happen,
2774 but this way if it does, we get a R_X86_64_NONE reloc instead
2776 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2777 if (s
->contents
== NULL
)
2781 if (htab
->plt_eh_frame
!= NULL
2782 && htab
->elf
.splt
!= NULL
2783 && htab
->elf
.splt
->size
!= 0
2784 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0)
2785 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2786 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2788 if (htab
->elf
.dynamic_sections_created
)
2790 /* Add some entries to the .dynamic section. We fill in the
2791 values later, in elf_x86_64_finish_dynamic_sections, but we
2792 must add the entries now so that we get the correct size for
2793 the .dynamic section. The DT_DEBUG entry is filled in by the
2794 dynamic linker and used by the debugger. */
2795 #define add_dynamic_entry(TAG, VAL) \
2796 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2798 if (info
->executable
)
2800 if (!add_dynamic_entry (DT_DEBUG
, 0))
2804 if (htab
->elf
.splt
->size
!= 0)
2806 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2807 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2808 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2809 || !add_dynamic_entry (DT_JMPREL
, 0))
2812 if (htab
->tlsdesc_plt
2813 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2814 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2820 if (!add_dynamic_entry (DT_RELA
, 0)
2821 || !add_dynamic_entry (DT_RELASZ
, 0)
2822 || !add_dynamic_entry (DT_RELAENT
, bed
->s
->sizeof_rela
))
2825 /* If any dynamic relocs apply to a read-only section,
2826 then we need a DT_TEXTREL entry. */
2827 if ((info
->flags
& DF_TEXTREL
) == 0)
2828 elf_link_hash_traverse (&htab
->elf
,
2829 elf_x86_64_readonly_dynrelocs
,
2832 if ((info
->flags
& DF_TEXTREL
) != 0)
2834 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2839 #undef add_dynamic_entry
2845 elf_x86_64_always_size_sections (bfd
*output_bfd
,
2846 struct bfd_link_info
*info
)
2848 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2852 struct elf_link_hash_entry
*tlsbase
;
2854 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2855 "_TLS_MODULE_BASE_",
2856 FALSE
, FALSE
, FALSE
);
2858 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2860 struct elf_x86_64_link_hash_table
*htab
;
2861 struct bfd_link_hash_entry
*bh
= NULL
;
2862 const struct elf_backend_data
*bed
2863 = get_elf_backend_data (output_bfd
);
2865 htab
= elf_x86_64_hash_table (info
);
2869 if (!(_bfd_generic_link_add_one_symbol
2870 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2871 tls_sec
, 0, NULL
, FALSE
,
2872 bed
->collect
, &bh
)))
2875 htab
->tls_module_base
= bh
;
2877 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2878 tlsbase
->def_regular
= 1;
2879 tlsbase
->other
= STV_HIDDEN
;
2880 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2887 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2888 executables. Rather than setting it to the beginning of the TLS
2889 section, we have to set it to the end. This function may be called
2890 multiple times, it is idempotent. */
2893 elf_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2895 struct elf_x86_64_link_hash_table
*htab
;
2896 struct bfd_link_hash_entry
*base
;
2898 if (!info
->executable
)
2901 htab
= elf_x86_64_hash_table (info
);
2905 base
= htab
->tls_module_base
;
2909 base
->u
.def
.value
= htab
->elf
.tls_size
;
2912 /* Return the base VMA address which should be subtracted from real addresses
2913 when resolving @dtpoff relocation.
2914 This is PT_TLS segment p_vaddr. */
2917 elf_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2919 /* If tls_sec is NULL, we should have signalled an error already. */
2920 if (elf_hash_table (info
)->tls_sec
== NULL
)
2922 return elf_hash_table (info
)->tls_sec
->vma
;
2925 /* Return the relocation value for @tpoff relocation
2926 if STT_TLS virtual address is ADDRESS. */
2929 elf_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2931 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2932 const struct elf_backend_data
*bed
= get_elf_backend_data (info
->output_bfd
);
2933 bfd_vma static_tls_size
;
2935 /* If tls_segment is NULL, we should have signalled an error already. */
2936 if (htab
->tls_sec
== NULL
)
2939 /* Consider special static TLS alignment requirements. */
2940 static_tls_size
= BFD_ALIGN (htab
->tls_size
, bed
->static_tls_alignment
);
2941 return address
- static_tls_size
- htab
->tls_sec
->vma
;
2944 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2948 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2950 /* Opcode Instruction
2953 0x0f 0x8x conditional jump */
2955 && (contents
[offset
- 1] == 0xe8
2956 || contents
[offset
- 1] == 0xe9))
2958 && contents
[offset
- 2] == 0x0f
2959 && (contents
[offset
- 1] & 0xf0) == 0x80));
2962 /* Relocate an x86_64 ELF section. */
2965 elf_x86_64_relocate_section (bfd
*output_bfd
,
2966 struct bfd_link_info
*info
,
2968 asection
*input_section
,
2970 Elf_Internal_Rela
*relocs
,
2971 Elf_Internal_Sym
*local_syms
,
2972 asection
**local_sections
)
2974 struct elf_x86_64_link_hash_table
*htab
;
2975 Elf_Internal_Shdr
*symtab_hdr
;
2976 struct elf_link_hash_entry
**sym_hashes
;
2977 bfd_vma
*local_got_offsets
;
2978 bfd_vma
*local_tlsdesc_gotents
;
2979 Elf_Internal_Rela
*rel
;
2980 Elf_Internal_Rela
*relend
;
2982 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2984 htab
= elf_x86_64_hash_table (info
);
2987 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2988 sym_hashes
= elf_sym_hashes (input_bfd
);
2989 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2990 local_tlsdesc_gotents
= elf_x86_64_local_tlsdesc_gotent (input_bfd
);
2992 elf_x86_64_set_tls_module_base (info
);
2995 relend
= relocs
+ input_section
->reloc_count
;
2996 for (; rel
< relend
; rel
++)
2998 unsigned int r_type
;
2999 reloc_howto_type
*howto
;
3000 unsigned long r_symndx
;
3001 struct elf_link_hash_entry
*h
;
3002 Elf_Internal_Sym
*sym
;
3004 bfd_vma off
, offplt
;
3006 bfd_boolean unresolved_reloc
;
3007 bfd_reloc_status_type r
;
3011 r_type
= ELF32_R_TYPE (rel
->r_info
);
3012 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
3013 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
3016 if (r_type
>= R_X86_64_max
)
3018 bfd_set_error (bfd_error_bad_value
);
3022 if (r_type
!= (int) R_X86_64_32
3023 || ABI_64_P (output_bfd
))
3024 howto
= x86_64_elf_howto_table
+ r_type
;
3026 howto
= (x86_64_elf_howto_table
3027 + ARRAY_SIZE (x86_64_elf_howto_table
) - 1);
3028 r_symndx
= htab
->r_sym (rel
->r_info
);
3032 unresolved_reloc
= FALSE
;
3033 if (r_symndx
< symtab_hdr
->sh_info
)
3035 sym
= local_syms
+ r_symndx
;
3036 sec
= local_sections
[r_symndx
];
3038 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
3041 /* Relocate against local STT_GNU_IFUNC symbol. */
3042 if (!info
->relocatable
3043 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3045 h
= elf_x86_64_get_local_sym_hash (htab
, input_bfd
,
3050 /* Set STT_GNU_IFUNC symbol value. */
3051 h
->root
.u
.def
.value
= sym
->st_value
;
3052 h
->root
.u
.def
.section
= sec
;
3057 bfd_boolean warned ATTRIBUTE_UNUSED
;
3059 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3060 r_symndx
, symtab_hdr
, sym_hashes
,
3062 unresolved_reloc
, warned
);
3065 if (sec
!= NULL
&& elf_discarded_section (sec
))
3066 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3067 rel
, relend
, howto
, contents
);
3069 if (info
->relocatable
)
3072 if (rel
->r_addend
== 0
3073 && r_type
== R_X86_64_64
3074 && !ABI_64_P (output_bfd
))
3076 /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend
3077 it to 64bit if addend is zero. */
3078 r_type
= R_X86_64_32
;
3079 memset (contents
+ rel
->r_offset
+ 4, 0, 4);
3082 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
3083 it here if it is defined in a non-shared object. */
3085 && h
->type
== STT_GNU_IFUNC
3092 if ((input_section
->flags
& SEC_ALLOC
) == 0
3093 || h
->plt
.offset
== (bfd_vma
) -1)
3096 /* STT_GNU_IFUNC symbol must go through PLT. */
3097 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3098 relocation
= (plt
->output_section
->vma
3099 + plt
->output_offset
+ h
->plt
.offset
);
3104 if (h
->root
.root
.string
)
3105 name
= h
->root
.root
.string
;
3107 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3109 (*_bfd_error_handler
)
3110 (_("%B: relocation %s against STT_GNU_IFUNC "
3111 "symbol `%s' isn't handled by %s"), input_bfd
,
3112 x86_64_elf_howto_table
[r_type
].name
,
3113 name
, __FUNCTION__
);
3114 bfd_set_error (bfd_error_bad_value
);
3123 if (ABI_64_P (output_bfd
))
3127 if (rel
->r_addend
!= 0)
3129 if (h
->root
.root
.string
)
3130 name
= h
->root
.root
.string
;
3132 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
3134 (*_bfd_error_handler
)
3135 (_("%B: relocation %s against STT_GNU_IFUNC "
3136 "symbol `%s' has non-zero addend: %d"),
3137 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
3138 name
, rel
->r_addend
);
3139 bfd_set_error (bfd_error_bad_value
);
3143 /* Generate dynamic relcoation only when there is a
3144 non-GOF reference in a shared object. */
3145 if (info
->shared
&& h
->non_got_ref
)
3147 Elf_Internal_Rela outrel
;
3150 /* Need a dynamic relocation to get the real function
3152 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3156 if (outrel
.r_offset
== (bfd_vma
) -1
3157 || outrel
.r_offset
== (bfd_vma
) -2)
3160 outrel
.r_offset
+= (input_section
->output_section
->vma
3161 + input_section
->output_offset
);
3163 if (h
->dynindx
== -1
3165 || info
->executable
)
3167 /* This symbol is resolved locally. */
3168 outrel
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
3169 outrel
.r_addend
= (h
->root
.u
.def
.value
3170 + h
->root
.u
.def
.section
->output_section
->vma
3171 + h
->root
.u
.def
.section
->output_offset
);
3175 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3176 outrel
.r_addend
= 0;
3179 sreloc
= htab
->elf
.irelifunc
;
3180 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3182 /* If this reloc is against an external symbol, we
3183 do not want to fiddle with the addend. Otherwise,
3184 we need to include the symbol value so that it
3185 becomes an addend for the dynamic reloc. For an
3186 internal symbol, we have updated addend. */
3192 case R_X86_64_PLT32
:
3195 case R_X86_64_GOTPCREL
:
3196 case R_X86_64_GOTPCREL64
:
3197 base_got
= htab
->elf
.sgot
;
3198 off
= h
->got
.offset
;
3200 if (base_got
== NULL
)
3203 if (off
== (bfd_vma
) -1)
3205 /* We can't use h->got.offset here to save state, or
3206 even just remember the offset, as finish_dynamic_symbol
3207 would use that as offset into .got. */
3209 if (htab
->elf
.splt
!= NULL
)
3211 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3212 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3213 base_got
= htab
->elf
.sgotplt
;
3217 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3218 off
= plt_index
* GOT_ENTRY_SIZE
;
3219 base_got
= htab
->elf
.igotplt
;
3222 if (h
->dynindx
== -1
3226 /* This references the local defitionion. We must
3227 initialize this entry in the global offset table.
3228 Since the offset must always be a multiple of 8,
3229 we use the least significant bit to record
3230 whether we have initialized it already.
3232 When doing a dynamic link, we create a .rela.got
3233 relocation entry to initialize the value. This
3234 is done in the finish_dynamic_symbol routine. */
3239 bfd_put_64 (output_bfd
, relocation
,
3240 base_got
->contents
+ off
);
3241 /* Note that this is harmless for the GOTPLT64
3242 case, as -1 | 1 still is -1. */
3248 relocation
= (base_got
->output_section
->vma
3249 + base_got
->output_offset
+ off
);
3255 /* When generating a shared object, the relocations handled here are
3256 copied into the output file to be resolved at run time. */
3259 case R_X86_64_GOT32
:
3260 case R_X86_64_GOT64
:
3261 /* Relocation is to the entry for this symbol in the global
3263 case R_X86_64_GOTPCREL
:
3264 case R_X86_64_GOTPCREL64
:
3265 /* Use global offset table entry as symbol value. */
3266 case R_X86_64_GOTPLT64
:
3267 /* This is the same as GOT64 for relocation purposes, but
3268 indicates the existence of a PLT entry. The difficulty is,
3269 that we must calculate the GOT slot offset from the PLT
3270 offset, if this symbol got a PLT entry (it was global).
3271 Additionally if it's computed from the PLT entry, then that
3272 GOT offset is relative to .got.plt, not to .got. */
3273 base_got
= htab
->elf
.sgot
;
3275 if (htab
->elf
.sgot
== NULL
)
3282 off
= h
->got
.offset
;
3284 && h
->plt
.offset
!= (bfd_vma
)-1
3285 && off
== (bfd_vma
)-1)
3287 /* We can't use h->got.offset here to save
3288 state, or even just remember the offset, as
3289 finish_dynamic_symbol would use that as offset into
3291 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3292 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3293 base_got
= htab
->elf
.sgotplt
;
3296 dyn
= htab
->elf
.dynamic_sections_created
;
3298 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3300 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3301 || (ELF_ST_VISIBILITY (h
->other
)
3302 && h
->root
.type
== bfd_link_hash_undefweak
))
3304 /* This is actually a static link, or it is a -Bsymbolic
3305 link and the symbol is defined locally, or the symbol
3306 was forced to be local because of a version file. We
3307 must initialize this entry in the global offset table.
3308 Since the offset must always be a multiple of 8, we
3309 use the least significant bit to record whether we
3310 have initialized it already.
3312 When doing a dynamic link, we create a .rela.got
3313 relocation entry to initialize the value. This is
3314 done in the finish_dynamic_symbol routine. */
3319 bfd_put_64 (output_bfd
, relocation
,
3320 base_got
->contents
+ off
);
3321 /* Note that this is harmless for the GOTPLT64 case,
3322 as -1 | 1 still is -1. */
3327 unresolved_reloc
= FALSE
;
3331 if (local_got_offsets
== NULL
)
3334 off
= local_got_offsets
[r_symndx
];
3336 /* The offset must always be a multiple of 8. We use
3337 the least significant bit to record whether we have
3338 already generated the necessary reloc. */
3343 bfd_put_64 (output_bfd
, relocation
,
3344 base_got
->contents
+ off
);
3349 Elf_Internal_Rela outrel
;
3351 /* We need to generate a R_X86_64_RELATIVE reloc
3352 for the dynamic linker. */
3353 s
= htab
->elf
.srelgot
;
3357 outrel
.r_offset
= (base_got
->output_section
->vma
3358 + base_got
->output_offset
3360 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3361 outrel
.r_addend
= relocation
;
3362 elf_append_rela (output_bfd
, s
, &outrel
);
3365 local_got_offsets
[r_symndx
] |= 1;
3369 if (off
>= (bfd_vma
) -2)
3372 relocation
= base_got
->output_section
->vma
3373 + base_got
->output_offset
+ off
;
3374 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3375 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3376 - htab
->elf
.sgotplt
->output_offset
;
3380 case R_X86_64_GOTOFF64
:
3381 /* Relocation is relative to the start of the global offset
3384 /* Check to make sure it isn't a protected function symbol
3385 for shared library since it may not be local when used
3386 as function address. */
3390 && h
->type
== STT_FUNC
3391 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3393 (*_bfd_error_handler
)
3394 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3395 input_bfd
, h
->root
.root
.string
);
3396 bfd_set_error (bfd_error_bad_value
);
3400 /* Note that sgot is not involved in this
3401 calculation. We always want the start of .got.plt. If we
3402 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3403 permitted by the ABI, we might have to change this
3405 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3406 + htab
->elf
.sgotplt
->output_offset
;
3409 case R_X86_64_GOTPC32
:
3410 case R_X86_64_GOTPC64
:
3411 /* Use global offset table as symbol value. */
3412 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3413 + htab
->elf
.sgotplt
->output_offset
;
3414 unresolved_reloc
= FALSE
;
3417 case R_X86_64_PLTOFF64
:
3418 /* Relocation is PLT entry relative to GOT. For local
3419 symbols it's the symbol itself relative to GOT. */
3421 /* See PLT32 handling. */
3422 && h
->plt
.offset
!= (bfd_vma
) -1
3423 && htab
->elf
.splt
!= NULL
)
3425 relocation
= (htab
->elf
.splt
->output_section
->vma
3426 + htab
->elf
.splt
->output_offset
3428 unresolved_reloc
= FALSE
;
3431 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3432 + htab
->elf
.sgotplt
->output_offset
;
3435 case R_X86_64_PLT32
:
3436 /* Relocation is to the entry for this symbol in the
3437 procedure linkage table. */
3439 /* Resolve a PLT32 reloc against a local symbol directly,
3440 without using the procedure linkage table. */
3444 if (h
->plt
.offset
== (bfd_vma
) -1
3445 || htab
->elf
.splt
== NULL
)
3447 /* We didn't make a PLT entry for this symbol. This
3448 happens when statically linking PIC code, or when
3449 using -Bsymbolic. */
3453 relocation
= (htab
->elf
.splt
->output_section
->vma
3454 + htab
->elf
.splt
->output_offset
3456 unresolved_reloc
= FALSE
;
3463 && ABI_64_P (output_bfd
)
3464 && (input_section
->flags
& SEC_ALLOC
) != 0
3465 && (input_section
->flags
& SEC_READONLY
) != 0
3468 bfd_boolean fail
= FALSE
;
3470 = (r_type
== R_X86_64_PC32
3471 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3473 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3475 /* Symbol is referenced locally. Make sure it is
3476 defined locally or for a branch. */
3477 fail
= !h
->def_regular
&& !branch
;
3481 /* Symbol isn't referenced locally. We only allow
3482 branch to symbol with non-default visibility. */
3484 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3491 const char *pic
= "";
3493 switch (ELF_ST_VISIBILITY (h
->other
))
3496 v
= _("hidden symbol");
3499 v
= _("internal symbol");
3502 v
= _("protected symbol");
3506 pic
= _("; recompile with -fPIC");
3511 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3513 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3515 (*_bfd_error_handler
) (fmt
, input_bfd
,
3516 x86_64_elf_howto_table
[r_type
].name
,
3517 v
, h
->root
.root
.string
, pic
);
3518 bfd_set_error (bfd_error_bad_value
);
3529 /* FIXME: The ABI says the linker should make sure the value is
3530 the same when it's zeroextended to 64 bit. */
3532 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3537 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3538 || h
->root
.type
!= bfd_link_hash_undefweak
)
3539 && (! IS_X86_64_PCREL_TYPE (r_type
)
3540 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3541 || (ELIMINATE_COPY_RELOCS
3548 || h
->root
.type
== bfd_link_hash_undefweak
3549 || h
->root
.type
== bfd_link_hash_undefined
)))
3551 Elf_Internal_Rela outrel
;
3552 bfd_boolean skip
, relocate
;
3555 /* When generating a shared object, these relocations
3556 are copied into the output file to be resolved at run
3562 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3564 if (outrel
.r_offset
== (bfd_vma
) -1)
3566 else if (outrel
.r_offset
== (bfd_vma
) -2)
3567 skip
= TRUE
, relocate
= TRUE
;
3569 outrel
.r_offset
+= (input_section
->output_section
->vma
3570 + input_section
->output_offset
);
3573 memset (&outrel
, 0, sizeof outrel
);
3575 /* h->dynindx may be -1 if this symbol was marked to
3579 && (IS_X86_64_PCREL_TYPE (r_type
)
3581 || ! SYMBOLIC_BIND (info
, h
)
3582 || ! h
->def_regular
))
3584 outrel
.r_info
= htab
->r_info (h
->dynindx
, r_type
);
3585 outrel
.r_addend
= rel
->r_addend
;
3589 /* This symbol is local, or marked to become local. */
3590 if (r_type
== htab
->pointer_r_type
)
3593 outrel
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
3594 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3596 else if (r_type
== R_X86_64_64
3597 && !ABI_64_P (output_bfd
))
3600 outrel
.r_info
= htab
->r_info (0,
3601 R_X86_64_RELATIVE64
);
3602 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3608 if (bfd_is_abs_section (sec
))
3610 else if (sec
== NULL
|| sec
->owner
== NULL
)
3612 bfd_set_error (bfd_error_bad_value
);
3619 /* We are turning this relocation into one
3620 against a section symbol. It would be
3621 proper to subtract the symbol's value,
3622 osec->vma, from the emitted reloc addend,
3623 but ld.so expects buggy relocs. */
3624 osec
= sec
->output_section
;
3625 sindx
= elf_section_data (osec
)->dynindx
;
3628 asection
*oi
= htab
->elf
.text_index_section
;
3629 sindx
= elf_section_data (oi
)->dynindx
;
3631 BFD_ASSERT (sindx
!= 0);
3634 outrel
.r_info
= htab
->r_info (sindx
, r_type
);
3635 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3639 sreloc
= elf_section_data (input_section
)->sreloc
;
3641 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
3643 r
= bfd_reloc_notsupported
;
3644 goto check_relocation_error
;
3647 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3649 /* If this reloc is against an external symbol, we do
3650 not want to fiddle with the addend. Otherwise, we
3651 need to include the symbol value so that it becomes
3652 an addend for the dynamic reloc. */
3659 case R_X86_64_TLSGD
:
3660 case R_X86_64_GOTPC32_TLSDESC
:
3661 case R_X86_64_TLSDESC_CALL
:
3662 case R_X86_64_GOTTPOFF
:
3663 tls_type
= GOT_UNKNOWN
;
3664 if (h
== NULL
&& local_got_offsets
)
3665 tls_type
= elf_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3667 tls_type
= elf_x86_64_hash_entry (h
)->tls_type
;
3669 if (! elf_x86_64_tls_transition (info
, input_bfd
,
3670 input_section
, contents
,
3671 symtab_hdr
, sym_hashes
,
3672 &r_type
, tls_type
, rel
,
3673 relend
, h
, r_symndx
))
3676 if (r_type
== R_X86_64_TPOFF32
)
3678 bfd_vma roff
= rel
->r_offset
;
3680 BFD_ASSERT (! unresolved_reloc
);
3682 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3684 /* GD->LE transition. For 64bit, change
3685 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3686 .word 0x6666; rex64; call __tls_get_addr
3689 leaq foo@tpoff(%rax), %rax
3691 leaq foo@tlsgd(%rip), %rdi
3692 .word 0x6666; rex64; call __tls_get_addr
3695 leaq foo@tpoff(%rax), %rax */
3696 if (ABI_64_P (output_bfd
))
3697 memcpy (contents
+ roff
- 4,
3698 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3701 memcpy (contents
+ roff
- 3,
3702 "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3704 bfd_put_32 (output_bfd
,
3705 elf_x86_64_tpoff (info
, relocation
),
3706 contents
+ roff
+ 8);
3707 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3711 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3713 /* GDesc -> LE transition.
3714 It's originally something like:
3715 leaq x@tlsdesc(%rip), %rax
3718 movl $x@tpoff, %rax. */
3720 unsigned int val
, type
;
3722 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3723 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3724 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3725 contents
+ roff
- 3);
3726 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3727 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3728 contents
+ roff
- 1);
3729 bfd_put_32 (output_bfd
,
3730 elf_x86_64_tpoff (info
, relocation
),
3734 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3736 /* GDesc -> LE transition.
3741 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3742 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3745 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3747 /* IE->LE transition:
3748 Originally it can be one of:
3749 movq foo@gottpoff(%rip), %reg
3750 addq foo@gottpoff(%rip), %reg
3753 leaq foo(%reg), %reg
3756 unsigned int val
, type
, reg
;
3758 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3759 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3760 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3766 bfd_put_8 (output_bfd
, 0x49,
3767 contents
+ roff
- 3);
3768 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3769 bfd_put_8 (output_bfd
, 0x41,
3770 contents
+ roff
- 3);
3771 bfd_put_8 (output_bfd
, 0xc7,
3772 contents
+ roff
- 2);
3773 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3774 contents
+ roff
- 1);
3778 /* addq -> addq - addressing with %rsp/%r12 is
3781 bfd_put_8 (output_bfd
, 0x49,
3782 contents
+ roff
- 3);
3783 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3784 bfd_put_8 (output_bfd
, 0x41,
3785 contents
+ roff
- 3);
3786 bfd_put_8 (output_bfd
, 0x81,
3787 contents
+ roff
- 2);
3788 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3789 contents
+ roff
- 1);
3795 bfd_put_8 (output_bfd
, 0x4d,
3796 contents
+ roff
- 3);
3797 else if (!ABI_64_P (output_bfd
) && val
== 0x44)
3798 bfd_put_8 (output_bfd
, 0x45,
3799 contents
+ roff
- 3);
3800 bfd_put_8 (output_bfd
, 0x8d,
3801 contents
+ roff
- 2);
3802 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3803 contents
+ roff
- 1);
3805 bfd_put_32 (output_bfd
,
3806 elf_x86_64_tpoff (info
, relocation
),
3814 if (htab
->elf
.sgot
== NULL
)
3819 off
= h
->got
.offset
;
3820 offplt
= elf_x86_64_hash_entry (h
)->tlsdesc_got
;
3824 if (local_got_offsets
== NULL
)
3827 off
= local_got_offsets
[r_symndx
];
3828 offplt
= local_tlsdesc_gotents
[r_symndx
];
3835 Elf_Internal_Rela outrel
;
3839 if (htab
->elf
.srelgot
== NULL
)
3842 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3844 if (GOT_TLS_GDESC_P (tls_type
))
3846 outrel
.r_info
= htab
->r_info (indx
, R_X86_64_TLSDESC
);
3847 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3848 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3849 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3850 + htab
->elf
.sgotplt
->output_offset
3852 + htab
->sgotplt_jump_table_size
);
3853 sreloc
= htab
->elf
.srelplt
;
3855 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3857 outrel
.r_addend
= 0;
3858 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3861 sreloc
= htab
->elf
.srelgot
;
3863 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3864 + htab
->elf
.sgot
->output_offset
+ off
);
3866 if (GOT_TLS_GD_P (tls_type
))
3867 dr_type
= R_X86_64_DTPMOD64
;
3868 else if (GOT_TLS_GDESC_P (tls_type
))
3871 dr_type
= R_X86_64_TPOFF64
;
3873 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3874 outrel
.r_addend
= 0;
3875 if ((dr_type
== R_X86_64_TPOFF64
3876 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3877 outrel
.r_addend
= relocation
- elf_x86_64_dtpoff_base (info
);
3878 outrel
.r_info
= htab
->r_info (indx
, dr_type
);
3880 elf_append_rela (output_bfd
, sreloc
, &outrel
);
3882 if (GOT_TLS_GD_P (tls_type
))
3886 BFD_ASSERT (! unresolved_reloc
);
3887 bfd_put_64 (output_bfd
,
3888 relocation
- elf_x86_64_dtpoff_base (info
),
3889 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3893 bfd_put_64 (output_bfd
, 0,
3894 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3895 outrel
.r_info
= htab
->r_info (indx
,
3897 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3898 elf_append_rela (output_bfd
, sreloc
,
3907 local_got_offsets
[r_symndx
] |= 1;
3910 if (off
>= (bfd_vma
) -2
3911 && ! GOT_TLS_GDESC_P (tls_type
))
3913 if (r_type
== ELF32_R_TYPE (rel
->r_info
))
3915 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3916 || r_type
== R_X86_64_TLSDESC_CALL
)
3917 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3918 + htab
->elf
.sgotplt
->output_offset
3919 + offplt
+ htab
->sgotplt_jump_table_size
;
3921 relocation
= htab
->elf
.sgot
->output_section
->vma
3922 + htab
->elf
.sgot
->output_offset
+ off
;
3923 unresolved_reloc
= FALSE
;
3927 bfd_vma roff
= rel
->r_offset
;
3929 if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3931 /* GD->IE transition. For 64bit, change
3932 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3933 .word 0x6666; rex64; call __tls_get_addr@plt
3936 addq foo@gottpoff(%rip), %rax
3938 leaq foo@tlsgd(%rip), %rdi
3939 .word 0x6666; rex64; call __tls_get_addr@plt
3942 addq foo@gottpoff(%rip), %rax */
3943 if (ABI_64_P (output_bfd
))
3944 memcpy (contents
+ roff
- 4,
3945 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3948 memcpy (contents
+ roff
- 3,
3949 "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3952 relocation
= (htab
->elf
.sgot
->output_section
->vma
3953 + htab
->elf
.sgot
->output_offset
+ off
3955 - input_section
->output_section
->vma
3956 - input_section
->output_offset
3958 bfd_put_32 (output_bfd
, relocation
,
3959 contents
+ roff
+ 8);
3960 /* Skip R_X86_64_PLT32. */
3964 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3966 /* GDesc -> IE transition.
3967 It's originally something like:
3968 leaq x@tlsdesc(%rip), %rax
3971 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3973 /* Now modify the instruction as appropriate. To
3974 turn a leaq into a movq in the form we use it, it
3975 suffices to change the second byte from 0x8d to
3977 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3979 bfd_put_32 (output_bfd
,
3980 htab
->elf
.sgot
->output_section
->vma
3981 + htab
->elf
.sgot
->output_offset
+ off
3983 - input_section
->output_section
->vma
3984 - input_section
->output_offset
3989 else if (ELF32_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3991 /* GDesc -> IE transition.
3998 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3999 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
4007 case R_X86_64_TLSLD
:
4008 if (! elf_x86_64_tls_transition (info
, input_bfd
,
4009 input_section
, contents
,
4010 symtab_hdr
, sym_hashes
,
4011 &r_type
, GOT_UNKNOWN
,
4012 rel
, relend
, h
, r_symndx
))
4015 if (r_type
!= R_X86_64_TLSLD
)
4017 /* LD->LE transition:
4018 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
4019 For 64bit, we change it into:
4020 .word 0x6666; .byte 0x66; movq %fs:0, %rax.
4021 For 32bit, we change it into:
4022 nopl 0x0(%rax); movl %fs:0, %eax. */
4024 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
4025 if (ABI_64_P (output_bfd
))
4026 memcpy (contents
+ rel
->r_offset
- 3,
4027 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
4029 memcpy (contents
+ rel
->r_offset
- 3,
4030 "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12);
4031 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
4036 if (htab
->elf
.sgot
== NULL
)
4039 off
= htab
->tls_ld_got
.offset
;
4044 Elf_Internal_Rela outrel
;
4046 if (htab
->elf
.srelgot
== NULL
)
4049 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4050 + htab
->elf
.sgot
->output_offset
+ off
);
4052 bfd_put_64 (output_bfd
, 0,
4053 htab
->elf
.sgot
->contents
+ off
);
4054 bfd_put_64 (output_bfd
, 0,
4055 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
4056 outrel
.r_info
= htab
->r_info (0, R_X86_64_DTPMOD64
);
4057 outrel
.r_addend
= 0;
4058 elf_append_rela (output_bfd
, htab
->elf
.srelgot
,
4060 htab
->tls_ld_got
.offset
|= 1;
4062 relocation
= htab
->elf
.sgot
->output_section
->vma
4063 + htab
->elf
.sgot
->output_offset
+ off
;
4064 unresolved_reloc
= FALSE
;
4067 case R_X86_64_DTPOFF32
:
4068 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
4069 relocation
-= elf_x86_64_dtpoff_base (info
);
4071 relocation
= elf_x86_64_tpoff (info
, relocation
);
4074 case R_X86_64_TPOFF32
:
4075 case R_X86_64_TPOFF64
:
4076 BFD_ASSERT (info
->executable
);
4077 relocation
= elf_x86_64_tpoff (info
, relocation
);
4084 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4085 because such sections are not SEC_ALLOC and thus ld.so will
4086 not process them. */
4087 if (unresolved_reloc
4088 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4090 (*_bfd_error_handler
)
4091 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4094 (long) rel
->r_offset
,
4096 h
->root
.root
.string
);
4099 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4100 contents
, rel
->r_offset
,
4101 relocation
, rel
->r_addend
);
4103 check_relocation_error
:
4104 if (r
!= bfd_reloc_ok
)
4109 name
= h
->root
.root
.string
;
4112 name
= bfd_elf_string_from_elf_section (input_bfd
,
4113 symtab_hdr
->sh_link
,
4118 name
= bfd_section_name (input_bfd
, sec
);
4121 if (r
== bfd_reloc_overflow
)
4123 if (! ((*info
->callbacks
->reloc_overflow
)
4124 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4125 (bfd_vma
) 0, input_bfd
, input_section
,
4131 (*_bfd_error_handler
)
4132 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4133 input_bfd
, input_section
,
4134 (long) rel
->r_offset
, name
, (int) r
);
4143 /* Finish up dynamic symbol handling. We set the contents of various
4144 dynamic sections here. */
4147 elf_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
4148 struct bfd_link_info
*info
,
4149 struct elf_link_hash_entry
*h
,
4150 Elf_Internal_Sym
*sym
)
4152 struct elf_x86_64_link_hash_table
*htab
;
4154 htab
= elf_x86_64_hash_table (info
);
4158 if (h
->plt
.offset
!= (bfd_vma
) -1)
4162 Elf_Internal_Rela rela
;
4164 asection
*plt
, *gotplt
, *relplt
;
4165 const struct elf_backend_data
*bed
;
4167 /* When building a static executable, use .iplt, .igot.plt and
4168 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4169 if (htab
->elf
.splt
!= NULL
)
4171 plt
= htab
->elf
.splt
;
4172 gotplt
= htab
->elf
.sgotplt
;
4173 relplt
= htab
->elf
.srelplt
;
4177 plt
= htab
->elf
.iplt
;
4178 gotplt
= htab
->elf
.igotplt
;
4179 relplt
= htab
->elf
.irelplt
;
4182 /* This symbol has an entry in the procedure linkage table. Set
4184 if ((h
->dynindx
== -1
4185 && !((h
->forced_local
|| info
->executable
)
4187 && h
->type
== STT_GNU_IFUNC
))
4193 /* Get the index in the procedure linkage table which
4194 corresponds to this symbol. This is the index of this symbol
4195 in all the symbols for which we are making plt entries. The
4196 first entry in the procedure linkage table is reserved.
4198 Get the offset into the .got table of the entry that
4199 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
4200 bytes. The first three are reserved for the dynamic linker.
4202 For static executables, we don't reserve anything. */
4204 if (plt
== htab
->elf
.splt
)
4206 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
4207 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4211 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
4212 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
4215 /* Fill in the entry in the procedure linkage table. */
4216 memcpy (plt
->contents
+ h
->plt
.offset
, elf_x86_64_plt_entry
,
4219 /* Insert the relocation positions of the plt section. The magic
4220 numbers at the end of the statements are the positions of the
4221 relocations in the plt section. */
4222 /* Put offset for jmp *name@GOTPCREL(%rip), since the
4223 instruction uses 6 bytes, subtract this value. */
4224 bfd_put_32 (output_bfd
,
4225 (gotplt
->output_section
->vma
4226 + gotplt
->output_offset
4228 - plt
->output_section
->vma
4229 - plt
->output_offset
4232 plt
->contents
+ h
->plt
.offset
+ 2);
4234 /* Don't fill PLT entry for static executables. */
4235 if (plt
== htab
->elf
.splt
)
4237 /* Put relocation index. */
4238 bfd_put_32 (output_bfd
, plt_index
,
4239 plt
->contents
+ h
->plt
.offset
+ 7);
4240 /* Put offset for jmp .PLT0. */
4241 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
4242 plt
->contents
+ h
->plt
.offset
+ 12);
4245 /* Fill in the entry in the global offset table, initially this
4246 points to the pushq instruction in the PLT which is at offset 6. */
4247 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4248 + plt
->output_offset
4249 + h
->plt
.offset
+ 6),
4250 gotplt
->contents
+ got_offset
);
4252 /* Fill in the entry in the .rela.plt section. */
4253 rela
.r_offset
= (gotplt
->output_section
->vma
4254 + gotplt
->output_offset
4256 if (h
->dynindx
== -1
4257 || ((info
->executable
4258 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4260 && h
->type
== STT_GNU_IFUNC
))
4262 /* If an STT_GNU_IFUNC symbol is locally defined, generate
4263 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
4264 rela
.r_info
= htab
->r_info (0, R_X86_64_IRELATIVE
);
4265 rela
.r_addend
= (h
->root
.u
.def
.value
4266 + h
->root
.u
.def
.section
->output_section
->vma
4267 + h
->root
.u
.def
.section
->output_offset
);
4271 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_JUMP_SLOT
);
4275 bed
= get_elf_backend_data (output_bfd
);
4276 loc
= relplt
->contents
+ plt_index
* bed
->s
->sizeof_rela
;
4277 bed
->s
->swap_reloca_out (output_bfd
, &rela
, loc
);
4279 if (!h
->def_regular
)
4281 /* Mark the symbol as undefined, rather than as defined in
4282 the .plt section. Leave the value if there were any
4283 relocations where pointer equality matters (this is a clue
4284 for the dynamic linker, to make function pointer
4285 comparisons work between an application and shared
4286 library), otherwise set it to zero. If a function is only
4287 called from a binary, there is no need to slow down
4288 shared libraries because of that. */
4289 sym
->st_shndx
= SHN_UNDEF
;
4290 if (!h
->pointer_equality_needed
)
4295 if (h
->got
.offset
!= (bfd_vma
) -1
4296 && ! GOT_TLS_GD_ANY_P (elf_x86_64_hash_entry (h
)->tls_type
)
4297 && elf_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
4299 Elf_Internal_Rela rela
;
4301 /* This symbol has an entry in the global offset table. Set it
4303 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
4306 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
4307 + htab
->elf
.sgot
->output_offset
4308 + (h
->got
.offset
&~ (bfd_vma
) 1));
4310 /* If this is a static link, or it is a -Bsymbolic link and the
4311 symbol is defined locally or was forced to be local because
4312 of a version file, we just want to emit a RELATIVE reloc.
4313 The entry in the global offset table will already have been
4314 initialized in the relocate_section function. */
4316 && h
->type
== STT_GNU_IFUNC
)
4320 /* Generate R_X86_64_GLOB_DAT. */
4327 if (!h
->pointer_equality_needed
)
4330 /* For non-shared object, we can't use .got.plt, which
4331 contains the real function addres if we need pointer
4332 equality. We load the GOT entry with the PLT entry. */
4333 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
4334 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
4335 + plt
->output_offset
4337 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4341 else if (info
->shared
4342 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4344 if (!h
->def_regular
)
4346 BFD_ASSERT((h
->got
.offset
& 1) != 0);
4347 rela
.r_info
= htab
->r_info (0, R_X86_64_RELATIVE
);
4348 rela
.r_addend
= (h
->root
.u
.def
.value
4349 + h
->root
.u
.def
.section
->output_section
->vma
4350 + h
->root
.u
.def
.section
->output_offset
);
4354 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4356 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4357 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
4358 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_GLOB_DAT
);
4362 elf_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
4367 Elf_Internal_Rela rela
;
4369 /* This symbol needs a copy reloc. Set it up. */
4371 if (h
->dynindx
== -1
4372 || (h
->root
.type
!= bfd_link_hash_defined
4373 && h
->root
.type
!= bfd_link_hash_defweak
)
4374 || htab
->srelbss
== NULL
)
4377 rela
.r_offset
= (h
->root
.u
.def
.value
4378 + h
->root
.u
.def
.section
->output_section
->vma
4379 + h
->root
.u
.def
.section
->output_offset
);
4380 rela
.r_info
= htab
->r_info (h
->dynindx
, R_X86_64_COPY
);
4382 elf_append_rela (output_bfd
, htab
->srelbss
, &rela
);
4385 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
4386 be NULL for local symbols. */
4388 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4389 || h
== htab
->elf
.hgot
))
4390 sym
->st_shndx
= SHN_ABS
;
4395 /* Finish up local dynamic symbol handling. We set the contents of
4396 various dynamic sections here. */
4399 elf_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
4401 struct elf_link_hash_entry
*h
4402 = (struct elf_link_hash_entry
*) *slot
;
4403 struct bfd_link_info
*info
4404 = (struct bfd_link_info
*) inf
;
4406 return elf_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4410 /* Used to decide how to sort relocs in an optimal manner for the
4411 dynamic linker, before writing them out. */
4413 static enum elf_reloc_type_class
4414 elf_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4416 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4418 case R_X86_64_RELATIVE
:
4419 return reloc_class_relative
;
4420 case R_X86_64_JUMP_SLOT
:
4421 return reloc_class_plt
;
4423 return reloc_class_copy
;
4425 return reloc_class_normal
;
4429 /* Finish up the dynamic sections. */
4432 elf_x86_64_finish_dynamic_sections (bfd
*output_bfd
,
4433 struct bfd_link_info
*info
)
4435 struct elf_x86_64_link_hash_table
*htab
;
4439 htab
= elf_x86_64_hash_table (info
);
4443 dynobj
= htab
->elf
.dynobj
;
4444 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4446 if (htab
->elf
.dynamic_sections_created
)
4448 bfd_byte
*dyncon
, *dynconend
;
4449 const struct elf_backend_data
*bed
;
4450 bfd_size_type sizeof_dyn
;
4452 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4455 bed
= get_elf_backend_data (dynobj
);
4456 sizeof_dyn
= bed
->s
->sizeof_dyn
;
4457 dyncon
= sdyn
->contents
;
4458 dynconend
= sdyn
->contents
+ sdyn
->size
;
4459 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
4461 Elf_Internal_Dyn dyn
;
4464 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
4472 s
= htab
->elf
.sgotplt
;
4473 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4477 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4481 s
= htab
->elf
.srelplt
->output_section
;
4482 dyn
.d_un
.d_val
= s
->size
;
4486 /* The procedure linkage table relocs (DT_JMPREL) should
4487 not be included in the overall relocs (DT_RELA).
4488 Therefore, we override the DT_RELASZ entry here to
4489 make it not include the JMPREL relocs. Since the
4490 linker script arranges for .rela.plt to follow all
4491 other relocation sections, we don't have to worry
4492 about changing the DT_RELA entry. */
4493 if (htab
->elf
.srelplt
!= NULL
)
4495 s
= htab
->elf
.srelplt
->output_section
;
4496 dyn
.d_un
.d_val
-= s
->size
;
4500 case DT_TLSDESC_PLT
:
4502 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4503 + htab
->tlsdesc_plt
;
4506 case DT_TLSDESC_GOT
:
4508 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4509 + htab
->tlsdesc_got
;
4513 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
4516 /* Fill in the special first entry in the procedure linkage table. */
4517 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4519 /* Fill in the first entry in the procedure linkage table. */
4520 memcpy (htab
->elf
.splt
->contents
, elf_x86_64_plt0_entry
,
4522 /* Add offset for pushq GOT+8(%rip), since the instruction
4523 uses 6 bytes subtract this value. */
4524 bfd_put_32 (output_bfd
,
4525 (htab
->elf
.sgotplt
->output_section
->vma
4526 + htab
->elf
.sgotplt
->output_offset
4528 - htab
->elf
.splt
->output_section
->vma
4529 - htab
->elf
.splt
->output_offset
4531 htab
->elf
.splt
->contents
+ 2);
4532 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4533 the end of the instruction. */
4534 bfd_put_32 (output_bfd
,
4535 (htab
->elf
.sgotplt
->output_section
->vma
4536 + htab
->elf
.sgotplt
->output_offset
4538 - htab
->elf
.splt
->output_section
->vma
4539 - htab
->elf
.splt
->output_offset
4541 htab
->elf
.splt
->contents
+ 8);
4543 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
=
4546 if (htab
->tlsdesc_plt
)
4548 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4549 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4551 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4552 elf_x86_64_plt0_entry
,
4555 /* Add offset for pushq GOT+8(%rip), since the
4556 instruction uses 6 bytes subtract this value. */
4557 bfd_put_32 (output_bfd
,
4558 (htab
->elf
.sgotplt
->output_section
->vma
4559 + htab
->elf
.sgotplt
->output_offset
4561 - htab
->elf
.splt
->output_section
->vma
4562 - htab
->elf
.splt
->output_offset
4565 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 2);
4566 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4567 htab->tlsdesc_got. The 12 is the offset to the end of
4569 bfd_put_32 (output_bfd
,
4570 (htab
->elf
.sgot
->output_section
->vma
4571 + htab
->elf
.sgot
->output_offset
4573 - htab
->elf
.splt
->output_section
->vma
4574 - htab
->elf
.splt
->output_offset
4577 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
4582 if (htab
->elf
.sgotplt
)
4584 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
4586 (*_bfd_error_handler
)
4587 (_("discarded output section: `%A'"), htab
->elf
.sgotplt
);
4591 /* Fill in the first three entries in the global offset table. */
4592 if (htab
->elf
.sgotplt
->size
> 0)
4594 /* Set the first entry in the global offset table to the address of
4595 the dynamic section. */
4597 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4599 bfd_put_64 (output_bfd
,
4600 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4601 htab
->elf
.sgotplt
->contents
);
4602 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4603 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4604 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4607 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4611 /* Adjust .eh_frame for .plt section. */
4612 if (htab
->plt_eh_frame
!= NULL
)
4614 if (htab
->elf
.splt
!= NULL
4615 && htab
->elf
.splt
->size
!= 0
4616 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
4617 && htab
->elf
.splt
->output_section
!= NULL
4618 && htab
->plt_eh_frame
->output_section
!= NULL
)
4620 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
4621 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
4622 + htab
->plt_eh_frame
->output_offset
4623 + PLT_FDE_START_OFFSET
;
4624 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
4625 htab
->plt_eh_frame
->contents
4626 + PLT_FDE_START_OFFSET
);
4628 if (htab
->plt_eh_frame
->sec_info_type
4629 == ELF_INFO_TYPE_EH_FRAME
)
4631 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
4633 htab
->plt_eh_frame
->contents
))
4638 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4639 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4642 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4643 htab_traverse (htab
->loc_hash_table
,
4644 elf_x86_64_finish_local_dynamic_symbol
,
4650 /* Return address for Ith PLT stub in section PLT, for relocation REL
4651 or (bfd_vma) -1 if it should not be included. */
4654 elf_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4655 const arelent
*rel ATTRIBUTE_UNUSED
)
4657 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4660 /* Handle an x86-64 specific section when reading an object file. This
4661 is called when elfcode.h finds a section with an unknown type. */
4664 elf_x86_64_section_from_shdr (bfd
*abfd
,
4665 Elf_Internal_Shdr
*hdr
,
4669 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4672 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4678 /* Hook called by the linker routine which adds symbols from an object
4679 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4683 elf_x86_64_add_symbol_hook (bfd
*abfd
,
4684 struct bfd_link_info
*info
,
4685 Elf_Internal_Sym
*sym
,
4686 const char **namep ATTRIBUTE_UNUSED
,
4687 flagword
*flagsp ATTRIBUTE_UNUSED
,
4693 switch (sym
->st_shndx
)
4695 case SHN_X86_64_LCOMMON
:
4696 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4699 lcomm
= bfd_make_section_with_flags (abfd
,
4703 | SEC_LINKER_CREATED
));
4706 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4709 *valp
= sym
->st_size
;
4713 if ((abfd
->flags
& DYNAMIC
) == 0
4714 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
4715 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
4716 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4722 /* Given a BFD section, try to locate the corresponding ELF section
4726 elf_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4727 asection
*sec
, int *index_return
)
4729 if (sec
== &_bfd_elf_large_com_section
)
4731 *index_return
= SHN_X86_64_LCOMMON
;
4737 /* Process a symbol. */
4740 elf_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4743 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4745 switch (elfsym
->internal_elf_sym
.st_shndx
)
4747 case SHN_X86_64_LCOMMON
:
4748 asym
->section
= &_bfd_elf_large_com_section
;
4749 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4750 /* Common symbol doesn't set BSF_GLOBAL. */
4751 asym
->flags
&= ~BSF_GLOBAL
;
4757 elf_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4759 return (sym
->st_shndx
== SHN_COMMON
4760 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4764 elf_x86_64_common_section_index (asection
*sec
)
4766 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4769 return SHN_X86_64_LCOMMON
;
4773 elf_x86_64_common_section (asection
*sec
)
4775 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4776 return bfd_com_section_ptr
;
4778 return &_bfd_elf_large_com_section
;
4782 elf_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4783 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4784 struct elf_link_hash_entry
*h
,
4785 Elf_Internal_Sym
*sym
,
4787 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4788 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4789 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4790 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4791 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4792 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4793 bfd_boolean
*newdyn ATTRIBUTE_UNUSED
,
4794 bfd_boolean
*newdef
,
4795 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4796 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4797 bfd
*abfd ATTRIBUTE_UNUSED
,
4799 bfd_boolean
*olddyn ATTRIBUTE_UNUSED
,
4800 bfd_boolean
*olddef
,
4801 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4802 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4806 /* A normal common symbol and a large common symbol result in a
4807 normal common symbol. We turn the large common symbol into a
4810 && h
->root
.type
== bfd_link_hash_common
4812 && bfd_is_com_section (*sec
)
4815 if (sym
->st_shndx
== SHN_COMMON
4816 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4818 h
->root
.u
.c
.p
->section
4819 = bfd_make_section_old_way (oldbfd
, "COMMON");
4820 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4822 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4823 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4824 *psec
= *sec
= bfd_com_section_ptr
;
4831 elf_x86_64_additional_program_headers (bfd
*abfd
,
4832 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4837 /* Check to see if we need a large readonly segment. */
4838 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4839 if (s
&& (s
->flags
& SEC_LOAD
))
4842 /* Check to see if we need a large data segment. Since .lbss sections
4843 is placed right after the .bss section, there should be no need for
4844 a large data segment just because of .lbss. */
4845 s
= bfd_get_section_by_name (abfd
, ".ldata");
4846 if (s
&& (s
->flags
& SEC_LOAD
))
4852 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4855 elf_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4857 if (h
->plt
.offset
!= (bfd_vma
) -1
4859 && !h
->pointer_equality_needed
)
4862 return _bfd_elf_hash_symbol (h
);
4865 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */
4868 elf_x86_64_relocs_compatible (const bfd_target
*input
,
4869 const bfd_target
*output
)
4871 return ((xvec_get_elf_backend_data (input
)->s
->elfclass
4872 == xvec_get_elf_backend_data (output
)->s
->elfclass
)
4873 && _bfd_elf_relocs_compatible (input
, output
));
4876 static const struct bfd_elf_special_section
4877 elf_x86_64_special_sections
[]=
4879 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4880 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4881 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4882 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4883 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4884 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4885 { NULL
, 0, 0, 0, 0 }
4888 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4889 #define TARGET_LITTLE_NAME "elf64-x86-64"
4890 #define ELF_ARCH bfd_arch_i386
4891 #define ELF_TARGET_ID X86_64_ELF_DATA
4892 #define ELF_MACHINE_CODE EM_X86_64
4893 #define ELF_MAXPAGESIZE 0x200000
4894 #define ELF_MINPAGESIZE 0x1000
4895 #define ELF_COMMONPAGESIZE 0x1000
4897 #define elf_backend_can_gc_sections 1
4898 #define elf_backend_can_refcount 1
4899 #define elf_backend_want_got_plt 1
4900 #define elf_backend_plt_readonly 1
4901 #define elf_backend_want_plt_sym 0
4902 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4903 #define elf_backend_rela_normal 1
4904 #define elf_backend_plt_alignment 4
4906 #define elf_info_to_howto elf_x86_64_info_to_howto
4908 #define bfd_elf64_bfd_link_hash_table_create \
4909 elf_x86_64_link_hash_table_create
4910 #define bfd_elf64_bfd_link_hash_table_free \
4911 elf_x86_64_link_hash_table_free
4912 #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup
4913 #define bfd_elf64_bfd_reloc_name_lookup \
4914 elf_x86_64_reloc_name_lookup
4916 #define elf_backend_adjust_dynamic_symbol elf_x86_64_adjust_dynamic_symbol
4917 #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible
4918 #define elf_backend_check_relocs elf_x86_64_check_relocs
4919 #define elf_backend_copy_indirect_symbol elf_x86_64_copy_indirect_symbol
4920 #define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
4921 #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
4922 #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
4923 #define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
4924 #define elf_backend_gc_sweep_hook elf_x86_64_gc_sweep_hook
4925 #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
4926 #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
4928 #define elf_backend_write_core_note elf_x86_64_write_core_note
4930 #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class
4931 #define elf_backend_relocate_section elf_x86_64_relocate_section
4932 #define elf_backend_size_dynamic_sections elf_x86_64_size_dynamic_sections
4933 #define elf_backend_always_size_sections elf_x86_64_always_size_sections
4934 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4935 #define elf_backend_plt_sym_val elf_x86_64_plt_sym_val
4936 #define elf_backend_object_p elf64_x86_64_elf_object_p
4937 #define bfd_elf64_mkobject elf_x86_64_mkobject
4939 #define elf_backend_section_from_shdr \
4940 elf_x86_64_section_from_shdr
4942 #define elf_backend_section_from_bfd_section \
4943 elf_x86_64_elf_section_from_bfd_section
4944 #define elf_backend_add_symbol_hook \
4945 elf_x86_64_add_symbol_hook
4946 #define elf_backend_symbol_processing \
4947 elf_x86_64_symbol_processing
4948 #define elf_backend_common_section_index \
4949 elf_x86_64_common_section_index
4950 #define elf_backend_common_section \
4951 elf_x86_64_common_section
4952 #define elf_backend_common_definition \
4953 elf_x86_64_common_definition
4954 #define elf_backend_merge_symbol \
4955 elf_x86_64_merge_symbol
4956 #define elf_backend_special_sections \
4957 elf_x86_64_special_sections
4958 #define elf_backend_additional_program_headers \
4959 elf_x86_64_additional_program_headers
4960 #define elf_backend_hash_symbol \
4961 elf_x86_64_hash_symbol
4963 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4965 #include "elf64-target.h"
4967 /* FreeBSD support. */
4969 #undef TARGET_LITTLE_SYM
4970 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4971 #undef TARGET_LITTLE_NAME
4972 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4975 #define ELF_OSABI ELFOSABI_FREEBSD
4978 #define elf64_bed elf64_x86_64_fbsd_bed
4980 #include "elf64-target.h"
4982 /* Solaris 2 support. */
4984 #undef TARGET_LITTLE_SYM
4985 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4986 #undef TARGET_LITTLE_NAME
4987 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4989 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4990 objects won't be recognized. */
4994 #define elf64_bed elf64_x86_64_sol2_bed
4996 /* The 64-bit static TLS arena size is rounded to the nearest 16-byte
4998 #undef elf_backend_static_tls_alignment
4999 #define elf_backend_static_tls_alignment 16
5001 /* The Solaris 2 ABI requires a plt symbol on all platforms.
5003 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
5005 #undef elf_backend_want_plt_sym
5006 #define elf_backend_want_plt_sym 1
5008 #include "elf64-target.h"
5010 /* Intel L1OM support. */
5013 elf64_l1om_elf_object_p (bfd
*abfd
)
5015 /* Set the right machine number for an L1OM elf64 file. */
5016 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
5020 #undef TARGET_LITTLE_SYM
5021 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
5022 #undef TARGET_LITTLE_NAME
5023 #define TARGET_LITTLE_NAME "elf64-l1om"
5025 #define ELF_ARCH bfd_arch_l1om
5027 #undef ELF_MACHINE_CODE
5028 #define ELF_MACHINE_CODE EM_L1OM
5033 #define elf64_bed elf64_l1om_bed
5035 #undef elf_backend_object_p
5036 #define elf_backend_object_p elf64_l1om_elf_object_p
5038 #undef elf_backend_static_tls_alignment
5040 #undef elf_backend_want_plt_sym
5041 #define elf_backend_want_plt_sym 0
5043 #include "elf64-target.h"
5045 /* FreeBSD L1OM support. */
5047 #undef TARGET_LITTLE_SYM
5048 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
5049 #undef TARGET_LITTLE_NAME
5050 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
5053 #define ELF_OSABI ELFOSABI_FREEBSD
5056 #define elf64_bed elf64_l1om_fbsd_bed
5058 #include "elf64-target.h"
5060 /* Intel K1OM support. */
5063 elf64_k1om_elf_object_p (bfd
*abfd
)
5065 /* Set the right machine number for an K1OM elf64 file. */
5066 bfd_default_set_arch_mach (abfd
, bfd_arch_k1om
, bfd_mach_k1om
);
5070 #undef TARGET_LITTLE_SYM
5071 #define TARGET_LITTLE_SYM bfd_elf64_k1om_vec
5072 #undef TARGET_LITTLE_NAME
5073 #define TARGET_LITTLE_NAME "elf64-k1om"
5075 #define ELF_ARCH bfd_arch_k1om
5077 #undef ELF_MACHINE_CODE
5078 #define ELF_MACHINE_CODE EM_K1OM
5083 #define elf64_bed elf64_k1om_bed
5085 #undef elf_backend_object_p
5086 #define elf_backend_object_p elf64_k1om_elf_object_p
5088 #undef elf_backend_static_tls_alignment
5090 #undef elf_backend_want_plt_sym
5091 #define elf_backend_want_plt_sym 0
5093 #include "elf64-target.h"
5095 /* FreeBSD K1OM support. */
5097 #undef TARGET_LITTLE_SYM
5098 #define TARGET_LITTLE_SYM bfd_elf64_k1om_freebsd_vec
5099 #undef TARGET_LITTLE_NAME
5100 #define TARGET_LITTLE_NAME "elf64-k1om-freebsd"
5103 #define ELF_OSABI ELFOSABI_FREEBSD
5106 #define elf64_bed elf64_k1om_fbsd_bed
5108 #include "elf64-target.h"
5110 /* 32bit x86-64 support. */
5113 elf32_x86_64_elf_object_p (bfd
*abfd
)
5115 /* Set the right machine number for an x86-64 elf32 file. */
5116 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x64_32
);
5120 #undef TARGET_LITTLE_SYM
5121 #define TARGET_LITTLE_SYM bfd_elf32_x86_64_vec
5122 #undef TARGET_LITTLE_NAME
5123 #define TARGET_LITTLE_NAME "elf32-x86-64"
5126 #define ELF_ARCH bfd_arch_i386
5128 #undef ELF_MACHINE_CODE
5129 #define ELF_MACHINE_CODE EM_X86_64
5131 #define bfd_elf32_bfd_link_hash_table_create \
5132 elf_x86_64_link_hash_table_create
5133 #define bfd_elf32_bfd_link_hash_table_free \
5134 elf_x86_64_link_hash_table_free
5135 #define bfd_elf32_bfd_reloc_type_lookup \
5136 elf_x86_64_reloc_type_lookup
5137 #define bfd_elf32_bfd_reloc_name_lookup \
5138 elf_x86_64_reloc_name_lookup
5139 #define bfd_elf32_mkobject \
5144 #undef elf_backend_object_p
5145 #define elf_backend_object_p \
5146 elf32_x86_64_elf_object_p
5148 #undef elf_backend_bfd_from_remote_memory
5149 #define elf_backend_bfd_from_remote_memory \
5150 _bfd_elf32_bfd_from_remote_memory
5152 #undef elf_backend_size_info
5153 #define elf_backend_size_info \
5154 _bfd_elf32_size_info
5156 #include "elf32-target.h"