summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/SyntheticSections.cpp7
-rw-r--r--lld/ELF/Writer.cpp2
2 files changed, 4 insertions, 5 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 1f8df13f9bf..66b5351de4a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -656,9 +656,10 @@ uint64_t GotSection::getGlobalDynOffset(const SymbolBody &B) const {
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) {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index b4342a93c56..0e27bc98662 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1187,8 +1187,6 @@ static void removeUnusedSyntheticSections() {
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) {
OpenPOWER on IntegriCloud