[PATCH] D126706: [CMake] Improve support for ASAN on Windows with MSVC cl & clang-cl
Andrew Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 31 08:32:52 PDT 2022
andrewng created this revision.
andrewng added reviewers: rnk, thakis.
Herald added a subscriber: mgorny.
Herald added a project: All.
andrewng requested review of this revision.
Herald added a project: LLVM.
Tested with MSVC 2019 (19.29) and LLVM 14.0.4.
https://reviews.llvm.org/D126706
Files:
llvm/cmake/modules/HandleLLVMOptions.cmake
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -814,12 +814,20 @@
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND LLVM_OPTIMIZE_SANITIZED_BUILDS)
add_flag_if_supported("-O1" O1)
endif()
- elseif (CLANG_CL)
- # Keep frame pointers around.
- append("/Oy-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ else()
# Always ask the linker to produce symbols with asan.
append("/Z7" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
- append("-debug" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ append("/debug" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ # Not compatible with /INCREMENTAL link.
+ foreach (flags_opt_to_scrub
+ CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ string (REGEX REPLACE "(^| )/INCREMENTAL($| )" " /INCREMENTAL:NO "
+ "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
+ endforeach()
+ if (CLANG_CL)
+ # Keep frame pointers around.
+ append("/Oy-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
endif()
endmacro()
@@ -875,7 +883,26 @@
elseif(MSVC)
if (LLVM_USE_SANITIZER STREQUAL "Address")
append_common_sanitizer_flags()
- append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ if (NOT CLANG_CL)
+ # Not compatible with /RTC flags.
+ foreach (flags_opt_to_scrub
+ CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE})
+ string (REGEX REPLACE "(^| )/RTC[1csu]*($| )" " "
+ "${flags_opt_to_scrub}" "${${flags_opt_to_scrub}}")
+ endforeach()
+ endif()
+ if (LINKER_IS_LLD_LINK)
+ if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
+ append("/wholearchive:clang_rt.asan-x86_64.lib /wholearchive:clang_rt.asan_cxx-x86_64.lib"
+ CMAKE_EXE_LINKER_FLAGS)
+ append("/wholearchive:clang_rt.asan_dll_thunk-x86_64.lib"
+ CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ else()
+ append("clang_rt.asan_dynamic-x86_64.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
+ CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ endif()
+ endif()
else()
message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}")
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126706.433094.patch
Type: text/x-patch
Size: 2656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220531/74ed057e/attachment.bin>
More information about the llvm-commits
mailing list