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 v6 2/2] Extend struct r_debug to support multiple namespaces
Date: Tue, 7 Sep 2021 08:18:04 -0700	[thread overview]
Message-ID: <CAMe9rOqK4nd7=WimRfZiu0RtqxEWQEHMJWFyPtg1yju+RQMHLg@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOozmPuta5GoDAJ4Oq9EMvjAPqk10Xwy9yk_QJtBHgknCw@mail.gmail.com>

On Mon, Sep 6, 2021 at 7:31 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Sep 6, 2021 at 7:24 AM Florian Weimer <fweimer@redhat.com> wrote:
> >
> > * H. J. Lu:
> >
> > > On Mon, Sep 6, 2021 at 2:39 AM Florian Weimer <fweimer@redhat.com> wrote:
> > >>
> > >> * H. J. Lu:
> > >>
> > >> > +* The r_version update in the debugger interface makes the glibc binary
> > >> > +  incompatible with GDB binaries built without the following commits:
> > >> > +
> > >> > +  c0154a4a21a gdb: Don't assume r_ldsomap when r_version > 1 on Linux
> > >> > +  4eb629d50d4 gdbserver: Check r_version < 1 for Linux debugger interface
> > >>
> > >> Does this incompatibility happen even if audit modules and dlmopen are
> > >> not used?
> > >
> > > Yes.
> >
> > Why?  Can't we keep r_version at 1 in this case?
>
> r_version is checked in GDB whenever DT_DEBUG is used to access
> the rtld debug interface, independent of audit modules and dlmopen.
>
> We can bump r_version only if a non-default namespace is used.

Fixed.

> > >> This puts the assember output from the compiler through the
> > >> preprocessor.  That seems to be brittle.  I think you would have to
> > >> preprocess the manually written fragment separately.
> > >>
> > >> However, I think we are overdesigning things here.  The following in
> > >> dl-debug-symbols-gen.c should work (and the file should have a different
> > >> name then):
> > >>
> > >> /* Alias _r_debug to a prefix of _r_debug_extended.  */
> > >> asm (".set _r_debug, _r_debug_extended\n\t"
> > >>      ".type _r_debug, %object\n\t"
> > >>      ".symver _r_debug_extended, _r_debug@@" FIRST_VERSION_ld__r_debug_STRING);
> > >> #if __WORDSIZE == 64
> > >> _Static_assert (sizeof (struct r_debug) == 40, "sizeof (struct r_debug)");
> > >> asm (".size _r_debug, 40");
> > >> #else
> > >> _Static_assert (sizeof (struct r_debug) == 20, "sizeof (struct r_debug)");
> > >> asm (".size _r_debug, 20");
> > >> #endif
> > >>
> > >> It's not exactly pretty, but at least it's obvious what is going on.
> > >> (Extended asm with input operands is not supported outside of functions.)
> > >
> > > This was the first thing I tried and it didn't work:
> > >
> > > [hjl@gnu-cfl-2 tmp]$ cat foo.s
> > > .set  _r_debug, _r_debug_extended
> > > .globl _r_debug
> > > .type _r_debug, %object
> > > .size _r_debug, 40
> > > .data
> > > .type _r_debug_extended, %object
> > > .size _r_debug_extended, 48
> > > .globl _r_debug_extended
> > > _r_debug_extended:
> > > .zero 48
> > > [hjl@gnu-cfl-2 tmp]$ gcc -c foo.s
> > > [hjl@gnu-cfl-2 tmp]$ readelf -sW foo.o | grep _r_debug
> > >      1: 0000000000000000    48 OBJECT  GLOBAL DEFAULT    2 _r_debug
> > >      2: 0000000000000000    48 OBJECT  GLOBAL DEFAULT    2 _r_debug_extended
> > > [hjl@gnu-cfl-2 tmp]$
> >
> > Huh.  Does this mean this depends on the symbol definition order in the
> > assembler file?
> >
> > I really hate the post-processing of compiler output.  This isn't GHC. 8->
> >
> > Can we write a portable assembler file instead?
> >
> > Nick Clifton has written down some guidelines:
> >
> >   Tips for writing portable assembler with GNU Assembler (GAS)
> >   <https://developers.redhat.com/blog/2021/02/26/tips-for-writing-portable-assembler-with-gnu-assembler-gas>
> >
> > There's no initializer, so all we need to know is size and alignment.
>
> Yes, I can do that.

Fixed.

> > >> Is this necessary?  It makes concurrent access to the list harder and
> > >
> > > When _dl_close_worker is called, it holds GL(dl_load_lock).  Why does
> > > this change make concurrent access harder?
> >
> > Something else might want to read the list directly, by starting with
> > DT_DEBUG.
>
> I can add _dl_debug_get and use _dl_debug_initialize only for initialization.
> Will it work?
>

I submitted the v7 patch with:

1. Rewrite dl-debug-symbols.S and remove dl-debug-compat-symbols.c.
2. Bump r_version to 2 only when multiple namespaces are used.
3. Verify r_version == 1 without multiple namespaces.
4. Keep the empty (unused) namespace on the namespace linked list.
5. Use atomic_store_release to update r_version and r_next.
6. Add _dl_debug_update without adding the namespace to the namespace
linked list.

-- 
H.J.

      reply	other threads:[~2021-09-07 15:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 17:38 [PATCH v6 0/2] " H.J. Lu
2021-08-30 17:38 ` [PATCH v6 1/2] Add declare_object_symbol_alias for assembly codes [BZ #28128] H.J. Lu
2021-08-30 17:38 ` [PATCH v6 2/2] Extend struct r_debug to support multiple namespaces H.J. Lu
2021-09-06  9:39   ` Florian Weimer
2021-09-06 13:19     ` H.J. Lu
2021-09-06 14:24       ` Florian Weimer
2021-09-06 14:31         ` H.J. Lu
2021-09-07 15:18           ` 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='CAMe9rOqK4nd7=WimRfZiu0RtqxEWQEHMJWFyPtg1yju+RQMHLg@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).