abe59f
commit 88361b408b9dbd313f15413cc2e6be0f1cafb01a
abe59f
Author: H.J. Lu <hjl.tools@gmail.com>
abe59f
Date:   Tue Aug 17 19:36:04 2021 -0700
abe59f
abe59f
    elf: Copy l_addr/l_ld when adding ld.so to a new namespace
abe59f
    
abe59f
    When add ld.so to a new namespace, we don't actually load ld.so.  We
abe59f
    create a new link map and refers the real one for almost everything.
abe59f
    Copy l_addr and l_ld from the real ld.so link map to avoid GDB warning:
abe59f
    
abe59f
    warning: .dynamic section for ".../elf/ld-linux-x86-64.so.2" is not at the expected address (wrong library or version mismatch?)
abe59f
    
abe59f
    when handling shared library loaded by dlmopen.
abe59f
    
abe59f
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
abe59f
abe59f
diff --git a/elf/dl-load.c b/elf/dl-load.c
abe59f
index cdb5d4b5b67f1ca1..303e6594f9af9b7e 100644
abe59f
--- a/elf/dl-load.c
abe59f
+++ b/elf/dl-load.c
abe59f
@@ -932,6 +932,10 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
abe59f
       /* Refer to the real descriptor.  */
abe59f
       l->l_real = &GL(dl_rtld_map);
abe59f
 
abe59f
+      /* Copy l_addr and l_ld to avoid a GDB warning with dlmopen().  */
abe59f
+      l->l_addr = l->l_real->l_addr;
abe59f
+      l->l_ld = l->l_real->l_ld;
abe59f
+
abe59f
       /* No need to bump the refcount of the real object, ld.so will
abe59f
 	 never be unloaded.  */
abe59f
       __close_nocancel (fd);