Skip to content

Commit

Permalink
Attempt to handle the s390x case
Browse files Browse the repository at this point in the history
  • Loading branch information
adampetro committed Jun 30, 2023
1 parent e085825 commit ff81d02
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 22 deletions.
3 changes: 2 additions & 1 deletion crates/fiber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ edition.workspace = true

[dependencies]
cfg-if = { workspace = true }
wasmtime-versioned-export-macros = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["mm", "param"] }
wasmtime-asm-macros = { workspace = true }
wasmtime-versioned-export-macros = { workspace = true }

[target.'cfg(windows)'.dependencies.windows-sys]
workspace = true
Expand All @@ -24,6 +24,7 @@ features = [

[build-dependencies]
cc = "1.0"
wasmtime-versioned-export-macros = { workspace = true }

[dev-dependencies]
backtrace = "0.3.61"
13 changes: 11 additions & 2 deletions crates/fiber/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::{env, fs, path::PathBuf};
use wasmtime_versioned_export_macros::versioned_suffix;

fn main() {
let mut build = cc::Build::new();
Expand All @@ -9,7 +10,15 @@ fn main() {
build.file("src/windows.c");
} else if arch == "s390x" {
println!("cargo:rerun-if-changed=src/unix/s390x.S");
build.file("src/unix/s390x.S");

// cc does not preprocess macros passed with -D for `.s` files so need to do
// it manually
let asm = fs::read_to_string("src/unix/s390x.S").unwrap();
let asm = asm.replace("VERSIONED_SUFFIX", versioned_suffix!());
let out_dir = env::var("OUT_DIR").unwrap();
let file_path = PathBuf::from(out_dir).join("s390x_preprocessed.S");
fs::write(&file_path, asm).unwrap();
build.file(file_path);
} else {
// assume that this is included via inline assembly in the crate itself,
// and the crate will otherwise have a `compile_error!` for unsupported
Expand Down
11 changes: 6 additions & 5 deletions crates/fiber/src/unix/s390x.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

.text

#define GLOBL(fnname) .globl fnname
#define HIDDEN(fnname) .hidden fnname
#define TYPE(fnname) .type fnname,@function
#define FUNCTION(fnname) fnname
#define SIZE(fnname) .size fnname,.-fnname
#define VERSIONED_SYMBOL(a) a ## VERSIONED_SUFFIX
#define GLOBL(fnname) .globl VERSIONED_SYMBOL(fnname)
#define HIDDEN(fnname) .hidden VERSIONED_SYMBOL(fnname)
#define TYPE(fnname) .type VERSIONED_SYMBOL(fnname),@function
#define FUNCTION(fnname) VERSIONED_SYMBOL(fnname)
#define SIZE(fnname) .size VERSIONED_SYMBOL(fnname),.-VERSIONED_SYMBOL(fnname)

// fn(top_of_stack(%x0): *mut u8)
HIDDEN(wasmtime_fiber_switch)
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ once_cell = { workspace = true }

[build-dependencies]
cc = "1.0"
wasmtime-versioned-export-macros = { workspace = true }

[features]
async = ["wasmtime-fiber"]
Expand Down
13 changes: 11 additions & 2 deletions crates/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::{env, fs, path::PathBuf};
use wasmtime_versioned_export_macros::versioned_suffix;

fn main() {
let mut build = cc::Build::new();
Expand All @@ -9,7 +10,15 @@ fn main() {
build.define(&format!("CFG_TARGET_ARCH_{}", arch), None);
if arch == "s390x" {
println!("cargo:rerun-if-changed=src/trampolines/s390x.S");
build.file("src/trampolines/s390x.S");

// cc does not preprocess macros passed with -D for `.s` files so need to do
// it manually
let asm = fs::read_to_string("src/trampolines/s390x.S").unwrap();
let asm = asm.replace("VERSIONED_SUFFIX", versioned_suffix!());
let out_dir = env::var("OUT_DIR").unwrap();
let file_path = PathBuf::from(out_dir).join("s390x_preprocessed.S");
fs::write(&file_path, asm).unwrap();
build.file(file_path);
}
println!("cargo:rerun-if-changed=src/helpers.c");
build.file("src/helpers.c");
Expand Down
5 changes: 0 additions & 5 deletions crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,3 @@ impl fmt::Display for WasmFault {
)
}
}

#[cfg(all(target_arch = "s390x", feature = "versioned-exports"))]
compile_error!(
"Feature `versioned-exports` is not currently supported for the `s390x` architecture"
);
1 change: 0 additions & 1 deletion crates/runtime/src/libcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ pub mod trampolines {
// the `sym` operator to get the symbol here, but other targets
// like s390x need to use outlined assembly files which requires
// `no_mangle`.
#[cfg_attr(target_arch = "s390x", no_mangle)]
#[cfg_attr(target_arch = "s390x", wasmtime_versioned_export_macros::versioned_export)]
unsafe extern "C" fn [<impl_ $name>](
vmctx: *mut VMContext,
Expand Down
14 changes: 8 additions & 6 deletions crates/runtime/src/trampolines/s390x.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
.type host_to_wasm_trampoline,@function
.p2align 2

#define VERSIONED_SYMBOL(a) a ## VERSIONED_SUFFIX

#define LIBCALL_TRAMPOLINE(libcall, libcall_impl) \
.hidden libcall ; \
.globl libcall ; \
.type libcall,@function ; \
.hidden VERSIONED_SYMBOL(libcall) ; \
.globl VERSIONED_SYMBOL(libcall) ; \
.type VERSIONED_SYMBOL(libcall),@function ; \
.p2align 2 ; \
libcall: ; \
VERSIONED_SYMBOL(libcall): ; \
.cfi_startproc ; \
\
/* Load the pointer to `VMRuntimeLimits` in `%r1`. */ \
Expand All @@ -28,10 +30,10 @@ libcall: ;
stg %r14, 32(%r1) ; \
\
/* Tail call to the actual implementation of this libcall. */ \
jg libcall_impl ; \
jg VERSIONED_SYMBOL(libcall_impl) ; \
\
.cfi_endproc ; \
.size libcall,.-libcall
.size VERSIONED_SYMBOL(libcall),.-VERSIONED_SYMBOL(libcall)

LIBCALL_TRAMPOLINE(memory32_grow, impl_memory32_grow)
LIBCALL_TRAMPOLINE(table_grow_func_ref, impl_table_grow_func_ref)
Expand Down
16 changes: 16 additions & 0 deletions crates/versioned-export-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ pub fn versioned_stringify_ident(item: proc_macro::TokenStream) -> proc_macro::T
.to_token_stream()
.into()
}

#[proc_macro]
pub fn versioned_suffix(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
if !item.is_empty() {
return syn::Error::new(
proc_macro2::Span::call_site(),
"`versioned_suffix!` accepts no input",
)
.to_compile_error()
.into();
};

syn::LitStr::new(version("").as_str(), proc_macro2::Span::call_site())
.to_token_stream()
.into()
}

0 comments on commit ff81d02

Please sign in to comment.