1 /* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka <jh@suse.cz>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "elf/x86-64.h"
29 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
30 #define MINUS_ONE (~ (bfd_vma) 0)
32 /* The relocation "howto" table. Order of fields:
33 type, size, bitsize, pc_relative, complain_on_overflow,
34 special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
35 static reloc_howto_type x86_64_elf_howto_table
[] =
37 HOWTO(R_X86_64_NONE
, 0, 0, 0, FALSE
, 0, complain_overflow_dont
,
38 bfd_elf_generic_reloc
, "R_X86_64_NONE", FALSE
, 0x00000000, 0x00000000,
40 HOWTO(R_X86_64_64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
41 bfd_elf_generic_reloc
, "R_X86_64_64", FALSE
, MINUS_ONE
, MINUS_ONE
,
43 HOWTO(R_X86_64_PC32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
44 bfd_elf_generic_reloc
, "R_X86_64_PC32", FALSE
, 0xffffffff, 0xffffffff,
46 HOWTO(R_X86_64_GOT32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
47 bfd_elf_generic_reloc
, "R_X86_64_GOT32", FALSE
, 0xffffffff, 0xffffffff,
49 HOWTO(R_X86_64_PLT32
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
50 bfd_elf_generic_reloc
, "R_X86_64_PLT32", FALSE
, 0xffffffff, 0xffffffff,
52 HOWTO(R_X86_64_COPY
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
53 bfd_elf_generic_reloc
, "R_X86_64_COPY", FALSE
, 0xffffffff, 0xffffffff,
55 HOWTO(R_X86_64_GLOB_DAT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
56 bfd_elf_generic_reloc
, "R_X86_64_GLOB_DAT", FALSE
, MINUS_ONE
,
58 HOWTO(R_X86_64_JUMP_SLOT
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
59 bfd_elf_generic_reloc
, "R_X86_64_JUMP_SLOT", FALSE
, MINUS_ONE
,
61 HOWTO(R_X86_64_RELATIVE
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
62 bfd_elf_generic_reloc
, "R_X86_64_RELATIVE", FALSE
, MINUS_ONE
,
64 HOWTO(R_X86_64_GOTPCREL
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
65 bfd_elf_generic_reloc
, "R_X86_64_GOTPCREL", FALSE
, 0xffffffff,
67 HOWTO(R_X86_64_32
, 0, 2, 32, FALSE
, 0, complain_overflow_unsigned
,
68 bfd_elf_generic_reloc
, "R_X86_64_32", FALSE
, 0xffffffff, 0xffffffff,
70 HOWTO(R_X86_64_32S
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
71 bfd_elf_generic_reloc
, "R_X86_64_32S", FALSE
, 0xffffffff, 0xffffffff,
73 HOWTO(R_X86_64_16
, 0, 1, 16, FALSE
, 0, complain_overflow_bitfield
,
74 bfd_elf_generic_reloc
, "R_X86_64_16", FALSE
, 0xffff, 0xffff, FALSE
),
75 HOWTO(R_X86_64_PC16
,0, 1, 16, TRUE
, 0, complain_overflow_bitfield
,
76 bfd_elf_generic_reloc
, "R_X86_64_PC16", FALSE
, 0xffff, 0xffff, TRUE
),
77 HOWTO(R_X86_64_8
, 0, 0, 8, FALSE
, 0, complain_overflow_signed
,
78 bfd_elf_generic_reloc
, "R_X86_64_8", FALSE
, 0xff, 0xff, FALSE
),
79 HOWTO(R_X86_64_PC8
, 0, 0, 8, TRUE
, 0, complain_overflow_signed
,
80 bfd_elf_generic_reloc
, "R_X86_64_PC8", FALSE
, 0xff, 0xff, TRUE
),
81 HOWTO(R_X86_64_DTPMOD64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
82 bfd_elf_generic_reloc
, "R_X86_64_DTPMOD64", FALSE
, MINUS_ONE
,
84 HOWTO(R_X86_64_DTPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
85 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF64", FALSE
, MINUS_ONE
,
87 HOWTO(R_X86_64_TPOFF64
, 0, 4, 64, FALSE
, 0, complain_overflow_bitfield
,
88 bfd_elf_generic_reloc
, "R_X86_64_TPOFF64", FALSE
, MINUS_ONE
,
90 HOWTO(R_X86_64_TLSGD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
91 bfd_elf_generic_reloc
, "R_X86_64_TLSGD", FALSE
, 0xffffffff,
93 HOWTO(R_X86_64_TLSLD
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
94 bfd_elf_generic_reloc
, "R_X86_64_TLSLD", FALSE
, 0xffffffff,
96 HOWTO(R_X86_64_DTPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_bitfield
,
97 bfd_elf_generic_reloc
, "R_X86_64_DTPOFF32", FALSE
, 0xffffffff,
99 HOWTO(R_X86_64_GOTTPOFF
, 0, 2, 32, TRUE
, 0, complain_overflow_signed
,
100 bfd_elf_generic_reloc
, "R_X86_64_GOTTPOFF", FALSE
, 0xffffffff,
102 HOWTO(R_X86_64_TPOFF32
, 0, 2, 32, FALSE
, 0, complain_overflow_signed
,
103 bfd_elf_generic_reloc
, "R_X86_64_TPOFF32", FALSE
, 0xffffffff,
106 /* GNU extension to record C++ vtable hierarchy. */
107 HOWTO (R_X86_64_GNU_VTINHERIT
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
108 NULL
, "R_X86_64_GNU_VTINHERIT", FALSE
, 0, 0, FALSE
),
110 /* GNU extension to record C++ vtable member usage. */
111 HOWTO (R_X86_64_GNU_VTENTRY
, 0, 4, 0, FALSE
, 0, complain_overflow_dont
,
112 _bfd_elf_rel_vtable_reloc_fn
, "R_X86_64_GNU_VTENTRY", FALSE
, 0, 0,
116 /* Map BFD relocs to the x86_64 elf relocs. */
119 bfd_reloc_code_real_type bfd_reloc_val
;
120 unsigned char elf_reloc_val
;
123 static const struct elf_reloc_map x86_64_reloc_map
[] =
125 { BFD_RELOC_NONE
, R_X86_64_NONE
, },
126 { BFD_RELOC_64
, R_X86_64_64
, },
127 { BFD_RELOC_32_PCREL
, R_X86_64_PC32
, },
128 { BFD_RELOC_X86_64_GOT32
, R_X86_64_GOT32
,},
129 { BFD_RELOC_X86_64_PLT32
, R_X86_64_PLT32
,},
130 { BFD_RELOC_X86_64_COPY
, R_X86_64_COPY
, },
131 { BFD_RELOC_X86_64_GLOB_DAT
, R_X86_64_GLOB_DAT
, },
132 { BFD_RELOC_X86_64_JUMP_SLOT
, R_X86_64_JUMP_SLOT
, },
133 { BFD_RELOC_X86_64_RELATIVE
, R_X86_64_RELATIVE
, },
134 { BFD_RELOC_X86_64_GOTPCREL
, R_X86_64_GOTPCREL
, },
135 { BFD_RELOC_32
, R_X86_64_32
, },
136 { BFD_RELOC_X86_64_32S
, R_X86_64_32S
, },
137 { BFD_RELOC_16
, R_X86_64_16
, },
138 { BFD_RELOC_16_PCREL
, R_X86_64_PC16
, },
139 { BFD_RELOC_8
, R_X86_64_8
, },
140 { BFD_RELOC_8_PCREL
, R_X86_64_PC8
, },
141 { BFD_RELOC_X86_64_DTPMOD64
, R_X86_64_DTPMOD64
, },
142 { BFD_RELOC_X86_64_DTPOFF64
, R_X86_64_DTPOFF64
, },
143 { BFD_RELOC_X86_64_TPOFF64
, R_X86_64_TPOFF64
, },
144 { BFD_RELOC_X86_64_TLSGD
, R_X86_64_TLSGD
, },
145 { BFD_RELOC_X86_64_TLSLD
, R_X86_64_TLSLD
, },
146 { BFD_RELOC_X86_64_DTPOFF32
, R_X86_64_DTPOFF32
, },
147 { BFD_RELOC_X86_64_GOTTPOFF
, R_X86_64_GOTTPOFF
, },
148 { BFD_RELOC_X86_64_TPOFF32
, R_X86_64_TPOFF32
, },
149 { BFD_RELOC_VTABLE_INHERIT
, R_X86_64_GNU_VTINHERIT
, },
150 { BFD_RELOC_VTABLE_ENTRY
, R_X86_64_GNU_VTENTRY
, },
153 static reloc_howto_type
*elf64_x86_64_reloc_type_lookup
154 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
155 static void elf64_x86_64_info_to_howto
156 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
157 static bfd_boolean elf64_x86_64_grok_prstatus
158 PARAMS ((bfd
*, Elf_Internal_Note
*));
159 static bfd_boolean elf64_x86_64_grok_psinfo
160 PARAMS ((bfd
*, Elf_Internal_Note
*));
161 static struct bfd_link_hash_table
*elf64_x86_64_link_hash_table_create
163 static int elf64_x86_64_tls_transition
164 PARAMS ((struct bfd_link_info
*, int, int));
165 static bfd_boolean elf64_x86_64_mkobject
167 static bfd_boolean elf64_x86_64_elf_object_p
PARAMS ((bfd
*abfd
));
168 static bfd_boolean create_got_section
169 PARAMS((bfd
*, struct bfd_link_info
*));
170 static bfd_boolean elf64_x86_64_create_dynamic_sections
171 PARAMS((bfd
*, struct bfd_link_info
*));
172 static void elf64_x86_64_copy_indirect_symbol
173 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
174 struct elf_link_hash_entry
*));
175 static bfd_boolean elf64_x86_64_check_relocs
176 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*sec
,
177 const Elf_Internal_Rela
*));
178 static asection
*elf64_x86_64_gc_mark_hook
179 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
180 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
182 static bfd_boolean elf64_x86_64_gc_sweep_hook
183 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
184 const Elf_Internal_Rela
*));
186 static struct bfd_hash_entry
*link_hash_newfunc
187 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
188 static bfd_boolean elf64_x86_64_adjust_dynamic_symbol
189 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
191 static bfd_boolean allocate_dynrelocs
192 PARAMS ((struct elf_link_hash_entry
*, PTR
));
193 static bfd_boolean readonly_dynrelocs
194 PARAMS ((struct elf_link_hash_entry
*, PTR
));
195 static bfd_boolean elf64_x86_64_size_dynamic_sections
196 PARAMS ((bfd
*, struct bfd_link_info
*));
197 static bfd_vma dtpoff_base
198 PARAMS ((struct bfd_link_info
*));
200 PARAMS ((struct bfd_link_info
*, bfd_vma
));
201 static bfd_boolean elf64_x86_64_relocate_section
202 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
203 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
204 static bfd_boolean elf64_x86_64_finish_dynamic_symbol
205 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
206 Elf_Internal_Sym
*sym
));
207 static bfd_boolean elf64_x86_64_finish_dynamic_sections
208 PARAMS ((bfd
*, struct bfd_link_info
*));
209 static enum elf_reloc_type_class elf64_x86_64_reloc_type_class
210 PARAMS ((const Elf_Internal_Rela
*));
212 /* Given a BFD reloc type, return a HOWTO structure. */
213 static reloc_howto_type
*
214 elf64_x86_64_reloc_type_lookup (abfd
, code
)
215 bfd
*abfd ATTRIBUTE_UNUSED
;
216 bfd_reloc_code_real_type code
;
219 for (i
= 0; i
< sizeof (x86_64_reloc_map
) / sizeof (struct elf_reloc_map
);
222 if (x86_64_reloc_map
[i
].bfd_reloc_val
== code
)
223 return &x86_64_elf_howto_table
[i
];
228 /* Given an x86_64 ELF reloc type, fill in an arelent structure. */
231 elf64_x86_64_info_to_howto (abfd
, cache_ptr
, dst
)
232 bfd
*abfd ATTRIBUTE_UNUSED
;
234 Elf_Internal_Rela
*dst
;
238 r_type
= ELF64_R_TYPE (dst
->r_info
);
239 if (r_type
< (unsigned int) R_X86_64_GNU_VTINHERIT
)
241 BFD_ASSERT (r_type
<= (unsigned int) R_X86_64_TPOFF32
);
246 BFD_ASSERT (r_type
< (unsigned int) R_X86_64_max
);
247 i
= r_type
- ((unsigned int) R_X86_64_GNU_VTINHERIT
- R_X86_64_TPOFF32
- 1);
249 cache_ptr
->howto
= &x86_64_elf_howto_table
[i
];
250 BFD_ASSERT (r_type
== cache_ptr
->howto
->type
);
253 /* Support for core dump NOTE sections. */
255 elf64_x86_64_grok_prstatus (abfd
, note
)
257 Elf_Internal_Note
*note
;
262 switch (note
->descsz
)
267 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */
269 elf_tdata (abfd
)->core_signal
270 = bfd_get_16 (abfd
, note
->descdata
+ 12);
273 elf_tdata (abfd
)->core_pid
274 = bfd_get_32 (abfd
, note
->descdata
+ 32);
283 /* Make a ".reg/999" section. */
284 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
285 raw_size
, note
->descpos
+ offset
);
289 elf64_x86_64_grok_psinfo (abfd
, note
)
291 Elf_Internal_Note
*note
;
293 switch (note
->descsz
)
298 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
299 elf_tdata (abfd
)->core_program
300 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
301 elf_tdata (abfd
)->core_command
302 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
305 /* Note that for some reason, a spurious space is tacked
306 onto the end of the args in some (at least one anyway)
307 implementations, so strip it off if it exists. */
310 char *command
= elf_tdata (abfd
)->core_command
;
311 int n
= strlen (command
);
313 if (0 < n
&& command
[n
- 1] == ' ')
314 command
[n
- 1] = '\0';
320 /* Functions for the x86-64 ELF linker. */
322 /* The name of the dynamic interpreter. This is put in the .interp
325 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
327 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
328 copying dynamic variables from a shared lib into an app's dynbss
329 section, and instead use a dynamic relocation to point into the
331 #define ELIMINATE_COPY_RELOCS 1
333 /* The size in bytes of an entry in the global offset table. */
335 #define GOT_ENTRY_SIZE 8
337 /* The size in bytes of an entry in the procedure linkage table. */
339 #define PLT_ENTRY_SIZE 16
341 /* The first entry in a procedure linkage table looks like this. See the
342 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
344 static const bfd_byte elf64_x86_64_plt0_entry
[PLT_ENTRY_SIZE
] =
346 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
347 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
348 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
351 /* Subsequent entries in a procedure linkage table look like this. */
353 static const bfd_byte elf64_x86_64_plt_entry
[PLT_ENTRY_SIZE
] =
355 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
356 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
357 0x68, /* pushq immediate */
358 0, 0, 0, 0, /* replaced with index into relocation table. */
359 0xe9, /* jmp relative */
360 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
363 /* The x86-64 linker needs to keep track of the number of relocs that
364 it decides to copy as dynamic relocs in check_relocs for each symbol.
365 This is so that it can later discard them if they are found to be
366 unnecessary. We store the information in a field extending the
367 regular ELF linker hash table. */
369 struct elf64_x86_64_dyn_relocs
372 struct elf64_x86_64_dyn_relocs
*next
;
374 /* The input section of the reloc. */
377 /* Total number of relocs copied for the input section. */
380 /* Number of pc-relative relocs copied for the input section. */
381 bfd_size_type pc_count
;
384 /* x86-64 ELF linker hash entry. */
386 struct elf64_x86_64_link_hash_entry
388 struct elf_link_hash_entry elf
;
390 /* Track dynamic relocs copied for this symbol. */
391 struct elf64_x86_64_dyn_relocs
*dyn_relocs
;
393 #define GOT_UNKNOWN 0
397 unsigned char tls_type
;
400 #define elf64_x86_64_hash_entry(ent) \
401 ((struct elf64_x86_64_link_hash_entry *)(ent))
403 struct elf64_x86_64_obj_tdata
405 struct elf_obj_tdata root
;
407 /* tls_type for each local got entry. */
408 char *local_got_tls_type
;
411 #define elf64_x86_64_tdata(abfd) \
412 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)
414 #define elf64_x86_64_local_got_tls_type(abfd) \
415 (elf64_x86_64_tdata (abfd)->local_got_tls_type)
418 /* x86-64 ELF linker hash table. */
420 struct elf64_x86_64_link_hash_table
422 struct elf_link_hash_table elf
;
424 /* Short-cuts to get to dynamic linker sections. */
434 bfd_signed_vma refcount
;
438 /* Small local sym to section mapping cache. */
439 struct sym_sec_cache sym_sec
;
442 /* Get the x86-64 ELF linker hash table from a link_info structure. */
444 #define elf64_x86_64_hash_table(p) \
445 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
447 /* Create an entry in an x86-64 ELF linker hash table. */
449 static struct bfd_hash_entry
*
450 link_hash_newfunc (entry
, table
, string
)
451 struct bfd_hash_entry
*entry
;
452 struct bfd_hash_table
*table
;
455 /* Allocate the structure if it has not already been allocated by a
459 entry
= bfd_hash_allocate (table
,
460 sizeof (struct elf64_x86_64_link_hash_entry
));
465 /* Call the allocation method of the superclass. */
466 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
469 struct elf64_x86_64_link_hash_entry
*eh
;
471 eh
= (struct elf64_x86_64_link_hash_entry
*) entry
;
472 eh
->dyn_relocs
= NULL
;
473 eh
->tls_type
= GOT_UNKNOWN
;
479 /* Create an X86-64 ELF linker hash table. */
481 static struct bfd_link_hash_table
*
482 elf64_x86_64_link_hash_table_create (abfd
)
485 struct elf64_x86_64_link_hash_table
*ret
;
486 bfd_size_type amt
= sizeof (struct elf64_x86_64_link_hash_table
);
488 ret
= (struct elf64_x86_64_link_hash_table
*) bfd_malloc (amt
);
492 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, link_hash_newfunc
))
505 ret
->sym_sec
.abfd
= NULL
;
506 ret
->tls_ld_got
.refcount
= 0;
508 return &ret
->elf
.root
;
511 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
512 shortcuts to them in our hash table. */
515 create_got_section (dynobj
, info
)
517 struct bfd_link_info
*info
;
519 struct elf64_x86_64_link_hash_table
*htab
;
521 if (! _bfd_elf_create_got_section (dynobj
, info
))
524 htab
= elf64_x86_64_hash_table (info
);
525 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
526 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
527 if (!htab
->sgot
|| !htab
->sgotplt
)
530 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
531 if (htab
->srelgot
== NULL
532 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
533 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
534 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
536 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
541 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
542 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
546 elf64_x86_64_create_dynamic_sections (dynobj
, info
)
548 struct bfd_link_info
*info
;
550 struct elf64_x86_64_link_hash_table
*htab
;
552 htab
= elf64_x86_64_hash_table (info
);
553 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
556 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
559 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
560 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
561 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
563 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
565 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
566 || (!info
->shared
&& !htab
->srelbss
))
572 /* Copy the extra info we tack onto an elf_link_hash_entry. */
575 elf64_x86_64_copy_indirect_symbol (bed
, dir
, ind
)
576 struct elf_backend_data
*bed
;
577 struct elf_link_hash_entry
*dir
, *ind
;
579 struct elf64_x86_64_link_hash_entry
*edir
, *eind
;
581 edir
= (struct elf64_x86_64_link_hash_entry
*) dir
;
582 eind
= (struct elf64_x86_64_link_hash_entry
*) ind
;
584 if (eind
->dyn_relocs
!= NULL
)
586 if (edir
->dyn_relocs
!= NULL
)
588 struct elf64_x86_64_dyn_relocs
**pp
;
589 struct elf64_x86_64_dyn_relocs
*p
;
591 if (ind
->root
.type
== bfd_link_hash_indirect
)
594 /* Add reloc counts against the weak sym to the strong sym
595 list. Merge any entries against the same section. */
596 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
598 struct elf64_x86_64_dyn_relocs
*q
;
600 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
601 if (q
->sec
== p
->sec
)
603 q
->pc_count
+= p
->pc_count
;
604 q
->count
+= p
->count
;
611 *pp
= edir
->dyn_relocs
;
614 edir
->dyn_relocs
= eind
->dyn_relocs
;
615 eind
->dyn_relocs
= NULL
;
618 if (ind
->root
.type
== bfd_link_hash_indirect
619 && dir
->got
.refcount
<= 0)
621 edir
->tls_type
= eind
->tls_type
;
622 eind
->tls_type
= GOT_UNKNOWN
;
625 if (ELIMINATE_COPY_RELOCS
626 && ind
->root
.type
!= bfd_link_hash_indirect
627 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
628 /* If called to transfer flags for a weakdef during processing
629 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
630 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
631 dir
->elf_link_hash_flags
|=
632 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
633 | ELF_LINK_HASH_REF_REGULAR
634 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
636 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
640 elf64_x86_64_mkobject (abfd
)
643 bfd_size_type amt
= sizeof (struct elf64_x86_64_obj_tdata
);
644 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
645 if (abfd
->tdata
.any
== NULL
)
651 elf64_x86_64_elf_object_p (abfd
)
654 /* Allocate our special target data. */
655 struct elf64_x86_64_obj_tdata
*new_tdata
;
656 bfd_size_type amt
= sizeof (struct elf64_x86_64_obj_tdata
);
657 new_tdata
= bfd_zalloc (abfd
, amt
);
658 if (new_tdata
== NULL
)
660 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
661 abfd
->tdata
.any
= new_tdata
;
662 /* Set the right machine number for an x86-64 elf64 file. */
663 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
668 elf64_x86_64_tls_transition (info
, r_type
, is_local
)
669 struct bfd_link_info
*info
;
679 case R_X86_64_GOTTPOFF
:
681 return R_X86_64_TPOFF32
;
682 return R_X86_64_GOTTPOFF
;
684 return R_X86_64_TPOFF32
;
690 /* Look through the relocs for a section during the first phase, and
691 calculate needed space in the global offset table, procedure
692 linkage table, and dynamic reloc sections. */
695 elf64_x86_64_check_relocs (abfd
, info
, sec
, relocs
)
697 struct bfd_link_info
*info
;
699 const Elf_Internal_Rela
*relocs
;
701 struct elf64_x86_64_link_hash_table
*htab
;
702 Elf_Internal_Shdr
*symtab_hdr
;
703 struct elf_link_hash_entry
**sym_hashes
;
704 const Elf_Internal_Rela
*rel
;
705 const Elf_Internal_Rela
*rel_end
;
708 if (info
->relocateable
)
711 htab
= elf64_x86_64_hash_table (info
);
712 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
713 sym_hashes
= elf_sym_hashes (abfd
);
717 rel_end
= relocs
+ sec
->reloc_count
;
718 for (rel
= relocs
; rel
< rel_end
; rel
++)
721 unsigned long r_symndx
;
722 struct elf_link_hash_entry
*h
;
724 r_symndx
= ELF64_R_SYM (rel
->r_info
);
725 r_type
= ELF64_R_TYPE (rel
->r_info
);
727 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
729 (*_bfd_error_handler
) (_("%s: bad symbol index: %d"),
730 bfd_archive_filename (abfd
),
735 if (r_symndx
< symtab_hdr
->sh_info
)
738 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
740 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
== NULL
);
744 htab
->tls_ld_got
.refcount
+= 1;
747 case R_X86_64_TPOFF32
:
750 (*_bfd_error_handler
)
751 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
752 bfd_archive_filename (abfd
),
753 x86_64_elf_howto_table
[r_type
].name
);
754 bfd_set_error (bfd_error_bad_value
);
759 case R_X86_64_GOTTPOFF
:
761 info
->flags
|= DF_STATIC_TLS
;
765 case R_X86_64_GOTPCREL
:
767 /* This symbol requires a global offset table entry. */
769 int tls_type
, old_tls_type
;
773 default: tls_type
= GOT_NORMAL
; break;
774 case R_X86_64_TLSGD
: tls_type
= GOT_TLS_GD
; break;
775 case R_X86_64_GOTTPOFF
: tls_type
= GOT_TLS_IE
; break;
780 h
->got
.refcount
+= 1;
781 old_tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
785 bfd_signed_vma
*local_got_refcounts
;
787 /* This is a global offset table entry for a local symbol. */
788 local_got_refcounts
= elf_local_got_refcounts (abfd
);
789 if (local_got_refcounts
== NULL
)
793 size
= symtab_hdr
->sh_info
;
794 size
*= sizeof (bfd_signed_vma
) + sizeof (char);
795 local_got_refcounts
= ((bfd_signed_vma
*)
796 bfd_zalloc (abfd
, size
));
797 if (local_got_refcounts
== NULL
)
799 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
800 elf64_x86_64_local_got_tls_type (abfd
)
801 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
803 local_got_refcounts
[r_symndx
] += 1;
805 = elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
];
808 /* If a TLS symbol is accessed using IE at least once,
809 there is no point to use dynamic model for it. */
810 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
811 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
813 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
814 tls_type
= old_tls_type
;
817 (*_bfd_error_handler
)
818 (_("%s: %s' accessed both as normal and thread local symbol"),
819 bfd_archive_filename (abfd
),
820 h
? h
->root
.root
.string
: "<local>");
825 if (old_tls_type
!= tls_type
)
828 elf64_x86_64_hash_entry (h
)->tls_type
= tls_type
;
830 elf64_x86_64_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
835 //case R_X86_64_GOTPCREL:
837 if (htab
->sgot
== NULL
)
839 if (htab
->elf
.dynobj
== NULL
)
840 htab
->elf
.dynobj
= abfd
;
841 if (!create_got_section (htab
->elf
.dynobj
, info
))
847 /* This symbol requires a procedure linkage table entry. We
848 actually build the entry in adjust_dynamic_symbol,
849 because this might be a case of linking PIC code which is
850 never referenced by a dynamic object, in which case we
851 don't need to generate a procedure linkage table entry
854 /* If this is a local symbol, we resolve it directly without
855 creating a procedure linkage table entry. */
859 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
860 h
->plt
.refcount
+= 1;
867 /* Let's help debug shared library creation. These relocs
868 cannot be used in shared libs. Don't error out for
869 sections we don't care about, such as debug sections or
870 non-constant sections. */
872 && (sec
->flags
& SEC_ALLOC
) != 0
873 && (sec
->flags
& SEC_READONLY
) != 0)
875 (*_bfd_error_handler
)
876 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
877 bfd_archive_filename (abfd
),
878 x86_64_elf_howto_table
[r_type
].name
);
879 bfd_set_error (bfd_error_bad_value
);
888 if (h
!= NULL
&& !info
->shared
)
890 /* If this reloc is in a read-only section, we might
891 need a copy reloc. We can't check reliably at this
892 stage whether the section is read-only, as input
893 sections have not yet been mapped to output sections.
894 Tentatively set the flag for now, and correct in
895 adjust_dynamic_symbol. */
896 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
898 /* We may need a .plt entry if the function this reloc
899 refers to is in a shared lib. */
900 h
->plt
.refcount
+= 1;
903 /* If we are creating a shared library, and this is a reloc
904 against a global symbol, or a non PC relative reloc
905 against a local symbol, then we need to copy the reloc
906 into the shared library. However, if we are linking with
907 -Bsymbolic, we do not need to copy a reloc against a
908 global symbol which is defined in an object we are
909 including in the link (i.e., DEF_REGULAR is set). At
910 this point we have not seen all the input files, so it is
911 possible that DEF_REGULAR is not set now but will be set
912 later (it is never cleared). In case of a weak definition,
913 DEF_REGULAR may be cleared later by a strong definition in
914 a shared library. We account for that possibility below by
915 storing information in the relocs_copied field of the hash
916 table entry. A similar situation occurs when creating
917 shared libraries and symbol visibility changes render the
920 If on the other hand, we are creating an executable, we
921 may need to keep relocations for symbols satisfied by a
922 dynamic library if we manage to avoid copy relocs for the
925 && (sec
->flags
& SEC_ALLOC
) != 0
926 && (((r_type
!= R_X86_64_PC8
)
927 && (r_type
!= R_X86_64_PC16
)
928 && (r_type
!= R_X86_64_PC32
))
931 || h
->root
.type
== bfd_link_hash_defweak
932 || (h
->elf_link_hash_flags
933 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
934 || (ELIMINATE_COPY_RELOCS
936 && (sec
->flags
& SEC_ALLOC
) != 0
938 && (h
->root
.type
== bfd_link_hash_defweak
939 || (h
->elf_link_hash_flags
940 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
942 struct elf64_x86_64_dyn_relocs
*p
;
943 struct elf64_x86_64_dyn_relocs
**head
;
945 /* We must copy these reloc types into the output file.
946 Create a reloc section in dynobj and make room for
953 name
= (bfd_elf_string_from_elf_section
955 elf_elfheader (abfd
)->e_shstrndx
,
956 elf_section_data (sec
)->rel_hdr
.sh_name
));
960 if (strncmp (name
, ".rela", 5) != 0
961 || strcmp (bfd_get_section_name (abfd
, sec
),
964 (*_bfd_error_handler
)
965 (_("%s: bad relocation section name `%s\'"),
966 bfd_archive_filename (abfd
), name
);
969 if (htab
->elf
.dynobj
== NULL
)
970 htab
->elf
.dynobj
= abfd
;
972 dynobj
= htab
->elf
.dynobj
;
974 sreloc
= bfd_get_section_by_name (dynobj
, name
);
979 sreloc
= bfd_make_section (dynobj
, name
);
980 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
981 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
982 if ((sec
->flags
& SEC_ALLOC
) != 0)
983 flags
|= SEC_ALLOC
| SEC_LOAD
;
985 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
986 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
989 elf_section_data (sec
)->sreloc
= sreloc
;
992 /* If this is a global symbol, we count the number of
993 relocations we need for this symbol. */
996 head
= &((struct elf64_x86_64_link_hash_entry
*) h
)->dyn_relocs
;
1000 /* Track dynamic relocs needed for local syms too.
1001 We really need local syms available to do this
1005 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1010 head
= ((struct elf64_x86_64_dyn_relocs
**)
1011 &elf_section_data (s
)->local_dynrel
);
1015 if (p
== NULL
|| p
->sec
!= sec
)
1017 bfd_size_type amt
= sizeof *p
;
1018 p
= ((struct elf64_x86_64_dyn_relocs
*)
1019 bfd_alloc (htab
->elf
.dynobj
, amt
));
1030 if (r_type
== R_X86_64_PC8
1031 || r_type
== R_X86_64_PC16
1032 || r_type
== R_X86_64_PC32
)
1037 /* This relocation describes the C++ object vtable hierarchy.
1038 Reconstruct it for later use during GC. */
1039 case R_X86_64_GNU_VTINHERIT
:
1040 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1044 /* This relocation describes which C++ vtable entries are actually
1045 used. Record for later use during GC. */
1046 case R_X86_64_GNU_VTENTRY
:
1047 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1059 /* Return the section that should be marked against GC for a given
1063 elf64_x86_64_gc_mark_hook (sec
, info
, rel
, h
, sym
)
1065 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1066 Elf_Internal_Rela
*rel
;
1067 struct elf_link_hash_entry
*h
;
1068 Elf_Internal_Sym
*sym
;
1072 switch (ELF64_R_TYPE (rel
->r_info
))
1074 case R_X86_64_GNU_VTINHERIT
:
1075 case R_X86_64_GNU_VTENTRY
:
1079 switch (h
->root
.type
)
1081 case bfd_link_hash_defined
:
1082 case bfd_link_hash_defweak
:
1083 return h
->root
.u
.def
.section
;
1085 case bfd_link_hash_common
:
1086 return h
->root
.u
.c
.p
->section
;
1094 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1099 /* Update the got entry reference counts for the section being removed. */
1102 elf64_x86_64_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1104 struct bfd_link_info
*info
;
1106 const Elf_Internal_Rela
*relocs
;
1108 Elf_Internal_Shdr
*symtab_hdr
;
1109 struct elf_link_hash_entry
**sym_hashes
;
1110 bfd_signed_vma
*local_got_refcounts
;
1111 const Elf_Internal_Rela
*rel
, *relend
;
1113 elf_section_data (sec
)->local_dynrel
= NULL
;
1115 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1116 sym_hashes
= elf_sym_hashes (abfd
);
1117 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1119 relend
= relocs
+ sec
->reloc_count
;
1120 for (rel
= relocs
; rel
< relend
; rel
++)
1122 unsigned long r_symndx
;
1123 unsigned int r_type
;
1124 struct elf_link_hash_entry
*h
= NULL
;
1126 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1127 if (r_symndx
>= symtab_hdr
->sh_info
)
1129 struct elf64_x86_64_link_hash_entry
*eh
;
1130 struct elf64_x86_64_dyn_relocs
**pp
;
1131 struct elf64_x86_64_dyn_relocs
*p
;
1133 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1134 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1136 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1139 /* Everything must go for SEC. */
1145 r_type
= ELF64_R_TYPE (rel
->r_info
);
1146 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
!= NULL
);
1149 case R_X86_64_TLSLD
:
1150 if (elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
> 0)
1151 elf64_x86_64_hash_table (info
)->tls_ld_got
.refcount
-= 1;
1154 case R_X86_64_TLSGD
:
1155 case R_X86_64_GOTTPOFF
:
1156 case R_X86_64_GOT32
:
1157 case R_X86_64_GOTPCREL
:
1160 if (h
->got
.refcount
> 0)
1161 h
->got
.refcount
-= 1;
1163 else if (local_got_refcounts
!= NULL
)
1165 if (local_got_refcounts
[r_symndx
] > 0)
1166 local_got_refcounts
[r_symndx
] -= 1;
1182 case R_X86_64_PLT32
:
1185 if (h
->plt
.refcount
> 0)
1186 h
->plt
.refcount
-= 1;
1198 /* Adjust a symbol defined by a dynamic object and referenced by a
1199 regular object. The current definition is in some section of the
1200 dynamic object, but we're not including those sections. We have to
1201 change the definition to something the rest of the link can
1205 elf64_x86_64_adjust_dynamic_symbol (info
, h
)
1206 struct bfd_link_info
*info
;
1207 struct elf_link_hash_entry
*h
;
1209 struct elf64_x86_64_link_hash_table
*htab
;
1211 unsigned int power_of_two
;
1213 /* If this is a function, put it in the procedure linkage table. We
1214 will fill in the contents of the procedure linkage table later,
1215 when we know the address of the .got section. */
1216 if (h
->type
== STT_FUNC
1217 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1219 if (h
->plt
.refcount
<= 0
1221 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1222 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
1223 && h
->root
.type
!= bfd_link_hash_undefweak
1224 && h
->root
.type
!= bfd_link_hash_undefined
))
1226 /* This case can occur if we saw a PLT32 reloc in an input
1227 file, but the symbol was never referred to by a dynamic
1228 object, or if all references were garbage collected. In
1229 such a case, we don't actually need to build a procedure
1230 linkage table, and we can just do a PC32 reloc instead. */
1231 h
->plt
.offset
= (bfd_vma
) -1;
1232 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1238 /* It's possible that we incorrectly decided a .plt reloc was
1239 needed for an R_X86_64_PC32 reloc to a non-function sym in
1240 check_relocs. We can't decide accurately between function and
1241 non-function syms in check-relocs; Objects loaded later in
1242 the link may change h->type. So fix it now. */
1243 h
->plt
.offset
= (bfd_vma
) -1;
1245 /* If this is a weak symbol, and there is a real definition, the
1246 processor independent code will have arranged for us to see the
1247 real definition first, and we can just use the same value. */
1248 if (h
->weakdef
!= NULL
)
1250 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1251 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1252 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1253 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1254 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
1255 h
->elf_link_hash_flags
1256 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
1257 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
1261 /* This is a reference to a symbol defined by a dynamic object which
1262 is not a function. */
1264 /* If we are creating a shared library, we must presume that the
1265 only references to the symbol are via the global offset table.
1266 For such cases we need not do anything here; the relocations will
1267 be handled correctly by relocate_section. */
1271 /* If there are no references to this symbol that do not use the
1272 GOT, we don't need to generate a copy reloc. */
1273 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1276 /* If -z nocopyreloc was given, we won't generate them either. */
1277 if (info
->nocopyreloc
)
1279 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1283 if (ELIMINATE_COPY_RELOCS
)
1285 struct elf64_x86_64_link_hash_entry
* eh
;
1286 struct elf64_x86_64_dyn_relocs
*p
;
1288 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1289 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1291 s
= p
->sec
->output_section
;
1292 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1296 /* If we didn't find any dynamic relocs in read-only sections, then
1297 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1300 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1305 /* We must allocate the symbol in our .dynbss section, which will
1306 become part of the .bss section of the executable. There will be
1307 an entry for this symbol in the .dynsym section. The dynamic
1308 object will contain position independent code, so all references
1309 from the dynamic object to this symbol will go through the global
1310 offset table. The dynamic linker will use the .dynsym entry to
1311 determine the address it must put in the global offset table, so
1312 both the dynamic object and the regular object will refer to the
1313 same memory location for the variable. */
1315 htab
= elf64_x86_64_hash_table (info
);
1317 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1318 to copy the initial value out of the dynamic object and into the
1319 runtime process image. */
1320 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1322 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
1323 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1326 /* We need to figure out the alignment required for this symbol. I
1327 have no idea how ELF linkers handle this. 16-bytes is the size
1328 of the largest type that requires hard alignment -- long double. */
1329 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
1331 power_of_two
= bfd_log2 (h
->size
);
1332 if (power_of_two
> 4)
1335 /* Apply the required alignment. */
1337 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
1338 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1340 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1344 /* Define the symbol as being at this point in the section. */
1345 h
->root
.u
.def
.section
= s
;
1346 h
->root
.u
.def
.value
= s
->_raw_size
;
1348 /* Increment the section size to make room for the symbol. */
1349 s
->_raw_size
+= h
->size
;
1354 /* This is the condition under which elf64_x86_64_finish_dynamic_symbol
1355 will be called from elflink.h. If elflink.h doesn't call our
1356 finish_dynamic_symbol routine, we'll need to do something about
1357 initializing any .plt and .got entries in elf64_x86_64_relocate_section. */
1358 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1360 && ((INFO)->shared \
1361 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1362 && ((H)->dynindx != -1 \
1363 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1365 /* Allocate space in .plt, .got and associated reloc sections for
1369 allocate_dynrelocs (h
, inf
)
1370 struct elf_link_hash_entry
*h
;
1373 struct bfd_link_info
*info
;
1374 struct elf64_x86_64_link_hash_table
*htab
;
1375 struct elf64_x86_64_link_hash_entry
*eh
;
1376 struct elf64_x86_64_dyn_relocs
*p
;
1378 if (h
->root
.type
== bfd_link_hash_indirect
)
1381 if (h
->root
.type
== bfd_link_hash_warning
)
1382 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1384 info
= (struct bfd_link_info
*) inf
;
1385 htab
= elf64_x86_64_hash_table (info
);
1387 if (htab
->elf
.dynamic_sections_created
1388 && h
->plt
.refcount
> 0)
1390 /* Make sure this symbol is output as a dynamic symbol.
1391 Undefined weak syms won't yet be marked as dynamic. */
1392 if (h
->dynindx
== -1
1393 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1395 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1399 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1400 || h
->root
.type
!= bfd_link_hash_undefweak
)
1401 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1403 asection
*s
= htab
->splt
;
1405 /* If this is the first .plt entry, make room for the special
1407 if (s
->_raw_size
== 0)
1408 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1410 h
->plt
.offset
= s
->_raw_size
;
1412 /* If this symbol is not defined in a regular file, and we are
1413 not generating a shared library, then set the symbol to this
1414 location in the .plt. This is required to make function
1415 pointers compare as equal between the normal executable and
1416 the shared library. */
1418 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1420 h
->root
.u
.def
.section
= s
;
1421 h
->root
.u
.def
.value
= h
->plt
.offset
;
1424 /* Make room for this entry. */
1425 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1427 /* We also need to make an entry in the .got.plt section, which
1428 will be placed in the .got section by the linker script. */
1429 htab
->sgotplt
->_raw_size
+= GOT_ENTRY_SIZE
;
1431 /* We also need to make an entry in the .rela.plt section. */
1432 htab
->srelplt
->_raw_size
+= sizeof (Elf64_External_Rela
);
1436 h
->plt
.offset
= (bfd_vma
) -1;
1437 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1442 h
->plt
.offset
= (bfd_vma
) -1;
1443 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1446 /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
1447 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
1448 if (h
->got
.refcount
> 0
1451 && elf64_x86_64_hash_entry (h
)->tls_type
== GOT_TLS_IE
)
1452 h
->got
.offset
= (bfd_vma
) -1;
1453 else if (h
->got
.refcount
> 0)
1457 int tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
1459 /* Make sure this symbol is output as a dynamic symbol.
1460 Undefined weak syms won't yet be marked as dynamic. */
1461 if (h
->dynindx
== -1
1462 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1464 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1469 h
->got
.offset
= s
->_raw_size
;
1470 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1471 /* R_X86_64_TLSGD needs 2 consecutive GOT slots. */
1472 if (tls_type
== GOT_TLS_GD
)
1473 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1474 dyn
= htab
->elf
.dynamic_sections_created
;
1475 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol
1477 R_X86_64_GOTTPOFF needs one dynamic relocation. */
1478 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
1479 || tls_type
== GOT_TLS_IE
)
1480 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1481 else if (tls_type
== GOT_TLS_GD
)
1482 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf64_External_Rela
);
1483 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1484 || h
->root
.type
!= bfd_link_hash_undefweak
)
1485 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
1486 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1489 h
->got
.offset
= (bfd_vma
) -1;
1491 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1492 if (eh
->dyn_relocs
== NULL
)
1495 /* In the shared -Bsymbolic case, discard space allocated for
1496 dynamic pc-relative relocs against symbols which turn out to be
1497 defined in regular objects. For the normal shared case, discard
1498 space for pc-relative relocs that have become local due to symbol
1499 visibility changes. */
1503 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1504 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
1507 struct elf64_x86_64_dyn_relocs
**pp
;
1509 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1511 p
->count
-= p
->pc_count
;
1520 else if (ELIMINATE_COPY_RELOCS
)
1522 /* For the non-shared case, discard space for relocs against
1523 symbols which turn out to need copy relocs or are not
1526 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1527 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1528 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1529 || (htab
->elf
.dynamic_sections_created
1530 && (h
->root
.type
== bfd_link_hash_undefweak
1531 || h
->root
.type
== bfd_link_hash_undefined
))))
1533 /* Make sure this symbol is output as a dynamic symbol.
1534 Undefined weak syms won't yet be marked as dynamic. */
1535 if (h
->dynindx
== -1
1536 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1538 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1542 /* If that succeeded, we know we'll be keeping all the
1544 if (h
->dynindx
!= -1)
1548 eh
->dyn_relocs
= NULL
;
1553 /* Finally, allocate space. */
1554 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1556 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1557 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1563 /* Find any dynamic relocs that apply to read-only sections. */
1566 readonly_dynrelocs (h
, inf
)
1567 struct elf_link_hash_entry
*h
;
1570 struct elf64_x86_64_link_hash_entry
*eh
;
1571 struct elf64_x86_64_dyn_relocs
*p
;
1573 if (h
->root
.type
== bfd_link_hash_warning
)
1574 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1576 eh
= (struct elf64_x86_64_link_hash_entry
*) h
;
1577 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1579 asection
*s
= p
->sec
->output_section
;
1581 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1583 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
1585 info
->flags
|= DF_TEXTREL
;
1587 /* Not an error, just cut short the traversal. */
1594 /* Set the sizes of the dynamic sections. */
1597 elf64_x86_64_size_dynamic_sections (output_bfd
, info
)
1598 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1599 struct bfd_link_info
*info
;
1601 struct elf64_x86_64_link_hash_table
*htab
;
1607 htab
= elf64_x86_64_hash_table (info
);
1608 dynobj
= htab
->elf
.dynobj
;
1612 if (htab
->elf
.dynamic_sections_created
)
1614 /* Set the contents of the .interp section to the interpreter. */
1617 s
= bfd_get_section_by_name (dynobj
, ".interp");
1620 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1621 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1625 /* Set up .got offsets for local syms, and space for local dynamic
1627 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1629 bfd_signed_vma
*local_got
;
1630 bfd_signed_vma
*end_local_got
;
1631 char *local_tls_type
;
1632 bfd_size_type locsymcount
;
1633 Elf_Internal_Shdr
*symtab_hdr
;
1636 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1639 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1641 struct elf64_x86_64_dyn_relocs
*p
;
1643 for (p
= *((struct elf64_x86_64_dyn_relocs
**)
1644 &elf_section_data (s
)->local_dynrel
);
1648 if (!bfd_is_abs_section (p
->sec
)
1649 && bfd_is_abs_section (p
->sec
->output_section
))
1651 /* Input section has been discarded, either because
1652 it is a copy of a linkonce section or due to
1653 linker script /DISCARD/, so we'll be discarding
1656 else if (p
->count
!= 0)
1658 srel
= elf_section_data (p
->sec
)->sreloc
;
1659 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
1660 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1661 info
->flags
|= DF_TEXTREL
;
1667 local_got
= elf_local_got_refcounts (ibfd
);
1671 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1672 locsymcount
= symtab_hdr
->sh_info
;
1673 end_local_got
= local_got
+ locsymcount
;
1674 local_tls_type
= elf64_x86_64_local_got_tls_type (ibfd
);
1676 srel
= htab
->srelgot
;
1677 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
1681 *local_got
= s
->_raw_size
;
1682 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1683 if (*local_tls_type
== GOT_TLS_GD
)
1684 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1686 || *local_tls_type
== GOT_TLS_GD
1687 || *local_tls_type
== GOT_TLS_IE
)
1688 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
1691 *local_got
= (bfd_vma
) -1;
1695 if (htab
->tls_ld_got
.refcount
> 0)
1697 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD
1699 htab
->tls_ld_got
.offset
= htab
->sgot
->_raw_size
;
1700 htab
->sgot
->_raw_size
+= 2 * GOT_ENTRY_SIZE
;
1701 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1704 htab
->tls_ld_got
.offset
= -1;
1706 /* Allocate global sym .plt and .got entries, and space for global
1707 sym dynamic relocs. */
1708 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
1710 /* We now have determined the sizes of the various dynamic sections.
1711 Allocate memory for them. */
1713 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1715 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1720 || s
== htab
->sgotplt
)
1722 /* Strip this section if we don't need it; see the
1725 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
1727 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
1730 /* We use the reloc_count field as a counter if we need
1731 to copy relocs into the output file. */
1736 /* It's not one of our sections, so don't allocate space. */
1740 if (s
->_raw_size
== 0)
1742 /* If we don't need this section, strip it from the
1743 output file. This is mostly to handle .rela.bss and
1744 .rela.plt. We must create both sections in
1745 create_dynamic_sections, because they must be created
1746 before the linker maps input sections to output
1747 sections. The linker does that before
1748 adjust_dynamic_symbol is called, and it is that
1749 function which decides whether anything needs to go
1750 into these sections. */
1752 _bfd_strip_section_from_output (info
, s
);
1756 /* Allocate memory for the section contents. We use bfd_zalloc
1757 here in case unused entries are not reclaimed before the
1758 section's contents are written out. This should not happen,
1759 but this way if it does, we get a R_X86_64_NONE reloc instead
1761 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1762 if (s
->contents
== NULL
)
1766 if (htab
->elf
.dynamic_sections_created
)
1768 /* Add some entries to the .dynamic section. We fill in the
1769 values later, in elf64_x86_64_finish_dynamic_sections, but we
1770 must add the entries now so that we get the correct size for
1771 the .dynamic section. The DT_DEBUG entry is filled in by the
1772 dynamic linker and used by the debugger. */
1773 #define add_dynamic_entry(TAG, VAL) \
1774 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1778 if (!add_dynamic_entry (DT_DEBUG
, 0))
1782 if (htab
->splt
->_raw_size
!= 0)
1784 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1785 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1786 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1787 || !add_dynamic_entry (DT_JMPREL
, 0))
1793 if (!add_dynamic_entry (DT_RELA
, 0)
1794 || !add_dynamic_entry (DT_RELASZ
, 0)
1795 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1798 /* If any dynamic relocs apply to a read-only section,
1799 then we need a DT_TEXTREL entry. */
1800 if ((info
->flags
& DF_TEXTREL
) == 0)
1801 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
1804 if ((info
->flags
& DF_TEXTREL
) != 0)
1806 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1811 #undef add_dynamic_entry
1816 /* Return the base VMA address which should be subtracted from real addresses
1817 when resolving @dtpoff relocation.
1818 This is PT_TLS segment p_vaddr. */
1822 struct bfd_link_info
*info
;
1824 /* If tls_segment is NULL, we should have signalled an error already. */
1825 if (elf_hash_table (info
)->tls_segment
== NULL
)
1827 return elf_hash_table (info
)->tls_segment
->start
;
1830 /* Return the relocation value for @tpoff relocation
1831 if STT_TLS virtual address is ADDRESS. */
1834 tpoff (info
, address
)
1835 struct bfd_link_info
*info
;
1838 struct elf_link_tls_segment
*tls_segment
1839 = elf_hash_table (info
)->tls_segment
;
1841 /* If tls_segment is NULL, we should have signalled an error already. */
1842 if (tls_segment
== NULL
)
1844 return address
- align_power (tls_segment
->size
, tls_segment
->align
)
1845 - tls_segment
->start
;
1848 /* Relocate an x86_64 ELF section. */
1851 elf64_x86_64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1852 contents
, relocs
, local_syms
, local_sections
)
1854 struct bfd_link_info
*info
;
1856 asection
*input_section
;
1858 Elf_Internal_Rela
*relocs
;
1859 Elf_Internal_Sym
*local_syms
;
1860 asection
**local_sections
;
1862 struct elf64_x86_64_link_hash_table
*htab
;
1863 Elf_Internal_Shdr
*symtab_hdr
;
1864 struct elf_link_hash_entry
**sym_hashes
;
1865 bfd_vma
*local_got_offsets
;
1866 Elf_Internal_Rela
*rel
;
1867 Elf_Internal_Rela
*relend
;
1869 if (info
->relocateable
)
1872 htab
= elf64_x86_64_hash_table (info
);
1873 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1874 sym_hashes
= elf_sym_hashes (input_bfd
);
1875 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1878 relend
= relocs
+ input_section
->reloc_count
;
1879 for (; rel
< relend
; rel
++)
1881 unsigned int r_type
;
1882 reloc_howto_type
*howto
;
1883 unsigned long r_symndx
;
1884 struct elf_link_hash_entry
*h
;
1885 Elf_Internal_Sym
*sym
;
1889 bfd_boolean unresolved_reloc
;
1890 bfd_reloc_status_type r
;
1893 r_type
= ELF64_R_TYPE (rel
->r_info
);
1894 if (r_type
== (int) R_X86_64_GNU_VTINHERIT
1895 || r_type
== (int) R_X86_64_GNU_VTENTRY
)
1898 if (r_type
>= R_X86_64_max
)
1900 bfd_set_error (bfd_error_bad_value
);
1904 howto
= x86_64_elf_howto_table
+ r_type
;
1905 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1909 unresolved_reloc
= FALSE
;
1910 if (r_symndx
< symtab_hdr
->sh_info
)
1912 sym
= local_syms
+ r_symndx
;
1913 sec
= local_sections
[r_symndx
];
1915 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1919 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1920 while (h
->root
.type
== bfd_link_hash_indirect
1921 || h
->root
.type
== bfd_link_hash_warning
)
1922 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1924 if (h
->root
.type
== bfd_link_hash_defined
1925 || h
->root
.type
== bfd_link_hash_defweak
)
1927 sec
= h
->root
.u
.def
.section
;
1928 if (sec
->output_section
== NULL
)
1930 /* Set a flag that will be cleared later if we find a
1931 relocation value for this symbol. output_section
1932 is typically NULL for symbols satisfied by a shared
1934 unresolved_reloc
= TRUE
;
1938 relocation
= (h
->root
.u
.def
.value
1939 + sec
->output_section
->vma
1940 + sec
->output_offset
);
1942 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1944 else if (info
->shared
1945 && !info
->no_undefined
1946 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1950 if (! ((*info
->callbacks
->undefined_symbol
)
1951 (info
, h
->root
.root
.string
, input_bfd
,
1952 input_section
, rel
->r_offset
,
1953 (!info
->shared
|| info
->no_undefined
1954 || ELF_ST_VISIBILITY (h
->other
)))))
1959 /* When generating a shared object, the relocations handled here are
1960 copied into the output file to be resolved at run time. */
1963 case R_X86_64_GOT32
:
1964 /* Relocation is to the entry for this symbol in the global
1966 case R_X86_64_GOTPCREL
:
1967 /* Use global offset table as symbol value. */
1968 if (htab
->sgot
== NULL
)
1975 off
= h
->got
.offset
;
1976 dyn
= htab
->elf
.dynamic_sections_created
;
1978 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
1982 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
1983 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1984 || (ELF_ST_VISIBILITY (h
->other
)
1985 && h
->root
.type
== bfd_link_hash_undefweak
))
1987 /* This is actually a static link, or it is a -Bsymbolic
1988 link and the symbol is defined locally, or the symbol
1989 was forced to be local because of a version file. We
1990 must initialize this entry in the global offset table.
1991 Since the offset must always be a multiple of 8, we
1992 use the least significant bit to record whether we
1993 have initialized it already.
1995 When doing a dynamic link, we create a .rela.got
1996 relocation entry to initialize the value. This is
1997 done in the finish_dynamic_symbol routine. */
2002 bfd_put_64 (output_bfd
, relocation
,
2003 htab
->sgot
->contents
+ off
);
2008 unresolved_reloc
= FALSE
;
2012 if (local_got_offsets
== NULL
)
2015 off
= local_got_offsets
[r_symndx
];
2017 /* The offset must always be a multiple of 8. We use
2018 the least significant bit to record whether we have
2019 already generated the necessary reloc. */
2024 bfd_put_64 (output_bfd
, relocation
,
2025 htab
->sgot
->contents
+ off
);
2030 Elf_Internal_Rela outrel
;
2033 /* We need to generate a R_X86_64_RELATIVE reloc
2034 for the dynamic linker. */
2039 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2040 + htab
->sgot
->output_offset
2042 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2043 outrel
.r_addend
= relocation
;
2045 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2046 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2049 local_got_offsets
[r_symndx
] |= 1;
2053 if (off
>= (bfd_vma
) -2)
2056 relocation
= htab
->sgot
->output_offset
+ off
;
2057 if (r_type
== R_X86_64_GOTPCREL
)
2058 relocation
+= htab
->sgot
->output_section
->vma
;
2062 case R_X86_64_PLT32
:
2063 /* Relocation is to the entry for this symbol in the
2064 procedure linkage table. */
2066 /* Resolve a PLT32 reloc against a local symbol directly,
2067 without using the procedure linkage table. */
2071 if (h
->plt
.offset
== (bfd_vma
) -1
2072 || htab
->splt
== NULL
)
2074 /* We didn't make a PLT entry for this symbol. This
2075 happens when statically linking PIC code, or when
2076 using -Bsymbolic. */
2080 relocation
= (htab
->splt
->output_section
->vma
2081 + htab
->splt
->output_offset
2083 unresolved_reloc
= FALSE
;
2093 /* FIXME: The ABI says the linker should make sure the value is
2094 the same when it's zeroextended to 64 bit. */
2096 /* r_symndx will be zero only for relocs against symbols
2097 from removed linkonce sections, or sections discarded by
2100 || (input_section
->flags
& SEC_ALLOC
) == 0)
2105 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2106 || h
->root
.type
!= bfd_link_hash_undefweak
)
2107 && ((r_type
!= R_X86_64_PC8
2108 && r_type
!= R_X86_64_PC16
2109 && r_type
!= R_X86_64_PC32
)
2112 && (! info
->symbolic
2113 || (h
->elf_link_hash_flags
2114 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2115 || (ELIMINATE_COPY_RELOCS
2119 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2120 && (((h
->elf_link_hash_flags
2121 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2122 && (h
->elf_link_hash_flags
2123 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2124 || h
->root
.type
== bfd_link_hash_undefweak
2125 || h
->root
.type
== bfd_link_hash_undefined
)))
2127 Elf_Internal_Rela outrel
;
2129 bfd_boolean skip
, relocate
;
2132 /* When generating a shared object, these relocations
2133 are copied into the output file to be resolved at run
2139 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2141 if (outrel
.r_offset
== (bfd_vma
) -1)
2143 else if (outrel
.r_offset
== (bfd_vma
) -2)
2144 skip
= TRUE
, relocate
= TRUE
;
2146 outrel
.r_offset
+= (input_section
->output_section
->vma
2147 + input_section
->output_offset
);
2150 memset (&outrel
, 0, sizeof outrel
);
2152 /* h->dynindx may be -1 if this symbol was marked to
2156 && (r_type
== R_X86_64_PC8
2157 || r_type
== R_X86_64_PC16
2158 || r_type
== R_X86_64_PC32
2161 || (h
->elf_link_hash_flags
2162 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2164 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
2165 outrel
.r_addend
= rel
->r_addend
;
2169 /* This symbol is local, or marked to become local. */
2170 if (r_type
== R_X86_64_64
)
2173 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2174 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2181 sec
= local_sections
[r_symndx
];
2184 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2186 == bfd_link_hash_defweak
));
2187 sec
= h
->root
.u
.def
.section
;
2189 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2191 else if (sec
== NULL
|| sec
->owner
== NULL
)
2193 bfd_set_error (bfd_error_bad_value
);
2200 osec
= sec
->output_section
;
2201 sindx
= elf_section_data (osec
)->dynindx
;
2202 BFD_ASSERT (sindx
> 0);
2205 outrel
.r_info
= ELF64_R_INFO (sindx
, r_type
);
2206 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2210 sreloc
= elf_section_data (input_section
)->sreloc
;
2214 loc
= sreloc
->contents
;
2215 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2216 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2218 /* If this reloc is against an external symbol, we do
2219 not want to fiddle with the addend. Otherwise, we
2220 need to include the symbol value so that it becomes
2221 an addend for the dynamic reloc. */
2228 case R_X86_64_TLSGD
:
2229 case R_X86_64_GOTTPOFF
:
2230 r_type
= elf64_x86_64_tls_transition (info
, r_type
, h
== NULL
);
2231 tls_type
= GOT_UNKNOWN
;
2232 if (h
== NULL
&& local_got_offsets
)
2233 tls_type
= elf64_x86_64_local_got_tls_type (input_bfd
) [r_symndx
];
2236 tls_type
= elf64_x86_64_hash_entry (h
)->tls_type
;
2237 if (!info
->shared
&& h
->dynindx
== -1 && tls_type
== GOT_TLS_IE
)
2238 r_type
= R_X86_64_TPOFF32
;
2240 if (r_type
== R_X86_64_TLSGD
)
2242 if (tls_type
== GOT_TLS_IE
)
2243 r_type
= R_X86_64_GOTTPOFF
;
2246 if (r_type
== R_X86_64_TPOFF32
)
2248 BFD_ASSERT (! unresolved_reloc
);
2249 if (ELF64_R_TYPE (rel
->r_info
) == R_X86_64_TLSGD
)
2252 static unsigned char tlsgd
[8]
2253 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
2255 /* GD->LE transition.
2256 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2257 .word 0x6666; rex64; call __tls_get_addr@plt
2260 leaq foo@tpoff(%rax), %rax */
2261 BFD_ASSERT (rel
->r_offset
>= 4);
2262 for (i
= 0; i
< 4; i
++)
2263 BFD_ASSERT (bfd_get_8 (input_bfd
,
2264 contents
+ rel
->r_offset
- 4 + i
)
2266 BFD_ASSERT (rel
->r_offset
+ 12 <= input_section
->_raw_size
);
2267 for (i
= 0; i
< 4; i
++)
2268 BFD_ASSERT (bfd_get_8 (input_bfd
,
2269 contents
+ rel
->r_offset
+ 4 + i
)
2271 BFD_ASSERT (rel
+ 1 < relend
);
2272 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2273 memcpy (contents
+ rel
->r_offset
- 4,
2274 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0",
2276 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2277 contents
+ rel
->r_offset
+ 8);
2278 /* Skip R_X86_64_PLT32. */
2284 unsigned int val
, type
, reg
;
2286 /* IE->LE transition:
2287 Originally it can be one of:
2288 movq foo@gottpoff(%rip), %reg
2289 addq foo@gottpoff(%rip), %reg
2292 leaq foo(%reg), %reg
2294 BFD_ASSERT (rel
->r_offset
>= 3);
2295 val
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 3);
2296 BFD_ASSERT (val
== 0x48 || val
== 0x4c);
2297 type
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2);
2298 BFD_ASSERT (type
== 0x8b || type
== 0x03);
2299 reg
= bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1);
2300 BFD_ASSERT ((reg
& 0xc7) == 5);
2302 BFD_ASSERT (rel
->r_offset
+ 4 <= input_section
->_raw_size
);
2307 bfd_put_8 (output_bfd
, 0x49,
2308 contents
+ rel
->r_offset
- 3);
2309 bfd_put_8 (output_bfd
, 0xc7,
2310 contents
+ rel
->r_offset
- 2);
2311 bfd_put_8 (output_bfd
, 0xc0 | reg
,
2312 contents
+ rel
->r_offset
- 1);
2316 /* addq -> addq - addressing with %rsp/%r12 is
2319 bfd_put_8 (output_bfd
, 0x49,
2320 contents
+ rel
->r_offset
- 3);
2321 bfd_put_8 (output_bfd
, 0x81,
2322 contents
+ rel
->r_offset
- 2);
2323 bfd_put_8 (output_bfd
, 0xc0 | reg
,
2324 contents
+ rel
->r_offset
- 1);
2330 bfd_put_8 (output_bfd
, 0x4d,
2331 contents
+ rel
->r_offset
- 3);
2332 bfd_put_8 (output_bfd
, 0x8d,
2333 contents
+ rel
->r_offset
- 2);
2334 bfd_put_8 (output_bfd
, 0x80 | reg
| (reg
<< 3),
2335 contents
+ rel
->r_offset
- 1);
2337 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
2338 contents
+ rel
->r_offset
);
2343 if (htab
->sgot
== NULL
)
2347 off
= h
->got
.offset
;
2350 if (local_got_offsets
== NULL
)
2353 off
= local_got_offsets
[r_symndx
];
2360 Elf_Internal_Rela outrel
;
2364 if (htab
->srelgot
== NULL
)
2367 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2368 + htab
->sgot
->output_offset
+ off
);
2370 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
2371 if (r_type
== R_X86_64_TLSGD
)
2372 dr_type
= R_X86_64_DTPMOD64
;
2374 dr_type
= R_X86_64_TPOFF64
;
2376 bfd_put_64 (output_bfd
, 0, htab
->sgot
->contents
+ off
);
2377 outrel
.r_addend
= 0;
2378 if (dr_type
== R_X86_64_TPOFF64
&& indx
== 0)
2379 outrel
.r_addend
= relocation
- dtpoff_base (info
);
2380 outrel
.r_info
= ELF64_R_INFO (indx
, dr_type
);
2382 loc
= htab
->srelgot
->contents
;
2383 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2384 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2386 if (r_type
== R_X86_64_TLSGD
)
2390 BFD_ASSERT (! unresolved_reloc
);
2391 bfd_put_64 (output_bfd
,
2392 relocation
- dtpoff_base (info
),
2393 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2397 bfd_put_64 (output_bfd
, 0,
2398 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2399 outrel
.r_info
= ELF64_R_INFO (indx
,
2401 outrel
.r_offset
+= GOT_ENTRY_SIZE
;
2402 htab
->srelgot
->reloc_count
++;
2403 loc
+= sizeof (Elf64_External_Rela
);
2404 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2411 local_got_offsets
[r_symndx
] |= 1;
2414 if (off
>= (bfd_vma
) -2)
2416 if (r_type
== ELF64_R_TYPE (rel
->r_info
))
2418 relocation
= htab
->sgot
->output_section
->vma
2419 + htab
->sgot
->output_offset
+ off
;
2420 unresolved_reloc
= FALSE
;
2425 static unsigned char tlsgd
[8]
2426 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 };
2428 /* GD->IE transition.
2429 .byte 0x66; leaq foo@tlsgd(%rip), %rdi
2430 .word 0x6666; rex64; call __tls_get_addr@plt
2433 addq foo@gottpoff(%rip), %rax */
2434 BFD_ASSERT (rel
->r_offset
>= 4);
2435 for (i
= 0; i
< 4; i
++)
2436 BFD_ASSERT (bfd_get_8 (input_bfd
,
2437 contents
+ rel
->r_offset
- 4 + i
)
2439 BFD_ASSERT (rel
->r_offset
+ 12 <= input_section
->_raw_size
);
2440 for (i
= 0; i
< 4; i
++)
2441 BFD_ASSERT (bfd_get_8 (input_bfd
,
2442 contents
+ rel
->r_offset
+ 4 + i
)
2444 BFD_ASSERT (rel
+ 1 < relend
);
2445 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2446 memcpy (contents
+ rel
->r_offset
- 4,
2447 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0",
2450 relocation
= (htab
->sgot
->output_section
->vma
2451 + htab
->sgot
->output_offset
+ off
2453 - input_section
->output_section
->vma
2454 - input_section
->output_offset
2456 bfd_put_32 (output_bfd
, relocation
,
2457 contents
+ rel
->r_offset
+ 8);
2458 /* Skip R_X86_64_PLT32. */
2464 case R_X86_64_TLSLD
:
2467 /* LD->LE transition:
2469 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr@plt.
2471 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */
2472 BFD_ASSERT (rel
->r_offset
>= 3);
2473 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 3)
2475 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 2)
2477 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
- 1)
2479 BFD_ASSERT (rel
->r_offset
+ 9 <= input_section
->_raw_size
);
2480 BFD_ASSERT (bfd_get_8 (input_bfd
, contents
+ rel
->r_offset
+ 4)
2482 BFD_ASSERT (rel
+ 1 < relend
);
2483 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_X86_64_PLT32
);
2484 memcpy (contents
+ rel
->r_offset
- 3,
2485 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12);
2486 /* Skip R_X86_64_PLT32. */
2491 if (htab
->sgot
== NULL
)
2494 off
= htab
->tls_ld_got
.offset
;
2499 Elf_Internal_Rela outrel
;
2502 if (htab
->srelgot
== NULL
)
2505 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
2506 + htab
->sgot
->output_offset
+ off
);
2508 bfd_put_64 (output_bfd
, 0,
2509 htab
->sgot
->contents
+ off
);
2510 bfd_put_64 (output_bfd
, 0,
2511 htab
->sgot
->contents
+ off
+ GOT_ENTRY_SIZE
);
2512 outrel
.r_info
= ELF64_R_INFO (0, R_X86_64_DTPMOD64
);
2513 outrel
.r_addend
= 0;
2514 loc
= htab
->srelgot
->contents
;
2515 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2516 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2517 htab
->tls_ld_got
.offset
|= 1;
2519 relocation
= htab
->sgot
->output_section
->vma
2520 + htab
->sgot
->output_offset
+ off
;
2521 unresolved_reloc
= FALSE
;
2524 case R_X86_64_DTPOFF32
:
2525 if (info
->shared
|| (input_section
->flags
& SEC_CODE
) == 0)
2526 relocation
-= dtpoff_base (info
);
2528 relocation
= tpoff (info
, relocation
);
2531 case R_X86_64_TPOFF32
:
2532 BFD_ASSERT (! info
->shared
);
2533 relocation
= tpoff (info
, relocation
);
2540 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
2541 because such sections are not SEC_ALLOC and thus ld.so will
2542 not process them. */
2543 if (unresolved_reloc
2544 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
2545 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2546 (*_bfd_error_handler
)
2547 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
2548 bfd_archive_filename (input_bfd
),
2549 bfd_get_section_name (input_bfd
, input_section
),
2550 (long) rel
->r_offset
,
2551 h
->root
.root
.string
);
2553 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2554 contents
, rel
->r_offset
,
2555 relocation
, rel
->r_addend
);
2557 if (r
!= bfd_reloc_ok
)
2562 name
= h
->root
.root
.string
;
2565 name
= bfd_elf_string_from_elf_section (input_bfd
,
2566 symtab_hdr
->sh_link
,
2571 name
= bfd_section_name (input_bfd
, sec
);
2574 if (r
== bfd_reloc_overflow
)
2577 if (! ((*info
->callbacks
->reloc_overflow
)
2578 (info
, name
, howto
->name
, (bfd_vma
) 0,
2579 input_bfd
, input_section
, rel
->r_offset
)))
2584 (*_bfd_error_handler
)
2585 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
2586 bfd_archive_filename (input_bfd
),
2587 bfd_get_section_name (input_bfd
, input_section
),
2588 (long) rel
->r_offset
, name
, (int) r
);
2597 /* Finish up dynamic symbol handling. We set the contents of various
2598 dynamic sections here. */
2601 elf64_x86_64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2603 struct bfd_link_info
*info
;
2604 struct elf_link_hash_entry
*h
;
2605 Elf_Internal_Sym
*sym
;
2607 struct elf64_x86_64_link_hash_table
*htab
;
2609 htab
= elf64_x86_64_hash_table (info
);
2611 if (h
->plt
.offset
!= (bfd_vma
) -1)
2615 Elf_Internal_Rela rela
;
2618 /* This symbol has an entry in the procedure linkage table. Set
2620 if (h
->dynindx
== -1
2621 || htab
->splt
== NULL
2622 || htab
->sgotplt
== NULL
2623 || htab
->srelplt
== NULL
)
2626 /* Get the index in the procedure linkage table which
2627 corresponds to this symbol. This is the index of this symbol
2628 in all the symbols for which we are making plt entries. The
2629 first entry in the procedure linkage table is reserved. */
2630 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2632 /* Get the offset into the .got table of the entry that
2633 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
2634 bytes. The first three are reserved for the dynamic linker. */
2635 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
2637 /* Fill in the entry in the procedure linkage table. */
2638 memcpy (htab
->splt
->contents
+ h
->plt
.offset
, elf64_x86_64_plt_entry
,
2641 /* Insert the relocation positions of the plt section. The magic
2642 numbers at the end of the statements are the positions of the
2643 relocations in the plt section. */
2644 /* Put offset for jmp *name@GOTPCREL(%rip), since the
2645 instruction uses 6 bytes, subtract this value. */
2646 bfd_put_32 (output_bfd
,
2647 (htab
->sgotplt
->output_section
->vma
2648 + htab
->sgotplt
->output_offset
2650 - htab
->splt
->output_section
->vma
2651 - htab
->splt
->output_offset
2654 htab
->splt
->contents
+ h
->plt
.offset
+ 2);
2655 /* Put relocation index. */
2656 bfd_put_32 (output_bfd
, plt_index
,
2657 htab
->splt
->contents
+ h
->plt
.offset
+ 7);
2658 /* Put offset for jmp .PLT0. */
2659 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ PLT_ENTRY_SIZE
),
2660 htab
->splt
->contents
+ h
->plt
.offset
+ 12);
2662 /* Fill in the entry in the global offset table, initially this
2663 points to the pushq instruction in the PLT which is at offset 6. */
2664 bfd_put_64 (output_bfd
, (htab
->splt
->output_section
->vma
2665 + htab
->splt
->output_offset
2666 + h
->plt
.offset
+ 6),
2667 htab
->sgotplt
->contents
+ got_offset
);
2669 /* Fill in the entry in the .rela.plt section. */
2670 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
2671 + htab
->sgotplt
->output_offset
2673 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_JUMP_SLOT
);
2675 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
2676 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2678 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2680 /* Mark the symbol as undefined, rather than as defined in
2681 the .plt section. Leave the value alone. This is a clue
2682 for the dynamic linker, to make function pointer
2683 comparisons work between an application and shared
2685 sym
->st_shndx
= SHN_UNDEF
;
2689 if (h
->got
.offset
!= (bfd_vma
) -1
2690 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_GD
2691 && elf64_x86_64_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
2693 Elf_Internal_Rela rela
;
2696 /* This symbol has an entry in the global offset table. Set it
2698 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
2701 rela
.r_offset
= (htab
->sgot
->output_section
->vma
2702 + htab
->sgot
->output_offset
2703 + (h
->got
.offset
&~ (bfd_vma
) 1));
2705 /* If this is a static link, or it is a -Bsymbolic link and the
2706 symbol is defined locally or was forced to be local because
2707 of a version file, we just want to emit a RELATIVE reloc.
2708 The entry in the global offset table will already have been
2709 initialized in the relocate_section function. */
2713 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
2714 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2716 BFD_ASSERT((h
->got
.offset
& 1) != 0);
2717 rela
.r_info
= ELF64_R_INFO (0, R_X86_64_RELATIVE
);
2718 rela
.r_addend
= (h
->root
.u
.def
.value
2719 + h
->root
.u
.def
.section
->output_section
->vma
2720 + h
->root
.u
.def
.section
->output_offset
);
2724 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2725 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2726 htab
->sgot
->contents
+ h
->got
.offset
);
2727 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_GLOB_DAT
);
2731 loc
= htab
->srelgot
->contents
;
2732 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2733 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2736 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2738 Elf_Internal_Rela rela
;
2741 /* This symbol needs a copy reloc. Set it up. */
2743 if (h
->dynindx
== -1
2744 || (h
->root
.type
!= bfd_link_hash_defined
2745 && h
->root
.type
!= bfd_link_hash_defweak
)
2746 || htab
->srelbss
== NULL
)
2749 rela
.r_offset
= (h
->root
.u
.def
.value
2750 + h
->root
.u
.def
.section
->output_section
->vma
2751 + h
->root
.u
.def
.section
->output_offset
);
2752 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_X86_64_COPY
);
2754 loc
= htab
->srelbss
->contents
;
2755 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2756 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
2759 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2760 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2761 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2762 sym
->st_shndx
= SHN_ABS
;
2767 /* Used to decide how to sort relocs in an optimal manner for the
2768 dynamic linker, before writing them out. */
2770 static enum elf_reloc_type_class
2771 elf64_x86_64_reloc_type_class (rela
)
2772 const Elf_Internal_Rela
*rela
;
2774 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2776 case R_X86_64_RELATIVE
:
2777 return reloc_class_relative
;
2778 case R_X86_64_JUMP_SLOT
:
2779 return reloc_class_plt
;
2781 return reloc_class_copy
;
2783 return reloc_class_normal
;
2787 /* Finish up the dynamic sections. */
2790 elf64_x86_64_finish_dynamic_sections (output_bfd
, info
)
2792 struct bfd_link_info
*info
;
2794 struct elf64_x86_64_link_hash_table
*htab
;
2798 htab
= elf64_x86_64_hash_table (info
);
2799 dynobj
= htab
->elf
.dynobj
;
2800 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2802 if (htab
->elf
.dynamic_sections_created
)
2804 Elf64_External_Dyn
*dyncon
, *dynconend
;
2806 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
2809 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2810 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2811 for (; dyncon
< dynconend
; dyncon
++)
2813 Elf_Internal_Dyn dyn
;
2816 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2824 dyn
.d_un
.d_ptr
= htab
->sgot
->output_section
->vma
;
2828 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
2832 s
= htab
->srelplt
->output_section
;
2833 if (s
->_cooked_size
!= 0)
2834 dyn
.d_un
.d_val
= s
->_cooked_size
;
2836 dyn
.d_un
.d_val
= s
->_raw_size
;
2840 /* The procedure linkage table relocs (DT_JMPREL) should
2841 not be included in the overall relocs (DT_RELA).
2842 Therefore, we override the DT_RELASZ entry here to
2843 make it not include the JMPREL relocs. Since the
2844 linker script arranges for .rela.plt to follow all
2845 other relocation sections, we don't have to worry
2846 about changing the DT_RELA entry. */
2847 if (htab
->srelplt
!= NULL
)
2849 s
= htab
->srelplt
->output_section
;
2850 if (s
->_cooked_size
!= 0)
2851 dyn
.d_un
.d_val
-= s
->_cooked_size
;
2853 dyn
.d_un
.d_val
-= s
->_raw_size
;
2858 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2861 /* Fill in the special first entry in the procedure linkage table. */
2862 if (htab
->splt
&& htab
->splt
->_raw_size
> 0)
2864 /* Fill in the first entry in the procedure linkage table. */
2865 memcpy (htab
->splt
->contents
, elf64_x86_64_plt0_entry
,
2867 /* Add offset for pushq GOT+8(%rip), since the instruction
2868 uses 6 bytes subtract this value. */
2869 bfd_put_32 (output_bfd
,
2870 (htab
->sgotplt
->output_section
->vma
2871 + htab
->sgotplt
->output_offset
2873 - htab
->splt
->output_section
->vma
2874 - htab
->splt
->output_offset
2876 htab
->splt
->contents
+ 2);
2877 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
2878 the end of the instruction. */
2879 bfd_put_32 (output_bfd
,
2880 (htab
->sgotplt
->output_section
->vma
2881 + htab
->sgotplt
->output_offset
2883 - htab
->splt
->output_section
->vma
2884 - htab
->splt
->output_offset
2886 htab
->splt
->contents
+ 8);
2888 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
=
2895 /* Fill in the first three entries in the global offset table. */
2896 if (htab
->sgotplt
->_raw_size
> 0)
2898 /* Set the first entry in the global offset table to the address of
2899 the dynamic section. */
2901 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
);
2903 bfd_put_64 (output_bfd
,
2904 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2905 htab
->sgotplt
->contents
);
2906 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
2907 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
);
2908 bfd_put_64 (output_bfd
, (bfd_vma
) 0, htab
->sgotplt
->contents
+ GOT_ENTRY_SIZE
*2);
2911 elf_section_data (htab
->sgotplt
->output_section
)->this_hdr
.sh_entsize
=
2919 #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
2920 #define TARGET_LITTLE_NAME "elf64-x86-64"
2921 #define ELF_ARCH bfd_arch_i386
2922 #define ELF_MACHINE_CODE EM_X86_64
2923 #define ELF_MAXPAGESIZE 0x100000
2925 #define elf_backend_can_gc_sections 1
2926 #define elf_backend_can_refcount 1
2927 #define elf_backend_want_got_plt 1
2928 #define elf_backend_plt_readonly 1
2929 #define elf_backend_want_plt_sym 0
2930 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
2931 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
2932 #define elf_backend_rela_normal 1
2934 #define elf_info_to_howto elf64_x86_64_info_to_howto
2936 #define bfd_elf64_bfd_link_hash_table_create \
2937 elf64_x86_64_link_hash_table_create
2938 #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
2940 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
2941 #define elf_backend_check_relocs elf64_x86_64_check_relocs
2942 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
2943 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
2944 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
2945 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
2946 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
2947 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
2948 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus
2949 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo
2950 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
2951 #define elf_backend_relocate_section elf64_x86_64_relocate_section
2952 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
2953 #define elf_backend_object_p elf64_x86_64_elf_object_p
2954 #define bfd_elf64_mkobject elf64_x86_64_mkobject
2956 #include "elf64-target.h"