Skip to content

Commit 3aab955

Browse files
winch: Fix missing zero-extensions of addresses loaded from (#13014)
* winch: Add add_uextend to perform explicit extension when needed. This commit fixes an out-of-bounds access caused by the lack zero extension in the code responsible for calculating the heap address for loads/stores. This issue manifests in aarch64 (unlike x64) given that no automatic extension is performed, resulting in an out-of-bounds access. An alternative approach is to emit an extend for the index, however this approach is preferred given that it gives the MacroAssembler layer better control of how to lower addition, e.g., in aarch64 we can inline the desired extension in a single instruction. * winch: Correctly type the result of table.grow This commit fixes an out-of-bounds access caused by the lack of type narrowing from the `table.grow` builtin. Without explicit narrowing, the type is treated as 64-bit value, which could cause issues when paired with loads/stores. * Review comments * Properly handle table index types Only narrow when dealing with the 64-bit pointer/32-bit tables * winch: Refine zero extension heuristic This commit refines the zero extension heuristic such that it unconditionally emits a zero extension when dealing with 32-bit heaps. This eliminates any ambiguity related to the value of the memory indices across ISAs. --------- Co-authored-by: Saúl Cabrera <saulecabrera@gmail.com>
1 parent ed55592 commit 3aab955

116 files changed

Lines changed: 600 additions & 368 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/disas/winch/aarch64/load/dynamic_heap.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
;; 5c: cmp x2, x1, uxtx
4747
;; b.hi #0x158
4848
;; 64: ldur x3, [x9, #0x38]
49-
;; add x3, x3, x0, uxtx
49+
;; add x3, x3, w0, uxtw
5050
;; mov x4, #0
5151
;; cmp x2, x1, uxtx
5252
;; csel x3, x4, x3, hi
@@ -59,7 +59,7 @@
5959
;; 90: cmp x3, x2, uxtx
6060
;; b.hi #0x160
6161
;; 98: ldur x4, [x9, #0x38]
62-
;; add x4, x4, x1, uxtx
62+
;; add x4, x4, w1, uxtw
6363
;; add x4, x4, #4
6464
;; mov x5, #0
6565
;; cmp x3, x2, uxtx
@@ -75,7 +75,7 @@
7575
;; d0: cmp x4, x3, uxtx
7676
;; b.hi #0x168
7777
;; d8: ldur x5, [x9, #0x38]
78-
;; add x5, x5, x2, uxtx
78+
;; add x5, x5, w2, uxtw
7979
;; orr x16, xzr, #0xfffff
8080
;; add x5, x5, x16, uxtx
8181
;; mov x6, #0

tests/disas/winch/aarch64/load/f32.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
;; stur x1, [x28]
2626
;; mov x0, #0
2727
;; ldur x1, [x9, #0x38]
28-
;; add x1, x1, x0, uxtx
28+
;; add x1, x1, w0, uxtw
2929
;; ldur s0, [x1]
3030
;; add x28, x28, #0x10
3131
;; mov sp, x28

tests/disas/winch/aarch64/load/f64.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
;; stur x1, [x28]
2525
;; mov x0, #0
2626
;; ldur x1, [x9, #0x38]
27-
;; add x1, x1, x0, uxtx
27+
;; add x1, x1, w0, uxtw
2828
;; ldur d0, [x1]
2929
;; add x28, x28, #0x10
3030
;; mov sp, x28

tests/disas/winch/aarch64/load/i32.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
;; stur x1, [x28]
2626
;; mov x0, #0
2727
;; ldur x1, [x9, #0x38]
28-
;; add x1, x1, x0, uxtx
28+
;; add x1, x1, w0, uxtw
2929
;; ldur w0, [x1]
3030
;; add x28, x28, #0x10
3131
;; mov sp, x28

tests/disas/winch/aarch64/load/i64.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
;; ldur x0, [x28]
2929
;; mov x1, #8
3030
;; ldur x2, [x9, #0x38]
31-
;; add x2, x2, x1, uxtx
31+
;; add x2, x2, w1, uxtw
3232
;; sub sp, x28, #8
3333
;; sturb w0, [x2]
3434
;; mov sp, x28
3535
;; mov x0, #8
3636
;; ldur x1, [x9, #0x38]
37-
;; add x1, x1, x0, uxtx
37+
;; add x1, x1, w0, uxtw
3838
;; sub sp, x28, #8
3939
;; ldursb x0, [x1]
4040
;; mov sp, x28

tests/disas/winch/aarch64/store/dynamic_heap.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
;; 68: cmp x3, x2, uxtx
5050
;; b.hi #0x12c
5151
;; 70: ldur x4, [x9, #0x38]
52-
;; add x4, x4, x1, uxtx
52+
;; add x4, x4, w1, uxtw
5353
;; mov x5, #0
5454
;; cmp x3, x2, uxtx
5555
;; csel x4, x5, x4, hi
@@ -63,7 +63,7 @@
6363
;; a0: cmp x3, x2, uxtx
6464
;; b.hi #0x134
6565
;; a8: ldur x4, [x9, #0x38]
66-
;; add x4, x4, x1, uxtx
66+
;; add x4, x4, w1, uxtw
6767
;; add x4, x4, #4
6868
;; mov x5, #0
6969
;; cmp x3, x2, uxtx
@@ -80,7 +80,7 @@
8080
;; e4: cmp x3, x2, uxtx
8181
;; b.hi #0x13c
8282
;; ec: ldur x4, [x9, #0x38]
83-
;; add x4, x4, x1, uxtx
83+
;; add x4, x4, w1, uxtw
8484
;; orr x16, xzr, #0xfffff
8585
;; add x4, x4, x16, uxtx
8686
;; mov x5, #0

tests/disas/winch/aarch64/store/f32.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
;; ldr s0, #0x70
2626
;; mov x0, #0
2727
;; ldur x1, [x9, #0x38]
28-
;; add x1, x1, x0, uxtx
28+
;; add x1, x1, w0, uxtw
2929
;; stur s0, [x1]
3030
;; add x28, x28, #0x10
3131
;; mov sp, x28

tests/disas/winch/aarch64/store/f64.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
;; ldr d0, #0x70
2727
;; mov x0, #0
2828
;; ldur x1, [x9, #0x38]
29-
;; add x1, x1, x0, uxtx
29+
;; add x1, x1, w0, uxtw
3030
;; stur d0, [x1]
3131
;; add x28, x28, #0x10
3232
;; mov sp, x28

tests/disas/winch/aarch64/store/i32.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
;; mov x0, #1
2828
;; mov x1, #0
2929
;; ldur x2, [x9, #0x38]
30-
;; add x2, x2, x1, uxtx
30+
;; add x2, x2, w1, uxtw
3131
;; stur w0, [x2]
3232
;; add x28, x28, #0x10
3333
;; mov sp, x28

tests/disas/winch/x64/atomic/fence/fence.wat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; movq 0x18(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x62
18+
;; ja 0x66
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
@@ -24,15 +24,17 @@
2424
;; movl $0, %ecx
2525
;; movq 0x30(%r14), %r11
2626
;; movq (%r11), %rdx
27+
;; movl %ecx, %ecx
2728
;; addq %rcx, %rdx
2829
;; movl %eax, (%rdx)
2930
;; mfence
3031
;; movl $0, %eax
3132
;; movq 0x30(%r14), %r11
3233
;; movq (%r11), %rcx
34+
;; movl %eax, %eax
3335
;; addq %rax, %rcx
3436
;; movl (%rcx), %eax
3537
;; addq $0x10, %rsp
3638
;; popq %rbp
3739
;; retq
38-
;; 62: ud2
40+
;; 66: ud2

0 commit comments

Comments
 (0)