[PATCH] D74364: [GWP-ASan] Update alignment on Android.

Mitch Phillips via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 18:12:35 PST 2020


hctim added a comment.

In D74364#1868418 <https://reviews.llvm.org/D74364#1868418>, @morehouse wrote:

> Does Bionic's `malloc` have the required alignment information available at the call to `gwp_asan::allocate`?  If so, we could get tighter right alignment by adding an `alignment` parameter (instead of conservative 16-byte rounding).  This is the approach used in both Chrome and TCMalloc.
>
> e.g., one of the most common malloc sizes is 24 (nodes in tree structures), which won't get perfectly right-aligned with the current approach, though it should be safe to do so.


Unfortunately not, we're called directly from the `malloc()` family. Doesn't matter though, because...

As @pcc pointed out, the Android policy isn't eight-then-sixteen, it's actually "always align to 16 bytes if asked for an allocation with alignment 16-bytes, otherwise align 8-bytes", e.g.

  malloc(5) => malloc(8)
  malloc(9) => malloc(16)
  malloc(17) => malloc(24)
  malloc(16) => malloc(16), or if you're the backing allocator and there are no 16-byte buckets, you *must* use malloc(32), not malloc(24).

For our purposes, we can *always* ensure that a 16-byte allocation gets 16-bytes, and we only need to round to 8-bytes. Let me update the patchset.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74364/new/

https://reviews.llvm.org/D74364





More information about the llvm-commits mailing list