]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Implement pthread_self in libc.so [BZ #22635]
authorFlorian Weimer <fweimer@redhat.com>
Wed, 20 Dec 2017 10:40:36 +0000 (11:40 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 20 Dec 2017 10:42:04 +0000 (11:42 +0100)
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.

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.

ChangeLog
nptl/Makefile
nptl/compat-pthread_self.c [new file with mode: 0644]
nptl/forward.c
nptl/nptl-init.c
nptl/pthread_self.c
sysdeps/nptl/pthread-functions.h

index 982798c8c3fb52165bd8697e221ad34e84eadb94..de2ee3f779fb62165c664d258de2f9cb108476bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2017-12-20  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #22635]
+       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):
+       Remove ptr_pthread_self.
+
 2017-12-19  Arnold D. Robbins  <arnold@skeeve.com>
 
        * posix/regcomp.c: Fix spelling in comments.
index 60d036a1ea425192b5c21e1b92eea99a5251f337..ab8cc98728ed27d28646f333bb5229ffdc463c65 100644 (file)
@@ -31,7 +31,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
@@ -49,7 +49,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 (file)
index 0000000..5e9f4eb
--- /dev/null
@@ -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
+   <http://www.gnu.org/licenses/>.  */
+
+/* Compatibility version of pthread_self for old binaries which link
+   directly against libpthread's version.  */
+
+#include <shlib-compat.h>
+
+#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
index ac96765f29af73ea975ecd6cd5d89b00716a1a87..8abbccdf5e5a6b4d23459f374ce719f95426f0f0 100644 (file)
@@ -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)
index 869e926f17aa218ab0b122eeda935069ef419ae5..a5979f27fd4f939af6870b3fe47047d3b5ce6423 100644 (file)
@@ -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,
index 8e21775e31b57dafad74b33d3e1f96e8f3262a2a..b75af9358e1b28bd42214fd37aa26ef32bac4560 100644 (file)
 #include "pthreadP.h"
 #include <tls.h>
 
-
 pthread_t
-__pthread_self (void)
+pthread_self (void)
 {
   return (pthread_t) THREAD_SELF;
 }
-weak_alias (__pthread_self, pthread_self)
index 4006fc6c2509570f9fd16313c6e1a650cbc0bfd1..4af21425d326317a37a75cef3479d6d8cc23c731 100644 (file)
@@ -74,7 +74,6 @@ 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);
   int (*ptr___pthread_setcancelstate) (int, int *);
   int (*ptr_pthread_setcanceltype) (int, int *);
   void (*ptr___pthread_cleanup_upto) (__jmp_buf, char *);