[ELF] - Do not crash if common symbol has alignment 0.

Testcase contains a common symbol with zero alignment,
previously lld would crash, patch fixes that.

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

llvm-svn: 283197
This commit is contained in:
George Rimar 2016-10-04 08:49:52 +00:00
parent 5cbf23664d
commit 0c82561c4c
3 changed files with 9 additions and 0 deletions

View File

@ -400,6 +400,9 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
/*CanOmitFromDynSym*/ false, this)
->body();
case SHN_COMMON:
if (Sym->st_value == 0)
fatal(getFilename(this) + ": common symbol '" + Name +
"' alignment is 0");
return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
Binding, Sym->st_other,
Sym->getType(), this)

View File

@ -0,0 +1,6 @@
# REQUIRES: x86
## common-symbol-alignment.elf contains common symbol with zero alignment.
# RUN: not ld.lld %S/Inputs/common-symbol-alignment.elf \
# RUN: -o %t 2>&1 | FileCheck %s
# CHECK: common symbol 'bar' alignment is 0