Skip to content

Commit

Permalink
Fix msan build
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Dec 29, 2024
1 parent 62561ac commit 367e3b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 9 additions & 5 deletions scripts/bootstrap-cmake-linux-msan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ mkdir ${builddir}


# path to libcxx(built with msan)
LIBCXX_MSAN_DIR=${curdir}/libcxx_msan/dist
LIBCXX_MSAN_DIR=${curdir}/llvm_project_msan_dist

# Specify sanitizer flag directly to CXX compiler

export CXX="clang++-18 -fsanitize=memory"
export CC="clang-18 -fsanitize=memory"
export CXX="clang++-18 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer "
export CC="clang-18 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer "

#
# Use isystem for custom built libcxx to suppress clang's warnings.
#

cd ${builddir} && cmake \
-DCMAKE_TOOLCHAIN_FILE=cmake/lld-linux.toolchain.cmake \
-DCMAKE_CXX_FLAGS="-fsanitize=memory -I${LIBCXX_MSAN_DIR}/include -I${LIBCXX_MSAN_DIR}/include/c++/v1 -stdlib=libc++ " \
-DCMAKE_EXE_LINKER_FLAGS="-L${LIBCXX_MSAN_DIR}/lib -lc++abi " \
-DCMAKE_CXX_FLAGS="-fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins -isystem ${LIBCXX_MSAN_DIR}/include -isystem ${LIBCXX_MSAN_DIR}/include/c++/v1 -nostdinc++ " \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath,${LIBCXX_MSAN_DIR}/lib -lc++ -lc++abi -lunwind " \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_VERBOSE_MAKEFILE=1 \
-DTINYUSDZ_WITH_OPENSUBDIV=0 \
Expand Down
16 changes: 12 additions & 4 deletions scripts/build_msan_libcxx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-19.1.0

build_dir=libcxx_msan
dist_dir=llvm_project_msan_dist
libcxx_build_dir=libcxx_msan
libc_build_dir=libc_msan

rm -rf ${build_dir}
mkdir -p ${build_dir}
Expand All @@ -12,7 +14,13 @@ mkdir -p ${build_dir}
# Assume clang(17 or later required) is installed on your system.
#

CXX=clang++-18 CC=clang-18 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=${build_dir}/dist -B ${build_dir} -S llvm-project/runtimes/ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_USE_SANITIZER=Memory -DCMAKE_BUILD_TYPE=Release && \
ninja -C ${build_dir} && \
ninja -C ${build_dir} install \
CXX=clang++-18 CC=clang-18 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=${dist_dir} -B ${libcxx_build_dir} -S llvm-project/runtimes/ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_BUILD_TYPE=Release && \
ninja -C ${libcxx_build_dir} && \
ninja -C ${libcxx_build_dir} install

#
# TODO: build libc without msan
#
#CXX=clang++-18 CC=clang-18 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=${dist_dir} -B ${libc_build_dir} -S llvm-project/runtimes/ -DLLVM_ENABLE_RUNTIMES="libc" -DCMAKE_BUILD_TYPE=Release && \
#ninja -C ${libc_build_dir} && \
#ninja -C ${libc_build_dir} install

0 comments on commit 367e3b8

Please sign in to comment.