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