mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-08 23:58:31 +08:00
elf: directly call dl_init_static_tls
htl can now have it directly in ld.so
This commit is contained in:
+1
-1
@@ -408,7 +408,7 @@ TLS generation counter wrapped! Please report this."));
|
||||
_dl_update_slotinfo (imap->l_tls_modid, newgen);
|
||||
#endif
|
||||
|
||||
dl_init_static_tls (imap);
|
||||
_dl_init_static_tls (imap);
|
||||
assert (imap->l_need_tls_init == 0);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-22
@@ -119,7 +119,7 @@ _dl_try_allocate_static_tls (struct link_map *map, bool optional)
|
||||
(void) _dl_update_slotinfo (map->l_tls_modid, GL(dl_tls_generation));
|
||||
#endif
|
||||
|
||||
dl_init_static_tls (map);
|
||||
_dl_init_static_tls (map);
|
||||
}
|
||||
else
|
||||
map->l_need_tls_init = 1;
|
||||
@@ -142,27 +142,6 @@ cannot allocate memory in static TLS block"));
|
||||
}
|
||||
}
|
||||
|
||||
#if !PTHREAD_IN_LIBC
|
||||
/* Initialize static TLS area and DTV for current (only) thread.
|
||||
libpthread implementations should provide their own hook
|
||||
to handle all threads. */
|
||||
void
|
||||
_dl_nothread_init_static_tls (struct link_map *map)
|
||||
{
|
||||
#if TLS_TCB_AT_TP
|
||||
void *dest = (char *) THREAD_SELF - map->l_tls_offset;
|
||||
#elif TLS_DTV_AT_TP
|
||||
void *dest = (char *) THREAD_SELF + map->l_tls_offset + TLS_PRE_TCB_SIZE;
|
||||
#else
|
||||
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
|
||||
#endif
|
||||
|
||||
/* Initialize the memory. */
|
||||
memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
|
||||
'\0', map->l_tls_blocksize - map->l_tls_initimage_size);
|
||||
}
|
||||
#endif /* !PTHREAD_IN_LIBC */
|
||||
|
||||
static __always_inline lookup_t
|
||||
resolve_map (lookup_t l, struct r_scope_elem *scope[], const ElfW(Sym) **ref,
|
||||
const struct r_found_version *version, unsigned long int r_type)
|
||||
|
||||
@@ -177,9 +177,6 @@ size_t _dl_stack_cache_actsize;
|
||||
uintptr_t _dl_in_flight_stack;
|
||||
int _dl_stack_cache_lock;
|
||||
#endif
|
||||
#if !PTHREAD_IN_LIBC
|
||||
void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
|
||||
#endif
|
||||
struct dl_scope_free_list *_dl_scope_free_list;
|
||||
|
||||
#ifdef NEED_DL_SYSINFO
|
||||
|
||||
+4
-3
@@ -29,8 +29,9 @@
|
||||
#include <dl-tls.h>
|
||||
#include <ldsodefs.h>
|
||||
#include <dl-tls_block_align.h>
|
||||
#include <pthreadP.h>
|
||||
|
||||
#if PTHREAD_IN_LIBC
|
||||
#ifdef __PTHREAD_NPTL
|
||||
# include <list.h>
|
||||
#endif
|
||||
|
||||
@@ -1300,7 +1301,7 @@ cannot create TLS data structures"));
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PTHREAD_IN_LIBC
|
||||
#ifdef __PTHREAD_NPTL
|
||||
static inline void __attribute__((always_inline))
|
||||
init_one_static_tls (struct pthread *curp, struct link_map *map)
|
||||
{
|
||||
@@ -1333,4 +1334,4 @@ _dl_init_static_tls (struct link_map *map)
|
||||
|
||||
lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE);
|
||||
}
|
||||
#endif /* PTHREAD_IN_LIBC */
|
||||
#endif /* __PTHREAD_NPTL */
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
void
|
||||
__tls_pre_init_tp (void)
|
||||
{
|
||||
#if !PTHREAD_IN_LIBC
|
||||
GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -307,7 +307,6 @@ libc {
|
||||
__pthread_block_intr;
|
||||
__pthread_create;
|
||||
__pthread_init_thread;
|
||||
__pthread_init_static_tls;
|
||||
__pthread_default_attr;
|
||||
__pthread_attr_init;
|
||||
__pthread_attr_getstacksize;
|
||||
|
||||
@@ -204,33 +204,3 @@ retry:
|
||||
return 0;
|
||||
}
|
||||
libc_hidden_def (__pthread_alloc)
|
||||
|
||||
void
|
||||
attribute_hidden
|
||||
__pthread_init_static_tls (struct link_map *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
__mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
|
||||
for (i = 0; i < GL (dl_pthread_num_threads); ++i)
|
||||
{
|
||||
struct __pthread *t = GL (dl_pthread_threads)[i];
|
||||
|
||||
if (t == NULL)
|
||||
continue;
|
||||
|
||||
# if TLS_TCB_AT_TP
|
||||
void *dest = (char *) t->tcb - map->l_tls_offset;
|
||||
# elif TLS_DTV_AT_TP
|
||||
void *dest = (char *) t->tcb + map->l_tls_offset + TLS_PRE_TCB_SIZE;
|
||||
# else
|
||||
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
|
||||
# endif
|
||||
|
||||
/* Initialize the memory. */
|
||||
memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
|
||||
'\0', map->l_tls_blocksize - map->l_tls_initimage_size);
|
||||
}
|
||||
__mach_rwlock_unlock (GL (dl_pthread_threads_lock));
|
||||
}
|
||||
libc_hidden_def (__pthread_init_static_tls)
|
||||
|
||||
@@ -441,10 +441,6 @@ struct rtld_global
|
||||
/* Generation counter for the dtv. */
|
||||
EXTERN size_t _dl_tls_generation;
|
||||
|
||||
#if !PTHREAD_IN_LIBC
|
||||
EXTERN void (*_dl_init_static_tls) (struct link_map *);
|
||||
#endif
|
||||
|
||||
/* Scopes to free after next THREAD_GSCOPE_WAIT (). */
|
||||
EXTERN struct dl_scope_free_list
|
||||
{
|
||||
@@ -1239,8 +1235,6 @@ extern bool __rtld_tls_init_tp_called attribute_hidden;
|
||||
extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
|
||||
rtld_hidden_proto (_dl_deallocate_tls)
|
||||
|
||||
extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
|
||||
|
||||
/* Get a pointer to _dl_main_map. */
|
||||
extern struct link_map * _dl_get_dl_main_map (void) attribute_hidden;
|
||||
|
||||
@@ -1321,21 +1315,10 @@ extern void _dl_aux_init (ElfW(auxv_t) *av)
|
||||
attribute_hidden;
|
||||
|
||||
/* Initialize the static TLS space for the link map in all existing
|
||||
threads. */
|
||||
#if PTHREAD_IN_LIBC
|
||||
threads.
|
||||
The stack list is available to ld.so, so the initialization can
|
||||
be handled within ld.so directly. */
|
||||
void _dl_init_static_tls (struct link_map *map) attribute_hidden;
|
||||
#endif
|
||||
static inline void
|
||||
dl_init_static_tls (struct link_map *map)
|
||||
{
|
||||
#if PTHREAD_IN_LIBC
|
||||
/* The stack list is available to ld.so, so the initialization can
|
||||
be handled within ld.so directly. */
|
||||
_dl_init_static_tls (map);
|
||||
#else
|
||||
GL (dl_init_static_tls) (map);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef SHARED
|
||||
/* Called before relocating ld.so during static dlopen. This can be
|
||||
|
||||
@@ -5,3 +5,7 @@ endif
|
||||
ifeq ($(subdir),posix)
|
||||
CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"HTL $(version)"'
|
||||
endif
|
||||
|
||||
ifeq ($(subdir),elf)
|
||||
sysdep-dl-routines += pt-static-tls
|
||||
endif
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <ldsodefs.h>
|
||||
#include <pthread.h>
|
||||
#include <htl/pt-internal.h>
|
||||
#include <pt-internal.h>
|
||||
|
||||
static inline int *
|
||||
thread_gscope_flag (struct __pthread *t)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* Initialize the static TLS space for the link map in all existing threads.
|
||||
Copyright (C) 2000-2026 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 <pthread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pt-internal.h>
|
||||
#include <ldsodefs.h>
|
||||
|
||||
static inline void __attribute__((always_inline))
|
||||
init_one_static_tls (tcbhead_t *curp, struct link_map *map)
|
||||
{
|
||||
# if TLS_TCB_AT_TP
|
||||
void *dest = (char *) curp - map->l_tls_offset;
|
||||
# elif TLS_DTV_AT_TP
|
||||
void *dest = (char *) curp + map->l_tls_offset + TLS_PRE_TCB_SIZE;
|
||||
# else
|
||||
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
|
||||
# endif
|
||||
|
||||
/* Initialize the memory. */
|
||||
memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
|
||||
'\0', map->l_tls_blocksize - map->l_tls_initimage_size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_dl_init_static_tls (struct link_map *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!GL (dl_pthread_num_threads))
|
||||
{
|
||||
init_one_static_tls (THREAD_SELF, map);
|
||||
return;
|
||||
}
|
||||
|
||||
__mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
|
||||
for (i = 0; i < GL (dl_pthread_num_threads); ++i)
|
||||
{
|
||||
struct __pthread *t = GL (dl_pthread_threads)[i];
|
||||
|
||||
if (t == NULL)
|
||||
continue;
|
||||
|
||||
init_one_static_tls (t->tcb, map);
|
||||
}
|
||||
__mach_rwlock_unlock (GL (dl_pthread_threads_lock));
|
||||
}
|
||||
@@ -28,9 +28,6 @@
|
||||
/* Attribute to indicate thread creation was issued from C11 thrd_create. */
|
||||
#define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
|
||||
|
||||
extern void __pthread_init_static_tls (struct link_map *);
|
||||
libc_hidden_proto (__pthread_init_static_tls)
|
||||
|
||||
/* These represent the interface used by glibc itself. */
|
||||
|
||||
extern int __pthread_barrier_destroy (pthread_barrier_t *__barrier);
|
||||
|
||||
@@ -123,8 +123,6 @@ _init_routine (void *stack)
|
||||
|
||||
__register_atfork (NULL, NULL, reset_pthread_total, __dso_handle);
|
||||
|
||||
GL(dl_init_static_tls) = &__pthread_init_static_tls;
|
||||
|
||||
/* Make MiG code thread aware. */
|
||||
__mig_init (thread->stackaddr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user