a16z / jolt

The simplest and most extensible zkVM. Fast and fully open source from a16z crypto and friends. ⚡
https://jolt.a16zcrypto.com
MIT License
655 stars 137 forks source link

Encountering Problem When Compiling Jolt as Dynamic Library #346

Open khandar-william opened 5 months ago

khandar-william commented 5 months ago

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:

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.