-
-
Notifications
You must be signed in to change notification settings - Fork 63
Building TinyUSDZ with Sanitizers
Specify
-DSANITIZE_ADDRESS=1
to cmake args
Specify
-DSANITIZE_UNDEFINED=1
to cmake args
Specify
-DSANITIZE_THREAD=1
to cmake args
Building TinyUSDZ with MSAN(MemorySanitizer) support requires extra work. We need to compile all source code with MSAN support, including C++ STL(libcxx).
- clang(17 or later required. Otherwise libcxx cannot be compiled(at least for llvm v19.1.0))
- llvm runtime source codes(libcxx, libcxxabi, libunwind)
- 19.1.0
- https://stackoverflow.com/questions/56454026/building-libc-with-memorysanitizer-instrumentation-fails-due-to-memorysanitize
- https://reviews.llvm.org/D112724
Install clang. In ubuntu you may be able to install clang by
$ sudo apt install clang-18 libclang-18-dev
Handy build script is provided: https://github.com/lighttransport/tinyusdz/blob/dev/scripts/build_msan_libcxx.sh
$ cd <tinyusdz-repo>
$ ./scripts/build_libcxx_msan.sh
Checkout llvm-project source code(version 19.1.0)
git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-19.1.0
Bootstrap libcxx, libcxxabi and libunwind with cmake
(Specify which runtime module to build through LLVM_ENABLE_RUNTIMES)
CXX=clang++-18 CC=clang-18 cmake -G Ninja -B ${build_dir} -S llvm-project/runtimes/ \
-DCMAKE_INSTALL_PREFIX=${dist_dir} \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLLVM_USE_SANITIZER=MemoryFromOrigins \
-DCMAKE_BUILD_TYPE=Release
Then build & install libcxx with Ninja.
See https://github.com/lighttransport/tinyusdz/blob/dev/scripts/bootstrap-cmake-linux-msan.sh for the script.
Set CXX and CC as follows:
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 CMAKE_CXX_FLAGS to specify msan sanitizer(-DSANITIZER_MEMORY=1 does not work) and set include path to msan-enabled libcxx
-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++
And use CMAKE_EXE_LINKER_FLAGS to specify lib path and libraries to be linked.
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath,${LIBCXX_MSAN_DIR}/lib -lc++ -lc++abi -lunwind "
Also set -DTINYUSDZ_MSAN=1 recommended.