diff options
| author | Jakob Koschel <jkl820.git@gmail.com> | 2024-11-08 13:24:54 +0000 |
|---|---|---|
| committer | Jieyou Xu <jieyouxu@outlook.com> | 2024-11-14 04:20:18 +0800 |
| commit | 61013f040e6e3e91b012791d2b77a9d3e47e390b (patch) | |
| tree | c634f309f559aad08d8cd526926ab5b7a0f3ece2 | |
| parent | a00df61387e5389d6fe23e38e657f90d672668b1 (diff) | |
| download | rust-61013f040e6e3e91b012791d2b77a9d3e47e390b.tar.gz rust-61013f040e6e3e91b012791d2b77a9d3e47e390b.zip | |
PassWrapper: disable UseOdrIndicator for Asan Win32
As described here UseOdrIndicator should be disabled on Windows since link.exe does not support duplicate weak definitions (https://reviews.llvm.org/D137227). Co-Authored-By: Bastian Kersting <bkersting@google.com>
| -rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 15 | ||||
| -rw-r--r-- | tests/ui/asan-odr-win/asan_odr_windows.rs | 18 | ||||
| -rw-r--r-- | tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs | 11 |
3 files changed, 40 insertions, 4 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 1ed702ab4cb..489c911d7ee 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -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{ @@ -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) { diff --git a/tests/ui/asan-odr-win/asan_odr_windows.rs b/tests/ui/asan-odr-win/asan_odr_windows.rs new file mode 100644 index 00000000000..c618ac02a66 --- /dev/null +++ b/tests/ui/asan-odr-win/asan_odr_windows.rs @@ -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(); +} diff --git a/tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs b/tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs new file mode 100644 index 00000000000..75488a29e5e --- /dev/null +++ b/tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs @@ -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()); +} |
