asmjs icon indicating copy to clipboard operation
asmjs copied to clipboard

Passing $pc0 to wasm functions?

Open pipcet opened this issue 9 years ago • 0 comments

Right now, wasm functions have the signature (int, int, int, int, int, int) -> int

The arguments are:

  • callee $dpc (-1 for first call)
  • $sp1 (= $sp + 16)
  • $r0
  • $r1
  • $rpc = caller $dpc
  • callee $pc0

There are six of them because there are six integer registers used for function arguments on x86_64.

The last argument is the callee's $pc0, which I thought would be a good idea to pass for dynamic linking. Now that dynamic linking is somewhat working, it turns out it's a bad idea to pass it: in the callee, the $pc0 is available as

    get_global $plt
    i32.const f
    i32.add

while in the caller, it's actually hard to calculate: the actual call is

    call f@plt

with the heavy lifting done by the assembler and linker interpreting the "@plt" part. But there's no way to write i32.const f@plt, since we can't have runtime relocs in text, so we're left with creating a GOT entry for every function we call, which seems excessive overhead.

It also seems questionable to pass the caller's $dpc but not the caller's $pc0; originally those were in a single 32-bit word, and used for __builtin_return_address, but that's another issue...

I'm considering omitting the last two arguments for now (and leaving __builtin_return_address broken).

pipcet avatar Dec 08 '16 14:12 pipcet