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 @@ -1019,8 +1019,14 @@ template elf_symbol_iterator ELFObjectFile::dynamic_symbol_begin() const { - DataRefImpl Sym = toDRI(DotDynSymSec, 0); - return symbol_iterator(SymbolRef(Sym, this)); + if (!DotDynSymSec || !DotDynSymSec->sh_size || + DotDynSymSec->sh_size % sizeof(Elf_Sym) != 0) { + // We are ignoring malformed .dynsym section. + return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this)); + } else { + // Skip 0-index NULL symbol. + return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this)); + } } template