From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C2CB33857C7F; Mon, 21 Dec 2020 22:43:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2CB33857C7F From: "noloader at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 Date: Mon, 21 Dec 2020 22:43:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: noloader at gmail dot com 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2020 22:43:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98416 Bug ID: 98416 Summary: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: noloader at gmail dot com Target Milestone: --- Created attachment 49827 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49827&action=3Dedit preprocessed ppc_power9.cpp We are testing on GCC203 on the compile farm. GCC203 is a Debian POWER8 mac= hine with GCC 10.2.1. The following code executes 'darn r3, 0;', which is a POWER9 instruction. It causes a SIGILL, which is expected. However, when restarted from the setjump the program SIGILLs again. The second SIGILL is not expected. // https://github.com/weidai11/cryptopp/blob/master/ppc_power9.cpp#L42 // With the extra cruft removed... bool CPU_ProbePower9() { // longjmp and clobber warnings. Volatile is required. volatile int result =3D true; volatile SigHandler oldHandler =3D signal(SIGILL, SigIllHandler); if (oldHandler =3D=3D SIG_ERR) return false; volatile sigset_t oldMask; if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask)) { signal(SIGILL, oldHandler); return false; } if (setjmp(s_jmpSIGILL)) result =3D false; ///// <=3D SIGILL here! ///// else { // This is "darn r3, 0". We had to move away from the instrinsic=20 // because Clang and IBM XL C/C++ does not support the instrinsic. #if __BIG_ENDIAN__ __asm__ __volatile__ (".byte 0x7c, 0x60, 0x05, 0xe6 \n" : : : "r3"= ); #else __asm__ __volatile__ (".byte 0xe6, 0x05, 0x60, 0x7c \n" : : : "r3"= ); #endif result =3D true; } sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR); signal(SIGILL, oldHandler); return result; } Here's what it looks like under the debugger: (gdb) r v Starting program: /home/noloader/cryptopp/cryptest.exe v ... ### This one is expected. It is a feature probe. ### Program received signal SIGILL, Illegal instruction. CryptoPP::CPU_ProbePower9 () at ppc_power9.cpp:70 70 __asm__ __volatile__ (".byte 0x7c, 0x60, 0x05, 0xe6 \n" : = : : "r3"); (gdb) n CryptoPP::SigIllHandler () at ppc_power9.cpp:35 35 longjmp(s_jmpSIGILL, 1); (gdb) n ### This one is not expected. ### Program received signal SIGILL, Illegal instruction. CryptoPP::CPU_ProbePower9 () at ppc_power9.cpp:64 64 result =3D false; (gdb) n Program terminated with signal SIGILL, Illegal instruction. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > the complete command line that triggers the bug; > the compiler output (error messages, warnings, etc.); The compiler command invoked by make before and after are also shown. The program is clean with -Wall, UBsan, Asan, etc. g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mcpu=3Dpower8 -c ppc_power8.cpp g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mcpu=3Dpower9 -c ppc_power9.cpp g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -maltivec -c ppc_simd.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > the preprocessed file (*.i*) that triggers the bug, generated by adding -= save-temps to the complete compilation command, or, in the case of a bug re= port for the GNAT front end, a complete set of source files (see below). Attached. The command used was: g++ -save-temps -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mcpu=3Dpower9 -c ppc_power9.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > the exact version of GCC; > the system type; > the options given when GCC was configured/built; $ gcc --version gcc (Debian 10.2.1-1) 10.2.1 20201207 $ lsb_release -a Distributor ID: Debian Description: Debian GNU/Linux bullseye/sid Release: unstable Codename: sid $ gcc -v 2>&1 | fold -w 80 Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/powerpc64-linux-gnu/10/lto-wrapper Target: powerpc64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Debian 10.2.1-1' --with- bugurl=3Dfile:///usr/share/doc/gcc-10/README.Bugs --enable-languages=3Dc,ada,c++,go, d,fortran,objc,obj-c++ --prefix=3D/usr --with-gcc-major-version-only --program-suf fix=3D-10 --program-prefix=3Dpowerpc64-linux-gnu- --enable-shared --enable-linker-bu ild-id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads= =3Dposix - -libdir=3D/usr/lib --enable-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-l ibstdcxx-debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi= =3Dnew --en able-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --ena ble-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Dr elease --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-se= cureplt - -disable-softfloat --enable-targets=3Dpowerpc64-linux,powerpc-linux --enable-multi arch --disable-werror --with-long-double-128 --enable-multilib --enable-checking =3Drelease --build=3Dpowerpc64-linux-gnu --host=3Dpowerpc64-linux-gnu --target=3Dpowerpc 64-linux-gnu --with-build-config=3Dbootstrap-lto-lean --enable-link-mutex Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.1 20201207 (Debian 10.2.1-1)=