[PATCH] D49422: [ELF][MIPS] Fix primary GOT sometimes overflowing by one or two words

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 05:52:44 PDT 2018


jrtc27 created this revision.
jrtc27 added a reviewer: atanasyan.
Herald added subscribers: llvm-commits, arichardson, sdardis, emaste.
Herald added a reviewer: espindola.

If we fail to merge a secondary GOT with the primary GOT but so far only
one merged GOT has been created (the primary one), the final element in
MergedGots is the primary GOT. Thus we should not try to merge with this
final element passing IsPrimary=false, since this will ignore the fact
that the destination GOT does in fact need a header, and those extra two
entries can be enough to allow the merge to incorrectly occur. Instead
we should check for this case before attempting the second merge.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D49422

Files:
  ELF/SyntheticSections.cpp


Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -858,7 +858,13 @@
     if (tryMergeGots(MergedGots.front(), SrcGot, true)) {
       File->MipsGotIndex = 0;
     } else {
-      if (!tryMergeGots(MergedGots.back(), SrcGot, false)) {
+      // If this is the first time we failed to merge with the primary GOT,
+      // MergedGots.back() will also be the primary GOT. We must make sure not
+      // to try to merge again with IsPrimary=false, as otherwise, if the
+      // inputs are just right, we could allow the primary GOT to become 1 or 2
+      // words too big due to ignoring the header size.
+      if (MergedGots.size() == 1 ||
+          !tryMergeGots(MergedGots.back(), SrcGot, false)) {
         MergedGots.emplace_back();
         std::swap(MergedGots.back(), SrcGot);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49422.155865.patch
Type: text/x-patch
Size: 909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180717/b6efe6db/attachment.bin>


More information about the llvm-commits mailing list