Expose getRel and getRela to reduce code duplication.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241266 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-07-02 14:21:38 +00:00
parent 016970f468
commit ab6b4cfe2a
2 changed files with 13 additions and 22 deletions

View File

@ -247,9 +247,6 @@ protected:
return *Sec;
}
const Elf_Rel *getRel(DataRefImpl Rel) const;
const Elf_Rela *getRela(DataRefImpl Rela) const;
const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
return reinterpret_cast<const Elf_Sym *>(Sym.p & ~uintptr_t(1));
}
@ -304,6 +301,9 @@ protected:
public:
ELFObjectFile(MemoryBufferRef Object, std::error_code &EC);
const Elf_Rel *getRel(DataRefImpl Rel) const;
const Elf_Rela *getRela(DataRefImpl Rela) const;
const Elf_Sym *getSymbol(DataRefImpl Symb) const;
basic_symbol_iterator symbol_begin_impl() const override;

View File

@ -297,26 +297,15 @@ PrettyPrinter &selectPrettyPrinter(Triple const &Triple) {
}
}
template <class ELFT>
static const typename ELFObjectFile<ELFT>::Elf_Rel *
getRel(const ELFFile<ELFT> &EF, DataRefImpl Rel) {
typedef typename ELFObjectFile<ELFT>::Elf_Rel Elf_Rel;
return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
}
template <class ELFT>
static const typename ELFObjectFile<ELFT>::Elf_Rela *
getRela(const ELFFile<ELFT> &EF, DataRefImpl Rela) {
typedef typename ELFObjectFile<ELFT>::Elf_Rela Elf_Rela;
return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
}
template <class ELFT>
static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
DataRefImpl Rel,
SmallVectorImpl<char> &Result) {
typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
typedef typename ELFObjectFile<ELFT>::Elf_Rel Elf_Rel;
typedef typename ELFObjectFile<ELFT>::Elf_Rela Elf_Rela;
const ELFFile<ELFT> &EF = *Obj->getELFFile();
ErrorOr<const Elf_Shdr *> SecOrErr = EF.getSection(Rel.d.a);
@ -344,15 +333,17 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
default:
return object_error::parse_failed;
case ELF::SHT_REL: {
type = getRel(EF, Rel)->getType(EF.isMips64EL());
symbol_index = getRel(EF, Rel)->getSymbol(EF.isMips64EL());
const Elf_Rel *ERel = Obj->getRel(Rel);
type = ERel->getType(EF.isMips64EL());
symbol_index = ERel->getSymbol(EF.isMips64EL());
// TODO: Read implicit addend from section data.
break;
}
case ELF::SHT_RELA: {
type = getRela(EF, Rel)->getType(EF.isMips64EL());
symbol_index = getRela(EF, Rel)->getSymbol(EF.isMips64EL());
addend = getRela(EF, Rel)->r_addend;
const Elf_Rela *ERela = Obj->getRela(Rel);
type = ERela->getType(EF.isMips64EL());
symbol_index = ERela->getSymbol(EF.isMips64EL());
addend = ERela->r_addend;
break;
}
}