break;
}
- /* Calculate the size of the static TLS surplus. */
- _dl_tls_static_surplus_init ();
+ /* Calculate the size of the static TLS surplus, with 0 auditors. */
+ _dl_tls_static_surplus_init (0);
/* We have to set up the TCB block which also (possibly) contains
'errno'. Therefore we avoid 'malloc' which might touch 'errno'.
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. */
+ if more dlmopen namespaces are used.
+
+ Audit modules use their own namespaces, they are not included in rtld.nns,
+ but come on top when computing the number of namespaces. */
/* Size of initial-exec TLS in libc.so. */
#define LIBC_IE_TLS 192
/* Size of additional surplus TLS, placeholder for TLS optimizations. */
#define OPT_SURPLUS_TLS 512
+/* Calculate the size of the static TLS surplus, when the given
+ number of audit modules are loaded. Must be called after the
+ number of audit modules is known and before static TLS allocation. */
void
-_dl_tls_static_surplus_init (void)
+_dl_tls_static_surplus_init (size_t naudit)
{
size_t nns;
#endif
if (nns > DL_NNS)
nns = DL_NNS;
+ if (DL_NNS - nns < naudit)
+ _dl_fatal_printf ("Failed loading %lu audit modules, %lu are supported.\n",
+ (unsigned long) naudit, (unsigned long) (DL_NNS - nns));
+ nns += naudit;
+
GLRO(dl_tls_static_surplus) = ((nns - 1) * LIBC_IE_TLS
+ nns * OTHER_IE_TLS
+ OPT_SURPLUS_TLS);
}
}
+/* Count audit modules before they are loaded so GLRO(dl_naudit)
+ is not yet usable. */
+static size_t
+audit_list_count (struct audit_list *list)
+{
+ /* Restore the audit_list iterator state at the end. */
+ const char *saved_tail = list->current_tail;
+ size_t naudit = 0;
+
+ assert (list->current_index == 0);
+ while (audit_list_next (list) != NULL)
+ naudit++;
+ list->current_tail = saved_tail;
+ list->current_index = 0;
+ return naudit;
+}
+
#ifndef HAVE_INLINED_SYSCALLS
/* Set nonzero during loading and initialization of executable and
libraries, cleared before the executable's entry point runs. This
static bool tls_init_tp_called;
static void *
-init_tls (void)
+init_tls (size_t naudit)
{
/* Number of elements in the static TLS block. */
GL(dl_tls_static_nelem) = GL(dl_tls_max_dtv_idx);
assert (i == GL(dl_tls_max_dtv_idx));
/* Calculate the size of the static TLS surplus. */
- _dl_tls_static_surplus_init ();
+ _dl_tls_static_surplus_init (naudit);
/* Compute the TLS offsets for the various blocks. */
_dl_determine_tlsoffset ();
bool need_security_init = true;
if (audit_list.length > 0)
{
+ size_t naudit = audit_list_count (&audit_list);
+
/* Since we start using the auditing DSOs right away we need to
initialize the data structures now. */
- tcbp = init_tls ();
+ tcbp = init_tls (naudit);
/* Initialize security features. We need to do it this early
since otherwise the constructors of the audit libraries will
need_security_init = false;
load_audit_modules (main_map, &audit_list);
+
+ /* The count based on audit strings may overestimate the number
+ of audit modules that got loaded, but not underestimate. */
+ assert (GLRO(dl_naudit) <= naudit);
}
/* Keep track of the currently loaded modules to count how many
multiple threads (from a non-TLS-using libpthread). */
bool was_tls_init_tp_called = tls_init_tp_called;
if (tcbp == NULL)
- tcbp = init_tls ();
+ tcbp = init_tls (0);
if (__glibc_likely (need_security_init))
/* Initialize security features. But only if we have not done it
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}.
+is useful when your application uses more than 4 dynamic link namespaces as
+created by @code{dlmopen} with an lmid argument of @code{LM_ID_NEWLM}.
+Dynamic linker audit modules are loaded in their own dynamic link namespaces,
+but they are not accounted for in @code{glibc.rtld.nns}. They implicitly
+increase the per-thread memory usage as necessary, so this tunable does
+not need to be changed to allow many audit modules e.g. via @env{LD_AUDIT}.
@end deftp
@node Elision Tunables
/* 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;
+/* Calculate the size of the static TLS surplus, when the given
+ number of audit modules are loaded. */
+void _dl_tls_static_surplus_init (size_t naudit) attribute_hidden;
#ifndef SHARED
/* Set up the TCB for statically linked applications. This is called