http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53572
Bug #: 53572 Summary: Some public symbols don't get to serialized LTO Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto AssignedTo: unassig...@gcc.gnu.org ReportedBy: tetra2...@gmail.com Created attachment 27553 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27553 This archive includes Makefile, header and two cpps which illustrate the problem The attached small project builds successfully by default ygribov@ygribov-desktop:~/test/repro-x86$ make CC=<path-to-gcc> clean all rm -f prog main.o lib.a lib.o gcc -O2 -DNDEBUG -frtti -c -o main.o main.cpp gcc -O2 -DNDEBUG -frtti -c -o lib.o lib.cpp ar rcs lib.a lib.o gcc main.o -L. lib.a -o prog -lsupc++ but fails if I compile with LTO enabled: ygribov@ygribov-desktop:~/test/repro-x86/jni$ make CC=<path-to-gcc> LTO=-flto clean all rm -f prog main.o lib.a lib.o gcc -flto -O2 -DNDEBUG -frtti -save-temps -c -o main.o main.cpp gcc -O2 -DNDEBUG -frtti -save-temps -c -o lib.o lib.cpp ar rcs lib.a lib.o gcc -flto main.o -L. lib.a -o prog -lsupc++ `_ZTI1A' referenced in section `.rodata._ZTV1A[_ZTV1A]' of lib.a(lib.o): defined in discarded section `.text' of main.o (symbol from plugin) collect2: error: ld returned 1 exit status make: *** [prog] Error 1 _ZTI1A is a weak definition of vtable for class A which is defined both in main.cpp and in lib.cpp (because they both include common.h which defines thus class). Main.cpp is compiled with -flto and _ZTI1A then gets into main.o's LTO symtab. As main.o is the first file in the list which declares to provide definition for this weak symbol linker assumes that it should come from main.o. But for some reason the actual GIMPLE tree for _ZTI1A is not stored in main.o's LTO sections and this causes errors during linking (linker can't find symbol promised by main.o's LTO symtab). I tried to compile both with gcc 4.6 and gcc trunk and every time it failed in the same way. I have to include a tgz instead of single source file because problem manifests itself only when I link several files.