diff options
Diffstat (limited to 'src/wasm-emscripten.cpp')
-rw-r--r-- | src/wasm-emscripten.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/wasm-emscripten.cpp b/src/wasm-emscripten.cpp index e8f0194d3..99115fae9 100644 --- a/src/wasm-emscripten.cpp +++ b/src/wasm-emscripten.cpp @@ -57,8 +57,20 @@ static bool hasI64ResultOrParam(FunctionType* ft) { return false; } +void removeImportsWithSubstring(Module& module, Name name) { + std::vector<Name> toRemove; + for (auto& import : module.imports) { + if (import->name.hasSubstring(name)) { + toRemove.push_back(import->name); + } + } + for (auto importName : toRemove) { + module.removeImport(importName); + } +} + std::vector<Function*> makeDynCallThunks(Module& wasm, std::vector<Name> const& tableSegmentData) { - wasm.removeImport(EMSCRIPTEN_ASM_CONST); // we create _sig versions + removeImportsWithSubstring(wasm, EMSCRIPTEN_ASM_CONST); // we create _sig versions std::vector<Function*> generatedFunctions; std::unordered_set<std::string> sigs; @@ -103,7 +115,7 @@ struct AsmConstWalker : public PostWalker<AsmConstWalker, Visitor<AsmConstWalker }; void AsmConstWalker::visitCallImport(CallImport* curr) { - if (curr->target == EMSCRIPTEN_ASM_CONST) { + if (curr->target.hasSubstring(EMSCRIPTEN_ASM_CONST)) { auto arg = curr->operands[0]->cast<Const>(); auto address = arg->value.geti32(); auto segmentIterator = segmentsByAddress.find(address); @@ -122,7 +134,14 @@ void AsmConstWalker::visitCallImport(CallImport* curr) { } else { id = ids[code]; } - std::string sig = getSig(curr); + std::string baseSig = getSig(curr); + std::string sig = ""; + for (size_t i = 0; i < baseSig.size(); ++i) { + // Omit the signature of the "code" parameter, taken as a string, as the first argument + if (i != 1) { + sig += baseSig[i]; + } + } sigsForCode[code].insert(sig); std::string fixedTarget = EMSCRIPTEN_ASM_CONST.str + std::string("_") + sig; curr->target = cashew::IString(fixedTarget.c_str(), false); |