From d017b0ab5a181dce4145f3a1b3b27e3341abd201 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 10 May 2021 10:31:41 +0200 Subject: elf: Introduce __tls_pre_init_tp This is an early variant of __tls_init_tp, primarily for initializing thread-related elements of _rtld_global/GL. Some existing initialization code not needed for NPTL is moved into the generic version of this function. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- elf/dl-mutex.c | 2 +- elf/dl-tls_init_tp.c | 29 +++++++++++++++++++++++++++++ elf/rtld.c | 38 +------------------------------------- 3 files changed, 31 insertions(+), 38 deletions(-) (limited to 'elf') diff --git a/elf/dl-mutex.c b/elf/dl-mutex.c index 2cd9d49..ae1d8a8 100644 --- a/elf/dl-mutex.c +++ b/elf/dl-mutex.c @@ -16,4 +16,4 @@ License along with the GNU C Library; if not, see . */ -/* The generic version initialization happpens in dl_main. */ +/* Initialization happens in __tls_pre_init_tp in dl-tls_init_tp.c. */ diff --git a/elf/dl-tls_init_tp.c b/elf/dl-tls_init_tp.c index 728cd84..d84adc9 100644 --- a/elf/dl-tls_init_tp.c +++ b/elf/dl-tls_init_tp.c @@ -18,6 +18,35 @@ #include +#if defined SHARED && defined _LIBC_REENTRANT \ + && defined __rtld_lock_default_lock_recursive +static void +rtld_lock_default_lock_recursive (void *lock) +{ + __rtld_lock_default_lock_recursive (lock); +} + +static void +rtld_lock_default_unlock_recursive (void *lock) +{ + __rtld_lock_default_unlock_recursive (lock); +} +#endif + +void +__tls_pre_init_tp (void) +{ +#if !THREAD_GSCOPE_IN_TCB + GL(dl_init_static_tls) = &_dl_nothread_init_static_tls; +#endif + +#if defined SHARED && defined _LIBC_REENTRANT \ + && defined __rtld_lock_default_lock_recursive + GL(dl_rtld_lock_recursive) = rtld_lock_default_lock_recursive; + GL(dl_rtld_unlock_recursive) = rtld_lock_default_unlock_recursive; +#endif +} + void __tls_init_tp (void) { diff --git a/elf/rtld.c b/elf/rtld.c index a359167..1255d5c 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -843,30 +843,6 @@ ERROR: ld.so: object '%s' from %s cannot be preloaded (%s): ignored.\n", return 0; } -#if defined SHARED && defined _LIBC_REENTRANT \ - && defined __rtld_lock_default_lock_recursive -static void -rtld_lock_default_lock_recursive (void *lock) -{ - __rtld_lock_default_lock_recursive (lock); -} - -static void -rtld_lock_default_unlock_recursive (void *lock) -{ - __rtld_lock_default_unlock_recursive (lock); -} -#endif -#if PTHREAD_IN_LIBC -/* Dummy implementation. See __rtld_mutex_init. */ -static int -rtld_mutex_dummy (pthread_mutex_t *lock) -{ - return 0; -} -#endif - - static void security_init (void) { @@ -1147,19 +1123,7 @@ dl_main (const ElfW(Phdr) *phdr, struct dl_main_state state; dl_main_state_init (&state); -#if !THREAD_GSCOPE_IN_TCB - GL(dl_init_static_tls) = &_dl_nothread_init_static_tls; -#endif - -#if defined SHARED && defined _LIBC_REENTRANT \ - && defined __rtld_lock_default_lock_recursive - GL(dl_rtld_lock_recursive) = rtld_lock_default_lock_recursive; - GL(dl_rtld_unlock_recursive) = rtld_lock_default_unlock_recursive; -#endif -#if PTHREAD_IN_LIBC - ___rtld_mutex_lock = rtld_mutex_dummy; - ___rtld_mutex_unlock = rtld_mutex_dummy; -#endif + __tls_pre_init_tp (); /* The explicit initialization here is cheaper than processing the reloc in the _rtld_local definition's initializer. */ -- cgit v1.1