public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert
  2017-10-16 20:44 [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] Adhemerval Zanella
  2017-10-16 20:44 ` [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets Adhemerval Zanella
@ 2017-10-16 20:44 ` Adhemerval Zanella
  2017-11-06 14:12   ` H.J. Lu
  2017-10-16 21:37 ` [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] H.J. Lu
  2 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2017-10-16 20:44 UTC (permalink / raw)
  To: libc-alpha

Instead of rely on runtime check to assure correct pthread types
size a better strategy would use _Static_assert to trigger an error
on build time (and thus allowing to check to potentially ABI breakage
on cross-compiling make check).

Checked on x86_64-linux-gnu and with a build check for all affected
ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).

	* nptl/tst-typesizes.c: Make sizes check _Static_asserts at
	built time.
---
 ChangeLog            |  3 ++
 nptl/tst-typesizes.c | 77 +++++++++++++---------------------------------------
 2 files changed, 22 insertions(+), 58 deletions(-)

diff --git a/nptl/tst-typesizes.c b/nptl/tst-typesizes.c
index 78ed773..3355614 100644
--- a/nptl/tst-typesizes.c
+++ b/nptl/tst-typesizes.c
@@ -20,56 +20,26 @@
 #include <pthreadP.h>
 #include <semaphore.h>
 
