[llvm-readobj] - Do not crash when GnuHashTable->symndx is greater than the dynamic...
authorGeorgii Rymar <grimar@accesssoftek.com>
Tue, 16 Jun 2020 14:05:51 +0000 (17:05 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Wed, 17 Jun 2020 11:26:36 +0000 (14:26 +0300)
commit88c8581d9fe449f07781ff8abedf598b9410e727
treeaf22a5cb9b76da06e12e14046f3df863f880c989
parente8299a806ad197d64a627c1868b842256f464035
[llvm-readobj] - Do not crash when GnuHashTable->symndx is greater than the dynamic symbols count.

`Elf_GnuHash_Impl` has the following method:

```
ArrayRef<Elf_Word> values(unsigned DynamicSymCount) const {
  return ArrayRef<Elf_Word>(buckets().end(), DynamicSymCount - symndx);
}
```

When DynamicSymCount is less than symndx we return an array with the huge broken size.
This patch fixes the issue and adds an assert. This assert helped to fix an issue
in one of the test cases.

Differential revision: https://reviews.llvm.org/D81937
llvm/include/llvm/Object/ELFTypes.h
llvm/test/tools/llvm-readobj/ELF/gnuhash.test
llvm/test/tools/llvm-readobj/ELF/hash-histogram.test
llvm/tools/llvm-readobj/ELFDumper.cpp