Re: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang

From: Matt Turner

Date: Tue Aug 11 2026 - 14:03:52 EST


On Tue, Aug 11, 2026 at 1:55 PM Magnus Lindholm <linmag7@xxxxxxxxx> wrote:
>
> On Tue, Aug 11, 2026 at 1:10 PM Maciej W. Rozycki <macro@xxxxxxxxxxx> wrote:
> >
> > On Mon, 3 Aug 2026, Magnus Lindholm wrote:
> >
> > > > diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> > > > index 7631129ac914..5b4f1ae2b74b 100644
> > > > --- a/arch/alpha/kernel/traps.c
> > > > +++ b/arch/alpha/kernel/traps.c
> > > > @@ -925,7 +925,9 @@ void
> > > > trap_init(void)
> > > > {
> > > > /* Tell PAL-code what global pointer we want in the kernel. */
> > > > - register unsigned long gptr __asm__("$29");
> > > > + unsigned long gptr;
> > > > +
> > > > + __asm__ volatile("mov $29, %0" : "=r"(gptr));
> > > > wrkgp(gptr);
> > > >
> > > > wrent(entArith, 1);
> > >
> > > This looks good to me. The explicit $gp read and use of
> > > current_stack_pointer avoid relying on the unsupported local
> > > register-asm behavior.
> >
> > It could have been worth mentioning in the change description that no
> > code quality regression results here with GCC:
> >
> > --- arch/alpha/kernel/traps-0.dump 2026-08-11 11:57:59.895247441 +0100
> > +++ arch/alpha/kernel/traps-1.dump 2026-08-11 11:56:31.788713285 +0100
> > @@ -2223,8 +2223,8 @@
> > 1b70: GPDISP .text+0x4
> > 1b74: 00 00 bd 23 lda gp,0(gp)
> > 1b78: f0 ff de 23 lda sp,-16(sp)
> > - 1b7c: 10 04 fd 47 mov gp,a0
> > - 1b80: 00 00 5e b7 stq ra,0(sp)
> > + 1b7c: 00 00 5e b7 stq ra,0(sp)
> > + 1b80: 10 04 fd 47 mov gp,a0
> > 1b84: 37 00 00 00 call_pal 0x37
> > 1b88: 04 00 00 c2 br a0,1b9c <trap_init+0x2c>
> > 1b8c: 08 00 1e a6 ldq a0,8(sp)
> >
> > Also I think our coding style would rather see the asm written as:
> >
> > __asm__ __volatile__("mov $29, %0" : "=r" (gptr));
> >
> > Otherwise:
> >
> > Reviewed-by: Maciej W. Rozycki <macro@xxxxxxxxxxx>
> >
> > Maciej
>
> Hi Matt,
>
> Given Maciej's comment on the inline asm style, do you want to send a v2
> of this patch, or are you happy for me to fold the
>
> __asm__ volatile(...)
>
> to
>
> __asm__ __volatile__(...)
>
> style change in when I apply it to the Alpha tree?
>
> Either is fine with me.
>
> Thanks,
> Magnus

Hey Magnus,

Feel free to just fix it up when you apply it.

Thanks,
Matt