[lld] r296508 - De-template DefinedRegular.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 11:29:56 PST 2017


Author: ruiu
Date: Tue Feb 28 13:29:55 2017
New Revision: 296508

URL: http://llvm.org/viewvc/llvm-project?rev=296508&view=rev
Log:
De-template DefinedRegular.

Differential Revision: https://reviews.llvm.org/D30348

Modified:
    lld/trunk/ELF/ICF.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/MapFile.cpp
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Thunks.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue Feb 28 13:29:55 2017
@@ -244,8 +244,8 @@ bool ICF<ELFT>::variableEq(const InputSe
     if (&SA == &SB)
       return true;
 
-    auto *DA = dyn_cast<DefinedRegular<ELFT>>(&SA);
-    auto *DB = dyn_cast<DefinedRegular<ELFT>>(&SB);
+    auto *DA = dyn_cast<DefinedRegular>(&SA);
+    auto *DB = dyn_cast<DefinedRegular>(&SB);
     if (!DA || !DB)
       return false;
     if (DA->Value != DB->Value)

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Feb 28 13:29:55 2017
@@ -514,8 +514,8 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
       return new (BAlloc)
           Undefined(Name, /*IsLocal=*/true, StOther, Type, this);
 
-    return new (BAlloc) DefinedRegular<ELFT>(Name, /*IsLocal=*/true, StOther,
-                                             Type, Value, Size, Sec, this);
+    return new (BAlloc) DefinedRegular(Name, /*IsLocal=*/true, StOther, Type,
+                                       Value, Size, Sec, this);
   }
 
   StringRef Name = check(Sym->getName(this->StringTable));

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Feb 28 13:29:55 2017
@@ -150,7 +150,7 @@ template <class ELFT> void InputSectionB
 }
 
 template <class ELFT>
-uint64_t InputSectionBase::getOffset(const DefinedRegular<ELFT> &Sym) const {
+uint64_t InputSectionBase::getOffset(const DefinedRegular &Sym) const {
   return getOffset<ELFT>(Sym.Value);
 }
 
@@ -177,7 +177,7 @@ std::string InputSectionBase::getLocatio
 
   // Find a function symbol that encloses a given location.
   for (SymbolBody *B : getFile<ELFT>()->getSymbols())
-    if (auto *D = dyn_cast<DefinedRegular<ELFT>>(B))
+    if (auto *D = dyn_cast<DefinedRegular>(B))
       if (D->Section == this && D->Type == STT_FUNC)
         if (D->Value <= Offset && Offset < D->Value + D->Size)
           return SrcFile + ":(function " + toString(*D) + ")";
@@ -250,7 +250,7 @@ void InputSection::copyRelocations(uint8
       // avoid having to parse and recreate .eh_frame, we just replace any
       // relocation in it pointing to discarded sections with R_*_NONE, which
       // hopefully creates a frame that is ignored at runtime.
-      InputSectionBase *Section = cast<DefinedRegular<ELFT>>(Body).Section;
+      InputSectionBase *Section = cast<DefinedRegular>(Body).Section;
       if (Section == &InputSection::Discarded) {
         P->setSymbolAndType(0, 0, false);
         continue;
@@ -840,13 +840,13 @@ template InputSectionBase *InputSection:
 template InputSectionBase *InputSection::getRelocatedSection<ELF64BE>();
 
 template uint64_t
-InputSectionBase::getOffset(const DefinedRegular<ELF32LE> &Sym) const;
+InputSectionBase::getOffset<ELF32LE>(const DefinedRegular &Sym) const;
 template uint64_t
-InputSectionBase::getOffset(const DefinedRegular<ELF32BE> &Sym) const;
+InputSectionBase::getOffset<ELF32BE>(const DefinedRegular &Sym) const;
 template uint64_t
-InputSectionBase::getOffset(const DefinedRegular<ELF64LE> &Sym) const;
+InputSectionBase::getOffset<ELF64LE>(const DefinedRegular &Sym) const;
 template uint64_t
-InputSectionBase::getOffset(const DefinedRegular<ELF64BE> &Sym) const;
+InputSectionBase::getOffset<ELF64BE>(const DefinedRegular &Sym) const;
 
 template uint64_t InputSectionBase::getOffset<ELF32LE>(uint64_t Offset) const;
 template uint64_t InputSectionBase::getOffset<ELF32BE>(uint64_t Offset) const;

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Feb 28 13:29:55 2017
@@ -27,7 +27,7 @@ class DefinedCommon;
 class SymbolBody;
 struct SectionPiece;
 
-template <class ELFT> class DefinedRegular;
+class DefinedRegular;
 template <class ELFT> class EhFrameSection;
 template <class ELFT> class MergeSyntheticSection;
 template <class ELFT> class ObjectFile;
@@ -117,8 +117,7 @@ public:
     return getFile<ELFT>()->getObj();
   }
 
-  template <class ELFT>
-  uint64_t getOffset(const DefinedRegular<ELFT> &Sym) const;
+  template <class ELFT> uint64_t getOffset(const DefinedRegular &Sym) const;
 
   template <class ELFT> InputSectionBase *getLinkOrderDep() const;
   // Translate an offset in the input section to an offset in the output

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Feb 28 13:29:55 2017
@@ -63,9 +63,8 @@ template <class ELFT> static SymbolBody
       Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
       /*File*/ nullptr);
   Sym->Binding = STB_GLOBAL;
-  replaceBody<DefinedRegular<ELFT>>(Sym, Cmd->Name, /*IsLocal=*/false,
-                                    Visibility, STT_NOTYPE, 0, 0, nullptr,
-                                    nullptr);
+  replaceBody<DefinedRegular>(Sym, Cmd->Name, /*IsLocal=*/false, Visibility,
+                              STT_NOTYPE, 0, 0, nullptr, nullptr);
   return Sym->body();
 }
 
