Skip to content

Commit

Permalink
Plugin variant 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Mar 5, 2021
1 parent 1c77a1f commit 0149bc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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 @@ -10,6 +10,8 @@ use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use std::ffi::{CStr, CString};

use libc;

use std::slice;
use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -113,6 +115,16 @@ unsafe fn configure_llvm(sess: &Session) {
}

llvm::LLVMInitializePasses();

for plugin in &sess.opts.cg.llvm_plugins {
let path = CString::new(plugin.as_bytes()).unwrap();
let res = libc::dlopen(path.as_ptr(), libc::RTLD_LAZY | libc::RTLD_GLOBAL);
if res.is_null() {
println!("{}", CStr::from_ptr(libc::dlerror()).to_string_lossy().into_owned());
}
println!("{:p}", res);
println!("{}", plugin);
}

rustc_llvm::initialize_available_targets();

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 @@ -789,6 +789,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"generate build artifacts that are compatible with linker-based LTO"),
llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
"a list of arguments to pass to LLVM (space separated)"),
llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
"a list LLVM plugins to enable (space separated)"),
lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
"perform LLVM link-time optimizations"),
metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
Expand Down

0 comments on commit 0149bc4

Please sign in to comment.