public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
From: Chung-Lin Tang <cltang@codesourcery.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>,
	"libc-ports@sourceware.org"	<libc-ports@sourceware.org>,
	Andrew Pinski <pinskia@gmail.com>
Subject: Re: struct statfs/statfs64 in linux-generic
Date: Wed, 13 Nov 2013 08:17:00 -0000	[thread overview]
Message-ID: <5283357D.2050205@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1311111746460.18663@digraph.polyomino.org.uk>

[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]

On 13/11/12 上午1:48, Joseph S. Myers wrote:
> On Sun, 10 Nov 2013, Chung-Lin Tang wrote:
> 
>> I think I found my problem, which is more simpler than I thought: unlike
>> the majority of targets, 64-bit types are 4-byte aligned under Nios II,
>> which causes a 4-byte difference between the glibc/kernel structure
>> definitions because the kernel one doesn't have
>> __attribute__((aligned(8))) forced on to it.
>>
>> Stack alignment is 4-bytes as well in nios2, so I'll probably be
>> maintaining that and using a specific nios2/bits/statfs.h header without
>> the double-word alignment bits.
> 
> Are you sure this is the only place in the kernel/userspace ABI where 
> linux-generic is assuming natural alignment?
> 

generic/bits/stat.h also has use of __attribute__(aligned()), though the
field elements happen to amount to an even number of words, so no such
inconsistency there; just that user code will enforce additional alignment.

The problem I think is the use of the hard coded "8", so instead of
requiring ports like nios2 to possess nearly identical header files
(without the alignment attributes), how about the attached patch that
changes it to use __alignof__(type64) instead?

Thanks,
Chung-Lin

2013-11-13  Chung-Lin Tang  <cltang@codesourcery.com>

	ports/
	* sysdeps/unix/sysv/linux/generic/bits/stat.h (__field64): Use
	__alignof__(type64) in alignment attribute instead of 8.
	* sysdeps/unix/sysv/linux/generic/bits/statfs.h (__field64): Use
	__alignof__(type64) in alignment attribute instead of 8.
	(struct statfs): Use __alignof__(__u64) in alignment attribute
	instead of 8.
	(struct statfs64): Likewise.


[-- Attachment #2: x.diff --]
[-- Type: text/plain, Size: 2069 bytes --]

diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h b/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h
index 6e74cec..feb5f2b 100644
--- a/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -46,10 +46,10 @@
 # define __field64(type, type64, name) type name
 #elif __BYTE_ORDER == __LITTLE_ENDIAN
 # define __field64(type, type64, name) \
-  type name __attribute__((__aligned__(8))); int __##name##_pad
+  type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
 #else
 # define __field64(type, type64, name) \
-  int __##name##_pad __attribute__((__aligned__(8))); type name
+  int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
 #endif
 
 struct stat
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 7063c7a..54edeb5 100644
--- a/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -38,10 +38,10 @@
 # define __field64(type, type64, name) type name
 #elif __BYTE_ORDER == __LITTLE_ENDIAN
 # define __field64(type, type64, name) \
-  type name __attribute__((__aligned__(8))); int __##name##_pad
+  type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
 #else
 # define __field64(type, type64, name) \
-  int __##name##_pad __attribute__((__aligned__(8))); type name
+  int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
 #endif
 
 struct statfs
@@ -58,7 +58,7 @@ struct statfs
     __SWORD_TYPE f_frsize;
     __SWORD_TYPE f_flags;
     __SWORD_TYPE f_spare[4];
-  } __attribute__((__aligned__(8)));
+  } __attribute__((__aligned__ (__alignof__ (__u64))));
 
 #undef __field64
 
@@ -77,7 +77,7 @@ struct statfs64
     __SWORD_TYPE f_frsize;
     __SWORD_TYPE f_flags;
     __SWORD_TYPE f_spare[4];
-  } __attribute__((__aligned__(8)));
+  } __attribute__((__aligned__ (__alignof__ (__u64))));
 #endif
 
 /* Tell code we have these members.  */

  reply	other threads:[~2013-11-13  8:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04  7:18 Chung-Lin Tang
2013-11-04  8:19 ` Andrew Pinski
2013-11-05  4:23   ` Chung-Lin Tang
2013-11-07 19:55 ` Chris Metcalf
2013-11-10  8:24   ` Chung-Lin Tang
2013-11-11 17:48     ` Joseph S. Myers
2013-11-13  8:17       ` Chung-Lin Tang [this message]
2013-11-13 12:59         ` Joseph S. Myers
2013-11-14  4:34           ` Chung-Lin Tang
2013-11-14 13:36             ` Joseph S. Myers
2013-11-14 18:28             ` Chris Metcalf
2013-11-15  7:39               ` Chung-Lin Tang
2013-11-18 23:39                 ` Chris Metcalf
2013-11-19 13:50                   ` Chung-Lin Tang
2013-11-22  2:43                     ` Chris Metcalf

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=5283357D.2050205@codesourcery.com \
    --to=cltang@codesourcery.com \
    --cc=cmetcalf@tilera.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-ports@sourceware.org \
    --cc=pinskia@gmail.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).