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

"Maciej W. Rozycki" <[email protected]>
Newsgroups gmane.linux.ports.alpha,gmane.linux.kernel,gmane.linux.kbuild.devel
Message-ID <[email protected]>
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 <[email protected]>

  Maciej
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.