ARM64 backend, part 9 / 11: wasmtime support.

This commit adds a few odds and ends required to build wasmtime on ARM64
with the new backend. In particular, it adds:

- Support for the `Arm64Call` relocation type.
- Support for fetching the trap PC when a signal is received.
- A hook for `SIGTRAP`, which is sent by the `brk` opcode (in contrast to
  x86's `SIGILL`).

With the patch sequence up to and including this patch applied,
`wasmtime` can now compile and successfully execute code on arm64. Not
all tests pass yet, but basic Wasm/WASI tests work correctly.
This commit is contained in:
Chris Fallin
2020-04-09 13:54:29 -07:00
parent 60990aeaae
commit bab0c79c31
4 changed files with 45 additions and 9 deletions

View File

@@ -31,6 +31,7 @@ cfg_if::cfg_if! {
static mut PREV_SIGBUS: MaybeUninit<libc::sigaction> = MaybeUninit::uninit();
static mut PREV_SIGILL: MaybeUninit<libc::sigaction> = MaybeUninit::uninit();
static mut PREV_SIGFPE: MaybeUninit<libc::sigaction> = MaybeUninit::uninit();
static mut PREV_SIGTRAP: MaybeUninit<libc::sigaction> = MaybeUninit::uninit();
unsafe fn platform_init() {
let register = |slot: &mut MaybeUninit<libc::sigaction>, signal: i32| {
@@ -70,6 +71,9 @@ cfg_if::cfg_if! {
register(&mut PREV_SIGFPE, libc::SIGFPE);
}
// on ARM64, we use `brk` to report traps, which generates SIGTRAP.
register(&mut PREV_SIGTRAP, libc::SIGTRAP);
// On ARM, handle Unaligned Accesses.
// On Darwin, guard page accesses are raised as SIGBUS.
if cfg!(target_arch = "arm") || cfg!(target_os = "macos") {
@@ -87,6 +91,7 @@ cfg_if::cfg_if! {
libc::SIGBUS => &PREV_SIGBUS,
libc::SIGFPE => &PREV_SIGFPE,
libc::SIGILL => &PREV_SIGILL,
libc::SIGTRAP => &PREV_SIGTRAP,
_ => panic!("unknown signal: {}", signum),
};
let handled = tls::with(|info| {
@@ -158,6 +163,12 @@ 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 = "aarch64"))] {
// libc doesn't seem to support Linux/aarch64 at the moment?
extern "C" {
fn GetPcFromUContext(cx: *mut libc::c_void) -> *const u8;
}
GetPcFromUContext(cx)
} else if #[cfg(target_os = "macos")] {
// FIXME(rust-lang/libc#1702) - once that lands and is
// released we should inline the definition here