[binutils-gdb] LD/testsuite: Expand archive verification to `--whole-archive' feature
Maciej W. Rozycki
macro@sourceware.org
Mon Dec 15 19:11:36 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3ae3dae7371862e7b91db25b040400a672cd9c51
commit 3ae3dae7371862e7b91db25b040400a672cd9c51
Author: Maciej W. Rozycki <macro@redhat.com>
Date: Mon Dec 15 19:04:30 2025 +0000
LD/testsuite: Expand archive verification to `--whole-archive' feature
Expand archive verification to cover the `--whole-archive' feature,
adding link map and verbose output matching to verify the correct
archive members are added and the unwanted ones omitted.
Adjust the linker flags accordingly for XCOFF targets, by switching from
the `-bexpall' option to `-unix' (`-bexpfull' would do too, but has some
test coverage already, unlike `-unix', which is a superset of the former
option), so that additional symbols pulled with `--whole-archive' aren't
discarded by linker garbage collection.
This test expansion has revealed the lack of thin archive support in AR
for Alpha/VMS and XCOFF targets, despite apparent presence of relevant
code in the respective BFD backends. With `ar rcT' invocation a regular
archive is silently produced instead.
Rather than making the relevant tests overly permissive, XFAIL them for
the affected targets, referring PR binutils/33600.
Diff:
---
ld/testsuite/ld-archive/abc.vd | 22 ++++++++++
ld/testsuite/ld-archive/abtc.vd | 22 ++++++++++
ld/testsuite/ld-archive/abwc.vd | 24 ++++++++++
ld/testsuite/ld-archive/abwtc.vd | 24 ++++++++++
ld/testsuite/ld-archive/archive.exp | 88 +++++++++++++++++++++++++++++++++----
ld/testsuite/ld-archive/nx.nd | 4 ++
ld/testsuite/ld-archive/ny.nd | 4 ++
ld/testsuite/ld-archive/x.nd | 3 ++
ld/testsuite/ld-archive/y.nd | 3 ++
9 files changed, 185 insertions(+), 9 deletions(-)
diff --git a/ld/testsuite/ld-archive/abc.vd b/ld/testsuite/ld-archive/abc.vd
new file mode 100644
index 00000000000..ff3183b443a
--- /dev/null
+++ b/ld/testsuite/ld-archive/abc.vd
@@ -0,0 +1,22 @@
+#...
+using ..ternal linker script:.*
+==================================================
+#...
+==================================================
+.*: mode .*
+attempt to open tmpdir/abc\.o succeeded
+tmpdir/abc\.o
+attempt to open tmpdir/ab\.a succeeded
+tmpdir/ab\.a
+Archive member included to satisfy reference by file \(symbol\)
+
+tmpdir/ab\.a\(a\.o(:?bj)?\) +tmpdir/abc\.o \(aa\)
+\(tmpdir/ab\.a\)a\.o(:?bj)?
+tmpdir/ab\.a\(b\.o(:?bj)?\) +tmpdir/abc\.o \(bb\)
+\(tmpdir/ab\.a\)b\.o(:?bj)?
+!(:?\()?tmpdir/.*
+#...
+LOAD tmpdir/abc\.o
+LOAD tmpdir/ab\.a
+!LOAD .*
+#pass
diff --git a/ld/testsuite/ld-archive/abtc.vd b/ld/testsuite/ld-archive/abtc.vd
new file mode 100644
index 00000000000..b2fe394af13
--- /dev/null
+++ b/ld/testsuite/ld-archive/abtc.vd
@@ -0,0 +1,22 @@
+#...
+using ..ternal linker script:.*
+==================================================
+#...
+==================================================
+.*: mode .*
+attempt to open tmpdir/abc\.o succeeded
+tmpdir/abc\.o
+attempt to open tmpdir/abt\.a succeeded
+tmpdir/abt\.a
+Archive member included to satisfy reference by file \(symbol\)
+
+tmpdir/a\.o +tmpdir/abc\.o \(aa\)
+tmpdir/a\.o
+tmpdir/b\.o +tmpdir/abc\.o \(bb\)
+tmpdir/b\.o
+!(:?\()?tmpdir/.*
+#...
+LOAD tmpdir/abc\.o
+LOAD tmpdir/abt\.a
+!LOAD .*
+#pass
diff --git a/ld/testsuite/ld-archive/abwc.vd b/ld/testsuite/ld-archive/abwc.vd
new file mode 100644
index 00000000000..bc750a69002
--- /dev/null
+++ b/ld/testsuite/ld-archive/abwc.vd
@@ -0,0 +1,24 @@
+#...
+using ..ternal linker script:.*
+==================================================
+#...
+==================================================
+.*: mode .*
+attempt to open tmpdir/abc\.o succeeded
+tmpdir/abc\.o
+attempt to open tmpdir/ab\.a succeeded
+tmpdir/ab\.a
+Archive member included to satisfy reference by file \(symbol\)
+
+tmpdir/ab\.a\(a\.o(:?bj)?\) +\(--whole-archive\)
+\(tmpdir/ab\.a\)a\.o(:?bj)?
+tmpdir/ab\.a\(b\.o(:?bj)?\) +\(--whole-archive\)
+\(tmpdir/ab\.a\)b\.o(:?bj)?
+tmpdir/ab\.a\(x\.o(:?bj)?\) +\(--whole-archive\)
+\(tmpdir/ab\.a\)x\.o(:?bj)?
+!(:?\()?tmpdir/.*
+#...
+LOAD tmpdir/abc\.o
+LOAD tmpdir/ab\.a
+!LOAD .*
+#pass
diff --git a/ld/testsuite/ld-archive/abwtc.vd b/ld/testsuite/ld-archive/abwtc.vd
new file mode 100644
index 00000000000..5af70f043c2
--- /dev/null
+++ b/ld/testsuite/ld-archive/abwtc.vd
@@ -0,0 +1,24 @@
+#...
+using ..ternal linker script:.*
+==================================================
+#...
+==================================================
+.*: mode .*
+attempt to open tmpdir/abc\.o succeeded
+tmpdir/abc\.o
+attempt to open tmpdir/abt\.a succeeded
+tmpdir/abt\.a
+Archive member included to satisfy reference by file \(symbol\)
+
+tmpdir/a\.o +\(--whole-archive\)
+tmpdir/a\.o
+tmpdir/b\.o +\(--whole-archive\)
+tmpdir/b\.o
+tmpdir/x\.o +\(--whole-archive\)
+tmpdir/x\.o
+!(:?\()?tmpdir/.*
+#...
+LOAD tmpdir/abc\.o
+LOAD tmpdir/abt\.a
+!LOAD .*
+#pass
diff --git a/ld/testsuite/ld-archive/archive.exp b/ld/testsuite/ld-archive/archive.exp
index 035b271f775..490db9e7b34 100644
--- a/ld/testsuite/ld-archive/archive.exp
+++ b/ld/testsuite/ld-archive/archive.exp
@@ -35,7 +35,7 @@ set old_ldflags $LDFLAGS
# Prevent our otherwise unused data symbols from being GC'd on XCOFF targets.
if { [is_xcoff_format] } {
- append LDFLAGS " -bexpall"
+ append LDFLAGS " -unix"
}
# With Alpha/VMS NM doesn't handle executables and for MS-DOS there's no way
@@ -54,30 +54,70 @@ proc ld_archive_filter_tests { arg } {
}
}
+# Single archive tests.
run_ld_link_tests [list \
[list "Regular archive link" \
- "-e ff" "tmpdir/ab.a" \
+ "-e ff" "tmpdir/ab.a --verbose --print-map" \
"" {abc.s} \
- [ld_archive_filter_tests {{nm "" abc.nd}}] \
+ [ld_archive_filter_tests {{ld abc.vd} \
+ {nm "" abc.nd} \
+ {nm "" nx.nd}}] \
"abc" \
] \
]
setup_xfail "binutils/33484" "alpha*-*-linux*ecoff*" "alpha*-*-osf*"
setup_xfail "binutils/33485" "cris-*-*aout*" "i\[3-7\]86-*-bsd*" \
"i\[3-7\]86-*-msdos*" "ns32k-*-*" "pdp11-*-*"
+setup_xfail "binutils/33600" "alpha*-*-*vms*"
+if { [is_xcoff_format] } {
+ setup_xfail "binutils/33600" "*-*-*"
+}
run_ld_link_tests [list \
[list "Thin archive link" \
- "-e ff" "tmpdir/abt.a" \
+ "-e ff" "tmpdir/abt.a --verbose --print-map" \
"" {abc.s} \
- [ld_archive_filter_tests {{nm "" abc.nd}}] \
+ [ld_archive_filter_tests {{ld abtc.vd} \
+ {nm "" abc.nd} \
+ {nm "" nx.nd}}] \
"abtc" \
] \
]
+
+# Single whole archive tests.
+run_ld_link_tests [list \
+ [list "Regular whole archive link" \
+ "-e ff" "--whole-archive tmpdir/ab.a --verbose --print-map" \
+ "" {abc.s} \
+ [ld_archive_filter_tests {{ld abwc.vd} \
+ {nm "" abc.nd} \
+ {nm "" x.nd}}] \
+ "abwc" \
+ ] \
+]
+setup_xfail "binutils/33484" "alpha*-*-linux*ecoff*" "alpha*-*-osf*"
+setup_xfail "binutils/33600" "alpha*-*-*vms*"
+if { [is_xcoff_format] } {
+ setup_xfail "binutils/33600" "*-*-*"
+}
+run_ld_link_tests [list \
+ [list "Thin whole archive link" \
+ "-e ff" "--whole-archive tmpdir/abt.a --verbose --print-map" \
+ "" {abc.s} \
+ [ld_archive_filter_tests {{ld abwtc.vd} \
+ {nm "" abc.nd} \
+ {nm "" x.nd}}] \
+ "abwtc" \
+ ] \
+]
+
+# Dual archive tests.
run_ld_link_tests [list \
[list "Regular archive plus regular link" \
"-e ff" "tmpdir/ab.a tmpdir/cd.a" \
"" {abcde.s} \
- [ld_archive_filter_tests {{nm "" abcde.nd}}] \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" ny.nd}}] \
"abcde" \
] \
]
@@ -88,7 +128,9 @@ run_ld_link_tests [list \
[list "Regular archive plus thin link" \
"-e ff" "tmpdir/ab.a tmpdir/cdt.a" \
"" {abcde.s} \
- [ld_archive_filter_tests {{nm "" abcde.nd}}] \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" ny.nd}}] \
"abcdte" \
] \
]
@@ -99,7 +141,9 @@ run_ld_link_tests [list \
[list "Thin archive plus regular link" \
"-e ff" "tmpdir/abt.a tmpdir/cd.a" \
"" {abcde.s} \
- [ld_archive_filter_tests {{nm "" abcde.nd}}] \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" ny.nd}}] \
"abtcde" \
] \
]
@@ -110,11 +154,36 @@ run_ld_link_tests [list \
[list "Thin archive plus thin link" \
"-e ff" "tmpdir/abt.a tmpdir/cdt.a" \
"" {abcde.s} \
- [ld_archive_filter_tests {{nm "" abcde.nd}}] \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" ny.nd}}] \
"abtcdte" \
] \
]
+# Dual whole archive tests.
+run_ld_link_tests [list \
+ [list "Regular archive plus whole regular link" \
+ "-e ff" "tmpdir/ab.a --whole-archive tmpdir/cd.a" \
+ "" {abcde.s} \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" y.nd}}] \
+ "abcdwe" \
+ ] \
+]
+setup_xfail "binutils/33484" "alpha*-*-linux*ecoff*" "alpha*-*-osf*"
+run_ld_link_tests [list \
+ [list "Regular archive plus whole thin link" \
+ "-e ff" "tmpdir/ab.a --whole-archive tmpdir/cdt.a" \
+ "" {abcde.s} \
+ [ld_archive_filter_tests {{nm "" abcde.nd} \
+ {nm "" nx.nd} \
+ {nm "" y.nd}}] \
+ "abcdwte" \
+ ] \
+]
+
set LDFLAGS $old_ldflags
# Alpha/VMS archives always have an index and XCOFF targets currently
@@ -123,6 +192,7 @@ if { [istarget "alpha*-*-*vms*"] || [is_xcoff_format] } {
return
}
+# Single non-index archive tests.
run_ld_link_tests [list \
[list "Regular archive w/o index link" \
"-e ff" "tmpdir/abn.a" \
diff --git a/ld/testsuite/ld-archive/nx.nd b/ld/testsuite/ld-archive/nx.nd
new file mode 100644
index 00000000000..0a127c92710
--- /dev/null
+++ b/ld/testsuite/ld-archive/nx.nd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f]+ D xx
+#pass
diff --git a/ld/testsuite/ld-archive/ny.nd b/ld/testsuite/ld-archive/ny.nd
new file mode 100644
index 00000000000..7c8beeb71ef
--- /dev/null
+++ b/ld/testsuite/ld-archive/ny.nd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f]+ D yy
+#pass
diff --git a/ld/testsuite/ld-archive/x.nd b/ld/testsuite/ld-archive/x.nd
new file mode 100644
index 00000000000..f27929829a2
--- /dev/null
+++ b/ld/testsuite/ld-archive/x.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ D xx
+#pass
diff --git a/ld/testsuite/ld-archive/y.nd b/ld/testsuite/ld-archive/y.nd
new file mode 100644
index 00000000000..8b0fa39f331
--- /dev/null
+++ b/ld/testsuite/ld-archive/y.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ D yy
+#pass
More information about the Binutils-cvs
mailing list