http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58592
Bug ID: 58592 Summary: -flto -fwhole-program caused undefined reference in g++ 4.7.3 Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: suihong.liang at gmail dot com Created attachment 30945 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30945&action=edit source code and makefiles Bug 41729 seems to be the same issue, however it was for 4.5.0 and it was closed. g++ 4.6.3 works fine, it compiles and runs. However g++ 4.7.3 gives linking error "undefined reference". Below shows the steps to reproduce. Thanks in advance! linkerror/lib# make clean; make rm -f *.o *.so g++ -flto -fwhole-program -Wall -Werror -pedantic -Wextra -Weffc++ -Waddress -Warray-bounds -Wno-builtin-macro-redefined -Wc++0x-compat -Wundef -std=c++0x -c -fPIC A.cpp g++ -flto -fwhole-program -Wall -Werror -pedantic -Wextra -Weffc++ -Waddress -Warray-bounds -Wno-builtin-macro-redefined -Wc++0x-compat -Wundef -std=c++0x -shared -o libself.so A.o linkerror/app# make clean; make rm -f *.o a.out g++ -flto -fwhole-program -Wall -Werror -Wextra -pedantic -Weffc++ -Waddress -Warray-bounds -Wno-builtin-macro-redefined -Wc++0x-compat -Wundef -std=c++0x -c main.cpp g++ -flto -fwhole-program -Wall -Werror -Wextra -pedantic -Weffc++ -Waddress -Warray-bounds -Wno-builtin-macro-redefined -Wc++0x-compat -Wundef -std=c++0x -o a.out main.o -L../lib -lself /tmp/ccWfzcXT.ltrans0.ltrans.o: In function `main': ccWfzcXT.ltrans0.o:(.text+0x1c): undefined reference to `A::A()' ccWfzcXT.ltrans0.o:(.text+0x31): undefined reference to `A::~A()' collect2: error: ld returned 1 exit status make: *** [all] Error 1 # g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1) # uname -a Linux sinit 3.8.0-31-generic #46-Ubuntu SMP Tue Sep 10 20:03:44 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux