source: trunk/src/binutils/bfd/elf64-x86-64.c@ 536

Last change on this file since 536 was 10, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 59.0 KB
Line 
1/* X86-64 specific support for 64-bit ELF
2 Copyright 2000, 2001 Free Software Foundation, Inc.
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"
23#include "libbfd.h"
24#include "elf-bfd.h"
25
26#include "elf/x86-64.h"
27
28/* We use only the RELA entries. */
29#define USE_RELA
30
31/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
32#define MINUS_ONE (~ (bfd_vma) 0)
33
34/* The relocation "howto" table. Order of fields:
35 type, size, bitsize, pc_relative, complain_on_overflow,
36 special_function, name, partial_inplace, src_mask, dst_pack, pcrel_offset. */
37static reloc_howto_type x86_64_elf_howto_table[] =
38{
39 HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont,
40 bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0x00000000, 0x00000000,
41 false),
42 HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
43 bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE,
44 false),
45 HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed,
46 bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff,
47 true),
48 HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed,
49 bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff,
50 false),
51 HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed,
52 bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff,
53 true),
54 HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield,
55 bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff,
56 false),
57 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
58 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE,
59 MINUS_ONE, false),
60 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
61 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE,
62 MINUS_ONE, false),
63 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
64 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE,
65 MINUS_ONE, false),
66 HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true,0 , complain_overflow_signed,
67 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0xffffffff,
68 0xffffffff, true),
69 HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned,
70 bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
71 false),
72 HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed,
73 bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff,
74 false),
75 HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
76 bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false),
77 HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield,
78 bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true),
79 HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_signed,
80 bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false),
81 HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
82 bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true)
83};
84
85/* Map BFD relocs to the x86_64 elf relocs. */
86struct elf_reloc_map
87{
88 bfd_reloc_code_real_type bfd_reloc_val;
89 unsigned char elf_reloc_val;
90};
91
92static CONST struct elf_reloc_map x86_64_reloc_map[] =
93{
94 { BFD_RELOC_NONE, R_X86_64_NONE, },
95 { BFD_RELOC_64, R_X86_64_64, },
96 { BFD_RELOC_32_PCREL, R_X86_64_PC32, },
97 { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,},
98 { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,},
99 { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, },
100 { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, },
101 { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, },
102 { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, },
103 { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, },
104 { BFD_RELOC_32, R_X86_64_32, },
105 { BFD_RELOC_X86_64_32S, R_X86_64_32S, },
106 { BFD_RELOC_16, R_X86_64_16, },
107 { BFD_RELOC_16_PCREL, R_X86_64_PC16, },
108 { BFD_RELOC_8, R_X86_64_8, },
109 { BFD_RELOC_8_PCREL, R_X86_64_PC8, },
110};
111
112static reloc_howto_type *elf64_x86_64_reloc_type_lookup
113 PARAMS ((bfd *, bfd_reloc_code_real_type));
114static void elf64_x86_64_info_to_howto
115 PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
116static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create
117 PARAMS ((bfd *));
118
119static struct bfd_hash_entry *elf64_x86_64_link_hash_newfunc
120 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
121static boolean elf64_x86_64_adjust_dynamic_symbol
122 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
123
124static boolean elf64_x86_64_size_dynamic_sections
125 PARAMS ((bfd *, struct bfd_link_info *));
126static boolean elf64_x86_64_relocate_section
127 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
128 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
129static boolean elf64_x86_64_finish_dynamic_symbol
130 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
131 Elf_Internal_Sym *sym));
132static boolean elf64_x86_64_finish_dynamic_sections
133 PARAMS ((bfd *, struct bfd_link_info *));
134
135/* Given a BFD reloc type, return a HOWTO structure. */
136static reloc_howto_type *
137elf64_x86_64_reloc_type_lookup (abfd, code)
138 bfd *abfd ATTRIBUTE_UNUSED;
139 bfd_reloc_code_real_type code;
140{
141 unsigned int i;
142 for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map);
143 i++)
144 {
145 if (x86_64_reloc_map[i].bfd_reloc_val == code)
146 return &x86_64_elf_howto_table[(int)
147 x86_64_reloc_map[i].elf_reloc_val];
148 }
149 return 0;
150}
151
152/* Given an x86_64 ELF reloc type, fill in an arelent structure. */
153
154static void
155elf64_x86_64_info_to_howto (abfd, cache_ptr, dst)
156 bfd *abfd ATTRIBUTE_UNUSED;
157 arelent *cache_ptr;
158 Elf64_Internal_Rela *dst;
159{
160 unsigned r_type;
161
162 r_type = ELF64_R_TYPE (dst->r_info);
163 BFD_ASSERT (r_type < (unsigned int) R_X86_64_max);
164 cache_ptr->howto = &x86_64_elf_howto_table[r_type];
165 BFD_ASSERT (r_type == cache_ptr->howto->type);
166}
167
168
169/* Functions for the x86-64 ELF linker. */
170
171/* The name of the dynamic interpreter. This is put in the .interp
172 section. */
173
174#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
175
176/* The size in bytes of an entry in the global offset table. */
177
178#define GOT_ENTRY_SIZE 8
179
180/* The size in bytes of an entry in the procedure linkage table. */
181
182#define PLT_ENTRY_SIZE 16
183
184/* The first entry in a procedure linkage table looks like this. See the
185 SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */
186
187static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] =
188{
189 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
190 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */
191 0x90, 0x90, 0x90, 0x90 /* pad out to 16 bytes with nops. */
192};
193
194/* Subsequent entries in a procedure linkage table look like this. */
195
196static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] =
197{
198 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */
199 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */
200 0x68, /* pushq immediate */
201 0, 0, 0, 0, /* replaced with index into relocation table. */
202 0xe9, /* jmp relative */
203 0, 0, 0, 0 /* replaced with offset to start of .plt0. */
204};
205
206/* The x86-64 linker needs to keep track of the number of relocs that
207 it decides to copy in check_relocs for each symbol. This is so
208 that it can discard PC relative relocs if it doesn't need them when
209 linking with -Bsymbolic. We store the information in a field
210 extending the regular ELF linker hash table. */
211
212/* This structure keeps track of the number of PC relative relocs we
213 have copied for a given symbol. */
214
215struct elf64_x86_64_pcrel_relocs_copied
216{
217 /* Next section. */
218 struct elf64_x86_64_pcrel_relocs_copied *next;
219 /* A section in dynobj. */
220 asection *section;
221 /* Number of relocs copied in this section. */
222 bfd_size_type count;
223};
224
225/* x86-64 ELF linker hash entry. */
226
227struct elf64_x86_64_link_hash_entry
228{
229 struct elf_link_hash_entry root;
230
231 /* Number of PC relative relocs copied for this symbol. */
232 struct elf64_x86_64_pcrel_relocs_copied *pcrel_relocs_copied;
233};
234
235/* x86-64 ELF linker hash table. */
236
237struct elf64_x86_64_link_hash_table
238{
239 struct elf_link_hash_table root;
240};
241
242/* Declare this now that the above structures are defined. */
243
244static boolean elf64_x86_64_discard_copies
245 PARAMS ((struct elf64_x86_64_link_hash_entry *, PTR));
246
247/* Traverse an x86-64 ELF linker hash table. */
248
249#define elf64_x86_64_link_hash_traverse(table, func, info) \
250 (elf_link_hash_traverse \
251 (&(table)->root, \
252 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
253 (info)))
254
255/* Get the x86-64 ELF linker hash table from a link_info structure. */
256
257#define elf64_x86_64_hash_table(p) \
258 ((struct elf64_x86_64_link_hash_table *) ((p)->hash))
259
260/* Create an entry in an x86-64 ELF linker hash table. */
261
262static struct bfd_hash_entry *
263elf64_x86_64_link_hash_newfunc (entry, table, string)
264 struct bfd_hash_entry *entry;
265 struct bfd_hash_table *table;
266 const char *string;
267{
268 struct elf64_x86_64_link_hash_entry *ret =
269 (struct elf64_x86_64_link_hash_entry *) entry;
270
271 /* Allocate the structure if it has not already been allocated by a
272 subclass. */
273 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
274 ret = ((struct elf64_x86_64_link_hash_entry *)
275 bfd_hash_allocate (table,
276 sizeof (struct elf64_x86_64_link_hash_entry)));
277 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL)
278 return (struct bfd_hash_entry *) ret;
279
280 /* Call the allocation method of the superclass. */
281 ret = ((struct elf64_x86_64_link_hash_entry *)
282 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
283 table, string));
284 if (ret != (struct elf64_x86_64_link_hash_entry *) NULL)
285 {
286 ret->pcrel_relocs_copied = NULL;
287 }
288
289 return (struct bfd_hash_entry *) ret;
290}
291
292/* Create an X86-64 ELF linker hash table. */
293
294static struct bfd_link_hash_table *
295elf64_x86_64_link_hash_table_create (abfd)
296 bfd *abfd;
297{
298 struct elf64_x86_64_link_hash_table *ret;
299
300 ret = ((struct elf64_x86_64_link_hash_table *)
301 bfd_alloc (abfd, sizeof (struct elf64_x86_64_link_hash_table)));
302 if (ret == (struct elf64_x86_64_link_hash_table *) NULL)
303 return NULL;
304
305 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
306 elf64_x86_64_link_hash_newfunc))
307 {
308 bfd_release (abfd, ret);
309 return NULL;
310 }
311
312 return &ret->root.root;
313}
314
315boolean
316elf64_x86_64_elf_object_p (abfd)
317 bfd *abfd;
318{
319 /* Set the right machine number for an x86-64 elf64 file. */
320 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
321 return true;
322}
323
324/* Look through the relocs for a section during the first phase, and
325 allocate space in the global offset table or procedure linkage
326 table. */
327
328static boolean
329elf64_x86_64_check_relocs (abfd, info, sec, relocs)
330 bfd *abfd;
331 struct bfd_link_info *info;
332 asection *sec;
333 const Elf_Internal_Rela *relocs;
334{
335 bfd *dynobj;
336 Elf_Internal_Shdr *symtab_hdr;
337 struct elf_link_hash_entry **sym_hashes;
338 bfd_signed_vma *local_got_refcounts;
339 const Elf_Internal_Rela *rel;
340 const Elf_Internal_Rela *rel_end;
341 asection *sgot;
342 asection *srelgot;
343 asection *sreloc;
344
345 if (info->relocateable)
346 return true;
347
348 dynobj = elf_hash_table (info)->dynobj;
349 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
350 sym_hashes = elf_sym_hashes (abfd);
351 local_got_refcounts = elf_local_got_refcounts (abfd);
352
353 sgot = srelgot = sreloc = NULL;
354 rel_end = relocs + sec->reloc_count;
355 for (rel = relocs; rel < rel_end; rel++)
356 {
357 unsigned long r_symndx;
358 struct elf_link_hash_entry *h;
359
360 r_symndx = ELF64_R_SYM (rel->r_info);
361 if (r_symndx < symtab_hdr->sh_info)
362 h = NULL;
363 else
364 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
365
366 /* Some relocs require a global offset table. */
367 if (dynobj == NULL)
368 {
369 switch (ELF64_R_TYPE (rel->r_info))
370 {
371 case R_X86_64_GOT32:
372 case R_X86_64_GOTPCREL:
373 elf_hash_table (info)->dynobj = dynobj = abfd;
374 if (! _bfd_elf_create_got_section (dynobj, info))
375 return false;
376 break;
377 }
378 }
379
380 switch (ELF64_R_TYPE (rel->r_info))
381 {
382 case R_X86_64_GOTPCREL:
383 case R_X86_64_GOT32:
384 /* This symbol requires a global offset table entry. */
385
386 if (sgot == NULL)
387 {
388 sgot = bfd_get_section_by_name (dynobj, ".got");
389 BFD_ASSERT (sgot != NULL);
390 }
391
392 if (srelgot == NULL && (h != NULL || info->shared))
393 {
394 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
395 if (srelgot == NULL)
396 {
397 srelgot = bfd_make_section (dynobj, ".rela.got");
398 if (srelgot == NULL
399 || ! bfd_set_section_flags (dynobj, srelgot,
400 (SEC_ALLOC
401 | SEC_LOAD
402 | SEC_HAS_CONTENTS
403 | SEC_IN_MEMORY
404 | SEC_LINKER_CREATED
405 | SEC_READONLY))
406 || ! bfd_set_section_alignment (dynobj, srelgot, 3))
407 return false;
408 }
409 }
410
411 if (h != NULL)
412 {
413 if (h->got.refcount == -1)
414 {
415 h->got.refcount = 1;
416
417 /* Make sure this symbol is output as a dynamic symbol. */
418 if (h->dynindx == -1)
419 {
420 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
421 return false;
422 }
423
424 sgot->_raw_size += GOT_ENTRY_SIZE;
425 srelgot->_raw_size += sizeof (Elf64_External_Rela);
426 }
427 else
428 h->got.refcount += 1;
429 }
430 else
431 {
432 /* This is a global offset table entry for a local symbol. */
433 if (local_got_refcounts == NULL)
434 {
435 size_t size;
436
437 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
438 local_got_refcounts = ((bfd_signed_vma *)
439 bfd_alloc (abfd, size));
440 if (local_got_refcounts == NULL)
441 return false;
442 elf_local_got_refcounts (abfd) = local_got_refcounts;
443 memset (local_got_refcounts, -1, size);
444 }
445 if (local_got_refcounts[r_symndx] == -1)
446 {
447 local_got_refcounts[r_symndx] = 1;
448
449 sgot->_raw_size += GOT_ENTRY_SIZE;
450 if (info->shared)
451 {
452 /* If we are generating a shared object, we need to
453 output a R_X86_64_RELATIVE reloc so that the dynamic
454 linker can adjust this GOT entry. */
455 srelgot->_raw_size += sizeof (Elf64_External_Rela);
456 }
457 }
458 else
459 local_got_refcounts[r_symndx] += 1;
460 }
461 break;
462
463 case R_X86_64_PLT32:
464 /* This symbol requires a procedure linkage table entry. We
465 actually build the entry in adjust_dynamic_symbol,
466 because this might be a case of linking PIC code which is
467 never referenced by a dynamic object, in which case we
468 don't need to generate a procedure linkage table entry
469 after all. */
470
471 /* If this is a local symbol, we resolve it directly without
472 creating a procedure linkage table entry. */
473 if (h == NULL)
474 continue;
475
476 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
477 if (h->plt.refcount == -1)
478 h->plt.refcount = 1;
479 else
480 h->plt.refcount += 1;
481 break;
482
483 case R_X86_64_8:
484 case R_X86_64_16:
485 case R_X86_64_32:
486 case R_X86_64_64:
487 case R_X86_64_32S:
488 case R_X86_64_PC32:
489 if (h != NULL)
490 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
491
492 /* If we are creating a shared library, and this is a reloc
493 against a global symbol, or a non PC relative reloc
494 against a local symbol, then we need to copy the reloc
495 into the shared library. However, if we are linking with
496 -Bsymbolic, we do not need to copy a reloc against a
497 global symbol which is defined in an object we are
498 including in the link (i.e., DEF_REGULAR is set). At
499 this point we have not seen all the input files, so it is
500 possible that DEF_REGULAR is not set now but will be set
501 later (it is never cleared). We account for that
502 possibility below by storing information in the
503 pcrel_relocs_copied field of the hash table entry.
504 A similar situation occurs when creating shared libraries
505 and symbol visibility changes render the symbol local. */
506 if (info->shared
507 && (sec->flags & SEC_ALLOC) != 0
508 && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8)
509 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16)
510 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32))
511 || (h != NULL
512 && (! info->symbolic
513 || (h->elf_link_hash_flags
514 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
515 {
516 /* When creating a shared object, we must copy these
517 reloc types into the output file. We create a reloc
518 section in dynobj and make room for this reloc. */
519 if (sreloc == NULL)
520 {
521 const char *name;
522
523 name = (bfd_elf_string_from_elf_section
524 (abfd,
525 elf_elfheader (abfd)->e_shstrndx,
526 elf_section_data (sec)->rel_hdr.sh_name));
527 if (name == NULL)
528 return false;
529
530 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
531 && strcmp (bfd_get_section_name (abfd, sec),
532 name + 5) == 0);
533
534 sreloc = bfd_get_section_by_name (dynobj, name);
535 if (sreloc == NULL)
536 {
537 flagword flags;
538
539 sreloc = bfd_make_section (dynobj, name);
540 flags = (SEC_HAS_CONTENTS | SEC_READONLY
541 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
542 if ((sec->flags & SEC_ALLOC) != 0)
543 flags |= SEC_ALLOC | SEC_LOAD;
544 if (sreloc == NULL
545 || ! bfd_set_section_flags (dynobj, sreloc, flags)
546 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
547 return false;
548 }
549 }
550
551 sreloc->_raw_size += sizeof (Elf64_External_Rela);
552
553 /* If this is a global symbol, we count the number of PC
554 relative relocations we have entered for this symbol,
555 so that we can discard them later as necessary. Note
556 that this function is only called if we are using an
557 elf64_x86_64 linker hash table, which means that h is
558 really a pointer to an elf64_x86_64_link_hash_entry. */
559 if (h != NULL
560 && ((ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8)
561 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16)
562 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)))
563 {
564 struct elf64_x86_64_link_hash_entry *eh;
565 struct elf64_x86_64_pcrel_relocs_copied *p;
566
567 eh = (struct elf64_x86_64_link_hash_entry *) h;
568
569 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
570 if (p->section == sreloc)
571 break;
572
573 if (p == NULL)
574 {
575 p = ((struct elf64_x86_64_pcrel_relocs_copied *)
576 bfd_alloc (dynobj, sizeof *p));
577 if (p == NULL)
578 return false;
579 p->next = eh->pcrel_relocs_copied;
580 eh->pcrel_relocs_copied = p;
581 p->section = sreloc;
582 p->count = 0;
583 }
584
585 ++p->count;
586 }
587 }
588 break;
589 }
590 }
591
592 return true;
593}
594
595/* Return the section that should be marked against GC for a given
596 relocation. */
597
598static asection *
599elf64_x86_64_gc_mark_hook (abfd, info, rel, h, sym)
600 bfd *abfd;
601 struct bfd_link_info *info ATTRIBUTE_UNUSED;
602 Elf_Internal_Rela *rel ATTRIBUTE_UNUSED;
603 struct elf_link_hash_entry *h;
604 Elf_Internal_Sym *sym;
605{
606 if (h != NULL)
607 {
608 switch (h->root.type)
609 {
610 case bfd_link_hash_defined:
611 case bfd_link_hash_defweak:
612 return h->root.u.def.section;
613
614 case bfd_link_hash_common:
615 return h->root.u.c.p->section;
616
617 default:
618 break;
619 }
620 }
621 else
622 {
623 if (!(elf_bad_symtab (abfd)
624 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
625 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
626 && sym->st_shndx != SHN_COMMON))
627 {
628 return bfd_section_from_elf_index (abfd, sym->st_shndx);
629 }
630 }
631
632 return NULL;
633}
634
635/* Update the got entry reference counts for the section being removed. */
636
637static boolean
638elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs)
639 bfd *abfd;
640 struct bfd_link_info *info ATTRIBUTE_UNUSED;
641 asection *sec;
642 const Elf_Internal_Rela *relocs;
643{
644 Elf_Internal_Shdr *symtab_hdr;
645 struct elf_link_hash_entry **sym_hashes;
646 bfd_signed_vma *local_got_refcounts;
647 const Elf_Internal_Rela *rel, *relend;
648 unsigned long r_symndx;
649 struct elf_link_hash_entry *h;
650 bfd *dynobj;
651 asection *sgot;
652 asection *srelgot;
653
654 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
655 sym_hashes = elf_sym_hashes (abfd);
656 local_got_refcounts = elf_local_got_refcounts (abfd);
657
658 dynobj = elf_hash_table (info)->dynobj;
659 if (dynobj == NULL)
660 return true;
661
662 sgot = bfd_get_section_by_name (dynobj, ".got");
663 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
664
665 relend = relocs + sec->reloc_count;
666 for (rel = relocs; rel < relend; rel++)
667 switch (ELF64_R_TYPE (rel->r_info))
668 {
669 case R_X86_64_GOT32:
670 case R_X86_64_GOTPCREL:
671 r_symndx = ELF64_R_SYM (rel->r_info);
672 if (r_symndx >= symtab_hdr->sh_info)
673 {
674 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
675 if (h->got.refcount > 0)
676 {
677 h->got.refcount -= 1;
678 if (h->got.refcount == 0)
679 {
680 sgot->_raw_size -= GOT_ENTRY_SIZE;
681 srelgot->_raw_size -= sizeof (Elf64_External_Rela);
682 }
683 }
684 }
685 else if (local_got_refcounts != NULL)
686 {
687 if (local_got_refcounts[r_symndx] > 0)
688 {
689 local_got_refcounts[r_symndx] -= 1;
690 if (local_got_refcounts[r_symndx] == 0)
691 {
692 sgot->_raw_size -= GOT_ENTRY_SIZE;
693 if (info->shared)
694 srelgot->_raw_size -= sizeof (Elf64_External_Rela);
695 }
696 }
697 }
698 break;
699
700 case R_X86_64_PLT32:
701 r_symndx = ELF64_R_SYM (rel->r_info);
702 if (r_symndx >= symtab_hdr->sh_info)
703 {
704 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
705 if (h->plt.refcount > 0)
706 h->plt.refcount -= 1;
707 }
708 break;
709
710 default:
711 break;
712 }
713
714 return true;
715}
716
717/* Adjust a symbol defined by a dynamic object and referenced by a
718 regular object. The current definition is in some section of the
719 dynamic object, but we're not including those sections. We have to
720 change the definition to something the rest of the link can
721 understand. */
722
723static boolean
724elf64_x86_64_adjust_dynamic_symbol (info, h)
725 struct bfd_link_info *info;
726 struct elf_link_hash_entry *h;
727{
728 bfd *dynobj;
729 asection *s;
730 unsigned int power_of_two;
731
732 dynobj = elf_hash_table (info)->dynobj;
733
734 /* Make sure we know what is going on here. */
735 BFD_ASSERT (dynobj != NULL
736 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
737 || h->weakdef != NULL
738 || ((h->elf_link_hash_flags
739 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
740 && (h->elf_link_hash_flags
741 & ELF_LINK_HASH_REF_REGULAR) != 0
742 && (h->elf_link_hash_flags
743 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
744
745 /* If this is a function, put it in the procedure linkage table. We
746 will fill in the contents of the procedure linkage table later,
747 when we know the address of the .got section. */
748 if (h->type == STT_FUNC
749 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
750 {
751 if ((! info->shared
752 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
753 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
754 || (info->shared && h->plt.refcount <= 0))
755 {
756 /* This case can occur if we saw a PLT32 reloc in an input
757 file, but the symbol was never referred to by a dynamic
758 object, or if all references were garbage collected. In
759 such a case, we don't actually need to build a procedure
760 linkage table, and we can just do a PC32 reloc instead. */
761 h->plt.offset = (bfd_vma) -1;
762 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
763 return true;
764 }
765
766 /* Make sure this symbol is output as a dynamic symbol. */
767 if (h->dynindx == -1)
768 {
769 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
770 return false;
771 }
772
773 s = bfd_get_section_by_name (dynobj, ".plt");
774 BFD_ASSERT (s != NULL);
775
776 /* If this is the first .plt entry, make room for the special
777 first entry. */
778 if (s->_raw_size == 0)
779 s->_raw_size = PLT_ENTRY_SIZE;
780
781 /* If this symbol is not defined in a regular file, and we are
782 not generating a shared library, then set the symbol to this
783 location in the .plt. This is required to make function
784 pointers compare as equal between the normal executable and
785 the shared library. */
786 if (! info->shared
787 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
788 {
789 h->root.u.def.section = s;
790 h->root.u.def.value = s->_raw_size;
791 }
792
793 h->plt.offset = s->_raw_size;
794
795 /* Make room for this entry. */
796 s->_raw_size += PLT_ENTRY_SIZE;
797
798 /* We also need to make an entry in the .got.plt section, which
799 will be placed in the .got section by the linker script. */
800 s = bfd_get_section_by_name (dynobj, ".got.plt");
801 BFD_ASSERT (s != NULL);
802 s->_raw_size += GOT_ENTRY_SIZE;
803
804 /* We also need to make an entry in the .rela.plt section. */
805 s = bfd_get_section_by_name (dynobj, ".rela.plt");
806 BFD_ASSERT (s != NULL);
807 s->_raw_size += sizeof (Elf64_External_Rela);
808
809 return true;
810 }
811
812 /* If this is a weak symbol, and there is a real definition, the
813 processor independent code will have arranged for us to see the
814 real definition first, and we can just use the same value. */
815 if (h->weakdef != NULL)
816 {
817 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
818 || h->weakdef->root.type == bfd_link_hash_defweak);
819 h->root.u.def.section = h->weakdef->root.u.def.section;
820 h->root.u.def.value = h->weakdef->root.u.def.value;
821 return true;
822 }
823
824 /* This is a reference to a symbol defined by a dynamic object which
825 is not a function. */
826
827 /* If we are creating a shared library, we must presume that the
828 only references to the symbol are via the global offset table.
829 For such cases we need not do anything here; the relocations will
830 be handled correctly by relocate_section. */
831 if (info->shared)
832 return true;
833
834 /* If there are no references to this symbol that do not use the
835 GOT, we don't need to generate a copy reloc. */
836 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
837 return true;
838
839 /* We must allocate the symbol in our .dynbss section, which will
840 become part of the .bss section of the executable. There will be
841 an entry for this symbol in the .dynsym section. The dynamic
842 object will contain position independent code, so all references
843 from the dynamic object to this symbol will go through the global
844 offset table. The dynamic linker will use the .dynsym entry to
845 determine the address it must put in the global offset table, so
846 both the dynamic object and the regular object will refer to the
847 same memory location for the variable. */
848
849 s = bfd_get_section_by_name (dynobj, ".dynbss");
850 BFD_ASSERT (s != NULL);
851
852 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker
853 to copy the initial value out of the dynamic object and into the
854 runtime process image. We need to remember the offset into the
855 .rela.bss section we are going to use. */
856 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
857 {
858 asection *srel;
859
860 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
861 BFD_ASSERT (srel != NULL);
862 srel->_raw_size += sizeof (Elf64_External_Rela);
863 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
864 }
865
866 /* We need to figure out the alignment required for this symbol. I
867 have no idea how ELF linkers handle this. 16-bytes is the size
868 of the largest type that requires hard alignment -- long double. */
869 /* FIXME: This is VERY ugly. Should be fixed for all architectures using
870 this construct. */
871 power_of_two = bfd_log2 (h->size);
872 if (power_of_two > 4)
873 power_of_two = 4;
874
875 /* Apply the required alignment. */
876 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
877 if (power_of_two > bfd_get_section_alignment (dynobj, s))
878 {
879 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
880 return false;
881 }
882
883 /* Define the symbol as being at this point in the section. */
884 h->root.u.def.section = s;
885 h->root.u.def.value = s->_raw_size;
886
887 /* Increment the section size to make room for the symbol. */
888 s->_raw_size += h->size;
889
890 return true;
891}
892
893/* Set the sizes of the dynamic sections. */
894
895static boolean
896elf64_x86_64_size_dynamic_sections (output_bfd, info)
897 bfd *output_bfd;
898 struct bfd_link_info *info;
899{
900 bfd *dynobj;
901 asection *s;
902 boolean plt;
903 boolean relocs;
904 boolean reltext;
905
906 dynobj = elf_hash_table (info)->dynobj;
907 BFD_ASSERT (dynobj != NULL);
908
909 if (elf_hash_table (info)->dynamic_sections_created)
910 {
911 /* Set the contents of the .interp section to the interpreter. */
912 if (! info->shared)
913 {
914 s = bfd_get_section_by_name (dynobj, ".interp");
915 BFD_ASSERT (s != NULL);
916 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
917 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
918 }
919 }
920 else
921 {
922 /* We may have created entries in the .rela.got section.
923 However, if we are not creating the dynamic sections, we will
924 not actually use these entries. Reset the size of .rela.got,
925 which will cause it to get stripped from the output file
926 below. */
927 s = bfd_get_section_by_name (dynobj, ".rela.got");
928 if (s != NULL)
929 s->_raw_size = 0;
930 }
931
932 /* If this is a -Bsymbolic shared link, then we need to discard all
933 PC relative relocs against symbols defined in a regular object.
934 We allocated space for them in the check_relocs routine, but we
935 will not fill them in in the relocate_section routine. */
936 if (info->shared)
937 elf64_x86_64_link_hash_traverse (elf64_x86_64_hash_table (info),
938 elf64_x86_64_discard_copies,
939 (PTR) info);
940
941 /* The check_relocs and adjust_dynamic_symbol entry points have
942 determined the sizes of the various dynamic sections. Allocate
943 memory for them. */
944 plt = relocs = reltext = false;
945 for (s = dynobj->sections; s != NULL; s = s->next)
946 {
947 const char *name;
948 boolean strip;
949
950 if ((s->flags & SEC_LINKER_CREATED) == 0)
951 continue;
952
953 /* It's OK to base decisions on the section name, because none
954 of the dynobj section names depend upon the input files. */
955 name = bfd_get_section_name (dynobj, s);
956
957 strip = false;
958 if (strcmp (name, ".plt") == 0)
959 {
960 if (s->_raw_size == 0)
961 {
962 /* Strip this section if we don't need it; see the
963 comment below. */
964 strip = true;
965 }
966 else
967 {
968 /* Remember whether there is a PLT. */
969 plt = true;
970 }
971 }
972 else if (strncmp (name, ".rela", 5) == 0)
973 {
974 if (s->_raw_size == 0)
975 {
976 /* If we don't need this section, strip it from the
977 output file. This is mostly to handle .rela.bss and
978 .rela.plt. We must create both sections in
979 create_dynamic_sections, because they must be created
980 before the linker maps input sections to output
981 sections. The linker does that before
982 adjust_dynamic_symbol is called, and it is that
983 function which decides whether anything needs to go
984 into these sections. */
985 strip = true;
986 }
987 else
988 {
989 asection *target;
990
991 /* Remember whether there are any reloc sections other
992 than .rela.plt. */
993 if (strcmp (name, ".rela.plt") != 0)
994 {
995 const char *outname;
996
997 relocs = true;
998
999 /* If this relocation section applies to a read only
1000 section, then we probably need a DT_TEXTREL
1001 entry. The entries in the .rela.plt section
1002 really apply to the .got section, which we
1003 created ourselves and so know is not readonly. */
1004 outname = bfd_get_section_name (output_bfd,
1005 s->output_section);
1006 target = bfd_get_section_by_name (output_bfd, outname + 5);
1007 if (target != NULL
1008 && (target->flags & SEC_READONLY) != 0
1009 && (target->flags & SEC_ALLOC) != 0)
1010 reltext = true;
1011 }
1012
1013 /* We use the reloc_count field as a counter if we need
1014 to copy relocs into the output file. */
1015 s->reloc_count = 0;
1016 }
1017 }
1018 else if (strncmp (name, ".got", 4) != 0)
1019 {
1020 /* It's not one of our sections, so don't allocate space. */
1021 continue;
1022 }
1023
1024 if (strip)
1025 {
1026 _bfd_strip_section_from_output (info, s);
1027 continue;
1028 }
1029
1030 /* Allocate memory for the section contents. We use bfd_zalloc
1031 here in case unused entries are not reclaimed before the
1032 section's contents are written out. This should not happen,
1033 but this way if it does, we get a R_X86_64_NONE reloc instead
1034 of garbage. */
1035 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1036 if (s->contents == NULL && s->_raw_size != 0)
1037 return false;
1038 }
1039
1040 if (elf_hash_table (info)->dynamic_sections_created)
1041 {
1042 /* Add some entries to the .dynamic section. We fill in the
1043 values later, in elf64_x86_64_finish_dynamic_sections, but we
1044 must add the entries now so that we get the correct size for
1045 the .dynamic section. The DT_DEBUG entry is filled in by the
1046 dynamic linker and used by the debugger. */
1047 if (! info->shared)
1048 {
1049 if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
1050 return false;
1051 }
1052
1053 if (plt)
1054 {
1055 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
1056 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1057 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1058 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
1059 return false;
1060 }
1061
1062 if (relocs)
1063 {
1064 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
1065 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
1066 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
1067 sizeof (Elf64_External_Rela)))
1068 return false;
1069 }
1070
1071 if (reltext)
1072 {
1073 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
1074 return false;
1075 info->flags |= DF_TEXTREL;
1076 }
1077 }
1078
1079 return true;
1080}
1081
1082/* This function is called via elf64_x86_64_link_hash_traverse if we are
1083 creating a shared object. In the -Bsymbolic case, it discards the
1084 space allocated to copy PC relative relocs against symbols which
1085 are defined in regular objects. For the normal non-symbolic case,
1086 we also discard space for relocs that have become local due to
1087 symbol visibility changes. We allocated space for them in the
1088 check_relocs routine, but we won't fill them in in the
1089 relocate_section routine. */
1090
1091static boolean
1092elf64_x86_64_discard_copies (h, inf)
1093 struct elf64_x86_64_link_hash_entry *h;
1094 PTR inf;
1095{
1096 struct elf64_x86_64_pcrel_relocs_copied *s;
1097 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1098
1099 /* If a symbol has been forced local or we have found a regular
1100 definition for the symbolic link case, then we won't be needing
1101 any relocs. */
1102 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1103 && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
1104 || info->symbolic))
1105 {
1106 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1107 s->section->_raw_size -= s->count * sizeof (Elf64_External_Rela);
1108 }
1109
1110 return true;
1111}
1112
1113/* Relocate an x86_64 ELF section. */
1114
1115static boolean
1116elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
1117 contents, relocs, local_syms, local_sections)
1118 bfd *output_bfd;
1119 struct bfd_link_info *info;
1120 bfd *input_bfd;
1121 asection *input_section;
1122 bfd_byte *contents;
1123 Elf_Internal_Rela *relocs;
1124 Elf_Internal_Sym *local_syms;
1125 asection **local_sections;
1126{
1127 bfd *dynobj;
1128 Elf_Internal_Shdr *symtab_hdr;
1129 struct elf_link_hash_entry **sym_hashes;
1130 bfd_vma *local_got_offsets;
1131 asection *sgot;
1132 asection *splt;
1133 asection *sreloc;
1134 Elf_Internal_Rela *rela;
1135 Elf_Internal_Rela *relend;
1136
1137 dynobj = elf_hash_table (info)->dynobj;
1138 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1139 sym_hashes = elf_sym_hashes (input_bfd);
1140 local_got_offsets = elf_local_got_offsets (input_bfd);
1141
1142 sreloc = splt = sgot = NULL;
1143 if (dynobj != NULL)
1144 {
1145 splt = bfd_get_section_by_name (dynobj, ".plt");
1146 sgot = bfd_get_section_by_name (dynobj, ".got");
1147 }
1148
1149 rela = relocs;
1150 relend = relocs + input_section->reloc_count;
1151 for (; rela < relend; rela++)
1152 {
1153 int r_type;
1154 reloc_howto_type *howto;
1155 unsigned long r_symndx;
1156 struct elf_link_hash_entry *h;
1157 Elf_Internal_Sym *sym;
1158 asection *sec;
1159 bfd_vma relocation;
1160 bfd_reloc_status_type r;
1161 unsigned int indx;
1162
1163 r_type = ELF64_R_TYPE (rela->r_info);
1164
1165 if ((indx = (unsigned) r_type) >= R_X86_64_max)
1166 {
1167 bfd_set_error (bfd_error_bad_value);
1168 return false;
1169 }
1170 howto = x86_64_elf_howto_table + indx;
1171
1172 r_symndx = ELF64_R_SYM (rela->r_info);
1173
1174 if (info->relocateable)
1175 {
1176 /* This is a relocateable link. We don't have to change
1177 anything, unless the reloc is against a section symbol,
1178 in which case we have to adjust according to where the
1179 section symbol winds up in the output section. */
1180 if (r_symndx < symtab_hdr->sh_info)
1181 {
1182 sym = local_syms + r_symndx;
1183 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1184 {
1185 sec = local_sections[r_symndx];
1186 rela->r_addend += sec->output_offset + sym->st_value;
1187 }
1188 }
1189
1190 continue;
1191 }
1192
1193 /* This is a final link. */
1194 h = NULL;
1195 sym = NULL;
1196 sec = NULL;
1197 if (r_symndx < symtab_hdr->sh_info)
1198 {
1199 sym = local_syms + r_symndx;
1200 sec = local_sections[r_symndx];
1201 relocation = (sec->output_section->vma
1202 + sec->output_offset
1203 + sym->st_value);
1204 }
1205 else
1206 {
1207 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1208 while (h->root.type == bfd_link_hash_indirect
1209 || h->root.type == bfd_link_hash_warning)
1210 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1211 if (h->root.type == bfd_link_hash_defined
1212 || h->root.type == bfd_link_hash_defweak)
1213 {
1214 sec = h->root.u.def.section;
1215 if ((r_type == R_X86_64_PLT32
1216 && splt != NULL
1217 && h->plt.offset != (bfd_vma) -1)
1218 || ((r_type == R_X86_64_GOT32 || r_type == R_X86_64_GOTPCREL)
1219 && elf_hash_table (info)->dynamic_sections_created
1220 && (!info->shared
1221 || (! info->symbolic && h->dynindx != -1)
1222 || (h->elf_link_hash_flags
1223 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1224 || (info->shared
1225 && ((! info->symbolic && h->dynindx != -1)
1226 || (h->elf_link_hash_flags
1227 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1228 && (r_type == R_X86_64_8
1229 || r_type == R_X86_64_16
1230 || r_type == R_X86_64_32
1231 || r_type == R_X86_64_64
1232 || r_type == R_X86_64_PC8
1233 || r_type == R_X86_64_PC16
1234 || r_type == R_X86_64_PC32)
1235 && ((input_section->flags & SEC_ALLOC) != 0
1236 /* DWARF will emit R_X86_64_32 relocations in its
1237 sections against symbols defined externally
1238 in shared libraries. We can't do anything
1239 with them here. */
1240 || ((input_section->flags & SEC_DEBUGGING) != 0
1241 && (h->elf_link_hash_flags
1242 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
1243 {
1244 /* In these cases, we don't need the relocation
1245 value. We check specially because in some
1246 obscure cases sec->output_section will be NULL. */
1247 relocation = 0;
1248 }
1249 else if (sec->output_section == NULL)
1250 {
1251 (*_bfd_error_handler)
1252 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
1253 bfd_get_filename (input_bfd), h->root.root.string,
1254 bfd_get_section_name (input_bfd, input_section));
1255 relocation = 0;
1256 }
1257 else
1258 relocation = (h->root.u.def.value
1259 + sec->output_section->vma
1260 + sec->output_offset);
1261 }
1262 else if (h->root.type == bfd_link_hash_undefweak)
1263 relocation = 0;
1264 else if (info->shared && !info->symbolic && !info->no_undefined
1265 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1266 relocation = 0;
1267 else
1268 {
1269 if (! ((*info->callbacks->undefined_symbol)
1270 (info, h->root.root.string, input_bfd,
1271 input_section, rela->r_offset,
1272 (!info->shared || info->no_undefined
1273 || ELF_ST_VISIBILITY (h->other)))))
1274 return false;
1275 relocation = 0;
1276 }
1277 }
1278
1279 /* When generating a shared object, the relocations handled here are
1280 copied into the output file to be resolved at run time. */
1281 switch (r_type)
1282 {
1283 case R_X86_64_GOT32:
1284 /* Relocation is to the entry for this symbol in the global
1285 offset table. */
1286 case R_X86_64_GOTPCREL:
1287 /* Use global offset table as symbol value. */
1288 BFD_ASSERT (sgot != NULL);
1289
1290 if (h != NULL)
1291 {
1292 bfd_vma off = h->got.offset;
1293 BFD_ASSERT (off != (bfd_vma) -1);
1294
1295 if (! elf_hash_table (info)->dynamic_sections_created
1296 || (info->shared
1297 && (info->symbolic || h->dynindx == -1)
1298 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1299 {
1300 /* This is actually a static link, or it is a -Bsymbolic
1301 link and the symbol is defined locally, or the symbol
1302 was forced to be local because of a version file. We
1303 must initialize this entry in the global offset table.
1304 Since the offset must always be a multiple of 8, we
1305 use the least significant bit to record whether we
1306 have initialized it already.
1307
1308 When doing a dynamic link, we create a .rela.got
1309 relocation entry to initialize the value. This is
1310 done in the finish_dynamic_symbol routine. */
1311 if ((off & 1) != 0)
1312 off &= ~1;
1313 else
1314 {
1315 bfd_put_64 (output_bfd, relocation,
1316 sgot->contents + off);
1317 h->got.offset |= 1;
1318 }
1319 }
1320 if (r_type == R_X86_64_GOTPCREL)
1321 relocation = sgot->output_section->vma + sgot->output_offset + off;
1322 else
1323 relocation = sgot->output_offset + off;
1324 }
1325 else
1326 {
1327 bfd_vma off;
1328
1329 BFD_ASSERT (local_got_offsets != NULL
1330 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1331
1332 off = local_got_offsets[r_symndx];
1333
1334 /* The offset must always be a multiple of 8. We use
1335 the least significant bit to record whether we have
1336 already generated the necessary reloc. */
1337 if ((off & 1) != 0)
1338 off &= ~1;
1339 else
1340 {
1341 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
1342
1343 if (info->shared)
1344 {
1345 asection *srelgot;
1346 Elf_Internal_Rela outrel;
1347
1348 /* We need to generate a R_X86_64_RELATIVE reloc
1349 for the dynamic linker. */
1350 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1351 BFD_ASSERT (srelgot != NULL);
1352
1353 outrel.r_offset = (sgot->output_section->vma
1354 + sgot->output_offset
1355 + off);
1356 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1357 outrel.r_addend = relocation;
1358 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
1359 (((Elf64_External_Rela *)
1360 srelgot->contents)
1361 + srelgot->reloc_count));
1362 ++srelgot->reloc_count;
1363 }
1364
1365 local_got_offsets[r_symndx] |= 1;
1366 }
1367
1368 if (r_type == R_X86_64_GOTPCREL)
1369 relocation = sgot->output_section->vma + sgot->output_offset + off;
1370 else
1371 relocation = sgot->output_offset + off;
1372 }
1373
1374 break;
1375
1376 case R_X86_64_PLT32:
1377 /* Relocation is to the entry for this symbol in the
1378 procedure linkage table. */
1379
1380 /* Resolve a PLT32 reloc against a local symbol directly,
1381 without using the procedure linkage table. */
1382 if (h == NULL)
1383 break;
1384
1385 if (h->plt.offset == (bfd_vma) -1 || splt == NULL)
1386 {
1387 /* We didn't make a PLT entry for this symbol. This
1388 happens when statically linking PIC code, or when
1389 using -Bsymbolic. */
1390 break;
1391 }
1392
1393 relocation = (splt->output_section->vma
1394 + splt->output_offset
1395 + h->plt.offset);
1396 break;
1397
1398 case R_X86_64_PC8:
1399 case R_X86_64_PC16:
1400 case R_X86_64_PC32:
1401 if (h == NULL)
1402 break;
1403 /* Fall through. */
1404 case R_X86_64_8:
1405 case R_X86_64_16:
1406 case R_X86_64_32:
1407 case R_X86_64_64:
1408 /* FIXME: The ABI says the linker should make sure the value is
1409 the same when it's zeroextended to 64 bit. */
1410 if (info->shared
1411 && (input_section->flags & SEC_ALLOC) != 0
1412 && ((r_type != R_X86_64_PC8
1413 && r_type != R_X86_64_PC16
1414 && r_type != R_X86_64_PC32)
1415 || (! info->symbolic
1416 || (h->elf_link_hash_flags
1417 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
1418
1419 {
1420 Elf_Internal_Rela outrel;
1421 boolean skip, relocate;
1422
1423 /* When generating a shared object, these relocations
1424 are copied into the output file to be resolved at run
1425 time. */
1426
1427 if (sreloc == NULL)
1428 {
1429 const char *name;
1430
1431 name = (bfd_elf_string_from_elf_section
1432 (input_bfd,
1433 elf_elfheader (input_bfd)->e_shstrndx,
1434 elf_section_data (input_section)->rel_hdr.sh_name));
1435 if (name == NULL)
1436 return false;
1437
1438 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1439 && strcmp (bfd_get_section_name (input_bfd,
1440 input_section),
1441 name + 5) == 0);
1442
1443 sreloc = bfd_get_section_by_name (dynobj, name);
1444 BFD_ASSERT (sreloc != NULL);
1445 }
1446
1447 skip = false;
1448
1449 if (elf_section_data (input_section)->stab_info == NULL)
1450 outrel.r_offset = rela->r_offset;
1451 else
1452 {
1453 bfd_vma off;
1454
1455 off = (_bfd_stab_section_offset
1456 (output_bfd, &elf_hash_table (info)->stab_info,
1457 input_section,
1458 &elf_section_data (input_section)->stab_info,
1459 rela->r_offset));
1460 if (off == (bfd_vma) -1)
1461 skip = true;
1462 outrel.r_offset = off;
1463 }
1464
1465 outrel.r_offset += (input_section->output_section->vma
1466 + input_section->output_offset);
1467
1468 if (skip)
1469 {
1470 memset (&outrel, 0, sizeof outrel);
1471 relocate = false;
1472 }
1473 /* h->dynindx may be -1 if this symbol was marked to
1474 become local. */
1475 else if (h != NULL
1476 && ((! info->symbolic && h->dynindx != -1)
1477 || (h->elf_link_hash_flags
1478 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1479 {
1480 BFD_ASSERT (h->dynindx != -1);
1481 relocate = false;
1482 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
1483 outrel.r_addend = relocation + rela->r_addend;
1484 }
1485 else
1486 {
1487 if (r_type == R_X86_64_64)
1488 {
1489 relocate = true;
1490 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1491 outrel.r_addend = relocation + rela->r_addend;
1492 }
1493 else
1494 {
1495 long indx;
1496
1497 if (h == NULL)
1498 sec = local_sections[r_symndx];
1499 else
1500 {
1501 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1502 || (h->root.type
1503 == bfd_link_hash_defweak));
1504 sec = h->root.u.def.section;
1505 }
1506 if (sec != NULL && bfd_is_abs_section (sec))
1507 indx = 0;
1508 else if (sec == NULL || sec->owner == NULL)
1509 {
1510 bfd_set_error (bfd_error_bad_value);
1511 return false;
1512 }
1513 else
1514 {
1515 asection *osec;
1516
1517 osec = sec->output_section;
1518 indx = elf_section_data (osec)->dynindx;
1519 BFD_ASSERT (indx > 0);
1520 }
1521
1522 relocate = false;
1523 outrel.r_info = ELF64_R_INFO (indx, r_type);
1524 outrel.r_addend = relocation + rela->r_addend;
1525 }
1526
1527 }
1528
1529 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
1530 (((Elf64_External_Rela *)
1531 sreloc->contents)
1532 + sreloc->reloc_count));
1533 ++sreloc->reloc_count;
1534
1535 /* If this reloc is against an external symbol, we do
1536 not want to fiddle with the addend. Otherwise, we
1537 need to include the symbol value so that it becomes
1538 an addend for the dynamic reloc. */
1539 if (! relocate)
1540 continue;
1541 }
1542
1543 break;
1544
1545 default:
1546 break;
1547 }
1548
1549 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1550 contents, rela->r_offset,
1551 relocation, rela->r_addend);
1552
1553 if (r != bfd_reloc_ok)
1554 {
1555 switch (r)
1556 {
1557 default:
1558 case bfd_reloc_outofrange:
1559 abort ();
1560 case bfd_reloc_overflow:
1561 {
1562 const char *name;
1563
1564 if (h != NULL)
1565 name = h->root.root.string;
1566 else
1567 {
1568 name = bfd_elf_string_from_elf_section (input_bfd,
1569 symtab_hdr->sh_link,
1570 sym->st_name);
1571 if (name == NULL)
1572 return false;
1573 if (*name == '\0')
1574 name = bfd_section_name (input_bfd, sec);
1575 }
1576 if (! ((*info->callbacks->reloc_overflow)
1577 (info, name, howto->name, (bfd_vma) 0,
1578 input_bfd, input_section, rela->r_offset)))
1579 return false;
1580 }
1581 break;
1582 }
1583 }
1584 }
1585
1586 return true;
1587}
1588
1589/* Finish up dynamic symbol handling. We set the contents of various
1590 dynamic sections here. */
1591
1592static boolean
1593elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym)
1594 bfd *output_bfd;
1595 struct bfd_link_info *info;
1596 struct elf_link_hash_entry *h;
1597 Elf_Internal_Sym *sym;
1598{
1599 bfd *dynobj;
1600
1601 dynobj = elf_hash_table (info)->dynobj;
1602
1603 if (h->plt.offset != (bfd_vma) -1)
1604 {
1605 asection *splt;
1606 asection *sgot;
1607 asection *srela;
1608 bfd_vma plt_index;
1609 bfd_vma got_offset;
1610 Elf_Internal_Rela rela;
1611
1612 /* This symbol has an entry in the procedure linkage table. Set
1613 it up. */
1614
1615 BFD_ASSERT (h->dynindx != -1);
1616
1617 splt = bfd_get_section_by_name (dynobj, ".plt");
1618 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1619 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1620 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1621
1622 /* Get the index in the procedure linkage table which
1623 corresponds to this symbol. This is the index of this symbol
1624 in all the symbols for which we are making plt entries. The
1625 first entry in the procedure linkage table is reserved. */
1626 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1627
1628 /* Get the offset into the .got table of the entry that
1629 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
1630 bytes. The first three are reserved for the dynamic linker. */
1631 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
1632
1633 /* Fill in the entry in the procedure linkage table. */
1634 memcpy (splt->contents + h->plt.offset, elf64_x86_64_plt_entry,
1635 PLT_ENTRY_SIZE);
1636
1637 /* Insert the relocation positions of the plt section. The magic
1638 numbers at the end of the statements are the positions of the
1639 relocations in the plt section. */
1640 /* Put offset for jmp *name@GOTPCREL(%rip), since the
1641 instruction uses 6 bytes, subtract this value. */
1642 bfd_put_32 (output_bfd,
1643 (sgot->output_section->vma
1644 + sgot->output_offset
1645 + got_offset
1646 - splt->output_section->vma
1647 - splt->output_offset
1648 - h->plt.offset
1649 - 6),
1650 splt->contents + h->plt.offset + 2);
1651 /* Put relocation index. */
1652 bfd_put_32 (output_bfd, plt_index,
1653 splt->contents + h->plt.offset + 7);
1654 /* Put offset for jmp .PLT0. */
1655 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),
1656 splt->contents + h->plt.offset + 12);
1657
1658 /* Fill in the entry in the global offset table, initially this
1659 points to the pushq instruction in the PLT which is at offset 6. */
1660 bfd_put_64 (output_bfd, (splt->output_section->vma + splt->output_offset
1661 + h->plt.offset + 6),
1662 sgot->contents + got_offset);
1663
1664 /* Fill in the entry in the .rela.plt section. */
1665 rela.r_offset = (sgot->output_section->vma
1666 + sgot->output_offset
1667 + got_offset);
1668 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT);
1669 rela.r_addend = 0;
1670 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1671 ((Elf64_External_Rela *) srela->contents
1672 + plt_index));
1673
1674 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1675 {
1676 /* Mark the symbol as undefined, rather than as defined in
1677 the .plt section. Leave the value alone. */
1678 sym->st_shndx = SHN_UNDEF;
1679 /* If the symbol is weak, we do need to clear the value.
1680 Otherwise, the PLT entry would provide a definition for
1681 the symbol even if the symbol wasn't defined anywhere,
1682 and so the symbol would never be NULL. */
1683 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
1684 == 0)
1685 sym->st_value = 0;
1686 }
1687 }
1688
1689 if (h->got.offset != (bfd_vma) -1)
1690 {
1691 asection *sgot;
1692 asection *srela;
1693 Elf_Internal_Rela rela;
1694
1695 /* This symbol has an entry in the global offset table. Set it
1696 up. */
1697
1698 sgot = bfd_get_section_by_name (dynobj, ".got");
1699 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1700 BFD_ASSERT (sgot != NULL && srela != NULL);
1701
1702 rela.r_offset = (sgot->output_section->vma
1703 + sgot->output_offset
1704 + (h->got.offset &~ 1));
1705
1706 /* If this is a static link, or it is a -Bsymbolic link and the
1707 symbol is defined locally or was forced to be local because
1708 of a version file, we just want to emit a RELATIVE reloc.
1709 The entry in the global offset table will already have been
1710 initialized in the relocate_section function. */
1711 if (! elf_hash_table (info)->dynamic_sections_created
1712 || (info->shared
1713 && (info->symbolic || h->dynindx == -1)
1714 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1715 {
1716 BFD_ASSERT((h->got.offset & 1) != 0);
1717 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
1718 rela.r_addend = (h->root.u.def.value
1719 + h->root.u.def.section->output_section->vma
1720 + h->root.u.def.section->output_offset);
1721 }
1722 else
1723 {
1724 BFD_ASSERT((h->got.offset & 1) == 0);
1725 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
1726 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT);
1727 rela.r_addend = 0;
1728 }
1729
1730 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1731 ((Elf64_External_Rela *) srela->contents
1732 + srela->reloc_count));
1733 ++srela->reloc_count;
1734 }
1735
1736 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1737 {
1738 asection *s;
1739 Elf_Internal_Rela rela;
1740
1741 /* This symbol needs a copy reloc. Set it up. */
1742
1743 BFD_ASSERT (h->dynindx != -1
1744 && (h->root.type == bfd_link_hash_defined
1745 || h->root.type == bfd_link_hash_defweak));
1746
1747 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1748 ".rela.bss");
1749 BFD_ASSERT (s != NULL);
1750
1751 rela.r_offset = (h->root.u.def.value
1752 + h->root.u.def.section->output_section->vma
1753 + h->root.u.def.section->output_offset);
1754 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY);
1755 rela.r_addend = 0;
1756 bfd_elf64_swap_reloca_out (output_bfd, &rela,
1757 ((Elf64_External_Rela *) s->contents
1758 + s->reloc_count));
1759 ++s->reloc_count;
1760 }
1761
1762 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1763 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1764 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1765 sym->st_shndx = SHN_ABS;
1766
1767 return true;
1768}
1769
1770/* Finish up the dynamic sections. */
1771
1772static boolean
1773elf64_x86_64_finish_dynamic_sections (output_bfd, info)
1774 bfd *output_bfd;
1775 struct bfd_link_info *info;
1776{
1777 bfd *dynobj;
1778 asection *sdyn;
1779 asection *sgot;
1780
1781 dynobj = elf_hash_table (info)->dynobj;
1782
1783 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1784 BFD_ASSERT (sgot != NULL);
1785 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1786
1787 if (elf_hash_table (info)->dynamic_sections_created)
1788 {
1789 asection *splt;
1790 Elf64_External_Dyn *dyncon, *dynconend;
1791
1792 BFD_ASSERT (sdyn != NULL);
1793
1794 dyncon = (Elf64_External_Dyn *) sdyn->contents;
1795 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1796 for (; dyncon < dynconend; dyncon++)
1797 {
1798 Elf_Internal_Dyn dyn;
1799 const char *name;
1800 asection *s;
1801
1802 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
1803
1804 switch (dyn.d_tag)
1805 {
1806 default:
1807 continue;
1808
1809 case DT_PLTGOT:
1810 name = ".got";
1811 goto get_vma;
1812
1813 case DT_JMPREL:
1814 name = ".rela.plt";
1815
1816 get_vma:
1817 s = bfd_get_section_by_name (output_bfd, name);
1818 BFD_ASSERT (s != NULL);
1819 dyn.d_un.d_ptr = s->vma;
1820 break;
1821
1822 case DT_RELASZ:
1823 /* FIXME: This comment and code is from elf64-alpha.c: */
1824 /* My interpretation of the TIS v1.1 ELF document indicates
1825 that RELASZ should not include JMPREL. This is not what
1826 the rest of the BFD does. It is, however, what the
1827 glibc ld.so wants. Do this fixup here until we found
1828 out who is right. */
1829 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1830 if (s)
1831 {
1832 /* Subtract JMPREL size from RELASZ. */
1833 dyn.d_un.d_val -=
1834 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
1835 }
1836 break;
1837
1838 case DT_PLTRELSZ:
1839 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
1840 BFD_ASSERT (s != NULL);
1841 dyn.d_un.d_val =
1842 (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size);
1843 break;
1844 }
1845 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
1846 }
1847
1848 /* Initialize the contents of the .plt section. */
1849 splt = bfd_get_section_by_name (dynobj, ".plt");
1850 BFD_ASSERT (splt != NULL);
1851 if (splt->_raw_size > 0)
1852 {
1853 /* Fill in the first entry in the procedure linkage table. */
1854 memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE);
1855 /* Add offset for pushq GOT+8(%rip), since the instruction
1856 uses 6 bytes subtract this value. */
1857 bfd_put_32 (output_bfd,
1858 (sgot->output_section->vma
1859 + sgot->output_offset
1860 + 8
1861 - splt->output_section->vma
1862 - splt->output_offset
1863 - 6),
1864 splt->contents + 2);
1865 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to
1866 the end of the instruction. */
1867 bfd_put_32 (output_bfd,
1868 (sgot->output_section->vma
1869 + sgot->output_offset
1870 + 16
1871 - splt->output_section->vma
1872 - splt->output_offset
1873 - 12),
1874 splt->contents + 8);
1875
1876 }
1877
1878 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
1879 PLT_ENTRY_SIZE;
1880 }
1881
1882 /* Set the first entry in the global offset table to the address of
1883 the dynamic section. */
1884 if (sgot->_raw_size > 0)
1885 {
1886 if (sdyn == NULL)
1887 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
1888 else
1889 bfd_put_64 (output_bfd,
1890 sdyn->output_section->vma + sdyn->output_offset,
1891 sgot->contents);
1892 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
1893 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE);
1894 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE*2);
1895 }
1896
1897 elf_section_data (sgot->output_section)->this_hdr.sh_entsize =
1898 GOT_ENTRY_SIZE;
1899
1900 return true;
1901}
1902
1903
1904#define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
1905#define TARGET_LITTLE_NAME "elf64-x86-64"
1906#define ELF_ARCH bfd_arch_i386
1907#define ELF_MACHINE_CODE EM_X86_64
1908#define ELF_MAXPAGESIZE 0x100000
1909
1910#define elf_backend_can_gc_sections 1
1911#define elf_backend_want_got_plt 1
1912#define elf_backend_plt_readonly 1
1913#define elf_backend_want_plt_sym 0
1914#define elf_backend_got_header_size (GOT_ENTRY_SIZE*3)
1915#define elf_backend_plt_header_size PLT_ENTRY_SIZE
1916
1917#define elf_info_to_howto elf64_x86_64_info_to_howto
1918
1919#define bfd_elf64_bfd_final_link _bfd_elf64_gc_common_final_link
1920#define bfd_elf64_bfd_link_hash_table_create \
1921 elf64_x86_64_link_hash_table_create
1922#define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup
1923
1924#define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
1925#define elf_backend_check_relocs elf64_x86_64_check_relocs
1926#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
1927#define elf_backend_finish_dynamic_sections \
1928 elf64_x86_64_finish_dynamic_sections
1929#define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol
1930#define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook
1931#define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
1932#define elf_backend_relocate_section elf64_x86_64_relocate_section
1933#define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
1934#define elf_backend_object_p elf64_x86_64_elf_object_p
1935
1936#include "elf64-target.h"
Note: See TracBrowser for help on using the repository browser.