[htl,v3,1/5] elf: Replace most uses of THREAD_GSCOPE_IN_TCB

Message ID 20210907133325.255690-2-bugaevc@gmail.com
State Committed, archived
Headers
Series Rewrite THREAD_GSCOPE |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Sergey Bugaev Sept. 7, 2021, 1:33 p.m. UTC
  While originally this definition was indeed used to distinguish between
the cases where the GSCOPE flag was stored in TCB or not, it has since
become used as a general way to distinguish between HTL and NPTL.

THREAD_GSCOPE_IN_TCB will be removed in the following commits, as HTL,
which currently is the only port that does not put the flag into TCB,
will get ported to put the GSCOPE flag into the TCB as well. To prepare
for that change, migrate all code that wants to distinguish between HTL
and NPTL to use PTHREAD_IN_LIBC instead, which is a better choice since
the distinction mostly has to do with whether libc has access to the
list of thread structures and therefore can initialize thread-local
storage.

The parts of code that actually depend on whether the GSCOPE flag is in
TCB are left unchanged.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 elf/dl-reloc.c             |  4 ++--
 elf/dl-support.c           |  6 ++++--
 elf/dl-tls.c               |  6 +++---
 elf/dl-tls_init_tp.c       |  2 +-
 sysdeps/generic/ldsodefs.h | 11 ++++++-----
 5 files changed, 16 insertions(+), 13 deletions(-)
  

Comments

Samuel Thibault Sept. 14, 2021, 11:30 p.m. UTC | #1
Sergey Bugaev, le mar. 07 sept. 2021 16:33:21 +0300, a ecrit:
> While originally this definition was indeed used to distinguish between
> the cases where the GSCOPE flag was stored in TCB or not, it has since
> become used as a general way to distinguish between HTL and NPTL.
> 
> THREAD_GSCOPE_IN_TCB will be removed in the following commits, as HTL,
> which currently is the only port that does not put the flag into TCB,
> will get ported to put the GSCOPE flag into the TCB as well. To prepare
> for that change, migrate all code that wants to distinguish between HTL
> and NPTL to use PTHREAD_IN_LIBC instead, which is a better choice since
> the distinction mostly has to do with whether libc has access to the
> list of thread structures and therefore can initialize thread-local
> storage.
> 
> The parts of code that actually depend on whether the GSCOPE flag is in
> TCB are left unchanged.
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>

Applied, thanks!

