Bug#575449: -O* needs to be passed to linker too
In fact -O* flags need to be passed to the linker too for LTO to do any optimizations at all. 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. Also -fuser-linker-plugin needs to be passed on by libtool. P.S.: 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. Best regards, --Edwin -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#575449: -O* needs to be passed to linker too
* 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. 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. Also -fuser-linker-plugin needs to be passed on by libtool. Yes, I gues libtool should support -fuse-linker-plugin too. 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. If you mix several languages in your package, you may need to add -flto to all per-language flags. Cheers, Ralf -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#575449: -O* needs to be passed to linker too
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 debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#575449: -O* needs to be passed to linker too
* Török Edwin wrote on Fri, Mar 26, 2010 at 08:45:44PM CET: 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 Yes. 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. Well, we simply cannot pass all of -f* through. -fPIC should be added by libtool itself. 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? Yes. Also -fuser-linker-plugin needs to be passed on by libtool. Yes, I gues libtool should support -fuse-linker-plugin too. Ok. BTW I'm using a simple hack for now, I set new_inherited_linker_flags=-flto -O2, and that allows me to test LTO. You should be able to use ./configure CC='gcc -flto -O2' too. Cheers, Ralf -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#575449: -O* needs to be passed to linker too
On 2010-03-26 22:21, Ralf Wildenhues wrote: * Török Edwin wrote on Fri, Mar 26, 2010 at 08:45:44PM CET: You should be able to use ./configure CC='gcc -flto -O2' too. Ah I've completely forgotten about that possibility, I used that when testing LLVM's LTO support (http://llvm.org/docs/GoldPlugin.html). Which uses yet another flag .. -use-gold-plugin. Best regards, --Edwin -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org