diff options
-rw-r--r-- | CMakeLists.txt | 20 | ||||
-rw-r--r-- | CMakeOptions.txt | 1 | ||||
-rw-r--r-- | configure.ac | 14 |
3 files changed, 33 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index eddd909914..de47807b3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -472,9 +472,9 @@ else() # # Code that may be worth looking into (coding practices) # - if((NOT ENABLE_ASAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING)) + if((NOT ENABLE_ASAN) AND (NOT ENABLE_TSAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING)) # - # Only do this if neither ASan nor UBSan are + # Only do this if none of ASan, TSan, and UBSan are # enabled; the instrumentation they add increases # the stack usage - we only care about stack # usage in normal operation. @@ -712,7 +712,23 @@ if(ENABLE_ASAN) endif() endif() +if(ENABLE_TSAN) + # Available since Clang >= 3.2 and GCC >= 4.8 + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=thread") + check_c_compiler_flag(-fsanitize=thread C__fsanitize_thread_VALID) + check_cxx_compiler_flag(-fsanitize=thread CXX__fsanitize_thread_VALID) + cmake_pop_check_state() + if(NOT C__fsanitize_thread_VALID OR NOT CXX__fsanitize_thread_VALID) + message(FATAL_ERROR "ENABLE_TSAN was requested, but not supported!") + endif() + set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}") + set(WS_LINK_FLAGS "-fsanitize=thread ${WS_LINK_FLAGS}") +endif() + if(ENABLE_UBSAN) + # Available since Clang >= 3.3 and GCC >= 4.9 cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined") check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 388f9c4813..e66cbed718 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -30,6 +30,7 @@ option(EXTCAP_ANDROIDDUMP_LIBPCAP "Build androiddump using libpcap" OFF) option(ENABLE_EXTRA_COMPILER_WARNINGS "Do additional compiler warnings (disables -Werror)" OFF) option(ENABLE_CODE_ANALYSIS "Enable the compiler's static analyzer if possible" OFF) option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF) +option(ENABLE_TSAN "Enable ThreadSanitizer (TSan) for debugging" OFF) option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF) option(ENABLE_CHECKHF_CONFLICT "Enable hf conflict check for debugging (start-up may be slower)" OFF) option(ENABLE_CCACHE "Speed up compiling and linking using ccache if possible" OFF) diff --git a/configure.ac b/configure.ac index 8abddafe02..3fcc038f18 100644 --- a/configure.ac +++ b/configure.ac @@ -759,6 +759,20 @@ AC_ARG_ENABLE(asan, AC_SUBST(NO_SANITIZE_CFLAGS) AC_SUBST(NO_SANITIZE_LDFLAGS) +# Try to enable ThreadSanitizer. +# +AC_ARG_ENABLE(tsan, + AC_HELP_STRING( [--enable-tsan], + [Enable ThreadSanitizer (TSan) for debugging@<:@default=no@:>@]), +[ + # + # Available since Clang >= 3.2 and GCC >= 4.8 + # + AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fsanitize=thread) + AC_WIRESHARK_LDFLAGS_CHECK(-fsanitize=thread) + +]) + # Try to enable UndefinedBehaviorSanitizer. # AC_ARG_ENABLE(ubsan, |