Skip to content

Commit 71e20c6

Browse files
authored
Fix references to required libraries when building LLVM with ASAN and MultiThreaded[Debug] on Windows (#139657)
After #81677, statically linking ASAN under Windows is no longer supported. Therefore, when using Clang built past 53a81d4 to build LLVM / Clang with `-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded[Debug] -DLLVM_USE_SANITIZER=Address`, a different set of dependent libraries must be linked. This is mentioned in the description of #81677 and also in https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-one-dll-for-all-runtime-configurations/.
1 parent 05b4bfe commit 71e20c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,13 +1038,14 @@ if(LLVM_USE_SANITIZER)
10381038
# lld string tail merging interacts badly with ASAN on Windows, turn it off here
10391039
# See https://github.com/llvm/llvm-project/issues/62078
10401040
append("/opt:nolldtailmerge" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1041+
# Static and dynamic C runtimes all load ASAN as a DLL
1042+
# See https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-one-dll-for-all-runtime-configurations/
1043+
append("clang_rt.asan_dynamic-${arch}.lib" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
10411044
if (${CMAKE_MSVC_RUNTIME_LIBRARY} MATCHES "^(MultiThreaded|MultiThreadedDebug)$")
1042-
append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
1043-
CMAKE_EXE_LINKER_FLAGS)
1044-
append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib"
1045-
CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
1045+
append("/wholearchive:clang_rt.asan_static_runtime_thunk-${arch}.lib"
1046+
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
10461047
else()
1047-
append("clang_rt.asan_dynamic-${arch}.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-${arch}.lib"
1048+
append("/wholearchive:clang_rt.asan_dynamic_runtime_thunk-${arch}.lib"
10481049
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
10491050
endif()
10501051
endif()

0 commit comments

Comments
 (0)