This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: LTO branch merged into trunk - trunk remains CLOSED
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Diego Novillo <dnovillo at google dot com>
- Cc: gcc at gcc dot gnu dot org, fortran at gcc dot gnu dot org, java at gcc dot gnu dot org
- Date: Sat, 3 Oct 2009 23:32:54 +0200
- Subject: Re: LTO branch merged into trunk - trunk remains CLOSED
- References: <20091003211217.GA22755@google.com>
On Sat, Oct 3, 2009 at 11:12 PM, Diego Novillo <dnovillo@google.com> wrote:
> The LTO branch has been merged into trunk at revision 152434.
...
> To enable LTO, simply add the flag '-flto' to both compile and
> link commands. ?It doesn't really matter whether you compile and
> link in separate invocations or a single one. ?All that matters
> is that -flto should be in both places:
>
> ? ? ? ?$ gcc -flto -O2 -o f f1.c f2.c
>
> ? ? ? ? ? ? ? ? ? ? ? ?or
>
> ? ? ? ?$ gcc -flto -c f1.c
> ? ? ? ?$ gcc -flto -c f2.c
> ? ? ? ?$ gcc -o f -flto -O2 f1.o f2.o
Remember though that options specified at compile time are _not_ automatically
enabled at link time! Thus the 2nd example above would perform no initial
optimization (effectively skipping all early optimizations until the IPA passes)
while enabling optimization (starting with IPA passes and then remaining
optimization passes) at link time. Thus the better canonical example would
have been
$ gcc -O2 -flto -c f1.c
$ gcc -O2 -flto -c f2.c
$ gcc -o f -flto -O2 f1.o f2.o
where in particular enabling -fwhole-program is what should enable extra
optimization (well, if you do actually link a final binary).
Note that one missing feature is picking up entries from static library
archives at link time. To not end up with unused LTO sections from
static libraries in the final binary you need to have recent enough binutils
or strip them manually.
Richard.