From 1034c9e342fcefa6ccc529c330969f1cdb49fbbb Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 9 Aug 2016 04:42:01 +0000 Subject: [PATCH] Remove isOutputDynamic and use Out::DynSymTab instead. This patch is to not instantiate DynSymTab and DynStrTab if the output is not a dynamic output. llvm-svn: 278095 --- lld/ELF/LinkerScript.cpp | 2 +- lld/ELF/OutputSections.cpp | 2 +- lld/ELF/Writer.cpp | 38 +++++++++++++++++--------------------- lld/ELF/Writer.h | 1 - 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 0d60e65..57172ff 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -318,7 +318,7 @@ std::vector> LinkerScript::createPhdrs() { Phdr.add(Out::Interp); break; case PT_DYNAMIC: - if (isOutputDynamic()) { + if (Out::DynSymTab) { Phdr.H.p_flags = Out::Dynamic->getPhdrFlags(); Phdr.add(Out::Dynamic); } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 10d08c6..6a56211 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -395,7 +395,7 @@ template unsigned RelocationSection::getRelocOffset() { } template void RelocationSection::finalize() { - this->Header.sh_link = isOutputDynamic() + this->Header.sh_link = Out::DynSymTab ? Out::DynSymTab->SectionIndex : Out::SymTab->SectionIndex; this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f078b8a..2f42127 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -120,9 +120,7 @@ template void elf::writeResult() { PltSection Plt; RelocationSection RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); - StringTableSection DynStrTab(".dynstr", true); StringTableSection ShStrTab(".shstrtab", false); - SymbolTableSection DynSymTab(DynStrTab); VersionTableSection VerSym; VersionNeedSection VerNeed; @@ -134,6 +132,8 @@ template void elf::writeResult() { // Instantiate optional output sections if they are needed. std::unique_ptr> Interp; std::unique_ptr> BuildId; + std::unique_ptr> DynStrTab; + std::unique_ptr> DynSymTab; std::unique_ptr> EhFrameHdr; std::unique_ptr> GnuHashTab; std::unique_ptr> GotPlt; @@ -156,6 +156,11 @@ template void elf::writeResult() { else if (Config->BuildId == BuildIdKind::Hexstring) BuildId.reset(new BuildIdHexstring); + if (!Symtab::X->getSharedFiles().empty() || Config->Pic) { + DynStrTab.reset(new StringTableSection(".dynstr", true)); + DynSymTab.reset(new SymbolTableSection(*DynStrTab)); + } + if (Config->EhFrameHdr) EhFrameHdr.reset(new EhFrameHeader); @@ -185,8 +190,8 @@ template void elf::writeResult() { Out::Bss = &Bss; Out::BuildId = BuildId.get(); - Out::DynStrTab = &DynStrTab; - Out::DynSymTab = &DynSymTab; + Out::DynStrTab = DynStrTab.get(); + Out::DynSymTab = DynSymTab.get(); Out::Dynamic = &Dynamic; Out::EhFrame = &EhFrame; Out::EhFrameHdr = EhFrameHdr.get(); @@ -481,10 +486,6 @@ static bool compareSections(OutputSectionBase *A, return false; } -template bool elf::isOutputDynamic() { - return !Symtab::X->getSharedFiles().empty() || Config->Pic; -} - template static bool isDiscarded(InputSectionBase *S) { return !S || S == &InputSection::Discarded || !S->Live; } @@ -523,7 +524,7 @@ static Symbol *addOptionalSynthetic(StringRef Name, // need these symbols, since IRELATIVE relocs are resolved through GOT // and PLT. For details, see http://www.airs.com/blog/archives/403. template void Writer::addRelIpltSymbols() { - if (isOutputDynamic() || !Out::RelaPlt) + if (Out::DynSymTab || !Out::RelaPlt) return; StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start"; addOptionalSynthetic(S, Out::RelaPlt, 0); @@ -576,7 +577,7 @@ template void Writer::addReservedSymbols() { // static linking the linker is required to optimize away any references to // __tls_get_addr, so it's not defined anywhere. Create a hidden definition // to avoid the undefined symbol error. - if (!isOutputDynamic()) + if (!Out::DynSymTab) Symtab::X->addIgnored("__tls_get_addr"); // If linker script do layout we do not need to create any standart symbols. @@ -685,7 +686,7 @@ template void Writer::finalizeSections() { // It should be okay as no one seems to care about the type. // Even the author of gold doesn't remember why gold behaves that way. // https://sourceware.org/ml/binutils/2002-03/msg00360.html - if (isOutputDynamic()) + if (Out::DynSymTab) Symtab::X->addSynthetic("_DYNAMIC", Out::Dynamic, 0); // Define __rel[a]_iplt_{start,end} symbols if needed. @@ -725,7 +726,7 @@ template void Writer::finalizeSections() { if (Out::SymTab) Out::SymTab->addSymbol(Body); - if (isOutputDynamic() && S->includeInDynsym()) { + if (Out::DynSymTab && S->includeInDynsym()) { Out::DynSymTab->addSymbol(Body); if (auto *SS = dyn_cast>(Body)) if (SS->file()->isNeeded()) @@ -759,7 +760,7 @@ template void Writer::finalizeSections() { // Finalizers fix each section's size. // .dynsym is finalized early since that may fill up .gnu.hash. - if (isOutputDynamic()) + if (Out::DynSymTab) Out::DynSymTab->finalize(); // Fill other section headers. The dynamic table is finalized @@ -771,7 +772,7 @@ template void Writer::finalizeSections() { if (Sec != Out::DynStrTab && Sec != Out::Dynamic) Sec->finalize(); - if (isOutputDynamic()) + if (Out::DynSymTab) Out::Dynamic->finalize(); // Now that all output offsets are fixed. Finalize mergeable sections @@ -817,7 +818,7 @@ template void Writer::addPredefinedSections() { Add(Out::SymTab); Add(Out::ShStrTab); Add(Out::StrTab); - if (isOutputDynamic()) { + if (Out::DynSymTab) { Add(Out::DynSymTab); bool HasVerNeed = Out::VerNeed->getNeedNum() != 0; @@ -979,7 +980,7 @@ std::vector> Writer::createPhdrs() { Ret.push_back(std::move(TlsHdr)); // Add an entry for .dynamic. - if (isOutputDynamic()) { + if (Out::DynSymTab) { Phdr &H = *AddHdr(PT_DYNAMIC, Out::Dynamic->getPhdrFlags()); H.add(Out::Dynamic); } @@ -1286,11 +1287,6 @@ template struct elf::PhdrEntry; template struct elf::PhdrEntry; template struct elf::PhdrEntry; -template bool elf::isOutputDynamic(); -template bool elf::isOutputDynamic(); -template bool elf::isOutputDynamic(); -template bool elf::isOutputDynamic(); - template bool elf::isRelroSection(OutputSectionBase *); template bool elf::isRelroSection(OutputSectionBase *); template bool elf::isRelroSection(OutputSectionBase *); diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h index 3047282..914db53 100644 --- a/lld/ELF/Writer.h +++ b/lld/ELF/Writer.h @@ -25,7 +25,6 @@ template class ObjectFile; template class SymbolTable; template void writeResult(); template void markLive(); -template bool isOutputDynamic(); template bool isRelroSection(OutputSectionBase *Sec); // This describes a program header entry. -- 2.7.4