From: Segher Boessenkool <segher@kernel.crashing.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jakub Jelinek <jakub@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
linux-toolchains@vger.kernel.org, x86@kernel.org
Subject: Re: GCC 15 -fzero-init-padding-bits= option and redzone clobber
Date: Sat, 30 Nov 2024 16:19:40 -0600 [thread overview]
Message-ID: <20241130221940.GS29862@gate.crashing.org> (raw)
In-Reply-To: <CAHk-=whJvN-pNfze=iher7nf1gkbA3DJ6+tPdCvVQVdBsdQEZQ@mail.gmail.com>
Hi!
On Sat, Nov 30, 2024 at 09:43:53AM -0800, Linus Torvalds wrote:
> On Sat, 30 Nov 2024 at 03:13, Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> >
> > But of course, GCC assumes there is a properly set up stack
> > *everywhere*, it can in principle insert calls *anywhere*. So these
> > asm constraints are totally superfluous anyway!
>
> Well, I wish that were true. But we used your trick for a reason: it
> fixed a real and present issue.
>
> So no. It's not superfluous. It's required.
It expresses a fact that is true always anyway. But it is required
to get a *side effect*. "It is a hack", if you want.
(And "is true always" means "is a requirement on any program", of course
a user can blatantly violate those rules by writing incorrect programs).
> Without that "add sp register as a a input/output reg", at least some
> versions of gcc did in fact put inline asm in places where the frame
> was not set up.
Yes. And that was not a bug, either: nothing expressed that there has
to be a frame set up for this asm to work, so GCC felt free to make more
optimal code (or what it thought was more optimal code, or potentially
anyway; "could be more optimal code").
> You seem to imply that that may be a gcc bug, of course. Par for the
> course - we have had other odd things in inline asms (or around them)
> for other gcc bugs.
Nope, it is not a GCC bug when users expect things that were not
promised to them.
> We do have commentary in some of our commits to that "it's a gcc bug"
> effect, ie this commit message from "only" seven years ago states:
>
> With GCC 7.2, however, GCC's behavior has changed. It now changes its
> behavior based on the conversion of the register variable to a global.
> That somehow convinces it to *always* set up the frame pointer before
> inserting *any* inline asm. (Therefore, listing the variable as an
> output constraint is a no-op and is no longer necessary.)
I have absolutely no idea what "conversion of the register variable to
a global" would mean, so I cannot parse what this sentence is meant to
mean.
There are two kinds of register variable: global register variables, and
local register variables. Global register variables are declared at
global scope, and local register variables are declared within a
function. There obviously is no way the compiler could decide to make a
local register variable a global one (that would change semantics!), so
it probably means something else, but I have no idea what.
> So if it makes you feel any better, the trick now works for a
> _different_reason_. Just the existence of the global register variable
> seems to matter to those newer versions of gcc.
Yeah, and I don't see now. If there was a full testcase I could take a
look :-)
> But we technically still support those older gcc versions that require
> the old format (we still support back to gcc-5.1, although IO think
> we're about to make the jump up to 8.1 based on staid enterprise
> distro people finally having left some of the ancient stuff behind).
Why 8.1? 8.5 was a bugfix release (in general, always require the
latest version in a release series, or recommend it at least: we cannot
fix any bug in older releases, but we can do new releases :-) )
> So we *may* be able to remove this hack, if gcc people can actually
> pinky promise that it's not required with anything newer than 8.1
The problem is still not completely clear to me. Maybe some other GCC
people will do such a promise, but at least I won't. Sorry.
Segher
next prev parent reply other threads:[~2024-11-30 22:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 11:19 GCC 15 -fzero-init-padding-bits= option and redzone clobber Jakub Jelinek
2024-11-29 12:52 ` Peter Zijlstra
2024-11-29 13:23 ` Jakub Jelinek
2024-11-29 17:55 ` Linus Torvalds
2024-11-29 18:21 ` Linus Torvalds
2024-11-30 11:10 ` Segher Boessenkool
2024-11-30 17:43 ` Linus Torvalds
2024-11-30 22:19 ` Segher Boessenkool [this message]
2024-11-30 22:43 ` Linus Torvalds
2024-11-30 22:45 ` Linus Torvalds
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=20241130221940.GS29862@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=jakub@redhat.com \
--cc=linux-toolchains@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.