public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1
@ 2020-12-21 22:43 noloader at gmail dot com
  2020-12-22  3:27 ` [Bug c++/98416] " noloader at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: noloader at gmail dot com @ 2020-12-21 22:43 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98416] POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1
  2020-12-21 22:43 [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 noloader at gmail dot com
@ 2020-12-22  3:27 ` noloader at gmail dot com
  2020-12-22  4:09 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: noloader at gmail dot com @ 2020-12-22  3:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98416

--- Comment #1 from Jeffrey Walton <noloader at gmail dot com> ---
Created attachment 49831
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49831&action=edit
Disassembly of ppc_power9.o

Created with 'objdump --disassemble ppc_power9.o | c++filt >
ppc_power9.disass'.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98416] POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1
  2020-12-21 22:43 [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 noloader at gmail dot com
  2020-12-22  3:27 ` [Bug c++/98416] " noloader at gmail dot com
@ 2020-12-22  4:09 ` pinskia at gcc dot gnu.org
  2020-12-22  4:22 ` noloader at gmail dot com
  2020-12-22 20:42 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-22  4:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98416

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is invalid.
The instruction which is failing is:
  9c:   f0 00 02 d0     xxspltib vs0,0

Which is only valid in power9 and above.
You need to mark CPU_ProbePower9 not to be compiled with -mcpu=power9, by using
the target attribute.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98416] POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1
  2020-12-21 22:43 [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 noloader at gmail dot com
  2020-12-22  3:27 ` [Bug c++/98416] " noloader at gmail dot com
  2020-12-22  4:09 ` pinskia at gcc dot gnu.org
@ 2020-12-22  4:22 ` noloader at gmail dot com
  2020-12-22 20:42 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: noloader at gmail dot com @ 2020-12-22  4:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98416

--- Comment #3 from Jeffrey Walton <noloader at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> This is invalid.
> The instruction which is failing is:
>   9c:	f0 00 02 d0 	xxspltib vs0,0
>
> Which is only valid in power9 and above.
> You need to mark CPU_ProbePower9 not to be compiled with -mcpu=power9, by
> using the target attribute.

I have to use it because I am using the POWER9 ISA.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98416] POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1
  2020-12-21 22:43 [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 noloader at gmail dot com
                   ` (2 preceding siblings ...)
  2020-12-22  4:22 ` noloader at gmail dot com
@ 2020-12-22 20:42 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-22 20:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98416

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You need to use the target atrribute on CPU_ProbePower9 so GCC won't use power9
instructions on it.

Something like:
bool CPU_ProbePower9() __attribute__((target("cpu=power7")));
bool CPU_ProbePower9()
....

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-22 20:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 22:43 [Bug c++/98416] New: POWER8: SIGILL handler does not restart properly after signal using GCC 10.2.1 noloader at gmail dot com
2020-12-22  3:27 ` [Bug c++/98416] " noloader at gmail dot com
2020-12-22  4:09 ` pinskia at gcc dot gnu.org
2020-12-22  4:22 ` noloader at gmail dot com
2020-12-22 20:42 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).