Skip to content
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

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

Open
KKould opened this issue Dec 30, 2023 · 2 comments
Labels

Comments

@KKould
Copy link

KKould commented Dec 30, 2023

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

@TheDan64
Copy link
Owner

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

@JCBurnside
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants