From fb8f1534cab7066ab6c30bf84dbd297f001a0e73 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 25 Jun 2021 17:10:38 +0800 Subject: [PATCH] fix(cmake/debug): fix asan do not work at windows env GitOrigin-RevId: 6638194fd724f9d3455d2587080142479683cdb1 --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f46d0724..a580b5f48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,11 @@ if(MSVC OR WIN32) # on windows need append VS_PATH/VC/Tools/Llvm/x64/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows # and VS_PATH/VC/Tools/Llvm/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows to PATH env if (MGE_BUILD_WITH_ASAN) + message(WARNING "please do (set)export ASAN_OPTIONS=windows_hook_rtl_allocators=true when run test after build finish, caused by we link asan dll!!") + if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + message(WARNING "Windows AddressSanitizer doesn't support linking with debug runtime libraries yet, which means do not support CMAKE_BUILD_TYPE=Debug") + message(FATAL_ERROR "Please build with RelWithDebInfo or Release by : EXTRA_CMAKE_ARGS=\"-DMGE_BUILD_WITH_ASAN=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ...\"") + endif() if("$ENV{VS_PATH}" STREQUAL "") message(FATAL_ERROR "can not find VS_PATH, please export Visual Studio root dir to VS_PATH env") endif() @@ -239,6 +244,12 @@ if(MSVC OR WIN32) link_libraries(${WINDOWS_ASAN_DLL_NAME}) link_libraries(${WINDOWS_ASAN_RUNTIME_THUNK_NAME}) set(WIN_FLAGS "/Od -DNDEBUG -fsanitize=address") + # windows Llvm asan do not take effect when /O2 + # RELWITHDEBINFO default value is /O2, so override it + set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_C_FLAGS_RELEASE "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "/Zi /Od /Ob1 /DNDEBUG") else() set(WIN_FLAGS "/O2") endif() -- GitLab