9

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?

anol
  • 8,264
  • 3
  • 34
  • 78

1 Answers1

6

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.

yugr
  • 19,769
  • 3
  • 51
  • 96
  • 2
    Is it something like this ```cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt" source-to-llvm -DCMAKE_BUILD_TYPE=Release``` ? – Jon marsh Sep 20 '19 at 12:17
  • Yes, your command will work if all three repos are in same folder, side-by-side. If you cloned `clang` and `compiler-rt` repos into `llvm/tools/clang` and `llvm/projects/compiler-rt` repo (as explained in ) you can do just `cmake -GNinja source-to-llvm -DCMAKE_BUILD_TYPE=Release`. – yugr Sep 20 '19 at 12:25