[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: streamline issue reporting (PR #131896)

Anatoly Trosinenko via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 20 06:41:05 PDT 2025


================
@@ -480,28 +481,43 @@ static void printBB(const BinaryContext &BC, const BinaryBasicBlock *BB,
 
 static void reportFoundGadgetInSingleBBSingleOverwInst(
     raw_ostream &OS, const BinaryContext &BC, const MCInstReference OverwInst,
-    const MCInstReference RetInst) {
-  BinaryBasicBlock *BB = RetInst.getBasicBlock();
+    const MCInstReference Location) {
+  BinaryBasicBlock *BB = Location.getBasicBlock();
   assert(OverwInst.ParentKind == MCInstReference::BasicBlockParent);
-  assert(RetInst.ParentKind == MCInstReference::BasicBlockParent);
+  assert(Location.ParentKind == MCInstReference::BasicBlockParent);
   MCInstInBBReference OverwInstBB = OverwInst.U.BBRef;
   if (BB == OverwInstBB.BB) {
     // overwriting inst and ret instruction are in the same basic block.
-    assert(OverwInstBB.BBIndex < RetInst.U.BBRef.BBIndex);
+    assert(OverwInstBB.BBIndex < Location.U.BBRef.BBIndex);
     OS << "  This happens in the following basic block:\n";
     printBB(BC, BB);
   }
 }
 
-void Gadget::generateReport(raw_ostream &OS, const BinaryContext &BC) const {
-  GenDiag(RetInst, "non-protected ret found").generateReport(OS, BC);
+void Report::printBasicInfo(raw_ostream &OS, const BinaryContext &BC,
+                            StringRef IssueKind) const {
+  BinaryFunction *BF = Location.getFunction();
+  BinaryBasicBlock *BB = Location.getBasicBlock();
+
+  OS << "\nGS-PAUTH: " << IssueKind;
+  OS << " in function " << BF->getPrintName();
+  if (BB)
+    OS << ", basic block " << BB->getName();
+  OS << ", at address " << llvm::format("%x", Location.getAddress()) << "\n";
+  OS << "  The instruction is ";
+  BC.printInstruction(OS, Location, Location.getAddress(), BF);
+}
 
-  BinaryFunction *BF = RetInst.getFunction();
-  OS << "  The " << OverwritingRetRegInst.size()
-     << " instructions that write to the return register after any "
+void GadgetReport::generateReport(raw_ostream &OS,
+                                  const BinaryContext &BC) const {
+  printBasicInfo(OS, BC, Kind.getDescription());
+
+  BinaryFunction *BF = Location.getFunction();
+  OS << "  The " << OverwritingInstrs.size()
+     << " instructions that write to the affected registers after any "
         "authentication are:\n";
   // Sort by address to ensure output is deterministic.
-  std::vector<MCInstReference> ORRI = OverwritingRetRegInst;
+  std::vector<MCInstReference> ORRI = OverwritingInstrs;
----------------
atrosinenko wrote:

Updated, thanks!

https://github.com/llvm/llvm-project/pull/131896


More information about the llvm-branch-commits mailing list