X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_codegen_llvm%2Fsrc%2Fllvm_util.rs;h=e4935ac431c8d8bcee2fbb7890377b0b450e5276;hb=3f2a1c9c1726d4d93e3433303262e44faa5910e9;hp=c3e7e7169a92c913934c223b7dfc60a522753a25;hpb=032dfe43605f4324966933078ffe6f717b77c7c8;p=rust.git diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index c3e7e7169a9..e4935ac431c 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -1,9 +1,10 @@ use crate::back::write::create_informational_target_machine; use crate::{llvm, llvm_util}; use libc::c_int; +use libloading::Library; use rustc_codegen_ssa::target_features::supported_target_features; use rustc_data_structures::fx::FxHashSet; -use rustc_metadata::dynamic_lib::DynamicLibrary; +use rustc_fs_util::path_to_c_string; use rustc_middle::bug; use rustc_session::config::PrintRequest; use rustc_session::Session; @@ -75,7 +76,9 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str { if sess.print_llvm_passes() { add("-debug-pass=Structure", false); } - if !sess.opts.debugging_opts.no_generate_arange_section { + if sess.target.generate_arange_section + && !sess.opts.debugging_opts.no_generate_arange_section + { add("-generate-arange-section", false); } @@ -118,14 +121,14 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str { llvm::LLVMInitializePasses(); + // Register LLVM plugins by loading them into the compiler process. for plugin in &sess.opts.debugging_opts.llvm_plugins { - let path = Path::new(plugin); - let res = DynamicLibrary::open(path); - match res { - Ok(_) => debug!("LLVM plugin loaded succesfully {} ({})", path.display(), plugin), - Err(e) => bug!("couldn't load plugin: {}", e), - } - mem::forget(res); + let lib = Library::new(plugin).unwrap_or_else(|e| bug!("couldn't load plugin: {}", e)); + debug!("LLVM plugin loaded successfully {:?} ({})", lib, plugin); + + // Intentionally leak the dynamic library. We can't ever unload it + // since the library can make things that will live arbitrarily long. + mem::forget(lib); } rustc_llvm::initialize_available_targets(); @@ -133,9 +136,9 @@ fn llvm_arg_to_arg_name(full_arg: &str) -> &str { llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr()); } -pub fn time_trace_profiler_finish(file_name: &str) { +pub fn time_trace_profiler_finish(file_name: &Path) { unsafe { - let file_name = CString::new(file_name).unwrap(); + let file_name = path_to_c_string(file_name); llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr()); } }