Wasm GC: global.get in initializer expression can access preceding global definitions
Categories
(Core :: JavaScript: WebAssembly, defect, P1)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox120 | --- | fixed |
People
(Reporter: jerome, Assigned: yury)
References
Details
Attachments
(1 file)
Steps to reproduce:
I have a Web assembly program that contains global definitions that refers to previous global definitions.
Actual results:
I get this error message in the console:
CompileError: wasm validation error: at offset 21410: global.get in initializer expression must reference a global immutable import
Expected results:
This should be allowed. (It works in Chrome 119.)
The GC proposal states the following:
"global.get is a constant instruction and can access preceding (immutable) global definitions, not just imports as in the MVP"
(https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md)
| Assignee | ||
Comment 1•2 years ago
|
||
The following wasm code doesn't trigger the validation error:
(module
(global $g i32 (i32.const 1))
(global $g2 i32 (global.get $g))
)
Can you provide the minimal example that fails the validation?
| Assignee | ||
Comment 2•2 years ago
|
||
I think that
(module
(import "" "d" (global $g0 i32))
(global $g i32 (i32.const 1))
(global $g2 (mut i32) (global.get $g))
)
is the test case, but I want to make sure before changing the title
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Updated•2 years ago
|
Here are two other different test cases, which do not involve mutable globals.
(module
(import "xx" "d" (global $g0 i32))
(global $int i32 (i32.const 251))
(global $tbl2 (ref i31) (ref.i31
(global.get $int)
))
)
(module
(import "xx" "d" (global $g0 i32))
(type $block (array (ref eq)))
(global $len i32 (i32.const 256))
(global $tbl (ref $block) (array.new $block
(ref.i31
(i32.const 0)
)
(global.get $len)
))
)
Comment 4•2 years ago
|
||
It looks like the arithmetic around valid globals for global.get is screwed up when there imported globals [1]. We should be adding the amount of imported globals to i.
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 5•2 years ago
|
||
Change validation logic and cleanup around DecodeConstantExpression.
Comment 7•2 years ago
|
||
| bugherder | ||
Description
•