From da4e17d827c444bbbcceb08d577c528020d4d959 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 16 Apr 2021 17:55:35 -0700 Subject: LegalizeJSInterface: Remove illegal imports once they are no longer used (#3815) This prevents used imports which also happen to have duplicate names and therefore cannot be provided by wasm (JS is happen to fill these in with polymorphic JS functions). I noticed this when working on emscripten and directly hooking modules together. I was seeing failures, but not in release builds (because wasm-opt would mop these up in release builds). --- src/passes/LegalizeJSInterface.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/passes/LegalizeJSInterface.cpp') diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index e840e375b..10e751701 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -144,6 +144,11 @@ struct LegalizeJSInterface : public Pass { Fixer fixer(&illegalImportsToLegal); fixer.run(runner, module); fixer.walkModuleCode(module); + + // Finally we can remove all the now-unused illegal imports + for (const auto& pair : illegalImportsToLegal) { + module->removeFunction(pair.first); + } } } -- cgit v1.2.3