Commit | Line | Data |
---|---|---|
8d88c4ca | 1 | /* X86-64 specific support for 64-bit ELF |
0ffa91dd | 2 | Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
3eb128b2 | 3 | Free Software Foundation, Inc. |
8d88c4ca NC |
4 | Contributed by Jan Hubicka <jh@suse.cz>. |
5 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
8d88c4ca | 7 | |
ae9a127f NC |
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 | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 11 | (at your option) any later version. |
8d88c4ca | 12 | |
ae9a127f NC |
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. | |
8d88c4ca | 17 | |
ae9a127f NC |
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 | |
cd123cb7 NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
8d88c4ca | 22 | |
8d88c4ca | 23 | #include "sysdep.h" |
3db64b00 | 24 | #include "bfd.h" |
c434dee6 | 25 | #include "bfdlink.h" |
8d88c4ca NC |
26 | #include "libbfd.h" |
27 | #include "elf-bfd.h" | |
142411ca | 28 | #include "bfd_stdint.h" |
c25bc9fc L |
29 | #include "objalloc.h" |
30 | #include "hashtab.h" | |
8d88c4ca NC |
31 | |
32 | #include "elf/x86-64.h" | |
33 | ||
8d88c4ca NC |
34 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ |
35 | #define MINUS_ONE (~ (bfd_vma) 0) | |
36 | ||
37 | /* The relocation "howto" table. Order of fields: | |
7b81dfbb AJ |
38 | type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow, |
39 | special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */ | |
70256ad8 AJ |
40 | static reloc_howto_type x86_64_elf_howto_table[] = |
41 | { | |
b34976b6 AM |
42 | HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont, |
43 | bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000, | |
44 | FALSE), | |
45 | HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
46 | bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE, | |
47 | FALSE), | |
48 | HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
49 | bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff, | |
50 | TRUE), | |
51 | HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed, | |
52 | bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff, | |
53 | FALSE), | |
54 | HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
55 | bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff, | |
56 | TRUE), | |
57 | HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | |
58 | bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff, | |
59 | FALSE), | |
60 | HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
61 | bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE, | |
62 | MINUS_ONE, FALSE), | |
63 | HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
64 | bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE, | |
65 | MINUS_ONE, FALSE), | |
66 | HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
67 | bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE, | |
68 | MINUS_ONE, FALSE), | |
69 | HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
70 | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff, | |
71 | 0xffffffff, TRUE), | |
72 | HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned, | |
73 | bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff, | |
74 | FALSE), | |
75 | HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed, | |
76 | bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff, | |
77 | FALSE), | |
78 | HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, | |
79 | bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE), | |
b0360d8c | 80 | HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield, |
b34976b6 | 81 | bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE), |
ac2aa337 | 82 | HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, |
b34976b6 AM |
83 | bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE), |
84 | HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, | |
85 | bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE), | |
86 | HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
87 | bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE, | |
88 | MINUS_ONE, FALSE), | |
89 | HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
90 | bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE, | |
91 | MINUS_ONE, FALSE), | |
92 | HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
93 | bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE, | |
94 | MINUS_ONE, FALSE), | |
95 | HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
96 | bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff, | |
97 | 0xffffffff, TRUE), | |
98 | HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
99 | bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff, | |
100 | 0xffffffff, TRUE), | |
ac2aa337 | 101 | HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, |
b34976b6 AM |
102 | bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff, |
103 | 0xffffffff, FALSE), | |
104 | HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
105 | bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff, | |
106 | 0xffffffff, TRUE), | |
107 | HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, | |
108 | bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff, | |
109 | 0xffffffff, FALSE), | |
d6ab8113 JB |
110 | HOWTO(R_X86_64_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield, |
111 | bfd_elf_generic_reloc, "R_X86_64_PC64", FALSE, MINUS_ONE, MINUS_ONE, | |
112 | TRUE), | |
113 | HOWTO(R_X86_64_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, | |
114 | bfd_elf_generic_reloc, "R_X86_64_GOTOFF64", | |
115 | FALSE, MINUS_ONE, MINUS_ONE, FALSE), | |
116 | HOWTO(R_X86_64_GOTPC32, 0, 2, 32, TRUE, 0, complain_overflow_signed, | |
117 | bfd_elf_generic_reloc, "R_X86_64_GOTPC32", | |
118 | FALSE, 0xffffffff, 0xffffffff, TRUE), | |
7b81dfbb AJ |
119 | HOWTO(R_X86_64_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_signed, |
120 | bfd_elf_generic_reloc, "R_X86_64_GOT64", FALSE, MINUS_ONE, MINUS_ONE, | |
121 | FALSE), | |
122 | HOWTO(R_X86_64_GOTPCREL64, 0, 4, 64, TRUE, 0, complain_overflow_signed, | |
123 | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", FALSE, MINUS_ONE, | |
124 | MINUS_ONE, TRUE), | |
125 | HOWTO(R_X86_64_GOTPC64, 0, 4, 64, TRUE, 0, complain_overflow_signed, | |
126 | bfd_elf_generic_reloc, "R_X86_64_GOTPC64", | |
127 | FALSE, MINUS_ONE, MINUS_ONE, TRUE), | |
128 | HOWTO(R_X86_64_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_signed, | |
129 | bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", FALSE, MINUS_ONE, | |
130 | MINUS_ONE, FALSE), | |
131 | HOWTO(R_X86_64_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_signed, | |
132 | bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", FALSE, MINUS_ONE, | |
133 | MINUS_ONE, FALSE), | |
67a4f2b7 AO |
134 | EMPTY_HOWTO (32), |
135 | EMPTY_HOWTO (33), | |
136 | HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 2, 32, TRUE, 0, | |
137 | complain_overflow_bitfield, bfd_elf_generic_reloc, | |
138 | "R_X86_64_GOTPC32_TLSDESC", | |
139 | FALSE, 0xffffffff, 0xffffffff, TRUE), | |
140 | HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, FALSE, 0, | |
141 | complain_overflow_dont, bfd_elf_generic_reloc, | |
142 | "R_X86_64_TLSDESC_CALL", | |
143 | FALSE, 0, 0, FALSE), | |
144 | HOWTO(R_X86_64_TLSDESC, 0, 4, 64, FALSE, 0, | |
145 | complain_overflow_bitfield, bfd_elf_generic_reloc, | |
146 | "R_X86_64_TLSDESC", | |
147 | FALSE, MINUS_ONE, MINUS_ONE, FALSE), | |
cbe950e9 L |
148 | HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, |
149 | bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE, | |
150 | MINUS_ONE, FALSE), | |
fe4770f4 | 151 | |
a33d77bc JB |
152 | /* We have a gap in the reloc numbers here. |
153 | R_X86_64_standard counts the number up to this point, and | |
154 | R_X86_64_vt_offset is the value to subtract from a reloc type of | |
155 | R_X86_64_GNU_VT* to form an index into this table. */ | |
cbe950e9 | 156 | #define R_X86_64_standard (R_X86_64_IRELATIVE + 1) |
a33d77bc JB |
157 | #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard) |
158 | ||
fe4770f4 | 159 | /* GNU extension to record C++ vtable hierarchy. */ |
b34976b6 AM |
160 | HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont, |
161 | NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE), | |
fe4770f4 AJ |
162 | |
163 | /* GNU extension to record C++ vtable member usage. */ | |
b34976b6 AM |
164 | HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont, |
165 | _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0, | |
166 | FALSE) | |
8d88c4ca NC |
167 | }; |
168 | ||
d8045f23 NC |
169 | #define IS_X86_64_PCREL_TYPE(TYPE) \ |
170 | ( ((TYPE) == R_X86_64_PC8) \ | |
171 | || ((TYPE) == R_X86_64_PC16) \ | |
172 | || ((TYPE) == R_X86_64_PC32) \ | |
173 | || ((TYPE) == R_X86_64_PC64)) | |
174 | ||
8d88c4ca | 175 | /* Map BFD relocs to the x86_64 elf relocs. */ |
70256ad8 AJ |
176 | struct elf_reloc_map |
177 | { | |
8d88c4ca NC |
178 | bfd_reloc_code_real_type bfd_reloc_val; |
179 | unsigned char elf_reloc_val; | |
180 | }; | |
181 | ||
dc810e39 | 182 | static const struct elf_reloc_map x86_64_reloc_map[] = |
8d88c4ca | 183 | { |
70256ad8 AJ |
184 | { BFD_RELOC_NONE, R_X86_64_NONE, }, |
185 | { BFD_RELOC_64, R_X86_64_64, }, | |
186 | { BFD_RELOC_32_PCREL, R_X86_64_PC32, }, | |
187 | { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,}, | |
188 | { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,}, | |
189 | { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, }, | |
190 | { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, }, | |
191 | { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, }, | |
192 | { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, }, | |
193 | { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, }, | |
194 | { BFD_RELOC_32, R_X86_64_32, }, | |
195 | { BFD_RELOC_X86_64_32S, R_X86_64_32S, }, | |
196 | { BFD_RELOC_16, R_X86_64_16, }, | |
197 | { BFD_RELOC_16_PCREL, R_X86_64_PC16, }, | |
198 | { BFD_RELOC_8, R_X86_64_8, }, | |
199 | { BFD_RELOC_8_PCREL, R_X86_64_PC8, }, | |
bffbf940 JJ |
200 | { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, }, |
201 | { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, }, | |
202 | { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, }, | |
203 | { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, }, | |
204 | { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, }, | |
205 | { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, }, | |
206 | { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, }, | |
207 | { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, }, | |
d6ab8113 JB |
208 | { BFD_RELOC_64_PCREL, R_X86_64_PC64, }, |
209 | { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, }, | |
210 | { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, }, | |
7b81dfbb AJ |
211 | { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, }, |
212 | { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, }, | |
213 | { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, }, | |
214 | { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, }, | |
215 | { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, }, | |
67a4f2b7 AO |
216 | { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, }, |
217 | { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, }, | |
218 | { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, }, | |
cbe950e9 | 219 | { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, }, |
fe4770f4 AJ |
220 | { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, }, |
221 | { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, | |
8d88c4ca NC |
222 | }; |
223 | ||
67a4f2b7 AO |
224 | static reloc_howto_type * |
225 | elf64_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type) | |
226 | { | |
227 | unsigned i; | |
228 | ||
229 | if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT | |
230 | || r_type >= (unsigned int) R_X86_64_max) | |
231 | { | |
232 | if (r_type >= (unsigned int) R_X86_64_standard) | |
233 | { | |
234 | (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | |
235 | abfd, (int) r_type); | |
236 | r_type = R_X86_64_NONE; | |
237 | } | |
238 | i = r_type; | |
239 | } | |
240 | else | |
241 | i = r_type - (unsigned int) R_X86_64_vt_offset; | |
242 | BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type); | |
243 | return &x86_64_elf_howto_table[i]; | |
244 | } | |
8d88c4ca NC |
245 | |
246 | /* Given a BFD reloc type, return a HOWTO structure. */ | |
247 | static reloc_howto_type * | |
67a4f2b7 | 248 | elf64_x86_64_reloc_type_lookup (bfd *abfd, |
27482721 | 249 | bfd_reloc_code_real_type code) |
8d88c4ca NC |
250 | { |
251 | unsigned int i; | |
27482721 | 252 | |
8d88c4ca NC |
253 | for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map); |
254 | i++) | |
255 | { | |
256 | if (x86_64_reloc_map[i].bfd_reloc_val == code) | |
67a4f2b7 AO |
257 | return elf64_x86_64_rtype_to_howto (abfd, |
258 | x86_64_reloc_map[i].elf_reloc_val); | |
8d88c4ca NC |
259 | } |
260 | return 0; | |
261 | } | |
262 | ||
157090f7 AM |
263 | static reloc_howto_type * |
264 | elf64_x86_64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
265 | const char *r_name) | |
266 | { | |
267 | unsigned int i; | |
268 | ||
269 | for (i = 0; | |
270 | i < (sizeof (x86_64_elf_howto_table) | |
271 | / sizeof (x86_64_elf_howto_table[0])); | |
272 | i++) | |
273 | if (x86_64_elf_howto_table[i].name != NULL | |
274 | && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0) | |
275 | return &x86_64_elf_howto_table[i]; | |
276 | ||
277 | return NULL; | |
278 | } | |
279 | ||
8d88c4ca | 280 | /* Given an x86_64 ELF reloc type, fill in an arelent structure. */ |
8da6118f | 281 | |
8d88c4ca | 282 | static void |
27482721 AJ |
283 | elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, |
284 | Elf_Internal_Rela *dst) | |
8d88c4ca | 285 | { |
67a4f2b7 | 286 | unsigned r_type; |
8d88c4ca NC |
287 | |
288 | r_type = ELF64_R_TYPE (dst->r_info); | |
67a4f2b7 | 289 | cache_ptr->howto = elf64_x86_64_rtype_to_howto (abfd, r_type); |
8d88c4ca NC |
290 | BFD_ASSERT (r_type == cache_ptr->howto->type); |
291 | } | |
70256ad8 | 292 | \f |
3bab7989 | 293 | /* Support for core dump NOTE sections. */ |
b34976b6 | 294 | static bfd_boolean |
27482721 | 295 | elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
3bab7989 ML |
296 | { |
297 | int offset; | |
eea6121a | 298 | size_t size; |
3bab7989 ML |
299 | |
300 | switch (note->descsz) | |
301 | { | |
302 | default: | |
b34976b6 | 303 | return FALSE; |
3bab7989 ML |
304 | |
305 | case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */ | |
306 | /* pr_cursig */ | |
cedb70c5 | 307 | elf_tdata (abfd)->core_signal |
3bab7989 ML |
308 | = bfd_get_16 (abfd, note->descdata + 12); |
309 | ||
310 | /* pr_pid */ | |
cedb70c5 | 311 | elf_tdata (abfd)->core_pid |
3bab7989 ML |
312 | = bfd_get_32 (abfd, note->descdata + 32); |
313 | ||
314 | /* pr_reg */ | |
315 | offset = 112; | |
eea6121a | 316 | size = 216; |
3bab7989 ML |
317 | |
318 | break; | |
319 | } | |
320 | ||
321 | /* Make a ".reg/999" section. */ | |
322 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
eea6121a | 323 | size, note->descpos + offset); |
3bab7989 ML |
324 | } |
325 | ||
b34976b6 | 326 | static bfd_boolean |
27482721 | 327 | elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
3bab7989 ML |
328 | { |
329 | switch (note->descsz) | |
330 | { | |
331 | default: | |
b34976b6 | 332 | return FALSE; |
3bab7989 ML |
333 | |
334 | case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */ | |
335 | elf_tdata (abfd)->core_program | |
336 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); | |
337 | elf_tdata (abfd)->core_command | |
338 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); | |
339 | } | |
340 | ||
341 | /* Note that for some reason, a spurious space is tacked | |
342 | onto the end of the args in some (at least one anyway) | |
343 | implementations, so strip it off if it exists. */ | |
344 | ||
345 | { | |
346 | char *command = elf_tdata (abfd)->core_command; | |
347 | int n = strlen (command); | |
348 | ||
349 | if (0 < n && command[n - 1] == ' ') | |
350 | command[n - 1] = '\0'; | |
351 | } | |
352 | ||
b34976b6 | 353 | return TRUE; |
3bab7989 ML |
354 | } |
355 | \f | |
407443a3 | 356 | /* Functions for the x86-64 ELF linker. */ |
70256ad8 | 357 | |
407443a3 | 358 | /* The name of the dynamic interpreter. This is put in the .interp |
70256ad8 AJ |
359 | section. */ |
360 | ||
407443a3 | 361 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1" |
70256ad8 | 362 | |
d40d037c AJ |
363 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
364 | copying dynamic variables from a shared lib into an app's dynbss | |
365 | section, and instead use a dynamic relocation to point into the | |
366 | shared lib. */ | |
367 | #define ELIMINATE_COPY_RELOCS 1 | |
368 | ||
70256ad8 AJ |
369 | /* The size in bytes of an entry in the global offset table. */ |
370 | ||
371 | #define GOT_ENTRY_SIZE 8 | |
8d88c4ca | 372 | |
70256ad8 | 373 | /* The size in bytes of an entry in the procedure linkage table. */ |
8d88c4ca | 374 | |
70256ad8 AJ |
375 | #define PLT_ENTRY_SIZE 16 |
376 | ||
377 | /* The first entry in a procedure linkage table looks like this. See the | |
378 | SVR4 ABI i386 supplement and the x86-64 ABI to see how this works. */ | |
379 | ||
380 | static const bfd_byte elf64_x86_64_plt0_entry[PLT_ENTRY_SIZE] = | |
381 | { | |
653165cc AJ |
382 | 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ |
383 | 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */ | |
10efb593 | 384 | 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */ |
70256ad8 AJ |
385 | }; |
386 | ||
387 | /* Subsequent entries in a procedure linkage table look like this. */ | |
388 | ||
389 | static const bfd_byte elf64_x86_64_plt_entry[PLT_ENTRY_SIZE] = | |
390 | { | |
653165cc | 391 | 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */ |
407443a3 | 392 | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
653165cc | 393 | 0x68, /* pushq immediate */ |
70256ad8 AJ |
394 | 0, 0, 0, 0, /* replaced with index into relocation table. */ |
395 | 0xe9, /* jmp relative */ | |
396 | 0, 0, 0, 0 /* replaced with offset to start of .plt0. */ | |
397 | }; | |
398 | ||
399 | /* The x86-64 linker needs to keep track of the number of relocs that | |
985142a4 | 400 | it decides to copy as dynamic relocs in check_relocs for each symbol. |
c434dee6 AJ |
401 | This is so that it can later discard them if they are found to be |
402 | unnecessary. We store the information in a field extending the | |
403 | regular ELF linker hash table. */ | |
70256ad8 | 404 | |
c434dee6 | 405 | struct elf64_x86_64_dyn_relocs |
70256ad8 AJ |
406 | { |
407 | /* Next section. */ | |
c434dee6 AJ |
408 | struct elf64_x86_64_dyn_relocs *next; |
409 | ||
410 | /* The input section of the reloc. */ | |
411 | asection *sec; | |
412 | ||
413 | /* Total number of relocs copied for the input section. */ | |
70256ad8 | 414 | bfd_size_type count; |
c434dee6 AJ |
415 | |
416 | /* Number of pc-relative relocs copied for the input section. */ | |
417 | bfd_size_type pc_count; | |
70256ad8 AJ |
418 | }; |
419 | ||
420 | /* x86-64 ELF linker hash entry. */ | |
421 | ||
422 | struct elf64_x86_64_link_hash_entry | |
423 | { | |
c434dee6 | 424 | struct elf_link_hash_entry elf; |
70256ad8 | 425 | |
c434dee6 AJ |
426 | /* Track dynamic relocs copied for this symbol. */ |
427 | struct elf64_x86_64_dyn_relocs *dyn_relocs; | |
bffbf940 JJ |
428 | |
429 | #define GOT_UNKNOWN 0 | |
430 | #define GOT_NORMAL 1 | |
431 | #define GOT_TLS_GD 2 | |
432 | #define GOT_TLS_IE 3 | |
67a4f2b7 AO |
433 | #define GOT_TLS_GDESC 4 |
434 | #define GOT_TLS_GD_BOTH_P(type) \ | |
435 | ((type) == (GOT_TLS_GD | GOT_TLS_GDESC)) | |
436 | #define GOT_TLS_GD_P(type) \ | |
437 | ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type)) | |
438 | #define GOT_TLS_GDESC_P(type) \ | |
439 | ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type)) | |
440 | #define GOT_TLS_GD_ANY_P(type) \ | |
441 | (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type)) | |
bffbf940 | 442 | unsigned char tls_type; |
67a4f2b7 AO |
443 | |
444 | /* Offset of the GOTPLT entry reserved for the TLS descriptor, | |
445 | starting at the end of the jump table. */ | |
446 | bfd_vma tlsdesc_got; | |
bffbf940 JJ |
447 | }; |
448 | ||
449 | #define elf64_x86_64_hash_entry(ent) \ | |
450 | ((struct elf64_x86_64_link_hash_entry *)(ent)) | |
451 | ||
452 | struct elf64_x86_64_obj_tdata | |
453 | { | |
454 | struct elf_obj_tdata root; | |
455 | ||
456 | /* tls_type for each local got entry. */ | |
457 | char *local_got_tls_type; | |
67a4f2b7 AO |
458 | |
459 | /* GOTPLT entries for TLS descriptors. */ | |
460 | bfd_vma *local_tlsdesc_gotent; | |
70256ad8 AJ |
461 | }; |
462 | ||
bffbf940 JJ |
463 | #define elf64_x86_64_tdata(abfd) \ |
464 | ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any) | |
465 | ||
466 | #define elf64_x86_64_local_got_tls_type(abfd) \ | |
467 | (elf64_x86_64_tdata (abfd)->local_got_tls_type) | |
468 | ||
67a4f2b7 AO |
469 | #define elf64_x86_64_local_tlsdesc_gotent(abfd) \ |
470 | (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent) | |
bffbf940 | 471 | |
0ffa91dd NC |
472 | #define is_x86_64_elf(bfd) \ |
473 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
474 | && elf_tdata (bfd) != NULL \ | |
475 | && elf_object_id (bfd) == X86_64_ELF_TDATA) | |
476 | ||
477 | static bfd_boolean | |
478 | elf64_x86_64_mkobject (bfd *abfd) | |
479 | { | |
480 | return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata), | |
481 | X86_64_ELF_TDATA); | |
482 | } | |
483 | ||
c434dee6 | 484 | /* x86-64 ELF linker hash table. */ |
8d88c4ca | 485 | |
407443a3 AJ |
486 | struct elf64_x86_64_link_hash_table |
487 | { | |
c434dee6 | 488 | struct elf_link_hash_table elf; |
70256ad8 | 489 | |
c434dee6 | 490 | /* Short-cuts to get to dynamic linker sections. */ |
c434dee6 AJ |
491 | asection *sdynbss; |
492 | asection *srelbss; | |
70256ad8 | 493 | |
67a4f2b7 AO |
494 | /* The offset into splt of the PLT entry for the TLS descriptor |
495 | resolver. Special values are 0, if not necessary (or not found | |
496 | to be necessary yet), and -1 if needed but not determined | |
497 | yet. */ | |
498 | bfd_vma tlsdesc_plt; | |
499 | /* The offset into sgot of the GOT entry used by the PLT entry | |
500 | above. */ | |
501 | bfd_vma tlsdesc_got; | |
502 | ||
bffbf940 JJ |
503 | union { |
504 | bfd_signed_vma refcount; | |
505 | bfd_vma offset; | |
506 | } tls_ld_got; | |
507 | ||
67a4f2b7 AO |
508 | /* The amount of space used by the jump slots in the GOT. */ |
509 | bfd_vma sgotplt_jump_table_size; | |
510 | ||
c434dee6 AJ |
511 | /* Small local sym to section mapping cache. */ |
512 | struct sym_sec_cache sym_sec; | |
9f03412a AO |
513 | |
514 | /* _TLS_MODULE_BASE_ symbol. */ | |
515 | struct bfd_link_hash_entry *tls_module_base; | |
c25bc9fc L |
516 | |
517 | /* Used by local STT_GNU_IFUNC symbols. */ | |
518 | htab_t loc_hash_table; | |
519 | void *loc_hash_memory; | |
c434dee6 | 520 | }; |
70256ad8 AJ |
521 | |
522 | /* Get the x86-64 ELF linker hash table from a link_info structure. */ | |
8d88c4ca NC |
523 | |
524 | #define elf64_x86_64_hash_table(p) \ | |
525 | ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) | |
526 | ||
67a4f2b7 | 527 | #define elf64_x86_64_compute_jump_table_size(htab) \ |
6de2ae4a | 528 | ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE) |
67a4f2b7 | 529 | |
407443a3 | 530 | /* Create an entry in an x86-64 ELF linker hash table. */ |
70256ad8 AJ |
531 | |
532 | static struct bfd_hash_entry * | |
eb4ff4d6 L |
533 | elf64_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry, |
534 | struct bfd_hash_table *table, | |
535 | const char *string) | |
70256ad8 | 536 | { |
70256ad8 | 537 | /* Allocate the structure if it has not already been allocated by a |
c434dee6 AJ |
538 | subclass. */ |
539 | if (entry == NULL) | |
540 | { | |
541 | entry = bfd_hash_allocate (table, | |
542 | sizeof (struct elf64_x86_64_link_hash_entry)); | |
543 | if (entry == NULL) | |
544 | return entry; | |
545 | } | |
70256ad8 AJ |
546 | |
547 | /* Call the allocation method of the superclass. */ | |
c434dee6 AJ |
548 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
549 | if (entry != NULL) | |
70256ad8 | 550 | { |
c434dee6 AJ |
551 | struct elf64_x86_64_link_hash_entry *eh; |
552 | ||
553 | eh = (struct elf64_x86_64_link_hash_entry *) entry; | |
554 | eh->dyn_relocs = NULL; | |
bffbf940 | 555 | eh->tls_type = GOT_UNKNOWN; |
67a4f2b7 | 556 | eh->tlsdesc_got = (bfd_vma) -1; |
70256ad8 AJ |
557 | } |
558 | ||
c434dee6 | 559 | return entry; |
70256ad8 AJ |
560 | } |
561 | ||
c25bc9fc L |
562 | /* Compute a hash of a local hash entry. We use elf_link_hash_entry |
563 | for local symbol so that we can handle local STT_GNU_IFUNC symbols | |
564 | as global symbol. We reuse indx and dynstr_index for local symbol | |
565 | hash since they aren't used by global symbols in this backend. */ | |
566 | ||
567 | static hashval_t | |
568 | elf64_x86_64_local_htab_hash (const void *ptr) | |
569 | { | |
570 | struct elf_link_hash_entry *h | |
571 | = (struct elf_link_hash_entry *) ptr; | |
d2149d72 | 572 | return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index); |
c25bc9fc L |
573 | } |
574 | ||
575 | /* Compare local hash entries. */ | |
576 | ||
577 | static int | |
578 | elf64_x86_64_local_htab_eq (const void *ptr1, const void *ptr2) | |
579 | { | |
580 | struct elf_link_hash_entry *h1 | |
581 | = (struct elf_link_hash_entry *) ptr1; | |
582 | struct elf_link_hash_entry *h2 | |
583 | = (struct elf_link_hash_entry *) ptr2; | |
584 | ||
585 | return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index; | |
586 | } | |
587 | ||
588 | /* Find and/or create a hash entry for local symbol. */ | |
589 | ||
590 | static struct elf_link_hash_entry * | |
591 | elf64_x86_64_get_local_sym_hash (struct elf64_x86_64_link_hash_table *htab, | |
592 | bfd *abfd, const Elf_Internal_Rela *rel, | |
593 | bfd_boolean create) | |
594 | { | |
595 | struct elf64_x86_64_link_hash_entry e, *ret; | |
596 | asection *sec = abfd->sections; | |
d2149d72 L |
597 | hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, |
598 | ELF64_R_SYM (rel->r_info)); | |
c25bc9fc L |
599 | void **slot; |
600 | ||
601 | e.elf.indx = sec->id; | |
602 | e.elf.dynstr_index = ELF64_R_SYM (rel->r_info); | |
603 | slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h, | |
604 | create ? INSERT : NO_INSERT); | |
605 | ||
606 | if (!slot) | |
607 | return NULL; | |
608 | ||
609 | if (*slot) | |
610 | { | |
611 | ret = (struct elf64_x86_64_link_hash_entry *) *slot; | |
612 | return &ret->elf; | |
613 | } | |
614 | ||
615 | ret = (struct elf64_x86_64_link_hash_entry *) | |
616 | objalloc_alloc ((struct objalloc *) htab->loc_hash_memory, | |
617 | sizeof (struct elf64_x86_64_link_hash_entry)); | |
618 | if (ret) | |
619 | { | |
620 | memset (ret, 0, sizeof (*ret)); | |
621 | ret->elf.indx = sec->id; | |
622 | ret->elf.dynstr_index = ELF64_R_SYM (rel->r_info); | |
623 | ret->elf.dynindx = -1; | |
624 | ret->elf.plt.offset = (bfd_vma) -1; | |
625 | ret->elf.got.offset = (bfd_vma) -1; | |
626 | *slot = ret; | |
627 | } | |
628 | return &ret->elf; | |
629 | } | |
630 | ||
8d88c4ca NC |
631 | /* Create an X86-64 ELF linker hash table. */ |
632 | ||
633 | static struct bfd_link_hash_table * | |
27482721 | 634 | elf64_x86_64_link_hash_table_create (bfd *abfd) |
8d88c4ca NC |
635 | { |
636 | struct elf64_x86_64_link_hash_table *ret; | |
dc810e39 | 637 | bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table); |
8d88c4ca | 638 | |
e2d34d7d | 639 | ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt); |
c434dee6 | 640 | if (ret == NULL) |
8d88c4ca NC |
641 | return NULL; |
642 | ||
eb4ff4d6 L |
643 | if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, |
644 | elf64_x86_64_link_hash_newfunc, | |
66eb6687 | 645 | sizeof (struct elf64_x86_64_link_hash_entry))) |
8d88c4ca | 646 | { |
e2d34d7d | 647 | free (ret); |
8d88c4ca NC |
648 | return NULL; |
649 | } | |
650 | ||
c434dee6 AJ |
651 | ret->sdynbss = NULL; |
652 | ret->srelbss = NULL; | |
653 | ret->sym_sec.abfd = NULL; | |
67a4f2b7 AO |
654 | ret->tlsdesc_plt = 0; |
655 | ret->tlsdesc_got = 0; | |
bffbf940 | 656 | ret->tls_ld_got.refcount = 0; |
67a4f2b7 | 657 | ret->sgotplt_jump_table_size = 0; |
9f03412a | 658 | ret->tls_module_base = NULL; |
c434dee6 | 659 | |
c25bc9fc L |
660 | ret->loc_hash_table = htab_try_create (1024, |
661 | elf64_x86_64_local_htab_hash, | |
662 | elf64_x86_64_local_htab_eq, | |
663 | NULL); | |
664 | ret->loc_hash_memory = objalloc_create (); | |
665 | if (!ret->loc_hash_table || !ret->loc_hash_memory) | |
666 | { | |
667 | free (ret); | |
668 | return NULL; | |
669 | } | |
670 | ||
c434dee6 AJ |
671 | return &ret->elf.root; |
672 | } | |
673 | ||
c25bc9fc L |
674 | /* Destroy an X86-64 ELF linker hash table. */ |
675 | ||
676 | static void | |
677 | elf64_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash) | |
678 | { | |
679 | struct elf64_x86_64_link_hash_table *htab | |
680 | = (struct elf64_x86_64_link_hash_table *) hash; | |
681 | ||
682 | if (htab->loc_hash_table) | |
683 | htab_delete (htab->loc_hash_table); | |
684 | if (htab->loc_hash_memory) | |
685 | objalloc_free ((struct objalloc *) htab->loc_hash_memory); | |
686 | _bfd_generic_link_hash_table_free (hash); | |
687 | } | |
688 | ||
c434dee6 AJ |
689 | /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and |
690 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | |
691 | hash table. */ | |
692 | ||
b34976b6 | 693 | static bfd_boolean |
27482721 | 694 | elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
c434dee6 AJ |
695 | { |
696 | struct elf64_x86_64_link_hash_table *htab; | |
697 | ||
c434dee6 | 698 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
b34976b6 | 699 | return FALSE; |
c434dee6 | 700 | |
6de2ae4a | 701 | htab = elf64_x86_64_hash_table (info); |
c434dee6 AJ |
702 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); |
703 | if (!info->shared) | |
704 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
705 | ||
6de2ae4a | 706 | if (!htab->sdynbss |
c434dee6 AJ |
707 | || (!info->shared && !htab->srelbss)) |
708 | abort (); | |
709 | ||
b34976b6 | 710 | return TRUE; |
c434dee6 AJ |
711 | } |
712 | ||
713 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
714 | ||
715 | static void | |
fcfa13d2 | 716 | elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info, |
27482721 AJ |
717 | struct elf_link_hash_entry *dir, |
718 | struct elf_link_hash_entry *ind) | |
c434dee6 AJ |
719 | { |
720 | struct elf64_x86_64_link_hash_entry *edir, *eind; | |
721 | ||
722 | edir = (struct elf64_x86_64_link_hash_entry *) dir; | |
723 | eind = (struct elf64_x86_64_link_hash_entry *) ind; | |
724 | ||
725 | if (eind->dyn_relocs != NULL) | |
726 | { | |
727 | if (edir->dyn_relocs != NULL) | |
728 | { | |
729 | struct elf64_x86_64_dyn_relocs **pp; | |
730 | struct elf64_x86_64_dyn_relocs *p; | |
731 | ||
fcfa13d2 | 732 | /* Add reloc counts against the indirect sym to the direct sym |
c434dee6 AJ |
733 | list. Merge any entries against the same section. */ |
734 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
735 | { | |
736 | struct elf64_x86_64_dyn_relocs *q; | |
737 | ||
738 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
739 | if (q->sec == p->sec) | |
740 | { | |
741 | q->pc_count += p->pc_count; | |
742 | q->count += p->count; | |
743 | *pp = p->next; | |
744 | break; | |
745 | } | |
746 | if (q == NULL) | |
747 | pp = &p->next; | |
748 | } | |
749 | *pp = edir->dyn_relocs; | |
750 | } | |
751 | ||
752 | edir->dyn_relocs = eind->dyn_relocs; | |
753 | eind->dyn_relocs = NULL; | |
754 | } | |
755 | ||
bffbf940 JJ |
756 | if (ind->root.type == bfd_link_hash_indirect |
757 | && dir->got.refcount <= 0) | |
758 | { | |
759 | edir->tls_type = eind->tls_type; | |
760 | eind->tls_type = GOT_UNKNOWN; | |
761 | } | |
762 | ||
d40d037c AJ |
763 | if (ELIMINATE_COPY_RELOCS |
764 | && ind->root.type != bfd_link_hash_indirect | |
f5385ebf AM |
765 | && dir->dynamic_adjusted) |
766 | { | |
767 | /* If called to transfer flags for a weakdef during processing | |
768 | of elf_adjust_dynamic_symbol, don't copy non_got_ref. | |
769 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */ | |
770 | dir->ref_dynamic |= ind->ref_dynamic; | |
771 | dir->ref_regular |= ind->ref_regular; | |
772 | dir->ref_regular_nonweak |= ind->ref_regular_nonweak; | |
773 | dir->needs_plt |= ind->needs_plt; | |
774 | dir->pointer_equality_needed |= ind->pointer_equality_needed; | |
775 | } | |
d40d037c | 776 | else |
fcfa13d2 | 777 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
8d88c4ca NC |
778 | } |
779 | ||
b34976b6 | 780 | static bfd_boolean |
27482721 | 781 | elf64_x86_64_elf_object_p (bfd *abfd) |
bffbf940 | 782 | { |
8d88c4ca NC |
783 | /* Set the right machine number for an x86-64 elf64 file. */ |
784 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64); | |
b34976b6 | 785 | return TRUE; |
8d88c4ca NC |
786 | } |
787 | ||
142411ca L |
788 | typedef union |
789 | { | |
790 | unsigned char c[2]; | |
791 | uint16_t i; | |
792 | } | |
793 | x86_64_opcode16; | |
794 | ||
795 | typedef union | |
796 | { | |
797 | unsigned char c[4]; | |
798 | uint32_t i; | |
799 | } | |
800 | x86_64_opcode32; | |
801 | ||
802 | /* Return TRUE if the TLS access code sequence support transition | |
803 | from R_TYPE. */ | |
804 | ||
805 | static bfd_boolean | |
806 | elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec, | |
807 | bfd_byte *contents, | |
808 | Elf_Internal_Shdr *symtab_hdr, | |
809 | struct elf_link_hash_entry **sym_hashes, | |
810 | unsigned int r_type, | |
811 | const Elf_Internal_Rela *rel, | |
812 | const Elf_Internal_Rela *relend) | |
bffbf940 | 813 | { |
142411ca L |
814 | unsigned int val; |
815 | unsigned long r_symndx; | |
816 | struct elf_link_hash_entry *h; | |
817 | bfd_vma offset; | |
818 | ||
819 | /* Get the section contents. */ | |
820 | if (contents == NULL) | |
821 | { | |
822 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
823 | contents = elf_section_data (sec)->this_hdr.contents; | |
824 | else | |
825 | { | |
826 | /* FIXME: How to better handle error condition? */ | |
827 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) | |
828 | return FALSE; | |
bffbf940 | 829 | |
142411ca L |
830 | /* Cache the section contents for elf_link_input_bfd. */ |
831 | elf_section_data (sec)->this_hdr.contents = contents; | |
832 | } | |
833 | } | |
834 | ||
835 | offset = rel->r_offset; | |
bffbf940 | 836 | switch (r_type) |
142411ca L |
837 | { |
838 | case R_X86_64_TLSGD: | |
839 | case R_X86_64_TLSLD: | |
840 | if ((rel + 1) >= relend) | |
841 | return FALSE; | |
842 | ||
843 | if (r_type == R_X86_64_TLSGD) | |
844 | { | |
845 | /* Check transition from GD access model. Only | |
846 | .byte 0x66; leaq foo@tlsgd(%rip), %rdi | |
847 | .word 0x6666; rex64; call __tls_get_addr | |
848 | can transit to different access model. */ | |
849 | ||
850 | static x86_64_opcode32 leaq = { { 0x66, 0x48, 0x8d, 0x3d } }, | |
851 | call = { { 0x66, 0x66, 0x48, 0xe8 } }; | |
852 | if (offset < 4 | |
853 | || (offset + 12) > sec->size | |
854 | || bfd_get_32 (abfd, contents + offset - 4) != leaq.i | |
855 | || bfd_get_32 (abfd, contents + offset + 4) != call.i) | |
856 | return FALSE; | |
857 | } | |
858 | else | |
859 | { | |
860 | /* Check transition from LD access model. Only | |
861 | leaq foo@tlsld(%rip), %rdi; | |
862 | call __tls_get_addr | |
863 | can transit to different access model. */ | |
864 | ||
865 | static x86_64_opcode32 ld = { { 0x48, 0x8d, 0x3d, 0xe8 } }; | |
866 | x86_64_opcode32 op; | |
867 | ||
868 | if (offset < 3 || (offset + 9) > sec->size) | |
869 | return FALSE; | |
870 | ||
871 | op.i = bfd_get_32 (abfd, contents + offset - 3); | |
872 | op.c[3] = bfd_get_8 (abfd, contents + offset + 4); | |
873 | if (op.i != ld.i) | |
874 | return FALSE; | |
875 | } | |
876 | ||
877 | r_symndx = ELF64_R_SYM (rel[1].r_info); | |
878 | if (r_symndx < symtab_hdr->sh_info) | |
879 | return FALSE; | |
880 | ||
881 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
c4fb387b L |
882 | /* Use strncmp to check __tls_get_addr since __tls_get_addr |
883 | may be versioned. */ | |
142411ca L |
884 | return (h != NULL |
885 | && h->root.root.string != NULL | |
886 | && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32 | |
887 | || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32) | |
c4fb387b L |
888 | && (strncmp (h->root.root.string, |
889 | "__tls_get_addr", 14) == 0)); | |
142411ca L |
890 | |
891 | case R_X86_64_GOTTPOFF: | |
892 | /* Check transition from IE access model: | |
893 | movq foo@gottpoff(%rip), %reg | |
894 | addq foo@gottpoff(%rip), %reg | |
895 | */ | |
896 | ||
897 | if (offset < 3 || (offset + 4) > sec->size) | |
898 | return FALSE; | |
899 | ||
900 | val = bfd_get_8 (abfd, contents + offset - 3); | |
901 | if (val != 0x48 && val != 0x4c) | |
902 | return FALSE; | |
903 | ||
904 | val = bfd_get_8 (abfd, contents + offset - 2); | |
905 | if (val != 0x8b && val != 0x03) | |
906 | return FALSE; | |
907 | ||
908 | val = bfd_get_8 (abfd, contents + offset - 1); | |
909 | return (val & 0xc7) == 5; | |
910 | ||
911 | case R_X86_64_GOTPC32_TLSDESC: | |
912 | /* Check transition from GDesc access model: | |
913 | leaq x@tlsdesc(%rip), %rax | |
914 | ||
915 | Make sure it's a leaq adding rip to a 32-bit offset | |
916 | into any register, although it's probably almost always | |
917 | going to be rax. */ | |
918 | ||
919 | if (offset < 3 || (offset + 4) > sec->size) | |
920 | return FALSE; | |
921 | ||
922 | val = bfd_get_8 (abfd, contents + offset - 3); | |
923 | if ((val & 0xfb) != 0x48) | |
924 | return FALSE; | |
925 | ||
926 | if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d) | |
927 | return FALSE; | |
928 | ||
929 | val = bfd_get_8 (abfd, contents + offset - 1); | |
930 | return (val & 0xc7) == 0x05; | |
931 | ||
932 | case R_X86_64_TLSDESC_CALL: | |
933 | /* Check transition from GDesc access model: | |
934 | call *x@tlsdesc(%rax) | |
935 | */ | |
936 | if (offset + 2 <= sec->size) | |
937 | { | |
938 | /* Make sure that it's a call *x@tlsdesc(%rax). */ | |
939 | static x86_64_opcode16 call = { { 0xff, 0x10 } }; | |
940 | return bfd_get_16 (abfd, contents + offset) == call.i; | |
941 | } | |
942 | ||
943 | return FALSE; | |
944 | ||
945 | default: | |
946 | abort (); | |
947 | } | |
948 | } | |
949 | ||
950 | /* Return TRUE if the TLS access transition is OK or no transition | |
951 | will be performed. Update R_TYPE if there is a transition. */ | |
952 | ||
953 | static bfd_boolean | |
954 | elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, | |
955 | asection *sec, bfd_byte *contents, | |
956 | Elf_Internal_Shdr *symtab_hdr, | |
957 | struct elf_link_hash_entry **sym_hashes, | |
958 | unsigned int *r_type, int tls_type, | |
959 | const Elf_Internal_Rela *rel, | |
960 | const Elf_Internal_Rela *relend, | |
961 | struct elf_link_hash_entry *h) | |
962 | { | |
963 | unsigned int from_type = *r_type; | |
964 | unsigned int to_type = from_type; | |
965 | bfd_boolean check = TRUE; | |
966 | ||
967 | switch (from_type) | |
bffbf940 JJ |
968 | { |
969 | case R_X86_64_TLSGD: | |
67a4f2b7 AO |
970 | case R_X86_64_GOTPC32_TLSDESC: |
971 | case R_X86_64_TLSDESC_CALL: | |
bffbf940 | 972 | case R_X86_64_GOTTPOFF: |
142411ca L |
973 | if (!info->shared) |
974 | { | |
975 | if (h == NULL) | |
976 | to_type = R_X86_64_TPOFF32; | |
977 | else | |
978 | to_type = R_X86_64_GOTTPOFF; | |
979 | } | |
980 | ||
981 | /* When we are called from elf64_x86_64_relocate_section, | |
982 | CONTENTS isn't NULL and there may be additional transitions | |
983 | based on TLS_TYPE. */ | |
984 | if (contents != NULL) | |
985 | { | |
986 | unsigned int new_to_type = to_type; | |
987 | ||
988 | if (!info->shared | |
989 | && h != NULL | |
990 | && h->dynindx == -1 | |
991 | && tls_type == GOT_TLS_IE) | |
992 | new_to_type = R_X86_64_TPOFF32; | |
993 | ||
994 | if (to_type == R_X86_64_TLSGD | |
995 | || to_type == R_X86_64_GOTPC32_TLSDESC | |
996 | || to_type == R_X86_64_TLSDESC_CALL) | |
997 | { | |
998 | if (tls_type == GOT_TLS_IE) | |
999 | new_to_type = R_X86_64_GOTTPOFF; | |
1000 | } | |
1001 | ||
1002 | /* We checked the transition before when we were called from | |
1003 | elf64_x86_64_check_relocs. We only want to check the new | |
1004 | transition which hasn't been checked before. */ | |
1005 | check = new_to_type != to_type && from_type == to_type; | |
1006 | to_type = new_to_type; | |
1007 | } | |
1008 | ||
1009 | break; | |
1010 | ||
bffbf940 | 1011 | case R_X86_64_TLSLD: |
142411ca L |
1012 | if (!info->shared) |
1013 | to_type = R_X86_64_TPOFF32; | |
1014 | break; | |
1015 | ||
1016 | default: | |
1017 | return TRUE; | |
bffbf940 JJ |
1018 | } |
1019 | ||
142411ca L |
1020 | /* Return TRUE if there is no transition. */ |
1021 | if (from_type == to_type) | |
1022 | return TRUE; | |
1023 | ||
1024 | /* Check if the transition can be performed. */ | |
1025 | if (check | |
1026 | && ! elf64_x86_64_check_tls_transition (abfd, sec, contents, | |
1027 | symtab_hdr, sym_hashes, | |
1028 | from_type, rel, relend)) | |
1029 | { | |
2f629d23 | 1030 | reloc_howto_type *from, *to; |
142411ca L |
1031 | |
1032 | from = elf64_x86_64_rtype_to_howto (abfd, from_type); | |
1033 | to = elf64_x86_64_rtype_to_howto (abfd, to_type); | |
1034 | ||
1035 | (*_bfd_error_handler) | |
1036 | (_("%B: TLS transition from %s to %s against `%s' at 0x%lx " | |
1037 | "in section `%A' failed"), | |
1038 | abfd, sec, from->name, to->name, | |
1039 | h ? h->root.root.string : "a local symbol", | |
1040 | (unsigned long) rel->r_offset); | |
1041 | bfd_set_error (bfd_error_bad_value); | |
1042 | return FALSE; | |
1043 | } | |
1044 | ||
1045 | *r_type = to_type; | |
1046 | return TRUE; | |
bffbf940 JJ |
1047 | } |
1048 | ||
70256ad8 | 1049 | /* Look through the relocs for a section during the first phase, and |
c434dee6 AJ |
1050 | calculate needed space in the global offset table, procedure |
1051 | linkage table, and dynamic reloc sections. */ | |
70256ad8 | 1052 | |
b34976b6 | 1053 | static bfd_boolean |
142411ca L |
1054 | elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
1055 | asection *sec, | |
27482721 | 1056 | const Elf_Internal_Rela *relocs) |
70256ad8 | 1057 | { |
c434dee6 | 1058 | struct elf64_x86_64_link_hash_table *htab; |
70256ad8 AJ |
1059 | Elf_Internal_Shdr *symtab_hdr; |
1060 | struct elf_link_hash_entry **sym_hashes; | |
70256ad8 AJ |
1061 | const Elf_Internal_Rela *rel; |
1062 | const Elf_Internal_Rela *rel_end; | |
70256ad8 | 1063 | asection *sreloc; |
c25bc9fc | 1064 | Elf_Internal_Sym *isymbuf; |
70256ad8 | 1065 | |
1049f94e | 1066 | if (info->relocatable) |
b34976b6 | 1067 | return TRUE; |
70256ad8 | 1068 | |
0ffa91dd NC |
1069 | BFD_ASSERT (is_x86_64_elf (abfd)); |
1070 | ||
c434dee6 | 1071 | htab = elf64_x86_64_hash_table (info); |
0ffa91dd | 1072 | symtab_hdr = &elf_symtab_hdr (abfd); |
c25bc9fc | 1073 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
70256ad8 | 1074 | sym_hashes = elf_sym_hashes (abfd); |
70256ad8 | 1075 | |
c434dee6 | 1076 | sreloc = NULL; |
cbe950e9 | 1077 | |
70256ad8 AJ |
1078 | rel_end = relocs + sec->reloc_count; |
1079 | for (rel = relocs; rel < rel_end; rel++) | |
1080 | { | |
bffbf940 | 1081 | unsigned int r_type; |
70256ad8 AJ |
1082 | unsigned long r_symndx; |
1083 | struct elf_link_hash_entry *h; | |
1084 | ||
1085 | r_symndx = ELF64_R_SYM (rel->r_info); | |
bffbf940 | 1086 | r_type = ELF64_R_TYPE (rel->r_info); |
c434dee6 AJ |
1087 | |
1088 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
1089 | { | |
d003868e AM |
1090 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), |
1091 | abfd, r_symndx); | |
b34976b6 | 1092 | return FALSE; |
c434dee6 AJ |
1093 | } |
1094 | ||
70256ad8 | 1095 | if (r_symndx < symtab_hdr->sh_info) |
c25bc9fc L |
1096 | { |
1097 | /* A local symbol. */ | |
1098 | Elf_Internal_Sym *isym; | |
1099 | ||
1100 | /* Read this BFD's local symbols. */ | |
1101 | if (isymbuf == NULL) | |
1102 | { | |
1103 | if (isymbuf == NULL) | |
1104 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
1105 | symtab_hdr->sh_info, 0, | |
1106 | NULL, NULL, NULL); | |
1107 | if (isymbuf == NULL) | |
1108 | return FALSE; | |
1109 | } | |
1110 | ||
1111 | /* Check relocation against local STT_GNU_IFUNC symbol. */ | |
1112 | isym = isymbuf + r_symndx; | |
1113 | if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) | |
1114 | { | |
1115 | h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel, | |
1116 | TRUE); | |
1117 | if (h == NULL) | |
1118 | return FALSE; | |
1119 | ||
1120 | /* Fake a STT_GNU_IFUNC symbol. */ | |
1121 | h->type = STT_GNU_IFUNC; | |
1122 | h->def_regular = 1; | |
1123 | h->ref_regular = 1; | |
1124 | h->forced_local = 1; | |
1125 | h->root.type = bfd_link_hash_defined; | |
1126 | } | |
1127 | else | |
1128 | h = NULL; | |
1129 | } | |
70256ad8 | 1130 | else |
71cb9464 L |
1131 | { |
1132 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1133 | while (h->root.type == bfd_link_hash_indirect | |
1134 | || h->root.type == bfd_link_hash_warning) | |
1135 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
c25bc9fc | 1136 | } |
cbe950e9 | 1137 | |
c25bc9fc L |
1138 | if (h != NULL) |
1139 | { | |
cbe950e9 L |
1140 | /* Create the ifunc sections for static executables. If we |
1141 | never see an indirect function symbol nor we are building | |
1142 | a static executable, those sections will be empty and | |
1143 | won't appear in output. */ | |
1144 | switch (r_type) | |
1145 | { | |
1146 | default: | |
1147 | break; | |
1148 | ||
1149 | case R_X86_64_32S: | |
1150 | case R_X86_64_32: | |
1151 | case R_X86_64_64: | |
1152 | case R_X86_64_PC32: | |
1153 | case R_X86_64_PC64: | |
1154 | case R_X86_64_PLT32: | |
1155 | case R_X86_64_GOTPCREL: | |
1156 | case R_X86_64_GOTPCREL64: | |
6de2ae4a L |
1157 | if (!_bfd_elf_create_ifunc_sections (abfd, info)) |
1158 | return FALSE; | |
cbe950e9 L |
1159 | break; |
1160 | } | |
1161 | ||
1162 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle | |
1163 | it here if it is defined in a non-shared object. */ | |
1164 | if (h->type == STT_GNU_IFUNC | |
1165 | && h->def_regular) | |
1166 | { | |
1167 | /* It is referenced by a non-shared object. */ | |
1168 | h->ref_regular = 1; | |
1169 | ||
1170 | /* STT_GNU_IFUNC symbol must go through PLT. */ | |
1171 | h->plt.refcount += 1; | |
1172 | ||
1173 | /* STT_GNU_IFUNC needs dynamic sections. */ | |
1174 | if (htab->elf.dynobj == NULL) | |
1175 | htab->elf.dynobj = abfd; | |
1176 | ||
1177 | switch (r_type) | |
1178 | { | |
048cbda4 L |
1179 | default: |
1180 | (*_bfd_error_handler) | |
1181 | (_("%B: relocation %s against STT_GNU_IFUNC " | |
1182 | "symbol `%s' isn't handled by %s"), abfd, | |
1183 | x86_64_elf_howto_table[r_type].name, | |
8b7e2992 L |
1184 | (h->root.root.string |
1185 | ? h->root.root.string : "a local symbol"), | |
048cbda4 L |
1186 | __FUNCTION__); |
1187 | bfd_set_error (bfd_error_bad_value); | |
1188 | return FALSE; | |
cbe950e9 | 1189 | |
710ab287 L |
1190 | case R_X86_64_64: |
1191 | h->non_got_ref = 1; | |
1192 | h->pointer_equality_needed = 1; | |
1193 | if (info->shared) | |
1194 | { | |
1195 | struct elf64_x86_64_dyn_relocs *p; | |
1196 | struct elf64_x86_64_dyn_relocs **head; | |
1197 | ||
1198 | /* We must copy these reloc types into the output | |
1199 | file. Create a reloc section in dynobj and | |
1200 | make room for this reloc. */ | |
1201 | if (sreloc == NULL) | |
1202 | { | |
1203 | if (htab->elf.dynobj == NULL) | |
1204 | htab->elf.dynobj = abfd; | |
1205 | ||
1206 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
1207 | (sec, htab->elf.dynobj, 3, abfd, TRUE); | |
1208 | ||
1209 | if (sreloc == NULL) | |
1210 | return FALSE; | |
1211 | } | |
1212 | ||
1213 | head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs; | |
1214 | p = *head; | |
1215 | if (p == NULL || p->sec != sec) | |
1216 | { | |
1217 | bfd_size_type amt = sizeof *p; | |
1218 | ||
1219 | p = ((struct elf64_x86_64_dyn_relocs *) | |
1220 | bfd_alloc (htab->elf.dynobj, amt)); | |
1221 | if (p == NULL) | |
1222 | return FALSE; | |
1223 | p->next = *head; | |
1224 | *head = p; | |
1225 | p->sec = sec; | |
1226 | p->count = 0; | |
1227 | p->pc_count = 0; | |
1228 | } | |
1229 | p->count += 1; | |
1230 | } | |
1231 | break; | |
1232 | ||
cbe950e9 L |
1233 | case R_X86_64_32S: |
1234 | case R_X86_64_32: | |
cbe950e9 L |
1235 | case R_X86_64_PC32: |
1236 | case R_X86_64_PC64: | |
1237 | h->non_got_ref = 1; | |
1238 | if (r_type != R_X86_64_PC32 | |
1239 | && r_type != R_X86_64_PC64) | |
1240 | h->pointer_equality_needed = 1; | |
1241 | break; | |
1242 | ||
1243 | case R_X86_64_PLT32: | |
1244 | break; | |
1245 | ||
1246 | case R_X86_64_GOTPCREL: | |
1247 | case R_X86_64_GOTPCREL64: | |
7afd84dc | 1248 | h->got.refcount += 1; |
6de2ae4a L |
1249 | if (htab->elf.sgot == NULL |
1250 | && !_bfd_elf_create_got_section (htab->elf.dynobj, | |
1251 | info)) | |
cbe950e9 L |
1252 | return FALSE; |
1253 | break; | |
1254 | } | |
1255 | ||
1256 | continue; | |
1257 | } | |
71cb9464 | 1258 | } |
70256ad8 | 1259 | |
142411ca L |
1260 | if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL, |
1261 | symtab_hdr, sym_hashes, | |
1262 | &r_type, GOT_UNKNOWN, | |
1263 | rel, rel_end, h)) | |
1264 | return FALSE; | |
1265 | ||
bffbf940 | 1266 | switch (r_type) |
70256ad8 | 1267 | { |
bffbf940 JJ |
1268 | case R_X86_64_TLSLD: |
1269 | htab->tls_ld_got.refcount += 1; | |
1270 | goto create_got; | |
1271 | ||
1272 | case R_X86_64_TPOFF32: | |
1273 | if (info->shared) | |
70256ad8 | 1274 | { |
bffbf940 | 1275 | (*_bfd_error_handler) |
d003868e AM |
1276 | (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"), |
1277 | abfd, | |
6610a52d L |
1278 | x86_64_elf_howto_table[r_type].name, |
1279 | (h) ? h->root.root.string : "a local symbol"); | |
bffbf940 | 1280 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1281 | return FALSE; |
70256ad8 | 1282 | } |
bffbf940 | 1283 | break; |
c434dee6 | 1284 | |
bffbf940 JJ |
1285 | case R_X86_64_GOTTPOFF: |
1286 | if (info->shared) | |
1287 | info->flags |= DF_STATIC_TLS; | |
1288 | /* Fall through */ | |
70256ad8 | 1289 | |
bffbf940 JJ |
1290 | case R_X86_64_GOT32: |
1291 | case R_X86_64_GOTPCREL: | |
1292 | case R_X86_64_TLSGD: | |
7b81dfbb AJ |
1293 | case R_X86_64_GOT64: |
1294 | case R_X86_64_GOTPCREL64: | |
1295 | case R_X86_64_GOTPLT64: | |
67a4f2b7 AO |
1296 | case R_X86_64_GOTPC32_TLSDESC: |
1297 | case R_X86_64_TLSDESC_CALL: | |
bffbf940 JJ |
1298 | /* This symbol requires a global offset table entry. */ |
1299 | { | |
1300 | int tls_type, old_tls_type; | |
1301 | ||
1302 | switch (r_type) | |
1303 | { | |
1304 | default: tls_type = GOT_NORMAL; break; | |
1305 | case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break; | |
1306 | case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break; | |
67a4f2b7 AO |
1307 | case R_X86_64_GOTPC32_TLSDESC: |
1308 | case R_X86_64_TLSDESC_CALL: | |
1309 | tls_type = GOT_TLS_GDESC; break; | |
bffbf940 JJ |
1310 | } |
1311 | ||
1312 | if (h != NULL) | |
1313 | { | |
7b81dfbb AJ |
1314 | if (r_type == R_X86_64_GOTPLT64) |
1315 | { | |
1316 | /* This relocation indicates that we also need | |
1317 | a PLT entry, as this is a function. We don't need | |
1318 | a PLT entry for local symbols. */ | |
1319 | h->needs_plt = 1; | |
1320 | h->plt.refcount += 1; | |
1321 | } | |
bffbf940 JJ |
1322 | h->got.refcount += 1; |
1323 | old_tls_type = elf64_x86_64_hash_entry (h)->tls_type; | |
1324 | } | |
1325 | else | |
1326 | { | |
1327 | bfd_signed_vma *local_got_refcounts; | |
1328 | ||
1329 | /* This is a global offset table entry for a local symbol. */ | |
1330 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
1331 | if (local_got_refcounts == NULL) | |
1332 | { | |
1333 | bfd_size_type size; | |
1334 | ||
1335 | size = symtab_hdr->sh_info; | |
67a4f2b7 AO |
1336 | size *= sizeof (bfd_signed_vma) |
1337 | + sizeof (bfd_vma) + sizeof (char); | |
bffbf940 JJ |
1338 | local_got_refcounts = ((bfd_signed_vma *) |
1339 | bfd_zalloc (abfd, size)); | |
1340 | if (local_got_refcounts == NULL) | |
b34976b6 | 1341 | return FALSE; |
bffbf940 | 1342 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
67a4f2b7 AO |
1343 | elf64_x86_64_local_tlsdesc_gotent (abfd) |
1344 | = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info); | |
bffbf940 | 1345 | elf64_x86_64_local_got_tls_type (abfd) |
67a4f2b7 | 1346 | = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info); |
bffbf940 JJ |
1347 | } |
1348 | local_got_refcounts[r_symndx] += 1; | |
1349 | old_tls_type | |
1350 | = elf64_x86_64_local_got_tls_type (abfd) [r_symndx]; | |
1351 | } | |
1352 | ||
1353 | /* If a TLS symbol is accessed using IE at least once, | |
1354 | there is no point to use dynamic model for it. */ | |
1355 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN | |
67a4f2b7 AO |
1356 | && (! GOT_TLS_GD_ANY_P (old_tls_type) |
1357 | || tls_type != GOT_TLS_IE)) | |
bffbf940 | 1358 | { |
67a4f2b7 | 1359 | if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type)) |
bffbf940 | 1360 | tls_type = old_tls_type; |
67a4f2b7 AO |
1361 | else if (GOT_TLS_GD_ANY_P (old_tls_type) |
1362 | && GOT_TLS_GD_ANY_P (tls_type)) | |
1363 | tls_type |= old_tls_type; | |
bffbf940 JJ |
1364 | else |
1365 | { | |
1366 | (*_bfd_error_handler) | |
1f7a4e42 | 1367 | (_("%B: '%s' accessed both as normal and thread local symbol"), |
d003868e | 1368 | abfd, h ? h->root.root.string : "<local>"); |
b34976b6 | 1369 | return FALSE; |
bffbf940 JJ |
1370 | } |
1371 | } | |
1372 | ||
1373 | if (old_tls_type != tls_type) | |
1374 | { | |
1375 | if (h != NULL) | |
1376 | elf64_x86_64_hash_entry (h)->tls_type = tls_type; | |
1377 | else | |
1378 | elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
1379 | } | |
1380 | } | |
c434dee6 AJ |
1381 | /* Fall through */ |
1382 | ||
d6ab8113 JB |
1383 | case R_X86_64_GOTOFF64: |
1384 | case R_X86_64_GOTPC32: | |
7b81dfbb | 1385 | case R_X86_64_GOTPC64: |
bffbf940 | 1386 | create_got: |
6de2ae4a | 1387 | if (htab->elf.sgot == NULL) |
c434dee6 AJ |
1388 | { |
1389 | if (htab->elf.dynobj == NULL) | |
1390 | htab->elf.dynobj = abfd; | |
6de2ae4a L |
1391 | if (!_bfd_elf_create_got_section (htab->elf.dynobj, |
1392 | info)) | |
b34976b6 | 1393 | return FALSE; |
c434dee6 | 1394 | } |
70256ad8 AJ |
1395 | break; |
1396 | ||
1397 | case R_X86_64_PLT32: | |
1398 | /* This symbol requires a procedure linkage table entry. We | |
407443a3 AJ |
1399 | actually build the entry in adjust_dynamic_symbol, |
1400 | because this might be a case of linking PIC code which is | |
1401 | never referenced by a dynamic object, in which case we | |
1402 | don't need to generate a procedure linkage table entry | |
1403 | after all. */ | |
70256ad8 AJ |
1404 | |
1405 | /* If this is a local symbol, we resolve it directly without | |
407443a3 | 1406 | creating a procedure linkage table entry. */ |
70256ad8 AJ |
1407 | if (h == NULL) |
1408 | continue; | |
1409 | ||
f5385ebf | 1410 | h->needs_plt = 1; |
51b64d56 | 1411 | h->plt.refcount += 1; |
70256ad8 AJ |
1412 | break; |
1413 | ||
7b81dfbb AJ |
1414 | case R_X86_64_PLTOFF64: |
1415 | /* This tries to form the 'address' of a function relative | |
1416 | to GOT. For global symbols we need a PLT entry. */ | |
1417 | if (h != NULL) | |
1418 | { | |
1419 | h->needs_plt = 1; | |
1420 | h->plt.refcount += 1; | |
1421 | } | |
1422 | goto create_got; | |
1423 | ||
cc78d0af AJ |
1424 | case R_X86_64_8: |
1425 | case R_X86_64_16: | |
70256ad8 AJ |
1426 | case R_X86_64_32: |
1427 | case R_X86_64_32S: | |
1b71fb54 AJ |
1428 | /* Let's help debug shared library creation. These relocs |
1429 | cannot be used in shared libs. Don't error out for | |
1430 | sections we don't care about, such as debug sections or | |
1431 | non-constant sections. */ | |
1432 | if (info->shared | |
1433 | && (sec->flags & SEC_ALLOC) != 0 | |
1434 | && (sec->flags & SEC_READONLY) != 0) | |
1435 | { | |
1436 | (*_bfd_error_handler) | |
d003868e AM |
1437 | (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"), |
1438 | abfd, | |
6610a52d L |
1439 | x86_64_elf_howto_table[r_type].name, |
1440 | (h) ? h->root.root.string : "a local symbol"); | |
1b71fb54 | 1441 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 1442 | return FALSE; |
1b71fb54 AJ |
1443 | } |
1444 | /* Fall through. */ | |
1445 | ||
c434dee6 AJ |
1446 | case R_X86_64_PC8: |
1447 | case R_X86_64_PC16: | |
70256ad8 | 1448 | case R_X86_64_PC32: |
d6ab8113 | 1449 | case R_X86_64_PC64: |
1b71fb54 | 1450 | case R_X86_64_64: |
710ab287 | 1451 | if (h != NULL && info->executable) |
c434dee6 AJ |
1452 | { |
1453 | /* If this reloc is in a read-only section, we might | |
1454 | need a copy reloc. We can't check reliably at this | |
1455 | stage whether the section is read-only, as input | |
1456 | sections have not yet been mapped to output sections. | |
1457 | Tentatively set the flag for now, and correct in | |
1458 | adjust_dynamic_symbol. */ | |
f5385ebf | 1459 | h->non_got_ref = 1; |
c434dee6 AJ |
1460 | |
1461 | /* We may need a .plt entry if the function this reloc | |
1462 | refers to is in a shared lib. */ | |
1463 | h->plt.refcount += 1; | |
d6ab8113 | 1464 | if (r_type != R_X86_64_PC32 && r_type != R_X86_64_PC64) |
f5385ebf | 1465 | h->pointer_equality_needed = 1; |
c434dee6 | 1466 | } |
70256ad8 AJ |
1467 | |
1468 | /* If we are creating a shared library, and this is a reloc | |
1469 | against a global symbol, or a non PC relative reloc | |
1470 | against a local symbol, then we need to copy the reloc | |
1471 | into the shared library. However, if we are linking with | |
1472 | -Bsymbolic, we do not need to copy a reloc against a | |
1473 | global symbol which is defined in an object we are | |
407443a3 | 1474 | including in the link (i.e., DEF_REGULAR is set). At |
70256ad8 AJ |
1475 | this point we have not seen all the input files, so it is |
1476 | possible that DEF_REGULAR is not set now but will be set | |
c434dee6 AJ |
1477 | later (it is never cleared). In case of a weak definition, |
1478 | DEF_REGULAR may be cleared later by a strong definition in | |
1479 | a shared library. We account for that possibility below by | |
1480 | storing information in the relocs_copied field of the hash | |
1481 | table entry. A similar situation occurs when creating | |
1482 | shared libraries and symbol visibility changes render the | |
1483 | symbol local. | |
1484 | ||
1485 | If on the other hand, we are creating an executable, we | |
1486 | may need to keep relocations for symbols satisfied by a | |
1487 | dynamic library if we manage to avoid copy relocs for the | |
0f88be7a | 1488 | symbol. */ |
c434dee6 AJ |
1489 | if ((info->shared |
1490 | && (sec->flags & SEC_ALLOC) != 0 | |
d8045f23 | 1491 | && (! IS_X86_64_PCREL_TYPE (r_type) |
c434dee6 | 1492 | || (h != NULL |
55255dae | 1493 | && (! SYMBOLIC_BIND (info, h) |
c434dee6 | 1494 | || h->root.type == bfd_link_hash_defweak |
f5385ebf | 1495 | || !h->def_regular)))) |
d40d037c AJ |
1496 | || (ELIMINATE_COPY_RELOCS |
1497 | && !info->shared | |
c434dee6 AJ |
1498 | && (sec->flags & SEC_ALLOC) != 0 |
1499 | && h != NULL | |
1500 | && (h->root.type == bfd_link_hash_defweak | |
0f88be7a | 1501 | || !h->def_regular))) |
70256ad8 | 1502 | { |
c434dee6 AJ |
1503 | struct elf64_x86_64_dyn_relocs *p; |
1504 | struct elf64_x86_64_dyn_relocs **head; | |
1505 | ||
1506 | /* We must copy these reloc types into the output file. | |
1507 | Create a reloc section in dynobj and make room for | |
1508 | this reloc. */ | |
70256ad8 AJ |
1509 | if (sreloc == NULL) |
1510 | { | |
c434dee6 AJ |
1511 | if (htab->elf.dynobj == NULL) |
1512 | htab->elf.dynobj = abfd; | |
1513 | ||
83bac4b0 NC |
1514 | sreloc = _bfd_elf_make_dynamic_reloc_section |
1515 | (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE); | |
70256ad8 | 1516 | |
70256ad8 | 1517 | if (sreloc == NULL) |
83bac4b0 | 1518 | return FALSE; |
70256ad8 AJ |
1519 | } |
1520 | ||
c434dee6 AJ |
1521 | /* If this is a global symbol, we count the number of |
1522 | relocations we need for this symbol. */ | |
1523 | if (h != NULL) | |
70256ad8 | 1524 | { |
c434dee6 AJ |
1525 | head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs; |
1526 | } | |
1527 | else | |
1528 | { | |
e81d3500 | 1529 | void **vpp; |
c434dee6 AJ |
1530 | /* Track dynamic relocs needed for local syms too. |
1531 | We really need local syms available to do this | |
1532 | easily. Oh well. */ | |
1533 | ||
1534 | asection *s; | |
1535 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
1536 | sec, r_symndx); | |
1537 | if (s == NULL) | |
b34976b6 | 1538 | return FALSE; |
70256ad8 | 1539 | |
e81d3500 DD |
1540 | /* Beware of type punned pointers vs strict aliasing |
1541 | rules. */ | |
1542 | vpp = &(elf_section_data (s)->local_dynrel); | |
1543 | head = (struct elf64_x86_64_dyn_relocs **)vpp; | |
c434dee6 | 1544 | } |
70256ad8 | 1545 | |
c434dee6 AJ |
1546 | p = *head; |
1547 | if (p == NULL || p->sec != sec) | |
1548 | { | |
1549 | bfd_size_type amt = sizeof *p; | |
d8045f23 | 1550 | |
c434dee6 AJ |
1551 | p = ((struct elf64_x86_64_dyn_relocs *) |
1552 | bfd_alloc (htab->elf.dynobj, amt)); | |
70256ad8 | 1553 | if (p == NULL) |
b34976b6 | 1554 | return FALSE; |
c434dee6 AJ |
1555 | p->next = *head; |
1556 | *head = p; | |
1557 | p->sec = sec; | |
1558 | p->count = 0; | |
1559 | p->pc_count = 0; | |
70256ad8 | 1560 | } |
c434dee6 AJ |
1561 | |
1562 | p->count += 1; | |
d8045f23 | 1563 | if (IS_X86_64_PCREL_TYPE (r_type)) |
c434dee6 | 1564 | p->pc_count += 1; |
70256ad8 AJ |
1565 | } |
1566 | break; | |
fe4770f4 AJ |
1567 | |
1568 | /* This relocation describes the C++ object vtable hierarchy. | |
1569 | Reconstruct it for later use during GC. */ | |
1570 | case R_X86_64_GNU_VTINHERIT: | |
c152c796 | 1571 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 1572 | return FALSE; |
fe4770f4 AJ |
1573 | break; |
1574 | ||
1575 | /* This relocation describes which C++ vtable entries are actually | |
1576 | used. Record for later use during GC. */ | |
1577 | case R_X86_64_GNU_VTENTRY: | |
d17e0c6e JB |
1578 | BFD_ASSERT (h != NULL); |
1579 | if (h != NULL | |
1580 | && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 1581 | return FALSE; |
fe4770f4 | 1582 | break; |
c434dee6 AJ |
1583 | |
1584 | default: | |
1585 | break; | |
70256ad8 AJ |
1586 | } |
1587 | } | |
1588 | ||
b34976b6 | 1589 | return TRUE; |
70256ad8 AJ |
1590 | } |
1591 | ||
1592 | /* Return the section that should be marked against GC for a given | |
407443a3 | 1593 | relocation. */ |
70256ad8 AJ |
1594 | |
1595 | static asection * | |
27482721 | 1596 | elf64_x86_64_gc_mark_hook (asection *sec, |
07adf181 | 1597 | struct bfd_link_info *info, |
27482721 AJ |
1598 | Elf_Internal_Rela *rel, |
1599 | struct elf_link_hash_entry *h, | |
1600 | Elf_Internal_Sym *sym) | |
70256ad8 AJ |
1601 | { |
1602 | if (h != NULL) | |
07adf181 AM |
1603 | switch (ELF64_R_TYPE (rel->r_info)) |
1604 | { | |
1605 | case R_X86_64_GNU_VTINHERIT: | |
1606 | case R_X86_64_GNU_VTENTRY: | |
1607 | return NULL; | |
1608 | } | |
1609 | ||
1610 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
70256ad8 AJ |
1611 | } |
1612 | ||
407443a3 | 1613 | /* Update the got entry reference counts for the section being removed. */ |
70256ad8 | 1614 | |
b34976b6 | 1615 | static bfd_boolean |
27482721 | 1616 | elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, |
142411ca L |
1617 | asection *sec, |
1618 | const Elf_Internal_Rela *relocs) | |
70256ad8 AJ |
1619 | { |
1620 | Elf_Internal_Shdr *symtab_hdr; | |
1621 | struct elf_link_hash_entry **sym_hashes; | |
1622 | bfd_signed_vma *local_got_refcounts; | |
1623 | const Elf_Internal_Rela *rel, *relend; | |
c434dee6 | 1624 | |
7dda2462 TG |
1625 | if (info->relocatable) |
1626 | return TRUE; | |
1627 | ||
c434dee6 | 1628 | elf_section_data (sec)->local_dynrel = NULL; |
70256ad8 | 1629 | |
0ffa91dd | 1630 | symtab_hdr = &elf_symtab_hdr (abfd); |
70256ad8 AJ |
1631 | sym_hashes = elf_sym_hashes (abfd); |
1632 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
1633 | ||
70256ad8 AJ |
1634 | relend = relocs + sec->reloc_count; |
1635 | for (rel = relocs; rel < relend; rel++) | |
26e41594 AM |
1636 | { |
1637 | unsigned long r_symndx; | |
1638 | unsigned int r_type; | |
1639 | struct elf_link_hash_entry *h = NULL; | |
70256ad8 | 1640 | |
26e41594 AM |
1641 | r_symndx = ELF64_R_SYM (rel->r_info); |
1642 | if (r_symndx >= symtab_hdr->sh_info) | |
1643 | { | |
1644 | struct elf64_x86_64_link_hash_entry *eh; | |
1645 | struct elf64_x86_64_dyn_relocs **pp; | |
1646 | struct elf64_x86_64_dyn_relocs *p; | |
c434dee6 | 1647 | |
26e41594 | 1648 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
3eb128b2 AM |
1649 | while (h->root.type == bfd_link_hash_indirect |
1650 | || h->root.type == bfd_link_hash_warning) | |
1651 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
26e41594 | 1652 | eh = (struct elf64_x86_64_link_hash_entry *) h; |
c434dee6 | 1653 | |
26e41594 AM |
1654 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
1655 | if (p->sec == sec) | |
1656 | { | |
1657 | /* Everything must go for SEC. */ | |
1658 | *pp = p->next; | |
1659 | break; | |
1660 | } | |
1661 | } | |
c434dee6 | 1662 | |
26e41594 | 1663 | r_type = ELF64_R_TYPE (rel->r_info); |
142411ca L |
1664 | if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL, |
1665 | symtab_hdr, sym_hashes, | |
1666 | &r_type, GOT_UNKNOWN, | |
1667 | rel, relend, h)) | |
1668 | return FALSE; | |
1669 | ||
26e41594 AM |
1670 | switch (r_type) |
1671 | { | |
1672 | case R_X86_64_TLSLD: | |
1673 | if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0) | |
1674 | elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1; | |
1675 | break; | |
c434dee6 | 1676 | |
26e41594 | 1677 | case R_X86_64_TLSGD: |
67a4f2b7 AO |
1678 | case R_X86_64_GOTPC32_TLSDESC: |
1679 | case R_X86_64_TLSDESC_CALL: | |
26e41594 AM |
1680 | case R_X86_64_GOTTPOFF: |
1681 | case R_X86_64_GOT32: | |
1682 | case R_X86_64_GOTPCREL: | |
7b81dfbb AJ |
1683 | case R_X86_64_GOT64: |
1684 | case R_X86_64_GOTPCREL64: | |
1685 | case R_X86_64_GOTPLT64: | |
26e41594 AM |
1686 | if (h != NULL) |
1687 | { | |
7b81dfbb AJ |
1688 | if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0) |
1689 | h->plt.refcount -= 1; | |
26e41594 AM |
1690 | if (h->got.refcount > 0) |
1691 | h->got.refcount -= 1; | |
1692 | } | |
1693 | else if (local_got_refcounts != NULL) | |
1694 | { | |
1695 | if (local_got_refcounts[r_symndx] > 0) | |
1696 | local_got_refcounts[r_symndx] -= 1; | |
1697 | } | |
1698 | break; | |
c434dee6 | 1699 | |
26e41594 AM |
1700 | case R_X86_64_8: |
1701 | case R_X86_64_16: | |
1702 | case R_X86_64_32: | |
1703 | case R_X86_64_64: | |
1704 | case R_X86_64_32S: | |
1705 | case R_X86_64_PC8: | |
1706 | case R_X86_64_PC16: | |
1707 | case R_X86_64_PC32: | |
d6ab8113 | 1708 | case R_X86_64_PC64: |
26e41594 AM |
1709 | if (info->shared) |
1710 | break; | |
1711 | /* Fall thru */ | |
c434dee6 | 1712 | |
26e41594 | 1713 | case R_X86_64_PLT32: |
7b81dfbb | 1714 | case R_X86_64_PLTOFF64: |
26e41594 AM |
1715 | if (h != NULL) |
1716 | { | |
1717 | if (h->plt.refcount > 0) | |
1718 | h->plt.refcount -= 1; | |
1719 | } | |
1720 | break; | |
70256ad8 | 1721 | |
26e41594 AM |
1722 | default: |
1723 | break; | |
1724 | } | |
1725 | } | |
70256ad8 | 1726 | |
b34976b6 | 1727 | return TRUE; |
70256ad8 AJ |
1728 | } |
1729 | ||
1730 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
1731 | regular object. The current definition is in some section of the | |
1732 | dynamic object, but we're not including those sections. We have to | |
1733 | change the definition to something the rest of the link can | |
407443a3 | 1734 | understand. */ |
70256ad8 | 1735 | |
b34976b6 | 1736 | static bfd_boolean |
27482721 AJ |
1737 | elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info, |
1738 | struct elf_link_hash_entry *h) | |
70256ad8 | 1739 | { |
c434dee6 | 1740 | struct elf64_x86_64_link_hash_table *htab; |
70256ad8 | 1741 | asection *s; |
70256ad8 | 1742 | |
cbe950e9 L |
1743 | /* STT_GNU_IFUNC symbol must go through PLT. */ |
1744 | if (h->type == STT_GNU_IFUNC) | |
1745 | { | |
1746 | if (h->plt.refcount <= 0) | |
1747 | { | |
1748 | h->plt.offset = (bfd_vma) -1; | |
1749 | h->needs_plt = 0; | |
1750 | } | |
1751 | return TRUE; | |
1752 | } | |
1753 | ||
70256ad8 AJ |
1754 | /* If this is a function, put it in the procedure linkage table. We |
1755 | will fill in the contents of the procedure linkage table later, | |
1756 | when we know the address of the .got section. */ | |
1757 | if (h->type == STT_FUNC | |
f5385ebf | 1758 | || h->needs_plt) |
70256ad8 | 1759 | { |
c434dee6 | 1760 | if (h->plt.refcount <= 0 |
27482721 AJ |
1761 | || SYMBOL_CALLS_LOCAL (info, h) |
1762 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
1763 | && h->root.type == bfd_link_hash_undefweak)) | |
70256ad8 | 1764 | { |
70256ad8 AJ |
1765 | /* This case can occur if we saw a PLT32 reloc in an input |
1766 | file, but the symbol was never referred to by a dynamic | |
1767 | object, or if all references were garbage collected. In | |
1768 | such a case, we don't actually need to build a procedure | |
1769 | linkage table, and we can just do a PC32 reloc instead. */ | |
70256ad8 | 1770 | h->plt.offset = (bfd_vma) -1; |
f5385ebf | 1771 | h->needs_plt = 0; |
70256ad8 AJ |
1772 | } |
1773 | ||
b34976b6 | 1774 | return TRUE; |
70256ad8 | 1775 | } |
bbd7ec4a | 1776 | else |
c434dee6 AJ |
1777 | /* It's possible that we incorrectly decided a .plt reloc was |
1778 | needed for an R_X86_64_PC32 reloc to a non-function sym in | |
1779 | check_relocs. We can't decide accurately between function and | |
1780 | non-function syms in check-relocs; Objects loaded later in | |
1781 | the link may change h->type. So fix it now. */ | |
bbd7ec4a | 1782 | h->plt.offset = (bfd_vma) -1; |
70256ad8 AJ |
1783 | |
1784 | /* If this is a weak symbol, and there is a real definition, the | |
1785 | processor independent code will have arranged for us to see the | |
407443a3 | 1786 | real definition first, and we can just use the same value. */ |
f6e332e6 | 1787 | if (h->u.weakdef != NULL) |
70256ad8 | 1788 | { |
f6e332e6 AM |
1789 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
1790 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
1791 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
1792 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
d40d037c | 1793 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) |
f6e332e6 | 1794 | h->non_got_ref = h->u.weakdef->non_got_ref; |
b34976b6 | 1795 | return TRUE; |
70256ad8 AJ |
1796 | } |
1797 | ||
1798 | /* This is a reference to a symbol defined by a dynamic object which | |
407443a3 | 1799 | is not a function. */ |
70256ad8 AJ |
1800 | |
1801 | /* If we are creating a shared library, we must presume that the | |
1802 | only references to the symbol are via the global offset table. | |
1803 | For such cases we need not do anything here; the relocations will | |
407443a3 | 1804 | be handled correctly by relocate_section. */ |
70256ad8 | 1805 | if (info->shared) |
b34976b6 | 1806 | return TRUE; |
70256ad8 AJ |
1807 | |
1808 | /* If there are no references to this symbol that do not use the | |
1809 | GOT, we don't need to generate a copy reloc. */ | |
f5385ebf | 1810 | if (!h->non_got_ref) |
b34976b6 | 1811 | return TRUE; |
70256ad8 | 1812 | |
c434dee6 AJ |
1813 | /* If -z nocopyreloc was given, we won't generate them either. */ |
1814 | if (info->nocopyreloc) | |
1815 | { | |
f5385ebf | 1816 | h->non_got_ref = 0; |
b34976b6 | 1817 | return TRUE; |
c434dee6 AJ |
1818 | } |
1819 | ||
d40d037c | 1820 | if (ELIMINATE_COPY_RELOCS) |
c434dee6 | 1821 | { |
d40d037c AJ |
1822 | struct elf64_x86_64_link_hash_entry * eh; |
1823 | struct elf64_x86_64_dyn_relocs *p; | |
c434dee6 | 1824 | |
d40d037c AJ |
1825 | eh = (struct elf64_x86_64_link_hash_entry *) h; |
1826 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
1827 | { | |
1828 | s = p->sec->output_section; | |
1829 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
1830 | break; | |
1831 | } | |
1832 | ||
1833 | /* If we didn't find any dynamic relocs in read-only sections, then | |
1834 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
1835 | if (p == NULL) | |
1836 | { | |
f5385ebf | 1837 | h->non_got_ref = 0; |
d40d037c AJ |
1838 | return TRUE; |
1839 | } | |
c434dee6 AJ |
1840 | } |
1841 | ||
909272ee AM |
1842 | if (h->size == 0) |
1843 | { | |
1844 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
1845 | h->root.root.string); | |
1846 | return TRUE; | |
1847 | } | |
1848 | ||
70256ad8 | 1849 | /* We must allocate the symbol in our .dynbss section, which will |
407443a3 | 1850 | become part of the .bss section of the executable. There will be |
70256ad8 AJ |
1851 | an entry for this symbol in the .dynsym section. The dynamic |
1852 | object will contain position independent code, so all references | |
1853 | from the dynamic object to this symbol will go through the global | |
1854 | offset table. The dynamic linker will use the .dynsym entry to | |
1855 | determine the address it must put in the global offset table, so | |
1856 | both the dynamic object and the regular object will refer to the | |
1857 | same memory location for the variable. */ | |
1858 | ||
c434dee6 | 1859 | htab = elf64_x86_64_hash_table (info); |
70256ad8 AJ |
1860 | |
1861 | /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker | |
1862 | to copy the initial value out of the dynamic object and into the | |
cedb70c5 | 1863 | runtime process image. */ |
70256ad8 AJ |
1864 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
1865 | { | |
eea6121a | 1866 | htab->srelbss->size += sizeof (Elf64_External_Rela); |
f5385ebf | 1867 | h->needs_copy = 1; |
70256ad8 AJ |
1868 | } |
1869 | ||
c434dee6 | 1870 | s = htab->sdynbss; |
70256ad8 | 1871 | |
027297b7 | 1872 | return _bfd_elf_adjust_dynamic_copy (h, s); |
70256ad8 AJ |
1873 | } |
1874 | ||
c434dee6 AJ |
1875 | /* Allocate space in .plt, .got and associated reloc sections for |
1876 | dynamic relocs. */ | |
1877 | ||
b34976b6 | 1878 | static bfd_boolean |
eb4ff4d6 | 1879 | elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
c434dee6 AJ |
1880 | { |
1881 | struct bfd_link_info *info; | |
1882 | struct elf64_x86_64_link_hash_table *htab; | |
1883 | struct elf64_x86_64_link_hash_entry *eh; | |
1884 | struct elf64_x86_64_dyn_relocs *p; | |
1885 | ||
e92d460e | 1886 | if (h->root.type == bfd_link_hash_indirect) |
b34976b6 | 1887 | return TRUE; |
c434dee6 | 1888 | |
e92d460e AM |
1889 | if (h->root.type == bfd_link_hash_warning) |
1890 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
cbe950e9 | 1891 | eh = (struct elf64_x86_64_link_hash_entry *) h; |
e92d460e | 1892 | |
c434dee6 AJ |
1893 | info = (struct bfd_link_info *) inf; |
1894 | htab = elf64_x86_64_hash_table (info); | |
1895 | ||
cbe950e9 L |
1896 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
1897 | here if it is defined and referenced in a non-shared object. */ | |
1898 | if (h->type == STT_GNU_IFUNC | |
1899 | && h->def_regular) | |
1900 | { | |
1901 | asection *plt, *gotplt, *relplt; | |
1902 | ||
44c4ea11 | 1903 | /* When a shared library references a STT_GNU_IFUNC symbol |
188dbb07 L |
1904 | defined in executable, the address of the resolved function |
1905 | may be used. But in non-shared executable, the address of | |
1906 | its .plt slot may be used. Pointer equality may not work | |
1907 | correctly. PIE should be used if pointer equality is | |
1908 | required here. */ | |
44c4ea11 L |
1909 | if (!info->shared |
1910 | && (h->dynindx != -1 | |
1911 | || info->export_dynamic) | |
1912 | && h->pointer_equality_needed) | |
1913 | { | |
1914 | info->callbacks->einfo | |
eba077f2 | 1915 | (_("%F%P: dynamic STT_GNU_IFUNC symbol `%s' with pointer " |
44c4ea11 L |
1916 | "equality in `%B' can not be used when making an " |
1917 | "executable; recompile with -fPIE and relink with -pie\n"), | |
1918 | h->root.root.string, | |
1919 | h->root.u.def.section->owner); | |
1920 | bfd_set_error (bfd_error_bad_value); | |
1921 | return FALSE; | |
1922 | } | |
1923 | ||
cbe950e9 L |
1924 | /* Return and discard space for dynamic relocations against it if |
1925 | it is never referenced in a non-shared object. */ | |
1926 | if (!h->ref_regular) | |
1927 | { | |
1928 | if (h->plt.refcount > 0 | |
1929 | || h->got.refcount > 0) | |
1930 | abort (); | |
1931 | h->got.offset = (bfd_vma) -1; | |
1932 | eh->dyn_relocs = NULL; | |
1933 | return TRUE; | |
1934 | } | |
1935 | ||
cbe950e9 L |
1936 | /* When building a static executable, use .iplt, .igot.plt and |
1937 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
6de2ae4a | 1938 | if (htab->elf.splt != NULL) |
cbe950e9 | 1939 | { |
6de2ae4a L |
1940 | plt = htab->elf.splt; |
1941 | gotplt = htab->elf.sgotplt; | |
1942 | relplt = htab->elf.srelplt; | |
cbe950e9 L |
1943 | |
1944 | /* If this is the first .plt entry, make room for the special | |
1945 | first entry. */ | |
1946 | if (plt->size == 0) | |
1947 | plt->size += PLT_ENTRY_SIZE; | |
1948 | } | |
1949 | else | |
1950 | { | |
6de2ae4a L |
1951 | plt = htab->elf.iplt; |
1952 | gotplt = htab->elf.igotplt; | |
1953 | relplt = htab->elf.irelplt; | |
cbe950e9 L |
1954 | } |
1955 | ||
1956 | /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need | |
1957 | the original value for R_X86_64_IRELATIVE. */ | |
1958 | h->plt.offset = plt->size; | |
1959 | ||
1960 | /* Make room for this entry in the .plt/.iplt section. */ | |
1961 | plt->size += PLT_ENTRY_SIZE; | |
1962 | ||
1963 | /* We also need to make an entry in the .got.plt/.got.iplt | |
1964 | section, which will be placed in the .got section by the | |
1965 | linker script. */ | |
1966 | gotplt->size += GOT_ENTRY_SIZE; | |
1967 | ||
1968 | /* We also need to make an entry in the .rela.plt/.rela.iplt | |
1969 | section. */ | |
1970 | relplt->size += sizeof (Elf64_External_Rela); | |
1971 | relplt->reloc_count++; | |
1972 | ||
710ab287 L |
1973 | /* We need dynamic relocation for STT_GNU_IFUNC symbol only |
1974 | when there is a non-GOT reference in a shared object. */ | |
1975 | if (!info->shared | |
1976 | || !h->non_got_ref) | |
cbe950e9 L |
1977 | eh->dyn_relocs = NULL; |
1978 | ||
710ab287 L |
1979 | /* Finally, allocate space. */ |
1980 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6de2ae4a L |
1981 | htab->elf.irelifunc->size |
1982 | += p->count * sizeof (Elf64_External_Rela); | |
710ab287 L |
1983 | |
1984 | /* For STT_GNU_IFUNC symbol, .got.plt has the real function | |
1985 | addres and .got has the PLT entry adddress. We will load | |
1986 | the GOT entry with the PLT entry in finish_dynamic_symbol if | |
1987 | it is used. For branch, it uses .got.plt. For symbol value, | |
1988 | 1. Use .got.plt in a shared object if it is forced local or | |
1989 | not dynamic. | |
1990 | 2. Use .got.plt in a non-shared object if pointer equality | |
1991 | isn't needed. | |
44c4ea11 L |
1992 | 3. Use .got.plt in PIE. |
1993 | 4. Use .got.plt if .got isn't used. | |
1994 | 5. Otherwise use .got so that it can be shared among different | |
710ab287 L |
1995 | objects at run-time. |
1996 | We only need to relocate .got entry in shared object. */ | |
1997 | if ((info->shared | |
1998 | && (h->dynindx == -1 | |
1999 | || h->forced_local)) | |
2000 | || (!info->shared | |
2001 | && !h->pointer_equality_needed) | |
44c4ea11 | 2002 | || (info->executable && info->shared) |
6de2ae4a | 2003 | || htab->elf.sgot == NULL) |
710ab287 L |
2004 | { |
2005 | /* Use .got.plt. */ | |
2006 | h->got.offset = (bfd_vma) -1; | |
2007 | } | |
2008 | else | |
2009 | { | |
6de2ae4a L |
2010 | h->got.offset = htab->elf.sgot->size; |
2011 | htab->elf.sgot->size += GOT_ENTRY_SIZE; | |
710ab287 | 2012 | if (info->shared) |
6de2ae4a | 2013 | htab->elf.srelgot->size += sizeof (Elf64_External_Rela); |
0018b0a3 | 2014 | } |
710ab287 L |
2015 | |
2016 | return TRUE; | |
cbe950e9 L |
2017 | } |
2018 | else if (htab->elf.dynamic_sections_created | |
2019 | && h->plt.refcount > 0) | |
c434dee6 AJ |
2020 | { |
2021 | /* Make sure this symbol is output as a dynamic symbol. | |
2022 | Undefined weak syms won't yet be marked as dynamic. */ | |
2023 | if (h->dynindx == -1 | |
f5385ebf | 2024 | && !h->forced_local) |
c434dee6 | 2025 | { |
c152c796 | 2026 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 2027 | return FALSE; |
c434dee6 AJ |
2028 | } |
2029 | ||
27482721 AJ |
2030 | if (info->shared |
2031 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) | |
c434dee6 | 2032 | { |
6de2ae4a | 2033 | asection *s = htab->elf.splt; |
c434dee6 AJ |
2034 | |
2035 | /* If this is the first .plt entry, make room for the special | |
2036 | first entry. */ | |
eea6121a AM |
2037 | if (s->size == 0) |
2038 | s->size += PLT_ENTRY_SIZE; | |
c434dee6 | 2039 | |
eea6121a | 2040 | h->plt.offset = s->size; |
c434dee6 AJ |
2041 | |
2042 | /* If this symbol is not defined in a regular file, and we are | |
2043 | not generating a shared library, then set the symbol to this | |
2044 | location in the .plt. This is required to make function | |
2045 | pointers compare as equal between the normal executable and | |
2046 | the shared library. */ | |
2047 | if (! info->shared | |
f5385ebf | 2048 | && !h->def_regular) |
c434dee6 AJ |
2049 | { |
2050 | h->root.u.def.section = s; | |
2051 | h->root.u.def.value = h->plt.offset; | |
2052 | } | |
2053 | ||
2054 | /* Make room for this entry. */ | |
eea6121a | 2055 | s->size += PLT_ENTRY_SIZE; |
c434dee6 AJ |
2056 | |
2057 | /* We also need to make an entry in the .got.plt section, which | |
2058 | will be placed in the .got section by the linker script. */ | |
6de2ae4a | 2059 | htab->elf.sgotplt->size += GOT_ENTRY_SIZE; |
c434dee6 AJ |
2060 | |
2061 | /* We also need to make an entry in the .rela.plt section. */ | |
6de2ae4a L |
2062 | htab->elf.srelplt->size += sizeof (Elf64_External_Rela); |
2063 | htab->elf.srelplt->reloc_count++; | |
c434dee6 AJ |
2064 | } |
2065 | else | |
2066 | { | |
2067 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 2068 | h->needs_plt = 0; |
c434dee6 AJ |
2069 | } |
2070 | } | |
2071 | else | |
2072 | { | |
2073 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 2074 | h->needs_plt = 0; |
c434dee6 AJ |
2075 | } |
2076 | ||
67a4f2b7 AO |
2077 | eh->tlsdesc_got = (bfd_vma) -1; |
2078 | ||
bffbf940 JJ |
2079 | /* If R_X86_64_GOTTPOFF symbol is now local to the binary, |
2080 | make it a R_X86_64_TPOFF32 requiring no GOT entry. */ | |
2081 | if (h->got.refcount > 0 | |
2082 | && !info->shared | |
2083 | && h->dynindx == -1 | |
2084 | && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE) | |
d8045f23 NC |
2085 | { |
2086 | h->got.offset = (bfd_vma) -1; | |
2087 | } | |
bffbf940 | 2088 | else if (h->got.refcount > 0) |
c434dee6 AJ |
2089 | { |
2090 | asection *s; | |
b34976b6 | 2091 | bfd_boolean dyn; |
bffbf940 | 2092 | int tls_type = elf64_x86_64_hash_entry (h)->tls_type; |
c434dee6 AJ |
2093 | |
2094 | /* Make sure this symbol is output as a dynamic symbol. | |
2095 | Undefined weak syms won't yet be marked as dynamic. */ | |
2096 | if (h->dynindx == -1 | |
f5385ebf | 2097 | && !h->forced_local) |
c434dee6 | 2098 | { |
c152c796 | 2099 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
b34976b6 | 2100 | return FALSE; |
c434dee6 AJ |
2101 | } |
2102 | ||
67a4f2b7 AO |
2103 | if (GOT_TLS_GDESC_P (tls_type)) |
2104 | { | |
6de2ae4a | 2105 | eh->tlsdesc_got = htab->elf.sgotplt->size |
67a4f2b7 | 2106 | - elf64_x86_64_compute_jump_table_size (htab); |
6de2ae4a | 2107 | htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE; |
67a4f2b7 AO |
2108 | h->got.offset = (bfd_vma) -2; |
2109 | } | |
2110 | if (! GOT_TLS_GDESC_P (tls_type) | |
2111 | || GOT_TLS_GD_P (tls_type)) | |
2112 | { | |
6de2ae4a | 2113 | s = htab->elf.sgot; |
67a4f2b7 AO |
2114 | h->got.offset = s->size; |
2115 | s->size += GOT_ENTRY_SIZE; | |
2116 | if (GOT_TLS_GD_P (tls_type)) | |
2117 | s->size += GOT_ENTRY_SIZE; | |
2118 | } | |
c434dee6 | 2119 | dyn = htab->elf.dynamic_sections_created; |
bffbf940 JJ |
2120 | /* R_X86_64_TLSGD needs one dynamic relocation if local symbol |
2121 | and two if global. | |
2122 | R_X86_64_GOTTPOFF needs one dynamic relocation. */ | |
67a4f2b7 | 2123 | if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1) |
bffbf940 | 2124 | || tls_type == GOT_TLS_IE) |
6de2ae4a | 2125 | htab->elf.srelgot->size += sizeof (Elf64_External_Rela); |
67a4f2b7 | 2126 | else if (GOT_TLS_GD_P (tls_type)) |
6de2ae4a | 2127 | htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela); |
67a4f2b7 AO |
2128 | else if (! GOT_TLS_GDESC_P (tls_type) |
2129 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
2130 | || h->root.type != bfd_link_hash_undefweak) | |
27482721 AJ |
2131 | && (info->shared |
2132 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
6de2ae4a | 2133 | htab->elf.srelgot->size += sizeof (Elf64_External_Rela); |
67a4f2b7 AO |
2134 | if (GOT_TLS_GDESC_P (tls_type)) |
2135 | { | |
6de2ae4a | 2136 | htab->elf.srelplt->size += sizeof (Elf64_External_Rela); |
67a4f2b7 AO |
2137 | htab->tlsdesc_plt = (bfd_vma) -1; |
2138 | } | |
c434dee6 AJ |
2139 | } |
2140 | else | |
2141 | h->got.offset = (bfd_vma) -1; | |
2142 | ||
c434dee6 | 2143 | if (eh->dyn_relocs == NULL) |
b34976b6 | 2144 | return TRUE; |
c434dee6 AJ |
2145 | |
2146 | /* In the shared -Bsymbolic case, discard space allocated for | |
2147 | dynamic pc-relative relocs against symbols which turn out to be | |
2148 | defined in regular objects. For the normal shared case, discard | |
2149 | space for pc-relative relocs that have become local due to symbol | |
2150 | visibility changes. */ | |
2151 | ||
2152 | if (info->shared) | |
2153 | { | |
27482721 AJ |
2154 | /* Relocs that use pc_count are those that appear on a call |
2155 | insn, or certain REL relocs that can generated via assembly. | |
2156 | We want calls to protected symbols to resolve directly to the | |
2157 | function rather than going via the plt. If people want | |
2158 | function pointer comparisons to work as expected then they | |
2159 | should avoid writing weird assembly. */ | |
2160 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
c434dee6 AJ |
2161 | { |
2162 | struct elf64_x86_64_dyn_relocs **pp; | |
2163 | ||
2164 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
2165 | { | |
2166 | p->count -= p->pc_count; | |
2167 | p->pc_count = 0; | |
2168 | if (p->count == 0) | |
2169 | *pp = p->next; | |
2170 | else | |
2171 | pp = &p->next; | |
2172 | } | |
2173 | } | |
4e795f50 AM |
2174 | |
2175 | /* Also discard relocs on undefined weak syms with non-default | |
2176 | visibility. */ | |
22d606e9 | 2177 | if (eh->dyn_relocs != NULL |
4e795f50 | 2178 | && h->root.type == bfd_link_hash_undefweak) |
22d606e9 AM |
2179 | { |
2180 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
2181 | eh->dyn_relocs = NULL; | |
2182 | ||
2183 | /* Make sure undefined weak symbols are output as a dynamic | |
2184 | symbol in PIEs. */ | |
2185 | else if (h->dynindx == -1 | |
d8045f23 NC |
2186 | && ! h->forced_local |
2187 | && ! bfd_elf_link_record_dynamic_symbol (info, h)) | |
2188 | return FALSE; | |
22d606e9 | 2189 | } |
cbe950e9 | 2190 | |
d8045f23 | 2191 | } |
d40d037c | 2192 | else if (ELIMINATE_COPY_RELOCS) |
c434dee6 AJ |
2193 | { |
2194 | /* For the non-shared case, discard space for relocs against | |
2195 | symbols which turn out to need copy relocs or are not | |
2196 | dynamic. */ | |
2197 | ||
f5385ebf AM |
2198 | if (!h->non_got_ref |
2199 | && ((h->def_dynamic | |
2200 | && !h->def_regular) | |
c434dee6 AJ |
2201 | || (htab->elf.dynamic_sections_created |
2202 | && (h->root.type == bfd_link_hash_undefweak | |
2203 | || h->root.type == bfd_link_hash_undefined)))) | |
2204 | { | |
2205 | /* Make sure this symbol is output as a dynamic symbol. | |
2206 | Undefined weak syms won't yet be marked as dynamic. */ | |
2207 | if (h->dynindx == -1 | |
d8045f23 NC |
2208 | && ! h->forced_local |
2209 | && ! bfd_elf_link_record_dynamic_symbol (info, h)) | |
2210 | return FALSE; | |
c434dee6 AJ |
2211 | |
2212 | /* If that succeeded, we know we'll be keeping all the | |
2213 | relocs. */ | |
2214 | if (h->dynindx != -1) | |
2215 | goto keep; | |
2216 | } | |
2217 | ||
2218 | eh->dyn_relocs = NULL; | |
2219 | ||
2220 | keep: ; | |
2221 | } | |
2222 | ||
2223 | /* Finally, allocate space. */ | |
2224 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
2225 | { | |
e7c33416 NC |
2226 | asection * sreloc; |
2227 | ||
cbe950e9 | 2228 | sreloc = elf_section_data (p->sec)->sreloc; |
e7c33416 NC |
2229 | |
2230 | BFD_ASSERT (sreloc != NULL); | |
2231 | ||
eea6121a | 2232 | sreloc->size += p->count * sizeof (Elf64_External_Rela); |
c434dee6 AJ |
2233 | } |
2234 | ||
b34976b6 | 2235 | return TRUE; |
c434dee6 AJ |
2236 | } |
2237 | ||
c25bc9fc L |
2238 | /* Allocate space in .plt, .got and associated reloc sections for |
2239 | local dynamic relocs. */ | |
2240 | ||
2241 | static bfd_boolean | |
2242 | elf64_x86_64_allocate_local_dynrelocs (void **slot, void *inf) | |
2243 | { | |
2244 | struct elf_link_hash_entry *h | |
2245 | = (struct elf_link_hash_entry *) *slot; | |
2246 | ||
2247 | if (h->type != STT_GNU_IFUNC | |
2248 | || !h->def_regular | |
2249 | || !h->ref_regular | |
2250 | || !h->forced_local | |
2251 | || h->root.type != bfd_link_hash_defined) | |
2252 | abort (); | |
2253 | ||
2254 | return elf64_x86_64_allocate_dynrelocs (h, inf); | |
2255 | } | |
2256 | ||
c434dee6 AJ |
2257 | /* Find any dynamic relocs that apply to read-only sections. */ |
2258 | ||
b34976b6 | 2259 | static bfd_boolean |
eb4ff4d6 | 2260 | elf64_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
c434dee6 AJ |
2261 | { |
2262 | struct elf64_x86_64_link_hash_entry *eh; | |
2263 | struct elf64_x86_64_dyn_relocs *p; | |
2264 | ||
e92d460e AM |
2265 | if (h->root.type == bfd_link_hash_warning) |
2266 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2267 | ||
c434dee6 AJ |
2268 | eh = (struct elf64_x86_64_link_hash_entry *) h; |
2269 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
2270 | { | |
2271 | asection *s = p->sec->output_section; | |
2272 | ||
2273 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
2274 | { | |
2275 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
2276 | ||
2277 | info->flags |= DF_TEXTREL; | |
2278 | ||
2279 | /* Not an error, just cut short the traversal. */ | |
b34976b6 | 2280 | return FALSE; |
c434dee6 AJ |
2281 | } |
2282 | } | |
b34976b6 | 2283 | return TRUE; |
c434dee6 AJ |
2284 | } |
2285 | ||
70256ad8 AJ |
2286 | /* Set the sizes of the dynamic sections. */ |
2287 | ||
b34976b6 | 2288 | static bfd_boolean |
27482721 AJ |
2289 | elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
2290 | struct bfd_link_info *info) | |
70256ad8 | 2291 | { |
c434dee6 | 2292 | struct elf64_x86_64_link_hash_table *htab; |
70256ad8 AJ |
2293 | bfd *dynobj; |
2294 | asection *s; | |
b34976b6 | 2295 | bfd_boolean relocs; |
c434dee6 | 2296 | bfd *ibfd; |
70256ad8 | 2297 | |
c434dee6 AJ |
2298 | htab = elf64_x86_64_hash_table (info); |
2299 | dynobj = htab->elf.dynobj; | |
2300 | if (dynobj == NULL) | |
2301 | abort (); | |
70256ad8 | 2302 | |
c434dee6 | 2303 | if (htab->elf.dynamic_sections_created) |
70256ad8 AJ |
2304 | { |
2305 | /* Set the contents of the .interp section to the interpreter. */ | |
36af4a4e | 2306 | if (info->executable) |
70256ad8 AJ |
2307 | { |
2308 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
c434dee6 AJ |
2309 | if (s == NULL) |
2310 | abort (); | |
eea6121a | 2311 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
70256ad8 AJ |
2312 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
2313 | } | |
2314 | } | |
70256ad8 | 2315 | |
c434dee6 AJ |
2316 | /* Set up .got offsets for local syms, and space for local dynamic |
2317 | relocs. */ | |
2318 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
70256ad8 | 2319 | { |
c434dee6 AJ |
2320 | bfd_signed_vma *local_got; |
2321 | bfd_signed_vma *end_local_got; | |
bffbf940 | 2322 | char *local_tls_type; |
67a4f2b7 | 2323 | bfd_vma *local_tlsdesc_gotent; |
c434dee6 AJ |
2324 | bfd_size_type locsymcount; |
2325 | Elf_Internal_Shdr *symtab_hdr; | |
2326 | asection *srel; | |
70256ad8 | 2327 | |
0ffa91dd | 2328 | if (! is_x86_64_elf (ibfd)) |
70256ad8 AJ |
2329 | continue; |
2330 | ||
c434dee6 | 2331 | for (s = ibfd->sections; s != NULL; s = s->next) |
70256ad8 | 2332 | { |
c434dee6 AJ |
2333 | struct elf64_x86_64_dyn_relocs *p; |
2334 | ||
e81d3500 DD |
2335 | for (p = (struct elf64_x86_64_dyn_relocs *) |
2336 | (elf_section_data (s)->local_dynrel); | |
c434dee6 AJ |
2337 | p != NULL; |
2338 | p = p->next) | |
70256ad8 | 2339 | { |
c434dee6 AJ |
2340 | if (!bfd_is_abs_section (p->sec) |
2341 | && bfd_is_abs_section (p->sec->output_section)) | |
2342 | { | |
2343 | /* Input section has been discarded, either because | |
2344 | it is a copy of a linkonce section or due to | |
2345 | linker script /DISCARD/, so we'll be discarding | |
2346 | the relocs too. */ | |
2347 | } | |
2348 | else if (p->count != 0) | |
2349 | { | |
2350 | srel = elf_section_data (p->sec)->sreloc; | |
eea6121a | 2351 | srel->size += p->count * sizeof (Elf64_External_Rela); |
c434dee6 AJ |
2352 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
2353 | info->flags |= DF_TEXTREL; | |
c434dee6 | 2354 | } |
70256ad8 AJ |
2355 | } |
2356 | } | |
c434dee6 AJ |
2357 | |
2358 | local_got = elf_local_got_refcounts (ibfd); | |
2359 | if (!local_got) | |
2360 | continue; | |
2361 | ||
0ffa91dd | 2362 | symtab_hdr = &elf_symtab_hdr (ibfd); |
c434dee6 AJ |
2363 | locsymcount = symtab_hdr->sh_info; |
2364 | end_local_got = local_got + locsymcount; | |
bffbf940 | 2365 | local_tls_type = elf64_x86_64_local_got_tls_type (ibfd); |
67a4f2b7 | 2366 | local_tlsdesc_gotent = elf64_x86_64_local_tlsdesc_gotent (ibfd); |
6de2ae4a L |
2367 | s = htab->elf.sgot; |
2368 | srel = htab->elf.srelgot; | |
67a4f2b7 AO |
2369 | for (; local_got < end_local_got; |
2370 | ++local_got, ++local_tls_type, ++local_tlsdesc_gotent) | |
70256ad8 | 2371 | { |
67a4f2b7 | 2372 | *local_tlsdesc_gotent = (bfd_vma) -1; |
c434dee6 | 2373 | if (*local_got > 0) |
70256ad8 | 2374 | { |
67a4f2b7 AO |
2375 | if (GOT_TLS_GDESC_P (*local_tls_type)) |
2376 | { | |
6de2ae4a | 2377 | *local_tlsdesc_gotent = htab->elf.sgotplt->size |
67a4f2b7 | 2378 | - elf64_x86_64_compute_jump_table_size (htab); |
6de2ae4a | 2379 | htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE; |
67a4f2b7 AO |
2380 | *local_got = (bfd_vma) -2; |
2381 | } | |
2382 | if (! GOT_TLS_GDESC_P (*local_tls_type) | |
2383 | || GOT_TLS_GD_P (*local_tls_type)) | |
2384 | { | |
2385 | *local_got = s->size; | |
2386 | s->size += GOT_ENTRY_SIZE; | |
2387 | if (GOT_TLS_GD_P (*local_tls_type)) | |
2388 | s->size += GOT_ENTRY_SIZE; | |
2389 | } | |
bffbf940 | 2390 | if (info->shared |
67a4f2b7 | 2391 | || GOT_TLS_GD_ANY_P (*local_tls_type) |
bffbf940 | 2392 | || *local_tls_type == GOT_TLS_IE) |
67a4f2b7 AO |
2393 | { |
2394 | if (GOT_TLS_GDESC_P (*local_tls_type)) | |
2395 | { | |
6de2ae4a L |
2396 | htab->elf.srelplt->size |
2397 | += sizeof (Elf64_External_Rela); | |
67a4f2b7 AO |
2398 | htab->tlsdesc_plt = (bfd_vma) -1; |
2399 | } | |
2400 | if (! GOT_TLS_GDESC_P (*local_tls_type) | |
2401 | || GOT_TLS_GD_P (*local_tls_type)) | |
2402 | srel->size += sizeof (Elf64_External_Rela); | |
2403 | } | |
70256ad8 AJ |
2404 | } |
2405 | else | |
c434dee6 AJ |
2406 | *local_got = (bfd_vma) -1; |
2407 | } | |
2408 | } | |
70256ad8 | 2409 | |
bffbf940 JJ |
2410 | if (htab->tls_ld_got.refcount > 0) |
2411 | { | |
2412 | /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD | |
2413 | relocs. */ | |
6de2ae4a L |
2414 | htab->tls_ld_got.offset = htab->elf.sgot->size; |
2415 | htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE; | |
2416 | htab->elf.srelgot->size += sizeof (Elf64_External_Rela); | |
bffbf940 JJ |
2417 | } |
2418 | else | |
2419 | htab->tls_ld_got.offset = -1; | |
2420 | ||
c434dee6 AJ |
2421 | /* Allocate global sym .plt and .got entries, and space for global |
2422 | sym dynamic relocs. */ | |
eb4ff4d6 L |
2423 | elf_link_hash_traverse (&htab->elf, elf64_x86_64_allocate_dynrelocs, |
2424 | info); | |
c434dee6 | 2425 | |
c25bc9fc L |
2426 | /* Allocate .plt and .got entries, and space for local symbols. */ |
2427 | htab_traverse (htab->loc_hash_table, | |
2428 | elf64_x86_64_allocate_local_dynrelocs, | |
2429 | info); | |
2430 | ||
67a4f2b7 AO |
2431 | /* For every jump slot reserved in the sgotplt, reloc_count is |
2432 | incremented. However, when we reserve space for TLS descriptors, | |
2433 | it's not incremented, so in order to compute the space reserved | |
2434 | for them, it suffices to multiply the reloc count by the jump | |
2435 | slot size. */ | |
6de2ae4a | 2436 | if (htab->elf.srelplt) |
67a4f2b7 AO |
2437 | htab->sgotplt_jump_table_size |
2438 | = elf64_x86_64_compute_jump_table_size (htab); | |
2439 | ||
2440 | if (htab->tlsdesc_plt) | |
2441 | { | |
2442 | /* If we're not using lazy TLS relocations, don't generate the | |
2443 | PLT and GOT entries they require. */ | |
2444 | if ((info->flags & DF_BIND_NOW)) | |
2445 | htab->tlsdesc_plt = 0; | |
2446 | else | |
2447 | { | |
6de2ae4a L |
2448 | htab->tlsdesc_got = htab->elf.sgot->size; |
2449 | htab->elf.sgot->size += GOT_ENTRY_SIZE; | |
67a4f2b7 AO |
2450 | /* Reserve room for the initial entry. |
2451 | FIXME: we could probably do away with it in this case. */ | |
6de2ae4a L |
2452 | if (htab->elf.splt->size == 0) |
2453 | htab->elf.splt->size += PLT_ENTRY_SIZE; | |
2454 | htab->tlsdesc_plt = htab->elf.splt->size; | |
2455 | htab->elf.splt->size += PLT_ENTRY_SIZE; | |
67a4f2b7 AO |
2456 | } |
2457 | } | |
2458 | ||
c434dee6 AJ |
2459 | /* We now have determined the sizes of the various dynamic sections. |
2460 | Allocate memory for them. */ | |
b34976b6 | 2461 | relocs = FALSE; |
c434dee6 AJ |
2462 | for (s = dynobj->sections; s != NULL; s = s->next) |
2463 | { | |
2464 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
2465 | continue; | |
2466 | ||
6de2ae4a L |
2467 | if (s == htab->elf.splt |
2468 | || s == htab->elf.sgot | |
2469 | || s == htab->elf.sgotplt | |
2470 | || s == htab->elf.iplt | |
2471 | || s == htab->elf.igotplt | |
75ff4589 | 2472 | || s == htab->sdynbss) |
c434dee6 AJ |
2473 | { |
2474 | /* Strip this section if we don't need it; see the | |
2475 | comment below. */ | |
2476 | } | |
0112cd26 | 2477 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) |
c434dee6 | 2478 | { |
6de2ae4a | 2479 | if (s->size != 0 && s != htab->elf.srelplt) |
b34976b6 | 2480 | relocs = TRUE; |
c434dee6 AJ |
2481 | |
2482 | /* We use the reloc_count field as a counter if we need | |
2483 | to copy relocs into the output file. */ | |
6de2ae4a | 2484 | if (s != htab->elf.srelplt) |
67a4f2b7 | 2485 | s->reloc_count = 0; |
70256ad8 | 2486 | } |
c434dee6 | 2487 | else |
70256ad8 AJ |
2488 | { |
2489 | /* It's not one of our sections, so don't allocate space. */ | |
2490 | continue; | |
2491 | } | |
2492 | ||
eea6121a | 2493 | if (s->size == 0) |
70256ad8 | 2494 | { |
c434dee6 AJ |
2495 | /* If we don't need this section, strip it from the |
2496 | output file. This is mostly to handle .rela.bss and | |
2497 | .rela.plt. We must create both sections in | |
2498 | create_dynamic_sections, because they must be created | |
2499 | before the linker maps input sections to output | |
2500 | sections. The linker does that before | |
2501 | adjust_dynamic_symbol is called, and it is that | |
2502 | function which decides whether anything needs to go | |
2503 | into these sections. */ | |
2504 | ||
8423293d | 2505 | s->flags |= SEC_EXCLUDE; |
70256ad8 AJ |
2506 | continue; |
2507 | } | |
2508 | ||
c456f082 AM |
2509 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
2510 | continue; | |
2511 | ||
70256ad8 AJ |
2512 | /* Allocate memory for the section contents. We use bfd_zalloc |
2513 | here in case unused entries are not reclaimed before the | |
2514 | section's contents are written out. This should not happen, | |
2515 | but this way if it does, we get a R_X86_64_NONE reloc instead | |
2516 | of garbage. */ | |
eea6121a | 2517 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
c434dee6 | 2518 | if (s->contents == NULL) |
b34976b6 | 2519 | return FALSE; |
70256ad8 AJ |
2520 | } |
2521 | ||
c434dee6 | 2522 | if (htab->elf.dynamic_sections_created) |
70256ad8 AJ |
2523 | { |
2524 | /* Add some entries to the .dynamic section. We fill in the | |
2525 | values later, in elf64_x86_64_finish_dynamic_sections, but we | |
2526 | must add the entries now so that we get the correct size for | |
407443a3 | 2527 | the .dynamic section. The DT_DEBUG entry is filled in by the |
70256ad8 | 2528 | dynamic linker and used by the debugger. */ |
dc810e39 | 2529 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 2530 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 | 2531 | |
36af4a4e | 2532 | if (info->executable) |
70256ad8 | 2533 | { |
dc810e39 | 2534 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 2535 | return FALSE; |
70256ad8 AJ |
2536 | } |
2537 | ||
6de2ae4a | 2538 | if (htab->elf.splt->size != 0) |
70256ad8 | 2539 | { |
dc810e39 AM |
2540 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
2541 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
2542 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
2543 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 2544 | return FALSE; |
67a4f2b7 AO |
2545 | |
2546 | if (htab->tlsdesc_plt | |
2547 | && (!add_dynamic_entry (DT_TLSDESC_PLT, 0) | |
2548 | || !add_dynamic_entry (DT_TLSDESC_GOT, 0))) | |
2549 | return FALSE; | |
70256ad8 AJ |
2550 | } |
2551 | ||
2552 | if (relocs) | |
2553 | { | |
dc810e39 AM |
2554 | if (!add_dynamic_entry (DT_RELA, 0) |
2555 | || !add_dynamic_entry (DT_RELASZ, 0) | |
2556 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
b34976b6 | 2557 | return FALSE; |
70256ad8 | 2558 | |
c434dee6 AJ |
2559 | /* If any dynamic relocs apply to a read-only section, |
2560 | then we need a DT_TEXTREL entry. */ | |
2561 | if ((info->flags & DF_TEXTREL) == 0) | |
eb4ff4d6 L |
2562 | elf_link_hash_traverse (&htab->elf, |
2563 | elf64_x86_64_readonly_dynrelocs, | |
2564 | info); | |
c434dee6 AJ |
2565 | |
2566 | if ((info->flags & DF_TEXTREL) != 0) | |
2567 | { | |
2568 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
b34976b6 | 2569 | return FALSE; |
c434dee6 | 2570 | } |
70256ad8 AJ |
2571 | } |
2572 | } | |
dc810e39 | 2573 | #undef add_dynamic_entry |
70256ad8 | 2574 | |
b34976b6 | 2575 | return TRUE; |
70256ad8 AJ |
2576 | } |
2577 | ||
67a4f2b7 AO |
2578 | static bfd_boolean |
2579 | elf64_x86_64_always_size_sections (bfd *output_bfd, | |
2580 | struct bfd_link_info *info) | |
2581 | { | |
2582 | asection *tls_sec = elf_hash_table (info)->tls_sec; | |
2583 | ||
2584 | if (tls_sec) | |
2585 | { | |
2586 | struct elf_link_hash_entry *tlsbase; | |
2587 | ||
2588 | tlsbase = elf_link_hash_lookup (elf_hash_table (info), | |
2589 | "_TLS_MODULE_BASE_", | |
2590 | FALSE, FALSE, FALSE); | |
2591 | ||
2592 | if (tlsbase && tlsbase->type == STT_TLS) | |
2593 | { | |
2594 | struct bfd_link_hash_entry *bh = NULL; | |
2595 | const struct elf_backend_data *bed | |
2596 | = get_elf_backend_data (output_bfd); | |
2597 | ||
2598 | if (!(_bfd_generic_link_add_one_symbol | |
2599 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, | |
2600 | tls_sec, 0, NULL, FALSE, | |
2601 | bed->collect, &bh))) | |
2602 | return FALSE; | |
9f03412a AO |
2603 | |
2604 | elf64_x86_64_hash_table (info)->tls_module_base = bh; | |
2605 | ||
67a4f2b7 AO |
2606 | tlsbase = (struct elf_link_hash_entry *)bh; |
2607 | tlsbase->def_regular = 1; | |
2608 | tlsbase->other = STV_HIDDEN; | |
2609 | (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE); | |
2610 | } | |
2611 | } | |
2612 | ||
2613 | return TRUE; | |
2614 | } | |
2615 | ||
9f03412a AO |
2616 | /* _TLS_MODULE_BASE_ needs to be treated especially when linking |
2617 | executables. Rather than setting it to the beginning of the TLS | |
2618 | section, we have to set it to the end. This function may be called | |
2619 | multiple times, it is idempotent. */ | |
2620 | ||
2621 | static void | |
eb4ff4d6 | 2622 | elf64_x86_64_set_tls_module_base (struct bfd_link_info *info) |
9f03412a AO |
2623 | { |
2624 | struct bfd_link_hash_entry *base; | |
2625 | ||
2626 | if (!info->executable) | |
2627 | return; | |
2628 | ||
2629 | base = elf64_x86_64_hash_table (info)->tls_module_base; | |
2630 | ||
2631 | if (!base) | |
2632 | return; | |
2633 | ||
2634 | base->u.def.value = elf_hash_table (info)->tls_size; | |
2635 | } | |
2636 | ||
bffbf940 JJ |
2637 | /* Return the base VMA address which should be subtracted from real addresses |
2638 | when resolving @dtpoff relocation. | |
2639 | This is PT_TLS segment p_vaddr. */ | |
2640 | ||
2641 | static bfd_vma | |
eb4ff4d6 | 2642 | elf64_x86_64_dtpoff_base (struct bfd_link_info *info) |
bffbf940 | 2643 | { |
e1918d23 AM |
2644 | /* If tls_sec is NULL, we should have signalled an error already. */ |
2645 | if (elf_hash_table (info)->tls_sec == NULL) | |
bffbf940 | 2646 | return 0; |
e1918d23 | 2647 | return elf_hash_table (info)->tls_sec->vma; |
bffbf940 JJ |
2648 | } |
2649 | ||
2650 | /* Return the relocation value for @tpoff relocation | |
2651 | if STT_TLS virtual address is ADDRESS. */ | |
2652 | ||
2653 | static bfd_vma | |
eb4ff4d6 | 2654 | elf64_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address) |
bffbf940 | 2655 | { |
e1918d23 | 2656 | struct elf_link_hash_table *htab = elf_hash_table (info); |
bffbf940 JJ |
2657 | |
2658 | /* If tls_segment is NULL, we should have signalled an error already. */ | |
e1918d23 | 2659 | if (htab->tls_sec == NULL) |
bffbf940 | 2660 | return 0; |
e1918d23 | 2661 | return address - htab->tls_size - htab->tls_sec->vma; |
bffbf940 JJ |
2662 | } |
2663 | ||
90f487df L |
2664 | /* Is the instruction before OFFSET in CONTENTS a 32bit relative |
2665 | branch? */ | |
2666 | ||
2667 | static bfd_boolean | |
2668 | is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset) | |
2669 | { | |
2670 | /* Opcode Instruction | |
2671 | 0xe8 call | |
2672 | 0xe9 jump | |
2673 | 0x0f 0x8x conditional jump */ | |
2674 | return ((offset > 0 | |
2675 | && (contents [offset - 1] == 0xe8 | |
2676 | || contents [offset - 1] == 0xe9)) | |
2677 | || (offset > 1 | |
2678 | && contents [offset - 2] == 0x0f | |
2679 | && (contents [offset - 1] & 0xf0) == 0x80)); | |
2680 | } | |
2681 | ||
8d88c4ca NC |
2682 | /* Relocate an x86_64 ELF section. */ |
2683 | ||
b34976b6 | 2684 | static bfd_boolean |
27482721 AJ |
2685 | elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, |
2686 | bfd *input_bfd, asection *input_section, | |
2687 | bfd_byte *contents, Elf_Internal_Rela *relocs, | |
2688 | Elf_Internal_Sym *local_syms, | |
2689 | asection **local_sections) | |
8d88c4ca | 2690 | { |
c434dee6 | 2691 | struct elf64_x86_64_link_hash_table *htab; |
8d88c4ca NC |
2692 | Elf_Internal_Shdr *symtab_hdr; |
2693 | struct elf_link_hash_entry **sym_hashes; | |
2694 | bfd_vma *local_got_offsets; | |
67a4f2b7 | 2695 | bfd_vma *local_tlsdesc_gotents; |
c434dee6 | 2696 | Elf_Internal_Rela *rel; |
8d88c4ca NC |
2697 | Elf_Internal_Rela *relend; |
2698 | ||
0ffa91dd NC |
2699 | BFD_ASSERT (is_x86_64_elf (input_bfd)); |
2700 | ||
c434dee6 | 2701 | htab = elf64_x86_64_hash_table (info); |
0ffa91dd | 2702 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
8d88c4ca NC |
2703 | sym_hashes = elf_sym_hashes (input_bfd); |
2704 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
67a4f2b7 | 2705 | local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd); |
8d88c4ca | 2706 | |
eb4ff4d6 | 2707 | elf64_x86_64_set_tls_module_base (info); |
9f03412a | 2708 | |
c434dee6 | 2709 | rel = relocs; |
8d88c4ca | 2710 | relend = relocs + input_section->reloc_count; |
c434dee6 | 2711 | for (; rel < relend; rel++) |
8d88c4ca | 2712 | { |
bffbf940 | 2713 | unsigned int r_type; |
8d88c4ca NC |
2714 | reloc_howto_type *howto; |
2715 | unsigned long r_symndx; | |
2716 | struct elf_link_hash_entry *h; | |
2717 | Elf_Internal_Sym *sym; | |
2718 | asection *sec; | |
67a4f2b7 | 2719 | bfd_vma off, offplt; |
8d88c4ca | 2720 | bfd_vma relocation; |
b34976b6 | 2721 | bfd_boolean unresolved_reloc; |
8d88c4ca | 2722 | bfd_reloc_status_type r; |
bffbf940 | 2723 | int tls_type; |
cbe950e9 | 2724 | asection *base_got; |
8d88c4ca | 2725 | |
c434dee6 | 2726 | r_type = ELF64_R_TYPE (rel->r_info); |
fe4770f4 AJ |
2727 | if (r_type == (int) R_X86_64_GNU_VTINHERIT |
2728 | || r_type == (int) R_X86_64_GNU_VTENTRY) | |
2729 | continue; | |
8d88c4ca | 2730 | |
bffbf940 | 2731 | if (r_type >= R_X86_64_max) |
8da6118f KH |
2732 | { |
2733 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2734 | return FALSE; |
8da6118f | 2735 | } |
8d88c4ca | 2736 | |
b491616a | 2737 | howto = x86_64_elf_howto_table + r_type; |
c434dee6 | 2738 | r_symndx = ELF64_R_SYM (rel->r_info); |
8d88c4ca NC |
2739 | h = NULL; |
2740 | sym = NULL; | |
2741 | sec = NULL; | |
b34976b6 | 2742 | unresolved_reloc = FALSE; |
8d88c4ca | 2743 | if (r_symndx < symtab_hdr->sh_info) |
8da6118f KH |
2744 | { |
2745 | sym = local_syms + r_symndx; | |
2746 | sec = local_sections[r_symndx]; | |
c434dee6 | 2747 | |
c25bc9fc L |
2748 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, |
2749 | &sec, rel); | |
2750 | ||
2751 | /* Relocate against local STT_GNU_IFUNC symbol. */ | |
2752 | if (ELF64_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
2753 | { | |
2754 | h = elf64_x86_64_get_local_sym_hash (htab, input_bfd, | |
2755 | rel, FALSE); | |
2756 | if (h == NULL) | |
2757 | abort (); | |
2758 | ||
2759 | /* Set STT_GNU_IFUNC symbol value. */ | |
2760 | h->root.u.def.value = sym->st_value; | |
2761 | h->root.u.def.section = sec; | |
2762 | } | |
8da6118f | 2763 | } |
8d88c4ca | 2764 | else |
8da6118f | 2765 | { |
560e09e9 | 2766 | bfd_boolean warned; |
c434dee6 | 2767 | |
b2a8e766 AM |
2768 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
2769 | r_symndx, symtab_hdr, sym_hashes, | |
2770 | h, sec, relocation, | |
2771 | unresolved_reloc, warned); | |
8da6118f | 2772 | } |
ab96bf03 AM |
2773 | |
2774 | if (sec != NULL && elf_discarded_section (sec)) | |
2775 | { | |
2776 | /* For relocs against symbols from removed linkonce sections, | |
2777 | or sections discarded by a linker script, we just want the | |
2778 | section contents zeroed. Avoid any special processing. */ | |
2779 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
2780 | rel->r_info = 0; | |
2781 | rel->r_addend = 0; | |
2782 | continue; | |
2783 | } | |
2784 | ||
2785 | if (info->relocatable) | |
2786 | continue; | |
2787 | ||
cbe950e9 L |
2788 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
2789 | it here if it is defined in a non-shared object. */ | |
2790 | if (h != NULL | |
2791 | && h->type == STT_GNU_IFUNC | |
2792 | && h->def_regular) | |
2793 | { | |
2794 | asection *plt; | |
2795 | bfd_vma plt_index; | |
2796 | ||
2797 | if ((input_section->flags & SEC_ALLOC) == 0 | |
2798 | || h->plt.offset == (bfd_vma) -1) | |
2799 | abort (); | |
2800 | ||
2801 | /* STT_GNU_IFUNC symbol must go through PLT. */ | |
6de2ae4a | 2802 | plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt; |
cbe950e9 L |
2803 | relocation = (plt->output_section->vma |
2804 | + plt->output_offset + h->plt.offset); | |
2805 | ||
2806 | switch (r_type) | |
2807 | { | |
2808 | default: | |
2809 | (*_bfd_error_handler) | |
2810 | (_("%B: relocation %s against STT_GNU_IFUNC " | |
2811 | "symbol `%s' isn't handled by %s"), input_bfd, | |
2812 | x86_64_elf_howto_table[r_type].name, | |
637fa7af L |
2813 | (h->root.root.string |
2814 | ? h->root.root.string : "a local symbol"), | |
2815 | __FUNCTION__); | |
cbe950e9 L |
2816 | bfd_set_error (bfd_error_bad_value); |
2817 | return FALSE; | |
2818 | ||
2819 | case R_X86_64_32S: | |
710ab287 | 2820 | if (info->shared) |
cbe950e9 | 2821 | abort (); |
710ab287 L |
2822 | goto do_relocation; |
2823 | ||
2824 | case R_X86_64_64: | |
2825 | if (rel->r_addend != 0) | |
2826 | { | |
2827 | (*_bfd_error_handler) | |
2828 | (_("%B: relocation %s against STT_GNU_IFUNC " | |
2829 | "symbol `%s' has non-zero addend: %d"), | |
2830 | input_bfd, x86_64_elf_howto_table[r_type].name, | |
637fa7af L |
2831 | (h->root.root.string |
2832 | ? h->root.root.string : "a local symbol"), | |
2833 | rel->r_addend); | |
710ab287 L |
2834 | bfd_set_error (bfd_error_bad_value); |
2835 | return FALSE; | |
2836 | } | |
2837 | ||
2838 | /* Generate dynamic relcoation only when there is a | |
2839 | non-GOF reference in a shared object. */ | |
2840 | if (info->shared && h->non_got_ref) | |
2841 | { | |
2842 | Elf_Internal_Rela outrel; | |
2843 | bfd_byte *loc; | |
2844 | asection *sreloc; | |
2845 | ||
c25bc9fc L |
2846 | /* Need a dynamic relocation to get the real function |
2847 | address. */ | |
710ab287 L |
2848 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, |
2849 | info, | |
2850 | input_section, | |
2851 | rel->r_offset); | |
2852 | if (outrel.r_offset == (bfd_vma) -1 | |
2853 | || outrel.r_offset == (bfd_vma) -2) | |
2854 | abort (); | |
2855 | ||
2856 | outrel.r_offset += (input_section->output_section->vma | |
2857 | + input_section->output_offset); | |
2858 | ||
2859 | if (h->dynindx == -1 | |
44c4ea11 L |
2860 | || h->forced_local |
2861 | || info->executable) | |
710ab287 L |
2862 | { |
2863 | /* This symbol is resolved locally. */ | |
2864 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE); | |
2865 | outrel.r_addend = (h->root.u.def.value | |
2866 | + h->root.u.def.section->output_section->vma | |
2867 | + h->root.u.def.section->output_offset); | |
2868 | } | |
2869 | else | |
2870 | { | |
2871 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); | |
2872 | outrel.r_addend = 0; | |
2873 | } | |
2874 | ||
6de2ae4a | 2875 | sreloc = htab->elf.irelifunc; |
710ab287 L |
2876 | loc = sreloc->contents; |
2877 | loc += (sreloc->reloc_count++ | |
2878 | * sizeof (Elf64_External_Rela)); | |
2879 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
2880 | ||
2881 | /* If this reloc is against an external symbol, we | |
2882 | do not want to fiddle with the addend. Otherwise, | |
2883 | we need to include the symbol value so that it | |
2884 | becomes an addend for the dynamic reloc. For an | |
2885 | internal symbol, we have updated addend. */ | |
2886 | continue; | |
2887 | } | |
cbe950e9 L |
2888 | |
2889 | case R_X86_64_32: | |
cbe950e9 L |
2890 | case R_X86_64_PC32: |
2891 | case R_X86_64_PC64: | |
2892 | case R_X86_64_PLT32: | |
2893 | goto do_relocation; | |
2894 | ||
2895 | case R_X86_64_GOTPCREL: | |
2896 | case R_X86_64_GOTPCREL64: | |
6de2ae4a | 2897 | base_got = htab->elf.sgot; |
cbe950e9 L |
2898 | off = h->got.offset; |
2899 | ||
7afd84dc | 2900 | if (base_got == NULL) |
cbe950e9 L |
2901 | abort (); |
2902 | ||
7afd84dc | 2903 | if (off == (bfd_vma) -1) |
cbe950e9 | 2904 | { |
7afd84dc L |
2905 | /* We can't use h->got.offset here to save state, or |
2906 | even just remember the offset, as finish_dynamic_symbol | |
2907 | would use that as offset into .got. */ | |
cbe950e9 | 2908 | |
6de2ae4a | 2909 | if (htab->elf.splt != NULL) |
7afd84dc L |
2910 | { |
2911 | plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; | |
2912 | off = (plt_index + 3) * GOT_ENTRY_SIZE; | |
6de2ae4a | 2913 | base_got = htab->elf.sgotplt; |
7afd84dc | 2914 | } |
cbe950e9 L |
2915 | else |
2916 | { | |
7afd84dc L |
2917 | plt_index = h->plt.offset / PLT_ENTRY_SIZE; |
2918 | off = plt_index * GOT_ENTRY_SIZE; | |
6de2ae4a | 2919 | base_got = htab->elf.igotplt; |
7afd84dc L |
2920 | } |
2921 | ||
2922 | if (h->dynindx == -1 | |
2923 | || h->forced_local | |
2924 | || info->symbolic) | |
2925 | { | |
2926 | /* This references the local defitionion. We must | |
2927 | initialize this entry in the global offset table. | |
2928 | Since the offset must always be a multiple of 8, | |
2929 | we use the least significant bit to record | |
2930 | whether we have initialized it already. | |
2931 | ||
2932 | When doing a dynamic link, we create a .rela.got | |
2933 | relocation entry to initialize the value. This | |
2934 | is done in the finish_dynamic_symbol routine. */ | |
2935 | if ((off & 1) != 0) | |
2936 | off &= ~1; | |
2937 | else | |
2938 | { | |
2939 | bfd_put_64 (output_bfd, relocation, | |
2940 | base_got->contents + off); | |
2941 | /* Note that this is harmless for the GOTPLT64 | |
2942 | case, as -1 | 1 still is -1. */ | |
2943 | h->got.offset |= 1; | |
2944 | } | |
cbe950e9 L |
2945 | } |
2946 | } | |
2947 | ||
2948 | relocation = (base_got->output_section->vma | |
2949 | + base_got->output_offset + off); | |
2950 | ||
2951 | if (r_type != R_X86_64_GOTPCREL | |
2952 | && r_type != R_X86_64_GOTPCREL64) | |
2953 | { | |
2954 | asection *gotplt; | |
6de2ae4a L |
2955 | if (htab->elf.splt != NULL) |
2956 | gotplt = htab->elf.sgotplt; | |
cbe950e9 | 2957 | else |
6de2ae4a | 2958 | gotplt = htab->elf.igotplt; |
cbe950e9 L |
2959 | relocation -= (gotplt->output_section->vma |
2960 | - gotplt->output_offset); | |
2961 | } | |
2962 | ||
2963 | goto do_relocation; | |
2964 | } | |
2965 | } | |
2966 | ||
70256ad8 AJ |
2967 | /* When generating a shared object, the relocations handled here are |
2968 | copied into the output file to be resolved at run time. */ | |
2969 | switch (r_type) | |
2970 | { | |
2971 | case R_X86_64_GOT32: | |
7b81dfbb | 2972 | case R_X86_64_GOT64: |
70256ad8 AJ |
2973 | /* Relocation is to the entry for this symbol in the global |
2974 | offset table. */ | |
70256ad8 | 2975 | case R_X86_64_GOTPCREL: |
7b81dfbb AJ |
2976 | case R_X86_64_GOTPCREL64: |
2977 | /* Use global offset table entry as symbol value. */ | |
2978 | case R_X86_64_GOTPLT64: | |
2979 | /* This is the same as GOT64 for relocation purposes, but | |
2980 | indicates the existence of a PLT entry. The difficulty is, | |
2981 | that we must calculate the GOT slot offset from the PLT | |
2982 | offset, if this symbol got a PLT entry (it was global). | |
2983 | Additionally if it's computed from the PLT entry, then that | |
2984 | GOT offset is relative to .got.plt, not to .got. */ | |
6de2ae4a | 2985 | base_got = htab->elf.sgot; |
7b81dfbb | 2986 | |
6de2ae4a | 2987 | if (htab->elf.sgot == NULL) |
c434dee6 | 2988 | abort (); |
053579d7 | 2989 | |
51e0a107 | 2990 | if (h != NULL) |
70256ad8 | 2991 | { |
b34976b6 | 2992 | bfd_boolean dyn; |
c434dee6 AJ |
2993 | |
2994 | off = h->got.offset; | |
7b81dfbb AJ |
2995 | if (h->needs_plt |
2996 | && h->plt.offset != (bfd_vma)-1 | |
2997 | && off == (bfd_vma)-1) | |
2998 | { | |
2999 | /* We can't use h->got.offset here to save | |
3000 | state, or even just remember the offset, as | |
3001 | finish_dynamic_symbol would use that as offset into | |
3002 | .got. */ | |
3003 | bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; | |
3004 | off = (plt_index + 3) * GOT_ENTRY_SIZE; | |
6de2ae4a | 3005 | base_got = htab->elf.sgotplt; |
7b81dfbb AJ |
3006 | } |
3007 | ||
c434dee6 | 3008 | dyn = htab->elf.dynamic_sections_created; |
51e0a107 | 3009 | |
27482721 | 3010 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
51e0a107 | 3011 | || (info->shared |
27482721 | 3012 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
4bc6e03a AJ |
3013 | || (ELF_ST_VISIBILITY (h->other) |
3014 | && h->root.type == bfd_link_hash_undefweak)) | |
51e0a107 JH |
3015 | { |
3016 | /* This is actually a static link, or it is a -Bsymbolic | |
3017 | link and the symbol is defined locally, or the symbol | |
407443a3 | 3018 | was forced to be local because of a version file. We |
51e0a107 JH |
3019 | must initialize this entry in the global offset table. |
3020 | Since the offset must always be a multiple of 8, we | |
3021 | use the least significant bit to record whether we | |
3022 | have initialized it already. | |
3023 | ||
3024 | When doing a dynamic link, we create a .rela.got | |
407443a3 AJ |
3025 | relocation entry to initialize the value. This is |
3026 | done in the finish_dynamic_symbol routine. */ | |
51e0a107 JH |
3027 | if ((off & 1) != 0) |
3028 | off &= ~1; | |
3029 | else | |
3030 | { | |
3031 | bfd_put_64 (output_bfd, relocation, | |
7b81dfbb AJ |
3032 | base_got->contents + off); |
3033 | /* Note that this is harmless for the GOTPLT64 case, | |
3034 | as -1 | 1 still is -1. */ | |
51e0a107 JH |
3035 | h->got.offset |= 1; |
3036 | } | |
3037 | } | |
053579d7 | 3038 | else |
b34976b6 | 3039 | unresolved_reloc = FALSE; |
70256ad8 | 3040 | } |
51e0a107 JH |
3041 | else |
3042 | { | |
c434dee6 AJ |
3043 | if (local_got_offsets == NULL) |
3044 | abort (); | |
51e0a107 JH |
3045 | |
3046 | off = local_got_offsets[r_symndx]; | |
3047 | ||
3048 | /* The offset must always be a multiple of 8. We use | |
407443a3 AJ |
3049 | the least significant bit to record whether we have |
3050 | already generated the necessary reloc. */ | |
51e0a107 JH |
3051 | if ((off & 1) != 0) |
3052 | off &= ~1; | |
3053 | else | |
3054 | { | |
c434dee6 | 3055 | bfd_put_64 (output_bfd, relocation, |
7b81dfbb | 3056 | base_got->contents + off); |
51e0a107 JH |
3057 | |
3058 | if (info->shared) | |
3059 | { | |
947216bf | 3060 | asection *s; |
51e0a107 | 3061 | Elf_Internal_Rela outrel; |
947216bf | 3062 | bfd_byte *loc; |
70256ad8 | 3063 | |
51e0a107 JH |
3064 | /* We need to generate a R_X86_64_RELATIVE reloc |
3065 | for the dynamic linker. */ | |
6de2ae4a | 3066 | s = htab->elf.srelgot; |
947216bf | 3067 | if (s == NULL) |
c434dee6 | 3068 | abort (); |
51e0a107 | 3069 | |
7b81dfbb AJ |
3070 | outrel.r_offset = (base_got->output_section->vma |
3071 | + base_got->output_offset | |
51e0a107 JH |
3072 | + off); |
3073 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); | |
3074 | outrel.r_addend = relocation; | |
947216bf AM |
3075 | loc = s->contents; |
3076 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela); | |
c434dee6 | 3077 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
51e0a107 JH |
3078 | } |
3079 | ||
3080 | local_got_offsets[r_symndx] |= 1; | |
3081 | } | |
51e0a107 | 3082 | } |
6a2bda3f | 3083 | |
c434dee6 AJ |
3084 | if (off >= (bfd_vma) -2) |
3085 | abort (); | |
3086 | ||
7b81dfbb AJ |
3087 | relocation = base_got->output_section->vma |
3088 | + base_got->output_offset + off; | |
3089 | if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64) | |
6de2ae4a L |
3090 | relocation -= htab->elf.sgotplt->output_section->vma |
3091 | - htab->elf.sgotplt->output_offset; | |
c434dee6 | 3092 | |
70256ad8 AJ |
3093 | break; |
3094 | ||
d6ab8113 JB |
3095 | case R_X86_64_GOTOFF64: |
3096 | /* Relocation is relative to the start of the global offset | |
3097 | table. */ | |
3098 | ||
3099 | /* Check to make sure it isn't a protected function symbol | |
3100 | for shared library since it may not be local when used | |
3101 | as function address. */ | |
3102 | if (info->shared | |
3103 | && h | |
3104 | && h->def_regular | |
3105 | && h->type == STT_FUNC | |
3106 | && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) | |
3107 | { | |
3108 | (*_bfd_error_handler) | |
3109 | (_("%B: relocation R_X86_64_GOTOFF64 against protected function `%s' can not be used when making a shared object"), | |
3110 | input_bfd, h->root.root.string); | |
3111 | bfd_set_error (bfd_error_bad_value); | |
3112 | return FALSE; | |
3113 | } | |
3114 | ||
3115 | /* Note that sgot is not involved in this | |
3116 | calculation. We always want the start of .got.plt. If we | |
3117 | defined _GLOBAL_OFFSET_TABLE_ in a different way, as is | |
3118 | permitted by the ABI, we might have to change this | |
3119 | calculation. */ | |
6de2ae4a L |
3120 | relocation -= htab->elf.sgotplt->output_section->vma |
3121 | + htab->elf.sgotplt->output_offset; | |
d6ab8113 JB |
3122 | break; |
3123 | ||
3124 | case R_X86_64_GOTPC32: | |
7b81dfbb | 3125 | case R_X86_64_GOTPC64: |
d6ab8113 | 3126 | /* Use global offset table as symbol value. */ |
6de2ae4a L |
3127 | relocation = htab->elf.sgotplt->output_section->vma |
3128 | + htab->elf.sgotplt->output_offset; | |
d6ab8113 JB |
3129 | unresolved_reloc = FALSE; |
3130 | break; | |
7b81dfbb AJ |
3131 | |
3132 | case R_X86_64_PLTOFF64: | |
3133 | /* Relocation is PLT entry relative to GOT. For local | |
3134 | symbols it's the symbol itself relative to GOT. */ | |
3135 | if (h != NULL | |
3136 | /* See PLT32 handling. */ | |
3137 | && h->plt.offset != (bfd_vma) -1 | |
6de2ae4a | 3138 | && htab->elf.splt != NULL) |
7b81dfbb | 3139 | { |
6de2ae4a L |
3140 | relocation = (htab->elf.splt->output_section->vma |
3141 | + htab->elf.splt->output_offset | |
7b81dfbb AJ |
3142 | + h->plt.offset); |
3143 | unresolved_reloc = FALSE; | |
3144 | } | |
3145 | ||
6de2ae4a L |
3146 | relocation -= htab->elf.sgotplt->output_section->vma |
3147 | + htab->elf.sgotplt->output_offset; | |
7b81dfbb | 3148 | break; |
d6ab8113 | 3149 | |
70256ad8 AJ |
3150 | case R_X86_64_PLT32: |
3151 | /* Relocation is to the entry for this symbol in the | |
3152 | procedure linkage table. */ | |
3153 | ||
3154 | /* Resolve a PLT32 reloc against a local symbol directly, | |
407443a3 | 3155 | without using the procedure linkage table. */ |
70256ad8 AJ |
3156 | if (h == NULL) |
3157 | break; | |
3158 | ||
c434dee6 | 3159 | if (h->plt.offset == (bfd_vma) -1 |
6de2ae4a | 3160 | || htab->elf.splt == NULL) |
70256ad8 AJ |
3161 | { |
3162 | /* We didn't make a PLT entry for this symbol. This | |
407443a3 AJ |
3163 | happens when statically linking PIC code, or when |
3164 | using -Bsymbolic. */ | |
70256ad8 AJ |
3165 | break; |
3166 | } | |
3167 | ||
6de2ae4a L |
3168 | relocation = (htab->elf.splt->output_section->vma |
3169 | + htab->elf.splt->output_offset | |
70256ad8 | 3170 | + h->plt.offset); |
b34976b6 | 3171 | unresolved_reloc = FALSE; |
70256ad8 AJ |
3172 | break; |
3173 | ||
fd8ab9e5 AJ |
3174 | case R_X86_64_PC8: |
3175 | case R_X86_64_PC16: | |
3176 | case R_X86_64_PC32: | |
6610a52d | 3177 | if (info->shared |
ba3bee0b | 3178 | && (input_section->flags & SEC_ALLOC) != 0 |
90f487df | 3179 | && (input_section->flags & SEC_READONLY) != 0 |
41bed6dd | 3180 | && h != NULL) |
6610a52d | 3181 | { |
41bed6dd L |
3182 | bfd_boolean fail = FALSE; |
3183 | bfd_boolean branch | |
3184 | = (r_type == R_X86_64_PC32 | |
3185 | && is_32bit_relative_branch (contents, rel->r_offset)); | |
3186 | ||
3187 | if (SYMBOL_REFERENCES_LOCAL (info, h)) | |
3188 | { | |
3189 | /* Symbol is referenced locally. Make sure it is | |
3190 | defined locally or for a branch. */ | |
3191 | fail = !h->def_regular && !branch; | |
3192 | } | |
90f487df | 3193 | else |
41bed6dd L |
3194 | { |
3195 | /* Symbol isn't referenced locally. We only allow | |
3196 | branch to symbol with non-default visibility. */ | |
3197 | fail = (!branch | |
3198 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT); | |
3199 | } | |
3200 | ||
3201 | if (fail) | |
3202 | { | |
3203 | const char *fmt; | |
3204 | const char *v; | |
3205 | const char *pic = ""; | |
3206 | ||
3207 | switch (ELF_ST_VISIBILITY (h->other)) | |
3208 | { | |
3209 | case STV_HIDDEN: | |
3210 | v = _("hidden symbol"); | |
3211 | break; | |
3212 | case STV_INTERNAL: | |
3213 | v = _("internal symbol"); | |
3214 | break; | |
3215 | case STV_PROTECTED: | |
3216 | v = _("protected symbol"); | |
3217 | break; | |
3218 | default: | |
3219 | v = _("symbol"); | |
3220 | pic = _("; recompile with -fPIC"); | |
3221 | break; | |
3222 | } | |
3223 | ||
3224 | if (h->def_regular) | |
3225 | fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s"); | |
3226 | else | |
3227 | fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s"); | |
3228 | ||
3229 | (*_bfd_error_handler) (fmt, input_bfd, | |
3230 | x86_64_elf_howto_table[r_type].name, | |
3231 | v, h->root.root.string, pic); | |
3232 | bfd_set_error (bfd_error_bad_value); | |
3233 | return FALSE; | |
3234 | } | |
6610a52d L |
3235 | } |
3236 | /* Fall through. */ | |
3237 | ||
70256ad8 AJ |
3238 | case R_X86_64_8: |
3239 | case R_X86_64_16: | |
3240 | case R_X86_64_32: | |
d6ab8113 | 3241 | case R_X86_64_PC64: |
6b3db546 | 3242 | case R_X86_64_64: |
80643fbc | 3243 | /* FIXME: The ABI says the linker should make sure the value is |
407443a3 | 3244 | the same when it's zeroextended to 64 bit. */ |
c434dee6 | 3245 | |
b1e24c02 | 3246 | if ((input_section->flags & SEC_ALLOC) == 0) |
c434dee6 AJ |
3247 | break; |
3248 | ||
3249 | if ((info->shared | |
4bc6e03a AJ |
3250 | && (h == NULL |
3251 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3252 | || h->root.type != bfd_link_hash_undefweak) | |
d8045f23 NC |
3253 | && (! IS_X86_64_PCREL_TYPE (r_type) |
3254 | || ! SYMBOL_CALLS_LOCAL (info, h))) | |
d40d037c AJ |
3255 | || (ELIMINATE_COPY_RELOCS |
3256 | && !info->shared | |
c434dee6 AJ |
3257 | && h != NULL |
3258 | && h->dynindx != -1 | |
f5385ebf AM |
3259 | && !h->non_got_ref |
3260 | && ((h->def_dynamic | |
3261 | && !h->def_regular) | |
c434dee6 | 3262 | || h->root.type == bfd_link_hash_undefweak |
0f88be7a | 3263 | || h->root.type == bfd_link_hash_undefined))) |
70256ad8 AJ |
3264 | { |
3265 | Elf_Internal_Rela outrel; | |
947216bf | 3266 | bfd_byte *loc; |
b34976b6 | 3267 | bfd_boolean skip, relocate; |
c434dee6 | 3268 | asection *sreloc; |
70256ad8 AJ |
3269 | |
3270 | /* When generating a shared object, these relocations | |
3271 | are copied into the output file to be resolved at run | |
407443a3 | 3272 | time. */ |
b34976b6 AM |
3273 | skip = FALSE; |
3274 | relocate = FALSE; | |
70256ad8 | 3275 | |
c629eae0 JJ |
3276 | outrel.r_offset = |
3277 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
c434dee6 | 3278 | rel->r_offset); |
c629eae0 | 3279 | if (outrel.r_offset == (bfd_vma) -1) |
b34976b6 | 3280 | skip = TRUE; |
0fb19cbc | 3281 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 3282 | skip = TRUE, relocate = TRUE; |
70256ad8 AJ |
3283 | |
3284 | outrel.r_offset += (input_section->output_section->vma | |
3285 | + input_section->output_offset); | |
3286 | ||
3287 | if (skip) | |
0bb2d96a | 3288 | memset (&outrel, 0, sizeof outrel); |
c434dee6 | 3289 | |
fd8ab9e5 AJ |
3290 | /* h->dynindx may be -1 if this symbol was marked to |
3291 | become local. */ | |
3292 | else if (h != NULL | |
c434dee6 | 3293 | && h->dynindx != -1 |
d8045f23 NC |
3294 | && (IS_X86_64_PCREL_TYPE (r_type) |
3295 | || ! info->shared | |
3296 | || ! SYMBOLIC_BIND (info, h) | |
3297 | || ! h->def_regular)) | |
70256ad8 | 3298 | { |
70256ad8 | 3299 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
c434dee6 | 3300 | outrel.r_addend = rel->r_addend; |
70256ad8 AJ |
3301 | } |
3302 | else | |
3303 | { | |
c434dee6 | 3304 | /* This symbol is local, or marked to become local. */ |
607c0e09 AS |
3305 | if (r_type == R_X86_64_64) |
3306 | { | |
b34976b6 | 3307 | relocate = TRUE; |
607c0e09 AS |
3308 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); |
3309 | outrel.r_addend = relocation + rel->r_addend; | |
3310 | } | |
3311 | else | |
3312 | { | |
3313 | long sindx; | |
3314 | ||
8517fae7 | 3315 | if (bfd_is_abs_section (sec)) |
607c0e09 AS |
3316 | sindx = 0; |
3317 | else if (sec == NULL || sec->owner == NULL) | |
3318 | { | |
3319 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 3320 | return FALSE; |
607c0e09 AS |
3321 | } |
3322 | else | |
3323 | { | |
3324 | asection *osec; | |
3325 | ||
74541ad4 AM |
3326 | /* We are turning this relocation into one |
3327 | against a section symbol. It would be | |
3328 | proper to subtract the symbol's value, | |
3329 | osec->vma, from the emitted reloc addend, | |
3330 | but ld.so expects buggy relocs. */ | |
607c0e09 AS |
3331 | osec = sec->output_section; |
3332 | sindx = elf_section_data (osec)->dynindx; | |
74541ad4 AM |
3333 | if (sindx == 0) |
3334 | { | |
3335 | asection *oi = htab->elf.text_index_section; | |
3336 | sindx = elf_section_data (oi)->dynindx; | |
3337 | } | |
3338 | BFD_ASSERT (sindx != 0); | |
607c0e09 AS |
3339 | } |
3340 | ||
3341 | outrel.r_info = ELF64_R_INFO (sindx, r_type); | |
3342 | outrel.r_addend = relocation + rel->r_addend; | |
3343 | } | |
70256ad8 AJ |
3344 | } |
3345 | ||
cbe950e9 | 3346 | sreloc = elf_section_data (input_section)->sreloc; |
d8045f23 | 3347 | |
e7c33416 | 3348 | BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL); |
c434dee6 | 3349 | |
947216bf AM |
3350 | loc = sreloc->contents; |
3351 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
c434dee6 | 3352 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
70256ad8 AJ |
3353 | |
3354 | /* If this reloc is against an external symbol, we do | |
3355 | not want to fiddle with the addend. Otherwise, we | |
3356 | need to include the symbol value so that it becomes | |
3357 | an addend for the dynamic reloc. */ | |
0f88be7a | 3358 | if (! relocate) |
70256ad8 AJ |
3359 | continue; |
3360 | } | |
3361 | ||
3362 | break; | |
3363 | ||
bffbf940 | 3364 | case R_X86_64_TLSGD: |
67a4f2b7 AO |
3365 | case R_X86_64_GOTPC32_TLSDESC: |
3366 | case R_X86_64_TLSDESC_CALL: | |
bffbf940 | 3367 | case R_X86_64_GOTTPOFF: |
bffbf940 JJ |
3368 | tls_type = GOT_UNKNOWN; |
3369 | if (h == NULL && local_got_offsets) | |
3370 | tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx]; | |
3371 | else if (h != NULL) | |
142411ca L |
3372 | tls_type = elf64_x86_64_hash_entry (h)->tls_type; |
3373 | ||
3374 | if (! elf64_x86_64_tls_transition (info, input_bfd, | |
3375 | input_section, contents, | |
3376 | symtab_hdr, sym_hashes, | |
3377 | &r_type, tls_type, rel, | |
3378 | relend, h)) | |
534a31f6 | 3379 | return FALSE; |
bffbf940 JJ |
3380 | |
3381 | if (r_type == R_X86_64_TPOFF32) | |
3382 | { | |
142411ca L |
3383 | bfd_vma roff = rel->r_offset; |
3384 | ||
bffbf940 | 3385 | BFD_ASSERT (! unresolved_reloc); |
142411ca | 3386 | |
bffbf940 JJ |
3387 | if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD) |
3388 | { | |
bffbf940 | 3389 | /* GD->LE transition. |
abcf1d52 | 3390 | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
a3fadc9a | 3391 | .word 0x6666; rex64; call __tls_get_addr |
bffbf940 JJ |
3392 | Change it into: |
3393 | movq %fs:0, %rax | |
3394 | leaq foo@tpoff(%rax), %rax */ | |
142411ca | 3395 | memcpy (contents + roff - 4, |
bffbf940 JJ |
3396 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0", |
3397 | 16); | |
eb4ff4d6 L |
3398 | bfd_put_32 (output_bfd, |
3399 | elf64_x86_64_tpoff (info, relocation), | |
142411ca | 3400 | contents + roff + 8); |
a3fadc9a | 3401 | /* Skip R_X86_64_PC32/R_X86_64_PLT32. */ |
bffbf940 JJ |
3402 | rel++; |
3403 | continue; | |
3404 | } | |
67a4f2b7 AO |
3405 | else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC) |
3406 | { | |
3407 | /* GDesc -> LE transition. | |
3408 | It's originally something like: | |
3409 | leaq x@tlsdesc(%rip), %rax | |
3410 | ||
3411 | Change it to: | |
3412 | movl $x@tpoff, %rax | |
142411ca | 3413 | */ |
67a4f2b7 AO |
3414 | |
3415 | unsigned int val, type, type2; | |
67a4f2b7 | 3416 | |
67a4f2b7 | 3417 | type = bfd_get_8 (input_bfd, contents + roff - 3); |
67a4f2b7 | 3418 | type2 = bfd_get_8 (input_bfd, contents + roff - 2); |
67a4f2b7 | 3419 | val = bfd_get_8 (input_bfd, contents + roff - 1); |
67a4f2b7 AO |
3420 | bfd_put_8 (output_bfd, 0x48 | ((type >> 2) & 1), |
3421 | contents + roff - 3); | |
3422 | bfd_put_8 (output_bfd, 0xc7, contents + roff - 2); | |
3423 | bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7), | |
3424 | contents + roff - 1); | |
eb4ff4d6 L |
3425 | bfd_put_32 (output_bfd, |
3426 | elf64_x86_64_tpoff (info, relocation), | |
67a4f2b7 AO |
3427 | contents + roff); |
3428 | continue; | |
3429 | } | |
3430 | else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL) | |
3431 | { | |
3432 | /* GDesc -> LE transition. | |
3433 | It's originally: | |
3434 | call *(%rax) | |
3435 | Turn it into: | |
142411ca | 3436 | xchg %ax,%ax. */ |
10efb593 | 3437 | bfd_put_8 (output_bfd, 0x66, contents + roff); |
67a4f2b7 AO |
3438 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); |
3439 | continue; | |
3440 | } | |
142411ca | 3441 | else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTTPOFF) |
bffbf940 | 3442 | { |
bffbf940 JJ |
3443 | /* IE->LE transition: |
3444 | Originally it can be one of: | |
3445 | movq foo@gottpoff(%rip), %reg | |
3446 | addq foo@gottpoff(%rip), %reg | |
3447 | We change it into: | |
3448 | movq $foo, %reg | |
3449 | leaq foo(%reg), %reg | |
3450 | addq $foo, %reg. */ | |
142411ca L |
3451 | |
3452 | unsigned int val, type, reg; | |
3453 | ||
3454 | val = bfd_get_8 (input_bfd, contents + roff - 3); | |
3455 | type = bfd_get_8 (input_bfd, contents + roff - 2); | |
3456 | reg = bfd_get_8 (input_bfd, contents + roff - 1); | |
bffbf940 | 3457 | reg >>= 3; |
bffbf940 JJ |
3458 | if (type == 0x8b) |
3459 | { | |
3460 | /* movq */ | |
3461 | if (val == 0x4c) | |
3462 | bfd_put_8 (output_bfd, 0x49, | |
142411ca | 3463 | contents + roff - 3); |
bffbf940 | 3464 | bfd_put_8 (output_bfd, 0xc7, |
142411ca | 3465 | contents + roff - 2); |
bffbf940 | 3466 | bfd_put_8 (output_bfd, 0xc0 | reg, |
142411ca | 3467 | contents + roff - 1); |
bffbf940 JJ |
3468 | } |
3469 | else if (reg == 4) | |
3470 | { | |
3471 | /* addq -> addq - addressing with %rsp/%r12 is | |
3472 | special */ | |
3473 | if (val == 0x4c) | |
3474 | bfd_put_8 (output_bfd, 0x49, | |
142411ca | 3475 | contents + roff - 3); |
bffbf940 | 3476 | bfd_put_8 (output_bfd, 0x81, |
142411ca | 3477 | contents + roff - 2); |
bffbf940 | 3478 | bfd_put_8 (output_bfd, 0xc0 | reg, |
142411ca | 3479 | contents + roff - 1); |
bffbf940 JJ |
3480 | } |
3481 | else | |
3482 | { | |
3483 | /* addq -> leaq */ | |
3484 | if (val == 0x4c) | |
3485 | bfd_put_8 (output_bfd, 0x4d, | |
142411ca | 3486 | contents + roff - 3); |
bffbf940 | 3487 | bfd_put_8 (output_bfd, 0x8d, |
142411ca | 3488 | contents + roff - 2); |
bffbf940 | 3489 | bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3), |
142411ca | 3490 | contents + roff - 1); |
bffbf940 | 3491 | } |
eb4ff4d6 L |
3492 | bfd_put_32 (output_bfd, |
3493 | elf64_x86_64_tpoff (info, relocation), | |
142411ca | 3494 | contents + roff); |
bffbf940 JJ |
3495 | continue; |
3496 | } | |
142411ca L |
3497 | else |
3498 | BFD_ASSERT (FALSE); | |
bffbf940 JJ |
3499 | } |
3500 | ||
6de2ae4a | 3501 | if (htab->elf.sgot == NULL) |
bffbf940 JJ |
3502 | abort (); |
3503 | ||
3504 | if (h != NULL) | |
67a4f2b7 AO |
3505 | { |
3506 | off = h->got.offset; | |
3507 | offplt = elf64_x86_64_hash_entry (h)->tlsdesc_got; | |
3508 | } | |
bffbf940 JJ |
3509 | else |
3510 | { | |
3511 | if (local_got_offsets == NULL) | |
3512 | abort (); | |
3513 | ||
3514 | off = local_got_offsets[r_symndx]; | |
67a4f2b7 | 3515 | offplt = local_tlsdesc_gotents[r_symndx]; |
bffbf940 JJ |
3516 | } |
3517 | ||
3518 | if ((off & 1) != 0) | |
3519 | off &= ~1; | |
26e41594 | 3520 | else |
bffbf940 JJ |
3521 | { |
3522 | Elf_Internal_Rela outrel; | |
947216bf | 3523 | bfd_byte *loc; |
bffbf940 | 3524 | int dr_type, indx; |
67a4f2b7 | 3525 | asection *sreloc; |
bffbf940 | 3526 | |
6de2ae4a | 3527 | if (htab->elf.srelgot == NULL) |
bffbf940 JJ |
3528 | abort (); |
3529 | ||
67a4f2b7 AO |
3530 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
3531 | ||
3532 | if (GOT_TLS_GDESC_P (tls_type)) | |
3533 | { | |
3534 | outrel.r_info = ELF64_R_INFO (indx, R_X86_64_TLSDESC); | |
3535 | BFD_ASSERT (htab->sgotplt_jump_table_size + offplt | |
6de2ae4a L |
3536 | + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size); |
3537 | outrel.r_offset = (htab->elf.sgotplt->output_section->vma | |
3538 | + htab->elf.sgotplt->output_offset | |
67a4f2b7 AO |
3539 | + offplt |
3540 | + htab->sgotplt_jump_table_size); | |
6de2ae4a | 3541 | sreloc = htab->elf.srelplt; |
67a4f2b7 AO |
3542 | loc = sreloc->contents; |
3543 | loc += sreloc->reloc_count++ | |
3544 | * sizeof (Elf64_External_Rela); | |
3545 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela) | |
3546 | <= sreloc->contents + sreloc->size); | |
3547 | if (indx == 0) | |
eb4ff4d6 | 3548 | outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info); |
67a4f2b7 AO |
3549 | else |
3550 | outrel.r_addend = 0; | |
3551 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
3552 | } | |
3553 | ||
6de2ae4a | 3554 | sreloc = htab->elf.srelgot; |
67a4f2b7 | 3555 | |
6de2ae4a L |
3556 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
3557 | + htab->elf.sgot->output_offset + off); | |
bffbf940 | 3558 | |
67a4f2b7 | 3559 | if (GOT_TLS_GD_P (tls_type)) |
bffbf940 | 3560 | dr_type = R_X86_64_DTPMOD64; |
67a4f2b7 AO |
3561 | else if (GOT_TLS_GDESC_P (tls_type)) |
3562 | goto dr_done; | |
bffbf940 JJ |
3563 | else |
3564 | dr_type = R_X86_64_TPOFF64; | |
3565 | ||
6de2ae4a | 3566 | bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off); |
bffbf940 | 3567 | outrel.r_addend = 0; |
67a4f2b7 AO |
3568 | if ((dr_type == R_X86_64_TPOFF64 |
3569 | || dr_type == R_X86_64_TLSDESC) && indx == 0) | |
eb4ff4d6 | 3570 | outrel.r_addend = relocation - elf64_x86_64_dtpoff_base (info); |
bffbf940 JJ |
3571 | outrel.r_info = ELF64_R_INFO (indx, dr_type); |
3572 | ||
67a4f2b7 AO |
3573 | loc = sreloc->contents; |
3574 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); | |
3575 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela) | |
3576 | <= sreloc->contents + sreloc->size); | |
bffbf940 JJ |
3577 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
3578 | ||
67a4f2b7 | 3579 | if (GOT_TLS_GD_P (tls_type)) |
bffbf940 JJ |
3580 | { |
3581 | if (indx == 0) | |
3582 | { | |
d40d037c | 3583 | BFD_ASSERT (! unresolved_reloc); |
bffbf940 | 3584 | bfd_put_64 (output_bfd, |
eb4ff4d6 | 3585 | relocation - elf64_x86_64_dtpoff_base (info), |
6de2ae4a | 3586 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
bffbf940 JJ |
3587 | } |
3588 | else | |
3589 | { | |
3590 | bfd_put_64 (output_bfd, 0, | |
6de2ae4a | 3591 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
bffbf940 JJ |
3592 | outrel.r_info = ELF64_R_INFO (indx, |
3593 | R_X86_64_DTPOFF64); | |
3594 | outrel.r_offset += GOT_ENTRY_SIZE; | |
67a4f2b7 | 3595 | sreloc->reloc_count++; |
947216bf | 3596 | loc += sizeof (Elf64_External_Rela); |
67a4f2b7 AO |
3597 | BFD_ASSERT (loc + sizeof (Elf64_External_Rela) |
3598 | <= sreloc->contents + sreloc->size); | |
947216bf | 3599 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
bffbf940 JJ |
3600 | } |
3601 | } | |
3602 | ||
67a4f2b7 | 3603 | dr_done: |
bffbf940 JJ |
3604 | if (h != NULL) |
3605 | h->got.offset |= 1; | |
3606 | else | |
3607 | local_got_offsets[r_symndx] |= 1; | |
3608 | } | |
3609 | ||
67a4f2b7 AO |
3610 | if (off >= (bfd_vma) -2 |
3611 | && ! GOT_TLS_GDESC_P (tls_type)) | |
bffbf940 JJ |
3612 | abort (); |
3613 | if (r_type == ELF64_R_TYPE (rel->r_info)) | |
3614 | { | |
67a4f2b7 AO |
3615 | if (r_type == R_X86_64_GOTPC32_TLSDESC |
3616 | || r_type == R_X86_64_TLSDESC_CALL) | |
6de2ae4a L |
3617 | relocation = htab->elf.sgotplt->output_section->vma |
3618 | + htab->elf.sgotplt->output_offset | |
67a4f2b7 AO |
3619 | + offplt + htab->sgotplt_jump_table_size; |
3620 | else | |
6de2ae4a L |
3621 | relocation = htab->elf.sgot->output_section->vma |
3622 | + htab->elf.sgot->output_offset + off; | |
b34976b6 | 3623 | unresolved_reloc = FALSE; |
bffbf940 | 3624 | } |
142411ca | 3625 | else |
67a4f2b7 | 3626 | { |
142411ca | 3627 | bfd_vma roff = rel->r_offset; |
67a4f2b7 | 3628 | |
142411ca L |
3629 | if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD) |
3630 | { | |
3631 | /* GD->IE transition. | |
3632 | .byte 0x66; leaq foo@tlsgd(%rip), %rdi | |
3633 | .word 0x6666; rex64; call __tls_get_addr@plt | |
3634 | Change it into: | |
3635 | movq %fs:0, %rax | |
3636 | addq foo@gottpoff(%rip), %rax */ | |
3637 | memcpy (contents + roff - 4, | |
3638 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0", | |
3639 | 16); | |
3640 | ||
6de2ae4a L |
3641 | relocation = (htab->elf.sgot->output_section->vma |
3642 | + htab->elf.sgot->output_offset + off | |
142411ca L |
3643 | - roff |
3644 | - input_section->output_section->vma | |
3645 | - input_section->output_offset | |
3646 | - 12); | |
3647 | bfd_put_32 (output_bfd, relocation, | |
3648 | contents + roff + 8); | |
3649 | /* Skip R_X86_64_PLT32. */ | |
3650 | rel++; | |
3651 | continue; | |
3652 | } | |
3653 | else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_GOTPC32_TLSDESC) | |
3654 | { | |
3655 | /* GDesc -> IE transition. | |
3656 | It's originally something like: | |
3657 | leaq x@tlsdesc(%rip), %rax | |
67a4f2b7 | 3658 | |
142411ca L |
3659 | Change it to: |
3660 | movq x@gottpoff(%rip), %rax # before xchg %ax,%ax | |
3661 | */ | |
67a4f2b7 | 3662 | |
142411ca | 3663 | unsigned int val, type, type2; |
67a4f2b7 | 3664 | |
142411ca L |
3665 | type = bfd_get_8 (input_bfd, contents + roff - 3); |
3666 | type2 = bfd_get_8 (input_bfd, contents + roff - 2); | |
3667 | val = bfd_get_8 (input_bfd, contents + roff - 1); | |
67a4f2b7 | 3668 | |
142411ca L |
3669 | /* Now modify the instruction as appropriate. To |
3670 | turn a leaq into a movq in the form we use it, it | |
3671 | suffices to change the second byte from 0x8d to | |
3672 | 0x8b. */ | |
3673 | bfd_put_8 (output_bfd, 0x8b, contents + roff - 2); | |
3674 | ||
3675 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
3676 | htab->elf.sgot->output_section->vma |
3677 | + htab->elf.sgot->output_offset + off | |
142411ca L |
3678 | - rel->r_offset |
3679 | - input_section->output_section->vma | |
3680 | - input_section->output_offset | |
3681 | - 4, | |
3682 | contents + roff); | |
3683 | continue; | |
3684 | } | |
3685 | else if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSDESC_CALL) | |
3686 | { | |
3687 | /* GDesc -> IE transition. | |
3688 | It's originally: | |
3689 | call *(%rax) | |
3690 | ||
3691 | Change it to: | |
3692 | xchg %ax,%ax. */ | |
3693 | ||
3694 | unsigned int val, type; | |
3695 | ||
3696 | type = bfd_get_8 (input_bfd, contents + roff); | |
3697 | val = bfd_get_8 (input_bfd, contents + roff + 1); | |
3698 | bfd_put_8 (output_bfd, 0x66, contents + roff); | |
3699 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); | |
3700 | continue; | |
3701 | } | |
3702 | else | |
3703 | BFD_ASSERT (FALSE); | |
67a4f2b7 | 3704 | } |
bffbf940 JJ |
3705 | break; |
3706 | ||
3707 | case R_X86_64_TLSLD: | |
142411ca L |
3708 | if (! elf64_x86_64_tls_transition (info, input_bfd, |
3709 | input_section, contents, | |
3710 | symtab_hdr, sym_hashes, | |
3711 | &r_type, GOT_UNKNOWN, | |
3712 | rel, relend, h)) | |
3713 | return FALSE; | |
a3fadc9a | 3714 | |
142411ca L |
3715 | if (r_type != R_X86_64_TLSLD) |
3716 | { | |
bffbf940 | 3717 | /* LD->LE transition: |
a3fadc9a | 3718 | leaq foo@tlsld(%rip), %rdi; call __tls_get_addr. |
bffbf940 JJ |
3719 | We change it into: |
3720 | .word 0x6666; .byte 0x66; movl %fs:0, %rax. */ | |
142411ca L |
3721 | |
3722 | BFD_ASSERT (r_type == R_X86_64_TPOFF32); | |
bffbf940 JJ |
3723 | memcpy (contents + rel->r_offset - 3, |
3724 | "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12); | |
a3fadc9a | 3725 | /* Skip R_X86_64_PC32/R_X86_64_PLT32. */ |
bffbf940 JJ |
3726 | rel++; |
3727 | continue; | |
3728 | } | |
3729 | ||
6de2ae4a | 3730 | if (htab->elf.sgot == NULL) |
bffbf940 JJ |
3731 | abort (); |
3732 | ||
3733 | off = htab->tls_ld_got.offset; | |
3734 | if (off & 1) | |
3735 | off &= ~1; | |
3736 | else | |
3737 | { | |
3738 | Elf_Internal_Rela outrel; | |
947216bf | 3739 | bfd_byte *loc; |
bffbf940 | 3740 | |
6de2ae4a | 3741 | if (htab->elf.srelgot == NULL) |
bffbf940 JJ |
3742 | abort (); |
3743 | ||
6de2ae4a L |
3744 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
3745 | + htab->elf.sgot->output_offset + off); | |
bffbf940 JJ |
3746 | |
3747 | bfd_put_64 (output_bfd, 0, | |
6de2ae4a | 3748 | htab->elf.sgot->contents + off); |
bffbf940 | 3749 | bfd_put_64 (output_bfd, 0, |
6de2ae4a | 3750 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
bffbf940 JJ |
3751 | outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64); |
3752 | outrel.r_addend = 0; | |
6de2ae4a L |
3753 | loc = htab->elf.srelgot->contents; |
3754 | loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela); | |
bffbf940 JJ |
3755 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
3756 | htab->tls_ld_got.offset |= 1; | |
3757 | } | |
6de2ae4a L |
3758 | relocation = htab->elf.sgot->output_section->vma |
3759 | + htab->elf.sgot->output_offset + off; | |
b34976b6 | 3760 | unresolved_reloc = FALSE; |
bffbf940 JJ |
3761 | break; |
3762 | ||
3763 | case R_X86_64_DTPOFF32: | |
a45bb67d | 3764 | if (info->shared || (input_section->flags & SEC_CODE) == 0) |
eb4ff4d6 | 3765 | relocation -= elf64_x86_64_dtpoff_base (info); |
bffbf940 | 3766 | else |
eb4ff4d6 | 3767 | relocation = elf64_x86_64_tpoff (info, relocation); |
bffbf940 JJ |
3768 | break; |
3769 | ||
3770 | case R_X86_64_TPOFF32: | |
3771 | BFD_ASSERT (! info->shared); | |
eb4ff4d6 | 3772 | relocation = elf64_x86_64_tpoff (info, relocation); |
bffbf940 JJ |
3773 | break; |
3774 | ||
70256ad8 AJ |
3775 | default: |
3776 | break; | |
3777 | } | |
8d88c4ca | 3778 | |
239e1f3a AM |
3779 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
3780 | because such sections are not SEC_ALLOC and thus ld.so will | |
3781 | not process them. */ | |
c434dee6 | 3782 | if (unresolved_reloc |
239e1f3a | 3783 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
f5385ebf | 3784 | && h->def_dynamic)) |
c434dee6 | 3785 | (*_bfd_error_handler) |
843fe662 | 3786 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
d003868e AM |
3787 | input_bfd, |
3788 | input_section, | |
c434dee6 | 3789 | (long) rel->r_offset, |
843fe662 | 3790 | howto->name, |
c434dee6 AJ |
3791 | h->root.root.string); |
3792 | ||
cbe950e9 | 3793 | do_relocation: |
8d88c4ca | 3794 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
c434dee6 AJ |
3795 | contents, rel->r_offset, |
3796 | relocation, rel->r_addend); | |
8d88c4ca NC |
3797 | |
3798 | if (r != bfd_reloc_ok) | |
8da6118f | 3799 | { |
c434dee6 AJ |
3800 | const char *name; |
3801 | ||
3802 | if (h != NULL) | |
3803 | name = h->root.root.string; | |
3804 | else | |
8da6118f | 3805 | { |
c434dee6 AJ |
3806 | name = bfd_elf_string_from_elf_section (input_bfd, |
3807 | symtab_hdr->sh_link, | |
3808 | sym->st_name); | |
3809 | if (name == NULL) | |
b34976b6 | 3810 | return FALSE; |
c434dee6 AJ |
3811 | if (*name == '\0') |
3812 | name = bfd_section_name (input_bfd, sec); | |
3813 | } | |
3814 | ||
3815 | if (r == bfd_reloc_overflow) | |
3816 | { | |
c434dee6 | 3817 | if (! ((*info->callbacks->reloc_overflow) |
dfeffb9f L |
3818 | (info, (h ? &h->root : NULL), name, howto->name, |
3819 | (bfd_vma) 0, input_bfd, input_section, | |
3820 | rel->r_offset))) | |
b34976b6 | 3821 | return FALSE; |
c434dee6 AJ |
3822 | } |
3823 | else | |
3824 | { | |
3825 | (*_bfd_error_handler) | |
d003868e AM |
3826 | (_("%B(%A+0x%lx): reloc against `%s': error %d"), |
3827 | input_bfd, input_section, | |
c434dee6 | 3828 | (long) rel->r_offset, name, (int) r); |
b34976b6 | 3829 | return FALSE; |
8da6118f KH |
3830 | } |
3831 | } | |
8d88c4ca | 3832 | } |
70256ad8 | 3833 | |
b34976b6 | 3834 | return TRUE; |
70256ad8 AJ |
3835 | } |
3836 | ||
3837 | /* Finish up dynamic symbol handling. We set the contents of various | |
3838 | dynamic sections here. */ | |
3839 | ||
b34976b6 | 3840 | static bfd_boolean |
27482721 AJ |
3841 | elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd, |
3842 | struct bfd_link_info *info, | |
3843 | struct elf_link_hash_entry *h, | |
3844 | Elf_Internal_Sym *sym) | |
70256ad8 | 3845 | { |
c434dee6 | 3846 | struct elf64_x86_64_link_hash_table *htab; |
70256ad8 | 3847 | |
c434dee6 | 3848 | htab = elf64_x86_64_hash_table (info); |
70256ad8 AJ |
3849 | |
3850 | if (h->plt.offset != (bfd_vma) -1) | |
3851 | { | |
70256ad8 AJ |
3852 | bfd_vma plt_index; |
3853 | bfd_vma got_offset; | |
3854 | Elf_Internal_Rela rela; | |
947216bf | 3855 | bfd_byte *loc; |
cbe950e9 L |
3856 | asection *plt, *gotplt, *relplt; |
3857 | ||
3858 | /* When building a static executable, use .iplt, .igot.plt and | |
3859 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
6de2ae4a | 3860 | if (htab->elf.splt != NULL) |
cbe950e9 | 3861 | { |
6de2ae4a L |
3862 | plt = htab->elf.splt; |
3863 | gotplt = htab->elf.sgotplt; | |
3864 | relplt = htab->elf.srelplt; | |
cbe950e9 L |
3865 | } |
3866 | else | |
3867 | { | |
6de2ae4a L |
3868 | plt = htab->elf.iplt; |
3869 | gotplt = htab->elf.igotplt; | |
3870 | relplt = htab->elf.irelplt; | |
cbe950e9 | 3871 | } |
70256ad8 AJ |
3872 | |
3873 | /* This symbol has an entry in the procedure linkage table. Set | |
407443a3 | 3874 | it up. */ |
cbe950e9 L |
3875 | if ((h->dynindx == -1 |
3876 | && !((h->forced_local || info->executable) | |
3877 | && h->def_regular | |
3878 | && h->type == STT_GNU_IFUNC)) | |
3879 | || plt == NULL | |
3880 | || gotplt == NULL | |
3881 | || relplt == NULL) | |
c434dee6 | 3882 | abort (); |
70256ad8 AJ |
3883 | |
3884 | /* Get the index in the procedure linkage table which | |
3885 | corresponds to this symbol. This is the index of this symbol | |
3886 | in all the symbols for which we are making plt entries. The | |
cbe950e9 L |
3887 | first entry in the procedure linkage table is reserved. |
3888 | ||
3889 | Get the offset into the .got table of the entry that | |
407443a3 | 3890 | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE |
cbe950e9 L |
3891 | bytes. The first three are reserved for the dynamic linker. |
3892 | ||
3893 | For static executables, we don't reserve anything. */ | |
3894 | ||
6de2ae4a | 3895 | if (plt == htab->elf.splt) |
cbe950e9 L |
3896 | { |
3897 | plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; | |
3898 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; | |
3899 | } | |
3900 | else | |
3901 | { | |
3902 | plt_index = h->plt.offset / PLT_ENTRY_SIZE; | |
3903 | got_offset = plt_index * GOT_ENTRY_SIZE; | |
3904 | } | |
70256ad8 AJ |
3905 | |
3906 | /* Fill in the entry in the procedure linkage table. */ | |
cbe950e9 | 3907 | memcpy (plt->contents + h->plt.offset, elf64_x86_64_plt_entry, |
70256ad8 AJ |
3908 | PLT_ENTRY_SIZE); |
3909 | ||
3910 | /* Insert the relocation positions of the plt section. The magic | |
3911 | numbers at the end of the statements are the positions of the | |
3912 | relocations in the plt section. */ | |
653165cc AJ |
3913 | /* Put offset for jmp *name@GOTPCREL(%rip), since the |
3914 | instruction uses 6 bytes, subtract this value. */ | |
3915 | bfd_put_32 (output_bfd, | |
cbe950e9 L |
3916 | (gotplt->output_section->vma |
3917 | + gotplt->output_offset | |
653165cc | 3918 | + got_offset |
cbe950e9 L |
3919 | - plt->output_section->vma |
3920 | - plt->output_offset | |
653165cc AJ |
3921 | - h->plt.offset |
3922 | - 6), | |
cbe950e9 L |
3923 | plt->contents + h->plt.offset + 2); |
3924 | ||
3925 | /* Don't fill PLT entry for static executables. */ | |
6de2ae4a | 3926 | if (plt == htab->elf.splt) |
cbe950e9 L |
3927 | { |
3928 | /* Put relocation index. */ | |
3929 | bfd_put_32 (output_bfd, plt_index, | |
3930 | plt->contents + h->plt.offset + 7); | |
3931 | /* Put offset for jmp .PLT0. */ | |
3932 | bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE), | |
3933 | plt->contents + h->plt.offset + 12); | |
3934 | } | |
70256ad8 | 3935 | |
653165cc AJ |
3936 | /* Fill in the entry in the global offset table, initially this |
3937 | points to the pushq instruction in the PLT which is at offset 6. */ | |
cbe950e9 L |
3938 | bfd_put_64 (output_bfd, (plt->output_section->vma |
3939 | + plt->output_offset | |
70256ad8 | 3940 | + h->plt.offset + 6), |
cbe950e9 | 3941 | gotplt->contents + got_offset); |
70256ad8 AJ |
3942 | |
3943 | /* Fill in the entry in the .rela.plt section. */ | |
cbe950e9 L |
3944 | rela.r_offset = (gotplt->output_section->vma |
3945 | + gotplt->output_offset | |
70256ad8 | 3946 | + got_offset); |
cbe950e9 L |
3947 | if (h->dynindx == -1 |
3948 | || ((info->executable | |
3949 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
3950 | && h->def_regular | |
3951 | && h->type == STT_GNU_IFUNC)) | |
3952 | { | |
3953 | /* If an STT_GNU_IFUNC symbol is locally defined, generate | |
3954 | R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */ | |
3955 | rela.r_info = ELF64_R_INFO (0, R_X86_64_IRELATIVE); | |
3956 | rela.r_addend = (h->root.u.def.value | |
3957 | + h->root.u.def.section->output_section->vma | |
3958 | + h->root.u.def.section->output_offset); | |
3959 | } | |
3960 | else | |
3961 | { | |
3962 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT); | |
3963 | rela.r_addend = 0; | |
3964 | } | |
3965 | loc = relplt->contents + plt_index * sizeof (Elf64_External_Rela); | |
c434dee6 | 3966 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
70256ad8 | 3967 | |
f5385ebf | 3968 | if (!h->def_regular) |
70256ad8 AJ |
3969 | { |
3970 | /* Mark the symbol as undefined, rather than as defined in | |
47a9f7b3 JJ |
3971 | the .plt section. Leave the value if there were any |
3972 | relocations where pointer equality matters (this is a clue | |
c434dee6 AJ |
3973 | for the dynamic linker, to make function pointer |
3974 | comparisons work between an application and shared | |
47a9f7b3 JJ |
3975 | library), otherwise set it to zero. If a function is only |
3976 | called from a binary, there is no need to slow down | |
3977 | shared libraries because of that. */ | |
70256ad8 | 3978 | sym->st_shndx = SHN_UNDEF; |
f5385ebf | 3979 | if (!h->pointer_equality_needed) |
47a9f7b3 | 3980 | sym->st_value = 0; |
70256ad8 AJ |
3981 | } |
3982 | } | |
3983 | ||
bffbf940 | 3984 | if (h->got.offset != (bfd_vma) -1 |
67a4f2b7 | 3985 | && ! GOT_TLS_GD_ANY_P (elf64_x86_64_hash_entry (h)->tls_type) |
bffbf940 | 3986 | && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE) |
053579d7 | 3987 | { |
053579d7 | 3988 | Elf_Internal_Rela rela; |
947216bf | 3989 | bfd_byte *loc; |
053579d7 AJ |
3990 | |
3991 | /* This symbol has an entry in the global offset table. Set it | |
bffbf940 | 3992 | up. */ |
6de2ae4a | 3993 | if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL) |
c434dee6 | 3994 | abort (); |
053579d7 | 3995 | |
6de2ae4a L |
3996 | rela.r_offset = (htab->elf.sgot->output_section->vma |
3997 | + htab->elf.sgot->output_offset | |
dc810e39 | 3998 | + (h->got.offset &~ (bfd_vma) 1)); |
053579d7 AJ |
3999 | |
4000 | /* If this is a static link, or it is a -Bsymbolic link and the | |
4001 | symbol is defined locally or was forced to be local because | |
4002 | of a version file, we just want to emit a RELATIVE reloc. | |
4003 | The entry in the global offset table will already have been | |
4004 | initialized in the relocate_section function. */ | |
710ab287 | 4005 | if (h->def_regular |
0018b0a3 L |
4006 | && h->type == STT_GNU_IFUNC) |
4007 | { | |
710ab287 L |
4008 | if (info->shared) |
4009 | { | |
4010 | /* Generate R_X86_64_GLOB_DAT. */ | |
4011 | goto do_glob_dat; | |
4012 | } | |
4013 | else | |
4014 | { | |
4015 | if (!h->pointer_equality_needed) | |
4016 | abort (); | |
4017 | ||
4018 | /* For non-shared object, we can't use .got.plt, which | |
4019 | contains the real function addres if we need pointer | |
4020 | equality. We load the GOT entry with the PLT entry. */ | |
6de2ae4a | 4021 | asection *plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt; |
710ab287 L |
4022 | bfd_put_64 (output_bfd, (plt->output_section->vma |
4023 | + plt->output_offset | |
4024 | + h->plt.offset), | |
6de2ae4a | 4025 | htab->elf.sgot->contents + h->got.offset); |
710ab287 L |
4026 | return TRUE; |
4027 | } | |
0018b0a3 L |
4028 | } |
4029 | else if (info->shared | |
4030 | && SYMBOL_REFERENCES_LOCAL (info, h)) | |
053579d7 | 4031 | { |
41bed6dd L |
4032 | if (!h->def_regular) |
4033 | return FALSE; | |
cc78d0af | 4034 | BFD_ASSERT((h->got.offset & 1) != 0); |
053579d7 AJ |
4035 | rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); |
4036 | rela.r_addend = (h->root.u.def.value | |
4037 | + h->root.u.def.section->output_section->vma | |
4038 | + h->root.u.def.section->output_offset); | |
4039 | } | |
4040 | else | |
4041 | { | |
4042 | BFD_ASSERT((h->got.offset & 1) == 0); | |
710ab287 | 4043 | do_glob_dat: |
c434dee6 | 4044 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
6de2ae4a | 4045 | htab->elf.sgot->contents + h->got.offset); |
053579d7 AJ |
4046 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT); |
4047 | rela.r_addend = 0; | |
4048 | } | |
4049 | ||
6de2ae4a L |
4050 | loc = htab->elf.srelgot->contents; |
4051 | loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela); | |
c434dee6 | 4052 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
053579d7 AJ |
4053 | } |
4054 | ||
f5385ebf | 4055 | if (h->needs_copy) |
70256ad8 | 4056 | { |
70256ad8 | 4057 | Elf_Internal_Rela rela; |
947216bf | 4058 | bfd_byte *loc; |
70256ad8 AJ |
4059 | |
4060 | /* This symbol needs a copy reloc. Set it up. */ | |
4061 | ||
c434dee6 AJ |
4062 | if (h->dynindx == -1 |
4063 | || (h->root.type != bfd_link_hash_defined | |
4064 | && h->root.type != bfd_link_hash_defweak) | |
4065 | || htab->srelbss == NULL) | |
4066 | abort (); | |
70256ad8 AJ |
4067 | |
4068 | rela.r_offset = (h->root.u.def.value | |
4069 | + h->root.u.def.section->output_section->vma | |
4070 | + h->root.u.def.section->output_offset); | |
4071 | rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY); | |
4072 | rela.r_addend = 0; | |
947216bf AM |
4073 | loc = htab->srelbss->contents; |
4074 | loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela); | |
c434dee6 | 4075 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
70256ad8 AJ |
4076 | } |
4077 | ||
c25bc9fc L |
4078 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may |
4079 | be NULL for local symbols. */ | |
4080 | if (sym != NULL | |
4081 | && (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
4082 | || h == htab->elf.hgot)) | |
70256ad8 AJ |
4083 | sym->st_shndx = SHN_ABS; |
4084 | ||
b34976b6 | 4085 | return TRUE; |
70256ad8 AJ |
4086 | } |
4087 | ||
c25bc9fc L |
4088 | /* Finish up local dynamic symbol handling. We set the contents of |
4089 | various dynamic sections here. */ | |
4090 | ||
4091 | static bfd_boolean | |
4092 | elf64_x86_64_finish_local_dynamic_symbol (void **slot, void *inf) | |
4093 | { | |
4094 | struct elf_link_hash_entry *h | |
4095 | = (struct elf_link_hash_entry *) *slot; | |
4096 | struct bfd_link_info *info | |
4097 | = (struct bfd_link_info *) inf; | |
4098 | ||
4099 | return elf64_x86_64_finish_dynamic_symbol (info->output_bfd, | |
4100 | info, h, NULL); | |
4101 | } | |
4102 | ||
c434dee6 AJ |
4103 | /* Used to decide how to sort relocs in an optimal manner for the |
4104 | dynamic linker, before writing them out. */ | |
4105 | ||
4106 | static enum elf_reloc_type_class | |
27482721 | 4107 | elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela) |
c434dee6 AJ |
4108 | { |
4109 | switch ((int) ELF64_R_TYPE (rela->r_info)) | |
4110 | { | |
4111 | case R_X86_64_RELATIVE: | |
4112 | return reloc_class_relative; | |
4113 | case R_X86_64_JUMP_SLOT: | |
4114 | return reloc_class_plt; | |
4115 | case R_X86_64_COPY: | |
4116 | return reloc_class_copy; | |
4117 | default: | |
4118 | return reloc_class_normal; | |
4119 | } | |
4120 | } | |
4121 | ||
70256ad8 AJ |
4122 | /* Finish up the dynamic sections. */ |
4123 | ||
b34976b6 | 4124 | static bfd_boolean |
27482721 | 4125 | elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) |
70256ad8 | 4126 | { |
c434dee6 | 4127 | struct elf64_x86_64_link_hash_table *htab; |
70256ad8 AJ |
4128 | bfd *dynobj; |
4129 | asection *sdyn; | |
70256ad8 | 4130 | |
c434dee6 AJ |
4131 | htab = elf64_x86_64_hash_table (info); |
4132 | dynobj = htab->elf.dynobj; | |
70256ad8 AJ |
4133 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
4134 | ||
c434dee6 | 4135 | if (htab->elf.dynamic_sections_created) |
70256ad8 | 4136 | { |
70256ad8 AJ |
4137 | Elf64_External_Dyn *dyncon, *dynconend; |
4138 | ||
6de2ae4a | 4139 | if (sdyn == NULL || htab->elf.sgot == NULL) |
c434dee6 | 4140 | abort (); |
70256ad8 AJ |
4141 | |
4142 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
eea6121a | 4143 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
70256ad8 AJ |
4144 | for (; dyncon < dynconend; dyncon++) |
4145 | { | |
4146 | Elf_Internal_Dyn dyn; | |
70256ad8 AJ |
4147 | asection *s; |
4148 | ||
4149 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
4150 | ||
4151 | switch (dyn.d_tag) | |
4152 | { | |
4153 | default: | |
053579d7 | 4154 | continue; |
70256ad8 AJ |
4155 | |
4156 | case DT_PLTGOT: | |
6de2ae4a | 4157 | s = htab->elf.sgotplt; |
8c37241b | 4158 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
c434dee6 | 4159 | break; |
70256ad8 AJ |
4160 | |
4161 | case DT_JMPREL: | |
6de2ae4a | 4162 | dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma; |
c434dee6 | 4163 | break; |
70256ad8 | 4164 | |
c434dee6 | 4165 | case DT_PLTRELSZ: |
6de2ae4a | 4166 | s = htab->elf.srelplt->output_section; |
eea6121a | 4167 | dyn.d_un.d_val = s->size; |
70256ad8 AJ |
4168 | break; |
4169 | ||
4170 | case DT_RELASZ: | |
c434dee6 AJ |
4171 | /* The procedure linkage table relocs (DT_JMPREL) should |
4172 | not be included in the overall relocs (DT_RELA). | |
4173 | Therefore, we override the DT_RELASZ entry here to | |
4174 | make it not include the JMPREL relocs. Since the | |
4175 | linker script arranges for .rela.plt to follow all | |
4176 | other relocation sections, we don't have to worry | |
4177 | about changing the DT_RELA entry. */ | |
6de2ae4a | 4178 | if (htab->elf.srelplt != NULL) |
70256ad8 | 4179 | { |
6de2ae4a | 4180 | s = htab->elf.srelplt->output_section; |
eea6121a | 4181 | dyn.d_un.d_val -= s->size; |
70256ad8 AJ |
4182 | } |
4183 | break; | |
67a4f2b7 AO |
4184 | |
4185 | case DT_TLSDESC_PLT: | |
6de2ae4a | 4186 | s = htab->elf.splt; |
67a4f2b7 AO |
4187 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
4188 | + htab->tlsdesc_plt; | |
4189 | break; | |
4190 | ||
4191 | case DT_TLSDESC_GOT: | |
6de2ae4a | 4192 | s = htab->elf.sgot; |
67a4f2b7 AO |
4193 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
4194 | + htab->tlsdesc_got; | |
4195 | break; | |
70256ad8 | 4196 | } |
c434dee6 | 4197 | |
70256ad8 AJ |
4198 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
4199 | } | |
4200 | ||
c434dee6 | 4201 | /* Fill in the special first entry in the procedure linkage table. */ |
6de2ae4a | 4202 | if (htab->elf.splt && htab->elf.splt->size > 0) |
70256ad8 | 4203 | { |
653165cc | 4204 | /* Fill in the first entry in the procedure linkage table. */ |
6de2ae4a | 4205 | memcpy (htab->elf.splt->contents, elf64_x86_64_plt0_entry, |
c434dee6 | 4206 | PLT_ENTRY_SIZE); |
653165cc AJ |
4207 | /* Add offset for pushq GOT+8(%rip), since the instruction |
4208 | uses 6 bytes subtract this value. */ | |
4209 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
4210 | (htab->elf.sgotplt->output_section->vma |
4211 | + htab->elf.sgotplt->output_offset | |
653165cc | 4212 | + 8 |
6de2ae4a L |
4213 | - htab->elf.splt->output_section->vma |
4214 | - htab->elf.splt->output_offset | |
653165cc | 4215 | - 6), |
6de2ae4a | 4216 | htab->elf.splt->contents + 2); |
653165cc AJ |
4217 | /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to |
4218 | the end of the instruction. */ | |
4219 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
4220 | (htab->elf.sgotplt->output_section->vma |
4221 | + htab->elf.sgotplt->output_offset | |
653165cc | 4222 | + 16 |
6de2ae4a L |
4223 | - htab->elf.splt->output_section->vma |
4224 | - htab->elf.splt->output_offset | |
653165cc | 4225 | - 12), |
6de2ae4a | 4226 | htab->elf.splt->contents + 8); |
653165cc | 4227 | |
6de2ae4a | 4228 | elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize = |
c434dee6 | 4229 | PLT_ENTRY_SIZE; |
67a4f2b7 AO |
4230 | |
4231 | if (htab->tlsdesc_plt) | |
4232 | { | |
4233 | bfd_put_64 (output_bfd, (bfd_vma) 0, | |
6de2ae4a | 4234 | htab->elf.sgot->contents + htab->tlsdesc_got); |
67a4f2b7 | 4235 | |
6de2ae4a | 4236 | memcpy (htab->elf.splt->contents + htab->tlsdesc_plt, |
67a4f2b7 AO |
4237 | elf64_x86_64_plt0_entry, |
4238 | PLT_ENTRY_SIZE); | |
4239 | ||
4240 | /* Add offset for pushq GOT+8(%rip), since the | |
4241 | instruction uses 6 bytes subtract this value. */ | |
4242 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
4243 | (htab->elf.sgotplt->output_section->vma |
4244 | + htab->elf.sgotplt->output_offset | |
67a4f2b7 | 4245 | + 8 |
6de2ae4a L |
4246 | - htab->elf.splt->output_section->vma |
4247 | - htab->elf.splt->output_offset | |
67a4f2b7 AO |
4248 | - htab->tlsdesc_plt |
4249 | - 6), | |
6de2ae4a | 4250 | htab->elf.splt->contents + htab->tlsdesc_plt + 2); |
67a4f2b7 AO |
4251 | /* Add offset for jmp *GOT+TDG(%rip), where TGD stands for |
4252 | htab->tlsdesc_got. The 12 is the offset to the end of | |
4253 | the instruction. */ | |
4254 | bfd_put_32 (output_bfd, | |
6de2ae4a L |
4255 | (htab->elf.sgot->output_section->vma |
4256 | + htab->elf.sgot->output_offset | |
67a4f2b7 | 4257 | + htab->tlsdesc_got |
6de2ae4a L |
4258 | - htab->elf.splt->output_section->vma |
4259 | - htab->elf.splt->output_offset | |
67a4f2b7 AO |
4260 | - htab->tlsdesc_plt |
4261 | - 12), | |
6de2ae4a | 4262 | htab->elf.splt->contents + htab->tlsdesc_plt + 8); |
67a4f2b7 | 4263 | } |
70256ad8 | 4264 | } |
70256ad8 AJ |
4265 | } |
4266 | ||
6de2ae4a | 4267 | if (htab->elf.sgotplt) |
70256ad8 | 4268 | { |
c434dee6 | 4269 | /* Fill in the first three entries in the global offset table. */ |
6de2ae4a | 4270 | if (htab->elf.sgotplt->size > 0) |
c434dee6 AJ |
4271 | { |
4272 | /* Set the first entry in the global offset table to the address of | |
4273 | the dynamic section. */ | |
4274 | if (sdyn == NULL) | |
6de2ae4a | 4275 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents); |
c434dee6 AJ |
4276 | else |
4277 | bfd_put_64 (output_bfd, | |
4278 | sdyn->output_section->vma + sdyn->output_offset, | |
6de2ae4a | 4279 | htab->elf.sgotplt->contents); |
c434dee6 | 4280 | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ |
6de2ae4a L |
4281 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE); |
4282 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + GOT_ENTRY_SIZE*2); | |
c434dee6 | 4283 | } |
70256ad8 | 4284 | |
6de2ae4a | 4285 | elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize = |
c434dee6 AJ |
4286 | GOT_ENTRY_SIZE; |
4287 | } | |
70256ad8 | 4288 | |
6de2ae4a L |
4289 | if (htab->elf.sgot && htab->elf.sgot->size > 0) |
4290 | elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize | |
8c37241b JJ |
4291 | = GOT_ENTRY_SIZE; |
4292 | ||
c25bc9fc L |
4293 | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
4294 | htab_traverse (htab->loc_hash_table, | |
4295 | elf64_x86_64_finish_local_dynamic_symbol, | |
4296 | info); | |
4297 | ||
b34976b6 | 4298 | return TRUE; |
8d88c4ca NC |
4299 | } |
4300 | ||
4c45e5c9 JJ |
4301 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
4302 | or (bfd_vma) -1 if it should not be included. */ | |
4303 | ||
4304 | static bfd_vma | |
4305 | elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt, | |
4306 | const arelent *rel ATTRIBUTE_UNUSED) | |
4307 | { | |
4308 | return plt->vma + (i + 1) * PLT_ENTRY_SIZE; | |
4309 | } | |
8df9fc9d | 4310 | |
d2b2c203 DJ |
4311 | /* Handle an x86-64 specific section when reading an object file. This |
4312 | is called when elfcode.h finds a section with an unknown type. */ | |
4313 | ||
4314 | static bfd_boolean | |
6dc132d9 L |
4315 | elf64_x86_64_section_from_shdr (bfd *abfd, |
4316 | Elf_Internal_Shdr *hdr, | |
4317 | const char *name, | |
4318 | int shindex) | |
d2b2c203 DJ |
4319 | { |
4320 | if (hdr->sh_type != SHT_X86_64_UNWIND) | |
4321 | return FALSE; | |
4322 | ||
6dc132d9 | 4323 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
d2b2c203 DJ |
4324 | return FALSE; |
4325 | ||
4326 | return TRUE; | |
4327 | } | |
4328 | ||
3b22753a L |
4329 | /* Hook called by the linker routine which adds symbols from an object |
4330 | file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead | |
4331 | of .bss. */ | |
4332 | ||
4333 | static bfd_boolean | |
4334 | elf64_x86_64_add_symbol_hook (bfd *abfd, | |
d8045f23 | 4335 | struct bfd_link_info *info, |
3b22753a L |
4336 | Elf_Internal_Sym *sym, |
4337 | const char **namep ATTRIBUTE_UNUSED, | |
4338 | flagword *flagsp ATTRIBUTE_UNUSED, | |
d8045f23 NC |
4339 | asection **secp, |
4340 | bfd_vma *valp) | |
3b22753a L |
4341 | { |
4342 | asection *lcomm; | |
4343 | ||
4344 | switch (sym->st_shndx) | |
4345 | { | |
4346 | case SHN_X86_64_LCOMMON: | |
4347 | lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON"); | |
4348 | if (lcomm == NULL) | |
4349 | { | |
4350 | lcomm = bfd_make_section_with_flags (abfd, | |
4351 | "LARGE_COMMON", | |
4352 | (SEC_ALLOC | |
4353 | | SEC_IS_COMMON | |
4354 | | SEC_LINKER_CREATED)); | |
4355 | if (lcomm == NULL) | |
4356 | return FALSE; | |
4357 | elf_section_flags (lcomm) |= SHF_X86_64_LARGE; | |
4358 | } | |
4359 | *secp = lcomm; | |
4360 | *valp = sym->st_size; | |
4361 | break; | |
4362 | } | |
d8045f23 NC |
4363 | |
4364 | if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
4365 | elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE; | |
4366 | ||
3b22753a L |
4367 | return TRUE; |
4368 | } | |
4369 | ||
4370 | ||
4371 | /* Given a BFD section, try to locate the corresponding ELF section | |
4372 | index. */ | |
4373 | ||
4374 | static bfd_boolean | |
4375 | elf64_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED, | |
4376 | asection *sec, int *index) | |
4377 | { | |
4378 | if (sec == &_bfd_elf_large_com_section) | |
4379 | { | |
4380 | *index = SHN_X86_64_LCOMMON; | |
4381 | return TRUE; | |
4382 | } | |
4383 | return FALSE; | |
4384 | } | |
4385 | ||
4386 | /* Process a symbol. */ | |
4387 | ||
4388 | static void | |
4389 | elf64_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
4390 | asymbol *asym) | |
4391 | { | |
4392 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
4393 | ||
4394 | switch (elfsym->internal_elf_sym.st_shndx) | |
4395 | { | |
4396 | case SHN_X86_64_LCOMMON: | |
4397 | asym->section = &_bfd_elf_large_com_section; | |
4398 | asym->value = elfsym->internal_elf_sym.st_size; | |
4399 | /* Common symbol doesn't set BSF_GLOBAL. */ | |
4400 | asym->flags &= ~BSF_GLOBAL; | |
4401 | break; | |
4402 | } | |
4403 | } | |
4404 | ||
4405 | static bfd_boolean | |
4406 | elf64_x86_64_common_definition (Elf_Internal_Sym *sym) | |
4407 | { | |
4408 | return (sym->st_shndx == SHN_COMMON | |
4409 | || sym->st_shndx == SHN_X86_64_LCOMMON); | |
4410 | } | |
4411 | ||
4412 | static unsigned int | |
4413 | elf64_x86_64_common_section_index (asection *sec) | |
4414 | { | |
4415 | if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0) | |
4416 | return SHN_COMMON; | |
4417 | else | |
4418 | return SHN_X86_64_LCOMMON; | |
4419 | } | |
4420 | ||
4421 | static asection * | |
4422 | elf64_x86_64_common_section (asection *sec) | |
4423 | { | |
4424 | if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0) | |
4425 | return bfd_com_section_ptr; | |
4426 | else | |
4427 | return &_bfd_elf_large_com_section; | |
4428 | } | |
4429 | ||
4430 | static bfd_boolean | |
4431 | elf64_x86_64_merge_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, | |
4432 | struct elf_link_hash_entry **sym_hash ATTRIBUTE_UNUSED, | |
4433 | struct elf_link_hash_entry *h, | |
4434 | Elf_Internal_Sym *sym, | |
00492999 | 4435 | asection **psec, |
3b22753a L |
4436 | bfd_vma *pvalue ATTRIBUTE_UNUSED, |
4437 | unsigned int *pold_alignment ATTRIBUTE_UNUSED, | |
4438 | bfd_boolean *skip ATTRIBUTE_UNUSED, | |
4439 | bfd_boolean *override ATTRIBUTE_UNUSED, | |
4440 | bfd_boolean *type_change_ok ATTRIBUTE_UNUSED, | |
4441 | bfd_boolean *size_change_ok ATTRIBUTE_UNUSED, | |
4442 | bfd_boolean *newdef ATTRIBUTE_UNUSED, | |
4443 | bfd_boolean *newdyn, | |
4444 | bfd_boolean *newdyncommon ATTRIBUTE_UNUSED, | |
4445 | bfd_boolean *newweak ATTRIBUTE_UNUSED, | |
4446 | bfd *abfd ATTRIBUTE_UNUSED, | |
4447 | asection **sec, | |
4448 | bfd_boolean *olddef ATTRIBUTE_UNUSED, | |
4449 | bfd_boolean *olddyn, | |
4450 | bfd_boolean *olddyncommon ATTRIBUTE_UNUSED, | |
4451 | bfd_boolean *oldweak ATTRIBUTE_UNUSED, | |
00492999 | 4452 | bfd *oldbfd, |
3b22753a L |
4453 | asection **oldsec) |
4454 | { | |
4455 | /* A normal common symbol and a large common symbol result in a | |
00492999 L |
4456 | normal common symbol. We turn the large common symbol into a |
4457 | normal one. */ | |
3b22753a L |
4458 | if (!*olddyn |
4459 | && h->root.type == bfd_link_hash_common | |
4460 | && !*newdyn | |
4461 | && bfd_is_com_section (*sec) | |
00492999 | 4462 | && *oldsec != *sec) |
3b22753a | 4463 | { |
00492999 L |
4464 | if (sym->st_shndx == SHN_COMMON |
4465 | && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) != 0) | |
4466 | { | |
4467 | h->root.u.c.p->section | |
4468 | = bfd_make_section_old_way (oldbfd, "COMMON"); | |
4469 | h->root.u.c.p->section->flags = SEC_ALLOC; | |
4470 | } | |
4471 | else if (sym->st_shndx == SHN_X86_64_LCOMMON | |
4472 | && (elf_section_flags (*oldsec) & SHF_X86_64_LARGE) == 0) | |
9a2e389a | 4473 | *psec = *sec = bfd_com_section_ptr; |
3b22753a L |
4474 | } |
4475 | ||
4476 | return TRUE; | |
4477 | } | |
4478 | ||
4479 | static int | |
a6b96beb AM |
4480 | elf64_x86_64_additional_program_headers (bfd *abfd, |
4481 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
3b22753a L |
4482 | { |
4483 | asection *s; | |
9a2e389a | 4484 | int count = 0; |
3b22753a L |
4485 | |
4486 | /* Check to see if we need a large readonly segment. */ | |
4487 | s = bfd_get_section_by_name (abfd, ".lrodata"); | |
4488 | if (s && (s->flags & SEC_LOAD)) | |
4489 | count++; | |
4490 | ||
4491 | /* Check to see if we need a large data segment. Since .lbss sections | |
4492 | is placed right after the .bss section, there should be no need for | |
4493 | a large data segment just because of .lbss. */ | |
4494 | s = bfd_get_section_by_name (abfd, ".ldata"); | |
4495 | if (s && (s->flags & SEC_LOAD)) | |
4496 | count++; | |
4497 | ||
4498 | return count; | |
4499 | } | |
4500 | ||
fdc90cb4 JJ |
4501 | /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ |
4502 | ||
4503 | static bfd_boolean | |
4504 | elf64_x86_64_hash_symbol (struct elf_link_hash_entry *h) | |
4505 | { | |
4506 | if (h->plt.offset != (bfd_vma) -1 | |
4507 | && !h->def_regular | |
4508 | && !h->pointer_equality_needed) | |
4509 | return FALSE; | |
4510 | ||
4511 | return _bfd_elf_hash_symbol (h); | |
4512 | } | |
4513 | ||
9a2e389a | 4514 | static const struct bfd_elf_special_section |
3b22753a L |
4515 | elf64_x86_64_special_sections[]= |
4516 | { | |
0112cd26 NC |
4517 | { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, |
4518 | { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE}, | |
4519 | { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE}, | |
4520 | { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, | |
4521 | { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, | |
4522 | { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE}, | |
4523 | { NULL, 0, 0, 0, 0 } | |
3b22753a L |
4524 | }; |
4525 | ||
70256ad8 AJ |
4526 | #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec |
4527 | #define TARGET_LITTLE_NAME "elf64-x86-64" | |
4528 | #define ELF_ARCH bfd_arch_i386 | |
4529 | #define ELF_MACHINE_CODE EM_X86_64 | |
f7661549 | 4530 | #define ELF_MAXPAGESIZE 0x200000 |
2043964e | 4531 | #define ELF_MINPAGESIZE 0x1000 |
24718e3b | 4532 | #define ELF_COMMONPAGESIZE 0x1000 |
70256ad8 AJ |
4533 | |
4534 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 4535 | #define elf_backend_can_refcount 1 |
70256ad8 AJ |
4536 | #define elf_backend_want_got_plt 1 |
4537 | #define elf_backend_plt_readonly 1 | |
4538 | #define elf_backend_want_plt_sym 0 | |
4539 | #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3) | |
b491616a | 4540 | #define elf_backend_rela_normal 1 |
70256ad8 AJ |
4541 | |
4542 | #define elf_info_to_howto elf64_x86_64_info_to_howto | |
70256ad8 | 4543 | |
70256ad8 AJ |
4544 | #define bfd_elf64_bfd_link_hash_table_create \ |
4545 | elf64_x86_64_link_hash_table_create | |
c25bc9fc L |
4546 | #define bfd_elf64_bfd_link_hash_table_free \ |
4547 | elf64_x86_64_link_hash_table_free | |
407443a3 | 4548 | #define bfd_elf64_bfd_reloc_type_lookup elf64_x86_64_reloc_type_lookup |
157090f7 AM |
4549 | #define bfd_elf64_bfd_reloc_name_lookup \ |
4550 | elf64_x86_64_reloc_name_lookup | |
70256ad8 AJ |
4551 | |
4552 | #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol | |
13285a1b | 4553 | #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible |
70256ad8 | 4554 | #define elf_backend_check_relocs elf64_x86_64_check_relocs |
c434dee6 AJ |
4555 | #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol |
4556 | #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections | |
4557 | #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections | |
70256ad8 AJ |
4558 | #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol |
4559 | #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook | |
4560 | #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook | |
3bab7989 ML |
4561 | #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus |
4562 | #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo | |
c434dee6 | 4563 | #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class |
70256ad8 AJ |
4564 | #define elf_backend_relocate_section elf64_x86_64_relocate_section |
4565 | #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections | |
67a4f2b7 | 4566 | #define elf_backend_always_size_sections elf64_x86_64_always_size_sections |
74541ad4 | 4567 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
4c45e5c9 | 4568 | #define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val |
407443a3 | 4569 | #define elf_backend_object_p elf64_x86_64_elf_object_p |
bffbf940 | 4570 | #define bfd_elf64_mkobject elf64_x86_64_mkobject |
8d88c4ca | 4571 | |
d2b2c203 DJ |
4572 | #define elf_backend_section_from_shdr \ |
4573 | elf64_x86_64_section_from_shdr | |
4574 | ||
3b22753a L |
4575 | #define elf_backend_section_from_bfd_section \ |
4576 | elf64_x86_64_elf_section_from_bfd_section | |
4577 | #define elf_backend_add_symbol_hook \ | |
4578 | elf64_x86_64_add_symbol_hook | |
4579 | #define elf_backend_symbol_processing \ | |
4580 | elf64_x86_64_symbol_processing | |
4581 | #define elf_backend_common_section_index \ | |
4582 | elf64_x86_64_common_section_index | |
4583 | #define elf_backend_common_section \ | |
4584 | elf64_x86_64_common_section | |
4585 | #define elf_backend_common_definition \ | |
4586 | elf64_x86_64_common_definition | |
4587 | #define elf_backend_merge_symbol \ | |
4588 | elf64_x86_64_merge_symbol | |
4589 | #define elf_backend_special_sections \ | |
4590 | elf64_x86_64_special_sections | |
4591 | #define elf_backend_additional_program_headers \ | |
4592 | elf64_x86_64_additional_program_headers | |
fdc90cb4 JJ |
4593 | #define elf_backend_hash_symbol \ |
4594 | elf64_x86_64_hash_symbol | |
3b22753a | 4595 | |
d8045f23 NC |
4596 | #undef elf_backend_post_process_headers |
4597 | #define elf_backend_post_process_headers _bfd_elf_set_osabi | |
4598 | ||
8d88c4ca | 4599 | #include "elf64-target.h" |
9d7cbccd NC |
4600 | |
4601 | /* FreeBSD support. */ | |
4602 | ||
4603 | #undef TARGET_LITTLE_SYM | |
4604 | #define TARGET_LITTLE_SYM bfd_elf64_x86_64_freebsd_vec | |
4605 | #undef TARGET_LITTLE_NAME | |
4606 | #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd" | |
4607 | ||
d1036acb L |
4608 | #undef ELF_OSABI |
4609 | #define ELF_OSABI ELFOSABI_FREEBSD | |
9d7cbccd | 4610 | |
9d7cbccd NC |
4611 | #undef elf64_bed |
4612 | #define elf64_bed elf64_x86_64_fbsd_bed | |
4613 | ||
4614 | #include "elf64-target.h" |