diff mbox series

[RFC,v7,07/20] elf/dl-open.c: Don't try libc linit in namespaces with no libc mapping

Message ID 20201216132650.22949-8-vivek@collabora.com
State New
Headers show
Series Implementation of RTLD_SHARED for dlmopen | expand

Commit Message

Vivek Das Mohapatra Dec. 16, 2020, 1:26 p.m. UTC
Secondary namespaces which share their libc mapping with the main
namespace cannot (and should not) have _dl_call_libc_early_init
called for them by dl_open_worker.
---
 elf/dl-open.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/elf/dl-open.c b/elf/dl-open.c
index 809845e5e9..a995e9086f 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -792,16 +792,21 @@  dl_open_worker (void *a)
      namespace.  */
   if (!args->libc_already_loaded)
     {
+      /* If this is a secondary (nsid != LM_ID_BASE) namespace then
+         it is POSSIBLE there's no libc_map at all - We use the one
+         shared with LM_ID_BASE instead (which MUST already be
+         initialised for us to even reach here).  */
       struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map;
 #ifdef SHARED
-      bool initial = libc_map->l_ns == LM_ID_BASE;
+      bool initial = libc_map && (libc_map->l_real->l_ns == LM_ID_BASE);
 #else
       /* In the static case, there is only one namespace, but it
 	 contains a secondary libc (the primary libc is statically
 	 linked).  */
       bool initial = false;
 #endif
-      _dl_call_libc_early_init (libc_map, initial);
+      if (libc_map != NULL)
+        _dl_call_libc_early_init (libc_map, initial);
     }
 
 #ifndef SHARED