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.
>From ae3be6a1cf3fc3f02d7fb8a25db1b89284d455e3 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <[email protected]>
Date: Sun, 10 Mar 2019 12:25:21 +0300
Subject: [PATCH] fat-arm.c: prefer getauxval() over /proc/cpuinfo parsing

When compiled for armv6+ and getauxval() is present (glibc 2.16+),
avoid slow and unreliable /proc/cpuinfo parsing.
---
 fat-arm.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/fat-arm.c b/fat-arm.c
index 6e4c8622..aaffbf23 100644
--- a/fat-arm.c
+++ b/fat-arm.c
@@ -40,6 +40,13 @@
 #include <stdlib.h>
 #include <string.h>
 
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)
+#include <sys/auxv.h>
+#if defined(AT_HWCAP) && defined(HWCAP_ARM_NEON)
+#define HAVE_GETAUXVAL 1
+#endif
+#endif
+
 #include "nettle-types.h"
 
 #include "aes-internal.h"
@@ -87,6 +94,18 @@ get_arm_features (struct arm_features *features)
       }
   else
     {
+#if defined(HAVE_GETAUXVAL) && __ARM_ARCH >= 6
+      unsigned long hwcap = getauxval(AT_HWCAP);
+      features->arch_version = __ARM_ARCH;
+      /* NEON implies VFPv3 with VFPD32 */
+      /* VFPv4 implies VFPv3 */
+      /* when NEON present, VFPv4 implies NEONv2 */
+      /* VFPv3 implies armv7 */
+      if (features->arch_version < 7 && (hwcap & HWCAP_ARM_VFPv3))
+	features->arch_version = 7;
+      if ((hwcap & HWCAP_ARM_NEON))
+	features->have_neon = 1;
+#else
       FILE *f;
       char line[200];
       int seen_arch = 0;
@@ -132,6 +151,7 @@ get_arm_features (struct arm_features *features)
 	  features->have_neon = 1;
 	}
       fclose (f);
+#endif
     }
 }
 
-- 
2.11.0

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to