Should we place the .plt before other text sections?

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 09:00:19 PDT 2016


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
-------------- next part --------------
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 6681f46..0112764 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -497,6 +497,12 @@ static bool compareSectionsNonScript(OutputSectionBase<ELFT> *A,
   if (AIsRelRo != BIsRelRo)
     return AIsRelRo;
 
+  // put plt first
+  bool AIsPLT = A == Out<ELFT>::Plt;
+  bool BIsPLT = B == Out<ELFT>::Plt;
+  if (AIsPLT != BIsPLT)
+    return AIsPLT;
+
   // Some architectures have additional ordering restrictions for sections
   // within the same PT_LOAD.
   if (Config->EMachine == EM_PPC64)


More information about the llvm-commits mailing list