bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH glibc 1/3] XXX: Rename THREAD_GSCOPE_IN_TCB -> THREAD_GSCOPE_


From: Sergey Bugaev
Subject: [RFC PATCH glibc 1/3] XXX: Rename THREAD_GSCOPE_IN_TCB -> THREAD_GSCOPE_LINK_MAP
Date: Sun, 9 May 2021 16:54:02 +0300

This patch is probably bogus; but I'm including it anyway.

I've noticed that THREAD_GSCOPE_IN_TCB is actually being used not to
check whether the thread global scope state is being stored in TCB,
but rather as a general flag to distinguish between NPTL and HTL.

When THREAD_GSCOPE_IN_TCB is defined, glibc (namely elf/dl-*) uses
NPTL-specific internals, such as their stack link map. Since the
following patches will move HTL towards having the global scope flag
in TCB as well, but the distinction between NPTL and HTL is still
useful, I'm trying to rename this flag.

This new name is also bad, though.

Overall, it was my impression that glibc tries hard not to have
ifdef'ed code paths (dependent on the platform being built for) in
common code; they seem to use platform-specific versions of headers
instead. So perhaps instead of having an environment variable, the
right thing to do would be to move this code into platform-specific
files.
---
 elf/dl-reloc.c                | 4 ++--
 elf/dl-support.c              | 2 +-
 elf/dl-tls.c                  | 6 +++---
 elf/rtld.c                    | 2 +-
 sysdeps/aarch64/nptl/tls.h    | 2 +-
 sysdeps/alpha/nptl/tls.h      | 2 +-
 sysdeps/arc/nptl/tls.h        | 2 +-
 sysdeps/arm/nptl/tls.h        | 2 +-
 sysdeps/csky/nptl/tls.h       | 2 +-
 sysdeps/generic/ldsodefs.h    | 8 ++++----
 sysdeps/generic/tls.h         | 3 ++-
 sysdeps/hppa/nptl/tls.h       | 2 +-
 sysdeps/i386/nptl/tls.h       | 2 +-
 sysdeps/ia64/nptl/tls.h       | 2 +-
 sysdeps/m68k/nptl/tls.h       | 2 +-
 sysdeps/mach/hurd/tls.h       | 2 +-
 sysdeps/microblaze/nptl/tls.h | 2 +-
 sysdeps/mips/nptl/tls.h       | 2 +-
 sysdeps/nios2/nptl/tls.h      | 2 +-
 sysdeps/powerpc/nptl/tls.h    | 2 +-
 sysdeps/riscv/nptl/tls.h      | 2 +-
 sysdeps/s390/nptl/tls.h       | 2 +-
 sysdeps/sh/nptl/tls.h         | 2 +-
 sysdeps/sparc/nptl/tls.h      | 2 +-
 sysdeps/x86_64/nptl/tls.h     | 2 +-
 25 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
index bb9ca1a1..77e10895 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 !THREAD_GSCOPE_LINK_MAP
 /* 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 /* !THREAD_GSCOPE_LINK_MAP */
 
 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 f966a2e7..af340bee 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -189,7 +189,7 @@ ElfW(Word) _dl_stack_flags = DEFAULT_STACK_PERMS;
 int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable;
 
 
-#if THREAD_GSCOPE_IN_TCB
+#if THREAD_GSCOPE_LINK_MAP
 list_t _dl_stack_used;
 list_t _dl_stack_user;
 int _dl_stack_cache_lock;
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 6baff0c1..8a7c534b 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 THREAD_GSCOPE_LINK_MAP
 # include <list.h>
 #endif
 
@@ -1010,7 +1010,7 @@ cannot create TLS data structures"));
     }
 }
 
-#if THREAD_GSCOPE_IN_TCB
+#if THREAD_GSCOPE_LINK_MAP
 static inline void __attribute__((always_inline))
 init_one_static_tls (struct pthread *curp, struct link_map *map)
 {
@@ -1043,4 +1043,4 @@ _dl_init_static_tls (struct link_map *map)
 
   lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE);
 }
