[PATCH] D51089: [LLD] [COFF] Add support for creating range extension thunks for ARM

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 12 08:24:14 PDT 2018


peter.smith added a comment.

In https://reviews.llvm.org/D51089#1231980, @ruiu wrote:

> Sorry for the belated response. I was thinking of this patch for a while.
>
> Every time I saw the code of thunk range extension, I wonder if we really need this multi-pass algorithm which add thunks iterative on each pass. I believe in almost all cases, the algorithm finishes on the first iteration, if we allow a very small margin when determining "reachability". As long as a margin is small, size increase by allowing a margin should be negligible.
>
> For pathetic executables for which we need to generate tons of thunks (which enlarges distance between callers and callees and thus need multiple passes with the current algorithm), we can simply discard everything that we made in the previous iteration instead of keeping them, double the margin, and then try again from scratch. In practice, I believe that fallback doesn't happen too frequently.
>
> What do you think of the algorithm? If it works, I prefer that algorithm because discarding everything and redo with a larger margin is simpler than keeping thunks created in previous passes.


It can work; I worked on a proprietary linker for embedded systems that used that algorithm,  It worked well enough 99% of the time. It could fail with nasty corner cases though, for example increasing the margin means more calls go out of range which leads to more thunks etc. Having said that I suspect that won't be a problem for COFF as most of the failures were a combination of a strange linker script and number of Thunks (Thumb branch range used to be 4 Megabytes, so there could be Thousands of thunks in a large project).


https://reviews.llvm.org/D51089





More information about the llvm-commits mailing list