[RFC,v1,07/16] RISC-V: Use 64-bit time_t and off_t for RV32 and RV64

Message ID 4b797fc0b4c368e0e42f963a42aaad0c3070d59f.1561177967.git.alistair.francis@wdc.com
State New, archived
Headers

Commit Message

Alistair Francis June 22, 2019, 4:37 a.m. UTC
  Using the original glibc headers under bits/ let's make small
modifications to use 64-bit time_t and off_t for both RV32 and RV64.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 ChangeLog                                     |  4 +
 .../unix/sysv/linux/riscv/bits/environments.h | 85 ++++++++++++++++++
 sysdeps/unix/sysv/linux/riscv/bits/time64.h   | 36 ++++++++
 sysdeps/unix/sysv/linux/riscv/bits/timesize.h | 22 +++++
 .../unix/sysv/linux/riscv/bits/typesizes.h    | 87 +++++++++++++++++++
 5 files changed, 234 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/riscv/bits/environments.h
 create mode 100644 sysdeps/unix/sysv/linux/riscv/bits/time64.h
 create mode 100644 sysdeps/unix/sysv/linux/riscv/bits/timesize.h
 create mode 100644 sysdeps/unix/sysv/linux/riscv/bits/typesizes.h
  

Comments

Arnd Bergmann June 23, 2019, 7:17 p.m. UTC | #1
On Sat, Jun 22, 2019 at 6:47 AM Alistair Francis
<alistair.francis@wdc.com> wrote:

> +#define __SSIZE_T_TYPE     __SWORD_TYPE
> +#define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
> +#define __SYSCALL_ULONG_TYPE __UQUAD_TYPE

Fairly sure you want __SYSCALL_SLONG_TYPE to be __SWORD_TYPE
not __SQUAD_TYPE here. Only x86/x32 is special here.

> +#define __CPU_MASK_TYPE    __UQUAD_TYPE
> +
> +/* Tell the libc code that off_t and off64_t are actually the same type
> +   for all ABI purposes, even if possibly expressed as different base types
> +   for C type-checking purposes.  */
> +# define __OFF_T_MATCHES_OFF64_T 1
> +
> +#ifdef __LP64__
> +/* Same for ino_t and ino64_t.  */
> +# define __INO_T_MATCHES_INO64_T 1
> +
> +/* And for rlim_t and rlim64_t.  */
> +# define __RLIM_T_MATCHES_RLIM64_T  1
> +#else
> +# define __RLIM_T_MATCHES_RLIM64_T  0
> +#endif

However, rlim_t, ino_t and off_t are all 64-bit and match their *64_t
counterparts, so drop the #ifdef here.

      Arnd
  
Alistair Francis June 24, 2019, 11:57 p.m. UTC | #2
On Sun, Jun 23, 2019 at 12:18 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Sat, Jun 22, 2019 at 6:47 AM Alistair Francis
> <alistair.francis@wdc.com> wrote:
>
> > +#define __SSIZE_T_TYPE     __SWORD_TYPE
> > +#define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
> > +#define __SYSCALL_ULONG_TYPE __UQUAD_TYPE
>
> Fairly sure you want __SYSCALL_SLONG_TYPE to be __SWORD_TYPE
> not __SQUAD_TYPE here. Only x86/x32 is special here.

I get some strange compiler errors if I do that, it looks like the
offset into some structures don't line up (I don't have the log handy
unfortunately).

>
> > +#define __CPU_MASK_TYPE    __UQUAD_TYPE
> > +
> > +/* Tell the libc code that off_t and off64_t are actually the same type
> > +   for all ABI purposes, even if possibly expressed as different base types
> > +   for C type-checking purposes.  */
> > +# define __OFF_T_MATCHES_OFF64_T 1
> > +
> > +#ifdef __LP64__
> > +/* Same for ino_t and ino64_t.  */
> > +# define __INO_T_MATCHES_INO64_T 1
> > +
> > +/* And for rlim_t and rlim64_t.  */
> > +# define __RLIM_T_MATCHES_RLIM64_T  1
> > +#else
> > +# define __RLIM_T_MATCHES_RLIM64_T  0
> > +#endif
>
> However, rlim_t, ino_t and off_t are all 64-bit and match their *64_t
> counterparts, so drop the #ifdef here.

Fixed.

Alistair

>
>       Arnd
  

Patch

diff --git a/ChangeLog b/ChangeLog
index 1f1070ebc3..9854fb6df7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@ 
 	* sysdeps/unix/sysv/linux/waitpid.c: Likewise.
 	* sysdeps/unix/sysv/linux/waitpid_nocancel.c: Likewise.
 	* sysdeps/unix/sysv/linux/getrlimit.c: Use __NR_prlimit64 if avaliable
