Skip to content

Commit

Permalink
[ELF] - Do not crash if common symbol alignment set to value greater …
Browse files Browse the repository at this point in the history
…than UINT32_MAX.

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: 283733
  • Loading branch information
George Rimar committed Oct 10, 2016
1 parent a9b79e6 commit 50188b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Binary file not shown.
8 changes: 7 additions & 1 deletion lld/test/ELF/invalid/common-symbol-alignment.s
Expand Up @@ -3,4 +3,10 @@
## 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
# 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

0 comments on commit 50188b2

Please sign in to comment.