Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -45,8 +45,9 @@ 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"); + if (Header->sh_addralign > UINT32_MAX || + (Header->sh_addralign && !isPowerOf2_32(Header->sh_addralign))) + fatal(getFilename(File) + ": section sh_addralign is invalid"); Alignment = std::max(Header->sh_addralign, 1); } Index: test/ELF/invalid/section-alignment.test =================================================================== --- test/ELF/invalid/section-alignment.test +++ test/ELF/invalid/section-alignment.test @@ -16,4 +16,4 @@ AddressAlign: 0x1000000000000001 Content: "00000000" -# CHECK: section sh_addralign is too large +# CHECK: section sh_addralign is invalid Index: test/ELF/invalid/section-alignment2.s =================================================================== --- test/ELF/invalid/section-alignment2.s +++ test/ELF/invalid/section-alignment2.s @@ -0,0 +1,5 @@ +## section-alignment-notpow2.elf has section alignment +## 0xFFFFFFFF which is not a power of 2. +# RUN: not ld.lld %p/Inputs/section-alignment-notpow2.elf -o %t2 2>&1 | \ +# RUN: FileCheck %s +# CHECK: section sh_addralign is invalid