[binutils-gdb] RISC-V: Ignore the deprecated privileged spec attributes

Kito Cheng kito@sourceware.org
Tue Nov 3 14:50:17 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2394c2445caa44e30dd58f0b08d7a6a5cc2c33da

commit 2394c2445caa44e30dd58f0b08d7a6a5cc2c33da
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Fri Oct 23 17:30:33 2026 +0800

    RISC-V: Ignore the deprecated privileged spec attributes
    
    The RISC-V psABI has deprecated Tag_RISCV_priv_spec,
    Tag_RISCV_priv_spec_minor and Tag_RISCV_priv_spec_revision.
    
    The assembler no longer emits them when CSR or privileged instructions
    are used, so riscv_is_priv_insn and explicit_priv_attr are removed.
    
    The linker ignores them in the input and does not output them, so the
    1.9.1 conflict warning is gone too.  The attr-merge-priv-spec tests are
    reduced to one test that checks the attributes are dropped, and the gas
    tests that checked the emitted attributes are removed or updated.

Diff:
---
 bfd/elfxx-riscv.c                                  | 59 +++--------------
 gas/config/tc-riscv.c                              | 76 +---------------------
 gas/doc/c-riscv.texi                               | 11 ++--
 gas/testsuite/gas/riscv/attribute-11.d             |  2 -
 gas/testsuite/gas/riscv/attribute-11.s             |  3 +-
 gas/testsuite/gas/riscv/attribute-12.d             |  2 -
 gas/testsuite/gas/riscv/attribute-14.s             | 14 ----
 gas/testsuite/gas/riscv/attribute-14a.d            |  8 ---
 gas/testsuite/gas/riscv/attribute-14b.d            |  8 ---
 gas/testsuite/gas/riscv/attribute-14c.d            |  8 ---
 gas/testsuite/gas/riscv/attribute-14d.d            |  8 ---
 gas/testsuite/gas/riscv/attribute-15.d             |  8 ---
 gas/testsuite/gas/riscv/attribute-16.d             |  6 --
 gas/testsuite/gas/riscv/attribute-priv-ignored.d   |  2 -
 .../ld-riscv-elf/attr-merge-priv-spec-01.d         |  7 +-
 .../ld-riscv-elf/attr-merge-priv-spec-02.d         | 10 ---
 .../ld-riscv-elf/attr-merge-priv-spec-03.d         | 10 ---
 ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s | 12 ----
 ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s |  1 -
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp         |  2 -
 20 files changed, 17 insertions(+), 240 deletions(-)

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 00e4a651327..31178c13193 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -3988,7 +3988,6 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info,
   obj_attribute *in_attr;
   obj_attribute *out_attr;
   bool result = true;
-  bool priv_attrs_merged = false;
   const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
   unsigned int i;
 
