From 9328b2cdde0134f5261a41be25e41c1f58c8cd41 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 14 Mar 2016 23:16:09 +0000 Subject: [PATCH] Use ELFT instead of ELFFile. llvm-svn: 263510 --- lld/ELF/ICF.cpp | 6 ++-- lld/ELF/InputFiles.cpp | 14 ++++---- lld/ELF/InputFiles.h | 26 +++++++------- lld/ELF/InputSection.cpp | 17 ++++------ lld/ELF/InputSection.h | 36 ++++++++++---------- lld/ELF/MarkLive.cpp | 6 ++-- lld/ELF/OutputSections.cpp | 12 +++---- lld/ELF/OutputSections.h | 84 ++++++++++++++++++++++------------------------ lld/ELF/SymbolTable.h | 4 +-- lld/ELF/Symbols.cpp | 28 ++++++---------- lld/ELF/Symbols.h | 47 ++++++++++++-------------- lld/ELF/Target.cpp | 6 ++-- lld/ELF/Target.h | 3 +- lld/ELF/Writer.cpp | 27 +++++++-------- 14 files changed, 146 insertions(+), 170 deletions(-) diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 7fad3df..a16b647 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -74,9 +74,9 @@ using namespace llvm::object; namespace lld { namespace elf { template class ICF { - typedef typename ELFFile::Elf_Shdr Elf_Shdr; - typedef typename ELFFile::Elf_Sym Elf_Sym; - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; typedef Elf_Rel_Impl Elf_Rel; using Comparator = std::function *, diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 8e07ffd..3622dc2 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -45,8 +45,7 @@ ELFKind ELFFileBase::getELFKind() { } template -typename ELFFileBase::Elf_Sym_Range -ELFFileBase::getElfSymbols(bool OnlyGlobals) { +typename ELFT::SymRange ELFFileBase::getElfSymbols(bool OnlyGlobals) { if (!Symtab) return Elf_Sym_Range(nullptr, nullptr); Elf_Sym_Range Syms = ELFObj.symbols(Symtab); @@ -141,9 +140,8 @@ elf::ObjectFile::getShtGroupEntries(const Elf_Shdr &Sec) { return Entries.slice(1); } -template -static bool shouldMerge(const typename ELFFile::Elf_Shdr &Sec) { - typedef typename ELFFile::uintX_t uintX_t; +template static bool shouldMerge(const typename ELFT::Shdr &Sec) { + typedef typename ELFT::uint uintX_t; uintX_t Flags = Sec.sh_flags; if (!(Flags & SHF_MERGE)) return false; @@ -370,7 +368,7 @@ SharedFile::SharedFile(MemoryBufferRef M) : ELFFileBase(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {} template -const typename ELFFile::Elf_Shdr * +const typename ELFT::Shdr * SharedFile::getSection(const Elf_Sym &Sym) const { uint32_t Index = this->getSectionIndex(Sym); if (Index == 0) @@ -381,8 +379,8 @@ SharedFile::getSection(const Elf_Sym &Sym) const { // Partially parse the shared object file so that we can call // getSoName on this object. template void SharedFile::parseSoName() { - typedef typename ELFFile::Elf_Dyn Elf_Dyn; - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::Dyn Elf_Dyn; + typedef typename ELFT::uint uintX_t; const Elf_Shdr *DynamicSec = nullptr; const ELFFile Obj = this->ELFObj; diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 46c35b1..5f7356b 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -56,10 +56,10 @@ private: template class ELFFileBase : public InputFile { public: - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; - typedef typename llvm::object::ELFFile::Elf_Sym_Range Elf_Sym_Range; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::Word Elf_Word; + typedef typename ELFT::SymRange Elf_Sym_Range; ELFFileBase(Kind K, MemoryBufferRef M); static bool classof(const InputFile *F) { @@ -92,11 +92,11 @@ protected: // .o file. template class ObjectFile : public ELFFileBase { typedef ELFFileBase Base; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym_Range Elf_Sym_Range; - typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::SymRange Elf_Sym_Range; + typedef typename ELFT::Word Elf_Word; + typedef typename ELFT::uint uintX_t; StringRef getShtGroupSignature(const Elf_Shdr &Sec); ArrayRef getShtGroupEntries(const Elf_Shdr &Sec); @@ -193,10 +193,10 @@ private: // .so file. template class SharedFile : public ELFFileBase { typedef ELFFileBase Base; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; - typedef typename llvm::object::ELFFile::Elf_Sym_Range Elf_Sym_Range; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::Word Elf_Word; + typedef typename ELFT::SymRange Elf_Sym_Range; std::vector> SymbolBodies; std::vector Undefs; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 667072f..79f5abb 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -48,8 +48,7 @@ ArrayRef InputSectionBase::getSectionData() const { } template -typename ELFFile::uintX_t -InputSectionBase::getOffset(uintX_t Offset) { +typename ELFT::uint InputSectionBase::getOffset(uintX_t Offset) { switch (SectionKind) { case Regular: return cast>(this)->OutSecOff + Offset; @@ -66,8 +65,7 @@ InputSectionBase::getOffset(uintX_t Offset) { } template -typename ELFFile::uintX_t -InputSectionBase::getOffset(const Elf_Sym &Sym) { +typename ELFT::uint InputSectionBase::getOffset(const Elf_Sym &Sym) { return getOffset(Sym.st_value); } @@ -362,8 +360,7 @@ bool EHInputSection::classof(const InputSectionBase *S) { } template -typename EHInputSection::uintX_t -EHInputSection::getOffset(uintX_t Offset) { +typename ELFT::uint EHInputSection::getOffset(uintX_t Offset) { // The file crtbeginT.o has relocations pointing to the start of an empty // .eh_frame that is known to be the first in the link. It does that to // identify the start of the output .eh_frame. Handle this special case. @@ -389,9 +386,8 @@ bool MergeInputSection::classof(const InputSectionBase *S) { } template -std::pair::uintX_t, - typename ELFFile::uintX_t> *, - typename ELFFile::uintX_t> +std::pair *, + typename ELFT::uint> SplitInputSection::getRangeAndSize(uintX_t Offset) { ArrayRef D = this->getSectionData(); StringRef Data((const char *)D.data(), D.size()); @@ -411,8 +407,7 @@ SplitInputSection::getRangeAndSize(uintX_t Offset) { } template -typename MergeInputSection::uintX_t -MergeInputSection::getOffset(uintX_t Offset) { +typename ELFT::uint MergeInputSection::getOffset(uintX_t Offset) { std::pair *, uintX_t> T = this->getRangeAndSize(Offset); std::pair *I = T.first; diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 3549bd5..0b6117e 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -26,11 +26,11 @@ template class OutputSectionBase; // This corresponds to a section of an input file. template class InputSectionBase { protected: - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; const Elf_Shdr *Header; // The file this section is from. @@ -94,8 +94,8 @@ InputSectionBase * // and each piece is copied to a different place in the output. // This class represents such special sections. template class SplitInputSection : public InputSectionBase { - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::uint uintX_t; public: SplitInputSection(ObjectFile *File, const Elf_Shdr *Header, @@ -111,9 +111,9 @@ public: // This corresponds to a SHF_MERGE section of an input file. template class MergeInputSection : public SplitInputSection { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; + typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::Shdr Elf_Shdr; public: MergeInputSection(ObjectFile *F, const Elf_Shdr *Header); @@ -126,8 +126,8 @@ public: // This corresponds to a .eh_frame section of an input file. template class EHInputSection : public SplitInputSection { public: - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::uint uintX_t; EHInputSection(ObjectFile *F, const Elf_Shdr *Header); static bool classof(const InputSectionBase *S); @@ -143,11 +143,11 @@ public: template class InputSection : public InputSectionBase { friend ICF; typedef InputSectionBase Base; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; public: InputSection(ObjectFile *F, const Elf_Shdr *Header); @@ -186,7 +186,7 @@ private: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf template class MipsReginfoInputSection : public InputSectionBase { - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; + typedef typename ELFT::Shdr Elf_Shdr; public: MipsReginfoInputSection(ObjectFile *F, const Elf_Shdr *Hdr); diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 0afb707..ecb6ac9 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -42,9 +42,9 @@ using namespace lld::elf; template static void forEachSuccessor(InputSection *Sec, std::function *)> Fn) { - typedef typename ELFFile::Elf_Rel Elf_Rel; - typedef typename ELFFile::Elf_Rela Elf_Rela; - typedef typename ELFFile::Elf_Shdr Elf_Shdr; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::Shdr Elf_Shdr; ELFFile &Obj = Sec->getFile()->getObj(); for (const Elf_Shdr *RelSec : Sec->RelocSections) { diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 9a15ad1..97cf56f 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -244,7 +244,7 @@ void RelocationSection::addReloc(const DynamicReloc &Reloc) { } template -typename ELFFile::uintX_t DynamicReloc::getOffset() const { +typename ELFT::uint DynamicReloc::getOffset() const { switch (OKind) { case Off_GTlsIndex: return Out::Got->getGlobalDynAddr(*Sym); @@ -1027,7 +1027,7 @@ uint8_t EHOutputSection::getFdeEncoding(ArrayRef D) { } template -static typename ELFFile::uintX_t readEntryLength(ArrayRef D) { +static typename ELFT::uint readEntryLength(ArrayRef D) { const endianness E = ELFT::TargetEndianness; if (D.size() < 4) fatal("CIE/FDE too small"); @@ -1140,9 +1140,8 @@ void EHOutputSection::addSection(InputSectionBase *C) { } template -static typename ELFFile::uintX_t writeAlignedCieOrFde(StringRef Data, - uint8_t *Buf) { - typedef typename ELFFile::uintX_t uintX_t; +static typename ELFT::uint writeAlignedCieOrFde(StringRef Data, uint8_t *Buf) { + typedef typename ELFT::uint uintX_t; const endianness E = ELFT::TargetEndianness; uint64_t Len = alignTo(Data.size(), sizeof(uintX_t)); write32(Buf, Len - 4); @@ -1401,8 +1400,7 @@ void SymbolTableSection::writeLocalSymbols(uint8_t *&Buf) { } template -static const typename llvm::object::ELFFile::Elf_Sym * -getElfSym(SymbolBody &Body) { +static const typename ELFT::Sym *getElfSym(SymbolBody &Body) { if (auto *EBody = dyn_cast>(&Body)) return &EBody->Sym; if (auto *EBody = dyn_cast>(&Body)) diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 5004c25..13259bd 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -33,14 +33,12 @@ template class ObjectFile; template class DefinedRegular; template -static inline typename llvm::object::ELFFile::uintX_t -getAddend(const typename llvm::object::ELFFile::Elf_Rel &Rel) { +static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) { return 0; } template -static inline typename llvm::object::ELFFile::uintX_t -getAddend(const typename llvm::object::ELFFile::Elf_Rela &Rel) { +static inline typename ELFT::uint getAddend(const typename ELFT::Rela &Rel) { return Rel.r_addend; } @@ -53,8 +51,8 @@ bool isValidCIdentifier(StringRef S); // non-overlapping file offsets and VAs. template class OutputSectionBase { public: - typedef typename llvm::object::ELFFile::uintX_t uintX_t; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; + typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags); void setVA(uintX_t VA) { Header.sh_addr = VA; } @@ -95,7 +93,7 @@ protected: template class GotSection final : public OutputSectionBase { typedef OutputSectionBase Base; - typedef typename Base::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; public: GotSection(); @@ -134,7 +132,7 @@ private: template class GotPltSection final : public OutputSectionBase { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; public: GotPltSection(); @@ -149,7 +147,7 @@ private: template class PltSection final : public OutputSectionBase { typedef OutputSectionBase Base; - typedef typename Base::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; public: PltSection(); @@ -163,7 +161,7 @@ private: }; template struct DynamicReloc { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; uint32_t Type; // Where the relocation is. @@ -201,10 +199,10 @@ template struct DynamicReloc { template class SymbolTableSection final : public OutputSectionBase { public: - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Sym_Range Elf_Sym_Range; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::SymRange Elf_Sym_Range; + typedef typename ELFT::uint uintX_t; SymbolTableSection(SymbolTable &Table, StringTableSection &StrTabSec); @@ -236,9 +234,9 @@ private: template class RelocationSection final : public OutputSectionBase { - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::uint uintX_t; public: RelocationSection(StringRef Name); @@ -257,11 +255,11 @@ private: template class OutputSection final : public OutputSectionBase { public: - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::uint uintX_t; OutputSection(StringRef Name, uint32_t Type, uintX_t Flags); void addSection(InputSectionBase *C) override; void sortInitFini(); @@ -276,7 +274,7 @@ private: template class MergeOutputSection final : public OutputSectionBase { - typedef typename OutputSectionBase::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; bool shouldTailMerge() const; @@ -294,7 +292,7 @@ private: // FDE or CIE template struct EHRegion { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; EHRegion(EHInputSection *S, unsigned Index); StringRef data() const; EHInputSection *S; @@ -310,10 +308,10 @@ template struct Cie : public EHRegion { template class EHOutputSection final : public OutputSectionBase { public: - typedef typename llvm::object::ELFFile::uintX_t uintX_t; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; + typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; EHOutputSection(StringRef Name, uint32_t Type, uintX_t Flags); void writeTo(uint8_t *Buf) override; @@ -343,7 +341,7 @@ public: template class StringTableSection final : public OutputSectionBase { public: - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; StringTableSection(StringRef Name, bool Dynamic); unsigned addString(StringRef S, bool HashIt = true); void writeTo(uint8_t *Buf) override; @@ -360,7 +358,7 @@ private: template class HashTableSection final : public OutputSectionBase { - typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; + typedef typename ELFT::Word Elf_Word; public: HashTableSection(); @@ -372,9 +370,9 @@ public: // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections template class GnuHashTableSection final : public OutputSectionBase { - typedef typename llvm::object::ELFFile::Elf_Off Elf_Off; - typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Off Elf_Off; + typedef typename ELFT::Word Elf_Word; + typedef typename ELFT::uint uintX_t; public: GnuHashTableSection(); @@ -409,12 +407,12 @@ private: template class DynamicSection final : public OutputSectionBase { typedef OutputSectionBase Base; - typedef typename llvm::object::ELFFile::Elf_Dyn Elf_Dyn; - typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; - typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Dyn Elf_Dyn; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; // The .dynamic section contains information for the dynamic linker. // The section consists of fixed size entries, which consist of @@ -477,7 +475,7 @@ private: // http://www.airs.com/blog/archives/462 (".eh_frame_hdr") template class EhFrameHeader final : public OutputSectionBase { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; public: EhFrameHeader(); @@ -519,8 +517,8 @@ private: // globally accessible. Writer initializes them, so don't use them // until Writer is initialized. template struct Out { - typedef typename llvm::object::ELFFile::uintX_t uintX_t; - typedef typename llvm::object::ELFFile::Elf_Phdr Elf_Phdr; + typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Phdr Elf_Phdr; static BuildIdSection *BuildId; static DynamicSection *Dynamic; static EhFrameHeader *EhFrameHdr; @@ -566,7 +564,7 @@ template StringTableSection *Out::ShStrTab; template StringTableSection *Out::StrTab; template SymbolTableSection *Out::DynSymTab; template SymbolTableSection *Out::SymTab; -template typename Out::Elf_Phdr *Out::TlsPhdr; +template typename ELFT::Phdr *Out::TlsPhdr; template OutputSectionBase *Out::ElfHeader; template OutputSectionBase *Out::ProgramHeaders; diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index a2a991a..08f3507 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -35,8 +35,8 @@ class Undefined; // undefined, it'll read an archive member to read a real definition // to replace the lazy symbol. The logic is implemented in resolve(). template class SymbolTable { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; public: void addFile(std::unique_ptr File); diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 78662ee..e32473e 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -29,10 +29,10 @@ using namespace lld; using namespace lld::elf; template -static typename ELFFile::uintX_t -getSymVA(const SymbolBody &Body, typename ELFFile::uintX_t &Addend) { - typedef typename ELFFile::Elf_Sym Elf_Sym; - typedef typename ELFFile::uintX_t uintX_t; +static typename ELFT::uint getSymVA(const SymbolBody &Body, + typename ELFT::uint &Addend) { + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; switch (Body.kind()) { case SymbolBody::DefinedSyntheticKind: { @@ -119,32 +119,26 @@ template bool SymbolBody::isGnuIfunc() const { } template -typename ELFFile::uintX_t -SymbolBody::getVA(typename ELFFile::uintX_t Addend) const { +typename ELFT::uint SymbolBody::getVA(typename ELFT::uint Addend) const { return getSymVA(*this, Addend) + Addend; } -template -typename ELFFile::uintX_t SymbolBody::getGotVA() const { +template typename ELFT::uint SymbolBody::getGotVA() const { return Out::Got->getVA() + (Out::Got->getMipsLocalEntriesNum() + GotIndex) * - sizeof(typename ELFFile::uintX_t); + sizeof(typename ELFT::uint); } -template -typename ELFFile::uintX_t SymbolBody::getGotPltVA() const { - return Out::GotPlt->getVA() + - GotPltIndex * sizeof(typename ELFFile::uintX_t); +template typename ELFT::uint SymbolBody::getGotPltVA() const { + return Out::GotPlt->getVA() + GotPltIndex * sizeof(typename ELFT::uint); } -template -typename ELFFile::uintX_t SymbolBody::getPltVA() const { +template typename ELFT::uint SymbolBody::getPltVA() const { return Out::Plt->getVA() + Target->PltZeroSize + PltIndex * Target->PltEntrySize; } -template -typename ELFFile::uintX_t SymbolBody::getSize() const { +template typename ELFT::uint SymbolBody::getSize() const { if (auto *B = dyn_cast>(this)) return B->Sym.st_size; return 0; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index b95d61e..6c869f6 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -91,16 +91,12 @@ public: bool isInPlt() const { return PltIndex != -1U; } template - typename llvm::object::ELFFile::uintX_t - getVA(typename llvm::object::ELFFile::uintX_t Addend = 0) const; - template - typename llvm::object::ELFFile::uintX_t getGotVA() const; - template - typename llvm::object::ELFFile::uintX_t getGotPltVA() const; - template - typename llvm::object::ELFFile::uintX_t getPltVA() const; - template - typename llvm::object::ELFFile::uintX_t getSize() const; + typename ELFT::uint getVA(typename ELFT::uint Addend = 0) const; + + template typename ELFT::uint getGotVA() const; + template typename ELFT::uint getGotPltVA() const; + template typename ELFT::uint getPltVA() const; + template typename ELFT::uint getSize() const; // A SymbolBody has a backreference to a Symbol. Originally they are // doubly-linked. A backreference will never change. But the pointer @@ -165,7 +161,7 @@ public: // Any defined symbol from an ELF file. template class DefinedElf : public Defined { protected: - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; + typedef typename ELFT::Sym Elf_Sym; public: DefinedElf(Kind K, StringRef N, const Elf_Sym &Sym) @@ -207,7 +203,7 @@ public: // Regular defined symbols read from object file symbol tables. template class DefinedRegular : public DefinedElf { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; + typedef typename ELFT::Sym Elf_Sym; public: DefinedRegular(StringRef N, const Elf_Sym &Sym, @@ -240,8 +236,8 @@ InputSectionBase *DefinedRegular::NullInputSection; // takes an output section to calculate output VA, etc. template class DefinedSynthetic : public Defined { public: - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; DefinedSynthetic(StringRef N, uintX_t Value, OutputSectionBase &Section, uint8_t Visibility); @@ -271,7 +267,7 @@ public: }; template class UndefinedElf : public Undefined { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; + typedef typename ELFT::Sym Elf_Sym; public: UndefinedElf(StringRef N, const Elf_Sym &Sym); @@ -283,8 +279,8 @@ public: }; template class SharedSymbol : public DefinedElf { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - typedef typename llvm::object::ELFFile::uintX_t uintX_t; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::uint uintX_t; public: static bool classof(const SymbolBody *S) { @@ -332,7 +328,7 @@ private: // DefinedRegular symbols, so they need Elf_Sym symbols. // Here we allocate such Elf_Sym symbols statically. template struct ElfSym { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; + typedef typename ELFT::Sym Elf_Sym; // Used to represent an undefined symbol which we don't want to add to the // output file's symbol table. It has weak binding and can be substituted. @@ -356,14 +352,13 @@ template struct ElfSym { static Elf_Sym RelaIpltEnd; }; -template typename ElfSym::Elf_Sym ElfSym::Ignored; -template typename ElfSym::Elf_Sym ElfSym::Etext; -template typename ElfSym::Elf_Sym ElfSym::Edata; -template typename ElfSym::Elf_Sym ElfSym::End; -template typename ElfSym::Elf_Sym ElfSym::MipsGp; -template -typename ElfSym::Elf_Sym ElfSym::RelaIpltStart; -template typename ElfSym::Elf_Sym ElfSym::RelaIpltEnd; +template typename ELFT::Sym ElfSym::Ignored; +template typename ELFT::Sym ElfSym::Etext; +template typename ELFT::Sym ElfSym::Edata; +template typename ELFT::Sym ElfSym::End; +template typename ELFT::Sym ElfSym::MipsGp; +template typename ELFT::Sym ElfSym::RelaIpltStart; +template typename ELFT::Sym ElfSym::RelaIpltEnd; } // namespace elf } // namespace lld diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index cd5ad87..c968cbe 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -1578,8 +1578,8 @@ uint32_t MipsTargetInfo::getDynRel(uint32_t Type) const { template void MipsTargetInfo::writeGotHeader(uint8_t *Buf) const { - typedef typename ELFFile::Elf_Off Elf_Off; - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::Off Elf_Off; + typedef typename ELFT::uint uintX_t; // Set the MSB of the second GOT slot. This is not required by any // MIPS ABI documentation, though. @@ -1793,7 +1793,7 @@ bool MipsTargetInfo::isRelRelative(uint32_t Type) const { // _gp is a MIPS-specific ABI-defined symbol which points to // a location that is relative to GOT. This function returns // the value for the symbol. -template typename ELFFile::uintX_t getMipsGpAddr() { +template typename ELFT::uint getMipsGpAddr() { unsigned GPOffset = 0x7ff0; if (uint64_t V = Out::Got->getVA()) return V + GPOffset; diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 1c706ea..49f1ea4 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -104,8 +104,7 @@ private: uint64_t getPPC64TocBase(); -template -typename llvm::object::ELFFile::uintX_t getMipsGpAddr(); +template typename ELFT::uint getMipsGpAddr(); extern TargetInfo *Target; TargetInfo *createTarget(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f0e16be..a8b1f9bb 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -32,13 +32,13 @@ namespace { // The writer writes a SymbolTable result to a file. template class Writer { public: - typedef typename ELFFile::uintX_t uintX_t; - typedef typename ELFFile::Elf_Shdr Elf_Shdr; - typedef typename ELFFile::Elf_Ehdr Elf_Ehdr; - typedef typename ELFFile::Elf_Phdr Elf_Phdr; - typedef typename ELFFile::Elf_Sym Elf_Sym; - typedef typename ELFFile::Elf_Sym_Range Elf_Sym_Range; - typedef typename ELFFile::Elf_Rela Elf_Rela; + typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::Ehdr Elf_Ehdr; + typedef typename ELFT::Phdr Elf_Phdr; + typedef typename ELFT::Sym Elf_Sym; + typedef typename ELFT::SymRange Elf_Sym_Range; + typedef typename ELFT::Rela Elf_Rela; Writer(SymbolTable &S) : Symtab(S) {} void run(); @@ -123,7 +123,7 @@ private: } // anonymous namespace template void elf::writeResult(SymbolTable *Symtab) { - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; // Create singleton output sections. DynamicSection Dynamic(*Symtab); @@ -515,7 +515,7 @@ static void reportUndefined(SymbolTable &Symtab, SymbolBody *Sym) { template static bool shouldKeepInSymtab(const elf::ObjectFile &File, StringRef SymName, - const typename ELFFile::Elf_Sym &Sym) { + const typename ELFT::Sym &Sym) { if (Sym.getType() == STT_FILE) return false; @@ -610,7 +610,7 @@ template static bool isRelroSection(OutputSectionBase *Sec) { template static bool compareSections(OutputSectionBase *A, OutputSectionBase *B) { - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::uint uintX_t; int Comp = Script->compareSections(A->getName(), B->getName()); if (Comp != 0) @@ -825,8 +825,8 @@ static bool includeInDynsym(const SymbolBody &B) { // linker scripts. namespace { template class OutputSectionFactory { - typedef typename ELFFile::Elf_Shdr Elf_Shdr; - typedef typename ELFFile::uintX_t uintX_t; + typedef typename ELFT::Shdr Elf_Shdr; + typedef typename ELFT::uint uintX_t; public: std::pair *, bool> create(InputSectionBase *C, @@ -1424,8 +1424,7 @@ static uint32_t getMipsEFlags() { return V; } -template -static typename ELFFile::uintX_t getEntryAddr() { +template static typename ELFT::uint getEntryAddr() { if (SymbolBody *B = Config->EntrySym) return B->repl().getVA(); if (Config->EntryAddr != uint64_t(-1)) -- 2.7.4