Fix: CMake: Windows: Make ASAN usable again on debug configurations
Seems like ASAN has been broken on debug builds for MSVC ever since
d5e50460e7 (1.5 years ago) the core reason is it's incompatible with
fastlink, it'll appear to work, but in the asan reports no symbols
will be resolved.
While looking into this, some other problems like the symbol format being
not inline with the table in the comment above it, and a warning coming
out of /extern were noted.
All of these issues are addressed in this commit.
This commit is contained in:
@@ -267,8 +267,8 @@ else()
|
||||
unset(CMAKE_C_COMPILER_LAUNCHER)
|
||||
unset(CMAKE_CXX_COMPILER_LAUNCHER)
|
||||
if(MSVC_ASAN)
|
||||
set(SYMBOL_FORMAT /Z7)
|
||||
set(SYMBOL_FORMAT_RELEASE /Z7)
|
||||
set(SYMBOL_FORMAT /Zi)
|
||||
set(SYMBOL_FORMAT_RELEASE /Zi)
|
||||
else()
|
||||
set(SYMBOL_FORMAT /ZI)
|
||||
set(SYMBOL_FORMAT_RELEASE /Zi)
|
||||
@@ -298,7 +298,12 @@ endif()
|
||||
|
||||
string(APPEND PLATFORM_LINKFLAGS " /SUBSYSTEM:CONSOLE /STACK:2097152")
|
||||
set(PLATFORM_LINKFLAGS_RELEASE "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib")
|
||||
string(APPEND PLATFORM_LINKFLAGS_DEBUG "/debug:fastlink /IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmtd.lib")
|
||||
|
||||
if(NOT WITH_COMPILER_ASAN)
|
||||
# Asan is incompatible with fastlink, it will appear to work, but will not resolve symbols which makes it somewhat useless
|
||||
string(APPEND PLATFORM_LINKFLAGS_DEBUG "/debug:fastlink ")
|
||||
endif()
|
||||
string(APPEND PLATFORM_LINKFLAGS_DEBUG " /IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmtd.lib")
|
||||
|
||||
# Ignore meaningless for us linker warnings.
|
||||
string(APPEND PLATFORM_LINKFLAGS " /ignore:4049 /ignore:4217 /ignore:4221")
|
||||
|
||||
16
extern/CMakeLists.txt
vendored
16
extern/CMakeLists.txt
vendored
@@ -21,11 +21,17 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
endif()
|
||||
|
||||
if(WITH_COMPILER_ASAN AND NOT WITH_COMPILER_ASAN_EXTERN)
|
||||
# Disable ASAN for extern dependencies, as it can lead to linking issues due to too large binaries.
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_C_FLAGS_DEBUG " -fno-sanitize=all")
|
||||
# Not only does MSVC not have an -fno-sanitize=all option, if you remove the /fsanitize=address
|
||||
# flag at this point, it will give a linker error as it generates an ODR violation for some
|
||||
# vector classes, for details see :
|
||||
# https://learn.microsoft.com/en-us/cpp/sanitizers/error-container-overflow?view=msvc-170
|
||||
if(NOT MSVC)
|
||||
# Disable ASAN for extern dependencies, as it can lead to linking issues due to too large binaries.
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fno-sanitize=all")
|
||||
string(APPEND CMAKE_C_FLAGS_DEBUG " -fno-sanitize=all")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user