[PATCH] D25235: [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
Tue Oct 4 06:57:18 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
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. I did not find the way to generate object using yaml2obj for that case.
https://reviews.llvm.org/D25235
Files:
ELF/InputFiles.cpp
test/ELF/invalid/Inputs/common-symbol-alignment2.elf
test/ELF/invalid/common-symbol-alignment.s
Index: test/ELF/invalid/common-symbol-alignment.s
===================================================================
--- test/ELF/invalid/common-symbol-alignment.s
+++ test/ELF/invalid/common-symbol-alignment.s
@@ -3,4 +3,9 @@
## 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' alignment is 0 or too large
+
+## 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
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -400,9 +400,9 @@
/*CanOmitFromDynSym*/ false, this)
->body();
case SHN_COMMON:
- if (Sym->st_value == 0)
+ if (Sym->st_value == 0 || Sym->st_value >= UINT32_MAX)
fatal(getFilename(this) + ": common symbol '" + Name +
- "' alignment is 0");
+ "' alignment is 0 or too large");
return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
Binding, Sym->st_other,
Sym->getType(), this)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25235.73471.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161004/e8aa1d57/attachment.bin>
More information about the llvm-commits
mailing list