WebAssembly / memory64

Memory with 64-bit indexes
Other
194 stars 21 forks source link

what to set for `max` on imported 64-bit memories #33

Open sbc100 opened 1 year ago

sbc100 commented 1 year ago

Imported, growable memories need to specify a max. In llvm, when we build a DLL, we generally don't care about the upper limit of the imported memory so we try to set the max max here:

https://github.com/llvm/llvm-project/blob/89197b59f597995ecb6b6dc2e262a1ecddeee901/lld/wasm/Writer.cpp#L351

For 32-bit memories the max is simple and obvious 2 ^ 32. For 64-bit memories it looks like 2 ^ 48 was chosen (most likely largely arbitrarily but IIRC that the size of the virtual address space on some 64-bit architectures?). However this currently run up against an implementation defined limit when trying to load such modules in v8:

[Error [CompileError]: WebAssembly.instantiate(): maximum memory size (4294967296 pages) is larger than implementation limit (262144 pages) @+85]
Thrown at:
    at /tmp/emtest_jt9nwb1e/emscripten_test_wasm64_mnmu7cfb/test_pthread_dylink.js:156:7
    at emit (node:events:510:28)
    at node:internal/process/execution:159:25

So for now I think we can modify llvm to emit 2 ^ 34 as the max, but we should probably come up with some better way to signal that we don't care about the maximum, or agree a sensible implementation limit and then embed that into the tools.

sbc100 commented 1 year ago

Proposed llvm change: https://reviews.llvm.org/D143783