binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

wasm2js does not support 64-bit memories

Open sighingnow opened this issue 3 years ago • 2 comments

For C++ source code,

extern "C" int add (int first, int second)
{
  return first + second;
}

Compiling with clang-15 with wasm64 target,

clang --target=wasm64 --no-standard-libraries -Wl,--export-all -Wl,--no-entry -o add.wasm add.cc

And translate to js using wasm2js,

wasm2js add.wasm

However it fails with

[PassRunner]   running pass: i64-to-i32-lowering...               0.0005889 seconds.                                                                                                                             [PassRunner]   (validating)                                                                                                                                                                                      [PassRunner] running nested passes                                                                                                                                                                               [PassRunner]   running pass: ... 0.0002939 seconds.                                                                                                                                                              [PassRunner] nested passes took 0.0002939 seconds.
[wasm-validator error in function add] i32 != i64: store pointer must match memory index type, on
(i32.store offset=12
 (block (result i32)
  (local.set $40
   (local.get $20)
  )
  (local.get $19)
 )
 (local.get $21)
)
[wasm-validator error in function add] i32 != i64: store pointer must match memory index type, on
(i32.store offset=8
 (block (result i32)
  (local.set $37
   (local.get $23)
  )
  (local.get $22)
 )                                                                                                                                                                                                                (local.get $24)                                                                                                                                                                                                 )
[wasm-validator error in function add] i32 != i64: load pointer type must match memory index type, on
(i32.load offset=12
 (block (result i32)
  (local.set $35
   (local.get $26)
  )
  (local.get $25)
 )
)
[wasm-validator error in function add] i32 != i64: load pointer type must match memory index type, on
(i32.load offset=8
 (block (result i32)
  (local.set $38
   (local.get $29)
  )
  (local.get $28)
 )
)

sighingnow avatar Feb 19 '22 10:02 sighingnow

The general problem here is that wasm2js does not support 64-bit memories right now. I'll change the issue title to reflect that, but I'm not sure how wasm2js even would lower a 64-bit memory access.

tlively avatar Mar 01 '22 16:03 tlively

BigInt64Array exists in JS (using BigInts), and could be used for this I think. It would take some work though.

kripken avatar Mar 01 '22 18:03 kripken