From 4c07bf5aaed99077076d29a4d9e3aeb8a27e9e2d Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Thu, 11 Feb 2021 00:38:31 +0100 Subject: [PATCH] Build: Add ThreadSanitizer (TSan) support Enable it by setting -DTSAN=1 This setting is mutually exclusive with -DASAN --- CMakeLists.txt | 5 +++++ cmake/compiler/clang/settings.cmake | 12 ++++++++++++ cmake/compiler/gcc/settings.cmake | 12 ++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ffde23ac..6df0d2b81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,11 @@ mark_as_advanced( option(BUILD_TEST_SUITE "Build the test suite" 0) option(BUILD_MAN "Build man pages" 1) option(ASAN "DEBUGGING: Build with AddressSanitizer (ASan) support" 0) +option(TSAN "DEBUGGING: Build with ThreadSanitizer (TSan) support" 0) + +if(ASAN AND TSAN) + message(FATAL_ERROR "ASAN and TSAN options are mutually exclusive") +endif() set(ZM_RUNDIR "/var/run/zm" CACHE PATH "Location of transient process files, default: /var/run/zm") diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index c8d90ae0f..c2f2cf74f 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -19,3 +19,15 @@ if(ASAN) message(STATUS "Clang: Enabled AddressSanitizer (ASan)") endif() + +if(TSAN) + target_compile_options(zm-compile-option-interface + INTERFACE + -fsanitize=thread) + + target_link_options(zm-compile-option-interface + INTERFACE + -fsanitize=thread) + + message(STATUS "Clang: Enabled ThreadSanitizer (TSan)") +endif() diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index ecdf31caa..4011b5df1 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -19,3 +19,15 @@ if(ASAN) message(STATUS "GCC: Enabled AddressSanitizer (ASan)") endif() + +if(TSAN) + target_compile_options(zm-compile-option-interface + INTERFACE + -fsanitize=thread) + + target_link_options(zm-compile-option-interface + INTERFACE + -fsanitize=thread) + + message(STATUS "GCC: Enabled ThreadSanitizer (TSan)") +endif()