Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
upgrade to wasmtime 0.30, cranelift 0.77 (#672)
Browse files Browse the repository at this point in the history
* upgrade to wasmtime 0.30, cranelift 0.77

* bump more deps

* test fixes

* fix lucet-runtime-internals dep on wiggle
  • Loading branch information
Pat Hickey committed Sep 27, 2021
1 parent 8dcf830 commit 2e5a1ae
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 257 deletions.
351 changes: 156 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lucet-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"

[dependencies]
anyhow = "1.0"
cranelift-entity = "0.76.0"
cranelift-entity = "0.77.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
bincode = "1.1.4"
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/lucet-runtime-internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
[dependencies]
lucet-module = { path = "../../lucet-module", version = "=0.7.0-dev" }
lucet-runtime-macros = { path = "../lucet-runtime-macros", version = "=0.7.0-dev" }
wiggle = { version = "0.29.0", default-features = false }
wiggle = { version = "0.30.0", default-features = false }

anyhow = "1.0"
bitflags = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion lucet-wasi-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ task-group = "0.2"
tempfile = "3.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
wait-timeout = "0.2"
wasi-common = "0.29.0"
wasi-common = "0.30.0"
11 changes: 6 additions & 5 deletions lucet-wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ lucet-wiggle-generate = { path = "../lucet-wiggle/generate", version = "=0.7.0-d
libc = "0.2.65"
nix = "0.17"
rand = "0.6"
wasi-common = { version = "0.29.0", default-features = false, features = ["wiggle_metadata"] }
wasi-tokio = "0.29.0"
wiggle = "0.29.0"
wasi-common = { version = "0.30.0", default-features = false, features = ["wiggle_metadata"] }
wasi-tokio = "0.30.0"
wiggle = "0.30.0"
witx = "0.9.1"
tracing = "0.1.19"
tracing-subscriber = "0.2.0"
cap-std = "0.16"
cap-std = "0.19.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"]}

[dev-dependencies]
lucet-wasi-sdk = { path = "../lucet-wasi-sdk" }
lucetc = { path = "../lucetc" }
tempfile = "3.0"
cap-tempfile = "0.16"
cap-tempfile = "0.19"

