public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Michael at MichaelKloos dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/112478] riscv: asm clobbers not honored
Date: Mon, 13 Nov 2023 20:22:49 +0000	[thread overview]
Message-ID: <bug-112478-4-sWa2XOyAXX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112478-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112478

Michael T. Kloos <Michael at MichaelKloos dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #5 from Michael T. Kloos <Michael at MichaelKloos dot com> ---
I disagree.  To quote you:

"You're using an ASM to implement a call.  That means your asm is responsible
for dealing with all ABI issues, including saving/restoring registers around
the call.

Essentially GCC has no visibility into what your ASM does.  It's just a text
string that gets passed through to the assembler."

Exactly.  I did handle that.  I specified all register clobbers in either the
outputs or clobber list of the asm statement.  The %ra register is specified in
the clobber list.  GCC is not honoring that clobber.  

That is a regression in GCCs behavior.  Of course, it would be possible to
write an asm statement that GCC could not work around, such as if you clobbered
every register so it could not track the stack pointer.  That is a known
limitation, will throw an error, and is not what we are talking about.  Playing
around with these ABI "special" registers inside inline asm is certainly not
unheard of.  There are many posts on the internet where such tricks are
discussed and GCC supports them.  If you are familiar with the ABI and are
designing architecture specific code, it can be a great optimization.  This
change is a regression.  It breaks any code that relies on this feature.  

Even if we conceded that clobbering the link register is not supported in GCC
asm clobber lists, which I don't, you still can't shift the blame to me because
the package that broke is not my code.  It broke libgcc, GCC's own internals. 
The sample code that I provided is just a minimal way to reproduce the bug, but
it's based on these parts of your own source code:
> include/longlong.h
> libgcc/config/riscv/muldi3.S
> libgcc/config/riscv/multi3.c

On riscv64 (The symbols get redefined on 64 vs 32 bit):
> multi3 calls __muluw3()
> __muluw3 is defined as a macro inside "include/longlong.h"
> __muluw3 becomes an asm call statement that calls __muldi3.

Beyond that, I have not attempted to further experiment with listing other
registers as asm clobbers and playing around with the edge cases of this bug. 
I don't know if the clobbers of anything else was broken.  I picked up on the
case of ra, specifically, because it broke libgcc.  

I know you don't want to take the time to work on this.  But if you are going
to dismiss someone out of hand, at least take the time to read and understand
their concerns.  I went over the libgcc breakage in my original post.

  parent reply	other threads:[~2023-11-13 20:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 15:39 [Bug c/112478] New: " Michael at MichaelKloos dot com
2023-11-10 15:49 ` [Bug target/112478] " Michael at MichaelKloos dot com
2023-11-10 16:49 ` andrew at sifive dot com
2023-11-11 17:02 ` Michael at MichaelKloos dot com
2023-11-13 19:18 ` law at gcc dot gnu.org
2023-11-13 20:22 ` Michael at MichaelKloos dot com [this message]
2023-11-14  2:10 ` kito at gcc dot gnu.org
2023-11-14 15:22 ` Michael at MichaelKloos dot com
2023-11-14 16:24 ` kito at gcc dot gnu.org
2023-11-16 11:36 ` cvs-commit at gcc dot gnu.org
2023-11-16 23:06 ` kito at gcc dot gnu.org

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=bug-112478-4-sWa2XOyAXX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).