[lld] r335140 - [ELF][MIPS] Fill a primary-GOT as much as possible

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 08:58:48 PDT 2018


Author: atanasyan
Date: Wed Jun 20 08:58:48 2018
New Revision: 335140

URL: http://llvm.org/viewvc/llvm-project?rev=335140&view=rev
Log:
[ELF][MIPS] Fill a primary-GOT as much as possible

While building a Global Offset Table try to fill the primary GOT as much
as possible because the primary GOT can be accessed in the most
effective way. If it is not possible, try to fill the last GOT in the
multi-GOT list, and finally create a new GOT if both attempts failed.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/test/ELF/mips-mgot.s

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=335140&r1=335139&r2=335140&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Jun 20 08:58:48 2018
@@ -848,17 +848,22 @@ template <class ELFT> void MipsGotSectio
     }
   }
 
-  // Merge GOTs. Try to join as much as possible GOTs but do not
-  // exceed maximum GOT size. In case of overflow create new GOT
-  // and continue merging.
+  // Merge GOTs. Try to join as much as possible GOTs but do not exceed
+  // maximum GOT size. At first, try to fill the primary GOT because
+  // the primary GOT can be accessed in the most effective way. If it
+  // is not possible, try to fill the last GOT in the list, and finally
+  // create a new GOT if both attempts failed.
   for (FileGot &SrcGot : Gots) {
-    FileGot &DstGot = MergedGots.back();
     InputFile *File = SrcGot.File;
-    if (!tryMergeGots(DstGot, SrcGot, &DstGot == PrimGot)) {
-      MergedGots.emplace_back();
-      std::swap(MergedGots.back(), SrcGot);
+    if (tryMergeGots(MergedGots.front(), SrcGot, true)) {
+      File->MipsGotIndex = 0;
+    } else {
+      if (!tryMergeGots(MergedGots.back(), SrcGot, false)) {
+        MergedGots.emplace_back();
+        std::swap(MergedGots.back(), SrcGot);
+      }
+      File->MipsGotIndex = MergedGots.size() - 1;
     }
-    File->MipsGotIndex = MergedGots.size() - 1;
   }
   std::swap(Gots, MergedGots);
 

Modified: lld/trunk/test/ELF/mips-mgot.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-mgot.s?rev=335140&r1=335139&r2=335140&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-mgot.s (original)
+++ lld/trunk/test/ELF/mips-mgot.s Wed Jun 20 08:58:48 2018
@@ -13,12 +13,10 @@
 
 # CHECK:      Contents of section .got:
 # CHECK-NEXT:  60000 00000000 80000000 00010000 00010030
-# CHECK-NEXT:  60010 00020000 00030000 00040000 00050000
-# CHECK-NEXT:  60020 00060000 00070000 00000000 00000000
-# CHECK-NEXT:  60030 00000004 00000000 00000000 00000000
-# CHECK-NEXT:  60040 00000000 00020000 00030000 00040000
-# CHECK-NEXT:  60050 00050000 00060000 00070000 00000000
-# CHECK-NEXT:  60060 00000000 00000000 00000000 00000000
+# CHECK-NEXT:  60010 00000000 00000004 00020000 00030000
+# CHECK-NEXT:  60020 00040000 00050000 00060000 00070000
+# CHECK-NEXT:  60030 00000000 00000000 00000000 00000000
+# CHECK-NEXT:  60040 00000000 00000000 00000000
 
 # CHECK: SYMBOL TABLE:
 # CHECK: 00000000 l       .tdata          00000000 loc0
@@ -31,29 +29,20 @@
 
 # GOT:      Relocations [
 # GOT-NEXT:   Section (7) .rel.dyn {
-# GOT-NEXT:     0x60010 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60014 R_MIPS_REL32 - 0x0
 # GOT-NEXT:     0x60018 R_MIPS_REL32 - 0x0
 # GOT-NEXT:     0x6001C R_MIPS_REL32 - 0x0
 # GOT-NEXT:     0x60020 R_MIPS_REL32 - 0x0
 # GOT-NEXT:     0x60024 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60044 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60048 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x6004C R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60050 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60054 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60058 R_MIPS_REL32 - 0x0
-# GOT-NEXT:     0x60028 R_MIPS_REL32 foo0 0x0
-# GOT-NEXT:     0x6005C R_MIPS_REL32 foo0 0x0
-# GOT-NEXT:     0x60060 R_MIPS_REL32 foo2 0x0
-# GOT-NEXT:     0x6003C R_MIPS_TLS_DTPMOD32 - 0x0
-# GOT-NEXT:     0x6002C R_MIPS_TLS_TPREL32 tls0 0x0
-# GOT-NEXT:     0x60034 R_MIPS_TLS_DTPMOD32 tls0 0x0
-# GOT-NEXT:     0x60038 R_MIPS_TLS_DTPREL32 tls0 0x0
-# GOT-NEXT:     0x60064 R_MIPS_TLS_TPREL32 tls0 0x0
-# GOT-NEXT:     0x60068 R_MIPS_TLS_DTPMOD32 tls0 0x0
-# GOT-NEXT:     0x6006C R_MIPS_TLS_DTPREL32 tls0 0x0
-# GOT-NEXT:     0x60030 R_MIPS_TLS_TPREL32 tls1 0x0
+# GOT-NEXT:     0x60028 R_MIPS_REL32 - 0x0
+# GOT-NEXT:     0x6002C R_MIPS_REL32 - 0x0
+# GOT-NEXT:     0x60030 R_MIPS_REL32 foo0 0x0
+# GOT-NEXT:     0x60034 R_MIPS_REL32 foo2 0x0
+# GOT-NEXT:     0x60044 R_MIPS_TLS_DTPMOD32 - 0x0
+# GOT-NEXT:     0x60010 R_MIPS_TLS_TPREL32 tls0 0x0
+# GOT-NEXT:     0x60038 R_MIPS_TLS_TPREL32 tls0 0x0
+# GOT-NEXT:     0x6003C R_MIPS_TLS_DTPMOD32 tls0 0x0
+# GOT-NEXT:     0x60040 R_MIPS_TLS_DTPREL32 tls0 0x0
+# GOT-NEXT:     0x60014 R_MIPS_TLS_TPREL32 tls1 0x0
 # GOT-NEXT:   }
 # GOT-NEXT: ]
 
@@ -106,7 +95,7 @@
 # GOT-NEXT:       Name: foo2
 # GOT-NEXT:     }
 # GOT-NEXT:   ]
-# GOT-NEXT:   Number of TLS and multi-GOT entries: 24
+# GOT-NEXT:   Number of TLS and multi-GOT entries: 15
 # GOT-NEXT: }
 
   .text




More information about the llvm-commits mailing list