0008-RISC-V-Improve-the-version-parsing-for-arch-string.patch 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. From 5b427d5371e8b33f4cdbfae6d16f339ed94c521e Mon Sep 17 00:00:00 2001
  2. From: Nelson Chu <nelson.chu@sifive.com>
  3. Date: Fri, 20 Nov 2020 17:26:04 +0800
  4. Subject: [PATCH 08/48] RISC-V: Improve the version parsing for arch string.
  5. Keep the riscv_add_subset to do the same thing, and use a new
  6. function, riscv_parse_add_subset, to cover most of the things
  7. when parsing, including find the default versions for extensions,
  8. and check whether the versions are valid. The version 0p0 should
  9. be an invalid version, that is the mistake I made before. This
  10. patch clarify the version rules as follows,
  11. * We accept any version of extensions set by users, except 0p0.
  12. * The non-standard x extensions must be set with versions in arch string.
  13. * If user don't set the versions, or set 0p0 for the extensions, then try
  14. to find the supported versions according to the chosen ISA spec.
  15. Otherwise, report errors rather than output 0p0 for them.
  16. Besides, we use as_bad rather than as_fatal to report more errors
  17. for assembler.
  18. bfd/
  19. * elfxx-riscv.c (riscv_lookup_subset): Moved to front.
  20. (riscv_add_subset): Likewise.
  21. (riscv_release_subset_list): Likewise.
  22. (riscv_parse_add_subset): New function. Find and check the
  23. versions before adding them by riscv_add_subset.
  24. (riscv_parsing_subset_version): Remove use_default_version
  25. and change the version type from unsigned to int. Set the
  26. versions to RISCV_UNKNOWN_VERSION if we can not find them
  27. in the arch string.
  28. (riscv_parse_std_ext): Updated.
  29. (riscv_parse_prefixed_ext): Updated. Since we use as_bad
  30. rather than as_fatal to report more errors, return NULL
  31. string if the parsed end_of_version is NULL, too.
  32. (riscv_parse_subset): Use a new boolean, no_conflict, to
  33. report more errors when we have more than one ISA conflicts.
  34. * elfxx-riscv.h (RISCV_DONT_CARE_VERSION): Changed to
  35. RISCV_UNKNOWN_VERSION.
  36. (riscv_lookup_subset_version): Removed.
  37. (riscv_parse_subset_t): Updated.
  38. gas/
  39. * config/tc-riscv.c (riscv_get_default_ext_version):
  40. Change the version type from unsigned to int.
  41. (riscv_set_arch): Use as_bad rather than as_fatal to
  42. report more errors.
  43. * testsuite/gas/riscv/attribute-02.d: Updated since x must be
  44. set with versions.
  45. * testsuite/gas/riscv/attribute-03.d: Likewise.
  46. * testsuite/gas/riscv/march-ok-two-nse.d: Likewise.
  47. * testsuite/gas/riscv/attribute-09.d: zicsr wasn't supported
  48. in the spec 2.2, so choose the newer spec.
  49. * testsuite/gas/riscv/march-fail-base-01.l: Updated since as_bad.
  50. * testsuite/gas/riscv/march-fail-base-02.l: Likewise.
  51. * testsuite/gas/riscv/march-fail-order-std.l: Likewise.
  52. * testsuite/gas/riscv/march-fail-order-x.l: Likewise.
  53. * testsuite/gas/riscv/march-fail-order-z.l: Likewise.
  54. * testsuite/gas/riscv/march-fail-porder.l: Likewise.
  55. * testsuite/gas/riscv/march-fail-rv32ef.l: Likewise.
  56. * testsuite/gas/riscv/march-fail-rv32id.l: Likewise.
  57. * testsuite/gas/riscv/march-fail-rv32iq.l: Likewise.
  58. * testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.
  59. * testsuite/gas/riscv/march-fail-single-char.l: Likewise.
  60. * testsuite/gas/riscv/march-fail-unknown-std.l: Likewise.
  61. * testsuite/gas/riscv/march-fail-unknown.l: Likewise.
  62. * testsuite/gas/riscv/march-fail-uppercase.l: Likewise.
  63. * testsuite/gas/riscv/march-fail-version.l: Likewise.
  64. * testsuite/gas/riscv/march-fail-isa-spec.d: Likewise.
  65. * testsuite/gas/riscv/march-fail-isa-spec.l: Likewise.
  66. include/
  67. * opcode/riscv.h (riscv_ext_version):
  68. Change the version type from unsigned to int.
  69. ---
  70. bfd/elfxx-riscv.c | 324 ++++++++----------
  71. bfd/elfxx-riscv.h | 11 +-
  72. gas/config/tc-riscv.c | 23 +-
  73. gas/testsuite/gas/riscv/attribute-02.d | 4 +-
  74. gas/testsuite/gas/riscv/attribute-03.d | 4 +-
  75. gas/testsuite/gas/riscv/attribute-09.d | 4 +-
  76. gas/testsuite/gas/riscv/march-fail-base-01.l | 2 +-
  77. gas/testsuite/gas/riscv/march-fail-base-02.l | 2 +-
  78. gas/testsuite/gas/riscv/march-fail-isa-spec.d | 3 +
  79. gas/testsuite/gas/riscv/march-fail-isa-spec.l | 5 +
  80. .../gas/riscv/march-fail-order-std.l | 2 +-
  81. gas/testsuite/gas/riscv/march-fail-order-x.l | 2 +-
  82. gas/testsuite/gas/riscv/march-fail-order-z.l | 2 +-
  83. gas/testsuite/gas/riscv/march-fail-porder.l | 2 +-
  84. gas/testsuite/gas/riscv/march-fail-rv32ef.l | 2 +-
  85. gas/testsuite/gas/riscv/march-fail-rv32id.l | 2 +-
  86. gas/testsuite/gas/riscv/march-fail-rv32iq.l | 3 +-
  87. gas/testsuite/gas/riscv/march-fail-rv64iq.l | 2 +-
  88. .../gas/riscv/march-fail-single-char.l | 2 +-
  89. .../gas/riscv/march-fail-unknown-std.l | 2 +-
  90. gas/testsuite/gas/riscv/march-fail-unknown.l | 2 +-
  91. .../gas/riscv/march-fail-uppercase.l | 2 +-
  92. gas/testsuite/gas/riscv/march-fail-version.l | 3 +-
  93. gas/testsuite/gas/riscv/march-ok-two-nse.d | 2 +-
  94. include/opcode/riscv.h | 4 +-
  95. 25 files changed, 193 insertions(+), 223 deletions(-)
  96. create mode 100644 gas/testsuite/gas/riscv/march-fail-isa-spec.d
  97. create mode 100644 gas/testsuite/gas/riscv/march-fail-isa-spec.l
  98. diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
  99. index 5a95c5cb6c..233f4e20d6 100644
  100. --- a/bfd/elfxx-riscv.c
  101. +++ b/bfd/elfxx-riscv.c
  102. @@ -1010,6 +1010,96 @@ riscv_elf_add_sub_reloc (bfd *abfd,
  103. return bfd_reloc_ok;
  104. }
  105. +/* Find subset in list, return NULL if not found. */
  106. +
  107. +riscv_subset_t *
  108. +riscv_lookup_subset (const riscv_subset_list_t *subset_list,
  109. + const char *subset)
  110. +{
  111. + riscv_subset_t *s;
  112. +
  113. + for (s = subset_list->head; s != NULL; s = s->next)
  114. + if (strcasecmp (s->name, subset) == 0)
  115. + return s;
  116. +
  117. + return NULL;
  118. +}
  119. +
  120. +/* Add extension to the subset list. */
  121. +
  122. +void
  123. +riscv_add_subset (riscv_subset_list_t *subset_list,
  124. + const char *subset,
  125. + int major,
  126. + int minor)
  127. +{
  128. + riscv_subset_t *s = xmalloc (sizeof *s);
  129. +
  130. + if (subset_list->head == NULL)
  131. + subset_list->head = s;
  132. +
  133. + s->name = xstrdup (subset);
  134. + s->major_version = major;
  135. + s->minor_version = minor;
  136. + s->next = NULL;
  137. +
  138. + if (subset_list->tail != NULL)
  139. + subset_list->tail->next = s;
  140. + subset_list->tail = s;
  141. +}
  142. +
  143. +/* Find the default versions for the extension before adding them to
  144. + the subset list, if their versions are RISCV_UNKNOWN_VERSION.
  145. + Afterwards, report errors if we can not find their default versions. */
  146. +
  147. +static void
  148. +riscv_parse_add_subset (riscv_parse_subset_t *rps,
  149. + const char *subset,
  150. + int major,
  151. + int minor)
  152. +{
  153. + int major_version = major;
  154. + int minor_version = minor;
  155. +
  156. + if ((major_version == RISCV_UNKNOWN_VERSION
  157. + || minor_version == RISCV_UNKNOWN_VERSION)
  158. + && rps->get_default_version != NULL)
  159. + rps->get_default_version (subset, &major_version, &minor_version);
  160. +
  161. + if (major_version == RISCV_UNKNOWN_VERSION
  162. + || minor_version == RISCV_UNKNOWN_VERSION)
  163. + {
  164. + if (subset[0] == 'x')
  165. + rps->error_handler
  166. + (_("x ISA extension `%s' must be set with the versions"),
  167. + subset);
  168. + else
  169. + rps->error_handler
  170. + (_("cannot find default versions of the ISA extension `%s'"),
  171. + subset);
  172. + return;
  173. + }
  174. +
  175. + riscv_add_subset (rps->subset_list, subset,
  176. + major_version, minor_version);
  177. +}
  178. +
  179. +/* Release subset list. */
  180. +
  181. +void
  182. +riscv_release_subset_list (riscv_subset_list_t *subset_list)
  183. +{
  184. + while (subset_list->head != NULL)
  185. + {
  186. + riscv_subset_t *next = subset_list->head->next;
  187. + free ((void *)subset_list->head->name);
  188. + free (subset_list->head);
  189. + subset_list->head = next;
  190. + }
  191. +
  192. + subset_list->tail = NULL;
  193. +}
  194. +
  195. /* Parsing extension version.
  196. Return Value:
  197. @@ -1019,25 +1109,20 @@ riscv_elf_add_sub_reloc (bfd *abfd,
  198. `rps`: Hooks and status for parsing extensions.
  199. `march`: Full arch string.
  200. `p`: Curent parsing position.
  201. - `major_version`: Parsing result of major version, using
  202. - default_major_version if version is not present in arch string.
  203. - `minor_version`: Parsing result of minor version, set to 0 if version is
  204. - not present in arch string, but set to `default_minor_version` if
  205. - `major_version` using default_major_version.
  206. - `std_ext_p`: True if parsing std extension.
  207. - `use_default_version`: Set it to True if we need the default version. */
  208. + `major_version`: Parsed major version.
  209. + `minor_version`: Parsed minor version.
  210. + `std_ext_p`: True if parsing standard extension. */
  211. static const char *
  212. riscv_parsing_subset_version (riscv_parse_subset_t *rps,
  213. const char *march,
  214. const char *p,
  215. - unsigned *major_version,
  216. - unsigned *minor_version,
  217. - bfd_boolean std_ext_p,
  218. - bfd_boolean *use_default_version)
  219. + int *major_version,
  220. + int *minor_version,
  221. + bfd_boolean std_ext_p)
  222. {
  223. bfd_boolean major_p = TRUE;
  224. - unsigned version = 0;
  225. + int version = 0;
  226. char np;
  227. *major_version = 0;
  228. @@ -1081,11 +1166,13 @@ riscv_parsing_subset_version (riscv_parse_subset_t *rps,
  229. else
  230. *minor_version = version;
  231. - /* We can not find any version in string, need to parse default version. */
  232. - if (use_default_version != NULL
  233. - && *major_version == 0
  234. - && *minor_version == 0)
  235. - *use_default_version = TRUE;
  236. + /* We can not find any version in string. */
  237. + if (*major_version == 0 && *minor_version == 0)
  238. + {
  239. + *major_version = RISCV_UNKNOWN_VERSION;
  240. + *minor_version = RISCV_UNKNOWN_VERSION;
  241. + }
  242. +
  243. return p;
  244. }
  245. @@ -1115,9 +1202,8 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
  246. {
  247. const char *all_std_exts = riscv_supported_std_ext ();
  248. const char *std_exts = all_std_exts;
  249. - unsigned major_version = 0;
  250. - unsigned minor_version = 0;
  251. - bfd_boolean use_default_version = FALSE;
  252. + int major_version;
  253. + int minor_version;
  254. char subset[2] = {0, 0};
  255. /* First letter must start with i, e or g. */
  256. @@ -1126,42 +1212,23 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
  257. case 'i':
  258. p = riscv_parsing_subset_version (rps, march, ++p,
  259. &major_version,
  260. - &minor_version, TRUE,
  261. - &use_default_version);
  262. - /* Find the default version if needed. */
  263. - if (use_default_version
  264. - && rps->get_default_version != NULL)
  265. - rps->get_default_version ("i",
  266. - &major_version,
  267. - &minor_version);
  268. - riscv_add_subset (rps->subset_list, "i",
  269. - major_version,
  270. - minor_version);
  271. + &minor_version, TRUE);
  272. + riscv_parse_add_subset (rps, "i",
  273. + major_version,
  274. + minor_version);
  275. break;
  276. case 'e':
  277. p = riscv_parsing_subset_version (rps, march, ++p,
  278. &major_version,
  279. - &minor_version, TRUE,
  280. - &use_default_version);
  281. - /* Find the default version if needed. */
  282. - if (use_default_version
  283. - && rps->get_default_version != NULL)
  284. - rps->get_default_version ("e",
  285. - &major_version,
  286. - &minor_version);
  287. - riscv_add_subset (rps->subset_list, "e",
  288. - major_version,
  289. - minor_version);
  290. -
  291. + &minor_version, TRUE);
  292. + riscv_parse_add_subset (rps, "e",
  293. + major_version,
  294. + minor_version);
  295. /* i-ext must be enabled. */
  296. - if (rps->get_default_version != NULL)
  297. - rps->get_default_version ("i",
  298. - &major_version,
  299. - &minor_version);
  300. - riscv_add_subset (rps->subset_list, "i",
  301. - major_version,
  302. - minor_version);
  303. + riscv_parse_add_subset (rps, "i",
  304. + RISCV_UNKNOWN_VERSION,
  305. + RISCV_UNKNOWN_VERSION);
  306. if (*rps->xlen > 32)
  307. {
  308. @@ -1177,27 +1244,17 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
  309. skip the setting if user set a version to it. */
  310. p = riscv_parsing_subset_version (rps, march, ++p,
  311. &major_version,
  312. - &minor_version, TRUE,
  313. - &use_default_version);
  314. + &minor_version, TRUE);
  315. /* i-ext must be enabled. */
  316. - if (rps->get_default_version != NULL)
  317. - rps->get_default_version ("i",
  318. - &major_version,
  319. - &minor_version);
  320. - riscv_add_subset (rps->subset_list, "i",
  321. - major_version,
  322. - minor_version);
  323. -
  324. + riscv_parse_add_subset (rps, "i",
  325. + RISCV_UNKNOWN_VERSION,
  326. + RISCV_UNKNOWN_VERSION);
  327. for ( ; *std_exts != 'q'; std_exts++)
  328. {
  329. subset[0] = *std_exts;
  330. - if (rps->get_default_version != NULL)
  331. - rps->get_default_version (subset,
  332. - &major_version,
  333. - &minor_version);
  334. - riscv_add_subset (rps->subset_list, subset,
  335. - major_version,
  336. - minor_version);
  337. + riscv_parse_add_subset (rps, subset,
  338. + RISCV_UNKNOWN_VERSION,
  339. + RISCV_UNKNOWN_VERSION);
  340. }
  341. break;
  342. @@ -1238,21 +1295,13 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
  343. }
  344. std_exts++;
  345. - use_default_version = FALSE;
  346. subset[0] = std_ext;
  347. p = riscv_parsing_subset_version (rps, march, ++p,
  348. &major_version,
  349. - &minor_version, TRUE,
  350. - &use_default_version);
  351. - /* Find the default version if needed. */
  352. - if (use_default_version
  353. - && rps->get_default_version != NULL)
  354. - rps->get_default_version (subset,
  355. - &major_version,
  356. - &minor_version);
  357. - riscv_add_subset (rps->subset_list, subset,
  358. - major_version,
  359. - minor_version);
  360. + &minor_version, TRUE);
  361. + riscv_parse_add_subset (rps, subset,
  362. + major_version,
  363. + minor_version);
  364. }
  365. return p;
  366. @@ -1309,11 +1358,10 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
  367. const char *p,
  368. const riscv_parse_config_t *config)
  369. {
  370. - unsigned major_version = 0;
  371. - unsigned minor_version = 0;
  372. + int major_version;
  373. + int minor_version;
  374. const char *last_name;
  375. riscv_isa_ext_class_t class;
  376. - bfd_boolean use_default_version;
  377. while (*p)
  378. {
  379. @@ -1337,14 +1385,18 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
  380. while (*++q != '\0' && *q != '_' && !ISDIGIT (*q))
  381. ;
  382. - use_default_version = FALSE;
  383. end_of_version =
  384. riscv_parsing_subset_version (rps, march, q,
  385. &major_version,
  386. - &minor_version, FALSE,
  387. - &use_default_version);
  388. + &minor_version, FALSE);
  389. *q = '\0';
  390. + if (end_of_version == NULL)
  391. + {
  392. + free (subset);
  393. + return NULL;
  394. + }
  395. +
  396. /* Check that the prefix extension is known.
  397. For 'x', anything goes but it cannot simply be 'x'.
  398. For 's', it must be known from a list and cannot simply be 's'.
  399. @@ -1384,16 +1436,9 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
  400. return NULL;
  401. }
  402. - /* Find the default version if needed. */
  403. - if (use_default_version
  404. - && rps->get_default_version != NULL)
  405. - rps->get_default_version (subset,
  406. - &major_version,
  407. - &minor_version);
  408. - riscv_add_subset (rps->subset_list, subset,
  409. - major_version,
  410. - minor_version);
  411. -
  412. + riscv_parse_add_subset (rps, subset,
  413. + major_version,
  414. + minor_version);
  415. free (subset);
  416. p += end_of_version - subset;
  417. @@ -1514,6 +1559,7 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
  418. {
  419. const char *p;
  420. size_t i;
  421. + bfd_boolean no_conflict = TRUE;
  422. for (p = arch; *p != '\0'; p++)
  423. {
  424. @@ -1580,7 +1626,7 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
  425. rps->error_handler
  426. (_("-march=%s: rv32e does not support the `f' extension"),
  427. arch);
  428. - return FALSE;
  429. + no_conflict = FALSE;
  430. }
  431. if (riscv_lookup_subset (rps->subset_list, "q") && *rps->xlen < 64)
  432. @@ -1588,7 +1634,7 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
  433. rps->error_handler
  434. (_("-march=%s: rv32 does not support the `q' extension"),
  435. arch);
  436. - return FALSE;
  437. + no_conflict = FALSE;
  438. }
  439. if (riscv_lookup_subset (rps->subset_list, "d")
  440. @@ -1597,7 +1643,7 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
  441. rps->error_handler
  442. (_("-march=%s: `d' extension requires `f' extension"),
  443. arch);
  444. - return FALSE;
  445. + no_conflict = FALSE;
  446. }
  447. if (riscv_lookup_subset (rps->subset_list, "q")
  448. @@ -1606,88 +1652,10 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
  449. rps->error_handler
  450. (_("-march=%s: `q' extension requires `d' extension"),
  451. arch);
  452. - return FALSE;
  453. - }
  454. -
  455. - return TRUE;
  456. -}
  457. -
  458. -/* Add new subset to list. */
  459. -
  460. -void
  461. -riscv_add_subset (riscv_subset_list_t *subset_list,
  462. - const char *subset,
  463. - int major,
  464. - int minor)
  465. -{
  466. - riscv_subset_t *s = xmalloc (sizeof *s);
  467. -
  468. - if (subset_list->head == NULL)
  469. - subset_list->head = s;
  470. -
  471. - s->name = xstrdup (subset);
  472. - s->major_version = major;
  473. - s->minor_version = minor;
  474. - s->next = NULL;
  475. -
  476. - if (subset_list->tail != NULL)
  477. - subset_list->tail->next = s;
  478. -
  479. - subset_list->tail = s;
  480. -}
  481. -
  482. -/* Find subset in list without version checking, return NULL if not found. */
  483. -
  484. -riscv_subset_t *
  485. -riscv_lookup_subset (const riscv_subset_list_t *subset_list,
  486. - const char *subset)
  487. -{
  488. - return riscv_lookup_subset_version
  489. - (subset_list, subset,
  490. - RISCV_DONT_CARE_VERSION,
  491. - RISCV_DONT_CARE_VERSION);
  492. -}
  493. -
  494. -/* Find subset in list with version checking, return NULL if not found. */
  495. -
  496. -riscv_subset_t *
  497. -riscv_lookup_subset_version (const riscv_subset_list_t *subset_list,
  498. - const char *subset,
  499. - int major, int minor)
  500. -{
  501. - riscv_subset_t *s;
  502. -
  503. - for (s = subset_list->head; s != NULL; s = s->next)
  504. - if (strcasecmp (s->name, subset) == 0)
  505. - {
  506. - if ((major != RISCV_DONT_CARE_VERSION)
  507. - && (s->major_version != major))
  508. - return NULL;
  509. -
  510. - if ((minor != RISCV_DONT_CARE_VERSION)
  511. - && (s->minor_version != minor))
  512. - return NULL;
  513. -
  514. - return s;
  515. - }
  516. -
  517. - return NULL;
  518. -}
  519. -
  520. -/* Release subset list. */
  521. -
  522. -void
  523. -riscv_release_subset_list (riscv_subset_list_t *subset_list)
  524. -{
  525. - while (subset_list->head != NULL)
  526. - {
  527. - riscv_subset_t *next = subset_list->head->next;
  528. - free ((void *)subset_list->head->name);
  529. - free (subset_list->head);
  530. - subset_list->head = next;
  531. + no_conflict = FALSE;
  532. }
  533. - subset_list->tail = NULL;
  534. + return no_conflict;
  535. }
  536. /* Return the number of digits for the input. */
  537. diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
  538. index 6b7cc5b0bf..45705ce31c 100644
  539. --- a/bfd/elfxx-riscv.h
  540. +++ b/bfd/elfxx-riscv.h
  541. @@ -33,7 +33,7 @@ riscv_reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
  542. extern reloc_howto_type *
  543. riscv_elf_rtype_to_howto (bfd *, unsigned int r_type);
  544. -#define RISCV_DONT_CARE_VERSION -1
  545. +#define RISCV_UNKNOWN_VERSION -1
  546. /* The information of architecture attribute. */
  547. struct riscv_subset_t
  548. @@ -64,11 +64,6 @@ extern riscv_subset_t *
  549. riscv_lookup_subset (const riscv_subset_list_t *,
  550. const char *);
  551. -extern riscv_subset_t *
  552. -riscv_lookup_subset_version (const riscv_subset_list_t *,
  553. - const char *,
  554. - int, int);
  555. -
  556. typedef struct
  557. {
  558. riscv_subset_list_t *subset_list;
  559. @@ -76,8 +71,8 @@ typedef struct
  560. ...) ATTRIBUTE_PRINTF_1;
  561. unsigned *xlen;
  562. void (*get_default_version) (const char *,
  563. - unsigned int *,
  564. - unsigned int *);
  565. + int *,
  566. + int *);
  567. } riscv_parse_subset_t;
  568. extern bfd_boolean
  569. diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
  570. index 9df6d3f415..24771b0a0b 100644
  571. --- a/gas/config/tc-riscv.c
  572. +++ b/gas/config/tc-riscv.c
  573. @@ -267,28 +267,25 @@ init_ext_version_hash (const struct riscv_ext_version *table)
  574. static void
  575. riscv_get_default_ext_version (const char *name,
  576. - unsigned int *major_version,
  577. - unsigned int *minor_version)
  578. + int *major_version,
  579. + int *minor_version)
  580. {
  581. struct riscv_ext_version *ext;
  582. - *major_version = 0;
  583. - *minor_version = 0;
  584. -
  585. if (name == NULL || default_isa_spec == ISA_SPEC_CLASS_NONE)
  586. return;
  587. ext = (struct riscv_ext_version *) str_hash_find (ext_version_hash, name);
  588. while (ext
  589. - && ext->name
  590. - && strcmp (ext->name, name) == 0)
  591. + && ext->name
  592. + && strcmp (ext->name, name) == 0)
  593. {
  594. if (ext->isa_spec_class == default_isa_spec)
  595. - {
  596. - *major_version = ext->major_version;
  597. - *minor_version = ext->minor_version;
  598. - return;
  599. - }
  600. + {
  601. + *major_version = ext->major_version;
  602. + *minor_version = ext->minor_version;
  603. + return;
  604. + }
  605. ext++;
  606. }
  607. }
  608. @@ -300,7 +297,7 @@ riscv_set_arch (const char *s)
  609. {
  610. riscv_parse_subset_t rps;
  611. rps.subset_list = &riscv_subsets;
  612. - rps.error_handler = as_fatal;
  613. + rps.error_handler = as_bad;
  614. rps.xlen = &xlen;
  615. rps.get_default_version = riscv_get_default_ext_version;
  616. diff --git a/gas/testsuite/gas/riscv/attribute-02.d b/gas/testsuite/gas/riscv/attribute-02.d
  617. index ae0195e9a2..45b89f2d62 100644
  618. --- a/gas/testsuite/gas/riscv/attribute-02.d
  619. +++ b/gas/testsuite/gas/riscv/attribute-02.d
  620. @@ -1,6 +1,6 @@
  621. -#as: -march=rv32gxargle -march-attr -misa-spec=2.2
  622. +#as: -march=rv32gxargle2p0 -march-attr -misa-spec=2.2
  623. #readelf: -A
  624. #source: empty.s
  625. Attribute Section: riscv
  626. File Attributes
  627. - Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle0p0"
  628. + Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle2p0"
  629. diff --git a/gas/testsuite/gas/riscv/attribute-03.d b/gas/testsuite/gas/riscv/attribute-03.d
  630. index 9916ff6e92..11416d63d2 100644
  631. --- a/gas/testsuite/gas/riscv/attribute-03.d
  632. +++ b/gas/testsuite/gas/riscv/attribute-03.d
  633. @@ -1,6 +1,6 @@
  634. -#as: -march=rv32gxargle_xfoo -march-attr -misa-spec=2.2
  635. +#as: -march=rv32gxargle2p0_xfoo3p0 -march-attr -misa-spec=2.2
  636. #readelf: -A
  637. #source: empty.s
  638. Attribute Section: riscv
  639. File Attributes
  640. - Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle0p0_xfoo0p0"
  641. + Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle2p0_xfoo3p0"
  642. diff --git a/gas/testsuite/gas/riscv/attribute-09.d b/gas/testsuite/gas/riscv/attribute-09.d
  643. index cad1713b0a..fc87f82c55 100644
  644. --- a/gas/testsuite/gas/riscv/attribute-09.d
  645. +++ b/gas/testsuite/gas/riscv/attribute-09.d
  646. @@ -1,6 +1,6 @@
  647. -#as: -march-attr -march=rv32i2p1m_zicsr -misa-spec=2.2
  648. +#as: -march-attr -march=rv32i2p2m_zicsr -misa-spec=20191213
  649. #readelf: -A
  650. #source: empty.s
  651. Attribute Section: riscv
  652. File Attributes
  653. - Tag_RISCV_arch: "rv32i2p1_m2p0_zicsr0p0"
  654. + Tag_RISCV_arch: "rv32i2p2_m2p0_zicsr2p0"
  655. diff --git a/gas/testsuite/gas/riscv/march-fail-base-01.l b/gas/testsuite/gas/riscv/march-fail-base-01.l
  656. index 9fa071f5b0..45d5c9ad98 100644
  657. --- a/gas/testsuite/gas/riscv/march-fail-base-01.l
  658. +++ b/gas/testsuite/gas/riscv/march-fail-base-01.l
  659. @@ -1,2 +1,2 @@
  660. .*Assembler messages:
  661. -.*Fatal error: .*first ISA extension must be `e', `i' or `g'
  662. +.*Error: .*first ISA extension must be `e', `i' or `g'
  663. diff --git a/gas/testsuite/gas/riscv/march-fail-base-02.l b/gas/testsuite/gas/riscv/march-fail-base-02.l
  664. index 6fc4dfa7ba..f6a3c1dc51 100644
  665. --- a/gas/testsuite/gas/riscv/march-fail-base-02.l
  666. +++ b/gas/testsuite/gas/riscv/march-fail-base-02.l
  667. @@ -1,2 +1,2 @@
  668. .*Assembler messages:
  669. -.*Fatal error: .*rv64e is not a valid base ISA
  670. +.*Error: .*rv64e is not a valid base ISA
  671. diff --git a/gas/testsuite/gas/riscv/march-fail-isa-spec.d b/gas/testsuite/gas/riscv/march-fail-isa-spec.d
  672. new file mode 100644
  673. index 0000000000..af707e232e
  674. --- /dev/null
  675. +++ b/gas/testsuite/gas/riscv/march-fail-isa-spec.d
  676. @@ -0,0 +1,3 @@
  677. +#as: -march=rv32iln_zicsr_xargle_xbargle -misa-spec=20191213
  678. +#source: empty.s
  679. +#error_output: march-fail-isa-spec.l
  680. diff --git a/gas/testsuite/gas/riscv/march-fail-isa-spec.l b/gas/testsuite/gas/riscv/march-fail-isa-spec.l
  681. new file mode 100644
  682. index 0000000000..e714ddf7ba
  683. --- /dev/null
  684. +++ b/gas/testsuite/gas/riscv/march-fail-isa-spec.l
  685. @@ -0,0 +1,5 @@
  686. +.*Assembler messages:
  687. +.*Error: cannot find default versions of the ISA extension `l'
  688. +.*Error: cannot find default versions of the ISA extension `n'
  689. +.*Error: x ISA extension `xargle' must be set with the versions
  690. +.*Error: x ISA extension `xbargle' must be set with the versions
  691. diff --git a/gas/testsuite/gas/riscv/march-fail-order-std.l b/gas/testsuite/gas/riscv/march-fail-order-std.l
  692. index 666a8c0d2c..9e3ce5e8d9 100644
  693. --- a/gas/testsuite/gas/riscv/march-fail-order-std.l
  694. +++ b/gas/testsuite/gas/riscv/march-fail-order-std.l
  695. @@ -1,2 +1,2 @@
  696. .*Assembler messages:
  697. -.*Fatal error: .*standard ISA extension `m' is not in canonical order
  698. +.*Error: .*standard ISA extension `m' is not in canonical order
  699. diff --git a/gas/testsuite/gas/riscv/march-fail-order-x.l b/gas/testsuite/gas/riscv/march-fail-order-x.l
  700. index f7b383d855..025db14686 100644
  701. --- a/gas/testsuite/gas/riscv/march-fail-order-x.l
  702. +++ b/gas/testsuite/gas/riscv/march-fail-order-x.l
  703. @@ -1,2 +1,2 @@
  704. .*Assembler messages:
  705. -.*Fatal error: .*x ISA extension `xargle' is not in alphabetical order. It must come before `xbargle'
  706. +.*Error: .*x ISA extension `xargle' is not in alphabetical order. It must come before `xbargle'
  707. diff --git a/gas/testsuite/gas/riscv/march-fail-order-z.l b/gas/testsuite/gas/riscv/march-fail-order-z.l
  708. index 1129219f2b..a98c53a279 100644
  709. --- a/gas/testsuite/gas/riscv/march-fail-order-z.l
  710. +++ b/gas/testsuite/gas/riscv/march-fail-order-z.l
  711. @@ -1,2 +1,2 @@
  712. .*Assembler messages:
  713. -.*Fatal error: .*z ISA extension `zicsr' is not in alphabetical order. It must come before `zifencei'
  714. +.*Error: .*z ISA extension `zicsr' is not in alphabetical order. It must come before `zifencei'
  715. diff --git a/gas/testsuite/gas/riscv/march-fail-porder.l b/gas/testsuite/gas/riscv/march-fail-porder.l
  716. index a06d586580..c5496eab49 100644
  717. --- a/gas/testsuite/gas/riscv/march-fail-porder.l
  718. +++ b/gas/testsuite/gas/riscv/march-fail-porder.l
  719. @@ -1,2 +1,2 @@
  720. .*Assembler messages:
  721. -.*Fatal error: .*unexpected ISA string at end:.*
  722. +.*Error: .*unexpected ISA string at end:.*
  723. diff --git a/gas/testsuite/gas/riscv/march-fail-rv32ef.l b/gas/testsuite/gas/riscv/march-fail-rv32ef.l
  724. index d2d915d872..e6d93f28fa 100644
  725. --- a/gas/testsuite/gas/riscv/march-fail-rv32ef.l
  726. +++ b/gas/testsuite/gas/riscv/march-fail-rv32ef.l
  727. @@ -1,2 +1,2 @@
  728. .*Assembler messages:
  729. -.*Fatal error: .*rv32e does not support the `f' extension
  730. +.*Error: .*rv32e does not support the `f' extension
  731. diff --git a/gas/testsuite/gas/riscv/march-fail-rv32id.l b/gas/testsuite/gas/riscv/march-fail-rv32id.l
  732. index 29b2717ef7..c5f990cd73 100644
  733. --- a/gas/testsuite/gas/riscv/march-fail-rv32id.l
  734. +++ b/gas/testsuite/gas/riscv/march-fail-rv32id.l
  735. @@ -1,2 +1,2 @@
  736. .*Assembler messages:
  737. -.*Fatal error: .*`d' extension requires `f' extension
  738. +.*Error: .*`d' extension requires `f' extension
  739. diff --git a/gas/testsuite/gas/riscv/march-fail-rv32iq.l b/gas/testsuite/gas/riscv/march-fail-rv32iq.l
  740. index 361c381b86..8143dd441d 100644
  741. --- a/gas/testsuite/gas/riscv/march-fail-rv32iq.l
  742. +++ b/gas/testsuite/gas/riscv/march-fail-rv32iq.l
  743. @@ -1,2 +1,3 @@
  744. .*Assembler messages:
  745. -.*Fatal error: .*rv32 does not support the `q' extension
  746. +.*Error: .*rv32 does not support the `q' extension
  747. +.*Error: .*`q' extension requires `d' extension
  748. diff --git a/gas/testsuite/gas/riscv/march-fail-rv64iq.l b/gas/testsuite/gas/riscv/march-fail-rv64iq.l
  749. index 76a41043e3..787f46d1ed 100644
  750. --- a/gas/testsuite/gas/riscv/march-fail-rv64iq.l
  751. +++ b/gas/testsuite/gas/riscv/march-fail-rv64iq.l
  752. @@ -1,2 +1,2 @@
  753. .*Assembler messages:
  754. -.*Fatal error: .*`q' extension requires `d' extension
  755. +.*Error: .*`q' extension requires `d' extension
  756. diff --git a/gas/testsuite/gas/riscv/march-fail-single-char.l b/gas/testsuite/gas/riscv/march-fail-single-char.l
  757. index 6466e164ff..435d0b23a4 100644
  758. --- a/gas/testsuite/gas/riscv/march-fail-single-char.l
  759. +++ b/gas/testsuite/gas/riscv/march-fail-single-char.l
  760. @@ -1,2 +1,2 @@
  761. .*Assembler messages:
  762. -.*Fatal error: .*unknown (s|h|z|x) ISA extension `(s|h|z|x)'
  763. +.*Error: .*unknown (s|h|z|x) ISA extension `(s|h|z|x)'
  764. diff --git a/gas/testsuite/gas/riscv/march-fail-unknown-std.l b/gas/testsuite/gas/riscv/march-fail-unknown-std.l
  765. index cb856377b3..75cdda3894 100644
  766. --- a/gas/testsuite/gas/riscv/march-fail-unknown-std.l
  767. +++ b/gas/testsuite/gas/riscv/march-fail-unknown-std.l
  768. @@ -1,2 +1,2 @@
  769. .*Assembler messages:
  770. -.*Fatal error: .*unknown standard ISA extension `[^eimafdqiglcbjtpvn]'
  771. +.*Error: .*unknown standard ISA extension `[^eimafdqiglcbjtpvn]'
  772. diff --git a/gas/testsuite/gas/riscv/march-fail-unknown.l b/gas/testsuite/gas/riscv/march-fail-unknown.l
  773. index 28a864dbb7..874b8d461b 100644
  774. --- a/gas/testsuite/gas/riscv/march-fail-unknown.l
  775. +++ b/gas/testsuite/gas/riscv/march-fail-unknown.l
  776. @@ -1,2 +1,2 @@
  777. .*Assembler messages:
  778. -.*Fatal error: .*unknown (s|h|z) ISA extension `(s|h|z)foo'
  779. +.*Error: .*unknown (s|h|z) ISA extension `(s|h|z)foo'
  780. diff --git a/gas/testsuite/gas/riscv/march-fail-uppercase.l b/gas/testsuite/gas/riscv/march-fail-uppercase.l
  781. index 292c18adcc..14f03d6954 100644
  782. --- a/gas/testsuite/gas/riscv/march-fail-uppercase.l
  783. +++ b/gas/testsuite/gas/riscv/march-fail-uppercase.l
  784. @@ -1,2 +1,2 @@
  785. .*Assembler messages:
  786. -.*Fatal error: .*ISA string cannot contain uppercase letters
  787. +.*Error: .*ISA string cannot contain uppercase letters
  788. diff --git a/gas/testsuite/gas/riscv/march-fail-version.l b/gas/testsuite/gas/riscv/march-fail-version.l
  789. index b5d0b91350..c7f8a4d548 100644
  790. --- a/gas/testsuite/gas/riscv/march-fail-version.l
  791. +++ b/gas/testsuite/gas/riscv/march-fail-version.l
  792. @@ -1,2 +1,3 @@
  793. .*Assembler messages:
  794. -.*Fatal error: .*expect number after `2p'
  795. +.*Error: cannot find default versions of the ISA extension `p'
  796. +.*Error: .*expect number after `2p'
  797. diff --git a/gas/testsuite/gas/riscv/march-ok-two-nse.d b/gas/testsuite/gas/riscv/march-ok-two-nse.d
  798. index 0fe503793b..e78cf9dd09 100644
  799. --- a/gas/testsuite/gas/riscv/march-ok-two-nse.d
  800. +++ b/gas/testsuite/gas/riscv/march-ok-two-nse.d
  801. @@ -1,4 +1,4 @@
  802. -#as: -march=rv32imafd_xargle_xbargle
  803. +#as: -march=rv32imafd_xargle2p0_xbargle3p0
  804. #objdump: -dr
  805. #source: empty.s
  806. diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
  807. index 2f1bc793e5..94a13803d9 100644
  808. --- a/include/opcode/riscv.h
  809. +++ b/include/opcode/riscv.h
  810. @@ -360,8 +360,8 @@ struct riscv_ext_version
  811. {
  812. const char *name;
  813. enum riscv_isa_spec_class isa_spec_class;
  814. - unsigned int major_version;
  815. - unsigned int minor_version;
  816. + int major_version;
  817. + int minor_version;
  818. };
  819. /* All RISC-V CSR belong to one of these classes. */
  820. --
  821. 2.33.0