Not all Linux arches include <asm/perf_regs.h>. Checking for just
architecture (__x86__/__i386__) has turned out to be brittle, so
now we add configury.

* configure.ac: Introduce HAVE_PERF_REGS_H.
* backends/i386_initreg_sample.c: Guard asm/perf_regs.h include.
* backends/x86_64_initreg_sample.c: Ditto.
* backends/libebl_PERF_FLAGS.h: Ditto.
* src/stacktrace.c: Clarify that eu-stacktrace configury currently
  conditions the asm/perf_regs.h include on _ASM_X86_PERF_REGS_H.
---
 backends/i386_initreg_sample.c   | 4 +++-
 backends/libebl_PERF_FLAGS.h     | 3 +--
 backends/x86_64_initreg_sample.c | 4 +++-
 configure.ac                     | 5 +++++
 src/stacktrace.c                 | 4 +++-
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/backends/i386_initreg_sample.c b/backends/i386_initreg_sample.c
index d7d312b0..52c81088 100644
--- a/backends/i386_initreg_sample.c
+++ b/backends/i386_initreg_sample.c
@@ -34,7 +34,9 @@
 #include <assert.h>
 #if (defined __i386__ || defined __x86_64__) && defined(__linux__)
 # include <linux/perf_event.h>
-# include <asm/perf_regs.h>
+# ifdef HAVE_PERF_REGS_H
+#  include <asm/perf_regs.h>
+# endif
 #endif
 
 #define BACKEND i386_
diff --git a/backends/libebl_PERF_FLAGS.h b/backends/libebl_PERF_FLAGS.h
index 51c20ea6..5b5a8d78 100644
--- a/backends/libebl_PERF_FLAGS.h
+++ b/backends/libebl_PERF_FLAGS.h
@@ -33,8 +33,7 @@
 
 #if defined(__linux__)
 /* XXX Need to exclude __linux__ arches without perf_regs.h. */
-#if defined(__x86_64__) || defined(__i386__)
-/* || defined(other_architecture)... */
+#if defined HAVE_PERF_REGS_H
 # include <asm/perf_regs.h>
 #endif
 #endif
diff --git a/backends/x86_64_initreg_sample.c b/backends/x86_64_initreg_sample.c
index 200a94a1..c115fedf 100644
--- a/backends/x86_64_initreg_sample.c
+++ b/backends/x86_64_initreg_sample.c
@@ -34,7 +34,9 @@
 #include <assert.h>
 #if defined(__x86_64__) && defined(__linux__)
 # include <linux/perf_event.h>
-# include <asm/perf_regs.h>
+# ifdef HAVE_PERF_REGS_H
+#  include <asm/perf_regs.h>
+# endif
 #endif
 
 #define BACKEND x86_64_
diff --git a/configure.ac b/configure.ac
index 58e58af2..ec40c7a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -971,6 +971,11 @@ AC_ARG_ENABLE(debuginfod-ima-cert-path,
 AC_SUBST(DEBUGINFOD_IMA_CERT_PATH, $default_debuginfod_ima_cert_path)
 AC_CONFIG_FILES([config/profile.sh config/profile.csh config/profile.fish])
 
+# check for asm/perf_regs.h, as it's completely absent on some architectures
+AH_TEMPLATE([HAVE_PERF_REGS_H], [Define to 1 if `asm/perf-regs.h` is provided 
by the system, 0 otherwise.])
+AC_CHECK_HEADER(asm/perf_regs.h,
+  [AC_DEFINE(HAVE_PERF_REGS_H)],[])
+
 # XXX Currently, eu-stacktrace can only work with sysprof/x86, hence:
 AC_ARG_ENABLE([stacktrace],AS_HELP_STRING([--enable-stacktrace], [Enable 
eu-stacktrace]))
 # check for x86, or more precisely _ASM_X86_PERF_REGS_H
diff --git a/src/stacktrace.c b/src/stacktrace.c
index c330e646..8f7325c5 100644
--- a/src/stacktrace.c
+++ b/src/stacktrace.c
@@ -83,7 +83,9 @@
 
 #include <linux/perf_event.h>
 
-/* TODO: Need to generalize the code beyond x86 architectures. */
+/* TODO: Need to generalize the code beyond x86 architectures.
+   eu-stacktrace currently disabled by configury
+   unless _ASM_X86_PERF_REGS_H is detected. */
 #include <asm/perf_regs.h>
 #ifndef _ASM_X86_PERF_REGS_H
 #error "eu-stacktrace is currently limited to x86 architectures"
-- 
2.51.1

Reply via email to