[lld] [lld-macho] Fix branch extension thunk estimation logic (PR #120529)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 15:32:18 PST 2025
================
@@ -184,15 +184,45 @@ uint64_t TextOutputSection::estimateStubsInRangeVA(size_t callIdx) const {
InputSection *isec = inputs[i];
isecEnd = alignToPowerOf2(isecEnd, isec->align) + isec->getSize();
}
+
+ // Tally up any thunks that have already been placed that have VA higher than
+ // inputs[callIdx]. First, find the index of the first thunk that is beyond
+ // the current inputs[callIdx].
+ auto itPostcallIdxThunks =
+ llvm::partition_point(thunks, [isecVA](const ConcatInputSection *t) {
+ return t->getVA() <= isecVA;
+ });
+ uint64_t existingForwardThunks = thunks.end() - itPostcallIdxThunks;
+
----------------
alx32 wrote:
I see. Indeed this is very tricky code. I should have clarified better - the thing that is being undercounted is the count of thunks that are needed to adjust the VA. `maxPotentialThunks` is correct, because it's counting the max thunks that can be created in the future - which it does correctly. The issue is that the VA also needs to be adjusted by the existing thunks that haven't been taken into consideration.
The implicit problematic assumption being that `maxPotentialThunks` includes the existing thunks, but it actually doesn't.
https://github.com/llvm/llvm-project/pull/120529
More information about the llvm-commits
mailing list