From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5074 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Pawe=C5=82_Dziepak?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] add definition of max_align_t to stddef.h Date: Wed, 7 May 2014 11:28:58 +0200 Message-ID: References: <20140507031306.GA26963@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1399454956 11285 80.91.229.3 (7 May 2014 09:29:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 7 May 2014 09:29:16 +0000 (UTC) Cc: Pawel Dziepak To: musl@lists.openwall.com Original-X-From: musl-return-5080-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 07 11:29:11 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WhyA3-0007i9-5l for gllmg-musl@plane.gmane.org; Wed, 07 May 2014 11:29:11 +0200 Original-Received: (qmail 12103 invoked by uid 550); 7 May 2014 09:29:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 12095 invoked from network); 7 May 2014 09:29:10 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=KVZ6/l7OwiGoAumMdEjodMnyipF0ha+zpNNu+H3sEaw=; b=ZzB2dixrtWL2AmPmOO91aa3jRdxesu94j1ygjfamnSXe0L7maQ92K9iZ3eaCTboC4n w0MzhVBqbhv71NEKkAhi5Gm2yTZcp2TCtbZQlp89Gus0BbeKUmLdQu+NB8wPdmEu+8Dc OtYgnZ6oJQz/jcq071FT6Gh8cUy0VoHUarqDz6RxCQCklgOmGgns8w8L//ScpUhrlrG6 0szvZrlw7lmMbPxvKc8c0Ovm+nP0yotoP/iN1xLs6cpn16VERTEhSmO4SPAbfv4WQnMq meN2lPliZPzaWDncPbZ+XZy9HFgCvBBBDAkHTBOGdsH6Qr4Zi2tP6gSQhbE8Bfb8xK8r /bOA== X-Gm-Message-State: ALoCoQn7Pqeu64+++HG+ESgZ0FwQaP0z+C3j1qh0LLetnGOfnKG0o/kBnJD1FSYr9+OeduOZSB3s X-Received: by 10.50.62.51 with SMTP id v19mr40684061igr.21.1399454938221; Wed, 07 May 2014 02:28:58 -0700 (PDT) In-Reply-To: <20140507031306.GA26963@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:5074 Archived-At: 2014-05-07 5:13 GMT+02:00 Rich Felker : > On Tue, May 06, 2014 at 12:35:55PM +0200, Pawe=C5=82 Dziepak wrote: >> >> would be a good thing to mach the definition gcc and clang use, i.e. >> >> something like that: >> >> >> >> union max_align_t { >> >> alignas(long long) long long _ll; >> >> alignas(long double) long double _ld; >> >> }; >> > >> > This should not give results different from omitting the "alignas". >> > The only reason it does give different results is a bug in GCC, so we >> > should not be copying this confusing mess that's a no-op for a correct >> > compiler. (Applying alignas(T) to type T is always a no-op.) >> >> I should have checked whether GCC 4.9 has changed before sending that. >> As I said earlier, alignof in 4.9 seems to be fixed and on i386 for >> fundamental types values <=3D4 are returned. alignof(max_align_t) >> remains 8, though. > > Then GCC still has a bug. The above definition should give an > alignment of 4, not 8. Neither alignas(long long) nor alignas(long > double) should impose 8-byte alignment. To clarify: GCC defines max_align_t so its alignment is 8. My original definition (without alignas) makes max_align_t 4-byte-aligned (both GCC 4.8.2 and 4.9). My second definition (with alignas) results in 8-byte-aligned max_align_t on GCC 4.8.2 and bug in GCC 4.9 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61053 GCC uses its own __alignof__ to define max_align_t. __alignof__ returns the recommended alignment (as oposed to minimal in case of alignof), which in case of long long is 8. >> However, while 4, undobtedly, is the expected value of >> alignof(max_align_t) I don't think that 8 is really wrong (well, from >> the C11 point of view). The standard is not very specific about what >> max_align_t really should be and if the compiler supports larger >> alignment in all contexts there is no reason that alignof(max_align_t) >> cannot be larger than alignof() of the type with the strictest >> alignment requirements. >> Obviously, since max_align_t is the part of ABI it is not like the >> implementation can set alignof(max_align_t) to any value or it would >> risk compatibility problems with binaries compiled with different >> max_align_t. Since both GCC and Clang already define max_align_t so >> that its alignment is 8 on i386 I think that Musl should do the same. > > If we want to achieve an alignment of 8, the above definition is > wrong; it will no longer have alignment 8 once the bug is fixed. > However I'm not convinced it's the right thing to do. Defining it as 8 > is tightening malloc's contract to always return 8-byte-aligned memory > (note that it presently returns at least 16-byte alignment anyway, but > this is an implementation detail that's not meant to be observable, > not part of the interface contract). I've mentioned earlier that it seems that the only option is to use GCC extensions (i.e. __alignof__) to match their definition of max_align_t, just like it is done in this patch: http://www.openwall.com/lists/musl/2014/04/28/3 It is not nice that GCC forces malloc to support "extended" alignment but I don't think there is much that can be done about it. Pawe=C5=82