* [PATCH v3] Fix build failure due to btf on Linux < 6.0
@ 2026-10-26 16:24 Giulio Benetti
2026-11-07 21:29 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Giulio Benetti @ 2026-10-26 16:24 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Giulio Benetti, Steven Rostedt (Google)
With commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6089fb325cf737eeb2c4d236c94697112ca860da
enum BTF_KIND_ENUM64 has been firstly introduced and this is the latest
BTF_KIND_* enumaration to be added to libtraceevent. So let's check
in runtime, both in Makefile and meson, if BTF_KIND_ENUM64 does exist
as well as struct btf_enum64 members name_off, val_lo32, val_hi32 to
make sure the entire enum64 facility is defined and guard for NO_BTF
selectively in trace-btf.c.
If it's not there let's disable btf support.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Co-authored-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
V1->V2:
* fixed meson check and all bft C source
V2->V3:
* check struct parameters other than only BTF_KIND_ENUM64
---
Makefile | 30 +++++++++++++++++++++++-------
src/meson.build | 14 ++++++++++++++
src/trace-btf.c | 7 +++++++
3 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 8a7a1dd..4b291c0 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,13 @@ $(call allow-override,PKG_CONFIG,pkg-config)
$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
$(call allow-override,LDCONFIG,ldconfig)
+# Set compile option CFLAGS
+ifdef EXTRA_CFLAGS
+ CFLAGS ?= $(EXTRA_CFLAGS)
+else
+ CFLAGS ?= -g -Wall
+endif
+
EXT = -std=gnu99
INSTALL = install
@@ -37,6 +44,22 @@ INSTALL = install
DESTDIR ?=
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+test-build = $(if $(shell sh -c 'echo "$(1)" | tee /tmp/t.c| \
+ $(CC) -o /dev/null -x c - > /dev/null 2>&1 && echo y'), $2)
+
+define BTF_LATEST_SOURCE
+#include <linux/btf.h>
+int main(void) { struct btf_enum64 e = {}; \
+ return e.name_off + e.val_lo32 + e.val_hi32 + \
+ BTF_KIND_ENUM64; }
+endef
+
+BTF_OK := $(call test-build,$(BTF_LATEST_SOURCE),y)
+
+ifneq ($(strip $(BTF_OK)), y)
+CFLAGS += -DNO_BTF
+endif
+
LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
ifeq ($(LP64), 1)
libdir_relative_temp = lib64
@@ -123,13 +146,6 @@ INCLUDES = -I. -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES)
export LIBTRACEEVENT_STATIC LIBTRACEEVENT_SHARED EP_HEADERS_DIR
-# Set compile option CFLAGS
-ifdef EXTRA_CFLAGS
- CFLAGS := $(EXTRA_CFLAGS)
-else
- CFLAGS := -g -Wall
-endif
-
LIBS ?= -ldl
export LIBS
diff --git a/src/meson.build b/src/meson.build
index 3a7a082..0fa5a5f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,20 @@ sources= [
cc = meson.get_compiler('c')
dl_dep = cc.find_library('dl')
+btf_enum64_test_code = '''
+#include <linux/btf.h>
+int main(void) {
+ struct btf_enum64 e = {};
+
+ return e.name_off + e.val_lo32 + e.val_hi32 +
+ BTF_KIND_ENUM64;
+}
+'''
+
+if not cc.compiles(btf_enum64_test_code, name : 'BTF_KIND_ENUM64 check')
+ add_project_arguments('-DNO_BTF', language : 'c')
+endif
+
libtraceevent = library(
'traceevent',
sources,
diff --git a/src/trace-btf.c b/src/trace-btf.c
index 2d66e01..f980d58 100644
--- a/src/trace-btf.c
+++ b/src/trace-btf.c
@@ -8,7 +8,9 @@
#include <stdlib.h>
#include <stdbool.h>
+#ifndef NO_BTF
#include <linux/btf.h>
+#endif
#include "event-parse.h"
#include "event-utils.h"
@@ -29,6 +31,9 @@ struct tep_btf {
void *raw_data;
};
+#ifdef NO_BTF
+void btf_free(struct tep_btf *btf) {}
+#else
#define REALLOC_SIZE (1 << 10)
#define REALLOC_MASK (REALLOC_SIZE - 1)
@@ -111,6 +116,7 @@ static int add_func(struct tep_btf *btf, struct btf_type *type)
static int btf_type_size(struct btf_type *type)
{
+ return -1;
int kind = BTF_INFO_KIND(type->info);
int size = sizeof(*type);
@@ -665,3 +671,4 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
}
return 0;
}
+#endif
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] Fix build failure due to btf on Linux < 6.0
2026-10-26 16:24 [PATCH v3] Fix build failure due to btf on Linux < 6.0 Giulio Benetti
@ 2026-11-07 21:29 ` Steven Rostedt
2026-11-09 10:26 ` [PATCH v4] libtraceevent: " Giulio Benetti
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2026-11-07 21:29 UTC (permalink / raw)
To: Giulio Benetti; +Cc: linux-trace-devel
On Mon, 26 Oct 2026 17:24:17 +0100
Giulio Benetti <giulio.benetti@benettiengineering.com> wrote:
Hi Giulio,
Thanks for the patch.
To make it easy to know which patch is for which library in patchwork,
can you add "libtraceevent" the subject line:
libtraceevent: Fix build failure due to btf on linux < 6.0
As I work on a repo, I filter out by the subjects and without having it
there the patch may be missed.
> With commit:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6089fb325cf737eeb2c4d236c94697112ca860da
> enum BTF_KIND_ENUM64 has been firstly introduced and this is the latest
> BTF_KIND_* enumaration to be added to libtraceevent. So let's check
> in runtime, both in Makefile and meson, if BTF_KIND_ENUM64 does exist
> as well as struct btf_enum64 members name_off, val_lo32, val_hi32 to
> make sure the entire enum64 facility is defined and guard for NO_BTF
> selectively in trace-btf.c.
> If it's not there let's disable btf support.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Co-authored-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
> ---
> V1->V2:
> * fixed meson check and all bft C source
> V2->V3:
> * check struct parameters other than only BTF_KIND_ENUM64
> ---
> Makefile | 30 +++++++++++++++++++++++-------
> src/meson.build | 14 ++++++++++++++
> src/trace-btf.c | 7 +++++++
> 3 files changed, 44 insertions(+), 7 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 8a7a1dd..4b291c0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -27,6 +27,13 @@ $(call allow-override,PKG_CONFIG,pkg-config)
> $(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
> $(call allow-override,LDCONFIG,ldconfig)
>
> +# Set compile option CFLAGS
> +ifdef EXTRA_CFLAGS
> + CFLAGS ?= $(EXTRA_CFLAGS)
> +else
> + CFLAGS ?= -g -Wall
> +endif
> +
> EXT = -std=gnu99
> INSTALL = install
>
> @@ -37,6 +44,22 @@ INSTALL = install
> DESTDIR ?=
> DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
>
> +test-build = $(if $(shell sh -c 'echo "$(1)" | tee /tmp/t.c| \
> + $(CC) -o /dev/null -x c - > /dev/null 2>&1 && echo y'), $2)
> +
> +define BTF_LATEST_SOURCE
> +#include <linux/btf.h>
> +int main(void) { struct btf_enum64 e = {}; \
> + return e.name_off + e.val_lo32 + e.val_hi32 + \
> + BTF_KIND_ENUM64; }
> +endef
> +
> +BTF_OK := $(call test-build,$(BTF_LATEST_SOURCE),y)
> +
> +ifneq ($(strip $(BTF_OK)), y)
> +CFLAGS += -DNO_BTF
> +endif
> +
> LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
> ifeq ($(LP64), 1)
> libdir_relative_temp = lib64
> @@ -123,13 +146,6 @@ INCLUDES = -I. -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES)
>
> export LIBTRACEEVENT_STATIC LIBTRACEEVENT_SHARED EP_HEADERS_DIR
>
> -# Set compile option CFLAGS
> -ifdef EXTRA_CFLAGS
> - CFLAGS := $(EXTRA_CFLAGS)
> -else
> - CFLAGS := -g -Wall
> -endif
> -
> LIBS ?= -ldl
> export LIBS
>
> diff --git a/src/meson.build b/src/meson.build
> index 3a7a082..0fa5a5f 100644
> --- a/src/meson.build
> +++ b/src/meson.build
> @@ -17,6 +17,20 @@ sources= [
> cc = meson.get_compiler('c')
> dl_dep = cc.find_library('dl')
>
> +btf_enum64_test_code = '''
> +#include <linux/btf.h>
> +int main(void) {
> + struct btf_enum64 e = {};
> +
> + return e.name_off + e.val_lo32 + e.val_hi32 +
> + BTF_KIND_ENUM64;
> +}
> +'''
> +
> +if not cc.compiles(btf_enum64_test_code, name : 'BTF_KIND_ENUM64 check')
> + add_project_arguments('-DNO_BTF', language : 'c')
> +endif
> +
> libtraceevent = library(
> 'traceevent',
> sources,
> diff --git a/src/trace-btf.c b/src/trace-btf.c
> index 2d66e01..f980d58 100644
> --- a/src/trace-btf.c
> +++ b/src/trace-btf.c
> @@ -8,7 +8,9 @@
> #include <stdlib.h>
> #include <stdbool.h>
>
> +#ifndef NO_BTF
> #include <linux/btf.h>
> +#endif
Instead of adding the #if wrapper above...
>
> #include "event-parse.h"
> #include "event-utils.h"
> @@ -29,6 +31,9 @@ struct tep_btf {
> void *raw_data;
> };
>
> +#ifdef NO_BTF
> +void btf_free(struct tep_btf *btf) {}
> +#else
Can you just move the header here?
#include <linux/btf.h>
Thanks!
-- Steve
> #define REALLOC_SIZE (1 << 10)
> #define REALLOC_MASK (REALLOC_SIZE - 1)
>
> @@ -111,6 +116,7 @@ static int add_func(struct tep_btf *btf, struct btf_type *type)
>
> static int btf_type_size(struct btf_type *type)
> {
> + return -1;
> int kind = BTF_INFO_KIND(type->info);
> int size = sizeof(*type);
>
> @@ -665,3 +671,4 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
> }
> return 0;
> }
> +#endif
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v4] libtraceevent: Fix build failure due to btf on Linux < 6.0
2026-11-07 21:29 ` Steven Rostedt
@ 2026-11-09 10:26 ` Giulio Benetti
0 siblings, 0 replies; 3+ messages in thread
From: Giulio Benetti @ 2026-11-09 10:26 UTC (permalink / raw)
To: Steven Rostedt; +Cc: linux-trace-devel, Giulio Benetti
With commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6089fb325cf737eeb2c4d236c94697112ca860da
enum BTF_KIND_ENUM64 has been firstly introduced and this is the latest
BTF_KIND_* enumaration to be added to libtraceevent. So let's check
in runtime, both in Makefile and meson, if BTF_KIND_ENUM64 does exist
as well as struct btf_enum64 members name_off, val_lo32, val_hi32 to
make sure the entire enum64 facility is defined and guard for NO_BTF
selectively in trace-btf.c.
If it's not there let's disable btf support.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Co-authored-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
V1->V2:
* fixed meson check and all bft C source
V2->V3:
* check struct parameters other than only BTF_KIND_ENUM64
V3->V4:
* add "libtraceevent:" prefix to subject
* move #include <linux/btf.h> into the #else branch of #ifdef NO_BTF
* drop leftover debug code (tee /tmp/t.c and early return -1 in btf_type_size())
---
Makefile | 30 +++++++++++++++++++++++-------
src/meson.build | 14 ++++++++++++++
src/trace-btf.c | 8 ++++++--
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/Makefile b/Makefile
index 8a7a1dd..b7d9b25 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,13 @@ $(call allow-override,PKG_CONFIG,pkg-config)
$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
$(call allow-override,LDCONFIG,ldconfig)
+# Set compile option CFLAGS
+ifdef EXTRA_CFLAGS
+ CFLAGS ?= $(EXTRA_CFLAGS)
+else
+ CFLAGS ?= -g -Wall
+endif
+
EXT = -std=gnu99
INSTALL = install
@@ -37,6 +44,22 @@ INSTALL = install
DESTDIR ?=
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+test-build = $(if $(shell sh -c 'echo "$(1)" | \
+ $(CC) -o /dev/null -x c - > /dev/null 2>&1 && echo y'), $2)
+
+define BTF_LATEST_SOURCE
+#include <linux/btf.h>
+int main(void) { struct btf_enum64 e = {}; \
+ return e.name_off + e.val_lo32 + e.val_hi32 + \
+ BTF_KIND_ENUM64; }
+endef
+
+BTF_OK := $(call test-build,$(BTF_LATEST_SOURCE),y)
+
+ifneq ($(strip $(BTF_OK)), y)
+CFLAGS += -DNO_BTF
+endif
+
LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
ifeq ($(LP64), 1)
libdir_relative_temp = lib64
@@ -123,13 +146,6 @@ INCLUDES = -I. -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES)
export LIBTRACEEVENT_STATIC LIBTRACEEVENT_SHARED EP_HEADERS_DIR
-# Set compile option CFLAGS
-ifdef EXTRA_CFLAGS
- CFLAGS := $(EXTRA_CFLAGS)
-else
- CFLAGS := -g -Wall
-endif
-
LIBS ?= -ldl
export LIBS
diff --git a/src/meson.build b/src/meson.build
index 3a7a082..0fa5a5f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,20 @@ sources= [
cc = meson.get_compiler('c')
dl_dep = cc.find_library('dl')
+btf_enum64_test_code = '''
+#include <linux/btf.h>
+int main(void) {
+ struct btf_enum64 e = {};
+
+ return e.name_off + e.val_lo32 + e.val_hi32 +
+ BTF_KIND_ENUM64;
+}
+'''
+
+if not cc.compiles(btf_enum64_test_code, name : 'BTF_KIND_ENUM64 check')
+ add_project_arguments('-DNO_BTF', language : 'c')
+endif
+
libtraceevent = library(
'traceevent',
sources,
diff --git a/src/trace-btf.c b/src/trace-btf.c
index 2d66e01..2152f4c 100644
--- a/src/trace-btf.c
+++ b/src/trace-btf.c
@@ -8,8 +8,6 @@
#include <stdlib.h>
#include <stdbool.h>
-#include <linux/btf.h>
-
#include "event-parse.h"
#include "event-utils.h"
#include "event-parse-local.h"
@@ -29,6 +27,11 @@ struct tep_btf {
void *raw_data;
};
+#ifdef NO_BTF
+void btf_free(struct tep_btf *btf) {}
+#else
+#include <linux/btf.h>
+
#define REALLOC_SIZE (1 << 10)
#define REALLOC_MASK (REALLOC_SIZE - 1)
@@ -665,3 +668,4 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
}
return 0;
}
+#endif
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-09 10:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26 16:24 [PATCH v3] Fix build failure due to btf on Linux < 6.0 Giulio Benetti
2026-11-07 21:29 ` Steven Rostedt
2026-11-09 10:26 ` [PATCH v4] libtraceevent: " Giulio Benetti
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.