Skip to content

Commit d8c661a

Browse files
committed
Mark __msan_keep_going as an exported symbol for LTO
1 parent 2c0845c commit d8c661a

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

src/librustc_codegen_ssa/back/symbol_export.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ fn exported_symbols_provider_local(
208208

209209
if let Some(Sanitizer::Memory) = tcx.sess.opts.debugging_opts.sanitizer {
210210
// Similar to profiling, preserve weak msan symbol during LTO.
211-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new("__msan_track_origins"));
212-
symbols.push((exported_symbol, SymbolExportLevel::C));
211+
const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
212+
213+
symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
214+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
215+
(exported_symbol, SymbolExportLevel::C)
216+
}));
213217
}
214218

215219
if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) {

src/test/codegen/sanitizer-recover.rs

+36-20
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,47 @@
44
// needs-sanitizer-support
55
// only-linux
66
// only-x86_64
7-
// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER
7+
// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER MSAN-RECOVER-LTO
8+
// no-prefer-dynamic
89
//
9-
//[ASAN] compile-flags: -Zsanitizer=address
10-
//[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address
11-
//[MSAN] compile-flags: -Zsanitizer=memory
12-
//[MSAN-RECOVER] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory
13-
14-
#![crate_type="lib"]
10+
//[ASAN] compile-flags: -Zsanitizer=address
11+
//[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address
12+
//[MSAN] compile-flags: -Zsanitizer=memory
13+
//[MSAN-RECOVER] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory
14+
//[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -C lto=fat
15+
//
16+
// MSAN-NOT: @__msan_keep_going
17+
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}} constant i32 1
18+
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}} constant i32 1
1519

16-
// ASAN-LABEL: define i32 @penguin(
20+
// ASAN-LABEL: define i32 @penguin(
21+
// ASAN: call void @__asan_report_load4(i64 %0)
22+
// ASAN: unreachable
23+
// ASAN: }
24+
//
1725
// ASAN-RECOVER-LABEL: define i32 @penguin(
18-
// MSAN-LABEL: define i32 @penguin(
26+
// ASAN-RECOVER: call void @__asan_report_load4_noabort(
27+
// ASAN-RECOVER-NOT: unreachable
28+
// ASAN: }
29+
//
30+
// MSAN-LABEL: define i32 @penguin(
31+
// MSAN: call void @__msan_warning_noreturn()
32+
// MSAN: unreachable
33+
// MSAN: }
34+
//
1935
// MSAN-RECOVER-LABEL: define i32 @penguin(
36+
// MSAN-RECOVER: call void @__msan_warning()
37+
// MSAN-RECOVER-NOT: unreachable
38+
// MSAN-RECOVER: }
39+
//
40+
// MSAN-RECOVER-LTO-LABEL: define i32 @penguin(
41+
// MSAN-RECOVER-LTO: call void @__msan_warning()
42+
// MSAN-RECOVER-LTO-NOT: unreachable
43+
// MSAN-RECOVER-LTO: }
44+
//
2045
#[no_mangle]
2146
pub fn penguin(p: &mut i32) -> i32 {
22-
// ASAN: call void @__asan_report_load4(i64 %0)
23-
// ASAN: unreachable
24-
//
25-
// ASAN-RECOVER: call void @__asan_report_load4_noabort(
26-
// ASAN-RECOVER-NOT: unreachable
27-
//
28-
// MSAN: call void @__msan_warning_noreturn()
29-
// MSAN: unreachable
30-
//
31-
// MSAN-RECOVER: call void @__msan_warning()
32-
// MSAN-RECOVER-NOT: unreachable
3347
*p
3448
}
49+
50+
fn main() {}

0 commit comments

Comments
 (0)