b1dca6
commit 4d0985543f479a6f421d4d8a9e0d1dc71c9c2c53
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Tue Dec 15 20:56:04 2020 +0100
b1dca6
b1dca6
    elf: Record libc.so link map when it is the main program (bug 20972)
b1dca6
    
b1dca6
    Otherwise, it will not participate in the dependency sorting.
b1dca6
    
b1dca6
    Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147
b1dca6
    ("elf: Include libc.so.6 as main program in dependency sort
b1dca6
    (bug 20972)").
b1dca6
b1dca6
Conflicts:
b1dca6
	elf/rtld.c
b1dca6
	  (Missing backported header include.)
b1dca6
b1dca6
diff --git a/elf/rtld.c b/elf/rtld.c
b1dca6
index fde5a6a4a485207e..992f825ba00762a7 100644
b1dca6
--- a/elf/rtld.c
b1dca6
+++ b/elf/rtld.c
b1dca6
@@ -46,6 +46,7 @@
b1dca6
 #include <array_length.h>
b1dca6
 #include <libc-early-init.h>
b1dca6
 #include <dl-main.h>
b1dca6
+#include <gnu/lib-names.h>
b1dca6
 
b1dca6
 #include <assert.h>
b1dca6
 
b1dca6
@@ -1588,6 +1589,16 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
b1dca6
     {
b1dca6
       /* Extract the contents of the dynamic section for easy access.  */
b1dca6
       elf_get_dynamic_info (main_map, NULL);
b1dca6
+
b1dca6
+      /* If the main map is libc.so, update the base namespace to
b1dca6
+	 refer to this map.  If libc.so is loaded later, this happens
b1dca6
+	 in _dl_map_object_from_fd.  */
b1dca6
+      if (main_map->l_info[DT_SONAME] != NULL
b1dca6
+	  && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB])
b1dca6
+		      + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO)
b1dca6
+	      == 0))
b1dca6
+	GL(dl_ns)[LM_ID_BASE].libc_map = main_map;
b1dca6
+
b1dca6
       /* Set up our cache of pointers into the hash table.  */
b1dca6
       _dl_setup_hash (main_map);
b1dca6
     }