RISC-V: Report warnings rather than errors for the mis-matched ISA versions.
authorNelson Chu <nelson.chu@sifive.com>
Tue, 18 Aug 2020 09:48:34 +0000 (17:48 +0800)
committerNelson Chu <nelson.chu@sifive.com>
Thu, 3 Sep 2020 03:11:51 +0000 (11:11 +0800)
Same as the privileged spec attributes check - different ISA versions
should be compatible, unless there are some known conflicts.  Therefore,
we should allow to link objects with different ISA versions, and update
the output ISA versions once the corresponding input ones are newer.
But it's better to also warn people that the conflicts may happen when
the ISA versions are mis-matched.

bfd/
* elfnn-riscv.c (riscv_version_mismatch): Change the return type
from void to bfd_boolean.  Report warnings rather than errors
when the ISA versions are mis-matched.  Afterwards, remember to
update the output ISA versions to the newest ones.
(riscv_merge_std_ext): Allow to link objects with different
standard ISA versions.  Try to add output ISA versions to
merged_subsets first.
(riscv_merge_multi_letter_ext): Likewise.  But for standard additional
ISA and non-standard ISA versions.

ld/
* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Update the
message from error to warning.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: New testcases.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

bfd/ChangeLog
bfd/elfnn-riscv.c
ld/ChangeLog
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp

index 8703aebeb3464f5998e8407272289c0ea9cc2fbf..3bf4d2938895fad1c862104aca44da6cce2de90c 100644 (file)
@@ -1,3 +1,15 @@
+2020-09-03  Nelson Chu  <nelson.chu@sifive.com>
+
+       * elfnn-riscv.c (riscv_version_mismatch): Change the return type
+       from void to bfd_boolean.  Report warnings rather than errors
+       when the ISA versions are mis-matched.  Afterwards, remember to
+       update the output ISA versions to the newest ones.
+       (riscv_merge_std_ext): Allow to link objects with different
+       standard ISA versions.  Try to add output ISA versions to
+       merged_subsets first.
+       (riscv_merge_multi_letter_ext): Likewise.  But for standard additional
+       ISA and non-standard ISA versions.
+
 2020-09-03  Kito Cheng  <kito.cheng@sifive.com>
 
        * elfnn-riscv.c (riscv_merge_std_ext): Fix to report the correct
index f8de7194ea65edcd8d8e8422cb45117e7931c05e..83d4e63ceb4de344853987f7911fde163af666fa 100644 (file)
@@ -2618,19 +2618,42 @@ riscv_std_ext_p (const char *name)
   return (strlen (name) == 1) && (name[0] != 'x') && (name[0] != 's');
 }
 
-/* Error handler when version mis-match.  */
+/* Check if the versions are compatible.  */
 
-static void
+static bfd_boolean
 riscv_version_mismatch (bfd *ibfd,
                        struct riscv_subset_t *in,
                        struct riscv_subset_t *out)
 {
-  _bfd_error_handler
-    (_("error: %pB: Mis-matched ISA version for '%s' extension. "
-       "%d.%d vs %d.%d"),
-       ibfd, in->name,
-       in->major_version, in->minor_version,
-       out->major_version, out->minor_version);
+  if (in == NULL || out == NULL)
+    return TRUE;
+
+  /* Since there are no version conflicts for now, we just report
+     warning when the versions are mis-matched.  */
+  if (in->major_version != out->major_version
+      || in->minor_version != out->minor_version)
+    {
+      _bfd_error_handler
+       (_("warning: %pB: mis-matched ISA version %d.%d for '%s' "
+          "extension, the output version is %d.%d"),
+        ibfd,
+        in->major_version,
+        in->minor_version,
+        in->name,
+        out->major_version,
+        out->minor_version);
+
+      /* Update the output ISA versions to the newest ones.  */
+      if ((in->major_version > out->major_version)
+         || (in->major_version == out->major_version
+             && in->minor_version > out->minor_version))
+       {
+         out->major_version = in->major_version;
+         out->minor_version = in->minor_version;
+       }
+    }
+
+  return TRUE;
 }
 
 /* Return true if subset is 'i' or 'e'.  */
@@ -2692,16 +2715,11 @@ riscv_merge_std_ext (bfd *ibfd,
         ibfd, in->name, out->name);
       return FALSE;
     }
-  else if ((in->major_version != out->major_version) ||
-          (in->minor_version != out->minor_version))
-    {
-      /* TODO: Allow different merge policy.  */
-      riscv_version_mismatch (ibfd, in, out);
-      return FALSE;
-    }
+  else if (!riscv_version_mismatch (ibfd, in, out))
+    return FALSE;
   else
     riscv_add_subset (&merged_subsets,
-                     in->name, in->major_version, in->minor_version);
+                     out->name, out->major_version, out->minor_version);
 
   in = in->next;
   out = out->next;
