[binutils-gdb] LD/testsuite: Add tests for archive handling

Maciej W. Rozycki macro@sourceware.org
Tue Oct 21 20:05:38 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=435223a9ae7016040ca8562efed3062472df5ade

commit 435223a9ae7016040ca8562efed3062472df5ade
Author: Maciej W. Rozycki <macro@redhat.com>
Date:   Tue Oct 21 21:02:38 2025 +0100

    LD/testsuite: Add tests for archive handling
    
    Add basic verification for archives to work, regular and thin, in the
    link.  Refer to PR binutils/33484 and PR binutils/33485 for targets that
    fail these basic checks, where `ar' fails to add subsequent members to
    the archive or fails to add symbols from subsequent members to the map
    respectively, for thin archives.
    
    NB symbol names chosen such as to avoid a clash with Z80 CPU registers.

Diff:
---
 ld/testsuite/ld-archive/a.s         |   4 ++
 ld/testsuite/ld-archive/abc.nd      |   7 +++
 ld/testsuite/ld-archive/abc.s       |   7 +++
 ld/testsuite/ld-archive/abcde.nd    |  11 ++++
 ld/testsuite/ld-archive/abcde.s     |   7 +++
 ld/testsuite/ld-archive/archive.exp | 100 ++++++++++++++++++++++++++++++++++++
 ld/testsuite/ld-archive/b.s         |   4 ++
 ld/testsuite/ld-archive/c.s         |   4 ++
 ld/testsuite/ld-archive/d.s         |   4 ++
 9 files changed, 148 insertions(+)

diff --git a/ld/testsuite/ld-archive/a.s b/ld/testsuite/ld-archive/a.s
new file mode 100644
index 00000000000..e02109b057a
--- /dev/null
+++ b/ld/testsuite/ld-archive/a.s
@@ -0,0 +1,4 @@
+	.data
+	.globl	aa
+aa:
+	.dc.a	bb
diff --git a/ld/testsuite/ld-archive/abc.nd b/ld/testsuite/ld-archive/abc.nd
new file mode 100644
index 00000000000..cd6a0d8c583
--- /dev/null
+++ b/ld/testsuite/ld-archive/abc.nd
@@ -0,0 +1,7 @@
+#...
+[0-9a-f]+ D aa
+#...
+[0-9a-f]+ D bb
+#...
+[0-9a-f]+ D cc
+#pass
diff --git a/ld/testsuite/ld-archive/abc.s b/ld/testsuite/ld-archive/abc.s
new file mode 100644
index 00000000000..e198b970677
--- /dev/null
+++ b/ld/testsuite/ld-archive/abc.s
@@ -0,0 +1,7 @@
+	.text
+	.globl	ff
+ff:
+	.data
+	.globl	cc
+cc:
+	.dc.a	aa, bb
diff --git a/ld/testsuite/ld-archive/abcde.nd b/ld/testsuite/ld-archive/abcde.nd
new file mode 100644
index 00000000000..6e68de28ab7
--- /dev/null
+++ b/ld/testsuite/ld-archive/abcde.nd
@@ -0,0 +1,11 @@
+#...
+[0-9a-f]+ D aa
+#...
+[0-9a-f]+ D bb
+#...
+[0-9a-f]+ D cc
+#...
+[0-9a-f]+ D dd
+#...
+[0-9a-f]+ D ee
+#pass
diff --git a/ld/testsuite/ld-archive/abcde.s b/ld/testsuite/ld-archive/abcde.s
new file mode 100644
index 00000000000..cfbd1e70478
--- /dev/null
+++ b/ld/testsuite/ld-archive/abcde.s
@@ -0,0 +1,7 @@
+	.text
+	.globl	ff
+ff:
+	.data
+	.globl	ee
+ee:
+	.dc.a	aa, cc
diff --git a/ld/testsuite/ld-archive/archive.exp b/ld/testsuite/ld-archive/archive.exp
new file mode 100644
index 00000000000..0e942a4c4ae
--- /dev/null
+++ b/ld/testsuite/ld-archive/archive.exp
@@ -0,0 +1,100 @@
+# Test for archive handling.
+# 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; see the file COPYING3. If not,
+# see <http://www.gnu.org/licenses/>.
+#
+
+remote_file host delete \
+    "tmpdir/ab.a" "tmpdir/cd.a" "tmpdir/abt.a" "tmpdir/cdt.a"
+
+run_ld_link_tests {
+    {"First regular archive create"     ""   "" "" {a.s b.s} {} "ab.a"  }
+    {"Second regular archive create"    ""   "" "" {c.s d.s} {} "cd.a"  }
+    {"First thin archive create"        "T"  "" "" {a.s b.s} {} "abt.a" }
+    {"Second thin archive create"       "T"  "" "" {c.s d.s} {} "cdt.a" }
+}
+
+set old_ldflags $LDFLAGS
+
+# Prevent our otherwise unused data symbols from being GC'd on XCOFF targets.
+if { [is_xcoff_format] } {
+    append LDFLAGS " -bexpall"
+}
+
+# For MS-DOS there's no way to keep symbols, so just check for success.
+run_ld_link_tests [list \
+    [list "Regular archive link" \
+	"-e ff" "tmpdir/ab.a" \
+	"" {abc.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abc.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*" "pdp11-*-*"
+run_ld_link_tests [list \
+    [list "Thin archive link" \
+	"-e ff" "tmpdir/abt.a" \
+	"" {abc.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abc.nd}} }] \
+	"abtc" \
+    ] \
+]
+run_ld_link_tests [list \
+    [list "Regular archive plus regular link" \
+	"-e ff" "tmpdir/ab.a tmpdir/cd.a" \
+	"" {abcde.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abcde.nd}} }] \
+	"abcde" \
+    ] \
+]
+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*" "pdp11-*-*"
+run_ld_link_tests [list \
+    [list "Regular archive plus thin link" \
+	"-e ff" "tmpdir/ab.a tmpdir/cdt.a" \
+	"" {abcde.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abcde.nd}} }] \
+	"abcdte" \
+    ] \
+]
+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*" "pdp11-*-*"
+run_ld_link_tests [list \
+    [list "Thin archive plus regular link" \
+	"-e ff" "tmpdir/abt.a tmpdir/cd.a" \
+	"" {abcde.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abcde.nd}} }] \
+	"abtcde" \
+    ] \
+]
+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*" "pdp11-*-*"
+run_ld_link_tests [list \
+    [list "Thin archive plus thin link" \
+	"-e ff" "tmpdir/abt.a tmpdir/cdt.a" \
+	"" {abcde.s} \
+	[expr { [istarget "*-*-msdos"] ? {} : {{nm "" abcde.nd}} }] \
+	"abtcdte" \
+    ] \
+]
+
+set LDFLAGS $old_ldflags
diff --git a/ld/testsuite/ld-archive/b.s b/ld/testsuite/ld-archive/b.s
new file mode 100644
index 00000000000..05bc78a3b99
--- /dev/null
+++ b/ld/testsuite/ld-archive/b.s
@@ -0,0 +1,4 @@
+	.data
+	.globl	bb
+bb:
+	.dc.a	aa
diff --git a/ld/testsuite/ld-archive/c.s b/ld/testsuite/ld-archive/c.s
new file mode 100644
index 00000000000..405db60877a
--- /dev/null
+++ b/ld/testsuite/ld-archive/c.s
@@ -0,0 +1,4 @@
+	.data
+	.globl	cc
+cc:
+	.dc.a	dd
diff --git a/ld/testsuite/ld-archive/d.s b/ld/testsuite/ld-archive/d.s
new file mode 100644
index 00000000000..35111703aa4
--- /dev/null
+++ b/ld/testsuite/ld-archive/d.s
@@ -0,0 +1,4 @@
+	.data
+	.globl	dd
+dd:
+	.dc.a	cc


More information about the Binutils-cvs mailing list