From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C6733858C60; Mon, 24 Jul 2023 12:29:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C6733858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690201765; bh=5gh0WmVauicwKkPCyEmFM888rfgD+i16PSAbU3+/jQo=; h=From:To:Subject:Date:From; b=oL9mYt1zwdkB0Z6eT4h2teYorEqzhEyIfDBD2D7Gq31ZXc1NT29kmJDKwHY5W6z4J obgRD41RcZlCvOWY34oBfq/iVqsIrwzt9WaAC/oVuNzarXf67d+HiNJIC5SvvCbPoV BFRiXk20tIxXJw6oxYH8FyktCe7V8mzHis8wuFCM= From: "lloyd at randombit dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/110792] New: GCC 13 x86_32 miscompilation of Whirlpool hash function Date: Mon, 24 Jul 2023 12:29:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lloyd at randombit dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110792 Bug ID: 110792 Summary: GCC 13 x86_32 miscompilation of Whirlpool hash function Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: lloyd at randombit dot net Target Milestone: --- Created attachment 55619 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55619&action=3Dedit Reproducing testcase Attached is a reproducing testcase for an apparent miscompilation bug in GC= C 13 when compiling for 32-bit x86. Upstream issue: https://github.com/randombit/botan/issues/3637 This code is the core loop of the Whirlpool hash function. In the attachment if `CAUSE_CODEGEN_BUG` is defined then a particular funct= ion is defined in an anonymous namespace. When that happens, GCC apparently generates invalid code $ g++ -O2 -std=3Dc++20 -m32 whirl.cpp -o whirl $ ./whirl 19FA61D75522A466 9B44E39C1D2E1726 C530232130D407F8 9AFEE0964997F7A7 3E83BE698B288FEB CF88E3E03C4F0757 EA8964E59B63D937 08B138CC42A66EB3 # above is the correct Whirlpool hash for the empty message $ g++ -DCAUSE_CODEGEN_BUG -O2 -std=3Dc++20 -m32 whirl.cpp -o whirl $ ./whirl zsh: segmentation fault ./whirl If compiled with Ubsan/Asan, the code is ok: $ g++ -DCAUSE_CODEGEN_BUG -fsanitize=3Daddress -fsanitize=3Dundefined -O2 -std=3Dc++20 -m32 whirl.cpp -o whirl $ ./whirl 19FA61D75522A466 9B44E39C1D2E1726 C530232130D407F8 9AFEE0964997F7A7 3E83BE698B288FEB CF88E3E03C4F0757 EA8964E59B63D937 08B138CC42A66EB3 My GCC is $ g++ -v Using built-in specs. COLLECT_GCC=3D/bin/g++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=3Dada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-boots= trap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr= /share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.1.1 20230429 (GCC) This is the compiler from Arch Linux which is AFAIK stock GCC. The original report related to the GCC 13 included in Alpine Edge.=