public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Nicholas Piggin <npiggin@gmail.com>,
	 linuxppc-dev@lists.ozlabs.org,
	 Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>,
	 libc-alpha@sourceware.org
Subject: Re: powerpc Linux scv support and scv system call ABI proposal
Date: Thu, 30 Jan 2020 11:03:00 -0000	[thread overview]
Message-ID: <87k1595iok.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <20200129175104.GO22482@gate.crashing.org> (Segher Boessenkool's message of "Wed, 29 Jan 2020 11:51:04 -0600")

* Segher Boessenkool:

> On Wed, Jan 29, 2020 at 06:02:34PM +0100, Florian Weimer wrote:
>> * Segher Boessenkool:
>> 
>> > On Wed, Jan 29, 2020 at 05:19:19PM +0100, Florian Weimer wrote:
>> >> * Segher Boessenkool:
>> >> >> But GCC doesn't expose them as integers to C code, so you can't do much
>> >> >> without them.
>> >> >
>> >> > Sure, it doesn't expose any other registers directly, either.
>> >> 
>> >> I can use r0 & 1 with a register variable r0 to check a bit.
>> >
>> > That is not reliable, or supported, and it *will* break.  This is
>> > explicit for local register asm, and global register asm is
>> > underdefined.
>> 
>> Ugh.  I did not know that.  And neither did the person who wrote
>> powerpc64/sysdep.h because it uses register variables in regular C
>> expressions. 8-(  Other architectures are affected as well.
>
> Where?  I don't see any?  Ah, the other one, heh (there are two).
>
> No, that *is* supported: as input to or output from an asm, a local
> register asm variable *is* guaranteed to live in the specified register.
> This is the *only* supported use.  Other uses may sometimes still work,
> but they never worked reliably, and it cannot be made reliable; it has
> been documented as not supported since ages, and it will not work at all
> anymore some day.

I must say I find this situation *very* confusing.

You said that r0 & 1 is undefined.  I *assumed* that I would still get
the value of r0 (the register) from the associated extended asm in this
expression, even if it may now be a different register.  Your comment
made me think that this is undefined.  But then the syscall wrappers use
this construct:

    __asm__ __volatile__						\
      ("sc\n\t"								\
       "mfcr  %0\n\t"							\
       "0:"								\
       : "=&r" (r0),							\
         "=&r" (r3), "=&r" (r4), "=&r" (r5),				\
         "=&r" (r6), "=&r" (r7), "=&r" (r8)				\
       : ASM_INPUT_##nr							\
       : "r9", "r10", "r11", "r12",					\
         "cr0", "ctr", "memory");					\
	  err = r0;  \
    r3;  \

That lone r3 at the end would be equally undefined because it is not
used in an input or output operand of an extended asm statement.

The GCC documentation has this warning:

|  _Warning:_ In the above example, be aware that a register (for
| example 'r0') can be call-clobbered by subsequent code, including
| function calls and library calls for arithmetic operators on other
| variables (for example the initialization of 'p2').

On POWER, the LOADARGS macros attempt to deal with this by using
non-register temporaries.  However, I don't know how effective this is
if the compiler really doesn't deal with call-clobbered registers
properly.

For the extended asm use case (to express register assignments that
cannot be listed in constraints), I would expect that these variables
retain their values according to the C specification (so they are never
clobbered by calls), but that they only reside in their designated
registers when used as input or output operands in extended asm
statements.

However, this is incompatible with other (ab)uses of local and global
register variables, which may well expect that they are clobbered by
calls.  It looks like GCC uses the same construct for two unrelated
things.

Thanks,
Florian

  reply	other threads:[~2020-01-30 10:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28 12:56 Nicholas Piggin
2020-01-28 13:58 ` Florian Weimer
2020-01-28 15:40   ` Nicholas Piggin
2020-01-28 15:55     ` Segher Boessenkool
2020-01-28 16:19       ` Florian Weimer
2020-01-28 17:02         ` Dan Horák
2020-01-28 20:38         ` Segher Boessenkool
2020-01-29 16:30           ` Florian Weimer
2020-01-29 16:36             ` Segher Boessenkool
2020-01-29 17:40               ` Florian Weimer
2020-01-29 18:59                 ` Segher Boessenkool
2020-01-30 11:03                   ` Florian Weimer [this message]
2020-01-30 12:04                     ` Segher Boessenkool
2020-01-30 12:34                       ` Florian Weimer
2020-01-30 14:34                         ` Segher Boessenkool
2020-01-30 17:59                           ` Adhemerval Zanella
2020-01-30 22:05                             ` Segher Boessenkool
2020-01-31 11:33                               ` Adhemerval Zanella
2020-01-31 12:12                                 ` Segher Boessenkool
2020-01-28 16:05     ` Florian Weimer
2020-01-29 11:18       ` Nicholas Piggin
2020-01-28 16:25     ` Adhemerval Zanella
     [not found]     ` <cd9e4b28-d577-8850-7c2b-a488fcb4740d@linaro.org>
     [not found]       ` <1580273424.ea818exa2c.astroid@bobo.none>
2020-01-29 16:19         ` Tulio Magno Quites Machado Filho
2020-02-19 11:04           ` Nicholas Piggin
2020-01-28 23:18   ` Joseph Myers

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=87k1595iok.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=npiggin@gmail.com \
    --cc=segher@kernel.crashing.org \
    --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).