From http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00349.html: Currently the thunks for a function are emitted from the frontend, exactly when the function itself is emitted (as RTL). The frontend does some analysis of thunks beforehand already, but I simply deactivated emission of thunks for my experiment. This needs to be done before IPA, either by making thunks a middle-end concept, or implementing alternate entry points for real Maybe it is possible to generate thunks eagerly as a first solution?
Created attachment 16722 [details] testcase
To reproduce: g++ -O2 -c thunk.C -flto-single -o thunk-lto.o g++ -O2 -c thunk.C -o thunk.o readelf -s thunk.o | grep Th 35: 0000000000000000 6 FUNC WEAK DEFAULT 19 _ZThn8_N1C1fEv readelf -s thunk-lto.o | grep Th 26: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ZThn8_N1C1fEv
This case can be easily fixed by setting targetm.asm_out.can_output_mi_thunk to NULL. This will introduce a performance regression. The only case that will be missing is varg functions. The llvm equivalent bug is http://llvm.org/bugs/show_bug.cgi?id=2861.
Confirmed.
Initial fix at http://gcc.gnu.org/ml/gcc-patches/2008-12/msg00953.html Keeping open as thunks with varargs are still broken.
*** Bug 41602 has been marked as a duplicate of this bug. ***
Another testcase in PR41602. SPEC CPU 2006 450.soplex is the only one in SPEC 2000/2006 to run into this issue.
*** Bug 41663 has been marked as a duplicate of this bug. ***
*** Bug 42009 has been marked as a duplicate of this bug. ***
There's a simple workaround for most cases, condition asm-thunks on !flag_write_lto. We'll do this if a proper implementation doesn't come up for 4.5.
Fixed by Honza.