forked from OSchip/llvm-project
Recommit r283733 "[ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX.
With fix: commit changes from InputFiles.cpp too. Original commit message: We have following code in lld, that truncates the alignment value to 32 bit. Big alignment in this case may give result 0 and crash later. template <class ELFT> CommonInputSection<ELFT>::CommonInputSection(std::vector<DefinedCommon *> Syms) : InputSection<ELFT>(nullptr, &Hdr, "") { .... for (DefinedCommon *Sym : Syms) { this->Alignment = std::max<uintX_t>(this->Alignment, Sym->Alignment); ... } } Patch fixes the issue. Differential revision: https://reviews.llvm.org/D25235 llvm-svn: 283738
This commit is contained in:
parent
a1b8245654
commit
27e651d4f6
|
@ -437,9 +437,9 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
|
||||||
/*CanOmitFromDynSym*/ false, this)
|
/*CanOmitFromDynSym*/ false, this)
|
||||||
->body();
|
->body();
|
||||||
case SHN_COMMON:
|
case SHN_COMMON:
|
||||||
if (Sym->st_value == 0)
|
if (Sym->st_value == 0 || Sym->st_value >= UINT32_MAX)
|
||||||
fatal(getFilename(this) + ": common symbol '" + Name +
|
fatal(getFilename(this) + ": common symbol '" + Name +
|
||||||
"' alignment is 0");
|
"' has invalid alignment: " + Twine(Sym->st_value));
|
||||||
return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
|
return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
|
||||||
Binding, Sym->st_other,
|
Binding, Sym->st_other,
|
||||||
Sym->getType(), this)
|
Sym->getType(), this)
|
||||||
|
|
Binary file not shown.
|
@ -3,4 +3,10 @@
|
||||||
## common-symbol-alignment.elf contains common symbol with zero alignment.
|
## common-symbol-alignment.elf contains common symbol with zero alignment.
|
||||||
# RUN: not ld.lld %S/Inputs/common-symbol-alignment.elf \
|
# RUN: not ld.lld %S/Inputs/common-symbol-alignment.elf \
|
||||||
# RUN: -o %t 2>&1 | FileCheck %s
|
# RUN: -o %t 2>&1 | FileCheck %s
|
||||||
# CHECK: common symbol 'bar' alignment is 0
|
# CHECK: common symbol 'bar' has invalid alignment: 0
|
||||||
|
|
||||||
|
## common-symbol-alignment2.elf contains common symbol alignment greater
|
||||||
|
## than UINT32_MAX.
|
||||||
|
# RUN: not ld.lld %S/Inputs/common-symbol-alignment2.elf \
|
||||||
|
# RUN: -o %t 2>&1 | FileCheck %s --check-prefix=BIG
|
||||||
|
# BIG: common symbol 'bar' has invalid alignment: 271644049215
|
||||||
|
|
Loading…
Reference in New Issue