summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/SyntheticSections.cpp21
-rw-r--r--lld/test/ELF/mips-mgot.s41
2 files changed, 28 insertions, 34 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index f66da1889b0..2cb41d59570 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -848,17 +848,22 @@ template <class ELFT> void MipsGotSection::build() {
}
}
- // 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);
diff --git a/lld/test/ELF/mips-mgot.s b/lld/test/ELF/mips-mgot.s
index e911d5d0f0e..2151b68fe0d 100644
--- a/lld/test/ELF/mips-mgot.s
+++ b/lld/test/ELF/mips-mgot.s
@@ -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
OpenPOWER on IntegriCloud