@samitouri / QOSamiQemu / commits / 7a2e863f9d

linux-user/alpha: populate AT_HWCAP from env->amask

Alpha has never set AT_HWCAP in linux-user emulation, so getauxval(AT_HWCAP) always returned 0 regardless of the emulated CPU model. The Linux kernel computes ELF_HWCAP as ~amask(-1), i.e. the set of ISA extension bits that the amask instruction reports as supported (cleared in its output). env->amask stores exactly those bits with the same layout (BWX=0x1, FIX=0x2, CIX=0x4, MVI=0x100, TRAP=0x200, PREFETCH=0x1000), so returning it directly from get_elf_hwcap matches the kernel convention. Add HAVE_ELF_HWCAP to target_elf.h and implement get_elf_hwcap() in elfload.c to expose the emulated CPU's capability mask to user-space programs via the auxiliary vector. Without this fix, programs using getauxval(AT_HWCAP) to detect BWX/FIX/CIX (such as glibc's memcpy or JIT compilers targeting Alpha) incorrectly concluded that no extensions were available even when emulating ev56+. Signed-off-by: Matt Turner <mattst88@gmail.com> Cc: qemu-stable@nongnu.org Reviewed-by: Helge Deller <deller@gmx.de> Signed-off-by: Helge Deller <deller@gmx.de>

Matt Turner committed Jul 12, 2026 at 21:36 UTC 7a2e863f9dd52883d6f59bb425f30609fc14aee4
2 files changed +12
linux-user/alpha/elfload.c
+11
@@ -6,6 +6,17 @@
6 #include "target_elf.h"
7
8
9 +abi_ulong get_elf_hwcap(CPUState *cs)
10 +{
11 + /*
12 + * The Linux kernel computes ELF_HWCAP as ~amask(-1), which clears a bit
13 + * for each supported ISA extension. env->amask stores exactly those bits
14 + * set for the extensions supported by the emulated CPU model, matching
15 + * the kernel's convention: bit set in AT_HWCAP ↔ extension present.
16 + */
17 + return cpu_env(cs)->amask;
18 +}
19 +
20 void elf_core_copy_regs(target_elf_gregset_t *r, const CPUAlphaState *env)
21 {
22 int i;
linux-user/alpha/target_elf.h
+1
@@ -12,6 +12,7 @@
12 #define ELF_MACHINE EM_ALPHA
13
14 #define HAVE_ELF_CORE_DUMP 1
15 +#define HAVE_ELF_HWCAP 1
16
17 /*
18 * Matches the kernel's elf_gregset_t (ELF_NGREG = 33):