]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Copy l_addr/l_ld when adding ld.so to a new namespace
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 18 Aug 2021 02:36:04 +0000 (19:36 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 29 Sep 2021 23:15:44 +0000 (16:15 -0700)
When add ld.so to a new namespace, we don't actually load ld.so.  We
create a new link map and refers the real one for almost everything.
Copy l_addr and l_ld from the real ld.so link map to avoid GDB warning:

warning: .dynamic section for ".../elf/ld-linux-x86-64.so.2" is not at the expected address (wrong library or version mismatch?)

when handling shared library loaded by dlmopen.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/dl-load.c

index 6ea71077afc2852c4da86e09bb1d6f58bef6fd6d..99c5ab83b3d85e8e8d9e8484b9f98c7ae8cc25c7 100644 (file)
@@ -1026,6 +1026,10 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
       /* Refer to the real descriptor.  */
       l->l_real = &GL(dl_rtld_map);
 
+      /* Copy l_addr and l_ld to avoid a GDB warning with dlmopen().  */
+      l->l_addr = l->l_real->l_addr;
+      l->l_ld = l->l_real->l_ld;
+
       /* No need to bump the refcount of the real object, ld.so will
         never be unloaded.  */
       __close_nocancel (fd);