From ee9ddb18fc8b5a7cc0120a7960ced65ab88eed54 Mon Sep 17 00:00:00 2001 From: losfair Date: Thu, 6 Feb 2020 23:10:55 +0800 Subject: [PATCH 1/3] Fix singlepass miscompilation on `Operator::CallIndirect`. --- lib/singlepass-backend/src/codegen_x64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 27f79dc62a9..f003bbbc847 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -6314,7 +6314,7 @@ impl FunctionCodeGenerator for X64FunctionCode { ExceptionCode::Memory, |a| a.emit_conditional_trap(Condition::BelowEqual), ); - a.emit_mov(Size::S64, func_index, Location::GPR(table_count)); + a.emit_mov(Size::S32, func_index, Location::GPR(table_count)); a.emit_imul_imm32_gpr64(vm::Anyfunc::size() as u32, table_count); a.emit_add( Size::S64, From 01e570d60a50a454f38c7c1f9e5fe25a90c636bc Mon Sep 17 00:00:00 2001 From: losfair Date: Wed, 12 Feb 2020 02:54:27 +0800 Subject: [PATCH 2/3] Add test for PR 1191. --- lib/spectests/spectests/wasmer.wast | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/spectests/spectests/wasmer.wast diff --git a/lib/spectests/spectests/wasmer.wast b/lib/spectests/spectests/wasmer.wast new file mode 100644 index 00000000000..cf3841f9bfc --- /dev/null +++ b/lib/spectests/spectests/wasmer.wast @@ -0,0 +1,33 @@ +;; Wasmer-specific tests. + +(module + ;; Auxiliary definitions + (type $out-i32 (func (result i32))) + + (func $const-i32 (type $out-i32) (i32.const 0x132)) + + (table funcref + (elem + $const-i32 + ) + ) + + ;; https://github.com/wasmerio/wasmer/pull/1191 + (func (export "call-indirect-from-spilled-stack") (result i32) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0) (i64.const 0)) + (i64.add (i64.const 0x100000000) (i64.const 0)) + (i32.wrap_i64) + (call_indirect (type $out-i32)) + (return) + ) +) + +(assert_return (invoke "call-indirect-from-spilled-stack") (i32.const 0x132)) \ No newline at end of file From 2f4e9b1fe3028264b51502b5e21072e0ca0d1251 Mon Sep 17 00:00:00 2001 From: losfair Date: Wed, 12 Feb 2020 02:56:12 +0800 Subject: [PATCH 3/3] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d690b402b17..1308dbad45b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## **[Unreleased]** - [#1192](https://github.com/wasmerio/wasmer/pull/1192) Use `ExceptionCode` for error representation. +- [#1191](https://github.com/wasmerio/wasmer/pull/1191) Fix singlepass miscompilation on `Operator::CallIndirect`. - [#1180](https://github.com/wasmerio/wasmer/pull/1180) Fix compilation for target `x86_64-unknown-linux-musl`. - [#1170](https://github.com/wasmerio/wasmer/pull/1170) Improve the WasiFs builder API with convenience methods for overriding stdin, stdout, and stderr as well as a new sub-builder for controlling the permissions and properties of preopened directories. Also breaks that implementations of `WasiFile` must be `Send` -- please file an issue if this change causes you any issues. - [#1161](https://github.com/wasmerio/wasmer/pull/1161) Require imported functions to be `Send`. This is a breaking change that fixes a soundness issue in the API.