Skip to content

Commit

Permalink
Add post-emscripten-side-module pass argument
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbc100 committed Nov 17, 2022
1 parent b2054b7 commit 1e7e3d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct PassOptions {
bool debugInfo = false;
// Arbitrary string arguments from the commandline, which we forward to
// passes.
std::map<std::string, std::string> arguments;
std::unordered_map<std::string, std::string> arguments;

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

bool hasArgument(std::string key) {
return arguments.count(key) > 0;
}

std::string getArgument(std::string key, std::string errorTextIfMissing) {
if (arguments.count(key) == 0) {
if (!hasArgument(key)) {
Fatal() << errorTextIfMissing;
}
return arguments[key];
}

std::string getArgumentOrDefault(std::string key, std::string default_) {
if (arguments.count(key) == 0) {
if (!hasArgument(key)) {
return default_;
}
return arguments[key];
Expand Down
13 changes: 5 additions & 8 deletions src/passes/Asyncify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,7 @@ struct Asyncify : public Pass {
String::Split listedImports(stateChangingImports, ",");
// TODO: consider renaming asyncify-ignore-indirect to
// asyncify-ignore-nondirect, but that could break users.
auto ignoreNonDirect =
options.getArgumentOrDefault("asyncify-ignore-indirect", "") == "";
auto ignoreNonDirect = options.hasArgument("asyncify-ignore-indirect");
std::string removeListInput =
options.getArgumentOrDefault("asyncify-removelist", "");
if (removeListInput.empty()) {
Expand All @@ -1558,12 +1557,10 @@ struct Asyncify : public Pass {
}
String::Split onlyList(
String::trim(read_possible_response_file(onlyListInput)), ",");
auto asserts = options.getArgumentOrDefault("asyncify-asserts", "") != "";
auto verbose = options.getArgumentOrDefault("asyncify-verbose", "") != "";
auto relocatable =
options.getArgumentOrDefault("asyncify-relocatable", "") != "";
auto secondaryMemory =
options.getArgumentOrDefault("asyncify-in-secondary-memory", "") != "";
auto asserts = options.hasArgument("asyncify-asserts");
auto verbose = options.hasArgument("asyncify-verbose");
auto relocatable = options.hasArgument("asyncify-relocatable");
auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory");

// Ensure there is a memory, as we need it.
if (secondaryMemory) {
Expand Down
13 changes: 10 additions & 3 deletions src/passes/PostEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,19 @@ struct PostEmscripten : public Pass {
std::vector<Address> segmentOffsets; // segment index => address offset
calcSegmentOffsets(module, segmentOffsets);

removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm");
auto& options = getPassOptions();
auto sideModule = options.hasArgument("post-emscripten-side-module");
if (!sideModule) {
// 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_asm");
module.removeExport("__stop_em_asm");
module.removeExport("__start_em_js");
module.removeExport("__stop_em_js");
module.removeExport("__start_em_lib_deps");
Expand Down

0 comments on commit 1e7e3d2

Please sign in to comment.