Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
SanitizerOptions->SanitizeKernelAddress) {
OptimizerLastEPCallbacks.push_back(
#if LLVM_VERSION_GE(20, 0)
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
[SanitizerOptions, TM](ModulePassManager &MPM,
OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
#else
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
[SanitizerOptions, TM](ModulePassManager &MPM,
OptimizationLevel Level) {
#endif
auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
AddressSanitizerOptions opts = AddressSanitizerOptions{
Expand All @@ -895,7 +897,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
/*UseAfterScope=*/true,
AsanDetectStackUseAfterReturnMode::Runtime,
};
MPM.addPass(AddressSanitizerPass(opts));
MPM.addPass(AddressSanitizerPass(
opts,
/*UseGlobalGC*/ true,
// UseOdrIndicator should be false on windows machines
// https://reviews.llvm.org/D137227
!TM->getTargetTriple().isOSWindows()));
});
}
if (SanitizerOptions->SanitizeHWAddress) {
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/asan-odr-win/asan_odr_windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Check that crates can be linked together with `-Z sanitizer=address` on msvc.
//! See <https://github.com/rust-lang/rust/issues/124390>.

//@ run-pass
//@ compile-flags:-Zsanitizer=address
//@ aux-build: asan_odr_win-2.rs
//@ only-windows-msvc

extern crate othercrate;

fn main() {
let result = std::panic::catch_unwind(|| {
println!("hello!");
});
assert!(result.is_ok());

othercrate::exposed_func();
}
11 changes: 11 additions & 0 deletions tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ no-prefer-dynamic
//@ compile-flags: -Z sanitizer=address
#![crate_name = "othercrate"]
#![crate_type = "rlib"]

pub fn exposed_func() {
let result = std::panic::catch_unwind(|| {
println!("hello!");
});
assert!(result.is_ok());
}