collect2: fatal error: ld terminated with signal 9 [Killed] clang

I was building clang on Ubuntu 18.04
https://clang.llvm.org/get_started.html#build

and got the error message
collect2: fatal error: ld terminated with signal 9 [Killed] clang

I have 8 GB ram
and increased the Linux swap to 40 GB but still same problem.

Full error message
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
tools/lto/CMakeFiles/LTO.dir/build.make:270: recipe for target ‘lib/libLTO.so.11git’ failed
make[2]: *** [lib/libLTO.so.11git] Error 1
make[2]: *** Deleting file ‘lib/libLTO.so.11git’
CMakeFiles/Makefile2:23538: recipe for target ‘tools/lto/CMakeFiles/LTO.dir/all’ failed
make[1]: *** [tools/lto/CMakeFiles/LTO.dir/all] Error 2
Makefile:151: recipe for target ‘all’ failed
make: *** [all] Error 2

The error message is typical of the ran-out-of-memory condition.

It appears you are using ld as your linker? (it is the default on Ubuntu) Our usual next suggestion is to use gold or lld instead, as they consume less memory. There are instructions on the web for making gold your default linker.

If that is not practical, the other suggestion is to reduce the number of threads (the -j option to make or ninja). If you are doing a Debug build, likely you would need to use -j1.

Best regards,

–paulr

There is currently a review going on to add mitigations to the
documentation: https://reviews.llvm.org/D75425

I asked the author to make one more simple change before I'd
accept/commit the change myself.

Michael

Thankyou,

I changed my linker to lld and it worked.

I have written the steps here if anyone wants
https://github.com/suyashsingh234/rtems-notes/blob/master/README.md