Skip to content

Commit 0353abb

Browse files
committed
[BOLT] Support for OpNegateRAState - first half
- when reading binary, drop OpNegateRAState CFIs - change CFI State calculation to ignore OpNegateRAState CFIs
1 parent 61efea9 commit 0353abb

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

bolt/lib/Core/BinaryBasicBlock.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ int32_t BinaryBasicBlock::getCFIStateAtInstr(const MCInst *Instr) const {
201201
InstrSeen = (&Inst == Instr);
202202
continue;
203203
}
204-
if (Function->getBinaryContext().MIB->isCFI(Inst)) {
204+
// Fix: ignoring OpNegateRAState CFIs here, as they dont have a "State"
205+
// number associated with them.
206+
if (Function->getBinaryContext().MIB->isCFI(Inst) &&
207+
(Function->getCFIFor(Inst)->getOperation() !=
208+
MCCFIInstruction::OpNegateRAState)) {
205209
LastCFI = &Inst;
206210
break;
207211
}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,7 @@ struct CFISnapshot {
25962596
void advanceTo(int32_t State) {
25972597
for (int32_t I = CurState, E = State; I != E; ++I) {
25982598
const MCCFIInstruction &Instr = FDE[I];
2599+
assert(Instr.getOperation() != MCCFIInstruction::OpNegateRAState);
25992600
if (Instr.getOperation() != MCCFIInstruction::OpRestoreState) {
26002601
update(Instr, I);
26012602
continue;

bolt/lib/Core/Exceptions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,10 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
632632
// DW_CFA_GNU_window_save and DW_CFA_GNU_NegateRAState just use the same
633633
// id but mean different things. The latter is used in AArch64.
634634
if (Function.getBinaryContext().isAArch64()) {
635-
Function.addCFIInstruction(
636-
Offset, MCCFIInstruction::createNegateRAState(nullptr));
635+
// Fix: not adding OpNegateRAState since the location they are needed
636+
// depends on the order of BasicBlocks, which changes during
637+
// optimizations. They are generated in InsertNegateRAStatePass after
638+
// optimizations instead.
637639
break;
638640
}
639641
if (opts::Verbosity >= 1)

0 commit comments

Comments
 (0)