]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Deprecate ".option arch, -ext" for users due to its controversial use
authorNelson Chu <nelson@rivosinc.com>
Wed, 9 Jul 2025 02:47:02 +0000 (10:47 +0800)
committerNelson Chu <nelson@rivosinc.com>
Thu, 10 Jul 2025 11:16:33 +0000 (19:16 +0800)
Before we figure out the whole remove situations for ".option arch, -ext", and
have any RISC-V public spec defines it, we should just deprecate it.

16 files changed:
bfd/elfxx-riscv.c
bfd/elfxx-riscv.h
gas/NEWS
gas/config/tc-riscv.c
gas/doc/c-riscv.texi
gas/testsuite/gas/riscv/align-1.s
gas/testsuite/gas/riscv/dis-addr-addiw.s
gas/testsuite/gas/riscv/dis-addr-overflow.s
gas/testsuite/gas/riscv/ext.s
gas/testsuite/gas/riscv/mapping-x.s
gas/testsuite/gas/riscv/mapping.s
gas/testsuite/gas/riscv/option-arch-fail.l
gas/testsuite/gas/riscv/option-arch-fail.s
gas/testsuite/gas/riscv/option-arch.s
gas/testsuite/gas/riscv/shamt-32.s
gas/testsuite/gas/riscv/shamt-64.s

