From 55394b4f06741b3ac9ed7b6d78baeed886e49dec Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 25 Jun 2019 16:04:31 -0700 Subject: [PATCH 01/13] Void type in llvm may only be used as a function return type. You may not form a pointer to void or use it as a structure member. Fixes assertion failure initializing llvm backend. --- lib/llvm-backend/src/intrinsics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index 0e00ff421..d34ccb2e4 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -159,10 +159,10 @@ impl Intrinsics { let imported_func_ty = context.struct_type(&[i8_ptr_ty_basic, ctx_ptr_ty.as_basic_type_enum()], false); let sigindex_ty = i32_ty; - let rt_intrinsics_ty = void_ty; + let rt_intrinsics_ty = i8_ty; let stack_lower_bound_ty = i8_ty; let memory_base_ty = i8_ty; - let memory_bound_ty = void_ty; + let memory_bound_ty = i8_ty; let internals_ty = i64_ty; let local_function_ty = i8_ptr_ty; From 70247a0c6e58b40e2c71cccf5a75ac665f08e735 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 25 Jun 2019 16:03:40 -0700 Subject: [PATCH 02/13] Simplify construction of floating point constants. --- lib/llvm-backend/src/code.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 7e76698a9..1a84a15c7 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -849,22 +849,12 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { } Operator::F32Const { value } => { let bits = intrinsics.i32_ty.const_int(value.bits() as u64, false); - let space = - builder.build_alloca(intrinsics.f32_ty.as_basic_type_enum(), "const_space"); - let i32_space = - builder.build_pointer_cast(space, intrinsics.i32_ptr_ty, "i32_space"); - builder.build_store(i32_space, bits); - let f = builder.build_load(space, "f"); + let f = builder.build_bitcast(bits, intrinsics.f32_ty, "f"); state.push1(f); } Operator::F64Const { value } => { let bits = intrinsics.i64_ty.const_int(value.bits(), false); - let space = - builder.build_alloca(intrinsics.f64_ty.as_basic_type_enum(), "const_space"); - let i64_space = - builder.build_pointer_cast(space, intrinsics.i64_ptr_ty, "i32_space"); - builder.build_store(i64_space, bits); - let f = builder.build_load(space, "f"); + let f = builder.build_bitcast(bits, intrinsics.f64_ty, "f"); state.push1(f); } From 1f28800e551c9a445f04214da39e2b20ff544354 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Wed, 26 Jun 2019 10:12:47 -0700 Subject: [PATCH 03/13] Update changelog for LLVM cleanup. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8281c924..9bdfa5da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#510](https://github.com/wasmerio/wasmer/pull/510) Simplify construction of floating point constants in LLVM backend. Fix LLVM assertion failure due to definition of %ctx. ## 0.5.1 - 2019-06-24 - [#508](https://github.com/wasmerio/wasmer/pull/508) Update wapm version, includes bug fixes From dda438ebd16288169fe7d2616019867fd7776c2b Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 11:14:38 -0700 Subject: [PATCH 04/13] Fixed lseek --- lib/emscripten/src/syscalls/mod.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 90c703d58..c7acf4905 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -433,27 +433,31 @@ pub fn ___syscall192(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// lseek +#[allow(exceeding_bitshifts)] pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", _which); let fd: i32 = varargs.get(ctx); - let _ = varargs.get::(ctx); // ignore high offset + let _offset_high: i32 = varargs.get(ctx); let offset_low: i32 = varargs.get(ctx); - let result_ptr_value = varargs.get::(ctx); + let result_ptr_value: i32 = varargs.get(ctx); let whence: i32 = varargs.get(ctx); let offset = offset_low as off_t; - let ret = unsafe { lseek(fd, offset, whence) as i32 }; + let ret = unsafe { lseek(fd, offset, whence) }; #[allow(clippy::cast_ptr_alignment)] - let result_ptr = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32; - assert_eq!(8, mem::align_of_val(&result_ptr)); + let result_ptr_0 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32; + let result_ptr_1 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value+4) as *mut i32; + assert_eq!(8, mem::align_of_val(&result_ptr_0)); unsafe { - *result_ptr = ret; + // HEAP32[((result)>>2)]=tempI64[0],HEAP32[(((result)+(4))>>2)]=tempI64[1]); + *result_ptr_0 = ret as i32; + *result_ptr_1 = (ret >> 32) as i32; } debug!( - "=> fd: {}, offset: {}, result_ptr: {}, whence: {} = {}\nlast os error: {}", + "=> fd: {}, offset: {}, result: {}, whence: {} = {}\nlast os error: {}", fd, offset, - result_ptr_value, + ret, whence, 0, Error::last_os_error(), From 47e38f0b2abd64a4f96d17e6be8f6205937f934b Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 11:18:49 -0700 Subject: [PATCH 05/13] Fixed formatting --- lib/emscripten/src/syscalls/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index c7acf4905..1d0f907ef 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -446,7 +446,7 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let ret = unsafe { lseek(fd, offset, whence) }; #[allow(clippy::cast_ptr_alignment)] let result_ptr_0 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32; - let result_ptr_1 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value+4) as *mut i32; + let result_ptr_1 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value + 4) as *mut i32; assert_eq!(8, mem::align_of_val(&result_ptr_0)); unsafe { // HEAP32[((result)>>2)]=tempI64[0],HEAP32[(((result)+(4))>>2)]=tempI64[1]); From 10eab1ca680814feabbb9a69dc1ebbdfcf2d24d9 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 11:21:03 -0700 Subject: [PATCH 06/13] Improved code --- lib/emscripten/src/syscalls/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 1d0f907ef..c65be55e3 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -433,12 +433,11 @@ pub fn ___syscall192(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in } /// lseek -#[allow(exceeding_bitshifts)] pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int debug!("emscripten::___syscall140 (lseek) {}", _which); let fd: i32 = varargs.get(ctx); - let _offset_high: i32 = varargs.get(ctx); + let _offset_high: i32 = varargs.get(ctx); // We don't use the offset high as emscripten skips it let offset_low: i32 = varargs.get(ctx); let result_ptr_value: i32 = varargs.get(ctx); let whence: i32 = varargs.get(ctx); From 73367ef6e9873aa7e9bf4bce70a0a1ccdb00784f Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 11:31:08 -0700 Subject: [PATCH 07/13] Fixed cast alignment issue --- lib/emscripten/src/syscalls/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index c65be55e3..455a189ce 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -445,6 +445,7 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let ret = unsafe { lseek(fd, offset, whence) }; #[allow(clippy::cast_ptr_alignment)] let result_ptr_0 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32; + #[allow(clippy::cast_ptr_alignment)] let result_ptr_1 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value + 4) as *mut i32; assert_eq!(8, mem::align_of_val(&result_ptr_0)); unsafe { From 6aa0ba8344c4cde644786c233928e16d2747b19f Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 11:31:51 -0700 Subject: [PATCH 08/13] Added changes to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bdfa5da3..39e048dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#513](https://github.com/wasmerio/wasmer/pull/510) Fix emscripten lseek implementation. - [#510](https://github.com/wasmerio/wasmer/pull/510) Simplify construction of floating point constants in LLVM backend. Fix LLVM assertion failure due to definition of %ctx. ## 0.5.1 - 2019-06-24 From 6aec631774f38c4e59f69de92ef5a58f15056ce8 Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 12:37:29 -0700 Subject: [PATCH 09/13] Improved lseek assignment --- lib/emscripten/src/syscalls/mod.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 455a189ce..5ee7c321e 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -50,7 +50,6 @@ use super::env; use std::cell::Cell; #[allow(unused_imports)] use std::io::Error; -use std::mem; use std::slice; /// exit @@ -439,20 +438,14 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let fd: i32 = varargs.get(ctx); let _offset_high: i32 = varargs.get(ctx); // We don't use the offset high as emscripten skips it let offset_low: i32 = varargs.get(ctx); - let result_ptr_value: i32 = varargs.get(ctx); + let result_ptr_value: WasmPtr = varargs.get(ctx); let whence: i32 = varargs.get(ctx); let offset = offset_low as off_t; let ret = unsafe { lseek(fd, offset, whence) }; - #[allow(clippy::cast_ptr_alignment)] - let result_ptr_0 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32; - #[allow(clippy::cast_ptr_alignment)] - let result_ptr_1 = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value + 4) as *mut i32; - assert_eq!(8, mem::align_of_val(&result_ptr_0)); - unsafe { - // HEAP32[((result)>>2)]=tempI64[0],HEAP32[(((result)+(4))>>2)]=tempI64[1]); - *result_ptr_0 = ret as i32; - *result_ptr_1 = (ret >> 32) as i32; - } + + let result_ptr = result_ptr_value.deref(ctx.memory(0)).unwrap(); + result_ptr.set(ret); + debug!( "=> fd: {}, offset: {}, result: {}, whence: {} = {}\nlast os error: {}", fd, From 6cc41f82c87e62a6db16fdc1c91e5bd11b9f45ff Mon Sep 17 00:00:00 2001 From: Syrus Date: Thu, 27 Jun 2019 12:42:27 -0700 Subject: [PATCH 10/13] Fixed lseek error in Windows --- lib/emscripten/src/syscalls/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 5ee7c321e..34ba90818 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -441,7 +441,7 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { let result_ptr_value: WasmPtr = varargs.get(ctx); let whence: i32 = varargs.get(ctx); let offset = offset_low as off_t; - let ret = unsafe { lseek(fd, offset, whence) }; + let ret = unsafe { lseek(fd, offset, whence) as i64 }; let result_ptr = result_ptr_value.deref(ctx.memory(0)).unwrap(); result_ptr.set(ret); From 299d41cfeaa3d13a7e7f2456fdc45a6652438ee4 Mon Sep 17 00:00:00 2001 From: Syrus Date: Sat, 29 Jun 2019 17:39:01 -0700 Subject: [PATCH 11/13] Improved emscripten dyncalls --- CHANGELOG.md | 1 + lib/emscripten/src/emscripten_target.rs | 5 +++++ lib/emscripten/src/lib.rs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39e048dfa..afbdc9062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#515](https://github.com/wasmerio/wasmer/pull/510) Improved Emscripten dyncalls - [#513](https://github.com/wasmerio/wasmer/pull/510) Fix emscripten lseek implementation. - [#510](https://github.com/wasmerio/wasmer/pull/510) Simplify construction of floating point constants in LLVM backend. Fix LLVM assertion failure due to definition of %ctx. diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 7e0b81af2..9e7819e58 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -634,6 +634,11 @@ pub fn invoke_iij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { invoke!(ctx, dyn_call_iij, index, a1, a2, a3) } +pub fn invoke_iji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 { + debug!("emscripten::invoke_iji"); + invoke!(ctx, dyn_call_iji, index, a1, a2, a3) +} + pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 { debug!("emscripten::invoke_iiji"); invoke!(ctx, dyn_call_iiji, index, a1, a2, a3, a4) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index e7b51a26a..1eb928b55 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -124,6 +124,7 @@ pub struct EmscriptenData<'a> { pub dyn_call_viiiiiiiiii: Option>, pub dyn_call_iij: Option>, + pub dyn_call_iji: Option>, pub dyn_call_iiji: Option>, pub dyn_call_iiijj: Option>, pub dyn_call_j: Option>, @@ -197,6 +198,7 @@ impl<'a> EmscriptenData<'a> { let dyn_call_viiiiiiiii = instance.func("dynCall_viiiiiiiii").ok(); let dyn_call_viiiiiiiiii = instance.func("dynCall_viiiiiiiiii").ok(); let dyn_call_iij = instance.func("dynCall_iij").ok(); + let dyn_call_iji = instance.func("dynCall_iji").ok(); let dyn_call_iiji = instance.func("dynCall_iiji").ok(); let dyn_call_iiijj = instance.func("dynCall_iiijj").ok(); let dyn_call_j = instance.func("dynCall_j").ok(); @@ -263,6 +265,7 @@ impl<'a> EmscriptenData<'a> { dyn_call_viiiiiiiii, dyn_call_viiiiiiiiii, dyn_call_iij, + dyn_call_iji, dyn_call_iiji, dyn_call_iiijj, dyn_call_j, @@ -912,6 +915,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii), "invoke_viiiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiiii), "invoke_iij" => func!(crate::emscripten_target::invoke_iij), + "invoke_iji" => func!(crate::emscripten_target::invoke_iji), "invoke_iiji" => func!(crate::emscripten_target::invoke_iiji), "invoke_iiijj" => func!(crate::emscripten_target::invoke_iiijj), "invoke_j" => func!(crate::emscripten_target::invoke_j), From a2b723d37e765d778bf57c45d842d68f44f1113b Mon Sep 17 00:00:00 2001 From: Syrus Date: Sun, 30 Jun 2019 11:10:54 -0700 Subject: [PATCH 12/13] Added more emscripten dyncalls --- lib/emscripten/src/emscripten_target.rs | 4 ++++ lib/emscripten/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index 9e7819e58..3ec4b83af 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -858,6 +858,10 @@ pub fn invoke_vijj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32 panic!("dyn_call_vijj is set to None"); } } +pub fn invoke_vidd(ctx: &mut Ctx, index: i32, a1: i32, a2: f64, a3: f64) { + debug!("emscripten::invoke_viid"); + invoke_no_return!(ctx, dyn_call_vidd, index, a1, a2, a3); +} pub fn invoke_viid(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: f64) { debug!("emscripten::invoke_viid"); invoke_no_return!(ctx, dyn_call_viid, index, a1, a2, a3); diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 1eb928b55..a61d02295 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -147,6 +147,7 @@ pub struct EmscriptenData<'a> { pub dyn_call_vijiii: Option>, pub dyn_call_vijj: Option>, pub dyn_call_viid: Option>, + pub dyn_call_vidd: Option>, pub dyn_call_viidii: Option>, pub dyn_call_viidddddddd: Option>, @@ -220,6 +221,7 @@ impl<'a> EmscriptenData<'a> { let dyn_call_vijiii = instance.func("dynCall_vijiii").ok(); let dyn_call_vijj = instance.func("dynCall_vijj").ok(); let dyn_call_viid = instance.func("dynCall_viid").ok(); + let dyn_call_vidd = instance.func("dynCall_vidd").ok(); let dyn_call_viidii = instance.func("dynCall_viidii").ok(); let dyn_call_viidddddddd = instance.func("dynCall_viidddddddd").ok(); @@ -287,6 +289,7 @@ impl<'a> EmscriptenData<'a> { dyn_call_vijiii, dyn_call_vijj, dyn_call_viid, + dyn_call_vidd, dyn_call_viidii, dyn_call_viidddddddd, temp_ret_0: 0, @@ -934,6 +937,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "invoke_viji" => func!(crate::emscripten_target::invoke_viji), "invoke_vijiii" => func!(crate::emscripten_target::invoke_vijiii), "invoke_vijj" => func!(crate::emscripten_target::invoke_vijj), + "invoke_vidd" => func!(crate::emscripten_target::invoke_vidd), "invoke_viid" => func!(crate::emscripten_target::invoke_viid), "invoke_viidii" => func!(crate::emscripten_target::invoke_viidii), "invoke_viidddddddd" => func!(crate::emscripten_target::invoke_viidddddddd), From 5f42045298aeafc43201d31fd85c8e9717c1e0a8 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 30 Jun 2019 16:28:26 -0700 Subject: [PATCH 13/13] Fixed CHANGELOG PR urls --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afbdc9062..9b23fbe29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,8 @@ All PRs to the Wasmer repository must add to this file. Blocks of changes will separated by version increments. ## **[Unreleased]** -- [#515](https://github.com/wasmerio/wasmer/pull/510) Improved Emscripten dyncalls -- [#513](https://github.com/wasmerio/wasmer/pull/510) Fix emscripten lseek implementation. +- [#515](https://github.com/wasmerio/wasmer/pull/515) Improved Emscripten dyncalls +- [#513](https://github.com/wasmerio/wasmer/pull/513) Fix emscripten lseek implementation. - [#510](https://github.com/wasmerio/wasmer/pull/510) Simplify construction of floating point constants in LLVM backend. Fix LLVM assertion failure due to definition of %ctx. ## 0.5.1 - 2019-06-24