This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] ld: Skip unsupported static executable tests


Skip static executable tests if static executable is unsupported.
Tested on Linux/x86 without libc.a.

OK for master?

H.J.
---
	PR ld/22732
	* testsuite/config/default.exp (STATIC_LDFLAGS): New.  Set to
	"-static" if target compiler supports it.
	* testsuite/ld-bootstrap/bootstrap.exp: Skip static executable
	tests if target compiler doesn't support it.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_tests): Likewise.
	(run_ld_link_exec_tests): Likewise.
	(run_cc_link_tests): Likewise.
---
 ld/testsuite/config/default.exp         | 37 +++++++++++++++++++++++++++++++++
 ld/testsuite/ld-bootstrap/bootstrap.exp |  8 +++++++
 ld/testsuite/ld-ifunc/ifunc.exp         | 25 +++++++++++++---------
 ld/testsuite/lib/ld-lib.exp             | 33 ++++++++++++++++++++++++-----
 4 files changed, 88 insertions(+), 15 deletions(-)

diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 29c020ffa4..1d9728afca 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -376,3 +376,40 @@ if { ![info exists GNU2_CFLAGS] } then {
 	set GNU2_CFLAGS ""
     }
 }
+
+# Set STATIC_LDFLAGS to "-static" if target compiler supports it.
+
+if { ![info exists STATIC_LDFLAGS] } then {
+    if { [which $CC] != 0 } {
+	# Check if gcc supports -static.
+	set flags ""
+	if [board_info [target_info name] exists cflags] {
+	    append flags " [board_info [target_info name] cflags]"
+	}
+	if [board_info [target_info name] exists ldflags] {
+	    append flags " [board_info [target_info name] ldflags]"
+	}
+
+	set basename "tmpdir/static[pid]"
+	set src ${basename}.c
+	set output ${basename}
+	set f [open $src "w"]
+	puts $f "int main (void) { return 0; }"
+	close $f
+	if [is_remote host] {
+	    set src [remote_download host $src]
+	}
+	set static_available [run_host_cmd_yesno "$CC" "-static $flags $src -o $output"]
+	remote_file host delete $src
+	remote_file host delete $output
+	file delete $src
+
+	if { $static_available == 1 } then {
+	    set STATIC_LDFLAGS "-static"
+	} else {
+	    set STATIC_LDFLAGS ""
+	}
+    } else {
+	set STATIC_LDFLAGS ""
+    }
+}
diff --git a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
index 32009d181f..f0bac3f7e9 100644
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp
@@ -29,6 +29,8 @@ if ![isnative] {
     return
 }
 
+global STATIC_LDFLAGS
+
 # Determine if plugin support is present.
 remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
 set tmp [file_contents "plugin-support"]
@@ -95,6 +97,12 @@ foreach flags $test_flags {
 	continue
     }
 
