summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2023-06-23 09:57:47 -0700
committerGitHub <noreply@github.com>2023-06-23 16:57:47 +0000
commit1545deb41194b205c6aba4e940f3db56cdec795f (patch)
treea2e507ee6afa10447f73d00c5544636a0b39ead2 /src
parent34c10dca94a4690a27fd89a7c56bddeb9ac7f858 (diff)
downloadbinaryen-1545deb41194b205c6aba4e940f3db56cdec795f.tar.gz
binaryen-1545deb41194b205c6aba4e940f3db56cdec795f.tar.bz2
binaryen-1545deb41194b205c6aba4e940f3db56cdec795f.zip
PostEmscripten: Preserve __em_js__ exports in side modules (#5780)
Diffstat (limited to 'src')
-rw-r--r--src/passes/PostEmscripten.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp
index b569cd0e0..39bc3e889 100644
--- a/src/passes/PostEmscripten.cpp
+++ b/src/passes/PostEmscripten.cpp
@@ -186,10 +186,13 @@ IString EM_JS_PREFIX("__em_js__");
IString EM_JS_DEPS_PREFIX("__em_lib_deps_");
struct EmJsWalker : public PostWalker<EmJsWalker> {
+ bool sideModule;
std::vector<Export> toRemove;
+ EmJsWalker(bool sideModule) : sideModule(sideModule) {}
+
void visitExport(Export* curr) {
- if (curr->name.startsWith(EM_JS_PREFIX)) {
+ if (!sideModule && curr->name.startsWith(EM_JS_PREFIX)) {
toRemove.push_back(*curr);
}
if (curr->name.startsWith(EM_JS_DEPS_PREFIX)) {
@@ -215,14 +218,15 @@ struct PostEmscripten : public Pass {
auto& options = getPassOptions();
auto sideModule = options.hasArgument("post-emscripten-side-module");
if (!sideModule) {
+ removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
+ removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js");
+
// Side modules read EM_ASM data from the module based on these exports
// so we need to keep them around in that case.
- removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
module.removeExport("__start_em_asm");
module.removeExport("__stop_em_asm");
}
- removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js");
removeData(
module, segmentOffsets, "__start_em_lib_deps", "__stop_em_lib_deps");
module.removeExport("__start_em_js");
@@ -232,7 +236,9 @@ struct PostEmscripten : public Pass {
}
void removeEmJsExports(Module& module) {
- EmJsWalker walker;
+ auto& options = getPassOptions();
+ auto sideModule = options.hasArgument("post-emscripten-side-module");
+ EmJsWalker walker(sideModule);
walker.walkModule(&module);
for (const Export& exp : walker.toRemove) {
if (exp.kind == ExternalKind::Function) {