RISC-V: The object without priv spec attributes can be linked with any object.
authorNelson Chu <nelson.chu@sifive.com>
Fri, 29 May 2020 08:56:36 +0000 (16:56 +0800)
committerNelson Chu <nelson.chu@sifive.com>
Fri, 5 Jun 2020 04:20:53 +0000 (12:20 +0800)
bfd/
* elfnn-riscv.c (riscv_merge_attributes): Add new boolean
priv_may_conflict, in_priv_zero and out_priv_zero to decide whether
the object can be linked according to it's priv attributes.  The object
without any priv spec attributes can be linked with others.  If the first
input object doesn't contain any priv attributes, then we need to copy
the setting from the next input one.  Also report more detailed error
messages to user.

ld/
* testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Rename to
attr-merge-priv-spec-01.d.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s: Set priv spec
to 1.11.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s: Empty priv spec
setting.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: New testcase.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.

16 files changed:
bfd/ChangeLog
bfd/elfnn-riscv.c
ld/ChangeLog
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/attr-merge-priv-spec.d [deleted file]
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp

index e99de6dbed89b44fa0da36796c7b47610f2f273d..0a34054da8cd1a72bd54e8117418db3b0d109930 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-05  Nelson Chu  <nelson.chu@sifive.com>
+
+       * elfnn-riscv.c (riscv_merge_attributes): Add new boolean
+       priv_may_conflict, in_priv_zero and out_priv_zero to decide
+       whether the object can be linked according to it's priv
+       attributes.  The object without any priv spec attributes can
+       be linked with others.  If the first input object doesn't contain
+       any priv attributes, then we need to copy the setting from the
+       next input one.  Also report more detailed error messages to user.
+
 2020-06-04  Stephen Casner  <casner@acm.org>
 
        Extend pdp11-aout symbol table format to accommodate .stab
index 163c4d9f7450f85d128966ba81668e99c8809095..986e717782fc2e5556295bcaca699d6cc7e21c80 100644 (file)
@@ -2987,6 +2987,9 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
   obj_attribute *in_attr;
   obj_attribute *out_attr;
   bfd_boolean result = TRUE;
+  bfd_boolean priv_may_conflict = FALSE;
+  bfd_boolean in_priv_zero = TRUE;
+  bfd_boolean out_priv_zero = TRUE;
   const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
   unsigned int i;
 
@@ -3041,20 +3044,52 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
              out_attr[Tag_RISCV_arch].s = merged_arch;
          }
        break;
+
       case Tag_RISCV_priv_spec:
       case Tag_RISCV_priv_spec_minor:
       case Tag_RISCV_priv_spec_revision:
+       if (in_attr[i].i != 0)
+         in_priv_zero = FALSE;
+       if (out_attr[i].i != 0)
+         out_priv_zero = FALSE;
        if (out_attr[i].i != in_attr[i].i)
+         priv_may_conflict = TRUE;
+
+       /* We check the priv version conflict when parsing the
+          revision version.  */
+       if (i != Tag_RISCV_priv_spec_revision)
+         break;
+
+       /* Allow to link the object without the priv setting.  */
+       if (out_priv_zero)
+         {
+           out_attr[i].i = in_attr[i].i;
+           out_attr[Tag_RISCV_priv_spec].i =
+               in_attr[Tag_RISCV_priv_spec].i;
+           out_attr[Tag_RISCV_priv_spec_minor].i =
+               in_attr[Tag_RISCV_priv_spec_minor].i;
+         }
+       else if (!in_priv_zero
+                && priv_may_conflict)
          {
            _bfd_error_handler
-             (_("error: %pB: conflicting priv spec version "
-                "(major/minor/revision)."), ibfd);
+             (_("error: %pB use privilege spec version %u.%u.%u but "
+                "the output use version %u.%u.%u."),
+              ibfd,
+              in_attr[Tag_RISCV_priv_spec].i,
+              in_attr[Tag_RISCV_priv_spec_minor].i,
+              in_attr[i].i,
+              out_attr[Tag_RISCV_priv_spec].i,
+              out_attr[Tag_RISCV_priv_spec_minor].i,
+              out_attr[i].i);
            result = FALSE;
          }
        break;
+
       case Tag_RISCV_unaligned_access:
        out_attr[i].i |= in_attr[i].i;
        break;
+
       case Tag_RISCV_stack_align:
        if (out_attr[i].i == 0)
          out_attr[i].i = in_attr[i].i;
@@ -3069,6 +3104,7 @@ riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
            result = FALSE;
          }
        break;
+
       default:
        result &= _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
       }
