diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 3e5d7b8efd530..fe8fbd50627d3 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -686,7 +686,9 @@ impl<'a> CrateLoader<'a> { } fn inject_profiler_runtime(&mut self) { - if self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled() { + if (self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled()) + && !self.sess.opts.debugging_opts.no_profiler_runtime + { info!("loading profiler"); let name = Symbol::intern("profiler_builtins"); diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index aaf30c583e263..ba2a4d1d56f23 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -1655,7 +1655,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let output_types = parse_output_types(&debugging_opts, matches, error_format); let mut cg = build_codegen_options(matches, error_format); - let (disable_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto( + let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto( &output_types, matches, error_format, @@ -1672,6 +1672,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { "can't instrument with gcov profiling when compiling incrementally", ); } + if debugging_opts.profile { + match codegen_units { + Some(1) => {} + None => codegen_units = Some(1), + Some(_) => early_error( + error_format, + "can't instrument with gcov profiling with multiple codegen units", + ), + } + } if cg.profile_generate.enabled() && cg.profile_use.is_some() { early_error( diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 8cd6ca86f4689..94e65093e71b2 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -890,6 +890,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "extra arguments to prepend to the linker invocation (space separated)"), profile: bool = (false, parse_bool, [TRACKED], "insert profiling code"), + no_profiler_runtime: bool = (false, parse_bool, [TRACKED], + "don't automatically inject the profiler_builtins crate"), relro_level: Option = (None, parse_relro_level, [TRACKED], "choose which RELRO level to use"), nll_facts: bool = (false, parse_bool, [UNTRACKED],