ld: Skip unsupported static executable tests

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.
This commit is contained in:
H.J. Lu 2018-01-29 04:54:57 -08:00
parent eb77f6a462
commit 98d72909f8
5 changed files with 87 additions and 12 deletions

View file

@ -1,3 +1,14 @@
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

View file

@ -413,3 +413,40 @@ if { ![info exists INT128_CFLAGS] } then {
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 ""
}
}

View file

@ -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 {

View file

@ -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]
}

View file

@ -1401,6 +1401,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
@ -1468,8 +1469,15 @@ 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 $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.
@ -1549,6 +1557,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]"
@ -1646,6 +1655,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"