1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010 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"
32 #include "elf/x86-64.h"
34 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
35 #define MINUS_ONE (~ (bfd_vma) 0)
37 /* The relocation "howto" table. Order of fields:
38 type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow,
39 special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
40 static reloc_howto_type x86_64_elf_howto_table
[] =
42 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
43 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
45 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
46 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
48 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
49 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
51 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
52 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
54 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
55 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
57 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
58 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
60 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
61 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
63 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
64 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
66 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
67 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
69 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
70 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
72 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
73 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
75 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
76 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
78 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
79 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
80 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
81 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
82 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_bitfield
,
83 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
84 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
85 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
86 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
87 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
89 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
90 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
92 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
93 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
95 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
96 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
98 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
99 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
101 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
102 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
104 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
105 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
107 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
108 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
110 HOWTO(R_X86_64_PC64
, 0, 4, 64, TRUE
, 0, complain_overflow_bitfield
,
111 bfd_elf_generic_reloc
, "R_X86_64_PC64", FALSE
, MINUS_ONE
, MINUS_ONE
,
113 HOWTO(R_X86_64_GOTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
114 bfd_elf_generic_reloc
, "R_X86_64_GOTOFF64",
115 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
116 HOWTO(R_X86_64_GOTPC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
117 bfd_elf_generic_reloc
, "R_X86_64_GOTPC32",
118 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
119 HOWTO(R_X86_64_GOT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
120 bfd_elf_generic_reloc
, "R_X86_64_GOT64", FALSE
, MINUS_ONE
, MINUS_ONE
,
122 HOWTO(R_X86_64_GOTPCREL64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
123 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL64", FALSE
, MINUS_ONE
,
125 HOWTO(R_X86_64_GOTPC64
, 0, 4, 64, TRUE
, 0, complain_overflow_signed
,
126 bfd_elf_generic_reloc
, "R_X86_64_GOTPC64",
127 FALSE
, MINUS_ONE
, MINUS_ONE
, TRUE
),
128 HOWTO(R_X86_64_GOTPLT64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
129 bfd_elf_generic_reloc
, "R_X86_64_GOTPLT64", FALSE
, MINUS_ONE
,
131 HOWTO(R_X86_64_PLTOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_signed
,
132 bfd_elf_generic_reloc
, "R_X86_64_PLTOFF64", FALSE
, MINUS_ONE
,
136 HOWTO(R_X86_64_GOTPC32_TLSDESC
, 0, 2, 32, TRUE
, 0,
137 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
138 "R_X86_64_GOTPC32_TLSDESC",
139 FALSE
, 0xffffffff, 0xffffffff, TRUE
),
140 HOWTO(R_X86_64_TLSDESC_CALL
, 0, 0, 0, FALSE
, 0,
141 complain_overflow_dont
, bfd_elf_generic_reloc
,
142 "R_X86_64_TLSDESC_CALL",
144 HOWTO(R_X86_64_TLSDESC
, 0, 4, 64, FALSE
, 0,
145 complain_overflow_bitfield
, bfd_elf_generic_reloc
,
147 FALSE
, MINUS_ONE
, MINUS_ONE
, FALSE
),
148 HOWTO(R_X86_64_IRELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
149 bfd_elf_generic_reloc
, "R_X86_64_IRELATIVE", FALSE
, MINUS_ONE
,
152 /* We have a gap in the reloc numbers here.
153 R_X86_64_standard counts the number up to this point, and
154 R_X86_64_vt_offset is the value to subtract from a reloc type of
155 R_X86_64_GNU_VT* to form an index into this table. */
156 #define R_X86_64_standard (R_X86_64_IRELATIVE + 1)
157 #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard)
159 /* GNU extension to record C++ vtable hierarchy. */
160 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
161 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
163 /* GNU extension to record C++ vtable member usage. */
164 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
165 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
169 #define IS_X86_64_PCREL_TYPE(TYPE) \
170 ( ((TYPE) == R_X86_64_PC8) \
171 || ((TYPE) == R_X86_64_PC16) \
172 || ((TYPE) == R_X86_64_PC32) \
173 || ((TYPE) == R_X86_64_PC64))
175 /* Map BFD relocs to the x86_64 elf relocs. */
178 bfd_reloc_code_real_type bfd_reloc_val
;
179 unsigned char elf_reloc_val
;
182 static const struct elf_reloc_map x86_64_reloc_map
[] =
184 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
185 { BFD_RELOC_64
, R_X86_64_64
, },
186 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
187 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
188 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
189 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
190 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
191 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
192 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
193 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
194 { BFD_RELOC_32
, R_X86_64_32
, },
195 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
196 { BFD_RELOC_16
, R_X86_64_16
, },
197 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
198 { BFD_RELOC_8
, R_X86_64_8
, },
199 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
200 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
201 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
202 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
203 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
204 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
205 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
206 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
207 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
208 { BFD_RELOC_64_PCREL
, R_X86_64_PC64
, },
209 { BFD_RELOC_X86_64_GOTOFF64
, R_X86_64_GOTOFF64
, },
210 { BFD_RELOC_X86_64_GOTPC32
, R_X86_64_GOTPC32
, },
211 { BFD_RELOC_X86_64_GOT64
, R_X86_64_GOT64
, },
212 { BFD_RELOC_X86_64_GOTPCREL64
,R_X86_64_GOTPCREL64
, },
213 { BFD_RELOC_X86_64_GOTPC64
, R_X86_64_GOTPC64
, },
214 { BFD_RELOC_X86_64_GOTPLT64
, R_X86_64_GOTPLT64
, },
215 { BFD_RELOC_X86_64_PLTOFF64
, R_X86_64_PLTOFF64
, },
216 { BFD_RELOC_X86_64_GOTPC32_TLSDESC
, R_X86_64_GOTPC32_TLSDESC
, },
217 { BFD_RELOC_X86_64_TLSDESC_CALL
, R_X86_64_TLSDESC_CALL
, },
218 { BFD_RELOC_X86_64_TLSDESC
, R_X86_64_TLSDESC
, },
219 { BFD_RELOC_X86_64_IRELATIVE
, R_X86_64_IRELATIVE
, },
220 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
221 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
224 static reloc_howto_type
*
225 elf64_x86_64_rtype_to_howto (bfd
*abfd
, unsigned r_type
)
229 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
230 || r_type
>= (unsigned int) R_X86_64_max
)
232 if (r_type
>= (unsigned int) R_X86_64_standard
)
234 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
236 r_type
= R_X86_64_NONE
;
241 i
= r_type
- (unsigned int) R_X86_64_vt_offset
;
242 BFD_ASSERT (x86_64_elf_howto_table
[i
].type
== r_type
);
243 return &x86_64_elf_howto_table
[i
];
246 /* Given a BFD reloc type, return a HOWTO structure. */
247 static reloc_howto_type
*
248 elf64_x86_64_reloc_type_lookup (bfd
*abfd
,
249 bfd_reloc_code_real_type code
)
253 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
256 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
257 return elf64_x86_64_rtype_to_howto (abfd
,
258 x86_64_reloc_map
[i
].elf_reloc_val
);
263 static reloc_howto_type
*
264 elf64_x86_64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
270 i
< (sizeof (x86_64_elf_howto_table
)
271 / sizeof (x86_64_elf_howto_table
[0]));
273 if (x86_64_elf_howto_table
[i
].name
!= NULL
274 && strcasecmp (x86_64_elf_howto_table
[i
].name
, r_name
) == 0)
275 return &x86_64_elf_howto_table
[i
];
280 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
283 elf64_x86_64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
284 Elf_Internal_Rela
*dst
)
288 r_type
= ELF64_R_TYPE (dst
->r_info
);
289 cache_ptr
->howto
= elf64_x86_64_rtype_to_howto (abfd
, r_type
);
290 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
293 /* Support for core dump NOTE sections. */
295 elf64_x86_64_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
300 switch (note
->descsz
)
305 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
307 elf_tdata (abfd
)->core_signal
308 = bfd_get_16 (abfd
, note
->descdata
+ 12);
311 elf_tdata (abfd
)->core_pid
312 = bfd_get_32 (abfd
, note
->descdata
+ 32);
321 /* Make a ".reg/999" section. */
322 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
323 size
, note
->descpos
+ offset
);
327 elf64_x86_64_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
329 switch (note
->descsz
)
334 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
335 elf_tdata (abfd
)->core_program
336 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
337 elf_tdata (abfd
)->core_command
338 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
341 /* Note that for some reason, a spurious space is tacked
342 onto the end of the args in some (at least one anyway)
343 implementations, so strip it off if it exists. */
346 char *command
= elf_tdata (abfd
)->core_command
;
347 int n
= strlen (command
);
349 if (0 < n
&& command
[n
- 1] == ' ')
350 command
[n
- 1] = '\0';
356 /* Functions for the x86-64 ELF linker. */
358 /* The name of the dynamic interpreter. This is put in the .interp
361 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
363 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
364 copying dynamic variables from a shared lib into an app's dynbss
365 section, and instead use a dynamic relocation to point into the
367 #define ELIMINATE_COPY_RELOCS 1
369 /* The size in bytes of an entry in the global offset table. */
371 #define GOT_ENTRY_SIZE 8
373 /* The size in bytes of an entry in the procedure linkage table. */
375 #define PLT_ENTRY_SIZE 16
377 /* The first entry in a procedure linkage table looks like this. See the
378 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
380 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
382 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
383 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
384 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
387 /* Subsequent entries in a procedure linkage table look like this. */
389 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
391 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
392 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
393 0x68, /* pushq immediate */
394 0, 0, 0, 0, /* replaced with index into relocation table. */
395 0xe9, /* jmp relative */
396 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
399 /* x86-64 ELF linker hash entry. */
401 struct elf64_x86_64_link_hash_entry
403 struct elf_link_hash_entry elf
;
405 /* Track dynamic relocs copied for this symbol. */
406 struct elf_dyn_relocs
*dyn_relocs
;
408 #define GOT_UNKNOWN 0
412 #define GOT_TLS_GDESC 4
413 #define GOT_TLS_GD_BOTH_P(type) \
414 ((type) == (GOT_TLS_GD | GOT_TLS_GDESC))
415 #define GOT_TLS_GD_P(type) \
416 ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type))
417 #define GOT_TLS_GDESC_P(type) \
418 ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type))
419 #define GOT_TLS_GD_ANY_P(type) \
420 (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
421 unsigned char tls_type
;
423 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
424 starting at the end of the jump table. */
428 #define elf64_x86_64_hash_entry(ent) \
429 ((struct elf64_x86_64_link_hash_entry *)(ent))
431 struct elf64_x86_64_obj_tdata
433 struct elf_obj_tdata root
;
435 /* tls_type for each local got entry. */
436 char *local_got_tls_type
;
438 /* GOTPLT entries for TLS descriptors. */
439 bfd_vma
*local_tlsdesc_gotent
;
442 #define elf64_x86_64_tdata(abfd) \
443 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
445 #define elf64_x86_64_local_got_tls_type(abfd) \
446 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
448 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
449 (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
451 #define is_x86_64_elf(bfd) \
452 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
453 && elf_tdata (bfd) != NULL \
454 && elf_object_id (bfd) == X86_64_ELF_DATA)
457 elf64_x86_64_mkobject (bfd
*abfd
)
459 return bfd_elf_allocate_object (abfd
, sizeof (struct elf64_x86_64_obj_tdata
),
463 /* x86-64 ELF linker hash table. */
465 struct elf64_x86_64_link_hash_table
467 struct elf_link_hash_table elf
;
469 /* Short-cuts to get to dynamic linker sections. */
475 bfd_signed_vma refcount
;
479 /* The amount of space used by the jump slots in the GOT. */
480 bfd_vma sgotplt_jump_table_size
;
482 /* Small local sym cache. */
483 struct sym_cache sym_cache
;
485 /* _TLS_MODULE_BASE_ symbol. */
486 struct bfd_link_hash_entry
*tls_module_base
;
488 /* Used by local STT_GNU_IFUNC symbols. */
489 htab_t loc_hash_table
;
490 void * loc_hash_memory
;
492 /* The offset into splt of the PLT entry for the TLS descriptor
493 resolver. Special values are 0, if not necessary (or not found
494 to be necessary yet), and -1 if needed but not determined
497 /* The offset into sgot of the GOT entry used by the PLT entry
502 /* Get the x86-64 ELF linker hash table from a link_info structure. */
504 #define elf64_x86_64_hash_table(p) \
505 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
506 == X86_64_ELF_DATA ? ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) : NULL)
508 #define elf64_x86_64_compute_jump_table_size(htab) \
509 ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE)
511 /* Create an entry in an x86-64 ELF linker hash table. */
513 static struct bfd_hash_entry
*
514 elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
515 struct bfd_hash_table
*table
,
518 /* Allocate the structure if it has not already been allocated by a
522 entry
= (struct bfd_hash_entry
*)
523 bfd_hash_allocate (table
,
524 sizeof (struct elf64_x86_64_link_hash_entry
));
529 /* Call the allocation method of the superclass. */
530 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
533 struct elf64_x86_64_link_hash_entry
*eh
;
535 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
536 eh
->dyn_relocs
= NULL
;
537 eh
->tls_type
= GOT_UNKNOWN
;
538 eh
->tlsdesc_got
= (bfd_vma
) -1;
544 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
545 for local symbol so that we can handle local STT_GNU_IFUNC symbols
546 as global symbol. We reuse indx and dynstr_index for local symbol
547 hash since they aren't used by global symbols in this backend. */
550 elf64_x86_64_local_htab_hash (const void *ptr
)
552 struct elf_link_hash_entry
*h
553 = (struct elf_link_hash_entry
*) ptr
;
554 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
557 /* Compare local hash entries. */
560 elf64_x86_64_local_htab_eq (const void *ptr1
, const void *ptr2
)
562 struct elf_link_hash_entry
*h1
563 = (struct elf_link_hash_entry
*) ptr1
;
564 struct elf_link_hash_entry
*h2
565 = (struct elf_link_hash_entry
*) ptr2
;
567 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
570 /* Find and/or create a hash entry for local symbol. */
572 static struct elf_link_hash_entry
*
573 elf64_x86_64_get_local_sym_hash (struct elf64_x86_64_link_hash_table
*htab
,
574 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
577 struct elf64_x86_64_link_hash_entry e
, *ret
;
578 asection
*sec
= abfd
->sections
;
579 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
580 ELF64_R_SYM (rel
->r_info
));
583 e
.elf
.indx
= sec
->id
;
584 e
.elf
.dynstr_index
= ELF64_R_SYM (rel
->r_info
);
585 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
586 create
? INSERT
: NO_INSERT
);
593 ret
= (struct elf64_x86_64_link_hash_entry
*) *slot
;
597 ret
= (struct elf64_x86_64_link_hash_entry
*)
598 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
599 sizeof (struct elf64_x86_64_link_hash_entry
));
602 memset (ret
, 0, sizeof (*ret
));
603 ret
->elf
.indx
= sec
->id
;
604 ret
->elf
.dynstr_index
= ELF64_R_SYM (rel
->r_info
);
605 ret
->elf
.dynindx
= -1;
611 /* Create an X86-64 ELF linker hash table. */
613 static struct bfd_link_hash_table
*
614 elf64_x86_64_link_hash_table_create (bfd
*abfd
)
616 struct elf64_x86_64_link_hash_table
*ret
;
617 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
619 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_malloc (amt
);
623 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
624 elf64_x86_64_link_hash_newfunc
,
625 sizeof (struct elf64_x86_64_link_hash_entry
),
634 ret
->sym_cache
.abfd
= NULL
;
635 ret
->tlsdesc_plt
= 0;
636 ret
->tlsdesc_got
= 0;
637 ret
->tls_ld_got
.refcount
= 0;
638 ret
->sgotplt_jump_table_size
= 0;
639 ret
->tls_module_base
= NULL
;
641 ret
->loc_hash_table
= htab_try_create (1024,
642 elf64_x86_64_local_htab_hash
,
643 elf64_x86_64_local_htab_eq
,
645 ret
->loc_hash_memory
= objalloc_create ();
646 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
652 return &ret
->elf
.root
;
655 /* Destroy an X86-64 ELF linker hash table. */
658 elf64_x86_64_link_hash_table_free (struct bfd_link_hash_table
*hash
)
660 struct elf64_x86_64_link_hash_table
*htab
661 = (struct elf64_x86_64_link_hash_table
*) hash
;
663 if (htab
->loc_hash_table
)
664 htab_delete (htab
->loc_hash_table
);
665 if (htab
->loc_hash_memory
)
666 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
667 _bfd_generic_link_hash_table_free (hash
);
670 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
671 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
675 elf64_x86_64_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
677 struct elf64_x86_64_link_hash_table
*htab
;
679 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
682 htab
= elf64_x86_64_hash_table (info
);
686 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
688 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
691 || (!info
->shared
&& !htab
->srelbss
))
697 /* Copy the extra info we tack onto an elf_link_hash_entry. */
700 elf64_x86_64_copy_indirect_symbol (struct bfd_link_info
*info
,
701 struct elf_link_hash_entry
*dir
,
702 struct elf_link_hash_entry
*ind
)
704 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
706 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
707 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
709 if (eind
->dyn_relocs
!= NULL
)
711 if (edir
->dyn_relocs
!= NULL
)
713 struct elf_dyn_relocs
**pp
;
714 struct elf_dyn_relocs
*p
;
716 /* Add reloc counts against the indirect sym to the direct sym
717 list. Merge any entries against the same section. */
718 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
720 struct elf_dyn_relocs
*q
;
722 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
723 if (q
->sec
== p
->sec
)
725 q
->pc_count
+= p
->pc_count
;
726 q
->count
+= p
->count
;
733 *pp
= edir
->dyn_relocs
;
736 edir
->dyn_relocs
= eind
->dyn_relocs
;
737 eind
->dyn_relocs
= NULL
;
740 if (ind
->root
.type
== bfd_link_hash_indirect
741 && dir
->got
.refcount
<= 0)
743 edir
->tls_type
= eind
->tls_type
;
744 eind
->tls_type
= GOT_UNKNOWN
;
747 if (ELIMINATE_COPY_RELOCS
748 && ind
->root
.type
!= bfd_link_hash_indirect
749 && dir
->dynamic_adjusted
)
751 /* If called to transfer flags for a weakdef during processing
752 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
753 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
754 dir
->ref_dynamic
|= ind
->ref_dynamic
;
755 dir
->ref_regular
|= ind
->ref_regular
;
756 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
757 dir
->needs_plt
|= ind
->needs_plt
;
758 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
761 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
765 elf64_x86_64_elf_object_p (bfd
*abfd
)
767 /* Set the right machine number for an x86-64 elf64 file. */
768 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
786 /* Return TRUE if the TLS access code sequence support transition
790 elf64_x86_64_check_tls_transition (bfd
*abfd
, asection
*sec
,
792 Elf_Internal_Shdr
*symtab_hdr
,
793 struct elf_link_hash_entry
**sym_hashes
,
795 const Elf_Internal_Rela
*rel
,
796 const Elf_Internal_Rela
*relend
)
799 unsigned long r_symndx
;
800 struct elf_link_hash_entry
*h
;
803 /* Get the section contents. */
804 if (contents
== NULL
)
806 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
807 contents
= elf_section_data (sec
)->this_hdr
.contents
;
810 /* FIXME: How to better handle error condition? */
811 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
814 /* Cache the section contents for elf_link_input_bfd. */
815 elf_section_data (sec
)->this_hdr
.contents
= contents
;
819 offset
= rel
->r_offset
;
824 if ((rel
+ 1) >= relend
)
827 if (r_type
== R_X86_64_TLSGD
)
829 /* Check transition from GD access model. Only
830 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
831 .word 0x6666; rex64; call __tls_get_addr
832 can transit to different access model. */
834 static x86_64_opcode32 leaq
= { { 0x66, 0x48, 0x8d, 0x3d } },
835 call
= { { 0x66, 0x66, 0x48, 0xe8 } };
837 || (offset
+ 12) > sec
->size
838 || bfd_get_32 (abfd
, contents
+ offset
- 4) != leaq
.i
839 || bfd_get_32 (abfd
, contents
+ offset
+ 4) != call
.i
)
844 /* Check transition from LD access model. Only
845 leaq foo@tlsld(%rip), %rdi;
847 can transit to different access model. */
849 static x86_64_opcode32 ld
= { { 0x48, 0x8d, 0x3d, 0xe8 } };
852 if (offset
< 3 || (offset
+ 9) > sec
->size
)
855 op
.i
= bfd_get_32 (abfd
, contents
+ offset
- 3);
856 op
.c
[3] = bfd_get_8 (abfd
, contents
+ offset
+ 4);
861 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
862 if (r_symndx
< symtab_hdr
->sh_info
)
865 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
866 /* Use strncmp to check __tls_get_addr since __tls_get_addr
869 && h
->root
.root
.string
!= NULL
870 && (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PC32
871 || ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
)
872 && (strncmp (h
->root
.root
.string
,
873 "__tls_get_addr", 14) == 0));
875 case R_X86_64_GOTTPOFF
:
876 /* Check transition from IE access model:
877 movq foo@gottpoff(%rip), %reg
878 addq foo@gottpoff(%rip), %reg
881 if (offset
< 3 || (offset
+ 4) > sec
->size
)
884 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
885 if (val
!= 0x48 && val
!= 0x4c)
888 val
= bfd_get_8 (abfd
, contents
+ offset
- 2);
889 if (val
!= 0x8b && val
!= 0x03)
892 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
893 return (val
& 0xc7) == 5;
895 case R_X86_64_GOTPC32_TLSDESC
:
896 /* Check transition from GDesc access model:
897 leaq x@tlsdesc(%rip), %rax
899 Make sure it's a leaq adding rip to a 32-bit offset
900 into any register, although it's probably almost always
903 if (offset
< 3 || (offset
+ 4) > sec
->size
)
906 val
= bfd_get_8 (abfd
, contents
+ offset
- 3);
907 if ((val
& 0xfb) != 0x48)
910 if (bfd_get_8 (abfd
, contents
+ offset
- 2) != 0x8d)
913 val
= bfd_get_8 (abfd
, contents
+ offset
- 1);
914 return (val
& 0xc7) == 0x05;
916 case R_X86_64_TLSDESC_CALL
:
917 /* Check transition from GDesc access model:
918 call *x@tlsdesc(%rax)
920 if (offset
+ 2 <= sec
->size
)
922 /* Make sure that it's a call *x@tlsdesc(%rax). */
923 static x86_64_opcode16 call
= { { 0xff, 0x10 } };
924 return bfd_get_16 (abfd
, contents
+ offset
) == call
.i
;
934 /* Return TRUE if the TLS access transition is OK or no transition
935 will be performed. Update R_TYPE if there is a transition. */
938 elf64_x86_64_tls_transition (struct bfd_link_info
*info
, bfd
*abfd
,
939 asection
*sec
, bfd_byte
*contents
,
940 Elf_Internal_Shdr
*symtab_hdr
,
941 struct elf_link_hash_entry
**sym_hashes
,
942 unsigned int *r_type
, int tls_type
,
943 const Elf_Internal_Rela
*rel
,
944 const Elf_Internal_Rela
*relend
,
945 struct elf_link_hash_entry
*h
,
946 unsigned long r_symndx
)
948 unsigned int from_type
= *r_type
;
949 unsigned int to_type
= from_type
;
950 bfd_boolean check
= TRUE
;
952 /* Skip TLS transition for functions. */
954 && (h
->type
== STT_FUNC
955 || h
->type
== STT_GNU_IFUNC
))
961 case R_X86_64_GOTPC32_TLSDESC
:
962 case R_X86_64_TLSDESC_CALL
:
963 case R_X86_64_GOTTPOFF
:
964 if (info
->executable
)
967 to_type
= R_X86_64_TPOFF32
;
969 to_type
= R_X86_64_GOTTPOFF
;
972 /* When we are called from elf64_x86_64_relocate_section,
973 CONTENTS isn't NULL and there may be additional transitions
974 based on TLS_TYPE. */
975 if (contents
!= NULL
)
977 unsigned int new_to_type
= to_type
;
982 && tls_type
== GOT_TLS_IE
)
983 new_to_type
= R_X86_64_TPOFF32
;
985 if (to_type
== R_X86_64_TLSGD
986 || to_type
== R_X86_64_GOTPC32_TLSDESC
987 || to_type
== R_X86_64_TLSDESC_CALL
)
989 if (tls_type
== GOT_TLS_IE
)
990 new_to_type
= R_X86_64_GOTTPOFF
;
993 /* We checked the transition before when we were called from
994 elf64_x86_64_check_relocs. We only want to check the new
995 transition which hasn't been checked before. */
996 check
= new_to_type
!= to_type
&& from_type
== to_type
;
997 to_type
= new_to_type
;
1002 case R_X86_64_TLSLD
:
1003 if (info
->executable
)
1004 to_type
= R_X86_64_TPOFF32
;
1011 /* Return TRUE if there is no transition. */
1012 if (from_type
== to_type
)
1015 /* Check if the transition can be performed. */
1017 && ! elf64_x86_64_check_tls_transition (abfd
, sec
, contents
,
1018 symtab_hdr
, sym_hashes
,
1019 from_type
, rel
, relend
))
1021 reloc_howto_type
*from
, *to
;
1024 from
= elf64_x86_64_rtype_to_howto (abfd
, from_type
);
1025 to
= elf64_x86_64_rtype_to_howto (abfd
, to_type
);
1028 name
= h
->root
.root
.string
;
1031 struct elf64_x86_64_link_hash_table
*htab
;
1033 htab
= elf64_x86_64_hash_table (info
);
1038 Elf_Internal_Sym
*isym
;
1040 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1042 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1046 (*_bfd_error_handler
)
1047 (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
1048 "in section `%A' failed"),
1049 abfd
, sec
, from
->name
, to
->name
, name
,
1050 (unsigned long) rel
->r_offset
);
1051 bfd_set_error (bfd_error_bad_value
);
1059 /* Look through the relocs for a section during the first phase, and
1060 calculate needed space in the global offset table, procedure
1061 linkage table, and dynamic reloc sections. */
1064 elf64_x86_64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1066 const Elf_Internal_Rela
*relocs
)
1068 struct elf64_x86_64_link_hash_table
*htab
;
1069 Elf_Internal_Shdr
*symtab_hdr
;
1070 struct elf_link_hash_entry
**sym_hashes
;
1071 const Elf_Internal_Rela
*rel
;
1072 const Elf_Internal_Rela
*rel_end
;
1075 if (info
->relocatable
)
1078 BFD_ASSERT (is_x86_64_elf (abfd
));
1080 htab
= elf64_x86_64_hash_table (info
);
1084 symtab_hdr
= &elf_symtab_hdr (abfd
);
1085 sym_hashes
= elf_sym_hashes (abfd
);
1089 rel_end
= relocs
+ sec
->reloc_count
;
1090 for (rel
= relocs
; rel
< rel_end
; rel
++)
1092 unsigned int r_type
;
1093 unsigned long r_symndx
;
1094 struct elf_link_hash_entry
*h
;
1095 Elf_Internal_Sym
*isym
;
1098 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1099 r_type
= ELF64_R_TYPE (rel
->r_info
);
1101 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
1103 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"),
1108 if (r_symndx
< symtab_hdr
->sh_info
)
1110 /* A local symbol. */
1111 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1116 /* Check relocation against local STT_GNU_IFUNC symbol. */
1117 if (ELF64_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1119 h
= elf64_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1124 /* Fake a STT_GNU_IFUNC symbol. */
1125 h
->type
= STT_GNU_IFUNC
;
1128 h
->forced_local
= 1;
1129 h
->root
.type
= bfd_link_hash_defined
;
1137 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1138 while (h
->root
.type
== bfd_link_hash_indirect
1139 || h
->root
.type
== bfd_link_hash_warning
)
1140 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1145 /* Create the ifunc sections for static executables. If we
1146 never see an indirect function symbol nor we are building
1147 a static executable, those sections will be empty and
1148 won't appear in output. */
1159 case R_X86_64_PLT32
:
1160 case R_X86_64_GOTPCREL
:
1161 case R_X86_64_GOTPCREL64
:
1162 if (!_bfd_elf_create_ifunc_sections (abfd
, info
))
1167 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
1168 it here if it is defined in a non-shared object. */
1169 if (h
->type
== STT_GNU_IFUNC
1172 /* It is referenced by a non-shared object. */
1176 /* STT_GNU_IFUNC symbol must go through PLT. */
1177 h
->plt
.refcount
+= 1;
1179 /* STT_GNU_IFUNC needs dynamic sections. */
1180 if (htab
->elf
.dynobj
== NULL
)
1181 htab
->elf
.dynobj
= abfd
;
1186 if (h
->root
.root
.string
)
1187 name
= h
->root
.root
.string
;
1189 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1191 (*_bfd_error_handler
)
1192 (_("%B: relocation %s against STT_GNU_IFUNC "
1193 "symbol `%s' isn't handled by %s"), abfd
,
1194 x86_64_elf_howto_table
[r_type
].name
,
1195 name
, __FUNCTION__
);
1196 bfd_set_error (bfd_error_bad_value
);
1201 h
->pointer_equality_needed
= 1;
1204 /* We must copy these reloc types into the output
1205 file. Create a reloc section in dynobj and
1206 make room for this reloc. */
1207 sreloc
= _bfd_elf_create_ifunc_dyn_reloc
1208 (abfd
, info
, sec
, sreloc
,
1209 &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
);
1220 if (r_type
!= R_X86_64_PC32
1221 && r_type
!= R_X86_64_PC64
)
1222 h
->pointer_equality_needed
= 1;
1225 case R_X86_64_PLT32
:
1228 case R_X86_64_GOTPCREL
:
1229 case R_X86_64_GOTPCREL64
:
1230 h
->got
.refcount
+= 1;
1231 if (htab
->elf
.sgot
== NULL
1232 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1242 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1243 symtab_hdr
, sym_hashes
,
1244 &r_type
, GOT_UNKNOWN
,
1245 rel
, rel_end
, h
, r_symndx
))
1250 case R_X86_64_TLSLD
:
1251 htab
->tls_ld_got
.refcount
+= 1;
1254 case R_X86_64_TPOFF32
:
1255 if (!info
->executable
)
1258 name
= h
->root
.root
.string
;
1260 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
,
1262 (*_bfd_error_handler
)
1263 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1265 x86_64_elf_howto_table
[r_type
].name
, name
);
1266 bfd_set_error (bfd_error_bad_value
);
1271 case R_X86_64_GOTTPOFF
:
1272 if (!info
->executable
)
1273 info
->flags
|= DF_STATIC_TLS
;
1276 case R_X86_64_GOT32
:
1277 case R_X86_64_GOTPCREL
:
1278 case R_X86_64_TLSGD
:
1279 case R_X86_64_GOT64
:
1280 case R_X86_64_GOTPCREL64
:
1281 case R_X86_64_GOTPLT64
:
1282 case R_X86_64_GOTPC32_TLSDESC
:
1283 case R_X86_64_TLSDESC_CALL
:
1284 /* This symbol requires a global offset table entry. */
1286 int tls_type
, old_tls_type
;
1290 default: tls_type
= GOT_NORMAL
; break;
1291 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
1292 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
1293 case R_X86_64_GOTPC32_TLSDESC
:
1294 case R_X86_64_TLSDESC_CALL
:
1295 tls_type
= GOT_TLS_GDESC
; break;
1300 if (r_type
== R_X86_64_GOTPLT64
)
1302 /* This relocation indicates that we also need
1303 a PLT entry, as this is a function. We don't need
1304 a PLT entry for local symbols. */
1306 h
->plt
.refcount
+= 1;
1308 h
->got
.refcount
+= 1;
1309 old_tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1313 bfd_signed_vma
*local_got_refcounts
;
1315 /* This is a global offset table entry for a local symbol. */
1316 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1317 if (local_got_refcounts
== NULL
)
1321 size
= symtab_hdr
->sh_info
;
1322 size
*= sizeof (bfd_signed_vma
)
1323 + sizeof (bfd_vma
) + sizeof (char);
1324 local_got_refcounts
= ((bfd_signed_vma
*)
1325 bfd_zalloc (abfd
, size
));
1326 if (local_got_refcounts
== NULL
)
1328 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1329 elf64_x86_64_local_tlsdesc_gotent (abfd
)
1330 = (bfd_vma
*) (local_got_refcounts
+ symtab_hdr
->sh_info
);
1331 elf64_x86_64_local_got_tls_type (abfd
)
1332 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
1334 local_got_refcounts
[r_symndx
] += 1;
1336 = elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
];
1339 /* If a TLS symbol is accessed using IE at least once,
1340 there is no point to use dynamic model for it. */
1341 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
1342 && (! GOT_TLS_GD_ANY_P (old_tls_type
)
1343 || tls_type
!= GOT_TLS_IE
))
1345 if (old_tls_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (tls_type
))
1346 tls_type
= old_tls_type
;
1347 else if (GOT_TLS_GD_ANY_P (old_tls_type
)
1348 && GOT_TLS_GD_ANY_P (tls_type
))
1349 tls_type
|= old_tls_type
;
1353 name
= h
->root
.root
.string
;
1355 name
= bfd_elf_sym_name (abfd
, symtab_hdr
,
1357 (*_bfd_error_handler
)
1358 (_("%B: '%s' accessed both as normal and thread local symbol"),
1364 if (old_tls_type
!= tls_type
)
1367 elf64_x86_64_hash_entry (h
)->tls_type
= tls_type
;
1369 elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1374 case R_X86_64_GOTOFF64
:
1375 case R_X86_64_GOTPC32
:
1376 case R_X86_64_GOTPC64
:
1378 if (htab
->elf
.sgot
== NULL
)
1380 if (htab
->elf
.dynobj
== NULL
)
1381 htab
->elf
.dynobj
= abfd
;
1382 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
,
1388 case R_X86_64_PLT32
:
1389 /* This symbol requires a procedure linkage table entry. We
1390 actually build the entry in adjust_dynamic_symbol,
1391 because this might be a case of linking PIC code which is
1392 never referenced by a dynamic object, in which case we
1393 don't need to generate a procedure linkage table entry
1396 /* If this is a local symbol, we resolve it directly without
1397 creating a procedure linkage table entry. */
1402 h
->plt
.refcount
+= 1;
1405 case R_X86_64_PLTOFF64
:
1406 /* This tries to form the 'address' of a function relative
1407 to GOT. For global symbols we need a PLT entry. */
1411 h
->plt
.refcount
+= 1;
1419 /* Let's help debug shared library creation. These relocs
1420 cannot be used in shared libs. Don't error out for
1421 sections we don't care about, such as debug sections or
1422 non-constant sections. */
1424 && (sec
->flags
& SEC_ALLOC
) != 0
1425 && (sec
->flags
& SEC_READONLY
) != 0)
1428 name
= h
->root
.root
.string
;
1430 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, isym
, NULL
);
1431 (*_bfd_error_handler
)
1432 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1433 abfd
, x86_64_elf_howto_table
[r_type
].name
, name
);
1434 bfd_set_error (bfd_error_bad_value
);
1444 if (h
!= NULL
&& info
->executable
)
1446 /* If this reloc is in a read-only section, we might
1447 need a copy reloc. We can't check reliably at this
1448 stage whether the section is read-only, as input
1449 sections have not yet been mapped to output sections.
1450 Tentatively set the flag for now, and correct in
1451 adjust_dynamic_symbol. */
1454 /* We may need a .plt entry if the function this reloc
1455 refers to is in a shared lib. */
1456 h
->plt
.refcount
+= 1;
1457 if (r_type
!= R_X86_64_PC32
&& r_type
!= R_X86_64_PC64
)
1458 h
->pointer_equality_needed
= 1;
1461 /* If we are creating a shared library, and this is a reloc
1462 against a global symbol, or a non PC relative reloc
1463 against a local symbol, then we need to copy the reloc
1464 into the shared library. However, if we are linking with
1465 -Bsymbolic, we do not need to copy a reloc against a
1466 global symbol which is defined in an object we are
1467 including in the link (i.e., DEF_REGULAR is set). At
1468 this point we have not seen all the input files, so it is
1469 possible that DEF_REGULAR is not set now but will be set
1470 later (it is never cleared). In case of a weak definition,
1471 DEF_REGULAR may be cleared later by a strong definition in
1472 a shared library. We account for that possibility below by
1473 storing information in the relocs_copied field of the hash
1474 table entry. A similar situation occurs when creating
1475 shared libraries and symbol visibility changes render the
1478 If on the other hand, we are creating an executable, we
1479 may need to keep relocations for symbols satisfied by a
1480 dynamic library if we manage to avoid copy relocs for the
1483 && (sec
->flags
& SEC_ALLOC
) != 0
1484 && (! IS_X86_64_PCREL_TYPE (r_type
)
1486 && (! SYMBOLIC_BIND (info
, h
)
1487 || h
->root
.type
== bfd_link_hash_defweak
1488 || !h
->def_regular
))))
1489 || (ELIMINATE_COPY_RELOCS
1491 && (sec
->flags
& SEC_ALLOC
) != 0
1493 && (h
->root
.type
== bfd_link_hash_defweak
1494 || !h
->def_regular
)))
1496 struct elf_dyn_relocs
*p
;
1497 struct elf_dyn_relocs
**head
;
1499 /* We must copy these reloc types into the output file.
1500 Create a reloc section in dynobj and make room for
1504 if (htab
->elf
.dynobj
== NULL
)
1505 htab
->elf
.dynobj
= abfd
;
1507 sreloc
= _bfd_elf_make_dynamic_reloc_section
1508 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
1514 /* If this is a global symbol, we count the number of
1515 relocations we need for this symbol. */
1518 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1522 /* Track dynamic relocs needed for local syms too.
1523 We really need local syms available to do this
1528 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1533 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1537 /* Beware of type punned pointers vs strict aliasing
1539 vpp
= &(elf_section_data (s
)->local_dynrel
);
1540 head
= (struct elf_dyn_relocs
**)vpp
;
1544 if (p
== NULL
|| p
->sec
!= sec
)
1546 bfd_size_type amt
= sizeof *p
;
1548 p
= ((struct elf_dyn_relocs
*)
1549 bfd_alloc (htab
->elf
.dynobj
, amt
));
1560 if (IS_X86_64_PCREL_TYPE (r_type
))
1565 /* This relocation describes the C++ object vtable hierarchy.
1566 Reconstruct it for later use during GC. */
1567 case R_X86_64_GNU_VTINHERIT
:
1568 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1572 /* This relocation describes which C++ vtable entries are actually
1573 used. Record for later use during GC. */
1574 case R_X86_64_GNU_VTENTRY
:
1575 BFD_ASSERT (h
!= NULL
);
1577 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1589 /* Return the section that should be marked against GC for a given
1593 elf64_x86_64_gc_mark_hook (asection
*sec
,
1594 struct bfd_link_info
*info
,
1595 Elf_Internal_Rela
*rel
,
1596 struct elf_link_hash_entry
*h
,
1597 Elf_Internal_Sym
*sym
)
1600 switch (ELF64_R_TYPE (rel
->r_info
))
1602 case R_X86_64_GNU_VTINHERIT
:
1603 case R_X86_64_GNU_VTENTRY
:
1607 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
1610 /* Update the got entry reference counts for the section being removed. */
1613 elf64_x86_64_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1615 const Elf_Internal_Rela
*relocs
)
1617 struct elf64_x86_64_link_hash_table
*htab
;
1618 Elf_Internal_Shdr
*symtab_hdr
;
1619 struct elf_link_hash_entry
**sym_hashes
;
1620 bfd_signed_vma
*local_got_refcounts
;
1621 const Elf_Internal_Rela
*rel
, *relend
;
1623 if (info
->relocatable
)
1626 htab
= elf64_x86_64_hash_table (info
);
1630 elf_section_data (sec
)->local_dynrel
= NULL
;
1632 symtab_hdr
= &elf_symtab_hdr (abfd
);
1633 sym_hashes
= elf_sym_hashes (abfd
);
1634 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1636 relend
= relocs
+ sec
->reloc_count
;
1637 for (rel
= relocs
; rel
< relend
; rel
++)
1639 unsigned long r_symndx
;
1640 unsigned int r_type
;
1641 struct elf_link_hash_entry
*h
= NULL
;
1643 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1644 if (r_symndx
>= symtab_hdr
->sh_info
)
1646 struct elf64_x86_64_link_hash_entry
*eh
;
1647 struct elf_dyn_relocs
**pp
;
1648 struct elf_dyn_relocs
*p
;
1650 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1651 while (h
->root
.type
== bfd_link_hash_indirect
1652 || h
->root
.type
== bfd_link_hash_warning
)
1653 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1654 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1656 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1659 /* Everything must go for SEC. */
1666 /* A local symbol. */
1667 Elf_Internal_Sym
*isym
;
1669 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
1672 /* Check relocation against local STT_GNU_IFUNC symbol. */
1674 && ELF64_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1676 h
= elf64_x86_64_get_local_sym_hash (htab
, abfd
, rel
,
1683 r_type
= ELF64_R_TYPE (rel
->r_info
);
1684 if (! elf64_x86_64_tls_transition (info
, abfd
, sec
, NULL
,
1685 symtab_hdr
, sym_hashes
,
1686 &r_type
, GOT_UNKNOWN
,
1687 rel
, relend
, h
, r_symndx
))
1692 case R_X86_64_TLSLD
:
1693 if (htab
->tls_ld_got
.refcount
> 0)
1694 htab
->tls_ld_got
.refcount
-= 1;
1697 case R_X86_64_TLSGD
:
1698 case R_X86_64_GOTPC32_TLSDESC
:
1699 case R_X86_64_TLSDESC_CALL
:
1700 case R_X86_64_GOTTPOFF
:
1701 case R_X86_64_GOT32
:
1702 case R_X86_64_GOTPCREL
:
1703 case R_X86_64_GOT64
:
1704 case R_X86_64_GOTPCREL64
:
1705 case R_X86_64_GOTPLT64
:
1708 if (r_type
== R_X86_64_GOTPLT64
&& h
->plt
.refcount
> 0)
1709 h
->plt
.refcount
-= 1;
1710 if (h
->got
.refcount
> 0)
1711 h
->got
.refcount
-= 1;
1712 if (h
->type
== STT_GNU_IFUNC
)
1714 if (h
->plt
.refcount
> 0)
1715 h
->plt
.refcount
-= 1;
1718 else if (local_got_refcounts
!= NULL
)
1720 if (local_got_refcounts
[r_symndx
] > 0)
1721 local_got_refcounts
[r_symndx
] -= 1;
1738 case R_X86_64_PLT32
:
1739 case R_X86_64_PLTOFF64
:
1742 if (h
->plt
.refcount
> 0)
1743 h
->plt
.refcount
-= 1;
1755 /* Adjust a symbol defined by a dynamic object and referenced by a
1756 regular object. The current definition is in some section of the
1757 dynamic object, but we're not including those sections. We have to
1758 change the definition to something the rest of the link can
1762 elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1763 struct elf_link_hash_entry
*h
)
1765 struct elf64_x86_64_link_hash_table
*htab
;
1768 /* STT_GNU_IFUNC symbol must go through PLT. */
1769 if (h
->type
== STT_GNU_IFUNC
)
1771 if (h
->plt
.refcount
<= 0)
1773 h
->plt
.offset
= (bfd_vma
) -1;
1779 /* If this is a function, put it in the procedure linkage table. We
1780 will fill in the contents of the procedure linkage table later,
1781 when we know the address of the .got section. */
1782 if (h
->type
== STT_FUNC
1785 if (h
->plt
.refcount
<= 0
1786 || SYMBOL_CALLS_LOCAL (info
, h
)
1787 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1788 && h
->root
.type
== bfd_link_hash_undefweak
))
1790 /* This case can occur if we saw a PLT32 reloc in an input
1791 file, but the symbol was never referred to by a dynamic
1792 object, or if all references were garbage collected. In
1793 such a case, we don't actually need to build a procedure
1794 linkage table, and we can just do a PC32 reloc instead. */
1795 h
->plt
.offset
= (bfd_vma
) -1;
1802 /* It's possible that we incorrectly decided a .plt reloc was
1803 needed for an R_X86_64_PC32 reloc to a non-function sym in
1804 check_relocs. We can't decide accurately between function and
1805 non-function syms in check-relocs; Objects loaded later in
1806 the link may change h->type. So fix it now. */
1807 h
->plt
.offset
= (bfd_vma
) -1;
1809 /* If this is a weak symbol, and there is a real definition, the
1810 processor independent code will have arranged for us to see the
1811 real definition first, and we can just use the same value. */
1812 if (h
->u
.weakdef
!= NULL
)
1814 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1815 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1816 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1817 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1818 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1819 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
1823 /* This is a reference to a symbol defined by a dynamic object which
1824 is not a function. */
1826 /* If we are creating a shared library, we must presume that the
1827 only references to the symbol are via the global offset table.
1828 For such cases we need not do anything here; the relocations will
1829 be handled correctly by relocate_section. */
1833 /* If there are no references to this symbol that do not use the
1834 GOT, we don't need to generate a copy reloc. */
1835 if (!h
->non_got_ref
)
1838 /* If -z nocopyreloc was given, we won't generate them either. */
1839 if (info
->nocopyreloc
)
1845 if (ELIMINATE_COPY_RELOCS
)
1847 struct elf64_x86_64_link_hash_entry
* eh
;
1848 struct elf_dyn_relocs
*p
;
1850 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1851 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1853 s
= p
->sec
->output_section
;
1854 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1858 /* If we didn't find any dynamic relocs in read-only sections, then
1859 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1869 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1870 h
->root
.root
.string
);
1874 /* We must allocate the symbol in our .dynbss section, which will
1875 become part of the .bss section of the executable. There will be
1876 an entry for this symbol in the .dynsym section. The dynamic
1877 object will contain position independent code, so all references
1878 from the dynamic object to this symbol will go through the global
1879 offset table. The dynamic linker will use the .dynsym entry to
1880 determine the address it must put in the global offset table, so
1881 both the dynamic object and the regular object will refer to the
1882 same memory location for the variable. */
1884 htab
= elf64_x86_64_hash_table (info
);
1888 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1889 to copy the initial value out of the dynamic object and into the
1890 runtime process image. */
1891 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1893 htab
->srelbss
->size
+= sizeof (Elf64_External_Rela
);
1899 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1902 /* Allocate space in .plt, .got and associated reloc sections for
1906 elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
1908 struct bfd_link_info
*info
;
1909 struct elf64_x86_64_link_hash_table
*htab
;
1910 struct elf64_x86_64_link_hash_entry
*eh
;
1911 struct elf_dyn_relocs
*p
;
1913 if (h
->root
.type
== bfd_link_hash_indirect
)
1916 if (h
->root
.type
== bfd_link_hash_warning
)
1917 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1918 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1920 info
= (struct bfd_link_info
*) inf
;
1921 htab
= elf64_x86_64_hash_table (info
);
1925 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1926 here if it is defined and referenced in a non-shared object. */
1927 if (h
->type
== STT_GNU_IFUNC
1929 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
1933 else if (htab
->elf
.dynamic_sections_created
1934 && h
->plt
.refcount
> 0)
1936 /* Make sure this symbol is output as a dynamic symbol.
1937 Undefined weak syms won't yet be marked as dynamic. */
1938 if (h
->dynindx
== -1
1939 && !h
->forced_local
)
1941 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1946 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1948 asection
*s
= htab
->elf
.splt
;
1950 /* If this is the first .plt entry, make room for the special
1953 s
->size
+= PLT_ENTRY_SIZE
;
1955 h
->plt
.offset
= s
->size
;
1957 /* If this symbol is not defined in a regular file, and we are
1958 not generating a shared library, then set the symbol to this
1959 location in the .plt. This is required to make function
1960 pointers compare as equal between the normal executable and
1961 the shared library. */
1965 h
->root
.u
.def
.section
= s
;
1966 h
->root
.u
.def
.value
= h
->plt
.offset
;
1969 /* Make room for this entry. */
1970 s
->size
+= PLT_ENTRY_SIZE
;
1972 /* We also need to make an entry in the .got.plt section, which
1973 will be placed in the .got section by the linker script. */
1974 htab
->elf
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
1976 /* We also need to make an entry in the .rela.plt section. */
1977 htab
->elf
.srelplt
->size
+= sizeof (Elf64_External_Rela
);
1978 htab
->elf
.srelplt
->reloc_count
++;
1982 h
->plt
.offset
= (bfd_vma
) -1;
1988 h
->plt
.offset
= (bfd_vma
) -1;
1992 eh
->tlsdesc_got
= (bfd_vma
) -1;
1994 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1995 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1996 if (h
->got
.refcount
> 0
1999 && elf64_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
2001 h
->got
.offset
= (bfd_vma
) -1;
2003 else if (h
->got
.refcount
> 0)
2007 int tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
2009 /* Make sure this symbol is output as a dynamic symbol.
2010 Undefined weak syms won't yet be marked as dynamic. */
2011 if (h
->dynindx
== -1
2012 && !h
->forced_local
)
2014 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2018 if (GOT_TLS_GDESC_P (tls_type
))
2020 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
2021 - elf64_x86_64_compute_jump_table_size (htab
);
2022 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2023 h
->got
.offset
= (bfd_vma
) -2;
2025 if (! GOT_TLS_GDESC_P (tls_type
)
2026 || GOT_TLS_GD_P (tls_type
))
2029 h
->got
.offset
= s
->size
;
2030 s
->size
+= GOT_ENTRY_SIZE
;
2031 if (GOT_TLS_GD_P (tls_type
))
2032 s
->size
+= GOT_ENTRY_SIZE
;
2034 dyn
= htab
->elf
.dynamic_sections_created
;
2035 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
2037 R_X86_64_GOTTPOFF needs one dynamic relocation. */
2038 if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
2039 || tls_type
== GOT_TLS_IE
)
2040 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2041 else if (GOT_TLS_GD_P (tls_type
))
2042 htab
->elf
.srelgot
->size
+= 2 * sizeof (Elf64_External_Rela
);
2043 else if (! GOT_TLS_GDESC_P (tls_type
)
2044 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2045 || h
->root
.type
!= bfd_link_hash_undefweak
)
2047 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
2048 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2049 if (GOT_TLS_GDESC_P (tls_type
))
2051 htab
->elf
.srelplt
->size
+= sizeof (Elf64_External_Rela
);
2052 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2056 h
->got
.offset
= (bfd_vma
) -1;
2058 if (eh
->dyn_relocs
== NULL
)
2061 /* In the shared -Bsymbolic case, discard space allocated for
2062 dynamic pc-relative relocs against symbols which turn out to be
2063 defined in regular objects. For the normal shared case, discard
2064 space for pc-relative relocs that have become local due to symbol
2065 visibility changes. */
2069 /* Relocs that use pc_count are those that appear on a call
2070 insn, or certain REL relocs that can generated via assembly.
2071 We want calls to protected symbols to resolve directly to the
2072 function rather than going via the plt. If people want
2073 function pointer comparisons to work as expected then they
2074 should avoid writing weird assembly. */
2075 if (SYMBOL_CALLS_LOCAL (info
, h
))
2077 struct elf_dyn_relocs
**pp
;
2079 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2081 p
->count
-= p
->pc_count
;
2090 /* Also discard relocs on undefined weak syms with non-default
2092 if (eh
->dyn_relocs
!= NULL
2093 && h
->root
.type
== bfd_link_hash_undefweak
)
2095 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2096 eh
->dyn_relocs
= NULL
;
2098 /* Make sure undefined weak symbols are output as a dynamic
2100 else if (h
->dynindx
== -1
2101 && ! h
->forced_local
2102 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2107 else if (ELIMINATE_COPY_RELOCS
)
2109 /* For the non-shared case, discard space for relocs against
2110 symbols which turn out to need copy relocs or are not
2116 || (htab
->elf
.dynamic_sections_created
2117 && (h
->root
.type
== bfd_link_hash_undefweak
2118 || h
->root
.type
== bfd_link_hash_undefined
))))
2120 /* Make sure this symbol is output as a dynamic symbol.
2121 Undefined weak syms won't yet be marked as dynamic. */
2122 if (h
->dynindx
== -1
2123 && ! h
->forced_local
2124 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2127 /* If that succeeded, we know we'll be keeping all the
2129 if (h
->dynindx
!= -1)
2133 eh
->dyn_relocs
= NULL
;
2138 /* Finally, allocate space. */
2139 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2143 sreloc
= elf_section_data (p
->sec
)->sreloc
;
2145 BFD_ASSERT (sreloc
!= NULL
);
2147 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2153 /* Allocate space in .plt, .got and associated reloc sections for
2154 local dynamic relocs. */
2157 elf64_x86_64_allocate_local_dynrelocs (void **slot
, void *inf
)
2159 struct elf_link_hash_entry
*h
2160 = (struct elf_link_hash_entry
*) *slot
;
2162 if (h
->type
!= STT_GNU_IFUNC
2166 || h
->root
.type
!= bfd_link_hash_defined
)
2169 return elf64_x86_64_allocate_dynrelocs (h
, inf
);
2172 /* Find any dynamic relocs that apply to read-only sections. */
2175 elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
2177 struct elf64_x86_64_link_hash_entry
*eh
;
2178 struct elf_dyn_relocs
*p
;
2180 if (h
->root
.type
== bfd_link_hash_warning
)
2181 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2183 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
2184 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2186 asection
*s
= p
->sec
->output_section
;
2188 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2190 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2192 info
->flags
|= DF_TEXTREL
;
2194 /* Not an error, just cut short the traversal. */
2201 /* Set the sizes of the dynamic sections. */
2204 elf64_x86_64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2205 struct bfd_link_info
*info
)
2207 struct elf64_x86_64_link_hash_table
*htab
;
2213 htab
= elf64_x86_64_hash_table (info
);
2217 dynobj
= htab
->elf
.dynobj
;
2221 if (htab
->elf
.dynamic_sections_created
)
2223 /* Set the contents of the .interp section to the interpreter. */
2224 if (info
->executable
)
2226 s
= bfd_get_section_by_name (dynobj
, ".interp");
2229 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2230 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2234 /* Set up .got offsets for local syms, and space for local dynamic
2236 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2238 bfd_signed_vma
*local_got
;
2239 bfd_signed_vma
*end_local_got
;
2240 char *local_tls_type
;
2241 bfd_vma
*local_tlsdesc_gotent
;
2242 bfd_size_type locsymcount
;
2243 Elf_Internal_Shdr
*symtab_hdr
;
2246 if (! is_x86_64_elf (ibfd
))
2249 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2251 struct elf_dyn_relocs
*p
;
2253 for (p
= (struct elf_dyn_relocs
*)
2254 (elf_section_data (s
)->local_dynrel
);
2258 if (!bfd_is_abs_section (p
->sec
)
2259 && bfd_is_abs_section (p
->sec
->output_section
))
2261 /* Input section has been discarded, either because
2262 it is a copy of a linkonce section or due to
2263 linker script /DISCARD/, so we'll be discarding
2266 else if (p
->count
!= 0)
2268 srel
= elf_section_data (p
->sec
)->sreloc
;
2269 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
2270 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2271 info
->flags
|= DF_TEXTREL
;
2276 local_got
= elf_local_got_refcounts (ibfd
);
2280 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2281 locsymcount
= symtab_hdr
->sh_info
;
2282 end_local_got
= local_got
+ locsymcount
;
2283 local_tls_type
= elf64_x86_64_local_got_tls_type (ibfd
);
2284 local_tlsdesc_gotent
= elf64_x86_64_local_tlsdesc_gotent (ibfd
);
2286 srel
= htab
->elf
.srelgot
;
2287 for (; local_got
< end_local_got
;
2288 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2290 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2293 if (GOT_TLS_GDESC_P (*local_tls_type
))
2295 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2296 - elf64_x86_64_compute_jump_table_size (htab
);
2297 htab
->elf
.sgotplt
->size
+= 2 * GOT_ENTRY_SIZE
;
2298 *local_got
= (bfd_vma
) -2;
2300 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2301 || GOT_TLS_GD_P (*local_tls_type
))
2303 *local_got
= s
->size
;
2304 s
->size
+= GOT_ENTRY_SIZE
;
2305 if (GOT_TLS_GD_P (*local_tls_type
))
2306 s
->size
+= GOT_ENTRY_SIZE
;
2309 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2310 || *local_tls_type
== GOT_TLS_IE
)
2312 if (GOT_TLS_GDESC_P (*local_tls_type
))
2314 htab
->elf
.srelplt
->size
2315 += sizeof (Elf64_External_Rela
);
2316 htab
->tlsdesc_plt
= (bfd_vma
) -1;
2318 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2319 || GOT_TLS_GD_P (*local_tls_type
))
2320 srel
->size
+= sizeof (Elf64_External_Rela
);
2324 *local_got
= (bfd_vma
) -1;
2328 if (htab
->tls_ld_got
.refcount
> 0)
2330 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
2332 htab
->tls_ld_got
.offset
= htab
->elf
.sgot
->size
;
2333 htab
->elf
.sgot
->size
+= 2 * GOT_ENTRY_SIZE
;
2334 htab
->elf
.srelgot
->size
+= sizeof (Elf64_External_Rela
);
2337 htab
->tls_ld_got
.offset
= -1;
2339 /* Allocate global sym .plt and .got entries, and space for global
2340 sym dynamic relocs. */
2341 elf_link_hash_traverse (&htab
->elf
, elf64_x86_64_allocate_dynrelocs
,
2344 /* Allocate .plt and .got entries, and space for local symbols. */
2345 htab_traverse (htab
->loc_hash_table
,
2346 elf64_x86_64_allocate_local_dynrelocs
,
2349 /* For every jump slot reserved in the sgotplt, reloc_count is
2350 incremented. However, when we reserve space for TLS descriptors,
2351 it's not incremented, so in order to compute the space reserved
2352 for them, it suffices to multiply the reloc count by the jump
2354 if (htab
->elf
.srelplt
)
2355 htab
->sgotplt_jump_table_size
2356 = elf64_x86_64_compute_jump_table_size (htab
);
2358 if (htab
->tlsdesc_plt
)
2360 /* If we're not using lazy TLS relocations, don't generate the
2361 PLT and GOT entries they require. */
2362 if ((info
->flags
& DF_BIND_NOW
))
2363 htab
->tlsdesc_plt
= 0;
2366 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
2367 htab
->elf
.sgot
->size
+= GOT_ENTRY_SIZE
;
2368 /* Reserve room for the initial entry.
2369 FIXME: we could probably do away with it in this case. */
2370 if (htab
->elf
.splt
->size
== 0)
2371 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2372 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
2373 htab
->elf
.splt
->size
+= PLT_ENTRY_SIZE
;
2377 /* We now have determined the sizes of the various dynamic sections.
2378 Allocate memory for them. */
2380 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2382 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2385 if (s
== htab
->elf
.splt
2386 || s
== htab
->elf
.sgot
2387 || s
== htab
->elf
.sgotplt
2388 || s
== htab
->elf
.iplt
2389 || s
== htab
->elf
.igotplt
2390 || s
== htab
->sdynbss
)
2392 /* Strip this section if we don't need it; see the
2395 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
2397 if (s
->size
!= 0 && s
!= htab
->elf
.srelplt
)
2400 /* We use the reloc_count field as a counter if we need
2401 to copy relocs into the output file. */
2402 if (s
!= htab
->elf
.srelplt
)
2407 /* It's not one of our sections, so don't allocate space. */
2413 /* If we don't need this section, strip it from the
2414 output file. This is mostly to handle .rela.bss and
2415 .rela.plt. We must create both sections in
2416 create_dynamic_sections, because they must be created
2417 before the linker maps input sections to output
2418 sections. The linker does that before
2419 adjust_dynamic_symbol is called, and it is that
2420 function which decides whether anything needs to go
2421 into these sections. */
2423 s
->flags
|= SEC_EXCLUDE
;
2427 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2430 /* Allocate memory for the section contents. We use bfd_zalloc
2431 here in case unused entries are not reclaimed before the
2432 section's contents are written out. This should not happen,
2433 but this way if it does, we get a R_X86_64_NONE reloc instead
2435 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2436 if (s
->contents
== NULL
)
2440 if (htab
->elf
.dynamic_sections_created
)
2442 /* Add some entries to the .dynamic section. We fill in the
2443 values later, in elf64_x86_64_finish_dynamic_sections, but we
2444 must add the entries now so that we get the correct size for
2445 the .dynamic section. The DT_DEBUG entry is filled in by the
2446 dynamic linker and used by the debugger. */
2447 #define add_dynamic_entry(TAG, VAL) \
2448 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2450 if (info
->executable
)
2452 if (!add_dynamic_entry (DT_DEBUG
, 0))
2456 if (htab
->elf
.splt
->size
!= 0)
2458 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2459 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2460 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2461 || !add_dynamic_entry (DT_JMPREL
, 0))
2464 if (htab
->tlsdesc_plt
2465 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
2466 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
2472 if (!add_dynamic_entry (DT_RELA
, 0)
2473 || !add_dynamic_entry (DT_RELASZ
, 0)
2474 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2477 /* If any dynamic relocs apply to a read-only section,
2478 then we need a DT_TEXTREL entry. */
2479 if ((info
->flags
& DF_TEXTREL
) == 0)
2480 elf_link_hash_traverse (&htab
->elf
,
2481 elf64_x86_64_readonly_dynrelocs
,
2484 if ((info
->flags
& DF_TEXTREL
) != 0)
2486 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2491 #undef add_dynamic_entry
2497 elf64_x86_64_always_size_sections (bfd
*output_bfd
,
2498 struct bfd_link_info
*info
)
2500 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2504 struct elf_link_hash_entry
*tlsbase
;
2506 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2507 "_TLS_MODULE_BASE_",
2508 FALSE
, FALSE
, FALSE
);
2510 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2512 struct elf64_x86_64_link_hash_table
*htab
;
2513 struct bfd_link_hash_entry
*bh
= NULL
;
2514 const struct elf_backend_data
*bed
2515 = get_elf_backend_data (output_bfd
);
2517 htab
= elf64_x86_64_hash_table (info
);
2521 if (!(_bfd_generic_link_add_one_symbol
2522 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2523 tls_sec
, 0, NULL
, FALSE
,
2524 bed
->collect
, &bh
)))
2527 htab
->tls_module_base
= bh
;
2529 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2530 tlsbase
->def_regular
= 1;
2531 tlsbase
->other
= STV_HIDDEN
;
2532 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
2539 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
2540 executables. Rather than setting it to the beginning of the TLS
2541 section, we have to set it to the end. This function may be called
2542 multiple times, it is idempotent. */
2545 elf64_x86_64_set_tls_module_base (struct bfd_link_info
*info
)
2547 struct elf64_x86_64_link_hash_table
*htab
;
2548 struct bfd_link_hash_entry
*base
;
2550 if (!info
->executable
)
2553 htab
= elf64_x86_64_hash_table (info
);
2557 base
= htab
->tls_module_base
;
2561 base
->u
.def
.value
= htab
->elf
.tls_size
;
2564 /* Return the base VMA address which should be subtracted from real addresses
2565 when resolving @dtpoff relocation.
2566 This is PT_TLS segment p_vaddr. */
2569 elf64_x86_64_dtpoff_base (struct bfd_link_info
*info
)
2571 /* If tls_sec is NULL, we should have signalled an error already. */
2572 if (elf_hash_table (info
)->tls_sec
== NULL
)
2574 return elf_hash_table (info
)->tls_sec
->vma
;
2577 /* Return the relocation value for @tpoff relocation
2578 if STT_TLS virtual address is ADDRESS. */
2581 elf64_x86_64_tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2583 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2585 /* If tls_segment is NULL, we should have signalled an error already. */
2586 if (htab
->tls_sec
== NULL
)
2588 return address
- htab
->tls_size
- htab
->tls_sec
->vma
;
2591 /* Is the instruction before OFFSET in CONTENTS a 32bit relative
2595 is_32bit_relative_branch (bfd_byte
*contents
, bfd_vma offset
)
2597 /* Opcode Instruction
2600 0x0f 0x8x conditional jump */
2602 && (contents
[offset
- 1] == 0xe8
2603 || contents
[offset
- 1] == 0xe9))
2605 && contents
[offset
- 2] == 0x0f
2606 && (contents
[offset
- 1] & 0xf0) == 0x80));
2610 elf64_x86_64_append_rela (bfd
*abfd
, asection
*s
, Elf_Internal_Rela
*rel
)
2612 bfd_byte
*loc
= s
->contents
;
2613 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2614 BFD_ASSERT (loc
+ sizeof (Elf64_External_Rela
)
2615 <= s
->contents
+ s
->size
);
2616 bfd_elf64_swap_reloca_out (abfd
, rel
, loc
);
2619 /* Relocate an x86_64 ELF section. */
2622 elf64_x86_64_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
2623 bfd
*input_bfd
, asection
*input_section
,
2624 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
2625 Elf_Internal_Sym
*local_syms
,
2626 asection
**local_sections
)
2628 struct elf64_x86_64_link_hash_table
*htab
;
2629 Elf_Internal_Shdr
*symtab_hdr
;
2630 struct elf_link_hash_entry
**sym_hashes
;
2631 bfd_vma
*local_got_offsets
;
2632 bfd_vma
*local_tlsdesc_gotents
;
2633 Elf_Internal_Rela
*rel
;
2634 Elf_Internal_Rela
*relend
;
2636 BFD_ASSERT (is_x86_64_elf (input_bfd
));
2638 htab
= elf64_x86_64_hash_table (info
);
2641 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
2642 sym_hashes
= elf_sym_hashes (input_bfd
);
2643 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2644 local_tlsdesc_gotents
= elf64_x86_64_local_tlsdesc_gotent (input_bfd
);
2646 elf64_x86_64_set_tls_module_base (info
);
2649 relend
= relocs
+ input_section
->reloc_count
;
2650 for (; rel
< relend
; rel
++)
2652 unsigned int r_type
;
2653 reloc_howto_type
*howto
;
2654 unsigned long r_symndx
;
2655 struct elf_link_hash_entry
*h
;
2656 Elf_Internal_Sym
*sym
;
2658 bfd_vma off
, offplt
;
2660 bfd_boolean unresolved_reloc
;
2661 bfd_reloc_status_type r
;
2665 r_type
= ELF64_R_TYPE (rel
->r_info
);
2666 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
2667 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
2670 if (r_type
>= R_X86_64_max
)
2672 bfd_set_error (bfd_error_bad_value
);
2676 howto
= x86_64_elf_howto_table
+ r_type
;
2677 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2681 unresolved_reloc
= FALSE
;
2682 if (r_symndx
< symtab_hdr
->sh_info
)
2684 sym
= local_syms
+ r_symndx
;
2685 sec
= local_sections
[r_symndx
];
2687 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
,
2690 /* Relocate against local STT_GNU_IFUNC symbol. */
2691 if (!info
->relocatable
2692 && ELF64_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
2694 h
= elf64_x86_64_get_local_sym_hash (htab
, input_bfd
,
2699 /* Set STT_GNU_IFUNC symbol value. */
2700 h
->root
.u
.def
.value
= sym
->st_value
;
2701 h
->root
.u
.def
.section
= sec
;
2706 bfd_boolean warned ATTRIBUTE_UNUSED
;
2708 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2709 r_symndx
, symtab_hdr
, sym_hashes
,
2711 unresolved_reloc
, warned
);
2714 if (sec
!= NULL
&& elf_discarded_section (sec
))
2715 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
2716 rel
, relend
, howto
, contents
);
2718 if (info
->relocatable
)
2721 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
2722 it here if it is defined in a non-shared object. */
2724 && h
->type
== STT_GNU_IFUNC
2731 if ((input_section
->flags
& SEC_ALLOC
) == 0
2732 || h
->plt
.offset
== (bfd_vma
) -1)
2735 /* STT_GNU_IFUNC symbol must go through PLT. */
2736 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
2737 relocation
= (plt
->output_section
->vma
2738 + plt
->output_offset
+ h
->plt
.offset
);
2743 if (h
->root
.root
.string
)
2744 name
= h
->root
.root
.string
;
2746 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
2748 (*_bfd_error_handler
)
2749 (_("%B: relocation %s against STT_GNU_IFUNC "
2750 "symbol `%s' isn't handled by %s"), input_bfd
,
2751 x86_64_elf_howto_table
[r_type
].name
,
2752 name
, __FUNCTION__
);
2753 bfd_set_error (bfd_error_bad_value
);
2762 if (rel
->r_addend
!= 0)
2764 if (h
->root
.root
.string
)
2765 name
= h
->root
.root
.string
;
2767 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
2769 (*_bfd_error_handler
)
2770 (_("%B: relocation %s against STT_GNU_IFUNC "
2771 "symbol `%s' has non-zero addend: %d"),
2772 input_bfd
, x86_64_elf_howto_table
[r_type
].name
,
2773 name
, rel
->r_addend
);
2774 bfd_set_error (bfd_error_bad_value
);
2778 /* Generate dynamic relcoation only when there is a
2779 non-GOF reference in a shared object. */
2780 if (info
->shared
&& h
->non_got_ref
)
2782 Elf_Internal_Rela outrel
;
2785 /* Need a dynamic relocation to get the real function
2787 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
2791 if (outrel
.r_offset
== (bfd_vma
) -1
2792 || outrel
.r_offset
== (bfd_vma
) -2)
2795 outrel
.r_offset
+= (input_section
->output_section
->vma
2796 + input_section
->output_offset
);
2798 if (h
->dynindx
== -1
2800 || info
->executable
)
2802 /* This symbol is resolved locally. */
2803 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_IRELATIVE
);
2804 outrel
.r_addend
= (h
->root
.u
.def
.value
2805 + h
->root
.u
.def
.section
->output_section
->vma
2806 + h
->root
.u
.def
.section
->output_offset
);
2810 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2811 outrel
.r_addend
= 0;
2814 sreloc
= htab
->elf
.irelifunc
;
2815 elf64_x86_64_append_rela (output_bfd
, sreloc
, &outrel
);
2817 /* If this reloc is against an external symbol, we
2818 do not want to fiddle with the addend. Otherwise,
2819 we need to include the symbol value so that it
2820 becomes an addend for the dynamic reloc. For an
2821 internal symbol, we have updated addend. */
2828 case R_X86_64_PLT32
:
2831 case R_X86_64_GOTPCREL
:
2832 case R_X86_64_GOTPCREL64
:
2833 base_got
= htab
->elf
.sgot
;
2834 off
= h
->got
.offset
;
2836 if (base_got
== NULL
)
2839 if (off
== (bfd_vma
) -1)
2841 /* We can't use h->got.offset here to save state, or
2842 even just remember the offset, as finish_dynamic_symbol
2843 would use that as offset into .got. */
2845 if (htab
->elf
.splt
!= NULL
)
2847 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2848 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2849 base_got
= htab
->elf
.sgotplt
;
2853 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
2854 off
= plt_index
* GOT_ENTRY_SIZE
;
2855 base_got
= htab
->elf
.igotplt
;
2858 if (h
->dynindx
== -1
2862 /* This references the local defitionion. We must
2863 initialize this entry in the global offset table.
2864 Since the offset must always be a multiple of 8,
2865 we use the least significant bit to record
2866 whether we have initialized it already.
2868 When doing a dynamic link, we create a .rela.got
2869 relocation entry to initialize the value. This
2870 is done in the finish_dynamic_symbol routine. */
2875 bfd_put_64 (output_bfd
, relocation
,
2876 base_got
->contents
+ off
);
2877 /* Note that this is harmless for the GOTPLT64
2878 case, as -1 | 1 still is -1. */
2884 relocation
= (base_got
->output_section
->vma
2885 + base_got
->output_offset
+ off
);
2887 if (r_type
!= R_X86_64_GOTPCREL
2888 && r_type
!= R_X86_64_GOTPCREL64
)
2891 if (htab
->elf
.splt
!= NULL
)
2892 gotplt
= htab
->elf
.sgotplt
;
2894 gotplt
= htab
->elf
.igotplt
;
2895 relocation
-= (gotplt
->output_section
->vma
2896 - gotplt
->output_offset
);
2903 /* When generating a shared object, the relocations handled here are
2904 copied into the output file to be resolved at run time. */
2907 case R_X86_64_GOT32
:
2908 case R_X86_64_GOT64
:
2909 /* Relocation is to the entry for this symbol in the global
2911 case R_X86_64_GOTPCREL
:
2912 case R_X86_64_GOTPCREL64
:
2913 /* Use global offset table entry as symbol value. */
2914 case R_X86_64_GOTPLT64
:
2915 /* This is the same as GOT64 for relocation purposes, but
2916 indicates the existence of a PLT entry. The difficulty is,
2917 that we must calculate the GOT slot offset from the PLT
2918 offset, if this symbol got a PLT entry (it was global).
2919 Additionally if it's computed from the PLT entry, then that
2920 GOT offset is relative to .got.plt, not to .got. */
2921 base_got
= htab
->elf
.sgot
;
2923 if (htab
->elf
.sgot
== NULL
)
2930 off
= h
->got
.offset
;
2932 && h
->plt
.offset
!= (bfd_vma
)-1
2933 && off
== (bfd_vma
)-1)
2935 /* We can't use h->got.offset here to save
2936 state, or even just remember the offset, as
2937 finish_dynamic_symbol would use that as offset into
2939 bfd_vma plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2940 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2941 base_got
= htab
->elf
.sgotplt
;
2944 dyn
= htab
->elf
.dynamic_sections_created
;
2946 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2948 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2949 || (ELF_ST_VISIBILITY (h
->other
)
2950 && h
->root
.type
== bfd_link_hash_undefweak
))
2952 /* This is actually a static link, or it is a -Bsymbolic
2953 link and the symbol is defined locally, or the symbol
2954 was forced to be local because of a version file. We
2955 must initialize this entry in the global offset table.
2956 Since the offset must always be a multiple of 8, we
2957 use the least significant bit to record whether we
2958 have initialized it already.
2960 When doing a dynamic link, we create a .rela.got
2961 relocation entry to initialize the value. This is
2962 done in the finish_dynamic_symbol routine. */
2967 bfd_put_64 (output_bfd
, relocation
,
2968 base_got
->contents
+ off
);
2969 /* Note that this is harmless for the GOTPLT64 case,
2970 as -1 | 1 still is -1. */
2975 unresolved_reloc
= FALSE
;
2979 if (local_got_offsets
== NULL
)
2982 off
= local_got_offsets
[r_symndx
];
2984 /* The offset must always be a multiple of 8. We use
2985 the least significant bit to record whether we have
2986 already generated the necessary reloc. */
2991 bfd_put_64 (output_bfd
, relocation
,
2992 base_got
->contents
+ off
);
2997 Elf_Internal_Rela outrel
;
2999 /* We need to generate a R_X86_64_RELATIVE reloc
3000 for the dynamic linker. */
3001 s
= htab
->elf
.srelgot
;
3005 outrel
.r_offset
= (base_got
->output_section
->vma
3006 + base_got
->output_offset
3008 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3009 outrel
.r_addend
= relocation
;
3010 elf64_x86_64_append_rela (output_bfd
, s
, &outrel
);
3013 local_got_offsets
[r_symndx
] |= 1;
3017 if (off
>= (bfd_vma
) -2)
3020 relocation
= base_got
->output_section
->vma
3021 + base_got
->output_offset
+ off
;
3022 if (r_type
!= R_X86_64_GOTPCREL
&& r_type
!= R_X86_64_GOTPCREL64
)
3023 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3024 - htab
->elf
.sgotplt
->output_offset
;
3028 case R_X86_64_GOTOFF64
:
3029 /* Relocation is relative to the start of the global offset
3032 /* Check to make sure it isn't a protected function symbol
3033 for shared library since it may not be local when used
3034 as function address. */
3038 && h
->type
== STT_FUNC
3039 && ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
3041 (*_bfd_error_handler
)
3042 (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"),
3043 input_bfd
, h
->root
.root
.string
);
3044 bfd_set_error (bfd_error_bad_value
);
3048 /* Note that sgot is not involved in this
3049 calculation. We always want the start of .got.plt. If we
3050 defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
3051 permitted by the ABI, we might have to change this
3053 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3054 + htab
->elf
.sgotplt
->output_offset
;
3057 case R_X86_64_GOTPC32
:
3058 case R_X86_64_GOTPC64
:
3059 /* Use global offset table as symbol value. */
3060 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3061 + htab
->elf
.sgotplt
->output_offset
;
3062 unresolved_reloc
= FALSE
;
3065 case R_X86_64_PLTOFF64
:
3066 /* Relocation is PLT entry relative to GOT. For local
3067 symbols it's the symbol itself relative to GOT. */
3069 /* See PLT32 handling. */
3070 && h
->plt
.offset
!= (bfd_vma
) -1
3071 && htab
->elf
.splt
!= NULL
)
3073 relocation
= (htab
->elf
.splt
->output_section
->vma
3074 + htab
->elf
.splt
->output_offset
3076 unresolved_reloc
= FALSE
;
3079 relocation
-= htab
->elf
.sgotplt
->output_section
->vma
3080 + htab
->elf
.sgotplt
->output_offset
;
3083 case R_X86_64_PLT32
:
3084 /* Relocation is to the entry for this symbol in the
3085 procedure linkage table. */
3087 /* Resolve a PLT32 reloc against a local symbol directly,
3088 without using the procedure linkage table. */
3092 if (h
->plt
.offset
== (bfd_vma
) -1
3093 || htab
->elf
.splt
== NULL
)
3095 /* We didn't make a PLT entry for this symbol. This
3096 happens when statically linking PIC code, or when
3097 using -Bsymbolic. */
3101 relocation
= (htab
->elf
.splt
->output_section
->vma
3102 + htab
->elf
.splt
->output_offset
3104 unresolved_reloc
= FALSE
;
3111 && (input_section
->flags
& SEC_ALLOC
) != 0
3112 && (input_section
->flags
& SEC_READONLY
) != 0
3115 bfd_boolean fail
= FALSE
;
3117 = (r_type
== R_X86_64_PC32
3118 && is_32bit_relative_branch (contents
, rel
->r_offset
));
3120 if (SYMBOL_REFERENCES_LOCAL (info
, h
))
3122 /* Symbol is referenced locally. Make sure it is
3123 defined locally or for a branch. */
3124 fail
= !h
->def_regular
&& !branch
;
3128 /* Symbol isn't referenced locally. We only allow
3129 branch to symbol with non-default visibility. */
3131 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
);
3138 const char *pic
= "";
3140 switch (ELF_ST_VISIBILITY (h
->other
))
3143 v
= _("hidden symbol");
3146 v
= _("internal symbol");
3149 v
= _("protected symbol");
3153 pic
= _("; recompile with -fPIC");
3158 fmt
= _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
3160 fmt
= _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
3162 (*_bfd_error_handler
) (fmt
, input_bfd
,
3163 x86_64_elf_howto_table
[r_type
].name
,
3164 v
, h
->root
.root
.string
, pic
);
3165 bfd_set_error (bfd_error_bad_value
);
3176 /* FIXME: The ABI says the linker should make sure the value is
3177 the same when it's zeroextended to 64 bit. */
3179 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3184 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3185 || h
->root
.type
!= bfd_link_hash_undefweak
)
3186 && (! IS_X86_64_PCREL_TYPE (r_type
)
3187 || ! SYMBOL_CALLS_LOCAL (info
, h
)))
3188 || (ELIMINATE_COPY_RELOCS
3195 || h
->root
.type
== bfd_link_hash_undefweak
3196 || h
->root
.type
== bfd_link_hash_undefined
)))
3198 Elf_Internal_Rela outrel
;
3199 bfd_boolean skip
, relocate
;
3202 /* When generating a shared object, these relocations
3203 are copied into the output file to be resolved at run
3209 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3211 if (outrel
.r_offset
== (bfd_vma
) -1)
3213 else if (outrel
.r_offset
== (bfd_vma
) -2)
3214 skip
= TRUE
, relocate
= TRUE
;
3216 outrel
.r_offset
+= (input_section
->output_section
->vma
3217 + input_section
->output_offset
);
3220 memset (&outrel
, 0, sizeof outrel
);
3222 /* h->dynindx may be -1 if this symbol was marked to
3226 && (IS_X86_64_PCREL_TYPE (r_type
)
3228 || ! SYMBOLIC_BIND (info
, h
)
3229 || ! h
->def_regular
))
3231 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3232 outrel
.r_addend
= rel
->r_addend
;
3236 /* This symbol is local, or marked to become local. */
3237 if (r_type
== R_X86_64_64
)
3240 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3241 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3247 if (bfd_is_abs_section (sec
))
3249 else if (sec
== NULL
|| sec
->owner
== NULL
)
3251 bfd_set_error (bfd_error_bad_value
);
3258 /* We are turning this relocation into one
3259 against a section symbol. It would be
3260 proper to subtract the symbol's value,
3261 osec->vma, from the emitted reloc addend,
3262 but ld.so expects buggy relocs. */
3263 osec
= sec
->output_section
;
3264 sindx
= elf_section_data (osec
)->dynindx
;
3267 asection
*oi
= htab
->elf
.text_index_section
;
3268 sindx
= elf_section_data (oi
)->dynindx
;
3270 BFD_ASSERT (sindx
!= 0);
3273 outrel
.r_info
= ELF64_R_INFO (sindx
, r_type
);
3274 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3278 sreloc
= elf_section_data (input_section
)->sreloc
;
3280 BFD_ASSERT (sreloc
!= NULL
&& sreloc
->contents
!= NULL
);
3282 elf64_x86_64_append_rela (output_bfd
, sreloc
, &outrel
);
3284 /* If this reloc is against an external symbol, we do
3285 not want to fiddle with the addend. Otherwise, we
3286 need to include the symbol value so that it becomes
3287 an addend for the dynamic reloc. */
3294 case R_X86_64_TLSGD
:
3295 case R_X86_64_GOTPC32_TLSDESC
:
3296 case R_X86_64_TLSDESC_CALL
:
3297 case R_X86_64_GOTTPOFF
:
3298 tls_type
= GOT_UNKNOWN
;
3299 if (h
== NULL
&& local_got_offsets
)
3300 tls_type
= elf64_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
3302 tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
3304 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3305 input_section
, contents
,
3306 symtab_hdr
, sym_hashes
,
3307 &r_type
, tls_type
, rel
,
3308 relend
, h
, r_symndx
))
3311 if (r_type
== R_X86_64_TPOFF32
)
3313 bfd_vma roff
= rel
->r_offset
;
3315 BFD_ASSERT (! unresolved_reloc
);
3317 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3319 /* GD->LE transition.
3320 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3321 .word 0x6666; rex64; call __tls_get_addr
3324 leaq foo@tpoff(%rax), %rax */
3325 memcpy (contents
+ roff
- 4,
3326 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
3328 bfd_put_32 (output_bfd
,
3329 elf64_x86_64_tpoff (info
, relocation
),
3330 contents
+ roff
+ 8);
3331 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3335 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3337 /* GDesc -> LE transition.
3338 It's originally something like:
3339 leaq x@tlsdesc(%rip), %rax
3342 movl $x@tpoff, %rax. */
3344 unsigned int val
, type
;
3346 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3347 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3348 bfd_put_8 (output_bfd
, 0x48 | ((type
>> 2) & 1),
3349 contents
+ roff
- 3);
3350 bfd_put_8 (output_bfd
, 0xc7, contents
+ roff
- 2);
3351 bfd_put_8 (output_bfd
, 0xc0 | ((val
>> 3) & 7),
3352 contents
+ roff
- 1);
3353 bfd_put_32 (output_bfd
,
3354 elf64_x86_64_tpoff (info
, relocation
),
3358 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3360 /* GDesc -> LE transition.
3365 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3366 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3369 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTTPOFF
)
3371 /* IE->LE transition:
3372 Originally it can be one of:
3373 movq foo@gottpoff(%rip), %reg
3374 addq foo@gottpoff(%rip), %reg
3377 leaq foo(%reg), %reg
3380 unsigned int val
, type
, reg
;
3382 val
= bfd_get_8 (input_bfd
, contents
+ roff
- 3);
3383 type
= bfd_get_8 (input_bfd
, contents
+ roff
- 2);
3384 reg
= bfd_get_8 (input_bfd
, contents
+ roff
- 1);
3390 bfd_put_8 (output_bfd
, 0x49,
3391 contents
+ roff
- 3);
3392 bfd_put_8 (output_bfd
, 0xc7,
3393 contents
+ roff
- 2);
3394 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3395 contents
+ roff
- 1);
3399 /* addq -> addq - addressing with %rsp/%r12 is
3402 bfd_put_8 (output_bfd
, 0x49,
3403 contents
+ roff
- 3);
3404 bfd_put_8 (output_bfd
, 0x81,
3405 contents
+ roff
- 2);
3406 bfd_put_8 (output_bfd
, 0xc0 | reg
,
3407 contents
+ roff
- 1);
3413 bfd_put_8 (output_bfd
, 0x4d,
3414 contents
+ roff
- 3);
3415 bfd_put_8 (output_bfd
, 0x8d,
3416 contents
+ roff
- 2);
3417 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
3418 contents
+ roff
- 1);
3420 bfd_put_32 (output_bfd
,
3421 elf64_x86_64_tpoff (info
, relocation
),
3429 if (htab
->elf
.sgot
== NULL
)
3434 off
= h
->got
.offset
;
3435 offplt
= elf64_x86_64_hash_entry (h
)->tlsdesc_got
;
3439 if (local_got_offsets
== NULL
)
3442 off
= local_got_offsets
[r_symndx
];
3443 offplt
= local_tlsdesc_gotents
[r_symndx
];
3450 Elf_Internal_Rela outrel
;
3454 if (htab
->elf
.srelgot
== NULL
)
3457 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
3459 if (GOT_TLS_GDESC_P (tls_type
))
3461 outrel
.r_info
= ELF64_R_INFO (indx
, R_X86_64_TLSDESC
);
3462 BFD_ASSERT (htab
->sgotplt_jump_table_size
+ offplt
3463 + 2 * GOT_ENTRY_SIZE
<= htab
->elf
.sgotplt
->size
);
3464 outrel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
3465 + htab
->elf
.sgotplt
->output_offset
3467 + htab
->sgotplt_jump_table_size
);
3468 sreloc
= htab
->elf
.srelplt
;
3470 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3472 outrel
.r_addend
= 0;
3473 elf64_x86_64_append_rela (output_bfd
, sreloc
, &outrel
);
3476 sreloc
= htab
->elf
.srelgot
;
3478 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3479 + htab
->elf
.sgot
->output_offset
+ off
);
3481 if (GOT_TLS_GD_P (tls_type
))
3482 dr_type
= R_X86_64_DTPMOD64
;
3483 else if (GOT_TLS_GDESC_P (tls_type
))
3486 dr_type
= R_X86_64_TPOFF64
;
3488 bfd_put_64 (output_bfd
, 0, htab
->elf
.sgot
->contents
+ off
);
3489 outrel
.r_addend
= 0;
3490 if ((dr_type
== R_X86_64_TPOFF64
3491 || dr_type
== R_X86_64_TLSDESC
) && indx
== 0)
3492 outrel
.r_addend
= relocation
- elf64_x86_64_dtpoff_base (info
);
3493 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
3495 elf64_x86_64_append_rela (output_bfd
, sreloc
, &outrel
);
3497 if (GOT_TLS_GD_P (tls_type
))
3501 BFD_ASSERT (! unresolved_reloc
);
3502 bfd_put_64 (output_bfd
,
3503 relocation
- elf64_x86_64_dtpoff_base (info
),
3504 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3508 bfd_put_64 (output_bfd
, 0,
3509 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3510 outrel
.r_info
= ELF64_R_INFO (indx
,
3512 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
3513 elf64_x86_64_append_rela (output_bfd
, sreloc
,
3522 local_got_offsets
[r_symndx
] |= 1;
3525 if (off
>= (bfd_vma
) -2
3526 && ! GOT_TLS_GDESC_P (tls_type
))
3528 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
3530 if (r_type
== R_X86_64_GOTPC32_TLSDESC
3531 || r_type
== R_X86_64_TLSDESC_CALL
)
3532 relocation
= htab
->elf
.sgotplt
->output_section
->vma
3533 + htab
->elf
.sgotplt
->output_offset
3534 + offplt
+ htab
->sgotplt_jump_table_size
;
3536 relocation
= htab
->elf
.sgot
->output_section
->vma
3537 + htab
->elf
.sgot
->output_offset
+ off
;
3538 unresolved_reloc
= FALSE
;
3542 bfd_vma roff
= rel
->r_offset
;
3544 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
3546 /* GD->IE transition.
3547 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
3548 .word 0x6666; rex64; call __tls_get_addr@plt
3551 addq foo@gottpoff(%rip), %rax */
3552 memcpy (contents
+ roff
- 4,
3553 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
3556 relocation
= (htab
->elf
.sgot
->output_section
->vma
3557 + htab
->elf
.sgot
->output_offset
+ off
3559 - input_section
->output_section
->vma
3560 - input_section
->output_offset
3562 bfd_put_32 (output_bfd
, relocation
,
3563 contents
+ roff
+ 8);
3564 /* Skip R_X86_64_PLT32. */
3568 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_GOTPC32_TLSDESC
)
3570 /* GDesc -> IE transition.
3571 It's originally something like:
3572 leaq x@tlsdesc(%rip), %rax
3575 movq x@gottpoff(%rip), %rax # before xchg %ax,%ax. */
3577 /* Now modify the instruction as appropriate. To
3578 turn a leaq into a movq in the form we use it, it
3579 suffices to change the second byte from 0x8d to
3581 bfd_put_8 (output_bfd
, 0x8b, contents
+ roff
- 2);
3583 bfd_put_32 (output_bfd
,
3584 htab
->elf
.sgot
->output_section
->vma
3585 + htab
->elf
.sgot
->output_offset
+ off
3587 - input_section
->output_section
->vma
3588 - input_section
->output_offset
3593 else if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSDESC_CALL
)
3595 /* GDesc -> IE transition.
3602 bfd_put_8 (output_bfd
, 0x66, contents
+ roff
);
3603 bfd_put_8 (output_bfd
, 0x90, contents
+ roff
+ 1);
3611 case R_X86_64_TLSLD
:
3612 if (! elf64_x86_64_tls_transition (info
, input_bfd
,
3613 input_section
, contents
,
3614 symtab_hdr
, sym_hashes
,
3615 &r_type
, GOT_UNKNOWN
,
3616 rel
, relend
, h
, r_symndx
))
3619 if (r_type
!= R_X86_64_TLSLD
)
3621 /* LD->LE transition:
3622 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr.
3624 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
3626 BFD_ASSERT (r_type
== R_X86_64_TPOFF32
);
3627 memcpy (contents
+ rel
->r_offset
- 3,
3628 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
3629 /* Skip R_X86_64_PC32/R_X86_64_PLT32. */
3634 if (htab
->elf
.sgot
== NULL
)
3637 off
= htab
->tls_ld_got
.offset
;
3642 Elf_Internal_Rela outrel
;
3644 if (htab
->elf
.srelgot
== NULL
)
3647 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3648 + htab
->elf
.sgot
->output_offset
+ off
);
3650 bfd_put_64 (output_bfd
, 0,
3651 htab
->elf
.sgot
->contents
+ off
);
3652 bfd_put_64 (output_bfd
, 0,
3653 htab
->elf
.sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
3654 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_DTPMOD64
);
3655 outrel
.r_addend
= 0;
3656 elf64_x86_64_append_rela (output_bfd
, htab
->elf
.srelgot
,
3658 htab
->tls_ld_got
.offset
|= 1;
3660 relocation
= htab
->elf
.sgot
->output_section
->vma
3661 + htab
->elf
.sgot
->output_offset
+ off
;
3662 unresolved_reloc
= FALSE
;
3665 case R_X86_64_DTPOFF32
:
3666 if (!info
->executable
|| (input_section
->flags
& SEC_CODE
) == 0)
3667 relocation
-= elf64_x86_64_dtpoff_base (info
);
3669 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3672 case R_X86_64_TPOFF32
:
3673 BFD_ASSERT (info
->executable
);
3674 relocation
= elf64_x86_64_tpoff (info
, relocation
);
3681 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3682 because such sections are not SEC_ALLOC and thus ld.so will
3683 not process them. */
3684 if (unresolved_reloc
3685 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
3687 (*_bfd_error_handler
)
3688 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3691 (long) rel
->r_offset
,
3693 h
->root
.root
.string
);
3696 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3697 contents
, rel
->r_offset
,
3698 relocation
, rel
->r_addend
);
3700 if (r
!= bfd_reloc_ok
)
3705 name
= h
->root
.root
.string
;
3708 name
= bfd_elf_string_from_elf_section (input_bfd
,
3709 symtab_hdr
->sh_link
,
3714 name
= bfd_section_name (input_bfd
, sec
);
3717 if (r
== bfd_reloc_overflow
)
3719 if (! ((*info
->callbacks
->reloc_overflow
)
3720 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3721 (bfd_vma
) 0, input_bfd
, input_section
,
3727 (*_bfd_error_handler
)
3728 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3729 input_bfd
, input_section
,
3730 (long) rel
->r_offset
, name
, (int) r
);
3739 /* Finish up dynamic symbol handling. We set the contents of various
3740 dynamic sections here. */
3743 elf64_x86_64_finish_dynamic_symbol (bfd
*output_bfd
,
3744 struct bfd_link_info
*info
,
3745 struct elf_link_hash_entry
*h
,
3746 Elf_Internal_Sym
*sym
)
3748 struct elf64_x86_64_link_hash_table
*htab
;
3750 htab
= elf64_x86_64_hash_table (info
);
3754 if (h
->plt
.offset
!= (bfd_vma
) -1)
3758 Elf_Internal_Rela rela
;
3760 asection
*plt
, *gotplt
, *relplt
;
3762 /* When building a static executable, use .iplt, .igot.plt and
3763 .rela.iplt sections for STT_GNU_IFUNC symbols. */
3764 if (htab
->elf
.splt
!= NULL
)
3766 plt
= htab
->elf
.splt
;
3767 gotplt
= htab
->elf
.sgotplt
;
3768 relplt
= htab
->elf
.srelplt
;
3772 plt
= htab
->elf
.iplt
;
3773 gotplt
= htab
->elf
.igotplt
;
3774 relplt
= htab
->elf
.irelplt
;
3777 /* This symbol has an entry in the procedure linkage table. Set
3779 if ((h
->dynindx
== -1
3780 && !((h
->forced_local
|| info
->executable
)
3782 && h
->type
== STT_GNU_IFUNC
))
3788 /* Get the index in the procedure linkage table which
3789 corresponds to this symbol. This is the index of this symbol
3790 in all the symbols for which we are making plt entries. The
3791 first entry in the procedure linkage table is reserved.
3793 Get the offset into the .got table of the entry that
3794 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
3795 bytes. The first three are reserved for the dynamic linker.
3797 For static executables, we don't reserve anything. */
3799 if (plt
== htab
->elf
.splt
)
3801 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3802 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
3806 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
;
3807 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
3810 /* Fill in the entry in the procedure linkage table. */
3811 memcpy (plt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
3814 /* Insert the relocation positions of the plt section. The magic
3815 numbers at the end of the statements are the positions of the
3816 relocations in the plt section. */
3817 /* Put offset for jmp *name@GOTPCREL(%rip), since the
3818 instruction uses 6 bytes, subtract this value. */
3819 bfd_put_32 (output_bfd
,
3820 (gotplt
->output_section
->vma
3821 + gotplt
->output_offset
3823 - plt
->output_section
->vma
3824 - plt
->output_offset
3827 plt
->contents
+ h
->plt
.offset
+ 2);
3829 /* Don't fill PLT entry for static executables. */
3830 if (plt
== htab
->elf
.splt
)
3832 /* Put relocation index. */
3833 bfd_put_32 (output_bfd
, plt_index
,
3834 plt
->contents
+ h
->plt
.offset
+ 7);
3835 /* Put offset for jmp .PLT0. */
3836 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
3837 plt
->contents
+ h
->plt
.offset
+ 12);
3840 /* Fill in the entry in the global offset table, initially this
3841 points to the pushq instruction in the PLT which is at offset 6. */
3842 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
3843 + plt
->output_offset
3844 + h
->plt
.offset
+ 6),
3845 gotplt
->contents
+ got_offset
);
3847 /* Fill in the entry in the .rela.plt section. */
3848 rela
.r_offset
= (gotplt
->output_section
->vma
3849 + gotplt
->output_offset
3851 if (h
->dynindx
== -1
3852 || ((info
->executable
3853 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
3855 && h
->type
== STT_GNU_IFUNC
))
3857 /* If an STT_GNU_IFUNC symbol is locally defined, generate
3858 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */
3859 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_IRELATIVE
);
3860 rela
.r_addend
= (h
->root
.u
.def
.value
3861 + h
->root
.u
.def
.section
->output_section
->vma
3862 + h
->root
.u
.def
.section
->output_offset
);
3866 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
3869 loc
= relplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3870 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3872 if (!h
->def_regular
)
3874 /* Mark the symbol as undefined, rather than as defined in
3875 the .plt section. Leave the value if there were any
3876 relocations where pointer equality matters (this is a clue
3877 for the dynamic linker, to make function pointer
3878 comparisons work between an application and shared
3879 library), otherwise set it to zero. If a function is only
3880 called from a binary, there is no need to slow down
3881 shared libraries because of that. */
3882 sym
->st_shndx
= SHN_UNDEF
;
3883 if (!h
->pointer_equality_needed
)
3888 if (h
->got
.offset
!= (bfd_vma
) -1
3889 && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h
)->tls_type
)
3890 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
3892 Elf_Internal_Rela rela
;
3894 /* This symbol has an entry in the global offset table. Set it
3896 if (htab
->elf
.sgot
== NULL
|| htab
->elf
.srelgot
== NULL
)
3899 rela
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
3900 + htab
->elf
.sgot
->output_offset
3901 + (h
->got
.offset
&~ (bfd_vma
) 1));
3903 /* If this is a static link, or it is a -Bsymbolic link and the
3904 symbol is defined locally or was forced to be local because
3905 of a version file, we just want to emit a RELATIVE reloc.
3906 The entry in the global offset table will already have been
3907 initialized in the relocate_section function. */
3909 && h
->type
== STT_GNU_IFUNC
)
3913 /* Generate R_X86_64_GLOB_DAT. */
3920 if (!h
->pointer_equality_needed
)
3923 /* For non-shared object, we can't use .got.plt, which
3924 contains the real function addres if we need pointer
3925 equality. We load the GOT entry with the PLT entry. */
3926 plt
= htab
->elf
.splt
? htab
->elf
.splt
: htab
->elf
.iplt
;
3927 bfd_put_64 (output_bfd
, (plt
->output_section
->vma
3928 + plt
->output_offset
3930 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3934 else if (info
->shared
3935 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3937 if (!h
->def_regular
)
3939 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3940 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
3941 rela
.r_addend
= (h
->root
.u
.def
.value
3942 + h
->root
.u
.def
.section
->output_section
->vma
3943 + h
->root
.u
.def
.section
->output_offset
);
3947 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3949 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
3950 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
3951 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
3955 elf64_x86_64_append_rela (output_bfd
, htab
->elf
.srelgot
, &rela
);
3960 Elf_Internal_Rela rela
;
3962 /* This symbol needs a copy reloc. Set it up. */
3964 if (h
->dynindx
== -1
3965 || (h
->root
.type
!= bfd_link_hash_defined
3966 && h
->root
.type
!= bfd_link_hash_defweak
)
3967 || htab
->srelbss
== NULL
)
3970 rela
.r_offset
= (h
->root
.u
.def
.value
3971 + h
->root
.u
.def
.section
->output_section
->vma
3972 + h
->root
.u
.def
.section
->output_offset
);
3973 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
3975 elf64_x86_64_append_rela (output_bfd
, htab
->srelbss
, &rela
);
3978 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
3979 be NULL for local symbols. */
3981 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3982 || h
== htab
->elf
.hgot
))
3983 sym
->st_shndx
= SHN_ABS
;
3988 /* Finish up local dynamic symbol handling. We set the contents of
3989 various dynamic sections here. */
3992 elf64_x86_64_finish_local_dynamic_symbol (void **slot
, void *inf
)
3994 struct elf_link_hash_entry
*h
3995 = (struct elf_link_hash_entry
*) *slot
;
3996 struct bfd_link_info
*info
3997 = (struct bfd_link_info
*) inf
;
3999 return elf64_x86_64_finish_dynamic_symbol (info
->output_bfd
,
4003 /* Used to decide how to sort relocs in an optimal manner for the
4004 dynamic linker, before writing them out. */
4006 static enum elf_reloc_type_class
4007 elf64_x86_64_reloc_type_class (const Elf_Internal_Rela
*rela
)
4009 switch ((int) ELF64_R_TYPE (rela
->r_info
))
4011 case R_X86_64_RELATIVE
:
4012 return reloc_class_relative
;
4013 case R_X86_64_JUMP_SLOT
:
4014 return reloc_class_plt
;
4016 return reloc_class_copy
;
4018 return reloc_class_normal
;
4022 /* Finish up the dynamic sections. */
4025 elf64_x86_64_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
4027 struct elf64_x86_64_link_hash_table
*htab
;
4031 htab
= elf64_x86_64_hash_table (info
);
4035 dynobj
= htab
->elf
.dynobj
;
4036 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4038 if (htab
->elf
.dynamic_sections_created
)
4040 Elf64_External_Dyn
*dyncon
, *dynconend
;
4042 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
4045 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4046 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4047 for (; dyncon
< dynconend
; dyncon
++)
4049 Elf_Internal_Dyn dyn
;
4052 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4060 s
= htab
->elf
.sgotplt
;
4061 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4065 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
4069 s
= htab
->elf
.srelplt
->output_section
;
4070 dyn
.d_un
.d_val
= s
->size
;
4074 /* The procedure linkage table relocs (DT_JMPREL) should
4075 not be included in the overall relocs (DT_RELA).
4076 Therefore, we override the DT_RELASZ entry here to
4077 make it not include the JMPREL relocs. Since the
4078 linker script arranges for .rela.plt to follow all
4079 other relocation sections, we don't have to worry
4080 about changing the DT_RELA entry. */
4081 if (htab
->elf
.srelplt
!= NULL
)
4083 s
= htab
->elf
.srelplt
->output_section
;
4084 dyn
.d_un
.d_val
-= s
->size
;
4088 case DT_TLSDESC_PLT
:
4090 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4091 + htab
->tlsdesc_plt
;
4094 case DT_TLSDESC_GOT
:
4096 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
4097 + htab
->tlsdesc_got
;
4101 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4104 /* Fill in the special first entry in the procedure linkage table. */
4105 if (htab
->elf
.splt
&& htab
->elf
.splt
->size
> 0)
4107 /* Fill in the first entry in the procedure linkage table. */
4108 memcpy (htab
->elf
.splt
->contents
, elf64_x86_64_plt0_entry
,
4110 /* Add offset for pushq GOT+8(%rip), since the instruction
4111 uses 6 bytes subtract this value. */
4112 bfd_put_32 (output_bfd
,
4113 (htab
->elf
.sgotplt
->output_section
->vma
4114 + htab
->elf
.sgotplt
->output_offset
4116 - htab
->elf
.splt
->output_section
->vma
4117 - htab
->elf
.splt
->output_offset
4119 htab
->elf
.splt
->contents
+ 2);
4120 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
4121 the end of the instruction. */
4122 bfd_put_32 (output_bfd
,
4123 (htab
->elf
.sgotplt
->output_section
->vma
4124 + htab
->elf
.sgotplt
->output_offset
4126 - htab
->elf
.splt
->output_section
->vma
4127 - htab
->elf
.splt
->output_offset
4129 htab
->elf
.splt
->contents
+ 8);
4131 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
=
4134 if (htab
->tlsdesc_plt
)
4136 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4137 htab
->elf
.sgot
->contents
+ htab
->tlsdesc_got
);
4139 memcpy (htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
,
4140 elf64_x86_64_plt0_entry
,
4143 /* Add offset for pushq GOT+8(%rip), since the
4144 instruction uses 6 bytes subtract this value. */
4145 bfd_put_32 (output_bfd
,
4146 (htab
->elf
.sgotplt
->output_section
->vma
4147 + htab
->elf
.sgotplt
->output_offset
4149 - htab
->elf
.splt
->output_section
->vma
4150 - htab
->elf
.splt
->output_offset
4153 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 2);
4154 /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for
4155 htab->tlsdesc_got. The 12 is the offset to the end of
4157 bfd_put_32 (output_bfd
,
4158 (htab
->elf
.sgot
->output_section
->vma
4159 + htab
->elf
.sgot
->output_offset
4161 - htab
->elf
.splt
->output_section
->vma
4162 - htab
->elf
.splt
->output_offset
4165 htab
->elf
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
4170 if (htab
->elf
.sgotplt
)
4172 /* Fill in the first three entries in the global offset table. */
4173 if (htab
->elf
.sgotplt
->size
> 0)
4175 /* Set the first entry in the global offset table to the address of
4176 the dynamic section. */
4178 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
);
4180 bfd_put_64 (output_bfd
,
4181 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4182 htab
->elf
.sgotplt
->contents
);
4183 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
4184 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
4185 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->elf
.sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
4188 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
=
4192 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
4193 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
4196 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4197 htab_traverse (htab
->loc_hash_table
,
4198 elf64_x86_64_finish_local_dynamic_symbol
,
4204 /* Return address for Ith PLT stub in section PLT, for relocation REL
4205 or (bfd_vma) -1 if it should not be included. */
4208 elf64_x86_64_plt_sym_val (bfd_vma i
, const asection
*plt
,
4209 const arelent
*rel ATTRIBUTE_UNUSED
)
4211 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
4214 /* Handle an x86-64 specific section when reading an object file. This
4215 is called when elfcode.h finds a section with an unknown type. */
4218 elf64_x86_64_section_from_shdr (bfd
*abfd
,
4219 Elf_Internal_Shdr
*hdr
,
4223 if (hdr
->sh_type
!= SHT_X86_64_UNWIND
)
4226 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4232 /* Hook called by the linker routine which adds symbols from an object
4233 file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead
4237 elf64_x86_64_add_symbol_hook (bfd
*abfd
,
4238 struct bfd_link_info
*info
,
4239 Elf_Internal_Sym
*sym
,
4240 const char **namep ATTRIBUTE_UNUSED
,
4241 flagword
*flagsp ATTRIBUTE_UNUSED
,
4247 switch (sym
->st_shndx
)
4249 case SHN_X86_64_LCOMMON
:
4250 lcomm
= bfd_get_section_by_name (abfd
, "LARGE_COMMON");
4253 lcomm
= bfd_make_section_with_flags (abfd
,
4257 | SEC_LINKER_CREATED
));
4260 elf_section_flags (lcomm
) |= SHF_X86_64_LARGE
;
4263 *valp
= sym
->st_size
;
4267 if ((abfd
->flags
& DYNAMIC
) == 0
4268 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
4269 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
4275 /* Given a BFD section, try to locate the corresponding ELF section
4279 elf64_x86_64_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
4280 asection
*sec
, int *index_return
)
4282 if (sec
== &_bfd_elf_large_com_section
)
4284 *index_return
= SHN_X86_64_LCOMMON
;
4290 /* Process a symbol. */
4293 elf64_x86_64_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4296 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
4298 switch (elfsym
->internal_elf_sym
.st_shndx
)
4300 case SHN_X86_64_LCOMMON
:
4301 asym
->section
= &_bfd_elf_large_com_section
;
4302 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
4303 /* Common symbol doesn't set BSF_GLOBAL. */
4304 asym
->flags
&= ~BSF_GLOBAL
;
4310 elf64_x86_64_common_definition (Elf_Internal_Sym
*sym
)
4312 return (sym
->st_shndx
== SHN_COMMON
4313 || sym
->st_shndx
== SHN_X86_64_LCOMMON
);
4317 elf64_x86_64_common_section_index (asection
*sec
)
4319 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4322 return SHN_X86_64_LCOMMON
;
4326 elf64_x86_64_common_section (asection
*sec
)
4328 if ((elf_section_flags (sec
) & SHF_X86_64_LARGE
) == 0)
4329 return bfd_com_section_ptr
;
4331 return &_bfd_elf_large_com_section
;
4335 elf64_x86_64_merge_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4336 struct elf_link_hash_entry
**sym_hash ATTRIBUTE_UNUSED
,
4337 struct elf_link_hash_entry
*h
,
4338 Elf_Internal_Sym
*sym
,
4340 bfd_vma
*pvalue ATTRIBUTE_UNUSED
,
4341 unsigned int *pold_alignment ATTRIBUTE_UNUSED
,
4342 bfd_boolean
*skip ATTRIBUTE_UNUSED
,
4343 bfd_boolean
*override ATTRIBUTE_UNUSED
,
4344 bfd_boolean
*type_change_ok ATTRIBUTE_UNUSED
,
4345 bfd_boolean
*size_change_ok ATTRIBUTE_UNUSED
,
4346 bfd_boolean
*newdef ATTRIBUTE_UNUSED
,
4347 bfd_boolean
*newdyn
,
4348 bfd_boolean
*newdyncommon ATTRIBUTE_UNUSED
,
4349 bfd_boolean
*newweak ATTRIBUTE_UNUSED
,
4350 bfd
*abfd ATTRIBUTE_UNUSED
,
4352 bfd_boolean
*olddef ATTRIBUTE_UNUSED
,
4353 bfd_boolean
*olddyn
,
4354 bfd_boolean
*olddyncommon ATTRIBUTE_UNUSED
,
4355 bfd_boolean
*oldweak ATTRIBUTE_UNUSED
,
4359 /* A normal common symbol and a large common symbol result in a
4360 normal common symbol. We turn the large common symbol into a
4363 && h
->root
.type
== bfd_link_hash_common
4365 && bfd_is_com_section (*sec
)
4368 if (sym
->st_shndx
== SHN_COMMON
4369 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) != 0)
4371 h
->root
.u
.c
.p
->section
4372 = bfd_make_section_old_way (oldbfd
, "COMMON");
4373 h
->root
.u
.c
.p
->section
->flags
= SEC_ALLOC
;
4375 else if (sym
->st_shndx
== SHN_X86_64_LCOMMON
4376 && (elf_section_flags (*oldsec
) & SHF_X86_64_LARGE
) == 0)
4377 *psec
= *sec
= bfd_com_section_ptr
;
4384 elf64_x86_64_additional_program_headers (bfd
*abfd
,
4385 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4390 /* Check to see if we need a large readonly segment. */
4391 s
= bfd_get_section_by_name (abfd
, ".lrodata");
4392 if (s
&& (s
->flags
& SEC_LOAD
))
4395 /* Check to see if we need a large data segment. Since .lbss sections
4396 is placed right after the .bss section, there should be no need for
4397 a large data segment just because of .lbss. */
4398 s
= bfd_get_section_by_name (abfd
, ".ldata");
4399 if (s
&& (s
->flags
& SEC_LOAD
))
4405 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
4408 elf64_x86_64_hash_symbol (struct elf_link_hash_entry
*h
)
4410 if (h
->plt
.offset
!= (bfd_vma
) -1
4412 && !h
->pointer_equality_needed
)
4415 return _bfd_elf_hash_symbol (h
);
4418 static const struct bfd_elf_special_section
4419 elf64_x86_64_special_sections
[]=
4421 { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4422 { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4423 { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
+ SHF_X86_64_LARGE
},
4424 { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4425 { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_X86_64_LARGE
},
4426 { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_X86_64_LARGE
},
4427 { NULL
, 0, 0, 0, 0 }
4430 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
4431 #define TARGET_LITTLE_NAME "elf64-x86-64"
4432 #define ELF_ARCH bfd_arch_i386
4433 #define ELF_MACHINE_CODE EM_X86_64
4434 #define ELF_MAXPAGESIZE 0x200000
4435 #define ELF_MINPAGESIZE 0x1000
4436 #define ELF_COMMONPAGESIZE 0x1000
4438 #define elf_backend_can_gc_sections 1
4439 #define elf_backend_can_refcount 1
4440 #define elf_backend_want_got_plt 1
4441 #define elf_backend_plt_readonly 1
4442 #define elf_backend_want_plt_sym 0
4443 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
4444 #define elf_backend_rela_normal 1
4446 #define elf_info_to_howto elf64_x86_64_info_to_howto
4448 #define bfd_elf64_bfd_link_hash_table_create \
4449 elf64_x86_64_link_hash_table_create
4450 #define bfd_elf64_bfd_link_hash_table_free \
4451 elf64_x86_64_link_hash_table_free
4452 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
4453 #define bfd_elf64_bfd_reloc_name_lookup \
4454 elf64_x86_64_reloc_name_lookup
4456 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
4457 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
4458 #define elf_backend_check_relocs elf64_x86_64_check_relocs
4459 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
4460 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
4461 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
4462 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
4463 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
4464 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
4465 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
4466 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
4467 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
4468 #define elf_backend_relocate_section elf64_x86_64_relocate_section
4469 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
4470 #define elf_backend_always_size_sections elf64_x86_64_always_size_sections
4471 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4472 #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val
4473 #define elf_backend_object_p elf64_x86_64_elf_object_p
4474 #define bfd_elf64_mkobject elf64_x86_64_mkobject
4476 #define elf_backend_section_from_shdr \
4477 elf64_x86_64_section_from_shdr
4479 #define elf_backend_section_from_bfd_section \
4480 elf64_x86_64_elf_section_from_bfd_section
4481 #define elf_backend_add_symbol_hook \
4482 elf64_x86_64_add_symbol_hook
4483 #define elf_backend_symbol_processing \
4484 elf64_x86_64_symbol_processing
4485 #define elf_backend_common_section_index \
4486 elf64_x86_64_common_section_index
4487 #define elf_backend_common_section \
4488 elf64_x86_64_common_section
4489 #define elf_backend_common_definition \
4490 elf64_x86_64_common_definition
4491 #define elf_backend_merge_symbol \
4492 elf64_x86_64_merge_symbol
4493 #define elf_backend_special_sections \
4494 elf64_x86_64_special_sections
4495 #define elf_backend_additional_program_headers \
4496 elf64_x86_64_additional_program_headers
4497 #define elf_backend_hash_symbol \
4498 elf64_x86_64_hash_symbol
4500 #undef elf_backend_post_process_headers
4501 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4503 #include "elf64-target.h"
4505 /* FreeBSD support. */
4507 #undef TARGET_LITTLE_SYM
4508 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec
4509 #undef TARGET_LITTLE_NAME
4510 #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd"
4513 #define ELF_OSABI ELFOSABI_FREEBSD
4516 #define elf64_bed elf64_x86_64_fbsd_bed
4518 #include "elf64-target.h"
4520 /* Solaris 2 support. */
4522 #undef TARGET_LITTLE_SYM
4523 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_sol2_vec
4524 #undef TARGET_LITTLE_NAME
4525 #define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
4527 /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
4528 objects won't be recognized. */
4532 #define elf64_bed elf64_x86_64_sol2_bed
4534 /* The Solaris 2 ABI requires a plt symbol on all platforms.
4536 Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
4538 #undef elf_backend_want_plt_sym
4539 #define elf_backend_want_plt_sym 1
4541 #include "elf64-target.h"
4543 /* Intel L1OM support. */
4546 elf64_l1om_elf_object_p (bfd
*abfd
)
4548 /* Set the right machine number for an L1OM elf64 file. */
4549 bfd_default_set_arch_mach (abfd
, bfd_arch_l1om
, bfd_mach_l1om
);
4553 #undef TARGET_LITTLE_SYM
4554 #define TARGET_LITTLE_SYM bfd_elf64_l1om_vec
4555 #undef TARGET_LITTLE_NAME
4556 #define TARGET_LITTLE_NAME "elf64-l1om"
4558 #define ELF_ARCH bfd_arch_l1om
4560 #undef ELF_MACHINE_CODE
4561 #define ELF_MACHINE_CODE EM_L1OM
4566 #define elf64_bed elf64_l1om_bed
4568 #undef elf_backend_object_p
4569 #define elf_backend_object_p elf64_l1om_elf_object_p
4571 #undef elf_backend_post_process_headers
4573 #include "elf64-target.h"
4575 /* FreeBSD L1OM support. */
4577 #undef TARGET_LITTLE_SYM
4578 #define TARGET_LITTLE_SYM bfd_elf64_l1om_freebsd_vec
4579 #undef TARGET_LITTLE_NAME
4580 #define TARGET_LITTLE_NAME "elf64-l1om-freebsd"
4583 #define ELF_OSABI ELFOSABI_FREEBSD
4586 #define elf64_bed elf64_l1om_fbsd_bed
4588 #undef elf_backend_post_process_headers
4589 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4591 #include "elf64-target.h"