Skip to content

Instantly share code, notes, and snippets.

@johnmcfarlane
Created February 14, 2020 21:58
Show Gist options
  • Save johnmcfarlane/2dbdcc99892c9282dfea2fed9463bbf4 to your computer and use it in GitHub Desktop.
Save johnmcfarlane/2dbdcc99892c9282dfea2fed9463bbf4 to your computer and use it in GitHub Desktop.
Script for building MSan
set -exu pipeline
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
PROJECT_DIR="$SCRIPT_DIR"/llvm-project
mkdir -p build
cd build
cmake \
-GNinja \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Release \
"$PROJECT_DIR"/llvm
# -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;libcxx;libcxxabi;libunwind" \
ninja
cd ..
#* ``LLVM_TABLEGEN``, ``CLANG_TABLEGEN`` : Paths to llvm-tblgen and clang-tblgen
# for the host architecture. If you already have built clang for the host, you
# can point these variables to the executables in your build directory. If not,
# you will need to build the llvm-tblgen and clang-tblgen host targets at
# least.
mkdir -p build-libcxx-msan
cd build-libcxx-msan
cmake \
-GNinja \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_USE_SANITIZER=MemoryWithOrigins \
-DLLVM_TABLEGEN="${SCRIPT_DIR}/build/bin/llvm-tblgen" \
"$PROJECT_DIR"/llvm
# -DCMAKE_C_COMPILER=$PWD/../build/bin/clang \
# -DCMAKE_CXX_COMPILER=$PWD/../build/bin/clang++ \
# -DCMAKE_CROSSCOMPILING=ON \
# -DLLVM_ENABLE_PROJECTS="libcxx" \
# -DLLVM_ENABLE_LIBCXX=ON \
# -DLIBCXX_CXX_ABI=libcxxabi \
# -DLIBCXX_CXX=libcxx \
# -DLLVM_TOOLS_BINARY_DIR="${SCRIPT_DIR}/build/bin" \
# -DLLVM_ENABLE_LIBCXX=ON \
# -DLIBCXX_CXX_ABI=libcxxabi \
# -DLIBCXX_CXX=libcxx \
# -DLLVM_ENABLE_LIBCXX=ON \
#-DLLVM_INSTALL_PREFIX="${SCRIPT_DIR}/build" \
#-DCMAKE_CXX_FLAGS="-fsanitize=memory -fsanitize-memory-track-origins" \
# -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
ninja
cd ..
mkdir -p build-clang-msan
cd build-clang-msan
CLANG_BUILD=$PWD/../build
LIBCXX_BUILD=$PWD/../build-libcxx-msan
MSAN_LINK_FLAGS="-lc++abi -Wl,--rpath=$LIBCXX_BUILD/lib -L$LIBCXX_BUILD/lib"
MSAN_FLAGS="$MSAN_LINK_FLAGS -nostdinc++ \
-isystem $LIBCXX_BUILD/include \
-isystem $LIBCXX_BUILD/include/c++/v1 \
-fsanitize=memory \
-fsanitize-memory-track-origins \
-w"
cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$CLANG_BUILD/bin/clang \
-DCMAKE_C_FLAGS="$MSAN_FLAGS" \
-DCMAKE_CXX_COMPILER=$CLANG_BUILD/bin/clang++ \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_FLAGS="$MSAN_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS=$MSAN_LINK_FLAGS \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_PROJECTS="clang;compiler-rt;libcxx;libcxxabi;libunwind" \
-DLLVM_USE_SANITIZER=MemoryWithOrigins \
"$PROJECT_DIR"/llvm
ninja
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment