From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#72145: rare Emacs screwups on x86 due to GCC bug 58416 Date: Tue, 16 Jul 2024 16:26:33 -0700 Organization: UCLA Computer Science Department Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------ACQdPPR23JeukjDZuA8EIuWr" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15682"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: 72145@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 17 01:27:34 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 1sTra1-0003qg-KT for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 17 Jul 2024 01:27:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTrZZ-0000yW-8a; Tue, 16 Jul 2024 19:27:05 -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 1sTrZU-0000y7-Bc for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 19:27: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 1sTrZU-0005n0-2u for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 19:27:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sTrZW-0007Z9-JM for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 19:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Jul 2024 23:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72145 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Emacs bug reports and feature requests Original-Received: via spool by submit@debbugs.gnu.org id=B.172117240729060 (code B ref -1); Tue, 16 Jul 2024 23:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Jul 2024 23:26:47 +0000 Original-Received: from localhost ([127.0.0.1]:34589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTrZG-0007Yd-L3 for submit@debbugs.gnu.org; Tue, 16 Jul 2024 19:26:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:32864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTrZD-0007YV-Lf for submit@debbugs.gnu.org; Tue, 16 Jul 2024 19:26:45 -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 1sTrZA-0000wL-I9 for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 19:26:40 -0400 Original-Received: from mail.cs.ucla.edu ([131.179.128.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTrZ7-0005YK-Sj for bug-gnu-emacs@gnu.org; Tue, 16 Jul 2024 19:26:40 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 8BB833C0140A4 for ; Tue, 16 Jul 2024 16:26:34 -0700 (PDT) Original-Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id Ubewo4EMCe2t for ; Tue, 16 Jul 2024 16:26:34 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 0052A3C00E415 for ; Tue, 16 Jul 2024 16:26:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 0052A3C00E415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1721172394; bh=O/7zlizyeCfQ0/3DE45/vBaM3P+ufZRqJcXbspM82sI=; h=Message-ID:Date:MIME-Version:To:From; b=RA1Y2BYlnRuzV+JYmRY5TDakxJlGnCkLaPDDMYTBAILsVlFnKddqhHelFIUZG7NWf IqrqSi7o1A9LegM9vnJgbHcGXCDUxe08XLHbEuoGnmJyLSAooSz1JslIjANDEIGq6+ SA8ZlRNR2LIXYuLwXCtXfv20svjOPZRh/bQwKTDr5bdxw93CY7VrSDUQV1ZZad7Ald Xse2l/M9axLmNJKpu/hxCL11LwOflvVKAAgWf9gqjKGDpaSIe7EMzGu3yHQaAMcoyv 5HX5yDQSI3TH1AH37Jp2LBDPcBVFJkczTgIJdhPz6PWNzhd5XCYsgNmPaBZ4MGN/qw GyCa8MsJx4E2A== X-Virus-Scanned: amavis at mail.cs.ucla.edu Original-Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id EJDzkBBsJDzt for ; Tue, 16 Jul 2024 16:26:33 -0700 (PDT) Original-Received: from [192.168.254.12] (unknown [47.154.17.165]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id DAAE83C0140A4 for ; Tue, 16 Jul 2024 16:26:33 -0700 (PDT) Content-Language: en-US Received-SPF: pass client-ip=131.179.128.66; envelope-from=eggert@cs.ucla.edu; helo=mail.cs.ucla.edu X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:288901 Archived-At: This is a multi-part message in MIME format. --------------ACQdPPR23JeukjDZuA8EIuWr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------ACQdPPR23JeukjDZuA8EIuWr Content-Type: text/x-patch; charset=UTF-8; name="0001-Work-around-GCC-bug-58416-when-building-for-x86.patch" Content-Disposition: attachment; filename*0="0001-Work-around-GCC-bug-58416-when-building-for-x86.patch" Content-Transfer-Encoding: base64 RnJvbSBiNmM2YzA1NDU2MDc2ODdlMzZmYzQ3ZTVkNTA3OWFlYzRmNThkNTkxIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBQYXVsIEVnZ2VydCA8ZWdnZXJ0QGNzLnVjbGEuZWR1 PgpEYXRlOiBNb24sIDE1IEp1bCAyMDI0IDEwOjI2OjQ3IC0wNzAwClN1YmplY3Q6IFtQQVRD SF0gV29yayBhcm91bmQgR0NDIGJ1ZyA1ODQxNiB3aGVuIGJ1aWxkaW5nIGZvciB4ODYKCiog Y29uZmlndXJlLmFjIChDX1NXSVRDSF9NQUNISU5FKTogQWRkIC1tZnBtYXRoPXNzZSBhbmQg cGVyaGFwcwotbXNzZTIgdG8gd29yayBhcm91bmQgR0NDIGJ1ZyA1ODQxNi4KLS0tCiBjb25m aWd1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