From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#72145: rare Emacs screwups on x86 due to GCC bug 58416 Date: Thu, 18 Jul 2024 10:19:03 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25929"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 72145@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 18 16:20:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sURzb-0006Td-8D for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 18 Jul 2024 16:20:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sURzF-0008CK-Kp; Thu, 18 Jul 2024 10:20:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sURzD-0008Bj-10 for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2024 10:19:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sURzC-0004uz-Mr for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2024 10:19:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sURzG-0003sT-Bm for bug-gnu-emacs@gnu.org; Thu, 18 Jul 2024 10:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Jul 2024 14:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72145 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72145-submit@debbugs.gnu.org id=B72145.172131235614837 (code B ref 72145); Thu, 18 Jul 2024 14:20:02 +0000 Original-Received: (at 72145) by debbugs.gnu.org; 18 Jul 2024 14:19:16 +0000 Original-Received: from localhost ([127.0.0.1]:37795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sURyV-0003rF-SW for submit@debbugs.gnu.org; Thu, 18 Jul 2024 10:19:16 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sURyT-0003r0-Q3 for 72145@debbugs.gnu.org; Thu, 18 Jul 2024 10:19:14 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sURyJ-0004lE-Rn; Thu, 18 Jul 2024 10:19:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=mnNRcRR0Zj0R+VId073fHfoQN2jyK1UGvLzU61/rE4M=; b=gTsCTjQlbKH5TYPREaFh fY+EPYpIoDmcgzOoEaf5tNSSIZQlMexGZIHHoFFb+EjdptDMpC5PACmQoIAblza0F3iLNB2wIF32a sM/2s+DVlorhWtbYskTLEVcoZMTVFRbfkCzt5JQOLX0MOgL2vcFvdgc2LMLXZLtEIs+rjUGnZ6wWg 3sNFakGSopCeeaTy8iofcQpcITWcFTkM7YHANNjcWVfNlCcbg8jlcoMgvi+9HX96fk2yPlF8FUoNI WbXyK9YjcSHrLKOSWnyYZ3git2GnMCOzOzx5h0wPkmHGPhJUFB55/tKt821yweSeEstwBpd/08JBJ Ni5zVj5Oi0M1RQ==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1sURyJ-0002xk-KD; Thu, 18 Jul 2024 10:19:03 -0400 In-Reply-To: (Paul Eggert's message of "Tue, 16 Jul 2024 16:26:33 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288968 Archived-At: Paul Eggert writes: > While testing GNU Emacs built on Fedora 40 with gcc (GCC) 14.1.1 > 20240607 (Red Hat 14.1.1-5) with -m32 for x86 and configured > --with-wide-int, I discovered that Emacs misbehaved in a hard-to-debug > way due to GCC bug 58416. This bug causes GCC to generate wrong x86 > machine instructions when a C program accesses a union containing a > 'double'. > > The bug I observed is that if you have something like this: > > union u { double d; long long int i; } u; > > then GCC sometimes generates x86 instructions that copy u.i by using > fldl/fstpl instruction pairs to push the 64-bit quantity onto the 387 > floating point stack, and then pop the stack into another memory > location. Unfortunately the fldl/fstpl trick fails in the unusual case > when the bit pattern of u.i, when interpreted as a double, is a NaN, > as that can cause the fldl/fstpl pair to store a different NaN with a > different bit pattern, which means the destination integer disagrees > with u.i. > > The bug is obscure, since the bug's presence depends on the GCC > version, on the optimization options used, on the exact source code, > and on the exact integer value at runtime (the value is typically > copied correctly even when GCC has generated the incorrect machine > code, since most long long int values don't alias with NaNs). > > In short the bug appears to be rare. > > Here are some possible courses of action: > > * Do nothing and hope x86 users won't run into this rare bug. > > * Have the GCC folks fix the bug. However, given that the bug has been > reported for over a decade multiple times without a fix, it seems > that fixing it is too difficult and/or too low priority for this > aging platform. Also, even if the bug is fixed in future GCC the bug > will still be present with people using older GCC. > > * Build with Clang or some other compiler instead. We should be > encouraging GCC, though. > > * Rewrite Emacs to never use 'double' (or 'float' or 'long double') > inside a union. This could be painful and hardly seems worthwhile. > > * When using GCC to build Emacs on x86, compile with safer options > that make the bug impossible. The attached proposed patch does that, > by telling GCC not to use the 387 stack. (This patch fixed the Emacs > misbehavior in my experimental build.) The downside is that the > resulting Emacs executables need SSE2, introduced for the Pentium 4 > in 2000 . Nowadays few users > need to run Emacs on non-SSE2 x86, so this may be good enough. Also, > the proposed patch gives the builder an option to compile Emacs > without the safer options, for people who want to build for older > Intel-compatible platforms and who don't mind an occasional wrong > answer or crash. Mmmh nice one :) I asked GCC people if they have a suggestion on how to work around this bug . Thanks Andrea