summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp41
1 files changed, 15 insertions, 26 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 8357983b2..1fd87f2ea 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -994,11 +994,11 @@ struct FixInvokeFunctionNamesWalker
: public PostWalker<FixInvokeFunctionNamesWalker> {
Module& wasm;
std::map<Name, Name> importRenames;
- std::map<Name, Name> functionReplace;
+ std::vector<Name> toRemove;
+ std::set<Name> newImports;
std::set<Signature> invokeSigs;
- ImportInfo imports;
- FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm), imports(wasm) {}
+ FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm) {}
// Converts invoke wrapper names generated by LLVM backend to real invoke
// wrapper names that are expected by JavaScript glue code.
@@ -1053,38 +1053,27 @@ struct FixInvokeFunctionNamesWalker
return;
}
- BYN_TRACE("renaming import: " << curr->module << "." << curr->base << " ("
- << curr->name << ") -> " << newname << "\n");
- assert(importRenames.count(curr->base) == 0);
- importRenames[curr->base] = newname;
- // Either rename the import, or replace it with an existing one
- Function* existingFunc = imports.getImportedFunction(curr->module, newname);
- if (existingFunc) {
- BYN_TRACE("replacing with an existing import: " << existingFunc->name
- << "\n");
- functionReplace[curr->name] = existingFunc->name;
+ assert(importRenames.count(curr->name) == 0);
+ BYN_TRACE("renaming: " << curr->name << " -> " << newname << "\n");
+ importRenames[curr->name] = newname;
+ // Either rename or remove the existing import
+ if (wasm.getFunctionOrNull(newname) || !newImports.insert(newname).second) {
+ toRemove.push_back(curr->name);
} else {
- BYN_TRACE("renaming the import in place\n");
curr->base = newname;
+ curr->name = newname;
}
}
void visitModule(Module* curr) {
- // For each replaced function first remove the function itself then
- // rename all uses to the point to the new function.
- for (auto& pair : functionReplace) {
- BYN_TRACE("removeFunction " << pair.first << "\n");
- wasm.removeFunction(pair.first);
+ for (auto importName : toRemove) {
+ wasm.removeFunction(importName);
}
- // Rename all uses of the removed functions
- ModuleUtils::renameFunctions(wasm, functionReplace);
-
- // For imports that for renamed, update any associated GOT.func imports.
+ ModuleUtils::renameFunctions(wasm, importRenames);
+ ImportInfo imports(wasm);
for (auto& pair : importRenames) {
- BYN_TRACE("looking for: GOT.func." << pair.first << "\n");
+ // Update any associated GOT.func import.
if (auto g = imports.getImportedGlobal("GOT.func", pair.first)) {
- BYN_TRACE("renaming corresponding GOT entry: " << g->base << " -> "
- << pair.second << "\n");
g->base = pair.second;
}
}