diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index efff38f11c4..5acb4ae3f4e 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -607,22 +607,6 @@ ELFObjectFile::section_rel_begin(DataRefImpl Sec) const { uintptr_t SHT = reinterpret_cast(EF.section_begin()); RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize; RelData.d.b = 0; - - const Elf_Shdr *S = reinterpret_cast(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 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::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 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::getRelocatedSection(DataRefImpl Sec) const { // Relocations template void ELFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { - Rel.d.b += 2; + ++Rel.d.b; } template @@ -673,12 +664,10 @@ ELFObjectFile::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 const typename ELFObjectFile::Elf_Rel * ELFObjectFile::getRel(DataRefImpl Rel) const { assert(getRelSection(Rel)->sh_type == ELF::SHT_REL); - return EF.template getEntry(Rel.d.a, Rel.d.b >> 1); + return EF.template getEntry(Rel.d.a, Rel.d.b); } template const typename ELFObjectFile::Elf_Rela * ELFObjectFile::getRela(DataRefImpl Rela) const { assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA); - return EF.template getEntry(Rela.d.a, Rela.d.b >> 1); + return EF.template getEntry(Rela.d.a, Rela.d.b); } template