[llvm] [BOLT] Gadget scanner: analyze functions without CFG information (PR #133461)
Anatoly Trosinenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 7 12:39:54 PDT 2025
================
@@ -522,37 +639,34 @@ Analysis::findGadgets(BinaryFunction &BF,
MCPlusBuilder::AllocatorIdTy AllocatorId) {
FunctionAnalysisResult Result;
- PacRetAnalysis PRA(BF, AllocatorId, {});
- PRA.run();
+ auto PRA = PacRetAnalysis::create(BF, AllocatorId, {});
+ PRA->run();
LLVM_DEBUG({
dbgs() << " After PacRetAnalysis:\n";
BF.dump();
});
BinaryContext &BC = BF.getBinaryContext();
- for (BinaryBasicBlock &BB : BF) {
- for (int64_t I = 0, E = BB.size(); I < E; ++I) {
- MCInstReference Inst(&BB, I);
- const State &S = *PRA.getStateBefore(Inst);
-
- // If non-empty state was never propagated from the entry basic block
- // to Inst, assume it to be unreachable and report a warning.
- if (S.empty()) {
- Result.Diagnostics.push_back(std::make_shared<GenericReport>(
- Inst, "Warning: unreachable instruction found"));
- continue;
- }
-
- if (auto Report = shouldReportReturnGadget(BC, Inst, S))
- Result.Diagnostics.push_back(Report);
-
- if (PacRetGadgetsOnly)
- continue;
-
- if (auto Report = shouldReportCallGadget(BC, Inst, S))
- Result.Diagnostics.push_back(Report);
+ iterateOverInstrs(BF, [&](MCInstReference Inst) {
----------------
atrosinenko wrote:
> I'm guessing that you might've tried to write this line so that it looks like a "traditional" loop
Yes, the idea was exactly like this.
https://github.com/llvm/llvm-project/pull/133461
More information about the llvm-commits
mailing list