http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54933
Joey Ye <joey.ye at arm dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |joey.ye at arm dot com --- Comment #1 from Joey Ye <joey.ye at arm dot com> 2013-01-18 06:33:20 UTC --- This issue especially impacts "retarget", where library functions are "retargeted" to user implementations. Retarget is a common practice in bare-metal development but runs into "defined in discarded section" with LTO enabled. Here is the retarget case: # gcc version 4.8.0 20130115 (experimental) [trunk revision 195189] (GCC) # GNU ld (GNU Binutils) 2.23.51.20130111 $ cat main.c int main() { return puts("Hello"); } // it works if following line is enabled // __attribute__ ((used)) int _write(int c) { /* Do something */ return c; } $ cat lib-a.c int puts(const char * str) { return _write(*str); } $ gcc -flto -c -o lib-a.o lib-a.c $ ar rv liba.a lib-a.o r - lib-a.o $ gcc main.c liba.a -flto --entry=main -nostdlib -o l `_write' referenced in section `.text' of liba.a(lib-a.o): defined in discarded section `.text' of /tmp/ccwUUKiA.o (symbol from plugin) collect2: error: ld returned 1 exit status