summaryrefslogtreecommitdiffstats
path: root/build_settings.cmake
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2020-03-25 10:28:34 +0000
committerTor Brede Vekterli <vekterli@verizonmedia.com>2020-03-25 10:28:34 +0000
commitfb6c4c75b00f97b27c90b3202ab6cb471550ab46 (patch)
tree6f6729daa9c3e81b9e4250c467ba474fdc7e548d /build_settings.cmake
parent139e6f662bbc016dbccfda9d02cb53bbe468f31b (diff)
Add CMake argument for enabling ASAN/TSAN instrumentation
Needs to be explicitly enabled at config time, example: ``` ./bootstrap-cmake.sh -u . -DVESPA_USE_SANITIZER=address ``` There is some interesting interaction between libLLVM and ASAN that makes new/delete interception not work properly in all cases. Binaries must be launched with `ASAN_OPTIONS=alloc_dealloc_mismatch=0` to get around this. System tests cannot readily be run with instrumentation yet due to library load ordering issues.
Diffstat (limited to 'build_settings.cmake')
-rw-r--r--build_settings.cmake20
1 files changed, 19 insertions, 1 deletions
diff --git a/build_settings.cmake b/build_settings.cmake
index 53fcbbad9a2..6e9b5b73abf 100644
--- a/build_settings.cmake
+++ b/build_settings.cmake
@@ -3,6 +3,14 @@
include(${CMAKE_CURRENT_LIST_DIR}/vtag.cmake)
+if (VESPA_USE_SANITIZER)
+ if (VESPA_USE_SANITIZER STREQUAL "address" OR VESPA_USE_SANITIZER STREQUAL "thread")
+ message("-- Instrumenting code using ${VESPA_USE_SANITIZER} sanitizer")
+ else()
+ message(FATAL_ERROR "Unsupported sanitizer option '${VESPA_USE_SANITIZER}'. Supported: 'address' or 'thread'")
+ endif()
+endif()
+
# Build options
# Whether to build unit tests as part of the 'all' target
set(EXCLUDE_TESTS_FROM_ALL FALSE CACHE BOOL "If TRUE, do not build tests as part of the 'all' target")
@@ -17,7 +25,13 @@ set(RUN_BENCHMARKS FALSE CACHE BOOL "If TRUE, benchmarks are run together with t
set(AUTORUN_UNIT_TESTS FALSE CACHE BOOL "If TRUE, tests will be run immediately after linking the test executable")
# Warnings
-set(C_WARN_OPTS "-Winline -Wuninitialized -Werror -Wall -W -Wchar-subscripts -Wcomment -Wformat -Wparentheses -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings")
+set(C_WARN_OPTS "-Wuninitialized -Werror -Wall -W -Wchar-subscripts -Wcomment -Wformat -Wparentheses -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings")
+if (VESPA_USE_SANITIZER)
+ # Instrumenting code changes binary size, which triggers inlining warnings that
+ # don't happen during normal, non-instrumented compilation.
+else()
+ set(C_WARN_OPTS "-Winline ${C_WARN_OPTS}")
+endif()
# Warnings that are specific to C++ compilation
# Note: this is not a union of C_WARN_OPTS, since CMAKE_CXX_FLAGS already includes CMAKE_C_FLAGS, which in turn includes C_WARN_OPTS transitively
@@ -47,6 +61,10 @@ endif()
# C and C++ compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -fno-omit-frame-pointer ${C_WARN_OPTS} -fPIC ${VESPA_CXX_ABI_FLAGS} -DBOOST_DISABLE_ASSERTS ${VESPA_CPU_ARCH_FLAGS} ${EXTRA_C_FLAGS}")
+# AddressSanitizer/ThreadSanitizer work for both GCC and Clang
+if (VESPA_USE_SANITIZER)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${VESPA_USE_SANITIZER}")
+endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} ${CXX_SPECIFIC_WARN_OPTS} -std=c++1z -fdiagnostics-color=auto ${EXTRA_CXX_FLAGS}")
else()