Skip to content

Commit 642ee73

Browse files
authored
Fix Pulley TrapIf patch offset (#9647)
* Fix Pulley `TrapIf` patch offset A missing `+N` meant that the instruction opcode was overwritten rather than the relative jump offset. * Fix tests
1 parent 57cd5a9 commit 642ee73

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

cranelift/codegen/src/isa/pulley_shared/inst/emit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn pulley_emit<P>(
149149
let label = sink.defer_trap(*code);
150150

151151
let cur_off = sink.cur_offset();
152-
sink.use_label_at_offset(cur_off, label, LabelUse::Jump(3));
152+
sink.use_label_at_offset(cur_off + 3, label, LabelUse::Jump(3));
153153

154154
use ir::condcodes::IntCC::*;
155155
use OperandSize::*;

cranelift/filetests/filetests/isa/pulley32/trap.clif

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ block0(v0: i64):
2929
;
3030
; Disassembled:
3131
; 0: 14 02 2a xconst8 x2, 42
32-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
32+
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
3333
; a: 00 ret
3434
; b: 00 ret
3535

@@ -49,7 +49,7 @@ block0(v0: i64):
4949
;
5050
; Disassembled:
5151
; 0: 14 02 2a xconst8 x2, 42
52-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
52+
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
5353
; a: 00 ret
5454
; b: 00 ret
5555

@@ -69,7 +69,7 @@ block0(v0: i64):
6969
;
7070
; Disassembled:
7171
; 0: 14 02 2a xconst8 x2, 42
72-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
72+
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
7373
; a: 00 ret
7474
; b: 00 ret
7575

@@ -89,7 +89,7 @@ block0(v0: i64):
8989
;
9090
; Disassembled:
9191
; 0: 14 02 2a xconst8 x2, 42
92-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
92+
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
9393
; a: 00 ret
9494
; b: 00 ret
9595

@@ -124,7 +124,7 @@ block2:
124124
; 6: 00 ret
125125
; 7: 14 05 2a xconst8 x5, 42
126126
; a: 14 06 00 xconst8 x6, 0
127-
; d: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0xd
127+
; d: 0c 05 06 08 00 00 00 br_if_xneq64 x5, x6, 0x8 // target = 0x15
128128
; 14: 00 ret
129129
; 15: 00 ret
130130

@@ -158,7 +158,7 @@ block2:
158158
; 0: 03 00 14 00 00 00 br_if x0, 0x14 // target = 0x14
159159
; 6: 14 04 00 xconst8 x4, 0
160160
; 9: 14 05 00 xconst8 x5, 0
161-
; c: 0c 00 00 00 00 00 00 br_if_xneq64 x0, x0, 0x0 // target = 0xc
161+
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
162162
; 13: 00 ret
163163
; 14: 00 ret
164164
; 15: 00 ret

cranelift/filetests/filetests/isa/pulley64/trap.clif

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ block0(v0: i64):
2929
;
3030
; Disassembled:
3131
; 0: 14 02 2a xconst8 x2, 42
32-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
32+
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
3333
; a: 00 ret
3434
; b: 00 ret
3535

@@ -49,7 +49,7 @@ block0(v0: i64):
4949
;
5050
; Disassembled:
5151
; 0: 14 02 2a xconst8 x2, 42
52-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
52+
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
5353
; a: 00 ret
5454
; b: 00 ret
5555

@@ -69,7 +69,7 @@ block0(v0: i64):
6969
;
7070
; Disassembled:
7171
; 0: 14 02 2a xconst8 x2, 42
72-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
72+
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
7373
; a: 00 ret
7474
; b: 00 ret
7575

@@ -89,7 +89,7 @@ block0(v0: i64):
8989
;
9090
; Disassembled:
9191
; 0: 14 02 2a xconst8 x2, 42
92-
; 3: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0x3
92+
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
9393
; a: 00 ret
9494
; b: 00 ret
9595

@@ -124,7 +124,7 @@ block2:
124124
; 6: 00 ret
125125
; 7: 14 05 2a xconst8 x5, 42
126126
; a: 14 06 00 xconst8 x6, 0
127-
; d: 0b 00 00 00 00 00 00 br_if_xeq64 x0, x0, 0x0 // target = 0xd
127+
; d: 0c 05 06 08 00 00 00 br_if_xneq64 x5, x6, 0x8 // target = 0x15
128128
; 14: 00 ret
129129
; 15: 00 ret
130130

@@ -158,7 +158,7 @@ block2:
158158
; 0: 03 00 14 00 00 00 br_if x0, 0x14 // target = 0x14
159159
; 6: 14 04 00 xconst8 x4, 0
160160
; 9: 14 05 00 xconst8 x5, 0
161-
; c: 0c 00 00 00 00 00 00 br_if_xneq64 x0, x0, 0x0 // target = 0xc
161+
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
162162
; 13: 00 ret
163163
; 14: 00 ret
164164
; 15: 00 ret

tests/disas/pulley/loads.wat

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;;! target = "pulley32"
2+
;;! test = "compile"
3+
;;! flags = "-Ccranelift-enable-heap-access-spectre-mitigation=no"
4+
5+
(module
6+
(memory 0)
7+
(func $i32 (param i32) (result i32)
8+
local.get 0
9+
i32.load
10+
)
11+
12+
(func $i64 (param i32) (result i64)
13+
local.get 0
14+
i64.load
15+
)
16+
)
17+
18+
;; wasm[0]::function[0]::i32:
19+
;; xconst8 spilltmp0, -16
20+
;; xadd32 sp, sp, spilltmp0
21+
;; store64_offset8 sp, 8, lr
22+
;; store64 sp, fp
23+
;; xmov fp, sp
24+
;; load32_u_offset8 x6, x0, 52
25+
;; br_if_xult32 x6, x2, 0x1f // target = 0x33
26+
;; 1b: load32_u_offset8 x7, x0, 48
27+
;; xadd32 x7, x7, x2
28+
;; load32_u x0, x7
29+
;; load64_offset8 lr, sp, 8
30+
;; load64 fp, sp
31+
;; xconst8 spilltmp0, 16
32+
;; xadd32 sp, sp, spilltmp0
33+
;; ret
34+
;; 33: ret
35+
;;
36+
;; wasm[0]::function[1]::i64:
37+
;; xconst8 spilltmp0, -16
38+
;; xadd32 sp, sp, spilltmp0
39+
;; store64_offset8 sp, 8, lr
40+
;; store64 sp, fp
41+
;; xmov fp, sp
42+
;; load32_u_offset8 x6, x0, 52
43+
;; br_if_xult32 x6, x2, 0x1f // target = 0x33
44+
;; 1b: load32_u_offset8 x7, x0, 48
45+
;; xadd32 x7, x7, x2
46+
;; load64 x0, x7
47+
;; load64_offset8 lr, sp, 8
48+
;; load64 fp, sp
49+
;; xconst8 spilltmp0, 16
50+
;; xadd32 sp, sp, spilltmp0
51+
;; ret
52+
;; 33: ret

0 commit comments

Comments
 (0)