Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 7 Jul 2019 19:17:48 +0100
From: Chris Hall <musl@...h.uk>
To: musl@...ts.openwall.com
Subject: malloc() alignment and max_align_t


The C11 Standard says that malloc() will return a pointer which "is 
suitably aligned so that it may be assigned to a pointer to any type of 
object with a fundamental alignment requirement", and it says that 
_Alignof(max_align_t) is equal to the "fundamental alignment".

I note that:

  * musl malloc() works to an alignment SIZE_ALIGN, which is
    #defined'd to 4*sizeof(size_t) == 32 for 64-bit processors.

  * musl defines max_align_t:

      typedef struct { long long __ll;
                       long double __ld; } max_align_t;

    (same like other libc, FWIW).

    _Alignof(max_align_t) == 16 for x86_64 (at least),
    because that's the ABI alignment for long double.

Clearly, C11 does not require malloc() to align exactly as max_align_t, 
and bigger is fine.

But I'm curious as to why SIZE_ALIGN is twice as big as it needs to be ?

Thanks,

Chris

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.