]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gnu directives: bfd: generic tests for merge of gnu attributes v2
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 10 Apr 2025 15:11:02 +0000 (16:11 +0100)
committerMatthieu Longo <matthieu.longo@arm.com>
Thu, 22 Jan 2026 10:11:17 +0000 (10:11 +0000)
These tests are a copy-paste of the generic tests for AArch64.

Test cases:
    - only one input object is copied to the output object
    - merge two inputs with optional subsections of both types
      ULEB128 and NTBS, which contains same, additional, and
      missing attributes.
    - mismatch subsection properties.
    - combine matching required subsections.
    - combine non-matching required subsections.
    - prune unknown attributes in known subsections.
    - prune unknown subsections.

18 files changed:
ld/testsuite/ld-attributes/ld-attributes.exp [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-all-optional-1.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-all-optional-2.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-one-file.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-1-two-files-all-optional-1more-1missing.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-1.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-2.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-1.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-2.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-required-subsec-A-1.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-required-subsec-A-2.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-required-subsec-B.s [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-required-subsec-nok.d [new file with mode: 0644]
ld/testsuite/ld-attributes/oav2-2-required-subsec-ok.d [new file with mode: 0644]

diff --git a/ld/testsuite/ld-attributes/ld-attributes.exp b/ld/testsuite/ld-attributes/ld-attributes.exp
new file mode 100644 (file)
index 0000000..dd1dc01
--- /dev/null
@@ -0,0 +1,31 @@
+# Expect script for AARCH64 ELF tests related to GNU properties.
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+#
+# Generic tests for GNU attributes v2
+#
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+
+foreach t $test_list {
+  # We need to strip the ".d", but can leave the dirname.
+  run_dump_test [file rootname $t] \
+    [list [list as "-I\$srcdir/\$subdir"]]
+}
diff --git a/ld/testsuite/ld-attributes/oav2-1-all-optional-1.s b/ld/testsuite/ld-attributes/oav2-1-all-optional-1.s
new file mode 100644 (file)
index 0000000..5cda02a
--- /dev/null
@@ -0,0 +1,15 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 0
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 0
+       .gnu_attribute  1, 1
+
+       .gnu_subsection gnu_testing_ba_3_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "hello"
+       .gnu_attribute  1, "world"
+
+       .gnu_subsection gnu_testing_ba_5_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "hello"
+       .gnu_attribute  1, "world"
diff --git a/ld/testsuite/ld-attributes/oav2-1-all-optional-2.s b/ld/testsuite/ld-attributes/oav2-1-all-optional-2.s
new file mode 100644 (file)
index 0000000..afe9334
--- /dev/null
@@ -0,0 +1,15 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection gnu_testing_ba_4_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
+
+       .gnu_subsection gnu_testing_ba_5_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
diff --git a/ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.d b/ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.d
new file mode 100644 (file)
index 0000000..939069b
--- /dev/null
@@ -0,0 +1,11 @@
+# name: Object Attributes v2: mismatch subsection properties with oav2-1-all-optional-1
+# target: [supports_oa_v2]
+# source: oav2-1-all-optional-1.s
+# source: oav2-1-mismatch-subsec-props-with-all-optional-1.s
+# ld: -shared
+#error: \A[^\n]*oav2-1-mismatch-subsec-props-with-all-optional-1\.o: error: mismatching properties of subsection 'gnu_testing_ba_1_MERGE_AND'
+#error: \n[^\n]*oav2-1-all-optional-1\.o: info: conflicting properties \(optional, .*\) live here
+#error: \ninfo: \(required, .*\) VS \(optional, .*\)
+#error: \n[^\n]*oav2-1-mismatch-subsec-props-with-all-optional-1\.o: error: mismatching properties of subsection 'gnu_testing_ba_2_MERGE_AND'
+#error: \n[^\n]*oav2-1-all-optional-1\.o: info: conflicting properties \(.*, ULEB128\) live here
+#error: \ninfo: \(.*, NTBS\) VS \(.*, ULEB128\)\Z
diff --git a/ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.s b/ld/testsuite/ld-attributes/oav2-1-mismatch-subsec-props-with-all-optional-1.s
new file mode 100644 (file)
index 0000000..701c6c5
--- /dev/null
@@ -0,0 +1,2 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128
+       .gnu_subsection gnu_testing_ba_2_MERGE_AND, optional, ntbs
diff --git a/ld/testsuite/ld-attributes/oav2-1-one-file.d b/ld/testsuite/ld-attributes/oav2-1-one-file.d
new file mode 100644 (file)
index 0000000..f609616
--- /dev/null
@@ -0,0 +1,42 @@
+# name: Object Attributes v2: only one input object is copied to the output object
+# target: [supports_oa_v2]
+# source: oav2-1-all-optional-1.s
+# ld: -shared
+# readelf: --arch-specific
+
+Subsections:
+ - Name:[       ]+gnu_testing_ba_1_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+1 .*
+ +Tag_unknown_1:[       ]+0 .*
+
+ - Name:[       ]+gnu_testing_ba_2_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+0 .*
+ +Tag_unknown_1:[       ]+1 .*
+
+ - Name:[       ]+gnu_testing_ba_3_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+47
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"hello"
+ +Tag_unknown_1:[       ]+"world"
+
+ - Name:[       ]+gnu_testing_ba_5_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+47
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"hello"
+ +Tag_unknown_1:[       ]+"world"
diff --git a/ld/testsuite/ld-attributes/oav2-1-two-files-all-optional-1more-1missing.d b/ld/testsuite/ld-attributes/oav2-1-two-files-all-optional-1more-1missing.d
new file mode 100644 (file)
index 0000000..6e327d3
--- /dev/null
@@ -0,0 +1,53 @@
+# name: Object Attributes v2: 2 files, all optional, 1 more, 1 missing
+# target: [supports_oa_v2]
+# source: oav2-1-all-optional-1.s
+# source: oav2-1-all-optional-2.s
+# ld: -shared
+# readelf: --arch-specific
+
+Subsections:
+ - Name:[       ]+gnu_testing_ba_1_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+1 .*
+ +Tag_unknown_1:[       ]+0 .*
+
+ - Name:[       ]+gnu_testing_ba_2_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+0 .*
+ +Tag_unknown_1:[       ]+1 .*
+
+ - Name:[       ]+gnu_testing_ba_3_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+47
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"hello"
+ +Tag_unknown_1:[       ]+"world"
+
+ - Name:[       ]+gnu_testing_ba_4_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+43
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"foo"
+ +Tag_unknown_1:[       ]+"bar"
+
+ - Name:[       ]+gnu_testing_ba_5_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+55
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"hello\+foo"
+ +Tag_unknown_1:[       ]+"world\+bar"
+
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-1.s b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-1.s
new file mode 100644 (file)
index 0000000..6636f7e
--- /dev/null
@@ -0,0 +1,11 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+       .gnu_attribute  2, 1 // Unknown tag
+       .gnu_attribute  3, 1 // Unknown tag
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
+       .gnu_attribute  2, "foo2" // Unknown tag
+       .gnu_attribute  3, "foo3" // Unknown tag
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-2.s b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection-2.s
new file mode 100644 (file)
index 0000000..42bed8a
--- /dev/null
@@ -0,0 +1,11 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+       .gnu_attribute  2, 1 // Unknown tag
+       .gnu_attribute  4, 1 // Unknown tag
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
+       .gnu_attribute  2, "foo2" // Unknown tag
+       .gnu_attribute  4, "foo4" // Unknown tag
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection.d b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-attr-known-subsection.d
new file mode 100644 (file)
index 0000000..4c7a924
--- /dev/null
@@ -0,0 +1,25 @@
+# name: Object Attributes v2: unknown attribute inside known subsection should be removed from the output.
+# target: [supports_oa_v2]
+# source: oav2-2-mix-unknown-and-known-attr-known-subsection-1.s
+# source: oav2-2-mix-unknown-and-known-attr-known-subsection-2.s
+# ld: -shared
+# readelf: --arch-specific
+
+Subsections:
+ - Name:[       ]+gnu_testing_ba_1_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+1 .*
+ +Tag_unknown_1:[       ]+1 .*
+
+ - Name:[       ]+gnu_testing_ba_2_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+51
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"foo\+foo"
+ +Tag_unknown_1:[       ]+"bar\+bar"
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-1.s b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-1.s
new file mode 100644 (file)
index 0000000..6c696bf
--- /dev/null
@@ -0,0 +1,19 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 0
+
+       .gnu_subsection private_1, optional, uleb128
+       .gnu_attribute  0, 0
+       .gnu_attribute  1, 1
+
+       .gnu_subsection private_2, optional, ntbs
+       .gnu_attribute  0, "hello"
+       .gnu_attribute  1, "world"
+
+       .gnu_subsection private_4, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "hello"
+       .gnu_attribute  1, "world"
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-2.s b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections-2.s
new file mode 100644 (file)
index 0000000..82cc675
--- /dev/null
@@ -0,0 +1,19 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection private_1, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection private_2, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
+
+       .gnu_subsection private_3, optional, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
+
+       .gnu_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs
+       .gnu_attribute  0, "foo"
+       .gnu_attribute  1, "bar"
diff --git a/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections.d b/ld/testsuite/ld-attributes/oav2-2-mix-unknown-and-known-subsections.d
new file mode 100644 (file)
index 0000000..14a39d2
--- /dev/null
@@ -0,0 +1,26 @@
+# name: Object Attributes v2: unknown subsections are removed from the output.
+# target: [supports_oa_v2]
+# source: oav2-2-mix-unknown-and-known-subsections-1.s
+# source: oav2-2-mix-unknown-and-known-subsections-2.s
+# ld: -shared
+# readelf: --arch-specific
+
+Subsections:
+ - Name:[       ]+gnu_testing_ba_1_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+optional
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+1 .*
+ +Tag_unknown_1:[       ]+0 .*
+
+ - Name:[       ]+gnu_testing_ba_2_MERGE_ADD
+   Scope:[      ]+private
+   Length:[     ]+55
+   Comprehension:[      ]+optional
+   Encoding:[   ]+NTBS
+   Values:
+ +Tag_unknown_0:[       ]+"hello\+foo"
+ +Tag_unknown_1:[       ]+"world\+bar"
+
diff --git a/ld/testsuite/ld-attributes/oav2-2-required-subsec-A-1.s b/ld/testsuite/ld-attributes/oav2-2-required-subsec-A-1.s
new file mode 100644 (file)
index 0000000..83412b7
--- /dev/null
@@ -0,0 +1,3 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 0
diff --git a/ld/testsuite/ld-attributes/oav2-2-required-subsec-A-2.s b/ld/testsuite/ld-attributes/oav2-2-required-subsec-A-2.s
new file mode 100644 (file)
index 0000000..83412b7
--- /dev/null
@@ -0,0 +1,3 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 0
diff --git a/ld/testsuite/ld-attributes/oav2-2-required-subsec-B.s b/ld/testsuite/ld-attributes/oav2-2-required-subsec-B.s
new file mode 100644 (file)
index 0000000..4664e6d
--- /dev/null
@@ -0,0 +1,3 @@
+       .gnu_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128
+       .gnu_attribute  0, 1
+       .gnu_attribute  1, 1
diff --git a/ld/testsuite/ld-attributes/oav2-2-required-subsec-nok.d b/ld/testsuite/ld-attributes/oav2-2-required-subsec-nok.d
new file mode 100644 (file)
index 0000000..f80b2b9
--- /dev/null
@@ -0,0 +1,8 @@
+# name: Object Attributes v2: combine non-matching required subsections
+# target: [supports_oa_v2]
+# source: oav2-2-required-subsec-A-1.s
+# source: oav2-2-required-subsec-B.s
+# source: oav2-2-required-subsec-A-2.s
+# ld: -shared
+#error: \A[^\n]*oav2-2-required-subsec-B\.o: error: mismatching value for required object attribute 'GNUTestTag_1' in subsection 'gnu_testing_ba_1_MERGE_AND': 0x1
+#error: \n[^\n]*oav2-2-required-subsec-A-1\.o: info: conflicting value '0' lives here\Z
diff --git a/ld/testsuite/ld-attributes/oav2-2-required-subsec-ok.d b/ld/testsuite/ld-attributes/oav2-2-required-subsec-ok.d
new file mode 100644 (file)
index 0000000..f7f8153
--- /dev/null
@@ -0,0 +1,16 @@
+# name: Object Attributes v2: combine matching required subsections
+# target: [supports_oa_v2]
+# source: oav2-2-required-subsec-A-1.s
+# source: oav2-2-required-subsec-A-2.s
+# ld: -shared
+# readelf: --arch-specific
+
+Subsections:
+ - Name:[       ]+gnu_testing_ba_1_MERGE_AND
+   Scope:[      ]+private
+   Length:[     ]+37
+   Comprehension:[      ]+required
+   Encoding:[   ]+ULEB128
+   Values:
+ +Tag_unknown_0:[       ]+1 .*
+ +Tag_unknown_1:[       ]+0 .*