From: "Paweł Dziepak" <pdziepak@quarnos.org>
To: musl@lists.openwall.com
Cc: Pawel Dziepak <pdziepak@quarnos.org>
Subject: Re: [PATCH] add definition of max_align_t to stddef.h
Date: Wed, 7 May 2014 11:28:58 +0200 [thread overview]
Message-ID: <CALS3df1_+E30JX-e_ig1qv13o_uzvN=9qJfVq1Qi7JjYopGQ9w@mail.gmail.com> (raw)
In-Reply-To: <20140507031306.GA26963@brightrain.aerifal.cx>
2014-05-07 5:13 GMT+02:00 Rich Felker <dalias@libc.org>:
> On Tue, May 06, 2014 at 12:35:55PM +0200, Paweł 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 <=4 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=61053
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ł
next prev parent reply other threads:[~2014-05-07 9:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 10:35 Paweł Dziepak
2014-05-07 3:13 ` Rich Felker
2014-05-07 4:14 ` Luca Barbato
2014-05-07 4:29 ` Rich Felker
2014-05-07 5:12 ` Luca Barbato
2014-05-07 22:48 ` Rich Felker
2014-05-08 12:07 ` Luca Barbato
2014-05-08 14:25 ` Rich Felker
2014-05-07 9:28 ` Paweł Dziepak [this message]
2014-05-07 23:07 ` Rich Felker
2014-05-08 10:57 ` Szabolcs Nagy
2014-05-08 14:11 ` Rich Felker
2014-05-08 16:41 ` Paweł Dziepak
2014-05-08 17:41 ` Rich Felker
2014-05-08 18:45 ` Jens Gustedt
2014-05-08 19:11 ` Paweł Dziepak
2014-05-08 19:22 ` Jens Gustedt
2014-05-08 19:45 ` Paweł Dziepak
2014-05-08 20:02 ` Rich Felker
2014-05-08 20:45 ` Paweł Dziepak
-- strict thread matches above, loose matches on Subject: below --
2014-04-30 20:23 Pawel Dziepak
2014-04-30 21:42 ` Szabolcs Nagy
2014-04-30 22:43 ` Rich Felker
2014-05-04 2:52 ` Paweł Dziepak
2014-05-04 11:42 ` Paweł Dziepak
2014-05-07 5:02 ` Jens Gustedt
2014-05-04 2:36 ` Paweł Dziepak
2014-05-04 5:02 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALS3df1_+E30JX-e_ig1qv13o_uzvN=9qJfVq1Qi7JjYopGQ9w@mail.gmail.com' \
--to=pdziepak@quarnos.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).