[lld] r267154 - Move getRelocTarget to ObjectFile.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 07:17:15 PDT 2016
Author: rafael
Date: Fri Apr 22 09:17:14 2016
New Revision: 267154
URL: http://llvm.org/viewvc/llvm-project?rev=267154&view=rev
Log:
Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection.
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Apr 22 09:17:14 2016
@@ -251,6 +251,24 @@ elf::ObjectFile<ELFT>::getRelocTarget(co
return Target;
}
+// Returns a section that Rel relocation is pointing to.
+template <class ELFT>
+InputSectionBase<ELFT> *
+elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Rel &Rel) const {
+ uint32_t SymIndex = Rel.getSymbol(Config->Mips64EL);
+ SymbolBody &B = getSymbolBody(SymIndex).repl();
+ if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B))
+ if (D->Section)
+ return D->Section->Repl;
+ return nullptr;
+}
+
+template <class ELFT>
+InputSectionBase<ELFT> *
+elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Rela &Rel) const {
+ return getRelocTarget(reinterpret_cast<const Elf_Rel &>(Rel));
+}
+
template <class ELFT>
InputSectionBase<ELFT> *
elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Fri Apr 22 09:17:14 2016
@@ -104,6 +104,8 @@ template <class ELFT> class ObjectFile :
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<Elf_Word> getShtGroupEntries(const Elf_Shdr &Sec);
@@ -138,6 +140,10 @@ public:
// st_name of the symbol.
std::vector<std::pair<const DefinedRegular<ELFT> *, unsigned>> KeptLocalSyms;
+ // Returns a section that Rel is pointing to. Used by the garbage collector.
+ InputSectionBase<ELFT> *getRelocTarget(const Elf_Rel &Rel) const;
+ InputSectionBase<ELFT> *getRelocTarget(const Elf_Rela &Rel) const;
+
private:
void initializeSections(llvm::DenseSet<StringRef> &ComdatGroups);
void initializeSymbols();
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Apr 22 09:17:14 2016
@@ -77,25 +77,6 @@ InputSectionBase<ELFT>::getOffset(const
return getOffset(Sym.Value);
}
-// Returns a section that Rel relocation is pointing to.
-template <class ELFT>
-InputSectionBase<ELFT> *
-InputSectionBase<ELFT>::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<DefinedRegular<ELFT>>(&B))
- if (D->Section)
- return D->Section->Repl;
- return nullptr;
-}
-
-template <class ELFT>
-InputSectionBase<ELFT> *
-InputSectionBase<ELFT>::getRelocTarget(const Elf_Rela &Rel) const {
- return getRelocTarget(reinterpret_cast<const Elf_Rel &>(Rel));
-}
-
template <class ELFT>
InputSection<ELFT>::InputSection(elf::ObjectFile<ELFT> *F,
const Elf_Shdr *Header)
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Fri Apr 22 09:17:14 2016
@@ -76,8 +76,6 @@ struct Relocation {
// This corresponds to a section of an input file.
template <class ELFT> 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<uint8_t> getSectionData() const;
- // Returns a section that Rel is pointing to. Used by the garbage collector.
- InputSectionBase<ELFT> *getRelocTarget(const Elf_Rel &Rel) const;
- InputSectionBase<ELFT> *getRelocTarget(const Elf_Rela &Rel) const;
-
void relocate(uint8_t *Buf, uint8_t *BufEnd);
std::vector<Relocation> Relocations;
};
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Fri Apr 22 09:17:14 2016
@@ -46,14 +46,15 @@ static void forEachSuccessor(InputSectio
typedef typename ELFT::Rela Elf_Rela;
typedef typename ELFT::Shdr Elf_Shdr;
- ELFFile<ELFT> &Obj = Sec->getFile()->getObj();
+ ObjectFile<ELFT> *File = Sec->getFile();
+ ELFFile<ELFT> &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));
}
}
}
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=267154&r1=267153&r2=267154&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Apr 22 09:17:14 2016
@@ -1132,7 +1132,7 @@ void EHOutputSection<ELFT>::addSectionAu
} else {
if (!HasReloc)
fatal("FDE doesn't reference another section");
- InputSectionBase<ELFT> *Target = S->getRelocTarget(*RelI);
+ InputSectionBase<ELFT> *Target = S->getFile()->getRelocTarget(*RelI);
if (Target && Target->Live) {
uint32_t CieOffset = Offset + 4 - ID;
auto I = OffsetToIndex.find(CieOffset);
More information about the llvm-commits
mailing list