about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-12-20 11:40:36 +0100
committerFlorian Weimer <fweimer@redhat.com>2017-12-20 11:42:04 +0100
commit8a26ad2ab7396bc94fd3cd7b25cba433908d30e1 (patch)
tree3e87bff8b59daaa5c7564532cc48c8d53ee5f7db /nptl
parent5069ff32842c60c55f8b573ee66fe43f9ec364af (diff)
downloadglibc-8a26ad2ab7396bc94fd3cd7b25cba433908d30e1.tar.gz
glibc-8a26ad2ab7396bc94fd3cd7b25cba433908d30e1.tar.xz
glibc-8a26ad2ab7396bc94fd3cd7b25cba433908d30e1.zip
nptl: Implement pthread_self in libc.so [BZ #22635]
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.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/Makefile4
-rw-r--r--nptl/compat-pthread_self.c27
-rw-r--r--nptl/forward.c4
-rw-r--r--nptl/nptl-init.c1
-rw-r--r--nptl/pthread_self.c4
5 files changed, 30 insertions, 10 deletions
diff --git a/nptl/Makefile b/nptl/Makefile
index 60d036a1ea..ab8cc98728 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -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
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
+   <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
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 <tls.h>
 
-
 pthread_t
-__pthread_self (void)
+pthread_self (void)
 {
   return (pthread_t) THREAD_SELF;
 }
-weak_alias (__pthread_self, pthread_self)