Skip to content
Snippets Groups Projects
Commit 89815cd3 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Sergey Kaplun
Browse files

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)
parent f67e047a
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -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 <sanitizer/asan_interface.h>
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment