matsc-at-sics-se / unison

Unison's source code
http://unison-code.github.io/
Other
5 stars 0 forks source link

stack object should be 16-aligned but is not in the code #47

Open matsc-at-sics-se opened 6 years ago

matsc-at-sics-se commented 6 years ago

The LEA64r instruction is supposed to make a 16-aligned pointer, but does not.

---
name:            spti_jit_start_end_helper
fixedStack:      
  - { id: 0, offset: -8, size: 8, alignment: 8 }
stack:           
  - { id: 0, offset: -40, size: 24, alignment: 16 }
body:             |
  bb.0 (freq 3):
    successors: %bb.2(1), %bb.1(2)

    %rsp = SUB64ri32 %rsp, 40, implicit-def %eflags
    CMP32mi8 %rip, 1, _, @spti_hooked, _, 0, implicit-def %eflags
    JE_1 %bb.2, implicit %eflags

  bb.1 (freq 2):
    successors: %bb.2(1)

    MOV64mr %rip, 1, _, @spti + 24, _, %rcx
    %rax = LEA64r %rsp, 1, _, 8, _
    MOV64mr %rip, 1, _, @spti + 40, _, %rax
    MOV64mi32 %rip, 1, _, @spti + 32, _, 3
    MOV64mr %rsp, 1, _, 8, _, %rdi
    %edi = MOV32ri @spti
    %rax = MOVSX64rr32 %esi
    MOV64mr %rsp, 1, _, 16, _, %rax
    MOV64mr %rsp, 1, _, 24, _, %rdx
    %rsi = MOV64rm %rip, 1, _, @spti_cookie, _
    CALL64m %rip, 1, _, @spti_hook, _, implicit %rsp
    %xmm0 = VXORPSrr %xmm0, %xmm0
    VMOVUPSmr %rip, 1, _, @spti + 24, _, %xmm0
    MOV64mi32 %rip, 1, _, @spti + 40, _, 0

  bb.2 (freq 3):

    %rsp = ADD64ri32 %rsp, 40, implicit-def %eflags
    RETQ 42

...
matsc-at-sics-se commented 6 years ago

The bug is in Export/directFrame. It assigns an unaligned offset to an object that requires align = 16:

[...]
frame:
    %stack.0: offset = 16, size = 24, align = 16
[...]
Output from directFrame:
[...]
frame:
    %stack.0: offset = -40, size = 24, align = 16
[...]

Reproducer: spti_jit_start_end_helper.uni.txt