diff --git a/Cargo.toml b/Cargo.toml index 19d88d8abd..bbbea71d06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,10 @@ name = "wasm2obj" path = "src/wasm2obj.rs" [dependencies] -cranelift-codegen = "0.22.0" -cranelift-native = "0.22.0" +cranelift-codegen = "0.24.0" +cranelift-native = "0.24.0" +cranelift-entity = "0.24.0" +cranelift-wasm = "0.24.0" wasmtime-environ = { path = "lib/environ" } wasmtime-execute = { path = "lib/execute" } wasmtime-obj = { path = "lib/obj" } @@ -27,7 +29,7 @@ docopt = "1.0.1" serde = "1.0.75" serde_derive = "1.0.75" tempdir = "*" -faerie = "0.5.0" -target-lexicon = { version = "0.0.3", default-features = false } +faerie = "0.6.0" +target-lexicon = { version = "0.2.0", default-features = false } [workspace] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index ae5a89800f..7fce2b145e 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,9 +10,9 @@ cargo-fuzz = true [dependencies] wasmtime-environ = { path = "../lib/environ" } wasmtime-execute = { path = "../lib/execute" } -cranelift-codegen = "0.22.0" -cranelift-wasm = "0.22.0" -cranelift-native = "0.22.0" +cranelift-codegen = "0.24.0" +cranelift-wasm = "0.24.0" +cranelift-native = "0.24.0" libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } wasmparser = { version = "0.17.2", default-features = false } diff --git a/lib/environ/Cargo.toml b/lib/environ/Cargo.toml index 196db3c5c4..7681f8bb6e 100644 --- a/lib/environ/Cargo.toml +++ b/lib/environ/Cargo.toml @@ -10,10 +10,9 @@ license = "Apache-2.0 WITH LLVM-exception" readme = "README.md" [dependencies] -cranelift-codegen = "0.22.0" -cranelift-entity = "0.22.0" -cranelift-wasm = "0.22.0" -target-lexicon = "0.0.3" +cranelift-codegen = "0.24.0" +cranelift-entity = "0.24.0" +cranelift-wasm = "0.24.0" memoffset = "0.2.1" [badges] diff --git a/lib/environ/src/lib.rs b/lib/environ/src/lib.rs index 2c99a49a9a..4ad0c82ad6 100644 --- a/lib/environ/src/lib.rs +++ b/lib/environ/src/lib.rs @@ -35,7 +35,6 @@ extern crate cranelift_codegen; extern crate cranelift_entity; extern crate cranelift_wasm; -extern crate target_lexicon; #[macro_use] extern crate memoffset; diff --git a/lib/environ/src/module.rs b/lib/environ/src/module.rs index 15afc86768..3e0391e04a 100644 --- a/lib/environ/src/module.rs +++ b/lib/environ/src/module.rs @@ -39,7 +39,7 @@ pub enum Export { #[derive(Debug)] pub struct Module { /// Unprocessed signatures exactly as provided by `declare_signature()`. - pub signatures: Vec, + pub signatures: PrimaryMap, /// Names of imported functions. pub imported_funcs: Vec<(String, String)>, @@ -48,13 +48,13 @@ pub struct Module { pub functions: PrimaryMap, /// WebAssembly tables. - pub tables: Vec, + pub tables: PrimaryMap, /// WebAssembly linear memories. - pub memories: Vec, + pub memories: PrimaryMap, /// WebAssembly global variables. - pub globals: Vec, + pub globals: PrimaryMap, /// Exported entities. pub exports: HashMap, @@ -70,12 +70,12 @@ impl Module { /// Allocates the module data structures. pub fn new() -> Self { Self { - signatures: Vec::new(), + signatures: PrimaryMap::new(), imported_funcs: Vec::new(), functions: PrimaryMap::new(), - tables: Vec::new(), - memories: Vec::new(), - globals: Vec::new(), + tables: PrimaryMap::new(), + memories: PrimaryMap::new(), + globals: PrimaryMap::new(), exports: HashMap::new(), start_func: None, table_elements: Vec::new(), diff --git a/lib/execute/Cargo.toml b/lib/execute/Cargo.toml index 16af933a91..f98a3ecaed 100644 --- a/lib/execute/Cargo.toml +++ b/lib/execute/Cargo.toml @@ -9,9 +9,9 @@ repository = "https://github.com/CraneStation/wasmtime" license = "Apache-2.0 WITH LLVM-exception" [dependencies] -cranelift-codegen = "0.22.0" -cranelift-entity = "0.22.0" -cranelift-wasm = "0.22.0" -region = "0.3.0" +cranelift-codegen = "0.24.0" +cranelift-entity = "0.24.0" +cranelift-wasm = "0.24.0" +region = "1.0.0" wasmtime-environ = { path = "../environ" } memmap = "0.7.0" diff --git a/lib/execute/src/execute.rs b/lib/execute/src/execute.rs index 90e0f1ee9b..1fd1092c59 100644 --- a/lib/execute/src/execute.rs +++ b/lib/execute/src/execute.rs @@ -1,7 +1,7 @@ use cranelift_codegen::binemit::Reloc; use cranelift_codegen::isa::TargetIsa; use cranelift_entity::{EntityRef, PrimaryMap}; -use cranelift_wasm::{DefinedFuncIndex, MemoryIndex}; +use cranelift_wasm::{DefinedFuncIndex, MemoryIndex, TableIndex}; use instance::Instance; use memory::LinearMemory; use region::protect; @@ -87,7 +87,7 @@ extern "C" fn grow_memory(size: u32, memory_index: u32, vmctx: *mut *mut u8) -> // FIXME: update the VMMemory's size let instance = (*vmctx.offset(4)) as *mut Instance; (*instance) - .memory_mut(memory_index as MemoryIndex) + .memory_mut(MemoryIndex::new(memory_index as usize)) .grow(size) .unwrap_or(u32::max_value()) } @@ -98,7 +98,7 @@ extern "C" fn current_memory(memory_index: u32, vmctx: *mut *mut u8) -> u32 { // FIXME: read the VMMemory's size instead let instance = (*vmctx.offset(4)) as *mut Instance; (*instance) - .memory_mut(memory_index as MemoryIndex) + .memory_mut(MemoryIndex::new(memory_index as usize)) .current_size() } } @@ -113,7 +113,7 @@ fn make_vmctx(instance: &mut Instance, mem_base_addrs: &mut [*mut u8]) -> Vec<*m let (default_table_ptr, default_table_len) = instance .tables - .get_mut(0) + .get_mut(TableIndex::new(0)) .map(|table| (table.as_mut_ptr() as *mut u8, table.len())) .unwrap_or((ptr::null_mut(), 0)); @@ -167,7 +167,7 @@ pub fn execute( // Collect all memory base addresses and Vec. let mut mem_base_addrs = instance .memories - .iter_mut() + .values_mut() .map(LinearMemory::base_addr) .collect::>(); let vmctx = make_vmctx(instance, &mut mem_base_addrs); diff --git a/lib/execute/src/instance.rs b/lib/execute/src/instance.rs index 5c427527ac..d9d214a7d2 100644 --- a/lib/execute/src/instance.rs +++ b/lib/execute/src/instance.rs @@ -2,7 +2,9 @@ //! module. use cranelift_codegen::ir; -use cranelift_wasm::GlobalIndex; +use cranelift_entity::EntityRef; +use cranelift_entity::PrimaryMap; +use cranelift_wasm::{GlobalIndex, MemoryIndex, TableIndex}; use memory::LinearMemory; use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements}; @@ -10,10 +12,10 @@ use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements}; #[derive(Debug)] pub struct Instance { /// WebAssembly table data. - pub tables: Vec>, + pub tables: PrimaryMap>, /// WebAssembly linear memory data. - pub memories: Vec, + pub memories: PrimaryMap, /// WebAssembly global variable data. pub globals: Vec, @@ -27,8 +29,8 @@ impl Instance { data_initializers: &[DataInitializer], ) -> Self { let mut result = Self { - tables: Vec::new(), - memories: Vec::new(), + tables: PrimaryMap::new(), + memories: PrimaryMap::new(), globals: Vec::new(), }; result.instantiate_tables(module, compilation, &module.table_elements); @@ -45,8 +47,9 @@ impl Instance { table_initializers: &[TableElements], ) { debug_assert!(self.tables.is_empty()); - self.tables.reserve_exact(module.tables.len()); - for table in &module.tables { + // TODO: Enable this once PrimaryMap supports this. + //self.tables.reserve_exact(module.tables.len()); + for table in module.tables.values() { let len = table.size; let mut v = Vec::with_capacity(len); v.resize(len, 0); @@ -69,8 +72,9 @@ impl Instance { fn instantiate_memories(&mut self, module: &Module, data_initializers: &[DataInitializer]) { debug_assert!(self.memories.is_empty()); // Allocate the underlying memory and initialize it to all zeros. - self.memories.reserve_exact(module.memories.len()); - for memory in &module.memories { + // TODO: Enable this once PrimaryMap supports it. + //self.memories.reserve_exact(module.memories.len()); + for memory in module.memories.values() { let v = LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32)); self.memories.push(v); } @@ -92,24 +96,24 @@ impl Instance { } /// Returns a mutable reference to a linear memory under the specified index. - pub fn memory_mut(&mut self, memory_index: usize) -> &mut LinearMemory { + pub fn memory_mut(&mut self, memory_index: MemoryIndex) -> &mut LinearMemory { self.memories .get_mut(memory_index) - .unwrap_or_else(|| panic!("no memory for index {}", memory_index)) + .unwrap_or_else(|| panic!("no memory for index {}", memory_index.index())) } /// Returns a slice of the contents of allocated linear memory. - pub fn inspect_memory(&self, memory_index: usize, address: usize, len: usize) -> &[u8] { + pub fn inspect_memory(&self, memory_index: MemoryIndex, address: usize, len: usize) -> &[u8] { &self .memories .get(memory_index) - .unwrap_or_else(|| panic!("no memory for index {}", memory_index)) + .unwrap_or_else(|| panic!("no memory for index {}", memory_index.index())) .as_ref()[address..address + len] } /// Shows the value of a global variable. pub fn inspect_global(&self, global_index: GlobalIndex, ty: ir::Type) -> &[u8] { - let offset = global_index * 8; + let offset = global_index.index() * 8; let len = ty.bytes() as usize; &self.globals[offset..offset + len] } diff --git a/lib/obj/Cargo.toml b/lib/obj/Cargo.toml index c37d1253e8..e64e0eb415 100644 --- a/lib/obj/Cargo.toml +++ b/lib/obj/Cargo.toml @@ -8,7 +8,7 @@ categories = ["wasm"] license = "Apache-2.0 WITH LLVM-exception" [dependencies] -cranelift-codegen = "0.22.0" -cranelift-entity = "0.22.0" +cranelift-codegen = "0.24.0" +cranelift-entity = "0.24.0" wasmtime-environ = { path = "../environ" } -faerie = "0.5.0" +faerie = "0.6.0" diff --git a/src/main.rs b/src/main.rs index 014b02401b..8e0995c0e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,9 @@ )] extern crate cranelift_codegen; +extern crate cranelift_entity; extern crate cranelift_native; +extern crate cranelift_wasm; extern crate docopt; extern crate wasmtime_environ; extern crate wasmtime_execute; @@ -45,6 +47,8 @@ extern crate tempdir; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings; use cranelift_codegen::settings::Configurable; +use cranelift_entity::EntityRef; +use cranelift_wasm::MemoryIndex; use docopt::Docopt; use std::error::Error; use std::fs::File; @@ -95,9 +99,10 @@ fn main() { .version(Some(String::from("0.0.0"))) .deserialize() }).unwrap_or_else(|e| e.exit()); - let (mut flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| { + let isa_builder = cranelift_native::builder().unwrap_or_else(|_| { panic!("host machine is not a supported target"); }); + let mut flag_builder = settings::builder(); // Enable verifier passes in debug mode. if cfg!(debug_assertions) { @@ -183,7 +188,7 @@ fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), Stri break; } let memory = instance.inspect_memory( - str::parse(split[0]).unwrap(), + MemoryIndex::new(str::parse(split[0]).unwrap()), str::parse(split[1]).unwrap(), str::parse(split[2]).unwrap(), ); diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index 1c419f0076..e7785dba62 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -43,7 +43,7 @@ extern crate faerie; extern crate target_lexicon; use cranelift_codegen::isa; -use cranelift_codegen::settings::{self, Configurable}; +use cranelift_codegen::settings; use docopt::Docopt; use faerie::Artifact; use std::error::Error; @@ -55,7 +55,7 @@ use std::path::Path; use std::path::PathBuf; use std::process; use std::str::FromStr; -use target_lexicon::{OperatingSystem, Triple}; +use target_lexicon::Triple; use wasmtime_environ::{compile_module, Module, ModuleEnvironment}; use wasmtime_obj::emit_module; @@ -116,31 +116,21 @@ fn handle_module(path: PathBuf, target: &Option, output: &str) -> Result } }; - let (flag_builder, isa_builder) = match *target { + let isa_builder = match *target { Some(ref target) => { let target = Triple::from_str(&target).map_err(|_| "could not parse --target")?; - let mut flag_builder = settings::builder(); - match target.operating_system { - OperatingSystem::Windows => { - flag_builder.set("call_conv", "windows_fastcall").unwrap(); - } - _ => { - flag_builder.set("call_conv", "system_v").unwrap(); - } - }; - - let isa_builder = isa::lookup(target).map_err(|err| match err { + isa::lookup(target).map_err(|err| match err { isa::LookupError::SupportDisabled => { "support for architecture disabled at compile time" } isa::LookupError::Unsupported => "unsupported architecture", - })?; - (flag_builder, isa_builder) + })? } - None => cranelift_native::builders().unwrap_or_else(|_| { + None => cranelift_native::builder().unwrap_or_else(|_| { panic!("host machine is not a supported target"); }), }; + let flag_builder = settings::builder(); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); let mut obj = Artifact::new(isa.triple().clone(), String::from(output));