]> git.eshelyaron.com Git - emacs.git/commitdiff
Work around GCC bug 58416 on 32-bit x86
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 19 Jul 2024 20:39:21 +0000 (13:39 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 22 Jul 2024 10:33:01 +0000 (12:33 +0200)
* configure.ac (C_SWITCH_MATCHINE): On 32-bit x86 with GCC 4+,
append -mfpmath=sse (if SSE2 is known to work) or -fno-tree-sra
(otherwise) to work around GCC bug 58416.
* etc/NEWS: Mention this.

(cherry picked from commit 9f4fc6608212191e1a9e07bf89f38ba9e4ea786c)

configure.ac
etc/NEWS

index 07ab9d3ff22427667da081512d1ae3f905d95323..7b32280639f348c58418749359264f6f4a75f778 100644 (file)
@@ -2333,6 +2333,51 @@ case $canonical in
     fi
   ;;
 esac
+
+AC_CACHE_CHECK([for flags to work around GCC bug 58416],
+  [emacs_cv_gcc_bug_58416_CFLAGS],
+  [emacs_cv_gcc_bug_58416_CFLAGS='none needed'
+   AS_CASE([$canonical],
+     [[i[3456]86-* | x86_64-*]],
+       [AS_IF([test "$GCC" = yes],
+         [old_CFLAGS=$CFLAGS
+          # If no flags are needed (e.g., not GCC 4+), don't use any.
+          # Otherwise, use -mfpmath=sse if already assuming SSE2.
+          # Otherwise, use -fno-tree-sra.
+          for emacs_cv_gcc_bug_58416_CFLAGS in \
+              'none needed' -mfpmath=sse -fno-tree-sra
+          do
+            AS_CASE([$emacs_cv_gcc_bug_58416_CFLAGS],
+              ['none needed'], [],
+              [-fno-tree-sra], [break],
+              [CFLAGS="$old_CFLAGS $emacs_cv_gcc_bug_58416_CFLAGS"])
+            AC_COMPILE_IFELSE(
+              [AC_LANG_DEFINES_PROVIDED
+               [/* Work around GCC bug with double in unions on x86,
+                   where the generated insns copy non-floating-point data
+                   via fldl/fstpl instruction pairs.  This can misbehave
+                   the data's bit pattern looks like a NaN.  See, e.g.:
+                      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58416#c10
+                      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71460
+                      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93271
+                      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659
+                   Problem observed with 'gcc -m32' with GCC 14.1.1
+                   20240607 (Red Hat 14.1.1-5) on x86-64.  */
+                #include <float.h>
+                #if \
+                    (4 <= __GNUC__ && !defined __clang__ \
+                     && (defined __i386__ || defined __x86_64__) \
+                     && ! (0 <= FLT_EVAL_METHOD && FLT_EVAL_METHOD <= 1))
+                # error "GCC bug 58416 is possibly present"
+                #endif
+              ]],
+              [break])
+          done
+          CFLAGS=$old_CFLAGS])])])
+AS_CASE([$emacs_cv_gcc_bug_58416_CFLAGS],
+  [-*],
+    [C_SWITCH_MACHINE="$C_SWITCH_MACHINE $emacs_cv_gcc_bug_58416_CFLAGS"])
+
 AC_SUBST([C_SWITCH_MACHINE])
 
 C_SWITCH_SYSTEM=
index 3ca90720390051d53317e2f7ab2feea0c307255d..e10514dd95394515c219a589e0ff693582c71816 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -24,6 +24,12 @@ applies, and please also update docstrings as needed.
 \f
 * Installation Changes in Emacs 31.1
 
+** When using GCC 4 or later to build Emacs on 32-bit x86 systems,
+'configure' now defaults to using the GCC options -mfpmath=sse (if the
+host system supports SSE2) or -fno-tree-sra (if not).  These GCC options
+work around GCC bug 58416, which can cause Emacs to behave incorrectly
+in rare cases.
+
 \f
 * Startup Changes in Emacs 31.1