@@ -4017,6 +4016,13 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info,
 	{
 	  switch (i)
 	    {
+	    /* The privileged spec tags are deprecated, drop them.  */
+	    case Tag_RISCV_priv_spec:
+	    case Tag_RISCV_priv_spec_minor:
+	    case Tag_RISCV_priv_spec_revision:
+	      out_attr[i].i = 0;
+	      break;
+
 	    case Tag_RISCV_unaligned_access:
 	      if (out_attr[i].i <= 1)
 		break;
@@ -4073,59 +4079,10 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info,
 	  }
 	break;
 
+      /* The privileged spec tags are deprecated, ignore them.  */
       case Tag_RISCV_priv_spec:
       case Tag_RISCV_priv_spec_minor:
       case Tag_RISCV_priv_spec_revision:
-	/* If we have handled the privileged elf attributes, then skip it.  */
-	if (!priv_attrs_merged)
-	  {
-	    unsigned int Tag_a = Tag_RISCV_priv_spec;
-	    unsigned int Tag_b = Tag_RISCV_priv_spec_minor;
-	    unsigned int Tag_c = Tag_RISCV_priv_spec_revision;
-	    enum riscv_spec_class in_priv_spec = PRIV_SPEC_CLASS_NONE;
-	    enum riscv_spec_class out_priv_spec = PRIV_SPEC_CLASS_NONE;
-
-	    /* Get the privileged spec class from elf attributes.  */
-	    riscv_get_priv_spec_class_from_numbers (in_attr[Tag_a].i,
-						    in_attr[Tag_b].i,
-						    in_attr[Tag_c].i,
-						    &in_priv_spec);
-	    riscv_get_priv_spec_class_from_numbers (out_attr[Tag_a].i,
-						    out_attr[Tag_b].i,
-						    out_attr[Tag_c].i,
-						    &out_priv_spec);
-
-	    /* Allow to link the object without the privileged specs.  */
-	    if (out_priv_spec == PRIV_SPEC_CLASS_NONE)
-	      {
-		out_attr[Tag_a].i = in_attr[Tag_a].i;
-		out_attr[Tag_b].i = in_attr[Tag_b].i;
-		out_attr[Tag_c].i = in_attr[Tag_c].i;
-	      }
-	    else if (in_priv_spec != PRIV_SPEC_CLASS_NONE
-		     && in_priv_spec != out_priv_spec)
-	      {
-		/* The abandoned privileged spec v1.9.1 can not be linked with
-		   others since the conflicts.  Keep the check since compatible
-		   issue.  */
-		if (in_priv_spec == PRIV_SPEC_CLASS_1P9P1
-		    || out_priv_spec == PRIV_SPEC_CLASS_1P9P1)
-		  {
-		    _bfd_error_handler
-		      (_("warning: privileged spec version 1.9.1 can not be "
-			 "linked with other spec versions"));
-		  }
-
-		/* Update the output privileged spec to the newest one.  */
-		if (in_priv_spec > out_priv_spec)
-		  {
-		    out_attr[Tag_a].i = in_attr[Tag_a].i;
-		    out_attr[Tag_b].i = in_attr[Tag_b].i;
-		    out_attr[Tag_c].i = in_attr[Tag_c].i;
-		  }
-	      }
-	    priv_attrs_merged = true;
-	  }
 	break;
 
       case Tag_RISCV_unaligned_access:
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index e63bc75e8b2..6796d667881 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -220,7 +220,7 @@ struct riscv_set_options
   int rvc; /* Generate RVC code.  */
   int relax; /* Emit relocs the linker is allowed to relax.  */
   int exact; /* Emit instructions without compression or relaxation.  */
-  int arch_attr; /* Emit architecture and privileged elf attributes.  */
+  int arch_attr; /* Emit architecture elf attribute.  */
   int csr_check; /* Enable the CSR checking.  */
 };
 
@@ -437,9 +437,6 @@ const char FLT_CHARS[] = "rRsSfFdDxXpPhHbB";
 /* Indicate ELF attributes are explicitly set.  */
 static bool explicit_attr = false;
 
-/* Indicate CSR or priv instructions are explicitly used.  */
-static bool explicit_priv_attr = false;
-
 static char *expr_parse_end;
 
 /* Macros for encoding relaxation state for RVC branches and far jumps.  */
@@ -2870,28 +2867,6 @@ riscv_csr_read_only_check (insn_t insn)
   return true;
 }
 
