From dc402a8b96dc50f5958fd923e533799f0ebf6432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 11 Apr 2023 14:15:34 +0200 Subject: [PATCH] Core: Fix ASAN on Clang-14 / Linux When using ASAN on Clang / Linux, the call to `find_library(... asan ...)` works against us, as it finds GCC's `libasan.so`. To work with Clang, we should simply not pass any explicit library, as Clang will figure things out by itself with the `-fsanitize=xxx` options. Furthermore, Clang is incompatible with `-fsanitize=object-size`, so that's now also no longer passed on Linux (mimicking the Apple) configuration. For the long run, it would be better to rewrite this entire section to select behaviour on a per-compiler basis, rather than per platform. That's tracked in #105956 Pull Request: https://projects.blender.org/blender/blender/pulls/106675 --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43855083b0c..2477ab1679e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -693,8 +693,10 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") else() string(APPEND _asan_defaults " -fsanitize=object-size") endif() - else() + elseif(CMAKE_COMPILER_IS_GNUCC) string(APPEND _asan_defaults " -fsanitize=leak -fsanitize=object-size") + else() + string(APPEND _asan_defaults " -fsanitize=leak") endif() set(COMPILER_ASAN_CFLAGS "${_asan_defaults}" CACHE STRING "C flags for address sanitizer") @@ -711,6 +713,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/7.0.0/lib/windows [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/6.0.0/lib/windows ) + mark_as_advanced(COMPILER_ASAN_LIBRARY) elseif(APPLE) execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=lib @@ -725,13 +728,14 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") "${CLANG_LIB_DIR}/darwin/" ) unset(CLANG_LIB_DIR) - else() + mark_as_advanced(COMPILER_ASAN_LIBRARY) + elseif(CMAKE_COMPILER_IS_GNUCC) find_library( COMPILER_ASAN_LIBRARY asan ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES} ) + mark_as_advanced(COMPILER_ASAN_LIBRARY) endif() - mark_as_advanced(COMPILER_ASAN_LIBRARY) endif() endif()