Stream: cranelift

Topic: cranelift-jit statically linked on musl


view this post on Zulip Terts Diepraam (Oct 15 2025 at 09:03):

Hi! I'm not sure whether this is even supposed to work, but I'm running into an issue with cranelift-jit on musl.

I can use cranelift-jit with my native target (x86_64-unknown-linux-gnu), but when I run my tests with --target=x86_64-unknown-linux-musl, the tests panic with this message:

thread 'codegen::tests::to_string' panicked at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/backend.rs:250:40:
can't resolve libcall memcpy
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/panicking.rs:75:14
   2: cranelift_jit::backend::JITModule::get_address::{{closure}}
             at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/backend.rs:250:40
   3: core::option::Option<T>::unwrap_or_else
             at /home/terts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1060:21
   4: cranelift_jit::backend::JITModule::get_address
             at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/backend.rs:250:22
   5: cranelift_jit::backend::JITModule::finalize_definitions::{{closure}}
             at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/backend.rs:326:50
   6: cranelift_jit::compiled_blob::CompiledBlob::perform_relocations
             at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/compiled_blob.rs:52:32
   7: cranelift_jit::backend::JITModule::finalize_definitions
             at /home/terts/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-jit-0.124.2/src/backend.rs:326:18
   8: roto::codegen::ModuleBuilder::finalize
             at ./src/codegen/mod.rs:573:20
< my own code omitted from the backtrace >

Is this a familiar issue to you? I couldn't really find any similar issues on GitHub. Thanks!

view this post on Zulip bjorn3 (Oct 15 2025 at 09:23):

When statically linking musl, dlsym will always return NULL. cranelift-jit tries to dlsym any function that isn't defined within the jitted module, which includes memcpy. You could try calling builder.symbol("memcpy", libc::memcpy as unsafe extern "C" fn(*mut c_void, *const c_void, size_t) -> *mut c_void as *const u8) on the JITBuilder to explicitly pass the address of memcpy.

view this post on Zulip Terts Diepraam (Oct 15 2025 at 09:30):

Ah that's unfortunate but a pretty good workaround! I'll try it. Thanks!


Last updated: Dec 06 2025 at 07:03 UTC