[Bug lto/95572] New: lto1: internal compiler error: in lto_input_tree_ref, at lto-streamer-in.c:370

2020-06-08 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95572

Bug ID: 95572
   Summary: lto1: internal compiler error: in lto_input_tree_ref,
at lto-streamer-in.c:370
   Product: gcc
   Version: lto
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: lto
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sujian.liu at huawei dot com
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48700
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48700&action=edit
Test case

The version used by GCC is 7.3.0.
Only under the O0 option, ICE will appear, and O1+ will not report an error.

When I use the riscv compiler,the following ICE will be reported: 

riscv32-unknown-elf-gcc vla-16.c -lm -o ./vla-16.exe -flto

In function 'f5':
lto1: internal compiler error: in lto_input_tree_ref, at lto-streamer-in.c:370
0x55b22e6f8b48 ???
../sysdeps/x86_64/start.S:108
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.
lto-wrapper: fatal error: riscv32-unknown-elf-gcc returned 1 exit status
compilation terminated.
/home/lsj/0608/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
error: lto-wrapper failed
collect2: error: ld returned 1 exit status

=

When I use the x86_64-linux-gnu compiler,the following ICE will be reported:

gcc vla-16.c -lm -o ./vla-16.exe -flto

In function ‘f3’:
lto1: internal compiler error: in lto_input_tree_ref, at lto-streamer-in.c:370
0x8431e8 lto_input_tree_ref(lto_input_block*, data_in*, function*, LTO_tags)
../../gcc/lto-streamer-in.c:370
0x84337d lto_input_tree_1(lto_input_block*, data_in*, LTO_tags, unsigned int)
../../gcc/lto-streamer-in.c:1446
0x84363b lto_input_tree(lto_input_block*, data_in*)
../../gcc/lto-streamer-in.c:1492
0xaf96c5 lto_input_ts_exp_tree_pointers
../../gcc/tree-streamer-in.c:895
0xaf96c5 streamer_read_tree_body(lto_input_block*, data_in*, tree_node*)
../../gcc/tree-streamer-in.c:1081
0x842caf lto_read_tree_1
../../gcc/lto-streamer-in.c:1333
0x8433c7 lto_read_tree
../../gcc/lto-streamer-in.c:1363
0x8433c7 lto_input_tree_1(lto_input_block*, data_in*, LTO_tags, unsigned int)
../../gcc/lto-streamer-in.c:1475
0x8435b2 lto_input_scc(lto_input_block*, data_in*, unsigned int*, unsigned
int*)
../../gcc/lto-streamer-in.c:1387
0x843614 lto_input_tree(lto_input_block*, data_in*)
../../gcc/lto-streamer-in.c:1490
0x8443a9 input_struct_function_base
../../gcc/lto-streamer-in.c:987
0x8443a9 input_function
../../gcc/lto-streamer-in.c:1061
0x8443a9 lto_read_body_or_constructor
../../gcc/lto-streamer-in.c:1259
0x6213f4 cgraph_node::get_untransformed_body()
../../gcc/cgraph.c:3620
0x62b47e cgraph_node::expand()
../../gcc/cgraphunit.c:2012
0x62c0c7 output_in_order
../../gcc/cgraphunit.c:2285
0x62c4f3 symbol_table::compile()
../../gcc/cgraphunit.c:2530
0x5b8ac4 lto_main()
../../gcc/lto/lto.c:3334
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.
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

Attachment provides the test case.

[Bug lto/95572] lto1: internal compiler error: in lto_input_tree_ref, at lto-streamer-in.c:370

2020-06-08 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95572

