http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53570
Bug #: 53570 Summary: Unused symbols are not removed for fully static targets (avr-gcc) Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: jwa...@gmail.com Using built-in specs. COLLECT_GCC=avr-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.7.0/lto-wrapper Target: avr Configured with: /build/src/gcc-4.7.0/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,c++ --disable-libssp --disable-nls --target=avr --with-as=/usr/bin/avr-as --with-ld=/usr/bin/avr-ld --with-gnu-as --with-gnu-ld Thread model: single gcc version 4.7.0 (GCC) This is a problem report for how the linker is not smart enough to remove unused functions, even with -Os. This makes it very hard to create libraries of functions where only some functions may be used in any particular binary. Note: "r" option to ar is passed in, so the linker should have all the symbol information it needs to make the determination. See the attached test program, especially the "lib.cpp" file. There is nothing in the C++ standard that requires the compiler or linker to include the not_called symbol, or the some_large_function symbol, when they are not used. On a small target like the AVR, including those symbols is too wasteful. To reproduce: - untar this archive - run ./make.sh - avr-objdump --disassemble main, and find the unused symbols still included