https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62034
Bug ID: 62034 Summary: ICE for big statically initialized arrays compiled with LTO Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: enkovich.gnu at gmail dot com Created attachment 33259 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33259&action=edit Reproducer I get ICE when try to compile tests with big amount of statically initialized data. gcc --version gcc (GCC) 4.10.0 20140806 (experimental) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. gcc -flto test.c gcc: internal compiler error: Segmentation fault (program lto1) 0x405c80 execute ../../gcc-ref/gcc/gcc.c:2900 0x409fe9 do_spec_1 ../../gcc-ref/gcc/gcc.c:4704 0x40d475 process_brace_body ../../gcc-ref/gcc/gcc.c:5987 0x40d2b1 handle_braces ../../gcc-ref/gcc/gcc.c:5901 0x40bf9d do_spec_1 ../../gcc-ref/gcc/gcc.c:5358 0x40d475 process_brace_body ../../gcc-ref/gcc/gcc.c:5987 0x40d2b1 handle_braces ../../gcc-ref/gcc/gcc.c:5901 0x40bf9d do_spec_1 ../../gcc-ref/gcc/gcc.c:5358 0x40c38c do_spec_1 ../../gcc-ref/gcc/gcc.c:5473 0x40d475 process_brace_body ../../gcc-ref/gcc/gcc.c:5987 0x40d2b1 handle_braces ../../gcc-ref/gcc/gcc.c:5901 0x40bf9d do_spec_1 ../../gcc-ref/gcc/gcc.c:5358 0x409664 do_spec_2 ../../gcc-ref/gcc/gcc.c:4405 0x409582 do_spec(char const*) ../../gcc-ref/gcc/gcc.c:4372 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. lto-wrapper: fatal error: gcc-ref-build/bin/gcc returned 4 exit status compilation terminated. /usr/bin/ld: lto-wrapper failed collect2: error: ld returned 1 exit status Debugger shows that problem appears when lto_input_tree tries to dig through a bunch of SCC entries in input stream. Each SCC entry cause two new functions (lto_input_tree and lto_input_tree_1) in the call stack. With many consequent SCC entries stack may grow too much (in my case compiler segfaulted with ~600 000 entries in the call stack). Attached test has a statically initialized array with a million elements. Bigger data set may be required to break the compiler if you use increased stack size. Problem appeared after this commit: https://gcc.gnu.org/ml/gcc-cvs/2014-07/msg00291.html Following patch removing recursion helps me to compile my tests: diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c index 698f926..25657da 100644 --- a/gcc/lto-streamer-in.c +++ b/gcc/lto-streamer-in.c @@ -1345,7 +1345,16 @@ lto_input_tree_1 (struct lto_input_block *ib, struct data_in *data_in, tree lto_input_tree (struct lto_input_block *ib, struct data_in *data_in) { - return lto_input_tree_1 (ib, data_in, streamer_read_record_start (ib), 0); + enum LTO_tags tag; + + /* Skip SCC entries. */ + while ((tag = streamer_read_record_start (ib)) == LTO_tree_scc) + { + unsigned len, entry_len; + lto_input_scc (ib, data_in, &len, &entry_len); + } + + return lto_input_tree_1 (ib, data_in, tag, 0); } Did not fully test this patch yet.