This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Define libc_max_align_t


On 04/02/2015 09:38 AM, Andreas Schwab wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> 
>> On 04/02/2015 12:01 AM, Andreas Schwab wrote:
>>> Florian Weimer <fweimer@redhat.com> writes:
>>>
>>>> +/* This mirrors the C11 max_align_t type provided by GCC, but it is
>>>> +   also available in C99 mode.  */
>>>> +typedef struct {
>>>> +  long long ll __attribute__ ((__aligned__ (__alignof__ (long long))));
>>>> +  long double ld __attribute__ ((__aligned__ (__alignof__ (long double))));
>>>> +} libc_max_align_t;
>>>
>>> Why aren't the attributes no-ops?
>>
>> Quoting Joseph:
>>
>> âThe attributes there are because some targets may give types lower
>> alignment inside structures and unions than outside; 32-bit x86 in
>> particular.â
> 
> This should probably be added to the comment.

Well, the GCC folks thought it wasn't necessary, but I agree that a
comment cannot hurt.

Is this okay?

-- 
Florian Weimer / Red Hat Product Security
>From 1d39ccadab8f2c11ac54242c9faaf0396f760c15 Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Thu, 2 Apr 2015 10:07:04 +0200
Subject: [PATCH] Define libc_max_align_t for internal use

---
 ChangeLog               | 4 ++++
 include/libc-internal.h | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index c687d13..b0a48ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-04-02  Florian Weimer  <fweimer@redhat.com>
+
+	* include/libc-internal.h (libc_max_align_t): Define.
+
 2015-04-02  Mel Gorman  <mgorman@suse.de>
 
 	[BZ #17195]
diff --git a/include/libc-internal.h b/include/libc-internal.h
index bca59a4..b37388e 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -107,4 +107,13 @@ extern void __init_misc (int, char **, char **);
 #define DIAG_IGNORE_NEEDS_COMMENT(version, option)	\
   _Pragma (_DIAG_STR (GCC diagnostic ignored option))
 
+/* This mirrors the C11 max_align_t type provided by GCC, but it is
+   also available in C99 mode.  The aligned attributes are required
+   because some ABIs have reduced alignment requirements for struct
+   and union members.  */
+typedef struct {
+  long long ll __attribute__ ((__aligned__ (__alignof__ (long long))));
+  long double ld __attribute__ ((__aligned__ (__alignof__ (long double))));
+} libc_max_align_t;
+
 #endif /* _LIBC_INTERNAL  */
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]