This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: sparc 32-bit dirent broken
- From: David Miller <davem at davemloft dot net>
- To: roland at hack dot frob dot com
- Cc: fweimer at redhat dot com, libc-alpha at sourceware dot org
- Date: Fri, 11 Oct 2013 01:33:55 -0400 (EDT)
- Subject: Re: sparc 32-bit dirent broken
- Authentication-results: sourceware.org; auth=none
- References: <20131010 dot 170628 dot 144428253182134045 dot davem at davemloft dot net> <20131010 dot 171716 dot 69341787771640099 dot davem at davemloft dot net> <20131010224837 dot 458872C05D at topped-with-meat dot com>
From: Roland McGrath <roland@hack.frob.com>
Date: Thu, 10 Oct 2013 15:48:37 -0700 (PDT)
> In the malloc code (which has the interface mandate of knowing "largest C
> base type alignment"), we use __alignof (long double), encoding the
> assumption that long double is the most-aligned C type. It would be
> consistent and adequate to use __alignof (long double) in dirstream.h too
> (with a clear comment about why it matters).
Ok, with that in mind I've committed the patch below
> But it would indeed be cleaner to have some sysdeps header that
> defines a macro that's explicitly for "largest C base type
> alignment". The sysdeps/generic definition can use __alignof (long
> double), and there might never be a need for a different version
> (that being the case, you could start by just putting the macro into
> include/libc-internal.h and using it in both malloc.c and
> dirstream.h; if a different definition is ever actually needed, we
> can sysdepsize it then).
Ok, I'll look into a cleaner way to do this tree wide.
====================
[PATCH] Fix readdir regressions on sparc 32-bit.
* sysdeps/posix/dirstream.h (struct __dirstream): Fix alignment of
directory block.
---
ChangeLog | 5 +++++
sysdeps/posix/dirstream.h | 9 +++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fdc2f0b..5d99bd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-10-10 David S. Miller <davem@davemloft.net>
+
+ * sysdeps/posix/dirstream.h (struct __dirstream): Fix alignment of
+ directory block.
+
2013-10-10 Joseph Myers <joseph@codesourcery.com>
* soft-fp/extendxftf2.c: Use copyright year range. Use URL
diff --git a/sysdeps/posix/dirstream.h b/sysdeps/posix/dirstream.h
index 8e8570d..be20895 100644
--- a/sysdeps/posix/dirstream.h
+++ b/sysdeps/posix/dirstream.h
@@ -41,8 +41,13 @@ struct __dirstream
int errcode; /* Delayed error code. */
- /* Directory block. */
- char data[0] __attribute__ ((aligned (__alignof__ (void*))));
+ /* Directory block. We must make sure that this block starts
+ at an address that is aligned adequately enough to store
+ dirent entries. Using the alignment of "void *" is not
+ sufficient because dirents on 32-bit platforms can require
+ 64-bit alignment. We use "long double" here to be consistent
+ with what malloc uses. */
+ char data[0] __attribute__ ((aligned (__alignof__ (long double))));
};
#define _DIR_dirfd(dirp) ((dirp)->fd)
--
1.8.1.2