+    # If -static doesn't work, these tests will fail.
+    if { $flags == "--static" && [string match "" $STATIC_LDFLAGS] } then {
+	untested $testname
+	continue
+    }
+
     # Plugin support requires linking with a dynamic library which
     # means that these tests will fail.
     if { $flags == "--static" && $plugins == "yes" } then {
diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
index 628712389e..cb019d9d91 100644
--- a/ld/testsuite/ld-ifunc/ifunc.exp
+++ b/ld/testsuite/ld-ifunc/ifunc.exp
@@ -218,13 +218,15 @@ if ![ld_link $CC "tmpdir/local_prog" "$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath=.
     fail "Could not link a dynamic executable using local ifunc"
     set fails [expr $fails + 1]
 }
-if ![ld_link $CC "tmpdir/static_prog" "-static -Ltmpdir tmpdir/static_prog.o -lifunc"] {
-    fail "Could not link a static executable"
-    set fails [expr $fails + 1]
-}
-if ![ld_link $ld "tmpdir/static_nonifunc_prog" "-static tmpdir/empty.o"] {
-    fail "Could not link a non-ifunc using static executable"
-    set fails [expr $fails + 1]
+if ![string match "" $STATIC_LDFLAGS] {
+    if ![ld_link $CC "tmpdir/static_prog" "-static -Ltmpdir tmpdir/static_prog.o -lifunc"] {
+	fail "Could not link a static executable"
+	set fails [expr $fails + 1]
+    }
+    if ![ld_link $ld "tmpdir/static_nonifunc_prog" "-static tmpdir/empty.o"] {
+	fail "Could not link a non-ifunc using static executable"
+	set fails [expr $fails + 1]
+    }
 }
 if ![ld_link $CC "tmpdir/test-1" "-Wl,--no-as-needed,-rpath=./tmpdir tmpdir/test-1.o tmpdir/libshared_ifunc.so"] {
     fail "Could not link test-1"
@@ -265,7 +267,8 @@ if {! [check_osabi tmpdir/local_prog {UNIX - GNU}]} {
     fail "Local ifunc-using executable does not have an OS/ABI field of GNU"
     set fails [expr $fails + 1]
 }
-if {! [check_osabi tmpdir/static_prog {UNIX - GNU}]} {
+if { ![string match "" $STATIC_LDFLAGS] \
+     && ![check_osabi tmpdir/static_prog {UNIX - GNU}]} {
     fail "Static ifunc-using executable does not have an OS/ABI field of GNU"
     set fails [expr $fails + 1]
 }
@@ -290,7 +293,8 @@ if {[contains_ifunc_symbol tmpdir/local_prog] != 1} {
     fail "Local ifunc-using executable does not contain an IFUNC symbol"
     set fails [expr $fails + 1]
 }
-if {[contains_ifunc_symbol tmpdir/static_prog] != 1} {
+if { ![string match "" $STATIC_LDFLAGS] \
+     && [contains_ifunc_symbol tmpdir/static_prog] != 1} {
     fail "Static ifunc-using executable does not contain an IFUNC symbol"
     set fails [expr $fails + 1]
 }
@@ -328,7 +332,8 @@ if {[contains_irelative_reloc tmpdir/local_prog] != 1} {
     fail "Local ifunc-using executable does not contain R_*_IRELATIVE relocation"
     set fails [expr $fails + 1]
 }
-if {[contains_irelative_reloc tmpdir/static_prog] != 1} {
+if { ![string match "" $STATIC_LDFLAGS] \
+    && [contains_irelative_reloc tmpdir/static_prog] != 1} {
     fail "Static ifunc-using executable does not contain R_*_IRELATIVE relocation"
     set fails [expr $fails + 1]
 }
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 52baf0b04c..03dffc9323 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1183,6 +1183,7 @@ proc run_ld_link_tests { ldtests args } {
     global runtests
     global exec_output
     global ld_elf_shared_opt
+    global STATIC_LDFLAGS
 
     if { [is_elf_format] && [check_shared_lib_support] } {
 	set ld_extra_opt "$ld_elf_shared_opt"
@@ -1255,9 +1256,16 @@ proc run_ld_link_tests { ldtests args } {
 	    if { ![ar_simple_create $ar $ld_options $binfile "$objfiles $ld_after"] } {
 		set failed 1
 	    }
-	} elseif { ![ld_link $ld $binfile "$ld_extra_opt -L$srcdir/$subdir $ld_options $objfiles $ld_after"] } {
-	    set maybe_failed 1
-	    set ld_output "$exec_output"
+	} else {
+	    if { [string match "" $STATIC_LDFLAGS] \
+		 && [regexp -- ".* \[-\]+static .*" " $ld_extra_opt $ld_options $objfiles $ld_after "] } {
+		untested $testname
+		continue
+	    }
+	    if {![ld_link $ld $binfile "$ld_extra_opt -L$srcdir/$subdir $ld_options $objfiles $ld_after"] } {
+		set maybe_failed 1
+		set ld_output "$exec_output"
+	    }
 	}
 
 	if { !$failed } {
@@ -1400,6 +1408,7 @@ proc run_ld_link_exec_tests { ldtests args } {
     global errcnt
     global exec_output
     global board_cflags
+    global STATIC_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
@@ -1466,8 +1475,16 @@ proc run_ld_link_exec_tests { ldtests args } {
 	    # compile only
 	    pass $testname
 	    continue;
-	} elseif ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles"] {
-	    set failed 1
+	} else {
+	    if { [string match "" $STATIC_LDFLAGS] \
+		 && [regexp -- ".* \[-\]+static .*" " $board_cflags $ld_options $objfiles "] } {
+		untested $testname
+		continue
+	    }
+	    send_log "xxxxxx:$board_cflags -L$srcdir/$subdir $ld_options $objfiles\n"
+	    if ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles"] {
+		set failed 1
+	    }
 	}
 
 	# Check if exec_output is expected.
@@ -1547,6 +1564,7 @@ proc run_cc_link_tests { ldtests } {
     global ar
     global exec_output
     global board_cflags
+    global STATIC_LDFLAGS
 
     if [board_info [target_info name] exists cflags] {
         set board_cflags " [board_info [target_info name] cflags]"
@@ -1644,6 +1662,11 @@ proc run_cc_link_tests { ldtests } {
 		set failed 1
 	    }
 	} else {
+	    if { [string match "" $STATIC_LDFLAGS] \
+		 && [regexp -- ".* \[-\]+static .*" " $board_cflags $ldflags $objfiles "] } {
+		untested $testname
+		continue
+	    }
 	    ld_link $cc_cmd $binfile "$board_cflags -L$srcdir/$subdir $ldflags $objfiles"
 	    set ld_output "$exec_output"
 
-- 
2.14.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]