What is GCC lto wrapper?

Mihalko picture Mihalko · Nov 6, 2013 · Viewed 9.2k times · Source

I am using buildroot to prepare images for embedded system. I want to export buildroots internal cross compiler so others can use same version, After command checking GCC version: arm-linux-gcc -vI see configured COLLECT_LTO_WRAPPER to static location on my HDD

 COLLECT_LTO_WRAPPER=/home/user/arm/buildroot/output/host/usr/libexec/gcc/arm-unknown-linux-uclibcgnueabi/4.7.1/lto-wrapper

It will not be correct on another system.

I was only able to find that LTO means Link Time Optimization. Can you please explain what is lto wrapper used for and when is needed?

Answer

user2284570 picture user2284570 · Dec 8, 2013

‫Whe‬n you compile an executable, gcc will optimize and merge same constants only for the current file. Normally, it can't analyze the whole program since the .o files are linked with ld.

‭‫That's the purpose of Interprocedural optimization: Compile the whole executable as if it was a single source file, allowing to make the code more static.

There's a problem with this, LD can't really recognize the exported GIMPLES.
‫‫For this purpose ld use the lto plugin(liblto_plugin.so.0.0.0) which calls make or thelto-wrapper directly which calls lto1 where each lto1 launch is responsible for producing a 'partition' (see the -flto-partition option and the lto-partitions parameter in gcc’s documentation).