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. Repository: rL LLVM http://reviews.llvm.org/D14119 Files: src/fallback_malloc.ipp Index: src/fallback_malloc.ipp =================================================================== --- src/fallback_malloc.ipp +++ src/fallback_malloc.ipp @@ -51,6 +51,7 @@ #define HEAP_SIZE 512 +__attribute((aligned(2))) char heap [ HEAP_SIZE ]; typedef unsigned short heap_offset;
Index: src/fallback_malloc.ipp =================================================================== --- src/fallback_malloc.ipp +++ src/fallback_malloc.ipp @@ -51,6 +51,7 @@ #define HEAP_SIZE 512 +__attribute((aligned(2))) char heap [ HEAP_SIZE ]; typedef unsigned short heap_offset;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits