-
Notifications
You must be signed in to change notification settings - Fork 830
Description
index.wat
(module
(import "env" "DYNAMICTOP_PTR" (global i32))
(global (mut i32) (global.get 0))
(func (export "_start") (;3480;)
global.get 1
drop
)
)(module
(global (export "DYNAMICTOP_PTR") i32 (i32.const 9568))
)~/binaryen-report/global_get_import wat2wasm index.wat && wat2wasm env.wat && wasm-merge index.wasm index env.wasm env -o merged.wasm && wasm2wat merged.wasm
merged.wasm:0000019: error: global variable out of range: 1 (max 1)It seems like in the resulting binary merged.wasm, global's initialization expression is still global.get 0, which is out of range. Reversing the two global declarations is also problematic with the error initializer expression can only reference an imported global.
(global (;0;) (mut i32) (global.get 1))
(global (;1;) i32 (i32.const 9568))Interestingly, if you remove the usage of global 1 at global.get 1, wasm-merge successfuly merges the globals, as below
(module
(type (;0;) (func))
(func (;0;) (type 0))
(global (;0;) i32 (i32.const 9568))
(export "_start" (func 0))
(export "DYNAMICTOP_PTR" (global 0)))Maybe it's not a bug and out of scope for wasm-merge, but as I thought wasm-merge should give at least a warning on this case , I am reporting now.
Code is also at this repo.
If this is a duplicate issue or non-issue, sorry in advance. Feel free to close the issue in that case.
I opened a separate issue with #6219 as there seems to be separate root cause, but if you feel like they should be consolidated please close this issue.