How to compile and install LLVM Gold plugin (LLVMgold.so) on Linux

Problem:

You want to use the LLVM Gold linker plugin but LLVMgold.so can’t be found.

Solution:

You should compile and install the LLVM gold plugin by yourself.

This guide has been tested on Ubuntu 12.04 and Ubuntu 12.10, but it should work on most Linux-based systems provided that you replace the  package-manager-specific commands appropriately.

A more unspecific and overcomplex, but official guide can be found here.

First, install the Gold linker (replacement for GNU ld) and the binutils dev package.

sudo apt-get install binutils-gold binutils-dev

After that, download the LLVM sourcecode from the LLVM releases website. Alternatively, get the latest version from SVN.

Unpack it and configure & compile it using these commands:

./configure --with-binutils-include=/usr/include
make -j8 ENABLE_OPTIMIZED=1

After that, you can find LLVMgold.so at ./Release+Asserts/lib/LLVMgold.so. Run

sudo cp ./Release+Asserts/lib/LLVMgold.so /usr/local/lib/

to put it in the directory where clang/clang++ tries to find it.