Skip to content

Commit 2c0845c

Browse files
nikictmiasko
authored andcommitted
Mark __msan_track_origins as an exported symbol for LTO
1 parent 66b0c97 commit 2c0845c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/librustc_codegen_ssa/back/symbol_export.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
55
use rustc::middle::exported_symbols::{metadata_symbol_name, ExportedSymbol, SymbolExportLevel};
6-
use rustc::session::config;
6+
use rustc::session::config::{self, Sanitizer};
77
use rustc::ty::query::Providers;
88
use rustc::ty::subst::SubstsRef;
99
use rustc::ty::Instance;
@@ -206,6 +206,12 @@ fn exported_symbols_provider_local(
206206
}));
207207
}
208208

209+
if let Some(Sanitizer::Memory) = tcx.sess.opts.debugging_opts.sanitizer {
210+
// 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));
213+
}
214+
209215
if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) {
210216
let symbol_name = metadata_symbol_name(tcx);
211217
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));

src/test/codegen/sanitizer-memory-track-orgins.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
// needs-sanitizer-support
55
// only-linux
66
// only-x86_64
7-
// revisions:MSAN-0 MSAN-1 MSAN-2
7+
// revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO
88
//
99
//[MSAN-0] compile-flags: -Zsanitizer=memory
1010
//[MSAN-1] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins=1
1111
//[MSAN-2] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins
12+
//[MSAN-1-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins=1 -C lto=fat
13+
//[MSAN-2-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins -C lto=fat
1214

1315
#![crate_type="lib"]
1416

1517
// MSAN-0-NOT: @__msan_track_origins
1618
// MSAN-1: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 1
1719
// MSAN-2: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 2
20+
// MSAN-1-LTO: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 1
21+
// MSAN-2-LTO: @__msan_track_origins = weak_odr local_unnamed_addr constant i32 2
1822
//
1923
// MSAN-0-LABEL: define void @copy(
2024
// MSAN-1-LABEL: define void @copy(

0 commit comments

Comments
 (0)