From 19d6ce9d8e2e587d4b5ef2b7b63b36203c5d66e8 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Mon, 25 Sep 2017 09:46:33 +0000 Subject: [PATCH] [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 llvm-svn: 314099 --- lld/ELF/SyntheticSections.cpp | 7 ++++--- lld/ELF/Writer.cpp | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 1f8df13..66b5351 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 b4342a9..0e27bc9 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::iterator Empty = OS->Commands.end(); for (auto I = OS->Commands.begin(), E = OS->Commands.end(); I != E; ++I) { -- 2.7.4