From 2433d365afe7ec7906bd51f33cd601036ba7aab9 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 22 Nov 2019 16:32:02 -0800 Subject: [PATCH 1/5] Add new test feature, enabled in test crates. When test feature is enabled, turn on LLVM verifier. This was previously never enabled. --- lib/emscripten-tests/Cargo.toml | 2 +- lib/llvm-backend/Cargo.toml | 1 + lib/llvm-backend/src/code.rs | 7 ++++--- lib/middleware-common-tests/Cargo.toml | 2 +- lib/runtime-core-tests/Cargo.toml | 2 +- lib/spectests/Cargo.toml | 2 +- lib/wasi-tests/Cargo.toml | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index 39700ab2198..2439b429578 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -12,7 +12,7 @@ build = "build/mod.rs" wasmer-emscripten = { path = "../emscripten", version = "0.11.0" } wasmer-runtime = { path = "../runtime", version = "0.11.0", default-features = false } wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true, features = ["test"] } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } [dev-dependencies] diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 24a3f082f85..2f5db92de99 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -41,3 +41,4 @@ wabt = "0.9.1" [features] debug = ["wasmer-runtime-core/debug"] +test = [] diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 0aca846505c..63efc3148f7 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -8286,9 +8286,10 @@ impl ModuleCodeGenerator } let pass_manager = PassManager::create(()); - if cfg!(test) { - pass_manager.add_verifier_pass(); - } + + #[cfg(feature = "test")] + pass_manager.add_verifier_pass(); + pass_manager.add_type_based_alias_analysis_pass(); pass_manager.add_lower_expect_intrinsic_pass(); pass_manager.add_scalar_repl_aggregates_pass(); diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index 1ed0fccdbd6..1541a096cf6 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -11,7 +11,7 @@ publish = false wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } wasmer-middleware-common = { path = "../middleware-common", version = "0.11.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0" } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } [features] diff --git a/lib/runtime-core-tests/Cargo.toml b/lib/runtime-core-tests/Cargo.toml index c844b3f164a..57e9e19f9cb 100644 --- a/lib/runtime-core-tests/Cargo.toml +++ b/lib/runtime-core-tests/Cargo.toml @@ -12,7 +12,7 @@ wabt = "0.9.1" wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } [features] default = ["backend-cranelift"] diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index ea49633ada0..81bd57669e8 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" glob = "0.3" wasmer-runtime = { path = "../runtime", version = "0.11.0", default-features = false} wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } [build-dependencies] diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 654921e373b..9b84e5ea91e 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -15,7 +15,7 @@ wasmer-wasi = { path = "../wasi", version = "0.11.0" } # hack to get tests to work wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } [build-dependencies] glob = "0.3" From 85666fc52250c89e13c0cec315dad12362bf7b84 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 22 Nov 2019 16:33:16 -0800 Subject: [PATCH 2/5] Add new llvm-backend-test crate. --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + Makefile | 1 + lib/llvm-backend-tests/Cargo.toml | 15 +++++++++++++++ lib/llvm-backend-tests/src/lib.rs | 7 +++++++ lib/llvm-backend-tests/tests/compile.rs | 22 ++++++++++++++++++++++ 6 files changed, 56 insertions(+) create mode 100644 lib/llvm-backend-tests/Cargo.toml create mode 100644 lib/llvm-backend-tests/src/lib.rs create mode 100644 lib/llvm-backend-tests/tests/compile.rs diff --git a/Cargo.lock b/Cargo.lock index b628e7cdc1f..c92d5ceb1c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1464,6 +1464,16 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasmer-llvm-backend-tests" +version = "0.10.2" +dependencies = [ + "wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-llvm-backend 0.11.0", + "wasmer-runtime 0.11.0", + "wasmer-runtime-core 0.11.0", +] + [[package]] name = "wasmer-middleware-common" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 22d436401c6..557fade49e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ members = [ "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", + "lib/llvm-backend-tests", "lib/wasi", "lib/middleware-common", "lib/kernel-loader", diff --git a/Makefile b/Makefile index 07e595e4487..4acde792584 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ cranelift: spectests-cranelift emtests-cranelift middleware-cranelift wasitests- llvm: spectests-llvm emtests-llvm wasitests-llvm cargo test -p wasmer-llvm-backend --release + cargo test -p wasmer-llvm-backend-tests --release cargo test -p wasmer-runtime-core-tests --release --no-default-features --features backend-llvm diff --git a/lib/llvm-backend-tests/Cargo.toml b/lib/llvm-backend-tests/Cargo.toml new file mode 100644 index 00000000000..bb6b24b511c --- /dev/null +++ b/lib/llvm-backend-tests/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "wasmer-llvm-backend-tests" +version = "0.10.2" +authors = ["Nick Lewycky "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +wabt = "0.9.1" +wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } +wasmer-runtime = { path = "../runtime", version = "0.11.0" } +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"] } + +[features] diff --git a/lib/llvm-backend-tests/src/lib.rs b/lib/llvm-backend-tests/src/lib.rs new file mode 100644 index 00000000000..ea79b78721e --- /dev/null +++ b/lib/llvm-backend-tests/src/lib.rs @@ -0,0 +1,7 @@ +pub use wabt::wat2wasm; +use wasmer_llvm_backend::LLVMCompiler; +use wasmer_runtime_core::backend::Compiler; + +pub fn get_compiler() -> impl Compiler { + LLVMCompiler::new() +} diff --git a/lib/llvm-backend-tests/tests/compile.rs b/lib/llvm-backend-tests/tests/compile.rs new file mode 100644 index 00000000000..edb59c4692f --- /dev/null +++ b/lib/llvm-backend-tests/tests/compile.rs @@ -0,0 +1,22 @@ +use wasmer_llvm_backend_tests::{get_compiler, wat2wasm}; +use wasmer_runtime::imports; +use wasmer_runtime_core::compile_with; + +#[test] +fn crash_return_with_float_on_stack() { + const MODULE: &str = r#" +(module + (type (;0;) (func)) + (type (;1;) (func (param f64) (result f64))) + (func $_start (type 0)) + (func $fmod (type 1) (param f64) (result f64) + local.get 0 + f64.const 0x0p+0 (;=0;) + f64.mul + return) +) +"#; + let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed"); + let module = compile_with(&wasm_binary, &get_compiler()).unwrap(); + let instance = module.instantiate(&imports! {}).unwrap(); +} From 681219b06c140e7fe2fbd49f91754293a855c85f Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 22 Nov 2019 16:47:02 -0800 Subject: [PATCH 3/5] Fix bug in LLVM lowering of 'return' when the stack has a float on it. --- lib/llvm-backend/src/code.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 63efc3148f7..2bf615e7d5e 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -1412,14 +1412,11 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } } Operator::Return => { - let frame = state.outermost_frame()?; let current_block = builder.get_insert_block().ok_or(BinaryReaderError { message: "not currently in a block", offset: -1isize as usize, })?; - builder.build_unconditional_branch(frame.br_dest()); - let frame = state.outermost_frame()?; for phi in frame.phis().to_vec().iter() { let (arg, info) = state.pop1_extra()?; @@ -1427,6 +1424,9 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { phi.add_incoming(&[(&arg, ¤t_block)]); } + let frame = state.outermost_frame()?; + builder.build_unconditional_branch(frame.br_dest()); + state.reachable = false; } From 3ef9f769df6f14f3ac07fb66b3c960c1de5ae8a2 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 22 Nov 2019 17:02:20 -0800 Subject: [PATCH 4/5] Fix TBAA crash with LLVM + the gas middleware. --- lib/llvm-backend/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index 717ed043d70..2e3466e45ca 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -1132,7 +1132,7 @@ impl<'a> CtxType<'a> { module.clone(), intrinsics, "context_field_ptr_to_internals", - local_internals_ptr_ptr.as_instruction_value().unwrap(), + local_internals_ptr.as_instruction_value().unwrap(), None, ); unsafe { From 91671d53474c7220c6fdb3a6745e353b731fe2df Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 22 Nov 2019 17:16:25 -0800 Subject: [PATCH 5/5] Add changelog entry. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e99bc60d32..5df0b8ae3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## **[Unreleased]** +- [#1009](https://github.com/wasmerio/wasmer/pull/1009) Enable LLVM verifier for all tests, add new llvm-backend-tests crate. + ## 0.11.0 - 2019-11-22 - [#713](https://github.com/wasmerio/wasmer/pull/713) Add AArch64 support for singlepass.