[llvm-commits] [PATCH] lli memory manager does not ensure proper alignment

Jim Grosbach grosbach at apple.com
Fri Oct 12 11:35:35 PDT 2012


+  // Honour the alignment requirement.
+  uint8_t *AlignedAddr = Addr;
+  unsigned AlignNeeded = Alignment - ((uintptr_t)Addr % Alignment);
+  if (AlignNeeded != Alignment)
+    AlignedAddr = Addr + AlignNeeded;

Why not just the following?
AlignedAddr = (uint8_t*)(((uintptr_t)Addr + Alignment - 1) / Alignment * Alignment);

On Oct 12, 2012, at 5:36 AM, Amara Emerson <amara.emerson at arm.com> wrote:

> Hi,
>  
> The allocateDataSection() function in the default lli memory manager does not properly align the memory address it receives from calloc in accordance with the caller’s requirements. This obviously creates problems as the data in the section assumes a certain alignment, causing segfaults on ARM.
>  
> Please review the attached patch.
>  
> Amara
> <lli-align-datasection.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121012/11f88143/attachment.html>


More information about the llvm-commits mailing list