public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: "Fāng-ruì Sòng" <maskray@google.com>
Cc: libc-alpha@sourceware.org,
	"Adhemerval Zanella" <adhemerval.zanella@linaro.org>,
	"GCC Patches" <gcc-patches@gcc.gnu.org>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	"Marco Elver" <elver@google.com>, "Martin Liška" <mliska@suse.cz>,
	"Jakub Jelinek" <jakub@redhat.com>
Subject: Re: [PATCH] elf: Add __libc_get_static_tls_bounds [BZ #16291]
Date: Tue, 21 Dec 2021 07:08:33 +0100	[thread overview]
Message-ID: <87h7b2cwwu.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAFP8O3J-jetAXtdWbMp3WEhOW8WOwf1429-upqfhhjMo2TKM8A@mail.gmail.com> (=?utf-8?B?IkbEgW5nLXJ1w6wgU8OybmciJ3M=?= message of "Mon, 20 Dec 2021 18:55:25 -0800")

* Fāng-ruì Sòng:

>> I *think* you can get what you need via existing GLIBC_PRIVATE
>> interfaces.  But in order to describe how to caox the data out of glibc,
>> I need to know what you need.
>
> Unfortunate no, not reliably. Currently _dl_get_tls_static_info
> (https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L207)
> is used. It has the size information but not the start address, so the
> sanitizer runtime is doing very ugly/error-prone probing of the start
> address by reading the thread pointer and hard coding the `struct
> pthread` size for various glibc versions.
> Every time `struct pthreads` increases in glibc, sanitizer runtime has to adapt.
>
> __libc_get_static_tls_bounds if supported by glibc, can replace
> _dl_get_tls_static_info and the existing glibc specific GetTls hacks,
> and provide a bit more compatibility when glibc struct pthreads
> increases.

We already export the size of struct pthread, though, as a GLIBC_PRIVATE
symbol.

  const unsigned int *psize = dlvsym("_thread_db_sizeof_pthread",
                                     "GLIBC_PRIVATE");
  if (psize != nullptr) {
    val = *psize;
    atomic_store_relaxed(&thread_descriptor_size, val);
    return val;
  }

in ThreadDescriptorSize() in
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp should work
with any further glibc changes today.  It definitely beats hard-coding
the architecture-specific struct pthread size.

Using _thread_db_sizeof_pthread does not remove all magic constants from
the code, and there is of course the _dl_get_tls_static_info symbol
usage.

This is a fairly recent change (glibc 2.34, I believe) that was
introduced to improve thread debugging without debuginfo present in the
glibc objects (which is why it's a GLIBC_PRIVATE symbol).  libthread_db
is bundled with glibc, so the _thread_db_* symbols are not gurantueed to
be stable, but there are no immediate plans to change this interface.

Thanks,
Florian


  reply	other threads:[~2021-12-21  6:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-25  0:42 Fangrui Song
2021-09-27 13:02 ` Florian Weimer
2021-09-27 17:59   ` Fangrui Song
2021-10-06 20:23     ` Fangrui Song
2021-10-15  0:13       ` Fangrui Song
2021-10-19 19:37         ` Fāng-ruì Sòng
2021-10-28  5:16           ` Fāng-ruì Sòng
2021-11-29 19:30             ` Florian Weimer
2021-12-21  2:55               ` Fāng-ruì Sòng
2021-12-21  6:08                 ` Florian Weimer [this message]
2021-09-27 17:38 ` Joseph Myers
2021-09-27 17:47   ` Florian Weimer

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=87h7b2cwwu.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    --cc=mliska@suse.cz \
    /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).