]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #68410 - tmiasko:msan-lto, r=varkor
authorTyler Mandry <tmandry@gmail.com>
Thu, 23 Jan 2020 00:02:16 +0000 (16:02 -0800)
committerGitHub <noreply@github.com>
Thu, 23 Jan 2020 00:02:16 +0000 (16:02 -0800)
Export weak symbols used by MemorySanitizer

Export weak symbols defined by MemorySanitizer instrumentation, which are used
to implement `-Zsanitizer-memory-track-origins` and `-Zsanitizer-recover=memory`.
Previously, when using fat LTO, they would internalized and eliminated.

Fixes #68367.

src/librustc_codegen_ssa/back/symbol_export.rs
src/test/codegen/sanitizer-memory-track-orgins.rs
src/test/codegen/sanitizer-recover.rs

index bd44b4a38fd58c0c3572a23462214fab35b14610..d680e14bbbd5b9d884d7aa4bf6df547b8bb7d6f3 100644 (file)
@@ -3,7 +3,7 @@
 
 use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc::middle::exported_symbols::{metadata_symbol_name, ExportedSymbol, SymbolExportLevel};
-use rustc::session::config;
+use rustc::session::config::{self, Sanitizer};
 use rustc::ty::query::Providers;
 use rustc::ty::subst::SubstsRef;
 use rustc::ty::Instance;
@@ -206,6 +206,16 @@ 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.
+        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) {
         let symbol_name = metadata_symbol_name(tcx);
         let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
index fd8be0bced796372ad2dc55b65c43e8a00fea4a5..1fd496b35dfcce3d651e6a01ec3c6ab3472ae0a2 100644 (file)
@@ -4,17 +4,21 @@
 // needs-sanitizer-support
 // only-linux
 // only-x86_64
-// revisions:MSAN-0 MSAN-1 MSAN-2
+// revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO
 //
 //[MSAN-0] compile-flags: -Zsanitizer=memory
 //[MSAN-1] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins=1
 //[MSAN-2] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins
+//[MSAN-1-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins=1 -C lto=fat
+//[MSAN-2-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins -C lto=fat
 
 #![crate_type="lib"]
 
 // MSAN-0-NOT: @__msan_track_origins
 // MSAN-1:     @__msan_track_origins = weak_odr local_unnamed_addr constant i32 1
 // MSAN-2:     @__msan_track_origins = weak_odr local_unnamed_addr constant i32 2
+// MSAN-1-LTO: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 1
+// MSAN-2-LTO: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 2
 //
 // MSAN-0-LABEL: define void @copy(
 // MSAN-1-LABEL: define void @copy(
index a292332667b54260d8148a312fd0d6494a0cc7c2..9a583725b0bf0c42d81e353341a964cacfbcd101 100644 (file)
@@ -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() {}