]> git.lizzy.rs Git - rust.git/commitdiff
Conditionally export msan symbols only if they are defined
authorGary Guo <gary@garyguo.net>
Mon, 18 Apr 2022 01:58:33 +0000 (02:58 +0100)
committerGary Guo <gary@garyguo.net>
Mon, 18 Apr 2022 19:50:56 +0000 (20:50 +0100)
* `__msan_keep_going` is defined when `-Zsanitizer-recover=memory`.
* `__msan_track_origins` is defined when `-Zsanitizer-memory-track-origins`.

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

index 56159cc2e08c54c8947736a3d79144e37993409b..2fa6778cca4d76b9ce6a191d79ea8ce3268a9b1d 100644 (file)
@@ -241,10 +241,18 @@ fn exported_symbols_provider_local<'tcx>(
     }
 
     if tcx.sess.opts.debugging_opts.sanitizer.contains(SanitizerSet::MEMORY) {
+        let mut msan_weak_symbols = Vec::new();
+
         // Similar to profiling, preserve weak msan symbol during LTO.
-        const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
+        if tcx.sess.opts.debugging_opts.sanitizer_recover.contains(SanitizerSet::MEMORY) {
+            msan_weak_symbols.push("__msan_keep_going");
+        }
+
+        if tcx.sess.opts.debugging_opts.sanitizer_memory_track_origins != 0 {
+            msan_weak_symbols.push("__msan_track_origins");
+        }
 
-        symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
+        symbols.extend(msan_weak_symbols.into_iter().map(|sym| {
             let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
             (
                 exported_symbol,