[PATCH] D14119: [libcxxabi] Correctly align fallback heap
Oliver Stannard via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 27 07:26:33 PDT 2015
olista01 created this revision.
olista01 added reviewers: mclow.lists, compnerd.
olista01 added a subscriber: cfe-commits.
olista01 set the repository for this revision to rL LLVM.
The fallback malloc in libcxxabi (used to allocate space for exception
objects in out-of-memory situations) defines its heap as an array of
chars, but casts it to a struct containing shorts before accessing it.
Sometimes, the heap does not get placed on a 2-byte boundary, so
accesses to it caused unaligned access faults on targets that do not
support unaligned accesses.
The fix is to specify the alignment of the heap array, so that it will
always be sufficient for a heap_node.
This is still technically invoking undefined behaviour, as it is
accessing an object of type "char array" through an lvalue of a
different type. However, I don't think it is possible to write malloc
without violating that rule, and we have tests covering this.
@@ -51,6 +51,7 @@
#define HEAP_SIZE 512
char heap [ HEAP_SIZE ];
typedef unsigned short heap_offset;
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 302 bytes
Desc: not available
More information about the cfe-commits