[llvm-branch-commits] [lld] [lld][macho] Track max thunks to create and remove --slop_scale (PR #193372)
Ellis Hoag via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Apr 29 15:08:22 PDT 2026
================
@@ -200,27 +200,35 @@ void TextOutputSection::finalize() {
branchesToProcess;
SmallVector<std::tuple<ConcatInputSection *, Relocation *, Defined *>>
deferredBranchRedirects;
+ unsigned numPendingThunkTargets = 0;
- const uint64_t slop = config->slopScale * thunkSize;
for (auto *isec : inputs) {
while (!branchesToProcess.empty()) {
auto &[callerIsec, r, thunkKey] = branchesToProcess.front();
assert(callerIsec->isFinal);
+ auto &thunkInfo = thunkMap[thunkKey];
if (isTargetInRange(*callerIsec, *r)) {
+ if (thunkInfo.pendingBranches.erase(r))
+ if (thunkInfo.pendingBranches.empty())
+ --numPendingThunkTargets;
branchesToProcess.pop_front();
continue;
}
if (auto *sym = getThunkInRange(*callerIsec, *r)) {
+ // The pending thunk target was already decremented when we created the
+ // thunk
deferredBranchRedirects.emplace_back(callerIsec, r, sym);
branchesToProcess.pop_front();
continue;
}
uint64_t highVA = callerIsec->getVA() + r->offset + forwardBranchRange;
uint64_t nextEnd =
alignToPowerOf2(addr + size, isec->align) + isec->getSize();
- if (nextEnd + slop <= highVA)
+ if (nextEnd + numPendingThunkTargets * thunkSize <= highVA)
break;
+ thunkInfo.pendingBranches.clear();
----------------
ellishg wrote:
Yes there could be. But we are about to create this thunk so we know it is no longer pending. This is why when we resolve a relocation we must check if we deleted it from `pendingBranches`.
```
if (thunkInfo.pendingBranches.erase(r))
if (thunkInfo.pendingBranches.empty())
--numPendingThunkTargets;
```
https://github.com/llvm/llvm-project/pull/193372
More information about the llvm-branch-commits
mailing list