Cherry-pick: Enable optional use of ASAN

AdressSanitizer is a lightweight memory error detector that instruments at
compile time instead of at execution time. This allows serious memory
errors to be detected without the cost of slowing down the whole program
that often happens when Valgrind is used. It is also easier to enable for
test runs as it is a simple compiler flag.

This is a cherry-pick of fb9b027842a7b65c4826455cd34d88e2f5f28e79 from the
2.2 branch.
This commit is contained in:
Markus Mäkelä 2017-08-17 08:00:58 +03:00
parent 3d7bf5683e
commit 69811d9b19
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 23 additions and 0 deletions

View File

@ -45,6 +45,7 @@ find_package(Jansson)
find_package(Avro)
find_package(GSSAPI)
find_package(SQLite)
find_package(ASAN)
# Find or build PCRE2
# Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target
@ -176,6 +177,11 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
endif()
if (WITH_ASAN AND ASAN_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-uninitialized")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -Wno-uninitialized")

14
cmake/FindASAN.cmake Normal file
View File

@ -0,0 +1,14 @@
# Find AddressSanitizer libraries
#
# The following variables are set:
# ASAN_FOUND - If AddressSanitizer was found
# ASAN_LIBRARIES - Path to the libasan library
find_library(ASAN_LIBRARIES NAMES libasan.so.0 libasan.so.3 libasan.so.4)
if (ASAN_LIBRARIES)
message(STATUS "Found AdressSanitizer libraries: ${ASAN_LIBRARIES}")
set(ASAN_FOUND TRUE CACHE INTERNAL "")
else()
message(STATUS "Could not find AdressSanitizer")
endif()

View File

@ -62,3 +62,6 @@ set(PACKAGE_NAME "maxscale" CACHE STRING "Name of the generated package")
# Which component to build (core, experimental, devel)
set(TARGET_COMPONENT "core" CACHE STRING "Which component to build (core, experimental, devel, all)")
# Enable AddressSanitizer: https://github.com/google/sanitizers/wiki/AddressSanitizer
set(WITH_ASAN FALSE CACHE BOOL "Enable AddressSanitizer")