-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples Segfault on OS X (LLVM 3.8.1) #25
Comments
I have managed to prove that this segfault is due to a double-free on the diff --git a/examples/add.rs b/examples/add.rs
index 9050176..f1f8cf0 100644
--- a/examples/add.rs
+++ b/examples/add.rs
@@ -1,21 +1,25 @@
extern crate llvm;
+use std::mem;
use llvm::*;
use llvm::Attribute::*;
fn main() {
let ctx = Context::new();
let module = Module::new("add", &ctx);
- let func = module.add_function("add", Type::get::<fn(f64, f64) -> f64>(&ctx));
- func.add_attributes(&[NoUnwind, ReadNone]);
- let entry = func.append("entry");
- let builder = Builder::new(&ctx);
- builder.position_at_end(entry);
- let a = &func[0];
- let b = &func[1];
- let value = builder.build_add(a, b);
- builder.build_ret(value);
- module.verify().unwrap();
- let ee = JitEngine::new(&module, JitOptions {opt_level: 3}).unwrap();
- ee.with_function(func, |add:extern fn((f64, f64)) -> f64| {
- println!("{} + {} = {}", 1., 2., add((1., 2.)));
- });
+ {
+ let func = module.add_function("add", Type::get::<fn(f64, f64) -> f64>(&ctx));
+ func.add_attributes(&[NoUnwind, ReadNone]);
+ let entry = func.append("entry");
+ let builder = Builder::new(&ctx);
+ builder.position_at_end(entry);
+ let a = &func[0];
+ let b = &func[1];
+ let value = builder.build_add(a, b);
+ builder.build_ret(value);
+ module.verify().unwrap();
+ let ee = JitEngine::new(&module, JitOptions {opt_level: 3}).unwrap();
+ ee.with_function(func, |add:extern fn((f64, f64)) -> f64| {
+ println!("{} + {} = {}", 1., 2., add((1., 2.)));
+ });
+ }
+ mem::forget(module);
} I guess this means that |
For anyone still concerned: you can also solve this issue by removing the module from the ExecutionEngine before the engine is dropped, i.e. |
Could the execution engine take ownership of the module when created so that Rust's ownership semantics protect us in this case? |
This fixes TomBebbington#25 by removing the compiled module from the execution engine before the engine is `free`'d.
I'm compiling on OS X with
rustc 1.13.0-nightly (f883b0bba 2016-08-19)
and LLVM3.8.1
from Homebrew.When running any of the examples I receive a segfault:
This seems to be from the drop implementation for
Module
I think this is because the
JitEngine
has taken ownership of the module and dropped it already.The text was updated successfully, but these errors were encountered: