[Integration,1/6] RISC-V/extended: Add extended extension hooks when parsing architecture string.

Message ID 1617097017-16776-2-git-send-email-nelson.chu@sifive.com
State New
Headers show
Series
  • RISC-V: The prototype of the integration and working branches for binutils.
Related show

Commit Message

Nelson Chu March 30, 2021, 9:36 a.m.
All known non-standard extensions will be defined in riscv_vendor_ext_strtab
of bfd/elfxx-riscv-vendor.c.  Report warning messages when the non-standard
extensions are unrecognized.  But as before, they won’t break assemble and
link time, we still need to encode them into the output architecture string.

bfd/
    * elfnn-riscv.c (riscv_merge_arch_attr_info): Set warning_handler when
    parsing architecture string.  Linker use _bfd_error_handler to report
    warnings.
    * elfxx-riscv.c (riscv_parse_add_subset): Message updated.
    (riscv_parse_prefixed_ext): Report warnings when the non-standard
    extensions are unrecognized.  Others as usual.
    (riscv_std_draft_ext_strtab): New array of string for draft extensions.
    (riscv_vendor_ext_strtab): New array of string for supported vendor
    extensions.
    (riscv_ext_x_valid_p): Check if the x vendor extensions are supported
    according to the riscv_vendor_ext_strtab.
    (riscv_ext_z_valid_p): Check if the z draft extensions are supported
    according to the riscv_std_draft_ext_strtab.
    * elfxx-riscv.h (riscv_parse_subset_t): Added warning_handler.
gas/
    * config/tc-riscv.c (riscv_set_arch): Set as_warn to warning_handler.
    * testsuite/gas/riscv/attribute-02.d: Updated.
    * testsuite/gas/riscv/attribute-02.l: Likewise.
    * testsuite/gas/riscv/attribute-03.d: Likewise.
    * testsuite/gas/riscv/attribute-03.l: Likewise.
    * testsuite/gas/riscv/march-fail-isa-spec.l: Likewise.
    * testsuite/gas/riscv/march-fail-order-x.l: Likewise.
    * testsuite/gas/riscv/march-fail-porder.l: Likewise.
    * testsuite/gas/riscv/march-ok-nse-with-version.d: Likewise.
    * testsuite/gas/riscv/march-ok-nse-with-version.l: Likewise.
    * testsuite/gas/riscv/march-ok-two-nse.d: Likewise.
    * testsuite/gas/riscv/march-ok-two-nse.l: Likewise.
ld/
    * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
    * testsuite/ld-riscv-elf/attr-merge-arch-03.l: Likewise.
---
 bfd/elfnn-riscv.c                                  |  2 +
 bfd/elfxx-riscv.c                                  | 48 ++++++++++++++++------
 bfd/elfxx-riscv.h                                  |  2 +
 gas/config/tc-riscv.c                              |  1 +
 gas/testsuite/gas/riscv/attribute-02.d             |  4 +-
 gas/testsuite/gas/riscv/attribute-02.l             |  2 +
 gas/testsuite/gas/riscv/attribute-03.d             |  4 +-
 gas/testsuite/gas/riscv/attribute-03.l             |  3 ++
 gas/testsuite/gas/riscv/march-fail-isa-spec.l      |  6 ++-
 gas/testsuite/gas/riscv/march-fail-order-x.l       |  2 +
 gas/testsuite/gas/riscv/march-fail-porder.l        |  1 +
 .../gas/riscv/march-ok-nse-with-version.d          |  3 +-
 .../gas/riscv/march-ok-nse-with-version.l          |  2 +
 gas/testsuite/gas/riscv/march-ok-two-nse.d         |  3 +-
 gas/testsuite/gas/riscv/march-ok-two-nse.l         |  3 ++
 ld/testsuite/ld-riscv-elf/attr-merge-arch-03.d     |  1 +
 ld/testsuite/ld-riscv-elf/attr-merge-arch-03.l     |  3 ++
 17 files changed, 72 insertions(+), 18 deletions(-)
 create mode 100644 gas/testsuite/gas/riscv/attribute-02.l
 create mode 100644 gas/testsuite/gas/riscv/attribute-03.l
 create mode 100644 gas/testsuite/gas/riscv/march-ok-nse-with-version.l
 create mode 100644 gas/testsuite/gas/riscv/march-ok-two-nse.l
 create mode 100644 ld/testsuite/ld-riscv-elf/attr-merge-arch-03.l

