Skip to content

Commit c8c0e90

Browse files
authored
[BOLT] Ensure remember and restore CFIs are in the same list (#144348)
In `addCFIInstruction`, we split the CFI information between `CFIInstrMapType CIEFrameInstructions` and `CFIInstrMapType FrameInstructions`. In some cases we can end up with the remember CFI in `CIEFrameInstructions` and the restore CFI in `FrameInstructions`. This patch adds a check to make sure we do not split remember and restore states and fixes #133501.
1 parent 0227aef commit c8c0e90

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,11 @@ class BinaryFunction {
16631663
Offset = I->first;
16641664
}
16651665
assert(I->first == Offset && "CFI pointing to unknown instruction");
1666-
if (I == Instructions.begin()) {
1666+
// When dealing with RememberState, we place this CFI in FrameInstructions.
1667+
// We want to ensure RememberState and RestoreState CFIs are in the same
1668+
// list in order to properly populate the StateStack.
1669+
if (I == Instructions.begin() &&
1670+
Inst.getOperation() != MCCFIInstruction::OpRememberState) {
16671671
CIEFrameInstructions.emplace_back(std::forward<MCCFIInstruction>(Inst));
16681672
return;
16691673
}

bolt/test/AArch64/cfi-state-list.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test checks that BOLT does not split remember and restore CFI states
2+
// into different lists, which would cause an assertion failure.
3+
4+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
5+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
6+
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
7+
8+
# CHECK: BOLT-INFO: Starting stub-insertion pass
9+
10+
.text
11+
.global main
12+
.type main, %function
13+
14+
main:
15+
.cfi_startproc
16+
.cfi_remember_state
17+
mov w0, wzr
18+
b.ne .L1
19+
.L0:
20+
mov w0, wzr
21+
.L1:
22+
cmp x0, #0
23+
b.lt .L2
24+
.L2:
25+
nop
26+
.cfi_restore_state
27+
mov x8, xzr
28+
b.ls .L0
29+
ret
30+
.cfi_endproc
31+
.size main, .-main
32+
33+
## Force relocation mode.
34+
.reloc 0, R_AARCH64_NONE

0 commit comments

Comments
 (0)