From: Matt Turner <[email protected]> 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 <[email protected]> Cc: [email protected] Reviewed-by: Helge Deller <[email protected]> Signed-off-by: Helge Deller <[email protected]> (cherry picked from commit 7a2e863f9dd52883d6f59bb425f30609fc14aee4) (Mjt: in 10.0.x, the code is in linux-user/elfload.c, - back-port changes to pre-elfload-reorg state: HAVE_ELF_HWCAP is ELF_HWCAP, get_elf_hwcap() accepts no argument and returns uint32_t) Signed-off-by: Michael Tokarev <[email protected]> diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 35b7ea23880..6b1be150a3e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1720,6 +1720,20 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_ALPHA +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + CPUState *cs = thread_cpu; + /* + * The Linux kernel computes ELF_HWCAP as ~amask(-1), which clears a bit + * for each supported ISA extension. env->amask stores exactly those bits + * set for the extensions supported by the emulated CPU model, matching + * the kernel's convention: bit set in AT_HWCAP ↔ extension present. + */ + return cpu_env(cs)->amask; +} + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { -- 2.47.3
