NetBSD Problem Report #51967

From www@NetBSD.org  Mon Feb 13 21:57:31 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A52C77A1AF
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 13 Feb 2017 21:57:31 +0000 (UTC)
Message-Id: <20170213215730.328137A28E@mollari.NetBSD.org>
Date: Mon, 13 Feb 2017 21:57:30 +0000 (UTC)
From: rokuyama@rk.phys.keio.ac.jp
Reply-To: rokuyama@rk.phys.keio.ac.jp
To: gnats-bugs@NetBSD.org
Subject: GCC 5.4 aborts on vax due to SIGILL for cc1
X-Send-Pr-Version: www-1.0

>Number:         51967
>Category:       port-vax
>Synopsis:       GCC 5.4 aborts on vax due to SIGILL for cc1
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    port-vax-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 13 22:00:00 +0000 2017
>Closed-Date:    Sun Oct 04 10:01:45 +0000 2020
>Last-Modified:  Sun Oct 04 10:01:45 +0000 2020
>Originator:     Rin Okuyama
>Release:        7.99.59
>Organization:
Faculty of Science and Technology, Keio University
>Environment:
NetBSD vax 7.99.59 NetBSD 7.99.59 (GENERIC) #0: Wed Jan 18 00:10:36 JST 2017  rin@latipes:/var/build/src/sys/arch/vax/compile/obj.vax-vax/GENERIC vax
>Description:
/usr/libexec/cc1 aborts on vax (on simh) via SIGILL when compiling
source codes like this with optimization -O1 or higher:

  % cat sample.c
  #ifndef USE_CHAR
  struct s {
          int x;
          int pad[10];
  } s1, s2;
  #else
  struct s {
          char x;
          char pad[36];
  } s1, s2;
  #endif

  int main() {
          s1.x = 0;
          s2 = s1;

          return 0;
  }

Then, "cc -O1 sample.c" and "cc -O1 -DUSE_CHAR sample.c" abort:

  % cc -v -O1 sample.c
  Using built-in specs.
  COLLECT_GCC=cc
  COLLECT_LTO_WRAPPER=/usr/libexec/lto-wrapper
  Target: vax--netbsdelf
  Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure --target=vax--netbsdelf --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb1 20160606' --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads --with-diagnostics-color=auto-if-env --with-mpc-lib=/var/obj/mknative/vax/usr/src/external/lgpl3/mpc/lib/libmpc --with-mpfr-lib=/var/obj/mknative/vax/usr/src/external/lgpl3/mpfr/lib/libmpfr --with-gmp-lib=/var/obj/mknative/vax/usr/src/external/lgpl3/gmp/lib/libgmp --with-mpc-include=/usr/src/external/lgpl3/mpc/dist/src --with-mpfr-include=/usr/src/external/lgpl3/mpfr/dist/src --with-gmp-include=/usr/src/external/lgpl3/gmp/lib/libgmp/arch/vax --disable-multilib --disable-symvers --disable-libstdcxx-pch --build=x86_64-unknown-netbsd7.0 --host=vax--netbsdelf --with-sysroot=/var/obj/mknative/vax/usr/src/destdir.vax
  Thread model: posix
  gcc version 5.4.0 (nb1 20160606)
  COLLECT_GCC_OPTIONS='-v' '-O1'
   /usr/libexec/cc1 -quiet -v sample.c -fPIC -quiet -dumpbase sample.c -auxbase sample -O1 -version -o /var/tmp//ccMNFtlG.s
  GNU C11 (nb1 20160606) version 5.4.0 (vax--netbsdelf)
          compiled by GNU C version 5.4.0, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.1
  GGC heuristics: --param ggc-min-expand=34 --param ggc-min-heapsize=8184
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/include/gcc-5
   /usr/include
  End of search list.
  GNU C11 (nb1 20160606) version 5.4.0 (vax--netbsdelf)
          compiled by GNU C version 5.4.0, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.1
  GGC heuristics: --param ggc-min-expand=34 --param ggc-min-heapsize=8184
  Compiler executable checksum: 00fef665a46b5ab23cff11102ac9e396
  sample.c: In function 'main':
  sample.c:19:1: internal compiler error: Illegal instruction
   }
   ^
  no stack trace because unwind library not available
  Please submit a full bug report,
  with preprocessed source if appropriate.
  See <http://www.NetBSD.org/support/send-pr.html> for instructions.

