* elf-bfd.h (struct elf_backend_data): Add rela_normal.
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
CommitLineData
8d88c4ca 1/* X86-64 specific support for 64-bit ELF
c434dee6 2 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
8d88c4ca
NC
3 Contributed by Jan Hubicka <jh@suse.cz>.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "bfd.h"
22#include "sysdep.h"
c434dee6 23#include "bfdlink.h"
8d88c4ca
NC
24#include "libbfd.h"
25#include "elf-bfd.h"
26
27#include "elf/x86-64.h"
28
29/* We use only the RELA entries. */
c434dee6 30#define USE_RELA 1
8d88c4ca
NC
31
32/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
33#define MINUS_ONE (~ (bfd_vma) 0)
34
35/* The relocation "howto" table. Order of fields:
407443a3
AJ
36 type, size, bitsize, pc_relative, complain_on_overflow,
37 special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
70256ad8
AJ
38static reloc_howto_type x86_64_elf_howto_table[] =
39{
407443a3 40 HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont,
fe4770f4
AJ
41 bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0x00000000, 0x00000000,
42 false),
407443a3 43 HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
fe4770f4
AJ
44 bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE,
45 false),
407443a3 46 HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed,
fe4770f4
AJ
47 bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff,
48 true),
407443a3 49 HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed,
fe4770f4
AJ
50 bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff,
51 false),
407443a3 52 HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed,
fe4770f4
AJ
53 bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff,
54 true),
407443a3 55 HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield,
fe4770f4
AJ
56 bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff,
57 false),
407443a3 58 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
fe4770f4
AJ
59 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE,
60 MINUS_ONE, false),
407443a3 61 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
fe4770f4
AJ
62 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE,
63 MINUS_ONE, false),
4a73f21b 64 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
fe4770f4
AJ
65 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE,
66 MINUS_ONE, false),
407443a3 67 HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true,0 , complain_overflow_signed,
fe4770f4
AJ
68 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0xffffffff,
69 0xffffffff, true),
407443a3 70 HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned,
fe4770f4
AJ
71 bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
72 false),
407443a3 73 HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed,
fe4770f4
AJ
74 bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff,
75 false),
407443a3
AJ
76 HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
77 bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false),
78 HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield,
79 bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true),
80 HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_signed,
81 bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),
82 HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
fe4770f4
AJ
83 bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true),
84
85/* GNU extension to record C++ vtable hierarchy. */
86 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, false, 0, complain_overflow_dont,
87 NULL, "R_X86_64_GNU_VTINHERIT", false, 0, 0, false),
88
89/* GNU extension to record C++ vtable member usage. */
90 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, false, 0, complain_overflow_dont,
91 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", false, 0, 0,
92 false)
8d88c4ca
NC
93};
94
95/* Map BFD relocs to the x86_64 elf relocs. */
70256ad8
AJ
96struct elf_reloc_map
97{
8d88c4ca
NC
98 bfd_reloc_code_real_type bfd_reloc_val;
99 unsigned char elf_reloc_val;
100};
101
dc810e39 102static const struct elf_reloc_map x86_64_reloc_map[] =
8d88c4ca 103{
70256ad8
AJ
104 { BFD_RELOC_NONE, R_X86_64_NONE, },
105 { BFD_RELOC_64, R_X86_64_64, },
106 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
107 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
108 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
109 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
110 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
111 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
112 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
113 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
114 { BFD_RELOC_32, R_X86_64_32, },
115 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
116 { BFD_RELOC_16, R_X86_64_16, },
117 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
118 { BFD_RELOC_8, R_X86_64_8, },
119 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
fe4770f4
AJ
120 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, },
121 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, },
8d88c4ca
NC
122};
123
8d88c4ca
NC
124static reloc_howto_type *elf64_x86_64_reloc_type_lookup
125 PARAMS ((bfd *, bfd_reloc_code_real_type));
126static void elf64_x86_64_info_to_howto
127 PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
128static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create
129 PARAMS ((bfd *));
1e1b3bc2 130static boolean elf64_x86_64_elf_object_p PARAMS ((bfd *abfd));
c434dee6
AJ
131static boolean create_got_section
132 PARAMS((bfd *, struct bfd_link_info *));
133static boolean elf64_x86_64_create_dynamic_sections
134 PARAMS((bfd *, struct bfd_link_info *));
135static void elf64_x86_64_copy_indirect_symbol
136 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
1e1b3bc2
AJ
137static boolean elf64_x86_64_check_relocs
138 PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
139 const Elf_Internal_Rela *));
140static asection *elf64_x86_64_gc_mark_hook
141 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
142 struct elf_link_hash_entry *, Elf_Internal_Sym *));
143
144static boolean elf64_x86_64_gc_sweep_hook
145 PARAMS ((bfd *, struct bfd_link_info *, asection *,
146 const Elf_Internal_Rela *));
70256ad8 147
c434dee6 148static struct bfd_hash_entry *link_hash_newfunc
70256ad8
AJ
149 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
150static boolean elf64_x86_64_adjust_dynamic_symbol
151 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
152
c434dee6
AJ
153static boolean allocate_dynrelocs
154 PARAMS ((struct elf_link_hash_entry *, PTR));
155static boolean readonly_dynrelocs
156 PARAMS ((struct elf_link_hash_entry *, PTR));
70256ad8
AJ
157static boolean elf64_x86_64_size_dynamic_sections
158 PARAMS ((bfd *, struct bfd_link_info *));
8d88c4ca
NC
159static boolean elf64_x86_64_relocate_section
160 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
407443a3 161 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
70256ad8
AJ
162static boolean elf64_x86_64_finish_dynamic_symbol
163 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
164 Elf_Internal_Sym *sym));
165static boolean elf64_x86_64_finish_dynamic_sections
166 PARAMS ((bfd *, struct bfd_link_info *));
f51e552e
AM
167static enum elf_reloc_type_class elf64_x86_64_reloc_type_class
168 PARAMS ((const Elf_Internal_Rela *));
8d88c4ca
NC
169
170/* Given a BFD reloc type, return a HOWTO structure. */
171static reloc_howto_type *
172elf64_x86_64_reloc_type_lookup (abfd, code)
173 bfd *abfd ATTRIBUTE_UNUSED;
174 bfd_reloc_code_real_type code;
175{
176 unsigned int i;
177 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
178 i++)
179 {
180 if (x86_64_reloc_map[i].bfd_reloc_val == code)
ffaef159 181 return &x86_64_elf_howto_table[i];
8d88c4ca
NC
182 }
183 return 0;
184}
185
8d88c4ca 186/* Given an x86_64 ELF reloc type, fill in an arelent structure. */
8da6118f 187
8d88c4ca
NC
188static void
189elf64_x86_64_info_to_howto (abfd, cache_ptr, dst)
190 bfd *abfd ATTRIBUTE_UNUSED;
191 arelent *cache_ptr;
192 Elf64_Internal_Rela *dst;
193{
fe4770f4 194 unsigned r_type, i;
8d88c4ca
NC
195
196 r_type = ELF64_R_TYPE (dst->r_info);
fe4770f4
AJ
197 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT)
198 {
199 BFD_ASSERT (r_type <= (unsigned int) R_X86_64_PC8);
200 i = r_type;
201 }
202 else
203 {
204 BFD_ASSERT (r_type < (unsigned int) R_X86_64_max);
205 i = r_type - ((unsigned int) R_X86_64_GNU_VTINHERIT - R_X86_64_PC8 - 1);
206 }
207 cache_ptr->howto = &x86_64_elf_howto_table[i];
8d88c4ca
NC
208 BFD_ASSERT (r_type == cache_ptr->howto->type);
209}
70256ad8 210\f
407443a3 211/* Functions for the x86-64 ELF linker. */
70256ad8 212
407443a3 213/* The name of the dynamic interpreter. This is put in the .interp
70256ad8
AJ
214 section. */
215
407443a3 216#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
70256ad8
AJ
217
218/* The size in bytes of an entry in the global offset table. */
219
220#define GOT_ENTRY_SIZE 8
8d88c4ca 221
70256ad8 222/* The size in bytes of an entry in the procedure linkage table. */
8d88c4ca 223
70256ad8
AJ
224#define PLT_ENTRY_SIZE 16
225
226/* The first entry in a procedure linkage table looks like this. See the
227 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
228
229static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
230{
653165cc
AJ
231 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
232 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
233 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
70256ad8
AJ
234};
235
236/* Subsequent entries in a procedure linkage table look like this. */
237
238static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
239{
653165cc 240 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
407443a3 241 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
653165cc 242 0x68, /* pushq immediate */
70256ad8
AJ
243 0, 0, 0, 0, /* replaced with index into relocation table. */
244 0xe9, /* jmp relative */
245 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
246};
247
248/* The x86-64 linker needs to keep track of the number of relocs that
985142a4 249 it decides to copy as dynamic relocs in check_relocs for each symbol.
c434dee6
AJ
250 This is so that it can later discard them if they are found to be
251 unnecessary. We store the information in a field extending the
252 regular ELF linker hash table. */
70256ad8 253
c434dee6 254struct elf64_x86_64_dyn_relocs
70256ad8
AJ
255{
256 /* Next section. */
c434dee6
AJ
257 struct elf64_x86_64_dyn_relocs *next;
258
259 /* The input section of the reloc. */
260 asection *sec;
261
262 /* Total number of relocs copied for the input section. */
70256ad8 263 bfd_size_type count;
c434dee6
AJ
264
265 /* Number of pc-relative relocs copied for the input section. */
266 bfd_size_type pc_count;
70256ad8
AJ
267};
268
269/* x86-64 ELF linker hash entry. */
270
271struct elf64_x86_64_link_hash_entry
272{
c434dee6 273 struct elf_link_hash_entry elf;
70256ad8 274
c434dee6
AJ
275 /* Track dynamic relocs copied for this symbol. */
276 struct elf64_x86_64_dyn_relocs *dyn_relocs;
70256ad8
AJ
277};
278
c434dee6 279/* x86-64 ELF linker hash table. */
8d88c4ca 280
407443a3
AJ
281struct elf64_x86_64_link_hash_table
282{
c434dee6 283 struct elf_link_hash_table elf;
70256ad8 284
c434dee6
AJ
285 /* Short-cuts to get to dynamic linker sections. */
286 asection *sgot;
287 asection *sgotplt;
288 asection *srelgot;
289 asection *splt;
290 asection *srelplt;
291 asection *sdynbss;
292 asection *srelbss;
70256ad8 293
c434dee6
AJ
294 /* Small local sym to section mapping cache. */
295 struct sym_sec_cache sym_sec;
296};
70256ad8
AJ
297
298/* Get the x86-64 ELF linker hash table from a link_info structure. */
8d88c4ca
NC
299
300#define elf64_x86_64_hash_table(p) \
301 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
302
407443a3 303/* Create an entry in an x86-64 ELF linker hash table. */
70256ad8
AJ
304
305static struct bfd_hash_entry *
c434dee6 306link_hash_newfunc (entry, table, string)
70256ad8
AJ
307 struct bfd_hash_entry *entry;
308 struct bfd_hash_table *table;
309 const char *string;
310{
70256ad8 311 /* Allocate the structure if it has not already been allocated by a
c434dee6
AJ
312 subclass. */
313 if (entry == NULL)
314 {
315 entry = bfd_hash_allocate (table,
316 sizeof (struct elf64_x86_64_link_hash_entry));
317 if (entry == NULL)
318 return entry;
319 }
70256ad8
AJ
320
321 /* Call the allocation method of the superclass. */
c434dee6
AJ
322 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
323 if (entry != NULL)
70256ad8 324 {
c434dee6
AJ
325 struct elf64_x86_64_link_hash_entry *eh;
326
327 eh = (struct elf64_x86_64_link_hash_entry *) entry;
328 eh->dyn_relocs = NULL;
70256ad8
AJ
329 }
330
c434dee6 331 return entry;
70256ad8
AJ
332}
333
8d88c4ca
NC
334/* Create an X86-64 ELF linker hash table. */
335
336static struct bfd_link_hash_table *
337elf64_x86_64_link_hash_table_create (abfd)
338 bfd *abfd;
339{
340 struct elf64_x86_64_link_hash_table *ret;
dc810e39 341 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
8d88c4ca 342
e2d34d7d 343 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt);
c434dee6 344 if (ret == NULL)
8d88c4ca
NC
345 return NULL;
346
c434dee6 347 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
8d88c4ca 348 {
e2d34d7d 349 free (ret);
8d88c4ca
NC
350 return NULL;
351 }
352
c434dee6
AJ
353 ret->sgot = NULL;
354 ret->sgotplt = NULL;
355 ret->srelgot = NULL;
356 ret->splt = NULL;
357 ret->srelplt = NULL;
358 ret->sdynbss = NULL;
359 ret->srelbss = NULL;
360 ret->sym_sec.abfd = NULL;
361
362 return &ret->elf.root;
363}
364
365/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
366 shortcuts to them in our hash table. */
367
368static boolean
369create_got_section (dynobj, info)
370 bfd *dynobj;
371 struct bfd_link_info *info;
372{
373 struct elf64_x86_64_link_hash_table *htab;
374
375 if (! _bfd_elf_create_got_section (dynobj, info))
376 return false;
377
378 htab = elf64_x86_64_hash_table (info);
379 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
380 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
381 if (!htab->sgot || !htab->sgotplt)
382 abort ();
383
384 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
385 if (htab->srelgot == NULL
386 || ! bfd_set_section_flags (dynobj, htab->srelgot,
387 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
388 | SEC_IN_MEMORY | SEC_LINKER_CREATED
389 | SEC_READONLY))
390 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
391 return false;
392 return true;
393}
394
395/* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
396 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
397 hash table. */
398
399static boolean
400elf64_x86_64_create_dynamic_sections (dynobj, info)
401 bfd *dynobj;
402 struct bfd_link_info *info;
403{
404 struct elf64_x86_64_link_hash_table *htab;
405
406 htab = elf64_x86_64_hash_table (info);
407 if (!htab->sgot && !create_got_section (dynobj, info))
408 return false;
409
410 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
411 return false;
412
413 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
414 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
415 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
416 if (!info->shared)
417 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
418
419 if (!htab->splt || !htab->srelplt || !htab->sdynbss
420 || (!info->shared && !htab->srelbss))
421 abort ();
422
423 return true;
424}
425
426/* Copy the extra info we tack onto an elf_link_hash_entry. */
427
428static void
429elf64_x86_64_copy_indirect_symbol (dir, ind)
430 struct elf_link_hash_entry *dir, *ind;
431{
432 struct elf64_x86_64_link_hash_entry *edir, *eind;
433
434 edir = (struct elf64_x86_64_link_hash_entry *) dir;
435 eind = (struct elf64_x86_64_link_hash_entry *) ind;
436
437 if (eind->dyn_relocs != NULL)
438 {
439 if (edir->dyn_relocs != NULL)
440 {
441 struct elf64_x86_64_dyn_relocs **pp;
442 struct elf64_x86_64_dyn_relocs *p;
443
444 if (ind->root.type == bfd_link_hash_indirect)
445 abort ();
446
447 /* Add reloc counts against the weak sym to the strong sym
448 list. Merge any entries against the same section. */
449 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
450 {
451 struct elf64_x86_64_dyn_relocs *q;
452
453 for (q = edir->dyn_relocs; q != NULL; q = q->next)
454 if (q->sec == p->sec)
455 {
456 q->pc_count += p->pc_count;
457 q->count += p->count;
458 *pp = p->next;
459 break;
460 }
461 if (q == NULL)
462 pp = &p->next;
463 }
464 *pp = edir->dyn_relocs;
465 }
466
467 edir->dyn_relocs = eind->dyn_relocs;
468 eind->dyn_relocs = NULL;
469 }
470
471 _bfd_elf_link_hash_copy_indirect (dir, ind);
8d88c4ca
NC
472}
473
1e1b3bc2 474static boolean
8d88c4ca
NC
475elf64_x86_64_elf_object_p (abfd)
476 bfd *abfd;
477{
478 /* Set the right machine number for an x86-64 elf64 file. */
479 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
480 return true;
481}
482
70256ad8 483/* Look through the relocs for a section during the first phase, and
c434dee6
AJ
484 calculate needed space in the global offset table, procedure
485 linkage table, and dynamic reloc sections. */
70256ad8
AJ
486
487static boolean
488elf64_x86_64_check_relocs (abfd, info, sec, relocs)
489 bfd *abfd;
490 struct bfd_link_info *info;
491 asection *sec;
492 const Elf_Internal_Rela *relocs;
493{
c434dee6 494 struct elf64_x86_64_link_hash_table *htab;
70256ad8
AJ
495 Elf_Internal_Shdr *symtab_hdr;
496 struct elf_link_hash_entry **sym_hashes;
70256ad8
AJ
497 const Elf_Internal_Rela *rel;
498 const Elf_Internal_Rela *rel_end;
70256ad8
AJ
499 asection *sreloc;
500
501 if (info->relocateable)
502 return true;
503
c434dee6 504 htab = elf64_x86_64_hash_table (info);
70256ad8
AJ
505 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
506 sym_hashes = elf_sym_hashes (abfd);
70256ad8 507
c434dee6
AJ
508 sreloc = NULL;
509
70256ad8
AJ
510 rel_end = relocs + sec->reloc_count;
511 for (rel = relocs; rel < rel_end; rel++)
512 {
513 unsigned long r_symndx;
514 struct elf_link_hash_entry *h;
515
516 r_symndx = ELF64_R_SYM (rel->r_info);
c434dee6
AJ
517
518 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
519 {
520 (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
521 bfd_archive_filename (abfd),
522 r_symndx);
523 return false;
524 }
525
70256ad8
AJ
526 if (r_symndx < symtab_hdr->sh_info)
527 h = NULL;
528 else
529 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
530
70256ad8
AJ
531 switch (ELF64_R_TYPE (rel->r_info))
532 {
533 case R_X86_64_GOT32:
c434dee6 534 case R_X86_64_GOTPCREL:
407443a3 535 /* This symbol requires a global offset table entry. */
70256ad8
AJ
536 if (h != NULL)
537 {
51b64d56 538 h->got.refcount += 1;
70256ad8
AJ
539 }
540 else
541 {
c434dee6
AJ
542 bfd_signed_vma *local_got_refcounts;
543
70256ad8 544 /* This is a global offset table entry for a local symbol. */
c434dee6 545 local_got_refcounts = elf_local_got_refcounts (abfd);
70256ad8
AJ
546 if (local_got_refcounts == NULL)
547 {
dc810e39 548 bfd_size_type size;
70256ad8 549
dc810e39
AM
550 size = symtab_hdr->sh_info;
551 size *= sizeof (bfd_signed_vma);
70256ad8 552 local_got_refcounts = ((bfd_signed_vma *)
51b64d56 553 bfd_zalloc (abfd, size));
70256ad8
AJ
554 if (local_got_refcounts == NULL)
555 return false;
556 elf_local_got_refcounts (abfd) = local_got_refcounts;
70256ad8 557 }
51b64d56 558 local_got_refcounts[r_symndx] += 1;
70256ad8 559 }
c434dee6
AJ
560 /* Fall through */
561
562 //case R_X86_64_GOTPCREL:
563 if (htab->sgot == NULL)
564 {
565 if (htab->elf.dynobj == NULL)
566 htab->elf.dynobj = abfd;
567 if (!create_got_section (htab->elf.dynobj, info))
568 return false;
569 }
70256ad8
AJ
570 break;
571
572 case R_X86_64_PLT32:
573 /* This symbol requires a procedure linkage table entry. We
407443a3
AJ
574 actually build the entry in adjust_dynamic_symbol,
575 because this might be a case of linking PIC code which is
576 never referenced by a dynamic object, in which case we
577 don't need to generate a procedure linkage table entry
578 after all. */
70256ad8
AJ
579
580 /* If this is a local symbol, we resolve it directly without
407443a3 581 creating a procedure linkage table entry. */
70256ad8
AJ
582 if (h == NULL)
583 continue;
584
cc78d0af 585 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
51b64d56 586 h->plt.refcount += 1;
70256ad8
AJ
587 break;
588
cc78d0af
AJ
589 case R_X86_64_8:
590 case R_X86_64_16:
70256ad8 591 case R_X86_64_32:
cc78d0af 592 case R_X86_64_64:
70256ad8 593 case R_X86_64_32S:
c434dee6
AJ
594 case R_X86_64_PC8:
595 case R_X86_64_PC16:
70256ad8 596 case R_X86_64_PC32:
c434dee6
AJ
597 if (h != NULL && !info->shared)
598 {
599 /* If this reloc is in a read-only section, we might
600 need a copy reloc. We can't check reliably at this
601 stage whether the section is read-only, as input
602 sections have not yet been mapped to output sections.
603 Tentatively set the flag for now, and correct in
604 adjust_dynamic_symbol. */
605 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
606
607 /* We may need a .plt entry if the function this reloc
608 refers to is in a shared lib. */
609 h->plt.refcount += 1;
610 }
70256ad8
AJ
611
612 /* If we are creating a shared library, and this is a reloc
613 against a global symbol, or a non PC relative reloc
614 against a local symbol, then we need to copy the reloc
615 into the shared library. However, if we are linking with
616 -Bsymbolic, we do not need to copy a reloc against a
617 global symbol which is defined in an object we are
407443a3 618 including in the link (i.e., DEF_REGULAR is set). At
70256ad8
AJ
619 this point we have not seen all the input files, so it is
620 possible that DEF_REGULAR is not set now but will be set
c434dee6
AJ
621 later (it is never cleared). In case of a weak definition,
622 DEF_REGULAR may be cleared later by a strong definition in
623 a shared library. We account for that possibility below by
624 storing information in the relocs_copied field of the hash
625 table entry. A similar situation occurs when creating
626 shared libraries and symbol visibility changes render the
627 symbol local.
628
629 If on the other hand, we are creating an executable, we
630 may need to keep relocations for symbols satisfied by a
631 dynamic library if we manage to avoid copy relocs for the
632 symbol. */
633 if ((info->shared
634 && (sec->flags & SEC_ALLOC) != 0
635 && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8)
636 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16)
637 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32))
638 || (h != NULL
639 && (! info->symbolic
640 || h->root.type == bfd_link_hash_defweak
641 || (h->elf_link_hash_flags
642 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
643 || (!info->shared
644 && (sec->flags & SEC_ALLOC) != 0
645 && h != NULL
646 && (h->root.type == bfd_link_hash_defweak
647 || (h->elf_link_hash_flags
648 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
70256ad8 649 {
c434dee6
AJ
650 struct elf64_x86_64_dyn_relocs *p;
651 struct elf64_x86_64_dyn_relocs **head;
652
653 /* We must copy these reloc types into the output file.
654 Create a reloc section in dynobj and make room for
655 this reloc. */
70256ad8
AJ
656 if (sreloc == NULL)
657 {
658 const char *name;
c434dee6 659 bfd *dynobj;
70256ad8
AJ
660
661 name = (bfd_elf_string_from_elf_section
662 (abfd,
663 elf_elfheader (abfd)->e_shstrndx,
664 elf_section_data (sec)->rel_hdr.sh_name));
665 if (name == NULL)
666 return false;
667
c434dee6
AJ
668 if (strncmp (name, ".rela", 5) != 0
669 || strcmp (bfd_get_section_name (abfd, sec),
670 name + 5) != 0)
671 {
672 (*_bfd_error_handler)
673 (_("%s: bad relocation section name `%s\'"),
674 bfd_archive_filename (abfd), name);
675 }
676
677 if (htab->elf.dynobj == NULL)
678 htab->elf.dynobj = abfd;
679
680 dynobj = htab->elf.dynobj;
70256ad8
AJ
681
682 sreloc = bfd_get_section_by_name (dynobj, name);
683 if (sreloc == NULL)
684 {
685 flagword flags;
686
687 sreloc = bfd_make_section (dynobj, name);
688 flags = (SEC_HAS_CONTENTS | SEC_READONLY
689 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
690 if ((sec->flags & SEC_ALLOC) != 0)
691 flags |= SEC_ALLOC | SEC_LOAD;
692 if (sreloc == NULL
693 || ! bfd_set_section_flags (dynobj, sreloc, flags)
cc78d0af 694 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
70256ad8
AJ
695 return false;
696 }
c434dee6 697 elf_section_data (sec)->sreloc = sreloc;
70256ad8
AJ
698 }
699
c434dee6
AJ
700 /* If this is a global symbol, we count the number of
701 relocations we need for this symbol. */
702 if (h != NULL)
70256ad8 703 {
c434dee6
AJ
704 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs;
705 }
706 else
707 {
708 /* Track dynamic relocs needed for local syms too.
709 We really need local syms available to do this
710 easily. Oh well. */
711
712 asection *s;
713 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
714 sec, r_symndx);
715 if (s == NULL)
716 return false;
70256ad8 717
c434dee6
AJ
718 head = ((struct elf64_x86_64_dyn_relocs **)
719 &elf_section_data (s)->local_dynrel);
720 }
70256ad8 721
c434dee6
AJ
722 p = *head;
723 if (p == NULL || p->sec != sec)
724 {
725 bfd_size_type amt = sizeof *p;
726 p = ((struct elf64_x86_64_dyn_relocs *)
727 bfd_alloc (htab->elf.dynobj, amt));
70256ad8 728 if (p == NULL)
c434dee6
AJ
729 return false;
730 p->next = *head;
731 *head = p;
732 p->sec = sec;
733 p->count = 0;
734 p->pc_count = 0;
70256ad8 735 }
c434dee6
AJ
736
737 p->count += 1;
738 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8
739 || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16
740 || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)
741 p->pc_count += 1;
70256ad8
AJ
742 }
743 break;
fe4770f4
AJ
744
745 /* This relocation describes the C++ object vtable hierarchy.
746 Reconstruct it for later use during GC. */
747 case R_X86_64_GNU_VTINHERIT:
748 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
749 return false;
750 break;
751
752 /* This relocation describes which C++ vtable entries are actually
753 used. Record for later use during GC. */
754 case R_X86_64_GNU_VTENTRY:
cc78d0af 755 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
fe4770f4
AJ
756 return false;
757 break;
c434dee6
AJ
758
759 default:
760 break;
70256ad8
AJ
761 }
762 }
763
764 return true;
765}
766
767/* Return the section that should be marked against GC for a given
407443a3 768 relocation. */
70256ad8
AJ
769
770static asection *
771elf64_x86_64_gc_mark_hook (abfd, info, rel, h, sym)
772 bfd *abfd;
773 struct bfd_link_info *info ATTRIBUTE_UNUSED;
c434dee6 774 Elf_Internal_Rela *rel;
70256ad8
AJ
775 struct elf_link_hash_entry *h;
776 Elf_Internal_Sym *sym;
777{
778 if (h != NULL)
779 {
fe4770f4 780 switch (ELF64_R_TYPE (rel->r_info))
70256ad8 781 {
fe4770f4
AJ
782 case R_X86_64_GNU_VTINHERIT:
783 case R_X86_64_GNU_VTENTRY:
784 break;
70256ad8
AJ
785
786 default:
fe4770f4
AJ
787 switch (h->root.type)
788 {
789 case bfd_link_hash_defined:
790 case bfd_link_hash_defweak:
791 return h->root.u.def.section;
792
793 case bfd_link_hash_common:
794 return h->root.u.c.p->section;
795
796 default:
797 break;
798 }
70256ad8
AJ
799 }
800 }
801 else
802 {
9ad5cbcf 803 return bfd_section_from_elf_index (abfd, sym->st_shndx);
70256ad8
AJ
804 }
805
806 return NULL;
807}
808
407443a3 809/* Update the got entry reference counts for the section being removed. */
70256ad8
AJ
810
811static boolean
812elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs)
813 bfd *abfd;
c434dee6 814 struct bfd_link_info *info;
70256ad8
AJ
815 asection *sec;
816 const Elf_Internal_Rela *relocs;
817{
818 Elf_Internal_Shdr *symtab_hdr;
819 struct elf_link_hash_entry **sym_hashes;
820 bfd_signed_vma *local_got_refcounts;
821 const Elf_Internal_Rela *rel, *relend;
822 unsigned long r_symndx;
823 struct elf_link_hash_entry *h;
c434dee6
AJ
824
825 elf_section_data (sec)->local_dynrel = NULL;
70256ad8
AJ
826
827 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
828 sym_hashes = elf_sym_hashes (abfd);
829 local_got_refcounts = elf_local_got_refcounts (abfd);
830
70256ad8
AJ
831 relend = relocs + sec->reloc_count;
832 for (rel = relocs; rel < relend; rel++)
833 switch (ELF64_R_TYPE (rel->r_info))
834 {
835 case R_X86_64_GOT32:
836 case R_X86_64_GOTPCREL:
837 r_symndx = ELF64_R_SYM (rel->r_info);
838 if (r_symndx >= symtab_hdr->sh_info)
839 {
840 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
841 if (h->got.refcount > 0)
c434dee6 842 h->got.refcount -= 1;
70256ad8
AJ
843 }
844 else if (local_got_refcounts != NULL)
845 {
846 if (local_got_refcounts[r_symndx] > 0)
c434dee6 847 local_got_refcounts[r_symndx] -= 1;
70256ad8
AJ
848 }
849 break;
850
c434dee6
AJ
851 case R_X86_64_8:
852 case R_X86_64_16:
853 case R_X86_64_32:
854 case R_X86_64_64:
855 case R_X86_64_32S:
856 case R_X86_64_PC8:
857 case R_X86_64_PC16:
858 case R_X86_64_PC32:
859 r_symndx = ELF64_R_SYM (rel->r_info);
860 if (r_symndx >= symtab_hdr->sh_info)
861 {
862 struct elf64_x86_64_link_hash_entry *eh;
863 struct elf64_x86_64_dyn_relocs **pp;
864 struct elf64_x86_64_dyn_relocs *p;
865
866 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
867
868 if (!info->shared && h->plt.refcount > 0)
869 h->plt.refcount -= 1;
870
871 eh = (struct elf64_x86_64_link_hash_entry *) h;
872
873 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
874 if (p->sec == sec)
875 {
876 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8
877 || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16
878 || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)
879 p->pc_count -= 1;
880 p->count -= 1;
881 if (p->count == 0)
882 *pp = p->next;
883 break;
884 }
885 }
886 break;
887
888
70256ad8
AJ
889 case R_X86_64_PLT32:
890 r_symndx = ELF64_R_SYM (rel->r_info);
891 if (r_symndx >= symtab_hdr->sh_info)
892 {
893 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
894 if (h->plt.refcount > 0)
895 h->plt.refcount -= 1;
896 }
897 break;
898
899 default:
900 break;
901 }
902
903 return true;
904}
905
906/* Adjust a symbol defined by a dynamic object and referenced by a
907 regular object. The current definition is in some section of the
908 dynamic object, but we're not including those sections. We have to
909 change the definition to something the rest of the link can
407443a3 910 understand. */
70256ad8
AJ
911
912static boolean
913elf64_x86_64_adjust_dynamic_symbol (info, h)
914 struct bfd_link_info *info;
915 struct elf_link_hash_entry *h;
916{
c434dee6
AJ
917 struct elf64_x86_64_link_hash_table *htab;
918 struct elf64_x86_64_link_hash_entry * eh;
919 struct elf64_x86_64_dyn_relocs *p;
70256ad8
AJ
920 asection *s;
921 unsigned int power_of_two;
922
70256ad8
AJ
923 /* If this is a function, put it in the procedure linkage table. We
924 will fill in the contents of the procedure linkage table later,
925 when we know the address of the .got section. */
926 if (h->type == STT_FUNC
927 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
928 {
c434dee6
AJ
929 if (h->plt.refcount <= 0
930 || (! info->shared
931 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
932 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
933 && h->root.type != bfd_link_hash_undefweak
934 && h->root.type != bfd_link_hash_undefined))
70256ad8 935 {
70256ad8
AJ
936 /* This case can occur if we saw a PLT32 reloc in an input
937 file, but the symbol was never referred to by a dynamic
938 object, or if all references were garbage collected. In
939 such a case, we don't actually need to build a procedure
940 linkage table, and we can just do a PC32 reloc instead. */
70256ad8
AJ
941 h->plt.offset = (bfd_vma) -1;
942 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
70256ad8
AJ
943 }
944
70256ad8
AJ
945 return true;
946 }
bbd7ec4a 947 else
c434dee6
AJ
948 /* It's possible that we incorrectly decided a .plt reloc was
949 needed for an R_X86_64_PC32 reloc to a non-function sym in
950 check_relocs. We can't decide accurately between function and
951 non-function syms in check-relocs; Objects loaded later in
952 the link may change h->type. So fix it now. */
bbd7ec4a 953 h->plt.offset = (bfd_vma) -1;
70256ad8
AJ
954
955 /* If this is a weak symbol, and there is a real definition, the
956 processor independent code will have arranged for us to see the
407443a3 957 real definition first, and we can just use the same value. */
70256ad8
AJ
958 if (h->weakdef != NULL)
959 {
960 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
961 || h->weakdef->root.type == bfd_link_hash_defweak);
962 h->root.u.def.section = h->weakdef->root.u.def.section;
963 h->root.u.def.value = h->weakdef->root.u.def.value;
964 return true;
965 }
966
967 /* This is a reference to a symbol defined by a dynamic object which
407443a3 968 is not a function. */
70256ad8
AJ
969
970 /* If we are creating a shared library, we must presume that the
971 only references to the symbol are via the global offset table.
972 For such cases we need not do anything here; the relocations will
407443a3 973 be handled correctly by relocate_section. */
70256ad8
AJ
974 if (info->shared)
975 return true;
976
977 /* If there are no references to this symbol that do not use the
978 GOT, we don't need to generate a copy reloc. */
979 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
980 return true;
981
c434dee6
AJ
982 /* If -z nocopyreloc was given, we won't generate them either. */
983 if (info->nocopyreloc)
984 {
985 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
986 return true;
987 }
988
989 eh = (struct elf64_x86_64_link_hash_entry *) h;
990 for (p = eh->dyn_relocs; p != NULL; p = p->next)
991 {
992 s = p->sec->output_section;
993 if (s != NULL && (s->flags & SEC_READONLY) != 0)
994 break;
995 }
996
997 /* If we didn't find any dynamic relocs in read-only sections, then
998 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
999 if (p == NULL)
1000 {
1001 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
1002 return true;
1003 }
1004
70256ad8 1005 /* We must allocate the symbol in our .dynbss section, which will
407443a3 1006 become part of the .bss section of the executable. There will be
70256ad8
AJ
1007 an entry for this symbol in the .dynsym section. The dynamic
1008 object will contain position independent code, so all references
1009 from the dynamic object to this symbol will go through the global
1010 offset table. The dynamic linker will use the .dynsym entry to
1011 determine the address it must put in the global offset table, so
1012 both the dynamic object and the regular object will refer to the
1013 same memory location for the variable. */
1014
c434dee6 1015 htab = elf64_x86_64_hash_table (info);
70256ad8
AJ
1016
1017 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
1018 to copy the initial value out of the dynamic object and into the
c434dee6 1019 runtime process image. */
70256ad8
AJ
1020 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1021 {
c434dee6 1022 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
70256ad8
AJ
1023 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1024 }
1025
1026 /* We need to figure out the alignment required for this symbol. I
407443a3 1027 have no idea how ELF linkers handle this. 16-bytes is the size
70256ad8
AJ
1028 of the largest type that requires hard alignment -- long double. */
1029 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
1030 this construct. */
1031 power_of_two = bfd_log2 (h->size);
1032 if (power_of_two > 4)
1033 power_of_two = 4;
1034
1035 /* Apply the required alignment. */
c434dee6 1036 s = htab->sdynbss;
70256ad8 1037 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
c434dee6 1038 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
70256ad8 1039 {
c434dee6 1040 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
70256ad8
AJ
1041 return false;
1042 }
1043
1044 /* Define the symbol as being at this point in the section. */
1045 h->root.u.def.section = s;
1046 h->root.u.def.value = s->_raw_size;
1047
1048 /* Increment the section size to make room for the symbol. */
1049 s->_raw_size += h->size;
1050
1051 return true;
1052}
1053
c434dee6
AJ
1054/* This is the condition under which elf64_x86_64_finish_dynamic_symbol
1055 will be called from elflink.h. If elflink.h doesn't call our
1056 finish_dynamic_symbol routine, we'll need to do something about
1057 initializing any .plt and .got entries in elf64_x86_64_relocate_section. */
1058#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1059 ((DYN) \
1060 && ((INFO)->shared \
1061 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1062 && ((H)->dynindx != -1 \
1063 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1064
1065/* Allocate space in .plt, .got and associated reloc sections for
1066 dynamic relocs. */
1067
1068static boolean
1069allocate_dynrelocs (h, inf)
1070 struct elf_link_hash_entry *h;
1071 PTR inf;
1072{
1073 struct bfd_link_info *info;
1074 struct elf64_x86_64_link_hash_table *htab;
1075 struct elf64_x86_64_link_hash_entry *eh;
1076 struct elf64_x86_64_dyn_relocs *p;
1077
e92d460e 1078 if (h->root.type == bfd_link_hash_indirect)
c434dee6
AJ
1079 return true;
1080
e92d460e
AM
1081 if (h->root.type == bfd_link_hash_warning)
1082 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1083
c434dee6
AJ
1084 info = (struct bfd_link_info *) inf;
1085 htab = elf64_x86_64_hash_table (info);
1086
1087 if (htab->elf.dynamic_sections_created
1088 && h->plt.refcount > 0)
1089 {
1090 /* Make sure this symbol is output as a dynamic symbol.
1091 Undefined weak syms won't yet be marked as dynamic. */
1092 if (h->dynindx == -1
1093 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1094 {
1095 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
1096 return false;
1097 }
1098
1099 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
1100 {
1101 asection *s = htab->splt;
1102
1103 /* If this is the first .plt entry, make room for the special
1104 first entry. */
1105 if (s->_raw_size == 0)
1106 s->_raw_size += PLT_ENTRY_SIZE;
1107
1108 h->plt.offset = s->_raw_size;
1109
1110 /* If this symbol is not defined in a regular file, and we are
1111 not generating a shared library, then set the symbol to this
1112 location in the .plt. This is required to make function
1113 pointers compare as equal between the normal executable and
1114 the shared library. */
1115 if (! info->shared
1116 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1117 {
1118 h->root.u.def.section = s;
1119 h->root.u.def.value = h->plt.offset;
1120 }
1121
1122 /* Make room for this entry. */
1123 s->_raw_size += PLT_ENTRY_SIZE;
1124
1125 /* We also need to make an entry in the .got.plt section, which
1126 will be placed in the .got section by the linker script. */
1127 htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
1128
1129 /* We also need to make an entry in the .rela.plt section. */
1130 htab->srelplt->_raw_size += sizeof (Elf64_External_Rela);
1131 }
1132 else
1133 {
1134 h->plt.offset = (bfd_vma) -1;
1135 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1136 }
1137 }
1138 else
1139 {
1140 h->plt.offset = (bfd_vma) -1;
1141 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1142 }
1143
1144 if (h->got.refcount > 0)
1145 {
1146 asection *s;
1147 boolean dyn;
1148
1149 /* Make sure this symbol is output as a dynamic symbol.
1150 Undefined weak syms won't yet be marked as dynamic. */
1151 if (h->dynindx == -1
1152 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1153 {
1154 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
1155 return false;
1156 }
1157
1158 s = htab->sgot;
1159 h->got.offset = s->_raw_size;
1160 s->_raw_size += GOT_ENTRY_SIZE;
1161 dyn = htab->elf.dynamic_sections_created;
1162 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
1163 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
1164 }
1165 else
1166 h->got.offset = (bfd_vma) -1;
1167
1168 eh = (struct elf64_x86_64_link_hash_entry *) h;
1169 if (eh->dyn_relocs == NULL)
1170 return true;
1171
1172 /* In the shared -Bsymbolic case, discard space allocated for
1173 dynamic pc-relative relocs against symbols which turn out to be
1174 defined in regular objects. For the normal shared case, discard
1175 space for pc-relative relocs that have become local due to symbol
1176 visibility changes. */
1177
1178 if (info->shared)
1179 {
1180 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1181 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
1182 || info->symbolic))
1183 {
1184 struct elf64_x86_64_dyn_relocs **pp;
1185
1186 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
1187 {
1188 p->count -= p->pc_count;
1189 p->pc_count = 0;
1190 if (p->count == 0)
1191 *pp = p->next;
1192 else
1193 pp = &p->next;
1194 }
1195 }
1196 }
1197 else
1198 {
1199 /* For the non-shared case, discard space for relocs against
1200 symbols which turn out to need copy relocs or are not
1201 dynamic. */
1202
1203 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
1204 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1205 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1206 || (htab->elf.dynamic_sections_created
1207 && (h->root.type == bfd_link_hash_undefweak
1208 || h->root.type == bfd_link_hash_undefined))))
1209 {
1210 /* Make sure this symbol is output as a dynamic symbol.
1211 Undefined weak syms won't yet be marked as dynamic. */
1212 if (h->dynindx == -1
1213 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1214 {
1215 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
1216 return false;
1217 }
1218
1219 /* If that succeeded, we know we'll be keeping all the
1220 relocs. */
1221 if (h->dynindx != -1)
1222 goto keep;
1223 }
1224
1225 eh->dyn_relocs = NULL;
1226
1227 keep: ;
1228 }
1229
1230 /* Finally, allocate space. */
1231 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1232 {
1233 asection *sreloc = elf_section_data (p->sec)->sreloc;
1234 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
1235 }
1236
1237 return true;
1238}
1239
1240/* Find any dynamic relocs that apply to read-only sections. */
1241
1242static boolean
1243readonly_dynrelocs (h, inf)
1244 struct elf_link_hash_entry *h;
1245 PTR inf;
1246{
1247 struct elf64_x86_64_link_hash_entry *eh;
1248 struct elf64_x86_64_dyn_relocs *p;
1249
e92d460e
AM
1250 if (h->root.type == bfd_link_hash_warning)
1251 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1252
c434dee6
AJ
1253 eh = (struct elf64_x86_64_link_hash_entry *) h;
1254 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1255 {
1256 asection *s = p->sec->output_section;
1257
1258 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1259 {
1260 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1261
1262 info->flags |= DF_TEXTREL;
1263
1264 /* Not an error, just cut short the traversal. */
1265 return false;
1266 }
1267 }
1268 return true;
1269}
1270
70256ad8
AJ
1271/* Set the sizes of the dynamic sections. */
1272
1273static boolean
1274elf64_x86_64_size_dynamic_sections (output_bfd, info)
8df9fc9d 1275 bfd *output_bfd ATTRIBUTE_UNUSED;
70256ad8
AJ
1276 struct bfd_link_info *info;
1277{
c434dee6 1278 struct elf64_x86_64_link_hash_table *htab;
70256ad8
AJ
1279 bfd *dynobj;
1280 asection *s;
70256ad8 1281 boolean relocs;
c434dee6 1282 bfd *ibfd;
70256ad8 1283
c434dee6
AJ
1284 htab = elf64_x86_64_hash_table (info);
1285 dynobj = htab->elf.dynobj;
1286 if (dynobj == NULL)
1287 abort ();
70256ad8 1288
c434dee6 1289 if (htab->elf.dynamic_sections_created)
70256ad8
AJ
1290 {
1291 /* Set the contents of the .interp section to the interpreter. */
1292 if (! info->shared)
1293 {
1294 s = bfd_get_section_by_name (dynobj, ".interp");
c434dee6
AJ
1295 if (s == NULL)
1296 abort ();
70256ad8
AJ
1297 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1298 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1299 }
1300 }
70256ad8 1301
c434dee6
AJ
1302 /* Set up .got offsets for local syms, and space for local dynamic
1303 relocs. */
1304 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
70256ad8 1305 {
c434dee6
AJ
1306 bfd_signed_vma *local_got;
1307 bfd_signed_vma *end_local_got;
1308 bfd_size_type locsymcount;
1309 Elf_Internal_Shdr *symtab_hdr;
1310 asection *srel;
70256ad8 1311
c434dee6 1312 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
70256ad8
AJ
1313 continue;
1314
c434dee6 1315 for (s = ibfd->sections; s != NULL; s = s->next)
70256ad8 1316 {
c434dee6
AJ
1317 struct elf64_x86_64_dyn_relocs *p;
1318
1319 for (p = *((struct elf64_x86_64_dyn_relocs **)
1320 &elf_section_data (s)->local_dynrel);
1321 p != NULL;
1322 p = p->next)
70256ad8 1323 {
c434dee6
AJ
1324 if (!bfd_is_abs_section (p->sec)
1325 && bfd_is_abs_section (p->sec->output_section))
1326 {
1327 /* Input section has been discarded, either because
1328 it is a copy of a linkonce section or due to
1329 linker script /DISCARD/, so we'll be discarding
1330 the relocs too. */
1331 }
1332 else if (p->count != 0)
1333 {
1334 srel = elf_section_data (p->sec)->sreloc;
1335 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
1336 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1337 info->flags |= DF_TEXTREL;
1338
1339 }
70256ad8
AJ
1340 }
1341 }
c434dee6
AJ
1342
1343 local_got = elf_local_got_refcounts (ibfd);
1344 if (!local_got)
1345 continue;
1346
1347 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1348 locsymcount = symtab_hdr->sh_info;
1349 end_local_got = local_got + locsymcount;
1350 s = htab->sgot;
1351 srel = htab->srelgot;
1352 for (; local_got < end_local_got; ++local_got)
70256ad8 1353 {
c434dee6 1354 if (*local_got > 0)
70256ad8 1355 {
c434dee6
AJ
1356 *local_got = s->_raw_size;
1357 s->_raw_size += GOT_ENTRY_SIZE;
1358 if (info->shared)
1359 srel->_raw_size += sizeof (Elf64_External_Rela);
70256ad8
AJ
1360 }
1361 else
c434dee6
AJ
1362 *local_got = (bfd_vma) -1;
1363 }
1364 }
70256ad8 1365
c434dee6
AJ
1366 /* Allocate global sym .plt and .got entries, and space for global
1367 sym dynamic relocs. */
1368 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
1369
1370 /* We now have determined the sizes of the various dynamic sections.
1371 Allocate memory for them. */
1372 relocs = false;
1373 for (s = dynobj->sections; s != NULL; s = s->next)
1374 {
1375 if ((s->flags & SEC_LINKER_CREATED) == 0)
1376 continue;
1377
1378 if (s == htab->splt
1379 || s == htab->sgot
1380 || s == htab->sgotplt)
1381 {
1382 /* Strip this section if we don't need it; see the
1383 comment below. */
1384 }
1385 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
1386 {
1387 if (s->_raw_size != 0 && s != htab->srelplt)
1388 relocs = true;
1389
1390 /* We use the reloc_count field as a counter if we need
1391 to copy relocs into the output file. */
1392 s->reloc_count = 0;
70256ad8 1393 }
c434dee6 1394 else
70256ad8
AJ
1395 {
1396 /* It's not one of our sections, so don't allocate space. */
1397 continue;
1398 }
1399
c434dee6 1400 if (s->_raw_size == 0)
70256ad8 1401 {
c434dee6
AJ
1402 /* If we don't need this section, strip it from the
1403 output file. This is mostly to handle .rela.bss and
1404 .rela.plt. We must create both sections in
1405 create_dynamic_sections, because they must be created
1406 before the linker maps input sections to output
1407 sections. The linker does that before
1408 adjust_dynamic_symbol is called, and it is that
1409 function which decides whether anything needs to go
1410 into these sections. */
1411
70256ad8
AJ
1412 _bfd_strip_section_from_output (info, s);
1413 continue;
1414 }
1415
1416 /* Allocate memory for the section contents. We use bfd_zalloc
1417 here in case unused entries are not reclaimed before the
1418 section's contents are written out. This should not happen,
1419 but this way if it does, we get a R_X86_64_NONE reloc instead
1420 of garbage. */
1421 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
c434dee6 1422 if (s->contents == NULL)
70256ad8
AJ
1423 return false;
1424 }
1425
c434dee6 1426 if (htab->elf.dynamic_sections_created)
70256ad8
AJ
1427 {
1428 /* Add some entries to the .dynamic section. We fill in the
1429 values later, in elf64_x86_64_finish_dynamic_sections, but we
1430 must add the entries now so that we get the correct size for
407443a3 1431 the .dynamic section. The DT_DEBUG entry is filled in by the
70256ad8 1432 dynamic linker and used by the debugger. */
dc810e39
AM
1433#define add_dynamic_entry(TAG, VAL) \
1434 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1435
70256ad8
AJ
1436 if (! info->shared)
1437 {
dc810e39 1438 if (!add_dynamic_entry (DT_DEBUG, 0))
70256ad8
AJ
1439 return false;
1440 }
1441
c434dee6 1442 if (htab->splt->_raw_size != 0)
70256ad8 1443 {
dc810e39
AM
1444 if (!add_dynamic_entry (DT_PLTGOT, 0)
1445 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1446 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1447 || !add_dynamic_entry (DT_JMPREL, 0))
70256ad8
AJ
1448 return false;
1449 }
1450
1451 if (relocs)
1452 {
dc810e39
AM
1453 if (!add_dynamic_entry (DT_RELA, 0)
1454 || !add_dynamic_entry (DT_RELASZ, 0)
1455 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
70256ad8 1456 return false;
70256ad8 1457
c434dee6
AJ
1458 /* If any dynamic relocs apply to a read-only section,
1459 then we need a DT_TEXTREL entry. */
1460 if ((info->flags & DF_TEXTREL) == 0)
1461 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
1462 (PTR) info);
1463
1464 if ((info->flags & DF_TEXTREL) != 0)
1465 {
1466 if (!add_dynamic_entry (DT_TEXTREL, 0))
1467 return false;
1468 }
70256ad8
AJ
1469 }
1470 }
dc810e39 1471#undef add_dynamic_entry
70256ad8
AJ
1472
1473 return true;
1474}
1475
8d88c4ca
NC
1476/* Relocate an x86_64 ELF section. */
1477
1478static boolean
1479elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
fe4770f4 1480 contents, relocs, local_syms, local_sections)
8d88c4ca
NC
1481 bfd *output_bfd;
1482 struct bfd_link_info *info;
1483 bfd *input_bfd;
1484 asection *input_section;
1485 bfd_byte *contents;
1486 Elf_Internal_Rela *relocs;
1487 Elf_Internal_Sym *local_syms;
1488 asection **local_sections;
1489{
c434dee6 1490 struct elf64_x86_64_link_hash_table *htab;
8d88c4ca
NC
1491 Elf_Internal_Shdr *symtab_hdr;
1492 struct elf_link_hash_entry **sym_hashes;
1493 bfd_vma *local_got_offsets;
c434dee6 1494 Elf_Internal_Rela *rel;
8d88c4ca
NC
1495 Elf_Internal_Rela *relend;
1496
b491616a
AM
1497 if (info->relocateable)
1498 return true;
1499
c434dee6 1500 htab = elf64_x86_64_hash_table (info);
8d88c4ca
NC
1501 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1502 sym_hashes = elf_sym_hashes (input_bfd);
1503 local_got_offsets = elf_local_got_offsets (input_bfd);
1504
c434dee6 1505 rel = relocs;
8d88c4ca 1506 relend = relocs + input_section->reloc_count;
c434dee6 1507 for (; rel < relend; rel++)
8d88c4ca
NC
1508 {
1509 int r_type;
1510 reloc_howto_type *howto;
1511 unsigned long r_symndx;
1512 struct elf_link_hash_entry *h;
1513 Elf_Internal_Sym *sym;
1514 asection *sec;
c434dee6 1515 bfd_vma off;
8d88c4ca 1516 bfd_vma relocation;
c434dee6 1517 boolean unresolved_reloc;
8d88c4ca 1518 bfd_reloc_status_type r;
8d88c4ca 1519
c434dee6 1520 r_type = ELF64_R_TYPE (rel->r_info);
fe4770f4
AJ
1521 if (r_type == (int) R_X86_64_GNU_VTINHERIT
1522 || r_type == (int) R_X86_64_GNU_VTENTRY)
1523 continue;
8d88c4ca 1524
c434dee6 1525 if (r_type < 0 || r_type >= R_X86_64_max)
8da6118f
KH
1526 {
1527 bfd_set_error (bfd_error_bad_value);
1528 return false;
1529 }
8d88c4ca 1530
b491616a 1531 howto = x86_64_elf_howto_table + r_type;
c434dee6 1532 r_symndx = ELF64_R_SYM (rel->r_info);
8d88c4ca
NC
1533 h = NULL;
1534 sym = NULL;
1535 sec = NULL;
c434dee6 1536 unresolved_reloc = false;
8d88c4ca 1537 if (r_symndx < symtab_hdr->sh_info)
8da6118f
KH
1538 {
1539 sym = local_syms + r_symndx;
1540 sec = local_sections[r_symndx];
c434dee6
AJ
1541
1542 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
8da6118f 1543 }
8d88c4ca 1544 else
8da6118f
KH
1545 {
1546 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1547 while (h->root.type == bfd_link_hash_indirect
1548 || h->root.type == bfd_link_hash_warning)
1549 h = (struct elf_link_hash_entry *) h->root.u.i.link;
c434dee6 1550
8da6118f
KH
1551 if (h->root.type == bfd_link_hash_defined
1552 || h->root.type == bfd_link_hash_defweak)
1553 {
1554 sec = h->root.u.def.section;
c434dee6 1555 if (sec->output_section == NULL)
8da6118f 1556 {
c434dee6
AJ
1557 /* Set a flag that will be cleared later if we find a
1558 relocation value for this symbol. output_section
1559 is typically NULL for symbols satisfied by a shared
1560 library. */
1561 unresolved_reloc = true;
8da6118f
KH
1562 relocation = 0;
1563 }
1564 else
1565 relocation = (h->root.u.def.value
1566 + sec->output_section->vma
1567 + sec->output_offset);
1568 }
1569 else if (h->root.type == bfd_link_hash_undefweak)
1570 relocation = 0;
671bae9c
NC
1571 else if (info->shared
1572 && (!info->symbolic || info->allow_shlib_undefined)
1573 && !info->no_undefined
70256ad8
AJ
1574 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1575 relocation = 0;
8da6118f
KH
1576 else
1577 {
1578 if (! ((*info->callbacks->undefined_symbol)
1579 (info, h->root.root.string, input_bfd,
c434dee6 1580 input_section, rel->r_offset,
8da6118f
KH
1581 (!info->shared || info->no_undefined
1582 || ELF_ST_VISIBILITY (h->other)))))
1583 return false;
1584 relocation = 0;
1585 }
1586 }
70256ad8
AJ
1587 /* When generating a shared object, the relocations handled here are
1588 copied into the output file to be resolved at run time. */
1589 switch (r_type)
1590 {
1591 case R_X86_64_GOT32:
1592 /* Relocation is to the entry for this symbol in the global
1593 offset table. */
70256ad8
AJ
1594 case R_X86_64_GOTPCREL:
1595 /* Use global offset table as symbol value. */
c434dee6
AJ
1596 if (htab->sgot == NULL)
1597 abort ();
053579d7 1598
51e0a107 1599 if (h != NULL)
70256ad8 1600 {
c434dee6
AJ
1601 boolean dyn;
1602
1603 off = h->got.offset;
1604 dyn = htab->elf.dynamic_sections_created;
51e0a107 1605
c434dee6 1606 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
51e0a107 1607 || (info->shared
c434dee6
AJ
1608 && (info->symbolic
1609 || h->dynindx == -1
1610 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
51e0a107
JH
1611 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1612 {
1613 /* This is actually a static link, or it is a -Bsymbolic
1614 link and the symbol is defined locally, or the symbol
407443a3 1615 was forced to be local because of a version file. We
51e0a107
JH
1616 must initialize this entry in the global offset table.
1617 Since the offset must always be a multiple of 8, we
1618 use the least significant bit to record whether we
1619 have initialized it already.
1620
1621 When doing a dynamic link, we create a .rela.got
407443a3
AJ
1622 relocation entry to initialize the value. This is
1623 done in the finish_dynamic_symbol routine. */
51e0a107
JH
1624 if ((off & 1) != 0)
1625 off &= ~1;
1626 else
1627 {
1628 bfd_put_64 (output_bfd, relocation,
c434dee6 1629 htab->sgot->contents + off);
51e0a107
JH
1630 h->got.offset |= 1;
1631 }
1632 }
053579d7 1633 else
c434dee6 1634 unresolved_reloc = false;
70256ad8 1635 }
51e0a107
JH
1636 else
1637 {
c434dee6
AJ
1638 if (local_got_offsets == NULL)
1639 abort ();
51e0a107
JH
1640
1641 off = local_got_offsets[r_symndx];
1642
1643 /* The offset must always be a multiple of 8. We use
407443a3
AJ
1644 the least significant bit to record whether we have
1645 already generated the necessary reloc. */
51e0a107
JH
1646 if ((off & 1) != 0)
1647 off &= ~1;
1648 else
1649 {
c434dee6
AJ
1650 bfd_put_64 (output_bfd, relocation,
1651 htab->sgot->contents + off);
51e0a107
JH
1652
1653 if (info->shared)
1654 {
1655 asection *srelgot;
1656 Elf_Internal_Rela outrel;
c434dee6 1657 Elf64_External_Rela *loc;
70256ad8 1658
51e0a107
JH
1659 /* We need to generate a R_X86_64_RELATIVE reloc
1660 for the dynamic linker. */
c434dee6
AJ
1661 srelgot = htab->srelgot;
1662 if (srelgot == NULL)
1663 abort ();
51e0a107 1664
c434dee6
AJ
1665 outrel.r_offset = (htab->sgot->output_section->vma
1666 + htab->sgot->output_offset
51e0a107
JH
1667 + off);
1668 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1669 outrel.r_addend = relocation;
c434dee6
AJ
1670 loc = (Elf64_External_Rela *) srelgot->contents;
1671 loc += srelgot->reloc_count++;
1672 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
51e0a107
JH
1673 }
1674
1675 local_got_offsets[r_symndx] |= 1;
1676 }
51e0a107 1677 }
6a2bda3f 1678
c434dee6
AJ
1679 if (off >= (bfd_vma) -2)
1680 abort ();
1681
1682 relocation = htab->sgot->output_offset + off;
1683 if (r_type == R_X86_64_GOTPCREL)
1684 relocation += htab->sgot->output_section->vma;
1685
70256ad8
AJ
1686 break;
1687
1688 case R_X86_64_PLT32:
1689 /* Relocation is to the entry for this symbol in the
1690 procedure linkage table. */
1691
1692 /* Resolve a PLT32 reloc against a local symbol directly,
407443a3 1693 without using the procedure linkage table. */
70256ad8
AJ
1694 if (h == NULL)
1695 break;
1696
c434dee6
AJ
1697 if (h->plt.offset == (bfd_vma) -1
1698 || htab->splt == NULL)
70256ad8
AJ
1699 {
1700 /* We didn't make a PLT entry for this symbol. This
407443a3
AJ
1701 happens when statically linking PIC code, or when
1702 using -Bsymbolic. */
70256ad8
AJ
1703 break;
1704 }
1705
c434dee6
AJ
1706 relocation = (htab->splt->output_section->vma
1707 + htab->splt->output_offset
70256ad8 1708 + h->plt.offset);
c434dee6 1709 unresolved_reloc = false;
70256ad8
AJ
1710 break;
1711
fd8ab9e5
AJ
1712 case R_X86_64_PC8:
1713 case R_X86_64_PC16:
1714 case R_X86_64_PC32:
70256ad8
AJ
1715 case R_X86_64_8:
1716 case R_X86_64_16:
1717 case R_X86_64_32:
6b3db546 1718 case R_X86_64_64:
80643fbc 1719 /* FIXME: The ABI says the linker should make sure the value is
407443a3 1720 the same when it's zeroextended to 64 bit. */
c434dee6
AJ
1721
1722 /* r_symndx will be zero only for relocs against symbols
1723 from removed linkonce sections, or sections discarded by
1724 a linker script. */
1725 if (r_symndx == 0
1726 || (input_section->flags & SEC_ALLOC) == 0)
1727 break;
1728
1729 if ((info->shared
1730 && ((r_type != R_X86_64_PC8
1731 && r_type != R_X86_64_PC16
1732 && r_type != R_X86_64_PC32)
1733 || (h != NULL
1734 && h->dynindx != -1
1735 && (! info->symbolic
1736 || (h->elf_link_hash_flags
1737 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
1738 || (!info->shared
1739 && h != NULL
1740 && h->dynindx != -1
1741 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
1742 && (((h->elf_link_hash_flags
1743 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1744 && (h->elf_link_hash_flags
1745 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1746 || h->root.type == bfd_link_hash_undefweak
1747 || h->root.type == bfd_link_hash_undefined)))
70256ad8
AJ
1748 {
1749 Elf_Internal_Rela outrel;
1750 boolean skip, relocate;
c434dee6
AJ
1751 asection *sreloc;
1752 Elf64_External_Rela *loc;
70256ad8
AJ
1753
1754 /* When generating a shared object, these relocations
1755 are copied into the output file to be resolved at run
407443a3 1756 time. */
70256ad8 1757
70256ad8 1758 skip = false;
0bb2d96a 1759 relocate = false;
70256ad8 1760
c629eae0
JJ
1761 outrel.r_offset =
1762 _bfd_elf_section_offset (output_bfd, info, input_section,
c434dee6 1763 rel->r_offset);
c629eae0
JJ
1764 if (outrel.r_offset == (bfd_vma) -1)
1765 skip = true;
0fb19cbc 1766 else if (outrel.r_offset == (bfd_vma) -2)
0bb2d96a 1767 skip = true, relocate = true;
70256ad8
AJ
1768
1769 outrel.r_offset += (input_section->output_section->vma
1770 + input_section->output_offset);
1771
1772 if (skip)
0bb2d96a 1773 memset (&outrel, 0, sizeof outrel);
c434dee6 1774
fd8ab9e5
AJ
1775 /* h->dynindx may be -1 if this symbol was marked to
1776 become local. */
1777 else if (h != NULL
c434dee6
AJ
1778 && h->dynindx != -1
1779 && (r_type == R_X86_64_PC8
1780 || r_type == R_X86_64_PC16
1781 || r_type == R_X86_64_PC32
1782 || !info->shared
1783 || !info->symbolic
fd8ab9e5
AJ
1784 || (h->elf_link_hash_flags
1785 & ELF_LINK_HASH_DEF_REGULAR) == 0))
70256ad8 1786 {
70256ad8 1787 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
c434dee6 1788 outrel.r_addend = rel->r_addend;
70256ad8
AJ
1789 }
1790 else
1791 {
c434dee6
AJ
1792 /* This symbol is local, or marked to become local. */
1793 relocate = true;
1794 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1795 outrel.r_addend = relocation + rel->r_addend;
70256ad8
AJ
1796 }
1797
c434dee6
AJ
1798 sreloc = elf_section_data (input_section)->sreloc;
1799 if (sreloc == NULL)
1800 abort ();
1801
1802 loc = (Elf64_External_Rela *) sreloc->contents;
1803 loc += sreloc->reloc_count++;
1804 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
70256ad8
AJ
1805
1806 /* If this reloc is against an external symbol, we do
1807 not want to fiddle with the addend. Otherwise, we
1808 need to include the symbol value so that it becomes
1809 an addend for the dynamic reloc. */
1810 if (! relocate)
1811 continue;
1812 }
1813
1814 break;
1815
1816 default:
1817 break;
1818 }
8d88c4ca 1819
c434dee6
AJ
1820 /* FIXME: Why do we allow debugging sections to escape this error?
1821 More importantly, why do we not emit dynamic relocs for
1822 R_386_32 above in debugging sections (which are ! SEC_ALLOC)?
1823 If we had emitted the dynamic reloc, we could remove the
1824 fudge here. */
1825 if (unresolved_reloc
1826 && !(info->shared
1827 && (input_section->flags & SEC_DEBUGGING) != 0
1828 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1829 (*_bfd_error_handler)
1830 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
1831 bfd_archive_filename (input_bfd),
1832 bfd_get_section_name (input_bfd, input_section),
1833 (long) rel->r_offset,
1834 h->root.root.string);
1835
8d88c4ca 1836 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
c434dee6
AJ
1837 contents, rel->r_offset,
1838 relocation, rel->r_addend);
8d88c4ca
NC
1839
1840 if (r != bfd_reloc_ok)
8da6118f 1841 {
c434dee6
AJ
1842 const char *name;
1843
1844 if (h != NULL)
1845 name = h->root.root.string;
1846 else
8da6118f 1847 {
c434dee6
AJ
1848 name = bfd_elf_string_from_elf_section (input_bfd,
1849 symtab_hdr->sh_link,
1850 sym->st_name);
1851 if (name == NULL)
1852 return false;
1853 if (*name == '\0')
1854 name = bfd_section_name (input_bfd, sec);
1855 }
1856
1857 if (r == bfd_reloc_overflow)
1858 {
1859
1860 if (! ((*info->callbacks->reloc_overflow)
1861 (info, name, howto->name, (bfd_vma) 0,
1862 input_bfd, input_section, rel->r_offset)))
1863 return false;
1864 }
1865 else
1866 {
1867 (*_bfd_error_handler)
1868 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
1869 bfd_archive_filename (input_bfd),
1870 bfd_get_section_name (input_bfd, input_section),
1871 (long) rel->r_offset, name, (int) r);
1872 return false;
8da6118f
KH
1873 }
1874 }
8d88c4ca 1875 }
70256ad8
AJ
1876
1877 return true;
1878}
1879
1880/* Finish up dynamic symbol handling. We set the contents of various
1881 dynamic sections here. */
1882
1883static boolean
1884elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym)
1885 bfd *output_bfd;
1886 struct bfd_link_info *info;
1887 struct elf_link_hash_entry *h;
1888 Elf_Internal_Sym *sym;
1889{
c434dee6 1890 struct elf64_x86_64_link_hash_table *htab;
70256ad8 1891
c434dee6 1892 htab = elf64_x86_64_hash_table (info);
70256ad8
AJ
1893
1894 if (h->plt.offset != (bfd_vma) -1)
1895 {
70256ad8
AJ
1896 bfd_vma plt_index;
1897 bfd_vma got_offset;
1898 Elf_Internal_Rela rela;
c434dee6 1899 Elf64_External_Rela *loc;
70256ad8
AJ
1900
1901 /* This symbol has an entry in the procedure linkage table. Set
407443a3 1902 it up. */
70256ad8 1903
c434dee6
AJ
1904 if (h->dynindx == -1
1905 || htab->splt == NULL
1906 || htab->sgotplt == NULL
1907 || htab->srelplt == NULL)
1908 abort ();
70256ad8
AJ
1909
1910 /* Get the index in the procedure linkage table which
1911 corresponds to this symbol. This is the index of this symbol
1912 in all the symbols for which we are making plt entries. The
1913 first entry in the procedure linkage table is reserved. */
1914 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1915
1916 /* Get the offset into the .got table of the entry that
407443a3 1917 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
fe4770f4 1918 bytes. The first three are reserved for the dynamic linker. */
70256ad8
AJ
1919 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
1920
1921 /* Fill in the entry in the procedure linkage table. */
c434dee6 1922 memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
70256ad8
AJ
1923 PLT_ENTRY_SIZE);
1924
1925 /* Insert the relocation positions of the plt section. The magic
1926 numbers at the end of the statements are the positions of the
1927 relocations in the plt section. */
653165cc
AJ
1928 /* Put offset for jmp *name@GOTPCREL(%rip), since the
1929 instruction uses 6 bytes, subtract this value. */
1930 bfd_put_32 (output_bfd,
c434dee6
AJ
1931 (htab->sgotplt->output_section->vma
1932 + htab->sgotplt->output_offset
653165cc 1933 + got_offset
c434dee6
AJ
1934 - htab->splt->output_section->vma
1935 - htab->splt->output_offset
653165cc
AJ
1936 - h->plt.offset
1937 - 6),
c434dee6 1938 htab->splt->contents + h->plt.offset + 2);
653165cc
AJ
1939 /* Put relocation index. */
1940 bfd_put_32 (output_bfd, plt_index,
c434dee6 1941 htab->splt->contents + h->plt.offset + 7);
653165cc
AJ
1942 /* Put offset for jmp .PLT0. */
1943 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
c434dee6 1944 htab->splt->contents + h->plt.offset + 12);
70256ad8 1945
653165cc
AJ
1946 /* Fill in the entry in the global offset table, initially this
1947 points to the pushq instruction in the PLT which is at offset 6. */
c434dee6
AJ
1948 bfd_put_64 (output_bfd, (htab->splt->output_section->vma
1949 + htab->splt->output_offset
70256ad8 1950 + h->plt.offset + 6),
c434dee6 1951 htab->sgotplt->contents + got_offset);
70256ad8
AJ
1952
1953 /* Fill in the entry in the .rela.plt section. */
c434dee6
AJ
1954 rela.r_offset = (htab->sgotplt->output_section->vma
1955 + htab->sgotplt->output_offset
70256ad8
AJ
1956 + got_offset);
1957 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
1958 rela.r_addend = 0;
c434dee6
AJ
1959 loc = (Elf64_External_Rela *) htab->srelplt->contents + plt_index;
1960 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
70256ad8
AJ
1961
1962 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1963 {
1964 /* Mark the symbol as undefined, rather than as defined in
c434dee6
AJ
1965 the .plt section. Leave the value alone. This is a clue
1966 for the dynamic linker, to make function pointer
1967 comparisons work between an application and shared
1968 library. */
70256ad8
AJ
1969 sym->st_shndx = SHN_UNDEF;
1970 }
1971 }
1972
053579d7
AJ
1973 if (h->got.offset != (bfd_vma) -1)
1974 {
053579d7 1975 Elf_Internal_Rela rela;
c434dee6 1976 Elf64_External_Rela *loc;
053579d7
AJ
1977
1978 /* This symbol has an entry in the global offset table. Set it
1979 up. */
1980
c434dee6
AJ
1981 if (htab->sgot == NULL || htab->srelgot == NULL)
1982 abort ();
053579d7 1983
c434dee6
AJ
1984 rela.r_offset = (htab->sgot->output_section->vma
1985 + htab->sgot->output_offset
dc810e39 1986 + (h->got.offset &~ (bfd_vma) 1));
053579d7
AJ
1987
1988 /* If this is a static link, or it is a -Bsymbolic link and the
1989 symbol is defined locally or was forced to be local because
1990 of a version file, we just want to emit a RELATIVE reloc.
1991 The entry in the global offset table will already have been
1992 initialized in the relocate_section function. */
c434dee6
AJ
1993 if (info->shared
1994 && (info->symbolic
1995 || h->dynindx == -1
1996 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
1997 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
053579d7 1998 {
cc78d0af 1999 BFD_ASSERT((h->got.offset & 1) != 0);
053579d7
AJ
2000 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
2001 rela.r_addend = (h->root.u.def.value
2002 + h->root.u.def.section->output_section->vma
2003 + h->root.u.def.section->output_offset);
2004 }
2005 else
2006 {
2007 BFD_ASSERT((h->got.offset & 1) == 0);
c434dee6
AJ
2008 bfd_put_64 (output_bfd, (bfd_vma) 0,
2009 htab->sgot->contents + h->got.offset);
053579d7
AJ
2010 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
2011 rela.r_addend = 0;
2012 }
2013
c434dee6
AJ
2014 loc = (Elf64_External_Rela *) htab->srelgot->contents;
2015 loc += htab->srelgot->reloc_count++;
2016 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
053579d7
AJ
2017 }
2018
70256ad8
AJ
2019 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2020 {
70256ad8 2021 Elf_Internal_Rela rela;
c434dee6 2022 Elf64_External_Rela *loc;
70256ad8
AJ
2023
2024 /* This symbol needs a copy reloc. Set it up. */
2025
c434dee6
AJ
2026 if (h->dynindx == -1
2027 || (h->root.type != bfd_link_hash_defined
2028 && h->root.type != bfd_link_hash_defweak)
2029 || htab->srelbss == NULL)
2030 abort ();
70256ad8
AJ
2031
2032 rela.r_offset = (h->root.u.def.value
2033 + h->root.u.def.section->output_section->vma
2034 + h->root.u.def.section->output_offset);
2035 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
2036 rela.r_addend = 0;
c434dee6
AJ
2037 loc = (Elf64_External_Rela *) htab->srelbss->contents;
2038 loc += htab->srelbss->reloc_count++;
2039 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
70256ad8
AJ
2040 }
2041
2042 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2043 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2044 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2045 sym->st_shndx = SHN_ABS;
2046
2047 return true;
2048}
2049
c434dee6
AJ
2050/* Used to decide how to sort relocs in an optimal manner for the
2051 dynamic linker, before writing them out. */
2052
2053static enum elf_reloc_type_class
2054elf64_x86_64_reloc_type_class (rela)
2055 const Elf_Internal_Rela *rela;
2056{
2057 switch ((int) ELF64_R_TYPE (rela->r_info))
2058 {
2059 case R_X86_64_RELATIVE:
2060 return reloc_class_relative;
2061 case R_X86_64_JUMP_SLOT:
2062 return reloc_class_plt;
2063 case R_X86_64_COPY:
2064 return reloc_class_copy;
2065 default:
2066 return reloc_class_normal;
2067 }
2068}
2069
70256ad8
AJ
2070/* Finish up the dynamic sections. */
2071
2072static boolean
2073elf64_x86_64_finish_dynamic_sections (output_bfd, info)
2074 bfd *output_bfd;
2075 struct bfd_link_info *info;
2076{
c434dee6 2077 struct elf64_x86_64_link_hash_table *htab;
70256ad8
AJ
2078 bfd *dynobj;
2079 asection *sdyn;
70256ad8 2080
c434dee6
AJ
2081 htab = elf64_x86_64_hash_table (info);
2082 dynobj = htab->elf.dynobj;
70256ad8
AJ
2083 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2084
c434dee6 2085 if (htab->elf.dynamic_sections_created)
70256ad8 2086 {
70256ad8
AJ
2087 Elf64_External_Dyn *dyncon, *dynconend;
2088
c434dee6
AJ
2089 if (sdyn == NULL || htab->sgot == NULL)
2090 abort ();
70256ad8
AJ
2091
2092 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2093 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2094 for (; dyncon < dynconend; dyncon++)
2095 {
2096 Elf_Internal_Dyn dyn;
70256ad8
AJ
2097 asection *s;
2098
2099 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2100
2101 switch (dyn.d_tag)
2102 {
2103 default:
053579d7 2104 continue;
70256ad8
AJ
2105
2106 case DT_PLTGOT:
c434dee6
AJ
2107 dyn.d_un.d_ptr = htab->sgot->output_section->vma;
2108 break;
70256ad8
AJ
2109
2110 case DT_JMPREL:
c434dee6
AJ
2111 dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
2112 break;
70256ad8 2113
c434dee6
AJ
2114 case DT_PLTRELSZ:
2115 s = htab->srelplt->output_section;
2116 if (s->_cooked_size != 0)
2117 dyn.d_un.d_val = s->_cooked_size;
2118 else
2119 dyn.d_un.d_val = s->_raw_size;
70256ad8
AJ
2120 break;
2121
2122 case DT_RELASZ:
c434dee6
AJ
2123 /* The procedure linkage table relocs (DT_JMPREL) should
2124 not be included in the overall relocs (DT_RELA).
2125 Therefore, we override the DT_RELASZ entry here to
2126 make it not include the JMPREL relocs. Since the
2127 linker script arranges for .rela.plt to follow all
2128 other relocation sections, we don't have to worry
2129 about changing the DT_RELA entry. */
2130 if (htab->srelplt != NULL)
70256ad8 2131 {
c434dee6
AJ
2132 s = htab->srelplt->output_section;
2133 if (s->_cooked_size != 0)
2134 dyn.d_un.d_val -= s->_cooked_size;
2135 else
2136 dyn.d_un.d_val -= s->_raw_size;
70256ad8
AJ
2137 }
2138 break;
70256ad8 2139 }
c434dee6 2140
70256ad8
AJ
2141 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2142 }
2143
c434dee6
AJ
2144 /* Fill in the special first entry in the procedure linkage table. */
2145 if (htab->splt && htab->splt->_raw_size > 0)
70256ad8 2146 {
653165cc 2147 /* Fill in the first entry in the procedure linkage table. */
c434dee6
AJ
2148 memcpy (htab->splt->contents, elf64_x86_64_plt0_entry,
2149 PLT_ENTRY_SIZE);
653165cc
AJ
2150 /* Add offset for pushq GOT+8(%rip), since the instruction
2151 uses 6 bytes subtract this value. */
2152 bfd_put_32 (output_bfd,
c434dee6
AJ
2153 (htab->sgotplt->output_section->vma
2154 + htab->sgotplt->output_offset
653165cc 2155 + 8
c434dee6
AJ
2156 - htab->splt->output_section->vma
2157 - htab->splt->output_offset
653165cc 2158 - 6),
c434dee6 2159 htab->splt->contents + 2);
653165cc
AJ
2160 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
2161 the end of the instruction. */
2162 bfd_put_32 (output_bfd,
c434dee6
AJ
2163 (htab->sgotplt->output_section->vma
2164 + htab->sgotplt->output_offset
653165cc 2165 + 16
c434dee6
AJ
2166 - htab->splt->output_section->vma
2167 - htab->splt->output_offset
653165cc 2168 - 12),
c434dee6 2169 htab->splt->contents + 8);
653165cc 2170
c434dee6
AJ
2171 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize =
2172 PLT_ENTRY_SIZE;
70256ad8 2173 }
70256ad8
AJ
2174 }
2175
c434dee6 2176 if (htab->sgotplt)
70256ad8 2177 {
c434dee6
AJ
2178 /* Fill in the first three entries in the global offset table. */
2179 if (htab->sgotplt->_raw_size > 0)
2180 {
2181 /* Set the first entry in the global offset table to the address of
2182 the dynamic section. */
2183 if (sdyn == NULL)
2184 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents);
2185 else
2186 bfd_put_64 (output_bfd,
2187 sdyn->output_section->vma + sdyn->output_offset,
2188 htab->sgotplt->contents);
2189 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
2190 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE);
2191 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2);
2192 }
70256ad8 2193
c434dee6
AJ
2194 elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize =
2195 GOT_ENTRY_SIZE;
2196 }
70256ad8 2197
8d88c4ca
NC
2198 return true;
2199}
2200
8df9fc9d 2201
70256ad8
AJ
2202#define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
2203#define TARGET_LITTLE_NAME "elf64-x86-64"
2204#define ELF_ARCH bfd_arch_i386
2205#define ELF_MACHINE_CODE EM_X86_64
2206#define ELF_MAXPAGESIZE 0x100000
2207
2208#define elf_backend_can_gc_sections 1
51b64d56 2209#define elf_backend_can_refcount 1
70256ad8
AJ
2210#define elf_backend_want_got_plt 1
2211#define elf_backend_plt_readonly 1
2212#define elf_backend_want_plt_sym 0
2213#define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
2214#define elf_backend_plt_header_size PLT_ENTRY_SIZE
b491616a 2215#define elf_backend_rela_normal 1
70256ad8
AJ
2216
2217#define elf_info_to_howto elf64_x86_64_info_to_howto
70256ad8 2218
70256ad8
AJ
2219#define bfd_elf64_bfd_link_hash_table_create \
2220 elf64_x86_64_link_hash_table_create
407443a3 2221#define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
70256ad8
AJ
2222
2223#define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
2224#define elf_backend_check_relocs elf64_x86_64_check_relocs
c434dee6
AJ
2225#define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
2226#define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
2227#define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections
70256ad8
AJ
2228#define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
2229#define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
2230#define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
c434dee6 2231#define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class
70256ad8
AJ
2232#define elf_backend_relocate_section elf64_x86_64_relocate_section
2233#define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
407443a3 2234#define elf_backend_object_p elf64_x86_64_elf_object_p
8d88c4ca
NC
2235
2236#include "elf64-target.h"
This page took 0.197068 seconds and 4 git commands to generate.