diff options
author | Sam Clegg <sbc@chromium.org> | 2021-02-08 11:48:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-08 11:48:35 -0800 |
commit | 7bff209e0da1ea335cccfa9874fe830c49480eba (patch) | |
tree | 5f2ee61a07055202a7390858a9fbd705e1c94f69 /src | |
parent | d4e31719c6609e121d5bb6758e1b9d3335113755 (diff) | |
download | binaryen-7bff209e0da1ea335cccfa9874fe830c49480eba.tar.gz binaryen-7bff209e0da1ea335cccfa9874fe830c49480eba.tar.bz2 binaryen-7bff209e0da1ea335cccfa9874fe830c49480eba.zip |
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).
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
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<EmJsWalker> { Module& wasm; std::vector<Address> segmentOffsets; // segment index => address offset + std::vector<Export> toRemove; std::map<std::string, std::string> codeByName; @@ -387,6 +388,7 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { 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<Name> 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; } |