WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.48k stars 740 forks source link

Memory packing is not safe with imported memory #2423

Open tlively opened 4 years ago

tlively commented 4 years ago

The MemoryPacking pass assumes that the initial memory is zero, so it is free to remove spans of zeroes from active segments. This is not technically true with an imported memory. Do we care? This has not been a problem in practice because toolchains generally assume that memory is fresh and owned by the wasm module.

kripken commented 4 years ago

Good point. We should perhaps make variations on the pass that either make that assumption or do not, but a downside is that most code will likely assume this, so forcing people to opt-in means some would miss out. Still, it's probably the right thing to do.