From patchwork Thu Dec 14 18:37:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 848743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-88154-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="pPuEwone"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyMkm1vsyz9s5L for ; Fri, 15 Dec 2017 05:38:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= Ny/vGhrWAPM82WpqeskSfHxaCBcKbzz3Dct9s5J5Uc3PalEi/FXKne18uBrNcTKN 0dc0PUtEzSNJ5vdSJWMLJpa066ay1coG+z6XwJVJyh3SDAFfmIMoO52Twx80Gbgg r2wUlp3kGvlUBZHmSgqB5ehKJ7kz26iGQzJds2XwoNs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=dYFWAB FxsiJN5SWh+HolTvNUnIY=; b=pPuEwonegAi7wEyfl5s3w2OCCxEqM0364phXOX /ei8f5PJFfMrS269ksw+zV30zZZsi/4bEPJ5cbLVqVI9ItOKZBCbWIpqa+yqtAbB SrPrzPtNs8riNZG4bId64Cr/W4K0WXrsFYgfgy52Swlt3Sblp0/D0UibhPavun4K beFww= Received: (qmail 121523 invoked by alias); 14 Dec 2017 18:38:02 -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 121514 invoked by uid 89); 14 Dec 2017 18:38:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sk:unregis X-HELO: mx1.redhat.com Date: Thu, 14 Dec 2017 19:37:58 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Implement pthread_self in libc.so User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20171214183758.154F4439942EA@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) All binaries use TLS and thus need a properly set up TCB, so we can simply return its address directly, instead of forwarding to the libpthread implementation from libc. For versioned symbols, the dynamic linker checks that the soname matches the name supplied by the link editor, so a compatibility symbol in libpthread is needed. The layout of struct pthread_functions is not changed by this commit, although the pointer used to store the address of pthread_self is now unused. To avoid linking against the libpthread function in all cases, we would have to bump the symbol version of libpthread in libc.so and supply a compat symbol. This commit does not do that because the function implementation is so small, so the overhead by two active copies of the same function might well be smaller than the increase in symbol table size. 2017-12-14 Florian Weimer nptl: Provide full implementation of pthread_self in libc.so. * nptl/Makefile (routines): Add pthread_self. (libpthread-routines): Replace pthread_self with compat-pthread_self. * nptl/forward.c (pthread_self): Remove. * nptl/nptl-init.c (pthread_functions): Do not initialize ptr_pthread_self. * nptl/pthread_self.c (pthread_self): Remove weak alias. * nptl/compat-pthread_self.c: New file. * sysdeps/nptl/pthread-functions.h (struct pthread_functions): Rename ptr_pthread_self to unused_pthread_self. diff --git a/nptl/Makefile b/nptl/Makefile index 570a42301c..ae388d1112 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -30,7 +30,7 @@ install-lib-ldscripts := libpthread.so routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \ libc-cleanup libc_pthread_init libc_multiple_threads \ - register-atfork unregister-atfork + register-atfork unregister-atfork pthread_self shared-only-routines = forward # We need to provide certain routines for compatibility with existing @@ -48,7 +48,7 @@ pthread-compat-wrappers = \ libpthread-routines = nptl-init vars events version pt-interp \ pthread_create pthread_exit pthread_detach \ pthread_join pthread_tryjoin pthread_timedjoin \ - pthread_self pthread_equal pthread_yield \ + compat-pthread_self pthread_equal pthread_yield \ pthread_getconcurrency pthread_setconcurrency \ pthread_getschedparam pthread_setschedparam \ pthread_setschedprio \ diff --git a/nptl/compat-pthread_self.c b/nptl/compat-pthread_self.c new file mode 100644 index 0000000000..5e9f4eb27d --- /dev/null +++ b/nptl/compat-pthread_self.c @@ -0,0 +1,27 @@ +/* Compatibility version of pthread_self in libpthread. + 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 + . */ + +/* Compatibility version of pthread_self for old binaries which link + directly against libpthread's version. */ + +#include + +#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_27) +# include "pthread_self.c" +compat_symbol (libpthread, pthread_self, pthread_self, GLIBC_2_0); +#endif diff --git a/nptl/forward.c b/nptl/forward.c index ac96765f29..8abbccdf5e 100644 --- a/nptl/forward.c +++ b/nptl/forward.c @@ -193,10 +193,6 @@ FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0) FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0) - -FORWARD2 (pthread_self, pthread_t, (void), (), return 0) - - FORWARD (__pthread_setcancelstate, (int state, int *oldstate), (state, oldstate), 0) strong_alias (__pthread_setcancelstate, pthread_setcancelstate) diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index 869e926f17..a5979f27fd 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -122,7 +122,6 @@ static const struct pthread_functions pthread_functions = .ptr_pthread_mutex_init = __pthread_mutex_init, .ptr_pthread_mutex_lock = __pthread_mutex_lock, .ptr_pthread_mutex_unlock = __pthread_mutex_unlock, - .ptr_pthread_self = __pthread_self, .ptr___pthread_setcancelstate = __pthread_setcancelstate, .ptr_pthread_setcanceltype = __pthread_setcanceltype, .ptr___pthread_cleanup_upto = __pthread_cleanup_upto, diff --git a/nptl/pthread_self.c b/nptl/pthread_self.c index 8e21775e31..b75af9358e 100644 --- a/nptl/pthread_self.c +++ b/nptl/pthread_self.c @@ -19,10 +19,8 @@ #include "pthreadP.h" #include - pthread_t -__pthread_self (void) +pthread_self (void) { return (pthread_t) THREAD_SELF; } -weak_alias (__pthread_self, pthread_self) diff --git a/sysdeps/nptl/pthread-functions.h b/sysdeps/nptl/pthread-functions.h index 4006fc6c25..a385ff5684 100644 --- a/sysdeps/nptl/pthread-functions.h +++ b/sysdeps/nptl/pthread-functions.h @@ -74,7 +74,7 @@ struct pthread_functions const pthread_mutexattr_t *); int (*ptr_pthread_mutex_lock) (pthread_mutex_t *); int (*ptr_pthread_mutex_unlock) (pthread_mutex_t *); - pthread_t (*ptr_pthread_self) (void); + pthread_t (*unused_pthread_self) (void); int (*ptr___pthread_setcancelstate) (int, int *); int (*ptr_pthread_setcanceltype) (int, int *); void (*ptr___pthread_cleanup_upto) (__jmp_buf, char *);