[llvm] [BOLT] Check entry point address is not in constant island (PR #163418)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 14 09:04:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Asher Dobrescu (Asher8118)
<details>
<summary>Changes</summary>
There are cases where `addEntryPointAtOffset` is called with a given `Offset` that points to an address within a constant island. This triggers `assert(!isInConstantIsland(EntryPointAddress)` and causes BOLT to crash. This patch adds a check which ignores functions that would add such entry points and warns the user.
---
Full diff: https://github.com/llvm/llvm-project/pull/163418.diff
2 Files Affected:
- (modified) bolt/lib/Core/BinaryContext.cpp (+11-2)
- (added) bolt/test/AArch64/constant-island-entry.s (+35)
``````````diff
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index dd0d041692484..c35775464751b 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1336,8 +1336,17 @@ void BinaryContext::processInterproceduralReferences() {
<< Function.getPrintName() << " and "
<< TargetFunction->getPrintName() << '\n';
}
- if (uint64_t Offset = Address - TargetFunction->getAddress())
- TargetFunction->addEntryPointAtOffset(Offset);
+ if (uint64_t Offset = Address - TargetFunction->getAddress()) {
+ if (!TargetFunction->isInConstantIsland(Address)) {
+ TargetFunction->addEntryPointAtOffset(Offset);
+ } else {
+ TargetFunction->setIgnored();
+ this->outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
+ << Twine::utohexstr(Address)
+ << " in constant island of function " << *TargetFunction
+ << '\n';
+ }
+ }
continue;
}
diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s
new file mode 100644
index 0000000000000..bd0906d87f15f
--- /dev/null
+++ b/bolt/test/AArch64/constant-island-entry.s
@@ -0,0 +1,35 @@
+// This test checks that we ignore functions which add an entry point that
+// is in a costant island.
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-linux-gnu %s -o %t.o
+# RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
+# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+
+# CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
+
+.globl func
+.type func, %function
+func:
+ ret
+ nop
+ b .Lafter_constant
+
+.type constant_island, %object
+constant_island:
+ .xword 0xabcdef
+
+.Lafter_constant:
+ ret
+ .size func, .-func
+
+.globl caller
+.type caller, %function
+caller:
+ bl constant_island
+ ret
+
+.globl main
+.type main, %function
+main:
+ bl caller
+ ret
``````````
</details>
https://github.com/llvm/llvm-project/pull/163418
More information about the llvm-commits
mailing list