Skip to content

Commit

Permalink
[CMake] Add option for building w/ ThreadSanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ImmanuelHaffner committed Jan 27, 2024
1 parent 8c2a041 commit f2ef034
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ else()
set(USE_LIBCXX_default FALSE)
endif()

option(BUILD_SHARED_LIBS "Build mutable as a shared library" OFF)
option(ENABLE_SANITIZERS "Build mutable with address and UB sanitizers" ON)
option(ENABLE_SANITY_FIELDS "Build mutable with sanity fields enabled" ON)
option(USE_LIBCXX "Use libcxx (aka. libc++), LLVM's new implementation of the C++ standard library, instead of GNU's libstdc++" ${USE_LIBCXX_default})
option(USE_LLD "Use LLD, a linker from the LLVM project" ${HAS_LLD})
option(BUILD_SHARED_LIBS "Build mutable as a shared library" OFF)
option(ENABLE_SANITIZERS "Build mutable with address and UB sanitizers" ON)
option(ENABLE_THREAD_SANITIZER "Build mutable with thread sanitizer" OFF)
option(ENABLE_SANITY_FIELDS "Build mutable with sanity fields enabled" ON)
option(USE_LIBCXX "Use libcxx (aka. libc++), LLVM's new implementation of the C++ standard library, instead of GNU's libstdc++" ${USE_LIBCXX_default})
option(USE_LLD "Use LLD, a linker from the LLVM project" ${HAS_LLD})

# Enable backends
option(WITH_V8 "Build with the V8-based WebAssembly execution backend." ON)
option(WITH_V8 "Build with the V8-based WebAssembly execution backend." ON)

if(${BUILD_SHARED_LIBS})
set(LIB_TYPE SHARED)
Expand Down Expand Up @@ -159,10 +160,18 @@ if(${USE_LLD})
add_link_options("-fuse-ld=lld")
endif()

if (${ENABLE_SANITIZERS} AND ${ENABLE_THREAD_SANITIZER})
message(SEND_ERROR "ENABLE_SANITIZERS and ENABLE_THREAD_SANITIZER are mutually exclusive. Cannot combine UBSan and ASan with ThreadSan.")
endif()

if(${ENABLE_SANITIZERS})
message("[mutable] Compiling with address and UB sanitizers")
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr -fsanitize-link-c++-runtime)
add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr -fsanitize-link-c++-runtime)
elseif(${ENABLE_THREAD_SANITIZER})
message("[mutable] Compiling with thread sanitizer")
add_compile_options(-fsanitize=thread -fsanitize-link-c++-runtime)
add_link_options(-fsanitize=thread -fsanitize-link-c++-runtime)
endif()

if(${ENABLE_SANITY_FIELDS})
Expand Down

0 comments on commit f2ef034

Please sign in to comment.