Bug 85870 - [LTO1] ICE in linemap_line_start, at libcpp/line-map.c:794
Summary: [LTO1] ICE in linemap_line_start, at libcpp/line-map.c:794
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.3.0
: P2 normal
Target Milestone: 7.5
Assignee: Martin Liška
URL:
Keywords: ice-on-valid-code, lto
Depends on:
Blocks:
 
Reported: 2018-05-22 12:11 UTC by sudi
Modified: 2019-03-11 11:19 UTC (History)
3 users (show)

See Also:
Host:
Target: aarch64-none-linux-gnu, x86_64-pc-linux-gnu
Build:
Known to work: 7.4.1, 8.3.1, 9.0
Known to fail:
Last reconfirmed: 2018-05-22 00:00:00


Attachments
Reproducer (2.35 KB, application/gzip)
2018-05-22 12:11 UTC, sudi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sudi 2018-05-22 12:11:39 UTC
Created attachment 44160 [details]
Reproducer

Hi

Please find the attached tar to show the following failure

Reading object files: test_1.o test_2.olto1: internal compiler error:
in linemap_line_start, at libcpp/line-map.c:794
0x134278f linemap_line_start(line_maps*, unsigned int, unsigned int)
	/work/trunk/src/gcc/libcpp/line-map.c:794
0x97fea1 lto_location_cache::apply_location_cache()
	/work/trunk/src/gcc/gcc/lto-streamer-in.c:194
0x5dd948 lto_read_decls
	/work/trunk/src/gcc/gcc/lto/lto.c:1852
0x5dee7d lto_file_finalize
	/work/trunk/src/gcc/gcc/lto/lto.c:2121
0x5dee7d lto_create_files_from_ids
	/work/trunk/src/gcc/gcc/lto/lto.c:2131
0x5dee7d lto_file_read
	/work/trunk/src/gcc/gcc/lto/lto.c:2172
0x5dee7d read_cgraph_and_symbols
	/work/trunk/src/gcc/gcc/lto/lto.c:2845
0x5dee7d lto_main()
	/work/trunk/src/gcc/gcc/lto/lto.c:3362
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.

This is failing on (at least) AArch64 and x86 targets.
On AArch64, this is failing on gcc-6, gcc-7, gcc-8 and trunk.
On x86, this is failing on at least gcc-8 and trunk.

The folder contains the following:
  1) A README file.
  2) Two test files : test_1.i and test_2.i
  3) One script to reproduce the failure.

To be able to run the script, it needs the following to be defined:
  1) TARGET (aarch-none-linux-gnu or x86_64-pc-linux-gnu)
  2) GCC_INSTALL (/path/to/install/directory)
Comment 1 Richard Biener 2018-05-22 14:13:53 UTC
Confirmed.  Why's the code invalid?
Comment 2 sudi 2018-05-22 14:22:23 UTC
Sorry that was my bad..its valid code
Comment 3 Martin Liška 2018-10-09 10:30:20 UTC
Can't reproduce with GCC 7.3.0 on x86_64:

+ gcc-7 -O2 -flto -c test_1.i -o test_1.o
+ gcc-7 -O2 -flto -c test_2.i -o test_2.o
+ gcc-7 test_1.o test_2.o
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/7/../../../../lib64/crt1.o: in function `_start':
/home/abuild/rpmbuild/BUILD/glibc-2.27/csu/../sysdeps/x86_64/start.S:104: undefined reference to `main'
collect2: error: ld returned 1 exit status

