[compiler-rt] Add support for Alpha to libsanitizer (PR #194161)
Matt Turner via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 20:00:37 PDT 2026
https://github.com/mattst88 updated https://github.com/llvm/llvm-project/pull/194161
>From a525476f8eff6a1e1a845d93ab5898315852e4c5 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:06:30 -0400
Subject: [PATCH 01/16] [sanitizer] Add SANITIZER_ALPHA platform macro
Adds the SANITIZER_ALPHA preprocessor macro to sanitizer_platform.h,
following the same pattern as SANITIZER_RISCV64 and SANITIZER_LOONGARCH64.
---
compiler-rt/lib/sanitizer_common/sanitizer_platform.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index a1f3cf799e344..7f4310d301d44 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -302,6 +302,12 @@
# define SANITIZER_LOONGARCH64 0
#endif
+#if defined(__alpha__)
+# define SANITIZER_ALPHA 1
+#else
+# define SANITIZER_ALPHA 0
+#endif
+
#if defined(__AMDGPU__)
# define SANITIZER_AMDGPU 1
#else
>From e0a907382b84aeaff1bafd18fe038d1156e0d50a Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:07:11 -0400
Subject: [PATCH 02/16] [sanitizer] Add Linux/Alpha syscall implementation
Alpha's syscall ABI differs from every other Linux target: the kernel
signals errors via a separate flag in $a3 ($19) rather than returning a
negative errno in $v0. On error $a3 is 1 and $v0 holds the positive
errno; on success $a3 is 0 and $v0 holds the return value.
The wrappers normalize this to the standard -errno convention so that
internal_iserror's generic "retval >= -4095" test works unchanged.
For syscalls with 4-6 arguments $a3 ($19) serves dual purpose: it
carries the fourth argument on entry and holds the error flag on return.
Those overloads use a read-write ("+r") constraint for that register.
Clobbers follow glibc's alpha/sysdep.h: $1 (t0), $22-$25 (t8-t11),
$28 (at) -- the scratch registers consumed by the callsys PALcode.
---
.../lib/sanitizer_common/sanitizer_linux.cpp | 2 +
.../sanitizer_syscall_linux_alpha.inc | 146 ++++++++++++++++++
2 files changed, 148 insertions(+)
create mode 100644 compiler-rt/lib/sanitizer_common/sanitizer_syscall_linux_alpha.inc
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index bbe876828217f..fdb8f300046a0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -263,6 +263,8 @@ ScopedBlockSignals::~ScopedBlockSignals() { SetSigProcMask(&saved_, nullptr); }
# include "sanitizer_syscall_linux_hexagon.inc"
# elif SANITIZER_LINUX && SANITIZER_LOONGARCH64
# include "sanitizer_syscall_linux_loongarch64.inc"
+# elif SANITIZER_LINUX && SANITIZER_ALPHA
+# include "sanitizer_syscall_linux_alpha.inc"
# else
# include "sanitizer_syscall_generic.inc"
# endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_syscall_linux_alpha.inc b/compiler-rt/lib/sanitizer_common/sanitizer_syscall_linux_alpha.inc
new file mode 100644
index 0000000000000..322a3eb574bee
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_syscall_linux_alpha.inc
@@ -0,0 +1,146 @@
+//===-- sanitizer_syscall_linux_alpha.inc ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementations of internal_syscall and internal_iserror for Linux/Alpha.
+//
+// Alpha syscall ABI: number in $v0 ($0), args in $a0-$a5 ($16-$21), return
+// value in $v0 ($0), error flag in $a3 ($19) -- 0 on success, 1 on error.
+// On error, $v0 holds the positive errno. Normalize to the standard -errno
+// convention on return so that internal_iserror can use the generic test.
+//
+// For syscalls with 4-6 arguments $a3 ($19) serves dual purpose: it carries
+// the fourth argument on entry and the error flag on return, so those variants
+// use a read-write ("+r") constraint for that register.
+//
+//===----------------------------------------------------------------------===//
+
+#define SYSCALL(name) __NR_##name
+
+static uptr __internal_syscall(u64 nr) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a3 asm("$19");
+ asm volatile("callsys"
+ : "+r"(v0), "=r"(a3)
+ :
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall0(n) (__internal_syscall)(n)
+
+static uptr __internal_syscall(u64 nr, u64 arg1) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a3 asm("$19");
+ asm volatile("callsys"
+ : "+r"(v0), "=r"(a3)
+ : "r"(a0)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall1(n, a1) (__internal_syscall)(n, (u64)(a1))
+
+static uptr __internal_syscall(u64 nr, u64 arg1, long arg2) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a1 asm("$17") = arg2;
+ register u64 a3 asm("$19");
+ asm volatile("callsys"
+ : "+r"(v0), "=r"(a3)
+ : "r"(a0), "r"(a1)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall2(n, a1, a2) \
+ (__internal_syscall)(n, (u64)(a1), (long)(a2))
+
+static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a1 asm("$17") = arg2;
+ register u64 a2 asm("$18") = arg3;
+ register u64 a3 asm("$19");
+ asm volatile("callsys"
+ : "+r"(v0), "=r"(a3)
+ : "r"(a0), "r"(a1), "r"(a2)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall3(n, a1, a2, a3) \
+ (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3))
+
+static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
+ u64 arg4) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a1 asm("$17") = arg2;
+ register u64 a2 asm("$18") = arg3;
+ register u64 a3 asm("$19") = arg4;
+ asm volatile("callsys"
+ : "+r"(v0), "+r"(a3)
+ : "r"(a0), "r"(a1), "r"(a2)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall4(n, a1, a2, a3, a4) \
+ (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4))
+
+static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3, u64 arg4,
+ long arg5) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a1 asm("$17") = arg2;
+ register u64 a2 asm("$18") = arg3;
+ register u64 a3 asm("$19") = arg4;
+ register u64 a4 asm("$20") = arg5;
+ asm volatile("callsys"
+ : "+r"(v0), "+r"(a3)
+ : "r"(a0), "r"(a1), "r"(a2), "r"(a4)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall5(n, a1, a2, a3, a4, a5) \
+ (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
+ (u64)(a5))
+
+static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3, u64 arg4,
+ long arg5, long arg6) {
+ register u64 v0 asm("$0") = nr;
+ register u64 a0 asm("$16") = arg1;
+ register u64 a1 asm("$17") = arg2;
+ register u64 a2 asm("$18") = arg3;
+ register u64 a3 asm("$19") = arg4;
+ register u64 a4 asm("$20") = arg5;
+ register u64 a5 asm("$21") = arg6;
+ asm volatile("callsys"
+ : "+r"(v0), "+r"(a3)
+ : "r"(a0), "r"(a1), "r"(a2), "r"(a4), "r"(a5)
+ : "memory", "$1", "$22", "$23", "$24", "$25", "$28");
+ return a3 ? -v0 : v0;
+}
+#define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
+ (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
+ (u64)(a5), (long)(a6))
+
+#define __SYSCALL_NARGS_X(a1, a2, a3, a4, a5, a6, a7, a8, n, ...) n
+#define __SYSCALL_NARGS(...) \
+ __SYSCALL_NARGS_X(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
+#define __SYSCALL_CONCAT_X(a, b) a##b
+#define __SYSCALL_CONCAT(a, b) __SYSCALL_CONCAT_X(a, b)
+#define __SYSCALL_DISP(b, ...) \
+ __SYSCALL_CONCAT(b, __SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+
+#define internal_syscall(...) __SYSCALL_DISP(__internal_syscall, __VA_ARGS__)
+
+bool internal_iserror(uptr retval, int* rverrno) {
+ if (retval >= (uptr)-4095) {
+ if (rverrno)
+ *rverrno = -retval;
+ return true;
+ }
+ return false;
+}
>From 16e89a37ba266edab3a65f6001f02b3c3c5e95d2 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:40:57 -0400
Subject: [PATCH 03/16] [sanitizer] Report correct virtual address size on
Linux/Alpha
Linux/Alpha enforces a fixed 43-bit user virtual address space. Unlike
aarch64, RISC-V, or PowerPC64 -- where the VAS width varies at runtime
and must be probed -- Alpha's limit is constant across all
implementations, so a compile-time constant is correct.
---
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index fdb8f300046a0..28e04c509807f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1245,6 +1245,8 @@ uptr GetMaxVirtualAddress() {
// loongarch64 also has multiple address space layouts: default is 47-bit.
// RISC-V 64 also has multiple address space layouts: 39, 48 and 57-bit.
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
+# elif SANITIZER_ALPHA
+ return (1ULL << 43) - 1; // 0x000007ffffffffffUL
# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
>From 68e969817bffee10ad2bcc2ff00c2276f430d180 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:42:03 -0400
Subject: [PATCH 04/16] [sanitizer] Skip __old_kernel_stat check on Alpha
struct __old_kernel_stat is a legacy 32-bit-era stat structure that
Alpha never had. Add __alpha__ to the exclusion list alongside the
other 64-bit-only architectures that skip this check.
---
.../lib/sanitizer_common/sanitizer_platform_limits_linux.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
index bf0f355847cb1..a0cafd0b6cbde 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
@@ -60,7 +60,7 @@ using namespace __sanitizer;
# if !defined(__powerpc64__) && !defined(__x86_64__) && \
!defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
!defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__) && \
- !defined(__loongarch__)
+ !defined(__loongarch__) && !defined(__alpha__)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif
>From 827f9243ea665d27be262dc216e61c77ce17f088 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:45:04 -0400
Subject: [PATCH 05/16] [sanitizer] Use statx for stat syscalls on Linux/Alpha
Alpha's syscall table has no newfstatat; it uses fstatat64 for the
AT_FDCWD-relative case and statx for the modern path. Route
internal_stat, internal_lstat, and internal_fstat through statx (which
Alpha has at syscall 522), the same path already used for loongarch64.
---
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 28e04c509807f..63a365a856733 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -90,7 +90,8 @@
extern "C" SANITIZER_WEAK_ATTRIBUTE const char *strerrorname_np(int);
# endif
-# if SANITIZER_LINUX && (defined(__loongarch__) || defined(__hexagon__))
+# if SANITIZER_LINUX && \
+ (defined(__loongarch__) || defined(__hexagon__) || defined(__alpha__))
# include <sys/sysmacros.h>
# endif
@@ -375,7 +376,8 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
}
# endif
-# if SANITIZER_LINUX && (defined(__loongarch__) || defined(__hexagon__))
+# if SANITIZER_LINUX && \
+ (defined(__loongarch__) || defined(__hexagon__) || defined(__alpha__))
static void statx_to_stat(struct statx *in, struct stat *out) {
internal_memset(out, 0, sizeof(*out));
out->st_dev = makedev(in->stx_dev_major, in->stx_dev_minor);
@@ -455,7 +457,7 @@ uptr internal_stat(const char *path, void *buf) {
# if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
# elif SANITIZER_LINUX
-# if defined(__loongarch__) || defined(__hexagon__)
+# if defined(__loongarch__) || defined(__hexagon__) || defined(__alpha__)
struct statx bufx;
int res = internal_syscall(SYSCALL(statx), AT_FDCWD, (uptr)path,
AT_NO_AUTOMOUNT, STATX_BASIC_STATS, (uptr)&bufx);
@@ -493,7 +495,7 @@ uptr internal_lstat(const char *path, void *buf) {
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# elif SANITIZER_LINUX
-# if defined(__loongarch__) || defined(__hexagon__)
+# if defined(__loongarch__) || defined(__hexagon__) || defined(__alpha__)
struct statx bufx;
int res = internal_syscall(SYSCALL(statx), AT_FDCWD, (uptr)path,
AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT,
@@ -541,7 +543,7 @@ uptr internal_fstat(fd_t fd, void *buf) {
int res = internal_syscall(SYSCALL(fstat64), fd, &kbuf);
kernel_stat_to_stat(&kbuf, (struct stat *)buf);
return res;
-# elif SANITIZER_LINUX && defined(__loongarch__)
+# elif SANITIZER_LINUX && (defined(__loongarch__) || defined(__alpha__))
struct statx bufx;
int res = internal_syscall(SYSCALL(statx), fd, "", AT_EMPTY_PATH,
STATX_BASIC_STATS, (uptr)&bufx);
>From 9ab6bb3f9e4ffff8653433f10358640633cf114e Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:45:50 -0400
Subject: [PATCH 06/16] [sanitizer] Add GetPcSpBp signal context support for
Alpha
Extract PC, frame pointer ($15/$fp/$s6), and stack pointer ($30/$sp)
from the Alpha mcontext_t (which is a struct sigcontext) when reporting
errors from a signal handler context.
---
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 63a365a856733..4a1dc77a2c0cf 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2783,6 +2783,11 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
*pc = ucontext->uc_mcontext.__pc;
*bp = ucontext->uc_mcontext.__gregs[22];
*sp = ucontext->uc_mcontext.__gregs[3];
+# elif defined(__alpha__)
+ ucontext_t* ucontext = (ucontext_t*)context;
+ *pc = ucontext->uc_mcontext.sc_pc;
+ *bp = ucontext->uc_mcontext.sc_regs[15]; // $fp / $s6
+ *sp = ucontext->uc_mcontext.sc_regs[30]; // $sp
# else
# error "Unsupported arch"
# endif
>From 9106693570d4acc0f659408f1fa3cd16a3ff6186 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:46:39 -0400
Subject: [PATCH 07/16] [sanitizer] Add Alpha struct size constants
- struct_kernel_stat_sz = 80: seven 32-bit fields + 4-byte natural
padding + one 64-bit field + three 64-bit timestamps + four 32-bit
fields, matching arch/alpha/include/uapi/asm/stat.h.
- struct_kernel_stat64_sz = 136: five 64-bit fields + six 32-bit fields
+ six 64-bit timestamp/nsec fields + three 64-bit reserved slots.
- SIZEOF_STRUCT_USTAT = 32: same as other 64-bit Linux targets.
---
.../lib/sanitizer_common/sanitizer_platform_limits_posix.cpp | 2 +-
.../lib/sanitizer_common/sanitizer_platform_limits_posix.h | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index 3ea9002f5f19e..434b58644829c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -293,7 +293,7 @@ namespace __sanitizer {
#define SIZEOF_STRUCT_USTAT 32
# elif defined(__arm__) || defined(__i386__) || defined(__mips__) || \
defined(__powerpc__) || defined(__s390__) || defined(__sparc__) || \
- defined(__hexagon__)
+ defined(__hexagon__) || defined(__alpha__)
# define SIZEOF_STRUCT_USTAT 20
# elif defined(__loongarch__)
// Not used. The minimum Glibc version available for LoongArch is 2.36
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 05ebee49f2ab4..9910c58918f47 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -133,6 +133,9 @@ const unsigned struct_kernel_stat64_sz = 0;
# elif defined(__loongarch__)
const unsigned struct_kernel_stat_sz = 128;
const unsigned struct_kernel_stat64_sz = 0;
+# elif defined(__alpha__)
+const unsigned struct_kernel_stat_sz = 80;
+const unsigned struct_kernel_stat64_sz = 136;
# endif
struct __sanitizer_perf_event_attr {
unsigned type;
>From 561af02d456ffde7a5d5615e0c3f9cd3b4a6e92a Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 15:46:58 -0400
Subject: [PATCH 08/16] [sanitizer] Add Alpha ioctl encoding constants
Alpha uses a non-standard ioctl number layout inherited from OSF/1:
SIZEBITS=13, DIRBITS=3, NONE=1, WRITE=4, READ=2. This matches
powerpc, mips, and sparc; add __alpha__ to that condition.
---
.../lib/sanitizer_common/sanitizer_platform_limits_posix.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 9910c58918f47..ed50ba9071f26 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -1026,7 +1026,7 @@ struct __sanitizer_cookie_io_functions_t {
# define IOC_NRBITS 8
# define IOC_TYPEBITS 8
# if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__) || \
- defined(__sparc__)
+ defined(__sparc__) || defined(__alpha__)
# define IOC_SIZEBITS 13
# define IOC_DIRBITS 3
# define IOC_NONE 1U
>From e9389e4c4a9e34100d7e9d209efa3200258215c9 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 16:21:32 -0400
Subject: [PATCH 09/16] [compiler-rt][asan] Use dynamic shadow offset on Alpha
Alpha's 43-bit user VAS leaves no room for a single fixed shadow offset
that works across all possible memory layouts. Use the dynamic shadow
path (already used by RISC-V for similar reasons) so the shadow base is
chosen at ASan initialization time.
---
compiler-rt/lib/asan/asan_mapping.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h
index 50be8f2cb8901..fba81254c041e 100644
--- a/compiler-rt/lib/asan/asan_mapping.h
+++ b/compiler-rt/lib/asan/asan_mapping.h
@@ -210,6 +210,8 @@
# define ASAN_SHADOW_OFFSET_CONST 0x0000800000000000
# elif SANITIZER_RISCV64
# define ASAN_SHADOW_OFFSET_DYNAMIC
+# elif SANITIZER_ALPHA
+# define ASAN_SHADOW_OFFSET_DYNAMIC
# elif defined(__aarch64__)
# define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000
# elif defined(__powerpc64__)
>From aa6b57fb8b78be9b5c0b8d93afb31ac9fcf961dc Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Sat, 25 Apr 2026 12:20:19 -0400
Subject: [PATCH 10/16] [compiler-rt] sanitizer: Alpha struct sigaction has no
sa_restorer
Alpha does not use a signal restorer trampoline; the kernel handles
signal return through the PALcode mechanism rather than a userspace
restorer. Exclude sa_restorer from __sanitizer_sigaction, skip the
compile-time layout check, and skip the sa_restorer copy in
internal_sigaction_syscall.
---
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 4 ++--
.../lib/sanitizer_common/sanitizer_platform_limits_posix.cpp | 3 ++-
.../lib/sanitizer_common/sanitizer_platform_limits_posix.h | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 4a1dc77a2c0cf..33c5ca880a1ef 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1022,7 +1022,7 @@ int internal_sigaction_norestorer(int signum, const void *act, void *oldact) {
// rt_sigaction, so we need to do the same (we'll need to reimplement the
// restorers; for x86_64 the restorer address can be obtained from
// oldact->sa_restorer upon a call to sigaction(xxx, NULL, oldact).
-# if !SANITIZER_ANDROID || !SANITIZER_MIPS32
+# if (!SANITIZER_ANDROID || !SANITIZER_MIPS32) && !defined(__alpha__)
k_act.sa_restorer = u_act->sa_restorer;
# endif
}
@@ -1038,7 +1038,7 @@ int internal_sigaction_norestorer(int signum, const void *act, void *oldact) {
internal_memcpy(&u_oldact->sa_mask, &k_oldact.sa_mask,
sizeof(__sanitizer_kernel_sigset_t));
u_oldact->sa_flags = k_oldact.sa_flags;
-# if !SANITIZER_ANDROID || !SANITIZER_MIPS32
+# if (!SANITIZER_ANDROID || !SANITIZER_MIPS32) && !defined(__alpha__)
u_oldact->sa_restorer = k_oldact.sa_restorer;
# endif
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index 434b58644829c..14a0da40ab737 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -1154,7 +1154,8 @@ CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
// didn't exist.
CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_flags);
#endif
-#if SANITIZER_LINUX && (!SANITIZER_ANDROID || !SANITIZER_MIPS32)
+# if SANITIZER_LINUX && (!SANITIZER_ANDROID || !SANITIZER_MIPS32) && \
+ !defined(__alpha__)
CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_restorer);
#endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index ed50ba9071f26..12f9603cd05ab 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -744,7 +744,7 @@ struct __sanitizer_sigaction {
# endif
# endif
# endif
-# if SANITIZER_LINUX || SANITIZER_HAIKU
+# if (SANITIZER_LINUX && !defined(__alpha__)) || SANITIZER_HAIKU
void (*sa_restorer)();
# endif
# if defined(__mips__) && (SANITIZER_WORDSIZE == 32) && !SANITIZER_MUSL
>From 23d7f4d8504f8c7c8dcba2752d0935f2945c7099 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 16:22:18 -0400
Subject: [PATCH 11/16] [compiler-rt] sanitizer: Disable interceptor trampoline
on Alpha
Alpha has no ASM_TAIL_CALL definition, so C_ASM_TAIL_CALL is undefined
and the trampoline code in interception.h fails to parse. Add Alpha to
the existing no-trampoline list alongside i386, powerpc, s390, and
sparc, which use the simpler alias-based interceptor scheme instead.
---
compiler-rt/lib/sanitizer_common/sanitizer_asm.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
index 9235422499df1..d12beafccd021 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
@@ -105,8 +105,8 @@
# define ASM_SIZE(symbol) .size symbol, .-symbol
# define ASM_SYMBOL(symbol) symbol
# define ASM_SYMBOL_INTERCEPTOR(symbol) symbol
-# if defined(__i386__) || defined(__powerpc__) || defined(__s390__) || \
- defined(__sparc__)
+# if defined(__i386__) || defined(__powerpc__) || defined(__s390__) || \
+ defined(__sparc__) || defined(__alpha__)
// For details, see interception.h
# define ASM_WRAPPER_NAME(symbol) __interceptor_##symbol
# define ASM_TRAMPOLINE_ALIAS(symbol, name) \
>From 35645c0c567b525d443f2abb1120564b2700f335 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 16:22:11 -0400
Subject: [PATCH 12/16] [compiler-rt] sanitizer: Add Alpha __sanitizer_dirent
layout
Alpha's ino_t is 32-bit (unlike most 64-bit Linux targets where it is
64-bit), with an explicit 4-byte pad field between d_ino and the 64-bit
d_off. Add an Alpha-specific __sanitizer_dirent to match this layout
so the compile-time offset checks pass.
---
.../sanitizer_common/sanitizer_platform_limits_posix.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 12f9603cd05ab..3212e3043c1a8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -557,6 +557,14 @@ struct __sanitizer_dirent {
unsigned short d_reclen;
// more fields that we don't care about
};
+# elif defined(__alpha__)
+struct __sanitizer_dirent {
+ unsigned int d_ino; // ino_t is 32-bit on Alpha
+ int __pad; // explicit padding before d_off
+ unsigned long d_off;
+ unsigned short d_reclen;
+ // more fields that we don't care about
+};
# else
struct __sanitizer_dirent {
uptr d_ino;
>From c2eedfc132c4f7248b4d72b9e466b33045ab6249 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Sat, 25 Apr 2026 11:59:45 -0400
Subject: [PATCH 13/16] [compiler-rt] sanitizer: Add Alpha
ThreadDescriptorSizeFallback()
sizeof(struct pthread) is 1824 on Alpha with glibc 2.43.
---
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 2d398476738e0..2c78522a0fceb 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -293,6 +293,10 @@ static uptr ThreadDescriptorSizeFallback() {
# if defined(__powerpc64__)
return 1776; // from glibc.ppc64le 2.20-8.fc21
# endif
+
+# if defined(__alpha__)
+ return 1824; // from glibc 2.43
+# endif
}
# endif // SANITIZER_GLIBC && !SANITIZER_GO
>From b866abf5f2d4acceb42e002e679bdeedb40ffb3e Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 21 Apr 2026 16:21:01 -0400
Subject: [PATCH 14/16] [compiler-rt] Enable Alpha Linux target
Add Alpha to the compiler-rt CMake build system by registering it in
AllSupportedArchDefs.cmake and adding the target-detection branch to
base-config-ix.cmake, enabling sanitizer and UBSan runtimes for
alpha-unknown-linux-gnu.
---
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake | 7 ++++---
compiler-rt/cmake/base-config-ix.cmake | 2 ++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 761e26ce3e7d8..97ec5a1b6439a 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -1,3 +1,4 @@
+set(ALPHA alpha)
set(AMDGPU amdgcn)
set(ARM64 aarch64)
set(ARM32 arm armhf)
@@ -42,10 +43,10 @@ endif()
set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}
- ${HEXAGON} ${LOONGARCH64})
+ ${HEXAGON} ${LOONGARCH64} ${ALPHA})
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
- ${LOONGARCH64})
+ ${LOONGARCH64} ${ALPHA})
set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64}
${S390X})
@@ -105,7 +106,7 @@ endif()
set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X} ${HEXAGON})
set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
- ${LOONGARCH64} ${AMDGPU} ${NVPTX})
+ ${LOONGARCH64} ${AMDGPU} ${NVPTX} ${ALPHA})
if (OS_NAME MATCHES "FreeBSD")
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
else()
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index 4898e3428ebb0..ed0f3940daa92 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -315,6 +315,8 @@ macro(test_targets)
test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "ve")
test_target_arch(ve "__ve__" "--target=ve-unknown-none")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "alpha")
+ test_target_arch(alpha "" "")
endif()
set(COMPILER_RT_OS_SUFFIX "")
endif()
>From 38625a5f85f59cbe24e1dab9a8c3c4245ddb3e1e Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Mon, 27 Apr 2026 22:29:08 -0400
Subject: [PATCH 15/16] [compiler-rt] Use fixed shadow offset and cap VAS for
Alpha
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Alpha's 43-bit VAS cannot accommodate ASan's dynamic shadow model —
mmap(NULL, 1TB) places the shadow near the top of the 43-bit space and
the shadow-arithmetic then wraps beyond VAS boundaries.
Switch to a fixed shadow offset of 0x70000000000 (7 TiB), which yields
a no-HighMem layout that fits entirely within the 43-bit VAS:
LowMem: [0, 0x6FFFFFFFFFF] (~7.0 TiB, all app memory)
LowShadow: [0x70000000000, 0x7DFFFFFFFFF] (~896 GiB)
There is no room for HighMem above LowShadow: placing application memory
there would require its shadow to extend beyond the VAS boundary. Cap
GetMaxVirtualAddress() at 0x6FFFFFFFFFF (= ASAN_SHADOW_OFFSET - 1) so
that kHighMemBeg = MEM_TO_SHADOW(kHighMemEnd) + 1 > kHighMemEnd, keeping
the HighMem region empty.
The previous cap of (1 << 43) - 1 = 0x7FFFFFFFFFF included the LowShadow
region in the reported max user address, causing GetThreadStackTopAndBottom()
to fail with CHECK(*stack_top <= maxAddr) when the stack lands between
0x6FFFFFFFFFF and 0x70000000000.
---
compiler-rt/lib/asan/asan_mapping.h | 2 +-
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h
index fba81254c041e..406fcaba5692f 100644
--- a/compiler-rt/lib/asan/asan_mapping.h
+++ b/compiler-rt/lib/asan/asan_mapping.h
@@ -211,7 +211,7 @@
# elif SANITIZER_RISCV64
# define ASAN_SHADOW_OFFSET_DYNAMIC
# elif SANITIZER_ALPHA
-# define ASAN_SHADOW_OFFSET_DYNAMIC
+# define ASAN_SHADOW_OFFSET_CONST 0x70000000000
# elif defined(__aarch64__)
# define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000
# elif defined(__powerpc64__)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 33c5ca880a1ef..561ac36969d99 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1248,7 +1248,11 @@ uptr GetMaxVirtualAddress() {
// RISC-V 64 also has multiple address space layouts: 39, 48 and 57-bit.
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
# elif SANITIZER_ALPHA
- return (1ULL << 43) - 1; // 0x000007ffffffffffUL
+ // With fixed shadow offset 0x70000000000, all application memory lives in
+ // LowMem [0, ASAN_SHADOW_OFFSET-1]. There is no room for HighMem above
+ // LowShadow within the 43-bit VAS, so cap here to keep HighMem empty
+ // (kHighMemBeg = MEM_TO_SHADOW(kHighMemEnd) + 1 > kHighMemEnd).
+ return 0x6FFFFFFFFFFULL; // ASAN_SHADOW_OFFSET - 1
# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
>From 51ddac7796756b04ffb75af3f07b8d9fb96df5f5 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Mon, 27 Apr 2026 22:29:19 -0400
Subject: [PATCH 16/16] [compiler-rt][ASan] Skip high-shadow and gap setup when
HighMem is empty
On targets where the shadow offset sits above all addressable user memory
(e.g. Alpha with ASAN_SHADOW_OFFSET=0x70000000000 and a 43-bit VAS),
kHighMemBeg is set above kHighMemEnd so the HighMem region is empty.
Since MEM_TO_SHADOW is monotonically increasing, kHighMemBeg > kHighMemEnd
implies kHighShadowBeg > kHighShadowEnd. With Alpha's layout:
kHighMemEnd = 0x6FFFFFFFFFF
kHighMemBeg = MEM_TO_SHADOW(kHighMemEnd) + 1 = 0x7E000000000
kHighShadowEnd = MEM_TO_SHADOW(kHighMemEnd) = 0x7DFFFFFFFFF
kHighShadowBeg = MEM_TO_SHADOW(kHighMemBeg) = 0x7FC00000000
Calling ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd) passes
size = kHighShadowEnd - kHighShadowBeg + 1, which underflows to a large
negative value, and mmap() fails with ENOMEM.
ProtectGap is also skipped: there is no meaningful shadow gap between
LowShadow and an empty HighShadow.
Guard both operations on kHighMemBeg <= kHighMemEnd.
---
compiler-rt/lib/asan/asan_shadow_setup.cpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_shadow_setup.cpp b/compiler-rt/lib/asan/asan_shadow_setup.cpp
index 5b3591da067bd..8bd6c5956eda0 100644
--- a/compiler-rt/lib/asan/asan_shadow_setup.cpp
+++ b/compiler-rt/lib/asan/asan_shadow_setup.cpp
@@ -89,11 +89,17 @@ void InitializeShadowMemory() {
// mmap the low shadow plus at least one page at the left.
if (kLowShadowBeg)
ReserveShadowMemoryRange(shadow_start, kLowShadowEnd, "low shadow");
- // mmap the high shadow.
- ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd, "high shadow");
- // protect the gap.
- ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
- CHECK_EQ(kShadowGapEnd, kHighShadowBeg - 1);
+ // mmap the high shadow and protect the gap.
+ // On targets where the shadow offset sits above all addressable user memory
+ // (e.g. Alpha's 43-bit VAS with offset 0x70000000000), there is no HighMem
+ // region: kHighMemBeg is set above kHighMemEnd to make it empty. In that
+ // configuration kHighShadowBeg > kHighShadowEnd and kShadowGapBeg >
+ // kShadowGapEnd, so both operations would underflow. Skip them.
+ if (kHighMemBeg <= kHighMemEnd) {
+ ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd, "high shadow");
+ ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
+ CHECK_EQ(kShadowGapEnd, kHighShadowBeg - 1);
+ }
} else if (kMidMemBeg &&
MemoryRangeIsAvailable(shadow_start, kMidMemBeg - 1) &&
MemoryRangeIsAvailable(kMidMemEnd + 1, kHighShadowEnd)) {
More information about the llvm-commits
mailing list