diff options
| author | Alan Egerton <eggyal@gmail.com> | 2021-05-14 11:07:06 +0100 |
|---|---|---|
| committer | Alan Egerton <eggyal@gmail.com> | 2021-05-17 08:31:33 +0100 |
| commit | 93c636211ca4b0b7745d6d4ca82587a27ddc59a8 (patch) | |
| tree | c5718ebf7da48b19cc3cfd387deb5925efbba2de /compiler/rustc_metadata/src/creader.rs | |
| parent | 69b352ef7749825abde2d8f8e31c05f681e61a10 (diff) | |
| download | rust-93c636211ca4b0b7745d6d4ca82587a27ddc59a8.tar.gz rust-93c636211ca4b0b7745d6d4ca82587a27ddc59a8.zip | |
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.
Diffstat (limited to 'compiler/rustc_metadata/src/creader.rs')
| -rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index e9ae22f8ced..8108470e3d3 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -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 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 let Some(name) = + self.sess.opts.debugging_opts.profiler_runtime.as_deref().map(Symbol::intern) + { + info!("loading profiler"); + + 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)); + } } } } |
