public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: GNU C Library <libc-alpha@sourceware.org>,
	GDB <gdb@sourceware.org>,
	 libc-coord@lists.openwall.com,
	Daniel Walker <danielwa@cisco.com>
Subject: Re: [PATCH v8 1/1] Extend struct r_debug to support multiple namespaces [BZ #15971]
Date: Fri, 10 Sep 2021 12:26:48 -0700	[thread overview]
Message-ID: <CAMe9rOrnPcvWZ1fu0Pmvt6-yHNQhObV2EKhgGFTP2+9xKziy-Q@mail.gmail.com> (raw)
In-Reply-To: <87h7esfe8p.fsf@oldenburg.str.redhat.com>

On Fri, Sep 10, 2021 at 11:59 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > diff --git a/elf/link.h b/elf/link.h
> > index ff3a85c847..a297318236 100644
> > --- a/elf/link.h
> > +++ b/elf/link.h
> > @@ -34,14 +34,13 @@
>
> > -/* This is the instance of that structure used by the dynamic linker.  */
> > +/* This is the compatibility symbol of that structure provided by the
> > +   dynamic linker.  */
> >  extern struct r_debug _r_debug;
>
> I don't think we should say “compatibility symbol” in a public header.

I will remove "compatibility".

> Can we move GNAT off this symbol and deprecate it at least?

There is no harm in keeping it.

> > +/* The extended rendezvous structure used by the run-time dynamic linker
> > +   to communicate details of shared object loading to the debugger.  If
> > +   the executable's dynamic section has a DT_DEBUG element, the run-time
> > +   linker sets that element's value to the address where this structure
> > +   can be found.  */
> > +
> > +struct r_debug_extended
> > +  {
> > +    struct r_debug base;
> > +
> > +    /* The following field is added by r_version == 2.  */
> > +
> > +    /* Link to the next r_debug_extended structure.  Each r_debug_extended
> > +       structure represents a different namespace.  The first
> > +       r_debug_extended structure is for the default namespace.  */
> > +    struct r_debug_extended *r_next;
> > +  };
> > +
> >  /* This symbol refers to the "dynamic structure" in the `.dynamic' section
> >     of whatever module refers to `_DYNAMIC'.  So, to find its own
> > -   `struct r_debug', a program could do:
> > +   `struct r_debug_extended', a program could do:
> >       for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
> >         if (dyn->d_tag == DT_DEBUG)
> > -      r_debug = (struct r_debug *) dyn->d_un.d_ptr;
> > -   */
> > +      r_debug_extended = (struct r_debug_extended *) dyn->d_un.d_ptr;
> > + */
> >  extern ElfW(Dyn) _DYNAMIC[];
>
> What about shared objects?  How can they find r_debug_extended?  Should
> they just make sure they have DT_DEBUG in their dynamic section?

Linker generates DT_DEBUG only in the executable.   dl_iterate_phdr can be
used to locate DT_DEBUG in the executable.

>
> Calling getauxval (AT_PHDR) has a relocation dependencies, which I
> expect some consumers want to avoid.
>
> > +Extension to the r_debug structure
> > +==================================
> > +
> > +The r_debug_extended structure is an extension of the r_debug interface.
> > +If r_version is 2, one additional field is available:
> > +
> > +  struct r_debug_extended *r_next;
> > +    Link to the next r_debug_extended structure.  Each r_debug_extended
> > +    structure represents a different namespace.  The first r_debug_extended
> > +    structure is for the default namespace.
>
> I think this should say how a reader can determine which list elements
> are in fact active.

I will update it.

>
> > diff --git a/elf/tst-dlmopen4.c b/elf/tst-dlmopen4.c
> > new file mode 100644
> > index 0000000000..7a6c502e8c
> > --- /dev/null
> > +++ b/elf/tst-dlmopen4.c
>
> > +static int
> > +do_test (void)
> > +{
> > +  void *h = xdlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so",
> > +                   RTLD_LAZY);
>
> I think this should test that r_version is 1 before the dlmopen call.

I will add the test.

> > +
> > +  int status = EXIT_FAILURE;
> > +  ElfW(Dyn) *d;
> > +  for (d = _DYNAMIC; d->d_tag != DT_NULL; ++d)
> > +    {
> > +      struct r_debug_extended *debug = ELF_MACHINE_GET_R_DEBUG (d);
> > +      if (debug != NULL)
> > +     {
> > +       TEST_VERIFY_EXIT (debug->base.r_version == 2);
>
> You could use TEST_COMPARE.

I will fix it.

>
> > +       TEST_VERIFY_EXIT (debug->r_next != NULL);
> > +       TEST_VERIFY_EXIT (debug->r_next->r_next == NULL);
> > +       TEST_VERIFY_EXIT (debug->r_next->base.r_map != NULL);
> > +       TEST_VERIFY_EXIT (debug->r_next->base.r_map->l_name != NULL);
> > +       const char *name = basename (debug->r_next->base.r_map->l_name);
> > +       TEST_VERIFY_EXIT (strcmp (name, "tst-dlmopen1mod.so") == 0);
>
> You could use TEST_COMPARE_STRING.

I will fix it.

> Sorry, I have not reviewed the actual mechanics of the patch.
>
> Thanks,
> Florian
>

Thanks.

-- 
H.J.

      reply	other threads:[~2021-09-10 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 18:25 [PATCH v8 0/1] Extend struct r_debug to support multiple namespaces H.J. Lu
2021-09-08 18:25 ` [PATCH v8 1/1] Extend struct r_debug to support multiple namespaces [BZ #15971] H.J. Lu
2021-09-10 18:59   ` Florian Weimer
2021-09-10 19:26     ` H.J. Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOrnPcvWZ1fu0Pmvt6-yHNQhObV2EKhgGFTP2+9xKziy-Q@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=danielwa@cisco.com \
    --cc=fweimer@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=libc-alpha@sourceware.org \
    --cc=libc-coord@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).