Simplify how we represent relocation iterators.

Instead of using a bit to detect if they are "dynamic", just look at
sh_link.

This is a simplification on its own, and will help with using
llvm-objdump in dynamic objects.

llvm-svn: 264624
This commit is contained in:
Rafael Espindola 2016-03-28 19:23:51 +00:00
parent 398d066e7d
commit 76c717ec6a

View File

@ -607,22 +607,6 @@ ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const {
uintptr_t SHT = reinterpret_cast<uintptr_t>(EF.section_begin());
RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize;
RelData.d.b = 0;
const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
return relocation_iterator(RelocationRef(RelData, this));
const Elf_Shdr *RelSec = getRelSection(RelData);
ErrorOr<const Elf_Shdr *> SymSecOrErr = EF.getSection(RelSec->sh_link);
if (std::error_code EC = SymSecOrErr.getError())
report_fatal_error(EC.message());
const Elf_Shdr *SymSec = *SymSecOrErr;
uint32_t SymSecType = SymSec->sh_type;
if (SymSecType != ELF::SHT_SYMTAB && SymSecType != ELF::SHT_DYNSYM)
report_fatal_error("Invalid symbol table section type!");
if (SymSecType == ELF::SHT_DYNSYM)
RelData.d.b = 1;
return relocation_iterator(RelocationRef(RelData, this));
}
@ -634,7 +618,14 @@ ELFObjectFile<ELFT>::section_rel_end(DataRefImpl Sec) const {
if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
return Begin;
DataRefImpl RelData = Begin->getRawDataRefImpl();
RelData.d.b += (S->sh_size / S->sh_entsize) << 1;
const Elf_Shdr *RelSec = getRelSection(RelData);
// Error check sh_link here so that getRelocationSymbol can just use it.
ErrorOr<const Elf_Shdr *> SymSecOrErr = EF.getSection(RelSec->sh_link);
if (std::error_code EC = SymSecOrErr.getError())
report_fatal_error(EC.message());
RelData.d.b += S->sh_size / S->sh_entsize;
return relocation_iterator(RelocationRef(RelData, this));
}
@ -658,7 +649,7 @@ ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const {
// Relocations
template <class ELFT>
void ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const {
Rel.d.b += 2;
++Rel.d.b;
}
template <class ELFT>
@ -673,12 +664,10 @@ ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
if (!symbolIdx)
return symbol_end();
bool IsDyn = Rel.d.b & 1;
// FIXME: error check symbolIdx
DataRefImpl SymbolData;
if (IsDyn)
SymbolData = toDRI(DotDynSymSec, symbolIdx);
else
SymbolData = toDRI(DotSymtabSec, symbolIdx);
SymbolData.d.a = sec->sh_link;
SymbolData.d.b = symbolIdx;
return symbol_iterator(SymbolRef(SymbolData, this));
}
@ -726,14 +715,14 @@ template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rel *
ELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const {
assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b >> 1);
return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
}
template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rela *
ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const {
assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b >> 1);
return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
}
template <class ELFT>