about summary refs log tree commit diff
path: root/sysdeps/htl
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-09-15 20:11:08 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-09-16 01:04:05 +0200
commit166bb3eac351b88191d440b0fe8d5d7b757eaed0 (patch)
tree2a0366c36387bcee5c4ae2704ccca394cd969f48 /sysdeps/htl
parent4b6574a6f63b6c766f27be4a0b4c9376a35a4bd5 (diff)
downloadglibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.tar.gz
glibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.tar.xz
glibc-166bb3eac351b88191d440b0fe8d5d7b757eaed0.zip
htl: Move thread table to ld.so
The next commit is going to introduce a new implementation of
THREAD_GSCOPE_WAIT which needs to access the list of threads.
Since it must be usable from the dynamic laoder, we have to move
the symbols for the list of threads into the loader.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20210915171110.226187-2-bugaevc@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'sysdeps/htl')
-rw-r--r--sysdeps/htl/dl-support.c23
-rw-r--r--sysdeps/htl/pt-key-delete.c8
-rw-r--r--sysdeps/htl/pthreadP.h2
-rw-r--r--sysdeps/htl/raise.c8
-rw-r--r--sysdeps/htl/thrd_current.c7
5 files changed, 40 insertions, 8 deletions
diff --git a/sysdeps/htl/dl-support.c b/sysdeps/htl/dl-support.c
new file mode 100644
index 0000000000..7198a3fae4
--- /dev/null
+++ b/sysdeps/htl/dl-support.c
@@ -0,0 +1,23 @@
+/* Support for dynamic linking code in static libc.
+   Copyright (C) 2007-2021 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <elf/dl-support.c>
+
+int _dl_pthread_num_threads;
+struct __pthread **_dl_pthread_threads;
+__libc_rwlock_define_initialized (, _dl_pthread_threads_lock)
diff --git a/sysdeps/htl/pt-key-delete.c b/sysdeps/htl/pt-key-delete.c
index 4e77ef7521..9f5907bf13 100644
--- a/sysdeps/htl/pt-key-delete.c
+++ b/sysdeps/htl/pt-key-delete.c
@@ -39,12 +39,12 @@ __pthread_key_delete (pthread_key_t key)
       __pthread_key_destructors[key] = PTHREAD_KEY_INVALID;
       __pthread_key_invalid_count++;
 
-      __pthread_rwlock_rdlock (&__pthread_threads_lock);
-      for (i = 0; i < __pthread_num_threads; ++i)
+      __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));
+      for (i = 0; i < GL (dl_pthread_num_threads); ++i)
 	{
 	  struct __pthread *t;
 
-	  t = __pthread_threads[i];
+	  t = GL (dl_pthread_threads)[i];
 
 	  if (t == NULL)
 	    continue;
@@ -54,7 +54,7 @@ __pthread_key_delete (pthread_key_t key)
 	  if (key < t->thread_specifics_size)
 	    t->thread_specifics[key] = 0;
 	}
-      __pthread_rwlock_unlock (&__pthread_threads_lock);
+      __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
     }
 
   __pthread_mutex_unlock (&__pthread_key_lock);
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index 3fd774269f..8b02bef355 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -31,8 +31,6 @@ extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
 
 /* These represent the interface used by glibc itself.  */
 
-extern struct __pthread **__pthread_threads;
-
 extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
diff --git a/sysdeps/htl/raise.c b/sysdeps/htl/raise.c
index 5a0f37d3b8..8c17db6f65 100644
--- a/sysdeps/htl/raise.c
+++ b/sysdeps/htl/raise.c
@@ -17,6 +17,7 @@
    License along with this program.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <ldsodefs.h>
 #include <pthreadP.h>
 #include <signal.h>
 #include <unistd.h>
@@ -24,6 +25,11 @@
 #pragma weak __pthread_kill
 #pragma weak __pthread_self
 #pragma weak __pthread_threads
+
+#ifndef SHARED
+#pragma weak _dl_pthread_threads
+#endif
+
 int
 raise (int signo)
 {
@@ -31,7 +37,7 @@ raise (int signo)
      "the effect of the raise() function shall be equivalent to
      calling: pthread_kill(pthread_self(), sig);"  */
 
-  if (__pthread_kill != NULL && __pthread_threads != NULL)
+  if (__pthread_kill != NULL && GL (dl_pthread_threads) != NULL)
     {
       int err;
       err = __pthread_kill (__pthread_self (), signo);
diff --git a/sysdeps/htl/thrd_current.c b/sysdeps/htl/thrd_current.c
index eecb86af85..87359677d6 100644
--- a/sysdeps/htl/thrd_current.c
+++ b/sysdeps/htl/thrd_current.c
@@ -17,14 +17,19 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include "thrd_priv.h"
+#include <ldsodefs.h>
 
 #pragma weak __pthread_self
 #pragma weak __pthread_threads
 
+#ifndef SHARED
+#pragma weak _dl_pthread_threads
+#endif
+
 thrd_t
 thrd_current (void)
 {
-  if (__pthread_threads)
+  if (GL (dl_pthread_threads))
     return (thrd_t) __pthread_self ();
 
   return (thrd_t) 0;