Richi how did you achieve to reproduce that?
Comment 4 Ramana Radhakrishnan 2018-10-09 10:34:55 UTC
(In reply to Martin Liška from comment #3)
> Can't reproduce with GCC 7.3.0 on x86_64:
> 
> + gcc-7 -O2 -flto -c test_1.i -o test_1.o
> + gcc-7 -O2 -flto -c test_2.i -o test_2.o
> + gcc-7 test_1.o test_2.o
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld:
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../lib64/crt1.o: in function
> `_start':
> /home/abuild/rpmbuild/BUILD/glibc-2.27/csu/../sysdeps/x86_64/start.S:104:
> undefined reference to `main'
> collect2: error: ld returned 1 exit status
> 
> Richi how did you achieve to reproduce that?

It's still failing on aarch64-none-linux-gnu. So that doesn't mean this goes waiting.
Comment 5 Martin Liška 2018-10-09 10:41:02 UTC
(In reply to Ramana Radhakrishnan from comment #4)
> (In reply to Martin Liška from comment #3)
> > Can't reproduce with GCC 7.3.0 on x86_64:
> > 
> > + gcc-7 -O2 -flto -c test_1.i -o test_1.o
> > + gcc-7 -O2 -flto -c test_2.i -o test_2.o
> > + gcc-7 test_1.o test_2.o
> > /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld:
> > /usr/lib64/gcc/x86_64-suse-linux/7/../../../../lib64/crt1.o: in function
> > `_start':
> > /home/abuild/rpmbuild/BUILD/glibc-2.27/csu/../sysdeps/x86_64/start.S:104:
> > undefined reference to `main'
> > collect2: error: ld returned 1 exit status
> > 
> > Richi how did you achieve to reproduce that?
> 
> It's still failing on aarch64-none-linux-gnu. So that doesn't mean this goes
> waiting.

Native or cross compiler? Because cross compiler works fine for me:

$ aarch64-suse-linux-g++-8 -c test_1.i -c -flto
$ aarch64-suse-linux-g++-8 -c test_2.i -c -flto
$ /usr/lib64/gcc/aarch64-suse-linux/8/lto1 test_1.o test_2.o
Reading object files: test_1.o test_2.o {GC start 1697k} 
Reading the callgraph
Merging declarations
Reading summaries
Reading function bodies:
Performing interprocedural optimizations
 <whole-program> <profile_estimate> <icf> <devirt> <cp> <cdtor> <fnsummary> <inline> <pure-const> <free-fnsummary> <static-var> <single-use> <comdats>Assembling functions:
 <materialize-all-clones> init_xyz_0 init_xyz_1
Time variable                                   usr           sys          wall               GGC
 phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.00 (  0%)    1847 kB (  1%)
 phase opt and generate             :   2.11 (100%)   0.12 ( 92%)   2.23 (100%)  188629 kB ( 99%)
 phase finalize                     :   0.00 (  0%)   0.01 (  8%)   0.01 (  0%)       0 kB (  0%)
 lto stream inflate                 :   0.12 (  6%)   0.03 ( 23%)   0.15 (  7%)       0 kB (  0%)
 ipa lto constructors in            :   0.65 ( 31%)   0.03 ( 23%)   0.69 ( 31%)  188513 kB ( 99%)
 TOTAL                              :   2.11          0.13          2.24         190523 kB
Comment 6 sudi 2018-10-09 11:13:46 UTC
Still fails for me on aarch64-none-linux-gnu-gcc and aarch64-none-elf-gcc on trunk and gcc-8.2.1 with the same error

Reading object files: test_1.o test_2.olto1: internal compiler error: in linemap_line_start, at libcpp/line-map.c:794
0x1414d7b linemap_line_start(line_maps*, unsigned int, unsigned int)
	/aarch64-none-elf/build/src/gcc/libcpp/line-map.c:794
0x9a264f lto_location_cache::apply_location_cache()
	/aarch64-none-elf/build/src/gcc/gcc/lto-streamer-in.c:194
0x5e946c lto_read_decls
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:1852
0x5ea533 lto_file_finalize
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:2121
0x5ea533 lto_create_files_from_ids
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:2131
0x5ea533 lto_file_read
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:2172
0x5ea533 read_cgraph_and_symbols
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:2845
0x5ea533 lto_main()
	/aarch64-none-elf/build/src/gcc/gcc/lto/lto.c:3362
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.

aarch64-none-linux-gnu-gcc --version
aarch64-none-linux-gnu-gcc (fsf-trunk.1693) 9.0.0 20181005 (experimental)
Copyright (C) 2018 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.

aarch64-none-linux-gnu-gcc --version
aarch64-none-linux-gnu-gcc (fsf-8.90) 8.2.1 20181007
Copyright (C) 2018 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.

aarch64-none-elf-gcc --version
aarch64-none-elf-gcc (fsf-trunk.1693) 9.0.0 20181005 (experimental)
Copyright (C) 2018 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.

aarch64-none-elf-gcc --version
aarch64-none-elf-gcc (fsf-8.90) 8.2.1 20181007
Copyright (C) 2018 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.
Comment 7 sudi 2018-10-09 11:16:31 UTC
It is not failing on x86_64 trunk anymore but with 8.0.1

+ TARGET=x86_64-pc-linux-gnu
+ GCC_INSTALL=/work/x86-trunk/bld
+ GCC=/work/x86-trunk/bld/bin/x86_64-pc-linux-gnu-gcc-8.0.1
+ LTO1=/work/x86-trunk/bld/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto1
+ CFLAGS=-O2 -flto
+ /work/x86-trunk/bld/bin/x86_64-pc-linux-gnu-gcc-8.0.1 -O2 -flto -c test_1.i -o test_1.o
+ /work/x86-trunk/bld/bin/x86_64-pc-linux-gnu-gcc-8.0.1 -O2 -flto -c test_2.i -o test_2.o
+ /work/x86-trunk/bld/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto1 test_1.o test_2.o
Reading object files: test_1.o test_2.olto1: internal compiler error: in linemap_line_start, at libcpp/line-map.c:794
0x14a025b linemap_line_start(line_maps*, unsigned int, unsigned int)
	../../src/gcc/libcpp/line-map.c:794
0xa8c893 lto_location_cache::apply_location_cache()
	../../src/gcc/gcc/lto-streamer-in.c:194
0x76bc54 lto_read_decls
	../../src/gcc/gcc/lto/lto.c:1816
0x76e221 lto_file_finalize
	../../src/gcc/gcc/lto/lto.c:2076
0x76e221 lto_create_files_from_ids
	../../src/gcc/gcc/lto/lto.c:2086
0x76e221 lto_file_read
	../../src/gcc/gcc/lto/lto.c:2127
0x76e221 read_cgraph_and_symbols
	../../src/gcc/gcc/lto/lto.c:2839
0x76e221 lto_main()
	../../src/gcc/gcc/lto/lto.c:3356
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 8 Ramana Radhakrishnan 2018-10-09 11:20:05 UTC
(In reply to Martin Liška from comment #5)
> (In reply to Ramana Radhakrishnan from comment #4)
> > (In reply to Martin Liška from comment #3)
> > > Can't reproduce with GCC 7.3.0 on x86_64:
> > > 
> > > + gcc-7 -O2 -flto -c test_1.i -o test_1.o
> > > + gcc-7 -O2 -flto -c test_2.i -o test_2.o
> > > + gcc-7 test_1.o test_2.o
> > > /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld:
> > > /usr/lib64/gcc/x86_64-suse-linux/7/../../../../lib64/crt1.o: in function
> > > `_start':
> > > /home/abuild/rpmbuild/BUILD/glibc-2.27/csu/../sysdeps/x86_64/start.S:104:
> > > undefined reference to `main'
> > > collect2: error: ld returned 1 exit status
> > > 
> > > Richi how did you achieve to reproduce that?
> > 
> > It's still failing on aarch64-none-linux-gnu. So that doesn't mean this goes
> > waiting.
> 
> Native or cross compiler? Because cross compiler works fine for me:
> 
> $ aarch64-suse-linux-g++-8 -c test_1.i -c -flto
> $ aarch64-suse-linux-g++-8 -c test_2.i -c -flto
> $ /usr/lib64/gcc/aarch64-suse-linux/8/lto1 test_1.o test_2.o
> Reading object files: test_1.o test_2.o {GC start 1697k} 
> Reading the callgraph
> Merging declarations
> Reading summaries
> Reading function bodies:
> Performing interprocedural optimizations
>  <whole-program> <profile_estimate> <icf> <devirt> <cp> <cdtor> <fnsummary>
> <inline> <pure-const> <free-fnsummary> <static-var> <single-use>
> <comdats>Assembling functions:
>  <materialize-all-clones> init_xyz_0 init_xyz_1
> Time variable                                   usr           sys         
> wall               GGC
>  phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.00 ( 
> 0%)    1847 kB (  1%)
>  phase opt and generate             :   2.11 (100%)   0.12 ( 92%)   2.23
> (100%)  188629 kB ( 99%)
>  phase finalize                     :   0.00 (  0%)   0.01 (  8%)   0.01 ( 
> 0%)       0 kB (  0%)
>  lto stream inflate                 :   0.12 (  6%)   0.03 ( 23%)   0.15 ( 
> 7%)       0 kB (  0%)
>  ipa lto constructors in            :   0.65 ( 31%)   0.03 ( 23%)   0.69 (
> 31%)  188513 kB ( 99%)
>  TOTAL                              :   2.11          0.13          2.24    
> 190523 kB

cross-compiler built with revision r264905 and note that we have --enable-checking=yes turned on. Maybe that makes a difference ?
Comment 9 Martin Liška 2018-10-09 12:18:02 UTC
Now confirmed!
Comment 10 Martin Liška 2018-10-09 12:55:32 UTC
Obviously fails for the huge constructor in test_2.i:

SOURCE_LINE (map, r) == 14
while
to_line == 1048590

Note that line 14 is first element of the constructor. So maybe David can debug that?

The test-case can't be reduced, one needs so huge initialization.
Comment 11 sudi 2018-10-09 13:03:48 UTC
Yes I remember spending a while to get it to reduce further. But it needs a big constructor to fail.
Comment 12 Jakub Jelinek 2018-10-26 10:10:57 UTC
GCC 6 branch is being closed
Comment 13 Jakub Jelinek 2018-12-05 13:32:09 UTC
Reduced testcase that still ICEs in patch form:
--- gcc/testsuite/gcc.dg/lto/pr85870_0.c.jj	2018-12-05 14:30:47.506208171 +0100
+++ gcc/testsuite/gcc.dg/lto/pr85870_0.c	2018-12-05 14:29:15.468725392 +0100
@@ -0,0 +1,34 @@
+/* PR c/85870 */
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -flto -O2 } } } */
+
+typedef struct abc_s {
+  char a1;
+  short a2;
+  unsigned int a3;
+  unsigned int a4;
+} abc;
+
+typedef struct xyz_s {
+ unsigned x1;
+ unsigned x2;
+ abc *x3;
+} xyz;
+
+extern xyz XYZ[3];
+static const abc Arr1[]={
+                       {0,0,0xdeadbeaf,0xbeefdead} ,
+#line 1040
+                        {0,0,0xdeadbeaf,0xbeefdead} };
+
+void init_xyz_0() {
+  XYZ[0].x1=975753;
+  XYZ[0].x2=1024;
+  XYZ[0].x3=(abc *)Arr1;
+
+}
+
+int
+main ()
+{
+}
--- gcc/testsuite/gcc.dg/lto/pr85870_1.c.jj	2018-12-05 14:30:53.269113163 +0100
+++ gcc/testsuite/gcc.dg/lto/pr85870_1.c	2018-12-05 14:29:22.613607607 +0100
@@ -0,0 +1,27 @@
+typedef struct abc_s {
+  char a1;
+  short a2;
+  unsigned int a3;
+  unsigned int a4;
+} abc;
+
+
+typedef struct xyz_s {
+ unsigned int x1;
+ unsigned int x2;
+ abc *x3;
+} xyz;
+
+
+extern xyz XYZ[3];
+static const abc Arr2[]={
+                       {0,0,0xbeafdead,0xdeadbeef} ,
+#line 1048594
+                           {0,0,0xbeafdead,0xdeadbeef} };
+
+void init_xyz_1() {
+  XYZ[1].x1=425753;
+  XYZ[1].x2=1048576;
+  XYZ[1].x3=(abc *)Arr2;
+
+}
Comment 14 Jakub Jelinek 2018-12-05 13:40:34 UTC
Bet the line number is high enough that we jump over some threshold and stop counting ranges or columns or whatever at that point.  David, can you please have a look?
Comment 15 Martin Liška 2019-03-08 14:02:34 UTC
Dup of PR88147.
I'm going to install Jakub's testcase.
And I'll open this we'll need backports.
Comment 16 Martin Liška 2019-03-08 14:04:59 UTC
Author: marxin
Date: Fri Mar  8 14:04:27 2019
New Revision: 269495

URL: https://gcc.gnu.org/viewcvs?rev=269495&root=gcc&view=rev
Log:
Add tests for resolved PR (PR c/85870).

2019-03-08  Jakub Jelinek  <jakub@redhat.com>

	PR c/85870
	* gcc.dg/lto/pr85870_0.c: New test.
	* gcc.dg/lto/pr85870_1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/lto/pr85870_0.c
    trunk/gcc/testsuite/gcc.dg/lto/pr85870_1.c
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 17 Jakub Jelinek 2019-03-08 22:31:08 UTC
Author: jakub
Date: Fri Mar  8 22:30:34 2019
New Revision: 269516

URL: https://gcc.gnu.org/viewcvs?rev=269516&root=gcc&view=rev
Log:
	PR c/85870
	* gcc.dg/lto/pr85870_0.c: Add dg-extra-ld-options with
	-r -nostdlib -flinker-output=nolto-rel.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/lto/pr85870_0.c
Comment 18 Martin Liška 2019-03-11 11:19:21 UTC
Fixed now.