From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72145: rare Emacs screwups on x86 due to GCC bug 58416 Date: Wed, 17 Jul 2024 08:57:58 +0800 Message-ID: <87ttgoygvd.fsf@yahoo.com> References: Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25764"; 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 Wed Jul 17 02:59:22 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 1sTt0s-0006Vc-AX for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 17 Jul 2024 02:59:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTt0Y-0001xc-Ld; Tue, 16 Jul 2024 20:59:02 -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 1sTt0V-0001xH-Sd for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 20:59:00 -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 1sTt0V-0003kF-KW for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 20:58:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sTt0Y-0004Ku-9q for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 20:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Jul 2024 00:59: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.172117790316624 (code B ref 72145); Wed, 17 Jul 2024 00:59:02 +0000 Original-Received: (at 72145) by debbugs.gnu.org; 17 Jul 2024 00:58:23 +0000 Original-Received: from localhost ([127.0.0.1]:34728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTszu-0004K3-G3 for submit@debbugs.gnu.org; Tue, 16 Jul 2024 20:58:22 -0400 Original-Received: from sonic314-21.consmr.mail.ne1.yahoo.com ([66.163.189.147]:42196) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTszr-0004Jn-A5 for 72145@debbugs.gnu.org; Tue, 16 Jul 2024 20:58:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1721177890; bh=altrj4o6o8JY485ucJTU/BMWLHtUNEVMdrI1IAsv20A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=cFj0t5xfdD7aCZQcpA7Qv3abbz7XFVPjLJzgOEO0zRuiSUfj7vyq43JwGIPAZm2JQpcvO22D+Qt4dTo6kj5087yTPG0yZ4IFiumDsBGqDtjTOX8ZnawYWRC/+lGvzA8HSbrqqFTN86Qw6wk/KwnGg7lRZ4RYmoY8tv832Ek63pbuoo5KmHaFeoQd69Qu/CzLZdbQ38ciL+AF+eX7mRdxcTiQNngUk/90clFuW/sOn9HKp6hGGdTZ31Nc9bMI/wYvN/7wWagdqALCEjn4qFwdhusjfFZkDm5kJTK17KQio6sKiyjcAxg2YfmQRPmQt+JSslW9OsqZLerxZry4VkqUVQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1721177890; bh=Rq5hStsnDfkBQ7bB6zTQTnUoP8pKFkau1JOEYfTyHPC=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=WHm2+2uHqo8qkhyXERPmuA7PJDVb3NVhj7Q1yMwUaVynmxrl+D81aDfSBJNkky00P8LNzasjRr+HRPIGuvXQw5/69S8O+za/Qs1q8Ipj5yn1Ho5+bdo8xsJp41fMiWBcnh2rIavduDwCQBKd/+VUhugDvRJ6fLP3KeJwCeXIUz41fq23k/q2Led7DXHW5SfiLywjgBkXthKMiqavL70VQClkgIdl+nixckQkVak+BaWqopN0X10N08FiUDGsfP9tdGj3PeWwEGwLIVbXc1CMKmMV4VBQzRu0ISJ83NhSZxEQUJPd2uDuzT6Z9PUPdtsSbbQu2aipiz7txNYN1rA5pQ== X-YMail-OSG: 0mlTYtwVM1mADG25fH_ku2KkgQLPl8LW7qJyYFDLDgLFmCzlZEMKLWWSDYfMdoH TAGRxEG5.jDjp5R6rtGl8w1nPVrDfCApFeLOxYsNAxysswkXLnlegB7TylWldEj92tnAgo2aEtMM 3KzNakWx5uYpMZkmRa06I7YrikYMFymvrPIBQk6u2Q2Wj6nnsqaFpQIN2FrvhSJS2mQ0n7sUF8Wf SJ5sldAbmwabOXGbHxLZws0vEkkHuOzn9EepQxM8Y6VkX78T79ItNPkn1KuB2DNprn832HKBgT5O Y79.H.fQaxxU6nVFCHYn820eHFy60GQ5SrKlMCGy01pQaAHzoATspP5B9fvT5Mbm8Iwgix5wONCJ A0wozZRia426G_Py05LTeJEGVI0AzsM1n5h_5E1c326SxESmUMRVwwRWqbzubJnfAkM_kFDi8dp0 TmcwbiwXsAq.3b1PWqALh.lYWZBsuGcqo7IejxjV2t3RO1O2qCqFMRYrMH7Oz7FkqIJS4wx0dhmA sVwLGHtu_sy4GIk_M5kaL5gyH452jREijL4E1v8vyUnqvk8pk7o.6nMDJTFkD.bDIGRj3kECevjd 6m_0DZBd_J9DxfDCgauvMZ8VaiwlCThRMdMklx80zQAIVkCHK981oiXwajEamg.G4lbGPRWyFc79 rkuWuOBzXskux2AHZH1_x3SoB7_NqGIj60RuMDVWdNnY17.nfy99aO.bnMoPSvIvQJj5DpN_t2rk ir0POfwvyjsJFWqXavMaFe0r7EX.pMvjVuephx3Xksj.Kjuk0424EBh2242uTLygsZfx3Ca6Rmql yo2ktt53.7_TTh23WsSGbT7NRQFsLexAkPZbbtjrpg X-Sonic-MF: X-Sonic-ID: 76e6b53a-97c5-4149-85d1-8175b9ec3626 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Wed, 17 Jul 2024 00:58:10 +0000 Original-Received: by hermes--production-sg3-85fdb5cfc8-shvwz (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID cd96a3e21bc5953919a3014de02b10e3; Wed, 17 Jul 2024 00:58:07 +0000 (UTC) In-Reply-To: (Paul Eggert's message of "Tue, 16 Jul 2024 16:26:33 -0700") X-Mailer: WebService/1.1.22501 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:288903 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. Wouldn't it be better if configure attempted to detect the presence of SSE2 on the host system?