Build failure bft for trace-cmd and libtraceevent
Subsystems (2)
Hi Steven, All,
in Buildroot I'm bumping libtraceevent to 1.9.0 and trace-cmd to 3.4 and experiencing build failures because of the change of uapi/linux/bft.h defines/enums
I see as possible solution to create a bft_compat.h to deal with different Linux versions, but this is not a quick solution.
Otherwise the solution could be to switch according to Linux version between print_args() with and without bft support, basically re-adding the function here:
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/commit/?id=e798103c0815e6642e74d9317c325b2c62681f2e
What do you think about it?
Best regards
Giulio Benetti
Quoted 6 lines · On Sun, 8 Feb 2026 21:53:31 +0100 Giulio Benetti…
Otherwise the solution could be to switch according to Linux version between
print_args()with and without bft support, basically re-adding the function here:
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/commit/?id=e798103c0815e6642e74d9317c325b2c62681f2eWhat do you think about it?
Is the failure found at runtime? That is, the loaded BTF file doesn't parse correctly? What is the error exactly?
I guess if the tep_btf_print_args() fails, it should just print the raw args then.
-- Steve
Quoted 8 lines · Steven Rostedt
Quoted 5 lines · On Sun, 8 Feb 2026 21:53:31 +0100 Giulio Benetti…
Otherwise the solution could be to switch according to Linux version between
print_args()with and without bft support, basically re-adding the function here:
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/commit/?id=e798103c0815e6642e74d9317c325b2c62681f2e
Quoted 7 lines
Quoted 1 line
What do you think about it?
Is the failure found at runtime? That is, the loaded BTF file doesn't parse correctly? What is the error exactly?
I guess if the
tep_btf_print_args()fails, it should just print the raw args then.
Oh, I've forgotten to post the build failure, here it is and it's due to
dealing with different Linux versions:
[8/40] Compiling C object src/libtraceevent.so.1.9.0.p/trace-btf.c.o
FAILED: [code=1] src/libtraceevent.so.1.9.0.p/trace-btf.c.o/home/giuliobenetti/git/upstream/test-libtraceevent/bootlin-armv5-uclibc/host/bin/arm-linux-gcc -Isrc/libtraceevent.so.1.9.0.p -Isrc -I../src -Iinclude -I../include -Iinclude/traceevent -I../include/traceevent -fdiagnostics-color=always -Wall -Winvalid-pch -std=gnu99 -O3 -D_GNU_SOURCE '-DPLUGIN_DIR="/usr/lib/traceevent/plugins"' -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g0 -fPIC -MD -MQ src/libtraceevent.so.1.9.0.p/trace-btf.c.o -MF src/libtraceevent.so.1.9.0.p/trace-btf.c.o.d -o src/libtraceevent.so.1.9.0.p/trace-btf.c.o -c ../src/trace-btf.c ../src/trace-btf.c:60:10: error: ‘BTF_KIND_FLOAT’ undeclared here (not in a function); did you mean ‘BTF_KIND_CONST’?
60 | [BTF_KIND_FLOAT] = "FLOAT",
| ^~~~~~~~~~~~~~
| BTF_KIND_CONST../src/trace-btf.c:60:10: error: array index in initializer not of integer type ../src/trace-btf.c:60:10: note: (near initialization for ‘btf_kind_str’) ../src/trace-btf.c:60:35: warning: excess elements in array initializer
60 | [BTF_KIND_FLOAT] = "FLOAT",
| ^~~~~~~../src/trace-btf.c:60:35: note: (near initialization for ‘btf_kind_str’) ../src/trace-btf.c:61:10: error: ‘BTF_KIND_DECL_TAG’ undeclared here (not in a function)
61 | [BTF_KIND_DECL_TAG] = "DECL_TAG",
| ^~~~~~~~~~~~~~~~~
../src/trace-btf.c:61:10: error: array index in initializer not of integer type ../src/trace-btf.c:61:10: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c:61:35: warning: excess elements in array initializer
61 | [BTF_KIND_DECL_TAG] = "DECL_TAG",
| ^~~~~~~~~~../src/trace-btf.c:61:35: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c:62:10: error: ‘BTF_KIND_TYPE_TAG’ undeclared here (not in a function); did you mean ‘BTF_KIND_TYPEDEF’?
62 | [BTF_KIND_TYPE_TAG] = "TYPE_TAG",
| ^~~~~~~~~~~~~~~~~
| BTF_KIND_TYPEDEF../src/trace-btf.c:62:10: error: array index in initializer not of integer type ../src/trace-btf.c:62:10: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c:62:35: warning: excess elements in array initializer
62 | [BTF_KIND_TYPE_TAG] = "TYPE_TAG",
| ^~~~~~~~~~../src/trace-btf.c:62:35: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c:63:10: error: ‘BTF_KIND_ENUM64’ undeclared here (not in a function); did you mean ‘BTF_KIND_ENUM’?
63 | [BTF_KIND_ENUM64] = "ENUM64",
| ^~~~~~~~~~~~~~~
| BTF_KIND_ENUM../src/trace-btf.c:63:10: error: array index in initializer not of integer type../src/trace-btf.c:63:10: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c:63:35: warning: excess elements in array initializer
63 | [BTF_KIND_ENUM64] = "ENUM64",
| ^~~~~~~~../src/trace-btf.c:63:35: note: (near initialization for ‘btf_kind_str’)../src/trace-btf.c: In function ‘btf_type_size’:../src/trace-btf.c:115:38: error: invalid application of ‘sizeof’ to incomplete type ‘struct btf_decl_tag’
115 | return size + sizeof(struct btf_decl_tag);
| ^~~~~~../src/trace-btf.c:119:38: error: invalid application of ‘sizeof’ to incomplete type ‘struct btf_enum64’
119 | return size + sizeof(struct btf_enum64) *BTF_INFO_VLEN(type->info);
| ^~~~~~
[9/40] Compiling C object plugins/plugin_kmem.so.p/plugin_kmem.c.o
[10/40] Compiling C object plugins/plugin_tlb.so.p/plugin_tlb.c.o
[11/40] Compiling C object plugins/plugin_net.so.p/plugin_net.c.o
[12/40] Compiling C object src/libtraceevent.so.1.9.0.p/parse-utils.c.o
[13/40] Compiling C object plugins/plugin_sched_switch.so.p/plugin_sched_switch.c.o
[14/40] Compiling C object samples/test-event.p/test-event.c.o
[15/40] Compiling C object plugins/plugin_scsi.so.p/plugin_scsi.c.o
[16/40] Compiling C object src/libtraceevent.so.1.9.0.p/event-parse-api.c.o
[17/40] Compiling C object plugins/plugin_function.so.p/plugin_function.c.o
[18/40] Compiling C object src/libtraceevent.so.1.9.0.p/trace-seq.c.o
[19/40] Compiling C object plugins/plugin_kvm.so.p/plugin_kvm.c.o
[20/40] Compiling C object src/libtraceevent.so.1.9.0.p/event-plugin.c.o
[21/40] Compiling C object src/libtraceevent.so.1.9.0.p/kbuffer-parse.c.o
[22/40] Compiling C object src/libtraceevent.so.1.9.0.p/parse-filter.c.o
[23/40] Compiling C object src/libtraceevent.so.1.9.0.p/event-parse.c.o
ninja: build stopped: subcommand failed.
make[1]: *** [package/pkg-generic.mk:273: /home/giuliobenetti/git/upstream/test-libtraceevent/bootlin-armv5-uclibc/build/libtraceevent-1.9.0/.stamp_built] Error 1
make: *** [Makefile:83: _all] Error 2
Giulio
Quoted 2 lines · On Sun, 8 Feb 2026 22:44:24 +0100 Giulio Benetti…
Oh, I've forgotten to post the build failure, here it is and it's due to dealing with different Linux versions:
OK, if it is a build failure, we should add logic to make sure it builds properly and if not, warn and build without BTF. Kind of like what trace-cmd did when I was first started developing this:
https://lore.kernel.org/[email protected]
-- Steve
Quoted 7 lines
Il giorno 8 feb 2026, alle ore 23:01, Steven Rostedt <[email protected]> ha scritto:
On Sun, 8 Feb 2026 22:44:24 +0100
Giulio Benetti <[email protected]> wrote:
Quoted 8 lines
Quoted 2 lines
Oh, I've forgotten to post the build failure, here it is and it's due to dealing with different Linux versions:
OK, if it is a build failure, we should add logic to make sure it builds properly and if not, warn and build without BTF. Kind of like what trace-cmd did when I was first started developing this:
Oh, ok. I’m going to follow that commit and add btf option to disable btf to trace-cmd too. At the moment it only checks for libtraceevent version and that won’t be sufficient.
Thank you for taking care
Best regards
Giulio
Quoted 2 lines
-- Steve
Quoted 2 lines · On Sun, 8 Feb 2026 23:14:32 +0100 Giulio Benetti…
Oh, ok. I’m going to follow that commit and add btf option to disable btf to trace-cmd too. At the moment it only checks for libtraceevent version and that won’t be sufficient.
I don't think you need to change trace-cmd. We can just make the tep_btf_print_args() just print the arguments passed in if it is not supported, and have the list_args just fail.
Here's an update to the libtraceevent Makefile to do this. Will need something similar for the meson build.
-- Steve
Makefile +21 -7
@@ -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,20 @@ 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) { return 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 +144,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
Hi Steve,
Quoted 9 lines · Steven Rostedt
Quoted 2 lines · On Sun, 8 Feb 2026 23:14:32 +0100 Giulio Benetti…
Oh, ok. I’m going to follow that commit and add btf option to disable btf to trace-cmd too. At the moment it only checks for libtraceevent version and that won’t be sufficient.
I don't think you need to change trace-cmd. We can just make the
tep_btf_print_args()just print the arguments passed in if it is not supported,
it is not that clear to me here
Quoted 1 line
and have the
list_argsjust fail.
Ok.
Attached you find a patch to be tested.
Giulio
Quoted 49 lines
Here's an update to the libtraceevent
Makefileto do this. Will need something similar for the meson build.-- Steve
Makefile +21
-0@@ -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,20 @@ 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) { return 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 +144,6 @@ INCLUDES = -I. -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES) export LIBTRACEEVENT_STATIC LIBTRACEEVENT_SHARED EP_HEADERS_DIR
Makefile INCLUDES = -I. -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES) · line 149
Quoted 10 lines
Makefile +0
-7-# Set compile option CFLAGS -ifdef EXTRA_CFLAGS - CFLAGS := $(EXTRA_CFLAGS) -else - CFLAGS := -g -Wall -endif - LIBS ?= -ldl export LIBS
From e14139e63b68eccd2800406c4f5ad049015a8cf6 Mon Sep 17 00:00:00 2001
From: Giulio Benetti <[email protected]>
Date: Tue, 10 Feb 2026 17:57:52 +0100
Subject: [PATCH] Fix build failure due to btf on Linux < 6.0
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. If it's not there let's disable btf support.
--- Makefile | 28 +++++++++++++++++++++------- src/meson.build | 12 ++++++++++++ src/trace-btf.c | 9 +++++++++ 3 files changed, 42 insertions(+), 7 deletions(-)
Makefile +21 -7
@@ -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,20 @@ 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) { return 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 +144,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
src/meson.build +12 -0
@@ -17,6 +17,18 @@ sources= [ cc = meson.get_compiler('c') dl_dep = cc.find_library('dl') +btf_enum64_test_code = ''' +#include <linux/btf.h> +int main(void) { + int x = BTF_KIND_ENUM64; + return 0; +} +''' + +if cc.compiles(btf_enum64_test_code, name : 'BTF_KIND_ENUM64 check') + add_project_arguments('-DNO_BTF', language : 'c') +endif + libtraceevent = library( 'traceevent', sources,
src/trace-btf.c +9 -0
@@ -471,6 +471,9 @@ static int init_btf_func(struct tep_btf *btf, struct trace_seq *s,*/ int tep_btf_list_args (struct tep_handle *tep,struct trace_seq *s,const char *func) { +#ifdef NO_BTF +return -1 ; +#else struct tep_btf *btf = tep->btf;struct btf_type *type =tep_btf_find_func (btf, func);struct btf_param *param;
@@ -520,6 +523,7 @@ int tep_btf_list_args(struct tep_handle *tep, struct trace_seq *s, const char *f trace_seq_printf(s, "%s", param_name); }return p; +#endif }/**
@@ -543,6 +547,10 @@ int tep_btf_list_args(struct tep_handle *tep, struct trace_seq *s, const char *fint tep_btf_print_args (struct tep_handle *tep,struct trace_seq *s,void *args,int nmem,int size,const char *func) { +#ifdef NO_BTF +tep_warning ("BTF not supported. Args: ??? \n" ); +return -1 ; +#else struct tep_btf *btf = tep->btf;struct btf_type *type =tep_btf_find_func (btf, func);struct btf_param *param;
@@ -646,4 +654,5 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args, } }return 0 ; +#endif }
Signature · 1 line
2.47.3