hppa64-hpux: Create dummy milli.a archives for binutils and ld testsuites

Message ID adF0VeRSg2A4M_B6@mx3210.local
State New
Headers
Series hppa64-hpux: Create dummy milli.a archives for binutils and ld testsuites |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

John David Anglin April 4, 2026, 8:28 p.m. UTC
  Okay?

I had to hack default_link_ld to append LDFLAGS and modify the
binutils default.exp to include procs from the ld testsuite.

Tested on hppa64-hp-hpux11.11 and x86_64-pc-linux-gnu.

Dave
---

hppa64-hpux: Create dummy milli.a archives for binutils and ld testsuites

The hppa64-*-hpux* target has to always link against the milli.a
archive to resolve various millicode routines.  However, this
breaks the binutils and ld testsuites on hosts without the milli.a
archive.

This change adds dummy milli.a archives on the hppa64-*-hpux* target
if ld cannot find the file.  The procedure is similar to that used
for alpha*-*-*vms* but we also need it for the binutils testsuite.

Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>

2026-04-04  John David Anglin  <danglin@gcc.gnu.org>

binutils/ChangeLog:

	* testsuite/config/default.exp: Load ld-lib.exp.
	(ld_assemble, ld_link): New procs.
	Create dummy missing libraries for hppa*64-*-hpux*
	target.  Append " -Ltmpdir" to LDFLAGS.

ld/ChangeLog:

	* testsuite/config/default.exp: Create dummy missing
	libraries for hppa*64-*-hpux* target.  Append
	" -Ltmpdir" to LDFLAGS.
	* testsuite/lib/ld-lib.exp (default_ld_link): Append
	LDFLAGS to flags variable.
  

Comments

Alan Modra April 6, 2026, 1:11 a.m. UTC | #1
On Sat, Apr 04, 2026 at 04:28:05PM -0400, John David Anglin wrote:
> diff --git a/binutils/testsuite/config/default.exp b/binutils/testsuite/config/default.exp
> index 25bd1e64222..9dca734a27c 100644
> --- a/binutils/testsuite/config/default.exp
> +++ b/binutils/testsuite/config/default.exp
> @@ -20,6 +20,7 @@
>  # This file was written by Rob Savoye. (rob@cygnus.com)
>  
>  load_lib utils-lib.exp
> +load_lib ../../../ld/testsuite/lib/ld-lib.exp

That's a bit horrible.  Can't you append -Ltmpdir unconditionally to
LDFLAGS when testing hppa64-hpux?  Or "-L/lib/pa20_64 -Ltmpdir" if
needed to put -Ltmpdir after the system library.
  
John David Anglin April 6, 2026, 1:58 a.m. UTC | #2
On 2026-04-05 9:11 p.m., Alan Modra wrote:
> On Sat, Apr 04, 2026 at 04:28:05PM -0400, John David Anglin wrote:
>> diff --git a/binutils/testsuite/config/default.exp b/binutils/testsuite/config/default.exp
>> index 25bd1e64222..9dca734a27c 100644
>> --- a/binutils/testsuite/config/default.exp
>> +++ b/binutils/testsuite/config/default.exp
>> @@ -20,6 +20,7 @@
>>  # This file was written by Rob Savoye. (rob@cygnus.com)
>>  
>>  load_lib utils-lib.exp
>> +load_lib ../../../ld/testsuite/lib/ld-lib.exp
> 
> That's a bit horrible.  Can't you append -Ltmpdir unconditionally to
> LDFLAGS when testing hppa64-hpux?  Or "-L/lib/pa20_64 -Ltmpdir" if
> needed to put -Ltmpdir after the system library.

Yes but we also need to build the dummy milli.a file.  The binutils testsuite
runs before the ld testsuite, so I don't think we can use the file generated
in the ld testsuite.

There's only a couple of tests in the binutils testsuite that fail because of
this issue.  Maybe I could xfail them if the host isn't hppa*64*-*-hpux* and the
target is hppa*64*-*-hpux*?

Dave
  
Alan Modra April 6, 2026, 4:18 a.m. UTC | #3
On Sun, Apr 05, 2026 at 09:58:40PM -0400, John David Anglin wrote:
> On 2026-04-05 9:11 p.m., Alan Modra wrote:
> > On Sat, Apr 04, 2026 at 04:28:05PM -0400, John David Anglin wrote:
> >> diff --git a/binutils/testsuite/config/default.exp b/binutils/testsuite/config/default.exp
> >> index 25bd1e64222..9dca734a27c 100644
> >> --- a/binutils/testsuite/config/default.exp
> >> +++ b/binutils/testsuite/config/default.exp
> >> @@ -20,6 +20,7 @@
> >>  # This file was written by Rob Savoye. (rob@cygnus.com)
> >>  
> >>  load_lib utils-lib.exp
> >> +load_lib ../../../ld/testsuite/lib/ld-lib.exp
> > 
> > That's a bit horrible.  Can't you append -Ltmpdir unconditionally to
> > LDFLAGS when testing hppa64-hpux?  Or "-L/lib/pa20_64 -Ltmpdir" if
> > needed to put -Ltmpdir after the system library.
> 
> Yes but we also need to build the dummy milli.a file.  The binutils testsuite
> runs before the ld testsuite, so I don't think we can use the file generated
> in the ld testsuite.

