The test cases in GCC's libraries run via DejaGNU's "[find_gcc]" –
unless the compiler has been explicitly provided. [1] That means that by
default everything runs with "<buildir>/gcc/xgcc" – at least for an
in-build-dir test run.
As that's the C driver, specific libraries such as "-lgfortran" or
"-lstdc++" have to added explicitly.
The problem with Fortran is: gfortran is built with libquadmath support
on several platforms – in that case, libgfortran depends on libquadmath.
But libquadmath support can be disabled or is not present at all on a
given platform. – With the "gfortran" driver, that's solved by using a
.spec file. But for xgcc …
For build-tree test runs, it's simple: As we check for the libquadmath
libraries explicitly, we know an .a or .so file exists and can add
"-lquadmath" – but for out-of-tree runs, we cannot. – Hence, I propose a
link test.
What do you think of the attached patch? (Lightly tested on x86_64.)
Background (see also PR):
On x86_64 the issue is not visible. As Joseph pointed out internally
(half a year ago): The ELF linker has a (mis)feature where it
automatically looks for libraries named in DT_NEEDED, emulating how the
dynamic linker searches and using directories specified in -rpath-link
if necessary. See ld/emultempl/elf32.em.
But on systems like PowerPC, the linker explicitly requires "-lquadmath"
in order that the linking succeeds.
Tobias
[1] By contrast, those tests under gcc/testsuite/ call functions like
"gfortran_init" of "./lib/gfortran.exp" instead to get the proper
driver (gfortran, g++ etc.). But this function assume that the compiler
is relative to current working directly (base_dir) at
$base_dir/../../<name>. That's the case for the tests under
gcc/testsuite but not for the testsuite in the libraries.
PS: In principle, the same issue occurs with offloading – and has to be
fixed there as well. However, nvptx and AMD GCN unsurprisingly don't
have a libquadmath; though, Intel MIC might …
libgomp/
* testsuite/libgomp.fortran/fortran.exp: Add -lquadmath if available.
* testsuite/libgomp.oacc-fortran/fortran.exp: Ditto.
diff --git a/libgomp/testsuite/libgomp.fortran/fortran.exp b/libgomp/testsuite/libgomp.fortran/fortran.exp
index d848ed4d47f..caffbfe0346 100644
--- a/libgomp/testsuite/libgomp.fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.fortran/fortran.exp
@@ -54,11 +54,15 @@ if { $lang_test_file_found } {
# Allow for spec subsitution.
lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/${quadmath_library_path}/"
set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}:${blddir}/${quadmath_library_path}"
+ append lang_link_flags " -lquadmath"
} else {
set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
}
} else {
set ld_library_path "$always_ld_library_path"
+ if { [check_no_compiler_messages has_libquadmath executable {int main() {return 0;}} "-lgfortran -lquadmath"] } then {
+ append lang_link_flags " -lquadmath"
+ }
}
append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
set_ld_library_path_env_vars
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
index af25a22a522..393518d53f9 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
+++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp
@@ -56,11 +56,15 @@ if { $lang_test_file_found } {
# Allow for spec subsitution.
lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/${quadmath_library_path}/"
set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}:${blddir}/${quadmath_library_path}"
+ append lang_link_flags " -lquadmath"
} else {
set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
}
} else {
set ld_library_path "$always_ld_library_path"
+ if { [check_no_compiler_messages has_libquadmath executable {int main() {return 0;}} "-lgfortran -lquadmath"] } then {
+ append lang_link_flags " -lquadmath"
+ }
}
append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
set_ld_library_path_env_vars