Use asserts for checks that should never fail.

If a section is not SHT_REL or SHT_RELA, we never create a valid iterator,
so the getRelocation* methods should always see a section with the correct type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241023 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-06-29 23:55:05 +00:00
parent a74341308f
commit 2edab1ac31

View File

@ -637,18 +637,10 @@ symbol_iterator
ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const { ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
uint32_t symbolIdx; uint32_t symbolIdx;
const Elf_Shdr *sec = getRelSection(Rel); const Elf_Shdr *sec = getRelSection(Rel);
switch (sec->sh_type) { if (sec->sh_type == ELF::SHT_REL)
default:
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL: {
symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL()); symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
break; else
}
case ELF::SHT_RELA: {
symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL()); symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
break;
}
}
if (!symbolIdx) if (!symbolIdx)
return symbol_end(); return symbol_end();
@ -697,32 +689,20 @@ uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
template <class ELFT> template <class ELFT>
uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const { uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const {
const Elf_Shdr *sec = getRelSection(Rel); const Elf_Shdr *sec = getRelSection(Rel);
switch (sec->sh_type) { if (sec->sh_type == ELF::SHT_REL)
default:
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL:
return getRel(Rel)->r_offset; return getRel(Rel)->r_offset;
case ELF::SHT_RELA:
return getRela(Rel)->r_offset; return getRela(Rel)->r_offset;
}
} }
template <class ELFT> template <class ELFT>
std::error_code ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel, std::error_code ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel,
uint64_t &Result) const { uint64_t &Result) const {
const Elf_Shdr *sec = getRelSection(Rel); const Elf_Shdr *sec = getRelSection(Rel);
switch (sec->sh_type) { if (sec->sh_type == ELF::SHT_REL)
default:
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL: {
Result = getRel(Rel)->getType(EF.isMips64EL()); Result = getRel(Rel)->getType(EF.isMips64EL());
break; else
}
case ELF::SHT_RELA: {
Result = getRela(Rel)->getType(EF.isMips64EL()); Result = getRela(Rel)->getType(EF.isMips64EL());
break;
}
}
return std::error_code(); return std::error_code();
} }
@ -736,18 +716,10 @@ std::error_code ELFObjectFile<ELFT>::getRelocationTypeName(
DataRefImpl Rel, SmallVectorImpl<char> &Result) const { DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
const Elf_Shdr *sec = getRelSection(Rel); const Elf_Shdr *sec = getRelSection(Rel);
uint32_t type; uint32_t type;
switch (sec->sh_type) { if (sec->sh_type == ELF::SHT_REL)
default:
return object_error::parse_failed;
case ELF::SHT_REL: {
type = getRel(Rel)->getType(EF.isMips64EL()); type = getRel(Rel)->getType(EF.isMips64EL());
break; else
}
case ELF::SHT_RELA: {
type = getRela(Rel)->getType(EF.isMips64EL()); type = getRela(Rel)->getType(EF.isMips64EL());
break;
}
}
EF.getRelocationTypeName(type, Result); EF.getRelocationTypeName(type, Result);
return std::error_code(); return std::error_code();
@ -775,12 +747,14 @@ ELFObjectFile<ELFT>::getSymbol(DataRefImpl Symb) const {
template <class ELFT> template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rel * const typename ELFObjectFile<ELFT>::Elf_Rel *
ELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const { 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); return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
} }
template <class ELFT> template <class ELFT>
const typename ELFObjectFile<ELFT>::Elf_Rela * const typename ELFObjectFile<ELFT>::Elf_Rela *
ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const { 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); return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
} }