diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b660818..20432fe83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** - [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace` +- [#817](https://github.com/wasmerio/wasmer/pull/817) Add document for tracking features across backends and language integrations, [docs/feature_matrix.md] +- [#823](https://github.com/wasmerio/wasmer/issues/823) Improved Emscripten / WASI integration +- [#821](https://github.com/wasmerio/wasmer/issues/821) Remove patch version on most deps Cargo manifests. This gives Wasmer library users more control over which versions of the deps they use. - [#820](https://github.com/wasmerio/wasmer/issues/820) Remove null-pointer checks in `WasmPtr` from runtime-core, re-add them in Emscripten - [#803](https://github.com/wasmerio/wasmer/issues/803) Add method to `Ctx` to invoke functions by their `TableIndex` - [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model. diff --git a/Cargo.toml b/Cargo.toml index 06b2c2854..d433ad456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ include = [ ] [dependencies] -byteorder = "1.3.2" -errno = "0.2.4" -structopt = "0.3.0" +byteorder = "1.3" +errno = "0.2" +structopt = "0.3" wabt = "0.9.1" wasmer-clif-backend = { path = "lib/clif-backend" } wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true } @@ -63,8 +63,8 @@ members = [ [build-dependencies] wabt = "0.9.1" -glob = "0.3.0" -rustc_version = "0.2.3" +glob = "0.3" +rustc_version = "0.2" [dev-dependencies] serde = { version = "1", features = ["derive"] } # used by the plugin example diff --git a/Makefile b/Makefile index 5eb9c9aa2..905b54190 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,14 @@ # Generate files generate-spectests: - WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime-core --release + WASMER_RUNTIME_GENERATE_SPECTESTS=1 cargo build -p wasmer-runtime-core --release \ + && echo "formatting" \ + && cargo fmt generate-emtests: - WASM_EMSCRIPTEN_GENERATE_EMTESTS=1 cargo build -p wasmer-emscripten-tests --release + WASM_EMSCRIPTEN_GENERATE_EMTESTS=1 cargo build -p wasmer-emscripten-tests --release \ + && echo "formatting" \ + && cargo fmt generate-wasitests: wasitests-setup WASM_WASI_GENERATE_WASITESTS=1 cargo build -p wasmer-wasi-tests --release -vv \ diff --git a/docs/feature_matrix.md b/docs/feature_matrix.md new file mode 100644 index 000000000..6931c38b4 --- /dev/null +++ b/docs/feature_matrix.md @@ -0,0 +1,26 @@ +# Feature Table + +## Compiler Backend + +|   | Singlepass | Cranelift | LLVM | +| - | - | - | - | +| Caching | ❌ | ✅ | ✅ | +| Emscripten | ✅ | ✅ | ✅ | +| Metering | ✅ | ❌ | ✅ | +| Multi-value return | ❌ | ❌ | ❌ | +| OSR | 🚧 | ❓ | ❓ | +| SIMD | ❌ | ❌ | ✅ | +| WASI | ✅ | ✅ | ✅ | + + +## Language integration + +TODO: define a set of features that are relevant and mark them here + +Current ideas: + +- WASI FS API +- Callbacks +- Exiting early in hostcall +- Metering +- Caching diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index be48208c7..3b662358d 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -15,26 +15,26 @@ cranelift-codegen = { version = "0.31" } cranelift-entity = { version = "0.31" } cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.33" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.33" } -target-lexicon = "0.4.0" +target-lexicon = "0.4" wasmparser = "0.35.1" -byteorder = "1.3.2" -nix = "0.15.0" +byteorder = "1.3" +nix = "0.15" libc = "0.2.60" -rayon = "1.1.0" +rayon = "1.1" # Dependencies for caching. [dependencies.serde] -version = "1.0.99" +version = "1.0" features = ["rc"] [dependencies.serde_derive] -version = "1.0.98" +version = "1.0" [dependencies.serde_bytes] -version = "0.11.2" +version = "0.11" [dependencies.serde-bench] version = "0.0.7" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] } +winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] } wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.7.0" } [features] diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index 8c5f6c93e..2954e84fb 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -20,7 +20,7 @@ wabt = "0.9.1" wasmer-dev-utils = { path = "../dev-utils", version = "0.7.0"} [build-dependencies] -glob = "0.3.0" +glob = "0.3" [features] clif = [] diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index f547e640e..f5b6222b2 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -8,14 +8,14 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -byteorder = "1.3.2" -lazy_static = "1.4.0" +byteorder = "1.3" +lazy_static = "1.4" libc = "0.2.60" -time = "0.1.42" +time = "0.1" wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } [target.'cfg(windows)'.dependencies] -rand = "0.7.0" +rand = "0.7" [features] debug = ["wasmer-runtime-core/debug"] diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 727405381..e0be391a7 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -735,8 +735,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "___syscall345" => func!(crate::syscalls::___syscall345), // Process - "abort" => func!(crate::process::em_abort), + "abort" => func!(crate::process::_abort), "_abort" => func!(crate::process::_abort), + "_prctl" => func!(crate::process::_prctl), "abortStackOverflow" => func!(crate::process::abort_stack_overflow), "_llvm_trap" => func!(crate::process::_llvm_trap), "_fork" => func!(crate::process::_fork), @@ -829,6 +830,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject "_gmtime" => func!(crate::time::_gmtime), // Math + "sqrt" => func!(crate::math::sqrt), + "floor" => func!(crate::math::floor), + "fabs" => func!(crate::math::fabs), "f64-rem" => func!(crate::math::f64_rem), "_llvm_copysign_f32" => func!(crate::math::_llvm_copysign_f32), "_llvm_copysign_f64" => func!(crate::math::_llvm_copysign_f64), diff --git a/lib/emscripten/src/math.rs b/lib/emscripten/src/math.rs index 3aea6f8b7..914411ee9 100644 --- a/lib/emscripten/src/math.rs +++ b/lib/emscripten/src/math.rs @@ -88,6 +88,21 @@ pub fn log(_ctx: &mut Ctx, value: f64) -> f64 { value.ln() } +// emscripten: global.Math sqrt +pub fn sqrt(_ctx: &mut Ctx, value: f64) -> f64 { + value.sqrt() +} + +// emscripten: global.Math floor +pub fn floor(_ctx: &mut Ctx, value: f64) -> f64 { + value.floor() +} + +// emscripten: global.Math fabs +pub fn fabs(_ctx: &mut Ctx, value: f64) -> f64 { + value.abs() +} + // emscripten: asm2wasm.f64-to-int pub fn f64_to_int(_ctx: &mut Ctx, value: f64) -> i32 { debug!("emscripten::f64_to_int {}", value); diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index cd083e943..a776734b4 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -1,11 +1,10 @@ -use libc::{abort, c_char, c_int, exit, EAGAIN}; +use libc::{abort, c_int, exit, EAGAIN}; #[cfg(not(target_os = "windows"))] type PidT = libc::pid_t; #[cfg(target_os = "windows")] type PidT = c_int; -use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; pub fn abort_with_message(ctx: &mut Ctx, message: &str) { @@ -21,6 +20,12 @@ pub fn _abort(_ctx: &mut Ctx) { } } +pub fn _prctl(ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { + debug!("emscripten::_prctl"); + abort_with_message(ctx, "missing function: prctl"); + -1 +} + pub fn _fork(_ctx: &mut Ctx) -> PidT { debug!("emscripten::_fork"); // unsafe { @@ -45,18 +50,6 @@ pub fn _exit(_ctx: &mut Ctx, status: c_int) { unsafe { exit(status) } } -pub fn em_abort(ctx: &mut Ctx, message: u32) { - debug!("emscripten::em_abort {}", message); - let message_addr = emscripten_memory_pointer!(ctx.memory(0), message) as *mut c_char; - unsafe { - let message = CStr::from_ptr(message_addr) - .to_str() - .unwrap_or("Unexpected abort"); - - abort_with_message(ctx, message); - } -} - pub fn _kill(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { debug!("emscripten::_kill"); -1 diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 2585af43f..e1c403565 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -24,7 +24,9 @@ pub fn is_emscripten_module(module: &Module) -> bool { .namespace_table .get(import_name.namespace_index); let field = module.info().name_table.get(import_name.name_index); - if (field == "_emscripten_memcpy_big" || field == "emscripten_memcpy_big") + if (field == "_emscripten_memcpy_big" + || field == "emscripten_memcpy_big" + || field == "__map_file") && namespace == "env" { return true; diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index ca4e1e51e..2e198a6c3 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -8,10 +8,10 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmparser = "0.35.1" -smallvec = "0.6.10" +smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" -capstone = { version = "0.6.0", optional = true } +capstone = { version = "0.6", optional = true } byteorder = "1" [dependencies.inkwell] @@ -21,17 +21,17 @@ default-features = false features = ["llvm8-0", "target-x86"] [target.'cfg(unix)'.dependencies] -nix = "0.15.0" +nix = "0.15" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["memoryapi"] } +winapi = { version = "0.3", features = ["memoryapi"] } [build-dependencies] cc = "1.0" -lazy_static = "1.4.0" -regex = "1.2.1" +lazy_static = "1.4" +regex = "1.2" semver = "0.9" -rustc_version = "0.2.3" +rustc_version = "0.2" [dev-dependencies] wabt = "0.9.1" diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 8aac30da3..bcfa4bec5 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -32,4 +32,4 @@ llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] [build-dependencies] -cbindgen = "0.9.1" +cbindgen = "0.9" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 9349a7c64..f683a974e 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -8,46 +8,46 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -nix = "0.15.0" -page_size = "0.4.1" +nix = "0.15" +page_size = "0.4" wasmparser = "0.35.1" -parking_lot = "0.9.0" -lazy_static = "1.4.0" -errno = "0.2.4" +parking_lot = "0.9" +lazy_static = "1.4" +errno = "0.2" libc = "0.2.60" -hex = "0.3.2" -smallvec = "0.6.10" +hex = "0.3" +smallvec = "0.6" bincode = "1.1" [dependencies.indexmap] -version = "1.2.0" +version = "1.2" features = ["serde-1"] # Dependencies for caching. [dependencies.serde] -version = "1.0.99" +version = "1.0" # This feature is required for serde to support serializing/deserializing reference counted pointers (e.g. Rc and Arc). features = ["rc"] [dependencies.serde_derive] -version = "1.0.98" +version = "1.0" [dependencies.serde_bytes] -version = "0.11.2" +version = "0.11" [dependencies.serde-bench] version = "0.0.7" [dependencies.blake2b_simd] -version = "0.5.8" +version = "0.5" [dependencies.digest] -version = "0.8.1" +version = "0.8" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["memoryapi"] } +winapi = { version = "0.3", features = ["memoryapi"] } [dev-dependencies] -field-offset = "0.1.1" +field-offset = "0.1" [build-dependencies] -blake2b_simd = "0.5.8" -rustc_version = "0.2.3" +blake2b_simd = "0.5" +rustc_version = "0.2" cc = "1.0" [features] diff --git a/lib/runtime-core/image-loading-linux-x86-64.s b/lib/runtime-core/image-loading-linux-x86-64.s index 1d86bab08..859f010f8 100644 --- a/lib/runtime-core/image-loading-linux-x86-64.s +++ b/lib/runtime-core/image-loading-linux-x86-64.s @@ -81,7 +81,7 @@ pushq %r8 pushq %r9 pushq %r10 -callq get_boundary_register_preservation +callq get_boundary_register_preservation@PLT # Keep this consistent with BoundaryRegisterPreservation movq %r15, 0(%rax) diff --git a/lib/runtime-core/src/structures/map.rs b/lib/runtime-core/src/structures/map.rs index add5b0257..2d4f3323e 100644 --- a/lib/runtime-core/src/structures/map.rs +++ b/lib/runtime-core/src/structures/map.rs @@ -39,6 +39,10 @@ where self.elems.len() } + pub fn is_empty(&self) -> bool { + self.elems.is_empty() + } + pub fn push(&mut self, value: V) -> K { let len = self.len(); self.elems.push(value); diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 2321cf996..29b90955e 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -10,8 +10,8 @@ readme = "README.md" [dependencies] wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.7.0", optional = true } -lazy_static = "1.4.0" -memmap = "0.7.0" +lazy_static = "1.4" +memmap = "0.7" [dependencies.wasmer-runtime-core] path = "../runtime-core" @@ -23,7 +23,7 @@ version = "0.7.0" optional = true [dev-dependencies] -tempfile = "3.1.0" +tempfile = "3.1" criterion = "0.2" wabt = "0.9.1" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 65bfd54bc..f90afad12 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -13,8 +13,8 @@ wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmparser = "0.35.1" dynasm = "0.3.2" dynasmrt = "0.3.1" -lazy_static = "1.4.0" -byteorder = "1.3.2" -nix = "0.15.0" +lazy_static = "1.4" +byteorder = "1.3" +nix = "0.15" libc = "0.2.60" -smallvec = "0.6.10" +smallvec = "0.6" diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index feab4eccb..7b3e6adbe 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] -glob = "0.3.0" +glob = "0.3" wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } wasmer-clif-backend = { path = "../clif-backend", version = "0.7.0" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.7.0", optional = true } diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 7b0927101..9462fc731 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -18,7 +18,7 @@ wasmer-llvm-backend = { path = "../llvm-backend", version = "0.7.0", optional = [build-dependencies] -glob = "0.3.0" +glob = "0.3" [dev-dependencies] wasmer-clif-backend = { path = "../clif-backend", version = "0.7.0" } diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 70bdd6996..af65b65e8 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -9,16 +9,16 @@ edition = "2018" [dependencies] bincode = "1" -byteorder = "1.3.2" -generational-arena = { version = "0.2.2", features = ["serde"] } +byteorder = "1.3" +generational-arena = { version = "0.2", features = ["serde"] } libc = "0.2.60" -log = "0.4.8" -rand = "0.7.0" -time = "0.1.42" +log = "0.4" +rand = "0.7" +time = "0.1" typetag = "0.1" serde = { version = "1", features = ["derive"] } # wasmer-runtime-abi = { path = "../runtime-abi" } wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" } [target.'cfg(windows)'.dependencies] -winapi = "0.3.8" +winapi = "0.3" diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 4c3680be2..f96e35958 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -2,14 +2,17 @@ use wasmer_runtime_core::module::Module; /// Check if a provided module is compiled with WASI support pub fn is_wasi_module(module: &Module) -> bool { + if module.info().imported_functions.is_empty() { + return false; + } for (_, import_name) in &module.info().imported_functions { let namespace = module .info() .namespace_table .get(import_name.namespace_index); - if namespace == "wasi_unstable" { - return true; + if namespace != "wasi_unstable" { + return false; } } - false + true } diff --git a/lib/win-exception-handler/Cargo.toml b/lib/win-exception-handler/Cargo.toml index dd67b6733..4254ee5ae 100644 --- a/lib/win-exception-handler/Cargo.toml +++ b/lib/win-exception-handler/Cargo.toml @@ -13,6 +13,6 @@ winapi = { version = "0.3.8", features = ["winbase", "errhandlingapi", "minwinde libc = "0.2.60" [build-dependencies] -cmake = "0.1.40" -bindgen = "0.51.0" -regex = "1.2.1" +cmake = "0.1" +bindgen = "0.51" +regex = "1.2" diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 659f53c71..cbbea3b6b 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -512,7 +512,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { import_object.allow_missing_functions = true; // Import initialization might be left to the loader. let instance = module .instantiate(&import_object) - .map_err(|e| format!("Can't instantiate module: {:?}", e))?; + .map_err(|e| format!("Can't instantiate loader module: {:?}", e))?; let args: Vec = options .args @@ -551,7 +551,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals); let mut instance = module .instantiate(&import_object) - .map_err(|e| format!("Can't instantiate module: {:?}", e))?; + .map_err(|e| format!("Can't instantiate emscripten module: {:?}", e))?; wasmer_emscripten::run_emscripten_instance( &module, @@ -591,7 +591,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { #[allow(unused_mut)] // mut used in feature let mut instance = module .instantiate(&import_object) - .map_err(|e| format!("Can't instantiate module: {:?}", e))?; + .map_err(|e| format!("Can't instantiate WASI module: {:?}", e))?; let start: Func<(), ()> = instance.func("_start").map_err(|e| format!("{:?}", e))?; @@ -752,7 +752,7 @@ fn run(options: Run) { match execute_wasm(&options) { Ok(()) => {} Err(message) => { - eprintln!("execute_wasm: {:?}", message); + eprintln!("Error: {}", message); exit(1); } }