Skip to content

Commit d506a20

Browse files
committed
Adapt to LLVM 20 ASan library changes on Windows (CMake + linking)
1 parent a7848bc commit d506a20

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,15 @@ if (LDC_INSTALL_LLVM_RUNTIME_LIBS)
894894
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
895895
set(compilerrt_arch_suffix "i386")
896896
endif()
897-
copy_compilerrt_lib("clang_rt.asan-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
898-
copy_compilerrt_lib("clang_rt.lsan-${compilerrt_arch_suffix}.lib" "ldc_rt.lsan.lib" FALSE)
897+
if(LDC_LLVM_VER LESS 2000)
898+
copy_compilerrt_lib("clang_rt.asan-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
899+
copy_compilerrt_lib("clang_rt.lsan-${compilerrt_arch_suffix}.lib" "ldc_rt.lsan.lib" FALSE)
900+
else()
901+
copy_compilerrt_lib("clang_rt.asan_static_runtime_thunk-${compilerrt_arch_suffix}.lib" "ldc_rt.asan_static_runtime_thunk.lib" FALSE)
902+
copy_compilerrt_lib("clang_rt.asan_dynamic_runtime_thunk-${compilerrt_arch_suffix}.lib" "ldc_rt.asan_dynamic_runtime_thunk.lib" FALSE)
903+
copy_compilerrt_lib("clang_rt.asan_dynamic-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
904+
copy_compilerrt_lib("clang_rt.asan_dynamic-${compilerrt_arch_suffix}.dll" "clang_rt.asan_dynamic-${compilerrt_arch_suffix}.dll" FALSE)
905+
endif()
899906
copy_compilerrt_lib("clang_rt.builtins-${compilerrt_arch_suffix}.lib" "ldc_rt.builtins.lib" FALSE)
900907
copy_compilerrt_lib("clang_rt.profile-${compilerrt_arch_suffix}.lib" "ldc_rt.profile.lib" FALSE)
901908
copy_compilerrt_lib("clang_rt.fuzzer-${compilerrt_arch_suffix}.lib" "ldc_rt.fuzzer.lib" FALSE)

driver/linker-msvc.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ void addLibIfFound(std::vector<std::string> &args, const llvm::Twine &name) {
7373
}
7474
}
7575

76-
void addSanitizerLibs(std::vector<std::string> &args) {
76+
void addSanitizerLibs(bool useInternalToolchain,
77+
std::vector<std::string> &args) {
7778
if (opts::isSanitizerEnabled(opts::AddressSanitizer)) {
7879
args.push_back("ldc_rt.asan.lib");
80+
#if LDC_LLVM_VER >= 2000 // extra library since LLVM 20
81+
const bool linkStaticCRT =
82+
getMscrtLibName(&useInternalToolchain).contains_lower("libcmt");
83+
args.push_back((llvm::Twine("ldc_rt.asan_") +
84+
(linkStaticCRT ? "static" : "dynamic") +
85+
"_runtime_thunk.lib")
86+
.str());
87+
#endif
7988
} else if (opts::isSanitizerEnabled(opts::LeakSanitizer)) {
8089
// If ASan is enabled, it includes LSan. So only add LSan link flags if ASan is _not_ enabled already.
8190
args.push_back("ldc_rt.lsan.lib");
@@ -187,7 +196,7 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
187196

188197
// LLVM compiler-rt libs
189198
addLibIfFound(args, "ldc_rt.builtins.lib");
190-
addSanitizerLibs(args);
199+
addSanitizerLibs(useInternalToolchain, args);
191200
if (opts::isInstrumentingForPGO()) {
192201
args.push_back("ldc_rt.profile.lib");
193202
// it depends on ws2_32 for symbol `gethostname`

0 commit comments

Comments
 (0)