[llvm] [BOLT] Check if symbol is in data area of function (PR #160143)

Asher Dobrescu via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 1 07:58:39 PST 2025


Asher8118 wrote:

Hi Maks, I looked at the PR you shared, I apologise for taking so long to do this and thank you for bringing it to my attention.

It looks like `validateInternalBranch()` is very useful for some of the cases that hit the issue in this PR. Adding this:
```
@@ -2376,10 +2379,9 @@ BinaryFunction *BinaryContext::getFunctionForSymbol(const MCSymbol *Symbol,
   BinaryFunction *BF = BFI->second;
   if (EntryDesc) {
     const uint64_t Address = BF->getAddress() + Symbol->getOffset();
-    if (BF->isInConstantIsland(Address)) {
-      this->outs() << "BOLT-WARNING: symbol " << Symbol->getName()
-                   << " is in data region of function " << BF->getOneName()
-                   << "(0x" << Twine::utohexstr(BF->getAddress()) << ").\n";
+   if (!BF->validateInternalBranch()){
+      BF->setIgnored();
+      return nullptr;
     }
     *EntryDesc = BF->getEntryIDForSymbol(Symbol).value_or(0);
   }
   ```
   and removing the `llvm_unreachable` in `MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset)` fixes the main cases(the test ) in this patch work. Some of the test cases I mention above still fail with a different unreachable(`invalid CFG state to use getInstructionAtOffset()`), but that may be a different issue altogether.

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


More information about the llvm-commits mailing list