index 5b6805a31bc4a17b41c4f618716428aa2a487957..b40d36b3e7447c9fcec7d85ce97ab9b9f397d529 100644 (file)
@@ -1,3 +1,18 @@
+2020-06-05  Nelson Chu  <nelson.chu@sifive.com>
+
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Rename to
+       attr-merge-priv-spec-01.d.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s: Set spec to 1.11.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-d.s: Empty priv spec set.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: New testcase.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
+       * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
+       * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
+
 2020-06-05  Nelson Chu  <nelson.chu@sifive.com>
 
        * testsuite/ld-riscv-elf/attr-merge-arch-01.d: The CSR isn't used,
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
new file mode 100644 (file)
index 0000000..0aa6fe0
--- /dev/null
@@ -0,0 +1,12 @@
+#source: attr-merge-priv-spec-a.s
+#source: attr-merge-priv-spec-b.s
+#as: -march-attr
+#ld: -r
+#readelf: -A
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
+  Tag_RISCV_priv_spec: 1
+  Tag_RISCV_priv_spec_minor: 9
+  Tag_RISCV_priv_spec_revision: 1
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
new file mode 100644 (file)
index 0000000..0ac4ca7
--- /dev/null
@@ -0,0 +1,12 @@
+#source: attr-merge-priv-spec-a.s
+#source: attr-merge-priv-spec-d.s
+#as: -march-attr
+#ld: -r
+#readelf: -A
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
+  Tag_RISCV_priv_spec: 1
+  Tag_RISCV_priv_spec_minor: 9
+  Tag_RISCV_priv_spec_revision: 1
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
new file mode 100644 (file)
index 0000000..6950483
--- /dev/null
@@ -0,0 +1,12 @@
+#source: attr-merge-priv-spec-d.s
+#source: attr-merge-priv-spec-a.s
+#as: -march-attr
+#ld: -r
+#readelf: -A
+
+Attribute Section: riscv
+File Attributes
+  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
+  Tag_RISCV_priv_spec: 1
+  Tag_RISCV_priv_spec_minor: 9
+  Tag_RISCV_priv_spec_revision: 1
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-c.s
new file mode 100644 (file)
index 0000000..7ea3185
--- /dev/null
@@ -0,0 +1,2 @@
+       .attribute priv_spec, 1
+       .attribute priv_spec_minor, 11
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
new file mode 100644 (file)
index 0000000..37fddd0
--- /dev/null
@@ -0,0 +1 @@
+# Empty priv attributes setting.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d
new file mode 100644 (file)
index 0000000..c52ebac
--- /dev/null
@@ -0,0 +1,5 @@
+#source: attr-merge-priv-spec-a.s
+#source: attr-merge-priv-spec-c.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.11.0 but the output use version 1.9.1.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d
new file mode 100644 (file)
index 0000000..fc00145
--- /dev/null
@@ -0,0 +1,5 @@
+#source: attr-merge-priv-spec-c.s
+#source: attr-merge-priv-spec-a.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.9.1 but the output use version 1.11.0.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d
new file mode 100644 (file)
index 0000000..1d40e90
--- /dev/null
@@ -0,0 +1,6 @@
+#source: attr-merge-priv-spec-a.s
+#source: attr-merge-priv-spec-d.s
+#source: attr-merge-priv-spec-c.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.11.0 but the output use version 1.9.1.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d
new file mode 100644 (file)
index 0000000..0efee3c
--- /dev/null
@@ -0,0 +1,6 @@
+#source: attr-merge-priv-spec-d.s
+#source: attr-merge-priv-spec-a.s
+#source: attr-merge-priv-spec-c.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.11.0 but the output use version 1.9.1.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d
new file mode 100644 (file)
index 0000000..5b9b8d0
--- /dev/null
@@ -0,0 +1,6 @@
+#source: attr-merge-priv-spec-c.s
+#source: attr-merge-priv-spec-d.s
+#source: attr-merge-priv-spec-a.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.9.1 but the output use version 1.11.0.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d
new file mode 100644 (file)
index 0000000..dab7eb6
--- /dev/null
@@ -0,0 +1,6 @@
+#source: attr-merge-priv-spec-d.s
+#source: attr-merge-priv-spec-c.s
+#source: attr-merge-priv-spec-a.s
+#as:
+#ld: -r
+#error: .*use privilege spec version 1.9.1 but the output use version 1.11.0.
diff --git a/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec.d b/ld/testsuite/ld-riscv-elf/attr-merge-priv-spec.d
deleted file mode 100644 (file)
index 0aa6fe0..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#source: attr-merge-priv-spec-a.s
-#source: attr-merge-priv-spec-b.s
-#as: -march-attr
-#ld: -r
-#readelf: -A
-
-Attribute Section: riscv
-File Attributes
-  Tag_RISCV_arch: [a-zA-Z0-9_\"].*
-  Tag_RISCV_priv_spec: 1
-  Tag_RISCV_priv_spec_minor: 9
-  Tag_RISCV_priv_spec_revision: 1
index 0e9750e496009ce6adbeeb6d3ffebca416d70028..1a0c68fc44fd7b85a668314b3fdffe18a512f666 100644 (file)
@@ -35,9 +35,17 @@ if [istarget "riscv*-*-*"] {
     run_dump_test "attr-merge-strict-align-04"
     run_dump_test "attr-merge-strict-align-05"
     run_dump_test "attr-merge-stack-align"
-    run_dump_test "attr-merge-priv-spec"
+    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-arch-failed-01"
     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"
+    run_dump_test "attr-merge-priv-spec-failed-03"
+    run_dump_test "attr-merge-priv-spec-failed-04"
+    run_dump_test "attr-merge-priv-spec-failed-05"
+    run_dump_test "attr-merge-priv-spec-failed-06"
     run_ld_link_tests {
        { "Weak reference 32" "-T weakref.ld -melf32lriscv" ""
            "-march=rv32i -mabi=ilp32" {weakref32.s}