Friday, November 29, 2013

How to build and setup LLVM Scan Analyzer for Linaro Toolchain

Downloading and Installing Clang-Analyzer

Download LLVM, Clang, Clang-tools-extra and Compiler-RT from - http://llvm.org/releases/download.html.

  1. Extract the LLVM tarball. I'm going to use the variable LLVM to point to this directory going forward.
  2. Go to $LLVM/tools/src. Extract the clang release tarball. Rename the extracted directory as clang
  3. Go to $LLVM/tools/src/clang/tools/. Extract the clang-tools-extra and rename it as extra.
  4. Go to $LLVM/projects/. Extract the compiler-rt tarball and rename it as compiler-rt.
Note! - If you don't extract the clang, clang-tools-extra and compiler-rt in the respectively directories, it will not build them by default.

For more information look at http://clang.llvm.org/get_started.html. The instructions are for svn but they apply for the release tarballs as well.

Building and Installing Clang

Go to $LLVM directory and then you can configure, build and install clang.
 $ ./configure $ make $ make install
If you want to install clang in a specific directory then pass --prefix= to configure. Usually, I use /proj/staging/ to stage my builds and so, I usually build as ./configure --prefix=/proj/staging/llvm

Note! make install will not install scan-build and scan-view. They remain in $LLVM/tools/clang/tools/scan-build and $LLVM/tools/clang/tools/scan-view. So you will need to add these directories into your path.

Downloading and Installing Linaro Toolchain

Download Linaro Toolchain from - https://launchpad.net/linaro-toolchain-binaries/. Extract it to a directory of choice. I usually place it in /proj/staging/linaro-gcc. Next add the /proj/staging/linaro-gcc/bin directory to your PATH variable.

Running clang-analyzer with linaro toolchain

Now follow usual steps to cross compile your program. To enable scan-build make sure you run make via scan-build as shown in my previous post on running clang-analyzer.

No comments: