util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD

Signed-off-by: Brad Smith <brad@comstyle.com>
Message-ID: <ZqXB_zz0fR1CpA7k@humpty.home.comstyle.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Brad Smith 2024-07-27 23:58:55 -04:00 committed by Richard Henderson
parent 25268a1855
commit 27fca0a0d5
4 changed files with 18 additions and 6 deletions

View File

@ -2835,6 +2835,14 @@ config_host_data.set('CONFIG_GETAUXVAL', cc.links(gnu_source_prefix + '''
return getauxval(AT_HWCAP) == 0; return getauxval(AT_HWCAP) == 0;
}''')) }'''))
config_host_data.set('CONFIG_ELF_AUX_INFO', cc.links(gnu_source_prefix + '''
#include <sys/auxv.h>
int main(void) {
unsigned long hwcap = 0;
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
return hwcap;
}'''))
config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles(''' config_host_data.set('CONFIG_USBFS', have_linux_user and cc.compiles('''
#include <linux/usbdevice_fs.h> #include <linux/usbdevice_fs.h>

View File

@ -17,10 +17,13 @@
# define HWCAP2_BTI 0 /* added in glibc 2.32 */ # define HWCAP2_BTI 0 /* added in glibc 2.32 */
# endif # endif
#endif #endif
#ifdef CONFIG_ELF_AUX_INFO
#include <sys/auxv.h>
#endif
#ifdef CONFIG_DARWIN #ifdef CONFIG_DARWIN
# include <sys/sysctl.h> # include <sys/sysctl.h>
#endif #endif
#ifdef __OpenBSD__ #if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
# include <machine/armreg.h> # include <machine/armreg.h>
# include <machine/cpu.h> # include <machine/cpu.h>
# include <sys/types.h> # include <sys/types.h>
@ -61,7 +64,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info = CPUINFO_ALWAYS; info = CPUINFO_ALWAYS;
#ifdef CONFIG_LINUX #if defined(CONFIG_LINUX) || defined(CONFIG_ELF_AUX_INFO)
unsigned long hwcap = qemu_getauxval(AT_HWCAP); unsigned long hwcap = qemu_getauxval(AT_HWCAP);
info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0); info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0);
info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0); info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0);
@ -78,7 +81,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL; info |= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL;
info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI; info |= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI;
#endif #endif
#ifdef __OpenBSD__ #if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
int mib[2]; int mib[2];
uint64_t isar0; uint64_t isar0;
uint64_t pfr1; uint64_t pfr1;

View File

@ -14,7 +14,8 @@
# include "elf.h" # include "elf.h"
# endif # endif
#endif #endif
#ifdef __FreeBSD__ #if defined(CONFIG_ELF_AUX_INFO)
# include <sys/auxv.h>
# include <machine/cpu.h> # include <machine/cpu.h>
# ifndef PPC_FEATURE2_ARCH_3_1 # ifndef PPC_FEATURE2_ARCH_3_1
# define PPC_FEATURE2_ARCH_3_1 0 # define PPC_FEATURE2_ARCH_3_1 0
@ -35,7 +36,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
info = CPUINFO_ALWAYS; info = CPUINFO_ALWAYS;
#if defined(CONFIG_LINUX) || defined(__FreeBSD__) #if defined(CONFIG_LINUX) || defined(CONFIG_ELF_AUX_INFO)
unsigned long hwcap = qemu_getauxval(AT_HWCAP); unsigned long hwcap = qemu_getauxval(AT_HWCAP);
unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2); unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2);

View File

@ -99,7 +99,7 @@ unsigned long qemu_getauxval(unsigned long type)
return 0; return 0;
} }
#elif defined(__FreeBSD__) #elif defined(CONFIG_ELF_AUX_INFO)
#include <sys/auxv.h> #include <sys/auxv.h>
unsigned long qemu_getauxval(unsigned long type) unsigned long qemu_getauxval(unsigned long type)