diff options
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Symbols.cpp | 34 | ||||
-rw-r--r-- | lld/ELF/Symbols.h | 1 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 32 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.h | 2 |
5 files changed, 37 insertions, 34 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 04df93b1100..7e1185aeb66 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -983,7 +983,7 @@ template <class ELFT> bool LinkerScript<ELFT>::isAbsolute(StringRef S) { template <class ELFT> const OutputSection *LinkerScript<ELFT>::getSymbolSection(StringRef S) { if (SymbolBody *Sym = Symtab<ELFT>::X->find(S)) - return SymbolTableSection<ELFT>::getOutputSection(Sym); + return Sym->getOutputSection<ELFT>(); return CurOutSec; } diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 3ffb50744c5..7707d3d583c 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -172,6 +172,31 @@ template <class ELFT> typename ELFT::uint SymbolBody::getSize() const { return 0; } +template <class ELFT> +const OutputSection *SymbolBody::getOutputSection() const { + if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this)) { + if (S->Section) + return S->Section->template getOutputSection<ELFT>(); + return nullptr; + } + + if (auto *S = dyn_cast<SharedSymbol>(this)) { + if (S->NeedsCopy) + return S->Section->OutSec; + return nullptr; + } + + if (isa<DefinedCommon>(this)) { + if (Config->DefineCommon) + return In<ELFT>::Common->OutSec; + return nullptr; + } + + if (auto *S = dyn_cast<DefinedSynthetic>(this)) + return S->Section; + return nullptr; +} + // If a symbol name contains '@', the characters after that is // a symbol version name. This function parses that. void SymbolBody::parseSymbolVersion() { @@ -359,6 +384,15 @@ 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 OutputSection * + SymbolBody::template getOutputSection<ELF32LE>() const; +template const OutputSection * + SymbolBody::template getOutputSection<ELF32BE>() const; +template const OutputSection * + SymbolBody::template getOutputSection<ELF64LE>() const; +template const OutputSection * + SymbolBody::template getOutputSection<ELF64BE>() const; + template class elf::DefinedRegular<ELF32LE>; template class elf::DefinedRegular<ELF32BE>; template class elf::DefinedRegular<ELF64LE>; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index e63b4531f8b..4a684e7e2a0 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -84,6 +84,7 @@ public: template <class ELFT> typename ELFT::uint getGotPltVA() const; template <class ELFT> typename ELFT::uint getPltVA() const; template <class ELFT> typename ELFT::uint getSize() const; + template <class ELFT> const OutputSection *getOutputSection() const; // The file from which this symbol was created. InputFile *File = nullptr; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 095a538d8bf..4e6b3c92a73 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1387,7 +1387,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { ESym->st_size = Body->getSize<ELFT>(); ESym->st_value = Body->getVA<ELFT>(); - if (const OutputSection *OutSec = getOutputSection(Body)) { + if (const OutputSection *OutSec = Body->getOutputSection<ELFT>()) { ESym->st_shndx = OutSec->SectionIndex; // This piece of code should go away as it doesn't make sense, @@ -1428,36 +1428,6 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) { } template <class ELFT> -const OutputSection * -SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) { - switch (Sym->kind()) { - case SymbolBody::DefinedSyntheticKind: - return cast<DefinedSynthetic>(Sym)->Section; - case SymbolBody::DefinedRegularKind: { - auto &D = cast<DefinedRegular<ELFT>>(*Sym); - if (D.Section) - return D.Section->template getOutputSection<ELFT>(); - break; - } - case SymbolBody::DefinedCommonKind: - if (!Config->DefineCommon) - return nullptr; - return In<ELFT>::Common->OutSec; - case SymbolBody::SharedKind: { - auto &SS = cast<SharedSymbol>(*Sym); - if (SS.NeedsCopy) - return SS.Section->OutSec; - break; - } - case SymbolBody::UndefinedKind: - case SymbolBody::LazyArchiveKind: - case SymbolBody::LazyObjectKind: - break; - } - return nullptr; -} - -template <class ELFT> GnuHashTableSection<ELFT>::GnuHashTableSection() : SyntheticSection(SHF_ALLOC, SHT_GNU_HASH, sizeof(uintX_t), ".gnu.hash") { this->Entsize = ELFT::Is64Bits ? 0 : 4; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 68d5227fca2..662c241cabc 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -424,8 +424,6 @@ public: ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; } - static const OutputSection *getOutputSection(SymbolBody *Sym); - private: // A vector of symbols and their string table offsets. std::vector<SymbolTableEntry> Symbols; |