summaryrefslogtreecommitdiff
path: root/src/wasm-linker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-linker.cpp')
-rw-r--r--src/wasm-linker.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp
index 628e24ecc..3ff90cc0a 100644
--- a/src/wasm-linker.cpp
+++ b/src/wasm-linker.cpp
@@ -112,9 +112,30 @@ void Linker::layout() {
for (Name name : out.globls) exportFunction(name, false);
for (Name name : out.initializerFunctions) exportFunction(name, true);
+ // Pre-assign the function indexes
+ for (auto& pair : out.indirectIndexes) {
+ if (functionIndexes.count(pair.first) != 0 ||
+ functionNames.count(pair.second) != 0) {
+ Fatal() << "Function " << pair.first << " already has an index " <<
+ functionIndexes[pair.first] << " while setting index " << pair.second;
+ }
+ if (debug) {
+ std::cerr << "pre-assigned function index: " << pair.first << ": "
+ << pair.second << '\n';
+ }
+ functionIndexes[pair.first] = pair.second;
+ functionNames[pair.second] = pair.first;
+ }
+
+ // Emit the pre-assigned function names in sorted order
+ for (const auto& P : functionNames) {
+ out.wasm.table.names.push_back(P.second);
+ }
+
auto ensureFunctionIndex = [this](Name name) {
if (functionIndexes.count(name) == 0) {
functionIndexes[name] = out.wasm.table.names.size();
+ functionNames[functionIndexes[name]] = name;
out.wasm.table.names.push_back(name);
if (debug) {
std::cerr << "function index: " << name << ": "