diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-10-03 10:04:38 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-10-03 10:04:38 +0000 |
commit | 2c0a7f081a8a681f29e1fc4ad115e77a9ade0f64 (patch) | |
tree | a7ed90195700d2058cd2ddeab594bd817b1b6966 | |
parent | fd1b3814b321544aff5b7ab1609130b48b88bef7 (diff) | |
download | bcm5719-llvm-2c0a7f081a8a681f29e1fc4ad115e77a9ade0f64.tar.gz bcm5719-llvm-2c0a7f081a8a681f29e1fc4ad115e77a9ade0f64.zip |
[ELF] - Do not crash on invalid section alignment.
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.
Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.
Patch fixes the issue.
Differential revision: https://reviews.llvm.org/D25082
llvm-svn: 283097
-rw-r--r-- | lld/ELF/InputSection.cpp | 2 | ||||
-rw-r--r-- | lld/test/ELF/invalid/section-alignment.test | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 789b4e44968..09e640e3b16 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -45,6 +45,8 @@ InputSectionBase<ELFT>::InputSectionBase(elf::ObjectFile<ELFT> *File, Header(Hdr), File(File), Repl(this) { // The ELF spec states that a value of 0 means the section has // no alignment constraits. + if (Header->sh_addralign > UINT32_MAX) + fatal(getFilename(File) + ": section sh_addralign is too large"); Alignment = std::max<uintX_t>(Header->sh_addralign, 1); } diff --git a/lld/test/ELF/invalid/section-alignment.test b/lld/test/ELF/invalid/section-alignment.test new file mode 100644 index 00000000000..1c7afa7d469 --- /dev/null +++ b/lld/test/ELF/invalid/section-alignment.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %s -o %t +# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s + +## In current lld implementation, we do not accept sh_addralign +## larger than UINT32_MAX. +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x1000000000000001 + Content: "00000000" + +# CHECK: section sh_addralign is too large |