From 7bff209e0da1ea335cccfa9874fe830c49480eba Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 8 Feb 2021 11:48:35 -0800 Subject: Fix removal of EM_JS functions (#3552) The algorithm was trying to remove all __em_js functions but it was using the names of functions rather than export names so it was failing to remove these functions unless the internal function names happened to match (this turns out of the true for build with debug names). --- src/wasm/wasm-emscripten.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 8f0d4f9c8..96263f527 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -374,6 +374,7 @@ static AsmConstWalker fixEmAsmConstsAndReturnWalker(Module& wasm, struct EmJsWalker : public PostWalker { Module& wasm; std::vector
segmentOffsets; // segment index => address offset + std::vector toRemove; std::map codeByName; @@ -387,6 +388,7 @@ struct EmJsWalker : public PostWalker { if (!curr->name.startsWith(EM_JS_PREFIX.str)) { return; } + toRemove.push_back(*curr); auto* func = wasm.getFunction(curr->value); auto funcName = std::string(curr->name.stripPrefix(EM_JS_PREFIX.str)); // An EM_JS has a single const in the body. Typically it is just returned, @@ -407,15 +409,9 @@ EmJsWalker fixEmJsFuncsAndReturnWalker(Module& wasm) { EmJsWalker walker(wasm); walker.walkModule(&wasm); - std::vector toRemove; - for (auto& func : wasm.functions) { - if (func->name.startsWith(EM_JS_PREFIX.str)) { - toRemove.push_back(func->name); - } - } - for (auto funcName : toRemove) { - wasm.removeFunction(funcName); - wasm.removeExport(funcName); + for (const Export& exp : walker.toRemove) { + wasm.removeExport(exp.name); + wasm.removeFunction(exp.value); } return walker; } -- cgit v1.2.3