[PATCH] D132495: [BOLT] Verify externally referenced blocks against jump table targets
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 22:02:50 PDT 2022
Amir updated this revision to Diff 455794.
Amir added a comment.
Mark as non-simple
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132495/new/
https://reviews.llvm.org/D132495
Files:
bolt/lib/Core/BinaryFunction.cpp
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -1860,6 +1860,40 @@
if (HasFixedIndirectBranch)
return false;
+ // Validate that all data references to function offsets are claimed by
+ // recognized jump tables. Register externally referenced blocks as entry
+ // points.
+ if (!opts::StrictMode && hasInternalReference()) {
+ SmallPtrSet<MCSymbol *, 4> JTTargets;
+ for (const JumpTable *JT : llvm::make_second_range(JumpTables))
+ JTTargets.insert(JT->Entries.begin(), JT->Entries.end());
+
+ bool UnclaimedReference = false;
+ for (uint64_t Destination : ExternallyReferencedOffsets) {
+ // Ignore __builtin_unreachable().
+ if (Destination == getSize())
+ continue;
+
+ if (BinaryBasicBlock *BB = getBasicBlockAtOffset(Destination)) {
+ bool Found = JTTargets.contains(BB->getLabel());
+ if (Found)
+ continue;
+
+ if (opts::Verbosity >= 1) {
+ outs() << "BOLT-WARNING: unclaimed data to code reference (possibly "
+ << "an unrecognized jump table entry) to " << BB->getName()
+ << " in " << *this << ".\n";
+ }
+ } else if (opts::Verbosity >= 1) {
+ outs() << "BOLT-WARNING: unknown data to code reference to offset "
+ << Twine::utohexstr(Destination) << " in " << *this << ".\n";
+ }
+ UnclaimedReference = true;
+ }
+ if (UnclaimedReference)
+ return false;
+ }
+
if (HasUnknownControlFlow && !BC.HasRelocations)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132495.455794.patch
Type: text/x-patch
Size: 1662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220826/1a2d5814/attachment.bin>
More information about the llvm-commits
mailing list