Skip to content

Commit 5123100

Browse files
authored
winch(x64): Ensure correct operand size on memory alignment check (#13337)
Prior to this commit, the alignment check implementation part of the threads proposal was erroneously relying on the byte access size to calcuate the effective address, this would result in a panic at Cranelift's emission layer when mixing immediates and access sizes smaller than 4-bytes. The fix relies on the heap size for the arithmetic operations related to calculating the effective address and alignment calculation, mirroring what the heap address calculation will use prior to a memory access.
1 parent 83ee70b commit 5123100

29 files changed

Lines changed: 186 additions & 114 deletions

tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
;; movq %rsi, 0x10(%rsp)
2121
;; movl %edx, 0xc(%rsp)
2222
;; movl 0xc(%rsp), %eax
23-
;; andw $1, %ax
24-
;; cmpw $0, %ax
23+
;; andl $1, %eax
24+
;; cmpl $0, %eax
2525
;; jne 0x65
2626
;; 46: movl 0xc(%rsp), %eax
2727
;; movq 0x30(%r14), %r11

tests/disas/winch/x64/atomic/load/i64_atomic_load.wat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
;; movq 0x18(%r11), %r11
1515
;; addq $0x10, %r11
1616
;; cmpq %rsp, %r11
17-
;; ja 0x5e
17+
;; ja 0x5c
1818
;; 1c: movq %rdi, %r14
1919
;; subq $0x10, %rsp
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0, %eax
23-
;; andq $7, %rax
24-
;; cmpq $0, %rax
25-
;; jne 0x60
26-
;; 44: movl $0, %eax
23+
;; andl $7, %eax
24+
;; cmpl $0, %eax
25+
;; jne 0x5e
26+
;; 42: movl $0, %eax
2727
;; movq 0x38(%r14), %rcx
2828
;; movl %eax, %eax
2929
;; addq %rax, %rcx
3030
;; movq (%rcx), %rax
3131
;; addq $0x10, %rsp
3232
;; popq %rbp
3333
;; retq
34+
;; 5c: ud2
3435
;; 5e: ud2
35-
;; 60: ud2

tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0, %eax
23-
;; andw $1, %ax
24-
;; cmpw $0, %ax
23+
;; andl $1, %eax
24+
;; cmpl $0, %eax
2525
;; jne 0x5f
2626
;; 42: movl $0, %eax
2727
;; movq 0x38(%r14), %rcx
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
4+
(module
5+
(memory 2)
6+
(func (export "f") (param i32) (result i32)
7+
local.get 0
8+
i32.atomic.load16_u offset=0x80000000
9+
)
10+
)
11+
;; wasm[0]::function[0]:
12+
;; pushq %rbp
13+
;; movq %rsp, %rbp
14+
;; movq 8(%rdi), %r11
15+
;; movq 0x18(%r11), %r11
16+
;; addq $0x20, %r11
17+
;; cmpq %rsp, %r11
18+
;; ja 0x9c
19+
;; 1c: movq %rdi, %r14
20+
;; subq $0x20, %rsp
21+
;; movq %rdi, 0x18(%rsp)
22+
;; movq %rsi, 0x10(%rsp)
23+
;; movl %edx, 0xc(%rsp)
24+
;; movl 0xc(%rsp), %eax
25+
;; movl $0x80000000, %r11d
26+
;; addl %r11d, %eax
27+
;; andl $1, %eax
28+
;; cmpl $0, %eax
29+
;; jne 0x9e
30+
;; 4f: movl 0xc(%rsp), %eax
31+
;; movq 0x40(%r14), %rcx
32+
;; movl %eax, %edx
33+
;; movl $0x80000002, %r11d
34+
;; addq %r11, %rdx
35+
;; jb 0xa0
36+
;; 68: cmpq %rcx, %rdx
37+
;; ja 0xa2
38+
;; 71: movq 0x38(%r14), %rbx
39+
;; movl %eax, %eax
40+
;; addq %rax, %rbx
41+
;; movl $0x80000000, %r11d
42+
;; addq %r11, %rbx
43+
;; movl $0, %esi
44+
;; cmpq %rcx, %rdx
45+
;; cmovaq %rsi, %rbx
46+
;; movzwq (%rbx), %rax
47+
;; addq $0x20, %rsp
48+
;; popq %rbp
49+
;; retq
50+
;; 9c: ud2
51+
;; 9e: ud2
52+
;; a0: ud2
53+
;; a2: ud2

tests/disas/winch/x64/atomic/rmw/add/i32_atomic_rmw16_addu.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andw $1, %cx
23-
;; cmpw $0, %cx
22+
;; andl $1, %ecx
23+
;; cmpl $0, %ecx
2424
;; jne 0x6c
2525
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11

tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw16_addu.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andw $1, %cx
23-
;; cmpw $0, %cx
22+
;; andl $1, %ecx
23+
;; cmpl $0, %ecx
2424
;; jne 0x6d
2525
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11

tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw_add.wat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
;; movq 0x18(%r11), %r11
1313
;; addq $0x10, %r11
1414
;; cmpq %rsp, %r11
15-
;; ja 0x69
15+
;; ja 0x67
1616
;; 1c: movq %rdi, %r14
1717
;; subq $0x10, %rsp
1818
;; movq %rdi, 8(%rsp)
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andq $7, %rcx
23-
;; cmpq $0, %rcx
24-
;; jne 0x6b
25-
;; 4a: movl $0, %ecx
22+
;; andl $7, %ecx
23+
;; cmpl $0, %ecx
24+
;; jne 0x69
25+
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11
2727
;; movq (%r11), %rdx
2828
;; movl %ecx, %ecx
@@ -31,5 +31,5 @@
3131
;; addq $0x10, %rsp
3232
;; popq %rbp
3333
;; retq
34+
;; 67: ud2
3435
;; 69: ud2
35-
;; 6b: ud2

tests/disas/winch/x64/atomic/rmw/and/i32_atomic_rmw16_andu.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andw $1, %cx
23-
;; cmpw $0, %cx
22+
;; andl $1, %ecx
23+
;; cmpl $0, %ecx
2424
;; jne 0x91
2525
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11

tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw16_andu.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andw $1, %cx
23-
;; cmpw $0, %cx
22+
;; andl $1, %ecx
23+
;; cmpl $0, %ecx
2424
;; jne 0x80
2525
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11

tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw_and.wat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
;; movq 0x18(%r11), %r11
1313
;; addq $0x18, %r11
1414
;; cmpq %rsp, %r11
15-
;; ja 0x7a
15+
;; ja 0x78
1616
;; 1c: movq %rdi, %r14
1717
;; subq $0x10, %rsp
1818
;; movq %rdi, 8(%rsp)
1919
;; movq %rsi, (%rsp)
2020
;; movl $0x2a, %eax
2121
;; movl $0, %ecx
22-
;; andq $7, %rcx
23-
;; cmpq $0, %rcx
24-
;; jne 0x7c
25-
;; 4a: movl $0, %ecx
22+
;; andl $7, %ecx
23+
;; cmpl $0, %ecx
24+
;; jne 0x7a
25+
;; 48: movl $0, %ecx
2626
;; movq 0x30(%r14), %r11
2727
;; movq (%r11), %rdx
2828
;; movl %ecx, %ecx
@@ -33,9 +33,9 @@
3333
;; movq %rax, %r11
3434
;; andq %rcx, %r11
3535
;; lock cmpxchgq %r11, (%rdx)
36-
;; jne 0x60
37-
;; 71: addq $0x10, %rsp
36+
;; jne 0x5e
37+
;; 6f: addq $0x10, %rsp
3838
;; popq %rbp
3939
;; retq
40+
;; 78: ud2
4041
;; 7a: ud2
41-
;; 7c: ud2

0 commit comments

Comments
 (0)