--- Comment #2 from sujian.liu at huawei dot com ---
(In reply to Martin Liška from comment #1)
> Hello.
> GCC 7.x is out of support, can you please test a newer release, ideally GCC
> 10.1 release?

I tried to compile with GCC 8.2.0, but no errors were reported. 
For LTO, is there a lot of changes between GCC 8.x and GCC 7.x ? What I read in
the changelog is just adding the debug infos. Did I overlook any changes of
details ?

[Bug lto/95677] New: undefined reference to `(anonymous namespace)::xx'

2020-06-15 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95677

Bug ID: 95677
   Summary: undefined reference to `(anonymous namespace)::xx'
   Product: gcc
   Version: lto
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: lto
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sujian.liu at huawei dot com
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48731
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48731&action=edit
dejagnu/testsuite-7.3/g++.old-deja/g++.ns/extern1.C

When compile with lto,it will be reported the following error:

./riscv32-unknown-elf-gcc dejagnu/testsuite-7.3/g++.old-deja/g++.ns/extern1.C
-o extern1.exe -flto
  
/home/lsj/gits/gcc_10_1_0/build/hcc_riscv32/riscv32_elf_build_dir/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/extern1.exe.m1gfd6.ltrans0.ltrans.o: in function `.L0 ':
:(.text+0x6): undefined reference to `(anonymous namespace)::xx'
/home/lsj/gits/gcc_10_1_0/build/hcc_riscv32/riscv32_elf_build_dir/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld:
:(.text+0xa): undefined reference to `(anonymous namespace)::xx'
collect2: error: ld returned 1 exit status

It seems that lto can't deal with the extern variable in the namespace.

The testcase which is one of deja in testsuite-7.3 will be attached.

[Bug c++/95677] undefined reference to `(anonymous namespace)::xx'

2020-06-15 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95677

--- Comment #2 from liusujian  ---
(In reply to Richard Biener from comment #1)
> It's more likely the GENERIC / cgraph output by the C++ frontend is not
> correct
> and works by accident without LTO.  Initial symbol table:
> 
> Initial Symbol table:
> 
> int {anonymous}::xx/3 (int {anonymous}::xx) @0x7f615d2d8180
>   Type: variable
>   Visibility: external
>   References:
>   Referring: _ZN12_GLOBAL__N_13fooEv/0 (write)
>   Availability: not-ready
>   Varpool flags:
> main/2 (int main()) @0x7f615d421168
>   Type: function definition analyzed
>   Visibility: force_output no_reorder public
>   Aux: @0x37a5000
>   References: int {anonymous}::xx/1 (write)
>   Referring:
>   Function flags: body
>   Called by:
>   Calls:
> int {anonymous}::xx/1 (int {anonymous}::xx) @0x7f615d2d8100
>   Type: variable definition analyzed
>   Visibility: force_output no_reorder
>   Aux: @0x7f615d421168
>   References:
>   Referring: main/2 (write)
>   Availability: not-ready
>   Varpool flags: initialized
> _ZN12_GLOBAL__N_13fooEv/0 (void {anonymous}::foo()) @0x7f615d421000
>   Type: function definition analyzed
>   Visibility: force_output no_reorder
>   Aux: @0x7f615d2d8100
>   References: int {anonymous}::xx/3 (write)
>   Referring:
>   Function flags: body
>   Called by:
>   Calls:
> 
> where you can see there are actually two 'xx' objects and the C++ FE
> takes it up to the linker/assembler to resolve them.  But the symtab
> code does not include such "resolving" step.


In other words, C++ is currently unable to deal with this scenario ? Or any
other problems cause the error?

[Bug c++/95677] undefined reference to `(anonymous namespace)::xx'

2020-06-18 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95677

--- Comment #7 from liusujian  ---
Is this really a bug for the GCC when using LTO?
If so, is there any plan to fix this problem?

Thanks!

[Bug c++/95677] undefined reference to `(anonymous namespace)::xx'

2020-07-14 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95677

--- Comment #8 from liusujian  ---
(In reply to Nathan Sidwell from comment #6)
> Ah, anonymous namespaces have internal linkage (and a program-wide unique
> identifier).  Their contents have the linkage they have.  but because
> they're within the anonumous namespace they cannot be named from elsewhere,
> so they have internal linkage for implementation purposes.
> 
> when we actually gave anonymous namespaces there would be no collisions
> between TUs for '::x'.  Now we give it a specific name and adjust the
> linkages of their contents. 
> 
> The C++ FE should adjust the linkage of '::x' too.

Hello, has there been any progress regarding the repair of this issue now?

[Bug lto/96700] New: undefined reference to `failure_on_line_796'

2020-08-18 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96700

Bug ID: 96700
   Summary: undefined reference to `failure_on_line_796'
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: lto
  Assignee: unassigned at gcc dot gnu.org
  Reporter: sujian.liu at huawei dot com
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 49079
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49079&action=edit
the source code

When I compile without -flto, it has no errors.

riscv32-unknown-elf-gcc gcc.dg/tree-ssa/builtin-sprintf.c
-fno-optimize-sibling-calls -fstack-protector -fno-diagnostics-show-caret
-fdiagnostics-color=never -ansi -pedantic-errors -O2 -Wall -Wno-pedantic
-fprintf-return-value -lm -o ./builtin-sprintf.exe
gcc.dg/tree-ssa/builtin-sprintf.c: In function 'test_d_i':
gcc.dg/tree-ssa/builtin-sprintf.c:307:20: warning: '0' flag ignored with
precision and '%i' gnu_printf format [-Wformat=]
gcc.dg/tree-ssa/builtin-sprintf.c:128:44: note: in definition of macro 'RNG'
gcc.dg/tree-ssa/builtin-sprintf.c: In function 'test_percent':
gcc.dg/tree-ssa/builtin-sprintf.c:796:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'
gcc.dg/tree-ssa/builtin-sprintf.c:797:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'
gcc.dg/tree-ssa/builtin-sprintf.c:798:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'

When I compile with -flto, I will get the error as follow:

riscv32-unknown-elf-gcc gcc.dg/tree-ssa/builtin-sprintf.c
-fno-optimize-sibling-calls -fstack-protector -fno-diagnostics-show-caret
-fdiagnostics-color=never -ansi -pedantic-errors -O2 -Wall -Wno-pedantic
-fprintf-return-value -lm -o ./builtin-sprintf.exe -flto
gcc.dg/tree-ssa/builtin-sprintf.c: In function 'test_d_i':
gcc.dg/tree-ssa/builtin-sprintf.c:307:20: warning: '0' flag ignored with
precision and '%i' gnu_printf format [-Wformat=]
gcc.dg/tree-ssa/builtin-sprintf.c:128:44: note: in definition of macro 'RNG'
gcc.dg/tree-ssa/builtin-sprintf.c: In function 'test_percent':
gcc.dg/tree-ssa/builtin-sprintf.c:796:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'
gcc.dg/tree-ssa/builtin-sprintf.c:797:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'
gcc.dg/tree-ssa/builtin-sprintf.c:798:18: warning: too many arguments for
format [-Wformat-extra-args]
gcc.dg/tree-ssa/builtin-sprintf.c:114:44: note: in definition of macro 'EQL'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `check':
:(.text+0x182): undefined reference to `failure_on_line_796'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `test_percent':
:(.text+0x1c6): undefined reference to `failure_on_line_797'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
:(.text+0x206): undefined reference to `failure_on_line_798'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
:(.text+0x248): undefined reference to `failure_on_line_799'
..
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `.L576':
:(.text+0x7744): undefined reference to `failure_on_line_164'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `.L577':
:(.text+0x77a4): undefined reference to `failure_on_line_165'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `.L579':
:(.text+0x7808): undefined reference to `failure_on_line_167'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0.ltrans.o: in function `.L580':
:(.text+0x7862): undefined reference to `failure_on_line_168'
/home/lsj/b014/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/ld:
/tmp/ccvVHTzC.ltrans0

[Bug c++/95677] undefined reference to `(anonymous namespace)::xx'

2020-09-16 Thread sujian.liu at huawei dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95677

--- Comment #9 from liusujian  ---
After lto and as:

/home/lsj/dts/SDK_CPU_RISCV/output/hcc_riscv32/hcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0/../../../../riscv32-unknown-elf/bin/as
-v --traditional-format -march=rv32imc -march=rv32imc -mabi=ilp32 -mabi=ilp32
-o extern2.exe.ltrans0.ltrans.o extern2.exe.ltrans0.s

We got the two symbols of _ZN12_GLOBAL__N_12xxE and _ZN12_GLOBAL__N_12xxE.lto:

./riscv32-unknown-elf-readelf -s extern2.exe.ltrans0.ltrans.o

Symbol table '.symtab' contains 21 entries:
   Num:Value  Size TypeBind   Vis  Ndx Name
 0:  0 NOTYPE  LOCAL  DEFAULT  UND
 1:  0 FILELOCAL  DEFAULT  ABS 
 2:  0 SECTION LOCAL  DEFAULT1
 3:  0 SECTION LOCAL  DEFAULT3
 4:  0 SECTION LOCAL  DEFAULT4
 5: 20 FUNCLOCAL  DEFAULT1 _ZN12_GLOBAL__N_13fooEv
 6:  0 NOTYPE  LOCAL  DEFAULT1 .L0
 7: 0006 0 NOTYPE  LOCAL  DEFAULT1 .L0
 8: 0010 0 NOTYPE  LOCAL  DEFAULT1 .L0
 9: 0014 0 NOTYPE  LOCAL  DEFAULT1 .L0
10:  0 SECTION LOCAL  DEFAULT5
11:  4 OBJECT  LOCAL  DEFAULT5 _ZN12_GLOBAL__N_12xxE.lto
12: 0014 0 NOTYPE  LOCAL  DEFAULT1 .L0
13: 001a 0 NOTYPE  LOCAL  DEFAULT1 .L0
14: 002a 0 NOTYPE  LOCAL  DEFAULT1 .L0
15: 002e 0 NOTYPE  LOCAL  DEFAULT1 .L0
16:  0 SECTION LOCAL  DEFAULT6
17:  0 SECTION LOCAL  DEFAULT7
18:  0 SECTION LOCAL  DEFAULT9
19:  0 NOTYPE  GLOBAL DEFAULT  UND _ZN12_GLOBAL__N_12xxE
20: 001426 FUNCGLOBAL DEFAULT1 main

We found that by GDB ,it renamed by the function of rename_statics in
gcc\lto\lto-partition.c. Here is the function body of rename_statics:
---
/* If NODE represents a static variable.  See if there are other variables
   of the same name in partition ENCODER (or in whole compilation unit if
   ENCODER is NULL) and if so, mangle the statics.  Always mangle all
   conflicting statics, so we reduce changes of silently miscompiling
   asm statements referring to them by symbol name.  */

static void
rename_statics (lto_symtab_encoder_t encoder, symtab_node *node)
{
  tree decl = node->decl;
  symtab_node *s;
  tree name = DECL_ASSEMBLER_NAME (decl);

  /* See if this is static symbol. */
  if (((node->externally_visible && !node->weakref)
  /* FIXME: externally_visible is somewhat illogically not set for
 external symbols (i.e. those not defined).  Remove this test
 once this is fixed.  */
|| DECL_EXTERNAL (node->decl)
|| !node->real_symbol_p ())
   && !may_need_named_section_p (encoder, node))
return;

  /* Now walk symbols sharing the same name and see if there are any conflicts.
 (all types of symbols counts here, since we can not have static of the
 same name as external or public symbol.)  */
  for (s = symtab_node::get_for_asmname (name);
   s; s = s->next_sharing_asm_name)
if ((s->real_symbol_p () || may_need_named_section_p (encoder, s))
&& s->decl != node->decl
&& (!encoder
|| lto_symtab_encoder_lookup (encoder, s) != LCC_NOT_FOUND))
   break;

  /* OK, no confict, so we have nothing to do.  */
  if (!s)
return;

  if (symtab->dump_file)
fprintf (symtab->dump_file,
"Renaming statics with asm name: %s\n", node->name ());

  /* Assign every symbol in the set that shares the same ASM name an unique
 mangled name.  */
  for (s = symtab_node::get_for_asmname (name); s;)
if ((!s->externally_visible || s->weakref)
/* Transparent aliases having same name as target are renamed at a
   time their target gets new name.  Transparent aliases that use
   separate assembler name require the name to be unique.  */
&& (!s->transparent_alias || !s->definition || s->weakref
|| !symbol_table::assembler_names_equal_p
 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (s->decl)),
  IDENTIFIER_POINTER
(DECL_ASSEMBLER_NAME (s->get_alias_target()->decl
&& ((s->real_symbol_p ()
 && !DECL_EXTERNAL (s->decl)
 && !TREE_PUBLIC (s->decl))
|| may_need_named_section_p (encoder, s))
&& (!encoder
|| lto_symtab_encoder_lookup (encoder, s) != LCC_NOT_FOUND))
  {
if (privatize_symbol_name (s))
  /* Re-start from beginning since we do not know how many
 symbols changed a name.  */
  s = symtab_node::get_for_asmname (name);
else s = s->next_sharing_asm_name;
  }
else s = s->next_sharing_asm_name;
}
---
The