RemoveUnusedModuleElements drops an active elem segment whose items are global.get, so call_indirect traps
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in src/passes/RemoveUnusedModuleElements.cpp, especially Analyzer::prepare() and notePossibleFunc; the issue identifies the RefFunc-only check and the missing global.get handling. Read the existing pass tests for element segments and add a regression case based on the supplied WAT module. Done means the segment and referenced global are retained as needed, and optimized execution still returns 42 instead of trapping.
由索引模型根据 Issue 内容生成。
描述
An active element segment whose item is global.get (the "Initializing a table with imported funcref global" case in the spec's elem.wast) is removed by --remove-unused-module-elements and at -O1 and above. The table slot stays null and call_indirect traps.
;; b2.wat
(module
(type $f (func (result i32)))
(import "env" "g" (global $g funcref))
(table 1 funcref)
(elem (i32.const 0) funcref (global.get $g))
(func (export "call") (result i32)
(call_indirect (type $f) (i32.const 0))))
wasm-opt b2.wat --enable-reference-types --remove-unused-module-elements -S -o - prints:
(module
(type $f (func (result i32)))
(table $0 1 funcref)
(export "call" (func $0))
(func $0 (result i32)
(call_indirect $0 (type $f)
(i32.const 0)
)
)
)
The segment and the import are gone. Instantiated in Node.js 26.13.0 with env.g set to a function returning 42:
unoptimized: call() = 42
--remove-unused-module-elements: RuntimeError: function signature mismatch
-O1: RuntimeError: unreachable
The same happens when $g is a defined global initialized with ref.func (with --enable-gc).
Tested with wasm-opt version_133; on main (95a214dc48) the pass differs from version_133 only by the NFC renames in #9286/#9288.
In src/passes/RemoveUnusedModuleElements.cpp, notePossibleFunc in Analyzer::prepare() only looks at item->dynCast<RefFunc>(), so a segment with global.get items never gets into FlatTableInfo::typeElems and is considered unused.
Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.
Credit: https://ucsbplse.github.io/
- 主要语言
- WebAssembly
- 星标
- 8.7k
- 派生
- 905
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 86
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
WebAssembly/binaryen 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
WebAssembly/binaryen#9135 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 76/100
WebAssembly/binaryen#9018 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
WebAssembly/binaryen#9365 ·
维护者通常 1 天内回复
-
Add a pass to relax nullabilities of definitions可能已有人在做 @stevenfontanella 于 2 天前认领。 未关闭
WebAssembly/binaryen#9352 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
WebAssembly/binaryen#9307 · 2 条评论 ·
维护者通常 1 天内回复
查看 WebAssembly/binaryen 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
tree-sitter/tree-sitter-cpp#381 ·
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
new issue
难度 2/5 1-3 小时 新手友好度 72/100
llvm/llvm-project#240065 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
CanadaHonk/porffor#452 ·