@@ -131,7 +130,7 @@ void LinkerScript<ELFT>::assignSymbol(Sy
     return;
   }
 
-  cast<DefinedRegular<ELFT>>(Cmd->Sym)->Value = Cmd->Expression(Dot);
+  cast<DefinedRegular>(Cmd->Sym)->Value = Cmd->Expression(Dot);
 }
 
 template <class ELFT>
@@ -973,7 +972,7 @@ template <class ELFT> bool LinkerScript<
 
 template <class ELFT> bool LinkerScript<ELFT>::isAbsolute(StringRef S) {
   SymbolBody *Sym = Symtab<ELFT>::X->find(S);
-  auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym);
+  auto *DR = dyn_cast_or_null<DefinedRegular>(Sym);
   return DR && !DR->Section;
 }
 

Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Tue Feb 28 13:29:55 2017
@@ -80,7 +80,7 @@ static void writeInputSection(raw_fd_ost
   OS << '\n';
 
   for (SymbolBody *Sym : File->getSymbols()) {
-    auto *DR = dyn_cast<DefinedRegular<ELFT>>(Sym);
+    auto *DR = dyn_cast<DefinedRegular>(Sym);
     if (!DR)
       continue;
     if (DR->Section != IS)

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Tue Feb 28 13:29:55 2017
@@ -66,7 +66,7 @@ static typename ELFT::uint getAddend(Inp
 template <class ELFT, class RelT>
 static ResolvedReloc resolveReloc(InputSectionBase &Sec, RelT &Rel) {
   SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
-  auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
+  auto *D = dyn_cast<DefinedRegular>(&B);
   if (!D || !D->Section)
     return {nullptr, 0};
   typename ELFT::uint Offset = D->Value;
@@ -215,7 +215,7 @@ template <class ELFT> void elf::markLive
   };
 
   auto MarkSymbol = [&](const SymbolBody *Sym) {
-    if (auto *D = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
+    if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym))
       Enqueue({D->Section, D->Value});
   };
 

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Feb 28 13:29:55 2017
@@ -31,7 +31,7 @@ class OutputSection;
 template <class ELFT> class ObjectFile;
 template <class ELFT> class SharedFile;
 class SharedSymbol;
-template <class ELFT> class DefinedRegular;
+class DefinedRegular;
 
 // This represents a section in an output file.
 // It is composed of multiple InputSections.

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Feb 28 13:29:55 2017
@@ -292,7 +292,7 @@ static int32_t findMipsPairedAddend(cons
 template <class ELFT> static bool isAbsolute(const SymbolBody &Body) {
   if (Body.isUndefined())
     return !Body.isLocal() && Body.symbol()->isWeak();
-  if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(&Body))
+  if (const auto *DR = dyn_cast<DefinedRegular>(&Body))
     return DR->Section == nullptr; // Absolute symbol.
   return false;
 }
@@ -352,7 +352,7 @@ isStaticLinkTimeConstant(RelExpr E, uint
   if (AbsVal && RelE) {
     if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
       return true;
-    if (&Body == ElfSym<ELFT>::MipsGpDisp)
+    if (&Body == ElfSym::MipsGpDisp)
       return true;
     error(S.getLocation<ELFT>(RelOff) + ": relocation " + toString(Type) +
           " cannot refer to absolute symbol '" + toString(Body) +

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Feb 28 13:29:55 2017
@@ -126,19 +126,19 @@ template <class ELFT> void SymbolTable<E
 }
 
 template <class ELFT>
-DefinedRegular<ELFT> *SymbolTable<ELFT>::addAbsolute(StringRef Name,
-                                                     uint8_t Visibility,
-                                                     uint8_t Binding) {
+DefinedRegular *SymbolTable<ELFT>::addAbsolute(StringRef Name,
+                                               uint8_t Visibility,
+                                               uint8_t Binding) {
   Symbol *Sym =
       addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, nullptr, nullptr);
-  return cast<DefinedRegular<ELFT>>(Sym->body());
+  return cast<DefinedRegular>(Sym->body());
 }
 
 // Add Name as an "ignored" symbol. An ignored symbol is a regular
 // linker-synthesized defined symbol, but is only defined if needed.
 template <class ELFT>
-DefinedRegular<ELFT> *SymbolTable<ELFT>::addIgnored(StringRef Name,
-                                                    uint8_t Visibility) {
+DefinedRegular *SymbolTable<ELFT>::addIgnored(StringRef Name,
+                                              uint8_t Visibility) {
   SymbolBody *S = find(Name);
   if (!S || S->isInCurrentDSO())
     return nullptr;
@@ -309,7 +309,7 @@ static int compareDefinedNonCommon(Symbo
     if (Config->WarnCommon)
       warn("common " + S->body()->getName() + " is overridden");
     return 1;
-  } else if (auto *R = dyn_cast<DefinedRegular<ELFT>>(B)) {
+  } else if (auto *R = dyn_cast<DefinedRegular>(B)) {
     if (R->Section == nullptr && Binding == STB_GLOBAL && IsAbsolute &&
         R->Value == Value)
       return -1;
@@ -363,7 +363,7 @@ static void reportDuplicate(SymbolBody *
 template <class ELFT>
 static void reportDuplicate(SymbolBody *Existing, InputSectionBase *ErrSec,
                             typename ELFT::uint ErrOffset) {
-  DefinedRegular<ELFT> *D = dyn_cast<DefinedRegular<ELFT>>(Existing);
+  DefinedRegular *D = dyn_cast<DefinedRegular>(Existing);
   if (!D || !D->Section || !ErrSec) {
     reportDuplicate(Existing, ErrSec ? ErrSec->getFile<ELFT>() : nullptr);
     return;
@@ -388,8 +388,8 @@ SymbolTable<ELFT>::addRegular(StringRef
   int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding,
                                           Section == nullptr, Value);
   if (Cmp > 0)
-    replaceBody<DefinedRegular<ELFT>>(S, Name, /*IsLocal=*/false, StOther, Type,
-                                      Value, Size, Section, File);
+    replaceBody<DefinedRegular>(S, Name, /*IsLocal=*/false, StOther, Type,
+                                Value, Size, Section, File);
   else if (Cmp == 0)
     reportDuplicate<ELFT>(S->body(), Section, Value);
   return S;
@@ -446,8 +446,8 @@ Symbol *SymbolTable<ELFT>::addBitcode(St
   int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding,
                                           /*IsAbs*/ false, /*Value*/ 0);
   if (Cmp > 0)
-    replaceBody<DefinedRegular<ELFT>>(S, Name, /*IsLocal=*/false, StOther, Type,
-                                      0, 0, nullptr, F);
+    replaceBody<DefinedRegular>(S, Name, /*IsLocal=*/false, StOther, Type, 0, 0,
+                                nullptr, F);
   else if (Cmp == 0)
     reportDuplicate(S->body(), F);
   return S;

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Feb 28 13:29:55 2017
@@ -46,11 +46,11 @@ public:
   ArrayRef<BinaryFile *> getBinaryFiles() const { return BinaryFiles; }
   ArrayRef<SharedFile<ELFT> *> getSharedFiles() const { return SharedFiles; }
 
-  DefinedRegular<ELFT> *addAbsolute(StringRef Name,
-                                    uint8_t Visibility = llvm::ELF::STV_HIDDEN,
-                                    uint8_t Binding = llvm::ELF::STB_GLOBAL);
-  DefinedRegular<ELFT> *addIgnored(StringRef Name,
-                                   uint8_t Visibility = llvm::ELF::STV_HIDDEN);
+  DefinedRegular *addAbsolute(StringRef Name,
+                              uint8_t Visibility = llvm::ELF::STV_HIDDEN,
+                              uint8_t Binding = llvm::ELF::STB_GLOBAL);
+  DefinedRegular *addIgnored(StringRef Name,
+                             uint8_t Visibility = llvm::ELF::STV_HIDDEN);
 
   Symbol *addUndefined(StringRef Name);
   Symbol *addUndefined(StringRef Name, bool IsLocal, uint8_t Binding,

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Feb 28 13:29:55 2017
@@ -28,6 +28,18 @@ using namespace llvm::ELF;
 using namespace lld;
 using namespace lld::elf;
 
+InputSectionBase *DefinedRegular::NullInputSection;
+
+DefinedSynthetic *ElfSym::Etext;
+DefinedSynthetic *ElfSym::Etext2;
+DefinedSynthetic *ElfSym::Edata;
+DefinedSynthetic *ElfSym::Edata2;
+DefinedSynthetic *ElfSym::End;
+DefinedSynthetic *ElfSym::End2;
+DefinedRegular *ElfSym::MipsGpDisp;
+DefinedRegular *ElfSym::MipsLocalGp;
+DefinedRegular *ElfSym::MipsGp;
+
 template <class ELFT>
 static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) {
   typedef typename ELFT::uint uintX_t;
@@ -43,7 +55,7 @@ static typename ELFT::uint getSymVA(cons
     return Sec->Addr + D.Value;
   }
   case SymbolBody::DefinedRegularKind: {
-    auto &D = cast<DefinedRegular<ELFT>>(Body);
+    auto &D = cast<DefinedRegular>(Body);
     InputSectionBase *IS = D.Section;
 
     // According to the ELF spec reference to a local symbol from outside
@@ -188,7 +200,7 @@ template <class ELFT> typename ELFT::uin
 template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
   if (const auto *C = dyn_cast<DefinedCommon>(this))
     return C->Size;
-  if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
+  if (const auto *DR = dyn_cast<DefinedRegular>(this))
     return DR->Size;
   if (const auto *S = dyn_cast<SharedSymbol>(this))
     return S->getSize<ELFT>();
@@ -197,7 +209,7 @@ template <class ELFT> typename ELFT::uin
 
 template <class ELFT>
 const OutputSection *SymbolBody::getOutputSection() const {
-  if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this)) {
+  if (auto *S = dyn_cast<DefinedRegular>(this)) {
     if (S->Section)
       return S->Section->template getOutputSection<ELFT>();
     return nullptr;
@@ -263,7 +275,7 @@ Defined::Defined(Kind K, StringRefZ Name
                  uint8_t Type)
     : SymbolBody(K, Name, IsLocal, StOther, Type) {}
 
-template <class ELFT> bool DefinedRegular<ELFT>::isMipsPIC() const {
+template <class ELFT> bool DefinedRegular::isMipsPIC() const {
   if (!Section || !isFunc())
     return false;
   return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
@@ -416,10 +428,10 @@ template const OutputSection *
 template const OutputSection *
     SymbolBody::template getOutputSection<ELF64BE>() const;
 
-template class elf::DefinedRegular<ELF32LE>;
-template class elf::DefinedRegular<ELF32BE>;
-template class elf::DefinedRegular<ELF64LE>;
-template class elf::DefinedRegular<ELF64BE>;
+template bool DefinedRegular::template isMipsPIC<ELF32LE>() const;
+template bool DefinedRegular::template isMipsPIC<ELF32BE>() const;
+template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
+template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
 
 template uint64_t SharedSymbol::template getAlignment<ELF32LE>() const;
 template uint64_t SharedSymbol::template getAlignment<ELF32BE>() const;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Feb 28 13:29:55 2017
@@ -174,13 +174,10 @@ public:
 };
 
 // Regular defined symbols read from object file symbol tables.
-template <class ELFT> class DefinedRegular : public Defined {
-  typedef typename ELFT::Sym Elf_Sym;
-  typedef typename ELFT::uint uintX_t;
-
+class DefinedRegular : public Defined {
 public:
   DefinedRegular(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
-                 uintX_t Value, uintX_t Size, InputSectionBase *Section,
+                 uint64_t Value, uint64_t Size, InputSectionBase *Section,
                  InputFile *File)
       : Defined(SymbolBody::DefinedRegularKind, Name, IsLocal, StOther, Type),
         Value(Value), Size(Size),
@@ -189,14 +186,14 @@ public:
   }
 
   // Return true if the symbol is a PIC function.
-  bool isMipsPIC() const;
+  template <class ELFT> bool isMipsPIC() const;
 
   static bool classof(const SymbolBody *S) {
     return S->kind() == SymbolBody::DefinedRegularKind;
   }
 
-  uintX_t Value;
-  uintX_t Size;
+  uint64_t Value;
+  uint64_t Size;
 
   // The input section this symbol belongs to. Notice that this is
   // a reference to a pointer. We are using two levels of indirections
@@ -210,8 +207,6 @@ private:
   static InputSectionBase *NullInputSection;
 };
 
-template <class ELFT> InputSectionBase *DefinedRegular<ELFT>::NullInputSection;
-
 // DefinedSynthetic is a class to represent linker-generated ELF symbols.
 // The difference from the regular symbol is that DefinedSynthetic symbols
 // don't belong to any input files or sections. Thus, its constructor
@@ -337,7 +332,7 @@ public:
 
 // Some linker-generated symbols need to be created as
 // DefinedRegular symbols.
-template <class ELFT> struct ElfSym {
+struct ElfSym {
   // The content for _etext and etext symbols.
   static DefinedSynthetic *Etext;
   static DefinedSynthetic *Etext2;
@@ -351,21 +346,11 @@ template <class ELFT> struct ElfSym {
   static DefinedSynthetic *End2;
 
   // The content for _gp_disp/__gnu_local_gp symbols for MIPS target.
-  static DefinedRegular<ELFT> *MipsGpDisp;
-  static DefinedRegular<ELFT> *MipsLocalGp;
-  static DefinedRegular<ELFT> *MipsGp;
+  static DefinedRegular *MipsGpDisp;
+  static DefinedRegular *MipsLocalGp;
+  static DefinedRegular *MipsGp;
 };
 
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Etext;
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Etext2;
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Edata;
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Edata2;
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::End;
-template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::End2;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGpDisp;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsLocalGp;
-template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
-
 // A real symbol object, SymbolBody, is usually stored within a Symbol. There's
 // always one Symbol for each symbol name. The resolver updates the SymbolBody
 // stored in the Body field of this object as it resolves symbols. Symbol also
@@ -409,12 +394,9 @@ struct Symbol {
 
   // This field is used to store the Symbol's SymbolBody. This instantiation of
   // AlignedCharArrayUnion gives us a struct with a char array field that is
-  // large and aligned enough to store any derived class of SymbolBody. We
-  // assume that the size and alignment of ELF64LE symbols is sufficient for any
-  // ELFT, and we verify this with the static_asserts in replaceBody.
-  llvm::AlignedCharArrayUnion<
-      DefinedCommon, DefinedRegular<llvm::object::ELF64LE>, DefinedSynthetic,
-      Undefined, SharedSymbol, LazyArchive, LazyObject>
+  // large and aligned enough to store any derived class of SymbolBody.
+  llvm::AlignedCharArrayUnion<DefinedCommon, DefinedRegular, DefinedSynthetic,
+                              Undefined, SharedSymbol, LazyArchive, LazyObject>
       Body;
 
   SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Feb 28 13:29:55 2017
@@ -298,8 +298,8 @@ InputSection *elf::createInterpSection()
 template <class ELFT>
 SymbolBody *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
                                    uint64_t Size, InputSectionBase *Section) {
-  auto *S = make<DefinedRegular<ELFT>>(Name, /*IsLocal*/ true, STV_DEFAULT,
-                                       Type, Value, Size, Section, nullptr);
+  auto *S = make<DefinedRegular>(Name, /*IsLocal*/ true, STV_DEFAULT, Type,
+                                 Value, Size, Section, nullptr);
   if (In<ELFT>::SymTab)
     In<ELFT>::SymTab->addSymbol(S);
   return S;
@@ -448,7 +448,7 @@ bool EhFrameSection<ELFT>::isFdeLive(EhS
     return false;
   const RelTy &Rel = Rels[FirstRelI];
   SymbolBody &B = Sec->template getFile<ELFT>()->getRelocTargetSym(Rel);
-  auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
+  auto *D = dyn_cast<DefinedRegular>(&B);
   if (!D || !D->Section)
     return false;
   InputSectionBase *Target = D->Section->Repl;
@@ -700,7 +700,7 @@ void MipsGotSection<ELFT>::addEntry(Symb
     // sections referenced by GOT relocations. Then later in the `finalize`
     // method calculate number of "pages" required to cover all saved output
     // section and allocate appropriate number of GOT entries.
-    auto *DefSym = cast<DefinedRegular<ELFT>>(&Sym);
+    auto *DefSym = cast<DefinedRegular>(&Sym);
     PageIndexMap.insert(
         {DefSym->Section->template getOutputSection<ELFT>(), 0});
     return;
@@ -773,8 +773,7 @@ typename MipsGotSection<ELFT>::uintX_t
 MipsGotSection<ELFT>::getPageEntryOffset(const SymbolBody &B,
                                          int64_t Addend) const {
   const OutputSection *OutSec =
-      cast<DefinedRegular<ELFT>>(&B)
-          ->Section->template getOutputSection<ELFT>();
+      cast<DefinedRegular>(&B)->Section->template getOutputSection<ELFT>();
   uintX_t SecAddr = getMipsPageAddr(OutSec->Addr);
   uintX_t SymAddr = getMipsPageAddr(B.getVA<ELFT>(Addend));
   uintX_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) / 0xffff;
@@ -852,7 +851,7 @@ template <class ELFT> bool MipsGotSectio
 
 template <class ELFT>
 typename MipsGotSection<ELFT>::uintX_t MipsGotSection<ELFT>::getGp() const {
-  return ElfSym<ELFT>::MipsGp->template getVA<ELFT>(0);
+  return ElfSym::MipsGp->template getVA<ELFT>(0);
 }
 
 template <class ELFT>
@@ -1344,8 +1343,8 @@ size_t SymbolTableSection<ELFT>::getSymb
     // This is used for -r, so we have to handle multiple section
     // symbols being combined.
     if (Body->Type == STT_SECTION && E.Symbol->Type == STT_SECTION)
-      return cast<DefinedRegular<ELFT>>(Body)->Section->OutSec ==
-             cast<DefinedRegular<ELFT>>(E.Symbol)->Section->OutSec;
+      return cast<DefinedRegular>(Body)->Section->OutSec ==
+             cast<DefinedRegular>(E.Symbol)->Section->OutSec;
     return false;
   });
   if (I == Symbols.end())
@@ -1377,7 +1376,7 @@ template <class ELFT> void SymbolTableSe
     // Set a section index.
     if (const OutputSection *OutSec = Body->getOutputSection<ELFT>())
       ESym->st_shndx = OutSec->SectionIndex;
-    else if (isa<DefinedRegular<ELFT>>(Body))
+    else if (isa<DefinedRegular>(Body))
       ESym->st_shndx = SHN_ABS;
     else if (isa<DefinedCommon>(Body))
       ESym->st_shndx = SHN_COMMON;
@@ -1406,8 +1405,8 @@ template <class ELFT> void SymbolTableSe
         ESym->st_other |= STO_MIPS_PLT;
 
       if (Config->Relocatable)
-        if (auto *D = dyn_cast<DefinedRegular<ELFT>>(Body))
-          if (D->isMipsPIC())
+        if (auto *D = dyn_cast<DefinedRegular>(Body))
+          if (D->isMipsPIC<ELFT>())
             ESym->st_other |= STO_MIPS_PIC;
       ++ESym;
     }

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Feb 28 13:29:55 2017
@@ -2086,7 +2086,7 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
     // offset between start of function and 'gp' value which by default
     // equal to the start of .got section. In that case we consider these
     // relocations as relative.
-    if (&S == ElfSym<ELFT>::MipsGpDisp)
+    if (&S == ElfSym::MipsGpDisp)
       return R_PC;
     return R_ABS;
   case R_MIPS_PC32:
@@ -2245,10 +2245,10 @@ bool MipsTargetInfo<ELFT>::needsThunk(Re
   // If current file has PIC code, LA25 stub is not required.
   if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
     return false;
-  auto *D = dyn_cast<DefinedRegular<ELFT>>(&S);
+  auto *D = dyn_cast<DefinedRegular>(&S);
   // LA25 is required if target file has PIC code
   // or target symbol is a PIC symbol.
-  return D && D->isMipsPIC();
+  return D && D->isMipsPIC<ELFT>();
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Tue Feb 28 13:29:55 2017
@@ -225,7 +225,7 @@ template <class ELFT> void MipsThunk<ELF
 
 template <class ELFT>
 InputSection *MipsThunk<ELFT>::getTargetInputSection() const {
-  auto *DR = dyn_cast<DefinedRegular<ELFT>>(&this->Destination);
+  auto *DR = dyn_cast<DefinedRegular>(&this->Destination);
   return dyn_cast<InputSection>(DR->Section);
 }
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=296508&r1=296507&r2=296508&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Feb 28 13:29:55 2017
@@ -483,7 +483,7 @@ template <class ELFT> static bool includ
   if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj)
     return false;
 
-  if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B)) {
+  if (auto *D = dyn_cast<DefinedRegular>(&B)) {
     // Always include absolute symbols.
     if (!D->Section)
       return true;
@@ -507,7 +507,7 @@ template <class ELFT> void Writer<ELFT>:
       if (!B->IsLocal)
         fatal(toString(F) +
               ": broken object: getLocalSymbols returns a non-local symbol");
-      auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
+      auto *DR = dyn_cast<DefinedRegular>(B);
 
       // No reason to keep local undefined symbol in symtab.
       if (!DR)
@@ -534,8 +534,8 @@ template <class ELFT> void Writer<ELFT>:
         IS->Type == SHT_RELA)
       continue;
     auto *B = new (BAlloc)
-        DefinedRegular<ELFT>("", /*IsLocal=*/true, /*StOther*/ 0, STT_SECTION,
-                             /*Value*/ 0, /*Size*/ 0, IS, nullptr);
+        DefinedRegular("", /*IsLocal=*/true, /*StOther*/ 0, STT_SECTION,
+                       /*Value*/ 0, /*Size*/ 0, IS, nullptr);
 
     In<ELFT>::SymTab->addSymbol(B);
   }
@@ -788,15 +788,14 @@ template <class ELFT> void Writer<ELFT>:
     // to GOT. Default offset is 0x7ff0.
     // See "Global Data Symbols" in Chapter 6 in the following document:
     // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
-    ElfSym<ELFT>::MipsGp =
-        Symtab<ELFT>::X->addAbsolute("_gp", STV_HIDDEN, STB_LOCAL);
+    ElfSym::MipsGp = Symtab<ELFT>::X->addAbsolute("_gp", STV_HIDDEN, STB_LOCAL);
 
     // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
     // start of function and 'gp' pointer into GOT. To simplify relocation
     // calculation we assign _gp value to it and calculate corresponding
     // relocations as relative to this value.
     if (Symtab<ELFT>::X->find("_gp_disp"))
-      ElfSym<ELFT>::MipsGpDisp =
+      ElfSym::MipsGpDisp =
           Symtab<ELFT>::X->addAbsolute("_gp_disp", STV_HIDDEN, STB_LOCAL);
 
     // The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
@@ -804,7 +803,7 @@ template <class ELFT> void Writer<ELFT>:
     // in case of using -mno-shared option.
     // https://sourceware.org/ml/binutils/2004-12/msg00094.html
     if (Symtab<ELFT>::X->find("__gnu_local_gp"))
-      ElfSym<ELFT>::MipsLocalGp =
+      ElfSym::MipsLocalGp =
           Symtab<ELFT>::X->addAbsolute("__gnu_local_gp", STV_HIDDEN, STB_LOCAL);
   }
 
@@ -847,9 +846,9 @@ template <class ELFT> void Writer<ELFT>:
     Sym2 = addOptionalSynthetic<ELFT>(S, nullptr, 0, STV_DEFAULT);
   };
 
-  Define("_end", ElfSym<ELFT>::End, ElfSym<ELFT>::End2);
-  Define("_etext", ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2);
-  Define("_edata", ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2);
+  Define("_end", ElfSym::End, ElfSym::End2);
+  Define("_etext", ElfSym::Etext, ElfSym::Etext2);
+  Define("_edata", ElfSym::Edata, ElfSym::Edata2);
 }
 
 // Sort input sections by section name suffixes for
@@ -883,7 +882,7 @@ static void sortBySymbolsOrder(ArrayRef<
   DenseMap<InputSectionBase *, int> SectionOrder;
   for (elf::ObjectFile<ELFT> *File : Symtab<ELFT>::X->getObjectFiles()) {
     for (SymbolBody *Body : File->getSymbols()) {
-      auto *D = dyn_cast<DefinedRegular<ELFT>>(Body);
+      auto *D = dyn_cast<DefinedRegular>(Body);
       if (!D || !D->Section)
         continue;
       int &Priority = SectionOrder[D->Section];
@@ -1652,18 +1651,16 @@ template <class ELFT> void Writer<ELFT>:
       LastRO = &P;
   }
   if (Last)
-    Set(ElfSym<ELFT>::End, ElfSym<ELFT>::End2, Last->First, Last->p_memsz);
+    Set(ElfSym::End, ElfSym::End2, Last->First, Last->p_memsz);
   if (LastRO)
-    Set(ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2, LastRO->First,
-        LastRO->p_filesz);
+    Set(ElfSym::Etext, ElfSym::Etext2, LastRO->First, LastRO->p_filesz);
   if (LastRW)
-    Set(ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2, LastRW->First,
-        LastRW->p_filesz);
+    Set(ElfSym::Edata, ElfSym::Edata2, LastRW->First, LastRW->p_filesz);
 
   // Setup MIPS _gp_disp/__gnu_local_gp symbols which should
   // be equal to the _gp symbol's value.
   if (Config->EMachine == EM_MIPS) {
-    if (!ElfSym<ELFT>::MipsGp->Value) {
+    if (!ElfSym::MipsGp->Value) {
       // Find GP-relative section with the lowest address
       // and use this address to calculate default _gp value.
       uintX_t Gp = -1;
@@ -1671,12 +1668,12 @@ template <class ELFT> void Writer<ELFT>:
         if ((OS->Flags & SHF_MIPS_GPREL) && OS->Addr < Gp)
           Gp = OS->Addr;
       if (Gp != (uintX_t)-1)
-        ElfSym<ELFT>::MipsGp->Value = Gp + 0x7ff0;
+        ElfSym::MipsGp->Value = Gp + 0x7ff0;
     }
-    if (ElfSym<ELFT>::MipsGpDisp)
-      ElfSym<ELFT>::MipsGpDisp->Value = ElfSym<ELFT>::MipsGp->Value;
-    if (ElfSym<ELFT>::MipsLocalGp)
-      ElfSym<ELFT>::MipsLocalGp->Value = ElfSym<ELFT>::MipsGp->Value;
+    if (ElfSym::MipsGpDisp)
+      ElfSym::MipsGpDisp->Value = ElfSym::MipsGp->Value;
+    if (ElfSym::MipsLocalGp)
+      ElfSym::MipsLocalGp->Value = ElfSym::MipsGp->Value;
   }
 }
 




More information about the llvm-commits mailing list