[llvm-branch-commits] [lld] [lld][macho] Fix thunks with multiple text sections (PR #197049)
Vy Nguyen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon May 11 19:03:43 PDT 2026
================
----------------
oontvoo wrote:
This is just a suggestion - but perhaps you could avoid repeated call to isTargetstubsAndInRange() when `estimatedStubsEnd` is `std:nullopt`
Something like this:
```
// 1. keep the original signature
bool isTargetStubsAndInRange(InputSection* isec, Thunk* thunk, uint64_t estimatedStubsEnd);
void finalize() {
// .......
auto estimatedStubsEnd = estimateStubsEndVA(branchTargets.size());
// 2. Wrap BOTH loops in a single lambda
auto processAllBranches = [&](auto hasStubsTag) {
constexpr bool hasStubs = decltype(hasStubsTag)::value;
// Loop 1: Deferred Branch Redirects
for (auto [isec, r, thunk] : deferredBranchRedirects) {
if (isTargetKnownInRange(*isec, *r))
continue;
// This whole branch is gone if estimatedStubsEnd didn't have value
if constexpr (hasStubs) {
if (isTargetStubsAndInRange(*isec, *r, *estimatedStubsEnd))
continue;
}
updateBranchTargetToThunk(*r, thunk);
}
// Loop 2: Branches To Process
for (auto [isec, r] : branchesToProcess) {
if constexpr (hasStubs) {
if (isTargetStubsAndInRange(*isec, *r, *estimatedStubsEnd))
continue;
}
auto &thunkInfo = thunkMap[*r];
if (auto *thunk = getThunkInRange(*isec, *r, thunkInfo)) {
updateBranchTargetToThunk(*r, thunk);
continue;
}
createThunk(*isec, *r, thunkInfo);
}
};
// 3. Dispatch once for the entire processing phase
if (estimatedStubsEnd.has_value()) {
processAllBranches(std::true_type{});
} else {
processAllBranches(std::false_type{});
}
}
```
https://github.com/llvm/llvm-project/pull/197049
More information about the llvm-branch-commits
mailing list