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

Encountering Problem When Compiling Jolt as Dynamic Library #346

Open
khandar-william opened this issue May 7, 2024 · 0 comments
Open

Comments

@khandar-william
Copy link

khandar-william commented May 7, 2024

I'm trying to compile a Rust program that uses Jolt as a dynamic library (cdylib).
But libloading crate failed to load the compiled library (.so file).

thread 'main' panicked at src/main.rs:8:58:
called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../lib-producer/target/release/liblib_producer.so: undefined symbol: _HEAP_PTR" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To demonstrate the issue, I have provided the complete code in this repository .

There are 3 apps:

  • guest is the sample fibonacci guest code
  • lib-producer is a Rust library package
    • dependency: jolt-sdk and guest
    • target [lib] crate-type = ["rlib", "cdylib"]
    • in src/lib.rs it exports C functions arbitrary_string and execute_guest_code
    • it produces lib-producer/target/release/liblib_producer.so file
  • lib-consumer is a Rust app that will load the lib-producer/target/release/liblib_producer.so file and call the functions inside
    • dependency: libloading

In lib-producer/src/lib.rs, it exports function like this:

#[no_mangle]
#[allow(improper_ctypes_definitions)]
pub extern "C" fn arbitrary_string() -> String {
    "Hello, World!".to_string()
}

Then in lib-consumer/src/main.rs, it loads the dynamic library file and calls the function

    unsafe {
        // Load dynamic library
        let lib = libloading::Library::new(LIBRARY_PATH).unwrap(); // Error happened here, before executing any function inside

        // Execute arbitrary_string()
        let arbitrary_string_fn: libloading::Symbol<unsafe extern "C" fn() -> String> = lib
            .get(b"arbitrary_string")
            .unwrap();
        let arbitrary_string = arbitrary_string_fn();
        println!("arbitrary_string: {:?}", arbitrary_string);
}

You can see the complete code here.

So, first I run cargo build -r in lib-producer.
Then I run cargo run in lib-consumer.
But I always got this error:

thread 'main' panicked at src/main.rs:8:58:
called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../lib-producer/target/release/liblib_producer.so: undefined symbol: _HEAP_PTR" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Do you know what happened here?
Thank you.

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

No branches or pull requests

1 participant