Install LLVM Gold Plugin on Ubuntu - SVF-tools/SVF GitHub Wiki
Install Gold Plugin on Ubuntu
LLVM Gold Plugin is a link-time optimizer can generate whole program bit code file for interprocedural program analysis. Its official site can be found here.
The following installation guide has been tested on Ubuntu 14.04, but it should work on most Linux-based systems.
- Library requirements
sudo apt-get install linux-headers-$(uname -r) git g++ gcc cmake bash csh gawk automake libtool bison flex libncurses5-dev
Check 'makeinfo -v'. If 'makeinfo' does not exist
sudo apt-get install apt-file texinfo texi2html
sudo apt-file update
sudo apt-file search makeinfo
- Download binutils source code
cd ~
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils
- Build binutils
mkdir build
cd build
../binutils/configure --enable-gold --enable-plugins --disable-werror
make
- Download LLVM-6.0.0, clang-6.0.0. Unzip the LLVM and Clang source files
cd ~
tar xf llvm-6.0.0.tar.xz
tar xf cfe-6.0.0.tar.xz
mv cfe-6.0.0.src llvm-6.0.0.src/tools/clang
- Modify gold-plugin.cpp to make clang generate bitcode
vi llvm-6.0.0.src/tools/gold/gold-plugin.cpp
add a new line between line 257 and 258: "TheOutputType = OT_SAVE_TEMPS;"
- Build LLVM with gold-plugin
mkdir llvm-6.0.0.obj
cd llvm-6.0.0.obj
cmake ../llvm-6.0.0.src -DLLVM_BINUTILS_INCDIR="PATH_TO_binutils_SRC/include"
(or "cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../llvm-6.0.0.src -DLLVM_BINUTILS_INCDIR="PATH_TO_binutils_SRC/include"" for debug version)
make -j8
- Backup ar, nm, ld and ranlib
cd ~
mkdir backup
cd /usr/bin/
cp ar ~/backup/
cp nm ~/backup/
cp ld ~/backup/
cp ranlib ~/backup/
- Replace ar, nm, ld and ranlib
cd /usr/bin/
sudo cp ~/build/binutils/ar ./
sudo rm nm
sudo cp ~/build/binutils/nm-new ./nm
sudo cp ~/build/binutils/ranlib ./
sudo cp ~/build/gold/ld-new ./ld
- install LLVMgold.so to /usr/lib/bfd-plugins
cd /usr/lib
sudo mkdir bfd-plugins
cd bfd-plugins
sudo cp ~/llvm-6.0.0.obj/lib/LLVMgold.so ./
sudo cp ~/llvm-6.0.0.obj/lib/libLTO.* ./
- export environment variables
export CC="~/llvm-6.0.0.obj/bin/clang -flto -g"
export CXX="~/llvm-6.0.0.obj/bin/clang++ -flto -g"
export RANLIB=/bin/true