index 43d3c0d088473b65d0c745b282717886124a4ca8..776bfd5cea046059e1a4d08963a80b6a92b852bf 100644 (file)
@@ -2602,7 +2602,7 @@ riscv_remove_subset (riscv_subset_list_t *subset_list,
    called from riscv_update_subset./
 
    The IMPLICIT_EXTS, +extension[version] [,...,+extension_n[version_n]]
-                     -extension [,...,-extension_n],
+                     (Deprecated) -extension [,...,-extension_n],
                      full ISA.  */
 
 static bool
@@ -2694,16 +2694,26 @@ riscv_update_subset1 (riscv_parse_subset_t *rps,
          return false;
        }
 
-      if (explicit_subset == NULL
-         && (strcmp (subset, "i") == 0
-             || strcmp (subset, "e") == 0
-             || strcmp (subset, "g") == 0))
+      if (explicit_subset == NULL)
        {
-         rps->error_handler
-           (_("%scannot + or - base extension `%s' in %s `%s'"),
-              errmsg_internal, subset, errmsg_caller, implicit_exts);
-         free (subset);
-         return false;
+         if (removed)
+           {
+             rps->error_handler
+               (_("%sdeprecated - extension `%s' in %s `%s'"),
+                  errmsg_internal, subset, errmsg_caller, implicit_exts);
+             free (subset);
+             return false;
+           }
+         else if (strcmp (subset, "i") == 0
+                  || strcmp (subset, "e") == 0
+                  || strcmp (subset, "g") == 0)
+           {
+             rps->error_handler
+               (_("%scannot + base extension `%s' in %s `%s'"),
+                  errmsg_internal, subset, errmsg_caller, implicit_exts);
+             free (subset);
+             return false;
+           }
        }
 
       if (removed)
@@ -2729,8 +2739,8 @@ riscv_update_subset1 (riscv_parse_subset_t *rps,
   return no_conflict;
 }
 
-/* Add/Remove an extension to/from the subset list.  This is used for
-   the .option rvc or norvc, and .option arch directives.  */
+/* Add an extension to/from the subset list.  This is used for the .option rvc
+   and .option arch directives.  */
 
 bool
 riscv_update_subset (riscv_parse_subset_t *rps,
@@ -2739,6 +2749,16 @@ riscv_update_subset (riscv_parse_subset_t *rps,
   return riscv_update_subset1 (rps, NULL, str);
 }
 
+/* Called from .option norvc directives.  */
+
+bool
+riscv_update_subset_norvc (riscv_parse_subset_t *rps)
+{
+  return riscv_update_subset1 (rps, rps->subset_list->head,
+                              "-c,-zca,-zcd,-zcf,-zcb,-zce,-zcmp,-zcmt,"
+                              "-zcmop,-zclsd");
+}
+
 /* Check if the FEATURE subset is supported or not in the subset list.
    Return true if it is supported; Otherwise, return false.  */
 
index db494d08a0c7c5fb2499d4b4526bfdc4078a1242..fbbefb5ac1834723e6fea6c696315e2b21fda436 100644 (file)
@@ -118,6 +118,9 @@ riscv_copy_subset_list (riscv_subset_list_t *);
 extern bool
 riscv_update_subset (riscv_parse_subset_t *, const char *);
 
+extern bool
+riscv_update_subset_norvc (riscv_parse_subset_t *);
+
 extern bool
 riscv_subset_supports (riscv_parse_subset_t *, const char *);
 
index 66a9a7a30df25377b2f79b19564ef83fa17b3477..cbca8fe8656281901c5c80acd18a9d7c92ff3866 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -14,6 +14,9 @@
 * Support for x86 AVX10.2 256 bit rounding has been dropped, as all the
   hardware would directly support 512 bit vecotr width.
 
+* For RISC-V, the ".option arch, -ext" format is deprecated due to its
+  controversial use.
+
 * For RISC-V, stop generating mapping symbols $x and replace with $x<isa>.  The
   $x was defined to have the same ISA as previous $x<isa>, but now is defined
   to have the same ISA as elf architecture attribute.  Once used .option arch
index f0b119fbfedfae31ef8b310e3cb57df0b0469df7..8a3356888d29a79d92c922d9c42bc41a8accbeb6 100644 (file)
@@ -5073,8 +5073,7 @@ s_riscv_option (int x ATTRIBUTE_UNUSED)
     }
   else if (strcmp (name, "norvc") == 0)
     {
-      riscv_update_subset (&riscv_rps_as, "-c,-zca,-zcd,-zcf,-zcb,-zce,-zcmp,"
-                                         "-zcmt,-zcmop,-zclsd");
+      riscv_update_subset_norvc (&riscv_rps_as);
       riscv_arch_str (xlen, riscv_rps_as.subset_list, true/* update */);
       riscv_set_rvc (false);
     }
index a4c819e693a515a06c460a2e4bfb1bdd5069bc67..1791b882567a6eba5d140c4d628889b458c1ad2f 100644 (file)
@@ -181,12 +181,14 @@ instead of just
 It's not expected that options are changed in this manner during regular use,
 but there are a handful of esoteric cases like the one above where users need
 to disable particular features of the assembler for particular code sequences.
-However, it's also useful to enable/disable the extensions for some specific
-code regions by @samp{.option arch, +-}.  This is very common in the ifunc
-libraries.  We can support functions which are implemented by different
-extensions in the same library, but these should not affect any file-level
-settings, like the elf architecture attribute.  The complete list of option
-arguments is shown below:
+However, it's also useful to enable and reset the extensions for some specific
+code regions by @samp{.option arch, +ext} and @samp{.option arch, ISA}.  Or
+use @samp{.option push} and @samp{.option pop} at the beginning and end of the
+code, so that we can indirectly turn on and off extensions in this range.  This
+is very common in the ifunc libraries.  We can support functions which are
+implemented by different extensions in the same library, but these should not
+affect any file-level settings, like the elf architecture attribute.  The
+complete list of option arguments is shown below:
 
 @table @code
 @item push
@@ -217,17 +219,11 @@ desirable.
 Enables or disables the CSR checking.
 
 @item arch, @var{+extension[version]} [,...,@var{+extension_n[version_n]}]
-@itemx arch, @var{-extension} [,...,@var{-extension_n}]
 @itemx arch, @var{ISA}
-Enables or disables the extensions for specific code region.  For example,
-@samp{.option arch, +m2p0} means add m extension with version 2.0, and
-@samp{.option arch, -f, -d} means remove extensions, f and d, from the
-architecture string.  Note that, @samp{.option arch, +c, -c} have the same
-behavior as @samp{.option rvc, norvc}.  However, they are also undesirable
-sometimes.  Besides, @samp{.option arch, -i} is illegal, since we cannot
-remove the base i extension anytime.  If you want to reset the whole ISA
-string, you can also use @samp{.option arch, rv32imac} to overwrite the
-previous settings.
+Enable or reset the extensions for specific code region.  For example,
+@samp{.option arch, +m2p0} means add m extension with version 2.0.
+@samp{.option arch, rv32imac} means reset and overwrite the previous settings
+by rv32imac.
 @end table
 
 @cindex INSN directives
index ec28556e7be65636ce57dfa83a2ab1bceb2f93df..ee6a94dea78ce376f7a32bf3deb0bbe889345903 100644 (file)
@@ -1,3 +1,3 @@
-       .option arch, -c
+       .option norvc
        .align 2
        .align 1
index 7c878f86dd6208dc184379722659f4d15d7d83c4..38dc1c9fc6b84ca1f3b071d04d2151b904eb1bcf 100644 (file)
@@ -11,7 +11,7 @@
        .global _start
 _start:
        .option push
-       .option arch, -c
+       .option norvc
        # _start + 0x00
        auipc   t0, 0
        addiw   t1, t0, 0x18
index 77ca39c07b66d4a15fd413081fad876a5015976c..db48ae3f24b0634c40a216e58b8f950203d0a1a6 100644 (file)
@@ -24,7 +24,7 @@ topbase = 0
 
 target:
        .option push
-       .option arch, -c
+       .option norvc
        ## Use hi_addr
        # Load
        lui     t0, 0xfffff
@@ -50,7 +50,7 @@ target:
        c.addi  t6, -20
 .ifdef rv64
        .option push
-       .option arch, -c
+       .option norvc
        # ADDIW (not compressed)
        lui     s6, 0xffff8
        addiw   s7, s6, -24
index 0268dcafc1d3576cba112fa0c4a8bca1ad830933..b6ccce0304c09a39fae5b241219453f029932251 100644 (file)
@@ -1,5 +1,5 @@
 target:
-       .option arch, -c
+       .option norvc
        zext.b  a0, a0
        zext.h  a0, a0
        sext.b  a0, a0
index f17cf2295ca7c595b35e8bd9f54f39bbbd936e40..21312539f6618368526fee9f6828220e127bc3f3 100644 (file)
@@ -1,5 +1,5 @@
 .attribute arch, "rv32ic"
-.option arch, -c
+.option norvc
 .insn 4, 0x00000013
 $x:
 .insn 2, 0x0001
index 0382cfc3c655501edb66bfc92cd20ff63bab3c0e..c8ed24cc00d4ab288344911710fe9db11ceba53c 100644 (file)
@@ -11,7 +11,7 @@ j     funcA                   # rv32ic
 .globl funcB
 funcB:
 addi   a0, zero, 2             # rv32ic, need to be added since start of section
-.option arch, -c
+.option norvc
 j      funcB                   # rv32i
 .option pop
 
@@ -35,7 +35,7 @@ addi  a0, zero, 2             # $x, but same as previous addi, so removed
 .option arch, +c
 addi   a0, zero, 1             # $xrv32ic
 .byte  1                       # $d
-.option arch, -c
+.option norvc
 .align 3                       # odd alignment, $x replaced by $d + $x
 addi   a0, zero, 2             # $xrv32i
 .option pop
@@ -81,7 +81,7 @@ addi  a0, zero, 2
 .align 2                       # $xrv32ic, .align and .fill are in the different frag, so neither be removed,
                                # but will be removed in riscv_check_mapping_symbols
 .fill  1, 0, 0                 # $d with zero size, removed in make_mapping_symbol when adding $xrv32ic
-.option arch, -c
+.option norvc
 addi   a0, zero, 1             # $xrv32i
 addi   a0, zero, 2
 .option pop
@@ -89,7 +89,7 @@ addi  a0, zero, 2
 .section .text.last.section, "ax"
 .option push
 .option norelax
-.option arch, -c
+.option norvc
 addi   a0, zero, 1             # $xrv32i
 .word  1                       # $d
 .align 2                       # zero section padding, $x at the end of section, removed in riscv_check_mapping_symbols
@@ -112,7 +112,7 @@ addi        a0, zero, 2             # $xrv32iac
 .option arch, rv32ic
 .balign        4                       # $xrv32ic, add at the start of section
 addi   a0, zero, 1             # $x, won't added
-.option arch, -c
+.option norvc
 .align 3                       # $x, won't added
 addi   a0, zero, 2             # $xrv32i
 .option pop
index d83f01d8ad5c63d8be8809bb3a9ccc6fc95a7017..191f088c21b8f174fc33482f1aed712c0d89460e 100644 (file)
@@ -1,8 +1,9 @@
 .*Assembler messages:
 .*Error: m2p0: ISA string must begin with rv32, rv64 or Profiles
-.*Error: cannot \+ or \- base extension `i' in .option arch `\-i'
-.*Error: cannot \+ or \- base extension `e' in .option arch `\+e'
-.*Error: cannot \+ or \- base extension `g' in .option arch `\-g'
+.*Error: deprecated \- extension `i' in .option arch `\-i'
+.*Error: cannot \+ base extension `e' in .option arch `\+e'
+.*Error: deprecated \- extension `g' in .option arch `\-g'
+.*Error: deprecated \- extension `c' in .option arch `\-c'
 .*Error: unknown ISA extension `zsubset' in .option arch `\+zsubset2p0'
 .*Error: unknown ISA extension `f2p0_d' in .option arch `\+f2p0_d2p0'
 .*Error: unknown ISA extension `' in .option arch `\+'
index 101587aee16ead486a1070e7a297eaf388285b65..2ba7a16a3afc5c6f563316052e53bca15dd88c40 100644 (file)
@@ -4,6 +4,7 @@
 .option arch, -i
 .option arch, +e
 .option arch, -g
+.option arch, -c
 .option arch, +zsubset2p0
 .option arch, +f2p0_d2p0
 .option arch, +
index a37659f2c6cfc3619787917198efd22af5a78af9..8836bc153b18d2d978672553318be91f304bee44 100644 (file)
@@ -1,7 +1,8 @@
 .attribute arch, "rv64ic"      # file-level, rv64ic
 add    a0, a0, a1
 .option push
-.option arch, +d2p0, -c, +xvendor1p0
+.option arch, +d2p0, +xvendor1p0
+.option norvc
 add    a0, a0, a1              # func-level, rv64i_d2p0_xvendor1p0
 frcsr  a0
 .option pop
index a673f8810dc4c9f6888af0479fd0722b5074eda3..9fa18fb38a9a81979bc413e92b5facb53a963a1b 100644 (file)
@@ -1,4 +1,4 @@
-       .option arch, -c
+       .option norvc
        slli    a0, a0, 0
        slli    a0, a0, 31
        slli    a0, a0, 32
index 8878318f4a709dd20428f00b938d50065a733c2a..5ca5e6daa3de01701fd3e67f04f16efdf83570c6 100644 (file)
@@ -1,4 +1,4 @@
-       .option arch, -c
+       .option norvc
        slli    a0, a0, 0
        slli    a0, a0, 31
        slli    a0, a0, 32