Stream: git-wasmtime

Topic: wasmtime / Issue #1162 Multi-value returns do not work in...


view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2020 at 09:54):

teapotd commented on Issue #1162:

It looks like the bug is in x86 legalize_signature:

https://github.com/bytecodealliance/wasmtime/blob/c5b6c57c34f89d865e07939eff67d6687e9339e2/cranelift/codegen/src/isa/x86/abi.rs#L259-L277

Function that returns only i128 is single-return before legalization, so struct-return parameter is never introduced, even though legalize_args doesn't assign registers properly. After changing it to always backup arguments it generates correct code:

function %test_i128(i64 sret [%rcx], i64 fp [%rbp]) -> i64 sret [%rax], i64 fp [%rbp] windows_fastcall {
    ss0 = incoming_arg 16, offset -48

                                block0(v3: i64 [%rcx], v6: i64 [%rbp]):
[RexOp1pushq#50]                    x86_push v6
[RexOp1copysp#8089]                 copy_special %rsp -> %rbp
[RexOp1adjustsp_ib#d083]            adjust_sp_down_imm 32
[RexOp1pu_iq#80b8,%rax]             v0 = iconst.i64 0x4242_3535_1234_5678
                                    v4 -> v0
[RexOp1pu_iq#80b8,%rdx]             v1 = iconst.i64 0xabcd_ef01_beef_b411
                                    v5 -> v1
[-,-]                               v2 = iconcat v0, v1
[RexOp1st#8089]                     store notrap aligned v0, v3
[RexOp1stDisp8#8089]                store notrap aligned v1, v3+8
[RexOp1rmov#8089]                   regmove v3, %rcx -> %rax
[RexOp1adjustsp_ib#8083]            adjust_sp_up_imm 32
[RexOp1popq#58,%rbp]                v7 = x86_pop.i64
[Op1ret#c3]                         return v3, v7
}

Disassembly of 46 bytes:
   0:   40 55                   push    rbp
   2:   48 89 e5                mov rbp, rsp
   5:   48 83 ec 20             sub rsp, 0x20
   9:   48 b8 78 56 34 12 35 35 42 42
                movabs  rax, 0x4242353512345678
  13:   48 ba 11 b4 ef be 01 ef cd ab
                movabs  rdx, 0xabcdef01beefb411
  1d:   48 89 01                mov qword ptr [rcx], rax
  20:   48 89 51 08             mov qword ptr [rcx + 8], rdx
  24:   48 89 c8                mov rax, rcx
  27:   48 83 c4 20             add rsp, 0x20
  2b:   40 5d                   pop rbp
  2d:   c3                      ret

I'll make a PR.

view this post on Zulip Wasmtime GitHub notifications bot (May 29 2020 at 17:02):

fitzgen closed Issue #1162:

function %test_i128() -> i128 {
ebb0:
    v0 = iconst.i64 0x4242_3535_1234_5678
    v1 = iconst.i64 0xabcd_ef01_beef_b411
    v2 = iconcat v0, v1
    return v2
}
; run: %fn() == 0x4242_3535_1234_5678_abcd_ef01_beef_b411

Last updated: Nov 22 2024 at 17:03 UTC