From 90db2bb2c8529aad935dfa992936709b75e700ab Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 May 2017 00:09:43 +0200 Subject: Add --enable-ubsan/ENABLE_UBSAN for UndefinedBehaviorSanitizer UndefinedBehaviorSanitizer (UBSan) can catch a lot of issues (out-of-bounds memory access, integer overflows, undefined shifts, etc.) and is recommended during development using GCC or Clang. Add an option for it (similar to ASAN support). Change-Id: Ib0db50cee9eb5af0f5c4f06e07f3899a3a34702d Reviewed-on: https://code.wireshark.org/review/21673 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte Reviewed-by: Pascal Quantin Reviewed-by: Peter Wu --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'CMakeLists.txt') 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) -- cgit v1.2.1