Skip to content

Commit 30cc9b6

Browse files
maksfbmemfrob
authored andcommitted
[BOLT] Fix handling of RememberState CFI
Summary: When RememberState CFI happens to be the last CFI in a basic block, we used to set the state of the next basic block to a CFI prior to executing RememberState instruction. This contradicts comments in annotateCFIState() function and also differs form behaviour of getCFIStateAtInstr(). As a result we were getting code like the following: .LBB0121166 (21 instructions, align : 1) CFI State : 0 .... 0000001a: !CFI $1 ; OpOffset Reg6 -16 0000001a: !CFI $2 ; OpRememberState .... Successors: .Ltmp4167600, .Ltmp4167601 CFI State: 3 .Ltmp4167601 (13 instructions, align : 1) CFI State : 2 .... Notice that the state at the entry of the 2nd basic block is less than the state at the exit of the previous basic block. In practice we have never seen basic blocks where RememberState was the last CFI instruction in the basic block, and hence we've never run into this issue before. The fix is a synchronization of handling of last RememberState instruction by annotateCFIState() and getCFIStateAtInstr(). In the example above, the CFI state at the entry to the second BB will be 3 after this diff. (cherry picked from FBD6314916)
1 parent 5ebdfed commit 30cc9b6

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

bolt/BinaryFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,7 @@ void BinaryFunction::annotateCFIState() {
23442344
switch (CFI->getOperation()) {
23452345
case MCCFIInstruction::OpRememberState:
23462346
StateStack.push(EffectiveState);
2347+
EffectiveState = State;
23472348
break;
23482349
case MCCFIInstruction::OpRestoreState:
23492350
assert(!StateStack.empty() && "corrupt CFI stack");

0 commit comments

Comments
 (0)