* [PATCH 0/2] alpha: enable building with clang
@ 2026-08-03 17:08 Matt Turner
2026-08-03 17:08 ` [PATCH 1/2] " Matt Turner
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Matt Turner @ 2026-08-03 17:08 UTC (permalink / raw)
To: Richard Henderson, Matt Turner, Magnus Lindholm,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Nicolas Schier
Cc: linux-alpha, linux-kernel, llvm, linux-kbuild
Two small patches to let the alpha kernel build with clang.
The first registers the clang target triple and stops passing -Wa,-mev6
when the compiler is not gcc. That flag exists to keep gas from emulating
instructions it believes the target lacks; it is a gas-only option and
clang's integrated assembler does not emulate instructions, so it is not
needed there.
The second fixes two uses of local register-asm variables that clang does
not honor. clang treats `register unsigned long x __asm__("$N")` as the
named register only where the variable appears as an inline-asm operand,
so reading one to get the live $gp or $sp yields an undefined value.
trap_init() passed that to PAL_wrkgp and load_PCB() stored it into the
PCB for swpctx, either of which wedges an early boot.
Note that the alpha backend is not in upstream LLVM. It lives in
https://github.com/alphalinux-org/llvm-project
and is a work in progress, so the scripts/Makefile.clang entry has no
effect with an upstream clang today. I am sending this now because the
second patch is a real bug in its own right -- the register-asm reads are
only guaranteed to work by gcc's implementation, not by anything either
compiler documents -- but I understand if the kbuild side would rather
wait for the backend to land upstream.
---
Matt Turner (2):
alpha: enable building with clang
alpha: read $gp and $sp explicitly for clang
arch/alpha/Makefile | 8 +++++++-
arch/alpha/kernel/traps.c | 4 +++-
arch/alpha/mm/init.c | 3 +--
scripts/Makefile.clang | 1 +
4 files changed, 12 insertions(+), 4 deletions(-)
---
base-commit: 0e6be1d34ae92e2b0dbc1b7410d422b22464389a
change-id: 20260803-alpha-clang-6acd144eb86c
Best regards,
--
Matt Turner <mattst88@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] alpha: enable building with clang
2026-08-03 17:08 [PATCH 0/2] alpha: enable building with clang Matt Turner
@ 2026-08-03 17:08 ` Matt Turner
2026-08-03 20:56 ` Magnus Lindholm
2026-08-03 17:08 ` [PATCH 2/2] alpha: read $gp and $sp explicitly for clang Matt Turner
2026-08-03 19:51 ` [PATCH 0/2] alpha: enable building with clang Nathan Chancellor
2 siblings, 1 reply; 6+ messages in thread
From: Matt Turner @ 2026-08-03 17:08 UTC (permalink / raw)
To: Richard Henderson, Matt Turner, Magnus Lindholm,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Nicolas Schier
Cc: linux-alpha, linux-kernel, llvm, linux-kbuild
Register the clang target triple for alpha, and pass -Wa,-mev6 only when
building with gcc. That flag exists to stop gas emulating instructions
the assembler thinks the target lacks; it is a gas-only option, and
clang's integrated assembler does not emulate instructions in the first
place, so nothing is needed there.
With this, LLVM=1 (and LLVM_IAS=1) builds work. Note that the alpha
backend is not in upstream LLVM yet; it lives in
https://github.com/alphalinux-org/llvm-project
and is a work in progress.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/alpha/Makefile | 8 +++++++-
scripts/Makefile.clang | 1 +
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/alpha/Makefile b/arch/alpha/Makefile
index 35445ff2e489..54283705911f 100644
--- a/arch/alpha/Makefile
+++ b/arch/alpha/Makefile
@@ -27,10 +27,16 @@ cpuflags-$(CONFIG_ALPHA_GENERIC) := -mcpu=ev56 -mtune=ev6
cflags-y += $(cpuflags-y)
+KBUILD_CFLAGS += $(cflags-y)
+
# For TSUNAMI, we must have the assembler not emulate our instructions.
# The same is true for IRONGATE, POLARIS, PYXIS.
# BWX is most important, but we don't really want any emulation ever.
-KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6
+# Only gas emulates instructions the target does not implement, and only gas
+# understands -mev6; clang's integrated assembler never emulates.
+ifdef CONFIG_CC_IS_GCC
+KBUILD_CFLAGS += -Wa,-mev6
+endif
libs-y += arch/alpha/lib/
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang
index b67636b28c35..2434cf90ad7e 100644
--- a/scripts/Makefile.clang
+++ b/scripts/Makefile.clang
@@ -1,6 +1,7 @@
# Individual arch/{arch}/Makefiles should use -EL/-EB to set intended
# endianness and -m32/-m64 to set word size based on Kconfigs instead of
# relying on the target triple.
+CLANG_TARGET_FLAGS_alpha := alpha-linux-gnu
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
2026-08-03 17:08 [PATCH 0/2] alpha: enable building with clang Matt Turner
2026-08-03 17:08 ` [PATCH 1/2] " Matt Turner
@ 2026-08-03 17:08 ` Matt Turner
2026-08-03 21:15 ` Magnus Lindholm
2026-08-03 19:51 ` [PATCH 0/2] alpha: enable building with clang Nathan Chancellor
2 siblings, 1 reply; 6+ messages in thread
From: Matt Turner @ 2026-08-03 17:08 UTC (permalink / raw)
To: Richard Henderson, Matt Turner, Magnus Lindholm,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Nicolas Schier
Cc: linux-alpha, linux-kernel, llvm, linux-kbuild
clang honors a local `register unsigned long x __asm__("$N")` variable
only where it appears as an inline-asm operand; merely reading it does
not produce the contents of that register. So trap_init() passed an
undefined global pointer to PAL_wrkgp, and load_PCB() stored an undefined
stack pointer into the PCB that swpctx then loaded. Either one wedges an
early boot.
Read the registers explicitly instead: an inline mov for $gp in
trap_init(), and the file-scope current_stack_pointer for $sp in
load_PCB(). A file-scope register-asm variable is the form clang does
support.
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
arch/alpha/kernel/traps.c | 4 +++-
arch/alpha/mm/init.c | 3 +--
2 files changed, 4 insertions(+), 3 deletions(-)
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);
diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
index 9531cbc761c0..f4d65a60c869 100644
--- a/arch/alpha/mm/init.c
+++ b/arch/alpha/mm/init.c
@@ -63,8 +63,7 @@ pgd_alloc(struct mm_struct *mm)
static inline unsigned long
load_PCB(struct pcb_struct *pcb)
{
- register unsigned long sp __asm__("$30");
- pcb->ksp = sp;
+ pcb->ksp = (unsigned long)current_stack_pointer;
return __reload_thread(pcb);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] alpha: enable building with clang
2026-08-03 17:08 [PATCH 0/2] alpha: enable building with clang Matt Turner
2026-08-03 17:08 ` [PATCH 1/2] " Matt Turner
2026-08-03 17:08 ` [PATCH 2/2] alpha: read $gp and $sp explicitly for clang Matt Turner
@ 2026-08-03 19:51 ` Nathan Chancellor
2 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2026-08-03 19:51 UTC (permalink / raw)
To: Matt Turner
Cc: Richard Henderson, Magnus Lindholm, Nick Desaulniers,
Bill Wendling, Justin Stitt, Nicolas Schier, linux-alpha,
linux-kernel, llvm, linux-kbuild
Hi Matt,
On Mon, Aug 03, 2026 at 01:08:40PM -0400, Matt Turner wrote:
> Two small patches to let the alpha kernel build with clang.
Nice!
> The first registers the clang target triple and stops passing -Wa,-mev6
> when the compiler is not gcc. That flag exists to keep gas from emulating
> instructions it believes the target lacks; it is a gas-only option and
> clang's integrated assembler does not emulate instructions, so it is not
> needed there.
>
> The second fixes two uses of local register-asm variables that clang does
> not honor. clang treats `register unsigned long x __asm__("$N")` as the
> named register only where the variable appears as an inline-asm operand,
> so reading one to get the live $gp or $sp yields an undefined value.
> trap_init() passed that to PAL_wrkgp and load_PCB() stored it into the
> PCB for swpctx, either of which wedges an early boot.
>
> Note that the alpha backend is not in upstream LLVM. It lives in
>
> https://github.com/alphalinux-org/llvm-project
>
> and is a work in progress, so the scripts/Makefile.clang entry has no
> effect with an upstream clang today. I am sending this now because the
> second patch is a real bug in its own right -- the register-asm reads are
> only guaranteed to work by gcc's implementation, not by anything either
> compiler documents -- but I understand if the kbuild side would rather
> wait for the backend to land upstream.
Yeah, I am not sure how I feel taking the target triple part of the
first patch. On the one hand, I want it to be easy for you to test
against upstream Linux but on the other, I do not want people to read
this Makefile and assume that ARCH=alpha will work with an upstream
clang.
We could add a comment that the backend is currently out of tree but
that would go stale once it is actually upstream and it will be floating
around for forever. Maybe a better compromise is taking arch/alpha
changes now then landing the scripts/Makefile.clang change when you
actually start upstreaming the backend, as being able to use an upstream
version of clang should be relatively imminent at that point.
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] alpha: enable building with clang
2026-08-03 17:08 ` [PATCH 1/2] " Matt Turner
@ 2026-08-03 20:56 ` Magnus Lindholm
0 siblings, 0 replies; 6+ messages in thread
From: Magnus Lindholm @ 2026-08-03 20:56 UTC (permalink / raw)
To: Matt Turner
Cc: Richard Henderson, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Nicolas Schier, linux-alpha,
linux-kernel, llvm, linux-kbuild
On Mon, Aug 3, 2026 at 7:08 PM Matt Turner <mattst88@gmail.com> wrote:
>
> Register the clang target triple for alpha, and pass -Wa,-mev6 only when
> building with gcc. That flag exists to stop gas emulating instructions
> the assembler thinks the target lacks; it is a gas-only option, and
> clang's integrated assembler does not emulate instructions in the first
> place, so nothing is needed there.
>
> With this, LLVM=1 (and LLVM_IAS=1) builds work. Note that the alpha
> backend is not in upstream LLVM yet; it lives in
>
> https://github.com/alphalinux-org/llvm-project
>
> and is a work in progress.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
> arch/alpha/Makefile | 8 +++++++-
> scripts/Makefile.clang | 1 +
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/Makefile b/arch/alpha/Makefile
> index 35445ff2e489..54283705911f 100644
> --- a/arch/alpha/Makefile
> +++ b/arch/alpha/Makefile
> @@ -27,10 +27,16 @@ cpuflags-$(CONFIG_ALPHA_GENERIC) := -mcpu=ev56 -mtune=ev6
> cflags-y += $(cpuflags-y)
>
>
> +KBUILD_CFLAGS += $(cflags-y)
> +
> # For TSUNAMI, we must have the assembler not emulate our instructions.
> # The same is true for IRONGATE, POLARIS, PYXIS.
> # BWX is most important, but we don't really want any emulation ever.
> -KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6
> +# Only gas emulates instructions the target does not implement, and only gas
> +# understands -mev6; clang's integrated assembler never emulates.
> +ifdef CONFIG_CC_IS_GCC
> +KBUILD_CFLAGS += -Wa,-mev6
> +endif
>
> libs-y += arch/alpha/lib/
>
Hi Matt,
I agree with Nathan's suggestion to leave the
CLANG_TARGET_FLAGS_alpha entry out for now and add it separately when
the Alpha backend is being upstreamed to LLVM.
Could you send a v2 containing just the arch/alpha/Makefile change?
Since -Wa,-mev6 is an assembler-specific option, I think maybe the condition
should also test the assembler rather than the compiler?
ifdef CONFIG_AS_IS_GNU
KBUILD_CFLAGS += -Wa,-mev6
endif
That preserves the option for both GCC and clang builds using GNU as,
including clang with LLVM_IAS=0, while omitting it for LLVM's integrated
assembler.
The revised Alpha Makefile patch can then go through the Alpha tree,
while the scripts/Makefile.clang change can wait until the backend is
available upstream.
Thanks,
Magnus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
2026-08-03 17:08 ` [PATCH 2/2] alpha: read $gp and $sp explicitly for clang Matt Turner
@ 2026-08-03 21:15 ` Magnus Lindholm
0 siblings, 0 replies; 6+ messages in thread
From: Magnus Lindholm @ 2026-08-03 21:15 UTC (permalink / raw)
To: Matt Turner
Cc: Richard Henderson, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Nicolas Schier, linux-alpha,
linux-kernel, llvm, linux-kbuild
Hi Matt,
On Mon, Aug 3, 2026 at 7:08 PM Matt Turner <mattst88@gmail.com> wrote:
>
> clang honors a local `register unsigned long x __asm__("$N")` variable
> only where it appears as an inline-asm operand; merely reading it does
> not produce the contents of that register. So trap_init() passed an
> undefined global pointer to PAL_wrkgp, and load_PCB() stored an undefined
> stack pointer into the PCB that swpctx then loaded. Either one wedges an
> early boot.
>
> Read the registers explicitly instead: an inline mov for $gp in
> trap_init(), and the file-scope current_stack_pointer for $sp in
> load_PCB(). A file-scope register-asm variable is the form clang does
> support.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
> arch/alpha/kernel/traps.c | 4 +++-
> arch/alpha/mm/init.c | 3 +--
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> 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);
> diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
> index 9531cbc761c0..f4d65a60c869 100644
> --- a/arch/alpha/mm/init.c
> +++ b/arch/alpha/mm/init.c
> @@ -63,8 +63,7 @@ pgd_alloc(struct mm_struct *mm)
> static inline unsigned long
> load_PCB(struct pcb_struct *pcb)
> {
> - register unsigned long sp __asm__("$30");
> - pcb->ksp = sp;
> + pcb->ksp = (unsigned long)current_stack_pointer;
> return __reload_thread(pcb);
> }
>
>
> --
> 2.54.0
>
This looks good to me. The explicit $gp read and use of
current_stack_pointer avoid relying on the unsupported local
register-asm behavior.
I also built and booted the patched kernel successfully with GCC on an
AlphaStation DS10.
Reviewed-by: Magnus Lindholm linmag7@gmail.com
Tested-by: Magnus Lindholm linmag7@gmail.com
I am happy to take this through the Alpha tree.
Thanks,
Magnus
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-03 21:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 17:08 [PATCH 0/2] alpha: enable building with clang Matt Turner
2026-08-03 17:08 ` [PATCH 1/2] " Matt Turner
2026-08-03 20:56 ` Magnus Lindholm
2026-08-03 17:08 ` [PATCH 2/2] alpha: read $gp and $sp explicitly for clang Matt Turner
2026-08-03 21:15 ` Magnus Lindholm
2026-08-03 19:51 ` [PATCH 0/2] alpha: enable building with clang Nathan Chancellor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox