Skip to content

Commit 62cb70d

Browse files
tlivelycadcode
authored andcommitted
Limit the number of passive segments to work around a Chrome bug (WebAssembly#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.
1 parent 7eb69fd commit 62cb70d

File tree

4 files changed

+600
-2
lines changed

4 files changed

+600
-2
lines changed

src/passes/MemoryPacking.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Expression* makeShiftedMemorySize(Builder& builder) {
8787
struct MemoryPacking : public Pass {
8888
size_t dropStateGlobalCount = 0;
8989

90+
// FIXME: Chrome has a bug decoding section indices that prevents it from
91+
// using more than 63. Just use WebLimitations::MaxDataSegments once this is
92+
// fixed. See https://bugs.chromium.org/p/v8/issues/detail?id=10151.
93+
uint32_t maxSegments;
94+
9095
void run(PassRunner* runner, Module* module) override;
9196
void optimizeBulkMemoryOps(PassRunner* runner, Module* module);
9297
void getSegmentReferrers(Module* module, std::vector<Referrers>& referrers);
@@ -116,6 +121,9 @@ void MemoryPacking::run(PassRunner* runner, Module* module) {
116121
return;
117122
}
118123

124+
maxSegments = module->features.hasBulkMemory()
125+
? 63
126+
: uint32_t(WebLimitations::MaxDataSegments);
119127
auto& segments = module->memory.segments;
120128

121129
// For each segment, a list of bulk memory instructions that refer to it
@@ -436,7 +444,7 @@ void MemoryPacking::createSplitSegments(Builder& builder,
436444
offset = segment.offset;
437445
}
438446
}
439-
if (WebLimitations::MaxDataSegments <= packed.size() + segmentsRemaining) {
447+
if (maxSegments <= packed.size() + segmentsRemaining) {
440448
// Give up splitting and merge all remaining ranges except end zeroes
441449
auto lastNonzero = ranges.end() - 1;
442450
if (lastNonzero->isZero) {

src/wasm-binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ enum {
4747

4848
// wasm VMs on the web have decided to impose some limits on what they
4949
// accept
50-
enum WebLimitations {
50+
enum WebLimitations : uint32_t {
5151
MaxDataSegments = 100 * 1000,
5252
MaxFunctionBodySize = 128 * 1024,
5353
MaxFunctionLocals = 50 * 1000

0 commit comments

Comments
 (0)