Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LLVM crash on return with a float on the stack and a crash with gas metering. #1009

Merged
merged 5 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions lib/llvm-backend-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "wasmer-llvm-backend-tests"
version = "0.10.2"
authors = ["Nick Lewycky <[email protected]>"]
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]
7 changes: 7 additions & 0 deletions lib/llvm-backend-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}
22 changes: 22 additions & 0 deletions lib/llvm-backend-tests/tests/compile.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions lib/llvm-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ wabt = "0.9.1"

[features]
debug = ["wasmer-runtime-core/debug"]
test = []
13 changes: 7 additions & 6 deletions lib/llvm-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,21 +1412,21 @@ impl FunctionCodeGenerator<CodegenError> 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()?;
let arg = apply_pending_canonicalization(builder, intrinsics, arg, info);
phi.add_incoming(&[(&arg, &current_block)]);
}

let frame = state.outermost_frame()?;
builder.build_unconditional_branch(frame.br_dest());

state.reachable = false;
}

Expand Down Expand Up @@ -8286,9 +8286,10 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
}

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();
Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware-common-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion lib/spectests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down