about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-21 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-21 00:00:00 +0000
commitd8c661a88644ad710e309d3a8f0f27c5f74d705f (patch)
treec43a6cdfdd122500dbf4d676a1abc2c4145fdd60
parent2c0845c6ccfdee7fb255756918a22101376efa7e (diff)
downloadrust-d8c661a88644ad710e309d3a8f0f27c5f74d705f.tar.gz
rust-d8c661a88644ad710e309d3a8f0f27c5f74d705f.zip
Mark __msan_keep_going as an exported symbol for LTO
-rw-r--r--src/librustc_codegen_ssa/back/symbol_export.rs8
-rw-r--r--src/test/codegen/sanitizer-recover.rs56
2 files changed, 42 insertions, 22 deletions
diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs
index c5989748560..d680e14bbbd 100644
--- a/src/librustc_codegen_ssa/back/symbol_export.rs
+++ b/src/librustc_codegen_ssa/back/symbol_export.rs
@@ -208,8 +208,12 @@ fn exported_symbols_provider_local(
 
     if let Some(Sanitizer::Memory) = tcx.sess.opts.debugging_opts.sanitizer {
         // Similar to profiling, preserve weak msan symbol during LTO.
-        let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new("__msan_track_origins"));
-        symbols.push((exported_symbol, SymbolExportLevel::C));
+        const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
+
+        symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
+            let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
+            (exported_symbol, SymbolExportLevel::C)
+        }));
     }
 
     if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) {
diff --git a/src/test/codegen/sanitizer-recover.rs b/src/test/codegen/sanitizer-recover.rs
index a292332667b..9a583725b0b 100644
--- a/src/test/codegen/sanitizer-recover.rs
+++ b/src/test/codegen/sanitizer-recover.rs
@@ -4,31 +4,47 @@
 // needs-sanitizer-support
 // only-linux
 // only-x86_64
-// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER
+// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER MSAN-RECOVER-LTO
+// no-prefer-dynamic
 //
-//[ASAN]         compile-flags: -Zsanitizer=address
-//[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address
-//[MSAN]         compile-flags: -Zsanitizer=memory
-//[MSAN-RECOVER] compile-flags: -Zsanitizer=memory  -Zsanitizer-recover=memory
-
-#![crate_type="lib"]
+//[ASAN]             compile-flags: -Zsanitizer=address
+//[ASAN-RECOVER]     compile-flags: -Zsanitizer=address -Zsanitizer-recover=address
+//[MSAN]             compile-flags: -Zsanitizer=memory
+//[MSAN-RECOVER]     compile-flags: -Zsanitizer=memory  -Zsanitizer-recover=memory
+//[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory  -Zsanitizer-recover=memory -C lto=fat
+//
+// MSAN-NOT:         @__msan_keep_going
+// MSAN-RECOVER:     @__msan_keep_going = weak_odr {{.*}} constant i32 1
+// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}} constant i32 1
 
-// ASAN-LABEL:         define i32 @penguin(
+// ASAN-LABEL: define i32 @penguin(
+// ASAN:         call void @__asan_report_load4(i64 %0)
+// ASAN:         unreachable
+// ASAN:       }
+//
 // ASAN-RECOVER-LABEL: define i32 @penguin(
-// MSAN-LABEL:         define i32 @penguin(
+// ASAN-RECOVER:         call void @__asan_report_load4_noabort(
+// ASAN-RECOVER-NOT:     unreachable
+// ASAN:               }
+//
+// MSAN-LABEL: define i32 @penguin(
+// MSAN:         call void @__msan_warning_noreturn()
+// MSAN:         unreachable
+// MSAN:       }
+//
 // MSAN-RECOVER-LABEL: define i32 @penguin(
+// MSAN-RECOVER:         call void @__msan_warning()
+// MSAN-RECOVER-NOT:     unreachable
+// MSAN-RECOVER:       }
+//
+// MSAN-RECOVER-LTO-LABEL: define i32 @penguin(
+// MSAN-RECOVER-LTO:          call void @__msan_warning()
+// MSAN-RECOVER-LTO-NOT:      unreachable
+// MSAN-RECOVER-LTO:       }
+//
 #[no_mangle]
 pub fn penguin(p: &mut i32) -> i32 {
-    // ASAN:             call void @__asan_report_load4(i64 %0)
-    // ASAN:             unreachable
-    //
-    // ASAN-RECOVER:     call void @__asan_report_load4_noabort(
-    // ASAN-RECOVER-NOT: unreachable
-    //
-    // MSAN:             call void @__msan_warning_noreturn()
-    // MSAN:             unreachable
-    //
-    // MSAN-RECOVER:     call void @__msan_warning()
-    // MSAN-RECOVER-NOT: unreachable
     *p
 }
+
+fn main() {}