[PATCH] D25324: [ELF] - Check that section alignment is a power of 2.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 04:39:12 PDT 2016


grimar updated this revision to Diff 73913.
grimar added a comment.

- Addressed review comments.


https://reviews.llvm.org/D25324

Files:
  ELF/InputSection.cpp
  test/ELF/invalid/Inputs/section-alignment-notpow2.elf
  test/ELF/invalid/section-alignment.test
  test/ELF/invalid/section-alignment2.s


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 not a power of 2
Index: test/ELF/invalid/section-alignment.test
===================================================================
--- test/ELF/invalid/section-alignment.test
+++ test/ELF/invalid/section-alignment.test
@@ -13,7 +13,7 @@
   - Name:            .text
     Type:            SHT_PROGBITS
     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
-    AddressAlign:    0x1000000000000001
+    AddressAlign:    0x1000000000000000
     Content:         "00000000"
 
 # CHECK: section sh_addralign is too large
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -48,10 +48,14 @@
                        Hdr->sh_flags & SHF_COMPRESSED, !Config->GcSections),
       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)
+  // no alignment constraits. Also we reject object files having insanely large
+  // alignment requirements and may want to relax this limitation in the future.
+  uintX_t V = std::max<uintX_t>(Header->sh_addralign, 1);
+  if (!isPowerOf2_64(V))
+    fatal(getFilename(File) + ": section sh_addralign is not a power of 2");
+  if (V > UINT32_MAX)
     fatal(getFilename(File) + ": section sh_addralign is too large");
-  Alignment = std::max<uintX_t>(Header->sh_addralign, 1);
+  Alignment = V;
 }
 
 template <class ELFT> size_t InputSectionBase<ELFT>::getSize() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25324.73913.patch
Type: text/x-patch
Size: 1989 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161007/cd64becf/attachment.bin>


More information about the llvm-commits mailing list