From a1ca7069afda1f71aa6ace1b9d777a4027245e15 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:03:40 +0100 Subject: [PATCH 01/12] fix(llvm-backend) Remove unused imports. --- lib/llvm-backend/src/backend.rs | 5 +---- lib/llvm-backend/src/code.rs | 4 ++-- lib/llvm-backend/src/intrinsics.rs | 5 +---- lib/llvm-backend/src/lib.rs | 13 ++----------- lib/llvm-backend/src/platform/unix.rs | 4 +--- lib/llvm-backend/src/trampolines.rs | 7 +++---- 6 files changed, 10 insertions(+), 28 deletions(-) diff --git a/lib/llvm-backend/src/backend.rs b/lib/llvm-backend/src/backend.rs index 742069d48..8831f6aa7 100644 --- a/lib/llvm-backend/src/backend.rs +++ b/lib/llvm-backend/src/backend.rs @@ -23,10 +23,7 @@ use wasmer_runtime_core::{ export::Context, module::{ModuleInfo, ModuleInner}, structures::TypedIndex, - types::{ - FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type, - Value, - }, + types::{FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, SigIndex, Type, Value}, vm::{self, ImportBacking}, vmcalls, }; diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 173262b67..284e2aa36 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -3,14 +3,14 @@ use inkwell::{ context::Context, module::{Linkage, Module}, passes::PassManager, - types::{BasicType, BasicTypeEnum, FunctionType, IntType, PointerType}, + types::{BasicType, BasicTypeEnum, FunctionType, PointerType}, values::{BasicValue, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue}, AddressSpace, FloatPredicate, IntPredicate, }; use smallvec::SmallVec; use wasmer_runtime_core::{ memory::MemoryType, - module::{ExportIndex, ModuleInfo}, + module::ModuleInfo, structures::{Map, SliceMap, TypedIndex}, types::{ FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex, diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index ba1e3abd3..1ddbe743f 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -4,10 +4,7 @@ use inkwell::{ context::Context, module::Module, types::{BasicType, FloatType, FunctionType, IntType, PointerType, StructType, VoidType}, - values::{ - BasicValue, BasicValueEnum, FloatValue, FunctionValue, InstructionValue, IntValue, - PointerValue, - }, + values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, IntValue, PointerValue}, AddressSpace, }; use std::marker::PhantomData; diff --git a/lib/llvm-backend/src/lib.rs b/lib/llvm-backend/src/lib.rs index ee4e02bbc..5029c7cf7 100644 --- a/lib/llvm-backend/src/lib.rs +++ b/lib/llvm-backend/src/lib.rs @@ -1,10 +1,5 @@ #![cfg_attr(nightly, feature(unwind_attributes))] -use inkwell::{ - execution_engine::JitFunction, - targets::{CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetMachine}, - OptimizationLevel, -}; use wasmer_runtime_core::{ backend::{Compiler, CompilerConfig, Token}, cache::{Artifact, Error as CacheError}, @@ -47,14 +42,10 @@ impl Compiler for LLVMCompiler { // Create placeholder values here. let cache_gen = { - use wasmer_runtime_core::backend::{ - sys::Memory, CacheGen, ProtectedCaller, UserTrapper, - }; + use wasmer_runtime_core::backend::{sys::Memory, CacheGen}; use wasmer_runtime_core::cache::Error as CacheError; - use wasmer_runtime_core::error::RuntimeResult; use wasmer_runtime_core::module::ModuleInfo; - use wasmer_runtime_core::types::{FuncIndex, Value}; - use wasmer_runtime_core::vm; + struct Placeholder; impl CacheGen for Placeholder { fn generate_cache( diff --git a/lib/llvm-backend/src/platform/unix.rs b/lib/llvm-backend/src/platform/unix.rs index 2267ab129..266426303 100644 --- a/lib/llvm-backend/src/platform/unix.rs +++ b/lib/llvm-backend/src/platform/unix.rs @@ -1,7 +1,5 @@ use libc::{c_void, siginfo_t}; -use nix::sys::signal::{ - sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV, -}; +use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGSEGV}; /// `__register_frame` and `__deregister_frame` on macos take a single fde as an /// argument, so we need to parse the fde table here. diff --git a/lib/llvm-backend/src/trampolines.rs b/lib/llvm-backend/src/trampolines.rs index 4619cb990..425418050 100644 --- a/lib/llvm-backend/src/trampolines.rs +++ b/lib/llvm-backend/src/trampolines.rs @@ -3,10 +3,9 @@ use inkwell::{ builder::Builder, context::Context, module::{Linkage, Module}, - passes::PassManager, - types::{BasicType, BasicTypeEnum, FunctionType, PointerType}, - values::{BasicValue, FunctionValue, PhiValue, PointerValue}, - AddressSpace, FloatPredicate, IntPredicate, + types::{BasicType, FunctionType}, + values::FunctionValue, + AddressSpace, }; use wasmer_runtime_core::{ module::ModuleInfo, From 91f40639b7524ad86925cac59092aadba8709f56 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:04:09 +0100 Subject: [PATCH 02/12] fix(llvm-back) Mark `WasmTrapType` as deadcode. This enum is not used directly by Rust, but used externally. --- lib/llvm-backend/src/backend.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/llvm-backend/src/backend.rs b/lib/llvm-backend/src/backend.rs index 8831f6aa7..2ee3877c5 100644 --- a/lib/llvm-backend/src/backend.rs +++ b/lib/llvm-backend/src/backend.rs @@ -54,6 +54,7 @@ enum LLVMResult { OBJECT_LOAD_FAILURE, } +#[allow(dead_code)] #[repr(C)] enum WasmTrapType { Unreachable = 0, From dea4705dcbf4f2c929ffc927281bc8b16a142715 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:04:56 +0100 Subject: [PATCH 03/12] fix(llvm-backend) `LLVMBackend::new` doesn't use instrinsics yet. --- lib/llvm-backend/src/backend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/llvm-backend/src/backend.rs b/lib/llvm-backend/src/backend.rs index 2ee3877c5..5a692c40e 100644 --- a/lib/llvm-backend/src/backend.rs +++ b/lib/llvm-backend/src/backend.rs @@ -218,7 +218,7 @@ pub struct LLVMBackend { } impl LLVMBackend { - pub fn new(module: Module, intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) { + pub fn new(module: Module, _intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) { Target::initialize_x86(&InitializationConfig { asm_parser: true, asm_printer: true, From e3f39fc1278cb27a04844f58f205908946d55e44 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:05:39 +0100 Subject: [PATCH 04/12] fix(llvm-backend) `parse_function` doesn't need a `Module`. --- lib/llvm-backend/src/code.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 284e2aa36..14c3ced2d 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -102,7 +102,6 @@ pub fn parse_function_bodies( parse_function( &context, - &module, &builder, &intrinsics, info, @@ -143,7 +142,6 @@ pub fn parse_function_bodies( fn parse_function( context: &Context, - module: &Module, builder: &Builder, intrinsics: &Intrinsics, info: &ModuleInfo, From 20378de0e7d6fdce7a991d62782ff13f2596cf5d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:06:11 +0100 Subject: [PATCH 05/12] fix(llvm-backend) `llvm_sig` variable is not used here. --- lib/llvm-backend/src/code.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 14c3ced2d..601d117d9 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -153,7 +153,6 @@ fn parse_function( ) -> Result<(), BinaryReaderError> { let sig_index = info.func_assoc[func_index.convert_up(info)]; let func_sig = &info.signatures[sig_index]; - let llvm_sig = &signatures[sig_index]; let function = functions[func_index]; let mut state = State::new(); From 00e4b2511149c9421177ca5d968bf9fbb7975d38 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:06:31 +0100 Subject: [PATCH 06/12] fix(llvm-backend) No need to enumerate items in this iterator. --- lib/llvm-backend/src/code.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 601d117d9..20324bac9 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -190,7 +190,7 @@ fn parse_function( let param_len = locals.len(); let mut local_idx = 0; - for (index, local) in locals_reader.into_iter().enumerate() { + for local in locals_reader.into_iter() { let (count, ty) = local?; let wasmer_ty = type_to_type(ty)?; let ty = type_to_llvm(intrinsics, wasmer_ty); From 7645a812d98eebd32cad41c16d8b4db6d01656ac Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:07:08 +0100 Subject: [PATCH 07/12] fix(llvm-backend) Remove unused variables. --- lib/llvm-backend/src/code.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 20324bac9..05cde0694 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -487,7 +487,6 @@ fn parse_function( if let ControlFrame::IfElse { if_else, next, - phis, if_else_state, .. } = &frame @@ -863,7 +862,7 @@ fn parse_function( let value = call_site.try_as_basic_value().left().unwrap(); state.push1(value); } - returns @ _ => unimplemented!("multi-value returns"), + _ => unimplemented!("multi-value returns"), } } @@ -2155,7 +2154,7 @@ fn parse_function( [one_value] => { builder.build_return(Some(one_value)); } - returns @ _ => { + _ => { // let struct_ty = llvm_sig.get_return_type().as_struct_type(); // let ret_struct = struct_ty.const_zero(); unimplemented!("multi-value returns not yet implemented") @@ -2208,7 +2207,7 @@ fn trap_if_not_representatable_as_int( ), }; - let masked = builder.build_and( + builder.build_and( float_bits, int_ty.const_int(exponent_mask, false), "masked_bits", From 76d26d97ac5bcb1850ba7dacba0253f69f011131 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:07:38 +0100 Subject: [PATCH 08/12] fix(llvm-backend) Remove `Intrinsics.ctx_ty`, `CtxType.ctx_ty, and `.ctx_ptr_ty`. --- lib/llvm-backend/src/intrinsics.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index 1ddbe743f..cd683981e 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -114,7 +114,6 @@ pub struct Intrinsics { pub throw_trap: FunctionValue, - ctx_ty: StructType, pub ctx_ptr_ty: PointerType, } @@ -367,7 +366,6 @@ impl Intrinsics { void_ty.fn_type(&[i32_ty_basic], false), None, ), - ctx_ty, ctx_ptr_ty, } } @@ -380,9 +378,6 @@ impl Intrinsics { cache_builder: Builder, ) -> CtxType<'a> { CtxType { - ctx_ty: self.ctx_ty, - ctx_ptr_ty: self.ctx_ptr_ty, - ctx_ptr_value: func_value.get_nth_param(0).unwrap().into_pointer_value(), builder, @@ -432,9 +427,6 @@ struct ImportedFuncCache { } pub struct CtxType<'a> { - ctx_ty: StructType, - ctx_ptr_ty: PointerType, - ctx_ptr_value: PointerValue, builder: &'a Builder, From b03980f8c92b70df64c1fc14d4f1e0ea898deff4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:08:43 +0100 Subject: [PATCH 09/12] fix(llvm-backend) Remove unused variables or functions. --- lib/llvm-backend/src/intrinsics.rs | 47 +++--------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index cd683981e..1b367f5d4 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -449,9 +449,8 @@ impl<'a> CtxType<'a> { } pub fn memory(&mut self, index: MemoryIndex) -> MemoryCache { - let (cached_memories, builder, info, ctx_ptr_value, intrinsics, cache_builder) = ( + let (cached_memories, info, ctx_ptr_value, intrinsics, cache_builder) = ( &mut self.cached_memories, - self.builder, self.info, self.ctx_ptr_value, self.intrinsics, @@ -607,10 +606,8 @@ impl<'a> CtxType<'a> { } pub fn dynamic_sigindex(&mut self, index: SigIndex) -> IntValue { - let (cached_sigindices, builder, info, ctx_ptr_value, intrinsics, cache_builder) = ( + let (cached_sigindices, ctx_ptr_value, intrinsics, cache_builder) = ( &mut self.cached_sigindices, - self.builder, - self.info, self.ctx_ptr_value, self.intrinsics, &self.cache_builder, @@ -640,9 +637,8 @@ impl<'a> CtxType<'a> { } pub fn global_cache(&mut self, index: GlobalIndex) -> GlobalCache { - let (cached_globals, builder, ctx_ptr_value, info, intrinsics, cache_builder) = ( + let (cached_globals, ctx_ptr_value, info, intrinsics, cache_builder) = ( &mut self.cached_globals, - self.builder, self.ctx_ptr_value, self.info, self.intrinsics, @@ -717,9 +713,8 @@ impl<'a> CtxType<'a> { } pub fn imported_func(&mut self, index: ImportedFuncIndex) -> (PointerValue, PointerValue) { - let (cached_imported_functions, builder, ctx_ptr_value, intrinsics, cache_builder) = ( + let (cached_imported_functions, ctx_ptr_value, intrinsics, cache_builder) = ( &mut self.cached_imported_functions, - self.builder, self.ctx_ptr_value, self.intrinsics, &self.cache_builder, @@ -759,38 +754,4 @@ impl<'a> CtxType<'a> { (imported_func_cache.func_ptr, imported_func_cache.ctx_ptr) } - - pub fn build_trap(&self) { - self.builder.build_call(self.intrinsics.trap, &[], "trap"); - } } - -// pub struct Ctx { -// /// A pointer to an array of locally-defined memories, indexed by `MemoryIndex`. -// pub(crate) memories: *mut *mut LocalMemory, - -// /// A pointer to an array of locally-defined tables, indexed by `TableIndex`. -// pub(crate) tables: *mut *mut LocalTable, - -// /// A pointer to an array of locally-defined globals, indexed by `GlobalIndex`. -// pub(crate) globals: *mut *mut LocalGlobal, - -// /// A pointer to an array of imported memories, indexed by `MemoryIndex, -// pub(crate) imported_memories: *mut *mut LocalMemory, - -// /// A pointer to an array of imported tables, indexed by `TableIndex`. -// pub(crate) imported_tables: *mut *mut LocalTable, - -// /// A pointer to an array of imported globals, indexed by `GlobalIndex`. -// pub(crate) imported_globals: *mut *mut LocalGlobal, - -// /// A pointer to an array of imported functions, indexed by `FuncIndex`. -// pub(crate) imported_funcs: *mut ImportedFunc, - -// local_backing: *mut LocalBacking, -// import_backing: *mut ImportBacking, -// module: *const ModuleInner, - -// pub data: *mut c_void, -// pub data_finalizer: Option, -// } From 5cd45cbc28132a65942a883f2b4011d610b4e91d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:09:10 +0100 Subject: [PATCH 10/12] fix(llvm-backend) Mark a variable as unused. --- lib/llvm-backend/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/llvm-backend/src/lib.rs b/lib/llvm-backend/src/lib.rs index 5029c7cf7..50b061731 100644 --- a/lib/llvm-backend/src/lib.rs +++ b/lib/llvm-backend/src/lib.rs @@ -47,10 +47,11 @@ impl Compiler for LLVMCompiler { use wasmer_runtime_core::module::ModuleInfo; struct Placeholder; + impl CacheGen for Placeholder { fn generate_cache( &self, - module: &ModuleInner, + _module: &ModuleInner, ) -> Result<(Box, Box<[u8]>, Memory), CacheError> { unimplemented!() } From 34b4f2fb1139e3cffb0e91c02fc924914cde30a6 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:09:39 +0100 Subject: [PATCH 11/12] fix(llvm-backend) Mark some variables as unused. --- lib/llvm-backend/src/platform/unix.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/llvm-backend/src/platform/unix.rs b/lib/llvm-backend/src/platform/unix.rs index 266426303..12894f6bc 100644 --- a/lib/llvm-backend/src/platform/unix.rs +++ b/lib/llvm-backend/src/platform/unix.rs @@ -49,24 +49,22 @@ pub unsafe fn install_signal_handler() { SaFlags::SA_ONSTACK | SaFlags::SA_SIGINFO, SigSet::empty(), ); - // sigaction(SIGFPE, &sa).unwrap(); - // sigaction(SIGILL, &sa).unwrap(); sigaction(SIGSEGV, &sa).unwrap(); sigaction(SIGBUS, &sa).unwrap(); } #[cfg_attr(nightly, unwind(allowed))] extern "C" fn signal_trap_handler( - signum: ::nix::libc::c_int, - siginfo: *mut siginfo_t, - ucontext: *mut c_void, + _signum: ::nix::libc::c_int, + _siginfo: *mut siginfo_t, + _ucontext: *mut c_void, ) { unsafe { - /// Apparently, we can unwind from arbitary instructions, as long - /// as we don't need to catch the exception inside the function that - /// was interrupted. - /// - /// This works on macos, not sure about linux. + // Apparently, we can unwind from arbitary instructions, as long + // as we don't need to catch the exception inside the function that + // was interrupted. + // + // This works on macos, not sure about linux. throw_trap(2); } } From 8179dd6f96938131ed3f3fe0638a2bed2ebf62a3 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 29 Mar 2019 10:09:56 +0100 Subject: [PATCH 12/12] fix(llvm-backend) Remove `sign_type` from `generate_trampoline`. --- lib/llvm-backend/src/trampolines.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/llvm-backend/src/trampolines.rs b/lib/llvm-backend/src/trampolines.rs index 425418050..23677618b 100644 --- a/lib/llvm-backend/src/trampolines.rs +++ b/lib/llvm-backend/src/trampolines.rs @@ -42,20 +42,12 @@ pub fn generate_trampolines( Some(Linkage::External), ); - generate_trampoline( - trampoline_func, - func_type, - sig, - context, - builder, - intrinsics, - ); + generate_trampoline(trampoline_func, sig, context, builder, intrinsics); } } fn generate_trampoline( trampoline_func: FunctionValue, - sig_type: FunctionType, func_sig: &FuncSig, context: &Context, builder: &Builder,