Skip to content

Setup Guide (CMake)

Yulei Sui edited this page Jun 23, 2017 · 30 revisions

Build LLVM and Clang (if you have already done both, just skip it and jump to step 5)

  1. Download LLVM-4.0.0, clang-4.0.0

  2. Unzip the LLVM and Clang source files

tar xf llvm-4.0.0.tar.xz
tar xf cfe-4.0.0.tar.xz
mv cfe-4.0.0.src llvm-4.0.0.src/tools/clang
  1. Create your target build folder and make
mkdir llvm-4.0.0.obj
cd llvm-4.0.0.obj
cmake ../llvm-4.0.0.src (or "cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../llvm-4.0.0.src" for debug version)
make -j8  
  1. Add paths for LLVM and Clang
export LLVM_SRC=your_path_to_llvm-4.0.0.src
export LLVM_OBJ=your_path_to_llvm-4.0.0.obj
export LLVM_DIR=your_path_to_llvm-4.0.0.obj
export PATH=$LLVM_DIR/bin:$PATH

Build SVF

  1. Download the SVF source code
git clone https://github.com/unsw-corg/SVF.git SVF
  1. Build SVF using cmake (Alternatively, you can also use build.sh to build release or debug version of SVF)
cd SVF
mkdir Release-build
cmake ../
make -j4

Debug build

cd SVF
mkdir Debug-build
cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../
make -j4
  1. Add paths for SVF
export PATH=$SVFHOME/Release-build/bin:$PATH
  1. Compile a single-file C program to a LLVM bitcode file or compile and link multiple C files using llvm-link. To compile a complicated real-world project you may wish to use LLVM gold plugin. See this guide to install it.
clang -c -emit-llvm -g example.c -o example.bc
clang -c -emit-llvm -g example1.c -o example1.bc
clang -c -emit-llvm -g example2.c -o example2.bc
llvm-link example1.bc example2.bc
  1. Analyze a llvm bit-code file using SVF