From: Jonathan Wakely <jwakely@redhat.com>
To: Alexandre Oliva <oliva@adacore.com>
Cc: Jonathan Wakely <jwakely.gcc@gmail.com>,
gcc-patches <gcc-patches@gcc.gnu.org>,
"libstdc++" <libstdc++@gcc.gnu.org>,
Bernd Edlinger <bernd.edlinger@hotmail.de>
Subject: Re: [libstdc++] Use __gthread_join in jthread/95989
Date: Fri, 3 Mar 2023 18:12:53 +0000 [thread overview]
Message-ID: <CACb0b4=zWKsyf3=fK0gOem7vK1qKZNwyx61ActfpJ695xhZVoA@mail.gmail.com> (raw)
In-Reply-To: <orsfeliv75.fsf@lxoliva.fsfla.org>
[-- Attachment #1: Type: text/plain, Size: 1948 bytes --]
On Fri, 3 Mar 2023 at 17:47, Alexandre Oliva <oliva@adacore.com> wrote:
> On Mar 3, 2023, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> > On Fri, 3 Mar 2023 at 09:33, Jonathan Wakely <jwakely@redhat.com> wrote:
> >> Jakub previously suggested doing this for PR 61841, which was a similar
> >> problem with pthread_create:
> >>
> >> __asm ("" : : "r" (&pthread_create)); would not be optimized away.
> >>
> >>
> >> That would avoid the multiple copies.
>
> Not really. There would be multiple copies of the code that loads
> pthread_create's address. And we don't really need the address, a
> single never-executed call would do. I've explored these possibilities
> a bit, and here's what I've come up with: a private static member
> function that we output in units that instantiate the thread template
> ctor, to pass its address to _M_start_thread. Since it's never actually
> called, we don't really need the hacks in some of the alternatives I
> left in place, mainly for your enjoyment.
>
> They all work equally well, just as efficient per-instantiation at
> runtime, a little different space and loading overheads, but the last
> one, that is enabled, is my favorite: only PLT relocations, that we'd
> likely get anyway, no full-address resolution, and as-short-as-possible
> calls, enough to get a relocation with a strong reference to pull the
> symbol in when linking, but as short as possible call sequences, because
> of the type cast.
>
And those expressions aren't ever optimized away as unused?
>
> As a bonus, I put in (in the last minute, after my test runs) something
> to keep even LTO happy: the asm statements to prevent depend from being
> optimized out in _M_start_thread. In non-LTO, its impact should be
> virtually zero.
>
> How does this look? (minus the #if 0/#elif 0/.../#else)
>
Looks good, thanks for going the extra mile to check all the alternatives,
and the futureproofing it for LTO.
OK for trunk.
next prev parent reply other threads:[~2023-03-03 18:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 6:39 Alexandre Oliva
2023-02-17 10:58 ` Jonathan Wakely
2023-03-03 8:18 ` Alexandre Oliva
2023-03-03 9:33 ` Jonathan Wakely
2023-03-03 9:48 ` Jonathan Wakely
2023-03-03 17:46 ` Alexandre Oliva
2023-03-03 18:12 ` Jonathan Wakely [this message]
2023-03-03 18:14 ` Jonathan Wakely
2023-03-03 19:55 ` Alexandre Oliva
2023-03-03 20:15 ` Florian Weimer
2023-03-03 20:36 ` Alexandre Oliva
2023-03-03 20:57 ` Alexandre Oliva
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='CACb0b4=zWKsyf3=fK0gOem7vK1qKZNwyx61ActfpJ695xhZVoA@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=bernd.edlinger@hotmail.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--cc=libstdc++@gcc.gnu.org \
--cc=oliva@adacore.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).