[lld] r265234 - Remove DefinedElf class.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 11:06:19 PDT 2016


Author: ruiu
Date: Sat Apr  2 13:06:18 2016
New Revision: 265234

URL: http://llvm.org/viewvc/llvm-project?rev=265234&view=rev
Log:
Remove DefinedElf class.

DefinedElf was a superclass of DefinedRegular and SharedSymbol classes
and represented the notion of defined symbols created for ELF symbols.

It turned out that we didn't use that class often. We had only two
occurrences of dyn_cast'ing to DefinedElf, and both were easily
rewritten without it.

The class was also a bit confusing. The concept of "created for ELF
symbol" is orthogonal to defined/undefined types. However, we had
two distinct classes, DefinedElf and UndefinedElf.

This patch simply removes the class. Now the class hierarchy is one
level shallower.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=265234&r1=265233&r2=265234&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sat Apr  2 13:06:18 2016
@@ -1451,15 +1451,6 @@ void SymbolTableSection<ELFT>::writeLoca
 }
 
 template <class ELFT>
-static const typename ELFT::Sym *getElfSym(SymbolBody &Body) {
-  if (auto *EBody = dyn_cast<DefinedElf<ELFT>>(&Body))
-    return &EBody->Sym;
-  if (auto *EBody = dyn_cast<UndefinedElf<ELFT>>(&Body))
-    return &EBody->Sym;
-  return nullptr;
-}
-
-template <class ELFT>
 void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) {
   // Write the internal symbol table contents to the output symbol table
   // pointed by Buf.
@@ -1470,7 +1461,7 @@ void SymbolTableSection<ELFT>::writeGlob
 
     uint8_t Type = STT_NOTYPE;
     uintX_t Size = 0;
-    if (const Elf_Sym *InputSym = getElfSym<ELFT>(*Body)) {
+    if (const Elf_Sym *InputSym = Body->getElfSym<ELFT>()) {
       Type = InputSym->getType();
       Size = InputSym->st_size;
     } else if (auto *C = dyn_cast<DefinedCommon>(Body)) {
@@ -1533,7 +1524,7 @@ uint8_t SymbolTableSection<ELFT>::getSym
   uint8_t Visibility = Body->getVisibility();
   if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
     return STB_LOCAL;
-  if (const Elf_Sym *ESym = getElfSym<ELFT>(*Body))
+  if (const Elf_Sym *ESym = Body->getElfSym<ELFT>())
     return ESym->getBinding();
   if (isa<DefinedSynthetic<ELFT>>(Body))
     return STB_LOCAL;

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=265234&r1=265233&r2=265234&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sat Apr  2 13:06:18 2016
@@ -143,11 +143,21 @@ template <class ELFT> typename ELFT::uin
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
-  if (auto *B = dyn_cast<DefinedElf<ELFT>>(this))
-    return B->Sym.st_size;
+  if (const typename ELFT::Sym *Sym = getElfSym<ELFT>())
+    return Sym->st_size;
   return 0;
 }
 
+template <class ELFT> const typename ELFT::Sym *SymbolBody::getElfSym() const {
+  if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this))
+    return &S->Sym;
+  if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
+    return &S->Sym;
+  if (auto *S = dyn_cast<UndefinedElf<ELFT>>(this))
+    return &S->Sym;
+  return nullptr;
+}
+
 static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
   if (VA == STV_DEFAULT)
     return VB;
@@ -307,6 +317,11 @@ template uint32_t SymbolBody::template g
 template uint64_t SymbolBody::template getSize<ELF64LE>() const;
 template uint64_t SymbolBody::template getSize<ELF64BE>() const;
 
+template const ELF32LE::Sym *SymbolBody::template getElfSym<ELF32LE>() const;
+template const ELF32BE::Sym *SymbolBody::template getElfSym<ELF32BE>() const;
+template const ELF64LE::Sym *SymbolBody::template getElfSym<ELF64LE>() const;
+template const ELF64BE::Sym *SymbolBody::template getElfSym<ELF64BE>() const;
+
 template uint32_t SymbolBody::template getThunkVA<ELF32LE>() const;
 template uint32_t SymbolBody::template getThunkVA<ELF32BE>() const;
 template uint64_t SymbolBody::template getThunkVA<ELF64LE>() const;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=265234&r1=265233&r2=265234&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Sat Apr  2 13:06:18 2016
@@ -51,7 +51,6 @@ public:
     DefinedFirst,
     DefinedRegularKind = DefinedFirst,
     SharedKind,
-    DefinedElfLast = SharedKind,
     DefinedCommonKind,
     DefinedBitcodeKind,
     DefinedSyntheticKind,
@@ -101,6 +100,7 @@ public:
   template <class ELFT> typename ELFT::uint getPltVA() const;
   template <class ELFT> typename ELFT::uint getThunkVA() const;
   template <class ELFT> typename ELFT::uint getSize() const;
+  template <class ELFT> const typename ELFT::Sym *getElfSym() const;
 
   // A SymbolBody has a backreference to a Symbol. Originally they are
   // doubly-linked. A backreference will never change. But the pointer
@@ -165,24 +165,7 @@ public:
   static bool classof(const SymbolBody *S) { return S->isDefined(); }
 };
 
-// Any defined symbol from an ELF file.
-template <class ELFT> class DefinedElf : public Defined {
-protected:
-  typedef typename ELFT::Sym Elf_Sym;
-
-public:
-  DefinedElf(Kind K, StringRef N, const Elf_Sym &Sym)
-      : Defined(K, N, Sym.getBinding() == llvm::ELF::STB_WEAK,
-                Sym.getBinding() == llvm::ELF::STB_LOCAL, Sym.getVisibility(),
-                Sym.getType()),
-        Sym(Sym) {}
-
-  const Elf_Sym &Sym;
-  static bool classof(const SymbolBody *S) {
-    return S->kind() <= DefinedElfLast;
-  }
-};
-
+// The defined symbol in LLVM bitcode files.
 class DefinedBitcode : public Defined {
 public:
   DefinedBitcode(StringRef Name, bool IsWeak, uint8_t Visibility);
@@ -209,19 +192,24 @@ public:
 };
 
 // Regular defined symbols read from object file symbol tables.
-template <class ELFT> class DefinedRegular : public DefinedElf<ELFT> {
+template <class ELFT> class DefinedRegular : public Defined {
   typedef typename ELFT::Sym Elf_Sym;
 
 public:
-  DefinedRegular(StringRef N, const Elf_Sym &Sym,
+  DefinedRegular(StringRef Name, const Elf_Sym &Sym,
                  InputSectionBase<ELFT> *Section)
-      : DefinedElf<ELFT>(SymbolBody::DefinedRegularKind, N, Sym),
-        Section(Section ? Section->Repl : NullInputSection) {}
+      : Defined(SymbolBody::DefinedRegularKind, Name,
+                Sym.getBinding() == llvm::ELF::STB_WEAK,
+                Sym.getBinding() == llvm::ELF::STB_LOCAL,
+                Sym.getVisibility(), Sym.getType()),
+        Sym(Sym), Section(Section ? Section->Repl : NullInputSection) {}
 
   static bool classof(const SymbolBody *S) {
     return S->kind() == SymbolBody::DefinedRegularKind;
   }
 
+  const Elf_Sym &Sym;
+
   // The input section this symbol belongs to. Notice that this is
   // a reference to a pointer. We are using two levels of indirections
   // because of ICF. If ICF decides two sections need to be merged, it
@@ -289,7 +277,7 @@ public:
   }
 };
 
-template <class ELFT> class SharedSymbol : public DefinedElf<ELFT> {
+template <class ELFT> class SharedSymbol : public Defined {
   typedef typename ELFT::Sym Elf_Sym;
   typedef typename ELFT::uint uintX_t;
 
@@ -299,9 +287,14 @@ public:
   }
 
   SharedSymbol(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym)
-      : DefinedElf<ELFT>(SymbolBody::SharedKind, Name, Sym), File(F) {}
+      : Defined(SymbolBody::SharedKind, Name,
+                Sym.getBinding() == llvm::ELF::STB_WEAK,
+                Sym.getBinding() == llvm::ELF::STB_LOCAL,
+                Sym.getVisibility(), Sym.getType()),
+        File(F), Sym(Sym) {}
 
   SharedFile<ELFT> *File;
+  const Elf_Sym &Sym;
 
   // OffsetInBss is significant only when needsCopy() is true.
   uintX_t OffsetInBss = 0;




More information about the llvm-commits mailing list