summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-01-22 16:23:09 -0800
committerGitHub <noreply@github.com>2020-01-22 16:23:09 -0800
commitcfc581f7d3c629016aa382a7e915f8b0a955fb40 (patch)
tree0ec22a6f0d1275c51a6734a23e1a33db12b65ded /src
parent60cfc85293c18ca49b25daa4328e5902d4130dae (diff)
downloadbinaryen-cfc581f7d3c629016aa382a7e915f8b0a955fb40.tar.gz
binaryen-cfc581f7d3c629016aa382a7e915f8b0a955fb40.tar.bz2
binaryen-cfc581f7d3c629016aa382a7e915f8b0a955fb40.zip
Limit the number of passive segments to work around a Chrome bug (#2613)
Chrome is currently decoding the segment indices as signed numbers, so some ranges of indices greater than 63 do not work. As a temporary workaround, limit the number of segments produced by MemoryPacking to 63 when bulk-memory is enabled.
Diffstat (limited to 'src')
-rw-r--r--src/passes/MemoryPacking.cpp10
-rw-r--r--src/wasm-binary.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index d8e59cae6..640207fc7 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -87,6 +87,11 @@ Expression* makeShiftedMemorySize(Builder& builder) {
struct MemoryPacking : public Pass {
size_t dropStateGlobalCount = 0;
+ // FIXME: Chrome has a bug decoding section indices that prevents it from
+ // using more than 63. Just use WebLimitations::MaxDataSegments once this is
+ // fixed. See https://bugs.chromium.org/p/v8/issues/detail?id=10151.
+ uint32_t maxSegments;
+
void run(PassRunner* runner, Module* module) override;
void optimizeBulkMemoryOps(PassRunner* runner, Module* module);
void getSegmentReferrers(Module* module, std::vector<Referrers>& referrers);
@@ -116,6 +121,9 @@ void MemoryPacking::run(PassRunner* runner, Module* module) {
return;
}
+ maxSegments = module->features.hasBulkMemory()
+ ? 63
+ : uint32_t(WebLimitations::MaxDataSegments);
auto& segments = module->memory.segments;
// For each segment, a list of bulk memory instructions that refer to it
@@ -436,7 +444,7 @@ void MemoryPacking::createSplitSegments(Builder& builder,
offset = segment.offset;
}
}
- if (WebLimitations::MaxDataSegments <= packed.size() + segmentsRemaining) {
+ if (maxSegments <= packed.size() + segmentsRemaining) {
// Give up splitting and merge all remaining ranges except end zeroes
auto lastNonzero = ranges.end() - 1;
if (lastNonzero->isZero) {
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 5cfafb509..0dd8be61a 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -47,7 +47,7 @@ enum {
// wasm VMs on the web have decided to impose some limits on what they
// accept
-enum WebLimitations {
+enum WebLimitations : uint32_t {
MaxDataSegments = 100 * 1000,
MaxFunctionBodySize = 128 * 1024,
MaxFunctionLocals = 50 * 1000