Enable bulk-memory copy/fill opcodes in WAMR#16
Open
e-fu wants to merge 3 commits into
Open
Conversation
Go's GOOS=js GOARCH=wasm compiler (and TinyGo, Rust wasm-bindgen) emit bulk-memory opcodes unconditionally. WASM_ENABLE_BULK_MEMORY and WASM_ENABLE_REF_TYPES were already set via -D in native.ex, but the _OPT sub-feature gating memory.copy (fc 0a) / memory.fill (fc 0b) was not, so any such module failed to instantiate with 'unsupported opcode fc 0a'. Add -DWASM_ENABLE_BULK_MEMORY_OPT=1 beside the existing flags (the build's single source of truth; the vendored config.h #ifndef defaults are overridden by these -D defines). Regression test runs a module exercising all four bulk-memory opcodes (memory.fill/copy/init + data.drop) via both the native WASM API and the JS WebAssembly API, asserting run() == 43998.
There was a problem hiding this comment.
Pull request overview
Enables WAMR’s bulk-memory “_OPT” feature gate so memory.copy / memory.fill opcodes (emitted unconditionally by common WASM toolchains like Go/TinyGo/wasm-bindgen) are accepted by QuickBEAM’s embedded WASM runtime, and adds regression coverage to prevent future breakage.
Changes:
- Enable
WASM_ENABLE_BULK_MEMORY_OPT=1in the WAMR C compilation flags used by the native NIF build. - Add a regression WASM fixture plus tests that exercise all bulk-memory opcodes via both
QuickBEAM.WASMand the JSWebAssemblyAPI. - Document the change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/wasm_test.exs | Adds a bulk-memory opcode fixture and regression tests for both the native WASM API and JS WebAssembly.instantiate. |
| lib/quickbeam/native.ex | Enables WASM_ENABLE_BULK_MEMORY_OPT in WAMR build flags so memory.copy/memory.fill are supported. |
| CHANGELOG.md | Notes the newly enabled bulk-memory opcode support and the previously observed failure mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+500
to
+504
| @bulk_memory_wasm <<0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 127, 3, 2, 1, 0, 5, 3, 1, 0, | ||
| 1, 7, 13, 2, 3, 109, 101, 109, 2, 0, 3, 114, 117, 110, 0, 0, 12, 1, 1, 10, | ||
| 56, 1, 54, 0, 65, 0, 65, 171, 1, 65, 16, 252, 11, 0, 65, 228, 0, 65, 0, 65, | ||
| 16, 252, 10, 0, 0, 65, 200, 1, 65, 0, 65, 4, 252, 8, 0, 0, 252, 9, 0, 65, | ||
| 228, 0, 45, 0, 0, 65, 128, 2, 108, 65, 200, 1, 45, 0, 0, 106, 11, 11, 7, 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Go's
GOOS=js GOARCH=wasmcompiler — and TinyGo, Rustwasm-bindgen— emit bulk-memory opcodes unconditionally.WASM_ENABLE_BULK_MEMORYandWASM_ENABLE_REF_TYPESwere already set via-Dinnative.ex, but the_OPTsub-feature gatingmemory.copy(fc 0a) /memory.fill(fc 0b) was not. As a result any such module fails to instantiate withunsupported opcode fc 0a.Fix
Add
-DWASM_ENABLE_BULK_MEMORY_OPT=1beside the existing flags inlib/quickbeam/native.ex(the build's single source of truth; the vendoredconfig.h#ifndefdefaults are overridden by these-Ddefines).Test
A regression test runs a hand-assembled module exercising all four bulk-memory opcodes (
memory.fill/copy/init+data.drop) via both the native WASM API and the JSWebAssemblyAPI, assertingrun() == 43998(load8_u(100)*256 + load8_u(200)=0xAB*256 + 0xDE). Without the flag the module fails to compile withunsupported opcode fc 0a.Verification
CI was run on a downstream fork (the canonical CI setup) before opening this PR — all four jobs green on the same commit:
test (27.0, 1.18)— NIF built from source on Linux + full suite incl. the bulk-memory regression testUBSan + Zig DebugAddressSanitizerC static analysisRun: https://github.com/ZenHive/quickbeam/actions/runs/27730829659