Skip to content

Cranelift: Segfault with unaligned stack load sunk into extractlane on x64 #5922

@afonso360

Description

@afonso360

👋 Hey,

Me and @alexcrichton were discussing this via Zulip. The stack_load gets translated into a load.f64x2 notrap aligned v34, and that's why we do the load sinking in the backend.

Is stack_load required to be sufficiently aligned? Reading the docs, they don't mention anything. So it might just be a case of lets update the docs and the fuzzer.

.clif Test Case

test run
target x86_64
target aarch64
target s390x

function %a() -> f64 system_v {
    ss0 = explicit_slot 69

block0:
    v0 = iconst.i64 0
    stack_store.i64 v0, ss0+20
    stack_store.i64 v0, ss0+28
    stack_store.i64 v0, ss0+36

    v29 = stack_load.f64x2 ss0+23
    v30 = extractlane v29, 1
    return v30
}

; run: %a() == 0.0

Steps to Reproduce

  • clif-util test ./the-above.clif

Expected Results

The test to pass

Actual Results

    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `/home/afonso/git/wasmtime/target/debug/clif-util test ./lmao.clif`
Segmentation fault

This passes on AArch64 and S390x.

Versions and Environment

Cranelift version or commit: main

Operating system: Linux

Architecture: x64

Extra Info

Generated assembly:
Disassembly of 60 bytes:
   0:   55                      pushq   %rbp
   1:   48 89 e5                movq    %rsp, %rbp
   4:   48 83 ec 50             subq    $0x50, %rsp
   8:   4c 8d 54 24 14          leaq    0x14(%rsp), %r10
   d:   4d 31 db                xorq    %r11, %r11
  10:   4d 89 1a                movq    %r11, (%r10)
  13:   4c 8d 5c 24 1c          leaq    0x1c(%rsp), %r11
  18:   48 31 f6                xorq    %rsi, %rsi
  1b:   49 89 33                movq    %rsi, (%r11)
  1e:   48 8d 74 24 24          leaq    0x24(%rsp), %rsi
  23:   48 31 ff                xorq    %rdi, %rdi
  26:   48 89 3e                movq    %rdi, (%rsi)
  29:   48 8d 7c 24 17          leaq    0x17(%rsp), %rdi
  2e:   66 0f 70 07 ee          pshufd  $0xee, (%rdi), %xmm0
  33:   48 83 c4 50             addq    $0x50, %rsp
  37:   48 89 ec                movq    %rbp, %rsp
  3a:   5d                      popq    %rbp
  3b:   c3                      retq

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingcraneliftIssues related to the Cranelift code generatorcranelift:area:x64Issues related to x64 codegen

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions