Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 10 Sep 2021 20:59:50 +0200
From: Florian Weimer <fweimer@...hat.com>
To: "H.J. Lu" <hjl.tools@...il.com>
Cc: libc-alpha@...rceware.org,  gdb@...rceware.org,
  libc-coord@...ts.openwall.com,  Daniel Walker <danielwa@...co.com>
Subject: Re: [PATCH v8 1/1] Extend struct r_debug to support multiple
 namespaces [BZ #15971]

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

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

> +/* 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?

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.

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

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

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

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

Thanks,
Florian

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.