summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-04-02 18:06:18 +0000
committerRui Ueyama <ruiu@google.com>2016-04-02 18:06:18 +0000
commitbfc1d9d976f653c2695aa12e656ae1ae94795dac (patch)
tree93e020e732debe7f6a70bbe8d16e47a49b1288df
parent6d72d166dc0b67418bd334886e29a0a2bf541a92 (diff)
downloadbcm5719-llvm-bfc1d9d976f653c2695aa12e656ae1ae94795dac.tar.gz
bcm5719-llvm-bfc1d9d976f653c2695aa12e656ae1ae94795dac.zip
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. llvm-svn: 265234
-rw-r--r--lld/ELF/OutputSections.cpp13
-rw-r--r--lld/ELF/Symbols.cpp19
-rw-r--r--lld/ELF/Symbols.h43
3 files changed, 37 insertions, 38 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index bf693b78a97..c8acbb9e902 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -1451,15 +1451,6 @@ void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) {
}
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>::writeGlobalSymbols(uint8_t *Buf) {
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>::getSymbolBinding(SymbolBody *Body) {
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;
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index b536defca55..d4f612081ab 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -143,11 +143,21 @@ template <class ELFT> typename ELFT::uint SymbolBody::getThunkVA() const {
}
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 getSize<ELF32BE>() const;
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;
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 5f5ce88cff1..9e8199571fa 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -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;
OpenPOWER on IntegriCloud