forked from OSchip/llvm-project
Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection. llvm-svn: 267154
This commit is contained in:
parent
bfd695d591
commit
ea4d177977
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue