How to compile Clang with sanitizers

Viewed 2931

I just compiled Clang using CMake and then tried running a sanitizer (with clang -fsanitize=address), but got:

/usr/bin/ld: cannot find <CLANG_DIR>/9.0.0/lib/linux/libclang_rt.asan-x86_64.a:
  No such file or directory

I then went to the "How to build" Address sanitizer page, but it simply says:

Build LLVM/Clang with CMake.

Which takes me back to the first page. The only mention of "sanitize" anywhere within the page is:

LLVM_USE_SANITIZER:STRING

Define the sanitizer used to build LLVM binaries and tests. Possible values are Address, Memory, MemoryWithOrigins, Undefined, Thread, and Address;Undefined. Defaults to empty string.

But this is related to using sanitizers to build LLVM itself, not to making them available after the build.

So, how can I actually build the sanitizers and make them available for Clang?

1 Answers

Runtime library which implements Asan callbacks is in compiler-rt repo so you'll need to build that as well. One easy way to achieve this is to clone compiler-rt to llvm/projects before running cmake.

Related