Update to Cranelift 0.24.

This commit is contained in:
Dan Gohman
2018-11-16 11:37:39 -08:00
parent 0a0108f959
commit 74ccddcd64
11 changed files with 64 additions and 65 deletions

View File

@@ -18,8 +18,10 @@ name = "wasm2obj"
path = "src/wasm2obj.rs" path = "src/wasm2obj.rs"
[dependencies] [dependencies]
cranelift-codegen = "0.22.0" cranelift-codegen = "0.24.0"
cranelift-native = "0.22.0" cranelift-native = "0.24.0"
cranelift-entity = "0.24.0"
cranelift-wasm = "0.24.0"
wasmtime-environ = { path = "lib/environ" } wasmtime-environ = { path = "lib/environ" }
wasmtime-execute = { path = "lib/execute" } wasmtime-execute = { path = "lib/execute" }
wasmtime-obj = { path = "lib/obj" } wasmtime-obj = { path = "lib/obj" }
@@ -27,7 +29,7 @@ docopt = "1.0.1"
serde = "1.0.75" serde = "1.0.75"
serde_derive = "1.0.75" serde_derive = "1.0.75"
tempdir = "*" tempdir = "*"
faerie = "0.5.0" faerie = "0.6.0"
target-lexicon = { version = "0.0.3", default-features = false } target-lexicon = { version = "0.2.0", default-features = false }
[workspace] [workspace]

View File

@@ -10,9 +10,9 @@ cargo-fuzz = true
[dependencies] [dependencies]
wasmtime-environ = { path = "../lib/environ" } wasmtime-environ = { path = "../lib/environ" }
wasmtime-execute = { path = "../lib/execute" } wasmtime-execute = { path = "../lib/execute" }
cranelift-codegen = "0.22.0" cranelift-codegen = "0.24.0"
cranelift-wasm = "0.22.0" cranelift-wasm = "0.24.0"
cranelift-native = "0.22.0" cranelift-native = "0.24.0"
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
wasmparser = { version = "0.17.2", default-features = false } wasmparser = { version = "0.17.2", default-features = false }

View File

@@ -10,10 +10,9 @@ license = "Apache-2.0 WITH LLVM-exception"
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
cranelift-codegen = "0.22.0" cranelift-codegen = "0.24.0"
cranelift-entity = "0.22.0" cranelift-entity = "0.24.0"
cranelift-wasm = "0.22.0" cranelift-wasm = "0.24.0"
target-lexicon = "0.0.3"
memoffset = "0.2.1" memoffset = "0.2.1"
[badges] [badges]

View File

@@ -35,7 +35,6 @@
extern crate cranelift_codegen; extern crate cranelift_codegen;
extern crate cranelift_entity; extern crate cranelift_entity;
extern crate cranelift_wasm; extern crate cranelift_wasm;
extern crate target_lexicon;
#[macro_use] #[macro_use]
extern crate memoffset; extern crate memoffset;

View File

