Add tool to extract ELF Auxiliary vectors for HWCAPs
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63e2b20..05cd0b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -497,6 +497,12 @@
   ADD_EXECUTABLE(cache-info tools/cache-info.c)
   TARGET_LINK_LIBRARIES(cache-info PRIVATE cpuinfo)
 
+  IF(CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux)$" AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv5te|armv7|armv7-a|armv7l|arm64|aarch64)$")
+    ADD_EXECUTABLE(auxv-dump tools/auxv-dump.c)
+    TARGET_INCLUDE_DIRECTORIES(auxv-dump PRIVATE src)
+    TARGET_INCLUDE_DIRECTORIES(auxv-dump PRIVATE include)
+  ENDIF()
+
   IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64)$")
     ADD_EXECUTABLE(cpuid-dump tools/cpuid-dump.c)
     TARGET_INCLUDE_DIRECTORIES(cpuid-dump PRIVATE src)
diff --git a/jni/Android.mk b/jni/Android.mk
index 38092de..b34dd06 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -142,6 +142,17 @@
 LOCAL_STATIC_LIBRARIES := cpuinfo
 include $(BUILD_EXECUTABLE)
 
+ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI),armeabi armeabi-v7a arm64-v8a))
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := auxv-dump
+LOCAL_SRC_FILES := $(LOCAL_PATH)/tools/auxv-dump.c
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/src
+LOCAL_CFLAGS := -std=gnu99
+include $(BUILD_EXECUTABLE)
+
+endif # armeabi, armeabi-v7a, or arm64-v8a
+
 ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI),x86 x86_64))
 
 include $(CLEAR_VARS)
diff --git a/scripts/android-arm64-auxv-dump.sh b/scripts/android-arm64-auxv-dump.sh
new file mode 100755
index 0000000..6c3a0be
--- /dev/null
+++ b/scripts/android-arm64-auxv-dump.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/arm64-v8a/auxv-dump /data/local/tmp/auxv-dump
+adb shell /data/local/tmp/auxv-dump
diff --git a/scripts/android-armv7-auxv-dump.sh b/scripts/android-armv7-auxv-dump.sh
new file mode 100755
index 0000000..34c8eef
--- /dev/null
+++ b/scripts/android-armv7-auxv-dump.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+adb push libs/armeabi-v7a/auxv-dump /data/local/tmp/auxv-dump
+adb shell /data/local/tmp/auxv-dump
diff --git a/tools/auxv-dump.c b/tools/auxv-dump.c
new file mode 100644
index 0000000..a15e5c1
--- /dev/null
+++ b/tools/auxv-dump.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <sys/auxv.h>
+#include <errno.h>
+#include <dlfcn.h>
+
+#include <cpuinfo.h>
+
+
+typedef unsigned long (*getauxval_function_t)(unsigned long);
+
+int main(int argc, char** argv) {
+	void* libc = dlopen("libc.so", RTLD_NOW);
+	if (libc == NULL) {
+		fprintf(stderr, "Error: failed to load libc.so: %s\n", dlerror());
+		exit(EXIT_FAILURE);
+	}
+
+	getauxval_function_t getauxval = (getauxval_function_t) dlsym(libc, "getauxval");
+	if (getauxval == NULL) {
+		fprintf(stderr, "Error: failed to locate getauxval in libc.so: %s", dlerror());
+		exit(EXIT_FAILURE);
+	}
+
+	printf("AT_HWCAP = 0x%08lX\n", getauxval(AT_HWCAP));
+	#if CPUINFO_ARCH_ARM
+		printf("AT_HWCAP2 = 0x%08lX\n", getauxval(AT_HWCAP2));
+	#endif
+
+	return 0;
+}