[all-commits] [llvm/llvm-project] 68ebd0: [lld][macho] Restructure thunk generation algorith...
Ellis Hoag via All-commits
all-commits at lists.llvm.org
Tue May 26 09:42:03 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 68ebd09d5e19c30a79d416940d3400b5637b0f69
https://github.com/llvm/llvm-project/commit/68ebd09d5e19c30a79d416940d3400b5637b0f69
Author: Ellis Hoag <ellis.sparky.hoag at gmail.com>
Date: 2026-05-26 (Tue, 26 May 2026)
Changed paths:
M lld/MachO/ConcatOutputSection.cpp
M lld/MachO/ConcatOutputSection.h
M lld/MachO/InputSection.h
M lld/docs/ReleaseNotes.rst
M lld/test/MachO/arm64-thunks.s
Log Message:
-----------
[lld][macho] Restructure thunk generation algorithm (#193367)
Refactor the algorithm that generates thunks for Mach-O. Prior to this
PR, sections were finalized as early as possible while still leaving
enough room (`slopScale * thunkSize`) for new thunks to be created.
There was also additional bookkeeping
(`estimateBranchTargetThresholdVA()`) so that once all sections were
finalized, we could estimate the end of the stubs sections. This avoided
new thunks to stubs sections in some cases.
In this PR, I've restructured the algorithm to avoid eagerly finalizing
sections. Instead, I maintain a `branchesToProcess` queue to hold
branches that could need to use a thunk. I avoid processing this branch
until its target has been finalized, or if finalizing another section
not leave enough room for new thunks (computed using `slopScale`). This
increases the likelihood that a branch will be direct, rather than use a
thunk, as reflected in the test change. Once all sections are finalized,
we can compute an upper bound on the number of thunks that need to be
created. We use this to estimate the end of the stubs section, allowing
us to keep some direct branches.
For testing, I linked a large binary before and after this PR. Results
show a 0.80% reduction in the number of thunks and 6.6% reduction in
number of thunk calls. The change in the duration of the link was
negligible.
| | Thunk Count | Thunk Calls |
|-| - | - |
| Base | 138499 | 1707623 |
| New | 137395 | 1595313 |
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list