Llvm+clang Add LTO (Link time optimization) Support
binutils
LTO requires that the current system binutils can use the Gold linker or LD.BFD to support LTO, binutils version >= 2.21.511.0.2 via plugin. Ld-plugin can be used to check whether the current system supports plugin.
RHEL/CENTOS6 system comes with Binutils does not support plugin.
$ ld-v
GNU ld version 2.20.51.0.2-5.47.el6_9.1 20100205
$ ld-plugin
ld:unrecognized option '-plugin '
l D:use the--HELP option for usage information
Can be supported after installing DEVTOOLSET-7.
$ ld-v
GNU ld version 2.28-8.el6
$ ld-plugin
ld:-plugin:missing argument
ld:use the--HELP option for Usage information
can also be installed to the system by recompiling the Binutils to provide support
$ git clone--depth 1 git://sourceware.org/git/binutils-gdb.git binutils
$ mkdir Build
$ cd Build
$: /binutils/configure--disable-werror # LD.BFD includes plugin support by default
$ make All-ld
Llvm-clang
Full compile Llvm-clang
Reconfigure Llvm-clang run CMake add-dllvm_binutils_incdir=/path/to/binutils/include specify include plugin-api.h directory parameter, make Install/strip is Can. Llvmgold plugin
Install Binutils to the $PREFIX directory.
CMake ...-dllvm_binutils_incdir=/path/to/binutils/include. /llvm_release_500/
make-c tools/gold/
Copy/lib/llvmgold.so to $PREFIX/lib/bfd-plugins/ Usage
Clang-flto xxx.c-o XXX
Autotool tool chain configuration is used.
Export cc= "$PREFIX/bin/clang-flto"
export cxx= "$PREFIX/bin/clang++-flto"
export ar= "$PREFIX/bin/ar"
Export nm= "$PREFIX/bin/nm"
export ranlib=/bin/true #ranlib is isn't needed, and doesn ' t support. bc files in. A
Reference
Gold linker
GCC LTO
Liblto
Goldplugin