File: speculation-hardening-sls-blra.mir

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,696 kB
  • sloc: cpp: 7,438,781; ansic: 1,393,871; asm: 1,012,926; python: 241,771; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 8,596; ml: 5,082; perl: 4,730; makefile: 3,591; awk: 3,523; javascript: 2,251; xml: 892; fortran: 672
file content (210 lines) | stat: -rw-r--r-- 7,717 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# RUN: llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu \
# RUN:     -start-before aarch64-sls-hardening -o - %s \
# RUN:     -asm-verbose=0 \
# RUN: | FileCheck %s \
# RUN:     --implicit-check-not=__llvm_slsblr_thunk_aa_x5_x8 \
# RUN:     --implicit-check-not=__llvm_slsblr_thunk_ab_x5_x8 \
# RUN:     --implicit-check-not=__llvm_slsblr_thunk_aaz_x5 \
# RUN:     --implicit-check-not=__llvm_slsblr_thunk_abz_x5

# Pointer Authentication extension introduces more branch-with-link-to-register
# instructions for the BLR SLS hardening to handle, namely BLRAA, BLRAB, BLRAAZ
# and BLRABZ. Unlike the non-authenticating BLR instruction, BLRAA and BLRAB
# accept two register operands (almost 900 combinations for each instruction).
# For that reason, it is not practical to create all possible thunks.

# Check that the BLR SLS hardening transforms BLRA* instructions into
# unconditional BL calls to the correct thunk functions.
# Check that only relevant thunk functions are generated.
--- |
  define void @test_instructions() #0 {
  entry:
    ret void
  }

  define void @test_no_redef() #0 {
  entry:
    ret void
  }

  define void @test_regs() #0 {
  entry:
    ret void
  }

  attributes #0 = { "target-features"="+pauth,+harden-sls-blr" }
...

# Test that all BLRA* instructions are handled.
---
name:            test_instructions
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $lr, $x0, $x1, $x2, $x3

    BLRAA $x0, $x1, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAB $x1, $x2, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAAZ $x2, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRABZ $x3, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    RET undef $lr
...

# Test that the same thunk function is not created twice.
---
name:            test_no_redef
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $lr, $x0, $x1, $x2, $x3, $x4

    ; thunk used by @test_instructions
    BLRAB $x1, $x2, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0

    ; thunk used by this function twice
    BLRAB $x3, $x4, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAB $x3, $x4, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0

    RET undef $lr
...

# Test that all xN registers (except x16, x17, x30 and xzr) are handled.
---
name:            test_regs
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $lr, $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x24, $x25, $x26, $x27, $x28, $fp

    BLRAA $x0, $x1, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x2, $x3, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x4, $x5, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x6, $x7, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x8, $x9, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x10, $x11, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x12, $x13, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x14, $x15, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    ; skipping x16 and x17
    BLRAA $x18, $x19, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x20, $x21, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x22, $x23, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x24, $x25, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x26, $x27, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    BLRAA $x28, $fp, implicit-def $lr, implicit $sp, implicit-def $sp, implicit-def $w0
    RET undef $lr
...

# CHECK-LABEL: test_instructions:
# CHECK-NEXT:    .cfi_startproc
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x0_x1
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_ab_x1_x2
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aaz_x2
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_abz_x3
# CHECK-NEXT:    ret

# CHECK-LABEL: test_no_redef:
# CHECK-NEXT:    .cfi_startproc
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_ab_x1_x2
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_ab_x3_x4
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_ab_x3_x4
# CHECK-NEXT:    ret

# CHECK-LABEL: test_regs:
# CHECK-NEXT:    .cfi_startproc
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x0_x1
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x2_x3
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x4_x5
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x6_x7
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x8_x9
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x10_x11
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x12_x13
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x14_x15
# skipping x16 and x17
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x18_x19
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x20_x21
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x22_x23
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x24_x25
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x26_x27
# CHECK-NEXT:    bl      __llvm_slsblr_thunk_aa_x28_x29
# CHECK-NEXT:    ret

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x0_x1:
# CHECK-NEXT:    mov     x16, x0
# CHECK-NEXT:    braa    x16, x1
# CHECK-NEXT:    dsb     sy
# CHECK-NEXT:    isb

# CHECK-LABEL: __llvm_slsblr_thunk_ab_x1_x2:
# CHECK-NEXT:    mov     x16, x1
# CHECK-NEXT:    brab    x16, x2
# CHECK-NEXT:    dsb     sy
# CHECK-NEXT:    isb

# CHECK-LABEL: __llvm_slsblr_thunk_aaz_x2:
# CHECK-NEXT:    mov     x16, x2
# CHECK-NEXT:    braaz   x16
# CHECK-NEXT:    dsb     sy
# CHECK-NEXT:    isb

# CHECK-LABEL: __llvm_slsblr_thunk_abz_x3:
# CHECK-NEXT:    mov     x16, x3
# CHECK-NEXT:    brabz   x16
# CHECK-NEXT:    dsb     sy
# CHECK-NEXT:    isb

# The instruction *operands* should correspond to the thunk function *name*
# (check that the name is parsed correctly when populating the thunk).

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x2_x3:
# CHECK-NEXT:    mov     x16, x2
# CHECK:         braa    x16, x3

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x4_x5:
# CHECK-NEXT:    mov     x16, x4
# CHECK:         braa    x16, x5

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x6_x7:
# CHECK-NEXT:    mov     x16, x6
# CHECK:         braa    x16, x7

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x8_x9:
# CHECK-NEXT:    mov     x16, x8
# CHECK:         braa    x16, x9

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x10_x11:
# CHECK-NEXT:    mov     x16, x10
# CHECK:         braa    x16, x11

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x12_x13:
# CHECK-NEXT:    mov     x16, x12
# CHECK:         braa    x16, x13

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x14_x15:
# CHECK-NEXT:    mov     x16, x14
# CHECK:         braa    x16, x15

# skipping x16 and x17

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x18_x19:
# CHECK-NEXT:    mov     x16, x18
# CHECK:         braa    x16, x19

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x20_x21:
# CHECK-NEXT:    mov     x16, x20
# CHECK:         braa    x16, x21

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x22_x23:
# CHECK-NEXT:    mov     x16, x22
# CHECK:         braa    x16, x23

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x24_x25:
# CHECK-NEXT:    mov     x16, x24
# CHECK:         braa    x16, x25

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x26_x27:
# CHECK-NEXT:    mov     x16, x26
# CHECK:         braa    x16, x27

# CHECK-LABEL: __llvm_slsblr_thunk_aa_x28_x29:
# CHECK-NEXT:    mov     x16, x28
# CHECK:         braa    x16, x29