[lld] r278095 - Remove isOutputDynamic and use Out<ELFT>::DynSymTab instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 21:42:01 PDT 2016


Author: ruiu
Date: Mon Aug  8 23:42:01 2016
New Revision: 278095

URL: http://llvm.org/viewvc/llvm-project?rev=278095&view=rev
Log:
Remove isOutputDynamic and use Out<ELFT>::DynSymTab instead.

This patch is to not instantiate DynSymTab and DynStrTab if the
output is not a dynamic output.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=278095&r1=278094&r2=278095&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Aug  8 23:42:01 2016
@@ -318,7 +318,7 @@ std::vector<PhdrEntry<ELFT>> LinkerScrip
         Phdr.add(Out<ELFT>::Interp);
       break;
     case PT_DYNAMIC:
-      if (isOutputDynamic<ELFT>()) {
+      if (Out<ELFT>::DynSymTab) {
         Phdr.H.p_flags = Out<ELFT>::Dynamic->getPhdrFlags();
         Phdr.add(Out<ELFT>::Dynamic);
       }

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=278095&r1=278094&r2=278095&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Aug  8 23:42:01 2016
@@ -395,7 +395,7 @@ template <class ELFT> unsigned Relocatio
 }
 
 template <class ELFT> void RelocationSection<ELFT>::finalize() {
-  this->Header.sh_link = isOutputDynamic<ELFT>()
+  this->Header.sh_link = Out<ELFT>::DynSymTab
                              ? Out<ELFT>::DynSymTab->SectionIndex
                              : Out<ELFT>::SymTab->SectionIndex;
   this->Header.sh_size = Relocs.size() * this->Header.sh_entsize;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=278095&r1=278094&r2=278095&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug  8 23:42:01 2016
@@ -120,9 +120,7 @@ template <class ELFT> void elf::writeRes
   PltSection<ELFT> Plt;
   RelocationSection<ELFT> RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn",
                                   Config->ZCombreloc);
-  StringTableSection<ELFT> DynStrTab(".dynstr", true);
   StringTableSection<ELFT> ShStrTab(".shstrtab", false);
-  SymbolTableSection<ELFT> DynSymTab(DynStrTab);
   VersionTableSection<ELFT> VerSym;
   VersionNeedSection<ELFT> VerNeed;
 
@@ -134,6 +132,8 @@ template <class ELFT> void elf::writeRes
   // Instantiate optional output sections if they are needed.
   std::unique_ptr<InterpSection<ELFT>> Interp;
   std::unique_ptr<BuildIdSection<ELFT>> BuildId;
+  std::unique_ptr<StringTableSection<ELFT>> DynStrTab;
+  std::unique_ptr<SymbolTableSection<ELFT>> DynSymTab;
   std::unique_ptr<EhFrameHeader<ELFT>> EhFrameHdr;
   std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab;
   std::unique_ptr<GotPltSection<ELFT>> GotPlt;
@@ -156,6 +156,11 @@ template <class ELFT> void elf::writeRes
   else if (Config->BuildId == BuildIdKind::Hexstring)
     BuildId.reset(new BuildIdHexstring<ELFT>);
 
+  if (!Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic) {
+    DynStrTab.reset(new StringTableSection<ELFT>(".dynstr", true));
+    DynSymTab.reset(new SymbolTableSection<ELFT>(*DynStrTab));
+  }
+
   if (Config->EhFrameHdr)
     EhFrameHdr.reset(new EhFrameHeader<ELFT>);
 
@@ -185,8 +190,8 @@ template <class ELFT> void elf::writeRes
 
   Out<ELFT>::Bss = &Bss;
   Out<ELFT>::BuildId = BuildId.get();
-  Out<ELFT>::DynStrTab = &DynStrTab;
-  Out<ELFT>::DynSymTab = &DynSymTab;
+  Out<ELFT>::DynStrTab = DynStrTab.get();
+  Out<ELFT>::DynSymTab = DynSymTab.get();
   Out<ELFT>::Dynamic = &Dynamic;
   Out<ELFT>::EhFrame = &EhFrame;
   Out<ELFT>::EhFrameHdr = EhFrameHdr.get();
@@ -481,10 +486,6 @@ static bool compareSections(OutputSectio
   return false;
 }
 
-template <class ELFT> bool elf::isOutputDynamic() {
-  return !Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic;
-}
-
 template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) {
   return !S || S == &InputSection<ELFT>::Discarded || !S->Live;
 }
