[lld] r314099 - [ELF] - Simplify removeUnusedSyntheticSections a bit.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 02:46:33 PDT 2017


Author: grimar
Date: Mon Sep 25 02:46:33 2017
New Revision: 314099

URL: http://llvm.org/viewvc/llvm-project?rev=314099&view=rev
Log:
[ELF] - Simplify removeUnusedSyntheticSections a bit.

Previously`InX::Got` and InX::MipsGot synthetic sections
were not removed if ElfSym::GlobalOffsetTable was defined.
ElfSym::GlobalOffsetTable is a symbol for _GLOBAL_OFFSET_TABLE_.

Patch moves ElfSym::GlobalOffsetTable check out from removeUnusedSyntheticSections.
Also note that there was no point to check ElfSym::GlobalOffsetTable for MIPS case
because InX::MipsGot::empty() always returns false for non-relocatable case, and in case
of relocatable output we do not create special symbols anyways.

Differential revision: https://reviews.llvm.org/D37623

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=314099&r1=314098&r2=314099&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Sep 25 02:46:33 2017
@@ -656,9 +656,10 @@ uint64_t GotSection::getGlobalDynOffset(
 void GotSection::finalizeContents() { Size = NumEntries * Config->Wordsize; }
 
 bool GotSection::empty() const {
-  // If we have a relocation that is relative to GOT (such as GOTOFFREL),
-  // we need to emit a GOT even if it's empty.
-  return NumEntries == 0 && !HasGotOffRel;
+  // We need to emit a GOT even if it's empty if there's a relocation that is
+  // relative to GOT(such as GOTOFFREL) or there's a symbol that points to a GOT
+  // (i.e. _GLOBAL_OFFSET_TABLE_).
+  return NumEntries == 0 && !HasGotOffRel && !ElfSym::GlobalOffsetTable;
 }
 
 void GotSection::writeTo(uint8_t *Buf) {

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=314099&r1=314098&r2=314099&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Sep 25 02:46:33 2017
@@ -1187,8 +1187,6 @@ static void removeUnusedSyntheticSection
     OutputSection *OS = SS->getParent();
     if (!SS->empty() || !OS)
       continue;
-    if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable)
-      continue;
 
     std::vector<BaseCommand *>::iterator Empty = OS->Commands.end();
     for (auto I = OS->Commands.begin(), E = OS->Commands.end(); I != E; ++I) {




More information about the llvm-commits mailing list