This is an archive of the discontinued LLVM Phabricator instance.

[libcxxabi] Fix alignment of pointers returned by fallback_malloc
ClosedPublic

Authored by simon_tatham on Jul 15 2022, 2:38 AM.

Details

Summary

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.

Diff Detail

Event Timeline

simon_tatham created this revision.Jul 15 2022, 2:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 2:38 AM
simon_tatham requested review of this revision.Jul 15 2022, 2:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 2:38 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

CI fix: tell test_fallback_malloc_pass.cpp not to try to run in C++03 mode, which won't work now that the library source file it includes uses alignof.

miyuki added inline comments.Jul 28 2022, 10:18 AM
libcxxabi/src/fallback_malloc.cpp
105

(A + sizeof(heap_node)) % RequiredAlignment

Corrected that comment.

The patch LGTM, but since this is libc++abi, we need approval from the code owners.

Ping. Can someone in the libc++abi blocking reviewer group take a look at this patch, please?

Ping again. If I'm reading the libc++ group members page right, this patch needs to be looked at by at least one of: @EricWF @erik.pilkington @ldionne @mclow.lists @phosek @compnerd @urnathan . Is there somewhere else I should be asking, to bring it to the attention of the right people?

ldionne accepted this revision.Aug 19 2022, 6:35 AM
This revision is now accepted and ready to land.Aug 19 2022, 6:35 AM