Use the sym operator for inline assembly (#5459)

* Use the `sym` operator for inline assembly

Avoids extra `#[no_mangle]` functions and undue symbols being exposed
from Wasmtime. This is a newly stabilized feature in Rust 1.66.0. I've
also added a `rust-version` entry to the `wasmtime` crate to try to head
off possible reports in the future about odd error messages or usage of
unstable features if the rustc version is too old.

* Fix a s390x warning

* Add `rust-version` annotation to Wasmtime crate

As the other main entrypoint for embedders.
This commit is contained in:
Alex Crichton
2022-12-16 14:12:24 -06:00
committed by GitHub
parent 25bf8e0e67
commit d9fdbfd50e
12 changed files with 204 additions and 185 deletions

View File

@@ -5,51 +5,43 @@
//! 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`.
//!
//! It also exports a an `asm_sym!` macro which can be used to reference symbols
//! from within `global_asm!`-defined functions, and handles adding the leading
//! underscore that macOS prepends to symbols for you.
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
#[macro_export]
macro_rules! asm_func {
($name:expr, $($body:tt)*) => {
std::arch::global_asm!(concat!(
".p2align 4\n",
".private_extern _", $name, "\n",
".global _", $name, "\n",
"_", $name, ":\n",
$($body)*
));
($name:expr, $body:expr $(, $($args:tt)*)?) => {
std::arch::global_asm!(
concat!(
".p2align 4\n",
".private_extern _", $name, "\n",
".global _", $name, "\n",
"_", $name, ":\n",
$body,
),
$($($args)*)?
);
};
}
#[macro_export]
macro_rules! asm_sym {
( $( $name:tt )* ) => ( concat!("_", $( $name )* ) )
}
} else if #[cfg(target_os = "windows")] {
#[macro_export]
macro_rules! asm_func {
($name:expr, $($body:tt)*) => {
std::arch::global_asm!(concat!(
".def ", $name, "\n",
".scl 2\n",
".type 32\n",
".endef\n",
".global ", $name, "\n",
".p2align 4\n",
$name, ":\n",
$($body)*
));
($name:expr, $body:expr $(, $($args:tt)*)?) => {
std::arch::global_asm!(
concat!(
".def ", $name, "\n",
".scl 2\n",
".type 32\n",
".endef\n",
".global ", $name, "\n",
".p2align 4\n",
$name, ":\n",
$body
),
$($($args)*)?
);
};
}
#[macro_export]
macro_rules! asm_sym {
( $( $name:tt )* ) => ( $( $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
@@ -70,22 +62,20 @@ cfg_if::cfg_if! {
#[macro_export]
macro_rules! asm_func {
($name:expr, $($body:tt)*) => {
std::arch::global_asm!(concat!(
".p2align 4\n",
".hidden ", $name, "\n",
".global ", $name, "\n",
$crate::elf_func_type_header!($name),
$name, ":\n",
concat!($($body)*),
".size ", $name, ",.-", $name,
));
($name:expr, $body:expr $(, $($args: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,
)
$(, $($args)*)?
);
};
}
#[macro_export]
macro_rules! asm_sym {
( $( $name:tt )* ) => ( $( $name )* )
}
}
}