@@ -39,7 +39,7 @@ pub enum Export {
#[derive(Debug)] #[derive(Debug)]
pub struct Module { pub struct Module {
/// Unprocessed signatures exactly as provided by `declare_signature()`. /// Unprocessed signatures exactly as provided by `declare_signature()`.
pub signatures: Vec<ir::Signature>, pub signatures: PrimaryMap<SignatureIndex, ir::Signature>,
/// Names of imported functions. /// Names of imported functions.
pub imported_funcs: Vec<(String, String)>, pub imported_funcs: Vec<(String, String)>,
@@ -48,13 +48,13 @@ pub struct Module {
pub functions: PrimaryMap<FuncIndex, SignatureIndex>, pub functions: PrimaryMap<FuncIndex, SignatureIndex>,
/// WebAssembly tables. /// WebAssembly tables.
pub tables: Vec<Table>, pub tables: PrimaryMap<TableIndex, Table>,
/// WebAssembly linear memories. /// WebAssembly linear memories.
pub memories: Vec<Memory>, pub memories: PrimaryMap<MemoryIndex, Memory>,
/// WebAssembly global variables. /// WebAssembly global variables.
pub globals: Vec<Global>, pub globals: PrimaryMap<GlobalIndex, Global>,
/// Exported entities. /// Exported entities.
pub exports: HashMap<String, Export>, pub exports: HashMap<String, Export>,
@@ -70,12 +70,12 @@ impl Module {
/// Allocates the module data structures. /// Allocates the module data structures.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
signatures: Vec::new(), signatures: PrimaryMap::new(),
imported_funcs: Vec::new(), imported_funcs: Vec::new(),
functions: PrimaryMap::new(), functions: PrimaryMap::new(),
tables: Vec::new(), tables: PrimaryMap::new(),
memories: Vec::new(), memories: PrimaryMap::new(),
globals: Vec::new(), globals: PrimaryMap::new(),
exports: HashMap::new(), exports: HashMap::new(),
start_func: None, start_func: None,
table_elements: Vec::new(), table_elements: Vec::new(),

View File

@@ -9,9 +9,9 @@ repository = "https://github.com/CraneStation/wasmtime"
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
[dependencies] [dependencies]
cranelift-codegen = "0.22.0" cranelift-codegen = "0.24.0"
cranelift-entity = "0.22.0" cranelift-entity = "0.24.0"
cranelift-wasm = "0.22.0" cranelift-wasm = "0.24.0"
region = "0.3.0" region = "1.0.0"
wasmtime-environ = { path = "../environ" } wasmtime-environ = { path = "../environ" }
memmap = "0.7.0" memmap = "0.7.0"

View File

@@ -1,7 +1,7 @@
use cranelift_codegen::binemit::Reloc; use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_wasm::{DefinedFuncIndex, MemoryIndex}; use cranelift_wasm::{DefinedFuncIndex, MemoryIndex, TableIndex};
use instance::Instance; use instance::Instance;
use memory::LinearMemory; use memory::LinearMemory;
use region::protect; 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 // FIXME: update the VMMemory's size
let instance = (*vmctx.offset(4)) as *mut Instance; let instance = (*vmctx.offset(4)) as *mut Instance;
(*instance) (*instance)
.memory_mut(memory_index as MemoryIndex) .memory_mut(MemoryIndex::new(memory_index as usize))
.grow(size) .grow(size)
.unwrap_or(u32::max_value()) .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 // FIXME: read the VMMemory's size instead
let instance = (*vmctx.offset(4)) as *mut Instance; let instance = (*vmctx.offset(4)) as *mut Instance;
(*instance) (*instance)
.memory_mut(memory_index as MemoryIndex) .memory_mut(MemoryIndex::new(memory_index as usize))
.current_size() .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 let (default_table_ptr, default_table_len) = instance
.tables .tables
.get_mut(0) .get_mut(TableIndex::new(0))
.map(|table| (table.as_mut_ptr() as *mut u8, table.len())) .map(|table| (table.as_mut_ptr() as *mut u8, table.len()))
.unwrap_or((ptr::null_mut(), 0)); .unwrap_or((ptr::null_mut(), 0));
@@ -167,7 +167,7 @@ pub fn execute(
// Collect all memory base addresses and Vec. // Collect all memory base addresses and Vec.
let mut mem_base_addrs = instance let mut mem_base_addrs = instance
.memories .memories
.iter_mut() .values_mut()
.map(LinearMemory::base_addr) .map(LinearMemory::base_addr)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let vmctx = make_vmctx(instance, &mut mem_base_addrs); let vmctx = make_vmctx(instance, &mut mem_base_addrs);

View File

@@ -2,7 +2,9 @@
//! module. //! module.
use cranelift_codegen::ir; 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 memory::LinearMemory;
use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements}; use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
@@ -10,10 +12,10 @@ use wasmtime_environ::{Compilation, DataInitializer, Module, TableElements};
#[derive(Debug)] #[derive(Debug)]
pub struct Instance { pub struct Instance {
/// WebAssembly table data. /// WebAssembly table data.
pub tables: Vec<Vec<usize>>, pub tables: PrimaryMap<TableIndex, Vec<usize>>,
/// WebAssembly linear memory data. /// WebAssembly linear memory data.
pub memories: Vec<LinearMemory>, pub memories: PrimaryMap<MemoryIndex, LinearMemory>,
/// WebAssembly global variable data. /// WebAssembly global variable data.
pub globals: Vec<u8>, pub globals: Vec<u8>,
@@ -27,8 +29,8 @@ impl Instance {
data_initializers: &[DataInitializer], data_initializers: &[DataInitializer],
) -> Self { ) -> Self {
let mut result = Self { let mut result = Self {
tables: Vec::new(), tables: PrimaryMap::new(),
memories: Vec::new(), memories: PrimaryMap::new(),
globals: Vec::new(), globals: Vec::new(),
}; };
result.instantiate_tables(module, compilation, &module.table_elements); result.instantiate_tables(module, compilation, &module.table_elements);
@@ -45,8 +47,9 @@ impl Instance {
table_initializers: &[TableElements], table_initializers: &[TableElements],
) { ) {
debug_assert!(self.tables.is_empty()); debug_assert!(self.tables.is_empty());
self.tables.reserve_exact(module.tables.len()); // TODO: Enable this once PrimaryMap supports this.
for table in &module.tables { //self.tables.reserve_exact(module.tables.len());
for table in module.tables.values() {
let len = table.size; let len = table.size;
let mut v = Vec::with_capacity(len); let mut v = Vec::with_capacity(len);
v.resize(len, 0); v.resize(len, 0);
@@ -69,8 +72,9 @@ impl Instance {
fn instantiate_memories(&mut self, module: &Module, data_initializers: &[DataInitializer]) { fn instantiate_memories(&mut self, module: &Module, data_initializers: &[DataInitializer]) {
debug_assert!(self.memories.is_empty()); debug_assert!(self.memories.is_empty());
// Allocate the underlying memory and initialize it to all zeros. // Allocate the underlying memory and initialize it to all zeros.
self.memories.reserve_exact(module.memories.len()); // TODO: Enable this once PrimaryMap supports it.
for memory in &module.memories { //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)); let v = LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32));
self.memories.push(v); self.memories.push(v);
} }
@@ -92,24 +96,24 @@ impl Instance {
} }
/// Returns a mutable reference to a linear memory under the specified index. /// 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 self.memories
.get_mut(memory_index) .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. /// 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 &self
.memories .memories
.get(memory_index) .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] .as_ref()[address..address + len]
} }
/// Shows the value of a global variable. /// Shows the value of a global variable.
pub fn inspect_global(&self, global_index: GlobalIndex, ty: ir::Type) -> &[u8] { 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; let len = ty.bytes() as usize;
&self.globals[offset..offset + len] &self.globals[offset..offset + len]
} }

View File

@@ -8,7 +8,7 @@ categories = ["wasm"]
license = "Apache-2.0 WITH LLVM-exception" license = "Apache-2.0 WITH LLVM-exception"
[dependencies] [dependencies]
cranelift-codegen = "0.22.0" cranelift-codegen = "0.24.0"
cranelift-entity = "0.22.0" cranelift-entity = "0.24.0"
wasmtime-environ = { path = "../environ" } wasmtime-environ = { path = "../environ" }
faerie = "0.5.0" faerie = "0.6.0"

View File

@@ -34,7 +34,9 @@
)] )]
extern crate cranelift_codegen; extern crate cranelift_codegen;
extern crate cranelift_entity;
extern crate cranelift_native; extern crate cranelift_native;
extern crate cranelift_wasm;
extern crate docopt; extern crate docopt;
extern crate wasmtime_environ; extern crate wasmtime_environ;
extern crate wasmtime_execute; extern crate wasmtime_execute;
@@ -45,6 +47,8 @@ extern crate tempdir;
use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::settings; use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable; use cranelift_codegen::settings::Configurable;
use cranelift_entity::EntityRef;
use cranelift_wasm::MemoryIndex;
use docopt::Docopt; use docopt::Docopt;
use std::error::Error; use std::error::Error;
use std::fs::File; use std::fs::File;
@@ -95,9 +99,10 @@ fn main() {
.version(Some(String::from("0.0.0"))) .version(Some(String::from("0.0.0")))
.deserialize() .deserialize()
}).unwrap_or_else(|e| e.exit()); }).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"); panic!("host machine is not a supported target");
}); });
let mut flag_builder = settings::builder();
// Enable verifier passes in debug mode. // Enable verifier passes in debug mode.
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
@@ -183,7 +188,7 @@ fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), Stri
break; break;
} }
let memory = instance.inspect_memory( 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[1]).unwrap(),
str::parse(split[2]).unwrap(), str::parse(split[2]).unwrap(),
); );

