mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Paweł Dziepak" <pdziepak@quarnos.org>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [PATCH] add definition of max_align_t to stddef.h
Date: Thu, 8 May 2014 21:45:39 +0200	[thread overview]
Message-ID: <CALS3df3wpr_tL0a16HkphE=B9aWy=FYG8ZRjE5Lyr-agiuk5KA@mail.gmail.com> (raw)
In-Reply-To: <20140508174138.GJ26358@brightrain.aerifal.cx>

2014-05-08 19:41 GMT+02:00 Rich Felker <dalias@libc.org>:
> On Thu, May 08, 2014 at 06:41:19PM +0200, Paweł Dziepak wrote:
>> > 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.
>
> Indeed. This is not an ABI issue with libc.so, but it's an API
> difference that translates into an ABI difference between third-party
> translation units if they use max_align_t as you've described. Whether
> we care, I'm not sure. At least historically there were other cases
> like this in musl where type sizes differed in ways that didn't affect
> libc ABI but did affect ABI between third-party programs (jmp_buf
> comes to mind) but most if not all of these were changed.
>
> I'm not strongly opposed to imposing the 8-byte alignment requirement
> on malloc (it would be hard to make malloc work on smaller granularity
> anyway, and most archs need 8-byte alignment anyway for long long and
> for double) but I generally dislike the inconsistency of defining
> max_align_t in a semi-absurd way on i386, as well as the issue of
> having to use non-portable definitions and/or arch-specific ones.

I agree. The question remains, though, whether the consequences of
defining max_align_t differently are acceptable.

> BTW in your above example, it's not even clear to me if that use of
> alignas is valid. It makes no sense for an object to have an alignment
> that does not divide its type (imagine if you added [2] to the end of
> bar) and in other places (like the contract of aligned_alloc)
> alignments that do not divide the size are explicitly illegal. I'd
> like to understand this before making a decision.

6.7.5 doesn't mention such requirement. _Alignas, obviously, cannot
reduce the alignment requirement and the specified alignment has to
has to be either a valid fundamental alignment or valid extended
alignment supported by the implementation. Moreover, 6.2.8 requires
that valid alignment is a nonnegative integral power of two. As for
the additional requirement in contract of aligned_alloc 7.22.3.1
states that the requested alignment has to be valid and divide size of
the requested memory block. I don't see how that would disallow using
in alignas alignment larger than the size of the object.

Paweł


  parent reply	other threads:[~2014-05-08 19:45 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
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 [this message]
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='CALS3df3wpr_tL0a16HkphE=B9aWy=FYG8ZRjE5Lyr-agiuk5KA@mail.gmail.com' \
    --to=pdziepak@quarnos.org \
    --cc=dalias@libc.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).