This document explains how to properly configure and run sanitizers (AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer) with the cashd project.
Corresponding suppression files are located in the sanitizers/suppressions directory.
[!CAUTION] Do not mix Address and Thread sanitizers - they are incompatible. Also, we don’t yet support MSVC sanitizers, so this is only for Clang/GCC builds.
Follow the same instructions as mentioned in BUILD.md but with the following changes:
SANITIZERS environment variable before calling conan install. Only set it once.
Example: export SANITIZERS=address,undefinedbehaviorUse --profile:all sanitizers with Conan to build dependencies with sanitizer instrumentation.
[!NOTE] Building with sanitizer-instrumented dependencies is slower but produces fewer false positives.
ASAN_OPTIONS, LSAN_OPTIONS, UBSAN_OPTIONS and TSAN_OPTIONS environment variables to configure sanitizer behavior when running executables. More details below.cd /path/to/cashd
rm -rf .build
mkdir .build
cd .build
The SANITIZERS environment variable is used during conan install command.
SANITIZERS=address,undefinedbehavior conan install .. --output-folder . --build missing --settings build_type=Debug --profile:all sanitizers
Proceed with the rest of the build instructions as mentioned in BUILD.md.
IMPORTANT: ASAN with Boost produces many false positives. Use these options:
export ASAN_OPTIONS="include=sanitizers/suppressions/runtime-asan-options.txt:suppressions=sanitizers/suppressions/asan.supp"
export LSAN_OPTIONS="include=sanitizers/suppressions/runtime-lsan-options.txt:suppressions=sanitizers/suppressions/lsan.supp"
# Run tests
./cashd --unittest --unittest-jobs=5
Why detect_container_overflow=0?
AgedUnorderedContainer) trigger false positivesWorkers.cpp) confuses ASAN’s stack trackingexport TSAN_OPTIONS="include=sanitizers/suppressions/runtime-tsan-options.txt:suppressions=sanitizers/suppressions/tsan.supp"
# Run tests
./cashd --unittest --unittest-jobs=5
More details here.
LSan is automatically enabled with ASAN. To disable it:
export ASAN_OPTIONS="detect_leaks=0"
More details here.
export UBSAN_OPTIONS="include=sanitizers/suppressions/runtime-ubsan-options.txt:suppressions=sanitizers/suppressions/ubsan.supp"
# Run tests
./cashd --unittest --unittest-jobs=5
More details here.
[!NOTE] Attached files contain more details.
asan.suppinterceptor_name:<pattern> where pattern matches file names. Supported suppression types are:
lsan.suppleak:<pattern> where pattern matches function/file namesubsan.supp<error_type>:<pattern> (e.g., unsigned-integer-overflow:protobuf)tsan.supprace:<pattern> where pattern matches function/file namessanitizer-ignorelist.txt-fsanitize-ignorelist=absolute/path/to/sanitizer-ignorelist.txt<level>:<pattern> (e.g., src:Workers.cpp)These warnings appear when using Boost context switching and are harmless. They indicate potential false positives.
If you see undefined symbols like ___tsan_atomic_load when building with ASAN:
Problem: Dependencies were built with a different sanitizer than the main project.
Solution: Rebuild everything with the same sanitizer:
rm -rf .build
# Then follow the build instructions above
Then review the log files: asan.log.*, ubsan.log.*, tsan.log.*