From patchwork Sun Oct 15 15:11:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 23578 Received: (qmail 81528 invoked by alias); 15 Oct 2017 15:11:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 81518 invoked by uid 89); 15 Oct 2017 15:11:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:74.125.83.68, H*RU:74.125.83.68 X-HELO: mail-pg0-f68.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=NWB/pS3G0/TnYV5/792ulrL46wKv/QJ5PGe0FUw6cAg=; b=bhHW5711NjjsxHGKyJI7zxI8nlWEf+2oyTYNRuhB9ODnhV8ffFR0z9qMhRaeid/Y9r jnth7kb/4Fhykda+DLn8rN8MukftTQgGKoz215MqVX7FNwOoKqVbSGou/TJgqrBck7r2 pN4PrNnYSAYr0w1RJmds0pL4ziJblAg+c6qysfJ3W13SiwGY2iTbwwO4hddvCdZ2Bn/V jcGYT0WB2xUrMzj2feSa0nUA0YAh0ht+2tNMjI/OImyGhjL9LyXeZRSnT0pZLFq1y3YJ chyxzNIb7E1dxR2I/nx6b+rqQN7kryHWE09EXd5SHrpBntVezMnFaVLq7mWWyKQTDgft rbZg== X-Gm-Message-State: AMCzsaVFr5SsNt+J2Q0McbDuMVsHDLTzkWlT0AAG6jZALmwzA7NOiHVW b143s9EUZZ5pGKxZBB2Vr1p3Ag== X-Google-Smtp-Source: AOwi7QBmT1t/sS1aOrIyLZnGjWusxFrs8M9v1o/6s8MNpto7WbmExGK5zJs2Po1XPkHzpLR9LXD5rA== X-Received: by 10.98.213.194 with SMTP id d185mr6406675pfg.107.1508080262074; Sun, 15 Oct 2017 08:11:02 -0700 (PDT) Date: Sun, 15 Oct 2017 08:11:00 -0700 From: "H.J. Lu" To: GNU C Library Cc: Adhemerval Zanella Subject: [PATCH] Define __PTHREAD_MUTEX_HAVE_PREV only if undefined [BZ #22298] Message-ID: <20171015151100.GA29201@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) It is incorrect to define __PTHREAD_MUTEX_HAVE_PREV to 1 only when __WORDSIZE == 64. For x32, __PTHREAD_MUTEX_HAVE_PREV should be 1, but it has __WORDSIZE == 32. This patch defines __PTHREAD_MUTEX_HAVE_PREV based on __WORDSIZE only if it is undefined. __PTHREAD_MUTEX_HAVE_PREV check is changed from "#ifdef" to "#if" to support values of 0 or 1. OK for master and 2.26 branch? H.J. --- [BZ #22298] * 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_MUTEX_HAVE_PREV): Define only if it is undefined. (__pthread_internal_list): Check __pthread_internal_list instead of __WORDSIZE. (__PTHREAD_SPINS_DATA): Likewise. (__PTHREAD_SPINS): Likewise. (__pthread_mutex_s): Likewise. * sysdeps/x86/nptl/bits/pthreadtypes-arch.h (__PTHREAD_MUTEX_HAVE_PREV): Defined. --- nptl/allocatestack.c | 2 +- nptl/descr.h | 2 +- nptl/nptl-init.c | 2 +- nptl/pthread_create.c | 4 ++-- sysdeps/nptl/bits/thread-shared-types.h | 17 ++++++++++++----- sysdeps/nptl/fork.c | 2 +- sysdeps/nptl/pthread.h | 2 +- sysdeps/x86/nptl/bits/pthreadtypes-arch.h | 2 ++ 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index ad9add8d2a..1cc7893195 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 c5ad0c8dba..c83b17b674 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 29216077a2..869e926f17 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 992331e280..51ae60dfca 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/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h index 68b82b6bd6..d2c4f671f4 100644 --- a/sysdeps/nptl/bits/thread-shared-types.h +++ b/sysdeps/nptl/bits/thread-shared-types.h @@ -59,7 +59,15 @@ /* Common definition of pthread_mutex_t. */ -#if __WORDSIZE == 64 +#ifndef __PTHREAD_MUTEX_HAVE_PREV +# if __WORDSIZE == 64 +# define __PTHREAD_MUTEX_HAVE_PREV 1 +# else +# define __PTHREAD_MUTEX_HAVE_PREV 0 +# endif +#endif + +#if __PTHREAD_MUTEX_HAVE_PREV typedef struct __pthread_internal_list { struct __pthread_internal_list *__prev; @@ -74,7 +82,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 +109,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 4bb87e2331..48676c2f48 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 632ea7bc36..2b2b386ab3 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/x86/nptl/bits/pthreadtypes-arch.h b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h index fd86806800..2446d8d88a 100644 --- a/sysdeps/x86/nptl/bits/pthreadtypes-arch.h +++ b/sysdeps/x86/nptl/bits/pthreadtypes-arch.h @@ -21,6 +21,7 @@ #include #ifdef __x86_64__ +# define __PTHREAD_MUTEX_HAVE_PREV 1 # if __WORDSIZE == 64 # define __SIZEOF_PTHREAD_MUTEX_T 40 # define __SIZEOF_PTHREAD_ATTR_T 56 @@ -35,6 +36,7 @@ # define __SIZEOF_PTHREAD_BARRIER_T 20 # endif #else +# define __PTHREAD_MUTEX_HAVE_PREV 0 # define __SIZEOF_PTHREAD_MUTEX_T 24 # define __SIZEOF_PTHREAD_ATTR_T 36 # define __SIZEOF_PTHREAD_MUTEX_T 24