https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98416
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=49827&action=edit preprocessed ppc_power9.cpp We are testing on GCC203 on the compile farm. GCC203 is a Debian POWER8 machine 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 = true; volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler); if (oldHandler == 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 = false; ///// <= SIGILL here! ///// else { // This is "darn r3, 0". We had to move away from the instrinsic // 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 = 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 = false; (gdb) n Program terminated with signal SIGILL, Illegal instruction. ========================= > 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=power8 -c ppc_power8.cpp g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -mcpu=power9 -c ppc_power9.cpp g++ -DNDEBUG -g2 -O3 -fPIC -pthread -pipe -maltivec -c ppc_simd.cpp ========================= > 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 > report 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=power9 -c ppc_power9.cpp ========================= > 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=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/powerpc64-linux-gnu/10/lto-wrapper Target: powerpc64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-1' --with- bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go, d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suf fix=-10 --program-prefix=powerpc64-linux-gnu- --enable-shared --enable-linker-bu ild-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix - -libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-l ibstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --en able-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --ena ble-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=r elease --with-target-system-zlib=auto --enable-objc-gc=auto --enable-secureplt - -disable-softfloat --enable-targets=powerpc64-linux,powerpc-linux --enable-multi arch --disable-werror --with-long-double-128 --enable-multilib --enable-checking =release --build=powerpc64-linux-gnu --host=powerpc64-linux-gnu --target=powerpc 64-linux-gnu --with-build-config=bootstrap-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)