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