On 2010-03-26 21:11, Ralf Wildenhues wrote: > * Török Edwin wrote on Fri, Mar 26, 2010 at 12:33:14PM CET: >> In fact -O* flags need to be passed to the linker too for LTO to do any >> optimizations at all. > > Yup.
There's also a caveat (or rather compiler bug): using one -O level when compiling, and another when linking doesn't really work: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42402 > >> So if I call gcc -O2 -flto x.o y.o, libtool will need to pass both -O2 >> and -flto. And of course any -f* -m* flags that affect code generation. > > -m* is passed through by libtool. Ok, but I think -f* should be passed too, they affect code generation as well, especially -fPIC. Apparently even if you compile ALL the individual files with -fPIC, you need to pass -fPIC on the link command-line too, otherwise you get a failure when building shared libs (that relocation error message that tells you to use -fPIC). I consider this rather a gcc bug (it should know that -shared needs -fPIC for -flto), see here #575451. Or do you think libtool should handle this? > >> Also -fuser-linker-plugin needs to be passed on by libtool. > > Yes, I gues libtool should support -fuse-linker-plugin too. Ok. > >> In fact for LTO I think it'd make sense to pass all of CFLAGS/CXXFLAGS >> to the linker, since they affect code generation at link time now. >> Or document the fact that you need to export LDFLAGS="$CFLAGS" if you >> want LTO to work. > > When you use Automake to create your makefiles, then $(CFLAGS) is passed > on the C linker command line already. Using LDFLAGS=$CFLAGS will not > buy you anything. This issue is purely about which flags libtool passes > through to the compiler driver. Yeah nevermind LDFLAGS, I got confused by libtool stripping the flags. BTW I'm using a simple hack for now, I set new_inherited_linker_flags="-flto -O2", and that allows me to test LTO. > > If you mix several languages in your package, you may need to add -flto > to all per-language flags. Yes. Best regards, --Edwin -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]

