[PATCH] D12669: [libcxxabi] Fix alignment of pointers returned by fallback_malloc

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 6 23:20:07 PDT 2015


EricWF created this revision.
EricWF added reviewers: mclow.lists, compnerd, joerg, jroelofs.
EricWF added a subscriber: cfe-commits.

Currently the pointers returned by fallback_malloc do not have *ANY* alignment guarantees. This is caused by two different problems is `fallback_malloc.ipp`. 

The first reason is because the `heap` array used by fallback malloc only has an alignment requirement of '1'. Currently we try and put the first heap_node directly at the start of `heap` even though 'heap_node' has an alignment requirement of at least 2 bytes. This patch fixes this issue by manually aligning `heap` using `alignas(heap_node)`.

The second reason is because fallback_malloc returns the pointers that are exactly `sizeof(heap_node)` bytes after the heap_node header itself. Because heap_nodes only have an alignment requirement of '2' the resulting pointers also only have an alignment requirement of '2' even though an alignment of '16' bytes is required. This patch fixes this problem by
manually requiring that all heap_nodes  have an address that is 4 bytes before a 16 byte boundary.




http://reviews.llvm.org/D12669

Files:
  src/cxa_exception.cpp
  src/fallback_malloc.ipp
  test/test_fallback_malloc.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12669.34127.patch
Type: text/x-patch
Size: 9697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150907/c39c02ca/attachment-0001.bin>


More information about the cfe-commits mailing list