http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53808
Bug #: 53808 Summary: Undefined symbol when building a library with lto Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto AssignedTo: unassig...@gcc.gnu.org ReportedBy: rafael.espind...@gmail.com The gcc lto plugin can drop a symbol that another translation unit has an undefined reference to. This might also be a bug in gcc (>= 4.6, with and without lto) producing an undefined reference, the ABI is not very clear. $ cat test.h struct foo { virtual ~foo(); }; struct bar : public foo { virtual void zed(); }; $ cat def.cpp #include "test.h" void bar::zed() { } $ cat undef.cpp #include "test.h" void f() { foo *x(new bar); delete x; } Compile with: $ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ -c undef.cpp -o undef.o -O3 -fPIC $ nm undef.o | grep D0 U _ZN3barD0Ev $ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ -c def.cpp -o def.o -O3 -flto -fPIC $ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ def.o -o def.so -shared -fuse-linker-plugin $ readelf -sDW def.so | grep bar 12 7: 0000000000000931 5 OBJECT WEAK DEFAULT 13 _ZTS3bar 11 10: 0000000000001ca0 40 OBJECT WEAK DEFAULT 24 _ZTV3bar 13 14: 0000000000001cd0 24 OBJECT WEAK DEFAULT 24 _ZTI3bar 8 15: 00000000000008b0 10 FUNC GLOBAL DEFAULT 11 _ZN3bar3zedEv Note that we have the vtable, but no the destructor. $ g++ -shared -o foo.so undef.o def.so -Wl,-z,defs undef.o:undef.cpp:function f(): error: undefined reference to 'bar::~bar()'