[lib]
name = "lucet_wasi"
Expand Down
2 changes: 1 addition & 1 deletion lucet-wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn bindings() -> lucet_module::bindings::Bindings {

/// The witx document for the interface implemented by this crate. This is exposed as part of a
/// transition path away from always loading witx documents from the filesystem.
pub fn witx_document() -> lucet_wiggle::witx::Document {
pub fn witx_document() -> witx::Document {
wasi_common::snapshots::preview_1::metadata::document()
}

Expand Down
2 changes: 1 addition & 1 deletion lucet-wiggle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2018"
lucet-wiggle-macro = { path = "./macro", version = "0.7.0-dev" }
lucet-wiggle-generate = { path = "./generate", version = "0.7.0-dev" }
lucet-runtime = { path = "../lucet-runtime", version = "0.7.0-dev" }
wiggle = { version = "0.29.0", default-features = false }
wiggle = { version = "0.30.0", default-features = false }

[dev-dependencies]
tempfile = "3.1"
Expand Down
2 changes: 1 addition & 1 deletion lucet-wiggle/generate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Lucet team <lucet@fastly.com>"]
edition = "2018"

[dependencies]
wiggle-generate = "0.29.0"
wiggle-generate = "0.30.0"
lucet-module = { path = "../../lucet-module", version = "0.7.0-dev" }
witx = "0.9.1"
quote = "1.0"
Expand Down
14 changes: 7 additions & 7 deletions lucetc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ path = "lucetc/main.rs"
[dependencies]
anyhow = "1"
bincode = "1.1.4"
cranelift-codegen = { version = "0.76.0", features = ["x86" ] }
cranelift-entity = "0.76.0"
cranelift-native = "0.76.0"
cranelift-frontend = "0.76.0"
cranelift-module = "0.76.0"
cranelift-object = "0.76.0"
cranelift-wasm = "0.76.0"
cranelift-codegen = { version = "0.77.0", features = ["x86" ] }
cranelift-entity = "0.77.0"
cranelift-native = "0.77.0"
cranelift-frontend = "0.77.0"
cranelift-module = "0.77.0"
cranelift-object = "0.77.0"
cranelift-wasm = "0.77.0"
target-lexicon = "0.12"
lucet-module = { path = "../lucet-module", version = "=0.7.0-dev" }
lucet-wiggle-generate = { path = "../lucet-wiggle/generate", version = "=0.7.0-dev" }
Expand Down
7 changes: 6 additions & 1 deletion lucetc/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::decls::{FunctionDecl, ModuleDecls};
use crate::module::UniqueFuncIndex;
use crate::pointer::{NATIVE_POINTER, NATIVE_POINTER_SIZE};
use crate::table::TABLE_REF_SIZE;
use crate::types::value_type;
use cranelift_codegen::cursor::FuncCursor;
use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir::{self, condcodes::IntCC, InstBuilder};
Expand Down Expand Up @@ -472,7 +473,7 @@ impl<'a> FuncEnvironment for FuncInfo<'a> {
Ok(GlobalVariable::Memory {
gv: global_base,
offset,
ty: global.entity.ty,
ty: value_type(&global.entity.wasm_ty),
})
}

Expand Down Expand Up @@ -946,4 +947,8 @@ impl<'a> FuncEnvironment for FuncInfo<'a> {
) -> WasmResult<ir::Value> {
unimplemented!("translate atomic verify");
}

fn unsigned_add_overflow_condition(&self) -> IntCC {
unimplemented!("unsigned_add_overflow_condition");
}
}
12 changes: 5 additions & 7 deletions lucetc/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_wasm::{
wasmparser::{FuncValidator, FunctionBody, ValidatorResources},
DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, ModuleEnvironment,
Table, TableElementType, TableIndex, TargetEnvironment, TypeIndex, WasmError, WasmFuncType,
WasmResult, WasmType,
Table, TableIndex, TargetEnvironment, TypeIndex, WasmError, WasmFuncType, WasmResult, WasmType,
};
use lucet_module::UniqueSignatureIndex;
use std::collections::{hash_map::Entry, HashMap};
Expand Down Expand Up @@ -49,7 +48,7 @@ pub struct TableElems {
#[derive(Debug, Clone)]
pub struct DataInitializer<'a> {
pub base: Option<GlobalIndex>,
pub offset: u32,
pub offset: u64,
pub data: &'a [u8],
}

Expand Down Expand Up @@ -227,8 +226,8 @@ impl<'a> ModuleEnvironment<'a> for ModuleValidation<'a> {
_ => unimplemented!(),
})
};
sig.params.extend(wasm.params.iter().map(&cvt));
sig.returns.extend(wasm.returns.iter().map(&cvt));
sig.params.extend(wasm.params().iter().map(&cvt));
sig.returns.extend(wasm.returns().iter().map(&cvt));
self.info.declare_type_func(wasm, sig)
}
fn declare_func_import(
Expand Down Expand Up @@ -455,7 +454,6 @@ impl<'a> ModuleEnvironment<'a> for ModuleValidation<'a> {
Entry::Vacant(vac) => {
if self.info.tables.is_empty() && table_index == TableIndex::new(0) {
let table = Table {
ty: TableElementType::Func,
wasm_ty: WasmType::FuncRef,
minimum: 0,
maximum: None,
Expand All @@ -474,7 +472,7 @@ impl<'a> ModuleEnvironment<'a> for ModuleValidation<'a> {
&mut self,
memory_index: MemoryIndex,
base: Option<GlobalIndex>,
offset: u32,
offset: u64,
data: &'a [u8],
) -> WasmResult<()> {
let data_init = DataInitializer { base, offset, data };
Expand Down
24 changes: 12 additions & 12 deletions lucetc/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ impl Runtime {
returns: vec![AbiParam::new(types::I32)],
call_conv: target.default_call_conv,
},
wasm_func_type: WasmFuncType {
params: vec![].into_boxed_slice(),
returns: vec![WasmType::I32].into_boxed_slice(),
},
wasm_func_type: WasmFuncType::new(
vec![].into_boxed_slice(),
vec![WasmType::I32].into_boxed_slice(),
),
},
);
functions.insert(
Expand All @@ -49,10 +49,10 @@ impl Runtime {
returns: vec![AbiParam::new(types::I32)],
call_conv: target.default_call_conv,
},
wasm_func_type: WasmFuncType {
params: vec![WasmType::I32].into_boxed_slice(),
returns: vec![WasmType::I32].into_boxed_slice(),
},
wasm_func_type: WasmFuncType::new(
vec![WasmType::I32].into_boxed_slice(),
vec![WasmType::I32].into_boxed_slice(),
),
},
);
functions.insert(
Expand All @@ -64,10 +64,10 @@ impl Runtime {
returns: vec![],
call_conv: target.default_call_conv,
},
wasm_func_type: WasmFuncType {
params: vec![].into_boxed_slice(),
returns: vec![].into_boxed_slice(),
},
wasm_func_type: WasmFuncType::new(
vec![].into_boxed_slice(),
vec![].into_boxed_slice(),
),
},
);
Self { functions }
Expand Down
10 changes: 5 additions & 5 deletions lucetc/src/sparsedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use lucet_module::SparseData;
const PAGE_SIZE: u64 = 4096;

fn linear_memory_range<'a>(di: &DataInitializer<'a>, start: u32, end: u32) -> &'a [u8] {
let offs = di.offset;
let offs = di.offset as u32;
// The range of linear memory we're interested in is:
// valid: end is past the start
assert!(end >= start);
Expand All @@ -27,15 +27,15 @@ fn linear_memory_range<'a>(di: &DataInitializer<'a>, start: u32, end: u32) -> &'

