From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14358 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Chris Hall Newsgroups: gmane.linux.lib.musl.general Subject: malloc() alignment and max_align_t Date: Sun, 7 Jul 2019 19:17:48 +0100 Message-ID: <6b44b4a2-0047-6304-8c86-058236dc1c74@gmch.uk> References: <1561802993.8028.ezmlm@lists.openwall.com> <8c2d963e-1fcf-df2e-2a52-614f0250b594@gmch.uk> <20425c39-b411-b9bb-1e83-bf26dbcd7d4d@adelielinux.org> <20190629135859.GA21055@port70.net> <7dfceb33-b903-de2a-7abe-825f44512f0c@gmch.uk> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="106689"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 To: musl@lists.openwall.com Original-X-From: musl-return-14374-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jul 07 20:18:03 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hkBjd-000Rcs-7n for gllmg-musl@m.gmane.org; Sun, 07 Jul 2019 20:18:01 +0200 Original-Received: (qmail 13399 invoked by uid 550); 7 Jul 2019 18:17:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13366 invoked from network); 7 Jul 2019 18:17:56 -0000 In-Reply-To: <7dfceb33-b903-de2a-7abe-825f44512f0c@gmch.uk> Content-Language: en-GB Xref: news.gmane.org gmane.linux.lib.musl.general:14358 Archived-At: 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