-#endif /* THREAD_GSCOPE_IN_TCB */
+#endif /* THREAD_GSCOPE_LINK_MAP */
diff --git a/elf/rtld.c b/elf/rtld.c
index ad325d4c..1857479a 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1139,7 +1139,7 @@ dl_main (const ElfW(Phdr) *phdr,
   struct dl_main_state state;
   dl_main_state_init (&state);
 
-#if !THREAD_GSCOPE_IN_TCB
+#if !THREAD_GSCOPE_LINK_MAP
   GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
 #endif
 
diff --git a/sysdeps/aarch64/nptl/tls.h b/sysdeps/aarch64/nptl/tls.h
index 6e896207..a21a0826 100644
--- a/sysdeps/aarch64/nptl/tls.h
+++ b/sysdeps/aarch64/nptl/tls.h
@@ -109,7 +109,7 @@ typedef struct
   descr->member[idx] = (value)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-# define THREAD_GSCOPE_IN_TCB      1
+# define THREAD_GSCOPE_LINK_MAP      1
 # define THREAD_GSCOPE_FLAG_UNUSED 0
 # define THREAD_GSCOPE_FLAG_USED   1
 # define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/alpha/nptl/tls.h b/sysdeps/alpha/nptl/tls.h
index 4dbccc52..d15defaa 100644
--- a/sysdeps/alpha/nptl/tls.h
+++ b/sysdeps/alpha/nptl/tls.h
@@ -103,7 +103,7 @@ typedef struct
   descr->member[idx] = (value)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/arc/nptl/tls.h b/sysdeps/arc/nptl/tls.h
index 95300fdd..0d8e789a 100644
--- a/sysdeps/arc/nptl/tls.h
+++ b/sysdeps/arc/nptl/tls.h
@@ -111,7 +111,7 @@ typedef struct
   descr->member[idx] = (value)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/arm/nptl/tls.h b/sysdeps/arm/nptl/tls.h
index 1bd11307..39832204 100644
--- a/sysdeps/arm/nptl/tls.h
+++ b/sysdeps/arm/nptl/tls.h
@@ -100,7 +100,7 @@ typedef struct
   descr->member[idx] = (value)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/csky/nptl/tls.h b/sysdeps/csky/nptl/tls.h
index 7a234041..fe89a6f8 100644
--- a/sysdeps/csky/nptl/tls.h
+++ b/sysdeps/csky/nptl/tls.h
@@ -127,7 +127,7 @@ typedef struct
   descr->member[idx] = (value)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-# define THREAD_GSCOPE_IN_TCB      1
+# define THREAD_GSCOPE_LINK_MAP      1
 # define THREAD_GSCOPE_FLAG_UNUSED 0
 # define THREAD_GSCOPE_FLAG_USED   1
 # define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 1b064c58..7e087763 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -464,7 +464,7 @@ struct rtld_global
   /* Generation counter for the dtv.  */
   EXTERN size_t _dl_tls_generation;
 
-#if !THREAD_GSCOPE_IN_TCB
+#if !THREAD_GSCOPE_LINK_MAP
   EXTERN void (*_dl_init_static_tls) (struct link_map *);
 #endif
 
@@ -474,7 +474,7 @@ struct rtld_global
     size_t count;
     void *list[50];
   } *_dl_scope_free_list;
-#if THREAD_GSCOPE_IN_TCB
+#if THREAD_GSCOPE_LINK_MAP
   /* List of active thread stacks, with memory managed by glibc.  */
   EXTERN list_t _dl_stack_used;
 
@@ -1274,13 +1274,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 THREAD_GSCOPE_LINK_MAP
 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 THREAD_GSCOPE_LINK_MAP
   /* The stack list is available to ld.so, so the initialization can
      be handled within ld.so directly.  */
   _dl_init_static_tls (map);
diff --git a/sysdeps/generic/tls.h b/sysdeps/generic/tls.h
index e86d70e6..be4606fc 100644
--- a/sysdeps/generic/tls.h
+++ b/sysdeps/generic/tls.h
@@ -73,8 +73,9 @@
      to the dtv or the TCB (from which the DTV can found).
 
 
-     THREAD_GSCOPE_IN_TCB
+     THREAD_GSCOPE_LINK_MAP
 
+     XXX: TODO
      This should be set to 1 if the global scope flag is stored within the TCB.
      When set to 0, GL(_dl_thread_gscope_count) will be defined to store it.
   */
