Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD support for the ARM processor |
b3adc24a | 2 | Copyright (C) 1994-2020 Free Software Foundation, Inc. |
252b5132 RH |
3 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) |
4 | ||
e2fd756b | 5 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 6 | |
e2fd756b NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 9 | the Free Software Foundation; either version 3 of the License, or |
e2fd756b | 10 | (at your option) any later version. |
252b5132 | 11 | |
e2fd756b NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
252b5132 | 16 | |
e2fd756b NC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
252b5132 | 21 | |
252b5132 | 22 | #include "sysdep.h" |
3db64b00 | 23 | #include "bfd.h" |
252b5132 | 24 | #include "libbfd.h" |
5a6c6817 | 25 | #include "libiberty.h" |
f37164d7 | 26 | #include "cpu-arm.h" |
252b5132 | 27 | |
252b5132 RH |
28 | /* This routine is provided two arch_infos and works out which ARM |
29 | machine which would be compatible with both and returns a pointer | |
e2fd756b | 30 | to its info structure. */ |
252b5132 RH |
31 | |
32 | static const bfd_arch_info_type * | |
f075ee0c | 33 | compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b) |
252b5132 | 34 | { |
e2fd756b | 35 | /* If a & b are for different architecture we can do nothing. */ |
252b5132 RH |
36 | if (a->arch != b->arch) |
37 | return NULL; | |
38 | ||
e2fd756b | 39 | /* If a & b are for the same machine then all is well. */ |
252b5132 RH |
40 | if (a->mach == b->mach) |
41 | return a; | |
42 | ||
e2fd756b NC |
43 | /* Otherwise if either a or b is the 'default' machine |
44 | then it can be polymorphed into the other. */ | |
252b5132 RH |
45 | if (a->the_default) |
46 | return b; | |
71f6b586 | 47 | |
252b5132 RH |
48 | if (b->the_default) |
49 | return a; | |
50 | ||
e2fd756b NC |
51 | /* So far all newer ARM architecture cores are |
52 | supersets of previous cores. */ | |
252b5132 RH |
53 | if (a->mach < b->mach) |
54 | return b; | |
55 | else if (a->mach > b->mach) | |
56 | return a; | |
57 | ||
e2fd756b | 58 | /* Never reached! */ |
252b5132 RH |
59 | return NULL; |
60 | } | |
61 | ||
62 | static struct | |
63 | { | |
e2fd756b NC |
64 | unsigned int mach; |
65 | char * name; | |
252b5132 RH |
66 | } |
67 | processors[] = | |
68 | { | |
b5ab3163 TP |
69 | { bfd_mach_arm_2, "arm2" }, |
70 | { bfd_mach_arm_2a, "arm250" }, | |
71 | { bfd_mach_arm_2a, "arm3" }, | |
72 | { bfd_mach_arm_3, "arm6" }, | |
73 | { bfd_mach_arm_3, "arm60" }, | |
74 | { bfd_mach_arm_3, "arm600" }, | |
75 | { bfd_mach_arm_3, "arm610" }, | |
76 | { bfd_mach_arm_3, "arm620" }, | |
77 | { bfd_mach_arm_3, "arm7" }, | |
78 | { bfd_mach_arm_3, "arm70" }, | |
79 | { bfd_mach_arm_3, "arm700" }, | |
80 | { bfd_mach_arm_3, "arm700i" }, | |
81 | { bfd_mach_arm_3, "arm710" }, | |
82 | { bfd_mach_arm_3, "arm7100" }, | |
83 | { bfd_mach_arm_3, "arm710c" }, | |
84 | { bfd_mach_arm_4T, "arm710t" }, | |
85 | { bfd_mach_arm_3, "arm720" }, | |
86 | { bfd_mach_arm_4T, "arm720t" }, | |
87 | { bfd_mach_arm_4T, "arm740t" }, | |
88 | { bfd_mach_arm_3, "arm7500" }, | |
89 | { bfd_mach_arm_3, "arm7500fe" }, | |
90 | { bfd_mach_arm_3, "arm7d" }, | |
91 | { bfd_mach_arm_3, "arm7di" }, | |
92 | { bfd_mach_arm_3M, "arm7dm" }, | |
93 | { bfd_mach_arm_3M, "arm7dmi" }, | |
94 | { bfd_mach_arm_4T, "arm7t" }, | |
95 | { bfd_mach_arm_4T, "arm7tdmi" }, | |
96 | { bfd_mach_arm_4T, "arm7tdmi-s" }, | |
97 | { bfd_mach_arm_3M, "arm7m" }, | |
98 | { bfd_mach_arm_4, "arm8" }, | |
99 | { bfd_mach_arm_4, "arm810" }, | |
100 | { bfd_mach_arm_4, "arm9" }, | |
101 | { bfd_mach_arm_4T, "arm920" }, | |
102 | { bfd_mach_arm_4T, "arm920t" }, | |
103 | { bfd_mach_arm_4T, "arm922t" }, | |
104 | { bfd_mach_arm_5TEJ, "arm926ej" }, | |
105 | { bfd_mach_arm_5TEJ, "arm926ejs" }, | |
106 | { bfd_mach_arm_5TEJ, "arm926ej-s" }, | |
107 | { bfd_mach_arm_4T, "arm940t" }, | |
108 | { bfd_mach_arm_5TE, "arm946e" }, | |
109 | { bfd_mach_arm_5TE, "arm946e-r0" }, | |
110 | { bfd_mach_arm_5TE, "arm946e-s" }, | |
111 | { bfd_mach_arm_5TE, "arm966e" }, | |
112 | { bfd_mach_arm_5TE, "arm966e-r0" }, | |
113 | { bfd_mach_arm_5TE, "arm966e-s" }, | |
114 | { bfd_mach_arm_5TE, "arm968e-s" }, | |
115 | { bfd_mach_arm_5TE, "arm9e" }, | |
116 | { bfd_mach_arm_5TE, "arm9e-r0" }, | |
117 | { bfd_mach_arm_4T, "arm9tdmi" }, | |
118 | { bfd_mach_arm_5TE, "arm1020" }, | |
119 | { bfd_mach_arm_5T, "arm1020t" }, | |
120 | { bfd_mach_arm_5TE, "arm1020e" }, | |
121 | { bfd_mach_arm_5TE, "arm1022e" }, | |
122 | { bfd_mach_arm_5TEJ, "arm1026ejs" }, | |
123 | { bfd_mach_arm_5TEJ, "arm1026ej-s" }, | |
124 | { bfd_mach_arm_5TE, "arm10e" }, | |
125 | { bfd_mach_arm_5T, "arm10t" }, | |
126 | { bfd_mach_arm_5T, "arm10tdmi" }, | |
127 | { bfd_mach_arm_6, "arm1136j-s" }, | |
128 | { bfd_mach_arm_6, "arm1136js" }, | |
129 | { bfd_mach_arm_6, "arm1136jf-s" }, | |
130 | { bfd_mach_arm_6, "arm1136jfs" }, | |
131 | { bfd_mach_arm_6KZ, "arm1176jz-s" }, | |
132 | { bfd_mach_arm_6KZ, "arm1176jzf-s" }, | |
133 | { bfd_mach_arm_6T2, "arm1156t2-s" }, | |
134 | { bfd_mach_arm_6T2, "arm1156t2f-s" }, | |
135 | { bfd_mach_arm_7, "cortex-a5" }, | |
136 | { bfd_mach_arm_7, "cortex-a7" }, | |
137 | { bfd_mach_arm_7, "cortex-a8" }, | |
138 | { bfd_mach_arm_7, "cortex-a9" }, | |
139 | { bfd_mach_arm_7, "cortex-a12" }, | |
140 | { bfd_mach_arm_7, "cortex-a15" }, | |
141 | { bfd_mach_arm_7, "cortex-a17" }, | |
142 | { bfd_mach_arm_8, "cortex-a32" }, | |
143 | { bfd_mach_arm_8, "cortex-a35" }, | |
144 | { bfd_mach_arm_8, "cortex-a53" }, | |
145 | { bfd_mach_arm_8, "cortex-a55" }, | |
146 | { bfd_mach_arm_8, "cortex-a57" }, | |
147 | { bfd_mach_arm_8, "cortex-a72" }, | |
148 | { bfd_mach_arm_8, "cortex-a73" }, | |
149 | { bfd_mach_arm_8, "cortex-a75" }, | |
150 | { bfd_mach_arm_8, "cortex-a76" }, | |
0535e5d7 DZ |
151 | { bfd_mach_arm_8, "cortex-a76ae" }, |
152 | { bfd_mach_arm_8, "cortex-a77" }, | |
42c36b73 PW |
153 | { bfd_mach_arm_8, "cortex-a78" }, |
154 | { bfd_mach_arm_8, "cortex-a78ae" }, | |
b5ab3163 TP |
155 | { bfd_mach_arm_6SM, "cortex-m0" }, |
156 | { bfd_mach_arm_6SM, "cortex-m0plus" }, | |
157 | { bfd_mach_arm_6SM, "cortex-m1" }, | |
158 | { bfd_mach_arm_8M_BASE, "cortex-m23" }, | |
159 | { bfd_mach_arm_7, "cortex-m3" }, | |
160 | { bfd_mach_arm_8M_MAIN, "cortex-m33" }, | |
0535e5d7 | 161 | { bfd_mach_arm_8M_MAIN, "cortex-m35p" }, |
b5ab3163 TP |
162 | { bfd_mach_arm_7EM, "cortex-m4" }, |
163 | { bfd_mach_arm_7EM, "cortex-m7" }, | |
164 | { bfd_mach_arm_7, "cortex-r4" }, | |
165 | { bfd_mach_arm_7, "cortex-r4f" }, | |
166 | { bfd_mach_arm_7, "cortex-r5" }, | |
167 | { bfd_mach_arm_8R, "cortex-r52" }, | |
168 | { bfd_mach_arm_7, "cortex-r7" }, | |
169 | { bfd_mach_arm_7, "cortex-r8" }, | |
394e9bf6 | 170 | { bfd_mach_arm_8, "cortex-x1" }, |
b5ab3163 TP |
171 | { bfd_mach_arm_4T, "ep9312" }, |
172 | { bfd_mach_arm_8, "exynos-m1" }, | |
173 | { bfd_mach_arm_4, "fa526" }, | |
174 | { bfd_mach_arm_5TE, "fa606te" }, | |
175 | { bfd_mach_arm_5TE, "fa616te" }, | |
176 | { bfd_mach_arm_4, "fa626" }, | |
177 | { bfd_mach_arm_5TE, "fa626te" }, | |
178 | { bfd_mach_arm_5TE, "fa726te" }, | |
179 | { bfd_mach_arm_5TE, "fmp626" }, | |
180 | { bfd_mach_arm_XScale, "i80200" }, | |
181 | { bfd_mach_arm_7, "marvell-pj4" }, | |
182 | { bfd_mach_arm_7, "marvell-whitney" }, | |
183 | { bfd_mach_arm_6K, "mpcore" }, | |
184 | { bfd_mach_arm_6K, "mpcorenovfp" }, | |
185 | { bfd_mach_arm_4, "sa1" }, | |
186 | { bfd_mach_arm_4, "strongarm" }, | |
187 | { bfd_mach_arm_4, "strongarm1" }, | |
188 | { bfd_mach_arm_4, "strongarm110" }, | |
189 | { bfd_mach_arm_4, "strongarm1100" }, | |
190 | { bfd_mach_arm_4, "strongarm1110" }, | |
191 | { bfd_mach_arm_XScale, "xscale" }, | |
192 | { bfd_mach_arm_8, "xgene1" }, | |
193 | { bfd_mach_arm_8, "xgene2" }, | |
194 | { bfd_mach_arm_ep9312, "ep9312" }, | |
195 | { bfd_mach_arm_iWMMXt, "iwmmxt" }, | |
196 | { bfd_mach_arm_iWMMXt2, "iwmmxt2" }, | |
197 | { bfd_mach_arm_unknown, "arm_any" } | |
252b5132 RH |
198 | }; |
199 | ||
b34976b6 | 200 | static bfd_boolean |
f075ee0c | 201 | scan (const struct bfd_arch_info *info, const char *string) |
252b5132 RH |
202 | { |
203 | int i; | |
204 | ||
e2fd756b | 205 | /* First test for an exact match. */ |
252b5132 | 206 | if (strcasecmp (string, info->printable_name) == 0) |
b34976b6 | 207 | return TRUE; |
252b5132 | 208 | |
e2fd756b | 209 | /* Next check for a processor name instead of an Architecture name. */ |
252b5132 RH |
210 | for (i = sizeof (processors) / sizeof (processors[0]); i--;) |
211 | { | |
e2fd756b | 212 | if (strcasecmp (string, processors [i].name) == 0) |
252b5132 RH |
213 | break; |
214 | } | |
215 | ||
e2fd756b | 216 | if (i != -1 && info->mach == processors [i].mach) |
b34976b6 | 217 | return TRUE; |
252b5132 | 218 | |
e2fd756b | 219 | /* Finally check for the default architecture. */ |
252b5132 RH |
220 | if (strcasecmp (string, "arm") == 0) |
221 | return info->the_default; | |
71f6b586 | 222 | |
b34976b6 | 223 | return FALSE; |
252b5132 RH |
224 | } |
225 | ||
252b5132 | 226 | #define N(number, print, default, next) \ |
b7761f11 | 227 | { 32, 32, 8, bfd_arch_arm, number, "arm", print, 4, default, compatible, \ |
aebcfb76 | 228 | scan, bfd_arch_default_fill, next, 0 } |
252b5132 RH |
229 | |
230 | static const bfd_arch_info_type arch_info_struct[] = | |
71f6b586 | 231 | { |
c0c468d5 TP |
232 | N (bfd_mach_arm_2, "armv2", FALSE, & arch_info_struct[1]), |
233 | N (bfd_mach_arm_2a, "armv2a", FALSE, & arch_info_struct[2]), | |
234 | N (bfd_mach_arm_3, "armv3", FALSE, & arch_info_struct[3]), | |
235 | N (bfd_mach_arm_3M, "armv3m", FALSE, & arch_info_struct[4]), | |
236 | N (bfd_mach_arm_4, "armv4", FALSE, & arch_info_struct[5]), | |
237 | N (bfd_mach_arm_4T, "armv4t", FALSE, & arch_info_struct[6]), | |
238 | N (bfd_mach_arm_5, "armv5", FALSE, & arch_info_struct[7]), | |
239 | N (bfd_mach_arm_5T, "armv5t", FALSE, & arch_info_struct[8]), | |
240 | N (bfd_mach_arm_5TE, "armv5te", FALSE, & arch_info_struct[9]), | |
241 | N (bfd_mach_arm_XScale, "xscale", FALSE, & arch_info_struct[10]), | |
242 | N (bfd_mach_arm_ep9312, "ep9312", FALSE, & arch_info_struct[11]), | |
243 | N (bfd_mach_arm_iWMMXt, "iwmmxt", FALSE, & arch_info_struct[12]), | |
244 | N (bfd_mach_arm_iWMMXt2, "iwmmxt2", FALSE, & arch_info_struct[13]), | |
245 | N (bfd_mach_arm_5TEJ, "armv5tej", FALSE, & arch_info_struct[14]), | |
246 | N (bfd_mach_arm_6, "armv6", FALSE, & arch_info_struct[15]), | |
247 | N (bfd_mach_arm_6KZ, "armv6kz", FALSE, & arch_info_struct[16]), | |
248 | N (bfd_mach_arm_6T2, "armv6t2", FALSE, & arch_info_struct[17]), | |
249 | N (bfd_mach_arm_6K, "armv6k", FALSE, & arch_info_struct[18]), | |
250 | N (bfd_mach_arm_7, "armv7", FALSE, & arch_info_struct[19]), | |
251 | N (bfd_mach_arm_6M, "armv6-m", FALSE, & arch_info_struct[20]), | |
252 | N (bfd_mach_arm_6SM, "armv6s-m", FALSE, & arch_info_struct[21]), | |
253 | N (bfd_mach_arm_7EM, "armv7e-m", FALSE, & arch_info_struct[22]), | |
254 | N (bfd_mach_arm_8, "armv8-a", FALSE, & arch_info_struct[23]), | |
255 | N (bfd_mach_arm_8R, "armv8-r", FALSE, & arch_info_struct[24]), | |
256 | N (bfd_mach_arm_8M_BASE, "armv8-m.base", FALSE, & arch_info_struct[25]), | |
257 | N (bfd_mach_arm_8M_MAIN, "armv8-m.main", FALSE, & arch_info_struct[26]), | |
031254f2 | 258 | N (bfd_mach_arm_8_1M_MAIN, "armv8.1-m.main", FALSE, & arch_info_struct[27]), |
c0c468d5 | 259 | N (bfd_mach_arm_unknown, "arm_any", FALSE, NULL) |
252b5132 RH |
260 | }; |
261 | ||
262 | const bfd_arch_info_type bfd_arm_arch = | |
b34976b6 | 263 | N (0, "arm", TRUE, & arch_info_struct[0]); |
5a6c6817 NC |
264 | |
265 | /* Support functions used by both the COFF and ELF versions of the ARM port. */ | |
266 | ||
5c4491d3 | 267 | /* Handle the merging of the 'machine' settings of input file IBFD |
5a6c6817 NC |
268 | and an output file OBFD. These values actually represent the |
269 | different possible ARM architecture variants. | |
270 | Returns TRUE if they were merged successfully or FALSE otherwise. */ | |
271 | ||
272 | bfd_boolean | |
f075ee0c | 273 | bfd_arm_merge_machines (bfd *ibfd, bfd *obfd) |
5a6c6817 NC |
274 | { |
275 | unsigned int in = bfd_get_mach (ibfd); | |
276 | unsigned int out = bfd_get_mach (obfd); | |
277 | ||
278 | /* If the output architecture is unknown, we now have a value to set. */ | |
279 | if (out == bfd_mach_arm_unknown) | |
280 | bfd_set_arch_mach (obfd, bfd_arch_arm, in); | |
281 | ||
5c4491d3 | 282 | /* If the input architecture is unknown, |
5a6c6817 NC |
283 | then so must be the output architecture. */ |
284 | else if (in == bfd_mach_arm_unknown) | |
285 | /* FIXME: We ought to have some way to | |
286 | override this on the command line. */ | |
287 | bfd_set_arch_mach (obfd, bfd_arch_arm, bfd_mach_arm_unknown); | |
288 | ||
289 | /* If they are the same then nothing needs to be done. */ | |
290 | else if (out == in) | |
291 | ; | |
292 | ||
293 | /* Otherwise the general principle that a earlier architecture can be | |
5c4491d3 | 294 | linked with a later architecture to produce a binary that will execute |
5a6c6817 NC |
295 | on the later architecture. |
296 | ||
297 | We fail however if we attempt to link a Cirrus EP9312 binary with an | |
298 | Intel XScale binary, since these architecture have co-processors which | |
299 | will not both be present on the same physical hardware. */ | |
300 | else if (in == bfd_mach_arm_ep9312 | |
2d447fca JM |
301 | && (out == bfd_mach_arm_XScale |
302 | || out == bfd_mach_arm_iWMMXt | |
303 | || out == bfd_mach_arm_iWMMXt2)) | |
5a6c6817 | 304 | { |
695344c0 | 305 | /* xgettext: c-format */ |
dc1e8a47 AM |
306 | _bfd_error_handler (_("error: %pB is compiled for the EP9312, " |
307 | "whereas %pB is compiled for XScale"), | |
d003868e | 308 | ibfd, obfd); |
5a6c6817 NC |
309 | bfd_set_error (bfd_error_wrong_format); |
310 | return FALSE; | |
311 | } | |
312 | else if (out == bfd_mach_arm_ep9312 | |
2d447fca JM |
313 | && (in == bfd_mach_arm_XScale |
314 | || in == bfd_mach_arm_iWMMXt | |
315 | || in == bfd_mach_arm_iWMMXt2)) | |
5a6c6817 | 316 | { |
695344c0 | 317 | /* xgettext: c-format */ |
dc1e8a47 AM |
318 | _bfd_error_handler (_("error: %pB is compiled for the EP9312, " |
319 | "whereas %pB is compiled for XScale"), | |
d003868e | 320 | obfd, ibfd); |
5a6c6817 NC |
321 | bfd_set_error (bfd_error_wrong_format); |
322 | return FALSE; | |
323 | } | |
324 | else if (in > out) | |
325 | bfd_set_arch_mach (obfd, bfd_arch_arm, in); | |
326 | /* else | |
327 | Nothing to do. */ | |
328 | ||
329 | return TRUE; | |
330 | } | |
331 | ||
332 | typedef struct | |
333 | { | |
334 | unsigned char namesz[4]; /* Size of entry's owner string. */ | |
335 | unsigned char descsz[4]; /* Size of the note descriptor. */ | |
336 | unsigned char type[4]; /* Interpretation of the descriptor. */ | |
337 | char name[1]; /* Start of the name+desc data. */ | |
338 | } arm_Note; | |
339 | ||
340 | static bfd_boolean | |
f075ee0c AM |
341 | arm_check_note (bfd *abfd, |
342 | bfd_byte *buffer, | |
343 | bfd_size_type buffer_size, | |
344 | const char *expected_name, | |
345 | char **description_return) | |
5a6c6817 NC |
346 | { |
347 | unsigned long namesz; | |
348 | unsigned long descsz; | |
349 | unsigned long type; | |
07d6d2b8 | 350 | char * descr; |
5a6c6817 NC |
351 | |
352 | if (buffer_size < offsetof (arm_Note, name)) | |
353 | return FALSE; | |
354 | ||
355 | /* We have to extract the values this way to allow for a | |
356 | host whose endian-ness is different from the target. */ | |
357 | namesz = bfd_get_32 (abfd, buffer); | |
358 | descsz = bfd_get_32 (abfd, buffer + offsetof (arm_Note, descsz)); | |
359 | type = bfd_get_32 (abfd, buffer + offsetof (arm_Note, type)); | |
f075ee0c | 360 | descr = (char *) buffer + offsetof (arm_Note, name); |
5a6c6817 NC |
361 | |
362 | /* Check for buffer overflow. */ | |
363 | if (namesz + descsz + offsetof (arm_Note, name) > buffer_size) | |
364 | return FALSE; | |
365 | ||
366 | if (expected_name == NULL) | |
367 | { | |
368 | if (namesz != 0) | |
369 | return FALSE; | |
370 | } | |
371 | else | |
68ffbac6 | 372 | { |
60d8b524 | 373 | if (namesz != ((strlen (expected_name) + 1 + 3) & ~3)) |
5a6c6817 | 374 | return FALSE; |
68ffbac6 | 375 | |
5a6c6817 NC |
376 | if (strcmp (descr, expected_name) != 0) |
377 | return FALSE; | |
378 | ||
379 | descr += (namesz + 3) & ~3; | |
380 | } | |
381 | ||
382 | /* FIXME: We should probably check the type as well. */ | |
c7e2358a | 383 | (void) type; |
5a6c6817 NC |
384 | |
385 | if (description_return != NULL) | |
386 | * description_return = descr; | |
387 | ||
388 | return TRUE; | |
389 | } | |
390 | ||
07d6d2b8 | 391 | #define NOTE_ARCH_STRING "arch: " |
5a6c6817 NC |
392 | |
393 | bfd_boolean | |
f075ee0c | 394 | bfd_arm_update_notes (bfd *abfd, const char *note_section) |
5a6c6817 | 395 | { |
07d6d2b8 AM |
396 | asection * arm_arch_section; |
397 | bfd_size_type buffer_size; | |
398 | bfd_byte * buffer; | |
399 | char * arch_string; | |
400 | char * expected; | |
5a6c6817 NC |
401 | |
402 | /* Look for a note section. If one is present check the architecture | |
403 | string encoded in it, and set it to the current architecture if it is | |
404 | different. */ | |
405 | arm_arch_section = bfd_get_section_by_name (abfd, note_section); | |
406 | ||
407 | if (arm_arch_section == NULL) | |
408 | return TRUE; | |
409 | ||
eea6121a | 410 | buffer_size = arm_arch_section->size; |
5a6c6817 NC |
411 | if (buffer_size == 0) |
412 | return FALSE; | |
413 | ||
eea6121a | 414 | if (!bfd_malloc_and_get_section (abfd, arm_arch_section, &buffer)) |
5a6c6817 NC |
415 | goto FAIL; |
416 | ||
417 | /* Parse the note. */ | |
418 | if (! arm_check_note (abfd, buffer, buffer_size, NOTE_ARCH_STRING, & arch_string)) | |
419 | goto FAIL; | |
420 | ||
b5ab3163 TP |
421 | /* Check the architecture in the note against the architecture of the bfd. |
422 | Newer architectures versions should not be added here as build attribute | |
423 | are a better mechanism to convey ISA used. */ | |
5a6c6817 NC |
424 | switch (bfd_get_mach (abfd)) |
425 | { | |
426 | default: | |
427 | case bfd_mach_arm_unknown: expected = "unknown"; break; | |
428 | case bfd_mach_arm_2: expected = "armv2"; break; | |
429 | case bfd_mach_arm_2a: expected = "armv2a"; break; | |
430 | case bfd_mach_arm_3: expected = "armv3"; break; | |
431 | case bfd_mach_arm_3M: expected = "armv3M"; break; | |
432 | case bfd_mach_arm_4: expected = "armv4"; break; | |
433 | case bfd_mach_arm_4T: expected = "armv4t"; break; | |
434 | case bfd_mach_arm_5: expected = "armv5"; break; | |
435 | case bfd_mach_arm_5T: expected = "armv5t"; break; | |
436 | case bfd_mach_arm_5TE: expected = "armv5te"; break; | |
437 | case bfd_mach_arm_XScale: expected = "XScale"; break; | |
438 | case bfd_mach_arm_ep9312: expected = "ep9312"; break; | |
439 | case bfd_mach_arm_iWMMXt: expected = "iWMMXt"; break; | |
2d447fca | 440 | case bfd_mach_arm_iWMMXt2: expected = "iWMMXt2"; break; |
5a6c6817 NC |
441 | } |
442 | ||
443 | if (strcmp (arch_string, expected) != 0) | |
444 | { | |
f075ee0c AM |
445 | strcpy ((char *) buffer + (offsetof (arm_Note, name) |
446 | + ((strlen (NOTE_ARCH_STRING) + 3) & ~3)), | |
447 | expected); | |
5a6c6817 NC |
448 | |
449 | if (! bfd_set_section_contents (abfd, arm_arch_section, buffer, | |
450 | (file_ptr) 0, buffer_size)) | |
451 | { | |
4eca0228 | 452 | _bfd_error_handler |
695344c0 | 453 | /* xgettext: c-format */ |
871b3ab2 | 454 | (_("warning: unable to update contents of %s section in %pB"), |
dae82561 | 455 | note_section, abfd); |
5a6c6817 NC |
456 | goto FAIL; |
457 | } | |
458 | } | |
459 | ||
460 | free (buffer); | |
461 | return TRUE; | |
462 | ||
463 | FAIL: | |
c9594989 | 464 | free (buffer); |
5a6c6817 NC |
465 | return FALSE; |
466 | } | |
467 | ||
468 | ||
469 | static struct | |
470 | { | |
471 | const char * string; | |
472 | unsigned int mach; | |
473 | } | |
b5ab3163 TP |
474 | |
475 | /* Newer architectures versions should not be added here as build attribute are | |
476 | a better mechanism to convey ISA used. */ | |
5a6c6817 NC |
477 | architectures[] = |
478 | { | |
479 | { "armv2", bfd_mach_arm_2 }, | |
480 | { "armv2a", bfd_mach_arm_2a }, | |
481 | { "armv3", bfd_mach_arm_3 }, | |
482 | { "armv3M", bfd_mach_arm_3M }, | |
483 | { "armv4", bfd_mach_arm_4 }, | |
484 | { "armv4t", bfd_mach_arm_4T }, | |
485 | { "armv5", bfd_mach_arm_5 }, | |
486 | { "armv5t", bfd_mach_arm_5T }, | |
487 | { "armv5te", bfd_mach_arm_5TE }, | |
488 | { "XScale", bfd_mach_arm_XScale }, | |
489 | { "ep9312", bfd_mach_arm_ep9312 }, | |
2d447fca | 490 | { "iWMMXt", bfd_mach_arm_iWMMXt }, |
99914dfd NC |
491 | { "iWMMXt2", bfd_mach_arm_iWMMXt2 }, |
492 | { "arm_any", bfd_mach_arm_unknown } | |
5a6c6817 NC |
493 | }; |
494 | ||
495 | /* Extract the machine number stored in a note section. */ | |
496 | unsigned int | |
f075ee0c | 497 | bfd_arm_get_mach_from_notes (bfd *abfd, const char *note_section) |
5a6c6817 | 498 | { |
07d6d2b8 AM |
499 | asection * arm_arch_section; |
500 | bfd_size_type buffer_size; | |
501 | bfd_byte * buffer; | |
502 | char * arch_string; | |
503 | int i; | |
5a6c6817 NC |
504 | |
505 | /* Look for a note section. If one is present check the architecture | |
506 | string encoded in it, and set it to the current architecture if it is | |
507 | different. */ | |
508 | arm_arch_section = bfd_get_section_by_name (abfd, note_section); | |
509 | ||
510 | if (arm_arch_section == NULL) | |
511 | return bfd_mach_arm_unknown; | |
512 | ||
eea6121a | 513 | buffer_size = arm_arch_section->size; |
5a6c6817 NC |
514 | if (buffer_size == 0) |
515 | return bfd_mach_arm_unknown; | |
516 | ||
eea6121a | 517 | if (!bfd_malloc_and_get_section (abfd, arm_arch_section, &buffer)) |
5a6c6817 NC |
518 | goto FAIL; |
519 | ||
520 | /* Parse the note. */ | |
521 | if (! arm_check_note (abfd, buffer, buffer_size, NOTE_ARCH_STRING, & arch_string)) | |
522 | goto FAIL; | |
523 | ||
524 | /* Interpret the architecture string. */ | |
525 | for (i = ARRAY_SIZE (architectures); i--;) | |
526 | if (strcmp (arch_string, architectures[i].string) == 0) | |
527 | { | |
528 | free (buffer); | |
529 | return architectures[i].mach; | |
530 | } | |
531 | ||
532 | FAIL: | |
c9594989 | 533 | free (buffer); |
5a6c6817 NC |
534 | return bfd_mach_arm_unknown; |
535 | } | |
9d2da7ca JB |
536 | |
537 | bfd_boolean | |
b0796911 | 538 | bfd_is_arm_special_symbol_name (const char * name, int type) |
9d2da7ca | 539 | { |
38406048 | 540 | /* The ARM compiler outputs several obsolete forms. Recognize them |
efacb0fb DJ |
541 | in addition to the standard $a, $t and $d. We are somewhat loose |
542 | in what we accept here, since the full set is not documented. */ | |
b0796911 PB |
543 | if (!name || name[0] != '$') |
544 | return FALSE; | |
545 | if (name[1] == 'a' || name[1] == 't' || name[1] == 'd') | |
546 | type &= BFD_ARM_SPECIAL_SYM_TYPE_MAP; | |
547 | else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p') | |
548 | type &= BFD_ARM_SPECIAL_SYM_TYPE_TAG; | |
549 | else if (name[1] >= 'a' && name[1] <= 'z') | |
550 | type &= BFD_ARM_SPECIAL_SYM_TYPE_OTHER; | |
551 | else | |
552 | return FALSE; | |
553 | ||
554 | return (type != 0 && (name[2] == 0 || name[2] == '.')); | |
9d2da7ca JB |
555 | } |
556 |