Skip to content

Commit a363481

Browse files
committed
[BOLT] Refactor MCInst target symbol lookup. NFCI
In analyzeInstructionForFuncReference(), use MCPlusBuilder interface while scanning symbolic operands of MCInst. Should be NFC on x86, but will make the function work on other architectures. Note that it's currently unused on non-x86 as its functionality is exclusive to safe ICF that runs on x86 only.
1 parent 1618d09 commit a363481

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,15 +1544,11 @@ MCSymbol *BinaryFunction::registerBranch(uint64_t Src, uint64_t Dst) {
15441544
}
15451545

15461546
void BinaryFunction::analyzeInstructionForFuncReference(const MCInst &Inst) {
1547-
for (const MCOperand &Op : MCPlus::primeOperands(Inst)) {
1548-
if (!Op.isExpr())
1547+
for (unsigned OpNum = 0; OpNum < MCPlus::getNumPrimeOperands(Inst); ++OpNum) {
1548+
const MCSymbol *Symbol = BC.MIB->getTargetSymbol(Inst, OpNum);
1549+
if (!Symbol)
15491550
continue;
1550-
const MCExpr &Expr = *Op.getExpr();
1551-
if (Expr.getKind() != MCExpr::SymbolRef)
1552-
continue;
1553-
const MCSymbol &Symbol = cast<MCSymbolRefExpr>(Expr).getSymbol();
1554-
// Set HasAddressTaken for a function regardless of the ICF level.
1555-
if (BinaryFunction *BF = BC.getFunctionForSymbol(&Symbol))
1551+
if (BinaryFunction *BF = BC.getFunctionForSymbol(Symbol))
15561552
BF->setHasAddressTaken(true);
15571553
}
15581554
}

0 commit comments

Comments
 (0)