[lld] r256354 - Split Defined and DefinedElf.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 23 16:47:43 PST 2015
Author: rafael
Date: Wed Dec 23 18:47:42 2015
New Revision: 256354
URL: http://llvm.org/viewvc/llvm-project?rev=256354&view=rev
Log:
Split Defined and DefinedElf.
This is similar to what was done for Undefined and opens the way for
having a symbol defined in bitcode.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Dec 23 18:47:42 2015
@@ -130,7 +130,7 @@ InputSectionBase<ELFT>::findMipsPairedRe
template <class ELFT>
static typename llvm::object::ELFFile<ELFT>::uintX_t
getSymSize(SymbolBody &Body) {
- if (auto *SS = dyn_cast<Defined<ELFT>>(&Body))
+ if (auto *SS = dyn_cast<DefinedElf<ELFT>>(&Body))
return SS->Sym.st_size;
return 0;
}
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Dec 23 18:47:42 2015
@@ -787,7 +787,7 @@ typename ELFFile<ELFT>::uintX_t lld::elf
switch (S.kind()) {
case SymbolBody::DefinedSyntheticKind: {
auto &D = cast<DefinedSynthetic<ELFT>>(S);
- return D.Section.getVA() + D.Sym.st_value;
+ return D.Section.getVA() + D.Value;
}
case SymbolBody::DefinedAbsoluteKind:
return cast<DefinedAbsolute<ELFT>>(S).Sym.st_value;
@@ -1320,7 +1320,7 @@ void SymbolTableSection<ELFT>::writeLoca
template <class ELFT>
static const typename llvm::object::ELFFile<ELFT>::Elf_Sym *
getElfSym(SymbolBody &Body) {
- if (auto *EBody = dyn_cast<Defined<ELFT>>(&Body))
+ if (auto *EBody = dyn_cast<DefinedElf<ELFT>>(&Body))
return &EBody->Sym;
if (auto *EBody = dyn_cast<UndefinedElf<ELFT>>(&Body))
return &EBody->Sym;
@@ -1392,6 +1392,8 @@ uint8_t SymbolTableSection<ELFT>::getSym
return STB_LOCAL;
if (const Elf_Sym *ESym = getElfSym<ELFT>(*Body))
return ESym->getBinding();
+ if (isa<DefinedSynthetic<ELFT>>(Body))
+ return STB_LOCAL;
return Body->isWeak() ? STB_WEAK : STB_GLOBAL;
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Dec 23 18:47:42 2015
@@ -102,11 +102,7 @@ template <class ELFT>
void SymbolTable<ELFT>::addSynthetic(StringRef Name,
OutputSectionBase<ELFT> &Section,
typename ELFFile<ELFT>::uintX_t Value) {
- typedef typename DefinedSynthetic<ELFT>::Elf_Sym Elf_Sym;
- auto *ESym = new (Alloc) Elf_Sym;
- memset(ESym, 0, sizeof(Elf_Sym));
- ESym->st_value = Value;
- auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, *ESym, Section);
+ auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Value, Section);
resolve(Sym);
}
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Dec 23 18:47:42 2015
@@ -73,6 +73,10 @@ template <class ELFT> int SymbolBody::co
return 0;
}
+Defined::Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
+ bool IsTls)
+ : SymbolBody(K, Name, IsWeak, Visibility, IsTls) {}
+
Undefined::Undefined(SymbolBody::Kind K, StringRef N, bool IsWeak,
uint8_t Visibility, bool IsTls)
: SymbolBody(K, N, IsWeak, Visibility, IsTls), CanKeepUndefined(false) {}
@@ -91,6 +95,12 @@ UndefinedElf<ELFT>::UndefinedElf(StringR
Sym.getType() == llvm::ELF::STT_TLS),
Sym(Sym) {}
+template <typename ELFT>
+DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
+ OutputSectionBase<ELFT> &Section)
+ : Defined(SymbolBody::DefinedSyntheticKind, N, false, STV_DEFAULT, false),
+ Value(Value), Section(Section) {}
+
std::unique_ptr<InputFile> Lazy::getMember() {
MemoryBufferRef MBRef = File->getMember(&Sym);
@@ -124,3 +134,8 @@ template class lld::elf2::UndefinedElf<E
template class lld::elf2::UndefinedElf<ELF32BE>;
template class lld::elf2::UndefinedElf<ELF64LE>;
template class lld::elf2::UndefinedElf<ELF64BE>;
+
+template class lld::elf2::DefinedSynthetic<ELF32LE>;
+template class lld::elf2::DefinedSynthetic<ELF32BE>;
+template class lld::elf2::DefinedSynthetic<ELF64LE>;
+template class lld::elf2::DefinedSynthetic<ELF64BE>;
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Dec 23 18:47:42 2015
@@ -59,9 +59,10 @@ public:
DefinedRegularKind = DefinedFirst,
DefinedAbsoluteKind,
DefinedCommonKind,
- DefinedSyntheticKind,
SharedKind,
- DefinedLast = SharedKind,
+ DefinedElfLast = SharedKind,
+ DefinedSyntheticKind,
+ DefinedLast = DefinedSyntheticKind,
UndefinedElfKind,
UndefinedKind,
LazyKind
@@ -131,21 +132,30 @@ protected:
};
// The base class for any defined symbols, including absolute symbols, etc.
-template <class ELFT> class Defined : public SymbolBody {
+class Defined : public SymbolBody {
+public:
+ Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility, bool IsTls);
+ 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 llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
public:
- Defined(Kind K, StringRef N, const Elf_Sym &Sym)
- : SymbolBody(K, N, Sym.getBinding() == llvm::ELF::STB_WEAK,
- Sym.getVisibility(), Sym.getType() == llvm::ELF::STT_TLS),
+ DefinedElf(Kind K, StringRef N, const Elf_Sym &Sym)
+ : Defined(K, N, Sym.getBinding() == llvm::ELF::STB_WEAK,
+ Sym.getVisibility(), Sym.getType() == llvm::ELF::STT_TLS),
Sym(Sym) {}
const Elf_Sym &Sym;
- static bool classof(const SymbolBody *S) { return S->isDefined(); }
+ static bool classof(const SymbolBody *S) {
+ return S->kind() <= DefinedElfLast;
+ }
};
-template <class ELFT> class DefinedAbsolute : public Defined<ELFT> {
+template <class ELFT> class DefinedAbsolute : public DefinedElf<ELFT> {
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
public:
@@ -167,7 +177,7 @@ public:
static Elf_Sym RelaIpltEnd;
DefinedAbsolute(StringRef N, const Elf_Sym &Sym)
- : Defined<ELFT>(SymbolBody::DefinedAbsoluteKind, N, Sym) {}
+ : DefinedElf<ELFT>(SymbolBody::DefinedAbsoluteKind, N, Sym) {}
static bool classof(const SymbolBody *S) {
return S->kind() == SymbolBody::DefinedAbsoluteKind;
@@ -189,13 +199,13 @@ typename DefinedAbsolute<ELFT>::Elf_Sym
template <class ELFT>
typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::RelaIpltEnd;
-template <class ELFT> class DefinedCommon : public Defined<ELFT> {
+template <class ELFT> class DefinedCommon : public DefinedElf<ELFT> {
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
public:
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
DefinedCommon(StringRef N, const Elf_Sym &Sym)
- : Defined<ELFT>(SymbolBody::DefinedCommonKind, N, Sym) {
+ : DefinedElf<ELFT>(SymbolBody::DefinedCommonKind, N, Sym) {
MaxAlignment = Sym.st_value;
}
@@ -212,13 +222,13 @@ public:
};
// Regular defined symbols read from object file symbol tables.
-template <class ELFT> class DefinedRegular : public Defined<ELFT> {
+template <class ELFT> class DefinedRegular : public DefinedElf<ELFT> {
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
public:
DefinedRegular(StringRef N, const Elf_Sym &Sym,
InputSectionBase<ELFT> &Section)
- : Defined<ELFT>(SymbolBody::DefinedRegularKind, N, Sym),
+ : DefinedElf<ELFT>(SymbolBody::DefinedRegularKind, N, Sym),
Section(Section) {}
static bool classof(const SymbolBody *S) {
@@ -232,18 +242,18 @@ public:
// The difference from the regular symbol is that DefinedSynthetic symbols
// don't belong to any input files or sections. Thus, its constructor
// takes an output section to calculate output VA, etc.
-template <class ELFT> class DefinedSynthetic : public Defined<ELFT> {
+template <class ELFT> class DefinedSynthetic : public Defined {
public:
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
- DefinedSynthetic(StringRef N, const Elf_Sym &Sym,
- OutputSectionBase<ELFT> &Section)
- : Defined<ELFT>(SymbolBody::DefinedSyntheticKind, N, Sym),
- Section(Section) {}
+ typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
+ DefinedSynthetic(StringRef N, uintX_t Value,
+ OutputSectionBase<ELFT> &Section);
static bool classof(const SymbolBody *S) {
return S->kind() == SymbolBody::DefinedSyntheticKind;
}
+ uintX_t Value;
const OutputSectionBase<ELFT> &Section;
};
@@ -276,7 +286,7 @@ public:
}
};
-template <class ELFT> class SharedSymbol : public Defined<ELFT> {
+template <class ELFT> class SharedSymbol : public DefinedElf<ELFT> {
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
@@ -286,7 +296,7 @@ public:
}
SharedSymbol(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym)
- : Defined<ELFT>(SymbolBody::SharedKind, Name, Sym), File(F) {}
+ : DefinedElf<ELFT>(SymbolBody::SharedKind, Name, Sym), File(F) {}
SharedFile<ELFT> *File;
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=256354&r1=256353&r2=256354&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Dec 23 18:47:42 2015
@@ -71,7 +71,7 @@ template <unsigned N> static void checkA
}
template <class ELFT> bool isGnuIFunc(const SymbolBody &S) {
- if (auto *SS = dyn_cast<Defined<ELFT>>(&S))
+ if (auto *SS = dyn_cast<DefinedElf<ELFT>>(&S))
return SS->Sym.getType() == STT_GNU_IFUNC;
return false;
}
More information about the llvm-commits
mailing list