[v2,1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts

Message ID 20190925003114.21546-1-alistair.francis@wdc.com
State New, archived
Headers

Commit Message

Alistair Francis Sept. 25, 2019, 12:31 a.m. UTC
  On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T
defined) we want to update the stat struct to remove the padding as it
isn't required. As we don't have the padding we also need to update the
overflow checker to not access the undefined members.

2019-09-16  Alistair Francis  <alistair.francis@wdc.com>

	* sysdeps/unix/sysv/linux/generic/bits/stat.h: Handle 64-bit ino_t types
	on 32-bit hosts.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
---
This change was tested by running user space tests for RV32 and RV64.

v2:
 - Change to if defined instead of if == 1

 sysdeps/unix/sysv/linux/generic/bits/stat.h            | 5 ++++-
 sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)
  

Comments

Andreas Schwab Sept. 25, 2019, 7:39 a.m. UTC | #1
On Sep 24 2019, Alistair Francis <alistair.francis@wdc.com> wrote:

> diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> index 1565f3f8248..e580071d26c 100644
> --- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
> +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> @@ -40,7 +40,10 @@
>  /* Versions of the `xmknod' interface.  */
>  #define _MKNOD_VER_LINUX	0
>  
> -#if defined __USE_FILE_OFFSET64
> +#if defined (__USE_FILE_OFFSET64) || defined (__INO_T_MATCHES_INO64_T)
> +# if defined (__INO_T_MATCHES_INO64_T) && !defined (__OFF_T_MATCHES_OFF64_T)

Our style is to omit the parens after defined.

Andreas.
  
Alistair Francis Sept. 25, 2019, 10:52 p.m. UTC | #2
On Wed, Sep 25, 2019 at 12:39 AM Andreas Schwab <schwab@suse.de> wrote:
>
> On Sep 24 2019, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> > diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> > index 1565f3f8248..e580071d26c 100644
> > --- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
> > +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> > @@ -40,7 +40,10 @@
> >  /* Versions of the `xmknod' interface.  */
> >  #define _MKNOD_VER_LINUX     0
> >
> > -#if defined __USE_FILE_OFFSET64
> > +#if defined (__USE_FILE_OFFSET64) || defined (__INO_T_MATCHES_INO64_T)
> > +# if defined (__INO_T_MATCHES_INO64_T) && !defined (__OFF_T_MATCHES_OFF64_T)
>
> Our style is to omit the parens after defined.

Fixed in v3.

Alistair

>
> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
  

Patch

diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
index 1565f3f8248..e580071d26c 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -40,7 +40,10 @@ 
 /* Versions of the `xmknod' interface.  */
 #define _MKNOD_VER_LINUX	0
 
-#if defined __USE_FILE_OFFSET64
+#if defined (__USE_FILE_OFFSET64) || defined (__INO_T_MATCHES_INO64_T)
+# if defined (__INO_T_MATCHES_INO64_T) && !defined (__OFF_T_MATCHES_OFF64_T)
+#  error "ino_t and off_t must both be the same type"
+# endif
 # define __field64(type, type64, name) type64 name
 #elif __WORDSIZE == 64
 # define __field64(type, type64, name) type name
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
index 45efcd8fd34..3c21da501b2 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
@@ -36,12 +36,16 @@  static inline off_t lseek_overflow (loff_t res)
 
 static inline int stat_overflow (struct stat *buf)
 {
+#if defined (__INO_T_MATCHES_INO64_T)
+  return 0;
+#else
   if (buf->__st_ino_pad == 0 && buf->__st_size_pad == 0
       && buf->__st_blocks_pad == 0)
     return 0;
 
   __set_errno (EOVERFLOW);
   return -1;
+#endif
 }
 
 /* Note that f_files and f_ffree may validly be a sign-extended -1.  */