From dede877475625fa37e86400e3f4db363b76cd151 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Thu, 20 May 2021 14:59:10 -0700 Subject: Emit imported functions first in symbol maps (#3900) Imported functions come first when modules are emitted, so to ensure the function indices are correct, they need to come first in the symbol maps. We never noticed this bug before because imported functions are always the first functions when a module is parsed, so the bug never mattered in practice. However, wasm-split adds new imported functions after parsing and these were causing the symbol map indices to be incorrect. --- src/passes/PrintFunctionMap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/passes/PrintFunctionMap.cpp') diff --git a/src/passes/PrintFunctionMap.cpp b/src/passes/PrintFunctionMap.cpp index c2be0f3a2..325f4e48d 100644 --- a/src/passes/PrintFunctionMap.cpp +++ b/src/passes/PrintFunctionMap.cpp @@ -24,6 +24,7 @@ // 2:baz // +#include "ir/module-utils.h" #include "pass.h" #include "support/file.h" #include "wasm.h" @@ -40,9 +41,11 @@ struct PrintFunctionMap : public Pass { Output output(outFile, Flags::Text); auto& o = output.getStream(); Index i = 0; - for (auto& func : module->functions) { + auto write = [&](Function* func) { o << i++ << ':' << func->name.str << '\n'; - } + }; + ModuleUtils::iterImportedFunctions(*module, write); + ModuleUtils::iterDefinedFunctions(*module, write); } }; -- cgit v1.2.3