summaryrefslogtreecommitdiff
path: root/src/tools/wasm-ctor-eval.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-01-11 14:16:34 -0800
committerGitHub <noreply@github.com>2022-01-11 14:16:34 -0800
commitb63fea1feefce42be49fa28fd85d01d4a52603a2 (patch)
tree541a37da001dda677bdd9288897587a0de908ac1 /src/tools/wasm-ctor-eval.cpp
parentcc36ffd13f6794cc5212a1f0ba7f58e816e8a0de (diff)
downloadbinaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.tar.gz
binaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.tar.bz2
binaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.zip
[ctor-eval] Stop if there are any memory.init instructions (#4442)
This tool depends (atm) on flattening memory segments. That is not compatible with memory.init which cares about segment identities. This changes flatten() only by adding the check for MemoryInit. The rest is unchanged, although I saw the other two params are not needed and I removed them while I was there.
Diffstat (limited to 'src/tools/wasm-ctor-eval.cpp')
-rw-r--r--src/tools/wasm-ctor-eval.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index e6883e351..3923d137c 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -663,11 +663,6 @@ void evalCtors(Module& wasm,
CtorEvalExternalInterface interface(linkedInstances);
try {
- // flatten memory, so we do not depend on the layout of data segments
- if (!MemoryUtils::flatten(wasm.memory)) {
- Fatal() << " ...stopping since could not flatten memory\n";
- }
-
// create an instance for evalling
EvallingModuleInstance instance(wasm, &interface, linkedInstances);
// we should not add new globals from here on; as a result, using
@@ -712,6 +707,16 @@ void evalCtors(Module& wasm,
}
}
+static bool canEval(Module& wasm) {
+ // Check if we can flatten memory. We need to do so currently because of how
+ // we assume memory is simple and flat. TODO
+ if (!MemoryUtils::flatten(wasm)) {
+ std::cout << " ...stopping since could not flatten memory\n";
+ return false;
+ }
+ return true;
+}
+
} // anonymous namespace
//
@@ -808,19 +813,21 @@ int main(int argc, const char* argv[]) {
Fatal() << "error in validating input";
}
- evalCtors(wasm, ctors, keptExports);
-
- // Do some useful optimizations after the evalling
- {
- PassRunner passRunner(&wasm);
- passRunner.add("memory-packing"); // we flattened it, so re-optimize
- // TODO: just do -Os for the one function
- passRunner.add("remove-unused-names");
- passRunner.add("dce");
- passRunner.add("merge-blocks");
- passRunner.add("vacuum");
- passRunner.add("remove-unused-module-elements");
- passRunner.run();
+ if (canEval(wasm)) {
+ evalCtors(wasm, ctors, keptExports);
+
+ // Do some useful optimizations after the evalling
+ {
+ PassRunner passRunner(&wasm);
+ passRunner.add("memory-packing"); // we flattened it, so re-optimize
+ // TODO: just do -Os for the one function
+ passRunner.add("remove-unused-names");
+ passRunner.add("dce");
+ passRunner.add("merge-blocks");
+ passRunner.add("vacuum");
+ passRunner.add("remove-unused-module-elements");
+ passRunner.run();
+ }
}
if (options.extra.count("output") > 0) {