commit 18cf66c7bfc185665fb8e6ad80b7dfeb35754161 from: Sergey Bronnikov date: Tue Oct 15 07:44:33 2024 UTC cmake: fix build with GCC's AddressSanitizer GNU GCC compiler has AddressSanitizer support since 4.8.0 [1], but it was unsupported in tarantool's build. The patch fixes a build by GNU GCC with enabled AddressSanitizer. 1. https://gcc.gnu.org/gcc-4.8/changes.html NO_CHANGELOG=build NO_DOC=build NO_TEST=build (cherry picked from commit ef91f92a22c6d7910ecdd00ab14da359343a2ec2) commit - 89b2760ef192a744e09a41a8af347aa148bbdf33 commit + 18cf66c7bfc185665fb8e6ad80b7dfeb35754161 blob - aee1d561b2e2a37c3982df37906af8cdcb88f271 blob + e0baa6298cd00c4ea1d71cc0d06afd71b862eb56 --- cmake/CheckDependencies.cmake +++ cmake/CheckDependencies.cmake @@ -34,6 +34,9 @@ elseif(UNIX) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ENABLE_ASAN) set(ALLOWLIST ${ALLOWLIST} libresolv) endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND ENABLE_ASAN) + set(ALLOWLIST ${ALLOWLIST} libasan) + endif() else() message(FATAL_ERROR "Unknown platform") endif() blob - 16492efb160ff9a737670ba3f5aa5f6ddc30d3fd blob + 23fb46664ea0a718878e479c59465be2e8c01e73 --- cmake/profile.cmake +++ cmake/profile.cmake @@ -74,16 +74,25 @@ endif() option(ENABLE_ASAN "Enable AddressSanitizer, a fast memory error detector based on compiler instrumentation" OFF) if (ENABLE_ASAN) - if (CMAKE_COMPILER_IS_GNUCC) + # AddressSanitizer has been added to GCC since version 4.8.0, + # see https://gcc.gnu.org/gcc-4.8/changes.html. + if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8.0) message(FATAL_ERROR "\n" - " Tarantool does not support GCC's AddressSanitizer. Use clang:\n" + " GCC has AddressSanitizer support since 4.8.0. Update GCC version\n" + " or use Clang:\n" " $ git clean -xfd; git submodule foreach --recursive git clean -xfd\n" " $ CC=clang CXX=clang++ cmake . <...> -DENABLE_ASAN=ON && make -j\n" "\n") endif() - set(CMAKE_REQUIRED_FLAGS "-fsanitize=address -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/asan/asan.supp") + set(ASAN_FLAGS "-fsanitize=address") + if (CMAKE_C_COMPILER STREQUAL "Clang") + # Bug 61978 - implement blacklist for sanitizer, + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61978 + set(ASAN_FLAGS "${ASAN_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/asan/asan.supp") + endif() + set(CMAKE_REQUIRED_FLAGS ${ASAN_FLAGS}) check_c_source_compiles("int main(void) { #include void *x; @@ -106,5 +115,5 @@ if (ENABLE_ASAN) message(FATAL_ERROR "Cannot enable AddressSanitizer") endif() - add_compile_flags("C;CXX" -fsanitize=address -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/asan/asan.supp) + add_compile_flags("C;CXX" ${ASAN_FLAGS}) endif()