This is an archive of the discontinued LLVM Phabricator instance.

[libc++abi] Fix fallback allocator alignment issue
AbandonedPublic

Authored by miyuki on Apr 11 2022, 6:57 AM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Summary

Currently, the libc++abi fallback memory allocator only guarantees
4-byte alignment even on 64-bit systems. This causes failures
(hardware exceptions due to misalignment) on bare-metal AArch64.

The patch fixes the issue by increasing the heap block size to 8
bytes on 64-bit systems.

Diff Detail

Event Timeline

miyuki created this revision.Apr 11 2022, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2022, 6:57 AM
miyuki requested review of this revision.Apr 11 2022, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2022, 6:57 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
miyuki edited the summary of this revision. (Show Details)Apr 11 2022, 6:59 AM

Just to confirm my understanding, basically this only triggers when malloc(...) returns nullptr, i.e. when memory is exhausted, right?

libcxxabi/src/fallback_malloc.cpp
76–77

This is perhaps silly, but I'm not sure I understand why changing the representation of the offset and size is what we want to do here. Shouldn't we instead be adjusting the pointer we are returning when we allocate memory to have the proper alignment?

In other words, this patch has the side effect that we'll return properly aligned memory, however we could technically keep the same representation as before and also return aligned memory, right?

Just to confirm my understanding, basically this only triggers when malloc(...) returns nullptr, i.e. when memory is exhausted, right?

Yes, that's correct.

miyuki added inline comments.Apr 13 2022, 6:16 AM
libcxxabi/src/fallback_malloc.cpp
76–77

Right. I found an existing patch that seems to do the right thing: https://reviews.llvm.org/D12669. Should we revive it?

ldionne added inline comments.Apr 13 2022, 10:41 AM
libcxxabi/src/fallback_malloc.cpp
76–77

Very interesting! Yes, I would definitely support reviving that patch!

I've just uploaded D129842, an updated version of D12669.

miyuki abandoned this revision.Jul 28 2022, 9:42 AM

Abandoning in favor of D129842.