-/* Return true if it is a privileged instruction.  Otherwise, return false.
-
-   uret is actually a N-ext instruction.  So it is better to regard it as
-   an user instruction rather than the priv instruction.
-
-   hret is used to return from traps in H-mode.  H-mode is removed since
-   the v1.10 priv spec, but probably be added in the new hypervisor spec.
-   Therefore, hret should be controlled by the hypervisor spec rather than
-   priv spec in the future.
-
-   dret is defined in the debug spec, so it should be checked in the future,
-   too.  */
-
-static bool
-riscv_is_priv_insn (insn_t insn)
-{
-  return (((insn ^ MATCH_SRET) & MASK_SRET) == 0
-	  || ((insn ^ MATCH_MRET) & MASK_MRET) == 0
-	  || ((insn ^ MATCH_SFENCE_VMA) & MASK_SFENCE_VMA) == 0
-	  || ((insn ^ MATCH_WFI) & MASK_WFI) == 0);
-}
-
 static symbolS *deferred_sym_rootP;
 static symbolS *deferred_sym_lastP;
 /* Since symbols can't easily be freed, try to recycle ones which weren't
@@ -3008,9 +2983,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
 		      && !riscv_opts.rvc)
 		    break;
 
-		  if (riscv_is_priv_insn (ip->insn_opcode))
-		    explicit_priv_attr = true;
-
 		  /* Check if we write a read-only CSR by the CSR
 		     instruction.  */
 		  if (insn_with_csr
@@ -3570,7 +3542,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
 
 	    case 'E': /* Control register.  */
 	      insn_with_csr = true;
-	      explicit_priv_attr = true;
 	      if (reg_lookup (&asarg, RCLASS_CSR, &regno))
 		INSERT_OPERAND (CSR, *ip, regno);
 	      else
@@ -5895,58 +5866,17 @@ s_riscv_insn (int x ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
-/* Update architecture and privileged elf attributes.  If we don't set
-   them, then try to output the default ones.  */
+/* Update architecture elf attribute.  If we don't set it, then try to
+   output the default one.  */
 
 static void
 riscv_write_out_attrs (void)
 {
-  const char *priv_str, *p;
-  /* versions[0]: major version.
-     versions[1]: minor version.
-     versions[2]: revision version.  */
-  unsigned versions[3] = {0}, number = 0;
-  unsigned int i;
-
   /* Re-write architecture elf attribute.  */
   if (!bfd_elf_add_proc_attr_string (stdoutput, Tag_RISCV_arch, file_arch_str))
     as_fatal (_("error adding attribute: %s"),
 	      bfd_errmsg (bfd_get_error ()));
   free ((void *) file_arch_str);
-
-  /* Don't generate privileged elf attributes when no CSR and privileged
-     instructions are used.  */
-  if (!explicit_priv_attr)
-    return;
-
-  RISCV_GET_PRIV_SPEC_NAME (priv_str, default_priv_spec);
-  p = priv_str;
-  for (i = 0; *p; ++p)
-    {
-      if (*p == '.' && i < 3)
-       {
-         versions[i++] = number;
-         number = 0;
-       }
-      else if (ISDIGIT (*p))
-       number = (number * 10) + (*p - '0');
-      else
-       {
-         as_bad (_("internal: bad RISC-V privileged spec (%s)"), priv_str);
-         return;
-       }
-    }
-  versions[i] = number;
-
-  /* Re-write privileged elf attributes.  */
-  if (!bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec,
-				  versions[0])
-      || !bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_minor,
-				     versions[1])
-      || !bfd_elf_add_proc_attr_int (stdoutput, Tag_RISCV_priv_spec_revision,
-				     versions[2]))
-    as_fatal (_("error adding attribute: %s"),
-	      bfd_errmsg (bfd_get_error ()));
 }
 
 /* Add the default contents for the .riscv.attributes section.  */
diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
index f9273dd7306..9a7a35e2dd0 100644
--- a/gas/doc/c-riscv.texi
+++ b/gas/doc/c-riscv.texi
@@ -84,9 +84,8 @@ Don't do linker relaxations.
 Generate the default contents for the riscv elf attribute section if the
 .attribute directives are not set.  This section is used to record the
 information that a linker or runtime loader needs to check compatibility.
-This information includes ISA string, stack alignment requirement, unaligned
-memory accesses, and the major, minor and revision version of privileged
-specification.
+This information includes ISA string, stack alignment requirement and
+unaligned memory accesses.
 
 @cindex @samp{-mno-arch-attr} option, RISC-V
 @item -mno-arch-attr
@@ -765,10 +764,8 @@ memory accesses, and 1 for files that do allow unaligned memory accesses.
 @item Tag_RISCV_priv_spec_minor (10)
 @item Tag_RISCV_priv_spec_revision (12)
 Tag_RISCV_priv_spec contains the major/minor/revision version information of
