From 7b9761f4a26024794937cf94e887d7c7d0b76246 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Wed, 6 Mar 2019 20:55:24 -0600 Subject: [PATCH] Update cranelift dependencies to 0.29.0 (#59) --- Cargo.toml | 6 ++---- fuzz/Cargo.toml | 6 +++--- lib/debug/Cargo.toml | 6 +++--- lib/debug/src/address_transform.rs | 2 +- lib/environ/Cargo.toml | 6 +++--- lib/environ/src/cranelift.rs | 8 +++++--- lib/environ/src/lib.rs | 4 ++-- lib/environ/src/module_environ.rs | 22 +++++++++++++++++++--- lib/jit/Cargo.toml | 8 ++++---- lib/jit/src/compiler.rs | 6 ++++-- lib/obj/Cargo.toml | 6 +++--- lib/runtime/Cargo.toml | 6 +++--- lib/wast/Cargo.toml | 8 ++++---- 13 files changed, 56 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e57e4e2f9..12ea660bfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,8 @@ name = "wasm2obj" path = "src/wasm2obj.rs" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-native = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-native = "0.29.0" wasmtime-debug = { path = "lib/debug" } wasmtime-environ = { path = "lib/environ" } wasmtime-runtime = { path = "lib/runtime" } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index a6981ddeea..647e1a47d2 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,9 +11,9 @@ cargo-fuzz = true [dependencies] wasmtime-environ = { path = "../lib/environ" } wasmtime-jit = { path = "../lib/jit" } -cranelift-codegen = "0.28.0" -cranelift-wasm = "0.28.0" -cranelift-native = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-wasm = "0.29.0" +cranelift-native = "0.29.0" libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } wasmparser = { version = "0.29.2", default-features = false } binaryen = "0.5.0" diff --git a/lib/debug/Cargo.toml b/lib/debug/Cargo.toml index 2ecaa13aee..1d0913cc8c 100644 --- a/lib/debug/Cargo.toml +++ b/lib/debug/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] gimli = "0.17.0" wasmparser = { version = "0.28.0" } -cranelift-codegen = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-entity = "0.29.0" +cranelift-wasm = "0.29.0" faerie = "0.7.0" wasmtime-environ = { path = "../environ", default-features = false } target-lexicon = { version = "0.2.0", default-features = false } diff --git a/lib/debug/src/address_transform.rs b/lib/debug/src/address_transform.rs index 8f19ecddf1..595e76f5df 100644 --- a/lib/debug/src/address_transform.rs +++ b/lib/debug/src/address_transform.rs @@ -56,7 +56,7 @@ impl AddressTransform { continue; } // src_offset is a wasm bytecode offset in the code section - let src_offset = t.srcloc.bits() as WasmAddress + fn_offset; + let src_offset = t.srcloc.bits() as WasmAddress - code_section_offset; assert!(fn_offset <= src_offset && src_offset <= fn_offset + fn_size); lookup.insert( src_offset, diff --git a/lib/environ/Cargo.toml b/lib/environ/Cargo.toml index 9c0b9a3531..e2f9303421 100644 --- a/lib/environ/Cargo.toml +++ b/lib/environ/Cargo.toml @@ -12,9 +12,9 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-entity = "0.29.0" +cranelift-wasm = "0.29.0" cast = { version = "0.2.2", default-features = false } failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } diff --git a/lib/environ/src/cranelift.rs b/lib/environ/src/cranelift.rs index 0e3a762f39..5c62be4f25 100644 --- a/lib/environ/src/cranelift.rs +++ b/lib/environ/src/cranelift.rs @@ -9,6 +9,7 @@ use crate::func_environ::{ get_memory32_grow_name, get_memory32_size_name, FuncEnvironment, }; use crate::module::Module; +use crate::module_environ::FunctionBodyData; use cranelift_codegen::binemit; use cranelift_codegen::ir; use cranelift_codegen::ir::ExternalName; @@ -112,7 +113,7 @@ fn get_address_transform( /// associated relocations. pub fn compile_module<'data, 'module>( module: &'module Module, - function_body_inputs: PrimaryMap, + function_body_inputs: PrimaryMap>, isa: &dyn isa::TargetIsa, generate_debug_info: bool, ) -> Result<(Compilation, Relocations, AddressTransforms), CompileError> { @@ -122,7 +123,7 @@ pub fn compile_module<'data, 'module>( function_body_inputs .into_iter() - .collect::>() + .collect::)>>() .par_iter() .map(|(i, input)| { let func_index = module.func_index(*i); @@ -133,7 +134,8 @@ pub fn compile_module<'data, 'module>( let mut trans = FuncTranslator::new(); trans .translate( - input, + input.data, + input.module_offset, &mut context.func, &mut FuncEnvironment::new(isa.frontend_config(), module), ) diff --git a/lib/environ/src/lib.rs b/lib/environ/src/lib.rs index 9bd8620a39..e5cd6c6643 100644 --- a/lib/environ/src/lib.rs +++ b/lib/environ/src/lib.rs @@ -54,8 +54,8 @@ pub use crate::module::{ Export, MemoryPlan, MemoryStyle, Module, TableElements, TablePlan, TableStyle, }; pub use crate::module_environ::{ - translate_signature, DataInitializer, DataInitializerLocation, ModuleEnvironment, - ModuleTranslation, + translate_signature, DataInitializer, DataInitializerLocation, FunctionBodyData, + ModuleEnvironment, ModuleTranslation, }; pub use crate::tunables::Tunables; pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets}; diff --git a/lib/environ/src/module_environ.rs b/lib/environ/src/module_environ.rs index 1a75d21e45..1fa666030e 100644 --- a/lib/environ/src/module_environ.rs +++ b/lib/environ/src/module_environ.rs @@ -13,6 +13,15 @@ use std::boxed::Box; use std::string::String; use std::vec::Vec; +/// Contains function data: byte code and its offset in the module. +pub struct FunctionBodyData<'a> { + /// Body byte code. + pub data: &'a [u8], + + /// Body offset in the module file. + pub module_offset: usize, +} + /// The result of translating via `ModuleEnvironment`. Function bodies are not /// yet translated, and data initializers have not yet been copied out of the /// original buffer. @@ -24,7 +33,7 @@ pub struct ModuleTranslation<'data> { pub module: Module, /// References to the function bodies. - pub function_body_inputs: PrimaryMap, + pub function_body_inputs: PrimaryMap>, /// References to the data initializers. pub data_initializers: Vec>, @@ -260,8 +269,15 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data }); } - fn define_function_body(&mut self, body_bytes: &'data [u8]) -> WasmResult<()> { - self.result.function_body_inputs.push(body_bytes); + fn define_function_body( + &mut self, + body_bytes: &'data [u8], + body_offset: usize, + ) -> WasmResult<()> { + self.result.function_body_inputs.push(FunctionBodyData { + data: body_bytes, + module_offset: body_offset, + }); Ok(()) } diff --git a/lib/jit/Cargo.toml b/lib/jit/Cargo.toml index 4075962700..15b568a78c 100644 --- a/lib/jit/Cargo.toml +++ b/lib/jit/Cargo.toml @@ -12,10 +12,10 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" -cranelift-frontend = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-entity = "0.29.0" +cranelift-wasm = "0.29.0" +cranelift-frontend = "0.29.0" wasmtime-environ = { path = "../environ", default-features = false } wasmtime-runtime = { path = "../runtime", default-features = false } wasmtime-debug = { path = "../debug", default-features = false } diff --git a/lib/jit/src/compiler.rs b/lib/jit/src/compiler.rs index 1970d55b20..9f7084de06 100644 --- a/lib/jit/src/compiler.rs +++ b/lib/jit/src/compiler.rs @@ -16,7 +16,9 @@ use std::string::String; use std::vec::Vec; use wasmtime_debug::{emit_debugsections_image, DebugInfoData}; use wasmtime_environ::cranelift; -use wasmtime_environ::{Compilation, CompileError, Module, Relocations, Tunables}; +use wasmtime_environ::{ + Compilation, CompileError, FunctionBodyData, Module, Relocations, Tunables, +}; use wasmtime_runtime::{InstantiationError, SignatureRegistry, VMFunctionBody}; /// A WebAssembly code JIT compiler. @@ -66,7 +68,7 @@ impl Compiler { pub(crate) fn compile<'data>( &mut self, module: &Module, - function_body_inputs: PrimaryMap, + function_body_inputs: PrimaryMap>, debug_data: Option, ) -> Result< ( diff --git a/lib/obj/Cargo.toml b/lib/obj/Cargo.toml index 79def3e330..c90c8a0ec7 100644 --- a/lib/obj/Cargo.toml +++ b/lib/obj/Cargo.toml @@ -12,8 +12,8 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-entity = "0.29.0" +cranelift-wasm = "0.29.0" wasmtime-environ = { path = "../environ" } faerie = "0.7.1" diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 9b42668bf6..e976c67a19 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -12,9 +12,9 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-entity = "0.28.0" -cranelift-wasm = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-entity = "0.29.0" +cranelift-wasm = "0.29.0" wasmtime-environ = { path = "../environ", default-features = false } region = "2.0.0" lazy_static = "1.2.0" diff --git a/lib/wast/Cargo.toml b/lib/wast/Cargo.toml index a5540f4e85..c12b02b1d8 100644 --- a/lib/wast/Cargo.toml +++ b/lib/wast/Cargo.toml @@ -12,10 +12,10 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.28.0" -cranelift-native = "0.28.0" -cranelift-wasm = "0.28.0" -cranelift-entity = "0.28.0" +cranelift-codegen = "0.29.0" +cranelift-native = "0.29.0" +cranelift-wasm = "0.29.0" +cranelift-entity = "0.29.0" wasmtime-jit = { path = "../jit" } wasmtime-runtime = { path = "../runtime" } wasmtime-environ = { path = "../environ" }