add '-shared-libasan' to debug flags (bug #5533)

This commit is contained in:
Christian Rauch 2021-02-08 02:15:50 +03:00
parent dc45a228b9
commit 066960c207
1 changed files with 10 additions and 7 deletions

View File

@ -2312,20 +2312,22 @@ if(SDL_STATIC)
endif() endif()
endif() endif()
macro(asan_check_add_debug_flag ASAN_FLAG) macro(check_add_debug_flag FLAG SUFFIX)
set(FLAG "-fsanitize=${ASAN_FLAG}") check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX})
if (HAS_C_FLAG_${SUFFIX})
check_c_compiler_flag(${FLAG} HAS_C_FLAG_${ASAN_FLAG})
if (HAS_C_FLAG_${ASAN_FLAG})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif() endif()
check_cxx_compiler_flag("${FLAG}" HAS_CXX_${ASAN_FLAG}) check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
if (HAS_CXX_${ASAN_FLAG}) if (HAS_CXX_${SUFFIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif() endif()
endmacro() 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) macro(asan_check_add_debug_flag2 ASAN_FLAG)
# for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES: # 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 # 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() endmacro()
# enable AddressSanitizer if supported # enable AddressSanitizer if supported
check_add_debug_flag("-shared-libasan" "shared_libasan")
asan_check_add_debug_flag2("address") asan_check_add_debug_flag2("address")
asan_check_add_debug_flag("bool") asan_check_add_debug_flag("bool")
asan_check_add_debug_flag("bounds") asan_check_add_debug_flag("bounds")