From f5d0aa800e45488aa2277e97edf9383722c00969 Mon Sep 17 00:00:00 2001 From: "Alon Zakai (kripken)" Date: Wed, 4 Jan 2017 16:43:40 -0800 Subject: ensure exports are added deterministically from binaries --- src/wasm-binary.h | 1 + src/wasm/wasm-binary.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 1edd3fa12..81755905c 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -690,6 +690,7 @@ public: void readFunctions(); std::map exportIndexes; + std::vector exportOrder; void readExports(); Expression* readExpression(); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ebbc5a8ee..1d5ee1ff1 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1271,6 +1271,7 @@ void WasmBinaryBuilder::readExports() { curr->kind = (ExternalKind)getU32LEB(); auto index = getU32LEB(); exportIndexes[curr] = index; + exportOrder.push_back(curr); } } @@ -1346,16 +1347,16 @@ void WasmBinaryBuilder::processFunctions() { wasm.start = getFunctionIndexName(startIndex); } - for (auto& iter : exportIndexes) { - Export* curr = iter.first; + for (auto* curr : exportOrder) { + auto index = exportIndexes[curr]; switch (curr->kind) { case ExternalKind::Function: { - curr->value = getFunctionIndexName(iter.second); + curr->value = getFunctionIndexName(index); break; } case ExternalKind::Table: curr->value = Name::fromInt(0); break; case ExternalKind::Memory: curr->value = Name::fromInt(0); break; - case ExternalKind::Global: curr->value = getGlobalName(iter.second); break; + case ExternalKind::Global: curr->value = getGlobalName(index); break; default: WASM_UNREACHABLE(); } wasm.addExport(curr); -- cgit v1.2.3