I want to use c++ memory sanitizer(msan) on a code repo with llvm toolchain (libc++, libunwind, compiler-rt, clang ...). so the first thing i need to do is to build msan-instrumented libc++.
From MemorySanitizerLibcxxHowTo, i need to build libc++ with option -DLLVM_USE_SANITIZER=Memory
or -DLLVM_USE_SANITIZER=MemoryWithOrigin
.
From assembling a complete llvm toolchain, in the LLVM’s compiler runtime library
section
If using libc++ and/or libc++abi, you may need to configure them to use compiler-rt rather than libgcc_s by passing -DLIBCXX_USE_COMPILER_RT=YES and/or -DLIBCXXABI_USE_COMPILER_RT=YES to cmake. Otherwise, you may end up with both runtime libraries linked into your program (this is typically harmless, but wasteful).
Since i'm aiming for a full llvm toolchain, i think i should add -DLIBCXX_USE_COMPILER_RT=YES
and -DLIBCXXABI_USE_COMPILER_RT=YES
So i use the scripts below to download libcxx and libcxxabi and create expected dir layout and run the build.
#!/bin/bash
file_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
num_of_processors=$(cat /proc/cpuinfo | grep -c ^processor)
cd $file_dir
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
(cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx)
(cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi)
export CC=clang
export CXX=clang++
[ -d build ] && rm -rf build
mkdir -p build && cd build
cmake ../llvm -DCMAKE_INSTALL_PREFIX=.. \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_USE_SANITIZER=Memory \
-DLIBCXX_USE_COMPILER_RT=YES \
-DLIBCXXABI_USE_COMPILER_RT=YES
make install-libcxx install-libcxxabi -j$num_of_processors
The error i get is:
-- Performing Test LIBCXX_SUPPORTS_STD_COLON_CXX11_FLAG - Failed
CMake Error at projects/libcxx/CMakeLists.txt:538 (message):
C++11 or greater is required but the compiler does not support c++11
-- Configuring incomplete, errors occurred!
See also "~/libcxx-
msan/build/CMakeFiles/CMakeOutput.log".
See also "~/libcxx-
msan/build/CMakeFiles/CMakeError.log".
This erro only happens when -DLLVM_USE_SANITIZER=Memory
and -DLIBCXX_USE_COMPILER_RT=YES
both exists. Removing either of them will fix the problem.
Is there any way i can fix the problem and keep both options (msan and compiler rt)? Thanks in advance!