diff options
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | CMakeOptions.txt | 1 | ||||
-rw-r--r-- | configure.ac | 14 |
3 files changed, 27 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f31e7f72..497f239675 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -616,6 +616,18 @@ if(ENABLE_ASAN) endif() endif() +if(ENABLE_UBSAN) + set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined") + check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID) + check_cxx_compiler_flag(-fsanitize=undefined CXX__fsanitize_undefined_VALID) + set(CMAKE_REQUIRED_LIBRARIES "") + if(NOT C__fsanitize_undefined_VALID OR NOT CXX__fsanitize_undefined_VALID) + message(FATAL_ERROR "ENABLE_UBSAN was requested, but not supported!") + endif() + set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-fsanitize=undefined ${CMAKE_CXX_FLAGS}") +endif() + set(WERROR_COMMON_FLAGS "") set(NO_ERROR_DEPRECATED_DECLARATIONS_COMPILE_FLAGS "") if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 233a706a2e..5963ddaa4c 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -26,6 +26,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_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 29767774c1..b966aabbb6 100644 --- a/configure.ac +++ b/configure.ac @@ -786,6 +786,20 @@ AC_ARG_ENABLE(asan, AC_SUBST(NO_SANITIZE_CFLAGS) AC_SUBST(NO_SANITIZE_LDFLAGS) +# Try to enable UndefinedBehaviorSanitizer. +# +AC_ARG_ENABLE(ubsan, + AC_HELP_STRING( [--enable-ubsan], + [Enable UndefinedBehaviorSanitizer (UBSan) for debugging@<:@default=no@:>@]), +[ + # + # Available since Clang >= 3.3 and GCC >= 4.9 + # + # XXX shouldn't this also be added to LDFLAGS? + AC_WIRESHARK_COMPILER_FLAGS_CHECK(-fsanitize=undefined) + +]) + # Add check hf conflict.. # AC_ARG_ENABLE(checkhf-conflict, |