Re: GCC 15 -fzero-init-padding-bits= option and redzone clobber

Linus Torvalds <[email protected]>
Newsgroups org.kernel.vger.linux-toolchains
Message-ID <CAHk-=whf8Brp6+XmfRoAjeXukX_mc7wu2Q_izyTKV0YY6yuMag@mail.gmail.com>
On Fri, 29 Nov 2024 at 05:23, Jakub Jelinek <[email protected]> wrote:
>
> On Fri, Nov 29, 2024 at 01:52:38PM +0100, Peter Zijlstra wrote:
> > register unsigned long current_stack_pointer asm(_ASM_SP);
> > #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
> >
> > which we use a *LOT*.
>
> And wrongly so.  Inline asm really can't change the stack pointer (with the
> meaning that rsp would be different between the entry to the inline asm and
> its exit(s) (multiple for asm goto).  So telling the compiler it does change
> is wrong.

The value of %rsp doesn't change in the end, but we do read and write
it, because that's what a "call" instruction does.

So see that ASM_CALL_CONSTRAINT as us just telling the compiler that
we *use* rsp, because otherwise we've had issues with the compiler
inserting the inline asm before the frame pointer is set up, which
breaks all the usual tracing etc stuff. You can't do function calls
without a properly set up frame.

This has happened with both gcc and clang, and telling the compiler
that we need the stack pointer fixes it. I don't actually remember who
told us to do that, but I think it was a gcc person.

In fact, if I were a betting man, I would have thought it was you ;)

The comment above the ASM_CALL_CONSTRAINT definition actually explains it:

 * This output constraint should be used for any inline asm which has a "call"
 * instruction.  Otherwise the asm may be inserted before the frame pointer
 * gets set up by the containing function.  If you forget to do this, objtool
 * may print a "call without frame pointer save/setup" warning.

but we're open to other ways to tell the compiler that "we need the
stack pointer to be set up".

             Linus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.