From 41d668b4dad269c0f7c834c234c1a1ed9099061c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 20 Nov 2020 11:37:13 -0800 Subject: [PATCH 01/27] Introduce benchmarking API The new crate introduced here, `wasmtime-bench-api`, creates a shared library, e.g. `wasmtime_bench_api.so`, for executing Wasm benchmarks using Wasmtime. It allows us to measure several phases separately by exposing `engine_compile_module`, `engine_instantiate_module`, and `engine_execute_module`, which pass around an opaque pointer to the internally initialized state. This state is initialized and freed by `engine_create` and `engine_free`, respectively. The API also introduces a way of passing in functions to satisfy the `"bench" "start"` and `"bench" "end"` symbols that we expect Wasm benchmarks to import. The API is exposed in a C-compatible way so that we can dynamically load it (carefully) in our benchmark runner. --- Cargo.lock | 11 ++ Cargo.toml | 1 + crates/bench-api/Cargo.toml | 25 +++++ crates/bench-api/src/lib.rs | 198 ++++++++++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+) create mode 100644 crates/bench-api/Cargo.toml create mode 100644 crates/bench-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 13c13d89cf..80f890f6d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2449,6 +2449,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "wasmtime-bench-api" +version = "0.19.0" +dependencies = [ + "anyhow", + "wasi-common", + "wasmtime", + "wasmtime-wasi", + "wat", +] + [[package]] name = "wasmtime-c-api" version = "0.19.0" diff --git a/Cargo.toml b/Cargo.toml index 7ea112be71..890fa9e41b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ opt-level = 0 [workspace] members = [ "cranelift", + "crates/bench-api", "crates/c-api", "crates/fuzzing", "crates/misc/run-examples", diff --git a/crates/bench-api/Cargo.toml b/crates/bench-api/Cargo.toml new file mode 100644 index 0000000000..02dfd986be --- /dev/null +++ b/crates/bench-api/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "wasmtime-bench-api" +version = "0.19.0" +authors = ["The Wasmtime Project Developers"] +description = "Exposes a benchmarking API for the Wasmtime runtime" +license = "Apache-2.0 WITH LLVM-exception" +repository = "https://github.com/bytecodealliance/wasmtime" +readme = "README.md" +edition = "2018" +publish = false + +[lib] +name = "wasmtime_bench_api" +crate-type = ["rlib", "cdylib"] +# The rlib is only included here so that `cargo test` will run. + +[dependencies] +anyhow = "1.0" +wasmtime = { path = "../wasmtime", default-features = false } +wasmtime-wasi = { path = "../wasi" } +wasi-common = { path = "../wasi-common" } + + +[dev-dependencies] +wat = "1.0" diff --git a/crates/bench-api/src/lib.rs b/crates/bench-api/src/lib.rs new file mode 100644 index 0000000000..a12268e6de --- /dev/null +++ b/crates/bench-api/src/lib.rs @@ -0,0 +1,198 @@ +//! Expose a C-compatible API for controlling the Wasmtime engine during benchmarking. The API expects very sequential +//! use: +//! - `engine_create` +//! - `engine_compile_module` +//! - `engine_instantiate_module` +//! - `engine_execute_module` +//! - `engine_free` +//! +//! An example of this C-style usage, without error checking, is shown below: +//! +//! ``` +//! use wasmtime_bench_api::*; +//! let module = wat::parse_bytes(br#"(module +//! (func $bench_start (import "bench" "start")) +//! (func $bench_end (import "bench" "end")) +//! (func $start (export "_start") +//! (call $bench_start) (i32.const 2) (i32.const 2) (i32.add) (drop) (call $bench_end)) +//! )"#).unwrap(); +//! let engine = unsafe { engine_create(module.as_ptr(), module.len()) }; +//! +//! // Start compilation timer. +//! unsafe { engine_compile_module(engine) }; +//! // End compilation timer. +//! +//! // The Wasm benchmark will expect us to provide functions to start ("bench" "start") and stop ("bench" "stop") the +//! // measurement counters/timers during execution; here we provide a no-op implementation. +//! extern "C" fn noop() {} +//! +//! // Start instantiation timer. +//! unsafe { engine_instantiate_module(engine, noop, noop) }; +//! // End instantiation timer. +//! +//! // No need to start timers for the execution since, by convention, the timer functions we passed during +//! // instantiation will be called by the benchmark at the appropriate time (before and after the benchmarked section). +//! unsafe { engine_execute_module(engine) }; +//! +//! unsafe { engine_free(engine) } +//! ``` +use anyhow::{anyhow, Result}; +use core::slice; +use std::os::raw::c_int; +use wasi_common::WasiCtxBuilder; +use wasmtime::{Config, Engine, Instance, Linker, Module, Store}; +use wasmtime_wasi::Wasi; + +/// Exposes a C-compatible way of creating the engine from the bytes of a single Wasm module. This function returns a +/// pointer to an opaque structure that contains the engine's initialized state. +#[no_mangle] +pub extern "C" fn engine_create( + wasm_bytes: *const u8, + wasm_bytes_length: usize, +) -> *mut OpaqueEngineState { + let wasm_bytes = unsafe { slice::from_raw_parts(wasm_bytes, wasm_bytes_length) }; + let state = Box::new(EngineState::new(wasm_bytes)); + Box::into_raw(state) as *mut _ +} + +/// Free the engine state allocated by this library. +#[no_mangle] +pub extern "C" fn engine_free(state: *mut OpaqueEngineState) { + unsafe { + Box::from_raw(state); + } +} + +/// Compile the Wasm benchmark module. +#[no_mangle] +pub extern "C" fn engine_compile_module(state: *mut OpaqueEngineState) -> c_int { + let result = unsafe { OpaqueEngineState::convert(state) }.compile(); + to_c_error(result, "failed to compile") +} + +/// Instantiate the Wasm benchmark module. +#[no_mangle] +pub extern "C" fn engine_instantiate_module( + state: *mut OpaqueEngineState, + bench_start: extern "C" fn(), + bench_end: extern "C" fn(), +) -> c_int { + let result = unsafe { OpaqueEngineState::convert(state) }.instantiate(bench_start, bench_end); + to_c_error(result, "failed to instantiate") +} + +/// Execute the Wasm benchmark module. +#[no_mangle] +pub extern "C" fn engine_execute_module(state: *mut OpaqueEngineState) -> c_int { + let result = unsafe { OpaqueEngineState::convert(state) }.execute(); + to_c_error(result, "failed to execute") +} + +/// Helper function for converting a Rust result to a C error code (0 == success). Additionally, this will print an +/// error indicating some information regarding the failure. +fn to_c_error(result: Result, message: &str) -> c_int { + match result { + Ok(_) => 0, + Err(error) => { + println!("{}: {:?}", message, error); + 1 + } + } +} + +/// Opaque pointer type for hiding the engine state details. +#[repr(C)] +pub struct OpaqueEngineState { + _private: [u8; 0], +} +impl OpaqueEngineState { + unsafe fn convert(ptr: *mut OpaqueEngineState) -> &'static mut EngineState<'static> { + assert!(!ptr.is_null()); + &mut *(ptr as *mut EngineState) + } +} + +/// This structure contains the actual Rust implementation of the state required to manage the Wasmtime engine between +/// calls. +struct EngineState<'a> { + bytes: &'a [u8], + engine: Engine, + store: Store, + module: Option, + instance: Option, +} + +impl<'a> EngineState<'a> { + fn new(bytes: &'a [u8]) -> Self { + // TODO turn off caching? + let mut config = Config::new(); + config.wasm_simd(true); + let engine = Engine::new(&config); + let store = Store::new(&engine); + Self { + bytes, + engine, + store, + module: None, + instance: None, + } + } + + fn compile(&mut self) -> Result<()> { + self.module = Some(Module::from_binary(&self.engine, self.bytes)?); + Ok(()) + } + + fn instantiate( + &mut self, + bench_start: extern "C" fn(), + bench_end: extern "C" fn(), + ) -> Result<()> { + // TODO instantiate WASI modules? + match &self.module { + Some(module) => { + let mut linker = Linker::new(&self.store); + + // Import a very restricted WASI environment. + let mut cx = WasiCtxBuilder::new(); + cx.inherit_stdio(); + let cx = cx.build()?; + let wasi = Wasi::new(linker.store(), cx); + wasi.add_to_linker(&mut linker)?; + + // Import the specialized benchmarking functions. + linker.func("bench", "start", move || bench_start())?; + linker.func("bench", "end", move || bench_end())?; + + self.instance = Some(linker.instantiate(module)?); + } + None => panic!("compile the module before instantiating it"), + } + Ok(()) + } + + fn execute(&self) -> Result<()> { + match &self.instance { + Some(instance) => { + let start_func = instance.get_func("_start").expect("a _start function"); + let runnable_func = start_func.get0::<()>()?; + match runnable_func() { + Ok(_) => {} + Err(trap) => { + // Since _start will likely return by using the system `exit` call, we must + // check the trap code to see if it actually represents a successful exit. + let status = trap.i32_exit_status(); + if status != Some(0) { + return Err(anyhow!( + "_start exited with a non-zero code: {}", + status.unwrap() + )); + } + } + }; + } + None => panic!("instantiate the module before executing it"), + } + Ok(()) + } +} From 919600d10bb4e0d049e32ce88cd6aa3ab6628a4d Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Dec 2020 05:57:25 +0000 Subject: [PATCH 02/27] Stub out the utimesat emulation logic on Android. Android always has `utimensat` available, so it is not necessary (or possible, for that matter) to emulate it. Mark the fallback path as `unreachable!()`. --- crates/wasi-common/yanix/src/sys/linux/filetime.rs | 5 ++++- crates/wasi-common/yanix/src/sys/linux/mod.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/wasi-common/yanix/src/sys/linux/filetime.rs b/crates/wasi-common/yanix/src/sys/linux/filetime.rs index 3c4cdfa9f6..34faefc6d6 100644 --- a/crates/wasi-common/yanix/src/sys/linux/filetime.rs +++ b/crates/wasi-common/yanix/src/sys/linux/filetime.rs @@ -53,5 +53,8 @@ pub fn utimensat( return Err(err); } - super::utimesat::utimesat(dirfd, path, atime, mtime, symlink_nofollow) + #[cfg(not(target_os = "android"))] + return super::utimesat::utimesat(dirfd, path, atime, mtime, symlink_nofollow); + #[cfg(target_os = "android")] + unreachable!(); } diff --git a/crates/wasi-common/yanix/src/sys/linux/mod.rs b/crates/wasi-common/yanix/src/sys/linux/mod.rs index 26432d36dd..37d8a0a8af 100644 --- a/crates/wasi-common/yanix/src/sys/linux/mod.rs +++ b/crates/wasi-common/yanix/src/sys/linux/mod.rs @@ -2,4 +2,5 @@ pub(crate) mod dir; pub(crate) mod fadvise; pub(crate) mod file; pub(crate) mod filetime; +#[cfg(not(target_os = "android"))] pub(crate) mod utimesat; From 476ee59774d27a19ea6ac653615acc2c89aa3a38 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Dec 2020 06:08:22 +0000 Subject: [PATCH 03/27] Define local `seekdir` and `telldir` prototypes on Android. These functions are not yet defined in the `libc` crate. See https://github.com/rust-lang/libc/pull/1996. --- crates/wasi-common/yanix/src/dir.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/wasi-common/yanix/src/dir.rs b/crates/wasi-common/yanix/src/dir.rs index 50166a35b1..8e6c70a40f 100644 --- a/crates/wasi-common/yanix/src/dir.rs +++ b/crates/wasi-common/yanix/src/dir.rs @@ -36,9 +36,15 @@ impl Dir { } /// Set the position of the directory stream, see `seekdir(3)`. - #[cfg(not(target_os = "android"))] pub fn seek(&mut self, loc: SeekLoc) { - unsafe { libc::seekdir(self.0.as_ptr(), loc.0) } + // https://github.com/rust-lang/libc/pull/1996 + #[cfg(not(target_os = "android"))] + use libc::seekdir; + #[cfg(target_os = "android")] + extern "C" { + fn seekdir(dirp: *mut libc::DIR, loc: libc::c_long); + } + unsafe { seekdir(self.0.as_ptr(), loc.0) } } /// Reset directory stream, see `rewinddir(3)`. @@ -50,10 +56,16 @@ impl Dir { /// /// If this location is given to `Dir::seek`, the entries up to the previously returned /// will be omitted and the iteration will start from the currently pending directory entry. - #[cfg(not(target_os = "android"))] #[allow(dead_code)] pub fn tell(&self) -> SeekLoc { - let loc = unsafe { libc::telldir(self.0.as_ptr()) }; + #[cfg(not(target_os = "android"))] + use libc::telldir; + #[cfg(target_os = "android")] + extern "C" { + fn telldir(dirp: *mut libc::DIR) -> libc::c_long; + } + // https://github.com/rust-lang/libc/pull/1996 + let loc = unsafe { telldir(self.0.as_ptr()) }; SeekLoc(loc) } @@ -93,11 +105,9 @@ impl Entry { } } -#[cfg(not(target_os = "android"))] #[derive(Clone, Copy, Debug)] pub struct SeekLoc(pub(crate) libc::c_long); -#[cfg(not(target_os = "android"))] impl SeekLoc { pub fn to_raw(&self) -> i64 { self.0.into() From 1ec1834d6e2e0ed5e527e2a3b52a1634abeedf11 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Dec 2020 06:36:09 +0000 Subject: [PATCH 04/27] Treat Android like Linux in `wasi_common::sys::unix`. Just like it happens in `yanix::sys`. --- crates/wasi-common/src/sys/unix/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/wasi-common/src/sys/unix/mod.rs b/crates/wasi-common/src/sys/unix/mod.rs index 7135486ec2..84d8ec581e 100644 --- a/crates/wasi-common/src/sys/unix/mod.rs +++ b/crates/wasi-common/src/sys/unix/mod.rs @@ -9,7 +9,8 @@ pub(crate) mod poll; pub(crate) mod stdio; cfg_if::cfg_if! { - if #[cfg(target_os = "linux")] { + if #[cfg(any(target_os = "linux", + target_os = "android"))] { mod linux; use linux as sys_impl; } else if #[cfg(target_os = "emscripten")] { From fc4eeae8961c56d2307e4f9ed895f06d3ff43887 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Dec 2020 06:38:55 +0000 Subject: [PATCH 05/27] Alias `yanix::file::OFlags::RSYNC` to `SYNC` on Android. Android defines O_RSYNC to be the same as O_SYNC: https://github.com/aosp-mirror/platform_bionic/blob/35bb46188ce8dbbb8bde0702e6cc6bf1d0795980/libc/include/fcntl.h#L57 --- crates/wasi-common/yanix/src/file.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/wasi-common/yanix/src/file.rs b/crates/wasi-common/yanix/src/file.rs index 1764d29120..62af1c9d77 100644 --- a/crates/wasi-common/yanix/src/file.rs +++ b/crates/wasi-common/yanix/src/file.rs @@ -90,11 +90,26 @@ bitflags! { const WRONLY = libc::O_WRONLY; const RDWR = libc::O_RDWR; #[cfg(any(target_os = "linux", + target_os = "android", target_os = "netbsd", target_os = "openbsd", target_os = "wasi", target_os = "emscripten"))] - const RSYNC = libc::O_RSYNC; + const RSYNC = { + // Have to use cfg_if: https://github.com/bitflags/bitflags/issues/137 + cfg_if! { + if #[cfg(any(target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "wasi", + target_os = "emscripten"))] { + libc::O_RSYNC + } else if #[cfg(target_os = "android")] { + // Android defines O_RSYNC as O_SYNC + libc::O_SYNC + } + } + }; const SYNC = libc::O_SYNC; const TRUNC = libc::O_TRUNC; #[cfg(any(target_os = "linux", From fe10cc9d521b13a773755be8dc64fcb05a31f181 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 15 Dec 2020 15:44:43 +0100 Subject: [PATCH 06/27] Fix jitdump header magic field on big-endian platforms (#2511) The jitdump header contains a "magic" field that is defined to hold the value 0x4A695444 as u32 in native endianness. (This allows consumers of the file to detect the endianness of the platform where the file was written, and apply it when reading other fields.) However, current code always writes 0x4A695444 in little-endian byte order, even on big-endian system. This makes consumers fail when attempting to read files written on big-endian platforms. Fixed by always writing the magic in native endianness. --- crates/profiling/src/jitdump_linux.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/profiling/src/jitdump_linux.rs b/crates/profiling/src/jitdump_linux.rs index e16978843f..ef6684c95f 100644 --- a/crates/profiling/src/jitdump_linux.rs +++ b/crates/profiling/src/jitdump_linux.rs @@ -249,11 +249,7 @@ impl State { let header = FileHeader { timestamp: self.get_time_stamp(), e_machine: self.get_e_machine(), - magic: if cfg!(target_endian = "little") { - 0x4A695444 - } else { - 0x4454694a - }, + magic: 0x4A695444, version: 1, size: mem::size_of::() as u32, pad1: 0, From cc81570a05a766a0c2fff6557ef36220268aab4e Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 15 Dec 2020 11:19:30 -0800 Subject: [PATCH 07/27] bench-api: Clean up the benchmarking API Mostly just tweaks to docs/naming/readability/tidying up. The biggest thing is that the wasm bytes are passed in during compilation now, rather than on initialization, which lets us remove the lifetime from our state struct and makes wrangling unsafe conversions that much easier. --- crates/bench-api/src/lib.rs | 290 +++++++++++++++++++++--------------- 1 file changed, 170 insertions(+), 120 deletions(-) diff --git a/crates/bench-api/src/lib.rs b/crates/bench-api/src/lib.rs index a12268e6de..a2958f09a8 100644 --- a/crates/bench-api/src/lib.rs +++ b/crates/bench-api/src/lib.rs @@ -1,145 +1,189 @@ -//! Expose a C-compatible API for controlling the Wasmtime engine during benchmarking. The API expects very sequential -//! use: -//! - `engine_create` -//! - `engine_compile_module` -//! - `engine_instantiate_module` -//! - `engine_execute_module` -//! - `engine_free` +//! A C API for benchmarking Wasmtime's WebAssembly compilation, instantiation, +//! and execution. //! -//! An example of this C-style usage, without error checking, is shown below: +//! The API expects sequential calls to: +//! +//! - `wasm_bench_create` +//! - `wasm_bench_compile` +//! - `wasm_bench_instantiate` +//! - `wasm_bench_execute` +//! - `wasm_bench_free` +//! +//! You may repeat this sequence of calls multiple times to take multiple +//! measurements of compilation, instantiation, and execution time within a +//! single process. +//! +//! All API calls must happen on the same thread. +//! +//! Functions which return pointers use null as an error value. Function which +//! return `int` use `0` as OK and non-zero as an error value. +//! +//! # Example //! //! ``` //! use wasmtime_bench_api::*; -//! let module = wat::parse_bytes(br#"(module -//! (func $bench_start (import "bench" "start")) -//! (func $bench_end (import "bench" "end")) -//! (func $start (export "_start") -//! (call $bench_start) (i32.const 2) (i32.const 2) (i32.add) (drop) (call $bench_end)) -//! )"#).unwrap(); -//! let engine = unsafe { engine_create(module.as_ptr(), module.len()) }; //! -//! // Start compilation timer. -//! unsafe { engine_compile_module(engine) }; -//! // End compilation timer. +//! let engine = unsafe { wasm_bench_create() }; +//! assert!(!engine.is_null()); //! -//! // The Wasm benchmark will expect us to provide functions to start ("bench" "start") and stop ("bench" "stop") the -//! // measurement counters/timers during execution; here we provide a no-op implementation. -//! extern "C" fn noop() {} +//! let wasm = wat::parse_bytes(br#" +//! (module +//! (func $bench_start (import "bench" "start")) +//! (func $bench_end (import "bench" "end")) +//! (func $start (export "_start") +//! call $bench_start +//! i32.const 1 +//! i32.const 2 +//! i32.add +//! drop +//! call $bench_end +//! ) +//! ) +//! "#).unwrap(); //! -//! // Start instantiation timer. -//! unsafe { engine_instantiate_module(engine, noop, noop) }; -//! // End instantiation timer. +//! // Start your compilation timer here. +//! let code = unsafe { wasm_bench_compile(engine, wasm.as_ptr(), wasm.len()) }; +//! // End your compilation timer here. +//! assert_eq!(code, OK); //! -//! // No need to start timers for the execution since, by convention, the timer functions we passed during -//! // instantiation will be called by the benchmark at the appropriate time (before and after the benchmarked section). -//! unsafe { engine_execute_module(engine) }; +//! // The Wasm benchmark will expect us to provide functions to start ("bench" +//! // "start") and stop ("bench" "stop") the measurement counters/timers during +//! // execution. +//! extern "C" fn bench_start() { +//! // Start your execution timer here. +//! } +//! extern "C" fn bench_stop() { +//! // End your execution timer here. +//! } //! -//! unsafe { engine_free(engine) } +//! // Start your instantiation timer here. +//! let code = unsafe { wasm_bench_instantiate(engine, bench_start, bench_stop) }; +//! // End your instantiation timer here. +//! assert_eq!(code, OK); +//! +//! // No need to start timers for the execution since, by convention, the timer +//! // functions we passed during instantiation will be called by the benchmark +//! // at the appropriate time (before and after the benchmarked section). +//! let code = unsafe { wasm_bench_execute(engine) }; +//! assert_eq!(code, OK); +//! +//! unsafe { +//! wasm_bench_free(engine); +//! } //! ``` -use anyhow::{anyhow, Result}; -use core::slice; -use std::os::raw::c_int; + +use anyhow::{anyhow, Context, Result}; +use std::os::raw::{c_int, c_void}; +use std::slice; use wasi_common::WasiCtxBuilder; use wasmtime::{Config, Engine, Instance, Linker, Module, Store}; use wasmtime_wasi::Wasi; -/// Exposes a C-compatible way of creating the engine from the bytes of a single Wasm module. This function returns a -/// pointer to an opaque structure that contains the engine's initialized state. +pub type ExitCode = c_int; +pub const OK: ExitCode = 0; +pub const ERR: ExitCode = -1; + +/// Exposes a C-compatible way of creating the engine from the bytes of a single +/// Wasm module. +/// +/// This function returns a pointer to a structure that contains the engine's +/// initialized state. #[no_mangle] -pub extern "C" fn engine_create( - wasm_bytes: *const u8, - wasm_bytes_length: usize, -) -> *mut OpaqueEngineState { - let wasm_bytes = unsafe { slice::from_raw_parts(wasm_bytes, wasm_bytes_length) }; - let state = Box::new(EngineState::new(wasm_bytes)); - Box::into_raw(state) as *mut _ +pub extern "C" fn wasm_bench_create() -> *mut c_void { + let state = Box::new(BenchState::new()); + Box::into_raw(state) as _ } /// Free the engine state allocated by this library. #[no_mangle] -pub extern "C" fn engine_free(state: *mut OpaqueEngineState) { +pub extern "C" fn wasm_bench_free(state: *mut c_void) { + assert!(!state.is_null()); unsafe { - Box::from_raw(state); + Box::from_raw(state as *mut BenchState); } } /// Compile the Wasm benchmark module. #[no_mangle] -pub extern "C" fn engine_compile_module(state: *mut OpaqueEngineState) -> c_int { - let result = unsafe { OpaqueEngineState::convert(state) }.compile(); - to_c_error(result, "failed to compile") +pub extern "C" fn wasm_bench_compile( + state: *mut c_void, + wasm_bytes: *const u8, + wasm_bytes_length: usize, +) -> ExitCode { + let state = unsafe { (state as *mut BenchState).as_mut().unwrap() }; + let wasm_bytes = unsafe { slice::from_raw_parts(wasm_bytes, wasm_bytes_length) }; + let result = state.compile(wasm_bytes).context("failed to compile"); + to_exit_code(result) } /// Instantiate the Wasm benchmark module. #[no_mangle] -pub extern "C" fn engine_instantiate_module( - state: *mut OpaqueEngineState, +pub extern "C" fn wasm_bench_instantiate( + state: *mut c_void, bench_start: extern "C" fn(), bench_end: extern "C" fn(), -) -> c_int { - let result = unsafe { OpaqueEngineState::convert(state) }.instantiate(bench_start, bench_end); - to_c_error(result, "failed to instantiate") +) -> ExitCode { + let state = unsafe { (state as *mut BenchState).as_mut().unwrap() }; + let result = state + .instantiate(bench_start, bench_end) + .context("failed to instantiate"); + to_exit_code(result) } /// Execute the Wasm benchmark module. #[no_mangle] -pub extern "C" fn engine_execute_module(state: *mut OpaqueEngineState) -> c_int { - let result = unsafe { OpaqueEngineState::convert(state) }.execute(); - to_c_error(result, "failed to execute") +pub extern "C" fn wasm_bench_execute(state: *mut c_void) -> ExitCode { + let state = unsafe { (state as *mut BenchState).as_mut().unwrap() }; + let result = state.execute().context("failed to execute"); + to_exit_code(result) } -/// Helper function for converting a Rust result to a C error code (0 == success). Additionally, this will print an -/// error indicating some information regarding the failure. -fn to_c_error(result: Result, message: &str) -> c_int { - match result { - Ok(_) => 0, +/// Helper function for converting a Rust result to a C error code. +/// +/// This will print an error indicating some information regarding the failure. +fn to_exit_code(result: impl Into>) -> ExitCode { + match result.into() { + Ok(_) => OK, Err(error) => { - println!("{}: {:?}", message, error); - 1 + eprintln!("{:?}", error); + ERR } } } -/// Opaque pointer type for hiding the engine state details. -#[repr(C)] -pub struct OpaqueEngineState { - _private: [u8; 0], -} -impl OpaqueEngineState { - unsafe fn convert(ptr: *mut OpaqueEngineState) -> &'static mut EngineState<'static> { - assert!(!ptr.is_null()); - &mut *(ptr as *mut EngineState) - } -} - -/// This structure contains the actual Rust implementation of the state required to manage the Wasmtime engine between -/// calls. -struct EngineState<'a> { - bytes: &'a [u8], +/// This structure contains the actual Rust implementation of the state required +/// to manage the Wasmtime engine between calls. +struct BenchState { engine: Engine, store: Store, module: Option, instance: Option, + did_execute: bool, } -impl<'a> EngineState<'a> { - fn new(bytes: &'a [u8]) -> Self { - // TODO turn off caching? +impl BenchState { + fn new() -> Self { let mut config = Config::new(); config.wasm_simd(true); + // NB: do not configure a code cache. + let engine = Engine::new(&config); let store = Store::new(&engine); Self { - bytes, engine, store, module: None, instance: None, + did_execute: false, } } - fn compile(&mut self) -> Result<()> { - self.module = Some(Module::from_binary(&self.engine, self.bytes)?); + fn compile(&mut self, bytes: &[u8]) -> Result<()> { + assert!( + self.module.is_none(), + "create a new engine to repeat compilation" + ); + self.module = Some(Module::from_binary(&self.engine, bytes)?); Ok(()) } @@ -148,51 +192,57 @@ impl<'a> EngineState<'a> { bench_start: extern "C" fn(), bench_end: extern "C" fn(), ) -> Result<()> { - // TODO instantiate WASI modules? - match &self.module { - Some(module) => { - let mut linker = Linker::new(&self.store); + assert!( + self.instance.is_none(), + "create a new engine to repeat instantiation" + ); + let module = self + .module + .as_mut() + .expect("compile the module before instantiating it"); - // Import a very restricted WASI environment. - let mut cx = WasiCtxBuilder::new(); - cx.inherit_stdio(); - let cx = cx.build()?; - let wasi = Wasi::new(linker.store(), cx); - wasi.add_to_linker(&mut linker)?; + let mut linker = Linker::new(&self.store); - // Import the specialized benchmarking functions. - linker.func("bench", "start", move || bench_start())?; - linker.func("bench", "end", move || bench_end())?; + // Import a very restricted WASI environment. + let mut cx = WasiCtxBuilder::new(); + cx.inherit_stdio(); + let cx = cx.build()?; + let wasi = Wasi::new(linker.store(), cx); + wasi.add_to_linker(&mut linker)?; - self.instance = Some(linker.instantiate(module)?); - } - None => panic!("compile the module before instantiating it"), - } + // Import the specialized benchmarking functions. + linker.func("bench", "start", move || bench_start())?; + linker.func("bench", "end", move || bench_end())?; + + self.instance = Some(linker.instantiate(&module)?); Ok(()) } - fn execute(&self) -> Result<()> { - match &self.instance { - Some(instance) => { - let start_func = instance.get_func("_start").expect("a _start function"); - let runnable_func = start_func.get0::<()>()?; - match runnable_func() { - Ok(_) => {} - Err(trap) => { - // Since _start will likely return by using the system `exit` call, we must - // check the trap code to see if it actually represents a successful exit. - let status = trap.i32_exit_status(); - if status != Some(0) { - return Err(anyhow!( - "_start exited with a non-zero code: {}", - status.unwrap() - )); - } - } - }; + fn execute(&mut self) -> Result<()> { + assert!(!self.did_execute, "create a new engine to repeat execution"); + self.did_execute = true; + + let instance = self + .instance + .as_ref() + .expect("instantiate the module before executing it"); + + let start_func = instance.get_func("_start").expect("a _start function"); + let runnable_func = start_func.get0::<()>()?; + match runnable_func() { + Ok(_) => Ok(()), + Err(trap) => { + // Since _start will likely return by using the system `exit` call, we must + // check the trap code to see if it actually represents a successful exit. + match trap.i32_exit_status() { + Some(0) => Ok(()), + Some(n) => Err(anyhow!("_start exited with a non-zero code: {}", n)), + None => Err(anyhow!( + "executing the benchmark resulted in a trap: {}", + trap + )), + } } - None => panic!("instantiate the module before executing it"), } - Ok(()) } } From 22ad43b43068f9944a042b2cfd6505f23d1b15b0 Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Wed, 16 Dec 2020 14:30:08 +0100 Subject: [PATCH 08/27] Add filestat_get for stdout, stdin and stderr This makes fstat work for stdout, stdin and stderr as expected. This seemed like the only reasonable functions to implement from the filestat_* set, for stdout, stdin and stderr. Fixes #2515 --- crates/wasi-common/src/sys/stdio.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/wasi-common/src/sys/stdio.rs b/crates/wasi-common/src/sys/stdio.rs index 97005767d4..9ac6d6c9ca 100644 --- a/crates/wasi-common/src/sys/stdio.rs +++ b/crates/wasi-common/src/sys/stdio.rs @@ -17,7 +17,7 @@ // TODO it might worth re-investigating the suitability of this type on Windows. use super::{fd, AsFile}; -use crate::handle::{Fdflags, Filetype, Handle, HandleRights, Rights, RightsExt, Size}; +use crate::handle::{Fdflags, Filestat, Filetype, Handle, HandleRights, Rights, RightsExt, Size}; use crate::sandboxed_tty_writer::SandboxedTTYWriter; use crate::{Error, Result}; use std::any::Any; @@ -65,6 +65,9 @@ impl Handle for Stdin { } Ok(()) } + fn filestat_get(&self) -> Result { + fd::filestat_get(&*self.as_file()?) + } fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result { let nread = io::stdin().read_vectored(iovs)?; Ok(nread) @@ -111,6 +114,9 @@ impl Handle for Stdout { } Ok(()) } + fn filestat_get(&self) -> Result { + fd::filestat_get(&*self.as_file()?) + } fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result { // lock for the duration of the scope let stdout = io::stdout(); @@ -165,6 +171,9 @@ impl Handle for Stderr { } Ok(()) } + fn filestat_get(&self) -> Result { + fd::filestat_get(&*self.as_file()?) + } fn write_vectored(&self, iovs: &[io::IoSlice]) -> Result { // Always sanitize stderr, even if it's not directly connected to a tty, // because stderr is meant for diagnostics rather than binary output, From e91987c43ccd080596a932a1147b702854f5655b Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 16 Dec 2020 07:56:04 -0800 Subject: [PATCH 09/27] Allow both x86 backends to be included, selected with a "variant" flag. (#2514) This PR adds a new `isa::lookup_variant()` that takes a `BackendVariant` (`Legacy`, `MachInst` or `Any`), and exposes both x86 backends as separate variants if both are compiled into the build. This will allow some new use-cases that require both backends in the same process: for example, differential fuzzing between old and new backends, or perhaps allowing for dynamic feature-flag selection between the backends. --- cranelift/codegen/src/isa/mod.rs | 73 ++++++++++++++----- cranelift/codegen/src/isa/x86/unwind.rs | 10 +-- .../codegen/src/isa/x86/unwind/systemv.rs | 6 +- .../codegen/src/isa/x86/unwind/winx64.rs | 10 +-- 4 files changed, 67 insertions(+), 32 deletions(-) diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index 1ce10a155e..900dfd9ddd 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -75,10 +75,13 @@ use thiserror::Error; #[cfg(feature = "riscv")] mod riscv; -// Exclude the old x86 backend when the new one is enabled; it is unreachable -// anyway (requesting the x86-64 ISA will return the new backend), and a number -// of old-backend-specific tests fail. -#[cfg(all(feature = "x86", not(feature = "x64")))] +// N.B.: the old x86-64 backend (`x86`) and the new one (`x64`) can both be +// included; if the new backend is included, then it is the default backend +// returned for an x86-64 triple, but a specific option can request the old +// backend. It is important to have the ability to instantiate *both* backends +// in the same build so that we can do things like differential fuzzing between +// backends, or perhaps offer a runtime configuration flag in the future. +#[cfg(feature = "x86")] mod x86; #[cfg(feature = "x64")] @@ -117,24 +120,56 @@ macro_rules! isa_builder { }}; } +/// The "variant" for a given target. On one platform (x86-64), we have two +/// backends, the "old" and "new" one; the new one is the default if included +/// in the build configuration and not otherwise specified. +#[derive(Clone, Copy)] +pub enum BackendVariant { + /// Any backend available. + Any, + /// A "legacy" backend: one that operates using legalizations and encodings. + Legacy, + /// A backend built on `MachInst`s and the `VCode` framework. + MachInst, +} + +impl Default for BackendVariant { + fn default() -> Self { + BackendVariant::Any + } +} + +/// Look for an ISA for the given `triple`, selecting the backend variant given +/// by `variant` if available. +pub fn lookup_variant(triple: Triple, variant: BackendVariant) -> Result { + match (triple.architecture, variant) { + (Architecture::Riscv32 { .. }, _) | (Architecture::Riscv64 { .. }, _) => { + isa_builder!(riscv, (feature = "riscv"), triple) + } + (Architecture::X86_64, BackendVariant::Legacy) => { + isa_builder!(x86, (feature = "x86"), triple) + } + (Architecture::X86_64, BackendVariant::MachInst) => { + isa_builder!(x64, (feature = "x64"), triple) + } + #[cfg(feature = "x64")] + (Architecture::X86_64, BackendVariant::Any) => { + isa_builder!(x64, (feature = "x64"), triple) + } + #[cfg(not(feature = "x64"))] + (Architecture::X86_64, BackendVariant::Any) => { + isa_builder!(x86, (feature = "x86"), triple) + } + (Architecture::Arm { .. }, _) => isa_builder!(arm32, (feature = "arm32"), triple), + (Architecture::Aarch64 { .. }, _) => isa_builder!(aarch64, (feature = "arm64"), triple), + _ => Err(LookupError::Unsupported), + } +} + /// Look for an ISA for the given `triple`. /// Return a builder that can create a corresponding `TargetIsa`. pub fn lookup(triple: Triple) -> Result { - match triple.architecture { - Architecture::Riscv32 { .. } | Architecture::Riscv64 { .. } => { - isa_builder!(riscv, (feature = "riscv"), triple) - } - Architecture::X86_32 { .. } | Architecture::X86_64 => { - if cfg!(feature = "x64") { - isa_builder!(x64, (feature = "x64"), triple) - } else { - isa_builder!(x86, (all(feature = "x86", not(feature = "x64"))), triple) - } - } - Architecture::Arm { .. } => isa_builder!(arm32, (feature = "arm32"), triple), - Architecture::Aarch64 { .. } => isa_builder!(aarch64, (feature = "arm64"), triple), - _ => Err(LookupError::Unsupported), - } + lookup_variant(triple, BackendVariant::Any) } /// Look for a supported ISA with the given `name`. diff --git a/cranelift/codegen/src/isa/x86/unwind.rs b/cranelift/codegen/src/isa/x86/unwind.rs index 717964a287..2eed8b74e4 100644 --- a/cranelift/codegen/src/isa/x86/unwind.rs +++ b/cranelift/codegen/src/isa/x86/unwind.rs @@ -250,7 +250,7 @@ mod tests { use crate::ir::{ types, AbiParam, ExternalName, InstBuilder, Signature, StackSlotData, StackSlotKind, }; - use crate::isa::{lookup, CallConv}; + use crate::isa::{lookup_variant, BackendVariant, CallConv}; use crate::settings::{builder, Flags}; use crate::Context; use std::str::FromStr; @@ -258,7 +258,7 @@ mod tests { #[test] fn test_small_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -314,7 +314,7 @@ mod tests { #[test] fn test_medium_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -370,7 +370,7 @@ mod tests { #[test] fn test_large_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -442,7 +442,7 @@ mod tests { #[test] fn test_multi_return_func() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); diff --git a/cranelift/codegen/src/isa/x86/unwind/systemv.rs b/cranelift/codegen/src/isa/x86/unwind/systemv.rs index 8f112d943a..09778627bb 100644 --- a/cranelift/codegen/src/isa/x86/unwind/systemv.rs +++ b/cranelift/codegen/src/isa/x86/unwind/systemv.rs @@ -134,7 +134,7 @@ mod tests { use crate::ir::{ types, AbiParam, ExternalName, InstBuilder, Signature, StackSlotData, StackSlotKind, }; - use crate::isa::{lookup, CallConv}; + use crate::isa::{lookup_variant, BackendVariant, CallConv}; use crate::settings::{builder, Flags}; use crate::Context; use gimli::write::Address; @@ -143,7 +143,7 @@ mod tests { #[test] fn test_simple_func() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -185,7 +185,7 @@ mod tests { #[test] fn test_multi_return_func() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); diff --git a/cranelift/codegen/src/isa/x86/unwind/winx64.rs b/cranelift/codegen/src/isa/x86/unwind/winx64.rs index e49b2c1ef1..1fe93f9708 100644 --- a/cranelift/codegen/src/isa/x86/unwind/winx64.rs +++ b/cranelift/codegen/src/isa/x86/unwind/winx64.rs @@ -46,7 +46,7 @@ mod tests { use crate::ir::{ExternalName, InstBuilder, Signature, StackSlotData, StackSlotKind}; use crate::isa::unwind::winx64::UnwindCode; use crate::isa::x86::registers::RU; - use crate::isa::{lookup, CallConv}; + use crate::isa::{lookup_variant, BackendVariant, CallConv}; use crate::settings::{builder, Flags}; use crate::Context; use std::str::FromStr; @@ -54,7 +54,7 @@ mod tests { #[test] fn test_wrong_calling_convention() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -70,7 +70,7 @@ mod tests { #[test] fn test_small_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -127,7 +127,7 @@ mod tests { #[test] fn test_medium_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); @@ -188,7 +188,7 @@ mod tests { #[test] fn test_large_alloc() { - let isa = lookup(triple!("x86_64")) + let isa = lookup_variant(triple!("x86_64"), BackendVariant::Legacy) .expect("expect x86 ISA") .finish(Flags::new(builder())); From 51973aefbb4cb9fd70b8038886919f4771cfa60e Mon Sep 17 00:00:00 2001 From: Johnnie Birch <45402135+jlb6740@users.noreply.github.com> Date: Thu, 3 Dec 2020 08:32:48 -0800 Subject: [PATCH 10/27] Implements x64 SIMD loads for the new backend. --- cranelift/codegen/src/isa/x64/inst/emit.rs | 12 ++++ cranelift/codegen/src/isa/x64/lower.rs | 77 +++++++++++++++++++--- 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/cranelift/codegen/src/isa/x64/inst/emit.rs b/cranelift/codegen/src/isa/x64/inst/emit.rs index 401b8aad08..bf15513665 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit.rs @@ -1764,6 +1764,18 @@ pub(crate) fn emit( SseOpcode::Pabsb => (LegacyPrefixes::_66, 0x0F381C, 3), SseOpcode::Pabsw => (LegacyPrefixes::_66, 0x0F381D, 3), SseOpcode::Pabsd => (LegacyPrefixes::_66, 0x0F381E, 3), + SseOpcode::Pmovsxbd => (LegacyPrefixes::_66, 0x0F3821, 3), + SseOpcode::Pmovsxbw => (LegacyPrefixes::_66, 0x0F3820, 3), + SseOpcode::Pmovsxbq => (LegacyPrefixes::_66, 0x0F3822, 3), + SseOpcode::Pmovsxwd => (LegacyPrefixes::_66, 0x0F3823, 3), + SseOpcode::Pmovsxwq => (LegacyPrefixes::_66, 0x0F3824, 3), + SseOpcode::Pmovsxdq => (LegacyPrefixes::_66, 0x0F3825, 3), + SseOpcode::Pmovzxbd => (LegacyPrefixes::_66, 0x0F3831, 3), + SseOpcode::Pmovzxbw => (LegacyPrefixes::_66, 0x0F3830, 3), + SseOpcode::Pmovzxbq => (LegacyPrefixes::_66, 0x0F3832, 3), + SseOpcode::Pmovzxwd => (LegacyPrefixes::_66, 0x0F3833, 3), + SseOpcode::Pmovzxwq => (LegacyPrefixes::_66, 0x0F3834, 3), + SseOpcode::Pmovzxdq => (LegacyPrefixes::_66, 0x0F3835, 3), SseOpcode::Sqrtps => (LegacyPrefixes::None, 0x0F51, 2), SseOpcode::Sqrtpd => (LegacyPrefixes::_66, 0x0F51, 2), SseOpcode::Sqrtss => (LegacyPrefixes::_F3, 0x0F51, 2), diff --git a/cranelift/codegen/src/isa/x64/lower.rs b/cranelift/codegen/src/isa/x64/lower.rs index a01e35bc0d..21ed356cc1 100644 --- a/cranelift/codegen/src/isa/x64/lower.rs +++ b/cranelift/codegen/src/isa/x64/lower.rs @@ -3264,7 +3264,13 @@ fn lower_insn_to_regs>( | Opcode::Uload16Complex | Opcode::Sload16Complex | Opcode::Uload32Complex - | Opcode::Sload32Complex => { + | Opcode::Sload32Complex + | Opcode::Sload8x8 + | Opcode::Uload8x8 + | Opcode::Sload16x4 + | Opcode::Uload16x4 + | Opcode::Sload32x2 + | Opcode::Uload32x2 => { let offset = ctx.data(insn).load_store_offset().unwrap(); let elem_ty = match op { @@ -3279,6 +3285,18 @@ fn lower_insn_to_regs>( | Opcode::Uload32 | Opcode::Sload32Complex | Opcode::Uload32Complex => types::I32, + Opcode::Sload8x8 + | Opcode::Uload8x8 + | Opcode::Sload8x8Complex + | Opcode::Uload8x8Complex => types::I8X8, + Opcode::Sload16x4 + | Opcode::Uload16x4 + | Opcode::Sload16x4Complex + | Opcode::Uload16x4Complex => types::I16X4, + Opcode::Sload32x2 + | Opcode::Uload32x2 + | Opcode::Sload32x2Complex + | Opcode::Uload32x2Complex => types::I32X2, Opcode::Load | Opcode::LoadComplex => ctx.output_ty(insn, 0), _ => unimplemented!(), }; @@ -3291,7 +3309,13 @@ fn lower_insn_to_regs>( | Opcode::Sload16 | Opcode::Sload16Complex | Opcode::Sload32 - | Opcode::Sload32Complex => true, + | Opcode::Sload32Complex + | Opcode::Sload8x8 + | Opcode::Sload8x8Complex + | Opcode::Sload16x4 + | Opcode::Sload16x4Complex + | Opcode::Sload32x2 + | Opcode::Sload32x2Complex => true, _ => false, }; @@ -3302,7 +3326,13 @@ fn lower_insn_to_regs>( | Opcode::Uload16 | Opcode::Sload16 | Opcode::Uload32 - | Opcode::Sload32 => { + | Opcode::Sload32 + | Opcode::Sload8x8 + | Opcode::Uload8x8 + | Opcode::Sload16x4 + | Opcode::Uload16x4 + | Opcode::Sload32x2 + | Opcode::Uload32x2 => { assert_eq!(inputs.len(), 1, "only one input for load operands"); lower_to_amode(ctx, inputs[0], offset) } @@ -3313,7 +3343,13 @@ fn lower_insn_to_regs>( | Opcode::Uload16Complex | Opcode::Sload16Complex | Opcode::Uload32Complex - | Opcode::Sload32Complex => { + | Opcode::Sload32Complex + | Opcode::Sload8x8Complex + | Opcode::Uload8x8Complex + | Opcode::Sload16x4Complex + | Opcode::Uload16x4Complex + | Opcode::Sload32x2Complex + | Opcode::Uload32x2Complex => { assert_eq!( inputs.len(), 2, @@ -3325,12 +3361,12 @@ fn lower_insn_to_regs>( let flags = ctx.memflags(insn).expect("load should have memflags"); Amode::imm_reg_reg_shift(offset as u32, base, index, shift).with_flags(flags) } - _ => unreachable!(), }; let dst = get_output_reg(ctx, outputs[0]); let is_xmm = elem_ty.is_float() || elem_ty.is_vector(); + match (sign_extend, is_xmm) { (true, false) => { // The load is sign-extended only when the output size is lower than 64 bits, @@ -3350,15 +3386,40 @@ fn lower_insn_to_regs>( ctx.emit(match elem_ty { types::F32 => Inst::xmm_mov(SseOpcode::Movss, RegMem::mem(amode), dst), types::F64 => Inst::xmm_mov(SseOpcode::Movsd, RegMem::mem(amode), dst), + types::I8X8 => { + if sign_extend == true { + Inst::xmm_mov(SseOpcode::Pmovsxbw, RegMem::mem(amode), dst) + } else { + Inst::xmm_mov(SseOpcode::Pmovzxbw, RegMem::mem(amode), dst) + } + } + types::I16X4 => { + if sign_extend == true { + Inst::xmm_mov(SseOpcode::Pmovsxwd, RegMem::mem(amode), dst) + } else { + Inst::xmm_mov(SseOpcode::Pmovzxwd, RegMem::mem(amode), dst) + } + } + types::I32X2 => { + if sign_extend == true { + Inst::xmm_mov(SseOpcode::Pmovsxdq, RegMem::mem(amode), dst) + } else { + Inst::xmm_mov(SseOpcode::Pmovzxdq, RegMem::mem(amode), dst) + } + } _ if elem_ty.is_vector() && elem_ty.bits() == 128 => { Inst::xmm_mov(SseOpcode::Movups, RegMem::mem(amode), dst) - } // TODO Specialize for different types: MOVUPD, MOVDQU - _ => unreachable!("unexpected type for load: {:?}", elem_ty), + } + // TODO Specialize for different types: MOVUPD, MOVDQU + _ => unreachable!( + "unexpected type for load: {:?} - {:?}", + elem_ty, + elem_ty.bits() + ), }); } } } - Opcode::Store | Opcode::Istore8 | Opcode::Istore16 From f705a72aebd5c9100e3515c789ff87011923e7a1 Mon Sep 17 00:00:00 2001 From: Johnnie Birch <45402135+jlb6740@users.noreply.github.com> Date: Fri, 4 Dec 2020 13:28:25 -0800 Subject: [PATCH 11/27] Refactor packed moves to use xmm_mov instead of xmm_rm_r Refactors previous packed move implementation to use xmm_mov instead of xmm_rm_r which looks to simplify register accounting during lowering. --- cranelift/codegen/src/isa/x64/inst/emit.rs | 12 -- .../codegen/src/isa/x64/inst/emit_tests.rs | 152 +++++++++--------- cranelift/codegen/src/isa/x64/lower.rs | 20 +-- 3 files changed, 84 insertions(+), 100 deletions(-) diff --git a/cranelift/codegen/src/isa/x64/inst/emit.rs b/cranelift/codegen/src/isa/x64/inst/emit.rs index bf15513665..b655178bdf 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit.rs @@ -1873,18 +1873,6 @@ pub(crate) fn emit( SseOpcode::Pcmpgtw => (LegacyPrefixes::_66, 0x0F65, 2), SseOpcode::Pcmpgtd => (LegacyPrefixes::_66, 0x0F66, 2), SseOpcode::Pcmpgtq => (LegacyPrefixes::_66, 0x0F3837, 3), - SseOpcode::Pmovsxbd => (LegacyPrefixes::_66, 0x0F3821, 3), - SseOpcode::Pmovsxbw => (LegacyPrefixes::_66, 0x0F3820, 3), - SseOpcode::Pmovsxbq => (LegacyPrefixes::_66, 0x0F3822, 3), - SseOpcode::Pmovsxwd => (LegacyPrefixes::_66, 0x0F3823, 3), - SseOpcode::Pmovsxwq => (LegacyPrefixes::_66, 0x0F3824, 3), - SseOpcode::Pmovsxdq => (LegacyPrefixes::_66, 0x0F3825, 3), - SseOpcode::Pmovzxbd => (LegacyPrefixes::_66, 0x0F3831, 3), - SseOpcode::Pmovzxbw => (LegacyPrefixes::_66, 0x0F3830, 3), - SseOpcode::Pmovzxbq => (LegacyPrefixes::_66, 0x0F3832, 3), - SseOpcode::Pmovzxwd => (LegacyPrefixes::_66, 0x0F3833, 3), - SseOpcode::Pmovzxwq => (LegacyPrefixes::_66, 0x0F3834, 3), - SseOpcode::Pmovzxdq => (LegacyPrefixes::_66, 0x0F3835, 3), SseOpcode::Pmaxsb => (LegacyPrefixes::_66, 0x0F383C, 3), SseOpcode::Pmaxsw => (LegacyPrefixes::_66, 0x0FEE, 2), SseOpcode::Pmaxsd => (LegacyPrefixes::_66, 0x0F383D, 3), diff --git a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs index bda26e3f27..0786746672 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs @@ -10,7 +10,7 @@ //! RUST_BACKTRACE=1 cargo test --features test-programs/test_programs \ //! --features experimental_x64 --all --exclude peepmatic --exclude lightbeam \ //! --exclude wasmtime-lightbeam --exclude peepmatic-automata --exclude peepmatic-fuzzing \ -//! --exclude peepmatic-macro -- isa::x64::inst::emit_tests::test_x64_emit +//! --exclude peepmatic-macro --exclude wasmtime-wasi-nn -- isa::x64::inst::emit_tests::test_x64_emit use super::*; use crate::isa::test_utils; @@ -3201,81 +3201,6 @@ fn test_x64_emit() { "cvttps2dq %xmm9, %xmm8", )); - // ======================================================== - // XMM_RM_R: Packed Move - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxbd, RegMem::reg(xmm6), w_xmm8), - "66440F3821C6", - "pmovsxbd %xmm6, %xmm8", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxbw, RegMem::reg(xmm9), w_xmm10), - "66450F3820D1", - "pmovsxbw %xmm9, %xmm10", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxbq, RegMem::reg(xmm1), w_xmm1), - "660F3822C9", - "pmovsxbq %xmm1, %xmm1", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxwd, RegMem::reg(xmm13), w_xmm10), - "66450F3823D5", - "pmovsxwd %xmm13, %xmm10", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxwq, RegMem::reg(xmm12), w_xmm12), - "66450F3824E4", - "pmovsxwq %xmm12, %xmm12", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovsxdq, RegMem::reg(xmm10), w_xmm8), - "66450F3825C2", - "pmovsxdq %xmm10, %xmm8", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxbd, RegMem::reg(xmm5), w_xmm6), - "660F3831F5", - "pmovzxbd %xmm5, %xmm6", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxbw, RegMem::reg(xmm5), w_xmm13), - "66440F3830ED", - "pmovzxbw %xmm5, %xmm13", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxbq, RegMem::reg(xmm10), w_xmm11), - "66450F3832DA", - "pmovzxbq %xmm10, %xmm11", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxwd, RegMem::reg(xmm2), w_xmm10), - "66440F3833D2", - "pmovzxwd %xmm2, %xmm10", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxwq, RegMem::reg(xmm7), w_xmm4), - "660F3834E7", - "pmovzxwq %xmm7, %xmm4", - )); - - insns.push(( - Inst::xmm_rm_r(SseOpcode::Pmovzxdq, RegMem::reg(xmm3), w_xmm4), - "660F3835E3", - "pmovzxdq %xmm3, %xmm4", - )); - // XMM_Mov_R_M: float stores insns.push(( Inst::xmm_mov_r_m(SseOpcode::Movss, xmm15, Amode::imm_reg(128, r12)), @@ -3288,6 +3213,81 @@ fn test_x64_emit() { "movsd %xmm1, 0(%rsi)", )); + // ======================================================== + // XMM_MOV: Packed Move + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxbd, RegMem::reg(xmm6), w_xmm8), + "66440F3821C6", + "pmovsxbd %xmm6, %xmm8", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxbw, RegMem::reg(xmm9), w_xmm10), + "66450F3820D1", + "pmovsxbw %xmm9, %xmm10", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxbq, RegMem::reg(xmm1), w_xmm1), + "660F3822C9", + "pmovsxbq %xmm1, %xmm1", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxwd, RegMem::reg(xmm13), w_xmm10), + "66450F3823D5", + "pmovsxwd %xmm13, %xmm10", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxwq, RegMem::reg(xmm12), w_xmm12), + "66450F3824E4", + "pmovsxwq %xmm12, %xmm12", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovsxdq, RegMem::reg(xmm10), w_xmm8), + "66450F3825C2", + "pmovsxdq %xmm10, %xmm8", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxbd, RegMem::reg(xmm5), w_xmm6), + "660F3831F5", + "pmovzxbd %xmm5, %xmm6", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxbw, RegMem::reg(xmm5), w_xmm13), + "66440F3830ED", + "pmovzxbw %xmm5, %xmm13", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxbq, RegMem::reg(xmm10), w_xmm11), + "66450F3832DA", + "pmovzxbq %xmm10, %xmm11", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxwd, RegMem::reg(xmm2), w_xmm10), + "66440F3833D2", + "pmovzxwd %xmm2, %xmm10", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxwq, RegMem::reg(xmm7), w_xmm4), + "660F3834E7", + "pmovzxwq %xmm7, %xmm4", + )); + + insns.push(( + Inst::xmm_mov(SseOpcode::Pmovzxdq, RegMem::reg(xmm3), w_xmm4), + "660F3835E3", + "pmovzxdq %xmm3, %xmm4", + )); + // XmmUnary: moves and unary float ops insns.push(( Inst::xmm_unary_rm_r(SseOpcode::Movss, RegMem::reg(xmm13), w_xmm2), diff --git a/cranelift/codegen/src/isa/x64/lower.rs b/cranelift/codegen/src/isa/x64/lower.rs index 21ed356cc1..b15cb62a73 100644 --- a/cranelift/codegen/src/isa/x64/lower.rs +++ b/cranelift/codegen/src/isa/x64/lower.rs @@ -2910,12 +2910,10 @@ fn lower_insn_to_regs>( match op { Opcode::SwidenLow => match (input_ty, output_ty) { (types::I8X16, types::I16X8) => { - ctx.emit(Inst::gen_move(dst, src, output_ty)); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovsxbw, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovsxbw, RegMem::reg(src), dst)); } (types::I16X8, types::I32X4) => { - ctx.emit(Inst::gen_move(dst, src, output_ty)); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovsxwd, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovsxwd, RegMem::reg(src), dst)); } _ => unreachable!(), }, @@ -2929,7 +2927,7 @@ fn lower_insn_to_regs>( 8, false, )); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovsxbw, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovsxbw, RegMem::from(dst), dst)); } (types::I16X8, types::I32X4) => { ctx.emit(Inst::gen_move(dst, src, output_ty)); @@ -2940,18 +2938,16 @@ fn lower_insn_to_regs>( 8, false, )); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovsxwd, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovsxwd, RegMem::from(dst), dst)); } _ => unreachable!(), }, Opcode::UwidenLow => match (input_ty, output_ty) { (types::I8X16, types::I16X8) => { - ctx.emit(Inst::gen_move(dst, src, output_ty)); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovzxbw, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovzxbw, RegMem::reg(src), dst)); } (types::I16X8, types::I32X4) => { - ctx.emit(Inst::gen_move(dst, src, output_ty)); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovzxwd, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovzxwd, RegMem::reg(src), dst)); } _ => unreachable!(), }, @@ -2965,7 +2961,7 @@ fn lower_insn_to_regs>( 8, false, )); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovzxbw, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovzxbw, RegMem::from(dst), dst)); } (types::I16X8, types::I32X4) => { ctx.emit(Inst::gen_move(dst, src, output_ty)); @@ -2976,7 +2972,7 @@ fn lower_insn_to_regs>( 8, false, )); - ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmovzxwd, RegMem::from(dst), dst)); + ctx.emit(Inst::xmm_mov(SseOpcode::Pmovzxwd, RegMem::from(dst), dst)); } _ => unreachable!(), }, From 6bde8519c1df7302dbed4d538558174027c09c87 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 17 Dec 2020 11:09:10 +0000 Subject: [PATCH 12/27] cargo deny config --- crates/fuzzing/Cargo.toml | 1 + crates/test-programs/Cargo.toml | 1 + deny.toml | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 deny.toml diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index 7120601b2e..c4b13a2589 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -5,6 +5,7 @@ edition = "2018" name = "wasmtime-fuzzing" publish = false version = "0.19.0" +license = "Apache-2.0 WITH LLVM-exception" [dependencies] anyhow = "1.0.22" diff --git a/crates/test-programs/Cargo.toml b/crates/test-programs/Cargo.toml index 0ba9925014..a2fe35e3f4 100644 --- a/crates/test-programs/Cargo.toml +++ b/crates/test-programs/Cargo.toml @@ -5,6 +5,7 @@ authors = ["The Wasmtime Project Developers"] readme = "README.md" edition = "2018" publish = false +license = "Apache-2.0 WITH LLVM-exception" [build-dependencies] cfg-if = "1.0" diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000000..d564bf307e --- /dev/null +++ b/deny.toml @@ -0,0 +1,48 @@ +# Documentation for this configuration file can be found here +# https://embarkstudios.github.io/cargo-deny/checks/cfg.html + +targets = [ + { triple = "x86_64-unknown-linux-gnu" }, + { triple = "x86_64-apple-darwin" }, + { triple = "x86_64-pc-windows-msvc" }, + { triple = "aarch64-linux-android" }, +] + +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +vulnerability = "deny" +unmaintained = "deny" +yanked = "deny" +ignore = [ + "RUSTSEC-2020-0053", # dirs is unmaintained +] + +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +allow = [ + "Apache-2.0 WITH LLVM-exception", + "Apache-2.0", + "BSD-2-Clause", + "CC0-1.0", + "MIT", + "MPL-2.0", + "Zlib", +] + +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +multiple-versions = "deny" +wildcards = "allow" +deny = [] + +# Skip some multiple-versions checks, until they can be fixed. +skip = [ + { name = "ansi_term" }, + { name = "cfg-if" }, + { name = "env_logger" }, + { name = "getrandom" }, + { name = "humantime" }, + { name = "memoffset" }, + { name = "wasmparser" }, + { name = "wast" }, +] From b4283c514fd849ebdb1452d904138e81c688f9e7 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 17 Dec 2020 11:24:10 +0000 Subject: [PATCH 13/27] cargo deny runs on CI --- .github/workflows/main.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e80781daf..881f629610 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,19 @@ jobs: - run: rustup component add rustfmt - run: cargo fmt --all -- --check + # Lint dependency graph for security advisories, duplicate versions, and + # incompatible licences + cargo_deny: + name: Cargo deny + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: ./.github/actions/install-rust + - run: cargo install cargo-deny + - run: cargo deny check + # Build `mdBook` documentation for `wasmtime`, and upload it as a temporary # build artifact doc_book: From 26b60744201598806bd07ac2d30d0429e13426c9 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 17 Dec 2020 13:48:25 +0000 Subject: [PATCH 14/27] Download precompiled cargo deny --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 881f629610..8b42f8a9db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,11 @@ jobs: with: submodules: true - uses: ./.github/actions/install-rust - - run: cargo install cargo-deny + - run: | + set -e + curl -L https://github.com/EmbarkStudios/cargo-deny/releases/download/0.8.5/cargo-deny-0.8.5-x86_64-unknown-linux-musl.tar.gz | tar xzf - + mv cargo-deny-*-x86_64-unknown-linux-musl/cargo-deny cargo-deny + echo `pwd` >> $GITHUB_PATH - run: cargo deny check # Build `mdBook` documentation for `wasmtime`, and upload it as a temporary From 76fb9a08c7d4349e039891ac4542fc3ac3ea60a6 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 16 Dec 2020 18:50:05 -0800 Subject: [PATCH 15/27] cranelift-object: reject symbol names with NUL byte without panic'ing. Avoid a `panic!()`, and return a proper error, on a NUL byte. We hit a null-byte check inside the `object` crate otherwise; this blocks fuzzing when testing via a write-object-file-and-dlopen flow. --- cranelift/object/src/backend.rs | 16 ++++++++++++ cranelift/object/tests/basic.rs | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rs index 81dd75c4cd..98ab139a2f 100644 --- a/cranelift/object/src/backend.rs +++ b/cranelift/object/src/backend.rs @@ -145,6 +145,18 @@ impl ObjectModule { } } +fn validate_symbol(name: &str) -> ModuleResult<()> { + // null bytes are not allowed in symbol names and will cause the `object` + // crate to panic. Let's return a clean error instead. + if name.contains("\0") { + return Err(ModuleError::Backend(anyhow::anyhow!( + "Symbol {:?} has a null byte, which is disallowed", + name + ))); + } + Ok(()) +} + impl Module for ObjectModule { fn isa(&self) -> &dyn TargetIsa { &*self.isa @@ -160,6 +172,8 @@ impl Module for ObjectModule { linkage: Linkage, signature: &ir::Signature, ) -> ModuleResult { + validate_symbol(name)?; + let (id, decl) = self .declarations .declare_function(name, linkage, signature)?; @@ -194,6 +208,8 @@ impl Module for ObjectModule { writable: bool, tls: bool, ) -> ModuleResult { + validate_symbol(name)?; + let (id, decl) = self .declarations .declare_data(name, linkage, writable, tls)?; diff --git a/cranelift/object/tests/basic.rs b/cranelift/object/tests/basic.rs index 18acae5733..dad2bbca9d 100644 --- a/cranelift/object/tests/basic.rs +++ b/cranelift/object/tests/basic.rs @@ -197,3 +197,46 @@ fn libcall_function() { module.finish(); } + +#[test] +#[should_panic( + expected = "Result::unwrap()` on an `Err` value: Backend(Symbol \"function\\u{0}with\\u{0}nul\\u{0}bytes\" has a null byte, which is disallowed" +)] +fn reject_nul_byte_symbol_for_func() { + let flag_builder = settings::builder(); + let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); + let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let mut module = + ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); + + let sig = Signature { + params: vec![], + returns: vec![], + call_conv: CallConv::SystemV, + }; + + let _ = module + .declare_function("function\u{0}with\u{0}nul\u{0}bytes", Linkage::Local, &sig) + .unwrap(); +} + +#[test] +#[should_panic( + expected = "Result::unwrap()` on an `Err` value: Backend(Symbol \"data\\u{0}with\\u{0}nul\\u{0}bytes\" has a null byte, which is disallowed" +)] +fn reject_nul_byte_symbol_for_data() { + let flag_builder = settings::builder(); + let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap(); + let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let mut module = + ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap()); + + let _ = module + .declare_data( + "data\u{0}with\u{0}nul\u{0}bytes", + Linkage::Local, + /* writable = */ true, + /* tls = */ false, + ) + .unwrap(); +} From fe1ff02a80ba945d8bc7de1946253eb4840e09b3 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 10:57:47 -0800 Subject: [PATCH 16/27] cargo update --- Cargo.lock | 238 +++++++++++++++++++++++++---------------------------- 1 file changed, 113 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e200c31d2..b2e09c88ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,9 +17,9 @@ checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" [[package]] name = "ahash" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6789e291be47ace86a60303502173d84af8327e3627ecf334356ee0f87a164c" +checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" [[package]] name = "aho-corasick" @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7" +checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4" [[package]] name = "arbitrary" @@ -106,12 +106,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -163,9 +157,9 @@ dependencies = [ [[package]] name = "bit-vec" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" @@ -227,9 +221,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.61" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" dependencies = [ "jobserver", ] @@ -270,9 +264,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519" +checksum = "0659001ab56b791be01d4b729c44376edc6718cf389a502e579b77b758f3296c" dependencies = [ "glob", "libc", @@ -296,9 +290,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" dependencies = [ "cc", ] @@ -321,9 +315,9 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab" +checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" [[package]] name = "constant_time_eq" @@ -617,7 +611,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.0", + "crossbeam-utils", ] [[package]] @@ -628,43 +622,31 @@ checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils 0.8.0", + "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" +checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" dependencies = [ "cfg-if 1.0.0", "const_fn", - "crossbeam-utils 0.8.0", + "crossbeam-utils", "lazy_static", - "memoffset 0.5.6", + "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.7.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ "autocfg", "cfg-if 1.0.0", - "const_fn", "lazy_static", ] @@ -701,9 +683,9 @@ dependencies = [ [[package]] name = "derive_utils" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df5480412da86cdf5d6b7f3b682422c84359ff7399aa658df1d15ee83244b1d" +checksum = "64196eb9f551916167225134f1e8a90f0b5774331d3c900d6328fd94bafe3544" dependencies = [ "proc-macro2", "quote", @@ -826,9 +808,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd" +checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" dependencies = [ "atty", "humantime 2.0.1", @@ -1038,9 +1020,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" dependencies = [ "autocfg", "hashbrown", @@ -1061,9 +1043,9 @@ dependencies = [ [[package]] name = "iter-enum" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cdea9771bec3d95893f6c665a4fcd477af7858446a46bc2772f560534eee43b" +checksum = "86a94bc12a53bf84b705acee29eb8697a5ea7b4587d836152499e5db0a6d52b9" dependencies = [ "derive_utils", "quote", @@ -1111,9 +1093,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leb128" @@ -1123,15 +1105,15 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libfuzzer-sys" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8c42ab62f43795ed77a965ed07994c5584cdc94fd0ebf14b22ac1524077acc" +checksum = "fcf184a4b6b274f82a5df6b357da6055d3e82272327bba281c28bbba6f1664ef" dependencies = [ "arbitrary", "cc", @@ -1139,11 +1121,11 @@ dependencies = [ [[package]] name = "libloading" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" +checksum = "e9367bdfa836b7e3cf895867f7a570283444da90562980ec2263d6e1569b16bc" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "winapi", ] @@ -1161,7 +1143,7 @@ dependencies = [ "iter-enum", "itertools", "lazy_static", - "memoffset 0.6.1", + "memoffset", "more-asserts", "quickcheck", "smallvec", @@ -1227,15 +1209,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "memoffset" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.6.1" @@ -1348,9 +1321,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "opaque-debug" @@ -1428,7 +1401,7 @@ version = "0.66.0" dependencies = [ "arbitrary", "bincode", - "env_logger 0.8.1", + "env_logger 0.8.2", "fst", "log", "peepmatic", @@ -1483,7 +1456,7 @@ dependencies = [ name = "peepmatic-test" version = "0.2.0" dependencies = [ - "env_logger 0.8.1", + "env_logger 0.8.2", "log", "peepmatic", "peepmatic-runtime", @@ -1506,9 +1479,9 @@ version = "0.68.0" [[package]] name = "pin-project-lite" -version = "0.1.11" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" +checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" [[package]] name = "ppv-lite86" @@ -1581,9 +1554,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e0536f6528466dbbbbe6b986c34175a8d0ff25b794c4bacda22e068cd2f2c5" +checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" dependencies = [ "cc", ] @@ -1706,7 +1679,7 @@ checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils 0.8.0", + "crossbeam-utils", "lazy_static", "num_cpus", ] @@ -1799,14 +1772,14 @@ dependencies = [ [[package]] name = "rust-argon2" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" dependencies = [ - "base64 0.12.3", + "base64", "blake2b_simd", "constant_time_eq", - "crossbeam-utils 0.7.2", + "crossbeam-utils", ] [[package]] @@ -1906,18 +1879,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" +checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" +checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" dependencies = [ "proc-macro2", "quote", @@ -1926,9 +1899,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" +checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" dependencies = [ "itoa", "ryu", @@ -1937,9 +1910,9 @@ dependencies = [ [[package]] name = "serde_test" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a49e2f787c0fddfd5e758cbbd3cbf81c3a8d12ef091283c52d9e9b4d417d3c" +checksum = "f7f3f8714511d29f60be0ea965bc784df1b6903da5bbac801df36b1bbc7b4880" dependencies = [ "serde", ] @@ -1984,9 +1957,9 @@ checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" [[package]] name = "smallvec" -version = "1.4.2" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" +checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" [[package]] name = "souper-ir" @@ -2011,9 +1984,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" dependencies = [ "clap", "lazy_static", @@ -2022,9 +1995,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" dependencies = [ "heck", "proc-macro-error", @@ -2035,9 +2008,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.48" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" dependencies = [ "proc-macro2", "quote", @@ -2076,18 +2049,18 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] [[package]] name = "terminal_size" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a14cd9f8c72704232f0bfc8455c0e861f0ad4eb60cc9ec8a170e231414c1e13" +checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1" dependencies = [ "libc", "winapi", @@ -2169,11 +2142,11 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-attributes", @@ -2266,9 +2239,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-segmentation" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" @@ -2411,13 +2384,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed1b3f9e9cf01a580b9f3281214dfdb1922b5dfb8494ee312ca03ae10036c2a2" [[package]] -name = "wasmprinter" -version = "0.2.17" +name = "wasmparser" +version = "0.71.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89b2b24dce17e27fe9c09c28331cbd77067fcde5c6ea2508ac84bcbd5d3e018" +checksum = "89a30c99437829ede826802bfcf28500cf58df00e66cb9114df98813bc145ff1" + +[[package]] +name = "wasmprinter" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0515db67c610037f3c53ec36976edfd1eb01bac6b1226914b17ce609480e729f" dependencies = [ "anyhow", - "wasmparser 0.70.0", + "wasmparser 0.71.0", ] [[package]] @@ -2465,7 +2444,7 @@ name = "wasmtime-c-api" version = "0.19.0" dependencies = [ "anyhow", - "env_logger 0.8.1", + "env_logger 0.8.2", "once_cell", "wasi-common", "wasmtime", @@ -2487,7 +2466,7 @@ name = "wasmtime-cache" version = "0.21.0" dependencies = [ "anyhow", - "base64 0.13.0", + "base64", "bincode", "directories-next", "errno", @@ -2511,7 +2490,7 @@ name = "wasmtime-cli" version = "0.21.0" dependencies = [ "anyhow", - "env_logger 0.8.1", + "env_logger 0.8.2", "file-per-thread-logger", "filecheck", "humantime 2.0.1", @@ -2606,7 +2585,7 @@ version = "0.19.0" dependencies = [ "anyhow", "arbitrary", - "env_logger 0.8.1", + "env_logger 0.8.2", "log", "rayon", "wasm-smith", @@ -2701,7 +2680,7 @@ dependencies = [ "lazy_static", "libc", "log", - "memoffset 0.6.1", + "memoffset", "more-asserts", "psm", "region", @@ -2807,12 +2786,21 @@ dependencies = [ ] [[package]] -name = "wat" -version = "1.0.30" +name = "wast" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d11a88d953b298172d218d18f22853f4e6e12873b62755d05617b864d312c68" +checksum = "9b79907b22f740634810e882d8d1d9d0f9563095a8ab94e786e370242bff5cd2" dependencies = [ - "wast 29.0.0", + "leb128", +] + +[[package]] +name = "wat" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8279a02835bf12e61ed2b3c3cbc6ecf9918762fd97e036917c11a09ec20ca44" +dependencies = [ + "wast 30.0.0", ] [[package]] @@ -2871,7 +2859,7 @@ dependencies = [ name = "wiggle-test" version = "0.21.0" dependencies = [ - "env_logger 0.8.1", + "env_logger 0.8.2", "proptest", "thiserror", "tracing", @@ -2966,18 +2954,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.5.3+zstd.1.4.5" +version = "0.5.4+zstd.1.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01b32eaf771efa709e8308605bbf9319bf485dc1503179ec0469b611937c0cd8" +checksum = "69996ebdb1ba8b1517f61387a883857818a66c8a295f487b1ffd8fd9d2c82910" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "2.0.5+zstd.1.4.5" +version = "2.0.6+zstd.1.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfb642e0d27f64729a639c52db457e0ae906e7bc6f5fe8f5c453230400f1055" +checksum = "98aa931fb69ecee256d44589d19754e61851ae4769bf963b385119b1cc37a49e" dependencies = [ "libc", "zstd-sys", @@ -2985,9 +2973,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "1.4.17+zstd.1.4.5" +version = "1.4.18+zstd.1.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b89249644df056b522696b1bb9e7c18c87e8ffa3e2f0dc3b0155875d6498f01b" +checksum = "a1e6e8778706838f43f771d80d37787cb2fe06dafe89dd3aebaf6721b9eaec81" dependencies = [ "cc", "glob", From 4f5afe92dc80903c309153159a75292b6d575d75 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 10:58:02 -0800 Subject: [PATCH 17/27] wasmtime-debug: tune down features required from object in order to eliminate a dep on an old wasmparser --- Cargo.lock | 7 ------- crates/debug/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2e09c88ea..630be83fcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1316,7 +1316,6 @@ checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" dependencies = [ "crc32fast", "indexmap", - "wasmparser 0.57.0", ] [[package]] @@ -2371,12 +2370,6 @@ dependencies = [ "parity-wasm", ] -[[package]] -name = "wasmparser" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6" - [[package]] name = "wasmparser" version = "0.70.0" diff --git a/crates/debug/Cargo.toml b/crates/debug/Cargo.toml index f3b5bdede7..2236666c2a 100644 --- a/crates/debug/Cargo.toml +++ b/crates/debug/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] gimli = "0.23.0" wasmparser = "0.70" -object = { version = "0.22.0", default-features = false, features = ["read", "write"] } +object = { version = "0.22.0", default-features = false, features = ["read_core", "elf", "write"] } wasmtime-environ = { path = "../environ", version = "0.21.0" } target-lexicon = { version = "0.11.0", default-features = false } anyhow = "1.0" From 059cabb4cd80ec0b13f45dbf81115c271a218e33 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 11:00:28 -0800 Subject: [PATCH 18/27] deny.toml: comments on why --- deny.toml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/deny.toml b/deny.toml index d564bf307e..2e4a113687 100644 --- a/deny.toml +++ b/deny.toml @@ -37,12 +37,11 @@ deny = [] # Skip some multiple-versions checks, until they can be fixed. skip = [ - { name = "ansi_term" }, - { name = "cfg-if" }, - { name = "env_logger" }, - { name = "getrandom" }, - { name = "humantime" }, - { name = "memoffset" }, - { name = "wasmparser" }, - { name = "wast" }, + { name = "ansi_term" }, # transitive dependencies only + { name = "cfg-if" }, # transitive dependencies use 0.1 + { name = "env_logger" }, # pretty_env_logger and file-per-thread-logger depend on 0.7 + { name = "humantime" }, # caused by env_logger + { name = "getrandom" }, # rand not updates to 0.2 yet + { name = "wasmparser" }, # rapid development, some 0.70 and 0.71 + { name = "wast" }, # old one pulled in by witx ] From 0833a92ddd0bf560afe76accd25c2acaa6617513 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Thu, 17 Dec 2020 12:14:53 -0800 Subject: [PATCH 19/27] cranelift-native crate: add API variant allowing backend selection. --- cranelift/native/src/lib.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cranelift/native/src/lib.rs b/cranelift/native/src/lib.rs index 668a1934bf..3bd5716dac 100644 --- a/cranelift/native/src/lib.rs +++ b/cranelift/native/src/lib.rs @@ -34,10 +34,26 @@ use raw_cpuid::CpuId; /// machine, or `Err(())` if the host machine is not supported /// in the current configuration. pub fn builder() -> Result { - let mut isa_builder = isa::lookup(Triple::host()).map_err(|err| match err { - isa::LookupError::SupportDisabled => "support for architecture disabled at compile time", - isa::LookupError::Unsupported => "unsupported architecture", - })?; + builder_with_backend_variant(isa::BackendVariant::Any) +} + +/// Return an `isa` builder configured for the current host +/// machine, or `Err(())` if the host machine is not supported +/// in the current configuration. +/// +/// Selects the given backend variant specifically; this is +/// useful when more than oen backend exists for a given target +/// (e.g., on x86-64). +pub fn builder_with_backend_variant( + variant: isa::BackendVariant, +) -> Result { + let mut isa_builder = + isa::lookup_variant(Triple::host(), variant).map_err(|err| match err { + isa::LookupError::SupportDisabled => { + "support for architecture disabled at compile time" + } + isa::LookupError::Unsupported => "unsupported architecture", + })?; if cfg!(any(target_arch = "x86", target_arch = "x86_64")) { parse_x86_cpuid(&mut isa_builder)?; From 02260b7cd09f6f4222855cfe3bd2e7ff2f970613 Mon Sep 17 00:00:00 2001 From: David Haynes Date: Thu, 17 Dec 2020 13:47:18 -0800 Subject: [PATCH 20/27] 2499: First pass on TableOps fuzzer generator wasm_encoder migration (#2501) * 2499: First pass on TableOps fuzzer generator wasm_encoder migration - wasm binary generated via sections and smushed together into a module - test: compare generated wat against expected wat - note: doesn't work - Grouped instructions not implemented - Vec to wat String not implemented * 2499: Add typesection, abstract instruction puts, and update test - TableOp.insert now will interact with a function object directly - add types for generated function - expected test string now reflects expected generated code * 2499: Mark unused index as _i * 2499: Function insertion is in proper stack order, and fix off by 1 index - imported functions must be typed - instructions operate on a stack ie. define values as instructions before using * 2499: Apply suggestions from code review - typo fixing - oracle ingests binary bytes itself Co-authored-by: Nick Fitzgerald * 2499: Code cleanup + renaming vars - busywork, nothing to see here Co-authored-by: Nick Fitzgerald --- Cargo.lock | 1 + crates/fuzzing/Cargo.toml | 1 + crates/fuzzing/src/generators/table_ops.rs | 137 +++++++++++++-------- crates/fuzzing/src/oracles.rs | 17 +-- 4 files changed, 93 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e200c31d2..7466721815 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2609,6 +2609,7 @@ dependencies = [ "env_logger 0.8.1", "log", "rayon", + "wasm-encoder", "wasm-smith", "wasmi", "wasmparser 0.70.0", diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index c4b13a2589..5984b775da 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -17,6 +17,7 @@ wasmparser = "0.70" wasmprinter = "0.2.17" wasmtime = { path = "../wasmtime" } wasmtime-wast = { path = "../wast" } +wasm-encoder = "0.2" wasm-smith = "0.3.0" wasmi = "0.7.0" diff --git a/crates/fuzzing/src/generators/table_ops.rs b/crates/fuzzing/src/generators/table_ops.rs index 45aaa5b802..adb2373fea 100644 --- a/crates/fuzzing/src/generators/table_ops.rs +++ b/crates/fuzzing/src/generators/table_ops.rs @@ -1,8 +1,11 @@ //! Generating series of `table.get` and `table.set` operations. use arbitrary::Arbitrary; -use std::fmt::Write; use std::ops::Range; +use wasm_encoder::{ + CodeSection, EntityType, Export, ExportSection, Function, FunctionSection, ImportSection, + Instruction, Limits, Module, TableSection, TableType, TypeSection, ValType, +}; /// A description of a Wasm module that makes a series of `externref` table /// operations. @@ -32,7 +35,7 @@ impl TableOps { table_size } - /// Convert this into a WAT string. + /// Serialize this module into a Wasm binary. /// /// The module requires a single import: `(import "" "gc" (func))`. This /// should be a function to trigger GC. @@ -43,32 +46,62 @@ impl TableOps { /// The "run" function is guaranteed to terminate (no loops or recursive /// calls), but is not guaranteed to avoid traps (might access out-of-bounds /// of the table). - pub fn to_wat_string(&self) -> String { - let mut wat = "(module\n".to_string(); + pub fn to_wasm_binary(&self) -> Vec { + let mut module = Module::new(); // Import the GC function. - wat.push_str(" (import \"\" \"gc\" (func))\n"); + let mut imports = ImportSection::new(); + imports.import("", Some("gc"), EntityType::Function(0)); // Define our table. - wat.push_str(" (table $table "); - write!(&mut wat, "{}", self.table_size()).unwrap(); - wat.push_str(" externref)\n"); + let mut tables = TableSection::new(); + tables.table(TableType { + element_type: ValType::ExternRef, + limits: Limits { + min: self.table_size(), + max: None, + }, + }); + + // Encode the types for all functions that we are using. + let mut types = TypeSection::new(); + types.function(vec![], vec![]); // 0: "gc" + let mut params: Vec = Vec::with_capacity(self.num_params() as usize); + for _i in 0..self.num_params() { + params.push(ValType::ExternRef); + } + let results = vec![]; + types.function(params, results); // 1: "run" // Define the "run" function export. - wat.push_str(r#" (func (export "run") (param"#); - for _ in 0..self.num_params() { - wat.push_str(" externref"); - } - wat.push_str(")\n"); - for op in self.ops.iter().take(MAX_OPS) { - wat.push_str(" "); - op.to_wat_string(&mut wat); - wat.push('\n'); - } - wat.push_str(" )\n"); + let mut functions = FunctionSection::new(); + functions.function(1); - wat.push_str(")\n"); - wat + let mut exports = ExportSection::new(); + exports.export("run", Export::Function(1)); + + let mut params: Vec<(u32, ValType)> = Vec::with_capacity(self.num_params() as usize); + for _i in 0..self.num_params() { + params.push((0, ValType::ExternRef)); + } + let mut func = Function::new(params); + + for op in self.ops.iter().take(MAX_OPS) { + op.insert(&mut func); + } + + let mut code = CodeSection::new(); + code.function(&func); + + module + .section(&types) + .section(&imports) + .section(&functions) + .section(&tables) + .section(&exports) + .section(&code); + + module.finish() } } @@ -77,37 +110,34 @@ pub(crate) enum TableOp { // `(call 0)` Gc, // `(drop (table.get x))` - Get(u32), + Get(i32), // `(table.set x (local.get y))` - SetFromParam(u32, u8), + SetFromParam(i32, u32), // `(table.set x (table.get y))` - SetFromGet(u32, u32), + SetFromGet(i32, i32), } impl TableOp { - fn to_wat_string(&self, wat: &mut String) { + fn insert(&self, func: &mut Function) { match self { Self::Gc => { - wat.push_str("(call 0)"); + func.instruction(Instruction::Call(0)); } Self::Get(x) => { - wat.push_str("(drop (table.get $table (i32.const "); - write!(wat, "{}", x).unwrap(); - wat.push_str(")))"); + func.instruction(Instruction::I32Const(*x)); + func.instruction(Instruction::TableGet { table: 0 }); + func.instruction(Instruction::Drop); } Self::SetFromParam(x, y) => { - wat.push_str("(table.set $table (i32.const "); - write!(wat, "{}", x).unwrap(); - wat.push_str(") (local.get "); - write!(wat, "{}", y).unwrap(); - wat.push_str("))"); + func.instruction(Instruction::I32Const(*x)); + func.instruction(Instruction::LocalGet(*y)); + func.instruction(Instruction::TableSet { table: 0 }); } Self::SetFromGet(x, y) => { - wat.push_str("(table.set $table (i32.const "); - write!(wat, "{}", x).unwrap(); - wat.push_str(") (table.get $table (i32.const "); - write!(wat, "{}", y).unwrap(); - wat.push_str(")))"); + func.instruction(Instruction::I32Const(*x)); + func.instruction(Instruction::I32Const(*y)); + func.instruction(Instruction::TableGet { table: 0 }); + func.instruction(Instruction::TableSet { table: 0 }); } } } @@ -132,17 +162,26 @@ mod tests { let expected = r#" (module - (import "" "gc" (func)) - (table $table 10 externref) - (func (export "run") (param externref externref) - (call 0) - (drop (table.get $table (i32.const 0))) - (table.set $table (i32.const 1) (local.get 2)) - (table.set $table (i32.const 3) (table.get $table (i32.const 4))) - ) -) + (type (;0;) (func)) + (type (;1;) (func (param externref externref))) + (import "" "gc" (func (;0;) (type 0))) + (func (;1;) (type 1) (param externref externref) + call 0 + i32.const 0 + table.get 0 + drop + i32.const 1 + local.get 2 + table.set 0 + i32.const 3 + i32.const 4 + table.get 0 + table.set 0) + (table (;0;) 10 externref) + (export "run" (func 1))) "#; - let actual = ops.to_wat_string(); + let actual = ops.to_wasm_binary(); + let actual = wasmprinter::print_bytes(&actual).unwrap(); assert_eq!(actual.trim(), expected.trim()); } } diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index 9f04dc44df..6581f9e0dc 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -40,17 +40,6 @@ fn log_wasm(wasm: &[u8]) { } } -fn log_wat(wat: &str) { - if !log::log_enabled!(log::Level::Debug) { - return; - } - - let i = CNT.fetch_add(1, SeqCst); - let name = format!("testcase{}.wat", i); - log::debug!("wrote wat file to `{}`", name); - std::fs::write(&name, wat).expect("failed to write wat file"); -} - /// Instantiate the Wasm buffer, and implicitly fail if we have an unexpected /// panic or segfault or anything else that can be detected "passively". /// @@ -418,9 +407,9 @@ pub fn table_ops(config: crate::generators::Config, ops: crate::generators::tabl let engine = Engine::new(&config); let store = Store::new(&engine); - let wat = ops.to_wat_string(); - log_wat(&wat); - let module = match Module::new(&engine, &wat) { + let wasm = ops.to_wasm_binary(); + log_wasm(&wasm); + let module = match Module::new(&engine, &wasm) { Ok(m) => m, Err(_) => return, }; From 8cf652a2a58b228465b01b4a1ff79ecbea8e3e5b Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 14:26:25 -0800 Subject: [PATCH 21/27] Update deny.toml Co-authored-by: bjorn3 --- deny.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deny.toml b/deny.toml index 2e4a113687..a7bae721bb 100644 --- a/deny.toml +++ b/deny.toml @@ -39,7 +39,7 @@ deny = [] skip = [ { name = "ansi_term" }, # transitive dependencies only { name = "cfg-if" }, # transitive dependencies use 0.1 - { name = "env_logger" }, # pretty_env_logger and file-per-thread-logger depend on 0.7 + { name = "env_logger" }, # pretty_env_logger and file-per-thread-logger depend on 0.7 { name = "humantime" }, # caused by env_logger { name = "getrandom" }, # rand not updates to 0.2 yet { name = "wasmparser" }, # rapid development, some 0.70 and 0.71 From fb78025e4148e7f768b0639e89cb27a32a6cb2c7 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 14:48:40 -0800 Subject: [PATCH 22/27] upgrade all wasmparser to 0.71 new simd instructions are left as ubsupported in cranelift-wasm --- Cargo.lock | 26 ++++++++++---------------- Cargo.toml | 2 +- cranelift/wasm/Cargo.toml | 2 +- cranelift/wasm/src/code_translator.rs | 15 ++++++++++++++- crates/debug/Cargo.toml | 2 +- crates/environ/Cargo.toml | 2 +- crates/fuzzing/Cargo.toml | 2 +- crates/jit/Cargo.toml | 2 +- crates/lightbeam/Cargo.toml | 2 +- crates/lightbeam/wasmtime/Cargo.toml | 2 +- crates/wasmtime/Cargo.toml | 2 +- 11 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 630be83fcd..0d202185e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -591,7 +591,7 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror", - "wasmparser 0.70.0", + "wasmparser", "wat", ] @@ -1149,7 +1149,7 @@ dependencies = [ "smallvec", "thiserror", "typemap", - "wasmparser 0.70.0", + "wasmparser", "wat", ] @@ -2370,12 +2370,6 @@ dependencies = [ "parity-wasm", ] -[[package]] -name = "wasmparser" -version = "0.70.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1b3f9e9cf01a580b9f3281214dfdb1922b5dfb8494ee312ca03ae10036c2a2" - [[package]] name = "wasmparser" version = "0.71.0" @@ -2389,7 +2383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0515db67c610037f3c53ec36976edfd1eb01bac6b1226914b17ce609480e729f" dependencies = [ "anyhow", - "wasmparser 0.71.0", + "wasmparser", ] [[package]] @@ -2410,7 +2404,7 @@ dependencies = [ "smallvec", "target-lexicon", "tempfile", - "wasmparser 0.70.0", + "wasmparser", "wasmtime-cache", "wasmtime-environ", "wasmtime-jit", @@ -2499,7 +2493,7 @@ dependencies = [ "test-programs", "tracing-subscriber", "wasi-common", - "wasmparser 0.70.0", + "wasmparser", "wasmtime", "wasmtime-cache", "wasmtime-debug", @@ -2535,7 +2529,7 @@ dependencies = [ "object", "target-lexicon", "thiserror", - "wasmparser 0.70.0", + "wasmparser", "wasmtime-environ", ] @@ -2554,7 +2548,7 @@ dependencies = [ "more-asserts", "serde", "thiserror", - "wasmparser 0.70.0", + "wasmparser", ] [[package]] @@ -2583,7 +2577,7 @@ dependencies = [ "rayon", "wasm-smith", "wasmi", - "wasmparser 0.70.0", + "wasmparser", "wasmprinter", "wasmtime", "wasmtime-wast", @@ -2611,7 +2605,7 @@ dependencies = [ "serde", "target-lexicon", "thiserror", - "wasmparser 0.70.0", + "wasmparser", "wasmtime-cranelift", "wasmtime-debug", "wasmtime-environ", @@ -2628,7 +2622,7 @@ version = "0.21.0" dependencies = [ "cranelift-codegen", "lightbeam", - "wasmparser 0.70.0", + "wasmparser", "wasmtime-environ", ] diff --git a/Cargo.toml b/Cargo.toml index ea08c6ea64..d111151e38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ libc = "0.2.60" log = "0.4.8" rayon = "1.2.1" humantime = "2.0.0" -wasmparser = "0.70.0" +wasmparser = "0.71.0" [dev-dependencies] env_logger = "0.8.1" diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index 48e19a9d57..4a37c004d1 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"] edition = "2018" [dependencies] -wasmparser = { version = "0.70", default-features = false } +wasmparser = { version = "0.71", default-features = false } cranelift-codegen = { path = "../codegen", version = "0.68.0", default-features = false } cranelift-entity = { path = "../entity", version = "0.68.0" } cranelift-frontend = { path = "../frontend", version = "0.68.0", default-features = false } diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 2fe171842b..998a0c7417 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -1810,7 +1810,20 @@ pub fn translate_operator( let (a, b) = pop2_with_bitcast(state, I16X8, builder); state.push1(builder.ins().widening_pairwise_dot_product_s(a, b)); } - + Operator::I16x8ExtMulLowI8x16S + | Operator::I16x8ExtMulHighI8x16S + | Operator::I16x8ExtMulLowI8x16U + | Operator::I16x8ExtMulHighI8x16U + | Operator::I32x4ExtMulLowI16x8S + | Operator::I32x4ExtMulHighI16x8S + | Operator::I32x4ExtMulLowI16x8U + | Operator::I32x4ExtMulHighI16x8U + | Operator::I64x2ExtMulLowI32x4S + | Operator::I64x2ExtMulHighI32x4S + | Operator::I64x2ExtMulLowI32x4U + | Operator::I64x2ExtMulHighI32x4U => { + return Err(wasm_unsupported!("proposed simd operator {:?}", op)); + } Operator::ReturnCall { .. } | Operator::ReturnCallIndirect { .. } => { return Err(wasm_unsupported!("proposed tail-call operator {:?}", op)); } diff --git a/crates/debug/Cargo.toml b/crates/debug/Cargo.toml index 2236666c2a..c893c9ab13 100644 --- a/crates/debug/Cargo.toml +++ b/crates/debug/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] gimli = "0.23.0" -wasmparser = "0.70" +wasmparser = "0.71" object = { version = "0.22.0", default-features = false, features = ["read_core", "elf", "write"] } wasmtime-environ = { path = "../environ", version = "0.21.0" } target-lexicon = { version = "0.11.0", default-features = false } diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index 26b0ec0eaf..aa132a340f 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -16,7 +16,7 @@ anyhow = "1.0" cranelift-codegen = { path = "../../cranelift/codegen", version = "0.68.0", features = ["enable-serde"] } cranelift-entity = { path = "../../cranelift/entity", version = "0.68.0", features = ["enable-serde"] } cranelift-wasm = { path = "../../cranelift/wasm", version = "0.68.0", features = ["enable-serde"] } -wasmparser = "0.70" +wasmparser = "0.71" indexmap = { version = "1.0.2", features = ["serde-1"] } thiserror = "1.0.4" serde = { version = "1.0.94", features = ["derive"] } diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index c4b13a2589..3d77683437 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -13,7 +13,7 @@ arbitrary = { version = "0.4.1", features = ["derive"] } env_logger = "0.8.1" log = "0.4.8" rayon = "1.2.1" -wasmparser = "0.70" +wasmparser = "0.71" wasmprinter = "0.2.17" wasmtime = { path = "../wasmtime" } wasmtime-wast = { path = "../wast" } diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index c754126d92..7b578543b7 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -28,7 +28,7 @@ rayon = { version = "1.0", optional = true } region = "2.1.0" thiserror = "1.0.4" target-lexicon = { version = "0.11.0", default-features = false } -wasmparser = "0.70" +wasmparser = "0.71" more-asserts = "0.2.1" anyhow = "1.0" cfg-if = "1.0" diff --git a/crates/lightbeam/Cargo.toml b/crates/lightbeam/Cargo.toml index d178090cfa..65ad3ba751 100644 --- a/crates/lightbeam/Cargo.toml +++ b/crates/lightbeam/Cargo.toml @@ -24,7 +24,7 @@ more-asserts = "0.2.1" smallvec = "1.0.0" thiserror = "1.0.9" typemap = "0.3" -wasmparser = "0.70" +wasmparser = "0.71" [dev-dependencies] lazy_static = "1.2" diff --git a/crates/lightbeam/wasmtime/Cargo.toml b/crates/lightbeam/wasmtime/Cargo.toml index 41b47115ee..51b0900b50 100644 --- a/crates/lightbeam/wasmtime/Cargo.toml +++ b/crates/lightbeam/wasmtime/Cargo.toml @@ -13,6 +13,6 @@ edition = "2018" [dependencies] lightbeam = { path = "..", version = "0.21.0" } -wasmparser = "0.70" +wasmparser = "0.71" cranelift-codegen = { path = "../../../cranelift/codegen", version = "0.68.0" } wasmtime-environ = { path = "../../environ", version = "0.21.0" } diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index 1fa4f012f4..9f22c01c40 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -16,7 +16,7 @@ wasmtime-jit = { path = "../jit", version = "0.21.0" } wasmtime-cache = { path = "../cache", version = "0.21.0", optional = true } wasmtime-profiling = { path = "../profiling", version = "0.21.0" } target-lexicon = { version = "0.11.0", default-features = false } -wasmparser = "0.70" +wasmparser = "0.71" anyhow = "1.0.19" region = "2.2.0" libc = "0.2" From 8a09652d81c2ce8615247388c5550dfb07fea27c Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 17 Dec 2020 14:53:04 -0800 Subject: [PATCH 23/27] delete wasmparser exception from deny.toml --- deny.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/deny.toml b/deny.toml index a7bae721bb..b690fa0a0e 100644 --- a/deny.toml +++ b/deny.toml @@ -42,6 +42,5 @@ skip = [ { name = "env_logger" }, # pretty_env_logger and file-per-thread-logger depend on 0.7 { name = "humantime" }, # caused by env_logger { name = "getrandom" }, # rand not updates to 0.2 yet - { name = "wasmparser" }, # rapid development, some 0.70 and 0.71 { name = "wast" }, # old one pulled in by witx ] From ce6e967eebc7e293950394ba212689190e2cf0ed Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 18 Dec 2020 14:12:02 -0600 Subject: [PATCH 24/27] Add a CLI option for module linking (#2524) * Add a CLI option for module linking Forgot to add this earlier! * Always apt-get update before install --- .github/workflows/main.yml | 2 +- src/lib.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8b42f8a9db..3885cd9f09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -286,7 +286,7 @@ jobs: # Test debug (DWARF) related functionality. - run: | - sudo apt-get install -y gdb + sudo apt-get update && sudo apt-get install -y gdb cargo test test_debug_dwarf -- --ignored --test-threads 1 if: matrix.os == 'ubuntu-latest' env: diff --git a/src/lib.rs b/src/lib.rs index b7eaaa8a09..39bda21f66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,6 +127,10 @@ struct CommonOptions { #[structopt(long)] enable_multi_memory: bool, + /// Enable support for the module-linking proposal + #[structopt(long)] + enable_module_linking: bool, + /// Enable all experimental Wasm features #[structopt(long)] enable_all: bool, @@ -198,6 +202,7 @@ impl CommonOptions { .wasm_multi_value(self.enable_multi_value.unwrap_or(true) || self.enable_all) .wasm_threads(self.enable_threads || self.enable_all) .wasm_multi_memory(self.enable_multi_memory || self.enable_all) + .wasm_module_linking(self.enable_module_linking || self.enable_all) .cranelift_opt_level(self.opt_level()) .strategy(pick_compilation_strategy(self.cranelift, self.lightbeam)?)? .profiler(pick_profiling_strategy(self.jitdump, self.vtune)?)? From 2964023a77f94939242aad5381e32ff458e3793c Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Thu, 24 Dec 2020 07:52:50 -0600 Subject: [PATCH 25/27] [SIMD][x86_64] Add encoding for PMADDWD (#2530) * [SIMD][x86_64] Add encoding for PMADDWD * also for "experimental_x64" --- .../codegen/meta/src/isa/x86/encodings.rs | 4 ++++ cranelift/codegen/meta/src/isa/x86/opcodes.rs | 3 +++ cranelift/codegen/src/isa/x64/inst/args.rs | 3 +++ cranelift/codegen/src/isa/x64/inst/emit.rs | 1 + .../codegen/src/isa/x64/inst/emit_tests.rs | 6 ++++++ cranelift/codegen/src/isa/x64/lower.rs | 18 ++++++++++++++++++ .../isa/x86/simd-arithmetic-binemit.clif | 6 ++++++ 7 files changed, 41 insertions(+) diff --git a/cranelift/codegen/meta/src/isa/x86/encodings.rs b/cranelift/codegen/meta/src/isa/x86/encodings.rs index de48c57c5d..bdfcef9c6f 100644 --- a/cranelift/codegen/meta/src/isa/x86/encodings.rs +++ b/cranelift/codegen/meta/src/isa/x86/encodings.rs @@ -1691,6 +1691,7 @@ fn define_simd( let usub_sat = shared.by_name("usub_sat"); let vconst = shared.by_name("vconst"); let vselect = shared.by_name("vselect"); + let widening_pairwise_dot_product_s = shared.by_name("widening_pairwise_dot_product_s"); let x86_cvtt2si = x86.by_name("x86_cvtt2si"); let x86_insertps = x86.by_name("x86_insertps"); let x86_fmax = x86.by_name("x86_fmax"); @@ -2213,6 +2214,9 @@ fn define_simd( // SIMD multiplication with lane expansion. e.enc_both_inferred(x86_pmuludq, rec_fa.opcodes(&PMULUDQ)); + // SIMD multiplication and add adjacent pairs, from SSE2. + e.enc_both_inferred(widening_pairwise_dot_product_s, rec_fa.opcodes(&PMADDWD)); + // SIMD integer multiplication for I64x2 using a AVX512. { e.enc_32_64_maybe_isap( diff --git a/cranelift/codegen/meta/src/isa/x86/opcodes.rs b/cranelift/codegen/meta/src/isa/x86/opcodes.rs index 595d13ba2b..2e72a1744d 100644 --- a/cranelift/codegen/meta/src/isa/x86/opcodes.rs +++ b/cranelift/codegen/meta/src/isa/x86/opcodes.rs @@ -508,6 +508,9 @@ pub static VPMULLQ: [u8; 4] = [0x66, 0x0f, 0x38, 0x40]; /// in xmm2/m128, and store the quadword results in xmm1 (SSE2). pub static PMULUDQ: [u8; 3] = [0x66, 0x0f, 0xf4]; +/// Multiply the packed word integers, add adjacent doubleword results. +pub static PMADDWD: [u8; 3] = [0x66, 0x0f, 0xf5]; + /// Pop top of stack into r{16,32,64}; increment stack pointer. pub static POP_REG: [u8; 1] = [0x58]; diff --git a/cranelift/codegen/src/isa/x64/inst/args.rs b/cranelift/codegen/src/isa/x64/inst/args.rs index 7e3b3f22a2..4c61954630 100644 --- a/cranelift/codegen/src/isa/x64/inst/args.rs +++ b/cranelift/codegen/src/isa/x64/inst/args.rs @@ -498,6 +498,7 @@ pub enum SseOpcode { Pinsrb, Pinsrw, Pinsrd, + Pmaddwd, Pmaxsb, Pmaxsw, Pmaxsd, @@ -661,6 +662,7 @@ impl SseOpcode { | SseOpcode::Pcmpgtd | SseOpcode::Pextrw | SseOpcode::Pinsrw + | SseOpcode::Pmaddwd | SseOpcode::Pmaxsw | SseOpcode::Pmaxub | SseOpcode::Pminsw @@ -842,6 +844,7 @@ impl fmt::Debug for SseOpcode { SseOpcode::Pinsrb => "pinsrb", SseOpcode::Pinsrw => "pinsrw", SseOpcode::Pinsrd => "pinsrd", + SseOpcode::Pmaddwd => "pmaddwd", SseOpcode::Pmaxsb => "pmaxsb", SseOpcode::Pmaxsw => "pmaxsw", SseOpcode::Pmaxsd => "pmaxsd", diff --git a/cranelift/codegen/src/isa/x64/inst/emit.rs b/cranelift/codegen/src/isa/x64/inst/emit.rs index b655178bdf..fb32635a92 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit.rs @@ -1873,6 +1873,7 @@ pub(crate) fn emit( SseOpcode::Pcmpgtw => (LegacyPrefixes::_66, 0x0F65, 2), SseOpcode::Pcmpgtd => (LegacyPrefixes::_66, 0x0F66, 2), SseOpcode::Pcmpgtq => (LegacyPrefixes::_66, 0x0F3837, 3), + SseOpcode::Pmaddwd => (LegacyPrefixes::_66, 0x0FF5, 2), SseOpcode::Pmaxsb => (LegacyPrefixes::_66, 0x0F383C, 3), SseOpcode::Pmaxsw => (LegacyPrefixes::_66, 0x0FEE, 2), SseOpcode::Pmaxsd => (LegacyPrefixes::_66, 0x0F383D, 3), diff --git a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs index 0786746672..e2afa80e2a 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs @@ -3067,6 +3067,12 @@ fn test_x64_emit() { "pmuludq %xmm8, %xmm9", )); + insns.push(( + Inst::xmm_rm_r(SseOpcode::Pmaddwd, RegMem::reg(xmm8), w_xmm1), + "66410FF5C8", + "pmaddwd %xmm8, %xmm1", + )); + insns.push(( Inst::xmm_rm_r(SseOpcode::Pmaxsb, RegMem::reg(xmm15), w_xmm6), "66410F383CF7", diff --git a/cranelift/codegen/src/isa/x64/lower.rs b/cranelift/codegen/src/isa/x64/lower.rs index b15cb62a73..6e6198c44b 100644 --- a/cranelift/codegen/src/isa/x64/lower.rs +++ b/cranelift/codegen/src/isa/x64/lower.rs @@ -2235,6 +2235,24 @@ fn lower_insn_to_regs>( } } + Opcode::WideningPairwiseDotProductS => { + let lhs = put_input_in_reg(ctx, inputs[0]); + let rhs = input_to_reg_mem(ctx, inputs[1]); + let dst = get_output_reg(ctx, outputs[0]); + let ty = ty.unwrap(); + + ctx.emit(Inst::gen_move(dst, lhs, ty)); + + if ty == types::I32X4 { + ctx.emit(Inst::xmm_rm_r(SseOpcode::Pmaddwd, rhs, dst)); + } else { + panic!( + "Opcode::WideningPairwiseDotProductS: unsupported laneage: {:?}", + ty + ); + } + } + Opcode::Fadd | Opcode::Fsub | Opcode::Fmul | Opcode::Fdiv => { let lhs = put_input_in_reg(ctx, inputs[0]); let rhs = input_to_reg_mem(ctx, inputs[1]); diff --git a/cranelift/filetests/filetests/isa/x86/simd-arithmetic-binemit.clif b/cranelift/filetests/filetests/isa/x86/simd-arithmetic-binemit.clif index 8df5c2afa8..cd942338dd 100644 --- a/cranelift/filetests/filetests/isa/x86/simd-arithmetic-binemit.clif +++ b/cranelift/filetests/filetests/isa/x86/simd-arithmetic-binemit.clif @@ -108,3 +108,9 @@ block0(v0: i64x2 [%xmm3], v1: i64x2 [%xmm5]): [-, %xmm3] v2 = x86_pmuludq v0, v1 ; bin: 66 0f f4 dd return v2 } + +function %pmaddwd(i16x8, i16x8) -> i32x4 { +block0(v0: i16x8 [%xmm8], v1: i16x8 [%xmm9]): +[-, %xmm8] v2 = widening_pairwise_dot_product_s v0, v1 ; bin: 66 45 0f f5 c1 + return v2 +} From 40887c655fb5faf00fe002392ed656a13785d07b Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 4 Jan 2021 15:05:42 +0000 Subject: [PATCH 26/27] Upgrade shellexpand dep (#2529) The previous version depended on the deprecated `dirs` crate. --- Cargo.lock | 16 +++++++++++++--- deny.toml | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efe39c8699..dc2ec4c24e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -727,6 +727,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.5" @@ -1941,11 +1951,11 @@ dependencies = [ [[package]] name = "shellexpand" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2b22262a9aaf9464d356f656fea420634f78c881c5eebd5ef5e66d8b9bc603" +checksum = "83bdb7831b2d85ddf4a7b148aa19d0587eddbe8671a436b7bd1182eaad0f2829" dependencies = [ - "dirs", + "dirs-next", ] [[package]] diff --git a/deny.toml b/deny.toml index b690fa0a0e..37e5a3a0f8 100644 --- a/deny.toml +++ b/deny.toml @@ -14,7 +14,6 @@ vulnerability = "deny" unmaintained = "deny" yanked = "deny" ignore = [ - "RUSTSEC-2020-0053", # dirs is unmaintained ] # https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html From 4c7e66e58e97dea76759b02c1ecd23d34fc98848 Mon Sep 17 00:00:00 2001 From: hayasshi Date: Sat, 26 Dec 2020 17:22:12 +0900 Subject: [PATCH 27/27] Fix code in WASI-tutorial.md --- docs/WASI-tutorial.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/WASI-tutorial.md b/docs/WASI-tutorial.md index 2c5cc84bba..8a01ce5f19 100644 --- a/docs/WASI-tutorial.md +++ b/docs/WASI-tutorial.md @@ -121,14 +121,14 @@ use std::io::{Read, Write}; fn process(input_fname: &str, output_fname: &str) -> Result<(), String> { let mut input_file = - fs::File::open(input_fname).map_err(|err| format!("error opening input: {}", err))?; + fs::File::open(input_fname).map_err(|err| format!("error opening input {}: {}", input_fname, err))?; let mut contents = Vec::new(); input_file .read_to_end(&mut contents) .map_err(|err| format!("read error: {}", err))?; let mut output_file = fs::File::create(output_fname) - .map_err(|err| format!("error opening output '{}': {}", output_fname, err))?; + .map_err(|err| format!("error opening output {}: {}", output_fname, err))?; output_file .write_all(&contents) .map_err(|err| format!("write error: {}", err)) @@ -139,7 +139,7 @@ fn main() { let program = args[0].clone(); if args.len() < 3 { - eprintln!("{} ", program); + eprintln!("usage: {} ", program); return; }