From 2efdd5c46b589071767e0a5f880c637d07fff844 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 28 Jun 2022 09:34:31 -0500 Subject: [PATCH] Fix compilation of wasmtime-fiber on arm macOS (#4341) Turns out that `adr` doesn't work in inline assembly within LLVM on arm macOS, or at least not how we were using it. This switches instead to an `adrp` and `add` pair which seems to convince the linker that the relocations should all fit. The same pattern is used on Linux as well only it has different syntax (so much for a portable assembler) for consistency. Performance isn't really an issue here so there's no need to go out of our way to get the single-instruction operand working. --- crates/fiber/src/unix/aarch64.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/fiber/src/unix/aarch64.rs b/crates/fiber/src/unix/aarch64.rs index a0b4201b9d..92a3bfcb4d 100644 --- a/crates/fiber/src/unix/aarch64.rs +++ b/crates/fiber/src/unix/aarch64.rs @@ -20,15 +20,19 @@ cfg_if::cfg_if! { if #[cfg(target_os = "macos")] { - macro_rules! cfi_window_save { () => (); } - macro_rules! pacia1716 { () => (); } - macro_rules! paciasp { () => (); } - macro_rules! autiasp { () => (); } + macro_rules! cfi_window_save { () => (""); } + macro_rules! pacia1716 { () => (""); } + macro_rules! paciasp { () => (""); } + macro_rules! autiasp { () => (""); } + macro_rules! sym_adrp { ($s:tt) => (concat!("_", $s, "@PAGE")); } + macro_rules! sym_add { ($s:tt) => (concat!("_", $s, "@PAGEOFF")); } } else { macro_rules! cfi_window_save { () => (".cfi_window_save\n"); } macro_rules! pacia1716 { () => ("pacia1716\n"); } macro_rules! paciasp { () => ("paciasp\n"); } macro_rules! autiasp { () => ("autiasp\n"); } + macro_rules! sym_adrp { ($s:tt) => (concat!($s, "")); } + macro_rules! sym_add { ($s:tt) => (concat!(":lo12:", $s)); } } } @@ -112,7 +116,8 @@ asm_func!( .cfi_startproc hint #34 // bti c sub x16, x0, #16 - adr x17, ", asm_sym!("wasmtime_fiber_start"), " + adrp x17, ", sym_adrp!("wasmtime_fiber_start"), " + add x17, x17, ", sym_add!("wasmtime_fiber_start"), " ", pacia1716!(), "