Building LLVM in Debug mode takes more than 50 GB of disk space on my machine and then fails due to insufficient RAM (I have 32 GB). Am I missing a tip that could allow me to build on my 2021 laptop?
I just did:
cmake -S llvm -B build -G 'Unix Makefiles' -DLLVM_ENABLE_PROJECTS=clang\;clang-tools-extra -DCMAKE_BUILD_TYPE=Debug
Debug builds certainly take a lot of extra space; there is no easy way around that.
The first thing I would experiment with is the
LLVM_PARALLEL_LINK_JOBS CMake variable:
Linking tends to use the most RAM. You can try increasing it incrementally to see what works best for you.
Depending on what system that is, you might be using ld.bfd to link. That
always fails for me with a debug build of LLVM, even on systems with exorbitant amounts of ram. Try using LLD instead.
Thanks, I used
-DLLVM_PARALLEL_LINK_JOBS=1 and I build with clang, which is much faster. I no longer run out of RAM. But it looks like building with clang does not work in the end?
$ cmake -S llvm -B build -G 'Unix Makefiles' -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_RUNTIMES=compiler-rt -DCMAKE_BUILD_TYPE=Debug -DLLVM_PARALLEL_LINK_JOBS=1
[ 95%] Built target sanstats
[ 95%] Built target split-file
[ 95%] Built target verify-uselistorder
[ 97%] Built target yaml2obj
[ 97%] Built target builtins-clobber
[ 97%] Performing build step for 'builtins'
[ 0%] Building C object CMakeFiles/clang_rt.builtins-x86_64.dir/emutls.c.o
/home/olivier/other_projects/llvm-project/compiler-rt/lib/builtins/emutls.c:10:10: fatal error: 'stdlib.h' file not found
1 error generated.
make: *** [CMakeFiles/clang_rt.builtins-x86_64.dir/build.make:1672: CMakeFiles/clang_rt.builtins-x86_64.dir/emutls.c.o] Error 1
make: *** [CMakeFiles/Makefile2:416: CMakeFiles/clang_rt.builtins-x86_64.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
make: *** [runtimes/CMakeFiles/builtins.dir/build.make:86: runtimes/builtins-stamps/builtins-build] Error 2
make: *** [CMakeFiles/Makefile2:94178: runtimes/CMakeFiles/builtins.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
May 17, 2023, 12:45pm
@OlivierNicole If you don’t need an LLVM with all targets, this might also reduce the resources needed for a compilation.
Control which targets are enabled. For example you may only need to enable your native target with, for example, -DLLVM_TARGETS_TO_BUILD=X86.
Find more options here:
Building LLVM with CMake — LLVM 17.0.0git documentation
Thanks for your advice. I can almost build without OOM now. Looks like the rest of my build issues are 32-bit-related (and so unrelated to this thread).
May 22, 2023, 11:36am
I usually don’t build debug builds, because they are so big. And because I generally don’t need to debug LLVM builds. What I do instead, is that I make a release build with assertions enabled. This will catch most simple mistakes and still produces reasonably usable stack trace when hitting an assertion.
(The other suggestions are also a good idea,
especially using lld because it’s so much faster).