[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


https://github.com/smithp35 commented:

As you'll have noticed, this change will need quite a lot of the existing thunk tests updated. Do take care with that as some of the tests have been carefully chosen to trigger edge cases in the code and this may have depended on the order of thunks.

There could even be a case for making an opt out command-line `-z no-sort-thunksections` which could be added to existing tests.

There is one downside to reordering the order of thunks, it does increase the chances that a BL to a thunk in the thunk section drifts out of range. As the current order matches is that of ascending caller address. There is code to handle this case by inserting a thunk directly adjacent to its caller. That is likely less of a concern than failing to converge though.

An alternate idea that doesn't involve sorting, is to always make the short-thunks the same size as long ones by padding up to the long-thunk size with NOPS. That way if a short thunk becomes a long, later sections aren't changed and if no more thunks have been added, keeps the Thunk Section size the same. It does that at the expense of some code-size.

https://github.com/llvm/llvm-project/pull/209962


More information about the llvm-commits mailing list