/src/binutils-gdb/bfd/coff-aarch64.c
Line | Count | Source |
1 | | /* BFD back-end for AArch64 COFF files. |
2 | | Copyright (C) 2021-2026 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of BFD, the Binary File Descriptor library. |
5 | | |
6 | | This program is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3 of the License, or |
9 | | (at your option) any later version. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with this program; if not, write to the Free Software |
18 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | | MA 02110-1301, USA. */ |
20 | | |
21 | | #ifndef COFF_WITH_PE |
22 | | #error non-PE COFF unsupported |
23 | | #endif |
24 | | |
25 | | #include "sysdep.h" |
26 | | #include "bfd.h" |
27 | | #include "libbfd.h" |
28 | | #include "coff/aarch64.h" |
29 | | #include "coff/internal.h" |
30 | | #include "coff/pe.h" |
31 | | #include "libcoff.h" |
32 | | #include "libiberty.h" |
33 | | |
34 | | /* For these howto special functions, |
35 | | output_bfd == NULL => final link, or objdump -W and other calls to |
36 | | bfd_simple_get_relocated_section_contents |
37 | | output_bfd != NULL && output_bfd != abfd => ld -r |
38 | | output_bfd != NULL && output_bfd == abfd => gas. |
39 | | FIXME: ld -r is punted to bfd_perform_relocation. This won't be |
40 | | correct for cases where the addend needs to be adjusted, eg. for |
41 | | relocations against section symbols, and the field is split because |
42 | | bfd_perform_relocation can't write addends to split relocation fields. */ |
43 | | |
44 | | static bfd_reloc_status_type |
45 | | coff_aarch64_rel21_reloc (bfd *abfd, |
46 | | arelent *reloc_entry, |
47 | | asymbol *symbol, |
48 | | void *data, |
49 | | asection *input_section, |
50 | | bfd *output_bfd, |
51 | | char **error_message ATTRIBUTE_UNUSED) |
52 | 1 | { |
53 | 1 | if (output_bfd != NULL && output_bfd != abfd) |
54 | 0 | return bfd_reloc_continue; |
55 | | |
56 | 1 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, |
57 | 1 | input_section, reloc_entry->address)) |
58 | 1 | return bfd_reloc_outofrange; |
59 | | |
60 | 0 | uint32_t op = bfd_getl32 (data + reloc_entry->address); |
61 | 0 | bfd_vma relocation = reloc_entry->addend; |
62 | 0 | bfd_reloc_status_type ret = bfd_reloc_ok; |
63 | 0 | if (output_bfd == NULL) |
64 | 0 | { |
65 | 0 | if (bfd_is_und_section (symbol->section)) |
66 | 0 | { |
67 | 0 | if ((symbol->flags & BSF_WEAK) == 0) |
68 | 0 | ret = bfd_reloc_undefined; |
69 | 0 | } |
70 | 0 | else if (!bfd_is_com_section (symbol->section)) |
71 | 0 | relocation += (symbol->value |
72 | 0 | + symbol->section->output_offset |
73 | 0 | + symbol->section->output_section->vma); |
74 | 0 | bfd_vma addend = ((op >> 3) & 0x1ffffc) | ((op >> 29) & 0x3); |
75 | 0 | addend = (addend ^ 0x100000) - 0x100000; |
76 | 0 | relocation += addend; |
77 | 0 | relocation -= (reloc_entry->address |
78 | 0 | + input_section->output_offset |
79 | 0 | + input_section->output_section->vma); |
80 | 0 | relocation = (bfd_signed_vma) relocation >> reloc_entry->howto->rightshift; |
81 | 0 | } |
82 | 0 | if (relocation + 0x100000 > 0x1fffff) |
83 | 0 | ret = bfd_reloc_overflow; |
84 | |
|
85 | 0 | op &= 0x9f00001f; |
86 | 0 | op |= (relocation & 0x1ffffc) << 3; |
87 | 0 | op |= (relocation & 0x3) << 29; |
88 | |
|
89 | 0 | bfd_putl32 (op, data + reloc_entry->address); |
90 | |
|
91 | 0 | return ret; |
92 | 1 | } pe-aarch64.c:coff_aarch64_rel21_reloc Line | Count | Source | 52 | 1 | { | 53 | 1 | if (output_bfd != NULL && output_bfd != abfd) | 54 | 0 | return bfd_reloc_continue; | 55 | | | 56 | 1 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, | 57 | 1 | input_section, reloc_entry->address)) | 58 | 1 | return bfd_reloc_outofrange; | 59 | | | 60 | 0 | uint32_t op = bfd_getl32 (data + reloc_entry->address); | 61 | 0 | bfd_vma relocation = reloc_entry->addend; | 62 | 0 | bfd_reloc_status_type ret = bfd_reloc_ok; | 63 | 0 | if (output_bfd == NULL) | 64 | 0 | { | 65 | 0 | if (bfd_is_und_section (symbol->section)) | 66 | 0 | { | 67 | 0 | if ((symbol->flags & BSF_WEAK) == 0) | 68 | 0 | ret = bfd_reloc_undefined; | 69 | 0 | } | 70 | 0 | else if (!bfd_is_com_section (symbol->section)) | 71 | 0 | relocation += (symbol->value | 72 | 0 | + symbol->section->output_offset | 73 | 0 | + symbol->section->output_section->vma); | 74 | 0 | bfd_vma addend = ((op >> 3) & 0x1ffffc) | ((op >> 29) & 0x3); | 75 | 0 | addend = (addend ^ 0x100000) - 0x100000; | 76 | 0 | relocation += addend; | 77 | 0 | relocation -= (reloc_entry->address | 78 | 0 | + input_section->output_offset | 79 | 0 | + input_section->output_section->vma); | 80 | 0 | relocation = (bfd_signed_vma) relocation >> reloc_entry->howto->rightshift; | 81 | 0 | } | 82 | 0 | if (relocation + 0x100000 > 0x1fffff) | 83 | 0 | ret = bfd_reloc_overflow; | 84 | |
| 85 | 0 | op &= 0x9f00001f; | 86 | 0 | op |= (relocation & 0x1ffffc) << 3; | 87 | 0 | op |= (relocation & 0x3) << 29; | 88 | |
| 89 | 0 | bfd_putl32 (op, data + reloc_entry->address); | 90 | |
| 91 | 0 | return ret; | 92 | 1 | } |
Unexecuted instantiation: pei-aarch64.c:coff_aarch64_rel21_reloc |
93 | | |
94 | | static bfd_reloc_status_type |
95 | | coff_aarch64_po12l_reloc (bfd *abfd, |
96 | | arelent *reloc_entry, |
97 | | asymbol *symbol ATTRIBUTE_UNUSED, |
98 | | void *data, |
99 | | asection *input_section, |
100 | | bfd *output_bfd, |
101 | | char **error_message ATTRIBUTE_UNUSED) |
102 | 0 | { |
103 | 0 | if (output_bfd != NULL && output_bfd != abfd) |
104 | 0 | return bfd_reloc_continue; |
105 | | |
106 | 0 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, |
107 | 0 | input_section, reloc_entry->address)) |
108 | 0 | return bfd_reloc_outofrange; |
109 | | |
110 | 0 | uint32_t op = bfd_getl32 (data + reloc_entry->address); |
111 | 0 | bfd_vma relocation = reloc_entry->addend & 0xfff; |
112 | 0 | int shift; |
113 | |
|
114 | 0 | if ((op & 0xff800000) == 0x3d800000) |
115 | 0 | { |
116 | | /* LDR / STR with q register */ |
117 | 0 | shift = 4; |
118 | 0 | } |
119 | 0 | else |
120 | 0 | { |
121 | | /* top two bits represent how much addend should be shifted */ |
122 | 0 | shift = op >> 30; |
123 | 0 | } |
124 | |
|
125 | 0 | bfd_reloc_status_type ret = bfd_reloc_ok; |
126 | 0 | if (output_bfd == NULL) |
127 | 0 | { |
128 | 0 | if (bfd_is_und_section (symbol->section)) |
129 | 0 | { |
130 | 0 | if ((symbol->flags & BSF_WEAK) == 0) |
131 | 0 | ret = bfd_reloc_undefined; |
132 | 0 | } |
133 | 0 | else if (!bfd_is_com_section (symbol->section)) |
134 | 0 | relocation += (symbol->value |
135 | 0 | + symbol->section->output_offset |
136 | 0 | + symbol->section->output_section->vma); |
137 | 0 | bfd_vma addend = (op >> 10) & 0xfff; |
138 | 0 | addend <<= shift; |
139 | 0 | relocation += addend; |
140 | 0 | } |
141 | |
|
142 | 0 | if (relocation & ((1 << shift) - 1)) |
143 | 0 | ret = bfd_reloc_overflow; |
144 | |
|
145 | 0 | op &= 0xffc003ff; |
146 | 0 | op |= (relocation >> shift << 10) & 0x3ffc00; |
147 | |
|
148 | 0 | bfd_putl32 (op, data + reloc_entry->address); |
149 | |
|
150 | 0 | return ret; |
151 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_po12l_reloc Unexecuted instantiation: pei-aarch64.c:coff_aarch64_po12l_reloc |
152 | | |
153 | | static bfd_reloc_status_type |
154 | | coff_aarch64_addr32nb_reloc (bfd *abfd, |
155 | | arelent *reloc_entry, |
156 | | asymbol *symbol ATTRIBUTE_UNUSED, |
157 | | void *data, |
158 | | asection *input_section, |
159 | | bfd *output_bfd, |
160 | | char **error_message) |
161 | 0 | { |
162 | 0 | if (output_bfd != NULL && output_bfd != abfd) |
163 | 0 | return bfd_reloc_continue; |
164 | | |
165 | 0 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, |
166 | 0 | input_section, reloc_entry->address)) |
167 | 0 | return bfd_reloc_outofrange; |
168 | | |
169 | 0 | bfd_vma relocation = reloc_entry->addend; |
170 | 0 | bfd_reloc_status_type ret = bfd_reloc_ok; |
171 | 0 | if (output_bfd == NULL) |
172 | 0 | { |
173 | 0 | if (bfd_is_und_section (symbol->section)) |
174 | 0 | { |
175 | 0 | if ((symbol->flags & BSF_WEAK) == 0) |
176 | 0 | ret = bfd_reloc_undefined; |
177 | 0 | } |
178 | 0 | else if (!bfd_is_com_section (symbol->section)) |
179 | 0 | relocation += (symbol->value |
180 | 0 | + symbol->section->output_offset |
181 | 0 | + symbol->section->output_section->vma); |
182 | 0 | bfd_vma addend = bfd_getl_signed_32 (data + reloc_entry->address); |
183 | 0 | relocation += addend; |
184 | 0 | bfd *obfd = input_section->output_section->owner; |
185 | 0 | if (bfd_get_flavour (obfd) == bfd_target_coff_flavour |
186 | 0 | && obj_pe (obfd)) |
187 | 0 | relocation -= pe_data (obfd)->pe_opthdr.ImageBase; |
188 | 0 | else |
189 | 0 | { |
190 | 0 | *error_message = "unsupported"; |
191 | 0 | return bfd_reloc_dangerous; |
192 | 0 | } |
193 | 0 | } |
194 | | |
195 | 0 | if (relocation + 0x80000000 > 0xffffffff) |
196 | 0 | ret = bfd_reloc_overflow; |
197 | |
|
198 | 0 | bfd_putl32 (relocation, data + reloc_entry->address); |
199 | |
|
200 | 0 | return ret; |
201 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_addr32nb_reloc Unexecuted instantiation: pei-aarch64.c:coff_aarch64_addr32nb_reloc |
202 | | |
203 | | static bfd_reloc_status_type |
204 | | coff_aarch64_secrel_reloc (bfd *abfd, |
205 | | arelent *reloc_entry, |
206 | | asymbol *symbol ATTRIBUTE_UNUSED, |
207 | | void *data, |
208 | | asection *input_section, |
209 | | bfd *output_bfd, |
210 | | char **error_message ATTRIBUTE_UNUSED) |
211 | 0 | { |
212 | 0 | if (output_bfd != NULL && output_bfd != abfd) |
213 | 0 | return bfd_reloc_continue; |
214 | | |
215 | 0 | if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, |
216 | 0 | input_section, reloc_entry->address)) |
217 | 0 | return bfd_reloc_outofrange; |
218 | | |
219 | 0 | bfd_vma relocation = reloc_entry->addend; |
220 | 0 | bfd_reloc_status_type ret = bfd_reloc_ok; |
221 | 0 | if (output_bfd == NULL) |
222 | 0 | { |
223 | 0 | if (bfd_is_und_section (symbol->section)) |
224 | 0 | { |
225 | 0 | if ((symbol->flags & BSF_WEAK) == 0) |
226 | 0 | ret = bfd_reloc_undefined; |
227 | 0 | } |
228 | 0 | else if (!bfd_is_com_section (symbol->section)) |
229 | 0 | relocation += (symbol->value |
230 | 0 | + symbol->section->output_offset); |
231 | 0 | bfd_vma addend = bfd_getl_signed_32 (data + reloc_entry->address); |
232 | 0 | relocation += addend; |
233 | 0 | } |
234 | 0 | if (relocation > 0xffffffff) |
235 | 0 | ret = bfd_reloc_overflow; |
236 | |
|
237 | 0 | bfd_putl32 (relocation, data + reloc_entry->address); |
238 | |
|
239 | 0 | return ret; |
240 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_secrel_reloc Unexecuted instantiation: pei-aarch64.c:coff_aarch64_secrel_reloc |
241 | | |
242 | | #define coff_aarch64_NULL NULL |
243 | | #undef HOWTO_INSTALL_ADDEND |
244 | | #define HOWTO_INSTALL_ADDEND 1 |
245 | | #define HOW(type, right, size, bits, pcrel, left, ovf, func, mask) \ |
246 | | HOWTO (type, right, size, bits, pcrel, left, complain_overflow_##ovf, \ |
247 | | coff_aarch64_##func, #type, true, mask, mask, false) |
248 | | |
249 | | static const reloc_howto_type arm64_reloc_howto_abs |
250 | | = HOW (IMAGE_REL_ARM64_ABSOLUTE, |
251 | | 0, 0, 0, false, 0, dont, NULL, 0); |
252 | | |
253 | | static const reloc_howto_type arm64_reloc_howto_64 |
254 | | = HOW (IMAGE_REL_ARM64_ADDR64, |
255 | | 0, 8, 64, false, 0, dont, NULL, UINT64_C (-1)); |
256 | | |
257 | | static const reloc_howto_type arm64_reloc_howto_32 |
258 | | = HOW (IMAGE_REL_ARM64_ADDR32, |
259 | | 0, 4, 32, false, 0, signed, NULL, 0xffffffff); |
260 | | |
261 | | static const reloc_howto_type arm64_reloc_howto_32_pcrel |
262 | | = HOW (IMAGE_REL_ARM64_REL32, |
263 | | 0, 4, 32, true, 0, signed, NULL, 0xffffffff); |
264 | | |
265 | | static const reloc_howto_type arm64_reloc_howto_branch26 |
266 | | = HOW (IMAGE_REL_ARM64_BRANCH26, |
267 | | 2, 4, 26, true, 0, signed, NULL, 0x3ffffff); |
268 | | |
269 | | static const reloc_howto_type arm64_reloc_howto_page21 |
270 | | = HOW (IMAGE_REL_ARM64_PAGEBASE_REL21, |
271 | | 12, 4, 21, true, 0, signed, rel21_reloc, 0x1fffff); |
272 | | |
273 | | static const reloc_howto_type arm64_reloc_howto_lo21 |
274 | | = HOW (IMAGE_REL_ARM64_REL21, |
275 | | 0, 4, 21, true, 0, signed, rel21_reloc, 0x1fffff); |
276 | | |
277 | | static const reloc_howto_type arm64_reloc_howto_pgoff12l |
278 | | = HOW (IMAGE_REL_ARM64_PAGEOFFSET_12L, |
279 | | 0, 4, 12, true, 10, signed, po12l_reloc, 0x3ffc00); |
280 | | |
281 | | static const reloc_howto_type arm64_reloc_howto_branch19 |
282 | | = HOW (IMAGE_REL_ARM64_BRANCH19, |
283 | | 2, 4, 19, true, 5, signed, NULL, 0xffffe0); |
284 | | |
285 | | static const reloc_howto_type arm64_reloc_howto_branch14 |
286 | | = HOW (IMAGE_REL_ARM64_BRANCH14, |
287 | | 2, 4, 14, true, 5, signed, NULL, 0x7ffe0); |
288 | | |
289 | | static const reloc_howto_type arm64_reloc_howto_pgoff12a |
290 | | = HOW (IMAGE_REL_ARM64_PAGEOFFSET_12A, |
291 | | 0, 4, 12, true, 10, dont, NULL, 0x3ffc00); |
292 | | |
293 | | static const reloc_howto_type arm64_reloc_howto_32nb |
294 | | = HOW (IMAGE_REL_ARM64_ADDR32NB, |
295 | | 0, 4, 32, false, 0, signed, addr32nb_reloc, 0xffffffff); |
296 | | |
297 | | static const reloc_howto_type arm64_reloc_howto_secrel |
298 | | = HOW (IMAGE_REL_ARM64_SECREL, |
299 | | 0, 4, 32, false, 0, dont, secrel_reloc, 0xffffffff); |
300 | | |
301 | | static const reloc_howto_type arm64_reloc_howto_secidx |
302 | | = HOW (IMAGE_REL_ARM64_SECTION, |
303 | | 0, 2, 16, false, 0, dont, NULL, 0xffff); |
304 | | |
305 | | static const reloc_howto_type* const arm64_howto_table[] = { |
306 | | &arm64_reloc_howto_abs, |
307 | | &arm64_reloc_howto_64, |
308 | | &arm64_reloc_howto_32, |
309 | | &arm64_reloc_howto_32_pcrel, |
310 | | &arm64_reloc_howto_branch26, |
311 | | &arm64_reloc_howto_page21, |
312 | | &arm64_reloc_howto_lo21, |
313 | | &arm64_reloc_howto_pgoff12l, |
314 | | &arm64_reloc_howto_branch19, |
315 | | &arm64_reloc_howto_branch14, |
316 | | &arm64_reloc_howto_pgoff12a, |
317 | | &arm64_reloc_howto_32nb, |
318 | | &arm64_reloc_howto_secrel, |
319 | | &arm64_reloc_howto_secidx |
320 | | }; |
321 | | |
322 | | /* No adjustment to addends should be needed. The actual relocation |
323 | | addend is in the section contents. Unfortunately this means actual |
324 | | addends are not shown by objdump -r, but that's true for most |
325 | | COFF/PE targets where arelent.addend is an adjustment. */ |
326 | | #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \ |
327 | 4.14k | cache_ptr->addend = 0; |
328 | | |
329 | | #ifndef NUM_ELEM |
330 | 0 | #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0])) |
331 | | #endif |
332 | | |
333 | 0 | #define NUM_RELOCS NUM_ELEM (arm64_howto_table) |
334 | | |
335 | | #define coff_bfd_reloc_type_lookup coff_aarch64_reloc_type_lookup |
336 | | #define coff_bfd_reloc_name_lookup coff_aarch64_reloc_name_lookup |
337 | | |
338 | | static reloc_howto_type * |
339 | | coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) |
340 | 236 | { |
341 | 236 | switch (code) |
342 | 236 | { |
343 | 0 | case BFD_RELOC_64: |
344 | 0 | return &arm64_reloc_howto_64; |
345 | 56 | case BFD_RELOC_32: |
346 | 56 | return &arm64_reloc_howto_32; |
347 | 0 | case BFD_RELOC_32_PCREL: |
348 | 0 | return &arm64_reloc_howto_32_pcrel; |
349 | 0 | case BFD_RELOC_AARCH64_CALL26: |
350 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
351 | 0 | return &arm64_reloc_howto_branch26; |
352 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
353 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
354 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
355 | 0 | return &arm64_reloc_howto_page21; |
356 | 0 | case BFD_RELOC_AARCH64_TSTBR14: |
357 | 0 | return &arm64_reloc_howto_branch14; |
358 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
359 | 0 | return &arm64_reloc_howto_lo21; |
360 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
361 | 0 | return &arm64_reloc_howto_pgoff12a; |
362 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: |
363 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: |
364 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: |
365 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: |
366 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: |
367 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
368 | 0 | return &arm64_reloc_howto_pgoff12l; |
369 | 0 | case BFD_RELOC_AARCH64_BRANCH19: |
370 | 0 | return &arm64_reloc_howto_branch19; |
371 | 180 | case BFD_RELOC_RVA: |
372 | 180 | return &arm64_reloc_howto_32nb; |
373 | 0 | case BFD_RELOC_32_SECREL: |
374 | 0 | return &arm64_reloc_howto_secrel; |
375 | 0 | case BFD_RELOC_16_SECIDX: |
376 | 0 | return &arm64_reloc_howto_secidx; |
377 | 0 | default: |
378 | 0 | BFD_FAIL (); |
379 | 0 | return NULL; |
380 | 236 | } |
381 | | |
382 | 0 | return NULL; |
383 | 236 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_reloc_type_lookup pei-aarch64.c:coff_aarch64_reloc_type_lookup Line | Count | Source | 340 | 236 | { | 341 | 236 | switch (code) | 342 | 236 | { | 343 | 0 | case BFD_RELOC_64: | 344 | 0 | return &arm64_reloc_howto_64; | 345 | 56 | case BFD_RELOC_32: | 346 | 56 | return &arm64_reloc_howto_32; | 347 | 0 | case BFD_RELOC_32_PCREL: | 348 | 0 | return &arm64_reloc_howto_32_pcrel; | 349 | 0 | case BFD_RELOC_AARCH64_CALL26: | 350 | 0 | case BFD_RELOC_AARCH64_JUMP26: | 351 | 0 | return &arm64_reloc_howto_branch26; | 352 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | 353 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: | 354 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: | 355 | 0 | return &arm64_reloc_howto_page21; | 356 | 0 | case BFD_RELOC_AARCH64_TSTBR14: | 357 | 0 | return &arm64_reloc_howto_branch14; | 358 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: | 359 | 0 | return &arm64_reloc_howto_lo21; | 360 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: | 361 | 0 | return &arm64_reloc_howto_pgoff12a; | 362 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: | 363 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: | 364 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: | 365 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: | 366 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: | 367 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: | 368 | 0 | return &arm64_reloc_howto_pgoff12l; | 369 | 0 | case BFD_RELOC_AARCH64_BRANCH19: | 370 | 0 | return &arm64_reloc_howto_branch19; | 371 | 180 | case BFD_RELOC_RVA: | 372 | 180 | return &arm64_reloc_howto_32nb; | 373 | 0 | case BFD_RELOC_32_SECREL: | 374 | 0 | return &arm64_reloc_howto_secrel; | 375 | 0 | case BFD_RELOC_16_SECIDX: | 376 | 0 | return &arm64_reloc_howto_secidx; | 377 | 0 | default: | 378 | 0 | BFD_FAIL (); | 379 | 0 | return NULL; | 380 | 236 | } | 381 | | | 382 | 0 | return NULL; | 383 | 236 | } |
|
384 | | |
385 | | static reloc_howto_type * |
386 | | coff_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
387 | | const char *r_name) |
388 | 0 | { |
389 | 0 | unsigned int i; |
390 | |
|
391 | 0 | for (i = 0; i < NUM_RELOCS; i++) |
392 | 0 | if (arm64_howto_table[i]->name != NULL |
393 | 0 | && strcasecmp (arm64_howto_table[i]->name, r_name) == 0) |
394 | 0 | return arm64_howto_table[i]; |
395 | | |
396 | 0 | return NULL; |
397 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_reloc_name_lookup Unexecuted instantiation: pei-aarch64.c:coff_aarch64_reloc_name_lookup |
398 | | |
399 | 237k | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
400 | 388 | #define COFF_PAGE_SIZE 0x1000 |
401 | | |
402 | | static reloc_howto_type * |
403 | | coff_aarch64_rtype_lookup (unsigned int code) |
404 | 4.14k | { |
405 | 4.14k | switch (code) |
406 | 4.14k | { |
407 | 2.84k | case IMAGE_REL_ARM64_ABSOLUTE: |
408 | 2.84k | return &arm64_reloc_howto_abs; |
409 | 11 | case IMAGE_REL_ARM64_ADDR64: |
410 | 11 | return &arm64_reloc_howto_64; |
411 | 124 | case IMAGE_REL_ARM64_ADDR32: |
412 | 124 | return &arm64_reloc_howto_32; |
413 | 12 | case IMAGE_REL_ARM64_REL32: |
414 | 12 | return &arm64_reloc_howto_32_pcrel; |
415 | 87 | case IMAGE_REL_ARM64_BRANCH26: |
416 | 87 | return &arm64_reloc_howto_branch26; |
417 | 41 | case IMAGE_REL_ARM64_PAGEBASE_REL21: |
418 | 41 | return &arm64_reloc_howto_page21; |
419 | 47 | case IMAGE_REL_ARM64_REL21: |
420 | 47 | return &arm64_reloc_howto_lo21; |
421 | 16 | case IMAGE_REL_ARM64_PAGEOFFSET_12L: |
422 | 16 | return &arm64_reloc_howto_pgoff12l; |
423 | 15 | case IMAGE_REL_ARM64_BRANCH19: |
424 | 15 | return &arm64_reloc_howto_branch19; |
425 | 87 | case IMAGE_REL_ARM64_BRANCH14: |
426 | 87 | return &arm64_reloc_howto_branch14; |
427 | 13 | case IMAGE_REL_ARM64_PAGEOFFSET_12A: |
428 | 13 | return &arm64_reloc_howto_pgoff12a; |
429 | 92 | case IMAGE_REL_ARM64_ADDR32NB: |
430 | 92 | return &arm64_reloc_howto_32nb; |
431 | 177 | case IMAGE_REL_ARM64_SECREL: |
432 | 177 | return &arm64_reloc_howto_secrel; |
433 | 17 | case IMAGE_REL_ARM64_SECTION: |
434 | 17 | return &arm64_reloc_howto_secidx; |
435 | 562 | default: |
436 | 562 | return NULL; |
437 | 4.14k | } |
438 | | |
439 | 0 | return NULL; |
440 | 4.14k | } pe-aarch64.c:coff_aarch64_rtype_lookup Line | Count | Source | 404 | 4.14k | { | 405 | 4.14k | switch (code) | 406 | 4.14k | { | 407 | 2.84k | case IMAGE_REL_ARM64_ABSOLUTE: | 408 | 2.84k | return &arm64_reloc_howto_abs; | 409 | 11 | case IMAGE_REL_ARM64_ADDR64: | 410 | 11 | return &arm64_reloc_howto_64; | 411 | 124 | case IMAGE_REL_ARM64_ADDR32: | 412 | 124 | return &arm64_reloc_howto_32; | 413 | 12 | case IMAGE_REL_ARM64_REL32: | 414 | 12 | return &arm64_reloc_howto_32_pcrel; | 415 | 87 | case IMAGE_REL_ARM64_BRANCH26: | 416 | 87 | return &arm64_reloc_howto_branch26; | 417 | 41 | case IMAGE_REL_ARM64_PAGEBASE_REL21: | 418 | 41 | return &arm64_reloc_howto_page21; | 419 | 47 | case IMAGE_REL_ARM64_REL21: | 420 | 47 | return &arm64_reloc_howto_lo21; | 421 | 16 | case IMAGE_REL_ARM64_PAGEOFFSET_12L: | 422 | 16 | return &arm64_reloc_howto_pgoff12l; | 423 | 15 | case IMAGE_REL_ARM64_BRANCH19: | 424 | 15 | return &arm64_reloc_howto_branch19; | 425 | 87 | case IMAGE_REL_ARM64_BRANCH14: | 426 | 87 | return &arm64_reloc_howto_branch14; | 427 | 13 | case IMAGE_REL_ARM64_PAGEOFFSET_12A: | 428 | 13 | return &arm64_reloc_howto_pgoff12a; | 429 | 92 | case IMAGE_REL_ARM64_ADDR32NB: | 430 | 92 | return &arm64_reloc_howto_32nb; | 431 | 177 | case IMAGE_REL_ARM64_SECREL: | 432 | 177 | return &arm64_reloc_howto_secrel; | 433 | 17 | case IMAGE_REL_ARM64_SECTION: | 434 | 17 | return &arm64_reloc_howto_secidx; | 435 | 562 | default: | 436 | 562 | return NULL; | 437 | 4.14k | } | 438 | | | 439 | 0 | return NULL; | 440 | 4.14k | } |
Unexecuted instantiation: pei-aarch64.c:coff_aarch64_rtype_lookup |
441 | | |
442 | | #define RTYPE2HOWTO(cache_ptr, dst) \ |
443 | 4.14k | ((cache_ptr)->howto = coff_aarch64_rtype_lookup((dst)->r_type)) |
444 | | |
445 | | static reloc_howto_type * |
446 | | coff_aarch64_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, |
447 | | asection *sec ATTRIBUTE_UNUSED, |
448 | | struct internal_reloc *rel, |
449 | | struct coff_link_hash_entry *h ATTRIBUTE_UNUSED, |
450 | | struct internal_syment *sym ATTRIBUTE_UNUSED, |
451 | | bfd_vma *addendp) |
452 | 0 | { |
453 | 0 | reloc_howto_type *howto = coff_aarch64_rtype_lookup (rel->r_type); |
454 | | |
455 | | /* Cancel out code in _bfd_coff_generic_relocate_section. */ |
456 | 0 | *addendp = 0; |
457 | |
|
458 | 0 | return howto; |
459 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_aarch64_rtype_to_howto Unexecuted instantiation: pei-aarch64.c:coff_aarch64_rtype_to_howto |
460 | | |
461 | | #define coff_rtype_to_howto coff_aarch64_rtype_to_howto |
462 | | |
463 | 17 | #define SELECT_RELOC(x,howto) { (x).r_type = (howto)->type; } |
464 | | |
465 | | #ifndef bfd_pe_print_pdata |
466 | | #define bfd_pe_print_pdata NULL |
467 | | #endif |
468 | | |
469 | | #ifdef COFF_WITH_PE |
470 | | /* Return TRUE if this relocation should |
471 | | appear in the output .reloc section. */ |
472 | | |
473 | | static bool |
474 | | in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, |
475 | | reloc_howto_type * howto) |
476 | 0 | { |
477 | 0 | return !howto->pc_relative |
478 | 0 | && howto->type != IMAGE_REL_ARM64_ABSOLUTE |
479 | 0 | && howto->type != IMAGE_REL_ARM64_ADDR32NB |
480 | 0 | && howto->type != IMAGE_REL_ARM64_SECREL |
481 | 0 | && howto->type != IMAGE_REL_ARM64_SECREL_LOW12L |
482 | 0 | && howto->type != IMAGE_REL_ARM64_SECTION; |
483 | 0 | } Unexecuted instantiation: pe-aarch64.c:in_reloc_p Unexecuted instantiation: pei-aarch64.c:in_reloc_p |
484 | | #endif |
485 | | |
486 | | static bool |
487 | | coff_pe_aarch64_relocate_section (bfd *output_bfd, |
488 | | struct bfd_link_info *info, |
489 | | bfd *input_bfd, |
490 | | asection *input_section, |
491 | | bfd_byte *contents, |
492 | | struct internal_reloc *relocs, |
493 | | struct internal_syment *syms, |
494 | | asection **sections) |
495 | 0 | { |
496 | 0 | struct internal_reloc *rel; |
497 | 0 | struct internal_reloc *relend; |
498 | |
|
499 | 0 | if (bfd_link_relocatable (info)) |
500 | 0 | return true; |
501 | | |
502 | 0 | rel = relocs; |
503 | 0 | relend = rel + input_section->reloc_count; |
504 | | |
505 | | /* The addend for a relocation is stored in the immediate bits of each |
506 | | opcode. So for each relocation, we need to extract the immediate value, |
507 | | use this to calculate what it should be for the symbol, and rewrite the |
508 | | opcode into the section stream. */ |
509 | |
|
510 | 0 | for (; rel < relend; rel++) |
511 | 0 | { |
512 | 0 | long symndx; |
513 | 0 | struct coff_link_hash_entry *h; |
514 | 0 | bfd_vma sym_value; |
515 | 0 | asection *sec = NULL; |
516 | 0 | uint64_t dest_vma; |
517 | | |
518 | | /* skip trivial relocations */ |
519 | 0 | if (rel->r_type == IMAGE_REL_ARM64_ADDR32 |
520 | 0 | || rel->r_type == IMAGE_REL_ARM64_ADDR64 |
521 | 0 | || rel->r_type == IMAGE_REL_ARM64_ABSOLUTE) |
522 | 0 | continue; |
523 | | |
524 | 0 | symndx = rel->r_symndx; |
525 | |
|
526 | 0 | if (! coff_symndx_in_range (input_bfd, symndx)) |
527 | 0 | { |
528 | 0 | _bfd_error_handler |
529 | | /* xgettext: c-format */ |
530 | 0 | (_("%pB: invalid symbol index %ld in relocs"), |
531 | 0 | input_bfd, symndx); |
532 | 0 | bfd_set_error (bfd_error_bad_value); |
533 | 0 | return false; |
534 | 0 | } |
535 | | |
536 | 0 | sym_value = syms[symndx].n_value; |
537 | |
|
538 | 0 | h = obj_coff_sym_hashes (input_bfd)[symndx]; |
539 | |
|
540 | 0 | if (h && h->root.type == bfd_link_hash_defweak) |
541 | 0 | switch (rel->r_type) |
542 | 0 | { |
543 | 0 | case IMAGE_REL_ARM64_PAGEOFFSET_12A: |
544 | 0 | case IMAGE_REL_ARM64_PAGEOFFSET_12L: |
545 | 0 | { |
546 | 0 | rel->r_ignore = 1; |
547 | 0 | continue; |
548 | 0 | } |
549 | 0 | case IMAGE_REL_ARM64_BRANCH26: |
550 | 0 | { |
551 | 0 | const unsigned char prefix_length = sizeof("__imp_") - 1; |
552 | 0 | h = (struct coff_link_hash_entry*) |
553 | 0 | bfd_link_hash_lookup (info->hash, h->root.root.string |
554 | 0 | + prefix_length, 0, 0, 1); |
555 | 0 | break; |
556 | 0 | } |
557 | 0 | case IMAGE_REL_ARM64_PAGEBASE_REL21: |
558 | 0 | { |
559 | 0 | uint32_t opcode = 0x14000000; /* b <label>. */ |
560 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
561 | 0 | rel->r_type = IMAGE_REL_ARM64_BRANCH26; |
562 | |
|
563 | 0 | char* imp_label = xasprintf("%s_%x_%lx", h->root.root.string, |
564 | 0 | input_section->id, |
565 | 0 | (long unsigned) rel->r_vaddr); |
566 | 0 | h = (struct coff_link_hash_entry*) |
567 | 0 | bfd_link_hash_lookup (info->hash, imp_label, 0, 0, 1); |
568 | 0 | free(imp_label); |
569 | 0 | break; |
570 | 0 | } |
571 | 0 | } |
572 | | |
573 | 0 | if (h && h->root.type == bfd_link_hash_defined) |
574 | 0 | { |
575 | 0 | sec = h->root.u.def.section; |
576 | 0 | sym_value = h->root.u.def.value; |
577 | 0 | } |
578 | 0 | else |
579 | 0 | { |
580 | 0 | sec = sections[symndx]; |
581 | 0 | } |
582 | |
|
583 | 0 | if (!sec) |
584 | 0 | continue; |
585 | | |
586 | 0 | if (bfd_is_und_section (sec)) |
587 | 0 | continue; |
588 | | |
589 | 0 | if (discarded_section (sec)) |
590 | 0 | continue; |
591 | | |
592 | 0 | dest_vma = sec->output_section->vma + sec->output_offset + sym_value; |
593 | | |
594 | | /* All the relocs handled below operate on 4 bytes. */ |
595 | 0 | if (input_section->size < rel->r_vaddr |
596 | 0 | || input_section->size - rel->r_vaddr < 4) |
597 | 0 | { |
598 | 0 | _bfd_error_handler |
599 | | /* xgettext: c-format */ |
600 | 0 | (_("%pB: bad reloc address %#" PRIx64 " in section `%pA'"), |
601 | 0 | input_bfd, (uint64_t) rel->r_vaddr, input_section); |
602 | 0 | continue; |
603 | 0 | } |
604 | | |
605 | 0 | switch (rel->r_type) |
606 | 0 | { |
607 | 0 | case IMAGE_REL_ARM64_ADDR32NB: |
608 | 0 | { |
609 | 0 | uint64_t val; |
610 | 0 | int32_t addend; |
611 | |
|
612 | 0 | addend = bfd_getl32 (contents + rel->r_vaddr); |
613 | |
|
614 | 0 | dest_vma += addend; |
615 | |
|
616 | 0 | val = dest_vma; |
617 | 0 | val -= pe_data (output_bfd)->pe_opthdr.ImageBase; |
618 | |
|
619 | 0 | if (val > 0xffffffff) |
620 | 0 | (*info->callbacks->reloc_overflow) |
621 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
622 | 0 | "IMAGE_REL_ARM64_ADDR32NB", addend, input_bfd, |
623 | 0 | input_section, rel->r_vaddr - input_section->vma); |
624 | |
|
625 | 0 | bfd_putl32 (val, contents + rel->r_vaddr); |
626 | 0 | rel->r_ignore = 1; |
627 | |
|
628 | 0 | break; |
629 | 0 | } |
630 | | |
631 | 0 | case IMAGE_REL_ARM64_BRANCH26: |
632 | 0 | { |
633 | 0 | uint64_t cur_vma; |
634 | 0 | uint32_t opcode; |
635 | 0 | int64_t addend, val; |
636 | |
|
637 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
638 | |
|
639 | 0 | addend = (opcode & 0x3ffffff) << 2; |
640 | |
|
641 | 0 | if (addend & 0x8000000) |
642 | 0 | addend |= 0xfffffffff0000000; |
643 | |
|
644 | 0 | dest_vma += addend; |
645 | 0 | cur_vma = input_section->output_section->vma |
646 | 0 | + input_section->output_offset |
647 | 0 | + rel->r_vaddr; |
648 | |
|
649 | 0 | val = (dest_vma >> 2) - (cur_vma >> 2); |
650 | |
|
651 | 0 | if (val > 0x1ffffff || val < -0x2000000) |
652 | 0 | (*info->callbacks->reloc_overflow) |
653 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
654 | 0 | "IMAGE_REL_ARM64_BRANCH26", addend, input_bfd, |
655 | 0 | input_section, rel->r_vaddr - input_section->vma); |
656 | |
|
657 | 0 | opcode &= 0xfc000000; |
658 | 0 | opcode |= val & 0x3ffffff; |
659 | |
|
660 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
661 | 0 | rel->r_ignore = 1; |
662 | |
|
663 | 0 | break; |
664 | 0 | } |
665 | | |
666 | 0 | case IMAGE_REL_ARM64_BRANCH19: |
667 | 0 | { |
668 | 0 | uint64_t cur_vma; |
669 | 0 | uint32_t opcode; |
670 | 0 | int64_t addend, val; |
671 | |
|
672 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
673 | |
|
674 | 0 | addend = (opcode & 0xffffe0) >> 3; |
675 | |
|
676 | 0 | if (addend & 0x100000) |
677 | 0 | addend |= 0xffffffffffe00000; |
678 | |
|
679 | 0 | dest_vma += addend; |
680 | 0 | cur_vma = input_section->output_section->vma |
681 | 0 | + input_section->output_offset |
682 | 0 | + rel->r_vaddr; |
683 | |
|
684 | 0 | val = (dest_vma >> 2) - (cur_vma >> 2); |
685 | |
|
686 | 0 | if (val > 0x3ffff || val < -0x40000) |
687 | 0 | (*info->callbacks->reloc_overflow) |
688 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
689 | 0 | "IMAGE_REL_ARM64_BRANCH19", addend, input_bfd, |
690 | 0 | input_section, rel->r_vaddr - input_section->vma); |
691 | |
|
692 | 0 | opcode &= 0xff00001f; |
693 | 0 | opcode |= (val & 0x7ffff) << 5; |
694 | |
|
695 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
696 | 0 | rel->r_ignore = 1; |
697 | |
|
698 | 0 | break; |
699 | 0 | } |
700 | | |
701 | 0 | case IMAGE_REL_ARM64_BRANCH14: |
702 | 0 | { |
703 | 0 | uint64_t cur_vma; |
704 | 0 | uint32_t opcode; |
705 | 0 | int64_t addend, val; |
706 | |
|
707 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
708 | |
|
709 | 0 | addend = (opcode & 0x7ffe0) >> 3; |
710 | |
|
711 | 0 | if (addend & 0x8000) |
712 | 0 | addend |= 0xffffffffffff0000; |
713 | |
|
714 | 0 | dest_vma += addend; |
715 | 0 | cur_vma = input_section->output_section->vma |
716 | 0 | + input_section->output_offset |
717 | 0 | + rel->r_vaddr; |
718 | |
|
719 | 0 | val = (dest_vma >> 2) - (cur_vma >> 2); |
720 | |
|
721 | 0 | if (val > 0x1fff || val < -0x2000) |
722 | 0 | (*info->callbacks->reloc_overflow) |
723 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
724 | 0 | "IMAGE_REL_ARM64_BRANCH14", addend, input_bfd, |
725 | 0 | input_section, rel->r_vaddr - input_section->vma); |
726 | |
|
727 | 0 | opcode &= 0xfff8001f; |
728 | 0 | opcode |= (val & 0x3fff) << 5; |
729 | |
|
730 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
731 | 0 | rel->r_ignore = 1; |
732 | |
|
733 | 0 | break; |
734 | 0 | } |
735 | | |
736 | 0 | case IMAGE_REL_ARM64_PAGEBASE_REL21: |
737 | 0 | { |
738 | 0 | uint64_t cur_vma; |
739 | 0 | uint32_t opcode; |
740 | 0 | int64_t addend, val; |
741 | |
|
742 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
743 | |
|
744 | 0 | addend = ((opcode & 0xffffe0) >> 3) |
745 | 0 | | ((opcode & 0x60000000) >> 29); |
746 | |
|
747 | 0 | if (addend & 0x100000) |
748 | 0 | addend |= 0xffffffffffe00000; |
749 | |
|
750 | 0 | dest_vma += addend; |
751 | 0 | cur_vma = input_section->output_section->vma |
752 | 0 | + input_section->output_offset |
753 | 0 | + rel->r_vaddr; |
754 | |
|
755 | 0 | val = (dest_vma >> 12) - (cur_vma >> 12); |
756 | |
|
757 | 0 | if (val > 0xfffff || val < -0x100000) |
758 | 0 | (*info->callbacks->reloc_overflow) |
759 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
760 | 0 | "IMAGE_REL_ARM64_PAGEBASE_REL21", addend, input_bfd, |
761 | 0 | input_section, rel->r_vaddr - input_section->vma); |
762 | |
|
763 | 0 | opcode &= 0x9f00001f; |
764 | 0 | opcode |= (val & 0x3) << 29; |
765 | 0 | opcode |= (val & 0x1ffffc) << 3; |
766 | |
|
767 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
768 | 0 | rel->r_ignore = 1; |
769 | |
|
770 | 0 | break; |
771 | 0 | } |
772 | | |
773 | 0 | case IMAGE_REL_ARM64_REL21: |
774 | 0 | { |
775 | 0 | uint64_t cur_vma; |
776 | 0 | uint32_t opcode; |
777 | 0 | int64_t addend, val; |
778 | |
|
779 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
780 | |
|
781 | 0 | addend = ((opcode & 0xffffe0) >> 3) |
782 | 0 | | ((opcode & 0x60000000) >> 29); |
783 | |
|
784 | 0 | if (addend & 0x100000) |
785 | 0 | addend |= 0xffffffffffe00000; |
786 | |
|
787 | 0 | dest_vma += addend; |
788 | 0 | cur_vma = input_section->output_section->vma |
789 | 0 | + input_section->output_offset |
790 | 0 | + rel->r_vaddr; |
791 | |
|
792 | 0 | val = dest_vma - cur_vma; |
793 | |
|
794 | 0 | if (val > 0xfffff || val < -0x100000) |
795 | 0 | (*info->callbacks->reloc_overflow) |
796 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
797 | 0 | "IMAGE_REL_ARM64_REL21", addend, input_bfd, |
798 | 0 | input_section, rel->r_vaddr - input_section->vma); |
799 | |
|
800 | 0 | opcode &= 0x9f00001f; |
801 | 0 | opcode |= (val & 0x3) << 29; |
802 | 0 | opcode |= (val & 0x1ffffc) << 3; |
803 | |
|
804 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
805 | 0 | rel->r_ignore = 1; |
806 | |
|
807 | 0 | break; |
808 | 0 | } |
809 | | |
810 | 0 | case IMAGE_REL_ARM64_REL32: |
811 | 0 | { |
812 | 0 | uint64_t cur_vma; |
813 | 0 | int64_t addend, val; |
814 | |
|
815 | 0 | addend = bfd_getl32 (contents + rel->r_vaddr); |
816 | |
|
817 | 0 | if (addend & 0x80000000) |
818 | 0 | addend |= 0xffffffff00000000; |
819 | |
|
820 | 0 | dest_vma += addend; |
821 | 0 | cur_vma = input_section->output_section->vma |
822 | 0 | + input_section->output_offset |
823 | 0 | + rel->r_vaddr; |
824 | |
|
825 | 0 | val = dest_vma - cur_vma; |
826 | |
|
827 | 0 | if (val > 0xffffffff || val < -0x100000000) |
828 | 0 | (*info->callbacks->reloc_overflow) |
829 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
830 | 0 | "IMAGE_REL_ARM64_REL32", addend, input_bfd, |
831 | 0 | input_section, rel->r_vaddr - input_section->vma); |
832 | |
|
833 | 0 | bfd_putl32 (val, contents + rel->r_vaddr); |
834 | 0 | rel->r_ignore = 1; |
835 | |
|
836 | 0 | break; |
837 | 0 | } |
838 | | |
839 | 0 | case IMAGE_REL_ARM64_PAGEOFFSET_12L: |
840 | 0 | { |
841 | 0 | uint32_t opcode, val; |
842 | 0 | uint8_t shift; |
843 | 0 | int32_t addend; |
844 | |
|
845 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
846 | |
|
847 | 0 | addend = (opcode & 0x3ffc00) >> 10; |
848 | |
|
849 | 0 | if ((opcode & 0xff800000) == 0x3d800000) |
850 | 0 | { |
851 | | /* LDR / STR with q register */ |
852 | 0 | shift = 4; |
853 | 0 | } |
854 | 0 | else |
855 | 0 | { |
856 | | /* top two bits represent how much addend should be shifted */ |
857 | 0 | shift = opcode >> 30; |
858 | 0 | } |
859 | |
|
860 | 0 | addend <<= shift; |
861 | |
|
862 | 0 | dest_vma += addend; |
863 | | |
864 | | /* only interested in bottom 12 bits */ |
865 | 0 | val = dest_vma & 0xfff; |
866 | |
|
867 | 0 | if (val & ((1 << shift) - 1)) |
868 | 0 | (*info->callbacks->reloc_overflow) |
869 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
870 | 0 | "IMAGE_REL_ARM64_PAGEOFFSET_12L", addend, input_bfd, |
871 | 0 | input_section, rel->r_vaddr - input_section->vma); |
872 | |
|
873 | 0 | val >>= shift; |
874 | |
|
875 | 0 | opcode &= 0xffc003ff; |
876 | 0 | opcode |= val << 10; |
877 | |
|
878 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
879 | 0 | rel->r_ignore = 1; |
880 | |
|
881 | 0 | break; |
882 | 0 | } |
883 | | |
884 | 0 | case IMAGE_REL_ARM64_PAGEOFFSET_12A: |
885 | 0 | { |
886 | 0 | uint32_t opcode, val; |
887 | 0 | int32_t addend; |
888 | |
|
889 | 0 | opcode = bfd_getl32 (contents + rel->r_vaddr); |
890 | |
|
891 | 0 | addend = (opcode & 0x3ffc00) >> 10; |
892 | |
|
893 | 0 | dest_vma += addend; |
894 | | |
895 | | /* only interested in bottom 12 bits */ |
896 | 0 | val = dest_vma & 0xfff; |
897 | |
|
898 | 0 | opcode &= 0xffc003ff; |
899 | 0 | opcode |= val << 10; |
900 | |
|
901 | 0 | bfd_putl32 (opcode, contents + rel->r_vaddr); |
902 | 0 | rel->r_ignore = 1; |
903 | |
|
904 | 0 | break; |
905 | 0 | } |
906 | | |
907 | 0 | case IMAGE_REL_ARM64_SECREL: |
908 | 0 | { |
909 | 0 | uint64_t val; |
910 | 0 | int32_t addend; |
911 | |
|
912 | 0 | addend = bfd_getl32 (contents + rel->r_vaddr); |
913 | |
|
914 | 0 | val = sec->output_offset + sym_value + addend; |
915 | |
|
916 | 0 | if (val > 0xffffffff) |
917 | 0 | (*info->callbacks->reloc_overflow) |
918 | 0 | (info, h ? &h->root : NULL, syms[symndx]._n._n_name, |
919 | 0 | "IMAGE_REL_ARM64_SECREL", addend, input_bfd, |
920 | 0 | input_section, rel->r_vaddr - input_section->vma); |
921 | |
|
922 | 0 | bfd_putl32 (val, contents + rel->r_vaddr); |
923 | 0 | rel->r_ignore = 1; |
924 | |
|
925 | 0 | break; |
926 | 0 | } |
927 | | |
928 | 0 | case IMAGE_REL_ARM64_SECTION: |
929 | 0 | { |
930 | 0 | uint16_t idx = 0, i = 1; |
931 | 0 | asection *s; |
932 | |
|
933 | 0 | s = output_bfd->sections; |
934 | 0 | while (s) |
935 | 0 | { |
936 | 0 | if (s == sec->output_section) |
937 | 0 | { |
938 | 0 | idx = i; |
939 | 0 | break; |
940 | 0 | } |
941 | | |
942 | 0 | i++; |
943 | 0 | s = s->next; |
944 | 0 | } |
945 | | |
946 | |
|
947 | 0 | bfd_putl16 (idx, contents + rel->r_vaddr); |
948 | 0 | rel->r_ignore = 1; |
949 | |
|
950 | 0 | break; |
951 | 0 | } |
952 | | |
953 | 0 | default: |
954 | 0 | info->callbacks->fatal (_("%P: Unhandled relocation type %u\n"), |
955 | 0 | rel->r_type); |
956 | 0 | } |
957 | 0 | } |
958 | | |
959 | 0 | return _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, |
960 | 0 | input_section, contents, |
961 | 0 | relocs, syms, sections); |
962 | 0 | } Unexecuted instantiation: pe-aarch64.c:coff_pe_aarch64_relocate_section Unexecuted instantiation: pei-aarch64.c:coff_pe_aarch64_relocate_section |
963 | | |
964 | | #define coff_relocate_section coff_pe_aarch64_relocate_section |
965 | | |
966 | | #include "coffcode.h" |
967 | | |
968 | | /* Prevent assertion in md_apply_fix by forcing use_rela_p on for new |
969 | | sections. */ |
970 | | static bool |
971 | | coff_aarch64_new_section_hook (bfd *abfd, asection *section) |
972 | 118k | { |
973 | 118k | if (!coff_new_section_hook (abfd, section)) |
974 | 0 | return false; |
975 | | |
976 | 118k | section->use_rela_p = 1; |
977 | | |
978 | | return true; |
979 | 118k | } pe-aarch64.c:coff_aarch64_new_section_hook Line | Count | Source | 972 | 49.2k | { | 973 | 49.2k | if (!coff_new_section_hook (abfd, section)) | 974 | 0 | return false; | 975 | | | 976 | 49.2k | section->use_rela_p = 1; | 977 | | | 978 | | return true; | 979 | 49.2k | } |
pei-aarch64.c:coff_aarch64_new_section_hook Line | Count | Source | 972 | 69.2k | { | 973 | 69.2k | if (!coff_new_section_hook (abfd, section)) | 974 | 0 | return false; | 975 | | | 976 | 69.2k | section->use_rela_p = 1; | 977 | | | 978 | | return true; | 979 | 69.2k | } |
|
980 | | |
981 | | #define coff_aarch64_close_and_cleanup coff_close_and_cleanup |
982 | | #define coff_aarch64_bfd_free_cached_info coff_bfd_free_cached_info |
983 | | #define coff_aarch64_get_section_contents coff_get_section_contents |
984 | | |
985 | | /* Target vectors. */ |
986 | | const bfd_target |
987 | | #ifdef TARGET_SYM |
988 | | TARGET_SYM = |
989 | | #else |
990 | | # error "target symbol name not specified" |
991 | | #endif |
992 | | { |
993 | | #ifdef TARGET_NAME |
994 | | TARGET_NAME, |
995 | | #else |
996 | | # error "target name not specified" |
997 | | #endif |
998 | | bfd_target_coff_flavour, |
999 | | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ |
1000 | | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ |
1001 | | |
1002 | | (HAS_RELOC | EXEC_P /* Object flags. */ |
1003 | | | HAS_LINENO | HAS_DEBUG |
1004 | | | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), |
1005 | | |
1006 | | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ |
1007 | | #if defined(COFF_WITH_PE) |
1008 | | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING |
1009 | | #endif |
1010 | | | SEC_CODE | SEC_DATA | SEC_EXCLUDE ), |
1011 | | |
1012 | | #ifdef TARGET_UNDERSCORE |
1013 | | TARGET_UNDERSCORE, /* Leading underscore. */ |
1014 | | #else |
1015 | | 0, /* Leading underscore. */ |
1016 | | #endif |
1017 | | '/', /* Ar_pad_char. */ |
1018 | | 15, /* Ar_max_namelen. */ |
1019 | | 0, /* match priority. */ |
1020 | | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
1021 | | TARGET_MERGE_SECTIONS, |
1022 | | |
1023 | | /* Data conversion functions. */ |
1024 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
1025 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
1026 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ |
1027 | | /* Header conversion functions. */ |
1028 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
1029 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
1030 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs. */ |
1031 | | |
1032 | | /* Note that we allow an object file to be treated as a core file as well. */ |
1033 | | { /* bfd_check_format. */ |
1034 | | _bfd_dummy_target, |
1035 | | coff_object_p, |
1036 | | bfd_generic_archive_p, |
1037 | | coff_object_p |
1038 | | }, |
1039 | | { /* bfd_set_format. */ |
1040 | | _bfd_bool_bfd_false_error, |
1041 | | coff_mkobject, |
1042 | | _bfd_generic_mkarchive, |
1043 | | _bfd_bool_bfd_false_error |
1044 | | }, |
1045 | | { /* bfd_write_contents. */ |
1046 | | _bfd_bool_bfd_false_error, |
1047 | | coff_write_object_contents, |
1048 | | _bfd_write_archive_contents, |
1049 | | _bfd_bool_bfd_false_error |
1050 | | }, |
1051 | | |
1052 | | BFD_JUMP_TABLE_GENERIC (coff_aarch64), |
1053 | | BFD_JUMP_TABLE_COPY (coff), |
1054 | | BFD_JUMP_TABLE_CORE (_bfd_nocore), |
1055 | | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), |
1056 | | BFD_JUMP_TABLE_SYMBOLS (coff), |
1057 | | BFD_JUMP_TABLE_RELOCS (coff), |
1058 | | BFD_JUMP_TABLE_WRITE (coff), |
1059 | | BFD_JUMP_TABLE_LINK (coff), |
1060 | | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
1061 | | |
1062 | | NULL, |
1063 | | |
1064 | | COFF_SWAP_TABLE |
1065 | | }; |
1066 | | |
1067 | | #ifdef COFF_WITH_PE_BIGOBJ |
1068 | | const bfd_target |
1069 | | TARGET_SYM_BIG = |
1070 | | { |
1071 | | TARGET_NAME_BIG, |
1072 | | bfd_target_coff_flavour, |
1073 | | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ |
1074 | | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ |
1075 | | |
1076 | | (HAS_RELOC | EXEC_P /* Object flags. */ |
1077 | | | HAS_LINENO | HAS_DEBUG |
1078 | | | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), |
1079 | | |
1080 | | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ |
1081 | | #ifdef COFF_WITH_PE |
1082 | | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING |
1083 | | #endif |
1084 | | | SEC_CODE | SEC_DATA | SEC_EXCLUDE ), |
1085 | | |
1086 | | #ifdef TARGET_UNDERSCORE |
1087 | | TARGET_UNDERSCORE, /* Leading underscore. */ |
1088 | | #else |
1089 | | 0, /* Leading underscore. */ |
1090 | | #endif |
1091 | | '/', /* Ar_pad_char. */ |
1092 | | 15, /* Ar_max_namelen. */ |
1093 | | 0, /* match priority. */ |
1094 | | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
1095 | | TARGET_MERGE_SECTIONS, |
1096 | | |
1097 | | /* Data conversion functions. */ |
1098 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
1099 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
1100 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ |
1101 | | /* Header conversion functions. */ |
1102 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
1103 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
1104 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs. */ |
1105 | | |
1106 | | /* Note that we allow an object file to be treated as a core file as well. */ |
1107 | | { /* bfd_check_format. */ |
1108 | | _bfd_dummy_target, |
1109 | | coff_object_p, |
1110 | | bfd_generic_archive_p, |
1111 | | coff_object_p |
1112 | | }, |
1113 | | { /* bfd_set_format. */ |
1114 | | _bfd_bool_bfd_false_error, |
1115 | | coff_mkobject, |
1116 | | _bfd_generic_mkarchive, |
1117 | | _bfd_bool_bfd_false_error |
1118 | | }, |
1119 | | { /* bfd_write_contents. */ |
1120 | | _bfd_bool_bfd_false_error, |
1121 | | coff_write_object_contents, |
1122 | | _bfd_write_archive_contents, |
1123 | | _bfd_bool_bfd_false_error |
1124 | | }, |
1125 | | |
1126 | | BFD_JUMP_TABLE_GENERIC (coff_aarch64), |
1127 | | BFD_JUMP_TABLE_COPY (coff), |
1128 | | BFD_JUMP_TABLE_CORE (_bfd_nocore), |
1129 | | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), |
1130 | | BFD_JUMP_TABLE_SYMBOLS (coff), |
1131 | | BFD_JUMP_TABLE_RELOCS (coff), |
1132 | | BFD_JUMP_TABLE_WRITE (coff), |
1133 | | BFD_JUMP_TABLE_LINK (coff), |
1134 | | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
1135 | | |
1136 | | NULL, |
1137 | | |
1138 | | &bigobj_swap_table |
1139 | | }; |
1140 | | #endif |