[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
Wed Jun 8 03:18:43 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d6fcdf945f4: [CMake] Improve support for ASAN on Windows with MSVC cl & clang-cl (authored by andrewng).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126706/new/
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 (LLVM_HOST_TRIPLE MATCHES "i[2-6]86-.*")
+ # Keep frame pointers around.
+ append("/Oy-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
endif()
endmacro()
@@ -875,7 +883,31 @@
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_HOST_TRIPLE MATCHES "i[2-6]86-.*")
+ set(arch "i386")
+ else()
+ set(arch "x86_64")
+ endif()
+ if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
+ append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
+ CMAKE_EXE_LINKER_FLAGS)
+ append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib"
+ CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ else()
+ append("clang_rt.asan_dynamic-${arch}.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-${arch}.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.435093.patch
Type: text/x-patch
Size: 2835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220608/dbfa2bd1/attachment.bin>
More information about the llvm-commits
mailing list