struct dtv_slotinfo_list *_dl_tls_dtv_slotinfo_list;
/* Number of modules in the static TLS block. */
size_t _dl_tls_static_nelem;
-/* Size of the static TLS block. Giving this initialized value
- preallocates some surplus bytes in the static TLS area. */
-size_t _dl_tls_static_size = 2048;
+/* Size of the static TLS block. */
+size_t _dl_tls_static_size;
/* Size actually allocated in the static TLS block. */
size_t _dl_tls_static_used;
/* Alignment requirement of the static TLS block. */
size_t _dl_tls_static_align;
+/* Size of surplus space in the static TLS area for dynamically
+ loaded modules with IE-model TLS or for TLSDESC optimization.
+ See comments in elf/dl-tls.c where it is initialized. */
+size_t _dl_tls_static_surplus;
/* Generation counter for the dtv. */
size_t _dl_tls_generation;
static void
init_static_tls (size_t memsz, size_t align)
{
- /* That is the size of the TLS memory for this object. The initialized
- value of _dl_tls_static_size is provided by dl-open.c to request some
- surplus that permits dynamic loading of modules with IE-model TLS. */
- GL(dl_tls_static_size) = roundup (memsz + GL(dl_tls_static_size),
+ /* That is the size of the TLS memory for this object. */
+ GL(dl_tls_static_size) = roundup (memsz + GLRO(dl_tls_static_surplus),
TLS_TCB_ALIGN);
#if TLS_TCB_AT_TP
GL(dl_tls_static_size) += TLS_TCB_SIZE;
break;
}
+ /* Calculate the size of the static TLS surplus. */
+ _dl_tls_static_surplus_init ();
+
/* We have to set up the TCB block which also (possibly) contains
'errno'. Therefore we avoid 'malloc' which might touch 'errno'.
Instead we use 'sbrk' which would only uses 'errno' if it fails.
In this case we are right away out of memory and the user gets
- what she/he deserves.
-
- The initialized value of _dl_tls_static_size is provided by dl-open.c
- to request some surplus that permits dynamic loading of modules with
- IE-model TLS. */
+ what she/he deserves. */
#if TLS_TCB_AT_TP
/* Align the TCB offset to the maximum alignment, as
_dl_allocate_tls_storage (in elf/dl-tls.c) does using __libc_memalign
and dl_tls_static_align. */
- tcb_offset = roundup (memsz + GL(dl_tls_static_size), max_align);
+ tcb_offset = roundup (memsz + GLRO(dl_tls_static_surplus), max_align);
tlsblock = __sbrk (tcb_offset + TLS_INIT_TCB_SIZE + max_align);
#elif TLS_DTV_AT_TP
tcb_offset = roundup (TLS_INIT_TCB_SIZE, align ?: 1);
tlsblock = __sbrk (tcb_offset + memsz + max_align
- + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size));
+ + TLS_PRE_TCB_SIZE + GLRO(dl_tls_static_surplus));
tlsblock += TLS_PRE_TCB_SIZE;
#else
/* In case a model with a different layout for the TCB and DTV
#include <dl-tls.h>
#include <ldsodefs.h>
-/* Amount of excess space to allocate in the static TLS area
- to allow dynamic loading of modules defining IE-model TLS data. */
-#define TLS_STATIC_SURPLUS 64 + DL_NNS * 176
+#define TUNABLE_NAMESPACE rtld
+#include <dl-tunables.h>
+
+/* Surplus static TLS, GLRO(dl_tls_static_surplus), is used for
+
+ - IE TLS in libc.so for all dlmopen namespaces except in the initial
+ one where libc.so is not loaded dynamically but at startup time,
+ - IE TLS in other libraries which may be dynamically loaded even in the
+ initial namespace,
+ - and optionally for optimizing dynamic TLS access.
+
+ The maximum number of namespaces is DL_NNS, but to support that many
+ namespaces correctly the static TLS allocation should be significantly
+ increased, which may cause problems with small thread stacks due to the
+ way static TLS is accounted (bug 11787).
+
+ So there is a rtld.nns tunable limit on the number of supported namespaces
+ that affects the size of the static TLS and by default it's small enough
+ not to cause problems with existing applications. The limit is not
+ enforced or checked: it is the user's responsibility to increase rtld.nns
+ if more dlmopen namespaces are used. */
+
+/* Size of initial-exec TLS in libc.so. */
+#define LIBC_IE_TLS 192
+/* Size of initial-exec TLS in libraries other than libc.so.
+ This should be large enough to cover runtime libraries of the
+ compiler such as libgomp and libraries in libc other than libc.so. */
+#define OTHER_IE_TLS 144
+/* Size of additional surplus TLS, placeholder for TLS optimizations. */
+#define OPT_SURPLUS_TLS 512
+void
+_dl_tls_static_surplus_init (void)
+{
+ size_t nns;
+
+#if HAVE_TUNABLES
+ nns = TUNABLE_GET (nns, size_t, NULL);
+#else
+ /* Default values of the tunables. */
+ nns = 4;
+#endif
+ if (nns > DL_NNS)
+ nns = DL_NNS;
+ GLRO(dl_tls_static_surplus) = ((nns - 1) * LIBC_IE_TLS
+ + nns * OTHER_IE_TLS
+ + OPT_SURPLUS_TLS);
+}
/* Out-of-memory handler. */
static void
}
GL(dl_tls_static_used) = offset;
- GL(dl_tls_static_size) = (roundup (offset + TLS_STATIC_SURPLUS, max_align)
+ GL(dl_tls_static_size) = (roundup (offset + GLRO(dl_tls_static_surplus),
+ max_align)
+ TLS_TCB_SIZE);
#elif TLS_DTV_AT_TP
/* The TLS blocks start right after the TCB. */
}
GL(dl_tls_static_used) = offset;
- GL(dl_tls_static_size) = roundup (offset + TLS_STATIC_SURPLUS,
+ GL(dl_tls_static_size) = roundup (offset + GLRO(dl_tls_static_surplus),
TLS_TCB_ALIGN);
#else
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
default: 3
}
}
+
+ rtld {
+ nns {
+ type: SIZE_T
+ minval: 1
+ maxval: 16
+ default: 4
+ }
+ }
}
}
assert (i == GL(dl_tls_max_dtv_idx));
+ /* Calculate the size of the static TLS surplus. */
+ _dl_tls_static_surplus_init ();
+
/* Compute the TLS offsets for the various blocks. */
_dl_determine_tlsoffset ();
@menu
* Tunable names:: The structure of a tunable name
* Memory Allocation Tunables:: Tunables in the memory allocation subsystem
+* Dynamic Linking Tunables:: Tunables in the dynamic linking subsystem
* Elision Tunables:: Tunables in elision subsystem
* POSIX Thread Tunables:: Tunables in the POSIX thread subsystem
* Hardware Capability Tunables:: Tunables that modify the hardware
passed to @code{malloc} for the largest bin size to enable.
@end deftp
+@node Dynamic Linking Tunables
+@section Dynamic Linking Tunables
+@cindex dynamic linking tunables
+@cindex rtld tunables
+
+@deftp {Tunable namespace} glibc.rtld
+Dynamic linker behavior can be modified by setting the
+following tunables in the @code{rtld} namespace:
+@end deftp
+
+@deftp Tunable glibc.rtld.nns
+Sets the number of supported dynamic link namespaces (see @code{dlmopen}).
+Currently this limit can be set between 1 and 16 inclusive, the default is 4.
+Each link namespace consumes some memory in all thread, and thus raising the
+limit will increase the amount of memory each thread uses. Raising the limit
+is useful when your application uses more than 4 dynamic linker audit modules
+e.g. @env{LD_AUDIT}, or will use more than 4 dynamic link namespaces as created
+by @code{dlmopen} with an lmid argument of @code{LM_ID_NEWLM}.
+@end deftp
+
@node Elision Tunables
@section Elision Tunables
@cindex elision tunables
binaries, don't honor for PIEs). */
EXTERN ElfW(Addr) _dl_use_load_bias;
+ /* Size of surplus space in the static TLS area for dynamically
+ loaded modules with IE-model TLS or for TLSDESC optimization.
+ See comments in elf/dl-tls.c where it is initialized. */
+ EXTERN size_t _dl_tls_static_surplus;
+
/* Name of the shared object to be profiled (if any). */
EXTERN const char *_dl_profile;
/* Filename of the output file. */
/* Calculate offset of the TLS blocks in the static TLS block. */
extern void _dl_determine_tlsoffset (void) attribute_hidden;
+/* Calculate the size of the static TLS surplus. */
+void _dl_tls_static_surplus_init (void) attribute_hidden;
+
#ifndef SHARED
/* Set up the TCB for statically linked applications. This is called
early during startup because we always use TLS (for errno and the