public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6196] IBM Z: Detect libc's float_t behavior on cross compiles
@ 2020-12-17 10:49 Marius Hillenbrand
  0 siblings, 0 replies; only message in thread
From: Marius Hillenbrand @ 2020-12-17 10:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:33f925094d02ce40872d494d384d4494a4313779

commit r11-6196-g33f925094d02ce40872d494d384d4494a4313779
Author: Marius Hillenbrand <mhillen@linux.ibm.com>
Date:   Fri Dec 4 10:38:58 2020 +0100

    IBM Z: Detect libc's float_t behavior on cross compiles
    
    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-16  Marius Hillenbrand  <mhillen@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.

Diff:
---
 gcc/configure        | 67 ++++++++++++++++++++++++++++++++++------------------
 gcc/configure.ac     | 52 ++++++++++++++++++++++++++++------------
 gcc/doc/install.texi |  7 +++---
 3 files changed, 85 insertions(+), 41 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index fe649b277a8..fbe92089640 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -31855,9 +31855,9 @@ $as_echo "$ld_pushpopstate_support" >&6; }
 # 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.
 # Check whether --enable-s390-excess-float-precision was given.
 if test "${enable_s390_excess_float_precision+set}" = set; then :
   enableval=$enable_s390_excess_float_precision;
@@ -31868,42 +31868,63 @@ fi
 
 case $target in
   s390*-linux*)
-  if test "$target" = "$host" -a "$host" = "$build" -a \
-      x"$enable_s390_excess_float_precision" = xauto; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for glibc clamping float_t to double" >&5
+  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"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <math.h>
+
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  enable_s390_excess_float_precision=autodetect
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+      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
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for glibc clamping float_t to double" >&5
 $as_echo_n "checking for glibc clamping float_t to double... " >&6; }
 if ${gcc_cv_float_t_clamped_to_double+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test "$cross_compiling" = yes; then :
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run test program while cross compiling
-See \`config.log' for more details" "$LINENO" 5; }
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 #define __FLT_EVAL_METHOD__ 0
 #include <math.h>
-int main() {
-  return !(sizeof(float_t) == sizeof(double));
-}
+int dummy[sizeof(float_t) == sizeof(double) ? 1 : -1];
+
 _ACEOF
-if ac_fn_cxx_try_run "$LINENO"; then :
+if ac_fn_cxx_try_compile "$LINENO"; then :
   gcc_cv_float_t_clamped_to_double=yes
 else
   gcc_cv_float_t_clamped_to_double=no
 fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_float_t_clamped_to_double" >&5
 $as_echo "$gcc_cv_float_t_clamped_to_double" >&6; }
-    if test x"$gcc_cv_float_t_clamped_to_double" = xyes; then
-      enable_s390_excess_float_precision=yes
+      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/configure.ac b/gcc/configure.ac
index 37557222607..89b9981e872 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -7375,9 +7375,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
@@ -7386,20 +7386,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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-17 10:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 10:49 [gcc r11-6196] IBM Z: Detect libc's float_t behavior on cross compiles Marius Hillenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).