diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index bccbddf50585..cc101ab8b5e5 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -251,6 +251,24 @@ elf::ObjectFile::getRelocTarget(const Elf_Shdr &Sec) { return Target; } +// Returns a section that Rel relocation is pointing to. +template +InputSectionBase * +elf::ObjectFile::getRelocTarget(const Elf_Rel &Rel) const { + uint32_t SymIndex = Rel.getSymbol(Config->Mips64EL); + SymbolBody &B = getSymbolBody(SymIndex).repl(); + if (auto *D = dyn_cast>(&B)) + if (D->Section) + return D->Section->Repl; + return nullptr; +} + +template +InputSectionBase * +elf::ObjectFile::getRelocTarget(const Elf_Rela &Rel) const { + return getRelocTarget(reinterpret_cast(Rel)); +} + template InputSectionBase * elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index ca41d16392bd..0a0e06b59e4d 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -104,6 +104,8 @@ template class ObjectFile : public ELFFileBase { typedef typename ELFT::SymRange Elf_Sym_Range; typedef typename ELFT::Word Elf_Word; typedef typename ELFT::uint uintX_t; + typedef typename ELFT::Rel Elf_Rel; + typedef typename ELFT::Rela Elf_Rela; StringRef getShtGroupSignature(const Elf_Shdr &Sec); ArrayRef getShtGroupEntries(const Elf_Shdr &Sec); @@ -138,6 +140,10 @@ public: // st_name of the symbol. std::vector *, unsigned>> KeptLocalSyms; + // Returns a section that Rel is pointing to. Used by the garbage collector. + InputSectionBase *getRelocTarget(const Elf_Rel &Rel) const; + InputSectionBase *getRelocTarget(const Elf_Rela &Rel) const; + private: void initializeSections(llvm::DenseSet &ComdatGroups); void initializeSymbols(); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 6b4b8033bb6d..37d5cb42ba7b 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -77,25 +77,6 @@ InputSectionBase::getOffset(const DefinedRegular &Sym) { return getOffset(Sym.Value); } -// Returns a section that Rel relocation is pointing to. -template -InputSectionBase * -InputSectionBase::getRelocTarget(const Elf_Rel &Rel) const { - // Global symbol - uint32_t SymIndex = Rel.getSymbol(Config->Mips64EL); - SymbolBody &B = File->getSymbolBody(SymIndex).repl(); - if (auto *D = dyn_cast>(&B)) - if (D->Section) - return D->Section->Repl; - return nullptr; -} - -template -InputSectionBase * -InputSectionBase::getRelocTarget(const Elf_Rela &Rel) const { - return getRelocTarget(reinterpret_cast(Rel)); -} - template InputSection::InputSection(elf::ObjectFile *F, const Elf_Shdr *Header) diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index d182e0ae0658..cc853048da6b 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -76,8 +76,6 @@ struct Relocation { // This corresponds to a section of an input file. template class InputSectionBase { protected: - 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; @@ -123,10 +121,6 @@ public: ArrayRef getSectionData() const; - // Returns a section that Rel is pointing to. Used by the garbage collector. - InputSectionBase *getRelocTarget(const Elf_Rel &Rel) const; - InputSectionBase *getRelocTarget(const Elf_Rela &Rel) const; - void relocate(uint8_t *Buf, uint8_t *BufEnd); std::vector Relocations; }; diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 2511fc14ae4c..4c8e3594e5a7 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -46,14 +46,15 @@ static void forEachSuccessor(InputSection *Sec, typedef typename ELFT::Rela Elf_Rela; typedef typename ELFT::Shdr Elf_Shdr; - ELFFile &Obj = Sec->getFile()->getObj(); + ObjectFile *File = Sec->getFile(); + ELFFile &Obj = File->getObj(); for (const Elf_Shdr *RelSec : Sec->RelocSections) { if (RelSec->sh_type == SHT_RELA) { for (const Elf_Rela &RI : Obj.relas(RelSec)) - Fn(Sec->getRelocTarget(RI)); + Fn(File->getRelocTarget(RI)); } else { for (const Elf_Rel &RI : Obj.rels(RelSec)) - Fn(Sec->getRelocTarget(RI)); + Fn(File->getRelocTarget(RI)); } } } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 9052aec88f82..2f3707605d18 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -1132,7 +1132,7 @@ void EHOutputSection::addSectionAux(EHInputSection *S, } else { if (!HasReloc) fatal("FDE doesn't reference another section"); - InputSectionBase *Target = S->getRelocTarget(*RelI); + InputSectionBase *Target = S->getFile()->getRelocTarget(*RelI); if (Target && Target->Live) { uint32_t CieOffset = Offset + 4 - ID; auto I = OffsetToIndex.find(CieOffset);