alpha: enable building with clang
Subsystems (3)
Matt Turner
maintainercover alpha: enable building with clang
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,
Signature · 1 line
Matt Turner <[email protected]>
Matt Turner
maintainerPATCH 1/2 alpha: enable building with clang
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.
--- arch/alpha/Makefile | 8 +++++++- scripts/Makefile.clang | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
arch/alpha/Makefile +7 -1
@@ -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/
scripts/Makefile.clang +1 -0
@@ -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
Signature · 1 line
2.54.0
Magnus Lindholm
maintainerQuoted 32 lines · Matt Turner
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 <[email protected]>--- arch/alpha/Makefile | 8 +++++++- scripts/Makefile.clang | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)arch/alpha/Makefile +2
-0@@ -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.
arch/alpha/Makefile cpuflags-$(CONFIG_ALPHA_GENERIC) := -mcpu=ev56 -mtune=ev6 · line 42
Quoted 10 lines
arch/alpha/Makefile +5
-1# 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_GNUKBUILD_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
Matt Turner
maintainerPATCH 2/2 alpha: read $gp and $sp explicitly for clang
In reply to Matt Turnerclang 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.
--- arch/alpha/kernel/traps.c | 4 +++- arch/alpha/mm/init.c | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/alpha/kernel/traps.c +3 -1
@@ -925,7 +925,9 @@ voidtrap_init (void) {/* Tell PAL-code what global pointer we want in the kernel. */ - registerunsigned long gptr __asm__("$29" ); +unsigned long gptr; + + __asm__volatile ("mov $29, %0" :"=r" (gptr));wrkgp (gptr);wrent (entArith,1 );
arch/alpha/mm/init.c +1 -2
@@ -63,8 +63,7 @@ pgd_alloc(struct mm_struct *mm)static inline unsigned long load_PCB (struct pcb_struct *pcb) { - registerunsigned long sp __asm__("$30" ); - pcb->ksp = sp; + pcb->ksp = (unsigned long )current_stack_pointer;return __reload_thread (pcb); }
Signature · 1 line
2.54.0
Re: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
Hi Matt,
Quoted 50 lines · Matt Turner
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. Sotrap_init()passed an undefined global pointer toPAL_wrkgp, andload_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-scopecurrent_stack_pointerfor $sp inload_PCB(). A file-scope register-asm variable is the form clang does support.Signed-off-by Matt Turner <[email protected]>--- arch/alpha/kernel/traps.c | 4 +++- arch/alpha/mm/init.c | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-)arch/alpha/kernel/traps.c +3
-1@@ -925,7 +925,9 @@ voidtrap_init (void) {/* Tell PAL-code what global pointer we want in the kernel. */ - registerunsigned long gptr __asm__("$29" ); +unsigned long gptr; + + __asm__volatile ("mov $29, %0" :"=r" (gptr));wrkgp (gptr);wrent (entArith,1 );arch/alpha/mm/init.c +1
-3@@ -63,8 +63,7 @@ pgd_alloc(struct mm_struct *mm)static inline unsigned long load_PCB (struct pcb_struct *pcb) { - registerunsigned long sp __asm__("$30" ); - pcb->ksp = sp; + pcb->ksp = (unsigned long )current_stack_pointer;return __reload_thread (pcb); } --
Quoted 2 lines
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.
I am happy to take this through the Alpha tree.
Thanks,
Magnus
Maciej W. Rozycki
Reviewed-byRe: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
Quoted 14 lines · Magnus Lindholm
Quoted 14 lines
arch/alpha/kernel/traps.c +3
-1@@ -925,7 +925,9 @@ voidtrap_init (void) {/* Tell PAL-code what global pointer we want in the kernel. */ - registerunsigned long gptr __asm__("$29" ); +unsigned long gptr; + + __asm__volatile ("mov $29, %0" :"=r" (gptr));wrkgp (gptr);
Quoted 5 lines
arch/alpha/kernel/traps.c void · line 933
Quoted 1 line
arch/alpha/kernel/traps.c +0
-0wrent (entArith,1 );This looks good to me. The explicit $gp read and use of
current_stack_pointeravoid 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:
alpha/kernel/traps-1.dump renamed from alpha/kernel/traps-0.dump +2 -2
@@ -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:
Maciej
Magnus Lindholm
maintainerRe: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
Quoted 42 lines · Maciej W. Rozycki
Quoted 14 lines · Magnus Lindholm
Quoted 14 lines
arch/alpha/kernel/traps.c +3
-1@@ -925,7 +925,9 @@ voidtrap_init (void) {/* Tell PAL-code what global pointer we want in the kernel. */ - registerunsigned long gptr __asm__("$29" ); +unsigned long gptr; + + __asm__volatile ("mov $29, %0" :"=r" (gptr));wrkgp (gptr);Quoted 5 lines
arch/alpha/kernel/traps.c void · line 933
Quoted 1 line
arch/alpha/kernel/traps.c +0
-0wrent (entArith,1 );This looks good to me. The explicit $gp read and use of
current_stack_pointeravoid 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:alpha/kernel/traps-1.dump 2026-08-11 11:56:31.788713285 +0100 renamed from alpha/kernel/traps-0.dump 2026-08-11 11:57:59.895247441 +0100 +2
-2@@ -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:
Quoted 7 lines
__asm__ __volatile__("mov $29, %0" : "=r" (gptr));Otherwise:
Reviewed-by Maciej W. Rozycki <[email protected]>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
Matt Turner
maintainerRe: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
Quoted 61 lines · Magnus Lindholm
Quoted 42 lines · Maciej W. Rozycki
Quoted 14 lines · Magnus Lindholm
Quoted 14 lines
arch/alpha/kernel/traps.c +3
-1@@ -925,7 +925,9 @@ voidtrap_init (void) {/* Tell PAL-code what global pointer we want in the kernel. */ - registerunsigned long gptr __asm__("$29" ); +unsigned long gptr; + + __asm__volatile ("mov $29, %0" :"=r" (gptr));wrkgp (gptr);Quoted 5 lines
arch/alpha/kernel/traps.c void · line 933
Quoted 1 line
arch/alpha/kernel/traps.c +0
-0wrent (entArith,1 );This looks good to me. The explicit $gp read and use of
current_stack_pointeravoid 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:alpha/kernel/traps-1.dump 2026-08-11 11:56:31.788713285 +0100 renamed from alpha/kernel/traps-0.dump 2026-08-11 11:57:59.895247441 +0100 +2
-2@@ -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:
Quoted 7 lines
__asm__ __volatile__("mov $29, %0" : "=r" (gptr));Otherwise:
Reviewed-by Maciej W. Rozycki <[email protected]>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
Quoted 8 lines
__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
Re: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
In reply to Magnus LindholmQuoted 7 lines · Magnus Lindholm
Quoted 3 lines
Also I think our coding style would rather see the asm written as:
__asm__ __volatile__("mov $29, %0" : "=r" (gptr));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
Quoted 7 lines
__asm__volatile(...)to
__asm____volatile__(...)style change in when I apply it to the Alpha tree?
FAOD it's also the space in `"=r" (gptr)'.
Maciej
Magnus Lindholm
maintainerRe: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang
Quoted 4 lines · Maciej W. Rozycki
FAOD it's also the space in `"=r" (gptr)'.
Maciej
Done!
Magnus
Nathan Chancellor
maintainerHi Matt,
Quoted 1 line · Matt Turner
Two small patches to let the alpha kernel build with clang.
Nice!
Quoted 15 lines
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 toPAL_wrkgpandload_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
Quoted 8 lines
https://github.com/alphalinux-org/llvm-project
and is a work in progress, so the
scripts/Makefile.clangentry 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.
Signature · 2 lines
Cheers, Nathan
Nick Desaulniers
reviewer+ John Paul
Quoted 32 lines · Nathan Chancellor
Hi Matt,
Quoted 1 line · Matt Turner
Two small patches to let the alpha kernel build with clang.
Nice!
Quoted 15 lines
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 toPAL_wrkgpandload_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
Quoted 8 lines
https://github.com/alphalinux-org/llvm-project
and is a work in progress, so the
scripts/Makefile.clangentry 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.
Quoted 5 lines
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
Makefileand assume that ARCH=alpha will work with an upstream clang.
Right. It's cool you have something building. I'm curious if the resulting image boots? (That's the next major milestone).
I'm curious, since we've yet to have such a case of an out of tree llvm backend, what's your plan, if any, to upstream your backend in llvm-project proper? Perhaps as an experimental backend? We have bugs filed in our issue track for m68k which is experimental (but upstream) in LLVM.
Quoted 11 lines
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/alphachanges now then landing thescripts/Makefile.clangchange 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
--
Thanks,
~Nick Desaulniers
Matt Turner
maintainerQuoted 42 lines · Nick Desaulniers
+ John Paul
Quoted 32 lines · Nathan Chancellor
Hi Matt,
Quoted 1 line · Matt Turner
Two small patches to let the alpha kernel build with clang.
Nice!
Quoted 15 lines
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 toPAL_wrkgpandload_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
Quoted 8 lines
https://github.com/alphalinux-org/llvm-project
and is a work in progress, so the
scripts/Makefile.clangentry 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.Quoted 5 lines
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
Makefileand assume that ARCH=alpha will work with an upstream clang.
Quoted 8 lines
Right. It's cool you have something building. I'm curious if the resulting image boots? (That's the next major milestone).
I'm curious, since we've yet to have such a case of an out of tree llvm backend, what's your plan, if any, to upstream your backend in llvm-project proper? Perhaps as an experimental backend? We have bugs filed in our issue track for m68k which is experimental (but upstream) in LLVM.
It builds a kernel that boots in qemu and on real hardware.
As of two days ago, it's capable of building itself and the 373 packages of a Gentoo stage3 + a few other things. These include glibc and other core components (in a qemu-backend container on a fast multicore amd64 system).
I would very much prefer to have the backend upstream, and I plan to start a discussion on discourse.llvm.org this week. I think an experimental backend is probably the limit of what makes sense for Alpha?
If you have advice on going about this, I would welcome it (privately or in reply to this thread).
Current diffstat is
461 files changed, 29735 insertions(+), 88 deletions(-)
of which {llvm,lld,clang}/test is
266 files changed, 9871 insertions(+), 4 deletions(-)
Currently reviewing and cleaning up, so the numbers will change.
Nick Desaulniers
reviewerQuoted 8 lines · Matt Turner
Quoted 5 lines · Nick Desaulniers
Quoted 5 lines · Matt Turner
Quoted 1 line
Two small patches to let the alpha kernel build with clang.
Quoted 7 lines
Quoted 5 lines
I'm curious, since we've yet to have such a case of an out of tree llvm backend, what's your plan, if any, to upstream your backend in llvm-project proper? Perhaps as an experimental backend? We have bugs filed in our issue track for m68k which is experimental (but upstream) in LLVM.
It builds a kernel that boots in qemu and on real hardware.
Wild. Where did you even get real hardware? I know very little about Alpha.
Quoted 5 lines
As of two days ago, it's capable of building itself and the 373 packages of a Gentoo stage3 + a few other things. These include glibc and other core components (in a qemu-backend container on a fast multicore amd64 system).
I haven't kept up with Adhemerval's work on building glibc with clang, but pretty wild to hear about glibc building with clang period, for alpha no less.
Quoted 5 lines
I would very much prefer to have the backend upstream, and I plan to start a discussion on discourse.llvm.org this week. I think an experimental backend is probably the limit of what makes sense for Alpha?
I agree. An RFC on discourse is the way to go. I'd use m68k as an example.
Quoted 7 lines
If you have advice on going about this, I would welcome it (privately or in reply to this thread).
Current diffstat is
461 files changed, 29735 insertions(+), 88 deletions(-)
Only advice is that if any of that was AI generated, please do take the time to review LLVM's AI policy. Reviewers have been getting crunched by low quality AI commits recently, and are a bit salty all around.
https://llvm.org/docs/AIToolPolicy.html
Quoted 6 lines
of which {llvm,lld,clang}/test is
266 files changed, 9871 insertions(+), 4 deletions(-)Currently reviewing and cleaning up, so the numbers will change.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 3 lines · Nick Desaulniers
Quoted 1 line
It builds a kernel that boots in qemu and on real hardware.
Wild. Where did you even get real hardware? I know very little about Alpha.
Of course Matt has hardware, he's been an Alpha/Linux port maintainer for
some 16 years now! And several of us have some too. I've got mine since 2005, and previously ran and worked on Alpha/Linux as early as back in 1998 while the port was still supported by DEC (and the company existed in the first place).
Maciej
Matt Turner
maintainerQuoted 16 lines · Nick Desaulniers
Quoted 14 lines · Matt Turner
Quoted 10 lines · Nick Desaulniers
Quoted 5 lines · Matt Turner
Quoted 1 line
Two small patches to let the alpha kernel build with clang.
I'm curious, since we've yet to have such a case of an out of tree llvm backend, what's your plan, if any, to upstream your backend in llvm-project proper? Perhaps as an experimental backend? We have bugs filed in our issue track for m68k which is experimental (but upstream) in LLVM.
Quoted 3 lines
Quoted 1 line
It builds a kernel that boots in qemu and on real hardware.
Wild. Where did you even get real hardware? I know very little about Alpha.
Mostly eBay :)
... along with most of my other pet computers (https://mattst88.com/computers/)
Quoted 9 lines
Quoted 5 lines
As of two days ago, it's capable of building itself and the 373 packages of a Gentoo stage3 + a few other things. These include glibc and other core components (in a qemu-backend container on a fast multicore amd64 system).
I haven't kept up with Adhemerval's work on building glibc with clang, but pretty wild to hear about glibc building with clang period, for alpha no less.
What a time to be alive!
Quoted 7 lines
Quoted 5 lines
I would very much prefer to have the backend upstream, and I plan to start a discussion on discourse.llvm.org this week. I think an experimental backend is probably the limit of what makes sense for Alpha?
I agree. An RFC on discourse is the way to go. I'd use m68k as an example.
Thank you. I'll find the m68k discussion and model mine on that (assuming they were successful).
Quoted 6 lines
Quoted 6 lines
If you have advice on going about this, I would welcome it (privately or in reply to this thread).
Current diffstat is
Quoted 8 lines
Quoted 1 line
461 files changed, 29735 insertions(+), 88 deletions(-)Only advice is that if any of that was AI generated, please do take the time to review LLVM's AI policy. Reviewers have been getting crunched by low quality AI commits recently, and are a bit salty all around.
Indeed, I have been, but my goal is to do enough self-review such that no one would be able to tell that an LLM was involved. I will of course disclose that LLMs were used.
On Tue, 18 Aug 2026 09:24:37 -0700
Nick Desaulniers <[email protected]> wrote:
...
Quoted 1 line
Wild. Where did you even get real hardware? I know very little about Alpha.
There are two PC-case size alpha in my garage.
They have PCI, 64bit PCI and ISA expansion slots.
I'd guess they are 25-30 years old and are hardly used. Both worked last time I tried to boot them, but the scsi disks have stuck bearings.
They are close to going to the tip, but could be free to a good home!
David
Matt Turner
maintainerPATCH v2 1/2 alpha: pass -Wa,-mev6 only when using GNU as
In reply to Matt TurnerThat flag exists to stop gas emulating instructions the assembler thinks the target lacks. It is a gas-only option, and LLVM's integrated assembler does not emulate instructions in the first place, so nothing is needed there.
Condition it on CONFIG_AS_IS_GNU rather than the compiler, so it is still passed for clang builds using GNU as (LLVM_IAS=0) and omitted only for the integrated assembler.
---
Only this patch changed; patch 2/2 ("alpha: read $gp and $sp explicitly for clang") is unchanged from v1 and is not resent.
Changes in v2:
- Drop the scripts/Makefile.clang CLANG_TARGET_FLAGS_alpha entry. It
will be sent separately when the alpha backend is upstreamed to LLVM.
- Condition -Wa,-mev6 on CONFIG_AS_IS_GNU rather than CONFIG_CC_IS_GCC,
so it is still passed for clang builds using GNU as (LLVM_IAS=0).
- Reword the subject and commit message for the reduced scope.
- Link to v1: https://lore.kernel.org/r/[email protected]
arch/alpha/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/alpha/Makefile +7 -1
@@ -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. LLVM's integrated assembler never emulates. +ifdef CONFIG_AS_IS_GNU +KBUILD_CFLAGS += -Wa,-mev6 +endif libs-y += arch/alpha/lib/
Signature · 1 line
2.54.0
Re: [PATCH v2 1/2] alpha: pass -Wa,-mev6 only when using GNU as
Hi Matt,
Quoted 63 lines · Matt Turner
That flag exists to stop gas emulating instructions the assembler thinks the target lacks. It is a gas-only option, and LLVM's integrated assembler does not emulate instructions in the first place, so nothing is needed there.
Condition it on
CONFIG_AS_IS_GNUrather than the compiler, so it is still passed for clang builds using GNU as (LLVM_IAS=0) and omitted only for the integrated assembler.Signed-off-by Matt Turner <[email protected]>---
Only this patch changed; patch 2/2 ("alpha: read $gp and $sp explicitly for clang") is unchanged from v1 and is not resent.Changes in v2:
- Drop thescripts/Makefile.clangCLANG_TARGET_FLAGS_alphaentry. It
will be sent separately when the alpha backend is upstreamed to LLVM.
- Condition -Wa,-mev6 onCONFIG_AS_IS_GNUrather thanCONFIG_CC_IS_GCC,
so it is still passed for clang builds using GNU as (LLVM_IAS=0).
- Reword the subject and commit message for the reduced scope.
- Link to v1: https://lore.kernel.org/r/[email protected]arch/alpha/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/alpha/Makefile +7
-1@@ -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. LLVM's integrated assembler never emulates. +ifdef CONFIG_AS_IS_GNU +KBUILD_CFLAGS += -Wa,-mev6 +endif libs-y += arch/alpha/lib/Quoted 1 line
arch/alpha/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/alpha/Makefile +2
-0@@ -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.
arch/alpha/Makefile cpuflags-$(CONFIG_ALPHA_GENERIC) := -mcpu=ev56 -mtune=ev6 · line 42
Quoted 10 lines
arch/alpha/Makefile +5
-1# 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. LLVM's integrated assembler never emulates. +ifdef CONFIG_AS_IS_GNU +KBUILD_CFLAGS += -Wa,-mev6 +endif libs-y += arch/alpha/lib/
Thanks for the update. This looks good to me.
Thanks,
Magnus