From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Pedro Alves <palves@redhat.com>, Zack Weinberg <zackw@panix.com>
Cc: GNU C Library <libc-alpha@sourceware.org>, gdb@sourceware.org
Subject: Re: Using libthread_db.so with single-threaded programs, for TLS access (was: Re: [RFC PATCH 0/3] Pretty-printing for errno)
Date: Wed, 13 Sep 2017 19:27:00 -0000 [thread overview]
Message-ID: <1505330791.1896.10.camel@skynet.be> (raw)
In-Reply-To: <72a8ac9b-2429-c8bd-83b9-d758224571c5@redhat.com>
On Wed, 2017-09-13 at 12:22 +0100, Pedro Alves wrote:
> On 09/07/2017 12:34 PM, Pedro Alves wrote:
> > On 09/06/2017 10:03 PM, Zack Weinberg wrote:
> >
> > > So, changes to both gdb and libthread_db seem to be required
> > > here.  I
> > > do think that _in principle_ it ought to be possible to use
> > > libthread_db to retrieve the address of thread-local data even if
> > > the
> > > inferior is not linked with libpthread; glibc has quite a few
> > > thread-specific variables (errno most prominent, of course, but
> > > also
> > > h_errno, _res, etc), and so might any library which can be used
> > > from
> > > both single- and multithreaded programs.
> > >
> > > This is really not code I feel comfortable hacking up, though,
> > > and
> > > it's probably more of a project than I have time for, in any
> > > case.
> >
> > Sounds like a promising approach though.  I'd like to see this path
> > explored a bit more.  I'll keep this in my TODO, even though it's
> > not likely to bubble up very soon.  Thanks for the
> > discussion/ideas!
>
> So I played with this a bit more on the plane back from Cauldron,
> to try to see if we'd hit some major roadblock.  I also chatted
> with Carlos a bit about this back at the Cauldron, and seemingly
> there's no major reason this can't be made to work,
> TLS-internals-wise.
>
> Seems like that it's mainly a case of moving libthread_db.so-related
> symbols from libpthread.so elsewhere.  More below.
Note that in the valgrind gdbserver, I had to handle the same problem
i.e. find the address of a tls variable without access to any
library (valgrind cannot make use of any library including glibc).
So, I finally end-ed up implementing the minimum logic for that.
It is based on some real ugly hacks, e.g. to get the offset of
lm_modid in struct link_map.
There is also some arch dependent 1 or 2 lines of code to get the dtv.
This is all somewhat fragile, was done in 2014, not broken (yet).
But some more recent changes might have broken the hack,
as I have a test failing after upgrading to Debian 9.
See valgrind coregrind/m_gdbserver/server.c handling of qGetTLSAddr
for
the gory/hacky details.
Better (even partial) support for such things without the need of a
library would significantly improve my life :)
Philippe
next prev parent reply other threads:[~2017-09-13 19:27 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 22:45 [RFC PATCH 0/3] Pretty-printing for errno Zack Weinberg
2017-06-22 22:45 ` [PATCH 1/3] Improve testing of GDB pretty-printers Zack Weinberg
2017-06-22 22:46 ` [PATCH 3/3] Add pretty-printer for errno Zack Weinberg
2017-06-22 22:46 ` [PATCH 2/3] Make error_t always int; make __errno_location return an __error_t Zack Weinberg
2017-06-29 15:48 ` [RFC PATCH 0/3] Pretty-printing for errno Phil Muldoon
2017-06-29 16:53 ` Pedro Alves
2017-06-29 17:02 ` Pedro Alves
2017-06-29 17:28 ` Pedro Alves
2017-06-30 0:28 ` Zack Weinberg
2017-06-30 16:38 ` Pedro Alves
2017-06-30 16:47 ` Pedro Alves
2017-06-30 17:27 ` Zack Weinberg
2017-06-30 18:11 ` Pedro Alves
2017-07-01 11:56 ` Pedro Alves
2017-07-13 2:30 ` Pedro Alves
2017-09-04 21:25 ` Pedro Alves
2017-09-05 21:15 ` Zack Weinberg
2017-09-05 22:32 ` Pedro Alves
2017-09-06 13:05 ` Zack Weinberg
2017-09-06 13:32 ` Pedro Alves
2017-09-06 21:03 ` Zack Weinberg
[not found] ` <2432779a-f146-1612-236e-84dde15c5d01@redhat.com>
2017-09-13 11:22 ` Using libthread_db.so with single-threaded programs, for TLS access (was: Re: [RFC PATCH 0/3] Pretty-printing for errno) Pedro Alves
2017-09-13 19:27 ` Philippe Waroquiers [this message]
2017-09-14 0:02 ` Using libthread_db.so with single-threaded programs, for TLS access Pedro Alves
2017-09-18 13:17 ` Carlos O'Donell
2017-09-18 14:28 ` Pedro Alves
2017-07-01 14:35 ` [RFC PATCH 0/3] Pretty-printing for errno Siddhesh Poyarekar
2017-07-04 15:54 ` Pedro Alves
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=1505330791.1896.10.camel@skynet.be \
--to=philippe.waroquiers@skynet.be \
--cc=gdb@sourceware.org \
--cc=libc-alpha@sourceware.org \
--cc=palves@redhat.com \
--cc=zackw@panix.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