Skip to content

Commit cd748ab

Browse files
authored
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
2 parents 404e067 + 9f23b2d commit cd748ab

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/librustc_metadata/creader.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ impl<'a> CrateLoader<'a> {
686686
}
687687

688688
fn inject_profiler_runtime(&mut self) {
689-
if self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled() {
689+
if (self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled())
690+
&& !self.sess.opts.debugging_opts.no_profiler_runtime
691+
{
690692
info!("loading profiler");
691693

692694
let name = Symbol::intern("profiler_builtins");

src/librustc_session/config.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
16551655
let output_types = parse_output_types(&debugging_opts, matches, error_format);
16561656

16571657
let mut cg = build_codegen_options(matches, error_format);
1658-
let (disable_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto(
1658+
let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
16591659
&output_types,
16601660
matches,
16611661
error_format,
@@ -1672,6 +1672,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
16721672
"can't instrument with gcov profiling when compiling incrementally",
16731673
);
16741674
}
1675+
if debugging_opts.profile {
1676+
match codegen_units {
1677+
Some(1) => {}
1678+
None => codegen_units = Some(1),
1679+
Some(_) => early_error(
1680+
error_format,
1681+
"can't instrument with gcov profiling with multiple codegen units",
1682+
),
1683+
}
1684+
}
16751685

16761686
if cg.profile_generate.enabled() && cg.profile_use.is_some() {
16771687
early_error(

src/librustc_session/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
890890
"extra arguments to prepend to the linker invocation (space separated)"),
891891
profile: bool = (false, parse_bool, [TRACKED],
892892
"insert profiling code"),
893+
no_profiler_runtime: bool = (false, parse_bool, [TRACKED],
894+
"don't automatically inject the profiler_builtins crate"),
893895
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
894896
"choose which RELRO level to use"),
895897
nll_facts: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)