Rollup merge of #132773 - jakos-sec:fix-asan-win32, r=jieyouxu
PassWrapper: disable UseOdrIndicator for Asan Win32 As described in https://reviews.llvm.org/D137227 UseOdrIndicator should be disabled on Windows since link.exe does not support duplicate weak definitions. Fixes https://github.com/rust-lang/rust/issues/124390. Credits also belong to `@1c3t3a` who worked with me on this. We are currently testing this on a Windows machine.
This commit is contained in:
commit
e3c76c5699
3 changed files with 40 additions and 4 deletions
|
@ -882,10 +882,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
||||||
SanitizerOptions->SanitizeKernelAddress) {
|
SanitizerOptions->SanitizeKernelAddress) {
|
||||||
OptimizerLastEPCallbacks.push_back(
|
OptimizerLastEPCallbacks.push_back(
|
||||||
#if LLVM_VERSION_GE(20, 0)
|
#if LLVM_VERSION_GE(20, 0)
|
||||||
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
|
[SanitizerOptions, TM](ModulePassManager &MPM,
|
||||||
ThinOrFullLTOPhase phase) {
|
OptimizationLevel Level,
|
||||||
|
ThinOrFullLTOPhase phase) {
|
||||||
#else
|
#else
|
||||||
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
|
[SanitizerOptions, TM](ModulePassManager &MPM,
|
||||||
|
OptimizationLevel Level) {
|
||||||
#endif
|
#endif
|
||||||
auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
|
auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
|
||||||
AddressSanitizerOptions opts = AddressSanitizerOptions{
|
AddressSanitizerOptions opts = AddressSanitizerOptions{
|
||||||
|
@ -895,7 +897,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
||||||
/*UseAfterScope=*/true,
|
/*UseAfterScope=*/true,
|
||||||
AsanDetectStackUseAfterReturnMode::Runtime,
|
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) {
|
if (SanitizerOptions->SanitizeHWAddress) {
|
||||||
|
|
18
tests/ui/asan-odr-win/asan_odr_windows.rs
Normal file
18
tests/ui/asan-odr-win/asan_odr_windows.rs
Normal file
|
@ -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
tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs
Normal file
11
tests/ui/asan-odr-win/auxiliary/asan_odr_win-2.rs
Normal file
|
@ -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());
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue