diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml index 3db00c5e6..3d9387f3e 100644 --- a/.github/workflows/benchmark.yaml +++ b/.github/workflows/benchmark.yaml @@ -3,7 +3,7 @@ name: Run Benchmarks and upload results on: push: branches: - - master + - benchmark # TODO: change it back to master once we really track the results. We commented this as speed.wasmer.io is failing jobs: run_benchmark: diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c9295b377..ca01d29e4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -43,14 +43,14 @@ jobs: - build: linux-x64 os: ubuntu-18.04 rust: 1.48 - llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz' + llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/linux-amd64.tar.gz' artifact_name: 'wasmer-linux-amd64' cross_compilation_artifact_name: 'cross_compiled_from_linux' run_integration_tests: true - build: macos-x64 os: macos-latest rust: 1.48 - llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz' + llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/darwin-amd64.tar.gz' artifact_name: 'wasmer-darwin-amd64' cross_compilation_artifact_name: 'cross_compiled_from_mac' run_integration_tests: true @@ -62,7 +62,7 @@ jobs: - build: windows-x64 os: windows-latest rust: 1.48 - # llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz' + # llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/windows-amd64.tar.gz' artifact_name: 'wasmer-windows-amd64' cross_compilation_artifact_name: 'cross_compiled_from_win' run_integration_tests: true @@ -70,7 +70,7 @@ jobs: os: [self-hosted, linux, ARM64] random_sccache_port: true rust: 1.48 - llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz' + llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/linux-aarch64.tar.gz' artifact_name: 'wasmer-linux-aarch64' run_integration_tests: false env: @@ -108,9 +108,9 @@ jobs: mkdir ${{ env.LLVM_DIR }} tar xf llvm.tar.gz --strip-components=1 -C ${{ env.LLVM_DIR }} echo "${{ env.LLVM_DIR }}/bin" >> $GITHUB_PATH - echo "LLVM_SYS_100_PREFIX=${{ env.LLVM_DIR }}" >> $GITHUB_ENV + echo "LLVM_SYS_110_PREFIX=${{ env.LLVM_DIR }}" >> $GITHUB_ENV env: - LLVM_DIR: ${{ github.workspace }}/llvm-10 + LLVM_DIR: ${{ github.workspace }}/llvm-11 - name: Set up dependencies for Mac OS run: | brew install automake diff --git a/CHANGELOG.md b/CHANGELOG.md index ddede6f49..ca062340a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset` ### Fixed +- [#2084](https://github.com/wasmerio/wasmer/pull/2084) Avoid calling the function environment finalizer more than once when the environment has been cloned in the C API. - [#2069](https://github.com/wasmerio/wasmer/pull/2069) Use the new documentation for `include/README.md` in the Wasmer package. - [#2042](https://github.com/wasmerio/wasmer/pull/2042) Parse more exotic environment variables in `wasmer run`. - [#2041](https://github.com/wasmerio/wasmer/pull/2041) Documentation diagrams now have a solid white background rather than a transparent background. diff --git a/Cargo.lock b/Cargo.lock index a7da9c0db..7c1c8a915 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -971,9 +971,9 @@ dependencies = [ [[package]] name = "inkwell" -version = "0.1.0-llvm10sample" +version = "0.1.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e079c12273d96e41481454a37ad968e607e1ce51b39b9facd3a802a12df6e9dc" +checksum = "f5fe0be1e47c0c0f3da4397693e08f5d78329ae095c25d529e12ade78420fb41" dependencies = [ "either", "inkwell_internals", @@ -986,9 +986,9 @@ dependencies = [ [[package]] name = "inkwell_internals" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22cf4eda09069b48204cce4b7cd9a25311da813780e95a038524f2210fab44e" +checksum = "c2e1f71330ccec54ee62533ae88574c4169b67fb4b95cbb1196a1322582abd11" dependencies = [ "proc-macro2", "quote", @@ -1128,15 +1128,15 @@ dependencies = [ [[package]] name = "llvm-sys" -version = "100.2.0" +version = "110.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9109e19fbfac3458f2970189719fa19f1007c6fd4e08c44fdebf4be0ddbe261d" +checksum = "b0062a0c6635fb5d57c6ebba072dcae50e41651030363cf06d220b0d016840f2" dependencies = [ "cc", "lazy_static", "libc", "regex", - "semver 0.9.0", + "semver 0.11.0", ] [[package]] diff --git a/Makefile b/Makefile index bc1cf25a7..0e3b19ae2 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,7 @@ build-docs: build-docs-capi: cd lib/c-api/doc/deprecated/ && doxygen doxyfile - cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,jit,object-file,native,cranelift,wasi + cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,jit,object-file,native,cranelift,wasi $(capi_default_features) # We use cranelift as the default backend for the capi for now build-capi: build-capi-cranelift diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs index d7ae24181..e6020e35d 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -105,7 +105,7 @@ pub unsafe extern "C" fn wasm_func_new_with_env( #[repr(C)] struct WrapperEnv { env: *mut c_void, - finalizer: Option, + finalizer: Arc>, } // Only relevant when using multiple threads in the C API; @@ -115,8 +115,13 @@ pub unsafe extern "C" fn wasm_func_new_with_env( impl Drop for WrapperEnv { fn drop(&mut self) { - if let Some(finalizer) = self.finalizer { - unsafe { (finalizer)(self.env as _) } + if let Some(finalizer) = Arc::get_mut(&mut self.finalizer) + .map(Option::take) + .flatten() + { + if !self.env.is_null() { + unsafe { (finalizer)(self.env as _) } + } } } } @@ -160,7 +165,10 @@ pub unsafe extern "C" fn wasm_func_new_with_env( let function = Function::new_with_env( &store.inner, func_sig, - WrapperEnv { env, finalizer }, + WrapperEnv { + env, + finalizer: Arc::new(finalizer), + }, inner_callback, ); diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index 0baf3ae75..9ca253b50 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -24,9 +24,9 @@ itertools = "0.9" rayon = "1.5" [dependencies.inkwell] -version = "=0.1.0-llvm10sample" +version = "=0.1.0-beta.2" default-features = false -features = ["llvm10-0", "target-x86", "target-aarch64"] +features = ["llvm11-0", "target-x86", "target-aarch64"] [build-dependencies] cc = "1.0" diff --git a/lib/compiler-singlepass/src/codegen_x64.rs b/lib/compiler-singlepass/src/codegen_x64.rs index 9045cfcdc..eef73dd5e 100644 --- a/lib/compiler-singlepass/src/codegen_x64.rs +++ b/lib/compiler-singlepass/src/codegen_x64.rs @@ -5674,13 +5674,7 @@ impl<'a> FuncGen<'a> { ); self.emit_call_sysv( |this| { - let label = this.assembler.get_label(); - let after = this.assembler.get_label(); - this.assembler.emit_jmp(Condition::None, after); - this.assembler.emit_label(label); - this.assembler.emit_host_redirection(GPR::RAX); - this.assembler.emit_label(after); - this.assembler.emit_call_label(label); + this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, memory_index] iter::once(Location::Imm32(memory_index.index() as u32)), @@ -5719,13 +5713,7 @@ impl<'a> FuncGen<'a> { self.emit_call_sysv( |this| { - let label = this.assembler.get_label(); - let after = this.assembler.get_label(); - this.assembler.emit_jmp(Condition::None, after); - this.assembler.emit_label(label); - this.assembler.emit_host_redirection(GPR::RAX); - this.assembler.emit_label(after); - this.assembler.emit_call_label(label); + this.assembler.emit_call_register(GPR::RAX); }, // [vmctx, val, memory_index] iter::once(param_pages) diff --git a/lib/compiler-singlepass/src/emitter_x64.rs b/lib/compiler-singlepass/src/emitter_x64.rs index 17e1818d6..004a23861 100644 --- a/lib/compiler-singlepass/src/emitter_x64.rs +++ b/lib/compiler-singlepass/src/emitter_x64.rs @@ -205,6 +205,8 @@ pub trait Emitter { fn emit_call_label(&mut self, label: Self::Label); fn emit_call_location(&mut self, loc: Location); + fn emit_call_register(&mut self, reg: GPR); + fn emit_bkpt(&mut self); fn emit_host_redirection(&mut self, target: GPR); @@ -1389,6 +1391,10 @@ impl Emitter for Assembler { } } + fn emit_call_register(&mut self, reg: GPR) { + dynasm!(self ; call Rq(reg as u8)); + } + fn emit_bkpt(&mut self) { dynasm!(self ; int 0x3); } diff --git a/lib/wasi/README.md b/lib/wasi/README.md index 543a580f8..bcf54b299 100644 --- a/lib/wasi/README.md +++ b/lib/wasi/README.md @@ -20,8 +20,6 @@ let wasi_env = WasiState::new("command name") let import_object = wasi_env.import_object(&module)?; let instance = Instance::new(&module, &import_object)?; -wasi_env.set_memory(instance.exports.get_memory("memory")?.clone()); - let start = instance.exports.get_function("_start")?; start.call(&[])?; ```