Provide option for specifying the profiler runtime
Currently, if `-Zinstrument-coverage` is enabled, the target is linked against the `library/profiler_builtins` crate (which pulls in LLVM's compiler-rt runtime). This option enables backends to specify an alternative runtime crate for handling injected instrumentation calls.
This commit is contained in:
parent
69b352ef77
commit
93c636211c
4 changed files with 26 additions and 20 deletions
|
@ -769,27 +769,31 @@ impl<'a> CrateLoader<'a> {
|
|||
}
|
||||
|
||||
fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
|
||||
if (self.sess.instrument_coverage()
|
||||
if self.sess.instrument_coverage()
|
||||
|| self.sess.opts.debugging_opts.profile
|
||||
|| self.sess.opts.cg.profile_generate.enabled())
|
||||
&& !self.sess.opts.debugging_opts.no_profiler_runtime
|
||||
|| self.sess.opts.cg.profile_generate.enabled()
|
||||
{
|
||||
info!("loading profiler");
|
||||
if let Some(name) =
|
||||
self.sess.opts.debugging_opts.profiler_runtime.as_deref().map(Symbol::intern)
|
||||
{
|
||||
info!("loading profiler");
|
||||
|
||||
if self.sess.contains_name(&krate.attrs, sym::no_core) {
|
||||
self.sess.err(
|
||||
"`profiler_builtins` crate (required by compiler options) \
|
||||
is not compatible with crate attribute `#![no_core]`",
|
||||
);
|
||||
}
|
||||
if name == sym::profiler_builtins
|
||||
&& self.sess.contains_name(&krate.attrs, sym::no_core)
|
||||
{
|
||||
self.sess.err(
|
||||
"`profiler_builtins` crate (required by compiler options) \
|
||||
is not compatible with crate attribute `#![no_core]`",
|
||||
);
|
||||
}
|
||||
|
||||
let name = sym::profiler_builtins;
|
||||
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
|
||||
let data = self.cstore.get_crate_data(cnum);
|
||||
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
|
||||
let data = self.cstore.get_crate_data(cnum);
|
||||
|
||||
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
||||
if !data.is_profiler_runtime() {
|
||||
self.sess.err("the crate `profiler_builtins` is not a profiler runtime");
|
||||
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
||||
if !data.is_profiler_runtime() {
|
||||
self.sess.err(&format!("the crate `{}` is not a profiler runtime", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1100,7 +1100,9 @@ impl CrateError {
|
|||
if sess.is_nightly_build() && std::env::var("CARGO").is_ok() {
|
||||
err.help("consider building the standard library from source with `cargo build -Zbuild-std`");
|
||||
}
|
||||
} else if crate_name == sym::profiler_builtins {
|
||||
} else if Some(crate_name)
|
||||
== sess.opts.debugging_opts.profiler_runtime.as_deref().map(Symbol::intern)
|
||||
{
|
||||
err.note(&"the compiler may have been built without the profiler runtime");
|
||||
}
|
||||
err.span_label(span, "can't find crate");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue