From 45bca21a954799d64d9ad86f245916737cdb9971 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 4 Dec 2020 15:34:27 +0100 Subject: [PATCH] Detect ARM features with elf_aux_info on FreeBSD >= 12.0 by @devnexen, thanks! Fixes #1012 --- configure.ac | 2 +- src/libsodium/sodium/runtime.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ad27c924..ca020701 100644 --- a/configure.ac +++ b/configure.ac @@ -864,7 +864,7 @@ if (&getentropy != NULL) { ]) AC_CHECK_FUNCS([posix_memalign getpid nanosleep]) AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset]) -AC_CHECK_FUNCS([getauxval]) +AC_CHECK_FUNCS([getauxva elf_aux_info]) AC_SUBST([LIBTOOL_EXTRA_FLAGS]) diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index 7e0964a9..2251da9a 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -72,10 +72,24 @@ _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) #elif defined(__aarch64__) && defined(AT_HWCAP) # ifdef HAVE_GETAUXVAL cpu_features->has_neon = (getauxval(AT_HWCAP) & (1L << 1)) != 0; +# elif defined(HAVE_ELF_AUX_INFO) + { + unsigned long buf; + if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) { + cpu_features->has_neon = (buf & (1L << 1)) != 0; + } + } # endif #elif defined(__arm__) && defined(AT_HWCAP) # ifdef HAVE_GETAUXVAL cpu_features->has_neon = (getauxval(AT_HWCAP) & (1L << 12)) != 0; +# elif defined(HAVE_ELF_AUX_INFO) + { + unsigned long buf; + if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) { + cpu_features->has_neon = (buf & (1L << 12)) != 0; + } + } # endif #endif @@ -107,10 +121,24 @@ _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) #elif defined(__aarch64__) && defined(AT_HWCAP) # ifdef HAVE_GETAUXVAL cpu_features->has_armcrypto = (getauxval(AT_HWCAP) & (1L << 3)) != 0; +# elif defined(HAVE_ELF_AUX_INFO) + { + unsigned long buf; + if (elf_aux_info(AT_HWCAP, (void *) &buf, (int) sizeof buf) == 0) { + cpu_features->has_armcrypto = (buf & (1L << 3)) != 0; + } + } # endif #elif defined(__arm__) && defined(AT_HWCAP2) # ifdef HAVE_GETAUXVAL cpu_features->has_armcrypto = (getauxval(AT_HWCAP2) & (1L << 0)) != 0; +# elif defined(HAVE_ELF_AUX_INFO) + { + unsigned long buf; + if (elf_aux_info(AT_HWCAP2, (void *) &buf, (int) sizeof buf) == 0) { + cpu_features->has_armcrypto = (buf & (1L << 0)) != 0; + } + } # endif #endif