View File

@@ -43,7 +43,7 @@ extern crate faerie;
extern crate target_lexicon; extern crate target_lexicon;
use cranelift_codegen::isa; use cranelift_codegen::isa;
use cranelift_codegen::settings::{self, Configurable}; use cranelift_codegen::settings;
use docopt::Docopt; use docopt::Docopt;
use faerie::Artifact; use faerie::Artifact;
use std::error::Error; use std::error::Error;
@@ -55,7 +55,7 @@ use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::process; use std::process;
use std::str::FromStr; use std::str::FromStr;
use target_lexicon::{OperatingSystem, Triple}; use target_lexicon::Triple;
use wasmtime_environ::{compile_module, Module, ModuleEnvironment}; use wasmtime_environ::{compile_module, Module, ModuleEnvironment};
use wasmtime_obj::emit_module; use wasmtime_obj::emit_module;
@@ -116,31 +116,21 @@ fn handle_module(path: PathBuf, target: &Option<String>, output: &str) -> Result
} }
}; };
let (flag_builder, isa_builder) = match *target { let isa_builder = match *target {
Some(ref target) => { Some(ref target) => {
let target = Triple::from_str(&target).map_err(|_| "could not parse --target")?; let target = Triple::from_str(&target).map_err(|_| "could not parse --target")?;
let mut flag_builder = settings::builder(); isa::lookup(target).map_err(|err| match err {
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::LookupError::SupportDisabled => { isa::LookupError::SupportDisabled => {
"support for architecture disabled at compile time" "support for architecture disabled at compile time"
} }
isa::LookupError::Unsupported => "unsupported architecture", 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"); panic!("host machine is not a supported target");
}), }),
}; };
let flag_builder = settings::builder();
let isa = isa_builder.finish(settings::Flags::new(flag_builder)); let isa = isa_builder.finish(settings::Flags::new(flag_builder));
let mut obj = Artifact::new(isa.triple().clone(), String::from(output)); let mut obj = Artifact::new(isa.triple().clone(), String::from(output));