I don't see a problem building the dummy lib in binutils/tmpdir/ as
well.

> There's only a couple of tests in the binutils testsuite that fail because of
> this issue.  Maybe I could xfail them if the host isn't hppa*64*-*-hpux* and the
> target is hppa*64*-*-hpux*?
> 
> Dave
> -- 
> John David Anglin  dave.anglin@bell.net
  

Patch

diff --git a/binutils/testsuite/config/default.exp b/binutils/testsuite/config/default.exp
index 25bd1e64222..9dca734a27c 100644
--- a/binutils/testsuite/config/default.exp
+++ b/binutils/testsuite/config/default.exp
@@ -20,6 +20,7 @@ 
 # This file was written by Rob Savoye. (rob@cygnus.com)
 
 load_lib utils-lib.exp
+load_lib ../../../ld/testsuite/lib/ld-lib.exp
 
 if ![info exists AS] then {
     set AS [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
@@ -120,6 +121,41 @@  proc link_or_copy { src dst } {
     catch "exec cp -fpu ../$src tmpdir/gas/$dst" status
 }
 
+#
+# ld_assemble
+#       assemble a file
+#
+proc ld_assemble { as source object } {
+        default_ld_assemble $as "" $source $object
+}
+
+#
+# ld_link
+#       link a program using ld
+#
+proc ld_link { ld target objects } {
+        default_ld_link $ld $target $objects
+}
+
+if { [istarget hppa*64-*-hpux*] } {
+    set src tmpdir/empty.s
+    set f [open $src "w"]
+    close $f
+    if { [ld_assemble $AS $src tmpdir/empty.o]
+	 && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
+	 && [regsub -all {[^\n]*: cannot find ([^\n :]*)[^\n]*} $exec_output {tmpdir/\1 } missing_libs] } {
+	regsub -all {\$} $missing_libs {\\\$} missing_libs
+	for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
+	    set f [lindex $missing_libs $i]
+	    verbose -log "creating dummy $f"
+	    ar_simple_create $AR {} $f tmpdir/empty.o
+	}
+	append LDFLAGS " -Ltmpdir"
+	unset i missing_libs
+    }
+    unset f src
+}
+
 if {[file isfile gas/as-new[exe_ext]]} then {
     link_or_copy gas/as-new[exe_ext] as[exe_ext]
 } else {
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 2796f719f22..cc0576b3975 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -552,6 +552,26 @@  if { [istarget alpha*-*-*vms*] } {
     unset f src
 }
 
+# Provide dummy milli.a that hppa64-hpux-ld always loads
+if { [istarget hppa*64-*-hpux*] } {
+    set src tmpdir/empty.s
+    set f [open $src "w"]
+    close $f
+    if { [ld_assemble $as $src tmpdir/empty.o]
+	 && ![ld_link $LD tmpdir/empty tmpdir/empty.o]
+	 && [regsub -all {[^\n]*: cannot find ([^\n :]*)[^\n]*} $exec_output {tmpdir/\1 } missing_libs] } {
+	regsub -all {\$} $missing_libs {\\\$} missing_libs
+	for { set i 0 } { $i < [llength $missing_libs] } { incr i } {
+	    set f [lindex $missing_libs $i]
+	    verbose -log "creating dummy $f"
+	    ar_simple_create $ar {} $f tmpdir/empty.o
+	}
+	append LDFLAGS " -Ltmpdir"
+	unset i missing_libs
+    }
+    unset f src
+}
+
 set plug_opt ""
 if { [check_compiler_available] } {
     set plugin_names {
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index d37d33cd96c..d1b6f2e058f 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -231,11 +231,13 @@  proc get_board_flags {} {
 proc default_ld_link { ld target objects } {
     global host_triplet
     global exec_output
+    global LDFLAGS
 
     set flags ""
     if [is_endian_output_format $objects] then {
 	set flags [big_or_little_endian]
     }
+    set flags "$flags $LDFLAGS"
 
     # When using GCC as the linker driver, we need to specify board cflags when
     # linking because cflags may contain linker options.  For example when