Skip to contentSkip to conversation

kernel-devsrc: Install sources required for BPF host tools

PATCH In review Wang Mingyu 2 participants 2 messages Jul 31

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-devsrc: Install sources required for BPF host tools

From: Wang Mingyu <[email protected]>

When CONFIG_DEBUG_INFO_BTF is enabled in the kernel, building external modules that use BPF requires the 'resolve_btfids' host tool. This tool and its dependencies were not included in the kernel-devsrc package.

This can cause a build failure in an SDK environment when 'make scripts' is run, for example:

make[4]: *** No rule to make target '.../tools/bpf/resolve_btfids/main.o'

To fix this, unconditionally install the minimal set of source files required to build the 'resolve_btfids' tool and its library dependencies. This avoids coupling the recipe to specific kernel CONFIG symbols while also ensuring only necessary files are included in the package.

The copy operations ignore errors to prevent build failures on older kernel versions where these files may not exist.

---
V1: https://lists.openembedded.org/g/openembedded-core/message/242225
Changes in v2:
- Remove conditional copy based on CONFIG_DEBUG_INFO_BTF.
- Copy a minimal set of files instead of entire directories.
- Make copy operations robust against non-existent files.

---
 meta/recipes-kernel/linux/kernel-devsrc.bb | 12 ++++++++++++
 1 file changed, 12 insertions(+)
meta/recipes-kernel/linux/kernel-devsrc.bb +12 -0
index 237dec6b12..ca1a08cba3 100644
@@ -176,6 +176,18 @@ do_install() {
             cp -a --parents $(find tools/arch/${ARCH}/ -type f) $kerneldir/build/
         fi
 
+        # For v5.2+ when BTF is enabled, scripts prepare may rebuild the
+        # resolve_btfids host tool. Copy the minimal sources it needs instead
+        # of coupling this recipe to a specific kernel CONFIG_ symbol.
+        cp -a --parents tools/bpf/resolve_btfids/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/bpf/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/subcmd/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/ctype.c tools/lib/rbtree.c tools/lib/str_error_r.c \
+            tools/lib/string.c tools/lib/zalloc.c $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/build/Build.include tools/build/Build tools/build/fixdep.c \
+            tools/scripts/Makefile.arch tools/scripts/Makefile.include \
+            tools/scripts/utilities.mak $kerneldir/build/ 2>/dev/null || :
+
         if [ "${ARCH}" = "arm64" ]; then
             # arch/arm64/include/asm/xen references arch/arm
             cp -a --parents arch/arm/include/asm/xen $kerneldir/build/
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · wangmy via lists.openembedded.org

From: Wang Mingyu <[email protected]>

When CONFIG_DEBUG_INFO_BTF is enabled in the kernel, building external modules that use BPF requires the 'resolve_btfids' host tool. This tool and its dependencies were not included in the kernel-devsrc package.

This can cause a build failure in an SDK environment when 'make scripts' is run, for example:

make[4]: *** No rule to make target '.../tools/bpf/resolve_btfids/main.o'

Quoted 7 lines

To fix this, unconditionally install the minimal set of source files required to build the 'resolve_btfids' tool and its library dependencies. This avoids coupling the recipe to specific kernel CONFIG symbols while also ensuring only necessary files are included in the package.

The copy operations ignore errors to prevent build failures on older kernel versions where these files may not exist.

v2 is the right way to do it! Thanks for the quick turnaround

Quoted 48 lines

---
V1: https://lists.openembedded.org/g/openembedded-core/message/242225
Changes in v2:
- Remove conditional copy based on CONFIG_DEBUG_INFO_BTF.
- Copy a minimal set of files instead of entire directories.
- Make copy operations robust against non-existent files.

---
 meta/recipes-kernel/linux/kernel-devsrc.bb | 12 ++++++++++++
 1 file changed, 12 insertions(+)
meta/recipes-kernel/linux/kernel-devsrc.bb +12 -1
index 237dec6b12..ca1a08cba3 100644
@@ -176,6 +176,18 @@ do_install() {
             cp -a --parents $(find tools/arch/${ARCH}/ -type f) $kerneldir/build/
         fi
 
+        # For v5.2+ when BTF is enabled, scripts prepare may rebuild the
+        # resolve_btfids host tool. Copy the minimal sources it needs instead
+        # of coupling this recipe to a specific kernel CONFIG_ symbol.
+        cp -a --parents tools/bpf/resolve_btfids/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/bpf/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/subcmd/* $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/lib/ctype.c tools/lib/rbtree.c tools/lib/str_error_r.c \
+            tools/lib/string.c tools/lib/zalloc.c $kerneldir/build/ 2>/dev/null || :
+        cp -a --parents tools/build/Build.include tools/build/Build tools/build/fixdep.c \
+            tools/scripts/Makefile.arch tools/scripts/Makefile.include \
+            tools/scripts/utilities.mak $kerneldir/build/ 2>/dev/null || :
+
         if [ "${ARCH}" = "arm64" ]; then
             # arch/arm64/include/asm/xen references arch/arm
             cp -a --parents arch/arm/include/asm/xen $kerneldir/build/
--

2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#242391): https://lists.openembedded.org/g/openembedded-core/message/242391
Mute This Topic: https://lists.openembedded.org/mt/120530366/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II