summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-01-19 08:27:41 -0800
committerH.J. Lu <hjl.tools@gmail.com>2018-01-19 11:59:37 -0800
commit0599e49b531038c5b059e0654aea162cd548d1dc (patch)
tree4806054bd3126a97ddb5e015256932cdc0f7553e
parenta0aad53764f45a634462288befe4c2eaecbf302d (diff)
downloadbinutils-gdb-users/hjl/pr22732.tar.gz
ld: Skip unsupported static executable testsusers/hjl/pr22732
Skip static executable tests if static executable is unsupported. Tested on Linux/x86 without libc.a. 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_exec_tests): Likewise. (run_cc_link_tests): Likewise.
-rw-r--r--ld/testsuite/config/default.exp37
-rw-r--r--ld/testsuite/ld-bootstrap/bootstrap.exp8
-rw-r--r--ld/testsuite/ld-ifunc/ifunc.exp25
-rw-r--r--ld/testsuite/lib/ld-lib.exp19
4 files changed, 77 insertions, 12 deletions
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 29c020ffa46..1d9728afcae 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 32009d181f7..f0bac3f7e9f 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 628712389e8..cb019d9d911 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 52baf0b04ce..14084a54ffa 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1400,6 +1400,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 +1467,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 +1556,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 +1654,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"