Index: src/wasm/module-decoder.cc |
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc |
index f7d26a5f85645835a23965d52e4cc45db8bd9f3e..417d71fbe71ab44db3deea0d1a6b67c4177fd774 100644 |
--- a/src/wasm/module-decoder.cc |
+++ b/src/wasm/module-decoder.cc |
@@ -419,7 +419,9 @@ class ModuleDecoder : public Decoder { |
} |
done: |
- ModuleResult result = toResult(module); |
+ CalculateGlobalsOffsets(module); |
+ const WasmModule* finished_module = module; |
+ ModuleResult result = toResult(finished_module); |
if (FLAG_dump_wasm_module) { |
DumpModule(module, result); |
} |
@@ -570,6 +572,22 @@ class ModuleDecoder : public Decoder { |
consume_bytes(segment->source_size); |
} |
+ // Calculate individual global offsets and total size of globals table. |
+ void CalculateGlobalsOffsets(WasmModule* module) { |
+ uint32_t offset = 0; |
+ if (module->globals.size() == 0) { |
+ module->globals_size = 0; |
+ return; |
+ } |
+ for (WasmGlobal& global : module->globals) { |
+ byte size = WasmOpcodes::MemSize(global.type); |
+ offset = (offset + size - 1) & ~(size - 1); // align |
+ global.offset = offset; |
+ offset += size; |
+ } |
+ module->globals_size = offset; |
+ } |
+ |
// Verifies the body (code) of a given function. |
void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, |
WasmFunction* function) { |