public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Define wordsize.h macros everywhere
@ 2016-10-26 18:34 Steve Ellcey
  2016-10-26 19:39 ` Steve Ellcey
  2016-10-26 20:07 ` Joseph Myers
  0 siblings, 2 replies; 10+ messages in thread
From: Steve Ellcey @ 2016-10-26 18:34 UTC (permalink / raw)
  To: libc-alpha; +Cc: ynorov

This patch is based on an earlier patch Yury Norov sent out.
That patch is at:

	https://sourceware.org/ml/libc-alpha/2016-08/msg00840.html

This patch defines __WORDSIZE32_SIZE_ULONG, __WORDSIZE_TIME64_COMPAT32,
and __SYSCALL_WORDSIZE in all the wordsize.h files so that the values
of those macros can be checked instead of checking to see if they
are defined or not.  This matches the current glibc macro usage
preference as I understand it.  The patch also introduces a new macro,
__WORDSIZE32_PTRDIFF_LONG, that is needed by the aarch64 ILP32 ABI that
is in the works.  This macro doesn't technically have to be part of
this patch since the rest of the ILP32 work is not in yet but since it
touches the same wordsize.h files that the other macros touch it seems
to make sense to include it in this patch.  That way we will not have
to modify these files again as part of the aarch64 ILP patches.  I also
updated the comments that Yury had added to bits/wordsize.h in response
to earlier feedback.

I have tested this patch on x86_64 in 32, x32 and 64 bit modes and on
aarch64 with no regressions.

OK to checkin?

Steve Ellcey
sellcey@caviiumnetworks.com


2016-10-24  Yury Norov  <ynorov@caviumnetworks.com>
	    Steve Ellcey <sellcey@caviumnetworks.com>

	* bits/wordsize.h: Add documentation.
	* sysdeps/aarch64/bits/wordsize.h : New file
	* sysdeps/generic/stdint.h (PTRDIFF_MIN, PTRDIFF_MAX): Update
	definitions.
	(SIZE_MAX): Change ifdef to if in __WORDSIZE32_SIZE_ULONG check.
	* sysdeps/gnu/bits/utmp.h (__WORDSIZE_TIME64_COMPAT32): Check
	with #if instead of #ifdef.
	* sysdeps/gnu/bits/utmpx.h (__WORDSIZE_TIME64_COMPAT32): Ditto.
	* sysdeps/unix/sysv/linux/bits/statvfs.h (_STATVFSBUF_F_UNUSED):
	Change check to assume __SYSCALL_WORDSIZE is set.
	* sysdeps/mips/bits/wordsize.h (__SYSCALL_WORDSIZE,
	__WORDSIZE32_SIZE_ULONG, __WORDSIZE32_PTRDIFF_LONG,
	__WORDSIZE_TIME64_COMPAT32): Add or change defines.
	* sysdeps/powerpc/powerpc32/bits/wordsize.h: Likewise.
	* sysdeps/powerpc/powerpc64/bits/wordsize.h: Likewise.
	* sysdeps/s390/s390-32/bits/wordsize.h: Likewise.
	* sysdeps/s390/s390-64/bits/wordsize.h: Likewise.
	* sysdeps/sparc/sparc32/bits/wordsize.h: Likewise.
	* sysdeps/sparc/sparc64/bits/wordsize.h: Likewise.
	* sysdeps/tile/tilegx/bits/wordsize.h: Likewise.
	* sysdeps/tile/tilepro/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/alpha/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/wordsize.h: Likewise.
	* sysdeps/wordsize-32/bits/wordsize.h: Likewise.
	* sysdeps/wordsize-64/bits/wordsize.h: Likewise.
	* sysdeps/x86/bits/wordsize.h: Likewise.


diff --git a/bits/wordsize.h b/bits/wordsize.h
index 9ef0e85..2ebecd6 100644
--- a/bits/wordsize.h
+++ b/bits/wordsize.h
@@ -1 +1,28 @@
 #error "This file must be written based on the data type sizes of the target"
+
+/* The following entries are a template for what defines should be in the
+   wordsize.h header file for a target.  */
+
+/* Bits per word (size of CPU register).  */
+#define __WORDSIZE
+
+/* Set to the size of the f_fsid field in the statvfs and statvfs64 structs.
+   In most cases this is the same as __WORDSIZE but some 32 bit hosts may set
+   it to 64.  */
+#define __SYSCALL_WORDSIZE
+
+/* Set to 1 if ssize_t is type 'unsigned long' instead of type 'unsigned int'
+   so that SIZE_MAX is defined as an unsigned long constant instead of an
+   unsigned int constant.  Set to 0 if ssize_t is 'unsigned int'.  */
+#define __WORDSIZE32_SIZE_ULONG
+
+/* Set to 1 if ptrdiff_t is type 'long' instead of type 'int' so that
+   PTRDIFF_MIN and PTRDIFF_MAX are defined as long constants instead of
+   int constants.  Set to 0 if ptrdiff_t is type 'int'.  */
+#define __WORDSIZE32_PTRDIFF_LONG
+
+/* Set to 1 in order to force time types to be 32 bits instead of 64 bits in
+   struct lastlog and struct utmp{,x} on 64-bit ports.  This may be done in
+   order to make 64-bit ports compatible with 32-bit ports.  Set to 0 for
+   64-bit ports where the time types are 64-bits or for any 32-bit ports.  */
+#define __WORDSIZE_TIME64_COMPAT32
diff --git a/sysdeps/aarch64/bits/wordsize.h b/sysdeps/aarch64/bits/wordsize.h
index e69de29..c907986 100644
--- a/sysdeps/aarch64/bits/wordsize.h
+++ b/sysdeps/aarch64/bits/wordsize.h
@@ -0,0 +1,31 @@
+/* Determine the wordsize from the preprocessor defines.
+
+   Copyright (C) 2016 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
+   &lt;<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.  */
+
+#ifdef __LP64__
+# define __WORDSIZE			64
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
+#else
+# define __WORDSIZE			32
+# define __WORDSIZE32_SIZE_ULONG	1
+# define __WORDSIZE32_PTRDIFF_LONG	1
+#endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/generic/stdint.h b/sysdeps/generic/stdint.h
index 5428dbc..8e4347c 100644
--- a/sysdeps/generic/stdint.h
+++ b/sysdeps/generic/stdint.h
@@ -249,8 +249,13 @@ typedef unsigned long long int	uintmax_t;
 #  define PTRDIFF_MIN		(-9223372036854775807L-1)
 #  define PTRDIFF_MAX		(9223372036854775807L)
 # else
-#  define PTRDIFF_MIN		(-2147483647-1)
-#  define PTRDIFF_MAX		(2147483647)
+#  if __WORDSIZE32_PTRDIFF_LONG
+#   define PTRDIFF_MIN		(-2147483647L-1)
+#   define PTRDIFF_MAX		(2147483647L)
+#  else
+#   define PTRDIFF_MIN		(-2147483647-1)
+#   define PTRDIFF_MAX		(2147483647)
+#  endif
 # endif
 
 /* Limits of `sig_atomic_t'.  */
@@ -261,7 +266,7 @@ typedef unsigned long long int	uintmax_t;
 # if __WORDSIZE == 64
 #  define SIZE_MAX		(18446744073709551615UL)
 # else
-#  ifdef __WORDSIZE32_SIZE_ULONG
+#  if __WORDSIZE32_SIZE_ULONG
 #   define SIZE_MAX		(4294967295UL)
 #  else
 #   define SIZE_MAX		(4294967295U)
diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/gnu/bits/utmp.h
index 2a1ffcb..bce1a7b 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/sysdeps/gnu/bits/utmp.h
@@ -35,7 +35,7 @@
    previous logins.  */
 struct lastlog
   {
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
     int32_t ll_time;
 #else
     __time_t ll_time;
@@ -68,7 +68,7 @@ struct utmp
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
    shared between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/gnu/bits/utmpx.h b/sysdeps/gnu/bits/utmpx.h
index b41548b..a438660 100644
--- a/sysdeps/gnu/bits/utmpx.h
+++ b/sysdeps/gnu/bits/utmpx.h
@@ -66,7 +66,7 @@ struct utmpx
 /* The fields ut_session and ut_tv must be the same size when compiled
    32- and 64-bit.  This allows files and shared memory to be shared
    between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/mips/bits/wordsize.h b/sysdeps/mips/bits/wordsize.h
index bc90435..6d476ba 100644
--- a/sysdeps/mips/bits/wordsize.h
+++ b/sysdeps/mips/bits/wordsize.h
@@ -17,7 +17,13 @@
 
 #include <sgidefs.h>
 
-#define __WORDSIZE	_MIPS_SZPTR
+#define __WORDSIZE			_MIPS_SZPTR
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if _MIPS_SIM == _ABI64
 # define __WORDSIZE_TIME64_COMPAT32	1
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
diff --git a/sysdeps/powerpc/powerpc32/bits/wordsize.h b/sysdeps/powerpc/powerpc32/bits/wordsize.h
index f31ac9a..f08ab26 100644
--- a/sysdeps/powerpc/powerpc32/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc32/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/powerpc/powerpc64/bits/wordsize.h b/sysdeps/powerpc/powerpc64/bits/wordsize.h
index f31ac9a..f08ab26 100644
--- a/sysdeps/powerpc/powerpc64/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc64/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/s390/s390-32/bits/wordsize.h b/sysdeps/s390/s390-32/bits/wordsize.h
index da791fa..7ac7e6b 100644
--- a/sysdeps/s390/s390-32/bits/wordsize.h
+++ b/sysdeps/s390/s390-32/bits/wordsize.h
@@ -2,11 +2,16 @@
 
 #if defined __s390x__
 # define __WORDSIZE	64
+# define __WORDSIZE32_SIZE_ULONG       0
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_PTRDIFF_LONG      0
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/s390/s390-64/bits/wordsize.h b/sysdeps/s390/s390-64/bits/wordsize.h
index da791fa..7ac7e6b 100644
--- a/sysdeps/s390/s390-64/bits/wordsize.h
+++ b/sysdeps/s390/s390-64/bits/wordsize.h
@@ -2,11 +2,16 @@
 
 #if defined __s390x__
 # define __WORDSIZE	64
+# define __WORDSIZE32_SIZE_ULONG       0
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_PTRDIFF_LONG      0
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/sparc/sparc32/bits/wordsize.h b/sysdeps/sparc/sparc32/bits/wordsize.h
index d8fd1a5..73a3b7c 100644
--- a/sysdeps/sparc/sparc32/bits/wordsize.h
+++ b/sysdeps/sparc/sparc32/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/sparc/sparc64/bits/wordsize.h b/sysdeps/sparc/sparc64/bits/wordsize.h
index d8fd1a5..73a3b7c 100644
--- a/sysdeps/sparc/sparc64/bits/wordsize.h
+++ b/sysdeps/sparc/sparc64/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/tile/tilegx/bits/wordsize.h b/sysdeps/tile/tilegx/bits/wordsize.h
index 5d4e4b4..f5db53a 100644
--- a/sysdeps/tile/tilegx/bits/wordsize.h
+++ b/sysdeps/tile/tilegx/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/tile/tilepro/bits/wordsize.h b/sysdeps/tile/tilepro/bits/wordsize.h
index da587a2..e1f21c9 100644
--- a/sysdeps/tile/tilepro/bits/wordsize.h
+++ b/sysdeps/tile/tilepro/bits/wordsize.h
@@ -1,3 +1,7 @@
 /* Determine the wordsize from the preprocessor defines.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
index 51fc433..e1a3cdb 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
@@ -16,6 +16,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define __WORDSIZE	64
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
diff --git a/sysdeps/unix/sysv/linux/bits/statvfs.h b/sysdeps/unix/sysv/linux/bits/statvfs.h
index 9244401..fcdd2cd 100644
--- a/sysdeps/unix/sysv/linux/bits/statvfs.h
+++ b/sysdeps/unix/sysv/linux/bits/statvfs.h
@@ -21,8 +21,7 @@
 
 #include <bits/types.h>  /* For __fsblkcnt_t and __fsfilcnt_t.  */
 
-#if (__WORDSIZE == 32 \
-     && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
+#if (__WORDSIZE == 32 && __SYSCALL_WORDSIZE == 32)
 #define _STATVFSBUF_F_UNUSED
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
index 3e8a1e0..aaec974 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
@@ -5,8 +5,13 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal the glibc ABI didn't used to have a `long double'.
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
index 2d958d2..5df97ab 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
@@ -6,6 +6,11 @@
 # define __WORDSIZE	32
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 # if __WORDSIZE == 32
diff --git a/sysdeps/wordsize-32/bits/wordsize.h b/sysdeps/wordsize-32/bits/wordsize.h
index 2aa16bc..3454d7f 100644
--- a/sysdeps/wordsize-32/bits/wordsize.h
+++ b/sysdeps/wordsize-32/bits/wordsize.h
@@ -15,4 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/wordsize-64/bits/wordsize.h b/sysdeps/wordsize-64/bits/wordsize.h
index 0944f9e..5a4b6c5 100644
--- a/sysdeps/wordsize-64/bits/wordsize.h
+++ b/sysdeps/wordsize-64/bits/wordsize.h
@@ -15,4 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	64
+#define __WORDSIZE			64
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/x86/bits/wordsize.h b/sysdeps/x86/bits/wordsize.h
index e25af28..0834c13 100644
--- a/sysdeps/x86/bits/wordsize.h
+++ b/sysdeps/x86/bits/wordsize.h
@@ -6,8 +6,14 @@
 # define __WORDSIZE	32
 #endif
 
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #ifdef __x86_64__
 # define __WORDSIZE_TIME64_COMPAT32	1
 /* Both x86-64 and x32 use the 64-bit system call interface.  */
 # define __SYSCALL_WORDSIZE		64
+#else
+# define _WORDSIZE_TIME64_COMPAT32	0
+# define __SYSCALL_WORDSIZE		32
 #endif


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-26 18:34 [PATCH] Define wordsize.h macros everywhere Steve Ellcey
@ 2016-10-26 19:39 ` Steve Ellcey
  2016-10-26 20:07 ` Joseph Myers
  1 sibling, 0 replies; 10+ messages in thread
From: Steve Ellcey @ 2016-10-26 19:39 UTC (permalink / raw)
  To: libc-alpha; +Cc: ynorov

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

I got mail saying my patch may have been mangled by the emailer I am
using so here it is again as an attachment in case anyone else is
having problems with it.

Steve Ellcey
sellcey@caviumnetworks.com

[-- Attachment #2: wordsize.patch --]
[-- Type: text/x-patch, Size: 13519 bytes --]

diff --git a/bits/wordsize.h b/bits/wordsize.h
index 9ef0e85..2ebecd6 100644
--- a/bits/wordsize.h
+++ b/bits/wordsize.h
@@ -1 +1,28 @@
 #error "This file must be written based on the data type sizes of the target"
+
+/* The following entries are a template for what defines should be in the
+   wordsize.h header file for a target.  */
+
+/* Bits per word (size of CPU register).  */
+#define __WORDSIZE
+
+/* Set to the size of the f_fsid field in the statvfs and statvfs64 structs.
+   In most cases this is the same as __WORDSIZE but some 32 bit hosts may set
+   it to 64.  */
+#define __SYSCALL_WORDSIZE
+
+/* Set to 1 if ssize_t is type 'unsigned long' instead of type 'unsigned int'
+   so that SIZE_MAX is defined as an unsigned long constant instead of an
+   unsigned int constant.  Set to 0 if ssize_t is 'unsigned int'.  */
+#define __WORDSIZE32_SIZE_ULONG
+
+/* Set to 1 if ptrdiff_t is type 'long' instead of type 'int' so that
+   PTRDIFF_MIN and PTRDIFF_MAX are defined as long constants instead of
+   int constants.  Set to 0 if ptrdiff_t is type 'int'.  */
+#define __WORDSIZE32_PTRDIFF_LONG
+
+/* Set to 1 in order to force time types to be 32 bits instead of 64 bits in
+   struct lastlog and struct utmp{,x} on 64-bit ports.  This may be done in
+   order to make 64-bit ports compatible with 32-bit ports.  Set to 0 for
+   64-bit ports where the time types are 64-bits or for any 32-bit ports.  */
+#define __WORDSIZE_TIME64_COMPAT32
diff --git a/sysdeps/aarch64/bits/wordsize.h b/sysdeps/aarch64/bits/wordsize.h
index e69de29..c907986 100644
--- a/sysdeps/aarch64/bits/wordsize.h
+++ b/sysdeps/aarch64/bits/wordsize.h
@@ -0,0 +1,31 @@
+/* Determine the wordsize from the preprocessor defines.
+
+   Copyright (C) 2016 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
+   &lt;<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.  */
+
+#ifdef __LP64__
+# define __WORDSIZE			64
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
+#else
+# define __WORDSIZE			32
+# define __WORDSIZE32_SIZE_ULONG	1
+# define __WORDSIZE32_PTRDIFF_LONG	1
+#endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/generic/stdint.h b/sysdeps/generic/stdint.h
index 5428dbc..8e4347c 100644
--- a/sysdeps/generic/stdint.h
+++ b/sysdeps/generic/stdint.h
@@ -249,8 +249,13 @@ typedef unsigned long long int	uintmax_t;
 #  define PTRDIFF_MIN		(-9223372036854775807L-1)
 #  define PTRDIFF_MAX		(9223372036854775807L)
 # else
-#  define PTRDIFF_MIN		(-2147483647-1)
-#  define PTRDIFF_MAX		(2147483647)
+#  if __WORDSIZE32_PTRDIFF_LONG
+#   define PTRDIFF_MIN		(-2147483647L-1)
+#   define PTRDIFF_MAX		(2147483647L)
+#  else
+#   define PTRDIFF_MIN		(-2147483647-1)
+#   define PTRDIFF_MAX		(2147483647)
+#  endif
 # endif
 
 /* Limits of `sig_atomic_t'.  */
@@ -261,7 +266,7 @@ typedef unsigned long long int	uintmax_t;
 # if __WORDSIZE == 64
 #  define SIZE_MAX		(18446744073709551615UL)
 # else
-#  ifdef __WORDSIZE32_SIZE_ULONG
+#  if __WORDSIZE32_SIZE_ULONG
 #   define SIZE_MAX		(4294967295UL)
 #  else
 #   define SIZE_MAX		(4294967295U)
diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/gnu/bits/utmp.h
index 2a1ffcb..bce1a7b 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/sysdeps/gnu/bits/utmp.h
@@ -35,7 +35,7 @@
    previous logins.  */
 struct lastlog
   {
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
     int32_t ll_time;
 #else
     __time_t ll_time;
@@ -68,7 +68,7 @@ struct utmp
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
    shared between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/gnu/bits/utmpx.h b/sysdeps/gnu/bits/utmpx.h
index b41548b..a438660 100644
--- a/sysdeps/gnu/bits/utmpx.h
+++ b/sysdeps/gnu/bits/utmpx.h
@@ -66,7 +66,7 @@ struct utmpx
 /* The fields ut_session and ut_tv must be the same size when compiled
    32- and 64-bit.  This allows files and shared memory to be shared
    between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/mips/bits/wordsize.h b/sysdeps/mips/bits/wordsize.h
index bc90435..6d476ba 100644
--- a/sysdeps/mips/bits/wordsize.h
+++ b/sysdeps/mips/bits/wordsize.h
@@ -17,7 +17,13 @@
 
 #include <sgidefs.h>
 
-#define __WORDSIZE	_MIPS_SZPTR
+#define __WORDSIZE			_MIPS_SZPTR
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if _MIPS_SIM == _ABI64
 # define __WORDSIZE_TIME64_COMPAT32	1
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
diff --git a/sysdeps/powerpc/powerpc32/bits/wordsize.h b/sysdeps/powerpc/powerpc32/bits/wordsize.h
index f31ac9a..f08ab26 100644
--- a/sysdeps/powerpc/powerpc32/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc32/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/powerpc/powerpc64/bits/wordsize.h b/sysdeps/powerpc/powerpc64/bits/wordsize.h
index f31ac9a..f08ab26 100644
--- a/sysdeps/powerpc/powerpc64/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc64/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/s390/s390-32/bits/wordsize.h b/sysdeps/s390/s390-32/bits/wordsize.h
index da791fa..7ac7e6b 100644
--- a/sysdeps/s390/s390-32/bits/wordsize.h
+++ b/sysdeps/s390/s390-32/bits/wordsize.h
@@ -2,11 +2,16 @@
 
 #if defined __s390x__
 # define __WORDSIZE	64
+# define __WORDSIZE32_SIZE_ULONG       0
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_PTRDIFF_LONG      0
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/s390/s390-64/bits/wordsize.h b/sysdeps/s390/s390-64/bits/wordsize.h
index da791fa..7ac7e6b 100644
--- a/sysdeps/s390/s390-64/bits/wordsize.h
+++ b/sysdeps/s390/s390-64/bits/wordsize.h
@@ -2,11 +2,16 @@
 
 #if defined __s390x__
 # define __WORDSIZE	64
+# define __WORDSIZE32_SIZE_ULONG       0
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_PTRDIFF_LONG      0
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/sparc/sparc32/bits/wordsize.h b/sysdeps/sparc/sparc32/bits/wordsize.h
index d8fd1a5..73a3b7c 100644
--- a/sysdeps/sparc/sparc32/bits/wordsize.h
+++ b/sysdeps/sparc/sparc32/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/sparc/sparc64/bits/wordsize.h b/sysdeps/sparc/sparc64/bits/wordsize.h
index d8fd1a5..73a3b7c 100644
--- a/sysdeps/sparc/sparc64/bits/wordsize.h
+++ b/sysdeps/sparc/sparc64/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/tile/tilegx/bits/wordsize.h b/sysdeps/tile/tilegx/bits/wordsize.h
index 5d4e4b4..f5db53a 100644
--- a/sysdeps/tile/tilegx/bits/wordsize.h
+++ b/sysdeps/tile/tilegx/bits/wordsize.h
@@ -5,4 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
+
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/tile/tilepro/bits/wordsize.h b/sysdeps/tile/tilepro/bits/wordsize.h
index da587a2..e1f21c9 100644
--- a/sysdeps/tile/tilepro/bits/wordsize.h
+++ b/sysdeps/tile/tilepro/bits/wordsize.h
@@ -1,3 +1,7 @@
 /* Determine the wordsize from the preprocessor defines.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
index 51fc433..e1a3cdb 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
@@ -16,6 +16,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define __WORDSIZE	64
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
diff --git a/sysdeps/unix/sysv/linux/bits/statvfs.h b/sysdeps/unix/sysv/linux/bits/statvfs.h
index 9244401..fcdd2cd 100644
--- a/sysdeps/unix/sysv/linux/bits/statvfs.h
+++ b/sysdeps/unix/sysv/linux/bits/statvfs.h
@@ -21,8 +21,7 @@
 
 #include <bits/types.h>  /* For __fsblkcnt_t and __fsfilcnt_t.  */
 
-#if (__WORDSIZE == 32 \
-     && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
+#if (__WORDSIZE == 32 && __SYSCALL_WORDSIZE == 32)
 #define _STATVFSBUF_F_UNUSED
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
index 3e8a1e0..aaec974 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
@@ -5,8 +5,13 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal the glibc ABI didn't used to have a `long double'.
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
index 2d958d2..5df97ab 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
@@ -6,6 +6,11 @@
 # define __WORDSIZE	32
 #endif
 
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 # if __WORDSIZE == 32
diff --git a/sysdeps/wordsize-32/bits/wordsize.h b/sysdeps/wordsize-32/bits/wordsize.h
index 2aa16bc..3454d7f 100644
--- a/sysdeps/wordsize-32/bits/wordsize.h
+++ b/sysdeps/wordsize-32/bits/wordsize.h
@@ -15,4 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/wordsize-64/bits/wordsize.h b/sysdeps/wordsize-64/bits/wordsize.h
index 0944f9e..5a4b6c5 100644
--- a/sysdeps/wordsize-64/bits/wordsize.h
+++ b/sysdeps/wordsize-64/bits/wordsize.h
@@ -15,4 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	64
+#define __WORDSIZE			64
+#define __SYSCALL_WORDSIZE		__WORDSIZE
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/x86/bits/wordsize.h b/sysdeps/x86/bits/wordsize.h
index e25af28..0834c13 100644
--- a/sysdeps/x86/bits/wordsize.h
+++ b/sysdeps/x86/bits/wordsize.h
@@ -6,8 +6,14 @@
 # define __WORDSIZE	32
 #endif
 
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
+
 #ifdef __x86_64__
 # define __WORDSIZE_TIME64_COMPAT32	1
 /* Both x86-64 and x32 use the 64-bit system call interface.  */
 # define __SYSCALL_WORDSIZE		64
+#else
+# define _WORDSIZE_TIME64_COMPAT32	0
+# define __SYSCALL_WORDSIZE		32
 #endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-26 18:34 [PATCH] Define wordsize.h macros everywhere Steve Ellcey
  2016-10-26 19:39 ` Steve Ellcey
@ 2016-10-26 20:07 ` Joseph Myers
  2016-10-27 18:45   ` Steve Ellcey
  1 sibling, 1 reply; 10+ messages in thread
From: Joseph Myers @ 2016-10-26 20:07 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: libc-alpha, ynorov

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

On Wed, 26 Oct 2016, Steve Ellcey wrote:

> diff --git a/bits/wordsize.h b/bits/wordsize.h
> index 9ef0e85..2ebecd6 100644
> --- a/bits/wordsize.h
> +++ b/bits/wordsize.h
> @@ -1 +1,28 @@
>  #error "This file must be written based on the data type sizes of the target"
> +
> +/* The following entries are a template for what defines should be in the
> +   wordsize.h header file for a target.  */
> +
> +/* Bits per word (size of CPU register).  */
> +#define __WORDSIZE

That's not an accurate description.  It's definitely the size of long int 
and pointers, even if registers are larger.

> +/* Set to the size of the f_fsid field in the statvfs and statvfs64 structs.
> +   In most cases this is the same as __WORDSIZE but some 32 bit hosts may set
> +   it to 64.  */
> +#define __SYSCALL_WORDSIZE

If it's so specific to those syscalls, it doesn't belong in 
bits/wordsize.h but in some header specific to those syscalls.  Even the 
*concept* of syscalls doesn't belong in bits/wordsize.h (remember there 
are non-syscall ports such as Hurd).

> +/* Set to 1 if ssize_t is type 'unsigned long' instead of type 'unsigned int'
> +   so that SIZE_MAX is defined as an unsigned long constant instead of an
> +   unsigned int constant.  Set to 0 if ssize_t is 'unsigned int'.  */
> +#define __WORDSIZE32_SIZE_ULONG

Is this about ssize_t as the comment says (twice), or size_t?

> +/* Set to 1 if ptrdiff_t is type 'long' instead of type 'int' so that
> +   PTRDIFF_MIN and PTRDIFF_MAX are defined as long constants instead of
> +   int constants.  Set to 0 if ptrdiff_t is type 'int'.  */
> +#define __WORDSIZE32_PTRDIFF_LONG

For both these macros I think consensus is as Andreas said in 
<https://sourceware.org/ml/libc-alpha/2016-07/msg00251.html> and 
<https://sourceware.org/ml/libc-alpha/2016-07/msg00267.html>.

That is, they should only be defined if __WORDSIZE == 32.  They should be 
tested with #if not #ifdef, but all such tests should only be evaluated if 
__WORDSIZE == 32, so that we get -Wundef errors if any such test gets 
evaluated with __WORDSIZE == 64.

So the comments specifying the semantics of those macros should say that 
they are only defined or used if __WORDSIZE == 32, and the headers should 
only define them under that condition.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-26 20:07 ` Joseph Myers
@ 2016-10-27 18:45   ` Steve Ellcey
  2016-10-27 20:16     ` Adhemerval Zanella
  0 siblings, 1 reply; 10+ messages in thread
From: Steve Ellcey @ 2016-10-27 18:45 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha, ynorov

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

Here is an update of my earlier wordsize.h patch.  I removed the
__SYSCALL_WORDSIZE changes.  That macro definition is still in
the x86 wordsize.h header but nothing in this patch changes it 
anymore.

I updated the description of __WORDSIZE and the __WORDSIZE32_* macros
and I only define the __WORDSIZE32_* macros when __WORDSIZE is 32.
I also fixed the __WORDSIZE32_SIZE_ULONG description to refer to 
size_t instead of ssize_t since size_t is the type for SIZE_MAX.

I retested on x86 and aarch64 to ensure that everything still built
and ran with no regressions.

Steve Ellcey
sellcey@caviumnetworks.com


2016-10-27  Yury Norov  <ynorov@caviumnetworks.com>
	    Steve Ellcey <sellcey@caviumnetworks.com>

	* bits/wordsize.h: Add documentation.
	* sysdeps/aarch64/bits/wordsize.h : New file
	* sysdeps/generic/stdint.h (PTRDIFF_MIN, PTRDIFF_MAX): Update
	definitions.
	(SIZE_MAX): Change ifdef to if in __WORDSIZE32_SIZE_ULONG check.
	* sysdeps/gnu/bits/utmp.h (__WORDSIZE_TIME64_COMPAT32): Check
	with #if instead of #ifdef.
	* sysdeps/gnu/bits/utmpx.h (__WORDSIZE_TIME64_COMPAT32): Ditto.
	* sysdeps/mips/bits/wordsize.h (__WORDSIZE32_SIZE_ULONG,
	__WORDSIZE32_PTRDIFF_LONG, __WORDSIZE_TIME64_COMPAT32):
	Add or change defines.
	* sysdeps/powerpc/powerpc32/bits/wordsize.h: Likewise.
	* sysdeps/powerpc/powerpc64/bits/wordsize.h: Likewise.
	* sysdeps/s390/s390-32/bits/wordsize.h: Likewise.
	* sysdeps/s390/s390-64/bits/wordsize.h: Likewise.
	* sysdeps/sparc/sparc32/bits/wordsize.h: Likewise.
	* sysdeps/sparc/sparc64/bits/wordsize.h: Likewise.
	* sysdeps/tile/tilegx/bits/wordsize.h: Likewise.
	* sysdeps/tile/tilepro/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/alpha/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/wordsize.h: Likewise.
	* sysdeps/wordsize-32/bits/wordsize.h: Likewise.
	* sysdeps/wordsize-64/bits/wordsize.h: Likewise.
	* sysdeps/x86/bits/wordsize.h: Likewise.


[-- Attachment #2: wordsize.patch --]
[-- Type: text/x-patch, Size: 11927 bytes --]

diff --git a/bits/wordsize.h b/bits/wordsize.h
index 9ef0e85..14edae3 100644
--- a/bits/wordsize.h
+++ b/bits/wordsize.h
@@ -1 +1,27 @@
 #error "This file must be written based on the data type sizes of the target"
+
+/* The following entries are a template for what defines should be in the
+   wordsize.h header file for a target.  */
+
+/* Size in bits of the 'long int' and pointer types.  */
+#define __WORDSIZE
+
+/* This should be set to 1 if __WORDSIZE is 32 and size_t is type
+   'unsigned long' instead of type 'unsigned int'.  This will ensure
+   that SIZE_MAX is defined as an unsigned long constant instead of an
+   unsigned int constant.  Set to 0 if __WORDSIZE is 32 and size_t is
+   'unsigned int' and leave undefined if __WORDSIZE is 64.  */
+#define __WORDSIZE32_SIZE_ULONG
+
+/* This should be set to 1 if __WORDSIZE is 32 and ptrdiff_t is type 'long'
+   instead of type 'int'.  This will ensure that PTRDIFF_MIN and PTRDIFF_MAX
+   are defined as long constants instead of int constants.  Set to 0 if
+   __WORDSIZE is 32 and ptrdiff_t is type 'int' and leave undefined if
+   __WORDSIZE is 64.  */
+#define __WORDSIZE32_PTRDIFF_LONG
+
+/* Set to 1 in order to force time types to be 32 bits instead of 64 bits in
+   struct lastlog and struct utmp{,x} on 64-bit ports.  This may be done in
+   order to make 64-bit ports compatible with 32-bit ports.  Set to 0 for
+   64-bit ports where the time types are 64-bits or for any 32-bit ports.  */
+#define __WORDSIZE_TIME64_COMPAT32
diff --git a/sysdeps/aarch64/bits/wordsize.h b/sysdeps/aarch64/bits/wordsize.h
index e69de29..6f0a958 100644
--- a/sysdeps/aarch64/bits/wordsize.h
+++ b/sysdeps/aarch64/bits/wordsize.h
@@ -0,0 +1,28 @@
+/* Determine the wordsize from the preprocessor defines.
+
+   Copyright (C) 2016 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
+   &lt;<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.  */
+
+#ifdef __LP64__
+# define __WORDSIZE			64
+#else
+# define __WORDSIZE			32
+# define __WORDSIZE32_SIZE_ULONG	1
+# define __WORDSIZE32_PTRDIFF_LONG	1
+#endif
+
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/generic/stdint.h b/sysdeps/generic/stdint.h
index 5428dbc..8e4347c 100644
--- a/sysdeps/generic/stdint.h
+++ b/sysdeps/generic/stdint.h
@@ -249,8 +249,13 @@ typedef unsigned long long int	uintmax_t;
 #  define PTRDIFF_MIN		(-9223372036854775807L-1)
 #  define PTRDIFF_MAX		(9223372036854775807L)
 # else
-#  define PTRDIFF_MIN		(-2147483647-1)
-#  define PTRDIFF_MAX		(2147483647)
+#  if __WORDSIZE32_PTRDIFF_LONG
+#   define PTRDIFF_MIN		(-2147483647L-1)
+#   define PTRDIFF_MAX		(2147483647L)
+#  else
+#   define PTRDIFF_MIN		(-2147483647-1)
+#   define PTRDIFF_MAX		(2147483647)
+#  endif
 # endif
 
 /* Limits of `sig_atomic_t'.  */
@@ -261,7 +266,7 @@ typedef unsigned long long int	uintmax_t;
 # if __WORDSIZE == 64
 #  define SIZE_MAX		(18446744073709551615UL)
 # else
-#  ifdef __WORDSIZE32_SIZE_ULONG
+#  if __WORDSIZE32_SIZE_ULONG
 #   define SIZE_MAX		(4294967295UL)
 #  else
 #   define SIZE_MAX		(4294967295U)
diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/gnu/bits/utmp.h
index 2a1ffcb..bce1a7b 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/sysdeps/gnu/bits/utmp.h
@@ -35,7 +35,7 @@
    previous logins.  */
 struct lastlog
   {
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
     int32_t ll_time;
 #else
     __time_t ll_time;
@@ -68,7 +68,7 @@ struct utmp
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
    shared between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/gnu/bits/utmpx.h b/sysdeps/gnu/bits/utmpx.h
index b41548b..a438660 100644
--- a/sysdeps/gnu/bits/utmpx.h
+++ b/sysdeps/gnu/bits/utmpx.h
@@ -66,7 +66,7 @@ struct utmpx
 /* The fields ut_session and ut_tv must be the same size when compiled
    32- and 64-bit.  This allows files and shared memory to be shared
    between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/mips/bits/wordsize.h b/sysdeps/mips/bits/wordsize.h
index bc90435..7a3546b 100644
--- a/sysdeps/mips/bits/wordsize.h
+++ b/sysdeps/mips/bits/wordsize.h
@@ -17,7 +17,15 @@
 
 #include <sgidefs.h>
 
-#define __WORDSIZE	_MIPS_SZPTR
+#define __WORDSIZE			_MIPS_SZPTR
+
 #if _MIPS_SIM == _ABI64
 # define __WORDSIZE_TIME64_COMPAT32	1
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
+#endif
+
+#if __WORDSIZE == 32
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/powerpc/powerpc32/bits/wordsize.h b/sysdeps/powerpc/powerpc32/bits/wordsize.h
index f31ac9a..04ca9de 100644
--- a/sysdeps/powerpc/powerpc32/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc32/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/powerpc/powerpc64/bits/wordsize.h b/sysdeps/powerpc/powerpc64/bits/wordsize.h
index f31ac9a..04ca9de 100644
--- a/sysdeps/powerpc/powerpc64/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc64/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/s390/s390-32/bits/wordsize.h b/sysdeps/s390/s390-32/bits/wordsize.h
index da791fa..c7a5fbf 100644
--- a/sysdeps/s390/s390-32/bits/wordsize.h
+++ b/sysdeps/s390/s390-32/bits/wordsize.h
@@ -5,8 +5,11 @@
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
+# define __WORDSIZE32_PTRDIFF_LONG      0
 #endif
 
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/s390/s390-64/bits/wordsize.h b/sysdeps/s390/s390-64/bits/wordsize.h
index da791fa..31e0ec6 100644
--- a/sysdeps/s390/s390-64/bits/wordsize.h
+++ b/sysdeps/s390/s390-64/bits/wordsize.h
@@ -5,8 +5,11 @@
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
+# define __WORDSIZE32_PTRDIFF_LONG     0
 #endif
 
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/sparc/sparc32/bits/wordsize.h b/sysdeps/sparc/sparc32/bits/wordsize.h
index d8fd1a5..2f66f10 100644
--- a/sysdeps/sparc/sparc32/bits/wordsize.h
+++ b/sysdeps/sparc/sparc32/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/sparc/sparc64/bits/wordsize.h b/sysdeps/sparc/sparc64/bits/wordsize.h
index d8fd1a5..2f66f10 100644
--- a/sysdeps/sparc/sparc64/bits/wordsize.h
+++ b/sysdeps/sparc/sparc64/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/tile/tilegx/bits/wordsize.h b/sysdeps/tile/tilegx/bits/wordsize.h
index 5d4e4b4..9dc4da5 100644
--- a/sysdeps/tile/tilegx/bits/wordsize.h
+++ b/sysdeps/tile/tilegx/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/tile/tilepro/bits/wordsize.h b/sysdeps/tile/tilepro/bits/wordsize.h
index da587a2..8281538 100644
--- a/sysdeps/tile/tilepro/bits/wordsize.h
+++ b/sysdeps/tile/tilepro/bits/wordsize.h
@@ -1,3 +1,4 @@
 /* Determine the wordsize from the preprocessor defines.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
index 51fc433..f0961f6 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define __WORDSIZE	64
+#define __WORDSIZE_TIME64_COMPAT32	0
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
index 3e8a1e0..109f08c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
@@ -5,6 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
index 2d958d2..76d6579 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
@@ -4,6 +4,8 @@
 # define __WORDSIZE	64
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
diff --git a/sysdeps/wordsize-32/bits/wordsize.h b/sysdeps/wordsize-32/bits/wordsize.h
index 2aa16bc..a251f3a 100644
--- a/sysdeps/wordsize-32/bits/wordsize.h
+++ b/sysdeps/wordsize-32/bits/wordsize.h
@@ -15,4 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __WORDSIZE_TIME64_COMPAT32	0
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/wordsize-64/bits/wordsize.h b/sysdeps/wordsize-64/bits/wordsize.h
index 0944f9e..8b5c502 100644
--- a/sysdeps/wordsize-64/bits/wordsize.h
+++ b/sysdeps/wordsize-64/bits/wordsize.h
@@ -15,4 +15,5 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	64
+#define __WORDSIZE			64
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/x86/bits/wordsize.h b/sysdeps/x86/bits/wordsize.h
index e25af28..70f652b 100644
--- a/sysdeps/x86/bits/wordsize.h
+++ b/sysdeps/x86/bits/wordsize.h
@@ -4,10 +4,14 @@
 # define __WORDSIZE	64
 #else
 # define __WORDSIZE	32
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #ifdef __x86_64__
 # define __WORDSIZE_TIME64_COMPAT32	1
 /* Both x86-64 and x32 use the 64-bit system call interface.  */
 # define __SYSCALL_WORDSIZE		64
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-27 18:45   ` Steve Ellcey
@ 2016-10-27 20:16     ` Adhemerval Zanella
  2016-10-28 16:07       ` Steve Ellcey
  0 siblings, 1 reply; 10+ messages in thread
From: Adhemerval Zanella @ 2016-10-27 20:16 UTC (permalink / raw)
  To: libc-alpha



On 27/10/2016 16:45, Steve Ellcey wrote:

> --- a/sysdeps/aarch64/bits/wordsize.h
> +++ b/sysdeps/aarch64/bits/wordsize.h
> @@ -0,0 +1,28 @@
> +/* Determine the wordsize from the preprocessor defines.
> +
> +   Copyright (C) 2016 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
> +   &lt;<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.  */

I think you editor added some http tag on this URL.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-27 20:16     ` Adhemerval Zanella
@ 2016-10-28 16:07       ` Steve Ellcey
  2016-11-03 20:41         ` Steve Ellcey
  0 siblings, 1 reply; 10+ messages in thread
From: Steve Ellcey @ 2016-10-28 16:07 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On Thu, 2016-10-27 at 18:16 -0200, Adhemerval Zanella wrote:
> 
> On 27/10/2016 16:45, Steve Ellcey wrote:
> 
> > 
> > +   You should have received a copy of the GNU Lesser General
> > Public
> > +   License along with the GNU C Library; if not, see
> > +   &lt;<a rel="nofollow"
> > href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a
> > >&gt;.  */

> I think you editor added some http tag on this URL.

Actually, it looks like it got messed up in my patch.  I have fixed it
locally and can resubmit the patch if necessary.

Steve Ellcey
sellcey@caviumnetworks.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-10-28 16:07       ` Steve Ellcey
@ 2016-11-03 20:41         ` Steve Ellcey
  2016-11-04  8:16           ` Andreas Schwab
  2016-11-10 14:28           ` Joseph Myers
  0 siblings, 2 replies; 10+ messages in thread
From: Steve Ellcey @ 2016-11-03 20:41 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

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

On Fri, 2016-10-28 at 09:07 -0700, Steve Ellcey wrote:
> On Thu, 2016-10-27 at 18:16 -0200, Adhemerval Zanella wrote:
> > 
> > 
> > On 27/10/2016 16:45, Steve Ellcey wrote:
> > 
> > > 
> > >  
> > > +   You should have received a copy of the GNU Lesser General
> > > Public
> > > +   License along with the GNU C Library; if not, see
> > > +   &lt;<a rel="nofollow"
> > > href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/<
> > > /a
> > > > 
> > > > &gt;.  */
> > 
> > I think you editor added some http tag on this URL.
> Actually, it looks like it got messed up in my patch.  I have fixed
> it locally and can resubmit the patch if necessary.
> 
> Steve Ellcey
> sellcey@caviumnetworks.com

Here is a ping/repost of this patch with the comment fixed. This patch
defines macros in the various wordsize.h files so they can be used
without having to check if they are defined first and adds
documentation about what they do in bits/wordsize.h.

Steve Ellcey
sellcey@caviumnetworks.com


2016-11-03  Yury Norov  <ynorov@caviumnetworks.com>
            Steve Ellcey <sellcey@caviumnetworks.com>

        * bits/wordsize.h: Add documentation.
        * sysdeps/aarch64/bits/wordsize.h : New file
        * sysdeps/generic/stdint.h (PTRDIFF_MIN, PTRDIFF_MAX): Update
        definitions.
        (SIZE_MAX): Change ifdef to if in __WORDSIZE32_SIZE_ULONG check.
        * sysdeps/gnu/bits/utmp.h (__WORDSIZE_TIME64_COMPAT32): Check
        with #if instead of #ifdef.
        * sysdeps/gnu/bits/utmpx.h (__WORDSIZE_TIME64_COMPAT32): Ditto.
        * sysdeps/mips/bits/wordsize.h (__WORDSIZE32_SIZE_ULONG,
        __WORDSIZE32_PTRDIFF_LONG, __WORDSIZE_TIME64_COMPAT32):
        Add or change defines.
        * sysdeps/powerpc/powerpc32/bits/wordsize.h: Likewise.
        * sysdeps/powerpc/powerpc64/bits/wordsize.h: Likewise.
        * sysdeps/s390/s390-32/bits/wordsize.h: Likewise.
        * sysdeps/s390/s390-64/bits/wordsize.h: Likewise.
        * sysdeps/sparc/sparc32/bits/wordsize.h: Likewise.
        * sysdeps/sparc/sparc64/bits/wordsize.h: Likewise.
        * sysdeps/tile/tilegx/bits/wordsize.h: Likewise.
        * sysdeps/tile/tilepro/bits/wordsize.h: Likewise.
        * sysdeps/unix/sysv/linux/alpha/bits/wordsize.h: Likewise.

[-- Attachment #2: wordsize.patch --]
[-- Type: text/x-patch, Size: 11863 bytes --]

diff --git a/bits/wordsize.h b/bits/wordsize.h
index 9ef0e85..14edae3 100644
--- a/bits/wordsize.h
+++ b/bits/wordsize.h
@@ -1 +1,27 @@
 #error "This file must be written based on the data type sizes of the target"
+
+/* The following entries are a template for what defines should be in the
+   wordsize.h header file for a target.  */
+
+/* Size in bits of the 'long int' and pointer types.  */
+#define __WORDSIZE
+
+/* This should be set to 1 if __WORDSIZE is 32 and size_t is type
+   'unsigned long' instead of type 'unsigned int'.  This will ensure
+   that SIZE_MAX is defined as an unsigned long constant instead of an
+   unsigned int constant.  Set to 0 if __WORDSIZE is 32 and size_t is
+   'unsigned int' and leave undefined if __WORDSIZE is 64.  */
+#define __WORDSIZE32_SIZE_ULONG
+
+/* This should be set to 1 if __WORDSIZE is 32 and ptrdiff_t is type 'long'
+   instead of type 'int'.  This will ensure that PTRDIFF_MIN and PTRDIFF_MAX
+   are defined as long constants instead of int constants.  Set to 0 if
+   __WORDSIZE is 32 and ptrdiff_t is type 'int' and leave undefined if
+   __WORDSIZE is 64.  */
+#define __WORDSIZE32_PTRDIFF_LONG
+
+/* Set to 1 in order to force time types to be 32 bits instead of 64 bits in
+   struct lastlog and struct utmp{,x} on 64-bit ports.  This may be done in
+   order to make 64-bit ports compatible with 32-bit ports.  Set to 0 for
+   64-bit ports where the time types are 64-bits or for any 32-bit ports.  */
+#define __WORDSIZE_TIME64_COMPAT32
diff --git a/sysdeps/aarch64/bits/wordsize.h b/sysdeps/aarch64/bits/wordsize.h
index e69de29..6f0a958 100644
--- a/sysdeps/aarch64/bits/wordsize.h
+++ b/sysdeps/aarch64/bits/wordsize.h
@@ -0,0 +1,28 @@
+/* Determine the wordsize from the preprocessor defines.
+
+   Copyright (C) 2016 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/>.  */
+
+#ifdef __LP64__
+# define __WORDSIZE			64
+#else
+# define __WORDSIZE			32
+# define __WORDSIZE32_SIZE_ULONG	1
+# define __WORDSIZE32_PTRDIFF_LONG	1
+#endif
+
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/generic/stdint.h b/sysdeps/generic/stdint.h
index 5428dbc..8e4347c 100644
--- a/sysdeps/generic/stdint.h
+++ b/sysdeps/generic/stdint.h
@@ -249,8 +249,13 @@ typedef unsigned long long int	uintmax_t;
 #  define PTRDIFF_MIN		(-9223372036854775807L-1)
 #  define PTRDIFF_MAX		(9223372036854775807L)
 # else
-#  define PTRDIFF_MIN		(-2147483647-1)
-#  define PTRDIFF_MAX		(2147483647)
+#  if __WORDSIZE32_PTRDIFF_LONG
+#   define PTRDIFF_MIN		(-2147483647L-1)
+#   define PTRDIFF_MAX		(2147483647L)
+#  else
+#   define PTRDIFF_MIN		(-2147483647-1)
+#   define PTRDIFF_MAX		(2147483647)
+#  endif
 # endif
 
 /* Limits of `sig_atomic_t'.  */
@@ -261,7 +266,7 @@ typedef unsigned long long int	uintmax_t;
 # if __WORDSIZE == 64
 #  define SIZE_MAX		(18446744073709551615UL)
 # else
-#  ifdef __WORDSIZE32_SIZE_ULONG
+#  if __WORDSIZE32_SIZE_ULONG
 #   define SIZE_MAX		(4294967295UL)
 #  else
 #   define SIZE_MAX		(4294967295U)
diff --git a/sysdeps/gnu/bits/utmp.h b/sysdeps/gnu/bits/utmp.h
index 2a1ffcb..bce1a7b 100644
--- a/sysdeps/gnu/bits/utmp.h
+++ b/sysdeps/gnu/bits/utmp.h
@@ -35,7 +35,7 @@
    previous logins.  */
 struct lastlog
   {
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
     int32_t ll_time;
 #else
     __time_t ll_time;
@@ -68,7 +68,7 @@ struct utmp
 /* The ut_session and ut_tv fields must be the same size when compiled
    32- and 64-bit.  This allows data files and shared memory to be
    shared between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/gnu/bits/utmpx.h b/sysdeps/gnu/bits/utmpx.h
index b41548b..a438660 100644
--- a/sysdeps/gnu/bits/utmpx.h
+++ b/sysdeps/gnu/bits/utmpx.h
@@ -66,7 +66,7 @@ struct utmpx
 /* The fields ut_session and ut_tv must be the same size when compiled
    32- and 64-bit.  This allows files and shared memory to be shared
    between 32- and 64-bit applications.  */
-#ifdef __WORDSIZE_TIME64_COMPAT32
+#if __WORDSIZE_TIME64_COMPAT32
   __int32_t ut_session;		/* Session ID, used for windowing.  */
   struct
   {
diff --git a/sysdeps/mips/bits/wordsize.h b/sysdeps/mips/bits/wordsize.h
index bc90435..7a3546b 100644
--- a/sysdeps/mips/bits/wordsize.h
+++ b/sysdeps/mips/bits/wordsize.h
@@ -17,7 +17,15 @@
 
 #include <sgidefs.h>
 
-#define __WORDSIZE	_MIPS_SZPTR
+#define __WORDSIZE			_MIPS_SZPTR
+
 #if _MIPS_SIM == _ABI64
 # define __WORDSIZE_TIME64_COMPAT32	1
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
+#endif
+
+#if __WORDSIZE == 32
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/powerpc/powerpc32/bits/wordsize.h b/sysdeps/powerpc/powerpc32/bits/wordsize.h
index f31ac9a..04ca9de 100644
--- a/sysdeps/powerpc/powerpc32/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc32/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/powerpc/powerpc64/bits/wordsize.h b/sysdeps/powerpc/powerpc64/bits/wordsize.h
index f31ac9a..04ca9de 100644
--- a/sysdeps/powerpc/powerpc64/bits/wordsize.h
+++ b/sysdeps/powerpc/powerpc64/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/s390/s390-32/bits/wordsize.h b/sysdeps/s390/s390-32/bits/wordsize.h
index da791fa..c7a5fbf 100644
--- a/sysdeps/s390/s390-32/bits/wordsize.h
+++ b/sysdeps/s390/s390-32/bits/wordsize.h
@@ -5,8 +5,11 @@
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
+# define __WORDSIZE32_PTRDIFF_LONG      0
 #endif
 
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/s390/s390-64/bits/wordsize.h b/sysdeps/s390/s390-64/bits/wordsize.h
index da791fa..31e0ec6 100644
--- a/sysdeps/s390/s390-64/bits/wordsize.h
+++ b/sysdeps/s390/s390-64/bits/wordsize.h
@@ -5,8 +5,11 @@
 #else
 # define __WORDSIZE	32
 # define __WORDSIZE32_SIZE_ULONG       1
+# define __WORDSIZE32_PTRDIFF_LONG     0
 #endif
 
+#define __WORDSIZE_TIME64_COMPAT32     0
+
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
 /* Signal that we didn't used to have a `long double'. The changes all
diff --git a/sysdeps/sparc/sparc32/bits/wordsize.h b/sysdeps/sparc/sparc32/bits/wordsize.h
index d8fd1a5..2f66f10 100644
--- a/sysdeps/sparc/sparc32/bits/wordsize.h
+++ b/sysdeps/sparc/sparc32/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/sparc/sparc64/bits/wordsize.h b/sysdeps/sparc/sparc64/bits/wordsize.h
index d8fd1a5..2f66f10 100644
--- a/sysdeps/sparc/sparc64/bits/wordsize.h
+++ b/sysdeps/sparc/sparc64/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/tile/tilegx/bits/wordsize.h b/sysdeps/tile/tilegx/bits/wordsize.h
index 5d4e4b4..9dc4da5 100644
--- a/sysdeps/tile/tilegx/bits/wordsize.h
+++ b/sysdeps/tile/tilegx/bits/wordsize.h
@@ -5,4 +5,7 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
diff --git a/sysdeps/tile/tilepro/bits/wordsize.h b/sysdeps/tile/tilepro/bits/wordsize.h
index da587a2..8281538 100644
--- a/sysdeps/tile/tilepro/bits/wordsize.h
+++ b/sysdeps/tile/tilepro/bits/wordsize.h
@@ -1,3 +1,4 @@
 /* Determine the wordsize from the preprocessor defines.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
index 51fc433..f0961f6 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/wordsize.h
@@ -16,6 +16,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define __WORDSIZE	64
+#define __WORDSIZE_TIME64_COMPAT32	0
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
index 3e8a1e0..109f08c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/wordsize.h
@@ -5,6 +5,9 @@
 # define __WORDSIZE_TIME64_COMPAT32	1
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE_TIME64_COMPAT32	0
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
index 2d958d2..76d6579 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/wordsize.h
@@ -4,6 +4,8 @@
 # define __WORDSIZE	64
 #else
 # define __WORDSIZE	32
+# define __WORDSIZE32_SIZE_ULONG	0
+# define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #if !defined __NO_LONG_DOUBLE_MATH && !defined __LONG_DOUBLE_MATH_OPTIONAL
diff --git a/sysdeps/wordsize-32/bits/wordsize.h b/sysdeps/wordsize-32/bits/wordsize.h
index 2aa16bc..a251f3a 100644
--- a/sysdeps/wordsize-32/bits/wordsize.h
+++ b/sysdeps/wordsize-32/bits/wordsize.h
@@ -15,4 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	32
+#define __WORDSIZE			32
+#define __WORDSIZE_TIME64_COMPAT32	0
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
diff --git a/sysdeps/wordsize-64/bits/wordsize.h b/sysdeps/wordsize-64/bits/wordsize.h
index 0944f9e..8b5c502 100644
--- a/sysdeps/wordsize-64/bits/wordsize.h
+++ b/sysdeps/wordsize-64/bits/wordsize.h
@@ -15,4 +15,5 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __WORDSIZE	64
+#define __WORDSIZE			64
+#define __WORDSIZE_TIME64_COMPAT32	0
diff --git a/sysdeps/x86/bits/wordsize.h b/sysdeps/x86/bits/wordsize.h
index e25af28..70f652b 100644
--- a/sysdeps/x86/bits/wordsize.h
+++ b/sysdeps/x86/bits/wordsize.h
@@ -4,10 +4,14 @@
 # define __WORDSIZE	64
 #else
 # define __WORDSIZE	32
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0
 #endif
 
 #ifdef __x86_64__
 # define __WORDSIZE_TIME64_COMPAT32	1
 /* Both x86-64 and x32 use the 64-bit system call interface.  */
 # define __SYSCALL_WORDSIZE		64
+#else
+# define __WORDSIZE_TIME64_COMPAT32	0
 #endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-11-03 20:41         ` Steve Ellcey
@ 2016-11-04  8:16           ` Andreas Schwab
  2016-11-10 14:28           ` Joseph Myers
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2016-11-04  8:16 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: Adhemerval Zanella, libc-alpha

On Nov 03 2016, Steve Ellcey <sellcey@caviumnetworks.com> wrote:

> 2016-11-03  Yury Norov  <ynorov@caviumnetworks.com>
>             Steve Ellcey <sellcey@caviumnetworks.com>
>
>         * bits/wordsize.h: Add documentation.
>         * sysdeps/aarch64/bits/wordsize.h : New file
>         * sysdeps/generic/stdint.h (PTRDIFF_MIN, PTRDIFF_MAX): Update
>         definitions.
>         (SIZE_MAX): Change ifdef to if in __WORDSIZE32_SIZE_ULONG check.
>         * sysdeps/gnu/bits/utmp.h (__WORDSIZE_TIME64_COMPAT32): Check
>         with #if instead of #ifdef.
>         * sysdeps/gnu/bits/utmpx.h (__WORDSIZE_TIME64_COMPAT32): Ditto.
>         * sysdeps/mips/bits/wordsize.h (__WORDSIZE32_SIZE_ULONG,
>         __WORDSIZE32_PTRDIFF_LONG, __WORDSIZE_TIME64_COMPAT32):
>         Add or change defines.
>         * sysdeps/powerpc/powerpc32/bits/wordsize.h: Likewise.
>         * sysdeps/powerpc/powerpc64/bits/wordsize.h: Likewise.
>         * sysdeps/s390/s390-32/bits/wordsize.h: Likewise.
>         * sysdeps/s390/s390-64/bits/wordsize.h: Likewise.
>         * sysdeps/sparc/sparc32/bits/wordsize.h: Likewise.
>         * sysdeps/sparc/sparc64/bits/wordsize.h: Likewise.
>         * sysdeps/tile/tilegx/bits/wordsize.h: Likewise.
>         * sysdeps/tile/tilepro/bits/wordsize.h: Likewise.
>         * sysdeps/unix/sysv/linux/alpha/bits/wordsize.h: Likewise.

This is ok, if you use plain spaces and tabs in the changelog entry.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-11-03 20:41         ` Steve Ellcey
  2016-11-04  8:16           ` Andreas Schwab
@ 2016-11-10 14:28           ` Joseph Myers
  2016-11-10 15:43             ` Steve Ellcey
  1 sibling, 1 reply; 10+ messages in thread
From: Joseph Myers @ 2016-11-10 14:28 UTC (permalink / raw)
  To: Steve Ellcey; +Cc: Adhemerval Zanella, libc-alpha

I see errors in tilepro-linux-gnu builds with this patch:

../sysdeps/generic/stdint.h:252:7: error: "__WORDSIZE32_PTRDIFF_LONG" is not defined [-Werror=undef]
 #  if __WORDSIZE32_PTRDIFF_LONG
       ^~~~~~~~~~~~~~~~~~~~~~~~~
../sysdeps/generic/stdint.h:269:7: error: "__WORDSIZE32_SIZE_ULONG" is not defined [-Werror=undef]
 #  if __WORDSIZE32_SIZE_ULONG
       ^~~~~~~~~~~~~~~~~~~~~~~

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Define wordsize.h macros everywhere
  2016-11-10 14:28           ` Joseph Myers
@ 2016-11-10 15:43             ` Steve Ellcey
  0 siblings, 0 replies; 10+ messages in thread
From: Steve Ellcey @ 2016-11-10 15:43 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Adhemerval Zanella, libc-alpha

On Thu, 2016-11-10 at 14:28 +0000, Joseph Myers wrote:
> I see errors in tilepro-linux-gnu builds with this patch:
> 
> ../sysdeps/generic/stdint.h:252:7: error: "__WORDSIZE32_PTRDIFF_LONG"
> is not defined [-Werror=undef]
>  #  if __WORDSIZE32_PTRDIFF_LONG
>        ^~~~~~~~~~~~~~~~~~~~~~~~~
> ../sysdeps/generic/stdint.h:269:7: error: "__WORDSIZE32_SIZE_ULONG"
> is not defined [-Werror=undef]
>  #  if __WORDSIZE32_SIZE_ULONG
>        ^~~~~~~~~~~~~~~~~~~~~~~
> 

Sorry about that, I am not sure how those were missed.  I will check in
this patch as the obvious fix.

Steve Ellcey
sellcey@caviumnetworks.com



2016-11-10  Steve Ellcey  <sellcey@caviumnetworks.com>

	* sysdeps/tile/tilepro/bits/wordsize.h: Define __WORDSIZE32_SIZE_ULONG
	and __WORDSIZE32_PTRDIFF_LONG.


diff --git a/sysdeps/tile/tilepro/bits/wordsize.h b/sysdeps/tile/tilepro/bits/wo
rdsize.h
index 8281538..d2c4a35 100644
--- a/sysdeps/tile/tilepro/bits/wordsize.h
+++ b/sysdeps/tile/tilepro/bits/wordsize.h
@@ -2,3 +2,5 @@
 
 #define __WORDSIZE			32
 #define __WORDSIZE_TIME64_COMPAT32	0
+#define __WORDSIZE32_SIZE_ULONG		0
+#define __WORDSIZE32_PTRDIFF_LONG	0

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-11-10 15:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-26 18:34 [PATCH] Define wordsize.h macros everywhere Steve Ellcey
2016-10-26 19:39 ` Steve Ellcey
2016-10-26 20:07 ` Joseph Myers
2016-10-27 18:45   ` Steve Ellcey
2016-10-27 20:16     ` Adhemerval Zanella
2016-10-28 16:07       ` Steve Ellcey
2016-11-03 20:41         ` Steve Ellcey
2016-11-04  8:16           ` Andreas Schwab
2016-11-10 14:28           ` Joseph Myers
2016-11-10 15:43             ` Steve Ellcey

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).