public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nelson Chu <nelson.chu@sifive.com>
To: binutils@sourceware.org, jim.wilson.gcc@gmail.com,
	kito.cheng@sifive.com, palmer@dabbelt.com, jrtc27@jrtc27.com
Subject: [committed] RISC-V: Clarify the behavior of .option arch directive.
Date: Wed,  8 Dec 2021 23:58:29 -0800	[thread overview]
Message-ID: <1639036709-6852-1-git-send-email-nelson.chu@sifive.com> (raw)

* To be consistent with -march option, removed the "=" operator when
user want to reset the whole architecture string.  So the formats are,

.option arch, +<extension><version>, ...
.option arch, -<extension>
.option arch, <ISA string>

* Don't allow to add or remove the base extensions in the .option arch
directive.  Instead, users should reset the whole architecture string
while they want to change the base extension.

* The operator "+" won't update the version of extension, if the
extension is already in the subset list.

bfd/
	* elfxx-riscv.c (riscv_add_subset): Don't update the version
	if the extension is already in the subset list.
	(riscv_update_subset): To be consistent with -march option,
	removed the "=" operator when user want to reset the whole
	architecture string.  Besides, Don't allow to add or remove
	the base extensions in the .option arch directive.
gas/
	* testsuite/gas/riscv/option-arch-01.s: Updated since we cannot
	add or remove the base extensions in the .option arch directive.
	* testsuite/gas/riscv/option-arch-02.s: Likewise.
	* testsuite/gas/riscv/option-arch-fail.l: Likewise.
	* testsuite/gas/riscv/option-arch-fail.s: Likewise.
	* testsuite/gas/riscv/option-arch-01a.d: Set -misa-spec=2.2.
	* testsuite/gas/riscv/option-arch-01b.d: Likewise.
	* testsuite/gas/riscv/option-arch-02.d: Updated since the .option
	arch, + won't change the version of extension, if the extension is
	already in the subset list.
	* testsuite/gas/riscv/option-arch-03.s: Removed the "=" operator
	when resetting the whole architecture string.
