[libcxxabi] Fix alignment of pointers returned by fallback_malloc
authorSimon Tatham <simon.tatham@arm.com>
Fri, 19 Aug 2022 14:07:55 +0000 (15:07 +0100)
committerSimon Tatham <simon.tatham@arm.com>
Fri, 19 Aug 2022 14:07:57 +0000 (15:07 +0100)
commita771a91dcbe637bc545da510fe5a9a671ab5e977
tree479af1243fb89525866223e1813001ebdb9bc6a7
parent80bbc05436d9c98d65b9b3a5f3907346ef3cb095
[libcxxabi] Fix alignment of pointers returned by fallback_malloc

This aligns the ``heap[]`` array in ``fallback_malloc.cpp`` to ensure
that it can be safely cast to ``heap_node*``, and also adjusts the
allocation algorithm to ensure that every allocated block has the
alignment requested by ``__attribute__((aligned))``, by putting the
block's ``heap_node`` header 4 bytes before an aligned address.

Patch originally by Eric Fiselier: this is an updated version of
D12669, which was never landed.

Reviewed By: ldionne, #libc_abi

Differential Revision: https://reviews.llvm.org/D129842
libcxxabi/src/fallback_malloc.cpp
libcxxabi/test/test_fallback_malloc.pass.cpp