From a363481421a6ba029c019bc702267c988bf8ce89 Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Thu, 27 Feb 2025 13:50:06 -0800 Subject: [PATCH] [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. --- bolt/lib/Core/BinaryFunction.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index ff5eb5cf6e1eb..5a1ff58b72f75 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1544,15 +1544,11 @@ MCSymbol *BinaryFunction::registerBranch(uint64_t Src, uint64_t Dst) { } void BinaryFunction::analyzeInstructionForFuncReference(const MCInst &Inst) { - for (const MCOperand &Op : MCPlus::primeOperands(Inst)) { - if (!Op.isExpr()) + for (unsigned OpNum = 0; OpNum < MCPlus::getNumPrimeOperands(Inst); ++OpNum) { + const MCSymbol *Symbol = BC.MIB->getTargetSymbol(Inst, OpNum); + if (!Symbol) continue; - const MCExpr &Expr = *Op.getExpr(); - if (Expr.getKind() != MCExpr::SymbolRef) - continue; - const MCSymbol &Symbol = cast(Expr).getSymbol(); - // Set HasAddressTaken for a function regardless of the ICF level. - if (BinaryFunction *BF = BC.getFunctionForSymbol(&Symbol)) + if (BinaryFunction *BF = BC.getFunctionForSymbol(Symbol)) BF->setHasAddressTaken(true); } }