From: Paul Eggert <eggert@cs.ucla.edu>
To: Po Lu <luangruo@yahoo.com>
Cc: 72145@debbugs.gnu.org
Subject: bug#72145: rare Emacs screwups on x86 due to GCC bug 58416
Date: Wed, 17 Jul 2024 14:56:49 -0700 [thread overview]
Message-ID: <6f37e80e-6226-428c-a89d-e6fda856e32d@cs.ucla.edu> (raw)
In-Reply-To: <555e555d-49d5-40b4-9c32-3d063032e0fd@cs.ucla.edu>
[-- Attachment #1: Type: text/plain, Size: 571 bytes --]
On 2024-07-16 22:01, Paul Eggert wrote:
> We could add an AC_RUN_IFELSE test for SSE2, though I doubt whether it
> would affect builds significantly in practice.
On second thought the rare Arch or Gentoo user could still be building
Emacs for the Pentium III, and for such a user a run-time test on the
build host would be a win. This can be done via the attached revised
patch. It uses AC_LINK_IFELSE to compile and run a single program,
instead of AC_RUN_IFELSE which (when combined with AC_COMPILE_IFELSE)
would mean compiling two test programs and running one.
[-- Attachment #2: 0001-Work-around-GCC-bug-58416-when-building-for-x86.patch --]
[-- Type: text/x-patch, Size: 3465 bytes --]
From 5b14689f2389df1a4573c36ef9b597c1bd7c6326 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
etc/NEWS | 10 ++++++++++
2 files changed, 63 insertions(+)
diff --git a/configure.ac b/configure.ac
index e2b6dc2fc4d..8d6ff2c4db3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2325,6 +2325,59 @@ AC_DEFUN
fi
;;
esac
+
+AC_CACHE_CHECK([for flags to work around GCC bug 58416],
+ [emacs_cv_SSE2_CFLAGS],
+ [emacs_cv_SSE2_CFLAGS='none needed'
+ AS_CASE([$canonical],
+ [[i[3456]86-* | x86_64-*]],
+ [AS_IF([test "$GCC" = yes],
+ [old_CFLAGS=$CFLAGS
+ for emacs_cv_SSE2_CFLAGS in \
+ 'none needed' '-mfpmath=sse' '-msse2 -mfpmath=sse' 'none work'
+ do
+ AS_CASE([$emacs_cv_SSE2_CFLAGS],
+ ['none work'], [break],
+ ['none needed'], [],
+ [CFLAGS="$old_CFLAGS $emacs_cv_SSE2_CFLAGS"])
+ AC_LINK_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 <float.h>
+ #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
+ int
+ main (int argc, char **argv)
+ {
+ return argc / 1.3;
+ }
+ ]],
+ [# When not cross-compiling, test that the SSE2 code runs.
+ # This lets native builds work even on ancient systems
+ # (e.g., Pentium III, last new model introduced 2003).
+ AS_CASE([$cross,_compiling,$emacs_cv_SSE2_CFLAGS],
+ [no,-*],
+ [./conftest$EXEEXT]) && break])
+ done
+ CFLAGS=$old_CFLAGS])])])
+AS_CASE([$emacs_cv_SSE2_CFLAGS],
+ [-*],
+ [C_SWITCH_MACHINE="$C_SWITCH_MACHINE $emacs_cv_SSE2_CFLAGS"])
+
AC_SUBST([C_SWITCH_MACHINE])
C_SWITCH_SYSTEM=
diff --git a/etc/NEWS b/etc/NEWS
index 60bde2abb40..8ab60503ba4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -24,6 +24,16 @@ applies, and please also update docstrings as needed.
\f
* 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, either build natively on a system that lacks SSE2, or
+pass 'emacs_cv_SSE2_CFLAGS=no' to 'configure'; although the resulting
+Emacs may generate incorrect results or dump core, any such misbehavior
+should be rare.
+
\f
* Startup Changes in Emacs 31.1
--
2.45.2
next prev parent reply other threads:[~2024-07-17 21:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 23:26 bug#72145: rare Emacs screwups on x86 due to GCC bug 58416 Paul Eggert
2024-07-17 0:57 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-17 5:01 ` Paul Eggert
2024-07-17 21:56 ` Paul Eggert [this message]
2024-07-18 2:39 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-18 5:14 ` Eli Zaretskii
2024-07-18 3:22 ` Richard Stallman
2024-07-18 12:38 ` Paul Eggert
2024-07-18 15:19 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-19 21:31 ` Paul Eggert
2024-08-22 6:44 ` Paul Eggert
2024-07-18 14:19 ` Andrea Corallo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6f37e80e-6226-428c-a89d-e6fda856e32d@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=72145@debbugs.gnu.org \
--cc=luangruo@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).