TheDan64/inkwell

after importing LLVM IR, a segmentation fault occurs when calling its internal method

KKould opened this issue · 2 comments

Describe the Bug
after importing LLVM IR, a segmentation fault occurs when calling its internal method

To Reproduce
sum.rs

#[no_mangle]
fn hello() {
    println!("hello world");
}

fn main() {}

main.rs

fn main() {
    let context = Context::create();
    let memory = MemoryBuffer::create_from_file("./sum.ll".as_ref()).unwrap();
    let module = context.create_module_from_ir(memory).unwrap();
    let ee = module
        .create_jit_execution_engine(OptimizationLevel::None)
        .unwrap();
    unsafe {
        let fn_hello = ee.get_function::<unsafe extern "C" fn()>("hello").unwrap();

        fn_hello.call();
    }
}

I first use rustc --emit=llvm-ir /home/kould/rust-llvm-practises/helloworld/src/example/sum.rs to convert sum.rs to LLVM IR sum.ll, and then call the hello method after importing it as a Module

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

Expected Behavior
displayed in terminal

hello world

LLVM Version (please complete the following information):

  • LLVM Version: 16.0.0
  • Inkwell Branch Used: inkwell = { version = "0.2.0", features = ["llvm16-0"] }
  • rustc: 1.69.0

Desktop (please complete the following information):

  • OS: WSL Ubuntu 20.04.6 LTS

Additional Context

Doesn't hello have to be extern "C"? Not sure no mangle is enough

I don't think extern "C" changes anything here since all types are already in a c compatible arrangement but can't hurt