Rollup merge of #71283 - Amanieu:zprofile, r=davidtwco

Minor improvements to -Zprofile

- `-Zprofile` is broken with codegen units because GCOV assumes that each source file corresponds to one object file. This PR makes `-Zprofile` automatically set codegen units to 1 and gives an error if `-Ccodegen-units=X` is specified on the command line (with `X != 1`).
- The `profiler_builtins` crate is not suitable for `no_std` applications since it contains C code that depends on libc. In such cases a custom implementation of the LLVM gcov API (`llvm_gcov_init`, `llvm_gcda_*`) is needed. This PR adds `-Zno-profiler-runtime` flag which inhibits automatic injection of the `profiler_builtins` crate.

cc @whitequark who implemented the original `-Zprofile` support
This commit is contained in:
Dylan DPC 2020-04-19 01:04:53 +02:00 committed by GitHub
commit cd748abc56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -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");

View File

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

View File

@ -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<RelroLevel> = (None, parse_relro_level, [TRACKED],
"choose which RELRO level to use"),
nll_facts: bool = (false, parse_bool, [UNTRACKED],