mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] [PATCH v2] add qsort_r.
Date: Mon, 15 Mar 2021 22:18:08 -0400	[thread overview]
Message-ID: <20210316021807.GI32655@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2103160242430.17743@monopod.intra.ispras.ru>

On Tue, Mar 16, 2021 at 02:49:59AM +0300, Alexander Monakov wrote:
> On Tue, 9 Mar 2021, Rich Felker wrote:
> 
> > I tested sh4, sh2/fdpic, rv64, s390x, or1k, m68k, and mips (32-bit)
> > and they all do the tail call properly. But mips64 (n64 and n32) both
> > fail to. According to the GCC source, it's some thing to allow lazy
> > binding. MIPS64 does not use a real PLT, but actually has GOT entries
> > that might go through a lazy resolver and that expect %gp (call-saved)
> > to be valid on entry.
> 
> I think you botched something in your MIPS64 testing, probably making
> a direct call instead of an indirect call. An indirect call should not
> go to a lazy resolver (because then if you take the address once and
> reuse it many times, you risk entering the resolver multiple times).

No, it's even stupider. Somehow when I deleted the $TARGET-gcc to
replace with mips64-*-gcc I also deleted the -O2 right after it, so I
was looking at -O0...

> Here's a Compiler Explorer link demonstrating that indirect call
> compiles to a simple jump on MIPS64: https://godbolt.org/z/vroTs9

Yes, confirmed that now. However direct call indeed does not tail-call.

> > musl does not, and will never, do lazy binding, so this is purely
> > counterproductive for musl and we should probably teach GCC not to do
> > it. The current logic is:
> > 
> >   /* Sibling calls should not prevent lazy binding.  Lazy-binding stubs
> >      require $gp to be valid on entry, so sibcalls can only use stubs
> >      if $gp is call-clobbered.  */
> >   if (decl
> 
> decl will be NULL for an indirect call

*nod* ...

> 
> >       && TARGET_CALL_SAVED_GP
> >       && !TARGET_ABICALLS_PIC0
> >       && !targetm.binds_local_p (decl))
> >     return false;
> > 
> > TARGET_CALL_SAVED_GP is rightly true (it's the ABI).
> > 
> > TARGET_ABICALLS_PIC0 is rightly false (I'm pretty sure that's a bogus
> > alt ABI, and defined as TARGET_ABSOLUTE_ABICALLS && TARGET_PLT).
> > 
> > It probably needs an addition condition && TARGET_LAZY_BINDING that we
> > can define as false. Alternatively the issue could just be fixed not
> > to go through lazy resolver anywhere.
> > 
> > I opened a bug for it here:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99491

...but this bug is still valid, as it's undesirable for this to happen
with direct calls too.

Rich

      reply	other threads:[~2021-03-16  2:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09  3:56 Érico Nogueira
2021-03-09  9:11 ` Alexander Monakov
2021-03-09 13:42   ` Rich Felker
2021-03-09 14:13     ` Alexander Monakov
2021-03-09 15:03       ` Rich Felker
2021-03-09 16:54         ` Markus Wichmann
2021-03-09 18:04           ` Rich Felker
2021-03-15 23:49             ` Alexander Monakov
2021-03-16  2:18               ` Rich Felker [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=20210316021807.GI32655@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).