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