Bug 65803 - blackfin: internal compiler error: segment fault linux kernel
Summary: blackfin: internal compiler error: segment fault linux kernel
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-18 23:04 UTC by Chen Gang
Modified: 2015-06-24 04:29 UTC (History)
1 user (show)

See Also:
Host:
Target: blackfin
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Simplified version of file causing segfault (968 bytes, text/plain)
2015-05-07 09:29 UTC, Hans-Erik Floryd
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chen Gang 2015-04-18 23:04:38 UTC
The code:

  [root@localhost gcc]# cat lbalance.i
  struct a {
   short count;
  };

  struct reiserfs_de_head {
   unsigned short deh_location;
  } __attribute__ ((__packed__));

  void leaf_cut_from_buffer(struct a *ih, int from)
  {
   struct reiserfs_de_head *deh = (struct reiserfs_de_head *)ih;
   int i;

   for (i = ih->count - 1; i > from; i--)
    deh[i].deh_location--;

   for (i = 0; i < from; i++)
    deh[i].deh_location--;
  }

The error:

  [root@localhost gcc]# /upstream/build-gcc-blackfin/gcc/cc1 lbalance.i -Os -fno-strict-overflow
  lbalance.i: In function 'leaf_cut_from_buffer':
  lbalance.i:19:1: internal compiler error: Segmentation fault
   }
   ^
  0xa54a9f crash_signal
        ../../gcc-blackfin/gcc/toplev.c:383
  0x77af8b INSN_UID
        ../../gcc-blackfin/gcc/rtl.h:1329
  0x77af8b insn_current_reference_address(rtx_insn*)
        ../../gcc-blackfin/gcc/final.c:686  0xd39604 insn_current_length(rtx_insn*)
        /upstream/build-gcc-blackfin/gcc/insn-attrtab.c:84
  0x77c12e shorten_branches(rtx_insn*)
        ../../gcc-blackfin/gcc/final.c:1478
  0x77c51f rest_of_handle_shorten_branches
        ../../gcc-blackfin/gcc/final.c:4580
  0x77c51f execute
        ../../gcc-blackfin/gcc/final.c:4609
  Please submit a full bug report,

The version:

  [root@localhost gcc]# /upstream/release-blackfin/bin/bfin-gchen-elf-gcc -v
  Using built-in specs.
  COLLECT_GCC=/upstream/release-blackfin/bin/bfin-gchen-elf-gcc
  COLLECT_LTO_WRAPPER=/upstream/release-blackfin/libexec/gcc/bfin-gchen-elf/5.0.0/lto-wrapper
  Target: bfin-gchen-elf
  Configured with: ../gcc-blackfin/configure --target=bfin-gchen-elf --disable-nls --disable-threads --disable-shared --disable-libssp --disable-libquadmath --disable-libgomp --disable-libatomic --prefix=/upstream/release-blackfin --without-headers target_alias=bfin-gchen-elf --enable-languages=c,lto
  Thread model: single
  gcc version 5.0.0 20150401 (experimental) (GCC)
Comment 1 Hans-Erik Floryd 2015-05-07 09:14:45 UTC
I am seeing a similar problem compiling ip_addr.c from the lwIP project. The segfault happens with GCC >= 4.8. GCC4.7.4 works fine. Using GCC4.9.2:

vmadm@ubuntu$ /home/vmadm/buildcross/toolchain//bfin-elf/bin/bfin-elf-gcc -c ip_addr.i -Os -v
Using built-in specs.
COLLECT_GCC=/home/vmadm/buildcross/toolchain//bfin-elf/bin/bfin-elf-gcc
Target: bfin-elf
Configured with: ../gcc-4.9.2/configure --target=bfin-elf --prefix=/home/vmadm/buildcross/toolchain/bfin-elf --disable-nls --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --enable-plugins --with-newlib --with-headers=../newlib-2.2.0.20150323/newlib/libc/include --disable-shared --disable-threads --disable-libssp --disable-libmudflap --disable-libgomp --disable-__cxa_atexit --disable-libstdcxx-pch --disable-multilib
Thread model: single
gcc version 4.9.2 
COLLECT_GCC_OPTIONS='-c' '-Os' '-v'
 /home/vmadm/buildcross/toolchain/bfin-elf/libexec/gcc/bfin-elf/4.9.2/cc1 -fpreprocessed ip_addr.i -fshort-wchar -quiet -dumpbase ip_addr.i -auxbase ip_addr -Os -version -o /tmp/ccl40owG.s
