diff --git a/Cargo.lock b/Cargo.lock index c15375a54dc2..a83ef0559e66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4115,6 +4115,7 @@ dependencies = [ "component-test-util", "cranelift-codegen", "cranelift-filetests", + "cranelift-native", "cranelift-reader", "criterion", "env_logger 0.11.5", diff --git a/Cargo.toml b/Cargo.toml index 7245ef6dfda5..a47d58eb97c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,6 +124,7 @@ wasmtime-test-macros = { path = "crates/test-macros" } pulley-interpreter = { workspace = true, features = ["disas"] } wasmtime-wast-util = { path = 'crates/wast-util' } wasm-encoder = { workspace = true } +cranelift-native = { workspace = true } [target.'cfg(windows)'.dev-dependencies] windows-sys = { workspace = true, features = ["Win32_System_Memory"] } diff --git a/cranelift/filetests/src/function_runner.rs b/cranelift/filetests/src/function_runner.rs index b356fd3a194a..cbe4f07b9653 100644 --- a/cranelift/filetests/src/function_runner.rs +++ b/cranelift/filetests/src/function_runner.rs @@ -611,7 +611,6 @@ extern "C" fn __cranelift_x86_pshufb(a: __m128i, b: __m128i) -> __m128i { } #[cfg(test)] -#[cfg(target_pointer_width = "64")] // 32-bit platforms not supported at this time mod test { use super::*; use cranelift_reader::{parse_functions, parse_test, ParseOptions}; @@ -622,6 +621,10 @@ mod test { #[test] fn nop() { + // Skip this test when cranelift doesn't support the native platform. + if cranelift_native::builder().is_err() { + return; + } let code = String::from( " test run @@ -656,6 +659,10 @@ mod test { #[test] fn trampolines() { + // Skip this test when cranelift doesn't support the native platform. + if cranelift_native::builder().is_err() { + return; + } let function = parse( " function %test(f32, i8, i64x2, i8) -> f32x4, i64 { diff --git a/cranelift/src/run.rs b/cranelift/src/run.rs index d43912bad8ff..9186ad2a39d8 100644 --- a/cranelift/src/run.rs +++ b/cranelift/src/run.rs @@ -126,12 +126,14 @@ fn create_target_isa(isa_spec: &IsaSpec) -> Result { } #[cfg(test)] -#[cfg(target_pointer_width = "64")] // 32-bit platforms not supported yet mod test { use super::*; #[test] fn nop() { + if cranelift_native::builder().is_err() { + return; + } let code = String::from( " function %test() -> i8 { diff --git a/crates/cranelift/src/debug/transform/address_transform.rs b/crates/cranelift/src/debug/transform/address_transform.rs index a581b15f1095..debe58232dee 100644 --- a/crates/cranelift/src/debug/transform/address_transform.rs +++ b/crates/cranelift/src/debug/transform/address_transform.rs @@ -491,7 +491,6 @@ impl AddressTransform { } #[cfg(test)] - #[cfg(target_pointer_width = "64")] pub fn mock( module_map: &wasmtime_environ::PrimaryMap< wasmtime_environ::DefinedFuncIndex, @@ -661,8 +660,6 @@ impl AddressTransform { } #[cfg(test)] -#[cfg(target_pointer_width = "64")] // cranelift doesn't support native 32-bit - // platforms mod tests { use super::{build_function_lookup, get_wasm_code_offset, AddressTransform}; use crate::{CompiledFunctionMetadata, FunctionAddressMap}; @@ -787,6 +784,10 @@ mod tests { #[test] fn test_addr_translate() { + // Ignore this test if cranelift doesn't support the native platform. + if cranelift_native::builder().is_err() { + return; + } let func = CompiledFunctionMetadata { address_map: create_simple_func(11), ..Default::default() diff --git a/crates/cranelift/src/debug/transform/expression.rs b/crates/cranelift/src/debug/transform/expression.rs index 457b5668695d..d2c3811a2c00 100644 --- a/crates/cranelift/src/debug/transform/expression.rs +++ b/crates/cranelift/src/debug/transform/expression.rs @@ -795,8 +795,6 @@ impl std::fmt::Debug for JumpTargetMarker { #[cfg(test)] #[expect(trivial_numeric_casts, reason = "macro-generated code")] -#[cfg(target_pointer_width = "64")] // cranelift doesn't support native 32-bit - // platforms mod tests { use super::{ compile_expression, AddressTransform, CompiledExpression, CompiledExpressionPart, @@ -1224,6 +1222,11 @@ mod tests { use super::ValueLabelRangesBuilder; use crate::debug::ModuleMemoryOffset; + // Ignore this test if cranelift doesn't support the native platform. + if cranelift_native::builder().is_err() { + return; + } + let addr_tr = create_mock_address_transform(); let (value_ranges, value_labels) = create_mock_value_ranges(); let fi = FunctionFrameInfo { diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index 9dddcfd1966d..2c6f48f0c747 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -2073,8 +2073,11 @@ after empty } #[test] -#[cfg(target_pointer_width = "64")] // cranelift only supports 64-bit platforms fn settings_command() -> Result<()> { + // Skip this test on platforms that Cranelift doesn't support. + if cranelift_native::builder().is_err() { + return Ok(()); + } let output = run_wasmtime(&["settings"])?; assert!(output.contains("Cranelift settings for target")); Ok(()) diff --git a/tests/all/gc.rs b/tests/all/gc.rs index 73affd6897f5..523fc25fd130 100644 --- a/tests/all/gc.rs +++ b/tests/all/gc.rs @@ -1,5 +1,4 @@ use super::ref_types_module; -use super::skip_pooling_allocator_tests; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; use wasmtime::*; @@ -280,11 +279,9 @@ fn global_drops_externref() -> Result<()> { let _ = env_logger::try_init(); test_engine(&Engine::default())?; - if !skip_pooling_allocator_tests() { - test_engine(&Engine::new( - Config::new().allocation_strategy(InstanceAllocationStrategy::pooling()), - )?)?; - } + let mut config = Config::new(); + config.allocation_strategy(crate::small_pool_config()); + test_engine(&Engine::new(&config)?)?; return Ok(()); @@ -331,11 +328,9 @@ fn table_drops_externref() -> Result<()> { let _ = env_logger::try_init(); test_engine(&Engine::default())?; - if !skip_pooling_allocator_tests() { - test_engine(&Engine::new( - Config::new().allocation_strategy(InstanceAllocationStrategy::pooling()), - )?)?; - } + let mut config = Config::new(); + config.allocation_strategy(crate::small_pool_config()); + test_engine(&Engine::new(&config)?)?; return Ok(()); diff --git a/tests/all/main.rs b/tests/all/main.rs index 37b89dbfa637..bee9eb17331f 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -83,7 +83,7 @@ pub(crate) fn skip_pooling_allocator_tests() -> bool { // There are a couple of issues when running the pooling allocator tests under QEMU: // - high memory usage that may exceed the limits imposed by the environment (e.g. CI) // - https://github.com/bytecodealliance/wasmtime/pull/2518#issuecomment-747280133 - cfg!(target_pointer_width = "32") || std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() + std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() } /// Get the default pooling allocator configuration for tests, which is a diff --git a/tests/host_segfault.rs b/tests/host_segfault.rs index 707fea32f268..3f0cabbb54a0 100644 --- a/tests/host_segfault.rs +++ b/tests/host_segfault.rs @@ -259,10 +259,14 @@ fn run_test(name: &str, stack_overflow: StackOverflow) { } match stack_overflow { + // If the host stack overflows then the result should always indicate a + // stack overflow. If the guest stack overflows then that won't actually + // trigger an overflow when Cranelift doesn't have native support + // because Pulley is used in that case. StackOverflow::Host | StackOverflow::Wasm => { let native_stack_overflow = is_stack_overflow(&output.status, &stderr); let expect_native_overflow = - stack_overflow == StackOverflow::Host || cfg!(target_pointer_width = "64"); + stack_overflow == StackOverflow::Host || cranelift_native::builder().is_ok(); if native_stack_overflow == expect_native_overflow { assert!(