diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index aaf30c583e2..ba2a4d1d56f 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(