diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -968,9 +968,6 @@ template Expected ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const { - if (EF.getHeader().e_type != ELF::ET_REL) - return section_end(); - const Elf_Shdr *EShdr = getSection(Sec); uintX_t Type = EShdr->sh_type; if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA) @@ -979,6 +976,9 @@ Expected SecOrErr = EF.getSection(EShdr->sh_info); if (!SecOrErr) return SecOrErr.takeError(); + if (EF.getHeader().e_type != ELF::ET_REL && + !((*SecOrErr)->sh_flags & ELF::SHF_ALLOC)) + return section_end(); return section_iterator(SectionRef(toDRI(*SecOrErr), this)); }