From d03511f48f49fcb9bec4305586c26ab5d0063022 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 21 May 2021 22:35:00 +0200 Subject: 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 --- nptl/nptl-init.c | 46 +++------------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) (limited to 'nptl/nptl-init.c') 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 #include #include - -/* Size and alignment of static TLS block. */ -size_t __static_tls_size; -size_t __static_tls_align_m1; +#include /* 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); } -- cgit 1.4.1