When 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).