[BOLT] Accept PLT fall-throughs as valid traces (#129481)

We used to report PLT traces as invalid (mismatching disassembled
function contents) because PLT functions are marked as pseudo and
ignored, thus missing CFG. However, such traces are not mismatching
the function contents. Accept them without attaching the profile.

Test Plan: updated callcont-fallthru.s
This commit is contained in:
Amir Ayupov
2025-04-11 21:26:19 -07:00
committed by GitHub
parent 3a2d9a7c1e
commit fa4ac19f0f
3 changed files with 34 additions and 6 deletions

View File

@@ -871,11 +871,6 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
BinaryContext &BC = BF.getBinaryContext();
if (!BF.isSimple())
return std::nullopt;
assert(BF.hasCFG() && "can only record traces in CFG state");
// Offsets of the trace within this function.
const uint64_t From = FirstLBR.To - BF.getAddress();
const uint64_t To = SecondLBR.From - BF.getAddress();
@@ -883,6 +878,20 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
if (From > To)
return std::nullopt;
// Accept fall-throughs inside pseudo functions (PLT/thunks).
// This check has to be above BF.empty as pseudo functions would pass it:
// pseudo => ignored => CFG not built => empty.
// If we return nullopt, trace would be reported as mismatching disassembled
// function contents which it is not. To avoid this, return an empty
// fall-through list instead.
if (BF.isPseudo())
return Branches;
if (!BF.isSimple())
return std::nullopt;
assert(BF.hasCFG() && "can only record traces in CFG state");
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);