Skip to content


Kostya Serebryany edited this page Jan 5, 2016 · 4 revisions

AddressSanitizer is fully integrated with the LLVM source tree.

Checkout AddressSanitizer sources

# cd somewhere
# Get llvm, clang and compiler-rt
svn co llvm
cd llvm
R=$(svn info | grep Revision: | awk '{print $2}')
(cd tools && svn co -r $R clang)
(cd projects && svn co -r $R compiler-rt)

To switch your checkout to read-write mode:

cd llvm
svn switch --relocate https://$
(cd tools && svn switch --relocate https://$ clang)
(cd projects && svn switch --relocate https://$ compiler-rt)

Host compiler

In order to build fresh Clang you need some other compiler (e.g. GCC or an older version of Clang). Since January 2014 Clang will not build with old compilers (at least GCC 4.7 is required), so on older systems you may need to install a newer compiler separately. Follow these instructions to use new GCC as your host compiler.

Building AddressSanitizer with CMake (LLVM 3.2 or later)

  • Download and install CMake (you'll need at least CMake 2.8.8).
  • Get llvm, clang and compiler-rt sources (see above).
  • Make sure you have a modern C++ toolchain (see above).
  • Set configuration and build LLVM.
mkdir llvm_cmake_build && cd llvm_cmake_build
# Choose the host compiler
# Choose CMAKE_BUILD_TYPE {Debug, Release}
# Set LLVM_TARGETS_TO_BUILD to X86 to speed up the build
  • Now you can build and test LLVM code:
make -j12 # build everything
make check-all -j12 # build and run all tests (llvm+clang+ASan)
make check-sanitizer -j12 # build and run sanitizer_common tests
make check-asan -j12 # build and run ASan unit and output tests

Note that dynamic runtime tests are not included into check-asan or check-all on platforms where static runtime is default; to run them, you'll need to manually

make -j12 check-asan-dynamic

To build only ASan runtime library:

# On Linux:
make -j12 asan
# The runtime libraries are built at:
# llvm_cmake_build/lib/clang/<llvm_version>/lib/{linux,darwin}/

To build/run only ASan unit tests:

make -j12 AsanUnitTests
cd projects/compiler-rt/lib/asan/tests

To re-run a single ASan lit-style output test make sure you've built Clang and run:

# Make sure clang and llvm tools are in your PATH.
export PATH="/path/to/llvm_cmake_build/bin:$PATH"
# Run a specific output test.
cd llvm_cmake_build
bin/llvm-lit projects/compiler-rt/test/asan/64bitConfig/TestCases/
  • Visit LLVM CMake guide to see the ways you can customize your LLVM/Clang/ASan build. For example, you can build LLVM/Clang with ASan-ified Clang:
mkdir llvm_cmake_build_asan
cd llvm_cmake_build_asan
export CC=clang
export CXX=clang++
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Address /path/to/llvm/checkout

To run lint:



If you want to get even faster incremental builds, use ninja:


The Chromium team periodically bakes fresh LLVM/Clang binaries, which include AddressSanitizer support. Simply execute the following:

git clone --depth 1
# Now use ../third_party/llvm-build/Release+Asserts/bin/clang++
Clone this wiki locally
You can’t perform that action at this time.