GNU C version 4.9.2 (bfin-elf)
        compiled by GNU C version 4.8.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C version 4.9.2 (bfin-elf)
        compiled by GNU C version 4.8.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ccc6db3091b1c65b1a52924f93fd549a
ip_addr.c: In function 'ipaddr_ntoa_r':
ip_addr.c:312:1: internal compiler error: Segmentation fault
 }
 ^
0x8490960 crash_signal
        ../../gcc-4.9.2/gcc/toplev.c:337
0x82c6a01 insn_current_reference_address(rtx_def*)
        ../../gcc-4.9.2/gcc/final.c:656
0x867c44b insn_current_length(rtx_def*)
        /home/vmadm/buildcross/build/build_gcc/gcc/insn-attrtab.c:35
0x82c75d8 shorten_branches(rtx_def*)
        ../../gcc-4.9.2/gcc/final.c:1446
0x82c7a1f rest_of_handle_shorten_branches
        ../../gcc-4.9.2/gcc/final.c:4519
0x82c7a1f execute
        ../../gcc-4.9.2/gcc/final.c:4548
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.

The segfault only happens when using -Os.
Comment 2 Hans-Erik Floryd 2015-05-07 09:29:41 UTC
Created attachment 35484 [details]
Simplified version of file causing segfault
Comment 3 Chen Gang 2015-06-20 08:42:14 UTC
It is about JUMP_LABEL, gcc should set the JUMP_LABEL before use it. If we set the label as soon as it is generated, it can build the issue code successfully.


diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index dc24ed5..b8c9567 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -3777,7 +3777,8 @@ hwloop_optimize (hwloop_info loop)
        }
       else
        {
-         emit_jump_insn (gen_jump (label));
+         rtx_insn * ret = emit_jump_insn (gen_jump (label));
+         JUMP_LABEL(ret) = label;
          seq_end = emit_barrier ();
        }
     }

So we can say, it must be the direct cause (but may be not the root cause). I shall continue analyzing: "why gcc did not set JUMP_LABEL before using it".

Welcome any others' ideas, suggestions and completions.

Thanks.
Comment 4 Chen Gang 2015-06-20 10:26:22 UTC
Reference to gccint.pdf Page 268 for jump_isn, we know that JUMP_LABLE() must be defined after optimization completed. In our case, we are just doing optimization, and is almost finished, so we need set JUMP_LABLE() after emit jump_insn.

The related diff is bellow:

diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index dc24ed5..0297b59 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -3777,7 +3777,10 @@ hwloop_optimize (hwloop_info loop)
        }
       else
        {
-         emit_jump_insn (gen_jump (label));
+         rtx_insn * ret = emit_jump_insn (gen_jump (label));
+
+         JUMP_LABEL(ret) = label;
+         LABEL_NUSES (label)++;
          seq_end = emit_barrier ();
        }
     }
Comment 5 Jeffrey A. Law 2015-06-24 04:23:11 UTC
Author: law
Date: Wed Jun 24 04:22:39 2015
New Revision: 224866

URL: https://gcc.gnu.org/viewcvs?rev=224866&root=gcc&view=rev
Log:
	PR target/65803
	* config/bfin/bfin.c (hwloop_optimize): Initialize
	JUMP_LABEL for newly created jump.

        PR target/65803
	* gcc.c-torture/pr65803.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr65803.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/bfin/bfin.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jeffrey A. Law 2015-06-24 04:29:48 UTC
Fixed on trunk.