X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_metadata%2Fcreader.rs;h=181f872154c5107e55776b767d5c7a358bf23713;hb=72aaa3a414d17aa0c4f19feafa5bab5f84b60e63;hp=b21715fadfe6f899b1caa4c8c03b6c13bc10c376;hpb=2c3e5d3de023c0bfbf4a4c4d3b0d7a9844e96ffe;p=rust.git diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index b21715fadfe..181f872154c 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -6,32 +6,29 @@ use rustc::hir::map::Definitions; use rustc::middle::cstore::DepKind; use rustc::middle::cstore::{CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn}; -use rustc::session::config::{self, Sanitizer}; +use rustc::session::config; use rustc::session::search_paths::PathKind; use rustc::session::{CrateDisambiguator, Session}; use rustc::ty::TyCtxt; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; -use rustc_hir::def_id::CrateNum; -use rustc_hir::def_id::LOCAL_CRATE; -use rustc_index::vec::IndexVec; -use rustc_target::spec::{PanicStrategy, TargetTriple}; - -use std::path::Path; -use std::{cmp, fs}; - -use errors::struct_span_err; -use log::{debug, info, log_enabled}; -use proc_macro::bridge::client::ProcMacro; +use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_expand::base::SyntaxExtension; +use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; +use rustc_index::vec::IndexVec; use rustc_span::edition::Edition; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; +use rustc_target::spec::{PanicStrategy, TargetTriple}; use syntax::ast; use syntax::attr; use syntax::expand::allocator::{global_allocator_spans, AllocatorKind}; -use rustc_error_codes::*; +use log::{debug, info, log_enabled}; +use proc_macro::bridge::client::ProcMacro; +use std::path::Path; +use std::{cmp, fs}; #[derive(Clone)] pub struct CStore { @@ -674,108 +671,6 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) { self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime()); } - fn inject_sanitizer_runtime(&mut self) { - if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer { - // Sanitizers can only be used on some tested platforms with - // executables linked to `std` - const ASAN_SUPPORTED_TARGETS: &[&str] = - &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]; - const TSAN_SUPPORTED_TARGETS: &[&str] = - &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]; - const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; - const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"]; - - let supported_targets = match *sanitizer { - Sanitizer::Address => ASAN_SUPPORTED_TARGETS, - Sanitizer::Thread => TSAN_SUPPORTED_TARGETS, - Sanitizer::Leak => LSAN_SUPPORTED_TARGETS, - Sanitizer::Memory => MSAN_SUPPORTED_TARGETS, - }; - if !supported_targets.contains(&&*self.sess.opts.target_triple.triple()) { - self.sess.err(&format!( - "{:?}Sanitizer only works with the `{}` target", - sanitizer, - supported_targets.join("` or `") - )); - return; - } - - // firstyear 2017 - during testing I was unable to access an OSX machine - // to make this work on different crate types. As a result, today I have - // only been able to test and support linux as a target. - if self.sess.opts.target_triple.triple() == "x86_64-unknown-linux-gnu" { - if !self.sess.crate_types.borrow().iter().all(|ct| { - match *ct { - // Link the runtime - config::CrateType::Executable => true, - // This crate will be compiled with the required - // instrumentation pass - config::CrateType::Staticlib - | config::CrateType::Rlib - | config::CrateType::Dylib - | config::CrateType::Cdylib => false, - _ => { - self.sess.err(&format!( - "Only executables, staticlibs, \ - cdylibs, dylibs and rlibs can be compiled with \ - `-Z sanitizer`" - )); - false - } - } - }) { - return; - } - } else { - if !self.sess.crate_types.borrow().iter().all(|ct| { - match *ct { - // Link the runtime - config::CrateType::Executable => true, - // This crate will be compiled with the required - // instrumentation pass - config::CrateType::Rlib => false, - _ => { - self.sess.err(&format!( - "Only executables and rlibs can be \ - compiled with `-Z sanitizer`" - )); - false - } - } - }) { - return; - } - } - - let mut uses_std = false; - self.cstore.iter_crate_data(|_, data| { - if data.name() == sym::std { - uses_std = true; - } - }); - - if uses_std { - let name = Symbol::intern(match sanitizer { - Sanitizer::Address => "rustc_asan", - Sanitizer::Leak => "rustc_lsan", - Sanitizer::Memory => "rustc_msan", - Sanitizer::Thread => "rustc_tsan", - }); - info!("loading sanitizer: {}", name); - - let cnum = self.resolve_crate(name, DUMMY_SP, DepKind::Explicit, None); - let data = self.cstore.get_crate_data(cnum); - - // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime - if !data.is_sanitizer_runtime() { - self.sess.err(&format!("the crate `{}` is not a sanitizer runtime", name)); - } - } else { - self.sess.err("Must link std to be compiled with `-Z sanitizer`"); - } - } - } - fn inject_profiler_runtime(&mut self) { if self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled() { info!("loading profiler"); @@ -927,7 +822,6 @@ fn inject_dependency_if( } pub fn postprocess(&mut self, krate: &ast::Crate) { - self.inject_sanitizer_runtime(); self.inject_profiler_runtime(); self.inject_allocator_crate(krate); self.inject_panic_runtime(krate);