]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu_arm: fix build on non-Linux
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 8 Jul 2020 13:39:36 +0000 (17:39 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 9 Jul 2020 14:55:27 +0000 (18:55 +0400)
 - 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 <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
configure.ac
src/cpu/cpu_arm.c

index 79055db9b10404ccdf6555c3af5265be5930fb97..40a326c1aae4fc3510fb666545d20bca2731baee 100644 (file)
@@ -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 \
index 016d414143e2e6d610694fc2e7be23ef3f172d07..addeb4100e7d181079a00cb16fecdcdf51eb0fee 100644 (file)
@@ -22,7 +22,9 @@
 
 #include <config.h>
 #if defined(__aarch64__)
-# include <asm/hwcap.h>
+# if defined(HAVE_ASM_HWCAP_H)
+#  include <asm/hwcap.h>
+# endif
 # include <sys/auxv.h>
 #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);