Assuming this is possible, could someone tell me, how I have to configure the cmake build to create a "pure" llvm toolchain on ubuntu-16.04 consisting of
- clang
- lld
- libc++
- libc++abi
- libunwind (llvm)
- compiler-rt
- any other pieces that might be relevant and are "production ready"
The resulting compiler should
- be as fast as possible (optimizations turned on, no unnecessary asserts or other checks in the compiler binary itself)
- be installed in a separate, local directory (lets call it
<llvm_install>
) - not have dependencies to the llvm tolchain provided by packet manager
- use libc++, libc++abi etc by default.
- support the sanitizers (ubsan, address, memory, thread) (which probably means that I have to compile libc++ a second time)
So far I have cloned
- llvm from
http://llvm.org/git/llvm.git
into<llvm_root>
- clang from
http://llvm.org/git/clang.git
into<llvm_root>/tools/clang
- lld from
http://llvm.org/git/lld.git
into<llvm_root>/tools/lld
- compiler-rt, libcxx, libcxxabi, libunwind from
http://llvm.org/git/<project_name>
into<llvm_root>/projects/<project_name>
Then run ccmake in a separate directory - I have tried various settings, but as soon as I try anything more fancy beyond turning optimizations on, I almost always get some sort of build error. Unfortunately, I have yet to find a way to export my changes from ccmake otherwise I'd give you an example with the settings and according error, but I'm more interested in a best practice than a fix to my test configs anyway.
Bonus points: By default, this should build with the default g++ toolchain, but I'd also be interested in a two stage build if that improves the performance of the final toolchain (e.g. by using LTO).
Btw.: The whole Idea came from watching chandler's talk
Pacific++ 2017: Chandler Carruth "LLVM: A Modern, Open C++ Toolchain"
My usual procedure is to build a small enough LLVM/Clang so that I have something working with
libc++
andlibc++abi
. I guess you can the system-provided LLVM, but I haven't tried it. For this step, what you have checked-out is probably enough. A sample script for this:Having the aforementioned
clang
in yourPATH
environment variable, you can use the below build script again and adjust based on your needs (sanitizers, etc). Apart from the main documentation page on the subject, poking around theCMakeLists.txt
of each respective tool is also illuminating and helps adjust the build process from version to version.A note on performance, I haven't watched that talk yet, but my motivation behind this 2 step build was to have a toolchain that I can easily relocate between systems since the minimal system dependence that matters is
libc
.Lastly, relevant to the above procedure is this older question of mine, which still bugs me. If you have any insight on this, please don't hesitate.
PS: Scripts have been tested with LLVM 3.7 through 3.9 and current trunk 6.0.0.
Update: I've also applied these suggestions, and there is marked improvement when using the
gold
linker instead ofld
. LTO is also a boost.