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

Build fails for target aarch64-unknown-linux-musl #2133

Closed
ifreund opened this issue Aug 16, 2020 · 6 comments
Closed

Build fails for target aarch64-unknown-linux-musl #2133

ifreund opened this issue Aug 16, 2020 · 6 comments
Labels
wasmtime:platform-support Related to supporting a new platform in Wasmtime

Comments

@ifreund
Copy link

ifreund commented Aug 16, 2020

I am currently in the process of packaging wasmtime for void linux, a distribution which supports multiple architectures and musl as an alternative to glibc.

Reading the following code, it looks like wasmtime is intended to support aarch64 on linux.

if #[cfg(all(target_os = "linux", target_arch = "x86_64"))] {
let cx = &*(cx as *const libc::ucontext_t);
cx.uc_mcontext.gregs[libc::REG_RIP as usize] as *const u8
} else if #[cfg(all(target_os = "linux", target_arch = "x86"))] {
let cx = &*(cx as *const libc::ucontext_t);
cx.uc_mcontext.gregs[libc::REG_EIP as usize] as *const u8
} else if #[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "aarch64"))] {
let cx = &*(cx as *const libc::ucontext_t);
cx.uc_mcontext.pc as *const u8
} else if #[cfg(target_os = "macos")] {
let cx = &*(cx as *const libc::ucontext_t);
(*cx.uc_mcontext).__ss.__rip as *const u8
} else {
compile_error!("unsupported platform");
}

It builds fine for aarch64-unknown-linux-gnu but fails for aarch64-unknown-linux-musl with the following error:

error[E0412]: cannot find type `ucontext_t` in crate `libc`

   --> crates/runtime/src/traphandlers.rs:165:52
    |
165 |                     let cx = &*(cx as *const libc::ucontext_t);
    |                                                    ^^^^^^^^^^ not found in `libc`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.
error: could not compile `wasmtime-runtime`.

Building for x86_64-unknown-linux-musl works fine.

This failure occurred with rust 1.44.1 and wasmtime 0.19.0

@ifreund ifreund added the bug Incorrect behavior in the current implementation that needs fixing label Aug 16, 2020
@pmengelbert
Copy link

pmengelbert commented Sep 25, 2020

I see that the issue has been patched and is resolved if I upgrade to the latest version of the libc crate, but then I come across this issue here:

error[E0609]: no field `pc` on type `libc::mcontext_t`
   --> crates/runtime/src/traphandlers.rs:166:36
    |
166 |                     cx.uc_mcontext.pc as *const u8
    |                                    ^^ unknown field

error: aborting due to previous error

Like @ifreund, building for the x86_64-unknown-linux-musl target works just fine. Any pointers on where to look? Thanks

@bjorn3
Copy link
Contributor

bjorn3 commented Sep 25, 2020

On aarch64-unknown-linux-musl libc doesn't expose any fields for mcontext_t: https://github.com/rust-lang/libc/blob/c9ff3e9b4e49b1a1c8482fc409177615dce6b84c/src/unix/linux_like/linux/musl/b64/aarch64/align.rs#L19 This will require a change to the libc crate.

@jiayihu
Copy link

jiayihu commented Dec 18, 2020

I'm having the same issue of @pmengelbert, is there any way to workaround for now? For instance fork libc and apply some patch. I'd test and open the PR myself if anyone can point me what to write. Should I just copy over this lines?

https://github.com/rust-lang/libc/blob/c9ff3e9b4e49b1a1c8482fc409177615dce6b84c/src/unix/linux_like/linux/gnu/b64/aarch64/align.rs#L19-L27

@lu-zero
Copy link
Contributor

lu-zero commented Dec 18, 2020

something along https://gist.github.com/lu-zero/e770b7c3c01277a7ccac51b2af692632 should fix it.

bors added a commit to rust-lang/libc that referenced this issue Dec 21, 2020
Populate mcontext_t on aarch64-linux-musl

It is used by wasmtime.

Should address bytecodealliance/wasmtime#2133
bors added a commit to rust-lang/libc that referenced this issue Dec 21, 2020
Populate mcontext_t on aarch64-linux-musl

It is used by wasmtime.

Should address bytecodealliance/wasmtime#2133
@alexcrichton alexcrichton added wasmtime:platform-support Related to supporting a new platform in Wasmtime and removed bug Incorrect behavior in the current implementation that needs fixing labels May 5, 2022
@alexcrichton
Copy link
Member

This build now currently works for this target, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:platform-support Related to supporting a new platform in Wasmtime
Projects
None yet
Development

No branches or pull requests

6 participants