Skip to content

Commit 2f5b71d

Browse files
committed
[asan] Fix asan configuration for MacOS
The `c++ --print-file-name` command now seems to work, and it is indeed the more appropriate way to get the location of the asan shared library on MacOS. Also fix the following problems occurring when building on MacOS with -Dasan=ON Error: ``` CMake Error at cmake/modules/CheckAtomic.cmake:59 (message): Host compiler appears to require libatomic, but cannot find it. ``` Fix: fix typos in asan symbols (extra `_`) and specify correct linker flag (-U) Error: ``` error: static AddressSanitizer runtime is not supported on darwin ``` Fix: remove `-static-libsan` flag. This is required by latest MacOS Xcode
1 parent 5198675 commit 2f5b71d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

cmake/modules/SetUpMacOS.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,10 @@ if (CMAKE_SYSTEM_NAME MATCHES Darwin)
8282

8383
if(asan)
8484
# See also core/sanitizer/README.md for what's happening.
85-
86-
#This should be the right way to do it, but clang 10 seems to have a bug
87-
#execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan_osx_dynamic.dylib OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE)
88-
execute_process(COMMAND mdfind -name libclang_rt.asan_osx_dynamic.dylib OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE)
85+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan_osx_dynamic.dylib OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE)
8986
set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope)
90-
set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -static-libsan")
91-
set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -static-libsan -Wl,-u,___asan_default_options -Wl,-u,___lsan_default_options -Wl,-u,___lsan_default_suppressions")
87+
set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address")
88+
set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -Wl,-U,__asan_default_options -Wl,-U,__lsan_default_options -Wl,-U,__lsan_default_suppressions")
9289
endif()
9390

9491
else()

0 commit comments

Comments
 (0)