From: Rafael Espindola Date: Thu, 2 Jul 2015 14:27:07 +0000 (+0000) Subject: Move error checking from once per relocation to once per relocation section. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7540435bef5446938099e3c53ef91c9c6d8f45ba;p=oota-llvm.git Move error checking from once per relocation to once per relocation section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241269 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index e1cbced3fea..41aed2fcd9d 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -609,21 +609,34 @@ 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)); } template relocation_iterator ELFObjectFile::section_rel_end(DataRefImpl Sec) const { - DataRefImpl RelData; - uintptr_t SHT = reinterpret_cast(EF.section_begin()); const Elf_Shdr *S = reinterpret_cast(Sec.p); - RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize; + relocation_iterator Begin = section_rel_begin(Sec); if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL) - RelData.d.b = 0; - else - RelData.d.b = S->sh_size / S->sh_entsize; - + return Begin; + DataRefImpl RelData = Begin->getRawDataRefImpl(); + RelData.d.b += (S->sh_size / S->sh_entsize) << 1; return relocation_iterator(RelocationRef(RelData, this)); } @@ -647,7 +660,7 @@ ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const { // Relocations template void ELFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { - ++Rel.d.b; + Rel.d.b += 2; } template @@ -662,23 +675,12 @@ ELFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { if (!symbolIdx) return symbol_end(); - ErrorOr SymSecOrErr = EF.getSection(sec->sh_link); - if (std::error_code EC = SymSecOrErr.getError()) - report_fatal_error(EC.message()); - const Elf_Shdr *SymSec = *SymSecOrErr; - + bool IsDyn = Rel.d.b & 1; DataRefImpl SymbolData; - switch (SymSec->sh_type) { - default: - report_fatal_error("Invalid symbol table section type!"); - case ELF::SHT_SYMTAB: - SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false); - break; - case ELF::SHT_DYNSYM: + if (IsDyn) SymbolData = toDRI(EF.dynamic_symbol_begin() + symbolIdx, true); - break; - } - + else + SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false); return symbol_iterator(SymbolRef(SymbolData, this)); } @@ -754,14 +756,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); + return EF.template getEntry(Rel.d.a, Rel.d.b >> 1); } 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); + return EF.template getEntry(Rela.d.a, Rela.d.b >> 1); } template