@@ -2718,17 +2736,10 @@ riscv_merge_std_ext (bfd *ibfd,
       if (find_in == NULL && find_out == NULL)
        continue;
 
-      /* Check version is same or not.  */
-      /* TODO: Allow different merge policy.  */
-      if ((find_in != NULL && find_out != NULL)
-         && ((find_in->major_version != find_out->major_version)
-             || (find_in->minor_version != find_out->minor_version)))
-       {
-         riscv_version_mismatch (ibfd, find_in, find_out);
-         return FALSE;
-       }
+      if (!riscv_version_mismatch (ibfd, find_in, find_out))
+       return FALSE;
 
-      struct riscv_subset_t *merged = find_in ? find_in : find_out;
+      struct riscv_subset_t *merged = find_out ? find_out : find_in;
       riscv_add_subset (&merged_subsets, merged->name,
                        merged->major_version, merged->minor_version);
     }
@@ -2812,12 +2823,8 @@ riscv_merge_multi_letter_ext (bfd *ibfd,
       else
        {
          /* Both present, check version and increment both.  */
-         if ((in->major_version != out->major_version)
-             || (in->minor_version != out->minor_version))
-           {
-             riscv_version_mismatch (ibfd, in, out);
-             return FALSE;
-           }
+         if (!riscv_version_mismatch (ibfd, in, out))
+           return FALSE;
 
          riscv_add_subset (&merged_subsets, out->name, out->major_version,
                            out->minor_version);
index 4bba88474378f52faade677ffae297117835dc26..185f37b031fca950599e2a6512e2cd41020f6ffc 100644 (file)
@@ -1,3 +1,14 @@
+2020-09-03  Nelson Chu  <nelson.chu@sifive.com>
+
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Update the
+       message from error to warning.
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: New testcases.
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s: Likewise.
+       * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
+
 2020-09-03  Kito Cheng  <kito.cheng@sifive.com>
 
        * testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Updated.
index 8a9c0929f80b4f315f10b967fefdfa300ff9b3dc..4b312388f72e5d8799b6f13e61c8e0b5dd9e3955 100644 (file)
@@ -2,4 +2,10 @@
 #source: attr-merge-arch-failed-01b.s
 #as: -march-attr
 #ld: -r -melf32lriscv
-#error: Mis-matched ISA version for 'a' extension. 3.0 vs 2.0
+#warning: .*mis-matched ISA version 3.0 for 'a' extension, the output version is 2.0
+#readelf: -A
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: ".*a3p0.*"
+#..
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d b/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d
new file mode 100644 (file)
index 0000000..880ee15
--- /dev/null
@@ -0,0 +1,27 @@
+#source: attr-merge-arch-failed-02a.s
+#source: attr-merge-arch-failed-02b.s
+#source: attr-merge-arch-failed-02c.s
+#source: attr-merge-arch-failed-02d.s
+#as: -march-attr
+#ld: -r -melf32lriscv
+#warning: .*mis-matched ISA version 3.0 for 'i' extension, the output version is 2.0
+#warning: .*mis-matched ISA version 3.0 for 'm' extension, the output version is 2.0
+#warning: .*mis-matched ISA version 3.0 for 'a' extension, the output version is 2.0
+#warning: .*mis-matched ISA version 3.0 for 'zicsr' extension, the output version is 2.0
+#warning: .*mis-matched ISA version 3.0 for 'xunknown' extension, the output version is 2.0
+#warning: .*mis-matched ISA version 2.1 for 'i' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 2.2 for 'm' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 2.3 for 'a' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 2.4 for 'zicsr' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 2.5 for 'xunknown' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 4.6 for 'i' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 4.7 for 'm' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 4.8 for 'a' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 4.9 for 'zicsr' extension, the output version is 3.0
+#warning: .*mis-matched ISA version 4.0 for 'xunknown' extension, the output version is 3.0
+#readelf: -A
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: "rv32i4p6_m4p7_a4p8_zicsr4p9_xunknown4p0"
+#..
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s b/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s
new file mode 100644 (file)
index 0000000..3dbf8a2
--- /dev/null
@@ -0,0 +1 @@
+       .attribute arch, "rv32i2p0_m2p0_a2p0_zicsr2p0_xunknown2p0"
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s b/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s
new file mode 100644 (file)
index 0000000..7bbc39f
--- /dev/null
@@ -0,0 +1 @@
+       .attribute arch, "rv32i3p0_m3p0_a3p0_zicsr3p0_xunknown3p0"
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s b/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s
new file mode 100644 (file)
index 0000000..2a921e6
--- /dev/null
@@ -0,0 +1 @@
+       .attribute arch, "rv32i2p1_m2p2_a2p3_zicsr2p4_xunknown2p5"
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s b/ld/testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s
new file mode 100644 (file)
index 0000000..6ef5ee5
--- /dev/null
@@ -0,0 +1 @@
+       .attribute arch, "rv32i4p6_m4p7_a4p8_zicsr4p9_xunknown4p0"
index 1a0c68fc44fd7b85a668314b3fdffe18a512f666..2c008d4c35cdd3ed7041094652181358eddb9930 100644 (file)
@@ -39,6 +39,7 @@ if [istarget "riscv*-*-*"] {
     run_dump_test "attr-merge-priv-spec-02"
     run_dump_test "attr-merge-priv-spec-03"
     run_dump_test "attr-merge-arch-failed-01"
+    run_dump_test "attr-merge-arch-failed-02"
     run_dump_test "attr-merge-stack-align-failed"
     run_dump_test "attr-merge-priv-spec-failed-01"
     run_dump_test "attr-merge-priv-spec-failed-02"