aboutsummaryrefslogtreecommitdiff
path: root/tools/auxv-dump.c
diff options
context:
space:
mode:
authorMarat Dukhan <marat@fb.com>2017-11-29 15:15:36 -0800
committerMarat Dukhan <marat@fb.com>2017-11-29 15:15:36 -0800
commitf3a71e68abc065478780cf4f36bede13cad9e3cf (patch)
treebda99037028d84af71edf64676200670dfb1eda8 /tools/auxv-dump.c
parent63a7a6b48f72e7eef62522240a39d3bd0eb7fb02 (diff)
downloadcpuinfo-f3a71e68abc065478780cf4f36bede13cad9e3cf.tar.gz
Add tool to extract ELF Auxiliary vectors for HWCAPs
Diffstat (limited to 'tools/auxv-dump.c')
-rw-r--r--tools/auxv-dump.c32
1 files changed, 32 insertions, 0 deletions
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;
+}