Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 6 May 2014 23:13:06 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] add definition of max_align_t to stddef.h

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.

> 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).

Rich

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.