[LLVMdev] LTO for smaller memory footprint for Clang

ankur deshwal a.s.deshwal at gmail.com
Wed May 23 21:34:46 PDT 2012


Hi all,

I was trying to use LTO facility of LLVM to reduce the footprint of
Clang itself. I build the ld-gold  and LLVMgold.so as described at [1]
and then set the environment as described too. However, had to add the
path for plugin manually as Clang was not able pass it to ld
automatically. Following is the setting I used before starting to
build (small foot Clang.

CXX=clang++ -flto
-Wl,--plugin=/home/wer/llvm-3.0/build_config_gold_release/Release/lib/LLVMgold.so
CFLAGS=-O3
CC=clang -flto -Wl,--plugin=/home/wer/llvm-3.0/build_config_gold_release/Release/lib/LLVMgold.so
RANLIB=/bin/true

Then configured and did the build for LLVM. While building Clang tool,
there may be large part of LLVM/Clang libraries which are not used by
Clang. So I was expecting appreciable reduction in size for Clang.
However memory savings were minimal.

Also, as explained in [2] in the topic "Compiler driver invokes link
time optimizer separately." , there are many cases when invoking Clang
with -flto may not remove the dead code. However I cannot figure out
how to build the Clang with first compiling all files to LLVM bit code
and then allow linker to treat them as compiled binaries which can be
linked together with LTO pass.

If this is possible by changes in Makefiles or build system, it can
help me a lot in removing some generic parts in Clang too to make a
less generic but lighter compiler tool.

Please help me with the same.

Thanks,
Ankur

[1] http://llvm.org/docs/GoldPlugin.html
[2] http://llvm.org/docs/LinkTimeOptimization.html




More information about the llvm-dev mailing list