* [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
@ 2021-08-18 2:28 H.J. Lu
2021-09-20 16:52 ` PING^1 " H.J. Lu
2021-09-29 18:57 ` Adhemerval Zanella
0 siblings, 2 replies; 5+ messages in thread
From: H.J. Lu @ 2021-08-18 2:28 UTC (permalink / raw)
To: libc-alpha
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.
---
elf/dl-load.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index cb0618b7fc..aab290bea6 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
+ /* Also copy l_addr and l_ld. */
+ 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);
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* PING^1 [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
2021-08-18 2:28 [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace H.J. Lu
@ 2021-09-20 16:52 ` H.J. Lu
2021-09-29 16:59 ` PING^2 " H.J. Lu
2021-09-29 18:57 ` Adhemerval Zanella
1 sibling, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2021-09-20 16:52 UTC (permalink / raw)
To: GNU C Library, Carlos O'Donell, Florian Weimer
On Tue, Aug 17, 2021 at 7:28 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> 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.
> ---
> elf/dl-load.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index cb0618b7fc..aab290bea6 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -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);
>
> + /* Also copy l_addr and l_ld. */
> + 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);
> --
> 2.31.1
>
PING.
--
H.J.
^ permalink raw reply [flat|nested] 5+ messages in thread
* PING^2 [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
2021-09-20 16:52 ` PING^1 " H.J. Lu
@ 2021-09-29 16:59 ` H.J. Lu
0 siblings, 0 replies; 5+ messages in thread
From: H.J. Lu @ 2021-09-29 16:59 UTC (permalink / raw)
To: GNU C Library, Carlos O'Donell, Florian Weimer
On Mon, Sep 20, 2021 at 9:52 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Aug 17, 2021 at 7:28 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > 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.
> > ---
> > elf/dl-load.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/elf/dl-load.c b/elf/dl-load.c
> > index cb0618b7fc..aab290bea6 100644
> > --- a/elf/dl-load.c
> > +++ b/elf/dl-load.c
> > @@ -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);
> >
> > + /* Also copy l_addr and l_ld. */
> > + 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);
> > --
> > 2.31.1
> >
>
> PING.
>
Any comments on this patch?
--
H.J.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
2021-08-18 2:28 [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace H.J. Lu
2021-09-20 16:52 ` PING^1 " H.J. Lu
@ 2021-09-29 18:57 ` Adhemerval Zanella
2021-09-29 19:38 ` H.J. Lu
1 sibling, 1 reply; 5+ messages in thread
From: Adhemerval Zanella @ 2021-09-29 18:57 UTC (permalink / raw)
To: H.J. Lu, libc-alpha
On 17/08/2021 23:28, H.J. Lu via Libc-alpha wrote:
> 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.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> elf/dl-load.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index cb0618b7fc..aab290bea6 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -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);
>
> + /* Also copy l_addr and l_ld. */
This comments seems obvious, maybe add it is required 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);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
2021-09-29 18:57 ` Adhemerval Zanella
@ 2021-09-29 19:38 ` H.J. Lu
0 siblings, 0 replies; 5+ messages in thread
From: H.J. Lu @ 2021-09-29 19:38 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: GNU C Library
[-- Attachment #1: Type: text/plain, Size: 1567 bytes --]
On Wed, Sep 29, 2021 at 11:57 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
> On 17/08/2021 23:28, H.J. Lu via Libc-alpha wrote:
> > 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.
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> > ---
> > elf/dl-load.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/elf/dl-load.c b/elf/dl-load.c
> > index cb0618b7fc..aab290bea6 100644
> > --- a/elf/dl-load.c
> > +++ b/elf/dl-load.c
> > @@ -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);
> >
> > + /* Also copy l_addr and l_ld. */
>
> This comments seems obvious, maybe add it is required to avoid a
> GDB warning with dlmopen();
Changed to
/* 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);
> >
This is the patch I am checking in.
Thanks.
--
H.J.
[-- Attachment #2: 0001-elf-Copy-l_addr-l_ld-when-adding-ld.so-to-a-new-name.patch --]
[-- Type: text/x-patch, Size: 1324 bytes --]
From bb4cf09c2699cdc8e5380598dc8075dfa19203d1 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 17 Aug 2021 19:36:04 -0700
Subject: [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace
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 | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 6ea71077af..99c5ab83b3 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -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);
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-29 19:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 2:28 [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace H.J. Lu
2021-09-20 16:52 ` PING^1 " H.J. Lu
2021-09-29 16:59 ` PING^2 " H.J. Lu
2021-09-29 18:57 ` Adhemerval Zanella
2021-09-29 19:38 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).