[binutils-gdb] LD/testsuite: Factor out compilation of a dummy executable

Maciej W. Rozycki macro@sourceware.org
Tue Feb 17 10:43:49 GMT 2026


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

commit 46c365a4c59eeed3fe6c51dea7963ea555fd5b45
Author: Maciej W. Rozycki <macro@redhat.com>
Date:   Tue Feb 17 10:42:47 2026 +0000

    LD/testsuite: Factor out compilation of a dummy executable
    
    There is a dummy executable compiled for the purpose of determining
    whether a target compiler is available that can produce a runnable
    program.  This is now going to be also used to determine whether a
    program produced this way can be executed on the target, so take the
    relevant pieces from `check_compiler_available' procedure and factor
    them out to `make_dummy_target_executable' procedure leaving the
    executable produced in place and returning its name upon successful
    compilation.  This executable needs to be discarded by the caller once
    no longer needed.  No functional change overall.

Diff:
---
 ld/testsuite/lib/ld-lib.exp | 60 +++++++++++++++++++++++++++++----------------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 851cd89790e..819610bf33a 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1260,6 +1260,40 @@ proc check_sysroot_available { } {
     return $ld_sysroot_available_saved
 }
 
+# Return a path to a dummy target executable if we can build one
+# or an empty string otherwise.
+proc make_dummy_target_executable { } {
+    global CC_FOR_TARGET
+
+    if { [which $CC_FOR_TARGET] == 0 } {
+	return ""
+    }
+
+    set flags [get_board_flags]
+    set basename "tmpdir/compiler[pid]"
+    set src ${basename}.c
+    set output ${basename}.out
+    set f [open $src "w"]
+    puts $f "int main (void)"
+    puts $f "{"
+    puts $f "  return 0; "
+    puts $f "}"
+    close $f
+    if [is_remote host] {
+	set src [remote_download host $src]
+    }
+
+    set status [run_host_noleak "$CC_FOR_TARGET" "$flags $src -o $output"]
+    remote_file host delete $src
+    file delete $src
+    if { $status == 0 } {
+	remote_file host delete $output
+	return ""
+    }
+
+    return $output
+}
+
 # Return true if we can build a program with the compiler.
 # On some targets, CC might be defined, but libraries and startup
 # code might be missing or require special options that the ld test
@@ -1267,31 +1301,15 @@ proc check_sysroot_available { } {
 
 proc check_compiler_available { } {
     global compiler_available_saved
-    global CC_FOR_TARGET
 
     if {![info exists compiler_available_saved]} {
-	if { [which $CC_FOR_TARGET] == 0 } {
-	    set compiler_available_saved 0
-	    return 0
-	}
+	set compiler_available_saved 0
 
-	set flags [get_board_flags]
-	set basename "tmpdir/compiler[pid]"
-	set src ${basename}.c
-	set output ${basename}.out
-	set f [open $src "w"]
-	puts $f "int main (void)"
-	puts $f "{"
-	puts $f "  return 0; "
-	puts $f "}"
-	close $f
-	if [is_remote host] {
-	    set src [remote_download host $src]
+	set binfile [make_dummy_target_executable]
+	if { $binfile != "" } {
+	    remote_file host delete $binfile
+	    set compiler_available_saved 1
 	}
-	set compiler_available_saved [run_host_noleak "$CC_FOR_TARGET" "$flags $src -o $output"]
-	remote_file host delete $src
-	remote_file host delete $output
-	file delete $src
     }
     return $compiler_available_saved
 }


More information about the Binutils-cvs mailing list