// If the data initializer contains indexes that are out of range for a 32 bit linear
// memory, this function will return Err(TryFromIntError)
fn split<'a>(
di: &DataInitializer<'a>,
) -> Result<Vec<(u32, DataInitializer<'a>)>, std::num::TryFromIntError> {
fn split<'a>(di: &DataInitializer<'a>) -> Result<Vec<(u32, DataInitializer<'a>)>, anyhow::Error> {
use std::convert::TryInto;
// Divide a data initializer for linear memory into a set of data initializers for pages, and
// the index of the page they cover.
// The input initializer can cover many pages. Each output initializer covers exactly one.
let start = di.offset as u64;
let end = start + di.data.len() as u64;
let end = start
.checked_add(di.data.len() as u64)
.ok_or_else(|| anyhow::format_err!("overflow"))?;
let mut offs = start;
let mut out = Vec::new();

Expand Down
8 changes: 4 additions & 4 deletions lucetc/src/stack_probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ pub fn declare<'a>(
codegen_context,
STACK_PROBE_SYM.to_string(),
Linkage::Local,
WasmFuncType {
params: vec![].into_boxed_slice(),
returns: vec![WasmType::I32].into_boxed_slice(),
},
WasmFuncType::new(
vec![].into_boxed_slice(),
vec![WasmType::I32].into_boxed_slice(),
),
Signature {
params: vec![],
returns: vec![AbiParam::new(types::I32)],
Expand Down
8 changes: 4 additions & 4 deletions lucetc/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::pointer::NATIVE_POINTER_SIZE;
use byteorder::{LittleEndian, WriteBytesExt};
use cranelift_codegen::entity::EntityRef;
use cranelift_module::{DataContext, DataId, Module as ClifModule};
use cranelift_wasm::{TableElementType, TableIndex};
use cranelift_wasm::{TableIndex, WasmType};
use std::convert::TryInto;
use std::io::Cursor;

Expand All @@ -24,10 +24,10 @@ enum Elem {
}

fn table_elements(decl: &TableDecl<'_>) -> Result<Vec<Elem>, Error> {
match decl.table.ty {
TableElementType::Func => Ok(()),
match decl.table.wasm_ty {
WasmType::FuncRef => Ok(()),
_ => {
let message = format!("table with non-function elements: {:?}", decl);
let message = format!("table with non-FuncRef elements: {:?}", decl);
Err(Error::Unsupported(message))
}
}?;
Expand Down
17 changes: 15 additions & 2 deletions lucetc/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cranelift_codegen::ir;
use cranelift_wasm::{WasmFuncType, WasmType};
use lucet_module::{Signature, ValueType};
use std::fmt::{self, Display};
Expand All @@ -9,6 +10,18 @@ pub enum ValueError {
InvalidVMContext,
}

pub fn value_type(ty: &WasmType) -> ir::types::Type {
match ty {
WasmType::I32 => ir::types::I32,
WasmType::I64 => ir::types::I64,
WasmType::F32 => ir::types::F32,
WasmType::F64 => ir::types::F64,
WasmType::V128 => ir::types::I8X16,
WasmType::FuncRef | WasmType::ExternRef => ir::types::I64,
WasmType::ExnRef => unimplemented!(),
}
}

fn to_lucet_valuetype(ty: &WasmType) -> Result<ValueType, ValueError> {
match ty {
WasmType::I32 => Ok(ValueType::I32),
Expand All @@ -33,14 +46,14 @@ impl Display for SignatureError {

pub fn to_lucet_signature(func_type: &WasmFuncType) -> Result<Signature, SignatureError> {
let params = func_type
.params
.params()
.iter()
.map(|paramtype| {
to_lucet_valuetype(paramtype).map_err(|e| SignatureError::Type(*paramtype, e))
})
.collect::<Result<Vec<ValueType>, SignatureError>>()?;

let ret_ty: Option<ValueType> = match &*func_type.returns {
let ret_ty: Option<ValueType> = match &*func_type.returns() {
&[] => None,
&[ref ret_ty] => {
let value_ty =
Expand Down
8 changes: 3 additions & 5 deletions lucetc/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ impl ValidatorBuilder {
}

pub fn build(self) -> Validator {
let no_params_no_returns = WasmFuncType {
params: vec![].into_boxed_slice(),
returns: vec![].into_boxed_slice(),
};
let no_params_no_returns =
WasmFuncType::new(vec![].into_boxed_slice(), vec![].into_boxed_slice());
let exports = match self.wasi_mode {
None => vec![],
Some(WasiMode::Command) => vec![(
Expand Down Expand Up @@ -255,5 +253,5 @@ fn witx_to_functype(func: &witx::InterfaceFunc) -> WasmFuncType {
1 => vec![atom_to_type(&results[0])].into_boxed_slice(),
_ => unimplemented!("multiple result types"),
};
WasmFuncType { params, returns }
WasmFuncType::new(params, returns)
}
8 changes: 4 additions & 4 deletions lucetc/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ mod validate {
},
ValidationError::MissingRequiredExport {
field: "_start".to_owned(),
type_: cranelift_wasm::WasmFuncType {
params: vec![].into_boxed_slice(),
returns: vec![].into_boxed_slice()
}
type_: cranelift_wasm::WasmFuncType::new(
vec![].into_boxed_slice(),
vec![].into_boxed_slice()
)
}
]
),
Expand Down

0 comments on commit 2e5a1ae

Please sign in to comment.