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.
+2018-01-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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.
+
2018-01-27 H.J. Lu <hongjiu.lu@intel.com>
PR ld/22751
set INT128_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 ""
+ }
+}
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"]
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 {
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"
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]
}
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]
}
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]
}
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
# compile only
pass $testname
continue;
- } elseif ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles $ld_after"] {
- set failed 1
+ } else {
+ if { [string match "" $STATIC_LDFLAGS] \
+ && [regexp -- ".* \[-\]+static .*" " $board_cflags $ld_options $objfiles $ld_after "] } {
+ untested $testname
+ continue
+ }
+ if ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles $ld_after"] {
+ set failed 1
+ }
}
# Check if exec_output is expected.
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]"
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"