@@ -523,7 +524,7 @@ static Symbol *addOptionalSynthetic(Stri
 // need these symbols, since IRELATIVE relocs are resolved through GOT
 // and PLT. For details, see http://www.airs.com/blog/archives/403.
 template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
-  if (isOutputDynamic<ELFT>() || !Out<ELFT>::RelaPlt)
+  if (Out<ELFT>::DynSymTab || !Out<ELFT>::RelaPlt)
     return;
   StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
   addOptionalSynthetic(S, Out<ELFT>::RelaPlt, 0);
@@ -576,7 +577,7 @@ template <class ELFT> void Writer<ELFT>:
   // 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<ELFT>())
+  if (!Out<ELFT>::DynSymTab)
     Symtab<ELFT>::X->addIgnored("__tls_get_addr");
 
   // If linker script do layout we do not need to create any standart symbols.
@@ -685,7 +686,7 @@ template <class ELFT> void Writer<ELFT>:
   // 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<ELFT>())
+  if (Out<ELFT>::DynSymTab)
     Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
 
   // Define __rel[a]_iplt_{start,end} symbols if needed.
@@ -725,7 +726,7 @@ template <class ELFT> void Writer<ELFT>:
     if (Out<ELFT>::SymTab)
       Out<ELFT>::SymTab->addSymbol(Body);
 
-    if (isOutputDynamic<ELFT>() && S->includeInDynsym()) {
+    if (Out<ELFT>::DynSymTab && S->includeInDynsym()) {
       Out<ELFT>::DynSymTab->addSymbol(Body);
       if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(Body))
         if (SS->file()->isNeeded())
@@ -759,7 +760,7 @@ template <class ELFT> void Writer<ELFT>:
 
   // Finalizers fix each section's size.
   // .dynsym is finalized early since that may fill up .gnu.hash.
-  if (isOutputDynamic<ELFT>())
+  if (Out<ELFT>::DynSymTab)
     Out<ELFT>::DynSymTab->finalize();
 
   // Fill other section headers. The dynamic table is finalized
@@ -771,7 +772,7 @@ template <class ELFT> void Writer<ELFT>:
     if (Sec != Out<ELFT>::DynStrTab && Sec != Out<ELFT>::Dynamic)
       Sec->finalize();
 
-  if (isOutputDynamic<ELFT>())
+  if (Out<ELFT>::DynSymTab)
     Out<ELFT>::Dynamic->finalize();
 
   // Now that all output offsets are fixed. Finalize mergeable sections
@@ -817,7 +818,7 @@ template <class ELFT> void Writer<ELFT>:
   Add(Out<ELFT>::SymTab);
   Add(Out<ELFT>::ShStrTab);
   Add(Out<ELFT>::StrTab);
-  if (isOutputDynamic<ELFT>()) {
+  if (Out<ELFT>::DynSymTab) {
     Add(Out<ELFT>::DynSymTab);
 
     bool HasVerNeed = Out<ELFT>::VerNeed->getNeedNum() != 0;
@@ -979,7 +980,7 @@ std::vector<PhdrEntry<ELFT>> Writer<ELFT
     Ret.push_back(std::move(TlsHdr));
 
   // Add an entry for .dynamic.
-  if (isOutputDynamic<ELFT>()) {
+  if (Out<ELFT>::DynSymTab) {
     Phdr &H = *AddHdr(PT_DYNAMIC, Out<ELFT>::Dynamic->getPhdrFlags());
     H.add(Out<ELFT>::Dynamic);
   }
@@ -1286,11 +1287,6 @@ template struct elf::PhdrEntry<ELF32BE>;
 template struct elf::PhdrEntry<ELF64LE>;
 template struct elf::PhdrEntry<ELF64BE>;
 
-template bool elf::isOutputDynamic<ELF32LE>();
-template bool elf::isOutputDynamic<ELF32BE>();
-template bool elf::isOutputDynamic<ELF64LE>();
-template bool elf::isOutputDynamic<ELF64BE>();
-
 template bool elf::isRelroSection<ELF32LE>(OutputSectionBase<ELF32LE> *);
 template bool elf::isRelroSection<ELF32BE>(OutputSectionBase<ELF32BE> *);
 template bool elf::isRelroSection<ELF64LE>(OutputSectionBase<ELF64LE> *);

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=278095&r1=278094&r2=278095&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Mon Aug  8 23:42:01 2016
@@ -25,7 +25,6 @@ template <class ELFT> class ObjectFile;
 template <class ELFT> class SymbolTable;
 template <class ELFT> void writeResult();
 template <class ELFT> void markLive();
-template <class ELFT> bool isOutputDynamic();
 template <class ELFT> bool isRelroSection(OutputSectionBase<ELFT> *Sec);
 
 // This describes a program header entry.




More information about the llvm-commits mailing list