-static const struct
-{
-  const char *name;
-  size_t expected;
-  size_t is;
-} types[] =
-  {
-#define T(t, c) \
-    { #t, c, sizeof (t) }
-    T (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T),
-    T (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T),
-    T (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T),
-    T (pthread_cond_t, __SIZEOF_PTHREAD_COND_T),
-    T (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T),
-    T (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T),
-    T (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T),
-    T (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T),
-    T (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T)
-  };
-
 static int
 do_test (void)
 {
-  int result = 0;
-
-#define TEST_TYPE(name) \
-  printf ("%s: ", #name);						      \
-  if (sizeof (name) != sizeof (((name *) 0)->__size))			      \
-    {									      \
-      printf ("expected %zu, is %zu\n",					      \
-	      sizeof (((name *) 0)->__size), sizeof (name));		      \
-      result = 1;							      \
-    }									      \
-  else									      \
-    puts ("OK")
-
-  TEST_TYPE (pthread_mutex_t);
-  TEST_TYPE (pthread_cond_t);
-  TEST_TYPE (pthread_rwlock_t);
-
-#define TEST_TYPE2(name, internal)					      \
-  printf ("%s: ", #name);						      \
-  if (sizeof (((name *) 0)->__size) < sizeof (internal))		      \
-    {									      \
-      printf ("expected %zu, is %zu\n",					      \
-	      sizeof (((name *) 0)->__size), sizeof (internal));	      \
-      result = 1;							      \
-    }									      \
-  else									      \
-    puts ("OK")
+#define TEST_TYPE(__type, __size) \
+  _Static_assert (sizeof (__type) == __size, \
+		  "sizeof (" #__type ") != " #__size)
+
+  TEST_TYPE (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T);
+  TEST_TYPE (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T);
+  TEST_TYPE (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T);
+  TEST_TYPE (pthread_cond_t, __SIZEOF_PTHREAD_COND_T);
+  TEST_TYPE (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T);
+  TEST_TYPE (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T);
+  TEST_TYPE (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T);
+  TEST_TYPE (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T);
+  TEST_TYPE (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T);
+
+#define TEST_TYPE2(__type, __internal) \
+  _Static_assert (sizeof ((__type *) 0)->__size >= sizeof (__internal), \
+		  "sizeof (" #__type ".__size) > sizeof (" #__internal ")")
 
   TEST_TYPE2 (pthread_attr_t, struct pthread_attr);
   TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr);
@@ -80,16 +50,7 @@ do_test (void)
   TEST_TYPE2 (sem_t, struct new_sem);
   TEST_TYPE2 (sem_t, struct old_sem);
 
-  for (size_t i = 0; i < sizeof (types) / sizeof (types[0]); ++i)
-    if (types[i].expected != types[i].is)
-      {
-	printf ("%s: expected %zu, is %zu\n",
-		types[i].name, types[i].expected, types[i].is);
-	result = 1;
-      }
-
-  return result;
+  return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
-- 
2.7.4

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

* [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298]
@ 2017-10-16 20:44 Adhemerval Zanella
  2017-10-16 20:44 ` [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets Adhemerval Zanella
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2017-10-16 20:44 UTC (permalink / raw)
  To: libc-alpha

It is incorrect to define __PTHREAD_MUTEX_HAVE_PREV to 1 only when
__WORDSIZE == 64.  On x32, for instance, __PTHREAD_MUTEX_HAVE_PREV
should be 1, but it has __WORDSIZE == 32.

This patch defines __PTHREAD_MUTEX_HAVE_PREV for all architectures
and its check is changed from "#ifdef" to "#if" to support values
of 0 or 1.

Checked on x86_64-linux-gnu and with a build for all major ABIs
affected.

	H.J. Lu  <hongjiu.lu@intel.com>
	Adhemerval Zanella  <adhemerval.zanella@linaro.org>

	* nptl/allocatestack.c (allocate_stack): Check if
	__PTHREAD_MUTEX_HAVE_PREV is non-zero, instead if
	__PTHREAD_MUTEX_HAVE_PREV is defined.
	* nptl/descr.h (pthread): Likewise.
	* nptl/nptl-init.c (__pthread_initialize_minimal_internal):
	Likewise.
	* nptl/pthread_create.c (START_THREAD_DEFN): Likewise.
	* sysdeps/nptl/fork.c (__libc_fork): Likewise.
	* sysdeps/nptl/pthread.h (PTHREAD_MUTEX_INITIALIZER): Likewise.
	* sysdeps/nptl/bits/thread-shared-types.h (__pthread_internal_list,
	__pthread_mutex_s): Check __PTHREAD_MUTEX_HAVE_PREV instead of
	__WORDSIZE.
	* sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): New define.
	* sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/arm/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/mips/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/s390/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/sh/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/tile/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
	* sysdeps/x86/nptl/bits/pthreadtypes-arch.h
	(__PTHREAD_MUTEX_HAVE_PREV): Likewise.
---
 ChangeLog                                        | 46 ++++++++++++++++++++++++
 nptl/allocatestack.c                             |  2 +-
 nptl/descr.h                                     |  2 +-
 nptl/nptl-init.c                                 |  2 +-
 nptl/pthread_create.c                            |  4 +--
 sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h    |  5 +++
 sysdeps/alpha/nptl/bits/pthreadtypes-arch.h      |  1 +
 sysdeps/arm/nptl/bits/pthreadtypes-arch.h        |  1 +
 sysdeps/hppa/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/ia64/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/m68k/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h |  1 +
 sysdeps/mips/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/nios2/nptl/bits/pthreadtypes-arch.h      |  1 +
 sysdeps/nptl/bits/thread-shared-types.h          | 12 ++++---
 sysdeps/nptl/fork.c                              |  2 +-
 sysdeps/nptl/pthread.h                           |  2 +-
 sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h    |  1 +
 sysdeps/s390/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/sh/nptl/bits/pthreadtypes-arch.h         |  1 +
 sysdeps/sparc/nptl/bits/pthreadtypes-arch.h      |  1 +
 sysdeps/tile/nptl/bits/pthreadtypes-arch.h       |  1 +
 sysdeps/x86/nptl/bits/pthreadtypes-arch.h        |  5 +++
 23 files changed, 83 insertions(+), 12 deletions(-)

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index ad9add8..1cc7893 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -753,7 +753,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 				  - offsetof (pthread_mutex_t,
 					      __data.__list.__next));
   pd->robust_head.list_op_pending = NULL;
-#ifdef __PTHREAD_MUTEX_HAVE_PREV
+#if __PTHREAD_MUTEX_HAVE_PREV
   pd->robust_prev = &pd->robust_head;
 #endif
   pd->robust_head.list = &pd->robust_head;
diff --git a/nptl/descr.h b/nptl/descr.h
index c5ad0c8..c83b17b 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -169,7 +169,7 @@ struct pthread
   pid_t pid_ununsed;
 
   /* List of robust mutexes the thread is holding.  */
-#ifdef __PTHREAD_MUTEX_HAVE_PREV
+#if __PTHREAD_MUTEX_HAVE_PREV
   void *robust_prev;
   struct robust_list_head robust_head;
 
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 2921607..869e926 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -297,7 +297,7 @@ __pthread_initialize_minimal_internal (void)
 
   /* Initialize the robust mutex data.  */
   {
-#ifdef __PTHREAD_MUTEX_HAVE_PREV
+#if __PTHREAD_MUTEX_HAVE_PREV
     pd->robust_prev = &pd->robust_head;
 #endif
     pd->robust_head.list = &pd->robust_head;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 992331e..51ae60d 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -518,7 +518,7 @@ START_THREAD_DEFN
 
 #ifndef __ASSUME_SET_ROBUST_LIST
   /* If this thread has any robust mutexes locked, handle them now.  */
-# ifdef __PTHREAD_MUTEX_HAVE_PREV
+# if __PTHREAD_MUTEX_HAVE_PREV
   void *robust = pd->robust_head.list;
 # else
   __pthread_slist_t *robust = pd->robust_list.__next;
@@ -536,7 +536,7 @@ START_THREAD_DEFN
 					 __list.__next));
 	  robust = *((void **) robust);
 
-# ifdef __PTHREAD_MUTEX_HAVE_PREV
+# if __PTHREAD_MUTEX_HAVE_PREV
 	  this->__list.__prev = NULL;
 # endif
 	  this->__list.__next = NULL;
diff --git a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
index d13a75d..3c43707 100644
--- a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
@@ -45,6 +45,11 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION	0
+#ifdef __ILP32__
+#define __PTHREAD_MUTEX_HAVE_PREV	0
+#else
+#define __PTHREAD_MUTEX_HAVE_PREV	1
+#endif
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
index b6f6cb1..687028a 100644
--- a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
@@ -33,6 +33,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	1
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
index 3f9eca4..fac38ac 100644
--- a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
@@ -34,6 +34,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
index c158562..7ad0ce7 100644
--- a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
@@ -48,6 +48,7 @@
    pthread_mutex_t is larger than Linuxthreads.  */
 #define __PTHREAD_COMPAT_PADDING_END  int __reserved[2];
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT __attribute__ ((__aligned__(16)))
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
index 631cb33..d456aba 100644
--- a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
@@ -33,6 +33,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	1
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
index 845b9e6..25e93be 100644
--- a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
@@ -35,6 +35,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT __attribute__ ((__aligned__ (4)))
 #define __ONCE_ALIGNMENT __attribute__ ((__aligned__ (4)))
diff --git a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
index d687e2c..b9130b6 100644
--- a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
@@ -35,6 +35,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
index 6aa1bda..c5cc1f8 100644
--- a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
@@ -42,6 +42,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	(_MIPS_SIM == _ABI64)
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
index e2732f9..431da41 100644
--- a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
@@ -35,6 +35,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
index 68b82b6..0d24529 100644
--- a/sysdeps/nptl/bits/thread-shared-types.h
+++ b/sysdeps/nptl/bits/thread-shared-types.h
@@ -59,7 +59,10 @@
 
 /* Common definition of pthread_mutex_t. */
 
-#if __WORDSIZE == 64
+/* __PTHREAD_MUTEX_HAVE_PREV also defines the internal layout of
+   __pthread_mutex_s internal __nusers, __PTHREAD_SPINS_DATA, and
+   __list members.  */
+#if __PTHREAD_MUTEX_HAVE_PREV
 typedef struct __pthread_internal_list
 {
   struct __pthread_internal_list *__prev;
@@ -74,7 +77,7 @@ typedef struct __pthread_internal_slist
 
 /* Lock elision support.  */
 #if __PTHREAD_MUTEX_LOCK_ELISION
-# if __WORDSIZE == 64
+# if __PTHREAD_MUTEX_HAVE_PREV
 #  define __PTHREAD_SPINS_DATA	\
   short __spins;		\
   short __elision
@@ -101,17 +104,16 @@ struct __pthread_mutex_s
   int __lock __LOCK_ALIGNMENT;
   unsigned int __count;
   int __owner;
-#if __WORDSIZE == 64
+#if __PTHREAD_MUTEX_HAVE_PREV
   unsigned int __nusers;
 #endif
   /* KIND must stay at this position in the structure to maintain
      binary compatibility with static initializers.  */
   int __kind;
   __PTHREAD_COMPAT_PADDING_MID
-#if __WORDSIZE == 64
+#if __PTHREAD_MUTEX_HAVE_PREV
   __PTHREAD_SPINS_DATA;
   __pthread_list_t __list;
-# define __PTHREAD_MUTEX_HAVE_PREV      1
 #else
   unsigned int __nusers;
   __extension__ union
diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
index 4bb87e2..48676c2 100644
--- a/sysdeps/nptl/fork.c
+++ b/sysdeps/nptl/fork.c
@@ -166,7 +166,7 @@ __libc_fork (void)
 	 inherit the correct value from the parent.  We do not need to clear
 	 the pending operation because it must have been zero when fork was
 	 called.  */
-# ifdef __PTHREAD_MUTEX_HAVE_PREV
+# if __PTHREAD_MUTEX_HAVE_PREV
       self->robust_prev = &self->robust_head;
 # endif
       self->robust_head.list = &self->robust_head;
diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
index 632ea7b..2b2b386 100644
--- a/sysdeps/nptl/pthread.h
+++ b/sysdeps/nptl/pthread.h
@@ -83,7 +83,7 @@ enum
 #endif
 
 
-#ifdef __PTHREAD_MUTEX_HAVE_PREV
+#if __PTHREAD_MUTEX_HAVE_PREV
 # define PTHREAD_MUTEX_INITIALIZER \
   { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
 # ifdef __USE_GNU
diff --git a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
index f29119b..d56897b 100644
--- a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
@@ -42,6 +42,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    1
+#define __PTHREAD_MUTEX_HAVE_PREV	(__WORDSIZE == 64)
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
index 3a9ac57..e4c164a 100644
--- a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
@@ -45,6 +45,7 @@
 #else
 #define __PTHREAD_MUTEX_LOCK_ELISION	0
 #endif
+#define __PTHREAD_MUTEX_HAVE_PREV	(__WORDSIZE == 64)
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
index b2615fe..711e7bb 100644
--- a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
@@ -34,6 +34,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	0
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
index 1e188cf..6e7f47a 100644
--- a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
@@ -43,6 +43,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	(__WORDSIZE == 64)
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
index 145ee42..c753a9b 100644
--- a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
@@ -43,6 +43,7 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    0
+#define __PTHREAD_MUTEX_HAVE_PREV	(__WORDSIZE == 64)
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
diff --git a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
index fd86806..1df1e02 100644
--- a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
+++ b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
@@ -51,6 +51,11 @@
 #define __PTHREAD_COMPAT_PADDING_MID
 #define __PTHREAD_COMPAT_PADDING_END
 #define __PTHREAD_MUTEX_LOCK_ELISION    1
+#ifdef __x86_64__
+# define __PTHREAD_MUTEX_HAVE_PREV	1
+#else
+# define __PTHREAD_MUTEX_HAVE_PREV	0
+#endif
 
 #define __LOCK_ALIGNMENT
 #define __ONCE_ALIGNMENT
-- 
2.7.4

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

* [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets
  2017-10-16 20:44 [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] Adhemerval Zanella
@ 2017-10-16 20:44 ` Adhemerval Zanella
  2017-10-16 21:36   ` H.J. Lu
  2017-10-16 20:44 ` [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Adhemerval Zanella
  2017-10-16 21:37 ` [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] H.J. Lu
  2 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2017-10-16 20:44 UTC (permalink / raw)
  To: libc-alpha

This patch adds a new build test to check for internal fields
offsets uses on pthread_mutex_t static initialization macros
(PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).

Currently the only field which is statically initialized to a
non zero/null value is pthread_mutex_t.__data.__kind value.  A new
internal header (pthread-offset.h) is added to each major ABI with
the reference value.

Checked on x86_64-linux-gnu and with a build check for all affected
ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).

	* nptl/Makefile (tests-internal): Add tst-offsets.
	* nptl/tst-offsets.c: New file.
	* sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.
	* sysdeps/alpha/nptl/pthread-offsets.h: Likewise.
	* sysdeps/arm/nptl/pthread-offsets.h: Likewise.
	* sysdeps/hppa/nptl/pthread-offsets.h: Likewise.
	* sysdeps/i386/nptl/pthread-offsets.h: Likewise.
	* sysdeps/ia64/nptl/pthread-offsets.h: Likewise.
	* sysdeps/m68k/nptl/pthread-offsets.h: Likewise.
	* sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.
	* sysdeps/mips/nptl/pthread-offsets.h: Likewise.
	* sysdeps/nios2/nptl/pthread-offsets.h: Likewise.
	* sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.
	* sysdeps/s390/nptl/pthread-offsets.h: Likewise.
	* sysdeps/sh/nptl/pthread-offsets.h: Likewise.
	* sysdeps/sparc/nptl/pthread-offsets.h: Likewise.
	* sysdeps/tile/nptl/pthread-offsets.h: Likewise.
	* sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.
---
 ChangeLog                                 | 19 ++++++++++++++
 nptl/Makefile                             |  2 +-
 nptl/tst-offsets.c                        | 41 +++++++++++++++++++++++++++++++
 sysdeps/aarch64/nptl/pthread-offsets.h    |  1 +
 sysdeps/alpha/nptl/pthread-offsets.h      |  1 +
 sysdeps/arm/nptl/pthread-offsets.h        |  1 +
 sysdeps/hppa/nptl/pthread-offsets.h       |  1 +
 sysdeps/i386/nptl/pthread-offsets.h       |  1 +
 sysdeps/ia64/nptl/pthread-offsets.h       |  1 +
 sysdeps/m68k/nptl/pthread-offsets.h       |  1 +
 sysdeps/microblaze/nptl/pthread-offsets.h |  1 +
 sysdeps/mips/nptl/pthread-offsets.h       |  5 ++++
 sysdeps/nios2/nptl/pthread-offsets.h      |  1 +
 sysdeps/powerpc/nptl/pthread-offsets.h    |  7 ++++++
 sysdeps/s390/nptl/pthread-offsets.h       |  7 ++++++
 sysdeps/sh/nptl/pthread-offsets.h         |  1 +
 sysdeps/sparc/nptl/pthread-offsets.h      |  7 ++++++
 sysdeps/tile/nptl/pthread-offsets.h       |  7 ++++++
 sysdeps/x86_64/nptl/pthread-offsets.h     |  1 +
 19 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 nptl/tst-offsets.c
 create mode 100644 sysdeps/aarch64/nptl/pthread-offsets.h
 create mode 100644 sysdeps/alpha/nptl/pthread-offsets.h
 create mode 100644 sysdeps/arm/nptl/pthread-offsets.h
 create mode 100644 sysdeps/hppa/nptl/pthread-offsets.h
 create mode 100644 sysdeps/i386/nptl/pthread-offsets.h
 create mode 100644 sysdeps/ia64/nptl/pthread-offsets.h
 create mode 100644 sysdeps/m68k/nptl/pthread-offsets.h
 create mode 100644 sysdeps/microblaze/nptl/pthread-offsets.h
 create mode 100644 sysdeps/mips/nptl/pthread-offsets.h
 create mode 100644 sysdeps/nios2/nptl/pthread-offsets.h
 create mode 100644 sysdeps/powerpc/nptl/pthread-offsets.h
 create mode 100644 sysdeps/s390/nptl/pthread-offsets.h
 create mode 100644 sysdeps/sh/nptl/pthread-offsets.h
 create mode 100644 sysdeps/sparc/nptl/pthread-offsets.h
 create mode 100644 sysdeps/tile/nptl/pthread-offsets.h
 create mode 100644 sysdeps/x86_64/nptl/pthread-offsets.h

diff --git a/nptl/Makefile b/nptl/Makefile
index d819349..7492b06 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -304,7 +304,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
 	tst-thread_local1 tst-mutex-errorcheck tst-robust10 \
 	tst-robust-fork tst-create-detached tst-memstream
 
-tests-internal := tst-typesizes \
+tests-internal := tst-typesizes tst-offsets \
 		  tst-rwlock19 tst-rwlock20 \
 		  tst-sem11 tst-sem12 tst-sem13 \
 		  tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \
diff --git a/nptl/tst-offsets.c b/nptl/tst-offsets.c
new file mode 100644
index 0000000..1aa8a0e
--- /dev/null
+++ b/nptl/tst-offsets.c
@@ -0,0 +1,41 @@
+/* Check pthread internal offsets.
+   Copyright (C) 2017 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 <stdio.h>
+#include <pthreadP.h>
+#include <semaphore.h>
+
+#include <pthread-offsets.h>
+
+#define STR_HELPER(x) #x
+#define STR(x) STR_HELPER(x)
+
+static int
+do_test (void)
+{
+  /* Check if internal fields in pthread_mutex_t used by static initializers
+     have the expected offset.  */
+  _Static_assert (offsetof (pthread_mutex_t, __data.__kind) ==
+		  __PTHREAD_MUTEX_KIND_OFFSET,
+		  "offset of __kind field != "
+		  STR (__PTHREAD_MUTEX_KIND_OFFSET));
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/aarch64/nptl/pthread-offsets.h b/sysdeps/aarch64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..aaca502
--- /dev/null
+++ b/sysdeps/aarch64/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  16
diff --git a/sysdeps/alpha/nptl/pthread-offsets.h b/sysdeps/alpha/nptl/pthread-offsets.h
new file mode 100644
index 0000000..aaca502
--- /dev/null
+++ b/sysdeps/alpha/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  16
diff --git a/sysdeps/arm/nptl/pthread-offsets.h b/sysdeps/arm/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/arm/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/hppa/nptl/pthread-offsets.h b/sysdeps/hppa/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/hppa/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/i386/nptl/pthread-offsets.h b/sysdeps/i386/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/i386/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/ia64/nptl/pthread-offsets.h b/sysdeps/ia64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..aaca502
--- /dev/null
+++ b/sysdeps/ia64/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  16
diff --git a/sysdeps/m68k/nptl/pthread-offsets.h b/sysdeps/m68k/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/m68k/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/microblaze/nptl/pthread-offsets.h b/sysdeps/microblaze/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/microblaze/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/mips/nptl/pthread-offsets.h b/sysdeps/mips/nptl/pthread-offsets.h
new file mode 100644
index 0000000..6dd3dea
--- /dev/null
+++ b/sysdeps/mips/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@
+#if _MIPS_SIM == _ABI64
+# define __PTHREAD_MUTEX_KIND_OFFSET  16
+#else
+# define __PTHREAD_MUTEX_KIND_OFFSET  12
+#endif
diff --git a/sysdeps/nios2/nptl/pthread-offsets.h b/sysdeps/nios2/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/nios2/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/powerpc/nptl/pthread-offsets.h b/sysdeps/powerpc/nptl/pthread-offsets.h
new file mode 100644
index 0000000..f88961b
--- /dev/null
+++ b/sysdeps/powerpc/nptl/pthread-offsets.h
@@ -0,0 +1,7 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_KIND_OFFSET  16
+#else
+# define __PTHREAD_MUTEX_KIND_OFFSET  12
+#endif
diff --git a/sysdeps/s390/nptl/pthread-offsets.h b/sysdeps/s390/nptl/pthread-offsets.h
new file mode 100644
index 0000000..f88961b
--- /dev/null
+++ b/sysdeps/s390/nptl/pthread-offsets.h
@@ -0,0 +1,7 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_KIND_OFFSET  16
+#else
+# define __PTHREAD_MUTEX_KIND_OFFSET  12
+#endif
diff --git a/sysdeps/sh/nptl/pthread-offsets.h b/sysdeps/sh/nptl/pthread-offsets.h
new file mode 100644
index 0000000..235677f
--- /dev/null
+++ b/sysdeps/sh/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  12
diff --git a/sysdeps/sparc/nptl/pthread-offsets.h b/sysdeps/sparc/nptl/pthread-offsets.h
new file mode 100644
index 0000000..f88961b
--- /dev/null
+++ b/sysdeps/sparc/nptl/pthread-offsets.h
@@ -0,0 +1,7 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_KIND_OFFSET  16
+#else
+# define __PTHREAD_MUTEX_KIND_OFFSET  12
+#endif
diff --git a/sysdeps/tile/nptl/pthread-offsets.h b/sysdeps/tile/nptl/pthread-offsets.h
new file mode 100644
index 0000000..f88961b
--- /dev/null
+++ b/sysdeps/tile/nptl/pthread-offsets.h
@@ -0,0 +1,7 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __PTHREAD_MUTEX_KIND_OFFSET  16
+#else
+# define __PTHREAD_MUTEX_KIND_OFFSET  12
+#endif
diff --git a/sysdeps/x86_64/nptl/pthread-offsets.h b/sysdeps/x86_64/nptl/pthread-offsets.h
new file mode 100644
index 0000000..aaca502
--- /dev/null
+++ b/sysdeps/x86_64/nptl/pthread-offsets.h
@@ -0,0 +1 @@
+#define __PTHREAD_MUTEX_KIND_OFFSET  16
-- 
2.7.4

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

* Re: [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets
  2017-10-16 20:44 ` [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets Adhemerval Zanella
@ 2017-10-16 21:36   ` H.J. Lu
  2017-10-17 13:47     ` Adhemerval Zanella
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2017-10-16 21:36 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Mon, Oct 16, 2017 at 1:44 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> This patch adds a new build test to check for internal fields
> offsets uses on pthread_mutex_t static initialization macros
> (PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
> PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and
> PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).
>
> Currently the only field which is statically initialized to a
> non zero/null value is pthread_mutex_t.__data.__kind value.  A new
> internal header (pthread-offset.h) is added to each major ABI with
> the reference value.
>
> Checked on x86_64-linux-gnu and with a build check for all affected
> ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
> hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
> microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
> mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
> s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
> sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
> tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).
>
>         * nptl/Makefile (tests-internal): Add tst-offsets.
>         * nptl/tst-offsets.c: New file.
>         * sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/alpha/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/arm/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/hppa/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/i386/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/ia64/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/m68k/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/mips/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/nios2/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/s390/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/sh/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/sparc/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/tile/nptl/pthread-offsets.h: Likewise.
>         * sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.
> ---
>

__PTHREAD_MUTEX_HAVE_PREV affects quite few offsets.
We should check all of offsets which depend on it.


-- 
H.J.

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

* Re: [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298]
  2017-10-16 20:44 [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] Adhemerval Zanella
  2017-10-16 20:44 ` [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets Adhemerval Zanella
  2017-10-16 20:44 ` [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Adhemerval Zanella
@ 2017-10-16 21:37 ` H.J. Lu
  2 siblings, 0 replies; 7+ messages in thread
From: H.J. Lu @ 2017-10-16 21:37 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Mon, Oct 16, 2017 at 1:44 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> It is incorrect to define __PTHREAD_MUTEX_HAVE_PREV to 1 only when
> __WORDSIZE == 64.  On x32, for instance, __PTHREAD_MUTEX_HAVE_PREV
> should be 1, but it has __WORDSIZE == 32.
>
> This patch defines __PTHREAD_MUTEX_HAVE_PREV for all architectures
> and its check is changed from "#ifdef" to "#if" to support values
> of 0 or 1.
>
> Checked on x86_64-linux-gnu and with a build for all major ABIs
> affected.
>
>         H.J. Lu  <hongjiu.lu@intel.com>
>         Adhemerval Zanella  <adhemerval.zanella@linaro.org>

Missing [BZ #22298] here.  Otherwise, LGTM.

Thanks.

>         * nptl/allocatestack.c (allocate_stack): Check if
>         __PTHREAD_MUTEX_HAVE_PREV is non-zero, instead if
>         __PTHREAD_MUTEX_HAVE_PREV is defined.
>         * nptl/descr.h (pthread): Likewise.
>         * nptl/nptl-init.c (__pthread_initialize_minimal_internal):
>         Likewise.
>         * nptl/pthread_create.c (START_THREAD_DEFN): Likewise.
>         * sysdeps/nptl/fork.c (__libc_fork): Likewise.
>         * sysdeps/nptl/pthread.h (PTHREAD_MUTEX_INITIALIZER): Likewise.
>         * sysdeps/nptl/bits/thread-shared-types.h (__pthread_internal_list,
>         __pthread_mutex_s): Check __PTHREAD_MUTEX_HAVE_PREV instead of
>         __WORDSIZE.
>         * sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): New define.
>         * sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/arm/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/mips/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/s390/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/sh/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/tile/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
>         * sysdeps/x86/nptl/bits/pthreadtypes-arch.h
>         (__PTHREAD_MUTEX_HAVE_PREV): Likewise.
> ---
>  ChangeLog                                        | 46 ++++++++++++++++++++++++
>  nptl/allocatestack.c                             |  2 +-
>  nptl/descr.h                                     |  2 +-
>  nptl/nptl-init.c                                 |  2 +-
>  nptl/pthread_create.c                            |  4 +--
>  sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h    |  5 +++
>  sysdeps/alpha/nptl/bits/pthreadtypes-arch.h      |  1 +
>  sysdeps/arm/nptl/bits/pthreadtypes-arch.h        |  1 +
>  sysdeps/hppa/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/ia64/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/m68k/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h |  1 +
>  sysdeps/mips/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/nios2/nptl/bits/pthreadtypes-arch.h      |  1 +
>  sysdeps/nptl/bits/thread-shared-types.h          | 12 ++++---
>  sysdeps/nptl/fork.c                              |  2 +-
>  sysdeps/nptl/pthread.h                           |  2 +-
>  sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h    |  1 +
>  sysdeps/s390/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/sh/nptl/bits/pthreadtypes-arch.h         |  1 +
>  sysdeps/sparc/nptl/bits/pthreadtypes-arch.h      |  1 +
>  sysdeps/tile/nptl/bits/pthreadtypes-arch.h       |  1 +
>  sysdeps/x86/nptl/bits/pthreadtypes-arch.h        |  5 +++
>  23 files changed, 83 insertions(+), 12 deletions(-)
>
> diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
> index ad9add8..1cc7893 100644
> --- a/nptl/allocatestack.c
> +++ b/nptl/allocatestack.c
> @@ -753,7 +753,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
>                                   - offsetof (pthread_mutex_t,
>                                               __data.__list.__next));
>    pd->robust_head.list_op_pending = NULL;
> -#ifdef __PTHREAD_MUTEX_HAVE_PREV
> +#if __PTHREAD_MUTEX_HAVE_PREV
>    pd->robust_prev = &pd->robust_head;
>  #endif
>    pd->robust_head.list = &pd->robust_head;
> diff --git a/nptl/descr.h b/nptl/descr.h
> index c5ad0c8..c83b17b 100644
> --- a/nptl/descr.h
> +++ b/nptl/descr.h
> @@ -169,7 +169,7 @@ struct pthread
>    pid_t pid_ununsed;
>
>    /* List of robust mutexes the thread is holding.  */
> -#ifdef __PTHREAD_MUTEX_HAVE_PREV
> +#if __PTHREAD_MUTEX_HAVE_PREV
>    void *robust_prev;
>    struct robust_list_head robust_head;
>
> diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
> index 2921607..869e926 100644
> --- a/nptl/nptl-init.c
> +++ b/nptl/nptl-init.c
> @@ -297,7 +297,7 @@ __pthread_initialize_minimal_internal (void)
>
>    /* Initialize the robust mutex data.  */
>    {
> -#ifdef __PTHREAD_MUTEX_HAVE_PREV
> +#if __PTHREAD_MUTEX_HAVE_PREV
>      pd->robust_prev = &pd->robust_head;
>  #endif
>      pd->robust_head.list = &pd->robust_head;
> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
> index 992331e..51ae60d 100644
> --- a/nptl/pthread_create.c
> +++ b/nptl/pthread_create.c
> @@ -518,7 +518,7 @@ START_THREAD_DEFN
>
>  #ifndef __ASSUME_SET_ROBUST_LIST
>    /* If this thread has any robust mutexes locked, handle them now.  */
> -# ifdef __PTHREAD_MUTEX_HAVE_PREV
> +# if __PTHREAD_MUTEX_HAVE_PREV
>    void *robust = pd->robust_head.list;
>  # else
>    __pthread_slist_t *robust = pd->robust_list.__next;
> @@ -536,7 +536,7 @@ START_THREAD_DEFN
>                                          __list.__next));
>           robust = *((void **) robust);
>
> -# ifdef __PTHREAD_MUTEX_HAVE_PREV
> +# if __PTHREAD_MUTEX_HAVE_PREV
>           this->__list.__prev = NULL;
>  # endif
>           this->__list.__next = NULL;
> diff --git a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
> index d13a75d..3c43707 100644
> --- a/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/aarch64/nptl/bits/pthreadtypes-arch.h
> @@ -45,6 +45,11 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION   0
> +#ifdef __ILP32__
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
> +#else
> +#define __PTHREAD_MUTEX_HAVE_PREV      1
> +#endif
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
> index b6f6cb1..687028a 100644
> --- a/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
> @@ -33,6 +33,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      1
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
> index 3f9eca4..fac38ac 100644
> --- a/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/arm/nptl/bits/pthreadtypes-arch.h
> @@ -34,6 +34,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
> index c158562..7ad0ce7 100644
> --- a/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/hppa/nptl/bits/pthreadtypes-arch.h
> @@ -48,6 +48,7 @@
>     pthread_mutex_t is larger than Linuxthreads.  */
>  #define __PTHREAD_COMPAT_PADDING_END  int __reserved[2];
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT __attribute__ ((__aligned__(16)))
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
> index 631cb33..d456aba 100644
> --- a/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
> @@ -33,6 +33,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      1
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
> index 845b9e6..25e93be 100644
> --- a/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/m68k/nptl/bits/pthreadtypes-arch.h
> @@ -35,6 +35,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT __attribute__ ((__aligned__ (4)))
>  #define __ONCE_ALIGNMENT __attribute__ ((__aligned__ (4)))
> diff --git a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
> index d687e2c..b9130b6 100644
> --- a/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
> @@ -35,6 +35,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
> index 6aa1bda..c5cc1f8 100644
> --- a/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/mips/nptl/bits/pthreadtypes-arch.h
> @@ -42,6 +42,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      (_MIPS_SIM == _ABI64)
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
> index e2732f9..431da41 100644
> --- a/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/nios2/nptl/bits/pthreadtypes-arch.h
> @@ -35,6 +35,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
> index 68b82b6..0d24529 100644
> --- a/sysdeps/nptl/bits/thread-shared-types.h
> +++ b/sysdeps/nptl/bits/thread-shared-types.h
> @@ -59,7 +59,10 @@
>
>  /* Common definition of pthread_mutex_t. */
>
> -#if __WORDSIZE == 64
> +/* __PTHREAD_MUTEX_HAVE_PREV also defines the internal layout of
> +   __pthread_mutex_s internal __nusers, __PTHREAD_SPINS_DATA, and
> +   __list members.  */
> +#if __PTHREAD_MUTEX_HAVE_PREV
>  typedef struct __pthread_internal_list
>  {
>    struct __pthread_internal_list *__prev;
> @@ -74,7 +77,7 @@ typedef struct __pthread_internal_slist
>
>  /* Lock elision support.  */
>  #if __PTHREAD_MUTEX_LOCK_ELISION
> -# if __WORDSIZE == 64
> +# if __PTHREAD_MUTEX_HAVE_PREV
>  #  define __PTHREAD_SPINS_DATA \
>    short __spins;               \
>    short __elision
> @@ -101,17 +104,16 @@ struct __pthread_mutex_s
>    int __lock __LOCK_ALIGNMENT;
>    unsigned int __count;
>    int __owner;
> -#if __WORDSIZE == 64
> +#if __PTHREAD_MUTEX_HAVE_PREV
>    unsigned int __nusers;
>  #endif
>    /* KIND must stay at this position in the structure to maintain
>       binary compatibility with static initializers.  */
>    int __kind;
>    __PTHREAD_COMPAT_PADDING_MID
> -#if __WORDSIZE == 64
> +#if __PTHREAD_MUTEX_HAVE_PREV
>    __PTHREAD_SPINS_DATA;
>    __pthread_list_t __list;
> -# define __PTHREAD_MUTEX_HAVE_PREV      1
>  #else
>    unsigned int __nusers;
>    __extension__ union
> diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
> index 4bb87e2..48676c2 100644
> --- a/sysdeps/nptl/fork.c
> +++ b/sysdeps/nptl/fork.c
> @@ -166,7 +166,7 @@ __libc_fork (void)
>          inherit the correct value from the parent.  We do not need to clear
>          the pending operation because it must have been zero when fork was
>          called.  */
> -# ifdef __PTHREAD_MUTEX_HAVE_PREV
> +# if __PTHREAD_MUTEX_HAVE_PREV
>        self->robust_prev = &self->robust_head;
>  # endif
>        self->robust_head.list = &self->robust_head;
> diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
> index 632ea7b..2b2b386 100644
> --- a/sysdeps/nptl/pthread.h
> +++ b/sysdeps/nptl/pthread.h
> @@ -83,7 +83,7 @@ enum
>  #endif
>
>
> -#ifdef __PTHREAD_MUTEX_HAVE_PREV
> +#if __PTHREAD_MUTEX_HAVE_PREV
>  # define PTHREAD_MUTEX_INITIALIZER \
>    { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
>  # ifdef __USE_GNU
> diff --git a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
> index f29119b..d56897b 100644
> --- a/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
> @@ -42,6 +42,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    1
> +#define __PTHREAD_MUTEX_HAVE_PREV      (__WORDSIZE == 64)
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
> index 3a9ac57..e4c164a 100644
> --- a/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/s390/nptl/bits/pthreadtypes-arch.h
> @@ -45,6 +45,7 @@
>  #else
>  #define __PTHREAD_MUTEX_LOCK_ELISION   0
>  #endif
> +#define __PTHREAD_MUTEX_HAVE_PREV      (__WORDSIZE == 64)
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
> index b2615fe..711e7bb 100644
> --- a/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/sh/nptl/bits/pthreadtypes-arch.h
> @@ -34,6 +34,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      0
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
> index 1e188cf..6e7f47a 100644
> --- a/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
> @@ -43,6 +43,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      (__WORDSIZE == 64)
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
> index 145ee42..c753a9b 100644
> --- a/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/tile/nptl/bits/pthreadtypes-arch.h
> @@ -43,6 +43,7 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    0
> +#define __PTHREAD_MUTEX_HAVE_PREV      (__WORDSIZE == 64)
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> diff --git a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
> index fd86806..1df1e02 100644
> --- a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
> +++ b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h
> @@ -51,6 +51,11 @@
>  #define __PTHREAD_COMPAT_PADDING_MID
>  #define __PTHREAD_COMPAT_PADDING_END
>  #define __PTHREAD_MUTEX_LOCK_ELISION    1
> +#ifdef __x86_64__
> +# define __PTHREAD_MUTEX_HAVE_PREV     1
> +#else
> +# define __PTHREAD_MUTEX_HAVE_PREV     0
> +#endif
>
>  #define __LOCK_ALIGNMENT
>  #define __ONCE_ALIGNMENT
> --
> 2.7.4
>



-- 
H.J.

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

* Re: [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets
  2017-10-16 21:36   ` H.J. Lu
@ 2017-10-17 13:47     ` Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2017-10-17 13:47 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library



On 16/10/2017 19:36, H.J. Lu wrote:
> On Mon, Oct 16, 2017 at 1:44 PM, Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>> This patch adds a new build test to check for internal fields
>> offsets uses on pthread_mutex_t static initialization macros
>> (PTHREAD_MUTEX_INITIALIZER, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
>> PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, and
>> PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP).
>>
>> Currently the only field which is statically initialized to a
>> non zero/null value is pthread_mutex_t.__data.__kind value.  A new
>> internal header (pthread-offset.h) is added to each major ABI with
>> the reference value.
>>
>> Checked on x86_64-linux-gnu and with a build check for all affected
>> ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
>> hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
>> microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
>> mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
>> s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
>> sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
>> tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).
>>
>>         * nptl/Makefile (tests-internal): Add tst-offsets.
>>         * nptl/tst-offsets.c: New file.
>>         * sysdeps/aarch64/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/alpha/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/arm/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/hppa/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/i386/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/ia64/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/m68k/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/microblaze/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/mips/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/nios2/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/powerpc/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/s390/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/sh/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/sparc/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/tile/nptl/pthread-offsets.h: Likewise.
>>         * sysdeps/x86_64/nptl/pthread-offsets.h: Likewise.
>> ---
>>
> 
> __PTHREAD_MUTEX_HAVE_PREV affects quite few offsets.
> We should check all of offsets which depend on it.

I thought about it, however currently only __data.__kind member is initialized
to non zero value by the static initializers (and thus the only member really
affected by ABI change by change in internal layout). My idea is to make the
test a place-holder in case change the static initializers to user different
values. 

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

* Re: [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert
  2017-10-16 20:44 ` [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Adhemerval Zanella
@ 2017-11-06 14:12   ` H.J. Lu
  0 siblings, 0 replies; 7+ messages in thread
From: H.J. Lu @ 2017-11-06 14:12 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Mon, Oct 16, 2017 at 1:44 PM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> Instead of rely on runtime check to assure correct pthread types
> size a better strategy would use _Static_assert to trigger an error
> on build time (and thus allowing to check to potentially ABI breakage
> on cross-compiling make check).
>
> Checked on x86_64-linux-gnu and with a build check for all affected
> ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
> hppa-linux-gnu, i686-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
> microblaze-linux-gnu, mips64-linux-gnu, mips64-n32-linux-gnu,
> mips-linux-gnu, powerpc64le-linux-gnu, powerpc-linux-gnu,
> s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu, sparc64-linux-gnu,
> sparcv9-linux-gnu, tilegx-linux-gnu, tilegx-linux-gnu-x32,
> tilepro-linux-gnu, x86_64-linux-gnu, and x86_64-linux-x32).
>
>         * nptl/tst-typesizes.c: Make sizes check _Static_asserts at
>         built time.
> ---
>  ChangeLog            |  3 ++
>  nptl/tst-typesizes.c | 77 +++++++++++++---------------------------------------
>  2 files changed, 22 insertions(+), 58 deletions(-)
>
> diff --git a/nptl/tst-typesizes.c b/nptl/tst-typesizes.c
> index 78ed773..3355614 100644
> --- a/nptl/tst-typesizes.c
> +++ b/nptl/tst-typesizes.c
> @@ -20,56 +20,26 @@
>  #include <pthreadP.h>
>  #include <semaphore.h>
>
> -static const struct
> -{
> -  const char *name;
> -  size_t expected;
> -  size_t is;
> -} types[] =
> -  {
> -#define T(t, c) \
> -    { #t, c, sizeof (t) }
> -    T (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T),
> -    T (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T),
> -    T (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T),
> -    T (pthread_cond_t, __SIZEOF_PTHREAD_COND_T),
> -    T (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T),
> -    T (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T),
> -    T (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T),
> -    T (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T),
> -    T (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T)
> -  };
> -
>  static int
>  do_test (void)
>  {
> -  int result = 0;
> -
> -#define TEST_TYPE(name) \
> -  printf ("%s: ", #name);                                                    \
> -  if (sizeof (name) != sizeof (((name *) 0)->__size))                        \
> -    {                                                                        \
> -      printf ("expected %zu, is %zu\n",                                              \
> -             sizeof (((name *) 0)->__size), sizeof (name));                  \
> -      result = 1;                                                            \
> -    }                                                                        \
> -  else                                                                       \
> -    puts ("OK")
> -
> -  TEST_TYPE (pthread_mutex_t);
> -  TEST_TYPE (pthread_cond_t);
> -  TEST_TYPE (pthread_rwlock_t);
> -
> -#define TEST_TYPE2(name, internal)                                           \
> -  printf ("%s: ", #name);                                                    \
> -  if (sizeof (((name *) 0)->__size) < sizeof (internal))                     \
> -    {                                                                        \
> -      printf ("expected %zu, is %zu\n",                                              \
> -             sizeof (((name *) 0)->__size), sizeof (internal));              \
> -      result = 1;                                                            \
> -    }                                                                        \
> -  else                                                                       \
> -    puts ("OK")
> +#define TEST_TYPE(__type, __size) \
> +  _Static_assert (sizeof (__type) == __size, \
> +                 "sizeof (" #__type ") != " #__size)
> +
> +  TEST_TYPE (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T);
> +  TEST_TYPE (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T);
> +  TEST_TYPE (pthread_mutexattr_t, __SIZEOF_PTHREAD_MUTEXATTR_T);
> +  TEST_TYPE (pthread_cond_t, __SIZEOF_PTHREAD_COND_T);
> +  TEST_TYPE (pthread_condattr_t, __SIZEOF_PTHREAD_CONDATTR_T);
> +  TEST_TYPE (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T);
> +  TEST_TYPE (pthread_rwlockattr_t, __SIZEOF_PTHREAD_RWLOCKATTR_T);
> +  TEST_TYPE (pthread_barrier_t, __SIZEOF_PTHREAD_BARRIER_T);
> +  TEST_TYPE (pthread_barrierattr_t, __SIZEOF_PTHREAD_BARRIERATTR_T);
> +
> +#define TEST_TYPE2(__type, __internal) \
> +  _Static_assert (sizeof ((__type *) 0)->__size >= sizeof (__internal), \
> +                 "sizeof (" #__type ".__size) > sizeof (" #__internal ")")
>
>    TEST_TYPE2 (pthread_attr_t, struct pthread_attr);
>    TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr);
> @@ -80,16 +50,7 @@ do_test (void)
>    TEST_TYPE2 (sem_t, struct new_sem);
>    TEST_TYPE2 (sem_t, struct old_sem);
>
> -  for (size_t i = 0; i < sizeof (types) / sizeof (types[0]); ++i)
> -    if (types[i].expected != types[i].is)
> -      {
> -       printf ("%s: expected %zu, is %zu\n",
> -               types[i].name, types[i].expected, types[i].is);
> -       result = 1;
> -      }
> -
> -  return result;
> +  return 0;
>  }
>
> -#define TEST_FUNCTION do_test ()
> -#include "../test-skeleton.c"
> +#include <support/test-driver.c>
> --
> 2.7.4
>

LGTM.

Thanks.

-- 
H.J.

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

end of thread, other threads:[~2017-11-06 14:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 20:44 [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] Adhemerval Zanella
2017-10-16 20:44 ` [PATCH 3/3] nptl: Add tests for internal pthread_mutex_t offsets Adhemerval Zanella
2017-10-16 21:36   ` H.J. Lu
2017-10-17 13:47     ` Adhemerval Zanella
2017-10-16 20:44 ` [PATCH 2/3] nptl: Change tst-typesizes to _Static_assert Adhemerval Zanella
2017-11-06 14:12   ` H.J. Lu
2017-10-16 21:37 ` [PATCH 1/3] Define __PTHREAD_MUTEX_HAVE_PREV for all architectures [BZ #22298] H.J. Lu

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