Fix a problem with the libffi testsuite using a method to determine the compiler to use resulting in the tool being different from one the library has been built with, and causing a catastrophic failure from the inability to actually choose any compiler at all in a cross-compilation configuration.
Address this problem by passing the `--tool_exec' option to `runtest' via $(AM_RUNTESTFLAGS) with $(CC) as the argument, which will have all the required options set for the target compiler to build executables in the environment configured, removing failures like: FAIL: libffi.call/closure_fn0.c -W -Wall -Wno-psabi -O0 (test for excess errors) Excess errors: default_target_compile: No compiler to compile with UNRESOLVED: libffi.call/closure_fn0.c -W -Wall -Wno-psabi -O0 compilation failed to produce executable and bringing overall test results for the `riscv64-linux-gnu' target (here with the `x86_64-linux-gnu' host and RISC-V QEMU in the Linux user emulation mode as the target board) from: === libffi Summary === # of unexpected failures 708 # of unresolved testcases 708 # of unsupported tests 30 to: === libffi Summary === # of expected passes 1934 # of unsupported tests 28 For consistency with other top-level target libraries also respect the GCC_UNDER_TEST TCL variable, which can be set e.g. with an argument to `runtest' in a standalone run. Finally remove an unused TOOL_OPTIONS TCL variable instance. libffi/ * testsuite/Makefile.am (AM_RUNTESTFLAGS): Add `--tool_exec' option. * testsuite/Makefile.in: Regenerate. * testsuite/lib/libffi.exp (libffi-init): Handle GCC_UNDER_TEST and TOOL_EXECUTABLE. (libffi_target_compile): Use GCC_UNDER_TEST. --- Changes from v1: - Remove testsuite/libffi-test-support.exp.in and the associated changes. - Pass $(CC) via `--tool_exec' in $(AM_RUNTESTFLAGS). --- libffi/testsuite/Makefile.am | 2 +- libffi/testsuite/Makefile.in | 2 +- libffi/testsuite/lib/libffi.exp | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) gcc-test-libffi-runtestflags-tool-exec.diff Index: gcc/libffi/testsuite/Makefile.am =================================================================== --- gcc.orig/libffi/testsuite/Makefile.am +++ gcc/libffi/testsuite/Makefile.am @@ -11,7 +11,7 @@ RUNTEST = `if [ -f $(top_srcdir)/../deja echo $(top_srcdir)/../dejagnu/runtest ; \ else echo runtest; fi` -AM_RUNTESTFLAGS = +AM_RUNTESTFLAGS = --tool_exec "$(CC)" CLEANFILES = *.exe core* *.log *.sum Index: gcc/libffi/testsuite/Makefile.in =================================================================== --- gcc.orig/libffi/testsuite/Makefile.in +++ gcc/libffi/testsuite/Makefile.in @@ -134,7 +134,7 @@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LTLDFLAGS = @AM_LTLDFLAGS@ -AM_RUNTESTFLAGS = +AM_RUNTESTFLAGS = --tool_exec "$(CC)" AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ Index: gcc/libffi/testsuite/lib/libffi.exp =================================================================== --- gcc.orig/libffi/testsuite/lib/libffi.exp +++ gcc/libffi/testsuite/lib/libffi.exp @@ -99,7 +99,8 @@ proc libffi-init { args } { global blddirffi global objdir global blddircxx - global TOOL_OPTIONS + global TOOL_EXECUTABLE + global GCC_UNDER_TEST global tool global libffi_include global libffi_link_flags @@ -123,7 +124,15 @@ proc libffi-init { args } { set ld_library_path "." append ld_library_path ":${gccdir}" - set compiler "${gccdir}/xgcc" + if ![info exists GCC_UNDER_TEST] then { + if [info exists TOOL_EXECUTABLE] { + set GCC_UNDER_TEST $TOOL_EXECUTABLE + } else { + set GCC_UNDER_TEST "[find_gcc]" + } + } + + set compiler [lindex $GCC_UNDER_TEST 0] if { [is_remote host] == 0 && [which $compiler] != 0 } { foreach i "[exec $compiler --print-multi-lib]" { set mldir "" @@ -175,11 +184,14 @@ proc libffi_target_compile { source dest global srcdir global blddirffi global TOOL_OPTIONS + global GCC_UNDER_TEST global libffi_link_flags global libffi_include global target_triplet + lappend options "compiler=$GCC_UNDER_TEST" + if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } { lappend options "libs=${gluefile}" lappend options "ldflags=$wrap_flags"