[lld] [LLD][ELF] Do not reuse thunks in OVERLAYs (PR #200415)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 07:34:38 PDT 2026


smithp35 wrote:

> For `--icf=` we suppress folding when the output sections are different https://reviews.llvm.org/D66717 . This patch uses a more conservative condition (inOverlay) because thunk reuse has a weaker requirement.

Thanks for pointing that. The essential requirement for reusing a thunk in another OutputSection is that the OutputSection is present in memory at the same time as the caller. Not sure if that's significantly weaker than the requirements for ICF though.  

Thunks are a little bit more complicated in that there are Thunks that prefix their targets, as these are logically alternative entry points we can't blanket exclude these from reuse. There's no advantage in doing so, and could cause more problems than it solves. I've altered the implementation to do that and have added a test.

I think it could be possible to restrict the other Thunks to the same Output Section, there are test failures when I tried it, but I'm sure these could be fixed up. My preference would be to not do that by default as I think the vast majority of programs would benefit more from the additional reuse.


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


More information about the llvm-commits mailing list