[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.

llvm-svn: 335140
This commit is contained in:
Simon Atanasyan 2018-06-20 15:58:48 +00:00
parent 192184c5f8
commit 6d163c5feb
2 changed files with 28 additions and 34 deletions

View File

@ -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);

View File

@ -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