This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] Fix struct stat* (was Re: attribute(packed) in struct stat is wrong)


Hi!

On Thu, Feb 07, 2002 at 01:34:57PM +0100, Andreas Jaeger wrote:
> 
> With current CVS I get:
> 
> GCONV_PATH=/builds/glibc/gcc-3.1/iconvdata LC_ALL=C   /builds/glibc/gcc-3.1/elf/ld-linux.so.2 --library-path /builds/glibc/gcc-3.1:/builds/glibc/gcc-3.1/math:/builds/glibc/gcc-3.1/elf:/builds/glibc/gcc-3.1/dlfcn:/builds/glibc/gcc-3.1/nss:/builds/glibc/gcc-3.1/nis:/builds/glibc/gcc-3.1/rt:/builds/glibc/gcc-3.1/resolv:/builds/glibc/gcc-3.1/crypt:/builds/glibc/gcc-3.1/linuxthreads /builds/glibc/gcc-3.1/io/test-stat  > /builds/glibc/gcc-3.1/io/test-stat.out
> test-stat: test-stat.c:35: main: Assertion `sizeof (struct stat) == sizeof (struct stat64)' failed.
> 
> Removing the assertions gives:
> test-stat: test-stat.c:39: main: Assertion `((size_t) &((struct stat *)0)->st_ino) == ((size_t) &((struct stat64 *)0)->st_ino)' failed.

Here is a fix for this. I don't think we need to add attribute packed if the
structures are already properly packed (which they were not on IA-32, fixed
below).
I've tested this with all combinations of nothing/-fpack-struct and
nothing/-D_FILE_OFFSET_BITS=64 and in all cases the structures have 88 bytes
resp. 96 bytes as they used to (unless -fpack-struct was given).
arm/cris/hppa/sh maintainers should probably check whether the patch doesn't
make any difference on their arches, but I think just m68k doesn't align
32-bit value to 32-bits.

2002-02-07  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/bits/stat.h (struct stat): Remove packed
	attribute, change __pad{1,2} type to unsigned int.
	(struct stat64): Remove packed attribute.

--- libc/sysdeps/unix/sysv/linux/bits/stat.h.jj	Thu Feb  7 15:10:47 2002
+++ libc/sysdeps/unix/sysv/linux/bits/stat.h	Thu Feb  7 15:16:53 2002
@@ -36,7 +36,7 @@
 struct stat
   {
     __dev_t st_dev;			/* Device.  */
-    unsigned short int __pad1;
+    unsigned int __pad1;
 #ifndef __USE_FILE_OFFSET64
     __ino_t st_ino;			/* File serial number.	*/
 #else
@@ -47,7 +47,7 @@ struct stat
     __uid_t st_uid;			/* User ID of the file's owner.	*/
     __gid_t st_gid;			/* Group ID of the file's group.*/
     __dev_t st_rdev;			/* Device number, if device.  */
-    unsigned short int __pad2;
+    unsigned int __pad2;
 #ifndef __USE_FILE_OFFSET64
     __off_t st_size;			/* Size of file, in bytes.  */
 #else
@@ -72,7 +72,7 @@ struct stat
 #else
     __ino64_t st_ino;			/* File serial number.	*/
 #endif
-  } __attribute__ ((__packed__));
+  };
 
 #ifdef __USE_LARGEFILE64
 struct stat64
@@ -98,7 +98,7 @@ struct stat64
     __time_t st_ctime;			/* Time of last status change.  */
     unsigned long int __unused3;
     __ino64_t st_ino;			/* File serial number.		*/
-  } __attribute__ ((__packed__));
+  };
 #endif
 
 /* Tell code we have these members.  */


	Jakub


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