Skip to content

Commit

Permalink
PostEmscripten: Preserve __em_js__ exports in side modules
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Jun 23, 2023
1 parent 61f70af commit a5c9099
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/passes/PostEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit a5c9099

Please sign in to comment.