about summary refs log tree commit diff
path: root/nptl/nptl-init.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-05-21 22:35:00 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-05-21 22:35:00 +0200
commitd03511f48f49fcb9bec4305586c26ab5d0063022 (patch)
tree7608e5705c830e8c710e785e3bfc5a90e8986cb4 /nptl/nptl-init.c
parent2f69522d460611b1018e15df6c238dda2d8d6609 (diff)
downloadglibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.gz
glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.xz
glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.zip
nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables
Use the  __nptl_tls_static_size_for_stack inline function instead,
and the GLRO (dl_tls_static_align) value directly.

The computation of GLRO (dl_tls_static_align)  in
_dl_determine_tlsoffset ensures that the alignment is at least
TLS_TCB_ALIGN, which at least STACK_ALIGN (see allocate_stack).
Therefore, the additional rounding-up step is removed.

ALso move the initialization of the default stack size from
__pthread_initialize_minimal_internal to __pthread_early_init.
This introduces an extra system call during single-threaded startup,
but this simplifies the initialization sequence.  No locking is
needed around the writes to __default_pthread_attr because the
process is single-threaded at this point.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl/nptl-init.c')
-rw-r--r--nptl/nptl-init.c46
1 files changed, 3 insertions, 43 deletions
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index bc4831ac89..732e580355 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -36,10 +36,7 @@
 #include <kernel-features.h>
 #include <libc-pointer-arith.h>
 #include <pthread_mutex_conf.h>
-
-/* Size and alignment of static TLS block.  */
-size_t __static_tls_size;
-size_t __static_tls_align_m1;
+#include <nptl-stack.h>
 
 /* Version of the library, used in libthread_db to detect mismatches.  */
 static const char nptl_version[] __attribute_used__ = VERSION;
@@ -47,44 +44,6 @@ static const char nptl_version[] __attribute_used__ = VERSION;
 void
 __pthread_initialize_minimal_internal (void)
 {
-  /* Get the size of the static and alignment requirements for the TLS
-     block.  */
-  size_t static_tls_align;
-  _dl_get_tls_static_info (&__static_tls_size, &static_tls_align);
-
-  /* Make sure the size takes all the alignments into account.  */
-  if (STACK_ALIGN > static_tls_align)
-    static_tls_align = STACK_ALIGN;
-  __static_tls_align_m1 = static_tls_align - 1;
-
-  __static_tls_size = roundup (__static_tls_size, static_tls_align);
-
-  /* Determine the default allowed stack size.  This is the size used
-     in case the user does not specify one.  */
-  struct rlimit limit;
-  if (__getrlimit (RLIMIT_STACK, &limit) != 0
-      || limit.rlim_cur == RLIM_INFINITY)
-    /* The system limit is not usable.  Use an architecture-specific
-       default.  */
-    limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
-  else if (limit.rlim_cur < PTHREAD_STACK_MIN)
-    /* The system limit is unusably small.
-       Use the minimal size acceptable.  */
-    limit.rlim_cur = PTHREAD_STACK_MIN;
-
-  /* Make sure it meets the minimum size that allocate_stack
-     (allocatestack.c) will demand, which depends on the page size.  */
-  const uintptr_t pagesz = GLRO(dl_pagesize);
-  const size_t minstack = pagesz + __static_tls_size + MINIMAL_REST_STACK;
-  if (limit.rlim_cur < minstack)
-    limit.rlim_cur = minstack;
-
-  /* Round the resource limit up to page size.  */
-  limit.rlim_cur = ALIGN_UP (limit.rlim_cur, pagesz);
-  lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
-  __default_pthread_attr.internal.stacksize = limit.rlim_cur;
-  __default_pthread_attr.internal.guardsize = GLRO (dl_pagesize);
-  lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
 }
 strong_alias (__pthread_initialize_minimal_internal,
 	      __pthread_initialize_minimal)
@@ -101,5 +60,6 @@ strong_alias (__pthread_initialize_minimal_internal,
 size_t
 __pthread_get_minstack (const pthread_attr_t *attr)
 {
-  return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN;
+  return (GLRO(dl_pagesize) + __nptl_tls_static_size_for_stack ()
+	  + PTHREAD_STACK_MIN);
 }