It was requested on review for https://reviews.llvm.org/D25090 to add testcase in lld.
Spec says (http://www.sco.com/developers/gabi/1998-04-29/ch4.eheader.html) :
e_shnum
This member holds the number of entries in the section header table.
Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes.
If a file has no section header table, e_shnum holds the value zero.
In case revealed, broken input did not contain zero in this field.
LLD then could crash when proccessed sections (returned array has incorrect size):
template <class ELFT> void SharedFile<ELFT>::parseSoName() {
...
for (const Elf_Shdr &Sec : Obj.sections()) {
...
llvm-svn: 284375
--- /dev/null
+## Spec says that "If a file has no section header table, e_shnum holds the value zero.", though
+## in this test case it holds non-zero and lld may crash.
+# RUN: not ld.lld %p/Inputs/invalid-e_shnum.elf -o %t2 2>&1 | FileCheck %s
+# CHECK: e_shnum should be zero if a file has no section header table
\ No newline at end of file