在 clang 上启用消毒剂

Enabling Sanitizers on clang

我从源代码构建了 clang-4.0。当我尝试使用 "Undefined Behaviour" 消毒剂时,我得到了以下输出。

$ clang -fsanitize=undefined parallel_big_loop.c
/usr/bin/ld: cannot find /home/user/Software/polly/llvm_build/bin/../lib/clang/4.0.0/lib/linux/libclang_rt.ubsan_standalone-x86_64.a: No such file or directory
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

使用 Ubuntu 14.04.5 amd64,linux 4.4.0-31-generic。

如何指示 CMake 在构建期间包含它?

根据 Clang 官方指南:http://clang.llvm.org/get_started.html

svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../..
cd llvm/projects
# This repository is responsible for sanitizers
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ../..
# in-tree build is not supported
mkdir build
cd build
cmake -G"Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/clang/ ../llvm/
ninja

你当然可以使用 make 而不是 ninja,如果你不喜欢 svn,你可以使用这个 Github 存储库 https://github.com/llvm-mirror