Mark __msan_track_origins as an exported symbol for LTO

This commit is contained in:
Nikita Popov 2020-01-19 22:08:15 +01:00 committed by Tomasz Miąsko
parent 66b0c97070
commit 2c0845c6cc
2 changed files with 12 additions and 2 deletions

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
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,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));
}
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));

View 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(