[lld] r317448 - ELF: Merge DefinedRegular and Defined.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 5 20:35:32 PST 2017


Author: pcc
Date: Sun Nov  5 20:35:31 2017
New Revision: 317448

URL: http://llvm.org/viewvc/llvm-project?rev=317448&view=rev
Log:
ELF: Merge DefinedRegular and Defined.

Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

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

Modified:
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/ELF/GdbIndex.cpp
    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/LinkerScript.h
    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/Thunks.cpp
    lld/trunk/ELF/Thunks.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Sun Nov  5 20:35:31 2017
@@ -346,7 +346,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr Expr
   // 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>(&S);
+  auto *D = dyn_cast<Defined>(&S);
   // LA25 is required if target file has PIC code
   // or target symbol is a PIC symbol.
   return D && D->isMipsPIC<ELFT>();

Modified: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp Sun Nov  5 20:35:31 2017
@@ -67,7 +67,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSe
   const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
   uint32_t SecIndex = File->getSectionIndex(Sym);
   Symbol &B = File->getRelocTargetSym(Rel);
-  auto &DR = cast<DefinedRegular>(B);
+  auto &DR = cast<Defined>(B);
   uint64_t Val = DR.Value + getAddend<ELFT>(Rel);
 
   // FIXME: We should be consistent about always adding the file

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Sun Nov  5 20:35:31 2017
@@ -228,8 +228,8 @@ bool ICF<ELFT>::constantEq(const InputSe
       return false;
     }
 
-    auto *DA = dyn_cast<DefinedRegular>(&SA);
-    auto *DB = dyn_cast<DefinedRegular>(&SB);
+    auto *DA = dyn_cast<Defined>(&SA);
+    auto *DB = dyn_cast<Defined>(&SB);
     if (!DA || !DB)
       return false;
 
