[lld] [lld-macho] Fix branch extension thunk estimation logic (PR #120529)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 17:43:46 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:
Hmm not quite. From debugging there was no opportunity to actually improve the estimation to work in all cases (without changing the fundamental algorithm). The already placed thunks were just being ignored - basically forgotten to be taken into consideration. I am not sure if your proposal will work - I don't think it will for all cases - there are a few more variables in play.
I do think that we can improve the algorithm a bit - but I this is the direct fix for the current bug.
I am hesitant to try to improve the underlying algorithm right now as that can lead to more issues in unknown scenarios.
https://github.com/llvm/llvm-project/pull/120529
More information about the llvm-commits
mailing list