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

Failure to load LLVM-compiled WASM: undefined symbol: wasmer_raise_trap #2107

Closed
dotxlem opened this issue Feb 11, 2021 · 13 comments
Closed
Labels
bug Something isn't working priority-medium Medium priority issue 🏚 stale Inactive issues or PR

Comments

@dotxlem
Copy link

dotxlem commented Feb 11, 2021

Describe the bug

I have written an executable which compiles WASM via LLVM and serializes the module to disk.

I am attempting to cross-compile to Amazon Linux via target triple x86_64-linux-unknown, from macOS 11.1 (uname: Darwin xlembox.local 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64).

On the Linux side, another executable attempts to load the binary to run via the Native engine in headless mode:

let store = Store::new(&Native::headless().engine());
let module = unsafe { Module::deserialize_from_file(&store, file_path) }.unwrap();

Deserialize panics on the unwrap with

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CorruptedBinary("Library loading failed: /var/task/put-iomod-at.wasm.bin: undefined symbol: wasmer_raise_trap")', backends/aws-lambda/host/src/wasm.rs:28:78

Steps to reproduce

  1. Cross-compile WASM to module binary via LLVM and serialize the result.
  2. Load & deserialize the binary on the compilation target

Expected behavior

The module loads and executes via the native headless engine.

Actual behavior

Deserialize panics with CorruptedBinary error.

Additional context

This process works when using Cranelift instead of LLVM.

Snippet of code I use to cross-compile:

let mut compiler = LLVM::default();
let triple = Triple::from_str("x86_64-linux-unknown").unwrap();
let mut cpuid = CpuFeature::set();
cpuid.insert(CpuFeature::from_str("sse2").unwrap());
cpuid.insert(CpuFeature::from_str("avx2").unwrap());
let store = Store::new(&Native::new(compiler)
    target(Target::new(triple, cpuid))
    .engine()
);

let wasm_bytes = match fs::read(wasm_path) {
    Ok(bytes) => bytes,
    Err(err) => panic!(err.to_string()),
};
let module = Module::new(&store, wasm_bytes).unwrap();
let module_bytes = module.serialize().unwrap();
@dotxlem dotxlem added the bug Something isn't working label Feb 11, 2021
@nlewycky
Copy link
Contributor

The final binary that uses engine-native must link with a flag that exposes the wasmer VM functions to the shared object that we load. Here's our .cargo/cargo.toml: https://github.com/wasmerio/wasmer/blob/master/.cargo/config.toml . Try adding that to your project!

@dotxlem
Copy link
Author

dotxlem commented Feb 13, 2021

Thanks @nlewycky! Unfortunately I haven't been able to test this yet -- I'm running into issues getting LLVM running in my build container.

Will report back when I'm up and running again :)

@nlewycky
Copy link
Contributor

nlewycky commented Mar 30, 2021

Is that .cargo/config for the program that is being compiled into a .wasm? You need to update the native program that is using wasmer as a library, not the build of the .wasm code.

This .cargo/config needs to go on the Linux-side program that uses wasmer as a library to load the compiled .so file that was produced by compiling the .wasm:

[target.'cfg(target_os = "linux")']
rustflags = [
    # Put the VM functions in the dynamic symbol table.
    "-C", "link-arg=-Wl,-E",
]

@dotxlem
Copy link
Author

dotxlem commented Mar 30, 2021

Sorry I deleted my comment, I realized after that it likely wasn't supposed to go on the .wasm

However I also have it on the host binary which loads the .wasm, with the same result :(

@nlewycky
Copy link
Contributor

It sounds like you have two binaries, one on a mac which loads the .wasm and compiles to .so, and another on linux which loads the .so. Is that right? If so, this needs to go on the Linux one. If that still isn't working, I'll check for a bug where we pick the symbols names, maybe we're accidentally picking host names instead of target names or something like that.

@dotxlem
Copy link
Author

dotxlem commented Mar 30, 2021

I can confirm that I have the config.toml defined for the linux binary; is there a way to inspect the binary itself to make sure it's worked?

If it's helpful at all, the linux binary is running in Docker under Alpine 3.13 & linked against glibc-2.32

@nlewycky
Copy link
Contributor

I could use some help reproducing the issue, I've set up Alpine 3.14 with glibc 2.33 using packages from https://github.com/sgerrand/alpine-pkg-glibc but building with cargo build --target x86_64-unknown-linux-gnu produces a binary that uses ld-musl and has an unrelated error involving mapping too much memory.

@Hywan
Copy link
Contributor

Hywan commented Jul 16, 2021

This issue may be fixed by #2475.

@syrusakbary
Copy link
Member

We could solve this by having libcalls in the compilers be resolved by traversing the VMContext rather than using a static pointer at compile time

@stale
Copy link

stale bot commented Dec 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 🏚 stale Inactive issues or PR label Dec 13, 2022
@stale
Copy link

stale bot commented Jan 13, 2023

Feel free to reopen the issue if it has been closed by mistake.

@stale stale bot closed this as completed Jan 13, 2023
@syrusakbary syrusakbary reopened this Jan 13, 2023
@stale stale bot removed the 🏚 stale Inactive issues or PR label Jan 13, 2023
Copy link

stale bot commented Jan 15, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 🏚 stale Inactive issues or PR label Jan 15, 2024
Copy link

stale bot commented Feb 14, 2024

Feel free to reopen the issue if it has been closed by mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-medium Medium priority issue 🏚 stale Inactive issues or PR
Projects
Development

Successfully merging a pull request may close this issue.

4 participants