Created attachment 5155 [details] Example I think that it would be good to give a warning in such situation...
Created attachment 5156 [details] A patch
Fixed by commit 0ca9456fe1b8f0cf0793ca5e64317e658b18799c on hjl/lto-mixed branch.
I checked in a different fix with commit baf9b44566e088687f28f9fe476122876c1d2f4d. Now you will get /usr/gcc-4.6/bin/gcc -B./ -O -flto -c -o bar.o bar.c ar cr libbar.a bar.o /usr/gcc-4.6/bin/gcc -B./ -O -flto -fuse-linker-plugin -o prog1 -L. main.c -lbar foo.c /tmp/cc9q7ek9.ltrans0.ltrans.o: In function `main': cc9q7ek9.ltrans0.o:(.text+0x5): undefined reference to `bar' collect2: ld returned 1 exit status make: *** [prog1] Error 1
Works in 2.23 and tracked by "LTO 12a"/"LTO 12b" tests in ld-plugin.