//! This crate defines a macro named `asm_func!` which is suitable for1//! generating a single `global_asm!`-defined function.2//!3//! This macro takes care of platform-specific directives to get the symbol4//! attributes correct (e.g. ELF symbols get a size and are flagged as a5//! function) and additionally handles visibility across platforms. All symbols6//! should be visible to Rust but not visible externally outside of a `*.so`.7//!8//! > **⚠️ Warning ⚠️**: this crate is an internal-only crate for the Wasmtime9//! > project and is not intended for general use. APIs are not strictly10//! > reviewed for safety and usage outside of Wasmtime may have bugs. If11//! > you're interested in using this feel free to file an issue on the12//! > Wasmtime repository to start a discussion about doing so, but otherwise13//! > be aware that your usage of this crate is not supported.1415#![no_std]1617cfg_if::cfg_if! {18if #[cfg(target_vendor = "apple")] {19#[macro_export]20macro_rules! asm_func {21($name:expr, $body:expr $(, $($args:tt)*)?) => {22core::arch::global_asm!(23concat!(24".p2align 4\n",25".private_extern _", $name, "\n",26".global _", $name, "\n",27"_", $name, ":\n",28$body,29),30$($($args)*)?31);32};33}34} else if #[cfg(target_os = "windows")] {35#[macro_export]36macro_rules! asm_func {37($name:expr, $body:expr $(, $($args:tt)*)?) => {38core::arch::global_asm!(39concat!(40".def ", $name, "\n",41".scl 2\n",42".type 32\n",43".endef\n",44".global ", $name, "\n",45".p2align 4\n",46$name, ":\n",47$body48),49$($($args)*)?50);51};52}53} else {54// Note that for now this "else" clause just assumes that everything55// other than macOS is ELF and has the various directives here for56// that.57cfg_if::cfg_if! {58if #[cfg(target_arch = "arm")] {59#[macro_export]60macro_rules! elf_func_type_header {61($name:tt) => (concat!(".type ", $name, ",%function\n"))62}63} else {64#[macro_export]65macro_rules! elf_func_type_header {66($name:tt) => (concat!(".type ", $name, ",@function\n"))67}68}69}7071#[macro_export]72macro_rules! asm_func {73($name:expr, $body:expr $(, $($args:tt)*)?) => {74core::arch::global_asm!(75concat!(76".p2align 4\n",77".hidden ", $name, "\n",78".global ", $name, "\n",79$crate::elf_func_type_header!($name),80$name, ":\n",81$body,82".size ", $name, ",.-", $name,83)84$(, $($args)*)?85);86};87}88}89}909192