Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 8 May 2014 18:41:19 +0200
From: Paweł Dziepak <pdziepak@...rnos.org>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] add definition of max_align_t to stddef.h

2014-05-08 1:07 GMT+02:00 Rich Felker <dalias@...c.org>:
> On Wed, May 07, 2014 at 11:28:58AM +0200, Paweł Dziepak wrote:
>> 2014-05-07 5:13 GMT+02:00 Rich Felker <dalias@...c.org>:
>> > On Tue, May 06, 2014 at 12:35:55PM +0200, Paweł Dziepak wrote:
>> >> 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.
>
> I don't see how GCC "forces" this. The definition of max_align_t from
> glibc's stddef.h, which we do not use, is what forces it.

It is GCC that provides stddef.h, not glibc.

> As I see it, we have a choice whether to use the "8" definition on
> i386 or use the natural definition, which would yield "4" on i386.
> This is not an ABI issue (it does not affect the ability to use
> glibc-built object files/binaries/shared libraries with musl, nor the
> C++ name mangling ABI) but an API issue.

What about something like this?

struct foobar {
    char foo;
    alignas(max_align_t) char bar;
};

The binary representation of this structure depends on the definition
of max_align_t and binaries compiled with different
alignof(max_align_t) won't be compatible.

Paweł

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.