Skip to content

Commit c75645f

Browse files
committed
[BOLT] Add function splitting lit test without runtime dependency
- Test uses lit and FileCheck to check if OpNegateRAState CFIs are generated in the correct location for function-splitting. - Also fix a bug related to function-splitting.
1 parent 7df2811 commit c75645f

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

bolt/lib/Passes/InsertNegateRAStatePass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
102102
});
103103
// If a function is already split in the input, the first FF can also start
104104
// with Signed state. This covers that scenario as well.
105-
if (BC.MIB->isRASigned(*((*FirstNonEmpty)->begin()))) {
105+
if (BC.MIB->isRASigned(*((*FirstNonEmpty)->begin())) ||
106+
BC.MIB->isAuthenticating(*((*FirstNonEmpty)->begin()))) {
106107
BF.addCFIInstruction(*FirstNonEmpty, (*FirstNonEmpty)->begin(),
107108
MCCFIInstruction::createNegateRAState(nullptr));
108109
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Checking that we generate an OpNegateRAState CFI after the split point,
2+
# when splitting a region with signed RA state.
3+
4+
# REQUIRES: system-linux
5+
6+
# RUN: %clang %cflags -o %t %s
7+
# RUN: %clang %s %cflags -Wl,-q -o %t
8+
# RUN: link_fdata --no-lbr %s %t %t.fdata
9+
# RUN: llvm-bolt %t -o %t.bolt --data %t.fdata -split-functions \
10+
# RUN: --print-only foo --print-split --print-all 2>&1 | FileCheck %s
11+
12+
# Checking that we don't see any OpNegateRAState CFIs before the insertion pass.
13+
# CHECK-NOT: OpNegateRAState
14+
# CHECK: Binary Function "foo" after insert-negate-ra-state-pass
15+
16+
# CHECK: paciasp
17+
# CHECK-NEXT: OpNegateRAState
18+
19+
# CHECK: ------- HOT-COLD SPLIT POINT -------
20+
21+
# CHECK: OpNegateRAState
22+
# CHECK-NEXT: autiasp
23+
# CHECK-NEXT: OpNegateRAState
24+
# CHECK-NEXT: ret
25+
26+
# CHECK: autiasp
27+
# CHECK-NEXT: OpNegateRAState
28+
# CHECK-NEXT: ret
29+
30+
# End of the insert-negate-ra-state-pass logs
31+
# CHECK: Binary Function "foo" after finalize-functions
32+
33+
.text
34+
.globl foo
35+
.type foo, %function
36+
foo:
37+
.cfi_startproc
38+
.entry_bb:
39+
paciasp
40+
.cfi_negate_ra_state // indicating that paciasp changed the RA state to signed
41+
# FDATA: 1 foo #.entry_bb# 10
42+
cmp x0, #0
43+
b.eq .Lcold_bb1
44+
autiasp
45+
.cfi_negate_ra_state // indicating that autiasp changed the RA state to unsigned
46+
ret
47+
.cfi_negate_ra_state // ret has unsigned RA state, but the next inst (autiasp) has signed RA state
48+
.Lcold_bb1:
49+
autiasp
50+
.cfi_negate_ra_state // indicating that autiasp changed the RA state to unsigned
51+
ret
52+
.cfi_endproc
53+
.size foo, .-foo
54+
55+
## Force relocation mode.
56+
.reloc 0, R_AARCH64_NONE

0 commit comments

Comments
 (0)