@@ -300,8 +300,8 @@ bool ICF<ELFT>::variableEq(const InputSe
     if (&SA == &SB)
       continue;
 
-    auto *DA = cast<DefinedRegular>(&SA);
-    auto *DB = cast<DefinedRegular>(&SB);
+    auto *DA = cast<Defined>(&SA);
+    auto *DB = cast<Defined>(&SB);
 
     // We already dealt with absolute and non-InputSection symbols in
     // constantEq, and for InputSections we have already checked everything

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Sun Nov  5 20:35:31 2017
@@ -600,8 +600,8 @@ template <class ELFT> Symbol *ObjFile<EL
     if (Sym->st_shndx == SHN_UNDEF)
       return make<Undefined>(Name, /*IsLocal=*/true, StOther, Type);
 
-    return make<DefinedRegular>(Name, /*IsLocal=*/true, StOther, Type, Value,
-                                Size, Sec);
+    return make<Defined>(Name, /*IsLocal=*/true, StOther, Type, Value, Size,
+                         Sec);
   }
 
   StringRef Name = check(Sym->getName(this->StringTable), toString(this));

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun Nov  5 20:35:31 2017
@@ -61,7 +61,7 @@ DenseMap<SectionBase *, int> elf::buildS
   // Build a map from sections to their priorities.
   for (InputFile *File : ObjectFiles) {
     for (Symbol *Sym : File->getSymbols()) {
-      auto *D = dyn_cast<DefinedRegular>(Sym);
+      auto *D = dyn_cast<Defined>(Sym);
       if (!D || !D->Section)
         continue;
       int &Priority = SectionOrder[D->Section];
@@ -214,7 +214,7 @@ void InputSectionBase::maybeUncompress()
   this->Flags &= ~(uint64_t)SHF_COMPRESSED;
 }
 
-uint64_t SectionBase::getOffset(const DefinedRegular &Sym) const {
+uint64_t SectionBase::getOffset(const Defined &Sym) const {
   return getOffset(Sym.Value);
 }
 
@@ -251,7 +251,7 @@ std::string InputSectionBase::getLocatio
 
   // Find a function symbol that encloses a given location.
   for (Symbol *B : File->getSymbols())
-    if (auto *D = dyn_cast<DefinedRegular>(B))
+    if (auto *D = dyn_cast<Defined>(B))
       if (D->Section == this && D->Type == STT_FUNC)
         if (D->Value <= Offset && Offset < D->Value + D->Size)
           return SrcFile + ":(function " + toString(*D) + ")";
@@ -317,7 +317,7 @@ std::string InputSectionBase::getObjMsg(
 
   // Find a symbol that encloses a given location.
   for (Symbol *B : File->getSymbols())
-    if (auto *D = dyn_cast<DefinedRegular>(B))
+    if (auto *D = dyn_cast<Defined>(B))
       if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size)
         return Filename + ":(" + toString(*D) + ")" + Archive;
 
@@ -404,7 +404,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.
-      SectionBase *Section = cast<DefinedRegular>(Sym).Section;
+      SectionBase *Section = cast<Defined>(Sym).Section;
       if (Section == &InputSection::Discarded) {
         P->setSymbolAndType(0, 0, false);
         continue;

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sun Nov  5 20:35:31 2017
@@ -27,7 +27,7 @@ namespace elf {
 class Symbol;
 struct SectionPiece;
 
-class DefinedRegular;
+class Defined;
 class SyntheticSection;
 class MergeSyntheticSection;
 template <class ELFT> class ObjFile;
@@ -73,7 +73,7 @@ public:
   // section.
   uint64_t getOffset(uint64_t Offset) const;
 
-  uint64_t getOffset(const DefinedRegular &Sym) const;
+  uint64_t getOffset(const Defined &Sym) const;
 
 protected:
   SectionBase(Kind SectionKind, StringRef Name, uint64_t Flags,

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sun Nov  5 20:35:31 2017
@@ -149,9 +149,9 @@ void LinkerScript::addSymbol(SymbolAssig
   // write expressions like this: `alignment = 16; . = ALIGN(., alignment)`.
   uint64_t SymValue = Value.Sec ? 0 : Value.getValue();
 
-  replaceSymbol<DefinedRegular>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false,
-                                Visibility, STT_NOTYPE, SymValue, 0, Sec);
-  Cmd->Sym = cast<DefinedRegular>(Sym);
+  replaceSymbol<Defined>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false, Visibility,
+                         STT_NOTYPE, SymValue, 0, Sec);
+  Cmd->Sym = cast<Defined>(Sym);
 }
 
 // This function is called from assignAddresses, while we are
@@ -977,7 +977,7 @@ ExprValue LinkerScript::getSymbolValue(S
     return 0;
   }
 
-  if (auto *Sym = dyn_cast_or_null<DefinedRegular>(Symtab->find(Name)))
+  if (auto *Sym = dyn_cast_or_null<Defined>(Symtab->find(Name)))
     return {Sym->Section, false, Sym->Value, Loc};
 
   error(Loc + ": symbol not found: " + Name);

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Sun Nov  5 20:35:31 2017
@@ -29,7 +29,7 @@
 namespace lld {
 namespace elf {
 
-class DefinedRegular;
+class Defined;
 class Symbol;
 class InputSectionBase;
 class InputSection;
@@ -96,7 +96,7 @@ struct SymbolAssignment : BaseCommand {
 
   // The LHS of an expression. Name is either a symbol name or ".".
   StringRef Name;
-  DefinedRegular *Sym = nullptr;
+  Defined *Sym = nullptr;
 
   // The RHS of an expression.
   Expr Expression;

Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Sun Nov  5 20:35:31 2017
@@ -51,7 +51,7 @@ static std::vector<Defined *> getSymbols
   std::vector<Defined *> V;
   for (InputFile *File : ObjectFiles)
     for (Symbol *B : File->getSymbols())
-      if (auto *DR = dyn_cast<DefinedRegular>(B))
+      if (auto *DR = dyn_cast<Defined>(B))
         if (DR->getFile() == File && !DR->isSection() && DR->Section &&
             DR->Section->Live)
           V.push_back(DR);
@@ -62,7 +62,7 @@ static std::vector<Defined *> getSymbols
 static SymbolMapTy getSectionSyms(ArrayRef<Defined *> Syms) {
   SymbolMapTy Ret;
   for (Defined *S : Syms)
-    if (auto *DR = dyn_cast<DefinedRegular>(S))
+    if (auto *DR = dyn_cast<Defined>(S))
       Ret[DR->Section].push_back(S);
 
   // Sort symbols by address. We want to print out symbols in the

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Sun Nov  5 20:35:31 2017
@@ -64,7 +64,7 @@ static void resolveReloc(InputSectionBas
                          std::function<void(InputSectionBase *, uint64_t)> Fn) {
   Symbol &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
 
-  if (auto *D = dyn_cast<DefinedRegular>(&B)) {
+  if (auto *D = dyn_cast<Defined>(&B)) {
     if (!D->Section)
       return;
     uint64_t Offset = D->Value;
@@ -212,7 +212,7 @@ template <class ELFT> static void doGcSe
   };
 
   auto MarkSymbol = [&](Symbol *Sym) {
-    if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym))
+    if (auto *D = dyn_cast_or_null<Defined>(Sym))
       if (auto *IS = cast_or_null<InputSectionBase>(D->Section))
         Enqueue(IS, D->Value);
   };

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Sun Nov  5 20:35:31 2017
@@ -33,7 +33,7 @@ class OutputSection;
 template <class ELFT> class ObjFile;
 template <class ELFT> class SharedFile;
 class SharedSymbol;
-class DefinedRegular;
+class Defined;
 
 // 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=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sun Nov  5 20:35:31 2017
@@ -326,7 +326,7 @@ static RelType getMipsPairType(RelType T
 static bool isAbsolute(const Symbol &Sym) {
   if (Sym.isUndefWeak())
     return true;
-  if (const auto *DR = dyn_cast<DefinedRegular>(&Sym))
+  if (const auto *DR = dyn_cast<Defined>(&Sym))
     return DR->Section == nullptr; // Absolute symbol.
   return false;
 }

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Sun Nov  5 20:35:31 2017
@@ -135,11 +135,11 @@ template <class ELFT> void SymbolTable::
 }
 
 template <class ELFT>
-DefinedRegular *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
-                                         uint8_t Binding) {
+Defined *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
+                                  uint8_t Binding) {
   Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
                                  nullptr, nullptr);
-  return cast<DefinedRegular>(Sym);
+  return cast<Defined>(Sym);
 }
 
 // Set a flag for --trace-symbol so that we can print out a log message
@@ -366,7 +366,7 @@ static int compareDefinedNonCommon(Symbo
       S->Binding = Binding;
     return Cmp;
   }
-  if (auto *R = dyn_cast<DefinedRegular>(S)) {
+  if (auto *R = dyn_cast<Defined>(S)) {
     if (R->Section && isa<BssSection>(R->Section)) {
       // Non-common symbols take precedence over common symbols.
       if (Config->WarnCommon)
@@ -395,10 +395,10 @@ Symbol *SymbolTable::addCommon(StringRef
     InputSections.push_back(Bss);
 
     S->Binding = Binding;
-    replaceSymbol<DefinedRegular>(S, File, N, /*IsLocal=*/false, StOther, Type,
-                                  0, Size, Bss);
+    replaceSymbol<Defined>(S, File, N, /*IsLocal=*/false, StOther, Type, 0,
+                           Size, Bss);
   } else if (Cmp == 0) {
-    auto *D = cast<DefinedRegular>(S);
+    auto *D = cast<Defined>(S);
     auto *Bss = dyn_cast_or_null<BssSection>(D->Section);
     if (!Bss) {
       // Non-common symbols take precedence over common symbols.
@@ -435,7 +435,7 @@ static void reportDuplicate(Symbol *Sym,
 template <class ELFT>
 static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
                             typename ELFT::uint ErrOffset) {
-  DefinedRegular *D = dyn_cast<DefinedRegular>(Sym);
+  Defined *D = dyn_cast<Defined>(Sym);
   if (!D || !D->Section || !ErrSec) {
     reportDuplicate(Sym, ErrSec ? ErrSec->File : nullptr);
     return;
@@ -475,8 +475,8 @@ Symbol *SymbolTable::addRegular(StringRe
   int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
                                     Value, Name);
   if (Cmp > 0)
-    replaceSymbol<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther,
-                                  Type, Value, Size, Section);
+    replaceSymbol<Defined>(S, File, Name, /*IsLocal=*/false, StOther, Type,
+                           Value, Size, Section);
   else if (Cmp == 0)
     reportDuplicate<ELFT>(S, dyn_cast_or_null<InputSectionBase>(Section),
                           Value);
@@ -519,8 +519,8 @@ Symbol *SymbolTable::addBitcode(StringRe
   int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
                                     /*IsAbs*/ false, /*Value*/ 0, Name);
   if (Cmp > 0)
-    replaceSymbol<DefinedRegular>(S, F, Name, /*IsLocal=*/false, StOther, Type,
-                                  0, 0, nullptr);
+    replaceSymbol<Defined>(S, F, Name, /*IsLocal=*/false, StOther, Type, 0, 0,
+                           nullptr);
   else if (Cmp == 0)
     reportDuplicate(S, F);
   return S;
@@ -818,14 +818,14 @@ template Symbol *SymbolTable::addRegular
                                                   uint64_t, uint64_t, uint8_t,
                                                   SectionBase *, InputFile *);
 
-template DefinedRegular *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
-                                                           uint8_t);
-template DefinedRegular *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
-                                                           uint8_t);
-template DefinedRegular *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
-                                                           uint8_t);
-template DefinedRegular *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
-                                                           uint8_t);
+template Defined *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
+                                                    uint8_t);
+template Defined *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
+                                                    uint8_t);
+template Defined *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
+                                                    uint8_t);
+template Defined *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
+                                                    uint8_t);
 
 template Symbol *
 SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile *,

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Sun Nov  5 20:35:31 2017
@@ -41,9 +41,9 @@ public:
   ArrayRef<Symbol *> getSymbols() const { return SymVector; }
 
   template <class ELFT>
-  DefinedRegular *addAbsolute(StringRef Name,
-                              uint8_t Visibility = llvm::ELF::STV_HIDDEN,
-                              uint8_t Binding = llvm::ELF::STB_GLOBAL);
+  Defined *addAbsolute(StringRef Name,
+                       uint8_t Visibility = llvm::ELF::STV_HIDDEN,
+                       uint8_t Binding = llvm::ELF::STB_GLOBAL);
 
   template <class ELFT> Symbol *addUndefined(StringRef Name);
   template <class ELFT>

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sun Nov  5 20:35:31 2017
@@ -28,22 +28,22 @@ using namespace llvm::ELF;
 using namespace lld;
 using namespace lld::elf;
 
-DefinedRegular *ElfSym::Bss;
-DefinedRegular *ElfSym::Etext1;
-DefinedRegular *ElfSym::Etext2;
-DefinedRegular *ElfSym::Edata1;
-DefinedRegular *ElfSym::Edata2;
-DefinedRegular *ElfSym::End1;
-DefinedRegular *ElfSym::End2;
-DefinedRegular *ElfSym::GlobalOffsetTable;
-DefinedRegular *ElfSym::MipsGp;
-DefinedRegular *ElfSym::MipsGpDisp;
-DefinedRegular *ElfSym::MipsLocalGp;
+Defined *ElfSym::Bss;
+Defined *ElfSym::Etext1;
+Defined *ElfSym::Etext2;
+Defined *ElfSym::Edata1;
+Defined *ElfSym::Edata2;
+Defined *ElfSym::End1;
+Defined *ElfSym::End2;
+Defined *ElfSym::GlobalOffsetTable;
+Defined *ElfSym::MipsGp;
+Defined *ElfSym::MipsGpDisp;
+Defined *ElfSym::MipsLocalGp;
 
 static uint64_t getSymVA(const Symbol &Sym, int64_t &Addend) {
   switch (Sym.kind()) {
-  case Symbol::DefinedRegularKind: {
-    auto &D = cast<DefinedRegular>(Sym);
+  case Symbol::DefinedKind: {
+    auto &D = cast<Defined>(Sym);
     SectionBase *IS = D.Section;
     if (auto *ISB = dyn_cast_or_null<InputSectionBase>(IS))
       IS = ISB->Repl;
@@ -125,7 +125,7 @@ bool Symbol::isUndefWeak() const {
 
 InputFile *Symbol::getFile() const {
   if (isLocal()) {
-    const SectionBase *Sec = cast<DefinedRegular>(this)->Section;
+    const SectionBase *Sec = cast<Defined>(this)->Section;
     // Local absolute symbols actually have a file, but that is not currently
     // used. We could support that by having a mostly redundant InputFile in
     // Symbol, or having a special absolute section if needed.
@@ -180,7 +180,7 @@ uint64_t Symbol::getPltVA() const {
 }
 
 uint64_t Symbol::getSize() const {
-  if (const auto *DR = dyn_cast<DefinedRegular>(this))
+  if (const auto *DR = dyn_cast<Defined>(this))
     return DR->Size;
   if (const auto *S = dyn_cast<SharedSymbol>(this))
     return S->Size;
@@ -188,7 +188,7 @@ uint64_t Symbol::getSize() const {
 }
 
 OutputSection *Symbol::getOutputSection() const {
-  if (auto *S = dyn_cast<DefinedRegular>(this)) {
+  if (auto *S = dyn_cast<Defined>(this)) {
     if (S->Section)
       return S->Section->getOutputSection();
     return nullptr;
@@ -247,7 +247,7 @@ void Symbol::parseSymbolVersion() {
           Verstr);
 }
 
-template <class ELFT> bool DefinedRegular::isMipsPIC() const {
+template <class ELFT> bool Defined::isMipsPIC() const {
   typedef typename ELFT::Ehdr Elf_Ehdr;
   if (!Section || !isFunc())
     return false;
@@ -315,7 +315,7 @@ void elf::printTraceSymbol(Symbol *Sym)
     S = ": lazy definition of ";
   else if (Sym->isShared())
     S = ": shared definition of ";
-  else if (dyn_cast_or_null<BssSection>(cast<DefinedRegular>(Sym)->Section))
+  else if (dyn_cast_or_null<BssSection>(cast<Defined>(Sym)->Section))
     S = ": common definition of ";
   else
     S = ": definition of ";
@@ -331,7 +331,7 @@ std::string lld::toString(const Symbol &
   return B.getName();
 }
 
-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 bool Defined::template isMipsPIC<ELF32LE>() const;
+template bool Defined::template isMipsPIC<ELF32BE>() const;
+template bool Defined::template isMipsPIC<ELF64LE>() const;
+template bool Defined::template isMipsPIC<ELF64BE>() const;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Sun Nov  5 20:35:31 2017
@@ -38,9 +38,7 @@ template <class ELFT> class SharedFile;
 class Symbol {
 public:
   enum Kind {
-    DefinedFirst,
-    DefinedRegularKind = DefinedFirst,
-    DefinedLast = DefinedRegularKind,
+    DefinedKind,
     SharedKind,
     UndefinedKind,
     LazyArchiveKind,
@@ -95,7 +93,7 @@ public:
   bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
 
   bool isUndefined() const { return SymbolKind == UndefinedKind; }
-  bool isDefined() const { return SymbolKind <= DefinedLast; }
+  bool isDefined() const { return SymbolKind == DefinedKind; }
   bool isShared() const { return SymbolKind == SharedKind; }
   bool isLocal() const { return IsLocal; }
 
@@ -103,9 +101,7 @@ public:
     return SymbolKind == LazyArchiveKind || SymbolKind == LazyObjectKind;
   }
 
-  bool isInCurrentOutput() const {
-    return SymbolKind == DefinedRegularKind;
-  }
+  bool isInCurrentOutput() const { return isDefined(); }
 
   // True is this is an undefined weak symbol. This only works once
   // all input files have been added.
@@ -188,29 +184,18 @@ protected:
   StringRefZ Name;
 };
 
-// The base class for any defined symbols.
+// Represents a symbol that is defined in the current output file.
 class Defined : public Symbol {
 public:
-  Defined(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type)
-      : Symbol(K, Name, IsLocal, StOther, Type) {}
-
-  static bool classof(const Symbol *S) { return S->isDefined(); }
-};
-
-// Regular defined symbols read from object file symbol tables.
-class DefinedRegular : public Defined {
-public:
-  DefinedRegular(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
-                 uint64_t Value, uint64_t Size, SectionBase *Section)
-      : Defined(DefinedRegularKind, Name, IsLocal, StOther, Type), Value(Value),
+  Defined(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
+          uint64_t Value, uint64_t Size, SectionBase *Section)
+      : Symbol(DefinedKind, Name, IsLocal, StOther, Type), Value(Value),
         Size(Size), Section(Section) {}
 
   // Return true if the symbol is a PIC function.
   template <class ELFT> bool isMipsPIC() const;
 
-  static bool classof(const Symbol *S) {
-    return S->kind() == DefinedRegularKind;
-  }
+  static bool classof(const Symbol *S) { return S->isDefined(); }
 
   uint64_t Value;
   uint64_t Size;
@@ -323,39 +308,39 @@ public:
 };
 
 // Some linker-generated symbols need to be created as
-// DefinedRegular symbols.
+// Defined symbols.
 struct ElfSym {
   // __bss_start
-  static DefinedRegular *Bss;
+  static Defined *Bss;
 
   // etext and _etext
-  static DefinedRegular *Etext1;
-  static DefinedRegular *Etext2;
+  static Defined *Etext1;
+  static Defined *Etext2;
 
   // edata and _edata
-  static DefinedRegular *Edata1;
-  static DefinedRegular *Edata2;
+  static Defined *Edata1;
+  static Defined *Edata2;
 
   // end and _end
-  static DefinedRegular *End1;
-  static DefinedRegular *End2;
+  static Defined *End1;
+  static Defined *End2;
 
   // The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to
   // be at some offset from the base of the .got section, usually 0 or
   // the end of the .got.
-  static DefinedRegular *GlobalOffsetTable;
+  static Defined *GlobalOffsetTable;
 
   // _gp, _gp_disp and __gnu_local_gp symbols. Only for MIPS.
-  static DefinedRegular *MipsGp;
-  static DefinedRegular *MipsGpDisp;
-  static DefinedRegular *MipsLocalGp;
+  static Defined *MipsGp;
+  static Defined *MipsGpDisp;
+  static Defined *MipsLocalGp;
 };
 
 // A buffer class that is large enough to hold any Symbol-derived
 // object. We allocate memory using this class and instantiate a symbol
 // using the placement new.
 union SymbolUnion {
-  alignas(DefinedRegular) char A[sizeof(DefinedRegular)];
+  alignas(Defined) char A[sizeof(Defined)];
   alignas(Undefined) char C[sizeof(Undefined)];
   alignas(SharedSymbol) char D[sizeof(SharedSymbol)];
   alignas(LazyArchive) char E[sizeof(LazyArchive)];

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sun Nov  5 20:35:31 2017
@@ -275,8 +275,8 @@ InputSection *elf::createInterpSection()
 
 Symbol *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
                                uint64_t Size, InputSectionBase *Section) {
-  auto *S = make<DefinedRegular>(Name, /*IsLocal*/ true, STV_DEFAULT, Type,
-                                 Value, Size, Section);
+  auto *S = make<Defined>(Name, /*IsLocal*/ true, STV_DEFAULT, Type, Value,
+                          Size, Section);
   if (InX::SymTab)
     InX::SymTab->addSymbol(S);
   return S;
@@ -428,7 +428,7 @@ bool EhFrameSection::isFdeLive(EhSection
   Symbol &B = Sec->template getFile<ELFT>()->getRelocTargetSym(Rel);
 
   // FDEs for garbage-collected or merged-by-ICF sections are dead.
-  if (auto *D = dyn_cast<DefinedRegular>(&B))
+  if (auto *D = dyn_cast<Defined>(&B))
     if (auto *Sec = cast_or_null<InputSectionBase>(D->Section))
       return Sec->Live && (Sec == Sec->Repl);
   return false;
@@ -1576,13 +1576,13 @@ template <class ELFT> void SymbolTableSe
     // Set a section index.
     BssSection *CommonSec = nullptr;
     if (!Config->DefineCommon)
-      if (auto *D = dyn_cast<DefinedRegular>(Sym))
+      if (auto *D = dyn_cast<Defined>(Sym))
         CommonSec = dyn_cast_or_null<BssSection>(D->Section);
     if (CommonSec)
       ESym->st_shndx = SHN_COMMON;
     else if (const OutputSection *OutSec = Sym->getOutputSection())
       ESym->st_shndx = OutSec->SectionIndex;
-    else if (isa<DefinedRegular>(Sym))
+    else if (isa<Defined>(Sym))
       ESym->st_shndx = SHN_ABS;
     else
       ESym->st_shndx = SHN_UNDEF;
@@ -1621,7 +1621,7 @@ template <class ELFT> void SymbolTableSe
         ESym->st_other |= STO_MIPS_PLT;
 
       if (Config->Relocatable)
-        if (auto *D = dyn_cast<DefinedRegular>(Sym))
+        if (auto *D = dyn_cast<Defined>(Sym))
           if (D->isMipsPIC<ELFT>())
             ESym->st_other |= STO_MIPS_PIC;
       ++ESym;

Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Sun Nov  5 20:35:31 2017
@@ -251,7 +251,7 @@ void MipsThunk::addSymbols(ThunkSection
 }
 
 InputSection *MipsThunk::getTargetInputSection() const {
-  auto *DR = dyn_cast<DefinedRegular>(&Destination);
+  auto *DR = dyn_cast<Defined>(&Destination);
   return dyn_cast<InputSection>(DR->Section);
 }
 
@@ -276,7 +276,7 @@ void MicroMipsThunk::addSymbols(ThunkSec
 }
 
 InputSection *MicroMipsThunk::getTargetInputSection() const {
-  auto *DR = dyn_cast<DefinedRegular>(&Destination);
+  auto *DR = dyn_cast<Defined>(&Destination);
   return dyn_cast<InputSection>(DR->Section);
 }
 
@@ -301,7 +301,7 @@ void MicroMipsR6Thunk::addSymbols(ThunkS
 }
 
 InputSection *MicroMipsR6Thunk::getTargetInputSection() const {
-  auto *DR = dyn_cast<DefinedRegular>(&Destination);
+  auto *DR = dyn_cast<Defined>(&Destination);
   return dyn_cast<InputSection>(DR->Section);
 }
 

Modified: lld/trunk/ELF/Thunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.h?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.h (original)
+++ lld/trunk/ELF/Thunks.h Sun Nov  5 20:35:31 2017
@@ -23,7 +23,7 @@ class ThunkSection;
 // include transferring control from non-pi to pi and changing state on
 // targets like ARM.
 //
-// Thunks can be created for DefinedRegular, Shared and Undefined Symbols.
+// Thunks can be created for Defined, Shared and Undefined Symbols.
 // Thunks are assigned to synthetic ThunkSections
 class Thunk {
 public:

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=317448&r1=317447&r2=317448&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Nov  5 20:35:31 2017
@@ -426,7 +426,7 @@ static bool includeInSymtab(const Symbol
   if (!B.isLocal() && !B.IsUsedInRegularObj)
     return false;
 
-  if (auto *D = dyn_cast<DefinedRegular>(&B)) {
+  if (auto *D = dyn_cast<Defined>(&B)) {
     // Always include absolute symbols.
     SectionBase *Sec = D->Section;
     if (!Sec)
@@ -456,7 +456,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>(B);
+      auto *DR = dyn_cast<Defined>(B);
 
       // No reason to keep local undefined symbol in symtab.
       if (!DR)
@@ -491,9 +491,8 @@ template <class ELFT> void Writer<ELFT>:
         IS->Type == SHT_RELA)
       continue;
 
-    auto *Sym =
-        make<DefinedRegular>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
-                             /*Value=*/0, /*Size=*/0, IS);
+    auto *Sym = make<Defined>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
+                              /*Value=*/0, /*Size=*/0, IS);
     InX::SymTab->addSymbol(Sym);
   }
 }
@@ -735,16 +734,16 @@ void PhdrEntry::add(OutputSection *Sec)
 }
 
 template <class ELFT>
-static DefinedRegular *
-addOptionalRegular(StringRef Name, SectionBase *Sec, uint64_t Val,
-                   uint8_t StOther = STV_HIDDEN, uint8_t Binding = STB_GLOBAL) {
+static Defined *addOptionalRegular(StringRef Name, SectionBase *Sec,
+                                   uint64_t Val, uint8_t StOther = STV_HIDDEN,
+                                   uint8_t Binding = STB_GLOBAL) {
   Symbol *S = Symtab->find(Name);
   if (!S || S->isInCurrentOutput())
     return nullptr;
   Symbol *Sym = Symtab->addRegular<ELFT>(Name, StOther, STT_NOTYPE, Val,
                                          /*Size=*/0, Binding, Sec,
                                          /*File=*/nullptr);
-  return cast<DefinedRegular>(Sym);
+  return cast<Defined>(Sym);
 }
 
 // The beginning and the ending of .rel[a].plt section are marked




More information about the llvm-commits mailing list