File: | src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c |
Warning: | line 2353, column 13 Access to field 'def_regular' results in a dereference of a null pointer (loaded from variable 'h') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* X86-64 specific support for 64-bit ELF | |||
2 | Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 | |||
3 | Free Software Foundation, Inc. | |||
4 | Contributed by Jan Hubicka <jh@suse.cz>. | |||
5 | ||||
6 | This file is part of BFD, the Binary File Descriptor library. | |||
7 | ||||
8 | This program is free software; you can redistribute it and/or modify | |||
9 | it under the terms of the GNU General Public License as published by | |||
10 | the Free Software Foundation; either version 2 of the License, or | |||
11 | (at your option) any later version. | |||
12 | ||||
13 | This program is distributed in the hope that it will be useful, | |||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
16 | GNU General Public License for more details. | |||
17 | ||||
18 | You should have received a copy of the GNU General Public License | |||
19 | along with this program; if not, write to the Free Software | |||
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | |||
21 | ||||
22 | #include "bfd.h" | |||
23 | #include "sysdep.h" | |||
24 | #include "bfdlink.h" | |||
25 | #include "libbfd.h" | |||
26 | #include "elf-bfd.h" | |||
27 | ||||
28 | #include "elf/x86-64.h" | |||
29 | ||||
30 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ | |||
31 | #define MINUS_ONE(~ (bfd_vma) 0) (~ (bfd_vma) 0) | |||
32 | ||||
33 | /* The relocation "howto" table. Order of fields: | |||
34 | type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow, | |||
35 | special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */ | |||
36 | static reloc_howto_type x86_64_elf_howto_table[] = | |||
37 | { | |||
38 | HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,{ (unsigned) R_X86_64_NONE, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_NONE", 0, 0x00000000, 0x00000000 , 0 } | |||
39 | bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,{ (unsigned) R_X86_64_NONE, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_NONE", 0, 0x00000000, 0x00000000 , 0 } | |||
40 | FALSE){ (unsigned) R_X86_64_NONE, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_NONE", 0, 0x00000000, 0x00000000 , 0 }, | |||
41 | HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_64", 0, (~ (bfd_vma) 0), ( ~ (bfd_vma) 0), 0 } | |||
42 | bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE,{ (unsigned) R_X86_64_64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_64", 0, (~ (bfd_vma) 0), ( ~ (bfd_vma) 0), 0 } | |||
43 | FALSE){ (unsigned) R_X86_64_64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_64", 0, (~ (bfd_vma) 0), ( ~ (bfd_vma) 0), 0 }, | |||
44 | HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_PC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PC32", 0, 0xffffffff, 0xffffffff , 1 } | |||
45 | bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_PC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PC32", 0, 0xffffffff, 0xffffffff , 1 } | |||
46 | TRUE){ (unsigned) R_X86_64_PC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PC32", 0, 0xffffffff, 0xffffffff , 1 }, | |||
47 | HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOT32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT32", 0, 0xffffffff, 0xffffffff , 0 } | |||
48 | bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_GOT32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT32", 0, 0xffffffff, 0xffffffff , 0 } | |||
49 | FALSE){ (unsigned) R_X86_64_GOT32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT32", 0, 0xffffffff, 0xffffffff , 0 }, | |||
50 | HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_PLT32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLT32", 0, 0xffffffff, 0xffffffff , 1 } | |||
51 | bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_PLT32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLT32", 0, 0xffffffff, 0xffffffff , 1 } | |||
52 | TRUE){ (unsigned) R_X86_64_PLT32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLT32", 0, 0xffffffff, 0xffffffff , 1 }, | |||
53 | HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_COPY, 0, 2, 32, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_COPY", 0, 0xffffffff, 0xffffffff , 0 } | |||
54 | bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_COPY, 0, 2, 32, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_COPY", 0, 0xffffffff, 0xffffffff , 0 } | |||
55 | FALSE){ (unsigned) R_X86_64_COPY, 0, 2, 32, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_COPY", 0, 0xffffffff, 0xffffffff , 0 }, | |||
56 | HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_GLOB_DAT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
57 | bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_GLOB_DAT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
58 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_GLOB_DAT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
59 | HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_JUMP_SLOT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 0 } | |||
60 | bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_JUMP_SLOT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 0 } | |||
61 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_JUMP_SLOT, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 0 }, | |||
62 | HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_RELATIVE, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_RELATIVE", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
63 | bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_RELATIVE, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_RELATIVE", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
64 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_RELATIVE, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_RELATIVE", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
65 | HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTPCREL, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", 0, 0xffffffff, 0xffffffff , 1 } | |||
66 | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff,{ (unsigned) R_X86_64_GOTPCREL, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", 0, 0xffffffff, 0xffffffff , 1 } | |||
67 | 0xffffffff, TRUE){ (unsigned) R_X86_64_GOTPCREL, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", 0, 0xffffffff, 0xffffffff , 1 }, | |||
68 | HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned,{ (unsigned) R_X86_64_32, 0, 2, 32, 0, 0, complain_overflow_unsigned , bfd_elf_generic_reloc, "R_X86_64_32", 0, 0xffffffff, 0xffffffff , 0 } | |||
69 | bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_32, 0, 2, 32, 0, 0, complain_overflow_unsigned , bfd_elf_generic_reloc, "R_X86_64_32", 0, 0xffffffff, 0xffffffff , 0 } | |||
70 | FALSE){ (unsigned) R_X86_64_32, 0, 2, 32, 0, 0, complain_overflow_unsigned , bfd_elf_generic_reloc, "R_X86_64_32", 0, 0xffffffff, 0xffffffff , 0 }, | |||
71 | HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_32S, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_32S", 0, 0xffffffff, 0xffffffff , 0 } | |||
72 | bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff,{ (unsigned) R_X86_64_32S, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_32S", 0, 0xffffffff, 0xffffffff , 0 } | |||
73 | FALSE){ (unsigned) R_X86_64_32S, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_32S", 0, 0xffffffff, 0xffffffff , 0 }, | |||
74 | HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_16, 0, 1, 16, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_16", 0, 0xffff, 0xffff, 0 } | |||
75 | bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE){ (unsigned) R_X86_64_16, 0, 1, 16, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_16", 0, 0xffff, 0xffff, 0 }, | |||
76 | HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_PC16, 0, 1, 16, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_PC16", 0, 0xffff, 0xffff, 1 } | |||
77 | bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE){ (unsigned) R_X86_64_PC16, 0, 1, 16, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_PC16", 0, 0xffff, 0xffff, 1 }, | |||
78 | HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_8, 0, 0, 8, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_8", 0, 0xff, 0xff, 0 } | |||
79 | bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE){ (unsigned) R_X86_64_8, 0, 0, 8, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_8", 0, 0xff, 0xff, 0 }, | |||
80 | HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_PC8, 0, 0, 8, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PC8", 0, 0xff, 0xff, 1 } | |||
81 | bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE){ (unsigned) R_X86_64_PC8, 0, 0, 8, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PC8", 0, 0xff, 0xff, 1 }, | |||
82 | HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_DTPMOD64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
83 | bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_DTPMOD64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
84 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_DTPMOD64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
85 | HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_DTPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
86 | bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_DTPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
87 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_DTPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
88 | HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_TPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TPOFF64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 } | |||
89 | bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_TPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TPOFF64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 } | |||
90 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_TPOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TPOFF64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 }, | |||
91 | HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_TLSGD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSGD", 0, 0xffffffff, 0xffffffff , 1 } | |||
92 | bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff,{ (unsigned) R_X86_64_TLSGD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSGD", 0, 0xffffffff, 0xffffffff , 1 } | |||
93 | 0xffffffff, TRUE){ (unsigned) R_X86_64_TLSGD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSGD", 0, 0xffffffff, 0xffffffff , 1 }, | |||
94 | HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_TLSLD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSLD", 0, 0xffffffff, 0xffffffff , 1 } | |||
95 | bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff,{ (unsigned) R_X86_64_TLSLD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSLD", 0, 0xffffffff, 0xffffffff , 1 } | |||
96 | 0xffffffff, TRUE){ (unsigned) R_X86_64_TLSLD, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TLSLD", 0, 0xffffffff, 0xffffffff , 1 }, | |||
97 | HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_DTPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", 0, 0xffffffff, 0xffffffff , 0 } | |||
98 | bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff,{ (unsigned) R_X86_64_DTPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", 0, 0xffffffff, 0xffffffff , 0 } | |||
99 | 0xffffffff, FALSE){ (unsigned) R_X86_64_DTPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", 0, 0xffffffff, 0xffffffff , 0 }, | |||
100 | HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTTPOFF, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", 0, 0xffffffff, 0xffffffff , 1 } | |||
101 | bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff,{ (unsigned) R_X86_64_GOTTPOFF, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", 0, 0xffffffff, 0xffffffff , 1 } | |||
102 | 0xffffffff, TRUE){ (unsigned) R_X86_64_GOTTPOFF, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", 0, 0xffffffff, 0xffffffff , 1 }, | |||
103 | HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_TPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TPOFF32", 0, 0xffffffff, 0xffffffff , 0 } | |||
104 | bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff,{ (unsigned) R_X86_64_TPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TPOFF32", 0, 0xffffffff, 0xffffffff , 0 } | |||
105 | 0xffffffff, FALSE){ (unsigned) R_X86_64_TPOFF32, 0, 2, 32, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_TPOFF32", 0, 0xffffffff, 0xffffffff , 0 }, | |||
106 | HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_PC64, 0, 4, 64, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_PC64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 1 } | |||
107 | bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE,{ (unsigned) R_X86_64_PC64, 0, 4, 64, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_PC64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 1 } | |||
108 | TRUE){ (unsigned) R_X86_64_PC64, 0, 4, 64, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_PC64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 1 }, | |||
109 | HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,{ (unsigned) R_X86_64_GOTOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
110 | bfd_elf_generic_reloc, "R_X86_64_GOTOFF64",{ (unsigned) R_X86_64_GOTOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
111 | FALSE, MINUS_ONE, MINUS_ONE, FALSE){ (unsigned) R_X86_64_GOTOFF64, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
112 | HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTPC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC32", 0, 0xffffffff, 0xffffffff , 1 } | |||
113 | bfd_elf_generic_reloc, "R_X86_64_GOTPC32",{ (unsigned) R_X86_64_GOTPC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC32", 0, 0xffffffff, 0xffffffff , 1 } | |||
114 | FALSE, 0xffffffff, 0xffffffff, TRUE){ (unsigned) R_X86_64_GOTPC32, 0, 2, 32, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC32", 0, 0xffffffff, 0xffffffff , 1 }, | |||
115 | HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT64", 0, (~ (bfd_vma) 0) , (~ (bfd_vma) 0), 0 } | |||
116 | bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE,{ (unsigned) R_X86_64_GOT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT64", 0, (~ (bfd_vma) 0) , (~ (bfd_vma) 0), 0 } | |||
117 | FALSE){ (unsigned) R_X86_64_GOT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOT64", 0, (~ (bfd_vma) 0) , (~ (bfd_vma) 0), 0 }, | |||
118 | HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTPCREL64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 1 } | |||
119 | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_GOTPCREL64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 1 } | |||
120 | MINUS_ONE, TRUE){ (unsigned) R_X86_64_GOTPCREL64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", 0, (~ (bfd_vma ) 0), (~ (bfd_vma) 0), 1 }, | |||
121 | HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTPC64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 1 } | |||
122 | bfd_elf_generic_reloc, "R_X86_64_GOTPC64",{ (unsigned) R_X86_64_GOTPC64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 1 } | |||
123 | FALSE, MINUS_ONE, MINUS_ONE, TRUE){ (unsigned) R_X86_64_GOTPC64, 0, 4, 64, 1, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPC64", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 1 }, | |||
124 | HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_GOTPLT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
125 | bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_GOTPLT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
126 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_GOTPLT64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
127 | HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed,{ (unsigned) R_X86_64_PLTOFF64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
128 | bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE,{ (unsigned) R_X86_64_PLTOFF64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 } | |||
129 | MINUS_ONE, FALSE){ (unsigned) R_X86_64_PLTOFF64, 0, 4, 64, 0, 0, complain_overflow_signed , bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", 0, (~ (bfd_vma) 0), (~ (bfd_vma) 0), 0 }, | |||
130 | EMPTY_HOWTO (32){ (unsigned) (32), 0, 0, 0, 0, 0, complain_overflow_dont, ((void *)0), ((void*)0), 0, 0, 0, 0 }, | |||
131 | EMPTY_HOWTO (33){ (unsigned) (33), 0, 0, 0, 0, 0, complain_overflow_dont, ((void *)0), ((void*)0), 0, 0, 0, 0 }, | |||
132 | HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0,{ (unsigned) R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTPC32_TLSDESC", 0, 0xffffffff , 0xffffffff, 1 } | |||
133 | complain_overflow_bitfield, bfd_elf_generic_reloc,{ (unsigned) R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTPC32_TLSDESC", 0, 0xffffffff , 0xffffffff, 1 } | |||
134 | "R_X86_64_GOTPC32_TLSDESC",{ (unsigned) R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTPC32_TLSDESC", 0, 0xffffffff , 0xffffffff, 1 } | |||
135 | FALSE, 0xffffffff, 0xffffffff, TRUE){ (unsigned) R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, 1, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_GOTPC32_TLSDESC", 0, 0xffffffff , 0xffffffff, 1 }, | |||
136 | HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0,{ (unsigned) R_X86_64_TLSDESC_CALL, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_TLSDESC_CALL", 0, 0, 0, 0 } | |||
137 | complain_overflow_dont, bfd_elf_generic_reloc,{ (unsigned) R_X86_64_TLSDESC_CALL, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_TLSDESC_CALL", 0, 0, 0, 0 } | |||
138 | "R_X86_64_TLSDESC_CALL",{ (unsigned) R_X86_64_TLSDESC_CALL, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_TLSDESC_CALL", 0, 0, 0, 0 } | |||
139 | FALSE, 0, 0, FALSE){ (unsigned) R_X86_64_TLSDESC_CALL, 0, 0, 0, 0, 0, complain_overflow_dont , bfd_elf_generic_reloc, "R_X86_64_TLSDESC_CALL", 0, 0, 0, 0 }, | |||
140 | HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0,{ (unsigned) R_X86_64_TLSDESC, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TLSDESC", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 } | |||
141 | complain_overflow_bitfield, bfd_elf_generic_reloc,{ (unsigned) R_X86_64_TLSDESC, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TLSDESC", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 } | |||
142 | "R_X86_64_TLSDESC",{ (unsigned) R_X86_64_TLSDESC, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TLSDESC", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 } | |||
143 | FALSE, MINUS_ONE, MINUS_ONE, FALSE){ (unsigned) R_X86_64_TLSDESC, 0, 4, 64, 0, 0, complain_overflow_bitfield , bfd_elf_generic_reloc, "R_X86_64_TLSDESC", 0, (~ (bfd_vma) 0 ), (~ (bfd_vma) 0), 0 }, | |||
144 | ||||
145 | /* We have a gap in the reloc numbers here. | |||
146 | R_X86_64_standard counts the number up to this point, and | |||
147 | R_X86_64_vt_offset is the value to subtract from a reloc type of | |||
148 | R_X86_64_GNU_VT* to form an index into this table. */ | |||
149 | #define R_X86_64_standard(R_X86_64_TLSDESC + 1) (R_X86_64_TLSDESC + 1) | |||
150 | #define R_X86_64_vt_offset(R_X86_64_GNU_VTINHERIT - (R_X86_64_TLSDESC + 1)) (R_X86_64_GNU_VTINHERIT - R_X86_64_standard(R_X86_64_TLSDESC + 1)) | |||
151 | ||||
152 | /* GNU extension to record C++ vtable hierarchy. */ | |||
153 | HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont,{ (unsigned) R_X86_64_GNU_VTINHERIT, 0, 4, 0, 0, 0, complain_overflow_dont , ((void*)0), "R_X86_64_GNU_VTINHERIT", 0, 0, 0, 0 } | |||
154 | NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE){ (unsigned) R_X86_64_GNU_VTINHERIT, 0, 4, 0, 0, 0, complain_overflow_dont , ((void*)0), "R_X86_64_GNU_VTINHERIT", 0, 0, 0, 0 }, | |||
155 | ||||
156 | /* GNU extension to record C++ vtable member usage. */ | |||
157 | HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont,{ (unsigned) R_X86_64_GNU_VTENTRY, 0, 4, 0, 0, 0, complain_overflow_dont , _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", 0, 0, 0, 0 } | |||
158 | _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0,{ (unsigned) R_X86_64_GNU_VTENTRY, 0, 4, 0, 0, 0, complain_overflow_dont , _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", 0, 0, 0, 0 } | |||
159 | FALSE){ (unsigned) R_X86_64_GNU_VTENTRY, 0, 4, 0, 0, 0, complain_overflow_dont , _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", 0, 0, 0, 0 } | |||
160 | }; | |||
161 | ||||
162 | /* Map BFD relocs to the x86_64 elf relocs. */ | |||
163 | struct elf_reloc_map | |||
164 | { | |||
165 | bfd_reloc_code_real_type bfd_reloc_val; | |||
166 | unsigned char elf_reloc_val; | |||
167 | }; | |||
168 | ||||
169 | static const struct elf_reloc_map x86_64_reloc_map[] = | |||
170 | { | |||
171 | { BFD_RELOC_NONE, R_X86_64_NONE, }, | |||
172 | { BFD_RELOC_64, R_X86_64_64, }, | |||
173 | { BFD_RELOC_32_PCREL, R_X86_64_PC32, }, | |||
174 | { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,}, | |||
175 | { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,}, | |||
176 | { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, }, | |||
177 | { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, }, | |||
178 | { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, }, | |||
179 | { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, }, | |||
180 | { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, }, | |||
181 | { BFD_RELOC_32, R_X86_64_32, }, | |||
182 | { BFD_RELOC_X86_64_32S, R_X86_64_32S, }, | |||
183 | { BFD_RELOC_16, R_X86_64_16, }, | |||
184 | { BFD_RELOC_16_PCREL, R_X86_64_PC16, }, | |||
185 | { BFD_RELOC_8, R_X86_64_8, }, | |||
186 | { BFD_RELOC_8_PCREL, R_X86_64_PC8, }, | |||
187 | { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, }, | |||
188 | { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, }, | |||
189 | { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, }, | |||
190 | { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, }, | |||
191 | { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, }, | |||
192 | { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, }, | |||
193 | { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, }, | |||
194 | { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, }, | |||
195 | { BFD_RELOC_64_PCREL, R_X86_64_PC64, }, | |||
196 | { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, }, | |||
197 | { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, }, | |||
198 | { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, }, | |||
199 | { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, }, | |||
200 | { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, }, | |||
201 | { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, }, | |||
202 | { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, }, | |||
203 | { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, }, | |||
204 | { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, }, | |||
205 | { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, }, | |||
206 | { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, }, | |||
207 | { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, | |||
208 | }; | |||
209 | ||||
210 | static reloc_howto_type * | |||
211 | elf64_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type) | |||
212 | { | |||
213 | unsigned i; | |||
214 | ||||
215 | if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT | |||
216 | || r_type >= (unsigned int) R_X86_64_max) | |||
217 | { | |||
218 | if (r_type >= (unsigned int) R_X86_64_standard(R_X86_64_TLSDESC + 1)) | |||
219 | { | |||
220 | (*_bfd_error_handler) (_("%B: invalid relocation type %d")("%B: invalid relocation type %d"), | |||
221 | abfd, (int) r_type); | |||
222 | r_type = R_X86_64_NONE; | |||
223 | } | |||
224 | i = r_type; | |||
225 | } | |||
226 | else | |||
227 | i = r_type - (unsigned int) R_X86_64_vt_offset(R_X86_64_GNU_VTINHERIT - (R_X86_64_TLSDESC + 1)); | |||
228 | BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type)do { if (!(x86_64_elf_howto_table[i].type == r_type)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",228) ; } while (0); | |||
229 | return &x86_64_elf_howto_table[i]; | |||
230 | } | |||
231 | ||||
232 | /* Given a BFD reloc type, return a HOWTO structure. */ | |||
233 | static reloc_howto_type * | |||
234 | elf64_x86_64_reloc_type_lookup (bfd *abfd, | |||
235 | bfd_reloc_code_real_type code) | |||
236 | { | |||
237 | unsigned int i; | |||
238 | ||||
239 | for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map); | |||
240 | i++) | |||
241 | { | |||
242 | if (x86_64_reloc_map[i].bfd_reloc_val == code) | |||
243 | return elf64_x86_64_rtype_to_howto (abfd, | |||
244 | x86_64_reloc_map[i].elf_reloc_val); | |||
245 | } | |||
246 | return 0; | |||
247 | } | |||
248 | ||||
249 | /* Given an x86_64 ELF reloc type, fill in an arelent structure. */ | |||
250 | ||||
251 | static void | |||
252 | elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), arelent *cache_ptr, | |||
253 | Elf_Internal_Rela *dst) | |||
254 | { | |||
255 | unsigned r_type; | |||
256 | ||||
257 | r_type = ELF64_R_TYPE (dst->r_info)((dst->r_info) & 0xffffffff); | |||
258 | cache_ptr->howto = elf64_x86_64_rtype_to_howto (abfd, r_type); | |||
259 | BFD_ASSERT (r_type == cache_ptr->howto->type)do { if (!(r_type == cache_ptr->howto->type)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",259) ; } while (0); | |||
260 | } | |||
261 | ||||
262 | /* Support for core dump NOTE sections. */ | |||
263 | static bfd_boolean | |||
264 | elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) | |||
265 | { | |||
266 | int offset; | |||
267 | size_t size; | |||
268 | ||||
269 | switch (note->descsz) | |||
270 | { | |||
271 | default: | |||
272 | return FALSE0; | |||
273 | ||||
274 | case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */ | |||
275 | /* pr_cursig */ | |||
276 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_signal | |||
277 | = bfd_get_16 (abfd, note->descdata + 12)((*((abfd)->xvec->bfd_getx16)) (note->descdata + 12) ); | |||
278 | ||||
279 | /* pr_pid */ | |||
280 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_pid | |||
281 | = bfd_get_32 (abfd, note->descdata + 32)((*((abfd)->xvec->bfd_getx32)) (note->descdata + 32) ); | |||
282 | ||||
283 | /* pr_reg */ | |||
284 | offset = 112; | |||
285 | size = 216; | |||
286 | ||||
287 | break; | |||
288 | } | |||
289 | ||||
290 | /* Make a ".reg/999" section. */ | |||
291 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |||
292 | size, note->descpos + offset); | |||
293 | } | |||
294 | ||||
295 | static bfd_boolean | |||
296 | elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) | |||
297 | { | |||
298 | switch (note->descsz) | |||
299 | { | |||
300 | default: | |||
301 | return FALSE0; | |||
302 | ||||
303 | case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */ | |||
304 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_program | |||
305 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |||
306 | elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command | |||
307 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |||
308 | } | |||
309 | ||||
310 | /* Note that for some reason, a spurious space is tacked | |||
311 | onto the end of the args in some (at least one anyway) | |||
312 | implementations, so strip it off if it exists. */ | |||
313 | ||||
314 | { | |||
315 | char *command = elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->core_command; | |||
316 | int n = strlen (command); | |||
317 | ||||
318 | if (0 < n && command[n - 1] == ' ') | |||
319 | command[n - 1] = '\0'; | |||
320 | } | |||
321 | ||||
322 | return TRUE1; | |||
323 | } | |||
324 | ||||
325 | /* Functions for the x86-64 ELF linker. */ | |||
326 | ||||
327 | /* The name of the dynamic interpreter. This is put in the .interp | |||
328 | section. */ | |||
329 | ||||
330 | #define ELF_DYNAMIC_INTERPRETER"/lib/ld64.so.1" "/lib/ld64.so.1" | |||
331 | ||||
332 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid | |||
333 | copying dynamic variables from a shared lib into an app's dynbss | |||
334 | section, and instead use a dynamic relocation to point into the | |||
335 | shared lib. */ | |||
336 | #define ELIMINATE_COPY_RELOCS1 1 | |||
337 | ||||
338 | /* The size in bytes of an entry in the global offset table. */ | |||
339 | ||||
340 | #define GOT_ENTRY_SIZE8 8 | |||
341 | ||||
342 | /* The size in bytes of an entry in the procedure linkage table. */ | |||
343 | ||||
344 | #define PLT_ENTRY_SIZE16 16 | |||
345 | ||||
346 | /* The first entry in a procedure linkage table looks like this. See the | |||
347 | SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */ | |||
348 | ||||
349 | static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE16] = | |||
350 | { | |||
351 | 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ | |||
352 | 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */ | |||
353 | 0xcc, 0xcc, 0xcc, 0xcc /* pad out to 16 bytes with int3. */ | |||
354 | }; | |||
355 | ||||
356 | /* Subsequent entries in a procedure linkage table look like this. */ | |||
357 | ||||
358 | static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE16] = | |||
359 | { | |||
360 | 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */ | |||
361 | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ | |||
362 | 0x68, /* pushq immediate */ | |||
363 | 0, 0, 0, 0, /* replaced with index into relocation table. */ | |||
364 | 0xe9, /* jmp relative */ | |||
365 | 0, 0, 0, 0 /* replaced with offset to start of .plt0. */ | |||
366 | }; | |||
367 | ||||
368 | /* The x86-64 linker needs to keep track of the number of relocs that | |||
369 | it decides to copy as dynamic relocs in check_relocs for each symbol. | |||
370 | This is so that it can later discard them if they are found to be | |||
371 | unnecessary. We store the information in a field extending the | |||
372 | regular ELF linker hash table. */ | |||
373 | ||||
374 | struct elf64_x86_64_dyn_relocs | |||
375 | { | |||
376 | /* Next section. */ | |||
377 | struct elf64_x86_64_dyn_relocs *next; | |||
378 | ||||
379 | /* The input section of the reloc. */ | |||
380 | asection *sec; | |||
381 | ||||
382 | /* Total number of relocs copied for the input section. */ | |||
383 | bfd_size_type count; | |||
384 | ||||
385 | /* Number of pc-relative relocs copied for the input section. */ | |||
386 | bfd_size_type pc_count; | |||
387 | }; | |||
388 | ||||
389 | /* x86-64 ELF linker hash entry. */ | |||
390 | ||||
391 | struct elf64_x86_64_link_hash_entry | |||
392 | { | |||
393 | struct elf_link_hash_entry elf; | |||
394 | ||||
395 | /* Track dynamic relocs copied for this symbol. */ | |||
396 | struct elf64_x86_64_dyn_relocs *dyn_relocs; | |||
397 | ||||
398 | #define GOT_UNKNOWN0 0 | |||
399 | #define GOT_NORMAL1 1 | |||
400 | #define GOT_TLS_GD2 2 | |||
401 | #define GOT_TLS_IE3 3 | |||
402 | #define GOT_TLS_GDESC4 4 | |||
403 | #define GOT_TLS_GD_BOTH_P(type)((type) == (2 | 4)) \ | |||
404 | ((type) == (GOT_TLS_GD2 | GOT_TLS_GDESC4)) | |||
405 | #define GOT_TLS_GD_P(type)((type) == 2 || ((type) == (2 | 4))) \ | |||
406 | ((type) == GOT_TLS_GD2 || GOT_TLS_GD_BOTH_P (type)((type) == (2 | 4))) | |||
407 | #define GOT_TLS_GDESC_P(type)((type) == 4 || ((type) == (2 | 4))) \ | |||
408 | ((type) == GOT_TLS_GDESC4 || GOT_TLS_GD_BOTH_P (type)((type) == (2 | 4))) | |||
409 | #define GOT_TLS_GD_ANY_P(type)(((type) == 2 || ((type) == (2 | 4))) || ((type) == 4 || ((type ) == (2 | 4)))) \ | |||
410 | (GOT_TLS_GD_P (type)((type) == 2 || ((type) == (2 | 4))) || GOT_TLS_GDESC_P (type)((type) == 4 || ((type) == (2 | 4)))) | |||
411 | unsigned char tls_type; | |||
412 | ||||
413 | /* Offset of the GOTPLT entry reserved for the TLS descriptor, | |||
414 | starting at the end of the jump table. */ | |||
415 | bfd_vma tlsdesc_got; | |||
416 | }; | |||
417 | ||||
418 | #define elf64_x86_64_hash_entry(ent)((struct elf64_x86_64_link_hash_entry *)(ent)) \ | |||
419 | ((struct elf64_x86_64_link_hash_entry *)(ent)) | |||
420 | ||||
421 | struct elf64_x86_64_obj_tdata | |||
422 | { | |||
423 | struct elf_obj_tdata root; | |||
424 | ||||
425 | /* tls_type for each local got entry. */ | |||
426 | char *local_got_tls_type; | |||
427 | ||||
428 | /* GOTPLT entries for TLS descriptors. */ | |||
429 | bfd_vma *local_tlsdesc_gotent; | |||
430 | }; | |||
431 | ||||
432 | #define elf64_x86_64_tdata(abfd)((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any) \ | |||
433 | ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any) | |||
434 | ||||
435 | #define elf64_x86_64_local_got_tls_type(abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_got_tls_type) \ | |||
436 | (elf64_x86_64_tdata (abfd)((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)->local_got_tls_type) | |||
437 | ||||
438 | #define elf64_x86_64_local_tlsdesc_gotent(abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_tlsdesc_gotent) \ | |||
439 | (elf64_x86_64_tdata (abfd)((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)->local_tlsdesc_gotent) | |||
440 | ||||
441 | /* x86-64 ELF linker hash table. */ | |||
442 | ||||
443 | struct elf64_x86_64_link_hash_table | |||
444 | { | |||
445 | struct elf_link_hash_table elf; | |||
446 | ||||
447 | /* Short-cuts to get to dynamic linker sections. */ | |||
448 | asection *sgot; | |||
449 | asection *sgotplt; | |||
450 | asection *srelgot; | |||
451 | asection *splt; | |||
452 | asection *srelplt; | |||
453 | asection *sdynbss; | |||
454 | asection *srelbss; | |||
455 | ||||
456 | /* The offset into splt of the PLT entry for the TLS descriptor | |||
457 | resolver. Special values are 0, if not necessary (or not found | |||
458 | to be necessary yet), and -1 if needed but not determined | |||
459 | yet. */ | |||
460 | bfd_vma tlsdesc_plt; | |||
461 | /* The offset into sgot of the GOT entry used by the PLT entry | |||
462 | above. */ | |||
463 | bfd_vma tlsdesc_got; | |||
464 | ||||
465 | union { | |||
466 | bfd_signed_vma refcount; | |||
467 | bfd_vma offset; | |||
468 | } tls_ld_got; | |||
469 | ||||
470 | /* The amount of space used by the jump slots in the GOT. */ | |||
471 | bfd_vma sgotplt_jump_table_size; | |||
472 | ||||
473 | /* Small local sym to section mapping cache. */ | |||
474 | struct sym_sec_cache sym_sec; | |||
475 | }; | |||
476 | ||||
477 | /* Get the x86-64 ELF linker hash table from a link_info structure. */ | |||
478 | ||||
479 | #define elf64_x86_64_hash_table(p)((struct elf64_x86_64_link_hash_table *) ((p)->hash)) \ | |||
480 | ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) | |||
481 | ||||
482 | #define elf64_x86_64_compute_jump_table_size(htab)((htab)->srelplt->reloc_count * 8) \ | |||
483 | ((htab)->srelplt->reloc_count * GOT_ENTRY_SIZE8) | |||
484 | ||||
485 | /* Create an entry in an x86-64 ELF linker hash table. */ | |||
486 | ||||
487 | static struct bfd_hash_entry * | |||
488 | link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, | |||
489 | const char *string) | |||
490 | { | |||
491 | /* Allocate the structure if it has not already been allocated by a | |||
492 | subclass. */ | |||
493 | if (entry == NULL((void*)0)) | |||
494 | { | |||
495 | entry = bfd_hash_allocate (table, | |||
496 | sizeof (struct elf64_x86_64_link_hash_entry)); | |||
497 | if (entry == NULL((void*)0)) | |||
498 | return entry; | |||
499 | } | |||
500 | ||||
501 | /* Call the allocation method of the superclass. */ | |||
502 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |||
503 | if (entry != NULL((void*)0)) | |||
504 | { | |||
505 | struct elf64_x86_64_link_hash_entry *eh; | |||
506 | ||||
507 | eh = (struct elf64_x86_64_link_hash_entry *) entry; | |||
508 | eh->dyn_relocs = NULL((void*)0); | |||
509 | eh->tls_type = GOT_UNKNOWN0; | |||
510 | eh->tlsdesc_got = (bfd_vma) -1; | |||
511 | } | |||
512 | ||||
513 | return entry; | |||
514 | } | |||
515 | ||||
516 | /* Create an X86-64 ELF linker hash table. */ | |||
517 | ||||
518 | static struct bfd_link_hash_table * | |||
519 | elf64_x86_64_link_hash_table_create (bfd *abfd) | |||
520 | { | |||
521 | struct elf64_x86_64_link_hash_table *ret; | |||
522 | bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table); | |||
523 | ||||
524 | ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt); | |||
525 | if (ret == NULL((void*)0)) | |||
526 | return NULL((void*)0); | |||
527 | ||||
528 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, | |||
529 | sizeof (struct elf64_x86_64_link_hash_entry))) | |||
530 | { | |||
531 | free (ret); | |||
532 | return NULL((void*)0); | |||
533 | } | |||
534 | ||||
535 | ret->sgot = NULL((void*)0); | |||
536 | ret->sgotplt = NULL((void*)0); | |||
537 | ret->srelgot = NULL((void*)0); | |||
538 | ret->splt = NULL((void*)0); | |||
539 | ret->srelplt = NULL((void*)0); | |||
540 | ret->sdynbss = NULL((void*)0); | |||
541 | ret->srelbss = NULL((void*)0); | |||
542 | ret->sym_sec.abfd = NULL((void*)0); | |||
543 | ret->tlsdesc_plt = 0; | |||
544 | ret->tlsdesc_got = 0; | |||
545 | ret->tls_ld_got.refcount = 0; | |||
546 | ret->sgotplt_jump_table_size = 0; | |||
547 | ||||
548 | return &ret->elf.root; | |||
549 | } | |||
550 | ||||
551 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up | |||
552 | shortcuts to them in our hash table. */ | |||
553 | ||||
554 | static bfd_boolean | |||
555 | create_got_section (bfd *dynobj, struct bfd_link_info *info) | |||
556 | { | |||
557 | struct elf64_x86_64_link_hash_table *htab; | |||
558 | ||||
559 | if (! _bfd_elf_create_got_section (dynobj, info)) | |||
560 | return FALSE0; | |||
561 | ||||
562 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
563 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | |||
564 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |||
565 | if (!htab->sgot || !htab->sgotplt) | |||
566 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 566, __PRETTY_FUNCTION__); | |||
567 | ||||
568 | htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got", | |||
569 | (SEC_ALLOC0x001 | SEC_LOAD0x002 | |||
570 | | SEC_HAS_CONTENTS0x100 | |||
571 | | SEC_IN_MEMORY0x4000 | |||
572 | | SEC_LINKER_CREATED0x200000 | |||
573 | | SEC_READONLY0x008)); | |||
574 | if (htab->srelgot == NULL((void*)0) | |||
575 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3)(((htab->srelgot)->alignment_power = (3)),1)) | |||
576 | return FALSE0; | |||
577 | return TRUE1; | |||
578 | } | |||
579 | ||||
580 | /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and | |||
581 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | |||
582 | hash table. */ | |||
583 | ||||
584 | static bfd_boolean | |||
585 | elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) | |||
586 | { | |||
587 | struct elf64_x86_64_link_hash_table *htab; | |||
588 | ||||
589 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
590 | if (!htab->sgot && !create_got_section (dynobj, info)) | |||
591 | return FALSE0; | |||
592 | ||||
593 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |||
594 | return FALSE0; | |||
595 | ||||
596 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |||
597 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |||
598 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |||
599 | if (!info->shared) | |||
600 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |||
601 | ||||
602 | if (!htab->splt || !htab->srelplt || !htab->sdynbss | |||
603 | || (!info->shared && !htab->srelbss)) | |||
604 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 604, __PRETTY_FUNCTION__); | |||
605 | ||||
606 | return TRUE1; | |||
607 | } | |||
608 | ||||
609 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |||
610 | ||||
611 | static void | |||
612 | elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info, | |||
613 | struct elf_link_hash_entry *dir, | |||
614 | struct elf_link_hash_entry *ind) | |||
615 | { | |||
616 | struct elf64_x86_64_link_hash_entry *edir, *eind; | |||
617 | ||||
618 | edir = (struct elf64_x86_64_link_hash_entry *) dir; | |||
619 | eind = (struct elf64_x86_64_link_hash_entry *) ind; | |||
620 | ||||
621 | if (eind->dyn_relocs != NULL((void*)0)) | |||
622 | { | |||
623 | if (edir->dyn_relocs != NULL((void*)0)) | |||
624 | { | |||
625 | struct elf64_x86_64_dyn_relocs **pp; | |||
626 | struct elf64_x86_64_dyn_relocs *p; | |||
627 | ||||
628 | /* Add reloc counts against the indirect sym to the direct sym | |||
629 | list. Merge any entries against the same section. */ | |||
630 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL((void*)0); ) | |||
631 | { | |||
632 | struct elf64_x86_64_dyn_relocs *q; | |||
633 | ||||
634 | for (q = edir->dyn_relocs; q != NULL((void*)0); q = q->next) | |||
635 | if (q->sec == p->sec) | |||
636 | { | |||
637 | q->pc_count += p->pc_count; | |||
638 | q->count += p->count; | |||
639 | *pp = p->next; | |||
640 | break; | |||
641 | } | |||
642 | if (q == NULL((void*)0)) | |||
643 | pp = &p->next; | |||
644 | } | |||
645 | *pp = edir->dyn_relocs; | |||
646 | } | |||
647 | ||||
648 | edir->dyn_relocs = eind->dyn_relocs; | |||
649 | eind->dyn_relocs = NULL((void*)0); | |||
650 | } | |||
651 | ||||
652 | if (ind->root.type == bfd_link_hash_indirect | |||
653 | && dir->got.refcount <= 0) | |||
654 | { | |||
655 | edir->tls_type = eind->tls_type; | |||
656 | eind->tls_type = GOT_UNKNOWN0; | |||
657 | } | |||
658 | ||||
659 | if (ELIMINATE_COPY_RELOCS1 | |||
660 | && ind->root.type != bfd_link_hash_indirect | |||
661 | && dir->dynamic_adjusted) | |||
662 | { | |||
663 | /* If called to transfer flags for a weakdef during processing | |||
664 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |||
665 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |||
666 | dir->ref_dynamic |= ind->ref_dynamic; | |||
667 | dir->ref_regular |= ind->ref_regular; | |||
668 | dir->ref_regular_nonweak |= ind->ref_regular_nonweak; | |||
669 | dir->needs_plt |= ind->needs_plt; | |||
670 | dir->pointer_equality_needed |= ind->pointer_equality_needed; | |||
671 | } | |||
672 | else | |||
673 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); | |||
674 | } | |||
675 | ||||
676 | static bfd_boolean | |||
677 | elf64_x86_64_mkobject (bfd *abfd) | |||
678 | { | |||
679 | bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata); | |||
680 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |||
681 | if (abfd->tdata.any == NULL((void*)0)) | |||
682 | return FALSE0; | |||
683 | return TRUE1; | |||
684 | } | |||
685 | ||||
686 | static bfd_boolean | |||
687 | elf64_x86_64_elf_object_p (bfd *abfd) | |||
688 | { | |||
689 | /* Set the right machine number for an x86-64 elf64 file. */ | |||
690 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_6464); | |||
691 | return TRUE1; | |||
692 | } | |||
693 | ||||
694 | static int | |||
695 | elf64_x86_64_tls_transition (struct bfd_link_info *info, int r_type, int is_local) | |||
696 | { | |||
697 | if (info->shared && !info->executable) | |||
698 | return r_type; | |||
699 | ||||
700 | switch (r_type) | |||
701 | { | |||
702 | case R_X86_64_TLSGD: | |||
703 | case R_X86_64_GOTPC32_TLSDESC: | |||
704 | case R_X86_64_TLSDESC_CALL: | |||
705 | case R_X86_64_GOTTPOFF: | |||
706 | if (is_local) | |||
707 | return R_X86_64_TPOFF32; | |||
708 | return R_X86_64_GOTTPOFF; | |||
709 | case R_X86_64_TLSLD: | |||
710 | return R_X86_64_TPOFF32; | |||
711 | } | |||
712 | ||||
713 | return r_type; | |||
714 | } | |||
715 | ||||
716 | /* Look through the relocs for a section during the first phase, and | |||
717 | calculate needed space in the global offset table, procedure | |||
718 | linkage table, and dynamic reloc sections. */ | |||
719 | ||||
720 | static bfd_boolean | |||
721 | elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, | |||
722 | const Elf_Internal_Rela *relocs) | |||
723 | { | |||
724 | struct elf64_x86_64_link_hash_table *htab; | |||
725 | Elf_Internal_Shdr *symtab_hdr; | |||
726 | struct elf_link_hash_entry **sym_hashes; | |||
727 | const Elf_Internal_Rela *rel; | |||
728 | const Elf_Internal_Rela *rel_end; | |||
729 | asection *sreloc; | |||
730 | ||||
731 | if (info->relocatable) | |||
732 | return TRUE1; | |||
733 | ||||
734 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
735 | symtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
736 | sym_hashes = elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
737 | ||||
738 | sreloc = NULL((void*)0); | |||
739 | ||||
740 | rel_end = relocs + sec->reloc_count; | |||
741 | for (rel = relocs; rel < rel_end; rel++) | |||
742 | { | |||
743 | unsigned int r_type; | |||
744 | unsigned long r_symndx; | |||
745 | struct elf_link_hash_entry *h; | |||
746 | ||||
747 | r_symndx = ELF64_R_SYM (rel->r_info)((rel->r_info) >> 32); | |||
748 | r_type = ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff); | |||
749 | ||||
750 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)((symtab_hdr)->sh_size / (symtab_hdr)->sh_entsize)) | |||
751 | { | |||
752 | (*_bfd_error_handler) (_("%B: bad symbol index: %d")("%B: bad symbol index: %d"), | |||
753 | abfd, r_symndx); | |||
754 | return FALSE0; | |||
755 | } | |||
756 | ||||
757 | if (r_symndx < symtab_hdr->sh_info) | |||
758 | h = NULL((void*)0); | |||
759 | else | |||
760 | { | |||
761 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |||
762 | while (h->root.type == bfd_link_hash_indirect | |||
763 | || h->root.type == bfd_link_hash_warning) | |||
764 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
765 | } | |||
766 | ||||
767 | r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL((void*)0)); | |||
768 | switch (r_type) | |||
769 | { | |||
770 | case R_X86_64_TLSLD: | |||
771 | htab->tls_ld_got.refcount += 1; | |||
772 | goto create_got; | |||
773 | ||||
774 | case R_X86_64_TPOFF32: | |||
775 | if (info->shared && !info->executable) | |||
776 | { | |||
777 | (*_bfd_error_handler) | |||
778 | (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC")("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC" ), | |||
779 | abfd, | |||
780 | x86_64_elf_howto_table[r_type].name, | |||
781 | (h) ? h->root.root.string : "a local symbol"); | |||
782 | bfd_set_error (bfd_error_bad_value); | |||
783 | return FALSE0; | |||
784 | } | |||
785 | break; | |||
786 | ||||
787 | case R_X86_64_GOTTPOFF: | |||
788 | if (info->shared && !info->executable) | |||
789 | info->flags |= DF_STATIC_TLS(1 << 4); | |||
790 | /* Fall through */ | |||
791 | ||||
792 | case R_X86_64_GOT32: | |||
793 | case R_X86_64_GOTPCREL: | |||
794 | case R_X86_64_TLSGD: | |||
795 | case R_X86_64_GOT64: | |||
796 | case R_X86_64_GOTPCREL64: | |||
797 | case R_X86_64_GOTPLT64: | |||
798 | case R_X86_64_GOTPC32_TLSDESC: | |||
799 | case R_X86_64_TLSDESC_CALL: | |||
800 | /* This symbol requires a global offset table entry. */ | |||
801 | { | |||
802 | int tls_type, old_tls_type; | |||
803 | ||||
804 | switch (r_type) | |||
805 | { | |||
806 | default: tls_type = GOT_NORMAL1; break; | |||
807 | case R_X86_64_TLSGD: tls_type = GOT_TLS_GD2; break; | |||
808 | case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE3; break; | |||
809 | case R_X86_64_GOTPC32_TLSDESC: | |||
810 | case R_X86_64_TLSDESC_CALL: | |||
811 | tls_type = GOT_TLS_GDESC4; break; | |||
812 | } | |||
813 | ||||
814 | if (h != NULL((void*)0)) | |||
815 | { | |||
816 | if (r_type == R_X86_64_GOTPLT64) | |||
817 | { | |||
818 | /* This relocation indicates that we also need | |||
819 | a PLT entry, as this is a function. We don't need | |||
820 | a PLT entry for local symbols. */ | |||
821 | h->needs_plt = 1; | |||
822 | h->plt.refcount += 1; | |||
823 | } | |||
824 | h->got.refcount += 1; | |||
825 | old_tls_type = elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type; | |||
826 | } | |||
827 | else | |||
828 | { | |||
829 | bfd_signed_vma *local_got_refcounts; | |||
830 | ||||
831 | /* This is a global offset table entry for a local symbol. */ | |||
832 | local_got_refcounts = elf_local_got_refcounts (abfd)(((abfd) -> tdata.elf_obj_data) -> local_got.refcounts); | |||
833 | if (local_got_refcounts == NULL((void*)0)) | |||
834 | { | |||
835 | bfd_size_type size; | |||
836 | ||||
837 | size = symtab_hdr->sh_info; | |||
838 | size *= sizeof (bfd_signed_vma) | |||
839 | + sizeof (bfd_vma) + sizeof (char); | |||
840 | local_got_refcounts = ((bfd_signed_vma *) | |||
841 | bfd_zalloc (abfd, size)); | |||
842 | if (local_got_refcounts == NULL((void*)0)) | |||
843 | return FALSE0; | |||
844 | elf_local_got_refcounts (abfd)(((abfd) -> tdata.elf_obj_data) -> local_got.refcounts) = local_got_refcounts; | |||
845 | elf64_x86_64_local_tlsdesc_gotent (abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_tlsdesc_gotent) | |||
846 | = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info); | |||
847 | elf64_x86_64_local_got_tls_type (abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_got_tls_type) | |||
848 | = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info); | |||
849 | } | |||
850 | local_got_refcounts[r_symndx] += 1; | |||
851 | old_tls_type | |||
852 | = elf64_x86_64_local_got_tls_type (abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_got_tls_type) [r_symndx]; | |||
853 | } | |||
854 | ||||
855 | /* If a TLS symbol is accessed using IE at least once, | |||
856 | there is no point to use dynamic model for it. */ | |||
857 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN0 | |||
858 | && (! GOT_TLS_GD_ANY_P (old_tls_type)(((old_tls_type) == 2 || ((old_tls_type) == (2 | 4))) || ((old_tls_type ) == 4 || ((old_tls_type) == (2 | 4)))) | |||
859 | || tls_type != GOT_TLS_IE3)) | |||
860 | { | |||
861 | if (old_tls_type == GOT_TLS_IE3 && GOT_TLS_GD_ANY_P (tls_type)(((tls_type) == 2 || ((tls_type) == (2 | 4))) || ((tls_type) == 4 || ((tls_type) == (2 | 4))))) | |||
862 | tls_type = old_tls_type; | |||
863 | else if (GOT_TLS_GD_ANY_P (old_tls_type)(((old_tls_type) == 2 || ((old_tls_type) == (2 | 4))) || ((old_tls_type ) == 4 || ((old_tls_type) == (2 | 4)))) | |||
864 | && GOT_TLS_GD_ANY_P (tls_type)(((tls_type) == 2 || ((tls_type) == (2 | 4))) || ((tls_type) == 4 || ((tls_type) == (2 | 4))))) | |||
865 | tls_type |= old_tls_type; | |||
866 | else | |||
867 | { | |||
868 | (*_bfd_error_handler) | |||
869 | (_("%B: %s' accessed both as normal and thread local symbol")("%B: %s' accessed both as normal and thread local symbol"), | |||
870 | abfd, h ? h->root.root.string : "<local>"); | |||
871 | return FALSE0; | |||
872 | } | |||
873 | } | |||
874 | ||||
875 | if (old_tls_type != tls_type) | |||
876 | { | |||
877 | if (h != NULL((void*)0)) | |||
878 | elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type = tls_type; | |||
879 | else | |||
880 | elf64_x86_64_local_got_tls_type (abfd)(((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any)-> local_got_tls_type) [r_symndx] = tls_type; | |||
881 | } | |||
882 | } | |||
883 | /* Fall through */ | |||
884 | ||||
885 | case R_X86_64_GOTOFF64: | |||
886 | case R_X86_64_GOTPC32: | |||
887 | case R_X86_64_GOTPC64: | |||
888 | create_got: | |||
889 | if (htab->sgot == NULL((void*)0)) | |||
890 | { | |||
891 | if (htab->elf.dynobj == NULL((void*)0)) | |||
892 | htab->elf.dynobj = abfd; | |||
893 | if (!create_got_section (htab->elf.dynobj, info)) | |||
894 | return FALSE0; | |||
895 | } | |||
896 | break; | |||
897 | ||||
898 | case R_X86_64_PLT32: | |||
899 | /* This symbol requires a procedure linkage table entry. We | |||
900 | actually build the entry in adjust_dynamic_symbol, | |||
901 | because this might be a case of linking PIC code which is | |||
902 | never referenced by a dynamic object, in which case we | |||
903 | don't need to generate a procedure linkage table entry | |||
904 | after all. */ | |||
905 | ||||
906 | /* If this is a local symbol, we resolve it directly without | |||
907 | creating a procedure linkage table entry. */ | |||
908 | if (h == NULL((void*)0)) | |||
909 | continue; | |||
910 | ||||
911 | h->needs_plt = 1; | |||
912 | h->plt.refcount += 1; | |||
913 | break; | |||
914 | ||||
915 | case R_X86_64_PLTOFF64: | |||
916 | /* This tries to form the 'address' of a function relative | |||
917 | to GOT. For global symbols we need a PLT entry. */ | |||
918 | if (h != NULL((void*)0)) | |||
919 | { | |||
920 | h->needs_plt = 1; | |||
921 | h->plt.refcount += 1; | |||
922 | } | |||
923 | goto create_got; | |||
924 | ||||
925 | case R_X86_64_8: | |||
926 | case R_X86_64_16: | |||
927 | case R_X86_64_32: | |||
928 | case R_X86_64_32S: | |||
929 | /* Let's help debug shared library creation. These relocs | |||
930 | cannot be used in shared libs. Don't error out for | |||
931 | sections we don't care about, such as debug sections or | |||
932 | non-constant sections. */ | |||
933 | if (info->shared | |||
934 | && (sec->flags & SEC_ALLOC0x001) != 0 | |||
935 | && (sec->flags & SEC_READONLY0x008) != 0) | |||
936 | { | |||
937 | (*_bfd_error_handler) | |||
938 | (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC")("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC" ), | |||
939 | abfd, | |||
940 | x86_64_elf_howto_table[r_type].name, | |||
941 | (h) ? h->root.root.string : "a local symbol"); | |||
942 | bfd_set_error (bfd_error_bad_value); | |||
943 | return FALSE0; | |||
944 | } | |||
945 | /* Fall through. */ | |||
946 | ||||
947 | case R_X86_64_PC8: | |||
948 | case R_X86_64_PC16: | |||
949 | case R_X86_64_PC32: | |||
950 | case R_X86_64_PC64: | |||
951 | case R_X86_64_64: | |||
952 | if (h != NULL((void*)0) && !info->shared) | |||
953 | { | |||
954 | /* If this reloc is in a read-only section, we might | |||
955 | need a copy reloc. We can't check reliably at this | |||
956 | stage whether the section is read-only, as input | |||
957 | sections have not yet been mapped to output sections. | |||
958 | Tentatively set the flag for now, and correct in | |||
959 | adjust_dynamic_symbol. */ | |||
960 | h->non_got_ref = 1; | |||
961 | ||||
962 | /* We may need a .plt entry if the function this reloc | |||
963 | refers to is in a shared lib. */ | |||
964 | h->plt.refcount += 1; | |||
965 | if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64) | |||
966 | h->pointer_equality_needed = 1; | |||
967 | } | |||
968 | ||||
969 | /* If we are creating a shared library, and this is a reloc | |||
970 | against a global symbol, or a non PC relative reloc | |||
971 | against a local symbol, then we need to copy the reloc | |||
972 | into the shared library. However, if we are linking with | |||
973 | -Bsymbolic, we do not need to copy a reloc against a | |||
974 | global symbol which is defined in an object we are | |||
975 | including in the link (i.e., DEF_REGULAR is set). At | |||
976 | this point we have not seen all the input files, so it is | |||
977 | possible that DEF_REGULAR is not set now but will be set | |||
978 | later (it is never cleared). In case of a weak definition, | |||
979 | DEF_REGULAR may be cleared later by a strong definition in | |||
980 | a shared library. We account for that possibility below by | |||
981 | storing information in the relocs_copied field of the hash | |||
982 | table entry. A similar situation occurs when creating | |||
983 | shared libraries and symbol visibility changes render the | |||
984 | symbol local. | |||
985 | ||||
986 | If on the other hand, we are creating an executable, we | |||
987 | may need to keep relocations for symbols satisfied by a | |||
988 | dynamic library if we manage to avoid copy relocs for the | |||
989 | symbol. */ | |||
990 | if ((info->shared | |||
991 | && (sec->flags & SEC_ALLOC0x001) != 0 | |||
992 | && (((r_type != R_X86_64_PC8) | |||
993 | && (r_type != R_X86_64_PC16) | |||
994 | && (r_type != R_X86_64_PC32) | |||
995 | && (r_type != R_X86_64_PC64)) | |||
996 | || (h != NULL((void*)0) | |||
997 | && (! info->symbolic | |||
998 | || h->root.type == bfd_link_hash_defweak | |||
999 | || !h->def_regular)))) | |||
1000 | || (ELIMINATE_COPY_RELOCS1 | |||
1001 | && !info->shared | |||
1002 | && (sec->flags & SEC_ALLOC0x001) != 0 | |||
1003 | && h != NULL((void*)0) | |||
1004 | && (h->root.type == bfd_link_hash_defweak | |||
1005 | || !h->def_regular))) | |||
1006 | { | |||
1007 | struct elf64_x86_64_dyn_relocs *p; | |||
1008 | struct elf64_x86_64_dyn_relocs **head; | |||
1009 | ||||
1010 | /* We must copy these reloc types into the output file. | |||
1011 | Create a reloc section in dynobj and make room for | |||
1012 | this reloc. */ | |||
1013 | if (sreloc == NULL((void*)0)) | |||
1014 | { | |||
1015 | const char *name; | |||
1016 | bfd *dynobj; | |||
1017 | ||||
1018 | name = (bfd_elf_string_from_elf_section | |||
1019 | (abfd, | |||
1020 | elf_elfheader (abfd)(((abfd) -> tdata.elf_obj_data) -> elf_header)->e_shstrndx, | |||
1021 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->rel_hdr.sh_name)); | |||
1022 | if (name == NULL((void*)0)) | |||
1023 | return FALSE0; | |||
1024 | ||||
1025 | if (strncmp (name, ".rela", 5) != 0 | |||
1026 | || strcmp (bfd_get_section_name (abfd, sec)((sec)->name + 0), | |||
1027 | name + 5) != 0) | |||
1028 | { | |||
1029 | (*_bfd_error_handler) | |||
1030 | (_("%B: bad relocation section name `%s\'")("%B: bad relocation section name `%s\'"), | |||
1031 | abfd, name); | |||
1032 | } | |||
1033 | ||||
1034 | if (htab->elf.dynobj == NULL((void*)0)) | |||
1035 | htab->elf.dynobj = abfd; | |||
1036 | ||||
1037 | dynobj = htab->elf.dynobj; | |||
1038 | ||||
1039 | sreloc = bfd_get_section_by_name (dynobj, name); | |||
1040 | if (sreloc == NULL((void*)0)) | |||
1041 | { | |||
1042 | flagword flags; | |||
1043 | ||||
1044 | flags = (SEC_HAS_CONTENTS0x100 | SEC_READONLY0x008 | |||
1045 | | SEC_IN_MEMORY0x4000 | SEC_LINKER_CREATED0x200000); | |||
1046 | if ((sec->flags & SEC_ALLOC0x001) != 0) | |||
1047 | flags |= SEC_ALLOC0x001 | SEC_LOAD0x002; | |||
1048 | sreloc = bfd_make_section_with_flags (dynobj, | |||
1049 | name, | |||
1050 | flags); | |||
1051 | if (sreloc == NULL((void*)0) | |||
1052 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)(((sreloc)->alignment_power = (3)),1)) | |||
1053 | return FALSE0; | |||
1054 | } | |||
1055 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->sreloc = sreloc; | |||
1056 | } | |||
1057 | ||||
1058 | /* If this is a global symbol, we count the number of | |||
1059 | relocations we need for this symbol. */ | |||
1060 | if (h != NULL((void*)0)) | |||
1061 | { | |||
1062 | head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs; | |||
1063 | } | |||
1064 | else | |||
1065 | { | |||
1066 | void **vpp; | |||
1067 | /* Track dynamic relocs needed for local syms too. | |||
1068 | We really need local syms available to do this | |||
1069 | easily. Oh well. */ | |||
1070 | ||||
1071 | asection *s; | |||
1072 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |||
1073 | sec, r_symndx); | |||
1074 | if (s == NULL((void*)0)) | |||
1075 | return FALSE0; | |||
1076 | ||||
1077 | /* Beware of type punned pointers vs strict aliasing | |||
1078 | rules. */ | |||
1079 | vpp = &(elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->local_dynrel); | |||
1080 | head = (struct elf64_x86_64_dyn_relocs **)vpp; | |||
1081 | } | |||
1082 | ||||
1083 | p = *head; | |||
1084 | if (p == NULL((void*)0) || p->sec != sec) | |||
1085 | { | |||
1086 | bfd_size_type amt = sizeof *p; | |||
1087 | p = ((struct elf64_x86_64_dyn_relocs *) | |||
1088 | bfd_alloc (htab->elf.dynobj, amt)); | |||
1089 | if (p == NULL((void*)0)) | |||
1090 | return FALSE0; | |||
1091 | p->next = *head; | |||
1092 | *head = p; | |||
1093 | p->sec = sec; | |||
1094 | p->count = 0; | |||
1095 | p->pc_count = 0; | |||
1096 | } | |||
1097 | ||||
1098 | p->count += 1; | |||
1099 | if (r_type == R_X86_64_PC8 | |||
1100 | || r_type == R_X86_64_PC16 | |||
1101 | || r_type == R_X86_64_PC32 | |||
1102 | || r_type == R_X86_64_PC64) | |||
1103 | p->pc_count += 1; | |||
1104 | } | |||
1105 | break; | |||
1106 | ||||
1107 | /* This relocation describes the C++ object vtable hierarchy. | |||
1108 | Reconstruct it for later use during GC. */ | |||
1109 | case R_X86_64_GNU_VTINHERIT: | |||
1110 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |||
1111 | return FALSE0; | |||
1112 | break; | |||
1113 | ||||
1114 | /* This relocation describes which C++ vtable entries are actually | |||
1115 | used. Record for later use during GC. */ | |||
1116 | case R_X86_64_GNU_VTENTRY: | |||
1117 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |||
1118 | return FALSE0; | |||
1119 | break; | |||
1120 | ||||
1121 | default: | |||
1122 | break; | |||
1123 | } | |||
1124 | } | |||
1125 | ||||
1126 | return TRUE1; | |||
1127 | } | |||
1128 | ||||
1129 | /* Return the section that should be marked against GC for a given | |||
1130 | relocation. */ | |||
1131 | ||||
1132 | static asection * | |||
1133 | elf64_x86_64_gc_mark_hook (asection *sec, | |||
1134 | struct bfd_link_info *info ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
1135 | Elf_Internal_Rela *rel, | |||
1136 | struct elf_link_hash_entry *h, | |||
1137 | Elf_Internal_Sym *sym) | |||
1138 | { | |||
1139 | if (h != NULL((void*)0)) | |||
1140 | { | |||
1141 | switch (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff)) | |||
1142 | { | |||
1143 | case R_X86_64_GNU_VTINHERIT: | |||
1144 | case R_X86_64_GNU_VTENTRY: | |||
1145 | break; | |||
1146 | ||||
1147 | default: | |||
1148 | switch (h->root.type) | |||
1149 | { | |||
1150 | case bfd_link_hash_defined: | |||
1151 | case bfd_link_hash_defweak: | |||
1152 | return h->root.u.def.section; | |||
1153 | ||||
1154 | case bfd_link_hash_common: | |||
1155 | return h->root.u.c.p->section; | |||
1156 | ||||
1157 | default: | |||
1158 | break; | |||
1159 | } | |||
1160 | } | |||
1161 | } | |||
1162 | else | |||
1163 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); | |||
1164 | ||||
1165 | return NULL((void*)0); | |||
1166 | } | |||
1167 | ||||
1168 | /* Update the got entry reference counts for the section being removed. */ | |||
1169 | ||||
1170 | static bfd_boolean | |||
1171 | elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, | |||
1172 | asection *sec, const Elf_Internal_Rela *relocs) | |||
1173 | { | |||
1174 | Elf_Internal_Shdr *symtab_hdr; | |||
1175 | struct elf_link_hash_entry **sym_hashes; | |||
1176 | bfd_signed_vma *local_got_refcounts; | |||
1177 | const Elf_Internal_Rela *rel, *relend; | |||
1178 | ||||
1179 | elf_section_data (sec)((struct bfd_elf_section_data*)(sec)->used_by_bfd)->local_dynrel = NULL((void*)0); | |||
1180 | ||||
1181 | symtab_hdr = &elf_tdata (abfd)((abfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
1182 | sym_hashes = elf_sym_hashes (abfd)(((abfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
1183 | local_got_refcounts = elf_local_got_refcounts (abfd)(((abfd) -> tdata.elf_obj_data) -> local_got.refcounts); | |||
1184 | ||||
1185 | relend = relocs + sec->reloc_count; | |||
1186 | for (rel = relocs; rel < relend; rel++) | |||
1187 | { | |||
1188 | unsigned long r_symndx; | |||
1189 | unsigned int r_type; | |||
1190 | struct elf_link_hash_entry *h = NULL((void*)0); | |||
1191 | ||||
1192 | r_symndx = ELF64_R_SYM (rel->r_info)((rel->r_info) >> 32); | |||
1193 | if (r_symndx >= symtab_hdr->sh_info) | |||
1194 | { | |||
1195 | struct elf64_x86_64_link_hash_entry *eh; | |||
1196 | struct elf64_x86_64_dyn_relocs **pp; | |||
1197 | struct elf64_x86_64_dyn_relocs *p; | |||
1198 | ||||
1199 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |||
1200 | while (h->root.type == bfd_link_hash_indirect | |||
1201 | || h->root.type == bfd_link_hash_warning) | |||
1202 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1203 | eh = (struct elf64_x86_64_link_hash_entry *) h; | |||
1204 | ||||
1205 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL((void*)0); pp = &p->next) | |||
1206 | if (p->sec == sec) | |||
1207 | { | |||
1208 | /* Everything must go for SEC. */ | |||
1209 | *pp = p->next; | |||
1210 | break; | |||
1211 | } | |||
1212 | } | |||
1213 | ||||
1214 | r_type = ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff); | |||
1215 | r_type = elf64_x86_64_tls_transition (info, r_type, h != NULL((void*)0)); | |||
1216 | switch (r_type) | |||
1217 | { | |||
1218 | case R_X86_64_TLSLD: | |||
1219 | if (elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash))->tls_ld_got.refcount > 0) | |||
1220 | elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash))->tls_ld_got.refcount -= 1; | |||
1221 | break; | |||
1222 | ||||
1223 | case R_X86_64_TLSGD: | |||
1224 | case R_X86_64_GOTPC32_TLSDESC: | |||
1225 | case R_X86_64_TLSDESC_CALL: | |||
1226 | case R_X86_64_GOTTPOFF: | |||
1227 | case R_X86_64_GOT32: | |||
1228 | case R_X86_64_GOTPCREL: | |||
1229 | case R_X86_64_GOT64: | |||
1230 | case R_X86_64_GOTPCREL64: | |||
1231 | case R_X86_64_GOTPLT64: | |||
1232 | if (h != NULL((void*)0)) | |||
1233 | { | |||
1234 | if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0) | |||
1235 | h->plt.refcount -= 1; | |||
1236 | if (h->got.refcount > 0) | |||
1237 | h->got.refcount -= 1; | |||
1238 | } | |||
1239 | else if (local_got_refcounts != NULL((void*)0)) | |||
1240 | { | |||
1241 | if (local_got_refcounts[r_symndx] > 0) | |||
1242 | local_got_refcounts[r_symndx] -= 1; | |||
1243 | } | |||
1244 | break; | |||
1245 | ||||
1246 | case R_X86_64_8: | |||
1247 | case R_X86_64_16: | |||
1248 | case R_X86_64_32: | |||
1249 | case R_X86_64_64: | |||
1250 | case R_X86_64_32S: | |||
1251 | case R_X86_64_PC8: | |||
1252 | case R_X86_64_PC16: | |||
1253 | case R_X86_64_PC32: | |||
1254 | case R_X86_64_PC64: | |||
1255 | if (info->shared) | |||
1256 | break; | |||
1257 | /* Fall thru */ | |||
1258 | ||||
1259 | case R_X86_64_PLT32: | |||
1260 | case R_X86_64_PLTOFF64: | |||
1261 | if (h != NULL((void*)0)) | |||
1262 | { | |||
1263 | if (h->plt.refcount > 0) | |||
1264 | h->plt.refcount -= 1; | |||
1265 | } | |||
1266 | break; | |||
1267 | ||||
1268 | default: | |||
1269 | break; | |||
1270 | } | |||
1271 | } | |||
1272 | ||||
1273 | return TRUE1; | |||
1274 | } | |||
1275 | ||||
1276 | /* Adjust a symbol defined by a dynamic object and referenced by a | |||
1277 | regular object. The current definition is in some section of the | |||
1278 | dynamic object, but we're not including those sections. We have to | |||
1279 | change the definition to something the rest of the link can | |||
1280 | understand. */ | |||
1281 | ||||
1282 | static bfd_boolean | |||
1283 | elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info, | |||
1284 | struct elf_link_hash_entry *h) | |||
1285 | { | |||
1286 | struct elf64_x86_64_link_hash_table *htab; | |||
1287 | asection *s; | |||
1288 | unsigned int power_of_two; | |||
1289 | ||||
1290 | /* If this is a function, put it in the procedure linkage table. We | |||
1291 | will fill in the contents of the procedure linkage table later, | |||
1292 | when we know the address of the .got section. */ | |||
1293 | if (h->type == STT_FUNC2 | |||
1294 | || h->needs_plt) | |||
1295 | { | |||
1296 | if (h->plt.refcount <= 0 | |||
1297 | || SYMBOL_CALLS_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 1) | |||
1298 | || (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_DEFAULT0 | |||
1299 | && h->root.type == bfd_link_hash_undefweak)) | |||
1300 | { | |||
1301 | /* This case can occur if we saw a PLT32 reloc in an input | |||
1302 | file, but the symbol was never referred to by a dynamic | |||
1303 | object, or if all references were garbage collected. In | |||
1304 | such a case, we don't actually need to build a procedure | |||
1305 | linkage table, and we can just do a PC32 reloc instead. */ | |||
1306 | h->plt.offset = (bfd_vma) -1; | |||
1307 | h->needs_plt = 0; | |||
1308 | } | |||
1309 | ||||
1310 | return TRUE1; | |||
1311 | } | |||
1312 | else | |||
1313 | /* It's possible that we incorrectly decided a .plt reloc was | |||
1314 | needed for an R_X86_64_PC32 reloc to a non-function sym in | |||
1315 | check_relocs. We can't decide accurately between function and | |||
1316 | non-function syms in check-relocs; Objects loaded later in | |||
1317 | the link may change h->type. So fix it now. */ | |||
1318 | h->plt.offset = (bfd_vma) -1; | |||
1319 | ||||
1320 | /* If this is a weak symbol, and there is a real definition, the | |||
1321 | processor independent code will have arranged for us to see the | |||
1322 | real definition first, and we can just use the same value. */ | |||
1323 | if (h->u.weakdef != NULL((void*)0)) | |||
1324 | { | |||
1325 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defineddo { if (!(h->u.weakdef->root.type == bfd_link_hash_defined || h->u.weakdef->root.type == bfd_link_hash_defweak)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",1326 ); } while (0) | |||
1326 | || h->u.weakdef->root.type == bfd_link_hash_defweak)do { if (!(h->u.weakdef->root.type == bfd_link_hash_defined || h->u.weakdef->root.type == bfd_link_hash_defweak)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",1326 ); } while (0); | |||
1327 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |||
1328 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |||
1329 | if (ELIMINATE_COPY_RELOCS1 || info->nocopyreloc) | |||
1330 | h->non_got_ref = h->u.weakdef->non_got_ref; | |||
1331 | return TRUE1; | |||
1332 | } | |||
1333 | ||||
1334 | /* This is a reference to a symbol defined by a dynamic object which | |||
1335 | is not a function. */ | |||
1336 | ||||
1337 | /* If we are creating a shared library, we must presume that the | |||
1338 | only references to the symbol are via the global offset table. | |||
1339 | For such cases we need not do anything here; the relocations will | |||
1340 | be handled correctly by relocate_section. */ | |||
1341 | if (info->shared) | |||
1342 | return TRUE1; | |||
1343 | ||||
1344 | /* If there are no references to this symbol that do not use the | |||
1345 | GOT, we don't need to generate a copy reloc. */ | |||
1346 | if (!h->non_got_ref) | |||
1347 | return TRUE1; | |||
1348 | ||||
1349 | /* If -z nocopyreloc was given, we won't generate them either. */ | |||
1350 | if (info->nocopyreloc) | |||
1351 | { | |||
1352 | h->non_got_ref = 0; | |||
1353 | return TRUE1; | |||
1354 | } | |||
1355 | ||||
1356 | if (ELIMINATE_COPY_RELOCS1) | |||
1357 | { | |||
1358 | struct elf64_x86_64_link_hash_entry * eh; | |||
1359 | struct elf64_x86_64_dyn_relocs *p; | |||
1360 | ||||
1361 | eh = (struct elf64_x86_64_link_hash_entry *) h; | |||
1362 | for (p = eh->dyn_relocs; p != NULL((void*)0); p = p->next) | |||
1363 | { | |||
1364 | s = p->sec->output_section; | |||
1365 | if (s != NULL((void*)0) && (s->flags & SEC_READONLY0x008) != 0) | |||
1366 | break; | |||
1367 | } | |||
1368 | ||||
1369 | /* If we didn't find any dynamic relocs in read-only sections, then | |||
1370 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |||
1371 | if (p == NULL((void*)0)) | |||
1372 | { | |||
1373 | h->non_got_ref = 0; | |||
1374 | return TRUE1; | |||
1375 | } | |||
1376 | } | |||
1377 | ||||
1378 | if (h->size == 0) | |||
1379 | { | |||
1380 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size")("dynamic variable `%s' is zero size"), | |||
1381 | h->root.root.string); | |||
1382 | return TRUE1; | |||
1383 | } | |||
1384 | ||||
1385 | /* We must allocate the symbol in our .dynbss section, which will | |||
1386 | become part of the .bss section of the executable. There will be | |||
1387 | an entry for this symbol in the .dynsym section. The dynamic | |||
1388 | object will contain position independent code, so all references | |||
1389 | from the dynamic object to this symbol will go through the global | |||
1390 | offset table. The dynamic linker will use the .dynsym entry to | |||
1391 | determine the address it must put in the global offset table, so | |||
1392 | both the dynamic object and the regular object will refer to the | |||
1393 | same memory location for the variable. */ | |||
1394 | ||||
1395 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
1396 | ||||
1397 | /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker | |||
1398 | to copy the initial value out of the dynamic object and into the | |||
1399 | runtime process image. */ | |||
1400 | if ((h->root.u.def.section->flags & SEC_ALLOC0x001) != 0) | |||
1401 | { | |||
1402 | htab->srelbss->size += sizeof (Elf64_External_Rela); | |||
1403 | h->needs_copy = 1; | |||
1404 | } | |||
1405 | ||||
1406 | /* We need to figure out the alignment required for this symbol. I | |||
1407 | have no idea how ELF linkers handle this. 16-bytes is the size | |||
1408 | of the largest type that requires hard alignment -- long double. */ | |||
1409 | /* FIXME: This is VERY ugly. Should be fixed for all architectures using | |||
1410 | this construct. */ | |||
1411 | power_of_two = bfd_log2 (h->size); | |||
1412 | if (power_of_two > 4) | |||
1413 | power_of_two = 4; | |||
1414 | ||||
1415 | /* Apply the required alignment. */ | |||
1416 | s = htab->sdynbss; | |||
1417 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two))((((bfd_vma) (s->size) + ((bfd_size_type) (1 << power_of_two )) - 1) >= (bfd_vma) (s->size)) ? (((bfd_vma) (s->size ) + (((bfd_size_type) (1 << power_of_two)) - 1)) & ~ (bfd_vma) (((bfd_size_type) (1 << power_of_two))-1)) : ~ (bfd_vma) 0); | |||
1418 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)((s)->alignment_power + 0)) | |||
1419 | { | |||
1420 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)(((s)->alignment_power = (power_of_two)),1)) | |||
1421 | return FALSE0; | |||
1422 | } | |||
1423 | ||||
1424 | /* Define the symbol as being at this point in the section. */ | |||
1425 | h->root.u.def.section = s; | |||
1426 | h->root.u.def.value = s->size; | |||
1427 | ||||
1428 | /* Increment the section size to make room for the symbol. */ | |||
1429 | s->size += h->size; | |||
1430 | ||||
1431 | return TRUE1; | |||
1432 | } | |||
1433 | ||||
1434 | /* Allocate space in .plt, .got and associated reloc sections for | |||
1435 | dynamic relocs. */ | |||
1436 | ||||
1437 | static bfd_boolean | |||
1438 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) | |||
1439 | { | |||
1440 | struct bfd_link_info *info; | |||
1441 | struct elf64_x86_64_link_hash_table *htab; | |||
1442 | struct elf64_x86_64_link_hash_entry *eh; | |||
1443 | struct elf64_x86_64_dyn_relocs *p; | |||
1444 | ||||
1445 | if (h->root.type == bfd_link_hash_indirect) | |||
1446 | return TRUE1; | |||
1447 | ||||
1448 | if (h->root.type == bfd_link_hash_warning) | |||
1449 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1450 | ||||
1451 | info = (struct bfd_link_info *) inf; | |||
1452 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
1453 | ||||
1454 | if (htab->elf.dynamic_sections_created | |||
1455 | && h->plt.refcount > 0) | |||
1456 | { | |||
1457 | /* Make sure this symbol is output as a dynamic symbol. | |||
1458 | Undefined weak syms won't yet be marked as dynamic. */ | |||
1459 | if (h->dynindx == -1 | |||
1460 | && !h->forced_local) | |||
1461 | { | |||
1462 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
1463 | return FALSE0; | |||
1464 | } | |||
1465 | ||||
1466 | if (info->shared | |||
1467 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)((1) && ((0) || !(h)->forced_local) && ((h )->dynindx != -1 || (h)->forced_local))) | |||
1468 | { | |||
1469 | asection *s = htab->splt; | |||
1470 | ||||
1471 | /* If this is the first .plt entry, make room for the special | |||
1472 | first entry. */ | |||
1473 | if (s->size == 0) | |||
1474 | s->size += PLT_ENTRY_SIZE16; | |||
1475 | ||||
1476 | h->plt.offset = s->size; | |||
1477 | ||||
1478 | /* If this symbol is not defined in a regular file, and we are | |||
1479 | not generating a shared library, then set the symbol to this | |||
1480 | location in the .plt. This is required to make function | |||
1481 | pointers compare as equal between the normal executable and | |||
1482 | the shared library. */ | |||
1483 | if (! info->shared | |||
1484 | && !h->def_regular) | |||
1485 | { | |||
1486 | h->root.u.def.section = s; | |||
1487 | h->root.u.def.value = h->plt.offset; | |||
1488 | } | |||
1489 | ||||
1490 | /* Make room for this entry. */ | |||
1491 | s->size += PLT_ENTRY_SIZE16; | |||
1492 | ||||
1493 | /* We also need to make an entry in the .got.plt section, which | |||
1494 | will be placed in the .got section by the linker script. */ | |||
1495 | htab->sgotplt->size += GOT_ENTRY_SIZE8; | |||
1496 | ||||
1497 | /* We also need to make an entry in the .rela.plt section. */ | |||
1498 | htab->srelplt->size += sizeof (Elf64_External_Rela); | |||
1499 | htab->srelplt->reloc_count++; | |||
1500 | } | |||
1501 | else | |||
1502 | { | |||
1503 | h->plt.offset = (bfd_vma) -1; | |||
1504 | h->needs_plt = 0; | |||
1505 | } | |||
1506 | } | |||
1507 | else | |||
1508 | { | |||
1509 | h->plt.offset = (bfd_vma) -1; | |||
1510 | h->needs_plt = 0; | |||
1511 | } | |||
1512 | ||||
1513 | eh = (struct elf64_x86_64_link_hash_entry *) h; | |||
1514 | eh->tlsdesc_got = (bfd_vma) -1; | |||
1515 | ||||
1516 | /* If R_X86_64_GOTTPOFF symbol is now local to the binary, | |||
1517 | make it a R_X86_64_TPOFF32 requiring no GOT entry. */ | |||
1518 | if (h->got.refcount > 0 | |||
1519 | && (!info->shared || info->executable) | |||
1520 | && h->dynindx == -1 | |||
1521 | && elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type == GOT_TLS_IE3) | |||
1522 | h->got.offset = (bfd_vma) -1; | |||
1523 | else if (h->got.refcount > 0) | |||
1524 | { | |||
1525 | asection *s; | |||
1526 | bfd_boolean dyn; | |||
1527 | int tls_type = elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type; | |||
1528 | ||||
1529 | /* Make sure this symbol is output as a dynamic symbol. | |||
1530 | Undefined weak syms won't yet be marked as dynamic. */ | |||
1531 | if (h->dynindx == -1 | |||
1532 | && !h->forced_local) | |||
1533 | { | |||
1534 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
1535 | return FALSE0; | |||
1536 | } | |||
1537 | ||||
1538 | if (GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4)))) | |||
1539 | { | |||
1540 | eh->tlsdesc_got = htab->sgotplt->size | |||
1541 | - elf64_x86_64_compute_jump_table_size (htab)((htab)->srelplt->reloc_count * 8); | |||
1542 | htab->sgotplt->size += 2 * GOT_ENTRY_SIZE8; | |||
1543 | h->got.offset = (bfd_vma) -2; | |||
1544 | } | |||
1545 | if (! GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4))) | |||
1546 | || GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4)))) | |||
1547 | { | |||
1548 | s = htab->sgot; | |||
1549 | h->got.offset = s->size; | |||
1550 | s->size += GOT_ENTRY_SIZE8; | |||
1551 | if (GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4)))) | |||
1552 | s->size += GOT_ENTRY_SIZE8; | |||
1553 | } | |||
1554 | dyn = htab->elf.dynamic_sections_created; | |||
1555 | /* R_X86_64_TLSGD needs one dynamic relocation if local symbol | |||
1556 | and two if global. | |||
1557 | R_X86_64_GOTTPOFF needs one dynamic relocation. */ | |||
1558 | if ((GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4))) && h->dynindx == -1) | |||
1559 | || tls_type == GOT_TLS_IE3) | |||
1560 | htab->srelgot->size += sizeof (Elf64_External_Rela); | |||
1561 | else if (GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4)))) | |||
1562 | htab->srelgot->size += 2 * sizeof (Elf64_External_Rela); | |||
1563 | else if (! GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4))) | |||
1564 | && (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_DEFAULT0 | |||
1565 | || h->root.type != bfd_link_hash_undefweak) | |||
1566 | && (info->shared | |||
1567 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)((dyn) && ((0) || !(h)->forced_local) && ( (h)->dynindx != -1 || (h)->forced_local)))) | |||
1568 | htab->srelgot->size += sizeof (Elf64_External_Rela); | |||
1569 | if (GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4)))) | |||
1570 | { | |||
1571 | htab->srelplt->size += sizeof (Elf64_External_Rela); | |||
1572 | htab->tlsdesc_plt = (bfd_vma) -1; | |||
1573 | } | |||
1574 | } | |||
1575 | else | |||
1576 | h->got.offset = (bfd_vma) -1; | |||
1577 | ||||
1578 | if (eh->dyn_relocs == NULL((void*)0)) | |||
1579 | return TRUE1; | |||
1580 | ||||
1581 | /* In the shared -Bsymbolic case, discard space allocated for | |||
1582 | dynamic pc-relative relocs against symbols which turn out to be | |||
1583 | defined in regular objects. For the normal shared case, discard | |||
1584 | space for pc-relative relocs that have become local due to symbol | |||
1585 | visibility changes. */ | |||
1586 | ||||
1587 | if (info->shared) | |||
1588 | { | |||
1589 | /* Relocs that use pc_count are those that appear on a call | |||
1590 | insn, or certain REL relocs that can generated via assembly. | |||
1591 | We want calls to protected symbols to resolve directly to the | |||
1592 | function rather than going via the plt. If people want | |||
1593 | function pointer comparisons to work as expected then they | |||
1594 | should avoid writing weird assembly. */ | |||
1595 | if (SYMBOL_CALLS_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 1)) | |||
1596 | { | |||
1597 | struct elf64_x86_64_dyn_relocs **pp; | |||
1598 | ||||
1599 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL((void*)0); ) | |||
1600 | { | |||
1601 | p->count -= p->pc_count; | |||
1602 | p->pc_count = 0; | |||
1603 | if (p->count == 0) | |||
1604 | *pp = p->next; | |||
1605 | else | |||
1606 | pp = &p->next; | |||
1607 | } | |||
1608 | } | |||
1609 | ||||
1610 | /* Also discard relocs on undefined weak syms with non-default | |||
1611 | visibility. */ | |||
1612 | if (eh->dyn_relocs != NULL((void*)0) | |||
1613 | && h->root.type == bfd_link_hash_undefweak) | |||
1614 | { | |||
1615 | if (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_DEFAULT0) | |||
1616 | eh->dyn_relocs = NULL((void*)0); | |||
1617 | ||||
1618 | /* Make sure undefined weak symbols are output as a dynamic | |||
1619 | symbol in PIEs. */ | |||
1620 | else if (h->dynindx == -1 | |||
1621 | && !h->forced_local) | |||
1622 | { | |||
1623 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
1624 | return FALSE0; | |||
1625 | } | |||
1626 | } | |||
1627 | } | |||
1628 | else if (ELIMINATE_COPY_RELOCS1) | |||
1629 | { | |||
1630 | /* For the non-shared case, discard space for relocs against | |||
1631 | symbols which turn out to need copy relocs or are not | |||
1632 | dynamic. */ | |||
1633 | ||||
1634 | if (!h->non_got_ref | |||
1635 | && ((h->def_dynamic | |||
1636 | && !h->def_regular) | |||
1637 | || (htab->elf.dynamic_sections_created | |||
1638 | && (h->root.type == bfd_link_hash_undefweak | |||
1639 | || h->root.type == bfd_link_hash_undefined)))) | |||
1640 | { | |||
1641 | /* Make sure this symbol is output as a dynamic symbol. | |||
1642 | Undefined weak syms won't yet be marked as dynamic. */ | |||
1643 | if (h->dynindx == -1 | |||
1644 | && !h->forced_local) | |||
1645 | { | |||
1646 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |||
1647 | return FALSE0; | |||
1648 | } | |||
1649 | ||||
1650 | /* If that succeeded, we know we'll be keeping all the | |||
1651 | relocs. */ | |||
1652 | if (h->dynindx != -1) | |||
1653 | goto keep; | |||
1654 | } | |||
1655 | ||||
1656 | eh->dyn_relocs = NULL((void*)0); | |||
1657 | ||||
1658 | keep: ; | |||
1659 | } | |||
1660 | ||||
1661 | /* Finally, allocate space. */ | |||
1662 | for (p = eh->dyn_relocs; p != NULL((void*)0); p = p->next) | |||
1663 | { | |||
1664 | asection *sreloc = elf_section_data (p->sec)((struct bfd_elf_section_data*)(p->sec)->used_by_bfd)->sreloc; | |||
1665 | sreloc->size += p->count * sizeof (Elf64_External_Rela); | |||
1666 | } | |||
1667 | ||||
1668 | return TRUE1; | |||
1669 | } | |||
1670 | ||||
1671 | /* Find any dynamic relocs that apply to read-only sections. */ | |||
1672 | ||||
1673 | static bfd_boolean | |||
1674 | readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf) | |||
1675 | { | |||
1676 | struct elf64_x86_64_link_hash_entry *eh; | |||
1677 | struct elf64_x86_64_dyn_relocs *p; | |||
1678 | ||||
1679 | if (h->root.type == bfd_link_hash_warning) | |||
1680 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |||
1681 | ||||
1682 | eh = (struct elf64_x86_64_link_hash_entry *) h; | |||
1683 | for (p = eh->dyn_relocs; p != NULL((void*)0); p = p->next) | |||
1684 | { | |||
1685 | asection *s = p->sec->output_section; | |||
1686 | ||||
1687 | if (s != NULL((void*)0) && (s->flags & SEC_READONLY0x008) != 0) | |||
1688 | { | |||
1689 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |||
1690 | ||||
1691 | info->flags |= DF_TEXTREL(1 << 2); | |||
1692 | ||||
1693 | /* Not an error, just cut short the traversal. */ | |||
1694 | return FALSE0; | |||
1695 | } | |||
1696 | } | |||
1697 | return TRUE1; | |||
1698 | } | |||
1699 | ||||
1700 | /* Set the sizes of the dynamic sections. */ | |||
1701 | ||||
1702 | static bfd_boolean | |||
1703 | elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
1704 | struct bfd_link_info *info) | |||
1705 | { | |||
1706 | struct elf64_x86_64_link_hash_table *htab; | |||
1707 | bfd *dynobj; | |||
1708 | asection *s; | |||
1709 | bfd_boolean relocs; | |||
1710 | bfd *ibfd; | |||
1711 | ||||
1712 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
1713 | dynobj = htab->elf.dynobj; | |||
1714 | if (dynobj == NULL((void*)0)) | |||
1715 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 1715, __PRETTY_FUNCTION__); | |||
1716 | ||||
1717 | if (htab->elf.dynamic_sections_created) | |||
1718 | { | |||
1719 | /* Set the contents of the .interp section to the interpreter. */ | |||
1720 | if (info->executable && !info->static_link) | |||
1721 | { | |||
1722 | s = bfd_get_section_by_name (dynobj, ".interp"); | |||
1723 | if (s == NULL((void*)0)) | |||
1724 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 1724, __PRETTY_FUNCTION__); | |||
1725 | s->size = sizeof ELF_DYNAMIC_INTERPRETER"/lib/ld64.so.1"; | |||
1726 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER"/lib/ld64.so.1"; | |||
1727 | } | |||
1728 | } | |||
1729 | ||||
1730 | /* Set up .got offsets for local syms, and space for local dynamic | |||
1731 | relocs. */ | |||
1732 | for (ibfd = info->input_bfds; ibfd != NULL((void*)0); ibfd = ibfd->link_next) | |||
1733 | { | |||
1734 | bfd_signed_vma *local_got; | |||
1735 | bfd_signed_vma *end_local_got; | |||
1736 | char *local_tls_type; | |||
1737 | bfd_vma *local_tlsdesc_gotent; | |||
1738 | bfd_size_type locsymcount; | |||
1739 | Elf_Internal_Shdr *symtab_hdr; | |||
1740 | asection *srel; | |||
1741 | ||||
1742 | if (bfd_get_flavour (ibfd)((ibfd)->xvec->flavour) != bfd_target_elf_flavour) | |||
1743 | continue; | |||
1744 | ||||
1745 | for (s = ibfd->sections; s != NULL((void*)0); s = s->next) | |||
1746 | { | |||
1747 | struct elf64_x86_64_dyn_relocs *p; | |||
1748 | ||||
1749 | for (p = (struct elf64_x86_64_dyn_relocs *) | |||
1750 | (elf_section_data (s)((struct bfd_elf_section_data*)(s)->used_by_bfd)->local_dynrel); | |||
1751 | p != NULL((void*)0); | |||
1752 | p = p->next) | |||
1753 | { | |||
1754 | if (!bfd_is_abs_section (p->sec)((p->sec) == ((asection *) &bfd_abs_section)) | |||
1755 | && bfd_is_abs_section (p->sec->output_section)((p->sec->output_section) == ((asection *) &bfd_abs_section ))) | |||
1756 | { | |||
1757 | /* Input section has been discarded, either because | |||
1758 | it is a copy of a linkonce section or due to | |||
1759 | linker script /DISCARD/, so we'll be discarding | |||
1760 | the relocs too. */ | |||
1761 | } | |||
1762 | else if (p->count != 0) | |||
1763 | { | |||
1764 | srel = elf_section_data (p->sec)((struct bfd_elf_section_data*)(p->sec)->used_by_bfd)->sreloc; | |||
1765 | srel->size += p->count * sizeof (Elf64_External_Rela); | |||
1766 | if ((p->sec->output_section->flags & SEC_READONLY0x008) != 0) | |||
1767 | info->flags |= DF_TEXTREL(1 << 2); | |||
1768 | ||||
1769 | } | |||
1770 | } | |||
1771 | } | |||
1772 | ||||
1773 | local_got = elf_local_got_refcounts (ibfd)(((ibfd) -> tdata.elf_obj_data) -> local_got.refcounts); | |||
1774 | if (!local_got) | |||
1775 | continue; | |||
1776 | ||||
1777 | symtab_hdr = &elf_tdata (ibfd)((ibfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
1778 | locsymcount = symtab_hdr->sh_info; | |||
1779 | end_local_got = local_got + locsymcount; | |||
1780 | local_tls_type = elf64_x86_64_local_got_tls_type (ibfd)(((struct elf64_x86_64_obj_tdata *) (ibfd)->tdata.any)-> local_got_tls_type); | |||
1781 | local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd)(((struct elf64_x86_64_obj_tdata *) (ibfd)->tdata.any)-> local_tlsdesc_gotent); | |||
1782 | s = htab->sgot; | |||
1783 | srel = htab->srelgot; | |||
1784 | for (; local_got < end_local_got; | |||
1785 | ++local_got, ++local_tls_type, ++local_tlsdesc_gotent) | |||
1786 | { | |||
1787 | *local_tlsdesc_gotent = (bfd_vma) -1; | |||
1788 | if (*local_got > 0) | |||
1789 | { | |||
1790 | if (GOT_TLS_GDESC_P (*local_tls_type)((*local_tls_type) == 4 || ((*local_tls_type) == (2 | 4)))) | |||
1791 | { | |||
1792 | *local_tlsdesc_gotent = htab->sgotplt->size | |||
1793 | - elf64_x86_64_compute_jump_table_size (htab)((htab)->srelplt->reloc_count * 8); | |||
1794 | htab->sgotplt->size += 2 * GOT_ENTRY_SIZE8; | |||
1795 | *local_got = (bfd_vma) -2; | |||
1796 | } | |||
1797 | if (! GOT_TLS_GDESC_P (*local_tls_type)((*local_tls_type) == 4 || ((*local_tls_type) == (2 | 4))) | |||
1798 | || GOT_TLS_GD_P (*local_tls_type)((*local_tls_type) == 2 || ((*local_tls_type) == (2 | 4)))) | |||
1799 | { | |||
1800 | *local_got = s->size; | |||
1801 | s->size += GOT_ENTRY_SIZE8; | |||
1802 | if (GOT_TLS_GD_P (*local_tls_type)((*local_tls_type) == 2 || ((*local_tls_type) == (2 | 4)))) | |||
1803 | s->size += GOT_ENTRY_SIZE8; | |||
1804 | } | |||
1805 | if (info->shared | |||
1806 | || GOT_TLS_GD_ANY_P (*local_tls_type)(((*local_tls_type) == 2 || ((*local_tls_type) == (2 | 4))) || ((*local_tls_type) == 4 || ((*local_tls_type) == (2 | 4)))) | |||
1807 | || *local_tls_type == GOT_TLS_IE3) | |||
1808 | { | |||
1809 | if (GOT_TLS_GDESC_P (*local_tls_type)((*local_tls_type) == 4 || ((*local_tls_type) == (2 | 4)))) | |||
1810 | { | |||
1811 | htab->srelplt->size += sizeof (Elf64_External_Rela); | |||
1812 | htab->tlsdesc_plt = (bfd_vma) -1; | |||
1813 | } | |||
1814 | if (! GOT_TLS_GDESC_P (*local_tls_type)((*local_tls_type) == 4 || ((*local_tls_type) == (2 | 4))) | |||
1815 | || GOT_TLS_GD_P (*local_tls_type)((*local_tls_type) == 2 || ((*local_tls_type) == (2 | 4)))) | |||
1816 | srel->size += sizeof (Elf64_External_Rela); | |||
1817 | } | |||
1818 | } | |||
1819 | else | |||
1820 | *local_got = (bfd_vma) -1; | |||
1821 | } | |||
1822 | } | |||
1823 | ||||
1824 | if (htab->tls_ld_got.refcount > 0) | |||
1825 | { | |||
1826 | /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD | |||
1827 | relocs. */ | |||
1828 | htab->tls_ld_got.offset = htab->sgot->size; | |||
1829 | htab->sgot->size += 2 * GOT_ENTRY_SIZE8; | |||
1830 | htab->srelgot->size += sizeof (Elf64_External_Rela); | |||
1831 | } | |||
1832 | else | |||
1833 | htab->tls_ld_got.offset = -1; | |||
1834 | ||||
1835 | /* Allocate global sym .plt and .got entries, and space for global | |||
1836 | sym dynamic relocs. */ | |||
1837 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info)(bfd_link_hash_traverse (&(&htab->elf)->root, ( bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (allocate_dynrelocs ), ((void *) info))); | |||
1838 | ||||
1839 | /* For every jump slot reserved in the sgotplt, reloc_count is | |||
1840 | incremented. However, when we reserve space for TLS descriptors, | |||
1841 | it's not incremented, so in order to compute the space reserved | |||
1842 | for them, it suffices to multiply the reloc count by the jump | |||
1843 | slot size. */ | |||
1844 | if (htab->srelplt) | |||
1845 | htab->sgotplt_jump_table_size | |||
1846 | = elf64_x86_64_compute_jump_table_size (htab)((htab)->srelplt->reloc_count * 8); | |||
1847 | ||||
1848 | if (htab->tlsdesc_plt) | |||
1849 | { | |||
1850 | /* If we're not using lazy TLS relocations, don't generate the | |||
1851 | PLT and GOT entries they require. */ | |||
1852 | if ((info->flags & DF_BIND_NOW(1 << 3))) | |||
1853 | htab->tlsdesc_plt = 0; | |||
1854 | else | |||
1855 | { | |||
1856 | htab->tlsdesc_got = htab->sgot->size; | |||
1857 | htab->sgot->size += GOT_ENTRY_SIZE8; | |||
1858 | /* Reserve room for the initial entry. | |||
1859 | FIXME: we could probably do away with it in this case. */ | |||
1860 | if (htab->splt->size == 0) | |||
1861 | htab->splt->size += PLT_ENTRY_SIZE16; | |||
1862 | htab->tlsdesc_plt = htab->splt->size; | |||
1863 | htab->splt->size += PLT_ENTRY_SIZE16; | |||
1864 | } | |||
1865 | } | |||
1866 | ||||
1867 | /* We now have determined the sizes of the various dynamic sections. | |||
1868 | Allocate memory for them. */ | |||
1869 | relocs = FALSE0; | |||
1870 | for (s = dynobj->sections; s != NULL((void*)0); s = s->next) | |||
1871 | { | |||
1872 | if ((s->flags & SEC_LINKER_CREATED0x200000) == 0) | |||
1873 | continue; | |||
1874 | ||||
1875 | if (s == htab->splt | |||
1876 | || s == htab->sgot | |||
1877 | || s == htab->sgotplt | |||
1878 | || s == htab->sdynbss) | |||
1879 | { | |||
1880 | /* Strip this section if we don't need it; see the | |||
1881 | comment below. */ | |||
1882 | } | |||
1883 | else if (strncmp (bfd_get_section_name (dynobj, s)((s)->name + 0), ".rela", 5) == 0) | |||
1884 | { | |||
1885 | if (s->size != 0 && s != htab->srelplt) | |||
1886 | relocs = TRUE1; | |||
1887 | ||||
1888 | /* We use the reloc_count field as a counter if we need | |||
1889 | to copy relocs into the output file. */ | |||
1890 | if (s != htab->srelplt) | |||
1891 | s->reloc_count = 0; | |||
1892 | } | |||
1893 | else | |||
1894 | { | |||
1895 | /* It's not one of our sections, so don't allocate space. */ | |||
1896 | continue; | |||
1897 | } | |||
1898 | ||||
1899 | if (s->size == 0) | |||
1900 | { | |||
1901 | /* If we don't need this section, strip it from the | |||
1902 | output file. This is mostly to handle .rela.bss and | |||
1903 | .rela.plt. We must create both sections in | |||
1904 | create_dynamic_sections, because they must be created | |||
1905 | before the linker maps input sections to output | |||
1906 | sections. The linker does that before | |||
1907 | adjust_dynamic_symbol is called, and it is that | |||
1908 | function which decides whether anything needs to go | |||
1909 | into these sections. */ | |||
1910 | ||||
1911 | s->flags |= SEC_EXCLUDE0x8000; | |||
1912 | continue; | |||
1913 | } | |||
1914 | ||||
1915 | if ((s->flags & SEC_HAS_CONTENTS0x100) == 0) | |||
1916 | continue; | |||
1917 | ||||
1918 | /* Allocate memory for the section contents. We use bfd_zalloc | |||
1919 | here in case unused entries are not reclaimed before the | |||
1920 | section's contents are written out. This should not happen, | |||
1921 | but this way if it does, we get a R_X86_64_NONE reloc instead | |||
1922 | of garbage. */ | |||
1923 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); | |||
1924 | if (s->contents == NULL((void*)0)) | |||
1925 | return FALSE0; | |||
1926 | } | |||
1927 | ||||
1928 | if (htab->elf.dynamic_sections_created) | |||
1929 | { | |||
1930 | /* Add some entries to the .dynamic section. We fill in the | |||
1931 | values later, in elf64_x86_64_finish_dynamic_sections, but we | |||
1932 | must add the entries now so that we get the correct size for | |||
1933 | the .dynamic section. The DT_DEBUG entry is filled in by the | |||
1934 | dynamic linker and used by the debugger. */ | |||
1935 | #define add_dynamic_entry(TAG, VAL) \ | |||
1936 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |||
1937 | ||||
1938 | if (info->executable) | |||
1939 | { | |||
1940 | if (!add_dynamic_entry (DT_DEBUG21, 0)) | |||
1941 | return FALSE0; | |||
1942 | } | |||
1943 | ||||
1944 | if (htab->splt->size != 0) | |||
1945 | { | |||
1946 | if (!add_dynamic_entry (DT_PLTGOT3, 0) | |||
1947 | || !add_dynamic_entry (DT_PLTRELSZ2, 0) | |||
1948 | || !add_dynamic_entry (DT_PLTREL20, DT_RELA7) | |||
1949 | || !add_dynamic_entry (DT_JMPREL23, 0)) | |||
1950 | return FALSE0; | |||
1951 | ||||
1952 | if (htab->tlsdesc_plt | |||
1953 | && (!add_dynamic_entry (DT_TLSDESC_PLT0x6ffffef6, 0) | |||
1954 | || !add_dynamic_entry (DT_TLSDESC_GOT0x6ffffef7, 0))) | |||
1955 | return FALSE0; | |||
1956 | } | |||
1957 | ||||
1958 | if (relocs) | |||
1959 | { | |||
1960 | if (!add_dynamic_entry (DT_RELA7, 0) | |||
1961 | || !add_dynamic_entry (DT_RELASZ8, 0) | |||
1962 | || !add_dynamic_entry (DT_RELAENT9, sizeof (Elf64_External_Rela))) | |||
1963 | return FALSE0; | |||
1964 | ||||
1965 | /* If any dynamic relocs apply to a read-only section, | |||
1966 | then we need a DT_TEXTREL entry. */ | |||
1967 | if ((info->flags & DF_TEXTREL(1 << 2)) == 0) | |||
1968 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,(bfd_link_hash_traverse (&(&htab->elf)->root, ( bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (readonly_dynrelocs ), ((void *) info))) | |||
1969 | (PTR) info)(bfd_link_hash_traverse (&(&htab->elf)->root, ( bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (readonly_dynrelocs ), ((void *) info))); | |||
1970 | ||||
1971 | if ((info->flags & DF_TEXTREL(1 << 2)) != 0) | |||
1972 | { | |||
1973 | if (!add_dynamic_entry (DT_TEXTREL22, 0)) | |||
1974 | return FALSE0; | |||
1975 | } | |||
1976 | } | |||
1977 | } | |||
1978 | #undef add_dynamic_entry | |||
1979 | ||||
1980 | return TRUE1; | |||
1981 | } | |||
1982 | ||||
1983 | static bfd_boolean | |||
1984 | elf64_x86_64_always_size_sections (bfd *output_bfd, | |||
1985 | struct bfd_link_info *info) | |||
1986 | { | |||
1987 | asection *tls_sec = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->tls_sec; | |||
1988 | ||||
1989 | if (tls_sec) | |||
1990 | { | |||
1991 | struct elf_link_hash_entry *tlsbase; | |||
1992 | ||||
1993 | tlsbase = elf_link_hash_lookup (elf_hash_table (info),((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( "_TLS_MODULE_BASE_"), (0), (0), (0))) | |||
1994 | "_TLS_MODULE_BASE_",((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( "_TLS_MODULE_BASE_"), (0), (0), (0))) | |||
1995 | FALSE, FALSE, FALSE)((struct elf_link_hash_entry *) bfd_link_hash_lookup (&(( (struct elf_link_hash_table *) ((info)->hash)))->root, ( "_TLS_MODULE_BASE_"), (0), (0), (0))); | |||
1996 | ||||
1997 | if (tlsbase && tlsbase->type == STT_TLS6) | |||
1998 | { | |||
1999 | struct bfd_link_hash_entry *bh = NULL((void*)0); | |||
2000 | const struct elf_backend_data *bed | |||
2001 | = get_elf_backend_data (output_bfd)((const struct elf_backend_data *) (output_bfd)->xvec-> backend_data); | |||
2002 | ||||
2003 | if (!(_bfd_generic_link_add_one_symbol | |||
2004 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL0x01, | |||
2005 | tls_sec, 0, NULL((void*)0), FALSE0, | |||
2006 | bed->collect, &bh))) | |||
2007 | return FALSE0; | |||
2008 | tlsbase = (struct elf_link_hash_entry *)bh; | |||
2009 | tlsbase->def_regular = 1; | |||
2010 | tlsbase->other = STV_HIDDEN2; | |||
2011 | (*bed->elf_backend_hide_symbol_bfd_elf_link_hash_hide_symbol) (info, tlsbase, TRUE1); | |||
2012 | } | |||
2013 | } | |||
2014 | ||||
2015 | return TRUE1; | |||
2016 | } | |||
2017 | ||||
2018 | /* Return the base VMA address which should be subtracted from real addresses | |||
2019 | when resolving @dtpoff relocation. | |||
2020 | This is PT_TLS segment p_vaddr. */ | |||
2021 | ||||
2022 | static bfd_vma | |||
2023 | dtpoff_base (struct bfd_link_info *info) | |||
2024 | { | |||
2025 | /* If tls_sec is NULL, we should have signalled an error already. */ | |||
2026 | if (elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->tls_sec == NULL((void*)0)) | |||
2027 | return 0; | |||
2028 | return elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash))->tls_sec->vma; | |||
2029 | } | |||
2030 | ||||
2031 | /* Return the relocation value for @tpoff relocation | |||
2032 | if STT_TLS virtual address is ADDRESS. */ | |||
2033 | ||||
2034 | static bfd_vma | |||
2035 | tpoff (struct bfd_link_info *info, bfd_vma address) | |||
2036 | { | |||
2037 | struct elf_link_hash_table *htab = elf_hash_table (info)((struct elf_link_hash_table *) ((info)->hash)); | |||
2038 | ||||
2039 | /* If tls_segment is NULL, we should have signalled an error already. */ | |||
2040 | if (htab->tls_sec == NULL((void*)0)) | |||
2041 | return 0; | |||
2042 | return address - htab->tls_size - htab->tls_sec->vma; | |||
2043 | } | |||
2044 | ||||
2045 | /* Is the instruction before OFFSET in CONTENTS a 32bit relative | |||
2046 | branch? */ | |||
2047 | ||||
2048 | static bfd_boolean | |||
2049 | is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset) | |||
2050 | { | |||
2051 | /* Opcode Instruction | |||
2052 | 0xe8 call | |||
2053 | 0xe9 jump | |||
2054 | 0x0f 0x8x conditional jump */ | |||
2055 | return ((offset > 0 | |||
2056 | && (contents [offset - 1] == 0xe8 | |||
2057 | || contents [offset - 1] == 0xe9)) | |||
2058 | || (offset > 1 | |||
2059 | && contents [offset - 2] == 0x0f | |||
2060 | && (contents [offset - 1] & 0xf0) == 0x80)); | |||
2061 | } | |||
2062 | ||||
2063 | /* Relocate an x86_64 ELF section. */ | |||
2064 | ||||
2065 | static bfd_boolean | |||
2066 | elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, | |||
2067 | bfd *input_bfd, asection *input_section, | |||
2068 | bfd_byte *contents, Elf_Internal_Rela *relocs, | |||
2069 | Elf_Internal_Sym *local_syms, | |||
2070 | asection **local_sections) | |||
2071 | { | |||
2072 | struct elf64_x86_64_link_hash_table *htab; | |||
2073 | Elf_Internal_Shdr *symtab_hdr; | |||
2074 | struct elf_link_hash_entry **sym_hashes; | |||
2075 | bfd_vma *local_got_offsets; | |||
2076 | bfd_vma *local_tlsdesc_gotents; | |||
2077 | Elf_Internal_Rela *rel; | |||
2078 | Elf_Internal_Rela *relend; | |||
2079 | ||||
2080 | if (info->relocatable) | |||
| ||||
2081 | return TRUE1; | |||
2082 | ||||
2083 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
2084 | symtab_hdr = &elf_tdata (input_bfd)((input_bfd) -> tdata.elf_obj_data)->symtab_hdr; | |||
2085 | sym_hashes = elf_sym_hashes (input_bfd)(((input_bfd) -> tdata.elf_obj_data) -> sym_hashes); | |||
2086 | local_got_offsets = elf_local_got_offsets (input_bfd)(((input_bfd) -> tdata.elf_obj_data) -> local_got.offsets ); | |||
2087 | local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd)(((struct elf64_x86_64_obj_tdata *) (input_bfd)->tdata.any )->local_tlsdesc_gotent); | |||
2088 | ||||
2089 | rel = relocs; | |||
2090 | relend = relocs + input_section->reloc_count; | |||
2091 | for (; rel < relend; rel++) | |||
2092 | { | |||
2093 | unsigned int r_type; | |||
2094 | reloc_howto_type *howto; | |||
2095 | unsigned long r_symndx; | |||
2096 | struct elf_link_hash_entry *h; | |||
2097 | Elf_Internal_Sym *sym; | |||
2098 | asection *sec; | |||
2099 | bfd_vma off, offplt; | |||
2100 | bfd_vma relocation; | |||
2101 | bfd_boolean unresolved_reloc; | |||
2102 | bfd_reloc_status_type r; | |||
2103 | int tls_type; | |||
2104 | ||||
2105 | r_type = ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff); | |||
2106 | if (r_type == (int) R_X86_64_GNU_VTINHERIT | |||
2107 | || r_type == (int) R_X86_64_GNU_VTENTRY) | |||
2108 | continue; | |||
2109 | ||||
2110 | if (r_type >= R_X86_64_max) | |||
2111 | { | |||
2112 | bfd_set_error (bfd_error_bad_value); | |||
2113 | return FALSE0; | |||
2114 | } | |||
2115 | ||||
2116 | howto = x86_64_elf_howto_table + r_type; | |||
2117 | r_symndx = ELF64_R_SYM (rel->r_info)((rel->r_info) >> 32); | |||
2118 | h = NULL((void*)0); | |||
2119 | sym = NULL((void*)0); | |||
2120 | sec = NULL((void*)0); | |||
2121 | unresolved_reloc = FALSE0; | |||
2122 | if (r_symndx < symtab_hdr->sh_info) | |||
2123 | { | |||
2124 | sym = local_syms + r_symndx; | |||
2125 | sec = local_sections[r_symndx]; | |||
2126 | ||||
2127 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |||
2128 | } | |||
2129 | else | |||
2130 | { | |||
2131 | bfd_boolean warned; | |||
2132 | ||||
2133 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,do { if (sym_hashes == ((void*)0)) return 0; h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; warned = 0; unresolved_reloc = 0; relocation = 0; if (h->root.type == bfd_link_hash_defined || h->root .type == bfd_link_hash_defweak) { sec = h->root.u.def.section ; if (sec == ((void*)0) || sec->output_section == ((void*) 0)) unresolved_reloc = 1; else relocation = (h->root.u.def .value + sec->output_section->vma + sec->output_offset ); } else if (h->root.type == bfd_link_hash_undefweak) ; else if (info->unresolved_syms_in_objects == RM_IGNORE && ((h->other) & 0x3) == 0) ; else { bfd_boolean err; err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR || ((h->other) & 0x3) != 0); if (!info->callbacks-> undefined_symbol (info, h->root.root.string, input_bfd, input_section , rel->r_offset, err)) return 0; warned = 1; } } while (0) | |||
2134 | r_symndx, symtab_hdr, sym_hashes,do { if (sym_hashes == ((void*)0)) return 0; h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; warned = 0; unresolved_reloc = 0; relocation = 0; if (h->root.type == bfd_link_hash_defined || h->root .type == bfd_link_hash_defweak) { sec = h->root.u.def.section ; if (sec == ((void*)0) || sec->output_section == ((void*) 0)) unresolved_reloc = 1; else relocation = (h->root.u.def .value + sec->output_section->vma + sec->output_offset ); } else if (h->root.type == bfd_link_hash_undefweak) ; else if (info->unresolved_syms_in_objects == RM_IGNORE && ((h->other) & 0x3) == 0) ; else { bfd_boolean err; err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR || ((h->other) & 0x3) != 0); if (!info->callbacks-> undefined_symbol (info, h->root.root.string, input_bfd, input_section , rel->r_offset, err)) return 0; warned = 1; } } while (0) | |||
2135 | h, sec, relocation,do { if (sym_hashes == ((void*)0)) return 0; h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; warned = 0; unresolved_reloc = 0; relocation = 0; if (h->root.type == bfd_link_hash_defined || h->root .type == bfd_link_hash_defweak) { sec = h->root.u.def.section ; if (sec == ((void*)0) || sec->output_section == ((void*) 0)) unresolved_reloc = 1; else relocation = (h->root.u.def .value + sec->output_section->vma + sec->output_offset ); } else if (h->root.type == bfd_link_hash_undefweak) ; else if (info->unresolved_syms_in_objects == RM_IGNORE && ((h->other) & 0x3) == 0) ; else { bfd_boolean err; err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR || ((h->other) & 0x3) != 0); if (!info->callbacks-> undefined_symbol (info, h->root.root.string, input_bfd, input_section , rel->r_offset, err)) return 0; warned = 1; } } while (0) | |||
2136 | unresolved_reloc, warned)do { if (sym_hashes == ((void*)0)) return 0; h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; warned = 0; unresolved_reloc = 0; relocation = 0; if (h->root.type == bfd_link_hash_defined || h->root .type == bfd_link_hash_defweak) { sec = h->root.u.def.section ; if (sec == ((void*)0) || sec->output_section == ((void*) 0)) unresolved_reloc = 1; else relocation = (h->root.u.def .value + sec->output_section->vma + sec->output_offset ); } else if (h->root.type == bfd_link_hash_undefweak) ; else if (info->unresolved_syms_in_objects == RM_IGNORE && ((h->other) & 0x3) == 0) ; else { bfd_boolean err; err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR || ((h->other) & 0x3) != 0); if (!info->callbacks-> undefined_symbol (info, h->root.root.string, input_bfd, input_section , rel->r_offset, err)) return 0; warned = 1; } } while (0); | |||
2137 | } | |||
2138 | /* When generating a shared object, the relocations handled here are | |||
2139 | copied into the output file to be resolved at run time. */ | |||
2140 | switch (r_type) | |||
2141 | { | |||
2142 | asection *base_got; | |||
2143 | case R_X86_64_GOT32: | |||
2144 | case R_X86_64_GOT64: | |||
2145 | /* Relocation is to the entry for this symbol in the global | |||
2146 | offset table. */ | |||
2147 | case R_X86_64_GOTPCREL: | |||
2148 | case R_X86_64_GOTPCREL64: | |||
2149 | /* Use global offset table entry as symbol value. */ | |||
2150 | case R_X86_64_GOTPLT64: | |||
2151 | /* This is the same as GOT64 for relocation purposes, but | |||
2152 | indicates the existence of a PLT entry. The difficulty is, | |||
2153 | that we must calculate the GOT slot offset from the PLT | |||
2154 | offset, if this symbol got a PLT entry (it was global). | |||
2155 | Additionally if it's computed from the PLT entry, then that | |||
2156 | GOT offset is relative to .got.plt, not to .got. */ | |||
2157 | base_got = htab->sgot; | |||
2158 | ||||
2159 | if (htab->sgot == NULL((void*)0)) | |||
2160 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2160, __PRETTY_FUNCTION__); | |||
2161 | ||||
2162 | if (h != NULL((void*)0)) | |||
2163 | { | |||
2164 | bfd_boolean dyn; | |||
2165 | ||||
2166 | off = h->got.offset; | |||
2167 | if (h->needs_plt | |||
2168 | && h->plt.offset != (bfd_vma)-1 | |||
2169 | && off == (bfd_vma)-1) | |||
2170 | { | |||
2171 | /* We can't use h->got.offset here to save | |||
2172 | state, or even just remember the offset, as | |||
2173 | finish_dynamic_symbol would use that as offset into | |||
2174 | .got. */ | |||
2175 | bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE16 - 1; | |||
2176 | off = (plt_index + 3) * GOT_ENTRY_SIZE8; | |||
2177 | base_got = htab->sgotplt; | |||
2178 | } | |||
2179 | ||||
2180 | dyn = htab->elf.dynamic_sections_created; | |||
2181 | ||||
2182 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)((dyn) && ((info->shared) || !(h)->forced_local ) && ((h)->dynindx != -1 || (h)->forced_local)) | |||
2183 | || (info->shared | |||
2184 | && SYMBOL_REFERENCES_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 0)) | |||
2185 | || (ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) | |||
2186 | && h->root.type == bfd_link_hash_undefweak)) | |||
2187 | { | |||
2188 | /* This is actually a static link, or it is a -Bsymbolic | |||
2189 | link and the symbol is defined locally, or the symbol | |||
2190 | was forced to be local because of a version file. We | |||
2191 | must initialize this entry in the global offset table. | |||
2192 | Since the offset must always be a multiple of 8, we | |||
2193 | use the least significant bit to record whether we | |||
2194 | have initialized it already. | |||
2195 | ||||
2196 | When doing a dynamic link, we create a .rela.got | |||
2197 | relocation entry to initialize the value. This is | |||
2198 | done in the finish_dynamic_symbol routine. */ | |||
2199 | if ((off & 1) != 0) | |||
2200 | off &= ~1; | |||
2201 | else | |||
2202 | { | |||
2203 | bfd_put_64 (output_bfd, relocation,((*((output_bfd)->xvec->bfd_putx64)) ((relocation), (base_got ->contents + off))) | |||
2204 | base_got->contents + off)((*((output_bfd)->xvec->bfd_putx64)) ((relocation), (base_got ->contents + off))); | |||
2205 | /* Note that this is harmless for the GOTPLT64 case, | |||
2206 | as -1 | 1 still is -1. */ | |||
2207 | h->got.offset |= 1; | |||
2208 | } | |||
2209 | } | |||
2210 | else | |||
2211 | unresolved_reloc = FALSE0; | |||
2212 | } | |||
2213 | else | |||
2214 | { | |||
2215 | if (local_got_offsets == NULL((void*)0)) | |||
2216 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2216, __PRETTY_FUNCTION__); | |||
2217 | ||||
2218 | off = local_got_offsets[r_symndx]; | |||
2219 | ||||
2220 | /* The offset must always be a multiple of 8. We use | |||
2221 | the least significant bit to record whether we have | |||
2222 | already generated the necessary reloc. */ | |||
2223 | if ((off & 1) != 0) | |||
2224 | off &= ~1; | |||
2225 | else | |||
2226 | { | |||
2227 | bfd_put_64 (output_bfd, relocation,((*((output_bfd)->xvec->bfd_putx64)) ((relocation), (base_got ->contents + off))) | |||
2228 | base_got->contents + off)((*((output_bfd)->xvec->bfd_putx64)) ((relocation), (base_got ->contents + off))); | |||
2229 | ||||
2230 | if (info->shared) | |||
2231 | { | |||
2232 | asection *s; | |||
2233 | Elf_Internal_Rela outrel; | |||
2234 | bfd_byte *loc; | |||
2235 | ||||
2236 | /* We need to generate a R_X86_64_RELATIVE reloc | |||
2237 | for the dynamic linker. */ | |||
2238 | s = htab->srelgot; | |||
2239 | if (s == NULL((void*)0)) | |||
2240 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2240, __PRETTY_FUNCTION__); | |||
2241 | ||||
2242 | outrel.r_offset = (base_got->output_section->vma | |||
2243 | + base_got->output_offset | |||
2244 | + off); | |||
2245 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (R_X86_64_RELATIVE )); | |||
2246 | outrel.r_addend = relocation; | |||
2247 | loc = s->contents; | |||
2248 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela); | |||
2249 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2250 | } | |||
2251 | ||||
2252 | local_got_offsets[r_symndx] |= 1; | |||
2253 | } | |||
2254 | } | |||
2255 | ||||
2256 | if (off >= (bfd_vma) -2) | |||
2257 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2257, __PRETTY_FUNCTION__); | |||
2258 | ||||
2259 | relocation = base_got->output_section->vma | |||
2260 | + base_got->output_offset + off; | |||
2261 | if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64) | |||
2262 | relocation -= htab->sgotplt->output_section->vma | |||
2263 | - htab->sgotplt->output_offset; | |||
2264 | ||||
2265 | break; | |||
2266 | ||||
2267 | case R_X86_64_GOTOFF64: | |||
2268 | /* Relocation is relative to the start of the global offset | |||
2269 | table. */ | |||
2270 | ||||
2271 | /* Check to make sure it isn't a protected function symbol | |||
2272 | for shared library since it may not be local when used | |||
2273 | as function address. */ | |||
2274 | if (info->shared | |||
2275 | && h | |||
2276 | && h->def_regular | |||
2277 | && h->type == STT_FUNC2 | |||
2278 | && ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_PROTECTED3) | |||
2279 | { | |||
2280 | (*_bfd_error_handler) | |||
2281 | (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object")("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object" ), | |||
2282 | input_bfd, h->root.root.string); | |||
2283 | bfd_set_error (bfd_error_bad_value); | |||
2284 | return FALSE0; | |||
2285 | } | |||
2286 | ||||
2287 | /* Note that sgot is not involved in this | |||
2288 | calculation. We always want the start of .got.plt. If we | |||
2289 | defined _GLOBAL_OFFSET_TABLE_ in a different way, as is | |||
2290 | permitted by the ABI, we might have to change this | |||
2291 | calculation. */ | |||
2292 | relocation -= htab->sgotplt->output_section->vma | |||
2293 | + htab->sgotplt->output_offset; | |||
2294 | break; | |||
2295 | ||||
2296 | case R_X86_64_GOTPC32: | |||
2297 | case R_X86_64_GOTPC64: | |||
2298 | /* Use global offset table as symbol value. */ | |||
2299 | relocation = htab->sgotplt->output_section->vma | |||
2300 | + htab->sgotplt->output_offset; | |||
2301 | unresolved_reloc = FALSE0; | |||
2302 | break; | |||
2303 | ||||
2304 | case R_X86_64_PLTOFF64: | |||
2305 | /* Relocation is PLT entry relative to GOT. For local | |||
2306 | symbols it's the symbol itself relative to GOT. */ | |||
2307 | if (h != NULL((void*)0) | |||
2308 | /* See PLT32 handling. */ | |||
2309 | && h->plt.offset != (bfd_vma) -1 | |||
2310 | && htab->splt != NULL((void*)0)) | |||
2311 | { | |||
2312 | relocation = (htab->splt->output_section->vma | |||
2313 | + htab->splt->output_offset | |||
2314 | + h->plt.offset); | |||
2315 | unresolved_reloc = FALSE0; | |||
2316 | } | |||
2317 | ||||
2318 | relocation -= htab->sgotplt->output_section->vma | |||
2319 | + htab->sgotplt->output_offset; | |||
2320 | break; | |||
2321 | ||||
2322 | case R_X86_64_PLT32: | |||
2323 | /* Relocation is to the entry for this symbol in the | |||
2324 | procedure linkage table. */ | |||
2325 | ||||
2326 | /* Resolve a PLT32 reloc against a local symbol directly, | |||
2327 | without using the procedure linkage table. */ | |||
2328 | if (h == NULL((void*)0)) | |||
2329 | break; | |||
2330 | ||||
2331 | if (h->plt.offset == (bfd_vma) -1 | |||
2332 | || htab->splt == NULL((void*)0)) | |||
2333 | { | |||
2334 | /* We didn't make a PLT entry for this symbol. This | |||
2335 | happens when statically linking PIC code, or when | |||
2336 | using -Bsymbolic. */ | |||
2337 | break; | |||
2338 | } | |||
2339 | ||||
2340 | relocation = (htab->splt->output_section->vma | |||
2341 | + htab->splt->output_offset | |||
2342 | + h->plt.offset); | |||
2343 | unresolved_reloc = FALSE0; | |||
2344 | break; | |||
2345 | ||||
2346 | case R_X86_64_PC8: | |||
2347 | case R_X86_64_PC16: | |||
2348 | case R_X86_64_PC32: | |||
2349 | if (info->shared | |||
2350 | && !SYMBOL_REFERENCES_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 0) | |||
2351 | && (input_section->flags & SEC_ALLOC0x001) != 0 | |||
2352 | && (input_section->flags & SEC_READONLY0x008) != 0 | |||
2353 | && (!h->def_regular | |||
| ||||
2354 | || r_type != R_X86_64_PC32 | |||
2355 | || h->type != STT_FUNC2 | |||
2356 | || ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) != STV_PROTECTED3 | |||
2357 | || !is_32bit_relative_branch (contents, | |||
2358 | rel->r_offset))) | |||
2359 | { | |||
2360 | if (h->def_regular | |||
2361 | && r_type == R_X86_64_PC32 | |||
2362 | && h->type == STT_FUNC2 | |||
2363 | && ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_PROTECTED3) | |||
2364 | (*_bfd_error_handler) | |||
2365 | (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object")("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object" ), | |||
2366 | input_bfd, h->root.root.string); | |||
2367 | else | |||
2368 | (*_bfd_error_handler) | |||
2369 | (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC")("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC" ), | |||
2370 | input_bfd, x86_64_elf_howto_table[r_type].name, | |||
2371 | h->root.root.string); | |||
2372 | bfd_set_error (bfd_error_bad_value); | |||
2373 | return FALSE0; | |||
2374 | } | |||
2375 | /* Fall through. */ | |||
2376 | ||||
2377 | case R_X86_64_8: | |||
2378 | case R_X86_64_16: | |||
2379 | case R_X86_64_32: | |||
2380 | case R_X86_64_PC64: | |||
2381 | case R_X86_64_64: | |||
2382 | /* FIXME: The ABI says the linker should make sure the value is | |||
2383 | the same when it's zeroextended to 64 bit. */ | |||
2384 | ||||
2385 | /* r_symndx will be zero only for relocs against symbols | |||
2386 | from removed linkonce sections, or sections discarded by | |||
2387 | a linker script. */ | |||
2388 | if (r_symndx == 0 | |||
2389 | || (input_section->flags & SEC_ALLOC0x001) == 0) | |||
2390 | break; | |||
2391 | ||||
2392 | if ((info->shared | |||
2393 | && (h == NULL((void*)0) | |||
2394 | || ELF_ST_VISIBILITY (h->other)((h->other) & 0x3) == STV_DEFAULT0 | |||
2395 | || h->root.type != bfd_link_hash_undefweak) | |||
2396 | && ((r_type != R_X86_64_PC8 | |||
2397 | && r_type != R_X86_64_PC16 | |||
2398 | && r_type != R_X86_64_PC32 | |||
2399 | && r_type != R_X86_64_PC64) | |||
2400 | || !SYMBOL_CALLS_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 1))) | |||
2401 | || (ELIMINATE_COPY_RELOCS1 | |||
2402 | && !info->shared | |||
2403 | && h != NULL((void*)0) | |||
2404 | && h->dynindx != -1 | |||
2405 | && !h->non_got_ref | |||
2406 | && ((h->def_dynamic | |||
2407 | && !h->def_regular) | |||
2408 | || h->root.type == bfd_link_hash_undefweak | |||
2409 | || h->root.type == bfd_link_hash_undefined))) | |||
2410 | { | |||
2411 | Elf_Internal_Rela outrel; | |||
2412 | bfd_byte *loc; | |||
2413 | bfd_boolean skip, relocate; | |||
2414 | asection *sreloc; | |||
2415 | ||||
2416 | /* When generating a shared object, these relocations | |||
2417 | are copied into the output file to be resolved at run | |||
2418 | time. */ | |||
2419 | skip = FALSE0; | |||
2420 | relocate = FALSE0; | |||
2421 | ||||
2422 | outrel.r_offset = | |||
2423 | _bfd_elf_section_offset (output_bfd, info, input_section, | |||
2424 | rel->r_offset); | |||
2425 | if (outrel.r_offset == (bfd_vma) -1) | |||
2426 | skip = TRUE1; | |||
2427 | else if (outrel.r_offset == (bfd_vma) -2) | |||
2428 | skip = TRUE1, relocate = TRUE1; | |||
2429 | ||||
2430 | outrel.r_offset += (input_section->output_section->vma | |||
2431 | + input_section->output_offset); | |||
2432 | ||||
2433 | if (skip) | |||
2434 | memset (&outrel, 0, sizeof outrel); | |||
2435 | ||||
2436 | /* h->dynindx may be -1 if this symbol was marked to | |||
2437 | become local. */ | |||
2438 | else if (h != NULL((void*)0) | |||
2439 | && h->dynindx != -1 | |||
2440 | && (r_type == R_X86_64_PC8 | |||
2441 | || r_type == R_X86_64_PC16 | |||
2442 | || r_type == R_X86_64_PC32 | |||
2443 | || r_type == R_X86_64_PC64 | |||
2444 | || !info->shared | |||
2445 | || !info->symbolic | |||
2446 | || !h->def_regular)) | |||
2447 | { | |||
2448 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type)(((bfd_vma) (h->dynindx) << 31 << 1) + (bfd_vma ) (r_type)); | |||
2449 | outrel.r_addend = rel->r_addend; | |||
2450 | } | |||
2451 | else | |||
2452 | { | |||
2453 | /* This symbol is local, or marked to become local. */ | |||
2454 | if (r_type == R_X86_64_64) | |||
2455 | { | |||
2456 | relocate = TRUE1; | |||
2457 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (R_X86_64_RELATIVE )); | |||
2458 | outrel.r_addend = relocation + rel->r_addend; | |||
2459 | } | |||
2460 | else | |||
2461 | { | |||
2462 | long sindx; | |||
2463 | ||||
2464 | if (bfd_is_abs_section (sec)((sec) == ((asection *) &bfd_abs_section))) | |||
2465 | sindx = 0; | |||
2466 | else if (sec == NULL((void*)0) || sec->owner == NULL((void*)0)) | |||
2467 | { | |||
2468 | bfd_set_error (bfd_error_bad_value); | |||
2469 | return FALSE0; | |||
2470 | } | |||
2471 | else | |||
2472 | { | |||
2473 | asection *osec; | |||
2474 | ||||
2475 | osec = sec->output_section; | |||
2476 | sindx = elf_section_data (osec)((struct bfd_elf_section_data*)(osec)->used_by_bfd)->dynindx; | |||
2477 | BFD_ASSERT (sindx > 0)do { if (!(sindx > 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2477); } while (0); | |||
2478 | } | |||
2479 | ||||
2480 | outrel.r_info = ELF64_R_INFO (sindx, r_type)(((bfd_vma) (sindx) << 31 << 1) + (bfd_vma) (r_type )); | |||
2481 | outrel.r_addend = relocation + rel->r_addend; | |||
2482 | } | |||
2483 | } | |||
2484 | ||||
2485 | sreloc = elf_section_data (input_section)((struct bfd_elf_section_data*)(input_section)->used_by_bfd )->sreloc; | |||
2486 | if (sreloc == NULL((void*)0)) | |||
2487 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2487, __PRETTY_FUNCTION__); | |||
2488 | ||||
2489 | loc = sreloc->contents; | |||
2490 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |||
2491 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2492 | ||||
2493 | /* If this reloc is against an external symbol, we do | |||
2494 | not want to fiddle with the addend. Otherwise, we | |||
2495 | need to include the symbol value so that it becomes | |||
2496 | an addend for the dynamic reloc. */ | |||
2497 | if (! relocate) | |||
2498 | continue; | |||
2499 | } | |||
2500 | ||||
2501 | break; | |||
2502 | ||||
2503 | case R_X86_64_TLSGD: | |||
2504 | case R_X86_64_GOTPC32_TLSDESC: | |||
2505 | case R_X86_64_TLSDESC_CALL: | |||
2506 | case R_X86_64_GOTTPOFF: | |||
2507 | r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL((void*)0)); | |||
2508 | tls_type = GOT_UNKNOWN0; | |||
2509 | if (h == NULL((void*)0) && local_got_offsets) | |||
2510 | tls_type = elf64_x86_64_local_got_tls_type (input_bfd)(((struct elf64_x86_64_obj_tdata *) (input_bfd)->tdata.any )->local_got_tls_type) [r_symndx]; | |||
2511 | else if (h != NULL((void*)0)) | |||
2512 | { | |||
2513 | tls_type = elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type; | |||
2514 | if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE3) | |||
2515 | r_type = R_X86_64_TPOFF32; | |||
2516 | } | |||
2517 | if (r_type == R_X86_64_TLSGD | |||
2518 | || r_type == R_X86_64_GOTPC32_TLSDESC | |||
2519 | || r_type == R_X86_64_TLSDESC_CALL) | |||
2520 | { | |||
2521 | if (tls_type == GOT_TLS_IE3) | |||
2522 | r_type = R_X86_64_GOTTPOFF; | |||
2523 | } | |||
2524 | ||||
2525 | if (r_type == R_X86_64_TPOFF32) | |||
2526 | { | |||
2527 | BFD_ASSERT (! unresolved_reloc)do { if (!(! unresolved_reloc)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2527); } while (0); | |||
2528 | if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_TLSGD) | |||
2529 | { | |||
2530 | unsigned int i; | |||
2531 | static unsigned char tlsgd[8] | |||
2532 | = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 }; | |||
2533 | ||||
2534 | /* GD->LE transition. | |||
2535 | .byte 0x66; leaq foo@tlsgd(%rip), %rdi | |||
2536 | .word 0x6666; rex64; call __tls_get_addr@plt | |||
2537 | Change it into: | |||
2538 | movq %fs:0, %rax | |||
2539 | leaq foo@tpoff(%rax), %rax */ | |||
2540 | BFD_ASSERT (rel->r_offset >= 4)do { if (!(rel->r_offset >= 4)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2540); } while (0); | |||
2541 | for (i = 0; i < 4; i++) | |||
2542 | BFD_ASSERT (bfd_get_8 (input_bfd,do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2544); } while (0) | |||
2543 | contents + rel->r_offset - 4 + i)do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2544); } while (0) | |||
2544 | == tlsgd[i])do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2544); } while (0); | |||
2545 | BFD_ASSERT (rel->r_offset + 12 <= input_section->size)do { if (!(rel->r_offset + 12 <= input_section->size )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2545); } while (0); | |||
2546 | for (i = 0; i < 4; i++) | |||
2547 | BFD_ASSERT (bfd_get_8 (input_bfd,do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2549); } while (0) | |||
2548 | contents + rel->r_offset + 4 + i)do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2549); } while (0) | |||
2549 | == tlsgd[i+4])do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2549); } while (0); | |||
2550 | BFD_ASSERT (rel + 1 < relend)do { if (!(rel + 1 < relend)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2550); } while (0); | |||
2551 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)do { if (!(((rel[1].r_info) & 0xffffffff) == R_X86_64_PLT32 )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2551); } while (0); | |||
2552 | memcpy (contents + rel->r_offset - 4, | |||
2553 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0", | |||
2554 | 16); | |||
2555 | bfd_put_32 (output_bfd, tpoff (info, relocation),((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + rel->r_offset + 8))) | |||
2556 | contents + rel->r_offset + 8)((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + rel->r_offset + 8))); | |||
2557 | /* Skip R_X86_64_PLT32. */ | |||
2558 | rel++; | |||
2559 | continue; | |||
2560 | } | |||
2561 | else if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_GOTPC32_TLSDESC) | |||
2562 | { | |||
2563 | /* GDesc -> LE transition. | |||
2564 | It's originally something like: | |||
2565 | leaq x@tlsdesc(%rip), %rax | |||
2566 | ||||
2567 | Change it to: | |||
2568 | movl $x@tpoff, %rax | |||
2569 | ||||
2570 | Registers other than %rax may be set up here. */ | |||
2571 | ||||
2572 | unsigned int val, type, type2; | |||
2573 | bfd_vma roff; | |||
2574 | ||||
2575 | /* First, make sure it's a leaq adding rip to a | |||
2576 | 32-bit offset into any register, although it's | |||
2577 | probably almost always going to be rax. */ | |||
2578 | roff = rel->r_offset; | |||
2579 | BFD_ASSERT (roff >= 3)do { if (!(roff >= 3)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2579); } while (0); | |||
2580 | type = bfd_get_8 (input_bfd, contents + roff - 3)(*(unsigned char *) (contents + roff - 3) & 0xff); | |||
2581 | BFD_ASSERT ((type & 0xfb) == 0x48)do { if (!((type & 0xfb) == 0x48)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2581); } while (0); | |||
2582 | type2 = bfd_get_8 (input_bfd, contents + roff - 2)(*(unsigned char *) (contents + roff - 2) & 0xff); | |||
2583 | BFD_ASSERT (type2 == 0x8d)do { if (!(type2 == 0x8d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2583); } while (0); | |||
2584 | val = bfd_get_8 (input_bfd, contents + roff - 1)(*(unsigned char *) (contents + roff - 1) & 0xff); | |||
2585 | BFD_ASSERT ((val & 0xc7) == 0x05)do { if (!((val & 0xc7) == 0x05)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2585); } while (0); | |||
2586 | BFD_ASSERT (roff + 4 <= input_section->size)do { if (!(roff + 4 <= input_section->size)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",2586 ); } while (0); | |||
2587 | ||||
2588 | /* Now modify the instruction as appropriate. */ | |||
2589 | bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1),((void) (*((unsigned char *) (contents + roff - 3)) = (0x48 | ((type >> 2) & 1)) & 0xff)) | |||
2590 | contents + roff - 3)((void) (*((unsigned char *) (contents + roff - 3)) = (0x48 | ((type >> 2) & 1)) & 0xff)); | |||
2591 | bfd_put_8 (output_bfd, 0xc7, contents + roff - 2)((void) (*((unsigned char *) (contents + roff - 2)) = (0xc7) & 0xff)); | |||
2592 | bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),((void) (*((unsigned char *) (contents + roff - 1)) = (0xc0 | ((val >> 3) & 7)) & 0xff)) | |||
2593 | contents + roff - 1)((void) (*((unsigned char *) (contents + roff - 1)) = (0xc0 | ((val >> 3) & 7)) & 0xff)); | |||
2594 | bfd_put_32 (output_bfd, tpoff (info, relocation),((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + roff))) | |||
2595 | contents + roff)((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + roff))); | |||
2596 | continue; | |||
2597 | } | |||
2598 | else if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_TLSDESC_CALL) | |||
2599 | { | |||
2600 | /* GDesc -> LE transition. | |||
2601 | It's originally: | |||
2602 | call *(%rax) | |||
2603 | Turn it into: | |||
2604 | nop; nop. */ | |||
2605 | ||||
2606 | unsigned int val, type; | |||
2607 | bfd_vma roff; | |||
2608 | ||||
2609 | /* First, make sure it's a call *(%rax). */ | |||
2610 | roff = rel->r_offset; | |||
2611 | BFD_ASSERT (roff + 2 <= input_section->size)do { if (!(roff + 2 <= input_section->size)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",2611 ); } while (0); | |||
2612 | type = bfd_get_8 (input_bfd, contents + roff)(*(unsigned char *) (contents + roff) & 0xff); | |||
2613 | BFD_ASSERT (type == 0xff)do { if (!(type == 0xff)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2613); } while (0); | |||
2614 | val = bfd_get_8 (input_bfd, contents + roff + 1)(*(unsigned char *) (contents + roff + 1) & 0xff); | |||
2615 | BFD_ASSERT (val == 0x10)do { if (!(val == 0x10)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2615); } while (0); | |||
2616 | ||||
2617 | /* Now modify the instruction as appropriate. */ | |||
2618 | bfd_put_8 (output_bfd, 0x90, contents + roff)((void) (*((unsigned char *) (contents + roff)) = (0x90) & 0xff)); | |||
2619 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1)((void) (*((unsigned char *) (contents + roff + 1)) = (0x90) & 0xff)); | |||
2620 | continue; | |||
2621 | } | |||
2622 | else | |||
2623 | { | |||
2624 | unsigned int val, type, reg; | |||
2625 | ||||
2626 | /* IE->LE transition: | |||
2627 | Originally it can be one of: | |||
2628 | movq foo@gottpoff(%rip), %reg | |||
2629 | addq foo@gottpoff(%rip), %reg | |||
2630 | We change it into: | |||
2631 | movq $foo, %reg | |||
2632 | leaq foo(%reg), %reg | |||
2633 | addq $foo, %reg. */ | |||
2634 | BFD_ASSERT (rel->r_offset >= 3)do { if (!(rel->r_offset >= 3)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2634); } while (0); | |||
2635 | val = bfd_get_8 (input_bfd, contents + rel->r_offset - 3)(*(unsigned char *) (contents + rel->r_offset - 3) & 0xff ); | |||
2636 | BFD_ASSERT (val == 0x48 || val == 0x4c)do { if (!(val == 0x48 || val == 0x4c)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2636); } while (0); | |||
2637 | type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2)(*(unsigned char *) (contents + rel->r_offset - 2) & 0xff ); | |||
2638 | BFD_ASSERT (type == 0x8b || type == 0x03)do { if (!(type == 0x8b || type == 0x03)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2638); } while (0); | |||
2639 | reg = bfd_get_8 (input_bfd, contents + rel->r_offset - 1)(*(unsigned char *) (contents + rel->r_offset - 1) & 0xff ); | |||
2640 | BFD_ASSERT ((reg & 0xc7) == 5)do { if (!((reg & 0xc7) == 5)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2640); } while (0); | |||
2641 | reg >>= 3; | |||
2642 | BFD_ASSERT (rel->r_offset + 4 <= input_section->size)do { if (!(rel->r_offset + 4 <= input_section->size) ) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2642); } while (0); | |||
2643 | if (type == 0x8b) | |||
2644 | { | |||
2645 | /* movq */ | |||
2646 | if (val == 0x4c) | |||
2647 | bfd_put_8 (output_bfd, 0x49,((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x49) & 0xff)) | |||
2648 | contents + rel->r_offset - 3)((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x49) & 0xff)); | |||
2649 | bfd_put_8 (output_bfd, 0xc7,((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0xc7) & 0xff)) | |||
2650 | contents + rel->r_offset - 2)((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0xc7) & 0xff)); | |||
2651 | bfd_put_8 (output_bfd, 0xc0 | reg,((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0xc0 | reg) & 0xff)) | |||
2652 | contents + rel->r_offset - 1)((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0xc0 | reg) & 0xff)); | |||
2653 | } | |||
2654 | else if (reg == 4) | |||
2655 | { | |||
2656 | /* addq -> addq - addressing with %rsp/%r12 is | |||
2657 | special */ | |||
2658 | if (val == 0x4c) | |||
2659 | bfd_put_8 (output_bfd, 0x49,((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x49) & 0xff)) | |||
2660 | contents + rel->r_offset - 3)((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x49) & 0xff)); | |||
2661 | bfd_put_8 (output_bfd, 0x81,((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0x81) & 0xff)) | |||
2662 | contents + rel->r_offset - 2)((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0x81) & 0xff)); | |||
2663 | bfd_put_8 (output_bfd, 0xc0 | reg,((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0xc0 | reg) & 0xff)) | |||
2664 | contents + rel->r_offset - 1)((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0xc0 | reg) & 0xff)); | |||
2665 | } | |||
2666 | else | |||
2667 | { | |||
2668 | /* addq -> leaq */ | |||
2669 | if (val == 0x4c) | |||
2670 | bfd_put_8 (output_bfd, 0x4d,((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x4d) & 0xff)) | |||
2671 | contents + rel->r_offset - 3)((void) (*((unsigned char *) (contents + rel->r_offset - 3 )) = (0x4d) & 0xff)); | |||
2672 | bfd_put_8 (output_bfd, 0x8d,((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0x8d) & 0xff)) | |||
2673 | contents + rel->r_offset - 2)((void) (*((unsigned char *) (contents + rel->r_offset - 2 )) = (0x8d) & 0xff)); | |||
2674 | bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3),((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0x80 | reg | (reg << 3)) & 0xff)) | |||
2675 | contents + rel->r_offset - 1)((void) (*((unsigned char *) (contents + rel->r_offset - 1 )) = (0x80 | reg | (reg << 3)) & 0xff)); | |||
2676 | } | |||
2677 | bfd_put_32 (output_bfd, tpoff (info, relocation),((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + rel->r_offset))) | |||
2678 | contents + rel->r_offset)((*((output_bfd)->xvec->bfd_putx32)) ((tpoff (info, relocation )),(contents + rel->r_offset))); | |||
2679 | continue; | |||
2680 | } | |||
2681 | } | |||
2682 | ||||
2683 | if (htab->sgot == NULL((void*)0)) | |||
2684 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2684, __PRETTY_FUNCTION__); | |||
2685 | ||||
2686 | if (h != NULL((void*)0)) | |||
2687 | { | |||
2688 | off = h->got.offset; | |||
2689 | offplt = elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tlsdesc_got; | |||
2690 | } | |||
2691 | else | |||
2692 | { | |||
2693 | if (local_got_offsets == NULL((void*)0)) | |||
2694 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2694, __PRETTY_FUNCTION__); | |||
2695 | ||||
2696 | off = local_got_offsets[r_symndx]; | |||
2697 | offplt = local_tlsdesc_gotents[r_symndx]; | |||
2698 | } | |||
2699 | ||||
2700 | if ((off & 1) != 0) | |||
2701 | off &= ~1; | |||
2702 | else | |||
2703 | { | |||
2704 | Elf_Internal_Rela outrel; | |||
2705 | bfd_byte *loc; | |||
2706 | int dr_type, indx; | |||
2707 | asection *sreloc; | |||
2708 | ||||
2709 | if (htab->srelgot == NULL((void*)0)) | |||
2710 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2710, __PRETTY_FUNCTION__); | |||
2711 | ||||
2712 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |||
2713 | ||||
2714 | if (GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4)))) | |||
2715 | { | |||
2716 | outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC)(((bfd_vma) (indx) << 31 << 1) + (bfd_vma) (R_X86_64_TLSDESC )); | |||
2717 | BFD_ASSERT (htab->sgotplt_jump_table_size + offpltdo { if (!(htab->sgotplt_jump_table_size + offplt + 2 * 8 <= htab->sgotplt->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2718); } while (0) | |||
2718 | + 2 * GOT_ENTRY_SIZE <= htab->sgotplt->size)do { if (!(htab->sgotplt_jump_table_size + offplt + 2 * 8 <= htab->sgotplt->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2718); } while (0); | |||
2719 | outrel.r_offset = (htab->sgotplt->output_section->vma | |||
2720 | + htab->sgotplt->output_offset | |||
2721 | + offplt | |||
2722 | + htab->sgotplt_jump_table_size); | |||
2723 | sreloc = htab->srelplt; | |||
2724 | loc = sreloc->contents; | |||
2725 | loc += sreloc->reloc_count++ | |||
2726 | * sizeof (Elf64_External_Rela); | |||
2727 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2728); } while (0) | |||
2728 | <= sreloc->contents + sreloc->size)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2728); } while (0); | |||
2729 | if (indx == 0) | |||
2730 | outrel.r_addend = relocation - dtpoff_base (info); | |||
2731 | else | |||
2732 | outrel.r_addend = 0; | |||
2733 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2734 | } | |||
2735 | ||||
2736 | sreloc = htab->srelgot; | |||
2737 | ||||
2738 | outrel.r_offset = (htab->sgot->output_section->vma | |||
2739 | + htab->sgot->output_offset + off); | |||
2740 | ||||
2741 | if (GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4)))) | |||
2742 | dr_type = R_X86_64_DTPMOD64; | |||
2743 | else if (GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4)))) | |||
2744 | goto dr_done; | |||
2745 | else | |||
2746 | dr_type = R_X86_64_TPOFF64; | |||
2747 | ||||
2748 | bfd_put_64 (output_bfd, 0, htab->sgot->contents + off)((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off))); | |||
2749 | outrel.r_addend = 0; | |||
2750 | if ((dr_type == R_X86_64_TPOFF64 | |||
2751 | || dr_type == R_X86_64_TLSDESC) && indx == 0) | |||
2752 | outrel.r_addend = relocation - dtpoff_base (info); | |||
2753 | outrel.r_info = ELF64_R_INFO (indx, dr_type)(((bfd_vma) (indx) << 31 << 1) + (bfd_vma) (dr_type )); | |||
2754 | ||||
2755 | loc = sreloc->contents; | |||
2756 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |||
2757 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2758); } while (0) | |||
2758 | <= sreloc->contents + sreloc->size)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2758); } while (0); | |||
2759 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2760 | ||||
2761 | if (GOT_TLS_GD_P (tls_type)((tls_type) == 2 || ((tls_type) == (2 | 4)))) | |||
2762 | { | |||
2763 | if (indx == 0) | |||
2764 | { | |||
2765 | BFD_ASSERT (! unresolved_reloc)do { if (!(! unresolved_reloc)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2765); } while (0); | |||
2766 | bfd_put_64 (output_bfd,((*((output_bfd)->xvec->bfd_putx64)) ((relocation - dtpoff_base (info)), (htab->sgot->contents + off + 8))) | |||
2767 | relocation - dtpoff_base (info),((*((output_bfd)->xvec->bfd_putx64)) ((relocation - dtpoff_base (info)), (htab->sgot->contents + off + 8))) | |||
2768 | htab->sgot->contents + off + GOT_ENTRY_SIZE)((*((output_bfd)->xvec->bfd_putx64)) ((relocation - dtpoff_base (info)), (htab->sgot->contents + off + 8))); | |||
2769 | } | |||
2770 | else | |||
2771 | { | |||
2772 | bfd_put_64 (output_bfd, 0,((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off + 8))) | |||
2773 | htab->sgot->contents + off + GOT_ENTRY_SIZE)((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off + 8))); | |||
2774 | outrel.r_info = ELF64_R_INFO (indx,(((bfd_vma) (indx) << 31 << 1) + (bfd_vma) (R_X86_64_DTPOFF64 )) | |||
2775 | R_X86_64_DTPOFF64)(((bfd_vma) (indx) << 31 << 1) + (bfd_vma) (R_X86_64_DTPOFF64 )); | |||
2776 | outrel.r_offset += GOT_ENTRY_SIZE8; | |||
2777 | sreloc->reloc_count++; | |||
2778 | loc += sizeof (Elf64_External_Rela); | |||
2779 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2780); } while (0) | |||
2780 | <= sreloc->contents + sreloc->size)do { if (!(loc + sizeof (Elf64_External_Rela) <= sreloc-> contents + sreloc->size)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2780); } while (0); | |||
2781 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2782 | } | |||
2783 | } | |||
2784 | ||||
2785 | dr_done: | |||
2786 | if (h != NULL((void*)0)) | |||
2787 | h->got.offset |= 1; | |||
2788 | else | |||
2789 | local_got_offsets[r_symndx] |= 1; | |||
2790 | } | |||
2791 | ||||
2792 | if (off >= (bfd_vma) -2 | |||
2793 | && ! GOT_TLS_GDESC_P (tls_type)((tls_type) == 4 || ((tls_type) == (2 | 4)))) | |||
2794 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2794, __PRETTY_FUNCTION__); | |||
2795 | if (r_type == ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff)) | |||
2796 | { | |||
2797 | if (r_type == R_X86_64_GOTPC32_TLSDESC | |||
2798 | || r_type == R_X86_64_TLSDESC_CALL) | |||
2799 | relocation = htab->sgotplt->output_section->vma | |||
2800 | + htab->sgotplt->output_offset | |||
2801 | + offplt + htab->sgotplt_jump_table_size; | |||
2802 | else | |||
2803 | relocation = htab->sgot->output_section->vma | |||
2804 | + htab->sgot->output_offset + off; | |||
2805 | unresolved_reloc = FALSE0; | |||
2806 | } | |||
2807 | else if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_TLSGD) | |||
2808 | { | |||
2809 | unsigned int i; | |||
2810 | static unsigned char tlsgd[8] | |||
2811 | = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 }; | |||
2812 | ||||
2813 | /* GD->IE transition. | |||
2814 | .byte 0x66; leaq foo@tlsgd(%rip), %rdi | |||
2815 | .word 0x6666; rex64; call __tls_get_addr@plt | |||
2816 | Change it into: | |||
2817 | movq %fs:0, %rax | |||
2818 | addq foo@gottpoff(%rip), %rax */ | |||
2819 | BFD_ASSERT (rel->r_offset >= 4)do { if (!(rel->r_offset >= 4)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2819); } while (0); | |||
2820 | for (i = 0; i < 4; i++) | |||
2821 | BFD_ASSERT (bfd_get_8 (input_bfd,do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2823); } while (0) | |||
2822 | contents + rel->r_offset - 4 + i)do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2823); } while (0) | |||
2823 | == tlsgd[i])do { if (!((*(unsigned char *) (contents + rel->r_offset - 4 + i) & 0xff) == tlsgd[i])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2823); } while (0); | |||
2824 | BFD_ASSERT (rel->r_offset + 12 <= input_section->size)do { if (!(rel->r_offset + 12 <= input_section->size )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2824); } while (0); | |||
2825 | for (i = 0; i < 4; i++) | |||
2826 | BFD_ASSERT (bfd_get_8 (input_bfd,do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2828); } while (0) | |||
2827 | contents + rel->r_offset + 4 + i)do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2828); } while (0) | |||
2828 | == tlsgd[i+4])do { if (!((*(unsigned char *) (contents + rel->r_offset + 4 + i) & 0xff) == tlsgd[i+4])) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2828); } while (0); | |||
2829 | BFD_ASSERT (rel + 1 < relend)do { if (!(rel + 1 < relend)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2829); } while (0); | |||
2830 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)do { if (!(((rel[1].r_info) & 0xffffffff) == R_X86_64_PLT32 )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2830); } while (0); | |||
2831 | memcpy (contents + rel->r_offset - 4, | |||
2832 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0", | |||
2833 | 16); | |||
2834 | ||||
2835 | relocation = (htab->sgot->output_section->vma | |||
2836 | + htab->sgot->output_offset + off | |||
2837 | - rel->r_offset | |||
2838 | - input_section->output_section->vma | |||
2839 | - input_section->output_offset | |||
2840 | - 12); | |||
2841 | bfd_put_32 (output_bfd, relocation,((*((output_bfd)->xvec->bfd_putx32)) ((relocation),(contents + rel->r_offset + 8))) | |||
2842 | contents + rel->r_offset + 8)((*((output_bfd)->xvec->bfd_putx32)) ((relocation),(contents + rel->r_offset + 8))); | |||
2843 | /* Skip R_X86_64_PLT32. */ | |||
2844 | rel++; | |||
2845 | continue; | |||
2846 | } | |||
2847 | else if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_GOTPC32_TLSDESC) | |||
2848 | { | |||
2849 | /* GDesc -> IE transition. | |||
2850 | It's originally something like: | |||
2851 | leaq x@tlsdesc(%rip), %rax | |||
2852 | ||||
2853 | Change it to: | |||
2854 | movq x@gottpoff(%rip), %rax # before nop; nop | |||
2855 | ||||
2856 | Registers other than %rax may be set up here. */ | |||
2857 | ||||
2858 | unsigned int val, type, type2; | |||
2859 | bfd_vma roff; | |||
2860 | ||||
2861 | /* First, make sure it's a leaq adding rip to a 32-bit | |||
2862 | offset into any register, although it's probably | |||
2863 | almost always going to be rax. */ | |||
2864 | roff = rel->r_offset; | |||
2865 | BFD_ASSERT (roff >= 3)do { if (!(roff >= 3)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2865); } while (0); | |||
2866 | type = bfd_get_8 (input_bfd, contents + roff - 3)(*(unsigned char *) (contents + roff - 3) & 0xff); | |||
2867 | BFD_ASSERT ((type & 0xfb) == 0x48)do { if (!((type & 0xfb) == 0x48)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2867); } while (0); | |||
2868 | type2 = bfd_get_8 (input_bfd, contents + roff - 2)(*(unsigned char *) (contents + roff - 2) & 0xff); | |||
2869 | BFD_ASSERT (type2 == 0x8d)do { if (!(type2 == 0x8d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2869); } while (0); | |||
2870 | val = bfd_get_8 (input_bfd, contents + roff - 1)(*(unsigned char *) (contents + roff - 1) & 0xff); | |||
2871 | BFD_ASSERT ((val & 0xc7) == 0x05)do { if (!((val & 0xc7) == 0x05)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2871); } while (0); | |||
2872 | BFD_ASSERT (roff + 4 <= input_section->size)do { if (!(roff + 4 <= input_section->size)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",2872 ); } while (0); | |||
2873 | ||||
2874 | /* Now modify the instruction as appropriate. */ | |||
2875 | /* To turn a leaq into a movq in the form we use it, it | |||
2876 | suffices to change the second byte from 0x8d to | |||
2877 | 0x8b. */ | |||
2878 | bfd_put_8 (output_bfd, 0x8b, contents + roff - 2)((void) (*((unsigned char *) (contents + roff - 2)) = (0x8b) & 0xff)); | |||
2879 | ||||
2880 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2881 | htab->sgot->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2882 | + htab->sgot->output_offset + off((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2883 | - rel->r_offset((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2884 | - input_section->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2885 | - input_section->output_offset((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2886 | - 4,((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))) | |||
2887 | contents + roff)((*((output_bfd)->xvec->bfd_putx32)) ((htab->sgot-> output_section->vma + htab->sgot->output_offset + off - rel->r_offset - input_section->output_section->vma - input_section->output_offset - 4),(contents + roff))); | |||
2888 | continue; | |||
2889 | } | |||
2890 | else if (ELF64_R_TYPE (rel->r_info)((rel->r_info) & 0xffffffff) == R_X86_64_TLSDESC_CALL) | |||
2891 | { | |||
2892 | /* GDesc -> IE transition. | |||
2893 | It's originally: | |||
2894 | call *(%rax) | |||
2895 | ||||
2896 | Change it to: | |||
2897 | nop; nop. */ | |||
2898 | ||||
2899 | unsigned int val, type; | |||
2900 | bfd_vma roff; | |||
2901 | ||||
2902 | /* First, make sure it's a call *(%eax). */ | |||
2903 | roff = rel->r_offset; | |||
2904 | BFD_ASSERT (roff + 2 <= input_section->size)do { if (!(roff + 2 <= input_section->size)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",2904 ); } while (0); | |||
2905 | type = bfd_get_8 (input_bfd, contents + roff)(*(unsigned char *) (contents + roff) & 0xff); | |||
2906 | BFD_ASSERT (type == 0xff)do { if (!(type == 0xff)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2906); } while (0); | |||
2907 | val = bfd_get_8 (input_bfd, contents + roff + 1)(*(unsigned char *) (contents + roff + 1) & 0xff); | |||
2908 | BFD_ASSERT (val == 0x10)do { if (!(val == 0x10)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2908); } while (0); | |||
2909 | ||||
2910 | /* Now modify the instruction as appropriate. */ | |||
2911 | bfd_put_8 (output_bfd, 0x90, contents + roff)((void) (*((unsigned char *) (contents + roff)) = (0x90) & 0xff)); | |||
2912 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1)((void) (*((unsigned char *) (contents + roff + 1)) = (0x90) & 0xff)); | |||
2913 | ||||
2914 | continue; | |||
2915 | } | |||
2916 | else | |||
2917 | BFD_ASSERT (FALSE)do { if (!(0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2917); } while (0); | |||
2918 | break; | |||
2919 | ||||
2920 | case R_X86_64_TLSLD: | |||
2921 | if (! info->shared) | |||
2922 | { | |||
2923 | /* LD->LE transition: | |||
2924 | Ensure it is: | |||
2925 | leaq foo@tlsld(%rip), %rdi; call __tls_get_addr@plt. | |||
2926 | We change it into: | |||
2927 | .word 0x6666; .byte 0x66; movl %fs:0, %rax. */ | |||
2928 | BFD_ASSERT (rel->r_offset >= 3)do { if (!(rel->r_offset >= 3)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2928); } while (0); | |||
2929 | BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 3)do { if (!((*(unsigned char *) (contents + rel->r_offset - 3) & 0xff) == 0x48)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2930); } while (0) | |||
2930 | == 0x48)do { if (!((*(unsigned char *) (contents + rel->r_offset - 3) & 0xff) == 0x48)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2930); } while (0); | |||
2931 | BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 2)do { if (!((*(unsigned char *) (contents + rel->r_offset - 2) & 0xff) == 0x8d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2932); } while (0) | |||
2932 | == 0x8d)do { if (!((*(unsigned char *) (contents + rel->r_offset - 2) & 0xff) == 0x8d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2932); } while (0); | |||
2933 | BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 1)do { if (!((*(unsigned char *) (contents + rel->r_offset - 1) & 0xff) == 0x3d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2934); } while (0) | |||
2934 | == 0x3d)do { if (!((*(unsigned char *) (contents + rel->r_offset - 1) & 0xff) == 0x3d)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2934); } while (0); | |||
2935 | BFD_ASSERT (rel->r_offset + 9 <= input_section->size)do { if (!(rel->r_offset + 9 <= input_section->size) ) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2935); } while (0); | |||
2936 | BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4)do { if (!((*(unsigned char *) (contents + rel->r_offset + 4) & 0xff) == 0xe8)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2937); } while (0) | |||
2937 | == 0xe8)do { if (!((*(unsigned char *) (contents + rel->r_offset + 4) & 0xff) == 0xe8)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2937); } while (0); | |||
2938 | BFD_ASSERT (rel + 1 < relend)do { if (!(rel + 1 < relend)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2938); } while (0); | |||
2939 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)do { if (!(((rel[1].r_info) & 0xffffffff) == R_X86_64_PLT32 )) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,2939); } while (0); | |||
2940 | memcpy (contents + rel->r_offset - 3, | |||
2941 | "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12); | |||
2942 | /* Skip R_X86_64_PLT32. */ | |||
2943 | rel++; | |||
2944 | continue; | |||
2945 | } | |||
2946 | ||||
2947 | if (htab->sgot == NULL((void*)0)) | |||
2948 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2948, __PRETTY_FUNCTION__); | |||
2949 | ||||
2950 | off = htab->tls_ld_got.offset; | |||
2951 | if (off & 1) | |||
2952 | off &= ~1; | |||
2953 | else | |||
2954 | { | |||
2955 | Elf_Internal_Rela outrel; | |||
2956 | bfd_byte *loc; | |||
2957 | ||||
2958 | if (htab->srelgot == NULL((void*)0)) | |||
2959 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 2959, __PRETTY_FUNCTION__); | |||
2960 | ||||
2961 | outrel.r_offset = (htab->sgot->output_section->vma | |||
2962 | + htab->sgot->output_offset + off); | |||
2963 | ||||
2964 | bfd_put_64 (output_bfd, 0,((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off))) | |||
2965 | htab->sgot->contents + off)((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off))); | |||
2966 | bfd_put_64 (output_bfd, 0,((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off + 8))) | |||
2967 | htab->sgot->contents + off + GOT_ENTRY_SIZE)((*((output_bfd)->xvec->bfd_putx64)) ((0), (htab->sgot ->contents + off + 8))); | |||
2968 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (R_X86_64_DTPMOD64 )); | |||
2969 | outrel.r_addend = 0; | |||
2970 | loc = htab->srelgot->contents; | |||
2971 | loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); | |||
2972 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |||
2973 | htab->tls_ld_got.offset |= 1; | |||
2974 | } | |||
2975 | relocation = htab->sgot->output_section->vma | |||
2976 | + htab->sgot->output_offset + off; | |||
2977 | unresolved_reloc = FALSE0; | |||
2978 | break; | |||
2979 | ||||
2980 | case R_X86_64_DTPOFF32: | |||
2981 | if ((info->shared && !info->executable) | |||
2982 | || (input_section->flags & SEC_CODE0x010) == 0) | |||
2983 | relocation -= dtpoff_base (info); | |||
2984 | else | |||
2985 | relocation = tpoff (info, relocation); | |||
2986 | break; | |||
2987 | ||||
2988 | case R_X86_64_TPOFF32: | |||
2989 | BFD_ASSERT (! info->shared || info->executable)do { if (!(! info->shared || info->executable)) bfd_assert ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c",2989 ); } while (0); | |||
2990 | relocation = tpoff (info, relocation); | |||
2991 | break; | |||
2992 | ||||
2993 | default: | |||
2994 | break; | |||
2995 | } | |||
2996 | ||||
2997 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |||
2998 | because such sections are not SEC_ALLOC and thus ld.so will | |||
2999 | not process them. */ | |||
3000 | if (unresolved_reloc | |||
3001 | && !((input_section->flags & SEC_DEBUGGING0x2000) != 0 | |||
3002 | && h->def_dynamic)) | |||
3003 | (*_bfd_error_handler) | |||
3004 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'")("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'" ), | |||
3005 | input_bfd, | |||
3006 | input_section, | |||
3007 | (long) rel->r_offset, | |||
3008 | howto->name, | |||
3009 | h->root.root.string); | |||
3010 | ||||
3011 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |||
3012 | contents, rel->r_offset, | |||
3013 | relocation, rel->r_addend); | |||
3014 | ||||
3015 | if (r != bfd_reloc_ok) | |||
3016 | { | |||
3017 | const char *name; | |||
3018 | ||||
3019 | if (h != NULL((void*)0)) | |||
3020 | name = h->root.root.string; | |||
3021 | else | |||
3022 | { | |||
3023 | name = bfd_elf_string_from_elf_section (input_bfd, | |||
3024 | symtab_hdr->sh_link, | |||
3025 | sym->st_name); | |||
3026 | if (name == NULL((void*)0)) | |||
3027 | return FALSE0; | |||
3028 | if (*name == '\0') | |||
3029 | name = bfd_section_name (input_bfd, sec)((sec)->name); | |||
3030 | } | |||
3031 | ||||
3032 | if (r == bfd_reloc_overflow) | |||
3033 | { | |||
3034 | if (h != NULL((void*)0) | |||
3035 | && h->root.type == bfd_link_hash_undefweak | |||
3036 | && howto->pc_relative) | |||
3037 | /* Ignore reloc overflow on branches to undefweak syms. */ | |||
3038 | continue; | |||
3039 | ||||
3040 | if (! ((*info->callbacks->reloc_overflow) | |||
3041 | (info, (h ? &h->root : NULL((void*)0)), name, howto->name, | |||
3042 | (bfd_vma) 0, input_bfd, input_section, | |||
3043 | rel->r_offset))) | |||
3044 | return FALSE0; | |||
3045 | } | |||
3046 | else | |||
3047 | { | |||
3048 | (*_bfd_error_handler) | |||
3049 | (_("%B(%A+0x%lx): reloc against `%s': error %d")("%B(%A+0x%lx): reloc against `%s': error %d"), | |||
3050 | input_bfd, input_section, | |||
3051 | (long) rel->r_offset, name, (int) r); | |||
3052 | return FALSE0; | |||
3053 | } | |||
3054 | } | |||
3055 | } | |||
3056 | ||||
3057 | return TRUE1; | |||
3058 | } | |||
3059 | ||||
3060 | /* Finish up dynamic symbol handling. We set the contents of various | |||
3061 | dynamic sections here. */ | |||
3062 | ||||
3063 | static bfd_boolean | |||
3064 | elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd, | |||
3065 | struct bfd_link_info *info, | |||
3066 | struct elf_link_hash_entry *h, | |||
3067 | Elf_Internal_Sym *sym) | |||
3068 | { | |||
3069 | struct elf64_x86_64_link_hash_table *htab; | |||
3070 | ||||
3071 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
3072 | ||||
3073 | if (h->plt.offset != (bfd_vma) -1) | |||
3074 | { | |||
3075 | bfd_vma plt_index; | |||
3076 | bfd_vma got_offset; | |||
3077 | Elf_Internal_Rela rela; | |||
3078 | bfd_byte *loc; | |||
3079 | ||||
3080 | /* This symbol has an entry in the procedure linkage table. Set | |||
3081 | it up. */ | |||
3082 | if (h->dynindx == -1 | |||
3083 | || htab->splt == NULL((void*)0) | |||
3084 | || htab->sgotplt == NULL((void*)0) | |||
3085 | || htab->srelplt == NULL((void*)0)) | |||
3086 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 3086, __PRETTY_FUNCTION__); | |||
3087 | ||||
3088 | /* Get the index in the procedure linkage table which | |||
3089 | corresponds to this symbol. This is the index of this symbol | |||
3090 | in all the symbols for which we are making plt entries. The | |||
3091 | first entry in the procedure linkage table is reserved. */ | |||
3092 | plt_index = h->plt.offset / PLT_ENTRY_SIZE16 - 1; | |||
3093 | ||||
3094 | /* Get the offset into the .got table of the entry that | |||
3095 | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE | |||
3096 | bytes. The first three are reserved for the dynamic linker. */ | |||
3097 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE8; | |||
3098 | ||||
3099 | /* Fill in the entry in the procedure linkage table. */ | |||
3100 | memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry, | |||
3101 | PLT_ENTRY_SIZE16); | |||
3102 | ||||
3103 | /* Insert the relocation positions of the plt section. The magic | |||
3104 | numbers at the end of the statements are the positions of the | |||
3105 | relocations in the plt section. */ | |||
3106 | /* Put offset for jmp *name@GOTPCREL(%rip), since the | |||
3107 | instruction uses 6 bytes, subtract this value. */ | |||
3108 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3109 | (htab->sgotplt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3110 | + htab->sgotplt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3111 | + got_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3112 | - htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3113 | - htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3114 | - h->plt.offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3115 | - 6),((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))) | |||
3116 | htab->splt->contents + h->plt.offset + 2)((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + got_offset - htab->splt->output_section->vma - htab ->splt->output_offset - h->plt.offset - 6)),(htab-> splt->contents + h->plt.offset + 2))); | |||
3117 | /* Put relocation index. */ | |||
3118 | bfd_put_32 (output_bfd, plt_index,((*((output_bfd)->xvec->bfd_putx32)) ((plt_index),(htab ->splt->contents + h->plt.offset + 7))) | |||
3119 | htab->splt->contents + h->plt.offset + 7)((*((output_bfd)->xvec->bfd_putx32)) ((plt_index),(htab ->splt->contents + h->plt.offset + 7))); | |||
3120 | /* Put offset for jmp .PLT0. */ | |||
3121 | bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE),((*((output_bfd)->xvec->bfd_putx32)) ((- (h->plt.offset + 16)),(htab->splt->contents + h->plt.offset + 12)) ) | |||
3122 | htab->splt->contents + h->plt.offset + 12)((*((output_bfd)->xvec->bfd_putx32)) ((- (h->plt.offset + 16)),(htab->splt->contents + h->plt.offset + 12)) ); | |||
3123 | ||||
3124 | /* Fill in the entry in the global offset table, initially this | |||
3125 | points to the pushq instruction in the PLT which is at offset 6. */ | |||
3126 | bfd_put_64 (output_bfd, (htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx64)) (((htab->splt-> output_section->vma + htab->splt->output_offset + h-> plt.offset + 6)), (htab->sgotplt->contents + got_offset ))) | |||
3127 | + htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx64)) (((htab->splt-> output_section->vma + htab->splt->output_offset + h-> plt.offset + 6)), (htab->sgotplt->contents + got_offset ))) | |||
3128 | + h->plt.offset + 6),((*((output_bfd)->xvec->bfd_putx64)) (((htab->splt-> output_section->vma + htab->splt->output_offset + h-> plt.offset + 6)), (htab->sgotplt->contents + got_offset ))) | |||
3129 | htab->sgotplt->contents + got_offset)((*((output_bfd)->xvec->bfd_putx64)) (((htab->splt-> output_section->vma + htab->splt->output_offset + h-> plt.offset + 6)), (htab->sgotplt->contents + got_offset ))); | |||
3130 | ||||
3131 | /* Fill in the entry in the .rela.plt section. */ | |||
3132 | rela.r_offset = (htab->sgotplt->output_section->vma | |||
3133 | + htab->sgotplt->output_offset | |||
3134 | + got_offset); | |||
3135 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT)(((bfd_vma) (h->dynindx) << 31 << 1) + (bfd_vma ) (R_X86_64_JUMP_SLOT)); | |||
3136 | rela.r_addend = 0; | |||
3137 | loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela); | |||
3138 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |||
3139 | ||||
3140 | if (!h->def_regular) | |||
3141 | { | |||
3142 | /* Mark the symbol as undefined, rather than as defined in | |||
3143 | the .plt section. Leave the value if there were any | |||
3144 | relocations where pointer equality matters (this is a clue | |||
3145 | for the dynamic linker, to make function pointer | |||
3146 | comparisons work between an application and shared | |||
3147 | library), otherwise set it to zero. If a function is only | |||
3148 | called from a binary, there is no need to slow down | |||
3149 | shared libraries because of that. */ | |||
3150 | sym->st_shndx = SHN_UNDEF0; | |||
3151 | if (!h->pointer_equality_needed) | |||
3152 | sym->st_value = 0; | |||
3153 | } | |||
3154 | } | |||
3155 | ||||
3156 | if (h->got.offset != (bfd_vma) -1 | |||
3157 | && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type)(((((struct elf64_x86_64_link_hash_entry *)(h))->tls_type) == 2 || ((((struct elf64_x86_64_link_hash_entry *)(h))->tls_type ) == (2 | 4))) || ((((struct elf64_x86_64_link_hash_entry *)( h))->tls_type) == 4 || ((((struct elf64_x86_64_link_hash_entry *)(h))->tls_type) == (2 | 4)))) | |||
3158 | && elf64_x86_64_hash_entry (h)((struct elf64_x86_64_link_hash_entry *)(h))->tls_type != GOT_TLS_IE3) | |||
3159 | { | |||
3160 | Elf_Internal_Rela rela; | |||
3161 | bfd_byte *loc; | |||
3162 | ||||
3163 | /* This symbol has an entry in the global offset table. Set it | |||
3164 | up. */ | |||
3165 | if (htab->sgot == NULL((void*)0) || htab->srelgot == NULL((void*)0)) | |||
3166 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 3166, __PRETTY_FUNCTION__); | |||
3167 | ||||
3168 | rela.r_offset = (htab->sgot->output_section->vma | |||
3169 | + htab->sgot->output_offset | |||
3170 | + (h->got.offset &~ (bfd_vma) 1)); | |||
3171 | ||||
3172 | /* If this is a static link, or it is a -Bsymbolic link and the | |||
3173 | symbol is defined locally or was forced to be local because | |||
3174 | of a version file, we just want to emit a RELATIVE reloc. | |||
3175 | The entry in the global offset table will already have been | |||
3176 | initialized in the relocate_section function. */ | |||
3177 | if (info->shared | |||
3178 | && SYMBOL_REFERENCES_LOCAL (info, h)_bfd_elf_symbol_refs_local_p (h, info, 0)) | |||
3179 | { | |||
3180 | BFD_ASSERT((h->got.offset & 1) != 0)do { if (!((h->got.offset & 1) != 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,3180); } while (0); | |||
3181 | rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE)(((bfd_vma) (0) << 31 << 1) + (bfd_vma) (R_X86_64_RELATIVE )); | |||
3182 | rela.r_addend = (h->root.u.def.value | |||
3183 | + h->root.u.def.section->output_section->vma | |||
3184 | + h->root.u.def.section->output_offset); | |||
3185 | } | |||
3186 | else | |||
3187 | { | |||
3188 | BFD_ASSERT((h->got.offset & 1) == 0)do { if (!((h->got.offset & 1) == 0)) bfd_assert("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" ,3188); } while (0); | |||
3189 | bfd_put_64 (output_bfd, (bfd_vma) 0,((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgot->contents + h->got.offset))) | |||
3190 | htab->sgot->contents + h->got.offset)((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgot->contents + h->got.offset))); | |||
3191 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT)(((bfd_vma) (h->dynindx) << 31 << 1) + (bfd_vma ) (R_X86_64_GLOB_DAT)); | |||
3192 | rela.r_addend = 0; | |||
3193 | } | |||
3194 | ||||
3195 | loc = htab->srelgot->contents; | |||
3196 | loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); | |||
3197 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |||
3198 | } | |||
3199 | ||||
3200 | if (h->needs_copy) | |||
3201 | { | |||
3202 | Elf_Internal_Rela rela; | |||
3203 | bfd_byte *loc; | |||
3204 | ||||
3205 | /* This symbol needs a copy reloc. Set it up. */ | |||
3206 | ||||
3207 | if (h->dynindx == -1 | |||
3208 | || (h->root.type != bfd_link_hash_defined | |||
3209 | && h->root.type != bfd_link_hash_defweak) | |||
3210 | || htab->srelbss == NULL((void*)0)) | |||
3211 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 3211, __PRETTY_FUNCTION__); | |||
3212 | ||||
3213 | rela.r_offset = (h->root.u.def.value | |||
3214 | + h->root.u.def.section->output_section->vma | |||
3215 | + h->root.u.def.section->output_offset); | |||
3216 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY)(((bfd_vma) (h->dynindx) << 31 << 1) + (bfd_vma ) (R_X86_64_COPY)); | |||
3217 | rela.r_addend = 0; | |||
3218 | loc = htab->srelbss->contents; | |||
3219 | loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela); | |||
3220 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |||
3221 | } | |||
3222 | ||||
3223 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |||
3224 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |||
3225 | || h == htab->elf.hgot) | |||
3226 | sym->st_shndx = SHN_ABS0xFFF1; | |||
3227 | ||||
3228 | return TRUE1; | |||
3229 | } | |||
3230 | ||||
3231 | /* Used to decide how to sort relocs in an optimal manner for the | |||
3232 | dynamic linker, before writing them out. */ | |||
3233 | ||||
3234 | static enum elf_reloc_type_class | |||
3235 | elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela) | |||
3236 | { | |||
3237 | switch ((int) ELF64_R_TYPE (rela->r_info)((rela->r_info) & 0xffffffff)) | |||
3238 | { | |||
3239 | case R_X86_64_RELATIVE: | |||
3240 | return reloc_class_relative; | |||
3241 | case R_X86_64_JUMP_SLOT: | |||
3242 | return reloc_class_plt; | |||
3243 | case R_X86_64_COPY: | |||
3244 | return reloc_class_copy; | |||
3245 | default: | |||
3246 | return reloc_class_normal; | |||
3247 | } | |||
3248 | } | |||
3249 | ||||
3250 | /* Finish up the dynamic sections. */ | |||
3251 | ||||
3252 | static bfd_boolean | |||
3253 | elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) | |||
3254 | { | |||
3255 | struct elf64_x86_64_link_hash_table *htab; | |||
3256 | bfd *dynobj; | |||
3257 | asection *sdyn; | |||
3258 | ||||
3259 | htab = elf64_x86_64_hash_table (info)((struct elf64_x86_64_link_hash_table *) ((info)->hash)); | |||
3260 | dynobj = htab->elf.dynobj; | |||
3261 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |||
3262 | ||||
3263 | if (htab->elf.dynamic_sections_created) | |||
3264 | { | |||
3265 | Elf64_External_Dyn *dyncon, *dynconend; | |||
3266 | ||||
3267 | if (sdyn == NULL((void*)0) || htab->sgot == NULL((void*)0)) | |||
3268 | abort ()_bfd_abort ("/usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-x86-64.c" , 3268, __PRETTY_FUNCTION__); | |||
3269 | ||||
3270 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |||
3271 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); | |||
3272 | for (; dyncon < dynconend; dyncon++) | |||
3273 | { | |||
3274 | Elf_Internal_Dyn dyn; | |||
3275 | asection *s; | |||
3276 | ||||
3277 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |||
3278 | ||||
3279 | switch (dyn.d_tag) | |||
3280 | { | |||
3281 | default: | |||
3282 | continue; | |||
3283 | ||||
3284 | case DT_PLTGOT3: | |||
3285 | s = htab->sgotplt; | |||
3286 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |||
3287 | break; | |||
3288 | ||||
3289 | case DT_JMPREL23: | |||
3290 | dyn.d_un.d_ptr = htab->srelplt->output_section->vma; | |||
3291 | break; | |||
3292 | ||||
3293 | case DT_PLTRELSZ2: | |||
3294 | s = htab->srelplt->output_section; | |||
3295 | dyn.d_un.d_val = s->size; | |||
3296 | break; | |||
3297 | ||||
3298 | case DT_RELASZ8: | |||
3299 | /* The procedure linkage table relocs (DT_JMPREL) should | |||
3300 | not be included in the overall relocs (DT_RELA). | |||
3301 | Therefore, we override the DT_RELASZ entry here to | |||
3302 | make it not include the JMPREL relocs. Since the | |||
3303 | linker script arranges for .rela.plt to follow all | |||
3304 | other relocation sections, we don't have to worry | |||
3305 | about changing the DT_RELA entry. */ | |||
3306 | if (htab->srelplt != NULL((void*)0)) | |||
3307 | { | |||
3308 | s = htab->srelplt->output_section; | |||
3309 | dyn.d_un.d_val -= s->size; | |||
3310 | } | |||
3311 | break; | |||
3312 | ||||
3313 | case DT_TLSDESC_PLT0x6ffffef6: | |||
3314 | s = htab->splt; | |||
3315 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset | |||
3316 | + htab->tlsdesc_plt; | |||
3317 | break; | |||
3318 | ||||
3319 | case DT_TLSDESC_GOT0x6ffffef7: | |||
3320 | s = htab->sgot; | |||
3321 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset | |||
3322 | + htab->tlsdesc_got; | |||
3323 | break; | |||
3324 | } | |||
3325 | ||||
3326 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | |||
3327 | } | |||
3328 | ||||
3329 | /* Fill in the special first entry in the procedure linkage table. */ | |||
3330 | if (htab->splt && htab->splt->size > 0) | |||
3331 | { | |||
3332 | /* Fill in the first entry in the procedure linkage table. */ | |||
3333 | memcpy (htab->splt->contents, elf64_x86_64_plt0_entry, | |||
3334 | PLT_ENTRY_SIZE16); | |||
3335 | /* Add offset for pushq GOT+8(%rip), since the instruction | |||
3336 | uses 6 bytes subtract this value. */ | |||
3337 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3338 | (htab->sgotplt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3339 | + htab->sgotplt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3340 | + 8((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3341 | - htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3342 | - htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3343 | - 6),((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))) | |||
3344 | htab->splt->contents + 2)((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - 6)),(htab->splt->contents + 2))); | |||
3345 | /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to | |||
3346 | the end of the instruction. */ | |||
3347 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3348 | (htab->sgotplt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3349 | + htab->sgotplt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3350 | + 16((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3351 | - htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3352 | - htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3353 | - 12),((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))) | |||
3354 | htab->splt->contents + 8)((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 16 - htab->splt->output_section->vma - htab->splt ->output_offset - 12)),(htab->splt->contents + 8))); | |||
3355 | ||||
3356 | elf_section_data (htab->splt->output_section)((struct bfd_elf_section_data*)(htab->splt->output_section )->used_by_bfd)->this_hdr.sh_entsize = | |||
3357 | PLT_ENTRY_SIZE16; | |||
3358 | ||||
3359 | if (htab->tlsdesc_plt) | |||
3360 | { | |||
3361 | bfd_put_64 (output_bfd, (bfd_vma) 0,((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgot->contents + htab->tlsdesc_got))) | |||
3362 | htab->sgot->contents + htab->tlsdesc_got)((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgot->contents + htab->tlsdesc_got))); | |||
3363 | ||||
3364 | memcpy (htab->splt->contents + htab->tlsdesc_plt, | |||
3365 | elf64_x86_64_plt0_entry, | |||
3366 | PLT_ENTRY_SIZE16); | |||
3367 | ||||
3368 | /* Add offset for pushq GOT+8(%rip), since the | |||
3369 | instruction uses 6 bytes subtract this value. */ | |||
3370 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3371 | (htab->sgotplt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3372 | + htab->sgotplt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3373 | + 8((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3374 | - htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3375 | - htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3376 | - htab->tlsdesc_plt((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3377 | - 6),((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))) | |||
3378 | htab->splt->contents + htab->tlsdesc_plt + 2)((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgotplt ->output_section->vma + htab->sgotplt->output_offset + 8 - htab->splt->output_section->vma - htab->splt ->output_offset - htab->tlsdesc_plt - 6)),(htab->splt ->contents + htab->tlsdesc_plt + 2))); | |||
3379 | /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for | |||
3380 | htab->tlsdesc_got. The 12 is the offset to the end of | |||
3381 | the instruction. */ | |||
3382 | bfd_put_32 (output_bfd,((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3383 | (htab->sgot->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3384 | + htab->sgot->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3385 | + htab->tlsdesc_got((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3386 | - htab->splt->output_section->vma((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3387 | - htab->splt->output_offset((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3388 | - htab->tlsdesc_plt((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3389 | - 12),((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))) | |||
3390 | htab->splt->contents + htab->tlsdesc_plt + 8)((*((output_bfd)->xvec->bfd_putx32)) (((htab->sgot-> output_section->vma + htab->sgot->output_offset + htab ->tlsdesc_got - htab->splt->output_section->vma - htab->splt->output_offset - htab->tlsdesc_plt - 12) ),(htab->splt->contents + htab->tlsdesc_plt + 8))); | |||
3391 | } | |||
3392 | } | |||
3393 | } | |||
3394 | ||||
3395 | if (htab->sgotplt) | |||
3396 | { | |||
3397 | /* Fill in the first three entries in the global offset table. */ | |||
3398 | if (htab->sgotplt->size > 0) | |||
3399 | { | |||
3400 | /* Set the first entry in the global offset table to the address of | |||
3401 | the dynamic section. */ | |||
3402 | if (sdyn == NULL((void*)0)) | |||
3403 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents)((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgotplt->contents))); | |||
3404 | else | |||
3405 | bfd_put_64 (output_bfd,((*((output_bfd)->xvec->bfd_putx64)) ((sdyn->output_section ->vma + sdyn->output_offset), (htab->sgotplt->contents ))) | |||
3406 | sdyn->output_section->vma + sdyn->output_offset,((*((output_bfd)->xvec->bfd_putx64)) ((sdyn->output_section ->vma + sdyn->output_offset), (htab->sgotplt->contents ))) | |||
3407 | htab->sgotplt->contents)((*((output_bfd)->xvec->bfd_putx64)) ((sdyn->output_section ->vma + sdyn->output_offset), (htab->sgotplt->contents ))); | |||
3408 | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ | |||
3409 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE)((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgotplt->contents + 8))); | |||
3410 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2)((*((output_bfd)->xvec->bfd_putx64)) (((bfd_vma) 0), (htab ->sgotplt->contents + 8*2))); | |||
3411 | } | |||
3412 | ||||
3413 | elf_section_data (htab->sgotplt->output_section)((struct bfd_elf_section_data*)(htab->sgotplt->output_section )->used_by_bfd)->this_hdr.sh_entsize = | |||
3414 | GOT_ENTRY_SIZE8; | |||
3415 | } | |||
3416 | ||||
3417 | if (htab->sgot && htab->sgot->size > 0) | |||
3418 | elf_section_data (htab->sgot->output_section)((struct bfd_elf_section_data*)(htab->sgot->output_section )->used_by_bfd)->this_hdr.sh_entsize | |||
3419 | = GOT_ENTRY_SIZE8; | |||
3420 | ||||
3421 | return TRUE1; | |||
3422 | } | |||
3423 | ||||
3424 | /* Return address for Ith PLT stub in section PLT, for relocation REL | |||
3425 | or (bfd_vma) -1 if it should not be included. */ | |||
3426 | ||||
3427 | static bfd_vma | |||
3428 | elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt, | |||
3429 | const arelent *rel ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | |||
3430 | { | |||
3431 | return plt->vma + (i + 1) * PLT_ENTRY_SIZE16; | |||
3432 | } | |||
3433 | ||||
3434 | /* Handle an x86-64 specific section when reading an object file. This | |||
3435 | is called when elfcode.h finds a section with an unknown type. */ | |||
3436 | ||||
3437 | static bfd_boolean | |||
3438 | elf64_x86_64_section_from_shdr (bfd *abfd, | |||
3439 | Elf_Internal_Shdr *hdr, | |||
3440 | const char *name, | |||
3441 | int shindex) | |||
3442 | { | |||
3443 | if (hdr->sh_type != SHT_X86_64_UNWIND0x70000001) | |||
3444 | return FALSE0; | |||
3445 | ||||
3446 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |||
3447 | return FALSE0; | |||
3448 | ||||
3449 | return TRUE1; | |||
3450 | } | |||
3451 | ||||
3452 | /* Hook called by the linker routine which adds symbols from an object | |||
3453 | file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead | |||
3454 | of .bss. */ | |||
3455 | ||||
3456 | static bfd_boolean | |||
3457 | elf64_x86_64_add_symbol_hook (bfd *abfd, | |||
3458 | struct bfd_link_info *info ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3459 | Elf_Internal_Sym *sym, | |||
3460 | const char **namep ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3461 | flagword *flagsp ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3462 | asection **secp, bfd_vma *valp) | |||
3463 | { | |||
3464 | asection *lcomm; | |||
3465 | ||||
3466 | switch (sym->st_shndx) | |||
3467 | { | |||
3468 | case SHN_X86_64_LCOMMON0xff02: | |||
3469 | lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON"); | |||
3470 | if (lcomm == NULL((void*)0)) | |||
3471 | { | |||
3472 | lcomm = bfd_make_section_with_flags (abfd, | |||
3473 | "LARGE_COMMON", | |||
3474 | (SEC_ALLOC0x001 | |||
3475 | | SEC_IS_COMMON0x1000 | |||
3476 | | SEC_LINKER_CREATED0x200000)); | |||
3477 | if (lcomm == NULL((void*)0)) | |||
3478 | return FALSE0; | |||
3479 | elf_section_flags (lcomm)(((struct bfd_elf_section_data*)(lcomm)->used_by_bfd)-> this_hdr.sh_flags) |= SHF_X86_64_LARGE0x10000000; | |||
3480 | } | |||
3481 | *secp = lcomm; | |||
3482 | *valp = sym->st_size; | |||
3483 | break; | |||
3484 | } | |||
3485 | return TRUE1; | |||
3486 | } | |||
3487 | ||||
3488 | ||||
3489 | /* Given a BFD section, try to locate the corresponding ELF section | |||
3490 | index. */ | |||
3491 | ||||
3492 | static bfd_boolean | |||
3493 | elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3494 | asection *sec, int *index) | |||
3495 | { | |||
3496 | if (sec == &_bfd_elf_large_com_section) | |||
3497 | { | |||
3498 | *index = SHN_X86_64_LCOMMON0xff02; | |||
3499 | return TRUE1; | |||
3500 | } | |||
3501 | return FALSE0; | |||
3502 | } | |||
3503 | ||||
3504 | /* Process a symbol. */ | |||
3505 | ||||
3506 | static void | |||
3507 | elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3508 | asymbol *asym) | |||
3509 | { | |||
3510 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |||
3511 | ||||
3512 | switch (elfsym->internal_elf_sym.st_shndx) | |||
3513 | { | |||
3514 | case SHN_X86_64_LCOMMON0xff02: | |||
3515 | asym->section = &_bfd_elf_large_com_section; | |||
3516 | asym->value = elfsym->internal_elf_sym.st_size; | |||
3517 | /* Common symbol doesn't set BSF_GLOBAL. */ | |||
3518 | asym->flags &= ~BSF_GLOBAL0x02; | |||
3519 | break; | |||
3520 | } | |||
3521 | } | |||
3522 | ||||
3523 | static bfd_boolean | |||
3524 | elf64_x86_64_common_definition (Elf_Internal_Sym *sym) | |||
3525 | { | |||
3526 | return (sym->st_shndx == SHN_COMMON0xFFF2 | |||
3527 | || sym->st_shndx == SHN_X86_64_LCOMMON0xff02); | |||
3528 | } | |||
3529 | ||||
3530 | static unsigned int | |||
3531 | elf64_x86_64_common_section_index (asection *sec) | |||
3532 | { | |||
3533 | if ((elf_section_flags (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr .sh_flags) & SHF_X86_64_LARGE0x10000000) == 0) | |||
3534 | return SHN_COMMON0xFFF2; | |||
3535 | else | |||
3536 | return SHN_X86_64_LCOMMON0xff02; | |||
3537 | } | |||
3538 | ||||
3539 | static asection * | |||
3540 | elf64_x86_64_common_section (asection *sec) | |||
3541 | { | |||
3542 | if ((elf_section_flags (sec)(((struct bfd_elf_section_data*)(sec)->used_by_bfd)->this_hdr .sh_flags) & SHF_X86_64_LARGE0x10000000) == 0) | |||
3543 | return bfd_com_section_ptr((asection *) &bfd_com_section); | |||
3544 | else | |||
3545 | return &_bfd_elf_large_com_section; | |||
3546 | } | |||
3547 | ||||
3548 | static bfd_boolean | |||
3549 | elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3550 | struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3551 | struct elf_link_hash_entry *h, | |||
3552 | Elf_Internal_Sym *sym, | |||
3553 | asection **psec, | |||
3554 | bfd_vma *pvalue ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3555 | unsigned int *pold_alignment ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3556 | bfd_boolean *skip ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3557 | bfd_boolean *override ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3558 | bfd_boolean *type_change_ok ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3559 | bfd_boolean *size_change_ok ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3560 | bfd_boolean *newdef ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3561 | bfd_boolean *newdyn, | |||
3562 | bfd_boolean *newdyncommon ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3563 | bfd_boolean *newweak ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3564 | bfd *abfd ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3565 | asection **sec, | |||
3566 | bfd_boolean *olddef ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3567 | bfd_boolean *olddyn, | |||
3568 | bfd_boolean *olddyncommon ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3569 | bfd_boolean *oldweak ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | |||
3570 | bfd *oldbfd, | |||
3571 | asection **oldsec) | |||
3572 | { | |||
3573 | /* A normal common symbol and a large common symbol result in a | |||
3574 | normal common symbol. We turn the large common symbol into a | |||
3575 | normal one. */ | |||
3576 | if (!*olddyn | |||
3577 | && h->root.type == bfd_link_hash_common | |||
3578 | && !*newdyn | |||
3579 | && bfd_is_com_section (*sec)(((*sec)->flags & 0x1000) != 0) | |||
3580 | && *oldsec != *sec) | |||
3581 | { | |||
3582 | if (sym->st_shndx == SHN_COMMON0xFFF2 | |||
3583 | && (elf_section_flags (*oldsec)(((struct bfd_elf_section_data*)(*oldsec)->used_by_bfd)-> this_hdr.sh_flags) & SHF_X86_64_LARGE0x10000000) != 0) | |||
3584 | { | |||
3585 | h->root.u.c.p->section | |||
3586 | = bfd_make_section_old_way (oldbfd, "COMMON"); | |||
3587 | h->root.u.c.p->section->flags = SEC_ALLOC0x001; | |||
3588 | } | |||
3589 | else if (sym->st_shndx == SHN_X86_64_LCOMMON0xff02 | |||
3590 | && (elf_section_flags (*oldsec)(((struct bfd_elf_section_data*)(*oldsec)->used_by_bfd)-> this_hdr.sh_flags) & SHF_X86_64_LARGE0x10000000) == 0) | |||
3591 | *psec = *sec = bfd_com_section_ptr((asection *) &bfd_com_section); | |||
3592 | } | |||
3593 | ||||
3594 | return TRUE1; | |||
3595 | } | |||
3596 | ||||
3597 | static int | |||
3598 | elf64_x86_64_additional_program_headers (bfd *abfd) | |||
3599 | { | |||
3600 | asection *s; | |||
3601 | int count = 0; | |||
3602 | ||||
3603 | /* Check to see if we need a large readonly segment. */ | |||
3604 | s = bfd_get_section_by_name (abfd, ".lrodata"); | |||
3605 | if (s && (s->flags & SEC_LOAD0x002)) | |||
3606 | count++; | |||
3607 | ||||
3608 | /* Check to see if we need a large data segment. Since .lbss sections | |||
3609 | is placed right after the .bss section, there should be no need for | |||
3610 | a large data segment just because of .lbss. */ | |||
3611 | s = bfd_get_section_by_name (abfd, ".ldata"); | |||
3612 | if (s && (s->flags & SEC_LOAD0x002)) | |||
3613 | count++; | |||
3614 | ||||
3615 | return count; | |||
3616 | } | |||
3617 | ||||
3618 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ | |||
3619 | ||||
3620 | static bfd_boolean | |||
3621 | elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h) | |||
3622 | { | |||
3623 | if (h->plt.offset != (bfd_vma) -1 | |||
3624 | && !h->def_regular | |||
3625 | && !h->pointer_equality_needed) | |||
3626 | return FALSE0; | |||
3627 | ||||
3628 | return _bfd_elf_hash_symbol (h); | |||
3629 | } | |||
3630 | ||||
3631 | static const struct bfd_elf_special_section | |||
3632 | elf64_x86_64_special_sections[]= | |||
3633 | { | |||
3634 | { ".gnu.linkonce.lb", 16, -2, SHT_NOBITS8, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) + SHF_X86_64_LARGE0x10000000}, | |||
3635 | { ".gnu.linkonce.lr", 16, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_X86_64_LARGE0x10000000}, | |||
3636 | { ".gnu.linkonce.lt", 16, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_EXECINSTR(1 << 2) + SHF_X86_64_LARGE0x10000000}, | |||
3637 | { ".lbss", 5, -2, SHT_NOBITS8, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) + SHF_X86_64_LARGE0x10000000}, | |||
3638 | { ".ldata", 6, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_WRITE(1 << 0) + SHF_X86_64_LARGE0x10000000}, | |||
3639 | { ".lrodata", 8, -2, SHT_PROGBITS1, SHF_ALLOC(1 << 1) + SHF_X86_64_LARGE0x10000000}, | |||
3640 | { NULL((void*)0), 0, 0, 0, 0 } | |||
3641 | }; | |||
3642 | ||||
3643 | #define TARGET_LITTLE_SYMbfd_elf64_x86_64_vec bfd_elf64_x86_64_vec | |||
3644 | #define TARGET_LITTLE_NAME"elf64-x86-64" "elf64-x86-64" | |||
3645 | #define ELF_ARCHbfd_arch_i386 bfd_arch_i386 | |||
3646 | #define ELF_MACHINE_CODE62 EM_X86_6462 | |||
3647 | #define ELF_MAXPAGESIZE0x1000 0x1000 | |||
3648 | ||||
3649 | #define elf_backend_can_gc_sections1 1 | |||
3650 | #define elf_backend_can_refcount1 1 | |||
3651 | #define elf_backend_want_got_plt1 1 | |||
3652 | #define elf_backend_plt_readonly1 1 | |||
3653 | #define elf_backend_want_plt_sym0 0 | |||
3654 | #define elf_backend_got_header_size(8*3) (GOT_ENTRY_SIZE8*3) | |||
3655 | #define elf_backend_rela_normal1 1 | |||
3656 | ||||
3657 | #define elf_info_to_howtoelf64_x86_64_info_to_howto elf64_x86_64_info_to_howto | |||
3658 | ||||
3659 | #define bfd_elf64_bfd_link_hash_table_createelf64_x86_64_link_hash_table_create \ | |||
3660 | elf64_x86_64_link_hash_table_create | |||
3661 | #define bfd_elf64_bfd_reloc_type_lookupelf64_x86_64_reloc_type_lookup elf64_x86_64_reloc_type_lookup | |||
3662 | ||||
3663 | #define elf_backend_adjust_dynamic_symbolelf64_x86_64_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol | |||
3664 | #define elf_backend_check_relocself64_x86_64_check_relocs elf64_x86_64_check_relocs | |||
3665 | #define elf_backend_copy_indirect_symbolelf64_x86_64_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol | |||
3666 | #define elf_backend_create_dynamic_sectionself64_x86_64_create_dynamic_sections elf64_x86_64_create_dynamic_sections | |||
3667 | #define elf_backend_finish_dynamic_sectionself64_x86_64_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections | |||
3668 | #define elf_backend_finish_dynamic_symbolelf64_x86_64_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol | |||
3669 | #define elf_backend_gc_mark_hookelf64_x86_64_gc_mark_hook elf64_x86_64_gc_mark_hook | |||
3670 | #define elf_backend_gc_sweep_hookelf64_x86_64_gc_sweep_hook elf64_x86_64_gc_sweep_hook | |||
3671 | #define elf_backend_grok_prstatuself64_x86_64_grok_prstatus elf64_x86_64_grok_prstatus | |||
3672 | #define elf_backend_grok_psinfoelf64_x86_64_grok_psinfo elf64_x86_64_grok_psinfo | |||
3673 | #define elf_backend_reloc_type_clasself64_x86_64_reloc_type_class elf64_x86_64_reloc_type_class | |||
3674 | #define elf_backend_relocate_sectionelf64_x86_64_relocate_section elf64_x86_64_relocate_section | |||
3675 | #define elf_backend_size_dynamic_sectionself64_x86_64_size_dynamic_sections elf64_x86_64_size_dynamic_sections | |||
3676 | #define elf_backend_always_size_sectionself64_x86_64_always_size_sections elf64_x86_64_always_size_sections | |||
3677 | #define elf_backend_plt_sym_valelf64_x86_64_plt_sym_val elf64_x86_64_plt_sym_val | |||
3678 | #define elf_backend_object_pelf64_x86_64_elf_object_p elf64_x86_64_elf_object_p | |||
3679 | #define bfd_elf64_mkobjectelf64_x86_64_mkobject elf64_x86_64_mkobject | |||
3680 | ||||
3681 | #define elf_backend_section_from_shdrelf64_x86_64_section_from_shdr \ | |||
3682 | elf64_x86_64_section_from_shdr | |||
3683 | ||||
3684 | #define elf_backend_section_from_bfd_sectionelf64_x86_64_elf_section_from_bfd_section \ | |||
3685 | elf64_x86_64_elf_section_from_bfd_section | |||
3686 | #define elf_backend_add_symbol_hookelf64_x86_64_add_symbol_hook \ | |||
3687 | elf64_x86_64_add_symbol_hook | |||
3688 | #define elf_backend_symbol_processingelf64_x86_64_symbol_processing \ | |||
3689 | elf64_x86_64_symbol_processing | |||
3690 | #define elf_backend_common_section_indexelf64_x86_64_common_section_index \ | |||
3691 | elf64_x86_64_common_section_index | |||
3692 | #define elf_backend_common_sectionelf64_x86_64_common_section \ | |||
3693 | elf64_x86_64_common_section | |||
3694 | #define elf_backend_common_definitionelf64_x86_64_common_definition \ | |||
3695 | elf64_x86_64_common_definition | |||
3696 | #define elf_backend_merge_symbolelf64_x86_64_merge_symbol \ | |||
3697 | elf64_x86_64_merge_symbol | |||
3698 | #define elf_backend_special_sectionself64_x86_64_special_sections \ | |||
3699 | elf64_x86_64_special_sections | |||
3700 | #define elf_backend_additional_program_headerself64_x86_64_additional_program_headers \ | |||
3701 | elf64_x86_64_additional_program_headers | |||
3702 | #define elf_backend_hash_symbolelf64_x86_64_hash_symbol \ | |||
3703 | elf64_x86_64_hash_symbol | |||
3704 | ||||
3705 | #include "elf64-target.h" |