From patchwork Fri Jun 8 23:23:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 163871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D5035B6FB9 for ; Sat, 9 Jun 2012 09:23:29 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339802611; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:Message-Id:From:To:Subject:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=dC/gPa2NKO7trPzWsIdWnoTuNH0=; b=nfMgz8gT+YDZkXZMjeg/xrVx0agUYvEOISXw41OUEMp4+RRzpfQiMk3mVqOr71 FziSuLgBpD4vuvpL7ND7viVDxhKiANLdm+dSmppm5ZTkuQZ5hT00d/2NzJG2vzOw W2lidadZQDJm8BNVVAmXCWGyhRhRgDk2CD2XW7Qm/UTmA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Date:Message-Id:From:To:Subject:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ACV032nx6AUKYiN4suXIkhwB6eiRjEj+JYazXtdjjQQAfvhpl3CCrrzfkg8QIk 2IJBf0pldiaXjtb7yzII2y/TZjmTKXz9J6HiiBjveRoHHtbiJkjcfSGrOp1OQkVZ tgeNsXpPX3A7h8AP7Tyyrggg90HWhyYkfu95IIXD4ieKk=; Received: (qmail 24685 invoked by alias); 8 Jun 2012 23:23:26 -0000 Received: (qmail 24675 invoked by uid 22791); 8 Jun 2012 23:23:25 -0000 X-SWARE-Spam-Status: No, hits=-4.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Jun 2012 23:23:07 +0000 Received: by pbbrq2 with SMTP id rq2so3126319pbb.20 for ; Fri, 08 Jun 2012 16:23:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:message-id:from:to:subject:x-shopping-list:x-gm-message-state; bh=TKRHaMku1lJSWHQ7B8d/TRcoNf0kcndzFD9408IlYag=; b=GdxWsrKARo/IMrAFmDQRl91W2ttrcJ1hDJ1boYONNnTJHvifC0o3j0VYds5EHJLtyL /Yt0sVwQseqSgk+eEDozidErT+ZrHVzXXd3hhT6Sn3ZARAcfikk194lfYPumFJCXMYHU jNVSxM6qvWsfiMS/Nxbgaa37uOqO0+QzJDjv2RNO1EnYrK+MrS5jMPORt+/mI2K6LjAD rg2UMzWbriA8wqSd5KXUAcPlgqz0eqeRRoEPAMgoTTTO8d+EtTAjRwn2/1WaX3ehhy5F aKJcRoUdoVJCBR2CYm5ArSa2FfHQXeHasP6gxHDdItKCgVUD/iEBQ69+efGEoOBVpDbz EZRQ== Received: by 10.68.231.164 with SMTP id th4mr232403pbc.97.1339197787329; Fri, 08 Jun 2012 16:23:07 -0700 (PDT) Received: by 10.68.231.164 with SMTP id th4mr232395pbc.97.1339197787249; Fri, 08 Jun 2012 16:23:07 -0700 (PDT) Received: from frobland.mtv.corp.google.com.google.com ([2620:0:1000:1b01:6631:50ff:fe3b:961a]) by mx.google.com with ESMTPS id ny10sm6474285pbb.38.2012.06.08.16.23.05 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jun 2012 16:23:06 -0700 (PDT) Date: Fri, 08 Jun 2012 16:23:04 -0700 Message-Id: From: Roland McGrath To: gcc-patches@gcc.gnu.org Subject: [PATCH] libgcc: If __GLIBC__ is defined, don't refer to pthread_cancel. X-Gm-Message-State: ALoCoQkuA5O8dbb9978vZoL+1bnTz74ijLrjaQ7WiteyEgXKX/tSNd+HbELDUuRCdAHbmoxoA0LSKtfrNxHGqmDvC04aya3WDQBPRmayQUuMtMnfoiKVcr/MJ1KqeL12SxzEQniNqAweX+E73trLcYIgtro8/a2uZg== Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org See http://gcc.gnu.org/ml/gcc-patches/2012-01/msg01427.html for the previous discussion about the motivation for this patch and the choice of __pthread_key_create (also the comment added in the code by this patch). This had no effect on testsuite results on x86_64-linux-gnu (Ubuntu EGLIBC 2.11.1-0ubuntu7.10). Thanks, Roland libgcc/ 2012-06-08 Roland McGrath * gthr-posix.h [neither FreeBSD nor Solaris] (__gthread_active_p): If __GLIBC__ is defined, refer to __pthread_key_create instead of pthread_cancel. diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h index b5b1611..cc4e518 100644 --- a/libgcc/gthr-posix.h +++ b/libgcc/gthr-posix.h @@ -212,18 +212,43 @@ __gthread_active_p (void) #else /* neither FreeBSD nor Solaris */ +/* For a program to be multi-threaded the only thing that it certainly must + be using is pthread_create. However, there may be other libraries that + intercept pthread_create with their own definitions to wrap pthreads + functionality for some purpose. In those cases, pthread_create being + defined might not necessarily mean that libpthread is actually linked + in. + + For the GNU C library, we can use a known internal name. This is always + available in the ABI, but no other library would define it. That is + ideal, since any public pthread function might be intercepted just as + pthread_create might be. __pthread_key_create is an "internal" + implementation symbol, but it is part of the public exported ABI. Also, + it's among the symbols that the static libpthread.a always links in + whenever pthread_create is used, so there is no danger of a false + negative result in any statically-linked, multi-threaded program. + + For others, we choose pthread_cancel as a function that seems unlikely + to be redefined by an interceptor library. The bionic (Android) C + library does not provide pthread_cancel, so we do use pthread_create + there (and interceptor libraries lose). */ + +#ifdef __GLIBC__ +__gthrw2(__gthrw_(__pthread_key_create), + __pthread_key_create, + pthread_key_create) +# define GTHR_ACTIVE_PROXY __gthrw_(__pthread_key_create) +#elif defined (__BIONIC__) +# define GTHR_ACTIVE_PROXY __gthrw_(pthread_create) +#else +# define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel) +#endif + static inline int __gthread_active_p (void) { -/* Android's C library does not provide pthread_cancel, check for - `pthread_create' instead. */ -#ifndef __BIONIC__ static void *const __gthread_active_ptr - = __extension__ (void *) &__gthrw_(pthread_cancel); -#else - static void *const __gthread_active_ptr - = __extension__ (void *) &__gthrw_(pthread_create); -#endif + = __extension__ (void *) >HR_ACTIVE_PROXY; return __gthread_active_ptr != 0; }