* [PATCH] elf: Record libc.so link map when it is the main program (bug 20972)
@ 2020-12-15 10:57 Florian Weimer
2020-12-15 19:50 ` Carlos O'Donell
2020-12-16 13:32 ` Raphael M Zinsly
0 siblings, 2 replies; 3+ messages in thread
From: Florian Weimer @ 2020-12-15 10:57 UTC (permalink / raw)
To: libc-alpha
Otherwise, it will not participate in the dependency sorting.
Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147
("elf: Include libc.so.6 as main program in dependency sort
(bug 20972)").
---
elf/rtld.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/elf/rtld.c b/elf/rtld.c
index 526360237f..38f11f5b73 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -49,6 +49,7 @@
#include <libc-early-init.h>
#include <dl-main.h>
#include <list.h>
+#include <gnu/lib-names.h>
#include <assert.h>
@@ -1609,6 +1610,16 @@ dl_main (const ElfW(Phdr) *phdr,
{
/* Extract the contents of the dynamic section for easy access. */
elf_get_dynamic_info (main_map, NULL);
+
+ /* If the main map is libc.so, update the base namespace to
+ refer to this map. If libc.so is loaded later, this happens
+ in _dl_map_object_from_fd. */
+ if (main_map->l_info[DT_SONAME] != NULL
+ && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB])
+ + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO)
+ == 0))
+ GL(dl_ns)[LM_ID_BASE].libc_map = main_map;
+
/* Set up our cache of pointers into the hash table. */
_dl_setup_hash (main_map);
}
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf: Record libc.so link map when it is the main program (bug 20972)
2020-12-15 10:57 [PATCH] elf: Record libc.so link map when it is the main program (bug 20972) Florian Weimer
@ 2020-12-15 19:50 ` Carlos O'Donell
2020-12-16 13:32 ` Raphael M Zinsly
1 sibling, 0 replies; 3+ messages in thread
From: Carlos O'Donell @ 2020-12-15 19:50 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 12/15/20 5:57 AM, Florian Weimer via Libc-alpha wrote:
> Otherwise, it will not participate in the dependency sorting.
>
> Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147
> ("elf: Include libc.so.6 as main program in dependency sort
> (bug 20972)").
Thanks for catching this, I hadn't noticed that the map won't get
assigned.
For the record I think all of this code should be deleted. We should
not be allowing libc.so.6 to be run as a binary, instead all of that
functionality should move into ld.so where we should query libc.so.6
when run in --verbose to provide the same information. We might
have to keep libc.so.6 as a binary, but it should syscall write
"Please run ld.so --help." :-)
LGTM.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> elf/rtld.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 526360237f..38f11f5b73 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -49,6 +49,7 @@
> #include <libc-early-init.h>
> #include <dl-main.h>
> #include <list.h>
> +#include <gnu/lib-names.h>
>
> #include <assert.h>
>
> @@ -1609,6 +1610,16 @@ dl_main (const ElfW(Phdr) *phdr,
> {
> /* Extract the contents of the dynamic section for easy access. */
> elf_get_dynamic_info (main_map, NULL);
> +
> + /* If the main map is libc.so, update the base namespace to
> + refer to this map. If libc.so is loaded later, this happens
> + in _dl_map_object_from_fd. */
> + if (main_map->l_info[DT_SONAME] != NULL
> + && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB])
> + + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO)
> + == 0))
> + GL(dl_ns)[LM_ID_BASE].libc_map = main_map;
OK.
> +
> /* Set up our cache of pointers into the hash table. */
> _dl_setup_hash (main_map);
> }
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf: Record libc.so link map when it is the main program (bug 20972)
2020-12-15 10:57 [PATCH] elf: Record libc.so link map when it is the main program (bug 20972) Florian Weimer
2020-12-15 19:50 ` Carlos O'Donell
@ 2020-12-16 13:32 ` Raphael M Zinsly
1 sibling, 0 replies; 3+ messages in thread
From: Raphael M Zinsly @ 2020-12-16 13:32 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
The patch LGTM.
And I agree with Carlos, running libc.so.6 as binary shouldn't be allowed.
On 15/12/2020 07:57, Florian Weimer via Libc-alpha wrote:
> Otherwise, it will not participate in the dependency sorting.
>
> Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147
> ("elf: Include libc.so.6 as main program in dependency sort
> (bug 20972)").
>
> ---
> elf/rtld.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 526360237f..38f11f5b73 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -49,6 +49,7 @@
> #include <libc-early-init.h>
> #include <dl-main.h>
> #include <list.h>
> +#include <gnu/lib-names.h>
>
> #include <assert.h>
>
> @@ -1609,6 +1610,16 @@ dl_main (const ElfW(Phdr) *phdr,
> {
> /* Extract the contents of the dynamic section for easy access. */
> elf_get_dynamic_info (main_map, NULL);
> +
> + /* If the main map is libc.so, update the base namespace to
> + refer to this map. If libc.so is loaded later, this happens
> + in _dl_map_object_from_fd. */
> + if (main_map->l_info[DT_SONAME] != NULL
> + && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB])
> + + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO)
> + == 0))
> + GL(dl_ns)[LM_ID_BASE].libc_map = main_map;
> +
> /* Set up our cache of pointers into the hash table. */
> _dl_setup_hash (main_map);
> }
>
--
Raphael Moreira Zinsly
IBM
Linux on Power Toolchain
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-16 13:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 10:57 [PATCH] elf: Record libc.so link map when it is the main program (bug 20972) Florian Weimer
2020-12-15 19:50 ` Carlos O'Donell
2020-12-16 13:32 ` Raphael M Zinsly
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).