0005-RISC-V-Don-t-allow-any-uppercase-letter-in-the-arch-.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 537d1469b43f7c60cbdd196727afd186951a1286 Mon Sep 17 00:00:00 2001
  2. From: Nelson Chu <nelson.chu@sifive.com>
  3. Date: Sat, 21 Nov 2020 11:19:58 +0800
  4. Subject: [PATCH 05/48] RISC-V: Don't allow any uppercase letter in the arch
  5. string.
  6. Although I cannot find any RISC-V specs said that uppercases are not
  7. allowed in the arhc string, but seems like it is an established fact
  8. both for GNU and LLVM. Therefore, we shouldn't allow the uppercases
  9. for the non-standard x extensions, too.
  10. bfd/
  11. * elfxx-riscv.c (riscv_parse_subset): ISA string cannot contain
  12. any uppercase letter.
  13. gas/
  14. * testsuite/gas/riscv/march-fail-uppercase-base.d: Updated.
  15. * testsuite/gas/riscv/march-fail-uppercase.l: Updated.
  16. * testsuite/gas/riscv/march-fail-uppercase-x.d: New testcase.
  17. ---
  18. bfd/elfxx-riscv.c | 14 +++++++++++++-
  19. .../gas/riscv/march-fail-uppercase-base.d | 2 +-
  20. gas/testsuite/gas/riscv/march-fail-uppercase-x.d | 3 +++
  21. gas/testsuite/gas/riscv/march-fail-uppercase.l | 2 +-
  22. 4 files changed, 18 insertions(+), 3 deletions(-)
  23. create mode 100644 gas/testsuite/gas/riscv/march-fail-uppercase-x.d
  24. diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
  25. index dc196e0e12..d29bb0375e 100644
  26. --- a/bfd/elfxx-riscv.c
  27. +++ b/bfd/elfxx-riscv.c
  28. @@ -1495,9 +1495,21 @@ bfd_boolean
  29. riscv_parse_subset (riscv_parse_subset_t *rps,
  30. const char *arch)
  31. {
  32. - const char *p = arch;
  33. + const char *p;
  34. size_t i;
  35. + for (p = arch; *p != '\0'; p++)
  36. + {
  37. + if (ISUPPER (*p))
  38. + {
  39. + rps->error_handler
  40. + (_("-march=%s: ISA string cannot contain uppercase letters"),
  41. + arch);
  42. + return FALSE;
  43. + }
  44. + }
  45. +
  46. + p = arch;
  47. if (strncmp (p, "rv32", 4) == 0)
  48. {
  49. *rps->xlen = 32;
  50. diff --git a/gas/testsuite/gas/riscv/march-fail-uppercase-base.d b/gas/testsuite/gas/riscv/march-fail-uppercase-base.d
  51. index 74b55ea165..8b595856b4 100644
  52. --- a/gas/testsuite/gas/riscv/march-fail-uppercase-base.d
  53. +++ b/gas/testsuite/gas/riscv/march-fail-uppercase-base.d
  54. @@ -1,3 +1,3 @@
  55. #as: -march=rv32I
  56. #source: empty.s
  57. -#error_output: march-fail-base-01.l
  58. +#error_output: march-fail-uppercase.l
  59. diff --git a/gas/testsuite/gas/riscv/march-fail-uppercase-x.d b/gas/testsuite/gas/riscv/march-fail-uppercase-x.d
  60. new file mode 100644
  61. index 0000000000..316351fce8
  62. --- /dev/null
  63. +++ b/gas/testsuite/gas/riscv/march-fail-uppercase-x.d
  64. @@ -0,0 +1,3 @@
  65. +#as: -march=rv32ic_zicsr_xARGLE
  66. +#source: empty.s
  67. +#error_output: march-fail-uppercase.l
  68. diff --git a/gas/testsuite/gas/riscv/march-fail-uppercase.l b/gas/testsuite/gas/riscv/march-fail-uppercase.l
  69. index 2053135922..292c18adcc 100644
  70. --- a/gas/testsuite/gas/riscv/march-fail-uppercase.l
  71. +++ b/gas/testsuite/gas/riscv/march-fail-uppercase.l
  72. @@ -1,2 +1,2 @@
  73. .*Assembler messages:
  74. -.*Fatal error: .*unknown (standard|z) ISA extension.*
  75. +.*Fatal error: .*ISA string cannot contain uppercase letters
  76. --
  77. 2.33.0