This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: LTO branch merged into trunk - trunk remains CLOSED

On Sat, Oct 3, 2009 at 11:12 PM, Diego Novillo <> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]