Fix linked global initialization in multimodule (#3905)

While resolving linked globals in multi-module mode, WAMR tries to copy
the linked global's initial value into the destination global in the
current module.  However, a bug in the implementation causes the copy to
be done from the InitializerExpression struct, not from its WASMValue
field.

This did not come up in WAMR's spec test runner because those are built
with WASM_ENABLE_SPEC_TEST, which means these globals are resolved as
builtins, not linked globals, which goes through a different (presumably
not faulty) path.
This commit is contained in:
James Ring 2024-11-12 22:52:27 -08:00 committed by GitHub
parent 58f242f357
commit fdda259d36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1209,7 +1209,7 @@ globals_instantiate(WASMModule *module, WASMModuleInstance *module_inst,
/* The linked global instance has been initialized, we
just need to copy the value. */
bh_memcpy_s(&(global->initial_value), sizeof(WASMValue),
&(global_import->import_global_linked->init_expr),
&(global_import->import_global_linked->init_expr.u),
sizeof(WASMValue));
}
else