public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
@ 2021-03-15 10:03 Florian Weimer
  2021-03-15 12:10 ` H.J. Lu
  2021-03-15 12:49 ` Andreas Schwab
  0 siblings, 2 replies; 9+ messages in thread
From: Florian Weimer @ 2021-03-15 10:03 UTC (permalink / raw)
  To: libc-alpha

In this case, use the link map of the dynamic loader itself as
a replacement.  This is more than just a hack: if we ever support
DT_RUNPATH/DT_RPATH for the dynamic loader, reporting it for
ld.so --help (without further command line arguments) would be the
right thing to do.

Fixes commit 332421312576bd7095e70589154af99b124dd2d1 ("elf: Always
set l in _dl_init_paths (bug 23462)").

Tested on i686-linux-gnu and x86_64-linux-gnu.

---
 elf/Makefile  | 10 +++++++++-
 elf/dl-load.c |  8 +++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 4c9e63dac9..ebb331df36 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -245,7 +245,8 @@ tests += $(tests-execstack-$(have-z-execstack))
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-leaks1-mem.out \
 		 $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out \
-		 $(objpfx)tst-ldconfig-X.out
+		 $(objpfx)tst-ldconfig-X.out $(objpfx)tst-rtld-help.out \
+		 $(objpfx)tst-rtld-help-2.out
 endif
 tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@@ -1907,3 +1908,10 @@ $(objpfx)list-tunables.out: tst-rtld-list-tunables.sh $(objpfx)ld.so
 	$(evaluate-test)
 
 tst-dst-static-ENV = LD_LIBRARY_PATH='$$ORIGIN'
+
+$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
+	$(test-wrapper) $(rtld-prefix) --help > $@; \
+	$(evaluate-test)
+$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
+	grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
+	$(evaluate-test)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 376a2e64d6..2f760503c5 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -758,8 +758,14 @@ _dl_init_paths (const char *llp, const char *source,
   max_dirnamelen = SYSTEM_DIRS_MAX_LEN;
   *aelem = NULL;
 
-  /* This points to the map of the main object.  */
+  /* This points to the map of the main object.  If there is no main
+     object (e.g., under --help, use the dynamic loader itself as a
+     stand-in.  */
   l = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
+#ifdef SHARED
+  if (l == NULL)
+    l = &GL (dl_rtld_map);
+#endif
   assert (l->l_type != lt_loaded);
 
   if (l->l_info[DT_RUNPATH])


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 10:03 [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577] Florian Weimer
@ 2021-03-15 12:10 ` H.J. Lu
  2021-03-15 12:14   ` Florian Weimer
  2021-03-15 12:49 ` Andreas Schwab
  1 sibling, 1 reply; 9+ messages in thread
From: H.J. Lu @ 2021-03-15 12:10 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Mon, Mar 15, 2021 at 3:03 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> In this case, use the link map of the dynamic loader itself as
> a replacement.  This is more than just a hack: if we ever support
> DT_RUNPATH/DT_RPATH for the dynamic loader, reporting it for
> ld.so --help (without further command line arguments) would be the
> right thing to do.
>
> Fixes commit 332421312576bd7095e70589154af99b124dd2d1 ("elf: Always
> set l in _dl_init_paths (bug 23462)").
>
> Tested on i686-linux-gnu and x86_64-linux-gnu.
>
> ---
>  elf/Makefile  | 10 +++++++++-
>  elf/dl-load.c |  8 +++++++-
>  2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 4c9e63dac9..ebb331df36 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -245,7 +245,8 @@ tests += $(tests-execstack-$(have-z-execstack))
>  ifeq ($(run-built-tests),yes)
>  tests-special += $(objpfx)tst-leaks1-mem.out \
>                  $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out \
> -                $(objpfx)tst-ldconfig-X.out
> +                $(objpfx)tst-ldconfig-X.out $(objpfx)tst-rtld-help.out \
> +                $(objpfx)tst-rtld-help-2.out
>  endif
>  tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>  tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> @@ -1907,3 +1908,10 @@ $(objpfx)list-tunables.out: tst-rtld-list-tunables.sh $(objpfx)ld.so
>         $(evaluate-test)
>
>  tst-dst-static-ENV = LD_LIBRARY_PATH='$$ORIGIN'
> +
> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
> +       $(evaluate-test)
> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
> +       $(evaluate-test)

Can we avoid tst-rtld-help-2.out by grep $@ directly?

> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index 376a2e64d6..2f760503c5 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -758,8 +758,14 @@ _dl_init_paths (const char *llp, const char *source,
>    max_dirnamelen = SYSTEM_DIRS_MAX_LEN;
>    *aelem = NULL;
>
> -  /* This points to the map of the main object.  */
> +  /* This points to the map of the main object.  If there is no main
> +     object (e.g., under --help, use the dynamic loader itself as a
> +     stand-in.  */
>    l = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
> +#ifdef SHARED
> +  if (l == NULL)
> +    l = &GL (dl_rtld_map);
> +#endif
>    assert (l->l_type != lt_loaded);
>
>    if (l->l_info[DT_RUNPATH])
>


-- 
H.J.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:10 ` H.J. Lu
@ 2021-03-15 12:14   ` Florian Weimer
  2021-03-15 12:24     ` H.J. Lu
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2021-03-15 12:14 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

* H. J. Lu:

>> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
>> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
>> +       $(evaluate-test)
>> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
>> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
>> +       $(evaluate-test)
>
> Can we avoid tst-rtld-help-2.out by grep $@ directly?

We could use &&, but that would make diagnosing test failures difficult
(as in: did --help fail, or grep?).  The separate test seemed the
easiest way.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:14   ` Florian Weimer
@ 2021-03-15 12:24     ` H.J. Lu
  2021-03-15 12:28       ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: H.J. Lu @ 2021-03-15 12:24 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Mon, Mar 15, 2021 at 5:14 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> >> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
> >> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
> >> +       $(evaluate-test)
> >> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
> >> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
> >> +       $(evaluate-test)
> >
> > Can we avoid tst-rtld-help-2.out by grep $@ directly?
>
> We could use &&, but that would make diagnosing test failures difficult
> (as in: did --help fail, or grep?).  The separate test seemed the
> easiest way.
>

Running "ld.so --help" itself is very straight forward.   When there
is foo.out, I
usually search for foo.

-- 
H.J.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:24     ` H.J. Lu
@ 2021-03-15 12:28       ` Florian Weimer
  2021-03-15 12:48         ` H.J. Lu
  0 siblings, 1 reply; 9+ messages in thread
From: Florian Weimer @ 2021-03-15 12:28 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

* H. J. Lu:

> On Mon, Mar 15, 2021 at 5:14 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu:
>>
>> >> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
>> >> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
>> >> +       $(evaluate-test)
>> >> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
>> >> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
>> >> +       $(evaluate-test)
>> >
>> > Can we avoid tst-rtld-help-2.out by grep $@ directly?
>>
>> We could use &&, but that would make diagnosing test failures difficult
>> (as in: did --help fail, or grep?).  The separate test seemed the
>> easiest way.
>
> Running "ld.so --help" itself is very straight forward.  When there is
> foo.out, I usually search for foo.

Sorry, I don't understand what your comment means in this context.
Would you please elaborate?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:28       ` Florian Weimer
@ 2021-03-15 12:48         ` H.J. Lu
  2021-03-15 12:55           ` Florian Weimer
  0 siblings, 1 reply; 9+ messages in thread
From: H.J. Lu @ 2021-03-15 12:48 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Mon, Mar 15, 2021 at 5:28 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > On Mon, Mar 15, 2021 at 5:14 AM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * H. J. Lu:
> >>
> >> >> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
> >> >> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
> >> >> +       $(evaluate-test)
> >> >> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
> >> >> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
> >> >> +       $(evaluate-test)
> >> >
> >> > Can we avoid tst-rtld-help-2.out by grep $@ directly?
> >>
> >> We could use &&, but that would make diagnosing test failures difficult
> >> (as in: did --help fail, or grep?).  The separate test seemed the
> >> easiest way.
> >
> > Running "ld.so --help" itself is very straight forward.  When there is
> > foo.out, I usually search for foo.
>
> Sorry, I don't understand what your comment means in this context.
> Would you please elaborate?

A single tst-rtld-help.out doesn't make diagnosing ld.so --help
failures difficult.
Multiple output files is confusing.

-- 
H.J.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 10:03 [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577] Florian Weimer
  2021-03-15 12:10 ` H.J. Lu
@ 2021-03-15 12:49 ` Andreas Schwab
  2021-03-15 12:55   ` Florian Weimer
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2021-03-15 12:49 UTC (permalink / raw)
  To: Florian Weimer via Libc-alpha; +Cc: Florian Weimer

On Mär 15 2021, Florian Weimer via Libc-alpha wrote:

> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
> +	grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
> +	$(evaluate-test)

Shouldn't that create the target?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:48         ` H.J. Lu
@ 2021-03-15 12:55           ` Florian Weimer
  0 siblings, 0 replies; 9+ messages in thread
From: Florian Weimer @ 2021-03-15 12:55 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

* H. J. Lu:

> On Mon, Mar 15, 2021 at 5:28 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu:
>>
>> > On Mon, Mar 15, 2021 at 5:14 AM Florian Weimer <fweimer@redhat.com> wrote:
>> >>
>> >> * H. J. Lu:
>> >>
>> >> >> +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so
>> >> >> +       $(test-wrapper) $(rtld-prefix) --help > $@; \
>> >> >> +       $(evaluate-test)
>> >> >> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
>> >> >> +       grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
>> >> >> +       $(evaluate-test)
>> >> >
>> >> > Can we avoid tst-rtld-help-2.out by grep $@ directly?
>> >>
>> >> We could use &&, but that would make diagnosing test failures difficult
>> >> (as in: did --help fail, or grep?).  The separate test seemed the
>> >> easiest way.
>> >
>> > Running "ld.so --help" itself is very straight forward.  When there is
>> > foo.out, I usually search for foo.
>>
>> Sorry, I don't understand what your comment means in this context.
>> Would you please elaborate?
>
> A single tst-rtld-help.out doesn't make diagnosing ld.so --help
> failures difficult.
> Multiple output files is confusing.

All mtrace tests do this.  However, I will submit a different patch with
just one target.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
  2021-03-15 12:49 ` Andreas Schwab
@ 2021-03-15 12:55   ` Florian Weimer
  0 siblings, 0 replies; 9+ messages in thread
From: Florian Weimer @ 2021-03-15 12:55 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer via Libc-alpha

* Andreas Schwab:

> On Mär 15 2021, Florian Weimer via Libc-alpha wrote:
>
>> +$(objpfx)tst-rtld-help-2.out: $(objpfx)tst-rtld-help.out
>> +	grep -q 'Legacy HWCAP subdirectories under library search path directories' $<; \
>> +	$(evaluate-test)
>
> Shouldn't that create the target?

H.J. wants me to remove the separate target.  It will address this issue
as well.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-15 12:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 10:03 [PATCH] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577] Florian Weimer
2021-03-15 12:10 ` H.J. Lu
2021-03-15 12:14   ` Florian Weimer
2021-03-15 12:24     ` H.J. Lu
2021-03-15 12:28       ` Florian Weimer
2021-03-15 12:48         ` H.J. Lu
2021-03-15 12:55           ` Florian Weimer
2021-03-15 12:49 ` Andreas Schwab
2021-03-15 12:55   ` Florian Weimer

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).