Split global_asm! helper macros out from wasmtime-fibers (#4454)

This moves them into a new `wasmtime-asm-macros` crate that can be used not just
from the `wasmtime-fibers` crate but also from other crates (e.g. we will need
them in https://github.com/bytecodealliance/wasmtime/pull/4431).
This commit is contained in:
Nick Fitzgerald
2022-07-15 14:10:27 -07:00
committed by GitHub
parent 33312c5380
commit 439f566f3f
10 changed files with 97 additions and 57 deletions

View File

@@ -18,6 +18,7 @@ cfg-if = "1.0"
[target.'cfg(unix)'.dependencies]
rustix = { version = "0.35.6", features = ["mm", "param"] }
wasmtime-asm-macros = { version = "=0.40.0", path = "../asm-macros" }
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.36.1"

View File

@@ -177,63 +177,6 @@ impl Suspend {
}
}
// This macro itself generates a macro named `asm_func!` which is suitable for
// generating a single `global_asm!`-defined function. This takes care of
// platform-specific directives to get the symbol attributes correct (e.g. ELF
// symbols get a size and are flagged as a function) and additionally handles
// visibility across platforms. All symbols should be visible to Rust but not
// visible externally outside of a `*.so`.
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
macro_rules! asm_func {
($name:tt, $($body:tt)*) => {
std::arch::global_asm!(concat!(
".p2align 4\n",
".private_extern _", $name, "\n",
".global _", $name, "\n",
"_", $name, ":\n",
$($body)*
));
};
}
macro_rules! asm_sym {
($name:tt) => (concat!("_", $name))
}
} else {
// Note that for now this "else" clause just assumes that everything
// other than macOS is ELF and has the various directives here for
// that.
cfg_if::cfg_if! {
if #[cfg(target_arch = "arm")] {
macro_rules! elf_func_type_header {
($name:tt) => (concat!(".type ", $name, ",%function\n"))
}
} else {
macro_rules! elf_func_type_header {
($name:tt) => (concat!(".type ", $name, ",@function\n"))
}
}
}
macro_rules! asm_func {
($name:tt, $($body:tt)*) => {
std::arch::global_asm!(concat!(
".p2align 4\n",
".hidden ", $name, "\n",
".global ", $name, "\n",
elf_func_type_header!($name),
$name, ":\n",
$($body)*
".size ", $name, ",.-", $name,
));
};
}
macro_rules! asm_sym {
($name:tt) => ($name)
}
}
}
cfg_if::cfg_if! {
if #[cfg(target_arch = "aarch64")] {
mod aarch64;

View File

@@ -18,6 +18,8 @@
// `DW_CFA_AARCH64_negate_ra_state` DWARF operation (aliased with the
// `.cfi_window_save` assembler directive) informs an unwinder about this
use wasmtime_asm_macros::asm_func;
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
macro_rules! cfi_window_save { () => (""); }

View File

@@ -8,6 +8,8 @@
// Also at this time this file is heavily based off the x86_64 file, so you'll
// probably want to read that one as well.
use wasmtime_asm_macros::{asm_func, asm_sym};
// fn(top_of_stack(%r0): *mut u8)
asm_func!(
"wasmtime_fiber_switch",

View File

@@ -10,6 +10,8 @@
// different so the reserved space at the top of the stack is 8 bytes, not 16
// bytes. Still two pointers though.
use wasmtime_asm_macros::{asm_func, asm_sym};
// fn(top_of_stack: *mut u8)
asm_func!(
"wasmtime_fiber_switch",

View File

@@ -5,6 +5,8 @@
// all the other bits. Documentation tries to reference various bits here and
// there but try to make sure to read over everything before tweaking things!
use wasmtime_asm_macros::{asm_func, asm_sym};
// fn(top_of_stack(rdi): *mut u8)
asm_func!(
"wasmtime_fiber_switch",