Bug 92095 - [8/9/10 regression] internal error with -O1 -mcpu=niagara2 -fPIE
Summary: [8/9/10 regression] internal error with -O1 -mcpu=niagara2 -fPIE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 8.4
Assignee: Eric Botcazou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-14 21:51 UTC by Sergei Trofimovich
Modified: 2021-01-21 16:15 UTC (History)
5 users (show)

See Also:
Host:
Target: sparc
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-10-27 00:00:00


Attachments
bug.c (167 bytes, text/x-csrc)
2019-10-14 21:53 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2019-10-14 21:51:57 UTC
Originally reported by Rolf Eike Beer as a build failure of python-3.6.9:
    https://bugs.gentoo.org/697708

Here is the minimal reproducer against ghc-master:

$ cat bug.c
    // sparc-unknown-linux-gnu-gcc -O1 -mcpu=niagara2 -fPIE -c bug.c -o bug.o
    typedef union {
      double a;
      int b[2];
    } c;
    double d(int e) {
      c f;
      (&f)->b[0] = 15728640;
      return e ? -(&f)->a : (&f)->a;
    }

$ gcc/xgcc -Bgcc -O1 -mcpu=niagara2 -fPIE -c bug.c -o bug.o
during RTL pass: reload
bug.c: In function 'd':
bug.c:10:1: internal compiler error: Segmentation fault
   10 | }
      | ^

$ gcc/xgcc -Bgcc -v
Reading specs from /home/slyfox/dev/git/gcc-sparc/gcc/specs
COLLECT_GCC=/home/slyfox/dev/git/gcc-sparc/gcc/xgcc
COLLECT_LTO_WRAPPER=/home/slyfox/dev/git/gcc-sparc/gcc/lto-wrapper
Target: sparc-unknown-linux-gnu
Configured with: ../gcc/configure --target=sparc-unknown-linux-gnu --with-sysroot=/usr/sparc-unknown-linux-gnu --enable-languages=c --disable-bootstrap --prefix=/home/slyfox/dev/git/gcc-sparc/../gcc-sparc-installed --disable-multilib --without-isl cross_compiling=yes
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.0 20191014 (experimental) (GCC)
Comment 1 Sergei Trofimovich 2019-10-14 21:53:38 UTC
Created attachment 47034 [details]
bug.c
Comment 2 Mikael Pettersson 2019-10-26 13:01:25 UTC
I can reproduce.  Fails with gcc -m32 -O1 -mcpu=niagara2 -fPIE and GCC 8/9/10.  Works with -m64.  Works with GCC 7.

> gcc/xgcc -Bgcc -m32 -O1 -mcpu=niagara2 -fPIE -S pr92095.c
during RTL pass: reload
pr92095.c: In function 'd':
pr92095.c:10:1: internal compiler error: Segmentation fault
   10 | }
      | ^
0x596eef crash_signal
        /mnt/scratch/gcc-10-20191020/gcc/toplev.c:326
0x247100 validize_mem(rtx_def*)
        /mnt/scratch/gcc-10-20191020/gcc/explow.c:521
0x86c897 sparc_expand_move(machine_mode, rtx_def**)
        /mnt/scratch/gcc-10-20191020/gcc/config/sparc/sparc.c:2315
0xa68dbf gen_movdf(rtx_def*, rtx_def*)
        /mnt/scratch/gcc-10-20191020/gcc/config/sparc/sparc.md:2469
0x26d60f insn_gen_fn::operator()(rtx_def*, rtx_def*) const
        /mnt/scratch/gcc-10-20191020/gcc/recog.h:318
0x26d60f emit_move_insn_1(rtx_def*, rtx_def*)
        /mnt/scratch/gcc-10-20191020/gcc/expr.c:3727
0x26daa3 emit_move_insn(rtx_def*, rtx_def*)
        /mnt/scratch/gcc-10-20191020/gcc/expr.c:3823
0x4076c7 lra_emit_move(rtx_def*, rtx_def*)
        /mnt/scratch/gcc-10-20191020/gcc/lra.c:499
0x419cef curr_insn_transform
        /mnt/scratch/gcc-10-20191020/gcc/lra-constraints.c:4397
0x41bdab lra_constraints(bool)
        /mnt/scratch/gcc-10-20191020/gcc/lra-constraints.c:4994
0x407c6f lra(_IO_FILE*)
        /mnt/scratch/gcc-10-20191020/gcc/lra.c:2432
0x3bf45f do_reload
        /mnt/scratch/gcc-10-20191020/gcc/ira.c:5511
0x3bf45f execute
        /mnt/scratch/gcc-10-20191020/gcc/ira.c:5697
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 3 Eric Botcazou 2019-10-27 16:15:31 UTC
I can reproduce.
Comment 4 Eric Botcazou 2019-10-27 16:21:23 UTC
Investigating.
Comment 5 Eric Botcazou 2019-11-08 12:31:18 UTC
Author: ebotcazou
Date: Fri Nov  8 12:30:47 2019
New Revision: 277966