---
 bfd/elfxx-riscv.c                          | 39 ++++++++++++------------------
 gas/testsuite/gas/riscv/option-arch-01.s   |  2 +-
 gas/testsuite/gas/riscv/option-arch-01a.d  |  2 +-
 gas/testsuite/gas/riscv/option-arch-01b.d  |  2 +-
 gas/testsuite/gas/riscv/option-arch-02.d   |  4 +--
 gas/testsuite/gas/riscv/option-arch-02.s   |  2 +-
 gas/testsuite/gas/riscv/option-arch-03.s   |  2 +-
 gas/testsuite/gas/riscv/option-arch-fail.l |  6 +++--
 gas/testsuite/gas/riscv/option-arch-fail.s |  2 ++
 9 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 3bd41ff..8c44c4a 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -1468,15 +1468,7 @@ riscv_add_subset (riscv_subset_list_t *subset_list,
   riscv_subset_t *current, *new;
 
   if (riscv_lookup_subset (subset_list, subset, &current))
-    {
-      if (major != RISCV_UNKNOWN_VERSION
-	  && minor != RISCV_UNKNOWN_VERSION)
-	{
-	  current->major_version = major;
-	  current->minor_version = minor;
-	}
-      return;
-    }
+    return;
 
   new = xmalloc (sizeof *new);
   new->name = xstrdup (subset);
@@ -2217,18 +2209,15 @@ riscv_update_subset (riscv_parse_subset_t *rps,
       int minor_version = RISCV_UNKNOWN_VERSION;
 
       bool removed = false;
-      switch (*p++)
+      switch (*p)
 	{
 	case '+': removed = false; break;
 	case '-': removed = true; break;
-	case '=':
+	default:
 	  riscv_release_subset_list (rps->subset_list);
 	  return riscv_parse_subset (rps, p);
-	default:
-	  rps->error_handler
-	    (_("extensions must begin with +/-/= in .option arch `%s'"), str);
-	  return false;
 	}
+      ++p;
 
       char *subset = xstrdup (p);
       char *q = subset;
@@ -2293,17 +2282,19 @@ riscv_update_subset (riscv_parse_subset_t *rps,
 	  return false;
 	}
 
-      if (removed)
+      if (strcmp (subset, "i") == 0
+	  || strcmp (subset, "e") == 0
+	  || strcmp (subset, "g") == 0)
 	{
-	  if (strcmp (subset, "i") == 0)
-	    {
-	      rps->error_handler
-		(_("cannot remove extension `i' in .option arch `%s'"), str);
-	      free (subset);
-	      return false;
-	    }
-	  riscv_remove_subset (rps->subset_list, subset);
+	  rps->error_handler
+	    (_("cannot + or - base extension `%s' in .option "
+	       "arch `%s'"), subset, str);
+	  free (subset);
+	  return false;
 	}
+
+      if (removed)
+	riscv_remove_subset (rps->subset_list, subset);
       else
 	riscv_parse_add_subset (rps, subset, major_version, minor_version, true);
       p += end_of_version - subset;
diff --git a/gas/testsuite/gas/riscv/option-arch-01.s b/gas/testsuite/gas/riscv/option-arch-01.s
index 201f9b3..50285fc 100644
--- a/gas/testsuite/gas/riscv/option-arch-01.s
+++ b/gas/testsuite/gas/riscv/option-arch-01.s
@@ -5,6 +5,6 @@ add	a0, a0, a1
 add	a0, a0, a1
 frcsr	a0	# Should add mapping symbol with ISA here, and then dump it to frcsr.
 .option push
-.option arch, +i3p0, +m3p0, +d3p0
+.option arch, +m3p0, +d3p0
 .option pop
 .option pop
diff --git a/gas/testsuite/gas/riscv/option-arch-01a.d b/gas/testsuite/gas/riscv/option-arch-01a.d
index 59bc1d2..aed4ca8 100644
--- a/gas/testsuite/gas/riscv/option-arch-01a.d
+++ b/gas/testsuite/gas/riscv/option-arch-01a.d
@@ -1,4 +1,4 @@
-#as:
+#as: -misa-spec=2.2
 #source: option-arch-01.s
 #objdump: -d
 
diff --git a/gas/testsuite/gas/riscv/option-arch-01b.d b/gas/testsuite/gas/riscv/option-arch-01b.d
index 9a6c2c5..8f4284d 100644
--- a/gas/testsuite/gas/riscv/option-arch-01b.d
+++ b/gas/testsuite/gas/riscv/option-arch-01b.d
@@ -1,4 +1,4 @@
-#as:
+#as: -misa-spec=2.2
 #readelf: -A
 #source: option-arch-01.s
 
diff --git a/gas/testsuite/gas/riscv/option-arch-02.d b/gas/testsuite/gas/riscv/option-arch-02.d
index 0fe89ec..9ca013e 100644
--- a/gas/testsuite/gas/riscv/option-arch-02.d
+++ b/gas/testsuite/gas/riscv/option-arch-02.d
@@ -1,8 +1,8 @@
-#as:
+#as: -misa-spec=2.2
 #readelf: -A
 #source: option-arch-02.s
 
 Attribute Section: riscv
 File Attributes
-  Tag_RISCV_arch: "rv64i3p0_m3p0_f2p0_d3p0_c2p0_xvendor32x3p0"
+  Tag_RISCV_arch: "rv64i2p0_m3p0_f2p0_d3p0_c2p0_xvendor32x3p0"
 #...
diff --git a/gas/testsuite/gas/riscv/option-arch-02.s b/gas/testsuite/gas/riscv/option-arch-02.s
index f4ceee84..e0f5de3 100644
--- a/gas/testsuite/gas/riscv/option-arch-02.s
+++ b/gas/testsuite/gas/riscv/option-arch-02.s
@@ -5,4 +5,4 @@ add	a0, a0, a1
 add	a0, a0, a1
 frcsr	a0
 .option pop
-.option arch, +i3p0, +m3p0, +d3p0, +xvendor32x3p0
+.option arch, +m3p0, +d3p0, +xvendor32x3p0
diff --git a/gas/testsuite/gas/riscv/option-arch-03.s b/gas/testsuite/gas/riscv/option-arch-03.s
index 7183140..d982a0b 100644
--- a/gas/testsuite/gas/riscv/option-arch-03.s
+++ b/gas/testsuite/gas/riscv/option-arch-03.s
@@ -1,3 +1,3 @@
 .attribute arch, "rv64ic"
 .option arch, +d2p0, -c
-.option arch, =rv32ic
+.option arch, rv32ic
diff --git a/gas/testsuite/gas/riscv/option-arch-fail.l b/gas/testsuite/gas/riscv/option-arch-fail.l
index 3e0599e..b9979a4 100644
--- a/gas/testsuite/gas/riscv/option-arch-fail.l
+++ b/gas/testsuite/gas/riscv/option-arch-fail.l
@@ -1,6 +1,8 @@
 .*Assembler messages:
-.*Error: extensions must begin with \+/\-/\= in .option arch `m2p0'
-.*Error: cannot remove extension `i' in .option arch `\-i'
+.*Error: m2p0: ISA string must begin with rv32 or rv64
+.*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: 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 `\+'
diff --git a/gas/testsuite/gas/riscv/option-arch-fail.s b/gas/testsuite/gas/riscv/option-arch-fail.s
index a0b1bde..101587a 100644
--- a/gas/testsuite/gas/riscv/option-arch-fail.s
+++ b/gas/testsuite/gas/riscv/option-arch-fail.s
@@ -2,6 +2,8 @@
 .option push
 .option arch, m2p0
 .option arch, -i
+.option arch, +e
+.option arch, -g
 .option arch, +zsubset2p0
 .option arch, +f2p0_d2p0
 .option arch, +
-- 
2.7.4


                 reply	other threads:[~2021-12-09  7:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1639036709-6852-1-git-send-email-nelson.chu@sifive.com \
    --to=nelson.chu@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=jim.wilson.gcc@gmail.com \
    --cc=jrtc27@jrtc27.com \
    --cc=kito.cheng@sifive.com \
    --cc=palmer@dabbelt.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).