Browse Source
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).pull/4003/head
Nick Fitzgerald
2 years ago
committed by
GitHub
10 changed files with 97 additions and 57 deletions
@ -0,0 +1,13 @@ |
|||
[package] |
|||
authors = ["The Wasmtime Project Developers"] |
|||
description = "Macros for defining asm functions in Wasmtime" |
|||
edition = "2021" |
|||
license = "Apache-2.0 WITH LLVM-exception" |
|||
name = "wasmtime-asm-macros" |
|||
repository = "https://github.com/bytecodealliance/wasmtime" |
|||
version = "0.40.0" |
|||
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
|||
|
|||
[dependencies] |
|||
cfg-if = "1" |
@ -0,0 +1,66 @@ |
|||
//! This crate defines a macro named `asm_func!` which is suitable for
|
|||
//! generating a single `global_asm!`-defined function.
|
|||
//!
|
|||
//! This macro 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_export] |
|||
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_export] |
|||
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_export] |
|||
macro_rules! elf_func_type_header { |
|||
($name:tt) => (concat!(".type ", $name, ",%function\n")) |
|||
} |
|||
} else { |
|||
#[macro_export] |
|||
macro_rules! elf_func_type_header { |
|||
($name:tt) => (concat!(".type ", $name, ",@function\n")) |
|||
} |
|||
} |
|||
} |
|||
|
|||
#[macro_export] |
|||
macro_rules! asm_func { |
|||
($name:tt, $($body:tt)*) => { |
|||
std::arch::global_asm!(concat!( |
|||
".p2align 4\n", |
|||
".hidden ", $name, "\n", |
|||
".global ", $name, "\n", |
|||
$crate::elf_func_type_header!($name), |
|||
$name, ":\n", |
|||
$($body)* |
|||
".size ", $name, ",.-", $name, |
|||
)); |
|||
}; |
|||
} |
|||
|
|||
#[macro_export] |
|||
macro_rules! asm_sym { |
|||
($name:tt) => ($name) |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue