cpu-arm.c 19 KB

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