Parallel build fails for [buffer overflow detected error]

Hi,
during building LLVM with clang enabled for x86-64 architecture
following the steps here:
http://clang.llvm.org/get_started.html

I tried make -j32
the execution goes well till 92% but, the process exits giving following error:

[ 92%] Building CXX object
tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/RegisterValue.cpp.o
*** buffer overflow detected ***: /usr/bin/ld terminated

cc1plus: out of memory allocating 39806 bytes after a total of 651264 bytes
virtual memory exhausted: Cannot allocate memory
/usr/bin/cmake: error while loading shared libraries:
libasn1.so.8/usr/bin/cmake: : failed to map segment from shared
objecterror while loading shared libraries: libasn1.so.8
: failed to map segment from shared object

cc1plus: out of memory allocating 2048 bytes after a total of 843776 bytes

cc1plus: out of memory allocating 2048 bytes after a total of 815104 bytes

cc1plus: out of memory allocating 8032 bytes after a total of 806912 bytes

cc1plus: out of memory allocating 8032 bytes after a total of 790528 bytes

cc1plus: out of memory allocating 17638 bytes after a total of 815104 bytes
tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/build.make:398:
recipe for target
'tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/Target.cpp.o'
failed
make[2]: *** [tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/Target.cpp.o]
Error 127
virtual memory exhausted: Cannot allocate memory
make[2]: *** Waiting for unfinished jobs....
tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/build.make:422:
recipe for target
'tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/Uops.cpp.o'
failed
make[2]: *** [tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/Uops.cpp.o]
Error 127
make[2]: fork: Cannot allocate memory

cc1plus: out of memory allocating 92461 bytes after a total of 815104 bytes
virtual memory exhausted: Cannot allocate memory
virtual memory exhausted: Cannot allocate memory
/usr/bin/ld: can not read symbols: Memory exhausted

When executed
make
only single processor
with no parallel build it's builds successfully.

Is this an issue with the parallel building of LLVM , I encoutered the
issue 2 times that too beyond 90%?

Thanks,
Sameeran Joshi

The error message tells that you ran out-of-memory.
Running with -j32 supposed a fairly large machine, do you have so many CPU cores? How much memory do you have?

The message also mentions /usr/bin/ld above, the GNU BFD linker which is the default on many distribution can be fairly memory heavy, especially when building with debug info.
Some tweak to your build can involve:

  • Use LLVM lld linker instead (or the gold linker) (-DLLVM_ENABLE_LLD=Y)
  • Build without debug info (-DCMAKE_BUILD_TYPE=Release)
  • Limit the number of parallel linking process (-DLLVM_PARALLEL_LINK_JOBS=X)