On 14.03.2019 08:41, Niels Möller wrote:
"Yuriy M. Kaminskiy" yumkam@gmail.com writes:
When compiled for armv6+ and getauxval() is present (glibc 2.16+), avoid slow and unreliable /proc/cpuinfo parsing.
E.g. /proc/cpuinfo contains junk with qemu-user and can be unavailable in some chroot environment.
Do you know what's the preferred way to do this on android? Do we still need /proc/cpuinfo, or are there any library facilities?
Google suggests https://developer.android.com/ndk/guides/cpu-features I have no experience with it.
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16) +#include <sys/auxv.h>
This part could be an AC_CHECK_HEADERS([sys/auxv.h]) in configure.ac.
Hmm... musl also provides it, I'll move detection to configure; then again, musl does not define HWCAP_*, and I'm reluctant to fallback to <asm/hwcap.h> or define HWCAP_* myself, so practically it still works on glibc only.
else { +#if defined(HAVE_GETAUXVAL) && __ARM_ARCH >= 6
Why the condition __ARM_ARCH >= 6? Is it because getauxval doesn't let us make the distinction between arch_version 5 and 6?
There are (const char *)getauxval(AT_PLATFORM); it is expected to be "v[45678][lb]"; probably, I should use it.
Things that should be checked: arm (32bit) userland with aarch64/arm64 kernel.
unsigned long hwcap = getauxval(AT_HWCAP);
features->arch_version = __ARM_ARCH;
Is it important to take the compile-time arch into account? The effect (when it makes a difference at all) will be to force use of certain features, even if runtime checks say we're running on an older arch.
I wanted to limit change to cases I'm sure will work (e.g. on debian/armhf __ARM_ARCH is 7, on raspbian - 6; both are sufficient for nettle to use most optimized code); and don't touch anything "unusual".
Is the getauxval method missing a way to get cpu arch at runtime? In the docs (https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwca...) I don't see anything corresponding to the "CPU arcitecture" line in /proc/cpuinfo.
I'd be happier about getauxval if we could find a way to also get the arch version without reading /proc/cpuinfo. But I don't think it's a blocker for this change.