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

AArch64 Android compilation fails: unsupported platform #1998

Closed
Rochet2 opened this issue Jul 9, 2020 · 2 comments
Closed

AArch64 Android compilation fails: unsupported platform #1998

Rochet2 opened this issue Jul 9, 2020 · 2 comments

Comments

@Rochet2
Copy link
Contributor

Rochet2 commented Jul 9, 2020

Error

When compiling wasmtime for android aarch64, an error occurs:

$ cargo +nightly build --target aarch64-linux-android --release
   Compiling wasmtime-runtime v0.18.0 (/home/local/rimi/Documents/test/wasmtimetest/android_runtime/wasmtime/crates/runtime)
error: unsupported platform
   --> wasmtime/crates/runtime/src/traphandlers.rs:171:21
    |
171 |                     compile_error!("unsupported platform");
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> wasmtime/crates/runtime/src/traphandlers.rs:156:52
    |
156 |         unsafe fn get_pc(cx: *mut libc::c_void) -> *const u8 {
    |                   ------                           ^^^^^^^^^ expected *-ptr, found `()`
    |                   |
    |                   implicitly returns `()` as its body has no tail or `return` expression
    |
    = note: expected raw pointer `*const u8`
                 found unit type `()`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `wasmtime-runtime`.

To learn more, run the command again with --verbose.

Problem

The error comes from this code:

unsafe fn get_pc(cx: *mut libc::c_void) -> *const u8 {
cfg_if::cfg_if! {
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(target_os = "linux", 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");
}
}
}

The reason seems to be that there is no aarch64 android case in the code.

Proposed solution

By doing the following change I am able to compile successfully, but I am unsure if this is a proper fix to the issue.
The diff was generated for 5c35a96.

diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs
index 0bd6f2cd1b..198d03a640 100644
--- a/crates/runtime/src/traphandlers.rs
+++ b/crates/runtime/src/traphandlers.rs
@@ -161,7 +161,7 @@ cfg_if::cfg_if! {
                 } 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(target_os = "linux", target_arch = "aarch64"))] {
+                } 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")] {
@alexcrichton
Copy link
Member

If that patch works for you then it looks right to me too, would you be interested in sending a PR for this?

@alexcrichton
Copy link
Member

Addressed in #2002

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

2 participants