[PATCH] D124653: [ELF] Fix ThunkSection distance computation

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 19:09:14 PDT 2022


MaskRay created this revision.
MaskRay added a reviewer: peter.smith.
Herald added subscribers: StephenFan, kristof.beyls, arichardson, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Similar to D117734 <https://reviews.llvm.org/D117734>. Take AArch64 as an example when the branch range is +-0x8000000.

getISDThunkSec returns `ts` when `src-0x8000000-r_addend <= tsBase < src-0x8000000`
and the new thunk will be placed in `ts` (`ts->addThunk(t)`). However, the new
thunk (at the end of ts) may be unreachable from src. The bug is extremely rare
but I have observed it in one test with a sufficiently large r_addend (47664):
there are initially 245 Thunk's, then in each iteration 14 Thunk's cannot be reached and
get appended to the unreachable ThunkSection. After 15 iterations lld fails with
`thunk creation not converged`.

---

Still figuring out a test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124653

Files:
  lld/ELF/Relocations.cpp


Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -1872,8 +1872,8 @@
                                            uint64_t src) {
   for (std::pair<ThunkSection *, uint32_t> tp : isd->thunkSections) {
     ThunkSection *ts = tp.first;
-    uint64_t tsBase = os->addr + ts->outSecOff + rel.addend;
-    uint64_t tsLimit = tsBase + ts->getSize() + rel.addend;
+    uint64_t tsBase = os->addr + ts->outSecOff;
+    uint64_t tsLimit = tsBase + ts->getSize();
     if (target->inBranchRange(rel.type, src,
                               (src > tsLimit) ? tsBase : tsLimit))
       return ts;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124653.425945.patch
Type: text/x-patch
Size: 694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220429/7594e25f/attachment.bin>


More information about the llvm-commits mailing list