[lld] r283733 - [ELF] - Do not crash if common symbol alignment set to value greater than UINT32_MAX.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 10 03:10:10 PDT 2016


Author: grimar
Date: Mon Oct 10 05:10:09 2016
New Revision: 283733

URL: http://llvm.org/viewvc/llvm-project?rev=283733&view=rev
Log:
[ELF] - Do not crash if common symbol alignment set to value greater 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

Added:
    lld/trunk/test/ELF/invalid/Inputs/common-symbol-alignment2.elf   (with props)
Modified:
    lld/trunk/test/ELF/invalid/common-symbol-alignment.s

Added: lld/trunk/test/ELF/invalid/Inputs/common-symbol-alignment2.elf
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/Inputs/common-symbol-alignment2.elf?rev=283733&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lld/trunk/test/ELF/invalid/Inputs/common-symbol-alignment2.elf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: lld/trunk/test/ELF/invalid/common-symbol-alignment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/common-symbol-alignment.s?rev=283733&r1=283732&r2=283733&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/common-symbol-alignment.s (original)
+++ lld/trunk/test/ELF/invalid/common-symbol-alignment.s Mon Oct 10 05:10:09 2016
@@ -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




More information about the llvm-commits mailing list