Should we place the .plt before other text sections?

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 11:19:32 PDT 2016


There isn't any reason why R_ARM_THM_CALL shouldn't work with range
extension thunks. I can make at least ld.bfd generate a
__func_from_thumb thunk to a PLT entry, at least with some assembler.
This was with binutils 2.25.

There may be problems with crtbeginS.o as I notice that the only
R_ARM_THM_CALL (at least in my crtbeginS.o) is via a weak reference
__cxa_finalize which may introduce some problems if it is undefined.
I'll try and see if there is anything I can reproduce as it might be a
bug somewhere in the toolchain.

It is true that placing the PLT closest to the .text section will
minimise the need for long-range thunks, whether this is immediately
before or immediately after shouldn't matter. In theory the best place
is in the middle which would mean that we could go up to 32Mb of .text
size on Thumb 2 without needing a range extension thunk. That would be
a bit messy to implement though.

I'll take a look at the prelink documentation
http://people.redhat.com/jakub/prelink.pdf , when I read it many years
ago it did have some advice on placing the linker created sections to
make its life easier.

To summarise, if placing the PLT early makes it more likely to be
closer to the .text section I'm in favour.

Peter




On 28 September 2016 at 09:00, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
> I noticed a few interesting things while testing Peter's patch on ARM:
>
> * crtbeginS.o and other crt files use R_ARM_THM_CALL to functions
> defined in shared libraries.
> * We don't restrict the order of .plt sections.
> * Gold and bfd seem to always put .plt at the start of the rx PT_LOAD.
> * Gold and bfd assume that a .plt entry is in range when processing
> R_ARM_THM_CALL, but not R_ARM_CALL.
>
> Is there a reason why R_ARM_THM_CALL would not work with range
> extension thunks? The only reason llvm/clang/lld links successfully
> with bfd/gold on ARM is that by putting the .plt early it ends up
> being close to crtbegin.
>
> Should we do the same? I have attached the patch I used for an
> experiment and with it we can link llvm/clang/lld on ARM with the
> exception of clang, clang-check and libclang which hit cases that need
> range extension chunks.
>
> Cheers,
> Rafael


More information about the llvm-commits mailing list