Skip to content

Commit 1e7e3d2

Browse files
committed
Add post-emscripten-side-module pass argument
In this mode we don't remove the start/stop_em_asm symbols or data. This is because with side modules we read this information directly from the wasm binaryen at runtime. See emscripten-core/emscripten#18228
1 parent b2054b7 commit 1e7e3d2

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/pass.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct PassOptions {
188188
bool debugInfo = false;
189189
// Arbitrary string arguments from the commandline, which we forward to
190190
// passes.
191-
std::map<std::string, std::string> arguments;
191+
std::unordered_map<std::string, std::string> arguments;
192192

193193
// Effect info computed for functions. One pass can generate this and then
194194
// other passes later can benefit from it. It is up to the sequence of passes
@@ -217,15 +217,19 @@ struct PassOptions {
217217
return PassOptions(); // defaults are to not optimize
218218
}
219219

220+
bool hasArgument(std::string key) {
221+
return arguments.count(key) > 0;
222+
}
223+
220224
std::string getArgument(std::string key, std::string errorTextIfMissing) {
221-
if (arguments.count(key) == 0) {
225+
if (!hasArgument(key)) {
222226
Fatal() << errorTextIfMissing;
223227
}
224228
return arguments[key];
225229
}
226230

227231
std::string getArgumentOrDefault(std::string key, std::string default_) {
228-
if (arguments.count(key) == 0) {
232+
if (!hasArgument(key)) {
229233
return default_;
230234
}
231235
return arguments[key];

src/passes/Asyncify.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,7 @@ struct Asyncify : public Pass {
15361536
String::Split listedImports(stateChangingImports, ",");
15371537
// TODO: consider renaming asyncify-ignore-indirect to
15381538
// asyncify-ignore-nondirect, but that could break users.
1539-
auto ignoreNonDirect =
1540-
options.getArgumentOrDefault("asyncify-ignore-indirect", "") == "";
1539+
auto ignoreNonDirect = options.hasArgument("asyncify-ignore-indirect");
15411540
std::string removeListInput =
15421541
options.getArgumentOrDefault("asyncify-removelist", "");
15431542
if (removeListInput.empty()) {
@@ -1558,12 +1557,10 @@ struct Asyncify : public Pass {
15581557
}
15591558
String::Split onlyList(
15601559
String::trim(read_possible_response_file(onlyListInput)), ",");
1561-
auto asserts = options.getArgumentOrDefault("asyncify-asserts", "") != "";
1562-
auto verbose = options.getArgumentOrDefault("asyncify-verbose", "") != "";
1563-
auto relocatable =
1564-
options.getArgumentOrDefault("asyncify-relocatable", "") != "";
1565-
auto secondaryMemory =
1566-
options.getArgumentOrDefault("asyncify-in-secondary-memory", "") != "";
1560+
auto asserts = options.hasArgument("asyncify-asserts");
1561+
auto verbose = options.hasArgument("asyncify-verbose");
1562+
auto relocatable = options.hasArgument("asyncify-relocatable");
1563+
auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory");
15671564

15681565
// Ensure there is a memory, as we need it.
15691566
if (secondaryMemory) {

src/passes/PostEmscripten.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,19 @@ struct PostEmscripten : public Pass {
214214
std::vector<Address> segmentOffsets; // segment index => address offset
215215
calcSegmentOffsets(module, segmentOffsets);
216216

217-
removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
217+
auto& options = getPassOptions();
218+
auto sideModule = options.hasArgument("post-emscripten-side-module");
219+
if (!sideModule) {
220+
// Side modules read EM_ASM data from the module based on these exports
221+
// so we need to keep them around in that case.
222+
removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
223+
module.removeExport("__start_em_asm");
224+
module.removeExport("__stop_em_asm");
225+
}
226+
218227
removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js");
219228
removeData(
220229
module, segmentOffsets, "__start_em_lib_deps", "__stop_em_lib_deps");
221-
module.removeExport("__start_em_asm");
222-
module.removeExport("__stop_em_asm");
223230
module.removeExport("__start_em_js");
224231
module.removeExport("__stop_em_js");
225232
module.removeExport("__start_em_lib_deps");

0 commit comments

Comments
 (0)