Emit declarative element segments for ref.func references in WasmGC#13156
Open
zacharywhitley wants to merge 1 commit intooracle:masterfrom
Open
Emit declarative element segments for ref.func references in WasmGC#13156zacharywhitley wants to merge 1 commit intooracle:masterfrom
zacharywhitley wants to merge 1 commit intooracle:masterfrom
Conversation
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA). To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
5 tasks
The WebAssembly spec requires that functions referenced by ref.func
outside of active/passive element segments must be declared in a
declarative element segment (elem declare func ...).
Add a RefFuncCollector visitor that scans all function bodies and
global initializers for ref.func instructions, then emits a single
declarative element segment in the WAT output.
This fixes validation errors from wasm-tools validate and wasmtime
("undeclared function reference") that occurred because the WasmGC
heap initialization code uses ref.func for DynamicHub newInstance
and clone function pointers without declaring them.
cf05b8d to
91ac152
Compare
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.
Summary
The WebAssembly spec requires that functions referenced by
ref.funcoutside of active/passive element segments must be declared in a declarative element segment (elem declare func ...). The WasmGC backend usesref.funcin heap initialization code (DynamicHubnewInstanceandclonefunction pointers) but never emits the required declarations.This causes validation failures with strict validators:
wasm-tools validatereports "undeclared function reference"wasmtimerejects modules assembled bywasm-tools parsewasm-assilently adds declarations, masking the issueChanges
declarativeFuncRefsset toWasmModuleto track functions needing declarative element segmentsRefFuncCollectorvisitor inWasmPrinterthat scans all function bodies, globals, and table initializers forref.funcinstructions(elem declare func ...)in the WAT output with all collected referencesThe fix is general — it handles any current or future
ref.funcusage automatically, not just the heap initialization paths.Test plan
wasm-tools validate --features allpasses on WasmGC outputwasm-tools parsesuccessfully assembles WasmGC WAT to binary