[PATCH] RISC-V: Clear EF_RISCV_RVC/EF_RISCV_TSO when RVC/TSO is disabled using .attribute arch

Yu-Cheng Liang yclwlcy@gmail.com
Mon Nov 11 08:49:51 GMT 2024


If we enable RVC/TSO using -march and disable RVC/TSO using .attribute
arch, EF_RISCV_RVC/EF_RISCV_TSO won't be cleared in the current
implementation.

Signed-off-by: Yu-Cheng Liang <yclwlcy@gmail.com>
---
 gas/config/tc-riscv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index e19142dca19..3aec4d1d980 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -5666,7 +5666,13 @@ s_riscv_attribute (int ignored ATTRIBUTE_UNUSED)
       old_xlen = xlen;
       attr = elf_known_obj_attributes_proc (stdoutput);
       if (!start_assemble)
-       riscv_set_arch (attr[Tag_RISCV_arch].s);
+       {
+         riscv_set_arch (attr[Tag_RISCV_arch].s);
+         if (!riscv_opts.rvc)
+           elf_flags &= ~(EF_RISCV_RVC);
+         if (!riscv_subset_supports (&riscv_rps_as, "ztso"))
+           elf_flags &= ~(EF_RISCV_TSO);
+       }
       else
         as_fatal (_("architecture elf attributes must set before "
                     "any instructions"));
--
2.45.2


More information about the Binutils mailing list