From d38559f0b6227aa42759dac7a838f0778917e265 Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Wed, 8 Jul 2020 17:39:36 +0400 Subject: [PATCH] cpu_arm: fix build on non-Linux - Add a check for asm/hwcap.h header presence, - Add a check for getauxval() function that is used on Linux, and for elf_aux_info() which is a FreeBSD equivalent. This is based on a patch submitted by Mikael Urankar in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247722. Signed-off-by: Roman Bogorodskiy Reviewed-by: Michal Privoznik --- configure.ac | 3 +++ src/cpu/cpu_arm.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 79055db9b1..40a326c1aa 100644 --- a/configure.ac +++ b/configure.ac @@ -345,7 +345,9 @@ AC_CHECK_SIZEOF([long]) dnl Availability of various common functions (non-fatal if missing), dnl and various less common threadsafe functions AC_CHECK_FUNCS_ONCE([\ + elf_aux_info \ fallocate \ + getauxval \ getegid \ geteuid \ getgid \ @@ -374,6 +376,7 @@ AC_CHECK_FUNCS_ONCE([\ dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([\ + asm/hwcap.h \ ifaddrs.h \ libtasn1.h \ util.h \ diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 016d414143..addeb4100e 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -22,7 +22,9 @@ #include #if defined(__aarch64__) -# include +# if defined(HAVE_ASM_HWCAP_H) +# include +# endif # include #endif @@ -518,11 +520,13 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data) int cpu_feature_index = 0; size_t i; +# if defined(HAVE_GETAUXVAL) if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("CPUID registers unavailable")); return -1; } +# endif /* read the cpuid data from MIDR_EL1 register */ asm("mrs %0, MIDR_EL1" : "=r" (cpuid)); @@ -533,7 +537,13 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data) /* parse the corresponding vendor_id bits */ data->vendor_id = (cpuid >> 24) & 0xff; +# if defined(HAVE_GETAUXVAL) hwcaps = getauxval(AT_HWCAP); +# elif defined(HAVE_ELF_AUX_INFO) + elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long)); +# else +# error No routines to retrieve a value from the auxiliary vector +# endif VIR_DEBUG("CPU flags read from register: 0x%016lx", hwcaps); features = g_new0(char *, MAX_CPU_FLAGS + 1);