Skip to content

Commit 3630b97

Browse files
authored
Merge pull request rust-lang#113 from TheDan64/dont_link_owned_module
Don't allow linking in owned module
2 parents c21a157 + deb075a commit 3630b97

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/module.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1285,13 +1285,17 @@ impl Module {
12851285
/// assert!(module.link_in_module(module2).is_ok());
12861286
/// ```
12871287
pub fn link_in_module(&self, other: Self) -> Result<(), LLVMString> {
1288-
// REVIEW: Check if owned by EE? test_linking_modules seems OK as is...
1288+
if other.owned_by_ee.borrow().is_some() {
1289+
let string = "Cannot link a module which is already owned by an ExecutionEngine.\0";
1290+
return Err(LLVMString::create(string));
1291+
}
12891292

12901293
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
12911294
{
12921295
use llvm_sys::linker::{LLVMLinkerMode, LLVMLinkModules};
12931296

12941297
let mut err_string = ptr::null_mut();
1298+
// As of 3.7, LLVMLinkerDestroySource is the only option
12951299
let mode = LLVMLinkerMode::LLVMLinkerDestroySource;
12961300
let code = unsafe {
12971301
LLVMLinkModules(self.module.get(), other.module.get(), mode, &mut err_string)

tests/all/test_module.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,9 @@ fn test_linking_modules() {
415415

416416
let execution_engine2 = module6.create_jit_execution_engine(OptimizationLevel::None).expect("Could not create Execution Engine");
417417

418-
// EE owned module links in EE owned module
419-
assert!(module.link_in_module(module6).is_ok());
420-
421-
// EE2 still seems to "work" despite merging module6 into module...
422-
// But f4 is now missing from EE2 (though this is expected, I'm really
423-
// suprised it "just works" without segfault TBH)
424-
// TODO: Test this much more thoroughly
425-
#[cfg(feature = "llvm3-6")] // Likely a LLVM bug that 3-6 says ok, but others don't
418+
// EE owned module cannot link another EE owned module
419+
assert!(module.link_in_module(module6).is_err());
426420
assert_eq!(execution_engine2.get_function_value("f4"), Ok(fn_val4));
427-
#[cfg(not(feature = "llvm3-6"))]
428-
assert_ne!(execution_engine2.get_function_value("f4"), Ok(fn_val4));
429421
}
430422

431423
#[test]

0 commit comments

Comments
 (0)