-- 
2.7.4

Comments

Jim Wilson March 30, 2021, 10:46 p.m. | #1
On Tue, Mar 30, 2021 at 2:37 AM Nelson Chu <nelson.chu@sifive.com> wrote:

> All known non-standard extensions will be defined in

> riscv_vendor_ext_strtab

> of bfd/elfxx-riscv-vendor.c.  Report warning messages when the non-standard

>


You don't have a elfxx-riscv-vendor.c file anymore, so this comment is a
little out of date, but this doesn't really matter.

Jim

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 391846a..a42cd18 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3538,11 +3538,13 @@  riscv_merge_arch_attr_info (bfd *ibfd, char *in_arch, char *out_arch)
      the rpe_in.get_default_version and rpe_out.get_default_version to NULL.  */
   rpe_in.subset_list = &in_subsets;
   rpe_in.error_handler = _bfd_error_handler;
+  rpe_in.warning_handler = _bfd_error_handler;
   rpe_in.xlen = &xlen_in;
   rpe_in.get_default_version = NULL;
 
   rpe_out.subset_list = &out_subsets;
   rpe_out.error_handler = _bfd_error_handler;
+  rpe_out.warning_handler = _bfd_error_handler;
   rpe_out.xlen = &xlen_out;
   rpe_out.get_default_version = NULL;
 
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 966e142..1ce85e0 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -1200,7 +1200,7 @@  riscv_parse_add_subset (riscv_parse_subset_t *rps,
 
       if (subset[0] == 'x')
 	rps->error_handler
-	  (_("x ISA extension `%s' must be set with the versions"),
+	  (_("unknown x ISA extension `%s' must be set with the versions"),
 	   subset);
       else
 	rps->error_handler
@@ -1541,11 +1541,20 @@  riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
       /* Check that the extension name is well-formed.  */
       if (!config->ext_valid_p (subset))
 	{
-	  rps->error_handler
-	    (_("-march=%s: unknown %s ISA extension `%s'"),
-	     march, config->prefix, subset);
-	  free (subset);
-	  return NULL;
+	  /* Single x is invalid.  */
+	  if (config->class == RV_ISA_CLASS_X
+	      && strcmp (subset, "x") != 0)
+	    rps->warning_handler
+		(_("-march=%s: unknown x ISA extension `%s'"),
+		 march, subset);
+	  else
+	    {
+	      rps->error_handler
+		(_("-march=%s: unknown %s ISA extension `%s'"),
+		 march, config->prefix, subset);
+	      free (subset);
+	      return NULL;
+	    }
 	}
 
       /* Check that the extension isn't duplicate.  */
@@ -1611,6 +1620,16 @@  static const char * const riscv_std_h_ext_strtab[] =
   NULL
 };
 
+static const char * const riscv_std_draft_ext_strtab[] =
+{
+  NULL
+};
+
+static const char ** const riscv_vendor_ext_strtab[] =
+{
+  NULL
+};
+
 /* For the extension `ext`, search through the list of known extensions
    `known_exts` for a match, and return TRUE if found.  */
 
@@ -1627,16 +1646,20 @@  riscv_multi_letter_ext_valid_p (const char *ext,
   return FALSE;
 }
 
-/* Predicator function for x-prefixed extensions.
-   Anything goes, except the literal 'x'.  */
+/* Predicator function for x-prefixed vendor extensions.
+   Anything goes, but report warning when the vendor extensions
+   are unknown.  */
 
 static bfd_boolean
 riscv_ext_x_valid_p (const char *arg)
 {
-  if (!strcasecmp (arg, "x"))
-    return FALSE;
+  unsigned int i;
 
-  return TRUE;
+  for (i = 0; riscv_vendor_ext_strtab[i] != NULL; i++)
+    if (riscv_multi_letter_ext_valid_p (arg, riscv_vendor_ext_strtab[i]))
+      return TRUE;
+
+  return FALSE;
 }
 
 /* Predicator functions for z-prefixed extensions.
@@ -1645,7 +1668,8 @@  riscv_ext_x_valid_p (const char *arg)
 static bfd_boolean
 riscv_ext_z_valid_p (const char *arg)
 {
-  return riscv_multi_letter_ext_valid_p (arg, riscv_std_z_ext_strtab);
+  return (riscv_multi_letter_ext_valid_p (arg, riscv_std_z_ext_strtab)
+	  || riscv_multi_letter_ext_valid_p (arg, riscv_std_draft_ext_strtab));
 }
 
 /* Predicator function for 's' prefixed extensions.
diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
index a676d5c..a26869d 100644
--- a/bfd/elfxx-riscv.h
+++ b/bfd/elfxx-riscv.h
@@ -68,6 +68,8 @@  typedef struct
   riscv_subset_list_t *subset_list;
   void (*error_handler) (const char *,
 			 ...) ATTRIBUTE_PRINTF_1;
+  void (*warning_handler) (const char *,
+			   ...) ATTRIBUTE_PRINTF_1;
   unsigned *xlen;
   void (*get_default_version) (const char *,
 			       int *,
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 429732f..83cf157 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -408,6 +408,7 @@  riscv_set_arch (const char *s)
   riscv_parse_subset_t rps;
   rps.subset_list = &riscv_subsets;
   rps.error_handler = as_bad;
+  rps.warning_handler = as_warn;
   rps.xlen = &xlen;
   rps.get_default_version = riscv_get_default_ext_version;
 
diff --git a/gas/testsuite/gas/riscv/attribute-02.d b/gas/testsuite/gas/riscv/attribute-02.d
index 45b89f2..17c4ba5 100644
--- a/gas/testsuite/gas/riscv/attribute-02.d
+++ b/gas/testsuite/gas/riscv/attribute-02.d
@@ -1,6 +1,8 @@ 
 #as: -march=rv32gxargle2p0 -march-attr -misa-spec=2.2
-#readelf: -A
 #source: empty.s
+#warning_output: attribute-02.l
+#readelf: -A
+
 Attribute Section: riscv
 File Attributes
   Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle2p0"
diff --git a/gas/testsuite/gas/riscv/attribute-02.l b/gas/testsuite/gas/riscv/attribute-02.l
new file mode 100644
index 0000000..cf22fd0
--- /dev/null
+++ b/gas/testsuite/gas/riscv/attribute-02.l
@@ -0,0 +1,2 @@ 
+.*Assembler messages:
+.*Warning: -march=rv32gxargle2p0: unknown x ISA extension `xargle'
diff --git a/gas/testsuite/gas/riscv/attribute-03.d b/gas/testsuite/gas/riscv/attribute-03.d
index 11416d6..2eaeb0c 100644
--- a/gas/testsuite/gas/riscv/attribute-03.d
+++ b/gas/testsuite/gas/riscv/attribute-03.d
@@ -1,6 +1,8 @@ 
 #as: -march=rv32gxargle2p0_xfoo3p0 -march-attr -misa-spec=2.2
-#readelf: -A
 #source: empty.s
+#warning_output: attribute-03.l
+#readelf: -A
+
 Attribute Section: riscv
 File Attributes
   Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0_xargle2p0_xfoo3p0"
diff --git a/gas/testsuite/gas/riscv/attribute-03.l b/gas/testsuite/gas/riscv/attribute-03.l
new file mode 100644
index 0000000..8bb9bbf
--- /dev/null
+++ b/gas/testsuite/gas/riscv/attribute-03.l
@@ -0,0 +1,3 @@ 
+.*Assembler messages:
+.*Warning: -march=rv32gxargle2p0_xfoo3p0: unknown x ISA extension `xargle'
+.*Warning: -march=rv32gxargle2p0_xfoo3p0: unknown x ISA extension `xfoo'
diff --git a/gas/testsuite/gas/riscv/march-fail-isa-spec.l b/gas/testsuite/gas/riscv/march-fail-isa-spec.l
index e714ddf..ddc91ff 100644
--- a/gas/testsuite/gas/riscv/march-fail-isa-spec.l
+++ b/gas/testsuite/gas/riscv/march-fail-isa-spec.l
@@ -1,5 +1,7 @@ 
 .*Assembler messages:
 .*Error: cannot find default versions of the ISA extension `l'
 .*Error: cannot find default versions of the ISA extension `n'
-.*Error: x ISA extension `xargle' must be set with the versions
-.*Error: x ISA extension `xbargle' must be set with the versions
+.*Warning: -march=rv32iln_zicsr_xargle_xbargle: unknown x ISA extension `xargle'
+.*Error: unknown x ISA extension `xargle' must be set with the versions
+.*Warning: -march=rv32iln_zicsr_xargle_xbargle: unknown x ISA extension `xbargle'
+.*Error: unknown x ISA extension `xbargle' must be set with the versions
diff --git a/gas/testsuite/gas/riscv/march-fail-order-x.l b/gas/testsuite/gas/riscv/march-fail-order-x.l
index 025db14..6bc8cf4 100644
--- a/gas/testsuite/gas/riscv/march-fail-order-x.l
+++ b/gas/testsuite/gas/riscv/march-fail-order-x.l
@@ -1,2 +1,4 @@ 
 .*Assembler messages:
+.*Warning: -march=rv32i_xbargle2p0_xargle2p0: unknown x ISA extension `xbargle'
+.*Warning: -march=rv32i_xbargle2p0_xargle2p0: unknown x ISA extension `xargle'
 .*Error: .*x ISA extension `xargle' is not in alphabetical order.  It must come before `xbargle'
diff --git a/gas/testsuite/gas/riscv/march-fail-porder.l b/gas/testsuite/gas/riscv/march-fail-porder.l
index c5496ea..cc40db0 100644
--- a/gas/testsuite/gas/riscv/march-fail-porder.l
+++ b/gas/testsuite/gas/riscv/march-fail-porder.l
@@ -1,2 +1,3 @@ 
 .*Assembler messages:
+#...
 .*Error: .*unexpected ISA string at end:.*
diff --git a/gas/testsuite/gas/riscv/march-ok-nse-with-version.d b/gas/testsuite/gas/riscv/march-ok-nse-with-version.d
index 8e2110c..23b6314 100644
--- a/gas/testsuite/gas/riscv/march-ok-nse-with-version.d
+++ b/gas/testsuite/gas/riscv/march-ok-nse-with-version.d
@@ -1,5 +1,6 @@ 
 #as: -march=rv32imafd_xargle2p0
-#objdump: -dr
 #source: empty.s
+#warning_output: march-ok-nse-with-version.l
+#objdump: -dr
 
 .*:     file format elf32-(little|big)riscv
diff --git a/gas/testsuite/gas/riscv/march-ok-nse-with-version.l b/gas/testsuite/gas/riscv/march-ok-nse-with-version.l
new file mode 100644
index 0000000..363ed47
--- /dev/null
+++ b/gas/testsuite/gas/riscv/march-ok-nse-with-version.l
@@ -0,0 +1,2 @@ 
+.*Assembler messages:
+.*Warning: -march=rv32imafd_xargle2p0: unknown x ISA extension `xargle'
diff --git a/gas/testsuite/gas/riscv/march-ok-two-nse.d b/gas/testsuite/gas/riscv/march-ok-two-nse.d
index 8cdf316..ad7d09d 100644
--- a/gas/testsuite/gas/riscv/march-ok-two-nse.d
+++ b/gas/testsuite/gas/riscv/march-ok-two-nse.d
@@ -1,5 +1,6 @@ 
 #as: -march=rv32imafd_xargle2p0_xbargle3p0
-#objdump: -dr
 #source: empty.s
+#warning_output: march-ok-two-nse.l
+#objdump: -dr
 
 .*:     file format elf32-(little|big)riscv
diff --git a/gas/testsuite/gas/riscv/march-ok-two-nse.l b/gas/testsuite/gas/riscv/march-ok-two-nse.l
new file mode 100644
index 0000000..9a6f63d
--- /dev/null
+++ b/gas/testsuite/gas/riscv/march-ok-two-nse.l
@@ -0,0 +1,3 @@ 
+.*Assembler messages:
+.*Warning: -march=rv32imafd_xargle2p0_xbargle3p0: unknown x ISA extension `xargle'
+.*Warning: -march=rv32imafd_xargle2p0_xbargle3p0: unknown x ISA extension `xbargle'
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.d b/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.d
index 374a043..330c7db 100644
--- a/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.d
+++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.d
@@ -2,6 +2,7 @@ 
 #source: attr-merge-arch-03b.s
 #as:
 #ld: -r -m[riscv_choose_ilp32_emul]
+#warning_output: attr-merge-arch-03.l
 #readelf: -A
 
 Attribute Section: riscv
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.l b/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.l
new file mode 100644
index 0000000..83ddd24
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/attr-merge-arch-03.l
@@ -0,0 +1,3 @@ 
+#...
+.*unknown x ISA extension `(xfoo|xbar)'
+#...