Skip to content

Allow loading of llvm plugins on nightly #86267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ use crate::{llvm, llvm_util};
use libc::c_int;
use rustc_codegen_ssa::target_features::supported_target_features;
use rustc_data_structures::fx::FxHashSet;
use rustc_metadata::dynamic_lib::DynamicLibrary;
use rustc_middle::bug;
use rustc_session::config::PrintRequest;
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use std::ffi::{CStr, CString};
use tracing::debug;

use std::path::Path;
use std::ptr;
use std::slice;
use std::str;
Expand Down Expand Up @@ -129,6 +132,15 @@ unsafe fn configure_llvm(sess: &Session) {

llvm::LLVMInitializePasses();

for plugin in &sess.opts.debugging_opts.llvm_plugins {
let path = Path::new(plugin);
let res = DynamicLibrary::open(path);
match res {
Ok(_) => debug!("configure_llvm: {}", plugin),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: tracing already includes information about functions and modules that the debug call is in. This should perhaps say more about what's being done here precisely:

Suggested change
Ok(_) => debug!("configure_llvm: {}", plugin),
Ok(_) => debug!("LLVM plugin loaded {} ({})", path.display(), plugin),

Or something along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I will update it in this case. But how about this section, is it outdated? https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#logging-etiquette-and-conventions

A loosely followed convention is to use debug!("foo(...)") at the start of a function foo and debug!("foo: ...") within the function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I wonder if that convention predates the use of tracing for logging. @oli-obk do you know?

Err(e) => bug!("couldn't load plugin: {}", e),
}
}

rustc_llvm::initialize_available_targets();

llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr());
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
tracked!(instrument_mcount, true);
tracked!(link_only, true);
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
tracked!(merge_functions, Some(MergeFunctions::Disabled));
tracked!(mir_emit_retag, true);
tracked!(mir_opt_level, Some(4));
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ options! {
"link native libraries in the linker invocation (default: yes)"),
link_only: bool = (false, parse_bool, [TRACKED],
"link the `.rlink` file generated by `-Z no-link` (default: no)"),
llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
"a list LLVM plugins to enable (space separated)"),
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
"generate JSON tracing data file from LLVM data (default: no)"),
ls: bool = (false, parse_bool, [UNTRACKED],
Expand Down