While tuning is still in progress, results in the blog post show that
ThinLTO already performs well compared to LTO, in many cases matching
the performance improvement.
Current Status
==============
Clang/LLVM
----------
.._compiler:
The 3.9 release of clang includes ThinLTO support. However, ThinLTO
is under active development, and new features, improvements and bugfixes
are being added for the next release. For the latest ThinLTO support,
`build a recent version of clang and LLVM
<http://llvm.org/docs/CMake.html>`_.
Linkers
-------
.._linkers:
.._linker:
ThinLTO is currently supported for the following linkers:
-**gold (via the gold-plugin)**:
Similar to monolithic LTO, this requires using
a `gold linker configured with plugins enabled
<http://llvm.org/docs/GoldPlugin.html>`_.
-**ld64**:
Starting with `Xcode 8 <https://developer.apple.com/xcode/>`_.
Additionally, support is being added to the *lld* linker.
Usage
=====
Basic
-----
To utilize ThinLTO, simply add the -flto=thin option to compile and link. E.g.
..code-block:: console
% clang -flto=thin -O2 file1.c file2.c -c
% clang -flto=thin -O2 file1.o file2.o -o a.out
As mentioned earlier, by default the linkers will launch the ThinLTO backend
threads in parallel, passing the resulting native object files back to the
linker for the final native link. As such, the usage model the same as
non-LTO.
With gold, if you see an error during the link of the form:
..code-block:: console
/usr/bin/ld: error: /path/to/clang/bin/../lib/LLVMgold.so: could not load plugin library: /path/to/clang/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory
Then either gold was not configured with plugins enabled, or clang
was not built with ``-DLLVM_BINUTILS_INCDIR`` set properly. See