]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Use __libc_initial to detect an inner libc
authorFlorian Weimer <fweimer@redhat.com>
Wed, 16 Dec 2020 14:09:52 +0000 (15:09 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 16 Dec 2020 14:13:40 +0000 (15:13 +0100)
The secondary/non-primary/inner libc (loaded via dlmopen, LD_AUDIT,
static dlopen) must not use sbrk to allocate member because that would
interfere with allocations in the outer libc.  On Linux, this does not
matter because sbrk itself was changed to fail in secondary libcs.

 _dl_addr occasionally shows up in profiles, but had to be used before
because __libc_multiple_libs was unreliable.  So this change achieves
a slight reduction in startup time.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
malloc/arena.c
malloc/malloc.c

index 202daf15b06ac0871675630948d2c1c9007159c4..3c9c0ecd86b27b6b63d6140edcd204ce1c4254c6 100644 (file)
@@ -294,14 +294,11 @@ ptmalloc_init (void)
   __malloc_initialized = 0;
 
 #ifdef SHARED
-  /* In case this libc copy is in a non-default namespace, never use brk.
-     Likewise if dlopened from statically linked program.  */
-  Dl_info di;
-  struct link_map *l;
-
-  if (_dl_open_hook != NULL
-      || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0
-          && l->l_ns != LM_ID_BASE))
+  /* In case this libc copy is in a non-default namespace, never use
+     brk.  Likewise if dlopened from statically linked program.  The
+     generic sbrk implementation also enforces this, but it is not
+     used on Hurd.  */
+  if (!__libc_initial)
     __morecore = __failing_morecore;
 #endif
 
index ec2d934595956502b7ea629c0137d5378500d8e9..326075e704c03d5768846e306e5ade9038b5cde0 100644 (file)
 /* For SINGLE_THREAD_P.  */
 #include <sysdep-cancel.h>
 
+#include <libc-internal.h>
+
 /*
   Debugging: