diff --git a/Cargo.toml b/Cargo.toml index ce1d36219cbe..0045065d9d36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ edition = "2018" default-run = "wasmtime" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-native = "0.40.0" -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } +cranelift-native = "0.41.0" wasmtime-api = { path = "wasmtime-api" } wasmtime-debug = { path = "wasmtime-debug" } wasmtime-environ = { path = "wasmtime-environ" } diff --git a/cranelift-version.sh b/cranelift-version.sh index 730c6b888f99..006e4a53634f 100755 --- a/cranelift-version.sh +++ b/cranelift-version.sh @@ -9,7 +9,7 @@ topdir=$(dirname "$0") cd "$topdir" # All the cranelift-* crates have the same version number -version="0.38.0" +version="0.41.0" # Update all of the Cargo.toml files. echo "Updating crate versions to $version" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index d6b8f5be52dd..cd8d4c4ac418 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,9 +11,9 @@ cargo-fuzz = true [dependencies] wasmtime-environ = { path = "../wasmtime-environ" } wasmtime-jit = { path = "../wasmtime-jit" } -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } -cranelift-native = "0.40.0" +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } +cranelift-native = "0.41.0" libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } wasmparser = { version = "0.36.0", default-features = false } binaryen = "0.5.0" diff --git a/misc/wasmtime-py/Cargo.toml b/misc/wasmtime-py/Cargo.toml index c5bf58fcc5d8..51bfd193f216 100644 --- a/misc/wasmtime-py/Cargo.toml +++ b/misc/wasmtime-py/Cargo.toml @@ -12,11 +12,11 @@ name = "_wasmtime" crate-type = ["cdylib"] [dependencies] -cranelift-codegen = "0.40.0" -cranelift-native = "0.40.0" -cranelift-entity = "0.40.0" -cranelift-wasm = "0.40.0" -cranelift-frontend = "0.40.0" +cranelift-codegen = "0.41.0" +cranelift-native = "0.41.0" +cranelift-entity = "0.41.0" +cranelift-wasm = "0.41.0" +cranelift-frontend = "0.41.0" wasmtime-environ = { path = "../../wasmtime-environ" } wasmtime-interface-types = { path = "../../wasmtime-interface-types" } wasmtime-jit = { path = "../../wasmtime-jit" } diff --git a/misc/wasmtime-py/src/import.rs b/misc/wasmtime-py/src/import.rs index 2fa2280aa5ae..452c7a38b4e0 100644 --- a/misc/wasmtime-py/src/import.rs +++ b/misc/wasmtime-py/src/import.rs @@ -353,6 +353,14 @@ impl binemit::RelocSink for RelocSink { ) { panic!("trampoline compilation should not produce external symbol relocs"); } + fn reloc_constant( + &mut self, + _code_offset: binemit::CodeOffset, + _reloc: binemit::Reloc, + _constant_offset: ir::ConstantOffset, + ) { + panic!("trampoline compilation should not produce constant relocs"); + } fn reloc_jt( &mut self, _offset: binemit::CodeOffset, diff --git a/misc/wasmtime-rust/Cargo.toml b/misc/wasmtime-rust/Cargo.toml index 91d1865baf73..0c7b675d307f 100644 --- a/misc/wasmtime-rust/Cargo.toml +++ b/misc/wasmtime-rust/Cargo.toml @@ -12,8 +12,8 @@ test = false doctest = false [dependencies] -cranelift-codegen = "0.40.0" -cranelift-native = "0.40.0" +cranelift-codegen = "0.41.0" +cranelift-native = "0.41.0" failure = "0.1.5" wasmtime-interface-types = { path = "../../wasmtime-interface-types" } wasmtime-jit = { path = "../../wasmtime-jit" } diff --git a/wasmtime-api/Cargo.toml b/wasmtime-api/Cargo.toml index 48d443e19681..21a51f59c81d 100644 --- a/wasmtime-api/Cargo.toml +++ b/wasmtime-api/Cargo.toml @@ -12,11 +12,11 @@ name = "wasmtime_api" crate-type = ["lib", "staticlib", "cdylib"] [dependencies] -cranelift-codegen = "0.40.0" -cranelift-native = "0.40.0" -cranelift-entity = "0.40.0" -cranelift-wasm = "0.40.0" -cranelift-frontend = "0.40.0" +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-native = "0.41.0" +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } +cranelift-frontend = "0.41.0" wasmtime-runtime = { path="../wasmtime-runtime" } wasmtime-environ = { path="../wasmtime-environ" } wasmtime-jit = { path="../wasmtime-jit" } diff --git a/wasmtime-api/src/trampoline/func.rs b/wasmtime-api/src/trampoline/func.rs index 3982a8642bb7..288b4e00e6a8 100644 --- a/wasmtime-api/src/trampoline/func.rs +++ b/wasmtime-api/src/trampoline/func.rs @@ -254,6 +254,14 @@ impl binemit::RelocSink for RelocSink { ) { panic!("trampoline compilation should not produce external symbol relocs"); } + fn reloc_constant( + &mut self, + _code_offset: binemit::CodeOffset, + _reloc: binemit::Reloc, + _constant_offset: ir::ConstantOffset, + ) { + panic!("trampoline compilation should not produce constant relocs"); + } fn reloc_jt( &mut self, _offset: binemit::CodeOffset, diff --git a/wasmtime-debug/Cargo.toml b/wasmtime-debug/Cargo.toml index 3db02c0b4ba0..599418f681c9 100644 --- a/wasmtime-debug/Cargo.toml +++ b/wasmtime-debug/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] gimli = "0.19.0" wasmparser = { version = "0.36.0" } -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } faerie = "0.10.1" wasmtime-environ = { path = "../wasmtime-environ", default-features = false } target-lexicon = { version = "0.4.0", default-features = false } diff --git a/wasmtime-environ/Cargo.toml b/wasmtime-environ/Cargo.toml index 72428ca4bfb7..6310e5ac8b36 100644 --- a/wasmtime-environ/Cargo.toml +++ b/wasmtime-environ/Cargo.toml @@ -12,9 +12,9 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } lightbeam = { path = "../lightbeam", optional = true } failure = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false } @@ -35,6 +35,7 @@ tempfile = "3" target-lexicon = { version = "0.4.0", default-features = false } pretty_env_logger = "0.3.0" rand = { version = "0.7.0", features = ["small_rng"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde", "all-arch"] } [features] default = ["std"] diff --git a/wasmtime-environ/src/cache.rs b/wasmtime-environ/src/cache.rs index 71de817f3aa4..b1ad589369d4 100644 --- a/wasmtime-environ/src/cache.rs +++ b/wasmtime-environ/src/cache.rs @@ -1,5 +1,5 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges}; -use crate::compilation::{CodeAndJTOffsets, Compilation, Relocations}; +use crate::compilation::{Compilation, Relocations}; use crate::module::Module; use crate::module_environ::FunctionBodyData; use core::hash::Hasher; @@ -7,11 +7,9 @@ use cranelift_codegen::{ir, isa}; use cranelift_entity::PrimaryMap; use cranelift_wasm::DefinedFuncIndex; use lazy_static::lazy_static; -use log::{debug, warn}; -use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor}; -use serde::ser::{self, Serialize, SerializeSeq, SerializeStruct, Serializer}; +use log::{debug, trace, warn}; +use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -use std::fmt; use std::fs; use std::io; use std::path::PathBuf; @@ -152,28 +150,27 @@ pub mod conf { lazy_static! { static ref SELF_MTIME: String = { - match std::env::current_exe() { - Ok(path) => match fs::metadata(&path) { - Ok(metadata) => match metadata.modified() { - Ok(mtime) => match mtime.duration_since(std::time::UNIX_EPOCH) { - Ok(duration) => format!("{}", duration.as_millis()), - Err(err) => format!("m{}", err.duration().as_millis()), - }, - Err(_) => { - warn!("Failed to get modification time of current executable"); - "no-mtime".to_string() - } - }, - Err(_) => { - warn!("Failed to get metadata of current executable"); - "no-mtime".to_string() - } - }, - Err(_) => { - warn!("Failed to get path of current executable"); - "no-mtime".to_string() - } - } + std::env::current_exe() + .map_err(|_| warn!("Failed to get path of current executable")) + .ok() + .and_then(|path| { + fs::metadata(&path) + .map_err(|_| warn!("Failed to get metadata of current executable")) + .ok() + }) + .and_then(|metadata| { + metadata + .modified() + .map_err(|_| warn!("Failed to get metadata of current executable")) + .ok() + }) + .and_then(|mtime| { + Some(match mtime.duration_since(std::time::UNIX_EPOCH) { + Ok(duration) => format!("{}", duration.as_millis()), + Err(err) => format!("m{}", err.duration().as_millis()), + }) + }) + .unwrap_or("no-mtime".to_string()) }; } @@ -181,7 +178,7 @@ pub struct ModuleCacheEntry { mod_cache_path: Option, } -#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct ModuleCacheData { compilation: Compilation, relocations: Relocations, @@ -239,91 +236,73 @@ impl ModuleCacheEntry { None }; - ModuleCacheEntry { mod_cache_path } + Self { mod_cache_path } } pub fn get_data(&self) -> Option { - if let Some(p) = &self.mod_cache_path { - match fs::read(p) { - Ok(compressed_cache_bytes) => match zstd::decode_all(&compressed_cache_bytes[..]) { - Ok(cache_bytes) => match bincode::deserialize(&cache_bytes[..]) { - Ok(data) => Some(data), - Err(err) => { - warn!("Failed to deserialize cached code: {}", err); - None - } - }, - Err(err) => { - warn!("Failed to decompress cached code: {}", err); - None - } - }, - Err(_) => None, - } - } else { - None - } + let path = self.mod_cache_path.as_ref()?; + trace!("get_data() for path: {}", path.display()); + let compressed_cache_bytes = fs::read(path).ok()?; + let cache_bytes = zstd::decode_all(&compressed_cache_bytes[..]) + .map_err(|err| warn!("Failed to decompress cached code: {}", err)) + .ok()?; + bincode::deserialize(&cache_bytes[..]) + .map_err(|err| warn!("Failed to deserialize cached code: {}", err)) + .ok() } pub fn update_data(&self, data: &ModuleCacheData) { - if let Some(p) = &self.mod_cache_path { - let cache_buf = match bincode::serialize(&data) { - Ok(data) => match zstd::encode_all(&data[..], conf::compression_level()) { - Ok(data) => data, - Err(err) => { - warn!("Failed to compress cached code: {}", err); - return; - } - }, - Err(err) => { - warn!("Failed to serialize cached code: {}", err); - return; - } - }; - // Optimize syscalls: first, try writing to disk. It should succeed in most cases. - // Otherwise, try creating the cache directory and retry writing to the file. - match fs::write(p, &cache_buf) { - Ok(()) => (), - Err(err) => { - debug!( - "Attempting to create the cache directory, because \ - failed to write cached code to disk, path: {}, message: {}", - p.display(), - err, + let _ = self.update_data_impl(data); + } + + fn update_data_impl(&self, data: &ModuleCacheData) -> Option<()> { + let path = self.mod_cache_path.as_ref()?; + trace!("update_data() for path: {}", path.display()); + let serialized_data = bincode::serialize(&data) + .map_err(|err| warn!("Failed to serialize cached code: {}", err)) + .ok()?; + let compressed_data = zstd::encode_all(&serialized_data[..], conf::compression_level()) + .map_err(|err| warn!("Failed to compress cached code: {}", err)) + .ok()?; + + // Optimize syscalls: first, try writing to disk. It should succeed in most cases. + // Otherwise, try creating the cache directory and retry writing to the file. + let err = fs::write(path, &compressed_data).err()?; // return on success + debug!( + "Attempting to create the cache directory, because \ + failed to write cached code to disk, path: {}, message: {}", + path.display(), + err, + ); + + let cache_dir = path.parent().unwrap(); + fs::create_dir_all(cache_dir) + .map_err(|err| { + warn!( + "Failed to create cache directory, path: {}, message: {}", + cache_dir.display(), + err + ) + }) + .ok()?; + + let err = fs::write(path, &compressed_data).err()?; + warn!( + "Failed to write cached code to disk, path: {}, message: {}", + path.display(), + err + ); + fs::remove_file(path) + .map_err(|err| { + if err.kind() != io::ErrorKind::NotFound { + warn!( + "Failed to cleanup invalid cache, path: {}, message: {}", + path.display(), + err ); - let cache_dir = p.parent().unwrap(); - match fs::create_dir_all(cache_dir) { - Ok(()) => match fs::write(p, &cache_buf) { - Ok(()) => (), - Err(err) => { - warn!( - "Failed to write cached code to disk, path: {}, message: {}", - p.display(), - err - ); - match fs::remove_file(p) { - Ok(()) => (), - Err(err) => { - if err.kind() != io::ErrorKind::NotFound { - warn!( - "Failed to cleanup invalid cache, path: {}, message: {}", - p.display(), - err - ); - } - } - } - } - }, - Err(err) => warn!( - "Failed to create cache directory, path: {}, message: {}", - cache_dir.display(), - err - ), - } } - } - } + }) + .ok() } } @@ -370,175 +349,5 @@ impl Hasher for Sha256Hasher { } } -//-//////////////////////////////////////////////////////////////////// -// Serialization and deserialization of type containing SecondaryMap // -//-//////////////////////////////////////////////////////////////////// - -enum JtOffsetsWrapper<'a> { - Ref(&'a ir::JumpTableOffsets), // for serialization - Data(ir::JumpTableOffsets), // for deserialization -} - -impl Serialize for CodeAndJTOffsets { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut cajto = serializer.serialize_struct("CodeAndJTOffsets", 2)?; - cajto.serialize_field("body", &self.body)?; - cajto.serialize_field("jt_offsets", &JtOffsetsWrapper::Ref(&self.jt_offsets))?; - cajto.end() - } -} - -impl<'de> Deserialize<'de> for CodeAndJTOffsets { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(serde::Deserialize)] - #[serde(field_identifier, rename_all = "lowercase")] - enum Field { - Body, - JtOffsets, - }; - - struct CodeAndJTOffsetsVisitor; - - impl<'de> Visitor<'de> for CodeAndJTOffsetsVisitor { - type Value = CodeAndJTOffsets; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("struct CodeAndJTOffsets") - } - - fn visit_seq(self, mut seq: V) -> Result - where - V: SeqAccess<'de>, - { - let body = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(0, &self))?; - let jt_offsets = seq - .next_element()? - .ok_or_else(|| de::Error::invalid_length(1, &self))?; - match jt_offsets { - JtOffsetsWrapper::Data(jt_offsets) => Ok(CodeAndJTOffsets { body, jt_offsets }), - JtOffsetsWrapper::Ref(_) => Err(de::Error::custom( - "Received invalid variant of JtOffsetsWrapper", - )), - } - } - - fn visit_map(self, mut map: V) -> Result - where - V: MapAccess<'de>, - { - let mut body = None; - let mut jt_offsets = None; - while let Some(key) = map.next_key()? { - match key { - Field::Body => { - if body.is_some() { - return Err(de::Error::duplicate_field("body")); - } - body = Some(map.next_value()?); - } - Field::JtOffsets => { - if jt_offsets.is_some() { - return Err(de::Error::duplicate_field("jt_offsets")); - } - jt_offsets = Some(map.next_value()?); - } - } - } - - let body = body.ok_or_else(|| de::Error::missing_field("body"))?; - let jt_offsets = - jt_offsets.ok_or_else(|| de::Error::missing_field("jt_offsets"))?; - match jt_offsets { - JtOffsetsWrapper::Data(jt_offsets) => Ok(CodeAndJTOffsets { body, jt_offsets }), - JtOffsetsWrapper::Ref(_) => Err(de::Error::custom( - "Received invalid variant of JtOffsetsWrapper", - )), - } - } - } - - const FIELDS: &'static [&'static str] = &["body", "jt_offsets"]; - deserializer.deserialize_struct("CodeAndJTOffsets", FIELDS, CodeAndJTOffsetsVisitor) - } -} - -impl Serialize for JtOffsetsWrapper<'_> { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - match self { - JtOffsetsWrapper::Ref(data) => { - // TODO: bincode encodes option as "byte for Some/None" and then optionally the content - // TODO: we can actually optimize it by encoding manually bitmask, then elements - let default_val = data.get_default(); - let mut seq = serializer.serialize_seq(Some(1 + data.len()))?; - seq.serialize_element(&Some(default_val))?; - for e in data.values() { - let some_e = Some(e); - seq.serialize_element(if e == default_val { &None } else { &some_e })?; - } - seq.end() - } - JtOffsetsWrapper::Data(_) => Err(ser::Error::custom( - "Received invalid variant of JtOffsetsWrapper", - )), - } - } -} - -impl<'de> Deserialize<'de> for JtOffsetsWrapper<'_> { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct JtOffsetsWrapperVisitor; - - impl<'de> Visitor<'de> for JtOffsetsWrapperVisitor { - type Value = JtOffsetsWrapper<'static>; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("struct JtOffsetsWrapper") - } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - match seq.next_element()? { - Some(Some(default_val)) => { - let mut m = cranelift_entity::SecondaryMap::with_default(default_val); - let mut idx = 0; - while let Some(val) = seq.next_element()? { - let val: Option<_> = val; // compiler can't infer the type, and this line is needed - match ir::JumpTable::with_number(idx) { - Some(jt_idx) => m[jt_idx] = val.unwrap_or(default_val), - None => { - return Err(serde::de::Error::custom( - "Invalid JumpTable reference", - )) - } - }; - idx += 1; - } - Ok(JtOffsetsWrapper::Data(m)) - } - _ => Err(serde::de::Error::custom("Default value required")), - } - } - } - - deserializer.deserialize_seq(JtOffsetsWrapperVisitor {}) - } -} - #[cfg(test)] mod tests; diff --git a/wasmtime-environ/src/cache/tests.rs b/wasmtime-environ/src/cache/tests.rs index 133d6999967a..2401e4561098 100644 --- a/wasmtime-environ/src/cache/tests.rs +++ b/wasmtime-environ/src/cache/tests.rs @@ -1,8 +1,7 @@ use super::*; use crate::address_map::{FunctionAddressMap, InstructionAddressMap}; -use crate::compilation::{Relocation, RelocationTarget}; +use crate::compilation::{CodeAndJTOffsets, Relocation, RelocationTarget}; use crate::module::{MemoryPlan, MemoryStyle, Module}; -use cranelift_codegen::ir::entities::JumpTable; use cranelift_codegen::{binemit, ir, isa, settings, ValueLocRange}; use cranelift_entity::EntityRef; use cranelift_entity::{PrimaryMap, SecondaryMap}; @@ -10,7 +9,7 @@ use cranelift_wasm::{DefinedFuncIndex, FuncIndex, Global, GlobalInit, Memory, Si use rand::rngs::SmallRng; use rand::{Rng, SeedableRng}; use std::boxed::Box; -use std::cmp::{max, min}; +use std::cmp::min; use std::fs; use std::str::FromStr; use std::vec::Vec; @@ -45,7 +44,7 @@ fn test_write_read_cache() { code_container.resize(0x4000, 0); rng.fill(&mut code_container[..]); - let isa1 = new_isa("riscv64"); + let isa1 = new_isa("riscv64-unknown-unknown"); let isa2 = new_isa("i386"); let module1 = new_module(&mut rng); let module2 = new_module(&mut rng); @@ -264,64 +263,3 @@ impl ModuleCacheEntry { &self.mod_cache_path } } - -// cranelift's types (including SecondaryMap) doesn't implement PartialEq -impl PartialEq for ModuleCacheData { - fn eq(&self, other: &Self) -> bool { - // compilation field - if self.compilation.len() != other.compilation.len() { - return false; - } - - for i in (0..self.compilation.len()).map(DefinedFuncIndex::new) { - let lhs = self.compilation.get(i); - let rhs = other.compilation.get(i); - if lhs.body != rhs.body || lhs.jt_offsets.get_default() != rhs.jt_offsets.get_default() - { - return false; - } - - for j in (0..max(lhs.jt_offsets.len(), rhs.jt_offsets.len())).map(JumpTable::new) { - if lhs.jt_offsets.get(j) != rhs.jt_offsets.get(j) { - return false; - } - } - } - - // relocs - { - if self.relocations.len() != other.relocations.len() { - return false; - } - let it_lhs = self.relocations.iter(); - let it_rhs = other.relocations.iter(); - if it_lhs.zip(it_rhs).any(|(lhs, rhs)| lhs != rhs) { - return false; - } - } - - // debug symbols - { - if self.address_transforms.len() != other.address_transforms.len() { - return false; - } - let it_lhs = self.address_transforms.iter(); - let it_rhs = other.address_transforms.iter(); - if it_lhs.zip(it_rhs).any(|(lhs, rhs)| lhs != rhs) { - return false; - } - } - - true - } -} - -// binemit::Reloc doesn't implement PartialEq -impl PartialEq for Relocation { - fn eq(&self, other: &Self) -> bool { - self.reloc as u64 == other.reloc as u64 - && self.reloc_target == other.reloc_target - && self.offset == other.offset - && self.addend == other.addend - } -} diff --git a/wasmtime-environ/src/compilation.rs b/wasmtime-environ/src/compilation.rs index 27344c2d4d41..4d199a86fe29 100644 --- a/wasmtime-environ/src/compilation.rs +++ b/wasmtime-environ/src/compilation.rs @@ -12,7 +12,7 @@ use std::ops::Range; use std::vec::Vec; /// Compiled machine code: body and jump table offsets. -#[derive(Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct CodeAndJTOffsets { /// The function body. pub body: Vec, @@ -24,7 +24,7 @@ pub struct CodeAndJTOffsets { type Functions = PrimaryMap; /// The result of compiling a WebAssembly module's functions. -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)] pub struct Compilation { /// Compiled machine code for the function bodies. functions: Functions, @@ -95,7 +95,7 @@ impl<'a> Iterator for Iter<'a> { } /// A record of a relocation to perform. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct Relocation { /// The relocation code. pub reloc: binemit::Reloc, diff --git a/wasmtime-environ/src/cranelift.rs b/wasmtime-environ/src/cranelift.rs index c994cca04483..7e87a026b50e 100644 --- a/wasmtime-environ/src/cranelift.rs +++ b/wasmtime-environ/src/cranelift.rs @@ -72,6 +72,17 @@ impl binemit::RelocSink for RelocSink { addend, }); } + + fn reloc_constant( + &mut self, + _code_offset: binemit::CodeOffset, + _reloc: binemit::Reloc, + _constant_offset: ir::ConstantOffset, + ) { + // Do nothing for now: cranelift emits constant data after the function code and also emits + // function code with correct relative offsets to the constant data. + } + fn reloc_jt(&mut self, offset: binemit::CodeOffset, reloc: binemit::Reloc, jt: ir::JumpTable) { self.func_relocs.push(Relocation { reloc, diff --git a/wasmtime-interface-types/Cargo.toml b/wasmtime-interface-types/Cargo.toml index 42ebd47e3886..0017bd6a73ed 100644 --- a/wasmtime-interface-types/Cargo.toml +++ b/wasmtime-interface-types/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = "0.40.0" +cranelift-codegen = "0.41.0" failure = "0.1" walrus = "0.11.0" wasmparser = "0.36.0" diff --git a/wasmtime-jit/Cargo.toml b/wasmtime-jit/Cargo.toml index 266c5ed6c219..d69b6c99326f 100644 --- a/wasmtime-jit/Cargo.toml +++ b/wasmtime-jit/Cargo.toml @@ -11,10 +11,10 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } -cranelift-frontend = "0.40.0" +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } +cranelift-frontend = "0.41.0" wasmtime-environ = { path = "../wasmtime-environ", default-features = false } wasmtime-runtime = { path = "../wasmtime-runtime", default-features = false } wasmtime-debug = { path = "../wasmtime-debug", default-features = false } diff --git a/wasmtime-jit/src/compiler.rs b/wasmtime-jit/src/compiler.rs index 84d1a4624e98..8cd3de4398bc 100644 --- a/wasmtime-jit/src/compiler.rs +++ b/wasmtime-jit/src/compiler.rs @@ -330,6 +330,14 @@ impl binemit::RelocSink for RelocSink { ) { panic!("trampoline compilation should not produce external symbol relocs"); } + fn reloc_constant( + &mut self, + _code_offset: binemit::CodeOffset, + _reloc: binemit::Reloc, + _constant_offset: ir::ConstantOffset, + ) { + panic!("trampoline compilation should not produce constant relocs"); + } fn reloc_jt( &mut self, _offset: binemit::CodeOffset, diff --git a/wasmtime-obj/Cargo.toml b/wasmtime-obj/Cargo.toml index 969ca5474780..702109247e8c 100644 --- a/wasmtime-obj/Cargo.toml +++ b/wasmtime-obj/Cargo.toml @@ -11,8 +11,8 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } wasmtime-environ = { path = "../wasmtime-environ" } faerie = "0.10.1" diff --git a/wasmtime-runtime/Cargo.toml b/wasmtime-runtime/Cargo.toml index baa36adfa79b..df9b48985554 100644 --- a/wasmtime-runtime/Cargo.toml +++ b/wasmtime-runtime/Cargo.toml @@ -11,9 +11,9 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } wasmtime-environ = { path = "../wasmtime-environ", default-features = false } region = "2.0.0" lazy_static = "1.2.0" diff --git a/wasmtime-runtime/src/mmap.rs b/wasmtime-runtime/src/mmap.rs index f54d8613872e..7cd024e905b1 100644 --- a/wasmtime-runtime/src/mmap.rs +++ b/wasmtime-runtime/src/mmap.rs @@ -4,6 +4,7 @@ use core::ptr; use core::slice; use errno; +#[cfg(not(target_os = "windows"))] use libc; use region; use std::string::{String, ToString}; diff --git a/wasmtime-wasi-c/Cargo.toml b/wasmtime-wasi-c/Cargo.toml index 3b39e038d191..8f6d92f62c48 100644 --- a/wasmtime-wasi-c/Cargo.toml +++ b/wasmtime-wasi-c/Cargo.toml @@ -12,9 +12,9 @@ readme = "README.md" wasmtime-runtime = { path = "../wasmtime-runtime" } wasmtime-environ = { path = "../wasmtime-environ" } wasmtime-jit = { path = "../wasmtime-jit" } -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } target-lexicon = "0.4.0" log = { version = "0.4.8", default-features = false } libc = "0.2.60" diff --git a/wasmtime-wasi/Cargo.toml b/wasmtime-wasi/Cargo.toml index 9ff5293efdeb..3afc12e78e7b 100644 --- a/wasmtime-wasi/Cargo.toml +++ b/wasmtime-wasi/Cargo.toml @@ -13,9 +13,9 @@ wasmtime-runtime = { path = "../wasmtime-runtime" } wasmtime-environ = { path = "../wasmtime-environ" } wasmtime-jit = { path = "../wasmtime-jit" } wasi-common = { git = "https://github.com/CraneStation/wasi-common", rev = "8ea7a983d8b1364e5f62d2adf0e74b3b8db1c9b3"} -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } target-lexicon = "0.4.0" log = { version = "0.4.8", default-features = false } diff --git a/wasmtime-wast/Cargo.toml b/wasmtime-wast/Cargo.toml index 4bcfd4122c66..2939c77c6c82 100644 --- a/wasmtime-wast/Cargo.toml +++ b/wasmtime-wast/Cargo.toml @@ -11,9 +11,9 @@ readme = "README.md" edition = "2018" [dependencies] -cranelift-codegen = { version = "0.40.0", features = ["enable-serde"] } -cranelift-wasm = { version = "0.40.0", features = ["enable-serde"] } -cranelift-entity = { version = "0.40.0", features = ["enable-serde"] } +cranelift-codegen = { version = "0.41.0", features = ["enable-serde"] } +cranelift-entity = { version = "0.41.0", features = ["enable-serde"] } +cranelift-wasm = { version = "0.41.0", features = ["enable-serde"] } wasmtime-jit = { path = "../wasmtime-jit" } wasmtime-runtime = { path = "../wasmtime-runtime" } wasmtime-environ = { path = "../wasmtime-environ" }