[v3,1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
Commit Message
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.
* 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.
---
v3:
- Don't use brackets around the defined
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
On Thu, 3 Oct 2019, Alistair Francis wrote:
> diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> index 1565f3f8248..0c1850322be 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
Logically it feels like this actually should be added to the __WORDSIZE ==
64 case rather than the __USE_FILE_OFFSET64, so that the type names such
as __ino_t get used to define the fields rather than those such as
__ino64_t. (If that makes a difference to anything in practice, it should
just be to what typedef name debug info says was used to declare the
fields.)
There are actually three types involved, not two. If there's no other
place that needs to check whether blkcnt_t and blkcnt64_t match and so
needs a macro for that, I suppose some convenient .c file in linux/generic
could do
#if __INO_T_MATCHES_INO64_T
_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),
"__blkcnt_t and __blkcnt64_t must match");
#endif
to make sure the build fails if anyone tries to create a broken
configuration where some types match but not others.
@@ -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
@@ -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. */