public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Daniel Walker <danielwa@cisco.com>
Cc: GNU C Library <libc-alpha@sourceware.org>, GDB <gdb@sourceware.org>
Subject: Re: [PATCH v2 2/2] Extend struct r_debug to support multiple namespaces
Date: Tue, 17 Aug 2021 19:36:49 -0700	[thread overview]
Message-ID: <CAMe9rOruVp9mvemyiOtQvYZD5TdEkwpNoYzBGww2hS0fy0eLgw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOp3za1xxNpTS7JZnprsE11Y9U=mqt=d-q5NZXk6PQU4-Q@mail.gmail.com>

On Tue, Aug 17, 2021 at 5:21 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Aug 17, 2021 at 1:26 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Tue, Aug 17, 2021 at 10:57 AM Daniel Walker <danielwa@cisco.com> wrote:
> > >
> > > On Mon, Aug 16, 2021 at 06:06:29PM -0700, H.J. Lu wrote:
> > > > Glibc does not provide an interface for debugger to access libraries
> > > > loaded in multiple namespaces via dlmopen.
> > > >
> > > > The current rtld-debugger interface is described in the file:
> > > >
> > > > elf/rtld-debugger-interface.txt
> > > >
> > > > under the "Standard debugger interface" heading.  This interface only
> > > > provides access to the first link-map (LM_ID_BASE).
> > > >
> > > > Based on the patch from Conan C Huang <conhuang@cisco.com>:
> > > >
> > > > https://sourceware.org/pipermail/libc-alpha/2020-June/115448.html
> > > >
> > > > 1. Bump r_version to 2.  This triggers the GDB bug:
> > > >
> > > > https://sourceware.org/bugzilla/show_bug.cgi?id=28236
> > > >
> > > > 2. Add struct r_debug_extended to extend struct r_debug into a linked-list,
> > > > where each element correlates to an unique namespace.
> > > > 3. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended.
> > > > 4. Provide the compatibility symbol, _r_debug, with size of struct r_debug,
> > > > as an alise of _r_debug_extended, for programs which reference _r_debug.
> > >
> > >
> > > I've attached the GDB patch which was created at Cisco to support our version of
> > > this type of feature which is similar to what you've created. You might be able
> > > to make some small modifications to make it work for you.
> > >
> > > Daniel
> >
> >
>
> It seems to work pretty well with some cleanup:
>
> https://gitlab.com/x86-binutils/binutils-gdb/-/commit/ea336450f484fc8c0aa512a60bc99f69309a46d8
>
> (gdb) set  stop-on-solib-events 1
> (gdb) r --direct
> Starting program:
> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-dlmopen4
> --direct
> Stopped due to shared library event (no libraries added or removed)
> (gdb) c
> Continuing.
> warning: Unable to find libthread_db matching inferior's thread
> library, thread debugging will not be available.
> Stopped due to shared library event:
>   Inferior loaded
> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/libc.so.6
> (gdb)
> Continuing.
> Stopped due to shared library event (no libraries added or removed)
> (gdb)
> Continuing.
> warning: .dynamic section for
> "/export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/ld-linux-x86-64.so.2"
> is not at the expected address (wrong library or version mismatch?)
> warning: Unable to find libthread_db matching inferior's thread
> library, thread debugging will not be available.
> Stopped due to shared library event:
>   Inferior loaded
> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-dlmopen1mod.so
>     /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/libc.so.6
>     /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/ld-linux-x86-64.so.2
> (gdb)
> Continuing.
> Stopped due to shared library event (no libraries added or removed)
> (gdb)
> Continuing.
> Stopped due to shared library event:
>   Inferior unloaded
> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-dlmopen1mod.so
>     /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/libc.so.6
>     /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/ld-linux-x86-64.so.2
> (gdb)
> Continuing.
> [Inferior 1 (process 638559) exited normally]
> (gdb)
>
> (gdb) r --direct
> Starting program:
> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-dlmopen4
> --direct
> warning: Unable to find libthread_db matching inferior's thread
> library, thread debugging will not be available.
> warning: .dynamic section for
> "/export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/ld-linux-x86-64.so.2"
> is not at the expected address (wrong library or version mismatch?)
> warning: Unable to find libthread_db matching inferior's thread
> library, thread debugging will not be available.
> [Inferior 1 (process 638480) exited normally]
> (gdb)
>
> It looks like l_ld of ld.so in the new namespace isn't set properly:
>
> (gdb) p debug->r_next->r_map
> $5 = (struct link_map *) 0x408360
> (gdb) p *debug->r_next->r_map
> $6 = {l_addr = 140737351757824,
>   l_name = 0x4082f0
> "/export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-dlmopen1mod.so",
> l_ld = 0x7ffff7dbee10, l_next = 0x408900,
>   l_prev = 0x0}
> (gdb) p *debug->r_next->r_map->l_next
> $7 = {l_addr = 140737349664768,
>   l_name = 0x4088a0
> "/export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/libc.so.6",
> l_ld = 0x7ffff7daabc0, l_next = 0x408e90, l_prev = 0x408360}
> (gdb) p *debug->r_next->r_map->l_next->l_next
> $8 = {l_addr = 0,
>   l_name = 0x408e20
> "/export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/ld-linux-x86-64.so.2",
> l_ld = 0x0, l_next = 0x0, l_prev = 0x408900}
> (gdb)
>
>

Please try glibc users/hjl/pr15971/r_version branch:

https://gitlab.com/x86-glibc/glibc/-/tree/users/hjl/pr15971/r_version

and GDB users/hjl/pr11839/master branch:

https://gitlab.com/x86-binutils/binutils-gdb/-/tree/users/hjl/pr11839/master


-- 
H.J.

  reply	other threads:[~2021-08-18  2:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17  1:06 [PATCH v2 0/2] " H.J. Lu
2021-08-17  1:06 ` [PATCH v2 1/2] Add declare_object_symbol_alias for assembly codes [BZ #28128] H.J. Lu
2021-08-17  1:06 ` [PATCH v2 2/2] Extend struct r_debug to support multiple namespaces H.J. Lu
2021-08-17 17:44   ` Daniel Walker
2021-08-17 20:25     ` H.J. Lu
2021-08-18  0:14       ` H.J. Lu
2021-08-17 17:57   ` Daniel Walker
2021-08-17 20:26     ` H.J. Lu
2021-08-18  0:21       ` H.J. Lu
2021-08-18  2:36         ` H.J. Lu [this message]
2021-08-18 13:34           ` H.J. Lu
2021-08-17 17:57 ` [PATCH v2 0/2] " Joseph Myers

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=CAMe9rOruVp9mvemyiOtQvYZD5TdEkwpNoYzBGww2hS0fy0eLgw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=danielwa@cisco.com \
    --cc=gdb@sourceware.org \
    --cc=libc-alpha@sourceware.org \
    /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).