Hi, Currently, when the option --enable-s390-excess-float-precision is omitted, configure checks the libc's behavior only for native builds yet defaults to the new model for cross compiles. This patch extends the configure-time check to cross-compiles that have target headers available (e.g., in the second stage when manually bootstrapping a cross toolchain or in the build process for cross compilers in some distributions).
Built cross-compilers for target s390x on x86_64 and checked configure results and behavior wrt excess float precision (1) with target headers with old float_t behavior, (2) with new float_t behavior, and (3) without target headers. Bootstrapped and checked configure results on s390x. Tested configure and build on x86_64. Marius ----------->8------------>8------------>8------------>8------------ When cross-compiling GCC with target libc headers available and configure option --enable-s390-excess-float-precision has been omitted, identify whether they clamp float_t to double or respect __FLT_EVAL_METHOD__ via a compile test that coerces the build-system compiler to use the target headers. Then derive the setting from that. gcc/ChangeLog: 2020-12-14 Marius Hillenbrand <mhil...@linux.ibm.com> * configure.ac: Change --enable-s390-excess-float-precision default behavior for cross compiles with target headers. * configure: Regenerate. * doc/install.texi: Adjust documentation. --- gcc/configure.ac | 52 +++++++++++++++++++++++++++++++------------- gcc/doc/install.texi | 7 +++--- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/gcc/configure.ac b/gcc/configure.ac index 062f57fa12b..0964bab6fec 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -7372,9 +7372,9 @@ AC_MSG_RESULT($ld_pushpopstate_support) # gcc describes its behavior via the macro __FLT_EVAL_METHOD__ and glibc derives # float_t from that, this behavior can be configured with # --enable-s390-excess-float-precision. When given as enabled, that flag selects -# the old model. When omitted, native builds will derive the flag from the -# behavior of glibc. When glibc clamps float_t to double, gcc follows the old -# model. In any other case, it defaults to the new model. +# the old model. When omitted, native builds and cross compiles that have target +# libc headers will detect whether libc clamps float_t to double and in that +# case maintain the old model. Otherwise, they will default to the new model. AC_ARG_ENABLE(s390-excess-float-precision, [AS_HELP_STRING([--enable-s390-excess-float-precision], [on s390 targets, evaluate float with double precision @@ -7383,20 +7383,42 @@ AC_ARG_ENABLE(s390-excess-float-precision, case $target in s390*-linux*) - if test "$target" = "$host" -a "$host" = "$build" -a \ - x"$enable_s390_excess_float_precision" = xauto; then - AC_CACHE_CHECK([for glibc clamping float_t to double], - gcc_cv_float_t_clamped_to_double, - [AC_RUN_IFELSE([AC_LANG_SOURCE([ + if test x"$enable_s390_excess_float_precision" = xauto; then + # Can we autodetect the behavior of the target libc? + if test "$target" = "$host" -a "$host" = "$build"; then + enable_s390_excess_float_precision=autodetect + elif test "x$with_headers" != xno; then + # cross build. are target headers available? + # carefully coerce the build-system compiler to use target headers + saved_CXXFLAGS="$CXXFLAGS" + CROSS_TEST_CXXFLAGS="-nostdinc ${XGCC_FLAGS_FOR_TARGET//-B/-idirafter/}" + CXXFLAGS="$CROSS_TEST_CXXFLAGS" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include <math.h> +]])], [enable_s390_excess_float_precision=autodetect], []) + CXXFLAGS="$saved_CXXFLAGS" + fi + + if test x"$enable_s390_excess_float_precision" = xautodetect; then + saved_CXXFLAGS="$CXXFLAGS" + if ! test "$target" = "$host" -a "$host" = "$build"; then + CXXFLAGS="$CROSS_TEST_CXXFLAGS" + unset CROSS_TEST_CXXFLAGS + fi + AC_CACHE_CHECK([for glibc clamping float_t to double], + gcc_cv_float_t_clamped_to_double, [ + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #define __FLT_EVAL_METHOD__ 0 #include <math.h> -int main() { - return !(sizeof(float_t) == sizeof(double)); -}])], - [gcc_cv_float_t_clamped_to_double=yes], - [gcc_cv_float_t_clamped_to_double=no])]) - if test x"$gcc_cv_float_t_clamped_to_double" = xyes; then - enable_s390_excess_float_precision=yes +int dummy[sizeof(float_t) == sizeof(double) ? 1 : -1]; +]])], + [gcc_cv_float_t_clamped_to_double=yes], + [gcc_cv_float_t_clamped_to_double=no])]) + CXXFLAGS="$saved_CXXFLAGS" + enable_s390_excess_float_precision="$gcc_cv_float_t_clamped_to_double" + else + # no way to detect behavior of target libc, default to new model + enable_s390_excess_float_precision=no fi fi diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index a38ca3e3ce8..e30d2fc95bc 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -2277,9 +2277,10 @@ On s390(x) targets, enable treatment of float expressions with double precision when in standards-compliant mode (e.g., when @code{--std=c99} or @code{-fexcess-precision=standard} are given). -For a native build, the option's default is derived from glibc's behavior. When -glibc clamps float_t to double, gcc follows and enables the option. In all other -cases, it defaults to off. +For a native build and cross compiles that have target headers, the option's +default is derived from glibc's behavior. When glibc clamps float_t to double, +GCC follows and enables the option. For other cross compiles, the default is +disabled. @end table @subheading Cross-Compiler-Specific Options -- 2.26.2