> ---
>  elf/dl-reloc.c             |  4 ++--
>  elf/dl-support.c           |  6 ++++--
>  elf/dl-tls.c               |  6 +++---
>  elf/dl-tls_init_tp.c       |  2 +-
>  sysdeps/generic/ldsodefs.h | 11 ++++++-----
>  5 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
> index e13a672ade..6c957456b8 100644
> --- a/elf/dl-reloc.c
> +++ b/elf/dl-reloc.c
> @@ -141,7 +141,7 @@ cannot allocate memory in static TLS block"));
>      }
>  }
>  
> -#if !THREAD_GSCOPE_IN_TCB
> +#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.  */
> @@ -160,7 +160,7 @@ _dl_nothread_init_static_tls (struct link_map *map)
>    memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
>  	  '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
>  }
> -#endif /* !THREAD_GSCOPE_IN_TCB */
> +#endif /* !PTHREAD_IN_LIBC */
>  
>  void
>  _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
> diff --git a/elf/dl-support.c b/elf/dl-support.c
> index 0155718175..a317459fae 100644
> --- a/elf/dl-support.c
> +++ b/elf/dl-support.c
> @@ -183,7 +183,7 @@ uint64_t _dl_hwcap_mask;
>   * executable but this isn't true for all platforms.  */
>  ElfW(Word) _dl_stack_flags = DEFAULT_STACK_PERMS;
>  
> -#if THREAD_GSCOPE_IN_TCB
> +#if PTHREAD_IN_LIBC
>  list_t _dl_stack_used;
>  list_t _dl_stack_user;
>  list_t _dl_stack_cache;
> @@ -195,9 +195,11 @@ int _dl_stack_cache_lock;
>     when it was not, we do it by calling this function.
>     It returns an errno code or zero on success.  */
>  int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable;
> -int _dl_thread_gscope_count;
>  void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
>  #endif
> +#if !THREAD_GSCOPE_IN_TCB
> +int _dl_thread_gscope_count;
> +#endif
>  struct dl_scope_free_list *_dl_scope_free_list;
>  
>  #ifdef NEED_DL_SYSINFO
> diff --git a/elf/dl-tls.c b/elf/dl-tls.c
> index 423e380f7c..d554ae4497 100644
> --- a/elf/dl-tls.c
> +++ b/elf/dl-tls.c
> @@ -29,7 +29,7 @@
>  #include <dl-tls.h>
>  #include <ldsodefs.h>
>  
> -#if THREAD_GSCOPE_IN_TCB
> +#if PTHREAD_IN_LIBC
>  # include <list.h>
>  #endif
>  
> @@ -1058,7 +1058,7 @@ cannot create TLS data structures"));
>      }
>  }
>  
> -#if THREAD_GSCOPE_IN_TCB
> +#if PTHREAD_IN_LIBC
>  static inline void __attribute__((always_inline))
>  init_one_static_tls (struct pthread *curp, struct link_map *map)
>  {
> @@ -1091,4 +1091,4 @@ _dl_init_static_tls (struct link_map *map)
>  
>    lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE);
>  }
> -#endif /* THREAD_GSCOPE_IN_TCB */
> +#endif /* PTHREAD_IN_LIBC */
> diff --git a/elf/dl-tls_init_tp.c b/elf/dl-tls_init_tp.c
> index d84adc992c..e482f3cfa9 100644
> --- a/elf/dl-tls_init_tp.c
> +++ b/elf/dl-tls_init_tp.c
> @@ -36,7 +36,7 @@ rtld_lock_default_unlock_recursive (void *lock)
>  void
>  __tls_pre_init_tp (void)
>  {
> -#if !THREAD_GSCOPE_IN_TCB
> +#if !PTHREAD_IN_LIBC
>    GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
>  #endif
>  
> diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
> index 9c15259236..02bd579ef8 100644
> --- a/sysdeps/generic/ldsodefs.h
> +++ b/sysdeps/generic/ldsodefs.h
> @@ -456,7 +456,7 @@ struct rtld_global
>    /* Generation counter for the dtv.  */
>    EXTERN size_t _dl_tls_generation;
>  
> -#if !THREAD_GSCOPE_IN_TCB
> +#if !PTHREAD_IN_LIBC
>    EXTERN void (*_dl_init_static_tls) (struct link_map *);
>  #endif
>  
> @@ -466,7 +466,7 @@ struct rtld_global
>      size_t count;
>      void *list[50];
>    } *_dl_scope_free_list;
> -#if THREAD_GSCOPE_IN_TCB
> +#if PTHREAD_IN_LIBC
>    /* List of active thread stacks, with memory managed by glibc.  */
>    EXTERN list_t _dl_stack_used;
>  
> @@ -486,7 +486,8 @@ struct rtld_global
>  
>    /* Mutex protecting the stack lists.  */
>    EXTERN int _dl_stack_cache_lock;
> -#else
> +#endif
> +#if !THREAD_GSCOPE_IN_TCB
>    EXTERN int _dl_thread_gscope_count;
>  #endif
>  #ifdef SHARED
> @@ -1297,13 +1298,13 @@ extern void _dl_aux_init (ElfW(auxv_t) *av)
>  
>  /* Initialize the static TLS space for the link map in all existing
>     threads. */
> -#if THREAD_GSCOPE_IN_TCB
> +#if PTHREAD_IN_LIBC
>  void _dl_init_static_tls (struct link_map *map) attribute_hidden;
>  #endif
>  static inline void
>  dl_init_static_tls (struct link_map *map)
>  {
> -#if THREAD_GSCOPE_IN_TCB
> +#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);
> -- 
> 2.31.1
>
  

Patch

diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
index e13a672ade..6c957456b8 100644
--- a/elf/dl-reloc.c
+++ b/elf/dl-reloc.c
@@ -141,7 +141,7 @@  cannot allocate memory in static TLS block"));
     }
 }
 
