[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:04:21 PDT 2026
================
@@ -4107,7 +4084,21 @@ InputSection *ThunkSection::getTargetInputSection() const {
return t->getTargetInputSection();
}
-bool ThunkSection::assignOffsets() {
+bool ThunkSection::assignOffsets(bool sort) {
+ if (sort) {
----------------
smithp35 wrote:
If I've understood the logic here. Then for the following example
```
destA
destB
...
thunks
...
destC
destD
```
Then with thunks expanded this would have the ordering
```
destA
destB
...
backwards B
backwards A
...
forwards D
forwards C
...
destC
destD
```
I think that the main benefit of this ordering is that it would push the long thunks from the start to the centre, and by having the furthest away short thunks close to the middle, they will go to long middle out, which won't increase the distance between any of the other short-thunks and their targets.
This took me a while to think through as it seemed like this ordering is putting the short-thunk that has the furthest away destination closer to the centre where it is more likely to go out of range.
Would you be able to expand the comment, possibly with an example showing the order, and an explanation of why the ordering minimises the number of short-thunks displaced.
https://github.com/llvm/llvm-project/pull/209962
More information about the llvm-commits
mailing list