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