This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/3] endian.h: introduce __type3264() macro
- From: Yury Norov <ynorov at caviumnetworks dot com>
- To: <libc-alpha at sourceware dot org>, <joseph at codesourcery dot com>, <schwab at suse dot de>
- Cc: <arnd at arndb dot de>, <catalin dot marinas at arm dot com>, <davem at davemloft dot net>, <szabolcs dot nagy at arm dot com>, <maxim dot kuvyrkov at linaro dot org>, <pinskia at gmail dot com>, <bamvor dot zhangjian at huawei dot com>, <fweimer at redhat dot com>, <Prasun dot Kapoor at cavium dot com>, <adhemerval dot zanella at linaro dot org>, Yury Norov <ynorov at caviumnetworks dot com>
- Date: Thu, 4 Aug 2016 13:02:37 +0300
- Subject: [PATCH 1/3] endian.h: introduce __type3264() macro
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Yuri dot Norov at caviumnetworks dot com;
- References: <1470304959-9944-1-git-send-email-ynorov@caviumnetworks.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
__type3264() declares structure field that has different size
in 32- and 64-bit ABIs with paddings where needed, so final
layout becomes identical. This macro is used in __field64(),
and in next patch of this series to declare struct timestamp
in sysdeps/unix/sysv/linux/generic/bits/stat.h and
sysdeps/unix/sysv/linux/generic/bits/statfs.h
* string/endian.h: introduce __type3264() macro.
* sysdeps/unix/sysv/linux/generic/bits/stat.h: use __type3264() in __field 64().
* sysdeps/unix/sysv/linux/generic/bits/statfs.h: Likewise.
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
string/endian.h | 12 ++++++++++++
sysdeps/unix/sysv/linux/generic/bits/stat.h | 9 ++-------
sysdeps/unix/sysv/linux/generic/bits/statfs.h | 8 +-------
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/string/endian.h b/string/endian.h
index b13ddaa..09fb0dd 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -54,6 +54,18 @@
# define __LONG_LONG_PAIR(HI, LO) HI, LO
#endif
+/* Declare structure field that has different size
+ in 32- and 64-bit ABIs with paddings where needed,
+ so final layout becomes identical. */
+#if __WORDSIZE == 32
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __type3264(type, name) type name __attribute__((__aligned__ (__alignof__ (long long)))); type __##name##_pad
+# else
+# define __type3264(type, name) type __##name##_pad __attribute__((__aligned__ (__alignof__ (long long)))); type name
+# endif
+#else /* __WORDSIZE == 64. */
+# define __type3264(type, name) type name
+#endif
#if defined __USE_MISC && !defined __ASSEMBLER__
/* Conversion interfaces. */
diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
index dd8d799..8e3f745 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -24,6 +24,7 @@
#define _BITS_STAT_H 1
#include <endian.h>
+#include <bits/types.h>
#include <bits/wordsize.h>
/* 64-bit libc uses the kernel's 'struct stat', accessed via the
@@ -42,14 +43,8 @@
#if defined __USE_FILE_OFFSET64
# define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
-# define __field64(type, type64, name) type name
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# define __field64(type, type64, name) \
- type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
#else
-# define __field64(type, type64, name) \
- int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
+# define __field64(type, type64, name) __type3264 (type, name)
#endif
struct stat
diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 7d5aa2d..96629ac 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -34,14 +34,8 @@
#if defined __USE_FILE_OFFSET64
# define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
-# define __field64(type, type64, name) type name
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# define __field64(type, type64, name) \
- type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
#else
-# define __field64(type, type64, name) \
- int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
+# define __field64(type, type64, name) __type3264 (type, name)
#endif
struct statfs
--
2.7.4