Move getRelocTarget to ObjectFile.

It doesn't use anything from the InputSection.

llvm-svn: 267154
This commit is contained in:
Rafael Espindola 2016-04-22 14:17:14 +00:00
parent bfd695d591
commit ea4d177977
6 changed files with 29 additions and 29 deletions

View File

@ -251,6 +251,24 @@ elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Shdr &Sec) {
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) {

View File

@ -104,6 +104,8 @@ template <class ELFT> class ObjectFile : public ELFFileBase<ELFT> {
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();

View File

@ -77,25 +77,6 @@ InputSectionBase<ELFT>::getOffset(const DefinedRegular<ELFT> &Sym) {
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)

View File

@ -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;
};

View File

@ -46,14 +46,15 @@ static void forEachSuccessor(InputSection<ELFT> *Sec,
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));
}
}
}

View File

@ -1132,7 +1132,7 @@ void EHOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *S,
} 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);