From 066960c207bf72d9f0f1eef4e2f59f3b382e498d Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Mon, 8 Feb 2021 02:15:50 +0300 Subject: [PATCH] add '-shared-libasan' to debug flags (bug #5533) --- CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d244f7e4..5757388c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2312,20 +2312,22 @@ if(SDL_STATIC) endif() endif() -macro(asan_check_add_debug_flag ASAN_FLAG) - set(FLAG "-fsanitize=${ASAN_FLAG}") - - check_c_compiler_flag(${FLAG} HAS_C_FLAG_${ASAN_FLAG}) - if (HAS_C_FLAG_${ASAN_FLAG}) +macro(check_add_debug_flag FLAG SUFFIX) + check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX}) + if (HAS_C_FLAG_${SUFFIX}) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}") endif() - check_cxx_compiler_flag("${FLAG}" HAS_CXX_${ASAN_FLAG}) - if (HAS_CXX_${ASAN_FLAG}) + check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX}) + if (HAS_CXX_${SUFFIX}) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") endif() endmacro() +macro(asan_check_add_debug_flag ASAN_FLAG) + check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}") +endmacro() + macro(asan_check_add_debug_flag2 ASAN_FLAG) # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES: # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html @@ -2348,6 +2350,7 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG) endmacro() # enable AddressSanitizer if supported +check_add_debug_flag("-shared-libasan" "shared_libasan") asan_check_add_debug_flag2("address") asan_check_add_debug_flag("bool") asan_check_add_debug_flag("bounds")