Skip to content

Commit

Permalink
Emit remember_state CFI in the same code region as restore_state.
Browse files Browse the repository at this point in the history
Summary:
While creating remember_state/restore_state CFI sequences, we
were always placing remember_state instruction into the first
basic block. However, when we have hot-cold splitting, the cold
part has and independent FDE entry in .eh_frame, and thus the
restore_state instruction was missing its counter part.

The fix is to adjust the basic block that is used for placing
remember_state instruction whenever we see the hot-cold split
boundary.

(cherry picked from FBD3767102)
  • Loading branch information
maksfb committed Aug 24, 2016
1 parent 97f598f commit 43acb6a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bolt/BinaryFunction.cpp
Expand Up @@ -1540,16 +1540,18 @@ bool BinaryFunction::fixCFIState() {
};

uint32_t State = 0;
BinaryBasicBlock *EntryBB = *BasicBlocksLayout.begin();
auto *FDEStartBB = BasicBlocksLayout[0];
for (uint32_t I = 0, E = BasicBlocksLayout.size(); I != E; ++I) {
BinaryBasicBlock *BB = BasicBlocksLayout[I];
auto *BB = BasicBlocksLayout[I];
uint32_t BBIndex = getIndex(BB);

// Hot-cold border: check if this is the first BB to be allocated in a cold
// region (a different function). If yes, we need to reset the CFI state.
if (I != 0 &&
BB->IsCold != BasicBlocksLayout[I - 1]->IsCold)
// region (a different FDE). If yes, we need to reset the CFI state and
// the FDEStartBB that is used to insert remember_state CFIs (t12863876).
if (I != 0 && BB->IsCold != BasicBlocksLayout[I - 1]->IsCold) {
State = 0;
FDEStartBB = BB;
}

// We need to recover the correct state if it doesn't match expected
// state at BB entry point.
Expand All @@ -1561,10 +1563,10 @@ bool BinaryFunction::fixCFIState() {
// reach the desired state.
uint32_t OldState = BBCFIState[BBIndex];
// Remember state at function entry point (our reference state).
BinaryBasicBlock::const_iterator InsertIt = EntryBB->begin();
while (InsertIt != EntryBB->end() && BC.MIA->isCFI(*InsertIt))
BinaryBasicBlock::const_iterator InsertIt = FDEStartBB->begin();
while (InsertIt != FDEStartBB->end() && BC.MIA->isCFI(*InsertIt))
++InsertIt;
addCFIPseudo(EntryBB, InsertIt, FrameInstructions.size());
addCFIPseudo(FDEStartBB, InsertIt, FrameInstructions.size());
FrameInstructions.emplace_back(
MCCFIInstruction::createRememberState(nullptr));
// Restore state
Expand Down

0 comments on commit 43acb6a

Please sign in to comment.