From b6c6c0545607687e36fc47e5d5079aec4f58d591 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 15 Jul 2024 10:26:47 -0700 Subject: [PATCH] Work around GCC bug 58416 when building for x86 * configure.ac (C_SWITCH_MACHINE): Add -mfpmath=sse and perhaps -msse2 to work around GCC bug 58416. --- configure.ac | 43 +++++++++++++++++++++++++++++++++++++++++++ etc/NEWS | 9 +++++++++ 2 files changed, 52 insertions(+) diff --git a/configure.ac b/configure.ac index e2b6dc2fc4d..4e74d66c65f 100644 --- a/configure.ac +++ b/configure.ac @@ -2325,6 +2325,49 @@ AC_DEFUN 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 + for emacs_cv_gcc_bug_58416_CFLAGS in \ + 'none needed' '-mfpmath=sse' '-msse2 -mfpmath=sse' 'none work' + do + AS_CASE([$emacs_cv_gcc_bug_58416_CFLAGS], + ['none work'], [break], + ['none needed'], [], + [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 + 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 + #if \ + ((defined __GNUC__ && !defined __clang__) \ + && (defined __i386__ || defined __x86_64__) \ + && ! (defined FLT_EVAL_METHOD \ + && 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= diff --git a/etc/NEWS b/etc/NEWS index f10f9ae4d65..f3852750b9a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -24,6 +24,15 @@ applies, and please also update docstrings as needed. * Installation Changes in Emacs 31.1 +** When using GCC to build Emacs on 32-bit x86 systems, 'configure' now +defaults to specifying the GCC options -msse2 and -mfpmath=sse to work +around GCC bug 58416. As a result, the resulting Emacs executable now +requires support for SSE2, introduced by Intel in 2000 for the Pentium 4 +and by AMD in 2003 for the Opteron and Athlon 64. To build Emacs with +GCC for older x86 processors, pass 'emacs_cv_gcc_bug_58416_CFLAGS=no' to +'configure'; although the resulting Emacs may generate incorrect results +or dump core, any such misbehavior should be rare. + * Startup Changes in Emacs 31.1 -- 2.45.2