public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Nemanja Ivanovic <nemanjai@ca.ibm.com>,
	libc-alpha@sourceware.org, Fangrui Song <maskray@google.com>
Subject: Re: [PATCH] powerpc: Define USE_PPC64_NOTOC iff compiler and linker also supports it
Date: Wed, 17 Nov 2021 12:46:08 +1030	[thread overview]
Message-ID: <YZRl6PH0Yy8ZB/Az@squeak.grove.modra.org> (raw)
In-Reply-To: <87zgq33n1k.fsf@linux.ibm.com>

On Tue, Nov 16, 2021 at 04:42:15PM -0300, Tulio Magno Quites Machado Filho wrote:
> Alan Modra via Libc-alpha <libc-alpha@sourceware.org> writes:
> 
> > I have a question about powerpc64/ppc-mcount.S.  Why is the assembly
> > wrapper using ENTRY and a NOTOC call?  By using ENTRY you are saying
> > that calls to _mcount must have r2 valid.  Given that r2 is valid, why
> > then use NOTOC?
> 
> I wouldn't be surprised if that was a misinterpretation of the ABI on my part.
> 
> Looking at table 2.20 "Protocols for Local Function Calls", I think this is a
> scenario that falls to the last row of this table, where we have:

As Bill said, the ABI does define what is meant by local.  However, it
is true that if you have enough control over the full build process
(you never do when !SHARED in glibc) and know what you're doing, you
may use a wider definition of "local".  It's something like "I know
this function linkage will be exactly the same as a static function in
the current compilation unit".  Which implies known local definition
at link time that cannot be overridden, *and* same toc group.  The
latter condition is often forgotten, and bites people using ELFv1
-mcmodel=small code when the TOC exceeds 64k.

> - Local call method
> - nop is not needed
> - Relocation is R_PPC64_REL24_NOTOC.
> 
> If this interpretation is incorrect, what is the recommended solution for this
> case? Use ENTRY_TOCLESS?

If you use ENTRY_TOCLESS you are saying that the function neither uses
nor changes r2.  This situation is not covered by table 2.19 or 2.20
in the ABI, because ENTRY_TOCLESS functions generally do not make
calls!  There is a note saying that it is not forbidden but then *you*
must ensure that the call does not change r2.  Now it might be that
__mcount_internal currently does not change r2, but that won't
necessarily hold for all future compilers.  Power10 pcrel code may use
r2 as a scratch register..

I recommend losing the NOTOC on the call.  You already have the nop
after the call when !SHARED, which is correct and necessary for a
normal call.  You also likely have enough control over SHARED builds
to omit the nop in that case.

Note that having a localentry:8 _mcount is not ideal if someone wants
to build -mcpu=power10 glibc, but _mcount is quite a way down on the
priority list of removing localentry:8 functions for -mcpu=power10.

-- 
Alan Modra
Australia Development Lab, IBM

  parent reply	other threads:[~2021-11-17  2:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 11:33 Adhemerval Zanella
2021-11-08 22:48 ` Fangrui Song
2021-11-09 11:05   ` Alan Modra
2021-11-16 19:42     ` Tulio Magno Quites Machado Filho
2021-11-16 20:20       ` Tulio Magno Quites Machado Filho
2021-11-16 20:48         ` Florian Weimer
2021-11-16 22:12           ` Fāng-ruì Sòng
2021-11-16 22:46           ` Bill Schmidt
2021-11-17  2:16       ` Alan Modra [this message]
2021-11-17  2:30         ` Alan Modra
2021-11-09 13:03   ` Adhemerval Zanella
2021-11-09 17:44     ` Fangrui Song
2021-11-09 18:44       ` Adhemerval Zanella
2021-11-19 15:52 ` Tulio Magno Quites Machado Filho
2021-11-22 17:54   ` Adhemerval Zanella
2021-11-25 17:02     ` Tulio Magno Quites Machado Filho
2021-11-25 17:16       ` Adhemerval Zanella

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=YZRl6PH0Yy8ZB/Az@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    --cc=nemanjai@ca.ibm.com \
    --cc=tuliom@linux.ibm.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).