Skip to content

Commit

Permalink
Add ThreadSanitizer configure-time options.
Browse files Browse the repository at this point in the history
Add ENABLE_TSAN and enable-tsan options to CMake and Autotools
respectively which enable ThreadSanitizer, similar to AddressSanitizer
and UndefinedBehaviorSanitizer.

Change-Id: I79adf5c1516b0938f140bbf501c181bf14d7619b
Reviewed-on: https://code.wireshark.org/review/24515
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
  • Loading branch information
geraldcombs committed Nov 21, 2017
1 parent 8cbde93 commit 0b2eccc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions CMakeOptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0b2eccc

Please sign in to comment.