[lld] r296307 - Remove useless template so that Out<ELFT> becomes just Out.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 18:31:27 PST 2017


Author: ruiu
Date: Sun Feb 26 20:31:26 2017
New Revision: 296307

URL: http://llvm.org/viewvc/llvm-project?rev=296307&view=rev
Log:
Remove useless template so that Out<ELFT> becomes just Out.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun Feb 26 20:31:26 2017
@@ -368,11 +368,11 @@ getRelocTargetVA(uint32_t Type, int64_t
       return 0;
     if (Target->TcbSize)
       return Body.getVA<ELFT>(A) +
-             alignTo(Target->TcbSize, Out<ELFT>::TlsPhdr->p_align);
-    return Body.getVA<ELFT>(A) - Out<ELFT>::TlsPhdr->p_memsz;
+             alignTo(Target->TcbSize, Out::TlsPhdr->p_align);
+    return Body.getVA<ELFT>(A) - Out::TlsPhdr->p_memsz;
   case R_RELAX_TLS_GD_TO_LE_NEG:
   case R_NEG_TLS:
-    return Out<ELF32LE>::TlsPhdr->p_memsz - Body.getVA<ELFT>(A);
+    return Out::TlsPhdr->p_memsz - Body.getVA<ELFT>(A);
   case R_ABS:
   case R_RELAX_GOT_PC_NOPIC:
     return Body.getVA<ELFT>(A);
@@ -409,14 +409,14 @@ getRelocTargetVA(uint32_t Type, int64_t
     // so don't bother doing anything at all.
     if (!SymVA)
       return 0;
-    if (Out<ELF64BE>::Opd) {
+    if (Out::Opd) {
       // If this is a local call, and we currently have the address of a
       // function-descriptor, get the underlying code address instead.
-      uint64_t OpdStart = Out<ELF64BE>::Opd->Addr;
-      uint64_t OpdEnd = OpdStart + Out<ELF64BE>::Opd->Size;
+      uint64_t OpdStart = Out::Opd->Addr;
+      uint64_t OpdEnd = OpdStart + Out::Opd->Size;
       bool InOpd = OpdStart <= SymVA && SymVA < OpdEnd;
       if (InOpd)
-        SymVA = read64be(&Out<ELF64BE>::OpdBuf[SymVA - OpdStart]);
+        SymVA = read64be(&Out::OpdBuf[SymVA - OpdStart]);
     }
     return SymVA - P;
   }
@@ -469,7 +469,7 @@ void InputSection::relocateNonAlloc(uint
 
     uintX_t AddrLoc = this->OutSec->Addr + Offset;
     uint64_t SymVA = 0;
-    if (!Sym.isTls() || Out<ELFT>::TlsPhdr)
+    if (!Sym.isTls() || Out::TlsPhdr)
       SymVA = SignExtend64<sizeof(uintX_t) * 8>(
           getRelocTargetVA<ELFT>(Type, Addend, AddrLoc, Sym, R_ABS));
     Target->relocateOne(BufLoc, Type, SymVA);

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sun Feb 26 20:31:26 2017
@@ -829,9 +829,9 @@ template <class ELFT> std::vector<PhdrEn
     PhdrEntry &Phdr = Ret.back();
 
     if (Cmd.HasFilehdr)
-      Phdr.add(Out<ELFT>::ElfHeader);
+      Phdr.add(Out::ElfHeader);
     if (Cmd.HasPhdrs)
-      Phdr.add(Out<ELFT>::ProgramHeaders);
+      Phdr.add(Out::ProgramHeaders);
 
     if (Cmd.LMAExpr) {
       Phdr.p_paddr = Cmd.LMAExpr(0);

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sun Feb 26 20:31:26 2017
@@ -30,6 +30,19 @@ using namespace llvm::ELF;
 using namespace lld;
 using namespace lld::elf;
 
+uint8_t Out::First;
+OutputSection *Out::Bss;
+OutputSection *Out::BssRelRo;
+OutputSection *Out::Opd;
+uint8_t *Out::OpdBuf;
+PhdrEntry *Out::TlsPhdr;
+OutputSection *Out::DebugInfo;
+OutputSection *Out::ElfHeader;
+OutputSection *Out::ProgramHeaders;
+OutputSection *Out::PreinitArray;
+OutputSection *Out::InitArray;
+OutputSection *Out::FiniArray;
+
 uint32_t OutputSection::getPhdrFlags() const {
   uint32_t Ret = PF_R;
   if (Flags & SHF_WRITE)

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Sun Feb 26 20:31:26 2017
@@ -93,13 +93,10 @@ public:
   uint8_t *Loc = nullptr;
 };
 
-// All output sections that are hadnled by the linker specially are
+// All output sections that are handled by the linker specially are
 // globally accessible. Writer initializes them, so don't use them
 // until Writer is initialized.
-template <class ELFT> struct Out {
-  typedef typename ELFT::uint uintX_t;
-  typedef typename ELFT::Phdr Elf_Phdr;
-
+struct Out {
   static uint8_t First;
   static OutputSection *Bss;
   static OutputSection *BssRelRo;
@@ -154,21 +151,9 @@ private:
 template <class ELFT> uint64_t getHeaderSize() {
   if (Config->OFormatBinary)
     return 0;
-  return Out<ELFT>::ElfHeader->Size + Out<ELFT>::ProgramHeaders->Size;
+  return Out::ElfHeader->Size + Out::ProgramHeaders->Size;
 }
 
-template <class ELFT> uint8_t Out<ELFT>::First;
-template <class ELFT> OutputSection *Out<ELFT>::Bss;
-template <class ELFT> OutputSection *Out<ELFT>::BssRelRo;
-template <class ELFT> OutputSection *Out<ELFT>::Opd;
-template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
-template <class ELFT> PhdrEntry *Out<ELFT>::TlsPhdr;
-template <class ELFT> OutputSection *Out<ELFT>::DebugInfo;
-template <class ELFT> OutputSection *Out<ELFT>::ElfHeader;
-template <class ELFT> OutputSection *Out<ELFT>::ProgramHeaders;
-template <class ELFT> OutputSection *Out<ELFT>::PreinitArray;
-template <class ELFT> OutputSection *Out<ELFT>::InitArray;
-template <class ELFT> OutputSection *Out<ELFT>::FiniArray;
 } // namespace elf
 } // namespace lld
 

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sun Feb 26 20:31:26 2017
@@ -479,7 +479,7 @@ template <class ELFT> static void addCop
   // See if this symbol is in a read-only segment. If so, preserve the symbol's
   // memory protection by reserving space in the .bss.rel.ro section.
   bool IsReadOnly = isReadOnly<ELFT>(SS);
-  OutputSection *OSec = IsReadOnly ? Out<ELFT>::BssRelRo : Out<ELFT>::Bss;
+  OutputSection *OSec = IsReadOnly ? Out::BssRelRo : Out::Bss;
 
   // Create a SyntheticSection in Out to hold the .bss and the Copy Reloc.
   auto *ISec =

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sun Feb 26 20:31:26 2017
@@ -65,10 +65,10 @@ static typename ELFT::uint getSymVA(cons
     const OutputSection *OutSec = IS->getOutputSection<ELFT>();
     uintX_t VA = (OutSec ? OutSec->Addr : 0) + IS->getOffset<ELFT>(Offset);
     if (D.isTls() && !Config->Relocatable) {
-      if (!Out<ELFT>::TlsPhdr)
+      if (!Out::TlsPhdr)
         fatal(toString(D.File) +
               " has a STT_TLS symbol but doesn't have a PT_TLS section");
-      return VA - Out<ELFT>::TlsPhdr->p_vaddr;
+      return VA - Out::TlsPhdr->p_vaddr;
     }
     return VA;
   }

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sun Feb 26 20:31:26 2017
@@ -1102,17 +1102,17 @@ template <class ELFT> void DynamicSectio
   if (In<ELFT>::HashTab)
     add({DT_HASH, In<ELFT>::HashTab});
 
-  if (Out<ELFT>::PreinitArray) {
-    add({DT_PREINIT_ARRAY, Out<ELFT>::PreinitArray});
-    add({DT_PREINIT_ARRAYSZ, Out<ELFT>::PreinitArray, Entry::SecSize});
-  }
-  if (Out<ELFT>::InitArray) {
-    add({DT_INIT_ARRAY, Out<ELFT>::InitArray});
-    add({DT_INIT_ARRAYSZ, Out<ELFT>::InitArray, Entry::SecSize});
-  }
-  if (Out<ELFT>::FiniArray) {
-    add({DT_FINI_ARRAY, Out<ELFT>::FiniArray});
-    add({DT_FINI_ARRAYSZ, Out<ELFT>::FiniArray, Entry::SecSize});
+  if (Out::PreinitArray) {
+    add({DT_PREINIT_ARRAY, Out::PreinitArray});
+    add({DT_PREINIT_ARRAYSZ, Out::PreinitArray, Entry::SecSize});
+  }
+  if (Out::InitArray) {
+    add({DT_INIT_ARRAY, Out::InitArray});
+    add({DT_INIT_ARRAYSZ, Out::InitArray, Entry::SecSize});
+  }
+  if (Out::FiniArray) {
+    add({DT_FINI_ARRAY, Out::FiniArray});
+    add({DT_FINI_ARRAYSZ, Out::FiniArray, Entry::SecSize});
   }
 
   if (SymbolBody *B = Symtab<ELFT>::X->findInCurrentDSO(Config->Init))
@@ -1853,7 +1853,7 @@ template <class ELFT> void GdbIndexSecti
 }
 
 template <class ELFT> bool GdbIndexSection<ELFT>::empty() const {
-  return !Out<ELFT>::DebugInfo;
+  return !Out::DebugInfo;
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=296307&r1=296306&r2=296307&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Feb 26 20:31:26 2017
@@ -301,20 +301,19 @@ template <class ELFT> void Writer<ELFT>:
     exitLld(0);
 }
 
-// Initialize Out<ELFT> members.
+// Initialize Out members.
 template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
   // Initialize all pointers with NULL. This is needed because
   // you can call lld::elf::main more than once as a library.
-  memset(&Out<ELFT>::First, 0, sizeof(Out<ELFT>));
+  memset(&Out::First, 0, sizeof(Out));
 
   auto Add = [](InputSectionBase *Sec) {
     Symtab<ELFT>::X->Sections.push_back(Sec);
   };
 
   // Create singleton output sections.
-  Out<ELFT>::Bss =
-      make<OutputSection>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
-  Out<ELFT>::BssRelRo =
+  Out::Bss = make<OutputSection>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+  Out::BssRelRo =
       make<OutputSection>(".bss.rel.ro", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
   In<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
   In<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
@@ -322,10 +321,10 @@ template <class ELFT> void Writer<ELFT>:
       Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc);
   In<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false);
 
-  Out<ELFT>::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
-  Out<ELFT>::ElfHeader->Size = sizeof(Elf_Ehdr);
-  Out<ELFT>::ProgramHeaders = make<OutputSection>("", 0, SHF_ALLOC);
-  Out<ELFT>::ProgramHeaders->updateAlignment(sizeof(uintX_t));
+  Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);
+  Out::ElfHeader->Size = sizeof(Elf_Ehdr);
+  Out::ProgramHeaders = make<OutputSection>("", 0, SHF_ALLOC);
+  Out::ProgramHeaders->updateAlignment(sizeof(uintX_t));
 
   if (needsInterpSection<ELFT>()) {
     In<ELFT>::Interp = createInterpSection<ELFT>();
@@ -597,7 +596,7 @@ template <class ELFT> bool elf::isRelroS
     return true;
   if (In<ELFT>::Got && Sec == In<ELFT>::Got->OutSec)
     return true;
-  if (Sec == Out<ELFT>::BssRelRo)
+  if (Sec == Out::BssRelRo)
     return true;
 
   StringRef S = Sec->Name;
@@ -841,7 +840,7 @@ template <class ELFT> void Writer<ELFT>:
 
   // __ehdr_start is the location of ELF file headers.
   ElfSym<ELFT>::EhdrStart =
-      addOptionalSynthetic<ELFT>("__ehdr_start", Out<ELFT>::ElfHeader, 0);
+      addOptionalSynthetic<ELFT>("__ehdr_start", Out::ElfHeader, 0);
 
   auto Define = [](StringRef S, DefinedSynthetic *&Sym1,
                    DefinedSynthetic *&Sym2) {
@@ -1062,10 +1061,10 @@ static void removeUnusedSyntheticSection
 
 // Create output section objects and add them to OutputSections.
 template <class ELFT> void Writer<ELFT>::finalizeSections() {
-  Out<ELFT>::DebugInfo = findSection(".debug_info");
-  Out<ELFT>::PreinitArray = findSection(".preinit_array");
-  Out<ELFT>::InitArray = findSection(".init_array");
-  Out<ELFT>::FiniArray = findSection(".fini_array");
+  Out::DebugInfo = findSection(".debug_info");
+  Out::PreinitArray = findSection(".preinit_array");
+  Out::InitArray = findSection(".init_array");
+  Out::FiniArray = findSection(".fini_array");
 
   // The linker needs to define SECNAME_start, SECNAME_end and SECNAME_stop
   // symbols for sections, so that the runtime can get the start and end
@@ -1123,7 +1122,7 @@ template <class ELFT> void Writer<ELFT>:
     return;
 
   // So far we have added sections from input object files.
-  // This function adds linker-created Out<ELFT>::* sections.
+  // This function adds linker-created Out::* sections.
   addPredefinedSections();
   removeUnusedSyntheticSections<ELFT>(OutputSections);
 
@@ -1132,7 +1131,7 @@ template <class ELFT> void Writer<ELFT>:
   // This is a bit of a hack. A value of 0 means undef, so we set it
   // to 1 t make __ehdr_start defined. The section number is not
   // particularly relevant.
-  Out<ELFT>::ElfHeader->SectionIndex = 1;
+  Out::ElfHeader->SectionIndex = 1;
 
   unsigned I = 1;
   for (OutputSection *Sec : OutputSections) {
@@ -1183,8 +1182,8 @@ template <class ELFT> void Writer<ELFT>:
       OutputSections.push_back(Sec);
     }
   };
-  Add(Out<ELFT>::Bss);
-  Add(Out<ELFT>::BssRelRo);
+  Add(Out::Bss);
+  Add(Out::BssRelRo);
 
   // ARM ABI requires .ARM.exidx to be terminated by some piece of data.
   // We have the terminater synthetic section class. Add that at the end.
@@ -1203,10 +1202,9 @@ template <class ELFT> void Writer<ELFT>:
     addOptionalSynthetic<ELFT>(End, OS, OS ? -1 : 0);
   };
 
-  Define("__preinit_array_start", "__preinit_array_end",
-         Out<ELFT>::PreinitArray);
-  Define("__init_array_start", "__init_array_end", Out<ELFT>::InitArray);
-  Define("__fini_array_start", "__fini_array_end", Out<ELFT>::FiniArray);
+  Define("__preinit_array_start", "__preinit_array_end", Out::PreinitArray);
+  Define("__init_array_start", "__init_array_end", Out::InitArray);
+  Define("__fini_array_start", "__fini_array_end", Out::FiniArray);
 
   if (OutputSection *Sec = findSection(".ARM.exidx"))
     Define("__exidx_start", "__exidx_end", Sec);
@@ -1268,7 +1266,7 @@ template <class ELFT> std::vector<PhdrEn
   };
 
   // The first phdr entry is PT_PHDR which describes the program header itself.
-  AddHdr(PT_PHDR, PF_R)->add(Out<ELFT>::ProgramHeaders);
+  AddHdr(PT_PHDR, PF_R)->add(Out::ProgramHeaders);
 
   // PT_INTERP must be the second entry if exists.
   if (OutputSection *Sec = findSection(".interp"))
@@ -1427,8 +1425,8 @@ bool elf::allocateHeaders(std::vector<Ph
   if (!ScriptConfig->HasSections)
     Config->ImageBase = Min = std::min(Min, Config->ImageBase);
 
-  Out<ELFT>::ElfHeader->Addr = Min;
-  Out<ELFT>::ProgramHeaders->Addr = Min + Out<ELFT>::ElfHeader->Size;
+  Out::ElfHeader->Addr = Min;
+  Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size;
 
   if (Script<ELFT>::X->hasPhdrsCommands())
     return true;
@@ -1436,10 +1434,10 @@ bool elf::allocateHeaders(std::vector<Ph
   if (FirstPTLoad->First)
     for (OutputSection *Sec : OutputSections)
       if (Sec->FirstInPtLoad == FirstPTLoad->First)
-        Sec->FirstInPtLoad = Out<ELFT>::ElfHeader;
-  FirstPTLoad->First = Out<ELFT>::ElfHeader;
+        Sec->FirstInPtLoad = Out::ElfHeader;
+  FirstPTLoad->First = Out::ElfHeader;
   if (!FirstPTLoad->Last)
-    FirstPTLoad->Last = Out<ELFT>::ProgramHeaders;
+    FirstPTLoad->Last = Out::ProgramHeaders;
   return true;
 }
 
@@ -1447,7 +1445,7 @@ bool elf::allocateHeaders(std::vector<Ph
 // sections. These are special, we do not include them into output sections
 // list, but have them to simplify the code.
 template <class ELFT> void Writer<ELFT>::fixHeaders() {
-  Out<ELFT>::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
+  Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
   // If the script has SECTIONS, assignAddresses will compute the values.
   if (ScriptConfig->HasSections)
     return;
@@ -1535,8 +1533,8 @@ template <class ELFT> void Writer<ELFT>:
 // Assign file offsets to output sections.
 template <class ELFT> void Writer<ELFT>::assignFileOffsets() {
   uintX_t Off = 0;
-  Off = setOffset<ELFT>(Out<ELFT>::ElfHeader, Off);
-  Off = setOffset<ELFT>(Out<ELFT>::ProgramHeaders, Off);
+  Off = setOffset<ELFT>(Out::ElfHeader, Off);
+  Off = setOffset<ELFT>(Out::ProgramHeaders, Off);
 
   for (OutputSection *Sec : OutputSections)
     Off = setOffset<ELFT>(Sec, Off);
@@ -1574,7 +1572,7 @@ template <class ELFT> void Writer<ELFT>:
     // The TLS pointer goes after PT_TLS. At least glibc will align it,
     // so round up the size to make sure the offsets are correct.
     if (P.p_type == PT_TLS) {
-      Out<ELFT>::TlsPhdr = &P;
+      Out::TlsPhdr = &P;
       if (P.p_memsz)
         P.p_memsz = alignTo(P.p_memsz, P.p_align);
     }
@@ -1801,10 +1799,10 @@ template <class ELFT> void Writer<ELFT>:
 
   // PPC64 needs to process relocations in the .opd section
   // before processing relocations in code-containing sections.
-  Out<ELFT>::Opd = findSection(".opd");
-  if (Out<ELFT>::Opd) {
-    Out<ELFT>::OpdBuf = Buf + Out<ELFT>::Opd->Offset;
-    Out<ELFT>::Opd->template writeTo<ELFT>(Buf + Out<ELFT>::Opd->Offset);
+  Out::Opd = findSection(".opd");
+  if (Out::Opd) {
+    Out::OpdBuf = Buf + Out::Opd->Offset;
+    Out::Opd->template writeTo<ELFT>(Buf + Out::Opd->Offset);
   }
 
   OutputSection *EhFrameHdr =
@@ -1818,7 +1816,7 @@ template <class ELFT> void Writer<ELFT>:
       Sec->writeTo<ELFT>(Buf + Sec->Offset);
 
   for (OutputSection *Sec : OutputSections)
-    if (Sec != Out<ELFT>::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL &&
+    if (Sec != Out::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL &&
         Sec->Type != SHT_RELA)
       Sec->writeTo<ELFT>(Buf + Sec->Offset);
 




More information about the llvm-commits mailing list