/src/binutils-gdb/bfd/elf64-x86-64.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* X86-64 specific support for ELF |
2 | | Copyright (C) 2000-2023 Free Software Foundation, Inc. |
3 | | Contributed by Jan Hubicka <jh@suse.cz>. |
4 | | |
5 | | This file is part of BFD, the Binary File Descriptor library. |
6 | | |
7 | | This program is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3 of the License, or |
10 | | (at your option) any later version. |
11 | | |
12 | | This program is distributed in the hope that it will be useful, |
13 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | GNU General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this program; if not, write to the Free Software |
19 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | | MA 02110-1301, USA. */ |
21 | | |
22 | | #include "elfxx-x86.h" |
23 | | #include "dwarf2.h" |
24 | | #include "libiberty.h" |
25 | | #include "sframe.h" |
26 | | |
27 | | #include "opcode/i386.h" |
28 | | |
29 | | #ifdef CORE_HEADER |
30 | | #include <stdarg.h> |
31 | | #include CORE_HEADER |
32 | | #endif |
33 | | |
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 | | /* Since both 32-bit and 64-bit x86-64 encode relocation type in the |
38 | | identical manner, we use ELF32_R_TYPE instead of ELF64_R_TYPE to get |
39 | | relocation type. We also use ELF_ST_TYPE instead of ELF64_ST_TYPE |
40 | | since they are the same. */ |
41 | | |
42 | | /* The relocation "howto" table. Order of fields: |
43 | | type, rightshift, size, bitsize, pc_relative, bitpos, complain_on_overflow, |
44 | | special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */ |
45 | | static reloc_howto_type x86_64_elf_howto_table[] = |
46 | | { |
47 | | HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont, |
48 | | bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0, 0x00000000, |
49 | | false), |
50 | | HOWTO(R_X86_64_64, 0, 8, 64, false, 0, complain_overflow_dont, |
51 | | bfd_elf_generic_reloc, "R_X86_64_64", false, 0, MINUS_ONE, |
52 | | false), |
53 | | HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed, |
54 | | bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0, 0xffffffff, |
55 | | true), |
56 | | HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed, |
57 | | bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0, 0xffffffff, |
58 | | false), |
59 | | HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed, |
60 | | bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0, 0xffffffff, |
61 | | true), |
62 | | HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield, |
63 | | bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0, 0xffffffff, |
64 | | false), |
65 | | HOWTO(R_X86_64_GLOB_DAT, 0, 8, 64, false, 0, complain_overflow_dont, |
66 | | bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, 0, MINUS_ONE, |
67 | | false), |
68 | | HOWTO(R_X86_64_JUMP_SLOT, 0, 8, 64, false, 0, complain_overflow_dont, |
69 | | bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, 0, MINUS_ONE, |
70 | | false), |
71 | | HOWTO(R_X86_64_RELATIVE, 0, 8, 64, false, 0, complain_overflow_dont, |
72 | | bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, 0, MINUS_ONE, |
73 | | false), |
74 | | HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true, 0, complain_overflow_signed, |
75 | | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0, 0xffffffff, |
76 | | true), |
77 | | HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned, |
78 | | bfd_elf_generic_reloc, "R_X86_64_32", false, 0, 0xffffffff, |
79 | | false), |
80 | | HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed, |
81 | | bfd_elf_generic_reloc, "R_X86_64_32S", false, 0, 0xffffffff, |
82 | | false), |
83 | | HOWTO(R_X86_64_16, 0, 2, 16, false, 0, complain_overflow_bitfield, |
84 | | bfd_elf_generic_reloc, "R_X86_64_16", false, 0, 0xffff, false), |
85 | | HOWTO(R_X86_64_PC16, 0, 2, 16, true, 0, complain_overflow_bitfield, |
86 | | bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0, 0xffff, true), |
87 | | HOWTO(R_X86_64_8, 0, 1, 8, false, 0, complain_overflow_bitfield, |
88 | | bfd_elf_generic_reloc, "R_X86_64_8", false, 0, 0xff, false), |
89 | | HOWTO(R_X86_64_PC8, 0, 1, 8, true, 0, complain_overflow_signed, |
90 | | bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0, 0xff, true), |
91 | | HOWTO(R_X86_64_DTPMOD64, 0, 8, 64, false, 0, complain_overflow_dont, |
92 | | bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", false, 0, MINUS_ONE, |
93 | | false), |
94 | | HOWTO(R_X86_64_DTPOFF64, 0, 8, 64, false, 0, complain_overflow_dont, |
95 | | bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", false, 0, MINUS_ONE, |
96 | | false), |
97 | | HOWTO(R_X86_64_TPOFF64, 0, 8, 64, false, 0, complain_overflow_dont, |
98 | | bfd_elf_generic_reloc, "R_X86_64_TPOFF64", false, 0, MINUS_ONE, |
99 | | false), |
100 | | HOWTO(R_X86_64_TLSGD, 0, 4, 32, true, 0, complain_overflow_signed, |
101 | | bfd_elf_generic_reloc, "R_X86_64_TLSGD", false, 0, 0xffffffff, |
102 | | true), |
103 | | HOWTO(R_X86_64_TLSLD, 0, 4, 32, true, 0, complain_overflow_signed, |
104 | | bfd_elf_generic_reloc, "R_X86_64_TLSLD", false, 0, 0xffffffff, |
105 | | true), |
106 | | HOWTO(R_X86_64_DTPOFF32, 0, 4, 32, false, 0, complain_overflow_signed, |
107 | | bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", false, 0, 0xffffffff, |
108 | | false), |
109 | | HOWTO(R_X86_64_GOTTPOFF, 0, 4, 32, true, 0, complain_overflow_signed, |
110 | | bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", false, 0, 0xffffffff, |
111 | | true), |
112 | | HOWTO(R_X86_64_TPOFF32, 0, 4, 32, false, 0, complain_overflow_signed, |
113 | | bfd_elf_generic_reloc, "R_X86_64_TPOFF32", false, 0, 0xffffffff, |
114 | | false), |
115 | | HOWTO(R_X86_64_PC64, 0, 8, 64, true, 0, complain_overflow_dont, |
116 | | bfd_elf_generic_reloc, "R_X86_64_PC64", false, 0, MINUS_ONE, |
117 | | true), |
118 | | HOWTO(R_X86_64_GOTOFF64, 0, 8, 64, false, 0, complain_overflow_dont, |
119 | | bfd_elf_generic_reloc, "R_X86_64_GOTOFF64", false, 0, MINUS_ONE, |
120 | | false), |
121 | | HOWTO(R_X86_64_GOTPC32, 0, 4, 32, true, 0, complain_overflow_signed, |
122 | | bfd_elf_generic_reloc, "R_X86_64_GOTPC32", false, 0, 0xffffffff, |
123 | | true), |
124 | | HOWTO(R_X86_64_GOT64, 0, 8, 64, false, 0, complain_overflow_signed, |
125 | | bfd_elf_generic_reloc, "R_X86_64_GOT64", false, 0, MINUS_ONE, |
126 | | false), |
127 | | HOWTO(R_X86_64_GOTPCREL64, 0, 8, 64, true, 0, complain_overflow_signed, |
128 | | bfd_elf_generic_reloc, "R_X86_64_GOTPCREL64", false, 0, MINUS_ONE, |
129 | | true), |
130 | | HOWTO(R_X86_64_GOTPC64, 0, 8, 64, true, 0, complain_overflow_signed, |
131 | | bfd_elf_generic_reloc, "R_X86_64_GOTPC64", false, 0, MINUS_ONE, |
132 | | true), |
133 | | HOWTO(R_X86_64_GOTPLT64, 0, 8, 64, false, 0, complain_overflow_signed, |
134 | | bfd_elf_generic_reloc, "R_X86_64_GOTPLT64", false, 0, MINUS_ONE, |
135 | | false), |
136 | | HOWTO(R_X86_64_PLTOFF64, 0, 8, 64, false, 0, complain_overflow_signed, |
137 | | bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", false, 0, MINUS_ONE, |
138 | | false), |
139 | | HOWTO(R_X86_64_SIZE32, 0, 4, 32, false, 0, complain_overflow_unsigned, |
140 | | bfd_elf_generic_reloc, "R_X86_64_SIZE32", false, 0, 0xffffffff, |
141 | | false), |
142 | | HOWTO(R_X86_64_SIZE64, 0, 8, 64, false, 0, complain_overflow_dont, |
143 | | bfd_elf_generic_reloc, "R_X86_64_SIZE64", false, 0, MINUS_ONE, |
144 | | false), |
145 | | HOWTO(R_X86_64_GOTPC32_TLSDESC, 0, 4, 32, true, 0, |
146 | | complain_overflow_bitfield, bfd_elf_generic_reloc, |
147 | | "R_X86_64_GOTPC32_TLSDESC", false, 0, 0xffffffff, true), |
148 | | HOWTO(R_X86_64_TLSDESC_CALL, 0, 0, 0, false, 0, |
149 | | complain_overflow_dont, bfd_elf_generic_reloc, |
150 | | "R_X86_64_TLSDESC_CALL", |
151 | | false, 0, 0, false), |
152 | | HOWTO(R_X86_64_TLSDESC, 0, 8, 64, false, 0, |
153 | | complain_overflow_dont, bfd_elf_generic_reloc, |
154 | | "R_X86_64_TLSDESC", false, 0, MINUS_ONE, false), |
155 | | HOWTO(R_X86_64_IRELATIVE, 0, 8, 64, false, 0, complain_overflow_dont, |
156 | | bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", false, 0, MINUS_ONE, |
157 | | false), |
158 | | HOWTO(R_X86_64_RELATIVE64, 0, 8, 64, false, 0, complain_overflow_dont, |
159 | | bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", false, 0, MINUS_ONE, |
160 | | false), |
161 | | HOWTO(R_X86_64_PC32_BND, 0, 4, 32, true, 0, complain_overflow_signed, |
162 | | bfd_elf_generic_reloc, "R_X86_64_PC32_BND", false, 0, 0xffffffff, |
163 | | true), |
164 | | HOWTO(R_X86_64_PLT32_BND, 0, 4, 32, true, 0, complain_overflow_signed, |
165 | | bfd_elf_generic_reloc, "R_X86_64_PLT32_BND", false, 0, 0xffffffff, |
166 | | true), |
167 | | HOWTO(R_X86_64_GOTPCRELX, 0, 4, 32, true, 0, complain_overflow_signed, |
168 | | bfd_elf_generic_reloc, "R_X86_64_GOTPCRELX", false, 0, 0xffffffff, |
169 | | true), |
170 | | HOWTO(R_X86_64_REX_GOTPCRELX, 0, 4, 32, true, 0, complain_overflow_signed, |
171 | | bfd_elf_generic_reloc, "R_X86_64_REX_GOTPCRELX", false, 0, 0xffffffff, |
172 | | true), |
173 | | |
174 | | /* We have a gap in the reloc numbers here. |
175 | | R_X86_64_standard counts the number up to this point, and |
176 | | R_X86_64_vt_offset is the value to subtract from a reloc type of |
177 | | R_X86_64_GNU_VT* to form an index into this table. */ |
178 | 257k | #define R_X86_64_standard (R_X86_64_REX_GOTPCRELX + 1) |
179 | 31 | #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard) |
180 | | |
181 | | /* GNU extension to record C++ vtable hierarchy. */ |
182 | | HOWTO (R_X86_64_GNU_VTINHERIT, 0, 8, 0, false, 0, complain_overflow_dont, |
183 | | NULL, "R_X86_64_GNU_VTINHERIT", false, 0, 0, false), |
184 | | |
185 | | /* GNU extension to record C++ vtable member usage. */ |
186 | | HOWTO (R_X86_64_GNU_VTENTRY, 0, 8, 0, false, 0, complain_overflow_dont, |
187 | | _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", false, 0, 0, |
188 | | false), |
189 | | |
190 | | /* Use complain_overflow_bitfield on R_X86_64_32 for x32. */ |
191 | | HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_bitfield, |
192 | | bfd_elf_generic_reloc, "R_X86_64_32", false, 0, 0xffffffff, |
193 | | false) |
194 | | }; |
195 | | |
196 | | /* Map BFD relocs to the x86_64 elf relocs. */ |
197 | | struct elf_reloc_map |
198 | | { |
199 | | bfd_reloc_code_real_type bfd_reloc_val; |
200 | | unsigned char elf_reloc_val; |
201 | | }; |
202 | | |
203 | | static const struct elf_reloc_map x86_64_reloc_map[] = |
204 | | { |
205 | | { BFD_RELOC_NONE, R_X86_64_NONE, }, |
206 | | { BFD_RELOC_64, R_X86_64_64, }, |
207 | | { BFD_RELOC_32_PCREL, R_X86_64_PC32, }, |
208 | | { BFD_RELOC_X86_64_GOT32, R_X86_64_GOT32,}, |
209 | | { BFD_RELOC_X86_64_PLT32, R_X86_64_PLT32,}, |
210 | | { BFD_RELOC_X86_64_COPY, R_X86_64_COPY, }, |
211 | | { BFD_RELOC_X86_64_GLOB_DAT, R_X86_64_GLOB_DAT, }, |
212 | | { BFD_RELOC_X86_64_JUMP_SLOT, R_X86_64_JUMP_SLOT, }, |
213 | | { BFD_RELOC_X86_64_RELATIVE, R_X86_64_RELATIVE, }, |
214 | | { BFD_RELOC_X86_64_GOTPCREL, R_X86_64_GOTPCREL, }, |
215 | | { BFD_RELOC_32, R_X86_64_32, }, |
216 | | { BFD_RELOC_X86_64_32S, R_X86_64_32S, }, |
217 | | { BFD_RELOC_16, R_X86_64_16, }, |
218 | | { BFD_RELOC_16_PCREL, R_X86_64_PC16, }, |
219 | | { BFD_RELOC_8, R_X86_64_8, }, |
220 | | { BFD_RELOC_8_PCREL, R_X86_64_PC8, }, |
221 | | { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, }, |
222 | | { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, }, |
223 | | { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, }, |
224 | | { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, }, |
225 | | { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, }, |
226 | | { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, }, |
227 | | { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, }, |
228 | | { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, }, |
229 | | { BFD_RELOC_64_PCREL, R_X86_64_PC64, }, |
230 | | { BFD_RELOC_X86_64_GOTOFF64, R_X86_64_GOTOFF64, }, |
231 | | { BFD_RELOC_X86_64_GOTPC32, R_X86_64_GOTPC32, }, |
232 | | { BFD_RELOC_X86_64_GOT64, R_X86_64_GOT64, }, |
233 | | { BFD_RELOC_X86_64_GOTPCREL64,R_X86_64_GOTPCREL64, }, |
234 | | { BFD_RELOC_X86_64_GOTPC64, R_X86_64_GOTPC64, }, |
235 | | { BFD_RELOC_X86_64_GOTPLT64, R_X86_64_GOTPLT64, }, |
236 | | { BFD_RELOC_X86_64_PLTOFF64, R_X86_64_PLTOFF64, }, |
237 | | { BFD_RELOC_SIZE32, R_X86_64_SIZE32, }, |
238 | | { BFD_RELOC_SIZE64, R_X86_64_SIZE64, }, |
239 | | { BFD_RELOC_X86_64_GOTPC32_TLSDESC, R_X86_64_GOTPC32_TLSDESC, }, |
240 | | { BFD_RELOC_X86_64_TLSDESC_CALL, R_X86_64_TLSDESC_CALL, }, |
241 | | { BFD_RELOC_X86_64_TLSDESC, R_X86_64_TLSDESC, }, |
242 | | { BFD_RELOC_X86_64_IRELATIVE, R_X86_64_IRELATIVE, }, |
243 | | { BFD_RELOC_X86_64_PC32_BND, R_X86_64_PC32_BND, }, |
244 | | { BFD_RELOC_X86_64_PLT32_BND, R_X86_64_PLT32_BND, }, |
245 | | { BFD_RELOC_X86_64_GOTPCRELX, R_X86_64_GOTPCRELX, }, |
246 | | { BFD_RELOC_X86_64_REX_GOTPCRELX, R_X86_64_REX_GOTPCRELX, }, |
247 | | { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, }, |
248 | | { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, |
249 | | }; |
250 | | |
251 | | static reloc_howto_type * |
252 | | elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type) |
253 | 281k | { |
254 | 281k | unsigned i; |
255 | | |
256 | 281k | if (r_type == (unsigned int) R_X86_64_32) |
257 | 24.3k | { |
258 | 24.3k | if (ABI_64_P (abfd)) |
259 | 24.3k | i = r_type; |
260 | 0 | else |
261 | 0 | i = ARRAY_SIZE (x86_64_elf_howto_table) - 1; |
262 | 24.3k | } |
263 | 257k | else if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT |
264 | 257k | || r_type >= (unsigned int) R_X86_64_max) |
265 | 257k | { |
266 | 257k | if (r_type >= (unsigned int) R_X86_64_standard) |
267 | 606 | { |
268 | | /* xgettext:c-format */ |
269 | 606 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
270 | 606 | abfd, r_type); |
271 | 606 | bfd_set_error (bfd_error_bad_value); |
272 | 606 | return NULL; |
273 | 606 | } |
274 | 256k | i = r_type; |
275 | 256k | } |
276 | 31 | else |
277 | 31 | i = r_type - (unsigned int) R_X86_64_vt_offset; |
278 | 281k | BFD_ASSERT (x86_64_elf_howto_table[i].type == r_type); |
279 | 281k | return &x86_64_elf_howto_table[i]; |
280 | 281k | } |
281 | | |
282 | | /* Given a BFD reloc type, return a HOWTO structure. */ |
283 | | static reloc_howto_type * |
284 | | elf_x86_64_reloc_type_lookup (bfd *abfd, |
285 | | bfd_reloc_code_real_type code) |
286 | 0 | { |
287 | 0 | unsigned int i; |
288 | |
|
289 | 0 | for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map); |
290 | 0 | i++) |
291 | 0 | { |
292 | 0 | if (x86_64_reloc_map[i].bfd_reloc_val == code) |
293 | 0 | return elf_x86_64_rtype_to_howto (abfd, |
294 | 0 | x86_64_reloc_map[i].elf_reloc_val); |
295 | 0 | } |
296 | 0 | return NULL; |
297 | 0 | } |
298 | | |
299 | | static reloc_howto_type * |
300 | | elf_x86_64_reloc_name_lookup (bfd *abfd, |
301 | | const char *r_name) |
302 | 0 | { |
303 | 0 | unsigned int i; |
304 | |
|
305 | 0 | if (!ABI_64_P (abfd) && strcasecmp (r_name, "R_X86_64_32") == 0) |
306 | 0 | { |
307 | | /* Get x32 R_X86_64_32. */ |
308 | 0 | reloc_howto_type *reloc |
309 | 0 | = &x86_64_elf_howto_table[ARRAY_SIZE (x86_64_elf_howto_table) - 1]; |
310 | 0 | BFD_ASSERT (reloc->type == (unsigned int) R_X86_64_32); |
311 | 0 | return reloc; |
312 | 0 | } |
313 | | |
314 | 0 | for (i = 0; i < ARRAY_SIZE (x86_64_elf_howto_table); i++) |
315 | 0 | if (x86_64_elf_howto_table[i].name != NULL |
316 | 0 | && strcasecmp (x86_64_elf_howto_table[i].name, r_name) == 0) |
317 | 0 | return &x86_64_elf_howto_table[i]; |
318 | | |
319 | 0 | return NULL; |
320 | 0 | } |
321 | | |
322 | | /* Given an x86_64 ELF reloc type, fill in an arelent structure. */ |
323 | | |
324 | | static bool |
325 | | elf_x86_64_info_to_howto (bfd *abfd, arelent *cache_ptr, |
326 | | Elf_Internal_Rela *dst) |
327 | 281k | { |
328 | 281k | unsigned r_type; |
329 | | |
330 | 281k | r_type = ELF32_R_TYPE (dst->r_info); |
331 | 281k | cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type); |
332 | 281k | if (cache_ptr->howto == NULL) |
333 | 606 | return false; |
334 | 281k | BFD_ASSERT (r_type == cache_ptr->howto->type || cache_ptr->howto->type == R_X86_64_NONE); |
335 | 281k | return true; |
336 | 281k | } |
337 | | |
338 | | /* Support for core dump NOTE sections. */ |
339 | | static bool |
340 | | elf_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
341 | 0 | { |
342 | 0 | int offset; |
343 | 0 | size_t size; |
344 | |
|
345 | 0 | switch (note->descsz) |
346 | 0 | { |
347 | 0 | default: |
348 | 0 | return false; |
349 | | |
350 | 0 | case 296: /* sizeof(istruct elf_prstatus) on Linux/x32 */ |
351 | | /* pr_cursig */ |
352 | 0 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
353 | | |
354 | | /* pr_pid */ |
355 | 0 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24); |
356 | | |
357 | | /* pr_reg */ |
358 | 0 | offset = 72; |
359 | 0 | size = 216; |
360 | |
|
361 | 0 | break; |
362 | | |
363 | 0 | case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */ |
364 | | /* pr_cursig */ |
365 | 0 | elf_tdata (abfd)->core->signal |
366 | 0 | = bfd_get_16 (abfd, note->descdata + 12); |
367 | | |
368 | | /* pr_pid */ |
369 | 0 | elf_tdata (abfd)->core->lwpid |
370 | 0 | = bfd_get_32 (abfd, note->descdata + 32); |
371 | | |
372 | | /* pr_reg */ |
373 | 0 | offset = 112; |
374 | 0 | size = 216; |
375 | |
|
376 | 0 | break; |
377 | 0 | } |
378 | | |
379 | | /* Make a ".reg/999" section. */ |
380 | 0 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
381 | 0 | size, note->descpos + offset); |
382 | 0 | } |
383 | | |
384 | | static bool |
385 | | elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
386 | 0 | { |
387 | 0 | switch (note->descsz) |
388 | 0 | { |
389 | 0 | default: |
390 | 0 | return false; |
391 | | |
392 | 0 | case 124: |
393 | | /* sizeof (struct elf_external_linux_prpsinfo32_ugid16). */ |
394 | 0 | elf_tdata (abfd)->core->pid |
395 | 0 | = bfd_get_32 (abfd, note->descdata + 12); |
396 | 0 | elf_tdata (abfd)->core->program |
397 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
398 | 0 | elf_tdata (abfd)->core->command |
399 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
400 | 0 | break; |
401 | | |
402 | 0 | case 128: |
403 | | /* sizeof (struct elf_external_linux_prpsinfo32_ugid32). */ |
404 | 0 | elf_tdata (abfd)->core->pid |
405 | 0 | = bfd_get_32 (abfd, note->descdata + 12); |
406 | 0 | elf_tdata (abfd)->core->program |
407 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); |
408 | 0 | elf_tdata (abfd)->core->command |
409 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); |
410 | 0 | break; |
411 | | |
412 | 0 | case 136: |
413 | | /* sizeof (struct elf_prpsinfo) on Linux/x86_64. */ |
414 | 0 | elf_tdata (abfd)->core->pid |
415 | 0 | = bfd_get_32 (abfd, note->descdata + 24); |
416 | 0 | elf_tdata (abfd)->core->program |
417 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); |
418 | 0 | elf_tdata (abfd)->core->command |
419 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); |
420 | 0 | } |
421 | | |
422 | | /* Note that for some reason, a spurious space is tacked |
423 | | onto the end of the args in some (at least one anyway) |
424 | | implementations, so strip it off if it exists. */ |
425 | | |
426 | 0 | { |
427 | 0 | char *command = elf_tdata (abfd)->core->command; |
428 | 0 | int n = strlen (command); |
429 | |
|
430 | 0 | if (0 < n && command[n - 1] == ' ') |
431 | 0 | command[n - 1] = '\0'; |
432 | 0 | } |
433 | |
|
434 | 0 | return true; |
435 | 0 | } |
436 | | |
437 | | #ifdef CORE_HEADER |
438 | | # if GCC_VERSION >= 8000 |
439 | | # pragma GCC diagnostic push |
440 | | # pragma GCC diagnostic ignored "-Wstringop-truncation" |
441 | | # endif |
442 | | static char * |
443 | | elf_x86_64_write_core_note (bfd *abfd, char *buf, int *bufsiz, |
444 | | int note_type, ...) |
445 | 0 | { |
446 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
447 | 0 | va_list ap; |
448 | 0 | const char *fname, *psargs; |
449 | 0 | long pid; |
450 | 0 | int cursig; |
451 | 0 | const void *gregs; |
452 | |
|
453 | 0 | switch (note_type) |
454 | 0 | { |
455 | 0 | default: |
456 | 0 | return NULL; |
457 | | |
458 | 0 | case NT_PRPSINFO: |
459 | 0 | va_start (ap, note_type); |
460 | 0 | fname = va_arg (ap, const char *); |
461 | 0 | psargs = va_arg (ap, const char *); |
462 | 0 | va_end (ap); |
463 | |
|
464 | 0 | if (bed->s->elfclass == ELFCLASS32) |
465 | 0 | { |
466 | 0 | prpsinfo32_t data; |
467 | 0 | memset (&data, 0, sizeof (data)); |
468 | 0 | strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); |
469 | 0 | strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); |
470 | 0 | return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, |
471 | 0 | &data, sizeof (data)); |
472 | 0 | } |
473 | 0 | else |
474 | 0 | { |
475 | 0 | prpsinfo64_t data; |
476 | 0 | memset (&data, 0, sizeof (data)); |
477 | 0 | strncpy (data.pr_fname, fname, sizeof (data.pr_fname)); |
478 | 0 | strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs)); |
479 | 0 | return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, |
480 | 0 | &data, sizeof (data)); |
481 | 0 | } |
482 | | /* NOTREACHED */ |
483 | | |
484 | 0 | case NT_PRSTATUS: |
485 | 0 | va_start (ap, note_type); |
486 | 0 | pid = va_arg (ap, long); |
487 | 0 | cursig = va_arg (ap, int); |
488 | 0 | gregs = va_arg (ap, const void *); |
489 | 0 | va_end (ap); |
490 | |
|
491 | 0 | if (bed->s->elfclass == ELFCLASS32) |
492 | 0 | { |
493 | 0 | if (bed->elf_machine_code == EM_X86_64) |
494 | 0 | { |
495 | 0 | prstatusx32_t prstat; |
496 | 0 | memset (&prstat, 0, sizeof (prstat)); |
497 | 0 | prstat.pr_pid = pid; |
498 | 0 | prstat.pr_cursig = cursig; |
499 | 0 | memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); |
500 | 0 | return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, |
501 | 0 | &prstat, sizeof (prstat)); |
502 | 0 | } |
503 | 0 | else |
504 | 0 | { |
505 | 0 | prstatus32_t prstat; |
506 | 0 | memset (&prstat, 0, sizeof (prstat)); |
507 | 0 | prstat.pr_pid = pid; |
508 | 0 | prstat.pr_cursig = cursig; |
509 | 0 | memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); |
510 | 0 | return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, |
511 | 0 | &prstat, sizeof (prstat)); |
512 | 0 | } |
513 | 0 | } |
514 | 0 | else |
515 | 0 | { |
516 | 0 | prstatus64_t prstat; |
517 | 0 | memset (&prstat, 0, sizeof (prstat)); |
518 | 0 | prstat.pr_pid = pid; |
519 | 0 | prstat.pr_cursig = cursig; |
520 | 0 | memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg)); |
521 | 0 | return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type, |
522 | 0 | &prstat, sizeof (prstat)); |
523 | 0 | } |
524 | 0 | } |
525 | | /* NOTREACHED */ |
526 | 0 | } |
527 | | # if GCC_VERSION >= 8000 |
528 | | # pragma GCC diagnostic pop |
529 | | # endif |
530 | | #endif |
531 | | |
532 | | /* Functions for the x86-64 ELF linker. */ |
533 | | |
534 | | /* The size in bytes of an entry in the global offset table. */ |
535 | | |
536 | 0 | #define GOT_ENTRY_SIZE 8 |
537 | | |
538 | | /* The size in bytes of an entry in the lazy procedure linkage table. */ |
539 | | |
540 | | #define LAZY_PLT_ENTRY_SIZE 16 |
541 | | |
542 | | /* The size in bytes of an entry in the non-lazy procedure linkage |
543 | | table. */ |
544 | | |
545 | | #define NON_LAZY_PLT_ENTRY_SIZE 8 |
546 | | |
547 | | /* The first entry in a lazy procedure linkage table looks like this. |
548 | | See the SVR4 ABI i386 supplement and the x86-64 ABI to see how this |
549 | | works. */ |
550 | | |
551 | | static const bfd_byte elf_x86_64_lazy_plt0_entry[LAZY_PLT_ENTRY_SIZE] = |
552 | | { |
553 | | 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ |
554 | | 0xff, 0x25, 16, 0, 0, 0, /* jmpq *GOT+16(%rip) */ |
555 | | 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */ |
556 | | }; |
557 | | |
558 | | /* Subsequent entries in a lazy procedure linkage table look like this. */ |
559 | | |
560 | | static const bfd_byte elf_x86_64_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
561 | | { |
562 | | 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */ |
563 | | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
564 | | 0x68, /* pushq immediate */ |
565 | | 0, 0, 0, 0, /* replaced with index into relocation table. */ |
566 | | 0xe9, /* jmp relative */ |
567 | | 0, 0, 0, 0 /* replaced with offset to start of .plt0. */ |
568 | | }; |
569 | | |
570 | | /* The first entry in a lazy procedure linkage table with BND prefix |
571 | | like this. */ |
572 | | |
573 | | static const bfd_byte elf_x86_64_lazy_bnd_plt0_entry[LAZY_PLT_ENTRY_SIZE] = |
574 | | { |
575 | | 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ |
576 | | 0xf2, 0xff, 0x25, 16, 0, 0, 0, /* bnd jmpq *GOT+16(%rip) */ |
577 | | 0x0f, 0x1f, 0 /* nopl (%rax) */ |
578 | | }; |
579 | | |
580 | | /* Subsequent entries for branches with BND prefx in a lazy procedure |
581 | | linkage table look like this. */ |
582 | | |
583 | | static const bfd_byte elf_x86_64_lazy_bnd_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
584 | | { |
585 | | 0x68, 0, 0, 0, 0, /* pushq immediate */ |
586 | | 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */ |
587 | | 0x0f, 0x1f, 0x44, 0, 0 /* nopl 0(%rax,%rax,1) */ |
588 | | }; |
589 | | |
590 | | /* The first entry in the IBT-enabled lazy procedure linkage table is the |
591 | | the same as the lazy PLT with BND prefix so that bound registers are |
592 | | preserved when control is passed to dynamic linker. Subsequent |
593 | | entries for a IBT-enabled lazy procedure linkage table look like |
594 | | this. */ |
595 | | |
596 | | static const bfd_byte elf_x86_64_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
597 | | { |
598 | | 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ |
599 | | 0x68, 0, 0, 0, 0, /* pushq immediate */ |
600 | | 0xf2, 0xe9, 0, 0, 0, 0, /* bnd jmpq relative */ |
601 | | 0x90 /* nop */ |
602 | | }; |
603 | | |
604 | | /* The first entry in the x32 IBT-enabled lazy procedure linkage table |
605 | | is the same as the normal lazy PLT. Subsequent entries for an |
606 | | x32 IBT-enabled lazy procedure linkage table look like this. */ |
607 | | |
608 | | static const bfd_byte elf_x32_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
609 | | { |
610 | | 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ |
611 | | 0x68, 0, 0, 0, 0, /* pushq immediate */ |
612 | | 0xe9, 0, 0, 0, 0, /* jmpq relative */ |
613 | | 0x66, 0x90 /* xchg %ax,%ax */ |
614 | | }; |
615 | | |
616 | | /* Entries in the non-lazey procedure linkage table look like this. */ |
617 | | |
618 | | static const bfd_byte elf_x86_64_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] = |
619 | | { |
620 | | 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */ |
621 | | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
622 | | 0x66, 0x90 /* xchg %ax,%ax */ |
623 | | }; |
624 | | |
625 | | /* Entries for branches with BND prefix in the non-lazey procedure |
626 | | linkage table look like this. */ |
627 | | |
628 | | static const bfd_byte elf_x86_64_non_lazy_bnd_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] = |
629 | | { |
630 | | 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */ |
631 | | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
632 | | 0x90 /* nop */ |
633 | | }; |
634 | | |
635 | | /* Entries for branches with IBT-enabled in the non-lazey procedure |
636 | | linkage table look like this. They have the same size as the lazy |
637 | | PLT entry. */ |
638 | | |
639 | | static const bfd_byte elf_x86_64_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
640 | | { |
641 | | 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ |
642 | | 0xf2, 0xff, 0x25, /* bnd jmpq *name@GOTPC(%rip) */ |
643 | | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
644 | | 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopl 0x0(%rax,%rax,1) */ |
645 | | }; |
646 | | |
647 | | /* Entries for branches with IBT-enabled in the x32 non-lazey procedure |
648 | | linkage table look like this. They have the same size as the lazy |
649 | | PLT entry. */ |
650 | | |
651 | | static const bfd_byte elf_x32_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
652 | | { |
653 | | 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ |
654 | | 0xff, 0x25, /* jmpq *name@GOTPC(%rip) */ |
655 | | 0, 0, 0, 0, /* replaced with offset to this symbol in .got. */ |
656 | | 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */ |
657 | | }; |
658 | | |
659 | | /* The TLSDESC entry in a lazy procedure linkage table. */ |
660 | | static const bfd_byte elf_x86_64_tlsdesc_plt_entry[LAZY_PLT_ENTRY_SIZE] = |
661 | | { |
662 | | 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ |
663 | | 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ |
664 | | 0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */ |
665 | | }; |
666 | | |
667 | | /* .eh_frame covering the lazy .plt section. */ |
668 | | |
669 | | static const bfd_byte elf_x86_64_eh_frame_lazy_plt[] = |
670 | | { |
671 | | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ |
672 | | 0, 0, 0, 0, /* CIE ID */ |
673 | | 1, /* CIE version */ |
674 | | 'z', 'R', 0, /* Augmentation string */ |
675 | | 1, /* Code alignment factor */ |
676 | | 0x78, /* Data alignment factor */ |
677 | | 16, /* Return address column */ |
678 | | 1, /* Augmentation size */ |
679 | | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ |
680 | | DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */ |
681 | | DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */ |
682 | | DW_CFA_nop, DW_CFA_nop, |
683 | | |
684 | | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ |
685 | | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ |
686 | | 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */ |
687 | | 0, 0, 0, 0, /* .plt size goes here */ |
688 | | 0, /* Augmentation size */ |
689 | | DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */ |
690 | | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ |
691 | | DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */ |
692 | | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ |
693 | | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ |
694 | | 11, /* Block length */ |
695 | | DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */ |
696 | | DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */ |
697 | | DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge, |
698 | | DW_OP_lit3, DW_OP_shl, DW_OP_plus, |
699 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
700 | | }; |
701 | | |
702 | | /* .eh_frame covering the lazy BND .plt section. */ |
703 | | |
704 | | static const bfd_byte elf_x86_64_eh_frame_lazy_bnd_plt[] = |
705 | | { |
706 | | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ |
707 | | 0, 0, 0, 0, /* CIE ID */ |
708 | | 1, /* CIE version */ |
709 | | 'z', 'R', 0, /* Augmentation string */ |
710 | | 1, /* Code alignment factor */ |
711 | | 0x78, /* Data alignment factor */ |
712 | | 16, /* Return address column */ |
713 | | 1, /* Augmentation size */ |
714 | | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ |
715 | | DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */ |
716 | | DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */ |
717 | | DW_CFA_nop, DW_CFA_nop, |
718 | | |
719 | | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ |
720 | | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ |
721 | | 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */ |
722 | | 0, 0, 0, 0, /* .plt size goes here */ |
723 | | 0, /* Augmentation size */ |
724 | | DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */ |
725 | | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ |
726 | | DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */ |
727 | | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ |
728 | | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ |
729 | | 11, /* Block length */ |
730 | | DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */ |
731 | | DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */ |
732 | | DW_OP_lit15, DW_OP_and, DW_OP_lit5, DW_OP_ge, |
733 | | DW_OP_lit3, DW_OP_shl, DW_OP_plus, |
734 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
735 | | }; |
736 | | |
737 | | /* .eh_frame covering the lazy .plt section with IBT-enabled. */ |
738 | | |
739 | | static const bfd_byte elf_x86_64_eh_frame_lazy_ibt_plt[] = |
740 | | { |
741 | | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ |
742 | | 0, 0, 0, 0, /* CIE ID */ |
743 | | 1, /* CIE version */ |
744 | | 'z', 'R', 0, /* Augmentation string */ |
745 | | 1, /* Code alignment factor */ |
746 | | 0x78, /* Data alignment factor */ |
747 | | 16, /* Return address column */ |
748 | | 1, /* Augmentation size */ |
749 | | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ |
750 | | DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */ |
751 | | DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */ |
752 | | DW_CFA_nop, DW_CFA_nop, |
753 | | |
754 | | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ |
755 | | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ |
756 | | 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */ |
757 | | 0, 0, 0, 0, /* .plt size goes here */ |
758 | | 0, /* Augmentation size */ |
759 | | DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */ |
760 | | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ |
761 | | DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */ |
762 | | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ |
763 | | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ |
764 | | 11, /* Block length */ |
765 | | DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */ |
766 | | DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */ |
767 | | DW_OP_lit15, DW_OP_and, DW_OP_lit10, DW_OP_ge, |
768 | | DW_OP_lit3, DW_OP_shl, DW_OP_plus, |
769 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
770 | | }; |
771 | | |
772 | | /* .eh_frame covering the x32 lazy .plt section with IBT-enabled. */ |
773 | | |
774 | | static const bfd_byte elf_x32_eh_frame_lazy_ibt_plt[] = |
775 | | { |
776 | | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ |
777 | | 0, 0, 0, 0, /* CIE ID */ |
778 | | 1, /* CIE version */ |
779 | | 'z', 'R', 0, /* Augmentation string */ |
780 | | 1, /* Code alignment factor */ |
781 | | 0x78, /* Data alignment factor */ |
782 | | 16, /* Return address column */ |
783 | | 1, /* Augmentation size */ |
784 | | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ |
785 | | DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */ |
786 | | DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */ |
787 | | DW_CFA_nop, DW_CFA_nop, |
788 | | |
789 | | PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */ |
790 | | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ |
791 | | 0, 0, 0, 0, /* R_X86_64_PC32 .plt goes here */ |
792 | | 0, 0, 0, 0, /* .plt size goes here */ |
793 | | 0, /* Augmentation size */ |
794 | | DW_CFA_def_cfa_offset, 16, /* DW_CFA_def_cfa_offset: 16 */ |
795 | | DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */ |
796 | | DW_CFA_def_cfa_offset, 24, /* DW_CFA_def_cfa_offset: 24 */ |
797 | | DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */ |
798 | | DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */ |
799 | | 11, /* Block length */ |
800 | | DW_OP_breg7, 8, /* DW_OP_breg7 (rsp): 8 */ |
801 | | DW_OP_breg16, 0, /* DW_OP_breg16 (rip): 0 */ |
802 | | DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge, |
803 | | DW_OP_lit3, DW_OP_shl, DW_OP_plus, |
804 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
805 | | }; |
806 | | |
807 | | /* .eh_frame covering the non-lazy .plt section. */ |
808 | | |
809 | | static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt[] = |
810 | | { |
811 | | #define PLT_GOT_FDE_LENGTH 20 |
812 | | PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ |
813 | | 0, 0, 0, 0, /* CIE ID */ |
814 | | 1, /* CIE version */ |
815 | | 'z', 'R', 0, /* Augmentation string */ |
816 | | 1, /* Code alignment factor */ |
817 | | 0x78, /* Data alignment factor */ |
818 | | 16, /* Return address column */ |
819 | | 1, /* Augmentation size */ |
820 | | DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */ |
821 | | DW_CFA_def_cfa, 7, 8, /* DW_CFA_def_cfa: r7 (rsp) ofs 8 */ |
822 | | DW_CFA_offset + 16, 1, /* DW_CFA_offset: r16 (rip) at cfa-8 */ |
823 | | DW_CFA_nop, DW_CFA_nop, |
824 | | |
825 | | PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */ |
826 | | PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */ |
827 | | 0, 0, 0, 0, /* the start of non-lazy .plt goes here */ |
828 | | 0, 0, 0, 0, /* non-lazy .plt size goes here */ |
829 | | 0, /* Augmentation size */ |
830 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, |
831 | | DW_CFA_nop, DW_CFA_nop, DW_CFA_nop |
832 | | }; |
833 | | |
834 | | static const sframe_frame_row_entry elf_x86_64_sframe_null_fre = |
835 | | { |
836 | | 0, |
837 | | {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
838 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
839 | | }; |
840 | | |
841 | | /* .sframe FRE covering the .plt section entry. */ |
842 | | static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre1 = |
843 | | { |
844 | | 0, /* SFrame FRE start address. */ |
845 | | {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
846 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
847 | | }; |
848 | | |
849 | | /* .sframe FRE covering the .plt section entry. */ |
850 | | static const sframe_frame_row_entry elf_x86_64_sframe_plt0_fre2 = |
851 | | { |
852 | | 6, /* SFrame FRE start address. */ |
853 | | {24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
854 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
855 | | }; |
856 | | |
857 | | /* .sframe FRE covering the .plt section entry. */ |
858 | | static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre1 = |
859 | | { |
860 | | 0, /* SFrame FRE start address. */ |
861 | | {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
862 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
863 | | }; |
864 | | |
865 | | /* .sframe FRE covering the .plt section entry. */ |
866 | | static const sframe_frame_row_entry elf_x86_64_sframe_pltn_fre2 = |
867 | | { |
868 | | 11, /* SFrame FRE start address. */ |
869 | | {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
870 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
871 | | }; |
872 | | |
873 | | /* .sframe FRE covering the second .plt section entry. */ |
874 | | static const sframe_frame_row_entry elf_x86_64_sframe_sec_pltn_fre1 = |
875 | | { |
876 | | 0, /* SFrame FRE start address. */ |
877 | | {8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* 12 bytes. */ |
878 | | SFRAME_V1_FRE_INFO (SFRAME_BASE_REG_SP, 1, SFRAME_FRE_OFFSET_1B) /* FRE info. */ |
879 | | }; |
880 | | |
881 | | /* SFrame helper object for non-lazy PLT. Also used for IBT enabled PLT. */ |
882 | | static const struct elf_x86_sframe_plt elf_x86_64_sframe_non_lazy_plt = |
883 | | { |
884 | | LAZY_PLT_ENTRY_SIZE, |
885 | | 2, /* Number of FREs for PLT0. */ |
886 | | /* Array of SFrame FREs for plt0. */ |
887 | | { &elf_x86_64_sframe_plt0_fre1, &elf_x86_64_sframe_plt0_fre2 }, |
888 | | LAZY_PLT_ENTRY_SIZE, |
889 | | 1, /* Number of FREs for PLTn. */ |
890 | | /* Array of SFrame FREs for plt. */ |
891 | | { &elf_x86_64_sframe_sec_pltn_fre1, &elf_x86_64_sframe_null_fre }, |
892 | | 0, |
893 | | 0, /* There is no second PLT necessary. */ |
894 | | { &elf_x86_64_sframe_null_fre } |
895 | | }; |
896 | | |
897 | | /* SFrame helper object for lazy PLT. Also used for IBT enabled PLT. */ |
898 | | static const struct elf_x86_sframe_plt elf_x86_64_sframe_plt = |
899 | | { |
900 | | LAZY_PLT_ENTRY_SIZE, |
901 | | 2, /* Number of FREs for PLT0. */ |
902 | | /* Array of SFrame FREs for plt0. */ |
903 | | { &elf_x86_64_sframe_plt0_fre1, &elf_x86_64_sframe_plt0_fre2 }, |
904 | | LAZY_PLT_ENTRY_SIZE, |
905 | | 2, /* Number of FREs for PLTn. */ |
906 | | /* Array of SFrame FREs for plt. */ |
907 | | { &elf_x86_64_sframe_pltn_fre1, &elf_x86_64_sframe_pltn_fre2 }, |
908 | | NON_LAZY_PLT_ENTRY_SIZE, |
909 | | 1, /* Number of FREs for PLTn for second PLT. */ |
910 | | /* FREs for second plt (stack trace info for .plt.got is |
911 | | identical). Used when IBT or non-lazy PLT is in effect. */ |
912 | | { &elf_x86_64_sframe_sec_pltn_fre1 } |
913 | | }; |
914 | | |
915 | | /* These are the standard parameters. */ |
916 | | static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt = |
917 | | { |
918 | | elf_x86_64_lazy_plt0_entry, /* plt0_entry */ |
919 | | LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */ |
920 | | elf_x86_64_lazy_plt_entry, /* plt_entry */ |
921 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
922 | | elf_x86_64_tlsdesc_plt_entry, /* plt_tlsdesc_entry */ |
923 | | LAZY_PLT_ENTRY_SIZE, /* plt_tlsdesc_entry_size */ |
924 | | 6, /* plt_tlsdesc_got1_offset */ |
925 | | 12, /* plt_tlsdesc_got2_offset */ |
926 | | 10, /* plt_tlsdesc_got1_insn_end */ |
927 | | 16, /* plt_tlsdesc_got2_insn_end */ |
928 | | 2, /* plt0_got1_offset */ |
929 | | 8, /* plt0_got2_offset */ |
930 | | 12, /* plt0_got2_insn_end */ |
931 | | 2, /* plt_got_offset */ |
932 | | 7, /* plt_reloc_offset */ |
933 | | 12, /* plt_plt_offset */ |
934 | | 6, /* plt_got_insn_size */ |
935 | | LAZY_PLT_ENTRY_SIZE, /* plt_plt_insn_end */ |
936 | | 6, /* plt_lazy_offset */ |
937 | | elf_x86_64_lazy_plt0_entry, /* pic_plt0_entry */ |
938 | | elf_x86_64_lazy_plt_entry, /* pic_plt_entry */ |
939 | | elf_x86_64_eh_frame_lazy_plt, /* eh_frame_plt */ |
940 | | sizeof (elf_x86_64_eh_frame_lazy_plt) /* eh_frame_plt_size */ |
941 | | }; |
942 | | |
943 | | static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_plt = |
944 | | { |
945 | | elf_x86_64_non_lazy_plt_entry, /* plt_entry */ |
946 | | elf_x86_64_non_lazy_plt_entry, /* pic_plt_entry */ |
947 | | NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
948 | | 2, /* plt_got_offset */ |
949 | | 6, /* plt_got_insn_size */ |
950 | | elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
951 | | sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ |
952 | | }; |
953 | | |
954 | | static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_bnd_plt = |
955 | | { |
956 | | elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */ |
957 | | LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */ |
958 | | elf_x86_64_lazy_bnd_plt_entry, /* plt_entry */ |
959 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
960 | | elf_x86_64_tlsdesc_plt_entry, /* plt_tlsdesc_entry */ |
961 | | LAZY_PLT_ENTRY_SIZE, /* plt_tlsdesc_entry_size */ |
962 | | 6, /* plt_tlsdesc_got1_offset */ |
963 | | 12, /* plt_tlsdesc_got2_offset */ |
964 | | 10, /* plt_tlsdesc_got1_insn_end */ |
965 | | 16, /* plt_tlsdesc_got2_insn_end */ |
966 | | 2, /* plt0_got1_offset */ |
967 | | 1+8, /* plt0_got2_offset */ |
968 | | 1+12, /* plt0_got2_insn_end */ |
969 | | 1+2, /* plt_got_offset */ |
970 | | 1, /* plt_reloc_offset */ |
971 | | 7, /* plt_plt_offset */ |
972 | | 1+6, /* plt_got_insn_size */ |
973 | | 11, /* plt_plt_insn_end */ |
974 | | 0, /* plt_lazy_offset */ |
975 | | elf_x86_64_lazy_bnd_plt0_entry, /* pic_plt0_entry */ |
976 | | elf_x86_64_lazy_bnd_plt_entry, /* pic_plt_entry */ |
977 | | elf_x86_64_eh_frame_lazy_bnd_plt, /* eh_frame_plt */ |
978 | | sizeof (elf_x86_64_eh_frame_lazy_bnd_plt) /* eh_frame_plt_size */ |
979 | | }; |
980 | | |
981 | | static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_bnd_plt = |
982 | | { |
983 | | elf_x86_64_non_lazy_bnd_plt_entry, /* plt_entry */ |
984 | | elf_x86_64_non_lazy_bnd_plt_entry, /* pic_plt_entry */ |
985 | | NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
986 | | 1+2, /* plt_got_offset */ |
987 | | 1+6, /* plt_got_insn_size */ |
988 | | elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
989 | | sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ |
990 | | }; |
991 | | |
992 | | static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_ibt_plt = |
993 | | { |
994 | | elf_x86_64_lazy_bnd_plt0_entry, /* plt0_entry */ |
995 | | LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */ |
996 | | elf_x86_64_lazy_ibt_plt_entry, /* plt_entry */ |
997 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
998 | | elf_x86_64_tlsdesc_plt_entry, /* plt_tlsdesc_entry */ |
999 | | LAZY_PLT_ENTRY_SIZE, /* plt_tlsdesc_entry_size */ |
1000 | | 6, /* plt_tlsdesc_got1_offset */ |
1001 | | 12, /* plt_tlsdesc_got2_offset */ |
1002 | | 10, /* plt_tlsdesc_got1_insn_end */ |
1003 | | 16, /* plt_tlsdesc_got2_insn_end */ |
1004 | | 2, /* plt0_got1_offset */ |
1005 | | 1+8, /* plt0_got2_offset */ |
1006 | | 1+12, /* plt0_got2_insn_end */ |
1007 | | 4+1+2, /* plt_got_offset */ |
1008 | | 4+1, /* plt_reloc_offset */ |
1009 | | 4+1+6, /* plt_plt_offset */ |
1010 | | 4+1+6, /* plt_got_insn_size */ |
1011 | | 4+1+5+5, /* plt_plt_insn_end */ |
1012 | | 0, /* plt_lazy_offset */ |
1013 | | elf_x86_64_lazy_bnd_plt0_entry, /* pic_plt0_entry */ |
1014 | | elf_x86_64_lazy_ibt_plt_entry, /* pic_plt_entry */ |
1015 | | elf_x86_64_eh_frame_lazy_ibt_plt, /* eh_frame_plt */ |
1016 | | sizeof (elf_x86_64_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */ |
1017 | | }; |
1018 | | |
1019 | | static const struct elf_x86_lazy_plt_layout elf_x32_lazy_ibt_plt = |
1020 | | { |
1021 | | elf_x86_64_lazy_plt0_entry, /* plt0_entry */ |
1022 | | LAZY_PLT_ENTRY_SIZE, /* plt0_entry_size */ |
1023 | | elf_x32_lazy_ibt_plt_entry, /* plt_entry */ |
1024 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
1025 | | elf_x86_64_tlsdesc_plt_entry, /* plt_tlsdesc_entry */ |
1026 | | LAZY_PLT_ENTRY_SIZE, /* plt_tlsdesc_entry_size */ |
1027 | | 6, /* plt_tlsdesc_got1_offset */ |
1028 | | 12, /* plt_tlsdesc_got2_offset */ |
1029 | | 10, /* plt_tlsdesc_got1_insn_end */ |
1030 | | 16, /* plt_tlsdesc_got2_insn_end */ |
1031 | | 2, /* plt0_got1_offset */ |
1032 | | 8, /* plt0_got2_offset */ |
1033 | | 12, /* plt0_got2_insn_end */ |
1034 | | 4+2, /* plt_got_offset */ |
1035 | | 4+1, /* plt_reloc_offset */ |
1036 | | 4+6, /* plt_plt_offset */ |
1037 | | 4+6, /* plt_got_insn_size */ |
1038 | | 4+5+5, /* plt_plt_insn_end */ |
1039 | | 0, /* plt_lazy_offset */ |
1040 | | elf_x86_64_lazy_plt0_entry, /* pic_plt0_entry */ |
1041 | | elf_x32_lazy_ibt_plt_entry, /* pic_plt_entry */ |
1042 | | elf_x32_eh_frame_lazy_ibt_plt, /* eh_frame_plt */ |
1043 | | sizeof (elf_x32_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */ |
1044 | | }; |
1045 | | |
1046 | | static const struct elf_x86_non_lazy_plt_layout elf_x86_64_non_lazy_ibt_plt = |
1047 | | { |
1048 | | elf_x86_64_non_lazy_ibt_plt_entry, /* plt_entry */ |
1049 | | elf_x86_64_non_lazy_ibt_plt_entry, /* pic_plt_entry */ |
1050 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
1051 | | 4+1+2, /* plt_got_offset */ |
1052 | | 4+1+6, /* plt_got_insn_size */ |
1053 | | elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
1054 | | sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ |
1055 | | }; |
1056 | | |
1057 | | static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt = |
1058 | | { |
1059 | | elf_x32_non_lazy_ibt_plt_entry, /* plt_entry */ |
1060 | | elf_x32_non_lazy_ibt_plt_entry, /* pic_plt_entry */ |
1061 | | LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */ |
1062 | | 4+2, /* plt_got_offset */ |
1063 | | 4+6, /* plt_got_insn_size */ |
1064 | | elf_x86_64_eh_frame_non_lazy_plt, /* eh_frame_plt */ |
1065 | | sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ |
1066 | | }; |
1067 | | |
1068 | | static bool |
1069 | | elf64_x86_64_elf_object_p (bfd *abfd) |
1070 | 462 | { |
1071 | | /* Set the right machine number for an x86-64 elf64 file. */ |
1072 | 462 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64); |
1073 | 462 | return true; |
1074 | 462 | } |
1075 | | |
1076 | | static bool |
1077 | | elf32_x86_64_elf_object_p (bfd *abfd) |
1078 | 2 | { |
1079 | | /* Set the right machine number for an x86-64 elf32 file. */ |
1080 | 2 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x64_32); |
1081 | 2 | return true; |
1082 | 2 | } |
1083 | | |
1084 | | /* Return TRUE if the TLS access code sequence support transition |
1085 | | from R_TYPE. */ |
1086 | | |
1087 | | static bool |
1088 | | elf_x86_64_check_tls_transition (bfd *abfd, |
1089 | | struct bfd_link_info *info, |
1090 | | asection *sec, |
1091 | | bfd_byte *contents, |
1092 | | Elf_Internal_Shdr *symtab_hdr, |
1093 | | struct elf_link_hash_entry **sym_hashes, |
1094 | | unsigned int r_type, |
1095 | | const Elf_Internal_Rela *rel, |
1096 | | const Elf_Internal_Rela *relend) |
1097 | 0 | { |
1098 | 0 | unsigned int val; |
1099 | 0 | unsigned long r_symndx; |
1100 | 0 | bool largepic = false; |
1101 | 0 | struct elf_link_hash_entry *h; |
1102 | 0 | bfd_vma offset; |
1103 | 0 | struct elf_x86_link_hash_table *htab; |
1104 | 0 | bfd_byte *call; |
1105 | 0 | bool indirect_call; |
1106 | |
|
1107 | 0 | htab = elf_x86_hash_table (info, X86_64_ELF_DATA); |
1108 | 0 | offset = rel->r_offset; |
1109 | 0 | switch (r_type) |
1110 | 0 | { |
1111 | 0 | case R_X86_64_TLSGD: |
1112 | 0 | case R_X86_64_TLSLD: |
1113 | 0 | if ((rel + 1) >= relend) |
1114 | 0 | return false; |
1115 | | |
1116 | 0 | if (r_type == R_X86_64_TLSGD) |
1117 | 0 | { |
1118 | | /* Check transition from GD access model. For 64bit, only |
1119 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
1120 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
1121 | | or |
1122 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
1123 | | .byte 0x66; rex64 |
1124 | | call *__tls_get_addr@GOTPCREL(%rip) |
1125 | | which may be converted to |
1126 | | addr32 call __tls_get_addr |
1127 | | can transit to different access model. For 32bit, only |
1128 | | leaq foo@tlsgd(%rip), %rdi |
1129 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
1130 | | or |
1131 | | leaq foo@tlsgd(%rip), %rdi |
1132 | | .byte 0x66; rex64 |
1133 | | call *__tls_get_addr@GOTPCREL(%rip) |
1134 | | which may be converted to |
1135 | | addr32 call __tls_get_addr |
1136 | | can transit to different access model. For largepic, |
1137 | | we also support: |
1138 | | leaq foo@tlsgd(%rip), %rdi |
1139 | | movabsq $__tls_get_addr@pltoff, %rax |
1140 | | addq $r15, %rax |
1141 | | call *%rax |
1142 | | or |
1143 | | leaq foo@tlsgd(%rip), %rdi |
1144 | | movabsq $__tls_get_addr@pltoff, %rax |
1145 | | addq $rbx, %rax |
1146 | | call *%rax */ |
1147 | |
|
1148 | 0 | static const unsigned char leaq[] = { 0x66, 0x48, 0x8d, 0x3d }; |
1149 | |
|
1150 | 0 | if ((offset + 12) > sec->size) |
1151 | 0 | return false; |
1152 | | |
1153 | 0 | call = contents + offset + 4; |
1154 | 0 | if (call[0] != 0x66 |
1155 | 0 | || !((call[1] == 0x48 |
1156 | 0 | && call[2] == 0xff |
1157 | 0 | && call[3] == 0x15) |
1158 | 0 | || (call[1] == 0x48 |
1159 | 0 | && call[2] == 0x67 |
1160 | 0 | && call[3] == 0xe8) |
1161 | 0 | || (call[1] == 0x66 |
1162 | 0 | && call[2] == 0x48 |
1163 | 0 | && call[3] == 0xe8))) |
1164 | 0 | { |
1165 | 0 | if (!ABI_64_P (abfd) |
1166 | 0 | || (offset + 19) > sec->size |
1167 | 0 | || offset < 3 |
1168 | 0 | || memcmp (call - 7, leaq + 1, 3) != 0 |
1169 | 0 | || memcmp (call, "\x48\xb8", 2) != 0 |
1170 | 0 | || call[11] != 0x01 |
1171 | 0 | || call[13] != 0xff |
1172 | 0 | || call[14] != 0xd0 |
1173 | 0 | || !((call[10] == 0x48 && call[12] == 0xd8) |
1174 | 0 | || (call[10] == 0x4c && call[12] == 0xf8))) |
1175 | 0 | return false; |
1176 | 0 | largepic = true; |
1177 | 0 | } |
1178 | 0 | else if (ABI_64_P (abfd)) |
1179 | 0 | { |
1180 | 0 | if (offset < 4 |
1181 | 0 | || memcmp (contents + offset - 4, leaq, 4) != 0) |
1182 | 0 | return false; |
1183 | 0 | } |
1184 | 0 | else |
1185 | 0 | { |
1186 | 0 | if (offset < 3 |
1187 | 0 | || memcmp (contents + offset - 3, leaq + 1, 3) != 0) |
1188 | 0 | return false; |
1189 | 0 | } |
1190 | 0 | indirect_call = call[2] == 0xff; |
1191 | 0 | } |
1192 | 0 | else |
1193 | 0 | { |
1194 | | /* Check transition from LD access model. Only |
1195 | | leaq foo@tlsld(%rip), %rdi; |
1196 | | call __tls_get_addr@PLT |
1197 | | or |
1198 | | leaq foo@tlsld(%rip), %rdi; |
1199 | | call *__tls_get_addr@GOTPCREL(%rip) |
1200 | | which may be converted to |
1201 | | addr32 call __tls_get_addr |
1202 | | can transit to different access model. For largepic |
1203 | | we also support: |
1204 | | leaq foo@tlsld(%rip), %rdi |
1205 | | movabsq $__tls_get_addr@pltoff, %rax |
1206 | | addq $r15, %rax |
1207 | | call *%rax |
1208 | | or |
1209 | | leaq foo@tlsld(%rip), %rdi |
1210 | | movabsq $__tls_get_addr@pltoff, %rax |
1211 | | addq $rbx, %rax |
1212 | | call *%rax */ |
1213 | |
|
1214 | 0 | static const unsigned char lea[] = { 0x48, 0x8d, 0x3d }; |
1215 | |
|
1216 | 0 | if (offset < 3 || (offset + 9) > sec->size) |
1217 | 0 | return false; |
1218 | | |
1219 | 0 | if (memcmp (contents + offset - 3, lea, 3) != 0) |
1220 | 0 | return false; |
1221 | | |
1222 | 0 | call = contents + offset + 4; |
1223 | 0 | if (!(call[0] == 0xe8 |
1224 | 0 | || (call[0] == 0xff && call[1] == 0x15) |
1225 | 0 | || (call[0] == 0x67 && call[1] == 0xe8))) |
1226 | 0 | { |
1227 | 0 | if (!ABI_64_P (abfd) |
1228 | 0 | || (offset + 19) > sec->size |
1229 | 0 | || memcmp (call, "\x48\xb8", 2) != 0 |
1230 | 0 | || call[11] != 0x01 |
1231 | 0 | || call[13] != 0xff |
1232 | 0 | || call[14] != 0xd0 |
1233 | 0 | || !((call[10] == 0x48 && call[12] == 0xd8) |
1234 | 0 | || (call[10] == 0x4c && call[12] == 0xf8))) |
1235 | 0 | return false; |
1236 | 0 | largepic = true; |
1237 | 0 | } |
1238 | 0 | indirect_call = call[0] == 0xff; |
1239 | 0 | } |
1240 | | |
1241 | 0 | r_symndx = htab->r_sym (rel[1].r_info); |
1242 | 0 | if (r_symndx < symtab_hdr->sh_info) |
1243 | 0 | return false; |
1244 | | |
1245 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
1246 | 0 | if (h == NULL |
1247 | 0 | || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr) |
1248 | 0 | return false; |
1249 | 0 | else |
1250 | 0 | { |
1251 | 0 | r_type = (ELF32_R_TYPE (rel[1].r_info) |
1252 | 0 | & ~R_X86_64_converted_reloc_bit); |
1253 | 0 | if (largepic) |
1254 | 0 | return r_type == R_X86_64_PLTOFF64; |
1255 | 0 | else if (indirect_call) |
1256 | 0 | return (r_type == R_X86_64_GOTPCRELX || r_type == R_X86_64_GOTPCREL); |
1257 | 0 | else |
1258 | 0 | return (r_type == R_X86_64_PC32 || r_type == R_X86_64_PLT32); |
1259 | 0 | } |
1260 | | |
1261 | 0 | case R_X86_64_GOTTPOFF: |
1262 | | /* Check transition from IE access model: |
1263 | | mov foo@gottpoff(%rip), %reg |
1264 | | add foo@gottpoff(%rip), %reg |
1265 | | */ |
1266 | | |
1267 | | /* Check REX prefix first. */ |
1268 | 0 | if (offset >= 3 && (offset + 4) <= sec->size) |
1269 | 0 | { |
1270 | 0 | val = bfd_get_8 (abfd, contents + offset - 3); |
1271 | 0 | if (val != 0x48 && val != 0x4c) |
1272 | 0 | { |
1273 | | /* X32 may have 0x44 REX prefix or no REX prefix. */ |
1274 | 0 | if (ABI_64_P (abfd)) |
1275 | 0 | return false; |
1276 | 0 | } |
1277 | 0 | } |
1278 | 0 | else |
1279 | 0 | { |
1280 | | /* X32 may not have any REX prefix. */ |
1281 | 0 | if (ABI_64_P (abfd)) |
1282 | 0 | return false; |
1283 | 0 | if (offset < 2 || (offset + 3) > sec->size) |
1284 | 0 | return false; |
1285 | 0 | } |
1286 | | |
1287 | 0 | val = bfd_get_8 (abfd, contents + offset - 2); |
1288 | 0 | if (val != 0x8b && val != 0x03) |
1289 | 0 | return false; |
1290 | | |
1291 | 0 | val = bfd_get_8 (abfd, contents + offset - 1); |
1292 | 0 | return (val & 0xc7) == 5; |
1293 | | |
1294 | 0 | case R_X86_64_GOTPC32_TLSDESC: |
1295 | | /* Check transition from GDesc access model: |
1296 | | leaq x@tlsdesc(%rip), %rax <--- LP64 mode. |
1297 | | rex leal x@tlsdesc(%rip), %eax <--- X32 mode. |
1298 | | |
1299 | | Make sure it's a leaq adding rip to a 32-bit offset |
1300 | | into any register, although it's probably almost always |
1301 | | going to be rax. */ |
1302 | |
|
1303 | 0 | if (offset < 3 || (offset + 4) > sec->size) |
1304 | 0 | return false; |
1305 | | |
1306 | 0 | val = bfd_get_8 (abfd, contents + offset - 3); |
1307 | 0 | val &= 0xfb; |
1308 | 0 | if (val != 0x48 && (ABI_64_P (abfd) || val != 0x40)) |
1309 | 0 | return false; |
1310 | | |
1311 | 0 | if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d) |
1312 | 0 | return false; |
1313 | | |
1314 | 0 | val = bfd_get_8 (abfd, contents + offset - 1); |
1315 | 0 | return (val & 0xc7) == 0x05; |
1316 | | |
1317 | 0 | case R_X86_64_TLSDESC_CALL: |
1318 | | /* Check transition from GDesc access model: |
1319 | | call *x@tlsdesc(%rax) <--- LP64 mode. |
1320 | | call *x@tlsdesc(%eax) <--- X32 mode. |
1321 | | */ |
1322 | 0 | if (offset + 2 <= sec->size) |
1323 | 0 | { |
1324 | 0 | unsigned int prefix; |
1325 | 0 | call = contents + offset; |
1326 | 0 | prefix = 0; |
1327 | 0 | if (!ABI_64_P (abfd)) |
1328 | 0 | { |
1329 | | /* Check for call *x@tlsdesc(%eax). */ |
1330 | 0 | if (call[0] == 0x67) |
1331 | 0 | { |
1332 | 0 | prefix = 1; |
1333 | 0 | if (offset + 3 > sec->size) |
1334 | 0 | return false; |
1335 | 0 | } |
1336 | 0 | } |
1337 | | /* Make sure that it's a call *x@tlsdesc(%rax). */ |
1338 | 0 | return call[prefix] == 0xff && call[1 + prefix] == 0x10; |
1339 | 0 | } |
1340 | | |
1341 | 0 | return false; |
1342 | | |
1343 | 0 | default: |
1344 | 0 | abort (); |
1345 | 0 | } |
1346 | 0 | } |
1347 | | |
1348 | | /* Return TRUE if the TLS access transition is OK or no transition |
1349 | | will be performed. Update R_TYPE if there is a transition. */ |
1350 | | |
1351 | | static bool |
1352 | | elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, |
1353 | | asection *sec, bfd_byte *contents, |
1354 | | Elf_Internal_Shdr *symtab_hdr, |
1355 | | struct elf_link_hash_entry **sym_hashes, |
1356 | | unsigned int *r_type, int tls_type, |
1357 | | const Elf_Internal_Rela *rel, |
1358 | | const Elf_Internal_Rela *relend, |
1359 | | struct elf_link_hash_entry *h, |
1360 | | unsigned long r_symndx, |
1361 | | bool from_relocate_section) |
1362 | 0 | { |
1363 | 0 | unsigned int from_type = *r_type; |
1364 | 0 | unsigned int to_type = from_type; |
1365 | 0 | bool check = true; |
1366 | | |
1367 | | /* Skip TLS transition for functions. */ |
1368 | 0 | if (h != NULL |
1369 | 0 | && (h->type == STT_FUNC |
1370 | 0 | || h->type == STT_GNU_IFUNC)) |
1371 | 0 | return true; |
1372 | | |
1373 | 0 | switch (from_type) |
1374 | 0 | { |
1375 | 0 | case R_X86_64_TLSGD: |
1376 | 0 | case R_X86_64_GOTPC32_TLSDESC: |
1377 | 0 | case R_X86_64_TLSDESC_CALL: |
1378 | 0 | case R_X86_64_GOTTPOFF: |
1379 | 0 | if (bfd_link_executable (info)) |
1380 | 0 | { |
1381 | 0 | if (h == NULL) |
1382 | 0 | to_type = R_X86_64_TPOFF32; |
1383 | 0 | else |
1384 | 0 | to_type = R_X86_64_GOTTPOFF; |
1385 | 0 | } |
1386 | | |
1387 | | /* When we are called from elf_x86_64_relocate_section, there may |
1388 | | be additional transitions based on TLS_TYPE. */ |
1389 | 0 | if (from_relocate_section) |
1390 | 0 | { |
1391 | 0 | unsigned int new_to_type = to_type; |
1392 | |
|
1393 | 0 | if (TLS_TRANSITION_IE_TO_LE_P (info, h, tls_type)) |
1394 | 0 | new_to_type = R_X86_64_TPOFF32; |
1395 | |
|
1396 | 0 | if (to_type == R_X86_64_TLSGD |
1397 | 0 | || to_type == R_X86_64_GOTPC32_TLSDESC |
1398 | 0 | || to_type == R_X86_64_TLSDESC_CALL) |
1399 | 0 | { |
1400 | 0 | if (tls_type == GOT_TLS_IE) |
1401 | 0 | new_to_type = R_X86_64_GOTTPOFF; |
1402 | 0 | } |
1403 | | |
1404 | | /* We checked the transition before when we were called from |
1405 | | elf_x86_64_scan_relocs. We only want to check the new |
1406 | | transition which hasn't been checked before. */ |
1407 | 0 | check = new_to_type != to_type && from_type == to_type; |
1408 | 0 | to_type = new_to_type; |
1409 | 0 | } |
1410 | |
|
1411 | 0 | break; |
1412 | | |
1413 | 0 | case R_X86_64_TLSLD: |
1414 | 0 | if (bfd_link_executable (info)) |
1415 | 0 | to_type = R_X86_64_TPOFF32; |
1416 | 0 | break; |
1417 | | |
1418 | 0 | default: |
1419 | 0 | return true; |
1420 | 0 | } |
1421 | | |
1422 | | /* Return TRUE if there is no transition. */ |
1423 | 0 | if (from_type == to_type) |
1424 | 0 | return true; |
1425 | | |
1426 | | /* Check if the transition can be performed. */ |
1427 | 0 | if (check |
1428 | 0 | && ! elf_x86_64_check_tls_transition (abfd, info, sec, contents, |
1429 | 0 | symtab_hdr, sym_hashes, |
1430 | 0 | from_type, rel, relend)) |
1431 | 0 | { |
1432 | 0 | reloc_howto_type *from, *to; |
1433 | 0 | const char *name; |
1434 | |
|
1435 | 0 | from = elf_x86_64_rtype_to_howto (abfd, from_type); |
1436 | 0 | to = elf_x86_64_rtype_to_howto (abfd, to_type); |
1437 | |
|
1438 | 0 | if (from == NULL || to == NULL) |
1439 | 0 | return false; |
1440 | | |
1441 | 0 | if (h) |
1442 | 0 | name = h->root.root.string; |
1443 | 0 | else |
1444 | 0 | { |
1445 | 0 | struct elf_x86_link_hash_table *htab; |
1446 | |
|
1447 | 0 | htab = elf_x86_hash_table (info, X86_64_ELF_DATA); |
1448 | 0 | if (htab == NULL) |
1449 | 0 | name = "*unknown*"; |
1450 | 0 | else |
1451 | 0 | { |
1452 | 0 | Elf_Internal_Sym *isym; |
1453 | |
|
1454 | 0 | isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, |
1455 | 0 | abfd, r_symndx); |
1456 | 0 | name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); |
1457 | 0 | } |
1458 | 0 | } |
1459 | |
|
1460 | 0 | _bfd_error_handler |
1461 | | /* xgettext:c-format */ |
1462 | 0 | (_("%pB: TLS transition from %s to %s against `%s' at %#" PRIx64 |
1463 | 0 | " in section `%pA' failed"), |
1464 | 0 | abfd, from->name, to->name, name, (uint64_t) rel->r_offset, sec); |
1465 | 0 | bfd_set_error (bfd_error_bad_value); |
1466 | 0 | return false; |
1467 | 0 | } |
1468 | | |
1469 | 0 | *r_type = to_type; |
1470 | 0 | return true; |
1471 | 0 | } |
1472 | | |
1473 | | static bool |
1474 | | elf_x86_64_need_pic (struct bfd_link_info *info, |
1475 | | bfd *input_bfd, asection *sec, |
1476 | | struct elf_link_hash_entry *h, |
1477 | | Elf_Internal_Shdr *symtab_hdr, |
1478 | | Elf_Internal_Sym *isym, |
1479 | | reloc_howto_type *howto) |
1480 | 0 | { |
1481 | 0 | const char *v = ""; |
1482 | 0 | const char *und = ""; |
1483 | 0 | const char *pic = ""; |
1484 | 0 | const char *object; |
1485 | |
|
1486 | 0 | const char *name; |
1487 | 0 | if (h) |
1488 | 0 | { |
1489 | 0 | name = h->root.root.string; |
1490 | 0 | switch (ELF_ST_VISIBILITY (h->other)) |
1491 | 0 | { |
1492 | 0 | case STV_HIDDEN: |
1493 | 0 | v = _("hidden symbol "); |
1494 | 0 | break; |
1495 | 0 | case STV_INTERNAL: |
1496 | 0 | v = _("internal symbol "); |
1497 | 0 | break; |
1498 | 0 | case STV_PROTECTED: |
1499 | 0 | v = _("protected symbol "); |
1500 | 0 | break; |
1501 | 0 | default: |
1502 | 0 | if (((struct elf_x86_link_hash_entry *) h)->def_protected) |
1503 | 0 | v = _("protected symbol "); |
1504 | 0 | else |
1505 | 0 | v = _("symbol "); |
1506 | 0 | pic = NULL; |
1507 | 0 | break; |
1508 | 0 | } |
1509 | | |
1510 | 0 | if (!SYMBOL_DEFINED_NON_SHARED_P (h) && !h->def_dynamic) |
1511 | 0 | und = _("undefined "); |
1512 | 0 | } |
1513 | 0 | else |
1514 | 0 | { |
1515 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, isym, NULL); |
1516 | 0 | pic = NULL; |
1517 | 0 | } |
1518 | | |
1519 | 0 | if (bfd_link_dll (info)) |
1520 | 0 | { |
1521 | 0 | object = _("a shared object"); |
1522 | 0 | if (!pic) |
1523 | 0 | pic = _("; recompile with -fPIC"); |
1524 | 0 | } |
1525 | 0 | else |
1526 | 0 | { |
1527 | 0 | if (bfd_link_pie (info)) |
1528 | 0 | object = _("a PIE object"); |
1529 | 0 | else |
1530 | 0 | object = _("a PDE object"); |
1531 | 0 | if (!pic) |
1532 | 0 | pic = _("; recompile with -fPIE"); |
1533 | 0 | } |
1534 | | |
1535 | | /* xgettext:c-format */ |
1536 | 0 | _bfd_error_handler (_("%pB: relocation %s against %s%s`%s' can " |
1537 | 0 | "not be used when making %s%s"), |
1538 | 0 | input_bfd, howto->name, und, v, name, |
1539 | 0 | object, pic); |
1540 | 0 | bfd_set_error (bfd_error_bad_value); |
1541 | 0 | sec->check_relocs_failed = 1; |
1542 | 0 | return false; |
1543 | 0 | } |
1544 | | |
1545 | | /* With the local symbol, foo, we convert |
1546 | | mov foo@GOTPCREL(%rip), %reg |
1547 | | to |
1548 | | lea foo(%rip), %reg |
1549 | | and convert |
1550 | | call/jmp *foo@GOTPCREL(%rip) |
1551 | | to |
1552 | | nop call foo/jmp foo nop |
1553 | | When PIC is false, convert |
1554 | | test %reg, foo@GOTPCREL(%rip) |
1555 | | to |
1556 | | test $foo, %reg |
1557 | | and convert |
1558 | | binop foo@GOTPCREL(%rip), %reg |
1559 | | to |
1560 | | binop $foo, %reg |
1561 | | where binop is one of adc, add, and, cmp, or, sbb, sub, xor |
1562 | | instructions. */ |
1563 | | |
1564 | | static bool |
1565 | | elf_x86_64_convert_load_reloc (bfd *abfd, |
1566 | | bfd_byte *contents, |
1567 | | unsigned int *r_type_p, |
1568 | | Elf_Internal_Rela *irel, |
1569 | | struct elf_link_hash_entry *h, |
1570 | | bool *converted, |
1571 | | struct bfd_link_info *link_info) |
1572 | 0 | { |
1573 | 0 | struct elf_x86_link_hash_table *htab; |
1574 | 0 | bool is_pic; |
1575 | 0 | bool no_overflow; |
1576 | 0 | bool relocx; |
1577 | 0 | bool to_reloc_pc32; |
1578 | 0 | bool abs_symbol; |
1579 | 0 | bool local_ref; |
1580 | 0 | asection *tsec; |
1581 | 0 | bfd_signed_vma raddend; |
1582 | 0 | unsigned int opcode; |
1583 | 0 | unsigned int modrm; |
1584 | 0 | unsigned int r_type = *r_type_p; |
1585 | 0 | unsigned int r_symndx; |
1586 | 0 | bfd_vma roff = irel->r_offset; |
1587 | 0 | bfd_vma abs_relocation; |
1588 | |
|
1589 | 0 | if (roff < (r_type == R_X86_64_REX_GOTPCRELX ? 3 : 2)) |
1590 | 0 | return true; |
1591 | | |
1592 | 0 | raddend = irel->r_addend; |
1593 | | /* Addend for 32-bit PC-relative relocation must be -4. */ |
1594 | 0 | if (raddend != -4) |
1595 | 0 | return true; |
1596 | | |
1597 | 0 | htab = elf_x86_hash_table (link_info, X86_64_ELF_DATA); |
1598 | 0 | is_pic = bfd_link_pic (link_info); |
1599 | |
|
1600 | 0 | relocx = (r_type == R_X86_64_GOTPCRELX |
1601 | 0 | || r_type == R_X86_64_REX_GOTPCRELX); |
1602 | | |
1603 | | /* TRUE if --no-relax is used. */ |
1604 | 0 | no_overflow = link_info->disable_target_specific_optimizations > 1; |
1605 | |
|
1606 | 0 | r_symndx = htab->r_sym (irel->r_info); |
1607 | |
|
1608 | 0 | opcode = bfd_get_8 (abfd, contents + roff - 2); |
1609 | | |
1610 | | /* Convert mov to lea since it has been done for a while. */ |
1611 | 0 | if (opcode != 0x8b) |
1612 | 0 | { |
1613 | | /* Only convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX |
1614 | | for call, jmp or one of adc, add, and, cmp, or, sbb, sub, |
1615 | | test, xor instructions. */ |
1616 | 0 | if (!relocx) |
1617 | 0 | return true; |
1618 | 0 | } |
1619 | | |
1620 | | /* We convert only to R_X86_64_PC32: |
1621 | | 1. Branch. |
1622 | | 2. R_X86_64_GOTPCREL since we can't modify REX byte. |
1623 | | 3. no_overflow is true. |
1624 | | 4. PIC. |
1625 | | */ |
1626 | 0 | to_reloc_pc32 = (opcode == 0xff |
1627 | 0 | || !relocx |
1628 | 0 | || no_overflow |
1629 | 0 | || is_pic); |
1630 | |
|
1631 | 0 | abs_symbol = false; |
1632 | 0 | abs_relocation = 0; |
1633 | | |
1634 | | /* Get the symbol referred to by the reloc. */ |
1635 | 0 | if (h == NULL) |
1636 | 0 | { |
1637 | 0 | Elf_Internal_Sym *isym |
1638 | 0 | = bfd_sym_from_r_symndx (&htab->elf.sym_cache, abfd, r_symndx); |
1639 | | |
1640 | | /* Skip relocation against undefined symbols. */ |
1641 | 0 | if (isym->st_shndx == SHN_UNDEF) |
1642 | 0 | return true; |
1643 | | |
1644 | 0 | local_ref = true; |
1645 | 0 | if (isym->st_shndx == SHN_ABS) |
1646 | 0 | { |
1647 | 0 | tsec = bfd_abs_section_ptr; |
1648 | 0 | abs_symbol = true; |
1649 | 0 | abs_relocation = isym->st_value; |
1650 | 0 | } |
1651 | 0 | else if (isym->st_shndx == SHN_COMMON) |
1652 | 0 | tsec = bfd_com_section_ptr; |
1653 | 0 | else if (isym->st_shndx == SHN_X86_64_LCOMMON) |
1654 | 0 | tsec = &_bfd_elf_large_com_section; |
1655 | 0 | else |
1656 | 0 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
1657 | 0 | } |
1658 | 0 | else |
1659 | 0 | { |
1660 | | /* Undefined weak symbol is only bound locally in executable |
1661 | | and its reference is resolved as 0 without relocation |
1662 | | overflow. We can only perform this optimization for |
1663 | | GOTPCRELX relocations since we need to modify REX byte. |
1664 | | It is OK convert mov with R_X86_64_GOTPCREL to |
1665 | | R_X86_64_PC32. */ |
1666 | 0 | struct elf_x86_link_hash_entry *eh = elf_x86_hash_entry (h); |
1667 | |
|
1668 | 0 | abs_symbol = ABS_SYMBOL_P (h); |
1669 | 0 | abs_relocation = h->root.u.def.value; |
1670 | | |
1671 | | /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */ |
1672 | 0 | local_ref = SYMBOL_REFERENCES_LOCAL_P (link_info, h); |
1673 | 0 | if ((relocx || opcode == 0x8b) |
1674 | 0 | && (h->root.type == bfd_link_hash_undefweak |
1675 | 0 | && !eh->linker_def |
1676 | 0 | && local_ref)) |
1677 | 0 | { |
1678 | 0 | if (opcode == 0xff) |
1679 | 0 | { |
1680 | | /* Skip for branch instructions since R_X86_64_PC32 |
1681 | | may overflow. */ |
1682 | 0 | if (no_overflow) |
1683 | 0 | return true; |
1684 | 0 | } |
1685 | 0 | else if (relocx) |
1686 | 0 | { |
1687 | | /* For non-branch instructions, we can convert to |
1688 | | R_X86_64_32/R_X86_64_32S since we know if there |
1689 | | is a REX byte. */ |
1690 | 0 | to_reloc_pc32 = false; |
1691 | 0 | } |
1692 | | |
1693 | | /* Since we don't know the current PC when PIC is true, |
1694 | | we can't convert to R_X86_64_PC32. */ |
1695 | 0 | if (to_reloc_pc32 && is_pic) |
1696 | 0 | return true; |
1697 | | |
1698 | 0 | goto convert; |
1699 | 0 | } |
1700 | | /* Avoid optimizing GOTPCREL relocations againt _DYNAMIC since |
1701 | | ld.so may use its link-time address. */ |
1702 | 0 | else if (h->start_stop |
1703 | 0 | || eh->linker_def |
1704 | 0 | || ((h->def_regular |
1705 | 0 | || h->root.type == bfd_link_hash_defined |
1706 | 0 | || h->root.type == bfd_link_hash_defweak) |
1707 | 0 | && h != htab->elf.hdynamic |
1708 | 0 | && local_ref)) |
1709 | 0 | { |
1710 | | /* bfd_link_hash_new or bfd_link_hash_undefined is |
1711 | | set by an assignment in a linker script in |
1712 | | bfd_elf_record_link_assignment. start_stop is set |
1713 | | on __start_SECNAME/__stop_SECNAME which mark section |
1714 | | SECNAME. */ |
1715 | 0 | if (h->start_stop |
1716 | 0 | || eh->linker_def |
1717 | 0 | || (h->def_regular |
1718 | 0 | && (h->root.type == bfd_link_hash_new |
1719 | 0 | || h->root.type == bfd_link_hash_undefined |
1720 | 0 | || ((h->root.type == bfd_link_hash_defined |
1721 | 0 | || h->root.type == bfd_link_hash_defweak) |
1722 | 0 | && h->root.u.def.section == bfd_und_section_ptr)))) |
1723 | 0 | { |
1724 | | /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */ |
1725 | 0 | if (no_overflow) |
1726 | 0 | return true; |
1727 | 0 | goto convert; |
1728 | 0 | } |
1729 | 0 | tsec = h->root.u.def.section; |
1730 | 0 | } |
1731 | 0 | else |
1732 | 0 | return true; |
1733 | 0 | } |
1734 | | |
1735 | | /* Don't convert GOTPCREL relocation against large section. */ |
1736 | 0 | if (elf_section_data (tsec) != NULL |
1737 | 0 | && (elf_section_flags (tsec) & SHF_X86_64_LARGE) != 0) |
1738 | 0 | return true; |
1739 | | |
1740 | | /* Skip since R_X86_64_PC32/R_X86_64_32/R_X86_64_32S may overflow. */ |
1741 | 0 | if (no_overflow) |
1742 | 0 | return true; |
1743 | | |
1744 | 0 | convert: |
1745 | 0 | if (opcode == 0xff) |
1746 | 0 | { |
1747 | | /* We have "call/jmp *foo@GOTPCREL(%rip)". */ |
1748 | 0 | unsigned int nop; |
1749 | 0 | unsigned int disp; |
1750 | 0 | bfd_vma nop_offset; |
1751 | | |
1752 | | /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to |
1753 | | R_X86_64_PC32. */ |
1754 | 0 | modrm = bfd_get_8 (abfd, contents + roff - 1); |
1755 | 0 | if (modrm == 0x25) |
1756 | 0 | { |
1757 | | /* Convert to "jmp foo nop". */ |
1758 | 0 | modrm = 0xe9; |
1759 | 0 | nop = NOP_OPCODE; |
1760 | 0 | nop_offset = irel->r_offset + 3; |
1761 | 0 | disp = bfd_get_32 (abfd, contents + irel->r_offset); |
1762 | 0 | irel->r_offset -= 1; |
1763 | 0 | bfd_put_32 (abfd, disp, contents + irel->r_offset); |
1764 | 0 | } |
1765 | 0 | else |
1766 | 0 | { |
1767 | 0 | struct elf_x86_link_hash_entry *eh |
1768 | 0 | = (struct elf_x86_link_hash_entry *) h; |
1769 | | |
1770 | | /* Convert to "nop call foo". ADDR_PREFIX_OPCODE |
1771 | | is a nop prefix. */ |
1772 | 0 | modrm = 0xe8; |
1773 | | /* To support TLS optimization, always use addr32 prefix for |
1774 | | "call *__tls_get_addr@GOTPCREL(%rip)". */ |
1775 | 0 | if (eh && eh->tls_get_addr) |
1776 | 0 | { |
1777 | 0 | nop = 0x67; |
1778 | 0 | nop_offset = irel->r_offset - 2; |
1779 | 0 | } |
1780 | 0 | else |
1781 | 0 | { |
1782 | 0 | nop = htab->params->call_nop_byte; |
1783 | 0 | if (htab->params->call_nop_as_suffix) |
1784 | 0 | { |
1785 | 0 | nop_offset = irel->r_offset + 3; |
1786 | 0 | disp = bfd_get_32 (abfd, contents + irel->r_offset); |
1787 | 0 | irel->r_offset -= 1; |
1788 | 0 | bfd_put_32 (abfd, disp, contents + irel->r_offset); |
1789 | 0 | } |
1790 | 0 | else |
1791 | 0 | nop_offset = irel->r_offset - 2; |
1792 | 0 | } |
1793 | 0 | } |
1794 | 0 | bfd_put_8 (abfd, nop, contents + nop_offset); |
1795 | 0 | bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1); |
1796 | 0 | r_type = R_X86_64_PC32; |
1797 | 0 | } |
1798 | 0 | else |
1799 | 0 | { |
1800 | 0 | unsigned int rex; |
1801 | 0 | unsigned int rex_mask = REX_R; |
1802 | |
|
1803 | 0 | if (r_type == R_X86_64_REX_GOTPCRELX) |
1804 | 0 | rex = bfd_get_8 (abfd, contents + roff - 3); |
1805 | 0 | else |
1806 | 0 | rex = 0; |
1807 | |
|
1808 | 0 | if (opcode == 0x8b) |
1809 | 0 | { |
1810 | 0 | if (abs_symbol && local_ref && relocx) |
1811 | 0 | to_reloc_pc32 = false; |
1812 | |
|
1813 | 0 | if (to_reloc_pc32) |
1814 | 0 | { |
1815 | | /* Convert "mov foo@GOTPCREL(%rip), %reg" to |
1816 | | "lea foo(%rip), %reg". */ |
1817 | 0 | opcode = 0x8d; |
1818 | 0 | r_type = R_X86_64_PC32; |
1819 | 0 | } |
1820 | 0 | else |
1821 | 0 | { |
1822 | | /* Convert "mov foo@GOTPCREL(%rip), %reg" to |
1823 | | "mov $foo, %reg". */ |
1824 | 0 | opcode = 0xc7; |
1825 | 0 | modrm = bfd_get_8 (abfd, contents + roff - 1); |
1826 | 0 | modrm = 0xc0 | (modrm & 0x38) >> 3; |
1827 | 0 | if ((rex & REX_W) != 0 |
1828 | 0 | && ABI_64_P (link_info->output_bfd)) |
1829 | 0 | { |
1830 | | /* Keep the REX_W bit in REX byte for LP64. */ |
1831 | 0 | r_type = R_X86_64_32S; |
1832 | 0 | goto rewrite_modrm_rex; |
1833 | 0 | } |
1834 | 0 | else |
1835 | 0 | { |
1836 | | /* If the REX_W bit in REX byte isn't needed, |
1837 | | use R_X86_64_32 and clear the W bit to avoid |
1838 | | sign-extend imm32 to imm64. */ |
1839 | 0 | r_type = R_X86_64_32; |
1840 | | /* Clear the W bit in REX byte. */ |
1841 | 0 | rex_mask |= REX_W; |
1842 | 0 | goto rewrite_modrm_rex; |
1843 | 0 | } |
1844 | 0 | } |
1845 | 0 | } |
1846 | 0 | else |
1847 | 0 | { |
1848 | | /* R_X86_64_PC32 isn't supported. */ |
1849 | 0 | if (to_reloc_pc32) |
1850 | 0 | return true; |
1851 | | |
1852 | 0 | modrm = bfd_get_8 (abfd, contents + roff - 1); |
1853 | 0 | if (opcode == 0x85) |
1854 | 0 | { |
1855 | | /* Convert "test %reg, foo@GOTPCREL(%rip)" to |
1856 | | "test $foo, %reg". */ |
1857 | 0 | modrm = 0xc0 | (modrm & 0x38) >> 3; |
1858 | 0 | opcode = 0xf7; |
1859 | 0 | } |
1860 | 0 | else |
1861 | 0 | { |
1862 | | /* Convert "binop foo@GOTPCREL(%rip), %reg" to |
1863 | | "binop $foo, %reg". */ |
1864 | 0 | modrm = 0xc0 | (modrm & 0x38) >> 3 | (opcode & 0x3c); |
1865 | 0 | opcode = 0x81; |
1866 | 0 | } |
1867 | | |
1868 | | /* Use R_X86_64_32 with 32-bit operand to avoid relocation |
1869 | | overflow when sign-extending imm32 to imm64. */ |
1870 | 0 | r_type = (rex & REX_W) != 0 ? R_X86_64_32S : R_X86_64_32; |
1871 | |
|
1872 | 0 | rewrite_modrm_rex: |
1873 | 0 | if (abs_relocation) |
1874 | 0 | { |
1875 | | /* Check if R_X86_64_32S/R_X86_64_32 fits. */ |
1876 | 0 | if (r_type == R_X86_64_32S) |
1877 | 0 | { |
1878 | 0 | if ((abs_relocation + 0x80000000) > 0xffffffff) |
1879 | 0 | return true; |
1880 | 0 | } |
1881 | 0 | else |
1882 | 0 | { |
1883 | 0 | if (abs_relocation > 0xffffffff) |
1884 | 0 | return true; |
1885 | 0 | } |
1886 | 0 | } |
1887 | | |
1888 | 0 | bfd_put_8 (abfd, modrm, contents + roff - 1); |
1889 | |
|
1890 | 0 | if (rex) |
1891 | 0 | { |
1892 | | /* Move the R bit to the B bit in REX byte. */ |
1893 | 0 | rex = (rex & ~rex_mask) | (rex & REX_R) >> 2; |
1894 | 0 | bfd_put_8 (abfd, rex, contents + roff - 3); |
1895 | 0 | } |
1896 | | |
1897 | | /* No addend for R_X86_64_32/R_X86_64_32S relocations. */ |
1898 | 0 | irel->r_addend = 0; |
1899 | 0 | } |
1900 | | |
1901 | 0 | bfd_put_8 (abfd, opcode, contents + roff - 2); |
1902 | 0 | } |
1903 | | |
1904 | 0 | *r_type_p = r_type; |
1905 | 0 | irel->r_info = htab->r_info (r_symndx, |
1906 | 0 | r_type | R_X86_64_converted_reloc_bit); |
1907 | |
|
1908 | 0 | *converted = true; |
1909 | |
|
1910 | 0 | return true; |
1911 | 0 | } |
1912 | | |
1913 | | /* Look through the relocs for a section during the first phase, and |
1914 | | calculate needed space in the global offset table, and procedure |
1915 | | linkage table. */ |
1916 | | |
1917 | | static bool |
1918 | | elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info, |
1919 | | asection *sec, |
1920 | | const Elf_Internal_Rela *relocs) |
1921 | 0 | { |
1922 | 0 | struct elf_x86_link_hash_table *htab; |
1923 | 0 | Elf_Internal_Shdr *symtab_hdr; |
1924 | 0 | struct elf_link_hash_entry **sym_hashes; |
1925 | 0 | const Elf_Internal_Rela *rel; |
1926 | 0 | const Elf_Internal_Rela *rel_end; |
1927 | 0 | bfd_byte *contents; |
1928 | 0 | bool converted; |
1929 | |
|
1930 | 0 | if (bfd_link_relocatable (info)) |
1931 | 0 | return true; |
1932 | | |
1933 | 0 | htab = elf_x86_hash_table (info, X86_64_ELF_DATA); |
1934 | 0 | if (htab == NULL) |
1935 | 0 | { |
1936 | 0 | sec->check_relocs_failed = 1; |
1937 | 0 | return false; |
1938 | 0 | } |
1939 | | |
1940 | 0 | BFD_ASSERT (is_x86_elf (abfd, htab)); |
1941 | | |
1942 | | /* Get the section contents. */ |
1943 | 0 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
1944 | 0 | contents = elf_section_data (sec)->this_hdr.contents; |
1945 | 0 | else if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
1946 | 0 | { |
1947 | 0 | sec->check_relocs_failed = 1; |
1948 | 0 | return false; |
1949 | 0 | } |
1950 | | |
1951 | 0 | symtab_hdr = &elf_symtab_hdr (abfd); |
1952 | 0 | sym_hashes = elf_sym_hashes (abfd); |
1953 | |
|
1954 | 0 | converted = false; |
1955 | |
|
1956 | 0 | rel_end = relocs + sec->reloc_count; |
1957 | 0 | for (rel = relocs; rel < rel_end; rel++) |
1958 | 0 | { |
1959 | 0 | unsigned int r_type; |
1960 | 0 | unsigned int r_symndx; |
1961 | 0 | struct elf_link_hash_entry *h; |
1962 | 0 | struct elf_x86_link_hash_entry *eh; |
1963 | 0 | Elf_Internal_Sym *isym; |
1964 | 0 | const char *name; |
1965 | 0 | bool size_reloc; |
1966 | 0 | bool converted_reloc; |
1967 | 0 | bool no_dynreloc; |
1968 | |
|
1969 | 0 | r_symndx = htab->r_sym (rel->r_info); |
1970 | 0 | r_type = ELF32_R_TYPE (rel->r_info); |
1971 | |
|
1972 | 0 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
1973 | 0 | { |
1974 | | /* xgettext:c-format */ |
1975 | 0 | _bfd_error_handler (_("%pB: bad symbol index: %d"), |
1976 | 0 | abfd, r_symndx); |
1977 | 0 | goto error_return; |
1978 | 0 | } |
1979 | | |
1980 | 0 | if (r_symndx < symtab_hdr->sh_info) |
1981 | 0 | { |
1982 | | /* A local symbol. */ |
1983 | 0 | isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, |
1984 | 0 | abfd, r_symndx); |
1985 | 0 | if (isym == NULL) |
1986 | 0 | goto error_return; |
1987 | | |
1988 | | /* Check relocation against local STT_GNU_IFUNC symbol. */ |
1989 | 0 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
1990 | 0 | { |
1991 | 0 | h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel, |
1992 | 0 | true); |
1993 | 0 | if (h == NULL) |
1994 | 0 | goto error_return; |
1995 | | |
1996 | | /* Fake a STT_GNU_IFUNC symbol. */ |
1997 | 0 | h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr, |
1998 | 0 | isym, NULL); |
1999 | 0 | h->type = STT_GNU_IFUNC; |
2000 | 0 | h->def_regular = 1; |
2001 | 0 | h->ref_regular = 1; |
2002 | 0 | h->forced_local = 1; |
2003 | 0 | h->root.type = bfd_link_hash_defined; |
2004 | 0 | } |
2005 | 0 | else |
2006 | 0 | h = NULL; |
2007 | 0 | } |
2008 | 0 | else |
2009 | 0 | { |
2010 | 0 | isym = NULL; |
2011 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
2012 | 0 | while (h->root.type == bfd_link_hash_indirect |
2013 | 0 | || h->root.type == bfd_link_hash_warning) |
2014 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
2015 | 0 | } |
2016 | | |
2017 | | /* Check invalid x32 relocations. */ |
2018 | 0 | if (!ABI_64_P (abfd)) |
2019 | 0 | switch (r_type) |
2020 | 0 | { |
2021 | 0 | default: |
2022 | 0 | break; |
2023 | | |
2024 | 0 | case R_X86_64_DTPOFF64: |
2025 | 0 | case R_X86_64_TPOFF64: |
2026 | 0 | case R_X86_64_PC64: |
2027 | 0 | case R_X86_64_GOTOFF64: |
2028 | 0 | case R_X86_64_GOT64: |
2029 | 0 | case R_X86_64_GOTPCREL64: |
2030 | 0 | case R_X86_64_GOTPC64: |
2031 | 0 | case R_X86_64_GOTPLT64: |
2032 | 0 | case R_X86_64_PLTOFF64: |
2033 | 0 | { |
2034 | 0 | if (h) |
2035 | 0 | name = h->root.root.string; |
2036 | 0 | else |
2037 | 0 | name = bfd_elf_sym_name (abfd, symtab_hdr, isym, |
2038 | 0 | NULL); |
2039 | 0 | _bfd_error_handler |
2040 | | /* xgettext:c-format */ |
2041 | 0 | (_("%pB: relocation %s against symbol `%s' isn't " |
2042 | 0 | "supported in x32 mode"), abfd, |
2043 | 0 | x86_64_elf_howto_table[r_type].name, name); |
2044 | 0 | bfd_set_error (bfd_error_bad_value); |
2045 | 0 | goto error_return; |
2046 | 0 | } |
2047 | 0 | break; |
2048 | 0 | } |
2049 | | |
2050 | 0 | eh = (struct elf_x86_link_hash_entry *) h; |
2051 | |
|
2052 | 0 | if (h != NULL) |
2053 | 0 | { |
2054 | | /* It is referenced by a non-shared object. */ |
2055 | 0 | h->ref_regular = 1; |
2056 | 0 | } |
2057 | |
|
2058 | 0 | converted_reloc = false; |
2059 | 0 | if ((r_type == R_X86_64_GOTPCREL |
2060 | 0 | || r_type == R_X86_64_GOTPCRELX |
2061 | 0 | || r_type == R_X86_64_REX_GOTPCRELX) |
2062 | 0 | && (h == NULL || h->type != STT_GNU_IFUNC)) |
2063 | 0 | { |
2064 | 0 | Elf_Internal_Rela *irel = (Elf_Internal_Rela *) rel; |
2065 | 0 | if (!elf_x86_64_convert_load_reloc (abfd, contents, &r_type, |
2066 | 0 | irel, h, &converted_reloc, |
2067 | 0 | info)) |
2068 | 0 | goto error_return; |
2069 | | |
2070 | 0 | if (converted_reloc) |
2071 | 0 | converted = true; |
2072 | 0 | } |
2073 | | |
2074 | 0 | if (!_bfd_elf_x86_valid_reloc_p (sec, info, htab, rel, h, isym, |
2075 | 0 | symtab_hdr, &no_dynreloc)) |
2076 | 0 | return false; |
2077 | | |
2078 | 0 | if (! elf_x86_64_tls_transition (info, abfd, sec, contents, |
2079 | 0 | symtab_hdr, sym_hashes, |
2080 | 0 | &r_type, GOT_UNKNOWN, |
2081 | 0 | rel, rel_end, h, r_symndx, false)) |
2082 | 0 | goto error_return; |
2083 | | |
2084 | | /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */ |
2085 | 0 | if (h == htab->elf.hgot) |
2086 | 0 | htab->got_referenced = true; |
2087 | |
|
2088 | 0 | switch (r_type) |
2089 | 0 | { |
2090 | 0 | case R_X86_64_TLSLD: |
2091 | 0 | htab->tls_ld_or_ldm_got.refcount = 1; |
2092 | 0 | goto create_got; |
2093 | | |
2094 | 0 | case R_X86_64_TPOFF32: |
2095 | 0 | if (!bfd_link_executable (info) && ABI_64_P (abfd)) |
2096 | 0 | return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym, |
2097 | 0 | &x86_64_elf_howto_table[r_type]); |
2098 | 0 | if (eh != NULL) |
2099 | 0 | eh->zero_undefweak &= 0x2; |
2100 | 0 | break; |
2101 | | |
2102 | 0 | case R_X86_64_GOTTPOFF: |
2103 | 0 | if (!bfd_link_executable (info)) |
2104 | 0 | info->flags |= DF_STATIC_TLS; |
2105 | | /* Fall through */ |
2106 | |
|
2107 | 0 | case R_X86_64_GOT32: |
2108 | 0 | case R_X86_64_GOTPCREL: |
2109 | 0 | case R_X86_64_GOTPCRELX: |
2110 | 0 | case R_X86_64_REX_GOTPCRELX: |
2111 | 0 | case R_X86_64_TLSGD: |
2112 | 0 | case R_X86_64_GOT64: |
2113 | 0 | case R_X86_64_GOTPCREL64: |
2114 | 0 | case R_X86_64_GOTPLT64: |
2115 | 0 | case R_X86_64_GOTPC32_TLSDESC: |
2116 | 0 | case R_X86_64_TLSDESC_CALL: |
2117 | | /* This symbol requires a global offset table entry. */ |
2118 | 0 | { |
2119 | 0 | int tls_type, old_tls_type; |
2120 | |
|
2121 | 0 | switch (r_type) |
2122 | 0 | { |
2123 | 0 | default: |
2124 | 0 | tls_type = GOT_NORMAL; |
2125 | 0 | if (h) |
2126 | 0 | { |
2127 | 0 | if (ABS_SYMBOL_P (h)) |
2128 | 0 | tls_type = GOT_ABS; |
2129 | 0 | } |
2130 | 0 | else if (isym->st_shndx == SHN_ABS) |
2131 | 0 | tls_type = GOT_ABS; |
2132 | 0 | break; |
2133 | 0 | case R_X86_64_TLSGD: |
2134 | 0 | tls_type = GOT_TLS_GD; |
2135 | 0 | break; |
2136 | 0 | case R_X86_64_GOTTPOFF: |
2137 | 0 | tls_type = GOT_TLS_IE; |
2138 | 0 | break; |
2139 | 0 | case R_X86_64_GOTPC32_TLSDESC: |
2140 | 0 | case R_X86_64_TLSDESC_CALL: |
2141 | 0 | tls_type = GOT_TLS_GDESC; |
2142 | 0 | break; |
2143 | 0 | } |
2144 | | |
2145 | 0 | if (h != NULL) |
2146 | 0 | { |
2147 | 0 | h->got.refcount = 1; |
2148 | 0 | old_tls_type = eh->tls_type; |
2149 | 0 | } |
2150 | 0 | else |
2151 | 0 | { |
2152 | 0 | bfd_signed_vma *local_got_refcounts; |
2153 | |
|
2154 | 0 | if (!elf_x86_allocate_local_got_info (abfd, |
2155 | 0 | symtab_hdr->sh_info)) |
2156 | 0 | goto error_return; |
2157 | | |
2158 | | /* This is a global offset table entry for a local symbol. */ |
2159 | 0 | local_got_refcounts = elf_local_got_refcounts (abfd); |
2160 | 0 | local_got_refcounts[r_symndx] = 1; |
2161 | 0 | old_tls_type |
2162 | 0 | = elf_x86_local_got_tls_type (abfd) [r_symndx]; |
2163 | 0 | } |
2164 | | |
2165 | | /* If a TLS symbol is accessed using IE at least once, |
2166 | | there is no point to use dynamic model for it. */ |
2167 | 0 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN |
2168 | 0 | && (! GOT_TLS_GD_ANY_P (old_tls_type) |
2169 | 0 | || tls_type != GOT_TLS_IE)) |
2170 | 0 | { |
2171 | 0 | if (old_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (tls_type)) |
2172 | 0 | tls_type = old_tls_type; |
2173 | 0 | else if (GOT_TLS_GD_ANY_P (old_tls_type) |
2174 | 0 | && GOT_TLS_GD_ANY_P (tls_type)) |
2175 | 0 | tls_type |= old_tls_type; |
2176 | 0 | else |
2177 | 0 | { |
2178 | 0 | if (h) |
2179 | 0 | name = h->root.root.string; |
2180 | 0 | else |
2181 | 0 | name = bfd_elf_sym_name (abfd, symtab_hdr, |
2182 | 0 | isym, NULL); |
2183 | 0 | _bfd_error_handler |
2184 | | /* xgettext:c-format */ |
2185 | 0 | (_("%pB: '%s' accessed both as normal and" |
2186 | 0 | " thread local symbol"), |
2187 | 0 | abfd, name); |
2188 | 0 | bfd_set_error (bfd_error_bad_value); |
2189 | 0 | goto error_return; |
2190 | 0 | } |
2191 | 0 | } |
2192 | | |
2193 | 0 | if (old_tls_type != tls_type) |
2194 | 0 | { |
2195 | 0 | if (eh != NULL) |
2196 | 0 | eh->tls_type = tls_type; |
2197 | 0 | else |
2198 | 0 | elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type; |
2199 | 0 | } |
2200 | 0 | } |
2201 | | /* Fall through */ |
2202 | | |
2203 | 0 | case R_X86_64_GOTOFF64: |
2204 | 0 | case R_X86_64_GOTPC32: |
2205 | 0 | case R_X86_64_GOTPC64: |
2206 | 0 | create_got: |
2207 | 0 | if (eh != NULL) |
2208 | 0 | eh->zero_undefweak &= 0x2; |
2209 | 0 | break; |
2210 | | |
2211 | 0 | case R_X86_64_PLT32: |
2212 | | /* This symbol requires a procedure linkage table entry. We |
2213 | | actually build the entry in adjust_dynamic_symbol, |
2214 | | because this might be a case of linking PIC code which is |
2215 | | never referenced by a dynamic object, in which case we |
2216 | | don't need to generate a procedure linkage table entry |
2217 | | after all. */ |
2218 | | |
2219 | | /* If this is a local symbol, we resolve it directly without |
2220 | | creating a procedure linkage table entry. */ |
2221 | 0 | if (h == NULL) |
2222 | 0 | continue; |
2223 | | |
2224 | 0 | eh->zero_undefweak &= 0x2; |
2225 | 0 | h->needs_plt = 1; |
2226 | 0 | h->plt.refcount = 1; |
2227 | 0 | break; |
2228 | | |
2229 | 0 | case R_X86_64_PLTOFF64: |
2230 | | /* This tries to form the 'address' of a function relative |
2231 | | to GOT. For global symbols we need a PLT entry. */ |
2232 | 0 | if (h != NULL) |
2233 | 0 | { |
2234 | 0 | h->needs_plt = 1; |
2235 | 0 | h->plt.refcount = 1; |
2236 | 0 | } |
2237 | 0 | goto create_got; |
2238 | | |
2239 | 0 | case R_X86_64_SIZE32: |
2240 | 0 | case R_X86_64_SIZE64: |
2241 | 0 | size_reloc = true; |
2242 | 0 | goto do_size; |
2243 | | |
2244 | 0 | case R_X86_64_32: |
2245 | 0 | if (!ABI_64_P (abfd)) |
2246 | 0 | goto pointer; |
2247 | | /* Fall through. */ |
2248 | 0 | case R_X86_64_8: |
2249 | 0 | case R_X86_64_16: |
2250 | 0 | case R_X86_64_32S: |
2251 | | /* Check relocation overflow as these relocs may lead to |
2252 | | run-time relocation overflow. Don't error out for |
2253 | | sections we don't care about, such as debug sections or |
2254 | | when relocation overflow check is disabled. */ |
2255 | 0 | if (!htab->params->no_reloc_overflow_check |
2256 | 0 | && !converted_reloc |
2257 | 0 | && (bfd_link_pic (info) |
2258 | 0 | || (bfd_link_executable (info) |
2259 | 0 | && h != NULL |
2260 | 0 | && !h->def_regular |
2261 | 0 | && h->def_dynamic |
2262 | 0 | && (sec->flags & SEC_READONLY) == 0))) |
2263 | 0 | return elf_x86_64_need_pic (info, abfd, sec, h, symtab_hdr, isym, |
2264 | 0 | &x86_64_elf_howto_table[r_type]); |
2265 | | /* Fall through. */ |
2266 | | |
2267 | 0 | case R_X86_64_PC8: |
2268 | 0 | case R_X86_64_PC16: |
2269 | 0 | case R_X86_64_PC32: |
2270 | 0 | case R_X86_64_PC64: |
2271 | 0 | case R_X86_64_64: |
2272 | 0 | pointer: |
2273 | 0 | if (eh != NULL && (sec->flags & SEC_CODE) != 0) |
2274 | 0 | eh->zero_undefweak |= 0x2; |
2275 | | /* We are called after all symbols have been resolved. Only |
2276 | | relocation against STT_GNU_IFUNC symbol must go through |
2277 | | PLT. */ |
2278 | 0 | if (h != NULL |
2279 | 0 | && (bfd_link_executable (info) |
2280 | 0 | || h->type == STT_GNU_IFUNC)) |
2281 | 0 | { |
2282 | 0 | bool func_pointer_ref = false; |
2283 | |
|
2284 | 0 | if (r_type == R_X86_64_PC32) |
2285 | 0 | { |
2286 | | /* Since something like ".long foo - ." may be used |
2287 | | as pointer, make sure that PLT is used if foo is |
2288 | | a function defined in a shared library. */ |
2289 | 0 | if ((sec->flags & SEC_CODE) == 0) |
2290 | 0 | { |
2291 | 0 | h->pointer_equality_needed = 1; |
2292 | 0 | if (bfd_link_pie (info) |
2293 | 0 | && h->type == STT_FUNC |
2294 | 0 | && !h->def_regular |
2295 | 0 | && h->def_dynamic) |
2296 | 0 | { |
2297 | 0 | h->needs_plt = 1; |
2298 | 0 | h->plt.refcount = 1; |
2299 | 0 | } |
2300 | 0 | } |
2301 | 0 | } |
2302 | 0 | else if (r_type != R_X86_64_PC64) |
2303 | 0 | { |
2304 | | /* At run-time, R_X86_64_64 can be resolved for both |
2305 | | x86-64 and x32. But R_X86_64_32 and R_X86_64_32S |
2306 | | can only be resolved for x32. Function pointer |
2307 | | reference doesn't need PLT for pointer equality. */ |
2308 | 0 | if ((sec->flags & SEC_READONLY) == 0 |
2309 | 0 | && (r_type == R_X86_64_64 |
2310 | 0 | || (!ABI_64_P (abfd) |
2311 | 0 | && (r_type == R_X86_64_32 |
2312 | 0 | || r_type == R_X86_64_32S)))) |
2313 | 0 | func_pointer_ref = true; |
2314 | | |
2315 | | /* IFUNC symbol needs pointer equality in PDE so that |
2316 | | function pointer reference will be resolved to its |
2317 | | PLT entry directly. */ |
2318 | 0 | if (!func_pointer_ref |
2319 | 0 | || (bfd_link_pde (info) |
2320 | 0 | && h->type == STT_GNU_IFUNC)) |
2321 | 0 | h->pointer_equality_needed = 1; |
2322 | 0 | } |
2323 | |
|
2324 | 0 | if (!func_pointer_ref) |
2325 | 0 | { |
2326 | | /* If this reloc is in a read-only section, we might |
2327 | | need a copy reloc. We can't check reliably at this |
2328 | | stage whether the section is read-only, as input |
2329 | | sections have not yet been mapped to output sections. |
2330 | | Tentatively set the flag for now, and correct in |
2331 | | adjust_dynamic_symbol. */ |
2332 | 0 | h->non_got_ref = 1; |
2333 | |
|
2334 | 0 | if (!elf_has_indirect_extern_access (sec->owner)) |
2335 | 0 | eh->non_got_ref_without_indirect_extern_access = 1; |
2336 | | |
2337 | | /* We may need a .plt entry if the symbol is a function |
2338 | | defined in a shared lib or is a function referenced |
2339 | | from the code or read-only section. */ |
2340 | 0 | if (!h->def_regular |
2341 | 0 | || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
2342 | 0 | h->plt.refcount = 1; |
2343 | |
|
2344 | 0 | if (htab->elf.target_os != is_solaris |
2345 | 0 | && h->pointer_equality_needed |
2346 | 0 | && h->type == STT_FUNC |
2347 | 0 | && eh->def_protected |
2348 | 0 | && !SYMBOL_DEFINED_NON_SHARED_P (h) |
2349 | 0 | && h->def_dynamic) |
2350 | 0 | { |
2351 | | /* Disallow non-canonical reference to canonical |
2352 | | protected function. */ |
2353 | 0 | _bfd_error_handler |
2354 | | /* xgettext:c-format */ |
2355 | 0 | (_("%pB: non-canonical reference to canonical " |
2356 | 0 | "protected function `%s' in %pB"), |
2357 | 0 | abfd, h->root.root.string, |
2358 | 0 | h->root.u.def.section->owner); |
2359 | 0 | bfd_set_error (bfd_error_bad_value); |
2360 | 0 | goto error_return; |
2361 | 0 | } |
2362 | 0 | } |
2363 | 0 | } |
2364 | | |
2365 | 0 | size_reloc = false; |
2366 | 0 | do_size: |
2367 | 0 | if (!no_dynreloc |
2368 | 0 | && NEED_DYNAMIC_RELOCATION_P (true, info, true, h, sec, |
2369 | 0 | r_type, |
2370 | 0 | htab->pointer_r_type)) |
2371 | 0 | { |
2372 | 0 | struct elf_dyn_relocs *p; |
2373 | 0 | struct elf_dyn_relocs **head; |
2374 | | |
2375 | | /* If this is a global symbol, we count the number of |
2376 | | relocations we need for this symbol. */ |
2377 | 0 | if (h != NULL) |
2378 | 0 | head = &h->dyn_relocs; |
2379 | 0 | else |
2380 | 0 | { |
2381 | | /* Track dynamic relocs needed for local syms too. |
2382 | | We really need local syms available to do this |
2383 | | easily. Oh well. */ |
2384 | 0 | asection *s; |
2385 | 0 | void **vpp; |
2386 | |
|
2387 | 0 | isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, |
2388 | 0 | abfd, r_symndx); |
2389 | 0 | if (isym == NULL) |
2390 | 0 | goto error_return; |
2391 | | |
2392 | 0 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
2393 | 0 | if (s == NULL) |
2394 | 0 | s = sec; |
2395 | | |
2396 | | /* Beware of type punned pointers vs strict aliasing |
2397 | | rules. */ |
2398 | 0 | vpp = &(elf_section_data (s)->local_dynrel); |
2399 | 0 | head = (struct elf_dyn_relocs **)vpp; |
2400 | 0 | } |
2401 | | |
2402 | 0 | p = *head; |
2403 | 0 | if (p == NULL || p->sec != sec) |
2404 | 0 | { |
2405 | 0 | size_t amt = sizeof *p; |
2406 | |
|
2407 | 0 | p = ((struct elf_dyn_relocs *) |
2408 | 0 | bfd_alloc (htab->elf.dynobj, amt)); |
2409 | 0 | if (p == NULL) |
2410 | 0 | goto error_return; |
2411 | 0 | p->next = *head; |
2412 | 0 | *head = p; |
2413 | 0 | p->sec = sec; |
2414 | 0 | p->count = 0; |
2415 | 0 | p->pc_count = 0; |
2416 | 0 | } |
2417 | | |
2418 | 0 | p->count += 1; |
2419 | | /* Count size relocation as PC-relative relocation. */ |
2420 | 0 | if (X86_PCREL_TYPE_P (true, r_type) || size_reloc) |
2421 | 0 | p->pc_count += 1; |
2422 | 0 | } |
2423 | 0 | break; |
2424 | | |
2425 | | /* This relocation describes the C++ object vtable hierarchy. |
2426 | | Reconstruct it for later use during GC. */ |
2427 | 0 | case R_X86_64_GNU_VTINHERIT: |
2428 | 0 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
2429 | 0 | goto error_return; |
2430 | 0 | break; |
2431 | | |
2432 | | /* This relocation describes which C++ vtable entries are actually |
2433 | | used. Record for later use during GC. */ |
2434 | 0 | case R_X86_64_GNU_VTENTRY: |
2435 | 0 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
2436 | 0 | goto error_return; |
2437 | 0 | break; |
2438 | | |
2439 | 0 | default: |
2440 | 0 | break; |
2441 | 0 | } |
2442 | 0 | } |
2443 | | |
2444 | 0 | if (elf_section_data (sec)->this_hdr.contents != contents) |
2445 | 0 | { |
2446 | 0 | if (!converted && !_bfd_link_keep_memory (info)) |
2447 | 0 | free (contents); |
2448 | 0 | else |
2449 | 0 | { |
2450 | | /* Cache the section contents for elf_link_input_bfd if any |
2451 | | load is converted or --no-keep-memory isn't used. */ |
2452 | 0 | elf_section_data (sec)->this_hdr.contents = contents; |
2453 | 0 | info->cache_size += sec->size; |
2454 | 0 | } |
2455 | 0 | } |
2456 | | |
2457 | | /* Cache relocations if any load is converted. */ |
2458 | 0 | if (elf_section_data (sec)->relocs != relocs && converted) |
2459 | 0 | elf_section_data (sec)->relocs = (Elf_Internal_Rela *) relocs; |
2460 | |
|
2461 | 0 | return true; |
2462 | | |
2463 | 0 | error_return: |
2464 | 0 | if (elf_section_data (sec)->this_hdr.contents != contents) |
2465 | 0 | free (contents); |
2466 | 0 | sec->check_relocs_failed = 1; |
2467 | 0 | return false; |
2468 | 0 | } |
2469 | | |
2470 | | static bool |
2471 | | elf_x86_64_always_size_sections (bfd *output_bfd, |
2472 | | struct bfd_link_info *info) |
2473 | 0 | { |
2474 | 0 | bfd *abfd; |
2475 | | |
2476 | | /* Scan relocations after rel_from_abs has been set on __ehdr_start. */ |
2477 | 0 | for (abfd = info->input_bfds; |
2478 | 0 | abfd != (bfd *) NULL; |
2479 | 0 | abfd = abfd->link.next) |
2480 | 0 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour |
2481 | 0 | && !_bfd_elf_link_iterate_on_relocs (abfd, info, |
2482 | 0 | elf_x86_64_scan_relocs)) |
2483 | 0 | return false; |
2484 | | |
2485 | 0 | return _bfd_x86_elf_always_size_sections (output_bfd, info); |
2486 | 0 | } |
2487 | | |
2488 | | /* Return the relocation value for @tpoff relocation |
2489 | | if STT_TLS virtual address is ADDRESS. */ |
2490 | | |
2491 | | static bfd_vma |
2492 | | elf_x86_64_tpoff (struct bfd_link_info *info, bfd_vma address) |
2493 | 0 | { |
2494 | 0 | struct elf_link_hash_table *htab = elf_hash_table (info); |
2495 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd); |
2496 | 0 | bfd_vma static_tls_size; |
2497 | | |
2498 | | /* If tls_segment is NULL, we should have signalled an error already. */ |
2499 | 0 | if (htab->tls_sec == NULL) |
2500 | 0 | return 0; |
2501 | | |
2502 | | /* Consider special static TLS alignment requirements. */ |
2503 | 0 | static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment); |
2504 | 0 | return address - static_tls_size - htab->tls_sec->vma; |
2505 | 0 | } |
2506 | | |
2507 | | /* Relocate an x86_64 ELF section. */ |
2508 | | |
2509 | | static int |
2510 | | elf_x86_64_relocate_section (bfd *output_bfd, |
2511 | | struct bfd_link_info *info, |
2512 | | bfd *input_bfd, |
2513 | | asection *input_section, |
2514 | | bfd_byte *contents, |
2515 | | Elf_Internal_Rela *relocs, |
2516 | | Elf_Internal_Sym *local_syms, |
2517 | | asection **local_sections) |
2518 | 0 | { |
2519 | 0 | struct elf_x86_link_hash_table *htab; |
2520 | 0 | Elf_Internal_Shdr *symtab_hdr; |
2521 | 0 | struct elf_link_hash_entry **sym_hashes; |
2522 | 0 | bfd_vma *local_got_offsets; |
2523 | 0 | bfd_vma *local_tlsdesc_gotents; |
2524 | 0 | Elf_Internal_Rela *rel; |
2525 | 0 | Elf_Internal_Rela *wrel; |
2526 | 0 | Elf_Internal_Rela *relend; |
2527 | 0 | unsigned int plt_entry_size; |
2528 | 0 | bool status; |
2529 | | |
2530 | | /* Skip if check_relocs or scan_relocs failed. */ |
2531 | 0 | if (input_section->check_relocs_failed) |
2532 | 0 | return false; |
2533 | | |
2534 | 0 | htab = elf_x86_hash_table (info, X86_64_ELF_DATA); |
2535 | 0 | if (htab == NULL) |
2536 | 0 | return false; |
2537 | | |
2538 | 0 | if (!is_x86_elf (input_bfd, htab)) |
2539 | 0 | { |
2540 | 0 | bfd_set_error (bfd_error_wrong_format); |
2541 | 0 | return false; |
2542 | 0 | } |
2543 | | |
2544 | 0 | plt_entry_size = htab->plt.plt_entry_size; |
2545 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
2546 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
2547 | 0 | local_got_offsets = elf_local_got_offsets (input_bfd); |
2548 | 0 | local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd); |
2549 | |
|
2550 | 0 | _bfd_x86_elf_set_tls_module_base (info); |
2551 | |
|
2552 | 0 | status = true; |
2553 | 0 | rel = wrel = relocs; |
2554 | 0 | relend = relocs + input_section->reloc_count; |
2555 | 0 | for (; rel < relend; wrel++, rel++) |
2556 | 0 | { |
2557 | 0 | unsigned int r_type, r_type_tls; |
2558 | 0 | reloc_howto_type *howto; |
2559 | 0 | unsigned long r_symndx; |
2560 | 0 | struct elf_link_hash_entry *h; |
2561 | 0 | struct elf_x86_link_hash_entry *eh; |
2562 | 0 | Elf_Internal_Sym *sym; |
2563 | 0 | asection *sec; |
2564 | 0 | bfd_vma off, offplt, plt_offset; |
2565 | 0 | bfd_vma relocation; |
2566 | 0 | bool unresolved_reloc; |
2567 | 0 | bfd_reloc_status_type r; |
2568 | 0 | int tls_type; |
2569 | 0 | asection *base_got, *resolved_plt; |
2570 | 0 | bfd_vma st_size; |
2571 | 0 | bool resolved_to_zero; |
2572 | 0 | bool relative_reloc; |
2573 | 0 | bool converted_reloc; |
2574 | 0 | bool need_copy_reloc_in_pie; |
2575 | 0 | bool no_copyreloc_p; |
2576 | |
|
2577 | 0 | r_type = ELF32_R_TYPE (rel->r_info); |
2578 | 0 | if (r_type == (int) R_X86_64_GNU_VTINHERIT |
2579 | 0 | || r_type == (int) R_X86_64_GNU_VTENTRY) |
2580 | 0 | { |
2581 | 0 | if (wrel != rel) |
2582 | 0 | *wrel = *rel; |
2583 | 0 | continue; |
2584 | 0 | } |
2585 | | |
2586 | 0 | r_symndx = htab->r_sym (rel->r_info); |
2587 | 0 | converted_reloc = (r_type & R_X86_64_converted_reloc_bit) != 0; |
2588 | 0 | if (converted_reloc) |
2589 | 0 | { |
2590 | 0 | r_type &= ~R_X86_64_converted_reloc_bit; |
2591 | 0 | rel->r_info = htab->r_info (r_symndx, r_type); |
2592 | 0 | } |
2593 | |
|
2594 | 0 | howto = elf_x86_64_rtype_to_howto (input_bfd, r_type); |
2595 | 0 | if (howto == NULL) |
2596 | 0 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
2597 | | |
2598 | 0 | h = NULL; |
2599 | 0 | sym = NULL; |
2600 | 0 | sec = NULL; |
2601 | 0 | unresolved_reloc = false; |
2602 | 0 | if (r_symndx < symtab_hdr->sh_info) |
2603 | 0 | { |
2604 | 0 | sym = local_syms + r_symndx; |
2605 | 0 | sec = local_sections[r_symndx]; |
2606 | |
|
2607 | 0 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, |
2608 | 0 | &sec, rel); |
2609 | 0 | st_size = sym->st_size; |
2610 | | |
2611 | | /* Relocate against local STT_GNU_IFUNC symbol. */ |
2612 | 0 | if (!bfd_link_relocatable (info) |
2613 | 0 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
2614 | 0 | { |
2615 | 0 | h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd, |
2616 | 0 | rel, false); |
2617 | 0 | if (h == NULL) |
2618 | 0 | abort (); |
2619 | | |
2620 | | /* Set STT_GNU_IFUNC symbol value. */ |
2621 | 0 | h->root.u.def.value = sym->st_value; |
2622 | 0 | h->root.u.def.section = sec; |
2623 | 0 | } |
2624 | 0 | } |
2625 | 0 | else |
2626 | 0 | { |
2627 | 0 | bool warned ATTRIBUTE_UNUSED; |
2628 | 0 | bool ignored ATTRIBUTE_UNUSED; |
2629 | |
|
2630 | 0 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
2631 | 0 | r_symndx, symtab_hdr, sym_hashes, |
2632 | 0 | h, sec, relocation, |
2633 | 0 | unresolved_reloc, warned, ignored); |
2634 | 0 | st_size = h->size; |
2635 | 0 | } |
2636 | | |
2637 | 0 | if (sec != NULL && discarded_section (sec)) |
2638 | 0 | { |
2639 | 0 | _bfd_clear_contents (howto, input_bfd, input_section, |
2640 | 0 | contents, rel->r_offset); |
2641 | 0 | wrel->r_offset = rel->r_offset; |
2642 | 0 | wrel->r_info = 0; |
2643 | 0 | wrel->r_addend = 0; |
2644 | | |
2645 | | /* For ld -r, remove relocations in debug sections against |
2646 | | sections defined in discarded sections. Not done for |
2647 | | eh_frame editing code expects to be present. */ |
2648 | 0 | if (bfd_link_relocatable (info) |
2649 | 0 | && (input_section->flags & SEC_DEBUGGING)) |
2650 | 0 | wrel--; |
2651 | |
|
2652 | 0 | continue; |
2653 | 0 | } |
2654 | | |
2655 | 0 | if (bfd_link_relocatable (info)) |
2656 | 0 | { |
2657 | 0 | if (wrel != rel) |
2658 | 0 | *wrel = *rel; |
2659 | 0 | continue; |
2660 | 0 | } |
2661 | | |
2662 | 0 | if (rel->r_addend == 0 && !ABI_64_P (output_bfd)) |
2663 | 0 | { |
2664 | 0 | if (r_type == R_X86_64_64) |
2665 | 0 | { |
2666 | | /* For x32, treat R_X86_64_64 like R_X86_64_32 and |
2667 | | zero-extend it to 64bit if addend is zero. */ |
2668 | 0 | r_type = R_X86_64_32; |
2669 | 0 | memset (contents + rel->r_offset + 4, 0, 4); |
2670 | 0 | } |
2671 | 0 | else if (r_type == R_X86_64_SIZE64) |
2672 | 0 | { |
2673 | | /* For x32, treat R_X86_64_SIZE64 like R_X86_64_SIZE32 and |
2674 | | zero-extend it to 64bit if addend is zero. */ |
2675 | 0 | r_type = R_X86_64_SIZE32; |
2676 | 0 | memset (contents + rel->r_offset + 4, 0, 4); |
2677 | 0 | } |
2678 | 0 | } |
2679 | |
|
2680 | 0 | eh = (struct elf_x86_link_hash_entry *) h; |
2681 | | |
2682 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
2683 | | it here if it is defined in a non-shared object. */ |
2684 | 0 | if (h != NULL |
2685 | 0 | && h->type == STT_GNU_IFUNC |
2686 | 0 | && h->def_regular) |
2687 | 0 | { |
2688 | 0 | bfd_vma plt_index; |
2689 | 0 | const char *name; |
2690 | |
|
2691 | 0 | if ((input_section->flags & SEC_ALLOC) == 0) |
2692 | 0 | { |
2693 | | /* If this is a SHT_NOTE section without SHF_ALLOC, treat |
2694 | | STT_GNU_IFUNC symbol as STT_FUNC. */ |
2695 | 0 | if (elf_section_type (input_section) == SHT_NOTE) |
2696 | 0 | goto skip_ifunc; |
2697 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
2698 | | sections because such sections are not SEC_ALLOC and |
2699 | | thus ld.so will not process them. */ |
2700 | 0 | if ((input_section->flags & SEC_DEBUGGING) != 0) |
2701 | 0 | continue; |
2702 | 0 | abort (); |
2703 | 0 | } |
2704 | | |
2705 | 0 | switch (r_type) |
2706 | 0 | { |
2707 | 0 | default: |
2708 | 0 | break; |
2709 | | |
2710 | 0 | case R_X86_64_GOTPCREL: |
2711 | 0 | case R_X86_64_GOTPCRELX: |
2712 | 0 | case R_X86_64_REX_GOTPCRELX: |
2713 | 0 | case R_X86_64_GOTPCREL64: |
2714 | 0 | base_got = htab->elf.sgot; |
2715 | 0 | off = h->got.offset; |
2716 | |
|
2717 | 0 | if (base_got == NULL) |
2718 | 0 | abort (); |
2719 | | |
2720 | 0 | if (off == (bfd_vma) -1) |
2721 | 0 | { |
2722 | | /* We can't use h->got.offset here to save state, or |
2723 | | even just remember the offset, as finish_dynamic_symbol |
2724 | | would use that as offset into .got. */ |
2725 | |
|
2726 | 0 | if (h->plt.offset == (bfd_vma) -1) |
2727 | 0 | abort (); |
2728 | | |
2729 | 0 | if (htab->elf.splt != NULL) |
2730 | 0 | { |
2731 | 0 | plt_index = (h->plt.offset / plt_entry_size |
2732 | 0 | - htab->plt.has_plt0); |
2733 | 0 | off = (plt_index + 3) * GOT_ENTRY_SIZE; |
2734 | 0 | base_got = htab->elf.sgotplt; |
2735 | 0 | } |
2736 | 0 | else |
2737 | 0 | { |
2738 | 0 | plt_index = h->plt.offset / plt_entry_size; |
2739 | 0 | off = plt_index * GOT_ENTRY_SIZE; |
2740 | 0 | base_got = htab->elf.igotplt; |
2741 | 0 | } |
2742 | |
|
2743 | 0 | if (h->dynindx == -1 |
2744 | 0 | || h->forced_local |
2745 | 0 | || info->symbolic) |
2746 | 0 | { |
2747 | | /* This references the local defitionion. We must |
2748 | | initialize this entry in the global offset table. |
2749 | | Since the offset must always be a multiple of 8, |
2750 | | we use the least significant bit to record |
2751 | | whether we have initialized it already. |
2752 | | |
2753 | | When doing a dynamic link, we create a .rela.got |
2754 | | relocation entry to initialize the value. This |
2755 | | is done in the finish_dynamic_symbol routine. */ |
2756 | 0 | if ((off & 1) != 0) |
2757 | 0 | off &= ~1; |
2758 | 0 | else |
2759 | 0 | { |
2760 | 0 | bfd_put_64 (output_bfd, relocation, |
2761 | 0 | base_got->contents + off); |
2762 | | /* Note that this is harmless for the GOTPLT64 |
2763 | | case, as -1 | 1 still is -1. */ |
2764 | 0 | h->got.offset |= 1; |
2765 | 0 | } |
2766 | 0 | } |
2767 | 0 | } |
2768 | | |
2769 | 0 | relocation = (base_got->output_section->vma |
2770 | 0 | + base_got->output_offset + off); |
2771 | |
|
2772 | 0 | goto do_relocation; |
2773 | 0 | } |
2774 | | |
2775 | 0 | if (h->plt.offset == (bfd_vma) -1) |
2776 | 0 | { |
2777 | | /* Handle static pointers of STT_GNU_IFUNC symbols. */ |
2778 | 0 | if (r_type == htab->pointer_r_type |
2779 | 0 | && (input_section->flags & SEC_CODE) == 0) |
2780 | 0 | goto do_ifunc_pointer; |
2781 | 0 | goto bad_ifunc_reloc; |
2782 | 0 | } |
2783 | | |
2784 | | /* STT_GNU_IFUNC symbol must go through PLT. */ |
2785 | 0 | if (htab->elf.splt != NULL) |
2786 | 0 | { |
2787 | 0 | if (htab->plt_second != NULL) |
2788 | 0 | { |
2789 | 0 | resolved_plt = htab->plt_second; |
2790 | 0 | plt_offset = eh->plt_second.offset; |
2791 | 0 | } |
2792 | 0 | else |
2793 | 0 | { |
2794 | 0 | resolved_plt = htab->elf.splt; |
2795 | 0 | plt_offset = h->plt.offset; |
2796 | 0 | } |
2797 | 0 | } |
2798 | 0 | else |
2799 | 0 | { |
2800 | 0 | resolved_plt = htab->elf.iplt; |
2801 | 0 | plt_offset = h->plt.offset; |
2802 | 0 | } |
2803 | |
|
2804 | 0 | relocation = (resolved_plt->output_section->vma |
2805 | 0 | + resolved_plt->output_offset + plt_offset); |
2806 | |
|
2807 | 0 | switch (r_type) |
2808 | 0 | { |
2809 | 0 | default: |
2810 | 0 | bad_ifunc_reloc: |
2811 | 0 | if (h->root.root.string) |
2812 | 0 | name = h->root.root.string; |
2813 | 0 | else |
2814 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
2815 | 0 | NULL); |
2816 | 0 | _bfd_error_handler |
2817 | | /* xgettext:c-format */ |
2818 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
2819 | 0 | "symbol `%s' isn't supported"), input_bfd, |
2820 | 0 | howto->name, name); |
2821 | 0 | bfd_set_error (bfd_error_bad_value); |
2822 | 0 | return false; |
2823 | | |
2824 | 0 | case R_X86_64_32S: |
2825 | 0 | if (bfd_link_pic (info)) |
2826 | 0 | abort (); |
2827 | 0 | goto do_relocation; |
2828 | | |
2829 | 0 | case R_X86_64_32: |
2830 | 0 | if (ABI_64_P (output_bfd)) |
2831 | 0 | goto do_relocation; |
2832 | | /* FALLTHROUGH */ |
2833 | 0 | case R_X86_64_64: |
2834 | 0 | do_ifunc_pointer: |
2835 | 0 | if (rel->r_addend != 0) |
2836 | 0 | { |
2837 | 0 | if (h->root.root.string) |
2838 | 0 | name = h->root.root.string; |
2839 | 0 | else |
2840 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, |
2841 | 0 | sym, NULL); |
2842 | 0 | _bfd_error_handler |
2843 | | /* xgettext:c-format */ |
2844 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
2845 | 0 | "symbol `%s' has non-zero addend: %" PRId64), |
2846 | 0 | input_bfd, howto->name, name, (int64_t) rel->r_addend); |
2847 | 0 | bfd_set_error (bfd_error_bad_value); |
2848 | 0 | return false; |
2849 | 0 | } |
2850 | | |
2851 | | /* Generate dynamic relcoation only when there is a |
2852 | | non-GOT reference in a shared object or there is no |
2853 | | PLT. */ |
2854 | 0 | if ((bfd_link_pic (info) && h->non_got_ref) |
2855 | 0 | || h->plt.offset == (bfd_vma) -1) |
2856 | 0 | { |
2857 | 0 | Elf_Internal_Rela outrel; |
2858 | 0 | asection *sreloc; |
2859 | | |
2860 | | /* Need a dynamic relocation to get the real function |
2861 | | address. */ |
2862 | 0 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, |
2863 | 0 | info, |
2864 | 0 | input_section, |
2865 | 0 | rel->r_offset); |
2866 | 0 | if (outrel.r_offset == (bfd_vma) -1 |
2867 | 0 | || outrel.r_offset == (bfd_vma) -2) |
2868 | 0 | abort (); |
2869 | | |
2870 | 0 | outrel.r_offset += (input_section->output_section->vma |
2871 | 0 | + input_section->output_offset); |
2872 | |
|
2873 | 0 | if (POINTER_LOCAL_IFUNC_P (info, h)) |
2874 | 0 | { |
2875 | 0 | info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"), |
2876 | 0 | h->root.root.string, |
2877 | 0 | h->root.u.def.section->owner); |
2878 | | |
2879 | | /* This symbol is resolved locally. */ |
2880 | 0 | outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE); |
2881 | 0 | outrel.r_addend = (h->root.u.def.value |
2882 | 0 | + h->root.u.def.section->output_section->vma |
2883 | 0 | + h->root.u.def.section->output_offset); |
2884 | |
|
2885 | 0 | if (htab->params->report_relative_reloc) |
2886 | 0 | _bfd_x86_elf_link_report_relative_reloc |
2887 | 0 | (info, input_section, h, sym, |
2888 | 0 | "R_X86_64_IRELATIVE", &outrel); |
2889 | 0 | } |
2890 | 0 | else |
2891 | 0 | { |
2892 | 0 | outrel.r_info = htab->r_info (h->dynindx, r_type); |
2893 | 0 | outrel.r_addend = 0; |
2894 | 0 | } |
2895 | | |
2896 | | /* Dynamic relocations are stored in |
2897 | | 1. .rela.ifunc section in PIC object. |
2898 | | 2. .rela.got section in dynamic executable. |
2899 | | 3. .rela.iplt section in static executable. */ |
2900 | 0 | if (bfd_link_pic (info)) |
2901 | 0 | sreloc = htab->elf.irelifunc; |
2902 | 0 | else if (htab->elf.splt != NULL) |
2903 | 0 | sreloc = htab->elf.srelgot; |
2904 | 0 | else |
2905 | 0 | sreloc = htab->elf.irelplt; |
2906 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
2907 | | |
2908 | | /* If this reloc is against an external symbol, we |
2909 | | do not want to fiddle with the addend. Otherwise, |
2910 | | we need to include the symbol value so that it |
2911 | | becomes an addend for the dynamic reloc. For an |
2912 | | internal symbol, we have updated addend. */ |
2913 | 0 | continue; |
2914 | 0 | } |
2915 | | /* FALLTHROUGH */ |
2916 | 0 | case R_X86_64_PC32: |
2917 | 0 | case R_X86_64_PC64: |
2918 | 0 | case R_X86_64_PLT32: |
2919 | 0 | goto do_relocation; |
2920 | 0 | } |
2921 | 0 | } |
2922 | | |
2923 | 0 | skip_ifunc: |
2924 | 0 | resolved_to_zero = (eh != NULL |
2925 | 0 | && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh)); |
2926 | | |
2927 | | /* When generating a shared object, the relocations handled here are |
2928 | | copied into the output file to be resolved at run time. */ |
2929 | 0 | switch (r_type) |
2930 | 0 | { |
2931 | 0 | case R_X86_64_GOT32: |
2932 | 0 | case R_X86_64_GOT64: |
2933 | | /* Relocation is to the entry for this symbol in the global |
2934 | | offset table. */ |
2935 | 0 | case R_X86_64_GOTPCREL: |
2936 | 0 | case R_X86_64_GOTPCRELX: |
2937 | 0 | case R_X86_64_REX_GOTPCRELX: |
2938 | 0 | case R_X86_64_GOTPCREL64: |
2939 | | /* Use global offset table entry as symbol value. */ |
2940 | 0 | case R_X86_64_GOTPLT64: |
2941 | | /* This is obsolete and treated the same as GOT64. */ |
2942 | 0 | base_got = htab->elf.sgot; |
2943 | |
|
2944 | 0 | if (htab->elf.sgot == NULL) |
2945 | 0 | abort (); |
2946 | | |
2947 | 0 | relative_reloc = false; |
2948 | 0 | if (h != NULL) |
2949 | 0 | { |
2950 | 0 | off = h->got.offset; |
2951 | 0 | if (h->needs_plt |
2952 | 0 | && h->plt.offset != (bfd_vma)-1 |
2953 | 0 | && off == (bfd_vma)-1) |
2954 | 0 | { |
2955 | | /* We can't use h->got.offset here to save |
2956 | | state, or even just remember the offset, as |
2957 | | finish_dynamic_symbol would use that as offset into |
2958 | | .got. */ |
2959 | 0 | bfd_vma plt_index = (h->plt.offset / plt_entry_size |
2960 | 0 | - htab->plt.has_plt0); |
2961 | 0 | off = (plt_index + 3) * GOT_ENTRY_SIZE; |
2962 | 0 | base_got = htab->elf.sgotplt; |
2963 | 0 | } |
2964 | |
|
2965 | 0 | if (RESOLVED_LOCALLY_P (info, h, htab)) |
2966 | 0 | { |
2967 | | /* We must initialize this entry in the global offset |
2968 | | table. Since the offset must always be a multiple |
2969 | | of 8, we use the least significant bit to record |
2970 | | whether we have initialized it already. |
2971 | | |
2972 | | When doing a dynamic link, we create a .rela.got |
2973 | | relocation entry to initialize the value. This is |
2974 | | done in the finish_dynamic_symbol routine. */ |
2975 | 0 | if ((off & 1) != 0) |
2976 | 0 | off &= ~1; |
2977 | 0 | else |
2978 | 0 | { |
2979 | 0 | bfd_put_64 (output_bfd, relocation, |
2980 | 0 | base_got->contents + off); |
2981 | | /* Note that this is harmless for the GOTPLT64 case, |
2982 | | as -1 | 1 still is -1. */ |
2983 | 0 | h->got.offset |= 1; |
2984 | | |
2985 | | /* NB: Don't generate relative relocation here if |
2986 | | it has been generated by DT_RELR. */ |
2987 | 0 | if (!info->enable_dt_relr |
2988 | 0 | && GENERATE_RELATIVE_RELOC_P (info, h)) |
2989 | 0 | { |
2990 | | /* If this symbol isn't dynamic in PIC, |
2991 | | generate R_X86_64_RELATIVE here. */ |
2992 | 0 | eh->no_finish_dynamic_symbol = 1; |
2993 | 0 | relative_reloc = true; |
2994 | 0 | } |
2995 | 0 | } |
2996 | 0 | } |
2997 | 0 | else |
2998 | 0 | unresolved_reloc = false; |
2999 | 0 | } |
3000 | 0 | else |
3001 | 0 | { |
3002 | 0 | if (local_got_offsets == NULL) |
3003 | 0 | abort (); |
3004 | | |
3005 | 0 | off = local_got_offsets[r_symndx]; |
3006 | | |
3007 | | /* The offset must always be a multiple of 8. We use |
3008 | | the least significant bit to record whether we have |
3009 | | already generated the necessary reloc. */ |
3010 | 0 | if ((off & 1) != 0) |
3011 | 0 | off &= ~1; |
3012 | 0 | else |
3013 | 0 | { |
3014 | 0 | bfd_put_64 (output_bfd, relocation, |
3015 | 0 | base_got->contents + off); |
3016 | 0 | local_got_offsets[r_symndx] |= 1; |
3017 | | |
3018 | | /* NB: GOTPCREL relocations against local absolute |
3019 | | symbol store relocation value in the GOT slot |
3020 | | without relative relocation. Don't generate |
3021 | | relative relocation here if it has been generated |
3022 | | by DT_RELR. */ |
3023 | 0 | if (!info->enable_dt_relr |
3024 | 0 | && bfd_link_pic (info) |
3025 | 0 | && !(sym->st_shndx == SHN_ABS |
3026 | 0 | && (r_type == R_X86_64_GOTPCREL |
3027 | 0 | || r_type == R_X86_64_GOTPCRELX |
3028 | 0 | || r_type == R_X86_64_REX_GOTPCRELX))) |
3029 | 0 | relative_reloc = true; |
3030 | 0 | } |
3031 | 0 | } |
3032 | | |
3033 | 0 | if (relative_reloc) |
3034 | 0 | { |
3035 | 0 | asection *s; |
3036 | 0 | Elf_Internal_Rela outrel; |
3037 | | |
3038 | | /* We need to generate a R_X86_64_RELATIVE reloc |
3039 | | for the dynamic linker. */ |
3040 | 0 | s = htab->elf.srelgot; |
3041 | 0 | if (s == NULL) |
3042 | 0 | abort (); |
3043 | | |
3044 | 0 | outrel.r_offset = (base_got->output_section->vma |
3045 | 0 | + base_got->output_offset |
3046 | 0 | + off); |
3047 | 0 | outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE); |
3048 | 0 | outrel.r_addend = relocation; |
3049 | |
|
3050 | 0 | if (htab->params->report_relative_reloc) |
3051 | 0 | _bfd_x86_elf_link_report_relative_reloc |
3052 | 0 | (info, input_section, h, sym, "R_X86_64_RELATIVE", |
3053 | 0 | &outrel); |
3054 | |
|
3055 | 0 | elf_append_rela (output_bfd, s, &outrel); |
3056 | 0 | } |
3057 | | |
3058 | 0 | if (off >= (bfd_vma) -2) |
3059 | 0 | abort (); |
3060 | | |
3061 | 0 | relocation = base_got->output_section->vma |
3062 | 0 | + base_got->output_offset + off; |
3063 | 0 | if (r_type != R_X86_64_GOTPCREL |
3064 | 0 | && r_type != R_X86_64_GOTPCRELX |
3065 | 0 | && r_type != R_X86_64_REX_GOTPCRELX |
3066 | 0 | && r_type != R_X86_64_GOTPCREL64) |
3067 | 0 | relocation -= htab->elf.sgotplt->output_section->vma |
3068 | 0 | - htab->elf.sgotplt->output_offset; |
3069 | |
|
3070 | 0 | break; |
3071 | | |
3072 | 0 | case R_X86_64_GOTOFF64: |
3073 | | /* Relocation is relative to the start of the global offset |
3074 | | table. */ |
3075 | | |
3076 | | /* Check to make sure it isn't a protected function or data |
3077 | | symbol for shared library since it may not be local when |
3078 | | used as function address or with copy relocation. We also |
3079 | | need to make sure that a symbol is referenced locally. */ |
3080 | 0 | if (bfd_link_pic (info) && h) |
3081 | 0 | { |
3082 | 0 | if (!h->def_regular) |
3083 | 0 | { |
3084 | 0 | const char *v; |
3085 | |
|
3086 | 0 | switch (ELF_ST_VISIBILITY (h->other)) |
3087 | 0 | { |
3088 | 0 | case STV_HIDDEN: |
3089 | 0 | v = _("hidden symbol"); |
3090 | 0 | break; |
3091 | 0 | case STV_INTERNAL: |
3092 | 0 | v = _("internal symbol"); |
3093 | 0 | break; |
3094 | 0 | case STV_PROTECTED: |
3095 | 0 | v = _("protected symbol"); |
3096 | 0 | break; |
3097 | 0 | default: |
3098 | 0 | v = _("symbol"); |
3099 | 0 | break; |
3100 | 0 | } |
3101 | | |
3102 | 0 | _bfd_error_handler |
3103 | | /* xgettext:c-format */ |
3104 | 0 | (_("%pB: relocation R_X86_64_GOTOFF64 against undefined %s" |
3105 | 0 | " `%s' can not be used when making a shared object"), |
3106 | 0 | input_bfd, v, h->root.root.string); |
3107 | 0 | bfd_set_error (bfd_error_bad_value); |
3108 | 0 | return false; |
3109 | 0 | } |
3110 | 0 | else if (!bfd_link_executable (info) |
3111 | 0 | && !SYMBOL_REFERENCES_LOCAL_P (info, h) |
3112 | 0 | && (h->type == STT_FUNC |
3113 | 0 | || h->type == STT_OBJECT) |
3114 | 0 | && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) |
3115 | 0 | { |
3116 | 0 | _bfd_error_handler |
3117 | | /* xgettext:c-format */ |
3118 | 0 | (_("%pB: relocation R_X86_64_GOTOFF64 against protected %s" |
3119 | 0 | " `%s' can not be used when making a shared object"), |
3120 | 0 | input_bfd, |
3121 | 0 | h->type == STT_FUNC ? "function" : "data", |
3122 | 0 | h->root.root.string); |
3123 | 0 | bfd_set_error (bfd_error_bad_value); |
3124 | 0 | return false; |
3125 | 0 | } |
3126 | 0 | } |
3127 | | |
3128 | | /* Note that sgot is not involved in this |
3129 | | calculation. We always want the start of .got.plt. If we |
3130 | | defined _GLOBAL_OFFSET_TABLE_ in a different way, as is |
3131 | | permitted by the ABI, we might have to change this |
3132 | | calculation. */ |
3133 | 0 | relocation -= htab->elf.sgotplt->output_section->vma |
3134 | 0 | + htab->elf.sgotplt->output_offset; |
3135 | 0 | break; |
3136 | | |
3137 | 0 | case R_X86_64_GOTPC32: |
3138 | 0 | case R_X86_64_GOTPC64: |
3139 | | /* Use global offset table as symbol value. */ |
3140 | 0 | relocation = htab->elf.sgotplt->output_section->vma |
3141 | 0 | + htab->elf.sgotplt->output_offset; |
3142 | 0 | unresolved_reloc = false; |
3143 | 0 | break; |
3144 | | |
3145 | 0 | case R_X86_64_PLTOFF64: |
3146 | | /* Relocation is PLT entry relative to GOT. For local |
3147 | | symbols it's the symbol itself relative to GOT. */ |
3148 | 0 | if (h != NULL |
3149 | | /* See PLT32 handling. */ |
3150 | 0 | && (h->plt.offset != (bfd_vma) -1 |
3151 | 0 | || eh->plt_got.offset != (bfd_vma) -1) |
3152 | 0 | && htab->elf.splt != NULL) |
3153 | 0 | { |
3154 | 0 | if (eh->plt_got.offset != (bfd_vma) -1) |
3155 | 0 | { |
3156 | | /* Use the GOT PLT. */ |
3157 | 0 | resolved_plt = htab->plt_got; |
3158 | 0 | plt_offset = eh->plt_got.offset; |
3159 | 0 | } |
3160 | 0 | else if (htab->plt_second != NULL) |
3161 | 0 | { |
3162 | 0 | resolved_plt = htab->plt_second; |
3163 | 0 | plt_offset = eh->plt_second.offset; |
3164 | 0 | } |
3165 | 0 | else |
3166 | 0 | { |
3167 | 0 | resolved_plt = htab->elf.splt; |
3168 | 0 | plt_offset = h->plt.offset; |
3169 | 0 | } |
3170 | |
|
3171 | 0 | relocation = (resolved_plt->output_section->vma |
3172 | 0 | + resolved_plt->output_offset |
3173 | 0 | + plt_offset); |
3174 | 0 | unresolved_reloc = false; |
3175 | 0 | } |
3176 | |
|
3177 | 0 | relocation -= htab->elf.sgotplt->output_section->vma |
3178 | 0 | + htab->elf.sgotplt->output_offset; |
3179 | 0 | break; |
3180 | | |
3181 | 0 | case R_X86_64_PLT32: |
3182 | | /* Relocation is to the entry for this symbol in the |
3183 | | procedure linkage table. */ |
3184 | | |
3185 | | /* Resolve a PLT32 reloc against a local symbol directly, |
3186 | | without using the procedure linkage table. */ |
3187 | 0 | if (h == NULL) |
3188 | 0 | break; |
3189 | | |
3190 | 0 | if ((h->plt.offset == (bfd_vma) -1 |
3191 | 0 | && eh->plt_got.offset == (bfd_vma) -1) |
3192 | 0 | || htab->elf.splt == NULL) |
3193 | 0 | { |
3194 | | /* We didn't make a PLT entry for this symbol. This |
3195 | | happens when statically linking PIC code, or when |
3196 | | using -Bsymbolic. */ |
3197 | 0 | break; |
3198 | 0 | } |
3199 | | |
3200 | 0 | use_plt: |
3201 | 0 | if (h->plt.offset != (bfd_vma) -1) |
3202 | 0 | { |
3203 | 0 | if (htab->plt_second != NULL) |
3204 | 0 | { |
3205 | 0 | resolved_plt = htab->plt_second; |
3206 | 0 | plt_offset = eh->plt_second.offset; |
3207 | 0 | } |
3208 | 0 | else |
3209 | 0 | { |
3210 | 0 | resolved_plt = htab->elf.splt; |
3211 | 0 | plt_offset = h->plt.offset; |
3212 | 0 | } |
3213 | 0 | } |
3214 | 0 | else |
3215 | 0 | { |
3216 | | /* Use the GOT PLT. */ |
3217 | 0 | resolved_plt = htab->plt_got; |
3218 | 0 | plt_offset = eh->plt_got.offset; |
3219 | 0 | } |
3220 | |
|
3221 | 0 | relocation = (resolved_plt->output_section->vma |
3222 | 0 | + resolved_plt->output_offset |
3223 | 0 | + plt_offset); |
3224 | 0 | unresolved_reloc = false; |
3225 | 0 | break; |
3226 | | |
3227 | 0 | case R_X86_64_SIZE32: |
3228 | 0 | case R_X86_64_SIZE64: |
3229 | | /* Set to symbol size. */ |
3230 | 0 | relocation = st_size; |
3231 | 0 | goto direct; |
3232 | | |
3233 | 0 | case R_X86_64_PC8: |
3234 | 0 | case R_X86_64_PC16: |
3235 | 0 | case R_X86_64_PC32: |
3236 | | /* Don't complain about -fPIC if the symbol is undefined when |
3237 | | building executable unless it is unresolved weak symbol, |
3238 | | references a dynamic definition in PIE or -z nocopyreloc |
3239 | | is used. */ |
3240 | 0 | no_copyreloc_p |
3241 | 0 | = (info->nocopyreloc |
3242 | 0 | || (h != NULL |
3243 | 0 | && !h->root.linker_def |
3244 | 0 | && !h->root.ldscript_def |
3245 | 0 | && eh->def_protected)); |
3246 | |
|
3247 | 0 | if ((input_section->flags & SEC_ALLOC) != 0 |
3248 | 0 | && (input_section->flags & SEC_READONLY) != 0 |
3249 | 0 | && h != NULL |
3250 | 0 | && ((bfd_link_executable (info) |
3251 | 0 | && ((h->root.type == bfd_link_hash_undefweak |
3252 | 0 | && (eh == NULL |
3253 | 0 | || !UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, |
3254 | 0 | eh))) |
3255 | 0 | || (bfd_link_pie (info) |
3256 | 0 | && !SYMBOL_DEFINED_NON_SHARED_P (h) |
3257 | 0 | && h->def_dynamic) |
3258 | 0 | || (no_copyreloc_p |
3259 | 0 | && h->def_dynamic |
3260 | 0 | && !(h->root.u.def.section->flags & SEC_CODE)))) |
3261 | 0 | || (bfd_link_pie (info) |
3262 | 0 | && h->root.type == bfd_link_hash_undefweak) |
3263 | 0 | || bfd_link_dll (info))) |
3264 | 0 | { |
3265 | 0 | bool fail = false; |
3266 | 0 | if (SYMBOL_REFERENCES_LOCAL_P (info, h)) |
3267 | 0 | { |
3268 | | /* Symbol is referenced locally. Make sure it is |
3269 | | defined locally. */ |
3270 | 0 | fail = !SYMBOL_DEFINED_NON_SHARED_P (h); |
3271 | 0 | } |
3272 | 0 | else if (bfd_link_pie (info)) |
3273 | 0 | { |
3274 | | /* We can only use PC-relative relocations in PIE |
3275 | | from non-code sections. */ |
3276 | 0 | if (h->root.type == bfd_link_hash_undefweak |
3277 | 0 | || (h->type == STT_FUNC |
3278 | 0 | && (sec->flags & SEC_CODE) != 0)) |
3279 | 0 | fail = true; |
3280 | 0 | } |
3281 | 0 | else if (no_copyreloc_p || bfd_link_dll (info)) |
3282 | 0 | { |
3283 | | /* Symbol doesn't need copy reloc and isn't |
3284 | | referenced locally. Don't allow PC-relative |
3285 | | relocations against default and protected |
3286 | | symbols since address of protected function |
3287 | | and location of protected data may not be in |
3288 | | the shared object. */ |
3289 | 0 | fail = (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
3290 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_PROTECTED); |
3291 | 0 | } |
3292 | |
|
3293 | 0 | if (fail) |
3294 | 0 | return elf_x86_64_need_pic (info, input_bfd, input_section, |
3295 | 0 | h, NULL, NULL, howto); |
3296 | 0 | } |
3297 | | /* Since x86-64 has PC-relative PLT, we can use PLT in PIE |
3298 | | as function address. */ |
3299 | 0 | else if (h != NULL |
3300 | 0 | && (input_section->flags & SEC_CODE) == 0 |
3301 | 0 | && bfd_link_pie (info) |
3302 | 0 | && h->type == STT_FUNC |
3303 | 0 | && !h->def_regular |
3304 | 0 | && h->def_dynamic) |
3305 | 0 | goto use_plt; |
3306 | | /* Fall through. */ |
3307 | | |
3308 | 0 | case R_X86_64_8: |
3309 | 0 | case R_X86_64_16: |
3310 | 0 | case R_X86_64_32: |
3311 | 0 | case R_X86_64_PC64: |
3312 | 0 | case R_X86_64_64: |
3313 | | /* FIXME: The ABI says the linker should make sure the value is |
3314 | | the same when it's zeroextended to 64 bit. */ |
3315 | |
|
3316 | 0 | direct: |
3317 | 0 | if ((input_section->flags & SEC_ALLOC) == 0) |
3318 | 0 | break; |
3319 | | |
3320 | 0 | need_copy_reloc_in_pie = (bfd_link_pie (info) |
3321 | 0 | && h != NULL |
3322 | 0 | && (h->needs_copy |
3323 | 0 | || eh->needs_copy |
3324 | 0 | || (h->root.type |
3325 | 0 | == bfd_link_hash_undefined)) |
3326 | 0 | && (X86_PCREL_TYPE_P (true, r_type) |
3327 | 0 | || X86_SIZE_TYPE_P (true, |
3328 | 0 | r_type))); |
3329 | |
|
3330 | 0 | if (GENERATE_DYNAMIC_RELOCATION_P (true, info, eh, r_type, sec, |
3331 | 0 | need_copy_reloc_in_pie, |
3332 | 0 | resolved_to_zero, false)) |
3333 | 0 | { |
3334 | 0 | Elf_Internal_Rela outrel; |
3335 | 0 | bool skip, relocate; |
3336 | 0 | bool generate_dynamic_reloc = true; |
3337 | 0 | asection *sreloc; |
3338 | 0 | const char *relative_reloc_name = NULL; |
3339 | | |
3340 | | /* When generating a shared object, these relocations |
3341 | | are copied into the output file to be resolved at run |
3342 | | time. */ |
3343 | 0 | skip = false; |
3344 | 0 | relocate = false; |
3345 | |
|
3346 | 0 | outrel.r_offset = |
3347 | 0 | _bfd_elf_section_offset (output_bfd, info, input_section, |
3348 | 0 | rel->r_offset); |
3349 | 0 | if (outrel.r_offset == (bfd_vma) -1) |
3350 | 0 | skip = true; |
3351 | 0 | else if (outrel.r_offset == (bfd_vma) -2) |
3352 | 0 | skip = true, relocate = true; |
3353 | |
|
3354 | 0 | outrel.r_offset += (input_section->output_section->vma |
3355 | 0 | + input_section->output_offset); |
3356 | |
|
3357 | 0 | if (skip) |
3358 | 0 | memset (&outrel, 0, sizeof outrel); |
3359 | | |
3360 | 0 | else if (COPY_INPUT_RELOC_P (true, info, h, r_type)) |
3361 | 0 | { |
3362 | 0 | outrel.r_info = htab->r_info (h->dynindx, r_type); |
3363 | 0 | outrel.r_addend = rel->r_addend; |
3364 | 0 | } |
3365 | 0 | else |
3366 | 0 | { |
3367 | | /* This symbol is local, or marked to become local. |
3368 | | When relocation overflow check is disabled, we |
3369 | | convert R_X86_64_32 to dynamic R_X86_64_RELATIVE. */ |
3370 | 0 | if (r_type == htab->pointer_r_type |
3371 | 0 | || (r_type == R_X86_64_32 |
3372 | 0 | && htab->params->no_reloc_overflow_check)) |
3373 | 0 | { |
3374 | 0 | relocate = true; |
3375 | | /* NB: Don't generate relative relocation here if |
3376 | | it has been generated by DT_RELR. */ |
3377 | 0 | if (info->enable_dt_relr) |
3378 | 0 | generate_dynamic_reloc = false; |
3379 | 0 | else |
3380 | 0 | { |
3381 | 0 | outrel.r_info = |
3382 | 0 | htab->r_info (0, R_X86_64_RELATIVE); |
3383 | 0 | outrel.r_addend = relocation + rel->r_addend; |
3384 | 0 | relative_reloc_name = "R_X86_64_RELATIVE"; |
3385 | 0 | } |
3386 | 0 | } |
3387 | 0 | else if (r_type == R_X86_64_64 |
3388 | 0 | && !ABI_64_P (output_bfd)) |
3389 | 0 | { |
3390 | 0 | relocate = true; |
3391 | 0 | outrel.r_info = htab->r_info (0, |
3392 | 0 | R_X86_64_RELATIVE64); |
3393 | 0 | outrel.r_addend = relocation + rel->r_addend; |
3394 | 0 | relative_reloc_name = "R_X86_64_RELATIVE64"; |
3395 | | /* Check addend overflow. */ |
3396 | 0 | if ((outrel.r_addend & 0x80000000) |
3397 | 0 | != (rel->r_addend & 0x80000000)) |
3398 | 0 | { |
3399 | 0 | const char *name; |
3400 | 0 | int addend = rel->r_addend; |
3401 | 0 | if (h && h->root.root.string) |
3402 | 0 | name = h->root.root.string; |
3403 | 0 | else |
3404 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, |
3405 | 0 | sym, NULL); |
3406 | 0 | _bfd_error_handler |
3407 | | /* xgettext:c-format */ |
3408 | 0 | (_("%pB: addend %s%#x in relocation %s against " |
3409 | 0 | "symbol `%s' at %#" PRIx64 |
3410 | 0 | " in section `%pA' is out of range"), |
3411 | 0 | input_bfd, addend < 0 ? "-" : "", addend, |
3412 | 0 | howto->name, name, (uint64_t) rel->r_offset, |
3413 | 0 | input_section); |
3414 | 0 | bfd_set_error (bfd_error_bad_value); |
3415 | 0 | return false; |
3416 | 0 | } |
3417 | 0 | } |
3418 | 0 | else |
3419 | 0 | { |
3420 | 0 | long sindx; |
3421 | |
|
3422 | 0 | if (bfd_is_abs_section (sec)) |
3423 | 0 | sindx = 0; |
3424 | 0 | else if (sec == NULL || sec->owner == NULL) |
3425 | 0 | { |
3426 | 0 | bfd_set_error (bfd_error_bad_value); |
3427 | 0 | return false; |
3428 | 0 | } |
3429 | 0 | else |
3430 | 0 | { |
3431 | 0 | asection *osec; |
3432 | | |
3433 | | /* We are turning this relocation into one |
3434 | | against a section symbol. It would be |
3435 | | proper to subtract the symbol's value, |
3436 | | osec->vma, from the emitted reloc addend, |
3437 | | but ld.so expects buggy relocs. */ |
3438 | 0 | osec = sec->output_section; |
3439 | 0 | sindx = elf_section_data (osec)->dynindx; |
3440 | 0 | if (sindx == 0) |
3441 | 0 | { |
3442 | 0 | asection *oi = htab->elf.text_index_section; |
3443 | 0 | sindx = elf_section_data (oi)->dynindx; |
3444 | 0 | } |
3445 | 0 | BFD_ASSERT (sindx != 0); |
3446 | 0 | } |
3447 | | |
3448 | 0 | outrel.r_info = htab->r_info (sindx, r_type); |
3449 | 0 | outrel.r_addend = relocation + rel->r_addend; |
3450 | 0 | } |
3451 | 0 | } |
3452 | | |
3453 | 0 | if (generate_dynamic_reloc) |
3454 | 0 | { |
3455 | 0 | sreloc = elf_section_data (input_section)->sreloc; |
3456 | |
|
3457 | 0 | if (sreloc == NULL || sreloc->contents == NULL) |
3458 | 0 | { |
3459 | 0 | r = bfd_reloc_notsupported; |
3460 | 0 | goto check_relocation_error; |
3461 | 0 | } |
3462 | | |
3463 | 0 | if (relative_reloc_name |
3464 | 0 | && htab->params->report_relative_reloc) |
3465 | 0 | _bfd_x86_elf_link_report_relative_reloc |
3466 | 0 | (info, input_section, h, sym, |
3467 | 0 | relative_reloc_name, &outrel); |
3468 | |
|
3469 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
3470 | 0 | } |
3471 | | |
3472 | | /* If this reloc is against an external symbol, we do |
3473 | | not want to fiddle with the addend. Otherwise, we |
3474 | | need to include the symbol value so that it becomes |
3475 | | an addend for the dynamic reloc. */ |
3476 | 0 | if (! relocate) |
3477 | 0 | continue; |
3478 | 0 | } |
3479 | | |
3480 | 0 | break; |
3481 | | |
3482 | 0 | case R_X86_64_TLSGD: |
3483 | 0 | case R_X86_64_GOTPC32_TLSDESC: |
3484 | 0 | case R_X86_64_TLSDESC_CALL: |
3485 | 0 | case R_X86_64_GOTTPOFF: |
3486 | 0 | tls_type = GOT_UNKNOWN; |
3487 | 0 | if (h == NULL && local_got_offsets) |
3488 | 0 | tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx]; |
3489 | 0 | else if (h != NULL) |
3490 | 0 | tls_type = elf_x86_hash_entry (h)->tls_type; |
3491 | |
|
3492 | 0 | r_type_tls = r_type; |
3493 | 0 | if (! elf_x86_64_tls_transition (info, input_bfd, |
3494 | 0 | input_section, contents, |
3495 | 0 | symtab_hdr, sym_hashes, |
3496 | 0 | &r_type_tls, tls_type, rel, |
3497 | 0 | relend, h, r_symndx, true)) |
3498 | 0 | return false; |
3499 | | |
3500 | 0 | if (r_type_tls == R_X86_64_TPOFF32) |
3501 | 0 | { |
3502 | 0 | bfd_vma roff = rel->r_offset; |
3503 | |
|
3504 | 0 | if (roff >= input_section->size) |
3505 | 0 | goto corrupt_input; |
3506 | | |
3507 | 0 | BFD_ASSERT (! unresolved_reloc); |
3508 | |
|
3509 | 0 | if (r_type == R_X86_64_TLSGD) |
3510 | 0 | { |
3511 | | /* GD->LE transition. For 64bit, change |
3512 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
3513 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
3514 | | or |
3515 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
3516 | | .byte 0x66; rex64 |
3517 | | call *__tls_get_addr@GOTPCREL(%rip) |
3518 | | which may be converted to |
3519 | | addr32 call __tls_get_addr |
3520 | | into: |
3521 | | movq %fs:0, %rax |
3522 | | leaq foo@tpoff(%rax), %rax |
3523 | | For 32bit, change |
3524 | | leaq foo@tlsgd(%rip), %rdi |
3525 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
3526 | | or |
3527 | | leaq foo@tlsgd(%rip), %rdi |
3528 | | .byte 0x66; rex64 |
3529 | | call *__tls_get_addr@GOTPCREL(%rip) |
3530 | | which may be converted to |
3531 | | addr32 call __tls_get_addr |
3532 | | into: |
3533 | | movl %fs:0, %eax |
3534 | | leaq foo@tpoff(%rax), %rax |
3535 | | For largepic, change: |
3536 | | leaq foo@tlsgd(%rip), %rdi |
3537 | | movabsq $__tls_get_addr@pltoff, %rax |
3538 | | addq %r15, %rax |
3539 | | call *%rax |
3540 | | into: |
3541 | | movq %fs:0, %rax |
3542 | | leaq foo@tpoff(%rax), %rax |
3543 | | nopw 0x0(%rax,%rax,1) */ |
3544 | 0 | int largepic = 0; |
3545 | 0 | if (ABI_64_P (output_bfd)) |
3546 | 0 | { |
3547 | 0 | if (roff + 5 >= input_section->size) |
3548 | 0 | goto corrupt_input; |
3549 | 0 | if (contents[roff + 5] == 0xb8) |
3550 | 0 | { |
3551 | 0 | if (roff < 3 |
3552 | 0 | || (roff - 3 + 22) > input_section->size) |
3553 | 0 | { |
3554 | 0 | corrupt_input: |
3555 | 0 | info->callbacks->einfo |
3556 | 0 | (_("%F%P: corrupt input: %pB\n"), |
3557 | 0 | input_bfd); |
3558 | 0 | return false; |
3559 | 0 | } |
3560 | 0 | memcpy (contents + roff - 3, |
3561 | 0 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80" |
3562 | 0 | "\0\0\0\0\x66\x0f\x1f\x44\0", 22); |
3563 | 0 | largepic = 1; |
3564 | 0 | } |
3565 | 0 | else |
3566 | 0 | { |
3567 | 0 | if (roff < 4 |
3568 | 0 | || (roff - 4 + 16) > input_section->size) |
3569 | 0 | goto corrupt_input; |
3570 | 0 | memcpy (contents + roff - 4, |
3571 | 0 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0", |
3572 | 0 | 16); |
3573 | 0 | } |
3574 | 0 | } |
3575 | 0 | else |
3576 | 0 | { |
3577 | 0 | if (roff < 3 |
3578 | 0 | || (roff - 3 + 15) > input_section->size) |
3579 | 0 | goto corrupt_input; |
3580 | 0 | memcpy (contents + roff - 3, |
3581 | 0 | "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0", |
3582 | 0 | 15); |
3583 | 0 | } |
3584 | | |
3585 | 0 | if (roff + 8 + largepic >= input_section->size) |
3586 | 0 | goto corrupt_input; |
3587 | | |
3588 | 0 | bfd_put_32 (output_bfd, |
3589 | 0 | elf_x86_64_tpoff (info, relocation), |
3590 | 0 | contents + roff + 8 + largepic); |
3591 | | /* Skip R_X86_64_PC32, R_X86_64_PLT32, |
3592 | | R_X86_64_GOTPCRELX and R_X86_64_PLTOFF64. */ |
3593 | 0 | rel++; |
3594 | 0 | wrel++; |
3595 | 0 | continue; |
3596 | 0 | } |
3597 | 0 | else if (r_type == R_X86_64_GOTPC32_TLSDESC) |
3598 | 0 | { |
3599 | | /* GDesc -> LE transition. |
3600 | | It's originally something like: |
3601 | | leaq x@tlsdesc(%rip), %rax <--- LP64 mode. |
3602 | | rex leal x@tlsdesc(%rip), %eax <--- X32 mode. |
3603 | | |
3604 | | Change it to: |
3605 | | movq $x@tpoff, %rax <--- LP64 mode. |
3606 | | rex movl $x@tpoff, %eax <--- X32 mode. |
3607 | | */ |
3608 | |
|
3609 | 0 | unsigned int val, type; |
3610 | |
|
3611 | 0 | if (roff < 3) |
3612 | 0 | goto corrupt_input; |
3613 | 0 | type = bfd_get_8 (input_bfd, contents + roff - 3); |
3614 | 0 | val = bfd_get_8 (input_bfd, contents + roff - 1); |
3615 | 0 | bfd_put_8 (output_bfd, |
3616 | 0 | (type & 0x48) | ((type >> 2) & 1), |
3617 | 0 | contents + roff - 3); |
3618 | 0 | bfd_put_8 (output_bfd, 0xc7, contents + roff - 2); |
3619 | 0 | bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7), |
3620 | 0 | contents + roff - 1); |
3621 | 0 | bfd_put_32 (output_bfd, |
3622 | 0 | elf_x86_64_tpoff (info, relocation), |
3623 | 0 | contents + roff); |
3624 | 0 | continue; |
3625 | 0 | } |
3626 | 0 | else if (r_type == R_X86_64_TLSDESC_CALL) |
3627 | 0 | { |
3628 | | /* GDesc -> LE transition. |
3629 | | It's originally: |
3630 | | call *(%rax) <--- LP64 mode. |
3631 | | call *(%eax) <--- X32 mode. |
3632 | | Turn it into: |
3633 | | xchg %ax,%ax <-- LP64 mode. |
3634 | | nopl (%rax) <-- X32 mode. |
3635 | | */ |
3636 | 0 | unsigned int prefix = 0; |
3637 | 0 | if (!ABI_64_P (input_bfd)) |
3638 | 0 | { |
3639 | | /* Check for call *x@tlsdesc(%eax). */ |
3640 | 0 | if (contents[roff] == 0x67) |
3641 | 0 | prefix = 1; |
3642 | 0 | } |
3643 | 0 | if (prefix) |
3644 | 0 | { |
3645 | 0 | if (roff + 2 >= input_section->size) |
3646 | 0 | goto corrupt_input; |
3647 | | |
3648 | 0 | bfd_put_8 (output_bfd, 0x0f, contents + roff); |
3649 | 0 | bfd_put_8 (output_bfd, 0x1f, contents + roff + 1); |
3650 | 0 | bfd_put_8 (output_bfd, 0x00, contents + roff + 2); |
3651 | 0 | } |
3652 | 0 | else |
3653 | 0 | { |
3654 | 0 | if (roff + 1 >= input_section->size) |
3655 | 0 | goto corrupt_input; |
3656 | | |
3657 | 0 | bfd_put_8 (output_bfd, 0x66, contents + roff); |
3658 | 0 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); |
3659 | 0 | } |
3660 | 0 | continue; |
3661 | 0 | } |
3662 | 0 | else if (r_type == R_X86_64_GOTTPOFF) |
3663 | 0 | { |
3664 | | /* IE->LE transition: |
3665 | | For 64bit, originally it can be one of: |
3666 | | movq foo@gottpoff(%rip), %reg |
3667 | | addq foo@gottpoff(%rip), %reg |
3668 | | We change it into: |
3669 | | movq $foo, %reg |
3670 | | leaq foo(%reg), %reg |
3671 | | addq $foo, %reg. |
3672 | | For 32bit, originally it can be one of: |
3673 | | movq foo@gottpoff(%rip), %reg |
3674 | | addl foo@gottpoff(%rip), %reg |
3675 | | We change it into: |
3676 | | movq $foo, %reg |
3677 | | leal foo(%reg), %reg |
3678 | | addl $foo, %reg. */ |
3679 | |
|
3680 | 0 | unsigned int val, type, reg; |
3681 | |
|
3682 | 0 | if (roff >= 3) |
3683 | 0 | val = bfd_get_8 (input_bfd, contents + roff - 3); |
3684 | 0 | else |
3685 | 0 | { |
3686 | 0 | if (roff < 2) |
3687 | 0 | goto corrupt_input; |
3688 | 0 | val = 0; |
3689 | 0 | } |
3690 | 0 | type = bfd_get_8 (input_bfd, contents + roff - 2); |
3691 | 0 | reg = bfd_get_8 (input_bfd, contents + roff - 1); |
3692 | 0 | reg >>= 3; |
3693 | 0 | if (type == 0x8b) |
3694 | 0 | { |
3695 | | /* movq */ |
3696 | 0 | if (val == 0x4c) |
3697 | 0 | { |
3698 | 0 | if (roff < 3) |
3699 | 0 | goto corrupt_input; |
3700 | 0 | bfd_put_8 (output_bfd, 0x49, |
3701 | 0 | contents + roff - 3); |
3702 | 0 | } |
3703 | 0 | else if (!ABI_64_P (output_bfd) && val == 0x44) |
3704 | 0 | { |
3705 | 0 | if (roff < 3) |
3706 | 0 | goto corrupt_input; |
3707 | 0 | bfd_put_8 (output_bfd, 0x41, |
3708 | 0 | contents + roff - 3); |
3709 | 0 | } |
3710 | 0 | bfd_put_8 (output_bfd, 0xc7, |
3711 | 0 | contents + roff - 2); |
3712 | 0 | bfd_put_8 (output_bfd, 0xc0 | reg, |
3713 | 0 | contents + roff - 1); |
3714 | 0 | } |
3715 | 0 | else if (reg == 4) |
3716 | 0 | { |
3717 | | /* addq/addl -> addq/addl - addressing with %rsp/%r12 |
3718 | | is special */ |
3719 | 0 | if (val == 0x4c) |
3720 | 0 | { |
3721 | 0 | if (roff < 3) |
3722 | 0 | goto corrupt_input; |
3723 | 0 | bfd_put_8 (output_bfd, 0x49, |
3724 | 0 | contents + roff - 3); |
3725 | 0 | } |
3726 | 0 | else if (!ABI_64_P (output_bfd) && val == 0x44) |
3727 | 0 | { |
3728 | 0 | if (roff < 3) |
3729 | 0 | goto corrupt_input; |
3730 | 0 | bfd_put_8 (output_bfd, 0x41, |
3731 | 0 | contents + roff - 3); |
3732 | 0 | } |
3733 | 0 | bfd_put_8 (output_bfd, 0x81, |
3734 | 0 | contents + roff - 2); |
3735 | 0 | bfd_put_8 (output_bfd, 0xc0 | reg, |
3736 | 0 | contents + roff - 1); |
3737 | 0 | } |
3738 | 0 | else |
3739 | 0 | { |
3740 | | /* addq/addl -> leaq/leal */ |
3741 | 0 | if (val == 0x4c) |
3742 | 0 | { |
3743 | 0 | if (roff < 3) |
3744 | 0 | goto corrupt_input; |
3745 | 0 | bfd_put_8 (output_bfd, 0x4d, |
3746 | 0 | contents + roff - 3); |
3747 | 0 | } |
3748 | 0 | else if (!ABI_64_P (output_bfd) && val == 0x44) |
3749 | 0 | { |
3750 | 0 | if (roff < 3) |
3751 | 0 | goto corrupt_input; |
3752 | 0 | bfd_put_8 (output_bfd, 0x45, |
3753 | 0 | contents + roff - 3); |
3754 | 0 | } |
3755 | 0 | bfd_put_8 (output_bfd, 0x8d, |
3756 | 0 | contents + roff - 2); |
3757 | 0 | bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3), |
3758 | 0 | contents + roff - 1); |
3759 | 0 | } |
3760 | 0 | bfd_put_32 (output_bfd, |
3761 | 0 | elf_x86_64_tpoff (info, relocation), |
3762 | 0 | contents + roff); |
3763 | 0 | continue; |
3764 | 0 | } |
3765 | 0 | else |
3766 | 0 | BFD_ASSERT (false); |
3767 | 0 | } |
3768 | | |
3769 | 0 | if (htab->elf.sgot == NULL) |
3770 | 0 | abort (); |
3771 | | |
3772 | 0 | if (h != NULL) |
3773 | 0 | { |
3774 | 0 | off = h->got.offset; |
3775 | 0 | offplt = elf_x86_hash_entry (h)->tlsdesc_got; |
3776 | 0 | } |
3777 | 0 | else |
3778 | 0 | { |
3779 | 0 | if (local_got_offsets == NULL) |
3780 | 0 | abort (); |
3781 | | |
3782 | 0 | off = local_got_offsets[r_symndx]; |
3783 | 0 | offplt = local_tlsdesc_gotents[r_symndx]; |
3784 | 0 | } |
3785 | | |
3786 | 0 | if ((off & 1) != 0) |
3787 | 0 | off &= ~1; |
3788 | 0 | else |
3789 | 0 | { |
3790 | 0 | Elf_Internal_Rela outrel; |
3791 | 0 | int dr_type, indx; |
3792 | 0 | asection *sreloc; |
3793 | |
|
3794 | 0 | if (htab->elf.srelgot == NULL) |
3795 | 0 | abort (); |
3796 | | |
3797 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
3798 | |
|
3799 | 0 | if (GOT_TLS_GDESC_P (tls_type)) |
3800 | 0 | { |
3801 | 0 | outrel.r_info = htab->r_info (indx, R_X86_64_TLSDESC); |
3802 | 0 | BFD_ASSERT (htab->sgotplt_jump_table_size + offplt |
3803 | 0 | + 2 * GOT_ENTRY_SIZE <= htab->elf.sgotplt->size); |
3804 | 0 | outrel.r_offset = (htab->elf.sgotplt->output_section->vma |
3805 | 0 | + htab->elf.sgotplt->output_offset |
3806 | 0 | + offplt |
3807 | 0 | + htab->sgotplt_jump_table_size); |
3808 | 0 | sreloc = htab->elf.srelplt; |
3809 | 0 | if (indx == 0) |
3810 | 0 | outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info); |
3811 | 0 | else |
3812 | 0 | outrel.r_addend = 0; |
3813 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
3814 | 0 | } |
3815 | |
|
3816 | 0 | sreloc = htab->elf.srelgot; |
3817 | |
|
3818 | 0 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
3819 | 0 | + htab->elf.sgot->output_offset + off); |
3820 | |
|
3821 | 0 | if (GOT_TLS_GD_P (tls_type)) |
3822 | 0 | dr_type = R_X86_64_DTPMOD64; |
3823 | 0 | else if (GOT_TLS_GDESC_P (tls_type)) |
3824 | 0 | goto dr_done; |
3825 | 0 | else |
3826 | 0 | dr_type = R_X86_64_TPOFF64; |
3827 | | |
3828 | 0 | bfd_put_64 (output_bfd, 0, htab->elf.sgot->contents + off); |
3829 | 0 | outrel.r_addend = 0; |
3830 | 0 | if ((dr_type == R_X86_64_TPOFF64 |
3831 | 0 | || dr_type == R_X86_64_TLSDESC) && indx == 0) |
3832 | 0 | outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info); |
3833 | 0 | outrel.r_info = htab->r_info (indx, dr_type); |
3834 | |
|
3835 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
3836 | |
|
3837 | 0 | if (GOT_TLS_GD_P (tls_type)) |
3838 | 0 | { |
3839 | 0 | if (indx == 0) |
3840 | 0 | { |
3841 | 0 | BFD_ASSERT (! unresolved_reloc); |
3842 | 0 | bfd_put_64 (output_bfd, |
3843 | 0 | relocation - _bfd_x86_elf_dtpoff_base (info), |
3844 | 0 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
3845 | 0 | } |
3846 | 0 | else |
3847 | 0 | { |
3848 | 0 | bfd_put_64 (output_bfd, 0, |
3849 | 0 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
3850 | 0 | outrel.r_info = htab->r_info (indx, |
3851 | 0 | R_X86_64_DTPOFF64); |
3852 | 0 | outrel.r_offset += GOT_ENTRY_SIZE; |
3853 | 0 | elf_append_rela (output_bfd, sreloc, |
3854 | 0 | &outrel); |
3855 | 0 | } |
3856 | 0 | } |
3857 | |
|
3858 | 0 | dr_done: |
3859 | 0 | if (h != NULL) |
3860 | 0 | h->got.offset |= 1; |
3861 | 0 | else |
3862 | 0 | local_got_offsets[r_symndx] |= 1; |
3863 | 0 | } |
3864 | | |
3865 | 0 | if (off >= (bfd_vma) -2 |
3866 | 0 | && ! GOT_TLS_GDESC_P (tls_type)) |
3867 | 0 | abort (); |
3868 | 0 | if (r_type_tls == r_type) |
3869 | 0 | { |
3870 | 0 | if (r_type == R_X86_64_GOTPC32_TLSDESC |
3871 | 0 | || r_type == R_X86_64_TLSDESC_CALL) |
3872 | 0 | relocation = htab->elf.sgotplt->output_section->vma |
3873 | 0 | + htab->elf.sgotplt->output_offset |
3874 | 0 | + offplt + htab->sgotplt_jump_table_size; |
3875 | 0 | else |
3876 | 0 | relocation = htab->elf.sgot->output_section->vma |
3877 | 0 | + htab->elf.sgot->output_offset + off; |
3878 | 0 | unresolved_reloc = false; |
3879 | 0 | } |
3880 | 0 | else |
3881 | 0 | { |
3882 | 0 | bfd_vma roff = rel->r_offset; |
3883 | |
|
3884 | 0 | if (r_type == R_X86_64_TLSGD) |
3885 | 0 | { |
3886 | | /* GD->IE transition. For 64bit, change |
3887 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
3888 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
3889 | | or |
3890 | | .byte 0x66; leaq foo@tlsgd(%rip), %rdi |
3891 | | .byte 0x66; rex64 |
3892 | | call *__tls_get_addr@GOTPCREL(%rip |
3893 | | which may be converted to |
3894 | | addr32 call __tls_get_addr |
3895 | | into: |
3896 | | movq %fs:0, %rax |
3897 | | addq foo@gottpoff(%rip), %rax |
3898 | | For 32bit, change |
3899 | | leaq foo@tlsgd(%rip), %rdi |
3900 | | .word 0x6666; rex64; call __tls_get_addr@PLT |
3901 | | or |
3902 | | leaq foo@tlsgd(%rip), %rdi |
3903 | | .byte 0x66; rex64; |
3904 | | call *__tls_get_addr@GOTPCREL(%rip) |
3905 | | which may be converted to |
3906 | | addr32 call __tls_get_addr |
3907 | | into: |
3908 | | movl %fs:0, %eax |
3909 | | addq foo@gottpoff(%rip), %rax |
3910 | | For largepic, change: |
3911 | | leaq foo@tlsgd(%rip), %rdi |
3912 | | movabsq $__tls_get_addr@pltoff, %rax |
3913 | | addq %r15, %rax |
3914 | | call *%rax |
3915 | | into: |
3916 | | movq %fs:0, %rax |
3917 | | addq foo@gottpoff(%rax), %rax |
3918 | | nopw 0x0(%rax,%rax,1) */ |
3919 | 0 | int largepic = 0; |
3920 | 0 | if (ABI_64_P (output_bfd)) |
3921 | 0 | { |
3922 | 0 | if (contents[roff + 5] == 0xb8) |
3923 | 0 | { |
3924 | 0 | if (roff < 3 |
3925 | 0 | || (roff - 3 + 22) > input_section->size) |
3926 | 0 | goto corrupt_input; |
3927 | 0 | memcpy (contents + roff - 3, |
3928 | 0 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05" |
3929 | 0 | "\0\0\0\0\x66\x0f\x1f\x44\0", 22); |
3930 | 0 | largepic = 1; |
3931 | 0 | } |
3932 | 0 | else |
3933 | 0 | { |
3934 | 0 | if (roff < 4 |
3935 | 0 | || (roff - 4 + 16) > input_section->size) |
3936 | 0 | goto corrupt_input; |
3937 | 0 | memcpy (contents + roff - 4, |
3938 | 0 | "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0", |
3939 | 0 | 16); |
3940 | 0 | } |
3941 | 0 | } |
3942 | 0 | else |
3943 | 0 | { |
3944 | 0 | if (roff < 3 |
3945 | 0 | || (roff - 3 + 15) > input_section->size) |
3946 | 0 | goto corrupt_input; |
3947 | 0 | memcpy (contents + roff - 3, |
3948 | 0 | "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0", |
3949 | 0 | 15); |
3950 | 0 | } |
3951 | | |
3952 | 0 | relocation = (htab->elf.sgot->output_section->vma |
3953 | 0 | + htab->elf.sgot->output_offset + off |
3954 | 0 | - roff |
3955 | 0 | - largepic |
3956 | 0 | - input_section->output_section->vma |
3957 | 0 | - input_section->output_offset |
3958 | 0 | - 12); |
3959 | 0 | bfd_put_32 (output_bfd, relocation, |
3960 | 0 | contents + roff + 8 + largepic); |
3961 | | /* Skip R_X86_64_PLT32/R_X86_64_PLTOFF64. */ |
3962 | 0 | rel++; |
3963 | 0 | wrel++; |
3964 | 0 | continue; |
3965 | 0 | } |
3966 | 0 | else if (r_type == R_X86_64_GOTPC32_TLSDESC) |
3967 | 0 | { |
3968 | | /* GDesc -> IE transition. |
3969 | | It's originally something like: |
3970 | | leaq x@tlsdesc(%rip), %rax <--- LP64 mode. |
3971 | | rex leal x@tlsdesc(%rip), %eax <--- X32 mode. |
3972 | | |
3973 | | Change it to: |
3974 | | # before xchg %ax,%ax in LP64 mode. |
3975 | | movq x@gottpoff(%rip), %rax |
3976 | | # before nopl (%rax) in X32 mode. |
3977 | | rex movl x@gottpoff(%rip), %eax |
3978 | | */ |
3979 | | |
3980 | | /* Now modify the instruction as appropriate. To |
3981 | | turn a lea into a mov in the form we use it, it |
3982 | | suffices to change the second byte from 0x8d to |
3983 | | 0x8b. */ |
3984 | 0 | if (roff < 2) |
3985 | 0 | goto corrupt_input; |
3986 | 0 | bfd_put_8 (output_bfd, 0x8b, contents + roff - 2); |
3987 | |
|
3988 | 0 | bfd_put_32 (output_bfd, |
3989 | 0 | htab->elf.sgot->output_section->vma |
3990 | 0 | + htab->elf.sgot->output_offset + off |
3991 | 0 | - rel->r_offset |
3992 | 0 | - input_section->output_section->vma |
3993 | 0 | - input_section->output_offset |
3994 | 0 | - 4, |
3995 | 0 | contents + roff); |
3996 | 0 | continue; |
3997 | 0 | } |
3998 | 0 | else if (r_type == R_X86_64_TLSDESC_CALL) |
3999 | 0 | { |
4000 | | /* GDesc -> IE transition. |
4001 | | It's originally: |
4002 | | call *(%rax) <--- LP64 mode. |
4003 | | call *(%eax) <--- X32 mode. |
4004 | | |
4005 | | Change it to: |
4006 | | xchg %ax, %ax <-- LP64 mode. |
4007 | | nopl (%rax) <-- X32 mode. |
4008 | | */ |
4009 | |
|
4010 | 0 | unsigned int prefix = 0; |
4011 | 0 | if (!ABI_64_P (input_bfd)) |
4012 | 0 | { |
4013 | | /* Check for call *x@tlsdesc(%eax). */ |
4014 | 0 | if (contents[roff] == 0x67) |
4015 | 0 | prefix = 1; |
4016 | 0 | } |
4017 | 0 | if (prefix) |
4018 | 0 | { |
4019 | 0 | bfd_put_8 (output_bfd, 0x0f, contents + roff); |
4020 | 0 | bfd_put_8 (output_bfd, 0x1f, contents + roff + 1); |
4021 | 0 | bfd_put_8 (output_bfd, 0x00, contents + roff + 2); |
4022 | 0 | } |
4023 | 0 | else |
4024 | 0 | { |
4025 | 0 | bfd_put_8 (output_bfd, 0x66, contents + roff); |
4026 | 0 | bfd_put_8 (output_bfd, 0x90, contents + roff + 1); |
4027 | 0 | } |
4028 | 0 | continue; |
4029 | 0 | } |
4030 | 0 | else |
4031 | 0 | BFD_ASSERT (false); |
4032 | 0 | } |
4033 | 0 | break; |
4034 | | |
4035 | 0 | case R_X86_64_TLSLD: |
4036 | 0 | if (! elf_x86_64_tls_transition (info, input_bfd, |
4037 | 0 | input_section, contents, |
4038 | 0 | symtab_hdr, sym_hashes, |
4039 | 0 | &r_type, GOT_UNKNOWN, rel, |
4040 | 0 | relend, h, r_symndx, true)) |
4041 | 0 | return false; |
4042 | | |
4043 | 0 | if (r_type != R_X86_64_TLSLD) |
4044 | 0 | { |
4045 | | /* LD->LE transition: |
4046 | | leaq foo@tlsld(%rip), %rdi |
4047 | | call __tls_get_addr@PLT |
4048 | | For 64bit, we change it into: |
4049 | | .word 0x6666; .byte 0x66; movq %fs:0, %rax |
4050 | | For 32bit, we change it into: |
4051 | | nopl 0x0(%rax); movl %fs:0, %eax |
4052 | | Or |
4053 | | leaq foo@tlsld(%rip), %rdi; |
4054 | | call *__tls_get_addr@GOTPCREL(%rip) |
4055 | | which may be converted to |
4056 | | addr32 call __tls_get_addr |
4057 | | For 64bit, we change it into: |
4058 | | .word 0x6666; .word 0x6666; movq %fs:0, %rax |
4059 | | For 32bit, we change it into: |
4060 | | nopw 0x0(%rax); movl %fs:0, %eax |
4061 | | For largepic, change: |
4062 | | leaq foo@tlsgd(%rip), %rdi |
4063 | | movabsq $__tls_get_addr@pltoff, %rax |
4064 | | addq %rbx, %rax |
4065 | | call *%rax |
4066 | | into |
4067 | | data16 data16 data16 nopw %cs:0x0(%rax,%rax,1) |
4068 | | movq %fs:0, %eax */ |
4069 | |
|
4070 | 0 | BFD_ASSERT (r_type == R_X86_64_TPOFF32); |
4071 | 0 | if (ABI_64_P (output_bfd)) |
4072 | 0 | { |
4073 | 0 | if ((rel->r_offset + 5) >= input_section->size) |
4074 | 0 | goto corrupt_input; |
4075 | 0 | if (contents[rel->r_offset + 5] == 0xb8) |
4076 | 0 | { |
4077 | 0 | if (rel->r_offset < 3 |
4078 | 0 | || (rel->r_offset - 3 + 22) > input_section->size) |
4079 | 0 | goto corrupt_input; |
4080 | 0 | memcpy (contents + rel->r_offset - 3, |
4081 | 0 | "\x66\x66\x66\x66\x2e\x0f\x1f\x84\0\0\0\0\0" |
4082 | 0 | "\x64\x48\x8b\x04\x25\0\0\0", 22); |
4083 | 0 | } |
4084 | 0 | else if (contents[rel->r_offset + 4] == 0xff |
4085 | 0 | || contents[rel->r_offset + 4] == 0x67) |
4086 | 0 | { |
4087 | 0 | if (rel->r_offset < 3 |
4088 | 0 | || (rel->r_offset - 3 + 13) > input_section->size) |
4089 | 0 | goto corrupt_input; |
4090 | 0 | memcpy (contents + rel->r_offset - 3, |
4091 | 0 | "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", |
4092 | 0 | 13); |
4093 | |
|
4094 | 0 | } |
4095 | 0 | else |
4096 | 0 | { |
4097 | 0 | if (rel->r_offset < 3 |
4098 | 0 | || (rel->r_offset - 3 + 12) > input_section->size) |
4099 | 0 | goto corrupt_input; |
4100 | 0 | memcpy (contents + rel->r_offset - 3, |
4101 | 0 | "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12); |
4102 | 0 | } |
4103 | 0 | } |
4104 | 0 | else |
4105 | 0 | { |
4106 | 0 | if ((rel->r_offset + 4) >= input_section->size) |
4107 | 0 | goto corrupt_input; |
4108 | 0 | if (contents[rel->r_offset + 4] == 0xff) |
4109 | 0 | { |
4110 | 0 | if (rel->r_offset < 3 |
4111 | 0 | || (rel->r_offset - 3 + 13) > input_section->size) |
4112 | 0 | goto corrupt_input; |
4113 | 0 | memcpy (contents + rel->r_offset - 3, |
4114 | 0 | "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", |
4115 | 0 | 13); |
4116 | 0 | } |
4117 | 0 | else |
4118 | 0 | { |
4119 | 0 | if (rel->r_offset < 3 |
4120 | 0 | || (rel->r_offset - 3 + 12) > input_section->size) |
4121 | 0 | goto corrupt_input; |
4122 | 0 | memcpy (contents + rel->r_offset - 3, |
4123 | 0 | "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0", 12); |
4124 | 0 | } |
4125 | 0 | } |
4126 | | /* Skip R_X86_64_PC32, R_X86_64_PLT32, R_X86_64_GOTPCRELX |
4127 | | and R_X86_64_PLTOFF64. */ |
4128 | 0 | rel++; |
4129 | 0 | wrel++; |
4130 | 0 | continue; |
4131 | 0 | } |
4132 | | |
4133 | 0 | if (htab->elf.sgot == NULL) |
4134 | 0 | abort (); |
4135 | | |
4136 | 0 | off = htab->tls_ld_or_ldm_got.offset; |
4137 | 0 | if (off & 1) |
4138 | 0 | off &= ~1; |
4139 | 0 | else |
4140 | 0 | { |
4141 | 0 | Elf_Internal_Rela outrel; |
4142 | |
|
4143 | 0 | if (htab->elf.srelgot == NULL) |
4144 | 0 | abort (); |
4145 | | |
4146 | 0 | outrel.r_offset = (htab->elf.sgot->output_section->vma |
4147 | 0 | + htab->elf.sgot->output_offset + off); |
4148 | |
|
4149 | 0 | bfd_put_64 (output_bfd, 0, |
4150 | 0 | htab->elf.sgot->contents + off); |
4151 | 0 | bfd_put_64 (output_bfd, 0, |
4152 | 0 | htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
4153 | 0 | outrel.r_info = htab->r_info (0, R_X86_64_DTPMOD64); |
4154 | 0 | outrel.r_addend = 0; |
4155 | 0 | elf_append_rela (output_bfd, htab->elf.srelgot, |
4156 | 0 | &outrel); |
4157 | 0 | htab->tls_ld_or_ldm_got.offset |= 1; |
4158 | 0 | } |
4159 | 0 | relocation = htab->elf.sgot->output_section->vma |
4160 | 0 | + htab->elf.sgot->output_offset + off; |
4161 | 0 | unresolved_reloc = false; |
4162 | 0 | break; |
4163 | | |
4164 | 0 | case R_X86_64_DTPOFF32: |
4165 | 0 | if (!bfd_link_executable (info) |
4166 | 0 | || (input_section->flags & SEC_CODE) == 0) |
4167 | 0 | relocation -= _bfd_x86_elf_dtpoff_base (info); |
4168 | 0 | else |
4169 | 0 | relocation = elf_x86_64_tpoff (info, relocation); |
4170 | 0 | break; |
4171 | | |
4172 | 0 | case R_X86_64_TPOFF32: |
4173 | 0 | case R_X86_64_TPOFF64: |
4174 | 0 | BFD_ASSERT (bfd_link_executable (info)); |
4175 | 0 | relocation = elf_x86_64_tpoff (info, relocation); |
4176 | 0 | break; |
4177 | | |
4178 | 0 | case R_X86_64_DTPOFF64: |
4179 | 0 | BFD_ASSERT ((input_section->flags & SEC_CODE) == 0); |
4180 | 0 | relocation -= _bfd_x86_elf_dtpoff_base (info); |
4181 | 0 | break; |
4182 | | |
4183 | 0 | default: |
4184 | 0 | break; |
4185 | 0 | } |
4186 | | |
4187 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
4188 | | because such sections are not SEC_ALLOC and thus ld.so will |
4189 | | not process them. */ |
4190 | 0 | if (unresolved_reloc |
4191 | 0 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
4192 | 0 | && h->def_dynamic) |
4193 | 0 | && _bfd_elf_section_offset (output_bfd, info, input_section, |
4194 | 0 | rel->r_offset) != (bfd_vma) -1) |
4195 | 0 | { |
4196 | 0 | switch (r_type) |
4197 | 0 | { |
4198 | 0 | case R_X86_64_32S: |
4199 | 0 | sec = h->root.u.def.section; |
4200 | 0 | if ((info->nocopyreloc || eh->def_protected) |
4201 | 0 | && !(h->root.u.def.section->flags & SEC_CODE)) |
4202 | 0 | return elf_x86_64_need_pic (info, input_bfd, input_section, |
4203 | 0 | h, NULL, NULL, howto); |
4204 | | /* Fall through. */ |
4205 | | |
4206 | 0 | default: |
4207 | 0 | _bfd_error_handler |
4208 | | /* xgettext:c-format */ |
4209 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
4210 | 0 | "unresolvable %s relocation against symbol `%s'"), |
4211 | 0 | input_bfd, |
4212 | 0 | input_section, |
4213 | 0 | (uint64_t) rel->r_offset, |
4214 | 0 | howto->name, |
4215 | 0 | h->root.root.string); |
4216 | 0 | return false; |
4217 | 0 | } |
4218 | 0 | } |
4219 | | |
4220 | 0 | do_relocation: |
4221 | 0 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
4222 | 0 | contents, rel->r_offset, |
4223 | 0 | relocation, rel->r_addend); |
4224 | |
|
4225 | 0 | check_relocation_error: |
4226 | 0 | if (r != bfd_reloc_ok) |
4227 | 0 | { |
4228 | 0 | const char *name; |
4229 | |
|
4230 | 0 | if (h != NULL) |
4231 | 0 | name = h->root.root.string; |
4232 | 0 | else |
4233 | 0 | { |
4234 | 0 | name = bfd_elf_string_from_elf_section (input_bfd, |
4235 | 0 | symtab_hdr->sh_link, |
4236 | 0 | sym->st_name); |
4237 | 0 | if (name == NULL) |
4238 | 0 | return false; |
4239 | 0 | if (*name == '\0') |
4240 | 0 | name = bfd_section_name (sec); |
4241 | 0 | } |
4242 | | |
4243 | 0 | if (r == bfd_reloc_overflow) |
4244 | 0 | { |
4245 | 0 | if (converted_reloc) |
4246 | 0 | { |
4247 | 0 | info->callbacks->einfo |
4248 | 0 | ("%X%H:", input_bfd, input_section, rel->r_offset); |
4249 | 0 | info->callbacks->einfo |
4250 | 0 | (_(" failed to convert GOTPCREL relocation against " |
4251 | 0 | "'%s'; relink with --no-relax\n"), |
4252 | 0 | name); |
4253 | 0 | status = false; |
4254 | 0 | continue; |
4255 | 0 | } |
4256 | 0 | (*info->callbacks->reloc_overflow) |
4257 | 0 | (info, (h ? &h->root : NULL), name, howto->name, |
4258 | 0 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); |
4259 | 0 | } |
4260 | 0 | else |
4261 | 0 | { |
4262 | 0 | _bfd_error_handler |
4263 | | /* xgettext:c-format */ |
4264 | 0 | (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"), |
4265 | 0 | input_bfd, input_section, |
4266 | 0 | (uint64_t) rel->r_offset, name, (int) r); |
4267 | 0 | return false; |
4268 | 0 | } |
4269 | 0 | } |
4270 | | |
4271 | 0 | if (wrel != rel) |
4272 | 0 | *wrel = *rel; |
4273 | 0 | } |
4274 | | |
4275 | 0 | if (wrel != rel) |
4276 | 0 | { |
4277 | 0 | Elf_Internal_Shdr *rel_hdr; |
4278 | 0 | size_t deleted = rel - wrel; |
4279 | |
|
4280 | 0 | rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section); |
4281 | 0 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; |
4282 | 0 | if (rel_hdr->sh_size == 0) |
4283 | 0 | { |
4284 | | /* It is too late to remove an empty reloc section. Leave |
4285 | | one NONE reloc. |
4286 | | ??? What is wrong with an empty section??? */ |
4287 | 0 | rel_hdr->sh_size = rel_hdr->sh_entsize; |
4288 | 0 | deleted -= 1; |
4289 | 0 | } |
4290 | 0 | rel_hdr = _bfd_elf_single_rel_hdr (input_section); |
4291 | 0 | rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted; |
4292 | 0 | input_section->reloc_count -= deleted; |
4293 | 0 | } |
4294 | |
|
4295 | 0 | return status; |
4296 | 0 | } |
4297 | | |
4298 | | /* Finish up dynamic symbol handling. We set the contents of various |
4299 | | dynamic sections here. */ |
4300 | | |
4301 | | static bool |
4302 | | elf_x86_64_finish_dynamic_symbol (bfd *output_bfd, |
4303 | | struct bfd_link_info *info, |
4304 | | struct elf_link_hash_entry *h, |
4305 | | Elf_Internal_Sym *sym) |
4306 | 0 | { |
4307 | 0 | struct elf_x86_link_hash_table *htab; |
4308 | 0 | bool use_plt_second; |
4309 | 0 | struct elf_x86_link_hash_entry *eh; |
4310 | 0 | bool local_undefweak; |
4311 | |
|
4312 | 0 | htab = elf_x86_hash_table (info, X86_64_ELF_DATA); |
4313 | 0 | if (htab == NULL) |
4314 | 0 | return false; |
4315 | | |
4316 | | /* Use the second PLT section only if there is .plt section. */ |
4317 | 0 | use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL; |
4318 | |
|
4319 | 0 | eh = (struct elf_x86_link_hash_entry *) h; |
4320 | 0 | if (eh->no_finish_dynamic_symbol) |
4321 | 0 | abort (); |
4322 | | |
4323 | | /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for |
4324 | | resolved undefined weak symbols in executable so that their |
4325 | | references have value 0 at run-time. */ |
4326 | 0 | local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh); |
4327 | |
|
4328 | 0 | if (h->plt.offset != (bfd_vma) -1) |
4329 | 0 | { |
4330 | 0 | bfd_vma plt_index; |
4331 | 0 | bfd_vma got_offset, plt_offset; |
4332 | 0 | Elf_Internal_Rela rela; |
4333 | 0 | bfd_byte *loc; |
4334 | 0 | asection *plt, *gotplt, *relplt, *resolved_plt; |
4335 | 0 | const struct elf_backend_data *bed; |
4336 | 0 | bfd_vma plt_got_pcrel_offset; |
4337 | | |
4338 | | /* When building a static executable, use .iplt, .igot.plt and |
4339 | | .rela.iplt sections for STT_GNU_IFUNC symbols. */ |
4340 | 0 | if (htab->elf.splt != NULL) |
4341 | 0 | { |
4342 | 0 | plt = htab->elf.splt; |
4343 | 0 | gotplt = htab->elf.sgotplt; |
4344 | 0 | relplt = htab->elf.srelplt; |
4345 | 0 | } |
4346 | 0 | else |
4347 | 0 | { |
4348 | 0 | plt = htab->elf.iplt; |
4349 | 0 | gotplt = htab->elf.igotplt; |
4350 | 0 | relplt = htab->elf.irelplt; |
4351 | 0 | } |
4352 | |
|
4353 | 0 | VERIFY_PLT_ENTRY (info, h, plt, gotplt, relplt, local_undefweak) |
4354 | | |
4355 | | /* Get the index in the procedure linkage table which |
4356 | | corresponds to this symbol. This is the index of this symbol |
4357 | | in all the symbols for which we are making plt entries. The |
4358 | | first entry in the procedure linkage table is reserved. |
4359 | | |
4360 | | Get the offset into the .got table of the entry that |
4361 | | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE |
4362 | | bytes. The first three are reserved for the dynamic linker. |
4363 | | |
4364 | | For static executables, we don't reserve anything. */ |
4365 | | |
4366 | 0 | if (plt == htab->elf.splt) |
4367 | 0 | { |
4368 | 0 | got_offset = (h->plt.offset / htab->plt.plt_entry_size |
4369 | 0 | - htab->plt.has_plt0); |
4370 | 0 | got_offset = (got_offset + 3) * GOT_ENTRY_SIZE; |
4371 | 0 | } |
4372 | 0 | else |
4373 | 0 | { |
4374 | 0 | got_offset = h->plt.offset / htab->plt.plt_entry_size; |
4375 | 0 | got_offset = got_offset * GOT_ENTRY_SIZE; |
4376 | 0 | } |
4377 | | |
4378 | | /* Fill in the entry in the procedure linkage table. */ |
4379 | 0 | memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry, |
4380 | 0 | htab->plt.plt_entry_size); |
4381 | 0 | if (use_plt_second) |
4382 | 0 | { |
4383 | 0 | memcpy (htab->plt_second->contents + eh->plt_second.offset, |
4384 | 0 | htab->non_lazy_plt->plt_entry, |
4385 | 0 | htab->non_lazy_plt->plt_entry_size); |
4386 | |
|
4387 | 0 | resolved_plt = htab->plt_second; |
4388 | 0 | plt_offset = eh->plt_second.offset; |
4389 | 0 | } |
4390 | 0 | else |
4391 | 0 | { |
4392 | 0 | resolved_plt = plt; |
4393 | 0 | plt_offset = h->plt.offset; |
4394 | 0 | } |
4395 | | |
4396 | | /* Insert the relocation positions of the plt section. */ |
4397 | | |
4398 | | /* Put offset the PC-relative instruction referring to the GOT entry, |
4399 | | subtracting the size of that instruction. */ |
4400 | 0 | plt_got_pcrel_offset = (gotplt->output_section->vma |
4401 | 0 | + gotplt->output_offset |
4402 | 0 | + got_offset |
4403 | 0 | - resolved_plt->output_section->vma |
4404 | 0 | - resolved_plt->output_offset |
4405 | 0 | - plt_offset |
4406 | 0 | - htab->plt.plt_got_insn_size); |
4407 | | |
4408 | | /* Check PC-relative offset overflow in PLT entry. */ |
4409 | 0 | if ((plt_got_pcrel_offset + 0x80000000) > 0xffffffff) |
4410 | | /* xgettext:c-format */ |
4411 | 0 | info->callbacks->einfo (_("%F%pB: PC-relative offset overflow in PLT entry for `%s'\n"), |
4412 | 0 | output_bfd, h->root.root.string); |
4413 | |
|
4414 | 0 | bfd_put_32 (output_bfd, plt_got_pcrel_offset, |
4415 | 0 | (resolved_plt->contents + plt_offset |
4416 | 0 | + htab->plt.plt_got_offset)); |
4417 | | |
4418 | | /* Fill in the entry in the global offset table, initially this |
4419 | | points to the second part of the PLT entry. Leave the entry |
4420 | | as zero for undefined weak symbol in PIE. No PLT relocation |
4421 | | against undefined weak symbol in PIE. */ |
4422 | 0 | if (!local_undefweak) |
4423 | 0 | { |
4424 | 0 | if (htab->plt.has_plt0) |
4425 | 0 | bfd_put_64 (output_bfd, (plt->output_section->vma |
4426 | 0 | + plt->output_offset |
4427 | 0 | + h->plt.offset |
4428 | 0 | + htab->lazy_plt->plt_lazy_offset), |
4429 | 0 | gotplt->contents + got_offset); |
4430 | | |
4431 | | /* Fill in the entry in the .rela.plt section. */ |
4432 | 0 | rela.r_offset = (gotplt->output_section->vma |
4433 | 0 | + gotplt->output_offset |
4434 | 0 | + got_offset); |
4435 | 0 | if (PLT_LOCAL_IFUNC_P (info, h)) |
4436 | 0 | { |
4437 | 0 | info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"), |
4438 | 0 | h->root.root.string, |
4439 | 0 | h->root.u.def.section->owner); |
4440 | | |
4441 | | /* If an STT_GNU_IFUNC symbol is locally defined, generate |
4442 | | R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT. */ |
4443 | 0 | rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE); |
4444 | 0 | rela.r_addend = (h->root.u.def.value |
4445 | 0 | + h->root.u.def.section->output_section->vma |
4446 | 0 | + h->root.u.def.section->output_offset); |
4447 | |
|
4448 | 0 | if (htab->params->report_relative_reloc) |
4449 | 0 | _bfd_x86_elf_link_report_relative_reloc |
4450 | 0 | (info, relplt, h, sym, "R_X86_64_IRELATIVE", &rela); |
4451 | | |
4452 | | /* R_X86_64_IRELATIVE comes last. */ |
4453 | 0 | plt_index = htab->next_irelative_index--; |
4454 | 0 | } |
4455 | 0 | else |
4456 | 0 | { |
4457 | 0 | rela.r_info = htab->r_info (h->dynindx, R_X86_64_JUMP_SLOT); |
4458 | 0 | rela.r_addend = 0; |
4459 | 0 | plt_index = htab->next_jump_slot_index++; |
4460 | 0 | } |
4461 | | |
4462 | | /* Don't fill the second and third slots in PLT entry for |
4463 | | static executables nor without PLT0. */ |
4464 | 0 | if (plt == htab->elf.splt && htab->plt.has_plt0) |
4465 | 0 | { |
4466 | 0 | bfd_vma plt0_offset |
4467 | 0 | = h->plt.offset + htab->lazy_plt->plt_plt_insn_end; |
4468 | | |
4469 | | /* Put relocation index. */ |
4470 | 0 | bfd_put_32 (output_bfd, plt_index, |
4471 | 0 | (plt->contents + h->plt.offset |
4472 | 0 | + htab->lazy_plt->plt_reloc_offset)); |
4473 | | |
4474 | | /* Put offset for jmp .PLT0 and check for overflow. We don't |
4475 | | check relocation index for overflow since branch displacement |
4476 | | will overflow first. */ |
4477 | 0 | if (plt0_offset > 0x80000000) |
4478 | | /* xgettext:c-format */ |
4479 | 0 | info->callbacks->einfo (_("%F%pB: branch displacement overflow in PLT entry for `%s'\n"), |
4480 | 0 | output_bfd, h->root.root.string); |
4481 | 0 | bfd_put_32 (output_bfd, - plt0_offset, |
4482 | 0 | (plt->contents + h->plt.offset |
4483 | 0 | + htab->lazy_plt->plt_plt_offset)); |
4484 | 0 | } |
4485 | |
|
4486 | 0 | bed = get_elf_backend_data (output_bfd); |
4487 | 0 | loc = relplt->contents + plt_index * bed->s->sizeof_rela; |
4488 | 0 | bed->s->swap_reloca_out (output_bfd, &rela, loc); |
4489 | 0 | } |
4490 | 0 | } |
4491 | 0 | else if (eh->plt_got.offset != (bfd_vma) -1) |
4492 | 0 | { |
4493 | 0 | bfd_vma got_offset, plt_offset; |
4494 | 0 | asection *plt, *got; |
4495 | 0 | bool got_after_plt; |
4496 | 0 | int32_t got_pcrel_offset; |
4497 | | |
4498 | | /* Set the entry in the GOT procedure linkage table. */ |
4499 | 0 | plt = htab->plt_got; |
4500 | 0 | got = htab->elf.sgot; |
4501 | 0 | got_offset = h->got.offset; |
4502 | |
|
4503 | 0 | if (got_offset == (bfd_vma) -1 |
4504 | 0 | || (h->type == STT_GNU_IFUNC && h->def_regular) |
4505 | 0 | || plt == NULL |
4506 | 0 | || got == NULL) |
4507 | 0 | abort (); |
4508 | | |
4509 | | /* Use the non-lazy PLT entry template for the GOT PLT since they |
4510 | | are the identical. */ |
4511 | | /* Fill in the entry in the GOT procedure linkage table. */ |
4512 | 0 | plt_offset = eh->plt_got.offset; |
4513 | 0 | memcpy (plt->contents + plt_offset, |
4514 | 0 | htab->non_lazy_plt->plt_entry, |
4515 | 0 | htab->non_lazy_plt->plt_entry_size); |
4516 | | |
4517 | | /* Put offset the PC-relative instruction referring to the GOT |
4518 | | entry, subtracting the size of that instruction. */ |
4519 | 0 | got_pcrel_offset = (got->output_section->vma |
4520 | 0 | + got->output_offset |
4521 | 0 | + got_offset |
4522 | 0 | - plt->output_section->vma |
4523 | 0 | - plt->output_offset |
4524 | 0 | - plt_offset |
4525 | 0 | - htab->non_lazy_plt->plt_got_insn_size); |
4526 | | |
4527 | | /* Check PC-relative offset overflow in GOT PLT entry. */ |
4528 | 0 | got_after_plt = got->output_section->vma > plt->output_section->vma; |
4529 | 0 | if ((got_after_plt && got_pcrel_offset < 0) |
4530 | 0 | || (!got_after_plt && got_pcrel_offset > 0)) |
4531 | | /* xgettext:c-format */ |
4532 | 0 | info->callbacks->einfo (_("%F%pB: PC-relative offset overflow in GOT PLT entry for `%s'\n"), |
4533 | 0 | output_bfd, h->root.root.string); |
4534 | |
|
4535 | 0 | bfd_put_32 (output_bfd, got_pcrel_offset, |
4536 | 0 | (plt->contents + plt_offset |
4537 | 0 | + htab->non_lazy_plt->plt_got_offset)); |
4538 | 0 | } |
4539 | | |
4540 | 0 | if (!local_undefweak |
4541 | 0 | && !h->def_regular |
4542 | 0 | && (h->plt.offset != (bfd_vma) -1 |
4543 | 0 | || eh->plt_got.offset != (bfd_vma) -1)) |
4544 | 0 | { |
4545 | | /* Mark the symbol as undefined, rather than as defined in |
4546 | | the .plt section. Leave the value if there were any |
4547 | | relocations where pointer equality matters (this is a clue |
4548 | | for the dynamic linker, to make function pointer |
4549 | | comparisons work between an application and shared |
4550 | | library), otherwise set it to zero. If a function is only |
4551 | | called from a binary, there is no need to slow down |
4552 | | shared libraries because of that. */ |
4553 | 0 | sym->st_shndx = SHN_UNDEF; |
4554 | 0 | if (!h->pointer_equality_needed) |
4555 | 0 | sym->st_value = 0; |
4556 | 0 | } |
4557 | |
|
4558 | 0 | _bfd_x86_elf_link_fixup_ifunc_symbol (info, htab, h, sym); |
4559 | | |
4560 | | /* Don't generate dynamic GOT relocation against undefined weak |
4561 | | symbol in executable. */ |
4562 | 0 | if (h->got.offset != (bfd_vma) -1 |
4563 | 0 | && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h)->tls_type) |
4564 | 0 | && elf_x86_hash_entry (h)->tls_type != GOT_TLS_IE |
4565 | 0 | && !local_undefweak) |
4566 | 0 | { |
4567 | 0 | Elf_Internal_Rela rela; |
4568 | 0 | asection *relgot = htab->elf.srelgot; |
4569 | 0 | const char *relative_reloc_name = NULL; |
4570 | 0 | bool generate_dynamic_reloc = true; |
4571 | | |
4572 | | /* This symbol has an entry in the global offset table. Set it |
4573 | | up. */ |
4574 | 0 | if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL) |
4575 | 0 | abort (); |
4576 | | |
4577 | 0 | rela.r_offset = (htab->elf.sgot->output_section->vma |
4578 | 0 | + htab->elf.sgot->output_offset |
4579 | 0 | + (h->got.offset &~ (bfd_vma) 1)); |
4580 | | |
4581 | | /* If this is a static link, or it is a -Bsymbolic link and the |
4582 | | symbol is defined locally or was forced to be local because |
4583 | | of a version file, we just want to emit a RELATIVE reloc. |
4584 | | The entry in the global offset table will already have been |
4585 | | initialized in the relocate_section function. */ |
4586 | 0 | if (h->def_regular |
4587 | 0 | && h->type == STT_GNU_IFUNC) |
4588 | 0 | { |
4589 | 0 | if (h->plt.offset == (bfd_vma) -1) |
4590 | 0 | { |
4591 | | /* STT_GNU_IFUNC is referenced without PLT. */ |
4592 | 0 | if (htab->elf.splt == NULL) |
4593 | 0 | { |
4594 | | /* use .rel[a].iplt section to store .got relocations |
4595 | | in static executable. */ |
4596 | 0 | relgot = htab->elf.irelplt; |
4597 | 0 | } |
4598 | 0 | if (SYMBOL_REFERENCES_LOCAL_P (info, h)) |
4599 | 0 | { |
4600 | 0 | info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"), |
4601 | 0 | h->root.root.string, |
4602 | 0 | h->root.u.def.section->owner); |
4603 | |
|
4604 | 0 | rela.r_info = htab->r_info (0, |
4605 | 0 | R_X86_64_IRELATIVE); |
4606 | 0 | rela.r_addend = (h->root.u.def.value |
4607 | 0 | + h->root.u.def.section->output_section->vma |
4608 | 0 | + h->root.u.def.section->output_offset); |
4609 | 0 | relative_reloc_name = "R_X86_64_IRELATIVE"; |
4610 | 0 | } |
4611 | 0 | else |
4612 | 0 | goto do_glob_dat; |
4613 | 0 | } |
4614 | 0 | else if (bfd_link_pic (info)) |
4615 | 0 | { |
4616 | | /* Generate R_X86_64_GLOB_DAT. */ |
4617 | 0 | goto do_glob_dat; |
4618 | 0 | } |
4619 | 0 | else |
4620 | 0 | { |
4621 | 0 | asection *plt; |
4622 | 0 | bfd_vma plt_offset; |
4623 | |
|
4624 | 0 | if (!h->pointer_equality_needed) |
4625 | 0 | abort (); |
4626 | | |
4627 | | /* For non-shared object, we can't use .got.plt, which |
4628 | | contains the real function addres if we need pointer |
4629 | | equality. We load the GOT entry with the PLT entry. */ |
4630 | 0 | if (htab->plt_second != NULL) |
4631 | 0 | { |
4632 | 0 | plt = htab->plt_second; |
4633 | 0 | plt_offset = eh->plt_second.offset; |
4634 | 0 | } |
4635 | 0 | else |
4636 | 0 | { |
4637 | 0 | plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt; |
4638 | 0 | plt_offset = h->plt.offset; |
4639 | 0 | } |
4640 | 0 | bfd_put_64 (output_bfd, (plt->output_section->vma |
4641 | 0 | + plt->output_offset |
4642 | 0 | + plt_offset), |
4643 | 0 | htab->elf.sgot->contents + h->got.offset); |
4644 | 0 | return true; |
4645 | 0 | } |
4646 | 0 | } |
4647 | 0 | else if (bfd_link_pic (info) |
4648 | 0 | && SYMBOL_REFERENCES_LOCAL_P (info, h)) |
4649 | 0 | { |
4650 | 0 | if (!SYMBOL_DEFINED_NON_SHARED_P (h)) |
4651 | 0 | return false; |
4652 | 0 | BFD_ASSERT((h->got.offset & 1) != 0); |
4653 | 0 | if (info->enable_dt_relr) |
4654 | 0 | generate_dynamic_reloc = false; |
4655 | 0 | else |
4656 | 0 | { |
4657 | 0 | rela.r_info = htab->r_info (0, R_X86_64_RELATIVE); |
4658 | 0 | rela.r_addend = (h->root.u.def.value |
4659 | 0 | + h->root.u.def.section->output_section->vma |
4660 | 0 | + h->root.u.def.section->output_offset); |
4661 | 0 | relative_reloc_name = "R_X86_64_RELATIVE"; |
4662 | 0 | } |
4663 | 0 | } |
4664 | 0 | else |
4665 | 0 | { |
4666 | 0 | BFD_ASSERT((h->got.offset & 1) == 0); |
4667 | 0 | do_glob_dat: |
4668 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
4669 | 0 | htab->elf.sgot->contents + h->got.offset); |
4670 | 0 | rela.r_info = htab->r_info (h->dynindx, R_X86_64_GLOB_DAT); |
4671 | 0 | rela.r_addend = 0; |
4672 | 0 | } |
4673 | | |
4674 | 0 | if (generate_dynamic_reloc) |
4675 | 0 | { |
4676 | 0 | if (relative_reloc_name != NULL |
4677 | 0 | && htab->params->report_relative_reloc) |
4678 | 0 | _bfd_x86_elf_link_report_relative_reloc |
4679 | 0 | (info, relgot, h, sym, relative_reloc_name, &rela); |
4680 | |
|
4681 | 0 | elf_append_rela (output_bfd, relgot, &rela); |
4682 | 0 | } |
4683 | 0 | } |
4684 | | |
4685 | 0 | if (h->needs_copy) |
4686 | 0 | { |
4687 | 0 | Elf_Internal_Rela rela; |
4688 | 0 | asection *s; |
4689 | | |
4690 | | /* This symbol needs a copy reloc. Set it up. */ |
4691 | 0 | VERIFY_COPY_RELOC (h, htab) |
4692 | | |
4693 | 0 | rela.r_offset = (h->root.u.def.value |
4694 | 0 | + h->root.u.def.section->output_section->vma |
4695 | 0 | + h->root.u.def.section->output_offset); |
4696 | 0 | rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY); |
4697 | 0 | rela.r_addend = 0; |
4698 | 0 | if (h->root.u.def.section == htab->elf.sdynrelro) |
4699 | 0 | s = htab->elf.sreldynrelro; |
4700 | 0 | else |
4701 | 0 | s = htab->elf.srelbss; |
4702 | 0 | elf_append_rela (output_bfd, s, &rela); |
4703 | 0 | } |
4704 | | |
4705 | 0 | return true; |
4706 | 0 | } |
4707 | | |
4708 | | /* Finish up local dynamic symbol handling. We set the contents of |
4709 | | various dynamic sections here. */ |
4710 | | |
4711 | | static int |
4712 | | elf_x86_64_finish_local_dynamic_symbol (void **slot, void *inf) |
4713 | 0 | { |
4714 | 0 | struct elf_link_hash_entry *h |
4715 | 0 | = (struct elf_link_hash_entry *) *slot; |
4716 | 0 | struct bfd_link_info *info |
4717 | 0 | = (struct bfd_link_info *) inf; |
4718 | |
|
4719 | 0 | return elf_x86_64_finish_dynamic_symbol (info->output_bfd, |
4720 | 0 | info, h, NULL); |
4721 | 0 | } |
4722 | | |
4723 | | /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry |
4724 | | here since undefined weak symbol may not be dynamic and may not be |
4725 | | called for elf_x86_64_finish_dynamic_symbol. */ |
4726 | | |
4727 | | static bool |
4728 | | elf_x86_64_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh, |
4729 | | void *inf) |
4730 | 0 | { |
4731 | 0 | struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh; |
4732 | 0 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
4733 | |
|
4734 | 0 | if (h->root.type != bfd_link_hash_undefweak |
4735 | 0 | || h->dynindx != -1) |
4736 | 0 | return true; |
4737 | | |
4738 | 0 | return elf_x86_64_finish_dynamic_symbol (info->output_bfd, |
4739 | 0 | info, h, NULL); |
4740 | 0 | } |
4741 | | |
4742 | | /* Used to decide how to sort relocs in an optimal manner for the |
4743 | | dynamic linker, before writing them out. */ |
4744 | | |
4745 | | static enum elf_reloc_type_class |
4746 | | elf_x86_64_reloc_type_class (const struct bfd_link_info *info, |
4747 | | const asection *rel_sec ATTRIBUTE_UNUSED, |
4748 | | const Elf_Internal_Rela *rela) |
4749 | 0 | { |
4750 | 0 | bfd *abfd = info->output_bfd; |
4751 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
4752 | 0 | struct elf_x86_link_hash_table *htab |
4753 | 0 | = elf_x86_hash_table (info, X86_64_ELF_DATA); |
4754 | |
|
4755 | 0 | if (htab->elf.dynsym != NULL |
4756 | 0 | && htab->elf.dynsym->contents != NULL) |
4757 | 0 | { |
4758 | | /* Check relocation against STT_GNU_IFUNC symbol if there are |
4759 | | dynamic symbols. */ |
4760 | 0 | unsigned long r_symndx = htab->r_sym (rela->r_info); |
4761 | 0 | if (r_symndx != STN_UNDEF) |
4762 | 0 | { |
4763 | 0 | Elf_Internal_Sym sym; |
4764 | 0 | if (!bed->s->swap_symbol_in (abfd, |
4765 | 0 | (htab->elf.dynsym->contents |
4766 | 0 | + r_symndx * bed->s->sizeof_sym), |
4767 | 0 | 0, &sym)) |
4768 | 0 | abort (); |
4769 | | |
4770 | 0 | if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) |
4771 | 0 | return reloc_class_ifunc; |
4772 | 0 | } |
4773 | 0 | } |
4774 | | |
4775 | 0 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
4776 | 0 | { |
4777 | 0 | case R_X86_64_IRELATIVE: |
4778 | 0 | return reloc_class_ifunc; |
4779 | 0 | case R_X86_64_RELATIVE: |
4780 | 0 | case R_X86_64_RELATIVE64: |
4781 | 0 | return reloc_class_relative; |
4782 | 0 | case R_X86_64_JUMP_SLOT: |
4783 | 0 | return reloc_class_plt; |
4784 | 0 | case R_X86_64_COPY: |
4785 | 0 | return reloc_class_copy; |
4786 | 0 | default: |
4787 | 0 | return reloc_class_normal; |
4788 | 0 | } |
4789 | 0 | } |
4790 | | |
4791 | | /* Finish up the dynamic sections. */ |
4792 | | |
4793 | | static bool |
4794 | | elf_x86_64_finish_dynamic_sections (bfd *output_bfd, |
4795 | | struct bfd_link_info *info) |
4796 | 0 | { |
4797 | 0 | struct elf_x86_link_hash_table *htab; |
4798 | |
|
4799 | 0 | htab = _bfd_x86_elf_finish_dynamic_sections (output_bfd, info); |
4800 | 0 | if (htab == NULL) |
4801 | 0 | return false; |
4802 | | |
4803 | 0 | if (! htab->elf.dynamic_sections_created) |
4804 | 0 | return true; |
4805 | | |
4806 | 0 | if (htab->elf.splt && htab->elf.splt->size > 0) |
4807 | 0 | { |
4808 | 0 | if (bfd_is_abs_section (htab->elf.splt->output_section)) |
4809 | 0 | { |
4810 | 0 | info->callbacks->einfo |
4811 | 0 | (_("%F%P: discarded output section: `%pA'\n"), |
4812 | 0 | htab->elf.splt); |
4813 | 0 | return false; |
4814 | 0 | } |
4815 | | |
4816 | 0 | elf_section_data (htab->elf.splt->output_section) |
4817 | 0 | ->this_hdr.sh_entsize = htab->plt.plt_entry_size; |
4818 | |
|
4819 | 0 | if (htab->plt.has_plt0) |
4820 | 0 | { |
4821 | | /* Fill in the special first entry in the procedure linkage |
4822 | | table. */ |
4823 | 0 | memcpy (htab->elf.splt->contents, |
4824 | 0 | htab->lazy_plt->plt0_entry, |
4825 | 0 | htab->lazy_plt->plt0_entry_size); |
4826 | | /* Add offset for pushq GOT+8(%rip), since the instruction |
4827 | | uses 6 bytes subtract this value. */ |
4828 | 0 | bfd_put_32 (output_bfd, |
4829 | 0 | (htab->elf.sgotplt->output_section->vma |
4830 | 0 | + htab->elf.sgotplt->output_offset |
4831 | 0 | + 8 |
4832 | 0 | - htab->elf.splt->output_section->vma |
4833 | 0 | - htab->elf.splt->output_offset |
4834 | 0 | - 6), |
4835 | 0 | (htab->elf.splt->contents |
4836 | 0 | + htab->lazy_plt->plt0_got1_offset)); |
4837 | | /* Add offset for the PC-relative instruction accessing |
4838 | | GOT+16, subtracting the offset to the end of that |
4839 | | instruction. */ |
4840 | 0 | bfd_put_32 (output_bfd, |
4841 | 0 | (htab->elf.sgotplt->output_section->vma |
4842 | 0 | + htab->elf.sgotplt->output_offset |
4843 | 0 | + 16 |
4844 | 0 | - htab->elf.splt->output_section->vma |
4845 | 0 | - htab->elf.splt->output_offset |
4846 | 0 | - htab->lazy_plt->plt0_got2_insn_end), |
4847 | 0 | (htab->elf.splt->contents |
4848 | 0 | + htab->lazy_plt->plt0_got2_offset)); |
4849 | 0 | } |
4850 | |
|
4851 | 0 | if (htab->elf.tlsdesc_plt) |
4852 | 0 | { |
4853 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
4854 | 0 | htab->elf.sgot->contents + htab->elf.tlsdesc_got); |
4855 | |
|
4856 | 0 | memcpy (htab->elf.splt->contents + htab->elf.tlsdesc_plt, |
4857 | 0 | htab->lazy_plt->plt_tlsdesc_entry, |
4858 | 0 | htab->lazy_plt->plt_tlsdesc_entry_size); |
4859 | | |
4860 | | /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4 |
4861 | | bytes and the instruction uses 6 bytes, subtract these |
4862 | | values. */ |
4863 | 0 | bfd_put_32 (output_bfd, |
4864 | 0 | (htab->elf.sgotplt->output_section->vma |
4865 | 0 | + htab->elf.sgotplt->output_offset |
4866 | 0 | + 8 |
4867 | 0 | - htab->elf.splt->output_section->vma |
4868 | 0 | - htab->elf.splt->output_offset |
4869 | 0 | - htab->elf.tlsdesc_plt |
4870 | 0 | - htab->lazy_plt->plt_tlsdesc_got1_insn_end), |
4871 | 0 | (htab->elf.splt->contents |
4872 | 0 | + htab->elf.tlsdesc_plt |
4873 | 0 | + htab->lazy_plt->plt_tlsdesc_got1_offset)); |
4874 | | /* Add offset for indirect branch via GOT+TDG, where TDG |
4875 | | stands for htab->tlsdesc_got, subtracting the offset |
4876 | | to the end of that instruction. */ |
4877 | 0 | bfd_put_32 (output_bfd, |
4878 | 0 | (htab->elf.sgot->output_section->vma |
4879 | 0 | + htab->elf.sgot->output_offset |
4880 | 0 | + htab->elf.tlsdesc_got |
4881 | 0 | - htab->elf.splt->output_section->vma |
4882 | 0 | - htab->elf.splt->output_offset |
4883 | 0 | - htab->elf.tlsdesc_plt |
4884 | 0 | - htab->lazy_plt->plt_tlsdesc_got2_insn_end), |
4885 | 0 | (htab->elf.splt->contents |
4886 | 0 | + htab->elf.tlsdesc_plt |
4887 | 0 | + htab->lazy_plt->plt_tlsdesc_got2_offset)); |
4888 | 0 | } |
4889 | 0 | } |
4890 | | |
4891 | | /* Fill PLT entries for undefined weak symbols in PIE. */ |
4892 | 0 | if (bfd_link_pie (info)) |
4893 | 0 | bfd_hash_traverse (&info->hash->table, |
4894 | 0 | elf_x86_64_pie_finish_undefweak_symbol, |
4895 | 0 | info); |
4896 | |
|
4897 | 0 | return true; |
4898 | 0 | } |
4899 | | |
4900 | | /* Fill PLT/GOT entries and allocate dynamic relocations for local |
4901 | | STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table. |
4902 | | It has to be done before elf_link_sort_relocs is called so that |
4903 | | dynamic relocations are properly sorted. */ |
4904 | | |
4905 | | static bool |
4906 | | elf_x86_64_output_arch_local_syms |
4907 | | (bfd *output_bfd ATTRIBUTE_UNUSED, |
4908 | | struct bfd_link_info *info, |
4909 | | void *flaginfo ATTRIBUTE_UNUSED, |
4910 | | int (*func) (void *, const char *, |
4911 | | Elf_Internal_Sym *, |
4912 | | asection *, |
4913 | | struct elf_link_hash_entry *) ATTRIBUTE_UNUSED) |
4914 | 0 | { |
4915 | 0 | struct elf_x86_link_hash_table *htab |
4916 | 0 | = elf_x86_hash_table (info, X86_64_ELF_DATA); |
4917 | 0 | if (htab == NULL) |
4918 | 0 | return false; |
4919 | | |
4920 | | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
4921 | 0 | htab_traverse (htab->loc_hash_table, |
4922 | 0 | elf_x86_64_finish_local_dynamic_symbol, |
4923 | 0 | info); |
4924 | |
|
4925 | 0 | return true; |
4926 | 0 | } |
4927 | | |
4928 | | /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all |
4929 | | dynamic relocations. */ |
4930 | | |
4931 | | static long |
4932 | | elf_x86_64_get_synthetic_symtab (bfd *abfd, |
4933 | | long symcount ATTRIBUTE_UNUSED, |
4934 | | asymbol **syms ATTRIBUTE_UNUSED, |
4935 | | long dynsymcount, |
4936 | | asymbol **dynsyms, |
4937 | | asymbol **ret) |
4938 | 0 | { |
4939 | 0 | long count, i, n; |
4940 | 0 | int j; |
4941 | 0 | bfd_byte *plt_contents; |
4942 | 0 | long relsize; |
4943 | 0 | const struct elf_x86_lazy_plt_layout *lazy_plt; |
4944 | 0 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; |
4945 | 0 | const struct elf_x86_lazy_plt_layout *lazy_bnd_plt; |
4946 | 0 | const struct elf_x86_non_lazy_plt_layout *non_lazy_bnd_plt; |
4947 | 0 | const struct elf_x86_lazy_plt_layout *lazy_ibt_plt; |
4948 | 0 | const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt; |
4949 | 0 | const struct elf_x86_lazy_plt_layout *x32_lazy_ibt_plt; |
4950 | 0 | const struct elf_x86_non_lazy_plt_layout *x32_non_lazy_ibt_plt; |
4951 | 0 | asection *plt; |
4952 | 0 | enum elf_x86_plt_type plt_type; |
4953 | 0 | struct elf_x86_plt plts[] = |
4954 | 0 | { |
4955 | 0 | { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 }, |
4956 | 0 | { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }, |
4957 | 0 | { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 }, |
4958 | 0 | { ".plt.bnd", NULL, NULL, plt_second, 0, 0, 0, 0 }, |
4959 | 0 | { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 } |
4960 | 0 | }; |
4961 | |
|
4962 | 0 | *ret = NULL; |
4963 | |
|
4964 | 0 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0) |
4965 | 0 | return 0; |
4966 | | |
4967 | 0 | if (dynsymcount <= 0) |
4968 | 0 | return 0; |
4969 | | |
4970 | 0 | relsize = bfd_get_dynamic_reloc_upper_bound (abfd); |
4971 | 0 | if (relsize <= 0) |
4972 | 0 | return -1; |
4973 | | |
4974 | 0 | lazy_plt = &elf_x86_64_lazy_plt; |
4975 | 0 | non_lazy_plt = &elf_x86_64_non_lazy_plt; |
4976 | 0 | lazy_bnd_plt = &elf_x86_64_lazy_bnd_plt; |
4977 | 0 | non_lazy_bnd_plt = &elf_x86_64_non_lazy_bnd_plt; |
4978 | 0 | if (ABI_64_P (abfd)) |
4979 | 0 | { |
4980 | 0 | lazy_ibt_plt = &elf_x86_64_lazy_ibt_plt; |
4981 | 0 | non_lazy_ibt_plt = &elf_x86_64_non_lazy_ibt_plt; |
4982 | 0 | x32_lazy_ibt_plt = &elf_x32_lazy_ibt_plt; |
4983 | 0 | x32_non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt; |
4984 | 0 | } |
4985 | 0 | else |
4986 | 0 | { |
4987 | 0 | lazy_ibt_plt = &elf_x32_lazy_ibt_plt; |
4988 | 0 | non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt; |
4989 | 0 | x32_lazy_ibt_plt = NULL; |
4990 | 0 | x32_non_lazy_ibt_plt = NULL; |
4991 | 0 | } |
4992 | |
|
4993 | 0 | count = 0; |
4994 | 0 | for (j = 0; plts[j].name != NULL; j++) |
4995 | 0 | { |
4996 | 0 | plt = bfd_get_section_by_name (abfd, plts[j].name); |
4997 | 0 | if (plt == NULL |
4998 | 0 | || plt->size == 0 |
4999 | 0 | || (plt->flags & SEC_HAS_CONTENTS) == 0) |
5000 | 0 | continue; |
5001 | | |
5002 | | /* Get the PLT section contents. */ |
5003 | 0 | if (!bfd_malloc_and_get_section (abfd, plt, &plt_contents)) |
5004 | 0 | break; |
5005 | | |
5006 | | /* Check what kind of PLT it is. */ |
5007 | 0 | plt_type = plt_unknown; |
5008 | 0 | if (plts[j].type == plt_unknown |
5009 | 0 | && (plt->size >= (lazy_plt->plt_entry_size |
5010 | 0 | + lazy_plt->plt_entry_size))) |
5011 | 0 | { |
5012 | | /* Match lazy PLT first. Need to check the first two |
5013 | | instructions. */ |
5014 | 0 | if ((memcmp (plt_contents, lazy_plt->plt0_entry, |
5015 | 0 | lazy_plt->plt0_got1_offset) == 0) |
5016 | 0 | && (memcmp (plt_contents + 6, lazy_plt->plt0_entry + 6, |
5017 | 0 | 2) == 0)) |
5018 | 0 | { |
5019 | 0 | if (x32_lazy_ibt_plt != NULL |
5020 | 0 | && (memcmp (plt_contents |
5021 | 0 | + x32_lazy_ibt_plt->plt_entry_size, |
5022 | 0 | x32_lazy_ibt_plt->plt_entry, |
5023 | 0 | x32_lazy_ibt_plt->plt_got_offset) == 0)) |
5024 | 0 | { |
5025 | | /* The fist entry in the x32 lazy IBT PLT is the same |
5026 | | as the lazy PLT. */ |
5027 | 0 | plt_type = plt_lazy | plt_second; |
5028 | 0 | lazy_plt = x32_lazy_ibt_plt; |
5029 | 0 | } |
5030 | 0 | else |
5031 | 0 | plt_type = plt_lazy; |
5032 | 0 | } |
5033 | 0 | else if (lazy_bnd_plt != NULL |
5034 | 0 | && (memcmp (plt_contents, lazy_bnd_plt->plt0_entry, |
5035 | 0 | lazy_bnd_plt->plt0_got1_offset) == 0) |
5036 | 0 | && (memcmp (plt_contents + 6, |
5037 | 0 | lazy_bnd_plt->plt0_entry + 6, 3) == 0)) |
5038 | 0 | { |
5039 | 0 | plt_type = plt_lazy | plt_second; |
5040 | | /* The fist entry in the lazy IBT PLT is the same as the |
5041 | | lazy BND PLT. */ |
5042 | 0 | if ((memcmp (plt_contents + lazy_ibt_plt->plt_entry_size, |
5043 | 0 | lazy_ibt_plt->plt_entry, |
5044 | 0 | lazy_ibt_plt->plt_got_offset) == 0)) |
5045 | 0 | lazy_plt = lazy_ibt_plt; |
5046 | 0 | else |
5047 | 0 | lazy_plt = lazy_bnd_plt; |
5048 | 0 | } |
5049 | 0 | } |
5050 | |
|
5051 | 0 | if (non_lazy_plt != NULL |
5052 | 0 | && (plt_type == plt_unknown || plt_type == plt_non_lazy) |
5053 | 0 | && plt->size >= non_lazy_plt->plt_entry_size) |
5054 | 0 | { |
5055 | | /* Match non-lazy PLT. */ |
5056 | 0 | if (memcmp (plt_contents, non_lazy_plt->plt_entry, |
5057 | 0 | non_lazy_plt->plt_got_offset) == 0) |
5058 | 0 | plt_type = plt_non_lazy; |
5059 | 0 | } |
5060 | |
|
5061 | 0 | if (plt_type == plt_unknown || plt_type == plt_second) |
5062 | 0 | { |
5063 | 0 | if (non_lazy_bnd_plt != NULL |
5064 | 0 | && plt->size >= non_lazy_bnd_plt->plt_entry_size |
5065 | 0 | && (memcmp (plt_contents, non_lazy_bnd_plt->plt_entry, |
5066 | 0 | non_lazy_bnd_plt->plt_got_offset) == 0)) |
5067 | 0 | { |
5068 | | /* Match BND PLT. */ |
5069 | 0 | plt_type = plt_second; |
5070 | 0 | non_lazy_plt = non_lazy_bnd_plt; |
5071 | 0 | } |
5072 | 0 | else if (non_lazy_ibt_plt != NULL |
5073 | 0 | && plt->size >= non_lazy_ibt_plt->plt_entry_size |
5074 | 0 | && (memcmp (plt_contents, |
5075 | 0 | non_lazy_ibt_plt->plt_entry, |
5076 | 0 | non_lazy_ibt_plt->plt_got_offset) == 0)) |
5077 | 0 | { |
5078 | | /* Match IBT PLT. */ |
5079 | 0 | plt_type = plt_second; |
5080 | 0 | non_lazy_plt = non_lazy_ibt_plt; |
5081 | 0 | } |
5082 | 0 | else if (x32_non_lazy_ibt_plt != NULL |
5083 | 0 | && plt->size >= x32_non_lazy_ibt_plt->plt_entry_size |
5084 | 0 | && (memcmp (plt_contents, |
5085 | 0 | x32_non_lazy_ibt_plt->plt_entry, |
5086 | 0 | x32_non_lazy_ibt_plt->plt_got_offset) == 0)) |
5087 | 0 | { |
5088 | | /* Match x32 IBT PLT. */ |
5089 | 0 | plt_type = plt_second; |
5090 | 0 | non_lazy_plt = x32_non_lazy_ibt_plt; |
5091 | 0 | } |
5092 | 0 | } |
5093 | |
|
5094 | 0 | if (plt_type == plt_unknown) |
5095 | 0 | { |
5096 | 0 | free (plt_contents); |
5097 | 0 | continue; |
5098 | 0 | } |
5099 | | |
5100 | 0 | plts[j].sec = plt; |
5101 | 0 | plts[j].type = plt_type; |
5102 | |
|
5103 | 0 | if ((plt_type & plt_lazy)) |
5104 | 0 | { |
5105 | 0 | plts[j].plt_got_offset = lazy_plt->plt_got_offset; |
5106 | 0 | plts[j].plt_got_insn_size = lazy_plt->plt_got_insn_size; |
5107 | 0 | plts[j].plt_entry_size = lazy_plt->plt_entry_size; |
5108 | | /* Skip PLT0 in lazy PLT. */ |
5109 | 0 | i = 1; |
5110 | 0 | } |
5111 | 0 | else |
5112 | 0 | { |
5113 | 0 | plts[j].plt_got_offset = non_lazy_plt->plt_got_offset; |
5114 | 0 | plts[j].plt_got_insn_size = non_lazy_plt->plt_got_insn_size; |
5115 | 0 | plts[j].plt_entry_size = non_lazy_plt->plt_entry_size; |
5116 | 0 | i = 0; |
5117 | 0 | } |
5118 | | |
5119 | | /* Skip lazy PLT when the second PLT is used. */ |
5120 | 0 | if (plt_type == (plt_lazy | plt_second)) |
5121 | 0 | plts[j].count = 0; |
5122 | 0 | else |
5123 | 0 | { |
5124 | 0 | n = plt->size / plts[j].plt_entry_size; |
5125 | 0 | plts[j].count = n; |
5126 | 0 | count += n - i; |
5127 | 0 | } |
5128 | |
|
5129 | 0 | plts[j].contents = plt_contents; |
5130 | 0 | } |
5131 | |
|
5132 | 0 | return _bfd_x86_elf_get_synthetic_symtab (abfd, count, relsize, |
5133 | 0 | (bfd_vma) 0, plts, dynsyms, |
5134 | 0 | ret); |
5135 | 0 | } |
5136 | | |
5137 | | /* Handle an x86-64 specific section when reading an object file. This |
5138 | | is called when elfcode.h finds a section with an unknown type. */ |
5139 | | |
5140 | | static bool |
5141 | | elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr, |
5142 | | const char *name, int shindex) |
5143 | 2.40k | { |
5144 | 2.40k | if (hdr->sh_type != SHT_X86_64_UNWIND) |
5145 | 1.59k | return false; |
5146 | | |
5147 | 802 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
5148 | 0 | return false; |
5149 | | |
5150 | 802 | return true; |
5151 | 802 | } |
5152 | | |
5153 | | /* Hook called by the linker routine which adds symbols from an object |
5154 | | file. We use it to put SHN_X86_64_LCOMMON items in .lbss, instead |
5155 | | of .bss. */ |
5156 | | |
5157 | | static bool |
5158 | | elf_x86_64_add_symbol_hook (bfd *abfd, |
5159 | | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
5160 | | Elf_Internal_Sym *sym, |
5161 | | const char **namep ATTRIBUTE_UNUSED, |
5162 | | flagword *flagsp ATTRIBUTE_UNUSED, |
5163 | | asection **secp, |
5164 | | bfd_vma *valp) |
5165 | 0 | { |
5166 | 0 | asection *lcomm; |
5167 | |
|
5168 | 0 | switch (sym->st_shndx) |
5169 | 0 | { |
5170 | 0 | case SHN_X86_64_LCOMMON: |
5171 | 0 | lcomm = bfd_get_section_by_name (abfd, "LARGE_COMMON"); |
5172 | 0 | if (lcomm == NULL) |
5173 | 0 | { |
5174 | 0 | lcomm = bfd_make_section_with_flags (abfd, |
5175 | 0 | "LARGE_COMMON", |
5176 | 0 | (SEC_ALLOC |
5177 | 0 | | SEC_IS_COMMON |
5178 | 0 | | SEC_LINKER_CREATED)); |
5179 | 0 | if (lcomm == NULL) |
5180 | 0 | return false; |
5181 | 0 | elf_section_flags (lcomm) |= SHF_X86_64_LARGE; |
5182 | 0 | } |
5183 | 0 | *secp = lcomm; |
5184 | 0 | *valp = sym->st_size; |
5185 | 0 | return true; |
5186 | 0 | } |
5187 | | |
5188 | 0 | return true; |
5189 | 0 | } |
5190 | | |
5191 | | |
5192 | | /* Given a BFD section, try to locate the corresponding ELF section |
5193 | | index. */ |
5194 | | |
5195 | | static bool |
5196 | | elf_x86_64_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED, |
5197 | | asection *sec, int *index_return) |
5198 | 0 | { |
5199 | 0 | if (sec == &_bfd_elf_large_com_section) |
5200 | 0 | { |
5201 | 0 | *index_return = SHN_X86_64_LCOMMON; |
5202 | 0 | return true; |
5203 | 0 | } |
5204 | 0 | return false; |
5205 | 0 | } |
5206 | | |
5207 | | /* Process a symbol. */ |
5208 | | |
5209 | | static void |
5210 | | elf_x86_64_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, |
5211 | | asymbol *asym) |
5212 | 143k | { |
5213 | 143k | elf_symbol_type *elfsym = (elf_symbol_type *) asym; |
5214 | | |
5215 | 143k | switch (elfsym->internal_elf_sym.st_shndx) |
5216 | 143k | { |
5217 | 16 | case SHN_X86_64_LCOMMON: |
5218 | 16 | asym->section = &_bfd_elf_large_com_section; |
5219 | 16 | asym->value = elfsym->internal_elf_sym.st_size; |
5220 | | /* Common symbol doesn't set BSF_GLOBAL. */ |
5221 | 16 | asym->flags &= ~BSF_GLOBAL; |
5222 | 16 | break; |
5223 | 143k | } |
5224 | 143k | } |
5225 | | |
5226 | | static bool |
5227 | | elf_x86_64_common_definition (Elf_Internal_Sym *sym) |
5228 | 0 | { |
5229 | 0 | return (sym->st_shndx == SHN_COMMON |
5230 | 0 | || sym->st_shndx == SHN_X86_64_LCOMMON); |
5231 | 0 | } |
5232 | | |
5233 | | static unsigned int |
5234 | | elf_x86_64_common_section_index (asection *sec) |
5235 | 0 | { |
5236 | 0 | if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0) |
5237 | 0 | return SHN_COMMON; |
5238 | 0 | else |
5239 | 0 | return SHN_X86_64_LCOMMON; |
5240 | 0 | } |
5241 | | |
5242 | | static asection * |
5243 | | elf_x86_64_common_section (asection *sec) |
5244 | 0 | { |
5245 | 0 | if ((elf_section_flags (sec) & SHF_X86_64_LARGE) == 0) |
5246 | 0 | return bfd_com_section_ptr; |
5247 | 0 | else |
5248 | 0 | return &_bfd_elf_large_com_section; |
5249 | 0 | } |
5250 | | |
5251 | | static bool |
5252 | | elf_x86_64_merge_symbol (struct elf_link_hash_entry *h, |
5253 | | const Elf_Internal_Sym *sym, |
5254 | | asection **psec, |
5255 | | bool newdef, |
5256 | | bool olddef, |
5257 | | bfd *oldbfd, |
5258 | | const asection *oldsec) |
5259 | 0 | { |
5260 | | /* A normal common symbol and a large common symbol result in a |
5261 | | normal common symbol. We turn the large common symbol into a |
5262 | | normal one. */ |
5263 | 0 | if (!olddef |
5264 | 0 | && h->root.type == bfd_link_hash_common |
5265 | 0 | && !newdef |
5266 | 0 | && bfd_is_com_section (*psec) |
5267 | 0 | && oldsec != *psec) |
5268 | 0 | { |
5269 | 0 | if (sym->st_shndx == SHN_COMMON |
5270 | 0 | && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) != 0) |
5271 | 0 | { |
5272 | 0 | h->root.u.c.p->section |
5273 | 0 | = bfd_make_section_old_way (oldbfd, "COMMON"); |
5274 | 0 | h->root.u.c.p->section->flags = SEC_ALLOC; |
5275 | 0 | } |
5276 | 0 | else if (sym->st_shndx == SHN_X86_64_LCOMMON |
5277 | 0 | && (elf_section_flags (oldsec) & SHF_X86_64_LARGE) == 0) |
5278 | 0 | *psec = bfd_com_section_ptr; |
5279 | 0 | } |
5280 | |
|
5281 | 0 | return true; |
5282 | 0 | } |
5283 | | |
5284 | | static bool |
5285 | | elf_x86_64_section_flags (const Elf_Internal_Shdr *hdr) |
5286 | 25.1k | { |
5287 | 25.1k | if ((hdr->sh_flags & SHF_X86_64_LARGE) != 0) |
5288 | 281 | hdr->bfd_section->flags |= SEC_ELF_LARGE; |
5289 | | |
5290 | 25.1k | return true; |
5291 | 25.1k | } |
5292 | | |
5293 | | static bool |
5294 | | elf_x86_64_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, |
5295 | | Elf_Internal_Shdr *hdr, asection *sec) |
5296 | 0 | { |
5297 | 0 | if (sec->flags & SEC_ELF_LARGE) |
5298 | 0 | hdr->sh_flags |= SHF_X86_64_LARGE; |
5299 | |
|
5300 | 0 | return true; |
5301 | 0 | } |
5302 | | |
5303 | | static bool |
5304 | | elf_x86_64_copy_private_section_data (bfd *ibfd, asection *isec, |
5305 | | bfd *obfd, asection *osec) |
5306 | 0 | { |
5307 | 0 | if (!_bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec)) |
5308 | 0 | return false; |
5309 | | |
5310 | | /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE. */ |
5311 | 0 | if (ibfd != obfd) |
5312 | 0 | elf_section_flags (osec) &= ~SHF_X86_64_LARGE; |
5313 | |
|
5314 | 0 | return true; |
5315 | 0 | } |
5316 | | |
5317 | | static int |
5318 | | elf_x86_64_additional_program_headers (bfd *abfd, |
5319 | | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
5320 | 0 | { |
5321 | 0 | asection *s; |
5322 | 0 | int count = 0; |
5323 | | |
5324 | | /* Check to see if we need a large readonly segment. */ |
5325 | 0 | s = bfd_get_section_by_name (abfd, ".lrodata"); |
5326 | 0 | if (s && (s->flags & SEC_LOAD)) |
5327 | 0 | count++; |
5328 | | |
5329 | | /* Check to see if we need a large data segment. Since .lbss sections |
5330 | | is placed right after the .bss section, there should be no need for |
5331 | | a large data segment just because of .lbss. */ |
5332 | 0 | s = bfd_get_section_by_name (abfd, ".ldata"); |
5333 | 0 | if (s && (s->flags & SEC_LOAD)) |
5334 | 0 | count++; |
5335 | |
|
5336 | 0 | return count; |
5337 | 0 | } |
5338 | | |
5339 | | /* Return TRUE iff relocations for INPUT are compatible with OUTPUT. */ |
5340 | | |
5341 | | static bool |
5342 | | elf_x86_64_relocs_compatible (const bfd_target *input, |
5343 | | const bfd_target *output) |
5344 | 0 | { |
5345 | 0 | return ((xvec_get_elf_backend_data (input)->s->elfclass |
5346 | 0 | == xvec_get_elf_backend_data (output)->s->elfclass) |
5347 | 0 | && _bfd_elf_relocs_compatible (input, output)); |
5348 | 0 | } |
5349 | | |
5350 | | /* Set up x86-64 GNU properties. Return the first relocatable ELF input |
5351 | | with GNU properties if found. Otherwise, return NULL. */ |
5352 | | |
5353 | | static bfd * |
5354 | | elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info) |
5355 | 0 | { |
5356 | 0 | struct elf_x86_init_table init_table; |
5357 | 0 | const struct elf_backend_data *bed; |
5358 | 0 | struct elf_x86_link_hash_table *htab; |
5359 | |
|
5360 | 0 | if ((int) R_X86_64_standard >= (int) R_X86_64_converted_reloc_bit |
5361 | 0 | || (int) R_X86_64_max <= (int) R_X86_64_converted_reloc_bit |
5362 | 0 | || ((int) (R_X86_64_GNU_VTINHERIT | R_X86_64_converted_reloc_bit) |
5363 | 0 | != (int) R_X86_64_GNU_VTINHERIT) |
5364 | 0 | || ((int) (R_X86_64_GNU_VTENTRY | R_X86_64_converted_reloc_bit) |
5365 | 0 | != (int) R_X86_64_GNU_VTENTRY)) |
5366 | 0 | abort (); |
5367 | | |
5368 | | /* This is unused for x86-64. */ |
5369 | 0 | init_table.plt0_pad_byte = 0x90; |
5370 | |
|
5371 | 0 | bed = get_elf_backend_data (info->output_bfd); |
5372 | 0 | htab = elf_x86_hash_table (info, bed->target_id); |
5373 | 0 | if (!htab) |
5374 | 0 | abort (); |
5375 | | |
5376 | 0 | init_table.lazy_plt = &elf_x86_64_lazy_plt; |
5377 | 0 | init_table.non_lazy_plt = &elf_x86_64_non_lazy_plt; |
5378 | |
|
5379 | 0 | init_table.lazy_ibt_plt = &elf_x32_lazy_ibt_plt; |
5380 | 0 | init_table.non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt; |
5381 | |
|
5382 | 0 | if (ABI_64_P (info->output_bfd)) |
5383 | 0 | { |
5384 | 0 | init_table.sframe_lazy_plt = &elf_x86_64_sframe_plt; |
5385 | 0 | init_table.sframe_non_lazy_plt = &elf_x86_64_sframe_non_lazy_plt; |
5386 | 0 | init_table.sframe_lazy_ibt_plt = &elf_x86_64_sframe_plt; |
5387 | 0 | init_table.sframe_non_lazy_ibt_plt = &elf_x86_64_sframe_non_lazy_plt; |
5388 | 0 | } |
5389 | 0 | else |
5390 | 0 | { |
5391 | | /* SFrame is not supported for non AMD64. */ |
5392 | 0 | init_table.sframe_lazy_plt = NULL; |
5393 | 0 | init_table.sframe_non_lazy_plt = NULL; |
5394 | 0 | } |
5395 | |
|
5396 | 0 | if (ABI_64_P (info->output_bfd)) |
5397 | 0 | { |
5398 | 0 | init_table.r_info = elf64_r_info; |
5399 | 0 | init_table.r_sym = elf64_r_sym; |
5400 | 0 | } |
5401 | 0 | else |
5402 | 0 | { |
5403 | 0 | init_table.r_info = elf32_r_info; |
5404 | 0 | init_table.r_sym = elf32_r_sym; |
5405 | 0 | } |
5406 | |
|
5407 | 0 | return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table); |
5408 | 0 | } |
5409 | | |
5410 | | static const struct bfd_elf_special_section |
5411 | | elf_x86_64_special_sections[]= |
5412 | | { |
5413 | | { STRING_COMMA_LEN (".gnu.linkonce.lb"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, |
5414 | | { STRING_COMMA_LEN (".gnu.linkonce.lr"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE}, |
5415 | | { STRING_COMMA_LEN (".gnu.linkonce.lt"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR + SHF_X86_64_LARGE}, |
5416 | | { STRING_COMMA_LEN (".lbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, |
5417 | | { STRING_COMMA_LEN (".ldata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_X86_64_LARGE}, |
5418 | | { STRING_COMMA_LEN (".lrodata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_X86_64_LARGE}, |
5419 | | { NULL, 0, 0, 0, 0 } |
5420 | | }; |
5421 | | |
5422 | | #define TARGET_LITTLE_SYM x86_64_elf64_vec |
5423 | | #define TARGET_LITTLE_NAME "elf64-x86-64" |
5424 | | #define ELF_ARCH bfd_arch_i386 |
5425 | | #define ELF_TARGET_ID X86_64_ELF_DATA |
5426 | | #define ELF_MACHINE_CODE EM_X86_64 |
5427 | | #define ELF_MAXPAGESIZE 0x1000 |
5428 | | #define ELF_COMMONPAGESIZE 0x1000 |
5429 | | |
5430 | | #define elf_backend_can_gc_sections 1 |
5431 | | #define elf_backend_can_refcount 1 |
5432 | | #define elf_backend_want_got_plt 1 |
5433 | | #define elf_backend_plt_readonly 1 |
5434 | | #define elf_backend_want_plt_sym 0 |
5435 | | #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3) |
5436 | | #define elf_backend_rela_normal 1 |
5437 | | #define elf_backend_plt_alignment 4 |
5438 | | #define elf_backend_caches_rawsize 1 |
5439 | | #define elf_backend_dtrel_excludes_plt 1 |
5440 | | #define elf_backend_want_dynrelro 1 |
5441 | | |
5442 | | #define elf_info_to_howto elf_x86_64_info_to_howto |
5443 | | |
5444 | | #define bfd_elf64_bfd_copy_private_section_data \ |
5445 | | elf_x86_64_copy_private_section_data |
5446 | | #define bfd_elf64_bfd_reloc_type_lookup elf_x86_64_reloc_type_lookup |
5447 | | #define bfd_elf64_bfd_reloc_name_lookup \ |
5448 | | elf_x86_64_reloc_name_lookup |
5449 | | |
5450 | | #define elf_backend_relocs_compatible elf_x86_64_relocs_compatible |
5451 | | #define elf_backend_always_size_sections elf_x86_64_always_size_sections |
5452 | | #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections |
5453 | | #define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections |
5454 | | #define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol |
5455 | | #define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms |
5456 | | #define elf_backend_grok_prstatus elf_x86_64_grok_prstatus |
5457 | | #define elf_backend_grok_psinfo elf_x86_64_grok_psinfo |
5458 | | #ifdef CORE_HEADER |
5459 | | #define elf_backend_write_core_note elf_x86_64_write_core_note |
5460 | | #endif |
5461 | | #define elf_backend_reloc_type_class elf_x86_64_reloc_type_class |
5462 | | #define elf_backend_relocate_section elf_x86_64_relocate_section |
5463 | | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
5464 | | #define elf_backend_object_p elf64_x86_64_elf_object_p |
5465 | | #define bfd_elf64_get_synthetic_symtab elf_x86_64_get_synthetic_symtab |
5466 | | |
5467 | | #define elf_backend_section_from_shdr \ |
5468 | | elf_x86_64_section_from_shdr |
5469 | | |
5470 | | #define elf_backend_section_from_bfd_section \ |
5471 | | elf_x86_64_elf_section_from_bfd_section |
5472 | | #define elf_backend_add_symbol_hook \ |
5473 | | elf_x86_64_add_symbol_hook |
5474 | | #define elf_backend_symbol_processing \ |
5475 | | elf_x86_64_symbol_processing |
5476 | | #define elf_backend_common_section_index \ |
5477 | | elf_x86_64_common_section_index |
5478 | | #define elf_backend_common_section \ |
5479 | | elf_x86_64_common_section |
5480 | | #define elf_backend_common_definition \ |
5481 | | elf_x86_64_common_definition |
5482 | | #define elf_backend_merge_symbol \ |
5483 | | elf_x86_64_merge_symbol |
5484 | | #define elf_backend_special_sections \ |
5485 | | elf_x86_64_special_sections |
5486 | | #define elf_backend_section_flags elf_x86_64_section_flags |
5487 | | #define elf_backend_fake_sections elf_x86_64_fake_sections |
5488 | | #define elf_backend_additional_program_headers \ |
5489 | | elf_x86_64_additional_program_headers |
5490 | | #define elf_backend_setup_gnu_properties \ |
5491 | | elf_x86_64_link_setup_gnu_properties |
5492 | | #define elf_backend_hide_symbol \ |
5493 | | _bfd_x86_elf_hide_symbol |
5494 | | |
5495 | | #undef elf64_bed |
5496 | | #define elf64_bed elf64_x86_64_bed |
5497 | | |
5498 | | #include "elf64-target.h" |
5499 | | |
5500 | | /* CloudABI support. */ |
5501 | | |
5502 | | #undef TARGET_LITTLE_SYM |
5503 | | #define TARGET_LITTLE_SYM x86_64_elf64_cloudabi_vec |
5504 | | #undef TARGET_LITTLE_NAME |
5505 | | #define TARGET_LITTLE_NAME "elf64-x86-64-cloudabi" |
5506 | | |
5507 | | #undef ELF_OSABI |
5508 | | #define ELF_OSABI ELFOSABI_CLOUDABI |
5509 | | |
5510 | | #undef elf64_bed |
5511 | | #define elf64_bed elf64_x86_64_cloudabi_bed |
5512 | | |
5513 | | #include "elf64-target.h" |
5514 | | |
5515 | | /* FreeBSD support. */ |
5516 | | |
5517 | | #undef TARGET_LITTLE_SYM |
5518 | | #define TARGET_LITTLE_SYM x86_64_elf64_fbsd_vec |
5519 | | #undef TARGET_LITTLE_NAME |
5520 | | #define TARGET_LITTLE_NAME "elf64-x86-64-freebsd" |
5521 | | |
5522 | | #undef ELF_OSABI |
5523 | | #define ELF_OSABI ELFOSABI_FREEBSD |
5524 | | |
5525 | | #undef elf64_bed |
5526 | | #define elf64_bed elf64_x86_64_fbsd_bed |
5527 | | |
5528 | | #include "elf64-target.h" |
5529 | | |
5530 | | /* Solaris 2 support. */ |
5531 | | |
5532 | | #undef TARGET_LITTLE_SYM |
5533 | | #define TARGET_LITTLE_SYM x86_64_elf64_sol2_vec |
5534 | | #undef TARGET_LITTLE_NAME |
5535 | | #define TARGET_LITTLE_NAME "elf64-x86-64-sol2" |
5536 | | |
5537 | | #undef ELF_TARGET_OS |
5538 | | #define ELF_TARGET_OS is_solaris |
5539 | | |
5540 | | /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE |
5541 | | objects won't be recognized. */ |
5542 | | #undef ELF_OSABI |
5543 | | |
5544 | | #undef elf64_bed |
5545 | | #define elf64_bed elf64_x86_64_sol2_bed |
5546 | | |
5547 | | /* The 64-bit static TLS arena size is rounded to the nearest 16-byte |
5548 | | boundary. */ |
5549 | | #undef elf_backend_static_tls_alignment |
5550 | | #define elf_backend_static_tls_alignment 16 |
5551 | | |
5552 | | /* The Solaris 2 ABI requires a plt symbol on all platforms. |
5553 | | |
5554 | | Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output |
5555 | | File, p.63. */ |
5556 | | #undef elf_backend_want_plt_sym |
5557 | | #define elf_backend_want_plt_sym 1 |
5558 | | |
5559 | | #undef elf_backend_strtab_flags |
5560 | | #define elf_backend_strtab_flags SHF_STRINGS |
5561 | | |
5562 | | static bool |
5563 | | elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, |
5564 | | bfd *obfd ATTRIBUTE_UNUSED, |
5565 | | const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, |
5566 | | Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) |
5567 | 0 | { |
5568 | | /* PR 19938: FIXME: Need to add code for setting the sh_info |
5569 | | and sh_link fields of Solaris specific section types. */ |
5570 | 0 | return false; |
5571 | 0 | } |
5572 | | |
5573 | | #undef elf_backend_copy_special_section_fields |
5574 | | #define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields |
5575 | | |
5576 | | #include "elf64-target.h" |
5577 | | |
5578 | | /* Restore defaults. */ |
5579 | | #undef ELF_OSABI |
5580 | | #undef elf_backend_static_tls_alignment |
5581 | | #undef elf_backend_want_plt_sym |
5582 | | #define elf_backend_want_plt_sym 0 |
5583 | | #undef elf_backend_strtab_flags |
5584 | | #undef elf_backend_copy_special_section_fields |
5585 | | |
5586 | | /* 32bit x86-64 support. */ |
5587 | | |
5588 | | #undef TARGET_LITTLE_SYM |
5589 | | #define TARGET_LITTLE_SYM x86_64_elf32_vec |
5590 | | #undef TARGET_LITTLE_NAME |
5591 | | #define TARGET_LITTLE_NAME "elf32-x86-64" |
5592 | | #undef elf32_bed |
5593 | | #define elf32_bed elf32_x86_64_bed |
5594 | | |
5595 | | #undef ELF_ARCH |
5596 | | #define ELF_ARCH bfd_arch_i386 |
5597 | | |
5598 | | #undef ELF_MACHINE_CODE |
5599 | | #define ELF_MACHINE_CODE EM_X86_64 |
5600 | | |
5601 | | #undef ELF_TARGET_OS |
5602 | | #undef ELF_OSABI |
5603 | | |
5604 | | #define bfd_elf32_bfd_copy_private_section_data \ |
5605 | | elf_x86_64_copy_private_section_data |
5606 | | #define bfd_elf32_bfd_reloc_type_lookup \ |
5607 | | elf_x86_64_reloc_type_lookup |
5608 | | #define bfd_elf32_bfd_reloc_name_lookup \ |
5609 | | elf_x86_64_reloc_name_lookup |
5610 | | #define bfd_elf32_get_synthetic_symtab \ |
5611 | | elf_x86_64_get_synthetic_symtab |
5612 | | |
5613 | | #undef elf_backend_object_p |
5614 | | #define elf_backend_object_p \ |
5615 | | elf32_x86_64_elf_object_p |
5616 | | |
5617 | | #undef elf_backend_bfd_from_remote_memory |
5618 | | #define elf_backend_bfd_from_remote_memory \ |
5619 | | _bfd_elf32_bfd_from_remote_memory |
5620 | | |
5621 | | #undef elf_backend_size_info |
5622 | | #define elf_backend_size_info \ |
5623 | | _bfd_elf32_size_info |
5624 | | |
5625 | | #include "elf32-target.h" |