From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15027 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: max_align_t mess on i386 Date: Sun, 15 Dec 2019 23:03:08 +0300 (MSK) Message-ID: References: <20191214151932.GW1666@brightrain.aerifal.cx> <20191215182314.GB986899@wirbelwind.zhasha.com> <20191215185125.GB1666@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="242002"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) To: musl@lists.openwall.com Original-X-From: musl-return-15043-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 15 21:03:22 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 1iga6s-0010tC-Dg for gllmg-musl@m.gmane.org; Sun, 15 Dec 2019 21:03:22 +0100 Original-Received: (qmail 13953 invoked by uid 550); 15 Dec 2019 20:03:19 -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 13935 invoked from network); 15 Dec 2019 20:03:19 -0000 In-Reply-To: <20191215185125.GB1666@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:15027 Archived-At: On Sun, 15 Dec 2019, Rich Felker wrote: > > It might violate the standard technically speaking, but I don't know of > > any examples of types smaller than 16 bytes that require 16 byte > > alignment. > > It doesn't since no object can have size smaller than its alignment. > (As long as pointer types aren't lossy; if some pointer types lost low > bits, then it would be non-conforming.) Yeah. I believe one usual concern is whether low bits may be expected to be zero in case one wants to carry a couple of bits along with the pointer. On one hand, C doesn't say what it means for an arbitrary pointer to be suitably aligned for a particular type. On the other hand, in practice everyone assumes that it means that its value is divisible by alignment, and so on platforms with _Alignof(max_align_t) == 16, it means that low 4 bits of any address returned from malloc (including those with tiny allocated storage) will be zero. Which makes those bit positions available for flags associated with the pointer, if you can arrange for them to be masked off to use the pointer itself. (in principle a compiler could transform a program like that too, and unlike a programmer the compiler knows exactly what it means for a pointer to be aligned) So if such use is accepted as valid, malloc needs to ensure alignment despite a small allocation size. Alexander