mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] add definition of max_align_t to stddef.h
@ 2014-04-30 20:23 Pawel Dziepak
  2014-04-30 21:42 ` Szabolcs Nagy
  0 siblings, 1 reply; 28+ messages in thread
From: Pawel Dziepak @ 2014-04-30 20:23 UTC (permalink / raw)
  To: musl; +Cc: Pawel Dziepak

max_align_t is an object type with the strictest alignment supported by
the implementation in all contexts. An union is used to "choose" the greater
of the two greatest scalar types: long long and long double.

Signed-off-by: Pawel Dziepak <pdziepak@quarnos.org>
---
 include/alltypes.h.in | 2 ++
 include/stddef.h      | 1 +
 2 files changed, 3 insertions(+)

diff --git a/include/alltypes.h.in b/include/alltypes.h.in
index c4ca5d5..ec3873f 100644
--- a/include/alltypes.h.in
+++ b/include/alltypes.h.in
@@ -18,6 +18,8 @@ TYPEDEF unsigned _Int64 uint64_t;
 TYPEDEF unsigned _Int64 u_int64_t;
 TYPEDEF unsigned _Int64 uintmax_t;
 
+TYPEDEF union { long double ld; long long ll; } max_align_t;
+
 TYPEDEF unsigned mode_t;
 TYPEDEF unsigned _Reg nlink_t;
 TYPEDEF _Int64 off_t;
diff --git a/include/stddef.h b/include/stddef.h
index 0a32919..cab34d9 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -7,6 +7,7 @@
 #define NULL ((void*)0)
 #endif
 
+#define __NEED_max_align_t
 #define __NEED_ptrdiff_t
 #define __NEED_size_t
 #define __NEED_wchar_t
-- 
1.9.0



^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: [PATCH] add definition of max_align_t to stddef.h
@ 2014-05-06 10:35 Paweł Dziepak
  2014-05-07  3:13 ` Rich Felker
  0 siblings, 1 reply; 28+ messages in thread
From: Paweł Dziepak @ 2014-05-06 10:35 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Rich Felker wrote:
>On Sun, May 04, 2014 at 04:36:03AM +0200, Paweł Dziepak wrote:
>> 2014-04-30 23:42 GMT+02:00 Szabolcs Nagy <nsz@...t70.net>:
>> > * Pawel Dziepak <pdziepak@...rnos.org> [2014-04-30 22:23:01 +0200]:
>> >>
>> >> +TYPEDEF union { long double ld; long long ll; } max_align_t;
>> >
>> > this is wrong
>> >
>> > - ld and ll identifiers are not reserved for the implementation
>> > (you could name them _ld, _ll or __ld, __ll etc)
>>
>> I will fix that. However, I must admit I don't see why members of the
>> union (or struct) have to use identifiers reserved for the
>> implementation. It's not like they can conflict with anything, isn't
>> it?
>
> #define ll 0
> #include <stddef.h>

Ah, I didn't thought about that. Thanks for clarification.

>> > and see previous max_align_t discussion
>> > http://www.openwall.com/lists/musl/2014/04/28/8
>> >
>> > - compiler implementations are non-conforming on some platforms
>> > (_Alignof returns inconsistent results for the same object type so
>> > reasoning about alignments is problematic, there are exceptions
>> > where this is allowed in c++11 but not in c11)
>> >
>> > - max_align_t is part of the abi and your solution is incompatible
>> > with gcc and clang (your definition gives 4 byte _Alignof(max_align_t)
>> > on i386 instead of 8)
>>
>> The behavior of _Alignof on x86 is indeed quite surprising. I actually
>
> It's also wrong. The correct alignment for max_align_t on i386 is 4,
> not 8. It's a bug that GCC ever returns 8 for alignof on i386. We
> really need to file a bug against GCC and explain this clearly,
> because I have a feeling they're going to be opposed to fixing it...
>
>> don't see why 8 is the right value and 4 isn't - System V ABI for x86
>> doesn't mention any type with alignment 8. Anyway, I agree that it
>
> You're completely right; GCC is wrong.
>
>> 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.

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.

Paweł

PS Please, do not remove me from CC.


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2014-05-08 20:45 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30 20:23 [PATCH] add definition of max_align_t to stddef.h 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
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
2014-05-08 20:02             ` Rich Felker
2014-05-08 20:45               ` Paweł Dziepak

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