RISC-V: Imply 'Zicsr' from privileged extensions with CSRs
authorTsukasa OI <research_trasio@irq.a4lg.com>
Mon, 5 Sep 2022 08:11:54 +0000 (08:11 +0000)
committerTsukasa OI <research_trasio@irq.a4lg.com>
Fri, 14 Oct 2022 05:21:42 +0000 (05:21 +0000)
'H', 'Smstateen', 'Sscofpmf' and 'Sstc' are four privileged extensions with
their CSR definitions and 'Smepmp' is a privileged extension with additional
CSR bits.

Volume II: Privileged Architecture of the RISC-V ISA Manual states that the
privileged architecture requires the 'Zicsr' extension.  However, current
GNU Binutils has no direct way whether the program has dependency to the
privileged architecture itself.

As a workaround, we should add implications from privileged extensions that
either add new CSRs, extend existing CSRs or depends on using CSRs.

This commit adds such implications for existing privileged extensions that
satisfy this condition.

gas/ChangeLog:

* testsuite/gas/riscv/march-imply-h.d: New test, at least for 'H'.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_implicit_subsets): Add 'Zicsr'
implicications for privileged extensions 'H', 'Smstateen',
'Sscofpmf', 'Sstc' and 'Smepmp'.

bfd/elfxx-riscv.c
gas/testsuite/gas/riscv/march-imply-h.d [new file with mode: 0644]

index 1bcc6c0acb4495005aa40a06b489b9447fcf47a2..f0c91cc97f7f98a1b01b807a7b9ae72eb1b88173 100644 (file)
@@ -1047,6 +1047,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
   {"g", "zicsr",       check_implicit_always},
   {"g", "zifencei",    check_implicit_always},
   {"m", "zmmul",       check_implicit_always},
+  {"h", "zicsr",       check_implicit_always},
   {"q", "d",           check_implicit_always},
   {"v", "d",           check_implicit_always},
   {"v", "zve64d",      check_implicit_always},
@@ -1096,6 +1097,10 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
   {"zks", "zbkx",      check_implicit_always},
   {"zks", "zksed",     check_implicit_always},
   {"zks", "zksh",      check_implicit_always},
+  {"smepmp", "zicsr",          check_implicit_always},
+  {"smstateen", "zicsr",       check_implicit_always},
+  {"sscofpmf", "zicsr",                check_implicit_always},
+  {"sstc", "zicsr",            check_implicit_always},
   {NULL, NULL, NULL}
 };
 
diff --git a/gas/testsuite/gas/riscv/march-imply-h.d b/gas/testsuite/gas/riscv/march-imply-h.d
new file mode 100644 (file)
index 0000000..04ad9f6
--- /dev/null
@@ -0,0 +1,6 @@
+#as: -march=rv32ih -march-attr -misa-spec=20191213 -mpriv-spec=1.12
+#readelf: -A
+#source: empty.s
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: "rv32i2p1_h1p0_zicsr2p0"