Skip to content

Commit 0149bc4

Browse files
committed
Plugin variant 2
1 parent 1c77a1f commit 0149bc4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use rustc_span::symbol::Symbol;
1010
use rustc_target::spec::{MergeFunctions, PanicStrategy};
1111
use std::ffi::{CStr, CString};
1212

13+
use libc;
14+
1315
use std::slice;
1416
use std::str;
1517
use std::sync::atomic::{AtomicBool, Ordering};
@@ -113,6 +115,16 @@ unsafe fn configure_llvm(sess: &Session) {
113115
}
114116

115117
llvm::LLVMInitializePasses();
118+
119+
for plugin in &sess.opts.cg.llvm_plugins {
120+
let path = CString::new(plugin.as_bytes()).unwrap();
121+
let res = libc::dlopen(path.as_ptr(), libc::RTLD_LAZY | libc::RTLD_GLOBAL);
122+
if res.is_null() {
123+
println!("{}", CStr::from_ptr(libc::dlerror()).to_string_lossy().into_owned());
124+
}
125+
println!("{:p}", res);
126+
println!("{}", plugin);
127+
}
116128

117129
rustc_llvm::initialize_available_targets();
118130

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
789789
"generate build artifacts that are compatible with linker-based LTO"),
790790
llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
791791
"a list of arguments to pass to LLVM (space separated)"),
792+
llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
793+
"a list LLVM plugins to enable (space separated)"),
792794
lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
793795
"perform LLVM link-time optimizations"),
794796
metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],

0 commit comments

Comments
 (0)