Skip to content

Commit a5c9099

Browse files
committed
PostEmscripten: Preserve __em_js__ exports in side modules
1 parent 61f70af commit a5c9099

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/passes/PostEmscripten.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,13 @@ IString EM_JS_PREFIX("__em_js__");
186186
IString EM_JS_DEPS_PREFIX("__em_lib_deps_");
187187

188188
struct EmJsWalker : public PostWalker<EmJsWalker> {
189+
bool sideModule;
189190
std::vector<Export> toRemove;
190191

192+
EmJsWalker(bool sideModule) : sideModule(sideModule) {}
193+
191194
void visitExport(Export* curr) {
192-
if (curr->name.startsWith(EM_JS_PREFIX)) {
195+
if (!sideModule && curr->name.startsWith(EM_JS_PREFIX)) {
193196
toRemove.push_back(*curr);
194197
}
195198
if (curr->name.startsWith(EM_JS_DEPS_PREFIX)) {
@@ -215,14 +218,15 @@ struct PostEmscripten : public Pass {
215218
auto& options = getPassOptions();
216219
auto sideModule = options.hasArgument("post-emscripten-side-module");
217220
if (!sideModule) {
221+
removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
222+
removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js");
223+
218224
// Side modules read EM_ASM data from the module based on these exports
219225
// so we need to keep them around in that case.
220-
removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
221226
module.removeExport("__start_em_asm");
222227
module.removeExport("__stop_em_asm");
223228
}
224229

225-
removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js");
226230
removeData(
227231
module, segmentOffsets, "__start_em_lib_deps", "__stop_em_lib_deps");
228232
module.removeExport("__start_em_js");
@@ -232,7 +236,9 @@ struct PostEmscripten : public Pass {
232236
}
233237

234238
void removeEmJsExports(Module& module) {
235-
EmJsWalker walker;
239+
auto& options = getPassOptions();
240+
auto sideModule = options.hasArgument("post-emscripten-side-module");
241+
EmJsWalker walker(sideModule);
236242
walker.walkModule(&module);
237243
for (const Export& exp : walker.toRemove) {
238244
if (exp.kind == ExternalKind::Function) {

0 commit comments

Comments
 (0)