[ELF] - Do not crash on invalid symbol index.

Relative to PR30540.

If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.

This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"

Differential revision: https://reviews.llvm.org/D25025

llvm-svn: 283201
This commit is contained in:
George Rimar 2016-10-04 09:02:42 +00:00
parent ee8dcfbdf7
commit b1f78d1202
3 changed files with 12 additions and 0 deletions

View File

@ -151,6 +151,8 @@ public:
InputSectionBase<ELFT> *getSection(const Elf_Sym &Sym) const;
SymbolBody &getSymbolBody(uint32_t SymbolIndex) const {
if (SymbolIndex >= SymbolBodies.size())
fatal(getFilename(this) + ": invalid symbol index");
return *SymbolBodies[SymbolIndex];
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
## invalid-symbol-index.elf has incorrect type of .symtab section.
## There is no symbol bodies because of that and any symbol index becomes incorrect.
## Section Headers:
## [Nr] Name Type Address Off Size ES Flg Lk Inf Al
## [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
## ...
## [ 4] .symtab RELA 0000000000000000 000048 000030 18 1 2 8
# RUN: not ld.lld %p/Inputs/invalid-symbol-index.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-SYMBOL-INDEX %s
# INVALID-SYMBOL-INDEX: invalid symbol index