[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:18 PDT 2016


grimar added inline comments.


================
Comment at: ELF/InputSection.cpp:48
   // 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)))
----------------
ruiu wrote:
> Also, please leave a comment here to say that we reject object files having insanely large alignment requirements and may want to relax this limitation in the future.
> 
> binutils-ish tools have incredible long lifetime -- GNU ld has been used for decades now for example. We want to leave a hint why we are doing this, so that people who look at this code 10 years later won't have to wonder why we reject 4GB-aligned sections when they are creating 10 terabyte executable.
Done.


================
Comment at: ELF/InputSection.cpp:50
+      (Header->sh_addralign && !isPowerOf2_32(Header->sh_addralign)))
+    fatal(getFilename(File) + ": section sh_addralign is invalid");
   Alignment = std::max<uintX_t>(Header->sh_addralign, 1);
----------------
ruiu wrote:
> Technically, an alignment greater than 2^32 is not invalid, so this error message is wrong. Please separate the two conditions and print out different messages
> 
>   sh_addralign too large
>   sh_addralign is not a power of 2
Done.


https://reviews.llvm.org/D25324





More information about the llvm-commits mailing list