poniedziałek, 6 stycznia 2014

gcc link-time optimization

Link optimization can give impressive results (at least regarding executable size as presented below).
Here is output from simple program build. The program consists of 3 modules and 2 header files (6 functions in total).
  • Normal compilation (and linking), no optimization 'gcc mod1.c mod2.c mod3.c -o test'
    stripped executable size - 14480.
  • Normal compilation (and linking), optimized for size 'gcc mod1.c mod2.c mod3.c -o test -Os'
    stripped executable size - 10384.
  • LTO compilation (and linking), no optimization 'gcc mod1.c mod2.c mod3.c -o test -flto'
    stripped executable size - 10384.
  • LTO compilation (and linking), optimized for size 'gcc mod1.c mod2.c mod3.c -o test -flto -Os'
    stripped executable size - 6288.
GCC version used 4.8.2 (x86-64).

Please note that compilation time and output code speed was not taken into account in simple example consideration above.
Also for sure example is far too simple to treat it as meaningful case, please treat it just as remark of LTO possibilities.

References

  1. gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-flto-934
  2. gcc.gnu.org/wiki/summit2010?action=AttachFile&do=get&target=hubicka.pdf
  3. en.wikipedia.org/wiki/Link-time_optimization

Brak komentarzy:

Prześlij komentarz