mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
90e1f7d8ec
The -fsanitize-ignorelist (-fsanitize-blacklist is the alias for it) accepts not the suppressions but special case list, that accept only `fun` and `src`, so convert tsan_suppressions.txt into a proper tsan_ignorelist.txt with a proper syntax, otherwise suppressions simply does not work [1]. [1]: https://s3.amazonaws.com/clickhouse-test-reports/61526/958659584957ff419a9305d9c7edee5703fedbdc/integration_tests__tsan__[6_6].html Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
89 lines
4.5 KiB
CMake
89 lines
4.5 KiB
CMake
# Possible values:
|
|
# - `address` (ASan)
|
|
# - `memory` (MSan)
|
|
# - `thread` (TSan)
|
|
# - `undefined` (UBSan)
|
|
# - "" (no sanitizing)
|
|
option (SANITIZE "Enable one of the code sanitizers" "")
|
|
|
|
set (SAN_FLAGS "${SAN_FLAGS} -g -fno-omit-frame-pointer -DSANITIZER")
|
|
|
|
# It's possible to pass an ignore list to sanitizers (-fsanitize-ignorelist). Intentionally not doing this because
|
|
# 1. out-of-source suppressions are awkward 2. it seems ignore lists don't work after the Clang v16 upgrade (#49829)
|
|
|
|
if (SANITIZE)
|
|
if (SANITIZE STREQUAL "address")
|
|
set (ASAN_FLAGS "-fsanitize=address -fsanitize-address-use-after-scope")
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SAN_FLAGS} ${ASAN_FLAGS}")
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SAN_FLAGS} ${ASAN_FLAGS}")
|
|
|
|
elseif (SANITIZE STREQUAL "memory")
|
|
# MemorySanitizer flags are set according to the official documentation:
|
|
# https://clang.llvm.org/docs/MemorySanitizer.html#usage
|
|
|
|
# Linking can fail due to relocation overflows (see #49145), caused by too big object files / libraries.
|
|
# Work around this with position-independent builds (-fPIC and -fpie), this is slightly slower than non-PIC/PIE but that's okay.
|
|
set (MSAN_FLAGS "-fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -fno-optimize-sibling-calls -fPIC -fpie")
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SAN_FLAGS} ${MSAN_FLAGS}")
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SAN_FLAGS} ${MSAN_FLAGS}")
|
|
|
|
elseif (SANITIZE STREQUAL "thread")
|
|
set (TSAN_FLAGS "-fsanitize=thread")
|
|
if (COMPILER_CLANG)
|
|
set (TSAN_FLAGS "${TSAN_FLAGS} -fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/tests/tsan_ignorelist.txt")
|
|
endif()
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SAN_FLAGS} ${TSAN_FLAGS}")
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SAN_FLAGS} ${TSAN_FLAGS}")
|
|
|
|
elseif (SANITIZE STREQUAL "undefined")
|
|
set (UBSAN_FLAGS "-fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero")
|
|
if (ENABLE_FUZZING)
|
|
# Unsigned integer overflow is well defined behaviour from a perspective of C++ standard,
|
|
# compilers or CPU. We use in hash functions like SipHash and many other places in our codebase.
|
|
# This flag is needed only because fuzzers are run inside oss-fuzz infrastructure
|
|
# and they have a bunch of flags not halt the program if UIO happend and even to silence that warnings.
|
|
# But for unknown reason that flags don't work with ClickHouse or we don't understand how to properly use them,
|
|
# that's why we often receive reports about UIO. The simplest way to avoid this is just set this flag here.
|
|
set(UBSAN_FLAGS "${UBSAN_FLAGS} -fno-sanitize=unsigned-integer-overflow")
|
|
endif()
|
|
if (COMPILER_CLANG)
|
|
set (UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/tests/ubsan_ignorelist.txt")
|
|
endif()
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SAN_FLAGS} ${UBSAN_FLAGS}")
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SAN_FLAGS} ${UBSAN_FLAGS}")
|
|
|
|
else ()
|
|
message (FATAL_ERROR "Unknown sanitizer type: ${SANITIZE}")
|
|
endif ()
|
|
endif()
|
|
|
|
# Default coverage instrumentation (dumping the coverage map on exit)
|
|
option(WITH_COVERAGE "Instrumentation for code coverage with default implementation" OFF)
|
|
|
|
if (WITH_COVERAGE)
|
|
message (STATUS "Enabled instrumentation for code coverage")
|
|
set(COVERAGE_FLAGS "-fprofile-instr-generate -fcoverage-mapping")
|
|
endif()
|
|
|
|
option (SANITIZE_COVERAGE "Instrumentation for code coverage with custom callbacks" OFF)
|
|
|
|
if (SANITIZE_COVERAGE)
|
|
message (STATUS "Enabled instrumentation for code coverage")
|
|
|
|
# We set this define for whole build to indicate that at least some parts are compiled with coverage.
|
|
# And to expose it in system.build_options.
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSANITIZE_COVERAGE=1")
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSANITIZE_COVERAGE=1")
|
|
|
|
# But the actual coverage will be enabled on per-library basis: for ClickHouse code, but not for 3rd-party.
|
|
set (COVERAGE_FLAGS "-fsanitize-coverage=trace-pc-guard,pc-table")
|
|
|
|
set (WITHOUT_COVERAGE_FLAGS "-fno-profile-instr-generate -fno-coverage-mapping -fno-sanitize-coverage=trace-pc-guard,pc-table")
|
|
set (WITHOUT_COVERAGE_FLAGS_LIST -fno-profile-instr-generate -fno-coverage-mapping -fno-sanitize-coverage=trace-pc-guard,pc-table)
|
|
else()
|
|
set (WITHOUT_COVERAGE_FLAGS "")
|
|
set (WITHOUT_COVERAGE_FLAGS_LIST "")
|
|
endif()
|