+	* sysdeps/unix/sysv/linux/riscv/bits/environments.h: Use 64-bit time_t and off_t for RV32 and RV64.
+	* sysdeps/unix/sysv/linux/riscv/bits/time64.h: Likewise.
+	* sysdeps/unix/sysv/linux/riscv/bits/timesize.h: Likewise.
+	* sysdeps/unix/sysv/linux/riscv/bits/typesizes.h: Likewise.
 
 2019-06-20  Dmitry V. Levin  <ldv@altlinux.org>
 	    Florian Weimer  <fweimer@redhat.com>
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/environments.h b/sysdeps/unix/sysv/linux/riscv/bits/environments.h
new file mode 100644
index 0000000000..bdbf18fca0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/bits/environments.h
@@ -0,0 +1,85 @@ 
+/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _UNISTD_H
+# error "Never include this file directly.  Use <unistd.h> instead"
+#endif
+
+#include <bits/wordsize.h>
+
+/* This header should define the following symbols under the described
+   situations.  A value `1' means that the model is always supported,
+   `-1' means it is never supported.  Undefined means it cannot be
+   statically decided.
+
+   _POSIX_V7_ILP32_OFF32   32bit int, long, pointers, and off_t type
+   _POSIX_V7_ILP32_OFFBIG  32bit int, long, and pointers and larger off_t type
+
+   _POSIX_V7_LP64_OFF32	   64bit long and pointers and 32bit off_t type
+   _POSIX_V7_LPBIG_OFFBIG  64bit long and pointers and large off_t type
+
+   The macros _POSIX_V6_ILP32_OFF32, _POSIX_V6_ILP32_OFFBIG,
+   _POSIX_V6_LP64_OFF32, _POSIX_V6_LPBIG_OFFBIG, _XBS5_ILP32_OFF32,
+   _XBS5_ILP32_OFFBIG, _XBS5_LP64_OFF32, and _XBS5_LPBIG_OFFBIG were
+   used in previous versions of the Unix standard and are available
+   only for compatibility.
+*/
+
+#if __WORDSIZE == 64
+
+/* We can never provide environments with 32-bit wide pointers.  */
+# define _POSIX_V7_ILP32_OFF32	-1
+# define _POSIX_V7_ILP32_OFFBIG	-1
+# define _POSIX_V6_ILP32_OFF32	-1
+# define _POSIX_V6_ILP32_OFFBIG	-1
+# define _XBS5_ILP32_OFF32	-1
+# define _XBS5_ILP32_OFFBIG	-1
+/* We also have no use (for now) for an environment with bigger pointers
+   and offsets.  */
+# define _POSIX_V7_LPBIG_OFFBIG	-1
+# define _POSIX_V6_LPBIG_OFFBIG	-1
+# define _XBS5_LPBIG_OFFBIG	-1
+
+/* By default we have 64-bit wide `long int', pointers and `off_t'.  */
+# define _POSIX_V7_LP64_OFF64	1
+# define _POSIX_V6_LP64_OFF64	1
+# define _XBS5_LP64_OFF64	1
+
+#else /* __WORDSIZE == 32 */
+
+/* RISC-V requires 64-bit off_t
+  # undef _POSIX_V7_ILP32_OFF32
+  # undef _POSIX_V6_ILP32_OFF32
+  # undef _XBS5_ILP32_OFF32
+ */
+
+# define _POSIX_V7_ILP32_OFFBIG  1
+# define _POSIX_V6_ILP32_OFFBIG  1
+# define _XBS5_ILP32_OFFBIG   1
+
+/* We can never provide environments with 64-bit wide pointers.  */
+# define _POSIX_V7_LP64_OFF64	-1
+# define _POSIX_V7_LPBIG_OFFBIG	-1
+# define _POSIX_V6_LP64_OFF64	-1
+# define _POSIX_V6_LPBIG_OFFBIG	-1
+# define _XBS5_LP64_OFF64	-1
+# define _XBS5_LPBIG_OFFBIG	-1
+
+/* CFLAGS.  */
+#define __ILP32_OFFBIG_CFLAGS   "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+
+#endif /* __WORDSIZE == 32 */
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/time64.h b/sysdeps/unix/sysv/linux/riscv/bits/time64.h
new file mode 100644
index 0000000000..4be26d32d4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/bits/time64.h
@@ -0,0 +1,36 @@ 
+/* bits/time64.h -- underlying types for __time64_t.  Generic version.
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <bits/time64.h> directly; use <sys/types.h> instead."
+#endif
+
+#ifndef	_BITS_TIME64_H
+#define	_BITS_TIME64_H	1
+
+/* Define __TIME64_T_TYPE so that it is always a 64-bit type.  */
+
+#if __WORDSIZE == 64
+/* If we already have 64-bit time type then use it.  */
+# define __TIME64_T_TYPE		__TIME_T_TYPE
+#else
+/* Define a 64-bit time type alongsize the 32-bit one.  */
+# define __TIME64_T_TYPE		__SQUAD_TYPE
+#endif
+
+#endif /* bits/time64.h */
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/timesize.h b/sysdeps/unix/sysv/linux/riscv/bits/timesize.h
new file mode 100644
index 0000000000..150af80f86
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/bits/timesize.h
@@ -0,0 +1,22 @@ 
+/* Bit size of the time_t type at glibc build time, general case.
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <bits/wordsize.h>
+
+/* RV32 and RV64 both use 64-bit time_t */
+#define __TIMESIZE	64
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/typesizes.h b/sysdeps/unix/sysv/linux/riscv/bits/typesizes.h
new file mode 100644
index 0000000000..f0dda3d841
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/bits/typesizes.h
@@ -0,0 +1,87 @@ 
+/* bits/typesizes.h -- underlying types for *_t.  Generic version.
+   Copyright (C) 2002-2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_TYPES_H
+# error "Never include <bits/typesizes.h> directly; use <sys/types.h> instead."
+#endif
+
+#ifndef	_BITS_TYPESIZES_H
+#define	_BITS_TYPESIZES_H	1
+
+/* See <bits/types.h> for the meaning of these macros.  This file exists so
+   that <bits/types.h> need not vary across different GNU platforms.  */
+
+
+
+#define __DEV_T_TYPE    __UQUAD_TYPE
+#define __UID_T_TYPE    __U32_TYPE
+#define __GID_T_TYPE    __U32_TYPE
+#define __INO_T_TYPE    __UQUAD_TYPE
+#define __INO64_T_TYPE     __UQUAD_TYPE
+#define __MODE_T_TYPE      __U32_TYPE
+#define __NLINK_T_TYPE    __UQUAD_TYPE
+
+#define __OFF_T_TYPE    __SQUAD_TYPE
+#define __OFF64_T_TYPE     __SQUAD_TYPE
+#define __PID_T_TYPE    __S32_TYPE
+#define __RLIM_T_TYPE      __UQUAD_TYPE
+#define __RLIM64_T_TYPE    __UQUAD_TYPE
+#define __BLKCNT_T_TYPE    __SQUAD_TYPE
+#define __BLKCNT64_T_TYPE  __SQUAD_TYPE
+#define __FSBLKCNT_T_TYPE  __UQUAD_TYPE
+#define __FSBLKCNT64_T_TYPE   __UQUAD_TYPE
+#define __FSFILCNT_T_TYPE  __UQUAD_TYPE
+#define __FSFILCNT64_T_TYPE   __UQUAD_TYPE
+#define __FSWORD_T_TYPE   __SQUAD_TYPE
+
+#define __ID_T_TYPE     __U32_TYPE
+#define __CLOCK_T_TYPE     __SQUAD_TYPE
+#define __TIME_T_TYPE      __SQUAD_TYPE
+#define __USECONDS_T_TYPE  __U32_TYPE
+#define __SUSECONDS_T_TYPE __SQUAD_TYPE
+#define __DADDR_T_TYPE     __S32_TYPE
+#define __KEY_T_TYPE    __S32_TYPE
+#define __CLOCKID_T_TYPE   __S32_TYPE
+#define __TIMER_T_TYPE     void *
+#define __BLKSIZE_T_TYPE   __SQUAD_TYPE
+#define __FSID_T_TYPE      struct { int __val[2]; }
+#define __SSIZE_T_TYPE     __SWORD_TYPE
+#define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
+#define __SYSCALL_ULONG_TYPE __UQUAD_TYPE
+#define __CPU_MASK_TYPE    __UQUAD_TYPE
+
+/* Tell the libc code that off_t and off64_t are actually the same type
+   for all ABI purposes, even if possibly expressed as different base types
+   for C type-checking purposes.  */
+# define __OFF_T_MATCHES_OFF64_T 1
+
+#ifdef __LP64__
+/* Same for ino_t and ino64_t.  */
+# define __INO_T_MATCHES_INO64_T 1
+
+/* And for rlim_t and rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T  1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T  0
+#endif
+
+/* Number of descriptors that can fit in an `fd_set'.  */
+#define	__FD_SETSIZE		1024
+
+
+#endif /* bits/typesizes.h */