diff --git a/sysdeps/hppa/nptl/tls.h b/sysdeps/hppa/nptl/tls.h
index 857003a7..8524bfa7 100644
--- a/sysdeps/hppa/nptl/tls.h
+++ b/sysdeps/hppa/nptl/tls.h
@@ -134,7 +134,7 @@ static inline void __set_cr27(struct pthread *cr27)
 }
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index 86ee1ef3..8c3951a5 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -375,7 +375,7 @@ tls_fill_user_desc (union user_desc_init *desc,
 
 
 /* Get and set the global scope generation counter in the TCB head.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/ia64/nptl/tls.h b/sysdeps/ia64/nptl/tls.h
index 66d9bf31..19a9f644 100644
--- a/sysdeps/ia64/nptl/tls.h
+++ b/sysdeps/ia64/nptl/tls.h
@@ -155,7 +155,7 @@ register struct pthread *__thread_self __asm__("r13");
    = THREAD_GET_POINTER_GUARD ())
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/m68k/nptl/tls.h b/sysdeps/m68k/nptl/tls.h
index cfcd6d2b..d580c7f7 100644
--- a/sysdeps/m68k/nptl/tls.h
+++ b/sysdeps/m68k/nptl/tls.h
@@ -133,7 +133,7 @@ extern void * __m68k_read_tp (void);
 # define NO_TLS_OFFSET         -1
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/mach/hurd/tls.h b/sysdeps/mach/hurd/tls.h
index f83956d3..8cbf22aa 100644
--- a/sysdeps/mach/hurd/tls.h
+++ b/sysdeps/mach/hurd/tls.h
@@ -53,7 +53,7 @@
   (((tcbhead_t *) (descr))->dtv)
 
 /* Global scope switch support.  */
-#define THREAD_GSCOPE_IN_TCB      0
+#define THREAD_GSCOPE_LINK_MAP    0
 #define THREAD_GSCOPE_GLOBAL
 #define THREAD_GSCOPE_SET_FLAG() \
   atomic_exchange_and_add_acq (&GL(dl_thread_gscope_count), 1)
diff --git a/sysdeps/microblaze/nptl/tls.h b/sysdeps/microblaze/nptl/tls.h
index c93d90b1..ca74eaf7 100644
--- a/sysdeps/microblaze/nptl/tls.h
+++ b/sysdeps/microblaze/nptl/tls.h
@@ -116,7 +116,7 @@ typedef struct
   (descr->member[idx] = (value))
 
 /* Get and set the global scope generation counter in struct pthread.  */
-# define THREAD_GSCOPE_IN_TCB      1
+# define THREAD_GSCOPE_LINK_MAP      1
 # define THREAD_GSCOPE_FLAG_UNUSED 0
 # define THREAD_GSCOPE_FLAG_USED   1
 # define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h
index c09f4907..cc2b2ba4 100644
--- a/sysdeps/mips/nptl/tls.h
+++ b/sysdeps/mips/nptl/tls.h
@@ -158,7 +158,7 @@ typedef struct
 # define NO_TLS_OFFSET         -1
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/nios2/nptl/tls.h b/sysdeps/nios2/nptl/tls.h
index 02a05b4e..a03f2337 100644
--- a/sysdeps/nios2/nptl/tls.h
+++ b/sysdeps/nios2/nptl/tls.h
@@ -137,7 +137,7 @@ register struct pthread *__thread_self __asm__("r23");
 # define NO_TLS_OFFSET         -1
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h
index 6c779b66..06cc9de0 100644
--- a/sysdeps/powerpc/nptl/tls.h
+++ b/sysdeps/powerpc/nptl/tls.h
@@ -231,7 +231,7 @@ typedef struct
 # define NO_TLS_OFFSET         -1
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/riscv/nptl/tls.h b/sysdeps/riscv/nptl/tls.h
index 5350bcc0..51885ac2 100644
--- a/sysdeps/riscv/nptl/tls.h
+++ b/sysdeps/riscv/nptl/tls.h
@@ -119,7 +119,7 @@ typedef struct
 # define NO_TLS_OFFSET         -1
 
 /* Get and set the global scope generation counter in struct pthread.  */
-# define THREAD_GSCOPE_IN_TCB      1
+# define THREAD_GSCOPE_LINK_MAP      1
 # define THREAD_GSCOPE_FLAG_UNUSED 0
 # define THREAD_GSCOPE_FLAG_USED   1
 # define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/s390/nptl/tls.h b/sysdeps/s390/nptl/tls.h
index efb52515..6167a1e5 100644
--- a/sysdeps/s390/nptl/tls.h
+++ b/sysdeps/s390/nptl/tls.h
@@ -165,7 +165,7 @@ typedef struct
 #define THREAD_COPY_POINTER_GUARD(descr)
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/sh/nptl/tls.h b/sysdeps/sh/nptl/tls.h
index ac3c9a9e..86fd7920 100644
--- a/sysdeps/sh/nptl/tls.h
+++ b/sysdeps/sh/nptl/tls.h
@@ -141,7 +141,7 @@ typedef struct
      ((tcbhead_t *) (descr + 1))->pointer_guard        = 
__tcbp->pointer_guard;})
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/sparc/nptl/tls.h b/sysdeps/sparc/nptl/tls.h
index dd1eb82a..dde3862f 100644
--- a/sysdeps/sparc/nptl/tls.h
+++ b/sysdeps/sparc/nptl/tls.h
@@ -138,7 +138,7 @@ register struct pthread *__thread_self __asm__("%g7");
   ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
 
 /* Get and set the global scope generation counter in struct pthread.  */
-#define THREAD_GSCOPE_IN_TCB      1
+#define THREAD_GSCOPE_LINK_MAP      1
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
 #define THREAD_GSCOPE_FLAG_WAIT   2
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index a78c4f4d..8538bdd6 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -326,7 +326,7 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 
0x80,
 
 
 /* Get and set the global scope generation counter in the TCB head.  */
-# define THREAD_GSCOPE_IN_TCB      1
+# define THREAD_GSCOPE_LINK_MAP      1
 # define THREAD_GSCOPE_FLAG_UNUSED 0
 # define THREAD_GSCOPE_FLAG_USED   1
 # define THREAD_GSCOPE_FLAG_WAIT   2
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]