summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2021-05-20 14:59:10 -0700
committerGitHub <noreply@github.com>2021-05-20 14:59:10 -0700
commitdede877475625fa37e86400e3f4db363b76cd151 (patch)
tree4149a48881ac4b48fcc8dcae1ddd026aaea64169
parent35f9da76d53401ba4de054f4db631ce4177b32f1 (diff)
downloadbinaryen-dede877475625fa37e86400e3f4db363b76cd151.tar.gz
binaryen-dede877475625fa37e86400e3f4db363b76cd151.tar.bz2
binaryen-dede877475625fa37e86400e3f4db363b76cd151.zip
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.
-rw-r--r--src/passes/PrintFunctionMap.cpp7
-rw-r--r--test/lit/wasm-split/symbolmap.wast6
2 files changed, 10 insertions, 3 deletions
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);
}
};
diff --git a/test/lit/wasm-split/symbolmap.wast b/test/lit/wasm-split/symbolmap.wast
index 4fe0f5291..b1be9531b 100644
--- a/test/lit/wasm-split/symbolmap.wast
+++ b/test/lit/wasm-split/symbolmap.wast
@@ -3,7 +3,9 @@
;; RUN: filecheck %s --check-prefix SECONDARY-MAP < %t.2.wasm.symbols
;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY
-;; PRIMARY-MAP: 0:bar
+;; PRIMARY-MAP: 0:placeholder_0
+;; PRIMARY-MAP: 1:placeholder_2
+;; PRIMARY-MAP: 2:bar
;; SECONDARY-MAP: 0:baz
;; SECONDARY-MAP: 1:foo
@@ -12,6 +14,8 @@
;; PRIMARY: (func $0
(module
+ (table $table 3 3 funcref)
+ (elem $table (i32.const 0) $foo $bar $baz)
(func $foo
(nop)
)