Signed-off-by: Brad Smith brad@comstyle.com
--- configure.ac | 2 +- fat-arm64.c | 11 ++++++++++- fat-ppc.c | 12 ++++++------ 3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/configure.ac b/configure.ac index 4f27e663..1f53a890 100644 --- a/configure.ac +++ b/configure.ac @@ -212,7 +212,7 @@ LSH_FUNC_ALLOCA
# getenv_secure is used for fat overrides, # getline is used in the testsuite -AC_CHECK_FUNCS(secure_getenv getline) +AC_CHECK_FUNCS(secure_getenv getline elf_aux_info)
ASM_WORDS_BIGENDIAN=unknown AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1) diff --git a/fat-arm64.c b/fat-arm64.c index 45cce0cc..36136078 100644 --- a/fat-arm64.c +++ b/fat-arm64.c @@ -51,6 +51,8 @@ #if USE_GETAUXVAL # include <asm/hwcap.h> # include <sys/auxv.h> +#elif defined(HAVE_ELF_AUX_INFO) +# include <sys/auxv.h> #elif defined(__OpenBSD__) # include <sys/sysctl.h> # include <machine/cpu.h> @@ -133,8 +135,15 @@ get_arm64_features (struct arm64_features *features) } else { +#if USE_GETAUXVAL || defined(HAVE_ELF_AUX_INFO) + unsigned long hwcap = 0; + #if USE_GETAUXVAL - unsigned long hwcap = getauxval(AT_HWCAP); + hwcap = getauxval(AT_HWCAP); +#elif defined(HAVE_ELF_AUX_INFO) + elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); +#endif + features->have_aes = ((hwcap & (HWCAP_ASIMD | HWCAP_AES)) == (HWCAP_ASIMD | HWCAP_AES)); features->have_pmull diff --git a/fat-ppc.c b/fat-ppc.c index aaccc116..c4dae3a1 100644 --- a/fat-ppc.c +++ b/fat-ppc.c @@ -48,14 +48,14 @@ # include <asm/cputable.h> # include <sys/auxv.h> # endif -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__OpenBSD__) # include <machine/cpu.h> # ifdef PPC_FEATURE2_HAS_VEC_CRYPTO # define PPC_FEATURE2_VEC_CRYPTO PPC_FEATURE2_HAS_VEC_CRYPTO # endif -# if __FreeBSD__ >= 12 +# ifdef HAVE_ELF_AUX_INFO # include <sys/auxv.h> -# else +# elif !defined(__OpenBSD__) # include <sys/sysctl.h> # endif #endif @@ -129,11 +129,11 @@ get_ppc_features (struct ppc_features *features) # if USE_GETAUXVAL hwcap = getauxval(AT_HWCAP); hwcap2 = getauxval(AT_HWCAP2); -# elif defined(__FreeBSD__) -# if __FreeBSD__ >= 12 +# elif defined(__FreeBSD__) || defined(__OpenBSD__) +# ifdef HAVE_ELF_AUX_INFO elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2)); -# else +# elif !defined(__OpenBSD__) size_t len; len = sizeof(hwcap); sysctlbyname("hw.cpu_features", &hwcap, &len, NULL, 0);
Brad Smith brad@comstyle.com writes:
--- a/fat-arm64.c +++ b/fat-arm64.c @@ -51,6 +51,8 @@ #if USE_GETAUXVAL # include <asm/hwcap.h> # include <sys/auxv.h> +#elif defined(HAVE_ELF_AUX_INFO) +# include <sys/auxv.h> #elif defined(__OpenBSD__)
Hi, change looks reasonable to me, but can you explain how it relates the the previous openbsd support based on sysctl (added in commit b874bdead2903d715c6964b2e8f9ed7d2b61db12)? Are both methods needed, which one being used depending on openbsd version?
Regards, /Niels
On 2024-09-06 9:11 a.m., Niels Möller wrote:
Brad Smithbrad@comstyle.com writes:
--- a/fat-arm64.c +++ b/fat-arm64.c @@ -51,6 +51,8 @@ #if USE_GETAUXVAL # include <asm/hwcap.h> # include <sys/auxv.h> +#elif defined(HAVE_ELF_AUX_INFO) +# include <sys/auxv.h> #elif defined(__OpenBSD__)
Hi, change looks reasonable to me, but can you explain how it relates the the previous openbsd support based on sysctl (added in commit b874bdead2903d715c6964b2e8f9ed7d2b61db12)? Are both methods needed, which one being used depending on openbsd version?
Regards, /Niels
OpenBSD 7.6 will add elf_aux_info(). The sysctl path will be used for previous releases, so yes it is still necessary. We added the elf_aux_info() API as it is based on the Linux API and is more widespread, simpler API and more cross-platform with a simpler way of doing things. BTW, this also adds support for FreeBSD/arm64.
Brad Smith brad@comstyle.com writes:
OpenBSD 7.6 will add elf_aux_info(). The sysctl path will be used for previous releases, so yes it is still necessary.
Thanks, makes sense. Merged to the master-updates branch for testing (even though, unfortunately, I have no continuous testing set up for any BSD flavor on any arch).
BTW, this also adds support for FreeBSD/arm64.
I'm considering the below followup patch, to reduce level of #if nesting. Does it look right?
(Also not sure why USE_GETAUXVAL is defined the way it is, duplicated in several places, it should perhaps just be a configure test setting HAVE_GETAUXVAL).
Regards, /Niels
diff --git a/fat-ppc.c b/fat-ppc.c index c4dae3a1..9d50e5b1 100644 --- a/fat-ppc.c +++ b/fat-ppc.c @@ -55,7 +55,7 @@ # endif # ifdef HAVE_ELF_AUX_INFO # include <sys/auxv.h> -# elif !defined(__OpenBSD__) +# elif defined(__FreeBSD__) # include <sys/sysctl.h> # endif #endif @@ -129,17 +129,15 @@ get_ppc_features (struct ppc_features *features) # if USE_GETAUXVAL hwcap = getauxval(AT_HWCAP); hwcap2 = getauxval(AT_HWCAP2); -# elif defined(__FreeBSD__) || defined(__OpenBSD__) -# ifdef HAVE_ELF_AUX_INFO +# elif defined(HAVE_ELF_AUX_INFO) elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2)); -# elif !defined(__OpenBSD__) +# elif defined(__FreeBSD__) size_t len; len = sizeof(hwcap); sysctlbyname("hw.cpu_features", &hwcap, &len, NULL, 0); len = sizeof(hwcap2); sysctlbyname("hw.cpu_features2", &hwcap2, &len, NULL, 0); -# endif # endif features->have_crypto_ext = ((hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO);
On 2024-09-07 3:17 p.m., Niels Möller wrote:
Brad Smith brad@comstyle.com writes:
OpenBSD 7.6 will add elf_aux_info(). The sysctl path will be used for previous releases, so yes it is still necessary.
Thanks, makes sense. Merged to the master-updates branch for testing (even though, unfortunately, I have no continuous testing set up for any BSD flavor on any arch).
BTW, this also adds support for FreeBSD/arm64.
I'm considering the below followup patch, to reduce level of #if nesting. Does it look right?
(Also not sure why USE_GETAUXVAL is defined the way it is, duplicated in several places, it should perhaps just be a configure test setting HAVE_GETAUXVAL).
Regards, /Niels
Yes, that looks a little better.
diff --git a/fat-ppc.c b/fat-ppc.c index c4dae3a1..9d50e5b1 100644 --- a/fat-ppc.c +++ b/fat-ppc.c @@ -55,7 +55,7 @@ # endif # ifdef HAVE_ELF_AUX_INFO # include <sys/auxv.h> -# elif !defined(__OpenBSD__) +# elif defined(__FreeBSD__) # include <sys/sysctl.h> # endif #endif @@ -129,17 +129,15 @@ get_ppc_features (struct ppc_features *features) # if USE_GETAUXVAL hwcap = getauxval(AT_HWCAP); hwcap2 = getauxval(AT_HWCAP2); -# elif defined(__FreeBSD__) || defined(__OpenBSD__) -# ifdef HAVE_ELF_AUX_INFO +# elif defined(HAVE_ELF_AUX_INFO) elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2)); -# elif !defined(__OpenBSD__) +# elif defined(__FreeBSD__) size_t len; len = sizeof(hwcap); sysctlbyname("hw.cpu_features", &hwcap, &len, NULL, 0); len = sizeof(hwcap2); sysctlbyname("hw.cpu_features2", &hwcap2, &len, NULL, 0); -# endif # endif features->have_crypto_ext = ((hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO);
Brad Smith brad@comstyle.com writes:
Yes, that looks a little better.
Thanks. Your patch + this followup now merged.
Regards, /Niels
nettle-bugs@lists.lysator.liu.se