[PATCH v3 04/18] LD/testsuite: Expand archive verification to `--whole-archive' feature
Maciej W. Rozycki
macro@orcam.me.uk
Thu Nov 20 10:56:11 GMT 2025
From: Maciej W. Rozycki <macro@redhat.com>
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.
This 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 an `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.
---
No change from v2,
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511060204090.25436@angie.orcam.me.uk/>.
New change in v2.
---
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(-)
binutils-ld-test-archive-whole.diff
Index: binutils-gdb/ld/testsuite/ld-archive/abc.vd
===================================================================
--- /dev/null
+++ binutils-gdb/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
Index: binutils-gdb/ld/testsuite/ld-archive/abtc.vd
===================================================================
--- /dev/null
+++ binutils-gdb/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
Index: binutils-gdb/ld/testsuite/ld-archive/abwc.vd
===================================================================
--- /dev/null
+++ binutils-gdb/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
Index: binutils-gdb/ld/testsuite/ld-archive/abwtc.vd
===================================================================
--- /dev/null
+++ binutils-gdb/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
Index: binutils-gdb/ld/testsuite/ld-archive/archive.exp
===================================================================
--- binutils-gdb.orig/ld/testsuite/ld-archive/archive.exp
+++ binutils-gdb/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 " -bexpfull"
}
# 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_
return
}
+# Single non-index archive tests.
run_ld_link_tests [list \
[list "Regular archive w/o index link" \
"-e ff" "tmpdir/abn.a" \
Index: binutils-gdb/ld/testsuite/ld-archive/nx.nd
===================================================================
--- /dev/null
+++ binutils-gdb/ld/testsuite/ld-archive/nx.nd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f]+ D xx
+#pass
Index: binutils-gdb/ld/testsuite/ld-archive/ny.nd
===================================================================
--- /dev/null
+++ binutils-gdb/ld/testsuite/ld-archive/ny.nd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f]+ D yy
+#pass
Index: binutils-gdb/ld/testsuite/ld-archive/x.nd
===================================================================
--- /dev/null
+++ binutils-gdb/ld/testsuite/ld-archive/x.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ D xx
+#pass
Index: binutils-gdb/ld/testsuite/ld-archive/y.nd
===================================================================
--- /dev/null
+++ binutils-gdb/ld/testsuite/ld-archive/y.nd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ D yy
+#pass
More information about the Binutils
mailing list