From: Matthieu Longo Date: Tue, 25 Feb 2025 17:26:57 +0000 (+0000) Subject: ld tests for generic merge coverage of Object Attributes v2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ead2e8367044b9fc69c96cd42b8050d3709362e;p=thirdparty%2Fbinutils-gdb.git ld tests for generic merge coverage of Object Attributes v2 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. --- diff --git a/ld/testsuite/ld-aarch64/build-attributes/aarch64-build-attributes.exp b/ld/testsuite/ld-aarch64/build-attributes/aarch64-build-attributes.exp new file mode 100644 index 00000000000..655a6797145 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/aarch64-build-attributes.exp @@ -0,0 +1,47 @@ +# 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. + +# Exclude non-aarch64-ELF targets. +if { ![is_elf_format] || ![istarget "aarch64*-*-*"] } { + return +} + +load_file $srcdir/$subdir/../lib/aarch64-elf-lib.exp + +set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] + +# See definition of run_ld_link_tests in testsuite/lib/ld-lib.exp for more +# details. +# set aarch64elflinktests { +# {"Build bti-plt-so for PLT tests" +# "-shared" "" +# "-I$srcdir/$subdir -defsym __property_bti__=1" +# {bti-plt-so.s} {} "libbti-plt-so.so"} +# } + +# if [check_shared_lib_support] { +# run_ld_link_tests $aarch64elflinktests +# } + +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-aarch64/build-attributes/ba-1-all-optional-1.s b/ld/testsuite/ld-aarch64/build-attributes/ba-1-all-optional-1.s new file mode 100644 index 00000000000..7db4ad1f96d --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-all-optional-1.s @@ -0,0 +1,15 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 0 + +.aeabi_subsection gnu_testing_ba_2_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 0 +.aeabi_attribute 1, 1 + +.aeabi_subsection gnu_testing_ba_3_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "hello" +.aeabi_attribute 1, "world" + +.aeabi_subsection gnu_testing_ba_5_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "hello" +.aeabi_attribute 1, "world" diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-1-all-optional-2.s b/ld/testsuite/ld-aarch64/build-attributes/ba-1-all-optional-2.s new file mode 100644 index 00000000000..55d37943dae --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-all-optional-2.s @@ -0,0 +1,15 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection gnu_testing_ba_2_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection gnu_testing_ba_4_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" + +.aeabi_subsection gnu_testing_ba_5_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.d b/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.d new file mode 100644 index 00000000000..e3538652055 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.d @@ -0,0 +1,11 @@ +# name: Build attributes: mismatch subsection properties with ba-1-all-optional-1 +# source: ba-1-all-optional-1.s +# source: ba-1-mismatch-subsec-props-with-all-optional-1.s +# as: +# ld: -shared +#error: \A[^\n]*ba-1-mismatch-subsec-props-with-all-optional-1\.o: error: mismatching properties of subsection 'gnu_testing_ba_1_MERGE_AND' +#error: \n[^\n]*ba-1-all-optional-1\.o: info: conflicting properties \(optional, .*\) live here +#error: \ninfo: \(required, .*\) VS \(optional, .*\) +#error: \n[^\n]*ba-1-mismatch-subsec-props-with-all-optional-1\.o: error: mismatching properties of subsection 'gnu_testing_ba_2_MERGE_AND' +#error: \n[^\n]*ba-1-all-optional-1\.o: info: conflicting properties \(.*, ULEB128\) live here +#error: \ninfo: \(.*, NTBS\) VS \(.*, ULEB128\)\Z diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.s b/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.s new file mode 100644 index 00000000000..04e4d61f673 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-mismatch-subsec-props-with-all-optional-1.s @@ -0,0 +1,2 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128 +.aeabi_subsection gnu_testing_ba_2_MERGE_AND, optional, ntbs diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-1-one-file.d b/ld/testsuite/ld-aarch64/build-attributes/ba-1-one-file.d new file mode 100644 index 00000000000..ea893b42fdf --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-one-file.d @@ -0,0 +1,42 @@ +# name: Build attributes: only one input object is copied to the output object +# source: ba-1-all-optional-1.s +# as: +# 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-aarch64/build-attributes/ba-1-two-files-all-optional-1more-1missing.d b/ld/testsuite/ld-aarch64/build-attributes/ba-1-two-files-all-optional-1more-1missing.d new file mode 100644 index 00000000000..5fe0a325704 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-1-two-files-all-optional-1more-1missing.d @@ -0,0 +1,52 @@ +# name: Build attributes: 2 files, all optional, 1 more, 1 missing +# source: ba-1-all-optional-1.s +# source: ba-1-all-optional-2.s +# as: +# 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-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-1.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-1.s new file mode 100644 index 00000000000..f6fc5a078d7 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-1.s @@ -0,0 +1,11 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 +.aeabi_attribute 2, 1 // Unknown tag +.aeabi_attribute 3, 1 // Unknown tag + +.aeabi_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" +.aeabi_attribute 2, "foo2" // Unknown tag +.aeabi_attribute 3, "foo3" // Unknown tag diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-2.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-2.s new file mode 100644 index 00000000000..2079a7a5362 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection-2.s @@ -0,0 +1,11 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 +.aeabi_attribute 2, 1 // Unknown tag +.aeabi_attribute 4, 1 // Unknown tag + +.aeabi_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" +.aeabi_attribute 2, "foo2" // Unknown tag +.aeabi_attribute 4, "foo4" // Unknown tag diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection.d b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection.d new file mode 100644 index 00000000000..55602588811 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-attr-known-subsection.d @@ -0,0 +1,25 @@ +# name: Build attributes: unknown attribute inside known subsection should be removed from the output. +# source: ba-2-mix-unknown-and-known-attr-known-subsection-1.s +# source: ba-2-mix-unknown-and-known-attr-known-subsection-2.s +# as: +# 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-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-1.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-1.s new file mode 100644 index 00000000000..268ebbdc081 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-1.s @@ -0,0 +1,19 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 0 + +.aeabi_subsection private_1, optional, uleb128 +.aeabi_attribute 0, 0 +.aeabi_attribute 1, 1 + +.aeabi_subsection private_2, optional, ntbs +.aeabi_attribute 0, "hello" +.aeabi_attribute 1, "world" + +.aeabi_subsection private_4, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "hello" +.aeabi_attribute 1, "world" diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-2.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-2.s new file mode 100644 index 00000000000..4e9fe48f508 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections-2.s @@ -0,0 +1,19 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection private_1, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection private_2, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" + +.aeabi_subsection private_3, optional, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 + +.aeabi_subsection gnu_testing_ba_2_MERGE_ADD, optional, ntbs +.aeabi_attribute 0, "foo" +.aeabi_attribute 1, "bar" diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections.d b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections.d new file mode 100644 index 00000000000..0f8114c4f33 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-mix-unknown-and-known-subsections.d @@ -0,0 +1,25 @@ +# name: Build attributes: unknown subsections are removed from the output. +# source: ba-2-mix-unknown-and-known-subsections-1.s +# source: ba-2-mix-unknown-and-known-subsections-2.s +# as: +# 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-aarch64/build-attributes/ba-2-required-subsec-A-1.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-A-1.s new file mode 100644 index 00000000000..dfa0acd7ff7 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-A-1.s @@ -0,0 +1,3 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 0 diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-A-2.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-A-2.s new file mode 100644 index 00000000000..dfa0acd7ff7 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-A-2.s @@ -0,0 +1,3 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 0 diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-B.s b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-B.s new file mode 100644 index 00000000000..c7004874870 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-B.s @@ -0,0 +1,3 @@ +.aeabi_subsection gnu_testing_ba_1_MERGE_AND, required, uleb128 +.aeabi_attribute 0, 1 +.aeabi_attribute 1, 1 diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-nok.d b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-nok.d new file mode 100644 index 00000000000..b7ab21096c4 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-nok.d @@ -0,0 +1,8 @@ +# name: Build attributes: combine non-matching required subsections +# source: ba-2-required-subsec-A-1.s +# source: ba-2-required-subsec-B.s +# source: ba-2-required-subsec-A-2.s +# as: +# ld: -shared +#error: \A[^\n]*ba-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]*ba-2-required-subsec-A-1\.o: info: conflicting value '0' lives here\Z diff --git a/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-ok.d b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-ok.d new file mode 100644 index 00000000000..84f78d8fee2 --- /dev/null +++ b/ld/testsuite/ld-aarch64/build-attributes/ba-2-required-subsec-ok.d @@ -0,0 +1,16 @@ +# name: Build attributes: combine matching required subsections +# source: ba-2-required-subsec-A-1.s +# source: ba-2-required-subsec-A-2.s +# as: +# 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 .* diff --git a/ld/testsuite/ld-aarch64/lib/aarch64-elf-lib.exp b/ld/testsuite/ld-aarch64/lib/aarch64-elf-lib.exp index 2f99548b905..344da5731f7 100644 --- a/ld/testsuite/ld-aarch64/lib/aarch64-elf-lib.exp +++ b/ld/testsuite/ld-aarch64/lib/aarch64-elf-lib.exp @@ -56,4 +56,4 @@ proc run_dump_test_lp64 { testname } { run_dump_test $testname \ [list [list as "-mabi=lp64 -I\$srcdir/\$subdir"] \ [list ld [concat "-m " [aarch64_choose_lp64_emul]]]] -} \ No newline at end of file +}