-the privileged specification.  The assembler ignores these tags when set by
-@code{.attribute}, and only emits version 1.13 when CSR or privileged
-instructions are used.  The linker keeps the newest version when object
-files of different privileged specification versions are merged.
+the privileged specification.  These tags are deprecated by the RISC-V psABI.
+The assembler never emits them, and the linker ignores them.
 
 @end table
 
diff --git a/gas/testsuite/gas/riscv/attribute-11.d b/gas/testsuite/gas/riscv/attribute-11.d
index 4bd66f0bb29..05bb7775a6a 100644
--- a/gas/testsuite/gas/riscv/attribute-11.d
+++ b/gas/testsuite/gas/riscv/attribute-11.d
@@ -4,5 +4,3 @@
 Attribute Section: riscv
 File Attributes
   Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: [0-9_\"].*
-#...
diff --git a/gas/testsuite/gas/riscv/attribute-11.s b/gas/testsuite/gas/riscv/attribute-11.s
index ef4e7ff68bd..df4a6ef8133 100644
--- a/gas/testsuite/gas/riscv/attribute-11.s
+++ b/gas/testsuite/gas/riscv/attribute-11.s
@@ -1,4 +1,3 @@
-	# The csr is explicit used, so we need to generate the priv spec
-	# attributes even if the attributes are not set.
+	# The priv spec attributes are not generated even if the csr is used.
 	.option arch, +zicsr
 	csrr a0, 0x0
diff --git a/gas/testsuite/gas/riscv/attribute-12.d b/gas/testsuite/gas/riscv/attribute-12.d
index 5fb625181b6..96d072a892a 100644
--- a/gas/testsuite/gas/riscv/attribute-12.d
+++ b/gas/testsuite/gas/riscv/attribute-12.d
@@ -5,5 +5,3 @@
 Attribute Section: riscv
 File Attributes
   Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 13
diff --git a/gas/testsuite/gas/riscv/attribute-14.s b/gas/testsuite/gas/riscv/attribute-14.s
deleted file mode 100644
index dcca2d8671d..00000000000
--- a/gas/testsuite/gas/riscv/attribute-14.s
+++ /dev/null
@@ -1,14 +0,0 @@
-	# The priv instruction is explicit used, so we need to generate
-	# the priv spec attributes even if the attributes are not set.
-.ifdef priv_insn_a
-	mret
-.endif
-.ifdef priv_insn_b
-	sret
-.endif
-.ifdef priv_insn_c
-	wfi
-.endif
-.ifdef priv_insn_d
-	sfence.vma
-.endif
diff --git a/gas/testsuite/gas/riscv/attribute-14a.d b/gas/testsuite/gas/riscv/attribute-14a.d
deleted file mode 100644
index 7b66f0faa93..00000000000
--- a/gas/testsuite/gas/riscv/attribute-14a.d
+++ /dev/null
@@ -1,8 +0,0 @@
-#as: -march-attr --defsym priv_insn_a=1
-#readelf: -A
-#source: attribute-14.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: [0-9_\"].*
-#...
diff --git a/gas/testsuite/gas/riscv/attribute-14b.d b/gas/testsuite/gas/riscv/attribute-14b.d
deleted file mode 100644
index e044f4ff80d..00000000000
--- a/gas/testsuite/gas/riscv/attribute-14b.d
+++ /dev/null
@@ -1,8 +0,0 @@
-#as: -march-attr --defsym priv_insn_b=1
-#readelf: -A
-#source: attribute-14.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: [0-9_\"].*
-#...
diff --git a/gas/testsuite/gas/riscv/attribute-14c.d b/gas/testsuite/gas/riscv/attribute-14c.d
deleted file mode 100644
index 6311a9d7e51..00000000000
--- a/gas/testsuite/gas/riscv/attribute-14c.d
+++ /dev/null
@@ -1,8 +0,0 @@
-#as: -march-attr --defsym priv_insn_c=1
-#readelf: -A
-#source: attribute-14.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: [0-9_\"].*
-#...
diff --git a/gas/testsuite/gas/riscv/attribute-14d.d b/gas/testsuite/gas/riscv/attribute-14d.d
deleted file mode 100644
index f0f2d63b087..00000000000
--- a/gas/testsuite/gas/riscv/attribute-14d.d
+++ /dev/null
@@ -1,8 +0,0 @@
-#as: -march-attr --defsym priv_insn_d=1
-#readelf: -A
-#source: attribute-14.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: [0-9_\"].*
-#...
diff --git a/gas/testsuite/gas/riscv/attribute-15.d b/gas/testsuite/gas/riscv/attribute-15.d
deleted file mode 100644
index 3000a349d30..00000000000
--- a/gas/testsuite/gas/riscv/attribute-15.d
+++ /dev/null
@@ -1,8 +0,0 @@
-#as: -march-attr
-#readelf: -A
-#source: attribute-11.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 13
diff --git a/gas/testsuite/gas/riscv/attribute-16.d b/gas/testsuite/gas/riscv/attribute-16.d
deleted file mode 100644
index fbfe8f95ce7..00000000000
--- a/gas/testsuite/gas/riscv/attribute-16.d
+++ /dev/null
@@ -1,6 +0,0 @@
-#as: -march-attr
-#readelf: -A
-#source: empty.s
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
diff --git a/gas/testsuite/gas/riscv/attribute-priv-ignored.d b/gas/testsuite/gas/riscv/attribute-priv-ignored.d
index 45cac6008b9..a1def10cd37 100644
--- a/gas/testsuite/gas/riscv/attribute-priv-ignored.d
+++ b/gas/testsuite/gas/riscv/attribute-priv-ignored.d
@@ -5,5 +5,3 @@
 Attribute Section: riscv
 File Attributes
   Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 13
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d
index 3806cdd422e..91aae9e6de9 100644
--- a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d
+++ b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d
@@ -1,10 +1,5 @@
 #source: attr-merge-priv-spec-a.s
-#source: attr-merge-priv-spec-b.s
+#source: attr-merge-priv-spec-c.s
 #as: -mno-arch-attr
 #ld: -r
 #readelf: -A
-
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 10
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d
deleted file mode 100644
index c91f98c4806..00000000000
--- a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d
+++ /dev/null
@@ -1,10 +0,0 @@
-#source: attr-merge-priv-spec-a.s
-#source: attr-merge-priv-spec-d.s
-#as: -mno-arch-attr
-#ld: -r
-#readelf: -A
-
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 10
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d
deleted file mode 100644
index 1bf1ed2acee..00000000000
--- a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d
+++ /dev/null
@@ -1,10 +0,0 @@
-#source: attr-merge-priv-spec-d.s
-#source: attr-merge-priv-spec-a.s
-#as: -mno-arch-attr
-#ld: -r
-#readelf: -A
-
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 10
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s
deleted file mode 100644
index b358fcc20e7..00000000000
--- a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s
+++ /dev/null
@@ -1,12 +0,0 @@
-# The assembler ignores the privileged elf attributes, so write them by hand.
-	.section .riscv.attributes, "", %0x70000003
-	.byte	0x41
-.Lvendor:
-	.4byte	.Lend - .Lvendor
-	.asciz	"riscv"
-.Lfile:
-	.byte	1
-	.4byte	.Lend - .Lfile
-	# Tag_RISCV_priv_spec, Tag_RISCV_priv_spec_minor.
-	.byte	8, 1, 10, 10
-.Lend:
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s
deleted file mode 100644
index 37fddd0d2d9..00000000000
--- a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s
+++ /dev/null
@@ -1 +0,0 @@
-# Empty priv attributes setting.
diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index 83705f71d90..ad12f8d63b1 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -202,8 +202,6 @@ if [istarget "riscv*-*-*"] {
     run_dump_test "attr-merge-strict-align-05"
     run_dump_test "attr-merge-stack-align"
     run_dump_test "attr-merge-priv-spec-01"
-    run_dump_test "attr-merge-priv-spec-02"
-    run_dump_test "attr-merge-priv-spec-03"
     run_dump_test "attr-merge-user-ext-01"
     run_dump_test "attr-merge-stack-align-failed"
     run_dump_test "attr-phdr"


More information about the Binutils-cvs mailing list