-#if !THREAD_GSCOPE_IN_TCB
+#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.  */
@@ -160,7 +160,7 @@  _dl_nothread_init_static_tls (struct link_map *map)
   memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
 	  '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
 }
-#endif /* !THREAD_GSCOPE_IN_TCB */
+#endif /* !PTHREAD_IN_LIBC */
 
 void
 _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 0155718175..a317459fae 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -183,7 +183,7 @@  uint64_t _dl_hwcap_mask;
  * executable but this isn't true for all platforms.  */
 ElfW(Word) _dl_stack_flags = DEFAULT_STACK_PERMS;
 
-#if THREAD_GSCOPE_IN_TCB
+#if PTHREAD_IN_LIBC
 list_t _dl_stack_used;
 list_t _dl_stack_user;
 list_t _dl_stack_cache;
@@ -195,9 +195,11 @@  int _dl_stack_cache_lock;
    when it was not, we do it by calling this function.
    It returns an errno code or zero on success.  */
 int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable;
-int _dl_thread_gscope_count;
 void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
 #endif
+#if !THREAD_GSCOPE_IN_TCB
+int _dl_thread_gscope_count;
+#endif
 struct dl_scope_free_list *_dl_scope_free_list;
 
 #ifdef NEED_DL_SYSINFO
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 423e380f7c..d554ae4497 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -29,7 +29,7 @@ 
 #include <dl-tls.h>
 #include <ldsodefs.h>
 
-#if THREAD_GSCOPE_IN_TCB
+#if PTHREAD_IN_LIBC
 # include <list.h>
 #endif
 
@@ -1058,7 +1058,7 @@  cannot create TLS data structures"));
     }
 }
 
-#if THREAD_GSCOPE_IN_TCB
+#if PTHREAD_IN_LIBC
 static inline void __attribute__((always_inline))
 init_one_static_tls (struct pthread *curp, struct link_map *map)
 {
@@ -1091,4 +1091,4 @@  _dl_init_static_tls (struct link_map *map)
 
   lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE);
 }
-#endif /* THREAD_GSCOPE_IN_TCB */
+#endif /* PTHREAD_IN_LIBC */
diff --git a/elf/dl-tls_init_tp.c b/elf/dl-tls_init_tp.c
index d84adc992c..e482f3cfa9 100644
--- a/elf/dl-tls_init_tp.c
+++ b/elf/dl-tls_init_tp.c
@@ -36,7 +36,7 @@  rtld_lock_default_unlock_recursive (void *lock)
 void
 __tls_pre_init_tp (void)
 {
-#if !THREAD_GSCOPE_IN_TCB
+#if !PTHREAD_IN_LIBC
   GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
 #endif
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9c15259236..02bd579ef8 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -456,7 +456,7 @@  struct rtld_global
   /* Generation counter for the dtv.  */
   EXTERN size_t _dl_tls_generation;
 
-#if !THREAD_GSCOPE_IN_TCB
+#if !PTHREAD_IN_LIBC
   EXTERN void (*_dl_init_static_tls) (struct link_map *);
 #endif
 
@@ -466,7 +466,7 @@  struct rtld_global
     size_t count;
     void *list[50];
   } *_dl_scope_free_list;
-#if THREAD_GSCOPE_IN_TCB
+#if PTHREAD_IN_LIBC
   /* List of active thread stacks, with memory managed by glibc.  */
   EXTERN list_t _dl_stack_used;
 
@@ -486,7 +486,8 @@  struct rtld_global
 
   /* Mutex protecting the stack lists.  */
   EXTERN int _dl_stack_cache_lock;
-#else
+#endif
+#if !THREAD_GSCOPE_IN_TCB
   EXTERN int _dl_thread_gscope_count;
 #endif
 #ifdef SHARED
@@ -1297,13 +1298,13 @@  extern void _dl_aux_init (ElfW(auxv_t) *av)
 
 /* Initialize the static TLS space for the link map in all existing
    threads. */
-#if THREAD_GSCOPE_IN_TCB
+#if PTHREAD_IN_LIBC
 void _dl_init_static_tls (struct link_map *map) attribute_hidden;
 #endif
 static inline void
 dl_init_static_tls (struct link_map *map)
 {
-#if THREAD_GSCOPE_IN_TCB
+#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);