1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka <jh@suse.cz>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 #include "bfd_stdint.h"
30 #include "elf/x86-64.h"
32 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
33 #define MINUS_ONE (~ (bfd_vma) 0)
35 /* The relocation "howto" table. Order of fields:
36 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
37 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
38 static reloc_howto_type x86_64_elf_howto_table
[] =
40 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
41 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
43 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
44 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
46 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
47 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
49 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
50 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
52 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
53 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
55 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
58 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
61 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
64 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
65 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
67 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
68 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
70 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
71 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
74 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
76 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
77 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
78 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
79 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
80 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
81 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
82 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
83 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
84 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
87 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
90 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
91 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
93 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
94 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
96 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
97 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
99 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
100 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
102 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
103 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
105 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
106 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
108 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
109 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
111 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
112 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
113 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
114 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
115 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
116 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
117 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
118 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
120 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
121 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
123 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
124 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
125 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
126 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
127 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
129 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
130 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
134 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
135 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
136 "R_X86_64_GOTPC32_TLSDESC",
137 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
138 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
139 complain_overflow_dont
, bfd_elf_generic_reloc
,
140 "R_X86_64_TLSDESC_CALL",
142 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
143 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
145 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
146 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
150 /* We have a gap in the reloc numbers here.
151 R_X86_64_standard counts the number up to this point, and
152 R_X86_64_vt_offset is the value to subtract from a reloc type of
153 R_X86_64_GNU_VT* to form an index into this table. */
154 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
155 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
157 /* GNU extension to record C++ vtable hierarchy. */
158 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
159 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
161 /* GNU extension to record C++ vtable member usage. */
162 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
163 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
167 #define IS_X86_64_PCREL_TYPE(TYPE) \
168 ( ((TYPE) == R_X86_64_PC8) \
169 || ((TYPE) == R_X86_64_PC16) \
170 || ((TYPE) == R_X86_64_PC32) \
171 || ((TYPE) == R_X86_64_PC64))
173 /* Map BFD relocs to the x86_64 elf relocs. */
176 bfd_reloc_code_real_type bfd_reloc_val
;
177 unsigned char elf_reloc_val
;
180 static const struct elf_reloc_map x86_64_reloc_map
[] =
182 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
183 { BFD_RELOC_64
, R_X86_64_64
, },
184 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
185 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
186 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
187 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
188 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
189 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
190 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
191 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
192 { BFD_RELOC_32
, R_X86_64_32
, },
193 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
194 { BFD_RELOC_16
, R_X86_64_16
, },
195 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
196 { BFD_RELOC_8
, R_X86_64_8
, },
197 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
198 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
199 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
200 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
201 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
202 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
203 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
204 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
205 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
206 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
207 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
208 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
209 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
210 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
211 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
212 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
213 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
214 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
215 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
216 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
217 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
218 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
219 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
222 static reloc_howto_type
*
223 elf64_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
227 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
228 || r_type
>= (unsigned int) R_X86_64_max
)
230 if (r_type
>= (unsigned int) R_X86_64_standard
)
232 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
234 r_type
= R_X86_64_NONE
;
239 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
240 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
241 return &x86_64_elf_howto_table
[i
];
244 /* Given a BFD reloc type, return a HOWTO structure. */
245 static reloc_howto_type
*
246 elf64_x86_64_reloc_type_lookup (bfd
*abfd
,
247 bfd_reloc_code_real_type code
)
251 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
254 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
255 return elf64_x86_64_rtype_to_howto (abfd
,
256 x86_64_reloc_map
[i
].elf_reloc_val
);
261 static reloc_howto_type
*
262 elf64_x86_64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
268 i
< (sizeof (x86_64_elf_howto_table
)
269 / sizeof (x86_64_elf_howto_table
[0]));
271 if (x86_64_elf_howto_table
[i
].name
!= NULL
272 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
273 return &x86_64_elf_howto_table
[i
];
278 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
281 elf64_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
282 Elf_Internal_Rela
*dst
)
286 r_type
= ELF64_R_TYPE (dst
->r_info
);
287 cache_ptr
->howto
= elf64_x86_64_rtype_to_howto (abfd
, r_type
);
288 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
291 /* Support for core dump NOTE sections. */
293 elf64_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
298 switch (note
->descsz
)
303 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
305 elf_tdata (abfd
)->core_signal
306 = bfd_get_16 (abfd
, note
->descdata
+ 12);
309 elf_tdata (abfd
)->core_pid
310 = bfd_get_32 (abfd
, note
->descdata
+ 32);
319 /* Make a ".reg/999" section. */
320 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
321 size
, note
->descpos
+ offset
);
325 elf64_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
327 switch (note
->descsz
)
332 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
333 elf_tdata (abfd
)->core_program
334 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
335 elf_tdata (abfd
)->core_command
336 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
339 /* Note that for some reason, a spurious space is tacked
340 onto the end of the args in some (at least one anyway)
341 implementations, so strip it off if it exists. */
344 char *command
= elf_tdata (abfd
)->core_command
;
345 int n
= strlen (command
);
347 if (0 < n
&& command
[n
- 1] == ' ')
348 command
[n
- 1] = '\0';
354 /* Functions for the x86-64 ELF linker. */
356 /* The name of the dynamic interpreter. This is put in the .interp
359 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
361 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
362 copying dynamic variables from a shared lib into an app's dynbss
363 section, and instead use a dynamic relocation to point into the
365 #define ELIMINATE_COPY_RELOCS 1
367 /* The size in bytes of an entry in the global offset table. */
369 #define GOT_ENTRY_SIZE 8
371 /* The size in bytes of an entry in the procedure linkage table. */
373 #define PLT_ENTRY_SIZE 16
375 /* The first entry in a procedure linkage table looks like this. See the
376 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
378 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
380 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
381 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
382 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
385 /* Subsequent entries in a procedure linkage table look like this. */
387 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
389 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
390 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
391 0x68, /* pushq immediate */
392 0, 0, 0, 0, /* replaced with index into relocation table. */
393 0xe9, /* jmp relative */
394 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
397 /* The x86-64 linker needs to keep track of the number of relocs that
398 it decides to copy as dynamic relocs in check_relocs for each symbol.
399 This is so that it can later discard them if they are found to be
400 unnecessary. We store the information in a field extending the
401 regular ELF linker hash table. */
403 struct elf64_x86_64_dyn_relocs
406 struct elf64_x86_64_dyn_relocs
*next
;
408 /* The input section of the reloc. */
411 /* Total number of relocs copied for the input section. */
414 /* Number of pc-relative relocs copied for the input section. */
415 bfd_size_type pc_count
;
418 /* x86-64 ELF linker hash entry. */
420 struct elf64_x86_64_link_hash_entry
422 struct elf_link_hash_entry elf
;
424 /* Track dynamic relocs copied for this symbol. */
425 struct elf64_x86_64_dyn_relocs
*dyn_relocs
;
427 #define GOT_UNKNOWN 0
431 #define GOT_TLS_GDESC 4
432 #define GOT_TLS_GD_BOTH_P(type) \
433 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
434 #define GOT_TLS_GD_P(type) \
435 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
436 #define GOT_TLS_GDESC_P(type) \
437 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
438 #define GOT_TLS_GD_ANY_P(type) \
439 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
440 unsigned char tls_type
;
442 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
443 starting at the end of the jump table. */
447 #define elf64_x86_64_hash_entry(ent) \
448 ((struct elf64_x86_64_link_hash_entry *)(ent))
450 struct elf64_x86_64_obj_tdata
452 struct elf_obj_tdata root
;
454 /* tls_type for each local got entry. */
455 char *local_got_tls_type
;
457 /* GOTPLT entries for TLS descriptors. */
458 bfd_vma
*local_tlsdesc_gotent
;
461 #define elf64_x86_64_tdata(abfd) \
462 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
464 #define elf64_x86_64_local_got_tls_type(abfd) \
465 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
467 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
468 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
470 #define is_x86_64_elf(bfd) \
471 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
472 && elf_tdata (bfd) != NULL \
473 && elf_object_id (bfd) == X86_64_ELF_TDATA)
476 elf64_x86_64_mkobject (bfd
*abfd
)
478 return bfd_elf_allocate_object (abfd
, sizeof (struct elf64_x86_64_obj_tdata
),
482 /* x86-64 ELF linker hash table. */
484 struct elf64_x86_64_link_hash_table
486 struct elf_link_hash_table elf
;
488 /* Short-cuts to get to dynamic linker sections. */
500 /* The offset into splt of the PLT entry for the TLS descriptor
501 resolver. Special values are 0, if not necessary (or not found
502 to be necessary yet), and -1 if needed but not determined
505 /* The offset into sgot of the GOT entry used by the PLT entry
510 bfd_signed_vma refcount
;
514 /* The amount of space used by the jump slots in the GOT. */
515 bfd_vma sgotplt_jump_table_size
;
517 /* Small local sym to section mapping cache. */
518 struct sym_sec_cache sym_sec
;
520 /* _TLS_MODULE_BASE_ symbol. */
521 struct bfd_link_hash_entry
*tls_module_base
;
524 /* Get the x86-64 ELF linker hash table from a link_info structure. */
526 #define elf64_x86_64_hash_table(p) \
527 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
529 #define elf64_x86_64_compute_jump_table_size(htab) \
530 ((htab)->srelplt->reloc_count * GOT_ENTRY_SIZE)
532 /* Create an entry in an x86-64 ELF linker hash table. */
534 static struct bfd_hash_entry
*
535 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
536 struct bfd_hash_table
*table
,
539 /* Allocate the structure if it has not already been allocated by a
543 entry
= bfd_hash_allocate (table
,
544 sizeof (struct elf64_x86_64_link_hash_entry
));
549 /* Call the allocation method of the superclass. */
550 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
553 struct elf64_x86_64_link_hash_entry
*eh
;
555 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
556 eh
->dyn_relocs
= NULL
;
557 eh
->tls_type
= GOT_UNKNOWN
;
558 eh
->tlsdesc_got
= (bfd_vma
) -1;
564 /* Create an X86-64 ELF linker hash table. */
566 static struct bfd_link_hash_table
*
567 elf64_x86_64_link_hash_table_create (bfd
*abfd
)
569 struct elf64_x86_64_link_hash_table
*ret
;
570 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
572 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_malloc (amt
);
576 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
577 elf64_x86_64_link_hash_newfunc
,
578 sizeof (struct elf64_x86_64_link_hash_entry
)))
594 ret
->sym_sec
.abfd
= NULL
;
595 ret
->tlsdesc_plt
= 0;
596 ret
->tlsdesc_got
= 0;
597 ret
->tls_ld_got
.refcount
= 0;
598 ret
->sgotplt_jump_table_size
= 0;
599 ret
->tls_module_base
= NULL
;
601 return &ret
->elf
.root
;
604 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
605 shortcuts to them in our hash table. */
608 elf64_x86_64_create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
610 struct elf64_x86_64_link_hash_table
*htab
;
612 if (! _bfd_elf_create_got_section (dynobj
, info
))
615 htab
= elf64_x86_64_hash_table (info
);
616 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
617 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
618 if (!htab
->sgot
|| !htab
->sgotplt
)
621 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rela.got",
622 (SEC_ALLOC
| SEC_LOAD
627 if (htab
->srelgot
== NULL
628 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
633 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
634 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
638 elf64_x86_64_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
640 struct elf64_x86_64_link_hash_table
*htab
;
642 htab
= elf64_x86_64_hash_table (info
);
643 if (!htab
->sgot
&& !elf64_x86_64_create_got_section (dynobj
, info
))
646 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
649 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
650 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
651 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
653 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
655 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
656 || (!info
->shared
&& !htab
->srelbss
))
662 /* Copy the extra info we tack onto an elf_link_hash_entry. */
665 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
666 struct elf_link_hash_entry
*dir
,
667 struct elf_link_hash_entry
*ind
)
669 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
671 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
672 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
674 if (eind
->dyn_relocs
!= NULL
)
676 if (edir
->dyn_relocs
!= NULL
)
678 struct elf64_x86_64_dyn_relocs
**pp
;
679 struct elf64_x86_64_dyn_relocs
*p
;
681 /* Add reloc counts against the indirect sym to the direct sym
682 list. Merge any entries against the same section. */
683 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
685 struct elf64_x86_64_dyn_relocs
*q
;
687 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
688 if (q
->sec
== p
->sec
)
690 q
->pc_count
+= p
->pc_count
;
691 q
->count
+= p
->count
;
698 *pp
= edir
->dyn_relocs
;
701 edir
->dyn_relocs
= eind
->dyn_relocs
;
702 eind
->dyn_relocs
= NULL
;
705 if (ind
->root
.type
== bfd_link_hash_indirect
706 && dir
->got
.refcount
<= 0)
708 edir
->tls_type
= eind
->tls_type
;
709 eind
->tls_type
= GOT_UNKNOWN
;
712 if (ELIMINATE_COPY_RELOCS
713 && ind
->root
.type
!= bfd_link_hash_indirect
714 && dir
->dynamic_adjusted
)
716 /* If called to transfer flags for a weakdef during processing
717 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
718 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
719 dir
->ref_dynamic
|= ind
->ref_dynamic
;
720 dir
->ref_regular
|= ind
->ref_regular
;
721 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
722 dir
->needs_plt
|= ind
->needs_plt
;
723 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
726 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
730 elf64_x86_64_elf_object_p (bfd
*abfd
)
732 /* Set the right machine number for an x86-64 elf64 file. */
733 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
751 /* Return TRUE if the TLS access code sequence support transition
755 elf64_x86_64_check_tls_transition (bfd
*abfd
, asection
*sec
,
757 Elf_Internal_Shdr
*symtab_hdr
,
758 struct elf_link_hash_entry
**sym_hashes
,
760 const Elf_Internal_Rela
*rel
,
761 const Elf_Internal_Rela
*relend
)
764 unsigned long r_symndx
;
765 struct elf_link_hash_entry
*h
;
768 /* Get the section contents. */
769 if (contents
== NULL
)
771 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
772 contents
= elf_section_data (sec
)->this_hdr
.contents
;
775 /* FIXME: How to better handle error condition? */
776 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
779 /* Cache the section contents for elf_link_input_bfd. */
780 elf_section_data (sec
)->this_hdr
.contents
= contents
;
784 offset
= rel
->r_offset
;
789 if ((rel
+ 1) >= relend
)
792 if (r_type
== R_X86_64_TLSGD
)
794 /* Check transition from GD access model. Only
795 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
796 .word 0x6666; rex64; call __tls_get_addr
797 can transit to different access model. */
799 static x86_64_opcode32 leaq
= { { 0x66, 0x48, 0x8d, 0x3d } },
800 call
= { { 0x66, 0x66, 0x48, 0xe8 } };
802 || (offset
+ 12) > sec
->size
803 || bfd_get_32 (abfd
, contents
+ offset
- 4) != leaq
.i
804 || bfd_get_32 (abfd
, contents
+ offset
+ 4) != call
.i
)
809 /* Check transition from LD access model. Only
810 leaq foo@tlsld(%rip), %rdi;
812 can transit to different access model. */
814 static x86_64_opcode32 ld
= { { 0x48, 0x8d, 0x3d, 0xe8 } };
817 if (offset
< 3 || (offset
+ 9) > sec
->size
)
820 op
.i
= bfd_get_32 (abfd
, contents
+ offset
- 3);
821 op
.c
[3] = bfd_get_8 (abfd
, contents
+ offset
+ 4);
826 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
827 if (r_symndx
< symtab_hdr
->sh_info
)
830 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
831 /* Use strncmp to check __tls_get_addr since __tls_get_addr
834 && h
->root
.root
.string
!= NULL
835 && (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
836 || ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
837 && (strncmp (h
->root
.root
.string
,
838 "__tls_get_addr", 14) == 0));
840 case R_X86_64_GOTTPOFF
:
841 /* Check transition from IE access model:
842 movq foo@gottpoff(%rip), %reg
843 addq foo@gottpoff(%rip), %reg
846 if (offset
< 3 || (offset
+ 4) > sec
->size
)
849 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
850 if (val
!= 0x48 && val
!= 0x4c)
853 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
854 if (val
!= 0x8b && val
!= 0x03)
857 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
858 return (val
& 0xc7) == 5;
860 case R_X86_64_GOTPC32_TLSDESC
:
861 /* Check transition from GDesc access model:
862 leaq x@tlsdesc(%rip), %rax
864 Make sure it's a leaq adding rip to a 32-bit offset
865 into any register, although it's probably almost always
868 if (offset
< 3 || (offset
+ 4) > sec
->size
)
871 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
872 if ((val
& 0xfb) != 0x48)
875 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
878 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
879 return (val
& 0xc7) == 0x05;
881 case R_X86_64_TLSDESC_CALL
:
882 /* Check transition from GDesc access model:
883 call *x@tlsdesc(%rax)
885 if (offset
+ 2 <= sec
->size
)
887 /* Make sure that it's a call *x@tlsdesc(%rax). */
888 static x86_64_opcode16 call
= { { 0xff, 0x10 } };
889 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
899 /* Return TRUE if the TLS access transition is OK or no transition
900 will be performed. Update R_TYPE if there is a transition. */
903 elf64_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
904 asection
*sec
, bfd_byte
*contents
,
905 Elf_Internal_Shdr
*symtab_hdr
,
906 struct elf_link_hash_entry
**sym_hashes
,
907 unsigned int *r_type
, int tls_type
,
908 const Elf_Internal_Rela
*rel
,
909 const Elf_Internal_Rela
*relend
,
910 struct elf_link_hash_entry
*h
)
912 unsigned int from_type
= *r_type
;
913 unsigned int to_type
= from_type
;
914 bfd_boolean check
= TRUE
;
919 case R_X86_64_GOTPC32_TLSDESC
:
920 case R_X86_64_TLSDESC_CALL
:
921 case R_X86_64_GOTTPOFF
:
925 to_type
= R_X86_64_TPOFF32
;
927 to_type
= R_X86_64_GOTTPOFF
;
930 /* When we are called from elf64_x86_64_relocate_section,
931 CONTENTS isn't NULL and there may be additional transitions
932 based on TLS_TYPE. */
933 if (contents
!= NULL
)
935 unsigned int new_to_type
= to_type
;
940 && tls_type
== GOT_TLS_IE
)
941 new_to_type
= R_X86_64_TPOFF32
;
943 if (to_type
== R_X86_64_TLSGD
944 || to_type
== R_X86_64_GOTPC32_TLSDESC
945 || to_type
== R_X86_64_TLSDESC_CALL
)
947 if (tls_type
== GOT_TLS_IE
)
948 new_to_type
= R_X86_64_GOTTPOFF
;
951 /* We checked the transition before when we were called from
952 elf64_x86_64_check_relocs. We only want to check the new
953 transition which hasn't been checked before. */
954 check
= new_to_type
!= to_type
&& from_type
== to_type
;
955 to_type
= new_to_type
;
962 to_type
= R_X86_64_TPOFF32
;
969 /* Return TRUE if there is no transition. */
970 if (from_type
== to_type
)
973 /* Check if the transition can be performed. */
975 && ! elf64_x86_64_check_tls_transition (abfd
, sec
, contents
,
976 symtab_hdr
, sym_hashes
,
977 from_type
, rel
, relend
))
979 reloc_howto_type
*from
, *to
;
981 from
= elf64_x86_64_rtype_to_howto (abfd
, from_type
);
982 to
= elf64_x86_64_rtype_to_howto (abfd
, to_type
);
984 (*_bfd_error_handler
)
985 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
986 "in section `%A' failed"),
987 abfd
, sec
, from
->name
, to
->name
,
988 h
? h
->root
.root
.string
: "a local symbol",
989 (unsigned long) rel
->r_offset
);
990 bfd_set_error (bfd_error_bad_value
);
998 /* Look through the relocs for a section during the first phase, and
999 calculate needed space in the global offset table, procedure
1000 linkage table, and dynamic reloc sections. */
1003 elf64_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1005 const Elf_Internal_Rela
*relocs
)
1007 struct elf64_x86_64_link_hash_table
*htab
;
1008 Elf_Internal_Shdr
*symtab_hdr
;
1009 struct elf_link_hash_entry
**sym_hashes
;
1010 const Elf_Internal_Rela
*rel
;
1011 const Elf_Internal_Rela
*rel_end
;
1014 if (info
->relocatable
)
1017 BFD_ASSERT (is_x86_64_elf (abfd
));
1019 htab
= elf64_x86_64_hash_table (info
);
1020 symtab_hdr
= &elf_symtab_hdr (abfd
);
1021 sym_hashes
= elf_sym_hashes (abfd
);
1025 rel_end
= relocs
+ sec
->reloc_count
;
1026 for (rel
= relocs
; rel
< rel_end
; rel
++)
1028 unsigned int r_type
;
1029 unsigned long r_symndx
;
1030 struct elf_link_hash_entry
*h
;
1032 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1033 r_type
= ELF64_R_TYPE (rel
->r_info
);
1035 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1037 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1042 if (r_symndx
< symtab_hdr
->sh_info
)
1046 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1047 while (h
->root
.type
== bfd_link_hash_indirect
1048 || h
->root
.type
== bfd_link_hash_warning
)
1049 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1051 /* Create the ifunc sections for static executables. If we
1052 never see an indirect function symbol nor we are building
1053 a static executable, those sections will be empty and
1054 won't appear in output. */
1065 case R_X86_64_PLT32
:
1066 case R_X86_64_GOTPCREL
:
1067 case R_X86_64_GOTPCREL64
:
1068 if (!info
->shared
&& htab
->iplt
== NULL
)
1070 if (!_bfd_elf_create_static_ifunc_sections (abfd
,
1074 htab
->iplt
= bfd_get_section_by_name (abfd
, ".iplt");
1075 htab
->irelplt
= bfd_get_section_by_name (abfd
,
1077 htab
->igotplt
= bfd_get_section_by_name (abfd
,
1087 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1088 it here if it is defined in a non-shared object. */
1089 if (h
->type
== STT_GNU_IFUNC
1092 /* It is referenced by a non-shared object. */
1095 /* STT_GNU_IFUNC symbol must go through PLT. */
1096 h
->plt
.refcount
+= 1;
1098 /* STT_GNU_IFUNC needs dynamic sections. */
1099 if (htab
->elf
.dynobj
== NULL
)
1100 htab
->elf
.dynobj
= abfd
;
1105 (*_bfd_error_handler
)
1106 (_("%B: relocation %s against STT_GNU_IFUNC "
1107 "symbol `%s' isn't handled by %s"), abfd
,
1108 x86_64_elf_howto_table
[r_type
].name
,
1109 h
->root
.root
.string
, __FUNCTION__
);
1110 bfd_set_error (bfd_error_bad_value
);
1119 if (r_type
!= R_X86_64_PC32
1120 && r_type
!= R_X86_64_PC64
)
1121 h
->pointer_equality_needed
= 1;
1124 case R_X86_64_PLT32
:
1127 case R_X86_64_GOTPCREL
:
1128 case R_X86_64_GOTPCREL64
:
1129 if (htab
->sgot
== NULL
1130 && !elf64_x86_64_create_got_section (htab
->elf
.dynobj
,
1140 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1141 symtab_hdr
, sym_hashes
,
1142 &r_type
, GOT_UNKNOWN
,
1148 case R_X86_64_TLSLD
:
1149 htab
->tls_ld_got
.refcount
+= 1;
1152 case R_X86_64_TPOFF32
:
1155 (*_bfd_error_handler
)
1156 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1158 x86_64_elf_howto_table
[r_type
].name
,
1159 (h
) ? h
->root
.root
.string
: "a local symbol");
1160 bfd_set_error (bfd_error_bad_value
);
1165 case R_X86_64_GOTTPOFF
:
1167 info
->flags
|= DF_STATIC_TLS
;
1170 case R_X86_64_GOT32
:
1171 case R_X86_64_GOTPCREL
:
1172 case R_X86_64_TLSGD
:
1173 case R_X86_64_GOT64
:
1174 case R_X86_64_GOTPCREL64
:
1175 case R_X86_64_GOTPLT64
:
1176 case R_X86_64_GOTPC32_TLSDESC
:
1177 case R_X86_64_TLSDESC_CALL
:
1178 /* This symbol requires a global offset table entry. */
1180 int tls_type
, old_tls_type
;
1184 default: tls_type
= GOT_NORMAL
; break;
1185 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1186 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1187 case R_X86_64_GOTPC32_TLSDESC
:
1188 case R_X86_64_TLSDESC_CALL
:
1189 tls_type
= GOT_TLS_GDESC
; break;
1194 if (r_type
== R_X86_64_GOTPLT64
)
1196 /* This relocation indicates that we also need
1197 a PLT entry, as this is a function. We don't need
1198 a PLT entry for local symbols. */
1200 h
->plt
.refcount
+= 1;
1202 h
->got
.refcount
+= 1;
1203 old_tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1207 bfd_signed_vma
*local_got_refcounts
;
1209 /* This is a global offset table entry for a local symbol. */
1210 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1211 if (local_got_refcounts
== NULL
)
1215 size
= symtab_hdr
->sh_info
;
1216 size
*= sizeof (bfd_signed_vma
)
1217 + sizeof (bfd_vma
) + sizeof (char);
1218 local_got_refcounts
= ((bfd_signed_vma
*)
1219 bfd_zalloc (abfd
, size
));
1220 if (local_got_refcounts
== NULL
)
1222 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1223 elf64_x86_64_local_tlsdesc_gotent (abfd
)
1224 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1225 elf64_x86_64_local_got_tls_type (abfd
)
1226 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1228 local_got_refcounts
[r_symndx
] += 1;
1230 = elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1233 /* If a TLS symbol is accessed using IE at least once,
1234 there is no point to use dynamic model for it. */
1235 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1236 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1237 || tls_type
!= GOT_TLS_IE
))
1239 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1240 tls_type
= old_tls_type
;
1241 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1242 && GOT_TLS_GD_ANY_P (tls_type
))
1243 tls_type
|= old_tls_type
;
1246 (*_bfd_error_handler
)
1247 (_("%B: '%s' accessed both as normal and thread local symbol"),
1248 abfd
, h
? h
->root
.root
.string
: "<local>");
1253 if (old_tls_type
!= tls_type
)
1256 elf64_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1258 elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1263 case R_X86_64_GOTOFF64
:
1264 case R_X86_64_GOTPC32
:
1265 case R_X86_64_GOTPC64
:
1267 if (htab
->sgot
== NULL
)
1269 if (htab
->elf
.dynobj
== NULL
)
1270 htab
->elf
.dynobj
= abfd
;
1271 if (!elf64_x86_64_create_got_section (htab
->elf
.dynobj
,
1277 case R_X86_64_PLT32
:
1278 /* This symbol requires a procedure linkage table entry. We
1279 actually build the entry in adjust_dynamic_symbol,
1280 because this might be a case of linking PIC code which is
1281 never referenced by a dynamic object, in which case we
1282 don't need to generate a procedure linkage table entry
1285 /* If this is a local symbol, we resolve it directly without
1286 creating a procedure linkage table entry. */
1291 h
->plt
.refcount
+= 1;
1294 case R_X86_64_PLTOFF64
:
1295 /* This tries to form the 'address' of a function relative
1296 to GOT. For global symbols we need a PLT entry. */
1300 h
->plt
.refcount
+= 1;
1308 /* Let's help debug shared library creation. These relocs
1309 cannot be used in shared libs. Don't error out for
1310 sections we don't care about, such as debug sections or
1311 non-constant sections. */
1313 && (sec
->flags
& SEC_ALLOC
) != 0
1314 && (sec
->flags
& SEC_READONLY
) != 0)
1316 (*_bfd_error_handler
)
1317 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1319 x86_64_elf_howto_table
[r_type
].name
,
1320 (h
) ? h
->root
.root
.string
: "a local symbol");
1321 bfd_set_error (bfd_error_bad_value
);
1331 if (h
!= NULL
&& !info
->shared
)
1333 /* If this reloc is in a read-only section, we might
1334 need a copy reloc. We can't check reliably at this
1335 stage whether the section is read-only, as input
1336 sections have not yet been mapped to output sections.
1337 Tentatively set the flag for now, and correct in
1338 adjust_dynamic_symbol. */
1341 /* We may need a .plt entry if the function this reloc
1342 refers to is in a shared lib. */
1343 h
->plt
.refcount
+= 1;
1344 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1345 h
->pointer_equality_needed
= 1;
1348 /* If we are creating a shared library, and this is a reloc
1349 against a global symbol, or a non PC relative reloc
1350 against a local symbol, then we need to copy the reloc
1351 into the shared library. However, if we are linking with
1352 -Bsymbolic, we do not need to copy a reloc against a
1353 global symbol which is defined in an object we are
1354 including in the link (i.e., DEF_REGULAR is set). At
1355 this point we have not seen all the input files, so it is
1356 possible that DEF_REGULAR is not set now but will be set
1357 later (it is never cleared). In case of a weak definition,
1358 DEF_REGULAR may be cleared later by a strong definition in
1359 a shared library. We account for that possibility below by
1360 storing information in the relocs_copied field of the hash
1361 table entry. A similar situation occurs when creating
1362 shared libraries and symbol visibility changes render the
1365 If on the other hand, we are creating an executable, we
1366 may need to keep relocations for symbols satisfied by a
1367 dynamic library if we manage to avoid copy relocs for the
1370 && (sec
->flags
& SEC_ALLOC
) != 0
1371 && (! IS_X86_64_PCREL_TYPE (r_type
)
1373 && (! SYMBOLIC_BIND (info
, h
)
1374 || h
->root
.type
== bfd_link_hash_defweak
1375 || !h
->def_regular
))))
1376 || (ELIMINATE_COPY_RELOCS
1378 && (sec
->flags
& SEC_ALLOC
) != 0
1380 && (h
->root
.type
== bfd_link_hash_defweak
1381 || !h
->def_regular
)))
1383 struct elf64_x86_64_dyn_relocs
*p
;
1384 struct elf64_x86_64_dyn_relocs
**head
;
1386 /* We must copy these reloc types into the output file.
1387 Create a reloc section in dynobj and make room for
1391 if (htab
->elf
.dynobj
== NULL
)
1392 htab
->elf
.dynobj
= abfd
;
1394 sreloc
= _bfd_elf_make_dynamic_reloc_section
1395 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
1401 /* If this is a global symbol, we count the number of
1402 relocations we need for this symbol. */
1405 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1410 /* Track dynamic relocs needed for local syms too.
1411 We really need local syms available to do this
1415 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1420 /* Beware of type punned pointers vs strict aliasing
1422 vpp
= &(elf_section_data (s
)->local_dynrel
);
1423 head
= (struct elf64_x86_64_dyn_relocs
**)vpp
;
1427 if (p
== NULL
|| p
->sec
!= sec
)
1429 bfd_size_type amt
= sizeof *p
;
1431 p
= ((struct elf64_x86_64_dyn_relocs
*)
1432 bfd_alloc (htab
->elf
.dynobj
, amt
));
1443 if (IS_X86_64_PCREL_TYPE (r_type
))
1448 /* This relocation describes the C++ object vtable hierarchy.
1449 Reconstruct it for later use during GC. */
1450 case R_X86_64_GNU_VTINHERIT
:
1451 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1455 /* This relocation describes which C++ vtable entries are actually
1456 used. Record for later use during GC. */
1457 case R_X86_64_GNU_VTENTRY
:
1458 BFD_ASSERT (h
!= NULL
);
1460 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1472 /* Return the section that should be marked against GC for a given
1476 elf64_x86_64_gc_mark_hook (asection
*sec
,
1477 struct bfd_link_info
*info
,
1478 Elf_Internal_Rela
*rel
,
1479 struct elf_link_hash_entry
*h
,
1480 Elf_Internal_Sym
*sym
)
1483 switch (ELF64_R_TYPE (rel
->r_info
))
1485 case R_X86_64_GNU_VTINHERIT
:
1486 case R_X86_64_GNU_VTENTRY
:
1490 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1493 /* Update the got entry reference counts for the section being removed. */
1496 elf64_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1498 const Elf_Internal_Rela
*relocs
)
1500 Elf_Internal_Shdr
*symtab_hdr
;
1501 struct elf_link_hash_entry
**sym_hashes
;
1502 bfd_signed_vma
*local_got_refcounts
;
1503 const Elf_Internal_Rela
*rel
, *relend
;
1505 if (info
->relocatable
)
1508 elf_section_data (sec
)->local_dynrel
= NULL
;
1510 symtab_hdr
= &elf_symtab_hdr (abfd
);
1511 sym_hashes
= elf_sym_hashes (abfd
);
1512 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1514 relend
= relocs
+ sec
->reloc_count
;
1515 for (rel
= relocs
; rel
< relend
; rel
++)
1517 unsigned long r_symndx
;
1518 unsigned int r_type
;
1519 struct elf_link_hash_entry
*h
= NULL
;
1521 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1522 if (r_symndx
>= symtab_hdr
->sh_info
)
1524 struct elf64_x86_64_link_hash_entry
*eh
;
1525 struct elf64_x86_64_dyn_relocs
**pp
;
1526 struct elf64_x86_64_dyn_relocs
*p
;
1528 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1529 while (h
->root
.type
== bfd_link_hash_indirect
1530 || h
->root
.type
== bfd_link_hash_warning
)
1531 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1532 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1534 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1537 /* Everything must go for SEC. */
1543 r_type
= ELF64_R_TYPE (rel
->r_info
);
1544 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1545 symtab_hdr
, sym_hashes
,
1546 &r_type
, GOT_UNKNOWN
,
1552 case R_X86_64_TLSLD
:
1553 if (elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
> 0)
1554 elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
-= 1;
1557 case R_X86_64_TLSGD
:
1558 case R_X86_64_GOTPC32_TLSDESC
:
1559 case R_X86_64_TLSDESC_CALL
:
1560 case R_X86_64_GOTTPOFF
:
1561 case R_X86_64_GOT32
:
1562 case R_X86_64_GOTPCREL
:
1563 case R_X86_64_GOT64
:
1564 case R_X86_64_GOTPCREL64
:
1565 case R_X86_64_GOTPLT64
:
1568 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
1569 h
->plt
.refcount
-= 1;
1570 if (h
->got
.refcount
> 0)
1571 h
->got
.refcount
-= 1;
1573 else if (local_got_refcounts
!= NULL
)
1575 if (local_got_refcounts
[r_symndx
] > 0)
1576 local_got_refcounts
[r_symndx
] -= 1;
1593 case R_X86_64_PLT32
:
1594 case R_X86_64_PLTOFF64
:
1597 if (h
->plt
.refcount
> 0)
1598 h
->plt
.refcount
-= 1;
1610 /* Adjust a symbol defined by a dynamic object and referenced by a
1611 regular object. The current definition is in some section of the
1612 dynamic object, but we're not including those sections. We have to
1613 change the definition to something the rest of the link can
1617 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1618 struct elf_link_hash_entry
*h
)
1620 struct elf64_x86_64_link_hash_table
*htab
;
1623 /* STT_GNU_IFUNC symbol must go through PLT. */
1624 if (h
->type
== STT_GNU_IFUNC
)
1626 if (h
->plt
.refcount
<= 0)
1628 h
->plt
.offset
= (bfd_vma
) -1;
1634 /* If this is a function, put it in the procedure linkage table. We
1635 will fill in the contents of the procedure linkage table later,
1636 when we know the address of the .got section. */
1637 if (h
->type
== STT_FUNC
1640 if (h
->plt
.refcount
<= 0
1641 || SYMBOL_CALLS_LOCAL (info
, h
)
1642 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1643 && h
->root
.type
== bfd_link_hash_undefweak
))
1645 /* This case can occur if we saw a PLT32 reloc in an input
1646 file, but the symbol was never referred to by a dynamic
1647 object, or if all references were garbage collected. In
1648 such a case, we don't actually need to build a procedure
1649 linkage table, and we can just do a PC32 reloc instead. */
1650 h
->plt
.offset
= (bfd_vma
) -1;
1657 /* It's possible that we incorrectly decided a .plt reloc was
1658 needed for an R_X86_64_PC32 reloc to a non-function sym in
1659 check_relocs. We can't decide accurately between function and
1660 non-function syms in check-relocs; Objects loaded later in
1661 the link may change h->type. So fix it now. */
1662 h
->plt
.offset
= (bfd_vma
) -1;
1664 /* If this is a weak symbol, and there is a real definition, the
1665 processor independent code will have arranged for us to see the
1666 real definition first, and we can just use the same value. */
1667 if (h
->u
.weakdef
!= NULL
)
1669 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1670 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1671 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1672 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1673 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1674 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1678 /* This is a reference to a symbol defined by a dynamic object which
1679 is not a function. */
1681 /* If we are creating a shared library, we must presume that the
1682 only references to the symbol are via the global offset table.
1683 For such cases we need not do anything here; the relocations will
1684 be handled correctly by relocate_section. */
1688 /* If there are no references to this symbol that do not use the
1689 GOT, we don't need to generate a copy reloc. */
1690 if (!h
->non_got_ref
)
1693 /* If -z nocopyreloc was given, we won't generate them either. */
1694 if (info
->nocopyreloc
)
1700 if (ELIMINATE_COPY_RELOCS
)
1702 struct elf64_x86_64_link_hash_entry
* eh
;
1703 struct elf64_x86_64_dyn_relocs
*p
;
1705 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1706 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1708 s
= p
->sec
->output_section
;
1709 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1713 /* If we didn't find any dynamic relocs in read-only sections, then
1714 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1724 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1725 h
->root
.root
.string
);
1729 /* We must allocate the symbol in our .dynbss section, which will
1730 become part of the .bss section of the executable. There will be
1731 an entry for this symbol in the .dynsym section. The dynamic
1732 object will contain position independent code, so all references
1733 from the dynamic object to this symbol will go through the global
1734 offset table. The dynamic linker will use the .dynsym entry to
1735 determine the address it must put in the global offset table, so
1736 both the dynamic object and the regular object will refer to the
1737 same memory location for the variable. */
1739 htab
= elf64_x86_64_hash_table (info
);
1741 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1742 to copy the initial value out of the dynamic object and into the
1743 runtime process image. */
1744 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1746 htab
->srelbss
->size
+= sizeof (Elf64_External_Rela
);
1752 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1755 /* Allocate space in .plt, .got and associated reloc sections for
1759 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
1761 struct bfd_link_info
*info
;
1762 struct elf64_x86_64_link_hash_table
*htab
;
1763 struct elf64_x86_64_link_hash_entry
*eh
;
1764 struct elf64_x86_64_dyn_relocs
*p
;
1766 if (h
->root
.type
== bfd_link_hash_indirect
)
1769 if (h
->root
.type
== bfd_link_hash_warning
)
1770 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1771 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1773 info
= (struct bfd_link_info
*) inf
;
1774 htab
= elf64_x86_64_hash_table (info
);
1776 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1777 here if it is defined and referenced in a non-shared object. */
1778 if (h
->type
== STT_GNU_IFUNC
1781 asection
*plt
, *gotplt
, *relplt
;
1783 /* Return and discard space for dynamic relocations against it if
1784 it is never referenced in a non-shared object. */
1785 if (!h
->ref_regular
)
1787 if (h
->plt
.refcount
> 0
1788 || h
->got
.refcount
> 0)
1790 h
->got
.offset
= (bfd_vma
) -1;
1791 eh
->dyn_relocs
= NULL
;
1795 if (h
->plt
.refcount
<= 0)
1798 /* When building a static executable, use .iplt, .igot.plt and
1799 .rela.iplt sections for STT_GNU_IFUNC symbols. */
1800 if (htab
->splt
!= 0)
1803 gotplt
= htab
->sgotplt
;
1804 relplt
= htab
->srelplt
;
1806 /* If this is the first .plt entry, make room for the special
1809 plt
->size
+= PLT_ENTRY_SIZE
;
1814 gotplt
= htab
->igotplt
;
1815 relplt
= htab
->irelplt
;
1818 /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
1819 the original value for R_X86_64_IRELATIVE. */
1820 h
->plt
.offset
= plt
->size
;
1822 /* Make room for this entry in the .plt/.iplt section. */
1823 plt
->size
+= PLT_ENTRY_SIZE
;
1825 /* We also need to make an entry in the .got.plt/.got.iplt
1826 section, which will be placed in the .got section by the
1828 gotplt
->size
+= GOT_ENTRY_SIZE
;
1830 /* We also need to make an entry in the .rela.plt/.rela.iplt
1832 relplt
->size
+= sizeof (Elf64_External_Rela
);
1833 relplt
->reloc_count
++;
1835 /* No need for dynamic relocation for local STT_GNU_IFUNC symbol.
1836 Discard space for relocations against it. */
1837 if (h
->dynindx
== -1 || h
->forced_local
)
1838 eh
->dyn_relocs
= NULL
;
1840 /* STT_GNU_IFUNC symbol uses .got.plt, not .got. */
1841 h
->got
.refcount
= 0;
1843 else if (htab
->elf
.dynamic_sections_created
1844 && h
->plt
.refcount
> 0)
1846 /* Make sure this symbol is output as a dynamic symbol.
1847 Undefined weak syms won't yet be marked as dynamic. */
1848 if (h
->dynindx
== -1
1849 && !h
->forced_local
)
1851 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1856 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1858 asection
*s
= htab
->splt
;
1860 /* If this is the first .plt entry, make room for the special
1863 s
->size
+= PLT_ENTRY_SIZE
;
1865 h
->plt
.offset
= s
->size
;
1867 /* If this symbol is not defined in a regular file, and we are
1868 not generating a shared library, then set the symbol to this
1869 location in the .plt. This is required to make function
1870 pointers compare as equal between the normal executable and
1871 the shared library. */
1875 h
->root
.u
.def
.section
= s
;
1876 h
->root
.u
.def
.value
= h
->plt
.offset
;
1879 /* Make room for this entry. */
1880 s
->size
+= PLT_ENTRY_SIZE
;
1882 /* We also need to make an entry in the .got.plt section, which
1883 will be placed in the .got section by the linker script. */
1884 htab
->sgotplt
->size
+= GOT_ENTRY_SIZE
;
1886 /* We also need to make an entry in the .rela.plt section. */
1887 htab
->srelplt
->size
+= sizeof (Elf64_External_Rela
);
1888 htab
->srelplt
->reloc_count
++;
1892 h
->plt
.offset
= (bfd_vma
) -1;
1898 h
->plt
.offset
= (bfd_vma
) -1;
1902 eh
->tlsdesc_got
= (bfd_vma
) -1;
1904 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1905 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1906 if (h
->got
.refcount
> 0
1909 && elf64_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
1911 h
->got
.offset
= (bfd_vma
) -1;
1913 else if (h
->got
.refcount
> 0)
1917 int tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1919 /* Make sure this symbol is output as a dynamic symbol.
1920 Undefined weak syms won't yet be marked as dynamic. */
1921 if (h
->dynindx
== -1
1922 && !h
->forced_local
)
1924 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1928 if (GOT_TLS_GDESC_P (tls_type
))
1930 eh
->tlsdesc_got
= htab
->sgotplt
->size
1931 - elf64_x86_64_compute_jump_table_size (htab
);
1932 htab
->sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
1933 h
->got
.offset
= (bfd_vma
) -2;
1935 if (! GOT_TLS_GDESC_P (tls_type
)
1936 || GOT_TLS_GD_P (tls_type
))
1939 h
->got
.offset
= s
->size
;
1940 s
->size
+= GOT_ENTRY_SIZE
;
1941 if (GOT_TLS_GD_P (tls_type
))
1942 s
->size
+= GOT_ENTRY_SIZE
;
1944 dyn
= htab
->elf
.dynamic_sections_created
;
1945 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
1947 R_X86_64_GOTTPOFF needs one dynamic relocation. */
1948 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
1949 || tls_type
== GOT_TLS_IE
)
1950 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
1951 else if (GOT_TLS_GD_P (tls_type
))
1952 htab
->srelgot
->size
+= 2 * sizeof (Elf64_External_Rela
);
1953 else if (! GOT_TLS_GDESC_P (tls_type
)
1954 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1955 || h
->root
.type
!= bfd_link_hash_undefweak
)
1957 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1958 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
1959 if (GOT_TLS_GDESC_P (tls_type
))
1961 htab
->srelplt
->size
+= sizeof (Elf64_External_Rela
);
1962 htab
->tlsdesc_plt
= (bfd_vma
) -1;
1966 h
->got
.offset
= (bfd_vma
) -1;
1968 if (eh
->dyn_relocs
== NULL
)
1971 /* In the shared -Bsymbolic case, discard space allocated for
1972 dynamic pc-relative relocs against symbols which turn out to be
1973 defined in regular objects. For the normal shared case, discard
1974 space for pc-relative relocs that have become local due to symbol
1975 visibility changes. */
1979 /* Relocs that use pc_count are those that appear on a call
1980 insn, or certain REL relocs that can generated via assembly.
1981 We want calls to protected symbols to resolve directly to the
1982 function rather than going via the plt. If people want
1983 function pointer comparisons to work as expected then they
1984 should avoid writing weird assembly. */
1985 if (SYMBOL_CALLS_LOCAL (info
, h
))
1987 struct elf64_x86_64_dyn_relocs
**pp
;
1989 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1991 p
->count
-= p
->pc_count
;
2000 /* Also discard relocs on undefined weak syms with non-default
2002 if (eh
->dyn_relocs
!= NULL
2003 && h
->root
.type
== bfd_link_hash_undefweak
)
2005 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2006 eh
->dyn_relocs
= NULL
;
2008 /* Make sure undefined weak symbols are output as a dynamic
2010 else if (h
->dynindx
== -1
2011 && ! h
->forced_local
2012 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2017 else if (ELIMINATE_COPY_RELOCS
)
2019 /* For the non-shared case, discard space for relocs against
2020 symbols which turn out to need copy relocs or are not
2026 || (htab
->elf
.dynamic_sections_created
2027 && (h
->root
.type
== bfd_link_hash_undefweak
2028 || h
->root
.type
== bfd_link_hash_undefined
))))
2030 /* Make sure this symbol is output as a dynamic symbol.
2031 Undefined weak syms won't yet be marked as dynamic. */
2032 if (h
->dynindx
== -1
2033 && ! h
->forced_local
2034 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2037 /* If that succeeded, we know we'll be keeping all the
2039 if (h
->dynindx
!= -1)
2043 eh
->dyn_relocs
= NULL
;
2048 /* Finally, allocate space. */
2049 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2053 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2055 BFD_ASSERT (sreloc
!= NULL
);
2057 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2063 /* Find any dynamic relocs that apply to read-only sections. */
2066 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2068 struct elf64_x86_64_link_hash_entry
*eh
;
2069 struct elf64_x86_64_dyn_relocs
*p
;
2071 if (h
->root
.type
== bfd_link_hash_warning
)
2072 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2074 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
2075 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2077 asection
*s
= p
->sec
->output_section
;
2079 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2081 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2083 info
->flags
|= DF_TEXTREL
;
2085 /* Not an error, just cut short the traversal. */
2092 /* Set the sizes of the dynamic sections. */
2095 elf64_x86_64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2096 struct bfd_link_info
*info
)
2098 struct elf64_x86_64_link_hash_table
*htab
;
2104 htab
= elf64_x86_64_hash_table (info
);
2105 dynobj
= htab
->elf
.dynobj
;
2109 if (htab
->elf
.dynamic_sections_created
)
2111 /* Set the contents of the .interp section to the interpreter. */
2112 if (info
->executable
)
2114 s
= bfd_get_section_by_name (dynobj
, ".interp");
2117 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2118 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2122 /* Set up .got offsets for local syms, and space for local dynamic
2124 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2126 bfd_signed_vma
*local_got
;
2127 bfd_signed_vma
*end_local_got
;
2128 char *local_tls_type
;
2129 bfd_vma
*local_tlsdesc_gotent
;
2130 bfd_size_type locsymcount
;
2131 Elf_Internal_Shdr
*symtab_hdr
;
2134 if (! is_x86_64_elf (ibfd
))
2137 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2139 struct elf64_x86_64_dyn_relocs
*p
;
2141 for (p
= (struct elf64_x86_64_dyn_relocs
*)
2142 (elf_section_data (s
)->local_dynrel
);
2146 if (!bfd_is_abs_section (p
->sec
)
2147 && bfd_is_abs_section (p
->sec
->output_section
))
2149 /* Input section has been discarded, either because
2150 it is a copy of a linkonce section or due to
2151 linker script /DISCARD/, so we'll be discarding
2154 else if (p
->count
!= 0)
2156 srel
= elf_section_data (p
->sec
)->sreloc
;
2157 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2158 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2159 info
->flags
|= DF_TEXTREL
;
2164 local_got
= elf_local_got_refcounts (ibfd
);
2168 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2169 locsymcount
= symtab_hdr
->sh_info
;
2170 end_local_got
= local_got
+ locsymcount
;
2171 local_tls_type
= elf64_x86_64_local_got_tls_type (ibfd
);
2172 local_tlsdesc_gotent
= elf64_x86_64_local_tlsdesc_gotent (ibfd
);
2174 srel
= htab
->srelgot
;
2175 for (; local_got
< end_local_got
;
2176 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2178 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2181 if (GOT_TLS_GDESC_P (*local_tls_type
))
2183 *local_tlsdesc_gotent
= htab
->sgotplt
->size
2184 - elf64_x86_64_compute_jump_table_size (htab
);
2185 htab
->sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2186 *local_got
= (bfd_vma
) -2;
2188 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2189 || GOT_TLS_GD_P (*local_tls_type
))
2191 *local_got
= s
->size
;
2192 s
->size
+= GOT_ENTRY_SIZE
;
2193 if (GOT_TLS_GD_P (*local_tls_type
))
2194 s
->size
+= GOT_ENTRY_SIZE
;
2197 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2198 || *local_tls_type
== GOT_TLS_IE
)
2200 if (GOT_TLS_GDESC_P (*local_tls_type
))
2202 htab
->srelplt
->size
+= sizeof (Elf64_External_Rela
);
2203 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2205 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2206 || GOT_TLS_GD_P (*local_tls_type
))
2207 srel
->size
+= sizeof (Elf64_External_Rela
);
2211 *local_got
= (bfd_vma
) -1;
2215 if (htab
->tls_ld_got
.refcount
> 0)
2217 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2219 htab
->tls_ld_got
.offset
= htab
->sgot
->size
;
2220 htab
->sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2221 htab
->srelgot
->size
+= sizeof (Elf64_External_Rela
);
2224 htab
->tls_ld_got
.offset
= -1;
2226 /* Allocate global sym .plt and .got entries, and space for global
2227 sym dynamic relocs. */
2228 elf_link_hash_traverse (&htab
->elf
, elf64_x86_64_allocate_dynrelocs
,
2231 /* For every jump slot reserved in the sgotplt, reloc_count is
2232 incremented. However, when we reserve space for TLS descriptors,
2233 it's not incremented, so in order to compute the space reserved
2234 for them, it suffices to multiply the reloc count by the jump
2237 htab
->sgotplt_jump_table_size
2238 = elf64_x86_64_compute_jump_table_size (htab
);
2240 if (htab
->tlsdesc_plt
)
2242 /* If we're not using lazy TLS relocations, don't generate the
2243 PLT and GOT entries they require. */
2244 if ((info
->flags
& DF_BIND_NOW
))
2245 htab
->tlsdesc_plt
= 0;
2248 htab
->tlsdesc_got
= htab
->sgot
->size
;
2249 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
2250 /* Reserve room for the initial entry.
2251 FIXME: we could probably do away with it in this case. */
2252 if (htab
->splt
->size
== 0)
2253 htab
->splt
->size
+= PLT_ENTRY_SIZE
;
2254 htab
->tlsdesc_plt
= htab
->splt
->size
;
2255 htab
->splt
->size
+= PLT_ENTRY_SIZE
;
2259 /* We now have determined the sizes of the various dynamic sections.
2260 Allocate memory for them. */
2262 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2264 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2269 || s
== htab
->sgotplt
2271 || s
== htab
->igotplt
2272 || s
== htab
->sdynbss
)
2274 /* Strip this section if we don't need it; see the
2277 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2279 if (s
->size
!= 0 && s
!= htab
->srelplt
)
2282 /* We use the reloc_count field as a counter if we need
2283 to copy relocs into the output file. */
2284 if (s
!= htab
->srelplt
)
2289 /* It's not one of our sections, so don't allocate space. */
2295 /* If we don't need this section, strip it from the
2296 output file. This is mostly to handle .rela.bss and
2297 .rela.plt. We must create both sections in
2298 create_dynamic_sections, because they must be created
2299 before the linker maps input sections to output
2300 sections. The linker does that before
2301 adjust_dynamic_symbol is called, and it is that
2302 function which decides whether anything needs to go
2303 into these sections. */
2305 s
->flags
|= SEC_EXCLUDE
;
2309 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2312 /* Allocate memory for the section contents. We use bfd_zalloc
2313 here in case unused entries are not reclaimed before the
2314 section's contents are written out. This should not happen,
2315 but this way if it does, we get a R_X86_64_NONE reloc instead
2317 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2318 if (s
->contents
== NULL
)
2322 if (htab
->elf
.dynamic_sections_created
)
2324 /* Add some entries to the .dynamic section. We fill in the
2325 values later, in elf64_x86_64_finish_dynamic_sections, but we
2326 must add the entries now so that we get the correct size for
2327 the .dynamic section. The DT_DEBUG entry is filled in by the
2328 dynamic linker and used by the debugger. */
2329 #define add_dynamic_entry(TAG, VAL) \
2330 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2332 if (info
->executable
)
2334 if (!add_dynamic_entry (DT_DEBUG
, 0))
2338 if (htab
->splt
->size
!= 0)
2340 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2341 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2342 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2343 || !add_dynamic_entry (DT_JMPREL
, 0))
2346 if (htab
->tlsdesc_plt
2347 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2348 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2354 if (!add_dynamic_entry (DT_RELA
, 0)
2355 || !add_dynamic_entry (DT_RELASZ
, 0)
2356 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2359 /* If any dynamic relocs apply to a read-only section,
2360 then we need a DT_TEXTREL entry. */
2361 if ((info
->flags
& DF_TEXTREL
) == 0)
2362 elf_link_hash_traverse (&htab
->elf
,
2363 elf64_x86_64_readonly_dynrelocs
,
2366 if ((info
->flags
& DF_TEXTREL
) != 0)
2368 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2373 #undef add_dynamic_entry
2379 elf64_x86_64_always_size_sections (bfd
*output_bfd
,
2380 struct bfd_link_info
*info
)
2382 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2386 struct elf_link_hash_entry
*tlsbase
;
2388 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2389 "_TLS_MODULE_BASE_",
2390 FALSE
, FALSE
, FALSE
);
2392 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2394 struct bfd_link_hash_entry
*bh
= NULL
;
2395 const struct elf_backend_data
*bed
2396 = get_elf_backend_data (output_bfd
);
2398 if (!(_bfd_generic_link_add_one_symbol
2399 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2400 tls_sec
, 0, NULL
, FALSE
,
2401 bed
->collect
, &bh
)))
2404 elf64_x86_64_hash_table (info
)->tls_module_base
= bh
;
2406 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2407 tlsbase
->def_regular
= 1;
2408 tlsbase
->other
= STV_HIDDEN
;
2409 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2416 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2417 executables. Rather than setting it to the beginning of the TLS
2418 section, we have to set it to the end. This function may be called
2419 multiple times, it is idempotent. */
2422 elf64_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2424 struct bfd_link_hash_entry
*base
;
2426 if (!info
->executable
)
2429 base
= elf64_x86_64_hash_table (info
)->tls_module_base
;
2434 base
->u
.def
.value
= elf_hash_table (info
)->tls_size
;
2437 /* Return the base VMA address which should be subtracted from real addresses
2438 when resolving @dtpoff relocation.
2439 This is PT_TLS segment p_vaddr. */
2442 elf64_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2444 /* If tls_sec is NULL, we should have signalled an error already. */
2445 if (elf_hash_table (info
)->tls_sec
== NULL
)
2447 return elf_hash_table (info
)->tls_sec
->vma
;
2450 /* Return the relocation value for @tpoff relocation
2451 if STT_TLS virtual address is ADDRESS. */
2454 elf64_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2456 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2458 /* If tls_segment is NULL, we should have signalled an error already. */
2459 if (htab
->tls_sec
== NULL
)
2461 return address
- htab
->tls_size
- htab
->tls_sec
->vma
;
2464 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2468 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2470 /* Opcode Instruction
2473 0x0f 0x8x conditional jump */
2475 && (contents
[offset
- 1] == 0xe8
2476 || contents
[offset
- 1] == 0xe9))
2478 && contents
[offset
- 2] == 0x0f
2479 && (contents
[offset
- 1] & 0xf0) == 0x80));
2482 /* Relocate an x86_64 ELF section. */
2485 elf64_x86_64_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
2486 bfd
*input_bfd
, asection
*input_section
,
2487 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
2488 Elf_Internal_Sym
*local_syms
,
2489 asection
**local_sections
)
2491 struct elf64_x86_64_link_hash_table
*htab
;
2492 Elf_Internal_Shdr
*symtab_hdr
;
2493 struct elf_link_hash_entry
**sym_hashes
;
2494 bfd_vma
*local_got_offsets
;
2495 bfd_vma
*local_tlsdesc_gotents
;
2496 Elf_Internal_Rela
*rel
;
2497 Elf_Internal_Rela
*relend
;
2499 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2501 htab
= elf64_x86_64_hash_table (info
);
2502 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2503 sym_hashes
= elf_sym_hashes (input_bfd
);
2504 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2505 local_tlsdesc_gotents
= elf64_x86_64_local_tlsdesc_gotent (input_bfd
);
2507 elf64_x86_64_set_tls_module_base (info
);
2510 relend
= relocs
+ input_section
->reloc_count
;
2511 for (; rel
< relend
; rel
++)
2513 unsigned int r_type
;
2514 reloc_howto_type
*howto
;
2515 unsigned long r_symndx
;
2516 struct elf_link_hash_entry
*h
;
2517 Elf_Internal_Sym
*sym
;
2519 bfd_vma off
, offplt
;
2521 bfd_boolean unresolved_reloc
;
2522 bfd_reloc_status_type r
;
2526 r_type
= ELF64_R_TYPE (rel
->r_info
);
2527 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2528 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2531 if (r_type
>= R_X86_64_max
)
2533 bfd_set_error (bfd_error_bad_value
);
2537 howto
= x86_64_elf_howto_table
+ r_type
;
2538 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2542 unresolved_reloc
= FALSE
;
2543 if (r_symndx
< symtab_hdr
->sh_info
)
2545 sym
= local_syms
+ r_symndx
;
2546 sec
= local_sections
[r_symndx
];
2548 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2554 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2555 r_symndx
, symtab_hdr
, sym_hashes
,
2557 unresolved_reloc
, warned
);
2560 if (sec
!= NULL
&& elf_discarded_section (sec
))
2562 /* For relocs against symbols from removed linkonce sections,
2563 or sections discarded by a linker script, we just want the
2564 section contents zeroed. Avoid any special processing. */
2565 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2571 if (info
->relocatable
)
2574 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2575 it here if it is defined in a non-shared object. */
2577 && h
->type
== STT_GNU_IFUNC
2583 if ((input_section
->flags
& SEC_ALLOC
) == 0
2584 || h
->plt
.offset
== (bfd_vma
) -1)
2587 /* STT_GNU_IFUNC symbol must go through PLT. */
2588 plt
= htab
->splt
? htab
->splt
: htab
->iplt
;
2589 relocation
= (plt
->output_section
->vma
2590 + plt
->output_offset
+ h
->plt
.offset
);
2595 (*_bfd_error_handler
)
2596 (_("%B: relocation %s against STT_GNU_IFUNC "
2597 "symbol `%s' isn't handled by %s"), input_bfd
,
2598 x86_64_elf_howto_table
[r_type
].name
,
2599 h
->root
.root
.string
, __FUNCTION__
);
2600 bfd_set_error (bfd_error_bad_value
);
2604 if (!info
->executable
)
2611 case R_X86_64_PLT32
:
2614 case R_X86_64_GOTPCREL
:
2615 case R_X86_64_GOTPCREL64
:
2616 base_got
= htab
->sgot
;
2617 off
= h
->got
.offset
;
2619 if (base_got
== NULL
2620 || off
!= (bfd_vma
) -1)
2623 /* We can't use h->got.offset here to save state, or
2624 even just remember the offset, as finish_dynamic_symbol
2625 would use that as offset into .got. */
2627 if (htab
->splt
!= NULL
)
2629 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2630 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2631 base_got
= htab
->sgotplt
;
2635 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
2636 off
= plt_index
* GOT_ENTRY_SIZE
;
2637 base_got
= htab
->igotplt
;
2640 if (h
->dynindx
== -1
2644 /* This references the local defitionion. We must
2645 initialize this entry in the global offset table.
2646 Since the offset must always be a multiple of 8, we
2647 use the least significant bit to record whether we
2648 have initialized it already.
2650 When doing a dynamic link, we create a .rela.got
2651 relocation entry to initialize the value. This is
2652 done in the finish_dynamic_symbol routine. */
2657 bfd_put_64 (output_bfd
, relocation
,
2658 base_got
->contents
+ off
);
2659 /* Note that this is harmless for the GOTPLT64 case,
2660 as -1 | 1 still is -1. */
2665 relocation
= (base_got
->output_section
->vma
2666 + base_got
->output_offset
+ off
);
2668 if (r_type
!= R_X86_64_GOTPCREL
2669 && r_type
!= R_X86_64_GOTPCREL64
)
2672 if (htab
->splt
!= NULL
)
2673 gotplt
= htab
->sgotplt
;
2675 gotplt
= htab
->igotplt
;
2676 relocation
-= (gotplt
->output_section
->vma
2677 - gotplt
->output_offset
);
2684 /* When generating a shared object, the relocations handled here are
2685 copied into the output file to be resolved at run time. */
2688 case R_X86_64_GOT32
:
2689 case R_X86_64_GOT64
:
2690 /* Relocation is to the entry for this symbol in the global
2692 case R_X86_64_GOTPCREL
:
2693 case R_X86_64_GOTPCREL64
:
2694 /* Use global offset table entry as symbol value. */
2695 case R_X86_64_GOTPLT64
:
2696 /* This is the same as GOT64 for relocation purposes, but
2697 indicates the existence of a PLT entry. The difficulty is,
2698 that we must calculate the GOT slot offset from the PLT
2699 offset, if this symbol got a PLT entry (it was global).
2700 Additionally if it's computed from the PLT entry, then that
2701 GOT offset is relative to .got.plt, not to .got. */
2702 base_got
= htab
->sgot
;
2704 if (htab
->sgot
== NULL
)
2711 off
= h
->got
.offset
;
2713 && h
->plt
.offset
!= (bfd_vma
)-1
2714 && off
== (bfd_vma
)-1)
2716 /* We can't use h->got.offset here to save
2717 state, or even just remember the offset, as
2718 finish_dynamic_symbol would use that as offset into
2720 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2721 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2722 base_got
= htab
->sgotplt
;
2725 dyn
= htab
->elf
.dynamic_sections_created
;
2727 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2729 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2730 || (ELF_ST_VISIBILITY (h
->other
)
2731 && h
->root
.type
== bfd_link_hash_undefweak
))
2733 /* This is actually a static link, or it is a -Bsymbolic
2734 link and the symbol is defined locally, or the symbol
2735 was forced to be local because of a version file. We
2736 must initialize this entry in the global offset table.
2737 Since the offset must always be a multiple of 8, we
2738 use the least significant bit to record whether we
2739 have initialized it already.
2741 When doing a dynamic link, we create a .rela.got
2742 relocation entry to initialize the value. This is
2743 done in the finish_dynamic_symbol routine. */
2748 bfd_put_64 (output_bfd
, relocation
,
2749 base_got
->contents
+ off
);
2750 /* Note that this is harmless for the GOTPLT64 case,
2751 as -1 | 1 still is -1. */
2756 unresolved_reloc
= FALSE
;
2760 if (local_got_offsets
== NULL
)
2763 off
= local_got_offsets
[r_symndx
];
2765 /* The offset must always be a multiple of 8. We use
2766 the least significant bit to record whether we have
2767 already generated the necessary reloc. */
2772 bfd_put_64 (output_bfd
, relocation
,
2773 base_got
->contents
+ off
);
2778 Elf_Internal_Rela outrel
;
2781 /* We need to generate a R_X86_64_RELATIVE reloc
2782 for the dynamic linker. */
2787 outrel
.r_offset
= (base_got
->output_section
->vma
2788 + base_got
->output_offset
2790 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2791 outrel
.r_addend
= relocation
;
2793 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2794 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2797 local_got_offsets
[r_symndx
] |= 1;
2801 if (off
>= (bfd_vma
) -2)
2804 relocation
= base_got
->output_section
->vma
2805 + base_got
->output_offset
+ off
;
2806 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
2807 relocation
-= htab
->sgotplt
->output_section
->vma
2808 - htab
->sgotplt
->output_offset
;
2812 case R_X86_64_GOTOFF64
:
2813 /* Relocation is relative to the start of the global offset
2816 /* Check to make sure it isn't a protected function symbol
2817 for shared library since it may not be local when used
2818 as function address. */
2822 && h
->type
== STT_FUNC
2823 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
2825 (*_bfd_error_handler
)
2826 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
2827 input_bfd
, h
->root
.root
.string
);
2828 bfd_set_error (bfd_error_bad_value
);
2832 /* Note that sgot is not involved in this
2833 calculation. We always want the start of .got.plt. If we
2834 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
2835 permitted by the ABI, we might have to change this
2837 relocation
-= htab
->sgotplt
->output_section
->vma
2838 + htab
->sgotplt
->output_offset
;
2841 case R_X86_64_GOTPC32
:
2842 case R_X86_64_GOTPC64
:
2843 /* Use global offset table as symbol value. */
2844 relocation
= htab
->sgotplt
->output_section
->vma
2845 + htab
->sgotplt
->output_offset
;
2846 unresolved_reloc
= FALSE
;
2849 case R_X86_64_PLTOFF64
:
2850 /* Relocation is PLT entry relative to GOT. For local
2851 symbols it's the symbol itself relative to GOT. */
2853 /* See PLT32 handling. */
2854 && h
->plt
.offset
!= (bfd_vma
) -1
2855 && htab
->splt
!= NULL
)
2857 relocation
= (htab
->splt
->output_section
->vma
2858 + htab
->splt
->output_offset
2860 unresolved_reloc
= FALSE
;
2863 relocation
-= htab
->sgotplt
->output_section
->vma
2864 + htab
->sgotplt
->output_offset
;
2867 case R_X86_64_PLT32
:
2868 /* Relocation is to the entry for this symbol in the
2869 procedure linkage table. */
2871 /* Resolve a PLT32 reloc against a local symbol directly,
2872 without using the procedure linkage table. */
2876 if (h
->plt
.offset
== (bfd_vma
) -1
2877 || htab
->splt
== NULL
)
2879 /* We didn't make a PLT entry for this symbol. This
2880 happens when statically linking PIC code, or when
2881 using -Bsymbolic. */
2885 relocation
= (htab
->splt
->output_section
->vma
2886 + htab
->splt
->output_offset
2888 unresolved_reloc
= FALSE
;
2895 && (input_section
->flags
& SEC_ALLOC
) != 0
2896 && (input_section
->flags
& SEC_READONLY
) != 0
2899 bfd_boolean fail
= FALSE
;
2901 = (r_type
== R_X86_64_PC32
2902 && is_32bit_relative_branch (contents
, rel
->r_offset
));
2904 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
2906 /* Symbol is referenced locally. Make sure it is
2907 defined locally or for a branch. */
2908 fail
= !h
->def_regular
&& !branch
;
2912 /* Symbol isn't referenced locally. We only allow
2913 branch to symbol with non-default visibility. */
2915 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
2922 const char *pic
= "";
2924 switch (ELF_ST_VISIBILITY (h
->other
))
2927 v
= _("hidden symbol");
2930 v
= _("internal symbol");
2933 v
= _("protected symbol");
2937 pic
= _("; recompile with -fPIC");
2942 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
2944 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
2946 (*_bfd_error_handler
) (fmt
, input_bfd
,
2947 x86_64_elf_howto_table
[r_type
].name
,
2948 v
, h
->root
.root
.string
, pic
);
2949 bfd_set_error (bfd_error_bad_value
);
2960 /* FIXME: The ABI says the linker should make sure the value is
2961 the same when it's zeroextended to 64 bit. */
2963 if ((input_section
->flags
& SEC_ALLOC
) == 0)
2968 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2969 || h
->root
.type
!= bfd_link_hash_undefweak
)
2970 && (! IS_X86_64_PCREL_TYPE (r_type
)
2971 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
2972 || (ELIMINATE_COPY_RELOCS
2979 || h
->root
.type
== bfd_link_hash_undefweak
2980 || h
->root
.type
== bfd_link_hash_undefined
)))
2982 Elf_Internal_Rela outrel
;
2984 bfd_boolean skip
, relocate
;
2987 /* When generating a shared object, these relocations
2988 are copied into the output file to be resolved at run
2994 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2996 if (outrel
.r_offset
== (bfd_vma
) -1)
2998 else if (outrel
.r_offset
== (bfd_vma
) -2)
2999 skip
= TRUE
, relocate
= TRUE
;
3001 outrel
.r_offset
+= (input_section
->output_section
->vma
3002 + input_section
->output_offset
);
3005 memset (&outrel
, 0, sizeof outrel
);
3007 /* h->dynindx may be -1 if this symbol was marked to
3011 && (IS_X86_64_PCREL_TYPE (r_type
)
3013 || ! SYMBOLIC_BIND (info
, h
)
3014 || ! h
->def_regular
))
3016 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3017 outrel
.r_addend
= rel
->r_addend
;
3021 /* This symbol is local, or marked to become local. */
3022 if (r_type
== R_X86_64_64
)
3025 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3026 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3032 if (bfd_is_abs_section (sec
))
3034 else if (sec
== NULL
|| sec
->owner
== NULL
)
3036 bfd_set_error (bfd_error_bad_value
);
3043 /* We are turning this relocation into one
3044 against a section symbol. It would be
3045 proper to subtract the symbol's value,
3046 osec->vma, from the emitted reloc addend,
3047 but ld.so expects buggy relocs. */
3048 osec
= sec
->output_section
;
3049 sindx
= elf_section_data (osec
)->dynindx
;
3052 asection
*oi
= htab
->elf
.text_index_section
;
3053 sindx
= elf_section_data (oi
)->dynindx
;
3055 BFD_ASSERT (sindx
!= 0);
3058 outrel
.r_info
= ELF64_R_INFO (sindx
, r_type
);
3059 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3063 sreloc
= elf_section_data (input_section
)->sreloc
;
3065 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3067 loc
= sreloc
->contents
;
3068 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3069 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3071 /* If this reloc is against an external symbol, we do
3072 not want to fiddle with the addend. Otherwise, we
3073 need to include the symbol value so that it becomes
3074 an addend for the dynamic reloc. */
3081 case R_X86_64_TLSGD
:
3082 case R_X86_64_GOTPC32_TLSDESC
:
3083 case R_X86_64_TLSDESC_CALL
:
3084 case R_X86_64_GOTTPOFF
:
3085 tls_type
= GOT_UNKNOWN
;
3086 if (h
== NULL
&& local_got_offsets
)
3087 tls_type
= elf64_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3089 tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
3091 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3092 input_section
, contents
,
3093 symtab_hdr
, sym_hashes
,
3094 &r_type
, tls_type
, rel
,
3098 if (r_type
== R_X86_64_TPOFF32
)
3100 bfd_vma roff
= rel
->r_offset
;
3102 BFD_ASSERT (! unresolved_reloc
);
3104 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3106 /* GD->LE transition.
3107 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3108 .word 0x6666; rex64; call __tls_get_addr
3111 leaq foo@tpoff(%rax), %rax */
3112 memcpy (contents
+ roff
- 4,
3113 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3115 bfd_put_32 (output_bfd
,
3116 elf64_x86_64_tpoff (info
, relocation
),
3117 contents
+ roff
+ 8);
3118 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3122 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3124 /* GDesc -> LE transition.
3125 It's originally something like:
3126 leaq x@tlsdesc(%rip), %rax
3132 unsigned int val
, type
, type2
;
3134 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3135 type2
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3136 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3137 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3138 contents
+ roff
- 3);
3139 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3140 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3141 contents
+ roff
- 1);
3142 bfd_put_32 (output_bfd
,
3143 elf64_x86_64_tpoff (info
, relocation
),
3147 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3149 /* GDesc -> LE transition.
3154 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3155 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3158 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3160 /* IE->LE transition:
3161 Originally it can be one of:
3162 movq foo@gottpoff(%rip), %reg
3163 addq foo@gottpoff(%rip), %reg
3166 leaq foo(%reg), %reg
3169 unsigned int val
, type
, reg
;
3171 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3172 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3173 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3179 bfd_put_8 (output_bfd
, 0x49,
3180 contents
+ roff
- 3);
3181 bfd_put_8 (output_bfd
, 0xc7,
3182 contents
+ roff
- 2);
3183 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3184 contents
+ roff
- 1);
3188 /* addq -> addq - addressing with %rsp/%r12 is
3191 bfd_put_8 (output_bfd
, 0x49,
3192 contents
+ roff
- 3);
3193 bfd_put_8 (output_bfd
, 0x81,
3194 contents
+ roff
- 2);
3195 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3196 contents
+ roff
- 1);
3202 bfd_put_8 (output_bfd
, 0x4d,
3203 contents
+ roff
- 3);
3204 bfd_put_8 (output_bfd
, 0x8d,
3205 contents
+ roff
- 2);
3206 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3207 contents
+ roff
- 1);
3209 bfd_put_32 (output_bfd
,
3210 elf64_x86_64_tpoff (info
, relocation
),
3218 if (htab
->sgot
== NULL
)
3223 off
= h
->got
.offset
;
3224 offplt
= elf64_x86_64_hash_entry (h
)->tlsdesc_got
;
3228 if (local_got_offsets
== NULL
)
3231 off
= local_got_offsets
[r_symndx
];
3232 offplt
= local_tlsdesc_gotents
[r_symndx
];
3239 Elf_Internal_Rela outrel
;
3244 if (htab
->srelgot
== NULL
)
3247 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3249 if (GOT_TLS_GDESC_P (tls_type
))
3251 outrel
.r_info
= ELF64_R_INFO (indx
, R_X86_64_TLSDESC
);
3252 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3253 + 2 * GOT_ENTRY_SIZE
<= htab
->sgotplt
->size
);
3254 outrel
.r_offset
= (htab
->sgotplt
->output_section
->vma
3255 + htab
->sgotplt
->output_offset
3257 + htab
->sgotplt_jump_table_size
);
3258 sreloc
= htab
->srelplt
;
3259 loc
= sreloc
->contents
;
3260 loc
+= sreloc
->reloc_count
++
3261 * sizeof (Elf64_External_Rela
);
3262 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3263 <= sreloc
->contents
+ sreloc
->size
);
3265 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3267 outrel
.r_addend
= 0;
3268 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3271 sreloc
= htab
->srelgot
;
3273 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3274 + htab
->sgot
->output_offset
+ off
);
3276 if (GOT_TLS_GD_P (tls_type
))
3277 dr_type
= R_X86_64_DTPMOD64
;
3278 else if (GOT_TLS_GDESC_P (tls_type
))
3281 dr_type
= R_X86_64_TPOFF64
;
3283 bfd_put_64 (output_bfd
, 0, htab
->sgot
->contents
+ off
);
3284 outrel
.r_addend
= 0;
3285 if ((dr_type
== R_X86_64_TPOFF64
3286 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3287 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3288 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
3290 loc
= sreloc
->contents
;
3291 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3292 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3293 <= sreloc
->contents
+ sreloc
->size
);
3294 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3296 if (GOT_TLS_GD_P (tls_type
))
3300 BFD_ASSERT (! unresolved_reloc
);
3301 bfd_put_64 (output_bfd
,
3302 relocation
- elf64_x86_64_dtpoff_base (info
),
3303 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3307 bfd_put_64 (output_bfd
, 0,
3308 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3309 outrel
.r_info
= ELF64_R_INFO (indx
,
3311 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3312 sreloc
->reloc_count
++;
3313 loc
+= sizeof (Elf64_External_Rela
);
3314 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
3315 <= sreloc
->contents
+ sreloc
->size
);
3316 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3324 local_got_offsets
[r_symndx
] |= 1;
3327 if (off
>= (bfd_vma
) -2
3328 && ! GOT_TLS_GDESC_P (tls_type
))
3330 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
3332 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3333 || r_type
== R_X86_64_TLSDESC_CALL
)
3334 relocation
= htab
->sgotplt
->output_section
->vma
3335 + htab
->sgotplt
->output_offset
3336 + offplt
+ htab
->sgotplt_jump_table_size
;
3338 relocation
= htab
->sgot
->output_section
->vma
3339 + htab
->sgot
->output_offset
+ off
;
3340 unresolved_reloc
= FALSE
;
3344 bfd_vma roff
= rel
->r_offset
;
3346 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3348 /* GD->IE transition.
3349 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3350 .word 0x6666; rex64; call __tls_get_addr@plt
3353 addq foo@gottpoff(%rip), %rax */
3354 memcpy (contents
+ roff
- 4,
3355 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3358 relocation
= (htab
->sgot
->output_section
->vma
3359 + htab
->sgot
->output_offset
+ off
3361 - input_section
->output_section
->vma
3362 - input_section
->output_offset
3364 bfd_put_32 (output_bfd
, relocation
,
3365 contents
+ roff
+ 8);
3366 /* Skip R_X86_64_PLT32. */
3370 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3372 /* GDesc -> IE transition.
3373 It's originally something like:
3374 leaq x@tlsdesc(%rip), %rax
3377 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax
3380 unsigned int val
, type
, type2
;
3382 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3383 type2
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3384 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3386 /* Now modify the instruction as appropriate. To
3387 turn a leaq into a movq in the form we use it, it
3388 suffices to change the second byte from 0x8d to
3390 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3392 bfd_put_32 (output_bfd
,
3393 htab
->sgot
->output_section
->vma
3394 + htab
->sgot
->output_offset
+ off
3396 - input_section
->output_section
->vma
3397 - input_section
->output_offset
3402 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3404 /* GDesc -> IE transition.
3411 unsigned int val
, type
;
3413 type
= bfd_get_8 (input_bfd
, contents
+ roff
);
3414 val
= bfd_get_8 (input_bfd
, contents
+ roff
+ 1);
3415 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3416 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3424 case R_X86_64_TLSLD
:
3425 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3426 input_section
, contents
,
3427 symtab_hdr
, sym_hashes
,
3428 &r_type
, GOT_UNKNOWN
,
3432 if (r_type
!= R_X86_64_TLSLD
)
3434 /* LD->LE transition:
3435 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3437 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3439 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3440 memcpy (contents
+ rel
->r_offset
- 3,
3441 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3442 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3447 if (htab
->sgot
== NULL
)
3450 off
= htab
->tls_ld_got
.offset
;
3455 Elf_Internal_Rela outrel
;
3458 if (htab
->srelgot
== NULL
)
3461 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3462 + htab
->sgot
->output_offset
+ off
);
3464 bfd_put_64 (output_bfd
, 0,
3465 htab
->sgot
->contents
+ off
);
3466 bfd_put_64 (output_bfd
, 0,
3467 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3468 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_DTPMOD64
);
3469 outrel
.r_addend
= 0;
3470 loc
= htab
->srelgot
->contents
;
3471 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3472 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3473 htab
->tls_ld_got
.offset
|= 1;
3475 relocation
= htab
->sgot
->output_section
->vma
3476 + htab
->sgot
->output_offset
+ off
;
3477 unresolved_reloc
= FALSE
;
3480 case R_X86_64_DTPOFF32
:
3481 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
3482 relocation
-= elf64_x86_64_dtpoff_base (info
);
3484 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3487 case R_X86_64_TPOFF32
:
3488 BFD_ASSERT (! info
->shared
);
3489 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3496 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3497 because such sections are not SEC_ALLOC and thus ld.so will
3498 not process them. */
3499 if (unresolved_reloc
3500 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3502 (*_bfd_error_handler
)
3503 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3506 (long) rel
->r_offset
,
3508 h
->root
.root
.string
);
3511 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3512 contents
, rel
->r_offset
,
3513 relocation
, rel
->r_addend
);
3515 if (r
!= bfd_reloc_ok
)
3520 name
= h
->root
.root
.string
;
3523 name
= bfd_elf_string_from_elf_section (input_bfd
,
3524 symtab_hdr
->sh_link
,
3529 name
= bfd_section_name (input_bfd
, sec
);
3532 if (r
== bfd_reloc_overflow
)
3534 if (! ((*info
->callbacks
->reloc_overflow
)
3535 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3536 (bfd_vma
) 0, input_bfd
, input_section
,
3542 (*_bfd_error_handler
)
3543 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3544 input_bfd
, input_section
,
3545 (long) rel
->r_offset
, name
, (int) r
);
3554 /* Finish up dynamic symbol handling. We set the contents of various
3555 dynamic sections here. */
3558 elf64_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3559 struct bfd_link_info
*info
,
3560 struct elf_link_hash_entry
*h
,
3561 Elf_Internal_Sym
*sym
)
3563 struct elf64_x86_64_link_hash_table
*htab
;
3565 htab
= elf64_x86_64_hash_table (info
);
3567 if (h
->plt
.offset
!= (bfd_vma
) -1)
3571 Elf_Internal_Rela rela
;
3573 asection
*plt
, *gotplt
, *relplt
;
3575 /* When building a static executable, use .iplt, .igot.plt and
3576 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3577 if (htab
->splt
!= 0)
3580 gotplt
= htab
->sgotplt
;
3581 relplt
= htab
->srelplt
;
3586 gotplt
= htab
->igotplt
;
3587 relplt
= htab
->irelplt
;
3590 /* This symbol has an entry in the procedure linkage table. Set
3592 if ((h
->dynindx
== -1
3593 && !((h
->forced_local
|| info
->executable
)
3595 && h
->type
== STT_GNU_IFUNC
))
3601 /* Get the index in the procedure linkage table which
3602 corresponds to this symbol. This is the index of this symbol
3603 in all the symbols for which we are making plt entries. The
3604 first entry in the procedure linkage table is reserved.
3606 Get the offset into the .got table of the entry that
3607 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3608 bytes. The first three are reserved for the dynamic linker.
3610 For static executables, we don't reserve anything. */
3612 if (plt
== htab
->splt
)
3614 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3615 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3619 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3620 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
3623 /* Fill in the entry in the procedure linkage table. */
3624 memcpy (plt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
3627 /* Insert the relocation positions of the plt section. The magic
3628 numbers at the end of the statements are the positions of the
3629 relocations in the plt section. */
3630 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3631 instruction uses 6 bytes, subtract this value. */
3632 bfd_put_32 (output_bfd
,
3633 (gotplt
->output_section
->vma
3634 + gotplt
->output_offset
3636 - plt
->output_section
->vma
3637 - plt
->output_offset
3640 plt
->contents
+ h
->plt
.offset
+ 2);
3642 /* Don't fill PLT entry for static executables. */
3643 if (plt
== htab
->splt
)
3645 /* Put relocation index. */
3646 bfd_put_32 (output_bfd
, plt_index
,
3647 plt
->contents
+ h
->plt
.offset
+ 7);
3648 /* Put offset for jmp .PLT0. */
3649 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3650 plt
->contents
+ h
->plt
.offset
+ 12);
3653 /* Fill in the entry in the global offset table, initially this
3654 points to the pushq instruction in the PLT which is at offset 6. */
3655 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
3656 + plt
->output_offset
3657 + h
->plt
.offset
+ 6),
3658 gotplt
->contents
+ got_offset
);
3660 /* Fill in the entry in the .rela.plt section. */
3661 rela
.r_offset
= (gotplt
->output_section
->vma
3662 + gotplt
->output_offset
3664 if (h
->dynindx
== -1
3665 || ((info
->executable
3666 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3668 && h
->type
== STT_GNU_IFUNC
))
3670 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3671 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
3672 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_IRELATIVE
);
3673 rela
.r_addend
= (h
->root
.u
.def
.value
3674 + h
->root
.u
.def
.section
->output_section
->vma
3675 + h
->root
.u
.def
.section
->output_offset
);
3679 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
3682 loc
= relplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3683 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3685 if (!h
->def_regular
)
3687 /* Mark the symbol as undefined, rather than as defined in
3688 the .plt section. Leave the value if there were any
3689 relocations where pointer equality matters (this is a clue
3690 for the dynamic linker, to make function pointer
3691 comparisons work between an application and shared
3692 library), otherwise set it to zero. If a function is only
3693 called from a binary, there is no need to slow down
3694 shared libraries because of that. */
3695 sym
->st_shndx
= SHN_UNDEF
;
3696 if (!h
->pointer_equality_needed
)
3701 if (h
->got
.offset
!= (bfd_vma
) -1
3702 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h
)->tls_type
)
3703 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
3705 Elf_Internal_Rela rela
;
3708 /* This symbol has an entry in the global offset table. Set it
3710 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3713 rela
.r_offset
= (htab
->sgot
->output_section
->vma
3714 + htab
->sgot
->output_offset
3715 + (h
->got
.offset
&~ (bfd_vma
) 1));
3717 /* If this is a static link, or it is a -Bsymbolic link and the
3718 symbol is defined locally or was forced to be local because
3719 of a version file, we just want to emit a RELATIVE reloc.
3720 The entry in the global offset table will already have been
3721 initialized in the relocate_section function. */
3723 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3725 if (!h
->def_regular
)
3727 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3728 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3729 rela
.r_addend
= (h
->root
.u
.def
.value
3730 + h
->root
.u
.def
.section
->output_section
->vma
3731 + h
->root
.u
.def
.section
->output_offset
);
3735 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3736 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
3737 htab
->sgot
->contents
+ h
->got
.offset
);
3738 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
3742 loc
= htab
->srelgot
->contents
;
3743 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3744 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3749 Elf_Internal_Rela rela
;
3752 /* This symbol needs a copy reloc. Set it up. */
3754 if (h
->dynindx
== -1
3755 || (h
->root
.type
!= bfd_link_hash_defined
3756 && h
->root
.type
!= bfd_link_hash_defweak
)
3757 || htab
->srelbss
== NULL
)
3760 rela
.r_offset
= (h
->root
.u
.def
.value
3761 + h
->root
.u
.def
.section
->output_section
->vma
3762 + h
->root
.u
.def
.section
->output_offset
);
3763 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
3765 loc
= htab
->srelbss
->contents
;
3766 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3767 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3770 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3771 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3772 || h
== htab
->elf
.hgot
)
3773 sym
->st_shndx
= SHN_ABS
;
3778 /* Used to decide how to sort relocs in an optimal manner for the
3779 dynamic linker, before writing them out. */
3781 static enum elf_reloc_type_class
3782 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
3784 switch ((int) ELF64_R_TYPE (rela
->r_info
))
3786 case R_X86_64_RELATIVE
:
3787 return reloc_class_relative
;
3788 case R_X86_64_JUMP_SLOT
:
3789 return reloc_class_plt
;
3791 return reloc_class_copy
;
3793 return reloc_class_normal
;
3797 /* Finish up the dynamic sections. */
3800 elf64_x86_64_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
3802 struct elf64_x86_64_link_hash_table
*htab
;
3806 htab
= elf64_x86_64_hash_table (info
);
3807 dynobj
= htab
->elf
.dynobj
;
3808 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3810 if (htab
->elf
.dynamic_sections_created
)
3812 Elf64_External_Dyn
*dyncon
, *dynconend
;
3814 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3817 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3818 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3819 for (; dyncon
< dynconend
; dyncon
++)
3821 Elf_Internal_Dyn dyn
;
3824 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3833 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3837 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
3841 s
= htab
->srelplt
->output_section
;
3842 dyn
.d_un
.d_val
= s
->size
;
3846 /* The procedure linkage table relocs (DT_JMPREL) should
3847 not be included in the overall relocs (DT_RELA).
3848 Therefore, we override the DT_RELASZ entry here to
3849 make it not include the JMPREL relocs. Since the
3850 linker script arranges for .rela.plt to follow all
3851 other relocation sections, we don't have to worry
3852 about changing the DT_RELA entry. */
3853 if (htab
->srelplt
!= NULL
)
3855 s
= htab
->srelplt
->output_section
;
3856 dyn
.d_un
.d_val
-= s
->size
;
3860 case DT_TLSDESC_PLT
:
3862 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
3863 + htab
->tlsdesc_plt
;
3866 case DT_TLSDESC_GOT
:
3868 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
3869 + htab
->tlsdesc_got
;
3873 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3876 /* Fill in the special first entry in the procedure linkage table. */
3877 if (htab
->splt
&& htab
->splt
->size
> 0)
3879 /* Fill in the first entry in the procedure linkage table. */
3880 memcpy (htab
->splt
->contents
, elf64_x86_64_plt0_entry
,
3882 /* Add offset for pushq GOT+8(%rip), since the instruction
3883 uses 6 bytes subtract this value. */
3884 bfd_put_32 (output_bfd
,
3885 (htab
->sgotplt
->output_section
->vma
3886 + htab
->sgotplt
->output_offset
3888 - htab
->splt
->output_section
->vma
3889 - htab
->splt
->output_offset
3891 htab
->splt
->contents
+ 2);
3892 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
3893 the end of the instruction. */
3894 bfd_put_32 (output_bfd
,
3895 (htab
->sgotplt
->output_section
->vma
3896 + htab
->sgotplt
->output_offset
3898 - htab
->splt
->output_section
->vma
3899 - htab
->splt
->output_offset
3901 htab
->splt
->contents
+ 8);
3903 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
=
3906 if (htab
->tlsdesc_plt
)
3908 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
3909 htab
->sgot
->contents
+ htab
->tlsdesc_got
);
3911 memcpy (htab
->splt
->contents
+ htab
->tlsdesc_plt
,
3912 elf64_x86_64_plt0_entry
,
3915 /* Add offset for pushq GOT+8(%rip), since the
3916 instruction uses 6 bytes subtract this value. */
3917 bfd_put_32 (output_bfd
,
3918 (htab
->sgotplt
->output_section
->vma
3919 + htab
->sgotplt
->output_offset
3921 - htab
->splt
->output_section
->vma
3922 - htab
->splt
->output_offset
3925 htab
->splt
->contents
+ htab
->tlsdesc_plt
+ 2);
3926 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
3927 htab->tlsdesc_got. The 12 is the offset to the end of
3929 bfd_put_32 (output_bfd
,
3930 (htab
->sgot
->output_section
->vma
3931 + htab
->sgot
->output_offset
3933 - htab
->splt
->output_section
->vma
3934 - htab
->splt
->output_offset
3937 htab
->splt
->contents
+ htab
->tlsdesc_plt
+ 8);
3944 /* Fill in the first three entries in the global offset table. */
3945 if (htab
->sgotplt
->size
> 0)
3947 /* Set the first entry in the global offset table to the address of
3948 the dynamic section. */
3950 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
);
3952 bfd_put_64 (output_bfd
,
3953 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3954 htab
->sgotplt
->contents
);
3955 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
3956 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
);
3957 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
3960 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
=
3964 if (htab
->sgot
&& htab
->sgot
->size
> 0)
3965 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
3971 /* Return address for Ith PLT stub in section PLT, for relocation REL
3972 or (bfd_vma) -1 if it should not be included. */
3975 elf64_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
3976 const arelent
*rel ATTRIBUTE_UNUSED
)
3978 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
3981 /* Handle an x86-64 specific section when reading an object file. This
3982 is called when elfcode.h finds a section with an unknown type. */
3985 elf64_x86_64_section_from_shdr (bfd
*abfd
,
3986 Elf_Internal_Shdr
*hdr
,
3990 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
3993 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
3999 /* Hook called by the linker routine which adds symbols from an object
4000 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4004 elf64_x86_64_add_symbol_hook (bfd
*abfd
,
4005 struct bfd_link_info
*info
,
4006 Elf_Internal_Sym
*sym
,
4007 const char **namep ATTRIBUTE_UNUSED
,
4008 flagword
*flagsp ATTRIBUTE_UNUSED
,
4014 switch (sym
->st_shndx
)
4016 case SHN_X86_64_LCOMMON
:
4017 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4020 lcomm
= bfd_make_section_with_flags (abfd
,
4024 | SEC_LINKER_CREATED
));
4027 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4030 *valp
= sym
->st_size
;
4034 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4035 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4041 /* Given a BFD section, try to locate the corresponding ELF section
4045 elf64_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4046 asection
*sec
, int *index
)
4048 if (sec
== &_bfd_elf_large_com_section
)
4050 *index
= SHN_X86_64_LCOMMON
;
4056 /* Process a symbol. */
4059 elf64_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4062 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4064 switch (elfsym
->internal_elf_sym
.st_shndx
)
4066 case SHN_X86_64_LCOMMON
:
4067 asym
->section
= &_bfd_elf_large_com_section
;
4068 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4069 /* Common symbol doesn't set BSF_GLOBAL. */
4070 asym
->flags
&= ~BSF_GLOBAL
;
4076 elf64_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4078 return (sym
->st_shndx
== SHN_COMMON
4079 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4083 elf64_x86_64_common_section_index (asection
*sec
)
4085 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4088 return SHN_X86_64_LCOMMON
;
4092 elf64_x86_64_common_section (asection
*sec
)
4094 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4095 return bfd_com_section_ptr
;
4097 return &_bfd_elf_large_com_section
;
4101 elf64_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4102 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4103 struct elf_link_hash_entry
*h
,
4104 Elf_Internal_Sym
*sym
,
4106 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4107 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4108 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4109 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4110 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4111 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4112 bfd_boolean
*newdef ATTRIBUTE_UNUSED
,
4113 bfd_boolean
*newdyn
,
4114 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4115 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4116 bfd
*abfd ATTRIBUTE_UNUSED
,
4118 bfd_boolean
*olddef ATTRIBUTE_UNUSED
,
4119 bfd_boolean
*olddyn
,
4120 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4121 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4125 /* A normal common symbol and a large common symbol result in a
4126 normal common symbol. We turn the large common symbol into a
4129 && h
->root
.type
== bfd_link_hash_common
4131 && bfd_is_com_section (*sec
)
4134 if (sym
->st_shndx
== SHN_COMMON
4135 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4137 h
->root
.u
.c
.p
->section
4138 = bfd_make_section_old_way (oldbfd
, "COMMON");
4139 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4141 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4142 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4143 *psec
= *sec
= bfd_com_section_ptr
;
4150 elf64_x86_64_additional_program_headers (bfd
*abfd
,
4151 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4156 /* Check to see if we need a large readonly segment. */
4157 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4158 if (s
&& (s
->flags
& SEC_LOAD
))
4161 /* Check to see if we need a large data segment. Since .lbss sections
4162 is placed right after the .bss section, there should be no need for
4163 a large data segment just because of .lbss. */
4164 s
= bfd_get_section_by_name (abfd
, ".ldata");
4165 if (s
&& (s
->flags
& SEC_LOAD
))
4171 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4174 elf64_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4176 if (h
->plt
.offset
!= (bfd_vma
) -1
4178 && !h
->pointer_equality_needed
)
4181 return _bfd_elf_hash_symbol (h
);
4184 static const struct bfd_elf_special_section
4185 elf64_x86_64_special_sections
[]=
4187 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4188 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4189 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4190 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4191 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4192 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4193 { NULL
, 0, 0, 0, 0 }
4196 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4197 #define TARGET_LITTLE_NAME "elf64-x86-64"
4198 #define ELF_ARCH bfd_arch_i386
4199 #define ELF_MACHINE_CODE EM_X86_64
4200 #define ELF_MAXPAGESIZE 0x200000
4201 #define ELF_MINPAGESIZE 0x1000
4202 #define ELF_COMMONPAGESIZE 0x1000
4204 #define elf_backend_can_gc_sections 1
4205 #define elf_backend_can_refcount 1
4206 #define elf_backend_want_got_plt 1
4207 #define elf_backend_plt_readonly 1
4208 #define elf_backend_want_plt_sym 0
4209 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4210 #define elf_backend_rela_normal 1
4212 #define elf_info_to_howto elf64_x86_64_info_to_howto
4214 #define bfd_elf64_bfd_link_hash_table_create \
4215 elf64_x86_64_link_hash_table_create
4216 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
4217 #define bfd_elf64_bfd_reloc_name_lookup \
4218 elf64_x86_64_reloc_name_lookup
4220 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
4221 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4222 #define elf_backend_check_relocs elf64_x86_64_check_relocs
4223 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
4224 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
4225 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
4226 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
4227 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
4228 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
4229 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
4230 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
4231 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
4232 #define elf_backend_relocate_section elf64_x86_64_relocate_section
4233 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
4234 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
4235 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4236 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
4237 #define elf_backend_object_p elf64_x86_64_elf_object_p
4238 #define bfd_elf64_mkobject elf64_x86_64_mkobject
4240 #define elf_backend_section_from_shdr \
4241 elf64_x86_64_section_from_shdr
4243 #define elf_backend_section_from_bfd_section \
4244 elf64_x86_64_elf_section_from_bfd_section
4245 #define elf_backend_add_symbol_hook \
4246 elf64_x86_64_add_symbol_hook
4247 #define elf_backend_symbol_processing \
4248 elf64_x86_64_symbol_processing
4249 #define elf_backend_common_section_index \
4250 elf64_x86_64_common_section_index
4251 #define elf_backend_common_section \
4252 elf64_x86_64_common_section
4253 #define elf_backend_common_definition \
4254 elf64_x86_64_common_definition
4255 #define elf_backend_merge_symbol \
4256 elf64_x86_64_merge_symbol
4257 #define elf_backend_special_sections \
4258 elf64_x86_64_special_sections
4259 #define elf_backend_additional_program_headers \
4260 elf64_x86_64_additional_program_headers
4261 #define elf_backend_hash_symbol \
4262 elf64_x86_64_hash_symbol
4264 #undef elf_backend_post_process_headers
4265 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4267 #include "elf64-target.h"
4269 /* FreeBSD support. */
4271 #undef TARGET_LITTLE_SYM
4272 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4273 #undef TARGET_LITTLE_NAME
4274 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4277 #define ELF_OSABI ELFOSABI_FREEBSD
4280 #define elf64_bed elf64_x86_64_fbsd_bed
4282 #include "elf64-target.h"