[lld] [lld][ELF] Sort thunks by their destination to allow quicker convergence (PR #209962)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 06:28:50 PDT 2026
smithp35 wrote:
As an aside, there are more things that can be done to reduce the number of thunks, but they would require a more complex approach. Arm's proprietary linker, that faced similar problems for Thumb-1 (prior to v6) where the furthest branch range was 4 MiB so programs ended up with a lot of thunks. Main things:
* Many programs have a pareto like 20% of functions get 80% of the function calls, think of memcpy in a C program. Find these and move them closest to the highest density of callers.
* The default section layout is by object file, or by name or alignment. Many programs are structured like a tree (via branch instructions), so a flattened tree can often minimise the distance between branches.
* Instead of placing thunks in pools, find intervals [lowest, highest) where thunks can be inserted based on the addresses of the callers. For each destination there will be a list of disjoint intervals to insert a Thunk in.
I didn't attempt to add these into LLD as they would add significant complexity, for one relative niche target at the time.
https://github.com/llvm/llvm-project/pull/209962
More information about the llvm-commits
mailing list