File tree 2 files changed +7
-11
lines changed
2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -1285,13 +1285,17 @@ impl Module {
1285
1285
/// assert!(module.link_in_module(module2).is_ok());
1286
1286
/// ```
1287
1287
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
+ }
1289
1292
1290
1293
#[ cfg( any( feature = "llvm3-6" , feature = "llvm3-7" ) ) ]
1291
1294
{
1292
1295
use llvm_sys:: linker:: { LLVMLinkerMode , LLVMLinkModules } ;
1293
1296
1294
1297
let mut err_string = ptr:: null_mut ( ) ;
1298
+ // As of 3.7, LLVMLinkerDestroySource is the only option
1295
1299
let mode = LLVMLinkerMode :: LLVMLinkerDestroySource ;
1296
1300
let code = unsafe {
1297
1301
LLVMLinkModules ( self . module . get ( ) , other. module . get ( ) , mode, & mut err_string)
Original file line number Diff line number Diff line change @@ -415,17 +415,9 @@ fn test_linking_modules() {
415
415
416
416
let execution_engine2 = module6. create_jit_execution_engine ( OptimizationLevel :: None ) . expect ( "Could not create Execution Engine" ) ;
417
417
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( ) ) ;
426
420
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) ) ;
429
421
}
430
422
431
423
#[ test]
You can’t perform that action at this time.
0 commit comments