Note that if the size of pad is reduced, this failure does not occur.
According to GDB, SIGILL takes place in check_mem_read_use():

  % gdb /usr/libexec/cc1
  GNU gdb (GDB) 7.12
  ...
  Reading symbols from /usr/libexec/cc1...(no debugging symbols found)...done.
  (gdb) r -quiet -v sample.c -fPIC -quiet -dumpbase sample.c -auxbase sample -O1 -version -o /var/tmp//ccMNFtlG.s
  Starting program: /usr/libexec/cc1 -quiet -v sample.c -fPIC -quiet -dumpbase sample.c -auxbase sample -O1 -version -o /var/tmp//ccMNFtlG.s
  GNU C11 (nb1 20160606) version 5.4.0 (vax--netbsdelf)
  ...
  Compiler executable checksum: 00fef665a46b5ab23cff11102ac9e396

  Program received signal SIGILL, Illegal instruction.
  0x00238087 in check_mem_read_use(rtx_def**, void*) (2132440588, 2134585384)
  (gdb) bt
  #0  0x00238087 in check_mem_read_use(rtx_def**, void*) (2132440588, 2134585384)
  #1  0x001c507c in note_uses(rtx_def**, void (*)(rtx_def**, void*), void*)
      (2131802444, 2326056, 2134585384)
  #2  0x001c5032 in note_uses(rtx_def**, void (*)(rtx_def**, void*), void*)
      (2131822400, 2326056, 2134585384)
  #3  0x00239ce3 in (anonymous namespace)::pass_rtl_dse2::execute(function*)
      (2134141248, 2131783780)
  #4  0x00205512 in execute_one_pass(opt_pass*) (2134141248)
  #5  0x002058ae in execute_pass_list_1(opt_pass*) [clone .constprop.62]
      (2134139712)
  #6  0x002058be in execute_pass_list_1(opt_pass*) [clone .constprop.62]
      (2134114560)
  #7  0x002058f7 in execute_pass_list(function*, opt_pass*)
      (2131783780, 2134114560)
  #8  0x0046c3c1 in cgraph_node::expand() (2132414464)
  #9  0x0046d5d6 in symbol_table::compile() (2131783680)
  #10 0x0046e757 in symbol_table::finalize_compilation_unit() (2131783680)
  #11 0x0002885d in c_write_global_declarations() ()
  #12 0x0019ce0c in compile_file() ()
  #13 0x00706b3f in toplev::main(int, char**) (2147478798, 14, 2147478896)
  #14 0x0070617d in main (14, 2147478896, 2147478956)
  (gdb)
>How-To-Repeat:
Described above.
>Fix:
As a workaround, compile check_mem_read_use() in dse.c with -O0:

====
--- src/external/gpl3/gcc/usr.bin/backend/Makefile.orig	2017-02-14 06:45:14.671215727 +0900
+++ src/external/gpl3/gcc/usr.bin/backend/Makefile	2017-02-14 06:44:58.249596141 +0900
@@ -461,6 +461,7 @@
 COPTS.builtins.c+=-O0
 COPTS.convert.c+=-O0
 COPTS.dwarf2out.c+=-O0
+COPTS.dse.c+=-O0
 COPTS.expmed.c+=-O0
 COPTS.expr.c+=-O0
 COPTS.fixed-value.c+=-O0
====

Then, the sample code above can be successfully compiled.

>Release-Note:

>Audit-Trail:
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51967 CVS commit: src
Date: Mon, 13 Feb 2017 22:31:09 +0000

 Module Name:	src
 Committed By:	rin
 Date:		Mon Feb 13 22:31:09 UTC 2017

 Modified Files:
 	src/doc: HACKS
 	src/external/gpl3/gcc/usr.bin/backend: Makefile

 Log Message:
 PR port-vax/51967 GCC 5.4 aborts on vax due to SIGILL for cc1
 As a workaround, compile dse.c with -O0.


 To generate a diff of this commit:
 cvs rdiff -u -r1.177 -r1.178 src/doc/HACKS
 cvs rdiff -u -r1.34 -r1.35 src/external/gpl3/gcc/usr.bin/backend/Makefile

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Sun, 04 Oct 2020 10:01:45 +0000
State-Changed-Why:
Workaround committed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.