configure.ac: explicitly check for asm/perf_regs.h presence
Commit Message
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(-)
Comments
Hi Serhei,
On Mon, Nov 24, 2025 at 4:38 PM Serhei Makarov <serhei@serhei.io> wrote:
>
> 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.])
"perf-regs.h" should be "perf_regs.h". Also "...0 otherwise" isn't
technically correct since if asm/perf_regs.h isn't provided, then
HAVE_PERF_REGS_H isn't defined.
Otherwise this patch LGTM. IIRC this patch was motivated by a build
error on Debian. Were you able to verify that this patch fixes the
error in that build environment?
Aaron
> +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
>
Hi Serhei,
On Mon, Nov 24, 2025 at 04:38:03PM -0500, Serhei Makarov wrote:
> 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.
[...]
> --- 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"
Shouldn't this also be guarded like the other includes:
#ifdef HAVE_PERF_REGS_H
# include <asm/perf_regs.h>
#endif
Or is there some other mechanism that prevents stacktrace.c to be
compiled if asm/perf_regs.h isn't available?
Thanks,
Mark
On Wed, Nov 26, 2025, at 6:35 AM, Mark Wielaard wrote:
>> -/* 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"
>
> Shouldn't this also be guarded like the other includes:
>
> #ifdef HAVE_PERF_REGS_H
> # include <asm/perf_regs.h>
> #endif
>
> Or is there some other mechanism that prevents stacktrace.c to be
> compiled if asm/perf_regs.h isn't available?
Yes, eu-stacktrace is currently auto-disabled if a configury check
fails to see asm/perf_regs.h and _ASM_X86_PERF_REGS_H.
That's what the expanded comment was attempting to clarify,
seems I should clarify the comment further :-P
The additional #ifndef is more a diagnostic for someone who
overrides that configury to try to build eu-stacktrace anyways....
Still need to test the fix on a suitably exotic system...
will send a revised patch (cf Aaron's comments) once I've done that.
@@ -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_
@@ -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
@@ -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_
@@ -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
@@ -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"