[ELF2] - Fixed crash for case when section sh_entsize is set to zero for SHF_MERGE type of sections.

Differential revision: http://reviews.llvm.org/D14451

llvm-svn: 252454
This commit is contained in:
George Rimar
2015-11-09 08:40:44 +00:00
parent 9ea507edc7
commit 564da7ee87
3 changed files with 5 additions and 1 deletions

View File

@@ -143,7 +143,7 @@ static bool shouldMerge(const typename ELFFile<ELFT>::Elf_Shdr &Sec) {
if (Flags & SHF_WRITE)
error("Writable SHF_MERGE sections are not supported");
uintX_t EntSize = Sec.sh_entsize;
if (Sec.sh_size % EntSize)
if (!EntSize || Sec.sh_size % EntSize)
error("SHF_MERGE section size must be a multiple of sh_entsize");
// Don't try to merge if the aligment is larger than the sh_entsize.

Binary file not shown.

View File

@@ -23,4 +23,8 @@
# RUN: not ld.lld2 %p/Inputs/invalid-shstrndx.so -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX %s
# RUN: not ld.lld2 %p/Inputs/invalid-shentsize-zero.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-SHENTSIZE-ZERO %s
# INVALID-SHENTSIZE-ZERO: SHF_MERGE section size must be a multiple of sh_entsize
.long foo