URL: https://gcc.gnu.org/viewcvs?rev=277966&root=gcc&view=rev
Log:
	PR target/92095
	* config/sparc/sparc-protos.h (output_load_pcrel_sym): Declare.
	* config/sparc/sparc.c (sparc_cannot_force_const_mem): Revert latest
 	change.
	(got_helper_needed): New static variable.
	(output_load_pcrel_sym): New function.
	(get_pc_thunk_name): Remove after inlining...
	(load_got_register): ...here.  Rework the initialization of the GOT
	register and of the GOT helper.
	(save_local_or_in_reg_p): Test the REGNO of the GOT register.
	(sparc_file_end): Test got_helper_needed to decide whether the GOT
	helper must be emitted.  Use output_asm_insn instead of fprintf.
	(sparc_init_pic_reg): In PIC mode, always initialize the PIC register
	if optimization is enabled.
	* config/sparc/sparc.md (load_pcrel_sym<P:mode>): Emit the assembly
	by calling output_load_pcrel_sym.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sparc/sparc-protos.h
    trunk/gcc/config/sparc/sparc.c
    trunk/gcc/config/sparc/sparc.md
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/sparc/overflow-3.c
    trunk/gcc/testsuite/gcc.target/sparc/overflow-4.c
    trunk/gcc/testsuite/gcc.target/sparc/overflow-5.c
Comment 6 Eric Botcazou 2019-11-08 12:34:19 UTC
Author: ebotcazou
Date: Fri Nov  8 12:33:48 2019
New Revision: 277967

URL: https://gcc.gnu.org/viewcvs?rev=277967&root=gcc&view=rev
Log:
	PR target/92095
	* config/sparc/sparc-protos.h (output_load_pcrel_sym): Declare.
	* config/sparc/sparc.c (sparc_cannot_force_const_mem): Revert latest
 	change.
	(got_helper_needed): New static variable.
	(output_load_pcrel_sym): New function.
	(get_pc_thunk_name): Remove after inlining...
	(load_got_register): ...here.  Rework the initialization of the GOT
	register and of the GOT helper.
	(save_local_or_in_reg_p): Test the REGNO of the GOT register.
	(sparc_file_end): Test got_helper_needed to decide whether the GOT
	helper must be emitted.  Use output_asm_insn instead of fprintf.
	(sparc_init_pic_reg): In PIC mode, always initialize the PIC register
	if optimization is enabled.
	* config/sparc/sparc.md (load_pcrel_sym<P:mode>): Emit the assembly
	by calling output_load_pcrel_sym.

Added:
    branches/gcc-9-branch/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
      - copied unchanged from r277966, trunk/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/config/sparc/sparc-protos.h
    branches/gcc-9-branch/gcc/config/sparc/sparc.c
    branches/gcc-9-branch/gcc/config/sparc/sparc.md
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
    branches/gcc-9-branch/gcc/testsuite/gcc.target/sparc/overflow-3.c
    branches/gcc-9-branch/gcc/testsuite/gcc.target/sparc/overflow-4.c
    branches/gcc-9-branch/gcc/testsuite/gcc.target/sparc/overflow-5.c
Comment 7 Eric Botcazou 2019-11-08 12:38:35 UTC
Author: ebotcazou
Date: Fri Nov  8 12:38:03 2019
New Revision: 277968

URL: https://gcc.gnu.org/viewcvs?rev=277968&root=gcc&view=rev
Log:
	PR target/92095
	* config/sparc/sparc-protos.h (output_load_pcrel_sym): Declare.
	* config/sparc/sparc.c (sparc_cannot_force_const_mem): Revert latest
 	change.
	(got_helper_needed): New static variable.
	(output_load_pcrel_sym): New function.
	(get_pc_thunk_name): Remove after inlining...
	(load_got_register): ...here.  Rework the initialization of the GOT
	register and of the GOT helper.
	(save_local_or_in_reg_p): Test the REGNO of the GOT register.
	(sparc_file_end): Test got_helper_needed to decide whether the GOT
	helper must be emitted.  Use output_asm_insn instead of fprintf.
	(sparc_init_pic_reg): In PIC mode, always initialize the PIC register
	if optimization is enabled.
	* config/sparc/sparc.md (load_pcrel_sym<P:mode>): Emit the assembly
	by calling output_load_pcrel_sym.

Added:
    branches/gcc-8-branch/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
      - copied unchanged from r277967, trunk/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/config/sparc/sparc-protos.h
    branches/gcc-8-branch/gcc/config/sparc/sparc.c
    branches/gcc-8-branch/gcc/config/sparc/sparc.md
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
    branches/gcc-8-branch/gcc/testsuite/gcc.target/sparc/overflow-3.c
    branches/gcc-8-branch/gcc/testsuite/gcc.target/sparc/overflow-4.c
    branches/gcc-8-branch/gcc/testsuite/gcc.target/sparc/overflow-5.c
Comment 8 Eric Botcazou 2019-11-08 12:48:36 UTC
This should compile again.
Comment 9 Romain Naour 2021-01-21 11:33:38 UTC
Hello,

This patch produce a regression on sparcv8 SS10 platform.

In Buildroot we have a defconfig qemu_sparc_ss10_defconfig that was working (booting) with gcc 7.4, 8.3 and 9.2. But it doesn't boot anymore with gcc 8.4, 9.3 and 10.2.

I reverted this patch to be able to boot the system.

See:
http://patchwork.ozlabs.org/project/buildroot/patch/20210120230234.2086807-1-romain.naour@gmail.com/

Best regards,
Romain
Comment 10 Eric Botcazou 2021-01-21 16:15:46 UTC
> This patch produce a regression on sparcv8 SS10 platform.
> 
> In Buildroot we have a defconfig qemu_sparc_ss10_defconfig that was working
> (booting) with gcc 7.4, 8.3 and 9.2. But it doesn't boot anymore with gcc
> 8.4, 9.3 and 10.2.
> 
> I reverted this patch to be able to boot the system.
> 
> See:
> http://patchwork.ozlabs.org/project/buildroot/patch/20210120230234.2086807-1-
> romain.naour@gmail.com/

Unfortunately there is not enough information to investigate here.

Please consider creating a new PR as explained on https://gcc.gnu.org/bugs