Skip to content

Commit 0c28761

Browse files
committed
[BOLT] Improve negate-ra-state-incorrect test
- check all 3 possibilities that MarkRAStates warns about, - simplify the asm functions in the test, - use FileCheck instead of grep on the disassembly.
1 parent 2a5fd80 commit 0c28761

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed
Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
# This test checks that MarkRAStates pass ignores functions with
2+
# malformed .cfi_negate_ra_state sequences in the input binary.
3+
4+
# The cases checked are:
5+
# - extra .cfi_negate_ra_state in Signed state: checked in foo,
6+
# - extra .cfi_negate_ra_state in Unsigned state: checked in bar,
7+
# - missing .cfi_negate_ra_state from PSign or PAuth instructions: checked in baz.
8+
19
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
210
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
3-
# RUN: llvm-bolt %t.exe -o %t.exe.bolt | FileCheck %s
11+
# RUN: llvm-bolt %t.exe -o %t.exe.bolt --no-threads | FileCheck %s --check-prefix=CHECK-BOLT
12+
13+
# CHECK-BOLT: BOLT-INFO: inconsistent RAStates in function foo
14+
# CHECK-BOLT-NEXT: BOLT-INFO: ptr authenticating inst encountered in Unsigned RA state.
415

5-
# check that the output is listing foo as incorrect
6-
# CHECK: BOLT-INFO: inconsistent RAStates in function foo
16+
# CHECK-BOLT: BOLT-INFO: inconsistent RAStates in function bar
17+
# CHECK-BOLT-NEXT: BOLT-INFO: ptr signing inst encountered in Signed RA state
718

8-
# check that foo got Ignored, so it's not in the new .text section
9-
# RUN: llvm-objdump %t.exe.bolt -d -j .text > %t.exe.dump
10-
# RUN: not grep "<foo>:" %t.exe.dump
19+
# CHECK-BOLT: BOLT-INFO: inconsistent RAStates in function baz
20+
# CHECK-BOLT-NEXT: BOLT-INFO: ptr sign/auth inst without .cfi_negate_ra_state
21+
22+
# Check that the incorrect functions got ignored, so they are not in the new .text section
23+
# RUN: llvm-objdump %t.exe.bolt -d -j .text | FileCheck %s --check-prefix=CHECK-OBJDUMP
24+
# CHECK-OBJDUMP-NOT: <foo>:
25+
# CHECK-OBJDUMP-NOT: <bar>:
26+
# CHECK-OBJDUMP-NOT: <baz>:
1127

1228

13-
# How is this test incorrect?
14-
# There is an extra .cfi_negate_ra_state in foo.
15-
# Because of this, we will get to the autiasp (hint #29)
16-
# in a (seemingly) unsigned state. That is incorrect.
1729
.text
1830
.globl foo
1931
.p2align 2
@@ -22,23 +34,50 @@ foo:
2234
.cfi_startproc
2335
hint #25
2436
.cfi_negate_ra_state
25-
sub sp, sp, #16
26-
stp x29, x30, [sp, #16] // 16-byte Folded Spill
27-
.cfi_def_cfa_offset 16
28-
str w0, [sp, #12]
29-
ldr w8, [sp, #12]
37+
mov x1, #0
38+
.cfi_negate_ra_state // Incorrect CFI in signed state
39+
hint #29
40+
.cfi_negate_ra_state
41+
ret
42+
.cfi_endproc
43+
.size foo, .-foo
44+
45+
.text
46+
.globl bar
47+
.p2align 2
48+
.type bar,@function
49+
bar:
50+
.cfi_startproc
51+
mov x1, #0
52+
.cfi_negate_ra_state // Incorrect CFI in unsigned state
53+
hint #25
3054
.cfi_negate_ra_state
31-
add w0, w8, #1
32-
ldp x29, x30, [sp, #16] // 16-byte Folded Reload
33-
add sp, sp, #16
55+
mov x1, #0
3456
hint #29
3557
.cfi_negate_ra_state
3658
ret
37-
.Lfunc_end1:
38-
.size foo, .Lfunc_end1-foo
3959
.cfi_endproc
60+
.size bar, .-bar
61+
62+
.text
63+
.globl baz
64+
.p2align 2
65+
.type baz,@function
66+
baz:
67+
.cfi_startproc
68+
mov x1, #0
69+
hint #25
70+
.cfi_negate_ra_state
71+
mov x1, #0
72+
hint #29
73+
// Missing .cfi_negate_ra_state
74+
ret
75+
.cfi_endproc
76+
.size baz, .-baz
4077

4178
.global _start
4279
.type _start, %function
4380
_start:
4481
b foo
82+
b bar
83+
b baz

0 commit comments

Comments
 (0)